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.
14 // FIX: fatal errors ?
16 function error_handler($errno, $errstr, $file, $line) {
19 // error_reporting==0 when messages are set off with @
20 if ($errno & error_reporting())
21 $messages[] = array($errno, $errstr, $file, $line);
25 //------------------------------------------------------------------------------
26 // Formats system messages before insert them into message <div>
27 // FIX center is unused now
28 function fmt_errors($center=true) {
29 global $messages, $msg_colors;
31 $type = E_USER_NOTICE;
33 if (count($messages)) {
35 foreach($messages as $msg) {
36 if ($msg[0]>$type) continue;
37 if ($msg[0]<$type && $type>E_USER_ERROR) {
38 $content = ''; // clean notices when we have errors
39 $type = E_USER_ERROR; // php or user errors
42 $c = $msg_colors[$type];
43 if ($msg[0]<E_USER_ERROR && $msg[2]!=null)
44 $str .= ' '._('in file').': '.$msg[2].' '._('at line ').$msg[3];
45 $content .= "<tr><td " . ($center?"align='center' ":"").
46 " width='100%' bgcolor='{$c['bg']}'><font color='{$c['txt']}'>"
47 .$str."</font></td></tr>";
50 $str = "<center><table border='1' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='{$c['bd']}' width='98%'>"
51 . $content . "</table></center><br>\n";
59 //-----------------------------------------------------------------------------
60 // Error box <div> element.
62 function error_box() {
65 echo "<div id='msgbox'>";
66 $before_box = ob_get_clean(); // save html content before error box
67 // Necessary restart instead of get_contents/clean calls due to a bug in php 4.3.2
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.")
105 . "<br><a href='javascript:history.go(-1)'>" . _("Back") . "</a>", true);
112 function check_db_error($msg, $sql_statement, $exit_if_error=true, $rollback_if_error=true)
115 $db_error = db_error_no();
120 if (!frindly_db_error($db_error))
121 display_db_error($msg, $sql_statement, false);
123 if ($rollback_if_error)
125 $rollback_result = db_query("rollback","could not rollback");