From 718b3b19b45bb7df08bbccbe5518daab0ff237a4 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Mon, 20 Oct 2014 11:16:51 +0200
Subject: [PATCH] Fix: user and date modification not updated

---
 htdocs/admin/agenda.php                       |  2 +-
 ...terface_50_modAgenda_ActionsAuto.class.php | 42 +++++++++++++++++++
 htdocs/fichinter/class/fichinter.class.php    | 16 ++++++-
 .../mysql/data/llx_c_action_trigger.sql       |  3 +-
 .../install/mysql/migration/3.6.0-3.7.0.sql   |  4 ++
 5 files changed, 63 insertions(+), 4 deletions(-)

diff --git a/htdocs/admin/agenda.php b/htdocs/admin/agenda.php
index c7cb4258935..5ad9673a16f 100644
--- a/htdocs/admin/agenda.php
+++ b/htdocs/admin/agenda.php
@@ -154,7 +154,7 @@ print '<tr class="liste_titre">';
 print '<td colspan="2">'.$langs->trans("ActionsEvents").'</td>';
 print '<td><a href="'.$_SERVER["PHP_SELF"].'?action=selectall">'.$langs->trans("All").'</a>/<a href="'.$_SERVER["PHP_SELF"].'?action=selectnone">'.$langs->trans("None").'</a>';
 print '</tr>'."\n";
-// Show each trigger
+// Show each trigger (list is in c_action_trigger)
 if (! empty($triggers))
 {
 	foreach ($triggers as $trigger)
diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php
index e7ccc31583c..9a6af993107 100644
--- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php
+++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php
@@ -251,6 +251,20 @@ class InterfaceActionsAuto extends DolibarrTriggers
 
             $object->sendtoid=0;
 		}
+		elseif ($action == 'FICHINTER_CREATE')
+        {
+            $langs->load("other");
+            $langs->load("interventions");
+
+			$object->actiontypecode='AC_OTH_AUTO';
+            if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionCreatedInDolibarr",$object->ref);
+            $object->actionmsg=$langs->transnoentities("InterventionCreatedInDolibarr",$object->ref);
+            $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
+
+            $object->sendtoid=0;
+			$object->fk_element=0;
+			$object->elementtype='';
+		}
 		elseif ($action == 'FICHINTER_VALIDATE')
         {
             $langs->load("other");
@@ -261,6 +275,20 @@ class InterfaceActionsAuto extends DolibarrTriggers
             $object->actionmsg=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref);
             $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
 
+            $object->sendtoid=0;
+			$object->fk_element=0;
+			$object->elementtype='';
+		}
+		elseif ($action == 'FICHINTER_MODIFY')
+        {
+            $langs->load("other");
+            $langs->load("interventions");
+
+			$object->actiontypecode='AC_OTH_AUTO';
+            if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionModifiedInDolibarr",$object->ref);
+            $object->actionmsg=$langs->transnoentities("InterventionModifiedInDolibarr",$object->ref);
+            $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
+
             $object->sendtoid=0;
 			$object->fk_element=0;
 			$object->elementtype='';
@@ -290,6 +318,20 @@ class InterfaceActionsAuto extends DolibarrTriggers
 
             $object->sendtoid=0;
         }
+		elseif ($action == 'FICHINTER_DELETE')
+        {
+            $langs->load("other");
+            $langs->load("interventions");
+
+			$object->actiontypecode='AC_OTH_AUTO';
+            if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionDeletedInDolibarr",$object->ref);
+            $object->actionmsg=$langs->transnoentities("InterventionDeletedInDolibarr",$object->ref);
+            $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login;
+
+            $object->sendtoid=0;
+			$object->fk_element=0;
+			$object->elementtype='';
+		}
         elseif ($action == 'SHIPPING_VALIDATE')
         {
         	$langs->load("other");
diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php
index 6f613dda5c8..783024df800 100644
--- a/htdocs/fichinter/class/fichinter.class.php
+++ b/htdocs/fichinter/class/fichinter.class.php
@@ -240,6 +240,7 @@ class Fichinter extends CommonObject
 		$sql.= ", fk_projet = ".$this->fk_project;
 		$sql.= ", note_private = ".($this->note_private?"'".$this->db->escape($this->note_private)."'":"null");
 		$sql.= ", note_public = ".($this->note_public?"'".$this->db->escape($this->note_public)."'":"null");
+		$sql.= ", fk_user_modif = ".$user->id;
 		$sql.= " WHERE rowid = ".$this->id;
 
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
@@ -619,9 +620,11 @@ class Fichinter extends CommonObject
 		global $conf;
 
 		$sql = "SELECT f.rowid,";
-		$sql.= " datec,";
+		$sql.= " f.datec,";
+		$sql.= " f.tms as date_modification,";
 		$sql.= " f.date_valid as datev,";
 		$sql.= " f.fk_user_author,";
+		$sql.= " f.fk_user_modif as fk_user_modification,";
 		$sql.= " f.fk_user_valid";
 		$sql.= " FROM ".MAIN_DB_PREFIX."fichinter as f";
 		$sql.= " WHERE f.rowid = ".$id;
@@ -637,6 +640,7 @@ class Fichinter extends CommonObject
 				$this->id                = $obj->rowid;
 
 				$this->date_creation     = $this->db->jdate($obj->datec);
+				$this->date_modification = $this->db->jdate($obj->date_modification);
 				$this->date_validation   = $this->db->jdate($obj->datev);
 
 				$cuser = new User($this->db);
@@ -649,6 +653,13 @@ class Fichinter extends CommonObject
 					$vuser->fetch($obj->fk_user_valid);
 					$this->user_validation     = $vuser;
 				}
+				if ($obj->fk_user_modification)
+				{
+					$muser = new User($this->db);
+					$muser->fetch($obj->fk_user_modification);
+					$this->user_modification   = $muser;
+				}
+
 			}
 			$this->db->free($resql);
 		}
@@ -805,7 +816,8 @@ class Fichinter extends CommonObject
 		if ($user->rights->ficheinter->creer)
 		{
 			$sql = "UPDATE ".MAIN_DB_PREFIX."fichinter ";
-			$sql.= " SET description = '".$this->db->escape($description)."'";
+			$sql.= " SET description = '".$this->db->escape($description)."',";
+			$sql.= " fk_user_modif = ".$user->id;
 			$sql.= " WHERE rowid = ".$this->id;
 			$sql.= " AND entity = ".$conf->entity;
 
diff --git a/htdocs/install/mysql/data/llx_c_action_trigger.sql b/htdocs/install/mysql/data/llx_c_action_trigger.sql
index 6eddd5883c8..36f8e3ad9c3 100644
--- a/htdocs/install/mysql/data/llx_c_action_trigger.sql
+++ b/htdocs/install/mysql/data/llx_c_action_trigger.sql
@@ -32,7 +32,6 @@
 -- List of all managed triggered events (used for trigger agenda and for notification)
 --
 delete from llx_c_action_trigger;
-insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_VALIDATE','Intervention validated','Executed when a intervention is validated','ficheinter',19);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_VALIDATE','Customer invoice validated','Executed when a customer invoice is approved','facture',6);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_APPROVE','Supplier order request approved','Executed when a supplier order is approved','order_supplier',12);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('ORDER_SUPPLIER_REFUSE','Supplier order request refused','Executed when a supplier order is refused','order_supplier',13);
@@ -58,6 +57,8 @@ insert into llx_c_action_trigger (code,label,description,elementtype,rang) value
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_RESILIATE','Member resiliated','Executed when a member is resiliated','member',24);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('MEMBER_DELETE','Member deleted','Executed when a member is deleted','member',25);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('BILL_UNVALIDATE','Customer invoice unvalidated','Executed when a customer invoice status set back to draft','facture',10);
+insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_VALIDATE','Intervention validated','Executed when a intervention is validated','ficheinter',19);
+insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_CLASSIFY_BILLED','Intervention set billed','Executed when a intervention is set to billed','ficheinter',19);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_SENTBYMAIL','Intervention sent by mail','Executed when a intervention is sent by mail','ficheinter',19);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROJECT_CREATE','Project creation','Executed when a project is created','project',30);
 insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PROPAL_CLOSE_SIGNED','Customer proposal closed signed','Executed when a customer proposal is closed signed','propal',2);
diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
index ee01ef4850c..89d017af12c 100644
--- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
+++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql
@@ -19,6 +19,10 @@
 -- -- VMYSQL4.1 DELETE FROM llx_usergroup_user      WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
 
 
+--insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_MODIFY','Intervention modified','Executed when a intervention is modified','ficheinter',19);
+--insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('FICHINTER_DELETE','Intervention delete','Executed when a intervention is delete','ficheinter',19);
+
+
 ALTER TABLE llx_bank_account ADD COLUMN fk_user_author integer;
 
 ALTER TABLE llx_c_actioncomm ADD COLUMN color varchar(9);
-- 
GitLab