dolibarr 18.0.6
actioncomm.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011-2017 Juanjo Menent <jmenent@2byte.es>
6 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
7 * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
8 * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
29require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
30require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
31require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
32require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncommreminder.class.php';
33
34
39{
43 public $element = 'action';
44
48 public $table_element = 'actioncomm';
49
53 public $table_rowid = 'id';
54
58 public $picto = 'action';
59
63 public $ismultientitymanaged = 1;
64
70 public $restrictiononfksoc = 2;
71
75 public $id;
76
80 public $ref;
81
86 public $type_id;
87
92 public $type;
93
98 public $type_code;
99
103 public $type_label;
104
108 public $type_color;
109
113 public $type_picto;
114
119 public $code;
120
124 public $label;
125
130 public $libelle;
131
135 public $datec;
136
140 public $duree;
141
145 public $datem;
146
152 public $author;
153
159 public $usermod;
160
164 public $authorid;
165
169 public $usermodid;
170
174 public $datep;
175
179 public $datef;
180
184 public $date_start_in_calendar;
185
189 public $date_end_in_calendar;
190
194 public $datep2;
195
200 public $durationp = -1;
201
205 public $fulldayevent = 0;
206
210 public $ponctuel;
211
215 public $percentage;
216
220 public $location;
221
225 public $transparency;
226
230 public $priority;
231
235 public $userassigned = array();
236
240 public $userownerid;
241
245 public $userdoneid;
246
250 public $socpeopleassigned = array();
251
255 public $otherassigned = array();
256
260 public $reminders = array();
261
265 public $socid;
266
270 public $contact_id;
271
272
278 public $societe;
279
285 public $contact;
286
287 // Properties for links to other objects
291 public $fk_element; // Id of record
292
296 public $elementid;
297
301 public $elementtype;
302
306 public $icalname;
307
311 public $icalcolor;
312
316 public $extraparams;
317
321 public $actions = array();
322
326 public $email_msgid;
327
331 public $email_from;
332
336 public $email_sender;
337
341 public $email_to;
342
346 public $email_tocc;
350 public $email_tobcc;
351
355 public $email_subject;
356
360 public $errors_to;
361
365 public $num_vote;
366
370 public $event_paid;
371
375 public $status;
376
380 public $recurid; /* A string YYYYMMDDHHMMSS shared by allevent of same serie */
381 public $recurrule; /* Rule of recurring */
382 public $recurdateend; /* Repeat until this date */
383
384 public $calling_duration;
385
386
390 const EVENT_TODO = 0;
391
396
400 const EVENT_FINISHED = 100;
401
402
403 public $fields = array();
404
405
411 public function __construct(DoliDB $db)
412 {
413 $this->db = $db;
414 }
415
424 public function create(User $user, $notrigger = 0)
425 {
426 global $langs, $conf;
427
428 $error = 0;
429 $now = dol_now();
430
431 // Check parameters
432 if (!isset($this->userownerid) || (string) $this->userownerid === '') { // $this->userownerid may be 0 (anonymous event) or > 0
433 dol_syslog("You tried to create an event but mandatory property ownerid was not defined", LOG_WARNING);
434 $this->errors[] = 'ErrorActionCommPropertyUserowneridNotDefined';
435 return -1;
436 }
437
438 // Clean parameters
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;
444 }
445 if (empty($this->priority) || !is_numeric($this->priority)) {
446 $this->priority = 0;
447 }
448 if (empty($this->fulldayevent)) {
449 $this->fulldayevent = 0;
450 }
451 if (empty($this->transparency)) {
452 $this->transparency = 0;
453 }
454 if ($this->percentage > 100) {
455 $this->percentage = 100;
456 }
457 if (empty($this->datep) && $this->datep != '0') { // We should not insert event in calendar without a start date
458 $this->datep = $now;
459 }
460 if (!empty($this->datep) && !empty($this->datef)) {
461 $this->durationp = ($this->datef - $this->datep); // deprecated
462 }
463 if (!empty($this->datep) && !empty($this->datef) && $this->datep > $this->datef) {
464 $this->datef = $this->datep;
465 }
466 if (!isset($this->fk_project) || $this->fk_project < 0) {
467 $this->fk_project = 0;
468 }
469 // For backward compatibility
470 if ($this->elementtype == 'facture') {
471 $this->elementtype = 'invoice';
472 }
473 if ($this->elementtype == 'commande') {
474 $this->elementtype = 'order';
475 }
476 if ($this->elementtype == 'contrat') {
477 $this->elementtype = 'contract';
478 }
479
480 if (!is_array($this->userassigned) && !empty($this->userassigned)) { // For backward compatibility when userassigned was an int instead of an array
481 $tmpid = (int) $this->userassigned;
482 $this->userassigned = array();
483 $this->userassigned[$tmpid] = array('id'=>$tmpid, 'transparency'=>$this->transparency);
484 }
485
486 $userownerid = $this->userownerid;
487 $userdoneid = $this->userdoneid;
488
489 // Be sure assigned user is defined as an array of array('id'=>,'mandatory'=>,...).
490 if (empty($this->userassigned) || count($this->userassigned) == 0 || !is_array($this->userassigned)) {
491 $this->userassigned = array($userownerid=>array('id'=>$userownerid, 'transparency'=>$this->transparency));
492 }
493
494 if (!$this->type_id || !$this->type_code) {
495 $key = empty($this->type_id) ? $this->type_code : $this->type_id;
496
497 // Get id from code
498 $cactioncomm = new CActionComm($this->db);
499 $result = $cactioncomm->fetch($key);
500
501 if ($result > 0) {
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);
506 return -1;
507 } else {
508 $this->error = $cactioncomm->error;
509 return -1;
510 }
511 }
512 $code = empty($this->code) ? $this->type_code : $this->code;
513
514 // Check parameters
515 if (!$this->type_id) {
516 $this->error = "ErrorWrongParameters";
517 return -1;
518 }
519
520 $this->db->begin();
521
522 $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm";
523 $sql .= "(ref,";
524 $sql .= "datec,";
525 $sql .= "datep,";
526 $sql .= "datep2,";
527 $sql .= "durationp,"; // deprecated
528 $sql .= "fk_action,";
529 $sql .= "code,";
530 $sql .= "ref_ext,";
531 $sql .= "fk_soc,";
532 $sql .= "fk_project,";
533 $sql .= "note,";
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,";
542 $sql .= "entity,";
543 $sql .= "extraparams,";
544 // Fields emails
545 $sql .= "email_msgid,";
546 $sql .= "email_from,";
547 $sql .= "email_sender,";
548 $sql .= "email_to,";
549 $sql .= "email_tocc,";
550 $sql .= "email_tobcc,";
551 $sql .= "email_subject,";
552 $sql .= "errors_to,";
553 $sql .= "recurid,";
554 $sql .= "recurrule,";
555 $sql .= "recurdateend,";
556 $sql .= "num_vote,";
557 $sql .= "event_paid,";
558 $sql .= "status,";
559 $sql .= "ip";
560 $sql .= ") VALUES (";
561 $sql .= "'(PROV)', ";
562 $sql .= "'".$this->db->idate($now)."', "; // date creation
563 $sql .= "'".$this->db->idate($this->datep)."', "; // date start event
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").", "; // deprecated
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").", "; // deprecated, use ->socpeopleassigned
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").", ";
586 // Fields emails
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");
602 $sql .= ")";
603
604 dol_syslog(get_class($this)."::add", LOG_DEBUG);
605 $resql = $this->db->query($sql);
606 if ($resql) {
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;
609 $resql = $this->db->query($sql);
610 if (!$resql) {
611 $error++;
612 dol_syslog('Error to process ref: '.$this->db->lasterror(), LOG_ERR);
613 $this->errors[] = $this->db->lasterror();
614 }
615 // Now insert assigned users
616 if (!$error) {
617 //dol_syslog(var_export($this->userassigned, true));
618 $already_inserted = array();
619 foreach ($this->userassigned as $key => $val) {
620 // Common value with new behavior is to have $val = array('id'=>iduser, 'transparency'=>0|1) and $this->userassigned is an array of iduser => $val.
621 if (!is_array($val)) { // For backward compatibility when $val='id'.
622 $val = array('id'=>$val);
623 }
624
625 if ($val['id'] > 0) {
626 if (!empty($already_inserted[$val['id']])) {
627 continue;
628 }
629
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'])).")";
632
633 $resql = $this->db->query($sql);
634 if (!$resql) {
635 $error++;
636 dol_syslog('Error to process userassigned: ' . $this->db->lasterror(), LOG_ERR);
637 $this->errors[] = $this->db->lasterror();
638 } else {
639 $already_inserted[$val['id']] = true;
640 }
641 //var_dump($sql);exit;
642 }
643 }
644 }
645
646 if (!$error) {
647 if (!empty($this->socpeopleassigned)) {
648 $already_inserted = array();
649 foreach ($this->socpeopleassigned as $id => $val) {
650 // Common value with new behavior is to have $val = iduser and $this->socpeopleassigned is an array of iduser => $val.
651 if (!empty($already_inserted[$id])) {
652 continue;
653 }
654
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)";
657
658 $resql = $this->db->query($sql);
659 if (!$resql) {
660 $error++;
661 dol_syslog('Error to process socpeopleassigned: ' . $this->db->lasterror(), LOG_ERR);
662 $this->errors[] = $this->db->lasterror();
663 } else {
664 $already_inserted[$id] = true;
665 }
666 }
667 }
668 }
669
670 if (!$error) {
671 // Actions on extra fields
672 $result = $this->insertExtraFields();
673 if ($result < 0) {
674 $error++;
675 }
676 }
677
678 if (!$error && !$notrigger) {
679 // Call trigger
680 $result = $this->call_trigger('ACTION_CREATE', $user);
681 if ($result < 0) {
682 $error++;
683 }
684 // End call triggers
685 }
686
687 if (!$error) {
688 $this->db->commit();
689 return $this->id;
690 } else {
691 $this->db->rollback();
692 return -1;
693 }
694 } else {
695 $this->db->rollback();
696 $this->error = $this->db->lasterror();
697 return -1;
698 }
699 }
700
708 public function createFromClone(User $fuser, $socid)
709 {
710 global $hookmanager;
711
712 $error = 0;
713
714 $this->db->begin();
715
716 // Load source object
717 $objFrom = clone $this;
718
719 // Retrieve all extrafield
720 // fetch optionals attributes and labels
721 $this->fetch_optionals();
722
723 //$this->fetch_userassigned();
724 $this->fetchResources();
725
726 $this->id = 0;
727 $this->recurid = '';
728 $this->recurrule = '';
729 $this->recurdateend = '';
730
731 // Create clone
732 $this->context['createfromclone'] = 'createfromclone';
733 $result = $this->create($fuser);
734 if ($result < 0) {
735 $error++;
736 }
737
738 if (!$error) {
739 // Hook of thirdparty module
740 if (is_object($hookmanager)) {
741 $parameters = array('objFrom'=>$objFrom);
742 $action = '';
743 $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
744 if ($reshook < 0) {
745 $this->setErrorsFromObject($hookmanager);
746 $error++;
747 }
748 }
749
750 // Call trigger
751 $result = $this->call_trigger('ACTION_CLONE', $fuser);
752 if ($result < 0) {
753 $error++;
754 }
755 // End call triggers
756 }
757
758 unset($this->context['createfromclone']);
759
760 // End
761 if (!$error) {
762 $this->db->commit();
763 return $this->id;
764 } else {
765 $this->db->rollback();
766 return -1;
767 }
768 }
769
780 public function fetch($id, $ref = '', $ref_ext = '', $email_msgid = '', $loadresources = 1)
781 {
782 global $langs;
783
784 if (empty($id) && empty($ref) && empty($ref_ext) && empty($email_msgid)) {
785 dol_syslog(get_class($this)."::fetch Bad parameters", LOG_WARNING);
786 return -1;
787 }
788
789 $sql = "SELECT a.id,";
790 $sql .= " a.ref as ref,";
791 $sql .= " a.entity,";
792 $sql .= " a.ref_ext,";
793 $sql .= " a.datep,";
794 $sql .= " a.datep2,";
795 $sql .= " a.durationp,"; // deprecated
796 $sql .= " a.datec,";
797 $sql .= " a.tms as datem,";
798 $sql .= " a.code, a.label, a.note as note_private,";
799 $sql .= " a.fk_soc,";
800 $sql .= " a.fk_project,";
801 $sql .= " a.fk_user_author, a.fk_user_mod,";
802 $sql .= " a.fk_user_action, a.fk_user_done,";
803 $sql .= " a.fk_contact, a.percent as percentage,";
804 $sql .= " a.fk_element as elementid, a.elementtype,";
805 $sql .= " a.priority, a.fulldayevent, a.location, a.transparency,";
806 $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,";
807 $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,";
808 $sql .= " s.nom as socname,";
809 $sql .= " u.firstname, u.lastname as lastname,";
810 $sql .= " num_vote, event_paid, a.status";
811 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a ";
812 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_actioncomm as c ON a.fk_action=c.id ";
813 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author";
814 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc";
815 $sql .= " WHERE ";
816 if ($ref) {
817 $sql .= " a.ref = '".$this->db->escape($ref)."'";
818 } elseif ($ref_ext) {
819 $sql .= " a.ref_ext = '".$this->db->escape($ref_ext)."'";
820 } elseif ($email_msgid) {
821 $sql .= " a.email_msgid = '".$this->db->escape($email_msgid)."'";
822 } else {
823 $sql .= " a.id = ".((int) $id);
824 }
825
826 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
827 $resql = $this->db->query($sql);
828 if ($resql) {
829 $num = $this->db->num_rows($resql);
830 if ($num) {
831 $obj = $this->db->fetch_object($resql);
832
833 $this->id = $obj->id;
834 $this->entity = $obj->entity;
835 $this->ref = $obj->ref;
836 $this->ref_ext = $obj->ref_ext;
837
838 // Properties of parent table llx_c_actioncomm
839 $this->type_id = $obj->type_id;
840 $this->type_code = $obj->type_code;
841 $this->type_color = $obj->type_color;
842 $this->type_picto = $obj->type_picto;
843 $this->type = $obj->type_type;
844
845 $this->code = $obj->code;
846 $this->label = $obj->label;
847 $this->datep = $this->db->jdate($obj->datep);
848 $this->datef = $this->db->jdate($obj->datep2);
849
850 $this->datec = $this->db->jdate($obj->datec);
851 $this->datem = $this->db->jdate($obj->datem);
852
853 $this->note = $obj->note_private; // deprecated
854 $this->note_private = $obj->note_private;
855 $this->percentage = $obj->percentage;
856
857 $this->authorid = $obj->fk_user_author;
858 $this->usermodid = $obj->fk_user_mod;
859
860 if (!is_object($this->author)) {
861 $this->author = new User($this->db); // To avoid warning
862 }
863 $this->author->id = $obj->fk_user_author; // deprecated
864 $this->author->firstname = $obj->firstname; // deprecated
865 $this->author->lastname = $obj->lastname; // deprecated
866 if (!is_object($this->usermod)) {
867 $this->usermod = new User($this->db); // To avoid warning
868 }
869 $this->usermod->id = $obj->fk_user_mod; // deprecated
870
871 $this->userownerid = $obj->fk_user_action;
872 $this->priority = $obj->priority;
873 $this->fulldayevent = $obj->fulldayevent;
874 $this->location = $obj->location;
875 $this->transparency = $obj->transparency;
876
877 $this->socid = $obj->fk_soc; // To have fetch_thirdparty method working
878 $this->contact_id = $obj->fk_contact; // To have fetch_contact method working
879 $this->fk_project = $obj->fk_project; // To have fetch_projet method working
880
881 //$this->societe->id = $obj->fk_soc; // deprecated
882 //$this->contact->id = $obj->fk_contact; // deprecated
883
884 $this->fk_element = $obj->elementid;
885 $this->elementid = $obj->elementid;
886 $this->elementtype = $obj->elementtype;
887
888 $this->num_vote = $obj->num_vote;
889 $this->event_paid = $obj->event_paid;
890 $this->status = $obj->status;
891
892 //email information
893 $this->email_msgid=$obj->email_msgid;
894 $this->email_from=$obj->email_from;
895 $this->email_sender=$obj->email_sender;
896 $this->email_to=$obj->email_to;
897 $this->email_tocc=$obj->email_tocc;
898 $this->email_tobcc=$obj->email_tobcc;
899 $this->email_subject=$obj->email_subject;
900 $this->errors_to=$obj->errors_to;
901
902 $this->fetch_optionals();
903
904 if ($loadresources) {
905 $this->fetchResources();
906 }
907 }
908
909 $this->db->free($resql);
910 } else {
911 $this->error = $this->db->lasterror();
912 return -1;
913 }
914
915 return $num;
916 }
917
923 public function fetchResources()
924 {
925 $this->userassigned = array();
926 $this->socpeopleassigned = array();
927
928 $sql = 'SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency';
929 $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm_resources';
930 $sql .= ' WHERE fk_actioncomm = '.((int) $this->id);
931 $sql .= " AND element_type IN ('user', 'socpeople')";
932 $resql = $this->db->query($sql);
933 if ($resql) {
934 // If owner is known, we must but id first into list
935 if ($this->userownerid > 0) {
936 $this->userassigned[$this->userownerid] = array('id'=>$this->userownerid); // Set first so will be first into list.
937 }
938
939 while ($obj = $this->db->fetch_object($resql)) {
940 if ($obj->fk_element > 0) {
941 switch ($obj->element_type) {
942 case 'user':
943 $this->userassigned[$obj->fk_element] = array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency);
944 if (empty($this->userownerid)) {
945 $this->userownerid = $obj->fk_element; // If not defined (should not happened, we fix this)
946 }
947 break;
948 case 'socpeople':
949 $this->socpeopleassigned[$obj->fk_element] = array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency);
950 break;
951 }
952 }
953 }
954
955 return 1;
956 } else {
957 dol_print_error($this->db);
958 return -1;
959 }
960 }
961
962 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
969 public function fetch_userassigned($override = true)
970 {
971 // phpcs:enable
972 $sql = "SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency";
973 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm_resources";
974 $sql .= " WHERE element_type = 'user' AND fk_actioncomm = ".((int) $this->id);
975
976 $resql2 = $this->db->query($sql);
977 if ($resql2) {
978 $this->userassigned = array();
979
980 // If owner is known, we must but id first into list
981 if ($this->userownerid > 0) {
982 // Set first so will be first into list.
983 $this->userassigned[$this->userownerid] = array('id'=>$this->userownerid);
984 }
985
986 while ($obj = $this->db->fetch_object($resql2)) {
987 if ($obj->fk_element > 0) {
988 $this->userassigned[$obj->fk_element] = array('id'=>$obj->fk_element,
989 'mandatory'=>$obj->mandatory,
990 'answer_status'=>$obj->answer_status,
991 'transparency'=>$obj->transparency);
992 }
993
994 if ($override === true) {
995 // If not defined (should not happened, we fix this)
996 if (empty($this->userownerid)) {
997 $this->userownerid = $obj->fk_element;
998 }
999 }
1000 }
1001
1002 return 1;
1003 } else {
1004 dol_print_error($this->db);
1005 return -1;
1006 }
1007 }
1008
1015 public function delete($notrigger = 0)
1016 {
1017 global $user;
1018
1019 $error = 0;
1020
1021 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1022
1023 $this->db->begin();
1024
1025 // remove categorie association
1026 if (!$error) {
1027 $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_actioncomm";
1028 $sql .= " WHERE fk_actioncomm=".((int) $this->id);
1029
1030 $res = $this->db->query($sql);
1031 if (!$res) {
1032 $this->error = $this->db->lasterror();
1033 $error++;
1034 }
1035 }
1036
1037 // remove actioncomm_resources
1038 if (!$error) {
1039 $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources";
1040 $sql .= " WHERE fk_actioncomm=".((int) $this->id);
1041
1042 $res = $this->db->query($sql);
1043 if (!$res) {
1044 $this->error = $this->db->lasterror();
1045 $error++;
1046 }
1047 }
1048
1049 if (!$error) {
1050 $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
1051 $sql .= " WHERE fk_actioncomm = ".((int) $this->id);
1052
1053 $res = $this->db->query($sql);
1054 if (!$res) {
1055 $this->error = $this->db->lasterror();
1056 $error++;
1057 }
1058 }
1059
1060 // Removed extrafields
1061 if (!$error) {
1062 $result = $this->deleteExtraFields();
1063 if ($result < 0) {
1064 $error++;
1065 dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
1066 }
1067 }
1068
1069 // remove actioncomm
1070 if (!$error) {
1071 $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm";
1072 $sql .= " WHERE id=".((int) $this->id);
1073
1074 $res = $this->db->query($sql);
1075 if (!$res) {
1076 $this->error = $this->db->lasterror();
1077 $error++;
1078 }
1079 }
1080
1081 if (!$error) {
1082 if (!$notrigger) {
1083 // Call trigger
1084 $result = $this->call_trigger('ACTION_DELETE', $user);
1085 if ($result < 0) {
1086 $error++;
1087 }
1088 // End call triggers
1089 }
1090
1091 if (!$error) {
1092 $this->db->commit();
1093 return 1;
1094 } else {
1095 $this->db->rollback();
1096 return -2;
1097 }
1098 } else {
1099 $this->db->rollback();
1100 $this->error = $this->db->lasterror();
1101 return -1;
1102 }
1103 }
1104
1113 public function update(User $user, $notrigger = 0)
1114 {
1115 global $langs, $conf, $hookmanager;
1116
1117 $error = 0;
1118
1119 // Clean parameters
1120 $this->label = trim($this->label);
1121 $this->note_private = dol_htmlcleanlastbr(trim(!isset($this->note_private) ? $this->note : $this->note_private));
1122 if (empty($this->percentage)) {
1123 $this->percentage = 0;
1124 }
1125 if (empty($this->priority) || !is_numeric($this->priority)) {
1126 $this->priority = 0;
1127 }
1128 if (empty($this->transparency)) {
1129 $this->transparency = 0;
1130 }
1131 if (empty($this->fulldayevent)) {
1132 $this->fulldayevent = 0;
1133 }
1134 if ($this->percentage > 100) {
1135 $this->percentage = 100;
1136 }
1137 //if ($this->percentage == 100 && ! $this->dateend) $this->dateend = $this->date;
1138 if ($this->datep && $this->datef) {
1139 $this->durationp = ($this->datef - $this->datep); // deprecated
1140 }
1141 //if ($this->date && $this->dateend) $this->durationa=($this->dateend - $this->date);
1142 if ($this->datep && $this->datef && $this->datep > $this->datef) {
1143 $this->datef = $this->datep;
1144 }
1145 //if ($this->date && $this->dateend && $this->date > $this->dateend) $this->dateend=$this->date;
1146 if ($this->fk_project < 0) {
1147 $this->fk_project = 0;
1148 }
1149
1150 // Check parameters
1151 if ($this->percentage == 0 && $this->userdoneid > 0) {
1152 $this->error = "ErrorCantSaveADoneUserWithZeroPercentage";
1153 return -1;
1154 }
1155
1156 $socid = (($this->socid > 0) ? $this->socid : 0);
1157 $contactid = (($this->contact_id > 0) ? $this->contact_id : 0);
1158 $userownerid = ($this->userownerid ? $this->userownerid : 0);
1159 $userdoneid = ($this->userdoneid ? $this->userdoneid : 0);
1160
1161 // If a type_id is set, we must also have the type_code set
1162 if ($this->type_id > 0) {
1163 if (empty($this->type_code)) {
1164 $cactioncomm = new CActionComm($this->db);
1165 $result = $cactioncomm->fetch($this->type_id);
1166 if ($result >= 0 && !empty($cactioncomm->code)) {
1167 $this->type_code = $cactioncomm->code;
1168 }
1169 }
1170 }
1171
1172 $code = $this->code;
1173 if (empty($code) || (!empty($this->oldcopy) && $this->oldcopy->type_code != $this->type_code)) { // If code unknown or if we change the type, we reset $code too
1174 $code = $this->type_code;
1175 }
1176
1177 $this->db->begin();
1178
1179 $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm";
1180 $sql .= " SET percent = '".$this->db->escape($this->percentage)."'";
1181 $sql .= ", fk_action = ".(int) $this->type_id;
1182 $sql .= ", code = " . ($code ? "'".$this->db->escape($code)."'" : "null");
1183 $sql .= ", label = ".($this->label ? "'".$this->db->escape($this->label)."'" : "null");
1184 $sql .= ", datep = ".(strval($this->datep) != '' ? "'".$this->db->idate($this->datep)."'" : 'null');
1185 $sql .= ", datep2 = ".(strval($this->datef) != '' ? "'".$this->db->idate($this->datef)."'" : 'null');
1186 $sql .= ", durationp = ".(isset($this->durationp) && $this->durationp >= 0 && $this->durationp != '' ? "'".$this->db->escape($this->durationp)."'" : "null"); // deprecated
1187 $sql .= ", note = '".$this->db->escape($this->note_private)."'";
1188 $sql .= ", fk_project =".($this->fk_project > 0 ? ((int) $this->fk_project) : "null");
1189 $sql .= ", fk_soc =".($socid > 0 ? ((int) $socid) : "null");
1190 $sql .= ", fk_contact =".($contactid > 0 ? ((int) $contactid) : "null");
1191 $sql .= ", priority = '".$this->db->escape($this->priority)."'";
1192 $sql .= ", fulldayevent = '".$this->db->escape($this->fulldayevent)."'";
1193 $sql .= ", location = ".($this->location ? "'".$this->db->escape($this->location)."'" : "null");
1194 $sql .= ", transparency = '".$this->db->escape($this->transparency)."'";
1195 $sql .= ", fk_user_mod = ".((int) $user->id);
1196 $sql .= ", fk_user_action = ".($userownerid > 0 ? ((int) $userownerid) : "null");
1197 $sql .= ", fk_user_done = ".($userdoneid > 0 ? ((int) $userdoneid) : "null");
1198 if (!empty($this->fk_element)) {
1199 $sql .= ", fk_element=".($this->fk_element ? ((int) $this->fk_element) : "null");
1200 }
1201 if (!empty($this->elementtype)) {
1202 $sql .= ", elementtype=".($this->elementtype ? "'".$this->db->escape($this->elementtype)."'" : "null");
1203 }
1204 if (!empty($this->num_vote)) {
1205 $sql .= ", num_vote=".($this->num_vote ? (int) $this->num_vote : null);
1206 }
1207 if (!empty($this->event_paid)) {
1208 $sql .= ", event_paid=".($this->event_paid ? (int) $this->event_paid : 0);
1209 }
1210 if (!empty($this->status)) {
1211 $sql .= ", status=".($this->status ? (int) $this->status : 0);
1212 }
1213 $sql .= " WHERE id=".((int) $this->id);
1214
1215 dol_syslog(get_class($this)."::update", LOG_DEBUG);
1216 if ($this->db->query($sql)) {
1217 $action = 'update';
1218
1219 // Actions on extra fields
1220 if (!$error) {
1221 $result = $this->insertExtraFields();
1222 if ($result < 0) {
1223 $error++;
1224 }
1225 }
1226
1227 // Now insert assignedusers
1228 if (!$error) {
1229 $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources where fk_actioncomm = ".((int) $this->id)." AND element_type = 'user'";
1230 $resql = $this->db->query($sql);
1231
1232 $already_inserted = array();
1233 foreach ($this->userassigned as $key => $val) {
1234 if (!is_array($val)) { // For backward compatibility when val=id
1235 $val = array('id'=>$val);
1236 }
1237 if (!empty($already_inserted[$val['id']])) continue;
1238
1239 $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1240 $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'])).")";
1241
1242 $resql = $this->db->query($sql);
1243 if (!$resql) {
1244 $error++;
1245 $this->errors[] = $this->db->lasterror();
1246 } else {
1247 $already_inserted[$val['id']] = true;
1248 }
1249 //var_dump($sql);exit;
1250 }
1251 }
1252
1253 if (!$error) {
1254 $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources where fk_actioncomm = ".((int) $this->id)." AND element_type = 'socpeople'";
1255 $resql = $this->db->query($sql);
1256
1257 if (!empty($this->socpeopleassigned)) {
1258 $already_inserted = array();
1259 foreach (array_keys($this->socpeopleassigned) as $key => $val) {
1260 if (!is_array($val)) { // For backward compatibility when val=id
1261 $val = array('id'=>$val);
1262 }
1263 if (!empty($already_inserted[$val['id']])) continue;
1264
1265 $sql = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
1266 $sql .= " VALUES(".((int) $this->id).", 'socpeople', ".((int) $val['id']).", 0, 0, 0)";
1267
1268 $resql = $this->db->query($sql);
1269 if (!$resql) {
1270 $error++;
1271 $this->errors[] = $this->db->lasterror();
1272 } else {
1273 $already_inserted[$val['id']] = true;
1274 }
1275 }
1276 }
1277 }
1278
1279 if (!$error && !$notrigger) {
1280 // Call trigger
1281 $result = $this->call_trigger('ACTION_MODIFY', $user);
1282 if ($result < 0) {
1283 $error++;
1284 }
1285 // End call triggers
1286 }
1287
1288 if (!$error) {
1289 $this->db->commit();
1290 return 1;
1291 } else {
1292 $this->db->rollback();
1293 dol_syslog(get_class($this)."::update ".join(',', $this->errors), LOG_ERR);
1294 return -2;
1295 }
1296 } else {
1297 $this->db->rollback();
1298 $this->error = $this->db->lasterror();
1299 return -1;
1300 }
1301 }
1302
1316 public function getActions($socid = 0, $fk_element = 0, $elementtype = '', $filter = '', $sortfield = 'a.datep', $sortorder = 'DESC', $limit = 0)
1317 {
1318 global $conf, $langs, $hookmanager;
1319
1320 $resarray = array();
1321
1322 dol_syslog(get_class()."::getActions", LOG_DEBUG);
1323
1324 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
1325 if (!is_object($hookmanager)) {
1326 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
1327 $hookmanager = new HookManager($db);
1328 }
1329 $hookmanager->initHooks(array('agendadao'));
1330
1331 $sql = "SELECT a.id";
1332 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1333 // Fields from hook
1334 $parameters = array('sql' => &$sql, 'socid' => $socid, 'fk_element' => $fk_element, 'elementtype' => $elementtype);
1335 $reshook = $hookmanager->executeHooks('getActionsListFrom', $parameters); // Note that $action and $object may have been modified by hook
1336 if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1337 $sql .= " WHERE a.entity IN (".getEntity('agenda').")";
1338 if (!empty($socid)) {
1339 $sql .= " AND a.fk_soc = ".((int) $socid);
1340 }
1341 if (!empty($elementtype)) {
1342 if ($elementtype == 'project') {
1343 $sql .= ' AND a.fk_project = '.((int) $fk_element);
1344 } elseif ($elementtype == 'contact') {
1345 $sql .= ' AND a.id IN';
1346 $sql .= " (SELECT fk_actioncomm FROM ".MAIN_DB_PREFIX."actioncomm_resources WHERE";
1347 $sql .= " element_type = 'socpeople' AND fk_element = ".((int) $fk_element).')';
1348 } else {
1349 $sql .= " AND a.fk_element = ".((int) $fk_element)." AND a.elementtype = '".$this->db->escape($elementtype)."'";
1350 }
1351 }
1352 if (!empty($filter)) {
1353 $sql .= $filter;
1354 }
1355 // Fields where hook
1356 $parameters = array('sql' => &$sql, 'socid' => $socid, 'fk_element' => $fk_element, 'elementtype' => $elementtype);
1357 $reshook = $hookmanager->executeHooks('getActionsListWhere', $parameters); // Note that $action and $object may have been modified by hook
1358 if (!empty($hookmanager->resPrint)) $sql.= $hookmanager->resPrint;
1359 if ($sortorder && $sortfield) {
1360 $sql .= $this->db->order($sortfield, $sortorder);
1361 }
1362 $sql .= $this->db->plimit($limit, 0);
1363
1364 $resql = $this->db->query($sql);
1365 if ($resql) {
1366 $num = $this->db->num_rows($resql);
1367
1368 if ($num) {
1369 for ($i = 0; $i < $num; $i++) {
1370 $obj = $this->db->fetch_object($resql);
1371 $actioncommstatic = new ActionComm($this->db);
1372 $actioncommstatic->fetch($obj->id);
1373 $resarray[$i] = $actioncommstatic;
1374 }
1375 }
1376 $this->db->free($resql);
1377 return $resarray;
1378 } else {
1379 return $this->db->lasterror();
1380 }
1381 }
1382
1383 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1391 public function load_board($user, $load_state_board = 0)
1392 {
1393 // phpcs:enable
1394 global $conf, $langs;
1395
1396 if (empty($load_state_board)) {
1397 $sql = "SELECT a.id, a.datep as dp";
1398 } else {
1399 $this->nb = array();
1400 $sql = "SELECT count(a.id) as nb";
1401 }
1402 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
1403 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1404 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
1405 }
1406 if (!$user->hasRight('agenda', 'allactions', 'read')) {
1407 $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);
1408 }
1409 $sql .= " WHERE 1 = 1";
1410 if (empty($load_state_board)) {
1411 $sql .= " AND a.percent >= 0 AND a.percent < 100";
1412 }
1413 $sql .= " AND a.entity IN (".getEntity('agenda').")";
1414 if (empty($user->rights->societe->client->voir) && !$user->socid) {
1415 $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
1416 }
1417 if ($user->socid) {
1418 $sql .= " AND a.fk_soc = ".((int) $user->socid);
1419 }
1420 if (!$user->hasRight('agenda', 'allactions', 'read')) {
1421 $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);
1422 $sql .= " OR ar.fk_element = ".((int) $user->id);
1423 $sql .= ")";
1424 }
1425
1426 $resql = $this->db->query($sql);
1427 if ($resql) {
1428 if (empty($load_state_board)) {
1429 $agenda_static = new ActionComm($this->db);
1430 $response = new WorkboardResponse();
1431 $response->warning_delay = $conf->agenda->warning_delay / 60 / 60 / 24;
1432 $response->label = $langs->trans("ActionsToDo");
1433 $response->labelShort = $langs->trans("ActionsToDoShort");
1434 $response->url = DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&actioncode=0&status=todo&mainmenu=agenda';
1435 if ($user->hasRight("agenda", "allactions", "read")) {
1436 $response->url .= '&filtert=-1';
1437 }
1438 $response->img = img_object('', "action", 'class="inline-block valigntextmiddle"');
1439 }
1440 // This assignment in condition is not a bug. It allows walking the results.
1441 while ($obj = $this->db->fetch_object($resql)) {
1442 if (empty($load_state_board)) {
1443 $response->nbtodo++;
1444 $agenda_static->datep = $this->db->jdate($obj->dp);
1445 if ($agenda_static->hasDelay()) {
1446 $response->nbtodolate++;
1447 }
1448 } else {
1449 $this->nb["actionscomm"] = $obj->nb;
1450 }
1451 }
1452
1453 $this->db->free($resql);
1454 if (empty($load_state_board)) {
1455 return $response;
1456 } else {
1457 return 1;
1458 }
1459 } else {
1460 dol_print_error($this->db);
1461 $this->error = $this->db->error();
1462 return -1;
1463 }
1464 }
1465
1466
1473 public function info($id)
1474 {
1475 $sql = 'SELECT ';
1476 $sql .= ' a.id,';
1477 $sql .= ' datec,';
1478 $sql .= ' tms as datem,';
1479 $sql .= ' fk_user_author,';
1480 $sql .= ' fk_user_mod';
1481 $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
1482 $sql .= ' WHERE a.id = '.((int) $id);
1483
1484 dol_syslog(get_class($this)."::info", LOG_DEBUG);
1485 $result = $this->db->query($sql);
1486 if ($result) {
1487 if ($this->db->num_rows($result)) {
1488 $obj = $this->db->fetch_object($result);
1489 $this->id = $obj->id;
1490 $this->user_creation_id = $obj->fk_user_author;
1491 $this->user_modification_id = $obj->fk_user_mod;
1492 $this->date_creation = $this->db->jdate($obj->datec);
1493 $this->date_modification = empty($obj->datem) ? '' : $this->db->jdate($obj->datem);
1494 }
1495 $this->db->free($result);
1496 } else {
1497 dol_print_error($this->db);
1498 }
1499 }
1500
1501
1509 public function getLibStatut($mode, $hidenastatus = 0)
1510 {
1511 return $this->LibStatut($this->percentage, $mode, $hidenastatus, $this->datep);
1512 }
1513
1514 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1524 public function LibStatut($percent, $mode, $hidenastatus = 0, $datestart = '')
1525 {
1526 // phpcs:enable
1527 global $langs;
1528
1529 $labelStatus = $langs->transnoentitiesnoconv('StatusNotApplicable');
1530 if ($percent == -1 && !$hidenastatus) {
1531 $labelStatus = $langs->transnoentitiesnoconv('StatusNotApplicable');
1532 } elseif ($percent == 0) {
1533 $labelStatus = $langs->transnoentitiesnoconv('StatusActionToDo').' (0%)';
1534 } elseif ($percent > 0 && $percent < 100) {
1535 $labelStatus = $langs->transnoentitiesnoconv('StatusActionInProcess').' ('.$percent.'%)';
1536 } elseif ($percent >= 100) {
1537 $labelStatus = $langs->transnoentitiesnoconv('StatusActionDone').' (100%)';
1538 }
1539
1540 $labelStatusShort = $langs->transnoentitiesnoconv('StatusNotApplicable');
1541 if ($percent == -1 && !$hidenastatus) {
1542 $labelStatusShort = $langs->trans('NA');
1543 } elseif ($percent == 0) {
1544 $labelStatusShort = '0%';
1545 } elseif ($percent > 0 && $percent < 100) {
1546 $labelStatusShort = $percent.'%';
1547 } elseif ($percent >= 100) {
1548 $labelStatusShort = '100%';
1549 }
1550
1551 $statusType = 'status9';
1552 if ($percent == -1 && !$hidenastatus) {
1553 $statusType = 'status9';
1554 }
1555 if ($percent == 0) {
1556 $statusType = 'status1';
1557 }
1558 if ($percent > 0 && $percent < 100) {
1559 $statusType = 'status3';
1560 }
1561 if ($percent >= 100) {
1562 $statusType = 'status6';
1563 }
1564
1565 return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode);
1566 }
1567
1574 public function getTooltipContentArray($params)
1575 {
1576 global $conf, $langs, $user;
1577 $langs->load('agenda');
1578
1579 $datas = array();
1580 $nofetch = !empty($params['nofetch']);
1581
1582 // Set label of type
1583 $labeltype = '';
1584 if ($this->type_code) {
1585 $labeltype = ($langs->transnoentities("Action".$this->type_code) != "Action".$this->type_code) ? $langs->transnoentities("Action".$this->type_code) : $this->type_label;
1586 }
1587 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1588 if ($this->type_code != 'AC_OTH_AUTO') {
1589 $labeltype = $langs->trans('ActionAC_MANUAL');
1590 }
1591 }
1592
1593 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans('Action').'</u>';
1594 if (!empty($this->ref)) {
1595 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.dol_escape_htmltag($this->ref);
1596 }
1597 if (!empty($this->label)) {
1598 $datas['title'] = '<br><b>'.$langs->trans('Title').':</b> '.dol_escape_htmltag($this->label);
1599 }
1600 if (!empty($labeltype)) {
1601 $datas['labeltype'] = '<br><b>'.$langs->trans('Type').':</b> '.dol_escape_htmltag($labeltype);
1602 }
1603 if (!empty($this->location)) {
1604 $datas['location'] = '<br><b>'.$langs->trans('Location').':</b> '.dol_escape_htmltag($this->location);
1605 }
1606 if (isset($this->transparency)) {
1607 $datas['transparency'] = '<br><b>'.$langs->trans('Busy').':</b> '.yn($this->transparency);
1608 }
1609 if (!empty($this->email_msgid)) {
1610 $langs->load("mails");
1611 $datas['space'] = '<br>';
1612 // $datas['email'] = '<br><b>'.img_picto('', 'email').' '.$langs->trans("Email").'</b>';
1613 $datas['mailtopic'] = '<br><b>'.$langs->trans('MailTopic').':</b> '.dol_escape_htmltag($this->email_subject);
1614 $datas['mailfrom'] = '<br><b>'.$langs->trans('MailFrom').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_from);
1615 $datas['mailto'] = '<br><b>'.$langs->trans('MailTo').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_to);
1616 if (!empty($this->email_tocc)) {
1617 $datas['mailcc'] = '<br><b>'.$langs->trans('MailCC').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_tocc);
1618 }
1619 /* Disabled because bcc must remain by defintion not visible
1620 if (!empty($this->email_tobcc)) {
1621 $datas['mailccc'] = '<br><b>'.$langs->trans('MailCCC').':</b> '.$this->email_tobcc;
1622 } */
1623 }
1624 if (!empty($this->note_private)) {
1625 $datas['description'] = '<br><b>'.$langs->trans('Description').':</b><br>';
1626 // Try to limit length of content
1627 $texttoshow = dolGetFirstLineOfText($this->note_private, 10);
1628 // Restrict height of content into the tooltip
1629 $datas['note'] = '<div class="tenlinesmax">';
1630 $datas['note'] .= (dol_textishtml($texttoshow) ? str_replace(array("\r", "\n"), "", $texttoshow) : str_replace(array("\r", "\n"), '<br>', $texttoshow));
1631 $datas['note'] .= '</div>';
1632 }
1633 // show categories for this record only in ajax to not overload lists
1634 if (isModEnabled('categorie') && !$nofetch) {
1635 require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
1636 $form = new Form($this->db);
1637 $datas['categories'] = '<br>' . $form->showCategories($this->id, Categorie::TYPE_ACTIONCOMM, 1);
1638 }
1639
1640 return $datas;
1641 }
1642
1656 public function getNomUrl($withpicto = 0, $maxlength = 0, $classname = '', $option = '', $overwritepicto = 0, $notooltip = 0, $save_lastsearch_value = -1)
1657 {
1658 global $conf, $langs, $user, $hookmanager, $action;
1659
1660 if (!empty($conf->dol_no_mouse_hover)) {
1661 $notooltip = 1; // Force disable tooltips
1662 }
1663
1664 $canread = 0;
1665 if ($user->hasRight('agenda', 'myactions', 'read') && ($this->authorid == $user->id || $this->userownerid == $user->id)) {
1666 $canread = 1; // Can read my event
1667 }
1668 if ($user->hasRight('agenda', 'myactions', 'read') && array_key_exists($user->id, $this->userassigned)) {
1669 $canread = 1; // Can read my event i am assigned
1670 }
1671 if ($user->hasRight('agenda', 'allactions', 'read')) {
1672 $canread = 1; // Can read all event of other
1673 }
1674 if (!$canread) {
1675 $option = 'nolink';
1676 }
1677
1678 $label = $this->label;
1679 if (empty($label)) {
1680 $label = $this->libelle; // For backward compatibility
1681 }
1682
1683 $result = '';
1684
1685 // Set label of type
1686 $labeltype = '';
1687 if ($this->type_code) {
1688 $labeltype = ($langs->transnoentities("Action".$this->type_code) != "Action".$this->type_code) ? $langs->transnoentities("Action".$this->type_code) : $this->type_label;
1689 }
1690 if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1691 if ($this->type_code != 'AC_OTH_AUTO') {
1692 $labeltype = $langs->trans('ActionAC_MANUAL');
1693 }
1694 }
1695
1696 $tooltip = img_picto('', $this->picto).' <u>'.$langs->trans('Action').'</u>';
1697 if (!empty($this->ref)) {
1698 $tooltip .= '<br><b>'.$langs->trans('Ref').':</b> '.dol_escape_htmltag($this->ref);
1699 }
1700 if (!empty($label)) {
1701 $tooltip .= '<br><b>'.$langs->trans('Title').':</b> '.dol_escape_htmltag($label);
1702 }
1703 if (!empty($labeltype)) {
1704 $tooltip .= '<br><b>'.$langs->trans('Type').':</b> '.dol_escape_htmltag($labeltype);
1705 }
1706 if (!empty($this->location)) {
1707 $tooltip .= '<br><b>'.$langs->trans('Location').':</b> '.dol_escape_htmltag($this->location);
1708 }
1709 if (isset($this->transparency)) {
1710 $tooltip .= '<br><b>'.$langs->trans('Busy').':</b> '.yn($this->transparency);
1711 }
1712 if (!empty($this->email_msgid)) {
1713 $langs->load("mails");
1714 $tooltip .= '<br>';
1715 //$tooltip .= '<br><b>'.img_picto('', 'email').' '.$langs->trans("Email").'</b>';
1716 $tooltip .= '<br><b>'.$langs->trans('MailTopic').':</b> '.dol_escape_htmltag($this->email_subject);
1717 $tooltip .= '<br><b>'.$langs->trans('MailFrom').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), !empty($this->email_from) ? $this->email_from : '');
1718 $tooltip .= '<br><b>'.$langs->trans('MailTo').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), !empty($this->email_to) ? $this->email_to : '');
1719 if (!empty($this->email_tocc)) {
1720 $tooltip .= '<br><b>'.$langs->trans('MailCC').':</b> '.str_replace(array('<', '>'), array('&amp;lt', '&amp;gt'), $this->email_tocc);
1721 }
1722 /* Disabled because bcc must remain by defintion not visible
1723 if (!empty($this->email_tobcc)) {
1724 $tooltip .= '<br><b>'.$langs->trans('MailCCC').':</b> '.$this->email_tobcc;
1725 } */
1726 }
1727 if (!empty($this->note_private)) {
1728 $tooltip .= '<br><br><b>'.$langs->trans('Description').':</b><br>';
1729 $texttoshow = dolGetFirstLineOfText($this->note_private, 8); // Try to limit length of content
1730 $tooltip .= '<div class="tenlinesmax">'; // Restrict height of content into the tooltip
1731 $tooltip .= (dol_textishtml($texttoshow) ? str_replace(array("\r", "\n"), "", $texttoshow) : str_replace(array("\r", "\n"), '<br>', $texttoshow));
1732 $tooltip .= '</div>';
1733 }
1734 $linkclose = '';
1735 $classfortooltip = 'classfortooltip';
1736 $dataparams = '';
1737 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
1738 $params = [
1739 'id' => $this->id,
1740 'objecttype' => $this->element,
1741 'option' => $option,
1742 'nofetch' => 1,
1743 ];
1744 $classfortooltip = 'classforajaxtooltip';
1745 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
1746 $tooltip = '';
1747 }
1748 //if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && $this->type_color)
1749 // $linkclose = ' style="background-color:#'.$this->type_color.'"';
1750 if (empty($notooltip)) {
1751 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1752 $label = $langs->trans("ShowAction");
1753 $linkclose .= ' alt="'.dol_escape_htmltag($tooltip, 1).'"';
1754 }
1755 $linkclose .= ($tooltip ? ' title="'.dol_escape_htmltag($tooltip, 1).'"' : ' title="tocomplete"');
1756 $linkclose .= $dataparams.' class="'.$classname.' '.$classfortooltip.'"';
1757 } else {
1758 $linkclose .= ' class="'.$classname.'"';
1759 }
1760
1761 $url = '';
1762 if ($option == 'birthday') {
1763 $url = DOL_URL_ROOT.'/contact/perso.php?id='.$this->id;
1764 } elseif ($option == 'holiday') {
1765 $url = DOL_URL_ROOT.'/holiday/card.php?id='.$this->id;
1766 } else {
1767 $url = DOL_URL_ROOT.'/comm/action/card.php?id='.$this->id;
1768 }
1769
1770 if ($option !== 'nolink') {
1771 // Add param to save lastsearch_values or not
1772 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1773 if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1774 $add_save_lastsearch_values = 1;
1775 }
1776 if ($add_save_lastsearch_values) {
1777 $url .= '&save_lastsearch_values=1';
1778 }
1779 }
1780
1781 $linkstart = '<a href="'.$url.'"';
1782 $linkstart .= $linkclose.'>';
1783 $linkend = '</a>';
1784
1785 if ($option == 'nolink') {
1786 $linkstart = '';
1787 $linkend = '';
1788 }
1789
1790 if ($withpicto == 2) {
1791 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1792 $label = $labeltype;
1793 }
1794 $labelshort = '';
1795 } else {
1796 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($label)) {
1797 $label = $labeltype;
1798 }
1799 if ($maxlength < 0) {
1800 $labelshort = $this->ref;
1801 } else {
1802 $labelshort = dol_trunc($label, $maxlength);
1803 }
1804 }
1805
1806 if ($withpicto) {
1807 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) { // Add code into ()
1808 if ($labeltype) {
1809 $label .= (preg_match('/'.preg_quote($labeltype, '/').'/', $label) ? '' : ' ('.$langs->transnoentities("Action".$this->type_code).')');
1810 }
1811 }
1812 }
1813
1814 $result .= $linkstart;
1815 if ($withpicto) {
1816 $result .= img_object(($notooltip ? '' : $langs->trans("ShowAction").': '.$label), ($overwritepicto ? $overwritepicto : 'action'), (($this->type_color && $overwritepicto) ? 'style="color: #'.$this->type_color.' !important;" ' : '').($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : ' class="'.(($withpicto != 2) ? 'paddingright ' : '').'"'), 0, 0, $notooltip ? 0 : 1);
1817 }
1818 $result .= dol_escape_htmltag($labelshort);
1819 $result .= $linkend;
1820
1821 global $action;
1822 $hookmanager->initHooks(array('actiondao'));
1823 $parameters = array('id'=>$this->id, 'getnomurl' => &$result);
1824 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
1825 if ($reshook > 0) {
1826 $result = $hookmanager->resPrint;
1827 } else {
1828 $result .= $hookmanager->resPrint;
1829 }
1830
1831 return $result;
1832 }
1833
1839 public function getTypePicto()
1840 {
1841 global $conf;
1842
1843 $imgpicto = '';
1844 if (!empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
1845 $color = '';
1846 if ($this->type_color) {
1847 $color = 'style="color: #'.$this->type_color.' !important;"';
1848 }
1849 if ($this->type_picto) {
1850 $imgpicto = img_picto('', $this->type_picto, 'class="paddingright"');
1851 } else {
1852 if ($this->type_code == 'AC_RDV') {
1853 $imgpicto = img_picto('', 'meeting', $color, false, 0, 0, '', 'paddingright');
1854 } elseif ($this->type_code == 'AC_TEL') {
1855 $imgpicto = img_picto('', 'object_phoning', $color, false, 0, 0, '', 'paddingright');
1856 } elseif ($this->type_code == 'AC_FAX') {
1857 $imgpicto = img_picto('', 'object_phoning_fax', $color, false, 0, 0, '', 'paddingright');
1858 } elseif ($this->type_code == 'AC_EMAIL' || $this->type_code == 'AC_EMAIL_IN' || (!empty($this->code) && preg_match('/_SENTBYMAIL/', $this->code))) {
1859 $imgpicto = img_picto('', 'object_email', $color, false, 0, 0, '', 'paddingright');
1860 } elseif ($this->type_code == 'AC_INT') {
1861 $imgpicto = img_picto('', 'object_intervention', $color, false, 0, 0, '', 'paddingright');
1862 } elseif (!empty($this->code) && preg_match('/^TICKET_MSG/', $this->code)) {
1863 $imgpicto = img_picto('', 'object_conversation', $color, false, 0, 0, '', 'paddingright');
1864 } elseif ($this->type != 'systemauto') {
1865 $imgpicto = img_picto('', 'user-cog', $color, false, 0, 0, '', 'paddingright');
1866 } else {
1867 $imgpicto = img_picto('', 'cog', $color, false, 0, 0, '', 'paddingright');
1868 }
1869 }
1870 } else {
1871 // 2 picto: 1 for auto, 1 for manual
1872 if ($this->type != 'systemauto') {
1873 $imgpicto = img_picto('', 'user-cog', '', false, 0, 0, '', 'paddingright');
1874 } else {
1875 $imgpicto = img_picto('', 'cog', '', false, 0, 0, '', 'paddingright');
1876 }
1877 }
1878 return $imgpicto;
1879 }
1880
1881
1892 public function setCategories($categories)
1893 {
1894 // Handle single category
1895 if (!is_array($categories)) {
1896 $categories = array($categories);
1897 }
1898
1899 // Get current categories
1900 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1901 $c = new Categorie($this->db);
1902 $existing = $c->containing($this->id, Categorie::TYPE_ACTIONCOMM, 'id');
1903
1904 // Diff
1905 if (is_array($existing)) {
1906 $to_del = array_diff($existing, $categories);
1907 $to_add = array_diff($categories, $existing);
1908 } else {
1909 $to_del = array(); // Nothing to delete
1910 $to_add = $categories;
1911 }
1912
1913 // Process
1914 foreach ($to_del as $del) {
1915 if ($c->fetch($del) > 0) {
1916 $c->del_type($this, Categorie::TYPE_ACTIONCOMM);
1917 }
1918 }
1919 foreach ($to_add as $add) {
1920 if ($c->fetch($add) > 0) {
1921 $c->add_type($this, Categorie::TYPE_ACTIONCOMM);
1922 }
1923 }
1924 return 1;
1925 }
1926
1927 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1939 public function build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday = 0)
1940 {
1941 global $hookmanager;
1942
1943 // phpcs:enable
1944 global $conf, $langs, $dolibarr_main_url_root, $mysoc;
1945
1946 require_once DOL_DOCUMENT_ROOT."/core/lib/xcal.lib.php";
1947 require_once DOL_DOCUMENT_ROOT."/core/lib/date.lib.php";
1948 require_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
1949
1950 dol_syslog(get_class($this)."::build_exportfile Build export file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".count($filters), LOG_DEBUG);
1951
1952 // Check parameters
1953 if (empty($format)) {
1954 return -1;
1955 }
1956
1957 // Clean parameters
1958 if (!$filename) {
1959 $extension = 'vcs';
1960 if ($format == 'ical') {
1961 $extension = 'ics';
1962 }
1963 $filename = $format.'.'.$extension;
1964 }
1965
1966 // Create dir and define output file (definitive and temporary)
1967 $result = dol_mkdir($conf->agenda->dir_temp);
1968 $outputfile = $conf->agenda->dir_temp.'/'.$filename;
1969
1970 $result = 0;
1971
1972 $buildfile = true;
1973 $login = ''; $logina = ''; $logind = ''; $logint = '';
1974
1975 $now = dol_now();
1976
1977 if ($cachedelay) {
1978 $nowgmt = dol_now();
1979 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1980 if (dol_filemtime($outputfile) > ($nowgmt - $cachedelay)) {
1981 dol_syslog(get_class($this)."::build_exportfile file ".$outputfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay."). Build is canceled");
1982 $buildfile = false;
1983 }
1984 }
1985
1986 if ($buildfile) {
1987 // Build event array
1988 $eventarray = array();
1989
1990 $sql = "SELECT a.id,";
1991 $sql .= " a.datep,"; // Start
1992 $sql .= " a.datep2,"; // End
1993 $sql .= " a.durationp,"; // deprecated
1994 $sql .= " a.datec, a.tms as datem,";
1995 $sql .= " a.label, a.code, a.note as note_private, a.fk_action as type_id,";
1996 $sql .= " a.fk_soc,";
1997 $sql .= " a.fk_user_author, a.fk_user_mod,";
1998 $sql .= " a.fk_user_action,";
1999 $sql .= " a.fk_contact, a.percent as percentage,";
2000 $sql .= " a.fk_element, a.elementtype,";
2001 $sql .= " a.priority, a.fulldayevent, a.location, a.transparency,";
2002 $sql .= " u.firstname, u.lastname, u.email,";
2003 $sql .= " s.nom as socname,";
2004 $sql .= " c.id as type_id, c.code as type_code, c.libelle as type_label,";
2005 $sql .= " num_vote, event_paid, a.status";
2006 $sql .= " FROM (".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."actioncomm as a)";
2007 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author"; // Link to get author of event for export
2008 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc";
2009
2010 $parameters = array('filters' => $filters);
2011 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters); // Note that $action and $object may have been modified by hook
2012 $sql .= $hookmanager->resPrint;
2013
2014 // We must filter on assignement table
2015 if ($filters['logint']) {
2016 $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
2017 }
2018 $sql .= " WHERE a.fk_action=c.id";
2019 $sql .= " AND a.entity IN (".getEntity('agenda').")";
2020 foreach ($filters as $key => $value) {
2021 if ($key == 'notolderthan' && $value != '') {
2022 $sql .= " AND a.datep >= '".$this->db->idate($now - ($value * 24 * 60 * 60))."'";
2023 }
2024 if ($key == 'year') {
2025 $sql .= " AND a.datep BETWEEN '".$this->db->idate(dol_get_first_day($value, 1))."' AND '".$this->db->idate(dol_get_last_day($value, 12))."'";
2026 }
2027 if ($key == 'id') {
2028 $sql .= " AND a.id=".(is_numeric($value) ? $value : 0);
2029 }
2030 if ($key == 'idfrom') {
2031 $sql .= " AND a.id >= ".(is_numeric($value) ? $value : 0);
2032 }
2033 if ($key == 'idto') {
2034 $sql .= " AND a.id <= ".(is_numeric($value) ? $value : 0);
2035 }
2036 if ($key == 'project') {
2037 $sql .= " AND a.fk_project=".(is_numeric($value) ? $value : 0);
2038 }
2039 if ($key == 'actiontype') {
2040 $sql .= " AND c.type = '".$this->db->escape($value)."'";
2041 }
2042 if ($key == 'notactiontype') {
2043 $sql .= " AND c.type <> '".$this->db->escape($value)."'";
2044 }
2045 // We must filter on assignement table
2046 if ($key == 'logint') {
2047 $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
2048 }
2049 if ($key == 'logina') {
2050 $logina = $value;
2051 $condition = '=';
2052 if (preg_match('/^!/', $logina)) {
2053 $logina = preg_replace('/^!/', '', $logina);
2054 $condition = '<>';
2055 }
2056 $userforfilter = new User($this->db);
2057 $result = $userforfilter->fetch('', $logina);
2058 if ($result > 0) {
2059 $sql .= " AND a.fk_user_author ".$condition." ".$userforfilter->id;
2060 } elseif ($result < 0 || $condition == '=') {
2061 $sql .= " AND a.fk_user_author = 0";
2062 }
2063 }
2064 if ($key == 'logint') {
2065 $logint = $value;
2066 $condition = '=';
2067 if (preg_match('/^!/', $logint)) {
2068 $logint = preg_replace('/^!/', '', $logint);
2069 $condition = '<>';
2070 }
2071 $userforfilter = new User($this->db);
2072 $result = $userforfilter->fetch('', $logint);
2073 if ($result > 0) {
2074 $sql .= " AND ar.fk_element = ".((int) $userforfilter->id);
2075 } elseif ($result < 0 || $condition == '=') {
2076 $sql .= " AND ar.fk_element = 0";
2077 }
2078 }
2079 if ($key == 'module') {
2080 $sql .= " AND c.module LIKE '%".$this->db->escape($value)."'";
2081 }
2082 if ($key == 'status') {
2083 $sql .= " AND a.status =".((int) $value);
2084 }
2085 }
2086
2087 $sql .= " AND a.datep IS NOT NULL"; // To exclude corrupted events and avoid errors in lightning/sunbird import
2088
2089 $parameters = array('filters' => $filters);
2090 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
2091 $sql .= $hookmanager->resPrint;
2092
2093 $sql .= " ORDER by datep";
2094 //print $sql;exit;
2095
2096 dol_syslog(get_class($this)."::build_exportfile select events", LOG_DEBUG);
2097 $resql = $this->db->query($sql);
2098 if ($resql) {
2099 $diff = 0;
2100 while ($obj = $this->db->fetch_object($resql)) {
2101 $qualified = true;
2102
2103 // 'eid','startdate','duration','enddate','title','summary','category','email','url','desc','author'
2104 $event = array();
2105 $event['uid'] = 'dolibarragenda-'.$this->db->database_name.'-'.$obj->id."@".$_SERVER["SERVER_NAME"];
2106 $event['type'] = $type;
2107
2108 $datestart = $this->db->jdate($obj->datep) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2109
2110 // fix for -> Warning: A non-numeric value encountered
2111 if (is_numeric($this->db->jdate($obj->datep2))) {
2112 $dateend = $this->db->jdate($obj->datep2) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2113 } else {
2114 // use start date as fall-back to avoid pb with empty end date on ICS readers
2115 $dateend = $datestart;
2116 }
2117
2118 $duration = ($datestart && $dateend) ? ($dateend - $datestart) : 0;
2119 $event['summary'] = $obj->label.($obj->socname ? " (".$obj->socname.")" : "");
2120
2121 $event['desc'] = $obj->note_private;
2122 $event['startdate'] = $datestart;
2123 $event['enddate'] = $dateend; // Not required with type 'journal'
2124 $event['duration'] = $duration; // Not required with type 'journal'
2125 $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname);
2126 $event['priority'] = $obj->priority;
2127 $event['fulldayevent'] = $obj->fulldayevent;
2128 $event['location'] = $obj->location;
2129 $event['transparency'] = (($obj->transparency > 0) ? 'OPAQUE' : 'TRANSPARENT'); // OPAQUE (busy) or TRANSPARENT (not busy)
2130 $event['category'] = $obj->type_label;
2131 $event['email'] = $obj->email;
2132 // Define $urlwithroot
2133 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
2134 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
2135 //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
2136 $url = $urlwithroot.'/comm/action/card.php?id='.$obj->id;
2137 $event['url'] = $url;
2138 $event['created'] = $this->db->jdate($obj->datec) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2139 $event['modified'] = $this->db->jdate($obj->datem) - (empty($conf->global->AGENDA_EXPORT_FIX_TZ) ? 0 : ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600));
2140 $event['num_vote'] = $this->num_vote;
2141 $event['event_paid'] = $this->event_paid;
2142 $event['status'] = $this->status;
2143
2144 // TODO: find a way to call "$this->fetch_userassigned();" without override "$this" properties
2145 $this->id = $obj->id;
2146 $this->fetch_userassigned(false);
2147
2148 $assignedUserArray = array();
2149
2150 foreach ($this->userassigned as $key => $value) {
2151 $assignedUser = new User($this->db);
2152 $assignedUser->fetch($value['id']);
2153
2154 $assignedUserArray[$key] = $assignedUser;
2155 }
2156
2157 $event['assignedUsers'] = $assignedUserArray;
2158
2159 if ($qualified && $datestart) {
2160 $eventarray[] = $event;
2161 }
2162 $diff++;
2163 }
2164
2165 $parameters = array('filters' => $filters, 'eventarray' => &$eventarray);
2166 $reshook = $hookmanager->executeHooks('addMoreEventsExport', $parameters); // Note that $action and $object may have been modified by hook
2167 if ($reshook > 0) {
2168 $eventarray = $hookmanager->resArray;
2169 }
2170 } else {
2171 $this->error = $this->db->lasterror();
2172 return -1;
2173 }
2174
2175 if ($exportholiday == 1) {
2176 $langs->load("holiday");
2177 $title = $langs->transnoentities("Holidays");
2178
2179 $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";
2180 $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
2181 $sql .= " WHERE u.rowid = x.fk_user";
2182 $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
2183 $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
2184
2185 $resql = $this->db->query($sql);
2186 if ($resql) {
2187 $num = $this->db->num_rows($resql);
2188 $i = 0;
2189
2190 while ($i < $num) {
2191 $obj = $this->db->fetch_object($resql);
2192 $event = array();
2193
2194 if ($obj->halfday == 1) {
2195 $event['fulldayevent'] = false;
2196
2197 $timestampStart = dol_stringtotime($obj->date_start." 00:00:00", 0);
2198 $timestampEnd = dol_stringtotime($obj->date_end." 12:00:00", 0);
2199 } elseif ($obj->halfday == -1) {
2200 $event['fulldayevent'] = false;
2201
2202 $timestampStart = dol_stringtotime($obj->date_start." 12:00:00", 0);
2203 $timestampEnd = dol_stringtotime($obj->date_end." 23:59:59", 0);
2204 } else {
2205 $event['fulldayevent'] = true;
2206
2207 $timestampStart = dol_stringtotime($obj->date_start." 00:00:00", 0);
2208 $timestampEnd = dol_stringtotime($obj->date_end." 23:59:59", 0);
2209 }
2210
2211 if (!empty($conf->global->AGENDA_EXPORT_FIX_TZ)) {
2212 $timestampStart = $timestampStart - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2213 $timestampEnd = $timestampEnd - ($conf->global->AGENDA_EXPORT_FIX_TZ * 3600);
2214 }
2215
2216 $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
2217 $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT;
2218 $url = $urlwithroot.'/holiday/card.php?id='.$obj->rowid;
2219
2220 $event['uid'] = 'dolibarrholiday-'.$this->db->database_name.'-'.$obj->rowid."@".$_SERVER["SERVER_NAME"];
2221 $event['author'] = dolGetFirstLastname($obj->firstname, $obj->lastname);
2222 $event['type'] = 'event';
2223 $event['category'] = "Holiday";
2224 $event['transparency'] = 'OPAQUE';
2225 $event['email'] = $obj->email;
2226 $event['created'] = $timestampStart;
2227 $event['modified'] = $timestampStart;
2228 $event['startdate'] = $timestampStart;
2229 $event['enddate'] = $timestampEnd;
2230 $event['duration'] = $timestampEnd - $timestampStart;
2231 $event['url'] = $url;
2232
2233 if ($obj->status == 2) {
2234 // 2 = leave wait for approval
2235 $event['summary'] = $title." - ".$obj->lastname." (wait for approval)";
2236 } else {
2237 // 3 = leave approved
2238 $event['summary'] = $title." - ".$obj->lastname;
2239 }
2240
2241 $eventarray[] = $event;
2242
2243 $i++;
2244 }
2245 }
2246 }
2247
2248 $langs->load("agenda");
2249
2250 // Define title and desc
2251 $more = '';
2252 if ($login) {
2253 $more = $langs->transnoentities("User").' '.$login;
2254 }
2255 if ($logina) {
2256 $more = $langs->transnoentities("ActionsAskedBy").' '.$logina;
2257 }
2258 if ($logint) {
2259 $more = $langs->transnoentities("ActionsToDoBy").' '.$logint;
2260 }
2261 if ($logind) {
2262 $more = $langs->transnoentities("ActionsDoneBy").' '.$logind;
2263 }
2264 if ($more) {
2265 $title = 'Dolibarr actions '.$mysoc->name.' - '.$more;
2266 $desc = $more;
2267 $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
2268 } else {
2269 $title = 'Dolibarr actions '.$mysoc->name;
2270 $desc = $langs->transnoentities('ListOfActions');
2271 $desc .= ' ('.$mysoc->name.' - built by Dolibarr)';
2272 }
2273
2274 // Create temp file
2275 $outputfiletmp = tempnam($conf->agenda->dir_temp, 'tmp'); // Temporary file (allow call of function by different threads
2276 dolChmod($outputfiletmp);
2277
2278 // Write file
2279 if ($format == 'vcal') {
2280 $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2281 } elseif ($format == 'ical') {
2282 $result = build_calfile($format, $title, $desc, $eventarray, $outputfiletmp);
2283 } elseif ($format == 'rss') {
2284 $result = build_rssfile($format, $title, $desc, $eventarray, $outputfiletmp);
2285 }
2286
2287 if ($result >= 0) {
2288 if (dol_move($outputfiletmp, $outputfile, 0, 1, 0, 0)) {
2289 $result = 1;
2290 } else {
2291 $this->error = 'Failed to rename '.$outputfiletmp.' into '.$outputfile;
2292 dol_syslog(get_class($this)."::build_exportfile ".$this->error, LOG_ERR);
2293 dol_delete_file($outputfiletmp, 0, 1);
2294 $result = -1;
2295 }
2296 } else {
2297 dol_syslog(get_class($this)."::build_exportfile build_xxxfile function fails to for format=".$format." outputfiletmp=".$outputfile, LOG_ERR);
2298 dol_delete_file($outputfiletmp, 0, 1);
2299 $langs->load("errors");
2300 $this->error = $langs->trans("ErrorFailToCreateFile", $outputfile);
2301 }
2302 }
2303
2304 return $result;
2305 }
2306
2314 public function initAsSpecimen()
2315 {
2316 global $user;
2317
2318 $now = dol_now();
2319
2320 // Initialise parametres
2321 $this->id = 0;
2322 $this->specimen = 1;
2323
2324 $this->type_code = 'AC_OTH';
2325 $this->code = 'AC_SPECIMEN_CODE';
2326 $this->label = 'Label of event Specimen';
2327 $this->datec = $now;
2328 $this->datem = $now;
2329 $this->datep = $now;
2330 $this->datef = $now;
2331 $this->fulldayevent = 0;
2332 $this->percentage = 0;
2333 $this->status = 0;
2334 $this->location = 'Location';
2335 $this->transparency = 1; // 1 means opaque
2336 $this->priority = 1;
2337 //$this->note_public = "This is a 'public' note.";
2338 $this->note_private = "This is a 'private' note.";
2339
2340 $this->userownerid = $user->id;
2341 $this->userassigned[$user->id] = array('id'=>$user->id, 'transparency'=> 1);
2342 return 1;
2343 }
2344
2353 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
2354 {
2355 $tables = array(
2356 'actioncomm'
2357 );
2358
2359 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
2360 }
2361
2370 public static function replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
2371 {
2372 $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'actioncomm SET fk_element = ' . ((int) $dest_id) . ' WHERE elementtype="product" AND fk_element = '.((int) $origin_id);
2373 // using $dbs, not $this->db because function is static
2374 if (!$dbs->query($sql)) {
2375 //$this->errors = $dbs->lasterror();
2376 return false;
2377 }
2378
2379 return true;
2380 }
2381
2387 public function hasDelay()
2388 {
2389 global $conf;
2390
2391 $now = dol_now();
2392
2393 return $this->datep && ($this->datep < ($now - $conf->agenda->warning_delay));
2394 }
2395
2396
2405 public function loadReminders($type = '', $fk_user = 0, $onlypast = true)
2406 {
2407 global $conf, $langs, $user;
2408
2409 $error = 0;
2410
2411 $this->reminders = array();
2412
2413 //Select all action comm reminders for event
2414 $sql = "SELECT rowid as id, typeremind, dateremind, status, offsetvalue, offsetunit, fk_user, fk_email_template, lasterror";
2415 $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
2416 $sql .= " WHERE fk_actioncomm = ".((int) $this->id);
2417 if ($onlypast) {
2418 $sql .= " AND dateremind <= '".$this->db->idate(dol_now())."'";
2419 }
2420 if ($type) {
2421 $sql .= " AND typeremind = '".$this->db->escape($type)."'";
2422 }
2423 if ($fk_user > 0) {
2424 $sql .= " AND fk_user = ".((int) $fk_user);
2425 }
2426 if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2427 $sql .= " AND typeremind <> 'email'";
2428 }
2429 if (empty($conf->global->AGENDA_REMINDER_BROWSER)) {
2430 $sql .= " AND typeremind <> 'browser'";
2431 }
2432
2433 $sql .= $this->db->order("dateremind", "ASC");
2434 $resql = $this->db->query($sql);
2435
2436 if ($resql) {
2437 while ($obj = $this->db->fetch_object($resql)) {
2438 $tmpactioncommreminder = new ActionCommReminder($this->db);
2439 $tmpactioncommreminder->id = $obj->id;
2440 $tmpactioncommreminder->typeremind = $obj->typeremind;
2441 $tmpactioncommreminder->dateremind = $obj->dateremind;
2442 $tmpactioncommreminder->offsetvalue = $obj->offsetvalue;
2443 $tmpactioncommreminder->offsetunit = $obj->offsetunit;
2444 $tmpactioncommreminder->status = $obj->status;
2445 $tmpactioncommreminder->fk_user = $obj->fk_user;
2446 $tmpactioncommreminder->fk_email_template = $obj->fk_email_template;
2447 $tmpactioncommreminder->lasterror = $obj->lasterror;
2448
2449 $this->reminders[$obj->id] = $tmpactioncommreminder;
2450 }
2451 } else {
2452 $this->error = $this->db->lasterror();
2453 $error++;
2454 }
2455
2456 return count($this->reminders);
2457 }
2458
2459
2466 public function sendEmailsReminder()
2467 {
2468 global $conf, $langs, $user;
2469
2470 $error = 0;
2471 $this->output = '';
2472 $this->error = '';
2473 $nbMailSend = 0;
2474 $errorsMsg = array();
2475
2476 if (!isModEnabled('agenda')) { // Should not happen. If module disabled, cron job should not be visible.
2477 $langs->load("agenda");
2478 $this->output = $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Agenda"));
2479 return 0;
2480 }
2481 if (empty($conf->global->AGENDA_REMINDER_EMAIL)) {
2482 $langs->load("agenda");
2483 $this->output = $langs->trans('EventRemindersByEmailNotEnabled', $langs->transnoentitiesnoconv("Agenda"));
2484 return 0;
2485 }
2486
2487 $now = dol_now();
2488 $actionCommReminder = new ActionCommReminder($this->db);
2489
2490 dol_syslog(__METHOD__." start", LOG_INFO);
2491
2492 $this->db->begin();
2493
2494 //Select all action comm reminders
2495 $sql = "SELECT rowid as id FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
2496 $sql .= " WHERE typeremind = 'email'";
2497 $sql .= " AND status = 0"; // 0=No yet sent, -1=Error. TODO Include reminder in error once we can count number of error, so we can try 5 times and not more on errors.
2498 $sql .= " AND dateremind <= '".$this->db->idate($now)."'";
2499 $sql .= " AND entity IN (".getEntity('actioncomm').")";
2500 $sql .= $this->db->order("dateremind", "ASC");
2501 $resql = $this->db->query($sql);
2502
2503 if ($resql) {
2504 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2505 $formmail = new FormMail($this->db);
2506
2507 while ($obj = $this->db->fetch_object($resql)) {
2508 $res = $actionCommReminder->fetch($obj->id);
2509 if ($res < 0) {
2510 $error++;
2511 $errorsMsg[] = "Failed to load invoice ActionComm Reminder";
2512 }
2513
2514 if (!$error) {
2515 //Select email template
2516 $arraymessage = $formmail->getEMailTemplate($this->db, 'actioncomm_send', $user, $langs, (!empty($actionCommReminder->fk_email_template)) ? $actionCommReminder->fk_email_template : -1, 1);
2517
2518 // Load event
2519 $res = $this->fetch($actionCommReminder->fk_actioncomm);
2520 if ($res > 0) $res = $this->fetch_thirdparty();
2521 if ($res > 0) {
2522 // PREPARE EMAIL
2523 $errormesg = '';
2524
2525 // Make substitution in email content
2526 $substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this);
2527
2528 complete_substitutions_array($substitutionarray, $langs, $this);
2529
2530 // Content
2531 $sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
2532
2533 //Topic
2534 $sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->transnoentities('EventReminder'));
2535
2536 // Recipient
2537 $recipient = new User($this->db);
2538 $res = $recipient->fetch($actionCommReminder->fk_user);
2539 if ($res > 0) {
2540 if (!empty($recipient->email)) {
2541 $to = $recipient->email;
2542 } else {
2543 $errormesg = "Failed to send remind to user id=".$actionCommReminder->fk_user.". No email defined for user.";
2544 $error++;
2545 }
2546 } else {
2547 $errormesg = "Failed to load recipient with user id=".$actionCommReminder->fk_user;
2548 $error++;
2549 }
2550
2551 // Sender
2552 $from = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
2553 if (empty($from)) {
2554 $errormesg = "Failed to get sender into global setup MAIN_MAIL_EMAIL_FROM";
2555 $error++;
2556 }
2557
2558 if (!$error) {
2559 // Errors Recipient
2560 $errors_to = getDolGlobalString('MAIN_MAIL_ERRORS_TO');
2561
2562 // Mail Creation
2563 $cMailFile = new CMailFile($sendTopic, $to, $from, $sendContent, array(), array(), array(), '', "", 0, 1, $errors_to, '', '', '', '', '');
2564
2565 // Sending Mail
2566 if ($cMailFile->sendfile()) {
2567 $nbMailSend++;
2568 } else {
2569 $errormesg = 'Failed to send email to: '.$to.' '.$cMailFile->error.join(',', $cMailFile->errors);
2570 $error++;
2571 }
2572 }
2573
2574 if (!$error) {
2575 $actionCommReminder->status = $actionCommReminder::STATUS_DONE;
2576
2577 $res = $actionCommReminder->update($user);
2578 if ($res < 0) {
2579 $errorsMsg[] = "Failed to update status to done of ActionComm Reminder";
2580 $error++;
2581 break; // This is to avoid to have this error on all the selected email. If we fails here for one record, it may fails for others. We must solve first.
2582 }
2583 } else {
2584 $actionCommReminder->status = $actionCommReminder::STATUS_ERROR;
2585 $actionCommReminder->lasterror = dol_trunc($errormesg, 128, 'right', 'UTF-8', 1);
2586
2587 $res = $actionCommReminder->update($user);
2588 if ($res < 0) {
2589 $errorsMsg[] = "Failed to update status to error of ActionComm Reminder";
2590 $error++;
2591 break; // This is to avoid to have this error on all the selected email. If we fails here for one record, it may fails for others. We must solve first.
2592 } else {
2593 $errorsMsg[] = $errormesg;
2594 }
2595 }
2596 } else {
2597 $errorsMsg[] = 'Failed to fetch record actioncomm with ID = '.$actionCommReminder->fk_actioncomm;
2598 $error++;
2599 }
2600 }
2601 }
2602 } else {
2603 $error++;
2604 }
2605
2606 if (!$error) {
2607 // Delete also very old past events (we do not keep more than 1 month record in past)
2608 $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_reminder";
2609 $sql .= " WHERE dateremind < '".$this->db->idate($now - (3600 * 24 * 32))."'";
2610 $sql .= " AND status = ".((int) $actionCommReminder::STATUS_DONE);
2611 $resql = $this->db->query($sql);
2612
2613 if (!$resql) {
2614 $errorsMsg[] = 'Failed to delete old reminders';
2615 //$error++; // If this fails, we must not rollback other SQL requests already done. Never mind.
2616 }
2617 }
2618
2619 if (!$error) {
2620 $this->output = 'Nb of emails sent : '.$nbMailSend;
2621 $this->db->commit();
2622
2623 dol_syslog(__METHOD__." end - ".$this->output, LOG_INFO);
2624
2625 return 0;
2626 } else {
2627 $this->db->commit(); // We commit also on error, to have the error message recorded.
2628 $this->error = 'Nb of emails sent : '.$nbMailSend.', '.(!empty($errorsMsg)) ? join(', ', $errorsMsg) : $error;
2629
2630 dol_syslog(__METHOD__." end - ".$this->error, LOG_INFO);
2631
2632 return $error;
2633 }
2634 }
2635
2644 public function updatePercent($id, $percent, $usermodid = 0)
2645 {
2646 $this->db->begin();
2647
2648 $sql = "UPDATE ".MAIN_DB_PREFIX."actioncomm ";
2649 $sql .= " SET percent = ".(int) $percent;
2650 if ($usermodid > 0) $sql .= ", fk_user_mod = ".$usermodid;
2651 $sql .= " WHERE id = ".((int) $id);
2652
2653 if ($this->db->query($sql)) {
2654 $this->db->commit();
2655 return 1;
2656 } else {
2657 $this->db->rollback();
2658 $this->error = $this->db->lasterror();
2659 return -1;
2660 }
2661 }
2662}
$object ref
Definition info.php:78
Class to manage agenda events (actions)
const EVENT_FINISHED
Typical value for a event that is in a finished state.
hasDelay()
Is the action delayed?
build_exportfile($format, $type, $cachedelay, $filename, $filters, $exportholiday=0)
Export events from database into a cal file.
getTooltipContentArray($params)
getTooltipContentArray
update(User $user, $notrigger=0)
Update action into database If percentage = 100, on met a jour date 100%.
fetch_userassigned($override=true)
Initialize this->userassigned array with list of id of user assigned to event.
info($id)
Charge les informations d'ordre info dans l'objet facture.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
const EVENT_IN_PROGRESS
Typical value for a event that is in a progress state.
getNomUrl($withpicto=0, $maxlength=0, $classname='', $option='', $overwritepicto=0, $notooltip=0, $save_lastsearch_value=-1)
Return URL of event Use $this->id, $this->type_code, $this->label and $this->type_label.
sendEmailsReminder()
Send reminders by emails CAN BE A CRON TASK.
create(User $user, $notrigger=0)
Add an action/event into database.
const EVENT_TODO
Typical value for a event that is in a todo state.
setCategories($categories)
Sets object to supplied categories.
createFromClone(User $fuser, $socid)
Load an object from its id and create a new one in database.
$recurid
Properties to manage the recurring events.
getTypePicto()
Return Picto of type of event.
LibStatut($percent, $mode, $hidenastatus=0, $datestart='')
Return label of action status.
getActions($socid=0, $fk_element=0, $elementtype='', $filter='', $sortfield='a.datep', $sortorder='DESC', $limit=0)
Load all objects with filters.
load_board($user, $load_state_board=0)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
fetch($id, $ref='', $ref_ext='', $email_msgid='', $loadresources=1)
Load object from database.
updatePercent($id, $percent, $usermodid=0)
Udpate the percent value of a event with the given id.
loadReminders($type='', $fk_user=0, $onlypast=true)
Load event reminder of events.
fetchResources()
Initialize $this->userassigned & this->socpeopleassigned array with list of id of user and contact as...
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
__construct(DoliDB $db)
Constructor.
initAsSpecimen()
Initialise an instance with random values.
getLibStatut($mode, $hidenastatus=0)
Return the label of the status.
Class for ActionCommReminder.
Class to manage different types of events.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
setErrorsFromObject($object)
setErrorsFromObject
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Class to manage hooks.
Class to manage Dolibarr users.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:578
dol_stringtotime($string, $gm=1)
Convert a string date into a GM Timestamps date Warning: YYYY-MM-DDTHH:MM:SS+02:00 (RFC3339) is not s...
Definition date.lib.php:410
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:597
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array())
Move a file into another name.
dol_filemtime($pathoffile)
Return time of a file.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dolGetFirstLineOfText($text, $nboflines=1, $charset='UTF-8')
Return first line of text.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
dol_textishtml($msg, $option=0)
Return if a text is a html content.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
query($query, $usesavepoint=0, $type='auto', $result_mode=0)
Execute a SQL request and return the resultset.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120
build_calfile($format, $title, $desc, $events_array, $outputfile)
Build a file from an array of events All input params and data must be encoded in $conf->charset_outp...
Definition xcal.lib.php:35
build_rssfile($format, $title, $desc, $events_array, $outputfile, $filter='', $url='', $langcode='')
Build a file from an array of events.
Definition xcal.lib.php:325