2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $messages = array(); // container for system messages
13 $before_box = ''; // temporary container for output html data before error box
16 E_USER_ERROR => array('bg'=>'#ffcccc', 'txt'=>'#dd2200', 'bd'=>'#cc3300'),
17 E_USER_WARNING => array('bg'=>'#ffff00', 'txt'=>'#ff5500', 'bd'=>'#ff9900'),
18 E_USER_NOTICE => array('bg'=>'#ccffcc', 'txt'=>'#007700', 'bd'=>'#33cc00'));
20 //-----------------------------------------------------------------------------
21 // Error handler - collects all php/user messages for
22 // display in message box.
24 function error_handler($errno, $errstr, $file, $line) {
27 // error_reporting==0 when messages are set off with @
30 $messages[] = array($errno, $errstr, $file, $line);
32 $ignored = E_USER_WARNING|E_USER_ERROR|E_USER_NOTICE;
33 // don't log notices hidden with @ unless in debug mode
34 if (!$go_debug) $ignored |= E_NOTICE;
36 if (!($errno & $ignored))
38 user_company().':'.$_SESSION["wa_current_user"]->loginname.':'.
39 basename($file).":$line: $errstr");
43 //------------------------------------------------------------------------------
44 // Formats system messages before insert them into message <div>
45 // FIX center is unused now
46 function fmt_errors($center=true) {
47 global $messages, $msg_colors;
49 $type = E_USER_NOTICE;
51 if (count($messages)) {
53 foreach($messages as $msg) {
54 if ($msg[0]>$type) continue;
57 if ($msg[0] == E_USER_WARNING) {
58 $type = E_USER_WARNING; // user warnings
59 $content = ''; // clean notices when we have errors
61 $type = E_USER_ERROR; // php or user errors
62 if($type == E_USER_WARNING)
63 $content = ''; // clean other messages
67 $c = $msg_colors[$type];
68 if ($msg[0] < E_USER_ERROR && $msg[2] != null)
69 $str .= ' '._('in file').': '.$msg[2].' '._('at line ').$msg[3];
71 $content .= "<tr><td " . ($center?"align='center' ":"").
72 " width='100%' bgcolor='{$c['bg']}'><font color='{$c['txt']}'>"
73 .$str."</font></td></tr>";
76 $str = "<center><table border='1' cellpadding='3' cellspacing='0' style='border-collapse: collapse' bordercolor='{$c['bd']}' width='98%'>"
77 . $content . "</table></center><br>\n";
85 //-----------------------------------------------------------------------------
86 // Error box <div> element.
88 function error_box() {
91 echo "<div id='msgbox'>";
92 $before_box = ob_get_clean(); // save html content before error box
93 // Necessary restart instead of get_contents/clean calls due to a bug in php 4.3.2
94 register_shutdown_function('ob_end_flush');
95 ob_start('output_html');
99 function display_db_error($msg, $sql_statement=null, $exit=true)
102 $db_error = db_error_no();
104 $str = "<span class='errortext'><b>" . _("DATABASE ERROR :") . "</b> $msg</span><br>";
108 $str .= "error code : " . $db_error . "<br>";
109 $str .= "error message : " . db_error_msg($db) . "<br>";
114 $str .= "sql that failed was : " . $sql_statement . "<br>";
119 trigger_error($str, E_USER_ERROR);
125 function frindly_db_error($db_error)
127 global $db_duplicate_error_code;
129 if ($db_error == $db_duplicate_error_code)
131 display_error(_("The entered information is a duplicate. Please go back and enter different values."));
138 function check_db_error($msg, $sql_statement, $exit_if_error=true, $rollback_if_error=true)
141 $db_error = db_error_no();
146 if (!frindly_db_error($db_error))
147 display_db_error($msg, $sql_statement, false);
149 if ($rollback_if_error)
151 $rollback_result = db_query("rollback","could not rollback");