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');
49$entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
50if (is_numeric($entity)) {
51 define(
"DOLENTITY", $entity);
55require
'../../main.inc.php';
56require_once DOL_DOCUMENT_ROOT.
'/ticket/class/actions_ticket.class.php';
57require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formticket.class.php';
58require_once DOL_DOCUMENT_ROOT.
'/core/lib/ticket.lib.php';
59require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
60require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
61require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
62require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
63require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
64require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
65require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
68$langs->loadLangs(array(
'companies',
'other',
'mails',
'ticket'));
76$action =
GETPOST(
'action',
'aZ09');
77$cancel =
GETPOST(
'cancel',
'aZ09');
83$hookmanager->initHooks(array(
'publicnewticketcard',
'globalcard'));
89if (
getDolGlobalInt(
'TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST')) {
90 $with_contact =
new Contact($db);
93$extrafields->fetch_name_optionals_label(
$object->table_element);
95if (!isModEnabled(
'ticket')) {
108$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
113if (empty($reshook)) {
115 $backtopage =
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE', DOL_URL_ROOT.
'/public/ticket/');
117 header(
"Location: ".$backtopage);
122 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
126 $vardir = $conf->ticket->dir_output;
127 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
133 $action =
'create_ticket';
137 if (
GETPOST(
'removedfile',
'alpha') && !
GETPOST(
'save',
'alpha')) {
138 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
142 $vardir = $conf->ticket->dir_output.
'/';
143 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
147 $action =
'create_ticket';
150 if ($action ==
'create_ticket' &&
GETPOST(
'save',
'alpha')) {
152 $origin_email =
GETPOST(
'email',
'email');
153 if (empty($origin_email)) {
155 array_push(
$object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Email")));
159 $searched_companies =
$object->searchSocidByEmail($origin_email,
'0');
163 $contacts =
$object->searchContactByEmail($origin_email);
167 foreach ($contacts as $key => $contact) {
168 if ((
int) $contact->statut == 1) {
175 if (
getDolGlobalInt(
'TICKET_EMAIL_MUST_EXISTS') && ($cid < 0 || empty($contacts[$cid]->socid))) {
177 array_push(
$object->errors, $langs->trans(
"ErrorEmailMustExistToCreateTicket"));
182 $contact_lastname =
'';
183 $contact_firstname =
'';
188 if (is_array($contacts) && count($contacts) == 1) {
189 $with_contact = current($contacts);
193 $contact_lastname = trim(
GETPOST(
'contact_lastname',
'alphanohtml'));
194 $contact_firstname = trim(
GETPOST(
'contact_firstname',
'alphanohtml'));
195 $company_name = trim(
GETPOST(
'company_name',
'alphanohtml'));
196 $contact_phone = trim(
GETPOST(
'contact_phone',
'alphanohtml'));
197 if (!($with_contact->id > 0)) {
199 if (empty($contact_lastname)) {
201 array_push(
$object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Lastname')));
205 if (empty($contact_firstname)) {
207 array_push(
$object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Firstname')));
213 if (!
GETPOST(
"subject",
"alphanohtml")) {
215 array_push(
$object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Subject")));
218 if (!
GETPOST(
"message",
"restricthtml")) {
220 array_push(
$object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Message")));
225 if (!empty($origin_email) && !
isValidEmail($origin_email)) {
227 array_push(
$object->errors, $langs->trans(
"ErrorBadEmailAddress", $langs->transnoentities(
"email")));
233 $sessionkey =
'dol_antispam_value';
234 $ok = (array_key_exists($sessionkey, $_SESSION) ===
true && (strtolower($_SESSION[$sessionkey]) === strtolower(
GETPOST(
'code',
'restricthtml'))));
237 array_push(
$object->errors, $langs->trans(
"ErrorBadValueForCode"));
248 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
254 if ($nb_post_max > 0) {
255 $sql =
"SELECT COUNT(ref) as nb_tickets";
256 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket";
257 $sql .=
" WHERE ip = '".$db->escape(
$object->ip).
"'";
258 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
259 $resql = $db->query($sql);
261 $num = $db->num_rows($resql);
265 $obj = $db->fetch_object($resql);
266 $nb_post_ip = $obj->nb_tickets;
277 $object->origin_email = $origin_email;
278 $object->email_from = $origin_email;
284 if (!is_object($user)) {
285 $user =
new User($db);
290 if ($with_contact && !($with_contact->id > 0)) {
292 if (!empty($company_name)) {
293 $company->name = $company_name;
295 $company->particulier = 1;
298 $result = $company->create($user);
301 $errors = ($company->error ? array($company->error) : $company->errors);
302 array_push(
$object->errors, $errors);
303 $action =
'create_ticket';
308 $with_contact->email = $origin_email;
309 $with_contact->lastname = $contact_lastname;
310 $with_contact->firstname = $contact_firstname;
311 $with_contact->socid = $company->id;
312 $with_contact->phone_pro = $contact_phone;
313 $result = $with_contact->create($user);
316 $errors = ($with_contact->error ? array($with_contact->error) : $with_contact->errors);
317 array_push(
$object->errors, $errors);
318 $action =
'create_ticket';
320 $contacts = array($with_contact);
325 if (!empty($searched_companies) && is_array($searched_companies)) {
326 $object->fk_soc = $searched_companies[0]->id;
329 if (is_array($contacts) && count($contacts) > 0 && $cid >= 0) {
330 $object->fk_soc = $contacts[$cid]->socid;
331 $usertoassign = $contacts[$cid]->id;
334 $ret = $extrafields->setOptionalsFromPost(
null, $object);
339 $object->context[
'disableticketemail'] = 1;
342 $object->context[
'createdfrompublicinterface'] = 1;
344 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
346 array_push(
$object->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
347 $action =
'create_ticket';
357 $action =
'create_ticket';
361 if (!$error && $id > 0) {
362 if ($usertoassign > 0) {
363 $object->add_contact($usertoassign,
"SUPPORTCLI",
'external', 0);
368 $action =
"infos_success";
372 $action =
'create_ticket';
379 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
380 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
388 $attachedfiles = $formmail->get_attached_files();
389 $filepath = $attachedfiles[
'paths'];
390 $filename = $attachedfiles[
'names'];
391 $mimetype = $attachedfiles[
'mimes'];
394 $appli = $mysoc->name;
396 $subject =
'['.$appli.
'] '.$langs->transnoentities(
'TicketNewEmailSubject',
$object->ref,
$object->track_id);
398 $message .= $langs->transnoentities(
'TicketNewEmailBodyInfosTicket').
'<br>';
401 $infos_new_ticket = $langs->transnoentities(
'TicketNewEmailBodyInfosTrackId',
'<a href="'.$url_public_ticket.
'" rel="nofollow noopener">'.
$object->track_id.
'</a>').
'<br>';
402 $infos_new_ticket .= $langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrl').
'<br><br>';
404 $message .= $infos_new_ticket;
405 $message .=
getDolGlobalString(
'TICKET_MESSAGE_MAIL_SIGNATURE', $langs->transnoentities(
'TicketMessageMailSignatureText', $mysoc->name));
407 $sendto =
GETPOST(
'email',
'alpha');
409 $from =
getDolGlobalString(
'MAIN_INFO_SOCIETE_NOM') .
' <'.getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_FROM').
'>';
412 $deliveryreceipt = 0;
416 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
418 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
419 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.
$object->id,
'',
'ticket');
420 if ($mailfile->error || !empty($mailfile->errors)) {
423 $result = $mailfile->sendfile();
426 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
432 $appli = $mysoc->name;
434 $subject =
'['.$appli.
'] '.$langs->transnoentities(
'TicketNewEmailSubjectAdmin',
$object->ref,
$object->track_id);
435 $message_admin = $langs->transnoentities(
'TicketNewEmailBodyAdmin',
$object->track_id).
'<br><br>';
436 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.
$object->subject.
'</li>';
437 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.
$object->type_label.
'</li>';
438 $message_admin .=
'<li>'.$langs->trans(
'Category').
' : '.
$object->category_label.
'</li>';
439 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.
$object->severity_label.
'</li>';
440 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.
$object->origin_email.
'</li>';
442 $extrafields->fetch_name_optionals_label(
$object->table_element);
443 if (is_array(
$object->array_options) && count(
$object->array_options) > 0) {
444 foreach (
$object->array_options as $key => $value) {
445 $key = substr($key, 8);
446 $message_admin .=
'<li>'.$langs->trans($extrafields->attributes[
$object->table_element][
'label'][$key]).
' : '.$extrafields->showOutputField($key, $value,
'',
$object->table_element).
'</li>';
449 $message_admin .=
'</ul>';
451 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br>'.
$object->message.
'</p>';
452 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.
$object->track_id.
'" rel="nofollow noopener">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
459 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
461 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
462 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.
$object->id,
'',
'ticket');
463 if ($mailfile->error || !empty($mailfile->errors)) {
466 $result = $mailfile->sendfile();
469 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
475 $object->copyFilesForTicket(
'');
480 $messagetoshow = $langs->trans(
'MesgInfosPublicTicketCreatedWithTrackId',
'{s1}',
'{s2}');
481 $messagetoshow = str_replace(array(
'{s1}',
'{s2}'), array(
'<strong>'.
$object->track_id.
'</strong>',
'<strong>'.$object->ref.
'</strong>'), $messagetoshow);
485 header(
"Location: index.php".(!empty($entity) && isModEnabled(
'multicompany') ?
'?entity='.$entity :
''));
503$form =
new Form($db);
507 print
'<div class="error">'.$langs->trans(
'TicketPublicInterfaceForbidden').
'</div>';
514$arrayofcss = array(
'/opensurvey/css/style.css',
getDolGlobalString(
'TICKET_URL_PUBLIC_INTERFACE',
'/ticket/').
'css/styles.css.php');
516llxHeaderTicket($langs->trans(
"CreateTicket"),
"", 0, 0, $arrayofjs, $arrayofcss);
519print
'<div class="ticketpublicarea ticketlargemargin centpercent">';
521if ($action !=
"infos_success") {
522 $formticket->withfromsocid = isset($socid) ? $socid : $user->socid;
523 $formticket->withtitletopic = 1;
524 $formticket->withcompany = 0;
525 $formticket->withusercreate = 1;
526 $formticket->fk_user_create = 0;
527 $formticket->withemail = 1;
528 $formticket->ispublic = 1;
529 $formticket->withfile = 2;
530 $formticket->action =
'create_ticket';
531 $formticket->withcancel = 1;
533 $formticket->param = array(
'returnurl' => $_SERVER[
'PHP_SELF'].($conf->entity > 1 ?
'?entity='.$conf->entity :
''));
535 print
load_fiche_titre($langs->trans(
'NewTicket'),
'',
'', 0, 0,
'marginleftonly');
538 $langs->load(
"errors");
539 print
'<div class="error">';
540 print $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TicketEmailNotificationFrom")).
'<br>';
541 print $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentities(
"Ticket"));
545 $formticket->showForm(0, ($action ? $action :
'create'), 1, $with_contact,
'',
$object);
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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_add_file_process($upload_dir, $allowoverwrite=0, $updatesessionordb=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).
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.
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.
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.