list.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?php
  2. /* Copyright (C) 2005-2022 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. * \ingroup bookmark
  20. * \brief Page to display list of bookmarks
  21. */
  22. // Load Dolibarr environment
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
  25. // Load translation files required by the page
  26. $langs->loadLangs(array('bookmarks', 'admin'));
  27. // Get Parameters
  28. $action = GETPOST('action', 'aZ09');
  29. $massaction = GETPOST('massaction', 'alpha');
  30. $show_files = GETPOST('show_files', 'int');
  31. $confirm = GETPOST('confirm', 'alpha');
  32. $cancel = GETPOST('cancel', 'alpha');
  33. $toselect = GETPOST('toselect', 'array');
  34. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bookmarklist'; // To manage different context of search
  35. $backtopage = GETPOST('backtopage', 'alpha');
  36. $optioncss = GETPOST('optioncss', 'alpha');
  37. $mode = GETPOST('mode', 'aZ');
  38. $id = GETPOST("id", 'int');
  39. // Load variable for pagination
  40. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  41. $sortfield = GETPOST('sortfield', 'aZ09comma');
  42. $sortorder = GETPOST('sortorder', 'aZ09comma');
  43. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  44. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  45. // If $page is not defined, or '' or -1 or if we click on clear filters
  46. $page = 0;
  47. }
  48. $offset = $limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. if (!$sortfield) {
  52. $sortfield = 'b.position';
  53. }
  54. if (!$sortorder) {
  55. $sortorder = 'ASC';
  56. }
  57. // Initialize Objects
  58. $object = new Bookmark($db);
  59. $extrafields = new ExtraFields($db);
  60. $arrayfields = array();
  61. $hookmanager->initHooks(array('bookmarklist')); // Note that conf->hooks_modules contains array
  62. if ($id > 0) {
  63. $object->fetch($id);
  64. }
  65. $object->fields = dol_sort_array($object->fields, 'position');
  66. $arrayfields = dol_sort_array($arrayfields, 'position');
  67. // Security check
  68. restrictedArea($user, 'bookmark', $object);
  69. // Permissions
  70. $permissiontoread = $user->hasRight('bookmark', 'lire');
  71. $permissiontoadd = $user->hasRight('bookmark', 'creer');
  72. $permissiontodelete = ($user->hasRight('bookmark', 'supprimer') || ($permissiontoadd && $object->fk_user == $user->id));
  73. /*
  74. * Actions
  75. */
  76. if (GETPOST('cancel', 'alpha')) {
  77. $action = 'list';
  78. $massaction = '';
  79. }
  80. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  81. $massaction = '';
  82. }
  83. $parameters = array();
  84. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  85. if ($reshook < 0) {
  86. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  87. }
  88. if (empty($reshook)) {
  89. // Selection of new fields
  90. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  91. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  92. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  93. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  94. }
  95. // Mass actions
  96. $objectclass = 'Bookmark';
  97. $objectlabel = 'Bookmark';
  98. $uploaddir = $conf->bookmark->dir_output;
  99. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  100. if ($action == 'delete' && $permissiontodelete) {
  101. $object->fetch($id);
  102. $res = $object->delete($user);
  103. if ($res > 0) {
  104. header("Location: ".$_SERVER["PHP_SELF"]);
  105. exit;
  106. } else {
  107. setEventMessages($object->error, $object->errors, 'errors');
  108. $action = '';
  109. }
  110. }
  111. }
  112. /*
  113. * View
  114. */
  115. $form = new Form($db);
  116. $now = dol_now();
  117. //$help_url = "EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
  118. $help_url = '';
  119. $title = $langs->trans("Bookmarks");
  120. $morejs = array();
  121. $morecss = array();
  122. // Build and execute select
  123. // --------------------------------------------------------------------
  124. $sql = "SELECT b.rowid, b.dateb, b.fk_user, b.url, b.target, b.title, b.favicon, b.position,";
  125. $sql .= " u.login, u.lastname, u.firstname";
  126. // Add fields from extrafields
  127. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  128. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  129. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  130. }
  131. }
  132. // Add fields from hooks
  133. $parameters = array();
  134. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  135. $sql .= $hookmanager->resPrint;
  136. $sql = preg_replace('/,\s*$/', '', $sql);
  137. $sqlfields = $sql; // $sql fields to remove for count total
  138. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as b LEFT JOIN ".MAIN_DB_PREFIX."user as u ON b.fk_user=u.rowid";
  139. $sql .= " WHERE 1=1";
  140. $sql .= " AND b.entity IN (".getEntity('bookmark').")";
  141. if (!$user->admin) {
  142. $sql .= " AND (b.fk_user = ".((int) $user->id)." OR b.fk_user is NULL OR b.fk_user = 0)";
  143. }
  144. // Count total nb of records
  145. $nbtotalofrecords = '';
  146. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  147. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  148. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  149. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  150. $resql = $db->query($sqlforcount);
  151. if ($resql) {
  152. $objforcount = $db->fetch_object($resql);
  153. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  154. } else {
  155. dol_print_error($db);
  156. }
  157. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  158. $page = 0;
  159. $offset = 0;
  160. }
  161. $db->free($resql);
  162. }
  163. // Complete request and execute it with limit
  164. $sql .= $db->order($sortfield.", position", $sortorder);
  165. if ($limit) {
  166. $sql .= $db->plimit($limit + 1, $offset);
  167. }
  168. $resql = $db->query($sql);
  169. if (!$resql) {
  170. dol_print_error($db);
  171. exit;
  172. }
  173. $num = $db->num_rows($resql);
  174. // Output page
  175. // --------------------------------------------------------------------
  176. llxHeader('', $title);
  177. $arrayofselected = is_array($toselect) ? $toselect : array();
  178. $param = '';
  179. if (!empty($mode)) {
  180. $param .= '&mode='.urlencode($mode);
  181. }
  182. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  183. $param .= '&contextpage='.urlencode($contextpage);
  184. }
  185. if ($limit > 0 && $limit != $conf->liste_limit) {
  186. $param .= '&limit='.((int) $limit);
  187. }
  188. if ($optioncss != '') {
  189. $param .= '&optioncss='.urlencode($optioncss);
  190. }
  191. // Add $param from extra fields
  192. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  193. // Add $param from hooks
  194. $parameters = array();
  195. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  196. $param .= $hookmanager->resPrint;
  197. // List of mass actions available
  198. $arrayofmassactions = array(
  199. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  200. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  201. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  202. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  203. );
  204. if (!empty($permissiontodelete)) {
  205. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  206. }
  207. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  208. $arrayofmassactions = array();
  209. }
  210. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  211. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  212. if ($optioncss != '') {
  213. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  214. }
  215. print '<input type="hidden" name="token" value="'.newToken().'">';
  216. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  217. print '<input type="hidden" name="action" value="list">';
  218. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  219. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  220. print '<input type="hidden" name="page" value="'.$page.'">';
  221. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  222. print '<input type="hidden" name="page_y" value="">';
  223. print '<input type="hidden" name="mode" value="'.$mode.'">';
  224. $newcardbutton = '';
  225. $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'), '', $permissiontoadd);
  226. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'bookmark', 0, $newcardbutton, '', $limit, 0, 0, 1);
  227. // Add code for pre mass action (confirmation or email presend form)
  228. $topicmail = "SendBookmarkRef";
  229. $modelmail = "bookmark";
  230. $objecttmp = new Bookmark($db);
  231. $trackid = 'bookmark'.$object->id;
  232. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  233. $moreforfilter = '';
  234. $parameters = array();
  235. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  236. if (empty($reshook)) {
  237. $moreforfilter .= $hookmanager->resPrint;
  238. } else {
  239. $moreforfilter = $hookmanager->resPrint;
  240. }
  241. if (!empty($moreforfilter)) {
  242. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  243. print $moreforfilter;
  244. print '</div>';
  245. }
  246. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  247. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  248. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  249. print '<div class="div-table-responsive">';
  250. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  251. // Fields title search
  252. // --------------------------------------------------------------------
  253. // TODO
  254. $totalarray = array();
  255. $totalarray['nbfield'] = 0;
  256. // Fields title label
  257. // --------------------------------------------------------------------
  258. print '<tr class="liste_titre">';
  259. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  260. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  261. $totalarray['nbfield']++;
  262. }
  263. print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "b.rowid", "", $param, '', $sortfield, $sortorder);
  264. print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "b.title", "", $param, '', $sortfield, $sortorder);
  265. print_liste_field_titre("Link", $_SERVER["PHP_SELF"], "b.url", "", $param, '', $sortfield, $sortorder);
  266. print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "b.target", "", $param, '', $sortfield, $sortorder, 'center ');
  267. print_liste_field_titre("Visibility", $_SERVER["PHP_SELF"], "u.lastname", "", $param, '', $sortfield, $sortorder, 'center ');
  268. print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "b.dateb", "", $param, '', $sortfield, $sortorder, 'center ');
  269. print_liste_field_titre("Position", $_SERVER["PHP_SELF"], "b.position", "", $param, '', $sortfield, $sortorder, 'right ');
  270. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  271. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  272. $totalarray['nbfield']++;
  273. }
  274. print '</tr>'."\n";
  275. $totalarray = array();
  276. $totalarray['nbfield'] = 0;
  277. // Loop on record
  278. // --------------------------------------------------------------------
  279. $i = 0;
  280. $savnbfield = $totalarray['nbfield'];
  281. $totalarray = array();
  282. $totalarray['nbfield'] = 0;
  283. $imaxinloop = ($limit ? min($num, $limit) : $num);
  284. while ($i < $imaxinloop) {
  285. $obj = $db->fetch_object($resql);
  286. if (empty($obj)) {
  287. break; // Should not happen
  288. }
  289. $object->id = $obj->rowid;
  290. $object->ref = $obj->rowid;
  291. if ($mode == 'kanban') {
  292. if ($i == 0) {
  293. print '<tr><td colspan="'.$savnbfield.'">';
  294. print '<div class="box-flex-container">';
  295. }
  296. // Output Kanban
  297. print $object->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected)));
  298. if ($i == ($imaxinloop - 1)) {
  299. print '</div>';
  300. print '</td></tr>';
  301. }
  302. } else {
  303. // Show here line of result
  304. $j = 0;
  305. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  306. // Action column
  307. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  308. print '<td class="nowrap center">';
  309. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  310. $selected = 0;
  311. if (in_array($object->id, $arrayofselected)) {
  312. $selected = 1;
  313. }
  314. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  315. }
  316. print '</td>';
  317. if (!$i) {
  318. $totalarray['nbfield']++;
  319. }
  320. }
  321. // Id
  322. print '<td class="nowraponall">';
  323. print $object->getNomUrl(1);
  324. print '</td>';
  325. $linkintern = 1;
  326. if (preg_match('/^http/i', $obj->url)) {
  327. $linkintern = 0;
  328. }
  329. $title = $obj->title;
  330. $link = $obj->url;
  331. $canedit = $permissiontoadd;
  332. $candelete = $permissiontodelete;
  333. // Title
  334. print '<td class="tdoverflowmax200" alt="'.dol_escape_htmltag($title).'">';
  335. print dol_escape_htmltag($title);
  336. print "</td>\n";
  337. // Url
  338. print '<td class="tdoverflowmax200">';
  339. if (empty($linkintern)) {
  340. print img_picto('', 'url', 'class="pictofixedwidth"');
  341. print '<a class="" href="'.$obj->url.'"'.($obj->target ? ' target="newlink" rel="noopener"' : '').'>';
  342. } else {
  343. //print img_picto('', 'rightarrow', 'class="pictofixedwidth"');
  344. print '<a class="" href="'.$obj->url.'">';
  345. }
  346. print $link;
  347. print '</a>';
  348. print "</td>\n";
  349. // Target
  350. print '<td class="tdoverflowmax100 center">';
  351. if ($obj->target == 0) {
  352. print $langs->trans("BookmarkTargetReplaceWindowShort");
  353. }
  354. if ($obj->target == 1) {
  355. print $langs->trans("BookmarkTargetNewWindowShort");
  356. }
  357. print "</td>\n";
  358. // Author
  359. print '<td class="tdoverflowmax100 center">';
  360. if ($obj->fk_user > 0) {
  361. if (empty($conf->cache['users'][$obj->fk_user])) {
  362. $tmpuser = new User($db);
  363. $tmpuser->fetch($obj->fk_user);
  364. $conf->cache['users'][$obj->fk_user] = $tmpuser;
  365. }
  366. $tmpuser = $conf->cache['users'][$obj->fk_user];
  367. print $tmpuser->getNomUrl(-1);
  368. } else {
  369. print '<span class="opacitymedium">'.$langs->trans("Everybody").'</span>';
  370. if (!$user->admin) {
  371. $candelete = false;
  372. $canedit = false;
  373. }
  374. }
  375. print "</td>\n";
  376. // Date creation
  377. print '<td class="center" title="'.dol_escape_htmltag(dol_print_date($db->jdate($obj->dateb), 'dayhour')).'">'.dol_print_date($db->jdate($obj->dateb), 'day')."</td>";
  378. // Position
  379. print '<td class="right">'.$obj->position."</td>";
  380. // Action column
  381. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  382. print '<td class="nowrap center">';
  383. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  384. $selected = 0;
  385. if (in_array($object->id, $arrayofselected)) {
  386. $selected = 1;
  387. }
  388. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  389. }
  390. print '</td>';
  391. if (!$i) {
  392. $totalarray['nbfield']++;
  393. }
  394. }
  395. print "</tr>\n";
  396. }
  397. $i++;
  398. }
  399. // Show total line
  400. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  401. // If no record found
  402. if ($num == 0) {
  403. $colspan = 1;
  404. foreach ($arrayfields as $key => $val) {
  405. if (!empty($val['checked'])) {
  406. $colspan++;
  407. }
  408. }
  409. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  410. }
  411. $db->free($resql);
  412. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  413. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  414. print $hookmanager->resPrint;
  415. print '</table>'."\n";
  416. print '</div>'."\n";
  417. print '</form>'."\n";
  418. // End of page
  419. llxFooter();
  420. $db->close();