blob: d0f1480276b6abd5704829d837dd919aa2f38240 [file] [log] [blame]
droy3e7f3a82007-11-29 19:35:51 +00001<?php
2/*******************************************************************************
3 * Copyright (c) 2007 Eclipse Foundation and others.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Eclipse Foundation - initial API and implementation
11*******************************************************************************/
12
13class EventLog {
14
15 public $event_id = 0;
16 public $table_name = '';
17 public $key_name = '';
18 public $key_value = '';
19 public $action = '';
20 public $userid = 0;
21 public $created_on = '';
22
23 /**
24 * Default constructor
25 *
26 * @param String $_table_name
27 * @param String $_key_name
28 * @param String $_key_value
29 * @param String $_action
30 * @return EventLog
31 */
32 function EventLog ($_table_name, $_key_name, $_key_value, $_action) {
33 $this->table_name = $_table_name;
34 $this->key_name = $_key_name;
35 $this->key_value = $_key_value;
36 $this->action = $_action;
37 }
38
39 /**
40 * add event log entry to the table
41 *
42 * @return String Error message (if any)
43 */
44 function add() {
45 $rValue = "";
atoulme3e5e9342009-01-23 17:34:30 +000046 global $User, $dbh;
droy3e7f3a82007-11-29 19:35:51 +000047
48 # remove anything after a space
49 $has_space = strpos($this->action, ' ');
50 if($has_space !== FALSE && $has_space > 0) {
51 $this->action = substr($this->action, 0, $has_space);
52 }
53
54 if($this->table_name != "" && $this->key_name != "" && $this->key_value != "" && $this->action != "") {
55 $sql = "INSERT INTO event_log SET
56 event_id = NULL,
atoulme3e5e9342009-01-23 17:34:30 +000057 table_name = " . returnQuotedString(sqlSanitize($this->table_name, $dbh)) . ",
58 key_name = " . returnQuotedString(sqlSanitize($this->key_name, $dbh)) . ",
59 key_value = " . returnQuotedString(sqlSanitize($this->key_value, $dbh)) . ",
60 action = " . returnQuotedString(sqlSanitize($this->action, $dbh)) . ",
61 userid = " . sqlSanitize($User->userid, $dbh) . ",
droy3e7f3a82007-11-29 19:35:51 +000062 created_on = NOW()";
63
kitlo2c8d8a92018-04-19 13:25:09 -040064 mysqli_query($dbh, $sql);
kitlo6c07cfa2018-05-11 01:46:03 -040065 if(mysqli_error() != "") {
droy3e7f3a82007-11-29 19:35:51 +000066 echo "An unknown database error has occurred while logging information. Please contact the System Administrator.";
kitlo6c07cfa2018-05-11 01:46:03 -040067 echo mysqli_error();
68 $rValue = "MYSQL: " . mysqli_error();
droy3e7f3a82007-11-29 19:35:51 +000069 }
70 }
71 else {
72 $rValue = "CRIT: Missing critical information for logging";
73 }
74
75 return $rValue;
76 }
77}
78?>