bookmarks_page.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /* Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This file is a modified version of datepicker.php from phpBSM to fix some
  5. * bugs, to add new features and to dramatically increase speed.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/core/bookmarks_page.php
  22. * \brief File to return a page with the complete list of bookmarks
  23. */
  24. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  25. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  26. //if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
  27. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); // Not disabled cause need to do translations
  28. if (!defined('NOCSRFCHECK')) {
  29. define('NOCSRFCHECK', 1);
  30. }
  31. if (!defined('NOTOKENRENEWAL')) {
  32. define('NOTOKENRENEWAL', 1);
  33. }
  34. //if (! defined('NOLOGIN')) define('NOLOGIN',1); // Not disabled cause need to load personalized language
  35. if (!defined('NOREQUIREMENU')) {
  36. define('NOREQUIREMENU', 1);
  37. }
  38. //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML',1);
  39. require_once '../main.inc.php';
  40. if (GETPOST('lang', 'aZ09')) {
  41. $langs->setDefaultLang(GETPOST('lang', 'aZ09')); // If language was forced on URL by the main.inc.php
  42. }
  43. $langs->loadLangs(array("bookmarks"));
  44. $right = ($langs->trans("DIRECTION") == 'rtl' ? 'left' : 'right');
  45. $left = ($langs->trans("DIRECTION") == 'rtl' ? 'right' : 'left');
  46. /*
  47. * View
  48. */
  49. // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access.
  50. if (empty($dolibarr_nocache) && GETPOST('cache', 'int')) {
  51. header('Cache-Control: max-age='.GETPOST('cache', 'int').', public');
  52. // For a .php, we must set an Expires to avoid to have it forced to an expired value by the web server
  53. header('Expires: '.gmdate('D, d M Y H:i:s', dol_now('gmt') + GETPOST('cache', 'int')).' GMT');
  54. // HTTP/1.0
  55. header('Pragma: token=public');
  56. } else {
  57. // HTTP/1.0
  58. header('Cache-Control: no-cache');
  59. }
  60. $title = $langs->trans("Bookmarks");
  61. // URL http://mydolibarr/core/bookmarks_page?dol_use_jmobile=1 can be used for tests
  62. $head = '<!-- Bookmarks -->'."\n"; // This is used by DoliDroid to know page is a bookmark selection page
  63. $arrayofjs = array();
  64. $arrayofcss = array();
  65. top_htmlhead($head, $title, 0, 0, $arrayofjs, $arrayofcss);
  66. print '<body>'."\n";
  67. print '<div>';
  68. //print '<br>';
  69. // Instantiate hooks of thirdparty module
  70. $hookmanager->initHooks(array('bookmarks'));
  71. // Define $bookmarks
  72. $bookmarkList = '';
  73. $searchForm = '';
  74. if (empty($conf->bookmark->enabled)) {
  75. $langs->load("admin");
  76. $bookmarkList .= '<br><span class="opacitymedium">'.$langs->trans("WarningModuleNotActive", $langs->transnoentitiesnoconv("Bookmarks")).'</span>';
  77. $bookmarkList .= '<br><br>';
  78. } else {
  79. // Menu with list of bookmarks
  80. $sql = "SELECT rowid, title, url, target FROM ".MAIN_DB_PREFIX."bookmark";
  81. $sql .= " WHERE (fk_user = ".((int) $user->id)." OR fk_user is NULL OR fk_user = 0)";
  82. $sql .= " AND entity IN (".getEntity('bookmarks').")";
  83. $sql .= " ORDER BY position";
  84. if ($resql = $db->query($sql)) {
  85. $bookmarkList = '<div id="dropdown-bookmarks-list" class="start">';
  86. $i = 0;
  87. while ((empty($conf->global->BOOKMARKS_SHOW_IN_MENU) || $i < $conf->global->BOOKMARKS_SHOW_IN_MENU) && $obj = $db->fetch_object($resql)) {
  88. $bookmarkList .= '<a class="dropdown-item bookmark-item'.(strpos($obj->url, 'http') === 0 ? ' bookmark-item-external' : '').'" id="bookmark-item-'.$obj->rowid.'" data-id="'.$obj->rowid.'" '.($obj->target == 1 ? ' target="_blank" rel="noopener noreferrer"' : '').' href="'.dol_escape_htmltag($obj->url).'" >';
  89. $bookmarkList .= dol_escape_htmltag($obj->title);
  90. $bookmarkList .= '</a>';
  91. $i++;
  92. }
  93. if ($i == 0) {
  94. $bookmarkList .= '<br><span class="opacitymedium">'.$langs->trans("NoBookmarks").'</span>';
  95. $bookmarkList .= '<br><br>';
  96. }
  97. $newcardbutton = '';
  98. $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));
  99. // Url to list bookmark
  100. $bookmarkList .= '<br>';
  101. $bookmarkList .= '<a class="top-menu-dropdown-link" title="'.$langs->trans('Bookmarks').'" href="'.DOL_URL_ROOT.'/bookmarks/list.php" >';
  102. $bookmarkList .= img_picto('', 'bookmark', 'class="paddingright"').$langs->trans('Bookmarks').'</a>';
  103. $bookmarkList .= '<br>';
  104. $bookmarkList .= '<br>';
  105. $bookmarkList .= '<center>'.$newcardbutton.'</center>';
  106. $bookmarkList .= '</div>';
  107. $searchForm .= '<input name="bookmark" id="top-bookmark-search-input" class="dropdown-search-input" placeholder="'.$langs->trans('Bookmarks').'" autocomplete="off" >';
  108. } else {
  109. dol_print_error($db);
  110. }
  111. }
  112. // Execute hook printBookmarks
  113. $parameters = array('bookmarks'=>$bookmarkList);
  114. $reshook = $hookmanager->executeHooks('printBookmarks', $parameters); // Note that $action and $object may have been modified by some hooks
  115. if (empty($reshook)) {
  116. $bookmarkList .= $hookmanager->resPrint;
  117. } else {
  118. $bookmarkList = $hookmanager->resPrint;
  119. }
  120. print "\n";
  121. print "<!-- Begin Bookmarks list -->\n";
  122. print '<div class="center"><div class="center" style="padding: 6px;">';
  123. print '<style>.menu_titre { padding-top: 7px; }</style>';
  124. print '<div id="blockvmenusearch" class="tagtable center searchpage">'."\n";
  125. print $bookmarkList;
  126. print '</div>'."\n";
  127. print '</div></div>';
  128. print "\n<!-- End SearchForm -->\n";
  129. print '</div>';
  130. print '</body></html>'."\n";
  131. $db->close();