dolibarr  7.0.0-beta
interface_50_modNotification_Notification.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2011 Regis Houssin <regis.houssin@capnetworks.com>
4  * Copyright (C) 2013-2014 Marcos GarcĂ­a <marcosgdf@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
25 require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
26 
27 
32 {
33  public $family = 'notification';
34  public $description = "Triggers of this module send email notifications according to Notification module setup.";
35  public $version = self::VERSION_DOLIBARR;
36  public $picto = 'email';
37 
38  var $listofmanagedevents=array(
39  'BILL_VALIDATE',
40  'BILL_PAYED',
41  'ORDER_VALIDATE',
42  'PROPAL_VALIDATE',
43  'PROPAL_CLOSE_SIGNED',
44  'FICHINTER_VALIDATE',
45  'FICHINTER_ADD_CONTACT',
46  'ORDER_SUPPLIER_VALIDATE',
47  'ORDER_SUPPLIER_APPROVE',
48  'ORDER_SUPPLIER_REFUSE',
49  'SHIPPING_VALIDATE'
50  );
51 
63  public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
64  {
65  if (empty($conf->notification->enabled)) return 0; // Module not active, we do nothing
66 
67  require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
68  $notify = new Notify($this->db);
69 
70  if (! in_array($action, $notify->arrayofnotifsupported)) return 0;
71 
72  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
73 
74  $notify->send($action, $object);
75 
76  return 1;
77  }
78 
79 
86  {
87  global $conf;
88 
89  $ret=array();
90 
91  $sql = "SELECT rowid, code, label, description, elementtype";
92  $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
93  $sql.= $this->db->order("rang, elementtype, code");
94  dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG);
95  $resql=$this->db->query($sql);
96  if ($resql)
97  {
98  $num=$this->db->num_rows($resql);
99  $i=0;
100  while ($i < $num)
101  {
102  $obj=$this->db->fetch_object($resql);
103 
104  $qualified=0;
105  // Check is this event is supported by notification module
106  if (in_array($obj->code,$this->listofmanagedevents)) $qualified=1;
107  // Check if module for this event is active
108  if ($qualified)
109  {
110  //print 'xx'.$obj->code;
111  $element=$obj->elementtype;
112 
113  // Exclude events if related module is disabled
114  if ($element == 'order_supplier' && empty($conf->fournisseur->enabled)) $qualified=0;
115  elseif ($element == 'invoice_supplier' && empty($conf->fournisseur->enabled)) $qualified=0;
116  elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) $qualified=0;
117  elseif ($element == 'shipping' && empty($conf->expedition->enabled)) $qualified=0;
118  elseif ($element == 'member' && empty($conf->adherent->enabled)) $qualified=0;
119  elseif (! in_array($element,array('order_supplier','invoice_supplier','withdraw','shipping','member')) && empty($conf->$element->enabled)) $qualified=0;
120  }
121 
122  if ($qualified)
123  {
124  $ret[]=array('rowid'=>$obj->rowid,'code'=>$obj->code,'label'=>$obj->label,'description'=>$obj->description,'elementtype'=>$obj->elementtype);
125  }
126 
127  $i++;
128  }
129  }
130  else dol_print_error($this->db);
131 
132  return $ret;
133  }
134 
135 }
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
Class to stock current configuration.
Definition: conf.class.php:33
Class to manage notifications.
Class of triggers for notification module.
Class to manage Dolibarr users.
Definition: user.class.php:39
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage translations.
Class that all the triggers must extend.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:104
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->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)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
getListOfManagedEvents()
Return list of events managed by notification module.