dolibarr  13.0.2
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)) $sql .= " WHERE id=".(int) $id;
110  else $sql .= " WHERE code='".$this->db->escape($id)."'";
111 
112  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
113  $resql = $this->db->query($sql);
114  if ($resql)
115  {
116  if ($this->db->num_rows($resql))
117  {
118  $obj = $this->db->fetch_object($resql);
119 
120  $this->id = $obj->id;
121  $this->code = $obj->code;
122  $this->type = $obj->type;
123  $this->libelle = $obj->label; // deprecated
124  $this->label = $obj->label;
125  $this->active = $obj->active;
126  $this->color = $obj->color;
127 
128  $this->db->free($resql);
129  return 1;
130  } else {
131  $this->db->free($resql);
132  return 0;
133  }
134  } else {
135  $this->error = $this->db->error();
136  return -1;
137  }
138  }
139 
140  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
152  public function liste_array($active = '', $idorcode = 'id', $excludetype = '', $onlyautoornot = 0, $morefilter = '', $shortlabel = 0)
153  {
154  // phpcs:enable
155  global $langs, $conf;
156  $langs->load("commercial");
157 
158  $repid = array();
159  $repcode = array();
160 
161  $sql = "SELECT id, code, libelle as label, module, type, color, picto";
162  $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
163  $sql .= " WHERE 1=1";
164  if ($active != '') {
165  $sql .= " AND active=".(int) $active;
166  }
167  if (!empty($excludetype)) $sql .= " AND type <> '".$this->db->escape($excludetype)."'";
168  if ($morefilter) $sql .= " AND ".$morefilter;
169  $sql .= " ORDER BY module, position, type";
170 
171  dol_syslog(get_class($this)."::liste_array", LOG_DEBUG);
172  $resql = $this->db->query($sql);
173  if ($resql)
174  {
175  $nump = $this->db->num_rows($resql);
176  if ($nump)
177  {
178  $i = 0;
179  while ($i < $nump)
180  {
181  $obj = $this->db->fetch_object($resql);
182 
183  $qualified = 1;
184 
185  // $obj->type can be system, systemauto, module, moduleauto, xxx, xxxauto
186  if ($qualified && $onlyautoornot > 0 && preg_match('/^system/', $obj->type) && !preg_match('/^AC_OTH/', $obj->code)) $qualified = 0; // We discard detailed system events. We keep only the 2 generic lines (AC_OTH and AC_OTH_AUTO)
187 
188  if ($qualified && $obj->module)
189  {
190  if ($obj->module == 'invoice' && !$conf->facture->enabled) $qualified = 0;
191  if ($obj->module == 'order' && !$conf->commande->enabled) $qualified = 0;
192  if ($obj->module == 'propal' && !$conf->propal->enabled) $qualified = 0;
193  if ($obj->module == 'invoice_supplier' && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !$conf->supplier_invoice->enabled)) $qualified = 0;
194  if ($obj->module == 'order_supplier' && ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !$conf->supplier_order->enabled)) $qualified = 0;
195  if ($obj->module == 'shipping' && !$conf->expedition->enabled) $qualified = 0;
196  }
197 
198  if ($qualified)
199  {
200  $keyfortrans = '';
201  $transcode = '';
202  $code = $obj->code;
203  if ($onlyautoornot > 0 && $code == 'AC_OTH') $code = 'AC_MANUAL';
204  if ($onlyautoornot > 0 && $code == 'AC_OTH_AUTO') $code = 'AC_AUTO';
205  if ($shortlabel)
206  {
207  $keyfortrans = "Action".$code.'Short';
208  $transcode = $langs->trans($keyfortrans);
209  }
210  if (empty($keyfortrans) || $keyfortrans == $transcode)
211  {
212  $keyfortrans = "Action".$code;
213  $transcode = $langs->trans($keyfortrans);
214  }
215  $label = (($transcode != $keyfortrans) ? $transcode : $langs->trans($obj->label));
216  if ($onlyautoornot == -1 && !empty($conf->global->AGENDA_USE_EVENT_TYPE) && !preg_match('/auto/i', $code))
217  {
218  $label = '&nbsp; '.$label;
219  $repid[-99] = $langs->trans("ActionAC_MANUAL");
220  $repcode['AC_NON_AUTO'] = $langs->trans("ActionAC_MANUAL");
221  }
222  $repid[$obj->id] = $label;
223  $repcode[$obj->code] = $label;
224  if ($onlyautoornot > 0 && preg_match('/^module/', $obj->type) && $obj->module) $repcode[$obj->code] .= ' ('.$langs->trans("Module").': '.$obj->module.')';
225  }
226  $i++;
227  }
228  }
229  if ($idorcode == 'id') $this->liste_array = $repid;
230  if ($idorcode == 'code') $this->liste_array = $repcode;
231  return $this->liste_array;
232  } else {
233  $this->error = $this->db->lasterror();
234  return -1;
235  }
236  }
237 
238 
245  public function getNomUrl($withpicto = 0)
246  {
247  global $langs;
248 
249  // Check if translation available
250  $transcode = $langs->trans("Action".$this->code);
251  if ($transcode != "Action".$this->code) return $transcode;
252  }
253 }
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=&gt;label) or array(code=&gt;label)
if(!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'] country if(!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'] typent code
Definition: list.php:566
$conf db
API class for accounts.
Definition: inc.php:54
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
fetch($id)
Load action type from database.
getNomUrl($withpicto=0)
Return name of action type as a label translated.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:105