2009-01-23 01:47:23 +01:00
|
|
|
<?php
|
|
|
|
|
/* Copyright (C) 2009 Laurent Destailleur <eldy@users.sourceforge.net>
|
2024-09-25 22:21:31 +02:00
|
|
|
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
|
2009-01-23 01:47:23 +01:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2009-01-23 01:47:23 +01:00
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2019-09-23 21:55:30 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2009-01-23 01:47:23 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2010-07-21 14:35:56 +02:00
|
|
|
* \file htdocs/bookmarks/bookmarks.lib.php
|
2009-01-23 01:47:23 +01:00
|
|
|
* \ingroup bookmarks
|
|
|
|
|
* \brief File with library for bookmark module
|
|
|
|
|
*/
|
|
|
|
|
|
2019-09-29 11:47:34 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add area with bookmarks in top menu
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2019-10-17 20:59:42 +02:00
|
|
|
function printDropdownBookmarksList()
|
2019-09-29 11:47:34 +02:00
|
|
|
{
|
2024-03-28 17:10:22 +01:00
|
|
|
global $user, $db, $langs, $sortfield, $sortorder;
|
2020-10-31 14:32:18 +01:00
|
|
|
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php';
|
|
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
|
|
|
|
|
|
|
|
|
|
$langs->load("bookmarks");
|
|
|
|
|
|
2022-09-02 10:55:15 +02:00
|
|
|
$authorized_var=array('limit','optioncss','contextpage');
|
2020-10-31 14:32:18 +01:00
|
|
|
$url = $_SERVER["PHP_SELF"];
|
2023-02-19 19:12:47 +01:00
|
|
|
$url_param = array();
|
2020-12-16 20:15:48 +01:00
|
|
|
if (!empty($_SERVER["QUERY_STRING"])) {
|
2024-03-28 17:10:22 +01:00
|
|
|
if (is_array($_GET)) { // Parse the original GET URL. So we must keep $_GET here.
|
2022-09-02 10:42:27 +02:00
|
|
|
foreach ($_GET as $key => $val) {
|
2022-09-18 09:24:19 +02:00
|
|
|
if (is_array($val)) {
|
|
|
|
|
foreach ($val as $tmpsubval) {
|
|
|
|
|
$url_param[] = http_build_query(array(dol_escape_htmltag($key).'[]' => dol_escape_htmltag($tmpsubval)));
|
|
|
|
|
}
|
|
|
|
|
} elseif ($val != '') {
|
|
|
|
|
$url_param[$key] = http_build_query(array(dol_escape_htmltag($key) => dol_escape_htmltag($val)));
|
2020-12-16 20:15:48 +01:00
|
|
|
}
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
2022-09-02 10:42:27 +02:00
|
|
|
}
|
2023-01-19 13:40:37 +01:00
|
|
|
|
2022-09-02 10:42:27 +02:00
|
|
|
$tmpurl = '';
|
|
|
|
|
// No urlencode, all param $url will be urlencoded later
|
|
|
|
|
if ($sortfield) {
|
|
|
|
|
$tmpurl .= ($tmpurl ? '&' : '').'sortfield='.urlencode($sortfield);
|
|
|
|
|
}
|
|
|
|
|
if ($sortorder) {
|
|
|
|
|
$tmpurl .= ($tmpurl ? '&' : '').'sortorder='.urlencode($sortorder);
|
|
|
|
|
}
|
2022-10-10 14:23:02 +02:00
|
|
|
if (!empty($_POST) && is_array($_POST)) {
|
2022-09-02 10:42:27 +02:00
|
|
|
foreach ($_POST as $key => $val) {
|
|
|
|
|
if ((preg_match('/^search_/', $key) || in_array($key, $authorized_var))
|
|
|
|
|
&& $val != ''
|
|
|
|
|
&& !array_key_exists($key, $url_param)) {
|
2023-01-19 13:40:37 +01:00
|
|
|
if (is_array($val)) {
|
|
|
|
|
foreach ($val as $tmpsubval) {
|
|
|
|
|
$url_param[] = http_build_query(array(dol_escape_htmltag($key).'[]' => dol_escape_htmltag($tmpsubval)));
|
|
|
|
|
}
|
|
|
|
|
} elseif ($val != '') {
|
|
|
|
|
$url_param[$key] = http_build_query(array(dol_escape_htmltag($key) => dol_escape_htmltag($val)));
|
|
|
|
|
}
|
2022-09-02 10:42:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-18 09:24:19 +02:00
|
|
|
|
2022-09-02 10:42:27 +02:00
|
|
|
$url .= ($tmpurl ? '?'.$tmpurl : '');
|
|
|
|
|
if (!empty($url_param)) {
|
2023-02-19 19:12:47 +01:00
|
|
|
$url .= (strpos($url, '?') > 0 ? '&' : '?').implode('&', $url_param);
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$searchForm = '<!-- form with POST method by default, will be replaced with GET for external link by js -->'."\n";
|
2023-11-27 11:39:32 +01:00
|
|
|
$searchForm .= '<form id="top-menu-action-bookmark" name="actionbookmark" method="POST" action=""'.(!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER') ? ' onsubmit="return false"' : '').'>';
|
2020-10-31 14:32:18 +01:00
|
|
|
$searchForm .= '<input type="hidden" name="token" value="'.newToken().'">';
|
|
|
|
|
|
|
|
|
|
// Url to go on create new bookmark page
|
|
|
|
|
$newbtn = '';
|
2023-10-15 15:32:35 +02:00
|
|
|
if ($user->hasRight('bookmark', 'creer')) {
|
2021-08-10 13:01:57 +02:00
|
|
|
if (!preg_match('/bookmarks\/card.php/', $_SERVER['PHP_SELF'])) {
|
|
|
|
|
//$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&urlsource='.urlencode($url).'&url='.urlencode($url);
|
|
|
|
|
$urltoadd = DOL_URL_ROOT.'/bookmarks/card.php?action=create&url='.urlencode($url);
|
|
|
|
|
$newbtn .= '<a class="top-menu-dropdown-link" title="'.$langs->trans('AddThisPageToBookmarks').'" href="'.dol_escape_htmltag($urltoadd).'" >';
|
2024-09-28 17:05:44 +02:00
|
|
|
$newbtn .= img_picto('', 'add', '', 0, 0, 0, '', 'pictofixedwidth paddingright').dol_escape_htmltag($langs->trans('AddThisPageToBookmarks')).'</a>';
|
2021-08-10 13:01:57 +02:00
|
|
|
}
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-02 11:27:16 +02:00
|
|
|
// Url to list/edit bookmark
|
|
|
|
|
$listbtn = '<a class="top-menu-dropdown-link" title="'.dol_escape_htmltag($langs->trans('Bookmarks')).'" href="'.DOL_URL_ROOT.'/bookmarks/list.php">';
|
2024-09-28 17:05:44 +02:00
|
|
|
$listbtn .= img_picto('', 'edit', 'class="pictofixedwidth paddingright opacitymedium"').$langs->trans('EditBookmarks').'</a>';
|
2022-09-02 11:27:16 +02:00
|
|
|
|
2022-09-10 14:39:36 +02:00
|
|
|
$bookmarkList = '';
|
2023-02-19 18:11:41 +01:00
|
|
|
$bookmarkNb = 0;
|
2020-10-31 14:32:18 +01:00
|
|
|
// Menu with list of bookmarks
|
|
|
|
|
$sql = "SELECT rowid, title, url, target FROM ".MAIN_DB_PREFIX."bookmark";
|
2021-06-09 15:36:47 +02:00
|
|
|
$sql .= " WHERE (fk_user = ".((int) $user->id)." OR fk_user is NULL OR fk_user = 0)";
|
2020-10-31 14:32:18 +01:00
|
|
|
$sql .= " AND entity IN (".getEntity('bookmarks').")";
|
|
|
|
|
$sql .= " ORDER BY position";
|
2020-12-16 20:15:48 +01:00
|
|
|
if ($resql = $db->query($sql)) {
|
2023-11-27 11:39:32 +01:00
|
|
|
if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$bookmarkList = '<div id="dropdown-bookmarks-list" >';
|
|
|
|
|
$i = 0;
|
2024-01-05 04:18:53 +01:00
|
|
|
while ((!getDolGlobalString('BOOKMARKS_SHOW_IN_MENU') || $i < getDolGlobalInt('BOOKMARKS_SHOW_IN_MENU')) && $obj = $db->fetch_object($resql)) {
|
2021-11-22 02:35:55 +01:00
|
|
|
$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).'" >';
|
2020-10-31 14:32:18 +01:00
|
|
|
$bookmarkList .= dol_escape_htmltag($obj->title);
|
|
|
|
|
$bookmarkList .= '</a>';
|
|
|
|
|
$i++;
|
2023-02-19 18:11:41 +01:00
|
|
|
$bookmarkNb++;
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
|
|
|
|
$bookmarkList .= '</div>';
|
|
|
|
|
|
|
|
|
|
$searchForm .= '<input name="bookmark" id="top-bookmark-search-input" class="dropdown-search-input" placeholder="'.$langs->trans('Bookmarks').'" autocomplete="off" >';
|
|
|
|
|
} else {
|
2024-02-29 00:52:56 +01:00
|
|
|
$searchForm .= '<select name="bookmark" id="boxbookmark" class="topmenu-bookmark-dropdown .dropdown-toggle maxwidth100">';
|
2020-10-31 14:32:18 +01:00
|
|
|
$searchForm .= '<option hidden value="listbookmarks" class="optiongrey" selected rel="'.DOL_URL_ROOT.'/bookmarks/list.php">'.$langs->trans('Bookmarks').'</option>';
|
|
|
|
|
$searchForm .= '<option value="listbookmark" class="optionblue" rel="'.dol_escape_htmltag(DOL_URL_ROOT.'/bookmarks/list.php').'" ';
|
2023-10-15 15:32:35 +02:00
|
|
|
$searchForm .= ' data-html="'.dol_escape_htmltag(img_picto('', 'bookmark').' '.($user->hasRight('bookmark', 'creer') ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...').'">';
|
|
|
|
|
$searchForm .= dol_escape_htmltag($user->hasRight('bookmark', 'creer') ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...</option>';
|
2020-10-31 14:32:18 +01:00
|
|
|
// Url to go on create new bookmark page
|
2023-10-15 15:32:35 +02:00
|
|
|
if ($user->hasRight('bookmark', 'creer')) {
|
2021-08-10 13:06:57 +02:00
|
|
|
if (!preg_match('/bookmarks\/card.php/', $_SERVER['PHP_SELF'])) {
|
|
|
|
|
$urltoadd = DOL_URL_ROOT.'/bookmarks/card.php?action=create&url='.urlencode($url);
|
|
|
|
|
$searchForm .= '<option value="newbookmark" class="optionblue" rel="'.dol_escape_htmltag($urltoadd).'"';
|
|
|
|
|
$searchForm .= ' data-html="'.dol_escape_htmltag(img_picto('', 'bookmark').' '.$langs->trans('AddThisPageToBookmarks').'...').'">'.dol_escape_htmltag($langs->trans('AddThisPageToBookmarks').'...').'</option>';
|
|
|
|
|
}
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
|
|
|
|
$i = 0;
|
2024-01-05 04:18:53 +01:00
|
|
|
while ((!getDolGlobalString('BOOKMARKS_SHOW_IN_MENU') || $i < getDolGlobalInt('BOOKMARKS_SHOW_IN_MENU')) && $obj = $db->fetch_object($resql)) {
|
2021-11-22 02:35:55 +01:00
|
|
|
$searchForm .= '<option name="bookmark'.$obj->rowid.'" value="'.$obj->rowid.'" '.($obj->target == 1 ? ' target="_blank" rel="noopener noreferrer"' : '').' rel="'.dol_escape_htmltag($obj->url).'" >';
|
2020-10-31 14:32:18 +01:00
|
|
|
$searchForm .= dol_escape_htmltag($obj->title);
|
|
|
|
|
$searchForm .= '</option>';
|
|
|
|
|
$i++;
|
2023-02-19 18:11:41 +01:00
|
|
|
$bookmarkNb++;
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
|
|
|
|
$searchForm .= '</select>';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
dol_print_error($db);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$searchForm .= '</form>';
|
|
|
|
|
|
|
|
|
|
// Generate the return string
|
2023-11-27 11:39:32 +01:00
|
|
|
if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
|
2020-10-31 14:32:18 +01:00
|
|
|
$html = $searchForm;
|
|
|
|
|
|
|
|
|
|
$html .= '<!-- script to open selected choice -->
|
2020-03-25 15:40:02 +01:00
|
|
|
<script>
|
2020-12-16 20:15:48 +01:00
|
|
|
$(document).ready(function () {
|
|
|
|
|
jQuery("#boxbookmark").change(function() {
|
|
|
|
|
var urlselected = jQuery("#boxbookmark option:selected").attr("rel");
|
2020-03-25 15:40:02 +01:00
|
|
|
if (! urlselected) console.log("Error, failed to get the URL to jump to from the rel attribute");
|
2020-12-16 20:15:48 +01:00
|
|
|
var urltarget = jQuery("#boxbookmark option:selected").attr("target");
|
|
|
|
|
if (! urltarget) { urltarget=""; }
|
|
|
|
|
jQuery("form#top-menu-action-bookmark").attr("target",urltarget);
|
|
|
|
|
jQuery("form#top-menu-action-bookmark").attr("action",urlselected);
|
|
|
|
|
|
|
|
|
|
console.log("We change select bookmark. We choose urlselected="+urlselected+" with target="+urltarget);
|
|
|
|
|
|
|
|
|
|
// Method is POST for internal link, GET for external
|
|
|
|
|
if (urlselected.startsWith(\'http\'))
|
|
|
|
|
{
|
|
|
|
|
var newmethod=\'GET\';
|
|
|
|
|
jQuery("form#top-menu-action-bookmark").attr("method", newmethod);
|
|
|
|
|
console.log("We change method to newmethod="+newmethod);
|
|
|
|
|
jQuery("form#top-menu-action-bookmark").submit();
|
|
|
|
|
console.log("We restore method to POST");
|
2020-03-25 15:40:02 +01:00
|
|
|
jQuery("form#top-menu-action-bookmark").attr("method", \'POST\');
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-12-16 20:15:48 +01:00
|
|
|
jQuery("form#top-menu-action-bookmark").submit();
|
2020-03-25 15:40:02 +01:00
|
|
|
}
|
2020-12-16 20:15:48 +01:00
|
|
|
});
|
|
|
|
|
})
|
2020-03-25 15:40:02 +01:00
|
|
|
</script>';
|
2020-10-31 14:32:18 +01:00
|
|
|
} else {
|
|
|
|
|
$html = '
|
2020-12-16 20:15:48 +01:00
|
|
|
<!-- search input -->
|
|
|
|
|
<div class="dropdown-header bookmark-header">
|
|
|
|
|
' . $searchForm.'
|
|
|
|
|
</div>
|
|
|
|
|
';
|
2020-03-25 15:40:02 +01:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$html .= '
|
2022-09-02 11:27:16 +02:00
|
|
|
<!-- Menu bookmark tools-->
|
2020-12-16 20:15:48 +01:00
|
|
|
<div class="bookmark-footer">
|
|
|
|
|
'.$newbtn.$listbtn.'
|
2023-02-18 14:00:25 +01:00
|
|
|
<div class="clearboth"></div>
|
2020-12-16 20:15:48 +01:00
|
|
|
</div>
|
|
|
|
|
';
|
2020-03-25 15:40:02 +01:00
|
|
|
|
2023-02-19 18:25:02 +01:00
|
|
|
$html .= '
|
2023-05-14 17:38:08 +02:00
|
|
|
<!-- Menu Body bookmarks -->
|
2023-02-19 18:25:02 +01:00
|
|
|
<div class="bookmark-body dropdown-body">'.$bookmarkList.'
|
|
|
|
|
<span id="top-bookmark-search-nothing-found" class="'.($bookmarkNb ? 'hidden-search-result ' : '').'opacitymedium">'.dol_escape_htmltag($langs->trans("NoBookmarkFound")).'</span>
|
2023-02-19 18:11:41 +01:00
|
|
|
</div>
|
|
|
|
|
';
|
2022-09-02 11:27:16 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
$html .= '<!-- script to open/close the popup -->
|
2020-03-25 15:40:02 +01:00
|
|
|
<script>
|
2022-12-24 15:32:20 +01:00
|
|
|
jQuery(document).on("keyup", "#top-bookmark-search-input", function () {
|
2022-09-02 11:27:16 +02:00
|
|
|
console.log("keyup in bookmark search input");
|
2020-12-16 20:15:48 +01:00
|
|
|
|
|
|
|
|
var filter = $(this).val(), count = 0;
|
2022-12-24 15:32:20 +01:00
|
|
|
jQuery("#dropdown-bookmarks-list .bookmark-item").each(function () {
|
2020-12-16 20:15:48 +01:00
|
|
|
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
|
|
|
|
|
$(this).addClass("hidden-search-result");
|
|
|
|
|
} else {
|
|
|
|
|
$(this).removeClass("hidden-search-result");
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-12-24 15:32:20 +01:00
|
|
|
jQuery("#top-bookmark-search-filter-count").text(count);
|
2022-09-02 11:27:16 +02:00
|
|
|
if (count == 0) {
|
|
|
|
|
jQuery("#top-bookmark-search-nothing-found").removeClass("hidden-search-result");
|
|
|
|
|
} else {
|
|
|
|
|
jQuery("#top-bookmark-search-nothing-found").addClass("hidden-search-result");
|
|
|
|
|
}
|
2020-12-16 20:15:48 +01:00
|
|
|
});
|
|
|
|
|
</script>';
|
2020-10-31 14:32:18 +01:00
|
|
|
}
|
2019-09-29 11:47:34 +02:00
|
|
|
|
2020-10-31 14:32:18 +01:00
|
|
|
return $html;
|
2019-09-29 19:59:12 +02:00
|
|
|
}
|