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