3 require_once(dirname(__FILE__) .'/includes/utf8.php');
6 require_once(dirname(__FILE__) .'/includes/php-gettext/gettext.inc');
8 T_setlocale(LC_ALL, $locale);
9 T_bindtextdomain($domain, dirname(__FILE__) .'/locales');
10 T_bind_textdomain_codeset($domain, 'UTF-8');
11 T_textdomain($domain);
14 // - direction = out: convert spaces to underscores;
15 // - direction = in: convert underscores to spaces.
16 function convertTag($tag, $direction = 'out') {
17 if ($direction == 'out') {
18 $tag = str_replace(' ', '_', $tag);
20 $tag = str_replace('_', ' ', $tag);
25 function filter($data, $type = NULL) {
26 if (is_string($data)) {
28 $data = stripslashes($data);
31 $data = rawurlencode($data);
34 $data = htmlspecialchars($data);
37 } else if (is_array($data)) {
38 foreach(array_keys($data) as $key) {
40 $row = filter($row, $type);
46 function getPerPageCount() {
47 global $defaultPerPage;
48 return $defaultPerPage;
51 function getSortOrder($override = NULL) {
52 global $defaultOrderBy;
54 if (isset($_GET['sort'])) {
56 } else if (isset($override)) {
59 return $defaultOrderBy;
63 function multi_array_search($needle, $haystack) {
64 if (is_array($haystack)) {
65 foreach(array_keys($haystack) as $key) {
66 $value =& $haystack[$key];
67 $result = multi_array_search($needle, $value);
68 if (is_array($result)) {
70 array_unshift($return, $key);
72 } elseif ($result == true) {
79 if ($needle === $haystack) {
87 function createURL($page = '', $ending = '') {
88 global $cleanurls, $root;
89 if (!$cleanurls && $page != '') {
92 return $root . $page .'/'. $ending;
95 function message_die($msg_code, $msg_text = '', $msg_title = '', $err_line = '', $err_file = '', $sql = '', $db = NULL) {
96 if(defined('HAS_DIED'))
97 die(T_('message_die() was called multiple times.'));
98 define('HAS_DIED', 1);
102 // Get SQL error if we are debugging. Do this as soon as possible to prevent
103 // subsequent queries from overwriting the status of sql_error()
104 if (DEBUG && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
105 $sql_error = is_null($db) ? '' : $db->sql_error();
108 if ($sql_error['message'] != '')
109 $debug_text .= '<br /><br />'. T_('SQL Error') .' : '. $sql_error['code'] .' '. $sql_error['message'];
111 if ($sql_store != '')
112 $debug_text .= '<br /><br />'. $sql_store;
114 if ($err_line != '' && $err_file != '')
115 $debug_text .= '</br /><br />'. T_('Line') .' : '. $err_line .'<br />'. T_('File') .' :'. $err_file;
119 case GENERAL_MESSAGE:
120 if ($msg_title == '')
121 $msg_title = T_('Information');
124 case CRITICAL_MESSAGE:
125 if ($msg_title == '')
126 $msg_title = T_('Critical Information');
131 $msg_text = T_('An error occured');
133 if ($msg_title == '')
134 $msg_title = T_('General Error');
138 // Critical errors mean we cannot rely on _ANY_ DB information being
139 // available so we're going to dump out a simple echo'd statement
142 $msg_text = T_('An critical error occured');
144 if ($msg_title == '')
145 $msg_title = T_('Critical Error');
149 // Add on DEBUG info if we've enabled debug mode and this is an error. This
150 // prevents debug info being output for general messages should DEBUG be
151 // set TRUE by accident (preventing confusion for the end user!)
152 if (DEBUG && ($msg_code == GENERAL_ERROR || $msg_code == CRITICAL_ERROR)) {
153 if ($debug_text != '')
154 $msg_text = $msg_text . '<br /><br /><strong>'. T_('DEBUG MODE') .'</strong>'. $debug_text;
157 echo "<html>\n<body>\n". $msg_title ."\n<br /><br />\n". $msg_text ."</body>\n</html>";