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