Disable PDO options ATTR_EMULATE_PREPARES and ATTR_STRINGIFY_FETCHES.
[bugdar.git] / includes / init.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)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 // TODO(port): Define this in index.php instead.
31 define('BUGDAR_ROOT', dirname(dirname(__FILE__)));
32
33 require_once('./includes/version.php');
34
35 require_once('./framework/kernel.php');
36 $bugsys = new ISSO();
37
38 $bugsys->setAppPath(getcwd());
39 $bugsys->setApplication('Bugdar');
40 $bugsys->setAppVersion(BUGDAR_VERSION);
41
42 if (!file_exists('./includes/config.php'))
43 {
44 echo 'includes/config.php needs to be present!';
45 exit;
46 }
47
48 require_once('./includes/config.php');
49
50 $bugsys->setDebug($debug);
51 define('DEVDEBUG', $debug);
52 unset($debug);
53
54 // ###################################################################
55 // init the big three
56 $bugsys->options = array();
57 $bugsys->userinfo = array();
58
59 class Bugdar
60 {
61 /*! @var \PDO The database connection instance. */
62 static $db = NULL;
63
64 /*! @var \hoplite\http\Input Input filter for the new stack. */
65 static $input = NULL;
66
67 static $options = array();
68 static $user = array();
69 static $datastore = array();
70 }
71
72 // ###################################################################
73 // Hoplite early initialization.
74
75 define('HOPLITE_ROOT', dirname(__FILE__) . '/hoplite');
76
77 if (DEVDEBUG) {
78 require_once HOPLITE_ROOT . '/base/profiling.php';
79 \hoplite\base\Profiling::EnableProfiling();
80 }
81
82 // ###################################################################
83 // Connect to the database.
84
85 $pdo_class = '\\PDO';
86 if (DEVDEBUG) {
87 require_once HOPLITE_ROOT . '/data/profiling_pdo.php';
88 $pdo_class = '\\hoplite\\data\\ProfilingPDO';
89 }
90 Bugdar::$db = new $pdo_class("mysql:dbname=$database;host=$servername", $username, $password);
91 unset($database, $servername, $username, $password);
92
93 // Let ISSO handle the database connection failure message.
94 $bugsys->load('db_mysql_pdo', 'db', true);
95 $db->connect(Bugdar::$db);
96
97 Bugdar::$db->SetAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
98 Bugdar::$db->SetAttribute(\PDO::ATTR_EMULATE_PREPARES, FALSE);
99 Bugdar::$db->SetAttribute(\PDO::ATTR_STRINGIFY_FETCHES, FALSE);
100
101 if ($utf8)
102 {
103 $db->query("SET NAMES utf8");
104 }
105
106 // don't use sql strict mode
107 $db->query("SET sql_mode = ''");
108
109 $bugsys->load('functions', 'funct', true);
110 $bugsys->load('xml', 'xml', true);
111
112 // change cookie expiration to one hour
113 $funct->cookieexp = 3600;
114
115 define('TABLE_PREFIX', $tableprefix);
116 define('COOKIE_PREFIX', $cookieprefix);
117
118 unset($usepconnect, $tableprefix, $cookieprefix);
119
120 require_once('./includes/functions_datastore.php');
121 require_once('./includes/functions.php');
122 require_once('./includes/language.php');
123
124 // ###################################################################
125 // Hoplite late initialization.
126
127 require_once HOPLITE_ROOT . '/data/model.php';
128 \hoplite\data\Model::set_db(Bugdar::$db);
129
130 require_once HOPLITE_ROOT . '/http/input.php';
131 Bugdar::$input = new \hoplite\http\Input(\hoplite\http\Input::TYPE_HTML);
132
133 // ###################################################################
134 // send nocache
135 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
136 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
137 header("Cache-Control: no-store, no-cache, must-revalidate");
138 header("Cache-Control: post-check=0, pre-check=0", false);
139 if ($utf8)
140 {
141 header("Content-Type: text/html; charset=\"utf8\"");
142 }
143 header("Pragma: no-cache");
144
145 // ###################################################################
146 // populate our caches
147 $db->showerrors = false;
148 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
149 $db->showerrors = true;
150
151 if (!$datastoretemp)
152 {
153 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 />';
154 $db->error('Invalid SQL error');
155 }
156
157 while ($store = $db->fetch_array($datastoretemp))
158 {
159 Bugdar::$datastore["$store[title]"] = unserialize($store['data']);
160 }
161
162 $bugsys->options = Bugdar::$datastore['setting'];
163 $bugsys->options['columnoptions'] = unserialize($bugsys->options['columnoptions']);
164 unset(Bugdar::$datastore['setting']);
165 Bugdar::$options = $bugsys->options;
166
167 $bugsys->setAppVersion($bugsys->options['trackerversion']);
168
169 // ###################################################################
170 // load permissions
171
172 require_once('./includes/permissions.php');
173
174 // ###################################################################
175 // load userinfo
176
177 $authMethod = ((defined('USE_DEFAULT_AUTH_METHOD') AND constant('USE_DEFAULT_AUTH_METHOD') == 1) ? 'default' : $bugsys->options['authmethod']);
178 require_once('./includes/auth/auth_' . $authMethod . '.php');
179
180 $authClass = 'Authentication' . str_replace(' ', '', ucwords(str_replace('_', ' ', $authMethod)));
181 $bugsys->auth = $auth = new $authClass();
182
183 if ($auth->authenticateCookies())
184 {
185 $bugsys->userinfo = $auth->fetchBugdarUser();
186 $bugsys->userinfo['permissions'] = FetchUserPermissions($bugsys->userinfo);
187 $bugsys->userinfo['displaytitle'] = Bugdar::$datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['displaytitle'];
188 $bugsys->userinfo['columnoptions'] = unserialize($bugsys->userinfo['columnoptions']);
189 }
190 else
191 {
192 $bugsys->userinfo = fetch_guest_user();
193 }
194 Bugdar::$user = $bugsys->userinfo;
195
196 // ###################################################################
197 // initialize localization system
198
199 $language = fetch_user_language();
200
201 $stylevar['lang'] = $language['langcode'];
202 $stylevar['lang_dir'] = $language['direction'];
203 $stylevar['charset'] = $language['charset'];
204 $stylevar['left'] = ($language['direction'] == 'ltr' ? 'left' : 'right');
205 $stylevar['right'] = ($language['direction'] == 'ltr' ? 'right' : 'left');
206
207 require_once('./includes/definitions.php');
208
209 // ###################################################################
210 // initialize the date system
211 $bugsys->load('date', 'datef', true);
212 $datef->usertz = $bugsys->userinfo['timezone'] + ($bugsys->userinfo['usedst'] * 1);
213 $bugsys->debug('user tz = ' . $bugsys->userinfo['timezone'] . '; use version = ' . $datef->usertz);
214 $datef->fetch_offset();
215
216 // ###################################################################
217 // mail system
218 $bugsys->load('mail', 'mail', true);
219 $mail->setFromAddress($bugsys->options['webmasteremail']);
220 $mail->setFromName(T('Bugdar Notification'));
221