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);
56 require
'../../main.inc.php';
57 require_once DOL_DOCUMENT_ROOT.
'/ticket/class/actions_ticket.class.php';
58 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formticket.class.php';
59 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ticket.lib.php';
60 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
61 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
62 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
63 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
64 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
65 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
66 require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
69 $langs->loadLangs(array(
'companies',
'other',
'mails',
'ticket'));
73 $msg_id =
GETPOST(
'msg_id',
'int');
74 $socid =
GETPOST(
'socid',
'int');
77 $action =
GETPOST(
'action',
'aZ09');
78 $cancel =
GETPOST(
'cancel',
'aZ09');
83 $hookmanager->initHooks(array(
'publicnewticketcard',
'globalcard'));
89 if (!empty($conf->global->TICKET_CREATE_THIRD_PARTY_WITH_CONTACT_IF_NOT_EXIST)) {
90 $with_contact =
new Contact($db);
93 $extrafields->fetch_name_optionals_label($object->table_element);
108 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
113 if (empty($reshook)) {
115 $backtopage = DOL_URL_ROOT.
'/public/ticket/index.php';
117 header(
"Location: ".$backtopage);
125 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
128 $vardir = $conf->ticket->dir_output;
129 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
135 $action =
'create_ticket';
140 if (
GETPOST(
'removedfile',
'alpha') && !
GETPOST(
'save',
'alpha')) {
141 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
144 $vardir = $conf->ticket->dir_output.
'/';
145 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
149 $action =
'create_ticket';
152 if ($action ==
'create_ticket' &&
GETPOST(
'save',
'alpha')) {
154 $origin_email =
GETPOST(
'email',
'alpha');
155 if (empty($origin_email)) {
157 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Email")));
161 $searched_companies = $object->searchSocidByEmail($origin_email,
'0');
165 $contacts = $object->searchContactByEmail($origin_email);
169 foreach ($contacts as $key => $contact) {
170 if ((
int) $contact->statut == 1) {
177 if (!empty($conf->global->TICKET_EMAIL_MUST_EXISTS) && ($cid < 0 || empty($contacts[$cid]->socid))) {
179 array_push($object->errors, $langs->trans(
"ErrorEmailMustExistToCreateTicket"));
184 $contact_lastname =
'';
185 $contact_firstname =
'';
190 if (is_array($contacts) && count($contacts) == 1) {
191 $with_contact = current($contacts);
195 $contact_lastname = trim(
GETPOST(
'contact_lastname',
'alphanohtml'));
196 $contact_firstname = trim(
GETPOST(
'contact_firstname',
'alphanohtml'));
197 $company_name = trim(
GETPOST(
'company_name',
'alphanohtml'));
198 $contact_phone = trim(
GETPOST(
'contact_phone',
'alphanohtml'));
199 if (!($with_contact->id > 0)) {
201 if (empty($contact_lastname)) {
203 array_push($object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Lastname')));
207 if (empty($contact_firstname)) {
209 array_push($object->errors, $langs->trans(
'ErrorFieldRequired', $langs->transnoentities(
'Firstname')));
215 if (!
GETPOST(
"subject",
"restricthtml")) {
217 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Subject")));
220 if (!
GETPOST(
"message",
"restricthtml")) {
222 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Message")));
227 if (!empty($origin_email) && !
isValidEmail($origin_email)) {
229 array_push($object->errors, $langs->trans(
"ErrorBadEmailAddress", $langs->transnoentities(
"email")));
234 if (!empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA_TICKET)) {
235 $sessionkey =
'dol_antispam_value';
236 $ok = (array_key_exists($sessionkey, $_SESSION) ===
true && (strtolower($_SESSION[$sessionkey]) === strtolower(
GETPOST(
'code',
'restricthtml'))));
239 array_push($object->errors, $langs->trans(
"ErrorBadValueForCode"));
245 $object->type_code =
GETPOST(
"type_code",
'aZ09');
246 $object->category_code =
GETPOST(
"category_code",
'aZ09');
247 $object->severity_code =
GETPOST(
"severity_code",
'aZ09');
250 $nb_post_max =
getDolGlobalInt(
"MAIN_SECURITY_MAX_POST_ON_PUBLIC_PAGES_BY_IP_ADDRESS", 200);
256 if ($nb_post_max > 0) {
257 $sql =
"SELECT COUNT(ref) as nb_tickets";
258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"ticket";
259 $sql .=
" WHERE ip = '".$db->escape($object->ip).
"'";
260 $sql .=
" AND datec > '".$db->idate($minmonthpost).
"'";
261 $resql = $db->query($sql);
263 $num = $db->num_rows(
$resql);
267 $obj = $db->fetch_object(
$resql);
268 $nb_post_ip = $obj->nb_tickets;
275 $object->db->begin();
277 $object->subject =
GETPOST(
"subject",
"restricthtml");
278 $object->message =
GETPOST(
"message",
"restricthtml");
279 $object->origin_email = $origin_email;
281 $object->type_code =
GETPOST(
"type_code",
'aZ09');
282 $object->category_code =
GETPOST(
"category_code",
'aZ09');
283 $object->severity_code =
GETPOST(
"severity_code",
'aZ09');
285 if (!is_object($user)) {
286 $user =
new User($db);
291 if ($with_contact && !($with_contact->id > 0)) {
293 if (!empty($company_name)) {
294 $company->name = $company_name;
296 $company->particulier = 1;
299 $result = $company->create($user);
302 $errors = ($company->error ? array($company->error) : $company->errors);
303 array_push($object->errors, $errors);
304 $action =
'create_ticket';
309 $with_contact->email = $origin_email;
310 $with_contact->lastname = $contact_lastname;
311 $with_contact->firstname = $contact_firstname;
312 $with_contact->socid = $company->id;
313 $with_contact->phone_pro = $contact_phone;
314 $result = $with_contact->create($user);
317 $errors = ($with_contact->error ? array($with_contact->error) : $with_contact->errors);
318 array_push($object->errors, $errors);
319 $action =
'create_ticket';
321 $contacts = array($with_contact);
326 if (!empty($searched_companies) && is_array($searched_companies)) {
327 $object->fk_soc = $searched_companies[0]->id;
330 if (is_array($contacts) && count($contacts) > 0 && $cid >= 0) {
331 $object->fk_soc = $contacts[$cid]->socid;
332 $usertoassign = $contacts[$cid]->id;
335 $ret = $extrafields->setOptionalsFromPost(
null, $object);
338 $object->ref = $object->getDefaultRef();
340 $object->context[
'disableticketemail'] = 1;
342 if ($nb_post_max > 0 && $nb_post_ip >= $nb_post_max) {
344 $errors = array($langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
345 array_push($object->errors, $langs->trans(
"AlreadyTooMuchPostOnThisIPAdress"));
346 $action =
'create_ticket';
350 $id = $object->create($user);
353 $errors = ($object->error ? array($object->error) : $object->errors);
354 array_push($object->errors, $object->error ? array($object->error) : $object->errors);
355 $action =
'create_ticket';
359 if (!$error && $id > 0) {
360 if ($usertoassign > 0) {
361 $object->add_contact($usertoassign,
"SUPPORTCLI",
'external', 0);
365 $object->db->commit();
366 $action =
"infos_success";
368 $object->db->rollback();
370 $action =
'create_ticket';
374 $res = $object->fetch($id);
377 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
378 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
386 $attachedfiles = $formmail->get_attached_files();
387 $filepath = $attachedfiles[
'paths'];
388 $filename = $attachedfiles[
'names'];
389 $mimetype = $attachedfiles[
'mimes'];
393 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketNewEmailSubject', $object->ref, $object->track_id);
394 $message = ($conf->global->TICKET_MESSAGE_MAIL_NEW ? $conf->global->TICKET_MESSAGE_MAIL_NEW : $langs->transnoentities(
'TicketNewEmailBody')).
'<br><br>';
395 $message .= $langs->transnoentities(
'TicketNewEmailBodyInfosTicket').
'<br>';
397 $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;
398 $infos_new_ticket = $langs->transnoentities(
'TicketNewEmailBodyInfosTrackId',
'<a href="'.$url_public_ticket.
'" rel="nofollow noopener">'.$object->track_id.
'</a>').
'<br>';
399 $infos_new_ticket .= $langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrl').
'<br><br>';
401 $message .= $infos_new_ticket;
402 $message .=
getDolGlobalString(
'TICKET_MESSAGE_MAIL_SIGNATURE', $langs->transnoentities(
'TicketMessageMailSignatureText', $mysoc->name));
404 $sendto =
GETPOST(
'email',
'alpha');
406 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
' <'.
getDolGlobalString(
'TICKET_NOTIFICATION_EMAIL_FROM').
'>';
409 $deliveryreceipt = 0;
411 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
412 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
413 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
415 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
416 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.$object->id,
'',
'ticket');
417 if ($mailfile->error || !empty($mailfile->errors)) {
420 $result = $mailfile->sendfile();
422 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
423 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
427 $sendto = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
429 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$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>';
449 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
' <'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
452 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
453 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
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();
463 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
464 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
470 $destdir = $conf->ticket->dir_output.
'/'.$object->ref;
474 foreach ($filename as $i => $val) {
475 dol_move($filepath[$i], $destdir.
'/'.$filename[$i], 0, 1);
476 $formmail->remove_attached_files($i);
482 $messagetoshow = $langs->trans(
'MesgInfosPublicTicketCreatedWithTrackId',
'{s1}',
'{s2}');
483 $messagetoshow = str_replace(array(
'{s1}',
'{s2}'), array(
'<strong>'.$object->track_id.
'</strong>',
'<strong>'.$object->ref.
'</strong>'), $messagetoshow);
487 header(
"Location: index.php".(!empty($entity) &&
isModEnabled(
'multicompany')?
'?entity='.$entity:
''));
505 if (!$conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) {
506 print
'<div class="error">'.$langs->trans(
'TicketPublicInterfaceForbidden').
'</div>';
511 $arrayofjs = array();
512 $arrayofcss = array(
'/opensurvey/css/style.css',
'/ticket/css/styles.css.php');
514 llxHeaderTicket($langs->trans(
"CreateTicket"),
"", 0, 0, $arrayofjs, $arrayofcss);
517 print
'<div class="ticketpublicarea">';
519 if ($action !=
"infos_success") {
520 $formticket->withfromsocid = isset($socid) ? $socid : $user->socid;
521 $formticket->withtitletopic = 1;
522 $formticket->withcompany = 0;
523 $formticket->withusercreate = 1;
524 $formticket->fk_user_create = 0;
525 $formticket->withemail = 1;
526 $formticket->ispublic = 1;
527 $formticket->withfile = 2;
528 $formticket->action =
'create_ticket';
529 $formticket->withcancel = 1;
531 $formticket->param = array(
'returnurl' => $_SERVER[
'PHP_SELF'].($conf->entity > 1 ?
'?entity='.$conf->entity :
''));
533 print
load_fiche_titre($langs->trans(
'NewTicket'),
'',
'', 0, 0,
'marginleftonly');
535 if (empty($conf->global->TICKET_NOTIFICATION_EMAIL_FROM)) {
536 $langs->load(
"errors");
537 print
'<div class="error">';
538 print $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TicketEmailNotificationFrom")).
'<br>';
539 print $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentities(
"Ticket"));
543 $formticket->showForm(0,
'edit', 1, $with_contact);
550 htmlPrintOnlinePaymentFooter($mysoc, $langs, 1, $suffix, $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.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
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).
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getUserRemoteIP()
Return the IP of remote user.
isModEnabled($module)
Is Dolibarr module enabled.
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 header for public pages.