33 global $user,
$db, $langs, $sortfield, $sortorder;
35 require_once DOL_DOCUMENT_ROOT.
'/bookmarks/class/bookmark.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions.lib.php';
38 $langs->load(
"bookmarks");
40 $authorized_var=array(
'limit',
'optioncss',
'contextpage');
41 $url = $_SERVER[
"PHP_SELF"];
43 if (!empty($_SERVER[
"QUERY_STRING"])) {
44 if (is_array($_GET)) {
45 foreach ($_GET as $key => $val) {
47 foreach ($val as $tmpsubval) {
50 } elseif ($val !=
'') {
60 $tmpurl .=
'sortfield='.urlencode($sortfield);
63 $tmpurl .= ($tmpurl ?
'&' :
'').
'sortorder='.urlencode($sortorder);
65 if (!empty($_POST) && is_array($_POST)) {
66 foreach ($_POST as $key => $val) {
67 if ((preg_match(
'/^search_/', $key) || in_array($key, $authorized_var))
69 && !array_key_exists($key, $url_param)) {
71 foreach ($val as $tmpsubval) {
74 } elseif ($val !=
'') {
81 $url .= ($tmpurl ?
'?'.$tmpurl :
'');
82 if (!empty($url_param)) {
83 $url .= (strpos($url,
'?') > 0 ?
'&' :
'?').implode(
'&', $url_param);
86 $searchForm =
'<!-- form with POST method by default, will be replaced with GET for external link by js -->'.
"\n";
87 $searchForm .=
'<form id="top-menu-action-bookmark" name="actionbookmark" method="POST" action=""'.(!
getDolGlobalString(
'MAIN_OPTIMIZEFORTEXTBROWSER') ?
' onsubmit="return false"' :
'').
'>';
88 $searchForm .=
'<input type="hidden" name="token" value="'.newToken().
'">';
92 if ($user->hasRight(
'bookmark',
'creer')) {
93 if (!preg_match(
'/bookmarks\/card.php/', $_SERVER[
'PHP_SELF'])) {
95 $urltoadd = DOL_URL_ROOT.
'/bookmarks/card.php?action=create&url='.urlencode($url);
96 $newbtn .=
'<a class="top-menu-dropdown-link" title="'.$langs->trans(
'AddThisPageToBookmarks').
'" href="'.
dol_escape_htmltag($urltoadd).
'" >';
97 $newbtn .=
img_picto(
'',
'add',
'', 0, 0, 0,
'',
'pictofixedwidth paddingright').dol_escape_htmltag($langs->trans(
'AddThisPageToBookmarks')).
'</a>';
102 $listbtn =
'<a class="top-menu-dropdown-link" title="'.dol_escape_htmltag($langs->trans(
'Bookmarks')).
'" href="'.DOL_URL_ROOT.
'/bookmarks/list.php">';
103 $listbtn .=
img_picto(
'',
'edit',
'class="pictofixedwidth paddingright opacitymedium"').$langs->trans(
'EditBookmarks').
'</a>';
108 $sql =
"SELECT rowid, title, url, target FROM ".MAIN_DB_PREFIX.
"bookmark";
109 $sql .=
" WHERE (fk_user = ".((int) $user->id).
" OR fk_user is NULL OR fk_user = 0)";
110 $sql .=
" AND entity IN (".getEntity(
'bookmarks').
")";
111 $sql .=
" ORDER BY position";
112 if ($resql =
$db->query($sql)) {
114 $bookmarkList =
'<div id="dropdown-bookmarks-list" >';
117 $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).
'" >';
119 $bookmarkList .=
'</a>';
123 $bookmarkList .=
'</div>';
125 $searchForm .=
'<input ';
126 $searchForm .=
' name="bookmark" ';
127 $searchForm .=
' id="top-bookmark-search-input" ';
128 $searchForm .=
' class="dropdown-search-input" ';
129 $searchForm .=
' placeholder="' . $langs->trans(
'Bookmarks') .
'" ';
130 $searchForm .=
' data-search-tool-target="#dropdown-bookmarks-list .bookmark-item" ';
131 $searchForm .=
' data-counter-target="#top-bookmark-search-filter-count" ';
132 $searchForm .=
' data-no-item-target="#top-bookmark-search-nothing-found" ';
133 $searchForm .=
' autocomplete="off" ';
136 $searchForm .=
'<select name="bookmark" id="boxbookmark" class="topmenu-bookmark-dropdown .dropdown-toggle maxwidth100">';
137 $searchForm .=
'<option hidden value="listbookmarks" class="optiongrey" selected rel="'.DOL_URL_ROOT.
'/bookmarks/list.php">'.$langs->trans(
'Bookmarks').
'</option>';
138 $searchForm .=
'<option value="listbookmark" class="optionblue" rel="'.dol_escape_htmltag(DOL_URL_ROOT.
'/bookmarks/list.php').
'" ';
139 $searchForm .=
' data-html="'.dol_escape_htmltag(
img_picto(
'',
'bookmark').
' '.($user->hasRight(
'bookmark',
'creer') ? $langs->trans(
'EditBookmarks') : $langs->trans(
'ListOfBookmarks')).
'...').
'">';
140 $searchForm .=
dol_escape_htmltag($user->hasRight(
'bookmark',
'creer') ? $langs->trans(
'EditBookmarks') : $langs->trans(
'ListOfBookmarks')).
'...</option>';
142 if ($user->hasRight(
'bookmark',
'creer')) {
143 if (!preg_match(
'/bookmarks\/card.php/', $_SERVER[
'PHP_SELF'])) {
144 $urltoadd = DOL_URL_ROOT.
'/bookmarks/card.php?action=create&url='.urlencode($url);
145 $searchForm .=
'<option value="newbookmark" class="optionblue" rel="'.dol_escape_htmltag($urltoadd).
'"';
146 $searchForm .=
' data-html="'.dol_escape_htmltag(
img_picto(
'',
'bookmark').
' '.$langs->trans(
'AddThisPageToBookmarks').
'...').
'">'.
dol_escape_htmltag($langs->trans(
'AddThisPageToBookmarks').
'...').
'</option>';
151 $searchForm .=
'<option name="bookmark'.$obj->rowid.
'" value="'.$obj->rowid.
'" '.($obj->target == 1 ?
' target="_blank" rel="noopener noreferrer"' :
'').
' rel="'.
dol_escape_htmltag($obj->url).
'" >';
153 $searchForm .=
'</option>';
157 $searchForm .=
'</select>';
163 $searchForm .=
'</form>';
169 $html .=
'<!-- script to open selected choice -->
171 $(document).ready(function () {
172 jQuery("#boxbookmark").change(function() {
173 var urlselected = jQuery("#boxbookmark option:selected").attr("rel");
174 if (! urlselected) console.log("Error, failed to get the URL to jump to from the rel attribute");
175 var urltarget = jQuery("#boxbookmark option:selected").attr("target");
176 if (! urltarget) { urltarget=""; }
177 jQuery("form#top-menu-action-bookmark").attr("target",urltarget);
178 jQuery("form#top-menu-action-bookmark").attr("action",urlselected);
180 console.log("We change select bookmark. We choose urlselected="+urlselected+" with target="+urltarget);
182 // Method is POST for internal link, GET for external
183 if (urlselected.startsWith(\'http\'))
185 var newmethod=\'GET\';
186 jQuery("form#top-menu-action-bookmark").attr("method", newmethod);
187 console.log("We change method to newmethod="+newmethod);
188 jQuery("form#top-menu-action-bookmark").submit();
189 console.log("We restore method to POST");
190 jQuery("form#top-menu-action-bookmark").attr("method", \'POST\');
194 jQuery("form#top-menu-action-bookmark").submit();
201 <!-- search input -->
202 <div class="dropdown-header bookmark-header">
208 <!-- Menu bookmark tools-->
209 <div class="bookmark-footer">
211 <div class="clearboth"></div>
216 <!-- Menu Body bookmarks -->
217 <div class="bookmark-body dropdown-body">'.$bookmarkList.
'
218 <span id="top-bookmark-search-nothing-found" class="'.($bookmarkNb ?
'hidden-search-result ' :
'').
'opacitymedium">'.
dol_escape_htmltag($langs->trans(
"NoBookmarkFound")).
'</span>
printDropdownBookmarksList()
Add area with bookmarks in top menu.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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...