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