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 ©2002-2007 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 // initialize the database
26
27 define('ISSO_MT_START', microtime());
28 define('ISSO_CHECK_POST_REFERER', 1);
29
30 require_once('./includes/version.php');
31
32 require_once('./framework/kernel.php');
33 $bugsys = new ISSO();
34
35 $bugsys->setAppPath(getcwd());
36 $bugsys->setApplication('Bugdar');
37 $bugsys->setAppVersion(BUGDAR_VERSION);
38
39 if (!file_exists('./includes/config.php'))
40 {
41 echo 'includes/config.php needs to be present!';
42 exit;
43 }
44
45 require_once('./includes/config.php');
46
47 $bugsys->setDebug($debug);
48
49 define('ISSO_DB_LAYER', 'db_mysql');
50 $bugsys->load('db_mysql', 'db', true);
51 $db->connect($servername, $username, $password, $database, $usepconnect);
52 if ($utf8)
53 {
54 $db->query("SET NAMES utf8");
55 }
56
57 // don't use sql strict mode
58 $db->query("SET sql_mode = ''");
59
60 $bugsys->load('functions', 'funct', true);
61 $bugsys->load('xml', 'xml', true);
62
63 // change cookie expiration to one hour
64 $funct->cookieexp = 3600;
65
66 define('DEVDEBUG', $debug);
67 define('TABLE_PREFIX', $tableprefix);
68 define('COOKIE_PREFIX', $cookieprefix);
69
70 unset($database, $servername, $theuser, $password, $thepass, $usepconnect, $tableprefix, $cookieprefix);
71
72 require_once('./includes/functions_datastore.php');
73 require_once('./includes/functions.php');
74 require_once('./includes/language.php');
75
76 // ###################################################################
77 // init the big three
78 $bugsys->options = array();
79 $bugsys->userinfo = array();
80 $bugsys->datastore = array();
81
82 // ###################################################################
83 // send nocache
84 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
85 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
86 header("Cache-Control: no-store, no-cache, must-revalidate");
87 header("Cache-Control: post-check=0, pre-check=0", false);
88 if ($utf8)
89 {
90 header("Content-Type: text/html; charset=\"utf8\"");
91 }
92 header("Pragma: no-cache");
93
94 // ###################################################################
95 // populate our caches
96 $db->showerrors = false;
97 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
98 $db->showerrors = true;
99
100 if (!$datastoretemp)
101 {
102 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 />';
103 $db->error('Invalid SQL error');
104 }
105
106 while ($store = $db->fetch_array($datastoretemp))
107 {
108 $bugsys->datastore["$store[title]"] = unserialize($store['data']);
109 }
110 $bugsys->options = $bugsys->datastore['setting'];
111 $bugsys->options['columnoptions'] = unserialize($bugsys->options['columnoptions']);
112 unset($bugsys->datastore['setting']);
113
114 $bugsys->setAppVersion($bugsys->options['trackerversion']);
115
116 // ###################################################################
117 // load permissions
118
119 require_once('./includes/permissions.php');
120
121 // ###################################################################
122 // load userinfo
123
124 $authMethod = ((defined('USE_DEFAULT_AUTH_METHOD') AND constant('USE_DEFAULT_AUTH_METHOD') == 1) ? 'default' : $bugsys->options['authmethod']);
125 require_once('./includes/auth/auth_' . $authMethod . '.php');
126
127 $authClass = 'Authentication' . str_replace(' ', '', ucwords(str_replace('_', ' ', $authMethod)));
128 $bugsys->auth = $auth = new $authClass();
129
130 if ($auth->authenticateCookies())
131 {
132 $bugsys->userinfo = $auth->fetchBugdarUser();
133 $bugsys->userinfo['permissions'] = FetchUserPermissions($bugsys->userinfo);
134 $bugsys->userinfo['displaytitle'] = $bugsys->datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['displaytitle'];
135 $bugsys->userinfo['columnoptions'] = unserialize($bugsys->userinfo['columnoptions']);
136 }
137 else
138 {
139 $bugsys->userinfo = fetch_guest_user();
140 }
141
142 // ###################################################################
143 // initialize localization system
144
145 $language = fetch_user_language();
146
147 $stylevar['lang'] = $language['langcode'];
148 $stylevar['lang_dir'] = $language['direction'];
149 $stylevar['charset'] = $language['charset'];
150 $stylevar['left'] = ($language['direction'] == 'ltr' ? 'left' : 'right');
151 $stylevar['right'] = ($language['direction'] == 'ltr' ? 'right' : 'left');
152
153 // start gettext engine
154 if (!$bugsys->options['devgettext'])
155 {
156 putenv("LANG=$language[langcode]");
157 putenv("LANGUAGE=$language[langcode]");
158
159 setlocale(LC_ALL, $language['langcode']);
160
161 bindtextdomain('MESSAGES', $bugsys->apppath . 'locale/');
162 textdomain('MESSAGES');
163
164 bind_textdomain_codeset('MESSAGES', $language['charset']);
165 }
166 else
167 {
168 $bugsys->debug("using custom MOReader instead of Gettext");
169 }
170
171 require_once('./includes/definitions.php');
172
173 // ###################################################################
174 // initialize the date system
175 $bugsys->load('date', 'datef', true);
176 $datef->usertz = $bugsys->userinfo['timezone'] + ($bugsys->userinfo['usedst'] * 1);
177 $bugsys->debug('user tz = ' . $bugsys->userinfo['timezone'] . '; use version = ' . $datef->usertz);
178 $datef->fetch_offset();
179
180 // ###################################################################
181 // mail system
182 $bugsys->load('mail', 'mail', true);
183 $mail->setFromAddress($bugsys->options['webmasteremail']);
184 $mail->setFromName(T('Bugdar Notification'));
185
186 /*=====================================================================*\
187 || ###################################################################
188 || # $HeadURL$
189 || # $Id$
190 || ###################################################################
191 \*=====================================================================*/
192 ?>