dolibarr  9.0.0
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 <http://www.gnu.org/licenses/>.
17  */
18 
30 {
34  public $error='';
35 
39  public $db;
40 
44  public $id;
45 
46  public $code;
47  public $type;
48  public $libelle; // deprecated
49 
53  public $label;
54 
55  public $active;
56  public $color;
57 
61  public $picto;
62 
63  public $type_actions=array();
64 
65 
71  function __construct($db)
72  {
73  $this->db = $db;
74  }
75 
82  function fetch($id)
83  {
84  $sql = "SELECT id, code, type, libelle as label, color, active, picto";
85  $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
86  if (is_numeric($id)) $sql.= " WHERE id=".$id;
87  else $sql.= " WHERE code='".$id."'";
88 
89  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
90  $resql=$this->db->query($sql);
91  if ($resql)
92  {
93  if ($this->db->num_rows($resql))
94  {
95  $obj = $this->db->fetch_object($resql);
96 
97  $this->id = $obj->id;
98  $this->code = $obj->code;
99  $this->type = $obj->type;
100  $this->libelle = $obj->label; // deprecated
101  $this->label = $obj->label;
102  $this->active = $obj->active;
103  $this->color = $obj->color;
104 
105  $this->db->free($resql);
106  return 1;
107  }
108  else
109  {
110  $this->db->free($resql);
111  return 0;
112  }
113  }
114  else
115  {
116  $this->error=$this->db->error();
117  return -1;
118  }
119  }
120 
121  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
133  function liste_array($active='',$idorcode='id',$excludetype='',$onlyautoornot=0, $morefilter='', $shortlabel=0)
134  {
135  // phpcs:enable
136  global $langs,$conf;
137  $langs->load("commercial");
138 
139  $repid = array();
140  $repcode = array();
141 
142  $sql = "SELECT id, code, libelle as label, module, type, color, picto";
143  $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
144  $sql.= " WHERE 1=1";
145  if ($active != '') $sql.=" AND active=".$active;
146  if (! empty($excludetype)) $sql.=" AND type <> '".$excludetype."'";
147  if ($morefilter) $sql.=" AND ".$morefilter;
148  $sql.= " ORDER BY module, position, type";
149 
150  dol_syslog(get_class($this)."::liste_array", LOG_DEBUG);
151  $resql=$this->db->query($sql);
152  if ($resql)
153  {
154  $nump = $this->db->num_rows($resql);
155  if ($nump)
156  {
157  $i = 0;
158  while ($i < $nump)
159  {
160  $obj = $this->db->fetch_object($resql);
161 
162  $qualified=1;
163 
164  // $obj->type can be system, systemauto, module, moduleauto, xxx, xxxauto
165  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)
166 
167  if ($qualified && $obj->module)
168  {
169  if ($obj->module == 'invoice' && ! $conf->facture->enabled) $qualified=0;
170  if ($obj->module == 'order' && ! $conf->commande->enabled) $qualified=0;
171  if ($obj->module == 'propal' && ! $conf->propal->enabled) $qualified=0;
172  if ($obj->module == 'invoice_supplier' && ! $conf->fournisseur->enabled) $qualified=0;
173  if ($obj->module == 'order_supplier' && ! $conf->fournisseur->enabled) $qualified=0;
174  if ($obj->module == 'shipping' && ! $conf->expedition->enabled) $qualified=0;
175  }
176 
177  if ($qualified)
178  {
179  $keyfortrans='';
180  $transcode='';
181  $code=$obj->code;
182  if ($onlyautoornot > 0 && $code == 'AC_OTH') $code='AC_MANUAL';
183  if ($onlyautoornot > 0 && $code == 'AC_OTH_AUTO') $code='AC_AUTO';
184  if ($shortlabel)
185  {
186  $keyfortrans="Action".$code.'Short';
187  $transcode=$langs->trans($keyfortrans);
188  }
189  if (empty($keyfortrans) || $keyfortrans == $transcode)
190  {
191  $keyfortrans="Action".$code;
192  $transcode=$langs->trans($keyfortrans);
193  }
194  $label = (($transcode!=$keyfortrans) ? $transcode : $langs->trans($obj->label));
195  if ($onlyautoornot == -1 && ! empty($conf->global->AGENDA_USE_EVENT_TYPE) && ! preg_match('/auto/i', $code))
196  {
197  $label='&nbsp; '.$label;
198  $repid[-99]=$langs->trans("ActionAC_MANUAL");
199  $repcode['AC_NON_AUTO']=$langs->trans("ActionAC_MANUAL");
200  }
201  $repid[$obj->id] = $label;
202  $repcode[$obj->code] = $label;
203  if ($onlyautoornot > 0 && preg_match('/^module/',$obj->type) && $obj->module) $repcode[$obj->code].=' ('.$langs->trans("Module").': '.$obj->module.')';
204  }
205  $i++;
206  }
207  }
208  if ($idorcode == 'id') $this->liste_array=$repid;
209  if ($idorcode == 'code') $this->liste_array=$repcode;
210  return $this->liste_array;
211  }
212  else
213  {
214  $this->error=$this->db->lasterror();
215  return -1;
216  }
217  }
218 
219 
226  function getNomUrl($withpicto=0)
227  {
228  global $langs;
229 
230  // Check if translation available
231  $transcode=$langs->trans("Action".$this->code);
232  if ($transcode != "Action".$this->code) return $transcode;
233  }
234 }
Class to manage different types of events.
print $object label
hash of file content (md5_file(dol_osencode($destfull))
Definition: edit.php:153
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
liste_array($active='', $idorcode='id', $excludetype='', $onlyautoornot=0, $morefilter='', $shortlabel=0)
Return list of event types: array(id=>label) or array(code=>label)
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
type
Definition: viewcat.php:284
fetch($id)
Load action type from database.
getNomUrl($withpicto=0)
Return name of action type as a label translated.