1: <?php
2: //============================================================+
3: // File name : tce_functions_errmsg.php
4: // Begin : 2001-09-17
5: // Last Update : 2013-12-11
6: //
7: // Description : handle error messages
8: //
9: // Author: Nicola Asuni
10: //
11: // (c) Copyright:
12: // Nicola Asuni
13: // Tecnick.com LTD
14: // www.tecnick.com
15: // info@tecnick.com
16: //
17: // License:
18: // Copyright (C) 2004-2013 Nicola Asuni - Tecnick.com LTD
19: // See LICENSE.TXT file for more information.
20: //============================================================+
21:
22: /**
23: * @file
24: * Handle error/warning/system messages.<br>
25: * messagetype:
26: * <ul>
27: * <li>message</li>
28: * <li>warning</li>
29: * <li>error</li>
30: * </ul>
31: * @package com.tecnick.tcexam.shared
32: * @author Nicola Asuni
33: * @since 2001-09-17
34: */
35:
36: /**
37: * Handle error/warning/system messages.
38: * Print a message
39: * @param $messagetype (string) Type of message: 0=no message, message; warning; error.
40: * @param $messagetoprint (string) message to print.
41: * @param $exit (bool) if true output a message and terminate the current script [default = false].
42: */
43: function F_print_error($messagetype = 'MESSAGE', $messagetoprint = '', $exit = false)
44: {
45: require_once(dirname(__FILE__).'/../config/tce_config.php');
46: global $l;
47: $messagetype = strtolower($messagetype);
48: //message is appended to the log file
49: if (K_USE_ERROR_LOG and (!strcmp($messagetype, 'error'))) {
50: $logsttring = date(K_TIMESTAMP_FORMAT).K_TAB;
51: $logsttring .= $_SESSION['session_user_id'].K_TAB;
52: $logsttring .= $_SESSION['session_user_ip'].K_TAB;
53: $logsttring .= $messagetype.K_TAB;
54: $logsttring .= $_SERVER['SCRIPT_NAME'].K_TAB;
55: $logsttring .= $messagetoprint.K_NEWLINE;
56: error_log($logsttring, 3, '../log/tce_errors.log');
57: }
58: if (strlen($messagetoprint) > 0) {
59: switch ($messagetype) {
60: case 'message':{
61: $msgtitle = $l['t_message'];
62: break;
63: }
64: case 'warning':{
65: $msgtitle = $l['t_warning'];
66: break;
67: }
68: case 'error':{
69: $msgtitle = $l['t_error'];
70: break;
71: }
72: default: {//no message
73: $msgtitle = $messagetype;
74: break;
75: }
76: }
77: echo '<div class="'.$messagetype.'">'.$msgtitle.': '.$messagetoprint.'</div>'.K_NEWLINE;
78: if (K_ENABLE_JSERRORS) {
79: //display message on JavaScript Alert Window.
80: echo '<script type="text/javascript">'.K_NEWLINE;
81: echo '//<![CDATA['.K_NEWLINE;
82: $messagetoprint = unhtmlentities(strip_tags($messagetoprint));
83: $messagetoprint = str_replace("'", "\'", $messagetoprint);
84: echo 'alert(\'['.$msgtitle.']: '.$messagetoprint.'\');'.K_NEWLINE;
85: echo '//]]>'.K_NEWLINE;
86: echo '</script>'.K_NEWLINE;
87: }
88: }
89: if ($exit) {
90: exit(); // terminate the current script
91: }
92: }
93:
94: /**
95: * Print the database error message.
96: * @param $exit (bool) if true output a message and terminate the current script [default = true].
97: */
98: function F_display_db_error($exit = true)
99: {
100: global $db;
101: $messagetype = 'ERROR';
102: $messagetoprint = F_db_error($db);
103: F_print_error($messagetype, $messagetoprint, $exit);
104: }
105:
106: /**
107: * Custom PHP error handler function.
108: * @param $errno (int) The first parameter, errno, contains the level of the error raised, as an integer.
109: * @param $errstr (string) The second parameter, errstr, contains the error message, as a string.
110: * @param $errfile (string) The third parameter is optional, errfile, which contains the filename that the error was raised in, as a string.
111: * @param $errline (int) The fourth parameter is optional, errline, which contains the line number the error was raised at, as an integer.
112: */
113: function F_error_handler($errno, $errstr, $errfile, $errline)
114: {
115: if (ini_get('error_reporting') == 0) {
116: // this is required to ignore supressed error messages with '@'
117: return;
118: }
119: $messagetoprint = '['.$errno.'] '.$errstr.' | LINE: '.$errline.' | FILE: '.$errfile.'';
120: switch ($errno) {
121: case E_ERROR:
122: case E_USER_ERROR: {
123: F_print_error('ERROR', $messagetoprint, true);
124: break;
125: }
126: case E_WARNING:
127: case E_USER_WARNING: {
128: F_print_error('ERROR', $messagetoprint, false);
129: break;
130: }
131: case E_NOTICE:
132: case E_USER_NOTICE:
133: default: {
134: F_print_error('WARNING', $messagetoprint, false);
135: break;
136: }
137: }
138: }
139:
140: // Set the custom error handler function
141: $old_error_handler = set_error_handler('F_error_handler', K_ERROR_TYPES);
142:
143: //============================================================+
144: // END OF FILE
145: //============================================================+
146: