35 public $element =
'events';
40 public $table_element =
'events';
97 public $prefix_session;
102 public $authentication_method;
106 public $eventstolog = array(
107 array(
'id'=>
'USER_LOGIN',
'test'=>1),
108 array(
'id'=>
'USER_LOGIN_FAILED',
'test'=>1),
109 array(
'id'=>
'USER_LOGOUT',
'test'=>1),
110 array(
'id'=>
'USER_CREATE',
'test'=>1),
111 array(
'id'=>
'USER_MODIFY',
'test'=>1),
112 array(
'id'=>
'USER_NEW_PASSWORD',
'test'=>1),
113 array(
'id'=>
'USER_ENABLEDISABLE',
'test'=>1),
114 array(
'id'=>
'USER_DELETE',
'test'=>1),
115 array(
'id'=>
'USERGROUP_CREATE',
'test'=>1),
116 array(
'id'=>
'USERGROUP_MODIFY',
'test'=>1),
117 array(
'id'=>
'USERGROUP_DELETE',
'test'=>1),
125 public $fields = array(
126 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-2,
'noteditable'=>1,
'notnull'=> 1,
'index'=>1,
'position'=>1,
'comment'=>
'Id'),
127 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'enabled'=>1,
'visible'=>0,
'notnull'=> 1,
'default'=>1,
'index'=>1,
'position'=>20),
128 'prefix_session'=>array(
'type'=>
'varchar(255)',
'label'=>
'PrefixSession',
'enabled'=>1,
'visible'=>-1,
'notnull'=>-1,
'index'=>0,
'position'=>1000),
129 'user_agent' =>array(
'type'=>
'varchar(255)',
'label'=>
'UserAgent',
'enabled'=>1,
'visible'=>-1,
'notnull'=> 1,
'default'=>0,
'index'=>1,
'position'=>1000),
156 if (empty($this->user_agent)) {
157 $this->user_agent = (empty($_SERVER[
'HTTP_USER_AGENT']) ?
'' : $_SERVER[
'HTTP_USER_AGENT']);
162 $this->error =
'ErrorBadValueForParameterCreateEventDesc';
167 $sql =
"INSERT INTO ".$this->db->prefix().
"events(";
171 $sql .=
"user_agent,";
172 $sql .=
"dateevent,";
174 $sql .=
"description,";
175 $sql .=
"prefix_session";
176 $sql .=
") VALUES (";
177 $sql .=
" '".$this->db->escape($this->
type).
"',";
178 $sql .=
" ".((int) $conf->entity).
",";
180 $sql .=
" ".($this->user_agent ?
"'".$this->db->escape(
dol_trunc($this->user_agent, 250)).
"'" :
'NULL').
",";
181 $sql .=
" '".$this->db->idate($this->dateevent).
"',";
182 $sql .=
" ".($user->id > 0 ? ((int) $user->id) :
'NULL').
",";
184 $sql .=
" '".$this->db->escape(dol_getprefix()).
"'";
187 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
188 $resql = $this->db->query($sql);
190 $this->
id = $this->db->last_insert_id($this->db->prefix().
"events");
193 $this->error =
"Error ".$this->db->lasterror();
206 public function update($user =
null, $notrigger = 0)
209 $this->
id = (int) $this->
id;
217 $sql =
"UPDATE ".$this->db->prefix().
"events SET";
218 $sql .=
" type='".$this->db->escape($this->
type).
"',";
219 $sql .=
" dateevent='".$this->db->idate($this->dateevent).
"',";
220 $sql .=
" description='".$this->db->escape($this->
description).
"'";
221 $sql .=
" WHERE rowid=".((int) $this->
id);
223 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
224 $resql = $this->db->query($sql);
226 $this->error =
"Error ".$this->db->lasterror();
240 public function fetch($id, $user =
null)
246 $sql .=
" t.entity,";
247 $sql .=
" t.dateevent,";
248 $sql .=
" t.description,";
250 $sql .=
" t.user_agent,";
251 $sql .=
" t.prefix_session";
252 $sql .=
" FROM ".$this->db->prefix().
"events as t";
253 $sql .=
" WHERE t.rowid = ".((int) $id);
255 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
256 $resql = $this->db->query($sql);
258 if ($this->db->num_rows($resql)) {
259 $obj = $this->db->fetch_object($resql);
261 $this->
id = $obj->rowid;
262 $this->tms = $this->db->jdate($obj->tms);
263 $this->
type = $obj->type;
264 $this->entity = $obj->entity;
265 $this->dateevent = $this->db->jdate($obj->dateevent);
267 $this->ip = $obj->ip;
268 $this->user_agent = $obj->user_agent;
269 $this->prefix_session = $obj->prefix_session;
271 $this->db->free($resql);
275 $this->error =
"Error ".$this->db->lasterror();
287 public function delete($user)
289 $sql =
"DELETE FROM ".$this->db->prefix().
"events";
290 $sql .=
" WHERE rowid=".((int) $this->
id);
292 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
293 $resql = $this->db->query($sql);
295 $this->error =
"Error ".$this->db->lasterror();
316 $this->dateevent = time();
318 $this->ip =
'1.2.3.4';
319 $this->user_agent =
'Mozilla specimen User Agent X.Y';
320 $this->prefix_session = dol_getprefix();
initAsSpecimen()
Initialise an instance with random values.
__construct($db)
Constructor.
create($user)
Create in database.
fetch($id, $user=null)
Load object in memory from database.
update($user=null, $notrigger=0)
Update database.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
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.
getUserRemoteIP()
Return the IP of remote user.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type