dolibarr  7.0.0-beta
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@capnetworks.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 {
37  public $element='events';
38  public $table_element='events';
39 
40  var $id;
41  var $db;
42 
43  var $error;
44 
45  var $tms;
46  var $type;
47  var $entity;
48  var $dateevent;
49  var $description;
50 
51  // List of all Audit/Security events supported by triggers
52  var $eventstolog=array(
53  array('id'=>'USER_LOGIN', 'test'=>1),
54  array('id'=>'USER_LOGIN_FAILED', 'test'=>1),
55  array('id'=>'USER_LOGOUT', 'test'=>1),
56  array('id'=>'USER_CREATE', 'test'=>1),
57  array('id'=>'USER_MODIFY', 'test'=>1),
58  array('id'=>'USER_NEW_PASSWORD', 'test'=>1),
59  array('id'=>'USER_ENABLEDISABLE', 'test'=>1),
60  array('id'=>'USER_DELETE', 'test'=>1),
61  /* array('id'=>'USER_SETINGROUP', 'test'=>1), deprecated. Replace with USER_MODIFY
62  array('id'=>'USER_REMOVEFROMGROUP', 'test'=>1), deprecated. Replace with USER_MODIFY */
63  array('id'=>'GROUP_CREATE', 'test'=>1),
64  array('id'=>'GROUP_MODIFY', 'test'=>1),
65  array('id'=>'GROUP_DELETE', 'test'=>1),
66  /* array('id'=>'ACTION_CREATE', 'test'=>$conf->societe->enabled),
67  array('id'=>'COMPANY_CREATE', 'test'=>$conf->societe->enabled),
68  array('id'=>'CONTRACT_VALIDATE', 'test'=>$conf->contrat->enabled),
69  array('id'=>'PROPAL_VALIDATE', 'test'=>$conf->propal->enabled),
70  array('id'=>'PROPAL_CLOSE_SIGNED', 'test'=>$conf->propal->enabled),
71  array('id'=>'PROPAL_CLOSE_REFUSED', 'test'=>$conf->propal->enabled),
72  array('id'=>'PROPAL_SENTBYMAIL', 'test'=>$conf->propal->enabled),
73  array('id'=>'ORDER_VALIDATE', 'test'=>$conf->commande->enabled),
74  array('id'=>'ORDER_SENTBYMAIL', 'test'=>$conf->commande->enabled),
75  array('id'=>'BILL_VALIDATE', 'test'=>$conf->facture->enabled),
76  array('id'=>'BILL_PAYED', 'test'=>$conf->facture->enabled),
77  array('id'=>'BILL_CANCEL', 'test'=>$conf->facture->enabled),
78  array('id'=>'BILL_SENTBYMAIL', 'test'=>$conf->facture->enabled),
79  array('id'=>'PAYMENT_CUSTOMER_CREATE','test'=>$conf->facture->enabled),
80  array('id'=>'PAYMENT_SUPPLIER_CREATE','test'=>$conf->fournisseur->enabled),
81  array('id'=>'MEMBER_CREATE', 'test'=>$conf->adherent->enabled),
82  array('id'=>'MEMBER_VALIDATE', 'test'=>$conf->adherent->enabled),
83  array('id'=>'MEMBER_SUBSCRIPTION', 'test'=>$conf->adherent->enabled),
84  array('id'=>'MEMBER_MODIFY', 'test'=>$conf->adherent->enabled),
85  array('id'=>'MEMBER_RESILIATE', 'test'=>$conf->adherent->enabled),
86  array('id'=>'MEMBER_DELETE', 'test'=>$conf->adherent->enabled),
87  */
88  );
89 
90 
96  function __construct($db)
97  {
98  $this->db = $db;
99  return 1;
100  }
101 
102 
109  function create($user)
110  {
111  global $conf, $langs;
112 
113  // Clean parameters
114  $this->description=trim($this->description);
115 
116  // Check parameters
117  if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; }
118 
119  // Insert request
120  $sql = "INSERT INTO ".MAIN_DB_PREFIX."events(";
121  $sql.= "type,";
122  $sql.= "entity,";
123  $sql.= "ip,";
124  $sql.= "user_agent,";
125  $sql.= "dateevent,";
126  $sql.= "fk_user,";
127  $sql.= "description";
128  $sql.= ") VALUES (";
129  $sql.= " '".$this->db->escape($this->type)."',";
130  $sql.= " ".$conf->entity.",";
131  $sql.= " '".$this->db->escape($_SERVER['REMOTE_ADDR'])."',";
132  $sql.= " ".($_SERVER['HTTP_USER_AGENT']?"'".$this->db->escape(dol_trunc($_SERVER['HTTP_USER_AGENT'],250))."'":'NULL').",";
133  $sql.= " '".$this->db->idate($this->dateevent)."',";
134  $sql.= " ".($user->id?"'".$this->db->escape($user->id)."'":'NULL').",";
135  $sql.= " '".$this->db->escape(dol_trunc($this->description,250))."'";
136  $sql.= ")";
137 
138  dol_syslog(get_class($this)."::create", LOG_DEBUG);
139  $resql=$this->db->query($sql);
140  if ($resql)
141  {
142  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events");
143  return $this->id;
144  }
145  else
146  {
147  $this->error="Error ".$this->db->lasterror();
148  return -1;
149  }
150  }
151 
152 
160  function update($user=null, $notrigger=0)
161  {
162  global $conf, $langs;
163 
164  // Clean parameters
165  $this->id=trim($this->id);
166  $this->type=trim($this->type);
167  $this->description=trim($this->description);
168 
169  // Check parameters
170  // Put here code to add control on parameters values
171 
172  // Update request
173  $sql = "UPDATE ".MAIN_DB_PREFIX."events SET";
174  $sql.= " type='".$this->db->escape($this->type)."',";
175  $sql.= " dateevent='".$this->db->idate($this->dateevent)."',";
176  $sql.= " description='".$this->db->escape($this->description)."'";
177  $sql.= " WHERE rowid=".$this->id;
178 
179  dol_syslog(get_class($this)."::update", LOG_DEBUG);
180  $resql = $this->db->query($sql);
181  if (! $resql)
182  {
183  $this->error="Error ".$this->db->lasterror();
184  return -1;
185  }
186  return 1;
187  }
188 
189 
197  function fetch($id, $user=null)
198  {
199  global $langs;
200 
201  $sql = "SELECT";
202  $sql.= " t.rowid,";
203  $sql.= " t.tms,";
204  $sql.= " t.type,";
205  $sql.= " t.entity,";
206  $sql.= " t.dateevent,";
207  $sql.= " t.description,";
208  $sql.= " t.ip,";
209  $sql.= " t.user_agent";
210  $sql.= " FROM ".MAIN_DB_PREFIX."events as t";
211  $sql.= " WHERE t.rowid = ".$id;
212 
213  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
214  $resql=$this->db->query($sql);
215  if ($resql)
216  {
217  if ($this->db->num_rows($resql))
218  {
219  $obj = $this->db->fetch_object($resql);
220 
221  $this->id = $obj->rowid;
222  $this->tms = $this->db->jdate($obj->tms);
223  $this->type = $obj->type;
224  $this->entity = $obj->entity;
225  $this->dateevent = $this->db->jdate($obj->dateevent);
226  $this->description = $obj->description;
227  $this->ip = $obj->ip;
228  $this->user_agent = $obj->user_agent;
229  }
230  $this->db->free($resql);
231 
232  return 1;
233  }
234  else
235  {
236  $this->error="Error ".$this->db->lasterror();
237  return -1;
238  }
239  }
240 
241 
248  function delete($user)
249  {
250  global $conf, $langs;
251 
252  $sql = "DELETE FROM ".MAIN_DB_PREFIX."events";
253  $sql.= " WHERE rowid=".$this->id;
254 
255  dol_syslog(get_class($this)."::delete", LOG_DEBUG);
256  $resql = $this->db->query($sql);
257  if (! $resql)
258  {
259  $this->error="Error ".$this->db->lasterror();
260  return -1;
261  }
262 
263  return 1;
264  }
265 
266 
274  function initAsSpecimen()
275  {
276  $this->id=0;
277 
278  $this->tms=time();
279  $this->type='';
280  $this->dateevent=time();
281  $this->description='This is a specimen event';
282  }
283 
284 }
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="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< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
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.
create($user)
Create in database.
$table_element
Name of table without prefix where object is stored.
update($user=null, $notrigger=0)
Update database.
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
$element
Id that identify managed objects.
type
Definition: viewcat.php:283
Events class.