Start porting admin/ to use the hoplite HTTP stack.
[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 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 $bugsys->load('db_mysql_pdo', 'db', true);
50 $db->connect($servername, $username, $password, $database, $usepconnect);
51 if ($utf8)
52 {
53 $db->query("SET NAMES utf8");
54 }
55
56 // don't use sql strict mode
57 $db->query("SET sql_mode = ''");
58
59 $bugsys->load('functions', 'funct', true);
60 $bugsys->load('xml', 'xml', true);
61
62 // change cookie expiration to one hour
63 $funct->cookieexp = 3600;
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 $bugsys->options = array();
78 $bugsys->userinfo = array();
79 bugdar::$datastore = array();
80
81 class bugdar
82 {
83 /*! @var \PDO The database connection instance. */
84 static $db = NULL;
85
86 /*! @var \hoplite\http\Input Input filter for the new stack. */
87 static $input = NULL;
88
89 static $options = array();
90 static $user = array();
91 static $datastore = array();
92 }
93
94 // TODO(port): Define this in index.php instead.
95 define('BUGDAR_ROOT', dirname(dirname(__FILE__)));
96
97 // ###################################################################
98 // Initialize Hoplite concurrently with ISSO 2.x.
99
100 define('HOPLITE_ROOT', dirname(__FILE__) . '/hoplite');
101
102 require_once HOPLITE_ROOT . '/data/model.php';
103 \hoplite\data\Model::set_db($db->dblink);
104
105 require_once HOPLITE_ROOT . '/http/input.php';
106 bugdar::$input = new \hoplite\http\Input(\hoplite\http\Input::TYPE_HTML);
107
108 bugdar::$db = $db->dblink;
109
110 bugdar::$db->SetAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
111
112 // ###################################################################
113 // send nocache
114 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
115 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
116 header("Cache-Control: no-store, no-cache, must-revalidate");
117 header("Cache-Control: post-check=0, pre-check=0", false);
118 if ($utf8)
119 {
120 header("Content-Type: text/html; charset=\"utf8\"");
121 }
122 header("Pragma: no-cache");
123
124 // ###################################################################
125 // populate our caches
126 $db->showerrors = false;
127 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
128 $db->showerrors = true;
129
130 if (!$datastoretemp)
131 {
132 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 />';
133 $db->error('Invalid SQL error');
134 }
135
136 while ($store = $db->fetch_array($datastoretemp))
137 {
138 bugdar::$datastore["$store[title]"] = unserialize($store['data']);
139 }
140
141 $bugsys->options = bugdar::$datastore['setting'];
142 $bugsys->options['columnoptions'] = unserialize($bugsys->options['columnoptions']);
143 unset(bugdar::$datastore['setting']);
144 bugdar::$options = $bugsys->options;
145
146 $bugsys->setAppVersion($bugsys->options['trackerversion']);
147
148 // ###################################################################
149 // load permissions
150
151 require_once('./includes/permissions.php');
152
153 // ###################################################################
154 // load userinfo
155
156 $authMethod = ((defined('USE_DEFAULT_AUTH_METHOD') AND constant('USE_DEFAULT_AUTH_METHOD') == 1) ? 'default' : $bugsys->options['authmethod']);
157 require_once('./includes/auth/auth_' . $authMethod . '.php');
158
159 $authClass = 'Authentication' . str_replace(' ', '', ucwords(str_replace('_', ' ', $authMethod)));
160 $bugsys->auth = $auth = new $authClass();
161
162 if ($auth->authenticateCookies())
163 {
164 $bugsys->userinfo = $auth->fetchBugdarUser();
165 $bugsys->userinfo['permissions'] = FetchUserPermissions($bugsys->userinfo);
166 $bugsys->userinfo['displaytitle'] = bugdar::$datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['displaytitle'];
167 $bugsys->userinfo['columnoptions'] = unserialize($bugsys->userinfo['columnoptions']);
168 }
169 else
170 {
171 $bugsys->userinfo = fetch_guest_user();
172 }
173 bugdar::$user = $bugsys->userinfo;
174
175 // ###################################################################
176 // initialize localization system
177
178 $language = fetch_user_language();
179
180 $stylevar['lang'] = $language['langcode'];
181 $stylevar['lang_dir'] = $language['direction'];
182 $stylevar['charset'] = $language['charset'];
183 $stylevar['left'] = ($language['direction'] == 'ltr' ? 'left' : 'right');
184 $stylevar['right'] = ($language['direction'] == 'ltr' ? 'right' : 'left');
185
186 require_once('./includes/definitions.php');
187
188 // ###################################################################
189 // initialize the date system
190 $bugsys->load('date', 'datef', true);
191 $datef->usertz = $bugsys->userinfo['timezone'] + ($bugsys->userinfo['usedst'] * 1);
192 $bugsys->debug('user tz = ' . $bugsys->userinfo['timezone'] . '; use version = ' . $datef->usertz);
193 $datef->fetch_offset();
194
195 // ###################################################################
196 // mail system
197 $bugsys->load('mail', 'mail', true);
198 $mail->setFromAddress($bugsys->options['webmasteremail']);
199 $mail->setFromName(T('Bugdar Notification'));
200