droy | 3e7f3a8 | 2007-11-29 19:35:51 +0000 | [diff] [blame] | 1 | <?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 | |
| 13 | class 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 = ""; |
atoulme | 3e5e934 | 2009-01-23 17:34:30 +0000 | [diff] [blame] | 46 | global $User, $dbh; |
droy | 3e7f3a8 | 2007-11-29 19:35:51 +0000 | [diff] [blame] | 47 | |
| 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, |
atoulme | 3e5e934 | 2009-01-23 17:34:30 +0000 | [diff] [blame] | 57 | 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) . ", |
droy | 3e7f3a8 | 2007-11-29 19:35:51 +0000 | [diff] [blame] | 62 | created_on = NOW()"; |
| 63 | |
kitlo | 2c8d8a9 | 2018-04-19 13:25:09 -0400 | [diff] [blame] | 64 | mysqli_query($dbh, $sql); |
kitlo | 6c07cfa | 2018-05-11 01:46:03 -0400 | [diff] [blame^] | 65 | if(mysqli_error() != "") { |
droy | 3e7f3a8 | 2007-11-29 19:35:51 +0000 | [diff] [blame] | 66 | echo "An unknown database error has occurred while logging information. Please contact the System Administrator."; |
kitlo | 6c07cfa | 2018-05-11 01:46:03 -0400 | [diff] [blame^] | 67 | echo mysqli_error(); |
| 68 | $rValue = "MYSQL: " . mysqli_error(); |
droy | 3e7f3a8 | 2007-11-29 19:35:51 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | else { |
| 72 | $rValue = "CRIT: Missing critical information for logging"; |
| 73 | } |
| 74 | |
| 75 | return $rValue; |
| 76 | } |
| 77 | } |
| 78 | ?> |