dolibarr 21.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@inodbox.com>
4 * Copyright (C) 2013-2014 Marcos GarcĂ­a <marcosgdf@gmail.com>
5 * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.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
27require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php';
28include_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
29
30
35{
39 public $listofmanagedevents = array();
40
46 public function __construct($db)
47 {
48 $this->db = $db;
49
50 $this->name = preg_replace('/^Interface/i', '', get_class($this));
51 $this->family = "notification";
52 $this->description = "Triggers of this module send Email notifications according to Notification module setup.";
53 $this->version = self::VERSIONS['prod'];
54 $this->picto = 'email';
55
56 $this->listofmanagedevents = Notify::$arrayofnotifsupported;
57 }
58
70 public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
71 {
72 global $hookmanager;
73
74 if (empty($conf->notification) || !isModEnabled('notification')) {
75 return 0; // Module not active, we do nothing
76 }
77
78 if (!is_object($hookmanager)) {
79 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
80 $hookmanager = new HookManager($this->db);
81 }
82 $hookmanager->initHooks(array('notification'));
83
84 $parameters = array();
85 $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action);
86 if (empty($reshook)) {
87 if (!empty($hookmanager->resArray['arrayofnotifsupported'])) {
88 $this->listofmanagedevents = array_merge($this->listofmanagedevents, $hookmanager->resArray['arrayofnotifsupported']);
89 }
90 }
91
92 // If the trigger code is not managed by the Notification module
93 if (!in_array($action, $this->listofmanagedevents)) {
94 return 0;
95 }
96
97 dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id);
98
99 $notify = new Notify($this->db);
100 $notify->send($action, $object);
101
102 return 1;
103 }
104
110 public function getListOfManagedEvents()
111 {
112 global $conf, $action;
113 global $hookmanager;
114
115 if (!is_object($hookmanager)) {
116 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
117 $hookmanager = new HookManager($this->db);
118 }
119 $hookmanager->initHooks(array('notification'));
120
121 $parameters = array();
122 $object = new stdClass();
123 $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action);
124 if (empty($reshook)) {
125 if (!empty($hookmanager->resArray['arrayofnotifsupported'])) {
126 $this->listofmanagedevents = array_merge($this->listofmanagedevents, $hookmanager->resArray['arrayofnotifsupported']);
127 }
128 }
129
130 $ret = array();
131
132
133 $sql = "SELECT rowid, code, contexts, label, description, elementtype";
134 $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
135 $sql .= $this->db->order("rang, elementtype, code");
136
137 dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG);
138 $resql = $this->db->query($sql);
139 if ($resql) {
140 $num = $this->db->num_rows($resql);
141 $i = 0;
142 while ($i < $num) {
143 $obj = $this->db->fetch_object($resql);
144
145 $qualified = 0;
146 // Check is this event is supported by notification module
147 if (in_array($obj->code, $this->listofmanagedevents)) {
148 $qualified = 1;
149 }
150 // Check if module for this event is active
151 if ($qualified) {
152 //print 'xx'.$obj->code.' '.$obj->elementtype.'<br>';
153 $element = $obj->elementtype;
154
155 // Exclude events if related module is disabled
156 if ($element == 'order_supplier' && !isModEnabled('supplier_order')) {
157 $qualified = 0;
158 } elseif ($element == 'invoice_supplier' && !isModEnabled('supplier_invoice')) {
159 $qualified = 0;
160 } elseif ($element == 'withdraw' && !isModEnabled('prelevement')) {
161 $qualified = 0;
162 } elseif ($element == 'shipping' && !isModEnabled('shipping')) {
163 $qualified = 0;
164 } elseif ($element == 'member' && !isModEnabled('member')) {
165 $qualified = 0;
166 } elseif (($element == 'expense_report' || $element == 'expensereport') && !isModEnabled('expensereport')) {
167 $qualified = 0;
168 } elseif (!in_array($element, array('order_supplier', 'invoice_supplier', 'withdraw', 'shipping', 'member', 'expense_report', 'expensereport')) && empty($conf->$element->enabled)) {
169 $qualified = 0;
170 }
171 }
172
173 if ($qualified) {
174 $ret[] = array('rowid' => $obj->rowid, 'code' => $obj->code, 'contexts' => $obj->contexts, 'label' => $obj->label, 'description' => $obj->description, 'elementtype' => $obj->elementtype);
175 }
176
177 $i++;
178 }
179 } else {
180 dol_print_error($this->db);
181 }
182
183 return $ret;
184 }
185}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
Class to stock current configuration.
Class that all triggers must inherit.
Class to manage hooks.
Class of triggers for notification module.
getListOfManagedEvents()
Return list of events managed by notification module.
runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
Function called when a Dolibarr business event is done.
Class to manage the table of subscription to notifications.
Class to manage translations.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:152