1 | <?php |
---|
2 | /* |
---|
3 | This ddt library is released under the terms of the HTMLArea license. |
---|
4 | See license.txt that is shipped with Xinha. |
---|
5 | */ |
---|
6 | |
---|
7 | // must be included after the configuration has been loaded. |
---|
8 | |
---|
9 | if ( ! defined( "IM_CONFIG_LOADED" ) ) |
---|
10 | die( "sorry" ); |
---|
11 | |
---|
12 | /** |
---|
13 | * Debug and Error Message functions. |
---|
14 | * |
---|
15 | * These functions implement a procedural version of the formVista DDT debug |
---|
16 | * message system. |
---|
17 | * |
---|
18 | * @package formVista |
---|
19 | * @subpackage lib |
---|
20 | * @copyright DTLink, LLC 2005 |
---|
21 | * @author Yermo Lamers |
---|
22 | * @see http://www.formvista.com/contact.html |
---|
23 | */ |
---|
24 | |
---|
25 | // REVISION HISTORY: |
---|
26 | // |
---|
27 | // 26 Jan 2001 YmL: |
---|
28 | // . initial revision |
---|
29 | // |
---|
30 | // 2002-06-19 YmL: |
---|
31 | // . added logging debug and error messages to a file. |
---|
32 | // |
---|
33 | // 2004-02-06 YmL: |
---|
34 | // . added a newline to generated messages. |
---|
35 | // |
---|
36 | // 2005-01-09 YmL: |
---|
37 | // . now checks global $fvDEBUG[ "logfile" ] setting for |
---|
38 | // logfile to output to. |
---|
39 | // . dumping to file has not been combined into a dumpmsg |
---|
40 | // method. |
---|
41 | // |
---|
42 | // 2005-02-25 YmL: |
---|
43 | // . added _error() support for cmdLine programs. |
---|
44 | // |
---|
45 | // 2005-03-20 YmL: |
---|
46 | // . changed license for this file to HTMLArea from RPL. |
---|
47 | // . quick hack to repurpose for Xinha. |
---|
48 | // |
---|
49 | // ------------------------------------------------------- |
---|
50 | |
---|
51 | /** |
---|
52 | * dumps message to stdout or log file depending upon global. |
---|
53 | * |
---|
54 | * checks $fvDEBUG["logfile"] global for name of file to dump |
---|
55 | * messages to. Opens the file once. |
---|
56 | */ |
---|
57 | |
---|
58 | function dumpmsg( $msgline ) |
---|
59 | { |
---|
60 | |
---|
61 | global $fvDEBUG; |
---|
62 | |
---|
63 | if ( @$fvDEBUG[ "logfile" ] != NULL ) |
---|
64 | { |
---|
65 | |
---|
66 | // only open the file once and store the handle in the global |
---|
67 | // fvDEBUG array .. for now. |
---|
68 | |
---|
69 | if ( @$fvDEBUG[ "logfile_fp" ] == NULL ) |
---|
70 | { |
---|
71 | |
---|
72 | // we clear out the debug file on each run. |
---|
73 | |
---|
74 | if (( $fvDEBUG[ "logfile_fp" ] = fopen( $fvDEBUG[ "logfile" ], "a" )) == NULL ) |
---|
75 | { |
---|
76 | die( "ddt(): unable to open debug log" ); |
---|
77 | return false ; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | fputs( $fvDEBUG[ "logfile_fp" ], "$msgline" ); |
---|
82 | fflush( $fvDEBUG[ "logfile_fp" ] ); |
---|
83 | |
---|
84 | } |
---|
85 | else |
---|
86 | { |
---|
87 | echo $msgline; |
---|
88 | } |
---|
89 | |
---|
90 | } // end of dumpmsg. |
---|
91 | |
---|
92 | /** |
---|
93 | * displays a formatted debugging message. |
---|
94 | * |
---|
95 | * If ddtOn() was called, outputs a formatted debugging message. |
---|
96 | * |
---|
97 | * @param string $file filename, usually __FILE__ |
---|
98 | * @param string $line line number in file, usually __LINE__ |
---|
99 | * @param string $msg debugging message to display |
---|
100 | */ |
---|
101 | |
---|
102 | function _ddt( $file, $line, $msg ) |
---|
103 | { |
---|
104 | |
---|
105 | global $_DDT; |
---|
106 | global $_DDT_DEBUG_LOG; |
---|
107 | global $_DDT_CMDLINE; |
---|
108 | |
---|
109 | $basename = basename( $file ); |
---|
110 | |
---|
111 | if ( @$_DDT == "yes" ) |
---|
112 | { |
---|
113 | |
---|
114 | if ( @$_DDT_CMDLINE == "yes" ) |
---|
115 | { |
---|
116 | dumpmsg( basename( $file ) . ":$line: $msg \n" ); |
---|
117 | flush(); |
---|
118 | |
---|
119 | } |
---|
120 | else |
---|
121 | { |
---|
122 | dumpmsg( "<p>$basename:$line: $msg</p>\n" ); |
---|
123 | } |
---|
124 | } |
---|
125 | |
---|
126 | } // end of _ddt |
---|
127 | |
---|
128 | /** |
---|
129 | * displays a formatted dump of an associative array. |
---|
130 | * |
---|
131 | * If ddtOn() was called, outputs a formatted debugging message showing |
---|
132 | * contents of array. |
---|
133 | * |
---|
134 | * @param string $file filename, usually __FILE__ |
---|
135 | * @param string $line line number in file, usually __LINE__ |
---|
136 | * @param string $msg debugging message to display |
---|
137 | * @param array $array_var array to dump. |
---|
138 | */ |
---|
139 | |
---|
140 | function _ddtArray( $file, $line, $msg, $array_var ) |
---|
141 | { |
---|
142 | |
---|
143 | global $_DDT; |
---|
144 | |
---|
145 | if ( $_DDT == "yes" ) |
---|
146 | { |
---|
147 | |
---|
148 | dumpmsg( "<h2>$file:$line: $msg</h2>" ); |
---|
149 | |
---|
150 | foreach ( $array_var as $name => $value ) |
---|
151 | { |
---|
152 | dumpmsg( "<p><b>$name</b> => <b>$value</b>\n" ); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | } // end of _ddtArray |
---|
157 | |
---|
158 | // ----------------------------------------------------------------- |
---|
159 | |
---|
160 | /** |
---|
161 | * Central Error Function. |
---|
162 | * |
---|
163 | * Displays a formatted error message to the user. |
---|
164 | * If the global _DDT_ERROR_LOG is set the error message is dumped |
---|
165 | * to that file instead of being displayed to the user. |
---|
166 | */ |
---|
167 | |
---|
168 | function _error( $file, $line, $msg ) |
---|
169 | { |
---|
170 | |
---|
171 | global $_DDT_ERROR_LOG; |
---|
172 | global $_DDT_CMDLINE; |
---|
173 | |
---|
174 | if ( @$_DDT_ERROR_LOG == NULL ) |
---|
175 | { |
---|
176 | |
---|
177 | if ( @$_DDT_CMDLINE == "yes" ) |
---|
178 | { |
---|
179 | echo basename($file) . ":$line: $msg\n"; |
---|
180 | } |
---|
181 | else |
---|
182 | { |
---|
183 | echo "<h2>$file:$line: $msg</h2>"; |
---|
184 | } |
---|
185 | } |
---|
186 | else |
---|
187 | { |
---|
188 | |
---|
189 | if (( $fp = fopen( $_DDT_ERROR_LOG, "a" )) != NULL ) |
---|
190 | { |
---|
191 | fputs( $fp, date("D M j G:i:s T Y") . " - $file:$line: $msg\n" ); |
---|
192 | fclose( $fp ); |
---|
193 | } |
---|
194 | |
---|
195 | } |
---|
196 | |
---|
197 | } // end of _error |
---|
198 | |
---|
199 | // ---------------------------------------------------------------------- |
---|
200 | |
---|
201 | function errorEcho( $title, $field ) |
---|
202 | { |
---|
203 | |
---|
204 | global $error_msg; |
---|
205 | |
---|
206 | if ( $error_msg[ $field ] != "" ) |
---|
207 | { |
---|
208 | |
---|
209 | echo "<FONT SIZE=\"+2\" COLOR=\"RED\">$title</FONT>"; |
---|
210 | |
---|
211 | } |
---|
212 | else |
---|
213 | { |
---|
214 | |
---|
215 | echo $title; |
---|
216 | |
---|
217 | } |
---|
218 | |
---|
219 | } // end of errorEcho |
---|
220 | |
---|
221 | /** |
---|
222 | * turns on procedural debugging. |
---|
223 | * |
---|
224 | * Causes _ddt() calls to display debugging messages. |
---|
225 | */ |
---|
226 | |
---|
227 | function _ddtOn() |
---|
228 | { |
---|
229 | |
---|
230 | global $_DDT; |
---|
231 | |
---|
232 | $_DDT = "yes"; |
---|
233 | |
---|
234 | } |
---|
235 | |
---|
236 | /** |
---|
237 | * set error message destination. |
---|
238 | * |
---|
239 | * sets the destination for error messages. |
---|
240 | * |
---|
241 | * @param string $file full path to errorlog. |
---|
242 | */ |
---|
243 | |
---|
244 | function _setErrorLog( $errorLog ) |
---|
245 | { |
---|
246 | |
---|
247 | global $_DDT_ERROR_LOG; |
---|
248 | |
---|
249 | $_DDT_ERROR_LOG = $errorLog; |
---|
250 | |
---|
251 | } |
---|
252 | |
---|
253 | /** |
---|
254 | * set output file for debugging messages. |
---|
255 | * |
---|
256 | * sets the destination file for debugging messages. |
---|
257 | * |
---|
258 | * @param string $file full path to debuglog. |
---|
259 | */ |
---|
260 | |
---|
261 | function _setDebugLog( $debugLog ) |
---|
262 | { |
---|
263 | |
---|
264 | global $fvDEBUG; |
---|
265 | |
---|
266 | $fvDEBUG[ "logfile" ] = $debugLog; |
---|
267 | |
---|
268 | } |
---|
269 | |
---|
270 | /** |
---|
271 | * set debugging output style to command line. |
---|
272 | * |
---|
273 | * tells ddt to format debugging messages for a |
---|
274 | * command line program. |
---|
275 | */ |
---|
276 | |
---|
277 | function _ddtSetCmdLine() |
---|
278 | { |
---|
279 | |
---|
280 | global $_DDT_CMDLINE; |
---|
281 | |
---|
282 | $_DDT_CMDLINE = "yes"; |
---|
283 | |
---|
284 | } |
---|
285 | |
---|
286 | // END |
---|
287 | |
---|
288 | ?> |
---|