2006-08-05 20:21:19 +02:00
< ? php
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2015-10-15 03:38:21 +02:00
* Copyright ( C ) 2005 - 2015 Laurent Destailleur < eldy @ users . sourceforge . org >
2022-03-12 16:50:48 +01:00
* Copyright ( C ) 2013 Juanjo Menent < jmenent @ 2 byte . es >
2016-03-11 21:07:38 +01:00
* Copyright ( C ) 2015 Bahfir Abbes < contact @ dolibarrpar . org >
2024-06-30 15:28:00 +02:00
* Copyright ( C ) 2020 Thibault FOUCART < support @ ptibogxiv . net >
2022-03-12 16:50:48 +01:00
* Copyright ( C ) 2022 Anthony Berton < anthony . berton @ bb2a . fr >
2024-11-04 23:53:20 +01:00
* Copyright ( C ) 2024 Frédéric France < frederic . france @ free . fr >
2006-08-05 20:21:19 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2006-08-05 20:21:19 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2006-08-05 20:21:19 +02:00
*/
2009-07-30 00:03:20 +02:00
2006-08-05 20:21:19 +02:00
/**
2009-07-30 00:03:20 +02:00
* \file htdocs / admin / notification . php
* \ingroup notification
2011-06-06 10:44:36 +02:00
* \brief Page to setup notification module
2009-07-30 00:03:20 +02:00
*/
2006-08-05 20:21:19 +02:00
2022-09-07 20:08:59 +02:00
// Load Dolibarr environment
2012-08-22 23:24:21 +02:00
require '../main.inc.php' ;
2015-03-18 21:44:57 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/notify.class.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/core/triggers/interface_50_modNotification_Notification.class.php' ;
2006-08-05 20:21:19 +02:00
2024-11-04 23:53:20 +01:00
/**
* @ var Conf $conf
* @ var DoliDB $db
* @ var HookManager $hookmanager
* @ var Translate $langs
* @ var User $user
*/
2018-05-26 18:41:16 +02:00
// Load translation files required by the page
2024-09-10 03:04:49 +02:00
$langs -> loadLangs ( array ( 'admin' , 'other' , 'orders' , 'propal' , 'bills' , 'errors' , 'mails' , 'contracts' ));
2006-08-05 20:21:19 +02:00
2009-07-30 00:03:20 +02:00
// Security check
2020-05-04 20:30:02 +02:00
if ( ! $user -> admin ) {
accessforbidden ();
}
2006-08-05 20:21:19 +02:00
2019-01-27 11:55:16 +01:00
$action = GETPOST ( 'action' , 'aZ09' );
2020-05-04 20:30:02 +02:00
$error = 0 ;
2006-08-05 20:21:19 +02:00
2014-10-25 00:42:52 +02:00
2011-06-06 10:44:36 +02:00
/*
* Actions
*/
2020-04-13 16:23:29 +02:00
2020-04-13 16:20:22 +02:00
// Action to update or add a constant
2021-08-17 04:14:28 +02:00
if ( $action == 'settemplates' && $user -> admin ) {
2020-05-04 20:30:02 +02:00
$db -> begin ();
2020-04-13 16:20:22 +02:00
2021-02-26 22:04:03 +01:00
if ( ! $error && is_array ( $_POST )) {
2020-05-04 20:30:02 +02:00
$reg = array ();
2021-02-26 22:04:03 +01:00
foreach ( $_POST as $key => $val ) {
if ( ! preg_match ( '/^constvalue_(.*)_TEMPLATE/' , $key , $reg )) {
continue ;
}
2020-05-04 20:30:02 +02:00
$triggername = $reg [ 1 ];
$constvalue = GETPOST ( $key , 'alpha' );
$consttype = 'emailtemplate:xxx' ;
2020-10-31 14:32:18 +01:00
$tmparray = explode ( ':' , $constvalue );
if ( ! empty ( $tmparray [ 0 ]) && ! empty ( $tmparray [ 1 ])) {
2020-05-04 20:30:02 +02:00
$constvalue = $tmparray [ 0 ];
$consttype = 'emailtemplate:' . $tmparray [ 1 ];
//var_dump($constvalue);
//var_dump($consttype);
$res = dolibarr_set_const ( $db , $triggername . '_TEMPLATE' , $constvalue , $consttype , 0 , '' , $conf -> entity );
if ( $res < 0 ) {
$error ++ ;
break ;
}
} else {
$res = dolibarr_del_const ( $db , $triggername . '_TEMPLATE' , $conf -> entity );
}
}
}
2020-04-13 16:20:22 +02:00
2021-02-26 22:04:03 +01:00
if ( ! $error ) {
2020-05-04 20:30:02 +02:00
$db -> commit ();
2020-04-13 16:20:22 +02:00
setEventMessages ( $langs -> trans ( " SetupSaved " ), null , 'mesgs' );
2020-05-21 09:35:30 +02:00
} else {
2020-05-04 20:30:02 +02:00
$db -> rollback ();
2020-04-13 16:20:22 +02:00
setEventMessages ( $langs -> trans ( " Error " ), null , 'errors' );
}
}
2011-06-06 10:44:36 +02:00
2021-02-26 22:04:03 +01:00
if ( $action == 'setvalue' && $user -> admin ) {
2015-03-18 21:44:57 +01:00
$db -> begin ();
2021-03-20 21:29:36 +01:00
$result = dolibarr_set_const ( $db , " NOTIFICATION_EMAIL_FROM " , GETPOST ( " email_from " , " alphawithlgt " ), 'chaine' , 0 , '' , $conf -> entity );
2021-02-26 22:04:03 +01:00
if ( $result < 0 ) {
$error ++ ;
}
2014-10-25 00:42:52 +02:00
2021-04-08 13:37:09 +02:00
$result = dolibarr_set_const ( $db , " NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE " , GETPOST ( " notif_disable " , " alphawithlgt " ), 'chaine' , 0 , '' , $conf -> entity );
if ( $result < 0 ) {
$error ++ ;
}
2020-05-04 20:30:02 +02:00
2021-02-26 22:04:03 +01:00
if ( ! $error ) {
2020-10-31 14:32:18 +01:00
$db -> commit ();
2020-05-04 20:30:02 +02:00
2020-10-31 14:32:18 +01:00
setEventMessages ( $langs -> trans ( " SetupSaved " ), null , 'mesgs' );
} else {
$db -> rollback ();
2020-05-04 20:30:02 +02:00
2020-10-31 14:32:18 +01:00
setEventMessages ( $langs -> trans ( " Error " ), null , 'errors' );
}
2020-05-04 20:30:02 +02:00
}
2021-02-26 22:04:03 +01:00
if ( $action == 'setfixednotif' && $user -> admin ) {
2020-05-04 20:30:02 +02:00
$db -> begin ();
2021-02-26 22:04:03 +01:00
if ( ! $error && is_array ( $_POST )) {
2020-10-31 14:32:18 +01:00
$reg = array ();
2021-02-26 22:04:03 +01:00
foreach ( $_POST as $key => $val ) {
if ( ! preg_match ( '/^NOTIF_(.*)_key$/' , $key , $reg )) {
continue ;
}
2015-03-18 21:44:57 +01:00
2020-10-31 14:32:18 +01:00
$newval = '' ;
$newkey = '' ;
2015-03-18 21:44:57 +01:00
2020-10-31 14:32:18 +01:00
$shortkey = preg_replace ( '/_key$/' , '' , $key );
//print $shortkey.'<br>';
2015-03-18 21:44:57 +01:00
2021-02-26 22:04:03 +01:00
if ( preg_match ( '/^NOTIF_(.*)_old_(.*)_key/' , $key , $reg )) {
2015-03-18 21:44:57 +01:00
dolibarr_del_const ( $db , 'NOTIFICATION_FIXEDEMAIL_' . $reg [ 1 ] . '_THRESHOLD_HIGHER_' . $reg [ 2 ], $conf -> entity );
2019-11-13 19:35:02 +01:00
$newkey = 'NOTIFICATION_FIXEDEMAIL_' . $reg [ 1 ] . '_THRESHOLD_HIGHER_' . (( int ) GETPOST ( $shortkey . '_amount' ));
$newval = GETPOST ( $shortkey . '_key' );
2023-12-13 12:46:23 +01:00
//print $newkey.' - '.$newval.'<br>';
2021-02-26 22:04:03 +01:00
} elseif ( preg_match ( '/^NOTIF_(.*)_new_key/' , $key , $reg )) {
2020-10-31 14:32:18 +01:00
// Add a new entry
$newkey = 'NOTIFICATION_FIXEDEMAIL_' . $reg [ 1 ] . '_THRESHOLD_HIGHER_' . (( int ) GETPOST ( $shortkey . '_amount' ));
$newval = GETPOST ( $shortkey . '_key' );
}
2021-02-26 22:04:03 +01:00
if ( $newkey && $newval ) {
2019-11-13 19:35:02 +01:00
$result = dolibarr_set_const ( $db , $newkey , $newval , 'chaine' , 0 , '' , $conf -> entity );
2020-10-31 14:32:18 +01:00
}
}
}
2014-10-25 00:42:52 +02:00
2021-02-26 22:04:03 +01:00
if ( ! $error ) {
2020-10-31 14:32:18 +01:00
$db -> commit ();
2015-03-18 21:44:57 +01:00
2020-10-31 14:32:18 +01:00
setEventMessages ( $langs -> trans ( " SetupSaved " ), null , 'mesgs' );
} else {
2015-03-18 21:44:57 +01:00
$db -> rollback ();
2020-10-31 14:32:18 +01:00
setEventMessages ( $langs -> trans ( " Error " ), null , 'errors' );
}
2006-08-05 20:21:19 +02:00
}
/*
2009-07-30 00:03:20 +02:00
* View
2006-08-05 20:21:19 +02:00
*/
2019-11-13 19:35:02 +01:00
$form = new Form ( $db );
2015-03-18 21:44:57 +01:00
$notify = new Notify ( $db );
2015-02-23 13:10:18 +01:00
2024-06-08 17:03:08 +02:00
llxHeader ( '' , $langs -> trans ( " NotificationSetup " ), '' , '' , 0 , 0 , '' , '' , '' , 'mod-admin page-notification' );
2006-08-05 20:21:19 +02:00
2019-11-13 19:35:02 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs -> trans ( " BackToModuleList " ) . '</a>' ;
2019-01-27 11:55:16 +01:00
print load_fiche_titre ( $langs -> trans ( " NotificationSetup " ), $linkback , 'title_setup' );
2006-08-05 20:21:19 +02:00
2021-08-17 04:28:16 +02:00
print '<span class="opacitymedium">' ;
2016-07-15 17:05:12 +02:00
print $langs -> trans ( " NotificationsDesc " ) . '<br>' ;
print $langs -> trans ( " NotificationsDescUser " ) . '<br>' ;
2022-08-23 20:01:34 +02:00
if ( isModEnabled ( " societe " )) {
2021-02-26 22:04:03 +01:00
print $langs -> trans ( " NotificationsDescContact " ) . '<br>' ;
}
2024-03-19 15:34:47 +01:00
print $langs -> trans ( " NotificationsDescGlobal " ) . ' - ' . $langs -> trans ( " YouAreHere " ) . '<br>' ;
2021-08-17 04:28:16 +02:00
print '</span>' ;
2016-07-15 17:05:12 +02:00
print '<br>' ;
2006-08-05 20:21:19 +02:00
print '<form method="post" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2019-12-18 23:12:31 +01:00
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
2006-08-05 20:21:19 +02:00
print '<input type="hidden" name="action" value="setvalue">' ;
2024-04-02 14:11:24 +02:00
print '<div class="div-table-responsive-no-min">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2006-08-05 20:21:19 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Parameter " ) . '</td>' ;
2025-01-24 13:12:48 +01:00
print '<td></td>' ;
2006-08-05 20:21:19 +02:00
print " </tr> \n " ;
2017-04-14 11:22:48 +02:00
2024-04-02 14:06:03 +02:00
2017-04-14 13:02:29 +02:00
print '<tr class="oddeven"><td>' ;
2015-10-15 03:38:21 +02:00
print $langs -> trans ( " NotificationEMailFrom " ) . '</td>' ;
print '<td>' ;
2021-08-17 04:14:28 +02:00
print img_picto ( '' , 'email' , 'class="pictofixedwidth"' );
2022-07-21 10:59:15 +02:00
print '<input class="width150 quatrevingtpercentminusx" type="email" name="email_from" value="' . getDolGlobalString ( 'NOTIFICATION_EMAIL_FROM' ) . '">' ;
2024-04-02 14:06:03 +02:00
if ( getDolGlobalString ( 'NOTIFICATION_EMAIL_FROM' ) && ! isValidEmail ( getDolGlobalString ( 'NOTIFICATION_EMAIL_FROM' ))) {
2021-02-26 22:04:03 +01:00
print ' ' . img_warning ( $langs -> trans ( " ErrorBadEMail " ));
}
2015-10-15 03:38:21 +02:00
print '</td>' ;
print '</tr>' ;
2021-04-08 13:50:55 +02:00
2024-04-02 14:06:03 +02:00
2021-12-23 15:12:35 +01:00
print '<tr class="oddeven"><td>' ;
2024-04-02 14:06:03 +02:00
print $langs -> trans ( " NotificationDisableConfirmMessageUser " ) . '</td>' ;
2021-12-23 15:12:35 +01:00
print '<td>' ;
if ( $conf -> use_javascript_ajax ) {
2024-04-02 14:06:03 +02:00
print ajax_constantonoff ( 'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_USER' );
2021-12-23 15:12:35 +01:00
} else {
$arrval = array ( '0' => $langs -> trans ( " No " ), '1' => $langs -> trans ( " Yes " ));
2024-04-02 14:06:03 +02:00
print $form -> selectarray ( " NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_USER " , $arrval , getDolGlobalString ( 'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_USER' ));
2021-12-23 15:12:35 +01:00
}
print '</td>' ;
print '</tr>' ;
2024-04-02 14:06:03 +02:00
2021-04-08 13:37:09 +02:00
print '<tr class="oddeven"><td>' ;
2024-04-02 14:06:03 +02:00
print $langs -> trans ( " NotificationDisableConfirmMessageContact " ) . '</td>' ;
2021-04-08 13:37:09 +02:00
print '<td>' ;
2021-04-29 00:03:16 +02:00
if ( $conf -> use_javascript_ajax ) {
2024-04-02 14:06:03 +02:00
print ajax_constantonoff ( 'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT' );
2021-04-29 00:03:16 +02:00
} else {
$arrval = array ( '0' => $langs -> trans ( " No " ), '1' => $langs -> trans ( " Yes " ));
2024-04-02 14:06:03 +02:00
print $form -> selectarray ( " NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT " , $arrval , getDolGlobalString ( 'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_CONTACT' ));
2021-04-29 00:03:16 +02:00
}
print '</td>' ;
print '</tr>' ;
2021-12-23 15:12:35 +01:00
2024-04-02 14:06:03 +02:00
2021-04-29 00:03:16 +02:00
print '<tr class="oddeven"><td>' ;
print $langs -> trans ( " NotificationDisableConfirmMessageFix " ) . '</td>' ;
print '<td>' ;
if ( $conf -> use_javascript_ajax ) {
print ajax_constantonoff ( 'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_FIX' );
} else {
$arrval = array ( '0' => $langs -> trans ( " No " ), '1' => $langs -> trans ( " Yes " ));
2022-07-21 10:59:15 +02:00
print $form -> selectarray ( " NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_FIX " , $arrval , getDolGlobalString ( 'NOTIFICATION_EMAIL_DISABLE_CONFIRM_MESSAGE_FIX' ));
2021-04-29 00:03:16 +02:00
}
2021-04-08 13:37:09 +02:00
print '</td>' ;
print '</tr>' ;
2024-04-02 14:06:03 +02:00
2009-07-30 00:03:20 +02:00
print '</table>' ;
2022-07-21 10:59:15 +02:00
print '</div>' ;
2009-07-30 00:03:20 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " Save " , '' );
2020-05-04 20:30:02 +02:00
print '</form>' ;
2016-07-15 17:05:12 +02:00
print '<br><br>' ;
2024-08-20 11:02:47 +02:00
// Emails templates for notification
2020-05-04 20:30:02 +02:00
print '<form method="post" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="settemplates">' ;
2021-12-23 15:12:35 +01:00
$title = $langs -> trans ( " TemplatesForNotifications " );
print load_fiche_titre ( $title , '' , 'email' );
2016-07-15 17:05:12 +02:00
2020-04-13 16:20:22 +02:00
// Load array of available notifications
$notificationtrigger = new InterfaceNotification ( $db );
$listofnotifiedevents = $notificationtrigger -> getListOfManagedEvents ();
2023-03-02 03:20:26 +01:00
2021-12-23 15:12:35 +01:00
// Editing global variables not related to a specific theme
$constantes = array ();
foreach ( $listofnotifiedevents as $notifiedevent ) {
$label = $langs -> trans ( " Notify_ " . $notifiedevent [ 'code' ]); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label'];
$elementLabel = $langs -> trans ( ucfirst ( $notifiedevent [ 'elementtype' ]));
2022-03-30 12:41:57 +02:00
2022-03-30 12:38:34 +02:00
$model = $notifiedevent [ 'elementtype' ];
2020-04-13 16:20:22 +02:00
2021-12-23 15:12:35 +01:00
if ( $notifiedevent [ 'elementtype' ] == 'order_supplier' ) {
$elementLabel = $langs -> trans ( 'SupplierOrder' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'propal' ) {
$elementLabel = $langs -> trans ( 'Proposal' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'facture' ) {
$elementLabel = $langs -> trans ( 'Bill' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'commande' ) {
$elementLabel = $langs -> trans ( 'Order' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'ficheinter' ) {
$elementLabel = $langs -> trans ( 'Intervention' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'shipping' ) {
$elementLabel = $langs -> trans ( 'Shipping' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'expensereport' || $notifiedevent [ 'elementtype' ] == 'expense_report' ) {
$elementLabel = $langs -> trans ( 'ExpenseReport' );
2024-09-10 03:04:49 +02:00
} elseif ( $notifiedevent [ 'elementtype' ] == 'contrat' ) {
$elementLabel = $langs -> trans ( 'Contract' );
2021-12-23 15:12:35 +01:00
}
2020-04-13 16:23:29 +02:00
2021-12-23 15:12:35 +01:00
if ( $notifiedevent [ 'elementtype' ] == 'propal' ) {
$model = 'propal_send' ;
} elseif ( $notifiedevent [ 'elementtype' ] == 'commande' ) {
$model = 'order_send' ;
} elseif ( $notifiedevent [ 'elementtype' ] == 'facture' ) {
$model = 'facture_send' ;
} elseif ( $notifiedevent [ 'elementtype' ] == 'shipping' ) {
$model = 'shipping_send' ;
} elseif ( $notifiedevent [ 'elementtype' ] == 'ficheinter' ) {
$model = 'fichinter_send' ;
} elseif ( $notifiedevent [ 'elementtype' ] == 'expensereport' ) {
$model = 'expensereport_send' ;
} elseif ( $notifiedevent [ 'elementtype' ] == 'order_supplier' ) {
$model = 'order_supplier_send' ;
2024-08-20 11:02:47 +02:00
} elseif ( $notifiedevent [ 'elementtype' ] == 'invoice_supplier' ) {
$model = 'invoice_supplier_send' ;
2021-12-23 15:12:35 +01:00
} elseif ( $notifiedevent [ 'elementtype' ] == 'member' ) {
$model = 'member' ;
2024-09-10 03:04:49 +02:00
} elseif ( $notifiedevent [ 'elementtype' ] == 'contrat' ) {
$model = 'contract_send' ;
2020-04-13 16:23:29 +02:00
}
2020-04-13 16:20:22 +02:00
2021-12-23 15:12:35 +01:00
$constantes [ $notifiedevent [ 'code' ] . '_TEMPLATE' ] = array ( 'type' => 'emailtemplate:' . $model , 'label' => $label );
}
2021-08-17 03:20:57 +02:00
2024-08-20 11:02:47 +02:00
$helptext = $langs -> trans ( " EmailTemplateHelp " , $langs -> transnoentitiesnoconv ( " Tools " ), $langs -> transnoentitiesnoconv ( " EMailTemplates " ));
2021-12-23 15:12:35 +01:00
form_constantes ( $constantes , 3 , $helptext , 'EmailTemplate' );
print $form -> buttonsSaveCancel ( " Save " , '' );
2021-04-27 22:14:19 +02:00
2021-12-23 15:12:35 +01:00
/*
2020-04-13 16:20:22 +02:00
} else {
2020-04-13 16:23:29 +02:00
print '<table class="noborder centpercent">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Label " ) . '</td>' ;
//print '<td class="right">'.$langs->trans("NbOfTargetedContacts").'</td>';
print " </tr> \n " ;
print '<tr class="oddeven">' ;
print '<td>' ;
$i = 0 ;
2021-02-26 22:04:03 +01:00
foreach ( $listofnotifiedevents as $notifiedevent ) {
2020-04-13 16:23:29 +02:00
$label = $langs -> trans ( " Notify_ " . $notifiedevent [ 'code' ]); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label'];
$elementLabel = $langs -> trans ( ucfirst ( $notifiedevent [ 'elementtype' ]));
2020-04-13 16:20:22 +02:00
2021-02-26 22:04:03 +01:00
if ( $notifiedevent [ 'elementtype' ] == 'order_supplier' ) {
$elementLabel = $langs -> trans ( 'SupplierOrder' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'propal' ) {
$elementLabel = $langs -> trans ( 'Proposal' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'facture' ) {
$elementLabel = $langs -> trans ( 'Bill' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'commande' ) {
$elementLabel = $langs -> trans ( 'Order' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'ficheinter' ) {
$elementLabel = $langs -> trans ( 'Intervention' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'shipping' ) {
$elementLabel = $langs -> trans ( 'Shipping' );
2021-04-27 22:14:19 +02:00
} elseif ( $notifiedevent [ 'elementtype' ] == 'expensereport' || $notifiedevent [ 'elementtype' ] == 'expense_report' ) {
2021-02-26 22:04:03 +01:00
$elementLabel = $langs -> trans ( 'ExpenseReport' );
}
2016-07-15 17:05:12 +02:00
2021-02-26 22:04:03 +01:00
if ( $i ) {
print ', ' ;
}
2020-04-13 16:23:29 +02:00
print $label ;
2017-07-09 20:31:27 +02:00
2020-04-13 16:23:29 +02:00
$i ++ ;
}
2020-04-13 16:20:22 +02:00
2020-04-13 16:23:29 +02:00
print '</td></tr>' ;
print '</table>' ;
2020-04-13 16:20:22 +02:00
2021-08-17 03:20:57 +02:00
print '<div class="opacitymedium">' ;
print '* ' . $langs -> trans ( " GoOntoUserCardToAddMore " ) . '<br>' ;
2022-08-23 20:01:34 +02:00
if ( isModEnabled ( " societe " )) {
2021-08-17 03:20:57 +02:00
print '** ' . $langs -> trans ( " GoOntoContactCardToAddMore " ) . '<br>' ;
}
print '</div>' ;
2021-04-27 22:14:19 +02:00
}
2021-12-23 15:12:35 +01:00
*/
2020-05-04 20:30:02 +02:00
print '</form>' ;
2020-04-13 16:20:22 +02:00
2016-07-15 17:05:12 +02:00
print '<br><br>' ;
2015-03-18 21:44:57 +01:00
2020-05-04 20:30:02 +02:00
print '<form method="post" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
print '<input type="hidden" name="token" value="' . newToken () . '">' ;
print '<input type="hidden" name="action" value="setfixednotif">' ;
2021-08-17 04:28:16 +02:00
print '<input type="hidden" name="page_y" value="">' ;
2020-05-04 20:30:02 +02:00
2021-12-23 15:12:35 +01:00
print load_fiche_titre ( $langs -> trans ( " ListOfFixedNotifications " ), '' , 'email' );
print '<div class="info">' ;
print $langs -> trans ( " Note " ) . ':<br>' ;
print '* ' . $langs -> trans ( " GoOntoUserCardToAddMore " ) . '<br>' ;
2022-08-23 20:01:34 +02:00
if ( isModEnabled ( " societe " )) {
2021-12-23 15:12:35 +01:00
print '** ' . $langs -> trans ( " GoOntoContactCardToAddMore " ) . '<br>' ;
}
print '</div>' ;
2011-06-06 10:44:36 +02:00
2022-07-21 10:59:15 +02:00
print '<div class="div-table-responsive">' ;
2019-11-05 21:24:41 +01:00
print '<table class="noborder centpercent">' ;
2011-06-06 10:44:36 +02:00
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Module " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Code " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Label " ) . '</td>' ;
2014-10-25 00:42:52 +02:00
print '<td>' . $langs -> trans ( " FixedEmailTarget " ) . '</td>' ;
2015-03-18 21:44:57 +01:00
print '<td>' . $langs -> trans ( " Threshold " ) . '</td>' ;
2020-04-27 00:02:31 +02:00
print '<td></td>' ;
2011-06-06 10:44:36 +02:00
print " </tr> \n " ;
2021-02-26 22:04:03 +01:00
foreach ( $listofnotifiedevents as $notifiedevent ) {
2020-10-31 14:32:18 +01:00
$label = $langs -> trans ( " Notify_ " . $notifiedevent [ 'code' ]); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label'];
2012-12-31 05:54:38 +01:00
2021-04-27 22:14:19 +02:00
$elementPicto = $notifiedevent [ 'elementtype' ];
2020-10-31 14:32:18 +01:00
$elementLabel = $langs -> trans ( ucfirst ( $notifiedevent [ 'elementtype' ]));
2018-10-25 12:45:13 +02:00
// Special cases
2021-02-26 22:04:03 +01:00
if ( $notifiedevent [ 'elementtype' ] == 'order_supplier' ) {
2021-04-27 22:14:19 +02:00
$elementPicto = 'supplier_order' ;
2021-02-26 22:04:03 +01:00
$elementLabel = $langs -> trans ( 'SupplierOrder' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'propal' ) {
$elementLabel = $langs -> trans ( 'Proposal' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'facture' ) {
2021-04-27 22:14:19 +02:00
$elementPicto = 'bill' ;
2021-02-26 22:04:03 +01:00
$elementLabel = $langs -> trans ( 'Bill' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'commande' ) {
2021-04-27 22:14:19 +02:00
$elementPicto = 'order' ;
2021-02-26 22:04:03 +01:00
$elementLabel = $langs -> trans ( 'Order' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'ficheinter' ) {
2021-04-27 22:14:19 +02:00
$elementPicto = 'intervention' ;
2021-02-26 22:04:03 +01:00
$elementLabel = $langs -> trans ( 'Intervention' );
} elseif ( $notifiedevent [ 'elementtype' ] == 'shipping' ) {
2021-04-27 22:14:19 +02:00
$elementPicto = 'shipment' ;
2021-02-26 22:04:03 +01:00
$elementLabel = $langs -> trans ( 'Shipping' );
2021-04-27 22:14:19 +02:00
} elseif ( $notifiedevent [ 'elementtype' ] == 'expensereport' || $notifiedevent [ 'elementtype' ] == 'expense_report' ) {
$elementPicto = 'expensereport' ;
2021-02-26 22:04:03 +01:00
$elementLabel = $langs -> trans ( 'ExpenseReport' );
2024-09-10 03:04:49 +02:00
} elseif ( $notifiedevent [ 'elementtype' ] == 'contrat' ) {
$elementPicto = 'contract' ;
$elementLabel = $langs -> trans ( 'Contract' );
2023-03-02 02:19:24 +01:00
} elseif ( $notifiedevent [ 'elementtype' ] == 'agenda' ) {
$elementPicto = 'action' ;
2021-02-26 22:04:03 +01:00
}
2012-12-31 05:54:38 +01:00
2024-09-10 03:04:49 +02:00
$labelfortrigger = 'AmountHT' ;
2021-08-17 04:28:16 +02:00
$codehasnotrigger = 0 ;
2023-03-02 02:19:24 +01:00
if ( preg_match ( '/^(ACTION|HOLIDAY)/' , $notifiedevent [ 'code' ])) {
2021-08-17 04:28:16 +02:00
$codehasnotrigger ++ ;
}
2020-10-31 14:32:18 +01:00
print '<tr class="oddeven">' ;
2021-04-27 22:14:19 +02:00
print '<td>' ;
print img_picto ( '' , $elementPicto , 'class="pictofixedwidth"' );
print $elementLabel ;
print '</td>' ;
2020-10-31 14:32:18 +01:00
print '<td>' . $notifiedevent [ 'code' ] . '</td>' ;
2021-04-27 22:14:19 +02:00
print '<td><span class="opacitymedium">' . $label . '</span></td>' ;
2020-10-31 14:32:18 +01:00
print '<td>' ;
2021-08-17 04:14:28 +02:00
$inputfieldalreadyshown = 0 ;
2020-10-31 14:32:18 +01:00
// Notification with threshold
2021-02-26 22:04:03 +01:00
foreach ( $conf -> global as $key => $val ) {
2024-01-10 08:59:45 +01:00
if ( $val == '' || ! preg_match ( '/^NOTIFICATION_FIXEDEMAIL_' . preg_quote ( $notifiedevent [ 'code' ], '/' ) . '_THRESHOLD_HIGHER_(.*)/' , $key , $reg )) {
2021-02-26 22:04:03 +01:00
continue ;
}
2015-03-18 21:44:57 +01:00
2020-10-31 14:32:18 +01:00
$param = 'NOTIFICATION_FIXEDEMAIL_' . $notifiedevent [ 'code' ] . '_THRESHOLD_HIGHER_' . $reg [ 1 ];
2023-12-23 20:00:57 +01:00
$value = GETPOST ( 'NOTIF_' . $notifiedevent [ 'code' ] . '_old_' . $reg [ 1 ] . '_key' ) ? GETPOST ( 'NOTIF_' . $notifiedevent [ 'code' ] . '_old_' . $reg [ 1 ] . '_key' , 'alpha' ) : getDolGlobalString ( $param );
2015-03-18 21:44:57 +01:00
2022-07-21 10:59:15 +02:00
$s = '<input type="text" class="minwidth200" name="NOTIF_' . $notifiedevent [ 'code' ] . '_old_' . $reg [ 1 ] . '_key" value="' . dol_escape_htmltag ( $value ) . '">' ; // Do not use type="email" here, we must be able to enter a list of email with , separator.
2020-10-31 14:32:18 +01:00
$arrayemail = explode ( ',' , $value );
2019-11-13 19:35:02 +01:00
$showwarning = 0 ;
2021-02-26 22:04:03 +01:00
foreach ( $arrayemail as $keydet => $valuedet ) {
2019-11-13 19:35:02 +01:00
$valuedet = trim ( $valuedet );
2021-02-26 22:04:03 +01:00
if ( ! empty ( $valuedet ) && ! isValidEmail ( $valuedet , 1 )) {
$showwarning ++ ;
}
}
2023-12-23 20:00:57 +01:00
if ( getDolGlobalString ( $param ) && $showwarning ) {
2021-02-26 22:04:03 +01:00
$s .= ' ' . img_warning ( $langs -> trans ( " ErrorBadEMail " ));
2015-03-18 21:44:57 +01:00
}
2020-10-31 14:32:18 +01:00
print $form -> textwithpicto ( $s , $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ) . '<br>' . $langs -> trans ( " YouCanAlsoUseSupervisorKeyword " ), 1 , 'help' , '' , 0 , 2 );
2015-03-18 21:44:57 +01:00
print '<br>' ;
2021-08-17 04:14:28 +02:00
$inputfieldalreadyshown ++ ;
2020-10-31 14:32:18 +01:00
}
// New entry input fields
2021-08-17 04:28:16 +02:00
if ( empty ( $inputfieldalreadyshown ) || ! $codehasnotrigger ) {
2022-07-21 10:59:15 +02:00
$s = '<input type="text" class="minwidth200" name="NOTIF_' . $notifiedevent [ 'code' ] . '_new_key" value="">' ; // Do not use type="email" here, we must be able to enter a list of email with , separator.
2021-08-17 04:14:28 +02:00
print $form -> textwithpicto ( $s , $langs -> trans ( " YouCanUseCommaSeparatorForSeveralRecipients " ) . '<br>' . $langs -> trans ( " YouCanAlsoUseSupervisorKeyword " ), 1 , 'help' , '' , 0 , 2 );
}
2020-10-31 14:32:18 +01:00
print '</td>' ;
print '<td>' ;
// Notification with threshold
2021-08-17 04:14:28 +02:00
$inputfieldalreadyshown = 0 ;
2021-02-26 22:04:03 +01:00
foreach ( $conf -> global as $key => $val ) {
if ( $val == '' || ! preg_match ( '/^NOTIFICATION_FIXEDEMAIL_' . $notifiedevent [ 'code' ] . '_THRESHOLD_HIGHER_(.*)/' , $key , $reg )) {
continue ;
}
2015-03-18 21:44:57 +01:00
2021-08-17 04:28:16 +02:00
if ( ! $codehasnotrigger ) {
2021-08-17 04:14:28 +02:00
print $langs -> trans ( $labelfortrigger ) . ' >= <input type="text" size="4" name="NOTIF_' . $notifiedevent [ 'code' ] . '_old_' . $reg [ 1 ] . '_amount" value="' . dol_escape_htmltag ( $reg [ 1 ]) . '">' ;
print '<br>' ;
$inputfieldalreadyshown ++ ;
}
2020-10-31 14:32:18 +01:00
}
// New entry input fields
2021-08-17 04:28:16 +02:00
if ( ! $codehasnotrigger ) {
2021-08-17 04:14:28 +02:00
print $langs -> trans ( $labelfortrigger ) . ' >= <input type="text" size="4" name="NOTIF_' . $notifiedevent [ 'code' ] . '_new_amount" value="">' ;
}
2015-03-18 21:44:57 +01:00
print '</td>' ;
2020-10-31 14:32:18 +01:00
print '<td>' ;
2015-03-18 21:44:57 +01:00
// TODO Add link to show message content
2020-10-31 14:32:18 +01:00
print '</td>' ;
print '</tr>' ;
2011-06-06 10:44:36 +02:00
}
print '</table>' ;
2022-07-21 10:59:15 +02:00
print '</div>' ;
2006-08-05 20:21:19 +02:00
2021-08-20 14:41:30 +02:00
print $form -> buttonsSaveCancel ( " Save " , '' );
2014-10-25 00:42:52 +02:00
print '</form>' ;
2018-07-28 18:03:14 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2014-10-25 00:42:52 +02:00
$db -> close ();