dolibarr  13.0.2
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2010-2014 Juanjo Menent <jmenent@2byte.es>
5  * Copyright (C) 2015 Marcos GarcĂ­a <marcosgdf@gmail.com>
6  * Copyright (C) 2016 Abbes Bahfir <contact@dolibarrpar.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
28 require '../../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
31 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/triggers/interface_50_modNotification_Notification.class.php';
33 
34 // Load translation files required by page
35 $langs->loadLangs(array('companies', 'mails', 'admin', 'other'));
36 
37 $id = GETPOST("id", 'int');
38 $action = GETPOST('action', 'aZ09');
39 $actionid = GETPOST('actionid');
40 
41 // Security check
42 if ($user->socid) $id = $user->socid;
43 $result = restrictedArea($user, 'societe', '', '');
44 
45 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
46 $sortfield = GETPOST("sortfield", 'alpha');
47 $sortorder = GETPOST("sortorder", 'alpha');
48 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
49 if (!$sortorder) $sortorder = "DESC";
50 if (!$sortfield) $sortfield = "n.daten";
51 if (empty($page) || $page == -1) { $page = 0; }
52 $offset = $limit * $page;
53 $pageprev = $page - 1;
54 $pagenext = $page + 1;
55 
56 $now = dol_now();
57 
58 
59 /*
60  * Actions
61  */
62 
63 // Add a notification
64 if ($action == 'add')
65 {
66  $error = 0;
67 
68  if ($actionid <= 0)
69  {
70  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Action")), null, 'errors');
71  $error++;
72  }
73 
74  if (!$error)
75  {
76  $db->begin();
77 
78  $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def";
79  $sql .= " WHERE fk_user=".$id." AND fk_action=".$actionid;
80  if ($db->query($sql))
81  {
82  $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_user, fk_action)";
83  $sql .= " VALUES ('".$db->idate($now)."',".$id.",".$actionid.")";
84 
85  if (!$db->query($sql))
86  {
87  $error++;
88  dol_print_error($db);
89  }
90  } else {
91  dol_print_error($db);
92  }
93 
94  if (!$error)
95  {
96  $db->commit();
97  } else {
98  $db->rollback();
99  }
100  }
101 }
102 
103 // Remove a notification
104 if ($action == 'delete')
105 {
106  $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def where rowid=".GETPOST("actid", "int");
107  $db->query($sql);
108 }
109 
110 
111 
112 /*
113  * View
114  */
115 
116 $form = new Form($db);
117 
118 $object = new User($db);
119 $result = $object->fetch($id, '', '', 1);
120 $object->getrights();
121 
122 $title = $langs->trans("ThirdParty").' - '.$langs->trans("Notification");
123 if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name.' - '.$langs->trans("Notification");
124 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
125 llxHeader('', $title, $help_url);
126 
127 
128 if ($result > 0)
129 {
130  $langs->load("other");
131 
132  $head = user_prepare_head($object);
133 
134  print dol_get_fiche_head($head, 'notify', $langs->trans("User"), -1, 'user');
135 
136  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
137 
138  dol_banner_tab($object, 'id', $linkback, $user->rights->user->user->lire || $user->admin, 'rowid', 'ref', '', '', 0, '', '', 0, '');
139 
140  print '<div class="fichecenter">';
141 
142  print '<div class="underbanner clearboth"></div>';
143  print '<table class="border centpercent tableforfield">';
144 
145  // Login
146  print '<tr><td class="titlefield">'.$langs->trans("Login").'</td>';
147  if (!empty($object->ldap_sid) && $object->statut == 0)
148  {
149  print '<td class="error">'.$langs->trans("LoginAccountDisableInDolibarr").'</td>';
150  } else {
151  print '<td>'.$object->login.'</td>';
152  }
153  print '</tr>'."\n";
154 
155  /*print '<tr><td class="titlefield">'.$langs->trans("NbOfActiveNotifications").'</td>'; // Notification for this thirdparty
156  print '<td colspan="3">';
157  $nbofrecipientemails=0;
158  $notify=new Notify($db);
159  $tmparray = $notify->getNotificationsArray('', 0, null, $object->id, array('user'));
160  foreach($tmparray as $tmpkey => $tmpval)
161  {
162  $nbofrecipientemails++;
163  }
164  print $nbofrecipientemails;
165  print '</td></tr>';*/
166 
167  print '</table>';
168 
169  print '</div>';
170 
172 
173  print "\n";
174 
175  // Help
176  print '<span class="opacitymedium">';
177  print '<br>'.$langs->trans("NotificationsDesc");
178  print '<br>'.$langs->trans("NotificationsDescUser");
179  print '<br>'.$langs->trans("NotificationsDescContact");
180  print '<br>'.$langs->trans("NotificationsDescGlobal");
181  print '</span>';
182 
183  print '<br><br><br>'."\n";
184 
185 
186  // Add notification form
187  print load_fiche_titre($langs->trans("AddNewNotification"), '', '');
188 
189  print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$id.'" method="post">';
190  print '<input type="hidden" name="token" value="'.newToken().'">';
191  print '<input type="hidden" name="action" value="add">';
192 
193  $param = "&id=".$id;
194 
195  // Line with titles
196  print '<table width="100%" class="noborder">';
197  print '<tr class="liste_titre">';
198  print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '"width="45%"', $sortfield, $sortorder);
199  print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '"width="35%"', $sortfield, $sortorder);
200  print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '"width="10%"', $sortfield, $sortorder);
202  print "</tr>\n";
203 
204 
205  // $listofemails=$object->thirdparty_and_contact_email_array();
206  if ($object->email)
207  {
208  $actions = array();
209 
210  // Load array of available notifications
211  $notificationtrigger = new InterfaceNotification($db);
212  $listofnotifiedevents = $notificationtrigger->getListOfManagedEvents();
213 
214  foreach ($listofnotifiedevents as $notifiedevent)
215  {
216  $label = ($langs->trans("Notify_".$notifiedevent['code']) != "Notify_".$notifiedevent['code'] ? $langs->trans("Notify_".$notifiedevent['code']) : $notifiedevent['label']);
217  $actions[$notifiedevent['rowid']] = $label;
218  }
219  print '<tr class="oddeven nohover"><td>';
220  print $object->getNomUrl(1);
221  if (isValidEmail($object->email))
222  {
223  print ' &lt;'.$object->email.'&gt;';
224  } else {
225  $langs->load("errors");
226  print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail", $object->email);
227  }
228  print '</td>';
229  print '<td>';
230  print img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').$form->selectarray("actionid", $actions, '', 1);
231  print '</td>';
232  print '<td>';
233  $type = array('email'=>$langs->trans("EMail"));
234  print $form->selectarray("typeid", $type);
235  print '</td>';
236  print '<td class="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
237  print '</tr>';
238  } else {
239  print '<tr class="oddeven"><td colspan="4">';
240  print $langs->trans("YouMustAssignUserMailFirst");
241  print '</td></tr>';
242  }
243 
244  print '</table>';
245 
246  print '</form>';
247  print '<br>';
248 
249  // List of notifications enabled for contacts
250  $sql = "SELECT n.rowid, n.type,";
251  $sql .= " a.code, a.label,";
252  $sql .= " c.rowid as userid, c.lastname, c.firstname, c.email";
253  $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
254  $sql .= " ".MAIN_DB_PREFIX."notify_def as n,";
255  $sql .= " ".MAIN_DB_PREFIX."user c";
256  $sql .= " WHERE a.rowid = n.fk_action";
257  $sql .= " AND c.rowid = n.fk_user";
258  $sql .= " AND c.rowid = ".$object->id;
259 
260  $resql = $db->query($sql);
261  if ($resql)
262  {
263  $num = $db->num_rows($resql);
264  } else {
265  dol_print_error($db);
266  }
267 
268  // List of active notifications
269  print load_fiche_titre($langs->trans("ListOfActiveNotifications").' ('.$num.')', '', '');
270 
271  // Line with titles
272  print '<table width="100%" class="noborder">';
273  print '<tr class="liste_titre">';
274  print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '"width="45%"', $sortfield, $sortorder);
275  print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '"width="35%"', $sortfield, $sortorder);
276  print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '"width="10%"', $sortfield, $sortorder);
277  print_liste_field_titre('', '', '');
278  print '</tr>';
279 
280  $langs->load("errors");
281  $langs->load("other");
282 
283  if ($num)
284  {
285  $i = 0;
286 
287  $userstatic = new user($db);
288 
289  while ($i < $num)
290  {
291  $obj = $db->fetch_object($resql);
292 
293  $userstatic->id = $obj->userid;
294  $userstatic->lastname = $obj->lastname;
295  $userstatic->firstname = $obj->firstname;
296  print '<tr class="oddeven"><td>'.$userstatic->getNomUrl(1);
297  if ($obj->type == 'email')
298  {
299  if (isValidEmail($obj->email))
300  {
301  print ' &lt;'.$obj->email.'&gt;';
302  } else {
303  $langs->load("errors");
304  print ' &nbsp; '.img_warning().' '.$langs->trans("ErrorBadEMail", $obj->email);
305  }
306  }
307  print '</td>';
308  print '<td>';
309  $label = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label);
310  print img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').$label;
311  print '</td>';
312  print '<td>';
313  if ($obj->type == 'email') print $langs->trans("Email");
314  if ($obj->type == 'sms') print $langs->trans("SMS");
315  print '</td>';
316  print '<td class="right"><a href="card.php?id='.$id.'&amp;action=delete&amp;token='.newToken().'&amp;actid='.$obj->rowid.'">'.img_delete().'</a></td>';
317  print '</tr>';
318  $i++;
319  }
320  $db->free($resql);
321  }
322 
323  // List of notifications enabled for fixed email
324  /*
325  foreach($conf->global as $key => $val)
326  {
327  if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue;
328  $var = ! $var;
329  print '<tr class="oddeven"><td>';
330  $listtmp=explode(',',$val);
331  $first=1;
332  foreach($listtmp as $keyemail => $valemail)
333  {
334  if (! $first) print ', ';
335  $first=0;
336  $valemail=trim($valemail);
337  //print $keyemail.' - '.$valemail.' - '.$reg[1].'<br>';
338  if (isValidEmail($valemail, 1))
339  {
340  if ($valemail == '__SUPERVISOREMAIL__') print $valemail;
341  else print ' &lt;'.$valemail.'&gt;';
342  }
343  else
344  {
345  print ' '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail);
346  }
347  }
348  print '</td>';
349  print '<td>';
350  $notifcode=preg_replace('/_THRESHOLD_.*$/','',$reg[1]);
351  $notifcodecond=preg_replace('/^.*_(THRESHOLD_)/','$1',$reg[1]);
352  $label=($langs->trans("Notify_".$notifcode)!="Notify_".$notifcode?$langs->trans("Notify_".$notifcode):$notifcode);
353  print $label;
354  if (preg_match('/^THRESHOLD_HIGHER_(.*)$/',$notifcodecond,$regcond) && ($regcond[1] > 0))
355  {
356  print ' - '.$langs->trans("IfAmountHigherThan",$regcond[1]);
357  }
358  print '</td>';
359  print '<td>';
360  print $langs->trans("Email");
361  print '</td>';
362  print '<td class="right">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</td>';
363  print '</tr>';
364  }*/
365  /*if ($user->admin)
366  {
367  $var = ! $var;
368  print '<tr class="oddeven"><td colspan="4">';
369  print '+ <a href="'.DOL_URL_ROOT.'/admin/notification.php">'.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'</a>';
370  print '</td></tr>';
371  }*/
372 
373  print '</table>';
374 
375 
376  print '<br><br>'."\n";
377 
378 
379  // List
380  $sql = "SELECT n.rowid, n.daten, n.email, n.objet_type as object_type, n.objet_id as object_id, n.type,";
381  $sql .= " c.rowid as id, c.lastname, c.firstname, c.email as contactemail,";
382  $sql .= " a.code, a.label";
383  $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,";
384  $sql .= " ".MAIN_DB_PREFIX."notify as n";
385  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as c ON n.fk_user = c.rowid";
386  $sql .= " WHERE a.rowid = n.fk_action";
387  $sql .= " AND n.fk_user = ".$object->id;
388  $sql .= $db->order($sortfield, $sortorder);
389 
390  // Count total nb of records
391  $nbtotalofrecords = '';
392  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
393  {
394  $result = $db->query($sql);
395  $nbtotalofrecords = $db->num_rows($result);
396  if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0
397  {
398  $page = 0;
399  $offset = 0;
400  }
401  }
402 
403  $sql .= $db->plimit($limit + 1, $offset);
404 
405  $resql = $db->query($sql);
406  if ($resql)
407  {
408  $num = $db->num_rows($resql);
409  } else {
410  dol_print_error($db);
411  }
412 
413  $param = '&id='.$object->id;
414  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage;
415  if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit;
416 
417  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
418  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
419  print '<input type="hidden" name="token" value="'.newToken().'">';
420  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
421  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
422  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
423  print '<input type="hidden" name="page" value="'.$page.'">';
424  print '<input type="hidden" name="id" value="'.$object->id.'">';
425 
426  // List of notifications done
427  print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);
428 
429  // Line with titles
430  print '<table width="100%" class="noborder">';
431  print '<tr class="liste_titre">';
432  print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '', $sortfield, $sortorder);
433  print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder);
434  print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '', $sortfield, $sortorder);
435  //print_liste_field_titre("Object",$_SERVER["PHP_SELF"],"",'',$param,'"',$sortfield,$sortorder);
436  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "n.daten", '', $param, '', $sortfield, $sortorder, 'right ');
437  print '</tr>';
438 
439  if ($num)
440  {
441  $i = 0;
442 
443  $userstatic = new User($db);
444 
445  while ($i < $num)
446  {
447  $obj = $db->fetch_object($resql);
448 
449  print '<tr class="oddeven"><td>';
450  if ($obj->id > 0)
451  {
452  $userstatic->id = $obj->id;
453  $userstatic->lastname = $obj->lastname;
454  $userstatic->firstname = $obj->firstname;
455  print $userstatic->getNomUrl(1);
456  print $obj->email ? ' &lt;'.$obj->email.'&gt;' : $langs->trans("NoMail");
457  } else {
458  print $obj->email;
459  }
460  print '</td>';
461  print '<td>';
462  $label = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label);
463  print $label;
464  print '</td>';
465  print '<td>';
466  if ($obj->type == 'email') print $langs->trans("Email");
467  if ($obj->type == 'sms') print $langs->trans("Sms");
468  print '</td>';
469  // TODO Add link to object here for other types
470  /*print '<td>';
471  if ($obj->object_type == 'order')
472  {
473  $orderstatic->id=$obj->object_id;
474  $orderstatic->ref=...
475  print $orderstatic->getNomUrl(1);
476  }
477  print '</td>';*/
478  // print
479  print'<td class="right">'.dol_print_date($db->jdate($obj->daten), 'dayhour').'</td>';
480  print '</tr>';
481  $i++;
482  }
483  $db->free($resql);
484  } else {
485  print '<tr><td colspan="4"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
486  }
487 
488  print '</table>';
489 
490  print '</form>';
491 } else dol_print_error('', 'RecordNotFound');
492 
493 // End of page
494 llxFooter();
495 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
user_prepare_head($object)
Prepare array with list of tabs.
Class of triggers for notification module.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
Definition: user.class.php:44
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
$conf db user
Definition: repair.php:109
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
isValidEmail($address, $acceptsupervisorkey=0)
Return true if email syntax is ok.