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/html.formmail.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
33 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncommreminder.class.php';
44 public $element =
'action';
49 public $table_element =
'actioncomm';
54 public $table_rowid =
'id';
59 public $picto =
'action';
64 public $ismultientitymanaged = 1;
71 public $restrictiononfksoc = 2;
176 public $durationp = -1;
181 public $fulldayevent = 0;
196 public $transparency;
206 public $userassigned = array();
222 public $socpeopleassigned = array();
227 public $otherassigned = array();
232 public $reminders = array();
306 public $actions = array();
321 public $email_sender;
340 public $email_subject;
382 global $langs, $conf, $hookmanager;
388 if (!isset($this->userownerid) || $this->userownerid ===
'')
390 dol_syslog(
"You tried to create an event but mandatory property ownerid was not defined", LOG_WARNING);
391 $this->errors[] =
'ErrorPropertyUserowneridNotDefined';
396 $this->label =
dol_trunc(trim($this->label), 128);
397 $this->location =
dol_trunc(trim($this->location), 128);
398 $this->note_private =
dol_htmlcleanlastbr(trim(empty($this->note_private) ? $this->
note : $this->note_private));
399 if (empty($this->percentage)) $this->percentage = 0;
400 if (empty($this->priority) || !is_numeric($this->priority)) $this->priority = 0;
401 if (empty($this->fulldayevent)) $this->fulldayevent = 0;
402 if (empty($this->transparency)) $this->transparency = 0;
403 if ($this->percentage > 100) $this->percentage = 100;
405 if (!empty($this->datep) && !empty($this->datef)) $this->durationp = ($this->datef - $this->datep);
407 if (!empty($this->datep) && !empty($this->datef) && $this->datep > $this->datef) $this->datef = $this->datep;
409 if (!isset($this->fk_project) || $this->fk_project < 0) $this->fk_project = 0;
411 if ($this->elementtype ==
'facture') $this->elementtype =
'invoice';
412 if ($this->elementtype ==
'commande') $this->elementtype =
'order';
413 if ($this->elementtype ==
'contrat') $this->elementtype =
'contract';
415 if (!is_array($this->userassigned) && !empty($this->userassigned))
417 $tmpid = $this->userassigned;
418 $this->userassigned = array();
419 $this->userassigned[$tmpid] = array(
'id'=>$tmpid,
'transparency'=>$this->transparency);
422 $userownerid = $this->userownerid;
423 $userdoneid = $this->userdoneid;
426 if (empty($this->userassigned) || count($this->userassigned) == 0 || !is_array($this->userassigned))
427 $this->userassigned = array($userownerid=>array(
'id'=>$userownerid,
'transparency'=>$this->transparency));
429 if (!$this->type_id || !$this->type_code)
431 $key = empty($this->type_id) ? $this->type_code : $this->type_id;
435 $result = $cactioncomm->fetch($key);
439 $this->type_id = $cactioncomm->id;
440 $this->type_code = $cactioncomm->code;
441 } elseif ($result == 0)
443 $this->error =
'Failed to get record with id '.$this->type_id.
' code '.$this->type_code.
' from dictionary "type of events"';
446 $this->error = $cactioncomm->error;
450 $code = empty($this->
code) ? $this->type_code : $this->code;
455 $this->error =
"ErrorWrongParameters";
461 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm";
465 $sql .=
"durationp,";
466 $sql .=
"fk_action,";
470 $sql .=
"fk_project,";
472 $sql .=
"fk_contact,";
473 $sql .=
"fk_user_author,";
474 $sql .=
"fk_user_action,";
475 $sql .=
"fk_user_done,";
476 $sql .=
"label,percent,priority,fulldayevent,location,";
477 $sql .=
"transparency,";
478 $sql .=
"fk_element,";
479 $sql .=
"elementtype,";
481 $sql .=
"extraparams,";
483 $sql .=
"email_msgid,";
484 $sql .=
"email_from,";
485 $sql .=
"email_sender,";
487 $sql .=
"email_tocc,";
488 $sql .=
"email_tobcc,";
489 $sql .=
"email_subject,";
491 $sql .=
") VALUES (";
492 $sql .=
"'".$this->db->idate($now).
"', ";
493 $sql .= (strval($this->datep) !=
'' ?
"'".$this->db->idate($this->datep).
"'" :
"null").
", ";
494 $sql .= (strval($this->datef) !=
'' ?
"'".$this->db->idate($this->datef).
"'" :
"null").
", ";
495 $sql .= ((isset($this->durationp) && $this->durationp >= 0 && $this->durationp !=
'') ?
"'".$this->
db->escape($this->durationp).
"'" :
"null").
", ";
496 $sql .= (isset($this->type_id) ? $this->type_id :
"null").
",";
497 $sql .= ($code ? (
"'".$this->db->escape($code).
"'") :
"null").
", ";
498 $sql .= (!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
", ";
499 $sql .= ((isset($this->socid) && $this->socid > 0) ? $this->socid :
"null").
", ";
500 $sql .= ((isset($this->fk_project) && $this->fk_project > 0) ? $this->fk_project :
"null").
", ";
501 $sql .=
" '".$this->db->escape($this->note_private).
"', ";
502 $sql .= ((isset($this->contact_id) && $this->contact_id > 0) ? $this->contact_id :
"null").
", ";
503 $sql .= (isset($user->id) && $user->id > 0 ? $user->id :
"null").
", ";
504 $sql .= ($userownerid > 0 ? $userownerid :
"null").
", ";
505 $sql .= ($userdoneid > 0 ? $userdoneid :
"null").
", ";
506 $sql .=
"'".$this->db->escape($this->label).
"','".$this->
db->escape($this->percentage).
"','".$this->
db->escape($this->priority).
"','".$this->
db->escape($this->fulldayevent).
"','".$this->
db->escape($this->location).
"', ";
507 $sql .=
"'".$this->db->escape($this->transparency).
"', ";
508 $sql .= (!empty($this->fk_element) ? $this->fk_element :
"null").
", ";
509 $sql .= (!empty($this->elementtype) ?
"'".$this->db->escape($this->elementtype).
"'" :
"null").
", ";
510 $sql .= $conf->entity.
",";
511 $sql .= (!empty($this->extraparams) ?
"'".$this->db->escape($this->extraparams).
"'" :
"null").
", ";
513 $sql .= (!empty($this->email_msgid) ?
"'".$this->db->escape($this->email_msgid).
"'" :
"null").
", ";
514 $sql .= (!empty($this->email_from) ?
"'".$this->db->escape($this->email_from).
"'" :
"null").
", ";
515 $sql .= (!empty($this->email_sender) ?
"'".$this->db->escape($this->email_sender).
"'" :
"null").
", ";
516 $sql .= (!empty($this->email_to) ?
"'".$this->db->escape($this->email_to).
"'" :
"null").
", ";
517 $sql .= (!empty($this->email_tocc) ?
"'".$this->db->escape($this->email_tocc).
"'" :
"null").
", ";
518 $sql .= (!empty($this->email_tobcc) ?
"'".$this->db->escape($this->email_tobcc).
"'" :
"null").
", ";
519 $sql .= (!empty($this->email_subject) ?
"'".$this->db->escape($this->email_subject).
"'" :
"null").
", ";
520 $sql .= (!empty($this->errors_to) ?
"'".$this->db->escape($this->errors_to).
"'" :
"null");
523 dol_syslog(get_class($this).
"::add", LOG_DEBUG);
527 $this->ref = $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"actioncomm",
"id");
533 foreach ($this->userassigned as $key => $val)
537 $val = array(
'id'=>$val);
542 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
543 $sql .=
" VALUES(".$this->id.
", 'user', ".$val[
'id'].
", ".(empty($val[
'mandatory']) ?
'0' : $val[
'mandatory']).
", ".(empty($val[
'transparency']) ?
'0' : $val[
'transparency']).
", ".(empty($val[
'answer_status']) ?
'0' : $val[
'answer_status']).
")";
549 dol_syslog(
'Error to process userassigned: '.$this->
db->lasterror(), LOG_ERR);
550 $this->errors[] = $this->
db->lasterror();
559 if (!empty($this->socpeopleassigned))
561 foreach ($this->socpeopleassigned as $id => $val)
563 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
564 $sql .=
" VALUES(".$this->id.
", 'socpeople', ".$id.
", 0, 0, 0)";
570 dol_syslog(
'Error to process socpeopleassigned: '.$this->
db->lasterror(), LOG_ERR);
571 $this->errors[] = $this->
db->lasterror();
587 if (!$error && !$notrigger)
591 if ($result < 0) { $error++; }
600 $this->
db->rollback();
604 $this->
db->rollback();
605 $this->error = $this->
db->lasterror();
619 global $db, $conf, $hookmanager;
627 $objFrom = clone $this;
639 $this->context[
'createfromclone'] =
'createfromclone';
640 $result = $this->
create($fuser);
641 if ($result < 0) $error++;
646 if (is_object($hookmanager))
648 $parameters = array(
'objFrom'=>$objFrom);
650 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
651 if ($reshook < 0) $error++;
656 if ($result < 0) { $error++; }
660 unset($this->context[
'createfromclone']);
668 $this->
db->rollback();
682 public function fetch($id, $ref =
'', $ref_ext =
'', $email_msgid =
'')
686 $sql =
"SELECT a.id,";
687 $sql .=
" a.id as ref,";
688 $sql .=
" a.entity,";
689 $sql .=
" a.ref_ext,";
691 $sql .=
" a.datep2,";
692 $sql .=
" a.durationp,";
694 $sql .=
" a.tms as datem,";
695 $sql .=
" a.code, a.label, a.note,";
696 $sql .=
" a.fk_soc,";
697 $sql .=
" a.fk_project,";
698 $sql .=
" a.fk_user_author, a.fk_user_mod,";
699 $sql .=
" a.fk_user_action, a.fk_user_done,";
700 $sql .=
" a.fk_contact, a.percent as percentage,";
701 $sql .=
" a.fk_element as elementid, a.elementtype,";
702 $sql .=
" a.priority, a.fulldayevent, a.location, a.transparency,";
703 $sql .=
" a.email_msgid, a.email_subject, a.email_from, a.email_to, a.email_tocc, a.email_tobcc, a.errors_to,";
704 $sql .=
" c.id as type_id, c.code as type_code, c.libelle as type_label, c.color as type_color, c.picto as type_picto,";
705 $sql .=
" s.nom as socname,";
706 $sql .=
" u.firstname, u.lastname as lastname";
707 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a ";
708 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_actioncomm as c ON a.fk_action=c.id ";
709 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = a.fk_user_author";
710 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = a.fk_soc";
712 if ($ref) $sql .=
" a.id = ".((int) $ref);
713 elseif ($ref_ext) $sql .=
" a.ref_ext = '".$this->db->escape($ref_ext).
"'";
714 elseif ($email_msgid) $sql .=
" a.email_msgid = '".$this->db->escape($email_msgid).
"'";
715 else $sql .=
" a.id = ".((int) $id);
717 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
724 $obj = $this->
db->fetch_object(
$resql);
726 $this->
id = $obj->id;
727 $this->entity = $obj->entity;
728 $this->ref = $obj->ref;
729 $this->ref_ext = $obj->ref_ext;
732 $this->type_id = $obj->type_id;
733 $this->type_code = $obj->type_code;
734 $this->type_color = $obj->type_color;
735 $this->type_picto = $obj->type_picto;
736 $transcode = $langs->trans(
"Action".$obj->type_code);
737 $this->
type = (($transcode !=
"Action".$obj->type_code) ? $transcode : $obj->type_label);
738 $transcode = $langs->trans(
"Action".$obj->type_code.
'Short');
739 $this->type_short = (($transcode !=
"Action".$obj->type_code.
'Short') ? $transcode :
'');
741 $this->
code = $obj->code;
742 $this->label = $obj->label;
743 $this->datep = $this->
db->jdate($obj->datep);
744 $this->datef = $this->
db->jdate($obj->datep2);
746 $this->datec = $this->
db->jdate($obj->datec);
747 $this->datem = $this->
db->jdate($obj->datem);
749 $this->
note = $obj->note;
750 $this->note_private = $obj->note;
751 $this->percentage = $obj->percentage;
753 $this->authorid = $obj->fk_user_author;
754 $this->usermodid = $obj->fk_user_mod;
756 if (!is_object($this->author)) $this->author =
new stdClass();
757 $this->author->id = $obj->fk_user_author;
758 $this->author->firstname = $obj->firstname;
759 $this->author->lastname = $obj->lastname;
760 if (!is_object($this->usermod)) $this->usermod =
new stdClass();
761 $this->usermod->id = $obj->fk_user_mod;
763 $this->userownerid = $obj->fk_user_action;
764 $this->userdoneid = $obj->fk_user_done;
765 $this->priority = $obj->priority;
766 $this->fulldayevent = $obj->fulldayevent;
767 $this->location = $obj->location;
768 $this->transparency = $obj->transparency;
770 $this->socid = $obj->fk_soc;
771 $this->contact_id = $obj->fk_contact;
772 $this->fk_project = $obj->fk_project;
777 $this->fk_element = $obj->elementid;
778 $this->elementid = $obj->elementid;
779 $this->elementtype = $obj->elementtype;
785 $this->error = $this->
db->lasterror();
799 $this->userassigned = array();
800 $this->socpeopleassigned = array();
802 $sql =
'SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency';
803 $sql .=
' FROM '.MAIN_DB_PREFIX.
'actioncomm_resources';
804 $sql .=
' WHERE fk_actioncomm = '.$this->id;
805 $sql .=
" AND element_type IN ('user', 'socpeople')";
810 if ($this->userownerid > 0) $this->userassigned[$this->userownerid] = array(
'id'=>$this->userownerid);
812 while ($obj = $this->
db->fetch_object(
$resql))
814 if ($obj->fk_element > 0)
816 switch ($obj->element_type) {
818 $this->userassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
'mandatory'=>$obj->mandatory,
'answer_status'=>$obj->answer_status,
'transparency'=>$obj->transparency);
819 if (empty($this->userownerid)) $this->userownerid = $obj->fk_element;
822 $this->socpeopleassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
'mandatory'=>$obj->mandatory,
'answer_status'=>$obj->answer_status,
'transparency'=>$obj->transparency);
845 $sql =
"SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency";
846 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm_resources";
847 $sql .=
" WHERE element_type = 'user' AND fk_actioncomm = ".$this->id;
849 $resql2 = $this->
db->query($sql);
852 $this->userassigned = array();
855 if ($this->userownerid > 0)
858 $this->userassigned[$this->userownerid] = array(
'id'=>$this->userownerid);
861 while ($obj = $this->
db->fetch_object($resql2))
863 if ($obj->fk_element > 0)
865 $this->userassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
866 'mandatory'=>$obj->mandatory,
867 'answer_status'=>$obj->answer_status,
868 'transparency'=>$obj->transparency);
871 if ($override ===
true)
874 if (empty($this->userownerid))
876 $this->userownerid = $obj->fk_element;
894 public function delete($notrigger = 0)
900 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
906 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_actioncomm";
907 $sql .=
" WHERE fk_actioncomm=".$this->id;
909 $res = $this->
db->query($sql);
911 $this->error = $this->
db->lasterror();
918 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources";
919 $sql .=
" WHERE fk_actioncomm=".$this->id;
921 $res = $this->
db->query($sql);
923 $this->error = $this->
db->lasterror();
930 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
931 $sql .=
" WHERE fk_actioncomm = ".$this->id;
933 $res = $this->
db->query($sql);
935 $this->error = $this->
db->lasterror();
946 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
952 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm";
953 $sql .=
" WHERE id=".$this->id;
955 $res = $this->
db->query($sql);
957 $this->error = $this->
db->lasterror();
968 if ($result < 0) { $error++; }
977 $this->
db->rollback();
981 $this->
db->rollback();
982 $this->error = $this->
db->lasterror();
995 public function update($user, $notrigger = 0)
997 global $langs, $conf, $hookmanager;
1002 $this->label = trim($this->label);
1003 $this->note_private =
dol_htmlcleanlastbr(trim(!isset($this->note_private) ? $this->
note : $this->note_private));
1004 if (empty($this->percentage)) $this->percentage = 0;
1005 if (empty($this->priority) || !is_numeric($this->priority)) $this->priority = 0;
1006 if (empty($this->transparency)) $this->transparency = 0;
1007 if (empty($this->fulldayevent)) $this->fulldayevent = 0;
1008 if ($this->percentage > 100) $this->percentage = 100;
1010 if ($this->datep && $this->datef) $this->durationp = ($this->datef - $this->datep);
1012 if ($this->datep && $this->datef && $this->datep > $this->datef) $this->datef = $this->datep;
1014 if ($this->fk_project < 0) $this->fk_project = 0;
1017 if ($this->percentage == 0 && $this->userdoneid > 0)
1019 $this->error =
"ErrorCantSaveADoneUserWithZeroPercentage";
1023 $socid = (($this->socid > 0) ? $this->socid : 0);
1024 $contactid = (($this->contact_id > 0) ? $this->contact_id : 0);
1025 $userownerid = ($this->userownerid ? $this->userownerid : 0);
1026 $userdoneid = ($this->userdoneid ? $this->userdoneid : 0);
1030 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm ";
1031 $sql .=
" SET percent = '".$this->db->escape($this->percentage).
"'";
1032 if ($this->type_id > 0) $sql .=
", fk_action = '".$this->db->escape($this->type_id).
"'";
1033 $sql .=
", label = ".($this->label ?
"'".$this->db->escape($this->label).
"'" :
"null");
1034 $sql .=
", datep = ".(strval($this->datep) !=
'' ?
"'".$this->db->idate($this->datep).
"'" :
'null');
1035 $sql .=
", datep2 = ".(strval($this->datef) !=
'' ?
"'".$this->db->idate($this->datef).
"'" :
'null');
1036 $sql .=
", durationp = ".(isset($this->durationp) && $this->durationp >= 0 && $this->durationp !=
'' ?
"'".$this->db->escape($this->durationp).
"'" :
"null");
1037 $sql .=
", note = '".$this->db->escape($this->note_private).
"'";
1038 $sql .=
", fk_project =".($this->fk_project > 0 ? $this->fk_project :
"null");
1039 $sql .=
", fk_soc =".($socid > 0 ? $socid :
"null");
1040 $sql .=
", fk_contact =".($contactid > 0 ? $contactid :
"null");
1041 $sql .=
", priority = '".$this->db->escape($this->priority).
"'";
1042 $sql .=
", fulldayevent = '".$this->db->escape($this->fulldayevent).
"'";
1043 $sql .=
", location = ".($this->location ?
"'".$this->db->escape($this->location).
"'" :
"null");
1044 $sql .=
", transparency = '".$this->db->escape($this->transparency).
"'";
1045 $sql .=
", fk_user_mod = ".$user->id;
1046 $sql .=
", fk_user_action = ".($userownerid > 0 ?
"'".$this->db->escape($userownerid).
"'" :
"null");
1047 $sql .=
", fk_user_done = ".($userdoneid > 0 ?
"'".$this->db->escape($userdoneid).
"'" :
"null");
1048 if (!empty($this->fk_element)) $sql .=
", fk_element=".($this->fk_element ? $this->
db->escape($this->fk_element) :
"null");
1049 if (!empty($this->elementtype)) $sql .=
", elementtype=".($this->elementtype ?
"'".$this->
db->escape($this->elementtype).
"'" :
"null");
1050 $sql .=
" WHERE id=".$this->id;
1052 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1053 if ($this->
db->query($sql))
1070 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources where fk_actioncomm = ".$this->
id.
" AND element_type = 'user'";
1073 foreach ($this->userassigned as $key => $val)
1075 if (!is_array($val))
1077 $val = array(
'id'=>$val);
1079 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1080 $sql .=
" VALUES(".$this->id.
", 'user', ".$val[
'id'].
", ".(empty($val[
'mandatory']) ?
'0' : $val[
'mandatory']).
", ".(empty($val[
'transparency']) ?
'0' : $val[
'transparency']).
", ".(empty($val[
'answer_status']) ?
'0' : $val[
'answer_status']).
")";
1086 $this->errors[] = $this->
db->lasterror();
1094 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources where fk_actioncomm = ".$this->
id.
" AND element_type = 'socpeople'";
1097 if (!empty($this->socpeopleassigned))
1099 foreach (array_keys($this->socpeopleassigned) as $id)
1101 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1102 $sql .=
" VALUES(".$this->id.
", 'socpeople', ".$id.
", 0, 0, 0)";
1108 $this->errors[] = $this->
db->lasterror();
1114 if (!$error && !$notrigger)
1118 if ($result < 0) { $error++; }
1124 $this->
db->commit();
1127 $this->
db->rollback();
1128 dol_syslog(get_class($this).
"::update ".join(
',', $this->errors), LOG_ERR);
1132 $this->
db->rollback();
1133 $this->error = $this->
db->lasterror();
1152 public static function getActions($db, $socid = 0, $fk_element = 0, $elementtype =
'', $filter =
'', $sortfield =
'a.datep', $sortorder =
'DESC', $limit = 0)
1154 global $conf, $langs;
1156 $resarray = array();
1158 dol_syslog(get_class().
"::getActions", LOG_DEBUG);
1160 $sql =
"SELECT a.id";
1161 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
1162 $sql .=
" WHERE a.entity IN (".getEntity(
'agenda').
")";
1163 if (!empty($socid)) $sql .=
" AND a.fk_soc = ".$socid;
1164 if (!empty($elementtype))
1166 if ($elementtype ==
'project') {
1167 $sql .=
' AND a.fk_project = '.$fk_element;
1169 elseif ($elementtype ==
'contact') {
1170 $sql .=
' AND a.id IN';
1171 $sql .=
" (SELECT fk_actioncomm FROM ".MAIN_DB_PREFIX.
"actioncomm_resources WHERE";
1172 $sql .=
" element_type = 'socpeople' AND fk_element = ".$fk_element.
')';
1175 $sql .=
" AND a.fk_element = ".(int) $fk_element.
" AND a.elementtype = '".$db->escape($elementtype).
"'";
1178 if (!empty($filter)) $sql .= $filter;
1179 if ($sortorder && $sortfield) $sql .= $db->order($sortfield, $sortorder);
1180 $sql .= $db->plimit($limit, 0);
1182 $resql = $db->query($sql);
1185 $num = $db->num_rows(
$resql);
1189 for ($i = 0; $i < $num; $i++)
1191 $obj = $db->fetch_object(
$resql);
1193 $actioncommstatic->fetch($obj->id);
1194 $resarray[$i] = $actioncommstatic;
1200 return $db->lasterror();
1215 global $conf, $langs;
1217 if (empty($load_state_board)) {
1218 $sql =
"SELECT a.id, a.datep as dp";
1220 $this->nb = array();
1221 $sql =
"SELECT count(a.id) as nb";
1223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
1224 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
1225 if (!$user->rights->agenda->allactions->read) {
1226 $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 = ".$user->id;
1228 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON a.fk_soc = s.rowid";
1229 $sql .=
" WHERE 1 = 1";
1230 if (empty($load_state_board)) $sql .=
" AND a.percent >= 0 AND a.percent < 100";
1231 $sql .=
" AND a.entity IN (".getEntity(
'agenda').
")";
1232 if (!$user->rights->societe->client->voir && !$user->socid) $sql .=
" AND (a.fk_soc IS NULL OR sc.fk_user = ".$user->id.
")";
1233 if ($user->socid) $sql .=
" AND a.fk_soc = ".$user->socid;
1234 if (!$user->rights->agenda->allactions->read) {
1235 $sql .=
" AND (a.fk_user_author = ".$user->id.
" OR a.fk_user_action = ".$user->id.
" OR a.fk_user_done = ".$user->id;
1236 $sql .=
" OR ar.fk_element = ".$user->id;
1243 if (empty($load_state_board)) {
1246 $response->warning_delay = $conf->agenda->warning_delay / 60 / 60 / 24;
1247 $response->label = $langs->trans(
"ActionsToDo");
1248 $response->labelShort = $langs->trans(
"ActionsToDoShort");
1249 $response->url = DOL_URL_ROOT.
'/comm/action/list.php?action=show_list&actioncode=0&status=todo&mainmenu=agenda';
1250 if ($user->rights->agenda->allactions->read) $response->url .=
'&filtert=-1';
1251 $response->img =
img_object(
'',
"action",
'class="inline-block valigntextmiddle"');
1254 while ($obj = $this->
db->fetch_object(
$resql)) {
1255 if (empty($load_state_board)) {
1256 $response->nbtodo++;
1257 $agenda_static->datep = $this->
db->jdate($obj->dp);
1258 if ($agenda_static->hasDelay()) $response->nbtodolate++;
1260 $this->nb[
"actionscomm"] = $obj->nb;
1265 if (empty($load_state_board))
return $response;
1269 $this->error = $this->
db->error();
1286 $sql .=
' tms as datem,';
1287 $sql .=
' fk_user_author,';
1288 $sql .=
' fk_user_mod';
1289 $sql .=
' FROM '.MAIN_DB_PREFIX.
'actioncomm as a';
1290 $sql .=
' WHERE a.id = '.$id;
1292 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
1293 $result = $this->
db->query($sql);
1296 if ($this->
db->num_rows($result))
1298 $obj = $this->
db->fetch_object($result);
1299 $this->
id = $obj->id;
1300 if ($obj->fk_user_author)
1302 $cuser =
new User($this->
db);
1303 $cuser->fetch($obj->fk_user_author);
1304 $this->user_creation = $cuser;
1306 if ($obj->fk_user_mod)
1308 $muser =
new User($this->
db);
1309 $muser->fetch($obj->fk_user_mod);
1310 $this->user_modification = $muser;
1313 $this->date_creation = $this->
db->jdate($obj->datec);
1314 if (!empty($obj->fk_user_mod)) $this->date_modification = $this->
db->jdate($obj->datem);
1316 $this->
db->free($result);
1332 return $this->
LibStatut($this->percentage, $mode, $hidenastatus, $this->datep);
1345 public function LibStatut($percent, $mode, $hidenastatus = 0, $datestart =
'')
1350 $labelStatus = $langs->trans(
'StatusNotApplicable');
1351 if ($percent == -1 && !$hidenastatus) $labelStatus = $langs->trans(
'StatusNotApplicable');
1352 elseif ($percent == 0) $labelStatus = $langs->trans(
'StatusActionToDo').
' (0%)';
1353 elseif ($percent > 0 && $percent < 100) $labelStatus = $langs->trans(
'StatusActionInProcess').
' ('.$percent.
'%)';
1354 elseif ($percent >= 100) $labelStatus = $langs->trans(
'StatusActionDone').
' (100%)';
1356 $labelStatusShort = $langs->trans(
'StatusNotApplicable');
1357 if ($percent == -1 && !$hidenastatus) $labelStatusShort = $langs->trans(
'NA');
1358 elseif ($percent == 0) $labelStatusShort =
'0%';
1359 elseif ($percent > 0 && $percent < 100) $labelStatusShort = $percent.
'%';
1360 elseif ($percent >= 100) $labelStatusShort =
'100%';
1362 $statusType =
'status9';
1363 if ($percent == -1 && !$hidenastatus) $statusType =
'status9';
1364 if ($percent == 0) $statusType =
'status1';
1365 if ($percent > 0 && $percent < 100) $statusType =
'status3';
1366 if ($percent >= 100) $statusType =
'status6';
1368 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1384 public function getNomUrl($withpicto = 0, $maxlength = 0, $classname =
'', $option =
'', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
1386 global $conf, $langs, $user, $hookmanager, $action;
1388 if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1;
1391 if ($user->rights->agenda->myactions->read && $this->authorid == $user->id) $canread = 1;
1392 if ($user->rights->agenda->myactions->read && array_key_exists($user->id, $this->userassigned)) $canread = 1;
1393 if ($user->rights->agenda->allactions->read) $canread = 1;
1399 $label = $this->label;
1400 if (empty($label)) $label = $this->libelle;
1406 if ($this->type_code)
1408 $labeltype = ($langs->transnoentities(
"Action".$this->type_code) !=
"Action".$this->type_code) ? $langs->transnoentities(
"Action".$this->type_code) : $this->type_label;
1410 if (empty($conf->global->AGENDA_USE_EVENT_TYPE))
1412 if ($this->type_code !=
'AC_OTH_AUTO') $labeltype = $langs->trans(
'ActionAC_MANUAL');
1415 $tooltip =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
'Action').
'</u>';
1416 if (!empty($this->ref))
1417 $tooltip .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1419 $tooltip .=
'<br><b>'.$langs->trans(
'Title').
':</b> '.$label;
1420 if (!empty($labeltype))
1421 $tooltip .=
'<br><b>'.$langs->trans(
'Type').
':</b> '.$labeltype;
1422 if (!empty($this->location))
1423 $tooltip .=
'<br><b>'.$langs->trans(
'Location').
':</b> '.$this->location;
1424 if (isset($this->transparency))
1425 $tooltip .=
'<br><b>'.$langs->trans(
'Busy').
':</b> '.
yn($this->transparency);
1426 if (!empty($this->note_private))
1427 $tooltip .=
'<br><b>'.$langs->trans(
'Note').
':</b> '.(
dol_textishtml($this->note_private) ? str_replace(array(
"\r",
"\n"),
"", $this->note_private) : str_replace(array(
"\r",
"\n"),
'<br>', $this->note_private));
1429 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && $this->type_color)
1430 $linkclose =
' style="background-color:#'.$this->type_color.
'"';
1432 if (empty($notooltip))
1434 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
1436 $label = $langs->trans(
"ShowAction");
1437 $linkclose .=
' alt="'.dol_escape_htmltag($tooltip, 1).
'"';
1439 $linkclose .=
' title="'.dol_escape_htmltag($tooltip, 1).
'"';
1440 $linkclose .=
' class="'.$classname.
' classfortooltip"';
1448 }
else $linkclose .=
' class="'.$classname.
'"';
1451 if ($option ==
'birthday')
1452 $url = DOL_URL_ROOT.
'/contact/perso.php?id='.$this->id;
1453 elseif ($option ==
'holiday')
1454 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1455 else $url = DOL_URL_ROOT.
'/comm/action/card.php?id='.$this->id;
1456 if ($option !==
'nolink')
1459 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1460 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
1461 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
1464 $linkstart =
'<a href="'.$url.
'"';
1465 $linkstart .= $linkclose.
'>';
1468 if ($option ==
'nolink') {
1473 if ($withpicto == 2)
1476 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) $libelle = $labeltype;
1479 $libelle = (empty($this->libelle) ? $label : $this->libelle.(($label && $label != $this->libelle) ?
' '.$label :
''));
1480 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($libelle)) $libelle = $labeltype;
1481 if ($maxlength < 0) $libelleshort = $this->ref;
1482 else $libelleshort =
dol_trunc($libelle, $maxlength);
1487 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
1491 $libelle .= (preg_match(
'/'.preg_quote($labeltype,
'/').
'/', $libelle) ?
'' :
' ('.$langs->transnoentities(
"Action".$this->type_code).
')');
1496 $result .= $linkstart;
1497 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $langs->trans(
"ShowAction").
': '.$libelle), ($overwritepicto ? $overwritepicto :
'action'), ($notooltip ?
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"' :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1498 $result .= $libelleshort;
1499 $result .= $linkend;
1502 $hookmanager->initHooks(array(
'actiondao'));
1503 $parameters = array(
'id'=>$this->
id,
'getnomurl'=>$result);
1504 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1505 if ($reshook > 0) $result = $hookmanager->resPrint;
1506 else $result .= $hookmanager->resPrint;
1524 if (!is_array($categories)) {
1525 $categories = array($categories);
1529 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1531 $existing = $c->containing($this->
id, Categorie::TYPE_ACTIONCOMM,
'id');
1534 if (is_array($existing)) {
1535 $to_del = array_diff($existing, $categories);
1536 $to_add = array_diff($categories, $existing);
1539 $to_add = $categories;
1543 foreach ($to_del as $del) {
1544 if ($c->fetch($del) > 0) {
1545 $c->del_type($this, Categorie::TYPE_ACTIONCOMM);
1548 foreach ($to_add as $add) {
1549 if ($c->fetch($add) > 0) {
1550 $c->add_type($this, Categorie::TYPE_ACTIONCOMM);
1568 public function build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday = 0)
1570 global $hookmanager;
1573 global $conf, $langs, $dolibarr_main_url_root, $mysoc;
1575 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
1576 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
1577 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
1579 dol_syslog(get_class($this).
"::build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
1582 if (empty($format))
return -1;
1588 if ($format ==
'ical') $extension =
'ics';
1589 $filename = $format.
'.'.$extension;
1593 $result =
dol_mkdir($conf->agenda->dir_temp);
1594 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
1599 $login =
''; $logina =
''; $logind =
''; $logint =
'';
1606 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1609 dol_syslog(get_class($this).
"::build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
1617 $eventarray = array();
1619 $sql =
"SELECT a.id,";
1620 $sql .=
" a.datep,";
1621 $sql .=
" a.datep2,";
1622 $sql .=
" a.durationp,";
1623 $sql .=
" a.datec, a.tms as datem,";
1624 $sql .=
" a.label, a.code, a.note, a.fk_action as type_id,";
1625 $sql .=
" a.fk_soc,";
1626 $sql .=
" a.fk_user_author, a.fk_user_mod,";
1627 $sql .=
" a.fk_user_action,";
1628 $sql .=
" a.fk_contact, a.percent as percentage,";
1629 $sql .=
" a.fk_element, a.elementtype,";
1630 $sql .=
" a.priority, a.fulldayevent, a.location, a.transparency,";
1631 $sql .=
" u.firstname, u.lastname, u.email,";
1632 $sql .=
" s.nom as socname,";
1633 $sql .=
" c.id as type_id, c.code as type_code, c.libelle as type_label";
1634 $sql .=
" FROM (".MAIN_DB_PREFIX.
"c_actioncomm as c, ".MAIN_DB_PREFIX.
"actioncomm as a)";
1635 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = a.fk_user_author";
1636 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = a.fk_soc";
1638 $parameters = array(
'filters' => $filters);
1639 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
1640 $sql .= $hookmanager->resPrint;
1643 if ($filters[
'logint']) $sql .=
", ".MAIN_DB_PREFIX.
"actioncomm_resources as ar";
1644 $sql .=
" WHERE a.fk_action=c.id";
1645 $sql .=
" AND a.entity IN (".getEntity(
'agenda').
")";
1646 foreach ($filters as $key => $value)
1648 if ($key ==
'notolderthan' && $value !=
'') $sql .=
" AND a.datep >= '".$this->db->idate($now - ($value * 24 * 60 * 60)).
"'";
1650 if ($key ==
'id') $sql .=
" AND a.id=".(is_numeric($value) ? $value : 0);
1651 if ($key ==
'idfrom') $sql .=
" AND a.id >= ".(is_numeric($value) ? $value : 0);
1652 if ($key ==
'idto') $sql .=
" AND a.id <= ".(is_numeric($value) ? $value : 0);
1653 if ($key ==
'project') $sql .=
" AND a.fk_project=".(is_numeric($value) ? $value : 0);
1654 if ($key ==
'actiontype') $sql .=
" AND c.type = '".$this->db->escape($value).
"'";
1655 if ($key ==
'notactiontype') $sql .=
" AND c.type <> '".$this->db->escape($value).
"'";
1657 if ($key ==
'logint') $sql .=
" AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
1658 if ($key ==
'logina')
1662 if (preg_match(
'/^!/', $logina))
1664 $logina = preg_replace(
'/^!/',
'', $logina);
1667 $userforfilter =
new User($this->
db);
1668 $result = $userforfilter->fetch(
'', $logina);
1669 if ($result > 0) $sql .=
" AND a.fk_user_author ".$condition.
" ".$userforfilter->id;
1670 elseif ($result < 0 || $condition ==
'=') $sql .=
" AND a.fk_user_author = 0";
1672 if ($key ==
'logint')
1676 if (preg_match(
'/^!/', $logint))
1678 $logint = preg_replace(
'/^!/',
'', $logint);
1681 $userforfilter =
new User($this->
db);
1682 $result = $userforfilter->fetch(
'', $logint);
1683 if ($result > 0) $sql .=
" AND ar.fk_element = ".$userforfilter->id;
1684 elseif ($result < 0 || $condition ==
'=') $sql .=
" AND ar.fk_element = 0";
1688 $sql .=
" AND a.datep IS NOT NULL";
1690 $parameters = array(
'filters' => $filters);
1691 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
1692 $sql .= $hookmanager->resPrint;
1694 $sql .=
" ORDER by datep";
1697 dol_syslog(get_class($this).
"::build_exportfile select events", LOG_DEBUG);
1704 while ($obj = $this->
db->fetch_object(
$resql))
1710 $event[
'uid'] =
'dolibarragenda-'.$this->db->database_name.
'-'.$obj->id.
"@".
$_SERVER[
"SERVER_NAME"];
1711 $event[
'type'] = $type;
1712 $datestart = $this->
db->jdate($obj->datep) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
1715 if (is_numeric($this->
db->jdate($obj->datep2)))
1717 $dateend = $this->
db->jdate($obj->datep2)
1718 - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
1721 $dateend = $datestart;
1724 $duration = ($datestart && $dateend) ? ($dateend - $datestart) : 0;
1725 $event[
'summary'] = $obj->label.($obj->socname ?
" (".$obj->socname.
")" :
"");
1726 $event[
'desc'] = $obj->note;
1727 $event[
'startdate'] = $datestart;
1728 $event[
'enddate'] = $dateend;
1729 $event[
'duration'] = $duration;
1731 $event[
'priority'] = $obj->priority;
1732 $event[
'fulldayevent'] = $obj->fulldayevent;
1733 $event[
'location'] = $obj->location;
1734 $event[
'transparency'] = (($obj->transparency > 0) ?
'OPAQUE' :
'TRANSPARENT');
1735 $event[
'category'] = $obj->type_label;
1736 $event[
'email'] = $obj->email;
1738 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1739 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1741 $url = $urlwithroot.
'/comm/action/card.php?id='.$obj->id;
1742 $event[
'url'] = $url;
1743 $event[
'created'] = $this->
db->jdate($obj->datec) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
1744 $event[
'modified'] = $this->
db->jdate($obj->datem) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
1747 $this->
id = $obj->id;
1750 $assignedUserArray = array();
1752 foreach ($this->userassigned as $key => $value)
1754 $assignedUser =
new User($this->
db);
1755 $assignedUser->fetch($value[
'id']);
1757 $assignedUserArray[$key] = $assignedUser;
1760 $event[
'assignedUsers'] = $assignedUserArray;
1762 if ($qualified && $datestart)
1764 $eventarray[] = $event;
1769 $parameters = array(
'filters' => $filters,
'eventarray' => &$eventarray);
1770 $reshook = $hookmanager->executeHooks(
'addMoreEventsExport', $parameters);
1773 $eventarray = $hookmanager->resArray;
1776 $this->error = $this->
db->lasterror();
1780 if ($exportholiday == 1)
1782 $langs->load(
"holidays");
1783 $title = $langs->trans(
"Holidays");
1785 $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";
1786 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as x, ".MAIN_DB_PREFIX.
"user as u";
1787 $sql .=
" WHERE u.rowid = x.fk_user";
1788 $sql .=
" AND u.statut = '1'";
1789 $sql .=
" AND (x.statut = '2' OR x.statut = '3')";
1794 $num = $this->
db->num_rows(
$resql);
1799 $obj = $this->
db->fetch_object(
$resql);
1802 if ($obj->halfday == -1)
1804 $event[
'fulldayevent'] =
false;
1808 } elseif ($obj->halfday == 1)
1810 $event[
'fulldayevent'] =
false;
1815 $event[
'fulldayevent'] =
true;
1821 if (!empty($conf->global->AGENDA_EXPORT_FIX_TZ))
1823 $timestampStart = - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
1824 $timestampEnd = - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
1827 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
1828 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
1829 $url = $urlwithroot.
'/holiday/card.php?id='.$obj->rowid;
1831 $event[
'uid'] =
'dolibarrholiday-'.$this->db->database_name.
'-'.$obj->rowid.
"@".
$_SERVER[
"SERVER_NAME"];
1833 $event[
'type'] =
'event';
1834 $event[
'category'] =
"Holiday";
1835 $event[
'transparency'] =
'OPAQUE';
1836 $event[
'email'] = $obj->email;
1837 $event[
'created'] = $timestampStart;
1838 $event[
'modified'] = $timestampStart;
1839 $event[
'startdate'] = $timestampStart;
1840 $event[
'enddate'] = $timestampEnd;
1841 $event[
'duration'] = $timestampEnd - $timestampStart;
1842 $event[
'url'] = $url;
1844 if ($obj->status == 2)
1847 $event[
'summary'] = $title.
" - ".$obj->lastname.
" (wait for approval)";
1850 $event[
'summary'] = $title.
" - ".$obj->lastname;
1853 $eventarray[] = $event;
1860 $langs->load(
"agenda");
1864 if ($login) $more = $langs->transnoentities(
"User").
' '.$login;
1865 if ($logina) $more = $langs->transnoentities(
"ActionsAskedBy").
' '.$logina;
1866 if ($logint) $more = $langs->transnoentities(
"ActionsToDoBy").
' '.$logint;
1867 if ($logind) $more = $langs->transnoentities(
"ActionsDoneBy").
' '.$logind;
1870 $title =
'Dolibarr actions '.$mysoc->name.
' - '.$more;
1872 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
1874 $title =
'Dolibarr actions '.$mysoc->name;
1875 $desc = $langs->transnoentities(
'ListOfActions');
1876 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
1880 $outputfiletmp = tempnam($conf->agenda->dir_temp,
'tmp');
1881 @chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
1884 if ($format ==
'vcal') $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
1885 elseif ($format ==
'ical') $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
1886 elseif ($format ==
'rss') $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
1890 if (
dol_move($outputfiletmp, $outputfile, 0, 1)) $result = 1;
1892 $this->error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
1893 dol_syslog(get_class($this).
"::build_exportfile ".$this->error, LOG_ERR);
1898 dol_syslog(get_class($this).
"::build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
1900 $langs->load(
"errors");
1901 $this->error = $langs->trans(
"ErrorFailToCreateFile", $outputfile);
1923 $this->specimen = 1;
1925 $this->type_code =
'AC_OTH';
1926 $this->
code =
'AC_SPECIMEN_CODE';
1927 $this->label =
'Label of event Specimen';
1928 $this->datec = $now;
1929 $this->datem = $now;
1930 $this->datep = $now;
1931 $this->datef = $now;
1932 $this->fulldayevent = 0;
1933 $this->percentage = 0;
1934 $this->location =
'Location';
1935 $this->transparency = 1;
1936 $this->priority = 1;
1938 $this->note_private =
"This is a 'private' note.";
1940 $this->userownerid = $user->id;
1941 $this->userassigned[$user->id] = array(
'id'=>$user->id,
'transparency'=> 1);
1973 return $this->datep && ($this->datep < ($now - $conf->agenda->warning_delay));
1987 global $conf, $langs, $user;
1991 $this->reminders = array();
1994 $sql =
"SELECT rowid as id, typeremind, dateremind, status, offsetvalue, offsetunit, fk_user";
1995 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
1996 $sql .=
" WHERE fk_actioncomm = ".$this->id;
1998 $sql .=
" AND dateremind <= '".$this->db->idate(
dol_now()).
"'";
2001 $sql .=
" AND typeremind ='".$this->db->escape($type).
"'";
2004 $sql .=
" AND fk_user = ".((int) $fk_user);
2006 if (empty($conf->global->AGENDA_REMINDER_EMAIL)) $sql .=
" AND typeremind != 'email'";
2007 if (empty($conf->global->AGENDA_REMINDER_BROWSER)) $sql .=
" AND typeremind != 'browser'";
2009 $sql .= $this->
db->order(
"dateremind",
"ASC");
2013 while ($obj = $this->
db->fetch_object(
$resql)) {
2015 $tmpactioncommreminder->id = $obj->id;
2016 $tmpactioncommreminder->typeremind = $obj->typeremind;
2017 $tmpactioncommreminder->dateremind = $obj->dateremind;
2018 $tmpactioncommreminder->offsetvalue = $obj->offsetvalue;
2019 $tmpactioncommreminder->offsetunit = $obj->offsetunit;
2020 $tmpactioncommreminder->status = $obj->status;
2021 $tmpactioncommreminder->fk_user = $obj->fk_user;
2023 $this->reminders[$obj->id] = $tmpactioncommreminder;
2026 $this->error = $this->
db->lasterror();
2030 return count($this->reminders);
2042 global $conf, $langs, $user;
2048 $errorsMsg = array();
2050 if (empty($conf->agenda->enabled))
2052 $langs->load(
"agenda");
2053 $this->output = $langs->trans(
'ModuleNotEnabled', $langs->transnoentitiesnoconv(
"Agenda"));
2056 if (empty($conf->global->AGENDA_REMINDER_EMAIL))
2058 $langs->load(
"agenda");
2059 $this->output = $langs->trans(
'EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv(
"Agenda"));
2071 $sql =
"SELECT rowid as id FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2072 $sql .=
" WHERE typeremind = 'email' AND status = 0";
2073 $sql .=
" AND dateremind <= '".$this->db->idate(
dol_now()).
"'";
2074 $sql .= $this->
db->order(
"dateremind",
"ASC");
2080 while ($obj = $this->
db->fetch_object(
$resql)) {
2081 $res = $actionCommReminder->fetch($obj->id);
2084 $errorsMsg[] =
"Failed to load invoice ActionComm Reminder";
2089 $arraymessage = $formmail->getEMailTemplate($this->
db,
'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1);
2092 $res = $this->
fetch($actionCommReminder->fk_actioncomm);
2103 $sendContent =
make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
2106 $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->trans(
'EventReminder'));
2109 $recipient =
new User($this->
db);
2110 $res = $recipient->fetch($actionCommReminder->fk_user);
2112 if (!empty($recipient->email)) {
2113 $to = $recipient->email;
2115 $errormesg =
"Failed to send remind to user id=".$actionCommReminder->fk_user.
". No email defined for user.";
2119 $errormesg =
"Failed to load recipient with user id=".$actionCommReminder->fk_user;
2124 $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
2126 $errormesg =
"Failed to get sender into global setup MAIN_MAIL_EMAIL_FROM";
2132 $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO;
2135 $cMailFile =
new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(),
'',
"", 0, 1, $errors_to,
'',
'',
'',
'',
'');
2138 if ($cMailFile->sendfile()) {
2141 $errormesg = $cMailFile->error.
' : '.$to;
2147 $actionCommReminder->status = $actionCommReminder::STATUS_DONE;
2149 $res = $actionCommReminder->update($user);
2151 $errorsMsg[] =
"Failed to update status to done of ActionComm Reminder";
2156 $actionCommReminder->status = $actionCommReminder::STATUS_ERROR;
2157 $actionCommReminder->lasterror =
dol_trunc($errormesg, 128,
'right',
'UTF-8', 1);
2159 $res = $actionCommReminder->update($user);
2161 $errorsMsg[] =
"Failed to update status to error of ActionComm Reminder";
2165 $errorsMsg[] = $errormesg;
2169 $errorsMsg[] =
'Failed to fetch record actioncomm with ID = '.$actionCommReminder->fk_actioncomm;
2180 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2181 $sql .=
" WHERE dateremind < '".$this->db->idate($now - (3600 * 24 * 32)).
"'";
2182 $sql .=
" AND status = ".$actionCommReminder::STATUS_DONE;
2186 $errorsMsg[] =
'Failed to delete old reminders';
2192 $this->output =
'Nb of emails sent : '.$nbMailSend;
2193 $this->
db->commit();
2196 $this->
db->commit();
2197 $this->error =
'Nb of emails sent : '.$nbMailSend.
', '.(!empty($errorsMsg)) ? join(
', ', $errorsMsg) : $error;
2213 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm ";
2214 $sql .=
" SET percent = ".(int) $percent;
2215 $sql .=
" WHERE id=".$id;
2217 if ($this->
db->query($sql))
2219 $this->
db->commit();
2222 $this->
db->rollback();
2223 $this->error = $this->
db->lasterror();
Class to manage different types of events.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
Class for ActionCommReminder.
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
loadReminders($type= '', $fk_user=0, $onlypast=true)
Load event reminder of events.
Class to manage agenda events (actions)
updatePercent($id, $percent)
Udpate the percent value of a event with the given id.
LibStatut($percent, $mode, $hidenastatus=0, $datestart= '')
Return label of action status.
const EVENT_FINISHED
Typical value for a event that is in a finished state.
dol_now($mode= 'auto')
Return date for now.
create(User $user, $notrigger=0)
Add an action/event into database.
fetchResources()
Initialize $this->userassigned & this->socpeopleassigned array with list of id of user and contact as...
Class to manage Dolibarr users.
Class to manage Dolibarr database access.
setCategories($categories)
Sets object to supplied categories.
build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday=0)
Export events from database into a cal file.
info($id)
Charge les informations d'ordre info dans l'objet facture.
load_board($user, $load_state_board=0)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
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...
createFromClone(User $fuser, $socid)
Load an object from its id and create a new one in database.
build_calfile($format, $title, $desc, $events_array, $outputfile)
Build a file from an array of events All input params and data must be encoded in $conf->charset_outp...
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.
$conf db
API class for accounts.
__construct(DoliDB $db)
Constructor.
sendEmailsReminder()
Send reminders by emails CAN BE A CRON TASK.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
initAsSpecimen()
Initialise an instance with random values.
const EVENT_IN_PROGRESS
Typical value for a event that is in a progress state.
Class to manage categories.
update($user, $notrigger=0)
Update action into database If percentage = 100, on met a jour date 100%.
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter= '', $url= '', $langcode= '')
Build a file from an array of events.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
const EVENT_TODO
Typical value for a event that is in a todo state.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
deleteExtraFields()
Delete all extra fields values for the current object.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
hasDelay()
Is the action delayed?
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
call_trigger($triggerName, $user)
Call trigger based on this instance.
dol_filemtime($pathoffile)
Return time of a file.
static getActions($db, $socid=0, $fk_element=0, $elementtype= '', $filter= '', $sortfield= 'a.datep', $sortorder= 'DESC', $limit=0)
Load all objects with filters.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
fetch($id, $ref= '', $ref_ext= '', $email_msgid= '')
Load object from database.
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.
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
getLibStatut($mode, $hidenastatus=0)
Return label of status.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
fetch_userassigned($override=true)
Initialize this->userassigned array with list of id of user assigned to event.