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);
734 $this->errors += $hookmanager->errors;
735 $this->error = $hookmanager->error;
748 unset($this->context[
'createfromclone']);
755 $this->
db->rollback();
770 public function fetch($id, $ref =
'', $ref_ext =
'', $email_msgid =
'', $loadresources = 1)
774 if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) {
775 dol_syslog(get_class($this).
"::fetch Bad parameters", LOG_WARNING);
779 $sql =
"SELECT a.id,";
780 $sql .=
" a.ref as ref,";
781 $sql .=
" a.entity,";
782 $sql .=
" a.ref_ext,";
784 $sql .=
" a.datep2,";
785 $sql .=
" a.durationp,";
787 $sql .=
" a.tms as datem,";
788 $sql .=
" a.code, a.label, a.note as note_private,";
789 $sql .=
" a.fk_soc,";
790 $sql .=
" a.fk_project,";
791 $sql .=
" a.fk_user_author, a.fk_user_mod,";
792 $sql .=
" a.fk_user_action, a.fk_user_done,";
793 $sql .=
" a.fk_contact, a.percent as percentage,";
794 $sql .=
" a.fk_element as elementid, a.elementtype,";
795 $sql .=
" a.priority, a.fulldayevent, a.location, a.transparency,";
796 $sql .=
" a.email_msgid, a.email_subject, a.email_from, a.email_sender, a.email_to, a.email_tocc, a.email_tobcc, a.errors_to,";
797 $sql .=
" c.id as type_id, c.type as type_type, c.code as type_code, c.libelle as type_label, c.color as type_color, c.picto as type_picto,";
798 $sql .=
" s.nom as socname,";
799 $sql .=
" u.firstname, u.lastname as lastname,";
800 $sql .=
" num_vote, event_paid, a.status";
801 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a ";
802 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_actioncomm as c ON a.fk_action=c.id ";
803 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = a.fk_user_author";
804 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = a.fk_soc";
807 $sql .=
" a.ref = '".$this->db->escape($ref).
"'";
808 } elseif ($ref_ext) {
809 $sql .=
" a.ref_ext = '".$this->db->escape($ref_ext).
"'";
810 } elseif ($email_msgid) {
811 $sql .=
" a.email_msgid = '".$this->db->escape($email_msgid).
"'";
813 $sql .=
" a.id = ".((int) $id);
816 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
821 $obj = $this->
db->fetch_object(
$resql);
823 $this->
id = $obj->id;
824 $this->entity = $obj->entity;
825 $this->
ref = $obj->ref;
826 $this->ref_ext = $obj->ref_ext;
829 $this->type_id = $obj->type_id;
830 $this->type_code = $obj->type_code;
831 $this->type_color = $obj->type_color;
832 $this->type_picto = $obj->type_picto;
833 $this->
type = $obj->type_type;
836 $transcode = $langs->trans(
"Action".$obj->type_code.
'Short');
837 $this->type_short = (($transcode !=
"Action".$obj->type_code.
'Short') ? $transcode :
'');
839 $this->
code = $obj->code;
840 $this->label = $obj->label;
841 $this->datep = $this->
db->jdate($obj->datep);
842 $this->datef = $this->
db->jdate($obj->datep2);
844 $this->datec = $this->
db->jdate($obj->datec);
845 $this->datem = $this->
db->jdate($obj->datem);
847 $this->note = $obj->note_private;
848 $this->note_private = $obj->note_private;
849 $this->percentage = $obj->percentage;
851 $this->authorid = $obj->fk_user_author;
852 $this->usermodid = $obj->fk_user_mod;
854 if (!is_object($this->author)) {
855 $this->author =
new User($this->
db);
857 $this->author->id = $obj->fk_user_author;
858 $this->author->firstname = $obj->firstname;
859 $this->author->lastname = $obj->lastname;
860 if (!is_object($this->usermod)) {
861 $this->usermod =
new User($this->
db);
863 $this->usermod->id = $obj->fk_user_mod;
865 $this->userownerid = $obj->fk_user_action;
866 $this->priority = $obj->priority;
867 $this->fulldayevent = $obj->fulldayevent;
868 $this->location = $obj->location;
869 $this->transparency = $obj->transparency;
871 $this->socid = $obj->fk_soc;
872 $this->contact_id = $obj->fk_contact;
873 $this->fk_project = $obj->fk_project;
878 $this->fk_element = $obj->elementid;
879 $this->elementid = $obj->elementid;
880 $this->elementtype = $obj->elementtype;
882 $this->num_vote = $obj->num_vote;
883 $this->event_paid = $obj->event_paid;
884 $this->status = $obj->status;
887 $this->email_msgid=$obj->email_msgid;
888 $this->email_from=$obj->email_from;
889 $this->email_sender=$obj->email_sender;
890 $this->email_to=$obj->email_to;
891 $this->email_tocc=$obj->email_tocc;
892 $this->email_tobcc=$obj->email_tobcc;
893 $this->email_subject=$obj->email_subject;
894 $this->errors_to=$obj->errors_to;
898 if ($loadresources) {
905 $this->error = $this->
db->lasterror();
919 $this->userassigned = array();
920 $this->socpeopleassigned = array();
922 $sql =
'SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency';
923 $sql .=
' FROM '.MAIN_DB_PREFIX.
'actioncomm_resources';
924 $sql .=
' WHERE fk_actioncomm = '.((int) $this->
id);
925 $sql .=
" AND element_type IN ('user', 'socpeople')";
929 if ($this->userownerid > 0) {
930 $this->userassigned[$this->userownerid] = array(
'id'=>$this->userownerid);
933 while ($obj = $this->
db->fetch_object(
$resql)) {
934 if ($obj->fk_element > 0) {
935 switch ($obj->element_type) {
937 $this->userassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
'mandatory'=>$obj->mandatory,
'answer_status'=>$obj->answer_status,
'transparency'=>$obj->transparency);
938 if (empty($this->userownerid)) {
939 $this->userownerid = $obj->fk_element;
943 $this->socpeopleassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
'mandatory'=>$obj->mandatory,
'answer_status'=>$obj->answer_status,
'transparency'=>$obj->transparency);
966 $sql =
"SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency";
967 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm_resources";
968 $sql .=
" WHERE element_type = 'user' AND fk_actioncomm = ".((int) $this->
id);
970 $resql2 = $this->
db->query($sql);
972 $this->userassigned = array();
975 if ($this->userownerid > 0) {
977 $this->userassigned[$this->userownerid] = array(
'id'=>$this->userownerid);
980 while ($obj = $this->
db->fetch_object($resql2)) {
981 if ($obj->fk_element > 0) {
982 $this->userassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
983 'mandatory'=>$obj->mandatory,
984 'answer_status'=>$obj->answer_status,
985 'transparency'=>$obj->transparency);
988 if ($override ===
true) {
990 if (empty($this->userownerid)) {
991 $this->userownerid = $obj->fk_element;
1009 public function delete($notrigger = 0)
1015 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1021 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_actioncomm";
1022 $sql .=
" WHERE fk_actioncomm=".((int) $this->
id);
1024 $res = $this->
db->query($sql);
1026 $this->error = $this->
db->lasterror();
1033 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources";
1034 $sql .=
" WHERE fk_actioncomm=".((int) $this->
id);
1036 $res = $this->
db->query($sql);
1038 $this->error = $this->
db->lasterror();
1044 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
1045 $sql .=
" WHERE fk_actioncomm = ".((int) $this->
id);
1047 $res = $this->
db->query($sql);
1049 $this->error = $this->
db->lasterror();
1059 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1065 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm";
1066 $sql .=
" WHERE id=".((int) $this->
id);
1068 $res = $this->
db->query($sql);
1070 $this->error = $this->
db->lasterror();
1086 $this->
db->commit();
1089 $this->
db->rollback();
1093 $this->
db->rollback();
1094 $this->error = $this->
db->lasterror();
1109 global $langs, $conf, $hookmanager;
1114 $this->label = trim($this->label);
1115 $this->note_private =
dol_htmlcleanlastbr(trim(!isset($this->note_private) ? $this->note : $this->note_private));
1116 if (empty($this->percentage)) {
1117 $this->percentage = 0;
1119 if (empty($this->priority) || !is_numeric($this->priority)) {
1120 $this->priority = 0;
1122 if (empty($this->transparency)) {
1123 $this->transparency = 0;
1125 if (empty($this->fulldayevent)) {
1126 $this->fulldayevent = 0;
1128 if ($this->percentage > 100) {
1129 $this->percentage = 100;
1132 if ($this->datep && $this->datef) {
1133 $this->durationp = ($this->datef - $this->datep);
1136 if ($this->datep && $this->datef && $this->datep > $this->datef) {
1137 $this->datef = $this->datep;
1140 if ($this->fk_project < 0) {
1141 $this->fk_project = 0;
1145 if ($this->percentage == 0 && $this->userdoneid > 0) {
1146 $this->error =
"ErrorCantSaveADoneUserWithZeroPercentage";
1150 $socid = (($this->socid > 0) ? $this->socid : 0);
1151 $contactid = (($this->contact_id > 0) ? $this->contact_id : 0);
1152 $userownerid = ($this->userownerid ? $this->userownerid : 0);
1153 $userdoneid = ($this->userdoneid ? $this->userdoneid : 0);
1156 if ($this->type_id > 0) {
1157 if (empty($this->type_code)) {
1159 $result = $cactioncomm->fetch($this->type_id);
1160 if ($result >= 0 && !empty($cactioncomm->code)) {
1161 $this->type_code = $cactioncomm->code;
1166 $code = $this->code;
1167 if (empty($code) || (!empty($this->oldcopy) && $this->oldcopy->type_code != $this->type_code)) {
1168 $code = $this->type_code;
1173 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm ";
1174 $sql .=
" SET percent = '".$this->db->escape($this->percentage).
"'";
1175 $sql .=
", fk_action = ".(int) $this->type_id;
1176 $sql .=
", code = " . ($code ?
"'".$this->db->escape($code).
"'" :
"null");
1177 $sql .=
", label = ".($this->label ?
"'".$this->db->escape($this->label).
"'" :
"null");
1178 $sql .=
", datep = ".(strval($this->datep) !=
'' ?
"'".$this->db->idate($this->datep).
"'" :
'null');
1179 $sql .=
", datep2 = ".(strval($this->datef) !=
'' ?
"'".$this->db->idate($this->datef).
"'" :
'null');
1180 $sql .=
", durationp = ".(isset($this->durationp) && $this->durationp >= 0 && $this->durationp !=
'' ?
"'".$this->db->escape($this->durationp).
"'" :
"null");
1181 $sql .=
", note = '".$this->db->escape($this->note_private).
"'";
1182 $sql .=
", fk_project =".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1183 $sql .=
", fk_soc =".($socid > 0 ? ((int) $socid) :
"null");
1184 $sql .=
", fk_contact =".($contactid > 0 ? ((int) $contactid) :
"null");
1185 $sql .=
", priority = '".$this->db->escape($this->priority).
"'";
1186 $sql .=
", fulldayevent = '".$this->db->escape($this->fulldayevent).
"'";
1187 $sql .=
", location = ".($this->location ?
"'".$this->db->escape($this->location).
"'" :
"null");
1188 $sql .=
", transparency = '".$this->db->escape($this->transparency).
"'";
1189 $sql .=
", fk_user_mod = ".((int) $user->id);
1190 $sql .=
", fk_user_action = ".($userownerid > 0 ? ((int) $userownerid) :
"null");
1191 $sql .=
", fk_user_done = ".($userdoneid > 0 ? ((int) $userdoneid) :
"null");
1192 if (!empty($this->fk_element)) {
1193 $sql .=
", fk_element=".($this->fk_element ? ((int) $this->fk_element) :
"null");
1195 if (!empty($this->elementtype)) {
1196 $sql .=
", elementtype=".($this->elementtype ?
"'".$this->db->escape($this->elementtype).
"'" :
"null");
1198 if (!empty($this->num_vote)) {
1199 $sql .=
", num_vote=".($this->num_vote ? (int) $this->num_vote :
null);
1201 if (!empty($this->event_paid)) {
1202 $sql .=
", event_paid=".($this->event_paid ? (int) $this->event_paid : 0);
1204 if (!empty($this->status)) {
1205 $sql .=
", status=".($this->status ? (int) $this->status : 0);
1207 $sql .=
" WHERE id=".$this->id;
1209 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1210 if ($this->
db->query($sql)) {
1223 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources where fk_actioncomm = ".((int) $this->
id).
" AND element_type = 'user'";
1226 $already_inserted = array();
1227 foreach ($this->userassigned as $key => $val) {
1228 if (!is_array($val)) {
1229 $val = array(
'id'=>$val);
1231 if (!empty($already_inserted[$val[
'id']]))
continue;
1233 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1234 $sql .=
" VALUES(".((int) $this->
id).
", 'user', ".((int) $val[
'id']).
", ".(empty($val[
'mandatory']) ?
'0' : ((int) $val[
'mandatory'])).
", ".(empty($val[
'transparency']) ?
'0' : ((int) $val[
'transparency'])).
", ".(empty($val[
'answer_status']) ?
'0' : ((int) $val[
'answer_status'])).
")";
1239 $this->errors[] = $this->
db->lasterror();
1241 $already_inserted[$val[
'id']] =
true;
1248 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources where fk_actioncomm = ".((int) $this->
id).
" AND element_type = 'socpeople'";
1251 if (!empty($this->socpeopleassigned)) {
1252 $already_inserted = array();
1253 foreach (array_keys($this->socpeopleassigned) as $key => $val) {
1254 if (!is_array($val)) {
1255 $val = array(
'id'=>$val);
1257 if (!empty($already_inserted[$val[
'id']]))
continue;
1259 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1260 $sql .=
" VALUES(".((int) $this->
id).
", 'socpeople', ".((int) $val[
'id']).
", 0, 0, 0)";
1265 $this->errors[] = $this->
db->lasterror();
1267 $already_inserted[$val[
'id']] =
true;
1273 if (!$error && !$notrigger) {
1283 $this->
db->commit();
1286 $this->
db->rollback();
1287 dol_syslog(get_class($this).
"::update ".join(
',', $this->errors), LOG_ERR);
1291 $this->
db->rollback();
1292 $this->error = $this->
db->lasterror();
1310 public function getActions($socid = 0, $fk_element = 0, $elementtype =
'', $filter =
'', $sortfield =
'a.datep', $sortorder =
'DESC', $limit = 0)
1312 global $conf, $langs;
1314 $resarray = array();
1316 dol_syslog(get_class().
"::getActions", LOG_DEBUG);
1318 $sql =
"SELECT a.id";
1319 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
1320 $sql .=
" WHERE a.entity IN (".getEntity(
'agenda').
")";
1321 if (!empty($socid)) {
1322 $sql .=
" AND a.fk_soc = ".((int) $socid);
1324 if (!empty($elementtype)) {
1325 if ($elementtype ==
'project') {
1326 $sql .=
' AND a.fk_project = '.((int) $fk_element);
1327 } elseif ($elementtype ==
'contact') {
1328 $sql .=
' AND a.id IN';
1329 $sql .=
" (SELECT fk_actioncomm FROM ".MAIN_DB_PREFIX.
"actioncomm_resources WHERE";
1330 $sql .=
" element_type = 'socpeople' AND fk_element = ".((int) $fk_element).
')';
1332 $sql .=
" AND a.fk_element = ".((int) $fk_element).
" AND a.elementtype = '".$this->
db->escape($elementtype).
"'";
1335 if (!empty($filter)) {
1338 if ($sortorder && $sortfield) {
1339 $sql .= $this->
db->order($sortfield, $sortorder);
1341 $sql .= $this->
db->plimit($limit, 0);
1345 $num = $this->
db->num_rows(
$resql);
1348 for ($i = 0; $i < $num; $i++) {
1349 $obj = $this->
db->fetch_object(
$resql);
1351 $actioncommstatic->fetch($obj->id);
1352 $resarray[$i] = $actioncommstatic;
1358 return $this->
db->lasterror();
1373 global $conf, $langs;
1375 if (empty($load_state_board)) {
1376 $sql =
"SELECT a.id, a.datep as dp";
1378 $this->nb = array();
1379 $sql =
"SELECT count(a.id) as nb";
1381 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
1382 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1383 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
1385 if (empty($user->rights->agenda->allactions->read)) {
1386 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"actioncomm_resources AS ar ON a.id = ar.fk_actioncomm AND ar.element_type ='user' AND ar.fk_element = ".((int) $user->id);
1388 $sql .=
" WHERE 1 = 1";
1389 if (empty($load_state_board)) {
1390 $sql .=
" AND a.percent >= 0 AND a.percent < 100";
1392 $sql .=
" AND a.entity IN (".getEntity(
'agenda').
")";
1393 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1394 $sql .=
" AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).
")";
1397 $sql .=
" AND a.fk_soc = ".((int) $user->socid);
1399 if (empty($user->rights->agenda->allactions->read)) {
1400 $sql .=
" AND (a.fk_user_author = ".((int) $user->id).
" OR a.fk_user_action = ".((int) $user->id).
" OR a.fk_user_done = ".((int) $user->id);
1401 $sql .=
" OR ar.fk_element = ".((int) $user->id);
1407 if (empty($load_state_board)) {
1410 $response->warning_delay = $conf->agenda->warning_delay / 60 / 60 / 24;
1411 $response->label = $langs->trans(
"ActionsToDo");
1412 $response->labelShort = $langs->trans(
"ActionsToDoShort");
1413 $response->url = DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&actioncode=0&status=todo&mainmenu=agenda';
1414 if ($user->rights->agenda->allactions->read) {
1415 $response->url .=
'&filtert=-1';
1417 $response->img =
img_object(
'',
"action",
'class="inline-block valigntextmiddle"');
1420 while ($obj = $this->
db->fetch_object(
$resql)) {
1421 if (empty($load_state_board)) {
1422 $response->nbtodo++;
1423 $agenda_static->datep = $this->
db->jdate($obj->dp);
1424 if ($agenda_static->hasDelay()) {
1425 $response->nbtodolate++;
1428 $this->nb[
"actionscomm"] = $obj->nb;
1433 if (empty($load_state_board)) {
1440 $this->error = $this->
db->error();
1457 $sql .=
' tms as datem,';
1458 $sql .=
' fk_user_author,';
1459 $sql .=
' fk_user_mod';
1460 $sql .=
' FROM '.MAIN_DB_PREFIX.
'actioncomm as a';
1461 $sql .=
' WHERE a.id = '.((int) $id);
1463 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
1464 $result = $this->
db->query($sql);
1466 if ($this->
db->num_rows($result)) {
1467 $obj = $this->
db->fetch_object($result);
1468 $this->
id = $obj->id;
1469 $this->user_creation_id = $obj->fk_user_author;
1470 $this->user_modification_id = $obj->fk_user_mod;
1471 $this->date_creation = $this->
db->jdate($obj->datec);
1472 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
1474 $this->
db->free($result);
1490 return $this->
LibStatut($this->percentage, $mode, $hidenastatus, $this->datep);
1503 public function LibStatut($percent, $mode, $hidenastatus = 0, $datestart =
'')
1508 $labelStatus = $langs->transnoentitiesnoconv(
'StatusNotApplicable');
1509 if ($percent == -1 && !$hidenastatus) {
1510 $labelStatus = $langs->transnoentitiesnoconv(
'StatusNotApplicable');
1511 } elseif ($percent == 0) {
1512 $labelStatus = $langs->transnoentitiesnoconv(
'StatusActionToDo').
' (0%)';
1513 } elseif ($percent > 0 && $percent < 100) {
1514 $labelStatus = $langs->transnoentitiesnoconv(
'StatusActionInProcess').
' ('.$percent.
'%)';
1515 } elseif ($percent >= 100) {
1516 $labelStatus = $langs->transnoentitiesnoconv(
'StatusActionDone').
' (100%)';
1519 $labelStatusShort = $langs->transnoentitiesnoconv(
'StatusNotApplicable');
1520 if ($percent == -1 && !$hidenastatus) {
1521 $labelStatusShort = $langs->trans(
'NA');
1522 } elseif ($percent == 0) {
1523 $labelStatusShort =
'0%';
1524 } elseif ($percent > 0 && $percent < 100) {
1525 $labelStatusShort = $percent.
'%';
1526 } elseif ($percent >= 100) {
1527 $labelStatusShort =
'100%';
1530 $statusType =
'status9';
1531 if ($percent == -1 && !$hidenastatus) {
1532 $statusType =
'status9';
1534 if ($percent == 0) {
1535 $statusType =
'status1';
1537 if ($percent > 0 && $percent < 100) {
1538 $statusType =
'status3';
1540 if ($percent >= 100) {
1541 $statusType =
'status6';
1544 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1560 public function getNomUrl($withpicto = 0, $maxlength = 0, $classname =
'', $option =
'', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
1562 global $conf, $langs, $user, $hookmanager, $action;
1564 if (!empty($conf->dol_no_mouse_hover)) {
1569 if ($user->rights->agenda->myactions->read && ($this->authorid == $user->id || $this->userownerid == $user->id)) {
1572 if ($user->rights->agenda->myactions->read && array_key_exists($user->id, $this->userassigned)) {
1575 if ($user->rights->agenda->allactions->read) {
1582 $label = $this->label;
1583 if (empty($label)) {
1584 $label = $this->libelle;
1591 if ($this->type_code) {
1592 $labeltype = ($langs->transnoentities(
"Action".$this->type_code) !=
"Action".$this->type_code) ? $langs->transnoentities(
"Action".$this->type_code) : $this->type_label;
1594 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1595 if ($this->type_code !=
'AC_OTH_AUTO') {
1596 $labeltype = $langs->trans(
'ActionAC_MANUAL');
1600 $tooltip =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
'Action').
'</u>';
1601 if (!empty($this->
ref)) {
1602 $tooltip .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1604 if (!empty($label)) {
1605 $tooltip .=
'<br><b>'.$langs->trans(
'Title').
':</b> '.$label;
1607 if (!empty($labeltype)) {
1608 $tooltip .=
'<br><b>'.$langs->trans(
'Type').
':</b> '.$labeltype;
1610 if (!empty($this->location)) {
1611 $tooltip .=
'<br><b>'.$langs->trans(
'Location').
':</b> '.$this->location;
1613 if (isset($this->transparency)) {
1614 $tooltip .=
'<br><b>'.$langs->trans(
'Busy').
':</b> '.
yn($this->transparency);
1616 if (!empty($this->email_msgid)) {
1617 $langs->load(
"mails");
1620 $tooltip .=
'<br><b>'.$langs->trans(
'MailTopic').
':</b> '.$this->email_subject;
1621 $tooltip .=
'<br><b>'.$langs->trans(
'MailFrom').
':</b> '.str_replace(array(
'<',
'>'), array(
'&lt',
'&gt'), $this->email_from);
1622 $tooltip .=
'<br><b>'.$langs->trans(
'MailTo').
':</b> '.str_replace(array(
'<',
'>'), array(
'&lt',
'&gt'), $this->email_to);
1623 if (!empty($this->email_tocc)) {
1624 $tooltip .=
'<br><b>'.$langs->trans(
'MailCC').
':</b> '.str_replace(array(
'<',
'>'), array(
'&lt',
'&gt'), $this->email_tocc);
1631 if (!empty($this->note_private)) {
1632 $tooltip .=
'<br><br><b>'.$langs->trans(
'Description').
':</b><br>';
1634 $tooltip .= (
dol_textishtml($texttoshow) ? str_replace(array(
"\r",
"\n"),
"", $texttoshow) : str_replace(array(
"\r",
"\n"),
'<br>', $texttoshow));
1640 if (empty($notooltip)) {
1641 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1642 $label = $langs->trans(
"ShowAction");
1643 $linkclose .=
' alt="'.dol_escape_htmltag($tooltip, 1).
'"';
1645 $linkclose .=
' title="'.dol_escape_htmltag($tooltip, 1, 0,
'', 1).
'"';
1646 $linkclose .=
' class="'.$classname.
' classfortooltip"';
1648 $linkclose .=
' class="'.$classname.
'"';
1652 if ($option ==
'birthday') {
1653 $url = DOL_URL_ROOT.
'/contact/perso.php?id='.$this->id;
1654 } elseif ($option ==
'holiday') {
1655 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1657 $url = DOL_URL_ROOT.
'/comm/action/card.php?id='.$this->id;
1660 if ($option !==
'nolink') {
1662 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1663 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1664 $add_save_lastsearch_values = 1;
1666 if ($add_save_lastsearch_values) {
1667 $url .=
'&save_lastsearch_values=1';
1671 $linkstart =
'<a href="'.$url.
'"';
1672 $linkstart .= $linkclose.
'>';
1675 if ($option ==
'nolink') {
1680 if ($withpicto == 2) {
1681 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1682 $label = $labeltype;
1686 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($label)) {
1687 $label = $labeltype;
1689 if ($maxlength < 0) {
1690 $labelshort = $this->ref;
1692 $labelshort =
dol_trunc($label, $maxlength);
1697 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1699 $label .= (preg_match(
'/'.preg_quote($labeltype,
'/').
'/', $label) ?
'' :
' ('.$langs->transnoentities(
"Action".$this->type_code).
')');
1704 $result .= $linkstart;
1706 $result .=
img_object(($notooltip ?
'' : $langs->trans(
"ShowAction").
': '.$label), ($overwritepicto ? $overwritepicto :
'action'), (($this->type_color && $overwritepicto) ?
'style="color: #'.$this->type_color.
' !important;" ' :
'').($notooltip ?
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'"' :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1708 $result .= $labelshort;
1709 $result .= $linkend;
1712 $hookmanager->initHooks(array(
'actiondao'));
1713 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1714 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1716 $result = $hookmanager->resPrint;
1718 $result .= $hookmanager->resPrint;
1734 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1736 if ($this->type_color) {
1737 $color =
'style="color: #'.$this->type_color.
' !important;"';
1739 if ($this->type_picto) {
1740 $imgpicto =
img_picto(
'', $this->type_picto,
'class="paddingright"');
1742 if ($this->type_code ==
'AC_RDV') {
1743 $imgpicto =
img_picto(
'',
'meeting', $color,
false, 0, 0,
'',
'paddingright');
1744 } elseif ($this->type_code ==
'AC_TEL') {
1745 $imgpicto =
img_picto(
'',
'object_phoning', $color,
false, 0, 0,
'',
'paddingright');
1746 } elseif ($this->type_code ==
'AC_FAX') {
1747 $imgpicto =
img_picto(
'',
'object_phoning_fax', $color,
false, 0, 0,
'',
'paddingright');
1748 } elseif ($this->type_code ==
'AC_EMAIL' || $this->type_code ==
'AC_EMAIL_IN') {
1749 $imgpicto =
img_picto(
'',
'object_email', $color,
false, 0, 0,
'',
'paddingright');
1750 } elseif ($this->type_code ==
'AC_INT') {
1751 $imgpicto =
img_picto(
'',
'object_intervention', $color,
false, 0, 0,
'',
'paddingright');
1752 } elseif ($this->type_code ==
'AC_OTH' && $this->
code ==
'TICKET_MSG') {
1753 $imgpicto =
img_picto(
'',
'object_conversation', $color,
false, 0, 0,
'',
'paddingright');
1754 } elseif ($this->
type !=
'systemauto') {
1755 $imgpicto =
img_picto(
'',
'user-cog', $color,
false, 0, 0,
'',
'paddingright');
1757 $imgpicto =
img_picto(
'',
'cog', $color,
false, 0, 0,
'',
'paddingright');
1762 if ($this->
type !=
'systemauto') {
1763 $imgpicto =
img_picto(
'',
'user-cog',
'',
false, 0, 0,
'',
'paddingright');
1765 $imgpicto =
img_picto(
'',
'cog',
'',
false, 0, 0,
'',
'paddingright');
1785 if (!is_array($categories)) {
1786 $categories = array($categories);
1790 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1792 $existing = $c->containing($this->
id, Categorie::TYPE_ACTIONCOMM,
'id');
1795 if (is_array($existing)) {
1796 $to_del = array_diff($existing, $categories);
1797 $to_add = array_diff($categories, $existing);
1800 $to_add = $categories;
1804 foreach ($to_del as $del) {
1805 if ($c->fetch($del) > 0) {
1806 $c->del_type($this, Categorie::TYPE_ACTIONCOMM);
1809 foreach ($to_add as $add) {
1810 if ($c->fetch($add) > 0) {
1811 $c->add_type($this, Categorie::TYPE_ACTIONCOMM);
1829 public function build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday = 0)
1831 global $hookmanager;
1834 global $conf, $langs, $dolibarr_main_url_root, $mysoc;
1836 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
1837 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
1838 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
1840 dol_syslog(get_class($this).
"::build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
1843 if (empty($format)) {
1850 if ($format ==
'ical') {
1853 $filename = $format.
'.'.$extension;
1857 $result =
dol_mkdir($conf->agenda->dir_temp);
1858 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
1863 $login =
''; $logina =
''; $logind =
''; $logint =
'';
1869 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1871 dol_syslog(get_class($this).
"::build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
1878 $eventarray = array();
1880 $sql =
"SELECT a.id,";
1881 $sql .=
" a.datep,";
1882 $sql .=
" a.datep2,";
1883 $sql .=
" a.durationp,";
1884 $sql .=
" a.datec, a.tms as datem,";
1885 $sql .=
" a.label, a.code, a.note as note_private, a.fk_action as type_id,";
1886 $sql .=
" a.fk_soc,";
1887 $sql .=
" a.fk_user_author, a.fk_user_mod,";
1888 $sql .=
" a.fk_user_action,";
1889 $sql .=
" a.fk_contact, a.percent as percentage,";
1890 $sql .=
" a.fk_element, a.elementtype,";
1891 $sql .=
" a.priority, a.fulldayevent, a.location, a.transparency,";
1892 $sql .=
" u.firstname, u.lastname, u.email,";
1893 $sql .=
" s.nom as socname,";
1894 $sql .=
" c.id as type_id, c.code as type_code, c.libelle as type_label,";
1895 $sql .=
" num_vote, event_paid, a.status";
1896 $sql .=
" FROM (".MAIN_DB_PREFIX.
"c_actioncomm as c, ".MAIN_DB_PREFIX.
"actioncomm as a)";
1897 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = a.fk_user_author";
1898 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = a.fk_soc";
1900 $parameters = array(
'filters' => $filters);
1901 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
1902 $sql .= $hookmanager->resPrint;
1905 if ($filters[
'logint']) {
1906 $sql .=
", ".MAIN_DB_PREFIX.
"actioncomm_resources as ar";
1908 $sql .=
" WHERE a.fk_action=c.id";
1909 $sql .=
" AND a.entity IN (".getEntity(
'agenda').
")";
1910 foreach ($filters as $key => $value) {
1911 if ($key ==
'notolderthan' && $value !=
'') {
1912 $sql .=
" AND a.datep >= '".$this->db->idate($now - ($value * 24 * 60 * 60)).
"'";
1914 if ($key ==
'year') {
1918 $sql .=
" AND a.id=".(is_numeric($value) ? $value : 0);
1920 if ($key ==
'idfrom') {
1921 $sql .=
" AND a.id >= ".(is_numeric($value) ? $value : 0);
1923 if ($key ==
'idto') {
1924 $sql .=
" AND a.id <= ".(is_numeric($value) ? $value : 0);
1926 if ($key ==
'project') {
1927 $sql .=
" AND a.fk_project=".(is_numeric($value) ? $value : 0);
1929 if ($key ==
'actiontype') {
1930 $sql .=
" AND c.type = '".$this->db->escape($value).
"'";
1932 if ($key ==
'notactiontype') {
1933 $sql .=
" AND c.type <> '".$this->db->escape($value).
"'";
1936 if ($key ==
'logint') {
1937 $sql .=
" AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
1939 if ($key ==
'logina') {
1942 if (preg_match(
'/^!/', $logina)) {
1943 $logina = preg_replace(
'/^!/',
'', $logina);
1946 $userforfilter =
new User($this->
db);
1947 $result = $userforfilter->fetch(
'', $logina);
1949 $sql .=
" AND a.fk_user_author ".$condition.
" ".$userforfilter->id;
1950 } elseif ($result < 0 || $condition ==
'=') {
1951 $sql .=
" AND a.fk_user_author = 0";
1954 if ($key ==
'logint') {
1957 if (preg_match(
'/^!/', $logint)) {
1958 $logint = preg_replace(
'/^!/',
'', $logint);
1961 $userforfilter =
new User($this->
db);
1962 $result = $userforfilter->fetch(
'', $logint);
1964 $sql .=
" AND ar.fk_element = ".((int) $userforfilter->id);
1965 } elseif ($result < 0 || $condition ==
'=') {
1966 $sql .=
" AND ar.fk_element = 0";
1969 if ($key ==
'module') {
1970 $sql .=
" AND c.module LIKE '%".$this->db->escape($value).
"'";
1972 if ($key ==
'status') {
1973 $sql .=
" AND a.status =".((int) $value);
1977 $sql .=
" AND a.datep IS NOT NULL";
1979 $parameters = array(
'filters' => $filters);
1980 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
1981 $sql .= $hookmanager->resPrint;
1983 $sql .=
" ORDER by datep";
1986 dol_syslog(get_class($this).
"::build_exportfile select events", LOG_DEBUG);
1992 while ($obj = $this->
db->fetch_object(
$resql)) {
1997 $event[
'uid'] =
'dolibarragenda-'.$this->db->database_name.
'-'.$obj->id.
"@".$_SERVER[
"SERVER_NAME"];
1998 $event[
'type'] = $type;
2000 $datestart = $this->
db->jdate($obj->datep) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2003 if (is_numeric($this->
db->jdate($obj->datep2))) {
2004 $dateend = $this->
db->jdate($obj->datep2) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2007 $dateend = $datestart;
2010 $duration = ($datestart && $dateend) ? ($dateend - $datestart) : 0;
2011 $event[
'summary'] = $obj->label.($obj->socname ?
" (".$obj->socname.
")" :
"");
2013 $event[
'desc'] = $obj->note_private;
2014 $event[
'startdate'] = $datestart;
2015 $event[
'enddate'] = $dateend;
2016 $event[
'duration'] = $duration;
2018 $event[
'priority'] = $obj->priority;
2019 $event[
'fulldayevent'] = $obj->fulldayevent;
2020 $event[
'location'] = $obj->location;
2021 $event[
'transparency'] = (($obj->transparency > 0) ?
'OPAQUE' :
'TRANSPARENT');
2022 $event[
'category'] = $obj->type_label;
2023 $event[
'email'] = $obj->email;
2025 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2026 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2028 $url = $urlwithroot.
'/comm/action/card.php?id='.$obj->id;
2029 $event[
'url'] = $url;
2030 $event[
'created'] = $this->
db->jdate($obj->datec) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2031 $event[
'modified'] = $this->
db->jdate($obj->datem) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2032 $event[
'num_vote'] = $this->num_vote;
2033 $event[
'event_paid'] = $this->event_paid;
2034 $event[
'status'] = $this->status;
2037 $this->
id = $obj->id;
2040 $assignedUserArray = array();
2042 foreach ($this->userassigned as $key => $value) {
2043 $assignedUser =
new User($this->
db);
2044 $assignedUser->fetch($value[
'id']);
2046 $assignedUserArray[$key] = $assignedUser;
2049 $event[
'assignedUsers'] = $assignedUserArray;
2051 if ($qualified && $datestart) {
2052 $eventarray[] = $event;
2057 $parameters = array(
'filters' => $filters,
'eventarray' => &$eventarray);
2058 $reshook = $hookmanager->executeHooks(
'addMoreEventsExport', $parameters);
2060 $eventarray = $hookmanager->resArray;
2063 $this->error = $this->
db->lasterror();
2067 if ($exportholiday == 1) {
2068 $langs->load(
"holidays");
2069 $title = $langs->trans(
"Holidays");
2071 $sql =
"SELECT u.rowid as uid, u.lastname, u.firstname, u.email, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status";
2072 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as x, ".MAIN_DB_PREFIX.
"user as u";
2073 $sql .=
" WHERE u.rowid = x.fk_user";
2074 $sql .=
" AND u.statut = '1'";
2075 $sql .=
" AND (x.statut = '2' OR x.statut = '3')";
2079 $num = $this->
db->num_rows(
$resql);
2083 $obj = $this->
db->fetch_object(
$resql);
2086 if ($obj->halfday == -1) {
2087 $event[
'fulldayevent'] =
false;
2091 } elseif ($obj->halfday == 1) {
2092 $event[
'fulldayevent'] =
false;
2097 $event[
'fulldayevent'] =
true;
2103 if (!empty($conf->global->AGENDA_EXPORT_FIX_TZ)) {
2104 $timestampStart = $timestampStart - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2105 $timestampEnd = $timestampEnd - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2108 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2109 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2110 $url = $urlwithroot.
'/holiday/card.php?id='.$obj->rowid;
2112 $event[
'uid'] =
'dolibarrholiday-'.$this->db->database_name.
'-'.$obj->rowid.
"@".$_SERVER[
"SERVER_NAME"];
2114 $event[
'type'] =
'event';
2115 $event[
'category'] =
"Holiday";
2116 $event[
'transparency'] =
'OPAQUE';
2117 $event[
'email'] = $obj->email;
2118 $event[
'created'] = $timestampStart;
2119 $event[
'modified'] = $timestampStart;
2120 $event[
'startdate'] = $timestampStart;
2121 $event[
'enddate'] = $timestampEnd;
2122 $event[
'duration'] = $timestampEnd - $timestampStart;
2123 $event[
'url'] = $url;
2125 if ($obj->status == 2) {
2127 $event[
'summary'] = $title.
" - ".$obj->lastname.
" (wait for approval)";
2130 $event[
'summary'] = $title.
" - ".$obj->lastname;
2133 $eventarray[] = $event;
2140 $langs->load(
"agenda");
2145 $more = $langs->transnoentities(
"User").
' '.$login;
2148 $more = $langs->transnoentities(
"ActionsAskedBy").
' '.$logina;
2151 $more = $langs->transnoentities(
"ActionsToDoBy").
' '.$logint;
2154 $more = $langs->transnoentities(
"ActionsDoneBy").
' '.$logind;
2157 $title =
'Dolibarr actions '.$mysoc->name.
' - '.$more;
2159 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
2161 $title =
'Dolibarr actions '.$mysoc->name;
2162 $desc = $langs->transnoentities(
'ListOfActions');
2163 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
2167 $outputfiletmp = tempnam($conf->agenda->dir_temp,
'tmp');
2168 @chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
2171 if ($format ==
'vcal') {
2172 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2173 } elseif ($format ==
'ical') {
2174 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2175 } elseif ($format ==
'rss') {
2176 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
2180 if (
dol_move($outputfiletmp, $outputfile, 0, 1)) {
2183 $this->error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
2184 dol_syslog(get_class($this).
"::build_exportfile ".$this->error, LOG_ERR);
2189 dol_syslog(get_class($this).
"::build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
2191 $langs->load(
"errors");
2192 $this->error = $langs->trans(
"ErrorFailToCreateFile", $outputfile);
2214 $this->specimen = 1;
2216 $this->type_code =
'AC_OTH';
2217 $this->
code =
'AC_SPECIMEN_CODE';
2218 $this->label =
'Label of event Specimen';
2219 $this->datec = $now;
2220 $this->datem = $now;
2221 $this->datep = $now;
2222 $this->datef = $now;
2223 $this->fulldayevent = 0;
2224 $this->percentage = 0;
2226 $this->location =
'Location';
2227 $this->transparency = 1;
2228 $this->priority = 1;
2230 $this->note_private =
"This is a 'private' note.";
2232 $this->userownerid = $user->id;
2233 $this->userassigned[$user->id] = array(
'id'=>$user->id,
'transparency'=> 1);
2264 $sql =
'UPDATE ' . MAIN_DB_PREFIX .
'actioncomm SET fk_element = ' . ((int) $dest_id) .
' WHERE elementtype="product" AND fk_element = '.((int) $origin_id);
2266 if (!$dbs->
query($sql)) {
2285 return $this->datep && ($this->datep < ($now - $conf->agenda->warning_delay));
2299 global $conf, $langs, $user;
2303 $this->reminders = array();
2306 $sql =
"SELECT rowid as id, typeremind, dateremind, status, offsetvalue, offsetunit, fk_user";
2307 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2308 $sql .=
" WHERE fk_actioncomm = ".((int) $this->
id);
2310 $sql .=
" AND dateremind <= '".$this->db->idate(
dol_now()).
"'";
2313 $sql .=
" AND typeremind ='".$this->db->escape($type).
"'";
2316 $sql .=
" AND fk_user = ".((int) $fk_user);
2318 if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2319 $sql .=
" AND typeremind != 'email'";
2321 if (empty($conf->global->AGENDA_REMINDER_BROWSER)) {
2322 $sql .=
" AND typeremind != 'browser'";
2325 $sql .= $this->
db->order(
"dateremind",
"ASC");
2329 while ($obj = $this->
db->fetch_object(
$resql)) {
2331 $tmpactioncommreminder->id = $obj->id;
2332 $tmpactioncommreminder->typeremind = $obj->typeremind;
2333 $tmpactioncommreminder->dateremind = $obj->dateremind;
2334 $tmpactioncommreminder->offsetvalue = $obj->offsetvalue;
2335 $tmpactioncommreminder->offsetunit = $obj->offsetunit;
2336 $tmpactioncommreminder->status = $obj->status;
2337 $tmpactioncommreminder->fk_user = $obj->fk_user;
2339 $this->reminders[$obj->id] = $tmpactioncommreminder;
2342 $this->error = $this->
db->lasterror();
2346 return count($this->reminders);
2358 global $conf, $langs, $user;
2364 $errorsMsg = array();
2366 if (empty($conf->agenda->enabled)) {
2367 $langs->load(
"agenda");
2368 $this->output = $langs->trans(
'ModuleNotEnabled', $langs->transnoentitiesnoconv(
"Agenda"));
2371 if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2372 $langs->load(
"agenda");
2373 $this->output = $langs->trans(
'EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv(
"Agenda"));
2385 $sql =
"SELECT rowid as id FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2386 $sql .=
" WHERE typeremind = 'email' AND status = 0";
2387 $sql .=
" AND dateremind <= '".$this->db->idate($now).
"'";
2388 $sql .=
" AND entity IN (".getEntity(
'actioncomm').
")";
2389 $sql .= $this->
db->order(
"dateremind",
"ASC");
2393 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2396 while ($obj = $this->
db->fetch_object(
$resql)) {
2397 $res = $actionCommReminder->fetch($obj->id);
2400 $errorsMsg[] =
"Failed to load invoice ActionComm Reminder";
2405 $arraymessage = $formmail->getEMailTemplate($this->
db,
'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1);
2408 $res = $this->
fetch($actionCommReminder->fk_actioncomm);
2419 $sendContent =
make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
2422 $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->transnoentities(
'EventReminder'));
2425 $recipient =
new User($this->
db);
2426 $res = $recipient->fetch($actionCommReminder->fk_user);
2428 if (!empty($recipient->email)) {
2429 $to = $recipient->email;
2431 $errormesg =
"Failed to send remind to user id=".$actionCommReminder->fk_user.
". No email defined for user.";
2435 $errormesg =
"Failed to load recipient with user id=".$actionCommReminder->fk_user;
2440 $from = $conf->global->MAIN_MAIL_EMAIL_FROM;
2442 $errormesg =
"Failed to get sender into global setup MAIN_MAIL_EMAIL_FROM";
2448 $errors_to = $conf->global->MAIN_MAIL_ERRORS_TO;
2451 $cMailFile =
new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(),
'',
"", 0, 1, $errors_to,
'',
'',
'',
'',
'');
2454 if ($cMailFile->sendfile()) {
2457 $errormesg = $cMailFile->error.
' : '.$to;
2463 $actionCommReminder->status = $actionCommReminder::STATUS_DONE;
2465 $res = $actionCommReminder->update($user);
2467 $errorsMsg[] =
"Failed to update status to done of ActionComm Reminder";
2472 $actionCommReminder->status = $actionCommReminder::STATUS_ERROR;
2473 $actionCommReminder->lasterror =
dol_trunc($errormesg, 128,
'right',
'UTF-8', 1);
2475 $res = $actionCommReminder->update($user);
2477 $errorsMsg[] =
"Failed to update status to error of ActionComm Reminder";
2481 $errorsMsg[] = $errormesg;
2485 $errorsMsg[] =
'Failed to fetch record actioncomm with ID = '.$actionCommReminder->fk_actioncomm;
2496 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2497 $sql .=
" WHERE dateremind < '".$this->db->idate($now - (3600 * 24 * 32)).
"'";
2498 $sql .=
" AND status = ".((int) $actionCommReminder::STATUS_DONE);
2502 $errorsMsg[] =
'Failed to delete old reminders';
2508 $this->output =
'Nb of emails sent : '.$nbMailSend;
2509 $this->
db->commit();
2512 $this->
db->commit();
2513 $this->error =
'Nb of emails sent : '.$nbMailSend.
', '.(!empty($errorsMsg)) ? join(
', ', $errorsMsg) : $error;
2530 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm ";
2531 $sql .=
" SET percent = ".(int) $percent;
2532 if ($usermodid > 0) $sql .=
", fk_user_mod = ".$usermodid;
2533 $sql .=
" WHERE id = ".((int) $id);
2535 if ($this->
db->query($sql)) {
2536 $this->
db->commit();
2539 $this->
db->rollback();
2540 $this->error = $this->
db->lasterror();