32require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
33require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/core/lib/ticket.lib.php';
50 public $element =
'ticket';
55 public $table_element =
'ticket';
60 public $fk_element =
'fk_ticket';
65 public $picto =
'ticket';
100 public $fk_user_create;
105 public $fk_user_assign;
157 public $category_code;
162 public $severity_code;
172 public $category_label;
177 public $severity_label;
187 public $origin_replyto;
192 public $origin_references;
207 public $date_last_msg_sent;
217 public $cache_types_tickets;
222 public $cache_msgs_ticket;
227 public $notify_tiers_at_create;
252 public $regeximgext =
'\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm';
258 const STATUS_READ = 1;
259 const STATUS_ASSIGNED = 2;
260 const STATUS_IN_PROGRESS = 3;
261 const STATUS_NEED_MORE_INFO = 5;
262 const STATUS_WAITING = 7;
263 const STATUS_CLOSED = 8;
264 const STATUS_CANCELED = 9;
295 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'visible' => -2,
'enabled' => 1,
'position' => 1,
'notnull' => 1,
'index' => 1,
'comment' =>
"Id"),
296 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'visible' => 0,
'enabled' => 1,
'position' => 5,
'notnull' => 1,
'index' => 1),
297 'ref' => array(
'type' =>
'varchar(128)',
'label' =>
'Ref',
'visible' => 1,
'enabled' => 1,
'position' => 10,
'notnull' => 1,
'index' => 1,
'searchall' => 1,
'comment' =>
"Reference of object",
'css' =>
'',
'showoncombobox' => 1),
298 'track_id' => array(
'type' =>
'varchar(255)',
'label' =>
'TicketTrackId',
'visible' => -2,
'enabled' => 1,
'position' => 11,
'notnull' => -1,
'searchall' => 1,
'help' =>
"Help text"),
299 'fk_user_create' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'Author',
'visible' => 1,
'enabled' => 1,
'position' => 15,
'notnull' => 1,
'csslist' =>
'tdoverflowmax100 maxwidth150onsmartphone'),
300 'origin_email' => array(
'type' =>
'mail',
'label' =>
'OriginEmail',
'visible' => -2,
'enabled' => 1,
'position' => 16,
'notnull' => 1,
'index' => 1,
'searchall' => 1,
'comment' =>
"Reference of object",
'csslist' =>
'tdoverflowmax150'),
301 'origin_replyto' => array(
'type' =>
'mail',
'label' =>
'EmailReplyto',
'visible' => -2,
'enabled' => 1,
'position' => 17,
'notnull' => 1,
'index' => 1,
'searchall' => 1,
'comment' =>
"Email to reply to",
'csslist' =>
'tdoverflowmax150'),
302 'origin_references' => array(
'type' =>
'text',
'label' =>
'EmailReferences',
'visible' => -2,
'enabled' => 1,
'position' => 18,
'notnull' => 1,
'index' => 1,
'searchall' => 1,
'comment' =>
"References from origin email",
'csslist' =>
'tdoverflowmax150'),
303 'subject' => array(
'type' =>
'varchar(255)',
'label' =>
'Subject',
'visible' => 1,
'enabled' => 1,
'position' => 19,
'notnull' => -1,
'searchall' => 1,
'help' =>
"",
'css' =>
'maxwidth200 tdoverflowmax200',
'csslist' =>
'tdoverflowmax250',
'autofocusoncreate' => 1),
304 'type_code' => array(
'type' =>
'varchar(32)',
'label' =>
'Type',
'visible' => 1,
'enabled' => 1,
'position' => 20,
'notnull' => -1,
'help' =>
"",
'csslist' =>
'tdoverflowmax100'),
305 'category_code' => array(
'type' =>
'varchar(32)',
'label' =>
'TicketCategory',
'visible' => -1,
'enabled' => 1,
'position' => 21,
'notnull' => -1,
'help' =>
"",
'css' =>
'maxwidth100 tdoverflowmax200'),
306 'severity_code' => array(
'type' =>
'varchar(32)',
'label' =>
'Severity',
'visible' => 1,
'enabled' => 1,
'position' => 22,
'notnull' => -1,
'help' =>
"",
'css' =>
'maxwidth100'),
307 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'visible' => 1,
'enabled' =>
'isModEnabled("societe")',
'position' => 50,
'notnull' => -1,
'index' => 1,
'searchall' => 1,
'help' =>
"OrganizationEventLinkToThirdParty",
'css' =>
'tdoverflowmax150 maxwidth150onsmartphone'),
308 'notify_tiers_at_create' => array(
'type' =>
'integer',
'label' =>
'NotifyThirdparty',
'visible' => -1,
'enabled' => 0,
'position' => 51,
'notnull' => 1,
'index' => 1),
309 'fk_project' => array(
'type' =>
'integer:Project:projet/class/project.class.php',
'label' =>
'Project',
'visible' => -1,
'enabled' =>
'$conf->project->enabled',
'position' => 52,
'notnull' => -1,
'index' => 1,
'help' =>
"LinkToProject"),
310 'fk_contract' => array(
'type' =>
'integer:Contrat:contrat/class/contrat.class.php',
'label' =>
'Contract',
'visible' => -1,
'enabled' =>
'$conf->contract->enabled',
'position' => 53,
'notnull' => -1,
'index' => 1,
'help' =>
"LinkToContract"),
312 'datec' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'visible' => 1,
'enabled' => 1,
'position' => 500,
'notnull' => 1,
'csslist' =>
'nowraponall'),
313 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'visible' => -1,
'enabled' => 1,
'position' => 501,
'notnull' => 1),
314 'date_read' => array(
'type' =>
'datetime',
'label' =>
'DateReading',
'visible' => -1,
'enabled' => 1,
'position' => 505,
'notnull' => 1,
'csslist' =>
'nowraponall'),
315 'date_last_msg_sent' => array(
'type' =>
'datetime',
'label' =>
'TicketLastMessageDate',
'visible' => 0,
'enabled' => 1,
'position' => 506,
'notnull' => -1),
316 'fk_user_assign' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'AssignedTo',
'visible' => 1,
'enabled' => 1,
'position' => 507,
'notnull' => 1,
'csslist' =>
'tdoverflowmax100 maxwidth150onsmartphone'),
317 'date_close' => array(
'type' =>
'datetime',
'label' =>
'TicketCloseOn',
'visible' => -1,
'enabled' => 1,
'position' => 510,
'notnull' => 1),
318 'message' => array(
'type' =>
'html',
'label' =>
'Message',
'visible' => -2,
'enabled' => 1,
'position' => 540,
'notnull' => -1,),
319 'email_msgid' => array(
'type' =>
'varchar(255)',
'label' =>
'EmailMsgID',
'visible' => -2,
'enabled' => 1,
'position' => 540,
'notnull' => -1,
'help' =>
'EmailMsgIDDesc',
'csslist' =>
'tdoverflowmax100'),
320 'email_date' => array(
'type' =>
'datetime',
'label' =>
'EmailDate',
'visible' => -2,
'enabled' => 1,
'position' => 541),
321 'progress' => array(
'type' =>
'integer',
'label' =>
'Progression',
'visible' => -1,
'enabled' => 1,
'position' => 540,
'notnull' => -1,
'css' =>
'right',
'help' =>
"",
'isameasure' => 1,
'csslist' =>
'width50'),
322 'resolution' => array(
'type' =>
'integer',
'label' =>
'Resolution',
'visible' => -1,
'enabled' =>
'getDolGlobalString("TICKET_ENABLE_RESOLUTION")',
'position' => 550,
'notnull' => 1),
323 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'PDFTemplate',
'enabled' => 1,
'visible' => 0,
'position' => 560),
324 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => 0,
'position' => 570),
325 'fk_statut' => array(
'type' =>
'integer',
'label' =>
'Status',
'visible' => 1,
'enabled' => 1,
'position' => 600,
'notnull' => 1,
'index' => 1,
'arrayofkeyval' => array(0 =>
'Unread', 1 =>
'Read', 2 =>
'Assigned', 3 =>
'InProgress', 5 =>
'NeedMoreInformation', 7 =>
'OnHold', 8 =>
'SolvedClosed', 9 =>
'Deleted')),
326 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 900),
340 $this->ismultientitymanaged = 1;
341 $this->isextrafieldmanaged = 1;
343 $this->labelStatusShort = array(
344 self::STATUS_NOT_READ =>
'Unread',
345 self::STATUS_READ =>
'Read',
346 self::STATUS_ASSIGNED =>
'Assigned',
347 self::STATUS_IN_PROGRESS =>
'InProgress',
348 self::STATUS_NEED_MORE_INFO =>
'NeedMoreInformationShort',
349 self::STATUS_WAITING =>
'OnHold',
350 self::STATUS_CLOSED =>
'SolvedClosed',
351 self::STATUS_CANCELED =>
'Canceled'
353 $this->labelStatus = array(
354 self::STATUS_NOT_READ =>
'Unread',
355 self::STATUS_READ =>
'Read',
356 self::STATUS_ASSIGNED =>
'Assigned',
357 self::STATUS_IN_PROGRESS =>
'InProgress',
358 self::STATUS_NEED_MORE_INFO =>
'NeedMoreInformation',
359 self::STATUS_WAITING =>
'OnHold',
360 self::STATUS_CLOSED =>
'SolvedClosed',
361 self::STATUS_CANCELED =>
'Canceled'
365 unset($this->fields[
'fk_statut'][
'arrayofkeyval'][self::STATUS_WAITING]);
366 unset($this->labelStatusShort[self::STATUS_WAITING]);
367 unset($this->labelStatus[self::STATUS_WAITING]);
379 $this->errors = array();
384 if (isset($this->
ref)) {
385 $this->
ref = trim($this->
ref);
388 if (isset($this->track_id)) {
389 $this->track_id = trim($this->track_id);
392 if (isset($this->fk_soc)) {
393 $this->fk_soc = (int) $this->fk_soc;
396 if (isset($this->fk_project)) {
397 $this->fk_project = (int) $this->fk_project;
400 if (isset($this->origin_email)) {
401 $this->origin_email = trim($this->origin_email);
404 if (isset($this->fk_user_create)) {
405 $this->fk_user_create = (int) $this->fk_user_create;
408 if (isset($this->fk_user_assign)) {
409 $this->fk_user_assign = (int) $this->fk_user_assign;
412 if (isset($this->subject)) {
413 $this->subject = trim($this->subject);
416 if (isset($this->message)) {
417 $this->message = trim($this->message);
419 $this->errors[] =
'ErrorFieldTooLong';
420 dol_syslog(get_class($this).
'::create error -1 message too long', LOG_ERR);
425 if (isset($this->
status)) {
429 if (isset($this->resolution)) {
430 $this->resolution = (int) $this->resolution;
433 if (isset($this->progress)) {
434 $this->progress = (int) $this->progress;
437 if (isset($this->timing)) {
438 $this->timing = trim($this->timing);
441 if (isset($this->type_code)) {
442 $this->type_code = trim($this->type_code);
445 if (isset($this->category_code)) {
446 $this->category_code = trim($this->category_code);
449 if (isset($this->severity_code)) {
450 $this->severity_code = trim($this->severity_code);
453 if (empty($this->
ref)) {
454 $this->errors[] =
'ErrorTicketRefRequired';
455 dol_syslog(get_class($this).
"::create error -1 ref null", LOG_ERR);
471 $test =
new self($this->db);
473 if ($test->fetch(0, $getRef) > 0) {
474 if (($action ==
'add') || ($action ==
'update' && $this->
ref != $getRef)) {
479 $this->
ref = $getRef;
490 public function create($user, $notrigger = 0)
497 if (empty($this->datec)) {
500 if (empty($this->track_id)) {
506 $result = $this->
verify();
513 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"ticket(";
517 $sql .=
"fk_project,";
518 $sql .=
"fk_contract,";
519 $sql .=
"origin_email,";
520 $sql .=
"origin_replyto,";
521 $sql .=
"origin_references,";
522 $sql .=
"fk_user_create,";
523 $sql .=
"fk_user_assign,";
524 $sql .=
"email_msgid,";
525 $sql .=
"email_date,";
528 $sql .=
"fk_statut,";
529 $sql .=
"resolution,";
532 $sql .=
"type_code,";
533 $sql .=
"category_code,";
534 $sql .=
"severity_code,";
536 $sql .=
"date_read,";
537 $sql .=
"date_close,";
539 $sql .=
"notify_tiers_at_create,";
540 $sql .=
"model_pdf,";
542 $sql .=
") VALUES (";
543 $sql .=
" ".(!isset($this->
ref) ?
'' :
"'".$this->db->escape($this->
ref).
"'").
",";
544 $sql .=
" ".(!isset($this->track_id) ?
'NULL' :
"'".$this->db->escape($this->track_id).
"'").
",";
545 $sql .=
" ".($this->fk_soc > 0 ? ((int) $this->fk_soc) :
"null").
",";
546 $sql .=
" ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null").
",";
547 $sql .=
" ".($this->fk_contract > 0 ? ((int) $this->fk_contract) :
"null").
",";
548 $sql .=
" ".(!isset($this->origin_email) ?
'NULL' :
"'".$this->db->escape($this->origin_email).
"'").
",";
549 $sql .=
" ".(!isset($this->origin_replyto) ?
'NULL' :
"'".$this->db->escape($this->origin_replyto).
"'").
",";
550 $sql .=
" ".(!isset($this->origin_references) ?
'NULL' :
"'".$this->db->escape($this->origin_references).
"'").
",";
551 $sql .=
" ".(!isset($this->fk_user_create) ? ($user->id > 0 ? ((int) $user->id) :
'NULL') : ($this->fk_user_create > 0 ? ((int) $this->fk_user_create) :
'NULL')).
",";
552 $sql .=
" ".($this->fk_user_assign > 0 ? ((int) $this->fk_user_assign) :
'NULL').
",";
553 $sql .=
" ".(empty($this->email_msgid) ?
'NULL' :
"'".$this->db->escape($this->email_msgid).
"'").
",";
554 $sql .=
" ".(!
isDolTms($this->email_date) ?
'NULL' :
"'".$this->db->idate($this->email_date).
"'").
",";
555 $sql .=
" ".(!isset($this->subject) ?
'NULL' :
"'".$this->db->escape($this->subject).
"'").
",";
556 $sql .=
" ".(!isset($this->message) ?
'NULL' :
"'".$this->db->escape($this->message).
"'").
",";
557 $sql .=
" ".(!isset($this->
status) ?
'0' : ((int) $this->
status)).
",";
558 $sql .=
" ".(!isset($this->resolution) ?
'NULL' : ((int) $this->resolution)).
",";
559 $sql .=
" ".(!isset($this->progress) ?
'0' : ((int) $this->progress)).
",";
560 $sql .=
" ".(!isset($this->timing) ?
'NULL' :
"'".$this->db->escape($this->timing).
"'").
",";
561 $sql .=
" ".(!isset($this->type_code) ?
'NULL' :
"'".$this->db->escape($this->type_code).
"'").
",";
562 $sql .=
" ".(empty($this->category_code) || $this->category_code ==
'-1' ?
'NULL' :
"'".$this->db->escape($this->category_code).
"'").
",";
563 $sql .=
" ".(!isset($this->severity_code) ?
'NULL' :
"'".$this->db->escape($this->severity_code).
"'").
",";
564 $sql .=
" ".(!
isDolTms($this->datec) ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
565 $sql .=
" ".(!isset($this->date_read) ||
dol_strlen((
string) $this->date_read) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_read).
"'").
",";
566 $sql .=
" ".(!isset($this->date_close) ||
dol_strlen((
string) $this->date_close) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_close).
"'");
567 $sql .=
", ".((int) $this->entity);
568 $sql .=
", ".(!isset($this->notify_tiers_at_create) ? 1 : ((int) $this->notify_tiers_at_create));
569 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
570 $sql .=
", ".(!isset($this->ip) ?
'NULL' :
"'".$this->db->escape($this->ip).
"'");
575 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
576 $resql = $this->db->query($sql);
579 $this->errors[] =
"Error ".$this->db->lasterror();
583 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"ticket");
586 if (!$error &&
getDolGlobalString(
'TICKET_ADD_AUTHOR_AS_CONTACT') && empty($this->context[
"createdfrompublicinterface"])) {
590 if (!empty($user->socid) && !empty($user->contact_id) &&
getDolGlobalInt(
'TICKET_ADD_AUTHOR_AS_CONTACT') == 2) {
591 $contact_type =
'external';
592 $contributor_id = $user->contact_id;
594 $contact_type =
'internal';
595 $contributor_id = $user->id;
599 if ($this->
add_contact($contributor_id,
'CONTRIBUTOR', $contact_type) < 0) {
604 if (!$error && $this->fk_user_assign > 0) {
605 if ($this->
add_contact($this->fk_user_assign,
'SUPPORTTEC',
'internal') < 0) {
619 if (!$error && !$notrigger) {
630 foreach ($this->errors as $errmsg) {
631 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
632 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
634 $this->db->rollback();
641 $this->db->rollback();
642 dol_syslog(get_class($this).
"::Create fails verify ".implode(
',', $this->errors), LOG_WARNING);
656 public function fetch(
$id = 0, $ref =
'', $track_id =
'', $email_msgid =
'')
661 if (empty(
$id) && empty($ref) && empty($track_id) && empty($email_msgid)) {
662 $this->error =
'ErrorWrongParameters';
669 $sql .=
" t.entity,";
671 $sql .=
" t.track_id,";
672 $sql .=
" t.fk_soc,";
673 $sql .=
" t.fk_project,";
674 $sql .=
" t.fk_contract,";
675 $sql .=
" t.origin_email,";
676 $sql .=
" t.origin_replyto,";
677 $sql .=
" t.origin_references,";
678 $sql .=
" t.fk_user_create,";
679 $sql .=
" t.fk_user_assign,";
680 $sql .=
" t.email_msgid,";
681 $sql .=
" t.email_date,";
682 $sql .=
" t.subject,";
683 $sql .=
" t.message,";
684 $sql .=
" t.fk_statut as status,";
685 $sql .=
" t.resolution,";
686 $sql .=
" t.progress,";
687 $sql .=
" t.timing,";
688 $sql .=
" t.type_code,";
689 $sql .=
" t.category_code,";
690 $sql .=
" t.severity_code,";
692 $sql .=
" t.date_read,";
693 $sql .=
" t.date_last_msg_sent,";
694 $sql .=
" t.date_close,";
696 $sql .=
" t.model_pdf,";
697 $sql .=
" t.extraparams,";
699 $sql .=
" type.label as type_label, category.label as category_label, severity.label as severity_label";
700 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
701 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
702 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
703 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
706 $sql .=
" WHERE t.rowid = ".((int)
$id);
708 $sql .=
" WHERE t.entity IN (".getEntity($this->element, 1).
")";
710 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
711 } elseif ($track_id) {
712 $sql .=
" AND t.track_id = '".$this->db->escape($track_id).
"'";
714 $sql .=
" AND t.email_msgid = '".$this->db->escape($email_msgid).
"'";
718 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
719 $resql = $this->db->query($sql);
721 if ($this->db->num_rows($resql)) {
722 $obj = $this->db->fetch_object($resql);
724 $this->
id = $obj->rowid;
725 $this->entity = $obj->entity;
726 $this->
ref = $obj->ref;
727 $this->track_id = $obj->track_id;
728 $this->fk_soc = $obj->fk_soc;
729 $this->socid = $obj->fk_soc;
730 $this->fk_project = $obj->fk_project;
731 $this->fk_contract = $obj->fk_contract;
732 $this->origin_email = $obj->origin_email;
733 $this->origin_replyto = $obj->origin_replyto;
734 $this->origin_references = $obj->origin_references;
735 $this->fk_user_create = $obj->fk_user_create;
736 $this->fk_user_assign = $obj->fk_user_assign;
737 $this->email_msgid = $obj->email_msgid;
738 $this->email_date = $this->db->jdate($obj->email_date);
739 $this->subject = $obj->subject;
740 $this->message = $obj->message;
741 $this->model_pdf = $obj->model_pdf;
742 $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
743 $this->ip = $obj->ip;
745 $this->
status = $obj->status;
746 $this->fk_statut = $this->status;
748 $this->resolution = $obj->resolution;
749 $this->progress = $obj->progress;
750 $this->timing = $obj->timing;
752 $this->type_code = $obj->type_code;
753 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) !=
"TicketTypeShort".$obj->type_code ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
754 $this->type_label = $label_type;
756 $this->category_code = $obj->category_code;
757 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) !=
"TicketCategoryShort".$obj->category_code ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
758 $this->category_label = $label_category;
760 $this->severity_code = $obj->severity_code;
761 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) !=
"TicketSeverityShort".$obj->severity_code ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
762 $this->severity_label = $label_severity;
764 $this->datec = $this->db->jdate($obj->datec);
765 $this->date_creation = $this->db->jdate($obj->datec);
766 $this->date_read = $this->db->jdate($obj->date_read);
767 $this->date_validation = $this->db->jdate($obj->date_read);
768 $this->date_last_msg_sent = $this->db->jdate($obj->date_last_msg_sent);
769 $this->date_close = $this->db->jdate($obj->date_close);
770 $this->tms = $this->db->jdate($obj->tms);
771 $this->date_modification = $this->db->jdate($obj->tms);
775 $this->db->free($resql);
781 $this->error =
"Error ".$this->db->lasterror();
782 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
799 public function fetchAll($user, $sortorder =
'ASC', $sortfield =
't.datec', $limit = 0, $offset = 0, $arch = 0, $filter =
'')
801 global $langs, $extrafields;
804 $extrafields->fetch_name_optionals_label($this->table_element);
809 $sql .=
" t.track_id,";
810 $sql .=
" t.fk_soc,";
811 $sql .=
" t.fk_project,";
812 $sql .=
" t.fk_contract,";
813 $sql .=
" t.origin_email,";
814 $sql .=
" t.origin_replyto,";
815 $sql .=
" t.origin_references,";
816 $sql .=
" t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
817 $sql .=
" t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
818 $sql .=
" t.subject,";
819 $sql .=
" t.message,";
820 $sql .=
" t.fk_statut as status,";
821 $sql .=
" t.resolution,";
822 $sql .=
" t.progress,";
823 $sql .=
" t.timing,";
824 $sql .=
" t.type_code,";
825 $sql .=
" t.category_code,";
826 $sql .=
" t.severity_code,";
828 $sql .=
" t.date_read,";
829 $sql .=
" t.date_last_msg_sent,";
830 $sql .=
" t.date_close,";
832 $sql .=
" type.label as type_label, category.label as category_label, severity.label as severity_label";
834 if ($extrafields->attributes[$this->table_element][
'count'] > 0) {
835 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
836 $sql .= ($extrafields->attributes[$this->table_element][
'type'][$key] !=
'separate' ?
",ef.".$key.
" as options_".$key :
'');
839 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
840 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code = t.type_code";
841 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code = t.category_code";
842 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code = t.severity_code";
843 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid = t.fk_soc";
844 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as uc ON uc.rowid = t.fk_user_create";
845 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as ua ON ua.rowid = t.fk_user_assign";
846 if ($extrafields->attributes[$this->table_element][
'count'] > 0) {
847 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
848 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ticket_extrafields as ef on (t.rowid = ef.fk_object)";
851 $sql .=
" WHERE t.entity IN (".getEntity(
'ticket').
")";
854 if (is_array($filter)) {
855 foreach ($filter as $key => $value) {
856 if (strpos($key,
'date')) {
857 $sql .=
" AND ".$this->db->sanitize($key).
" = '".$this->db->escape((
string) $value).
"'";
858 } elseif (($key ==
't.fk_user_assign') || ($key ==
't.type_code') || ($key ==
't.category_code') || ($key ==
't.severity_code') || ($key ==
't.fk_soc')) {
859 $sql .=
" AND ".$this->db->sanitize($key).
" = '".$this->db->escape((
string) $value).
"'";
860 } elseif ($key ==
't.fk_statut') {
861 if (is_array($value) && count($value) > 0) {
862 $sql .=
" AND ".$this->db->sanitize($key).
" IN (".$this->db->sanitize(implode(
',', $value)).
")";
864 $sql .=
" AND ".$this->db->sanitize($key).
' = '.((int) $value);
866 } elseif ($key ==
't.fk_contract') {
867 $sql .=
" AND ".$this->db->sanitize($key).
' = '.((int) $value);
869 $sql .=
" AND ".$this->db->sanitize($key).
" LIKE '%".$this->db->escape($this->db->escapeforlike((
string) $value)).
"%'";
880 $this->errors[] = $errormessage;
881 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
886 $socid = $user->socid ?: 0;
889 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
890 $search_sale = $user->id;
893 if ($search_sale && $search_sale !=
'-1') {
894 if ($search_sale == -2) {
895 $sql .=
" AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc)";
896 } elseif ($search_sale > 0) {
897 $sql .=
" AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX.
"societe_commerciaux as sc WHERE sc.fk_soc = t.fk_soc AND sc.fk_user = ".((int) $search_sale).
")";
902 $sql .=
" AND t.fk_soc = ".((int) $socid);
905 $sql .= $this->db->order($sortfield, $sortorder);
906 if (!empty($limit)) {
907 $sql .= $this->db->plimit($limit + 1, $offset);
910 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
911 $resql = $this->db->query($sql);
914 $this->lines = array();
916 $num = $this->db->num_rows($resql);
921 $obj = $this->db->fetch_object($resql);
923 $line =
new self($this->db);
925 $line->id = $obj->rowid;
927 $line->ref = $obj->ref;
928 $line->track_id = $obj->track_id;
929 $line->fk_soc = $obj->fk_soc;
930 $line->fk_project = $obj->fk_project;
931 $line->fk_contract = $obj->fk_contract;
932 $line->origin_email = $obj->origin_email;
933 $line->origin_replyto = $obj->origin_replyto;
934 $line->origin_references = $obj->origin_references;
936 $line->fk_user_create = $obj->fk_user_create;
937 $line->fk_user_assign = $obj->fk_user_assign;
939 $line->subject = $obj->subject;
940 $line->message = $obj->message;
941 $line->fk_statut = $obj->status;
942 $line->status = $obj->status;
943 $line->resolution = $obj->resolution;
944 $line->progress = $obj->progress;
945 $line->timing = $obj->timing;
947 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) !=
"TicketTypeShort".$obj->type_code ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
948 $line->type_label = $label_type;
950 $this->category_code = $obj->category_code;
951 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) !=
"TicketCategoryShort".$obj->category_code ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
952 $line->category_label = $label_category;
954 $this->severity_code = $obj->severity_code;
955 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) !=
"TicketSeverityShort".$obj->severity_code ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
956 $line->severity_label = $label_severity;
958 $line->datec = $this->db->jdate($obj->datec);
959 $line->date_read = $this->db->jdate($obj->date_read);
960 $line->date_last_msg_sent = $this->db->jdate($obj->date_last_msg_sent);
961 $line->date_close = $this->db->jdate($obj->date_close);
964 if ($extrafields->attributes[$this->table_element][
'count'] > 0) {
965 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
966 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
967 $tmpkey =
'options_'.$key;
968 $line->{$tmpkey} = $obj->$tmpkey;
972 $this->lines[$i] = $line;
976 $this->db->free($resql);
979 $this->error =
"Error ".$this->db->lasterror();
980 dol_syslog(get_class($this).
"::fetchAll ".$this->error, LOG_ERR);
992 public function update($user, $notrigger = 0)
1003 if (isset($this->
ref)) {
1004 $this->
ref = trim($this->
ref);
1007 if (isset($this->track_id)) {
1008 $this->track_id = trim($this->track_id);
1011 if (isset($this->fk_soc)) {
1012 $this->fk_soc = (int) $this->fk_soc;
1015 if (isset($this->fk_project)) {
1016 $this->fk_project = (int) $this->fk_project;
1019 if (isset($this->fk_contract)) {
1020 $this->fk_contract = (int) $this->fk_contract;
1023 if (isset($this->origin_email)) {
1024 $this->origin_email = trim($this->origin_email);
1027 if (isset($this->fk_user_create)) {
1028 $this->fk_user_create = (int) $this->fk_user_create;
1031 if (isset($this->fk_user_assign)) {
1032 $this->fk_user_assign = (int) $this->fk_user_assign;
1035 if (isset($this->subject)) {
1036 $this->subject = trim($this->subject);
1039 if (isset($this->message)) {
1040 $this->message = trim($this->message);
1042 $this->errors[] =
'ErrorFieldTooLong';
1043 dol_syslog(get_class($this).
'::update error -1 message too long', LOG_ERR);
1048 if (isset($this->
status)) {
1052 if (isset($this->resolution)) {
1053 $this->resolution = (int) $this->resolution;
1056 if (isset($this->progress)) {
1057 $this->progress = (int) $this->progress;
1060 if (isset($this->timing)) {
1061 $this->timing = trim($this->timing);
1064 if (isset($this->type_code)) {
1065 $this->timing = trim($this->type_code);
1068 if (isset($this->category_code)) {
1069 $this->timing = trim($this->category_code);
1072 if (isset($this->severity_code)) {
1073 $this->timing = trim($this->severity_code);
1075 if (isset($this->model_pdf)) {
1076 $this->model_pdf = trim($this->model_pdf);
1081 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket SET";
1082 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"").
",";
1083 $sql .=
" track_id=".(isset($this->track_id) ?
"'".$this->db->escape($this->track_id).
"'" :
"null").
",";
1084 $sql .=
" fk_soc=".(isset($this->fk_soc) ? (int) $this->fk_soc :
"null").
",";
1085 $sql .=
" fk_project=".(isset($this->fk_project) ? (int) $this->fk_project :
"null").
",";
1086 $sql .=
" fk_contract=".(isset($this->fk_contract) ? (int) $this->fk_contract :
"null").
",";
1087 $sql .=
" origin_email=".(isset($this->origin_email) ?
"'".$this->db->escape($this->origin_email).
"'" :
"null").
",";
1088 $sql .=
" origin_replyto=".(isset($this->origin_replyto) ?
"'".$this->db->escape($this->origin_replyto).
"'" :
"null").
",";
1089 $sql .=
" origin_references=".(isset($this->origin_references) ?
"'".$this->db->escape($this->origin_references).
"'" :
"null").
",";
1090 $sql .=
" fk_user_create=".(isset($this->fk_user_create) ? (int) $this->fk_user_create :
"null").
",";
1091 $sql .=
" fk_user_assign=".(isset($this->fk_user_assign) ? (int) $this->fk_user_assign :
"null").
",";
1092 $sql .=
" subject=".(isset($this->subject) ?
"'".$this->db->escape($this->subject).
"'" :
"null").
",";
1093 $sql .=
" message=".(isset($this->message) ?
"'".$this->db->escape($this->message).
"'" :
"null").
",";
1094 $sql .=
" fk_statut=".(isset($this->
status) ? (int) $this->
status :
"0").
",";
1095 $sql .=
" resolution=".(isset($this->resolution) ? (int) $this->resolution :
"null").
",";
1096 $sql .=
" progress=".(isset($this->progress) ?
"'".$this->db->escape((
string) $this->progress).
"'" :
"null").
",";
1097 $sql .=
" timing=".(isset($this->timing) ?
"'".$this->db->escape($this->timing).
"'" :
"null").
",";
1098 $sql .=
" type_code=".(isset($this->type_code) ?
"'".$this->db->escape($this->type_code).
"'" :
"null").
",";
1099 $sql .=
" category_code=".(isset($this->category_code) ?
"'".$this->db->escape($this->category_code).
"'" :
"null").
",";
1100 $sql .=
" severity_code=".(isset($this->severity_code) ?
"'".$this->db->escape($this->severity_code).
"'" :
"null").
",";
1101 $sql .=
" datec=".(isDolTms($this->datec) ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
1102 $sql .=
" date_read=".(dol_strlen((
string) $this->date_read) != 0 ?
"'".$this->db->idate($this->date_read).
"'" :
'null').
",";
1103 $sql .=
" date_last_msg_sent=".(dol_strlen((
string) $this->date_last_msg_sent) != 0 ?
"'".$this->db->idate($this->date_last_msg_sent).
"'" :
'null').
",";
1104 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1105 $sql .=
" date_close=".(dol_strlen((
string) $this->date_close) != 0 ?
"'".$this->db->idate($this->date_close).
"'" :
'null');
1106 $sql .=
" WHERE rowid=".((int) $this->
id);
1110 $resql = $this->db->query($sql);
1113 $this->errors[] =
"Error ".$this->db->lasterror();
1118 $result = $this->insertExtraFields();
1124 if (!$error && !$notrigger) {
1126 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1135 foreach ($this->errors as $errmsg) {
1136 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1137 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1139 $this->db->rollback();
1142 $this->db->commit();
1154 public function delete($user, $notrigger = 0)
1162 $result = $this->call_trigger(
'TICKET_DELETE', $user);
1171 $res = $this->delete_linked_contact();
1173 dol_syslog(get_class($this).
"::delete error", LOG_ERR);
1180 $res = $this->deleteObjectLinked();
1188 $result = $this->deleteExtraFields();
1191 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1198 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_ticket";
1199 $sql .=
" WHERE fk_ticket = ".(int) $this->
id;
1201 $result = $this->db->query($sql);
1204 $this->errors[] = $this->db->lasterror();
1209 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ticket";
1210 $sql .=
" WHERE rowid=".((int) $this->
id);
1212 dol_syslog(get_class($this).
"::delete sql=".$sql);
1213 $resql = $this->db->query($sql);
1216 $this->errors[] =
"Error ".$this->db->lasterror();
1219 $this->deleteEcmFiles(1);
1221 $dir = DOL_DATA_ROOT.
'/'.$this->element.
'/'.$this->ref;
1225 $this->errors[] = $this->error;
1233 foreach ($this->errors as $errmsg) {
1234 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1235 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1237 $this->db->rollback();
1240 $this->db->commit();
1269 $object->context[
'createfromclone'] =
'createfromclone';
1270 $result =
$object->create($user);
1274 $this->error =
$object->error;
1278 unset(
$object->context[
'createfromclone']);
1282 $this->db->commit();
1285 $this->db->rollback();
1300 $this->
ref =
'TI0501-001';
1301 $this->track_id =
'XXXXaaaa';
1302 $this->origin_email =
'email@email.com';
1303 $this->fk_project = 1;
1304 $this->fk_user_create = 1;
1305 $this->fk_user_assign = 1;
1306 $this->subject =
'Subject of ticket';
1307 $this->message =
'Message of ticket';
1309 $this->resolution = 1;
1310 $this->progress = 10;
1312 $this->type_code =
'TYPECODE';
1313 $this->category_code =
'CATEGORYCODE';
1314 $this->severity_code =
'SEVERITYCODE';
1317 $this->date_last_msg_sent =
dol_now();
1318 $this->date_close =
dol_now();
1332 print
Form::selectarray(
'search_fk_statut', $this->labelStatusShort, $selected, $show_empty = 1, $key_in_label = 0, $value_as_key = 0, $option =
'', $translate = 1, $maxlen = 0, $disabled = 0, $sort =
'', $morecss =
'');
1345 if (!empty($this->cache_types_tickets) && count($this->cache_types_tickets)) {
1350 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1351 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type";
1352 $sql .=
" WHERE entity IN (".getEntity(
'c_ticket_type').
")";
1353 $sql .=
" AND active > 0";
1354 $sql .=
" ORDER BY pos";
1355 dol_syslog(get_class($this).
"::load_cache_type_tickets", LOG_DEBUG);
1356 $resql = $this->db->query($sql);
1358 $num = $this->db->num_rows($resql);
1361 $obj = $this->db->fetch_object($resql);
1362 $label = ($langs->trans(
"TicketTypeShort".$obj->code) !=
"TicketTypeShort".$obj->code ? $langs->trans(
"TicketTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1363 $this->cache_types_tickets[$obj->rowid][
'code'] = $obj->code;
1364 $this->cache_types_tickets[$obj->rowid][
'label'] = $label;
1365 $this->cache_types_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1366 $this->cache_types_tickets[$obj->rowid][
'pos'] = $obj->pos;
1384 global
$conf, $langs;
1386 if ($publicgroup == -1 && !empty(
$conf->cache[
'category_tickets']) && count(
$conf->cache[
'category_tickets'])) {
1391 $sql =
"SELECT rowid, code, label, use_default, pos, description, public, active, force_severity, fk_parent";
1392 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category";
1393 $sql .=
" WHERE entity IN (".getEntity(
'c_ticket_category').
")";
1394 $sql .=
" AND active > 0";
1395 if ($publicgroup > -1) {
1396 $sql .=
" AND public = ".((int) $publicgroup);
1398 $sql .=
" ORDER BY pos";
1400 dol_syslog(get_class($this).
"::load_cache_categories_tickets", LOG_DEBUG);
1402 $resql = $this->db->query($sql);
1404 $num = $this->db->num_rows($resql);
1407 $obj = $this->db->fetch_object($resql);
1408 $conf->cache[
'category_tickets'][$obj->rowid][
'code'] = $obj->code;
1409 $conf->cache[
'category_tickets'][$obj->rowid][
'use_default'] = $obj->use_default;
1410 $conf->cache[
'category_tickets'][$obj->rowid][
'pos'] = $obj->pos;
1411 $conf->cache[
'category_tickets'][$obj->rowid][
'public'] = $obj->public;
1412 $conf->cache[
'category_tickets'][$obj->rowid][
'active'] = $obj->active;
1413 $conf->cache[
'category_tickets'][$obj->rowid][
'force_severity'] = $obj->force_severity;
1414 $conf->cache[
'category_tickets'][$obj->rowid][
'fk_parent'] = $obj->fk_parent;
1418 $label = ($langs->trans(
"TicketCategoryShort".$obj->code) !=
"TicketCategoryShort".$obj->code ? $langs->trans(
"TicketCategoryShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1419 $conf->cache[
'category_tickets'][$obj->rowid][
'label'] = $label;
1437 global
$conf, $langs;
1439 if (!empty(
$conf->cache[
'severity_tickets']) && count(
$conf->cache[
'severity_tickets'])) {
1444 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1445 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity";
1446 $sql .=
" WHERE entity IN (".getEntity(
'c_ticket_severity').
")";
1447 $sql .=
" AND active > 0";
1448 $sql .=
" ORDER BY pos";
1449 dol_syslog(get_class($this).
"::loadCacheSeveritiesTickets", LOG_DEBUG);
1450 $resql = $this->db->query($sql);
1452 $num = $this->db->num_rows($resql);
1455 $obj = $this->db->fetch_object($resql);
1457 $conf->cache[
'severity_tickets'][$obj->rowid][
'code'] = $obj->code;
1458 $label = ($langs->trans(
"TicketSeverityShort".$obj->code) !=
"TicketSeverityShort".$obj->code ? $langs->trans(
"TicketSeverityShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1459 $conf->cache[
'severity_tickets'][$obj->rowid][
'label'] = $label;
1460 $conf->cache[
'severity_tickets'][$obj->rowid][
'use_default'] = $obj->use_default;
1461 $conf->cache[
'severity_tickets'][$obj->rowid][
'pos'] = $obj->pos;
1480 return $this->LibStatut($this->
status, $mode, 0, $this->progress);
1494 public function LibStatut($status, $mode = 0, $notooltip = 0, $progress = 0)
1497 global $langs, $hookmanager;
1499 $labelStatus = (isset($status) && !empty($this->labelStatus[$status])) ? $this->labelStatus[$status] :
'';
1500 $labelStatusShort = (isset($status) && !empty($this->labelStatusShort[$status])) ? $this->labelStatusShort[$status] :
'';
1503 case self::STATUS_NOT_READ:
1504 $statusType =
'status0';
1506 case self::STATUS_READ:
1507 $statusType =
'status1';
1509 case self::STATUS_ASSIGNED:
1510 $statusType =
'status2';
1512 case self::STATUS_IN_PROGRESS:
1513 $statusType =
'status4';
1515 case self::STATUS_WAITING:
1516 $statusType =
'status7';
1518 case self::STATUS_NEED_MORE_INFO:
1519 $statusType =
'status3';
1521 case self::STATUS_CANCELED:
1522 $statusType =
'status9';
1524 case self::STATUS_CLOSED:
1525 $statusType =
'status6';
1528 $labelStatus =
'Unknown';
1529 $labelStatusShort =
'Unknown';
1530 $statusType =
'status0';
1534 $parameters = array(
1535 'status' => $status,
1540 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
1543 return $hookmanager->resPrint;
1548 $params = array(
'tooltip' =>
'no');
1551 $labelStatus = $langs->transnoentitiesnoconv($labelStatus);
1552 $labelStatusShort = $langs->transnoentitiesnoconv($labelStatusShort);
1554 if ($status == self::STATUS_IN_PROGRESS && $progress > 0) {
1555 $labelStatus .=
' ('.round($progress).
'%)';
1556 $labelStatusShort .=
' ('.round($progress).
'%)';
1559 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $params);
1572 $langs->load(
'ticket');
1573 $nofetch = !empty($params[
'nofetch']);
1576 $datas[
'picto'] =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Ticket").
'</u>';
1577 $datas[
'picto'] .=
' '.$this->getLibStatut(4);
1578 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1579 $datas[
'track_id'] =
'<br><b>'.$langs->trans(
'TicketTrackId').
':</b> '.$this->track_id;
1580 $datas[
'subject'] =
'<br><b>'.$langs->trans(
'Subject').
':</b> '.$this->subject;
1581 if ($this->date_creation) {
1582 $datas[
'date_creation'] =
'<br><b>'.$langs->trans(
'DateCreation').
':</b> '.
dol_print_date($this->date_creation,
'dayhour');
1584 if ($this->date_modification) {
1585 $datas[
'date_modification'] =
'<br><b>'.$langs->trans(
'DateModification').
':</b> '.
dol_print_date($this->date_modification,
'dayhour');
1588 if (isModEnabled(
'category') && !$nofetch) {
1589 require_once DOL_DOCUMENT_ROOT .
'/categories/class/categorie.class.php';
1590 $form =
new Form($this->db);
1591 $datas[
'categories'] =
'<br>' . $form->showCategories($this->
id, Categorie::TYPE_TICKET, 1);
1607 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1609 global $action,
$conf, $hookmanager, $langs;
1611 if (!empty(
$conf->dol_no_mouse_hover)) {
1619 'objecttype' => $this->element,
1620 'option' => $option,
1623 $classfortooltip =
'classfortooltip';
1626 $classfortooltip =
'classforajaxtooltip';
1627 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1630 $label = implode($this->getTooltipContentArray($params));
1633 $url = DOL_URL_ROOT.
'/ticket/card.php?id='.
$this->id;
1635 if ($option !=
'nolink') {
1637 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1638 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1639 $add_save_lastsearch_values = 1;
1641 if ($add_save_lastsearch_values) {
1642 $url .=
'&save_lastsearch_values=1';
1647 if (empty($notooltip)) {
1649 $label = $langs->trans(
"ShowTicket");
1650 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1652 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1653 $linkclose .= $dataparams.
' class="'.$classfortooltip.($morecss ?
' '.$morecss :
'').
'"';
1655 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1658 $linkstart =
'<a href="'.$url.
'"';
1659 $linkstart .= $linkclose.
'>';
1662 $result .= $linkstart;
1664 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ?:
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1666 if ($withpicto != 2) {
1667 $result .= $this->ref;
1669 $result .= $linkend;
1672 $hookmanager->initHooks(array(
'ticketdao'));
1673 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1674 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1676 $result = $hookmanager->resPrint;
1678 $result .= $hookmanager->resPrint;
1698 if ($this->
status != self::STATUS_CANCELED) {
1703 $this->
status = Ticket::STATUS_READ;
1705 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1706 $sql .=
" SET fk_statut = ".((int) $this->
status) .
", date_read = '".$this->db->idate(
dol_now()).
"'";
1707 $sql .=
" WHERE rowid = ".((int) $this->
id);
1710 $resql = $this->db->query($sql);
1712 $this->context[
'actionmsg'] = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1713 $this->context[
'actionmsg2'] = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1717 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1725 $this->db->commit();
1728 $this->
status = $this->oldcopy->status;
1730 $this->db->rollback();
1732 $this->error = implode(
',', $this->errors);
1734 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1738 $this->
status = $this->oldcopy->status;
1740 $this->db->rollback();
1741 $this->error = $this->db->lasterror();
1742 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1758 public function assignUser($user, $id_assign_user, $notrigger = 0)
1766 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1767 if ($id_assign_user > 0) {
1768 $sql .=
" SET fk_user_assign=".((int) $id_assign_user).
", fk_statut = ".Ticket::STATUS_ASSIGNED;
1770 $sql .=
" SET fk_user_assign=null, fk_statut = ".Ticket::STATUS_READ;
1772 $sql .=
" WHERE rowid = ".((int) $this->
id);
1774 dol_syslog(get_class($this).
"::assignUser sql=".$sql);
1775 $resql = $this->db->query($sql);
1777 $this->fk_user_assign = $id_assign_user;
1781 $result = $this->call_trigger(
'TICKET_ASSIGNED', $user);
1789 $this->db->commit();
1792 $this->db->rollback();
1793 $this->error = implode(
',', $this->errors);
1794 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1798 $this->db->rollback();
1799 $this->error = $this->db->lasterror();
1800 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1817 public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $send_email =
false, $public_area = 0)
1825 if (isset($this->fk_track_id)) {
1826 $this->fk_track_id = trim($this->fk_track_id);
1829 if (isset($this->message)) {
1830 $this->message = trim($this->message);
1836 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1838 $actioncomm->type_code =
'AC_OTH_AUTO';
1839 $actioncomm->code =
'TICKET_MSG';
1840 if ($this->
private) {
1841 $actioncomm->code =
'TICKET_MSG_PRIVATE';
1844 $actioncomm->code .=
'_SENTBYMAIL';
1846 if ((empty($user->id) || $user->id == 0) && isset($_SESSION[
'email_customer'])) {
1847 $actioncomm->email_from = $_SESSION[
'email_customer'];
1849 $actioncomm->socid = $this->socid;
1850 $actioncomm->label = $this->subject;
1851 $actioncomm->note_private = $this->message;
1852 $actioncomm->userassigned = array($user->id => array(
'id' => $user->id,
'transparency' => 0));
1853 $actioncomm->userownerid = $user->id;
1854 $actioncomm->datep = $now;
1855 $actioncomm->percentage = -1;
1856 $actioncomm->elementtype =
'ticket';
1859 $actioncomm->elementtype =
'ticket';
1860 $actioncomm->fk_project = $this->fk_project;
1866 if ($public_area && !empty($this->origin_email) &&
getDolGlobalString(
'TICKET_ASSIGN_CONTACT_TO_MESSAGE')) {
1867 $contacts = $this->searchContactByEmail($this->origin_email);
1868 if (!empty($contacts)) {
1870 foreach ($contacts as $contact) {
1871 if ((
int) $contact->statut == 1) {
1872 $actioncomm->contact_id = $contact->id;
1879 $attachedfiles = array();
1880 $attachedfiles[
'paths'] = $filename_list;
1881 $attachedfiles[
'names'] = $mimefilename_list;
1882 $attachedfiles[
'mimes'] = $mimetype_list;
1883 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
1884 $actioncomm->attachedfiles = $attachedfiles;
1890 $actionid = $actioncomm->create($user);
1891 if ($actionid <= 0) {
1893 $this->error = $actioncomm->error;
1894 $this->errors = $actioncomm->errors;
1897 if ($actionid > 0) {
1898 if (is_array($attachedfiles) && array_key_exists(
'paths', $attachedfiles) && count($attachedfiles[
'paths']) > 0) {
1900 foreach ($attachedfiles[
'paths'] as $key => $filespath) {
1902 $destdir =
$conf->ticket->dir_output.
'/'.$this->ref;
1907 if (in_array($actioncomm->code, array(
'TICKET_MSG',
'TICKET_MSG_SENTBYMAIL',
'TICKET_MSG_PRIVATE'))) {
1908 $ecmfile =
new EcmFiles($this->db);
1909 $destdir = preg_replace(
'/^'.preg_quote(DOL_DATA_ROOT,
'/').
'/',
'', $destdir);
1910 $destdir = preg_replace(
'/[\\/]$/',
'', $destdir);
1911 $destdir = preg_replace(
'/^[\\/]/',
'', $destdir);
1913 $result = $ecmfile->fetch(0,
'', $destdir.
'/'.$attachedfiles[
'names'][$key]);
1916 $ecmfile->agenda_id = $actionid;
1919 $result = $ecmfile->update($user);
1932 $this->db->rollback();
1935 $this->db->commit();
1947 if (!empty($this->cache_msgs_ticket) && is_array($this->cache_msgs_ticket) && count($this->cache_msgs_ticket)) {
1953 $sql =
"SELECT id as rowid, fk_user_author, email_from, datec, datep, label, note as message, code";
1954 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm";
1955 $sql .=
" WHERE fk_element = ".(int) $this->
id;
1956 $sql .=
" AND elementtype = 'ticket'";
1957 $sql .=
" ORDER BY datep DESC";
1959 dol_syslog(get_class($this).
"::load_cache_actions_ticket", LOG_DEBUG);
1960 $resql = $this->db->query($sql);
1962 $num = $this->db->num_rows($resql);
1965 $obj = $this->db->fetch_object($resql);
1966 $this->cache_msgs_ticket[$i][
'id'] = $obj->rowid;
1967 $this->cache_msgs_ticket[$i][
'fk_user_author'] = $obj->fk_user_author;
1968 if (in_array($obj->code, array(
'TICKET_MSG',
'AC_TICKET_CREATE')) && empty($obj->fk_user_author)) {
1969 $this->cache_msgs_ticket[$i][
'fk_contact_author'] = $obj->email_from;
1971 $this->cache_msgs_ticket[$i][
'datec'] = $this->db->jdate($obj->datec);
1972 $this->cache_msgs_ticket[$i][
'datep'] = $this->db->jdate($obj->datep);
1973 $this->cache_msgs_ticket[$i][
'subject'] = $obj->label;
1974 $this->cache_msgs_ticket[$i][
'message'] = $obj->message;
1975 $this->cache_msgs_ticket[$i][
'private'] = (preg_match(
'/^TICKET_MSG_PRIVATE/', $obj->code) ? 1 : 0);
1980 $this->error =
"Error ".$this->db->lasterror();
1981 dol_syslog(get_class($this).
"::load_cache_actions_ticket ".$this->error, LOG_ERR);
1996 if ($this->
status != Ticket::STATUS_CLOSED && $this->
status != Ticket::STATUS_CANCELED) {
2000 $this->
status = ($mode ? Ticket::STATUS_CANCELED : Ticket::STATUS_CLOSED);
2002 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2003 $sql .=
" SET fk_statut = ".((int) $this->
status).
", progress=100, date_close='".$this->db->idate(
dol_now()).
"'";
2004 $sql .=
" WHERE rowid = ".((int) $this->
id);
2006 dol_syslog(get_class($this).
"::close mode=".$mode);
2007 $resql = $this->db->query($sql);
2012 if (isModEnabled(
'intervention') &&
getDolGlobalString(
'WORKFLOW_TICKET_CLOSE_INTERVENTION')) {
2013 dol_syslog(
"We have closed the ticket, so we close all linked interventions");
2014 $this->fetchObjectLinked($this->
id, $this->element,
null,
'fichinter');
2015 if ($this->linkedObjectsIds) {
2016 foreach ($this->linkedObjectsIds[
'fichinter'] as $fichinter_id) {
2018 $fichinter->fetch($fichinter_id);
2019 if ($fichinter->statut == 0) {
2020 $result = $fichinter->setValid($user);
2022 $this->errors[] = $fichinter->error;
2026 if ($fichinter->statut < 3) {
2027 $result = $fichinter->setStatut(3);
2029 $this->errors[] = $fichinter->error;
2038 $result = $this->call_trigger(
'TICKET_CLOSE', $user);
2045 $this->db->commit();
2048 $this->db->rollback();
2049 $this->error = implode(
',', $this->errors);
2050 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
2054 $this->db->rollback();
2055 $this->error = $this->db->lasterror();
2056 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
2075 $thirdparties = array();
2079 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
2080 $sql .=
" WHERE entity IN (".getEntity(
'ticket', 1).
")";
2081 if (!empty($type)) {
2082 if ($type == 1 || $type == 2) {
2083 $sql .=
" AND client = ".((int) $type);
2084 } elseif ($type == 3) {
2085 $sql .=
" AND fournisseur = 1";
2088 if (!empty($email)) {
2089 if (empty($exact)) {
2091 if (preg_match(
'/^([\*])?[^*]+([\*])?$/', $email, $regs) && count($regs) > 1) {
2092 $email = str_replace(
'*',
'%', $email);
2094 $email =
'%'.$email.
'%';
2098 if (is_array($filters) && !empty($filters)) {
2102 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
2104 if (is_array($filters) && !empty($filters)) {
2105 foreach ($filters as $field => $value) {
2106 $sql .=
" ".$clause.
" ".$this->db->sanitize($field).
" LIKE '".$this->db->escape($value).
"'";
2108 if (!empty($email)) {
2113 $res = $this->db->query($sql);
2115 while ($rec = $this->db->fetch_array($res)) {
2116 $soc =
new Societe($this->db);
2117 $soc->fetch($rec[
'rowid']);
2118 $thirdparties[] = $soc;
2121 return $thirdparties;
2123 $this->error = $this->db->error().
' sql='.$sql;
2124 dol_syslog(get_class($this).
"::searchSocidByEmail ".$this->error, LOG_ERR);
2139 $contacts = array();
2142 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople";
2143 $sql .=
" WHERE entity IN (".getEntity(
'contact').
")";
2144 if (!empty($socid)) {
2145 $sql .=
" AND fk_soc = ".((int) $socid);
2147 if (!empty($email)) {
2150 $sql .=
"email = '".$this->db->escape($email).
"'";
2152 $sql .=
"email LIKE BINARY '".$this->db->escape($this->db->escapeforlike($email)).
"'";
2156 $res = $this->db->query($sql);
2158 while ($rec = $this->db->fetch_object($res)) {
2159 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2160 $contactstatic =
new Contact($this->db);
2161 $contactstatic->fetch($rec->rowid);
2162 $contacts[] = $contactstatic;
2167 $this->error = $this->db->error().
' sql='.$sql;
2168 dol_syslog(get_class($this).
"::searchContactByEmail ".$this->error, LOG_ERR);
2182 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2183 $sql .=
" SET fk_soc = ".($id > 0 ? (int)
$id :
"null");
2184 $sql .=
" WHERE rowid = ".((int) $this->
id);
2185 dol_syslog(get_class($this).
'::setCustomer sql='.$sql);
2186 $resql = $this->db->query($sql);
2206 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2207 $sql .=
" SET progress = ".($percent > 0 ? (float) $percent :
"null");
2208 $sql .=
" WHERE rowid = ".((int) $this->
id);
2209 dol_syslog(get_class($this).
'::set_progression sql='.$sql);
2210 $resql = $this->db->query($sql);
2230 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
2231 $sql .=
" SET fk_contract = ".($contractid > 0 ? (int) $contractid :
"null");
2232 $sql .=
" WHERE rowid = ".((int) $this->
id);
2233 dol_syslog(get_class($this).
'::setContract sql='.$sql);
2234 $resql = $this->db->query($sql);
2254 return $this->getIdContact(
'internal',
'SUPPORTTEC');
2265 return $this->listeContact(-1,
'internal', 0,
'', $status);
2275 return $this->getIdContact(
'external',
'SUPPORTCLI');
2286 return $this->listeContact(-1,
'external', 0,
'', $status);
2296 return $this->getIdContact(
'internal',
'CONTRIBUTOR');
2306 return $this->getIdContact(
'external',
'CONTRIBUTOR');
2316 $array_contact = $this->getIdTicketInternalContact();
2318 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact());
2320 $array_contact = array_merge($array_contact, $this->getIdTicketInternalInvolvedContact());
2322 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact());
2324 return $array_contact;
2334 $array_contact = array();
2336 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact());
2338 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact());
2340 return $array_contact;
2355 public function listeContact($statusoflink = -1, $source =
'external', $list = 0, $code =
'', $status = -1)
2361 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
2362 if ($source ==
'internal') {
2363 $sql .=
", '-1' as socid, t.statut as statuscontact";
2366 if ($source ==
'external' || $source ==
'thirdparty') {
2367 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
2370 $sql .=
", t.civility, t.lastname as lastname, t.firstname, t.email";
2371 if ($source ==
'internal') {
2372 $sql .=
", t.office_phone as phone, t.user_mobile as phone_mobile";
2375 if ($source ==
'external') {
2376 $sql .=
", t.phone as phone, t.phone_mobile as phone_mobile, t.phone_perso as phone_perso";
2379 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_contact_label";
2380 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
2381 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact ec";
2382 if ($source ==
'internal') {
2383 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user t on ec.fk_socpeople = t.rowid";
2386 if ($source ==
'external' || $source ==
'thirdparty') {
2387 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople t on ec.fk_socpeople = t.rowid";
2390 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
2391 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
2392 $sql .=
" AND tc.element='".$this->db->escape($this->element).
"'";
2393 if ($source ==
'internal') {
2394 $sql .=
" AND tc.source = 'internal'";
2396 $sql .=
" AND t.statut = ".((int) $status);
2400 if ($source ==
'external' || $source ==
'thirdparty') {
2401 $sql .=
" AND tc.source = 'external'";
2403 $sql .=
" AND t.statut = ".((int) $status);
2407 if (!empty($code)) {
2408 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
2411 $sql .=
" AND tc.active=1";
2412 if ($statusoflink >= 0) {
2413 $sql .=
" AND ec.statut = ".((int) $statusoflink);
2416 $sql .=
" ORDER BY t.lastname ASC";
2418 $resql = $this->db->query($sql);
2420 $num = $this->db->num_rows($resql);
2423 $obj = $this->db->fetch_object($resql);
2426 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
2427 $labelType = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_contact_label);
2429 'source' => $obj->source,
2430 'socid' => (
int) $obj->socid,
2431 'id' => (
int) $obj->id,
2432 'nom' => $obj->lastname,
2433 'civility' => $obj->civility,
2434 'lastname' => $obj->lastname,
2435 'firstname' => $obj->firstname,
2436 'email' => $obj->email,
2437 'rowid' => (
int) $obj->rowid,
2438 'code' => $obj->code,
2439 'libelle' => $labelType,
2440 'labeltype' => $labelType,
2441 'status' => $obj->statuslink,
2442 'statuscontact' => (
int) $obj->statuscontact,
2443 'fk_c_type_contact' => (
int) $obj->fk_c_type_contact,
2444 'phone' => $obj->phone,
2445 'phone_mobile' => $obj->phone_mobile);
2446 if ($source ==
'external') {
2447 $tab[$i][
'phone_perso'] = $obj->phone_perso;
2450 $tab[$i] = $obj->id;
2458 $this->error = $this->db->error();
2481 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
2482 foreach ($dirmodels as $reldir) {
2483 $file =
dol_buildpath($reldir.
"core/modules/ticket/".$modele.
'.php', 0);
2484 if (file_exists($file)) {
2485 $classname = $modele;
2490 if ($classname !==
'') {
2492 $modTicket =
new $classname();
2493 '@phan-var-force ModeleNumRefTicket $modTicket';
2495 $defaultref = $modTicket->getNextValue($thirdparty, $this);
2498 if (is_numeric($defaultref) && $defaultref <= 0) {
2516 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2521 if (file_exists($dir_osencoded)) {
2522 $handle = opendir($dir_osencoded);
2523 if (is_resource($handle)) {
2524 while (($file = readdir($handle)) !==
false) {
2526 $file = mb_convert_encoding($file,
'UTF-8',
'ISO-8859-1');
2551 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2552 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2553 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2555 $maxwidthsmall = 270;
2556 $maxheightsmall = 150;
2557 $maxwidthmini = 128;
2558 $maxheightmini = 72;
2560 $formmail =
new FormMail($this->db);
2561 $formmail->trackid = (is_null($forcetrackid) ?
'tic'.$this->id :
'');
2562 $attachedfiles = $formmail->get_attached_files();
2564 $filepath = $attachedfiles[
'paths'];
2565 $filename = $attachedfiles[
'names'];
2566 $mimetype = $attachedfiles[
'mimes'];
2569 $destdir =
$conf->ticket->dir_output.
'/'.$this->ref;
2575 $listofpaths = array();
2576 $listofnames = array();
2577 foreach ($filename as $i => $val) {
2578 $destfile = $destdir.
'/'.$filename[$i];
2580 if (is_file($destfile)) {
2581 $pathinfo = pathinfo($filename[$i]);
2583 $destfile = $destdir.
'/'.$pathinfo[
'filename'].
' - '.
dol_print_date($now,
'dayhourlog').
'.'.$pathinfo[
'extension'];
2587 'description' =>
'File saved by copyFilesForTicket',
2588 'src_object_type' => $this->element,
2589 'src_object_id' => $this->
id,
2590 'gen_or_uploaded' =>
'uploaded'
2593 $res =
dol_move($filepath[$i], $destfile,
'0', 1, 0, 1, $moreinfo);
2597 $this->error =
"Failed to move file ".dirbasename($filepath[$i]).
" into ".
dirbasename($destfile);
2604 $imgThumbSmall =
vignette($destfile, $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
2607 $imgThumbMini =
vignette($destfile, $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
2612 $formmail->remove_attached_files($i);
2615 $listofpaths[$i] = $destfile;
2616 $listofnames[$i] = basename($destfile);
2619 return array(
'listofpaths' => $listofpaths,
'listofnames' => $listofnames,
'listofmimes' => $mimetype);
2635 if (!is_array($categories)) {
2636 $categories = array($categories);
2640 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2642 $existing =
$c->containing($this->
id, Categorie::TYPE_TICKET,
'id');
2645 if (is_array($existing)) {
2646 $to_del = array_diff($existing, $categories);
2647 $to_add = array_diff($categories, $existing);
2650 $to_add = $categories;
2654 foreach ($to_del as $del) {
2655 if (
$c->fetch($del) > 0) {
2656 $c->del_type($this, Categorie::TYPE_TICKET);
2659 foreach ($to_add as $add) {
2660 if (
$c->fetch($add) > 0) {
2661 $c->add_type($this, Categorie::TYPE_TICKET);
2680 public function newMessage($user, &$action, $private = 1, $public_area = 0)
2682 global $mysoc, $langs;
2696 array_push($this->errors, $langs->trans(
"ErrorTicketIsNotValid"));
2702 array_push($this->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Message")));
2703 $action =
'add_message';
2711 $send_email = (bool)
GETPOSTINT(
'send_email');
2714 $resarray =
$object->copyFilesForTicket();
2715 if (is_numeric($resarray) && $resarray == -1) {
2720 $listofpaths = $resarray[
'listofpaths'];
2721 $listofnames = $resarray[
'listofnames'];
2722 $listofmimes = $resarray[
'listofmimes'];
2727 $id =
$object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames, $send_email, $public_area);
2731 $this->error =
$object->error;
2732 $this->errors =
$object->errors;
2733 $action =
'add_message';
2736 if (!$error &&
$id > 0) {
2737 setEventMessages($langs->trans(
'TicketMessageSuccessfullyAdded'),
null,
'mesgs');
2740 if (!empty($public_area)) {
2748 $internal_contacts =
$object->getInfosTicketInternalContact(1);
2750 $assigned_user_dont_have_email =
'';
2754 if ($this->fk_user_assign > 0) {
2755 $assigned_user =
new User($this->db);
2756 $assigned_user->fetch($this->fk_user_assign);
2757 if (!empty($assigned_user->email)) {
2758 $sendto[$assigned_user->email] = $assigned_user->getFullName($langs).
" <".$assigned_user->email.
">";
2760 $assigned_user_dont_have_email = $assigned_user->getFullName($langs);
2763 $assigned_user =
null;
2767 foreach ($internal_contacts as $key => $info_sendto) {
2769 if ($info_sendto[
'id'] == $user->id) {
2774 if (!empty($info_sendto[
'email']) && ($assigned_user ===
null || $assigned_user->email != $info_sendto[
'email'])) {
2775 $sendto[] =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2779 if (empty($sendto)) {
2794 if (!empty($sendto)) {
2797 $subject =
'['.$appli.
'- ticket #'.
$object->track_id.
'] '.$this->subject;
2800 $message =
getDolGlobalString(
'TICKET_MESSAGE_MAIL_INTRO', $langs->trans(
'TicketMessageMailIntroText'));
2801 $message .=
'<br><br>';
2802 $messagePost =
GETPOST(
'message',
'restricthtml');
2806 $message .= $messagePost;
2809 $message .=
'<br><br>';
2810 $message .=
"==============================================";
2811 $message .= !empty(
$object->thirdparty->name) ?
'<br>'.$langs->trans(
'ThirdParty').
" : ".
$object->thirdparty->name :
'';
2812 $message .= !empty(
$object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".
$object->thirdparty->town :
'';
2813 $message .= !empty(
$object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".
$object->thirdparty->phone :
'';
2816 $message .=
'<br><br>';
2817 if (!empty($assigned_user_dont_have_email)) {
2818 $message .=
'<br>'.$langs->trans(
'NoEMail').
' : '.$assigned_user_dont_have_email;
2820 foreach ($sendto as $val) {
2821 $message .=
'<br>'.$langs->trans(
'TicketNotificationRecipient').
' : '.$val;
2826 $message .=
'<br><br>';
2827 $message .= $langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.
$object->track_id.
'</a>';
2834 $this->sendTicketMessageByEmail($subject, $message, 0, $sendto, $listofpaths, $listofmimes, $listofnames, array(), $from, $replyto);
2843 if ((
int) $send_email > 0) {
2845 $internal_contacts =
$object->getInfosTicketInternalContact(1);
2848 if (is_array($internal_contacts) && count($internal_contacts) > 0) {
2852 $subject =
GETPOST(
'subject',
'alphanohtml') ?
GETPOST(
'subject',
'alphanohtml') :
'['.$appli.
' - '.$langs->trans(
"Ticket").
' #'.
$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2854 $message_intro = $langs->trans(
'TicketNotificationEmailBody',
"#".
$object->id);
2857 $message =
getDolGlobalString(
'TICKET_MESSAGE_MAIL_INTRO', $langs->trans(
'TicketMessageMailIntroText'));
2858 $message .=
'<br><br>';
2859 $messagePost =
GETPOST(
'message',
'restricthtml');
2863 $message .= $messagePost;
2866 $message .=
'<br><br>';
2867 $message .=
"==============================================<br>";
2868 $message .= !empty(
$object->thirdparty->name) ? $langs->trans(
'ThirdParty').
" : ".
$object->thirdparty->name :
'';
2869 $message .= !empty(
$object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".
$object->thirdparty->town :
'';
2870 $message .= !empty(
$object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".
$object->thirdparty->phone :
'';
2873 foreach ($internal_contacts as $key => $info_sendto) {
2875 if ($info_sendto[
'id'] == $user->id) {
2876 dol_syslog(
"We cancel sending email to internal user ".$info_sendto[
'email'].
" because it is current user", LOG_DEBUG);
2880 if ($info_sendto[
'email'] !=
'') {
2881 $email = $info_sendto[
'email'];
2882 if ($email !=
null) {
2883 $sendto[$email] =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2887 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'], -1).
' ('.strtolower((
string) $info_sendto[
'libelle']).
')';
2888 $message .= (!empty($recipient) ?
'<br>'.$langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2896 $message .=
'<br>'.$langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.
$object->track_id.
'</a><br>';
2905 $sendtocc = array();
2915 if (!empty($sendto)) {
2916 $this->sendTicketMessageByEmail($subject, $message, 0, $sendto, $listofpaths, $listofmimes, $listofnames, $sendtocc, $from, $replyto);
2923 if (empty(
$object->private)) {
2925 $external_contacts =
$object->getInfosTicketExternalContact(1);
2928 if (is_array($external_contacts) && count($external_contacts) === 0) {
2929 if (!empty(
$object->fk_soc)) {
2931 $array_company = array(array(
'firstname' =>
'',
'lastname' =>
$object->thirdparty->name,
'email' =>
$object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' =>
$object->thirdparty->id));
2932 $external_contacts = array_merge($external_contacts, $array_company);
2933 } elseif (empty(
$object->fk_soc) && !empty(
$object->origin_replyto)) {
2934 $array_external = array(array(
'firstname' =>
'',
'lastname' =>
$object->origin_replyto,
'email' =>
$object->origin_replyto,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => 0));
2935 $external_contacts = array_merge($external_contacts, $array_external);
2936 } elseif (empty(
$object->fk_soc) && !empty(
$object->origin_email)) {
2937 $array_external = array(array(
'firstname' =>
'',
'lastname' =>
$object->origin_email,
'email' =>
$object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' =>
$object->thirdparty->id));
2938 $external_contacts = array_merge($external_contacts, $array_external);
2943 if (is_array($external_contacts) && count($external_contacts) > 0) {
2947 $subject =
GETPOST(
'subject') ?
GETPOST(
'subject') :
'['.$appli.
' - '.$langs->trans(
"Ticket").
' #'.
$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2952 $message_intro =
dol_nl2br($message_intro);
2955 $message_signature =
dol_nl2br($message_signature);
2959 $messagePost =
GETPOST(
'message',
'restricthtml');
2963 $message = $messagePost;
2964 $message .=
'<br><br>';
2966 foreach ($external_contacts as $key => $info_sendto) {
2968 if ($info_sendto[
'id'] == $user->contact_id) {
2972 if ($info_sendto[
'email'] !=
'' && $info_sendto[
'email'] !=
$object->origin_email) {
2973 $email = $info_sendto[
'email'];
2974 if ($email !=
null) {
2975 $sendto[$email] = trim($info_sendto[
'firstname'].
" ".$info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2978 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'], -1).
' ('.strtolower((
string) $info_sendto[
'libelle']).
')';
2979 $message .= (!empty($recipient) ?
'<br>'.$langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2984 $url_public_ticket = (
getDolGlobalInt(
'TICKET_ENABLE_PUBLIC_INTERFACE') ?
2987 if (
getDolGlobalInt(
'TICKET_INCLUDE_LINK_TO_PUBLIC_INTERFACE_IN_MESSAGE')) {
2988 $message .=
'<br>' . $langs->trans(
'TicketNewEmailBodyInfosTrackUrlCustomer') .
' : <a href="' . $url_public_ticket .
'">' .
$object->track_id .
'</a><br>';
2992 $message = $message_intro.
'<br><br>'.$message;
2995 $message .=
'<br>'.$message_signature;
2997 if (!empty(
$object->origin_replyto)) {
2999 } elseif (!empty(
$object->origin_email)) {
3003 if (
$object->fk_soc > 0 && !array_key_exists(
$object->origin_replyto, $sendto) && !array_key_exists(
$object->origin_email, $sendto)) {
3006 if (!empty(
$object->thirdparty->email)) {
3007 $sendto[
$object->thirdparty->email] =
$object->thirdparty->email;
3018 $sendtocc = array();
3024 if (!empty($sendto)) {
3029 $result = $this->sendTicketMessageByEmail($subject, $message, 0, $sendto, $listofpaths, $listofmimes, $listofnames, $sendtocc, $from, $replyto);
3032 $this->date_last_msg_sent =
dol_now();
3033 $this->update($user, 1);
3037 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"actioncomm";
3038 $sql .=
" SET email_msgid = '".$this->db->escape($this->email_msgid).
"',";
3039 $sql .=
" email_subject = '".$this->db->escape($subject).
"',";
3040 $sql .=
" email_from = '".$this->db->escape($from).
"',";
3041 $sql .=
" email_to = '".$this->db->escape(implode(
',', $sendto)).
"',";
3042 $sql .=
" email_tocc = '".$this->db->escape(implode(
',', $sendtocc)).
"',";
3043 $sql .=
" reply_to = '".$this->db->escape($replyto).
"'";
3044 $sql .=
" WHERE id = ".((int)
$id);
3046 $resql = $this->db->query($sql);
3059 && (
$object->status < self::STATUS_IN_PROGRESS && !$user->socid && !$private))
3060 || (
$object->status > self::STATUS_IN_PROGRESS && $public_area)) {
3062 $object->setStatut($object::STATUS_IN_PROGRESS,
null,
'',
'TICKET_MODIFY');
3063 } elseif (
getDolGlobalInt(
'TICKET_SET_STATUS_ON_ANSWER', -1) >= 0 && empty($user->socid) && empty($private)) {
3095 public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $array_receiver_cc = array(), $from =
'', $replyto =
'')
3097 global
$conf, $langs, $user;
3100 dol_syslog(get_class($this).
'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING);
3104 $langs->load(
"mails");
3106 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
3110 if (!is_array($array_receiver) || !count($array_receiver) > 0) {
3111 $array_receiver = $this->getInfosTicketInternalContact(1);
3112 $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact(1));
3115 dol_syslog(
"sendTicketMessageByEmail array_receiver=".json_encode($array_receiver), LOG_DEBUG);
3116 dol_syslog(
"sendTicketMessageByEmail array_receiver_cc=".json_encode($array_receiver_cc), LOG_DEBUG);
3119 if ($send_internal_cc) {
3122 if (!empty($array_receiver_cc) && is_array($array_receiver_cc)) {
3123 $sendtocc .= ($sendtocc ?
',' :
'').implode(
',', $array_receiver_cc);
3131 $this->email_msgids = array();
3133 if (is_array($array_receiver) && count($array_receiver) > 0) {
3135 $deliveryreceipt = 0;
3136 $filepath = $filename_list;
3137 $filename = $mimefilename_list;
3138 $mimetype = $mimetype_list;
3144 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
3147 $upload_dir_tmp =
$conf->user->dir_output.
"/".$user->id.
'/temp';
3149 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
3150 $trackid =
"tic".$this->id;
3152 $moreinheader =
'X-Dolibarr-Info: sendTicketMessageByEmail'.
"\r\n";
3153 if (!empty($this->email_msgid)) {
3155 $moreinheader .=
'In-Reply-To: <'.$this->email_msgid.
'>'.
"\r\n";
3163 if (!empty($this->origin_references)) {
3164 $references .= (empty($references) ?
'' :
' ').$this->origin_references;
3166 if (!empty($this->email_msgid) && !preg_match(
'/'.preg_quote($this->email_msgid,
'/').
'/', $references)) {
3167 $references .= (empty($references) ?
'' :
' ').
'<'.$this->email_msgid.
'>';
3170 $moreinheader .=
'References: '.$references.
"\r\n";
3174 $receiverstring =
'';
3175 foreach ($array_receiver as $key => $receiver) {
3176 $receiverstring .= ($receiverstring ?
',' :
'').$receiver;
3179 $sendcontext =
'ticket';
3182 $mailfile =
new CMailFile($subject, $receiverstring, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'', $trackid, $moreinheader, $sendcontext, $replyto, $upload_dir_tmp);
3185 if ($mailfile->error) {
3188 $result = $mailfile->sendfile();
3191 setEventMessages($langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiverstring, 2)),
null,
'mesgs');
3194 $this->email_msgid = $mailfile->msgid;
3196 $langs->load(
"other");
3197 if ($mailfile->error) {
3198 setEventMessages($langs->trans(
'ErrorFailedToSendMail', $from, $receiver),
null,
'errors');
3199 dol_syslog($langs->trans(
'ErrorFailedToSendMail', $from, $receiver).
' : '.$mailfile->error);
3201 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'errors');
3203 setEventMessages($langs->trans(
'ErrorFailedToSendMail', $from, $receiverstring),
null,
'errors');
3204 dol_syslog(
'ErrorFailedToSendMail (no error details) from='.$from.
' to='.$receiverstring, LOG_WARNING);
3210 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
3214 $langs->load(
"other");
3215 setEventMessages($langs->trans(
'ErrorMailRecipientIsEmptyForSendTicketMessage'),
null,
'warnings');
3232 global $user, $langs;
3239 $sql =
"SELECT p.rowid, p.ref, p.datec as datec";
3240 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
3241 if (empty($user->socid) && isModEnabled(
'societe') && !$user->hasRight(
'societe',
'client',
'voir') && !$user->socid) {
3242 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
3243 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3246 $sql .= $clause.
" p.entity IN (".
getEntity(
'ticket').
")";
3247 if ($mode ==
'opened') {
3248 $sql .=
" AND p.fk_statut NOT IN (".Ticket::STATUS_CLOSED.
", ".Ticket::STATUS_CANCELED.
")";
3251 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
3254 $resql = $this->db->query($sql);
3256 $label = $labelShort =
'';
3258 if ($mode ==
'opened') {
3259 $status =
'openall';
3262 $label = $langs->trans(
"MenuListNonClosed");
3263 $labelShort = $langs->trans(
"MenuListNonClosed");
3268 $response->label = $label;
3269 $response->labelShort = $labelShort;
3270 $response->url = DOL_URL_ROOT.
'/ticket/list.php?search_fk_statut[]='.$status;
3274 while ($obj = $this->db->fetch_object($resql)) {
3275 $response->nbtodo++;
3276 if ($mode ==
'opened') {
3277 $datelimit = (int) $this->db->jdate($obj->datec) + (int) $delay_warning;
3278 if ($datelimit < $now) {
3285 $this->error = $this->db->lasterror();
3299 $this->nb = array();
3302 $sql =
"SELECT count(p.rowid) as nb";
3303 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
3304 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
3305 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3306 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3307 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3310 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'ticket').
")";
3312 $resql = $this->db->query($sql);
3315 while ($obj = $this->db->fetch_object($resql)) {
3316 $this->nb[
"ticket"] = $obj->nb;
3318 $this->db->free($resql);
3322 $this->error = $this->db->lasterror();
3337 $tables = array(
'ticket');
3353 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3355 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3356 $return .=
'<div class="info-box info-box-sm">';
3357 $return .=
'<span class="info-box-icon bg-infobox-action">';
3359 $return .=
'</span>';
3360 $return .=
'<div class="info-box-content">';
3361 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->getNomUrl(1) : $this->ref).
'</span>';
3362 if ($selected >= 0) {
3363 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3365 if (!empty($arraydata[
'user_assignment'])) {
3366 $return .=
'<br><span class="info-box-label" title="'.dol_escape_htmltag($langs->trans(
"AssignedTo")).
'">'.$arraydata[
'user_assignment'].
'</span>';
3368 if (property_exists($this,
'type_code') && !empty($this->type_code)) {
3370 $return .=
'<div class="tdoverflowmax125 inline-block">'.$langs->getLabelFromKey($this->db,
'TicketTypeShort'.$this->type_code,
'c_ticket_type',
'code',
'label', $this->type_code).
'</div>';
3372 if (method_exists($this,
'getLibStatut')) {
3373 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3375 $return .=
'</div>';
3376 $return .=
'</div>';
3377 $return .=
'</div>';
3393 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3397 $langs->load(
"ticket");
3398 $outputlangs->load(
"ticket");
3401 $modele =
'generic_ticket_odt';
3403 if (!empty($this->model_pdf)) {
3404 $modele = $this->model_pdf;
3410 $modelpath =
"core/modules/ticket/doc/";
3412 return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Class to manage agenda events (actions)
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...
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.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Class to manage Dolibarr database access.
Class to manage ECM files.
Class to manage third parties objects (customers, suppliers, prospects...)
fetch($id=0, $ref='', $track_id='', $email_msgid='')
Load object in memory from the database.
fetchAll($user, $sortorder='ASC', $sortfield='t.datec', $limit=0, $offset=0, $arch=0, $filter='')
Load all objects in memory from database.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
listeContact($statusoflink=-1, $source='external', $list=0, $code='', $status=-1)
Get array of all contacts for a ticket Override method of file commonobject.class....
loadCacheMsgsTicket()
Load the list of event on ticket into ->cache_msgs_ticket.
sendTicketMessageByEmail($subject, $message, $send_internal_cc=0, $array_receiver=array(), $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $array_receiver_cc=array(), $from='', $replyto='')
Send ticket by email to linked contacts.
setProgression($percent)
Define progression of current ticket.
searchSocidByEmail($email, $type=0, $filters=array(), $clause='AND')
Search and fetch thirparties by email.
loadCacheSeveritiesTickets()
Charge dans cache la liste des sévérité de tickets (paramétrable dans dictionnaire)
$fields
'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]',...
getInfosTicketExternalContact($status=-1)
Retrieve information about external contacts.
searchContactByEmail($email, $socid=0, $case='')
Search and fetch contacts by email.
getIdTicketCustomerInvolvedContact()
Return id des contacts clients des intervenants.
LibStatut($status, $mode=0, $notooltip=0, $progress=0)
Return status label of object.
setContract($contractid)
Link element with a contract.
getTicketAllContacts()
Return id of all contacts for ticket.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
assignUser($user, $id_assign_user, $notrigger=0)
Set an assigned user to a ticket.
loadStateBoard()
Load indicator this->nb of global stats widget.
getTooltipContentArray($params)
getTooltipContentArray
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
printSelectStatus($selected="")
Print selected status.
is_photo_available($sdir)
Return if at least one photo is available.
getIdTicketInternalContact()
Return id des contacts interne de suivi.
update($user, $notrigger=0)
Update object into database.
loadCacheCategoriesTickets($publicgroup=-1)
Load into a cache array, the list of ticket categories (setup done into dictionary)
setCustomer($id)
Define parent commany of current ticket.
markAsRead($user, $notrigger=0)
Mark a message as read.
getDefaultRef($thirdparty=null)
Get a default reference.
const STATUS_NOT_READ
Status.
getTicketAllCustomerContacts()
Return id of all contacts for ticket.
createTicketMessage($user, $notrigger=0, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $send_email=false, $public_area=0)
Add message into database.
verify()
Check properties of ticket are ok (like ref, track_id, ...).
setCategories($categories)
Sets object to supplied categories.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
newMessage($user, &$action, $private=1, $public_area=0)
Add new message on a ticket (private/public area).
getIdTicketCustomerContact()
Return id des contacts clients pour le suivi ticket.
checkExistingRef(string $action, string $getRef)
Check if ref exists or not.
__construct(DoliDB $db)
Constructor.
loadCacheTypesTickets()
Load into a cache the types of tickets (setup done into dictionaries)
getLibStatut($mode=0)
Return status label of object.
close(User $user, $mode=0)
Close a ticket.
getIdTicketInternalInvolvedContact()
Return id des contacts clients des intervenants.
copyFilesForTicket($forcetrackid=null)
Copy files defined into $_SESSION array into the ticket directory of attached files.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionally the picto)
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
getInfosTicketInternalContact($status=-1)
Retrieve information about internal contacts.
create($user, $notrigger=0)
Create object into database.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dirbasename($pathfile)
Return the relative dirname (relative to DOL_DATA_ROOT) of a full path string.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=0)
Move a file into another name.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
isDolTms($timestamp)
isDolTms check if a timestamp is valid.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_textishtml($msg, $option=0)
Return if a text is a html content.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
utf8_check($str)
Check if a string is in UTF8.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
vignette($file, $maxWidth=160, $maxHeight=120, $extName='_small', $quality=50, $outdir='thumbs', $targetformat=0)
Create a thumbnail from an image file (Supported extensions are gif, jpg, png and bmp).
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Class to generate the form for creating a new ticket.
generate_random_id($car=16)
Generate a random id.