dolibarr  16.0.5
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  * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
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 <https://www.gnu.org/licenses/>.
19  */
20 
26 require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
27 include_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
28 
29 
34 {
35  public $listofmanagedevents = array();
36 
42  public function __construct($db)
43  {
44  $this->db = $db;
45 
46  $this->name = preg_replace('/^Interface/i', '', get_class($this));
47  $this->family = "notification";
48  $this->description = "Triggers of this module send email notifications according to Notification module setup.";
49  // 'development', 'experimental', 'dolibarr' or version
50  $this->version = self::VERSION_DOLIBARR;
51  $this->picto = 'email';
52 
53  $this->listofmanagedevents = Notify::$arrayofnotifsupported;
54  }
55 
67  public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
68  {
69  if (empty($conf->notification) || empty($conf->notification->enabled)) {
70  return 0; // Module not active, we do nothing
71  }
72 
73  if (!in_array($action, $this->listofmanagedevents)) {
74  return 0;
75  }
76 
77  dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
78 
79  $notify = new Notify($this->db);
80  $notify->send($action, $object);
81 
82  return 1;
83  }
84 
85 
91  public function getListOfManagedEvents()
92  {
93  global $conf;
94  global $hookmanager;
95 
96 
97  if (!is_object($hookmanager)) {
98  include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
99  $hookmanager = new HookManager($this->db);
100  }
101  $hookmanager->initHooks(array('notification'));
102 
103  $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action);
104  if (empty($reshook)) {
105  if (!empty($hookmanager->resArray['arrayofnotifsupported'])) {
106  $this->listofmanagedevents = array_merge($this->listofmanagedevents, $hookmanager->resArray['arrayofnotifsupported']);
107  }
108  }
109 
110  $ret = array();
111 
112 
113  $sql = "SELECT rowid, code, label, description, elementtype";
114  $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
115  $sql .= $this->db->order("rang, elementtype, code");
116 
117  dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG);
118  $resql = $this->db->query($sql);
119  if ($resql) {
120  $num = $this->db->num_rows($resql);
121  $i = 0;
122  while ($i < $num) {
123  $obj = $this->db->fetch_object($resql);
124 
125  $qualified = 0;
126  // Check is this event is supported by notification module
127  if (in_array($obj->code, $this->listofmanagedevents)) {
128  $qualified = 1;
129  }
130  // Check if module for this event is active
131  if ($qualified) {
132  //print 'xx'.$obj->code.' '.$obj->elementtype.'<br>';
133  $element = $obj->elementtype;
134 
135  // Exclude events if related module is disabled
136  if ($element == 'order_supplier' && ((empty($conf->fournisseur->enabled) && !empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || empty($conf->supplier_order->enabled))) {
137  $qualified = 0;
138  } elseif ($element == 'invoice_supplier' && ((empty($conf->fournisseur->enabled) && !empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || empty($conf->supplier_invoice->enabled))) {
139  $qualified = 0;
140  } elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) {
141  $qualified = 0;
142  } elseif ($element == 'shipping' && empty($conf->expedition->enabled)) {
143  $qualified = 0;
144  } elseif ($element == 'member' && empty($conf->adherent->enabled)) {
145  $qualified = 0;
146  } elseif (($element == 'expense_report' || $element == 'expensereport') && empty($conf->expensereport->enabled)) {
147  $qualified = 0;
148  } elseif (!in_array($element, array('order_supplier', 'invoice_supplier', 'withdraw', 'shipping', 'member', 'expense_report', 'expensereport')) && empty($conf->$element->enabled)) {
149  $qualified = 0;
150  }
151  }
152 
153  if ($qualified) {
154  $ret[] = array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$obj->label, 'description'=>$obj->description, 'elementtype'=>$obj->elementtype);
155  }
156 
157  $i++;
158  }
159  } else {
160  dol_print_error($this->db);
161  }
162 
163  return $ret;
164  }
165 }
db
$conf db
API class for accounts.
Definition: inc.php:41
description
print *****$script_file(".$version.") pid cd cd cd description as description
Definition: email_expire_services_to_customers.php:83
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
InterfaceNotification\__construct
__construct($db)
Constructor.
Definition: interface_50_modNotification_Notification.class.php:42
Translate
Class to manage translations.
Definition: translate.class.php:30
name
$conf db name
Definition: repair.php:122
Notify
Class to manage notifications.
Definition: notify.class.php:33
Conf
Class to stock current configuration.
Definition: conf.class.php:33
InterfaceNotification
Class of triggers for notification module.
Definition: interface_50_modNotification_Notification.class.php:33
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1603
User
Class to manage Dolibarr users.
Definition: user.class.php:44
DolibarrTriggers
Class that all the triggers must extend.
Definition: dolibarrtriggers.class.php:21
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
InterfaceNotification\getListOfManagedEvents
getListOfManagedEvents()
Return list of events managed by notification module.
Definition: interface_50_modNotification_Notification.class.php:91
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30
InterfaceNotification\runTrigger
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarrr business event is done.
Definition: interface_50_modNotification_Notification.class.php:67