r768: Setting `debug` needs to happen after we load config.php
[bugdar.git] / includes / init.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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->set('application', 'Bugdar');
34 $bugsys->set('appversion', '[#]verson[#]');
35
36 if (!file_exists('./includes/config.php'))
37 {
38 echo 'includes/config.php needs to be present!';
39 exit;
40 }
41
42 require_once('./includes/config.php');
43
44 $bugsys->set('debug', $debug);
45
46 define('ISSO_DB_LAYER', 'db_mysql');
47 $bugsys->load('db_mysql', 'db', true);
48 $db->connect($servername, $username, $password, $database, $usepconnect);
49
50 $bugsys->load('functions', 'funct', true);
51 $bugsys->exec_sanitize_data();
52
53 $bugsys->load('xml', 'xml', true);
54
55 // change cookie expiration to one hour
56 $funct->cookieexp = 3600;
57
58 define('DEVDEBUG', $debug);
59 define('TABLE_PREFIX', $tableprefix);
60 define('COOKIE_PREFIX', $cookieprefix);
61
62 unset($database, $servername, $theuser, $password, $thepass, $usepconnect, $tableprefix, $cookieprefix);
63
64 require_once('./includes/functions_datastore.php');
65 require_once('./includes/functions.php');
66
67 // ###################################################################
68 // init the big three
69 $bugsys->options = array();
70 $bugsys->userinfo = array();
71 $bugsys->datastore = array();
72
73 // ###################################################################
74 // send nocache
75 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
76 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
77 header("Cache-Control: no-store, no-cache, must-revalidate");
78 header("Cache-Control: post-check=0, pre-check=0", false);
79 header("Pragma: no-cache");
80
81 // ###################################################################
82 // populate our caches
83 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
84 while ($store = $db->fetch_array($datastoretemp))
85 {
86 $bugsys->datastore["$store[title]"] = unserialize($store['data']);
87 }
88 $bugsys->options = $bugsys->datastore['setting'];
89 unset($bugsys->datastore['setting']);
90
91 // ###################################################################
92 // load userinfo
93 $userid = intval($bugsys->in[COOKIE_PREFIX . 'userid']);
94
95 if ($userid)
96 {
97 $userinfo = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = $userid");
98 if (is_array($userinfo) AND $bugsys->in[COOKIE_PREFIX . 'authkey'] == $userinfo['authkey'])
99 {
100 $userinfo['permissions'] = (int)$bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['permissions'];
101 $userinfo['displaytitle'] = $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['displaytitle'];
102 $bugsys->userinfo = $userinfo;
103 $funct->cookie(COOKIE_PREFIX . 'userid', $bugsys->userinfo['userid']);
104 $funct->cookie(COOKIE_PREFIX . 'authkey', $bugsys->userinfo['authkey']);
105 }
106 }
107
108 if (!$userinfo)
109 {
110 $funct->cookie(COOKIE_PREFIX . 'userid');
111 $funct->cookie(COOKIE_PREFIX . 'authkey');
112 $bugsys->userinfo = array(
113 'usergroupid' => 1,
114 'userid' => 0,
115 'email' => '',
116 'displayname' => '',
117 'showcolours' => 1,
118 'permissions' => $bugsys->datastore['usergroup'][1]['permissions'],
119 'displaytitle' => $bugsys->datastore['usergroup'][1]['displaytitle'],
120 );
121 }
122
123 // ###################################################################
124 // initialize localization system
125 $bugsys->load('localize', 'lang', true);
126
127 require_once('./includes/language.php');
128
129 $LANGDATA = fetch_user_language();
130 $lang->init_with_table(fetch_strings($LANGDATA['id']));
131
132 $stylevar['lang'] = $LANGDATA['code'];
133 $stylevar['lang_dir'] = $LANGDATA['direction'];
134 $stylevar['charset'] = $LANGDATA['charset'];
135
136 // ###################################################################
137 // initialize the date system
138 $bugsys->load('date', 'datef', true);
139 $datef->usertz = $bugsys->userinfo['timezone'];
140 $datef->fetch_offset();
141
142 // ###################################################################
143 // mail system
144 $bugsys->load('mail', 'mail', true);
145 $mail->set('from', $bugsys->options['webmasteremail']);
146 $mail->set('fromname', $lang->string('Bugdar Notification'));
147
148 // ###################################################################
149 // load permissions
150
151 require_once('./includes/permissions.php');
152
153 /*=====================================================================*\
154 || ###################################################################
155 || # $HeadURL$
156 || # $Id$
157 || ###################################################################
158 \*=====================================================================*/
159 ?>