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');
82$hookmanager->initHooks(array(
'publicnewticketcard',
'globalcard'));
88if (
getDolGlobalInt(
'TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST')) {
89 $with_contact =
new Contact($db);
92$extrafields->fetch_name_optionals_label($object->table_element);
94if (!isModEnabled(
'ticket')) {
107$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
112if (empty($reshook)) {
114 $backtopage =
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.
'/public/ticket/');
116 header(
"Location: ".$backtopage);
121 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
125 $vardir = $conf->ticket->dir_output;
126 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
132 $action =
'create_ticket';
136 if (
GETPOST(
'removedfile',
'alpha') && !
GETPOST(
'save',
'alpha')) {
137 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
141 $vardir = $conf->ticket->dir_output.
'/';
142 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
146 $action =
'create_ticket';
149 if ($action ==
'create_ticket' &&
GETPOST(
'save',
'alpha')) {
151 $origin_email =
GETPOST(
'email',
'alpha');
152 if (empty($origin_email)) {
154 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Email")));
158 $searched_companies = $object->searchSocidByEmail($origin_email,
'0');
162 $contacts = $object->searchContactByEmail($origin_email);
166 foreach ($contacts as $key => $contact) {
167 if ((
int) $contact->statut == 1) {
174 if (
getDolGlobalInt(
'TICKET_EMAIL_MUST_EXISTS') && ($cid < 0 || empty($contacts[$cid]->socid))) {
176 array_push($object->errors, $langs->trans(
"ErrorEmailMustExistToCreateTicket"));
181 $contact_lastname =
'';
182 $contact_firstname =
'';
187 if (is_array($contacts) && count($contacts) == 1) {
188 $with_contact = current($contacts);
192 $contact_lastname = trim(
GETPOST(
'contact_lastname',
'alphanohtml'));
193 $contact_firstname = trim(
GETPOST(
'contact_firstname',
'alphanohtml'));
194 $company_name = trim(
GETPOST(
'company_name',
'alphanohtml'));
195 $contact_phone = trim(
GETPOST(
'contact_phone',
'alphanohtml'));
196 if (!($with_contact->id > 0)) {
198 if (empty($contact_lastname)) {
200 array_push($object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Lastname')));
204 if (empty($contact_firstname)) {
206 array_push($object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Firstname')));
212 if (!
GETPOST(
"subject",
"restricthtml")) {
214 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Subject")));
217 if (!
GETPOST(
"message",
"restricthtml")) {
219 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Message")));
224 if (!empty($origin_email) && !
isValidEmail($origin_email)) {
226 array_push($object->errors, $langs->trans(
"ErrorBadEmailAddress", $langs->transnoentities(
"email")));
232 $sessionkey =
'dol_antispam_value';
233 $ok = (array_key_exists($sessionkey, $_SESSION) ===
true && (strtolower($_SESSION[$sessionkey]) === strtolower(
GETPOST(
'code',
'restricthtml'))));
236 array_push($object->errors, $langs->trans(
"ErrorBadValueForCode"));
242 $object->type_code =
GETPOST(
"type_code",
'aZ09');
243 $object->category_code =
GETPOST(
"category_code",
'aZ09');
244 $object->severity_code =
GETPOST(
"severity_code",
'aZ09');
247 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
253 if ($nb_post_max > 0) {
254 $sql =
"SELECT COUNT(ref) as nb_tickets";
255 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket";
256 $sql .=
" WHERE ip = '".$db->escape($object->ip).
"'";
257 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
258 $resql = $db->query($sql);
260 $num = $db->num_rows($resql);
264 $obj = $db->fetch_object($resql);
265 $nb_post_ip = $obj->nb_tickets;
272 $object->db->begin();
274 $object->subject =
GETPOST(
"subject",
"restricthtml");
275 $object->message =
GETPOST(
"message",
"restricthtml");
276 $object->origin_email = $origin_email;
278 $object->type_code =
GETPOST(
"type_code",
'aZ09');
279 $object->category_code =
GETPOST(
"category_code",
'aZ09');
280 $object->severity_code =
GETPOST(
"severity_code",
'aZ09');
282 if (!is_object($user)) {
283 $user =
new User($db);
288 if ($with_contact && !($with_contact->id > 0)) {
290 if (!empty($company_name)) {
291 $company->name = $company_name;
293 $company->particulier = 1;
296 $result = $company->create($user);
299 $errors = ($company->error ? array($company->error) : $company->errors);
300 array_push($object->errors, $errors);
301 $action =
'create_ticket';
306 $with_contact->email = $origin_email;
307 $with_contact->lastname = $contact_lastname;
308 $with_contact->firstname = $contact_firstname;
309 $with_contact->socid = $company->id;
310 $with_contact->phone_pro = $contact_phone;
311 $result = $with_contact->create($user);
314 $errors = ($with_contact->error ? array($with_contact->error) : $with_contact->errors);
315 array_push($object->errors, $errors);
316 $action =
'create_ticket';
318 $contacts = array($with_contact);
323 if (!empty($searched_companies) && is_array($searched_companies)) {
324 $object->fk_soc = $searched_companies[0]->id;
327 if (is_array($contacts) && count($contacts) > 0 && $cid >= 0) {
328 $object->fk_soc = $contacts[$cid]->socid;
329 $usertoassign = $contacts[$cid]->id;
332 $ret = $extrafields->setOptionalsFromPost(
null, $object);
335 $object->ref = $object->getDefaultRef();
337 $object->context[
'disableticketemail'] = 1;
339 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
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'];
389 $appli = $mysoc->name;
391 $subject =
'['.$appli.
'] '.$langs->transnoentities(
'TicketNewEmailSubject', $object->ref, $object->track_id);
393 $message .= $langs->transnoentities(
'TicketNewEmailBodyInfosTicket').
'<br>';
396 $infos_new_ticket = $langs->transnoentities(
'TicketNewEmailBodyInfosTrackId',
'<a href="'.$url_public_ticket.
'" rel="nofollow noopener">'.$object->track_id.
'</a>').
'<br>';
397 $infos_new_ticket .= $langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrl').
'<br><br>';
399 $message .= $infos_new_ticket;
400 $message .=
getDolGlobalString(
'TICKET_MESSAGE_MAIL_SIGNATURE', $langs->transnoentities(
'TicketMessageMailSignatureText', $mysoc->name));
402 $sendto =
GETPOST(
'email',
'alpha');
404 $from =
getDolGlobalString(
'MAIN_INFO_SOCIETE_NOM') .
' <'.getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_FROM').
'>';
407 $deliveryreceipt = 0;
411 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
413 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
414 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.$object->id,
'',
'ticket');
415 if ($mailfile->error || !empty($mailfile->errors)) {
418 $result = $mailfile->sendfile();
421 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
427 $appli = $mysoc->name;
429 $subject =
'['.$appli.
'] '.$langs->transnoentities(
'TicketNewEmailSubjectAdmin', $object->ref, $object->track_id);
430 $message_admin = $langs->transnoentities(
'TicketNewEmailBodyAdmin', $object->track_id).
'<br><br>';
431 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
432 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$object->type_label.
'</li>';
433 $message_admin .=
'<li>'.$langs->trans(
'Category').
' : '.$object->category_label.
'</li>';
434 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$object->severity_label.
'</li>';
435 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.$object->origin_email.
'</li>';
437 $extrafields->fetch_name_optionals_label($object->table_element);
438 if (is_array($object->array_options) && count($object->array_options) > 0) {
439 foreach ($object->array_options as $key => $value) {
440 $key = substr($key, 8);
441 $message_admin .=
'<li>'.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' : '.$extrafields->showOutputField($key, $value,
'', $object->table_element).
'</li>';
444 $message_admin .=
'</ul>';
446 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br>'.$object->message.
'</p>';
447 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'" rel="nofollow noopener">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
454 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
456 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
457 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.$object->id,
'',
'ticket');
458 if ($mailfile->error || !empty($mailfile->errors)) {
461 $result = $mailfile->sendfile();
464 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
470 $object->copyFilesForTicket(
'');
475 $messagetoshow = $langs->trans(
'MesgInfosPublicTicketCreatedWithTrackId',
'{s1}',
'{s2}');
476 $messagetoshow = str_replace(array(
'{s1}',
'{s2}'), array(
'<strong>'.$object->track_id.
'</strong>',
'<strong>'.$object->ref.
'</strong>'), $messagetoshow);
480 header(
"Location: index.php".(!empty($entity) && isModEnabled(
'multicompany') ?
'?entity='.$entity :
''));
489if (!empty($object->errors) || !empty($object->error)) {
498$form =
new Form($db);
502 print
'<div class="error">'.$langs->trans(
'TicketPublicInterfaceForbidden').
'</div>';
509$arrayofcss = array(
'/opensurvey/css/style.css',
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE',
'/ticket/').
'css/styles.css.php');
511llxHeaderTicket($langs->trans(
"CreateTicket"),
"", 0, 0, $arrayofjs, $arrayofcss);
514print
'<div class="ticketpublicarea ticketlargemargin centpercent">';
516if ($action !=
"infos_success") {
517 $formticket->withfromsocid = isset($socid) ? $socid : $user->socid;
518 $formticket->withtitletopic = 1;
519 $formticket->withcompany = 0;
520 $formticket->withusercreate = 1;
521 $formticket->fk_user_create = 0;
522 $formticket->withemail = 1;
523 $formticket->ispublic = 1;
524 $formticket->withfile = 2;
525 $formticket->action =
'create_ticket';
526 $formticket->withcancel = 1;
528 $formticket->param = array(
'returnurl' => $_SERVER[
'PHP_SELF'].($conf->entity > 1 ?
'?entity='.$conf->entity :
''));
530 print
load_fiche_titre($langs->trans(
'NewTicket'),
'',
'', 0, 0,
'marginleftonly');
533 $langs->load(
"errors");
534 print
'<div class="error">';
535 print $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TicketEmailNotificationFrom")).
'<br>';
536 print $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentities(
"Ticket"));
540 $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 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.
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.