dolibarr  17.0.3
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) || !isModEnabled('notification')) {
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, $action;
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  $parameters = array();
104  $object = new stdClass();
105  $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action);
106  if (empty($reshook)) {
107  if (!empty($hookmanager->resArray['arrayofnotifsupported'])) {
108  $this->listofmanagedevents = array_merge($this->listofmanagedevents, $hookmanager->resArray['arrayofnotifsupported']);
109  }
110  }
111 
112  $ret = array();
113 
114 
115  $sql = "SELECT rowid, code, label, description, elementtype";
116  $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
117  $sql .= $this->db->order("rang, elementtype, code");
118 
119  dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG);
120  $resql = $this->db->query($sql);
121  if ($resql) {
122  $num = $this->db->num_rows($resql);
123  $i = 0;
124  while ($i < $num) {
125  $obj = $this->db->fetch_object($resql);
126 
127  $qualified = 0;
128  // Check is this event is supported by notification module
129  if (in_array($obj->code, $this->listofmanagedevents)) {
130  $qualified = 1;
131  }
132  // Check if module for this event is active
133  if ($qualified) {
134  //print 'xx'.$obj->code.' '.$obj->elementtype.'<br>';
135  $element = $obj->elementtype;
136 
137  // Exclude events if related module is disabled
138  if ($element == 'order_supplier' && ((!isModEnabled('fournisseur') && !empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !isModEnabled('supplier_order'))) {
139  $qualified = 0;
140  } elseif ($element == 'invoice_supplier' && ((!isModEnabled('fournisseur') && !empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !isModEnabled('supplier_invoice'))) {
141  $qualified = 0;
142  } elseif ($element == 'withdraw' && empty($conf->prelevement->enabled)) {
143  $qualified = 0;
144  } elseif ($element == 'shipping' && empty($conf->expedition->enabled)) {
145  $qualified = 0;
146  } elseif ($element == 'member' && empty($conf->adherent->enabled)) {
147  $qualified = 0;
148  } elseif (($element == 'expense_report' || $element == 'expensereport') && empty($conf->expensereport->enabled)) {
149  $qualified = 0;
150  } elseif (!in_array($element, array('order_supplier', 'invoice_supplier', 'withdraw', 'shipping', 'member', 'expense_report', 'expensereport')) && empty($conf->$element->enabled)) {
151  $qualified = 0;
152  }
153  }
154 
155  if ($qualified) {
156  $ret[] = array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$obj->label, 'description'=>$obj->description, 'elementtype'=>$obj->elementtype);
157  }
158 
159  $i++;
160  }
161  } else {
162  dol_print_error($this->db);
163  }
164 
165  return $ret;
166  }
167 }
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:4993
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
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("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->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1628
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:137
User
Class to manage Dolibarr users.
Definition: user.class.php:46
DolibarrTriggers
Class that all the triggers must extend.
Definition: dolibarrtriggers.class.php:21
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