29 require
'../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
31 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/triggers/interface_50_modNotification_Notification.class.php';
35 $langs->loadLangs(array(
'admin',
'other',
'orders',
'propal',
'bills',
'errors',
'mails'));
42 $action =
GETPOST(
'action',
'aZ09');
51 if ($action ==
'settemplates' && $user->admin) {
54 if (!$error && is_array($_POST)) {
56 foreach ($_POST as $key => $val) {
57 if (!preg_match(
'/^constvalue_(.*)_TEMPLATE/', $key, $reg)) {
61 $triggername = $reg[1];
62 $constvalue =
GETPOST($key,
'alpha');
63 $consttype =
'emailtemplate:xxx';
64 $tmparray = explode(
':', $constvalue);
65 if (!empty($tmparray[0]) && !empty($tmparray[1])) {
66 $constvalue = $tmparray[0];
67 $consttype =
'emailtemplate:'.$tmparray[1];
70 $res =
dolibarr_set_const($db, $triggername.
'_TEMPLATE', $constvalue, $consttype, 0,
'', $conf->entity);
93 if ($action ==
'setvalue' && $user->admin) {
96 $result =
dolibarr_set_const($db,
"NOTIFICATION_EMAIL_FROM",
GETPOST(
"email_from",
"alphawithlgt"),
'chaine', 0,
'', $conf->entity);
101 $result =
dolibarr_set_const($db,
"NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE",
GETPOST(
"notif_disable",
"alphawithlgt"),
'chaine', 0,
'', $conf->entity);
118 if ($action ==
'setfixednotif' && $user->admin) {
121 if (!$error && is_array($_POST)) {
123 foreach ($_POST as $key => $val) {
124 if (!preg_match(
'/^NOTIF_(.*)_key$/', $key, $reg)) {
131 $shortkey = preg_replace(
'/_key$/',
'', $key);
134 if (preg_match(
'/^NOTIF_(.*)_old_(.*)_key/', $key, $reg)) {
135 dolibarr_del_const($db,
'NOTIFICATION_FIXEDEMAIL_'.$reg[1].
'_THRESHOLD_HIGHER_'.$reg[2], $conf->entity);
137 $newkey =
'NOTIFICATION_FIXEDEMAIL_'.$reg[1].
'_THRESHOLD_HIGHER_'.((int)
GETPOST($shortkey.
'_amount'));
138 $newval =
GETPOST($shortkey.
'_key');
140 } elseif (preg_match(
'/^NOTIF_(.*)_new_key/', $key, $reg)) {
142 $newkey =
'NOTIFICATION_FIXEDEMAIL_'.$reg[1].
'_THRESHOLD_HIGHER_'.((int)
GETPOST($shortkey.
'_amount'));
143 $newval =
GETPOST($shortkey.
'_key');
146 if ($newkey && $newval) {
170 $notify =
new Notify($db);
172 llxHeader(
'', $langs->trans(
"NotificationSetup"));
174 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
175 print
load_fiche_titre($langs->trans(
"NotificationSetup"), $linkback,
'title_setup');
177 print
'<span class="opacitymedium">';
178 print $langs->trans(
"NotificationsDesc").
'<br>';
179 print $langs->trans(
"NotificationsDescUser").
'<br>';
180 if (!empty($conf->societe->enabled)) {
181 print $langs->trans(
"NotificationsDescContact").
'<br>';
183 print $langs->trans(
"NotificationsDescGlobal").
'<br>';
187 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
188 print
'<input type="hidden" name="token" value="'.newToken().
'">';
189 print
'<input type="hidden" name="action" value="setvalue">';
191 print
'<div class="div-table-responsive">';
192 print
'<table class="noborder centpercent">';
193 print
'<tr class="liste_titre">';
194 print
'<td>'.$langs->trans(
"Parameter").
'</td>';
195 print
'<td>'.$langs->trans(
"Value").
'</td>';
198 print
'<tr class="oddeven"><td>';
199 print $langs->trans(
"NotificationEMailFrom").
'</td>';
201 print
img_picto(
'',
'email',
'class="pictofixedwidth"');
202 print
'<input class="width150 quatrevingtpercentminusx" type="email" name="email_from" value="'.getDolGlobalString(
'NOTIFICATION_EMAIL_FROM').
'">';
203 if (!empty($conf->global->NOTIFICATION_EMAIL_FROM) && !
isValidEmail($conf->global->NOTIFICATION_EMAIL_FROM)) {
204 print
' '.img_warning($langs->trans(
"ErrorBadEMail"));
209 print
'<tr class="oddeven"><td>';
210 print $langs->trans(
"NotificationDisableConfirmMessageContact").
'</td>';
212 if ($conf->use_javascript_ajax) {
215 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
216 print
$form->selectarray(
"NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT", $arrval,
getDolGlobalString(
'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT'));
221 print
'<tr class="oddeven"><td>';
222 print $langs->trans(
"NotificationDisableConfirmMessageUser").
'</td>';
224 if ($conf->use_javascript_ajax) {
227 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
228 print
$form->selectarray(
"NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_USER", $arrval,
getDolGlobalString(
'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_USER'));
233 print
'<tr class="oddeven"><td>';
234 print $langs->trans(
"NotificationDisableConfirmMessageFix").
'</td>';
236 if ($conf->use_javascript_ajax) {
239 $arrval = array(
'0' => $langs->trans(
"No"),
'1' => $langs->trans(
"Yes"));
240 print
$form->selectarray(
"NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_FIX", $arrval,
getDolGlobalString(
'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_FIX'));
247 print
$form->buttonsSaveCancel(
"Save",
'');
255 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
256 print
'<input type="hidden" name="token" value="'.newToken().
'">';
257 print
'<input type="hidden" name="action" value="settemplates">';
260 $title = $langs->trans(
"TemplatesForNotifications");
266 $listofnotifiedevents = $notificationtrigger->getListOfManagedEvents();
269 $constantes = array();
270 foreach ($listofnotifiedevents as $notifiedevent) {
271 $label = $langs->trans(
"Notify_".$notifiedevent[
'code']);
272 $elementLabel = $langs->trans(ucfirst($notifiedevent[
'elementtype']));
274 $model = $notifiedevent[
'elementtype'];
276 if ($notifiedevent[
'elementtype'] ==
'order_supplier') {
277 $elementLabel = $langs->trans(
'SupplierOrder');
278 } elseif ($notifiedevent[
'elementtype'] ==
'propal') {
279 $elementLabel = $langs->trans(
'Proposal');
280 } elseif ($notifiedevent[
'elementtype'] ==
'facture') {
281 $elementLabel = $langs->trans(
'Bill');
282 } elseif ($notifiedevent[
'elementtype'] ==
'commande') {
283 $elementLabel = $langs->trans(
'Order');
284 } elseif ($notifiedevent[
'elementtype'] ==
'ficheinter') {
285 $elementLabel = $langs->trans(
'Intervention');
286 } elseif ($notifiedevent[
'elementtype'] ==
'shipping') {
287 $elementLabel = $langs->trans(
'Shipping');
288 } elseif ($notifiedevent[
'elementtype'] ==
'expensereport' || $notifiedevent[
'elementtype'] ==
'expense_report') {
289 $elementLabel = $langs->trans(
'ExpenseReport');
292 if ($notifiedevent[
'elementtype'] ==
'propal') {
293 $model =
'propal_send';
294 } elseif ($notifiedevent[
'elementtype'] ==
'commande') {
295 $model =
'order_send';
296 } elseif ($notifiedevent[
'elementtype'] ==
'facture') {
297 $model =
'facture_send';
298 } elseif ($notifiedevent[
'elementtype'] ==
'shipping') {
299 $model =
'shipping_send';
300 } elseif ($notifiedevent[
'elementtype'] ==
'ficheinter') {
301 $model =
'fichinter_send';
302 } elseif ($notifiedevent[
'elementtype'] ==
'expensereport') {
303 $model =
'expensereport_send';
304 } elseif ($notifiedevent[
'elementtype'] ==
'order_supplier') {
305 $model =
'order_supplier_send';
307 } elseif ($notifiedevent[
'elementtype'] ==
'member') {
311 $constantes[$notifiedevent[
'code'].
'_TEMPLATE'] = array(
'type'=>
'emailtemplate:'.$model,
'label'=>$label);
317 print
$form->buttonsSaveCancel(
"Save",
'');
377 print
'<form method="post" action="'.$_SERVER[
"PHP_SELF"].
'">';
378 print
'<input type="hidden" name="token" value="'.newToken().
'">';
379 print
'<input type="hidden" name="action" value="setfixednotif">';
380 print
'<input type="hidden" name="page_y" value="">';
382 print
load_fiche_titre($langs->trans(
"ListOfFixedNotifications"),
'',
'email');
384 print
'<div class="info">';
385 print $langs->trans(
"Note").
':<br>';
386 print
'* '.$langs->trans(
"GoOntoUserCardToAddMore").
'<br>';
387 if (!empty($conf->societe->enabled)) {
388 print
'** '.$langs->trans(
"GoOntoContactCardToAddMore").
'<br>';
392 print
'<div class="div-table-responsive">';
393 print
'<table class="noborder centpercent">';
394 print
'<tr class="liste_titre">';
395 print
'<td>'.$langs->trans(
"Module").
'</td>';
396 print
'<td>'.$langs->trans(
"Code").
'</td>';
397 print
'<td>'.$langs->trans(
"Label").
'</td>';
398 print
'<td>'.$langs->trans(
"FixedEmailTarget").
'</td>';
399 print
'<td>'.$langs->trans(
"Threshold").
'</td>';
403 foreach ($listofnotifiedevents as $notifiedevent) {
404 $label = $langs->trans(
"Notify_".$notifiedevent[
'code']);
406 $elementPicto = $notifiedevent[
'elementtype'];
407 $elementLabel = $langs->trans(ucfirst($notifiedevent[
'elementtype']));
409 if ($notifiedevent[
'elementtype'] ==
'order_supplier') {
410 $elementPicto =
'supplier_order';
411 $elementLabel = $langs->trans(
'SupplierOrder');
412 } elseif ($notifiedevent[
'elementtype'] ==
'propal') {
413 $elementLabel = $langs->trans(
'Proposal');
414 } elseif ($notifiedevent[
'elementtype'] ==
'facture') {
415 $elementPicto =
'bill';
416 $elementLabel = $langs->trans(
'Bill');
417 } elseif ($notifiedevent[
'elementtype'] ==
'commande') {
418 $elementPicto =
'order';
419 $elementLabel = $langs->trans(
'Order');
420 } elseif ($notifiedevent[
'elementtype'] ==
'ficheinter') {
421 $elementPicto =
'intervention';
422 $elementLabel = $langs->trans(
'Intervention');
423 } elseif ($notifiedevent[
'elementtype'] ==
'shipping') {
424 $elementPicto =
'shipment';
425 $elementLabel = $langs->trans(
'Shipping');
426 } elseif ($notifiedevent[
'elementtype'] ==
'expensereport' || $notifiedevent[
'elementtype'] ==
'expense_report') {
427 $elementPicto =
'expensereport';
428 $elementLabel = $langs->trans(
'ExpenseReport');
431 $labelfortrigger =
'AmountHT';
432 $codehasnotrigger = 0;
433 if (preg_match(
'/^HOLIDAY/', $notifiedevent[
'code'])) {
437 print
'<tr class="oddeven">';
439 print
img_picto(
'', $elementPicto,
'class="pictofixedwidth"');
442 print
'<td>'.$notifiedevent[
'code'].
'</td>';
443 print
'<td><span class="opacitymedium">'.$label.
'</span></td>';
445 $inputfieldalreadyshown = 0;
447 foreach ($conf->global as $key => $val) {
448 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifiedevent[
'code'].
'_THRESHOLD_HIGHER_(.*)/', $key, $reg)) {
452 $param =
'NOTIFICATION_FIXEDEMAIL_'.$notifiedevent[
'code'].
'_THRESHOLD_HIGHER_'.$reg[1];
453 $value =
GETPOST(
'NOTIF_'.$notifiedevent[
'code'].
'_old_'.$reg[1].
'_key') ?
GETPOST(
'NOTIF_'.$notifiedevent[
'code'].
'_old_'.$reg[1].
'_key',
'alpha') : $conf->global->$param;
455 $s =
'<input type="text" class="minwidth200" name="NOTIF_'.$notifiedevent[
'code'].
'_old_'.$reg[1].
'_key" value="'.
dol_escape_htmltag($value).
'">';
456 $arrayemail = explode(
',', $value);
458 foreach ($arrayemail as $keydet => $valuedet) {
459 $valuedet = trim($valuedet);
464 if ((!empty($conf->global->$param)) && $showwarning) {
465 $s .=
' '.img_warning($langs->trans(
"ErrorBadEMail"));
467 print
$form->textwithpicto($s, $langs->trans(
"YouCanUseCommaSeparatorForSeveralRecipients").
'<br>'.$langs->trans(
"YouCanAlsoUseSupervisorKeyword"), 1,
'help',
'', 0, 2);
470 $inputfieldalreadyshown++;
473 if (empty($inputfieldalreadyshown) || !$codehasnotrigger) {
474 $s =
'<input type="text" class="minwidth200" name="NOTIF_'.$notifiedevent[
'code'].
'_new_key" value="">';
475 print
$form->textwithpicto($s, $langs->trans(
"YouCanUseCommaSeparatorForSeveralRecipients").
'<br>'.$langs->trans(
"YouCanAlsoUseSupervisorKeyword"), 1,
'help',
'', 0, 2);
481 $inputfieldalreadyshown = 0;
482 foreach ($conf->global as $key => $val) {
483 if ($val ==
'' || !preg_match(
'/^NOTIFICATION_FIXEDEMAIL_'.$notifiedevent[
'code'].
'_THRESHOLD_HIGHER_(.*)/', $key, $reg)) {
487 if (!$codehasnotrigger) {
488 print $langs->trans($labelfortrigger).
' >= <input type="text" size="4" name="NOTIF_'.$notifiedevent[
'code'].
'_old_'.$reg[1].
'_amount" value="'.
dol_escape_htmltag($reg[1]).
'">';
491 $inputfieldalreadyshown++;
495 if (!$codehasnotrigger) {
496 print $langs->trans($labelfortrigger).
' >= <input type="text" size="4" name="NOTIF_'.$notifiedevent[
'code'].
'_new_amount" value="">';
509 print
$form->buttonsSaveCancel(
"Save",
'');