Disable MySQL strict mode so that errors do not occur if the server has it set. Fixes...
[bugdar.git] / includes / init.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 error_reporting(E_ALL & ~E_NOTICE);
23
24 // ###################################################################
25 // load the framework
26
27 define('ISSO_MT_START', microtime());
28 define('ISSO_CHECK_POST_REFERER', 1);
29
30 require_once('./includes/version.php');
31
32 if (!file_exists('./includes/config.php'))
33 {
34 echo 'includes/config.php needs to be present!';
35 exit;
36 }
37
38 require_once('./includes/config.php');
39
40 define('ISSO', getcwd() . '/includes/framework/');
41 require_once ISSO . '/App.php';
42 BSApp::set_debug($debug);
43
44 require_once ISSO . '/Functions.php';
45 BSFunctions::set_cookie_timeout(3600);
46
47 require_once ISSO . '/Input.php';
48 $input = BSApp::$input = new BSInput();
49
50 // ###################################################################
51 // initialize the database
52
53 require_once ISSO . '/DbMySqlI.php';
54 $db = BSApp::$db = new BSDBMySQLI();
55
56 $db->connect($servername, $username, $password, $database);
57 if ($utf8)
58 {
59 $db->query("SET NAMES utf8");
60 }
61
62 // don't use sql strict mode
63 $db->query("SET sql_mode = ''");
64
65 define('DEVDEBUG', $debug);
66 define('TABLE_PREFIX', $tableprefix);
67 define('COOKIE_PREFIX', $cookieprefix);
68
69 unset($database, $servername, $theuser, $password, $thepass, $usepconnect, $tableprefix, $cookieprefix);
70
71 require_once('./includes/functions_datastore.php');
72 require_once('./includes/functions.php');
73 require_once('./includes/language.php');
74
75 // ###################################################################
76 // init the big three
77
78 class bugdar
79 {
80 public static $options = array();
81 public static $userinfo = array();
82 public static $datastore = array();
83
84 public static $permissions = array();
85 public static $emailOptions = array();
86
87 private function __construct() {}
88 }
89
90 // ###################################################################
91 // send nocache
92 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
93 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
94 header("Cache-Control: no-store, no-cache, must-revalidate");
95 header("Cache-Control: post-check=0, pre-check=0", false);
96 if ($utf8)
97 {
98 header("Content-Type: text/html; charset=\"utf8\"");
99 }
100 header("Pragma: no-cache");
101
102 // ###################################################################
103 // populate our caches
104 $db->showerrors = false;
105 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
106 $db->showerrors = true;
107
108 if (!$datastoretemp)
109 {
110 echo '<div style="font-size: 18px"><strong>Notice:</strong> This error could be caused if you have not installed Bugdar. If this is the case, you can run the installer <a href="install/install.php">here</a>.</div><br />';
111 $db->error('Invalid SQL error');
112 }
113
114 foreach ($datastoretemp as $store)
115 {
116 bugdar::$datastore["$store[title]"] = unserialize($store['data']);
117 }
118 bugdar::$options = bugdar::$datastore['setting'];
119 bugdar::$options['columnoptions'] = unserialize(bugdar::$options['columnoptions']);
120 unset(bugdar::$datastore['setting']);
121
122 // ###################################################################
123 // load permissions
124
125 require_once('./includes/permissions.php');
126
127 // ###################################################################
128 // load userinfo
129
130 $authMethod = ((defined('USE_DEFAULT_AUTH_METHOD') AND constant('USE_DEFAULT_AUTH_METHOD') == 1) ? 'default' : bugdar::$options['authmethod']);
131 require_once('./includes/auth/auth_' . $authMethod . '.php');
132
133 $authClass = 'Authentication' . str_replace(' ', '', ucwords(str_replace('_', ' ', $authMethod)));
134 $auth = new $authClass();
135
136 if ($auth->authenticateCookies())
137 {
138 bugdar::$userinfo = $auth->fetchBugdarUser();
139 bugdar::$userinfo['permissions'] = FetchUserPermissions(bugdar::$userinfo);
140 bugdar::$userinfo['displaytitle'] = bugdar::$datastore['usergroup'][ bugdar::$userinfo['usergroupid'] ]['displaytitle'];
141 bugdar::$userinfo['columnoptions'] = unserialize(bugdar::$userinfo['columnoptions']);
142 }
143 else
144 {
145 bugdar::$userinfo = fetch_guest_user();
146 }
147
148 // ###################################################################
149 // initialize localization system
150
151 $language = fetch_user_language();
152
153 $stylevar['lang'] = $language['langcode'];
154 $stylevar['lang_dir'] = $language['direction'];
155 $stylevar['charset'] = $language['charset'];
156 $stylevar['left'] = ($language['direction'] == 'ltr' ? 'left' : 'right');
157 $stylevar['right'] = ($language['direction'] == 'ltr' ? 'right' : 'left');
158
159 // start gettext engine
160 if (!bugdar::$options['devgettext'])
161 {
162 putenv("LANG=$language[langcode]");
163 putenv("LANGUAGE=$language[langcode]");
164
165 setlocale(LC_ALL, $language['langcode']);
166
167 bindtextdomain('MESSAGES', $bugsys->apppath . 'locale/');
168 textdomain('MESSAGES');
169
170 bind_textdomain_codeset('MESSAGES', $language['charset']);
171 }
172 else
173 {
174 BSApp::debug("using custom MOReader instead of Gettext");
175 }
176
177 // ###################################################################
178 // initialize the date system
179 require_once ISSO . '/Date.php';
180 $datef = BSApp::$date = new BSDate();
181 $datef->setUserTimeZone(bugdar::$userinfo['timezone'] + (bugdar::$userinfo['usedst'] * 1));
182 BSApp::debug('user tz = ' . bugdar::$userinfo['timezone'] . '; use version = ' . $datef->usertz);
183
184 ?>