class_ErrorEvent.inc.php
4.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* @file ErrorEvent.inc.php
* @category freeSN
* @mailto code [at] netz.coop
* @version 0.4.200901
* @link http://netz.coop
*
* @copyright Copyright by netz.coop e.G. 2015
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
class ErrorEvent {
private static $zeilenumbruch = '
';
private static $tab = ' ';
public static $count_handleError =0;
public static $count_handleNotice =0;
public static function handleError($param_typ, $param_notice, $param_file, $param_row, $param_More) {
global $_E_LOGFILE_ERROR;
global $_E_CODEOFFSET;
global $_E_MAILADDR;
global $_E_MAILSUBJECT;
self::$count_handleError++;
// $var_ErrorHandling = CONFIG::getConfig('ErrorHandling');
$var_message = self::mkMessage($param_typ, $param_notice, $param_file, $param_row, $param_More, $_E_CODEOFFSET);
self::logMessage($_E_LOGFILE_ERROR, $var_message);
self::mailToAdmin($_E_MAILADDR, $_E_MAILSUBJECT, $var_message);
self::informUser();
}
public static function handleNotice($param_typ, $param_notice, $param_file, $param_row, $param_More) {
global $_E_LOGFILE_WARNINGNOTICE;
global $_E_CODEOFFSET;
self::$count_handleNotice++;
// $var_ErrorHandling = CONFIG::getConfig('ErrorHandling');
$var_message = self::mkMessage($param_typ, $param_notice, $param_file, $param_row, $param_More, $_E_CODEOFFSET);
self::logMessage($_E_LOGFILE_WARNINGNOTICE, $var_message);
}
private static function mkMessage($param_typ, $param_notice, $param_file, $param_row, $param_More, $param_offset) {
$var_message = self::$zeilenumbruch.'-------------------------------------------------------------'.self::$zeilenumbruch;
if(array_key_exists($param_typ, Error::$ErrorArray)) {
$var_message .= 'Typ:'.self::$tab.Error::$ErrorArray[$param_typ].self::$tab.date('d. m. Y G:i').self::$zeilenumbruch;
} else {
$var_message .= 'Typ:'.self::$tab.$param_typ.self::$tab.date('d. m. Y G:i').self::$zeilenumbruch;
}
$var_message .= 'Notice:'.self::$tab.$param_notice.self::$zeilenumbruch;
$var_message .= 'File:'.self::$tab.$param_file.' (row: '.$param_row.')'.self::$zeilenumbruch;
$var_message .= 'Url:'.self::$tab.urldecode(http_build_query($_GET));
// $var_message .= self::$zeilenumbruch;
$var_message .= self::getCodeFromRow($param_file, $param_row, $param_offset);
// $var_message .= self::$zeilenumbruch.self::$zeilenumbruch;
return $var_message;
}
private static function informUser() {
// D::li('leider ist ein Fehler aufgetreten, der Admin wurde informiert, wir hoffen das er bald behoben ist ;) ');
}
private static function mailToAdmin($param_to, $param_subject, $param_message, $param_logfile=null) {
mail($param_to, $param_subject, $param_message);
}
private static function logMessage($param_logfile, $param_message, $param_MailTo=null) {
@$var_file = fopen($param_logfile, 'a');
// @$var_file = fopen($param_logfile, 'w');
if ($var_file === false) {
if($param_MailTo) {
self::mailToAdmin($param_MailTo, '[The logfile does not exist]', $param_message);
} else {
D::li("The logfile $param_logfile does not exist");
}
} else {
fputs($var_file, $param_message);
fputs($var_file, self::$zeilenumbruch.self::$zeilenumbruch);
}
}
private static function getCodeFromRow($param_file, $param_row, $param_offset=0) {
$var_result = '';
@$var_file = file($param_file);
if($var_file === false) {
$var_result .= 'could not read file'.self::$zeilenumbruch;
$var_result .= 'Systemmessage: '.php_errormsg.self::$zeilenumbruch;
} else {
if(count($var_file) < $param_row) {
$var_result .= 'row not in the file'.self::$zeilenumbruch;
} else {
if($param_row-$param_offset < 0) {
$var_StartCode = 0;
} else {
$var_StartCode = $param_row - $param_offset ;
}
$var_EndCode = $param_row + $param_offset;
$var_result .= self::$zeilenumbruch.'<php>'.self::$zeilenumbruch;
for($i=$var_StartCode; $i < count($var_file);$i++) {
if($i > $var_EndCode) {
break;
}
if($i == $param_row) {
$var_marker = ' => ';
} else {
$var_marker = ' ';
}
if($i-1 >=0) {
$var_result .= $i.$var_marker.self::$tab.$var_file[$i-1];
}
}
$var_result .= '</php>';
}
}
return $var_result;
}
}
?>