1<?php
2/* Copyright (C) 2013-2018	Jean-François FERRY	<hello@librethic.io>
3 * Copyright (C) 2016		Christophe Battarel	<christophe@altairis.fr>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18
19/**
20 *     \file        admin/ticket_public.php
21 *     \ingroup     ticket
22 *     \brief       Page to public interface of module Ticket
23 */
24
25require '../main.inc.php';
26require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
27require_once DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php";
28require_once DOL_DOCUMENT_ROOT."/core/lib/ticket.lib.php";
29
30// Load translation files required by the page
31$langs->loadLangs(array("admin", "ticket"));
32
33// Access control
34if (!$user->admin) {
35	accessforbidden();
36}
37
38// Parameters
39$value = GETPOST('value', 'alpha');
40$action = GETPOST('action', 'aZ09');
41$label = GETPOST('label', 'alpha');
42$scandir = GETPOST('scandir', 'alpha');
43$type = 'ticket';
44
45$error = 0;
46
47/*
48 * Actions
49 */
50
51if ($action == 'setTICKET_ENABLE_PUBLIC_INTERFACE')
52{
53	if (GETPOST('value')) dolibarr_set_const($db, 'TICKET_ENABLE_PUBLIC_INTERFACE', 1, 'chaine', 0, '', $conf->entity);
54	else dolibarr_set_const($db, 'TICKET_ENABLE_PUBLIC_INTERFACE', 0, 'chaine', 0, '', $conf->entity);
55}
56
57if ($action == 'setvar') {
58	include_once DOL_DOCUMENT_ROOT."/core/lib/files.lib.php";
59
60	$topic_interface = GETPOST('TICKET_PUBLIC_INTERFACE_TOPIC', 'nohtml');
61	if (!empty($topic_interface)) {
62		$res = dolibarr_set_const($db, 'TICKET_PUBLIC_INTERFACE_TOPIC', $topic_interface, 'chaine', 0, '', $conf->entity);
63	} else {
64		$res = dolibarr_set_const($db, 'TICKET_PUBLIC_INTERFACE_TOPIC', '', 'chaine', 0, '', $conf->entity);
65	}
66	if (!($res > 0)) {
67		$error++;
68	}
69
70	$text_home = GETPOST('TICKET_PUBLIC_TEXT_HOME', 'restricthtml');
71	if (!empty($text_home)) {
72		$res = dolibarr_set_const($db, 'TICKET_PUBLIC_TEXT_HOME', $text_home, 'chaine', 0, '', $conf->entity);
73	} else {
74		$res = dolibarr_set_const($db, 'TICKET_PUBLIC_TEXT_HOME', $langs->trans('TicketPublicInterfaceTextHome'), 'chaine', 0, '', $conf->entity);
75	}
76	if (!($res > 0)) {
77		$error++;
78	}
79
80	$text_help = GETPOST('TICKET_PUBLIC_TEXT_HELP_MESSAGE', 'restricthtml');
81	if (!empty($text_help)) {
82		$res = dolibarr_set_const($db, 'TICKET_PUBLIC_TEXT_HELP_MESSAGE', $text_help, 'chaine', 0, '', $conf->entity);
83	} else {
84		$res = dolibarr_set_const($db, 'TICKET_PUBLIC_TEXT_HELP_MESSAGE', $langs->trans('TicketPublicPleaseBeAccuratelyDescribe'), 'chaine', 0, '', $conf->entity);
85	}
86	if (!($res > 0)) {
87		$error++;
88	}
89
90	$mail_new_ticket = GETPOST('TICKET_MESSAGE_MAIL_NEW', 'restricthtml');
91	if (!empty($mail_new_ticket)) {
92		$res = dolibarr_set_const($db, 'TICKET_MESSAGE_MAIL_NEW', $mail_new_ticket, 'chaine', 0, '', $conf->entity);
93	} else {
94		$res = dolibarr_set_const($db, 'TICKET_MESSAGE_MAIL_NEW', $langs->trans('TicketMessageMailNewText'), 'chaine', 0, '', $conf->entity);
95	}
96	if (!($res > 0)) {
97		$error++;
98	}
99
100	$url_interface = GETPOST('TICKET_URL_PUBLIC_INTERFACE', 'alpha');
101	if (!empty($url_interface)) {
102		$res = dolibarr_set_const($db, 'TICKET_URL_PUBLIC_INTERFACE', $url_interface, 'chaine', 0, '', $conf->entity);
103	} else {
104		$res = dolibarr_set_const($db, 'TICKET_URL_PUBLIC_INTERFACE', '', 'chaine', 0, '', $conf->entity);
105	}
106	if (!($res > 0)) {
107		$error++;
108	}
109
110	$param_public_notification_new_message_default_email = GETPOST('TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL', 'alpha');
111	$res = dolibarr_set_const($db, 'TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL', $param_public_notification_new_message_default_email, 'chaine', 0, '', $conf->entity);
112	if (!($res > 0)) {
113		$error++;
114	}
115}
116
117if ($action == 'setvarother') {
118	$param_enable_public_interface = GETPOST('TICKET_ENABLE_PUBLIC_INTERFACE', 'alpha');
119	$res = dolibarr_set_const($db, 'TICKET_ENABLE_PUBLIC_INTERFACE', $param_enable_public_interface, 'chaine', 0, '', $conf->entity);
120	if (!($res > 0)) {
121		$error++;
122	}
123
124	$param_must_exists = GETPOST('TICKET_EMAIL_MUST_EXISTS', 'alpha');
125	$res = dolibarr_set_const($db, 'TICKET_EMAIL_MUST_EXISTS', $param_must_exists, 'chaine', 0, '', $conf->entity);
126	if (!($res > 0)) {
127		$error++;
128	}
129
130	$param_disable_email = GETPOST('TICKET_DISABLE_CUSTOMER_MAILS', 'alpha');
131	$res = dolibarr_set_const($db, 'TICKET_DISABLE_CUSTOMER_MAILS', $param_disable_email, 'chaine', 0, '', $conf->entity);
132	if (!($res > 0)) {
133		$error++;
134	}
135
136   	$param_show_module_logo = GETPOST('TICKET_SHOW_COMPANY_LOGO', 'alpha');
137   	$res = dolibarr_set_const($db, 'TICKET_SHOW_COMPANY_LOGO', $param_show_module_logo, 'chaine', 0, '', $conf->entity);
138   	if (!($res > 0)) {
139	   	$error++;
140   	}
141
142	if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
143	{
144		$param_notification_also_main_addressemail = GETPOST('TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS', 'alpha');
145		$res = dolibarr_set_const($db, 'TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS', $param_notification_also_main_addressemail, 'chaine', 0, '', $conf->entity);
146		if (!($res > 0)) {
147			$error++;
148		}
149	}
150}
151
152
153
154/*
155 * View
156 */
157
158$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
159
160$form = new Form($db);
161
162$help_url = "FR:Module_Ticket";
163$page_name = "TicketSetup";
164llxHeader('', $langs->trans($page_name), $help_url);
165
166// Subheader
167$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
168
169print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
170
171// Configuration header
172$head = ticketAdminPrepareHead();
173
174print dol_get_fiche_head($head, 'public', $langs->trans("Module56000Name"), -1, "ticket");
175
176print '<span class="opacitymedium">'.$langs->trans("TicketPublicAccess").'</span> : <a class="wordbreak" href="'.dol_buildpath('/public/ticket/index.php', 1).'" target="_blank" >'.dol_buildpath('/public/ticket/index.php', 2).'</a>';
177
178print dol_get_fiche_end();
179
180
181$enabledisablehtml = $langs->trans("TicketsActivatePublicInterface").' ';
182if (empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE))
183{
184	// Button off, click to enable
185	$enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setTICKET_ENABLE_PUBLIC_INTERFACE&token='.newToken().'&value=1'.$param.'">';
186	$enabledisablehtml .= img_picto($langs->trans("Disabled"), 'switch_off');
187	$enabledisablehtml .= '</a>';
188} else {
189	// Button on, click to disable
190	$enabledisablehtml .= '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=setTICKET_ENABLE_PUBLIC_INTERFACE&token='.newToken().'&value=0'.$param.'">';
191	$enabledisablehtml .= img_picto($langs->trans("Activated"), 'switch_on');
192	$enabledisablehtml .= '</a>';
193}
194print $enabledisablehtml;
195print '<input type="hidden" id="TICKET_ENABLE_PUBLIC_INTERFACE" name="TICKET_ENABLE_PUBLIC_INTERFACE" value="'.(empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE) ? 0 : 1).'">';
196
197print '<br><br>';
198
199if (!empty($conf->global->TICKET_ENABLE_PUBLIC_INTERFACE))
200{
201	if (empty($conf->use_javascript_ajax)) {
202		print '<form method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data" >';
203		print '<input type="hidden" name="token" value="'.newToken().'">';
204		print '<input type="hidden" name="action" value="setvarother">';
205	}
206
207	print '<div class="div-table-responsive-no-min">';
208	print '<table class="noborder centpercent">';
209	print '<tr class="liste_titre"><td>'.$langs->trans("Parameters").'</td>';
210	print '<td class="left">';
211	print '</td>';
212	print '<td class="center">';
213	print '</td>';
214	print '</tr>';
215
216	// Check if email exists
217	print '<tr class="oddeven"><td>'.$langs->trans("TicketsEmailMustExist").'</td>';
218	print '<td class="left">';
219	if ($conf->use_javascript_ajax) {
220		print ajax_constantonoff('TICKET_EMAIL_MUST_EXISTS');
221	} else {
222		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
223		print $form->selectarray("TICKET_EMAIL_MUST_EXISTS", $arrval, $conf->global->TICKET_EMAIL_MUST_EXISTS);
224	}
225	print '</td>';
226	print '<td class="center">';
227	print $form->textwithpicto('', $langs->trans("TicketsEmailMustExistHelp"), 1, 'help');
228	print '</td>';
229	print '</tr>';
230
231	/*if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
232    {
233    	// Show logo for module
234    	print '<tr class="oddeven"><td>' . $langs->trans("TicketsShowModuleLogo") . '</td>';
235    	print '<td class="left">';
236    	if ($conf->use_javascript_ajax) {
237    	    print ajax_constantonoff('TICKET_SHOW_MODULE_LOGO');
238    	} else {
239    	    $arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
240    	    print $form->selectarray("TICKET_SHOW_MODULE_LOGO", $arrval, $conf->global->TICKET_SHOW_MODULE_LOGO);
241    	}
242    	print '</td>';
243    	print '<td class="center">';
244    	print $form->textwithpicto('', $langs->trans("TicketsShowModuleLogoHelp"), 1, 'help');
245    	print '</td>';
246    	print '</tr>';
247    }*/
248
249	// Show logo for company
250	print '<tr class="oddeven"><td>'.$langs->trans("TicketsShowCompanyLogo").'</td>';
251	print '<td class="left">';
252	if ($conf->use_javascript_ajax) {
253		print ajax_constantonoff('TICKET_SHOW_COMPANY_LOGO');
254	} else {
255		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
256		print $form->selectarray("TICKET_SHOW_COMPANY_LOGO", $arrval, $conf->global->TICKET_SHOW_COMPANY_LOGO);
257	}
258	print '</td>';
259	print '<td class="center">';
260	print $form->textwithpicto('', $langs->trans("TicketsShowCompanyLogoHelp"), 1, 'help');
261	print '</td>';
262	print '</tr>';
263
264	// Also send to main email address
265	if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
266	{
267		print '<tr class="oddeven"><td>'.$langs->trans("TicketsEmailAlsoSendToMainAddress").'</td>';
268		print '<td class="left">';
269		if ($conf->use_javascript_ajax) {
270			print ajax_constantonoff('TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS');
271		} else {
272			$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
273			print $form->selectarray("TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS", $arrval, $conf->global->TICKET_NOTIFICATION_ALSO_MAIN_ADDRESS);
274		}
275		print '</td>';
276		print '<td class="center">';
277		print $form->textwithpicto('', $langs->trans("TicketsEmailAlsoSendToMainAddressHelp"), 1, 'help');
278		print '</td>';
279		print '</tr>';
280	}
281
282	if (!$conf->use_javascript_ajax) {
283		print '<tr class="impair"><td colspan="3" align="center"><input type="submit" class="button button-save" value="'.$langs->trans("Save").'"></td>';
284		print '</tr>';
285	}
286
287	print '</table>';
288	print '</div>';
289	print '<br>';
290
291	if (!$conf->use_javascript_ajax) {
292		print '</form>';
293	}
294
295	// Admin var of module
296	print load_fiche_titre($langs->trans("TicketParamMail"));
297
298	print '<div class="div-table-responsive-no-min">';
299	print '<table class="noborder centpercent">';
300
301	print '<form method="post" action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data" >';
302	print '<input type="hidden" name="token" value="'.newToken().'">';
303	print '<input type="hidden" name="action" value="setvar">';
304
305	print '<tr class="liste_titre">';
306	print '<td colspan="3">'.$langs->trans("Parameter").'</td>';
307	print "</tr>\n";
308
309	if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) {
310		print '<tr>';
311		print '<td colspan="3"><div class="info">'.$langs->trans("TicketCkEditorEmailNotActivated").'</div></td>';
312		print "</tr>\n";
313	}
314
315	// Interface topic
316	$url_interface = $conf->global->TICKET_PUBLIC_INTERFACE_TOPIC;
317	print '<tr><td>'.$langs->trans("TicketPublicInterfaceTopicLabelAdmin").'</label>';
318	print '</td><td>';
319	print '<input type="text"   name="TICKET_PUBLIC_INTERFACE_TOPIC" value="'.$conf->global->TICKET_PUBLIC_INTERFACE_TOPIC.'" size="40" ></td>';
320	print '</td>';
321	print '<td class="center">';
322	print $form->textwithpicto('', $langs->trans("TicketPublicInterfaceTopicHelp"), 1, 'help');
323	print '</td></tr>';
324
325	// Texte d'accueil homepage
326	$public_text_home = $conf->global->TICKET_PUBLIC_TEXT_HOME ? $conf->global->TICKET_PUBLIC_TEXT_HOME : $langs->trans('TicketPublicInterfaceTextHome');
327	print '<tr><td>'.$langs->trans("TicketPublicInterfaceTextHomeLabelAdmin").'</label>';
328	print '</td><td>';
329	require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
330	$doleditor = new DolEditor('TICKET_PUBLIC_TEXT_HOME', $public_text_home, '100%', 180, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_2, 70);
331	$doleditor->Create();
332	print '</td>';
333	print '<td class="center">';
334	print $form->textwithpicto('', $langs->trans("TicketPublicInterfaceTextHomeHelpAdmin"), 1, 'help');
335	print '</td></tr>';
336
337	// Texte d'aide à la saisie du message
338	$public_text_help_message = $conf->global->TICKET_PUBLIC_TEXT_HELP_MESSAGE ? $conf->global->TICKET_PUBLIC_TEXT_HELP_MESSAGE : $langs->trans('TicketPublicPleaseBeAccuratelyDescribe');
339	print '<tr><td>'.$langs->trans("TicketPublicInterfaceTextHelpMessageLabelAdmin").'</label>';
340	print '</td><td>';
341	require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
342	$doleditor = new DolEditor('TICKET_PUBLIC_TEXT_HELP_MESSAGE', $public_text_help_message, '100%', 180, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_2, 70);
343	$doleditor->Create();
344	print '</td>';
345	print '<td class="center">';
346	print $form->textwithpicto('', $langs->trans("TicketPublicInterfaceTextHelpMessageHelpAdmin"), 1, 'help');
347	print '</td></tr>';
348
349	// Activate email creation to user
350	print '<tr class="pair"><td>'.$langs->trans("TicketsDisableCustomerEmail").'</td>';
351	print '<td class="left">';
352	if ($conf->use_javascript_ajax) {
353		print ajax_constantonoff('TICKET_DISABLE_CUSTOMER_MAILS');
354	} else {
355		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
356		print $form->selectarray("TICKET_DISABLE_CUSTOMER_MAILS", $arrval, $conf->global->TICKET_DISABLE_CUSTOMER_MAILS);
357	}
358	print '</td>';
359	print '<td class="center">';
360	print $form->textwithpicto('', $langs->trans("TicketsDisableEmailHelp"), 1, 'help');
361	print '</td>';
362	print '</tr>';
363
364	// Texte de création d'un ticket
365	$mail_mesg_new = $conf->global->TICKET_MESSAGE_MAIL_NEW ? $conf->global->TICKET_MESSAGE_MAIL_NEW : $langs->trans('TicketNewEmailBody');
366	print '<tr><td>'.$langs->trans("TicketNewEmailBodyLabel").'</label>';
367	print '</td><td>';
368	require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
369	$doleditor = new DolEditor('TICKET_MESSAGE_MAIL_NEW', $mail_mesg_new, '100%', 120, 'dolibarr_mailings', '', false, true, $conf->global->FCKEDITOR_ENABLE_MAIL, ROWS_2, 70);
370	$doleditor->Create();
371	print '</td>';
372	print '<td class="center">';
373	print $form->textwithpicto('', $langs->trans("TicketNewEmailBodyHelp"), 1, 'help');
374	print '</td></tr>';
375
376	// Url public interface
377	$url_interface = $conf->global->TICKET_URL_PUBLIC_INTERFACE;
378	print '<tr><td>'.$langs->trans("TicketUrlPublicInterfaceLabelAdmin").'</label>';
379	print '</td><td>';
380	print '<input type="text" class="minwidth500" name="TICKET_URL_PUBLIC_INTERFACE" value="'.$conf->global->TICKET_URL_PUBLIC_INTERFACE.'"></td>';
381	print '</td>';
382	print '<td class="center">';
383	print $form->textwithpicto('', $langs->trans("TicketUrlPublicInterfaceHelpAdmin"), 1, 'help');
384	print '</td></tr>';
385
386	// Activate email notification when a new message is added
387	print '<tr class="pair"><td>'.$langs->trans("TicketsPublicNotificationNewMessage").'</td>';
388	print '<td class="left">';
389	if ($conf->use_javascript_ajax) {
390		print ajax_constantonoff('TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED');
391	} else {
392		$arrval = array('0' => $langs->trans("No"), '1' => $langs->trans("Yes"));
393		print $form->selectarray("TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED", $arrval, $conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_ENABLED);
394	}
395	print '</td>';
396	print '<td align="center">';
397	print $form->textwithpicto('', $langs->trans("TicketsPublicNotificationNewMessageHelp"), 1, 'help');
398	print '</td>';
399	print '</tr>';
400
401	// Send notification when a new message is added to a email if a user is not assigned to the ticket
402	print '<tr><td>'.$langs->trans("TicketPublicNotificationNewMessageDefaultEmail").'</label>';
403	print '</td><td>';
404	print '<input type="text" name="TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL" value="'.$conf->global->TICKET_PUBLIC_NOTIFICATION_NEW_MESSAGE_DEFAULT_EMAIL.'" size="40" ></td>';
405	print '</td>';
406	print '<td align="center">';
407	print $form->textwithpicto('', $langs->trans("TicketPublicNotificationNewMessageDefaultEmailHelp"), 1, 'help');
408	print '</td></tr>';
409
410	print '</table>';
411	print '</div>';
412
413	print '<div class="center"><input type="submit" class="button button-save" value="'.$langs->trans("Save").'"></div>';
414
415	print '</form>';
416}
417
418// End of page
419llxFooter();
420$db->close();
421