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