dolibarr  7.0.0-beta
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 {
31  var $error;
32  var $db;
33 
34  var $id;
35 
36  var $code;
37  var $type;
38  var $libelle; // deprecated
39  var $label;
40  var $active;
41  var $color;
42  var $picto;
43 
44  var $type_actions=array();
45 
46 
52  function __construct($db)
53  {
54  $this->db = $db;
55  }
56 
63  function fetch($id)
64  {
65  $sql = "SELECT id, code, type, libelle as label, color, active, picto";
66  $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
67  if (is_numeric($id)) $sql.= " WHERE id=".$id;
68  else $sql.= " WHERE code='".$id."'";
69 
70  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
71  $resql=$this->db->query($sql);
72  if ($resql)
73  {
74  if ($this->db->num_rows($resql))
75  {
76  $obj = $this->db->fetch_object($resql);
77 
78  $this->id = $obj->id;
79  $this->code = $obj->code;
80  $this->type = $obj->type;
81  $this->libelle = $obj->label; // deprecated
82  $this->label = $obj->label;
83  $this->active = $obj->active;
84  $this->color = $obj->color;
85 
86  $this->db->free($resql);
87  return 1;
88  }
89  else
90  {
91  $this->db->free($resql);
92  return 0;
93  }
94  }
95  else
96  {
97  $this->error=$this->db->error();
98  return -1;
99  }
100  }
101 
113  function liste_array($active='',$idorcode='id',$excludetype='',$onlyautoornot=0, $morefilter='', $shortlabel=0)
114  {
115  global $langs,$conf;
116  $langs->load("commercial");
117 
118  $repid = array();
119  $repcode = array();
120 
121  $sql = "SELECT id, code, libelle as label, module, type, color, picto";
122  $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm";
123  $sql.= " WHERE 1=1";
124  if ($active != '') $sql.=" AND active=".$active;
125  if (! empty($excludetype)) $sql.=" AND type <> '".$excludetype."'";
126  if ($morefilter) $sql.=" AND ".$morefilter;
127  $sql.= " ORDER BY module, position, type";
128 
129  dol_syslog(get_class($this)."::liste_array", LOG_DEBUG);
130  $resql=$this->db->query($sql);
131  if ($resql)
132  {
133  $nump = $this->db->num_rows($resql);
134  if ($nump)
135  {
136  $i = 0;
137  while ($i < $nump)
138  {
139  $obj = $this->db->fetch_object($resql);
140 
141  $qualified=1;
142 
143  // $obj->type can be system, systemauto, module, moduleauto, xxx, xxxauto
144  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)
145 
146  if ($qualified && $obj->module)
147  {
148  if ($obj->module == 'invoice' && ! $conf->facture->enabled) $qualified=0;
149  if ($obj->module == 'order' && ! $conf->commande->enabled) $qualified=0;
150  if ($obj->module == 'propal' && ! $conf->propal->enabled) $qualified=0;
151  if ($obj->module == 'invoice_supplier' && ! $conf->fournisseur->enabled) $qualified=0;
152  if ($obj->module == 'order_supplier' && ! $conf->fournisseur->enabled) $qualified=0;
153  if ($obj->module == 'shipping' && ! $conf->expedition->enabled) $qualified=0;
154  }
155 
156  if ($qualified)
157  {
158  $keyfortrans='';
159  $transcode='';
160  $code=$obj->code;
161  if ($onlyautoornot > 0 && $code == 'AC_OTH') $code='AC_MANUAL';
162  if ($onlyautoornot > 0 && $code == 'AC_OTH_AUTO') $code='AC_AUTO';
163  if ($shortlabel)
164  {
165  $keyfortrans="Action".$code.'Short';
166  $transcode=$langs->trans($keyfortrans);
167  }
168  if (empty($keyfortrans) || $keyfortrans == $transcode)
169  {
170  $keyfortrans="Action".$code;
171  $transcode=$langs->trans($keyfortrans);
172  }
173  $label = (($transcode!=$keyfortrans) ? $transcode : $langs->trans($obj->label));
174  if ($onlyautoornot == -1 && ! empty($conf->global->AGENDA_USE_EVENT_TYPE) && ! preg_match('/auto/i', $code))
175  {
176  $label='&nbsp; '.$label;
177  $repid[-99]=$langs->trans("ActionAC_MANUAL");
178  $repcode['AC_NON_AUTO']=$langs->trans("ActionAC_MANUAL");
179  }
180  $repid[$obj->id] = $label;
181  $repcode[$obj->code] = $label;
182  if ($onlyautoornot > 0 && preg_match('/^module/',$obj->type) && $obj->module) $repcode[$obj->code].=' ('.$langs->trans("Module").': '.$obj->module.')';
183  }
184  $i++;
185  }
186  }
187  if ($idorcode == 'id') $this->liste_array=$repid;
188  if ($idorcode == 'code') $this->liste_array=$repcode;
189  return $this->liste_array;
190  }
191  else
192  {
193  $this->error=$this->db->lasterror();
194  return -1;
195  }
196  }
197 
198 
205  function getNomUrl($withpicto=0)
206  {
207  global $langs;
208 
209  // Check if translation available
210  $transcode=$langs->trans("Action".$this->code);
211  if ($transcode != "Action".$this->code) return $transcode;
212  }
213 
214 }
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)
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
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)&&$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:1013
type
Definition: viewcat.php:283