37 public $element =
'events';
42 public $table_element =
'events';
102 public $prefix_session;
107 public $authentication_method;
113 public $eventstolog = array(
114 array(
'id' =>
'USER_LOGIN',
'test' => 1),
115 array(
'id' =>
'USER_LOGIN_FAILED',
'test' => 1),
116 array(
'id' =>
'USER_LOGOUT',
'test' => 1),
117 array(
'id' =>
'USER_CREATE',
'test' => 1),
118 array(
'id' =>
'USER_MODIFY',
'test' => 1),
119 array(
'id' =>
'USER_NEW_PASSWORD',
'test' => 1),
120 array(
'id' =>
'USER_ENABLEDISABLE',
'test' => 1),
121 array(
'id' =>
'USER_DELETE',
'test' => 1),
122 array(
'id' =>
'USERGROUP_CREATE',
'test' => 1),
123 array(
'id' =>
'USERGROUP_MODIFY',
'test' => 1),
124 array(
'id' =>
'USERGROUP_DELETE',
'test' => 1),
132 public $fields = array(
133 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -2,
'noteditable' => 1,
'notnull' => 1,
'index' => 1,
'position' => 1,
'comment' =>
'Id'),
134 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'default' =>
'1',
'index' => 1,
'position' => 20),
135 'prefix_session' => array(
'type' =>
'varchar(255)',
'label' =>
'PrefixSession',
'enabled' => 1,
'visible' => -1,
'notnull' => -1,
'index' => 0,
'position' => 1000),
136 'user_agent' => array(
'type' =>
'varchar(255)',
'label' =>
'UserAgent',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'default' =>
'0',
'index' => 1,
'position' => 1000),
163 if (empty($this->user_agent)) {
164 $this->user_agent = (empty($_SERVER[
'HTTP_USER_AGENT']) ?
'' : $_SERVER[
'HTTP_USER_AGENT']);
169 $this->error =
'ErrorBadValueForParameterCreateEventDesc';
174 $sql =
"INSERT INTO ".$this->db->prefix().
"events(";
178 $sql .=
"user_agent,";
179 $sql .=
"dateevent,";
181 $sql .=
"description,";
182 $sql .=
"prefix_session";
183 $sql .=
") VALUES (";
184 $sql .=
" '".$this->db->escape($this->
type).
"',";
185 $sql .=
" ".((int) $conf->entity).
",";
187 $sql .=
" ".($this->user_agent ?
"'".$this->db->escape(
dol_trunc($this->user_agent, 250)).
"'" :
'NULL').
",";
188 $sql .=
" '".$this->db->idate($this->dateevent).
"',";
189 $sql .=
" ".($user->id > 0 ? ((int) $user->id) :
'NULL').
",";
191 $sql .=
" '".$this->db->escape(dol_getprefix()).
"'";
194 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
195 $resql = $this->db->query($sql);
197 $this->
id = $this->db->last_insert_id($this->db->prefix().
"events");
200 $this->error =
"Error ".$this->db->lasterror();
213 public function update($user =
null, $notrigger = 0)
216 $this->
id = (int) $this->
id;
224 $sql =
"UPDATE ".$this->db->prefix().
"events SET";
225 $sql .=
" type='".$this->db->escape($this->
type).
"',";
226 $sql .=
" dateevent='".$this->db->idate($this->dateevent).
"',";
227 $sql .=
" description='".$this->db->escape($this->
description).
"'";
228 $sql .=
" WHERE rowid=".((int) $this->
id);
230 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
231 $resql = $this->db->query($sql);
233 $this->error =
"Error ".$this->db->lasterror();
247 public function fetch($id, $user =
null)
253 $sql .=
" t.entity,";
254 $sql .=
" t.dateevent,";
255 $sql .=
" t.description,";
257 $sql .=
" t.user_agent,";
258 $sql .=
" t.prefix_session";
259 $sql .=
" FROM ".$this->db->prefix().
"events as t";
260 $sql .=
" WHERE t.rowid = ".((int) $id);
262 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
263 $resql = $this->db->query($sql);
265 if ($this->db->num_rows($resql)) {
266 $obj = $this->db->fetch_object($resql);
268 $this->
id = $obj->rowid;
269 $this->tms = $this->db->jdate($obj->tms);
270 $this->
type = $obj->type;
271 $this->entity = $obj->entity;
272 $this->dateevent = $this->db->jdate($obj->dateevent);
274 $this->ip = $obj->ip;
275 $this->user_agent = $obj->user_agent;
276 $this->prefix_session = $obj->prefix_session;
278 $this->db->free($resql);
282 $this->error =
"Error ".$this->db->lasterror();
294 public function delete($user)
296 $sql =
"DELETE FROM ".$this->db->prefix().
"events";
297 $sql .=
" WHERE rowid=".((int) $this->
id);
299 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
300 $resql = $this->db->query($sql);
302 $this->error =
"Error ".$this->db->lasterror();
323 $this->dateevent = time();
325 $this->ip =
'1.2.3.4';
326 $this->user_agent =
'Mozilla specimen User Agent X.Y';
327 $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