list.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. /* Copyright (C) 2005-2012 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', 'alpha');
  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') : 'myobjectlist'; // To manage different context of search
  32. // Security check
  33. if (!$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', 'alpha');
  40. $sortorder = GETPOST('sortorder', 'alpha');
  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')) { $page = 0; } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  43. $offset = $limit * $page;
  44. $pageprev = $page - 1;
  45. $pagenext = $page + 1;
  46. if (!$sortfield) $sortfield = 'position';
  47. if (!$sortorder) $sortorder = 'ASC';
  48. $id = GETPOST("id", 'int');
  49. $object = new Bookmark($db);
  50. $permissiontoread = $user->rights->bookmark->lire;
  51. $permissiontoadd = $user->rights->bookmark->write;
  52. $permissiontodelete = $user->rights->bookmark->delete;
  53. /*
  54. * Actions
  55. */
  56. if ($action == 'delete')
  57. {
  58. $res = $object->remove($id);
  59. if ($res > 0)
  60. {
  61. header("Location: ".$_SERVER["PHP_SELF"]);
  62. exit;
  63. }
  64. else
  65. {
  66. setEventMessages($object->error, $object->errors, 'errors');
  67. }
  68. }
  69. /*
  70. * View
  71. */
  72. $userstatic = new User($db);
  73. $title = $langs->trans("ListOfBookmarks");
  74. llxHeader('', $title);
  75. $sql = "SELECT b.rowid, b.dateb, b.fk_user, b.url, b.target, b.title, b.favicon, b.position,";
  76. $sql .= " u.login, u.lastname, u.firstname";
  77. $sql .= " FROM ".MAIN_DB_PREFIX."bookmark as b LEFT JOIN ".MAIN_DB_PREFIX."user as u ON b.fk_user=u.rowid";
  78. $sql .= " WHERE 1=1";
  79. $sql .= " AND b.entity IN (".getEntity('bookmark').")";
  80. if (!$user->admin) $sql .= " AND (b.fk_user = ".$user->id." OR b.fk_user is NULL OR b.fk_user = 0)";
  81. $sql .= $db->order($sortfield.", position", $sortorder);
  82. // Count total nb of records
  83. $nbtotalofrecords = '';
  84. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  85. {
  86. $resql = $db->query($sql);
  87. $nbtotalofrecords = $db->num_rows($resql);
  88. if (($page * $limit) > $nbtotalofrecords) // if total of record found is smaller than page * limit, goto and load page 0
  89. {
  90. $page = 0;
  91. $offset = 0;
  92. }
  93. }
  94. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  95. if (is_numeric($nbtotalofrecords) && $limit > $nbtotalofrecords)
  96. {
  97. $num = $nbtotalofrecords;
  98. }
  99. else
  100. {
  101. $sql .= $db->plimit($limit + 1, $offset);
  102. $resql = $db->query($sql);
  103. if (!$resql)
  104. {
  105. dol_print_error($db);
  106. exit;
  107. }
  108. $num = $db->num_rows($resql);
  109. }
  110. $param = "";
  111. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  112. if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
  113. if ($optioncss != '') $param = '&optioncss='.urlencode($optioncss);
  114. $moreforfilter = '';
  115. // List of mass actions available
  116. $arrayofmassactions = array(
  117. //'validate'=>$langs->trans("Validate"),
  118. //'generate_doc'=>$langs->trans("ReGeneratePDF"),
  119. //'builddoc'=>$langs->trans("PDFMerge"),
  120. //'presend'=>$langs->trans("SendByMail"),
  121. );
  122. if ($permissiontodelete) $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  123. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
  124. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  125. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  126. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  127. print '<input type="hidden" name="token" value="'.newToken().'">';
  128. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  129. print '<input type="hidden" name="action" value="list">';
  130. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  131. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  132. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  133. $newcardbutton = '';
  134. $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));
  135. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bookmark', 0, $newcardbutton, '', $limit, 0, 0, 1);
  136. print '<div class="div-table-responsive">';
  137. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  138. print "<tr class=\"liste_titre\">";
  139. //print "<td>&nbsp;</td>";
  140. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "b.rowid", "", $param, 'align="left"', $sortfield, $sortorder);
  141. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "b.title", "", $param, 'align="left"', $sortfield, $sortorder);
  142. print_liste_field_titre("Link", $_SERVER["PHP_SELF"], "b.url", "", $param, 'align="left"', $sortfield, $sortorder);
  143. print_liste_field_titre("Target", '', '', '', '', 'align="center"');
  144. print_liste_field_titre("Owner", $_SERVER["PHP_SELF"], "u.lastname", "", $param, 'align="center"', $sortfield, $sortorder);
  145. print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "b.dateb", "", $param, 'align="center"', $sortfield, $sortorder);
  146. print_liste_field_titre("Position", $_SERVER["PHP_SELF"], "b.position", "", $param, 'class="right"', $sortfield, $sortorder);
  147. print_liste_field_titre('');
  148. print "</tr>\n";
  149. $cacheOfUsers = array();
  150. $i = 0;
  151. while ($i < min($num, $limit))
  152. {
  153. $obj = $db->fetch_object($resql);
  154. $object->id = $obj->rowid;
  155. $object->ref = $obj->rowid;
  156. print '<tr class="oddeven">';
  157. // Id
  158. print '<td class="left">';
  159. print $object->getNomUrl(1);
  160. print '</td>';
  161. $linkintern = 0;
  162. $title = $obj->title;
  163. $link = $obj->url;
  164. // Title
  165. print "<td>";
  166. $linkintern = 1;
  167. if ($linkintern) print "<a href=\"".$obj->url."\">";
  168. print $title;
  169. if ($linkintern) print "</a>";
  170. print "</td>\n";
  171. // Url
  172. print '<td class="tdoverflowmax200">';
  173. if (!$linkintern) print '<a href="'.$obj->url.'"'.($obj->target ? ' target="newlink"' : '').'>';
  174. print $link;
  175. if (!$linkintern) print '</a>';
  176. print "</td>\n";
  177. // Target
  178. print '<td class="center">';
  179. if ($obj->target == 0) print $langs->trans("BookmarkTargetReplaceWindowShort");
  180. if ($obj->target == 1) print $langs->trans("BookmarkTargetNewWindowShort");
  181. print "</td>\n";
  182. // Author
  183. print '<td class="center">';
  184. if ($obj->fk_user)
  185. {
  186. if (empty($cacheOfUsers[$obj->fk_user])) {
  187. $tmpuser = new User($db);
  188. $tmpuser->fetch($obj->fk_user);
  189. $cacheOfUsers[$obj->fk_user] = $tmpuser;
  190. }
  191. $tmpuser = $cacheOfUsers[$obj->fk_user];
  192. print $tmpuser->getNomUrl(1);
  193. }
  194. else
  195. {
  196. print $langs->trans("Public");
  197. }
  198. print "</td>\n";
  199. // Date creation
  200. print '<td class="center">'.dol_print_date($db->jdate($obj->dateb), 'day')."</td>";
  201. // Position
  202. print '<td class="right">'.$obj->position."</td>";
  203. // Actions
  204. print '<td class="nowrap right">';
  205. if ($user->rights->bookmark->creer)
  206. {
  207. print '<a class="editfielda" href="'.DOL_URL_ROOT."/bookmarks/card.php?action=edit&id=".$obj->rowid."&backtopage=".urlencode($_SERVER["PHP_SELF"]).'">'.img_edit()."</a>";
  208. }
  209. if ($user->rights->bookmark->supprimer)
  210. {
  211. print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?action=delete&id='.$obj->rowid.'">'.img_delete().'</a>';
  212. }
  213. else
  214. {
  215. print "&nbsp;";
  216. }
  217. print "</td>";
  218. print "</tr>\n";
  219. $i++;
  220. }
  221. print "</table>";
  222. print '</div>';
  223. $db->free($resql);
  224. // End of page
  225. llxFooter();
  226. $db->close();