This commit is contained in:
Frédéric FRANCE 2020-12-16 20:15:48 +01:00
parent 2cc51c1aef
commit 3b19151c18
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
2 changed files with 73 additions and 74 deletions

View File

@ -28,20 +28,21 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
// Load translation files required by the page // Load translation files required by the page
$langs->load("admin"); $langs->load("admin");
if (!$user->admin) if (!$user->admin) {
accessforbidden(); accessforbidden();
}
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
if ($action == 'setvalue') if ($action == 'setvalue') {
{
$showmenu = GETPOST('BOOKMARKS_SHOW_IN_MENU', 'alpha'); $showmenu = GETPOST('BOOKMARKS_SHOW_IN_MENU', 'alpha');
$res = dolibarr_set_const($db, "BOOKMARKS_SHOW_IN_MENU", $showmenu, 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "BOOKMARKS_SHOW_IN_MENU", $showmenu, 'chaine', 0, '', $conf->entity);
if (!$res > 0) $error++; if (!$res > 0) {
$error++;
}
if (!$error) if (!$error) {
{
$db->commit(); $db->commit();
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
} else { } else {

View File

@ -38,20 +38,23 @@ function printDropdownBookmarksList()
$url = $_SERVER["PHP_SELF"]; $url = $_SERVER["PHP_SELF"];
if (!empty($_SERVER["QUERY_STRING"])) if (!empty($_SERVER["QUERY_STRING"])) {
{
$url .= (dol_escape_htmltag($_SERVER["QUERY_STRING"]) ? '?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]) : ''); $url .= (dol_escape_htmltag($_SERVER["QUERY_STRING"]) ? '?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]) : '');
} else { } else {
global $sortfield, $sortorder; global $sortfield, $sortorder;
$tmpurl = ''; $tmpurl = '';
// No urlencode, all param $url will be urlencoded later // No urlencode, all param $url will be urlencoded later
if ($sortfield) $tmpurl .= ($tmpurl ? '&' : '').'sortfield='.$sortfield; if ($sortfield) {
if ($sortorder) $tmpurl .= ($tmpurl ? '&' : '').'sortorder='.$sortorder; $tmpurl .= ($tmpurl ? '&' : '').'sortfield='.$sortfield;
if (is_array($_POST)) }
{ if ($sortorder) {
foreach ($_POST as $key => $val) $tmpurl .= ($tmpurl ? '&' : '').'sortorder='.$sortorder;
{ }
if (preg_match('/^search_/', $key) && $val != '') $tmpurl .= ($tmpurl ? '&' : '').$key.'='.$val; if (is_array($_POST)) {
foreach ($_POST as $key => $val) {
if (preg_match('/^search_/', $key) && $val != '') {
$tmpurl .= ($tmpurl ? '&' : '').$key.'='.$val;
}
} }
} }
$url .= ($tmpurl ? '?'.$tmpurl : ''); $url .= ($tmpurl ? '?'.$tmpurl : '');
@ -68,8 +71,7 @@ function printDropdownBookmarksList()
// Url to go on create new bookmark page // Url to go on create new bookmark page
$newbtn = ''; $newbtn = '';
if (!empty($user->rights->bookmark->creer)) if (!empty($user->rights->bookmark->creer)) {
{
//$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&urlsource='.urlencode($url).'&url='.urlencode($url); //$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); $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).'" >'; $newbtn .= '<a class="top-menu-dropdown-link" title="'.$langs->trans('AddThisPageToBookmarks').'" href="'.dol_escape_htmltag($urltoadd).'" >';
@ -81,13 +83,11 @@ function printDropdownBookmarksList()
$sql .= " WHERE (fk_user = ".$user->id." OR fk_user is NULL OR fk_user = 0)"; $sql .= " WHERE (fk_user = ".$user->id." OR fk_user is NULL OR fk_user = 0)";
$sql .= " AND entity IN (".getEntity('bookmarks').")"; $sql .= " AND entity IN (".getEntity('bookmarks').")";
$sql .= " ORDER BY position"; $sql .= " ORDER BY position";
if ($resql = $db->query($sql)) if ($resql = $db->query($sql)) {
{
if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
$bookmarkList = '<div id="dropdown-bookmarks-list" >'; $bookmarkList = '<div id="dropdown-bookmarks-list" >';
$i = 0; $i = 0;
while ((empty($conf->global->BOOKMARKS_SHOW_IN_MENU) || $i < $conf->global->BOOKMARKS_SHOW_IN_MENU) && $obj = $db->fetch_object($resql)) while ((empty($conf->global->BOOKMARKS_SHOW_IN_MENU) || $i < $conf->global->BOOKMARKS_SHOW_IN_MENU) && $obj = $db->fetch_object($resql)) {
{
$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"' : '').' href="'.dol_escape_htmltag($obj->url).'" >'; $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"' : '').' href="'.dol_escape_htmltag($obj->url).'" >';
$bookmarkList .= dol_escape_htmltag($obj->title); $bookmarkList .= dol_escape_htmltag($obj->title);
$bookmarkList .= '</a>'; $bookmarkList .= '</a>';
@ -104,15 +104,13 @@ function printDropdownBookmarksList()
$searchForm .= ' data-html="'.dol_escape_htmltag(img_picto('', 'bookmark').' '.($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...').'">'; $searchForm .= ' data-html="'.dol_escape_htmltag(img_picto('', 'bookmark').' '.($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...').'">';
$searchForm .= dol_escape_htmltag($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...</option>'; $searchForm .= dol_escape_htmltag($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...</option>';
// Url to go on create new bookmark page // Url to go on create new bookmark page
if (!empty($user->rights->bookmark->creer)) if (!empty($user->rights->bookmark->creer)) {
{
$urltoadd = DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;url='.urlencode($url); $urltoadd = DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;url='.urlencode($url);
$searchForm .= '<option value="newbookmark" class="optionblue" rel="'.dol_escape_htmltag($urltoadd).'"'; $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>'; $searchForm .= ' data-html="'.dol_escape_htmltag(img_picto('', 'bookmark').' '.$langs->trans('AddThisPageToBookmarks').'...').'">'.dol_escape_htmltag($langs->trans('AddThisPageToBookmarks').'...').'</option>';
} }
$i = 0; $i = 0;
while ((empty($conf->global->BOOKMARKS_SHOW_IN_MENU) || $i < $conf->global->BOOKMARKS_SHOW_IN_MENU) && $obj = $db->fetch_object($resql)) while ((empty($conf->global->BOOKMARKS_SHOW_IN_MENU) || $i < $conf->global->BOOKMARKS_SHOW_IN_MENU) && $obj = $db->fetch_object($resql)) {
{
$searchForm .= '<option name="bookmark'.$obj->rowid.'" value="'.$obj->rowid.'" '.($obj->target == 1 ? ' target="_blank"' : '').' rel="'.dol_escape_htmltag($obj->url).'" >'; $searchForm .= '<option name="bookmark'.$obj->rowid.'" value="'.$obj->rowid.'" '.($obj->target == 1 ? ' target="_blank"' : '').' rel="'.dol_escape_htmltag($obj->url).'" >';
$searchForm .= dol_escape_htmltag($obj->title); $searchForm .= dol_escape_htmltag($obj->title);
$searchForm .= '</option>'; $searchForm .= '</option>';
@ -132,74 +130,74 @@ function printDropdownBookmarksList()
$html .= '<!-- script to open selected choice --> $html .= '<!-- script to open selected choice -->
<script> <script>
$(document).ready(function () { $(document).ready(function () {
jQuery("#boxbookmark").change(function() { jQuery("#boxbookmark").change(function() {
var urlselected = jQuery("#boxbookmark option:selected").attr("rel"); var urlselected = jQuery("#boxbookmark option:selected").attr("rel");
if (! urlselected) console.log("Error, failed to get the URL to jump to from the rel attribute"); if (! urlselected) console.log("Error, failed to get the URL to jump to from the rel attribute");
var urltarget = jQuery("#boxbookmark option:selected").attr("target"); var urltarget = jQuery("#boxbookmark option:selected").attr("target");
if (! urltarget) { urltarget=""; } if (! urltarget) { urltarget=""; }
jQuery("form#top-menu-action-bookmark").attr("target",urltarget); jQuery("form#top-menu-action-bookmark").attr("target",urltarget);
jQuery("form#top-menu-action-bookmark").attr("action",urlselected); jQuery("form#top-menu-action-bookmark").attr("action",urlselected);
console.log("We change select bookmark. We choose urlselected="+urlselected+" with target="+urltarget); console.log("We change select bookmark. We choose urlselected="+urlselected+" with target="+urltarget);
// Method is POST for internal link, GET for external // Method is POST for internal link, GET for external
if (urlselected.startsWith(\'http\')) if (urlselected.startsWith(\'http\'))
{ {
var newmethod=\'GET\'; var newmethod=\'GET\';
jQuery("form#top-menu-action-bookmark").attr("method", newmethod); jQuery("form#top-menu-action-bookmark").attr("method", newmethod);
console.log("We change method to newmethod="+newmethod); console.log("We change method to newmethod="+newmethod);
jQuery("form#top-menu-action-bookmark").submit(); jQuery("form#top-menu-action-bookmark").submit();
console.log("We restore method to POST"); console.log("We restore method to POST");
jQuery("form#top-menu-action-bookmark").attr("method", \'POST\'); jQuery("form#top-menu-action-bookmark").attr("method", \'POST\');
} }
else else
{ {
jQuery("form#top-menu-action-bookmark").submit(); jQuery("form#top-menu-action-bookmark").submit();
} }
}); });
}) })
</script>'; </script>';
} else { } else {
$html = ' $html = '
<!-- search input --> <!-- search input -->
<div class="dropdown-header bookmark-header"> <div class="dropdown-header bookmark-header">
' . $searchForm.' ' . $searchForm.'
</div> </div>
'; ';
$html .= ' $html .= '
<!-- Menu Body --> <!-- Menu Body -->
<div class="bookmark-body dropdown-body"> <div class="bookmark-body dropdown-body">
'.$bookmarkList.' '.$bookmarkList.'
</div> </div>
'; ';
$html .= ' $html .= '
<!-- Menu Footer--> <!-- Menu Footer-->
<div class="bookmark-footer"> <div class="bookmark-footer">
'.$newbtn.$listbtn.' '.$newbtn.$listbtn.'
<div style="clear:both;"></div> <div style="clear:both;"></div>
</div> </div>
'; ';
$html .= '<!-- script to open/close the popup --> $html .= '<!-- script to open/close the popup -->
<script> <script>
$( document ).on("keyup", "#top-bookmark-search-input", function () { $( document ).on("keyup", "#top-bookmark-search-input", function () {
var filter = $(this).val(), count = 0; var filter = $(this).val(), count = 0;
$("#dropdown-bookmarks-list .bookmark-item").each(function () { $("#dropdown-bookmarks-list .bookmark-item").each(function () {
if ($(this).text().search(new RegExp(filter, "i")) < 0) { if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).addClass("hidden-search-result"); $(this).addClass("hidden-search-result");
} else { } else {
$(this).removeClass("hidden-search-result"); $(this).removeClass("hidden-search-result");
count++; count++;
} }
}); });
$("#top-bookmark-search-filter-count").text(count); $("#top-bookmark-search-filter-count").text(count);
}); });
</script>'; </script>';
} }
return $html; return $html;