From 30747f3256ca031f5062bd84b8800cbfaf181cad Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Thu, 17 Apr 2008 12:04:40 +0000
Subject: [PATCH] Fix: Click to dial picto is shown only if module configured

---
 htdocs/comm/action/fiche.php   | 17 ++++++++++++-----
 htdocs/comm/fiche.php          |  2 +-
 htdocs/comm/prospect/fiche.php |  2 +-
 htdocs/compta/fiche.php        |  2 +-
 htdocs/contact/index.php       | 26 +++++++++++---------------
 htdocs/fourn/fiche.php         |  2 +-
 htdocs/lib/functions.lib.php   | 15 +++++++++------
 7 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php
index a3dd744282c..2f4e6efd4a5 100644
--- a/htdocs/comm/action/fiche.php
+++ b/htdocs/comm/action/fiche.php
@@ -65,8 +65,14 @@ if ($_POST["action"] == 'add_action')
 	
     if ($_POST['cancel'])
 	{
-		if ($_POST['socid'] > 0) header("Location: ".DOL_URL_ROOT.'/comm/fiche.php?socid='.$_POST['socid']);
-		else header("Location: ".DOL_URL_ROOT.'/comm/action/indexactions.php');
+		$back='';
+		if (! empty($_POST["back"])) $back=$_POST["back"];
+		if (! $back)
+		{
+			if ($_POST['socid'] > 0) $back=DOL_URL_ROOT.'/comm/fiche.php?socid='.$_POST['socid'];
+			else $back=DOL_URL_ROOT.'/comm/action/indexactions.php';
+		}
+		header("Location: ".$back);
 		exit;	
 	}
 
@@ -401,12 +407,13 @@ if ($_GET["action"] == 'create')
 	if ($_GET["contactid"])
 	{
 		$contact = new Contact($db);
-		$contact->fetch($_GET["contactid"]);
+		$result=$contact->fetch($_GET["contactid"]);
 	}
 
 	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 ($_GET["actioncode"] == 'AC_RDV') print_titre ($langs->trans("AddActionRendezVous"));
 	else print_titre ($langs->trans("AddAnAction"));
@@ -421,8 +428,8 @@ if ($_GET["action"] == 'create')
 	if ($_GET["actioncode"])
 	{
 		print '<input type="hidden" name="actioncode" value="'.$_GET["actioncode"].'">'."\n";
-		$caction->fetch($_GET["actioncode"]);
-		print $caction->getNomUrl();
+		$cactioncomm->fetch($_GET["actioncode"]);
+		print $cactioncomm->getNomUrl();
 	}
 	else
 	{
diff --git a/htdocs/comm/fiche.php b/htdocs/comm/fiche.php
index e9059de22ab..709462d2521 100644
--- a/htdocs/comm/fiche.php
+++ b/htdocs/comm/fiche.php
@@ -680,7 +680,7 @@ if ($socid > 0)
         print dolibarr_print_phone($obj->phone);
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
     	    print '</a>';
-		if ($obj->phone) print ' '.dol_phone_link($obj->phone);
+		if ($obj->phone) print dol_phone_link($obj->phone);
     	print '</td>';
         print '<td>';
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
diff --git a/htdocs/comm/prospect/fiche.php b/htdocs/comm/prospect/fiche.php
index 4d16d8da56c..056e4ad5b41 100644
--- a/htdocs/comm/prospect/fiche.php
+++ b/htdocs/comm/prospect/fiche.php
@@ -301,7 +301,7 @@ if ($socid > 0)
             print dolibarr_print_phone($obj->phone,'');
             if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
 	        	print '</a>';
-			if ($obj->phone) print ' '.dol_phone_link($obj->phone);
+			if ($obj->phone) print dol_phone_link($obj->phone);
 			print '</td>';
 
         	// Fax
diff --git a/htdocs/compta/fiche.php b/htdocs/compta/fiche.php
index 5ad22a3fbd0..89538d8d247 100644
--- a/htdocs/compta/fiche.php
+++ b/htdocs/compta/fiche.php
@@ -405,7 +405,7 @@ if ($socid > 0)
         print $obj->phone;
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
         	print '</a>';
-		if ($obj->phone) print ' '.dol_phone_link($obj->phone);
+		if ($obj->phone) print dol_phone_link($obj->phone);
         print '</td>';
 	    print '<td>';
         if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
diff --git a/htdocs/contact/index.php b/htdocs/contact/index.php
index 5ede80da901..37ac610f9fd 100644
--- a/htdocs/contact/index.php
+++ b/htdocs/contact/index.php
@@ -104,7 +104,7 @@ llxHeader();
 
 $form=new Form($db);
 
-$sql = "SELECT s.rowid as socid, s.nom, ";
+$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.= " ".$db->pdate("p.tms")." as tms";
 $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p";
@@ -249,13 +249,7 @@ if ($result)
     print '<td class="liste_titre">';
     print '<input class="flat" type="text" name="search_societe" size="10" value="'.$search_societe.'">';
     print '</td>';
-    if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
-    {
-    	print '<td class="liste_titre">';
-    	print '&nbsp;';
-    	print '</td>';
-    }
-    
+	print '<td class="liste_titre">&nbsp;</td>';
     if ($_GET["view"] == 'phone')
     {
         print '<td class="liste_titre">';
@@ -271,7 +265,6 @@ if ($result)
         print '<input class="flat" type="text" name="search_email" size="12" value="'.$search_email.'">';
         print '</td>';
     }
-
 	print '<td class="liste_titre">&nbsp;</td>';
 	print '<td class="liste_titre">';
 	$selectarray=array('0'=>$langs->trans("ContactPublic"),'1'=>$langs->trans("ContactPrivate"));
@@ -316,16 +309,19 @@ if ($result)
         }
         print '</td>';
 		
+		// Phone
+        print '<td>';
     	if ($conf->agenda->enabled && $user->rights->agenda->myactions->create)
-    	{
-        	print '<td><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).'</a>&nbsp;</td>';
-    	}
-    	
+        	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>';
+		else
+			print dolibarr_print_phone($obj->phone,$obj->fk_pays);
+    	print '</td>';
+		
         if ($_GET["view"] == 'phone')
         {
-            print '<td>'.dolibarr_print_phone($obj->phone_mobile,$obj->fp_pays).'&nbsp;</td>';
+            print '<td>'.dolibarr_print_phone($obj->phone_mobile,$obj->fk_pays).'&nbsp;</td>';
 
-            print '<td>'.dolibarr_print_phone($obj->fax,$obj->fp_pays).'&nbsp;</td>';
+            print '<td>'.dolibarr_print_phone($obj->fax,$obj->fk_pays).'&nbsp;</td>';
         }
         else
         {
diff --git a/htdocs/fourn/fiche.php b/htdocs/fourn/fiche.php
index cff30d1a23c..522f04457af 100644
--- a/htdocs/fourn/fiche.php
+++ b/htdocs/fourn/fiche.php
@@ -326,7 +326,7 @@ if ( $societe->fetch($socid) )
 		print "</td>";
 		print "<td>$obj->poste&nbsp;</td>";
 		print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_TEL&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->phone.'</a>';
-		if ($obj->phone) print ' '.dol_phone_link($obj->phone);
+		if ($obj->phone) print dol_phone_link($obj->phone);
 		print '</td>';
 		print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_FAX&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->fax.'</a></td>';
 		print '<td><a href="../comm/action/fiche.php?action=create&actioncode=AC_EMAIL&contactid='.$obj->rowid.'&socid='.$societe->id.'">'.$obj->email.'</a></td>';
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index 086d1111df8..95bc4bc1f43 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -683,12 +683,15 @@ function dol_phone_link($phone,$option=0)
 	global $conf,$user;
 	
 	$link='';
-	$phone=trim($phone);
-	
-   	$url = $conf->global->CLICKTODIAL_URL;
-   	$url.= "?login=".urlencode($user->clicktodial_login)."&password=".urlencode($user->clicktodial_password);
-   	$url.= "&caller=".urlencode($user->clicktodial_poste)."&called=".urlencode(trim($phone));
-   	$link.='<a href="#" onclick="newpopup(\''.$url.'\',\'\');">'.img_phone("default",0).'</a>';	
+	//if (! empty($conf->global->CLICKTODIAL_URL))
+	if ($conf->clicktodial->enabled)
+	{
+		$phone=trim($phone);
+	   	$url = $conf->global->CLICKTODIAL_URL;
+	   	$url.= "?login=".urlencode($user->clicktodial_login)."&password=".urlencode($user->clicktodial_password);
+	   	$url.= "&caller=".urlencode($user->clicktodial_poste)."&called=".urlencode(trim($phone));
+	   	$link.='<a href="URL_DEFINED_IN_CLICKTODIAL_MODULE" onclick="newpopup(\''.$url.'\',\'\'); return false;">'.img_phone("default",0).'</a>';	
+	}
 	return $link;
 }
 
-- 
GitLab