2006-08-05 20:21:19 +02:00
< ? php
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2011-06-06 10:44:36 +02:00
* Copyright ( C ) 2005 - 2011 Laurent Destailleur < eldy @ users . sourceforge . org >
2013-08-20 16:10:01 +02:00
* Copyright ( C ) 2013 Juanjo Menent < jmenent @ 2 byte . es >
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
2011-08-01 00:21:57 +02:00
* along with this program . If not , see < http :// 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
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
$langs -> load ( " admin " );
2011-09-06 12:52:42 +02:00
$langs -> load ( " other " );
2012-12-31 05:54:38 +01:00
$langs -> load ( " orders " );
$langs -> load ( " propal " );
$langs -> load ( " bills " );
2014-10-25 00:42:52 +02:00
$langs -> load ( " errors " );
2015-02-23 13:10:18 +01:00
$langs -> load ( " mails " );
2006-08-05 20:21:19 +02:00
2009-07-30 00:03:20 +02:00
// Security check
2006-08-05 20:21:19 +02:00
if ( ! $user -> admin )
accessforbidden ();
2011-09-06 12:52:42 +02:00
$action = GETPOST ( " action " );
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
*/
2011-09-06 12:52:42 +02:00
if ( $action == 'setvalue' && $user -> admin )
2006-08-05 20:21:19 +02:00
{
2015-03-18 21:44:57 +01:00
$db -> begin ();
2014-10-25 00:42:52 +02:00
$result = dolibarr_set_const ( $db , " NOTIFICATION_EMAIL_FROM " , $_POST [ " email_from " ], 'chaine' , 0 , '' , $conf -> entity );
if ( $result < 0 ) $error ++ ;
if ( ! $error )
{
2015-03-18 21:44:57 +01:00
//var_dump($_POST);
2014-10-25 00:42:52 +02:00
foreach ( $_POST as $key => $val )
{
2015-03-18 21:44:57 +01:00
if ( ! preg_match ( '/^NOTIF_(.*)_key$/' , $key , $reg )) continue ;
$newval = '' ;
$newkey = '' ;
$shortkey = preg_replace ( '/_key$/' , '' , $key );
//print $shortkey.'<br>';
if ( preg_match ( '/^NOTIF_(.*)_old_(.*)_key/' , $key , $reg ))
{
dolibarr_del_const ( $db , 'NOTIFICATION_FIXEDEMAIL_' . $reg [ 1 ] . '_THRESHOLD_HIGHER_' . $reg [ 2 ], $conf -> entity );
$newkey = 'NOTIFICATION_FIXEDEMAIL_' . $reg [ 1 ] . '_THRESHOLD_HIGHER_' . (( int ) GETPOST ( $shortkey . '_amount' ));
$newval = GETPOST ( $shortkey . '_key' );
//print $newkey.' - '.$newval.'<br>';
}
else if ( preg_match ( '/^NOTIF_(.*)_new_key/' , $key , $reg ))
{
// Add a new entry
$newkey = 'NOTIFICATION_FIXEDEMAIL_' . $reg [ 1 ] . '_THRESHOLD_HIGHER_' . (( int ) GETPOST ( $shortkey . '_amount' ));
$newval = GETPOST ( $shortkey . '_key' );
}
if ( $newkey && $newval )
{
$result = dolibarr_set_const ( $db , $newkey , $newval , 'chaine' , 0 , '' , $conf -> entity );
}
2014-10-25 00:42:52 +02:00
}
}
if ( ! $error )
2013-08-20 16:10:01 +02:00
{
2015-03-18 21:44:57 +01:00
$db -> commit ();
2013-08-20 16:10:01 +02:00
setEventMessage ( $langs -> trans ( " SetupSaved " ));
}
else
2014-10-25 00:42:52 +02:00
{
2015-03-18 21:44:57 +01:00
$db -> rollback ();
2013-08-20 16:10:01 +02:00
setEventMessage ( $langs -> trans ( " Error " ), '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
*/
2015-02-23 13:10:18 +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
llxHeader ( '' , $langs -> trans ( " NotificationSetup " ));
2006-08-05 20:21:19 +02:00
2008-01-26 16:10:18 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs -> trans ( " BackToModuleList " ) . '</a>' ;
2015-04-18 19:47:09 +02:00
print_fiche_titre ( $langs -> trans ( " NotificationSetup " ), $linkback , 'title_setup' );
2006-08-05 20:21:19 +02:00
2014-10-25 00:42:52 +02:00
print $langs -> trans ( " NotificationsDesc " ) . '<br><br>' ;
2006-08-05 20:21:19 +02:00
print '<form method="post" action="' . $_SERVER [ " PHP_SELF " ] . '">' ;
2009-05-17 10:01:54 +02:00
print '<input type="hidden" name="token" value="' . $_SESSION [ 'newtoken' ] . '">' ;
2006-08-05 20:21:19 +02:00
print '<input type="hidden" name="action" value="setvalue">' ;
$var = true ;
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Parameter " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Value " ) . '</td>' ;
print " </tr> \n " ;
$var =! $var ;
print '<tr ' . $bc [ $var ] . '><td>' ;
print $langs -> trans ( " NotificationEMailFrom " ) . '</td><td>' ;
2014-10-25 00:42:52 +02:00
print '<input size="32" type="email" name="email_from" value="' . $conf -> global -> NOTIFICATION_EMAIL_FROM . '">' ;
if ( ! empty ( $conf -> global -> NOTIFICATION_EMAIL_FROM ) && ! isValidEmail ( $conf -> global -> NOTIFICATION_EMAIL_FROM )) print ' ' . img_warning ( $langs -> trans ( " ErrorBadEMail " ));
2006-08-05 20:21:19 +02:00
print '</td></tr>' ;
2009-07-30 00:03:20 +02:00
print '</table>' ;
print '<br>' ;
2015-03-18 21:44:57 +01:00
if ( $conf -> societe -> enabled )
{
print_fiche_titre ( $langs -> trans ( " ListOfNotificationsPerContact " ), '' , '' );
print '<table class="noborder" width="100%">' ;
print '<tr class="liste_titre">' ;
print '<td>' . $langs -> trans ( " Module " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Code " ) . '</td>' ;
print '<td>' . $langs -> trans ( " Label " ) . '</td>' ;
print '<td align="right">' . $langs -> trans ( " NbOfTargetedContacts " ) . '</td>' ;
print '<td>' . '</td>' ;
print " </tr> \n " ;
// Load array of available notifications
$notificationtrigger = new InterfaceNotification ( $db );
$listofnotifiedevents = $notificationtrigger -> getListOfManagedEvents ();
$var = true ;
foreach ( $listofnotifiedevents as $notifiedevent )
{
$var =! $var ;
$label = $langs -> trans ( " Notify_ " . $notifiedevent [ 'code' ]); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label'];
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' );
print '<tr ' . $bc [ $var ] . '>' ;
print '<td>' . $elementLabel . '</td>' ;
print '<td>' . $notifiedevent [ 'code' ] . '</td>' ;
print '<td>' . $label . '</td>' ;
print '<td align="right">' ;
2015-04-13 17:04:18 +02:00
$tmparray = $notify -> getNotificationsArray ( $notifiedevent [ 'code' ], 0 );
print count ( $tmparray );
2015-03-18 21:44:57 +01:00
print '</td>' ;
print '</tr>' ;
}
print '</table>' ;
print '* ' . $langs -> trans ( " GoOntoContactCardToAddMore " ) . '<br>' ;
print '<br>' ;
}
print_fiche_titre ( $langs -> trans ( " ListOfFixedNotifications " ), '' , '' );
2011-06-06 10:44:36 +02:00
print '<table class="noborder" width="100%">' ;
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>' ;
print '<td>' . '</td>' ;
2011-06-06 10:44:36 +02:00
print " </tr> \n " ;
// Load array of available notifications
$notificationtrigger = new InterfaceNotification ( $db );
$listofnotifiedevents = $notificationtrigger -> getListOfManagedEvents ();
2015-03-18 21:44:57 +01:00
$var = true ;
2011-06-06 10:44:36 +02:00
foreach ( $listofnotifiedevents as $notifiedevent )
{
$var =! $var ;
2011-09-06 12:52:42 +02: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
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' );
2011-06-06 10:44:36 +02:00
print '<tr ' . $bc [ $var ] . '>' ;
2012-12-31 05:54:38 +01:00
print '<td>' . $elementLabel . '</td>' ;
2011-06-06 10:44:36 +02:00
print '<td>' . $notifiedevent [ 'code' ] . '</td>' ;
print '<td>' . $label . '</td>' ;
2015-02-23 13:10:18 +01:00
print '<td>' ;
2015-03-18 21:44:57 +01:00
// Notification with threshold
foreach ( $conf -> global as $key => $val )
{
if ( $val == '' || ! preg_match ( '/^NOTIFICATION_FIXEDEMAIL_' . $notifiedevent [ 'code' ] . '_THRESHOLD_HIGHER_(.*)/' , $key , $reg )) continue ;
$param = 'NOTIFICATION_FIXEDEMAIL_' . $notifiedevent [ 'code' ] . '_THRESHOLD_HIGHER_' . $reg [ 1 ];
$value = GETPOST ( 'NOTIF_' . $notifiedevent [ 'code' ] . '_old_' . $reg [ 1 ] . '_key' ) ? GETPOST ( 'NOTIF_' . $notifiedevent [ 'code' ] . '_old_' . $reg [ 1 ] . '_key' , 'alpha' ) : $conf -> global -> $param ;
$s = '<input type="text" size="32" 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.
$arrayemail = explode ( ',' , $value );
$showwarning = 0 ;
foreach ( $arrayemail as $key => $valuedet )
{
$valuedet = trim ( $valuedet );
2015-03-19 11:47:30 +01:00
if ( ! empty ( $valuedet ) && ! isValidEmail ( $valuedet , 1 )) $showwarning ++ ;
2015-03-18 21:44:57 +01:00
}
if (( ! empty ( $conf -> global -> $param )) && $showwarning ) $s .= ' ' . img_warning ( $langs -> trans ( " ErrorBadEMail " ));
2015-03-19 11:47:30 +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>' ;
}
// New entry input fields
$s = '<input type="text" size="32" 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.
2015-03-23 14:43:19 +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 '</td>' ;
print '<td>' ;
// Notification with threshold
foreach ( $conf -> global as $key => $val )
{
if ( $val == '' || ! preg_match ( '/^NOTIFICATION_FIXEDEMAIL_' . $notifiedevent [ 'code' ] . '_THRESHOLD_HIGHER_(.*)/' , $key , $reg )) continue ;
print $langs -> trans ( " AmountHT " ) . ' >= <input type="text" size="4" name="NOTIF_' . $notifiedevent [ 'code' ] . '_old_' . $reg [ 1 ] . '_amount" value="' . dol_escape_htmltag ( $reg [ 1 ]) . '">' ;
print '<br>' ;
}
// New entry input fields
print $langs -> trans ( " AmountHT " ) . ' >= <input type="text" size="4" name="NOTIF_' . $notifiedevent [ 'code' ] . '_new_amount" value="">' ;
print '</td>' ;
print '<td>' ;
// TODO Add link to show message content
2014-10-25 00:42:52 +02:00
print '</td>' ;
2011-06-06 10:44:36 +02:00
print '</tr>' ;
}
print '</table>' ;
2006-08-05 20:21:19 +02:00
2014-10-25 00:42:52 +02:00
print '<br>' ;
2014-11-25 20:13:43 +01:00
print '<div class="center"><input type="submit" class="button" value="' . $langs -> trans ( " Save " ) . '"></div>' ;
2014-10-25 00:42:52 +02:00
print '</form>' ;
2006-08-05 20:21:19 +02:00
2011-08-27 16:24:16 +02:00
llxFooter ();
2014-10-25 00:42:52 +02:00
$db -> close ();