From 985826e6657faa3d5b8351c0019a7215dc074099 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Sun, 27 Apr 2008 15:51:01 +0000
Subject: [PATCH] Fix: Fetch of third party and contact for action

---
 htdocs/actioncomm.class.php  |  3 ++-
 htdocs/comm/action/fiche.php | 17 ++++++++++++++---
 htdocs/contact.class.php     | 14 +++++++-------
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/htdocs/actioncomm.class.php b/htdocs/actioncomm.class.php
index 0fb6256f8bc..999fa6ef5a3 100644
--- a/htdocs/actioncomm.class.php
+++ b/htdocs/actioncomm.class.php
@@ -244,7 +244,7 @@ class ActionComm
 				$this->datem = $obj->datem;
 				$this->note =$obj->note;
 				$this->percentage =$obj->percentage;
-				$this->societe->id = $obj->fk_soc;
+
 				$this->author->id  = $obj->fk_user_author;
 				$this->usermod->id  = $obj->fk_user_mod;
 
@@ -252,6 +252,7 @@ class ActionComm
 				$this->userdone->id  = $obj->fk_user_done;
 				$this->priority = $obj->priority;
 
+				$this->societe->id = $obj->fk_soc;
 				$this->contact->id = $obj->fk_contact;
 
 				$this->fk_facture = $obj->fk_facture;
diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php
index f29d61ad4b3..ccc5533a2da 100644
--- a/htdocs/comm/action/fiche.php
+++ b/htdocs/comm/action/fiche.php
@@ -565,14 +565,25 @@ if ($_GET["id"])
 
     $act = new ActionComm($db);
     $result=$act->fetch($_GET["id"]);
-	//print $result."ee".$act->userdone->id."ee";
-    $result=$act->societe->fetch($act->societe->id);
+
+	$societe = new Societe($db);
+	if ($act->societe->id)
+	{
+		$result=$societe->fetch($act->societe->id);
+	}
+	$act->societe = $societe;
+
     if ($act->author->id > 0)   $res=$act->author->fetch();     // Le parametre est le login, hors seul l'id est charge.
     if ($act->usermod->id > 0)  $res=$act->usermod->fetch();    
     if ($act->usertodo->id > 0) $res=$act->usertodo->fetch();   
     if ($act->userdone->id > 0) $res=$act->userdone->fetch();
 
-    $res=$act->contact->fetch($act->contact->id);
+	$contact = new Contact($db);
+	if ($act->contact->id)
+	{
+		$result=$contact->fetch($act->contact->id,$user);
+	}
+    $act->contact = $contact;
 
     /*
      * Affichage onglets
diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php
index f12f8acd914..74ca09a0667 100644
--- a/htdocs/contact.class.php
+++ b/htdocs/contact.class.php
@@ -443,8 +443,8 @@ class Contact extends CommonObject
 	            }
 	            else
 	            {
-	                dolibarr_syslog("Error in Contact::fetch() selectuser sql=$sql");
-	           	    $this->error="Error in Contact::fetch() selectuser - ".$this->db->error()." - ".$sql;
+	           	    $this->error=$this->db->error();
+	                dolibarr_syslog("Contact::fetch ".$this->error, LOG_ERR);
 	                return -1;
 	            }
 	    
@@ -453,7 +453,7 @@ class Contact extends CommonObject
 	            {
 	                $sql = "SELECT fk_user";
 	                $sql .= " FROM ".MAIN_DB_PREFIX."user_alert";
-	                $sql .= " WHERE fk_user = $user->id AND fk_contact = ".$id;
+	                $sql .= " WHERE fk_user = ".$user->id." AND fk_contact = ".$id;
 	    
 	                $resql=$this->db->query($sql);
 	                if ($resql)
@@ -468,8 +468,8 @@ class Contact extends CommonObject
 	                 }
 	                else
 	                {
-	                    dolibarr_syslog("Error in Contact::fetch() selectuseralert sql=$sql");
-	            	    $this->error="Error in Contact::fetch() selectuseralert - ".$this->db->error()." - ".$sql;
+		           	    $this->error=$this->db->error();
+		                dolibarr_syslog("Contact::fetch ".$this->error, LOG_ERR);
 	                    return -1;
 	                }
 	            }
@@ -484,8 +484,8 @@ class Contact extends CommonObject
         }
         else
         {
-            dolibarr_syslog("Error in Contact::fetch() selectsocpeople sql=$sql");
-      	    $this->error="Error in Contact::fetch() selectsocpeople - ".$this->db->error()." - ".$sql;
+			$this->error=$this->db->error();
+			dolibarr_syslog("Contact::fetch ".$this->error, LOG_ERR);
             return -1;
         }
     }
-- 
GitLab