dolibarr  16.0.5
ticket.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2013-2018 Jean-François Ferry <hello@librethic.io>
3  * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
4  * Copyright (C) 2019-2020 Frédéric France <frederic.france@netlogic.fr>
5  * Copyright (C) 2020 Laurent Destailleur <eldy@users.sourceforge.net>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  */
20 
27 // Put here all includes required by your class file
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';
31 
32 
36 class Ticket extends CommonObject
37 {
41  public $element = 'ticket';
42 
46  public $table_element = 'ticket';
47 
51  public $fk_element = 'fk_ticket';
52 
56  public $ismultientitymanaged = 1;
57 
61  public $isextrafieldmanaged = 1;
62 
66  public $picto = 'ticket';
67 
68 
72  public $track_id;
73 
77  public $fk_soc;
78 
82  public $fk_project;
83 
87  public $origin_email;
88 
92  public $fk_user_create;
93 
97  public $fk_user_assign;
98 
102  public $subject;
103 
107  public $message;
108 
113  public $fk_statut;
114 
118  public $status;
119 
123  public $resolution;
124 
128  public $progress;
129 
133  public $timing;
134 
138  public $type_code;
139 
143  public $category_code;
144 
148  public $severity_code;
149 
153  public $type_label;
154 
159 
164 
168  public $email_from;
169 
173  public $datec = '';
174 
178  public $date_read = '';
179 
183  public $date_last_msg_sent = '';
184 
188  public $date_close = '';
189 
193  public $cache_types_tickets;
194 
198  public $cache_category_tickets;
199 
203  public $notify_tiers_at_create;
204 
208  public $email_msgid;
209 
210  public $lines;
211 
215  public $regeximgext = '\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff';
216 
220  const STATUS_NOT_READ = 0;
221  const STATUS_READ = 1;
222  const STATUS_ASSIGNED = 2;
223  const STATUS_IN_PROGRESS = 3;
224  const STATUS_NEED_MORE_INFO = 5;
225  const STATUS_WAITING = 7; // on hold
226  const STATUS_CLOSED = 8; // Closed - Solved
227  const STATUS_CANCELED = 9; // Closed - Not solved
228 
229 
256  // BEGIN MODULEBUILDER PROPERTIES
257  public $fields = array(
258  'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'position'=>1, 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id"),
259  'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'notnull'=>1, 'index'=>1),
260  '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),
261  'track_id' => array('type'=>'varchar(255)', 'label'=>'TicketTrackId', 'visible'=>-2, 'enabled'=>1, 'position'=>11, 'notnull'=>-1, 'searchall'=>1, 'help'=>"Help text"),
262  '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'),
263  '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'),
264  'subject' => array('type'=>'varchar(255)', 'label'=>'Subject', 'visible'=>1, 'enabled'=>1, 'position'=>18, 'notnull'=>-1, 'searchall'=>1, 'help'=>"", 'css'=>'maxwidth200 tdoverflowmax200', 'autofocusoncreate'=>1),
265  'type_code' => array('type'=>'varchar(32)', 'label'=>'Type', 'visible'=>1, 'enabled'=>1, 'position'=>20, 'notnull'=>-1, 'help'=>"", 'csslist'=>'maxwidth125 tdoverflowmax50'),
266  'category_code' => array('type'=>'varchar(32)', 'label'=>'TicketCategory', 'visible'=>-1, 'enabled'=>1, 'position'=>21, 'notnull'=>-1, 'help'=>"", 'css'=>'maxwidth100 tdoverflowmax200'),
267  'severity_code' => array('type'=>'varchar(32)', 'label'=>'Severity', 'visible'=>1, 'enabled'=>1, 'position'=>22, 'notnull'=>-1, 'help'=>"", 'css'=>'maxwidth100'),
268  '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'),
269  'notify_tiers_at_create' => array('type'=>'integer', 'label'=>'NotifyThirdparty', 'visible'=>-1, 'enabled'=>0, 'position'=>51, 'notnull'=>1, 'index'=>1),
270  '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"),
271  //'timing' => array('type'=>'varchar(20)', 'label'=>'Timing', 'visible'=>-1, 'enabled'=>1, 'position'=>42, 'notnull'=>-1, 'help'=>""), // what is this ?
272  'datec' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>1, 'enabled'=>1, 'position'=>500, 'notnull'=>1, 'csslist'=>'nowraponall'),
273  'date_read' => array('type'=>'datetime', 'label'=>'TicketReadOn', 'visible'=>-1, 'enabled'=>1, 'position'=>501, 'notnull'=>1),
274  'date_last_msg_sent' => array('type'=>'datetime', 'label'=>'TicketLastMessageDate', 'visible'=>0, 'enabled'=>1, 'position'=>502, 'notnull'=>-1),
275  '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'),
276  'date_close' => array('type'=>'datetime', 'label'=>'TicketCloseOn', 'visible'=>-1, 'enabled'=>1, 'position'=>510, 'notnull'=>1),
277  'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-1, 'enabled'=>1, 'position'=>520, 'notnull'=>1),
278  'message' => array('type'=>'text', 'label'=>'Message', 'visible'=>-2, 'enabled'=>1, 'position'=>540, 'notnull'=>-1,),
279  'email_msgid' => array('type'=>'varchar(255)', 'label'=>'EmailMsgID', 'visible'=>-2, 'enabled'=>1, 'position'=>540, 'notnull'=>-1, 'help'=>'EmailMsgIDDesc'),
280  'progress' => array('type'=>'integer', 'label'=>'Progression', 'visible'=>-1, 'enabled'=>1, 'position'=>540, 'notnull'=>-1, 'css'=>'right', 'help'=>"", 'isameasure'=>2, 'csslist'=>'width50'),
281  'resolution' => array('type'=>'integer', 'label'=>'Resolution', 'visible'=>-1, 'enabled'=>'$conf->global->TICKET_ENABLE_RESOLUTION', 'position'=>550, 'notnull'=>1),
282  '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')),
283  'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>900),
284  );
285  // END MODULEBUILDER PROPERTIES
286 
287 
293  public function __construct($db)
294  {
295  global $conf;
296 
297  $this->db = $db;
298 
299  $this->statuts_short = array(
300  self::STATUS_NOT_READ => 'Unread',
301  self::STATUS_READ => 'Read',
302  self::STATUS_ASSIGNED => 'Assigned',
303  self::STATUS_IN_PROGRESS => 'InProgress',
304  self::STATUS_WAITING => 'OnHold',
305  self::STATUS_NEED_MORE_INFO => 'NeedMoreInformationShort',
306  self::STATUS_CLOSED => 'SolvedClosed',
307  self::STATUS_CANCELED => 'Canceled'
308  );
309  $this->statuts = array(
310  self::STATUS_NOT_READ => 'Unread',
311  self::STATUS_READ => 'Read',
312  self::STATUS_ASSIGNED => 'Assigned',
313  self::STATUS_IN_PROGRESS => 'InProgress',
314  self::STATUS_WAITING => 'OnHold',
315  self::STATUS_NEED_MORE_INFO => 'NeedMoreInformation',
316  self::STATUS_CLOSED => 'SolvedClosed',
317  self::STATUS_CANCELED => 'Canceled'
318  );
319  }
320 
327  private function verify()
328  {
329  $this->errors = array();
330 
331  $result = 0;
332 
333  // Clean parameters
334  if (isset($this->ref)) {
335  $this->ref = trim($this->ref);
336  }
337 
338  if (isset($this->track_id)) {
339  $this->track_id = trim($this->track_id);
340  }
341 
342  if (isset($this->fk_soc)) {
343  $this->fk_soc = (int) $this->fk_soc;
344  }
345 
346  if (isset($this->fk_project)) {
347  $this->fk_project = (int) $this->fk_project;
348  }
349 
350  if (isset($this->origin_email)) {
351  $this->origin_email = trim($this->origin_email);
352  }
353 
354  if (isset($this->fk_user_create)) {
355  $this->fk_user_create = (int) $this->fk_user_create;
356  }
357 
358  if (isset($this->fk_user_assign)) {
359  $this->fk_user_assign = (int) $this->fk_user_assign;
360  }
361 
362  if (isset($this->subject)) {
363  $this->subject = trim($this->subject);
364  }
365 
366  if (isset($this->message)) {
367  $this->message = trim($this->message);
368  }
369 
370  if (isset($this->fk_statut)) {
371  $this->fk_statut = (int) $this->fk_statut;
372  }
373 
374  if (isset($this->resolution)) {
375  $this->resolution = trim($this->resolution);
376  }
377 
378  if (isset($this->progress)) {
379  $this->progress = trim($this->progress);
380  }
381 
382  if (isset($this->timing)) {
383  $this->timing = trim($this->timing);
384  }
385 
386  if (isset($this->type_code)) {
387  $this->type_code = trim($this->type_code);
388  }
389 
390  if (isset($this->category_code)) {
391  $this->category_code = trim($this->category_code);
392  }
393 
394  if (isset($this->severity_code)) {
395  $this->severity_code = trim($this->severity_code);
396  }
397 
398  if (empty($this->ref)) {
399  $this->errors[] = 'ErrorTicketRefRequired';
400  dol_syslog(get_class($this)."::create error -1 ref null", LOG_ERR);
401  $result = -1;
402  }
403 
404  return $result;
405  }
406 
414  public function create($user, $notrigger = 0)
415  {
416  global $conf, $langs;
417  $error = 0;
418 
419  // Clean parameters
420  $this->datec = dol_now();
421  if (empty($this->track_id)) {
422  $this->track_id = generate_random_id(16);
423  }
424 
425  // Check more parameters
426  // If error, this->errors[] is filled
427  $result = $this->verify();
428 
429  if ($result >= 0) {
430  // Insert request
431  $sql = "INSERT INTO ".MAIN_DB_PREFIX."ticket(";
432  $sql .= "ref,";
433  $sql .= "track_id,";
434  $sql .= "fk_soc,";
435  $sql .= "fk_project,";
436  $sql .= "origin_email,";
437  $sql .= "fk_user_create,";
438  $sql .= "fk_user_assign,";
439  $sql .= "email_msgid,";
440  $sql .= "subject,";
441  $sql .= "message,";
442  $sql .= "fk_statut,";
443  $sql .= "resolution,";
444  $sql .= "progress,";
445  $sql .= "timing,";
446  $sql .= "type_code,";
447  $sql .= "category_code,";
448  $sql .= "severity_code,";
449  $sql .= "datec,";
450  $sql .= "date_read,";
451  $sql .= "date_close,";
452  $sql .= "entity,";
453  $sql .= "notify_tiers_at_create";
454  $sql .= ") VALUES (";
455  $sql .= " ".(!isset($this->ref) ? '' : "'".$this->db->escape($this->ref)."'").",";
456  $sql .= " ".(!isset($this->track_id) ? 'NULL' : "'".$this->db->escape($this->track_id)."'").",";
457  $sql .= " ".($this->fk_soc > 0 ? $this->db->escape($this->fk_soc) : "null").",";
458  $sql .= " ".($this->fk_project > 0 ? $this->db->escape($this->fk_project) : "null").",";
459  $sql .= " ".(!isset($this->origin_email) ? 'NULL' : "'".$this->db->escape($this->origin_email)."'").",";
460  $sql .= " ".($this->fk_user_create > 0 ? $this->fk_user_create : ($user->id > 0 ? $user->id : 'NULL')).",";
461  $sql .= " ".($this->fk_user_assign > 0 ? $this->fk_user_assign : 'NULL').",";
462  $sql .= " ".(empty($this->email_msgid) ? 'NULL' : "'".$this->db->escape($this->email_msgid)."'").",";
463  $sql .= " ".(!isset($this->subject) ? 'NULL' : "'".$this->db->escape($this->subject)."'").",";
464  $sql .= " ".(!isset($this->message) ? 'NULL' : "'".$this->db->escape($this->message)."'").",";
465  $sql .= " ".(!isset($this->fk_statut) ? '0' : "'".$this->db->escape($this->fk_statut)."'").",";
466  $sql .= " ".(!isset($this->resolution) ? 'NULL' : "'".$this->db->escape($this->resolution)."'").",";
467  $sql .= " ".(!isset($this->progress) ? '0' : "'".$this->db->escape($this->progress)."'").",";
468  $sql .= " ".(!isset($this->timing) ? 'NULL' : "'".$this->db->escape($this->timing)."'").",";
469  $sql .= " ".(!isset($this->type_code) ? 'NULL' : "'".$this->db->escape($this->type_code)."'").",";
470  $sql .= " ".(empty($this->category_code) || $this->category_code == '-1' ? 'NULL' : "'".$this->db->escape($this->category_code)."'").",";
471  $sql .= " ".(!isset($this->severity_code) ? 'NULL' : "'".$this->db->escape($this->severity_code)."'").",";
472  $sql .= " ".(!isset($this->datec) || dol_strlen($this->datec) == 0 ? 'NULL' : "'".$this->db->idate($this->datec)."'").",";
473  $sql .= " ".(!isset($this->date_read) || dol_strlen($this->date_read) == 0 ? 'NULL' : "'".$this->db->idate($this->date_read)."'").",";
474  $sql .= " ".(!isset($this->date_close) || dol_strlen($this->date_close) == 0 ? 'NULL' : "'".$this->db->idate($this->date_close)."'")."";
475  $sql .= ", ".((int) $conf->entity);
476  $sql .= ", ".(!isset($this->notify_tiers_at_create) ? '1' : "'".$this->db->escape($this->notify_tiers_at_create)."'");
477  $sql .= ")";
478 
479  $this->db->begin();
480 
481  dol_syslog(get_class($this)."::create", LOG_DEBUG);
482  $resql = $this->db->query($sql);
483  if (!$resql) {
484  $error++;
485  $this->errors[] = "Error ".$this->db->lasterror();
486  }
487 
488  if (!$error) {
489  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."ticket");
490  }
491 
492  if (!$error && ! empty($conf->global->TICKET_ADD_AUTHOR_AS_CONTACT)) {
493  // add creator as contributor
494  if ($this->add_contact($user->id, 'CONTRIBUTOR', 'internal') < 0) {
495  $error++;
496  }
497  }
498 
499  if (!$error && $this->fk_user_assign > 0) {
500  if ($this->add_contact($this->fk_user_assign, 'SUPPORTTEC', 'internal') < 0) {
501  $error++;
502  }
503  }
504 
505 
506  //Update extrafield
507  if (!$error) {
508  $result = $this->insertExtraFields();
509  if ($result < 0) {
510  $error++;
511  }
512  }
513 
514  if (!$error && !$notrigger) {
515  // Call trigger
516  $result = $this->call_trigger('TICKET_CREATE', $user);
517  if ($result < 0) {
518  $error++;
519  }
520  // End call triggers
521  }
522 
523  // Commit or rollback
524  if ($error) {
525  foreach ($this->errors as $errmsg) {
526  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
527  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
528  }
529  $this->db->rollback();
530  return -1 * $error;
531  } else {
532  $this->db->commit();
533  return $this->id;
534  }
535  } else {
536  $this->db->rollback();
537  dol_syslog(get_class($this)."::Create fails verify ".join(',', $this->errors), LOG_WARNING);
538  return -3;
539  }
540  }
541 
551  public function fetch($id = '', $ref = '', $track_id = '', $email_msgid = '')
552  {
553  global $langs;
554 
555  // Check parameters
556  if (empty($id) && empty($ref) && empty($track_id) && empty($email_msgid)) {
557  $this->error = 'ErrorWrongParameters';
558  dol_print_error(get_class($this)."::fetch ".$this->error);
559  return -1;
560  }
561 
562  $sql = "SELECT";
563  $sql .= " t.rowid,";
564  $sql .= " t.entity,";
565  $sql .= " t.ref,";
566  $sql .= " t.track_id,";
567  $sql .= " t.fk_soc,";
568  $sql .= " t.fk_project,";
569  $sql .= " t.origin_email,";
570  $sql .= " t.fk_user_create,";
571  $sql .= " t.fk_user_assign,";
572  $sql .= " t.email_msgid,";
573  $sql .= " t.subject,";
574  $sql .= " t.message,";
575  $sql .= " t.fk_statut as status,";
576  $sql .= " t.resolution,";
577  $sql .= " t.progress,";
578  $sql .= " t.timing,";
579  $sql .= " t.type_code,";
580  $sql .= " t.category_code,";
581  $sql .= " t.severity_code,";
582  $sql .= " t.datec,";
583  $sql .= " t.date_read,";
584  $sql .= " t.date_last_msg_sent,";
585  $sql .= " t.date_close,";
586  $sql .= " t.tms,";
587  $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label";
588  $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
589  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
590  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code";
591  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code";
592 
593  if ($id) {
594  $sql .= " WHERE t.rowid = ".((int) $id);
595  } else {
596  $sql .= " WHERE t.entity IN (".getEntity($this->element, 1).")";
597  if (!empty($ref)) {
598  $sql .= " AND t.ref = '".$this->db->escape($ref)."'";
599  } elseif ($track_id) {
600  $sql .= " AND t.track_id = '".$this->db->escape($track_id)."'";
601  } else {
602  $sql .= " AND t.email_msgid = '".$this->db->escape($email_msgid)."'";
603  }
604  }
605 
606  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
607  $resql = $this->db->query($sql);
608  if ($resql) {
609  if ($this->db->num_rows($resql)) {
610  $obj = $this->db->fetch_object($resql);
611 
612  $this->id = $obj->rowid;
613  $this->entity = $obj->entity;
614  $this->ref = $obj->ref;
615  $this->track_id = $obj->track_id;
616  $this->fk_soc = $obj->fk_soc;
617  $this->socid = $obj->fk_soc; // for fetch_thirdparty() method
618  $this->fk_project = $obj->fk_project;
619  $this->origin_email = $obj->origin_email;
620  $this->fk_user_create = $obj->fk_user_create;
621  $this->fk_user_assign = $obj->fk_user_assign;
622  $this->email_msgid = $obj->email_msgid;
623  $this->subject = $obj->subject;
624  $this->message = $obj->message;
625 
626  $this->status = $obj->status;
627  $this->fk_statut = $this->status; // For backward compatibility
628 
629  $this->resolution = $obj->resolution;
630  $this->progress = $obj->progress;
631  $this->timing = $obj->timing;
632 
633  $this->type_code = $obj->type_code;
634  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
635  $label_type = ($langs->trans("TicketTypeShort".$obj->type_code) != ("TicketTypeShort".$obj->type_code) ? $langs->trans("TicketTypeShort".$obj->type_code) : ($obj->type_label != '-' ? $obj->type_label : ''));
636  $this->type_label = $label_type;
637 
638  $this->category_code = $obj->category_code;
639  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
640  $label_category = ($langs->trans("TicketCategoryShort".$obj->category_code) != ("TicketCategoryShort".$obj->category_code) ? $langs->trans("TicketCategoryShort".$obj->category_code) : ($obj->category_label != '-' ? $obj->category_label : ''));
641  $this->category_label = $label_category;
642 
643  $this->severity_code = $obj->severity_code;
644  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
645  $label_severity = ($langs->trans("TicketSeverityShort".$obj->severity_code) != ("TicketSeverityShort".$obj->severity_code) ? $langs->trans("TicketSeverityShort".$obj->severity_code) : ($obj->severity_label != '-' ? $obj->severity_label : ''));
646  $this->severity_label = $label_severity;
647 
648  $this->datec = $this->db->jdate($obj->datec);
649  $this->date_creation = $this->db->jdate($obj->datec);
650  $this->date_read = $this->db->jdate($obj->date_read);
651  $this->date_validation = $this->db->jdate($obj->date_read);
652  $this->date_last_msg_sent = $this->db->jdate($obj->date_last_msg_sent);
653  $this->date_close = $this->db->jdate($obj->date_close);
654  $this->tms = $this->db->jdate($obj->tms);
655  $this->date_modification = $this->db->jdate($obj->tms);
656 
657  $this->fetch_optionals();
658 
659  $this->db->free($resql);
660  return 1;
661  } else {
662  return 0;
663  }
664  } else {
665  $this->error = "Error ".$this->db->lasterror();
666  dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR);
667  return -1;
668  }
669  }
670 
684  public function fetchAll($user, $sortorder = 'ASC', $sortfield = 't.datec', $limit = '', $offset = 0, $arch = '', $filter = '')
685  {
686  global $langs;
687 
688  $extrafields = new ExtraFields($this->db);
689 
690  // fetch optionals attributes and labels
691  $extrafields->fetch_name_optionals_label($this->table_element);
692 
693  $sql = "SELECT";
694  $sql .= " t.rowid,";
695  $sql .= " t.ref,";
696  $sql .= " t.track_id,";
697  $sql .= " t.fk_soc,";
698  $sql .= " t.fk_project,";
699  $sql .= " t.origin_email,";
700  $sql .= " t.fk_user_create, uc.lastname as user_create_lastname, uc.firstname as user_create_firstname,";
701  $sql .= " t.fk_user_assign, ua.lastname as user_assign_lastname, ua.firstname as user_assign_firstname,";
702  $sql .= " t.subject,";
703  $sql .= " t.message,";
704  $sql .= " t.fk_statut,";
705  $sql .= " t.resolution,";
706  $sql .= " t.progress,";
707  $sql .= " t.timing,";
708  $sql .= " t.type_code,";
709  $sql .= " t.category_code,";
710  $sql .= " t.severity_code,";
711  $sql .= " t.datec,";
712  $sql .= " t.date_read,";
713  $sql .= " t.date_last_msg_sent,";
714  $sql .= " t.date_close,";
715  $sql .= " t.tms";
716  $sql .= ", type.label as type_label, category.label as category_label, severity.label as severity_label";
717  // Add fields for extrafields
718  foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
719  $sql .= ($extrafields->attributes[$this->table_element]['type'][$key] != 'separate' ? ",ef.".$key." as options_".$key : '');
720  }
721  $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t";
722  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_type as type ON type.code=t.type_code";
723  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_category as category ON category.code=t.category_code";
724  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_ticket_severity as severity ON severity.code=t.severity_code";
725  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=t.fk_soc";
726  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as uc ON uc.rowid=t.fk_user_create";
727  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as ua ON ua.rowid=t.fk_user_assign";
728  if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label'])) {
729  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."ticket_extrafields as ef on (t.rowid = ef.fk_object)";
730  }
731  if (empty($user->rights->societe->client->voir) && !$user->socid) {
732  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
733  }
734 
735  $sql .= " WHERE t.entity IN (".getEntity('ticket').")";
736 
737  // Manage filter
738  if (!empty($filter)) {
739  foreach ($filter as $key => $value) {
740  if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year
741  $sql .= " AND ".$key." = '".$this->db->escape($value)."'";
742  } elseif (($key == 't.fk_user_assign') || ($key == 't.type_code') || ($key == 't.category_code') || ($key == 't.severity_code') || ($key == 't.fk_soc')) {
743  $sql .= " AND ".$key." = '".$this->db->escape($value)."'";
744  } elseif ($key == 't.fk_statut') {
745  if (is_array($value) && count($value) > 0) {
746  $sql .= " AND ".$key." IN (".$this->db->sanitize(implode(',', $value)).")";
747  } else {
748  $sql .= " AND ".$key.' = '.((int) $value);
749  }
750  } else {
751  $sql .= " AND ".$key." LIKE '%".$this->db->escape($value)."%'";
752  }
753  }
754  }
755  if (empty($user->rights->societe->client->voir) && !$user->socid) {
756  $sql .= " AND t.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
757  } elseif ($user->socid) {
758  $sql .= " AND t.fk_soc = ".((int) $user->socid);
759  }
760 
761  $sql .= $this->db->order($sortfield, $sortorder);
762  if (!empty($limit)) {
763  $sql .= $this->db->plimit($limit + 1, $offset);
764  }
765 
766  dol_syslog(get_class($this)."::fetchAll", LOG_DEBUG);
767  $resql = $this->db->query($sql);
768 
769  if ($resql) {
770  $this->lines = array();
771 
772  $num = $this->db->num_rows($resql);
773  $i = 0;
774 
775  if ($num) {
776  while ($i < $num) {
777  $obj = $this->db->fetch_object($resql);
778 
779  $line = new TicketsLine();
780 
781  $line->id = $obj->rowid;
782  $line->rowid = $obj->rowid;
783  $line->ref = $obj->ref;
784  $line->track_id = $obj->track_id;
785  $line->fk_soc = $obj->fk_soc;
786  $line->fk_project = $obj->fk_project;
787  $line->origin_email = $obj->origin_email;
788 
789  $line->fk_user_create = $obj->fk_user_create;
790  $line->user_create_lastname = $obj->user_create_lastname;
791  $line->user_create_firstname = $obj->user_create_firstname;
792 
793  $line->fk_user_assign = $obj->fk_user_assign;
794  $line->user_assign_lastname = $obj->user_assign_lastname;
795  $line->user_assign_firstname = $obj->user_assign_firstname;
796 
797  $line->subject = $obj->subject;
798  $line->message = $obj->message;
799  $line->fk_statut = $obj->fk_statut;
800  $line->resolution = $obj->resolution;
801  $line->progress = $obj->progress;
802  $line->timing = $obj->timing;
803 
804  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
805  $label_type = ($langs->trans("TicketTypeShort".$obj->type_code) != ("TicketTypeShort".$obj->type_code) ? $langs->trans("TicketTypeShort".$obj->type_code) : ($obj->type_label != '-' ? $obj->type_label : ''));
806  $line->type_label = $label_type;
807 
808  $this->category_code = $obj->category_code;
809  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
810  $label_category = ($langs->trans("TicketCategoryShort".$obj->category_code) != ("TicketCategoryShort".$obj->category_code) ? $langs->trans("TicketCategoryShort".$obj->category_code) : ($obj->category_label != '-' ? $obj->category_label : ''));
811  $line->category_label = $label_category;
812 
813  $this->severity_code = $obj->severity_code;
814  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
815  $label_severity = ($langs->trans("TicketSeverityShort".$obj->severity_code) != ("TicketSeverityShort".$obj->severity_code) ? $langs->trans("TicketSeverityShort".$obj->severity_code) : ($obj->severity_label != '-' ? $obj->severity_label : ''));
816  $line->severity_label = $label_severity;
817 
818  $line->datec = $this->db->jdate($obj->datec);
819  $line->date_read = $this->db->jdate($obj->date_read);
820  $line->date_last_msg_sent = $this->db->jdate($obj->date_last_msg_sent);
821  $line->date_close = $this->db->jdate($obj->date_close);
822 
823  // Extra fields
824  if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label'])) {
825  foreach ($extrafields->attributes[$this->table_element]['label'] as $key => $val) {
826  $tmpkey = 'options_'.$key;
827  $line->{$tmpkey} = $obj->$tmpkey;
828  }
829  }
830 
831  $this->lines[$i] = $line;
832  $i++;
833  }
834  }
835  $this->db->free($resql);
836  return $num;
837  } else {
838  $this->error = "Error ".$this->db->lasterror();
839  dol_syslog(get_class($this)."::fetchAll ".$this->error, LOG_ERR);
840  return -1;
841  }
842  }
843 
851  public function update($user = 0, $notrigger = 0)
852  {
853  global $conf, $langs, $hookmanager;
854  $error = 0;
855 
856  // Clean parameters
857  if (isset($this->ref)) {
858  $this->ref = trim($this->ref);
859  }
860 
861  if (isset($this->track_id)) {
862  $this->track_id = trim($this->track_id);
863  }
864 
865  if (isset($this->fk_soc)) {
866  $this->fk_soc = (int) $this->fk_soc;
867  }
868 
869  if (isset($this->fk_project)) {
870  $this->fk_project = (int) $this->fk_project;
871  }
872 
873  if (isset($this->origin_email)) {
874  $this->origin_email = trim($this->origin_email);
875  }
876 
877  if (isset($this->fk_user_create)) {
878  $this->fk_user_create = (int) $this->fk_user_create;
879  }
880 
881  if (isset($this->fk_user_assign)) {
882  $this->fk_user_assign = (int) $this->fk_user_assign;
883  }
884 
885  if (isset($this->subject)) {
886  $this->subject = trim($this->subject);
887  }
888 
889  if (isset($this->message)) {
890  $this->message = trim($this->message);
891  }
892 
893  if (isset($this->fk_statut)) {
894  $this->fk_statut = (int) $this->fk_statut;
895  }
896 
897  if (isset($this->resolution)) {
898  $this->resolution = trim($this->resolution);
899  }
900 
901  if (isset($this->progress)) {
902  $this->progress = trim($this->progress);
903  }
904 
905  if (isset($this->timing)) {
906  $this->timing = trim($this->timing);
907  }
908 
909  if (isset($this->type_code)) {
910  $this->timing = trim($this->type_code);
911  }
912 
913  if (isset($this->category_code)) {
914  $this->timing = trim($this->category_code);
915  }
916 
917  if (isset($this->severity_code)) {
918  $this->timing = trim($this->severity_code);
919  }
920 
921  // Check parameters
922  // Put here code to add a control on parameters values
923  // Update request
924  $sql = "UPDATE ".MAIN_DB_PREFIX."ticket SET";
925  $sql .= " ref=".(isset($this->ref) ? "'".$this->db->escape($this->ref)."'" : "").",";
926  $sql .= " track_id=".(isset($this->track_id) ? "'".$this->db->escape($this->track_id)."'" : "null").",";
927  $sql .= " fk_soc=".(isset($this->fk_soc) ? "'".$this->db->escape($this->fk_soc)."'" : "null").",";
928  $sql .= " fk_project=".(isset($this->fk_project) ? "'".$this->db->escape($this->fk_project)."'" : "null").",";
929  $sql .= " origin_email=".(isset($this->origin_email) ? "'".$this->db->escape($this->origin_email)."'" : "null").",";
930  $sql .= " fk_user_create=".(isset($this->fk_user_create) ? $this->fk_user_create : "null").",";
931  $sql .= " fk_user_assign=".(isset($this->fk_user_assign) ? $this->fk_user_assign : "null").",";
932  $sql .= " subject=".(isset($this->subject) ? "'".$this->db->escape($this->subject)."'" : "null").",";
933  $sql .= " message=".(isset($this->message) ? "'".$this->db->escape($this->message)."'" : "null").",";
934  $sql .= " fk_statut=".(isset($this->fk_statut) ? $this->fk_statut : "null").",";
935  $sql .= " resolution=".(isset($this->resolution) ? $this->resolution : "null").",";
936  $sql .= " progress=".(isset($this->progress) ? "'".$this->db->escape($this->progress)."'" : "null").",";
937  $sql .= " timing=".(isset($this->timing) ? "'".$this->db->escape($this->timing)."'" : "null").",";
938  $sql .= " type_code=".(isset($this->type_code) ? "'".$this->db->escape($this->type_code)."'" : "null").",";
939  $sql .= " category_code=".(isset($this->category_code) ? "'".$this->db->escape($this->category_code)."'" : "null").",";
940  $sql .= " severity_code=".(isset($this->severity_code) ? "'".$this->db->escape($this->severity_code)."'" : "null").",";
941  $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
942  $sql .= " date_read=".(dol_strlen($this->date_read) != 0 ? "'".$this->db->idate($this->date_read)."'" : 'null').",";
943  $sql .= " date_last_msg_sent=".(dol_strlen($this->date_last_msg_sent) != 0 ? "'".$this->db->idate($this->date_last_msg_sent)."'" : 'null').",";
944  $sql .= " date_close=".(dol_strlen($this->date_close) != 0 ? "'".$this->db->idate($this->date_close)."'" : 'null')."";
945  $sql .= " WHERE rowid=".((int) $this->id);
946 
947  $this->db->begin();
948 
949  $resql = $this->db->query($sql);
950  if (!$resql) {
951  $error++;
952  $this->errors[] = "Error ".$this->db->lasterror();
953  }
954 
955  if (!$error) {
956  // Update extrafields
957  $result = $this->insertExtraFields();
958  if ($result < 0) {
959  $error++;
960  }
961  }
962 
963  if (!$error && !$notrigger) {
964  // Call trigger
965  $result = $this->call_trigger('TICKET_MODIFY', $user);
966  if ($result < 0) {
967  $error++;
968  }
969  // End call triggers
970  }
971 
972  // Commit or rollback
973  if ($error) {
974  foreach ($this->errors as $errmsg) {
975  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
976  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
977  }
978  $this->db->rollback();
979  return -1 * $error;
980  } else {
981  $this->db->commit();
982  return 1;
983  }
984  }
985 
993  public function delete($user, $notrigger = 0)
994  {
995  global $conf, $langs;
996  $error = 0;
997 
998  $this->db->begin();
999 
1000  if (!$error) {
1001  if (!$notrigger) {
1002  // Call trigger
1003  $result = $this->call_trigger('TICKET_DELETE', $user);
1004  if ($result < 0) {
1005  $error++;
1006  }
1007  // End call triggers
1008  }
1009  }
1010 
1011  if (!$error) {
1012  // Delete linked contacts
1013  $res = $this->delete_linked_contact();
1014  if ($res < 0) {
1015  dol_syslog(get_class($this)."::delete error", LOG_ERR);
1016  $error++;
1017  }
1018  }
1019 
1020  if (!$error) {
1021  // Delete linked object
1022  $res = $this->deleteObjectLinked();
1023  if ($res < 0) {
1024  $error++;
1025  }
1026  }
1027 
1028  // Removed extrafields
1029  if (!$error) {
1030  $result = $this->deleteExtraFields();
1031  if ($result < 0) {
1032  $error++;
1033  dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
1034  }
1035  }
1036 
1037  // Delete all child tables
1038 
1039  if (!$error) {
1040  $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_ticket";
1041  $sql .= " WHERE fk_ticket = ".(int) $this->id;
1042 
1043  $result = $this->db->query($sql);
1044  if (!$result) {
1045  $error++;
1046  $this->errors[] = $this->db->lasterror();
1047  }
1048  }
1049 
1050  if (!$error) {
1051  $sql = "DELETE FROM ".MAIN_DB_PREFIX."ticket";
1052  $sql .= " WHERE rowid=".((int) $this->id);
1053 
1054  dol_syslog(get_class($this)."::delete sql=".$sql);
1055  $resql = $this->db->query($sql);
1056  if (!$resql) {
1057  $error++;
1058  $this->errors[] = "Error ".$this->db->lasterror();
1059  }
1060  }
1061 
1062  // Commit or rollback
1063  if ($error) {
1064  foreach ($this->errors as $errmsg) {
1065  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
1066  $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
1067  }
1068  $this->db->rollback();
1069  return -1 * $error;
1070  } else {
1071  $this->db->commit();
1072  return 1;
1073  }
1074  }
1075 
1083  public function createFromClone(User $user, $fromid)
1084  {
1085  $error = 0;
1086 
1087  $object = new Ticket($this->db);
1088 
1089  $this->db->begin();
1090 
1091  // Load source object
1092  $object->fetch($fromid);
1093  $object->id = 0;
1094  $object->statut = 0;
1095 
1096  // Clear fields
1097  // ...
1098  // Create clone
1099  $object->context['createfromclone'] = 'createfromclone';
1100  $result = $object->create($user);
1101 
1102  // Other options
1103  if ($result < 0) {
1104  $this->error = $object->error;
1105  $error++;
1106  }
1107 
1108  if (!$error) {
1109  }
1110 
1111  unset($object->context['createfromclone']);
1112 
1113  // End
1114  if (!$error) {
1115  $this->db->commit();
1116  return $object->id;
1117  } else {
1118  $this->db->rollback();
1119  return -1;
1120  }
1121  }
1122 
1129  public function initAsSpecimen()
1130  {
1131  $this->id = 0;
1132  $this->entity = 1;
1133  $this->ref = 'TI0501-001';
1134  $this->track_id = 'XXXXaaaa';
1135  $this->origin_email = 'email@email.com';
1136  $this->fk_project = 1;
1137  $this->fk_user_create = 1;
1138  $this->fk_user_assign = 1;
1139  $this->subject = 'Subject of ticket';
1140  $this->message = 'Message of ticket';
1141  $this->status = 0;
1142  $this->resolution = '1';
1143  $this->progress = '10';
1144  //$this->timing = '30';
1145  $this->type_code = 'TYPECODE';
1146  $this->category_code = 'CATEGORYCODE';
1147  $this->severity_code = 'SEVERITYCODE';
1148  $this->datec = '';
1149  $this->date_read = '';
1150  $this->date_last_msg_sent = '';
1151  $this->date_close = '';
1152  $this->tms = '';
1153  return 1;
1154  }
1155 
1162  public function printSelectStatus($selected = "")
1163  {
1164  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 = '');
1165  }
1166 
1167 
1173  public function loadCacheTypesTickets()
1174  {
1175  global $langs;
1176 
1177  if (!empty($this->cache_types_tickets) && count($this->cache_types_tickets)) {
1178  return 0;
1179  }
1180  // Cache deja charge
1181 
1182  $sql = "SELECT rowid, code, label, use_default, pos, description";
1183  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_type";
1184  $sql .= " WHERE active > 0";
1185  $sql .= " ORDER BY pos";
1186  dol_syslog(get_class($this)."::load_cache_type_tickets", LOG_DEBUG);
1187  $resql = $this->db->query($sql);
1188  if ($resql) {
1189  $num = $this->db->num_rows($resql);
1190  $i = 0;
1191  while ($i < $num) {
1192  $obj = $this->db->fetch_object($resql);
1193  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
1194  $label = ($langs->trans("TicketTypeShort".$obj->code) != ("TicketTypeShort".$obj->code) ? $langs->trans("TicketTypeShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
1195  $this->cache_types_tickets[$obj->rowid]['code'] = $obj->code;
1196  $this->cache_types_tickets[$obj->rowid]['label'] = $label;
1197  $this->cache_types_tickets[$obj->rowid]['use_default'] = $obj->use_default;
1198  $this->cache_types_tickets[$obj->rowid]['pos'] = $obj->pos;
1199  $i++;
1200  }
1201  return $num;
1202  } else {
1203  dol_print_error($this->db);
1204  return -1;
1205  }
1206  }
1207 
1213  public function loadCacheCategoriesTickets()
1214  {
1215  global $conf, $langs;
1216 
1217  if (!empty($this->cache_category_ticket) && count($this->cache_category_tickets)) {
1218  // Cache already loaded
1219  return 0;
1220  }
1221 
1222  $sql = "SELECT rowid, code, label, use_default, pos, description, public, active, force_severity, fk_parent";
1223  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category";
1224  $sql .= " WHERE active > 0 AND entity = ".((int) $conf->entity);
1225  $sql .= " ORDER BY pos";
1226  dol_syslog(get_class($this)."::load_cache_categories_tickets", LOG_DEBUG);
1227  $resql = $this->db->query($sql);
1228  if ($resql) {
1229  $num = $this->db->num_rows($resql);
1230  $i = 0;
1231  while ($i < $num) {
1232  $obj = $this->db->fetch_object($resql);
1233  $this->cache_category_tickets[$obj->rowid]['code'] = $obj->code;
1234  $this->cache_category_tickets[$obj->rowid]['use_default'] = $obj->use_default;
1235  $this->cache_category_tickets[$obj->rowid]['pos'] = $obj->pos;
1236  $this->cache_category_tickets[$obj->rowid]['public'] = $obj->public;
1237  $this->cache_category_tickets[$obj->rowid]['active'] = $obj->active;
1238  $this->cache_category_tickets[$obj->rowid]['force_severity'] = $obj->force_severity;
1239  $this->cache_category_tickets[$obj->rowid]['fk_parent'] = $obj->fk_parent;
1240 
1241  // If translation exists, we use it to store already translated string.
1242  // Warning: You should not use this and recompute the translated string into caller code to get the value into expected language
1243  $label = ($langs->trans("TicketCategoryShort".$obj->code) != ("TicketCategoryShort".$obj->code) ? $langs->trans("TicketCategoryShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
1244  $this->cache_category_tickets[$obj->rowid]['label'] = $label;
1245 
1246  $i++;
1247  }
1248  return $num;
1249  } else {
1250  dol_print_error($this->db);
1251  return -1;
1252  }
1253  }
1254 
1260  public function loadCacheSeveritiesTickets()
1261  {
1262  global $langs;
1263 
1264  if (!empty($this->cache_severity_tickets) && count($this->cache_severity_tickets)) {
1265  return 0;
1266  }
1267  // Cache deja charge
1268 
1269  $sql = "SELECT rowid, code, label, use_default, pos, description";
1270  $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity";
1271  $sql .= " WHERE active > 0";
1272  $sql .= " ORDER BY pos";
1273  dol_syslog(get_class($this)."::loadCacheSeveritiesTickets", LOG_DEBUG);
1274  $resql = $this->db->query($sql);
1275  if ($resql) {
1276  $num = $this->db->num_rows($resql);
1277  $i = 0;
1278  while ($i < $num) {
1279  $obj = $this->db->fetch_object($resql);
1280 
1281  $this->cache_severity_tickets[$obj->rowid]['code'] = $obj->code;
1282  // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
1283  $label = ($langs->trans("TicketSeverityShort".$obj->code) != ("TicketSeverityShort".$obj->code) ? $langs->trans("TicketSeverityShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
1284  $this->cache_severity_tickets[$obj->rowid]['label'] = $label;
1285  $this->cache_severity_tickets[$obj->rowid]['use_default'] = $obj->use_default;
1286  $this->cache_severity_tickets[$obj->rowid]['pos'] = $obj->pos;
1287  $i++;
1288  }
1289  return $num;
1290  } else {
1291  dol_print_error($this->db);
1292  return -1;
1293  }
1294  }
1295 
1296 
1303  public function getLibStatut($mode = 0)
1304  {
1305  return $this->libStatut($this->fk_statut, $mode, 0, $this->progress);
1306  }
1307 
1308 
1309  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
1319  public function LibStatut($status, $mode = 0, $notooltip = 0, $progress = 0)
1320  {
1321  // phpcs:enable
1322  global $langs, $hookmanager;
1323 
1324  $labelStatus = $this->statuts[$status];
1325  $labelStatusShort = $this->statuts_short[$status];
1326 
1327  if ($status == self::STATUS_NOT_READ) {
1328  $statusType = 'status0';
1329  } elseif ($status == self::STATUS_READ) {
1330  $statusType = 'status1';
1331  } elseif ($status == self::STATUS_ASSIGNED) {
1332  $statusType = 'status2';
1333  } elseif ($status == self::STATUS_IN_PROGRESS) {
1334  $statusType = 'status4';
1335  } elseif ($status == self::STATUS_WAITING) {
1336  $statusType = 'status7';
1337  } elseif ($status == self::STATUS_NEED_MORE_INFO) {
1338  $statusType = 'status3';
1339  } elseif ($status == self::STATUS_CANCELED) {
1340  $statusType = 'status9';
1341  } elseif ($status == self::STATUS_CLOSED) {
1342  $statusType = 'status6';
1343  } else {
1344  $labelStatus = 'Unknown';
1345  $labelStatusShort = 'Unknown';
1346  $statusType = 'status0';
1347  $mode = 0;
1348  }
1349 
1350  $parameters = array(
1351  'status' => $status,
1352  'mode' => $mode,
1353  );
1354 
1355  // Note that $action and $object may have been modified by hook
1356  $reshook = $hookmanager->executeHooks('LibStatut', $parameters, $this);
1357 
1358  if ($reshook > 0) {
1359  return $hookmanager->resPrint;
1360  }
1361 
1362  $params = array();
1363  if ($notooltip) {
1364  $params = array('tooltip' => 'no');
1365  }
1366 
1367  $labelStatus = $langs->transnoentitiesnoconv($labelStatus);
1368  $labelStatusShort = $langs->transnoentitiesnoconv($labelStatusShort);
1369 
1370  if ($status == self::STATUS_IN_PROGRESS && $progress > 0) {
1371  $labelStatus .= ' ('.round($progress).'%)';
1372  $labelStatusShort .= ' ('.round($progress).'%)';
1373  }
1374 
1375  return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode, '', $params);
1376  }
1377 
1378 
1389  public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
1390  {
1391  global $db, $conf, $langs;
1392  global $dolibarr_main_authentication, $dolibarr_main_demo;
1393  global $menumanager;
1394 
1395  if (!empty($conf->dol_no_mouse_hover)) {
1396  $notooltip = 1; // Force disable tooltips
1397  }
1398 
1399  $result = '';
1400 
1401  $label = img_picto('', $this->picto).' <u class="paddingrightonly">'.$langs->trans("Ticket").'</u>';
1402  $label .= ' '.$this->getLibStatut(4);
1403  $label .= '<br>';
1404  $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref.'<br>';
1405  $label .= '<b>'.$langs->trans('TicketTrackId').':</b> '.$this->track_id.'<br>';
1406  $label .= '<b>'.$langs->trans('Subject').':</b> '.$this->subject;
1407  if ($this->date_creation) {
1408  $label .= '<br><b>'.$langs->trans('DateCreation').':</b> '.$this->date_creation;
1409  }
1410  if ($this->date_modification) {
1411  $label .= '<br><b>'.$langs->trans('DateModification').':</b> '.$this->date_modification;
1412  }
1413  $url = DOL_URL_ROOT.'/ticket/card.php?id='.$this->id;
1414 
1415  if ($option != 'nolink') {
1416  // Add param to save lastsearch_values or not
1417  $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1418  if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
1419  $add_save_lastsearch_values = 1;
1420  }
1421  if ($add_save_lastsearch_values) {
1422  $url .= '&save_lastsearch_values=1';
1423  }
1424  }
1425 
1426  $linkclose = '';
1427  if (empty($notooltip)) {
1428  if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
1429  $label = $langs->trans("ShowTicket");
1430  $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
1431  }
1432  $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
1433  $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
1434  } else {
1435  $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
1436  }
1437 
1438  $linkstart = '<a href="'.$url.'"';
1439  $linkstart .= $linkclose.'>';
1440  $linkend = '</a>';
1441 
1442  $result .= $linkstart;
1443  if ($withpicto) {
1444  $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);
1445  }
1446  if ($withpicto != 2) {
1447  $result .= $this->ref;
1448  }
1449  $result .= $linkend;
1450  //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
1451 
1452  return $result;
1453  }
1454 
1455 
1463  public function markAsRead($user, $notrigger = 0)
1464  {
1465  global $conf, $langs;
1466 
1467  $error = 0;
1468 
1469  if ($this->statut != self::STATUS_CANCELED) { // no closed
1470  $this->db->begin();
1471 
1472  $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
1473  $sql .= " SET fk_statut = ".Ticket::STATUS_READ.", date_read='".$this->db->idate(dol_now())."'";
1474  $sql .= " WHERE rowid = ".((int) $this->id);
1475 
1476  dol_syslog(get_class($this)."::markAsRead");
1477  $resql = $this->db->query($sql);
1478  if ($resql) {
1479  $this->actionmsg = $langs->trans('TicketLogMesgReadBy', $this->ref, $user->getFullName($langs));
1480  $this->actionmsg2 = $langs->trans('TicketLogMesgReadBy', $this->ref, $user->getFullName($langs));
1481 
1482  if (!$error && !$notrigger) {
1483  // Call trigger
1484  $result = $this->call_trigger('TICKET_MODIFY', $user);
1485  if ($result < 0) {
1486  $error++;
1487  }
1488  // End call triggers
1489  }
1490 
1491  if (!$error) {
1492  $this->db->commit();
1493  return 1;
1494  } else {
1495  $this->db->rollback();
1496  $this->error = join(',', $this->errors);
1497  dol_syslog(get_class($this)."::markAsRead ".$this->error, LOG_ERR);
1498  return -1;
1499  }
1500  } else {
1501  $this->db->rollback();
1502  $this->error = $this->db->lasterror();
1503  dol_syslog(get_class($this)."::markAsRead ".$this->error, LOG_ERR);
1504  return -1;
1505  }
1506  }
1507  }
1508 
1517  public function assignUser($user, $id_assign_user, $notrigger = 0)
1518  {
1519  global $conf, $langs;
1520 
1521  $error = 0;
1522  $this->db->begin();
1523 
1524  $this->oldcopy = dol_clone($this);
1525 
1526  $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
1527  if ($id_assign_user > 0) {
1528  $sql .= " SET fk_user_assign=".((int) $id_assign_user).", fk_statut = ".Ticket::STATUS_ASSIGNED;
1529  } else {
1530  $sql .= " SET fk_user_assign=null, fk_statut = ".Ticket::STATUS_READ;
1531  }
1532  $sql .= " WHERE rowid = ".((int) $this->id);
1533 
1534  dol_syslog(get_class($this)."::assignUser sql=".$sql);
1535  $resql = $this->db->query($sql);
1536  if ($resql) {
1537  $this->fk_user_assign = $id_assign_user; // May be used by trigger
1538 
1539  if (!$notrigger) {
1540  // Call trigger
1541  $result = $this->call_trigger('TICKET_ASSIGNED', $user);
1542  if ($result < 0) {
1543  $error++;
1544  }
1545  // End call triggers
1546  }
1547 
1548  if (!$error) {
1549  $this->db->commit();
1550  return 1;
1551  } else {
1552  $this->db->rollback();
1553  $this->error = join(',', $this->errors);
1554  dol_syslog(get_class($this)."::assignUser ".$this->error, LOG_ERR);
1555  return -1;
1556  }
1557  } else {
1558  $this->db->rollback();
1559  $this->error = $this->db->lasterror();
1560  dol_syslog(get_class($this)."::assignUser ".$this->error, LOG_ERR);
1561  return -1;
1562  }
1563  }
1564 
1565 
1573  private function sendLogByEmail($user, $message)
1574  {
1575  global $conf, $langs;
1576 
1577  $nb_sent = 0;
1578 
1579  $langs->load('ticket');
1580 
1581  // Retrieve email of all contacts (internal and external)
1582  $contacts = $this->listeContact(-1, 'internal');
1583  $contacts = array_merge($contacts, $this->listeContact(-1, 'external'));
1584 
1585  /* If origin_email and no socid, we add email to the list * */
1586  if (!empty($this->origin_email) && empty($this->fk_soc)) {
1587  $array_ext = array(array('firstname' => '', 'lastname' => '', 'email' => $this->origin_email, 'libelle' => $langs->transnoentities('TicketEmailOriginIssuer'), 'socid' => "-1"));
1588  $contacts = array_merge($contacts, $array_ext);
1589  }
1590 
1591  if (!empty($this->fk_soc)) {
1592  $this->fetch_thirdparty($this->fk_soc);
1593  $array_company = array(array('firstname' => '', 'lastname' => $this->client->name, 'email' => $this->client->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $this->client->id));
1594  $contacts = array_merge($contacts, $array_company);
1595  }
1596 
1597  // foreach contact send email with notification message
1598  if (count($contacts) > 0) {
1599  foreach ($contacts as $key => $info_sendto) {
1600  $message = '';
1601  $subject = '['.$conf->global->MAIN_INFO_SOCIETE_NOM.'] '.$langs->transnoentities('TicketNotificationEmailSubject', $this->track_id);
1602  $message .= $langs->transnoentities('TicketNotificationEmailBody', $this->track_id)."\n\n";
1603  $message .= $langs->transnoentities('Title').' : '.$this->subject."\n";
1604 
1605  $recipient_name = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1');
1606  $recipient = (!empty($recipient_name) ? $recipient_name : $info_sendto['email']).' ('.strtolower($info_sendto['libelle']).')';
1607  $message .= $langs->transnoentities('TicketNotificationRecipient').' : '.$recipient."\n";
1608  $message .= "\n";
1609  $message .= '* '.$langs->transnoentities('TicketNotificationLogMessage').' *'."\n";
1610  $message .= dol_html_entity_decode($log_message, ENT_QUOTES | ENT_HTML5)."\n";
1611 
1612  if ($info_sendto['source'] == 'internal') {
1613  $url_internal_ticket = dol_buildpath('/ticket/card.php', 2).'?track_id='.$this->track_id;
1614  $message .= "\n".$langs->transnoentities('TicketNotificationEmailBodyInfosTrackUrlinternal').' : <a href="'.$url_internal_ticket.'">'.$this->track_id.'</a>'."\n";
1615  } else {
1616  $url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.'/view.php' : dol_buildpath('/public/ticket/view.php', 2)).'?track_id='.$this->track_id;
1617  $message .= "\n".$langs->transnoentities('TicketNewEmailBodyInfosTrackUrlCustomer').' : <a href="'.$url_public_ticket.'">'.$this->track_id.'</a>'."\n";
1618  }
1619 
1620  $message .= "\n";
1621  $message .= $langs->transnoentities('TicketEmailPleaseDoNotReplyToThisEmail')."\n";
1622 
1623  $from = $conf->global->MAIN_INFO_SOCIETE_NOM.'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.'>';
1624  $replyto = $from;
1625 
1626  // Init to avoid errors
1627  $filepath = array();
1628  $filename = array();
1629  $mimetype = array();
1630 
1631  $message = dol_nl2br($message);
1632 
1633  if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
1634  $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
1635  $conf->global->MAIN_MAIL_AUTOCOPY_TO = '';
1636  }
1637  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
1638  $sendtocc = '';
1639  $deliveryreceipt = 0;
1640  $mailfile = new CMailFile($subject, $info_sendto['email'], $from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, 0);
1641  if ($mailfile->error || $mailfile->errors) {
1642  setEventMessages($mailfile->error, $mailfile->errors, 'errors');
1643  } else {
1644  $result = $mailfile->sendfile();
1645  if ($result > 0) {
1646  $nb_sent++;
1647  }
1648  }
1649  if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
1650  $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
1651  }
1652  }
1653 
1654  setEventMessages($langs->trans('TicketNotificationNumberEmailSent', $nb_sent), null, 'mesgs');
1655  }
1656 
1657  return $nb_sent;
1658  }
1659 
1665  public function loadCacheLogsTicket()
1666  {
1667  global $langs;
1668 
1669  if (is_array($this->cache_logs_ticket) && count($this->cache_logs_ticket)) {
1670  return 0;
1671  }
1672  // Cache deja charge
1673 
1674  // TODO Read the table llx_actioncomm
1675  /*
1676  $sql = "SELECT rowid, fk_user_create, datec, message";
1677  $sql .= " FROM " . MAIN_DB_PREFIX . "ticket_logs";
1678  $sql .= " WHERE fk_track_id ='" . $this->db->escape($this->track_id) . "'";
1679  $sql .= " ORDER BY datec DESC";
1680 
1681  $resql = $this->db->query($sql);
1682  if ($resql) {
1683  $num = $this->db->num_rows($resql);
1684  $i = 0;
1685  while ($i < $num) {
1686  $obj = $this->db->fetch_object($resql);
1687  $this->cache_logs_ticket[$i]['id'] = $obj->rowid;
1688  $this->cache_logs_ticket[$i]['fk_user_create'] = $obj->fk_user_create;
1689  $this->cache_logs_ticket[$i]['datec'] = $this->db->jdate($obj->datec);
1690  $this->cache_logs_ticket[$i]['message'] = $obj->message;
1691  $i++;
1692  }
1693  return $num;
1694  } else {
1695  $this->error = "Error " . $this->db->lasterror();
1696  dol_syslog(get_class($this) . "::loadCacheLogsTicket " . $this->error, LOG_ERR);
1697  return -1;
1698  }*/
1699 
1700  return 0;
1701  }
1702 
1713  public function createTicketMessage($user, $notrigger = 0, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
1714  {
1715  global $conf, $langs;
1716  $error = 0;
1717 
1718  $now = dol_now();
1719 
1720  // Clean parameters
1721  if (isset($this->fk_track_id)) {
1722  $this->fk_track_id = trim($this->fk_track_id);
1723  }
1724 
1725  if (isset($this->message)) {
1726  $this->message = trim($this->message);
1727  }
1728 
1729  $this->db->begin();
1730 
1731  // Insert entry into agenda with code 'TICKET_MSG'
1732  include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
1733  $actioncomm = new ActionComm($this->db);
1734  $actioncomm->type_code = 'AC_OTH';
1735  $actioncomm->code = 'TICKET_MSG';
1736  if ($this->private) {
1737  $actioncomm->code = 'TICKET_MSG_PRIVATE';
1738  }
1739  $actioncomm->socid = $this->socid;
1740  $actioncomm->label = $this->subject;
1741  $actioncomm->note_private = $this->message;
1742  $actioncomm->userassigned = array($user->id);
1743  $actioncomm->userownerid = $user->id;
1744  $actioncomm->datep = $now;
1745  $actioncomm->percentage = -1; // percentage is not relevant for punctual events
1746  $actioncomm->elementtype = 'ticket';
1747  $actioncomm->fk_element = $this->id;
1748 
1749  $attachedfiles = array();
1750  $attachedfiles['paths'] = $filename_list;
1751  $attachedfiles['names'] = $mimefilename_list;
1752  $attachedfiles['mimes'] = $mimetype_list;
1753  if (is_array($attachedfiles) && count($attachedfiles) > 0) {
1754  $actioncomm->attachedfiles = $attachedfiles;
1755  }
1756 
1757  if (!empty($mimefilename_list) && is_array($mimefilename_list)) {
1758  $actioncomm->note_private = dol_concatdesc($actioncomm->note_private, "\n".$langs->transnoentities("AttachedFiles").': '.join(';', $mimefilename_list));
1759  }
1760 
1761  $actionid = $actioncomm->create($user);
1762  if ($actionid <= 0) {
1763  $error++;
1764  $this->error = $actioncomm->error;
1765  $this->errors = $actioncomm->errors;
1766  }
1767 
1768  // Commit or rollback
1769  if ($error) {
1770  $this->db->rollback();
1771  return -1 * $error;
1772  } else {
1773  $this->db->commit();
1774  return 1;
1775  }
1776  }
1777 
1783  public function loadCacheMsgsTicket()
1784  {
1785  if (is_array($this->cache_msgs_ticket) && count($this->cache_msgs_ticket)) {
1786  return 0;
1787  }
1788 
1789  // Cache already loaded
1790 
1791  $sql = "SELECT id as rowid, fk_user_author, datec, label, note as message, code";
1792  $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm";
1793  $sql .= " WHERE fk_element = ".(int) $this->id;
1794  $sql .= " AND elementtype = 'ticket'";
1795  $sql .= " ORDER BY datec DESC";
1796 
1797  dol_syslog(get_class($this)."::load_cache_actions_ticket", LOG_DEBUG);
1798  $resql = $this->db->query($sql);
1799  if ($resql) {
1800  $num = $this->db->num_rows($resql);
1801  $i = 0;
1802  while ($i < $num) {
1803  $obj = $this->db->fetch_object($resql);
1804  $this->cache_msgs_ticket[$i]['id'] = $obj->rowid;
1805  $this->cache_msgs_ticket[$i]['fk_user_author'] = $obj->fk_user_author;
1806  $this->cache_msgs_ticket[$i]['datec'] = $this->db->jdate($obj->datec);
1807  $this->cache_msgs_ticket[$i]['subject'] = $obj->label;
1808  $this->cache_msgs_ticket[$i]['message'] = $obj->message;
1809  $this->cache_msgs_ticket[$i]['private'] = ($obj->code == 'TICKET_MSG_PRIVATE' ? 1 : 0);
1810  $i++;
1811  }
1812  return $num;
1813  } else {
1814  $this->error = "Error ".$this->db->lasterror();
1815  dol_syslog(get_class($this)."::load_cache_actions_ticket ".$this->error, LOG_ERR);
1816  return -1;
1817  }
1818  }
1819 
1827  public function close(User $user, $mode = 0)
1828  {
1829  global $conf, $langs;
1830 
1831  if ($this->fk_statut != Ticket::STATUS_CLOSED && $this->fk_statut != Ticket::STATUS_CANCELED) { // not closed
1832  $this->db->begin();
1833 
1834  $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
1835  $sql .= " SET fk_statut=".($mode ? Ticket::STATUS_CANCELED : Ticket::STATUS_CLOSED).", progress=100, date_close='".$this->db->idate(dol_now())."'";
1836  $sql .= " WHERE rowid = ".((int) $this->id);
1837 
1838  dol_syslog(get_class($this)."::close mode=".$mode);
1839  $resql = $this->db->query($sql);
1840  if ($resql) {
1841  $error = 0;
1842 
1843  // Valid and close fichinter linked
1844  if (isModEnabled('ficheinter') && !empty($conf->global->WORKFLOW_TICKET_CLOSE_INTERVENTION)) {
1845  dol_syslog("We have closed the ticket, so we close all linked interventions");
1846  $this->fetchObjectLinked($this->id, $this->element, null, 'fichinter');
1847  if ($this->linkedObjectsIds) {
1848  foreach ($this->linkedObjectsIds['fichinter'] as $fichinter_id) {
1849  $fichinter = new Fichinter($this->db);
1850  $fichinter->fetch($fichinter_id);
1851  if ($fichinter->statut == 0) {
1852  $result = $fichinter->setValid($user);
1853  if (!$result) {
1854  $this->errors[] = $fichinter->error;
1855  $error++;
1856  }
1857  }
1858  if ($fichinter->statut < 3) {
1859  $result = $fichinter->setStatut(3);
1860  if (!$result) {
1861  $this->errors[] = $fichinter->error;
1862  $error++;
1863  }
1864  }
1865  }
1866  }
1867  }
1868 
1869  // Call trigger
1870  $result = $this->call_trigger('TICKET_CLOSE', $user);
1871  if ($result < 0) {
1872  $error++;
1873  }
1874  // End call triggers
1875 
1876  if (!$error) {
1877  $this->db->commit();
1878  return 1;
1879  } else {
1880  $this->db->rollback();
1881  $this->error = join(',', $this->errors);
1882  dol_syslog(get_class($this)."::close ".$this->error, LOG_ERR);
1883  return -1;
1884  }
1885  } else {
1886  $this->db->rollback();
1887  $this->error = $this->db->lasterror();
1888  dol_syslog(get_class($this)."::close ".$this->error, LOG_ERR);
1889  return -1;
1890  }
1891  }
1892  }
1893 
1903  public function searchSocidByEmail($email, $type = '0', $filters = array(), $clause = 'AND')
1904  {
1905  $thirdparties = array();
1906  $exact = 0;
1907 
1908  // Generation requete recherche
1909  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe";
1910  $sql .= " WHERE entity IN (".getEntity('ticket', 1).")";
1911  if (!empty($type)) {
1912  if ($type == 1 || $type == 2) {
1913  $sql .= " AND client = ".((int) $type);
1914  } elseif ($type == 3) {
1915  $sql .= " AND fournisseur = 1";
1916  }
1917  }
1918  if (!empty($email)) {
1919  if (empty($exact)) {
1920  $regs = array();
1921  if (preg_match('/^([\*])?[^*]+([\*])?$/', $email, $regs) && count($regs) > 1) {
1922  $email = str_replace('*', '%', $email);
1923  } else {
1924  $email = '%'.$email.'%';
1925  }
1926  }
1927  $sql .= " AND ";
1928  if (is_array($filters) && !empty($filters)) {
1929  $sql .= "(";
1930  }
1931 
1932  $sql .= "email LIKE '".$this->db->escape($email)."'";
1933  }
1934  if (is_array($filters) && !empty($filters)) {
1935  foreach ($filters as $field => $value) {
1936  $sql .= " ".$clause." ".$field." LIKE '".$this->db->escape($value)."'";
1937  }
1938  if (!empty($email)) {
1939  $sql .= ")";
1940  }
1941  }
1942 
1943  $res = $this->db->query($sql);
1944  if ($res) {
1945  while ($rec = $this->db->fetch_array($res)) {
1946  $soc = new Societe($this->db);
1947  $soc->fetch($rec['rowid']);
1948  $thirdparties[] = $soc;
1949  }
1950 
1951  return $thirdparties;
1952  } else {
1953  $this->error = $this->db->error().' sql='.$sql;
1954  dol_syslog(get_class($this)."::searchSocidByEmail ".$this->error, LOG_ERR);
1955  return -1;
1956  }
1957  }
1958 
1967  public function searchContactByEmail($email, $socid = '', $case = '')
1968  {
1969  $contacts = array();
1970 
1971  // Generation requete recherche
1972  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople";
1973  $sql .= " WHERE entity IN (".getEntity('contact').")";
1974  if (!empty($socid)) {
1975  $sql .= " AND fk_soc='".$this->db->escape($socid)."'";
1976  }
1977 
1978  if (!empty($email)) {
1979  $sql .= " AND ";
1980 
1981  if (!$case) {
1982  $sql .= "email LIKE '".$this->db->escape($email)."'";
1983  } else {
1984  $sql .= "email LIKE BINARY '".$this->db->escape($email)."'";
1985  }
1986  }
1987 
1988  $res = $this->db->query($sql);
1989  if ($res) {
1990  while ($rec = $this->db->fetch_array($res)) {
1991  include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
1992  $contactstatic = new Contact($this->db);
1993  $contactstatic->fetch($rec['rowid']);
1994  $contacts[] = $contactstatic;
1995  }
1996 
1997  return $contacts;
1998  } else {
1999  $this->error = $this->db->error().' sql='.$sql;
2000  dol_syslog(get_class($this)."::searchContactByEmail ".$this->error, LOG_ERR);
2001  return -1;
2002  }
2003  }
2004 
2011  public function setCustomer($id)
2012  {
2013  if ($this->id) {
2014  $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
2015  $sql .= " SET fk_soc = ".($id > 0 ? $id : "null");
2016  $sql .= " WHERE rowid = ".((int) $this->id);
2017  dol_syslog(get_class($this).'::setCustomer sql='.$sql);
2018  $resql = $this->db->query($sql);
2019  if ($resql) {
2020  return 1;
2021  } else {
2022  return -1;
2023  }
2024  } else {
2025  return -1;
2026  }
2027  }
2028 
2035  public function setProgression($percent)
2036  {
2037  if ($this->id) {
2038  $sql = "UPDATE ".MAIN_DB_PREFIX."ticket";
2039  $sql .= " SET progress = ".($percent > 0 ? $percent : "null");
2040  $sql .= " WHERE rowid = ".((int) $this->id);
2041  dol_syslog(get_class($this).'::set_progression sql='.$sql);
2042  $resql = $this->db->query($sql);
2043  if ($resql) {
2044  return 1;
2045  } else {
2046  return -1;
2047  }
2048  } else {
2049  return -1;
2050  }
2051  }
2052 
2059  public function setContract($contractid)
2060  {
2061  if (!$this->table_element) {
2062  dol_syslog(get_class($this)."::setContract was called on objet with property table_element not defined", LOG_ERR);
2063  return -1;
2064  }
2065 
2066  $result = $this->add_object_linked('contrat', $contractid);
2067  if ($result) {
2068  $this->fk_contract = $contractid;
2069  return 1;
2070  } else {
2071  dol_print_error($this->db);
2072  return -1;
2073  }
2074  }
2075 
2076  /* gestion des contacts d'un ticket */
2077 
2083  public function getIdTicketInternalContact()
2084  {
2085  return $this->getIdContact('internal', 'SUPPORTTEC');
2086  }
2087 
2094  {
2095  return $this->listeContact(-1, 'internal');
2096  }
2097 
2103  public function getIdTicketCustomerContact()
2104  {
2105  return $this->getIdContact('external', 'SUPPORTCLI');
2106  }
2107 
2114  {
2115  return $this->listeContact(-1, 'external');
2116  }
2117 
2124  {
2125  return $this->getIdContact('internal', 'CONTRIBUTOR');
2126  }
2127 
2134  {
2135  return $this->getIdContact('external', 'CONTRIBUTOR');
2136  }
2137 
2143  public function getTicketAllContacts()
2144  {
2145  $array_contact = array();
2146 
2147  $array_contact = $this->getIdTicketInternalContact($exclude_self);
2148 
2149  $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact($exclude_self));
2150 
2151  $array_contact = array_merge($array_contact, $this->getIdTicketInternalInvolvedContact($exclude_self));
2152  $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact($exclude_self));
2153 
2154  return $array_contact;
2155  }
2156 
2163  {
2164  $array_contact = array();
2165 
2166  $array_contact = array_merge($array_contact, $this->getIdTicketCustomerContact($exclude_self));
2167  $array_contact = array_merge($array_contact, $this->getIdTicketCustomerInvolvedContact($exclude_self));
2168 
2169  return $array_contact;
2170  }
2171 
2172 
2183  public function listeContact($status = -1, $source = 'external', $list = 0, $code = '')
2184  {
2185  global $langs;
2186 
2187  $tab = array();
2188 
2189  $sql = "SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact"; // This field contains id of llx_socpeople or id of llx_user
2190  if ($source == 'internal') {
2191  $sql .= ", '-1' as socid, t.statut as statuscontact";
2192  }
2193 
2194  if ($source == 'external' || $source == 'thirdparty') {
2195  $sql .= ", t.fk_soc as socid, t.statut as statuscontact";
2196  }
2197 
2198  $sql .= ", t.civility, t.lastname as lastname, t.firstname, t.email";
2199  if ($source == 'internal') {
2200  $sql .= ", t.office_phone as phone, t.user_mobile as phone_mobile";
2201  }
2202 
2203  if ($source == 'external') {
2204  $sql .= ", t.phone as phone, t.phone_mobile as phone_mobile, t.phone_perso as phone_perso";
2205  }
2206 
2207  $sql .= ", tc.source, tc.element, tc.code, tc.libelle as type_contact_label";
2208  $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc";
2209  $sql .= ", ".MAIN_DB_PREFIX."element_contact ec";
2210  if ($source == 'internal') {
2211  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid";
2212  }
2213 
2214  if ($source == 'external' || $source == 'thirdparty') {
2215  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid";
2216  }
2217 
2218  $sql .= " WHERE ec.element_id = ".((int) $this->id);
2219  $sql .= " AND ec.fk_c_type_contact=tc.rowid";
2220  $sql .= " AND tc.element='".$this->db->escape($this->element)."'";
2221  if ($source == 'internal') {
2222  $sql .= " AND tc.source = 'internal'";
2223  }
2224 
2225  if ($source == 'external' || $source == 'thirdparty') {
2226  $sql .= " AND tc.source = 'external'";
2227  }
2228 
2229  if (!empty($code)) {
2230  $sql .= " AND tc.code = '".$this->db->escape($code)."'";
2231  }
2232 
2233  $sql .= " AND tc.active=1";
2234  if ($status >= 0) {
2235  $sql .= " AND ec.statut = ".((int) $status);
2236  }
2237 
2238  $sql .= " ORDER BY t.lastname ASC";
2239 
2240  $resql = $this->db->query($sql);
2241  if ($resql) {
2242  $num = $this->db->num_rows($resql);
2243  $i = 0;
2244  while ($i < $num) {
2245  $obj = $this->db->fetch_object($resql);
2246 
2247  if (!$list) {
2248  $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code;
2249  $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->type_contact_label);
2250  $tab[$i] = array(
2251  'source' => $obj->source,
2252  'socid' => $obj->socid,
2253  'id' => $obj->id,
2254  'nom' => $obj->lastname, // For backward compatibility
2255  'civility' => $obj->civility,
2256  'lastname' => $obj->lastname,
2257  'firstname' => $obj->firstname,
2258  'email' => $obj->email,
2259  'rowid' => $obj->rowid,
2260  'code' => $obj->code,
2261  'libelle' => $libelle_type,
2262  'status' => $obj->statuslink,
2263  'statuscontact'=>$obj->statuscontact,
2264  'fk_c_type_contact' => $obj->fk_c_type_contact,
2265  'phone' => $obj->phone,
2266  'phone_mobile' => $obj->phone_mobile);
2267  } else {
2268  $tab[$i] = $obj->id;
2269  }
2270 
2271  $i++;
2272  }
2273 
2274  return $tab;
2275  } else {
2276  $this->error = $this->db->error();
2277  dol_print_error($this->db);
2278  return -1;
2279  }
2280  }
2281 
2288  public function getDefaultRef($thirdparty = '')
2289  {
2290  global $conf;
2291 
2292  $defaultref = '';
2293  $modele = empty($conf->global->TICKET_ADDON) ? 'mod_ticket_simple' : $conf->global->TICKET_ADDON;
2294 
2295  // Search template files
2296  $file = '';
2297  $classname = '';
2298  $filefound = 0;
2299  $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
2300  foreach ($dirmodels as $reldir) {
2301  $file = dol_buildpath($reldir."core/modules/ticket/".$modele.'.php', 0);
2302  if (file_exists($file)) {
2303  $filefound = 1;
2304  $classname = $modele;
2305  break;
2306  }
2307  }
2308 
2309  if ($filefound) {
2310  $result = dol_include_once($reldir."core/modules/ticket/".$modele.'.php');
2311  $modTicket = new $classname;
2312 
2313  $defaultref = $modTicket->getNextValue($thirdparty, $this);
2314  }
2315 
2316  if (is_numeric($defaultref) && $defaultref <= 0) {
2317  $defaultref = '';
2318  }
2319 
2320  return $defaultref;
2321  }
2322 
2323 
2324  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2331  public function is_photo_available($sdir)
2332  {
2333  // phpcs:enable
2334  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2335 
2336  global $conf;
2337 
2338  $dir = $sdir.'/';
2339  $nbphoto = 0;
2340 
2341  $dir_osencoded = dol_osencode($dir);
2342  if (file_exists($dir_osencoded)) {
2343  $handle = opendir($dir_osencoded);
2344  if (is_resource($handle)) {
2345  while (($file = readdir($handle)) !== false) {
2346  if (!utf8_check($file)) {
2347  $file = utf8_encode($file); // To be sure data is stored in UTF8 in memory
2348  }
2349  if (dol_is_file($dir.$file)) {
2350  return true;
2351  }
2352  }
2353  }
2354  }
2355  return false;
2356  }
2357 
2358 
2367  public function copyFilesForTicket($forcetrackid = null)
2368  {
2369  global $conf;
2370 
2371  // Create form object
2372  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
2373  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2374  include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
2375 
2376  $maxwidthsmall = 270;
2377  $maxheightsmall = 150;
2378  $maxwidthmini = 128;
2379  $maxheightmini = 72;
2380 
2381  $formmail = new FormMail($this->db);
2382  $formmail->trackid = (is_null($forcetrackid) ? 'tic'.$this->id : '');
2383  $attachedfiles = $formmail->get_attached_files();
2384 
2385  $filepath = $attachedfiles['paths'];
2386  $filename = $attachedfiles['names'];
2387  $mimetype = $attachedfiles['mimes'];
2388 
2389  // Copy files into ticket directory
2390  $destdir = $conf->ticket->dir_output.'/'.$this->ref;
2391 
2392  if (!dol_is_dir($destdir)) {
2393  dol_mkdir($destdir);
2394  }
2395 
2396  $listofpaths = array();
2397  $listofnames = array();
2398  foreach ($filename as $i => $val) {
2399  $destfile = $destdir.'/'.$filename[$i];
2400  // If destination file already exists, we add a suffix to avoid to overwrite
2401  if (is_file($destfile)) {
2402  $pathinfo = pathinfo($filename[$i]);
2403  $now = dol_now();
2404  $destfile = $destdir.'/'.$pathinfo['filename'].' - '.dol_print_date($now, 'dayhourlog').'.'.$pathinfo['extension'];
2405  }
2406 
2407  $res = dol_move($filepath[$i], $destfile, 0, 1);
2408 
2409  if (image_format_supported($destfile) == 1) {
2410  // Create small thumbs for image (Ratio is near 16/9)
2411  // Used on logon for example
2412  $imgThumbSmall = vignette($destfile, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs");
2413  // Create mini thumbs for image (Ratio is near 16/9)
2414  // Used on menu or for setup page for example
2415  $imgThumbMini = vignette($destfile, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs");
2416  }
2417 
2418  $formmail->remove_attached_files($i);
2419 
2420  // Fill array with new names
2421  $listofpaths[$i] = $destfile;
2422  $listofnames[$i] = basename($destfile);
2423  }
2424 
2425  return array('listofpaths'=>$listofpaths, 'listofnames'=>$listofnames, 'listofmimes'=>$mimetype);
2426  }
2427 
2438  public function setCategories($categories)
2439  {
2440  // Handle single category
2441  if (!is_array($categories)) {
2442  $categories = array($categories);
2443  }
2444 
2445  // Get current categories
2446  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
2447  $c = new Categorie($this->db);
2448  $existing = $c->containing($this->id, Categorie::TYPE_TICKET, 'id');
2449 
2450  // Diff
2451  if (is_array($existing)) {
2452  $to_del = array_diff($existing, $categories);
2453  $to_add = array_diff($categories, $existing);
2454  } else {
2455  $to_del = array(); // Nothing to delete
2456  $to_add = $categories;
2457  }
2458 
2459  // Process
2460  foreach ($to_del as $del) {
2461  if ($c->fetch($del) > 0) {
2462  $c->del_type($this, Categorie::TYPE_TICKET);
2463  }
2464  }
2465  foreach ($to_add as $add) {
2466  if ($c->fetch($add) > 0) {
2467  $c->add_type($this, Categorie::TYPE_TICKET);
2468  }
2469  }
2470 
2471  return;
2472  }
2473 
2483  public function newMessage($user, &$action, $private = 1, $public_area = 0)
2484  {
2485  global $mysoc, $conf, $langs;
2486 
2487  $error = 0;
2488 
2489  $object = new Ticket($this->db);
2490 
2491  $ret = $object->fetch('', '', GETPOST('track_id', 'alpha'));
2492 
2493  $object->socid = $object->fk_soc;
2494  $object->fetch_thirdparty();
2495 
2496  if ($ret < 0) {
2497  $error++;
2498  array_push($this->errors, $langs->trans("ErrorTicketIsNotValid"));
2499  $action = '';
2500  }
2501 
2502  if (!GETPOST("message")) {
2503  $error++;
2504  array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("message")));
2505  $action = 'add_message';
2506  }
2507 
2508  if (!$error) {
2509  $object->subject = GETPOST('subject', 'alphanohtml');
2510  $object->message = GETPOST("message", "restricthtml");
2511  $object->private = GETPOST("private_message", "alpha");
2512 
2513  $send_email = GETPOST('send_email', 'int');
2514 
2515  // Copy attached files (saved into $_SESSION) as linked files to ticket. Return array with final name used.
2516  $resarray = $object->copyFilesForTicket();
2517 
2518  $listofpaths = $resarray['listofpaths'];
2519  $listofnames = $resarray['listofnames'];
2520  $listofmimes = $resarray['listofmimes'];
2521 
2522  $id = $object->createTicketMessage($user, 0, $listofpaths, $listofmimes, $listofnames);
2523  if ($id <= 0) {
2524  $error++;
2525  $this->error = $object->error;
2526  $this->errors = $object->errors;
2527  $action = 'add_message';
2528  }
2529 
2530  if (!$error && $id > 0) {
2531  setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs');
2532 
2533  //var_dump($_SESSION);
2534  //var_dump($listofpaths);exit;
2535 
2536  /*
2537  * Public area
2538  */
2539  if (!empty($public_area)) {
2540  /*
2541  * Send emails to assigned users (public area notification)
2542  */
2543  if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED)) {
2544  $assigned_user_dont_have_email = '';
2545  $sendto = array();
2546  if ($this->fk_user_assign > 0) {
2547  $assigned_user = new User($this->db);
2548  $assigned_user->fetch($this->fk_user_assign);
2549  if (!empty($assigned_user->email)) {
2550  $sendto[$assigned_user->email] = $assigned_user->getFullName($langs)." <".$assigned_user->email.">";
2551  } else {
2552  $assigned_user_dont_have_email = $assigned_user->getFullName($langs);
2553  }
2554  }
2555  if (empty($sendto)) {
2556  if (!empty($conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL)) {
2557  $sendto[$conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL] = $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL;
2558  } elseif (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2559  $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2560  }
2561  }
2562 
2563  // Add global email address recipient
2564  if (!empty($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS) &&
2565  !empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)
2566  ) {
2567  $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2568  }
2569 
2570  if (!empty($sendto)) {
2571  $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2572  $subject = '['.$label_title.'- ticket #'.$object->track_id.'] '.$langs->trans('TicketNewMessage');
2573 
2574  // Message send
2575  $message = $langs->trans('TicketMessageMailIntroText');
2576  $message .= '<br><br>';
2577  $messagePost = GETPOST('message', 'restricthtml');
2578  if (!dol_textishtml($messagePost)) {
2579  $messagePost = dol_nl2br($messagePost);
2580  }
2581  $message .= $messagePost;
2582 
2583  // Customer company infos
2584  $message .= '<br><br>';
2585  $message .= "==============================================";
2586  $message .= !empty($object->thirdparty->name) ? '<br>'.$langs->trans('Thirdparty')." : ".$object->thirdparty->name : '';
2587  $message .= !empty($object->thirdparty->town) ? '<br>'.$langs->trans('Town')." : ".$object->thirdparty->town : '';
2588  $message .= !empty($object->thirdparty->phone) ? '<br>'.$langs->trans('Phone')." : ".$object->thirdparty->phone : '';
2589 
2590  // Email send to
2591  $message .= '<br><br>';
2592  if (!empty($assigned_user_dont_have_email)) {
2593  $message .= '<br>'.$langs->trans('NoEMail').' : '.$assigned_user_dont_have_email;
2594  }
2595  foreach ($sendto as $val) {
2596  $message .= '<br>'.$langs->trans('TicketNotificationRecipient').' : '.$val;
2597  }
2598 
2599  // URL ticket
2600  $url_internal_ticket = dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id;
2601  $message .= '<br><br>';
2602  $message .= $langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal').' : <a href="'.$url_internal_ticket.'">'.$object->track_id.'</a>';
2603 
2604  $this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames);
2605  }
2606  }
2607  } else {
2608  /*
2609  * Private area
2610  */
2611  /*
2612  * Send emails to internal users (linked contacts)
2613  */
2614  if ($send_email > 0) {
2615  // Retrieve internal contact datas
2616  $internal_contacts = $object->getInfosTicketInternalContact();
2617 
2618  $sendto = array();
2619  if (is_array($internal_contacts) && count($internal_contacts) > 0) {
2620  // altairis: set default subject
2621  $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2622  $subject = GETPOST('subject', 'alphanohtml') ? GETPOST('subject', 'alphanohtml') : '['.$label_title.'- ticket #'.$object->track_id.'] '.$langs->trans('TicketNewMessage');
2623 
2624  $message_intro = $langs->trans('TicketNotificationEmailBody', "#".$object->id);
2625  $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
2626 
2627  $message = $langs->trans('TicketMessageMailIntroText');
2628  $message .= '<br><br>';
2629  $messagePost = GETPOST('message', 'restricthtml');
2630  if (!dol_textishtml($messagePost)) {
2631  $messagePost = dol_nl2br($messagePost);
2632  }
2633  $message .= $messagePost;
2634 
2635  // Coordonnées client
2636  $message .= '<br><br>';
2637  $message .= "==============================================<br>";
2638  $message .= !empty($object->thirdparty->name) ? $langs->trans('Thirdparty')." : ".$object->thirdparty->name : '';
2639  $message .= !empty($object->thirdparty->town) ? '<br>'.$langs->trans('Town')." : ".$object->thirdparty->town : '';
2640  $message .= !empty($object->thirdparty->phone) ? '<br>'.$langs->trans('Phone')." : ".$object->thirdparty->phone : '';
2641 
2642  // Build array to display recipient list
2643  foreach ($internal_contacts as $key => $info_sendto) {
2644  // altairis: avoid duplicate notifications
2645  if ($info_sendto['id'] == $user->id) {
2646  continue;
2647  }
2648 
2649  if ($info_sendto['email'] != '') {
2650  if (!empty($info_sendto['email'])) {
2651  $sendto[$info_sendto['email']] = trim($info_sendto['firstname']." ".$info_sendto['lastname'])." <".$info_sendto['email'].">";
2652  }
2653 
2654  //Contact type
2655  $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1').' ('.strtolower($info_sendto['libelle']).')';
2656  $message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient').' : '.$recipient.'<br>' : '');
2657  }
2658  }
2659  $message .= '<br>';
2660  // URL ticket
2661  $url_internal_ticket = dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id;
2662 
2663  // altairis: make html link on url
2664  $message .= '<br>'.$langs->trans('TicketNotificationEmailBodyInfosTrackUrlinternal').' : <a href="'.$url_internal_ticket.'">'.$object->track_id.'</a><br>';
2665 
2666  // Add global email address recipient
2667  if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2668  if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2669  $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2670  }
2671  }
2672 
2673  // altairis: dont try to send email if no recipient
2674  if (!empty($sendto)) {
2675  $this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames);
2676  }
2677  }
2678 
2679  /*
2680  * Send emails for externals users if not private (linked contacts)
2681  */
2682  if (empty($object->private)) {
2683  // Retrieve email of all contacts (external)
2684  $external_contacts = $object->getInfosTicketExternalContact();
2685 
2686  // If no contact, get email from thirdparty
2687  if (is_array($external_contacts) && count($external_contacts) === 0) {
2688  if (!empty($object->fk_soc)) {
2689  $object->fetch_thirdparty($object->fk_soc);
2690  $array_company = array(array('firstname' => '', 'lastname' => $object->thirdparty->name, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id));
2691  $external_contacts = array_merge($external_contacts, $array_company);
2692  } elseif (empty($object->fk_soc) && !empty($object->origin_email)) {
2693  $array_external = array(array('firstname' => '', 'lastname' => $object->origin_email, 'email' => $object->thirdparty->email, 'libelle' => $langs->transnoentities('Customer'), 'socid' => $object->thirdparty->id));
2694  $external_contacts = array_merge($external_contacts, $array_external);
2695  }
2696  }
2697 
2698  $sendto = array();
2699  if (is_array($external_contacts) && count($external_contacts) > 0) {
2700  // altairis: get default subject for email to external contacts
2701  $label_title = empty($conf->global->MAIN_APPLICATION_TITLE) ? $mysoc->name : $conf->global->MAIN_APPLICATION_TITLE;
2702  $subject = GETPOST('subject') ? GETPOST('subject') : '['.$label_title.'- ticket #'.$object->track_id.'] '.$langs->trans('TicketNewMessage');
2703 
2704  $message_intro = GETPOST('mail_intro') ? GETPOST('mail_intro', 'restricthtml') : $conf->global->TICKET_MESSAGE_MAIL_INTRO;
2705  $message_signature = GETPOST('mail_signature') ? GETPOST('mail_signature', 'restricthtml') : $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE;
2706  if (!dol_textishtml($message_intro)) {
2707  $message_intro = dol_nl2br($message_intro);
2708  }
2709  if (!dol_textishtml($message_signature)) {
2710  $message_signature = dol_nl2br($message_signature);
2711  }
2712 
2713  // We put intro after
2714  $messagePost = GETPOST('message', 'restricthtml');
2715  if (!dol_textishtml($messagePost)) {
2716  $messagePost = dol_nl2br($messagePost);
2717  }
2718  $message = $messagePost;
2719  $message .= '<br><br>';
2720 
2721  foreach ($external_contacts as $key => $info_sendto) {
2722  // altairis: avoid duplicate emails to external contacts
2723  if ($info_sendto['id'] == $user->contact_id) {
2724  continue;
2725  }
2726 
2727  if ($info_sendto['email'] != '' && $info_sendto['email'] != $object->origin_email) {
2728  if (!empty($info_sendto['email'])) {
2729  $sendto[$info_sendto['email']] = trim($info_sendto['firstname']." ".$info_sendto['lastname'])." <".$info_sendto['email'].">";
2730  }
2731 
2732  $recipient = dolGetFirstLastname($info_sendto['firstname'], $info_sendto['lastname'], '-1').' ('.strtolower($info_sendto['libelle']).')';
2733  $message .= (!empty($recipient) ? $langs->trans('TicketNotificationRecipient').' : '.$recipient.'<br>' : '');
2734  }
2735  }
2736 
2737  // If public interface is not enable, use link to internal page into mail
2738  $url_public_ticket = (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ?
2739  (!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;
2740  $message .= '<br>'.$langs->trans('TicketNewEmailBodyInfosTrackUrlCustomer').' : <a href="'.$url_public_ticket.'">'.$object->track_id.'</a><br>';
2741 
2742  // Build final message
2743  $message = $message_intro.'<br><br>'.$message;
2744 
2745  // Add signature
2746  $message .= '<br>'.$message_signature;
2747 
2748  if (!empty($object->origin_email)) {
2749  $sendto[$object->origin_email] = $object->origin_email;
2750  }
2751 
2752  if ($object->fk_soc > 0 && !array_key_exists($object->origin_email, $sendto)) {
2753  $object->socid = $object->fk_soc;
2754  $object->fetch_thirdparty();
2755  if (!empty($object->thirdparty->email)) {
2756  $sendto[$object->thirdparty->email] = $object->thirdparty->email;
2757  }
2758  }
2759 
2760  // altairis: Add global email address reciepient
2761  if ($conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS && !array_key_exists($conf->global->TICKET_NOTIFICATION_EMAIL_TO, $sendto)) {
2762  if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO)) {
2763  $sendto[$conf->global->TICKET_NOTIFICATION_EMAIL_TO] = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
2764  }
2765  }
2766 
2767  // altairis: dont try to send email when no recipient
2768  if (!empty($sendto)) {
2769  $result = $this->sendTicketMessageByEmail($subject, $message, '', $sendto, $listofpaths, $listofmimes, $listofnames);
2770  if ($result) {
2771  // update last_msg_sent date
2772  $this->date_last_msg_sent = dol_now();
2773  $this->update($user);
2774  }
2775  }
2776  }
2777  }
2778  }
2779  }
2780 
2781  // Set status to "answered" if not set yet, but only if internal user
2782  if ($object->status < 3 && !$user->socid) {
2783  $object->setStatut(3);
2784  }
2785  return 1;
2786  } else {
2787  setEventMessages($object->error, $object->errors, 'errors');
2788  return -1;
2789  }
2790  } else {
2791  setEventMessages($this->error, $this->errors, 'errors');
2792  return -1;
2793  }
2794  }
2795 
2796 
2809  public function sendTicketMessageByEmail($subject, $message, $send_internal_cc = 0, $array_receiver = array(), $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array())
2810  {
2811  global $conf, $langs;
2812 
2813  if ($conf->global->TICKET_DISABLE_ALL_MAILS) {
2814  dol_syslog(get_class($this).'::sendTicketMessageByEmail: Emails are disable into ticket setup by option TICKET_DISABLE_ALL_MAILS', LOG_WARNING);
2815  return false;
2816  }
2817 
2818  $langs->load("mails");
2819 
2820  include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
2821  //$contactstatic = new Contact($this->db);
2822 
2823  // If no receiver defined, load all ticket linked contacts
2824  if (!is_array($array_receiver) || !count($array_receiver) > 0) {
2825  $array_receiver = $this->getInfosTicketInternalContact();
2826  $array_receiver = array_merge($array_receiver, $this->getInfosTicketExternalContact());
2827  }
2828 
2829  if ($send_internal_cc) {
2830  $sendtocc = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2831  }
2832 
2833  $from = $conf->global->TICKET_NOTIFICATION_EMAIL_FROM;
2834  $is_sent = false;
2835  if (is_array($array_receiver) && count($array_receiver) > 0) {
2836  foreach ($array_receiver as $key => $receiver) {
2837  $deliveryreceipt = 0;
2838  $filepath = $filename_list;
2839  $filename = $mimefilename_list;
2840  $mimetype = $mimetype_list;
2841 
2842  // Envoi du mail
2843  if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2844  $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
2845  $conf->global->MAIN_MAIL_AUTOCOPY_TO = '';
2846  }
2847  include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
2848  $trackid = "tic".$this->id;
2849  $mailfile = new CMailFile($subject, $receiver, $from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1, '', '', $trackid, '', 'ticket');
2850  if ($mailfile->error) {
2851  setEventMessages($mailfile->error, null, 'errors');
2852  } else {
2853  $result = $mailfile->sendfile();
2854  if ($result) {
2855  setEventMessages($langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($receiver, 2)), null, 'mesgs');
2856  $is_sent = true;
2857  } else {
2858  $langs->load("other");
2859  if ($mailfile->error) {
2860  setEventMessages($langs->trans('ErrorFailedToSendMail', $from, $receiver), null, 'errors');
2861  dol_syslog($langs->trans('ErrorFailedToSendMail', $from, $receiver).' : '.$mailfile->error);
2862  } else {
2863  setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'errors');
2864  }
2865  }
2866  }
2867  if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
2868  $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
2869  }
2870  }
2871  } else {
2872  $langs->load("other");
2873  setEventMessages($langs->trans('ErrorMailRecipientIsEmptyForSendTicketMessage'), null, 'warnings');
2874  }
2875  return $is_sent;
2876  }
2877 
2878  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2886  public function load_board($user, $mode)
2887  {
2888  // phpcs:enable
2889  global $conf, $user, $langs;
2890 
2891  $now = dol_now();
2892  $delay_warning = 0;
2893 
2894  $this->nbtodo = $this->nbtodolate = 0;
2895  $clause = " WHERE";
2896 
2897  $sql = "SELECT p.rowid, p.ref, p.datec as datec";
2898  $sql .= " FROM ".MAIN_DB_PREFIX."ticket as p";
2899  if (isModEnabled('societe') && empty($user->rights->societe->client->voir) && !$user->socid) {
2900  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON p.fk_soc = sc.fk_soc";
2901  $sql .= " WHERE sc.fk_user = ".((int) $user->id);
2902  $clause = " AND";
2903  }
2904  $sql .= $clause." p.entity IN (".getEntity('ticket').")";
2905  if ($mode == 'opened') {
2906  $sql .= " AND p.fk_statut NOT IN (".Ticket::STATUS_CLOSED.", ".Ticket::STATUS_CANCELED.")";
2907  }
2908  if ($user->socid) {
2909  $sql .= " AND p.fk_soc = ".((int) $user->socid);
2910  }
2911 
2912  $resql = $this->db->query($sql);
2913  if ($resql) {
2914  $label = $labelShort = '';
2915  $status = '';
2916  if ($mode == 'opened') {
2917  $status = 'openall';
2918  //$delay_warning = $conf->ticket->warning_delay;
2919  $delay_warning = 0;
2920  $label = $langs->trans("MenuListNonClosed");
2921  $labelShort = $langs->trans("MenuListNonClosed");
2922  }
2923 
2924  $response = new WorkboardResponse();
2925  //$response->warning_delay = $delay_warning / 60 / 60 / 24;
2926  $response->label = $label;
2927  $response->labelShort = $labelShort;
2928  $response->url = DOL_URL_ROOT.'/ticket/list.php?search_fk_statut[]='.$status;
2929  $response->img = img_object('', "ticket");
2930 
2931  // This assignment in condition is not a bug. It allows walking the results.
2932  while ($obj = $this->db->fetch_object($resql)) {
2933  $response->nbtodo++;
2934  if ($mode == 'opened') {
2935  $datelimit = $this->db->jdate($obj->datec) + $delay_warning;
2936  if ($datelimit < $now) {
2937  //$response->nbtodolate++;
2938  }
2939  }
2940  }
2941  return $response;
2942  } else {
2943  $this->error = $this->db->lasterror();
2944  return -1;
2945  }
2946  }
2947 
2948  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2954  public function load_state_board()
2955  {
2956  // phpcs:enable
2957  global $conf, $user;
2958 
2959  $this->nb = array();
2960  $clause = "WHERE";
2961 
2962  $sql = "SELECT count(p.rowid) as nb";
2963  $sql .= " FROM ".MAIN_DB_PREFIX."ticket as p";
2964  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON p.fk_soc = s.rowid";
2965  if (empty($user->rights->societe->client->voir) && !$user->socid) {
2966  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2967  $sql .= " WHERE sc.fk_user = ".((int) $user->id);
2968  $clause = "AND";
2969  }
2970  $sql .= " ".$clause." p.entity IN (".getEntity('ticket').")";
2971 
2972  $resql = $this->db->query($sql);
2973  if ($resql) {
2974  // This assignment in condition is not a bug. It allows walking the results.
2975  while ($obj = $this->db->fetch_object($resql)) {
2976  $this->nb["ticket"] = $obj->nb;
2977  }
2978  $this->db->free($resql);
2979  return 1;
2980  } else {
2981  dol_print_error($this->db);
2982  $this->error = $this->db->lasterror();
2983  return -1;
2984  }
2985  }
2986 
2995  public static function replaceThirdparty($db, $origin_id, $dest_id)
2996  {
2997  $tables = array('ticket');
2998 
2999  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
3000  }
3001 }
3002 
3003 
3008 {
3013  public $rowid;
3014 
3018  public $id;
3019 
3023  public $ref;
3024 
3028  public $track_id;
3029 
3033  public $fk_soc;
3034 
3038  public $fk_project;
3039 
3044 
3049 
3054 
3058  public $subject;
3059 
3063  public $message;
3064 
3068  public $fk_statut;
3069 
3073  public $resolution;
3074 
3078  public $progress;
3079 
3083  public $timing;
3084 
3088  public $type_code;
3089 
3094 
3099 
3103  public $type_label;
3104 
3109 
3114 
3118  public $datec = '';
3119 
3123  public $date_read = '';
3124 
3128  public $date_last_msg_sent = '';
3129 
3133  public $date_close = '';
3134 }
Ticket\getIdTicketInternalContact
getIdTicketInternalContact()
Return id des contacts interne de suivi.
Definition: ticket.class.php:2083
Ticket\sendTicketMessageByEmail
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.
Definition: ticket.class.php:2809
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
db
$conf db
API class for accounts.
Definition: inc.php:41
TicketsLine\$date_read
$date_read
Read date.
Definition: ticket.class.php:3123
TicketsLine\$timing
$timing
Duration for ticket.
Definition: ticket.class.php:3083
TicketsLine\$progress
$progress
Progress in percent.
Definition: ticket.class.php:3078
Ticket\replaceThirdparty
static replaceThirdparty($db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
Definition: ticket.class.php:2995
ActionComm
Class to manage agenda events (actions)
Definition: actioncomm.class.php:38
TicketsLine\$type_label
$type_label
Type label.
Definition: ticket.class.php:3103
Ticket\fetchAll
fetchAll($user, $sortorder='ASC', $sortfield='t.datec', $limit='', $offset=0, $arch='', $filter='')
Load all objects in memory from database.
Definition: ticket.class.php:684
dol_osencode
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
Definition: functions.lib.php:8485
TicketsLine\$origin_email
$origin_email
Person email who have create ticket.
Definition: ticket.class.php:3043
Ticket\listeContact
listeContact($status=-1, $source='external', $list=0, $code='')
Get array of all contacts for a ticket Override method of file commonobject.class....
Definition: ticket.class.php:2183
Ticket\is_photo_available
is_photo_available($sdir)
Return if at least one photo is available.
Definition: ticket.class.php:2331
Ticket\$category_label
$category_label
Category label.
Definition: ticket.class.php:158
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_nl2br
dol_nl2br($stringtoencode, $nl2brmode=0, $forxml=false)
Replace CRLF in string with a HTML BR tag.
Definition: functions.lib.php:6949
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4830
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1033
Ticket\sendLogByEmail
sendLogByEmail($user, $message)
Send notification of changes by email.
Definition: ticket.class.php:1573
dol_buildpath
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
Definition: functions.lib.php:1062
Ticket\update
update($user=0, $notrigger=0)
Update object into database.
Definition: ticket.class.php:851
ref
$object ref
Definition: info.php:77
CMailFile
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Definition: CMailFile.class.php:38
TicketsLine\$datec
$datec
Creation date.
Definition: ticket.class.php:3118
TicketsLine\$message
$message
Ticket message.
Definition: ticket.class.php:3063
Ticket\LibStatut
LibStatut($status, $mode=0, $notooltip=0, $progress=0)
Return status label of object.
Definition: ticket.class.php:1319
image_format_supported
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:80
Categorie
Class to manage categories.
Definition: categorie.class.php:47
dol_clone
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for properties) With native = 0: P...
Definition: functions.lib.php:1157
CommonObject
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Definition: commonobject.class.php:44
Ticket\setCategories
setCategories($categories)
Sets object to supplied categories.
Definition: ticket.class.php:2438
TicketsLine\$date_close
$date_close
Close ticket date.
Definition: ticket.class.php:3133
dol_is_file
dol_is_file($pathoffile)
Return if path is a file.
Definition: files.lib.php:477
Ticket\searchContactByEmail
searchContactByEmail($email, $socid='', $case='')
Search and fetch contacts by email.
Definition: ticket.class.php:1967
Ticket\assignUser
assignUser($user, $id_assign_user, $notrigger=0)
Mark a message as read.
Definition: ticket.class.php:1517
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2500
WorkboardResponse
Definition: workboardresponse.class.php:25
dol_concatdesc
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...
Definition: functions.lib.php:7234
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:3866
Ticket\getLibStatut
getLibStatut($mode=0)
Return status label of object.
Definition: ticket.class.php:1303
TicketsLine\$fk_project
$fk_project
Project ID.
Definition: ticket.class.php:3038
utf8_check
utf8_check($str)
Check if a string is in UTF8.
Definition: functions.lib.php:8424
Ticket\getTicketAllCustomerContacts
getTicketAllCustomerContacts()
Return id of all contacts for ticket.
Definition: ticket.class.php:2162
Ticket\markAsRead
markAsRead($user, $notrigger=0)
Mark a message as read.
Definition: ticket.class.php:1463
TicketsLine\$type_code
$type_code
Type code.
Definition: ticket.class.php:3088
Ticket\setContract
setContract($contractid)
Link element with a contract.
Definition: ticket.class.php:2059
Ticket\load_state_board
load_state_board()
Load indicator this->nb of global stats widget.
Definition: ticket.class.php:2954
getEntity
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
Definition: functions.lib.php:148
TicketsLine\$severity_label
$severity_label
Severity label.
Definition: ticket.class.php:3113
Ticket\getNomUrl
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
Definition: ticket.class.php:1389
CommonObject\insertExtraFields
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Definition: commonobject.class.php:6143
Ticket\$fields
$fields
'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]',...
Definition: ticket.class.php:257
Ticket\printSelectStatus
printSelectStatus($selected="")
Print selected status.
Definition: ticket.class.php:1162
Ticket\loadCacheSeveritiesTickets
loadCacheSeveritiesTickets()
Charge dans cache la liste des sévérité de tickets (paramétrable dans dictionnaire)
Definition: ticket.class.php:1260
Ticket\searchSocidByEmail
searchSocidByEmail($email, $type='0', $filters=array(), $clause='AND')
Search and fetch thirparties by email.
Definition: ticket.class.php:1903
Ticket\loadCacheMsgsTicket
loadCacheMsgsTicket()
Load the list of event on ticket into ->cache_msgs_ticket.
Definition: ticket.class.php:1783
TicketsLine\$severity_code
$severity_code
Severity code.
Definition: ticket.class.php:3098
CommonObject\add_contact
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Definition: commonobject.class.php:1108
CommonObject\commonReplaceThirdparty
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
Definition: commonobject.class.php:8329
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1589
Ticket\loadCacheLogsTicket
loadCacheLogsTicket()
Charge la liste des actions sur le ticket.
Definition: ticket.class.php:1665
Ticket\loadCacheCategoriesTickets
loadCacheCategoriesTickets()
Load into a cache array, the list of ticket categories (setup done into dictionary)
Definition: ticket.class.php:1213
Ticket\close
close(User $user, $mode=0)
Close a ticket.
Definition: ticket.class.php:1827
Contact
Class to manage contact/addresses.
Definition: contact.class.php:40
Ticket\$email_from
$email_from
Email from user.
Definition: ticket.class.php:168
generate_random_id
generate_random_id($car=16)
Generate a random id.
Definition: ticket.lib.php:184
Ticket\create
create($user, $notrigger=0)
Create object into database.
Definition: ticket.class.php:414
Ticket\initAsSpecimen
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
Definition: ticket.class.php:1129
Ticket\__construct
__construct($db)
Constructor.
Definition: ticket.class.php:293
CommonObject\fetch_optionals
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...
Definition: commonobject.class.php:5994
Ticket\getTicketAllContacts
getTicketAllContacts()
Return id of all contacts for ticket.
Definition: ticket.class.php:2143
Ticket\$severity_label
$severity_label
Severity label.
Definition: ticket.class.php:163
Ticket\setProgression
setProgression($percent)
Define progression of current ticket.
Definition: ticket.class.php:2035
Ticket\newMessage
newMessage($user, &$action, $private=1, $public_area=0)
Add new message on a ticket (private/public area).
Definition: ticket.class.php:2483
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3733
Fichinter
Class to manage interventions.
Definition: fichinter.class.php:37
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
dolGetFirstLastname
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
Definition: functions.lib.php:8048
Ticket\STATUS_NOT_READ
const STATUS_NOT_READ
Status.
Definition: ticket.class.php:220
User
Class to manage Dolibarr users.
Definition: user.class.php:44
Ticket\getInfosTicketInternalContact
getInfosTicketInternalContact()
Retrieve informations about internal contacts.
Definition: ticket.class.php:2093
dol_html_entity_decode
dol_html_entity_decode($a, $b, $c='UTF-8', $keepsomeentities=0)
Replace html_entity_decode functions to manage errors.
Definition: functions.lib.php:7038
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Ticket\createTicketMessage
createTicketMessage($user, $notrigger=0, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array())
Add message into database.
Definition: ticket.class.php:1713
dolGetStatus
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
Definition: functions.lib.php:10324
Ticket\loadCacheTypesTickets
loadCacheTypesTickets()
Load into a cache the types of tickets (setup done into dictionaries)
Definition: ticket.class.php:1173
Ticket\load_board
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
Definition: ticket.class.php:2886
TicketsLine\$subject
$subject
Ticket subject.
Definition: ticket.class.php:3058
Ticket\copyFilesForTicket
copyFilesForTicket($forcetrackid=null)
Copy files defined into $_SESSION array into the ticket directory of attached files.
Definition: ticket.class.php:2367
img_object
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
Definition: functions.lib.php:4197
Ticket\getDefaultRef
getDefaultRef($thirdparty='')
Get a default reference.
Definition: ticket.class.php:2288
Form\selectarray
static selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=1, $moreparamonempty='', $disablebademail=0, $nohtmlescape=0)
Return a HTML select string, built from an array of key+value.
Definition: html.form.class.php:7880
Ticket\setCustomer
setCustomer($id)
Define parent commany of current ticket.
Definition: ticket.class.php:2011
TicketsLine\$resolution
$resolution
State resolution.
Definition: ticket.class.php:3073
Ticket\getIdTicketCustomerInvolvedContact
getIdTicketCustomerInvolvedContact()
Return id des contacts clients des intervenants.
Definition: ticket.class.php:2133
TicketsLine\$track_id
$track_id
Hash to identify ticket.
Definition: ticket.class.php:3028
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2831
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->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->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
TicketsLine\$category_label
$category_label
Category label.
Definition: ticket.class.php:3108
TicketsLine\$fk_statut
$fk_statut
Ticket statut.
Definition: ticket.class.php:3068
Ticket\verify
verify()
Check properties of ticket are ok (like ref, track_id, ...).
Definition: ticket.class.php:327
Ticket
Class to generate the form for creating a new ticket.
Definition: html.formticket.class.php:31
TicketsLine\$fk_user_assign
$fk_user_assign
User id who have ticket assigned.
Definition: ticket.class.php:3053
CommonObject\call_trigger
call_trigger($triggerName, $user)
Call trigger based on this instance.
Definition: commonobject.class.php:5778
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8123
TicketsLine\$category_code
$category_code
Category code.
Definition: ticket.class.php:3093
dol_textishtml
dol_textishtml($msg, $option=0)
Return if a text is a html content.
Definition: functions.lib.php:7171
dol_is_dir
dol_is_dir($folder)
Test if filename is a directory.
Definition: files.lib.php:447
Ticket\getIdTicketCustomerContact
getIdTicketCustomerContact()
Return id des contacts clients pour le suivi ticket.
Definition: ticket.class.php:2103
Ticket\createFromClone
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
Definition: ticket.class.php:1083
FormMail
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Definition: html.formmail.class.php:38
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6589
vignette
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).
Definition: images.lib.php:507
Ticket\getInfosTicketExternalContact
getInfosTicketExternalContact()
Retrieve informations about external contacts.
Definition: ticket.class.php:2113
TicketsLine\$fk_user_create
$fk_user_create
User id who have create ticket.
Definition: ticket.class.php:3048
Ticket\$type_label
$type_label
Type label.
Definition: ticket.class.php:153
TicketsLine
Ticket line Class.
Definition: ticket.class.php:3007
Ticket\getIdTicketInternalInvolvedContact
getIdTicketInternalInvolvedContact()
Return id des contacts clients des intervenants.
Definition: ticket.class.php:2123
Ticket\$subject
$subject
var string Ticket subject
Definition: ticket.class.php:102
dol_move
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
Definition: files.lib.php:855
Ticket\fetch
fetch($id='', $ref='', $track_id='', $email_msgid='')
Load object in memory from the database.
Definition: ticket.class.php:551