dolibarr  9.0.0
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@inodbox.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 
40  public $version = self::VERSION_DOLIBARR;
41 
45  public $picto = 'email';
46 
47  // @TODO Defined also into notify.class.php)
48  public $listofmanagedevents=array(
49  'BILL_VALIDATE',
50  'BILL_PAYED',
51  'ORDER_VALIDATE',
52  'PROPAL_VALIDATE',
53  'PROPAL_CLOSE_SIGNED',
54  'FICHINTER_VALIDATE',
55  'FICHINTER_ADD_CONTACT',
56  'ORDER_SUPPLIER_VALIDATE',
57  'ORDER_SUPPLIER_APPROVE',
58  'ORDER_SUPPLIER_REFUSE',
59  'SHIPPING_VALIDATE',
60  'EXPENSE_REPORT_VALIDATE',
61  'EXPENSE_REPORT_APPROVE',
62  'HOLIDAY_VALIDATE',
63  'HOLIDAY_APPROVE'
64  );
65 
77  public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
78  {
79  if (empty($conf->notification->enabled)) return 0; // Module not active, we do nothing
80 
81  require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
82  $notify = new Notify($this->db);
83 
84  if (! in_array($action, $notify->arrayofnotifsupported)) return 0;
85 
86  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
87 
88  $notify->send($action, $object);
89 
90  return 1;
91  }
92 
93 
100  {
101  global $conf;
102 
103  $ret=array();
104 
105  $sql = "SELECT rowid, code, label, description, elementtype";
106  $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
107  $sql.= $this->db->order("rang, elementtype, code");
108  dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG);
109  $resql=$this->db->query($sql);
110  if ($resql)
111  {
112  $num=$this->db->num_rows($resql);
113  $i=0;
114  while ($i < $num)
115  {
116  $obj=$this->db->fetch_object($resql);
117 
118  $qualified=0;
119  // Check is this event is supported by notification module
120  if (in_array($obj->code, $this->listofmanagedevents)) $qualified=1;
121  // Check if module for this event is active
122  if ($qualified)
123  {
124  //print 'xx'.$obj->code;
125  $element=$obj->elementtype;
126 
127  // Exclude events if related module is disabled
128  if ($element == 'order_supplier' && empty($conf->fournisseur->enabled)) $qualified=0;
129  elseif ($element == 'invoice_supplier' && empty($conf->fournisseur->enabled)) $qualified=0;
130  elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) $qualified=0;
131  elseif ($element == 'shipping' && empty($conf->expedition->enabled)) $qualified=0;
132  elseif ($element == 'member' && empty($conf->adherent->enabled)) $qualified=0;
133  elseif (! in_array($element,array('order_supplier','invoice_supplier','withdraw','shipping','member','expensereport')) && empty($conf->$element->enabled)) $qualified=0;
134  }
135 
136  if ($qualified)
137  {
138  $ret[]=array('rowid'=>$obj->rowid,'code'=>$obj->code,'label'=>$obj->label,'description'=>$obj->description,'elementtype'=>$obj->elementtype);
139  }
140 
141  $i++;
142  }
143  }
144  else dol_print_error($this->db);
145 
146  return $ret;
147  }
148 }
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.
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:1053
Class of triggers for notification module.
Class to manage Dolibarr users.
Definition: user.class.php:41
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition: repair.php:103
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.
getListOfManagedEvents()
Return list of events managed by notification module.