class_mcReport.inc.php
4.93 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/**
* @filesource class_mcReport.inc.php
* @category mcClasses
* @author f@mensch.coop
* @since 2010-12-20
*/
class mcReport {
private static $Stack = array();
protected static function add(mcReport $param_obj) {
if(!array_key_exists(get_class($param_obj), self::$Stack)) {
self::$Stack[get_class($param_obj)] = array();
}
self::$Stack[get_class($param_obj)][] = $param_obj;
}
/**
*
* @param array $param_config
*/
public static function distribute(array $param_config=null) {
if($param_config !== null) {
//D::show($_SERVER);
foreach($param_config as $kindOfReport => $whatToDo) {
if(array_key_exists($kindOfReport, self::$Stack)) {
$GENERAL_TEXT = mcCONST::LINEBREAK.date('d.m.Y G:i:s').mcCONST::LINEBREAK;
$GENERAL_TEXT .= 'File: '.mcCONST::TAB.$_SERVER['SCRIPT_NAME'].mcCONST::LINEBREAK;
if(!empty ($_GET)) {
$GENERAL_TEXT .= 'Url: '.mcCONST::TAB.urldecode(http_build_query($_GET)).mcCONST::LINEBREAK;
}
$GENERAL_TEXT .= 'PHP: '.mcCONST::TAB.PHP_VERSION.' ('.PHP_OS.')'.mcCONST::LINEBREAK;
$GENERAL_TEXT .= 'User: '.mcCONST::TAB.$_SERVER['HTTP_USER_AGENT'].mcCONST::LINEBREAK;
$GENERAL_TEXT .= mcCONST::LINEBREAK;
foreach($whatToDo as $kindOfToDo => $params) {
if($kindOfToDo == 'toScreen' ) {
if(!empty ($params) && array_key_exists('text', $params)) {
self::informUser($params['text']);
}
} else if($kindOfToDo == 'toFile') {
if(array_key_exists('file', $params)) {
$Text = $GENERAL_TEXT;
$Text .= 'KindOf: '.$kindOfReport.' ('.count(self::$Stack[$kindOfReport]).')'.mcCONST::LINEBREAK.mcCONST::LINEBREAK;
$Text .= self::getTextMessageFrom($kindOfReport);
if(array_key_exists('writemode', $params)) {
$writemode = $params['writemode'];
} else {
$writemode = 'a';
}
mcFile::write($params['file'], $Text, $writemode);
}
} else if($kindOfToDo == 'toMail') {
if(array_key_exists('subject', $params)) {
$MailSubject = $params['subject'];
} else {
$MailSubject = '';
}
if(array_key_exists('mail', $params)) {
$MailAdr = $params['mail'];
} else {
break;
}
$MailMessage = $GENERAL_TEXT;
$MailMessage .= self::getTextMessageFrom($kindOfReport);
mcMail::mail($MailAdr, $MailSubject, $MailMessage);
} else {
D::li('kind of mcReport ('.$kindOfToDo.') not supported');
}
}
}
}
}
}
private $Values = array();
protected function setValues(array $param_values) {
$this->Values = $param_values;
}
protected function getDOMElement(DOMDocument $DOMDocument) {
$DOMElement = $DOMDocument->createElement(get_class($this));
foreach($this->Values as $key => $value){
$DOMElement->setAttribute($key,$value);
}
return $DOMElement;
}
private static $TextMessageReports = array();
private static function getTextMessageFrom($param_KindOfReport) {
if(array_key_exists($param_KindOfReport, self::$Stack)) {
if(!array_key_exists($param_KindOfReport, self::$TextMessageReports)) {
self::$TextMessageReports[$param_KindOfReport] = '';
foreach(self::$Stack[$param_KindOfReport] as $mcReportObj) {
self::$TextMessageReports[$param_KindOfReport] .= $mcReportObj->getTextMessage();
}
}
return self::$TextMessageReports[$param_KindOfReport];
} else {
return false;
}
}
protected $TextMessage = null;
protected function getTextMessage() {
if(is_null($this->TextMessage)) {
$this->TextMessage = get_class($this);
}
return $this->TextMessage;
}
protected static function informUser($param_string = null) {
if(is_null($param_string)) {
$param_string = 'leider ist ein Fehler aufgetreten, der Admin wurde informiert, wir hoffen das er bald behoben ist ;) ';
}
/**
* @todo Achtung wie wird genau ein User informiert!!!!
*/
Error::newError('UserError',$param_string,'256');
}
protected static function getCodeFromRow($param_errfile, $param_errline, $param_offset=0) {
$var_result = '';
@$var_file = file($param_errfile);
if($var_file === false) {
$var_result .= 'could not read file'.mcCONST::LINEBREAK;
} else {
if(count($var_file) < $param_errline) {
$var_result .= 'row not in the file'.mcCONST::LINEBREAK;
} else {
if($param_errline-$param_offset < 0) {
$var_StartCode = 0;
} else {
$var_StartCode = $param_errline - $param_offset ;
}
$var_EndCode = $param_errline + $param_offset;
$var_result .= mcCONST::LINEBREAK.'<php>'.mcCONST::LINEBREAK;
for($i=$var_StartCode; $i < count($var_file);$i++) {
if($i > $var_EndCode) {
break;
}
if($i == $param_errline) {
$var_marker = ' => ';
} else {
$var_marker = ' ';
}
if($i-1 >=0) {
$var_result .= $i.$var_marker.mcCONST::TAB.$var_file[$i-1];
}
}
$var_result .= '</php>';
}
}
return $var_result;
}
}
?>