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();
321 public $actions = array();
336 public $email_sender;
355 public $email_subject;
382 public $recurdateend;
384 public $calling_duration;
403 public $fields = array();
426 global $langs, $conf;
432 if (!isset($this->userownerid) || $this->userownerid ===
'') {
433 dol_syslog(
"You tried to create an event but mandatory property ownerid was not defined", LOG_WARNING);
434 $this->errors[] =
'ErrorActionCommPropertyUserowneridNotDefined';
439 $this->label =
dol_trunc(trim($this->label), 128);
440 $this->location =
dol_trunc(trim($this->location), 128);
441 $this->note_private =
dol_htmlcleanlastbr(trim(empty($this->note_private) ? $this->note : $this->note_private));
442 if (empty($this->percentage)) {
443 $this->percentage = 0;
445 if (empty($this->priority) || !is_numeric($this->priority)) {
448 if (empty($this->fulldayevent)) {
449 $this->fulldayevent = 0;
451 if (empty($this->transparency)) {
452 $this->transparency = 0;
454 if ($this->percentage > 100) {
455 $this->percentage = 100;
457 if (empty($this->datep) && $this->datep !=
'0') {
460 if (!empty($this->datep) && !empty($this->datef)) {
461 $this->durationp = ($this->datef - $this->datep);
463 if (!empty($this->datep) && !empty($this->datef) && $this->datep > $this->datef) {
464 $this->datef = $this->datep;
466 if (!isset($this->fk_project) || $this->fk_project < 0) {
467 $this->fk_project = 0;
470 if ($this->elementtype ==
'facture') {
471 $this->elementtype =
'invoice';
473 if ($this->elementtype ==
'commande') {
474 $this->elementtype =
'order';
476 if ($this->elementtype ==
'contrat') {
477 $this->elementtype =
'contract';
480 if (!is_array($this->userassigned) && !empty($this->userassigned)) {
481 $tmpid = $this->userassigned;
482 $this->userassigned = array();
483 $this->userassigned[$tmpid] = array(
'id'=>$tmpid,
'transparency'=>$this->transparency);
486 $userownerid = $this->userownerid;
487 $userdoneid = $this->userdoneid;
490 if (empty($this->userassigned) || count($this->userassigned) == 0 || !is_array($this->userassigned)) {
491 $this->userassigned = array($userownerid=>array(
'id'=>$userownerid,
'transparency'=>$this->transparency));
494 if (!$this->type_id || !$this->type_code) {
495 $key = empty($this->type_id) ? $this->type_code : $this->type_id;
499 $result = $cactioncomm->fetch($key);
502 $this->type_id = $cactioncomm->id;
503 $this->type_code = $cactioncomm->code;
504 } elseif ($result == 0) {
505 $this->error = $langs->trans(
'ErrorActionCommBadType', $this->type_id, $this->type_code);
508 $this->error = $cactioncomm->error;
512 $code = empty($this->
code) ? $this->type_code : $this->code;
515 if (!$this->type_id) {
516 $this->error =
"ErrorWrongParameters";
522 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm";
527 $sql .=
"durationp,";
528 $sql .=
"fk_action,";
532 $sql .=
"fk_project,";
534 $sql .=
"fk_contact,";
535 $sql .=
"fk_user_author,";
536 $sql .=
"fk_user_action,";
537 $sql .=
"fk_user_done,";
538 $sql .=
"label,percent,priority,fulldayevent,location,";
539 $sql .=
"transparency,";
540 $sql .=
"fk_element,";
541 $sql .=
"elementtype,";
543 $sql .=
"extraparams,";
545 $sql .=
"email_msgid,";
546 $sql .=
"email_from,";
547 $sql .=
"email_sender,";
549 $sql .=
"email_tocc,";
550 $sql .=
"email_tobcc,";
551 $sql .=
"email_subject,";
552 $sql .=
"errors_to,";
554 $sql .=
"recurrule,";
555 $sql .=
"recurdateend,";
557 $sql .=
"event_paid,";
560 $sql .=
") VALUES (";
561 $sql .=
"'(PROV)', ";
562 $sql .=
"'".$this->db->idate($now).
"', ";
563 $sql .=
"'".$this->db->idate($this->datep).
"', ";
564 $sql .= (strval($this->datef) !=
'' ?
"'".$this->db->idate($this->datef).
"'" :
"null").
", ";
565 $sql .= ((isset($this->durationp) && $this->durationp >= 0 && $this->durationp !=
'') ?
"'".$this->
db->escape($this->durationp).
"'" :
"null").
", ";
566 $sql .= (isset($this->type_id) ? $this->type_id :
"null").
",";
567 $sql .= ($code ? (
"'".$this->db->escape($code).
"'") :
"null").
", ";
568 $sql .= (!empty($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
", ";
569 $sql .= ((isset($this->socid) && $this->socid > 0) ? ((
int) $this->socid) :
"null").
", ";
570 $sql .= ((isset($this->fk_project) && $this->fk_project > 0) ? ((
int) $this->fk_project) :
"null").
", ";
571 $sql .=
" '".$this->db->escape($this->note_private).
"', ";
572 $sql .= ((isset($this->contact_id) && $this->contact_id > 0) ? ((
int) $this->contact_id) :
"null").
", ";
573 $sql .= (isset($user->id) && $user->id > 0 ? $user->id :
"null").
", ";
574 $sql .= ($userownerid > 0 ? $userownerid :
"null").
", ";
575 $sql .= ($userdoneid > 0 ? $userdoneid :
"null").
", ";
576 $sql .=
"'".$this->db->escape($this->label).
"', ";
577 $sql .=
"'".$this->db->escape($this->percentage).
"', ";
578 $sql .=
"'".$this->db->escape($this->priority).
"', ";
579 $sql .=
"'".$this->db->escape($this->fulldayevent).
"', ";
580 $sql .=
"'".$this->db->escape($this->location).
"', ";
581 $sql .=
"'".$this->db->escape($this->transparency).
"', ";
582 $sql .= (!empty($this->fk_element) ? ((int) $this->fk_element) :
"null").
", ";
583 $sql .= (!empty($this->elementtype) ?
"'".$this->db->escape($this->elementtype).
"'" :
"null").
", ";
584 $sql .= ((int) $conf->entity).
",";
585 $sql .= (!empty($this->extraparams) ?
"'".$this->db->escape($this->extraparams).
"'" :
"null").
", ";
587 $sql .= (!empty($this->email_msgid) ?
"'".$this->db->escape($this->email_msgid).
"'" :
"null").
", ";
588 $sql .= (!empty($this->email_from) ?
"'".$this->db->escape($this->email_from).
"'" :
"null").
", ";
589 $sql .= (!empty($this->email_sender) ?
"'".$this->db->escape($this->email_sender).
"'" :
"null").
", ";
590 $sql .= (!empty($this->email_to) ?
"'".$this->db->escape($this->email_to).
"'" :
"null").
", ";
591 $sql .= (!empty($this->email_tocc) ?
"'".$this->db->escape($this->email_tocc).
"'" :
"null").
", ";
592 $sql .= (!empty($this->email_tobcc) ?
"'".$this->db->escape($this->email_tobcc).
"'" :
"null").
", ";
593 $sql .= (!empty($this->email_subject) ?
"'".$this->db->escape($this->email_subject).
"'" :
"null").
", ";
594 $sql .= (!empty($this->errors_to) ?
"'".$this->db->escape($this->errors_to).
"'" :
"null").
", ";
595 $sql .= (!empty($this->recurid) ?
"'".$this->db->escape($this->recurid).
"'" :
"null").
", ";
596 $sql .= (!empty($this->recurrule) ?
"'".$this->db->escape($this->recurrule).
"'" :
"null").
", ";
597 $sql .= (!empty($this->recurdateend) ?
"'".$this->db->idate($this->recurdateend).
"'" :
"null").
", ";
598 $sql .= (!empty($this->num_vote) ? (int) $this->num_vote :
"null").
", ";
599 $sql .= (!empty($this->event_paid) ? (int) $this->event_paid : 0).
", ";
600 $sql .= (!empty($this->status) ? (int) $this->status :
"0").
", ";
601 $sql .= (!empty($this->ip) ?
"'".$this->db->escape($this->ip).
"'" :
"null");
604 dol_syslog(get_class($this).
"::add", LOG_DEBUG);
607 $this->
ref = $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"actioncomm",
"id");
608 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm SET ref='".$this->
db->escape($this->
ref).
"' WHERE id=".$this->id;
612 dol_syslog(
'Error to process ref: '.$this->
db->lasterror(), LOG_ERR);
613 $this->errors[] = $this->
db->lasterror();
618 $already_inserted = array();
619 foreach ($this->userassigned as $key => $val) {
621 if (!is_array($val)) {
622 $val = array(
'id'=>$val);
625 if ($val[
'id'] > 0) {
626 if (!empty($already_inserted[$val[
'id']])) {
630 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
631 $sql .=
" VALUES(".((int) $this->
id).
", 'user', ".((int) $val[
'id']).
", ".(empty($val[
'mandatory']) ?
'0' : ((int) $val[
'mandatory'])).
", ".(empty($val[
'transparency']) ?
'0' : ((int) $val[
'transparency'])).
", ".(empty($val[
'answer_status']) ?
'0' : ((int) $val[
'answer_status'])).
")";
636 dol_syslog(
'Error to process userassigned: ' . $this->
db->lasterror(), LOG_ERR);
637 $this->errors[] = $this->
db->lasterror();
639 $already_inserted[$val[
'id']] =
true;
647 if (!empty($this->socpeopleassigned)) {
648 $already_inserted = array();
649 foreach ($this->socpeopleassigned as $id => $val) {
651 if (!empty($already_inserted[$id])) {
655 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
656 $sql .=
" VALUES(".((int) $this->
id).
", 'socpeople', ".((int) $id).
", 0, 0, 0)";
661 dol_syslog(
'Error to process socpeopleassigned: ' . $this->
db->lasterror(), LOG_ERR);
662 $this->errors[] = $this->
db->lasterror();
664 $already_inserted[$id] =
true;
678 if (!$error && !$notrigger) {
691 $this->
db->rollback();
695 $this->
db->rollback();
696 $this->error = $this->
db->lasterror();
717 $objFrom = clone $this;
728 $this->recurrule =
'';
729 $this->recurdateend =
'';
732 $this->context[
'createfromclone'] =
'createfromclone';
733 $result = $this->
create($fuser);
740 if (is_object($hookmanager)) {
741 $parameters = array(
'objFrom'=>$objFrom);
743 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
745 $this->errors += $hookmanager->errors;
746 $this->error = $hookmanager->error;
759 unset($this->context[
'createfromclone']);
766 $this->
db->rollback();
781 public function fetch($id, $ref =
'', $ref_ext =
'', $email_msgid =
'', $loadresources = 1)
785 if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) {
786 dol_syslog(get_class($this).
"::fetch Bad parameters", LOG_WARNING);
790 $sql =
"SELECT a.id,";
791 $sql .=
" a.ref as ref,";
792 $sql .=
" a.entity,";
793 $sql .=
" a.ref_ext,";
795 $sql .=
" a.datep2,";
796 $sql .=
" a.durationp,";
798 $sql .=
" a.tms as datem,";
799 $sql .=
" a.code, a.label, a.note as note_private,";
800 $sql .=
" a.fk_soc,";
801 $sql .=
" a.fk_project,";
802 $sql .=
" a.fk_user_author, a.fk_user_mod,";
803 $sql .=
" a.fk_user_action, a.fk_user_done,";
804 $sql .=
" a.fk_contact, a.percent as percentage,";
805 $sql .=
" a.fk_element as elementid, a.elementtype,";
806 $sql .=
" a.priority, a.fulldayevent, a.location, a.transparency,";
807 $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,";
808 $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,";
809 $sql .=
" s.nom as socname,";
810 $sql .=
" u.firstname, u.lastname as lastname,";
811 $sql .=
" num_vote, event_paid, a.status";
812 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a ";
813 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_actioncomm as c ON a.fk_action=c.id ";
814 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = a.fk_user_author";
815 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = a.fk_soc";
818 $sql .=
" a.ref = '".$this->db->escape($ref).
"'";
819 } elseif ($ref_ext) {
820 $sql .=
" a.ref_ext = '".$this->db->escape($ref_ext).
"'";
821 } elseif ($email_msgid) {
822 $sql .=
" a.email_msgid = '".$this->db->escape($email_msgid).
"'";
824 $sql .=
" a.id = ".((int) $id);
827 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
832 $obj = $this->
db->fetch_object(
$resql);
834 $this->
id = $obj->id;
835 $this->entity = $obj->entity;
836 $this->
ref = $obj->ref;
837 $this->ref_ext = $obj->ref_ext;
840 $this->type_id = $obj->type_id;
841 $this->type_code = $obj->type_code;
842 $this->type_color = $obj->type_color;
843 $this->type_picto = $obj->type_picto;
844 $this->
type = $obj->type_type;
847 $transcode = $langs->trans(
"Action".$obj->type_code.
'Short');
848 $this->type_short = (($transcode !=
"Action".$obj->type_code.
'Short') ? $transcode :
'');
850 $this->
code = $obj->code;
851 $this->label = $obj->label;
852 $this->datep = $this->
db->jdate($obj->datep);
853 $this->datef = $this->
db->jdate($obj->datep2);
855 $this->datec = $this->
db->jdate($obj->datec);
856 $this->datem = $this->
db->jdate($obj->datem);
858 $this->note = $obj->note_private;
859 $this->note_private = $obj->note_private;
860 $this->percentage = $obj->percentage;
862 $this->authorid = $obj->fk_user_author;
863 $this->usermodid = $obj->fk_user_mod;
865 if (!is_object($this->author)) {
866 $this->author =
new User($this->
db);
868 $this->author->id = $obj->fk_user_author;
869 $this->author->firstname = $obj->firstname;
870 $this->author->lastname = $obj->lastname;
871 if (!is_object($this->usermod)) {
872 $this->usermod =
new User($this->
db);
874 $this->usermod->id = $obj->fk_user_mod;
876 $this->userownerid = $obj->fk_user_action;
877 $this->priority = $obj->priority;
878 $this->fulldayevent = $obj->fulldayevent;
879 $this->location = $obj->location;
880 $this->transparency = $obj->transparency;
882 $this->socid = $obj->fk_soc;
883 $this->contact_id = $obj->fk_contact;
884 $this->fk_project = $obj->fk_project;
889 $this->fk_element = $obj->elementid;
890 $this->elementid = $obj->elementid;
891 $this->elementtype = $obj->elementtype;
893 $this->num_vote = $obj->num_vote;
894 $this->event_paid = $obj->event_paid;
895 $this->status = $obj->status;
898 $this->email_msgid=$obj->email_msgid;
899 $this->email_from=$obj->email_from;
900 $this->email_sender=$obj->email_sender;
901 $this->email_to=$obj->email_to;
902 $this->email_tocc=$obj->email_tocc;
903 $this->email_tobcc=$obj->email_tobcc;
904 $this->email_subject=$obj->email_subject;
905 $this->errors_to=$obj->errors_to;
909 if ($loadresources) {
916 $this->error = $this->
db->lasterror();
930 $this->userassigned = array();
931 $this->socpeopleassigned = array();
933 $sql =
'SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency';
934 $sql .=
' FROM '.MAIN_DB_PREFIX.
'actioncomm_resources';
935 $sql .=
' WHERE fk_actioncomm = '.((int) $this->
id);
936 $sql .=
" AND element_type IN ('user', 'socpeople')";
940 if ($this->userownerid > 0) {
941 $this->userassigned[$this->userownerid] = array(
'id'=>$this->userownerid);
944 while ($obj = $this->
db->fetch_object(
$resql)) {
945 if ($obj->fk_element > 0) {
946 switch ($obj->element_type) {
948 $this->userassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
'mandatory'=>$obj->mandatory,
'answer_status'=>$obj->answer_status,
'transparency'=>$obj->transparency);
949 if (empty($this->userownerid)) {
950 $this->userownerid = $obj->fk_element;
954 $this->socpeopleassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
'mandatory'=>$obj->mandatory,
'answer_status'=>$obj->answer_status,
'transparency'=>$obj->transparency);
977 $sql =
"SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency";
978 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm_resources";
979 $sql .=
" WHERE element_type = 'user' AND fk_actioncomm = ".((int) $this->
id);
981 $resql2 = $this->
db->query($sql);
983 $this->userassigned = array();
986 if ($this->userownerid > 0) {
988 $this->userassigned[$this->userownerid] = array(
'id'=>$this->userownerid);
991 while ($obj = $this->
db->fetch_object($resql2)) {
992 if ($obj->fk_element > 0) {
993 $this->userassigned[$obj->fk_element] = array(
'id'=>$obj->fk_element,
994 'mandatory'=>$obj->mandatory,
995 'answer_status'=>$obj->answer_status,
996 'transparency'=>$obj->transparency);
999 if ($override ===
true) {
1001 if (empty($this->userownerid)) {
1002 $this->userownerid = $obj->fk_element;
1020 public function delete($notrigger = 0)
1026 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1032 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_actioncomm";
1033 $sql .=
" WHERE fk_actioncomm=".((int) $this->
id);
1035 $res = $this->
db->query($sql);
1037 $this->error = $this->
db->lasterror();
1044 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources";
1045 $sql .=
" WHERE fk_actioncomm=".((int) $this->
id);
1047 $res = $this->
db->query($sql);
1049 $this->error = $this->
db->lasterror();
1055 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
1056 $sql .=
" WHERE fk_actioncomm = ".((int) $this->
id);
1058 $res = $this->
db->query($sql);
1060 $this->error = $this->
db->lasterror();
1070 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1076 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm";
1077 $sql .=
" WHERE id=".((int) $this->
id);
1079 $res = $this->
db->query($sql);
1081 $this->error = $this->
db->lasterror();
1097 $this->
db->commit();
1100 $this->
db->rollback();
1104 $this->
db->rollback();
1105 $this->error = $this->
db->lasterror();
1120 global $langs, $conf, $hookmanager;
1125 $this->label = trim($this->label);
1126 $this->note_private =
dol_htmlcleanlastbr(trim(!isset($this->note_private) ? $this->note : $this->note_private));
1127 if (empty($this->percentage)) {
1128 $this->percentage = 0;
1130 if (empty($this->priority) || !is_numeric($this->priority)) {
1131 $this->priority = 0;
1133 if (empty($this->transparency)) {
1134 $this->transparency = 0;
1136 if (empty($this->fulldayevent)) {
1137 $this->fulldayevent = 0;
1139 if ($this->percentage > 100) {
1140 $this->percentage = 100;
1143 if ($this->datep && $this->datef) {
1144 $this->durationp = ($this->datef - $this->datep);
1147 if ($this->datep && $this->datef && $this->datep > $this->datef) {
1148 $this->datef = $this->datep;
1151 if ($this->fk_project < 0) {
1152 $this->fk_project = 0;
1156 if ($this->percentage == 0 && $this->userdoneid > 0) {
1157 $this->error =
"ErrorCantSaveADoneUserWithZeroPercentage";
1161 $socid = (($this->socid > 0) ? $this->socid : 0);
1162 $contactid = (($this->contact_id > 0) ? $this->contact_id : 0);
1163 $userownerid = ($this->userownerid ? $this->userownerid : 0);
1164 $userdoneid = ($this->userdoneid ? $this->userdoneid : 0);
1167 if ($this->type_id > 0) {
1168 if (empty($this->type_code)) {
1170 $result = $cactioncomm->fetch($this->type_id);
1171 if ($result >= 0 && !empty($cactioncomm->code)) {
1172 $this->type_code = $cactioncomm->code;
1177 $code = $this->code;
1178 if (empty($code) || (!empty($this->oldcopy) && $this->oldcopy->type_code != $this->type_code)) {
1179 $code = $this->type_code;
1184 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm";
1185 $sql .=
" SET percent = '".$this->db->escape($this->percentage).
"'";
1186 $sql .=
", fk_action = ".(int) $this->type_id;
1187 $sql .=
", code = " . ($code ?
"'".$this->db->escape($code).
"'" :
"null");
1188 $sql .=
", label = ".($this->label ?
"'".$this->db->escape($this->label).
"'" :
"null");
1189 $sql .=
", datep = ".(strval($this->datep) !=
'' ?
"'".$this->db->idate($this->datep).
"'" :
'null');
1190 $sql .=
", datep2 = ".(strval($this->datef) !=
'' ?
"'".$this->db->idate($this->datef).
"'" :
'null');
1191 $sql .=
", durationp = ".(isset($this->durationp) && $this->durationp >= 0 && $this->durationp !=
'' ?
"'".$this->db->escape($this->durationp).
"'" :
"null");
1192 $sql .=
", note = '".$this->db->escape($this->note_private).
"'";
1193 $sql .=
", fk_project =".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1194 $sql .=
", fk_soc =".($socid > 0 ? ((int) $socid) :
"null");
1195 $sql .=
", fk_contact =".($contactid > 0 ? ((int) $contactid) :
"null");
1196 $sql .=
", priority = '".$this->db->escape($this->priority).
"'";
1197 $sql .=
", fulldayevent = '".$this->db->escape($this->fulldayevent).
"'";
1198 $sql .=
", location = ".($this->location ?
"'".$this->db->escape($this->location).
"'" :
"null");
1199 $sql .=
", transparency = '".$this->db->escape($this->transparency).
"'";
1200 $sql .=
", fk_user_mod = ".((int) $user->id);
1201 $sql .=
", fk_user_action = ".($userownerid > 0 ? ((int) $userownerid) :
"null");
1202 $sql .=
", fk_user_done = ".($userdoneid > 0 ? ((int) $userdoneid) :
"null");
1203 if (!empty($this->fk_element)) {
1204 $sql .=
", fk_element=".($this->fk_element ? ((int) $this->fk_element) :
"null");
1206 if (!empty($this->elementtype)) {
1207 $sql .=
", elementtype=".($this->elementtype ?
"'".$this->db->escape($this->elementtype).
"'" :
"null");
1209 if (!empty($this->num_vote)) {
1210 $sql .=
", num_vote=".($this->num_vote ? (int) $this->num_vote :
null);
1212 if (!empty($this->event_paid)) {
1213 $sql .=
", event_paid=".($this->event_paid ? (int) $this->event_paid : 0);
1215 if (!empty($this->status)) {
1216 $sql .=
", status=".($this->status ? (int) $this->status : 0);
1218 $sql .=
" WHERE id=".((int) $this->
id);
1220 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1221 if ($this->
db->query($sql)) {
1234 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources where fk_actioncomm = ".((int) $this->
id).
" AND element_type = 'user'";
1237 $already_inserted = array();
1238 foreach ($this->userassigned as $key => $val) {
1239 if (!is_array($val)) {
1240 $val = array(
'id'=>$val);
1242 if (!empty($already_inserted[$val[
'id']]))
continue;
1244 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1245 $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'])).
")";
1250 $this->errors[] = $this->
db->lasterror();
1252 $already_inserted[$val[
'id']] =
true;
1259 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_resources where fk_actioncomm = ".((int) $this->
id).
" AND element_type = 'socpeople'";
1262 if (!empty($this->socpeopleassigned)) {
1263 $already_inserted = array();
1264 foreach (array_keys($this->socpeopleassigned) as $key => $val) {
1265 if (!is_array($val)) {
1266 $val = array(
'id'=>$val);
1268 if (!empty($already_inserted[$val[
'id']]))
continue;
1270 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1271 $sql .=
" VALUES(".((int) $this->
id).
", 'socpeople', ".((int) $val[
'id']).
", 0, 0, 0)";
1276 $this->errors[] = $this->
db->lasterror();
1278 $already_inserted[$val[
'id']] =
true;
1284 if (!$error && !$notrigger) {
1294 $this->
db->commit();
1297 $this->
db->rollback();
1298 dol_syslog(get_class($this).
"::update ".join(
',', $this->errors), LOG_ERR);
1302 $this->
db->rollback();
1303 $this->error = $this->
db->lasterror();
1321 public function getActions($socid = 0, $fk_element = 0, $elementtype =
'', $filter =
'', $sortfield =
'a.datep', $sortorder =
'DESC', $limit = 0)
1323 global $conf, $langs;
1325 $resarray = array();
1327 dol_syslog(get_class().
"::getActions", LOG_DEBUG);
1329 require_once DOL_DOCUMENT_ROOT .
'/core/class/hookmanager.class.php';
1332 $hookmanager->initHooks(array(
'agendadao'));
1334 $sql =
"SELECT a.id";
1335 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
1337 $parameters = array(
'sql' => &$sql,
'socid' => $socid,
'fk_element' => $fk_element,
'elementtype' => $elementtype);
1338 $reshook = $hookmanager->executeHooks(
'getActionsListFrom', $parameters);
1339 if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1340 $sql .=
" WHERE a.entity IN (".getEntity(
'agenda').
")";
1341 if (!empty($socid)) {
1342 $sql .=
" AND a.fk_soc = ".((int) $socid);
1344 if (!empty($elementtype)) {
1345 if ($elementtype ==
'project') {
1346 $sql .=
' AND a.fk_project = '.((int) $fk_element);
1347 } elseif ($elementtype ==
'contact') {
1348 $sql .=
' AND a.id IN';
1349 $sql .=
" (SELECT fk_actioncomm FROM ".MAIN_DB_PREFIX.
"actioncomm_resources WHERE";
1350 $sql .=
" element_type = 'socpeople' AND fk_element = ".((int) $fk_element).
')';
1352 $sql .=
" AND a.fk_element = ".((int) $fk_element).
" AND a.elementtype = '".$this->
db->escape($elementtype).
"'";
1355 if (!empty($filter)) {
1359 $parameters = array(
'sql' => &$sql,
'socid' => $socid,
'fk_element' => $fk_element,
'elementtype' => $elementtype);
1360 $reshook = $hookmanager->executeHooks(
'getActionsListWhere', $parameters);
1361 if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1362 if ($sortorder && $sortfield) {
1363 $sql .= $this->
db->order($sortfield, $sortorder);
1365 $sql .= $this->
db->plimit($limit, 0);
1369 $num = $this->
db->num_rows(
$resql);
1372 for ($i = 0; $i < $num; $i++) {
1373 $obj = $this->
db->fetch_object(
$resql);
1375 $actioncommstatic->fetch($obj->id);
1376 $resarray[$i] = $actioncommstatic;
1382 return $this->
db->lasterror();
1397 global $conf, $langs;
1399 if (empty($load_state_board)) {
1400 $sql =
"SELECT a.id, a.datep as dp";
1402 $this->nb = array();
1403 $sql =
"SELECT count(a.id) as nb";
1405 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
1406 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1407 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
1409 if (empty($user->rights->agenda->allactions->read)) {
1410 $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);
1412 $sql .=
" WHERE 1 = 1";
1413 if (empty($load_state_board)) {
1414 $sql .=
" AND a.percent >= 0 AND a.percent < 100";
1416 $sql .=
" AND a.entity IN (".getEntity(
'agenda').
")";
1417 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1418 $sql .=
" AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).
")";
1421 $sql .=
" AND a.fk_soc = ".((int) $user->socid);
1423 if (empty($user->rights->agenda->allactions->read)) {
1424 $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);
1425 $sql .=
" OR ar.fk_element = ".((int) $user->id);
1431 if (empty($load_state_board)) {
1434 $response->warning_delay = $conf->agenda->warning_delay / 60 / 60 / 24;
1435 $response->label = $langs->trans(
"ActionsToDo");
1436 $response->labelShort = $langs->trans(
"ActionsToDoShort");
1437 $response->url = DOL_URL_ROOT.
'/comm/action/list.php?mode=show_list&actioncode=0&status=todo&mainmenu=agenda';
1438 if ($user->hasRight(
"agenda",
"allactions",
"read")) {
1439 $response->url .=
'&filtert=-1';
1441 $response->img =
img_object(
'',
"action",
'class="inline-block valigntextmiddle"');
1444 while ($obj = $this->
db->fetch_object(
$resql)) {
1445 if (empty($load_state_board)) {
1446 $response->nbtodo++;
1447 $agenda_static->datep = $this->
db->jdate($obj->dp);
1448 if ($agenda_static->hasDelay()) {
1449 $response->nbtodolate++;
1452 $this->nb[
"actionscomm"] = $obj->nb;
1457 if (empty($load_state_board)) {
1464 $this->error = $this->
db->error();
1481 $sql .=
' tms as datem,';
1482 $sql .=
' fk_user_author,';
1483 $sql .=
' fk_user_mod';
1484 $sql .=
' FROM '.MAIN_DB_PREFIX.
'actioncomm as a';
1485 $sql .=
' WHERE a.id = '.((int) $id);
1487 dol_syslog(get_class($this).
"::info", LOG_DEBUG);
1488 $result = $this->
db->query($sql);
1490 if ($this->
db->num_rows($result)) {
1491 $obj = $this->
db->fetch_object($result);
1492 $this->
id = $obj->id;
1493 $this->user_creation_id = $obj->fk_user_author;
1494 $this->user_modification_id = $obj->fk_user_mod;
1495 $this->date_creation = $this->
db->jdate($obj->datec);
1496 $this->date_modification = empty($obj->datem) ?
'' : $this->
db->jdate($obj->datem);
1498 $this->
db->free($result);
1514 return $this->
LibStatut($this->percentage, $mode, $hidenastatus, $this->datep);
1527 public function LibStatut($percent, $mode, $hidenastatus = 0, $datestart =
'')
1532 $labelStatus = $langs->transnoentitiesnoconv(
'StatusNotApplicable');
1533 if ($percent == -1 && !$hidenastatus) {
1534 $labelStatus = $langs->transnoentitiesnoconv(
'StatusNotApplicable');
1535 } elseif ($percent == 0) {
1536 $labelStatus = $langs->transnoentitiesnoconv(
'StatusActionToDo').
' (0%)';
1537 } elseif ($percent > 0 && $percent < 100) {
1538 $labelStatus = $langs->transnoentitiesnoconv(
'StatusActionInProcess').
' ('.$percent.
'%)';
1539 } elseif ($percent >= 100) {
1540 $labelStatus = $langs->transnoentitiesnoconv(
'StatusActionDone').
' (100%)';
1543 $labelStatusShort = $langs->transnoentitiesnoconv(
'StatusNotApplicable');
1544 if ($percent == -1 && !$hidenastatus) {
1545 $labelStatusShort = $langs->trans(
'NA');
1546 } elseif ($percent == 0) {
1547 $labelStatusShort =
'0%';
1548 } elseif ($percent > 0 && $percent < 100) {
1549 $labelStatusShort = $percent.
'%';
1550 } elseif ($percent >= 100) {
1551 $labelStatusShort =
'100%';
1554 $statusType =
'status9';
1555 if ($percent == -1 && !$hidenastatus) {
1556 $statusType =
'status9';
1558 if ($percent == 0) {
1559 $statusType =
'status1';
1561 if ($percent > 0 && $percent < 100) {
1562 $statusType =
'status3';
1564 if ($percent >= 100) {
1565 $statusType =
'status6';
1568 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode);
1584 public function getNomUrl($withpicto = 0, $maxlength = 0, $classname =
'', $option =
'', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
1586 global $conf, $langs, $user, $hookmanager, $action;
1588 if (!empty($conf->dol_no_mouse_hover)) {
1593 if ($user->hasRight(
'agenda',
'myactions',
'read') && ($this->authorid == $user->id || $this->userownerid == $user->id)) {
1596 if (!empty($user->rights->agenda->myactions->read) && array_key_exists($user->id, $this->userassigned)) {
1599 if (!empty($user->rights->agenda->allactions->read)) {
1606 $label = $this->label;
1607 if (empty($label)) {
1608 $label = $this->libelle;
1615 if ($this->type_code) {
1616 $labeltype = ($langs->transnoentities(
"Action".$this->type_code) !=
"Action".$this->type_code) ? $langs->transnoentities(
"Action".$this->type_code) : $this->type_label;
1618 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1619 if ($this->type_code !=
'AC_OTH_AUTO') {
1620 $labeltype = $langs->trans(
'ActionAC_MANUAL');
1624 $tooltip =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
'Action').
'</u>';
1625 if (!empty($this->
ref)) {
1628 if (!empty($label)) {
1631 if (!empty($labeltype)) {
1634 if (!empty($this->location)) {
1635 $tooltip .=
'<br><b>'.$langs->trans(
'Location').
':</b> '.
dol_escape_htmltag($this->location);
1637 if (isset($this->transparency)) {
1638 $tooltip .=
'<br><b>'.$langs->trans(
'Busy').
':</b> '.
yn($this->transparency);
1640 if (!empty($this->email_msgid)) {
1641 $langs->load(
"mails");
1644 $tooltip .=
'<br><b>'.$langs->trans(
'MailTopic').
':</b> '.
dol_escape_htmltag($this->email_subject);
1645 $tooltip .=
'<br><b>'.$langs->trans(
'MailFrom').
':</b> '.str_replace(array(
'<',
'>'), array(
'&lt',
'&gt'), $this->email_from);
1646 $tooltip .=
'<br><b>'.$langs->trans(
'MailTo').
':</b> '.str_replace(array(
'<',
'>'), array(
'&lt',
'&gt'), $this->email_to);
1647 if (!empty($this->email_tocc)) {
1648 $tooltip .=
'<br><b>'.$langs->trans(
'MailCC').
':</b> '.str_replace(array(
'<',
'>'), array(
'&lt',
'&gt'), $this->email_tocc);
1655 if (!empty($this->note_private)) {
1656 $tooltip .=
'<br><br><b>'.$langs->trans(
'Description').
':</b><br>';
1658 $tooltip .=
'<div class="tenlinesmax">';
1659 $tooltip .= (
dol_textishtml($texttoshow) ? str_replace(array(
"\r",
"\n"),
"", $texttoshow) : str_replace(array(
"\r",
"\n"),
'<br>', $texttoshow));
1660 $tooltip .=
'</div>';
1666 if (empty($notooltip)) {
1667 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1668 $label = $langs->trans(
"ShowAction");
1669 $linkclose .=
' alt="'.dol_escape_htmltag($tooltip, 1).
'"';
1671 $linkclose .=
' title="'.dol_escape_htmltag($tooltip, 1, 0,
'', 1).
'"';
1672 $linkclose .=
' class="'.$classname.
' classfortooltip"';
1674 $linkclose .=
' class="'.$classname.
'"';
1678 if ($option ==
'birthday') {
1679 $url = DOL_URL_ROOT.
'/contact/perso.php?id='.$this->id;
1680 } elseif ($option ==
'holiday') {
1681 $url = DOL_URL_ROOT.
'/holiday/card.php?id='.$this->id;
1683 $url = DOL_URL_ROOT.
'/comm/action/card.php?id='.$this->id;
1686 if ($option !==
'nolink') {
1688 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1689 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1690 $add_save_lastsearch_values = 1;
1692 if ($add_save_lastsearch_values) {
1693 $url .=
'&save_lastsearch_values=1';
1697 $linkstart =
'<a href="'.$url.
'"';
1698 $linkstart .= $linkclose.
'>';
1701 if ($option ==
'nolink') {
1706 if ($withpicto == 2) {
1707 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1708 $label = $labeltype;
1712 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($label)) {
1713 $label = $labeltype;
1715 if ($maxlength < 0) {
1716 $labelshort = $this->ref;
1718 $labelshort =
dol_trunc($label, $maxlength);
1723 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1725 $label .= (preg_match(
'/'.preg_quote($labeltype,
'/').
'/', $label) ?
'' :
' ('.$langs->transnoentities(
"Action".$this->type_code).
')');
1730 $result .= $linkstart;
1732 $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);
1735 $result .= $linkend;
1738 $hookmanager->initHooks(array(
'actiondao'));
1739 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1740 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1742 $result = $hookmanager->resPrint;
1744 $result .= $hookmanager->resPrint;
1760 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1762 if ($this->type_color) {
1763 $color =
'style="color: #'.$this->type_color.
' !important;"';
1765 if ($this->type_picto) {
1766 $imgpicto =
img_picto(
'', $this->type_picto,
'class="paddingright"');
1768 if ($this->type_code ==
'AC_RDV') {
1769 $imgpicto =
img_picto(
'',
'meeting', $color,
false, 0, 0,
'',
'paddingright');
1770 } elseif ($this->type_code ==
'AC_TEL') {
1771 $imgpicto =
img_picto(
'',
'object_phoning', $color,
false, 0, 0,
'',
'paddingright');
1772 } elseif ($this->type_code ==
'AC_FAX') {
1773 $imgpicto =
img_picto(
'',
'object_phoning_fax', $color,
false, 0, 0,
'',
'paddingright');
1774 } elseif ($this->type_code ==
'AC_EMAIL' || $this->type_code ==
'AC_EMAIL_IN' || preg_match(
'/_SENTBYMAIL/', $this->
code)) {
1775 $imgpicto =
img_picto(
'',
'object_email', $color,
false, 0, 0,
'',
'paddingright');
1776 } elseif ($this->type_code ==
'AC_INT') {
1777 $imgpicto =
img_picto(
'',
'object_intervention', $color,
false, 0, 0,
'',
'paddingright');
1778 } elseif (preg_match(
'/^TICKET_MSG/', $this->
code)) {
1779 $imgpicto =
img_picto(
'',
'object_conversation', $color,
false, 0, 0,
'',
'paddingright');
1780 } elseif ($this->
type !=
'systemauto') {
1781 $imgpicto =
img_picto(
'',
'user-cog', $color,
false, 0, 0,
'',
'paddingright');
1783 $imgpicto =
img_picto(
'',
'cog', $color,
false, 0, 0,
'',
'paddingright');
1788 if ($this->
type !=
'systemauto') {
1789 $imgpicto =
img_picto(
'',
'user-cog',
'',
false, 0, 0,
'',
'paddingright');
1791 $imgpicto =
img_picto(
'',
'cog',
'',
false, 0, 0,
'',
'paddingright');
1811 if (!is_array($categories)) {
1812 $categories = array($categories);
1816 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1818 $existing = $c->containing($this->
id, Categorie::TYPE_ACTIONCOMM,
'id');
1821 if (is_array($existing)) {
1822 $to_del = array_diff($existing, $categories);
1823 $to_add = array_diff($categories, $existing);
1826 $to_add = $categories;
1830 foreach ($to_del as $del) {
1831 if ($c->fetch($del) > 0) {
1832 $c->del_type($this, Categorie::TYPE_ACTIONCOMM);
1835 foreach ($to_add as $add) {
1836 if ($c->fetch($add) > 0) {
1837 $c->add_type($this, Categorie::TYPE_ACTIONCOMM);
1855 public function build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday = 0)
1857 global $hookmanager;
1860 global $conf, $langs, $dolibarr_main_url_root, $mysoc;
1862 require_once DOL_DOCUMENT_ROOT.
"/core/lib/xcal.lib.php";
1863 require_once DOL_DOCUMENT_ROOT.
"/core/lib/date.lib.php";
1864 require_once DOL_DOCUMENT_ROOT.
"/core/lib/files.lib.php";
1866 dol_syslog(get_class($this).
"::build_exportfile Build export file format=".$format.
", type=".$type.
", cachedelay=".$cachedelay.
", filename=".$filename.
", filters size=".count($filters), LOG_DEBUG);
1869 if (empty($format)) {
1876 if ($format ==
'ical') {
1879 $filename = $format.
'.'.$extension;
1883 $result =
dol_mkdir($conf->agenda->dir_temp);
1884 $outputfile = $conf->agenda->dir_temp.
'/'.$filename;
1889 $login =
''; $logina =
''; $logind =
''; $logint =
'';
1895 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1897 dol_syslog(get_class($this).
"::build_exportfile file ".$outputfile.
" is not older than now - cachedelay (".$nowgmt.
" - ".$cachedelay.
"). Build is canceled");
1904 $eventarray = array();
1906 $sql =
"SELECT a.id,";
1907 $sql .=
" a.datep,";
1908 $sql .=
" a.datep2,";
1909 $sql .=
" a.durationp,";
1910 $sql .=
" a.datec, a.tms as datem,";
1911 $sql .=
" a.label, a.code, a.note as note_private, a.fk_action as type_id,";
1912 $sql .=
" a.fk_soc,";
1913 $sql .=
" a.fk_user_author, a.fk_user_mod,";
1914 $sql .=
" a.fk_user_action,";
1915 $sql .=
" a.fk_contact, a.percent as percentage,";
1916 $sql .=
" a.fk_element, a.elementtype,";
1917 $sql .=
" a.priority, a.fulldayevent, a.location, a.transparency,";
1918 $sql .=
" u.firstname, u.lastname, u.email,";
1919 $sql .=
" s.nom as socname,";
1920 $sql .=
" c.id as type_id, c.code as type_code, c.libelle as type_label,";
1921 $sql .=
" num_vote, event_paid, a.status";
1922 $sql .=
" FROM (".MAIN_DB_PREFIX.
"c_actioncomm as c, ".MAIN_DB_PREFIX.
"actioncomm as a)";
1923 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as u on u.rowid = a.fk_user_author";
1924 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s on s.rowid = a.fk_soc";
1926 $parameters = array(
'filters' => $filters);
1927 $reshook = $hookmanager->executeHooks(
'printFieldListFrom', $parameters);
1928 $sql .= $hookmanager->resPrint;
1931 if ($filters[
'logint']) {
1932 $sql .=
", ".MAIN_DB_PREFIX.
"actioncomm_resources as ar";
1934 $sql .=
" WHERE a.fk_action=c.id";
1935 $sql .=
" AND a.entity IN (".getEntity(
'agenda').
")";
1936 foreach ($filters as $key => $value) {
1937 if ($key ==
'notolderthan' && $value !=
'') {
1938 $sql .=
" AND a.datep >= '".$this->db->idate($now - ($value * 24 * 60 * 60)).
"'";
1940 if ($key ==
'year') {
1944 $sql .=
" AND a.id=".(is_numeric($value) ? $value : 0);
1946 if ($key ==
'idfrom') {
1947 $sql .=
" AND a.id >= ".(is_numeric($value) ? $value : 0);
1949 if ($key ==
'idto') {
1950 $sql .=
" AND a.id <= ".(is_numeric($value) ? $value : 0);
1952 if ($key ==
'project') {
1953 $sql .=
" AND a.fk_project=".(is_numeric($value) ? $value : 0);
1955 if ($key ==
'actiontype') {
1956 $sql .=
" AND c.type = '".$this->db->escape($value).
"'";
1958 if ($key ==
'notactiontype') {
1959 $sql .=
" AND c.type <> '".$this->db->escape($value).
"'";
1962 if ($key ==
'logint') {
1963 $sql .=
" AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
1965 if ($key ==
'logina') {
1968 if (preg_match(
'/^!/', $logina)) {
1969 $logina = preg_replace(
'/^!/',
'', $logina);
1972 $userforfilter =
new User($this->
db);
1973 $result = $userforfilter->fetch(
'', $logina);
1975 $sql .=
" AND a.fk_user_author ".$condition.
" ".$userforfilter->id;
1976 } elseif ($result < 0 || $condition ==
'=') {
1977 $sql .=
" AND a.fk_user_author = 0";
1980 if ($key ==
'logint') {
1983 if (preg_match(
'/^!/', $logint)) {
1984 $logint = preg_replace(
'/^!/',
'', $logint);
1987 $userforfilter =
new User($this->
db);
1988 $result = $userforfilter->fetch(
'', $logint);
1990 $sql .=
" AND ar.fk_element = ".((int) $userforfilter->id);
1991 } elseif ($result < 0 || $condition ==
'=') {
1992 $sql .=
" AND ar.fk_element = 0";
1995 if ($key ==
'module') {
1996 $sql .=
" AND c.module LIKE '%".$this->db->escape($value).
"'";
1998 if ($key ==
'status') {
1999 $sql .=
" AND a.status =".((int) $value);
2003 $sql .=
" AND a.datep IS NOT NULL";
2005 $parameters = array(
'filters' => $filters);
2006 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters);
2007 $sql .= $hookmanager->resPrint;
2009 $sql .=
" ORDER by datep";
2012 dol_syslog(get_class($this).
"::build_exportfile select events", LOG_DEBUG);
2018 while ($obj = $this->
db->fetch_object(
$resql)) {
2023 $event[
'uid'] =
'dolibarragenda-'.$this->db->database_name.
'-'.$obj->id.
"@".$_SERVER[
"SERVER_NAME"];
2024 $event[
'type'] = $type;
2026 $datestart = $this->
db->jdate($obj->datep) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2029 if (is_numeric($this->
db->jdate($obj->datep2))) {
2030 $dateend = $this->
db->jdate($obj->datep2) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2033 $dateend = $datestart;
2036 $duration = ($datestart && $dateend) ? ($dateend - $datestart) : 0;
2037 $event[
'summary'] = $obj->label.($obj->socname ?
" (".$obj->socname.
")" :
"");
2039 $event[
'desc'] = $obj->note_private;
2040 $event[
'startdate'] = $datestart;
2041 $event[
'enddate'] = $dateend;
2042 $event[
'duration'] = $duration;
2044 $event[
'priority'] = $obj->priority;
2045 $event[
'fulldayevent'] = $obj->fulldayevent;
2046 $event[
'location'] = $obj->location;
2047 $event[
'transparency'] = (($obj->transparency > 0) ?
'OPAQUE' :
'TRANSPARENT');
2048 $event[
'category'] = $obj->type_label;
2049 $event[
'email'] = $obj->email;
2051 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2052 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2054 $url = $urlwithroot.
'/comm/action/card.php?id='.$obj->id;
2055 $event[
'url'] = $url;
2056 $event[
'created'] = $this->
db->jdate($obj->datec) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2057 $event[
'modified'] = $this->
db->jdate($obj->datem) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2058 $event[
'num_vote'] = $this->num_vote;
2059 $event[
'event_paid'] = $this->event_paid;
2060 $event[
'status'] = $this->status;
2063 $this->
id = $obj->id;
2066 $assignedUserArray = array();
2068 foreach ($this->userassigned as $key => $value) {
2069 $assignedUser =
new User($this->
db);
2070 $assignedUser->fetch($value[
'id']);
2072 $assignedUserArray[$key] = $assignedUser;
2075 $event[
'assignedUsers'] = $assignedUserArray;
2077 if ($qualified && $datestart) {
2078 $eventarray[] = $event;
2083 $parameters = array(
'filters' => $filters,
'eventarray' => &$eventarray);
2084 $reshook = $hookmanager->executeHooks(
'addMoreEventsExport', $parameters);
2086 $eventarray = $hookmanager->resArray;
2089 $this->error = $this->
db->lasterror();
2093 if ($exportholiday == 1) {
2094 $langs->load(
"holiday");
2095 $title = $langs->trans(
"Holidays");
2097 $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";
2098 $sql .=
" FROM ".MAIN_DB_PREFIX.
"holiday as x, ".MAIN_DB_PREFIX.
"user as u";
2099 $sql .=
" WHERE u.rowid = x.fk_user";
2100 $sql .=
" AND u.statut = '1'";
2101 $sql .=
" AND (x.statut = '2' OR x.statut = '3')";
2105 $num = $this->
db->num_rows(
$resql);
2109 $obj = $this->
db->fetch_object(
$resql);
2112 if ($obj->halfday == -1) {
2113 $event[
'fulldayevent'] =
false;
2117 } elseif ($obj->halfday == 1) {
2118 $event[
'fulldayevent'] =
false;
2123 $event[
'fulldayevent'] =
true;
2129 if (!empty($conf->global->AGENDA_EXPORT_FIX_TZ)) {
2130 $timestampStart = $timestampStart - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2131 $timestampEnd = $timestampEnd - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2134 $urlwithouturlroot = preg_replace(
'/'.preg_quote(DOL_URL_ROOT,
'/').
'$/i',
'', trim($dolibarr_main_url_root));
2135 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2136 $url = $urlwithroot.
'/holiday/card.php?id='.$obj->rowid;
2138 $event[
'uid'] =
'dolibarrholiday-'.$this->db->database_name.
'-'.$obj->rowid.
"@".$_SERVER[
"SERVER_NAME"];
2140 $event[
'type'] =
'event';
2141 $event[
'category'] =
"Holiday";
2142 $event[
'transparency'] =
'OPAQUE';
2143 $event[
'email'] = $obj->email;
2144 $event[
'created'] = $timestampStart;
2145 $event[
'modified'] = $timestampStart;
2146 $event[
'startdate'] = $timestampStart;
2147 $event[
'enddate'] = $timestampEnd;
2148 $event[
'duration'] = $timestampEnd - $timestampStart;
2149 $event[
'url'] = $url;
2151 if ($obj->status == 2) {
2153 $event[
'summary'] = $title.
" - ".$obj->lastname.
" (wait for approval)";
2156 $event[
'summary'] = $title.
" - ".$obj->lastname;
2159 $eventarray[] = $event;
2166 $langs->load(
"agenda");
2171 $more = $langs->transnoentities(
"User").
' '.$login;
2174 $more = $langs->transnoentities(
"ActionsAskedBy").
' '.$logina;
2177 $more = $langs->transnoentities(
"ActionsToDoBy").
' '.$logint;
2180 $more = $langs->transnoentities(
"ActionsDoneBy").
' '.$logind;
2183 $title =
'Dolibarr actions '.$mysoc->name.
' - '.$more;
2185 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
2187 $title =
'Dolibarr actions '.$mysoc->name;
2188 $desc = $langs->transnoentities(
'ListOfActions');
2189 $desc .=
' ('.$mysoc->name.
' - built by Dolibarr)';
2193 $outputfiletmp = tempnam($conf->agenda->dir_temp,
'tmp');
2194 @chmod($outputfiletmp, octdec($conf->global->MAIN_UMASK));
2197 if ($format ==
'vcal') {
2198 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2199 } elseif ($format ==
'ical') {
2200 $result =
build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2201 } elseif ($format ==
'rss') {
2202 $result =
build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
2206 if (
dol_move($outputfiletmp, $outputfile, 0, 1, 0, 0)) {
2209 $this->error =
'Failed to rename '.$outputfiletmp.
' into '.$outputfile;
2210 dol_syslog(get_class($this).
"::build_exportfile ".$this->error, LOG_ERR);
2215 dol_syslog(get_class($this).
"::build_exportfile build_xxxfile function fails to for format=".$format.
" outputfiletmp=".$outputfile, LOG_ERR);
2217 $langs->load(
"errors");
2218 $this->error = $langs->trans(
"ErrorFailToCreateFile", $outputfile);
2240 $this->specimen = 1;
2242 $this->type_code =
'AC_OTH';
2243 $this->
code =
'AC_SPECIMEN_CODE';
2244 $this->label =
'Label of event Specimen';
2245 $this->datec = $now;
2246 $this->datem = $now;
2247 $this->datep = $now;
2248 $this->datef = $now;
2249 $this->fulldayevent = 0;
2250 $this->percentage = 0;
2252 $this->location =
'Location';
2253 $this->transparency = 1;
2254 $this->priority = 1;
2256 $this->note_private =
"This is a 'private' note.";
2258 $this->userownerid = $user->id;
2259 $this->userassigned[$user->id] = array(
'id'=>$user->id,
'transparency'=> 1);
2290 $sql =
'UPDATE ' . MAIN_DB_PREFIX .
'actioncomm SET fk_element = ' . ((int) $dest_id) .
' WHERE elementtype="product" AND fk_element = '.((int) $origin_id);
2292 if (!$dbs->
query($sql)) {
2311 return $this->datep && ($this->datep < ($now - $conf->agenda->warning_delay));
2325 global $conf, $langs, $user;
2329 $this->reminders = array();
2332 $sql =
"SELECT rowid as id, typeremind, dateremind, status, offsetvalue, offsetunit, fk_user";
2333 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2334 $sql .=
" WHERE fk_actioncomm = ".((int) $this->
id);
2336 $sql .=
" AND dateremind <= '".$this->db->idate(
dol_now()).
"'";
2339 $sql .=
" AND typeremind ='".$this->db->escape($type).
"'";
2342 $sql .=
" AND fk_user = ".((int) $fk_user);
2344 if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2345 $sql .=
" AND typeremind != 'email'";
2347 if (empty($conf->global->AGENDA_REMINDER_BROWSER)) {
2348 $sql .=
" AND typeremind != 'browser'";
2351 $sql .= $this->
db->order(
"dateremind",
"ASC");
2355 while ($obj = $this->
db->fetch_object(
$resql)) {
2357 $tmpactioncommreminder->id = $obj->id;
2358 $tmpactioncommreminder->typeremind = $obj->typeremind;
2359 $tmpactioncommreminder->dateremind = $obj->dateremind;
2360 $tmpactioncommreminder->offsetvalue = $obj->offsetvalue;
2361 $tmpactioncommreminder->offsetunit = $obj->offsetunit;
2362 $tmpactioncommreminder->status = $obj->status;
2363 $tmpactioncommreminder->fk_user = $obj->fk_user;
2365 $this->reminders[$obj->id] = $tmpactioncommreminder;
2368 $this->error = $this->
db->lasterror();
2372 return count($this->reminders);
2384 global $conf, $langs, $user;
2390 $errorsMsg = array();
2393 $langs->load(
"agenda");
2394 $this->output = $langs->trans(
'ModuleNotEnabled', $langs->transnoentitiesnoconv(
"Agenda"));
2397 if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2398 $langs->load(
"agenda");
2399 $this->output = $langs->trans(
'EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv(
"Agenda"));
2411 $sql =
"SELECT rowid as id FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2412 $sql .=
" WHERE typeremind = 'email' AND status = 0";
2413 $sql .=
" AND dateremind <= '".$this->db->idate($now).
"'";
2414 $sql .=
" AND entity IN (".getEntity(
'actioncomm').
")";
2415 $sql .= $this->
db->order(
"dateremind",
"ASC");
2419 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2422 while ($obj = $this->
db->fetch_object(
$resql)) {
2423 $res = $actionCommReminder->fetch($obj->id);
2426 $errorsMsg[] =
"Failed to load invoice ActionComm Reminder";
2431 $arraymessage = $formmail->getEMailTemplate($this->
db,
'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1);
2434 $res = $this->
fetch($actionCommReminder->fk_actioncomm);
2445 $sendContent =
make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
2448 $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->transnoentities(
'EventReminder'));
2451 $recipient =
new User($this->
db);
2452 $res = $recipient->fetch($actionCommReminder->fk_user);
2454 if (!empty($recipient->email)) {
2455 $to = $recipient->email;
2457 $errormesg =
"Failed to send remind to user id=".$actionCommReminder->fk_user.
". No email defined for user.";
2461 $errormesg =
"Failed to load recipient with user id=".$actionCommReminder->fk_user;
2468 $errormesg =
"Failed to get sender into global setup MAIN_MAIL_EMAIL_FROM";
2477 $cMailFile =
new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(),
'',
"", 0, 1, $errors_to,
'',
'',
'',
'',
'');
2480 if ($cMailFile->sendfile()) {
2483 $errormesg = $cMailFile->error.
' : '.$to;
2489 $actionCommReminder->status = $actionCommReminder::STATUS_DONE;
2491 $res = $actionCommReminder->update($user);
2493 $errorsMsg[] =
"Failed to update status to done of ActionComm Reminder";
2498 $actionCommReminder->status = $actionCommReminder::STATUS_ERROR;
2499 $actionCommReminder->lasterror =
dol_trunc($errormesg, 128,
'right',
'UTF-8', 1);
2501 $res = $actionCommReminder->update($user);
2503 $errorsMsg[] =
"Failed to update status to error of ActionComm Reminder";
2507 $errorsMsg[] = $errormesg;
2511 $errorsMsg[] =
'Failed to fetch record actioncomm with ID = '.$actionCommReminder->fk_actioncomm;
2522 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"actioncomm_reminder";
2523 $sql .=
" WHERE dateremind < '".$this->db->idate($now - (3600 * 24 * 32)).
"'";
2524 $sql .=
" AND status = ".((int) $actionCommReminder::STATUS_DONE);
2528 $errorsMsg[] =
'Failed to delete old reminders';
2534 $this->output =
'Nb of emails sent : '.$nbMailSend;
2535 $this->
db->commit();
2538 $this->
db->commit();
2539 $this->error =
'Nb of emails sent : '.$nbMailSend.
', '.(!empty($errorsMsg)) ? join(
', ', $errorsMsg) : $error;
2556 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm ";
2557 $sql .=
" SET percent = ".(int) $percent;
2558 if ($usermodid > 0) $sql .=
", fk_user_mod = ".$usermodid;
2559 $sql .=
" WHERE id = ".((int) $id);
2561 if ($this->
db->query($sql)) {
2562 $this->
db->commit();
2565 $this->
db->rollback();
2566 $this->error = $this->
db->lasterror();