dolibarr  16.0.1
actioncomm.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2011-2017 Juanjo Menent <jmenent@2byte.es>
6  * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
7  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
8  * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
29 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncommreminder.class.php';
33 
34 
38 class ActionComm extends CommonObject
39 {
43  public $element = 'action';
44 
48  public $table_element = 'actioncomm';
49 
53  public $table_rowid = 'id';
54 
58  public $picto = 'action';
59 
63  public $ismultientitymanaged = 1;
64 
70  public $restrictiononfksoc = 2;
71 
75  public $id;
76 
80  public $ref;
81 
86  public $type_id;
87 
92  public $type;
93 
98  public $type_code;
99 
103  public $type_label;
104 
108  public $type_color;
109 
113  public $type_picto;
114 
119  public $code;
120 
124  public $label;
125 
130  public $libelle;
131 
135  public $datec;
136 
140  public $duree;
141 
145  public $datem;
146 
152  public $author;
153 
159  public $usermod;
160 
164  public $authorid;
165 
169  public $usermodid;
170 
174  public $datep;
175 
179  public $datef;
180 
184  public $date_start_in_calendar;
185 
189  public $date_end_in_calendar;
190 
194  public $datep2;
195 
200  public $durationp = -1;
201 
205  public $fulldayevent = 0;
206 
210  public $ponctuel;
211 
215  public $percentage;
216 
220  public $location;
221 
225  public $transparency;
226 
230  public $priority;
231 
235  public $userassigned = array();
236 
240  public $userownerid;
241 
245  public $userdoneid;
246 
250  public $socpeopleassigned = array();
251 
255  public $otherassigned = array();
256 
260  public $reminders = array();
261 
265  public $socid;
266 
270  public $contact_id;
271 
277  public $societe;
278 
284  public $contact;
285 
286  // Properties for links to other objects
290  public $fk_element; // Id of record
291 
295  public $elementid;
296 
300  public $elementtype;
301 
305  public $icalname;
306 
310  public $icalcolor;
311 
315  public $extraparams;
316 
320  public $actions = array();
321 
325  public $email_msgid;
326 
330  public $email_from;
331 
335  public $email_sender;
336 
340  public $email_to;
341 
345  public $email_tocc;
349  public $email_tobcc;
350 
354  public $email_subject;
355 
359  public $errors_to;
360 
364  public $num_vote;
365 
369  public $event_paid;
370 
374  public $status;
375 
379  public $recurid;
380  public $recurrule;
381  public $recurdateend;
382 
383  public $calling_duration;
384 
385 
389  const EVENT_TODO = 0;
390 
394  const EVENT_IN_PROGRESS = 50;
395 
399  const EVENT_FINISHED = 100;
400 
401 
402  public $fields = array();
403 
404 
410  public function __construct(DoliDB $db)
411  {
412  $this->db = $db;
413  }
414 
423  public function create(User $user, $notrigger = 0)
424  {
425  global $langs, $conf, $hookmanager;
426 
427  $error = 0;
428  $now = dol_now();
429 
430  // Check parameters
431  if (!isset($this->userownerid) || $this->userownerid === '') { // $this->userownerid may be 0 (anonymous event) of > 0
432  dol_syslog("You tried to create an event but mandatory property ownerid was not defined", LOG_WARNING);
433  $this->errors[] = 'ErrorActionCommPropertyUserowneridNotDefined';
434  return -1;
435  }
436 
437  // Clean parameters
438  $this->label = dol_trunc(trim($this->label), 128);
439  $this->location = dol_trunc(trim($this->location), 128);
440  $this->note_private = dol_htmlcleanlastbr(trim(empty($this->note_private) ? $this->note : $this->note_private));
441  if (empty($this->percentage)) {
442  $this->percentage = 0;
443  }
444  if (empty($this->priority) || !is_numeric($this->priority)) {
445  $this->priority = 0;
446  }
447  if (empty($this->fulldayevent)) {
448  $this->fulldayevent = 0;
449  }
450  if (empty($this->transparency)) {
451  $this->transparency = 0;
452  }
453  if ($this->percentage > 100) {
454  $this->percentage = 100;
455  }
456  //if ($this->percentage == 100 && ! $this->dateend) $this->dateend = $this->date;
457  if (!empty($this->datep) && !empty($this->datef)) {
458  $this->durationp = ($this->datef - $this->datep); // deprecated
459  }
460  //if (! empty($this->date) && ! empty($this->dateend)) $this->durationa=($this->dateend - $this->date);
461  if (!empty($this->datep) && !empty($this->datef) && $this->datep > $this->datef) {
462  $this->datef = $this->datep;
463  }
464  //if (! empty($this->date) && ! empty($this->dateend) && $this->date > $this->dateend) $this->dateend=$this->date;
465  if (!isset($this->fk_project) || $this->fk_project < 0) {
466  $this->fk_project = 0;
467  }
468  // For backward compatibility
469  if ($this->elementtype == 'facture') {
470  $this->elementtype = 'invoice';
471  }
472  if ($this->elementtype == 'commande') {
473  $this->elementtype = 'order';
474  }
475  if ($this->elementtype == 'contrat') {
476  $this->elementtype = 'contract';
477  }
478 
479  if (!is_array($this->userassigned) && !empty($this->userassigned)) { // For backward compatibility when userassigned was an int instead fo array
480  $tmpid = $this->userassigned;
481  $this->userassigned = array();
482  $this->userassigned[$tmpid] = array('id'=>$tmpid, 'transparency'=>$this->transparency);
483  }
484 
485  $userownerid = $this->userownerid;
486  $userdoneid = $this->userdoneid;
487 
488  // Be sure assigned user is defined as an array of array('id'=>,'mandatory'=>,...).
489  if (empty($this->userassigned) || count($this->userassigned) == 0 || !is_array($this->userassigned)) {
490  $this->userassigned = array($userownerid=>array('id'=>$userownerid, 'transparency'=>$this->transparency));
491  }
492 
493  if (!$this->type_id || !$this->type_code) {
494  $key = empty($this->type_id) ? $this->type_code : $this->type_id;
495 
496  // Get id from code
497  $cactioncomm = new CActionComm($this->db);
498  $result = $cactioncomm->fetch($key);
499 
500  if ($result > 0) {
501  $this->type_id = $cactioncomm->id;
502  $this->type_code = $cactioncomm->code;
503  } elseif ($result == 0) {
504  $this->error = $langs->trans('ErrorActionCommBadType', $this->type_id, $this->type_code);
505  return -1;
506  } else {
507  $this->error = $cactioncomm->error;
508  return -1;
509  }
510  }
511  $code = empty($this->code) ? $this->type_code : $this->code;
512 
513  // Check parameters
514  if (!$this->type_id) {
515  $this->error = "ErrorWrongParameters";
516  return -1;
517  }
518 
519  $this->db->begin();
520 
521  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm";
522  $sql .= "(ref,";
523  $sql .= "datec,";
524  $sql .= "datep,";
525  $sql .= "datep2,";
526  $sql .= "durationp,"; // deprecated
527  $sql .= "fk_action,";
528  $sql .= "code,";
529  $sql .= "ref_ext,";
530  $sql .= "fk_soc,";
531  $sql .= "fk_project,";
532  $sql .= "note,";
533  $sql .= "fk_contact,";
534  $sql .= "fk_user_author,";
535  $sql .= "fk_user_action,";
536  $sql .= "fk_user_done,";
537  $sql .= "label,percent,priority,fulldayevent,location,";
538  $sql .= "transparency,";
539  $sql .= "fk_element,";
540  $sql .= "elementtype,";
541  $sql .= "entity,";
542  $sql .= "extraparams,";
543  // Fields emails
544  $sql .= "email_msgid,";
545  $sql .= "email_from,";
546  $sql .= "email_sender,";
547  $sql .= "email_to,";
548  $sql .= "email_tocc,";
549  $sql .= "email_tobcc,";
550  $sql .= "email_subject,";
551  $sql .= "errors_to,";
552  $sql .= "num_vote,";
553  $sql .= "event_paid,";
554  $sql .= "status";
555  $sql .= ") VALUES (";
556  $sql .= "'(PROV)', ";
557  $sql .= "'".$this->db->idate($now)."', ";
558  $sql .= (strval($this->datep) != '' ? "'".$this->db->idate($this->datep)."'" : "null").", ";
559  $sql .= (strval($this->datef) != '' ? "'".$this->db->idate($this->datef)."'" : "null").", ";
560  $sql .= ((isset($this->durationp) && $this->durationp >= 0 && $this->durationp != '') ? "'".$this->db->escape($this->durationp)."'" : "null").", "; // deprecated
561  $sql .= (isset($this->type_id) ? $this->type_id : "null").",";
562  $sql .= ($code ? ("'".$this->db->escape($code)."'") : "null").", ";
563  $sql .= (!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null").", ";
564  $sql .= ((isset($this->socid) && $this->socid > 0) ? ((int) $this->socid) : "null").", ";
565  $sql .= ((isset($this->fk_project) && $this->fk_project > 0) ? ((int) $this->fk_project) : "null").", ";
566  $sql .= " '".$this->db->escape($this->note_private)."', ";
567  $sql .= ((isset($this->contact_id) && $this->contact_id > 0) ? ((int) $this->contact_id) : "null").", "; // deprecated, use ->socpeopleassigned
568  $sql .= (isset($user->id) && $user->id > 0 ? $user->id : "null").", ";
569  $sql .= ($userownerid > 0 ? $userownerid : "null").", ";
570  $sql .= ($userdoneid > 0 ? $userdoneid : "null").", ";
571  $sql .= "'".$this->db->escape($this->label)."', ";
572  $sql .= "'".$this->db->escape($this->percentage)."', ";
573  $sql .= "'".$this->db->escape($this->priority)."', ";
574  $sql .= "'".$this->db->escape($this->fulldayevent)."', ";
575  $sql .= "'".$this->db->escape($this->location)."', ";
576  $sql .= "'".$this->db->escape($this->transparency)."', ";
577  $sql .= (!empty($this->fk_element) ? ((int) $this->fk_element) : "null").", ";
578  $sql .= (!empty($this->elementtype) ? "'".$this->db->escape($this->elementtype)."'" : "null").", ";
579  $sql .= ((int) $conf->entity).",";
580  $sql .= (!empty($this->extraparams) ? "'".$this->db->escape($this->extraparams)."'" : "null").", ";
581  // Fields emails
582  $sql .= (!empty($this->email_msgid) ? "'".$this->db->escape($this->email_msgid)."'" : "null").", ";
583  $sql .= (!empty($this->email_from) ? "'".$this->db->escape($this->email_from)."'" : "null").", ";
584  $sql .= (!empty($this->email_sender) ? "'".$this->db->escape($this->email_sender)."'" : "null").", ";
585  $sql .= (!empty($this->email_to) ? "'".$this->db->escape($this->email_to)."'" : "null").", ";
586  $sql .= (!empty($this->email_tocc) ? "'".$this->db->escape($this->email_tocc)."'" : "null").", ";
587  $sql .= (!empty($this->email_tobcc) ? "'".$this->db->escape($this->email_tobcc)."'" : "null").", ";
588  $sql .= (!empty($this->email_subject) ? "'".$this->db->escape($this->email_subject)."'" : "null").", ";
589  $sql .= (!empty($this->errors_to) ? "'".$this->db->escape($this->errors_to)."'" : "null").", ";
590  $sql .= (!empty($this->num_vote) ? (int) $this->num_vote : "null").", ";
591  $sql .= (!empty($this->event_paid) ? (int) $this->event_paid : 0).", ";
592  $sql .= (!empty($this->status) ? (int) $this->status : "0");
593  $sql .= ")";
594 
595  dol_syslog(get_class($this)."::add", LOG_DEBUG);
596  $resql = $this->db->query($sql);
597  if ($resql) {
598  $this->ref = $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm", "id");
599  $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm SET ref='".$this->db->escape($this->ref)."' WHERE id=".$this->id;
600  $resql = $this->db->query($sql);
601  if (!$resql) {
602  $error++;
603  dol_syslog('Error to process ref: '.$this->db->lasterror(), LOG_ERR);
604  $this->errors[] = $this->db->lasterror();
605  }
606  // Now insert assigned users
607  if (!$error) {
608  //dol_syslog(var_export($this->userassigned, true));
609  $already_inserted = array();
610  foreach ($this->userassigned as $key => $val) {
611  // Common value with new behavior is to have $val = array('id'=>iduser, 'transparency'=>0|1) and $this->userassigned is an array of iduser => $val.
612  if (!is_array($val)) { // For backward compatibility when $val='id'.
613  $val = array('id'=>$val);
614  }
615 
616  if ($val['id'] > 0) {
617  if (!empty($already_inserted[$val['id']])) {
618  continue;
619  }
620 
621  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
622  $sql .= " VALUES(".((int) $this->id).", 'user', ".((int) $val['id']).", ".(empty($val['mandatory']) ? '0' : ((int) $val['mandatory'])).", ".(empty($val['transparency']) ? '0' : ((int) $val['transparency'])).", ".(empty($val['answer_status']) ? '0' : ((int) $val['answer_status'])).")";
623 
624  $resql = $this->db->query($sql);
625  if (!$resql) {
626  $error++;
627  dol_syslog('Error to process userassigned: ' . $this->db->lasterror(), LOG_ERR);
628  $this->errors[] = $this->db->lasterror();
629  } else {
630  $already_inserted[$val['id']] = true;
631  }
632  //var_dump($sql);exit;
633  }
634  }
635  }
636 
637  if (!$error) {
638  if (!empty($this->socpeopleassigned)) {
639  $already_inserted = array();
640  foreach ($this->socpeopleassigned as $id => $val) {
641  // Common value with new behavior is to have $val = iduser and $this->socpeopleassigned is an array of iduser => $val.
642  if (!empty($already_inserted[$id])) {
643  continue;
644  }
645 
646  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
647  $sql .= " VALUES(".((int) $this->id).", 'socpeople', ".((int) $id).", 0, 0, 0)";
648 
649  $resql = $this->db->query($sql);
650  if (!$resql) {
651  $error++;
652  dol_syslog('Error to process socpeopleassigned: ' . $this->db->lasterror(), LOG_ERR);
653  $this->errors[] = $this->db->lasterror();
654  } else {
655  $already_inserted[$id] = true;
656  }
657  }
658  }
659  }
660 
661  if (!$error) {
662  // Actions on extra fields
663  $result = $this->insertExtraFields();
664  if ($result < 0) {
665  $error++;
666  }
667  }
668 
669  if (!$error && !$notrigger) {
670  // Call trigger
671  $result = $this->call_trigger('ACTION_CREATE', $user);
672  if ($result < 0) {
673  $error++;
674  }
675  // End call triggers
676  }
677 
678  if (!$error) {
679  $this->db->commit();
680  return $this->id;
681  } else {
682  $this->db->rollback();
683  return -1;
684  }
685  } else {
686  $this->db->rollback();
687  $this->error = $this->db->lasterror();
688  return -1;
689  }
690  }
691 
699  public function createFromClone(User $fuser, $socid)
700  {
701  global $db, $conf, $hookmanager;
702 
703  $error = 0;
704  $now = dol_now();
705 
706  $this->db->begin();
707 
708  // Load source object
709  $objFrom = clone $this;
710 
711  // Retrieve all extrafield
712  // fetch optionals attributes and labels
713  $this->fetch_optionals();
714 
715  //$this->fetch_userassigned();
716  $this->fetchResources();
717 
718  $this->id = 0;
719 
720  // Create clone
721  $this->context['createfromclone'] = 'createfromclone';
722  $result = $this->create($fuser);
723  if ($result < 0) {
724  $error++;
725  }
726 
727  if (!$error) {
728  // Hook of thirdparty module
729  if (is_object($hookmanager)) {
730  $parameters = array('objFrom'=>$objFrom);
731  $action = '';
732  $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
733  if ($reshook < 0) {
734  $error++;
735  }
736  }
737 
738  // Call trigger
739  $result = $this->call_trigger('ACTION_CLONE', $fuser);
740  if ($result < 0) {
741  $error++;
742  }
743  // End call triggers
744  }
745 
746  unset($this->context['createfromclone']);
747 
748  // End
749  if (!$error) {
750  $this->db->commit();
751  return $this->id;
752  } else {
753  $this->db->rollback();
754  return -1;
755  }
756  }
757 
768  public function fetch($id, $ref = '', $ref_ext = '', $email_msgid = '', $loadresources = 1)
769  {
770  global $langs;
771 
772  if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) {
773  dol_syslog(get_class($this)."::fetch Bad parameters", LOG_WARNING);
774  return -1;
775  }
776 
777  $sql = "SELECT a.id,";
778  $sql .= " a.ref as ref,";
779  $sql .= " a.entity,";
780  $sql .= " a.ref_ext,";
781  $sql .= " a.datep,";
782  $sql .= " a.datep2,";
783  $sql .= " a.durationp,"; // deprecated
784  $sql .= " a.datec,";
785  $sql .= " a.tms as datem,";
786  $sql .= " a.code, a.label, a.note as note_private,";
787  $sql .= " a.fk_soc,";
788  $sql .= " a.fk_project,";
789  $sql .= " a.fk_user_author, a.fk_user_mod,";
790  $sql .= " a.fk_user_action, a.fk_user_done,";
791  $sql .= " a.fk_contact, a.percent as percentage,";
792  $sql .= " a.fk_element as elementid, a.elementtype,";
793  $sql .= " a.priority, a.fulldayevent, a.location, a.transparency,";
794  $sql .= " a.email_msgid, a.email_subject, a.email_from, a.email_sender, a.email_to, a.email_tocc, a.email_tobcc, a.errors_to,";
795  $sql .= " c.id as type_id, c.type as type_type, c.code as type_code, c.libelle as type_label, c.color as type_color, c.picto as type_picto,";
796  $sql .= " s.nom as socname,";
797  $sql .= " u.firstname, u.lastname as lastname,";
798  $sql .= " num_vote, event_paid, a.status";
799  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a ";
800  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action=c.id ";
801  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author";
802  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc";
803  $sql .= " WHERE ";
804  if ($ref) {
805  $sql .= " a.ref = '".$this->db->escape($ref)."'";
806  } elseif ($ref_ext) {
807  $sql .= " a.ref_ext = '".$this->db->escape($ref_ext)."'";
808  } elseif ($email_msgid) {
809  $sql .= " a.email_msgid = '".$this->db->escape($email_msgid)."'";
810  } else {
811  $sql .= " a.id = ".((int) $id);
812  }
813 
814  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
815  $resql = $this->db->query($sql);
816  if ($resql) {
817  $num = $this->db->num_rows($resql);
818  if ($num) {
819  $obj = $this->db->fetch_object($resql);
820 
821  $this->id = $obj->id;
822  $this->entity = $obj->entity;
823  $this->ref = $obj->ref;
824  $this->ref_ext = $obj->ref_ext;
825 
826  // Properties of parent table llx_c_actioncomm
827  $this->type_id = $obj->type_id;
828  $this->type_code = $obj->type_code;
829  $this->type_color = $obj->type_color;
830  $this->type_picto = $obj->type_picto;
831  $this->type = $obj->type_type;
832  /*$transcode = $langs->trans("Action".$obj->type_code);
833  $this->type = (($transcode != "Action".$obj->type_code) ? $transcode : $obj->type_label); */
834  $transcode = $langs->trans("Action".$obj->type_code.'Short');
835  $this->type_short = (($transcode != "Action".$obj->type_code.'Short') ? $transcode : '');
836 
837  $this->code = $obj->code;
838  $this->label = $obj->label;
839  $this->datep = $this->db->jdate($obj->datep);
840  $this->datef = $this->db->jdate($obj->datep2);
841 
842  $this->datec = $this->db->jdate($obj->datec);
843  $this->datem = $this->db->jdate($obj->datem);
844 
845  $this->note = $obj->note_private; // deprecated
846  $this->note_private = $obj->note_private;
847  $this->percentage = $obj->percentage;
848 
849  $this->authorid = $obj->fk_user_author;
850  $this->usermodid = $obj->fk_user_mod;
851 
852  if (!is_object($this->author)) {
853  $this->author = new User($this->db); // To avoid warning
854  }
855  $this->author->id = $obj->fk_user_author; // deprecated
856  $this->author->firstname = $obj->firstname; // deprecated
857  $this->author->lastname = $obj->lastname; // deprecated
858  if (!is_object($this->usermod)) {
859  $this->usermod = new User($this->db); // To avoid warning
860  }
861  $this->usermod->id = $obj->fk_user_mod; // deprecated
862 
863  $this->userownerid = $obj->fk_user_action;
864  $this->priority = $obj->priority;
865  $this->fulldayevent = $obj->fulldayevent;
866  $this->location = $obj->location;
867  $this->transparency = $obj->transparency;
868 
869  $this->socid = $obj->fk_soc; // To have fetch_thirdparty method working
870  $this->contact_id = $obj->fk_contact; // To have fetch_contact method working
871  $this->fk_project = $obj->fk_project; // To have fetch_projet method working
872 
873  //$this->societe->id = $obj->fk_soc; // deprecated
874  //$this->contact->id = $obj->fk_contact; // deprecated
875 
876  $this->fk_element = $obj->elementid;
877  $this->elementid = $obj->elementid;
878  $this->elementtype = $obj->elementtype;
879 
880  $this->num_vote = $obj->num_vote;
881  $this->event_paid = $obj->event_paid;
882  $this->status = $obj->status;
883 
884  //email information
885  $this->email_msgid=$obj->email_msgid;
886  $this->email_from=$obj->email_from;
887  $this->email_sender=$obj->email_sender;
888  $this->email_to=$obj->email_to;
889  $this->email_tocc=$obj->email_tocc;
890  $this->email_tobcc=$obj->email_tobcc;
891  $this->email_subject=$obj->email_subject;
892  $this->errors_to=$obj->errors_to;
893 
894  $this->fetch_optionals();
895 
896  if ($loadresources) {
897  $this->fetchResources();
898  }
899  }
900 
901  $this->db->free($resql);
902  } else {
903  $this->error = $this->db->lasterror();
904  return -1;
905  }
906 
907  return $num;
908  }
909 
915  public function fetchResources()
916  {
917  $this->userassigned = array();
918  $this->socpeopleassigned = array();
919 
920  $sql = 'SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency';
921  $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm_resources';
922  $sql .= ' WHERE fk_actioncomm = '.((int) $this->id);
923  $sql .= " AND element_type IN ('user', 'socpeople')";
924  $resql = $this->db->query($sql);
925  if ($resql) {
926  // If owner is known, we must but id first into list
927  if ($this->userownerid > 0) {
928  $this->userassigned[$this->userownerid] = array('id'=>$this->userownerid); // Set first so will be first into list.
929  }
930 
931  while ($obj = $this->db->fetch_object($resql)) {
932  if ($obj->fk_element > 0) {
933  switch ($obj->element_type) {
934  case 'user':
935  $this->userassigned[$obj->fk_element] = array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency);
936  if (empty($this->userownerid)) {
937  $this->userownerid = $obj->fk_element; // If not defined (should not happened, we fix this)
938  }
939  break;
940  case 'socpeople':
941  $this->socpeopleassigned[$obj->fk_element] = array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency);
942  break;
943  }
944  }
945  }
946 
947  return 1;
948  } else {
949  dol_print_error($this->db);
950  return -1;
951  }
952  }
953 
954  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
961  public function fetch_userassigned($override = true)
962  {
963  // phpcs:enable
964  $sql = "SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency";
965  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm_resources";
966  $sql .= " WHERE element_type = 'user' AND fk_actioncomm = ".((int) $this->id);
967 
968  $resql2 = $this->db->query($sql);
969  if ($resql2) {
970  $this->userassigned = array();
971 
972  // If owner is known, we must but id first into list
973  if ($this->userownerid > 0) {
974  // Set first so will be first into list.
975  $this->userassigned[$this->userownerid] = array('id'=>$this->userownerid);
976  }
977 
978  while ($obj = $this->db->fetch_object($resql2)) {
979  if ($obj->fk_element > 0) {
980  $this->userassigned[$obj->fk_element] = array('id'=>$obj->fk_element,
981  'mandatory'=>$obj->mandatory,
982  'answer_status'=>$obj->answer_status,
983  'transparency'=>$obj->transparency);
984  }
985 
986  if ($override === true) {
987  // If not defined (should not happened, we fix this)
988  if (empty($this->userownerid)) {
989  $this->userownerid = $obj->fk_element;
990  }
991  }
992  }
993 
994  return 1;
995  } else {
996  dol_print_error($this->db);
997  return -1;
998  }
999  }
1000 
1007  public function delete($notrigger = 0)
1008  {
1009  global $user;
1010 
1011  $error = 0;
1012 
1013  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1014 
1015  $this->db->begin();
1016 
1017  // remove categorie association
1018  if (!$error) {
1019  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_actioncomm";
1020  $sql .= " WHERE fk_actioncomm=".((int) $this->id);
1021 
1022  $res = $this->db->query($sql);
1023  if (!$res) {
1024  $this->error = $this->db->lasterror();
1025  $error++;
1026  }
1027  }
1028 
1029  // remove actioncomm_resources
1030  if (!$error) {
1031  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources";
1032  $sql .= " WHERE fk_actioncomm=".((int) $this->id);
1033 
1034  $res = $this->db->query($sql);
1035  if (!$res) {
1036  $this->error = $this->db->lasterror();
1037  $error++;
1038  }
1039  }
1040 
1041  if (!$error) {
1042  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
1043  $sql .= " WHERE fk_actioncomm = ".((int) $this->id);
1044 
1045  $res = $this->db->query($sql);
1046  if (!$res) {
1047  $this->error = $this->db->lasterror();
1048  $error++;
1049  }
1050  }
1051 
1052  // Removed extrafields
1053  if (!$error) {
1054  $result = $this->deleteExtraFields();
1055  if ($result < 0) {
1056  $error++;
1057  dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
1058  }
1059  }
1060 
1061  // remove actioncomm
1062  if (!$error) {
1063  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm";
1064  $sql .= " WHERE id=".((int) $this->id);
1065 
1066  $res = $this->db->query($sql);
1067  if (!$res) {
1068  $this->error = $this->db->lasterror();
1069  $error++;
1070  }
1071  }
1072 
1073  if (!$error) {
1074  if (!$notrigger) {
1075  // Call trigger
1076  $result = $this->call_trigger('ACTION_DELETE', $user);
1077  if ($result < 0) {
1078  $error++;
1079  }
1080  // End call triggers
1081  }
1082 
1083  if (!$error) {
1084  $this->db->commit();
1085  return 1;
1086  } else {
1087  $this->db->rollback();
1088  return -2;
1089  }
1090  } else {
1091  $this->db->rollback();
1092  $this->error = $this->db->lasterror();
1093  return -1;
1094  }
1095  }
1096 
1105  public function update(User $user, $notrigger = 0)
1106  {
1107  global $langs, $conf, $hookmanager;
1108 
1109  $error = 0;
1110 
1111  // Clean parameters
1112  $this->label = trim($this->label);
1113  $this->note_private = dol_htmlcleanlastbr(trim(!isset($this->note_private) ? $this->note : $this->note_private));
1114  if (empty($this->percentage)) {
1115  $this->percentage = 0;
1116  }
1117  if (empty($this->priority) || !is_numeric($this->priority)) {
1118  $this->priority = 0;
1119  }
1120  if (empty($this->transparency)) {
1121  $this->transparency = 0;
1122  }
1123  if (empty($this->fulldayevent)) {
1124  $this->fulldayevent = 0;
1125  }
1126  if ($this->percentage > 100) {
1127  $this->percentage = 100;
1128  }
1129  //if ($this->percentage == 100 && ! $this->dateend) $this->dateend = $this->date;
1130  if ($this->datep && $this->datef) {
1131  $this->durationp = ($this->datef - $this->datep); // deprecated
1132  }
1133  //if ($this->date && $this->dateend) $this->durationa=($this->dateend - $this->date);
1134  if ($this->datep && $this->datef && $this->datep > $this->datef) {
1135  $this->datef = $this->datep;
1136  }
1137  //if ($this->date && $this->dateend && $this->date > $this->dateend) $this->dateend=$this->date;
1138  if ($this->fk_project < 0) {
1139  $this->fk_project = 0;
1140  }
1141 
1142  // Check parameters
1143  if ($this->percentage == 0 && $this->userdoneid > 0) {
1144  $this->error = "ErrorCantSaveADoneUserWithZeroPercentage";
1145  return -1;
1146  }
1147 
1148  $socid = (($this->socid > 0) ? $this->socid : 0);
1149  $contactid = (($this->contact_id > 0) ? $this->contact_id : 0);
1150  $userownerid = ($this->userownerid ? $this->userownerid : 0);
1151  $userdoneid = ($this->userdoneid ? $this->userdoneid : 0);
1152 
1153  $this->db->begin();
1154 
1155  $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm ";
1156  $sql .= " SET percent = '".$this->db->escape($this->percentage)."'";
1157  if ($this->type_id > 0) {
1158  $sql .= ", fk_action = ".(int) $this->type_id;
1159  if (empty($this->type_code)) {
1160  $cactioncomm = new CActionComm($this->db);
1161  $result = $cactioncomm->fetch($this->type_id);
1162  if ($result >= 0 && !empty($cactioncomm->code)) {
1163  $this->type_code = $cactioncomm->code;
1164  }
1165  }
1166  }
1167  $sql .= ", code = " . (isset($this->type_code)? "'".$this->db->escape($this->type_code) . "'":"null");
1168  $sql .= ", label = ".($this->label ? "'".$this->db->escape($this->label)."'" : "null");
1169  $sql .= ", datep = ".(strval($this->datep) != '' ? "'".$this->db->idate($this->datep)."'" : 'null');
1170  $sql .= ", datep2 = ".(strval($this->datef) != '' ? "'".$this->db->idate($this->datef)."'" : 'null');
1171  $sql .= ", durationp = ".(isset($this->durationp) && $this->durationp >= 0 && $this->durationp != '' ? "'".$this->db->escape($this->durationp)."'" : "null"); // deprecated
1172  $sql .= ", note = '".$this->db->escape($this->note_private)."'";
1173  $sql .= ", fk_project =".($this->fk_project > 0 ? ((int) $this->fk_project) : "null");
1174  $sql .= ", fk_soc =".($socid > 0 ? ((int) $socid) : "null");
1175  $sql .= ", fk_contact =".($contactid > 0 ? ((int) $contactid) : "null");
1176  $sql .= ", priority = '".$this->db->escape($this->priority)."'";
1177  $sql .= ", fulldayevent = '".$this->db->escape($this->fulldayevent)."'";
1178  $sql .= ", location = ".($this->location ? "'".$this->db->escape($this->location)."'" : "null");
1179  $sql .= ", transparency = '".$this->db->escape($this->transparency)."'";
1180  $sql .= ", fk_user_mod = ".((int) $user->id);
1181  $sql .= ", fk_user_action = ".($userownerid > 0 ? ((int) $userownerid) : "null");
1182  $sql .= ", fk_user_done = ".($userdoneid > 0 ? ((int) $userdoneid) : "null");
1183  if (!empty($this->fk_element)) {
1184  $sql .= ", fk_element=".($this->fk_element ? ((int) $this->fk_element) : "null");
1185  }
1186  if (!empty($this->elementtype)) {
1187  $sql .= ", elementtype=".($this->elementtype ? "'".$this->db->escape($this->elementtype)."'" : "null");
1188  }
1189  if (!empty($this->num_vote)) {
1190  $sql .= ", num_vote=".($this->num_vote ? (int) $this->num_vote : null);
1191  }
1192  if (!empty($this->event_paid)) {
1193  $sql .= ", event_paid=".($this->event_paid ? (int) $this->event_paid : 0);
1194  }
1195  if (!empty($this->status)) {
1196  $sql .= ", status=".($this->status ? (int) $this->status : 0);
1197  }
1198  $sql .= " WHERE id=".$this->id;
1199 
1200  dol_syslog(get_class($this)."::update", LOG_DEBUG);
1201  if ($this->db->query($sql)) {
1202  $action = 'update';
1203 
1204  // Actions on extra fields
1205  if (!$error) {
1206  $result = $this->insertExtraFields();
1207  if ($result < 0) {
1208  $error++;
1209  }
1210  }
1211 
1212  // Now insert assignedusers
1213  if (!$error) {
1214  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources where fk_actioncomm = ".((int) $this->id)." AND element_type = 'user'";
1215  $resql = $this->db->query($sql);
1216 
1217  $already_inserted = array();
1218  foreach ($this->userassigned as $key => $val) {
1219  if (!is_array($val)) { // For backward compatibility when val=id
1220  $val = array('id'=>$val);
1221  }
1222  if (!empty($already_inserted[$val['id']])) continue;
1223 
1224  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1225  $sql .= " VALUES(".((int) $this->id).", 'user', ".((int) $val['id']).", ".(empty($val['mandatory']) ? '0' : ((int) $val['mandatory'])).", ".(empty($val['transparency']) ? '0' : ((int) $val['transparency'])).", ".(empty($val['answer_status']) ? '0' : ((int) $val['answer_status'])).")";
1226 
1227  $resql = $this->db->query($sql);
1228  if (!$resql) {
1229  $error++;
1230  $this->errors[] = $this->db->lasterror();
1231  } else {
1232  $already_inserted[$val['id']] = true;
1233  }
1234  //var_dump($sql);exit;
1235  }
1236  }
1237 
1238  if (!$error) {
1239  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources where fk_actioncomm = ".((int) $this->id)." AND element_type = 'socpeople'";
1240  $resql = $this->db->query($sql);
1241 
1242  if (!empty($this->socpeopleassigned)) {
1243  $already_inserted = array();
1244  foreach (array_keys($this->socpeopleassigned) as $key => $val) {
1245  if (!is_array($val)) { // For backward compatibility when val=id
1246  $val = array('id'=>$val);
1247  }
1248  if (!empty($already_inserted[$val['id']])) continue;
1249 
1250  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1251  $sql .= " VALUES(".((int) $this->id).", 'socpeople', ".((int) $val['id']).", 0, 0, 0)";
1252 
1253  $resql = $this->db->query($sql);
1254  if (!$resql) {
1255  $error++;
1256  $this->errors[] = $this->db->lasterror();
1257  } else {
1258  $already_inserted[$val['id']] = true;
1259  }
1260  }
1261  }
1262  }
1263 
1264  if (!$error && !$notrigger) {
1265  // Call trigger
1266  $result = $this->call_trigger('ACTION_MODIFY', $user);
1267  if ($result < 0) {
1268  $error++;
1269  }
1270  // End call triggers
1271  }
1272 
1273  if (!$error) {
1274  $this->db->commit();
1275  return 1;
1276  } else {
1277  $this->db->rollback();
1278  dol_syslog(get_class($this)."::update ".join(',', $this->errors), LOG_ERR);
1279  return -2;
1280  }
1281  } else {
1282  $this->db->rollback();
1283  $this->error = $this->db->lasterror();
1284  return -1;
1285  }
1286  }
1287 
1301  public function getActions($socid = 0, $fk_element = 0, $elementtype = '', $filter = '', $sortfield = 'a.datep', $sortorder = 'DESC', $limit = 0)
1302  {
1303  global $conf, $langs;
1304 
1305  $resarray = array();
1306 
1307  dol_syslog(get_class()."::getActions", LOG_DEBUG);
1308 
1309  $sql = "SELECT a.id";
1310  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1311  $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
1312  if (!empty($socid)) {
1313  $sql .= " AND a.fk_soc = ".((int) $socid);
1314  }
1315  if (!empty($elementtype)) {
1316  if ($elementtype == 'project') {
1317  $sql .= ' AND a.fk_project = '.((int) $fk_element);
1318  } elseif ($elementtype == 'contact') {
1319  $sql .= ' AND a.id IN';
1320  $sql .= " (SELECT fk_actioncomm FROM ".MAIN_DB_PREFIX."actioncomm_resources WHERE";
1321  $sql .= " element_type = 'socpeople' AND fk_element = ".((int) $fk_element).')';
1322  } else {
1323  $sql .= " AND a.fk_element = ".((int) $fk_element)." AND a.elementtype = '".$this->db->escape($elementtype)."'";
1324  }
1325  }
1326  if (!empty($filter)) {
1327  $sql .= $filter;
1328  }
1329  if ($sortorder && $sortfield) {
1330  $sql .= $this->db->order($sortfield, $sortorder);
1331  }
1332  $sql .= $this->db->plimit($limit, 0);
1333 
1334  $resql = $this->db->query($sql);
1335  if ($resql) {
1336  $num = $this->db->num_rows($resql);
1337 
1338  if ($num) {
1339  for ($i = 0; $i < $num; $i++) {
1340  $obj = $this->db->fetch_object($resql);
1341  $actioncommstatic = new ActionComm($this->db);
1342  $actioncommstatic->fetch($obj->id);
1343  $resarray[$i] = $actioncommstatic;
1344  }
1345  }
1346  $this->db->free($resql);
1347  return $resarray;
1348  } else {
1349  return $this->db->lasterror();
1350  }
1351  }
1352 
1353  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1361  public function load_board($user, $load_state_board = 0)
1362  {
1363  // phpcs:enable
1364  global $conf, $langs;
1365 
1366  if (empty($load_state_board)) {
1367  $sql = "SELECT a.id, a.datep as dp";
1368  } else {
1369  $this->nb = array();
1370  $sql = "SELECT count(a.id) as nb";
1371  }
1372  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1373  if (empty($user->rights->societe->client->voir) && !$user->socid) {
1374  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
1375  }
1376  if (empty($user->rights->agenda->allactions->read)) {
1377  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_resources AS ar ON a.id = ar.fk_actioncomm AND ar.element_type ='user' AND ar.fk_element = ".((int) $user->id);
1378  }
1379  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
1380  $sql .= " WHERE 1 = 1";
1381  if (empty($load_state_board)) {
1382  $sql .= " AND a.percent >= 0 AND a.percent < 100";
1383  }
1384  $sql .= " AND a.entity IN (".getEntity('agenda').")";
1385  if (empty($user->rights->societe->client->voir) && !$user->socid) {
1386  $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
1387  }
1388  if ($user->socid) {
1389  $sql .= " AND a.fk_soc = ".((int) $user->socid);
1390  }
1391  if (empty($user->rights->agenda->allactions->read)) {
1392  $sql .= " AND (a.fk_user_author = ".((int) $user->id)." OR a.fk_user_action = ".((int) $user->id)." OR a.fk_user_done = ".((int) $user->id);
1393  $sql .= " OR ar.fk_element = ".((int) $user->id);
1394  $sql .= ")";
1395  }
1396 
1397  $resql = $this->db->query($sql);
1398  if ($resql) {
1399  if (empty($load_state_board)) {
1400  $agenda_static = new ActionComm($this->db);
1401  $response = new WorkboardResponse();
1402  $response->warning_delay = $conf->agenda->warning_delay / 60 / 60 / 24;
1403  $response->label = $langs->trans("ActionsToDo");
1404  $response->labelShort = $langs->trans("ActionsToDoShort");
1405  $response->url = DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&actioncode=0&status=todo&mainmenu=agenda';
1406  if ($user->rights->agenda->allactions->read) {
1407  $response->url .= '&filtert=-1';
1408  }
1409  $response->img = img_object('', "action", 'class="inline-block valigntextmiddle"');
1410  }
1411  // This assignment in condition is not a bug. It allows walking the results.
1412  while ($obj = $this->db->fetch_object($resql)) {
1413  if (empty($load_state_board)) {
1414  $response->nbtodo++;
1415  $agenda_static->datep = $this->db->jdate($obj->dp);
1416  if ($agenda_static->hasDelay()) {
1417  $response->nbtodolate++;
1418  }
1419  } else {
1420  $this->nb["actionscomm"] = $obj->nb;
1421  }
1422  }
1423 
1424  $this->db->free($resql);
1425  if (empty($load_state_board)) {
1426  return $response;
1427  } else {
1428  return 1;
1429  }
1430  } else {
1431  dol_print_error($this->db);
1432  $this->error = $this->db->error();
1433  return -1;
1434  }
1435  }
1436 
1437 
1444  public function info($id)
1445  {
1446  $sql = 'SELECT ';
1447  $sql .= ' a.id,';
1448  $sql .= ' datec,';
1449  $sql .= ' tms as datem,';
1450  $sql .= ' fk_user_author,';
1451  $sql .= ' fk_user_mod';
1452  $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
1453  $sql .= ' WHERE a.id = '.((int) $id);
1454 
1455  dol_syslog(get_class($this)."::info", LOG_DEBUG);
1456  $result = $this->db->query($sql);
1457  if ($result) {
1458  if ($this->db->num_rows($result)) {
1459  $obj = $this->db->fetch_object($result);
1460  $this->id = $obj->id;
1461  $this->user_creation_id = $obj->fk_user_author;
1462  $this->user_modification_id = $obj->fk_user_mod;
1463  $this->date_creation = $this->db->jdate($obj->datec);
1464  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1465  }
1466  $this->db->free($result);
1467  } else {
1468  dol_print_error($this->db);
1469  }
1470  }
1471 
1472 
1480  public function getLibStatut($mode, $hidenastatus = 0)
1481  {
1482  return $this->LibStatut($this->percentage, $mode, $hidenastatus, $this->datep);
1483  }
1484 
1485  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1495  public function LibStatut($percent, $mode, $hidenastatus = 0, $datestart = '')
1496  {
1497  // phpcs:enable
1498  global $langs;
1499 
1500  $labelStatus = $langs->transnoentitiesnoconv('StatusNotApplicable');
1501  if ($percent == -1 && !$hidenastatus) {
1502  $labelStatus = $langs->transnoentitiesnoconv('StatusNotApplicable');
1503  } elseif ($percent == 0) {
1504  $labelStatus = $langs->transnoentitiesnoconv('StatusActionToDo').' (0%)';
1505  } elseif ($percent > 0 && $percent < 100) {
1506  $labelStatus = $langs->transnoentitiesnoconv('StatusActionInProcess').' ('.$percent.'%)';
1507  } elseif ($percent >= 100) {
1508  $labelStatus = $langs->transnoentitiesnoconv('StatusActionDone').' (100%)';
1509  }
1510 
1511  $labelStatusShort = $langs->transnoentitiesnoconv('StatusNotApplicable');
1512  if ($percent == -1 && !$hidenastatus) {
1513  $labelStatusShort = $langs->trans('NA');
1514  } elseif ($percent == 0) {
1515  $labelStatusShort = '0%';
1516  } elseif ($percent > 0 && $percent < 100) {
1517  $labelStatusShort = $percent.'%';
1518  } elseif ($percent >= 100) {
1519  $labelStatusShort = '100%';
1520  }
1521 
1522  $statusType = 'status9';
1523  if ($percent == -1 && !$hidenastatus) {
1524  $statusType = 'status9';
1525  }
1526  if ($percent == 0) {
1527  $statusType = 'status1';
1528  }
1529  if ($percent > 0 && $percent < 100) {
1530  $statusType = 'status3';
1531  }
1532  if ($percent >= 100) {
1533  $statusType = 'status6';
1534  }
1535 
1536  return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1537  }
1538 
1552  public function getNomUrl($withpicto = 0, $maxlength = 0, $classname = '', $option = '', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
1553  {
1554  global $conf, $langs, $user, $hookmanager, $action;
1555 
1556  if (!empty($conf->dol_no_mouse_hover)) {
1557  $notooltip = 1; // Force disable tooltips
1558  }
1559 
1560  $canread = 0;
1561  if ($user->rights->agenda->myactions->read && $this->authorid == $user->id) {
1562  $canread = 1; // Can read my event
1563  }
1564  if ($user->rights->agenda->myactions->read && array_key_exists($user->id, $this->userassigned)) {
1565  $canread = 1; // Can read my event i am assigned
1566  }
1567  if ($user->rights->agenda->allactions->read) {
1568  $canread = 1; // Can read all event of other
1569  }
1570  if (!$canread) {
1571  $option = 'nolink';
1572  }
1573 
1574  $label = $this->label;
1575  if (empty($label)) {
1576  $label = $this->libelle; // For backward compatibility
1577  }
1578 
1579  $result = '';
1580 
1581  // Set label of type
1582  $labeltype = '';
1583  if ($this->type_code) {
1584  $labeltype = ($langs->transnoentities("Action".$this->type_code) != "Action".$this->type_code) ? $langs->transnoentities("Action".$this->type_code) : $this->type_label;
1585  }
1586  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1587  if ($this->type_code != 'AC_OTH_AUTO') {
1588  $labeltype = $langs->trans('ActionAC_MANUAL');
1589  }
1590  }
1591 
1592  $tooltip = img_picto('', $this->picto).' <u>'.$langs->trans('Action').'</u>';
1593  if (!empty($this->ref)) {
1594  $tooltip .= '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
1595  }
1596  if (!empty($label)) {
1597  $tooltip .= '<br><b>'.$langs->trans('Title').':</b> '.$label;
1598  }
1599  if (!empty($labeltype)) {
1600  $tooltip .= '<br><b>'.$langs->trans('Type').':</b> '.$labeltype;
1601  }
1602  if (!empty($this->location)) {
1603  $tooltip .= '<br><b>'.$langs->trans('Location').':</b> '.$this->location;
1604  }
1605  if (isset($this->transparency)) {
1606  $tooltip .= '<br><b>'.$langs->trans('Busy').':</b> '.yn($this->transparency);
1607  }
1608  if (!empty($this->email_msgid)) {
1609  $langs->load("mails");
1610  $tooltip .= '<br>';
1611  //$tooltip .= '<br><b>'.img_picto('', 'email').' '.$langs->trans("Email").'</b>';
1612  $tooltip .= '<br><b>'.$langs->trans('MailTopic').':</b> '.$this->email_subject;
1613  $tooltip .= '<br><b>'.$langs->trans('MailFrom').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_from);
1614  $tooltip .= '<br><b>'.$langs->trans('MailTo').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_to);
1615  if (!empty($this->email_tocc)) {
1616  $tooltip .= '<br><b>'.$langs->trans('MailCC').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_tocc);
1617  }
1618  /* Disabled because bcc must remain by defintion not visible
1619  if (!empty($this->email_tobcc)) {
1620  $tooltip .= '<br><b>'.$langs->trans('MailCCC').':</b> '.$this->email_tobcc;
1621  } */
1622  }
1623  if (!empty($this->note_private)) {
1624  $tooltip .= '<br><br><b>'.$langs->trans('Description').':</b><br>';
1625  $texttoshow = dolGetFirstLineOfText($this->note_private, 10);
1626  $tooltip .= (dol_textishtml($texttoshow) ? str_replace(array("\r", "\n"), "", $texttoshow) : str_replace(array("\r", "\n"), '<br>', $texttoshow));
1627  }
1628  $linkclose = '';
1629  //if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && $this->type_color)
1630  // $linkclose = ' style="background-color:#'.$this->type_color.'"';
1631 
1632  if (empty($notooltip)) {
1633  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1634  $label = $langs->trans("ShowAction");
1635  $linkclose .= ' alt="'.dol_escape_htmltag($tooltip, 1).'"';
1636  }
1637  $linkclose .= ' title="'.dol_escape_htmltag($tooltip, 1, 0, '', 1).'"';
1638  $linkclose .= ' class="'.$classname.' classfortooltip"';
1639  } else {
1640  $linkclose .= ' class="'.$classname.'"';
1641  }
1642 
1643  $url = '';
1644  if ($option == 'birthday') {
1645  $url = DOL_URL_ROOT.'/contact/perso.php?id='.$this->id;
1646  } elseif ($option == 'holiday') {
1647  $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
1648  } else {
1649  $url = DOL_URL_ROOT.'/comm/action/card.php?id='.$this->id;
1650  }
1651 
1652  if ($option !== 'nolink') {
1653  // Add param to save lastsearch_values or not
1654  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1655  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1656  $add_save_lastsearch_values = 1;
1657  }
1658  if ($add_save_lastsearch_values) {
1659  $url .= '&save_lastsearch_values=1';
1660  }
1661  }
1662 
1663  $linkstart = '<a href="'.$url.'"';
1664  $linkstart .= $linkclose.'>';
1665  $linkend = '</a>';
1666 
1667  if ($option == 'nolink') {
1668  $linkstart = '';
1669  $linkend = '';
1670  }
1671 
1672  if ($withpicto == 2) {
1673  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1674  $label = $labeltype;
1675  }
1676  $labelshort = '';
1677  } else {
1678  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($label)) {
1679  $label = $labeltype;
1680  }
1681  if ($maxlength < 0) {
1682  $labelshort = $this->ref;
1683  } else {
1684  $labelshort = dol_trunc($label, $maxlength);
1685  }
1686  }
1687 
1688  if ($withpicto) {
1689  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) { // Add code into ()
1690  if ($labeltype) {
1691  $label .= (preg_match('/'.preg_quote($labeltype, '/').'/', $label) ? '' : ' ('.$langs->transnoentities("Action".$this->type_code).')');
1692  }
1693  }
1694  }
1695 
1696  $result .= $linkstart;
1697  if ($withpicto) {
1698  $result .= img_object(($notooltip ? '' : $langs->trans("ShowAction").': '.$label), ($overwritepicto ? $overwritepicto : 'action'), (($this->type_color && $overwritepicto) ? 'style="color: #'.$this->type_color.' !important;" ' : '').($notooltip ? 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'"' : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1699  }
1700  $result .= $labelshort;
1701  $result .= $linkend;
1702 
1703  global $action;
1704  $hookmanager->initHooks(array('actiondao'));
1705  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1706  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1707  if ($reshook > 0) {
1708  $result = $hookmanager->resPrint;
1709  } else {
1710  $result .= $hookmanager->resPrint;
1711  }
1712 
1713  return $result;
1714  }
1715 
1721  public function getTypePicto()
1722  {
1723  global $conf;
1724 
1725  $imgpicto = '';
1726  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1727  $color = '';
1728  if ($this->type_color) {
1729  $color = 'style="color: #'.$this->type_color.' !important;"';
1730  }
1731  if ($this->type_picto) {
1732  $imgpicto = img_picto('', $this->type_picto, 'class="paddingright"');
1733  } else {
1734  if ($this->type_code == 'AC_RDV') {
1735  $imgpicto = img_picto('', 'meeting', $color, false, 0, 0, '', 'paddingright');
1736  } elseif ($this->type_code == 'AC_TEL') {
1737  $imgpicto = img_picto('', 'object_phoning', $color, false, 0, 0, '', 'paddingright');
1738  } elseif ($this->type_code == 'AC_FAX') {
1739  $imgpicto = img_picto('', 'object_phoning_fax', $color, false, 0, 0, '', 'paddingright');
1740  } elseif ($this->type_code == 'AC_EMAIL' || $this->type_code == 'AC_EMAIL_IN') {
1741  $imgpicto = img_picto('', 'object_email', $color, false, 0, 0, '', 'paddingright');
1742  } elseif ($this->type_code == 'AC_INT') {
1743  $imgpicto = img_picto('', 'object_intervention', $color, false, 0, 0, '', 'paddingright');
1744  } elseif ($this->type_code == 'AC_OTH' && $this->code == 'TICKET_MSG') {
1745  $imgpicto = img_picto('', 'object_conversation', $color, false, 0, 0, '', 'paddingright');
1746  } elseif ($this->type != 'systemauto') {
1747  $imgpicto = img_picto('', 'user-cog', $color, false, 0, 0, '', 'paddingright');
1748  } else {
1749  $imgpicto = img_picto('', 'cog', $color, false, 0, 0, '', 'paddingright');
1750  }
1751  }
1752  } else {
1753  // 2 picto: 1 for auto, 1 for manual
1754  if ($this->type != 'systemauto') {
1755  $imgpicto = img_picto('', 'user-cog', '', false, 0, 0, '', 'paddingright');
1756  } else {
1757  $imgpicto = img_picto('', 'cog', '', false, 0, 0, '', 'paddingright');
1758  }
1759  }
1760  return $imgpicto;
1761  }
1762 
1763 
1774  public function setCategories($categories)
1775  {
1776  // Handle single category
1777  if (!is_array($categories)) {
1778  $categories = array($categories);
1779  }
1780 
1781  // Get current categories
1782  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1783  $c = new Categorie($this->db);
1784  $existing = $c->containing($this->id, Categorie::TYPE_ACTIONCOMM, 'id');
1785 
1786  // Diff
1787  if (is_array($existing)) {
1788  $to_del = array_diff($existing, $categories);
1789  $to_add = array_diff($categories, $existing);
1790  } else {
1791  $to_del = array(); // Nothing to delete
1792  $to_add = $categories;
1793  }
1794 
1795  // Process
1796  foreach ($to_del as $del) {
1797  if ($c->fetch($del) > 0) {
1798  $c->del_type($this, Categorie::TYPE_ACTIONCOMM);
1799  }
1800  }
1801  foreach ($to_add as $add) {
1802  if ($c->fetch($add) > 0) {
1803  $c->add_type($this, Categorie::TYPE_ACTIONCOMM);
1804  }
1805  }
1806  return;
1807  }
1808 
1809  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1821  public function build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday = 0)
1822  {
1823  global $hookmanager;
1824 
1825  // phpcs:enable
1826  global $conf, $langs, $dolibarr_main_url_root, $mysoc;
1827 
1828  require_once DOL_DOCUMENT_ROOT."/core/lib/xcal.lib.php";
1829  require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
1830  require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
1831 
1832  dol_syslog(get_class($this)."::build_exportfile Build export file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".count($filters), LOG_DEBUG);
1833 
1834  // Check parameters
1835  if (empty($format)) {
1836  return -1;
1837  }
1838 
1839  // Clean parameters
1840  if (!$filename) {
1841  $extension = 'vcs';
1842  if ($format == 'ical') {
1843  $extension = 'ics';
1844  }
1845  $filename = $format.'.'.$extension;
1846  }
1847 
1848  // Create dir and define output file (definitive and temporary)
1849  $result = dol_mkdir($conf->agenda->dir_temp);
1850  $outputfile = $conf->agenda->dir_temp.'/'.$filename;
1851 
1852  $result = 0;
1853 
1854  $buildfile = true;
1855  $login = ''; $logina = ''; $logind = ''; $logint = '';
1856 
1857  $now = dol_now();
1858 
1859  if ($cachedelay) {
1860  $nowgmt = dol_now();
1861  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1862  if (dol_filemtime($outputfile) > ($nowgmt - $cachedelay)) {
1863  dol_syslog(get_class($this)."::build_exportfile file ".$outputfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay."). Build is canceled");
1864  $buildfile = false;
1865  }
1866  }
1867 
1868  if ($buildfile) {
1869  // Build event array
1870  $eventarray = array();
1871 
1872  $sql = "SELECT a.id,";
1873  $sql .= " a.datep,"; // Start
1874  $sql .= " a.datep2,"; // End
1875  $sql .= " a.durationp,"; // deprecated
1876  $sql .= " a.datec, a.tms as datem,";
1877  $sql .= " a.label, a.code, a.note as note_private, a.fk_action as type_id,";
1878  $sql .= " a.fk_soc,";
1879  $sql .= " a.fk_user_author, a.fk_user_mod,";
1880  $sql .= " a.fk_user_action,";
1881  $sql .= " a.fk_contact, a.percent as percentage,";
1882  $sql .= " a.fk_element, a.elementtype,";
1883  $sql .= " a.priority, a.fulldayevent, a.location, a.transparency,";
1884  $sql .= " u.firstname, u.lastname, u.email,";
1885  $sql .= " s.nom as socname,";
1886  $sql .= " c.id as type_id, c.code as type_code, c.libelle as type_label,";
1887  $sql .= " num_vote, event_paid, a.status";
1888  $sql .= " FROM (".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."actioncomm as a)";
1889  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author"; // Link to get author of event for export
1890  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc";
1891 
1892  $parameters = array('filters' => $filters);
1893  $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters); // Note that $action and $object may have been modified by hook
1894  $sql .= $hookmanager->resPrint;
1895 
1896  // We must filter on assignement table
1897  if ($filters['logint']) {
1898  $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
1899  }
1900  $sql .= " WHERE a.fk_action=c.id";
1901  $sql .= " AND a.entity IN (".getEntity('agenda').")";
1902  foreach ($filters as $key => $value) {
1903  if ($key == 'notolderthan' && $value != '') {
1904  $sql .= " AND a.datep >= '".$this->db->idate($now - ($value * 24 * 60 * 60))."'";
1905  }
1906  if ($key == 'year') {
1907  $sql .= " AND a.datep BETWEEN '".$this->db->idate(dol_get_first_day($value, 1))."' AND '".$this->db->idate(dol_get_last_day($value, 12))."'";
1908  }
1909  if ($key == 'id') {
1910  $sql .= " AND a.id=".(is_numeric($value) ? $value : 0);
1911  }
1912  if ($key == 'idfrom') {
1913  $sql .= " AND a.id >= ".(is_numeric($value) ? $value : 0);
1914  }
1915  if ($key == 'idto') {
1916  $sql .= " AND a.id <= ".(is_numeric($value) ? $value : 0);
1917  }
1918  if ($key == 'project') {
1919  $sql .= " AND a.fk_project=".(is_numeric($value) ? $value : 0);
1920  }
1921  if ($key == 'actiontype') {
1922  $sql .= " AND c.type = '".$this->db->escape($value)."'";
1923  }
1924  if ($key == 'notactiontype') {
1925  $sql .= " AND c.type <> '".$this->db->escape($value)."'";
1926  }
1927  // We must filter on assignement table
1928  if ($key == 'logint') {
1929  $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
1930  }
1931  if ($key == 'logina') {
1932  $logina = $value;
1933  $condition = '=';
1934  if (preg_match('/^!/', $logina)) {
1935  $logina = preg_replace('/^!/', '', $logina);
1936  $condition = '<>';
1937  }
1938  $userforfilter = new User($this->db);
1939  $result = $userforfilter->fetch('', $logina);
1940  if ($result > 0) {
1941  $sql .= " AND a.fk_user_author ".$condition." ".$userforfilter->id;
1942  } elseif ($result < 0 || $condition == '=') {
1943  $sql .= " AND a.fk_user_author = 0";
1944  }
1945  }
1946  if ($key == 'logint') {
1947  $logint = $value;
1948  $condition = '=';
1949  if (preg_match('/^!/', $logint)) {
1950  $logint = preg_replace('/^!/', '', $logint);
1951  $condition = '<>';
1952  }
1953  $userforfilter = new User($this->db);
1954  $result = $userforfilter->fetch('', $logint);
1955  if ($result > 0) {
1956  $sql .= " AND ar.fk_element = ".((int) $userforfilter->id);
1957  } elseif ($result < 0 || $condition == '=') {
1958  $sql .= " AND ar.fk_element = 0";
1959  }
1960  }
1961  if ($key == 'module') {
1962  $sql .= " AND c.module LIKE '%".$this->db->escape($value)."'";
1963  }
1964  if ($key == 'status') {
1965  $sql .= " AND a.status =".((int) $value);
1966  }
1967  }
1968 
1969  $sql .= " AND a.datep IS NOT NULL"; // To exclude corrupted events and avoid errors in lightning/sunbird import
1970 
1971  $parameters = array('filters' => $filters);
1972  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
1973  $sql .= $hookmanager->resPrint;
1974 
1975  $sql .= " ORDER by datep";
1976  //print $sql;exit;
1977 
1978  dol_syslog(get_class($this)."::build_exportfile select events", LOG_DEBUG);
1979  $resql = $this->db->query($sql);
1980  if ($resql) {
1981  // Note: Output of sql request is encoded in $conf->file->character_set_client
1982  // This assignment in condition is not a bug. It allows walking the results.
1983  $diff = 0;
1984  while ($obj = $this->db->fetch_object($resql)) {
1985  $qualified = true;
1986 
1987  // 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
1988  $event = array();
1989  $event['uid'] = 'dolibarragenda-'.$this->db->database_name.'-'.$obj->id."@".$_SERVER["SERVER_NAME"];
1990  $event['type'] = $type;
1991 
1992  $datestart = $this->db->jdate($obj->datep) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
1993 
1994  // fix for -> Warning: A non-numeric value encountered
1995  if (is_numeric($this->db->jdate($obj->datep2))) {
1996  $dateend = $this->db->jdate($obj->datep2) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
1997  } else {
1998  // use start date as fall-back to avoid pb with empty end date on ICS readers
1999  $dateend = $datestart;
2000  }
2001 
2002  $duration = ($datestart && $dateend) ? ($dateend - $datestart) : 0;
2003  $event['summary'] = $obj->label.($obj->socname ? " (".$obj->socname.")" : "");
2004 
2005  $event['desc'] = $obj->note_private;
2006  $event['startdate'] = $datestart;
2007  $event['enddate'] = $dateend; // Not required with type 'journal'
2008  $event['duration'] = $duration; // Not required with type 'journal'
2009  $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname);
2010  $event['priority'] = $obj->priority;
2011  $event['fulldayevent'] = $obj->fulldayevent;
2012  $event['location'] = $obj->location;
2013  $event['transparency'] = (($obj->transparency > 0) ? 'OPAQUE' : 'TRANSPARENT'); // OPAQUE (busy) or TRANSPARENT (not busy)
2014  $event['category'] = $obj->type_label;
2015  $event['email'] = $obj->email;
2016  // Define $urlwithroot
2017  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
2018  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
2019  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2020  $url = $urlwithroot.'/comm/action/card.php?id='.$obj->id;
2021  $event['url'] = $url;
2022  $event['created'] = $this->db->jdate($obj->datec) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2023  $event['modified'] = $this->db->jdate($obj->datem) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2024  $event['num_vote'] = $this->num_vote;
2025  $event['event_paid'] = $this->event_paid;
2026  $event['status'] = $this->status;
2027 
2028  // TODO: find a way to call "$this->fetch_userassigned();" without override "$this" properties
2029  $this->id = $obj->id;
2030  $this->fetch_userassigned(false);
2031 
2032  $assignedUserArray = array();
2033 
2034  foreach ($this->userassigned as $key => $value) {
2035  $assignedUser = new User($this->db);
2036  $assignedUser->fetch($value['id']);
2037 
2038  $assignedUserArray[$key] = $assignedUser;
2039  }
2040 
2041  $event['assignedUsers'] = $assignedUserArray;
2042 
2043  if ($qualified && $datestart) {
2044  $eventarray[] = $event;
2045  }
2046  $diff++;
2047  }
2048 
2049  $parameters = array('filters' => $filters, 'eventarray' => &$eventarray);
2050  $reshook = $hookmanager->executeHooks('addMoreEventsExport', $parameters); // Note that $action and $object may have been modified by hook
2051  if ($reshook > 0) {
2052  $eventarray = $hookmanager->resArray;
2053  }
2054  } else {
2055  $this->error = $this->db->lasterror();
2056  return -1;
2057  }
2058 
2059  if ($exportholiday == 1) {
2060  $langs->load("holidays");
2061  $title = $langs->trans("Holidays");
2062 
2063  $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.email, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status";
2064  $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
2065  $sql .= " WHERE u.rowid = x.fk_user";
2066  $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
2067  $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
2068 
2069  $resql = $this->db->query($sql);
2070  if ($resql) {
2071  $num = $this->db->num_rows($resql);
2072  $i = 0;
2073 
2074  while ($i < $num) {
2075  $obj = $this->db->fetch_object($resql);
2076  $event = array();
2077 
2078  if ($obj->halfday == -1) {
2079  $event['fulldayevent'] = false;
2080 
2081  $timestampStart = dol_stringtotime($obj->date_start." 00:00:00", 0);
2082  $timestampEnd = dol_stringtotime($obj->date_end." 12:00:00", 0);
2083  } elseif ($obj->halfday == 1) {
2084  $event['fulldayevent'] = false;
2085 
2086  $timestampStart = dol_stringtotime($obj->date_start." 12:00:00", 0);
2087  $timestampEnd = dol_stringtotime($obj->date_end." 23:59:59", 0);
2088  } else {
2089  $event['fulldayevent'] = true;
2090 
2091  $timestampStart = dol_stringtotime($obj->date_start." 00:00:00", 0);
2092  $timestampEnd = dol_stringtotime($obj->date_end." 23:59:59", 0);
2093  }
2094 
2095  if (!empty($conf->global->AGENDA_EXPORT_FIX_TZ)) {
2096  $timestampStart = $timestampStart - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2097  $timestampEnd = $timestampEnd - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2098  }
2099 
2100  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
2101  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2102  $url = $urlwithroot.'/holiday/card.php?id='.$obj->rowid;
2103 
2104  $event['uid'] = 'dolibarrholiday-'.$this->db->database_name.'-'.$obj->rowid."@".$_SERVER["SERVER_NAME"];
2105  $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname);
2106  $event['type'] = 'event';
2107  $event['category'] = "Holiday";
2108  $event['transparency'] = 'OPAQUE';
2109  $event['email'] = $obj->email;
2110  $event['created'] = $timestampStart;
2111  $event['modified'] = $timestampStart;
2112  $event['startdate'] = $timestampStart;
2113  $event['enddate'] = $timestampEnd;
2114  $event['duration'] = $timestampEnd - $timestampStart;
2115  $event['url'] = $url;
2116 
2117  if ($obj->status == 2) {
2118  // 2 = leave wait for approval
2119  $event['summary'] = $title." - ".$obj->lastname." (wait for approval)";
2120  } else {
2121  // 3 = leave approved
2122  $event['summary'] = $title." - ".$obj->lastname;
2123  }
2124 
2125  $eventarray[] = $event;
2126 
2127  $i++;
2128  }
2129  }
2130  }
2131 
2132  $langs->load("agenda");
2133 
2134  // Define title and desc
2135  $more = '';
2136  if ($login) {
2137  $more = $langs->transnoentities("User").' '.$login;
2138  }
2139  if ($logina) {
2140  $more = $langs->transnoentities("ActionsAskedBy").' '.$logina;
2141  }
2142  if ($logint) {
2143  $more = $langs->transnoentities("ActionsToDoBy").' '.$logint;
2144  }
2145  if ($logind) {
2146  $more = $langs->transnoentities("ActionsDoneBy").' '.$logind;
2147  }
2148  if ($more) {
2149  $title = 'Dolibarr actions '.$mysoc->name.' - '.$more;
2150  $desc = $more;
2151  $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
2152  } else {
2153  $title = 'Dolibarr actions '.$mysoc->name;
2154  $desc = $langs->transnoentities('ListOfActions');
2155  $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
2156  }
2157 
2158  // Create temp file
2159  $outputfiletmp = tempnam($conf->agenda->dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
2160  @chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
2161 
2162  // Write file
2163  if ($format == 'vcal') {
2164  $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2165  } elseif ($format == 'ical') {
2166  $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2167  } elseif ($format == 'rss') {
2168  $result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
2169  }
2170 
2171  if ($result >= 0) {
2172  if (dol_move($outputfiletmp, $outputfile, 0, 1)) {
2173  $result = 1;
2174  } else {
2175  $this->error = 'Failed to rename '.$outputfiletmp.' into '.$outputfile;
2176  dol_syslog(get_class($this)."::build_exportfile ".$this->error, LOG_ERR);
2177  dol_delete_file($outputfiletmp, 0, 1);
2178  $result = -1;
2179  }
2180  } else {
2181  dol_syslog(get_class($this)."::build_exportfile build_xxxfile function fails to for format=".$format." outputfiletmp=".$outputfile, LOG_ERR);
2182  dol_delete_file($outputfiletmp, 0, 1);
2183  $langs->load("errors");
2184  $this->error = $langs->trans("ErrorFailToCreateFile", $outputfile);
2185  }
2186  }
2187 
2188  return $result;
2189  }
2190 
2198  public function initAsSpecimen()
2199  {
2200  global $user;
2201 
2202  $now = dol_now();
2203 
2204  // Initialise parametres
2205  $this->id = 0;
2206  $this->specimen = 1;
2207 
2208  $this->type_code = 'AC_OTH';
2209  $this->code = 'AC_SPECIMEN_CODE';
2210  $this->label = 'Label of event Specimen';
2211  $this->datec = $now;
2212  $this->datem = $now;
2213  $this->datep = $now;
2214  $this->datef = $now;
2215  $this->fulldayevent = 0;
2216  $this->percentage = 0;
2217  $this->status = 0;
2218  $this->location = 'Location';
2219  $this->transparency = 1; // 1 means opaque
2220  $this->priority = 1;
2221  //$this->note_public = "This is a 'public' note.";
2222  $this->note_private = "This is a 'private' note.";
2223 
2224  $this->userownerid = $user->id;
2225  $this->userassigned[$user->id] = array('id'=>$user->id, 'transparency'=> 1);
2226  return 1;
2227  }
2228 
2237  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
2238  {
2239  $tables = array(
2240  'actioncomm'
2241  );
2242 
2243  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
2244  }
2245 
2254  public static function replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
2255  {
2256  $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'actioncomm SET fk_element = ' . ((int) $dest_id) . ' WHERE elementtype="product" AND fk_element = '.((int) $origin_id);
2257  // using $dbs, not $this->db because function is static
2258  if (!$dbs->query($sql)) {
2259  //$this->errors = $dbs->lasterror();
2260  return false;
2261  }
2262 
2263  return true;
2264  }
2265 
2271  public function hasDelay()
2272  {
2273  global $conf;
2274 
2275  $now = dol_now();
2276 
2277  return $this->datep && ($this->datep < ($now - $conf->agenda->warning_delay));
2278  }
2279 
2280 
2289  public function loadReminders($type = '', $fk_user = 0, $onlypast = true)
2290  {
2291  global $conf, $langs, $user;
2292 
2293  $error = 0;
2294 
2295  $this->reminders = array();
2296 
2297  //Select all action comm reminders for event
2298  $sql = "SELECT rowid as id, typeremind, dateremind, status, offsetvalue, offsetunit, fk_user";
2299  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
2300  $sql .= " WHERE fk_actioncomm = ".((int) $this->id);
2301  if ($onlypast) {
2302  $sql .= " AND dateremind <= '".$this->db->idate(dol_now())."'";
2303  }
2304  if ($type) {
2305  $sql .= " AND typeremind ='".$this->db->escape($type)."'";
2306  }
2307  if ($fk_user > 0) {
2308  $sql .= " AND fk_user = ".((int) $fk_user);
2309  }
2310  if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2311  $sql .= " AND typeremind != 'email'";
2312  }
2313  if (empty($conf->global->AGENDA_REMINDER_BROWSER)) {
2314  $sql .= " AND typeremind != 'browser'";
2315  }
2316 
2317  $sql .= $this->db->order("dateremind", "ASC");
2318  $resql = $this->db->query($sql);
2319 
2320  if ($resql) {
2321  while ($obj = $this->db->fetch_object($resql)) {
2322  $tmpactioncommreminder = new ActionCommReminder($this->db);
2323  $tmpactioncommreminder->id = $obj->id;
2324  $tmpactioncommreminder->typeremind = $obj->typeremind;
2325  $tmpactioncommreminder->dateremind = $obj->dateremind;
2326  $tmpactioncommreminder->offsetvalue = $obj->offsetvalue;
2327  $tmpactioncommreminder->offsetunit = $obj->offsetunit;
2328  $tmpactioncommreminder->status = $obj->status;
2329  $tmpactioncommreminder->fk_user = $obj->fk_user;
2330 
2331  $this->reminders[$obj->id] = $tmpactioncommreminder;
2332  }
2333  } else {
2334  $this->error = $this->db->lasterror();
2335  $error++;
2336  }
2337 
2338  return count($this->reminders);
2339  }
2340 
2341 
2348  public function sendEmailsReminder()
2349  {
2350  global $conf, $langs, $user;
2351 
2352  $error = 0;
2353  $this->output = '';
2354  $this->error = '';
2355  $nbMailSend = 0;
2356  $errorsMsg = array();
2357 
2358  if (empty($conf->agenda->enabled)) { // Should not happen. If module disabled, cron job should not be visible.
2359  $langs->load("agenda");
2360  $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Agenda"));
2361  return 0;
2362  }
2363  if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2364  $langs->load("agenda");
2365  $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Agenda"));
2366  return 0;
2367  }
2368 
2369  $now = dol_now();
2370  $actionCommReminder = new ActionCommReminder($this->db);
2371 
2372  dol_syslog(__METHOD__, LOG_DEBUG);
2373 
2374  $this->db->begin();
2375 
2376  //Select all action comm reminders
2377  $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
2378  $sql .= " WHERE typeremind = 'email' AND status = 0";
2379  $sql .= " AND dateremind <= '".$this->db->idate($now)."'";
2380  $sql .= " AND entity IN (".getEntity('actioncomm').")";
2381  $sql .= $this->db->order("dateremind", "ASC");
2382  $resql = $this->db->query($sql);
2383 
2384  if ($resql) {
2385  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2386  $formmail = new FormMail($this->db);
2387 
2388  while ($obj = $this->db->fetch_object($resql)) {
2389  $res = $actionCommReminder->fetch($obj->id);
2390  if ($res < 0) {
2391  $error++;
2392  $errorsMsg[] = "Failed to load invoice ActionComm Reminder";
2393  }
2394 
2395  if (!$error) {
2396  //Select email template
2397  $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1);
2398 
2399  // Load event
2400  $res = $this->fetch($actionCommReminder->fk_actioncomm);
2401  if ($res > 0) {
2402  // PREPARE EMAIL
2403  $errormesg = '';
2404 
2405  // Make substitution in email content
2406  $substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this);
2407 
2408  complete_substitutions_array($substitutionarray, $langs, $this);
2409 
2410  // Content
2411  $sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
2412 
2413  //Topic
2414  $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->transnoentities('EventReminder'));
2415 
2416  // Recipient
2417  $recipient = new User($this->db);
2418  $res = $recipient->fetch($actionCommReminder->fk_user);
2419  if ($res > 0) {
2420  if (!empty($recipient->email)) {
2421  $to = $recipient->email;
2422  } else {
2423  $errormesg = "Failed to send remind to user id=".$actionCommReminder->fk_user.". No email defined for user.";
2424  $error++;
2425  }
2426  } else {
2427  $errormesg = "Failed to load recipient with user id=".$actionCommReminder->fk_user;
2428  $error++;
2429  }
2430 
2431  // Sender
2432  $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
2433  if (empty($from)) {
2434  $errormesg = "Failed to get sender into global setup MAIN_MAIL_EMAIL_FROM";
2435  $error++;
2436  }
2437 
2438  if (!$error) {
2439  // Errors Recipient
2440  $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO;
2441 
2442  // Mail Creation
2443  $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', '');
2444 
2445  // Sending Mail
2446  if ($cMailFile->sendfile()) {
2447  $nbMailSend++;
2448  } else {
2449  $errormesg = $cMailFile->error.' : '.$to;
2450  $error++;
2451  }
2452  }
2453 
2454  if (!$error) {
2455  $actionCommReminder->status = $actionCommReminder::STATUS_DONE;
2456 
2457  $res = $actionCommReminder->update($user);
2458  if ($res < 0) {
2459  $errorsMsg[] = "Failed to update status to done of ActionComm Reminder";
2460  $error++;
2461  break; // This is to avoid to have this error on all the selected email. If we fails here for one record, it may fails for others. We must solve first.
2462  }
2463  } else {
2464  $actionCommReminder->status = $actionCommReminder::STATUS_ERROR;
2465  $actionCommReminder->lasterror = dol_trunc($errormesg, 128, 'right', 'UTF-8', 1);
2466 
2467  $res = $actionCommReminder->update($user);
2468  if ($res < 0) {
2469  $errorsMsg[] = "Failed to update status to error of ActionComm Reminder";
2470  $error++;
2471  break; // This is to avoid to have this error on all the selected email. If we fails here for one record, it may fails for others. We must solve first.
2472  } else {
2473  $errorsMsg[] = $errormesg;
2474  }
2475  }
2476  } else {
2477  $errorsMsg[] = 'Failed to fetch record actioncomm with ID = '.$actionCommReminder->fk_actioncomm;
2478  $error++;
2479  }
2480  }
2481  }
2482  } else {
2483  $error++;
2484  }
2485 
2486  if (!$error) {
2487  // Delete also very old past events (we do not keep more than 1 month record in past)
2488  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
2489  $sql .= " WHERE dateremind < '".$this->db->idate($now - (3600 * 24 * 32))."'";
2490  $sql .= " AND status = ".((int) $actionCommReminder::STATUS_DONE);
2491  $resql = $this->db->query($sql);
2492 
2493  if (!$resql) {
2494  $errorsMsg[] = 'Failed to delete old reminders';
2495  //$error++; // If this fails, we must not rollback other SQL requests already done. Never mind.
2496  }
2497  }
2498 
2499  if (!$error) {
2500  $this->output = 'Nb of emails sent : '.$nbMailSend;
2501  $this->db->commit();
2502  return 0;
2503  } else {
2504  $this->db->commit(); // We commit also on error, to have the error message recorded.
2505  $this->error = 'Nb of emails sent : '.$nbMailSend.', '.(!empty($errorsMsg)) ? join(', ', $errorsMsg) : $error;
2506  return $error;
2507  }
2508  }
2509 
2518  public function updatePercent($id, $percent, $usermodid = 0)
2519  {
2520  $this->db->begin();
2521 
2522  $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm ";
2523  $sql .= " SET percent = ".(int) $percent;
2524  if ($usermodid > 0) $sql .= ", fk_user_mod = ".$usermodid;
2525  $sql .= " WHERE id = ".((int) $id);
2526 
2527  if ($this->db->query($sql)) {
2528  $this->db->commit();
2529  return 1;
2530  } else {
2531  $this->db->rollback();
2532  $this->error = $this->db->lasterror();
2533  return -1;
2534  }
2535  }
2536 }
Class to manage different types of events.
Classe permettant la generation du formulaire html d&#39;envoi de mail unitaire Usage: $formail = new For...
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
updatePercent($id, $percent, $usermodid=0)
Udpate the percent value of a event with the given id.
Class for ActionCommReminder.
dol_mkdir($dir, $dataroot= '', $newmask= '')
Creation of a directory (this can create recursive subdir)
loadReminders($type= '', $fk_user=0, $onlypast=true)
Load event reminder of events.
Class to manage agenda events (actions)
$conf db
API class for accounts.
Definition: inc.php:41
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
LibStatut($percent, $mode, $hidenastatus=0, $datestart= '')
Return label of action status.
const EVENT_FINISHED
Typical value for a event that is in a finished state.
dol_now($mode= 'auto')
Return date for now.
create(User $user, $notrigger=0)
Add an action/event into database.
fetchResources()
Initialize $this-&gt;userassigned &amp; this-&gt;socpeopleassigned array with list of id of user and contact as...
Class to manage Dolibarr users.
Definition: user.class.php:44
Class to manage Dolibarr database access.
setCategories($categories)
Sets object to supplied categories.
build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday=0)
Export events from database into a cal file.
info($id)
Charge les informations d&#39;ordre info dans l&#39;objet facture.
load_board($user, $load_state_board=0)
Load indicators for dashboard (this-&gt;nbtodo and this-&gt;nbtodolate)
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:551
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition: date.lib.php:383
getActions($socid=0, $fk_element=0, $elementtype= '', $filter= '', $sortfield= 'a.datep', $sortorder= 'DESC', $limit=0)
Load all objects with filters.
update(User $user, $notrigger=0)
Update action into database If percentage = 100, on met a jour date 100%.
createFromClone(User $fuser, $socid)
Load an object from its id and create a new one in database.
build_calfile($format, $title, $desc, $events_array, $outputfile)
Build a file from an array of events All input params and data must be encoded in $conf-&gt;charset_outp...
Definition: xcal.lib.php:35
getNomUrl($withpicto=0, $maxlength=0, $classname= '', $option= '', $overwritepicto=0, $notooltip=0, $save_lastsearch_value=-1)
Return URL of event Use $this-&gt;id, $this-&gt;type_code, $this-&gt;label and $this-&gt;type_label.
__construct(DoliDB $db)
Constructor.
sendEmailsReminder()
Send reminders by emails CAN BE A CRON TASK.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
Definition: files.lib.php:854
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
initAsSpecimen()
Initialise an instance with random values.
const EVENT_IN_PROGRESS
Typical value for a event that is in a progress state.
Class to manage categories.
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter= '', $url= '', $langcode= '')
Build a file from an array of events.
Definition: xcal.lib.php:311
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge, other ! Closing when no payment: replaced, abandoned
fetch($id, $ref= '', $ref_ext= '', $email_msgid= '', $loadresources=1)
Load object from database.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile-&gt;sendfile();.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
const EVENT_TODO
Typical value for a event that is in a todo state.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
deleteExtraFields()
Delete all extra fields values for the current object.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this-&gt;array_options This method is in most cases call...
hasDelay()
Is the action delayed?
$recurid
Properties to manage the recurring events.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
dolGetFirstLineOfText($text, $nboflines=1, $charset= 'UTF-8')
Return first line of text.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:570
call_trigger($triggerName, $user)
Call trigger based on this instance.
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:592
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
$object ref
Definition: info.php:77
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;…&#39; if string larger than length. ...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
query($query, $usesavepoint=0, $type= 'auto', $result_mode=0)
Execute a SQL request and return the resultset.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=&gt;newva...
getLibStatut($mode, $hidenastatus=0)
Return the label of the status.
getTypePicto()
Return Picto of type of event.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
Definition: files.lib.php:1230
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the &quot;subst...
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
fetch_userassigned($override=true)
Initialize this-&gt;userassigned array with list of id of user assigned to event.