dolibarr 24.0.0-beta
create_ticket.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2016 Jean-François FERRY <hello@librethic.io>
3 * Copyright (C) 2016 Christophe Battarel <christophe@altairis.fr>
4 * Copyright (C) 2023 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
28/* We need object $user->default_values
29if (!defined('NOREQUIREUSER')) {
30 define('NOREQUIREUSER', '1');
31}*/
32if (!defined('NOREQUIREMENU')) {
33 define('NOREQUIREMENU', '1');
34}
35if (!defined('NOREQUIREHTML')) {
36 define('NOREQUIREHTML', '1');
37}
38if (!defined('NOLOGIN')) {
39 define("NOLOGIN", 1); // This means this output page does not require to be logged.
40}
41if (!defined('NOIPCHECK')) {
42 define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip
43}
44if (!defined('NOBROWSERNOTIF')) {
45 define('NOBROWSERNOTIF', '1');
46}
47
48// For MultiCompany module.
49// Do not use GETPOST here, function is not defined and define must be done before including main.inc.php
50// Because 2 entities can have the same ref.
51$entity = (!empty($_GET['entity']) ? (int) $_GET['entity'] : (!empty($_POST['entity']) ? (int) $_POST['entity'] : 1));
52if (is_numeric($entity)) {
53 define("DOLENTITY", $entity);
54}
55
56// Load Dolibarr environment
57require '../../main.inc.php';
58require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php';
59require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php';
60require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php';
61require_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
62require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
63require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
64require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
65require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
66require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
67require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
68
78// Load translation files required by the page
79$langs->loadLangs(array('companies', 'other', 'mails', 'ticket'));
80
81// Get parameters
82$id = GETPOSTINT('id');
83$msg_id = GETPOSTINT('msg_id');
84$socid = GETPOSTINT('socid');
85$suffix = "";
86
87$action = GETPOST('action', 'aZ09');
88$cancel = GETPOST('cancel');
89
90
91$backtopage = '';
92
93// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
94$hookmanager->initHooks(array('publicnewticketcard', 'globalcard'));
95
96$object = new Ticket($db);
97$extrafields = new ExtraFields($db);
98$contacts = array();
99$with_contact = null;
100if (getDolGlobalInt('TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST')) {
101 $with_contact = new Contact($db);
102}
103
104$extrafields->fetch_name_optionals_label($object->table_element);
105
106if (!isModEnabled('ticket')) {
107 httponly_accessforbidden('Module Ticket not enabled');
108}
109
110if (!is_object($user)) {
111 $user = new User($db);
112}
113
114$captchaobj = null;
115if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET')) {
116 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
117 $captcha = getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_HANDLER', 'standard');
118 // List of directories where we can find captcha handlers
119 $dirModCaptcha = array_merge(
120 array(
121 'main' => '/core/modules/security/captcha/'
122 ),
123 is_array($conf->modules_parts['captcha']) ? $conf->modules_parts['captcha'] : array()
124 );
125 $fullpathclassfile = '';
126 foreach ($dirModCaptcha as $dir) {
127 $fullpathclassfile = dol_buildpath($dir."modCaptcha".ucfirst($captcha).'.class.php', 0, 2);
128 if ($fullpathclassfile) {
129 break;
130 }
131 }
132 if ($fullpathclassfile) {
133 include_once $fullpathclassfile;
134 // Charging the numbering class
135 $classname = "modCaptcha".ucfirst($captcha);
136 if (class_exists($classname)) {
137 $captchaobj = new $classname($db, $conf, $langs, $user);
138 '@phan-var-force ModeleCaptcha $captchaobj';
140 } else {
141 print 'Error, the captcha handler class '.$classname.' was not found after the include';
142 }
143 } else {
144 print 'Error, the captcha handler '.$captcha.' has no class file found modCaptcha'.ucfirst($captcha);
145 }
146}
147
148/*
149 * Actions
150 */
151
152$parameters = array(
153 'id' => $id,
154);
155// Note that $action and $object may have been modified by some hooks
156$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
157if ($reshook < 0) {
158 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
159}
160// Add file in email form
161if (empty($reshook)) {
162 if ($cancel) {
163 $backtopage = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.'/public/ticket/');
164
165 header("Location: ".$backtopage);
166 exit;
167 }
168
169 if (GETPOST('addfile', 'alpha') && !GETPOST('save', 'alpha')) {
170 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
171
172 // Set tmp directory
173 // TODO Use a dedicated directory for temporary emails files
174 $vardir = $conf->ticket->dir_output;
175 $upload_dir_tmp = $vardir.'/temp/'.session_id();
176 if (!dol_is_dir($upload_dir_tmp)) {
177 dol_mkdir($upload_dir_tmp);
178 }
179
180 dol_add_file_process($upload_dir_tmp, 0, 0, 'addedfile', '', null, '', 0);
181 $action = 'create_ticket';
182 }
183
184 // Remove file
185 if (GETPOST('removedfile', 'alpha') && !GETPOST('save', 'alpha')) {
186 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
187
188 // Set tmp directory
189 // TODO Use a dedicated directory for temporary emails files
190 $vardir = $conf->ticket->dir_output.'/';
191 $upload_dir_tmp = $vardir.'/temp/'.session_id();
192
193 // TODO Delete only files that was uploaded from form
194 dol_remove_file_process(GETPOSTINT('removedfile'), 0, 0);
195 $action = 'create_ticket';
196 }
197
198 if ($action == 'create_ticket' && GETPOST('save', 'alpha')) { // Test on permission not required. This is a public form. Security is managed by mitigation.
199 $error = 0;
200 $cid = -1;
201 $origin_email = GETPOST('email', 'email');
202 if (empty($origin_email)) {
203 $error++;
204 array_push($object->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Email")));
205 $action = '';
206 } else {
207 // Search company saved with email
208 $searched_companies = $object->searchSocidByEmail($origin_email, 0);
209
210 // Look for an existing contact with this email address
211 // The first contact found is used to dtermine the tracking contact
212 $contacts = $object->searchContactByEmail($origin_email);
213 if (!is_array($contacts)) {
214 $contacts = array();
215 }
216
217 // Ensure that contact is active and select first active contact
218 foreach ($contacts as $key => $contact) {
219 if ((int) $contact->statut == 1) {
220 $cid = $key;
221 break;
222 }
223 }
224
225 // Option to require email exists to create ticket
226 if (getDolGlobalInt('TICKET_EMAIL_MUST_EXISTS') && ($cid < 0 || empty($contacts[$cid]->socid))) {
227 $error++;
228 array_push($object->errors, $langs->trans("ErrorEmailMustExistToCreateTicket"));
229 $action = '';
230 }
231 }
232
233 $contact_lastname = '';
234 $contact_firstname = '';
235 $company_name = '';
236 $contact_phone = '';
237 if ($with_contact) {
238 // set linked contact to add in form
239 if (/* is_array($contacts) && */ count($contacts) == 1) {
240 $with_contact = current($contacts);
241 }
242
243 // check mandatory fields on contact
244 $contact_lastname = trim(GETPOST('contact_lastname', 'alphanohtml'));
245 $contact_firstname = trim(GETPOST('contact_firstname', 'alphanohtml'));
246 $company_name = trim(GETPOST('company_name', 'alphanohtml'));
247 $contact_phone = trim(GETPOST('contact_phone', 'alphanohtml'));
248 if (!($with_contact->id > 0)) {
249 // check lastname
250 if (empty($contact_lastname)) {
251 $error++;
252 array_push($object->errors, $langs->trans('ErrorFieldRequired', $langs->transnoentities('Lastname')));
253 $action = '';
254 }
255 // check firstname
256 if (empty($contact_firstname)) {
257 $error++;
258 array_push($object->errors, $langs->trans('ErrorFieldRequired', $langs->transnoentities('Firstname')));
259 $action = '';
260 }
261 }
262 }
263
264
265 // Check value of input fields
266 $fieldsToCheck = [
267 'type_code' => ['check' => 'alpha', 'langs' => 'TicketTypeRequest'],
268 'category_code' => ['check' => 'alpha', 'langs' => 'TicketCategory'],
269 'severity_code' => ['check' => 'alpha', 'langs' => 'TicketSeverity'],
270 'subject' => ['check' => 'alphanohtml', 'langs' => 'Subject'],
271 ];
272 if (getDolGlobalInt('FCKEDITOR_ENABLE_TICKET') >= 2) { // 0=no reich text editor, 1=allowed on backoffice only, 2=allowed on backoffice and public page (very dangerous)
273 $fieldsToCheck['message'] = ['check' => 'restricthtml', 'langs' => 'Message'];
274 } else {
275 $fieldsToCheck['message'] = ['check' => 'alphanohtml', 'langs' => 'Message'];
276 }
277 FormTicket::checkRequiredFields($fieldsToCheck, $error);
278
279 // Check email address
280 if (!empty($origin_email) && !isValidEmail($origin_email)) {
281 $error++;
282 array_push($object->errors, $langs->trans("ErrorBadEmailAddress", $langs->transnoentities("Email")));
283 $action = '';
284 }
285
286 // Check Captcha code if is enabled
287 $ok = false;
288 if (getDolGlobalString('MAIN_SECURITY_ENABLECAPTCHA_TICKET') && is_object($captchaobj)) {
289 if (method_exists($captchaobj, 'validateCodeAfterLoginSubmit')) {
290 $ok = $captchaobj->validateCodeAfterLoginSubmit(); // @phan-suppress-current-line PhanUndeclaredMethod
291 } else {
292 print 'Error, the captcha handler '.get_class($captchaobj).' does not have any method validateCodeAfterLoginSubmit()';
293 }
294 if (!$ok) {
295 $error++;
296 array_push($object->errors, $langs->trans("ErrorBadValueForCode"));
297 $action = '';
298 }
299 }
300
301 if (!$error) {
302 $object->type_code = GETPOST("type_code", 'aZ09');
303 $object->category_code = GETPOST("category_code", 'aZ09');
304 $object->severity_code = GETPOST("severity_code", 'aZ09');
305 $object->ip = getUserRemoteIP();
306
307 $nb_post_max = getDolGlobalInt("MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
308 $now = dol_now();
309 $minmonthpost = dol_time_plus_duree($now, -1, "m");
310
311 // Calculate nb of post for IP
312 $nb_post_ip = 0;
313 if ($nb_post_max > 0) { // Calculate only if there is a limit to check
314 $sql = "SELECT COUNT(ref) as nb_tickets";
315 $sql .= " FROM ".MAIN_DB_PREFIX."ticket";
316 $sql .= " WHERE ip = '".$db->escape($object->ip)."'";
317 $sql .= " AND datec > '".$db->idate($minmonthpost)."'";
318 $resql = $db->query($sql);
319 if ($resql) {
320 $num = $db->num_rows($resql);
321 $i = 0;
322 while ($i < $num) {
323 $i++;
324 $obj = $db->fetch_object($resql);
325 $nb_post_ip = $obj->nb_tickets;
326 }
327 }
328 }
329
330 $object->track_id = generate_random_id(16);
331
332 $object->db->begin();
333
334 $object->subject = GETPOST("subject", "alphanohtml");
335 if (getDolGlobalInt('FCKEDITOR_ENABLE_TICKET') >= 2) { // 0=no reich text editor, 1=allowed on backoffice only, 2=allowed on backoffice and public page (very dangerous)
336 $object->message = GETPOST("message", "restricthtml");
337 } else {
338 $object->message = GETPOST("message", "alphanohtml");
339 }
340 $object->origin_email = $origin_email;
341 $object->email_from = $origin_email;
342
343 $object->type_code = GETPOST("type_code", 'aZ09');
344 $object->category_code = GETPOST("category_code", 'aZ09');
345 $object->severity_code = GETPOST("severity_code", 'aZ09');
346
347 // create third-party with contact
348 $usertoassign = 0;
349 if ($with_contact && !($with_contact->id > 0)) {
350 $company = new Societe($db);
351 if (!empty($company_name)) {
352 $company->name = $company_name;
353 } else {
354 $company->particulier = 1;
355 $company->name = dolGetFirstLastname($contact_firstname, $contact_lastname);
356 }
357 $result = $company->create($user);
358 if ($result < 0) {
359 $error++;
360 $errors = ($company->error ? array($company->error) : $company->errors);
361 $object->errors = array_merge($object->errors, $errors);
362 $action = 'create_ticket';
363 }
364
365 // create contact and link to this new company
366 if (!$error) {
367 $with_contact->email = $origin_email;
368 $with_contact->lastname = $contact_lastname;
369 $with_contact->firstname = $contact_firstname;
370 $with_contact->socid = $company->id;
371 $with_contact->phone_pro = $contact_phone;
372 $result = $with_contact->create($user);
373 if ($result < 0) {
374 $error++;
375 $errors = ($with_contact->error ? array($with_contact->error) : $with_contact->errors);
376 $object->errors = array_merge($object->errors, $errors);
377 $action = 'create_ticket';
378 } else {
379 $contacts = array($with_contact);
380 }
381 }
382 }
383
384 if (!empty($searched_companies) && is_array($searched_companies)) {
385 $object->fk_soc = $searched_companies[0]->id;
386 }
387
388 if (/* is_array($contacts) && */ count($contacts) > 0 && $cid >= 0) {
389 $object->fk_soc = $contacts[$cid]->socid;
390 $usertoassign = $contacts[$cid]->id;
391 }
392
393 $ret = $extrafields->setOptionalsFromPost(null, $object);
394
395 // Generate new ref
396 $object->ref = $object->getDefaultRef();
397
398 $object->context['disableticketemail'] = 1; // Disable emails sent by ticket trigger when creation is done from this page, emails are already sent later
399 $object->context['contactid'] = GETPOSTINT('contactid'); // Disable emails sent by ticket trigger when creation is done from this page, emails are already sent later
400
401 $object->context['createdfrompublicinterface'] = 1; // To make a difference between a ticket created from the public interface and a ticket directly created from dolibarr
402
403 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
404 $error++;
405 array_push($object->errors, $langs->trans("AlreadyTooMuchPostOnThisIPAdress"));
406 $action = 'create_ticket';
407 }
408
409 if (!$error) {
410 // Creation of the ticket
411 $id = $object->create($user);
412 if ($id <= 0) {
413 $error++;
414 $errors = ($object->error ? array($object->error) : $object->errors);
415 if ($object->error) {
416 array_push($object->errors, $object->error);
417 }
418 $action = 'create_ticket';
419 }
420 }
421
422 if (!$error && $id > 0) {
423 if ($usertoassign > 0) {
424 $object->add_contact($usertoassign, "SUPPORTCLI", 'external', 0);
425 }
426
427 if (!$error) {
428 $object->db->commit();
429 $action = "infos_success";
430 } else {
431 $object->db->rollback();
432 setEventMessages($object->error, $object->errors, 'errors');
433 $action = 'create_ticket';
434 }
435
436 if (!$error) {
437 $res = $object->fetch($id);
438 if ($res) {
439 // Create form object
440 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
441 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
442 $formmail = new FormMail($db);
443
444 // Init to avoid errors
445 $filepath = array();
446 $filename = array();
447 $mimetype = array();
448
449 $attachedfiles = $formmail->get_attached_files();
450 $filepath = $attachedfiles['paths'];
451 $filename = $attachedfiles['names'];
452 $mimetype = $attachedfiles['mimes'];
453
454 // Send email to customer
455 $appli = $mysoc->name;
456
457 $subject = '['.$appli.'] '.$langs->transnoentities('TicketNewEmailSubject', $object->ref, $object->track_id);
458 $message = (getDolGlobalString('TICKET_MESSAGE_MAIL_NEW') !== '' ? getDolGlobalString('TICKET_MESSAGE_MAIL_NEW') : $langs->transnoentities('TicketNewEmailBody')).'<br><br>';
459 $message .= $langs->transnoentities('TicketNewEmailBodyInfosTicket').'<br>';
460
461 $url_public_ticket = getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', dol_buildpath('/public/ticket/', 2)).'view.php?track_id='.$object->track_id;
462 $infos_new_ticket = $langs->transnoentities('TicketNewEmailBodyInfosTrackId', '<a href="'.$url_public_ticket.'" rel="nofollow noopener">'.$object->track_id.'</a>').'<br>';
463 $infos_new_ticket .= $langs->transnoentities('TicketNewEmailBodyInfosTrackUrl').'<br><br>';
464
465 $message .= $infos_new_ticket;
466 $message .= getDolGlobalString('TICKET_MESSAGE_MAIL_SIGNATURE', $langs->transnoentities('TicketMessageMailSignatureText', $mysoc->name));
467
468 $sendto = GETPOST('email', 'alpha');
469
470 $from = getDolGlobalString('MAIN_INFO_SOCIETE_NOM') . ' <'.getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM').'>';
471 $replyto = $from;
472 $sendtocc = '';
473 $deliveryreceipt = 0;
474
475 $old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO');
476 if ($old_MAIN_MAIL_AUTOCOPY_TO !== '') {
477 $conf->global->MAIN_MAIL_AUTOCOPY_TO = '';
478 }
479 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
480 $mailfile = new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1, '', '', 'tic'.$object->id, '', 'ticket');
481 if ($mailfile->error || !empty($mailfile->errors)) {
482 setEventMessages($mailfile->error, $mailfile->errors, 'errors');
483 } else {
484 $result = $mailfile->sendfile();
485 }
486 if ($old_MAIN_MAIL_AUTOCOPY_TO !== '') {
487 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
488 }
489
490 // Send email to TICKET_NOTIFICATION_EMAIL_TO
491 $sendto = getDolGlobalString('TICKET_NOTIFICATION_EMAIL_TO');
492 if ($sendto) {
493 $appli = $mysoc->name;
494
495 $subject = '['.$appli.'] '.$langs->transnoentities('TicketNewEmailSubjectAdmin', $object->ref, $object->track_id);
496 $message_admin = $langs->transnoentities('TicketNewEmailBodyAdmin', $object->track_id).'<br><br>';
497 $message_admin .= '<ul><li>'.$langs->trans('Title').' : '.$object->subject.'</li>';
498 $message_admin .= '<li>'.$langs->trans('Type').' : '.$object->type_label.'</li>';
499 $message_admin .= '<li>'.$langs->trans('Category').' : '.$object->category_label.'</li>';
500 $message_admin .= '<li>'.$langs->trans('Severity').' : '.$object->severity_label.'</li>';
501 $message_admin .= '<li>'.$langs->trans('From').' : '.$object->origin_email.'</li>';
502 // Extrafields
503 $extrafields->fetch_name_optionals_label($object->table_element);
504 if (is_array($object->array_options) && count($object->array_options) > 0) {
505 foreach ($object->array_options as $key => $value) {
506 $key = substr($key, 8); // remove "options_"
507 $message_admin .= '<li>'.$langs->trans($extrafields->attributes[$object->table_element]['label'][$key]).' : '.$extrafields->showOutputField($key, $value, '', $object->table_element).'</li>';
508 }
509 }
510 $message_admin .= '</ul>';
511
512 $message_admin .= '<p>'.$langs->trans('Message').' : <br>'.dolPrintText($object->message).'</p>';
513 $message_admin .= '<p><a href="'.dol_buildpath('/ticket/card.php', 2).'?track_id='.$object->track_id.'" rel="nofollow noopener">'.$langs->trans('SeeThisTicketIntomanagementInterface').'</a></p>';
514
515 $from = getDolGlobalString('MAIN_INFO_SOCIETE_NOM') . ' <' . getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM').'>';
516 $replyto = $from;
517
518 $old_MAIN_MAIL_AUTOCOPY_TO = getDolGlobalString('TICKET_DISABLE_MAIL_AUTOCOPY_TO');
519 if ($old_MAIN_MAIL_AUTOCOPY_TO !== '') {
520 $conf->global->MAIN_MAIL_AUTOCOPY_TO = '';
521 }
522 include_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
523 $mailfile = new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc, '', $deliveryreceipt, -1, '', '', 'tic'.$object->id, '', 'ticket');
524 if ($mailfile->error || !empty($mailfile->errors)) {
525 setEventMessages($mailfile->error, $mailfile->errors, 'errors');
526 } else {
527 $result = $mailfile->sendfile();
528 }
529 if ($old_MAIN_MAIL_AUTOCOPY_TO !== '') {
530 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
531 }
532 }
533 }
534
535 // Copy files into ticket directory
536 $object->copyFilesForTicket('');
537
538 //setEventMessages($langs->trans('YourTicketSuccessfullySaved'), null, 'mesgs');
539
540 // Make a redirect to avoid to have ticket submitted twice if we make back
541 $messagetoshow = $langs->trans('MesgInfosPublicTicketCreatedWithTrackId', '{s1}', '{s2}');
542 $messagetoshow = str_replace(array('{s1}', '{s2}'), array('<strong>'.$object->track_id.'</strong>', '<strong>'.$object->ref.'</strong>'), $messagetoshow);
543 setEventMessages($messagetoshow, null, 'warnings');
544 setEventMessages($langs->trans('PleaseRememberThisId'), null, 'warnings');
545
546 header("Location: index.php".(!empty($entity) && isModEnabled('multicompany') ? '?entity='.$entity : ''));
547 exit;
548 }
549 } else {
550 setEventMessages($object->error, $object->errors, 'errors');
551 }
552 }
553 }
554}
555if (!empty($object->errors) || !empty($object->error)) {
556 setEventMessages($object->error, $object->errors, 'errors');
557}
558
559
560/*
561 * View
562 */
563
564$form = new Form($db);
565$formticket = new FormTicket($db);
566
567if (!getDolGlobalInt('TICKET_ENABLE_PUBLIC_INTERFACE')) {
568 print '<div class="error">'.$langs->trans('TicketPublicInterfaceForbidden').'</div>';
569 $db->close();
570 exit();
571}
572
573$arrayofjs = array();
574
575$arrayofcss = array(getDolGlobalString('TICKET_URL_PUBLIC_INTERFACE', '/public/ticket/').'css/styles.css.php');
576
577llxHeaderTicket($langs->trans("CreateTicket"), "", 0, 0, $arrayofjs, $arrayofcss);
578
579
580print '<div class="ticketpublicarea ticketlargemargin">';
581
582if ($action != "infos_success") {
583 $formticket->withfromsocid = isset($socid) ? $socid : $user->socid;
584 $formticket->withtitletopic = 1;
585 $formticket->withcompany = 0;
586 $formticket->withusercreate = 1;
587 $formticket->fk_user_create = 0;
588 $formticket->withemail = 1;
589 $formticket->ispublic = 1;
590 $formticket->withfile = 2;
591 $formticket->action = 'create_ticket';
592 $formticket->withcancel = 1;
593
594 $formticket->param = array('returnurl' => $_SERVER['PHP_SELF'].($conf->entity > 1 ? '?entity='.$conf->entity : ''));
595
596 print load_fiche_titre($langs->trans('NewTicket'), '', '', 0, '', 'marginleftonly');
597
598 if (!getDolGlobalString('TICKET_NOTIFICATION_EMAIL_FROM')) {
599 $langs->load("errors");
600 print '<div class="error">';
601 print $langs->trans("ErrorFieldRequired", $langs->transnoentities("TicketEmailNotificationFrom")).'<br>';
602 print $langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentities("Ticket"));
603 print '</div>';
604 } else {
605 //print '<div class="info marginleftonly marginrightonly">'.$langs->trans('TicketPublicInfoCreateTicket').'</div>';
606 $formticket->showForm(0, ($action ? $action : 'create'), 1, $with_contact, '', $object);
607 }
608}
609
610print '</div>';
611
612print '<br>';
613
614if (getDolGlobalInt('TICKET_SHOW_COMPANY_FOOTER')) {
615 // End of page
616 htmlPrintOnlineFooter($mysoc, $langs, 0, $suffix, $object);
617}
618
619llxFooter('', 'public');
620
621$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class to manage a HTML form to send a unitary email Usage: $formail = new FormMail($db) $formmail->pr...
static checkRequiredFields(array $fields, int &$errors)
Check required fields.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
htmlPrintOnlineFooter($fromcompany, $langs, $addformmessage=0, $suffix='', $object=null)
Show footer of company in HTML public pages.
global $mysoc
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:126
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
dol_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=0, $keyforsourcefile='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null, $forceFullTextIndexation='', $mode=0)
Get and save an upload file (for example after submitting a new file in a mail form).
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid='')
Remove an uploaded file (for example after submitting a new file a mail form).
dol_is_dir($folder)
Test if filename is a directory.
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolPrintText($s)
Return a string label (possible on several lines and that should not contains any HTML) ready to be o...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Class to generate the form for creating a new ticket.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
generate_random_id($car=16)
Generate a random id.
llxHeaderTicket($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs=[], $arrayofcss=[])
Show http header, open body tag and show HTML header banner for public pages for tickets.