list.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. /* Copyright (C) 2005-2020 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/bookmarks/list.php
  19. * \brief Page to display list of bookmarks
  20. * \ingroup bookmark
  21. */
  22. require '../main.inc.php';
  23. require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
  24. // Load translation files required by the page
  25. $langs->loadLangs(array('bookmarks', 'admin'));
  26. $action = GETPOST('action', 'aZ09');
  27. $massaction = GETPOST('massaction', 'alpha');
  28. $show_files = GETPOST('show_files', 'int');
  29. $confirm = GETPOST('confirm', 'alpha');
  30. $toselect = GETPOST('toselect', 'array');
  31. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bookmarklist'; // To manage different context of search
  32. // Security check
  33. if (empty($user->rights->bookmark->lire)) {
  34. restrictedArea($user, 'bookmarks');
  35. }
  36. $optioncss = GETPOST('optioncss', 'alpha');
  37. // Load variable for pagination
  38. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  39. $sortfield = GETPOST('sortfield', 'aZ09comma');
  40. $sortorder = GETPOST('sortorder', 'aZ09comma');
  41. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  42. if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  43. $page = 0;
  44. } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  45. $offset = $limit * $page;
  46. $pageprev = $page - 1;
  47. $pagenext = $page + 1;
  48. if (!$sortfield) {
  49. $sortfield = 'position';
  50. }
  51. if (!$sortorder) {
  52. $sortorder = 'ASC';
  53. }
  54. $id = GETPOST("id", 'int');
  55. $object = new Bookmark($db);
  56. $permissiontoread = !empty($user->rights->bookmark->lire);
  57. $permissiontoadd = !empty($user->rights->bookmark->creer);
  58. $permissiontodelete = !empty($user->rights->bookmark->supprimer);
  59. /*
  60. * Actions
  61. */
  62. if ($action == 'delete') {
  63. $res = $object->remove($id);
  64. if ($res > 0) {
  65. header("Location: ".$_SERVER["PHP_SELF"]);
  66. exit;
  67. } else {
  68. setEventMessages($object->error, $object->errors, 'errors');
  69. }
  70. }
  71. /*
  72. * View
  73. */
  74. $form = new Form($db);
  75. $title = $langs->trans("ListOfBookmarks");
  76. llxHeader('', $title);
  77. $sql = "SELECT b.rowid, b.dateb, b.fk_user, b.url, b.target, b.title, b.favicon, b.position,";
  78. $sql .= " u.login, u.lastname, u.firstname";
  79. $sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b LEFT JOIN ".MAIN_DB_PREFIX."user as u ON b.fk_user=u.rowid";
  80. $sql .= " WHERE 1=1";
  81. $sql .= " AND b.entity IN (".getEntity('bookmark').")";
  82. if (!$user->admin) {
  83. $sql .= " AND (b.fk_user = ".((int) $user->id)." OR b.fk_user is NULL OR b.fk_user = 0)";
  84. }
  85. $sql .= $db->order($sortfield.", position", $sortorder);
  86. // Count total nb of records
  87. $nbtotalofrecords = '';
  88. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  89. $resql = $db->query($sql);
  90. $nbtotalofrecords = $db->num_rows($resql);
  91. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  92. $page = 0;
  93. $offset = 0;
  94. }
  95. }
  96. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  97. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords) {
  98. $num = $nbtotalofrecords;
  99. } else {
  100. $sql .= $db->plimit($limit + 1, $offset);
  101. $resql = $db->query($sql);
  102. if (!$resql) {
  103. dol_print_error($db);
  104. exit;
  105. }
  106. $num = $db->num_rows($resql);
  107. }
  108. $param = "";
  109. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  110. $param .= '&contextpage='.urlencode($contextpage);
  111. }
  112. if ($limit > 0 && $limit != $conf->liste_limit) {
  113. $param .= '&limit='.urlencode($limit);
  114. }
  115. if ($optioncss != '') {
  116. $param = '&optioncss='.urlencode($optioncss);
  117. }
  118. $moreforfilter = '';
  119. // List of mass actions available
  120. $arrayofmassactions = array(
  121. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  122. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  123. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  124. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  125. );
  126. if ($permissiontodelete) {
  127. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  128. }
  129. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  130. $arrayofmassactions = array();
  131. }
  132. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  133. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  134. if ($optioncss != '') {
  135. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  136. }
  137. print '<input type="hidden" name="token" value="'.newToken().'">';
  138. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  139. print '<input type="hidden" name="action" value="list">';
  140. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  141. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  142. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  143. $newcardbutton = '';
  144. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/bookmarks/card.php?action=create&backtopage='.urlencode(DOL_URL_ROOT.'/bookmarks/list.php'), '', !empty($user->rights->bookmark->creer));
  145. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bookmark', 0, $newcardbutton, '', $limit, 0, 0, 1);
  146. print '<div class="div-table-responsive">';
  147. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  148. print '<tr class="liste_titre">';
  149. //print "<td>&nbsp;</td>";
  150. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "b.rowid", "", $param, 'align="left"', $sortfield, $sortorder);
  151. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "b.title", "", $param, 'align="left"', $sortfield, $sortorder);
  152. print_liste_field_titre("Link", $_SERVER["PHP_SELF"], "b.url", "", $param, 'align="left"', $sortfield, $sortorder);
  153. print_liste_field_titre("Target", '', '', '', '', 'align="center"');
  154. print_liste_field_titre("Visibility", $_SERVER["PHP_SELF"], "u.lastname", "", $param, 'align="center"', $sortfield, $sortorder);
  155. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "b.dateb", "", $param, 'align="center"', $sortfield, $sortorder);
  156. print_liste_field_titre("Position", $_SERVER["PHP_SELF"], "b.position", "", $param, 'class="right"', $sortfield, $sortorder);
  157. print_liste_field_titre('');
  158. print "</tr>\n";
  159. $cacheOfUsers = array();
  160. $i = 0;
  161. while ($i < min($num, $limit)) {
  162. $obj = $db->fetch_object($resql);
  163. $object->id = $obj->rowid;
  164. $object->ref = $obj->rowid;
  165. print '<tr class="oddeven">';
  166. // Id
  167. print '<td class="nowraponall">';
  168. print $object->getNomUrl(1);
  169. print '</td>';
  170. $linkintern = 0;
  171. $title = $obj->title;
  172. $link = $obj->url;
  173. $canedit = $user->rights->bookmark->supprimer;
  174. $candelete = $user->rights->bookmark->creer;
  175. // Title
  176. print "<td>";
  177. $linkintern = 1;
  178. if ($linkintern) {
  179. print '<a href="'.$obj->url.'">';
  180. }
  181. print $title;
  182. if ($linkintern) {
  183. print "</a>";
  184. }
  185. print "</td>\n";
  186. // Url
  187. print '<td class="tdoverflowmax200">';
  188. if (!$linkintern) {
  189. print '<a href="'.$obj->url.'"'.($obj->target ? ' target="newlink" rel="noopener"' : '').'>';
  190. }
  191. print $link;
  192. if (!$linkintern) {
  193. print '</a>';
  194. }
  195. print "</td>\n";
  196. // Target
  197. print '<td class="center">';
  198. if ($obj->target == 0) {
  199. print $langs->trans("BookmarkTargetReplaceWindowShort");
  200. }
  201. if ($obj->target == 1) {
  202. print $langs->trans("BookmarkTargetNewWindowShort");
  203. }
  204. print "</td>\n";
  205. // Author
  206. print '<td class="center">';
  207. if ($obj->fk_user) {
  208. if (empty($cacheOfUsers[$obj->fk_user])) {
  209. $tmpuser = new User($db);
  210. $tmpuser->fetch($obj->fk_user);
  211. $cacheOfUsers[$obj->fk_user] = $tmpuser;
  212. }
  213. $tmpuser = $cacheOfUsers[$obj->fk_user];
  214. print $tmpuser->getNomUrl(1);
  215. } else {
  216. print '<span class="opacitymedium">'.$langs->trans("Everybody").'</span>';
  217. if (!$user->admin) {
  218. $candelete = false;
  219. $canedit = false;
  220. }
  221. }
  222. print "</td>\n";
  223. // Date creation
  224. print '<td class="center">'.dol_print_date($db->jdate($obj->dateb), 'day')."</td>";
  225. // Position
  226. print '<td class="right">'.$obj->position."</td>";
  227. // Actions
  228. print '<td class="nowraponall right">';
  229. if ($canedit) {
  230. print '<a class="editfielda marginleftonly" href="'.DOL_URL_ROOT.'/bookmarks/card.php?action=edit&token='.newToken().'&id='.$obj->rowid.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'">'.img_edit()."</a>";
  231. }
  232. if ($candelete) {
  233. print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$obj->rowid.'">'.img_delete().'</a>';
  234. }
  235. print "</td>";
  236. print "</tr>\n";
  237. $i++;
  238. }
  239. print "</table>";
  240. print '</div>';
  241. $db->free($resql);
  242. // End of page
  243. llxFooter();
  244. $db->close();