LEPTON CMS 7.0.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
lepton_logging.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
25{
27 public string $log_table = '';
28 public string $logged = '';
29 public array $secure_data = [];
30 public int $user_id = 0;
31 public string $username = '';
32 public array $sUploadMessages = []; // php upload messages for superglobal $_FiLES
33
34 public static $instance;
35
42 public static function getInstance()
43 {
44 if (null === static::$instance)
45 {
46 static::$instance = new static();
47 static::$instance->initialize();
48 }
49
50 return static::$instance;
51 }
52
53 public function initialize()
54 {
55
56 $this->database = LEPTON_database::getInstance();
57 $this->secure_data = array('username','action','log_text');
58 $this->log_table = TABLE_PREFIX.'log';
59 if(!isset($_SESSION['USER_ID']))
60 {
61 $this->user_id = -99;
62 $this->username = 'LEPTON cms';
63 }
64 else
65 {
66 $this->user_id = $_SESSION['USER_ID'];
67 $this->username = $_SESSION['USERNAME'];
68 }
69
70 date_default_timezone_set('Europe/London'); // mysql always uses UTC/0 in standard
71 $this->logged = date('Y-m-d H:i:s',time());
72
73 global $MESSAGE;
74 $this->sUploadMessages = [
75 0 => $MESSAGE['UPLOAD_ERR_OK'],
76 1 => $MESSAGE['UPLOAD_ERR_INI_SIZE'],
77 2 => $MESSAGE['UPLOAD_ERR_FORM_SIZE'],
78 3 => $MESSAGE['UPLOAD_ERR_PARTIAL'],
79 4 => $MESSAGE['UPLOAD_ERR_NO_FILE'],
80 5 => $MESSAGE['unknown_upload_error'],
81 6 => $MESSAGE['UPLOAD_ERR_NO_TMP_DIR'],
82 7 => $MESSAGE['UPLOAD_ERR_CANT_WRITE'],
83 8 => $MESSAGE['UPLOAD_ERR_EXTENSION'],
84 ];
85
86 }
87
88
99 public function insert_entry( $action = 0, $log_text = 0 )
100 {
101
102 $all_values = array (
103 'id'=> NULL,
104 'logged' => $this->logged,
105 'user_id' => $this->user_id,
106 'username' => $this->username,
107 'action' => $action,
108 'log_text' => $log_text
109 );
110
111 $result = $this->database->build_and_execute( 'INSERT', $this->log_table, $all_values, '');
112
113 if($result === false) {
114 echo LEPTON_tools::display($this->database->get_error(),'pre','ui red message');
115 }
116
117 $latest_id = $this->database->get_one("SELECT LAST_INSERT_ID() FROM ".$this->log_table." ");
118 if($latest_id > 99900)
119 {
120 echo LEPTON_tools::display('Please contact your admin: log-table is running full','pre','ui red message');
121 }
122
123 return $result;
124 }
125
126
134 public function display_entry( $start = 1, $end = 100000 )
135 {
136
137 $entries = array();
138 $this->database->execute_query(
139 "SELECT * FROM ".$this->log_table." WHERE id BETWEEN ".$start." AND ".$end." ",
140 true,
141 $entries,
142 true
143 );
144
145 return $entries;
146 }
147
158 public function insert_secure_entry( $action = 0, $log_text = 0 )
159 {
160 $all_values = array (
161 'id'=> NULL,
162 'logged' => $this->logged,
163 'user_id' => $this->user_id,
164 'username' => $this->username,
165 'action' => $action,
166 'log_text' => $log_text
167 );
168
169 $result = $this->database->secure_build_and_execute( 'INSERT', $this->log_table, $all_values, '', $this->secure_data);
170
171 if($result === false) {
172 echo LEPTON_tools::display($this->database->get_error(),'pre','ui red message');
173 }
174
175 $latest_id = $this->database->get_one("SELECT LAST_INSERT_ID() FROM ".$this->log_table." ");
176 if($latest_id > 99900) {
177 echo LEPTON_tools::display('Please contact your admin: log-table is running full','pre','ui red message');
178 }
179
180 return $result;
181 }
182
190 public function display_secure_entry( $start = 1, $end = 100000 )
191 {
192
193 $entries = array();
194 $this->database->secure_execute_query(
195 "SELECT * FROM ".$this->log_table." WHERE id BETWEEN ".$start." AND ".$end." ",
196 true,
197 $entries,
198 true,
199 $this->secure_data
200 );
201
202 return $entries;
203 }
204
212 public function check_entry()
213 {
214 $temp = array();
215 $this->database->execute_query(
216 "SELECT * FROM ".$this->log_table,
217 true,
218 $temp,
219 true
220 );
221
222 $entries = array();
223 foreach($temp as $entry)
224 {
225 if($entry['logged'] != $entry['check'] )
226 {
227 $entries[] = array(
228 'id' => $entry['id'],
229 'user_id' => $entry['user_id'],
230 'logged' => $entry['logged'],
231 'check' => $entry['check'],
232 'comment' => $entry['comment']
233 );
234 }
235 }
236 return $entries;
237 }
238}
$temp
static getInstance(array &$settings=[])
display_secure_entry( $start=1, $end=100000)
LEPTON_database $database
display_entry( $start=1, $end=100000)
insert_secure_entry( $action=0, $log_text=0)
insert_entry( $action=0, $log_text=0)
static display(mixed $something_to_display="", string $tag="pre", string|null $css_class=null)