notification.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005-2015 Laurent Destailleur <eldy@users.sourceforge.org>
  4. * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
  5. * Copyright (C) 2015 Bahfir Abbes <contact@dolibarrpar.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/admin/notification.php
  22. * \ingroup notification
  23. * \brief Page to setup notification module
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/triggers/interface_50_modNotification_Notification.class.php';
  29. $langs->load("admin");
  30. $langs->load("other");
  31. $langs->load("orders");
  32. $langs->load("propal");
  33. $langs->load("bills");
  34. $langs->load("errors");
  35. $langs->load("mails");
  36. // Security check
  37. if (!$user->admin)
  38. accessforbidden();
  39. $action = GETPOST('action','aZ09');
  40. /*
  41. * Actions
  42. */
  43. if ($action == 'setvalue' && $user->admin)
  44. {
  45. $db->begin();
  46. $result=dolibarr_set_const($db, "NOTIFICATION_EMAIL_FROM", $_POST["email_from"], 'chaine', 0, '', $conf->entity);
  47. if ($result < 0) $error++;
  48. if (! $error)
  49. {
  50. //var_dump($_POST);
  51. foreach($_POST as $key => $val)
  52. {
  53. if (! preg_match('/^NOTIF_(.*)_key$/', $key, $reg)) continue;
  54. $newval='';
  55. $newkey='';
  56. $shortkey=preg_replace('/_key$/','',$key);
  57. //print $shortkey.'<br>';
  58. if (preg_match('/^NOTIF_(.*)_old_(.*)_key/',$key,$reg))
  59. {
  60. dolibarr_del_const($db, 'NOTIFICATION_FIXEDEMAIL_'.$reg[1].'_THRESHOLD_HIGHER_'.$reg[2], $conf->entity);
  61. $newkey='NOTIFICATION_FIXEDEMAIL_'.$reg[1].'_THRESHOLD_HIGHER_'.((int) GETPOST($shortkey.'_amount'));
  62. $newval=GETPOST($shortkey.'_key');
  63. //print $newkey.' - '.$newval.'<br>';
  64. }
  65. else if (preg_match('/^NOTIF_(.*)_new_key/',$key,$reg))
  66. {
  67. // Add a new entry
  68. $newkey='NOTIFICATION_FIXEDEMAIL_'.$reg[1].'_THRESHOLD_HIGHER_'.((int) GETPOST($shortkey.'_amount'));
  69. $newval=GETPOST($shortkey.'_key');
  70. }
  71. if ($newkey && $newval)
  72. {
  73. $result=dolibarr_set_const($db, $newkey, $newval, 'chaine', 0, '', $conf->entity);
  74. }
  75. }
  76. }
  77. if (! $error)
  78. {
  79. $db->commit();
  80. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  81. }
  82. else
  83. {
  84. $db->rollback();
  85. setEventMessages($langs->trans("Error"), null, 'errors');
  86. }
  87. }
  88. /*
  89. * View
  90. */
  91. $form=new Form($db);
  92. $notify = new Notify($db);
  93. llxHeader('',$langs->trans("NotificationSetup"));
  94. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  95. print load_fiche_titre($langs->trans("NotificationSetup"),$linkback,'title_setup');
  96. print $langs->trans("NotificationsDesc").'<br>';
  97. print $langs->trans("NotificationsDescUser").'<br>';
  98. if (! empty($conf->societe->enabled)) print $langs->trans("NotificationsDescContact").'<br>';
  99. print $langs->trans("NotificationsDescGlobal").'<br>';
  100. print '<br>';
  101. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
  102. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  103. print '<input type="hidden" name="action" value="setvalue">';
  104. $var=true;
  105. print '<table class="noborder" width="100%">';
  106. print '<tr class="liste_titre">';
  107. print '<td>'.$langs->trans("Parameter").'</td>';
  108. print '<td>'.$langs->trans("Value").'</td>';
  109. print "</tr>\n";
  110. print '<tr class="oddeven"><td>';
  111. print $langs->trans("NotificationEMailFrom").'</td>';
  112. print '<td>';
  113. print '<input size="32" type="email" name="email_from" value="'.$conf->global->NOTIFICATION_EMAIL_FROM.'">';
  114. if (! empty($conf->global->NOTIFICATION_EMAIL_FROM) && ! isValidEmail($conf->global->NOTIFICATION_EMAIL_FROM)) print ' '.img_warning($langs->trans("ErrorBadEMail"));
  115. print '</td>';
  116. print '</tr>';
  117. print '</table>';
  118. print '<br><br>';
  119. // Notification per contacts
  120. $title=$langs->trans("ListOfNotificationsPerUser");
  121. if (! empty($conf->societe->enabled)) $title=$langs->trans("ListOfNotificationsPerUserOrContact");
  122. print load_fiche_titre($title,'','');
  123. print '<table class="noborder" width="100%">';
  124. print '<tr class="liste_titre">';
  125. print '<td>'.$langs->trans("Label").'</td>';
  126. /*print '<td>'.$langs->trans("Code").'</td>';
  127. print '<td>'.$langs->trans("Label").'</td>';*/
  128. //print '<td align="right">'.$langs->trans("NbOfTargetedContacts").'</td>';
  129. print "</tr>\n";
  130. // Load array of available notifications
  131. $notificationtrigger=new InterfaceNotification($db);
  132. $listofnotifiedevents=$notificationtrigger->getListOfManagedEvents();
  133. print '<tr class="oddeven">';
  134. print '<td>';
  135. $var=true;
  136. $i=0;
  137. foreach($listofnotifiedevents as $notifiedevent)
  138. {
  139. $label=$langs->trans("Notify_".$notifiedevent['code']); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label'];
  140. if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder');
  141. elseif ($notifiedevent['elementtype'] == 'propal') $elementLabel = $langs->trans('Proposal');
  142. elseif ($notifiedevent['elementtype'] == 'facture') $elementLabel = $langs->trans('Bill');
  143. elseif ($notifiedevent['elementtype'] == 'commande') $elementLabel = $langs->trans('Order');
  144. elseif ($notifiedevent['elementtype'] == 'ficheinter') $elementLabel = $langs->trans('Intervention');
  145. if ($i) print ', ';
  146. print $label;
  147. $i++;
  148. }
  149. print '</td></tr>';
  150. print '</table>';
  151. print '* '.$langs->trans("GoOntoUserCardToAddMore").'<br>';
  152. if (! empty($conf->societe->enabled)) print '** '.$langs->trans("GoOntoContactCardToAddMore").'<br>';
  153. print '<br><br>';
  154. print load_fiche_titre($langs->trans("ListOfFixedNotifications"),'','');
  155. print '<table class="noborder" width="100%">';
  156. print '<tr class="liste_titre">';
  157. print '<td>'.$langs->trans("Module").'</td>';
  158. print '<td>'.$langs->trans("Code").'</td>';
  159. print '<td>'.$langs->trans("Label").'</td>';
  160. print '<td>'.$langs->trans("FixedEmailTarget").'</td>';
  161. print '<td>'.$langs->trans("Threshold").'</td>';
  162. print '<td>'.'</td>';
  163. print "</tr>\n";
  164. // Load array of available notifications
  165. $notificationtrigger=new InterfaceNotification($db);
  166. $listofnotifiedevents=$notificationtrigger->getListOfManagedEvents();
  167. $var=true;
  168. foreach($listofnotifiedevents as $notifiedevent)
  169. {
  170. $label=$langs->trans("Notify_".$notifiedevent['code']); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label'];
  171. if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder');
  172. elseif ($notifiedevent['elementtype'] == 'propal') $elementLabel = $langs->trans('Proposal');
  173. elseif ($notifiedevent['elementtype'] == 'facture') $elementLabel = $langs->trans('Bill');
  174. elseif ($notifiedevent['elementtype'] == 'commande') $elementLabel = $langs->trans('Order');
  175. elseif ($notifiedevent['elementtype'] == 'ficheinter') $elementLabel = $langs->trans('Intervention');
  176. print '<tr class="oddeven">';
  177. print '<td>'.$elementLabel.'</td>';
  178. print '<td>'.$notifiedevent['code'].'</td>';
  179. print '<td>'.$label.'</td>';
  180. print '<td>';
  181. // Notification with threshold
  182. foreach($conf->global as $key => $val)
  183. {
  184. if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifiedevent['code'].'_THRESHOLD_HIGHER_(.*)/', $key, $reg)) continue;
  185. $param='NOTIFICATION_FIXEDEMAIL_'.$notifiedevent['code'].'_THRESHOLD_HIGHER_'.$reg[1];
  186. $value=GETPOST('NOTIF_'.$notifiedevent['code'].'_old_'.$reg[1].'_key')?GETPOST('NOTIF_'.$notifiedevent['code'].'_old_'.$reg[1].'_key','alpha'):$conf->global->$param;
  187. $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.
  188. $arrayemail=explode(',',$value);
  189. $showwarning=0;
  190. foreach($arrayemail as $key=>$valuedet)
  191. {
  192. $valuedet=trim($valuedet);
  193. if (! empty($valuedet) && ! isValidEmail($valuedet,1)) $showwarning++;
  194. }
  195. if ((! empty($conf->global->$param)) && $showwarning) $s.=' '.img_warning($langs->trans("ErrorBadEMail"));
  196. print $form->textwithpicto($s,$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients").'<br>'.$langs->trans("YouCanAlsoUseSupervisorKeyword"),1,'help','',0,2);
  197. print '<br>';
  198. }
  199. // New entry input fields
  200. $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.
  201. print $form->textwithpicto($s,$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients").'<br>'.$langs->trans("YouCanAlsoUseSupervisorKeyword"),1,'help','',0,2);
  202. print '</td>';
  203. print '<td>';
  204. // Notification with threshold
  205. foreach($conf->global as $key => $val)
  206. {
  207. if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifiedevent['code'].'_THRESHOLD_HIGHER_(.*)/', $key, $reg)) continue;
  208. print $langs->trans("AmountHT").' >= <input type="text" size="4" name="NOTIF_'.$notifiedevent['code'].'_old_'.$reg[1].'_amount" value="'.dol_escape_htmltag($reg[1]).'">';
  209. print '<br>';
  210. }
  211. // New entry input fields
  212. print $langs->trans("AmountHT").' >= <input type="text" size="4" name="NOTIF_'.$notifiedevent['code'].'_new_amount" value="">';
  213. print '</td>';
  214. print '<td>';
  215. // TODO Add link to show message content
  216. print '</td>';
  217. print '</tr>';
  218. }
  219. print '</table>';
  220. print '<br>';
  221. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></div>';
  222. print '</form>';
  223. llxFooter();
  224. $db->close();