dolibarr 21.0.0-alpha
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{
36 public $listofmanagedevents = array();
37
43 public function __construct($db)
44 {
45 $this->db = $db;
46
47 $this->name = preg_replace('/^Interface/i', '', get_class($this));
48 $this->family = "notification";
49 $this->description = "Triggers of this module send Email notifications according to Notification module setup.";
50 $this->version = self::VERSIONS['prod'];
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 global $hookmanager;
70
71 if (empty($conf->notification) || !isModEnabled('notification')) {
72 return 0; // Module not active, we do nothing
73 }
74
75 if (!is_object($hookmanager)) {
76 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
77 $hookmanager = new HookManager($this->db);
78 }
79 $hookmanager->initHooks(array('notification'));
80
81 $parameters = array();
82 $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action);
83 if (empty($reshook)) {
84 if (!empty($hookmanager->resArray['arrayofnotifsupported'])) {
85 $this->listofmanagedevents = array_merge($this->listofmanagedevents, $hookmanager->resArray['arrayofnotifsupported']);
86 }
87 }
88
89 // If the trigger code is not managed by the Notification module
90 if (!in_array($action, $this->listofmanagedevents)) {
91 return 0;
92 }
93
94 dol_syslog("Trigger '".$this->name."' for action '".$action."' launched by ".__FILE__.". id=".$object->id);
95
96 $notify = new Notify($this->db);
97 $notify->send($action, $object);
98
99 return 1;
100 }
101
107 public function getListOfManagedEvents()
108 {
109 global $conf, $action;
110 global $hookmanager;
111
112 if (!is_object($hookmanager)) {
113 include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
114 $hookmanager = new HookManager($this->db);
115 }
116 $hookmanager->initHooks(array('notification'));
117
118 $parameters = array();
119 $object = new stdClass();
120 $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action);
121 if (empty($reshook)) {
122 if (!empty($hookmanager->resArray['arrayofnotifsupported'])) {
123 $this->listofmanagedevents = array_merge($this->listofmanagedevents, $hookmanager->resArray['arrayofnotifsupported']);
124 }
125 }
126
127 $ret = array();
128
129
130 $sql = "SELECT rowid, code, contexts, label, description, elementtype";
131 $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger";
132 $sql .= $this->db->order("rang, elementtype, code");
133
134 dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG);
135 $resql = $this->db->query($sql);
136 if ($resql) {
137 $num = $this->db->num_rows($resql);
138 $i = 0;
139 while ($i < $num) {
140 $obj = $this->db->fetch_object($resql);
141
142 $qualified = 0;
143 // Check is this event is supported by notification module
144 if (in_array($obj->code, $this->listofmanagedevents)) {
145 $qualified = 1;
146 }
147 // Check if module for this event is active
148 if ($qualified) {
149 //print 'xx'.$obj->code.' '.$obj->elementtype.'<br>';
150 $element = $obj->elementtype;
151
152 // Exclude events if related module is disabled
153 if ($element == 'order_supplier' && !isModEnabled('supplier_order')) {
154 $qualified = 0;
155 } elseif ($element == 'invoice_supplier' && !isModEnabled('supplier_invoice')) {
156 $qualified = 0;
157 } elseif ($element == 'withdraw' && !isModEnabled('prelevement')) {
158 $qualified = 0;
159 } elseif ($element == 'shipping' && !isModEnabled('shipping')) {
160 $qualified = 0;
161 } elseif ($element == 'member' && !isModEnabled('member')) {
162 $qualified = 0;
163 } elseif (($element == 'expense_report' || $element == 'expensereport') && !isModEnabled('expensereport')) {
164 $qualified = 0;
165 } elseif (!in_array($element, array('order_supplier', 'invoice_supplier', 'withdraw', 'shipping', 'member', 'expense_report', 'expensereport')) && empty($conf->$element->enabled)) {
166 $qualified = 0;
167 }
168 }
169
170 if ($qualified) {
171 $ret[] = array('rowid' => $obj->rowid, 'code' => $obj->code, 'contexts' => $obj->contexts, 'label' => $obj->label, 'description' => $obj->description, 'elementtype' => $obj->elementtype);
172 }
173
174 $i++;
175 }
176 } else {
177 dol_print_error($this->db);
178 }
179
180 return $ret;
181 }
182}
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
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.
$conf db name
Only used if Module[ID]Name translation string is not found.
Definition repair.php:142