dolibarr 18.0.6
cactioncomm.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
30{
34 public $error = '';
35
39 public $db;
40
44 public $id;
45
49 public $code;
50
54 public $type;
55
61 public $libelle;
62
66 public $label;
67
71 public $active;
72
76 public $color;
77
81 public $picto;
82
86 public $type_actions = array();
87
88
92 public $liste_array;
93
94
100 public function __construct($db)
101 {
102 $this->db = $db;
103 }
104
111 public function fetch($id)
112 {
113 $sql = "SELECT id, code, type, libelle as label, color, active, picto";
114 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
115 if (is_numeric($id)) {
116 $sql .= " WHERE id=".(int) $id;
117 } else {
118 $sql .= " WHERE code='".$this->db->escape($id)."'";
119 }
120
121 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
122 $resql = $this->db->query($sql);
123 if ($resql) {
124 if ($this->db->num_rows($resql)) {
125 $obj = $this->db->fetch_object($resql);
126
127 $this->id = $obj->id;
128 $this->code = $obj->code;
129 $this->type = $obj->type;
130 $this->libelle = $obj->label; // deprecated
131 $this->label = $obj->label;
132 $this->active = $obj->active;
133 $this->color = $obj->color;
134
135 $this->db->free($resql);
136 return 1;
137 } else {
138 $this->db->free($resql);
139 return 0;
140 }
141 } else {
142 $this->error = $this->db->error();
143 return -1;
144 }
145 }
146
147 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
159 public function liste_array($active = '', $idorcode = 'id', $excludetype = '', $onlyautoornot = 0, $morefilter = '', $shortlabel = 0)
160 {
161 // phpcs:enable
162 global $langs, $conf, $user;
163 $langs->load("commercial");
164
165 $repid = array();
166 $repcode = array();
167 $repall = array();
168
169 $sql = "SELECT id, code, libelle as label, module, type, color, picto";
170 $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
171 $sql .= " WHERE 1=1";
172 if ($active != '') {
173 $sql .= " AND active=".(int) $active;
174 }
175 if (!empty($excludetype)) {
176 $sql .= " AND type <> '".$this->db->escape($excludetype)."'";
177 }
178 if ($morefilter) {
179 $sql .= " AND ".$morefilter;
180 }
181 $sql .= " ORDER BY type, position, module";
182
183 dol_syslog(get_class($this)."::liste_array", LOG_DEBUG);
184 $resql = $this->db->query($sql);
185 if ($resql) {
186 $nump = $this->db->num_rows($resql);
187 if ($nump) {
188 $idforallfornewmodule = 97;
189 $i = 0;
190 while ($i < $nump) {
191 $obj = $this->db->fetch_object($resql);
192
193 $qualified = 1;
194
195 // $obj->type can be 'system', 'systemauto', 'module', 'moduleauto', 'xxx', 'xxxauto'
196 // Note: type = system... than type of event is added among other standard events.
197 // type = module... then type of event is grouped into module defined into module = myobject@mymodule. Example: Event organization or external modules
198 // type = xxx... then type of event is added into list as a new flat value (not grouped). Example: Agefod external module
199 if ($qualified && $onlyautoornot > 0 && preg_match('/^system/', $obj->type) && !preg_match('/^AC_OTH/', $obj->code)) {
200 $qualified = 0; // We discard detailed system events. We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
201 }
202
203 if ($qualified && !empty($obj->module)) {
204 //var_dump($obj->type.' '.$obj->module.' '); var_dump($user->hasRight('facture', 'lire'));
205 $qualified = 0;
206 // Special cases
207 if ($obj->module == 'invoice' && isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
208 $qualified = 1;
209 }
210 if ($obj->module == 'order' && isModEnabled('commande') && !$user->hasRight('commande', 'lire')) {
211 $qualified = 1;
212 }
213 if ($obj->module == 'propal' && isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
214 $qualified = 1;
215 }
216 if ($obj->module == 'invoice_supplier' && ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && !empty($user->rights->fournisseur->facture->lire)) || (isModEnabled('supplier_invoice') && !empty($user->rights->supplier_invoice->lire)))) {
217 $qualified = 1;
218 }
219 if ($obj->module == 'order_supplier' && ((isModEnabled("fournisseur") && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && !empty($user->rights->fournisseur->commande->lire)) || (!isModEnabled('supplier_order') && !empty($user->rights->supplier_order->lire)))) {
220 $qualified = 1;
221 }
222 if ($obj->module == 'shipping' && isModEnabled("expedition") && !empty($user->rights->expedition->lire)) {
223 $qualified = 1;
224 }
225 // For case module = 'myobject@eventorganization'
226 $tmparray = explode("@", $obj->module);
227 if (count($tmparray) > 1 && $tmparray[1] == 'eventorganization' && isModEnabled('eventorganization')) {
228 $qualified = 1;
229 }
230 // For the generic case with type = 'module...' and module = 'myobject@mymodule'
231 $regs = array();
232 if (preg_match('/^module/', $obj->type)) {
233 if (preg_match('/^(.+)@(.+)$/', $obj->module, $regs)) {
234 $tmpobject = $regs[1];
235 $tmpmodule = $regs[2];
236 //var_dump($user->$tmpmodule);
237 if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule) && (!empty($user->rights->$tmpmodule->read) || !empty($user->rights->$tmpmodule->lire) || !empty($user->rights->$tmpmodule->$tmpobject->read) || !empty($user->rights->$tmpmodule->$tmpobject->lire))) {
238 $qualified = 1;
239 }
240 }
241 }
242 // For the case type is not 'system...' neither 'module', we just check module is on
243 if (! in_array($obj->type, array('system', 'systemauto', 'module', 'moduleauto'))) {
244 $tmpmodule = $obj->module;
245 //var_dump($tmpmodule);
246 if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule)) {
247 $qualified = 1;
248 }
249 }
250 }
251
252 if ($qualified) {
253 $keyfortrans = '';
254 $transcode = '';
255 $code = $obj->code;
256 $typecalendar = $obj->type;
257
258 if ($onlyautoornot > 0 && $typecalendar == 'system') {
259 $code = 'AC_MANUAL';
260 } elseif ($onlyautoornot > 0 && $typecalendar == 'systemauto') {
261 $code = 'AC_AUTO';
262 } elseif ($onlyautoornot > 0) {
263 $code = 'AC_'.strtoupper($obj->module);
264 }
265
266 if ($shortlabel) {
267 $keyfortrans = "Action".$code.'Short';
268 $transcode = $langs->trans($keyfortrans);
269 }
270 if (empty($keyfortrans) || $keyfortrans == $transcode) {
271 $keyfortrans = "Action".$code;
272 $transcode = $langs->trans($keyfortrans);
273 }
274 $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
275 if (($onlyautoornot == -1 || $onlyautoornot == -2) && !empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
276 if ($typecalendar == 'system') {
277 $label = '&nbsp;&nbsp; '.$label;
278 $repid[-99] = $langs->trans("ActionAC_MANUAL");
279 $repcode['AC_NON_AUTO'] = '-- '.$langs->trans("ActionAC_MANUAL");
280 }
281 if ($typecalendar == 'systemauto') {
282 $label = '&nbsp;&nbsp; '.$label;
283 $repid[-98] = $langs->trans("ActionAC_AUTO");
284 $repcode['AC_ALL_AUTO'] = '-- '.$langs->trans("ActionAC_AUTO");
285 }
286 if ($typecalendar == 'module') {
287 //TODO check if possible to push it between system and systemauto
288 if (preg_match('/@/', $obj->module)) {
289 $module = explode('@', $obj->module)[1];
290 } else {
291 $module = $obj->module;
292 }
293 $label = '&nbsp;&nbsp; '.$label;
294 if (!isset($repcode['AC_ALL_'.strtoupper($module)])) { // If first time for this module
295 $idforallfornewmodule--;
296 }
297 $repid[$idforallfornewmodule] = $langs->trans("ActionAC_ALL_".strtoupper($module));
298 $repcode['AC_ALL_'.strtoupper($module)] = '-- '.$langs->trans("Module").' '.ucfirst($module);
299 }
300 }
301 $repid[$obj->id] = $label;
302 $repcode[$obj->code] = $label;
303 $repall[$obj->code] = array('id' => $label, 'label' => $label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
304 if ($onlyautoornot > 0 && preg_match('/^module/', $obj->type) && $obj->module) {
305 $repcode[$obj->code] .= ' ('.$langs->trans("Module").': '.$obj->module.')';
306 $repall[$obj->code]['label'] .= ' ('.$langs->trans("Module").': '.$obj->module.')';
307 }
308 }
309 $i++;
310 }
311 }
312
313 if ($idorcode == 'id') {
314 $this->liste_array = $repid;
315 } elseif ($idorcode == 'code') {
316 $this->liste_array = $repcode;
317 } else {
318 $this->liste_array = $repall;
319 }
320
321 return $this->liste_array;
322 } else {
323 $this->error = $this->db->lasterror();
324 return -1;
325 }
326 }
327
328
335 public function getNomUrl($withpicto = 0)
336 {
337 global $langs;
338
339 // Check if translation available
340 $transcode = $langs->trans("Action".$this->code);
341 if ($transcode != "Action".$this->code) {
342 return $transcode;
343 }
344 return -1;
345 }
346}
Class to manage different types of events.
liste_array($active='', $idorcode='id', $excludetype='', $onlyautoornot=0, $morefilter='', $shortlabel=0)
Return list of event types: array(id=>label) or array(code=>label)
fetch($id)
Load action type from database.
__construct($db)
Constructor.
getNomUrl($withpicto=0)
Return name of action type as a label translated.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition repair.php:120