dolibarr  17.0.3
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 
94  public function __construct($db)
95  {
96  $this->db = $db;
97  }
98 
105  public function fetch($id)
106  {
107  $sql = "SELECT id, code, type, libelle as label, color, active, picto";
108  $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
109  if (is_numeric($id)) {
110  $sql .= " WHERE id=".(int) $id;
111  } else {
112  $sql .= " WHERE code='".$this->db->escape($id)."'";
113  }
114 
115  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
116  $resql = $this->db->query($sql);
117  if ($resql) {
118  if ($this->db->num_rows($resql)) {
119  $obj = $this->db->fetch_object($resql);
120 
121  $this->id = $obj->id;
122  $this->code = $obj->code;
123  $this->type = $obj->type;
124  $this->libelle = $obj->label; // deprecated
125  $this->label = $obj->label;
126  $this->active = $obj->active;
127  $this->color = $obj->color;
128 
129  $this->db->free($resql);
130  return 1;
131  } else {
132  $this->db->free($resql);
133  return 0;
134  }
135  } else {
136  $this->error = $this->db->error();
137  return -1;
138  }
139  }
140 
141  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
153  public function liste_array($active = '', $idorcode = 'id', $excludetype = '', $onlyautoornot = 0, $morefilter = '', $shortlabel = 0)
154  {
155  // phpcs:enable
156  global $langs, $conf, $user;
157  $langs->load("commercial");
158 
159  $repid = array();
160  $repcode = array();
161  $repall = array();
162 
163  $sql = "SELECT id, code, libelle as label, module, type, color, picto";
164  $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
165  $sql .= " WHERE 1=1";
166  if ($active != '') {
167  $sql .= " AND active=".(int) $active;
168  }
169  if (!empty($excludetype)) {
170  $sql .= " AND type <> '".$this->db->escape($excludetype)."'";
171  }
172  if ($morefilter) {
173  $sql .= " AND ".$morefilter;
174  }
175  $sql .= " ORDER BY type, position, module";
176 
177  dol_syslog(get_class($this)."::liste_array", LOG_DEBUG);
178  $resql = $this->db->query($sql);
179  if ($resql) {
180  $nump = $this->db->num_rows($resql);
181  if ($nump) {
182  $idforallfornewmodule = 97;
183  $i = 0;
184  while ($i < $nump) {
185  $obj = $this->db->fetch_object($resql);
186 
187  $qualified = 1;
188 
189  // $obj->type can be 'system', 'systemauto', 'module', 'moduleauto', 'xxx', 'xxxauto'
190  // Note: type = system... than type of event is added among other standard events.
191  // type = module... then type of event is grouped into module defined into module = myobject@mymodule. Example: Event organization or external modules
192  // type = xxx... then type of event is added into list as a new flat value (not grouped). Example: Agefod external module
193  if ($qualified && $onlyautoornot > 0 && preg_match('/^system/', $obj->type) && !preg_match('/^AC_OTH/', $obj->code)) {
194  $qualified = 0; // We discard detailed system events. We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
195  }
196 
197  if ($qualified && !empty($obj->module)) {
198  //var_dump($obj->type.' '.$obj->module.' '); var_dump($user->rights->facture->lire);
199  $qualified = 0;
200  // Special cases
201  if ($obj->module == 'invoice' && isModEnabled('facture') && !empty($user->rights->facture->lire)) {
202  $qualified = 1;
203  }
204  if ($obj->module == 'order' && isModEnabled('commande') && empty($user->rights->commande->lire)) {
205  $qualified = 1;
206  }
207  if ($obj->module == 'propal' && isModEnabled("propal") && !empty($user->rights->propal->lire)) {
208  $qualified = 1;
209  }
210  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)))) {
211  $qualified = 1;
212  }
213  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)))) {
214  $qualified = 1;
215  }
216  if ($obj->module == 'shipping' && isModEnabled("expedition") && !empty($user->rights->expedition->lire)) {
217  $qualified = 1;
218  }
219  // For case module = 'myobject@eventorganization'
220  $tmparray = preg_split("/@/", $obj->module, -1);
221  if (count($tmparray) > 1 && $tmparray[1] == 'eventorganization' && isModEnabled('eventorganization')) {
222  $qualified = 1;
223  }
224  // For the generic case with type = 'module...' and module = 'myobject@mymodule'
225  $regs = array();
226  if (preg_match('/^module/', $obj->type)) {
227  if (preg_match('/^(.+)@(.+)$/', $obj->module, $regs)) {
228  $tmpobject = $regs[1];
229  $tmpmodule = $regs[2];
230  //var_dump($user->$tmpmodule);
231  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))) {
232  $qualified = 1;
233  }
234  }
235  }
236  // For the case type is not 'system...' neither 'module', we just check module is on
237  if (! in_array($obj->type, array('system', 'systemauto', 'module', 'moduleauto'))) {
238  $tmpmodule = $obj->module;
239  //var_dump($tmpmodule);
240  if ($tmpmodule && isset($conf->$tmpmodule) && isModEnabled($tmpmodule)) {
241  $qualified = 1;
242  }
243  }
244  }
245 
246  if ($qualified) {
247  $keyfortrans = '';
248  $transcode = '';
249  $code = $obj->code;
250  $typecalendar = $obj->type;
251 
252  if ($onlyautoornot > 0 && $typecalendar == 'system') {
253  $code = 'AC_MANUAL';
254  } elseif ($onlyautoornot > 0 && $typecalendar == 'systemauto') {
255  $code = 'AC_AUTO';
256  } elseif ($onlyautoornot > 0) {
257  $code = 'AC_'.strtoupper($obj->module);
258  }
259 
260  if ($shortlabel) {
261  $keyfortrans = "Action".$code.'Short';
262  $transcode = $langs->trans($keyfortrans);
263  }
264  if (empty($keyfortrans) || $keyfortrans == $transcode) {
265  $keyfortrans = "Action".$code;
266  $transcode = $langs->trans($keyfortrans);
267  }
268  $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
269  if (($onlyautoornot == -1 || $onlyautoornot == -2) && !empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
270  if ($typecalendar == 'system') {
271  $label = '&nbsp;&nbsp; '.$label;
272  $repid[-99] = $langs->trans("ActionAC_MANUAL");
273  $repcode['AC_NON_AUTO'] = '-- '.$langs->trans("ActionAC_MANUAL");
274  }
275  if ($typecalendar == 'systemauto') {
276  $label = '&nbsp;&nbsp; '.$label;
277  $repid[-98] = $langs->trans("ActionAC_AUTO");
278  $repcode['AC_ALL_AUTO'] = '-- '.$langs->trans("ActionAC_AUTO");
279  }
280  if ($typecalendar == 'module') {
281  //TODO check if possible to push it between system and systemauto
282  if (preg_match('/@/', $obj->module)) {
283  $module = explode('@', $obj->module)[1];
284  } else {
285  $module = $obj->module;
286  }
287  $label = '&nbsp;&nbsp; '.$label;
288  if (!isset($repcode['AC_ALL_'.strtoupper($module)])) { // If first time for this module
289  $idforallfornewmodule--;
290  }
291  $repid[$idforallfornewmodule] = $langs->trans("ActionAC_ALL_".strtoupper($module));
292  $repcode['AC_ALL_'.strtoupper($module)] = '-- '.$langs->trans("Module").' '.ucfirst($module);
293  }
294  }
295  $repid[$obj->id] = $label;
296  $repcode[$obj->code] = $label;
297  $repall[$obj->code] = array('id' => $label, 'label' => $label, 'type' => $typecalendar, 'color' => $obj->color, 'picto' => $obj->picto);
298  if ($onlyautoornot > 0 && preg_match('/^module/', $obj->type) && $obj->module) {
299  $repcode[$obj->code] .= ' ('.$langs->trans("Module").': '.$obj->module.')';
300  $repall[$obj->code]['label'] .= ' ('.$langs->trans("Module").': '.$obj->module.')';
301  }
302  }
303  $i++;
304  }
305  }
306 
307  if ($idorcode == 'id') {
308  $this->liste_array = $repid;
309  } elseif ($idorcode == 'code') {
310  $this->liste_array = $repcode;
311  } else {
312  $this->liste_array = $repall;
313  }
314 
315  return $this->liste_array;
316  } else {
317  $this->error = $this->db->lasterror();
318  return -1;
319  }
320  }
321 
322 
329  public function getNomUrl($withpicto = 0)
330  {
331  global $langs;
332 
333  // Check if translation available
334  $transcode = $langs->trans("Action".$this->code);
335  if ($transcode != "Action".$this->code) {
336  return $transcode;
337  }
338  }
339 }
db
$conf db
API class for accounts.
Definition: inc.php:41
CActionComm\liste_array
liste_array($active='', $idorcode='id', $excludetype='', $onlyautoornot=0, $morefilter='', $shortlabel=0)
Return list of event types: array(id=>label) or array(code=>label)
Definition: cactioncomm.class.php:153
CActionComm\__construct
__construct($db)
Constructor.
Definition: cactioncomm.class.php:94
CActionComm
Class to manage different types of events.
Definition: cactioncomm.class.php:29
code
print *****$script_file(".$version.") pid code
! Closing after partial payment: discount_vat, badcustomer or badsupplier, bankcharge,...
Definition: sync_members_ldap2dolibarr.php:60
CActionComm\getNomUrl
getNomUrl($withpicto=0)
Return name of action type as a label translated.
Definition: cactioncomm.class.php:329
$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
CActionComm\fetch
fetch($id)
Load action type from database.
Definition: cactioncomm.class.php:105
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119