From 93db51039c521666b988eb794a3c098d7b527438 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Thu, 17 Apr 2008 12:15:20 +0000
Subject: [PATCH] New: Go back to caller page if cancel

---
 htdocs/comm/action/fiche.php | 15 +++++++--------
 htdocs/comm/fiche.php        |  8 ++++----
 htdocs/contact/index.php     |  9 +++++----
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php
index c585f1632fc..a6f7471060f 100644
--- a/htdocs/comm/action/fiche.php
+++ b/htdocs/comm/action/fiche.php
@@ -65,14 +65,14 @@ if ($_POST["action"] == 'add_action')
 	
     if ($_POST['cancel'])
 	{
-		$back='';
-		if (! empty($_POST["back"])) $back=$_POST["back"];
-		if (! $back)
+		$backtopage='';
+		if (! empty($_POST["backtopage"])) $backtopage=$_POST["backtopage"];
+		if (! $backtopage)
 		{
-			if ($_POST['socid'] > 0) $back=DOL_URL_ROOT.'/comm/fiche.php?socid='.$_POST['socid'];
-			else $back=DOL_URL_ROOT.'/comm/action/indexactions.php';
+			if ($_POST['socid'] > 0) $backtopage=DOL_URL_ROOT.'/comm/fiche.php?socid='.$_POST['socid'];
+			else $backtopage=DOL_URL_ROOT.'/comm/action/indexactions.php';
 		}
-		header("Location: ".$back);
+		header("Location: ".$backtopage);
 		exit;	
 	}
 
@@ -411,9 +411,8 @@ if ($_GET["action"] == 'create')
 	}
 
 	print '<form name="action" action="fiche.php" method="post">';
-    if (! empty($_REQUEST["backtopage"])) print '<input type="hidden" name="from" value="'.($_REQUEST["from"] ? $_REQUEST["from"] : $_SERVER["HTTP_REFERER"]).'">';
 	print '<input type="hidden" name="action" value="add_action">';
-	print '<input type="hidden" name="back" value="'.$_SERVER['HTTP_REFERER'].'">';
+    if (! empty($_REQUEST["backtopage"])) print '<input type="hidden" name="backtopage" value="'.($_REQUEST["backtopage"] != 1 ? $_REQUEST["backtopage"] : $_SERVER["HTTP_REFERER"]).'">';
 
 	if ($_GET["actioncode"] == 'AC_RDV') print_titre ($langs->trans("AddActionRendezVous"));
 	else print_titre ($langs->trans("AddAnAction"));
diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php
index 709462d2521..cb59adb78f7 100644
--- a/htdocs/comm/fiche.php
+++ b/htdocs/comm/fiche.php
@@ -676,7 +676,7 @@ if ($socid > 0)
         // Lien click to dial
        	print '<td>';
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
-        	print '<a href="action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">';
+        	print '<a href="action/fiche.php?action=create&backtopage=1&actioncode=AC_TEL&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">';
         print dolibarr_print_phone($obj->phone);
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
     	    print '</a>';
@@ -684,14 +684,14 @@ if ($socid > 0)
     	print '</td>';
         print '<td>';
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
-       		print '<a href="action/fiche.php?action=create&actioncode=AC_FAX&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">';
+       		print '<a href="action/fiche.php?action=create&backtopage=1&actioncode=AC_FAX&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">';
         print dolibarr_print_phone($obj->fax);
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
         	print '</a>';
         print '&nbsp;</td>';
         print '<td>';
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
-        	print '<a href="action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">';
+        	print '<a href="action/fiche.php?action=create&backtopage=1&actioncode=AC_EMAIL&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">';
         print $obj->email;
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
         	print '</a>';
@@ -704,7 +704,7 @@ if ($socid > 0)
 
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
         {
-        	print '<td align="center"><a href="action/fiche.php?action=create&actioncode=AC_RDV&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">';
+        	print '<td align="center"><a href="action/fiche.php?action=create&backtopage=1&actioncode=AC_RDV&contactid='.$obj->rowid.'&socid='.$objsoc->id.'">';
             print img_object($langs->trans("Rendez-Vous"),"action");
         	print '</a></td>';
         }
diff --git a/htdocs/contact/index.php b/htdocs/contact/index.php
index 37ac610f9fd..5b94825bae3 100644
--- a/htdocs/contact/index.php
+++ b/htdocs/contact/index.php
@@ -104,8 +104,9 @@ llxHeader();
 
 $form=new Form($db);
 
-$sql = "SELECT s.rowid as socid, s.nom, s.fk_pays,";
-$sql.= " p.rowid as cidp, p.name, p.firstname, p.email, p.phone, p.phone_mobile, p.fax, p.priv,";
+$sql = "SELECT s.rowid as socid, s.nom,";
+$sql.= " p.rowid as cidp, p.name, p.firstname, p.email,";
+$sql.= " p.phone, p.phone_mobile, p.fax, p.fk_pays, p.priv,";
 $sql.= " ".$db->pdate("p.tms")." as tms";
 $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p";
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
@@ -312,9 +313,9 @@ if ($result)
 		// Phone
         print '<td>';
     	if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
-        	print '<a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&amp;actioncode=AC_TEL&amp;contactid='.$obj->cidp.'&amp;socid='.$obj->socid.'">'.dolibarr_print_phone($obj->phone,$obj->fk_pays).'</a>';
+        	print '<a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?action=create&amp;backtopage=1&amp;actioncode=AC_TEL&amp;contactid='.$obj->cidp.'&amp;socid='.$obj->socid.'">'.dolibarr_print_phone($obj->phone,$obj->pays_code).'</a>';
 		else
-			print dolibarr_print_phone($obj->phone,$obj->fk_pays);
+			print dolibarr_print_phone($obj->phone,$obj->pays_code);
     	print '</td>';
 		
         if ($_GET["view"] == 'phone')
-- 
GitLab