diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index aef2d5fad3d..827e2df976a 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -219,6 +219,7 @@ if ($action == 'add') if ($value['id'] > 0) { $usertodo->fetch($value['id']); + $object->userownerid = $usertodo->id; } $object->usertodo = $usertodo; $object->transparency = (GETPOST("transparency")=='on'?1:0); @@ -235,6 +236,7 @@ if ($action == 'add') if ($_POST["doneby"] > 0) { $userdone->fetch($_POST["doneby"]); + $object->userdoneid = $userdone->id; } $object->userdone = $userdone; } diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 1d7cf0efd68..fa7130ec018 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -47,8 +47,10 @@ class ActionComm extends CommonObject var $datec; // Date creation record (datec) var $datem; // Date modification record (tms) - var $author; // Object user that create action - var $usermod; // Object user that modified action + var $author; // Object user that create action //deprecated + var $usermod; // Object user that modified action // deprecated + var $authorid; // Id user that create action + var $usermodid; // Id user that modified action var $datep; // Date action start (datep) var $datef; // Date action end (datep2) @@ -63,8 +65,9 @@ class ActionComm extends CommonObject var $note; // Description var $userassigned = array(); // Array of user ids - var $usertodo; // Object user of owner - var $userdone; // Object user that did action (deprecated) + var $userownerid; // Id of user owner + var $usertodo; // Object user of owner // deprecated + var $userdone; // Object user that did action // deprecated var $socid; var $contactid; @@ -134,6 +137,9 @@ class ActionComm extends CommonObject if ($this->elementtype=='commande') $this->elementtype='order'; if ($this->elementtype=='contrat') $this->elementtype='contract'; + $userownerid=isset($this->usertodo->id)?$this->usertodo->id:$this->userownerid; // For backward compatibility + $userdoneid=isset($this->userdone->id)?$this->userdone->id:$this->userdoneid; // For backward compatibility + if (! $this->type_id && $this->type_code) { // Get id from code @@ -197,8 +203,8 @@ class ActionComm extends CommonObject $sql.= " '".$this->db->escape($this->note)."',"; $sql.= (isset($this->contactid) && $this->contactid > 0?"'".$this->contactid."'":"null").","; $sql.= (isset($user->id) && $user->id > 0 ? "'".$user->id."'":"null").","; - $sql.= (isset($this->usertodo->id) && $this->usertodo->id > 0?"'".$this->usertodo->id."'":"null").","; - $sql.= (isset($this->userdone->id) && $this->userdone->id > 0?"'".$this->userdone->id."'":"null").","; + $sql.= ($userownerid>0?"'".$userownerid."'":"null").","; + $sql.= ($userdoneid>0?"'".$userdoneid."'":"null").","; $sql.= "'".$this->db->escape($this->label)."','".$this->percentage."','".$this->priority."','".$this->fulldayevent."','".$this->db->escape($this->location)."','".$this->punctual."',"; $sql.= "'".$this->transparency."',"; $sql.= (! empty($this->fk_element)?$this->fk_element:"null").","; @@ -351,8 +357,9 @@ class ActionComm extends CommonObject $this->author->lastname = $obj->lastname; $this->usermod->id = $obj->fk_user_mod; - $this->usertodo->id = $obj->fk_user_action; - $this->userdone->id = $obj->fk_user_done; + $this->userownerid = $obj->fk_user_action; + $this->usertodo->id = $obj->fk_user_action; // deprecated + //$this->userdone->id = $obj->fk_user_done; $this->priority = $obj->priority; $this->fulldayevent = $obj->fulldayevent; $this->location = $obj->location; @@ -380,19 +387,25 @@ class ActionComm extends CommonObject /** - * Initialize this->userassigned array + * Initialize this->userassigned array with list of id of user assigned to event * * @return int <0 if KO, >0 if OK */ function fetch_userassigned() { global $langs; + $sql.="SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency"; $sql.=" FROM ".MAIN_DB_PREFIX."actioncomm_resources"; $sql.=" WHERE element_type = 'user' AND fk_actioncomm = ".$this->id; $resql2=$this->db->query($sql); if ($resql2) { + $this->userassigned=array(); + + // If owner is known, we must but id first into list + if ($this->userownerid > 0) $this->userassigned[$this->userownerid]=array('id'=>$this->userownerid); // Set first so will be first into list. + while ($obj = $this->db->fetch_object($resql2)) { $this->userassigned[$obj->fk_element]=array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency); diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 44d1e209694..67d27de66a5 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -484,10 +484,12 @@ if ($resql) $event->type_code=$obj->code; $event->libelle=$obj->label; $event->percentage=$obj->percent; - $event->author->id=$obj->fk_user_author; // user id of creator - $event->usertodo->id=$obj->fk_user_action; // user id of owner - $event->userdone->id=$obj->fk_user_done; // deprecated - // $event->userstodo=... with s after user, in future version, will be an array with all id of user assigned to event + //$event->author->id=$obj->fk_user_author; // user id of creator + $event->authorid=$obj->fk_user_author; // user id of creator + $event->userownerid=$obj->fk_user_action; // user id of owner + $event->fetch_userassigned(); // This load $event->userassigned + //$event->usertodo->id=$obj->fk_user_action; // user id of owner + //$event->userdone->id=$obj->fk_user_done; // deprecated $event->priority=$obj->priority; $event->fulldayevent=$obj->fulldayevent; $event->location=$obj->location; @@ -1132,19 +1134,19 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa { if ($i < $maxprint || $maxprint == 0 || ! empty($conf->global->MAIN_JS_SWITCH_AGENDA)) { - $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar); + $keysofuserassigned=array_keys($event->userassigned); + + $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar); // Define $color and $cssclass of event $color=-1; $cssclass=''; $colorindex=-1; - if ((! empty($event->author->id) && $event->author->id == $user->id) - || (! empty($event->usertodo->id) && $event->usertodo->id == $user->id) - || (! empty($event->userdone->id) && $event->userdone->id == $user->id)) - { - $nummytasks++; $cssclass='family_mytasks'; + if (in_array($user->id, $keysofuserassigned)) + { + $nummytasks++; $cssclass='family_mytasks'; // TODO Set a color using user color // Must defined rule to choose color of who to use. - // event->usertodo->id will still contains user id of owner - // event->userstodo will be an array in future. + // event->ownerid will still contains user id of owner + // event->userassigned will be an array in future. // $color=$user->color; } else if ($event->type_code == 'ICALEVENT') @@ -1164,7 +1166,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa if ($color == -1) // Color was not forced. Set color according to color index. { // Define color index if not yet defined - $idusertouse=($event->usertodo->id?$event->usertodo->id:0); + $idusertouse=($event->userownerid?$event->userownerid:0); if (isset($colorindexused[$idusertouse])) { $colorindex=$colorindexused[$idusertouse]; // Color already assigned to this user @@ -1344,7 +1346,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa } else { - print 'datep=$db->jdate($obj->datep); // datep and datef are GMT date $event->datef=$db->jdate($obj->datep2); $event->type_code=$obj->code; - $event->libelle=$obj->label; // deprecated + //$event->libelle=$obj->label; // deprecated $event->label=$obj->label; $event->percentage=$obj->percent; - $event->author->id=$obj->fk_user_author; // user id of creator - $event->usertodo->id=$obj->fk_user_action; // user id of owner - $event->userdone->id=$obj->fk_user_done; // deprecated - // $event->userstodo=... with s after user, in future version, will be an array with all id of user assigned to event + //$event->author->id=$obj->fk_user_author; // user id of creator + $event->authorid=$obj->fk_user_author; // user id of creator + $event->userownerid=$obj->fk_user_action; // user id of owner + $event->fetch_userassigned(); // This load $event->userassigned + //$event->userdone->id=$obj->fk_user_done; // deprecated $event->priority=$obj->priority; $event->fulldayevent=$obj->fulldayevent; $event->location=$obj->location; @@ -412,8 +413,8 @@ if ($resql) $event->socid=$obj->fk_soc; $event->contactid=$obj->fk_contact; - $event->societe->id=$obj->fk_soc; - $event->contact->id=$obj->fk_contact; + //$event->societe->id=$obj->fk_soc; // deprecated + //$event->contact->id=$obj->fk_contact; // deprecated // Defined date_start_in_calendar and date_end_in_calendar property // They are date start and end of action but modified to not be outside calendar view. @@ -424,7 +425,7 @@ if ($resql) else $event->date_end_in_calendar=$event->datep; } else - { + { $event->date_start_in_calendar=$event->datep; if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef; else $event->date_end_in_calendar=$event->datep; @@ -442,7 +443,7 @@ if ($resql) // This record is out of visible range } else - { + { if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow; if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=$lastdaytoshow; @@ -598,6 +599,9 @@ else $usernames = $tmpgroup->listUsersForGroup(); } +// Load array of colors by type +// TODO +$colorsbytype=array(); // Loop on each user to show calendar $sav = $tmpday; @@ -608,6 +612,7 @@ foreach ($usernames as $username) echo '