28 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobject.class.php";
29 require_once DOL_DOCUMENT_ROOT.
'/fichinter/class/fichinter.class.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ticket.lib.php';
41 public $element =
'ticket';
46 public $table_element =
'ticket';
51 public $fk_element =
'fk_ticket';
56 public $ismultientitymanaged = 1;
61 public $isextrafieldmanaged = 1;
66 public $picto =
'ticket';
92 public $fk_user_create;
97 public $fk_user_assign;
144 public $category_code;
149 public $severity_code;
179 public $date_read =
'';
184 public $date_last_msg_sent =
'';
189 public $date_close =
'';
194 public $cache_types_tickets;
199 public $cache_category_tickets;
204 public $notify_tiers_at_create;
230 public $regeximgext =
'\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.webp|\.xpm|\.xbm';
236 const STATUS_READ = 1;
237 const STATUS_ASSIGNED = 2;
238 const STATUS_IN_PROGRESS = 3;
239 const STATUS_NEED_MORE_INFO = 5;
240 const STATUS_WAITING = 7;
241 const STATUS_CLOSED = 8;
242 const STATUS_CANCELED = 9;
273 'rowid' => array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'visible'=>-2,
'enabled'=>1,
'position'=>1,
'notnull'=>1,
'index'=>1,
'comment'=>
"Id"),
274 'entity' => array(
'type'=>
'integer',
'label'=>
'Entity',
'visible'=>0,
'enabled'=>1,
'position'=>5,
'notnull'=>1,
'index'=>1),
275 '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),
276 'track_id' => array(
'type'=>
'varchar(255)',
'label'=>
'TicketTrackId',
'visible'=>-2,
'enabled'=>1,
'position'=>11,
'notnull'=>-1,
'searchall'=>1,
'help'=>
"Help text"),
277 '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'),
278 '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'),
279 'subject' => array(
'type'=>
'varchar(255)',
'label'=>
'Subject',
'visible'=>1,
'enabled'=>1,
'position'=>18,
'notnull'=>-1,
'searchall'=>1,
'help'=>
"",
'css'=>
'maxwidth200 tdoverflowmax200',
'autofocusoncreate'=>1),
280 'type_code' => array(
'type'=>
'varchar(32)',
'label'=>
'Type',
'visible'=>1,
'enabled'=>1,
'position'=>20,
'notnull'=>-1,
'help'=>
"",
'csslist'=>
'maxwidth125 tdoverflowmax50'),
281 'category_code' => array(
'type'=>
'varchar(32)',
'label'=>
'TicketCategory',
'visible'=>-1,
'enabled'=>1,
'position'=>21,
'notnull'=>-1,
'help'=>
"",
'css'=>
'maxwidth100 tdoverflowmax200'),
282 'severity_code' => array(
'type'=>
'varchar(32)',
'label'=>
'Severity',
'visible'=>1,
'enabled'=>1,
'position'=>22,
'notnull'=>-1,
'help'=>
"",
'css'=>
'maxwidth100'),
283 'fk_soc' => array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'visible'=>1,
'enabled'=>
'$conf->societe->enabled',
'position'=>50,
'notnull'=>-1,
'index'=>1,
'searchall'=>1,
'help'=>
"OrganizationEventLinkToThirdParty",
'css'=>
'tdoverflowmax150 maxwidth150onsmartphone'),
284 'notify_tiers_at_create' => array(
'type'=>
'integer',
'label'=>
'NotifyThirdparty',
'visible'=>-1,
'enabled'=>0,
'position'=>51,
'notnull'=>1,
'index'=>1),
285 '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"),
287 'datec' => array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'visible'=>1,
'enabled'=>1,
'position'=>500,
'notnull'=>1,
'csslist'=>
'nowraponall'),
288 'date_read' => array(
'type'=>
'datetime',
'label'=>
'TicketReadOn',
'visible'=>-1,
'enabled'=>1,
'position'=>501,
'notnull'=>1),
289 'date_last_msg_sent' => array(
'type'=>
'datetime',
'label'=>
'TicketLastMessageDate',
'visible'=>0,
'enabled'=>1,
'position'=>502,
'notnull'=>-1),
290 'fk_user_assign' => array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'AssignedTo',
'visible'=>1,
'enabled'=>1,
'position'=>505,
'notnull'=>1,
'csslist'=>
'tdoverflowmax100 maxwidth150onsmartphone'),
291 'date_close' => array(
'type'=>
'datetime',
'label'=>
'TicketCloseOn',
'visible'=>-1,
'enabled'=>1,
'position'=>510,
'notnull'=>1),
292 'tms' => array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'visible'=>-1,
'enabled'=>1,
'position'=>520,
'notnull'=>1),
293 'message' => array(
'type'=>
'text',
'label'=>
'Message',
'visible'=>-2,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,),
294 'email_msgid' => array(
'type'=>
'varchar(255)',
'label'=>
'EmailMsgID',
'visible'=>-2,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,
'help'=>
'EmailMsgIDDesc',
'csslist'=>
'tdoverflowmax100'),
295 'email_date' => array(
'type'=>
'datetime',
'label'=>
'EmailDate',
'visible'=>-2,
'enabled'=>1,
'position'=>541),
296 'progress' => array(
'type'=>
'integer',
'label'=>
'Progression',
'visible'=>-1,
'enabled'=>1,
'position'=>540,
'notnull'=>-1,
'css'=>
'right',
'help'=>
"",
'isameasure'=>2,
'csslist'=>
'width50'),
297 'resolution' => array(
'type'=>
'integer',
'label'=>
'Resolution',
'visible'=>-1,
'enabled'=>
'$conf->global->TICKET_ENABLE_RESOLUTION',
'position'=>550,
'notnull'=>1),
298 'fk_statut' => array(
'type'=>
'integer',
'label'=>
'Status',
'visible'=>1,
'enabled'=>1,
'position'=>600,
'notnull'=>1,
'index'=>1,
'arrayofkeyval'=>array(0 =>
'Unread', 1 =>
'Read', 3 =>
'Answered', 4 =>
'Assigned', 5 =>
'InProgress', 6 =>
'Waiting', 8 =>
'SolvedClosed', 9 =>
'Deleted')),
299 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>900),
315 $this->statuts_short = array(
316 self::STATUS_NOT_READ =>
'Unread',
317 self::STATUS_READ =>
'Read',
318 self::STATUS_ASSIGNED =>
'Assigned',
319 self::STATUS_IN_PROGRESS =>
'InProgress',
320 self::STATUS_WAITING =>
'OnHold',
321 self::STATUS_NEED_MORE_INFO =>
'NeedMoreInformationShort',
322 self::STATUS_CLOSED =>
'SolvedClosed',
323 self::STATUS_CANCELED =>
'Canceled'
325 $this->statuts = array(
326 self::STATUS_NOT_READ =>
'Unread',
327 self::STATUS_READ =>
'Read',
328 self::STATUS_ASSIGNED =>
'Assigned',
329 self::STATUS_IN_PROGRESS =>
'InProgress',
330 self::STATUS_WAITING =>
'OnHold',
331 self::STATUS_NEED_MORE_INFO =>
'NeedMoreInformation',
332 self::STATUS_CLOSED =>
'SolvedClosed',
333 self::STATUS_CANCELED =>
'Canceled'
345 $this->errors = array();
350 if (isset($this->
ref)) {
351 $this->
ref = trim($this->
ref);
354 if (isset($this->track_id)) {
355 $this->track_id = trim($this->track_id);
358 if (isset($this->fk_soc)) {
359 $this->fk_soc = (int) $this->fk_soc;
362 if (isset($this->fk_project)) {
363 $this->fk_project = (int) $this->fk_project;
366 if (isset($this->origin_email)) {
367 $this->origin_email = trim($this->origin_email);
370 if (isset($this->fk_user_create)) {
371 $this->fk_user_create = (int) $this->fk_user_create;
374 if (isset($this->fk_user_assign)) {
375 $this->fk_user_assign = (int) $this->fk_user_assign;
378 if (isset($this->subject)) {
379 $this->subject = trim($this->subject);
382 if (isset($this->message)) {
383 $this->message = trim($this->message);
385 $this->errors[] =
'ErrorFieldTooLong';
386 dol_syslog(get_class($this).
'::create error -1 message too long', LOG_ERR);
391 if (isset($this->fk_statut)) {
392 $this->fk_statut = (int) $this->fk_statut;
395 if (isset($this->resolution)) {
396 $this->resolution = trim($this->resolution);
399 if (isset($this->progress)) {
400 $this->progress = trim($this->progress);
403 if (isset($this->timing)) {
404 $this->timing = trim($this->timing);
407 if (isset($this->type_code)) {
408 $this->type_code = trim($this->type_code);
411 if (isset($this->category_code)) {
412 $this->category_code = trim($this->category_code);
415 if (isset($this->severity_code)) {
416 $this->severity_code = trim($this->severity_code);
419 if (empty($this->
ref)) {
420 $this->errors[] =
'ErrorTicketRefRequired';
421 dol_syslog(get_class($this).
"::create error -1 ref null", LOG_ERR);
435 public function create($user, $notrigger = 0)
437 global $conf, $langs;
442 if (empty($this->track_id)) {
448 $result = $this->
verify();
452 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"ticket(";
456 $sql .=
"fk_project,";
457 $sql .=
"origin_email,";
458 $sql .=
"fk_user_create,";
459 $sql .=
"fk_user_assign,";
460 $sql .=
"email_msgid,";
461 $sql .=
"email_date,";
464 $sql .=
"fk_statut,";
465 $sql .=
"resolution,";
468 $sql .=
"type_code,";
469 $sql .=
"category_code,";
470 $sql .=
"severity_code,";
472 $sql .=
"date_read,";
473 $sql .=
"date_close,";
475 $sql .=
"notify_tiers_at_create,";
477 $sql .=
") VALUES (";
478 $sql .=
" ".(!isset($this->
ref) ?
'' :
"'".$this->db->escape($this->
ref).
"'").
",";
479 $sql .=
" ".(!isset($this->track_id) ?
'NULL' :
"'".$this->db->escape($this->track_id).
"'").
",";
480 $sql .=
" ".($this->fk_soc > 0 ? $this->
db->escape($this->fk_soc) :
"null").
",";
481 $sql .=
" ".($this->fk_project > 0 ? $this->
db->escape($this->fk_project) :
"null").
",";
482 $sql .=
" ".(!isset($this->origin_email) ?
'NULL' :
"'".$this->db->escape($this->origin_email).
"'").
",";
483 $sql .=
" ".($this->fk_user_create > 0 ? $this->fk_user_create : ($user->id > 0 ? $user->id :
'NULL')).
",";
484 $sql .=
" ".($this->fk_user_assign > 0 ? $this->fk_user_assign :
'NULL').
",";
485 $sql .=
" ".(empty($this->email_msgid) ?
'NULL' :
"'".$this->db->escape($this->email_msgid).
"'").
",";
486 $sql .=
" ".(empty($this->email_date) ?
'NULL' :
"'".$this->db->idate($this->email_date).
"'").
",";
487 $sql .=
" ".(!isset($this->subject) ?
'NULL' :
"'".$this->db->escape($this->subject).
"'").
",";
488 $sql .=
" ".(!isset($this->message) ?
'NULL' :
"'".$this->db->escape($this->message).
"'").
",";
489 $sql .=
" ".(!isset($this->fk_statut) ?
'0' :
"'".$this->db->escape($this->fk_statut).
"'").
",";
490 $sql .=
" ".(!isset($this->resolution) ?
'NULL' :
"'".$this->db->escape($this->resolution).
"'").
",";
491 $sql .=
" ".(!isset($this->progress) ?
'0' :
"'".$this->db->escape($this->progress).
"'").
",";
492 $sql .=
" ".(!isset($this->timing) ?
'NULL' :
"'".$this->db->escape($this->timing).
"'").
",";
493 $sql .=
" ".(!isset($this->type_code) ?
'NULL' :
"'".$this->db->escape($this->type_code).
"'").
",";
494 $sql .=
" ".(empty($this->category_code) || $this->category_code ==
'-1' ?
'NULL' :
"'".$this->db->escape($this->category_code).
"'").
",";
495 $sql .=
" ".(!isset($this->severity_code) ?
'NULL' :
"'".$this->db->escape($this->severity_code).
"'").
",";
496 $sql .=
" ".(!isset($this->datec) ||
dol_strlen($this->datec) == 0 ?
'NULL' :
"'".$this->db->idate($this->datec).
"'").
",";
497 $sql .=
" ".(!isset($this->date_read) ||
dol_strlen($this->date_read) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_read).
"'").
",";
498 $sql .=
" ".(!isset($this->date_close) ||
dol_strlen($this->date_close) == 0 ?
'NULL' :
"'".$this->db->idate($this->date_close).
"'");
499 $sql .=
", ".((int) $conf->entity);
500 $sql .=
", ".(!isset($this->notify_tiers_at_create) ?
'1' :
"'".$this->db->escape($this->notify_tiers_at_create).
"'");
501 $sql .=
", ".(!isset($this->ip) ?
'NULL' :
"'".$this->db->escape($this->ip).
"'");
506 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
510 $this->errors[] =
"Error ".$this->db->lasterror();
514 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"ticket");
517 if (!$error && !empty($conf->global->TICKET_ADD_AUTHOR_AS_CONTACT)) {
519 if ($this->
add_contact($user->id,
'CONTRIBUTOR',
'internal') < 0) {
524 if (!$error && $this->fk_user_assign > 0) {
525 if ($this->
add_contact($this->fk_user_assign,
'SUPPORTTEC',
'internal') < 0) {
539 if (!$error && !$notrigger) {
550 foreach ($this->errors as $errmsg) {
551 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
552 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
554 $this->
db->rollback();
561 $this->
db->rollback();
562 dol_syslog(get_class($this).
"::Create fails verify ".join(
',', $this->errors), LOG_WARNING);
576 public function fetch($id =
'', $ref =
'', $track_id =
'', $email_msgid =
'')
581 if (empty($id) && empty($ref) && empty($track_id) && empty($email_msgid)) {
582 $this->error =
'ErrorWrongParameters';
589 $sql .=
" t.entity,";
591 $sql .=
" t.track_id,";
592 $sql .=
" t.fk_soc,";
593 $sql .=
" t.fk_project,";
594 $sql .=
" t.origin_email,";
595 $sql .=
" t.fk_user_create,";
596 $sql .=
" t.fk_user_assign,";
597 $sql .=
" t.email_msgid,";
598 $sql .=
" t.email_date,";
599 $sql .=
" t.subject,";
600 $sql .=
" t.message,";
601 $sql .=
" t.fk_statut as status,";
602 $sql .=
" t.resolution,";
603 $sql .=
" t.progress,";
604 $sql .=
" t.timing,";
605 $sql .=
" t.type_code,";
606 $sql .=
" t.category_code,";
607 $sql .=
" t.severity_code,";
609 $sql .=
" t.date_read,";
610 $sql .=
" t.date_last_msg_sent,";
611 $sql .=
" t.date_close,";
613 $sql .=
" type.label as type_label, category.label as category_label, severity.label as severity_label";
614 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
615 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
616 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
617 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
620 $sql .=
" WHERE t.rowid = ".((int) $id);
622 $sql .=
" WHERE t.entity IN (".getEntity($this->element, 1).
")";
624 $sql .=
" AND t.ref = '".$this->db->escape($ref).
"'";
625 } elseif ($track_id) {
626 $sql .=
" AND t.track_id = '".$this->db->escape($track_id).
"'";
628 $sql .=
" AND t.email_msgid = '".$this->db->escape($email_msgid).
"'";
632 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
636 $obj = $this->
db->fetch_object(
$resql);
638 $this->
id = $obj->rowid;
639 $this->entity = $obj->entity;
640 $this->
ref = $obj->ref;
641 $this->track_id = $obj->track_id;
642 $this->fk_soc = $obj->fk_soc;
643 $this->socid = $obj->fk_soc;
644 $this->fk_project = $obj->fk_project;
645 $this->origin_email = $obj->origin_email;
646 $this->fk_user_create = $obj->fk_user_create;
647 $this->fk_user_assign = $obj->fk_user_assign;
648 $this->email_msgid = $obj->email_msgid;
649 $this->email_date = $this->
db->jdate($obj->email_date);
650 $this->subject = $obj->subject;
651 $this->message = $obj->message;
653 $this->status = $obj->status;
654 $this->fk_statut = $this->status;
656 $this->resolution = $obj->resolution;
657 $this->progress = $obj->progress;
658 $this->timing = $obj->timing;
660 $this->type_code = $obj->type_code;
662 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) != (
"TicketTypeShort".$obj->type_code) ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
663 $this->type_label = $label_type;
665 $this->category_code = $obj->category_code;
667 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) != (
"TicketCategoryShort".$obj->category_code) ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
668 $this->category_label = $label_category;
670 $this->severity_code = $obj->severity_code;
672 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) != (
"TicketSeverityShort".$obj->severity_code) ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
673 $this->severity_label = $label_severity;
675 $this->datec = $this->
db->jdate($obj->datec);
676 $this->date_creation = $this->
db->jdate($obj->datec);
677 $this->date_read = $this->
db->jdate($obj->date_read);
678 $this->date_validation = $this->
db->jdate($obj->date_read);
679 $this->date_last_msg_sent = $this->
db->jdate($obj->date_last_msg_sent);
680 $this->date_close = $this->
db->jdate($obj->date_close);
681 $this->tms = $this->
db->jdate($obj->tms);
682 $this->date_modification = $this->
db->jdate($obj->tms);
692 $this->error =
"Error ".$this->db->lasterror();
693 dol_syslog(get_class($this).
"::fetch ".$this->error, LOG_ERR);
711 public function fetchAll($user, $sortorder =
'ASC', $sortfield =
't.datec', $limit =
'', $offset = 0, $arch =
'', $filter =
'')
718 $extrafields->fetch_name_optionals_label($this->table_element);
723 $sql .=
" t.track_id,";
724 $sql .=
" t.fk_soc,";
725 $sql .=
" t.fk_project,";
726 $sql .=
" t.origin_email,";
727 $sql .=
" t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
728 $sql .=
" t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
729 $sql .=
" t.subject,";
730 $sql .=
" t.message,";
731 $sql .=
" t.fk_statut,";
732 $sql .=
" t.resolution,";
733 $sql .=
" t.progress,";
734 $sql .=
" t.timing,";
735 $sql .=
" t.type_code,";
736 $sql .=
" t.category_code,";
737 $sql .=
" t.severity_code,";
739 $sql .=
" t.date_read,";
740 $sql .=
" t.date_last_msg_sent,";
741 $sql .=
" t.date_close,";
743 $sql .=
", type.label as type_label, category.label as category_label, severity.label as severity_label";
745 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
746 $sql .= ($extrafields->attributes[$this->table_element][
'type'][$key] !=
'separate' ?
",ef.".$key.
" as options_".$key :
'');
748 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as t";
749 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_type as type ON type.code=t.type_code";
750 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_category as category ON category.code=t.category_code";
751 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_ticket_severity as severity ON severity.code=t.severity_code";
752 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON s.rowid=t.fk_soc";
753 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as uc ON uc.rowid=t.fk_user_create";
754 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user as ua ON ua.rowid=t.fk_user_assign";
755 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
756 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"ticket_extrafields as ef on (t.rowid = ef.fk_object)";
758 if (empty($user->rights->societe->client->voir) && !$user->socid) {
759 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
762 $sql .=
" WHERE t.entity IN (".getEntity(
'ticket').
")";
765 if (!empty($filter)) {
766 foreach ($filter as $key => $value) {
767 if (strpos($key,
'date')) {
768 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
769 } elseif (($key ==
't.fk_user_assign') || ($key ==
't.type_code') || ($key ==
't.category_code') || ($key ==
't.severity_code') || ($key ==
't.fk_soc')) {
770 $sql .=
" AND ".$key.
" = '".$this->
db->escape($value).
"'";
771 } elseif ($key ==
't.fk_statut') {
772 if (is_array($value) && count($value) > 0) {
773 $sql .=
" AND ".$key.
" IN (".$this->
db->sanitize(implode(
',', $value)).
")";
775 $sql .=
" AND ".$key.
' = '.((int) $value);
778 $sql .=
" AND ".$key.
" LIKE '%".$this->
db->escape($value).
"%'";
782 if (empty($user->rights->societe->client->voir) && !$user->socid) {
783 $sql .=
" AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
784 } elseif ($user->socid) {
785 $sql .=
" AND t.fk_soc = ".((int) $user->socid);
788 $sql .= $this->
db->order($sortfield, $sortorder);
789 if (!empty($limit)) {
790 $sql .= $this->
db->plimit($limit + 1, $offset);
793 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
797 $this->lines = array();
804 $obj = $this->
db->fetch_object(
$resql);
808 $line->id = $obj->rowid;
809 $line->rowid = $obj->rowid;
810 $line->ref = $obj->ref;
811 $line->track_id = $obj->track_id;
812 $line->fk_soc = $obj->fk_soc;
813 $line->fk_project = $obj->fk_project;
814 $line->origin_email = $obj->origin_email;
816 $line->fk_user_create = $obj->fk_user_create;
817 $line->user_create_lastname = $obj->user_create_lastname;
818 $line->user_create_firstname = $obj->user_create_firstname;
820 $line->fk_user_assign = $obj->fk_user_assign;
821 $line->user_assign_lastname = $obj->user_assign_lastname;
822 $line->user_assign_firstname = $obj->user_assign_firstname;
824 $line->subject = $obj->subject;
825 $line->message = $obj->message;
826 $line->fk_statut = $obj->fk_statut;
827 $line->resolution = $obj->resolution;
828 $line->progress = $obj->progress;
829 $line->timing = $obj->timing;
832 $label_type = ($langs->trans(
"TicketTypeShort".$obj->type_code) != (
"TicketTypeShort".$obj->type_code) ? $langs->trans(
"TicketTypeShort".$obj->type_code) : ($obj->type_label !=
'-' ? $obj->type_label :
''));
833 $line->type_label = $label_type;
835 $this->category_code = $obj->category_code;
837 $label_category = ($langs->trans(
"TicketCategoryShort".$obj->category_code) != (
"TicketCategoryShort".$obj->category_code) ? $langs->trans(
"TicketCategoryShort".$obj->category_code) : ($obj->category_label !=
'-' ? $obj->category_label :
''));
838 $line->category_label = $label_category;
840 $this->severity_code = $obj->severity_code;
842 $label_severity = ($langs->trans(
"TicketSeverityShort".$obj->severity_code) != (
"TicketSeverityShort".$obj->severity_code) ? $langs->trans(
"TicketSeverityShort".$obj->severity_code) : ($obj->severity_label !=
'-' ? $obj->severity_label :
''));
843 $line->severity_label = $label_severity;
845 $line->datec = $this->
db->jdate($obj->datec);
846 $line->date_read = $this->
db->jdate($obj->date_read);
847 $line->date_last_msg_sent = $this->
db->jdate($obj->date_last_msg_sent);
848 $line->date_close = $this->
db->jdate($obj->date_close);
851 if (is_array($extrafields->attributes[$this->table_element][
'label']) && count($extrafields->attributes[$this->table_element][
'label'])) {
852 foreach ($extrafields->attributes[$this->table_element][
'label'] as $key => $val) {
853 $tmpkey =
'options_'.$key;
854 $line->{$tmpkey} = $obj->$tmpkey;
858 $this->lines[$i] = $line;
865 $this->error =
"Error ".$this->db->lasterror();
866 dol_syslog(get_class($this).
"::fetchAll ".$this->error, LOG_ERR);
878 public function update($user = 0, $notrigger = 0)
880 global $conf, $langs, $hookmanager;
889 if (isset($this->
ref)) {
890 $this->
ref = trim($this->
ref);
893 if (isset($this->track_id)) {
894 $this->track_id = trim($this->track_id);
897 if (isset($this->fk_soc)) {
898 $this->fk_soc = (int) $this->fk_soc;
901 if (isset($this->fk_project)) {
902 $this->fk_project = (int) $this->fk_project;
905 if (isset($this->origin_email)) {
906 $this->origin_email = trim($this->origin_email);
909 if (isset($this->fk_user_create)) {
910 $this->fk_user_create = (int) $this->fk_user_create;
913 if (isset($this->fk_user_assign)) {
914 $this->fk_user_assign = (int) $this->fk_user_assign;
917 if (isset($this->subject)) {
918 $this->subject = trim($this->subject);
921 if (isset($this->message)) {
922 $this->message = trim($this->message);
924 $this->errors[] =
'ErrorFieldTooLong';
925 dol_syslog(get_class($this).
'::update error -1 message too long', LOG_ERR);
930 if (isset($this->fk_statut)) {
931 $this->fk_statut = (int) $this->fk_statut;
934 if (isset($this->resolution)) {
935 $this->resolution = trim($this->resolution);
938 if (isset($this->progress)) {
939 $this->progress = trim($this->progress);
942 if (isset($this->timing)) {
943 $this->timing = trim($this->timing);
946 if (isset($this->type_code)) {
947 $this->timing = trim($this->type_code);
950 if (isset($this->category_code)) {
951 $this->timing = trim($this->category_code);
954 if (isset($this->severity_code)) {
955 $this->timing = trim($this->severity_code);
961 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket SET";
962 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"").
",";
963 $sql .=
" track_id=".(isset($this->track_id) ?
"'".$this->db->escape($this->track_id).
"'" :
"null").
",";
964 $sql .=
" fk_soc=".(isset($this->fk_soc) ?
"'".$this->db->escape($this->fk_soc).
"'" :
"null").
",";
965 $sql .=
" fk_project=".(isset($this->fk_project) ?
"'".$this->db->escape($this->fk_project).
"'" :
"null").
",";
966 $sql .=
" origin_email=".(isset($this->origin_email) ?
"'".$this->db->escape($this->origin_email).
"'" :
"null").
",";
967 $sql .=
" fk_user_create=".(isset($this->fk_user_create) ? $this->fk_user_create :
"null").
",";
968 $sql .=
" fk_user_assign=".(isset($this->fk_user_assign) ? $this->fk_user_assign :
"null").
",";
969 $sql .=
" subject=".(isset($this->subject) ?
"'".$this->db->escape($this->subject).
"'" :
"null").
",";
970 $sql .=
" message=".(isset($this->message) ?
"'".$this->db->escape($this->message).
"'" :
"null").
",";
971 $sql .=
" fk_statut=".(isset($this->fk_statut) ? $this->fk_statut :
"null").
",";
972 $sql .=
" resolution=".(isset($this->resolution) ? $this->resolution :
"null").
",";
973 $sql .=
" progress=".(isset($this->progress) ?
"'".$this->db->escape($this->progress).
"'" :
"null").
",";
974 $sql .=
" timing=".(isset($this->timing) ?
"'".$this->db->escape($this->timing).
"'" :
"null").
",";
975 $sql .=
" type_code=".(isset($this->type_code) ?
"'".$this->db->escape($this->type_code).
"'" :
"null").
",";
976 $sql .=
" category_code=".(isset($this->category_code) ?
"'".$this->db->escape($this->category_code).
"'" :
"null").
",";
977 $sql .=
" severity_code=".(isset($this->severity_code) ?
"'".$this->db->escape($this->severity_code).
"'" :
"null").
",";
978 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
979 $sql .=
" date_read=".(dol_strlen($this->date_read) != 0 ?
"'".$this->db->idate($this->date_read).
"'" :
'null').
",";
980 $sql .=
" date_last_msg_sent=".(dol_strlen($this->date_last_msg_sent) != 0 ?
"'".$this->db->idate($this->date_last_msg_sent).
"'" :
'null').
",";
981 $sql .=
" date_close=".(dol_strlen($this->date_close) != 0 ?
"'".$this->db->idate($this->date_close).
"'" :
'null');
982 $sql .=
" WHERE rowid=".((int) $this->
id);
989 $this->errors[] =
"Error ".$this->db->lasterror();
994 $result = $this->insertExtraFields();
1000 if (!$error && !$notrigger) {
1002 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1011 foreach ($this->errors as $errmsg) {
1012 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1013 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1015 $this->
db->rollback();
1018 $this->
db->commit();
1030 public function delete($user, $notrigger = 0)
1032 global $conf, $langs;
1040 $result = $this->call_trigger(
'TICKET_DELETE', $user);
1050 $res = $this->delete_linked_contact();
1052 dol_syslog(get_class($this).
"::delete error", LOG_ERR);
1059 $res = $this->deleteObjectLinked();
1067 $result = $this->deleteExtraFields();
1070 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1077 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_ticket";
1078 $sql .=
" WHERE fk_ticket = ".(int) $this->
id;
1080 $result = $this->
db->query($sql);
1083 $this->errors[] = $this->
db->lasterror();
1088 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"ticket";
1089 $sql .=
" WHERE rowid=".((int) $this->
id);
1091 dol_syslog(get_class($this).
"::delete sql=".$sql);
1095 $this->errors[] =
"Error ".$this->db->lasterror();
1101 foreach ($this->errors as $errmsg) {
1102 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
1103 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1105 $this->
db->rollback();
1108 $this->
db->commit();
1129 $object->fetch($fromid);
1131 $object->statut = 0;
1136 $object->context[
'createfromclone'] =
'createfromclone';
1137 $result = $object->create($user);
1141 $this->error = $object->error;
1148 unset($object->context[
'createfromclone']);
1152 $this->
db->commit();
1155 $this->
db->rollback();
1170 $this->
ref =
'TI0501-001';
1171 $this->track_id =
'XXXXaaaa';
1172 $this->origin_email =
'email@email.com';
1173 $this->fk_project = 1;
1174 $this->fk_user_create = 1;
1175 $this->fk_user_assign = 1;
1176 $this->subject =
'Subject of ticket';
1177 $this->message =
'Message of ticket';
1179 $this->resolution =
'1';
1180 $this->progress =
'10';
1182 $this->type_code =
'TYPECODE';
1183 $this->category_code =
'CATEGORYCODE';
1184 $this->severity_code =
'SEVERITYCODE';
1186 $this->date_read =
'';
1187 $this->date_last_msg_sent =
'';
1188 $this->date_close =
'';
1201 print
Form::selectarray(
'search_fk_statut', $this->statuts_short, $selected, $show_empty = 1, $key_in_label = 0, $value_as_key = 0, $option =
'', $translate = 1, $maxlen = 0, $disabled = 0, $sort =
'', $morecss =
'');
1214 if (!empty($this->cache_types_tickets) && count($this->cache_types_tickets)) {
1219 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1220 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_type";
1221 $sql .=
" WHERE active > 0";
1222 $sql .=
" ORDER BY pos";
1223 dol_syslog(get_class($this).
"::load_cache_type_tickets", LOG_DEBUG);
1226 $num = $this->
db->num_rows(
$resql);
1229 $obj = $this->
db->fetch_object(
$resql);
1231 $label = ($langs->trans(
"TicketTypeShort".$obj->code) != (
"TicketTypeShort".$obj->code) ? $langs->trans(
"TicketTypeShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1232 $this->cache_types_tickets[$obj->rowid][
'code'] = $obj->code;
1233 $this->cache_types_tickets[$obj->rowid][
'label'] = $label;
1234 $this->cache_types_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1235 $this->cache_types_tickets[$obj->rowid][
'pos'] = $obj->pos;
1252 global $conf, $langs;
1254 if (!empty($this->cache_category_ticket) && count($this->cache_category_tickets)) {
1259 $sql =
"SELECT rowid, code, label, use_default, pos, description, public, active, force_severity, fk_parent";
1260 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_category";
1261 $sql .=
" WHERE active > 0 AND entity = ".((int) $conf->entity);
1262 $sql .=
" ORDER BY pos";
1263 dol_syslog(get_class($this).
"::load_cache_categories_tickets", LOG_DEBUG);
1266 $num = $this->
db->num_rows(
$resql);
1269 $obj = $this->
db->fetch_object(
$resql);
1270 $this->cache_category_tickets[$obj->rowid][
'code'] = $obj->code;
1271 $this->cache_category_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1272 $this->cache_category_tickets[$obj->rowid][
'pos'] = $obj->pos;
1273 $this->cache_category_tickets[$obj->rowid][
'public'] = $obj->public;
1274 $this->cache_category_tickets[$obj->rowid][
'active'] = $obj->active;
1275 $this->cache_category_tickets[$obj->rowid][
'force_severity'] = $obj->force_severity;
1276 $this->cache_category_tickets[$obj->rowid][
'fk_parent'] = $obj->fk_parent;
1280 $label = ($langs->trans(
"TicketCategoryShort".$obj->code) != (
"TicketCategoryShort".$obj->code) ? $langs->trans(
"TicketCategoryShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1281 $this->cache_category_tickets[$obj->rowid][
'label'] = $label;
1301 if (!empty($this->cache_severity_tickets) && count($this->cache_severity_tickets)) {
1306 $sql =
"SELECT rowid, code, label, use_default, pos, description";
1307 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_ticket_severity";
1308 $sql .=
" WHERE active > 0";
1309 $sql .=
" ORDER BY pos";
1310 dol_syslog(get_class($this).
"::loadCacheSeveritiesTickets", LOG_DEBUG);
1313 $num = $this->
db->num_rows(
$resql);
1316 $obj = $this->
db->fetch_object(
$resql);
1318 $this->cache_severity_tickets[$obj->rowid][
'code'] = $obj->code;
1320 $label = ($langs->trans(
"TicketSeverityShort".$obj->code) != (
"TicketSeverityShort".$obj->code) ? $langs->trans(
"TicketSeverityShort".$obj->code) : ($obj->label !=
'-' ? $obj->label :
''));
1321 $this->cache_severity_tickets[$obj->rowid][
'label'] = $label;
1322 $this->cache_severity_tickets[$obj->rowid][
'use_default'] = $obj->use_default;
1323 $this->cache_severity_tickets[$obj->rowid][
'pos'] = $obj->pos;
1342 return $this->libStatut($this->fk_statut, $mode, 0, $this->progress);
1356 public function LibStatut($status, $mode = 0, $notooltip = 0, $progress = 0)
1361 $labelStatus = $this->statuts[$status];
1362 $labelStatusShort = $this->statuts_short[$status];
1364 if ($status == self::STATUS_NOT_READ) {
1365 $statusType =
'status0';
1366 } elseif ($status == self::STATUS_READ) {
1367 $statusType =
'status1';
1368 } elseif ($status == self::STATUS_ASSIGNED) {
1369 $statusType =
'status2';
1370 } elseif ($status == self::STATUS_IN_PROGRESS) {
1371 $statusType =
'status4';
1372 } elseif ($status == self::STATUS_WAITING) {
1373 $statusType =
'status7';
1374 } elseif ($status == self::STATUS_NEED_MORE_INFO) {
1375 $statusType =
'status3';
1376 } elseif ($status == self::STATUS_CANCELED) {
1377 $statusType =
'status9';
1378 } elseif ($status == self::STATUS_CLOSED) {
1379 $statusType =
'status6';
1381 $labelStatus =
'Unknown';
1382 $labelStatusShort =
'Unknown';
1383 $statusType =
'status0';
1389 $params = array(
'tooltip' =>
'no');
1392 $labelStatus = $langs->transnoentitiesnoconv($labelStatus);
1393 $labelStatusShort = $langs->transnoentitiesnoconv($labelStatusShort);
1395 if ($status == self::STATUS_IN_PROGRESS && $progress > 0) {
1396 $labelStatus .=
' ('.round($progress).
'%)';
1397 $labelStatusShort .=
' ('.round($progress).
'%)';
1400 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $params);
1414 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
1416 global $db, $conf, $langs;
1417 global $dolibarr_main_authentication, $dolibarr_main_demo;
1418 global $menumanager;
1420 if (!empty($conf->dol_no_mouse_hover)) {
1426 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Ticket").
'</u>';
1427 $label .=
' '.$this->getLibStatut(4);
1429 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->
ref.
'<br>';
1430 $label .=
'<b>'.$langs->trans(
'TicketTrackId').
':</b> '.$this->track_id.
'<br>';
1431 $label .=
'<b>'.$langs->trans(
'Subject').
':</b> '.$this->subject;
1432 if ($this->date_creation) {
1433 $label .=
'<br><b>'.$langs->trans(
'DateCreation').
':</b> '.$this->date_creation;
1435 if ($this->date_modification) {
1436 $label .=
'<br><b>'.$langs->trans(
'DateModification').
':</b> '.$this->date_modification;
1438 $url = DOL_URL_ROOT.
'/ticket/card.php?id='.$this->id;
1440 if ($option !=
'nolink') {
1442 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1443 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1444 $add_save_lastsearch_values = 1;
1446 if ($add_save_lastsearch_values) {
1447 $url .=
'&save_lastsearch_values=1';
1452 if (empty($notooltip)) {
1453 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1454 $label = $langs->trans(
"ShowTicket");
1455 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1457 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
1458 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
1460 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
1463 $linkstart =
'<a href="'.$url.
'"';
1464 $linkstart .= $linkclose.
'>';
1467 $result .= $linkstart;
1469 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
1471 if ($withpicto != 2) {
1472 $result .= $this->ref;
1474 $result .= $linkend;
1490 global $conf, $langs;
1494 if ($this->statut != self::STATUS_CANCELED) {
1499 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1500 $sql .=
" SET fk_statut = ".Ticket::STATUS_READ.
", date_read = '".$this->
db->idate(
dol_now()).
"'";
1501 $sql .=
" WHERE rowid = ".((int) $this->
id);
1506 $this->actionmsg = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1507 $this->actionmsg2 = $langs->trans(
'TicketLogMesgReadBy', $this->
ref, $user->getFullName($langs));
1509 if (!$error && !$notrigger) {
1511 $result = $this->call_trigger(
'TICKET_MODIFY', $user);
1519 $this->
db->commit();
1522 $this->
db->rollback();
1523 $this->error = join(
',', $this->errors);
1524 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1528 $this->
db->rollback();
1529 $this->error = $this->
db->lasterror();
1530 dol_syslog(get_class($this).
"::markAsRead ".$this->error, LOG_ERR);
1544 public function assignUser($user, $id_assign_user, $notrigger = 0)
1546 global $conf, $langs;
1554 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1555 if ($id_assign_user > 0) {
1556 $sql .=
" SET fk_user_assign=".((int) $id_assign_user).
", fk_statut = ".Ticket::STATUS_ASSIGNED;
1558 $sql .=
" SET fk_user_assign=null, fk_statut = ".Ticket::STATUS_READ;
1560 $sql .=
" WHERE rowid = ".((int) $this->
id);
1562 dol_syslog(get_class($this).
"::assignUser sql=".$sql);
1565 $this->fk_user_assign = $id_assign_user;
1569 $result = $this->call_trigger(
'TICKET_ASSIGNED', $user);
1577 $this->
db->commit();
1580 $this->
db->rollback();
1581 $this->error = join(
',', $this->errors);
1582 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1586 $this->
db->rollback();
1587 $this->error = $this->
db->lasterror();
1588 dol_syslog(get_class($this).
"::assignUser ".$this->error, LOG_ERR);
1604 public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $send_email =
false)
1606 global $conf, $langs;
1612 if (isset($this->fk_track_id)) {
1613 $this->fk_track_id = trim($this->fk_track_id);
1616 if (isset($this->message)) {
1617 $this->message = trim($this->message);
1623 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
1625 $actioncomm->type_code =
'AC_OTH_AUTO';
1626 $actioncomm->code =
'TICKET_MSG';
1627 if ($this->
private) {
1628 $actioncomm->code =
'TICKET_MSG_PRIVATE';
1631 $actioncomm->code .=
'_SENTBYMAIL';
1633 $actioncomm->socid = $this->socid;
1634 $actioncomm->label = $this->subject;
1635 $actioncomm->note_private = $this->message;
1636 $actioncomm->userassigned = array($user->id);
1637 $actioncomm->userownerid = $user->id;
1638 $actioncomm->datep = $now;
1639 $actioncomm->percentage = -1;
1640 $actioncomm->elementtype =
'ticket';
1641 $actioncomm->fk_element = $this->id;
1642 $actioncomm->fk_project = $this->fk_project;
1644 $attachedfiles = array();
1645 $attachedfiles[
'paths'] = $filename_list;
1646 $attachedfiles[
'names'] = $mimefilename_list;
1647 $attachedfiles[
'mimes'] = $mimetype_list;
1648 if (is_array($attachedfiles) && count($attachedfiles) > 0) {
1649 $actioncomm->attachedfiles = $attachedfiles;
1652 if (!empty($mimefilename_list) && is_array($mimefilename_list)) {
1653 $actioncomm->note_private =
dol_concatdesc($actioncomm->note_private,
"\n".$langs->transnoentities(
"AttachedFiles").
': '.join(
';', $mimefilename_list));
1656 $actionid = $actioncomm->create($user);
1657 if ($actionid <= 0) {
1659 $this->error = $actioncomm->error;
1660 $this->errors = $actioncomm->errors;
1665 $this->
db->rollback();
1668 $this->
db->commit();
1680 if (!empty($this->cache_msgs_ticket) && is_array($this->cache_msgs_ticket) && count($this->cache_msgs_ticket)) {
1686 $sql =
"SELECT id as rowid, fk_user_author, datec, label, note as message, code";
1687 $sql .=
" FROM ".MAIN_DB_PREFIX.
"actioncomm";
1688 $sql .=
" WHERE fk_element = ".(int) $this->
id;
1689 $sql .=
" AND elementtype = 'ticket'";
1690 $sql .=
" ORDER BY datec DESC";
1692 dol_syslog(get_class($this).
"::load_cache_actions_ticket", LOG_DEBUG);
1695 $num = $this->
db->num_rows(
$resql);
1698 $obj = $this->
db->fetch_object(
$resql);
1699 $this->cache_msgs_ticket[$i][
'id'] = $obj->rowid;
1700 $this->cache_msgs_ticket[$i][
'fk_user_author'] = $obj->fk_user_author;
1701 $this->cache_msgs_ticket[$i][
'datec'] = $this->
db->jdate($obj->datec);
1702 $this->cache_msgs_ticket[$i][
'subject'] = $obj->label;
1703 $this->cache_msgs_ticket[$i][
'message'] = $obj->message;
1704 $this->cache_msgs_ticket[$i][
'private'] = (preg_match(
'/^TICKET_MSG_PRIVATE/', $obj->code) ? 1 : 0);
1709 $this->error =
"Error ".$this->db->lasterror();
1710 dol_syslog(get_class($this).
"::load_cache_actions_ticket ".$this->error, LOG_ERR);
1724 global $conf, $langs;
1726 if ($this->fk_statut != Ticket::STATUS_CLOSED && $this->fk_statut != Ticket::STATUS_CANCELED) {
1729 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1730 $sql .=
" SET fk_statut=".($mode ? Ticket::STATUS_CANCELED : Ticket::STATUS_CLOSED).
", progress=100, date_close='".$this->
db->idate(
dol_now()).
"'";
1731 $sql .=
" WHERE rowid = ".((int) $this->
id);
1733 dol_syslog(get_class($this).
"::close mode=".$mode);
1739 if (
isModEnabled(
'ficheinter') && !empty($conf->global->WORKFLOW_TICKET_CLOSE_INTERVENTION)) {
1740 dol_syslog(
"We have closed the ticket, so we close all linked interventions");
1741 $this->fetchObjectLinked($this->
id, $this->element,
null,
'fichinter');
1742 if ($this->linkedObjectsIds) {
1743 foreach ($this->linkedObjectsIds[
'fichinter'] as $fichinter_id) {
1745 $fichinter->fetch($fichinter_id);
1746 if ($fichinter->statut == 0) {
1747 $result = $fichinter->setValid($user);
1749 $this->errors[] = $fichinter->error;
1753 if ($fichinter->statut < 3) {
1754 $result = $fichinter->setStatut(3);
1756 $this->errors[] = $fichinter->error;
1765 $result = $this->call_trigger(
'TICKET_CLOSE', $user);
1772 $this->
db->commit();
1775 $this->
db->rollback();
1776 $this->error = join(
',', $this->errors);
1777 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1781 $this->
db->rollback();
1782 $this->error = $this->
db->lasterror();
1783 dol_syslog(get_class($this).
"::close ".$this->error, LOG_ERR);
1800 $thirdparties = array();
1804 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"societe";
1805 $sql .=
" WHERE entity IN (".getEntity(
'ticket', 1).
")";
1806 if (!empty($type)) {
1807 if ($type == 1 || $type == 2) {
1808 $sql .=
" AND client = ".((int) $type);
1809 } elseif ($type == 3) {
1810 $sql .=
" AND fournisseur = 1";
1813 if (!empty($email)) {
1814 if (empty($exact)) {
1816 if (preg_match(
'/^([\*])?[^*]+([\*])?$/', $email, $regs) && count($regs) > 1) {
1817 $email = str_replace(
'*',
'%', $email);
1819 $email =
'%'.$email.
'%';
1823 if (is_array($filters) && !empty($filters)) {
1827 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
1829 if (is_array($filters) && !empty($filters)) {
1830 foreach ($filters as $field => $value) {
1831 $sql .=
" ".$clause.
" ".$field.
" LIKE '".$this->
db->escape($value).
"'";
1833 if (!empty($email)) {
1838 $res = $this->
db->query($sql);
1840 while ($rec = $this->
db->fetch_array($res)) {
1842 $soc->fetch($rec[
'rowid']);
1843 $thirdparties[] = $soc;
1846 return $thirdparties;
1848 $this->error = $this->
db->error().
' sql='.$sql;
1849 dol_syslog(get_class($this).
"::searchSocidByEmail ".$this->error, LOG_ERR);
1864 $contacts = array();
1867 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"socpeople";
1868 $sql .=
" WHERE entity IN (".getEntity(
'contact').
")";
1869 if (!empty($socid)) {
1870 $sql .=
" AND fk_soc='".$this->db->escape($socid).
"'";
1873 if (!empty($email)) {
1877 $sql .=
"email LIKE '".$this->db->escape($email).
"'";
1879 $sql .=
"email LIKE BINARY '".$this->db->escape($email).
"'";
1883 $res = $this->
db->query($sql);
1885 while ($rec = $this->
db->fetch_array($res)) {
1886 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
1887 $contactstatic =
new Contact($this->
db);
1888 $contactstatic->fetch($rec[
'rowid']);
1889 $contacts[] = $contactstatic;
1894 $this->error = $this->
db->error().
' sql='.$sql;
1895 dol_syslog(get_class($this).
"::searchContactByEmail ".$this->error, LOG_ERR);
1909 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1910 $sql .=
" SET fk_soc = ".($id > 0 ? $id :
"null");
1911 $sql .=
" WHERE rowid = ".((int) $this->
id);
1912 dol_syslog(get_class($this).
'::setCustomer sql='.$sql);
1933 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"ticket";
1934 $sql .=
" SET progress = ".($percent > 0 ? $percent :
"null");
1935 $sql .=
" WHERE rowid = ".((int) $this->
id);
1936 dol_syslog(get_class($this).
'::set_progression sql='.$sql);
1956 if (!$this->table_element) {
1957 dol_syslog(get_class($this).
"::setContract was called on objet with property table_element not defined", LOG_ERR);
1961 $result = $this->add_object_linked(
'contrat', $contractid);
1963 $this->fk_contract = $contractid;
1980 return $this->getIdContact(
'internal',
'SUPPORTTEC');
1990 return $this->listeContact(-1,
'internal');
2000 return $this->getIdContact(
'external',
'SUPPORTCLI');
2010 return $this->listeContact(-1,
'external');
2020 return $this->getIdContact(
'internal',
'CONTRIBUTOR');
2030 return $this->getIdContact(
'external',
'CONTRIBUTOR');
2040 $array_contact = array();
2042 $array_contact = $this->getIdTicketInternalContact();
2044 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact());
2046 $array_contact = array_merge($array_contact, $this->getIdTicketInternalInvolvedContact());
2048 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact());
2050 return $array_contact;
2060 $array_contact = array();
2062 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact());
2064 $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact());
2066 return $array_contact;
2080 public function listeContact($status = -1, $source =
'external', $list = 0, $code =
'')
2086 $sql =
"SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact";
2087 if ($source ==
'internal') {
2088 $sql .=
", '-1' as socid, t.statut as statuscontact";
2091 if ($source ==
'external' || $source ==
'thirdparty') {
2092 $sql .=
", t.fk_soc as socid, t.statut as statuscontact";
2095 $sql .=
", t.civility, t.lastname as lastname, t.firstname, t.email";
2096 if ($source ==
'internal') {
2097 $sql .=
", t.office_phone as phone, t.user_mobile as phone_mobile";
2100 if ($source ==
'external') {
2101 $sql .=
", t.phone as phone, t.phone_mobile as phone_mobile, t.phone_perso as phone_perso";
2104 $sql .=
", tc.source, tc.element, tc.code, tc.libelle as type_contact_label";
2105 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_type_contact tc";
2106 $sql .=
", ".MAIN_DB_PREFIX.
"element_contact ec";
2107 if ($source ==
'internal') {
2108 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"user t on ec.fk_socpeople = t.rowid";
2111 if ($source ==
'external' || $source ==
'thirdparty') {
2112 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"socpeople t on ec.fk_socpeople = t.rowid";
2115 $sql .=
" WHERE ec.element_id = ".((int) $this->
id);
2116 $sql .=
" AND ec.fk_c_type_contact=tc.rowid";
2117 $sql .=
" AND tc.element='".$this->db->escape($this->element).
"'";
2118 if ($source ==
'internal') {
2119 $sql .=
" AND tc.source = 'internal'";
2122 if ($source ==
'external' || $source ==
'thirdparty') {
2123 $sql .=
" AND tc.source = 'external'";
2126 if (!empty($code)) {
2127 $sql .=
" AND tc.code = '".$this->db->escape($code).
"'";
2130 $sql .=
" AND tc.active=1";
2132 $sql .=
" AND ec.statut = ".((int) $status);
2135 $sql .=
" ORDER BY t.lastname ASC";
2139 $num = $this->
db->num_rows(
$resql);
2142 $obj = $this->
db->fetch_object(
$resql);
2145 $transkey =
"TypeContact_".$obj->element.
"_".$obj->source.
"_".$obj->code;
2146 $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_contact_label);
2148 'source' => $obj->source,
2149 'socid' => $obj->socid,
2151 'nom' => $obj->lastname,
2152 'civility' => $obj->civility,
2153 'lastname' => $obj->lastname,
2154 'firstname' => $obj->firstname,
2155 'email' => $obj->email,
2156 'rowid' => $obj->rowid,
2157 'code' => $obj->code,
2158 'libelle' => $libelle_type,
2159 'status' => $obj->statuslink,
2160 'statuscontact'=>$obj->statuscontact,
2161 'fk_c_type_contact' => $obj->fk_c_type_contact,
2162 'phone' => $obj->phone,
2163 'phone_mobile' => $obj->phone_mobile);
2165 $tab[$i] = $obj->id;
2173 $this->error = $this->
db->error();
2190 $modele = empty($conf->global->TICKET_ADDON) ?
'mod_ticket_simple' : $conf->global->TICKET_ADDON;
2196 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
2197 foreach ($dirmodels as $reldir) {
2198 $file =
dol_buildpath($reldir.
"core/modules/ticket/".$modele.
'.php', 0);
2199 if (file_exists($file)) {
2201 $classname = $modele;
2208 $modTicket =
new $classname;
2210 $defaultref = $modTicket->getNextValue($thirdparty, $this);
2213 if (is_numeric($defaultref) && $defaultref <= 0) {
2231 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2239 if (file_exists($dir_osencoded)) {
2240 $handle = opendir($dir_osencoded);
2241 if (is_resource($handle)) {
2242 while (($file = readdir($handle)) !==
false) {
2244 $file = utf8_encode($file);
2268 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2269 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2270 include_once DOL_DOCUMENT_ROOT.
'/core/lib/images.lib.php';
2272 $maxwidthsmall = 270;
2273 $maxheightsmall = 150;
2274 $maxwidthmini = 128;
2275 $maxheightmini = 72;
2279 $attachedfiles = $formmail->get_attached_files();
2281 $filepath = $attachedfiles[
'paths'];
2282 $filename = $attachedfiles[
'names'];
2283 $mimetype = $attachedfiles[
'mimes'];
2286 $destdir = $conf->ticket->dir_output.
'/'.$this->ref;
2292 $listofpaths = array();
2293 $listofnames = array();
2294 foreach ($filename as $i => $val) {
2295 $destfile = $destdir.
'/'.$filename[$i];
2297 if (is_file($destfile)) {
2298 $pathinfo = pathinfo($filename[$i]);
2300 $destfile = $destdir.
'/'.$pathinfo[
'filename'].
' - '.
dol_print_date($now,
'dayhourlog').
'.'.$pathinfo[
'extension'];
2303 $res =
dol_move($filepath[$i], $destfile, 0, 1);
2308 $imgThumbSmall =
vignette($destfile, $maxwidthsmall, $maxheightsmall,
'_small', 50,
"thumbs");
2311 $imgThumbMini =
vignette($destfile, $maxwidthmini, $maxheightmini,
'_mini', 50,
"thumbs");
2314 $formmail->remove_attached_files($i);
2317 $listofpaths[$i] = $destfile;
2318 $listofnames[$i] = basename($destfile);
2321 return array(
'listofpaths'=>$listofpaths,
'listofnames'=>$listofnames,
'listofmimes'=>$mimetype);
2337 if (!is_array($categories)) {
2338 $categories = array($categories);
2342 include_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
2344 $existing = $c->containing($this->
id, Categorie::TYPE_TICKET,
'id');
2347 if (is_array($existing)) {
2348 $to_del = array_diff($existing, $categories);
2349 $to_add = array_diff($categories, $existing);
2352 $to_add = $categories;
2356 foreach ($to_del as $del) {
2357 if ($c->fetch($del) > 0) {
2358 $c->del_type($this, Categorie::TYPE_TICKET);
2361 foreach ($to_add as $add) {
2362 if ($c->fetch($add) > 0) {
2363 $c->add_type($this, Categorie::TYPE_TICKET);
2380 public function newMessage($user, &$action, $private = 1, $public_area = 0)
2382 global $mysoc, $conf, $langs;
2388 $ret = $object->fetch(
'',
'',
GETPOST(
'track_id',
'alpha'));
2390 $object->socid = $object->fk_soc;
2391 $object->fetch_thirdparty();
2392 $object->fetch_project();
2396 array_push($this->errors, $langs->trans(
"ErrorTicketIsNotValid"));
2402 array_push($this->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"message")));
2403 $action =
'add_message';
2407 $object->subject =
GETPOST(
'subject',
'alphanohtml');
2408 $object->message =
GETPOST(
"message",
"restricthtml");
2409 $object->private =
GETPOST(
"private_message",
"alpha");
2411 $send_email =
GETPOST(
'send_email',
'int');
2414 $resarray = $object->copyFilesForTicket();
2416 $listofpaths = $resarray[
'listofpaths'];
2417 $listofnames = $resarray[
'listofnames'];
2418 $listofmimes = $resarray[
'listofmimes'];
2420 $id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames, $send_email);
2423 $this->error = $object->error;
2424 $this->errors = $object->errors;
2425 $action =
'add_message';
2428 if (!$error && $id > 0) {
2429 setEventMessages($langs->trans(
'TicketMessageSuccessfullyAdded'),
null,
'mesgs');
2434 if (!empty($public_area)) {
2440 if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) {
2442 $internal_contacts = $object->getInfosTicketInternalContact();
2444 $assigned_user_dont_have_email =
'';
2448 if ($this->fk_user_assign > 0) {
2449 $assigned_user =
new User($this->
db);
2450 $assigned_user->fetch($this->fk_user_assign);
2451 if (!empty($assigned_user->email)) {
2452 $sendto[] = $assigned_user->getFullName($langs).
" <".$assigned_user->email.
">";
2454 $assigned_user_dont_have_email = $assigned_user->getFullName($langs);
2459 foreach ($internal_contacts as $key => $info_sendto) {
2461 if ($info_sendto[
'id'] == $user->id) {
2465 if ($info_sendto[
'email'] !=
'') {
2466 if (!empty($info_sendto[
'email'])) {
2467 $sendto[] =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2472 if (empty($sendto)) {
2473 if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL)) {
2474 $sendto[] = $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL;
2475 } elseif (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2476 $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2481 if (!empty($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS) &&
2482 !empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)
2484 $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2487 if (!empty($sendto)) {
2488 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2489 $subject =
'['.$label_title.
'- ticket #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2492 $message = $langs->trans(
'TicketMessageMailIntroText');
2493 $message .=
'<br><br>';
2494 $messagePost =
GETPOST(
'message',
'restricthtml');
2498 $message .= $messagePost;
2501 $message .=
'<br><br>';
2502 $message .=
"==============================================";
2503 $message .= !empty($object->thirdparty->name) ?
'<br>'.$langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2504 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2505 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2508 $message .=
'<br><br>';
2509 if (!empty($assigned_user_dont_have_email)) {
2510 $message .=
'<br>'.$langs->trans(
'NoEMail').
' : '.$assigned_user_dont_have_email;
2512 foreach ($sendto as $val) {
2513 $message .=
'<br>'.$langs->trans(
'TicketNotificationRecipient').
' : '.$val;
2517 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2518 $message .=
'<br><br>';
2519 $message .= $langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a>';
2521 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2530 if ($send_email > 0) {
2532 $internal_contacts = $object->getInfosTicketInternalContact();
2535 if (is_array($internal_contacts) && count($internal_contacts) > 0) {
2537 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2538 $appli = $label_title;
2539 $subject =
GETPOST(
'subject',
'alphanohtml') ?
GETPOST(
'subject',
'alphanohtml') :
'['.$appli.
' - '.$langs->trans(
"Ticket").
' #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2541 $message_intro = $langs->trans(
'TicketNotificationEmailBody',
"#".$object->id);
2544 $message = $langs->trans(
'TicketMessageMailIntroText');
2545 $message .=
'<br><br>';
2546 $messagePost =
GETPOST(
'message',
'restricthtml');
2550 $message .= $messagePost;
2553 $message .=
'<br><br>';
2554 $message .=
"==============================================<br>";
2555 $message .= !empty($object->thirdparty->name) ? $langs->trans(
'Thirdparty').
" : ".$object->thirdparty->name :
'';
2556 $message .= !empty($object->thirdparty->town) ?
'<br>'.$langs->trans(
'Town').
" : ".$object->thirdparty->town :
'';
2557 $message .= !empty($object->thirdparty->phone) ?
'<br>'.$langs->trans(
'Phone').
" : ".$object->thirdparty->phone :
'';
2560 foreach ($internal_contacts as $key => $info_sendto) {
2562 if ($info_sendto[
'id'] == $user->id) {
2566 if ($info_sendto[
'email'] !=
'') {
2567 if (!empty($info_sendto[
'email'])) {
2568 $sendto[] =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2572 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2573 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2578 $url_internal_ticket =
dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id;
2581 $message .=
'<br>'.$langs->trans(
'TicketNotificationEmailBodyInfosTrackUrlinternal').
' : <a href="'.$url_internal_ticket.
'">'.$object->track_id.
'</a><br>';
2584 if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2585 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2586 $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2591 if (!empty($sendto)) {
2592 $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2599 if (empty($object->private)) {
2601 $external_contacts = $object->getInfosTicketExternalContact();
2604 if (is_array($external_contacts) && count($external_contacts) === 0) {
2605 if (!empty($object->fk_soc)) {
2606 $object->fetch_thirdparty($object->fk_soc);
2607 $array_company = array(array(
'firstname' =>
'',
'lastname' => $object->thirdparty->name,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2608 $external_contacts = array_merge($external_contacts, $array_company);
2609 } elseif (empty($object->fk_soc) && !empty($object->origin_email)) {
2610 $array_external = array(array(
'firstname' =>
'',
'lastname' => $object->origin_email,
'email' => $object->thirdparty->email,
'libelle' => $langs->transnoentities(
'Customer'),
'socid' => $object->thirdparty->id));
2611 $external_contacts = array_merge($external_contacts, $array_external);
2616 if (is_array($external_contacts) && count($external_contacts) > 0) {
2618 $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2619 $appli = $mysoc->name;
2620 $subject =
GETPOST(
'subject') ?
GETPOST(
'subject') :
'['.$appli.
' - '.$langs->trans(
"Ticket").
' #'.$object->track_id.
'] '.$langs->trans(
'TicketNewMessage');
2625 $message_intro =
dol_nl2br($message_intro);
2628 $message_signature =
dol_nl2br($message_signature);
2632 $messagePost =
GETPOST(
'message',
'restricthtml');
2636 $message = $messagePost;
2637 $message .=
'<br><br>';
2639 foreach ($external_contacts as $key => $info_sendto) {
2641 if ($info_sendto[
'id'] == $user->contact_id) {
2645 if ($info_sendto[
'email'] !=
'' && $info_sendto[
'email'] != $object->origin_email) {
2646 if (!empty($info_sendto[
'email'])) {
2647 $sendto[] = trim($info_sendto[
'firstname'].
" ".$info_sendto[
'lastname']).
" <".$info_sendto[
'email'].
">";
2650 $recipient =
dolGetFirstLastname($info_sendto[
'firstname'], $info_sendto[
'lastname'],
'-1').
' ('.strtolower($info_sendto[
'libelle']).
')';
2651 $message .= (!empty($recipient) ? $langs->trans(
'TicketNotificationRecipient').
' : '.$recipient.
'<br>' :
'');
2656 $url_public_ticket = (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ?
2657 (!empty($conf->global->TICKET_URL_PUBLIC_INTERFACE) ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.
'/view.php' :
dol_buildpath(
'/public/ticket/view.php', 2)) :
dol_buildpath(
'/ticket/card.php', 2)).
'?track_id='.$object->track_id;
2658 $message .=
'<br>'.$langs->trans(
'TicketNewEmailBodyInfosTrackUrlCustomer').
' : <a href="'.$url_public_ticket.
'">'.$object->track_id.
'</a><br>';
2661 $message = $message_intro.
'<br><br>'.$message;
2664 $message .=
'<br>'.$message_signature;
2666 if (!empty($object->origin_email)) {
2667 $sendto[] = $object->origin_email;
2670 if ($object->fk_soc > 0 && !in_array($object->origin_email, $sendto)) {
2671 $object->socid = $object->fk_soc;
2672 $object->fetch_thirdparty();
2673 if (!empty($object->thirdparty->email)) {
2674 $sendto[] = $object->thirdparty->email;
2679 if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !in_array($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2680 if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2681 $sendto[] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2686 if (!empty($sendto)) {
2687 $result = $this->sendTicketMessageByEmail($subject, $message,
'', $sendto, $listofpaths, $listofmimes, $listofnames);
2690 $this->date_last_msg_sent =
dol_now();
2691 $this->update($user, 1);
2701 if (($object->status < self::STATUS_IN_PROGRESS && !$user->socid && !$private) ||
2702 ($object->status > self::STATUS_IN_PROGRESS && $public_area)
2704 $object->setStatut(3);
2730 public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
2732 global $conf, $langs;
2734 if ($conf->global->TICKET_DISABLE_ALL_MAILS) {
2735 dol_syslog(get_class($this).
'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING);
2739 $langs->load(
"mails");
2741 include_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
2745 if (!is_array($array_receiver) || !count($array_receiver) > 0) {
2746 $array_receiver = $this->getInfosTicketInternalContact();
2747 $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact());
2750 if ($send_internal_cc) {
2751 $sendtocc = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2754 $from = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2756 if (is_array($array_receiver) && count($array_receiver) > 0) {
2757 foreach ($array_receiver as $key => $receiver) {
2758 $deliveryreceipt = 0;
2759 $filepath = $filename_list;
2760 $filename = $mimefilename_list;
2761 $mimetype = $mimetype_list;
2767 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2768 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
2771 $upload_dir_tmp = $conf->user->dir_output.
"/".$user->id.
'/temp';
2773 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
2774 $trackid =
"tic".$this->id;
2776 $moreinheader =
'X-Dolibarr-Info: sendTicketMessageByEmail'.
"\r\n";
2777 if (!empty($this->email_msgid)) {
2778 $moreinheader .=
'References <'.$this->email_msgid.
'>'.
"\r\n";
2781 $mailfile =
new CMailFile($subject, $receiver, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'', $trackid, $moreinheader,
'ticket',
'', $upload_dir_tmp);
2782 if ($mailfile->error) {
2785 $result = $mailfile->sendfile();
2787 setEventMessages($langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)),
null,
'mesgs');
2790 $langs->load(
"other");
2791 if ($mailfile->error) {
2792 setEventMessages($langs->trans(
'ErrorFailedToSendMail', $from, $receiver),
null,
'errors');
2793 dol_syslog($langs->trans(
'ErrorFailedToSendMail', $from, $receiver).
' : '.$mailfile->error);
2795 setEventMessages(
'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS',
null,
'errors');
2800 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2801 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
2805 $langs->load(
"other");
2806 setEventMessages($langs->trans(
'ErrorMailRecipientIsEmptyForSendTicketMessage'),
null,
'warnings');
2823 global $conf, $user, $langs;
2828 $this->nbtodo = $this->nbtodolate = 0;
2831 $sql =
"SELECT p.rowid, p.ref, p.datec as datec";
2832 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2833 if (
isModEnabled(
'societe') && empty($user->rights->societe->client->voir) && !$user->socid) {
2834 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2835 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2838 $sql .= $clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2839 if ($mode ==
'opened') {
2840 $sql .=
" AND p.fk_statut NOT IN (".Ticket::STATUS_CLOSED.
", ".Ticket::STATUS_CANCELED.
")";
2843 $sql .=
" AND p.fk_soc = ".((int) $user->socid);
2848 $label = $labelShort =
'';
2850 if ($mode ==
'opened') {
2851 $status =
'openall';
2854 $label = $langs->trans(
"MenuListNonClosed");
2855 $labelShort = $langs->trans(
"MenuListNonClosed");
2860 $response->label = $label;
2861 $response->labelShort = $labelShort;
2862 $response->url = DOL_URL_ROOT.
'/ticket/list.php?search_fk_statut[]='.$status;
2866 while ($obj = $this->
db->fetch_object(
$resql)) {
2867 $response->nbtodo++;
2868 if ($mode ==
'opened') {
2869 $datelimit = $this->
db->jdate($obj->datec) + $delay_warning;
2870 if ($datelimit < $now) {
2877 $this->error = $this->
db->lasterror();
2891 global $conf, $user;
2893 $this->nb = array();
2896 $sql =
"SELECT count(p.rowid) as nb";
2897 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket as p";
2898 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON p.fk_soc = s.rowid";
2899 if (empty($user->rights->societe->client->voir) && !$user->socid) {
2900 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2901 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2904 $sql .=
" ".$clause.
" p.entity IN (".
getEntity(
'ticket').
")";
2909 while ($obj = $this->
db->fetch_object(
$resql)) {
2910 $this->nb[
"ticket"] = $obj->nb;
2916 $this->error = $this->
db->lasterror();
2931 $tables = array(
'ticket');
3062 public $date_last_msg_sent =
'';
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 interventions.
Class to manage third parties objects (customers, suppliers, prospects...)
update($user=0, $notrigger=0)
Update object into database.
$email_from
Email from user.
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
fetch($id='', $ref='', $track_id='', $email_msgid='')
Load object in memory from the database.
loadCacheMsgsTicket()
Load the list of event on ticket into ->cache_msgs_ticket.
setProgression($percent)
Define progression of current ticket.
listeContact($status=-1, $source='external', $list=0, $code='')
Get array of all contacts for a ticket Override method of file commonobject.class....
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]]',...
searchContactByEmail($email, $socid='', $case='')
Search and fetch contacts by email.
getIdTicketCustomerInvolvedContact()
Return id des contacts clients des intervenants.
getInfosTicketInternalContact()
Retrieve informations about internal contacts.
copyFilesForTicket()
Copy files defined into $_SESSION array into the ticket directory of attached files.
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)
Mark a message as read.
load_state_board()
Load indicator this->nb of global stats widget.
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.
fetchAll($user, $sortorder='ASC', $sortfield='t.datec', $limit='', $offset=0, $arch='', $filter='')
Load all objects in memory from database.
setCustomer($id)
Define parent commany of current ticket.
markAsRead($user, $notrigger=0)
Mark a message as read.
getDefaultRef($thirdparty='')
Get a default reference.
sendTicketMessageByEmail($subject, $message, $send_internal_cc=0, $array_receiver=array(), $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array())
Send ticket by email to linked contacts.
const STATUS_NOT_READ
Status.
__construct($db)
Constructor.
getTicketAllCustomerContacts()
Return id of all contacts for ticket.
$category_label
Category label.
create($user, $notrigger=0)
Create object into database.
searchSocidByEmail($email, $type='0', $filters=array(), $clause='AND')
Search and fetch thirparties by email.
$severity_label
Severity label.
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).
$subject
var string Ticket subject
getIdTicketCustomerContact()
Return id des contacts clients pour le suivi ticket.
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.
getInfosTicketExternalContact()
Retrieve informations about external contacts.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
createTicketMessage($user, $notrigger=0, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $send_email=false)
Add message into database.
loadCacheCategoriesTickets()
Load into a cache array, the list of ticket categories (setup done into dictionary)
$category_code
Category code.
$fk_user_assign
User id who have ticket assigned.
$timing
Duration for ticket.
$category_label
Category label.
$severity_code
Severity code.
$track_id
Hash to identify ticket.
$progress
Progress in percent.
$date_close
Close ticket date.
$severity_label
Severity label.
$origin_email
Person email who have create ticket.
$resolution
State resolution.
$fk_user_create
User id who have create ticket.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_is_file($pathoffile)
Return if path is a file.
dol_is_dir($folder)
Test if filename is a directory.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
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)
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $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.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.
Class to generate the form for creating a new ticket.
$conf db
API class for accounts.
generate_random_id($car=16)
Generate a random id.