dolibarr  17.0.4
ticket.lib.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-2022 Frédéric France <frederic.france@netlogic.fr>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
32 {
33  global $langs, $conf, $db;
34 
35  $extrafields = new ExtraFields($db);
36  $extrafields->fetch_name_optionals_label('ticket');
37 
38  $langs->load("ticket");
39 
40  $h = 0;
41  $head = array();
42 
43  $head[$h][0] = DOL_URL_ROOT.'/admin/ticket.php';
44  $head[$h][1] = $langs->trans("TicketSettings");
45  $head[$h][2] = 'settings';
46  $h++;
47 
48  $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_extrafields.php';
49  $head[$h][1] = $langs->trans("ExtraFieldsTicket");
50  $nbExtrafields = $extrafields->attributes['ticket']['count'];
51  if ($nbExtrafields > 0) {
52  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbExtrafields.'</span>';
53  }
54  $head[$h][2] = 'attributes';
55  $h++;
56 
57  $head[$h][0] = DOL_URL_ROOT.'/admin/ticket_public.php';
58  $head[$h][1] = $langs->trans("PublicInterface");
59  $head[$h][2] = 'public';
60  $h++;
61 
62  // Show more tabs from modules
63  // Entries must be declared in modules descriptor with line
64  //$this->tabs = array(
65  // 'entity:+tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
66  //); // to add new tab
67  //$this->tabs = array(
68  // 'entity:-tabname:Title:@ticket:/ticket/mypage.php?id=__ID__'
69  //); // to remove a tab
70  complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin');
71 
72  complete_head_from_modules($conf, $langs, null, $head, $h, 'ticketadmin', 'remove');
73 
74  return $head;
75 }
76 
83 function ticket_prepare_head($object)
84 {
85  global $db, $langs, $conf, $user;
86 
87  $h = 0;
88  $head = array();
89  $head[$h][0] = DOL_URL_ROOT.'/ticket/card.php?track_id='.$object->track_id;
90  $head[$h][1] = $langs->trans("Ticket");
91  $head[$h][2] = 'tabTicket';
92  $h++;
93 
94  if (!getDolGlobalInt('MAIN_DISABLE_CONTACTS_TAB') && empty($user->socid) && isModEnabled("societe")) {
95  $nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
96  $head[$h][0] = DOL_URL_ROOT.'/ticket/contact.php?track_id='.$object->track_id;
97  $head[$h][1] = $langs->trans('ContactsAddresses');
98  if ($nbContact > 0) {
99  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
100  }
101  $head[$h][2] = 'contact';
102  $h++;
103  }
104 
105  complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'core');
106 
107  // Attached files
108  include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
109  $upload_dir = $conf->ticket->dir_output."/".$object->ref;
110  $nbFiles = count(dol_dir_list($upload_dir, 'files'));
111  $head[$h][0] = DOL_URL_ROOT.'/ticket/document.php?id='.$object->id;
112  $head[$h][1] = $langs->trans("Documents");
113  if ($nbFiles > 0) {
114  $head[$h][1] .= '<span class="badge marginleftonlyshort">'.$nbFiles.'</span>';
115  }
116 
117  $head[$h][2] = 'tabTicketDocument';
118  $h++;
119 
120 
121  // History
122  $ticketViewType = "messaging";
123  if (empty($_SESSION['ticket-view-type'])) {
124  $_SESSION['ticket-view-type'] = $ticketViewType;
125  } else {
126  $ticketViewType = $_SESSION['ticket-view-type'];
127  }
128 
129  if ($ticketViewType == "messaging") {
130  $head[$h][0] = DOL_URL_ROOT.'/ticket/messaging.php?track_id='.$object->track_id;
131  } else {
132  // $ticketViewType == "list"
133  $head[$h][0] = DOL_URL_ROOT.'/ticket/agenda.php?track_id='.$object->track_id;
134  }
135  $head[$h][1] = $langs->trans('Events');
136  if (isModEnabled('agenda') && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read))) {
137  $head[$h][1] .= '/';
138  $head[$h][1] .= $langs->trans("Agenda");
139  }
140  $head[$h][2] = 'tabTicketLogs';
141  $h++;
142 
143 
144  complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'add', 'external');
145 
146  complete_head_from_modules($conf, $langs, $object, $head, $h, 'ticket', 'remove');
147 
148  return $head;
149 }
150 
157 function showDirectPublicLink($object)
158 {
159  global $conf, $langs;
160 
161  require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
162  $email = CMailFile::getValidAddress($object->origin_email, 2);
163  $url = '';
164  if ($email) {
165  $url = dol_buildpath('/public/ticket/view.php', 3).'?track_id='.$object->track_id.'&email='.$email;
166  }
167 
168  $out = '';
169  if (!getDolGlobalInt('TICKET_ENABLE_PUBLIC_INTERFACE')) {
170  $langs->load('errors');
171  $out .= '<span class="opacitymedium">'.$langs->trans("ErrorPublicInterfaceNotEnabled").'</span>';
172  } else {
173  $out .= img_picto('', 'object_globe.png').' <span class="opacitymedium">'.$langs->trans("TicketPublicAccess").'</span><br>';
174  if ($url) {
175  $out .= '<div class="urllink">';
176  $out .= '<input type="text" id="directpubliclink" class="quatrevingtpercentminusx" value="'.$url.'">';
177  $out .= '<a href="'.$url.'" target="_blank" rel="noopener noreferrer">'.img_picto('', 'object_globe.png', 'class="paddingleft"').'</a>';
178  $out .= '</div>';
179  $out .= ajax_autoselect("directpubliclink", 0);
180  } else {
181  $out .= '<span class="opacitymedium">'.$langs->trans("TicketNotCreatedFromPublicInterface").'</span>';
182  }
183  }
184 
185  return $out;
186 }
187 
194 function generate_random_id($car = 16)
195 {
196  $string = "";
197  $chaine = "abcdefghijklmnopqrstuvwxyz123456789";
198  mt_srand((double) microtime() * 1000000);
199  for ($i = 0; $i < $car; $i++) {
200  $string .= $chaine[mt_rand() % strlen($chaine)];
201  }
202  return $string;
203 }
204 
216 function llxHeaderTicket($title, $head = "", $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '')
217 {
218  global $user, $conf, $langs, $mysoc;
219  $urllogo = "";
220  top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss, 0, 1); // Show html headers
221 
222  print '<body id="mainbody" class="publicnewticketform">';
223  print '<div class="center">';
224 
225  // Define urllogo
226  if (getDolGlobalInt('TICKET_SHOW_COMPANY_LOGO') || getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
227  // Print logo
228  if (getDolGlobalInt('TICKET_SHOW_COMPANY_LOGO')) {
229  $urllogo = DOL_URL_ROOT.'/theme/common/login_logo.png';
230 
231  if (!empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) {
232  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/thumbs/'.$mysoc->logo_small);
233  } elseif (!empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) {
234  $urllogo = DOL_URL_ROOT.'/viewimage.php?modulepart=mycompany&amp;entity='.$conf->entity.'&amp;file='.urlencode('logos/'.$mysoc->logo);
235  } elseif (is_readable(DOL_DOCUMENT_ROOT.'/theme/dolibarr_logo.svg')) {
236  $urllogo = DOL_URL_ROOT.'/theme/dolibarr_logo.svg';
237  }
238  }
239  }
240 
241  // Output html code for logo
242  if ($urllogo || getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
243  print '<div class="backgreypublicpayment">';
244  print '<div class="logopublicpayment">';
245  if ($urllogo) {
246  print '<a href="'.(getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') ? getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE') : dol_buildpath('/public/ticket/index.php?entity='.$conf->entity, 1)).'">';
247  print '<img id="dolpaymentlogo" src="'.$urllogo.'"';
248  print '>';
249  print '</a>';
250  }
251  if (getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC')) {
252  print '<div class="clearboth"></div><strong>'.(getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC') ? getDolGlobalString('TICKET_PUBLIC_INTERFACE_TOPIC') : $langs->trans("TicketSystem")).'</strong>';
253  }
254  print '</div>';
255  if (!getDolGlobalInt('MAIN_HIDE_POWERED_BY')) {
256  print '<div class="poweredbypublicpayment opacitymedium right hideonsmartphone"><a class="poweredbyhref" href="https://www.dolibarr.org?utm_medium=website&utm_source=poweredby" target="dolibarr" rel="noopener">'.$langs->trans("PoweredBy").'<br><img src="'.DOL_URL_ROOT.'/theme/dolibarr_logo.svg" width="80px"></a></div>';
257  }
258  print '</div>';
259  }
260 
261  if (getDolGlobalInt('TICKET_IMAGE_PUBLIC_INTERFACE')) {
262  print '<div class="backimagepublicticket">';
263  print '<img id="idTICKET_IMAGE_PUBLIC_INTERFACE" src="'.getDolGlobalString('TICKET_IMAGE_PUBLIC_INTERFACE').'">';
264  print '</div>';
265  }
266 
267  print '</div>';
268 
269  print '<div class="ticketlargemargin">';
270 }
static getValidAddress($address, $format, $encode=0, $maxnumberofemail=0)
Return a formatted address string for SMTP protocol.
Class to manage standard extra fields.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
ajax_autoselect($htmlname, $addlink='', $textonlink='Link')
Make content of an input box selected when we click into input field.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode='add', $filterorigmodule='')
Complete or removed entries into a head array (used to build tabs).
isModEnabled($module)
Is Dolibarr module enabled.
top_htmlhead($head, $title='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $disableforlogin=0, $disablenofollow=0, $disablenoindex=0)
Ouput html header of a page.
Definition: main.inc.php:1571
generate_random_id($car=16)
Generate a random id.
Definition: ticket.lib.php:194
llxHeaderTicket($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='')
Show header for public pages.
Definition: ticket.lib.php:216
ticketAdminPrepareHead()
Build tabs for admin page.
Definition: ticket.lib.php:31
showDirectPublicLink($object)
Return string with full Url.
Definition: ticket.lib.php:157
ticket_prepare_head($object)
Build tabs for a Ticket object.
Definition: ticket.lib.php:83