init.php is now largely upgraded
[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 // load the framework
26
27 define('ISSO_MT_START', microtime());
28 define('ISSO_CHECK_POST_REFERER', 1);
29
30 require_once('./includes/version.php');
31
32 if (!file_exists('./includes/config.php'))
33 {
34 echo 'includes/config.php needs to be present!';
35 exit;
36 }
37
38 require_once('./includes/config.php');
39
40 define('ISSO', getcwd() . '/includes/framework/');
41 require_once ISSO . '/App.php';
42 BSApp::set_debug($debug);
43
44 // ###################################################################
45 // initialize the database
46
47 require_once ISSO . '/DbMySqlI.php';
48 $db = BSApp::$db = new BSDBMySQLI();
49
50 $db->connect($servername, $username, $password, $database);
51 if ($utf8)
52 {
53 $db->query("SET NAMES utf8");
54 }
55
56 require_once ISSO . '/Functions.php';
57
58 // change cookie expiration to one hour
59 BSFunctions::set_cookie_timeout(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 foreach ($datastoretemp as $store)
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 // ###################################################################
110 // load permissions
111
112 require_once('./includes/permissions.php');
113
114 // ###################################################################
115 // load userinfo
116
117 $authMethod = ((defined('USE_DEFAULT_AUTH_METHOD') AND constant('USE_DEFAULT_AUTH_METHOD') == 1) ? 'default' : $bugsys->options['authmethod']);
118 require_once('./includes/auth/auth_' . $authMethod . '.php');
119
120 $authClass = 'Authentication' . str_replace(' ', '', ucwords(str_replace('_', ' ', $authMethod)));
121 $bugsys->auth = $auth = new $authClass();
122
123 if ($auth->authenticateCookies())
124 {
125 $bugsys->userinfo = $auth->fetchBugdarUser();
126 $bugsys->userinfo['permissions'] = FetchUserPermissions($bugsys->userinfo);
127 $bugsys->userinfo['displaytitle'] = $bugsys->datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['displaytitle'];
128 $bugsys->userinfo['columnoptions'] = unserialize($bugsys->userinfo['columnoptions']);
129 }
130 else
131 {
132 $bugsys->userinfo = fetch_guest_user();
133 }
134
135 // ###################################################################
136 // initialize localization system
137
138 $language = fetch_user_language();
139
140 $stylevar['lang'] = $language['langcode'];
141 $stylevar['lang_dir'] = $language['direction'];
142 $stylevar['charset'] = $language['charset'];
143 $stylevar['left'] = ($language['direction'] == 'ltr' ? 'left' : 'right');
144 $stylevar['right'] = ($language['direction'] == 'ltr' ? 'right' : 'left');
145
146 // start gettext engine
147 if (!$bugsys->options['devgettext'])
148 {
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 else
160 {
161 $bugsys->debug("using custom MOReader instead of Gettext");
162 }
163
164 // ###################################################################
165 // initialize the date system
166 require_once ISSO . '/Date.php';
167 $datef = BSApp::$date = new BSDate();
168 $datef->setUserTimeZone($bugsys->userinfo['timezone'] + ($bugsys->userinfo['usedst'] * 1));
169 $bugsys->debug('user tz = ' . $bugsys->userinfo['timezone'] . '; use version = ' . $datef->usertz);
170
171 // ###################################################################
172 // mail system
173 $bugsys->load('mail', 'mail', true);
174 $mail->setFromAddress($bugsys->options['webmasteremail']);
175 $mail->setFromName(T('Bugdar Notification'));
176
177 /*=====================================================================*\
178 || ###################################################################
179 || # $HeadURL$
180 || # $Id$
181 || ###################################################################
182 \*=====================================================================*/
183 ?>