25 if (!defined(
'NOREQUIREUSER')) define(
'NOREQUIREUSER',
'1');
26 if (!defined(
'NOTOKENRENEWAL')) define(
'NOTOKENRENEWAL',
'1');
27 if (!defined(
'NOREQUIREMENU')) define(
'NOREQUIREMENU',
'1');
28 if (!defined(
'NOREQUIREHTML')) define(
'NOREQUIREHTML',
'1');
29 if (!defined(
'NOLOGIN')) define(
"NOLOGIN", 1);
30 if (!defined(
'NOCSRFCHECK')) define(
"NOCSRFCHECK", 1);
31 if (!defined(
'NOIPCHECK')) define(
'NOIPCHECK',
'1');
32 if (!defined(
'NOBROWSERNOTIF')) define(
'NOBROWSERNOTIF',
'1');
35 require
'../../main.inc.php';
36 require_once DOL_DOCUMENT_ROOT.
'/ticket/class/actions_ticket.class.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formticket.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/core/lib/ticket.lib.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/lib/company.lib.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/lib/payments.lib.php';
42 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
46 $langs->loadLangs(array(
'companies',
'other',
'mails',
'ticket'));
50 $msg_id =
GETPOST(
'msg_id',
'int');
52 $action =
GETPOST(
'action',
'aZ09');
55 $hookmanager->initHooks(array(
'publicnewticketcard',
'globalcard'));
60 $extrafields->fetch_name_optionals_label($object->table_element);
70 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
75 if (empty($reshook) &&
GETPOST(
'addfile',
'alpha') && !
GETPOST(
'add',
'alpha')) {
79 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
82 $vardir = $conf->ticket->dir_output;
83 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
89 $action =
'create_ticket';
94 if (empty($reshook) &&
GETPOST(
'removedfile',
'alpha') && !
GETPOST(
'add',
'alpha')) {
95 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
98 $vardir = $conf->ticket->dir_output.
'/';
99 $upload_dir_tmp = $vardir.
'/temp/'.session_id();
103 $action =
'create_ticket';
106 if (empty($reshook) && $action ==
'create_ticket' &&
GETPOST(
'add',
'alpha')) {
108 $origin_email =
GETPOST(
'email',
'alpha');
109 if (empty($origin_email)) {
111 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Email")));
115 $searched_companies = $object->searchSocidByEmail($origin_email,
'0');
119 $contacts = $object->searchContactByEmail($origin_email);
122 if (!empty($conf->global->TICKET_EMAIL_MUST_EXISTS) && !$contacts[0]->socid) {
124 array_push($object->errors, $langs->trans(
"ErrorEmailMustExistToCreateTicket"));
129 if (!
GETPOST(
"subject",
"restricthtml")) {
131 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"Subject")));
133 } elseif (!
GETPOST(
"message",
"restricthtml")) {
135 array_push($object->errors, $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"message")));
142 array_push($object->errors, $langs->trans(
"ErrorBadEmailAddress", $langs->transnoentities(
"email")));
147 $object->db->begin();
151 $object->subject =
GETPOST(
"subject",
"restricthtml");
152 $object->message =
GETPOST(
"message",
"restricthtml");
153 $object->origin_email = $origin_email;
155 $object->type_code =
GETPOST(
"type_code",
'aZ09');
156 $object->category_code =
GETPOST(
"category_code",
'aZ09');
157 $object->severity_code =
GETPOST(
"severity_code",
'aZ09');
158 if (is_array($searched_companies)) {
159 $object->fk_soc = $searched_companies[0]->id;
162 if (is_array($contacts) and count($contacts) > 0) {
163 $object->fk_soc = $contacts[0]->socid;
164 $usertoassign = $contacts[0]->id;
167 $ret = $extrafields->setOptionalsFromPost(null, $object);
170 $object->ref = $object->getDefaultRef();
171 if (!is_object($user)) {
172 $user =
new User($db);
175 $object->context[
'disableticketemail'] = 1;
177 $id = $object->create($user);
180 $errors = ($object->error ? array($object->error) : $object->errors);
181 array_push($object->errors, $object->error ? array($object->error) : $object->errors);
182 $action =
'create_ticket';
185 if (!$error && $id > 0) {
186 if ($usertoassign > 0) {
187 $object->add_contact($usertoassign,
"SUPPORTCLI",
'external', 0);
192 $object->db->commit();
193 $action =
"infos_success";
195 $object->db->rollback();
197 $action =
'create_ticket';
201 $res = $object->fetch($id);
204 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
205 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
213 $attachedfiles = $formmail->get_attached_files();
214 $filepath = $attachedfiles[
'paths'];
215 $filename = $attachedfiles[
'names'];
216 $mimetype = $attachedfiles[
'mimes'];
220 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketNewEmailSubject', $object->ref, $object->track_id);
221 $message = ($conf->global->TICKET_MESSAGE_MAIL_NEW ? $conf->global->TICKET_MESSAGE_MAIL_NEW : $langs->transnoentities(
'TicketNewEmailBody')).
'<br><br>';
222 $message .= $langs->transnoentities(
'TicketNewEmailBodyInfosTicket').
'<br>';
224 $url_public_ticket = ($conf->global->TICKET_URL_PUBLIC_INTERFACE ? $conf->global->TICKET_URL_PUBLIC_INTERFACE.
'/' :
dol_buildpath(
'/public/ticket/view.php', 2)).
'?track_id='.$object->track_id;
225 $infos_new_ticket = $langs->transnoentities(
'TicketNewEmailBodyInfosTrackId',
'<a href="'.$url_public_ticket.
'" rel="nofollow noopener">'.$object->track_id.
'</a>').
'<br>';
226 $infos_new_ticket .= $langs->transnoentities(
'TicketNewEmailBodyInfosTrackUrl').
'<br><br>';
228 $message .= $infos_new_ticket;
229 $message .= $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE ? $conf->global->TICKET_MESSAGE_MAIL_SIGNATURE : $langs->transnoentities(
'TicketMessageMailSignatureText');
231 $sendto =
GETPOST(
'email',
'alpha');
233 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
'<'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
236 $deliveryreceipt = 0;
238 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
239 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
240 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
242 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
243 $mailfile =
new CMailFile($subject, $sendto, $from, $message, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.$object->id,
'',
'ticket');
244 if ($mailfile->error || $mailfile->errors) {
247 $result = $mailfile->sendfile();
249 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
250 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
254 $sendto = $conf->global->TICKET_NOTIFICATION_EMAIL_TO;
256 $subject =
'['.$conf->global->MAIN_INFO_SOCIETE_NOM.
'] '.$langs->transnoentities(
'TicketNewEmailSubjectAdmin', $object->ref, $object->track_id);
257 $message_admin = $langs->transnoentities(
'TicketNewEmailBodyAdmin', $object->track_id).
'<br><br>';
258 $message_admin .=
'<ul><li>'.$langs->trans(
'Title').
' : '.$object->subject.
'</li>';
259 $message_admin .=
'<li>'.$langs->trans(
'Type').
' : '.$object->type_label.
'</li>';
260 $message_admin .=
'<li>'.$langs->trans(
'Category').
' : '.$object->category_label.
'</li>';
261 $message_admin .=
'<li>'.$langs->trans(
'Severity').
' : '.$object->severity_label.
'</li>';
262 $message_admin .=
'<li>'.$langs->trans(
'From').
' : '.$object->origin_email.
'</li>';
264 $extrafields->fetch_name_optionals_label($object->table_element);
265 if (is_array($object->array_options) && count($object->array_options) > 0) {
266 foreach ($object->array_options as $key => $value) {
267 $key = substr($key, 8);
268 $message_admin .=
'<li>'.$langs->trans($extrafields->attributes[$object->element][
'label'][$key]).
' : '.$extrafields->showOutputField($key, $value).
'</li>';
271 $message_admin .=
'</ul>';
273 $message_admin .=
'</ul>';
274 $message_admin .=
'<p>'.$langs->trans(
'Message').
' : <br>'.$object->message.
'</p>';
275 $message_admin .=
'<p><a href="'.dol_buildpath(
'/ticket/card.php', 2).
'?track_id='.$object->track_id.
'" rel="nofollow noopener">'.$langs->trans(
'SeeThisTicketIntomanagementInterface').
'</a></p>';
277 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
' <'.$conf->global->TICKET_NOTIFICATION_EMAIL_FROM.
'>';
280 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
281 $old_MAIN_MAIL_AUTOCOPY_TO = $conf->global->MAIN_MAIL_AUTOCOPY_TO;
282 $conf->global->MAIN_MAIL_AUTOCOPY_TO =
'';
284 include_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
285 $mailfile =
new CMailFile($subject, $sendto, $from, $message_admin, $filepath, $mimetype, $filename, $sendtocc,
'', $deliveryreceipt, -1,
'',
'',
'tic'.$object->id,
'',
'ticket');
286 if ($mailfile->error || $mailfile->errors) {
289 $result = $mailfile->sendfile();
291 if (!empty($conf->global->TICKET_DISABLE_MAIL_AUTOCOPY_TO)) {
292 $conf->global->MAIN_MAIL_AUTOCOPY_TO = $old_MAIN_MAIL_AUTOCOPY_TO;
298 $destdir = $conf->ticket->dir_output.
'/'.$object->ref;
302 foreach ($filename as $i => $val) {
303 dol_move($filepath[$i], $destdir.
'/'.$filename[$i], 0, 1);
304 $formmail->remove_attached_files($i);
310 $messagetoshow = $langs->trans(
'MesgInfosPublicTicketCreatedWithTrackId',
'{s1}',
'{s2}');
311 $messagetoshow = str_replace(array(
'{s1}',
'{s2}'), array(
'<strong>'.$object->track_id.
'</strong>',
'<strong>'.$object->ref.
'</strong>'), $messagetoshow);
314 header(
"Location: index.php");
328 $form =
new Form($db);
331 if (!$conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) {
332 print '<div class="error">'.$langs->trans(
'TicketPublicInterfaceForbidden').
'</div>';
337 $arrayofjs = array();
338 $arrayofcss = array(
'/opensurvey/css/style.css',
'/ticket/css/styles.css.php');
340 llxHeaderTicket($langs->trans(
"CreateTicket"),
"", 0, 0, $arrayofjs, $arrayofcss);
343 print '<div class="ticketpublicarea">';
345 if ($action !=
"infos_success") {
346 $formticket->withfromsocid = isset($socid) ? $socid : $user->socid;
347 $formticket->withtitletopic = 1;
348 $formticket->withcompany = 0;
349 $formticket->withusercreate = 1;
350 $formticket->fk_user_create = 0;
351 $formticket->withemail = 1;
352 $formticket->ispublic = 1;
353 $formticket->withfile = 2;
354 $formticket->action =
'create_ticket';
356 $formticket->param = array(
'returnurl' =>
$_SERVER[
'PHP_SELF'].($conf->entity > 1 ?
'?entity='.$conf->entity :
''));
358 print
load_fiche_titre($langs->trans(
'NewTicket'),
'',
'', 0, 0,
'marginleftonly');
360 if (empty($conf->global->TICKET_NOTIFICATION_EMAIL_FROM)) {
361 $langs->load(
"errors");
362 print
'<div class="error">';
363 print $langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"TicketEmailNotificationFrom")).
'<br>';
364 print $langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentities(
"Ticket"));
367 print
'<div class="info marginleftonly marginrightonly">'.$langs->trans(
'TicketPublicInfoCreateTicket').
'</div>';
368 $formticket->showForm();
375 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.
Class to manage Dolibarr users.
dol_is_dir($folder)
Test if filename is a directory.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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.
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.
dol_remove_file_process($filenb, $donotupdatesession=0, $donotdeletefile=1, $trackid= '')
Remove an uploaded file (for example after submitting a new file a mail form).
print $_SERVER["PHP_SELF"]
Edit parameters.
print
Draft customers invoices.
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).
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)