dolibarr  20.0.0-alpha
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  $rep_id = array();
166  $rep_code = array();
167  $rep_all = 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  // If AGENDA_SORT_EVENT_TYPE_BY_POSITION_FIRST is defined, we use position as main sort criterion
182  // otherwise we use type as main sort criterion
183  if (getDolGlobalString('AGENDA_SORT_EVENT_TYPE_BY_POSITION_FIRST')) {
184  $sql .= " ORDER BY position, type, module";
185  } else {
186  $sql .= " ORDER BY type, position, module";
187  }
188 
189  dol_syslog(get_class($this)."::liste_array", LOG_DEBUG);
190  $resql = $this->db->query($sql);
191  if ($resql) {
192  $nump = $this->db->num_rows($resql);
193  if ($nump) {
194  $idforallfornewmodule = 96;
195  $TSystem = array(
196  'id' => [],
197  'code' => [],
198  'all' => []
199  );
200  $TSystemAuto = array(
201  'id' => [],
202  'code' => [],
203  'all' => []
204  );
205  $TModule = array(
206  'id' => [],
207  'code' => [],
208  'all' => []
209  );
210  $i = 0;
211  while ($i < $nump) {
212  $obj = $this->db->fetch_object($resql);
213 
214  $qualified = 1;
215 
216  // $obj->type into c_actioncomm can be 'system', 'systemauto', 'module', 'moduleauto', 'xxx', 'xxxauto'
217  // Note: type = system... than type of event is added among other standard events.
218  // type = module... then type of event is grouped into module defined into module = myobject@mymodule. Example: Event organization or external modules
219  // type = xxx... then type of event is added into list as a new flat value (not grouped). Example: Agefod external module
220  if ($qualified && $onlyautoornot > 0 && preg_match('/^system/', $obj->type) && !preg_match('/^AC_OTH/', $obj->code)) {
221  $qualified = 0; // We discard detailed system events. We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
222  }
223 
224  if ($qualified && !empty($obj->module)) {
225  //var_dump($obj->type.' '.$obj->module.' '); var_dump($user->hasRight('facture', 'lire'));
226  $qualified = 0;
227  // Special cases
228  if ($obj->module == 'invoice' && isModEnabled('invoice') && $user->hasRight('facture', 'lire')) {
229  $qualified = 1;
230  }
231  if ($obj->module == 'order' && isModEnabled('order') && !$user->hasRight('commande', 'lire')) {
232  $qualified = 1;
233  }
234  if ($obj->module == 'propal' && isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
235  $qualified = 1;
236  }
237  if ($obj->module == 'invoice_supplier' && ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'facture', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire')))) {
238  $qualified = 1;
239  }
240  if ($obj->module == 'order_supplier' && ((isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'commande', 'lire')) || (!isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')))) {
241  $qualified = 1;
242  }
243  if ($obj->module == 'shipping' && isModEnabled("shipping") && $user->hasRight('expedition', 'lire')) {
244  $qualified = 1;
245  }
246  // For case module = 'myobject@eventorganization'
247  $tmparray = explode("@", $obj->module);
248  if (count($tmparray) > 1 && $tmparray[1] == 'eventorganization' && isModEnabled('eventorganization')) {
249  $qualified = 1;
250  }
251  // For the generic case with type = 'module...' and module = 'myobject@mymodule'
252  $regs = array();
253  if (preg_match('/^module/', $obj->type)) {
254  if (preg_match('/^(.+)@(.+)$/', $obj->module, $regs)) {
255  $tmpobject = $regs[1];
256  $tmpmodule = $regs[2];
257  //var_dump($user->$tmpmodule);
258  if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule) && ($user->hasRight($tmpmodule, 'read') || $user->hasRight($tmpmodule, 'lire') || $user->hasRight($tmpmodule, $tmpobject, 'read') || $user->hasRight($tmpmodule, $tmpobject, 'lire'))) {
259  $qualified = 1;
260  }
261  }
262  }
263  // For the case type is not 'system...' neither 'module', we just check module is on
264  if (! in_array($obj->type, array('system', 'systemauto', 'module', 'moduleauto'))) {
265  $tmpmodule = $obj->module;
266  //var_dump($tmpmodule);
267  if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule)) {
268  $qualified = 1;
269  }
270  }
271  }
272 
273  if ($qualified) {
274  $keyfortrans = '';
275  $transcode = '';
276  $code = $obj->code;
277  $typecalendar = $obj->type;
278 
279  if ($onlyautoornot > 0 && $typecalendar == 'system') {
280  $code = 'AC_MANUAL';
281  } elseif ($onlyautoornot > 0 && $typecalendar == 'systemauto') {
282  $code = 'AC_AUTO';
283  } elseif ($onlyautoornot > 0) {
284  $code = 'AC_'.strtoupper($obj->module);
285  }
286 
287  if ($shortlabel) {
288  $keyfortrans = "Action".$code.'Short';
289  $transcode = $langs->trans($keyfortrans);
290  }
291  if (empty($keyfortrans) || $keyfortrans == $transcode) {
292  $keyfortrans = "Action".$code;
293  $transcode = $langs->trans($keyfortrans);
294  }
295 
296  $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
297  if (($onlyautoornot == -1 || $onlyautoornot == -2) && getDolGlobalString('AGENDA_USE_EVENT_TYPE')) {
298  // Add a group of elements
299  if ($typecalendar == 'system' || $typecalendar == 'user') {
300  $label = '&nbsp;&nbsp; '.$label;
301  $TSystem['id'][-99] = $langs->trans("ActionAC_MANUAL");
302  $TSystem['code']['AC_NON_AUTO'] = '-- '.$langs->trans("ActionAC_MANUAL");
303  }
304  if ($typecalendar == 'systemauto') {
305  $label = '&nbsp;&nbsp; '.$label;
306  $TSystemAuto['id'][-98] = $langs->trans("ActionAC_AUTO");
307  $TSystemAuto['code']['AC_ALL_AUTO'] = '-- '.$langs->trans("ActionAC_AUTO");
308  }
309 
310  if ($typecalendar == 'module') {
311  $module = preg_replace('/^[^@]+@/', '', $obj->module);
312  $label = '&nbsp;&nbsp; '.$label;
313  if (!isset($rep_code['AC_ALL_'.strtoupper($module)])) { // If first time for this module
314  $idforallfornewmodule--;
315  }
316  $TModule['id'][$idforallfornewmodule] = $langs->trans("ActionAC_ALL_".strtoupper($module));
317  $TModule['code']['AC_ALL_'.strtoupper($module)] = '-- '.$langs->trans("Module").' '.ucfirst($module);
318  }
319  }
320  // Add element
321  if ($typecalendar == 'system' || $typecalendar == 'user') {
322  $TSystem['id'][$obj->id] = $label;
323  $TSystem['code'][$obj->code] = $label;
324  $TSystem['all'][$obj->code] = array('id' => $label, 'label' => $label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
325  } elseif ($typecalendar == 'systemauto') {
326  $TSystemAuto['id'][$obj->id] = $label;
327  $TSystemAuto['code'][$obj->code] = $label;
328  $TSystemAuto['all'][$obj->code] = array('id' => $label, 'label' => $label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
329  } elseif ($typecalendar == 'module') { // Can be automatic or manual
330  $module = preg_replace('/^[^@]+@/', '', $obj->module);
331  $TModule['id'][$obj->id] = $label;
332  $TModule['code'][$obj->code] = $label;
333  $TModule['all'][$obj->code] = array('id' => $label, 'label' => $langs->trans("Module").' '.ucfirst($module).' - '.$label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
334  }
335 
336  if ($onlyautoornot > 0 && preg_match('/^module/', $obj->type) && $obj->module) {
337  $moduletoshow = ucfirst(preg_replace('/^[^@]+@/', '', $obj->module));
338  //array_key_exists($obj->code, $TModule['code']) ? ($TModule['code'][$obj->code] .= $langs->trans("Module").': '.$moduletoshow.' - '.$label) : ($TModule['code'][$obj->code] = $langs->trans("Module").': '.$moduletoshow.' - '.$label);
339  //array_key_exists($obj->code, $TModule['all']) ? ($TModule['all'][$obj->code]['label'] .= $langs->trans("Module").': '.$moduletoshow.' - '.$label) : ($TModule['all'][$obj->code]['label'] = $langs->trans("Module").': '.$moduletoshow.' - '.$label);
340  $TModule['code'][$obj->code] = $moduletoshow.' - '.$label;
341  $TModule['all'][$obj->code]['label'] = $moduletoshow.' - '.$label;
342  }
343  }
344  $i++;
345  }
346  }
347 
348  if (empty($idorcode)) {
349  $idorcode = 'all';
350  }
351  $TType = $TSystem[$idorcode];
352  if (! empty($TSystemAuto[$idorcode])) {
353  $TType = array_merge($TType, $TSystemAuto[$idorcode]);
354  }
355  if (! empty($TModule[$idorcode])) {
356  $TType = array_merge($TType, $TModule[$idorcode]);
357  }
358  $this->liste_array = $TType;
359 
360 
361  return $this->liste_array;
362  } else {
363  $this->error = $this->db->lasterror();
364  return -1;
365  }
366  }
367 
368 
375  public function getNomUrl($withpicto = 0)
376  {
377  global $langs;
378 
379  // Check if translation available
380  $transcode = $langs->trans("Action".$this->code);
381  if ($transcode != "Action".$this->code) {
382  return $transcode;
383  }
384  return -1;
385  }
386 }
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.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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:122
print *****$script_file(".$version.") pid code
1: frais de port 2: ecotaxe 3: option line (when qty = 0)