From f563578b4fbe80fe13c8d19bf7fe0eaa1079c8df Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Tue, 15 Apr 2008 08:34:36 +0000
Subject: [PATCH] Enhancement of actions

---
 htdocs/comm/action/fiche.php                  | 306 ++++++++++--------
 htdocs/comm/action/index.php                  |  46 ++-
 htdocs/html.form.class.php                    |   4 +-
 .../interface_modAgenda_ActionsAuto.class.php |  14 +-
 htdocs/langs/en_US/agenda.lang                |   6 +-
 htdocs/langs/fr_FR/agenda.lang                |  10 +-
 htdocs/langs/fr_FR/commercial.lang            |   2 +-
 7 files changed, 237 insertions(+), 151 deletions(-)

diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php
index 333707a48fc..de130e1674a 100644
--- a/htdocs/comm/action/fiche.php
+++ b/htdocs/comm/action/fiche.php
@@ -37,6 +37,7 @@ $langs->load("commercial");
 $langs->load("other");
 $langs->load("bills");
 $langs->load("orders");
+$langs->load("agenda");
 
 // Securite acces client
 if ($user->societe_id > 0)
@@ -46,6 +47,10 @@ if ($user->societe_id > 0)
 }
 if (isset($_GET["error"])) $error=$_GET["error"];
 
+$cactioncomm = new CActionComm($db);
+$actioncomm = new ActionComm($db);
+$contact = new Contact($db);
+
 
 /*
  * Action creation de l'action
@@ -55,7 +60,6 @@ if ($_POST["action"] == 'add_action')
 {
     if ($_POST["contactid"])
     {
-        $contact = new Contact($db);
         $result=$contact->fetch($_POST["contactid"]);
     }
 	
@@ -71,6 +75,10 @@ if ($_POST["action"] == 'add_action')
 	if ($_POST["apmin"] == -1) $_POST["apmin"]='0';
 	if ($_POST["adhour"] == -1) $_POST["adhour"]='0';
 	if ($_POST["admin"] == -1) $_POST["admin"]='0';
+	if ($_POST["p2hour"] == -1) $_POST["p2hour"]='0';
+	if ($_POST["p2min"] == -1) $_POST["p2min"]='0';
+	if ($_POST["a2hour"] == -1) $_POST["a2hour"]='0';
+	if ($_POST["a2min"] == -1) $_POST["a2min"]='0';
 	$datep=dolibarr_mktime($_POST["aphour"],
                    $_POST["apmin"],
                    0,
@@ -83,17 +91,103 @@ if ($_POST["action"] == 'add_action')
                    $_POST["admonth"],
                    $_POST["adday"],
                    $_POST["adyear"]);
+	$datep2=dolibarr_mktime($_POST["p2hour"],
+                   $_POST["p2min"],
+                   0,
+                   $_POST["p2month"],
+                   $_POST["p2day"],
+                   $_POST["p2year"]);
+	$datea2=dolibarr_mktime($_POST["a2hour"],
+                   $_POST["a2min"],
+                   0,
+                   $_POST["a2month"],
+                   $_POST["a2day"],
+                   $_POST["a2year"]);
 	// Si param incorrects, mktime renvoi false en PHP 5.1, -1 avant
 	if (! ($datep > 0)) $datep='';
 	if (! ($datea > 0)) $datea='';
-
+	if (! ($datep2 > 0)) $datep2='';
+	if (! ($datea2 > 0)) $datea2='';
+	
+	// Initialisation objet cactioncomm
     if (! $_POST["actioncode"])
     {
     	$error=1;
 		$_GET["action"] = 'create';
         $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Type")).'</div>';
     }
+	else 
+	{
+		$result=$cactioncomm->fetch($_POST["actioncode"]);
+	}
+	
+	// Initialisation objet actioncomm
+	$actioncomm->type_id = $cactioncomm->id;
+	$actioncomm->type_code = $cactioncomm->code;
+	$actioncomm->priority = isset($_POST["priority"])?$_POST["priority"]:0;
+	$actioncomm->label = trim($_POST["label"]);
+	if (! $_POST["label"])
+	{
+		if ($_POST["actioncode"] == 'AC_RDV' && $contact->getFullName($langs))
+		{
+			$actioncomm->label = $langs->trans("TaskRDVWith",$contact->getFullName($langs));
+		}
+		else
+		{
+			if ($langs->trans("Action".$actioncomm->type_code) != "Action".$actioncomm->type_code)
+			{
+				$actioncomm->label = $langs->trans("Action".$actioncomm->type_code)."\n";
+			}
+		}
+	}
+	$actioncomm->datep = $datep;
+	$actioncomm->date = $datea;
+	$actioncomm->datef = $datep2;
+	$actioncomm->dateend = $datea2;
+	if ($_POST["percentage"] < 100 && ! $actioncomm->datep) $actioncomm->datep=$actioncomm->date;
+	if ($actioncomm->type_code == 'AC_RDV')
+	{
+		// RDV
+		if ($actioncomm->date)
+		{
+			$actioncomm->percentage = 100;
+		}
+		else
+		{
+			$actioncomm->percentage = 0;
+		}
+	}
+	else
+	{
+		$actioncomm->percentage = isset($_POST["percentage"])?$_POST["percentage"]:0;
+	}
+	$actioncomm->duree=(($_POST["dureehour"] * 60) + $_POST["dureemin"]) * 60;
 
+	$usertodo=new User($db,$_POST["affectedto"]);
+	if ($_POST["affectedto"])
+	{
+		$usertodo->fetch();
+	}
+	$actioncomm->usertodo = $usertodo;
+	$userdone=new User($db,$_POST["doneby"]);
+	if ($_POST["doneby"])
+	{
+		$userdone->fetch();
+	}
+	$actioncomm->userdone = $userdone;
+	
+	$actioncomm->note = trim($_POST["note"]);
+	if (isset($_POST["contactid"])) $actioncomm->contact = $contact;
+	if (isset($_REQUEST["socid"]) && $_REQUEST["socid"] > 0)
+	{
+		$societe = new Societe($db);
+		$societe->fetch($_REQUEST["socid"]);
+		$actioncomm->societe = $societe;
+	}
+	if ($_POST["add_webcal"] == 'on' && $conf->webcal->enabled) $actioncomm->use_webcal=1;
+	if ($_POST["add_phenix"] == 'on' && $conf->phenix->enabled) $actioncomm->use_phenix=1;
+
+	
 	if ($datea && $_POST["percentage"] == 0)
 	{
 		$error=1;	
@@ -112,77 +206,7 @@ if ($_POST["action"] == 'add_action')
     {
         $db->begin();
 
-        $cactioncomm = new CActionComm($db);
-        $cactioncomm->fetch($_POST["actioncode"]);
-
-        // Initialisation objet actioncomm
-        $actioncomm = new ActionComm($db);
-
-        $actioncomm->type_id = $cactioncomm->id;
-        $actioncomm->type_code = $cactioncomm->code;
-        $actioncomm->priority = isset($_POST["priority"])?$_POST["priority"]:0;
-        $actioncomm->label = trim($_POST["label"]);
-        if (! $_POST["label"])
-        {
-            if ($_POST["actioncode"] == 'AC_RDV' && $contact->getFullName($langs))
-            {
-                $actioncomm->label = $langs->trans("TaskRDVWith",$contact->getFullName($langs));
-            }
-            else
-            {
-                if ($langs->trans("Action".$actioncomm->type_code) != "Action".$actioncomm->type_code)
-                {
-                    $actioncomm->label = $langs->trans("Action".$actioncomm->type_code)."\n";
-                }
-            }
-        }
-//        print $_POST["aphour"]." ".$_POST["apmin"]." ".$_POST["apday"];
-    	$actioncomm->datep = $datep;
-    	$actioncomm->date = $datea;
-	    if ($_POST["percentage"] < 100 && ! $actioncomm->datep) $actioncomm->datep=$actioncomm->date;
-		if ($actioncomm->type_code == 'AC_RDV')
-		{
-			// RDV
-			if ($actioncomm->date)
-			{
-				$actioncomm->percentage = 100;
-			}
-			else
-			{
-				$actioncomm->percentage = 0;
-			}
-		}
-		else
-		{
-        	$actioncomm->percentage = isset($_POST["percentage"])?$_POST["percentage"]:0;
-	    }
-        $actioncomm->duree=(($_POST["dureehour"] * 60) + $_POST["dureemin"]) * 60;
-
-		$usertodo=new User($db,$_POST["affectedto"]);
-        if ($_POST["affectedto"])
-		{
-			$usertodo->fetch();
-		}
-		$actioncomm->usertodo = $usertodo;
-		$userdone=new User($db,$_POST["doneby"]);
-        if ($_POST["doneby"])
-		{
-			$userdone->fetch();
-		}
-		$actioncomm->userdone = $userdone;
-		
-        $actioncomm->note = trim($_POST["note"]);
-        if (isset($_POST["contactid"]))    $actioncomm->contact = $contact;
-        if (isset($_REQUEST["socid"]) && $_REQUEST["socid"] > 0)
-        {
-	        $societe = new Societe($db);
-    	    $societe->fetch($_REQUEST["socid"]);
-        	$actioncomm->societe = $societe;
-       	}
-        if ($_POST["add_webcal"] == 'on' && $conf->webcal->enabled) $actioncomm->use_webcal=1;
-        if ($_POST["add_phenix"] == 'on' && $conf->phenix->enabled) $actioncomm->use_phenix=1;
-
-        // On cr�e l'action
+        // On cree l'action
         $idaction=$actioncomm->add($user);
 
         if ($idaction > 0)
@@ -260,21 +284,43 @@ if ($_POST["action"] == 'update')
         $actioncomm = new Actioncomm($db);
         $actioncomm->fetch($_POST["id"]);
 
-    	$actioncomm->datep = dolibarr_mktime($_POST["aphour"],
+    	$datep=dolibarr_mktime($_POST["aphour"],
                                    $_POST["apmin"],
                                    0,
                                    $_POST["apmonth"],
                                    $_POST["apday"],
                                    $_POST["apyear"]);
-    	$actioncomm->date = dolibarr_mktime($_POST["adhour"],
+    	$datea=dolibarr_mktime($_POST["adhour"],
                                    $_POST["admin"],
                                    0,
                                    $_POST["admonth"],
                                    $_POST["adday"],
                                    $_POST["adyear"]);
+		$datep2=dolibarr_mktime($_POST["p2hour"],
+	                   $_POST["p2min"],
+	                   0,
+	                   $_POST["p2month"],
+	                   $_POST["p2day"],
+	                   $_POST["p2year"]);
+		$datea2=dolibarr_mktime($_POST["a2hour"],
+	                   $_POST["a2min"],
+	                   0,
+	                   $_POST["a2month"],
+	                   $_POST["a2day"],
+	                   $_POST["a2year"]);
+		// Si param incorrects, mktime renvoi false en PHP 5.1, -1 avant
+		if (! ($datep > 0)) $datep='';
+		if (! ($datea > 0)) $datea='';
+		if (! ($datep2 > 0)) $datep2='';
+		if (! ($datea2 > 0)) $datea2='';
+		
 		//print $_POST["apmonth"].",".$_POST["apday"].",".$_POST["apyear"].",".$_POST["aphour"].",".$_POST["apmin"]."<br>\n";
 		//print $actioncomm->datep;
         $actioncomm->label       = $_POST["label"];
+		$actioncomm->datep = $datep;
+		$actioncomm->date = $datea;
+		$actioncomm->datef = $datep2;
+		$actioncomm->dateend = $datea2;
         $actioncomm->percentage  = $_POST["percentage"];
         $actioncomm->priority    = $_POST["priority"];
         $actioncomm->contact->id = $_POST["contactid"];
@@ -334,8 +380,6 @@ $html = new Form($db);
 
 if ($_GET["action"] == 'create')
 {
-	$caction = new CActioncomm($db);
-
 	if ($_GET["contactid"])
 	{
 		$contact = new Contact($db);
@@ -353,9 +397,9 @@ if ($_GET["action"] == 'create')
 	if ($_GET["actioncode"] == 'AC_RDV')
 	{
 		print_titre ($langs->trans("AddActionRendezVous"));
-		print "<br>";
 
 		if ($mesg) print $mesg.'<br>';
+		else print "<br>";
 
 		print '<input type="hidden" name="date" value="'.$db->idate(time()).'">'."\n";
 
@@ -398,28 +442,30 @@ if ($_GET["action"] == 'create')
 		$html->select_users($_REQUEST["doneby"],'doneby',1);
 		print '</td></tr>';
 
-		// Date planification
-		print '<tr><td>'.$langs->trans("DateActionPlanned").'</td><td>';
-		if ($_GET["afaire"] == 1 || $_GET["afaire"] == 2)
-		{
-			$html->select_date(-1,'ap',1,1,1,"action");
-		}
-		else
-		{
-			$html->select_date(-1,'ap',1,1,1,"action");
-		}
+		// Date start planed
+		print '<tr><td nowrap="nowrap">'.$langs->trans("DateActionPlannedStart").'</td><td>';
+		if ($_REQUEST["afaire"] == 1) $html->select_date($actioncomm->datea,'ap',1,1,0,"action");
+		else if ($_REQUEST["afaire"] == 2) $html->select_date('','ap',1,1,1,"action");
+		else $html->select_date('','ap',1,1,1,"action");
+		print '</td></tr>';
+		// Date end planed
+		print '<tr><td>'.$langs->trans("DateActionPlannedEnd").'</td><td>';
+		if ($_REQUEST["afaire"] == 1) $html->select_date('','p2',1,1,1,"action");
+		else if ($_REQUEST["afaire"] == 2) $html->select_date('','p2',1,1,1,"action");
+		else $html->select_date('','p2',1,1,1,"action");
 		print '</td></tr>';
 
-		// Date done
-		print '<tr><td>'.$langs->trans("DateActionDone").'</td><td>';
-		if ($_GET["afaire"] == 1 || $_GET["afaire"] == 2)
-		{
-			$html->select_date(-1,'ad',1,1,1,"action");
-		}
-		else
-		{
-			$html->select_date(-1,'ad',1,1,1,"action");
-		}
+		// Date start done
+		print '<tr><td>'.$langs->trans("DateActionDoneStart").'</td><td>';
+		if ($_REQUEST["afaire"] == 1) $html->select_date('','ad',1,1,1,"action");
+		else if ($_REQUEST["afaire"] == 2) $html->select_date('','ad',1,1,0,"action");
+		else $html->select_date('','ad',1,1,1,"action");
+		print '</td></tr>';
+		// Date end done
+		print '<tr><td>'.$langs->trans("DateActionDoneEnd").'</td><td>';
+		if ($_REQUEST["afaire"] == 1) $html->select_date('','a2',1,1,1,"action");
+		else if ($_REQUEST["afaire"] == 2) $html->select_date('','a2',1,1,0,"action");
+		else $html->select_date('','a2',1,1,1,"action");
 		print '</td></tr>';
 
 		// Duration
@@ -459,10 +505,10 @@ if ($_GET["action"] == 'create')
 	else
 	{
 		print_titre ($langs->trans("AddAnAction"));
-		print "<br>";
 
 		if ($mesg) print $mesg.'<br>';
-
+		else print "<br>";
+		
 		print '<table class="border" width="100%">';
 
 		// Type d'action actifs
@@ -475,15 +521,15 @@ if ($_GET["action"] == 'create')
 		}
 		else
 		{
-			$html->select_type_actions(0, "actioncode");
+			$html->select_type_actions($actioncomm->type_code, "actioncode");
 		}
 		print '</td></tr>';
 
-		print '<tr><td>'.$langs->trans("Title").'</td><td><input type="text" name="label" size="30"></td></tr>';
+		print '<tr><td>'.$langs->trans("Title").'</td><td><input type="text" name="label" size="30" value="'.$actioncomm->label.'"></td></tr>';
 
 		// Societe, contact
 		print '<tr><td nowrap>'.$langs->trans("ActionOnCompany").'</td><td>';
-		if ($_REQUEST["socid"])
+		if ($_REQUEST["socid"] > 0)
 		{
 			$societe = new Societe($db);
 			$societe->fetch($_REQUEST["socid"]);
@@ -497,7 +543,7 @@ if ($_GET["action"] == 'create')
 		print '</td></tr>';
 
 		// Si la societe est imposee, on propose ces contacts
-		if ($_REQUEST["socid"])
+		if ($_REQUEST["socid"] > 0)
 		{
 			print '<tr><td nowrap>'.$langs->trans("ActionOnContact").'</td><td>';
 			$html->select_contacts($_REQUEST["socid"],'','contactid',1,1);
@@ -506,22 +552,22 @@ if ($_GET["action"] == 'create')
 
 		// Affecte a
 		print '<tr><td nowrap>'.$langs->trans("ActionAffectedTo").'</td><td>';
-		$html->select_users($_REQUEST["affectedto"],'affectedto',1);
+		$html->select_users($_REQUEST["affectedto"]?$_REQUEST["affectedto"]:$actioncomm->usertodo,'affectedto',1);
 		print '</td></tr>';
 
 		// Realise par
 		print '<tr><td nowrap>'.$langs->trans("ActionDoneBy").'</td><td>';
-		$html->select_users($_REQUEST["doneby"],'doneby',1);
+		$html->select_users($_REQUEST["doneby"]?$_REQUEST["doneby"]:$actioncomm->userdone,'doneby',1);
 		print '</td></tr>';
 
 		// Avancement
-		if ($_GET["afaire"] == 1)
+		if ($_REQUEST["afaire"] == 1)
 		{
 			print '<input type="hidden" name="percentage" value="0">';
 			print '<input type="hidden" name="todo" value="on">';
 			print '<tr><td width="10%">'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td><td>'.$langs->trans("StatusActionToDo").' / 0%</td></tr>';
 		}
-		elseif ($_GET["afaire"] == 2)
+		elseif ($_REQUEST["afaire"] == 2)
 		{
 			print '<input type="hidden" name="percentage" value="100">';
 			print '<tr><td>'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td><td>'.$langs->trans("StatusActionDone").' / 100%</td></tr>';
@@ -530,28 +576,30 @@ if ($_GET["action"] == 'create')
 			print '<tr><td>'.$langs->trans("Status").' / '.$langs->trans("Percentage").'</td><td><input type="text" name="percentage" value="0" size="4">%</td></tr>';
 		}
 
-		// Date planification
-		print '<tr><td>'.$langs->trans("DateActionPlanned").'</td><td>';
-		if ($_GET["afaire"] == 1 || $_GET["afaire"] == 2)
-		{
-			$html->select_date('','ap',1,1,0,"action");
-		}
-		else
-		{
-			$html->select_date('','ap',1,1,0,"action");
-		}
+		// Date start planed
+		print '<tr><td nowrap="nowrap">'.$langs->trans("DateActionPlannedStart").'</td><td>';
+		if ($_REQUEST["afaire"] == 1) $html->select_date($actioncomm->datep,'ap',1,1,0,"action");
+		else if ($_REQUEST["afaire"] == 2) $html->select_date($actioncomm->datep,'ap',1,1,1,"action");
+		else $html->select_date($actioncomm->datep,'ap',1,1,1,"action");
+		print '</td></tr>';
+		// Date end planed
+		print '<tr><td>'.$langs->trans("DateActionPlannedEnd").'</td><td>';
+		if ($_REQUEST["afaire"] == 1) $html->select_date($actioncomm->datef,'p2',1,1,1,"action");
+		else if ($_REQUEST["afaire"] == 2) $html->select_date($actioncomm->datef,'p2',1,1,1,"action");
+		else $html->select_date($actioncomm->datef,'p2',1,1,1,"action");
 		print '</td></tr>';
 
-		// Date done
-		print '<tr><td>'.$langs->trans("DateActionDone").'</td><td>';
-		if ($_GET["afaire"] == 1 || $_GET["afaire"] == 2)
-		{
-			$html->select_date(-1,'ad',1,1,1,"action");
-		}
-		elseif ($_GET["afaire"] != 1)
-		{
-			$html->select_date(-1,'ad',1,1,1,"action");
-		}
+		// Date start done
+		print '<tr><td>'.$langs->trans("DateActionDoneStart").'</td><td>';
+		if ($_REQUEST["afaire"] == 1) $html->select_date($actioncomm->date,'ad',1,1,1,"action");
+		else if ($_REQUEST["afaire"] == 2) $html->select_date($actioncomm->date,'ad',1,1,0,"action");
+		else $html->select_date($actioncomm->date,'ad',1,1,1,"action");
+		print '</td></tr>';
+		// Date end done
+		print '<tr><td>'.$langs->trans("DateActionDoneEnd").'</td><td>';
+		if ($_REQUEST["afaire"] == 1) $html->select_date($actioncomm->dateend,'a2',1,1,1,"action");
+		else if ($_REQUEST["afaire"] == 2) $html->select_date($actioncomm->dateend,'a2',1,1,0,"action");
+		else $html->select_date($actioncomm->dateend,'a2',1,1,1,"action");
 		print '</td></tr>';
 
 		add_row_for_calendar_link();
@@ -834,7 +882,7 @@ function add_row_for_calendar_link()
 	global $conf,$langs,$user;
   $nbtr=0;
 
-  // Lien avec calendrier si module activ�
+  // Lien avec calendrier si module active
   if ($conf->webcal->enabled)
   {
   	if ($conf->global->PHPWEBCALENDAR_SYNCRO != 'never')
diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php
index 127c7a3a302..64d24130d85 100644
--- a/htdocs/comm/action/index.php
+++ b/htdocs/comm/action/index.php
@@ -112,11 +112,16 @@ $next = dol_get_next_month($month, $year);
 $next_year  = $next['year'];
 $next_month = $next['month'];
 
-$max_day_in_month = date("t",dolibarr_mktime(0,0,0,$month,1,$year));
 $max_day_in_prev_month = date("t",dolibarr_mktime(0,0,0,$prev_month,1,$prev_year));
-
+$max_day_in_month = date("t",dolibarr_mktime(0,0,0,$month,1,$year));
 $day = -date("w",dolibarr_mktime(0,0,0,$month,1,$year))+2;
 if ($day > 1) $day -= 7;
+$firstdaytoshow=dolibarr_mktime(0,0,0,$prev_month,$max_day_in_prev_month+$day,$prev_year);
+$next_day=7-($max_day_in_month+1-$day)%7;
+if ($next_day < 6) $next_day+=7;
+$lastdaytoshow=dolibarr_mktime(0,0,0,$next_month,$next_day,$next_year);
+//print dolibarr_print_date($firstdaytoshow,'day');
+//print dolibarr_print_date($lastdaytoshow,'day');
 
 $title=$langs->trans("DoneAndToDoActions");
 if ($status == 'done') $title=$langs->trans("DoneActions");
@@ -205,6 +210,7 @@ if ($filtera > 0 || $filtert > 0 || $filterd > 0)
 }
 if ($status == 'done') { $sql.= " AND a.percent = 100"; }
 if ($status == 'todo') { $sql.= " AND a.percent < 100"; }
+// \TODO Add filters on dates
 
 //echo "$sql<br>";
 $actionarray=array();
@@ -224,23 +230,31 @@ if ($resql)
 		$action->libelle=$obj->label;
 		$action->percentage=$obj->percent;
 
+		// Defined date_start_in_calendar and date_end_in_calendar property
 		if ($action->percentage <= 0)
 		{
-			$action->date_to_show_in_calendar=$action->datep;
-			// Add days until datep2
+			$action->date_start_in_calendar=$action->datep;
+			if ($action->datef != '' && $action->datef >= $action->datep) $action->date_end_in_calendar=$action->datef;
+			else $action->date_end_in_calendar=$action->datep;
 		}
-		else if ($action->percentage > 0)
+		else
 		{
-			$action->date_to_show_in_calendar=$action->date;
-			// Add days until dateend
-
+			$action->date_start_in_calendar=$action->date;
+			if ($action->dateend != '' && $action->dateend >= $action->date) $action->date_end_in_calendar=$action->dateend;
+			else $action->date_end_in_calendar=$action->date;
+		}
+		// Define ponctuel property
+		if ($action->date_start_in_calendar == $action->date_end_in_calendar)
+		{
+			$action->ponctuel=1;
 		}
 
-		//var_dump($action);
-		$actionarray[]=$action;
+		// Add an entry in action array for each day
+		// \TODO
+		$daykey=$action->date_start_in_calendar;
+		$actionarray[$daykey]=$action;
 		$i++;
 	}
-	//echo $num;
 }
 else
 {
@@ -323,15 +337,15 @@ function show_day_events($db, $day, $month, $year, $style, $actionarray)
 
 	//$curtime = dolibarr_mktime (0, 0, 0, $month, $day, $year);
 	$i=0;
-	foreach ($actionarray as $action)
+	foreach ($actionarray as $daykey => $action)
 	{
-		$annee = date('Y',$action->date_to_show_in_calendar);
-		$mois = date('m',$action->date_to_show_in_calendar);
-		$jour = date('d',$action->date_to_show_in_calendar);
+		$annee = date('Y',$action->date_start_in_calendar);
+		$mois = date('m',$action->date_start_in_calendar);
+		$jour = date('d',$action->date_start_in_calendar);
 		if ($day==$jour && $month==$mois && $year==$annee)
 		{
 			if ($i) print "<br>";
-	   		print $action->getNomUrl(1,10)." ".$action->getLibStatut(3);
+	   		print $action->getNomUrl(1,9).$action->getLibStatut(3);
 			$i++;
 		}
 	}
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index 2ef2bb4d564..a266eee3145 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -572,7 +572,7 @@ class Form
 		$arraylist[0]='&nbsp;';
 		asort($arraylist);
 		
-		$this->select_array($htmlname, $arraylist, 0);
+		$this->select_array($htmlname, $arraylist, $selected);
 		if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
 	}
 
@@ -2728,7 +2728,7 @@ class Form
         \brief  Affiche un select � partir d'un tableau
         \param	htmlname        Nom de la zone select
         \param	array           Tableau de key+valeur
-        \param	id              Key pr�-s�lectionn�e
+        \param	id              Preselected key
         \param	show_empty      1 si il faut ajouter une valeur vide dans la liste, 0 sinon
         \param	key_in_label    1 pour afficher la key dans la valeur "[key] value"
         \param	value_as_key    1 pour utiliser la valeur comme cl�
diff --git a/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php b/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php
index dd5607e7e34..50ffb4095a6 100644
--- a/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php
+++ b/htdocs/includes/triggers/interface_modAgenda_ActionsAuto.class.php
@@ -120,6 +120,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("other");
+            $langs->load("agenda");
 
 			$object->actiontypecode='AC_OTH';
             $object->actionmsg2=$langs->transnoentities("NewCompanyToDolibarr",$object->nom);
@@ -138,6 +139,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("contracts");
+            $langs->load("agenda");
 
 			$object->actiontypecode='AC_OTH';
             $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref);
@@ -152,6 +154,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("propal");
+            $langs->load("agenda");
 
 			$object->actiontypecode='AC_OTH';
             $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref);
@@ -167,6 +170,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("propal");
+            $langs->load("agenda");
 			$ok=1;
 			
 			// Parameters $object->xxx defined by caller
@@ -175,6 +179,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("propal");
+            $langs->load("agenda");
 
 			$object->actiontypecode='AC_OTH';
             $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref);
@@ -190,6 +195,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("propal");
+            $langs->load("agenda");
 
 			$object->actiontypecode='AC_OTH';
             $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref);
@@ -205,7 +211,8 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("orders");
-
+            $langs->load("agenda");
+			
 			$object->actiontypecode='AC_OTH';
             $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
             $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref);
@@ -220,6 +227,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("orders");
+            $langs->load("agenda");
 			$ok=1;
 
 			// Parameters $object->xxx defined by caller
@@ -228,6 +236,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("bills");
+            $langs->load("agenda");
 
 			$object->actiontypecode='AC_OTH';
             $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref);
@@ -243,6 +252,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("bills");
+            $langs->load("agenda");
 			$ok=1;
 			
 			// Parameters $object->xxx defined by caller
@@ -251,6 +261,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("bills");
+            $langs->load("agenda");
 
 			$object->actiontypecode='AC_OTH';
             $object->actionmsg2=$langs->transnoentities("InvoicePayedInDolibarr",$object->ref);
@@ -266,6 +277,7 @@ class InterfaceActionsAuto
         {
             dolibarr_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
             $langs->load("bills");
+            $langs->load("agenda");
 
 			$object->actiontypecode='AC_OTH';
             $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref);
diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang
index 12fbcf517ee..71954385c32 100644
--- a/htdocs/langs/en_US/agenda.lang
+++ b/htdocs/langs/en_US/agenda.lang
@@ -25,4 +25,8 @@ ViewWithPredefinedFilters=View with predefined filters
 AutoActions=Automatic creation of actions
 AgendaAutoActionDesc=Define here events for which you want Dolibarr to create automatically an action in agenda. If nothing is checked (by default), only manual actions will be included in agenda.
 AgendaSetupOtherDesc=This page allows to configure other parameters of agenda module.
-ActionsEvents=Events for which create an action
\ No newline at end of file
+ActionsEvents=Events for which create an action
+PropalValidatedInDolibarr=Proposal validated
+InvoiceValidatedInDolibarr=Invoice validated
+OrderValidatedInDolibarr=Order validated
+NewCompanyToDolibarr=Third party created
diff --git a/htdocs/langs/fr_FR/agenda.lang b/htdocs/langs/fr_FR/agenda.lang
index 2f7e4135251..61fa472b6d5 100644
--- a/htdocs/langs/fr_FR/agenda.lang
+++ b/htdocs/langs/fr_FR/agenda.lang
@@ -25,4 +25,12 @@ ViewWithPredefinedFilters=Vues avec filtres pr
 AutoActions=Cr�ation automatiques des actions
 AgendaAutoActionDesc=D�finissez dans cet onglet les �v�nements pour lesquels dolibarr cr�era automatiquement une action dans l'agenda. Si aucune case n'est coch�e (par d�faut), seules les actions manuelles seront incluses dans l'agenda.
 AgendaSetupOtherDesc=Cette page permet de configurer les autres param�tres du module agenda.
-ActionsEvents=Ev�nements pour lesquels creer une action
\ No newline at end of file
+ActionsEvents=Ev�nements pour lesquels creer une action
+PropalValidatedInDolibarr=Proposition valid�e
+InvoiceValidatedInDolibarr=Facture valid�e
+OrderValidatedInDolibarr=Commande valid�e
+NewCompanyToDolibarr=Tiers cr��
+DateActionPlannedStart=Date d�but r�alisation pr�vue
+DateActionPlannedEnd=Date fin r�alisation pr�vue
+DateActionDoneStart=Date d�but r�alisation r�elle
+DateActionDoneEnd=Date fin r�alisation r�elle
diff --git a/htdocs/langs/fr_FR/commercial.lang b/htdocs/langs/fr_FR/commercial.lang
index c7a4a3edeb8..d9dbec5f4eb 100644
--- a/htdocs/langs/fr_FR/commercial.lang
+++ b/htdocs/langs/fr_FR/commercial.lang
@@ -63,7 +63,7 @@ ActionAskedBy=Action enregistr
 ActionAffectedTo=Action affect�e �
 ActionDoneBy=Action faite par
 ActionUserAsk=Enregistr� par
-ErrorStatusCantBeZeroIfStarted=Si le champ '<b>Date de r�alisation</b>' est renseign� alors l'action est commenc�e voire finie, aussi le champ 'Etat' ne peut etre 0%%.
+ErrorStatusCantBeZeroIfStarted=Si le champ '<b>Date d�but r�alisation r�elle</b>' est renseign� alors l'action est commenc�e voire finie, aussi le champ 'Etat' ne peut etre 0%%.
 ActionAC_TEL=Appel t�l�phonique
 ActionAC_FAX=Envoi fax
 ActionAC_PROP=Envoi proposition par mail
-- 
GitLab