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