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'=>'#ffcccc', 'txt'=>'#dd2200', 'bd'=>'#cc3300'),
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;
36 if ($msg[0]<$type && $type>E_USER_ERROR) {
37 $content = ''; // clean notices when we have errors
38 $type = E_USER_ERROR; // php or user errors
41 $c = $msg_colors[$type];
42 if ($msg[0]<E_USER_ERROR && $msg[2]!=null)
43 $str .= ' '._('in file').': '.$msg[2].' '._('at line ').$msg[3];
44 $content .= "<tr><td " . ($center?"align='center' ":"").
45 " width='100%' bgcolor='{$c['bg']}'><font color='{$c['txt']}'>"
46 .$str."</font></td></tr>";
49 $str = "<center><table border='1' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='{$c['bd']}' width='98%'>"
50 . $content . "</table></center><br>\n";
58 //-----------------------------------------------------------------------------
59 // Error box <div> element.
61 function error_box() {
64 echo "<div id='msgbox'>";
65 $before_box = ob_get_clean(); // save html content before error box
66 // Necessary restart instead of get_contents/clean calls due to a bug in php 4.3.2
67 register_shutdown_function('ob_end_flush');
68 ob_start('output_html');
72 function display_db_error($msg, $sql_statement=null, $exit=true)
75 $db_error = db_error_no();
77 $str = "<span class='errortext'><b>" . _("DATABASE ERROR :") . "</b> $msg</span><br>";
81 $str .= "error code : " . $db_error . "<br>";
82 $str .= "error message : " . db_error_msg($db) . "<br>";
87 $str .= "sql that failed was : " . $sql_statement . "<br>";
92 trigger_error($str, E_USER_ERROR);
98 function frindly_db_error($db_error)
100 global $db_duplicate_error_code;
102 if ($db_error == $db_duplicate_error_code)
104 display_error(_("The entered information is a duplicate. Please go back and enter different values."));
111 function check_db_error($msg, $sql_statement, $exit_if_error=true, $rollback_if_error=true)
114 $db_error = db_error_no();
119 if (!frindly_db_error($db_error))
120 display_db_error($msg, $sql_statement, false);
122 if ($rollback_if_error)
124 $rollback_result = db_query("rollback","could not rollback");