Record total memory usage in debug messages.
[bugdar.git] / includes / init.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)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_MEMORY_START', memory_get_usage(true));
29 define('ISSO_CHECK_POST_REFERER', 1);
30
31 require_once('./includes/version.php');
32
33 require_once('./framework/kernel.php');
34 $bugsys = new ISSO();
35
36 $bugsys->setAppPath(getcwd());
37 $bugsys->setApplication('Bugdar');
38 $bugsys->setAppVersion(BUGDAR_VERSION);
39
40 if (!file_exists('./includes/config.php'))
41 {
42 echo 'includes/config.php needs to be present!';
43 exit;
44 }
45
46 require_once('./includes/config.php');
47
48 $bugsys->setDebug($debug);
49
50 $bugsys->load('db_mysql_pdo', 'db', true);
51 $db->connect($servername, $username, $password, $database, $usepconnect);
52 if ($utf8)
53 {
54 $db->query("SET NAMES utf8");
55 }
56
57 // don't use sql strict mode
58 $db->query("SET sql_mode = ''");
59
60 $bugsys->load('functions', 'funct', true);
61 $bugsys->load('xml', 'xml', true);
62
63 // change cookie expiration to one hour
64 $funct->cookieexp = 3600;
65
66 define('DEVDEBUG', $debug);
67 define('TABLE_PREFIX', $tableprefix);
68 define('COOKIE_PREFIX', $cookieprefix);
69
70 unset($database, $servername, $theuser, $password, $thepass, $usepconnect, $tableprefix, $cookieprefix);
71
72 require_once('./includes/functions_datastore.php');
73 require_once('./includes/functions.php');
74 require_once('./includes/language.php');
75
76 // ###################################################################
77 // init the big three
78 $bugsys->options = array();
79 $bugsys->userinfo = array();
80 bugdar::$datastore = array();
81
82 class bugdar
83 {
84 static $db = NULL;
85
86 static $options = array();
87 static $user = array();
88 static $datastore = array();
89 }
90
91 bugdar::$db = $db->dblink;
92
93 // ###################################################################
94 // send nocache
95 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
96 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
97 header("Cache-Control: no-store, no-cache, must-revalidate");
98 header("Cache-Control: post-check=0, pre-check=0", false);
99 if ($utf8)
100 {
101 header("Content-Type: text/html; charset=\"utf8\"");
102 }
103 header("Pragma: no-cache");
104
105 // ###################################################################
106 // populate our caches
107 $db->showerrors = false;
108 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
109 $db->showerrors = true;
110
111 if (!$datastoretemp)
112 {
113 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 />';
114 $db->error('Invalid SQL error');
115 }
116
117 while ($store = $db->fetch_array($datastoretemp))
118 {
119 bugdar::$datastore["$store[title]"] = unserialize($store['data']);
120 }
121
122 $bugsys->options = bugdar::$datastore['setting'];
123 $bugsys->options['columnoptions'] = unserialize($bugsys->options['columnoptions']);
124 unset(bugdar::$datastore['setting']);
125 bugdar::$options = $bugsys->options;
126
127 $bugsys->setAppVersion($bugsys->options['trackerversion']);
128
129 // ###################################################################
130 // load permissions
131
132 require_once('./includes/permissions.php');
133
134 // ###################################################################
135 // load userinfo
136
137 $authMethod = ((defined('USE_DEFAULT_AUTH_METHOD') AND constant('USE_DEFAULT_AUTH_METHOD') == 1) ? 'default' : $bugsys->options['authmethod']);
138 require_once('./includes/auth/auth_' . $authMethod . '.php');
139
140 $authClass = 'Authentication' . str_replace(' ', '', ucwords(str_replace('_', ' ', $authMethod)));
141 $bugsys->auth = $auth = new $authClass();
142
143 if ($auth->authenticateCookies())
144 {
145 $bugsys->userinfo = $auth->fetchBugdarUser();
146 $bugsys->userinfo['permissions'] = FetchUserPermissions($bugsys->userinfo);
147 $bugsys->userinfo['displaytitle'] = bugdar::$datastore['usergroup'][ $bugsys->userinfo['usergroupid'] ]['displaytitle'];
148 $bugsys->userinfo['columnoptions'] = unserialize($bugsys->userinfo['columnoptions']);
149 }
150 else
151 {
152 $bugsys->userinfo = fetch_guest_user();
153 }
154 bugdar::$user = $bugsys->userinfo;
155
156 // ###################################################################
157 // initialize localization system
158
159 $language = fetch_user_language();
160
161 $stylevar['lang'] = $language['langcode'];
162 $stylevar['lang_dir'] = $language['direction'];
163 $stylevar['charset'] = $language['charset'];
164 $stylevar['left'] = ($language['direction'] == 'ltr' ? 'left' : 'right');
165 $stylevar['right'] = ($language['direction'] == 'ltr' ? 'right' : 'left');
166
167 require_once('./includes/definitions.php');
168
169 // ###################################################################
170 // initialize the date system
171 $bugsys->load('date', 'datef', true);
172 $datef->usertz = $bugsys->userinfo['timezone'] + ($bugsys->userinfo['usedst'] * 1);
173 $bugsys->debug('user tz = ' . $bugsys->userinfo['timezone'] . '; use version = ' . $datef->usertz);
174 $datef->fetch_offset();
175
176 // ###################################################################
177 // mail system
178 $bugsys->load('mail', 'mail', true);
179 $mail->setFromAddress($bugsys->options['webmasteremail']);
180 $mail->setFromName(T('Bugdar Notification'));
181