Fix DB_MySQL_PDO::escape_binary().
[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_MEMORY_START', memory_get_usage(true));
29 define('ISSO_CHECK_POST_REFERER', 1);
30
31 require_once('./includes/version.php');
32
33 require_once('./framework/kernel.php');
34 $bugsys = new ISSO();
35
36 $bugsys->setAppPath(getcwd());
37 $bugsys->setApplication('Bugdar');
38 $bugsys->setAppVersion(BUGDAR_VERSION);
39
40 if (!file_exists('./includes/config.php'))
41 {
42 echo 'includes/config.php needs to be present!';
43 exit;
44 }
45
46 require_once('./includes/config.php');
47
48 $bugsys->setDebug($debug);
49
50 $bugsys->load('db_mysql_pdo', '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
81 class bugdar
82 {
83 static $db = NULL;
84
85 static $options = array();
86 static $user = array();
87 static $datastore = array();
88 }
89
90 bugdar::$db = $db->dblink;
91
92 // ###################################################################
93 // send nocache
94 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
95 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
96 header("Cache-Control: no-store, no-cache, must-revalidate");
97 header("Cache-Control: post-check=0, pre-check=0", false);
98 if ($utf8)
99 {
100 header("Content-Type: text/html; charset=\"utf8\"");
101 }
102 header("Pragma: no-cache");
103
104 // ###################################################################
105 // populate our caches
106 $db->showerrors = false;
107 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
108 $db->showerrors = true;
109
110 if (!$datastoretemp)
111 {
112 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 />';
113 $db->error('Invalid SQL error');
114 }
115
116 while ($store = $db->fetch_array($datastoretemp))
117 {
118 bugdar::$datastore["$store[title]"] = unserialize($store['data']);
119 }
120
121 $bugsys->options = bugdar::$datastore['setting'];
122 $bugsys->options['columnoptions'] = unserialize($bugsys->options['columnoptions']);
123 unset(bugdar::$datastore['setting']);
124 bugdar::$options = $bugsys->options;
125
126 $bugsys->setAppVersion($bugsys->options['trackerversion']);
127
128 // ###################################################################
129 // load permissions
130
131 require_once('./includes/permissions.php');
132
133 // ###################################################################
134 // load userinfo
135
136 $authMethod = ((defined('USE_DEFAULT_AUTH_METHOD') AND constant('USE_DEFAULT_AUTH_METHOD') == 1) ? 'default' : $bugsys->options['authmethod']);
137 require_once('./includes/auth/auth_' . $authMethod . '.php');
138
139 $authClass = 'Authentication' . str_replace(' ', '', ucwords(str_replace('_', ' ', $authMethod)));
140 $bugsys->auth = $auth = new $authClass();
141
142 if ($auth->authenticateCookies())
143 {
144 $bugsys->userinfo = $auth->fetchBugdarUser();
145 $bugsys->userinfo['permissions'] = FetchUserPermissions($bugsys->userinfo);
146 $bugsys->userinfo['displaytitle'] = bugdar::$datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['displaytitle'];
147 $bugsys->userinfo['columnoptions'] = unserialize($bugsys->userinfo['columnoptions']);
148 }
149 else
150 {
151 $bugsys->userinfo = fetch_guest_user();
152 }
153 bugdar::$user = $bugsys->userinfo;
154
155 // ###################################################################
156 // initialize localization system
157
158 $language = fetch_user_language();
159
160 $stylevar['lang'] = $language['langcode'];
161 $stylevar['lang_dir'] = $language['direction'];
162 $stylevar['charset'] = $language['charset'];
163 $stylevar['left'] = ($language['direction'] == 'ltr' ? 'left' : 'right');
164 $stylevar['right'] = ($language['direction'] == 'ltr' ? 'right' : 'left');
165
166 require_once('./includes/definitions.php');
167
168 // ###################################################################
169 // initialize the date system
170 $bugsys->load('date', 'datef', true);
171 $datef->usertz = $bugsys->userinfo['timezone'] + ($bugsys->userinfo['usedst'] * 1);
172 $bugsys->debug('user tz = ' . $bugsys->userinfo['timezone'] . '; use version = ' . $datef->usertz);
173 $datef->fetch_offset();
174
175 // ###################################################################
176 // mail system
177 $bugsys->load('mail', 'mail', true);
178 $mail->setFromAddress($bugsys->options['webmasteremail']);
179 $mail->setFromName(T('Bugdar Notification'));
180