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';
78$langs->loadLangs(array(
'companies',
'other',
'mails',
'ticket'));
86$action =
GETPOST(
'action',
'aZ09');
93$hookmanager->initHooks(array(
'publicnewticketcard',
'globalcard'));
99if (
getDolGlobalInt(
'TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST')) {
100 $with_contact =
new Contact($db);
103$extrafields->fetch_name_optionals_label(
$object->table_element);
105if (!isModEnabled(
'ticket')) {
118$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
123if (empty($reshook)) {
125 $backtopage =
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.
'/public/ticket/');
127 header(
"Location: ".$backtopage);
132 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
136 $vardir =
$conf->ticket->dir_output;
137 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
143 $action =
'create_ticket';
147 if (
GETPOST(
'removedfile',
'alpha') && !
GETPOST(
'save',
'alpha')) {
148 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
152 $vardir =
$conf->ticket->dir_output.
'/';
153 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
157 $action =
'create_ticket';
160 if ($action ==
'create_ticket' &&
GETPOST(
'save',
'alpha')) {
163 $origin_email =
GETPOST(
'email',
'email');
164 if (empty($origin_email)) {
166 array_push(
$object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Email")));
170 $searched_companies =
$object->searchSocidByEmail($origin_email, 0);
174 $contacts =
$object->searchContactByEmail($origin_email);
175 if (!is_array($contacts)) {
180 foreach ($contacts as $key => $contact) {
181 if ((
int) $contact->statut == 1) {
188 if (
getDolGlobalInt(
'TICKET_EMAIL_MUST_EXISTS') && ($cid < 0 || empty($contacts[$cid]->socid))) {
190 array_push(
$object->errors, $langs->trans(
"ErrorEmailMustExistToCreateTicket"));
195 $contact_lastname =
'';
196 $contact_firstname =
'';
201 if ( count($contacts) == 1) {
202 $with_contact = current($contacts);
206 $contact_lastname = trim(
GETPOST(
'contact_lastname',
'alphanohtml'));
207 $contact_firstname = trim(
GETPOST(
'contact_firstname',
'alphanohtml'));
208 $company_name = trim(
GETPOST(
'company_name',
'alphanohtml'));
209 $contact_phone = trim(
GETPOST(
'contact_phone',
'alphanohtml'));
210 if (!($with_contact->id > 0)) {
212 if (empty($contact_lastname)) {
214 array_push(
$object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Lastname')));
218 if (empty($contact_firstname)) {
220 array_push(
$object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Firstname')));
228 'type_code' => [
'check' =>
'alpha',
'langs' =>
'TicketTypeRequest'],
229 'category_code' => [
'check' =>
'alpha',
'langs' =>
'TicketCategory'],
230 'severity_code' => [
'check' =>
'alpha',
'langs' =>
'TicketSeverity'],
231 'subject' => [
'check' =>
'alphanohtml',
'langs' =>
'Subject'],
232 'message' => [
'check' =>
'restricthtml',
'langs' =>
'Message']
238 if (!empty($origin_email) && !
isValidEmail($origin_email)) {
240 array_push(
$object->errors, $langs->trans(
"ErrorBadEmailAddress", $langs->transnoentities(
"Email")));
246 $sessionkey =
'dol_antispam_value';
247 $ok = (array_key_exists($sessionkey, $_SESSION) && (strtolower($_SESSION[$sessionkey]) === strtolower(
GETPOST(
'code',
'restricthtml'))));
250 array_push(
$object->errors, $langs->trans(
"ErrorBadValueForCode"));
261 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
267 if ($nb_post_max > 0) {
268 $sql =
"SELECT COUNT(ref) as nb_tickets";
269 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket";
270 $sql .=
" WHERE ip = '".$db->escape(
$object->ip).
"'";
271 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
272 $resql = $db->query($sql);
274 $num = $db->num_rows($resql);
278 $obj = $db->fetch_object($resql);
279 $nb_post_ip = $obj->nb_tickets;
290 $object->origin_email = $origin_email;
291 $object->email_from = $origin_email;
297 if (!is_object($user)) {
298 $user =
new User($db);
303 if ($with_contact && !($with_contact->id > 0)) {
305 if (!empty($company_name)) {
306 $company->name = $company_name;
308 $company->particulier = 1;
311 $result = $company->create($user);
314 $errors = ($company->error ? array($company->error) : $company->errors);
316 $action =
'create_ticket';
321 $with_contact->email = $origin_email;
322 $with_contact->lastname = $contact_lastname;
323 $with_contact->firstname = $contact_firstname;
324 $with_contact->socid = $company->id;
325 $with_contact->phone_pro = $contact_phone;
326 $result = $with_contact->create($user);
329 $errors = ($with_contact->error ? array($with_contact->error) : $with_contact->errors);
331 $action =
'create_ticket';
333 $contacts = array($with_contact);
338 if (!empty($searched_companies) && is_array($searched_companies)) {
339 $object->fk_soc = $searched_companies[0]->id;
342 if ( count($contacts) > 0 && $cid >= 0) {
343 $object->fk_soc = $contacts[$cid]->socid;
344 $usertoassign = $contacts[$cid]->id;
347 $ret = $extrafields->setOptionalsFromPost(
null, $object);
352 $object->context[
'disableticketemail'] = 1;
355 $object->context[
'createdfrompublicinterface'] = 1;
357 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
359 array_push(
$object->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
360 $action =
'create_ticket';
372 $action =
'create_ticket';
376 if (!$error && $id > 0) {
377 if ($usertoassign > 0) {
378 $object->add_contact($usertoassign,
"SUPPORTCLI",
'external', 0);
383 $action =
"infos_success";
387 $action =
'create_ticket';
394 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
395 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
403 $attachedfiles = $formmail->get_attached_files();
404 $filepath = $attachedfiles[
'paths'];
405 $filename = $attachedfiles[
'names'];
406 $mimetype = $attachedfiles[
'mimes'];
409 $appli = $mysoc->name;
411 $subject =
'['.$appli.
'] '.$langs->transnoentities(
'TicketNewEmailSubject',
$object->ref,
$object->track_id);
413 $message .= $langs->transnoentities(
'TicketNewEmailBodyInfosTicket').
'<br>';
416 $infos_new_ticket = $langs->transnoentities(
'TicketNewEmailBodyInfosTrackId',
'<a href="'.$url_public_ticket.
'" rel="nofollow noopener">'.
$object->track_id.
'</a>').
'<br>';
417 $infos_new_ticket .= $langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrl').
'<br><br>';
419 $message .= $infos_new_ticket;
420 $message .=
getDolGlobalString(
'TICKET_MESSAGE_MAIL_SIGNATURE', $langs->transnoentities(
'TicketMessageMailSignatureText', $mysoc->name));
422 $sendto =
GETPOST(
'email',
'alpha');
424 $from =
getDolGlobalString(
'MAIN_INFO_SOCIETE_NOM') .
' <'.getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_FROM').
'>';
427 $deliveryreceipt = 0;
430 if ($old_MAIN_MAIL_AUTOCOPY_TO !==
'') {
431 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
433 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
434 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.
$object->id,
'',
'ticket');
435 if ($mailfile->error || !empty($mailfile->errors)) {
438 $result = $mailfile->sendfile();
440 if ($old_MAIN_MAIL_AUTOCOPY_TO !==
'') {
441 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
447 $appli = $mysoc->name;
449 $subject =
'['.$appli.
'] '.$langs->transnoentities(
'TicketNewEmailSubjectAdmin',
$object->ref,
$object->track_id);
450 $message_admin = $langs->transnoentities(
'TicketNewEmailBodyAdmin',
$object->track_id).
'<br><br>';
451 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
452 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.
$object->type_label.
'</li>';
453 $message_admin .=
'<li>'.$langs->trans(
'Category').
' : '.
$object->category_label.
'</li>';
454 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.
$object->severity_label.
'</li>';
455 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.
$object->origin_email.
'</li>';
457 $extrafields->fetch_name_optionals_label(
$object->table_element);
458 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
459 foreach (
$object->array_options as $key => $value) {
460 $key = substr($key, 8);
461 $message_admin .=
'<li>'.$langs->trans($extrafields->attributes[
$object->table_element][
'label'][$key]).
' : '.$extrafields->showOutputField($key, $value,
'',
$object->table_element).
'</li>';
464 $message_admin .=
'</ul>';
466 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br>'.
$object->message.
'</p>';
467 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.
$object->track_id.
'" rel="nofollow noopener">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
473 if ($old_MAIN_MAIL_AUTOCOPY_TO !==
'') {
474 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
476 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
477 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.
$object->id,
'',
'ticket');
478 if ($mailfile->error || !empty($mailfile->errors)) {
481 $result = $mailfile->sendfile();
483 if ($old_MAIN_MAIL_AUTOCOPY_TO !==
'') {
484 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
490 $object->copyFilesForTicket(
'');
495 $messagetoshow = $langs->trans(
'MesgInfosPublicTicketCreatedWithTrackId',
'{s1}',
'{s2}');
496 $messagetoshow = str_replace(array(
'{s1}',
'{s2}'), array(
'<strong>'.
$object->track_id.
'</strong>',
'<strong>'.$object->ref.
'</strong>'), $messagetoshow);
500 header(
"Location: index.php".(!empty($entity) && isModEnabled(
'multicompany') ?
'?entity='.$entity :
''));
518$form =
new Form($db);
522 print
'<div class="error">'.$langs->trans(
'TicketPublicInterfaceForbidden').
'</div>';
529$arrayofcss = array(
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE',
'/public/ticket/').
'css/styles.css.php');
531llxHeaderTicket($langs->trans(
"CreateTicket"),
"", 0, 0, $arrayofjs, $arrayofcss);
534print
'<div class="ticketpublicarea ticketlargemargin">';
536if ($action !=
"infos_success") {
537 $formticket->withfromsocid = isset($socid) ? $socid : $user->socid;
538 $formticket->withtitletopic = 1;
539 $formticket->withcompany = 0;
540 $formticket->withusercreate = 1;
541 $formticket->fk_user_create = 0;
542 $formticket->withemail = 1;
543 $formticket->ispublic = 1;
544 $formticket->withfile = 2;
545 $formticket->action =
'create_ticket';
546 $formticket->withcancel = 1;
548 $formticket->param = array(
'returnurl' => $_SERVER[
'PHP_SELF'].(
$conf->entity > 1 ?
'?entity='.$conf->entity :
''));
550 print
load_fiche_titre($langs->trans(
'NewTicket'),
'',
'', 0,
'',
'marginleftonly');
553 $langs->load(
"errors");
554 print
'<div class="error">';
555 print $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TicketEmailNotificationFrom")).
'<br>';
556 print $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentities(
"Ticket"));
560 $formticket->showForm(0, ($action ? $action :
'create'), 1, $with_contact,
'',
$object);
$id
Support class for third parties, contacts, members, users or resources.
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getUserRemoteIP($trusted=0)
Return the real IP of remote user.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.