32 global $conf, $user, $db, $langs, $sortfield, $sortorder;
34 require_once DOL_DOCUMENT_ROOT.
'/bookmarks/class/bookmark.class.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
37 $langs->load(
"bookmarks");
39 $authorized_var=array(
'limit',
'optioncss',
'contextpage');
40 $url = $_SERVER[
"PHP_SELF"];
42 if (!empty($_SERVER[
"QUERY_STRING"])) {
43 if (is_array($_GET)) {
44 foreach ($_GET as $key => $val) {
46 foreach ($val as $tmpsubval) {
49 } elseif ($val !=
'') {
59 $tmpurl .= ($tmpurl ?
'&' :
'').
'sortfield='.urlencode($sortfield);
62 $tmpurl .= ($tmpurl ?
'&' :
'').
'sortorder='.urlencode($sortorder);
64 if (!empty($_POST) && is_array($_POST)) {
65 foreach ($_POST as $key => $val) {
66 if ((preg_match(
'/^search_/', $key) || in_array($key, $authorized_var))
68 && !array_key_exists($key, $url_param)) {
70 foreach ($val as $tmpsubval) {
73 } elseif ($val !=
'') {
80 $url .= ($tmpurl ?
'?'.$tmpurl :
'');
81 if (!empty($url_param)) {
82 $url .= (strpos($url,
'?') > 0 ?
'&' :
'?').implode(
'&', $url_param);
85 $searchForm =
'<!-- form with POST method by default, will be replaced with GET for external link by js -->'.
"\n";
86 $searchForm .=
'<form id="top-menu-action-bookmark" name="actionbookmark" method="POST" action=""'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ?
' onsubmit="return false"' :
'').
'>';
87 $searchForm .=
'<input type="hidden" name="token" value="'.newToken().
'">';
91 if (!empty($user->rights->bookmark->creer)) {
92 if (!preg_match(
'/bookmarks\/card.php/', $_SERVER[
'PHP_SELF'])) {
94 $urltoadd = DOL_URL_ROOT.
'/bookmarks/card.php?action=create&url='.urlencode($url);
95 $newbtn .=
'<a class="top-menu-dropdown-link" title="'.$langs->trans(
'AddThisPageToBookmarks').
'" href="'.
dol_escape_htmltag($urltoadd).
'" >';
96 $newbtn .=
img_picto(
'',
'add',
'',
false, 0, 0,
'',
'paddingright').dol_escape_htmltag($langs->trans(
'AddThisPageToBookmarks')).
'</a>';
101 $listbtn =
'<a class="top-menu-dropdown-link" title="'.dol_escape_htmltag($langs->trans(
'Bookmarks')).
'" href="'.DOL_URL_ROOT.
'/bookmarks/list.php">';
102 $listbtn .=
img_picto(
'',
'edit',
'class="paddingright opacitymedium"').$langs->trans(
'EditBookmarks').
'</a>';
107 $sql =
"SELECT rowid, title, url, target FROM ".MAIN_DB_PREFIX.
"bookmark";
108 $sql .=
" WHERE (fk_user = ".((int) $user->id).
" OR fk_user is NULL OR fk_user = 0)";
109 $sql .=
" AND entity IN (".getEntity(
'bookmarks').
")";
110 $sql .=
" ORDER BY position";
111 if ($resql = $db->query($sql)) {
112 if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
113 $bookmarkList =
'<div id="dropdown-bookmarks-list" >';
115 while ((empty($conf->global->BOOKMARKS_SHOW_IN_MENU) || $i < $conf->global->BOOKMARKS_SHOW_IN_MENU) && $obj = $db->fetch_object($resql)) {
116 $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).
'" >';
118 $bookmarkList .=
'</a>';
122 $bookmarkList .=
'</div>';
124 $searchForm .=
'<input name="bookmark" id="top-bookmark-search-input" class="dropdown-search-input" placeholder="'.$langs->trans(
'Bookmarks').
'" autocomplete="off" >';
126 $searchForm .=
'<select name"=bookmark" id="boxbookmark" class="topmenu-bookmark-dropdown .dropdown-toggle">';
128 $searchForm .=
'<option hidden value="listbookmarks" class="optiongrey" selected rel="'.DOL_URL_ROOT.
'/bookmarks/list.php">'.$langs->trans(
'Bookmarks').
'</option>';
129 $searchForm .=
'<option value="listbookmark" class="optionblue" rel="'.dol_escape_htmltag(DOL_URL_ROOT.
'/bookmarks/list.php').
'" ';
130 $searchForm .=
' data-html="'.dol_escape_htmltag(
img_picto(
'',
'bookmark').
' '.($user->rights->bookmark->creer ? $langs->trans(
'EditBookmarks') : $langs->trans(
'ListOfBookmarks')).
'...').
'">';
131 $searchForm .=
dol_escape_htmltag($user->rights->bookmark->creer ? $langs->trans(
'EditBookmarks') : $langs->trans(
'ListOfBookmarks')).
'...</option>';
133 if (!empty($user->rights->bookmark->creer)) {
134 if (!preg_match(
'/bookmarks\/card.php/', $_SERVER[
'PHP_SELF'])) {
135 $urltoadd = DOL_URL_ROOT.
'/bookmarks/card.php?action=create&url='.urlencode($url);
136 $searchForm .=
'<option value="newbookmark" class="optionblue" rel="'.dol_escape_htmltag($urltoadd).
'"';
137 $searchForm .=
' data-html="'.dol_escape_htmltag(
img_picto(
'',
'bookmark').
' '.$langs->trans(
'AddThisPageToBookmarks').
'...').
'">'.
dol_escape_htmltag($langs->trans(
'AddThisPageToBookmarks').
'...').
'</option>';
141 while ((empty($conf->global->BOOKMARKS_SHOW_IN_MENU) || $i < $conf->global->BOOKMARKS_SHOW_IN_MENU) && $obj = $db->fetch_object($resql)) {
142 $searchForm .=
'<option name="bookmark'.$obj->rowid.
'" value="'.$obj->rowid.
'" '.($obj->target == 1 ?
' target="_blank" rel="noopener noreferrer"' :
'').
' rel="'.
dol_escape_htmltag($obj->url).
'" >';
144 $searchForm .=
'</option>';
148 $searchForm .=
'</select>';
154 $searchForm .=
'</form>';
157 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
160 $html .=
'<!-- script to open selected choice -->
162 $(document).ready(function () {
163 jQuery("#boxbookmark").change(function() {
164 var urlselected = jQuery("#boxbookmark option:selected").attr("rel");
165 if (! urlselected) console.log("Error, failed to get the URL to jump to from the rel attribute");
166 var urltarget = jQuery("#boxbookmark option:selected").attr("target");
167 if (! urltarget) { urltarget=""; }
168 jQuery("form#top-menu-action-bookmark").attr("target",urltarget);
169 jQuery("form#top-menu-action-bookmark").attr("action",urlselected);
171 console.log("We change select bookmark. We choose urlselected="+urlselected+" with target="+urltarget);
173 // Method is POST for internal link, GET for external
174 if (urlselected.startsWith(\'http\'))
176 var newmethod=\'GET\';
177 jQuery("form#top-menu-action-bookmark").attr("method", newmethod);
178 console.log("We change method to newmethod="+newmethod);
179 jQuery("form#top-menu-action-bookmark").submit();
180 console.log("We restore method to POST");
181 jQuery("form#top-menu-action-bookmark").attr("method", \'POST\');
185 jQuery("form#top-menu-action-bookmark").submit();
192 <!-- search input -->
193 <div class="dropdown-header bookmark-header">
199 <!-- Menu bookmark tools-->
200 <div class="bookmark-footer">
202 <div class="clearboth"></div>
207 <!-- Menu Body bookmarks -->
208 <div class="bookmark-body dropdown-body">'.$bookmarkList.
'
209 <span id="top-bookmark-search-nothing-found" class="'.($bookmarkNb ?
'hidden-search-result ' :
'').
'opacitymedium">'.
dol_escape_htmltag($langs->trans(
"NoBookmarkFound")).
'</span>
213 $html .=
'<!-- script to open/close the popup -->
215 jQuery(document).on("keyup", "#top-bookmark-search-input", function () {
216 console.log("keyup in bookmark search input");
218 var filter = $(this).val(), count = 0;
219 jQuery("#dropdown-bookmarks-list .bookmark-item").each(function () {
220 if ($(this).text().search(new RegExp(filter, "i")) < 0) {
221 $(this).addClass("hidden-search-result");
223 $(this).removeClass("hidden-search-result");
227 jQuery("#top-bookmark-search-filter-count").text(count);
229 jQuery("#top-bookmark-search-nothing-found").removeClass("hidden-search-result");
231 jQuery("#top-bookmark-search-nothing-found").addClass("hidden-search-result");
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...