From 92287ab18d0473e6315f7b4fcdd11623e2cfeda7 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Tue, 27 Jun 2017 11:12:03 +0200
Subject: [PATCH] Fix url suggested for bookmark did not always include params

---
 htdocs/bookmarks/bookmarks.lib.php         | 24 ++++++++++++++++++++--
 htdocs/bookmarks/card.php                  | 20 ++++++++++--------
 htdocs/core/menus/standard/auguria.lib.php | 20 +++++++++---------
 3 files changed, 43 insertions(+), 21 deletions(-)

diff --git a/htdocs/bookmarks/bookmarks.lib.php b/htdocs/bookmarks/bookmarks.lib.php
index b6a022db898..8f8295f0e53 100644
--- a/htdocs/bookmarks/bookmarks.lib.php
+++ b/htdocs/bookmarks/bookmarks.lib.php
@@ -40,7 +40,26 @@ function printBookmarksList($aDb, $aLangs)
 
 	$langs->load("bookmarks");
 
-	$url= $_SERVER["PHP_SELF"].(dol_escape_htmltag($_SERVER["QUERY_STRING"])?'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]):'');
+	$url= $_SERVER["PHP_SELF"];
+
+	if (! empty($_SERVER["QUERY_STRING"]))
+	{
+	    $url.=(dol_escape_htmltag($_SERVER["QUERY_STRING"])?'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]):'');
+	}
+	else
+	{
+	    global $sortfield,$sortorder;
+	    $tmpurl='';
+	    // No urlencode, all param $url will be urlencoded later
+	    if ($sortfield) $tmpurl.=($tmpurl?'&':'').'sortfield='.$sortfield;
+	    if ($sortorder) $tmpurl.=($tmpurl?'&':'').'sortorder='.$sortorder;
+	    foreach($_POST as $key => $val)
+	    {
+            if (preg_match('/^search_/', $key) && $val != '') $tmpurl.=($tmpurl?'&':'').$key.'='.$val;
+	    }
+
+	    $url.=($tmpurl?'?'.$tmpurl:'');
+	}
 
 	$ret = '';
 
@@ -55,7 +74,8 @@ function printBookmarksList($aDb, $aLangs)
 	// Url to go on create new bookmark page
 	if ($user->rights->bookmark->creer)
 	{
-    	$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;urlsource='.urlencode($url).'&amp;url='.urlencode($url);
+    	//$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;urlsource='.urlencode($url).'&amp;url='.urlencode($url);
+	    $urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&amp;url='.urlencode($url);
     	$ret.= '<option value="newbookmark" class="optionblue" rel="'.dol_escape_htmltag($urltoadd).'">'.dol_escape_htmltag($langs->trans('AddThisPageToBookmarks')).'...</option>';
 	}
 	// Menu with all bookmarks
diff --git a/htdocs/bookmarks/card.php b/htdocs/bookmarks/card.php
index a9d4a39ef85..e9722669e7d 100644
--- a/htdocs/bookmarks/card.php
+++ b/htdocs/bookmarks/card.php
@@ -39,6 +39,7 @@ $id=GETPOST("id");
 $action=GETPOST("action","alpha");
 $title=GETPOST("title","alpha");
 $url=GETPOST("url","alpha");
+$urlsource=GETPOST("urlsource","alpha");
 $target=GETPOST("target","alpha");
 $userid=GETPOST("userid","int");
 $position=GETPOST("position","int");
@@ -64,7 +65,7 @@ if ($action == 'add' || $action == 'addproduct' || $action == 'update')
 
 	if (GETPOST("cancel"))
 	{
-		if (empty($backtopage)) $backtopage=(GETPOST("urlsource")?GETPOST("urlsource"):((! empty($url))?$url:DOL_URL_ROOT.'/bookmarks/list.php'));
+		if (empty($backtopage)) $backtopage=($urlsource?$urlsource:((! empty($url))?$url:DOL_URL_ROOT.'/bookmarks/list.php'));
 		header("Location: ".$backtopage);
 		exit;
 	}
@@ -97,7 +98,7 @@ if ($action == 'add' || $action == 'addproduct' || $action == 'update')
 
 		if ($res > 0)
 		{
-			if (empty($backtopage)) $backtopage=(GETPOST("urlsource")?GETPOST("urlsource"):DOL_URL_ROOT.'/bookmarks/list.php');
+			if (empty($backtopage)) $backtopage=($urlsource?$urlsource:((! empty($url))?$url:DOL_URL_ROOT.'/bookmarks/list.php'));
 			header("Location: ".$backtopage);
 			exit;
 		}
@@ -121,6 +122,7 @@ if ($action == 'add' || $action == 'addproduct' || $action == 'update')
 	}
 }
 
+
 /*
  * View
  */
@@ -153,15 +155,15 @@ if ($action == 'create')
 
 	print load_fiche_titre($langs->trans("NewBookmark"));
 
-	dol_fiche_head($head, $hselected, $langs->trans("Bookmark"),0,'bookmark');
+	dol_fiche_head($head, $hselected, $langs->trans("Bookmark"), 0, 'bookmark');
 
 	print '<table class="border" width="100%">';
 
 	print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("BookmarkTitle").'</td><td><input id="titlebookmark" class="flat minwidth100" name="title" value="'.$title.'"></td><td class="hideonsmartphone">'.$langs->trans("SetHereATitleForLink").'</td></tr>';
 	dol_set_focus('#titlebookmark');
-	
+
 	// Url
-	print '<tr><td class="fieldrequired">'.$langs->trans("UrlOrLink").'</td><td><input class="flat quatrevingtpercent" name="url" value="'.$url.'"></td><td class="hideonsmartphone">'.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'</td></tr>';
+	print '<tr><td class="fieldrequired">'.$langs->trans("UrlOrLink").'</td><td><input class="flat quatrevingtpercent" name="url" value="'.dol_escape_htmltag($url).'"></td><td class="hideonsmartphone">'.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'</td></tr>';
 
 	// Target
 	print '<tr><td>'.$langs->trans("BehaviourOnClick").'</td><td>';
@@ -219,14 +221,14 @@ if ($id > 0 && ! preg_match('/^add/i',$action))
 	}
 
 
-	dol_fiche_head($head, $hselected, $langs->trans("Bookmark"),0,'bookmark');
+	dol_fiche_head($head, $hselected, $langs->trans("Bookmark"), -1, 'bookmark');
 
 	$linkback = '<a href="'.DOL_URL_ROOT.'/bookmarks/list.php">'.$langs->trans("BackToList").'</a>';
-	
+
     dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', '', 0);
 
     print '<div class="fichecenter">';
-    
+
     print '<div class="underbanner clearboth"></div>';
 	print '<table class="border" width="100%">';
 
@@ -304,7 +306,7 @@ if ($id > 0 && ! preg_match('/^add/i',$action))
 	print '</table>';
 
 	print '</div>';
-	
+
 	dol_fiche_end();
 
 	if ($action == 'edit')
diff --git a/htdocs/core/menus/standard/auguria.lib.php b/htdocs/core/menus/standard/auguria.lib.php
index 6334696a99f..6b42e7ad500 100644
--- a/htdocs/core/menus/standard/auguria.lib.php
+++ b/htdocs/core/menus/standard/auguria.lib.php
@@ -301,6 +301,16 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM
         print "<!-- End SearchForm -->\n";
 	}
 
+	if (is_array($moredata) && ! empty($moredata['bookmarks']))
+	{
+	    print "\n";
+	    print "<!-- Begin Bookmarks -->\n";
+	    print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">'."\n";
+	    print $moredata['bookmarks'];
+	    print '</div>'."\n";
+	    print "<!-- End Bookmarks -->\n";
+	}
+
 	// We update newmenu with entries found into database
 	$menuArbo = new Menubase($db,'auguria');
 	$newmenu = $menuArbo->menuLeftCharger($newmenu,$mainmenu,$leftmenu,($user->societe_id?1:0),'auguria',$tabMenu);
@@ -564,16 +574,6 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM
 		if ($altok) print '<div class="blockvmenuend"></div>';    // End menu block
 	}
 
-	if (is_array($moredata) && ! empty($moredata['bookmarks']))
-	{
-	        print "\n";
-	        print "<!-- Begin Bookmarks -->\n";
-	        print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">'."\n";
-	        print $moredata['bookmarks'];
-	        print '</div>'."\n";
-	        print "<!-- End Bookmarks -->\n";
-	}
-
 	return count($menu_array);
 }
 
-- 
GitLab