r1462: Fix the tag from "verson" to "version"
[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
66 // ###################################################################
67 // init the big three
68 $bugsys->options = array();
69 $bugsys->userinfo = array();
70 $bugsys->datastore = array();
71
72 // ###################################################################
73 // send nocache
74 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
75 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
76 header("Cache-Control: no-store, no-cache, must-revalidate");
77 header("Cache-Control: post-check=0, pre-check=0", false);
78 header("Pragma: no-cache");
79
80 // ###################################################################
81 // populate our caches
82 $db->showerrors = false;
83 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
84 $db->showerrors = true;
85
86 if (!$datastoretemp)
87 {
88 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 />';
89 $db->error('Invalid SQL error');
90 }
91
92 while ($store = $db->fetch_array($datastoretemp))
93 {
94 $bugsys->datastore["$store[title]"] = unserialize($store['data']);
95 }
96 $bugsys->options = $bugsys->datastore['setting'];
97 $bugsys->options['columnoptions'] = unserialize($bugsys->options['columnoptions']);
98 unset($bugsys->datastore['setting']);
99
100 $bugsys->setAppVersion($bugsys->options['trackerversion']);
101
102 // ###################################################################
103 // load permissions
104
105 require_once('./includes/permissions.php');
106
107 // ###################################################################
108 // load userinfo
109
110 $authMethod = ((defined('USE_DEFAULT_AUTH_METHOD') AND constant('USE_DEFAULT_AUTH_METHOD') == 1) ? 'default' : $bugsys->options['authmethod']);
111 require_once('./includes/auth/auth_' . $authMethod . '.php');
112
113 $authClass = 'Authentication' . str_replace(' ', '', ucwords(str_replace('_', ' ', $authMethod)));
114 $bugsys->auth = $auth = new $authClass();
115
116 if ($auth->authenticateCookies())
117 {
118 $bugsys->userinfo = $auth->fetchBugdarUser();
119 $bugsys->userinfo['permissions'] = (int)$bugsys->datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['permissions'];
120 $bugsys->userinfo['displaytitle'] = $bugsys->datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['displaytitle'];
121 $bugsys->userinfo['columnoptions'] = unserialize($bugsys->userinfo['columnoptions']);
122 }
123 else
124 {
125 $bugsys->userinfo = fetch_guest_user();
126 }
127
128 // ###################################################################
129 // initialize localization system
130
131 require_once('./includes/language.php');
132
133 $language = fetch_user_language();
134
135 $stylevar['lang'] = $language['langcode'];
136 $stylevar['lang_dir'] = $language['direction'];
137 $stylevar['charset'] = $language['charset'];
138 $stylevar['left'] = ($language['direction'] == 'ltr' ? 'left' : 'right');
139 $stylevar['right'] = ($language['direction'] == 'ltr' ? 'right' : 'left');
140
141 // start gettext engine
142 putenv("LANG=$language[langcode]");
143 putenv("LANGUAGE=$language[langcode]");
144
145 setlocale(LC_ALL, $language['langcode']);
146
147 bindtextdomain('MESSAGES', $bugsys->apppath . 'locale/');
148 textdomain('MESSAGES');
149
150 bind_textdomain_codeset('MESSAGES', $language['charset']);
151
152 // ###################################################################
153 // initialize the date system
154 $bugsys->load('date', 'datef', true);
155 $datef->usertz = $bugsys->userinfo['timezone'] + ($bugsys->userinfo['usedst'] * 1);
156 $bugsys->debug('user tz = ' . $bugsys->userinfo['timezone'] . '; use version = ' . $datef->usertz);
157 $datef->fetch_offset();
158
159 // ###################################################################
160 // mail system
161 $bugsys->load('mail', 'mail', true);
162 $mail->setFromAddress($bugsys->options['webmasteremail']);
163 $mail->setFromName(_('Bugdar Notification'));
164
165 /*=====================================================================*\
166 || ###################################################################
167 || # $HeadURL$
168 || # $Id$
169 || ###################################################################
170 \*=====================================================================*/
171 ?>