30if (!defined(
'NOREQUIREMENU')) {
31 define(
'NOREQUIREMENU',
'1');
33if (!defined(
'NOREQUIREHTML')) {
34 define(
'NOREQUIREHTML',
'1');
36if (!defined(
'NOLOGIN')) {
39if (!defined(
'NOIPCHECK')) {
40 define(
'NOIPCHECK',
'1');
42if (!defined(
'NOBROWSERNOTIF')) {
43 define(
'NOBROWSERNOTIF',
'1');
48$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
49if (is_numeric($entity)) {
50 define(
"DOLENTITY", $entity);
54require
'../../main.inc.php';
55require_once DOL_DOCUMENT_ROOT.
'/ticket/class/actions_ticket.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formticket.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/lib/ticket.lib.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
61require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
62require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
63require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
64require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
67$langs->loadLangs(array(
'companies',
'other',
'mails',
'ticket'));
71$msg_id =
GETPOST(
'msg_id',
'int');
72$socid =
GETPOST(
'socid',
'int');
75$action =
GETPOST(
'action',
'aZ09');
76$cancel =
GETPOST(
'cancel',
'aZ09');
81$hookmanager->initHooks(array(
'publicnewticketcard',
'globalcard'));
87if (!empty($conf->global->TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST)) {
88 $with_contact =
new Contact($db);
91$extrafields->fetch_name_optionals_label($object->table_element);
93if (!isModEnabled(
'ticket')) {
106$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
111if (empty($reshook)) {
113 $backtopage =
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.
'/public/ticket/');
115 header(
"Location: ".$backtopage);
120 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
124 $vardir = $conf->ticket->dir_output;
125 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
131 $action =
'create_ticket';
135 if (
GETPOST(
'removedfile',
'alpha') && !
GETPOST(
'save',
'alpha')) {
136 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
140 $vardir = $conf->ticket->dir_output.
'/';
141 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
145 $action =
'create_ticket';
148 if ($action ==
'create_ticket' &&
GETPOST(
'save',
'alpha')) {
150 $origin_email =
GETPOST(
'email',
'alpha');
151 if (empty($origin_email)) {
153 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Email")));
157 $searched_companies = $object->searchSocidByEmail($origin_email,
'0');
161 $contacts = $object->searchContactByEmail($origin_email);
165 foreach ($contacts as $key => $contact) {
166 if ((
int) $contact->statut == 1) {
173 if (!empty($conf->global->TICKET_EMAIL_MUST_EXISTS) && ($cid < 0 || empty($contacts[$cid]->socid))) {
175 array_push($object->errors, $langs->trans(
"ErrorEmailMustExistToCreateTicket"));
180 $contact_lastname =
'';
181 $contact_firstname =
'';
186 if (is_array($contacts) && count($contacts) == 1) {
187 $with_contact = current($contacts);
191 $contact_lastname = trim(
GETPOST(
'contact_lastname',
'alphanohtml'));
192 $contact_firstname = trim(
GETPOST(
'contact_firstname',
'alphanohtml'));
193 $company_name = trim(
GETPOST(
'company_name',
'alphanohtml'));
194 $contact_phone = trim(
GETPOST(
'contact_phone',
'alphanohtml'));
195 if (!($with_contact->id > 0)) {
197 if (empty($contact_lastname)) {
199 array_push($object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Lastname')));
203 if (empty($contact_firstname)) {
205 array_push($object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Firstname')));
211 if (!
GETPOST(
"subject",
"restricthtml")) {
213 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Subject")));
216 if (!
GETPOST(
"message",
"restricthtml")) {
218 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Message")));
223 if (!empty($origin_email) && !
isValidEmail($origin_email)) {
225 array_push($object->errors, $langs->trans(
"ErrorBadEmailAddress", $langs->transnoentities(
"email")));
230 if (!empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA_TICKET)) {
231 $sessionkey =
'dol_antispam_value';
232 $ok = (array_key_exists($sessionkey, $_SESSION) ===
true && (strtolower($_SESSION[$sessionkey]) === strtolower(
GETPOST(
'code',
'restricthtml'))));
235 array_push($object->errors, $langs->trans(
"ErrorBadValueForCode"));
241 $object->type_code =
GETPOST(
"type_code",
'aZ09');
242 $object->category_code =
GETPOST(
"category_code",
'aZ09');
243 $object->severity_code =
GETPOST(
"severity_code",
'aZ09');
246 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
252 if ($nb_post_max > 0) {
253 $sql =
"SELECT COUNT(ref) as nb_tickets";
254 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket";
255 $sql .=
" WHERE ip = '".$db->escape($object->ip).
"'";
256 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
257 $resql = $db->query($sql);
259 $num = $db->num_rows($resql);
263 $obj = $db->fetch_object($resql);
264 $nb_post_ip = $obj->nb_tickets;
271 $object->db->begin();
273 $object->subject =
GETPOST(
"subject",
"restricthtml");
274 $object->message =
GETPOST(
"message",
"restricthtml");
275 $object->origin_email = $origin_email;
277 $object->type_code =
GETPOST(
"type_code",
'aZ09');
278 $object->category_code =
GETPOST(
"category_code",
'aZ09');
279 $object->severity_code =
GETPOST(
"severity_code",
'aZ09');
281 if (!is_object($user)) {
282 $user =
new User($db);
287 if ($with_contact && !($with_contact->id > 0)) {
289 if (!empty($company_name)) {
290 $company->name = $company_name;
292 $company->particulier = 1;
295 $result = $company->create($user);
298 $errors = ($company->error ? array($company->error) : $company->errors);
299 array_push($object->errors, $errors);
300 $action =
'create_ticket';
305 $with_contact->email = $origin_email;
306 $with_contact->lastname = $contact_lastname;
307 $with_contact->firstname = $contact_firstname;
308 $with_contact->socid = $company->id;
309 $with_contact->phone_pro = $contact_phone;
310 $result = $with_contact->create($user);
313 $errors = ($with_contact->error ? array($with_contact->error) : $with_contact->errors);
314 array_push($object->errors, $errors);
315 $action =
'create_ticket';
317 $contacts = array($with_contact);
322 if (!empty($searched_companies) && is_array($searched_companies)) {
323 $object->fk_soc = $searched_companies[0]->id;
326 if (is_array($contacts) && count($contacts) > 0 && $cid >= 0) {
327 $object->fk_soc = $contacts[$cid]->socid;
328 $usertoassign = $contacts[$cid]->id;
331 $ret = $extrafields->setOptionalsFromPost(
null, $object);
334 $object->ref = $object->getDefaultRef();
336 $object->context[
'disableticketemail'] = 1;
338 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
340 $errors = array($langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
341 array_push($object->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
342 $action =
'create_ticket';
347 $id = $object->create($user);
350 $errors = ($object->error ? array($object->error) : $object->errors);
351 array_push($object->errors, $object->error ? array($object->error) : $object->errors);
352 $action =
'create_ticket';
356 if (!$error && $id > 0) {
357 if ($usertoassign > 0) {
358 $object->add_contact($usertoassign,
"SUPPORTCLI",
'external', 0);
362 $object->db->commit();
363 $action =
"infos_success";
365 $object->db->rollback();
367 $action =
'create_ticket';
371 $res = $object->fetch($id);
374 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
375 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
383 $attachedfiles = $formmail->get_attached_files();
384 $filepath = $attachedfiles[
'paths'];
385 $filename = $attachedfiles[
'names'];
386 $mimetype = $attachedfiles[
'mimes'];
390 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketNewEmailSubject', $object->ref, $object->track_id);
391 $message = ($conf->global->TICKET_MESSAGE_MAIL_NEW ? $conf->global->TICKET_MESSAGE_MAIL_NEW : $langs->transnoentities(
'TicketNewEmailBody')).
'<br><br>';
392 $message .= $langs->transnoentities(
'TicketNewEmailBodyInfosTicket').
'<br>';
395 $infos_new_ticket = $langs->transnoentities(
'TicketNewEmailBodyInfosTrackId',
'<a href="'.$url_public_ticket.
'" rel="nofollow noopener">'.$object->track_id.
'</a>').
'<br>';
396 $infos_new_ticket .= $langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrl').
'<br><br>';
398 $message .= $infos_new_ticket;
399 $message .=
getDolGlobalString(
'TICKET_MESSAGE_MAIL_SIGNATURE', $langs->transnoentities(
'TicketMessageMailSignatureText', $mysoc->name));
401 $sendto =
GETPOST(
'email',
'alpha');
403 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
' <'.
getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_FROM').
'>';
406 $deliveryreceipt = 0;
408 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
409 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
410 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
412 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
413 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.$object->id,
'',
'ticket');
414 if ($mailfile->error || !empty($mailfile->errors)) {
417 $result = $mailfile->sendfile();
419 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
420 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
424 $sendto = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
426 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketNewEmailSubjectAdmin', $object->ref, $object->track_id);
427 $message_admin = $langs->transnoentities(
'TicketNewEmailBodyAdmin', $object->track_id).
'<br><br>';
428 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
429 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$object->type_label.
'</li>';
430 $message_admin .=
'<li>'.$langs->trans(
'Category').
' : '.$object->category_label.
'</li>';
431 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$object->severity_label.
'</li>';
432 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.$object->origin_email.
'</li>';
434 $extrafields->fetch_name_optionals_label($object->table_element);
435 if (is_array($object->array_options) && count($object->array_options) > 0) {
436 foreach ($object->array_options as $key => $value) {
437 $key = substr($key, 8);
438 $message_admin .=
'<li>'.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' : '.$extrafields->showOutputField($key, $value,
'', $object->table_element).
'</li>';
441 $message_admin .=
'</ul>';
443 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br>'.$object->message.
'</p>';
444 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'" rel="nofollow noopener">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
446 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
' <'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
449 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
450 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
451 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
453 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
454 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.$object->id,
'',
'ticket');
455 if ($mailfile->error || !empty($mailfile->errors)) {
458 $result = $mailfile->sendfile();
460 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
461 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
467 $object->copyFilesForTicket(
'');
472 $messagetoshow = $langs->trans(
'MesgInfosPublicTicketCreatedWithTrackId',
'{s1}',
'{s2}');
473 $messagetoshow = str_replace(array(
'{s1}',
'{s2}'), array(
'<strong>'.$object->track_id.
'</strong>',
'<strong>'.$object->ref.
'</strong>'), $messagetoshow);
477 header(
"Location: index.php".(!empty($entity) && isModEnabled(
'multicompany')?
'?entity='.$entity:
''));
486if (!empty($object->errors) || !empty($object->error)) {
495$form =
new Form($db);
498if (!$conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) {
499 print
'<div class="error">'.$langs->trans(
'TicketPublicInterfaceForbidden').
'</div>';
506$arrayofcss = array(
'/opensurvey/css/style.css',
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE',
'/ticket/').
'css/styles.css.php');
508llxHeaderTicket($langs->trans(
"CreateTicket"),
"", 0, 0, $arrayofjs, $arrayofcss);
511print
'<div class="ticketpublicarea ticketlargemargin centpercent">';
513if ($action !=
"infos_success") {
514 $formticket->withfromsocid = isset($socid) ? $socid : $user->socid;
515 $formticket->withtitletopic = 1;
516 $formticket->withcompany = 0;
517 $formticket->withusercreate = 1;
518 $formticket->fk_user_create = 0;
519 $formticket->withemail = 1;
520 $formticket->ispublic = 1;
521 $formticket->withfile = 2;
522 $formticket->action =
'create_ticket';
523 $formticket->withcancel = 1;
525 $formticket->param = array(
'returnurl' => $_SERVER[
'PHP_SELF'].($conf->entity > 1 ?
'?entity='.$conf->entity :
''));
527 print
load_fiche_titre($langs->trans(
'NewTicket'),
'',
'', 0, 0,
'marginleftonly');
529 if (empty($conf->global->TICKET_NOTIFICATION_EMAIL_FROM)) {
530 $langs->load(
"errors");
531 print
'<div class="error">';
532 print $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TicketEmailNotificationFrom")).
'<br>';
533 print $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentities(
"Ticket"));
537 $formticket->showForm(0,
'edit', 1, $with_contact);
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 pages.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
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_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesession=0, $varfiles='addedfile', $savingdocmask='', $link=null, $trackid='', $generatethumbs=1, $object=null)
Get and save an upload file (for example after submitting a new file a mail form).
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return 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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getUserRemoteIP()
Return the IP of remote user.
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.