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