3 $messages = array(); // container for system messages
4 $before_box = ''; // temporary container for output html data before error box
7 E_USER_ERROR => array('bg'=>'#ffcccc', 'txt'=>'#dd2200', 'bd'=>'#cc3300'),
8 E_USER_WARNING => array('bg'=>'#ffdd33', 'txt'=>'#ff5500', 'bd'=>'#ff9900'),
9 E_USER_NOTICE => array('bg'=>'#ccffcc', 'txt'=>'#007700', 'bd'=>'#33cc00'));
11 //-----------------------------------------------------------------------------
12 // Error handler - collects all php/user messages for
13 // display in message box.
15 function error_handler($errno, $errstr, $file, $line) {
18 // error_reporting==0 when messages are set off with @
19 if ($errno & error_reporting()) {
20 $messages[] = array($errno, $errstr, $file, $line);
24 //------------------------------------------------------------------------------
25 // Formats system messages before insert them into message <div>
26 // FIX center is unused now
27 function fmt_errors($center=true) {
28 global $messages, $msg_colors;
30 $type = E_USER_NOTICE;
32 if (count($messages)) {
34 foreach($messages as $msg) {
35 if ($msg[0]>$type) continue;
38 if ($msg[0] == E_USER_WARNING) {
39 $type = E_USER_WARNING; // user warnings
40 $content = ''; // clean notices when we have errors
42 $type = E_USER_ERROR; // php or user errors
43 if($type == E_USER_WARNING)
44 $content = ''; // clean other messages
48 $c = $msg_colors[$type];
49 if ($msg[0] < E_USER_ERROR && $msg[2] != null)
50 $str .= ' '._('in file').': '.$msg[2].' '._('at line ').$msg[3];
52 $content .= "<tr><td " . ($center?"align='center' ":"").
53 " width='100%' bgcolor='{$c['bg']}'><font color='{$c['txt']}'>"
54 .$str."</font></td></tr>";
57 $str = "<center><table border='1' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='{$c['bd']}' width='98%'>"
58 . $content . "</table></center><br>\n";
66 //-----------------------------------------------------------------------------
67 // Error box <div> element.
69 function error_box() {
72 echo "<div id='msgbox'>";
73 $before_box = ob_get_clean(); // save html content before error box
74 // Necessary restart instead of get_contents/clean calls due to a bug in php 4.3.2
75 register_shutdown_function('ob_end_flush');
76 ob_start('output_html');
80 function display_db_error($msg, $sql_statement=null, $exit=true)
83 $db_error = db_error_no();
85 $str = "<span class='errortext'><b>" . _("DATABASE ERROR :") . "</b> $msg</span><br>";
89 $str .= "error code : " . $db_error . "<br>";
90 $str .= "error message : " . db_error_msg($db) . "<br>";
95 $str .= "sql that failed was : " . $sql_statement . "<br>";
100 trigger_error($str, E_USER_ERROR);
106 function frindly_db_error($db_error)
108 global $db_duplicate_error_code;
110 if ($db_error == $db_duplicate_error_code)
112 display_error(_("The entered information is a duplicate. Please go back and enter different values."));
119 function check_db_error($msg, $sql_statement, $exit_if_error=true, $rollback_if_error=true)
122 $db_error = db_error_no();
127 if (!frindly_db_error($db_error))
128 display_db_error($msg, $sql_statement, false);
130 if ($rollback_if_error)
132 $rollback_result = db_query("rollback","could not rollback");