dolibarr  18.0.0-alpha
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-2023 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 
272 
278  public $societe;
279 
285  public $contact;
286 
287  // Properties for links to other objects
291  public $fk_element; // Id of record
292 
296  public $elementid;
297 
301  public $elementtype;
302 
306  public $icalname;
307 
311  public $icalcolor;
312 
316  public $extraparams;
317 
321  public $actions = array();
322 
326  public $email_msgid;
327 
331  public $email_from;
332 
336  public $email_sender;
337 
341  public $email_to;
342 
346  public $email_tocc;
350  public $email_tobcc;
351 
355  public $email_subject;
356 
360  public $errors_to;
361 
365  public $num_vote;
366 
370  public $event_paid;
371 
375  public $status;
376 
380  public $recurid; /* A string YYYYMMDDHHMMSS shared by allevent of same serie */
381  public $recurrule; /* Rule of recurring */
382  public $recurdateend; /* Repeat until this date */
383 
384  public $calling_duration;
385 
386 
390  const EVENT_TODO = 0;
391 
395  const EVENT_IN_PROGRESS = 50;
396 
400  const EVENT_FINISHED = 100;
401 
402 
403  public $fields = array();
404 
405 
411  public function __construct(DoliDB $db)
412  {
413  $this->db = $db;
414  }
415 
424  public function create(User $user, $notrigger = 0)
425  {
426  global $langs, $conf;
427 
428  $error = 0;
429  $now = dol_now();
430 
431  // Check parameters
432  if (!isset($this->userownerid) || (string) $this->userownerid === '') { // $this->userownerid may be 0 (anonymous event) or > 0
433  dol_syslog("You tried to create an event but mandatory property ownerid was not defined", LOG_WARNING);
434  $this->errors[] = 'ErrorActionCommPropertyUserowneridNotDefined';
435  return -1;
436  }
437 
438  // Clean parameters
439  $this->label = dol_trunc(trim($this->label), 128);
440  $this->location = dol_trunc(trim($this->location), 128);
441  $this->note_private = dol_htmlcleanlastbr(trim(empty($this->note_private) ? $this->note : $this->note_private));
442  if (empty($this->percentage)) {
443  $this->percentage = 0;
444  }
445  if (empty($this->priority) || !is_numeric($this->priority)) {
446  $this->priority = 0;
447  }
448  if (empty($this->fulldayevent)) {
449  $this->fulldayevent = 0;
450  }
451  if (empty($this->transparency)) {
452  $this->transparency = 0;
453  }
454  if ($this->percentage > 100) {
455  $this->percentage = 100;
456  }
457  //if ($this->percentage == 100 && ! $this->dateend) $this->dateend = $this->date;
458  if (!empty($this->datep) && !empty($this->datef)) {
459  $this->durationp = ($this->datef - $this->datep); // deprecated
460  }
461  //if (!empty($this->date) && !empty($this->dateend)) $this->durationa=($this->dateend - $this->date);
462  if (!empty($this->datep) && !empty($this->datef) && $this->datep > $this->datef) {
463  $this->datef = $this->datep;
464  }
465  //if (!empty($this->date) && !empty($this->dateend) && $this->date > $this->dateend) $this->dateend=$this->date;
466  if (!isset($this->fk_project) || $this->fk_project < 0) {
467  $this->fk_project = 0;
468  }
469  // For backward compatibility
470  if ($this->elementtype == 'facture') {
471  $this->elementtype = 'invoice';
472  }
473  if ($this->elementtype == 'commande') {
474  $this->elementtype = 'order';
475  }
476  if ($this->elementtype == 'contrat') {
477  $this->elementtype = 'contract';
478  }
479 
480  if (!is_array($this->userassigned) && !empty($this->userassigned)) { // For backward compatibility when userassigned was an int instead of an array
481  $tmpid = (int) $this->userassigned;
482  $this->userassigned = array();
483  $this->userassigned[$tmpid] = array('id'=>$tmpid, 'transparency'=>$this->transparency);
484  }
485 
486  $userownerid = $this->userownerid;
487  $userdoneid = $this->userdoneid;
488 
489  // Be sure assigned user is defined as an array of array('id'=>,'mandatory'=>,...).
490  if (empty($this->userassigned) || count($this->userassigned) == 0 || !is_array($this->userassigned)) {
491  $this->userassigned = array($userownerid=>array('id'=>$userownerid, 'transparency'=>$this->transparency));
492  }
493 
494  if (!$this->type_id || !$this->type_code) {
495  $key = empty($this->type_id) ? $this->type_code : $this->type_id;
496 
497  // Get id from code
498  $cactioncomm = new CActionComm($this->db);
499  $result = $cactioncomm->fetch($key);
500 
501  if ($result > 0) {
502  $this->type_id = $cactioncomm->id;
503  $this->type_code = $cactioncomm->code;
504  } elseif ($result == 0) {
505  $this->error = $langs->trans('ErrorActionCommBadType', $this->type_id, $this->type_code);
506  return -1;
507  } else {
508  $this->error = $cactioncomm->error;
509  return -1;
510  }
511  }
512  $code = empty($this->code) ? $this->type_code : $this->code;
513 
514  // Check parameters
515  if (!$this->type_id) {
516  $this->error = "ErrorWrongParameters";
517  return -1;
518  }
519 
520  $this->db->begin();
521 
522  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm";
523  $sql .= "(ref,";
524  $sql .= "datec,";
525  $sql .= "datep,";
526  $sql .= "datep2,";
527  $sql .= "durationp,"; // deprecated
528  $sql .= "fk_action,";
529  $sql .= "code,";
530  $sql .= "ref_ext,";
531  $sql .= "fk_soc,";
532  $sql .= "fk_project,";
533  $sql .= "note,";
534  $sql .= "fk_contact,";
535  $sql .= "fk_user_author,";
536  $sql .= "fk_user_action,";
537  $sql .= "fk_user_done,";
538  $sql .= "label,percent,priority,fulldayevent,location,";
539  $sql .= "transparency,";
540  $sql .= "fk_element,";
541  $sql .= "elementtype,";
542  $sql .= "entity,";
543  $sql .= "extraparams,";
544  // Fields emails
545  $sql .= "email_msgid,";
546  $sql .= "email_from,";
547  $sql .= "email_sender,";
548  $sql .= "email_to,";
549  $sql .= "email_tocc,";
550  $sql .= "email_tobcc,";
551  $sql .= "email_subject,";
552  $sql .= "errors_to,";
553  $sql .= "recurid,";
554  $sql .= "recurrule,";
555  $sql .= "recurdateend,";
556  $sql .= "num_vote,";
557  $sql .= "event_paid,";
558  $sql .= "status,";
559  $sql .= "ip";
560  $sql .= ") VALUES (";
561  $sql .= "'(PROV)', ";
562  $sql .= "'".$this->db->idate($now)."', ";
563  $sql .= (strval($this->datep) != '' ? "'".$this->db->idate($this->datep)."'" : "null").", ";
564  $sql .= (strval($this->datef) != '' ? "'".$this->db->idate($this->datef)."'" : "null").", ";
565  $sql .= ((isset($this->durationp) && $this->durationp >= 0 && $this->durationp != '') ? "'".$this->db->escape($this->durationp)."'" : "null").", "; // deprecated
566  $sql .= (isset($this->type_id) ? $this->type_id : "null").",";
567  $sql .= ($code ? ("'".$this->db->escape($code)."'") : "null").", ";
568  $sql .= (!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null").", ";
569  $sql .= ((isset($this->socid) && $this->socid > 0) ? ((int) $this->socid) : "null").", ";
570  $sql .= ((isset($this->fk_project) && $this->fk_project > 0) ? ((int) $this->fk_project) : "null").", ";
571  $sql .= " '".$this->db->escape($this->note_private)."', ";
572  $sql .= ((isset($this->contact_id) && $this->contact_id > 0) ? ((int) $this->contact_id) : "null").", "; // deprecated, use ->socpeopleassigned
573  $sql .= (isset($user->id) && $user->id > 0 ? $user->id : "null").", ";
574  $sql .= ($userownerid > 0 ? $userownerid : "null").", ";
575  $sql .= ($userdoneid > 0 ? $userdoneid : "null").", ";
576  $sql .= "'".$this->db->escape($this->label)."', ";
577  $sql .= "'".$this->db->escape($this->percentage)."', ";
578  $sql .= "'".$this->db->escape($this->priority)."', ";
579  $sql .= "'".$this->db->escape($this->fulldayevent)."', ";
580  $sql .= "'".$this->db->escape($this->location)."', ";
581  $sql .= "'".$this->db->escape($this->transparency)."', ";
582  $sql .= (!empty($this->fk_element) ? ((int) $this->fk_element) : "null").", ";
583  $sql .= (!empty($this->elementtype) ? "'".$this->db->escape($this->elementtype)."'" : "null").", ";
584  $sql .= ((int) $conf->entity).",";
585  $sql .= (!empty($this->extraparams) ? "'".$this->db->escape($this->extraparams)."'" : "null").", ";
586  // Fields emails
587  $sql .= (!empty($this->email_msgid) ? "'".$this->db->escape($this->email_msgid)."'" : "null").", ";
588  $sql .= (!empty($this->email_from) ? "'".$this->db->escape($this->email_from)."'" : "null").", ";
589  $sql .= (!empty($this->email_sender) ? "'".$this->db->escape($this->email_sender)."'" : "null").", ";
590  $sql .= (!empty($this->email_to) ? "'".$this->db->escape($this->email_to)."'" : "null").", ";
591  $sql .= (!empty($this->email_tocc) ? "'".$this->db->escape($this->email_tocc)."'" : "null").", ";
592  $sql .= (!empty($this->email_tobcc) ? "'".$this->db->escape($this->email_tobcc)."'" : "null").", ";
593  $sql .= (!empty($this->email_subject) ? "'".$this->db->escape($this->email_subject)."'" : "null").", ";
594  $sql .= (!empty($this->errors_to) ? "'".$this->db->escape($this->errors_to)."'" : "null").", ";
595  $sql .= (!empty($this->recurid) ? "'".$this->db->escape($this->recurid)."'" : "null").", ";
596  $sql .= (!empty($this->recurrule) ? "'".$this->db->escape($this->recurrule)."'" : "null").", ";
597  $sql .= (!empty($this->recurdateend) ? "'".$this->db->idate($this->recurdateend)."'" : "null").", ";
598  $sql .= (!empty($this->num_vote) ? (int) $this->num_vote : "null").", ";
599  $sql .= (!empty($this->event_paid) ? (int) $this->event_paid : 0).", ";
600  $sql .= (!empty($this->status) ? (int) $this->status : "0").", ";
601  $sql .= (!empty($this->ip) ? "'".$this->db->escape($this->ip)."'" : "null");
602  $sql .= ")";
603 
604  dol_syslog(get_class($this)."::add", LOG_DEBUG);
605  $resql = $this->db->query($sql);
606  if ($resql) {
607  $this->ref = $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."actioncomm", "id");
608  $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm SET ref='".$this->db->escape($this->ref)."' WHERE id=".$this->id;
609  $resql = $this->db->query($sql);
610  if (!$resql) {
611  $error++;
612  dol_syslog('Error to process ref: '.$this->db->lasterror(), LOG_ERR);
613  $this->errors[] = $this->db->lasterror();
614  }
615  // Now insert assigned users
616  if (!$error) {
617  //dol_syslog(var_export($this->userassigned, true));
618  $already_inserted = array();
619  foreach ($this->userassigned as $key => $val) {
620  // Common value with new behavior is to have $val = array('id'=>iduser, 'transparency'=>0|1) and $this->userassigned is an array of iduser => $val.
621  if (!is_array($val)) { // For backward compatibility when $val='id'.
622  $val = array('id'=>$val);
623  }
624 
625  if ($val['id'] > 0) {
626  if (!empty($already_inserted[$val['id']])) {
627  continue;
628  }
629 
630  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
631  $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'])).")";
632 
633  $resql = $this->db->query($sql);
634  if (!$resql) {
635  $error++;
636  dol_syslog('Error to process userassigned: ' . $this->db->lasterror(), LOG_ERR);
637  $this->errors[] = $this->db->lasterror();
638  } else {
639  $already_inserted[$val['id']] = true;
640  }
641  //var_dump($sql);exit;
642  }
643  }
644  }
645 
646  if (!$error) {
647  if (!empty($this->socpeopleassigned)) {
648  $already_inserted = array();
649  foreach ($this->socpeopleassigned as $id => $val) {
650  // Common value with new behavior is to have $val = iduser and $this->socpeopleassigned is an array of iduser => $val.
651  if (!empty($already_inserted[$id])) {
652  continue;
653  }
654 
655  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
656  $sql .= " VALUES(".((int) $this->id).", 'socpeople', ".((int) $id).", 0, 0, 0)";
657 
658  $resql = $this->db->query($sql);
659  if (!$resql) {
660  $error++;
661  dol_syslog('Error to process socpeopleassigned: ' . $this->db->lasterror(), LOG_ERR);
662  $this->errors[] = $this->db->lasterror();
663  } else {
664  $already_inserted[$id] = true;
665  }
666  }
667  }
668  }
669 
670  if (!$error) {
671  // Actions on extra fields
672  $result = $this->insertExtraFields();
673  if ($result < 0) {
674  $error++;
675  }
676  }
677 
678  if (!$error && !$notrigger) {
679  // Call trigger
680  $result = $this->call_trigger('ACTION_CREATE', $user);
681  if ($result < 0) {
682  $error++;
683  }
684  // End call triggers
685  }
686 
687  if (!$error) {
688  $this->db->commit();
689  return $this->id;
690  } else {
691  $this->db->rollback();
692  return -1;
693  }
694  } else {
695  $this->db->rollback();
696  $this->error = $this->db->lasterror();
697  return -1;
698  }
699  }
700 
708  public function createFromClone(User $fuser, $socid)
709  {
710  global $hookmanager;
711 
712  $error = 0;
713 
714  $this->db->begin();
715 
716  // Load source object
717  $objFrom = clone $this;
718 
719  // Retrieve all extrafield
720  // fetch optionals attributes and labels
721  $this->fetch_optionals();
722 
723  //$this->fetch_userassigned();
724  $this->fetchResources();
725 
726  $this->id = 0;
727  $this->recurid = '';
728  $this->recurrule = '';
729  $this->recurdateend = '';
730 
731  // Create clone
732  $this->context['createfromclone'] = 'createfromclone';
733  $result = $this->create($fuser);
734  if ($result < 0) {
735  $error++;
736  }
737 
738  if (!$error) {
739  // Hook of thirdparty module
740  if (is_object($hookmanager)) {
741  $parameters = array('objFrom'=>$objFrom);
742  $action = '';
743  $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
744  if ($reshook < 0) {
745  $this->setErrorsFromObject($hookmanager);
746  $error++;
747  }
748  }
749 
750  // Call trigger
751  $result = $this->call_trigger('ACTION_CLONE', $fuser);
752  if ($result < 0) {
753  $error++;
754  }
755  // End call triggers
756  }
757 
758  unset($this->context['createfromclone']);
759 
760  // End
761  if (!$error) {
762  $this->db->commit();
763  return $this->id;
764  } else {
765  $this->db->rollback();
766  return -1;
767  }
768  }
769 
780  public function fetch($id, $ref = '', $ref_ext = '', $email_msgid = '', $loadresources = 1)
781  {
782  global $langs;
783 
784  if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) {
785  dol_syslog(get_class($this)."::fetch Bad parameters", LOG_WARNING);
786  return -1;
787  }
788 
789  $sql = "SELECT a.id,";
790  $sql .= " a.ref as ref,";
791  $sql .= " a.entity,";
792  $sql .= " a.ref_ext,";
793  $sql .= " a.datep,";
794  $sql .= " a.datep2,";
795  $sql .= " a.durationp,"; // deprecated
796  $sql .= " a.datec,";
797  $sql .= " a.tms as datem,";
798  $sql .= " a.code, a.label, a.note as note_private,";
799  $sql .= " a.fk_soc,";
800  $sql .= " a.fk_project,";
801  $sql .= " a.fk_user_author, a.fk_user_mod,";
802  $sql .= " a.fk_user_action, a.fk_user_done,";
803  $sql .= " a.fk_contact, a.percent as percentage,";
804  $sql .= " a.fk_element as elementid, a.elementtype,";
805  $sql .= " a.priority, a.fulldayevent, a.location, a.transparency,";
806  $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,";
807  $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,";
808  $sql .= " s.nom as socname,";
809  $sql .= " u.firstname, u.lastname as lastname,";
810  $sql .= " num_vote, event_paid, a.status";
811  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a ";
812  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action=c.id ";
813  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author";
814  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc";
815  $sql .= " WHERE ";
816  if ($ref) {
817  $sql .= " a.ref = '".$this->db->escape($ref)."'";
818  } elseif ($ref_ext) {
819  $sql .= " a.ref_ext = '".$this->db->escape($ref_ext)."'";
820  } elseif ($email_msgid) {
821  $sql .= " a.email_msgid = '".$this->db->escape($email_msgid)."'";
822  } else {
823  $sql .= " a.id = ".((int) $id);
824  }
825 
826  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
827  $resql = $this->db->query($sql);
828  if ($resql) {
829  $num = $this->db->num_rows($resql);
830  if ($num) {
831  $obj = $this->db->fetch_object($resql);
832 
833  $this->id = $obj->id;
834  $this->entity = $obj->entity;
835  $this->ref = $obj->ref;
836  $this->ref_ext = $obj->ref_ext;
837 
838  // Properties of parent table llx_c_actioncomm
839  $this->type_id = $obj->type_id;
840  $this->type_code = $obj->type_code;
841  $this->type_color = $obj->type_color;
842  $this->type_picto = $obj->type_picto;
843  $this->type = $obj->type_type;
844  /*$transcode = $langs->trans("Action".$obj->type_code);
845  $this->type = (($transcode != "Action".$obj->type_code) ? $transcode : $obj->type_label); */
846  $transcode = $langs->trans("Action".$obj->type_code.'Short');
847  $this->type_short = (($transcode != "Action".$obj->type_code.'Short') ? $transcode : '');
848 
849  $this->code = $obj->code;
850  $this->label = $obj->label;
851  $this->datep = $this->db->jdate($obj->datep);
852  $this->datef = $this->db->jdate($obj->datep2);
853 
854  $this->datec = $this->db->jdate($obj->datec);
855  $this->datem = $this->db->jdate($obj->datem);
856 
857  $this->note = $obj->note_private; // deprecated
858  $this->note_private = $obj->note_private;
859  $this->percentage = $obj->percentage;
860 
861  $this->authorid = $obj->fk_user_author;
862  $this->usermodid = $obj->fk_user_mod;
863 
864  if (!is_object($this->author)) {
865  $this->author = new User($this->db); // To avoid warning
866  }
867  $this->author->id = $obj->fk_user_author; // deprecated
868  $this->author->firstname = $obj->firstname; // deprecated
869  $this->author->lastname = $obj->lastname; // deprecated
870  if (!is_object($this->usermod)) {
871  $this->usermod = new User($this->db); // To avoid warning
872  }
873  $this->usermod->id = $obj->fk_user_mod; // deprecated
874 
875  $this->userownerid = $obj->fk_user_action;
876  $this->priority = $obj->priority;
877  $this->fulldayevent = $obj->fulldayevent;
878  $this->location = $obj->location;
879  $this->transparency = $obj->transparency;
880 
881  $this->socid = $obj->fk_soc; // To have fetch_thirdparty method working
882  $this->contact_id = $obj->fk_contact; // To have fetch_contact method working
883  $this->fk_project = $obj->fk_project; // To have fetch_projet method working
884 
885  //$this->societe->id = $obj->fk_soc; // deprecated
886  //$this->contact->id = $obj->fk_contact; // deprecated
887 
888  $this->fk_element = $obj->elementid;
889  $this->elementid = $obj->elementid;
890  $this->elementtype = $obj->elementtype;
891 
892  $this->num_vote = $obj->num_vote;
893  $this->event_paid = $obj->event_paid;
894  $this->status = $obj->status;
895 
896  //email information
897  $this->email_msgid=$obj->email_msgid;
898  $this->email_from=$obj->email_from;
899  $this->email_sender=$obj->email_sender;
900  $this->email_to=$obj->email_to;
901  $this->email_tocc=$obj->email_tocc;
902  $this->email_tobcc=$obj->email_tobcc;
903  $this->email_subject=$obj->email_subject;
904  $this->errors_to=$obj->errors_to;
905 
906  $this->fetch_optionals();
907 
908  if ($loadresources) {
909  $this->fetchResources();
910  }
911  }
912 
913  $this->db->free($resql);
914  } else {
915  $this->error = $this->db->lasterror();
916  return -1;
917  }
918 
919  return $num;
920  }
921 
927  public function fetchResources()
928  {
929  $this->userassigned = array();
930  $this->socpeopleassigned = array();
931 
932  $sql = 'SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency';
933  $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm_resources';
934  $sql .= ' WHERE fk_actioncomm = '.((int) $this->id);
935  $sql .= " AND element_type IN ('user', 'socpeople')";
936  $resql = $this->db->query($sql);
937  if ($resql) {
938  // If owner is known, we must but id first into list
939  if ($this->userownerid > 0) {
940  $this->userassigned[$this->userownerid] = array('id'=>$this->userownerid); // Set first so will be first into list.
941  }
942 
943  while ($obj = $this->db->fetch_object($resql)) {
944  if ($obj->fk_element > 0) {
945  switch ($obj->element_type) {
946  case 'user':
947  $this->userassigned[$obj->fk_element] = array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency);
948  if (empty($this->userownerid)) {
949  $this->userownerid = $obj->fk_element; // If not defined (should not happened, we fix this)
950  }
951  break;
952  case 'socpeople':
953  $this->socpeopleassigned[$obj->fk_element] = array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency);
954  break;
955  }
956  }
957  }
958 
959  return 1;
960  } else {
961  dol_print_error($this->db);
962  return -1;
963  }
964  }
965 
966  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
973  public function fetch_userassigned($override = true)
974  {
975  // phpcs:enable
976  $sql = "SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency";
977  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm_resources";
978  $sql .= " WHERE element_type = 'user' AND fk_actioncomm = ".((int) $this->id);
979 
980  $resql2 = $this->db->query($sql);
981  if ($resql2) {
982  $this->userassigned = array();
983 
984  // If owner is known, we must but id first into list
985  if ($this->userownerid > 0) {
986  // Set first so will be first into list.
987  $this->userassigned[$this->userownerid] = array('id'=>$this->userownerid);
988  }
989 
990  while ($obj = $this->db->fetch_object($resql2)) {
991  if ($obj->fk_element > 0) {
992  $this->userassigned[$obj->fk_element] = array('id'=>$obj->fk_element,
993  'mandatory'=>$obj->mandatory,
994  'answer_status'=>$obj->answer_status,
995  'transparency'=>$obj->transparency);
996  }
997 
998  if ($override === true) {
999  // If not defined (should not happened, we fix this)
1000  if (empty($this->userownerid)) {
1001  $this->userownerid = $obj->fk_element;
1002  }
1003  }
1004  }
1005 
1006  return 1;
1007  } else {
1008  dol_print_error($this->db);
1009  return -1;
1010  }
1011  }
1012 
1019  public function delete($notrigger = 0)
1020  {
1021  global $user;
1022 
1023  $error = 0;
1024 
1025  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1026 
1027  $this->db->begin();
1028 
1029  // remove categorie association
1030  if (!$error) {
1031  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_actioncomm";
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  // remove actioncomm_resources
1042  if (!$error) {
1043  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources";
1044  $sql .= " WHERE fk_actioncomm=".((int) $this->id);
1045 
1046  $res = $this->db->query($sql);
1047  if (!$res) {
1048  $this->error = $this->db->lasterror();
1049  $error++;
1050  }
1051  }
1052 
1053  if (!$error) {
1054  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
1055  $sql .= " WHERE fk_actioncomm = ".((int) $this->id);
1056 
1057  $res = $this->db->query($sql);
1058  if (!$res) {
1059  $this->error = $this->db->lasterror();
1060  $error++;
1061  }
1062  }
1063 
1064  // Removed extrafields
1065  if (!$error) {
1066  $result = $this->deleteExtraFields();
1067  if ($result < 0) {
1068  $error++;
1069  dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
1070  }
1071  }
1072 
1073  // remove actioncomm
1074  if (!$error) {
1075  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm";
1076  $sql .= " WHERE id=".((int) $this->id);
1077 
1078  $res = $this->db->query($sql);
1079  if (!$res) {
1080  $this->error = $this->db->lasterror();
1081  $error++;
1082  }
1083  }
1084 
1085  if (!$error) {
1086  if (!$notrigger) {
1087  // Call trigger
1088  $result = $this->call_trigger('ACTION_DELETE', $user);
1089  if ($result < 0) {
1090  $error++;
1091  }
1092  // End call triggers
1093  }
1094 
1095  if (!$error) {
1096  $this->db->commit();
1097  return 1;
1098  } else {
1099  $this->db->rollback();
1100  return -2;
1101  }
1102  } else {
1103  $this->db->rollback();
1104  $this->error = $this->db->lasterror();
1105  return -1;
1106  }
1107  }
1108 
1117  public function update(User $user, $notrigger = 0)
1118  {
1119  global $langs, $conf, $hookmanager;
1120 
1121  $error = 0;
1122 
1123  // Clean parameters
1124  $this->label = trim($this->label);
1125  $this->note_private = dol_htmlcleanlastbr(trim(!isset($this->note_private) ? $this->note : $this->note_private));
1126  if (empty($this->percentage)) {
1127  $this->percentage = 0;
1128  }
1129  if (empty($this->priority) || !is_numeric($this->priority)) {
1130  $this->priority = 0;
1131  }
1132  if (empty($this->transparency)) {
1133  $this->transparency = 0;
1134  }
1135  if (empty($this->fulldayevent)) {
1136  $this->fulldayevent = 0;
1137  }
1138  if ($this->percentage > 100) {
1139  $this->percentage = 100;
1140  }
1141  //if ($this->percentage == 100 && ! $this->dateend) $this->dateend = $this->date;
1142  if ($this->datep && $this->datef) {
1143  $this->durationp = ($this->datef - $this->datep); // deprecated
1144  }
1145  //if ($this->date && $this->dateend) $this->durationa=($this->dateend - $this->date);
1146  if ($this->datep && $this->datef && $this->datep > $this->datef) {
1147  $this->datef = $this->datep;
1148  }
1149  //if ($this->date && $this->dateend && $this->date > $this->dateend) $this->dateend=$this->date;
1150  if ($this->fk_project < 0) {
1151  $this->fk_project = 0;
1152  }
1153 
1154  // Check parameters
1155  if ($this->percentage == 0 && $this->userdoneid > 0) {
1156  $this->error = "ErrorCantSaveADoneUserWithZeroPercentage";
1157  return -1;
1158  }
1159 
1160  $socid = (($this->socid > 0) ? $this->socid : 0);
1161  $contactid = (($this->contact_id > 0) ? $this->contact_id : 0);
1162  $userownerid = ($this->userownerid ? $this->userownerid : 0);
1163  $userdoneid = ($this->userdoneid ? $this->userdoneid : 0);
1164 
1165  // If a type_id is set, we must also have the type_code set
1166  if ($this->type_id > 0) {
1167  if (empty($this->type_code)) {
1168  $cactioncomm = new CActionComm($this->db);
1169  $result = $cactioncomm->fetch($this->type_id);
1170  if ($result >= 0 && !empty($cactioncomm->code)) {
1171  $this->type_code = $cactioncomm->code;
1172  }
1173  }
1174  }
1175 
1176  $code = $this->code;
1177  if (empty($code) || (!empty($this->oldcopy) && $this->oldcopy->type_code != $this->type_code)) { // If code unknown or if we change the type, we reset $code too
1178  $code = $this->type_code;
1179  }
1180 
1181  $this->db->begin();
1182 
1183  $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm";
1184  $sql .= " SET percent = '".$this->db->escape($this->percentage)."'";
1185  $sql .= ", fk_action = ".(int) $this->type_id;
1186  $sql .= ", code = " . ($code ? "'".$this->db->escape($code)."'" : "null");
1187  $sql .= ", label = ".($this->label ? "'".$this->db->escape($this->label)."'" : "null");
1188  $sql .= ", datep = ".(strval($this->datep) != '' ? "'".$this->db->idate($this->datep)."'" : 'null');
1189  $sql .= ", datep2 = ".(strval($this->datef) != '' ? "'".$this->db->idate($this->datef)."'" : 'null');
1190  $sql .= ", durationp = ".(isset($this->durationp) && $this->durationp >= 0 && $this->durationp != '' ? "'".$this->db->escape($this->durationp)."'" : "null"); // deprecated
1191  $sql .= ", note = '".$this->db->escape($this->note_private)."'";
1192  $sql .= ", fk_project =".($this->fk_project > 0 ? ((int) $this->fk_project) : "null");
1193  $sql .= ", fk_soc =".($socid > 0 ? ((int) $socid) : "null");
1194  $sql .= ", fk_contact =".($contactid > 0 ? ((int) $contactid) : "null");
1195  $sql .= ", priority = '".$this->db->escape($this->priority)."'";
1196  $sql .= ", fulldayevent = '".$this->db->escape($this->fulldayevent)."'";
1197  $sql .= ", location = ".($this->location ? "'".$this->db->escape($this->location)."'" : "null");
1198  $sql .= ", transparency = '".$this->db->escape($this->transparency)."'";
1199  $sql .= ", fk_user_mod = ".((int) $user->id);
1200  $sql .= ", fk_user_action = ".($userownerid > 0 ? ((int) $userownerid) : "null");
1201  $sql .= ", fk_user_done = ".($userdoneid > 0 ? ((int) $userdoneid) : "null");
1202  if (!empty($this->fk_element)) {
1203  $sql .= ", fk_element=".($this->fk_element ? ((int) $this->fk_element) : "null");
1204  }
1205  if (!empty($this->elementtype)) {
1206  $sql .= ", elementtype=".($this->elementtype ? "'".$this->db->escape($this->elementtype)."'" : "null");
1207  }
1208  if (!empty($this->num_vote)) {
1209  $sql .= ", num_vote=".($this->num_vote ? (int) $this->num_vote : null);
1210  }
1211  if (!empty($this->event_paid)) {
1212  $sql .= ", event_paid=".($this->event_paid ? (int) $this->event_paid : 0);
1213  }
1214  if (!empty($this->status)) {
1215  $sql .= ", status=".($this->status ? (int) $this->status : 0);
1216  }
1217  $sql .= " WHERE id=".((int) $this->id);
1218 
1219  dol_syslog(get_class($this)."::update", LOG_DEBUG);
1220  if ($this->db->query($sql)) {
1221  $action = 'update';
1222 
1223  // Actions on extra fields
1224  if (!$error) {
1225  $result = $this->insertExtraFields();
1226  if ($result < 0) {
1227  $error++;
1228  }
1229  }
1230 
1231  // Now insert assignedusers
1232  if (!$error) {
1233  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources where fk_actioncomm = ".((int) $this->id)." AND element_type = 'user'";
1234  $resql = $this->db->query($sql);
1235 
1236  $already_inserted = array();
1237  foreach ($this->userassigned as $key => $val) {
1238  if (!is_array($val)) { // For backward compatibility when val=id
1239  $val = array('id'=>$val);
1240  }
1241  if (!empty($already_inserted[$val['id']])) continue;
1242 
1243  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1244  $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'])).")";
1245 
1246  $resql = $this->db->query($sql);
1247  if (!$resql) {
1248  $error++;
1249  $this->errors[] = $this->db->lasterror();
1250  } else {
1251  $already_inserted[$val['id']] = true;
1252  }
1253  //var_dump($sql);exit;
1254  }
1255  }
1256 
1257  if (!$error) {
1258  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources where fk_actioncomm = ".((int) $this->id)." AND element_type = 'socpeople'";
1259  $resql = $this->db->query($sql);
1260 
1261  if (!empty($this->socpeopleassigned)) {
1262  $already_inserted = array();
1263  foreach (array_keys($this->socpeopleassigned) as $key => $val) {
1264  if (!is_array($val)) { // For backward compatibility when val=id
1265  $val = array('id'=>$val);
1266  }
1267  if (!empty($already_inserted[$val['id']])) continue;
1268 
1269  $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1270  $sql .= " VALUES(".((int) $this->id).", 'socpeople', ".((int) $val['id']).", 0, 0, 0)";
1271 
1272  $resql = $this->db->query($sql);
1273  if (!$resql) {
1274  $error++;
1275  $this->errors[] = $this->db->lasterror();
1276  } else {
1277  $already_inserted[$val['id']] = true;
1278  }
1279  }
1280  }
1281  }
1282 
1283  if (!$error && !$notrigger) {
1284  // Call trigger
1285  $result = $this->call_trigger('ACTION_MODIFY', $user);
1286  if ($result < 0) {
1287  $error++;
1288  }
1289  // End call triggers
1290  }
1291 
1292  if (!$error) {
1293  $this->db->commit();
1294  return 1;
1295  } else {
1296  $this->db->rollback();
1297  dol_syslog(get_class($this)."::update ".join(',', $this->errors), LOG_ERR);
1298  return -2;
1299  }
1300  } else {
1301  $this->db->rollback();
1302  $this->error = $this->db->lasterror();
1303  return -1;
1304  }
1305  }
1306 
1320  public function getActions($socid = 0, $fk_element = 0, $elementtype = '', $filter = '', $sortfield = 'a.datep', $sortorder = 'DESC', $limit = 0)
1321  {
1322  global $conf, $langs;
1323 
1324  $resarray = array();
1325 
1326  dol_syslog(get_class()."::getActions", LOG_DEBUG);
1327 
1328  require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
1329  $hookmanager = new HookManager($this->db);
1330  // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
1331  $hookmanager->initHooks(array('agendadao'));
1332 
1333  $sql = "SELECT a.id";
1334  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1335  // Fields from hook
1336  $parameters = array('sql' => &$sql, 'socid' => $socid, 'fk_element' => $fk_element, 'elementtype' => $elementtype);
1337  $reshook = $hookmanager->executeHooks('getActionsListFrom', $parameters); // Note that $action and $object may have been modified by hook
1338  if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1339  $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
1340  if (!empty($socid)) {
1341  $sql .= " AND a.fk_soc = ".((int) $socid);
1342  }
1343  if (!empty($elementtype)) {
1344  if ($elementtype == 'project') {
1345  $sql .= ' AND a.fk_project = '.((int) $fk_element);
1346  } elseif ($elementtype == 'contact') {
1347  $sql .= ' AND a.id IN';
1348  $sql .= " (SELECT fk_actioncomm FROM ".MAIN_DB_PREFIX."actioncomm_resources WHERE";
1349  $sql .= " element_type = 'socpeople' AND fk_element = ".((int) $fk_element).')';
1350  } else {
1351  $sql .= " AND a.fk_element = ".((int) $fk_element)." AND a.elementtype = '".$this->db->escape($elementtype)."'";
1352  }
1353  }
1354  if (!empty($filter)) {
1355  $sql .= $filter;
1356  }
1357  // Fields where hook
1358  $parameters = array('sql' => &$sql, 'socid' => $socid, 'fk_element' => $fk_element, 'elementtype' => $elementtype);
1359  $reshook = $hookmanager->executeHooks('getActionsListWhere', $parameters); // Note that $action and $object may have been modified by hook
1360  if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1361  if ($sortorder && $sortfield) {
1362  $sql .= $this->db->order($sortfield, $sortorder);
1363  }
1364  $sql .= $this->db->plimit($limit, 0);
1365 
1366  $resql = $this->db->query($sql);
1367  if ($resql) {
1368  $num = $this->db->num_rows($resql);
1369 
1370  if ($num) {
1371  for ($i = 0; $i < $num; $i++) {
1372  $obj = $this->db->fetch_object($resql);
1373  $actioncommstatic = new ActionComm($this->db);
1374  $actioncommstatic->fetch($obj->id);
1375  $resarray[$i] = $actioncommstatic;
1376  }
1377  }
1378  $this->db->free($resql);
1379  return $resarray;
1380  } else {
1381  return $this->db->lasterror();
1382  }
1383  }
1384 
1385  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1393  public function load_board($user, $load_state_board = 0)
1394  {
1395  // phpcs:enable
1396  global $conf, $langs;
1397 
1398  if (empty($load_state_board)) {
1399  $sql = "SELECT a.id, a.datep as dp";
1400  } else {
1401  $this->nb = array();
1402  $sql = "SELECT count(a.id) as nb";
1403  }
1404  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1405  if (empty($user->rights->societe->client->voir) && !$user->socid) {
1406  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
1407  }
1408  if (empty($user->rights->agenda->allactions->read)) {
1409  $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);
1410  }
1411  $sql .= " WHERE 1 = 1";
1412  if (empty($load_state_board)) {
1413  $sql .= " AND a.percent >= 0 AND a.percent < 100";
1414  }
1415  $sql .= " AND a.entity IN (".getEntity('agenda').")";
1416  if (empty($user->rights->societe->client->voir) && !$user->socid) {
1417  $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
1418  }
1419  if ($user->socid) {
1420  $sql .= " AND a.fk_soc = ".((int) $user->socid);
1421  }
1422  if (empty($user->rights->agenda->allactions->read)) {
1423  $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);
1424  $sql .= " OR ar.fk_element = ".((int) $user->id);
1425  $sql .= ")";
1426  }
1427 
1428  $resql = $this->db->query($sql);
1429  if ($resql) {
1430  if (empty($load_state_board)) {
1431  $agenda_static = new ActionComm($this->db);
1432  $response = new WorkboardResponse();
1433  $response->warning_delay = $conf->agenda->warning_delay / 60 / 60 / 24;
1434  $response->label = $langs->trans("ActionsToDo");
1435  $response->labelShort = $langs->trans("ActionsToDoShort");
1436  $response->url = DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&actioncode=0&status=todo&mainmenu=agenda';
1437  if ($user->hasRight("agenda", "allactions", "read")) {
1438  $response->url .= '&filtert=-1';
1439  }
1440  $response->img = img_object('', "action", 'class="inline-block valigntextmiddle"');
1441  }
1442  // This assignment in condition is not a bug. It allows walking the results.
1443  while ($obj = $this->db->fetch_object($resql)) {
1444  if (empty($load_state_board)) {
1445  $response->nbtodo++;
1446  $agenda_static->datep = $this->db->jdate($obj->dp);
1447  if ($agenda_static->hasDelay()) {
1448  $response->nbtodolate++;
1449  }
1450  } else {
1451  $this->nb["actionscomm"] = $obj->nb;
1452  }
1453  }
1454 
1455  $this->db->free($resql);
1456  if (empty($load_state_board)) {
1457  return $response;
1458  } else {
1459  return 1;
1460  }
1461  } else {
1462  dol_print_error($this->db);
1463  $this->error = $this->db->error();
1464  return -1;
1465  }
1466  }
1467 
1468 
1475  public function info($id)
1476  {
1477  $sql = 'SELECT ';
1478  $sql .= ' a.id,';
1479  $sql .= ' datec,';
1480  $sql .= ' tms as datem,';
1481  $sql .= ' fk_user_author,';
1482  $sql .= ' fk_user_mod';
1483  $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
1484  $sql .= ' WHERE a.id = '.((int) $id);
1485 
1486  dol_syslog(get_class($this)."::info", LOG_DEBUG);
1487  $result = $this->db->query($sql);
1488  if ($result) {
1489  if ($this->db->num_rows($result)) {
1490  $obj = $this->db->fetch_object($result);
1491  $this->id = $obj->id;
1492  $this->user_creation_id = $obj->fk_user_author;
1493  $this->user_modification_id = $obj->fk_user_mod;
1494  $this->date_creation = $this->db->jdate($obj->datec);
1495  $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1496  }
1497  $this->db->free($result);
1498  } else {
1499  dol_print_error($this->db);
1500  }
1501  }
1502 
1503 
1511  public function getLibStatut($mode, $hidenastatus = 0)
1512  {
1513  return $this->LibStatut($this->percentage, $mode, $hidenastatus, $this->datep);
1514  }
1515 
1516  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1526  public function LibStatut($percent, $mode, $hidenastatus = 0, $datestart = '')
1527  {
1528  // phpcs:enable
1529  global $langs;
1530 
1531  $labelStatus = $langs->transnoentitiesnoconv('StatusNotApplicable');
1532  if ($percent == -1 && !$hidenastatus) {
1533  $labelStatus = $langs->transnoentitiesnoconv('StatusNotApplicable');
1534  } elseif ($percent == 0) {
1535  $labelStatus = $langs->transnoentitiesnoconv('StatusActionToDo').' (0%)';
1536  } elseif ($percent > 0 && $percent < 100) {
1537  $labelStatus = $langs->transnoentitiesnoconv('StatusActionInProcess').' ('.$percent.'%)';
1538  } elseif ($percent >= 100) {
1539  $labelStatus = $langs->transnoentitiesnoconv('StatusActionDone').' (100%)';
1540  }
1541 
1542  $labelStatusShort = $langs->transnoentitiesnoconv('StatusNotApplicable');
1543  if ($percent == -1 && !$hidenastatus) {
1544  $labelStatusShort = $langs->trans('NA');
1545  } elseif ($percent == 0) {
1546  $labelStatusShort = '0%';
1547  } elseif ($percent > 0 && $percent < 100) {
1548  $labelStatusShort = $percent.'%';
1549  } elseif ($percent >= 100) {
1550  $labelStatusShort = '100%';
1551  }
1552 
1553  $statusType = 'status9';
1554  if ($percent == -1 && !$hidenastatus) {
1555  $statusType = 'status9';
1556  }
1557  if ($percent == 0) {
1558  $statusType = 'status1';
1559  }
1560  if ($percent > 0 && $percent < 100) {
1561  $statusType = 'status3';
1562  }
1563  if ($percent >= 100) {
1564  $statusType = 'status6';
1565  }
1566 
1567  return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1568  }
1569 
1576  public function getTooltipContentArray($params)
1577  {
1578  global $conf, $langs, $user;
1579  $langs->load('agenda');
1580 
1581  $datas = array();
1582  $nofetch = !empty($params['nofetch']);
1583 
1584  // Set label of type
1585  $labeltype = '';
1586  if ($this->type_code) {
1587  $labeltype = ($langs->transnoentities("Action".$this->type_code) != "Action".$this->type_code) ? $langs->transnoentities("Action".$this->type_code) : $this->type_label;
1588  }
1589  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1590  if ($this->type_code != 'AC_OTH_AUTO') {
1591  $labeltype = $langs->trans('ActionAC_MANUAL');
1592  }
1593  }
1594 
1595  $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans('Action').'</u>';
1596  if (!empty($this->ref)) {
1597  $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.dol_escape_htmltag($this->ref);
1598  }
1599  if (!empty($this->label)) {
1600  $datas['title'] = '<br><b>'.$langs->trans('Title').':</b> '.dol_escape_htmltag($this->label);
1601  }
1602  if (!empty($labeltype)) {
1603  $datas['labeltype'] = '<br><b>'.$langs->trans('Type').':</b> '.dol_escape_htmltag($labeltype);
1604  }
1605  if (!empty($this->location)) {
1606  $datas['location'] = '<br><b>'.$langs->trans('Location').':</b> '.dol_escape_htmltag($this->location);
1607  }
1608  if (isset($this->transparency)) {
1609  $datas['transparency'] = '<br><b>'.$langs->trans('Busy').':</b> '.yn($this->transparency);
1610  }
1611  if (!empty($this->email_msgid)) {
1612  $langs->load("mails");
1613  $datas['space'] = '<br>';
1614  // $datas['email'] = '<br><b>'.img_picto('', 'email').' '.$langs->trans("Email").'</b>';
1615  $datas['mailtopic'] = '<br><b>'.$langs->trans('MailTopic').':</b> '.dol_escape_htmltag($this->email_subject);
1616  $datas['mailfrom'] = '<br><b>'.$langs->trans('MailFrom').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_from);
1617  $datas['mailto'] = '<br><b>'.$langs->trans('MailTo').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_to);
1618  if (!empty($this->email_tocc)) {
1619  $datas['mailcc'] = '<br><b>'.$langs->trans('MailCC').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_tocc);
1620  }
1621  /* Disabled because bcc must remain by defintion not visible
1622  if (!empty($this->email_tobcc)) {
1623  $datas['mailccc'] = '<br><b>'.$langs->trans('MailCCC').':</b> '.$this->email_tobcc;
1624  } */
1625  }
1626  if (!empty($this->note_private)) {
1627  $datas['description'] = '<br><b>'.$langs->trans('Description').':</b><br>';
1628  // Try to limit length of content
1629  $texttoshow = dolGetFirstLineOfText($this->note_private, 10);
1630  // Restrict height of content into the tooltip
1631  $datas['note'] = '<div class="tenlinesmax">';
1632  $datas['note'] .= (dol_textishtml($texttoshow) ? str_replace(array("\r", "\n"), "", $texttoshow) : str_replace(array("\r", "\n"), '<br>', $texttoshow));
1633  $datas['note'] .= '</div>';
1634  }
1635  // show categories for this record only in ajax to not overload lists
1636  if (isModEnabled('categorie') && !$nofetch) {
1637  require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1638  $form = new Form($this->db);
1639  $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_ACTIONCOMM, 1);
1640  }
1641 
1642  return $datas;
1643  }
1644 
1658  public function getNomUrl($withpicto = 0, $maxlength = 0, $classname = '', $option = '', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
1659  {
1660  global $conf, $langs, $user, $hookmanager, $action;
1661 
1662  if (!empty($conf->dol_no_mouse_hover)) {
1663  $notooltip = 1; // Force disable tooltips
1664  }
1665 
1666  $canread = 0;
1667  if (!empty($user->rights->agenda->myactions->read) && $this->authorid == $user->id) {
1668  $canread = 1; // Can read my event
1669  }
1670  if (!empty($user->rights->agenda->myactions->read) && array_key_exists($user->id, $this->userassigned)) {
1671  $canread = 1; // Can read my event i am assigned
1672  }
1673  if (!empty($user->rights->agenda->allactions->read)) {
1674  $canread = 1; // Can read all event of other
1675  }
1676  if (!$canread) {
1677  $option = 'nolink';
1678  }
1679 
1680  $label = $this->label;
1681  if (empty($label)) {
1682  $label = $this->libelle; // For backward compatibility
1683  }
1684 
1685  $result = '';
1686 
1687  // Set label of type
1688  $labeltype = '';
1689  if ($this->type_code) {
1690  $labeltype = ($langs->transnoentities("Action".$this->type_code) != "Action".$this->type_code) ? $langs->transnoentities("Action".$this->type_code) : $this->type_label;
1691  }
1692  if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1693  if ($this->type_code != 'AC_OTH_AUTO') {
1694  $labeltype = $langs->trans('ActionAC_MANUAL');
1695  }
1696  }
1697 
1698  $tooltip = img_picto('', $this->picto).' <u>'.$langs->trans('Action').'</u>';
1699  if (!empty($this->ref)) {
1700  $tooltip .= '<br><b>'.$langs->trans('Ref').':</b> '.dol_escape_htmltag($this->ref);
1701  }
1702  if (!empty($label)) {
1703  $tooltip .= '<br><b>'.$langs->trans('Title').':</b> '.dol_escape_htmltag($label);
1704  }
1705  if (!empty($labeltype)) {
1706  $tooltip .= '<br><b>'.$langs->trans('Type').':</b> '.dol_escape_htmltag($labeltype);
1707  }
1708  if (!empty($this->location)) {
1709  $tooltip .= '<br><b>'.$langs->trans('Location').':</b> '.dol_escape_htmltag($this->location);
1710  }
1711  if (isset($this->transparency)) {
1712  $tooltip .= '<br><b>'.$langs->trans('Busy').':</b> '.yn($this->transparency);
1713  }
1714  if (!empty($this->email_msgid)) {
1715  $langs->load("mails");
1716  $tooltip .= '<br>';
1717  //$tooltip .= '<br><b>'.img_picto('', 'email').' '.$langs->trans("Email").'</b>';
1718  $tooltip .= '<br><b>'.$langs->trans('MailTopic').':</b> '.dol_escape_htmltag($this->email_subject);
1719  $tooltip .= '<br><b>'.$langs->trans('MailFrom').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_from);
1720  $tooltip .= '<br><b>'.$langs->trans('MailTo').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_to);
1721  if (!empty($this->email_tocc)) {
1722  $tooltip .= '<br><b>'.$langs->trans('MailCC').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_tocc);
1723  }
1724  /* Disabled because bcc must remain by defintion not visible
1725  if (!empty($this->email_tobcc)) {
1726  $tooltip .= '<br><b>'.$langs->trans('MailCCC').':</b> '.$this->email_tobcc;
1727  } */
1728  }
1729  if (!empty($this->note_private)) {
1730  $tooltip .= '<br><br><b>'.$langs->trans('Description').':</b><br>';
1731  $texttoshow = dolGetFirstLineOfText($this->note_private, 10); // Try to limit length of content
1732  $tooltip .= '<div class="tenlinesmax">'; // Restrict height of content into the tooltip
1733  $tooltip .= (dol_textishtml($texttoshow) ? str_replace(array("\r", "\n"), "", $texttoshow) : str_replace(array("\r", "\n"), '<br>', $texttoshow));
1734  $tooltip .= '</div>';
1735  }
1736  $linkclose = '';
1737  $classfortooltip = 'classfortooltip';
1738  $dataparams = '';
1739  if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1740  $params = [
1741  'id' => $this->id,
1742  'objecttype' => $this->element,
1743  'option' => $option,
1744  'nofetch' => 1,
1745  ];
1746  $classfortooltip = 'classforajaxtooltip';
1747  $dataparams = ' data-params='.json_encode($params);
1748  // $label = $langs->trans('Loading');
1749  }
1750  //if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && $this->type_color)
1751  // $linkclose = ' style="background-color:#'.$this->type_color.'"';
1752 
1753  if (empty($notooltip)) {
1754  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1755  $label = $langs->trans("ShowAction");
1756  $linkclose .= ' alt="'.dol_escape_htmltag($tooltip, 1).'"';
1757  }
1758  $linkclose .= ' title="'.dol_escape_htmltag($tooltip, 1, 0, '', 1).'"';
1759  $linkclose .= $dataparams.' class="'.$classname.' '.$classfortooltip.'"';
1760  } else {
1761  $linkclose .= ' class="'.$classname.'"';
1762  }
1763 
1764  $url = '';
1765  if ($option == 'birthday') {
1766  $url = DOL_URL_ROOT.'/contact/perso.php?id='.$this->id;
1767  } elseif ($option == 'holiday') {
1768  $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
1769  } else {
1770  $url = DOL_URL_ROOT.'/comm/action/card.php?id='.$this->id;
1771  }
1772 
1773  if ($option !== 'nolink') {
1774  // Add param to save lastsearch_values or not
1775  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1776  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1777  $add_save_lastsearch_values = 1;
1778  }
1779  if ($add_save_lastsearch_values) {
1780  $url .= '&save_lastsearch_values=1';
1781  }
1782  }
1783 
1784  $linkstart = '<a href="'.$url.'"';
1785  $linkstart .= $linkclose.'>';
1786  $linkend = '</a>';
1787 
1788  if ($option == 'nolink') {
1789  $linkstart = '';
1790  $linkend = '';
1791  }
1792 
1793  if ($withpicto == 2) {
1794  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1795  $label = $labeltype;
1796  }
1797  $labelshort = '';
1798  } else {
1799  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($label)) {
1800  $label = $labeltype;
1801  }
1802  if ($maxlength < 0) {
1803  $labelshort = $this->ref;
1804  } else {
1805  $labelshort = dol_trunc($label, $maxlength);
1806  }
1807  }
1808 
1809  if ($withpicto) {
1810  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) { // Add code into ()
1811  if ($labeltype) {
1812  $label .= (preg_match('/'.preg_quote($labeltype, '/').'/', $label) ? '' : ' ('.$langs->transnoentities("Action".$this->type_code).')');
1813  }
1814  }
1815  }
1816 
1817  $result .= $linkstart;
1818  if ($withpicto) {
1819  $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 ' : '').'"' : $dataparams.' class="'.(($withpicto != 2) ? 'paddingright ' : '').$classfortooltip.'"'), 0, 0, $notooltip ? 0 : 1);
1820  }
1821  $result .= dol_escape_htmltag($labelshort);
1822  $result .= $linkend;
1823 
1824  global $action;
1825  $hookmanager->initHooks(array('actiondao'));
1826  $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1827  $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1828  if ($reshook > 0) {
1829  $result = $hookmanager->resPrint;
1830  } else {
1831  $result .= $hookmanager->resPrint;
1832  }
1833 
1834  return $result;
1835  }
1836 
1842  public function getTypePicto()
1843  {
1844  global $conf;
1845 
1846  $imgpicto = '';
1847  if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1848  $color = '';
1849  if ($this->type_color) {
1850  $color = 'style="color: #'.$this->type_color.' !important;"';
1851  }
1852  if ($this->type_picto) {
1853  $imgpicto = img_picto('', $this->type_picto, 'class="paddingright"');
1854  } else {
1855  if ($this->type_code == 'AC_RDV') {
1856  $imgpicto = img_picto('', 'meeting', $color, false, 0, 0, '', 'paddingright');
1857  } elseif ($this->type_code == 'AC_TEL') {
1858  $imgpicto = img_picto('', 'object_phoning', $color, false, 0, 0, '', 'paddingright');
1859  } elseif ($this->type_code == 'AC_FAX') {
1860  $imgpicto = img_picto('', 'object_phoning_fax', $color, false, 0, 0, '', 'paddingright');
1861  } elseif ($this->type_code == 'AC_EMAIL' || $this->type_code == 'AC_EMAIL_IN' || preg_match('/_SENTBYMAIL/', $this->code)) {
1862  $imgpicto = img_picto('', 'object_email', $color, false, 0, 0, '', 'paddingright');
1863  } elseif ($this->type_code == 'AC_INT') {
1864  $imgpicto = img_picto('', 'object_intervention', $color, false, 0, 0, '', 'paddingright');
1865  } elseif (preg_match('/^TICKET_MSG/', $this->code)) {
1866  $imgpicto = img_picto('', 'object_conversation', $color, false, 0, 0, '', 'paddingright');
1867  } elseif ($this->type != 'systemauto') {
1868  $imgpicto = img_picto('', 'user-cog', $color, false, 0, 0, '', 'paddingright');
1869  } else {
1870  $imgpicto = img_picto('', 'cog', $color, false, 0, 0, '', 'paddingright');
1871  }
1872  }
1873  } else {
1874  // 2 picto: 1 for auto, 1 for manual
1875  if ($this->type != 'systemauto') {
1876  $imgpicto = img_picto('', 'user-cog', '', false, 0, 0, '', 'paddingright');
1877  } else {
1878  $imgpicto = img_picto('', 'cog', '', false, 0, 0, '', 'paddingright');
1879  }
1880  }
1881  return $imgpicto;
1882  }
1883 
1884 
1895  public function setCategories($categories)
1896  {
1897  // Handle single category
1898  if (!is_array($categories)) {
1899  $categories = array($categories);
1900  }
1901 
1902  // Get current categories
1903  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1904  $c = new Categorie($this->db);
1905  $existing = $c->containing($this->id, Categorie::TYPE_ACTIONCOMM, 'id');
1906 
1907  // Diff
1908  if (is_array($existing)) {
1909  $to_del = array_diff($existing, $categories);
1910  $to_add = array_diff($categories, $existing);
1911  } else {
1912  $to_del = array(); // Nothing to delete
1913  $to_add = $categories;
1914  }
1915 
1916  // Process
1917  foreach ($to_del as $del) {
1918  if ($c->fetch($del) > 0) {
1919  $c->del_type($this, Categorie::TYPE_ACTIONCOMM);
1920  }
1921  }
1922  foreach ($to_add as $add) {
1923  if ($c->fetch($add) > 0) {
1924  $c->add_type($this, Categorie::TYPE_ACTIONCOMM);
1925  }
1926  }
1927  return 1;
1928  }
1929 
1930  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1942  public function build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday = 0)
1943  {
1944  global $hookmanager;
1945 
1946  // phpcs:enable
1947  global $conf, $langs, $dolibarr_main_url_root, $mysoc;
1948 
1949  require_once DOL_DOCUMENT_ROOT."/core/lib/xcal.lib.php";
1950  require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
1951  require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
1952 
1953  dol_syslog(get_class($this)."::build_exportfile Build export file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".count($filters), LOG_DEBUG);
1954 
1955  // Check parameters
1956  if (empty($format)) {
1957  return -1;
1958  }
1959 
1960  // Clean parameters
1961  if (!$filename) {
1962  $extension = 'vcs';
1963  if ($format == 'ical') {
1964  $extension = 'ics';
1965  }
1966  $filename = $format.'.'.$extension;
1967  }
1968 
1969  // Create dir and define output file (definitive and temporary)
1970  $result = dol_mkdir($conf->agenda->dir_temp);
1971  $outputfile = $conf->agenda->dir_temp.'/'.$filename;
1972 
1973  $result = 0;
1974 
1975  $buildfile = true;
1976  $login = ''; $logina = ''; $logind = ''; $logint = '';
1977 
1978  $now = dol_now();
1979 
1980  if ($cachedelay) {
1981  $nowgmt = dol_now();
1982  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1983  if (dol_filemtime($outputfile) > ($nowgmt - $cachedelay)) {
1984  dol_syslog(get_class($this)."::build_exportfile file ".$outputfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay."). Build is canceled");
1985  $buildfile = false;
1986  }
1987  }
1988 
1989  if ($buildfile) {
1990  // Build event array
1991  $eventarray = array();
1992 
1993  $sql = "SELECT a.id,";
1994  $sql .= " a.datep,"; // Start
1995  $sql .= " a.datep2,"; // End
1996  $sql .= " a.durationp,"; // deprecated
1997  $sql .= " a.datec, a.tms as datem,";
1998  $sql .= " a.label, a.code, a.note as note_private, a.fk_action as type_id,";
1999  $sql .= " a.fk_soc,";
2000  $sql .= " a.fk_user_author, a.fk_user_mod,";
2001  $sql .= " a.fk_user_action,";
2002  $sql .= " a.fk_contact, a.percent as percentage,";
2003  $sql .= " a.fk_element, a.elementtype,";
2004  $sql .= " a.priority, a.fulldayevent, a.location, a.transparency,";
2005  $sql .= " u.firstname, u.lastname, u.email,";
2006  $sql .= " s.nom as socname,";
2007  $sql .= " c.id as type_id, c.code as type_code, c.libelle as type_label,";
2008  $sql .= " num_vote, event_paid, a.status";
2009  $sql .= " FROM (".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."actioncomm as a)";
2010  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author"; // Link to get author of event for export
2011  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc";
2012 
2013  $parameters = array('filters' => $filters);
2014  $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters); // Note that $action and $object may have been modified by hook
2015  $sql .= $hookmanager->resPrint;
2016 
2017  // We must filter on assignement table
2018  if ($filters['logint']) {
2019  $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
2020  }
2021  $sql .= " WHERE a.fk_action=c.id";
2022  $sql .= " AND a.entity IN (".getEntity('agenda').")";
2023  foreach ($filters as $key => $value) {
2024  if ($key == 'notolderthan' && $value != '') {
2025  $sql .= " AND a.datep >= '".$this->db->idate($now - ($value * 24 * 60 * 60))."'";
2026  }
2027  if ($key == 'year') {
2028  $sql .= " AND a.datep BETWEEN '".$this->db->idate(dol_get_first_day($value, 1))."' AND '".$this->db->idate(dol_get_last_day($value, 12))."'";
2029  }
2030  if ($key == 'id') {
2031  $sql .= " AND a.id=".(is_numeric($value) ? $value : 0);
2032  }
2033  if ($key == 'idfrom') {
2034  $sql .= " AND a.id >= ".(is_numeric($value) ? $value : 0);
2035  }
2036  if ($key == 'idto') {
2037  $sql .= " AND a.id <= ".(is_numeric($value) ? $value : 0);
2038  }
2039  if ($key == 'project') {
2040  $sql .= " AND a.fk_project=".(is_numeric($value) ? $value : 0);
2041  }
2042  if ($key == 'actiontype') {
2043  $sql .= " AND c.type = '".$this->db->escape($value)."'";
2044  }
2045  if ($key == 'notactiontype') {
2046  $sql .= " AND c.type <> '".$this->db->escape($value)."'";
2047  }
2048  // We must filter on assignement table
2049  if ($key == 'logint') {
2050  $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
2051  }
2052  if ($key == 'logina') {
2053  $logina = $value;
2054  $condition = '=';
2055  if (preg_match('/^!/', $logina)) {
2056  $logina = preg_replace('/^!/', '', $logina);
2057  $condition = '<>';
2058  }
2059  $userforfilter = new User($this->db);
2060  $result = $userforfilter->fetch('', $logina);
2061  if ($result > 0) {
2062  $sql .= " AND a.fk_user_author ".$condition." ".$userforfilter->id;
2063  } elseif ($result < 0 || $condition == '=') {
2064  $sql .= " AND a.fk_user_author = 0";
2065  }
2066  }
2067  if ($key == 'logint') {
2068  $logint = $value;
2069  $condition = '=';
2070  if (preg_match('/^!/', $logint)) {
2071  $logint = preg_replace('/^!/', '', $logint);
2072  $condition = '<>';
2073  }
2074  $userforfilter = new User($this->db);
2075  $result = $userforfilter->fetch('', $logint);
2076  if ($result > 0) {
2077  $sql .= " AND ar.fk_element = ".((int) $userforfilter->id);
2078  } elseif ($result < 0 || $condition == '=') {
2079  $sql .= " AND ar.fk_element = 0";
2080  }
2081  }
2082  if ($key == 'module') {
2083  $sql .= " AND c.module LIKE '%".$this->db->escape($value)."'";
2084  }
2085  if ($key == 'status') {
2086  $sql .= " AND a.status =".((int) $value);
2087  }
2088  }
2089 
2090  $sql .= " AND a.datep IS NOT NULL"; // To exclude corrupted events and avoid errors in lightning/sunbird import
2091 
2092  $parameters = array('filters' => $filters);
2093  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
2094  $sql .= $hookmanager->resPrint;
2095 
2096  $sql .= " ORDER by datep";
2097  //print $sql;exit;
2098 
2099  dol_syslog(get_class($this)."::build_exportfile select events", LOG_DEBUG);
2100  $resql = $this->db->query($sql);
2101  if ($resql) {
2102  // Note: Output of sql request is encoded in $conf->file->character_set_client
2103  // This assignment in condition is not a bug. It allows walking the results.
2104  $diff = 0;
2105  while ($obj = $this->db->fetch_object($resql)) {
2106  $qualified = true;
2107 
2108  // 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
2109  $event = array();
2110  $event['uid'] = 'dolibarragenda-'.$this->db->database_name.'-'.$obj->id."@".$_SERVER["SERVER_NAME"];
2111  $event['type'] = $type;
2112 
2113  $datestart = $this->db->jdate($obj->datep) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2114 
2115  // fix for -> Warning: A non-numeric value encountered
2116  if (is_numeric($this->db->jdate($obj->datep2))) {
2117  $dateend = $this->db->jdate($obj->datep2) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2118  } else {
2119  // use start date as fall-back to avoid pb with empty end date on ICS readers
2120  $dateend = $datestart;
2121  }
2122 
2123  $duration = ($datestart && $dateend) ? ($dateend - $datestart) : 0;
2124  $event['summary'] = $obj->label.($obj->socname ? " (".$obj->socname.")" : "");
2125 
2126  $event['desc'] = $obj->note_private;
2127  $event['startdate'] = $datestart;
2128  $event['enddate'] = $dateend; // Not required with type 'journal'
2129  $event['duration'] = $duration; // Not required with type 'journal'
2130  $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname);
2131  $event['priority'] = $obj->priority;
2132  $event['fulldayevent'] = $obj->fulldayevent;
2133  $event['location'] = $obj->location;
2134  $event['transparency'] = (($obj->transparency > 0) ? 'OPAQUE' : 'TRANSPARENT'); // OPAQUE (busy) or TRANSPARENT (not busy)
2135  $event['category'] = $obj->type_label;
2136  $event['email'] = $obj->email;
2137  // Define $urlwithroot
2138  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
2139  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
2140  //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2141  $url = $urlwithroot.'/comm/action/card.php?id='.$obj->id;
2142  $event['url'] = $url;
2143  $event['created'] = $this->db->jdate($obj->datec) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2144  $event['modified'] = $this->db->jdate($obj->datem) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2145  $event['num_vote'] = $this->num_vote;
2146  $event['event_paid'] = $this->event_paid;
2147  $event['status'] = $this->status;
2148 
2149  // TODO: find a way to call "$this->fetch_userassigned();" without override "$this" properties
2150  $this->id = $obj->id;
2151  $this->fetch_userassigned(false);
2152 
2153  $assignedUserArray = array();
2154 
2155  foreach ($this->userassigned as $key => $value) {
2156  $assignedUser = new User($this->db);
2157  $assignedUser->fetch($value['id']);
2158 
2159  $assignedUserArray[$key] = $assignedUser;
2160  }
2161 
2162  $event['assignedUsers'] = $assignedUserArray;
2163 
2164  if ($qualified && $datestart) {
2165  $eventarray[] = $event;
2166  }
2167  $diff++;
2168  }
2169 
2170  $parameters = array('filters' => $filters, 'eventarray' => &$eventarray);
2171  $reshook = $hookmanager->executeHooks('addMoreEventsExport', $parameters); // Note that $action and $object may have been modified by hook
2172  if ($reshook > 0) {
2173  $eventarray = $hookmanager->resArray;
2174  }
2175  } else {
2176  $this->error = $this->db->lasterror();
2177  return -1;
2178  }
2179 
2180  if ($exportholiday == 1) {
2181  $langs->load("holiday");
2182  $title = $langs->trans("Holidays");
2183 
2184  $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";
2185  $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
2186  $sql .= " WHERE u.rowid = x.fk_user";
2187  $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
2188  $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
2189 
2190  $resql = $this->db->query($sql);
2191  if ($resql) {
2192  $num = $this->db->num_rows($resql);
2193  $i = 0;
2194 
2195  while ($i < $num) {
2196  $obj = $this->db->fetch_object($resql);
2197  $event = array();
2198 
2199  if ($obj->halfday == -1) {
2200  $event['fulldayevent'] = false;
2201 
2202  $timestampStart = dol_stringtotime($obj->date_start." 00:00:00", 0);
2203  $timestampEnd = dol_stringtotime($obj->date_end." 12:00:00", 0);
2204  } elseif ($obj->halfday == 1) {
2205  $event['fulldayevent'] = false;
2206 
2207  $timestampStart = dol_stringtotime($obj->date_start." 12:00:00", 0);
2208  $timestampEnd = dol_stringtotime($obj->date_end." 23:59:59", 0);
2209  } else {
2210  $event['fulldayevent'] = true;
2211 
2212  $timestampStart = dol_stringtotime($obj->date_start." 00:00:00", 0);
2213  $timestampEnd = dol_stringtotime($obj->date_end." 23:59:59", 0);
2214  }
2215 
2216  if (!empty($conf->global->AGENDA_EXPORT_FIX_TZ)) {
2217  $timestampStart = $timestampStart - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2218  $timestampEnd = $timestampEnd - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2219  }
2220 
2221  $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
2222  $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2223  $url = $urlwithroot.'/holiday/card.php?id='.$obj->rowid;
2224 
2225  $event['uid'] = 'dolibarrholiday-'.$this->db->database_name.'-'.$obj->rowid."@".$_SERVER["SERVER_NAME"];
2226  $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname);
2227  $event['type'] = 'event';
2228  $event['category'] = "Holiday";
2229  $event['transparency'] = 'OPAQUE';
2230  $event['email'] = $obj->email;
2231  $event['created'] = $timestampStart;
2232  $event['modified'] = $timestampStart;
2233  $event['startdate'] = $timestampStart;
2234  $event['enddate'] = $timestampEnd;
2235  $event['duration'] = $timestampEnd - $timestampStart;
2236  $event['url'] = $url;
2237 
2238  if ($obj->status == 2) {
2239  // 2 = leave wait for approval
2240  $event['summary'] = $title." - ".$obj->lastname." (wait for approval)";
2241  } else {
2242  // 3 = leave approved
2243  $event['summary'] = $title." - ".$obj->lastname;
2244  }
2245 
2246  $eventarray[] = $event;
2247 
2248  $i++;
2249  }
2250  }
2251  }
2252 
2253  $langs->load("agenda");
2254 
2255  // Define title and desc
2256  $more = '';
2257  if ($login) {
2258  $more = $langs->transnoentities("User").' '.$login;
2259  }
2260  if ($logina) {
2261  $more = $langs->transnoentities("ActionsAskedBy").' '.$logina;
2262  }
2263  if ($logint) {
2264  $more = $langs->transnoentities("ActionsToDoBy").' '.$logint;
2265  }
2266  if ($logind) {
2267  $more = $langs->transnoentities("ActionsDoneBy").' '.$logind;
2268  }
2269  if ($more) {
2270  $title = 'Dolibarr actions '.$mysoc->name.' - '.$more;
2271  $desc = $more;
2272  $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
2273  } else {
2274  $title = 'Dolibarr actions '.$mysoc->name;
2275  $desc = $langs->transnoentities('ListOfActions');
2276  $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
2277  }
2278 
2279  // Create temp file
2280  $outputfiletmp = tempnam($conf->agenda->dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
2281  dolChmod($outputfiletmp);
2282 
2283  // Write file
2284  if ($format == 'vcal') {
2285  $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2286  } elseif ($format == 'ical') {
2287  $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2288  } elseif ($format == 'rss') {
2289  $result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
2290  }
2291 
2292  if ($result >= 0) {
2293  if (dol_move($outputfiletmp, $outputfile, 0, 1)) {
2294  $result = 1;
2295  } else {
2296  $this->error = 'Failed to rename '.$outputfiletmp.' into '.$outputfile;
2297  dol_syslog(get_class($this)."::build_exportfile ".$this->error, LOG_ERR);
2298  dol_delete_file($outputfiletmp, 0, 1);
2299  $result = -1;
2300  }
2301  } else {
2302  dol_syslog(get_class($this)."::build_exportfile build_xxxfile function fails to for format=".$format." outputfiletmp=".$outputfile, LOG_ERR);
2303  dol_delete_file($outputfiletmp, 0, 1);
2304  $langs->load("errors");
2305  $this->error = $langs->trans("ErrorFailToCreateFile", $outputfile);
2306  }
2307  }
2308 
2309  return $result;
2310  }
2311 
2319  public function initAsSpecimen()
2320  {
2321  global $user;
2322 
2323  $now = dol_now();
2324 
2325  // Initialise parametres
2326  $this->id = 0;
2327  $this->specimen = 1;
2328 
2329  $this->type_code = 'AC_OTH';
2330  $this->code = 'AC_SPECIMEN_CODE';
2331  $this->label = 'Label of event Specimen';
2332  $this->datec = $now;
2333  $this->datem = $now;
2334  $this->datep = $now;
2335  $this->datef = $now;
2336  $this->fulldayevent = 0;
2337  $this->percentage = 0;
2338  $this->status = 0;
2339  $this->location = 'Location';
2340  $this->transparency = 1; // 1 means opaque
2341  $this->priority = 1;
2342  //$this->note_public = "This is a 'public' note.";
2343  $this->note_private = "This is a 'private' note.";
2344 
2345  $this->userownerid = $user->id;
2346  $this->userassigned[$user->id] = array('id'=>$user->id, 'transparency'=> 1);
2347  return 1;
2348  }
2349 
2358  public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
2359  {
2360  $tables = array(
2361  'actioncomm'
2362  );
2363 
2364  return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
2365  }
2366 
2375  public static function replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
2376  {
2377  $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'actioncomm SET fk_element = ' . ((int) $dest_id) . ' WHERE elementtype="product" AND fk_element = '.((int) $origin_id);
2378  // using $dbs, not $this->db because function is static
2379  if (!$dbs->query($sql)) {
2380  //$this->errors = $dbs->lasterror();
2381  return false;
2382  }
2383 
2384  return true;
2385  }
2386 
2392  public function hasDelay()
2393  {
2394  global $conf;
2395 
2396  $now = dol_now();
2397 
2398  return $this->datep && ($this->datep < ($now - $conf->agenda->warning_delay));
2399  }
2400 
2401 
2410  public function loadReminders($type = '', $fk_user = 0, $onlypast = true)
2411  {
2412  global $conf, $langs, $user;
2413 
2414  $error = 0;
2415 
2416  $this->reminders = array();
2417 
2418  //Select all action comm reminders for event
2419  $sql = "SELECT rowid as id, typeremind, dateremind, status, offsetvalue, offsetunit, fk_user";
2420  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
2421  $sql .= " WHERE fk_actioncomm = ".((int) $this->id);
2422  if ($onlypast) {
2423  $sql .= " AND dateremind <= '".$this->db->idate(dol_now())."'";
2424  }
2425  if ($type) {
2426  $sql .= " AND typeremind ='".$this->db->escape($type)."'";
2427  }
2428  if ($fk_user > 0) {
2429  $sql .= " AND fk_user = ".((int) $fk_user);
2430  }
2431  if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2432  $sql .= " AND typeremind != 'email'";
2433  }
2434  if (empty($conf->global->AGENDA_REMINDER_BROWSER)) {
2435  $sql .= " AND typeremind != 'browser'";
2436  }
2437 
2438  $sql .= $this->db->order("dateremind", "ASC");
2439  $resql = $this->db->query($sql);
2440 
2441  if ($resql) {
2442  while ($obj = $this->db->fetch_object($resql)) {
2443  $tmpactioncommreminder = new ActionCommReminder($this->db);
2444  $tmpactioncommreminder->id = $obj->id;
2445  $tmpactioncommreminder->typeremind = $obj->typeremind;
2446  $tmpactioncommreminder->dateremind = $obj->dateremind;
2447  $tmpactioncommreminder->offsetvalue = $obj->offsetvalue;
2448  $tmpactioncommreminder->offsetunit = $obj->offsetunit;
2449  $tmpactioncommreminder->status = $obj->status;
2450  $tmpactioncommreminder->fk_user = $obj->fk_user;
2451 
2452  $this->reminders[$obj->id] = $tmpactioncommreminder;
2453  }
2454  } else {
2455  $this->error = $this->db->lasterror();
2456  $error++;
2457  }
2458 
2459  return count($this->reminders);
2460  }
2461 
2462 
2469  public function sendEmailsReminder()
2470  {
2471  global $conf, $langs, $user;
2472 
2473  $error = 0;
2474  $this->output = '';
2475  $this->error = '';
2476  $nbMailSend = 0;
2477  $errorsMsg = array();
2478 
2479  if (!isModEnabled('agenda')) { // Should not happen. If module disabled, cron job should not be visible.
2480  $langs->load("agenda");
2481  $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Agenda"));
2482  return 0;
2483  }
2484  if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2485  $langs->load("agenda");
2486  $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Agenda"));
2487  return 0;
2488  }
2489 
2490  $now = dol_now();
2491  $actionCommReminder = new ActionCommReminder($this->db);
2492 
2493  dol_syslog(__METHOD__, LOG_DEBUG);
2494 
2495  $this->db->begin();
2496 
2497  //Select all action comm reminders
2498  $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
2499  $sql .= " WHERE typeremind = 'email' AND status = 0";
2500  $sql .= " AND dateremind <= '".$this->db->idate($now)."'";
2501  $sql .= " AND entity IN (".getEntity('actioncomm').")";
2502  $sql .= $this->db->order("dateremind", "ASC");
2503  $resql = $this->db->query($sql);
2504 
2505  if ($resql) {
2506  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2507  $formmail = new FormMail($this->db);
2508 
2509  while ($obj = $this->db->fetch_object($resql)) {
2510  $res = $actionCommReminder->fetch($obj->id);
2511  if ($res < 0) {
2512  $error++;
2513  $errorsMsg[] = "Failed to load invoice ActionComm Reminder";
2514  }
2515 
2516  if (!$error) {
2517  //Select email template
2518  $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1);
2519 
2520  // Load event
2521  $res = $this->fetch($actionCommReminder->fk_actioncomm);
2522  if ($res > 0) {
2523  // PREPARE EMAIL
2524  $errormesg = '';
2525 
2526  // Make substitution in email content
2527  $substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this);
2528 
2529  complete_substitutions_array($substitutionarray, $langs, $this);
2530 
2531  // Content
2532  $sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
2533 
2534  //Topic
2535  $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->transnoentities('EventReminder'));
2536 
2537  // Recipient
2538  $recipient = new User($this->db);
2539  $res = $recipient->fetch($actionCommReminder->fk_user);
2540  if ($res > 0) {
2541  if (!empty($recipient->email)) {
2542  $to = $recipient->email;
2543  } else {
2544  $errormesg = "Failed to send remind to user id=".$actionCommReminder->fk_user.". No email defined for user.";
2545  $error++;
2546  }
2547  } else {
2548  $errormesg = "Failed to load recipient with user id=".$actionCommReminder->fk_user;
2549  $error++;
2550  }
2551 
2552  // Sender
2553  $from = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
2554  if (empty($from)) {
2555  $errormesg = "Failed to get sender into global setup MAIN_MAIL_EMAIL_FROM";
2556  $error++;
2557  }
2558 
2559  if (!$error) {
2560  // Errors Recipient
2561  $errors_to = getDolGlobalString('MAIN_MAIL_ERRORS_TO');
2562 
2563  // Mail Creation
2564  $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', '');
2565 
2566  // Sending Mail
2567  if ($cMailFile->sendfile()) {
2568  $nbMailSend++;
2569  } else {
2570  $errormesg = $cMailFile->error.' : '.$to;
2571  $error++;
2572  }
2573  }
2574 
2575  if (!$error) {
2576  $actionCommReminder->status = $actionCommReminder::STATUS_DONE;
2577 
2578  $res = $actionCommReminder->update($user);
2579  if ($res < 0) {
2580  $errorsMsg[] = "Failed to update status to done of ActionComm Reminder";
2581  $error++;
2582  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.
2583  }
2584  } else {
2585  $actionCommReminder->status = $actionCommReminder::STATUS_ERROR;
2586  $actionCommReminder->lasterror = dol_trunc($errormesg, 128, 'right', 'UTF-8', 1);
2587 
2588  $res = $actionCommReminder->update($user);
2589  if ($res < 0) {
2590  $errorsMsg[] = "Failed to update status to error of ActionComm Reminder";
2591  $error++;
2592  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.
2593  } else {
2594  $errorsMsg[] = $errormesg;
2595  }
2596  }
2597  } else {
2598  $errorsMsg[] = 'Failed to fetch record actioncomm with ID = '.$actionCommReminder->fk_actioncomm;
2599  $error++;
2600  }
2601  }
2602  }
2603  } else {
2604  $error++;
2605  }
2606 
2607  if (!$error) {
2608  // Delete also very old past events (we do not keep more than 1 month record in past)
2609  $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
2610  $sql .= " WHERE dateremind < '".$this->db->idate($now - (3600 * 24 * 32))."'";
2611  $sql .= " AND status = ".((int) $actionCommReminder::STATUS_DONE);
2612  $resql = $this->db->query($sql);
2613 
2614  if (!$resql) {
2615  $errorsMsg[] = 'Failed to delete old reminders';
2616  //$error++; // If this fails, we must not rollback other SQL requests already done. Never mind.
2617  }
2618  }
2619 
2620  if (!$error) {
2621  $this->output = 'Nb of emails sent : '.$nbMailSend;
2622  $this->db->commit();
2623  return 0;
2624  } else {
2625  $this->db->commit(); // We commit also on error, to have the error message recorded.
2626  $this->error = 'Nb of emails sent : '.$nbMailSend.', '.(!empty($errorsMsg)) ? join(', ', $errorsMsg) : $error;
2627  return $error;
2628  }
2629  }
2630 
2639  public function updatePercent($id, $percent, $usermodid = 0)
2640  {
2641  $this->db->begin();
2642 
2643  $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm ";
2644  $sql .= " SET percent = ".(int) $percent;
2645  if ($usermodid > 0) $sql .= ", fk_user_mod = ".$usermodid;
2646  $sql .= " WHERE id = ".((int) $id);
2647 
2648  if ($this->db->query($sql)) {
2649  $this->db->commit();
2650  return 1;
2651  } else {
2652  $this->db->rollback();
2653  $this->error = $this->db->lasterror();
2654  return -1;
2655  }
2656  }
2657 }
make_substitutions
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Definition: functions.lib.php:8210
db
$conf db
API class for accounts.
Definition: inc.php:41
yn
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Definition: functions.lib.php:6699
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1504
dol_trunc
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
Definition: functions.lib.php:3950
ActionComm
Class to manage agenda events (actions)
Definition: actioncomm.class.php:38
ActionComm\replaceProduct
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
Definition: actioncomm.class.php:2375
ActionComm\getTypePicto
getTypePicto()
Return Picto of type of event.
Definition: actioncomm.class.php:1842
ActionComm\fetch
fetch($id, $ref='', $ref_ext='', $email_msgid='', $loadresources=1)
Load object from database.
Definition: actioncomm.class.php:780
DoliDB
Class to manage Dolibarr database access.
Definition: DoliDB.class.php:30
dol_filemtime
dol_filemtime($pathoffile)
Return time of a file.
Definition: files.lib.php:597
$sql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:745
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4994
CommonObject\setErrorsFromObject
setErrorsFromObject($object)
setErrorsFromObject
Definition: commonobject.class.php:679
ActionComm\__construct
__construct(DoliDB $db)
Constructor.
Definition: actioncomm.class.php:411
CMailFile
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Definition: CMailFile.class.php:40
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
ActionComm\sendEmailsReminder
sendEmailsReminder()
Send reminders by emails CAN BE A CRON TASK.
Definition: actioncomm.class.php:2469
ActionComm\update
update(User $user, $notrigger=0)
Update action into database If percentage = 100, on met a jour date 100%.
Definition: actioncomm.class.php:1117
Categorie
Class to manage categories.
Definition: categorie.class.php:47
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:45
build_rssfile
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter='', $url='', $langcode='')
Build a file from an array of events.
Definition: xcal.lib.php:308
ActionComm\getTooltipContentArray
getTooltipContentArray($params)
getTooltipContentArray
Definition: actioncomm.class.php:1576
ActionComm\$recurid
$recurid
Properties to manage the recurring events.
Definition: actioncomm.class.php:380
WorkboardResponse
Definition: workboardresponse.class.php:24
ActionComm\updatePercent
updatePercent($id, $percent, $usermodid=0)
Udpate the percent value of a event with the given id.
Definition: actioncomm.class.php:2639
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4025
dolChmod
dolChmod($filepath, $newmask='')
Change mod of a file.
Definition: functions.lib.php:6882
dol_delete_file
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:1261
ActionCommReminder
Class for ActionCommReminder.
Definition: actioncommreminder.class.php:31
ActionComm\setCategories
setCategories($categories)
Sets object to supplied categories.
Definition: actioncomm.class.php:1895
CActionComm
Class to manage different types of events.
Definition: cactioncomm.class.php:29
ActionComm\fetch_userassigned
fetch_userassigned($override=true)
Initialize this->userassigned array with list of id of user assigned to event.
Definition: actioncomm.class.php:973
ActionComm\build_exportfile
build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday=0)
Export events from database into a cal file.
Definition: actioncomm.class.php:1942
code
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...
Definition: sync_members_ldap2dolibarr.php:60
ActionComm\EVENT_TODO
const EVENT_TODO
Typical value for a event that is in a todo state.
Definition: actioncomm.class.php:390
ActionComm\replaceThirdparty
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Definition: actioncomm.class.php:2358
CommonObject\insertExtraFields
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Definition: commonobject.class.php:6229
ActionComm\getLibStatut
getLibStatut($mode, $hidenastatus=0)
Return the label of the status.
Definition: actioncomm.class.php:1511
ActionComm\info
info($id)
Charge les informations d'ordre info dans l'objet facture.
Definition: actioncomm.class.php:1475
ActionComm\loadReminders
loadReminders($type='', $fk_user=0, $onlypast=true)
Load event reminder of events.
Definition: actioncomm.class.php:2410
getCommonSubstitutionArray
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
Definition: functions.lib.php:7617
ActionComm\hasDelay
hasDelay()
Is the action delayed?
Definition: actioncomm.class.php:2392
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1639
ActionComm\getNomUrl
getNomUrl($withpicto=0, $maxlength=0, $classname='', $option='', $overwritepicto=0, $notooltip=0, $save_lastsearch_value=-1)
Return URL of event Use $this->id, $this->type_code, $this->label and $this->type_label.
Definition: actioncomm.class.php:1658
dol_get_first_day
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:576
CommonObject\fetch_optionals
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
Definition: commonobject.class.php:6080
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
ActionComm\EVENT_FINISHED
const EVENT_FINISHED
Typical value for a event that is in a finished state.
Definition: actioncomm.class.php:400
dol_htmlcleanlastbr
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
Definition: functions.lib.php:7374
ActionComm\initAsSpecimen
initAsSpecimen()
Initialise an instance with random values.
Definition: actioncomm.class.php:2319
dol_get_last_day
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:595
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:147
dolGetFirstLastname
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
Definition: functions.lib.php:8434
ActionComm\LibStatut
LibStatut($percent, $mode, $hidenastatus=0, $datestart='')
Return label of action status.
Definition: actioncomm.class.php:1526
ActionComm\create
create(User $user, $notrigger=0)
Add an action/event into database.
Definition: actioncomm.class.php:424
ref
$object ref
Definition: info.php:78
User
Class to manage Dolibarr users.
Definition: user.class.php:44
CommonObject\deleteExtraFields
deleteExtraFields()
Delete all extra fields values for the current object.
Definition: commonobject.class.php:6189
ActionComm\createFromClone
createFromClone(User $fuser, $socid)
Load an object from its id and create a new one in database.
Definition: actioncomm.class.php:708
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10767
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
ActionComm\getActions
getActions($socid=0, $fk_element=0, $elementtype='', $filter='', $sortfield='a.datep', $sortorder='DESC', $limit=0)
Load all objects with filters.
Definition: actioncomm.class.php:1320
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4361
build_calfile
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->charset_outp...
Definition: xcal.lib.php:35
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2947
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5864
dol_textishtml
dol_textishtml($msg, $option=0)
Return if a text is a html content.
Definition: functions.lib.php:7523
Database\query
query($query, $usesavepoint=0, $type='auto', $result_mode=0)
Execute a SQL request and return the resultset.
dolGetFirstLineOfText
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
Definition: functions.lib.php:7145
ActionComm\EVENT_IN_PROGRESS
const EVENT_IN_PROGRESS
Typical value for a event that is in a progress state.
Definition: actioncomm.class.php:395
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6811
ActionComm\load_board
load_board($user, $load_state_board=0)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
Definition: actioncomm.class.php:1393
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
ActionComm\fetchResources
fetchResources()
Initialize $this->userassigned & this->socpeopleassigned array with list of id of user and contact as...
Definition: actioncomm.class.php:927
CommonObject\commonReplaceThirdparty
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
Definition: commonobject.class.php:8570
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
dol_stringtotime
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:408
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
complete_substitutions_array
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 "subst...
Definition: functions.lib.php:8333
dol_move
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
Definition: files.lib.php:875