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