list.php 18 KB

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