29 if (!defined(
'NOTOKENRENEWAL')) {
30 define(
'NOTOKENRENEWAL',
'1');
32 if (!defined(
'NOREQUIREMENU')) {
33 define(
'NOREQUIREMENU',
'1');
35 if (!defined(
'NOREQUIREHTML')) {
36 define(
'NOREQUIREHTML',
'1');
38 if (!defined(
'NOLOGIN')) {
41 if (!defined(
'NOIPCHECK')) {
42 define(
'NOIPCHECK',
'1');
44 if (!defined(
'NOBROWSERNOTIF')) {
45 define(
'NOBROWSERNOTIF',
'1');
50 $entity = (!empty($_GET[
'entity']) ? (int) $_GET[
'entity'] : (!empty($_POST[
'entity']) ? (int) $_POST[
'entity'] : 1));
51 if (is_numeric($entity)) {
52 define(
"DOLENTITY", $entity);
55 require
'../../main.inc.php';
56 require_once DOL_DOCUMENT_ROOT.
'/ticket/class/actions_ticket.class.php';
57 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formticket.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ticket.lib.php';
59 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
60 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
61 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
62 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
63 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
64 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
67 $langs->loadLangs(array(
'companies',
'other',
'mails',
'ticket'));
71 $msg_id =
GETPOST(
'msg_id',
'int');
73 $action =
GETPOST(
'action',
'aZ09');
74 $cancel =
GETPOST(
'cancel',
'aZ09');
79 $hookmanager->initHooks(array(
'publicnewticketcard',
'globalcard'));
85 if (!empty($conf->global->TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST)) {
86 $with_contact =
new Contact($db);
89 $extrafields->fetch_name_optionals_label($object->table_element);
91 if (empty($conf->ticket->enabled)) {
104 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
109 if (empty($reshook)) {
111 $backtopage = DOL_URL_ROOT.
'/public/ticket/index.php';
113 header(
"Location: ".$backtopage);
121 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';
136 if (
GETPOST(
'removedfile',
'alpha') && !
GETPOST(
'save',
'alpha')) {
137 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);
164 if (!empty($conf->global->TICKET_EMAIL_MUST_EXISTS) && !$contacts[0]->socid) {
166 array_push($object->errors, $langs->trans(
"ErrorEmailMustExistToCreateTicket"));
171 $contact_lastname =
'';
172 $contact_firstname =
'';
177 if (is_array($contacts) && count($contacts) == 1) {
178 $with_contact = current($contacts);
182 $contact_lastname = trim(
GETPOST(
'contact_lastname',
'alphanohtml'));
183 $contact_firstname = trim(
GETPOST(
'contact_firstname',
'alphanohtml'));
184 $company_name = trim(
GETPOST(
'company_name',
'alphanohtml'));
185 $contact_phone = trim(
GETPOST(
'contact_phone',
'alphanohtml'));
186 if (!($with_contact->id > 0)) {
188 if (empty($contact_lastname)) {
190 array_push($object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Lastname')));
194 if (empty($contact_firstname)) {
196 array_push($object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Firstname')));
202 if (!
GETPOST(
"subject",
"restricthtml")) {
204 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Subject")));
207 if (!
GETPOST(
"message",
"restricthtml")) {
209 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Message")));
214 if (!empty($origin_email) && !
isValidEmail($origin_email)) {
216 array_push($object->errors, $langs->trans(
"ErrorBadEmailAddress", $langs->transnoentities(
"email")));
221 if (!empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA_TICKET)) {
222 $sessionkey =
'dol_antispam_value';
223 $ok = (array_key_exists($sessionkey, $_SESSION) ===
true && (strtolower($_SESSION[$sessionkey]) === strtolower(
GETPOST(
'code',
'restricthtml'))));
226 array_push($object->errors, $langs->trans(
"ErrorBadValueForCode"));
232 $object->db->begin();
236 $object->subject =
GETPOST(
"subject",
"restricthtml");
237 $object->message =
GETPOST(
"message",
"restricthtml");
238 $object->origin_email = $origin_email;
240 $object->type_code =
GETPOST(
"type_code",
'aZ09');
241 $object->category_code =
GETPOST(
"category_code",
'aZ09');
242 $object->severity_code =
GETPOST(
"severity_code",
'aZ09');
244 if (!is_object($user)) {
245 $user =
new User($db);
250 if ($with_contact && !($with_contact->id > 0)) {
252 if (!empty($company_name)) {
253 $company->name = $company_name;
255 $company->particulier = 1;
258 $result = $company->create($user);
261 $errors = ($company->error ? array($company->error) : $company->errors);
262 array_push($object->errors, $errors);
263 $action =
'create_ticket';
268 $with_contact->email = $origin_email;
269 $with_contact->lastname = $contact_lastname;
270 $with_contact->firstname = $contact_firstname;
271 $with_contact->socid = $company->id;
272 $with_contact->phone_pro = $contact_phone;
273 $result = $with_contact->create($user);
276 $errors = ($with_contact->error ? array($with_contact->error) : $with_contact->errors);
277 array_push($object->errors, $errors);
278 $action =
'create_ticket';
280 $contacts = array($with_contact);
285 if (is_array($searched_companies)) {
286 $object->fk_soc = $searched_companies[0]->id;
289 if (is_array($contacts) and count($contacts) > 0) {
290 $object->fk_soc = $contacts[0]->socid;
291 $usertoassign = $contacts[0]->id;
294 $ret = $extrafields->setOptionalsFromPost(null, $object);
297 $object->ref = $object->getDefaultRef();
299 $object->context[
'disableticketemail'] = 1;
301 $id = $object->create($user);
304 $errors = ($object->error ? array($object->error) : $object->errors);
305 array_push($object->errors, $object->error ? array($object->error) : $object->errors);
306 $action =
'create_ticket';
309 if (!$error && $id > 0) {
310 if ($usertoassign > 0) {
311 $object->add_contact($usertoassign,
"SUPPORTCLI",
'external', 0);
316 $object->db->commit();
317 $action =
"infos_success";
319 $object->db->rollback();
321 $action =
'create_ticket';
325 $res = $object->fetch($id);
328 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
329 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
337 $attachedfiles = $formmail->get_attached_files();
338 $filepath = $attachedfiles[
'paths'];
339 $filename = $attachedfiles[
'names'];
340 $mimetype = $attachedfiles[
'mimes'];
344 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketNewEmailSubject', $object->ref, $object->track_id);
345 $message = ($conf->global->TICKET_MESSAGE_MAIL_NEW ? $conf->global->TICKET_MESSAGE_MAIL_NEW : $langs->transnoentities(
'TicketNewEmailBody')).
'<br><br>';
346 $message .= $langs->transnoentities(
'TicketNewEmailBodyInfosTicket').
'<br>';
348 $url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.
'/view.php' :
dol_buildpath(
'/public/ticket/view.php', 2)).
'?track_id='.$object->track_id;
349 $infos_new_ticket = $langs->transnoentities(
'TicketNewEmailBodyInfosTrackId',
'<a href="'.$url_public_ticket.
'" rel="nofollow noopener">'.$object->track_id.
'</a>').
'<br>';
350 $infos_new_ticket .= $langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrl').
'<br><br>';
352 $message .= $infos_new_ticket;
353 $message .=
getDolGlobalString(
'TICKET_MESSAGE_MAIL_SIGNATURE', $langs->transnoentities(
'TicketMessageMailSignatureText', $mysoc->name));
355 $sendto =
GETPOST(
'email',
'alpha');
357 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
' <'.
getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_FROM').
'>';
360 $deliveryreceipt = 0;
362 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
363 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
364 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
366 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
367 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.$object->id,
'',
'ticket');
368 if ($mailfile->error || $mailfile->errors) {
371 $result = $mailfile->sendfile();
373 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
374 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
378 $sendto = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
380 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketNewEmailSubjectAdmin', $object->ref, $object->track_id);
381 $message_admin = $langs->transnoentities(
'TicketNewEmailBodyAdmin', $object->track_id).
'<br><br>';
382 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
383 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$object->type_label.
'</li>';
384 $message_admin .=
'<li>'.$langs->trans(
'Category').
' : '.$object->category_label.
'</li>';
385 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$object->severity_label.
'</li>';
386 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.$object->origin_email.
'</li>';
388 $extrafields->fetch_name_optionals_label($object->table_element);
389 if (is_array($object->array_options) && count($object->array_options) > 0) {
390 foreach ($object->array_options as $key => $value) {
391 $key = substr($key, 8);
392 $message_admin .=
'<li>'.$langs->trans($extrafields->attributes[$object->table_element][
'label'][$key]).
' : '.$extrafields->showOutputField($key, $value,
'', $object->table_element).
'</li>';
395 $message_admin .=
'</ul>';
397 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br>'.$object->message.
'</p>';
398 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'" rel="nofollow noopener">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
400 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
' <'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
403 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
404 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
405 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
407 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
408 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.$object->id,
'',
'ticket');
409 if ($mailfile->error || $mailfile->errors) {
412 $result = $mailfile->sendfile();
414 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
415 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
421 $destdir = $conf->ticket->dir_output.
'/'.$object->ref;
425 foreach ($filename as $i => $val) {
426 dol_move($filepath[$i], $destdir.
'/'.$filename[$i], 0, 1);
427 $formmail->remove_attached_files($i);
433 $messagetoshow = $langs->trans(
'MesgInfosPublicTicketCreatedWithTrackId',
'{s1}',
'{s2}');
434 $messagetoshow = str_replace(array(
'{s1}',
'{s2}'), array(
'<strong>'.$object->track_id.
'</strong>',
'<strong>'.$object->ref.
'</strong>'), $messagetoshow);
437 header(
"Location: index.php".(!empty($entity) && !empty($conf->multicompany->enabled)?
'?entity='.$entity:
''));
454 if (!$conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) {
455 print
'<div class="error">'.$langs->trans(
'TicketPublicInterfaceForbidden').
'</div>';
460 $arrayofjs = array();
461 $arrayofcss = array(
'/opensurvey/css/style.css',
'/ticket/css/styles.css.php');
463 llxHeaderTicket($langs->trans(
"CreateTicket"),
"", 0, 0, $arrayofjs, $arrayofcss);
466 print
'<div class="ticketpublicarea">';
468 if ($action !=
"infos_success") {
469 $formticket->withfromsocid = isset($socid) ? $socid : $user->socid;
470 $formticket->withtitletopic = 1;
471 $formticket->withcompany = 0;
472 $formticket->withusercreate = 1;
473 $formticket->fk_user_create = 0;
474 $formticket->withemail = 1;
475 $formticket->ispublic = 1;
476 $formticket->withfile = 2;
477 $formticket->action =
'create_ticket';
478 $formticket->withcancel = 1;
480 $formticket->param = array(
'returnurl' => $_SERVER[
'PHP_SELF'].($conf->entity > 1 ?
'?entity='.$conf->entity :
''));
482 print
load_fiche_titre($langs->trans(
'NewTicket'),
'',
'', 0, 0,
'marginleftonly');
484 if (empty($conf->global->TICKET_NOTIFICATION_EMAIL_FROM)) {
485 $langs->load(
"errors");
486 print
'<div class="error">';
487 print $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TicketEmailNotificationFrom")).
'<br>';
488 print $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentities(
"Ticket"));
492 $formticket->showForm(0,
'edit', 1, $with_contact);
499 htmlPrintOnlinePaymentFooter($mysoc, $langs, 1, $suffix, $object);
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
dol_mkdir($dir, $dataroot= '', $newmask= '')
Creation of a directory (this can create recursive subdir)
Class to manage Dolibarr users.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default= '')
Return dolibarr global constant string value.
dol_is_dir($folder)
Test if filename is a directory.
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.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
llxHeaderTicket($title, $head="", $disablejs=0, $disablehead=0, $arrayofjs= '', $arrayofcss= '')
Show header for public pages.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();.
generate_random_id($car=16)
Generate a random id.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
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_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).
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.