dolibarr  9.0.0
notification.php
Go to the documentation of this file.
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 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/triggers/interface_50_modNotification_Notification.class.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array('admin', 'other', 'orders', 'propal', 'bills', 'errors', 'mails'));
34 
35 // Security check
36 if (!$user->admin)
38 
39 $action = GETPOST('action','aZ09');
40 
41 
42 /*
43  * Actions
44  */
45 
46 if ($action == 'setvalue' && $user->admin)
47 {
48  $db->begin();
49 
50  $result=dolibarr_set_const($db, "NOTIFICATION_EMAIL_FROM", $_POST["email_from"], 'chaine', 0, '', $conf->entity);
51  if ($result < 0) $error++;
52 
53  if (! $error && is_array($_POST))
54  {
55  //var_dump($_POST);
56  foreach($_POST as $key => $val)
57  {
58  if (! preg_match('/^NOTIF_(.*)_key$/', $key, $reg)) continue;
59 
60  $newval='';
61  $newkey='';
62 
63  $shortkey=preg_replace('/_key$/','',$key);
64  //print $shortkey.'<br>';
65 
66  if (preg_match('/^NOTIF_(.*)_old_(.*)_key/',$key,$reg))
67  {
68  dolibarr_del_const($db, 'NOTIFICATION_FIXEDEMAIL_'.$reg[1].'_THRESHOLD_HIGHER_'.$reg[2], $conf->entity);
69 
70  $newkey='NOTIFICATION_FIXEDEMAIL_'.$reg[1].'_THRESHOLD_HIGHER_'.((int) GETPOST($shortkey.'_amount'));
71  $newval=GETPOST($shortkey.'_key');
72  //print $newkey.' - '.$newval.'<br>';
73  }
74  else if (preg_match('/^NOTIF_(.*)_new_key/',$key,$reg))
75  {
76  // Add a new entry
77  $newkey='NOTIFICATION_FIXEDEMAIL_'.$reg[1].'_THRESHOLD_HIGHER_'.((int) GETPOST($shortkey.'_amount'));
78  $newval=GETPOST($shortkey.'_key');
79  }
80 
81  if ($newkey && $newval)
82  {
83  $result=dolibarr_set_const($db, $newkey, $newval, 'chaine', 0, '', $conf->entity);
84  }
85  }
86  }
87 
88  if (! $error)
89  {
90  $db->commit();
91 
92  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
93  }
94  else
95  {
96  $db->rollback();
97 
98  setEventMessages($langs->trans("Error"), null, 'errors');
99  }
100 }
101 
102 
103 
104 /*
105  * View
106  */
107 
108 $form=new Form($db);
109 $notify = new Notify($db);
110 
111 llxHeader('',$langs->trans("NotificationSetup"));
112 
113 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
114 print load_fiche_titre($langs->trans("NotificationSetup"),$linkback,'title_setup');
115 
116 print $langs->trans("NotificationsDesc").'<br>';
117 print $langs->trans("NotificationsDescUser").'<br>';
118 if (! empty($conf->societe->enabled)) print $langs->trans("NotificationsDescContact").'<br>';
119 print $langs->trans("NotificationsDescGlobal").'<br>';
120 print '<br>';
121 
122 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
123 print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
124 print '<input type="hidden" name="action" value="setvalue">';
125 
126 print '<table class="noborder" width="100%">';
127 print '<tr class="liste_titre">';
128 print '<td>'.$langs->trans("Parameter").'</td>';
129 print '<td>'.$langs->trans("Value").'</td>';
130 print "</tr>\n";
131 
132 print '<tr class="oddeven"><td>';
133 print $langs->trans("NotificationEMailFrom").'</td>';
134 print '<td>';
135 print '<input size="32" type="email" name="email_from" value="'.$conf->global->NOTIFICATION_EMAIL_FROM.'">';
136 if (! empty($conf->global->NOTIFICATION_EMAIL_FROM) && ! isValidEmail($conf->global->NOTIFICATION_EMAIL_FROM)) print ' '.img_warning($langs->trans("ErrorBadEMail"));
137 print '</td>';
138 print '</tr>';
139 print '</table>';
140 
141 print '<br><br>';
142 
143 
144 // Notification per contacts
145 $title=$langs->trans("ListOfNotificationsPerUser");
146 if (! empty($conf->societe->enabled)) $title=$langs->trans("ListOfNotificationsPerUserOrContact");
147 print load_fiche_titre($title,'','');
148 
149 print '<table class="noborder" width="100%">';
150 print '<tr class="liste_titre">';
151 print '<td>'.$langs->trans("Label").'</td>';
152 /*print '<td>'.$langs->trans("Code").'</td>';
153  print '<td>'.$langs->trans("Label").'</td>';*/
154 //print '<td align="right">'.$langs->trans("NbOfTargetedContacts").'</td>';
155 print "</tr>\n";
156 
157 // Load array of available notifications
158 $notificationtrigger=new InterfaceNotification($db);
159 $listofnotifiedevents=$notificationtrigger->getListOfManagedEvents();
160 
161 print '<tr class="oddeven">';
162 print '<td>';
163 
164 $i=0;
165 foreach($listofnotifiedevents as $notifiedevent)
166 {
167 
168  $label=$langs->trans("Notify_".$notifiedevent['code']);
169  $elementLabel = $langs->trans(ucfirst($notifiedevent['elementtype']));
170 
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  elseif ($notifiedevent['elementtype'] == 'shipping') $elementLabel = $langs->trans('Shipping');
177  elseif ($notifiedevent['elementtype'] == 'expensereport') $elementLabel = $langs->trans('ExpenseReport');
178 
179  if ($i) print ', ';
180  print $label;
181 
182  $i++;
183 }
184 print '</td></tr>';
185 
186 print '</table>';
187 print '<div class="opacitymedium">';
188 print '* '.$langs->trans("GoOntoUserCardToAddMore").'<br>';
189 if (! empty($conf->societe->enabled)) print '** '.$langs->trans("GoOntoContactCardToAddMore").'<br>';
190 print '</div>';
191 print '<br><br>';
192 
193 
194 print load_fiche_titre($langs->trans("ListOfFixedNotifications"),'','');
195 
196 print '<table class="noborder" width="100%">';
197 print '<tr class="liste_titre">';
198 print '<td>'.$langs->trans("Module").'</td>';
199 print '<td>'.$langs->trans("Code").'</td>';
200 print '<td>'.$langs->trans("Label").'</td>';
201 print '<td>'.$langs->trans("FixedEmailTarget").'</td>';
202 print '<td>'.$langs->trans("Threshold").'</td>';
203 print '<td>'.'</td>';
204 print "</tr>\n";
205 
206 // Load array of available notifications
207 $notificationtrigger=new InterfaceNotification($db);
208 $listofnotifiedevents=$notificationtrigger->getListOfManagedEvents();
209 
210 foreach($listofnotifiedevents as $notifiedevent)
211 {
212 
213  $label=$langs->trans("Notify_".$notifiedevent['code']);
214 
215  $elementLabel = $langs->trans(ucfirst($notifiedevent['elementtype']));
216  // Special cases
217  if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder');
218  elseif ($notifiedevent['elementtype'] == 'propal') $elementLabel = $langs->trans('Proposal');
219  elseif ($notifiedevent['elementtype'] == 'facture') $elementLabel = $langs->trans('Bill');
220  elseif ($notifiedevent['elementtype'] == 'commande') $elementLabel = $langs->trans('Order');
221  elseif ($notifiedevent['elementtype'] == 'ficheinter') $elementLabel = $langs->trans('Intervention');
222  elseif ($notifiedevent['elementtype'] == 'shipping') $elementLabel = $langs->trans('Shipping');
223  elseif ($notifiedevent['elementtype'] == 'expensereport') $elementLabel = $langs->trans('ExpenseReport');
224 
225  print '<tr class="oddeven">';
226  print '<td>'.$elementLabel.'</td>';
227  print '<td>'.$notifiedevent['code'].'</td>';
228  print '<td>'.$label.'</td>';
229  print '<td>';
230  // Notification with threshold
231  foreach($conf->global as $key => $val)
232  {
233  if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifiedevent['code'].'_THRESHOLD_HIGHER_(.*)/', $key, $reg)) continue;
234 
235  $param='NOTIFICATION_FIXEDEMAIL_'.$notifiedevent['code'].'_THRESHOLD_HIGHER_'.$reg[1];
236  $value=GETPOST('NOTIF_'.$notifiedevent['code'].'_old_'.$reg[1].'_key')?GETPOST('NOTIF_'.$notifiedevent['code'].'_old_'.$reg[1].'_key','alpha'):$conf->global->$param;
237 
238  $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.
239  $arrayemail=explode(',',$value);
240  $showwarning=0;
241  foreach($arrayemail as $key=>$valuedet)
242  {
243  $valuedet=trim($valuedet);
244  if (! empty($valuedet) && ! isValidEmail($valuedet,1)) $showwarning++;
245  }
246  if ((! empty($conf->global->$param)) && $showwarning) $s.=' '.img_warning($langs->trans("ErrorBadEMail"));
247  print $form->textwithpicto($s,$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients").'<br>'.$langs->trans("YouCanAlsoUseSupervisorKeyword"),1,'help','',0,2);
248  print '<br>';
249  }
250  // New entry input fields
251  $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.
252  print $form->textwithpicto($s,$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients").'<br>'.$langs->trans("YouCanAlsoUseSupervisorKeyword"),1,'help','',0,2);
253  print '</td>';
254 
255  print '<td>';
256  // Notification with threshold
257  foreach($conf->global as $key => $val)
258  {
259  if ($val == '' || ! preg_match('/^NOTIFICATION_FIXEDEMAIL_'.$notifiedevent['code'].'_THRESHOLD_HIGHER_(.*)/', $key, $reg)) continue;
260 
261  print $langs->trans("AmountHT").' >= <input type="text" size="4" name="NOTIF_'.$notifiedevent['code'].'_old_'.$reg[1].'_amount" value="'.dol_escape_htmltag($reg[1]).'">';
262  print '<br>';
263  }
264  // New entry input fields
265  print $langs->trans("AmountHT").' >= <input type="text" size="4" name="NOTIF_'.$notifiedevent['code'].'_new_amount" value="">';
266  print '</td>';
267 
268  print '<td>';
269  // TODO Add link to show message content
270 
271  print '</td>';
272  print '</tr>';
273 }
274 print '</table>';
275 
276 print '<br>';
277 
278 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("Save").'"></div>';
279 
280 print '</form>';
281 
282 // End of page
283 llxFooter();
284 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage notifications.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
Class of triggers for notification module.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Definition: admin.lib.php:510
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dolibarr_del_const($db, $name, $entity=1)
Effacement d&#39;une constante dans la base de donnees.
Definition: admin.lib.php:435
llxHeader()
Empty header.
Definition: wrapper.php:44
if(GETPOST('cancel', 'alpha')) if(! GETPOST( 'confirmmassaction', 'alpha') &&$massaction !='presend' &&$massaction !='confirm_presend')
Draft customers invoices.
Definition: list.php:156
Class to manage Trips and Expenses.
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.