32if (!defined(
'NOREQUIREMENU')) {
33 define(
'NOREQUIREMENU',
'1');
35if (!defined(
'NOREQUIREHTML')) {
36 define(
'NOREQUIREHTML',
'1');
38if (!defined(
'NOLOGIN')) {
41if (!defined(
'NOIPCHECK')) {
42 define(
'NOIPCHECK',
'1');
44if (!defined(
'NOBROWSERNOTIF')) {
45 define(
'NOBROWSERNOTIF',
'1');
51$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
52if (is_numeric($entity)) {
53 define(
"DOLENTITY", $entity);
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';
79$langs->loadLangs(array(
'companies',
'other',
'mails',
'ticket'));
87$action =
GETPOST(
'action',
'aZ09');
94$hookmanager->initHooks(array(
'publicnewticketcard',
'globalcard'));
100if (
getDolGlobalInt(
'TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST')) {
101 $with_contact =
new Contact($db);
104$extrafields->fetch_name_optionals_label(
$object->table_element);
110if (!is_object($user)) {
111 $user =
new User($db);
116 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security2.lib.php';
119 $dirModCaptcha = array_merge(
121 'main' =>
'/core/modules/security/captcha/'
123 is_array($conf->modules_parts[
'captcha']) ? $conf->modules_parts[
'captcha'] : array()
125 $fullpathclassfile =
'';
126 foreach ($dirModCaptcha as $dir) {
127 $fullpathclassfile =
dol_buildpath($dir.
"modCaptcha".ucfirst($captcha).
'.class.php', 0, 2);
128 if ($fullpathclassfile) {
132 if ($fullpathclassfile) {
133 include_once $fullpathclassfile;
135 $classname =
"modCaptcha".ucfirst($captcha);
136 if (class_exists($classname)) {
137 $captchaobj =
new $classname($db, $conf, $langs, $user);
138 '@phan-var-force ModeleCaptcha $captchaobj';
141 print
'Error, the captcha handler class '.$classname.
' was not found after the include';
144 print
'Error, the captcha handler '.$captcha.
' has no class file found modCaptcha'.ucfirst($captcha);
156$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
161if (empty($reshook)) {
163 $backtopage =
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.
'/public/ticket/');
165 header(
"Location: ".$backtopage);
170 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
174 $vardir = $conf->ticket->dir_output;
175 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
181 $action =
'create_ticket';
185 if (
GETPOST(
'removedfile',
'alpha') && !
GETPOST(
'save',
'alpha')) {
186 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
190 $vardir = $conf->ticket->dir_output.
'/';
191 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
195 $action =
'create_ticket';
198 if ($action ==
'create_ticket' &&
GETPOST(
'save',
'alpha')) {
201 $origin_email =
GETPOST(
'email',
'email');
202 if (empty($origin_email)) {
204 array_push(
$object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Email")));
208 $searched_companies =
$object->searchSocidByEmail($origin_email, 0);
212 $contacts =
$object->searchContactByEmail($origin_email);
213 if (!is_array($contacts)) {
218 foreach ($contacts as $key => $contact) {
219 if ((
int) $contact->statut == 1) {
226 if (
getDolGlobalInt(
'TICKET_EMAIL_MUST_EXISTS') && ($cid < 0 || empty($contacts[$cid]->socid))) {
228 array_push(
$object->errors, $langs->trans(
"ErrorEmailMustExistToCreateTicket"));
233 $contact_lastname =
'';
234 $contact_firstname =
'';
239 if ( count($contacts) == 1) {
240 $with_contact = current($contacts);
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)) {
250 if (empty($contact_lastname)) {
252 array_push(
$object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Lastname')));
256 if (empty($contact_firstname)) {
258 array_push(
$object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Firstname')));
266 'type_code' => [
'check' =>
'alpha',
'langs' =>
'TicketTypeRequest'],
267 'category_code' => [
'check' =>
'alpha',
'langs' =>
'TicketCategory'],
268 'severity_code' => [
'check' =>
'alpha',
'langs' =>
'TicketSeverity'],
269 'subject' => [
'check' =>
'alphanohtml',
'langs' =>
'Subject'],
270 'message' => [
'check' =>
'restricthtml',
'langs' =>
'Message']
276 if (!empty($origin_email) && !
isValidEmail($origin_email)) {
278 array_push(
$object->errors, $langs->trans(
"ErrorBadEmailAddress", $langs->transnoentities(
"Email")));
284 if (
getDolGlobalString(
'MAIN_SECURITY_ENABLECAPTCHA_TICKET') && is_object($captchaobj)) {
285 if (method_exists($captchaobj,
'validateCodeAfterLoginSubmit')) {
286 $ok = $captchaobj->validateCodeAfterLoginSubmit();
288 print
'Error, the captcha handler '.get_class($captchaobj).
' does not have any method validateCodeAfterLoginSubmit()';
292 array_push(
$object->errors, $langs->trans(
"ErrorBadValueForCode"));
303 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
309 if ($nb_post_max > 0) {
310 $sql =
"SELECT COUNT(ref) as nb_tickets";
311 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket";
312 $sql .=
" WHERE ip = '".$db->escape(
$object->ip).
"'";
313 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
314 $resql = $db->query($sql);
316 $num = $db->num_rows($resql);
320 $obj = $db->fetch_object($resql);
321 $nb_post_ip = $obj->nb_tickets;
332 $object->origin_email = $origin_email;
333 $object->email_from = $origin_email;
341 if ($with_contact && !($with_contact->id > 0)) {
343 if (!empty($company_name)) {
344 $company->name = $company_name;
346 $company->particulier = 1;
349 $result = $company->create($user);
352 $errors = ($company->error ? array($company->error) : $company->errors);
354 $action =
'create_ticket';
359 $with_contact->email = $origin_email;
360 $with_contact->lastname = $contact_lastname;
361 $with_contact->firstname = $contact_firstname;
362 $with_contact->socid = $company->id;
363 $with_contact->phone_pro = $contact_phone;
364 $result = $with_contact->create($user);
367 $errors = ($with_contact->error ? array($with_contact->error) : $with_contact->errors);
369 $action =
'create_ticket';
371 $contacts = array($with_contact);
376 if (!empty($searched_companies) && is_array($searched_companies)) {
377 $object->fk_soc = $searched_companies[0]->id;
380 if ( count($contacts) > 0 && $cid >= 0) {
381 $object->fk_soc = $contacts[$cid]->socid;
382 $usertoassign = $contacts[$cid]->id;
385 $ret = $extrafields->setOptionalsFromPost(
null, $object);
390 $object->context[
'disableticketemail'] = 1;
393 $object->context[
'createdfrompublicinterface'] = 1;
395 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
397 array_push(
$object->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
398 $action =
'create_ticket';
410 $action =
'create_ticket';
414 if (!$error && $id > 0) {
415 if ($usertoassign > 0) {
416 $object->add_contact($usertoassign,
"SUPPORTCLI",
'external', 0);
421 $action =
"infos_success";
425 $action =
'create_ticket';
432 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
433 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
441 $attachedfiles = $formmail->get_attached_files();
442 $filepath = $attachedfiles[
'paths'];
443 $filename = $attachedfiles[
'names'];
444 $mimetype = $attachedfiles[
'mimes'];
449 $subject =
'['.$appli.
'] '.$langs->transnoentities(
'TicketNewEmailSubject',
$object->ref,
$object->track_id);
451 $message .= $langs->transnoentities(
'TicketNewEmailBodyInfosTicket').
'<br>';
454 $infos_new_ticket = $langs->transnoentities(
'TicketNewEmailBodyInfosTrackId',
'<a href="'.$url_public_ticket.
'" rel="nofollow noopener">'.
$object->track_id.
'</a>').
'<br>';
455 $infos_new_ticket .= $langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrl').
'<br><br>';
457 $message .= $infos_new_ticket;
458 $message .=
getDolGlobalString(
'TICKET_MESSAGE_MAIL_SIGNATURE', $langs->transnoentities(
'TicketMessageMailSignatureText',
$mysoc->name));
460 $sendto =
GETPOST(
'email',
'alpha');
462 $from =
getDolGlobalString(
'MAIN_INFO_SOCIETE_NOM') .
' <'.getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_FROM').
'>';
465 $deliveryreceipt = 0;
468 if ($old_MAIN_MAIL_AUTOCOPY_TO !==
'') {
469 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
471 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
472 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.
$object->id,
'',
'ticket');
473 if ($mailfile->error || !empty($mailfile->errors)) {
476 $result = $mailfile->sendfile();
478 if ($old_MAIN_MAIL_AUTOCOPY_TO !==
'') {
479 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
487 $subject =
'['.$appli.
'] '.$langs->transnoentities(
'TicketNewEmailSubjectAdmin',
$object->ref,
$object->track_id);
488 $message_admin = $langs->transnoentities(
'TicketNewEmailBodyAdmin',
$object->track_id).
'<br><br>';
489 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
490 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.
$object->type_label.
'</li>';
491 $message_admin .=
'<li>'.$langs->trans(
'Category').
' : '.
$object->category_label.
'</li>';
492 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.
$object->severity_label.
'</li>';
493 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.
$object->origin_email.
'</li>';
495 $extrafields->fetch_name_optionals_label(
$object->table_element);
496 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
497 foreach (
$object->array_options as $key => $value) {
498 $key = substr($key, 8);
499 $message_admin .=
'<li>'.$langs->trans($extrafields->attributes[
$object->table_element][
'label'][$key]).
' : '.$extrafields->showOutputField($key, $value,
'',
$object->table_element).
'</li>';
502 $message_admin .=
'</ul>';
504 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br>'.
$object->message.
'</p>';
505 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.
$object->track_id.
'" rel="nofollow noopener">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
511 if ($old_MAIN_MAIL_AUTOCOPY_TO !==
'') {
512 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
514 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
515 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.
$object->id,
'',
'ticket');
516 if ($mailfile->error || !empty($mailfile->errors)) {
519 $result = $mailfile->sendfile();
521 if ($old_MAIN_MAIL_AUTOCOPY_TO !==
'') {
522 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
528 $object->copyFilesForTicket(
'');
533 $messagetoshow = $langs->trans(
'MesgInfosPublicTicketCreatedWithTrackId',
'{s1}',
'{s2}');
534 $messagetoshow = str_replace(array(
'{s1}',
'{s2}'), array(
'<strong>'.
$object->track_id.
'</strong>',
'<strong>'.$object->ref.
'</strong>'), $messagetoshow);
538 header(
"Location: index.php".(!empty($entity) &&
isModEnabled(
'multicompany') ?
'?entity='.$entity :
''));
556$form =
new Form($db);
560 print
'<div class="error">'.$langs->trans(
'TicketPublicInterfaceForbidden').
'</div>';
567$arrayofcss = array(
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE',
'/public/ticket/').
'css/styles.css.php');
569llxHeaderTicket($langs->trans(
"CreateTicket"),
"", 0, 0, $arrayofjs, $arrayofcss);
572print
'<div class="ticketpublicarea ticketlargemargin">';
574if ($action !=
"infos_success") {
575 $formticket->withfromsocid = isset($socid) ? $socid : $user->socid;
576 $formticket->withtitletopic = 1;
577 $formticket->withcompany = 0;
578 $formticket->withusercreate = 1;
579 $formticket->fk_user_create = 0;
580 $formticket->withemail = 1;
581 $formticket->ispublic = 1;
582 $formticket->withfile = 2;
583 $formticket->action =
'create_ticket';
584 $formticket->withcancel = 1;
586 $formticket->param = array(
'returnurl' => $_SERVER[
'PHP_SELF'].($conf->entity > 1 ?
'?entity='.$conf->entity :
''));
588 print
load_fiche_titre($langs->trans(
'NewTicket'),
'',
'', 0,
'',
'marginleftonly');
591 $langs->load(
"errors");
592 print
'<div class="error">';
593 print $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TicketEmailNotificationFrom")).
'<br>';
594 print $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentities(
"Ticket"));
598 $formticket->showForm(0, ($action ? $action :
'create'), 1, $with_contact,
'',
$object);
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
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.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
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.
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.