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';
43 public $element =
'action';
48 public $table_element =
'actioncomm';
53 public $table_rowid =
'id';
58 public $picto =
'action';
63 public $ismultientitymanaged = 1;
70 public $restrictiononfksoc = 2;
184 public $date_start_in_calendar;
189 public $date_end_in_calendar;
200 public $durationp = -1;
205 public $fulldayevent = 0;
225 public $transparency;
235 public $userassigned = array();
250 public $socpeopleassigned = array();
255 public $otherassigned = array();
260 public $reminders = array();
320 public $actions = array();
335 public $email_sender;
354 public $email_subject;
381 public $recurdateend;
383 public $calling_duration;
402 public $fields = array();
425 global $langs, $conf, $hookmanager;
431 if (!isset($this->userownerid) || $this->userownerid ===
'') {
432 dol_syslog(
"You tried to create an event but mandatory property ownerid was not defined", LOG_WARNING);
433 $this->errors[] =
'ErrorActionCommPropertyUserowneridNotDefined';
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;
444 if (empty($this->priority) || !is_numeric($this->priority)) {
447 if (empty($this->fulldayevent)) {
448 $this->fulldayevent = 0;
450 if (empty($this->transparency)) {
451 $this->transparency = 0;
453 if ($this->percentage > 100) {
454 $this->percentage = 100;
457 if (!empty($this->datep) && !empty($this->datef)) {
458 $this->durationp = ($this->datef - $this->datep);
461 if (!empty($this->datep) && !empty($this->datef) && $this->datep > $this->datef) {
462 $this->datef = $this->datep;
465 if (!isset($this->fk_project) || $this->fk_project < 0) {
466 $this->fk_project = 0;
469 if ($this->elementtype ==
'facture') {
470 $this->elementtype =
'invoice';
472 if ($this->elementtype ==
'commande') {
473 $this->elementtype =
'order';
475 if ($this->elementtype ==
'contrat') {
476 $this->elementtype =
'contract';
479 if (!is_array($this->userassigned) && !empty($this->userassigned)) {
480 $tmpid = $this->userassigned;
481 $this->userassigned = array();
482 $this->userassigned[$tmpid] = array(
'id'=>$tmpid,
'transparency'=>$this->transparency);
485 $userownerid = $this->userownerid;
486 $userdoneid = $this->userdoneid;
489 if (empty($this->userassigned) || count($this->userassigned) == 0 || !is_array($this->userassigned)) {
490 $this->userassigned = array($userownerid=>array(
'id'=>$userownerid,
'transparency'=>$this->transparency));
493 if (!$this->type_id || !$this->type_code) {
494 $key = empty($this->type_id) ? $this->type_code : $this->type_id;
498 $result = $cactioncomm->fetch($key);
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);
507 $this->error = $cactioncomm->error;
511 $code = empty($this->
code) ? $this->type_code : $this->code;
514 if (!$this->type_id) {
515 $this->error =
"ErrorWrongParameters";
521 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm";
526 $sql .=
"durationp,";
527 $sql .=
"fk_action,";
531 $sql .=
"fk_project,";
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,";
542 $sql .=
"extraparams,";
544 $sql .=
"email_msgid,";
545 $sql .=
"email_from,";
546 $sql .=
"email_sender,";
548 $sql .=
"email_tocc,";
549 $sql .=
"email_tobcc,";
550 $sql .=
"email_subject,";
551 $sql .=
"errors_to,";
553 $sql .=
"event_paid,";
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").
", ";
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").
", ";
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").
", ";
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");
595 dol_syslog(get_class($this).
"::add", LOG_DEBUG);
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;
603 dol_syslog(
'Error to process ref: '.$this->
db->lasterror(), LOG_ERR);
604 $this->errors[] = $this->
db->lasterror();
609 $already_inserted = array();
610 foreach ($this->userassigned as $key => $val) {
612 if (!is_array($val)) {
613 $val = array(
'id'=>$val);
616 if ($val[
'id'] > 0) {
617 if (!empty($already_inserted[$val[
'id']])) {
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'])).
")";
627 dol_syslog(
'Error to process userassigned: ' . $this->
db->lasterror(), LOG_ERR);
628 $this->errors[] = $this->
db->lasterror();
630 $already_inserted[$val[
'id']] =
true;
638 if (!empty($this->socpeopleassigned)) {
639 $already_inserted = array();
640 foreach ($this->socpeopleassigned as $id => $val) {
642 if (!empty($already_inserted[$id])) {
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)";
652 dol_syslog(
'Error to process socpeopleassigned: ' . $this->
db->lasterror(), LOG_ERR);
653 $this->errors[] = $this->
db->lasterror();
655 $already_inserted[$id] =
true;
669 if (!$error && !$notrigger) {
682 $this->
db->rollback();
686 $this->
db->rollback();
687 $this->error = $this->
db->lasterror();
701 global $db, $conf, $hookmanager;
709 $objFrom = clone $this;
721 $this->context[
'createfromclone'] =
'createfromclone';
722 $result = $this->
create($fuser);
729 if (is_object($hookmanager)) {
730 $parameters = array(
'objFrom'=>$objFrom);
732 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
746 unset($this->context[
'createfromclone']);
753 $this->
db->rollback();
768 public function fetch($id, $ref =
'', $ref_ext =
'', $email_msgid =
'', $loadresources = 1)
772 if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) {
773 dol_syslog(get_class($this).
"::fetch Bad parameters", LOG_WARNING);
777 $sql =
"SELECT a.id,";
778 $sql .=
" a.ref as ref,";
779 $sql .=
" a.entity,";
780 $sql .=
" a.ref_ext,";
782 $sql .=
" a.datep2,";
783 $sql .=
" a.durationp,";
785 $sql .=
" a.tms as datem,";
786 $sql .=
" a.code, a.label, a.note as note_private,";
787 $sql .=
" a.fk_soc,";
788 $sql .=
" a.fk_project,";
789 $sql .=
" a.fk_user_author, a.fk_user_mod,";
790 $sql .=
" a.fk_user_action, a.fk_user_done,";
791 $sql .=
" a.fk_contact, a.percent as percentage,";
792 $sql .=
" a.fk_element as elementid, a.elementtype,";
793 $sql .=
" a.priority, a.fulldayevent, a.location, a.transparency,";
794 $sql .=
" a.email_msgid, a.email_subject, a.email_from, a.email_sender, a.email_to, a.email_tocc, a.email_tobcc, a.errors_to,";
795 $sql .=
" c.id as type_id, c.type as type_type, c.code as type_code, c.libelle as type_label, c.color as type_color, c.picto as type_picto,";
796 $sql .=
" s.nom as socname,";
797 $sql .=
" u.firstname, u.lastname as lastname,";
798 $sql .=
" num_vote, event_paid, a.status";
799 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a ";
800 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_actioncomm as c ON a.fk_action=c.id ";
801 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = a.fk_user_author";
802 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = a.fk_soc";
805 $sql .=
" a.ref = '".$this->db->escape($ref).
"'";
806 } elseif ($ref_ext) {
807 $sql .=
" a.ref_ext = '".$this->db->escape($ref_ext).
"'";
808 } elseif ($email_msgid) {
809 $sql .=
" a.email_msgid = '".$this->db->escape($email_msgid).
"'";
811 $sql .=
" a.id = ".((int) $id);
814 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
819 $obj = $this->
db->fetch_object(
$resql);
821 $this->
id = $obj->id;
822 $this->entity = $obj->entity;
823 $this->
ref = $obj->ref;
824 $this->ref_ext = $obj->ref_ext;
827 $this->type_id = $obj->type_id;
828 $this->type_code = $obj->type_code;
829 $this->type_color = $obj->type_color;
830 $this->type_picto = $obj->type_picto;
831 $this->
type = $obj->type_type;
834 $transcode = $langs->trans(
"Action".$obj->type_code.
'Short');
835 $this->type_short = (($transcode !=
"Action".$obj->type_code.
'Short') ? $transcode :
'');
837 $this->
code = $obj->code;
838 $this->label = $obj->label;
839 $this->datep = $this->
db->jdate($obj->datep);
840 $this->datef = $this->
db->jdate($obj->datep2);
842 $this->datec = $this->
db->jdate($obj->datec);
843 $this->datem = $this->
db->jdate($obj->datem);
845 $this->note = $obj->note_private;
846 $this->note_private = $obj->note_private;
847 $this->percentage = $obj->percentage;
849 $this->authorid = $obj->fk_user_author;
850 $this->usermodid = $obj->fk_user_mod;
852 if (!is_object($this->author)) {
853 $this->author =
new User($this->
db);
855 $this->author->id = $obj->fk_user_author;
856 $this->author->firstname = $obj->firstname;
857 $this->author->lastname = $obj->lastname;
858 if (!is_object($this->usermod)) {
859 $this->usermod =
new User($this->
db);
861 $this->usermod->id = $obj->fk_user_mod;
863 $this->userownerid = $obj->fk_user_action;
864 $this->priority = $obj->priority;
865 $this->fulldayevent = $obj->fulldayevent;
866 $this->location = $obj->location;
867 $this->transparency = $obj->transparency;
869 $this->socid = $obj->fk_soc;
870 $this->contact_id = $obj->fk_contact;
871 $this->fk_project = $obj->fk_project;
876 $this->fk_element = $obj->elementid;
877 $this->elementid = $obj->elementid;
878 $this->elementtype = $obj->elementtype;
880 $this->num_vote = $obj->num_vote;
881 $this->event_paid = $obj->event_paid;
882 $this->status = $obj->status;
885 $this->email_msgid=$obj->email_msgid;
886 $this->email_from=$obj->email_from;
887 $this->email_sender=$obj->email_sender;
888 $this->email_to=$obj->email_to;
889 $this->email_tocc=$obj->email_tocc;
890 $this->email_tobcc=$obj->email_tobcc;
891 $this->email_subject=$obj->email_subject;
892 $this->errors_to=$obj->errors_to;
896 if ($loadresources) {
903 $this->error = $this->
db->lasterror();
917 $this->userassigned = array();
918 $this->socpeopleassigned = array();
920 $sql =
'SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency';
921 $sql .=
' FROM '.MAIN_DB_PREFIX.
'actioncomm_resources';
922 $sql .=
' WHERE fk_actioncomm = '.((int) $this->
id);
923 $sql .=
" AND element_type IN ('user', 'socpeople')";
927 if ($this->userownerid > 0) {
928 $this->userassigned[$this->userownerid] = array(
'id'=>$this->userownerid);
931 while ($obj = $this->
db->fetch_object(
$resql)) {
932 if ($obj->fk_element > 0) {
933 switch ($obj->element_type) {
935 $this->userassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
'mandatory'=>$obj->mandatory,
'answer_status'=>$obj->answer_status,
'transparency'=>$obj->transparency);
936 if (empty($this->userownerid)) {
937 $this->userownerid = $obj->fk_element;
941 $this->socpeopleassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
'mandatory'=>$obj->mandatory,
'answer_status'=>$obj->answer_status,
'transparency'=>$obj->transparency);
964 $sql =
"SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency";
965 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm_resources";
966 $sql .=
" WHERE element_type = 'user' AND fk_actioncomm = ".((int) $this->
id);
968 $resql2 = $this->
db->query($sql);
970 $this->userassigned = array();
973 if ($this->userownerid > 0) {
975 $this->userassigned[$this->userownerid] = array(
'id'=>$this->userownerid);
978 while ($obj = $this->
db->fetch_object($resql2)) {
979 if ($obj->fk_element > 0) {
980 $this->userassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
981 'mandatory'=>$obj->mandatory,
982 'answer_status'=>$obj->answer_status,
983 'transparency'=>$obj->transparency);
986 if ($override ===
true) {
988 if (empty($this->userownerid)) {
989 $this->userownerid = $obj->fk_element;
1007 public function delete($notrigger = 0)
1013 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1019 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_actioncomm";
1020 $sql .=
" WHERE fk_actioncomm=".((int) $this->
id);
1022 $res = $this->
db->query($sql);
1024 $this->error = $this->
db->lasterror();
1031 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources";
1032 $sql .=
" WHERE fk_actioncomm=".((int) $this->
id);
1034 $res = $this->
db->query($sql);
1036 $this->error = $this->
db->lasterror();
1042 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
1043 $sql .=
" WHERE fk_actioncomm = ".((int) $this->
id);
1045 $res = $this->
db->query($sql);
1047 $this->error = $this->
db->lasterror();
1057 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1063 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm";
1064 $sql .=
" WHERE id=".((int) $this->
id);
1066 $res = $this->
db->query($sql);
1068 $this->error = $this->
db->lasterror();
1084 $this->
db->commit();
1087 $this->
db->rollback();
1091 $this->
db->rollback();
1092 $this->error = $this->
db->lasterror();
1107 global $langs, $conf, $hookmanager;
1112 $this->label = trim($this->label);
1113 $this->note_private =
dol_htmlcleanlastbr(trim(!isset($this->note_private) ? $this->note : $this->note_private));
1114 if (empty($this->percentage)) {
1115 $this->percentage = 0;
1117 if (empty($this->priority) || !is_numeric($this->priority)) {
1118 $this->priority = 0;
1120 if (empty($this->transparency)) {
1121 $this->transparency = 0;
1123 if (empty($this->fulldayevent)) {
1124 $this->fulldayevent = 0;
1126 if ($this->percentage > 100) {
1127 $this->percentage = 100;
1130 if ($this->datep && $this->datef) {
1131 $this->durationp = ($this->datef - $this->datep);
1134 if ($this->datep && $this->datef && $this->datep > $this->datef) {
1135 $this->datef = $this->datep;
1138 if ($this->fk_project < 0) {
1139 $this->fk_project = 0;
1143 if ($this->percentage == 0 && $this->userdoneid > 0) {
1144 $this->error =
"ErrorCantSaveADoneUserWithZeroPercentage";
1148 $socid = (($this->socid > 0) ? $this->socid : 0);
1149 $contactid = (($this->contact_id > 0) ? $this->contact_id : 0);
1150 $userownerid = ($this->userownerid ? $this->userownerid : 0);
1151 $userdoneid = ($this->userdoneid ? $this->userdoneid : 0);
1155 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm ";
1156 $sql .=
" SET percent = '".$this->db->escape($this->percentage).
"'";
1157 if ($this->type_id > 0) {
1158 $sql .=
", fk_action = ".(int) $this->type_id;
1159 if (empty($this->type_code)) {
1161 $result = $cactioncomm->fetch($this->type_id);
1162 if ($result >= 0 && !empty($cactioncomm->code)) {
1163 $this->type_code = $cactioncomm->code;
1167 $sql .=
", code = " . (isset($this->type_code)?
"'".$this->db->escape($this->type_code) .
"'":
"null");
1168 $sql .=
", label = ".($this->label ?
"'".$this->db->escape($this->label).
"'" :
"null");
1169 $sql .=
", datep = ".(strval($this->datep) !=
'' ?
"'".$this->db->idate($this->datep).
"'" :
'null');
1170 $sql .=
", datep2 = ".(strval($this->datef) !=
'' ?
"'".$this->db->idate($this->datef).
"'" :
'null');
1171 $sql .=
", durationp = ".(isset($this->durationp) && $this->durationp >= 0 && $this->durationp !=
'' ?
"'".$this->db->escape($this->durationp).
"'" :
"null");
1172 $sql .=
", note = '".$this->db->escape($this->note_private).
"'";
1173 $sql .=
", fk_project =".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1174 $sql .=
", fk_soc =".($socid > 0 ? ((int) $socid) :
"null");
1175 $sql .=
", fk_contact =".($contactid > 0 ? ((int) $contactid) :
"null");
1176 $sql .=
", priority = '".$this->db->escape($this->priority).
"'";
1177 $sql .=
", fulldayevent = '".$this->db->escape($this->fulldayevent).
"'";
1178 $sql .=
", location = ".($this->location ?
"'".$this->db->escape($this->location).
"'" :
"null");
1179 $sql .=
", transparency = '".$this->db->escape($this->transparency).
"'";
1180 $sql .=
", fk_user_mod = ".((int) $user->id);
1181 $sql .=
", fk_user_action = ".($userownerid > 0 ? ((int) $userownerid) :
"null");
1182 $sql .=
", fk_user_done = ".($userdoneid > 0 ? ((int) $userdoneid) :
"null");
1183 if (!empty($this->fk_element)) {
1184 $sql .=
", fk_element=".($this->fk_element ? ((int) $this->fk_element) :
"null");
1186 if (!empty($this->elementtype)) {
1187 $sql .=
", elementtype=".($this->elementtype ?
"'".$this->db->escape($this->elementtype).
"'" :
"null");
1189 if (!empty($this->num_vote)) {
1190 $sql .=
", num_vote=".($this->num_vote ? (int) $this->num_vote : null);
1192 if (!empty($this->event_paid)) {
1193 $sql .=
", event_paid=".($this->event_paid ? (int) $this->event_paid : 0);
1195 if (!empty($this->status)) {
1196 $sql .=
", status=".($this->status ? (int) $this->status : 0);
1198 $sql .=
" WHERE id=".$this->id;
1200 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1201 if ($this->
db->query($sql)) {
1214 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources where fk_actioncomm = ".((int) $this->
id).
" AND element_type = 'user'";
1217 $already_inserted = array();
1218 foreach ($this->userassigned as $key => $val) {
1219 if (!is_array($val)) {
1220 $val = array(
'id'=>$val);
1222 if (!empty($already_inserted[$val[
'id']]))
continue;
1224 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1225 $sql .=
" VALUES(".((int) $this->
id).
", 'user', ".((int) $val[
'id']).
", ".(empty($val[
'mandatory']) ?
'0' : ((int) $val[
'mandatory'])).
", ".(empty($val[
'transparency']) ?
'0' : ((int) $val[
'transparency'])).
", ".(empty($val[
'answer_status']) ?
'0' : ((int) $val[
'answer_status'])).
")";
1230 $this->errors[] = $this->
db->lasterror();
1232 $already_inserted[$val[
'id']] =
true;
1239 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources where fk_actioncomm = ".((int) $this->
id).
" AND element_type = 'socpeople'";
1242 if (!empty($this->socpeopleassigned)) {
1243 $already_inserted = array();
1244 foreach (array_keys($this->socpeopleassigned) as $key => $val) {
1245 if (!is_array($val)) {
1246 $val = array(
'id'=>$val);
1248 if (!empty($already_inserted[$val[
'id']]))
continue;
1250 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1251 $sql .=
" VALUES(".((int) $this->
id).
", 'socpeople', ".((int) $val[
'id']).
", 0, 0, 0)";
1256 $this->errors[] = $this->
db->lasterror();
1258 $already_inserted[$val[
'id']] =
true;
1264 if (!$error && !$notrigger) {
1274 $this->
db->commit();
1277 $this->
db->rollback();
1278 dol_syslog(get_class($this).
"::update ".join(
',', $this->errors), LOG_ERR);
1282 $this->
db->rollback();
1283 $this->error = $this->
db->lasterror();
1301 public function getActions($socid = 0, $fk_element = 0, $elementtype =
'', $filter =
'', $sortfield =
'a.datep', $sortorder =
'DESC', $limit = 0)
1303 global $conf, $langs;
1305 $resarray = array();
1307 dol_syslog(get_class().
"::getActions", LOG_DEBUG);
1309 $sql =
"SELECT a.id";
1310 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
1311 $sql .=
" WHERE a.entity IN (".getEntity(
'agenda').
")";
1312 if (!empty($socid)) {
1313 $sql .=
" AND a.fk_soc = ".((int) $socid);
1315 if (!empty($elementtype)) {
1316 if ($elementtype ==
'project') {
1317 $sql .=
' AND a.fk_project = '.((int) $fk_element);
1318 } elseif ($elementtype ==
'contact') {
1319 $sql .=
' AND a.id IN';
1320 $sql .=
" (SELECT fk_actioncomm FROM ".MAIN_DB_PREFIX.
"actioncomm_resources WHERE";
1321 $sql .=
" element_type = 'socpeople' AND fk_element = ".((int) $fk_element).
')';
1323 $sql .=
" AND a.fk_element = ".((int) $fk_element).
" AND a.elementtype = '".$this->
db->escape($elementtype).
"'";
1326 if (!empty($filter)) {
1329 if ($sortorder && $sortfield) {
1330 $sql .= $this->
db->order($sortfield, $sortorder);
1332 $sql .= $this->
db->plimit($limit, 0);
1336 $num = $this->
db->num_rows(
$resql);
1339 for ($i = 0; $i < $num; $i++) {
1340 $obj = $this->
db->fetch_object(
$resql);
1342 $actioncommstatic->fetch($obj->id);
1343 $resarray[$i] = $actioncommstatic;
1349 return $this->
db->lasterror();
1364 global $conf, $langs;
1366 if (empty($load_state_board)) {
1367 $sql =
"SELECT a.id, a.datep as dp";
1369 $this->nb = array();
1370 $sql =
"SELECT count(a.id) as nb";
1372 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
1373 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1374 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
1376 if (empty($user->rights->agenda->allactions->read)) {
1377 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"actioncomm_resources AS ar ON a.id = ar.fk_actioncomm AND ar.element_type ='user' AND ar.fk_element = ".((int) $user->id);
1379 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON a.fk_soc = s.rowid";
1380 $sql .=
" WHERE 1 = 1";
1381 if (empty($load_state_board)) {
1382 $sql .=
" AND a.percent >= 0 AND a.percent < 100";
1384 $sql .=
" AND a.entity IN (".getEntity(
'agenda').
")";
1385 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1386 $sql .=
" AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).
")";
1389 $sql .=
" AND a.fk_soc = ".((int) $user->socid);
1391 if (empty($user->rights->agenda->allactions->read)) {
1392 $sql .=
" AND (a.fk_user_author = ".((int) $user->id).
" OR a.fk_user_action = ".((int) $user->id).
" OR a.fk_user_done = ".((int) $user->id);
1393 $sql .=
" OR ar.fk_element = ".((int) $user->id);
1399 if (empty($load_state_board)) {
1402 $response->warning_delay = $conf->agenda->warning_delay / 60 / 60 / 24;
1403 $response->label = $langs->trans(
"ActionsToDo");
1404 $response->labelShort = $langs->trans(
"ActionsToDoShort");
1405 $response->url = DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&actioncode=0&status=todo&mainmenu=agenda';
1406 if ($user->rights->agenda->allactions->read) {
1407 $response->url .=
'&filtert=-1';
1409 $response->img =
img_object(
'',
"action",
'class="inline-block valigntextmiddle"');
1412 while ($obj = $this->
db->fetch_object(
$resql)) {
1413 if (empty($load_state_board)) {
1414 $response->nbtodo++;
1415 $agenda_static->datep = $this->
db->jdate($obj->dp);
1416 if ($agenda_static->hasDelay()) {
1417 $response->nbtodolate++;
1420 $this->nb[
"actionscomm"] = $obj->nb;
1425 if (empty($load_state_board)) {
1432 $this->error = $this->
db->error();
1449 $sql .=
' tms as datem,';
1450 $sql .=
' fk_user_author,';
1451 $sql .=
' fk_user_mod';
1452 $sql .=
' FROM '.MAIN_DB_PREFIX.
'actioncomm as a';
1453 $sql .=
' WHERE a.id = '.((int) $id);
1455 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
1456 $result = $this->
db->query($sql);
1458 if ($this->
db->num_rows($result)) {
1459 $obj = $this->
db->fetch_object($result);
1460 $this->
id = $obj->id;
1461 $this->user_creation_id = $obj->fk_user_author;
1462 $this->user_modification_id = $obj->fk_user_mod;
1463 $this->date_creation = $this->
db->jdate($obj->datec);
1464 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
1466 $this->
db->free($result);
1482 return $this->
LibStatut($this->percentage, $mode, $hidenastatus, $this->datep);
1495 public function LibStatut($percent, $mode, $hidenastatus = 0, $datestart =
'')
1500 $labelStatus = $langs->transnoentitiesnoconv(
'StatusNotApplicable');
1501 if ($percent == -1 && !$hidenastatus) {
1502 $labelStatus = $langs->transnoentitiesnoconv(
'StatusNotApplicable');
1503 } elseif ($percent == 0) {
1504 $labelStatus = $langs->transnoentitiesnoconv(
'StatusActionToDo').
' (0%)';
1505 } elseif ($percent > 0 && $percent < 100) {
1506 $labelStatus = $langs->transnoentitiesnoconv(
'StatusActionInProcess').
' ('.$percent.
'%)';
1507 } elseif ($percent >= 100) {
1508 $labelStatus = $langs->transnoentitiesnoconv(
'StatusActionDone').
' (100%)';
1511 $labelStatusShort = $langs->transnoentitiesnoconv(
'StatusNotApplicable');
1512 if ($percent == -1 && !$hidenastatus) {
1513 $labelStatusShort = $langs->trans(
'NA');
1514 } elseif ($percent == 0) {
1515 $labelStatusShort =
'0%';
1516 } elseif ($percent > 0 && $percent < 100) {
1517 $labelStatusShort = $percent.
'%';
1518 } elseif ($percent >= 100) {
1519 $labelStatusShort =
'100%';
1522 $statusType =
'status9';
1523 if ($percent == -1 && !$hidenastatus) {
1524 $statusType =
'status9';
1526 if ($percent == 0) {
1527 $statusType =
'status1';
1529 if ($percent > 0 && $percent < 100) {
1530 $statusType =
'status3';
1532 if ($percent >= 100) {
1533 $statusType =
'status6';
1536 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1552 public function getNomUrl($withpicto = 0, $maxlength = 0, $classname =
'', $option =
'', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
1554 global $conf, $langs, $user, $hookmanager, $action;
1556 if (!empty($conf->dol_no_mouse_hover)) {
1561 if ($user->rights->agenda->myactions->read && $this->authorid == $user->id) {
1564 if ($user->rights->agenda->myactions->read && array_key_exists($user->id, $this->userassigned)) {
1567 if ($user->rights->agenda->allactions->read) {
1574 $label = $this->label;
1575 if (empty($label)) {
1576 $label = $this->libelle;
1583 if ($this->type_code) {
1584 $labeltype = ($langs->transnoentities(
"Action".$this->type_code) !=
"Action".$this->type_code) ? $langs->transnoentities(
"Action".$this->type_code) : $this->type_label;
1586 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1587 if ($this->type_code !=
'AC_OTH_AUTO') {
1588 $labeltype = $langs->trans(
'ActionAC_MANUAL');
1592 $tooltip =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
'Action').
'</u>';
1593 if (!empty($this->
ref)) {
1594 $tooltip .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1596 if (!empty($label)) {
1597 $tooltip .=
'<br><b>'.$langs->trans(
'Title').
':</b> '.$label;
1599 if (!empty($labeltype)) {
1600 $tooltip .=
'<br><b>'.$langs->trans(
'Type').
':</b> '.$labeltype;
1602 if (!empty($this->location)) {
1603 $tooltip .=
'<br><b>'.$langs->trans(
'Location').
':</b> '.$this->location;
1605 if (isset($this->transparency)) {
1606 $tooltip .=
'<br><b>'.$langs->trans(
'Busy').
':</b> '.
yn($this->transparency);
1608 if (!empty($this->email_msgid)) {
1609 $langs->load(
"mails");
1612 $tooltip .=
'<br><b>'.$langs->trans(
'MailTopic').
':</b> '.$this->email_subject;
1613 $tooltip .=
'<br><b>'.$langs->trans(
'MailFrom').
':</b> '.str_replace(array(
'<',
'>'), array(
'&lt',
'&gt'), $this->email_from);
1614 $tooltip .=
'<br><b>'.$langs->trans(
'MailTo').
':</b> '.str_replace(array(
'<',
'>'), array(
'&lt',
'&gt'), $this->email_to);
1615 if (!empty($this->email_tocc)) {
1616 $tooltip .=
'<br><b>'.$langs->trans(
'MailCC').
':</b> '.str_replace(array(
'<',
'>'), array(
'&lt',
'&gt'), $this->email_tocc);
1623 if (!empty($this->note_private)) {
1624 $tooltip .=
'<br><br><b>'.$langs->trans(
'Description').
':</b><br>';
1626 $tooltip .= (
dol_textishtml($texttoshow) ? str_replace(array(
"\r",
"\n"),
"", $texttoshow) : str_replace(array(
"\r",
"\n"),
'<br>', $texttoshow));
1632 if (empty($notooltip)) {
1633 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1634 $label = $langs->trans(
"ShowAction");
1635 $linkclose .=
' alt="'.dol_escape_htmltag($tooltip, 1).
'"';
1637 $linkclose .=
' title="'.dol_escape_htmltag($tooltip, 1, 0,
'', 1).
'"';
1638 $linkclose .=
' class="'.$classname.
' classfortooltip"';
1640 $linkclose .=
' class="'.$classname.
'"';
1644 if ($option ==
'birthday') {
1645 $url = DOL_URL_ROOT.
'/contact/perso.php?id='.$this->id;
1646 } elseif ($option ==
'holiday') {
1647 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1649 $url = DOL_URL_ROOT.
'/comm/action/card.php?id='.$this->id;
1652 if ($option !==
'nolink') {
1654 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1655 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1656 $add_save_lastsearch_values = 1;
1658 if ($add_save_lastsearch_values) {
1659 $url .=
'&save_lastsearch_values=1';
1663 $linkstart =
'<a href="'.$url.
'"';
1664 $linkstart .= $linkclose.
'>';
1667 if ($option ==
'nolink') {
1672 if ($withpicto == 2) {
1673 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1674 $label = $labeltype;
1678 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($label)) {
1679 $label = $labeltype;
1681 if ($maxlength < 0) {
1682 $labelshort = $this->ref;
1684 $labelshort =
dol_trunc($label, $maxlength);
1689 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1691 $label .= (preg_match(
'/'.preg_quote($labeltype,
'/').
'/', $label) ?
'' :
' ('.$langs->transnoentities(
"Action".$this->type_code).
')');
1696 $result .= $linkstart;
1698 $result .=
img_object(($notooltip ?
'' : $langs->trans(
"ShowAction").
': '.$label), ($overwritepicto ? $overwritepicto :
'action'), (($this->type_color && $overwritepicto) ?
'style="color: #'.$this->type_color.
' !important;" ' :
'').($notooltip ?
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"' :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1700 $result .= $labelshort;
1701 $result .= $linkend;
1704 $hookmanager->initHooks(array(
'actiondao'));
1705 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1706 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1708 $result = $hookmanager->resPrint;
1710 $result .= $hookmanager->resPrint;
1726 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1728 if ($this->type_color) {
1729 $color =
'style="color: #'.$this->type_color.
' !important;"';
1731 if ($this->type_picto) {
1732 $imgpicto =
img_picto(
'', $this->type_picto,
'class="paddingright"');
1734 if ($this->type_code ==
'AC_RDV') {
1735 $imgpicto =
img_picto(
'',
'meeting', $color,
false, 0, 0,
'',
'paddingright');
1736 } elseif ($this->type_code ==
'AC_TEL') {
1737 $imgpicto =
img_picto(
'',
'object_phoning', $color,
false, 0, 0,
'',
'paddingright');
1738 } elseif ($this->type_code ==
'AC_FAX') {
1739 $imgpicto =
img_picto(
'',
'object_phoning_fax', $color,
false, 0, 0,
'',
'paddingright');
1740 } elseif ($this->type_code ==
'AC_EMAIL' || $this->type_code ==
'AC_EMAIL_IN') {
1741 $imgpicto =
img_picto(
'',
'object_email', $color,
false, 0, 0,
'',
'paddingright');
1742 } elseif ($this->type_code ==
'AC_INT') {
1743 $imgpicto =
img_picto(
'',
'object_intervention', $color,
false, 0, 0,
'',
'paddingright');
1744 } elseif ($this->type_code ==
'AC_OTH' && $this->
code ==
'TICKET_MSG') {
1745 $imgpicto =
img_picto(
'',
'object_conversation', $color,
false, 0, 0,
'',
'paddingright');
1746 } elseif ($this->
type !=
'systemauto') {
1747 $imgpicto =
img_picto(
'',
'user-cog', $color,
false, 0, 0,
'',
'paddingright');
1749 $imgpicto =
img_picto(
'',
'cog', $color,
false, 0, 0,
'',
'paddingright');
1754 if ($this->
type !=
'systemauto') {
1755 $imgpicto =
img_picto(
'',
'user-cog',
'',
false, 0, 0,
'',
'paddingright');
1757 $imgpicto =
img_picto(
'',
'cog',
'',
false, 0, 0,
'',
'paddingright');
1777 if (!is_array($categories)) {
1778 $categories = array($categories);
1782 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1784 $existing = $c->containing($this->
id, Categorie::TYPE_ACTIONCOMM,
'id');
1787 if (is_array($existing)) {
1788 $to_del = array_diff($existing, $categories);
1789 $to_add = array_diff($categories, $existing);
1792 $to_add = $categories;
1796 foreach ($to_del as $del) {
1797 if ($c->fetch($del) > 0) {
1798 $c->del_type($this, Categorie::TYPE_ACTIONCOMM);
1801 foreach ($to_add as $add) {
1802 if ($c->fetch($add) > 0) {
1803 $c->add_type($this, Categorie::TYPE_ACTIONCOMM);
1821 public function build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday = 0)
1823 global $hookmanager;
1826 global $conf, $langs, $dolibarr_main_url_root, $mysoc;
1828 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
1829 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
1830 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
1832 dol_syslog(get_class($this).
"::build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
1835 if (empty($format)) {
1842 if ($format ==
'ical') {
1845 $filename = $format.
'.'.$extension;
1849 $result =
dol_mkdir($conf->agenda->dir_temp);
1850 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
1855 $login =
''; $logina =
''; $logind =
''; $logint =
'';
1861 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1863 dol_syslog(get_class($this).
"::build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
1870 $eventarray = array();
1872 $sql =
"SELECT a.id,";
1873 $sql .=
" a.datep,";
1874 $sql .=
" a.datep2,";
1875 $sql .=
" a.durationp,";
1876 $sql .=
" a.datec, a.tms as datem,";
1877 $sql .=
" a.label, a.code, a.note as note_private, a.fk_action as type_id,";
1878 $sql .=
" a.fk_soc,";
1879 $sql .=
" a.fk_user_author, a.fk_user_mod,";
1880 $sql .=
" a.fk_user_action,";
1881 $sql .=
" a.fk_contact, a.percent as percentage,";
1882 $sql .=
" a.fk_element, a.elementtype,";
1883 $sql .=
" a.priority, a.fulldayevent, a.location, a.transparency,";
1884 $sql .=
" u.firstname, u.lastname, u.email,";
1885 $sql .=
" s.nom as socname,";
1886 $sql .=
" c.id as type_id, c.code as type_code, c.libelle as type_label,";
1887 $sql .=
" num_vote, event_paid, a.status";
1888 $sql .=
" FROM (".MAIN_DB_PREFIX.
"c_actioncomm as c, ".MAIN_DB_PREFIX.
"actioncomm as a)";
1889 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = a.fk_user_author";
1890 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = a.fk_soc";
1892 $parameters = array(
'filters' => $filters);
1893 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
1894 $sql .= $hookmanager->resPrint;
1897 if ($filters[
'logint']) {
1898 $sql .=
", ".MAIN_DB_PREFIX.
"actioncomm_resources as ar";
1900 $sql .=
" WHERE a.fk_action=c.id";
1901 $sql .=
" AND a.entity IN (".getEntity(
'agenda').
")";
1902 foreach ($filters as $key => $value) {
1903 if ($key ==
'notolderthan' && $value !=
'') {
1904 $sql .=
" AND a.datep >= '".$this->db->idate($now - ($value * 24 * 60 * 60)).
"'";
1906 if ($key ==
'year') {
1910 $sql .=
" AND a.id=".(is_numeric($value) ? $value : 0);
1912 if ($key ==
'idfrom') {
1913 $sql .=
" AND a.id >= ".(is_numeric($value) ? $value : 0);
1915 if ($key ==
'idto') {
1916 $sql .=
" AND a.id <= ".(is_numeric($value) ? $value : 0);
1918 if ($key ==
'project') {
1919 $sql .=
" AND a.fk_project=".(is_numeric($value) ? $value : 0);
1921 if ($key ==
'actiontype') {
1922 $sql .=
" AND c.type = '".$this->db->escape($value).
"'";
1924 if ($key ==
'notactiontype') {
1925 $sql .=
" AND c.type <> '".$this->db->escape($value).
"'";
1928 if ($key ==
'logint') {
1929 $sql .=
" AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
1931 if ($key ==
'logina') {
1934 if (preg_match(
'/^!/', $logina)) {
1935 $logina = preg_replace(
'/^!/',
'', $logina);
1938 $userforfilter =
new User($this->
db);
1939 $result = $userforfilter->fetch(
'', $logina);
1941 $sql .=
" AND a.fk_user_author ".$condition.
" ".$userforfilter->id;
1942 } elseif ($result < 0 || $condition ==
'=') {
1943 $sql .=
" AND a.fk_user_author = 0";
1946 if ($key ==
'logint') {
1949 if (preg_match(
'/^!/', $logint)) {
1950 $logint = preg_replace(
'/^!/',
'', $logint);
1953 $userforfilter =
new User($this->
db);
1954 $result = $userforfilter->fetch(
'', $logint);
1956 $sql .=
" AND ar.fk_element = ".((int) $userforfilter->id);
1957 } elseif ($result < 0 || $condition ==
'=') {
1958 $sql .=
" AND ar.fk_element = 0";
1961 if ($key ==
'module') {
1962 $sql .=
" AND c.module LIKE '%".$this->db->escape($value).
"'";
1964 if ($key ==
'status') {
1965 $sql .=
" AND a.status =".((int) $value);
1969 $sql .=
" AND a.datep IS NOT NULL";
1971 $parameters = array(
'filters' => $filters);
1972 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
1973 $sql .= $hookmanager->resPrint;
1975 $sql .=
" ORDER by datep";
1978 dol_syslog(get_class($this).
"::build_exportfile select events", LOG_DEBUG);
1984 while ($obj = $this->
db->fetch_object(
$resql)) {
1989 $event[
'uid'] =
'dolibarragenda-'.$this->db->database_name.
'-'.$obj->id.
"@".$_SERVER[
"SERVER_NAME"];
1990 $event[
'type'] = $type;
1992 $datestart = $this->
db->jdate($obj->datep) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
1995 if (is_numeric($this->
db->jdate($obj->datep2))) {
1996 $dateend = $this->
db->jdate($obj->datep2) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
1999 $dateend = $datestart;
2002 $duration = ($datestart && $dateend) ? ($dateend - $datestart) : 0;
2003 $event[
'summary'] = $obj->label.($obj->socname ?
" (".$obj->socname.
")" :
"");
2005 $event[
'desc'] = $obj->note_private;
2006 $event[
'startdate'] = $datestart;
2007 $event[
'enddate'] = $dateend;
2008 $event[
'duration'] = $duration;
2010 $event[
'priority'] = $obj->priority;
2011 $event[
'fulldayevent'] = $obj->fulldayevent;
2012 $event[
'location'] = $obj->location;
2013 $event[
'transparency'] = (($obj->transparency > 0) ?
'OPAQUE' :
'TRANSPARENT');
2014 $event[
'category'] = $obj->type_label;
2015 $event[
'email'] = $obj->email;
2017 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2018 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2020 $url = $urlwithroot.
'/comm/action/card.php?id='.$obj->id;
2021 $event[
'url'] = $url;
2022 $event[
'created'] = $this->
db->jdate($obj->datec) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2023 $event[
'modified'] = $this->
db->jdate($obj->datem) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2024 $event[
'num_vote'] = $this->num_vote;
2025 $event[
'event_paid'] = $this->event_paid;
2026 $event[
'status'] = $this->status;
2029 $this->
id = $obj->id;
2032 $assignedUserArray = array();
2034 foreach ($this->userassigned as $key => $value) {
2035 $assignedUser =
new User($this->
db);
2036 $assignedUser->fetch($value[
'id']);
2038 $assignedUserArray[$key] = $assignedUser;
2041 $event[
'assignedUsers'] = $assignedUserArray;
2043 if ($qualified && $datestart) {
2044 $eventarray[] = $event;
2049 $parameters = array(
'filters' => $filters,
'eventarray' => &$eventarray);
2050 $reshook = $hookmanager->executeHooks(
'addMoreEventsExport', $parameters);
2052 $eventarray = $hookmanager->resArray;
2055 $this->error = $this->
db->lasterror();
2059 if ($exportholiday == 1) {
2060 $langs->load(
"holidays");
2061 $title = $langs->trans(
"Holidays");
2063 $sql =
"SELECT u.rowid as uid, u.lastname, u.firstname, u.email, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status";
2064 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as x, ".MAIN_DB_PREFIX.
"user as u";
2065 $sql .=
" WHERE u.rowid = x.fk_user";
2066 $sql .=
" AND u.statut = '1'";
2067 $sql .=
" AND (x.statut = '2' OR x.statut = '3')";
2071 $num = $this->
db->num_rows(
$resql);
2075 $obj = $this->
db->fetch_object(
$resql);
2078 if ($obj->halfday == -1) {
2079 $event[
'fulldayevent'] =
false;
2083 } elseif ($obj->halfday == 1) {
2084 $event[
'fulldayevent'] =
false;
2089 $event[
'fulldayevent'] =
true;
2095 if (!empty($conf->global->AGENDA_EXPORT_FIX_TZ)) {
2096 $timestampStart = $timestampStart - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2097 $timestampEnd = $timestampEnd - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2100 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2101 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2102 $url = $urlwithroot.
'/holiday/card.php?id='.$obj->rowid;
2104 $event[
'uid'] =
'dolibarrholiday-'.$this->db->database_name.
'-'.$obj->rowid.
"@".$_SERVER[
"SERVER_NAME"];
2106 $event[
'type'] =
'event';
2107 $event[
'category'] =
"Holiday";
2108 $event[
'transparency'] =
'OPAQUE';
2109 $event[
'email'] = $obj->email;
2110 $event[
'created'] = $timestampStart;
2111 $event[
'modified'] = $timestampStart;
2112 $event[
'startdate'] = $timestampStart;
2113 $event[
'enddate'] = $timestampEnd;
2114 $event[
'duration'] = $timestampEnd - $timestampStart;
2115 $event[
'url'] = $url;
2117 if ($obj->status == 2) {
2119 $event[
'summary'] = $title.
" - ".$obj->lastname.
" (wait for approval)";
2122 $event[
'summary'] = $title.
" - ".$obj->lastname;
2125 $eventarray[] = $event;
2132 $langs->load(
"agenda");
2137 $more = $langs->transnoentities(
"User").
' '.$login;
2140 $more = $langs->transnoentities(
"ActionsAskedBy").
' '.$logina;
2143 $more = $langs->transnoentities(
"ActionsToDoBy").
' '.$logint;
2146 $more = $langs->transnoentities(
"ActionsDoneBy").
' '.$logind;
2149 $title =
'Dolibarr actions '.$mysoc->name.
' - '.$more;
2151 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
2153 $title =
'Dolibarr actions '.$mysoc->name;
2154 $desc = $langs->transnoentities(
'ListOfActions');
2155 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
2159 $outputfiletmp = tempnam($conf->agenda->dir_temp,
'tmp');
2160 @chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
2163 if ($format ==
'vcal') {
2164 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2165 } elseif ($format ==
'ical') {
2166 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2167 } elseif ($format ==
'rss') {
2168 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
2172 if (
dol_move($outputfiletmp, $outputfile, 0, 1)) {
2175 $this->error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
2176 dol_syslog(get_class($this).
"::build_exportfile ".$this->error, LOG_ERR);
2181 dol_syslog(get_class($this).
"::build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
2183 $langs->load(
"errors");
2184 $this->error = $langs->trans(
"ErrorFailToCreateFile", $outputfile);
2206 $this->specimen = 1;
2208 $this->type_code =
'AC_OTH';
2209 $this->
code =
'AC_SPECIMEN_CODE';
2210 $this->label =
'Label of event Specimen';
2211 $this->datec = $now;
2212 $this->datem = $now;
2213 $this->datep = $now;
2214 $this->datef = $now;
2215 $this->fulldayevent = 0;
2216 $this->percentage = 0;
2218 $this->location =
'Location';
2219 $this->transparency = 1;
2220 $this->priority = 1;
2222 $this->note_private =
"This is a 'private' note.";
2224 $this->userownerid = $user->id;
2225 $this->userassigned[$user->id] = array(
'id'=>$user->id,
'transparency'=> 1);
2256 $sql =
'UPDATE ' . MAIN_DB_PREFIX .
'actioncomm SET fk_element = ' . ((int) $dest_id) .
' WHERE elementtype="product" AND fk_element = '.((int) $origin_id);
2258 if (!$dbs->
query($sql)) {
2277 return $this->datep && ($this->datep < ($now - $conf->agenda->warning_delay));
2291 global $conf, $langs, $user;
2295 $this->reminders = array();
2298 $sql =
"SELECT rowid as id, typeremind, dateremind, status, offsetvalue, offsetunit, fk_user";
2299 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2300 $sql .=
" WHERE fk_actioncomm = ".((int) $this->
id);
2302 $sql .=
" AND dateremind <= '".$this->db->idate(
dol_now()).
"'";
2305 $sql .=
" AND typeremind ='".$this->db->escape($type).
"'";
2308 $sql .=
" AND fk_user = ".((int) $fk_user);
2310 if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2311 $sql .=
" AND typeremind != 'email'";
2313 if (empty($conf->global->AGENDA_REMINDER_BROWSER)) {
2314 $sql .=
" AND typeremind != 'browser'";
2317 $sql .= $this->
db->order(
"dateremind",
"ASC");
2321 while ($obj = $this->
db->fetch_object(
$resql)) {
2323 $tmpactioncommreminder->id = $obj->id;
2324 $tmpactioncommreminder->typeremind = $obj->typeremind;
2325 $tmpactioncommreminder->dateremind = $obj->dateremind;
2326 $tmpactioncommreminder->offsetvalue = $obj->offsetvalue;
2327 $tmpactioncommreminder->offsetunit = $obj->offsetunit;
2328 $tmpactioncommreminder->status = $obj->status;
2329 $tmpactioncommreminder->fk_user = $obj->fk_user;
2331 $this->reminders[$obj->id] = $tmpactioncommreminder;
2334 $this->error = $this->
db->lasterror();
2338 return count($this->reminders);
2350 global $conf, $langs, $user;
2356 $errorsMsg = array();
2358 if (empty($conf->agenda->enabled)) {
2359 $langs->load(
"agenda");
2360 $this->output = $langs->trans(
'ModuleNotEnabled', $langs->transnoentitiesnoconv(
"Agenda"));
2363 if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2364 $langs->load(
"agenda");
2365 $this->output = $langs->trans(
'EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv(
"Agenda"));
2377 $sql =
"SELECT rowid as id FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2378 $sql .=
" WHERE typeremind = 'email' AND status = 0";
2379 $sql .=
" AND dateremind <= '".$this->db->idate($now).
"'";
2380 $sql .=
" AND entity IN (".getEntity(
'actioncomm').
")";
2381 $sql .= $this->
db->order(
"dateremind",
"ASC");
2385 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2388 while ($obj = $this->
db->fetch_object(
$resql)) {
2389 $res = $actionCommReminder->fetch($obj->id);
2392 $errorsMsg[] =
"Failed to load invoice ActionComm Reminder";
2397 $arraymessage = $formmail->getEMailTemplate($this->
db,
'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1);
2400 $res = $this->
fetch($actionCommReminder->fk_actioncomm);
2411 $sendContent =
make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
2414 $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->transnoentities(
'EventReminder'));
2417 $recipient =
new User($this->
db);
2418 $res = $recipient->fetch($actionCommReminder->fk_user);
2420 if (!empty($recipient->email)) {
2421 $to = $recipient->email;
2423 $errormesg =
"Failed to send remind to user id=".$actionCommReminder->fk_user.
". No email defined for user.";
2427 $errormesg =
"Failed to load recipient with user id=".$actionCommReminder->fk_user;
2432 $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
2434 $errormesg =
"Failed to get sender into global setup MAIN_MAIL_EMAIL_FROM";
2440 $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO;
2443 $cMailFile =
new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(),
'',
"", 0, 1, $errors_to,
'',
'',
'',
'',
'');
2446 if ($cMailFile->sendfile()) {
2449 $errormesg = $cMailFile->error.
' : '.$to;
2455 $actionCommReminder->status = $actionCommReminder::STATUS_DONE;
2457 $res = $actionCommReminder->update($user);
2459 $errorsMsg[] =
"Failed to update status to done of ActionComm Reminder";
2464 $actionCommReminder->status = $actionCommReminder::STATUS_ERROR;
2465 $actionCommReminder->lasterror =
dol_trunc($errormesg, 128,
'right',
'UTF-8', 1);
2467 $res = $actionCommReminder->update($user);
2469 $errorsMsg[] =
"Failed to update status to error of ActionComm Reminder";
2473 $errorsMsg[] = $errormesg;
2477 $errorsMsg[] =
'Failed to fetch record actioncomm with ID = '.$actionCommReminder->fk_actioncomm;
2488 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2489 $sql .=
" WHERE dateremind < '".$this->db->idate($now - (3600 * 24 * 32)).
"'";
2490 $sql .=
" AND status = ".((int) $actionCommReminder::STATUS_DONE);
2494 $errorsMsg[] =
'Failed to delete old reminders';
2500 $this->output =
'Nb of emails sent : '.$nbMailSend;
2501 $this->
db->commit();
2504 $this->
db->commit();
2505 $this->error =
'Nb of emails sent : '.$nbMailSend.
', '.(!empty($errorsMsg)) ? join(
', ', $errorsMsg) : $error;
2522 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm ";
2523 $sql .=
" SET percent = ".(int) $percent;
2524 if ($usermodid > 0) $sql .=
", fk_user_mod = ".$usermodid;
2525 $sql .=
" WHERE id = ".((int) $id);
2527 if ($this->
db->query($sql)) {
2528 $this->
db->commit();
2531 $this->
db->rollback();
2532 $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.
updatePercent($id, $percent, $usermodid=0)
Udpate the percent value of a event with the given id.
Class for ActionCommReminder.
dol_mkdir($dir, $dataroot= '', $newmask= '')
Creation of a directory (this can create recursive subdir)
loadReminders($type= '', $fk_user=0, $onlypast=true)
Load event reminder of events.
Class to manage agenda events (actions)
$conf db
API class for accounts.
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
LibStatut($percent, $mode, $hidenastatus=0, $datestart= '')
Return label of action status.
const EVENT_FINISHED
Typical value for a event that is in a finished state.
dol_now($mode= 'auto')
Return date for now.
create(User $user, $notrigger=0)
Add an action/event into database.
fetchResources()
Initialize $this->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...
getActions($socid=0, $fk_element=0, $elementtype= '', $filter= '', $sortfield= 'a.datep', $sortorder= 'DESC', $limit=0)
Load all objects with filters.
update(User $user, $notrigger=0)
Update action into database If percentage = 100, on met a jour date 100%.
createFromClone(User $fuser, $socid)
Load an object from its id and create a new one in database.
build_calfile($format, $title, $desc, $events_array, $outputfile)
Build a file from an array of events All input params and data must be encoded in $conf->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.
__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.
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter= '', $url= '', $langcode= '')
Build a file from an array of events.
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge, other ! Closing when no payment: replaced, abandoned
fetch($id, $ref= '', $ref_ext= '', $email_msgid= '', $loadresources=1)
Load object from database.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->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.
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?
$recurid
Properties to manage the recurring events.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dolGetFirstLineOfText($text, $nboflines=1, $charset= 'UTF-8')
Return first line of text.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
call_trigger($triggerName, $user)
Call trigger based on this instance.
dol_filemtime($pathoffile)
Return time of a file.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc= 'right', $stringencoding= 'UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length. ...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
query($query, $usesavepoint=0, $type= 'auto', $result_mode=0)
Execute a SQL request and return the resultset.
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
getLibStatut($mode, $hidenastatus=0)
Return the label of the status.
getTypePicto()
Return Picto of type of event.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
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.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "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.