dolibarr  9.0.0
events.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
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 
26 // Put here all includes required by your class file
27 //require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
28 //require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
29 //require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
30 
31 
35 class Events // extends CommonObject
36 {
40  public $element='events';
41 
45  public $table_element='events';
46 
50  public $id;
51 
55  public $db;
56 
60  public $error='';
61 
62  public $tms;
63  public $type;
64 
68  public $entity;
69 
70  public $dateevent;
71 
75  public $description;
76 
77  // List of all Audit/Security events supported by triggers
78  public $eventstolog=array(
79  array('id'=>'USER_LOGIN', 'test'=>1),
80  array('id'=>'USER_LOGIN_FAILED', 'test'=>1),
81  array('id'=>'USER_LOGOUT', 'test'=>1),
82  array('id'=>'USER_CREATE', 'test'=>1),
83  array('id'=>'USER_MODIFY', 'test'=>1),
84  array('id'=>'USER_NEW_PASSWORD', 'test'=>1),
85  array('id'=>'USER_ENABLEDISABLE', 'test'=>1),
86  array('id'=>'USER_DELETE', 'test'=>1),
87  /* array('id'=>'USER_SETINGROUP', 'test'=>1), deprecated. Replace with USER_MODIFY
88  array('id'=>'USER_REMOVEFROMGROUP', 'test'=>1), deprecated. Replace with USER_MODIFY */
89  array('id'=>'GROUP_CREATE', 'test'=>1),
90  array('id'=>'GROUP_MODIFY', 'test'=>1),
91  array('id'=>'GROUP_DELETE', 'test'=>1),
92  /* array('id'=>'ACTION_CREATE', 'test'=>$conf->societe->enabled),
93  array('id'=>'COMPANY_CREATE', 'test'=>$conf->societe->enabled),
94  array('id'=>'CONTRACT_VALIDATE', 'test'=>$conf->contrat->enabled),
95  array('id'=>'PROPAL_VALIDATE', 'test'=>$conf->propal->enabled),
96  array('id'=>'PROPAL_CLOSE_SIGNED', 'test'=>$conf->propal->enabled),
97  array('id'=>'PROPAL_CLOSE_REFUSED', 'test'=>$conf->propal->enabled),
98  array('id'=>'PROPAL_SENTBYMAIL', 'test'=>$conf->propal->enabled),
99  array('id'=>'ORDER_VALIDATE', 'test'=>$conf->commande->enabled),
100  array('id'=>'ORDER_SENTBYMAIL', 'test'=>$conf->commande->enabled),
101  array('id'=>'BILL_VALIDATE', 'test'=>$conf->facture->enabled),
102  array('id'=>'BILL_PAYED', 'test'=>$conf->facture->enabled),
103  array('id'=>'BILL_CANCEL', 'test'=>$conf->facture->enabled),
104  array('id'=>'BILL_SENTBYMAIL', 'test'=>$conf->facture->enabled),
105  array('id'=>'PAYMENT_CUSTOMER_CREATE','test'=>$conf->facture->enabled),
106  array('id'=>'PAYMENT_SUPPLIER_CREATE','test'=>$conf->fournisseur->enabled),
107  array('id'=>'MEMBER_CREATE', 'test'=>$conf->adherent->enabled),
108  array('id'=>'MEMBER_VALIDATE', 'test'=>$conf->adherent->enabled),
109  array('id'=>'MEMBER_SUBSCRIPTION', 'test'=>$conf->adherent->enabled),
110  array('id'=>'MEMBER_MODIFY', 'test'=>$conf->adherent->enabled),
111  array('id'=>'MEMBER_RESILIATE', 'test'=>$conf->adherent->enabled),
112  array('id'=>'MEMBER_DELETE', 'test'=>$conf->adherent->enabled),
113  */
114  );
115 
116 
122  function __construct($db)
123  {
124  $this->db = $db;
125  }
126 
127 
134  function create($user)
135  {
136  global $conf, $langs;
137 
138  // Clean parameters
139  $this->description=trim($this->description);
140  if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent=$_SERVER['HTTP_USER_AGENT'];
141 
142  // Check parameters
143  if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; }
144 
145  // Insert request
146  $sql = "INSERT INTO ".MAIN_DB_PREFIX."events(";
147  $sql.= "type,";
148  $sql.= "entity,";
149  $sql.= "ip,";
150  $sql.= "user_agent,";
151  $sql.= "dateevent,";
152  $sql.= "fk_user,";
153  $sql.= "description";
154  $sql.= ") VALUES (";
155  $sql.= " '".$this->db->escape($this->type)."',";
156  $sql.= " ".$conf->entity.",";
157  $sql.= " '".$this->db->escape(getUserRemoteIP())."',";
158  $sql.= " ".($this->user_agent ? "'".$this->db->escape(dol_trunc($this->user_agent,250))."'" : 'NULL').",";
159  $sql.= " '".$this->db->idate($this->dateevent)."',";
160  $sql.= " ".($user->id?"'".$this->db->escape($user->id)."'":'NULL').",";
161  $sql.= " '".$this->db->escape(dol_trunc($this->description,250))."'";
162  $sql.= ")";
163 
164  dol_syslog(get_class($this)."::create", LOG_DEBUG);
165  $resql=$this->db->query($sql);
166  if ($resql)
167  {
168  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events");
169  return $this->id;
170  }
171  else
172  {
173  $this->error="Error ".$this->db->lasterror();
174  return -1;
175  }
176  }
177 
178 
186  function update($user=null, $notrigger=0)
187  {
188  global $conf, $langs;
189 
190  // Clean parameters
191  $this->id=trim($this->id);
192  $this->type=trim($this->type);
193  $this->description=trim($this->description);
194 
195  // Check parameters
196  // Put here code to add control on parameters values
197 
198  // Update request
199  $sql = "UPDATE ".MAIN_DB_PREFIX."events SET";
200  $sql.= " type='".$this->db->escape($this->type)."',";
201  $sql.= " dateevent='".$this->db->idate($this->dateevent)."',";
202  $sql.= " description='".$this->db->escape($this->description)."'";
203  $sql.= " WHERE rowid=".$this->id;
204 
205  dol_syslog(get_class($this)."::update", LOG_DEBUG);
206  $resql = $this->db->query($sql);
207  if (! $resql)
208  {
209  $this->error="Error ".$this->db->lasterror();
210  return -1;
211  }
212  return 1;
213  }
214 
215 
223  function fetch($id, $user=null)
224  {
225  global $langs;
226 
227  $sql = "SELECT";
228  $sql.= " t.rowid,";
229  $sql.= " t.tms,";
230  $sql.= " t.type,";
231  $sql.= " t.entity,";
232  $sql.= " t.dateevent,";
233  $sql.= " t.description,";
234  $sql.= " t.ip,";
235  $sql.= " t.user_agent";
236  $sql.= " FROM ".MAIN_DB_PREFIX."events as t";
237  $sql.= " WHERE t.rowid = ".$id;
238 
239  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
240  $resql=$this->db->query($sql);
241  if ($resql)
242  {
243  if ($this->db->num_rows($resql))
244  {
245  $obj = $this->db->fetch_object($resql);
246 
247  $this->id = $obj->rowid;
248  $this->tms = $this->db->jdate($obj->tms);
249  $this->type = $obj->type;
250  $this->entity = $obj->entity;
251  $this->dateevent = $this->db->jdate($obj->dateevent);
252  $this->description = $obj->description;
253  $this->ip = $obj->ip;
254  $this->user_agent = $obj->user_agent;
255  }
256  $this->db->free($resql);
257 
258  return 1;
259  }
260  else
261  {
262  $this->error="Error ".$this->db->lasterror();
263  return -1;
264  }
265  }
266 
267 
274  function delete($user)
275  {
276  global $conf, $langs;
277 
278  $sql = "DELETE FROM ".MAIN_DB_PREFIX."events";
279  $sql.= " WHERE rowid=".$this->id;
280 
281  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
282  $resql = $this->db->query($sql);
283  if (! $resql)
284  {
285  $this->error="Error ".$this->db->lasterror();
286  return -1;
287  }
288 
289  return 1;
290  }
291 
292 
300  function initAsSpecimen()
301  {
302  $this->id=0;
303 
304  $this->tms=time();
305  $this->type='';
306  $this->dateevent=time();
307  $this->description='This is a specimen event';
308  }
309 }
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
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
getUserRemoteIP()
Return the IP of remote user.
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
fetch($id, $user=null)
Load object in memory from database.
initAsSpecimen()
Initialise an instance with random values.
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
type
Definition: viewcat.php:284
create($user)
Create in database.
update($user=null, $notrigger=0)
Update database.
Events class.