r63: Updated initial copyright year from 2003 to 2002
[bugdar.git] / includes / init.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Renapsus [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2002-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2002 - [#]year[#] Iris Studios, Inc. | http://www.iris-studios.com # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 error_reporting(E_ALL & ~E_NOTICE);
14
15 // ###################################################################
16 if (PHP_VERSION < '4.1.0')
17 {
18 echo 'you do not have a new enough version of PHP';
19 exit;
20 }
21
22 // ###################################################################
23 // set quotes runtime
24 set_magic_quotes_runtime(0);
25
26 // ###################################################################
27 // Initialize the database
28 if (!file_exists('./includes/config.php'))
29 {
30 echo 'includes/config.php needs to be present!';
31 exit;
32 }
33
34 require_once('./includes/config.php');
35 require_once('./includes/db_mysql.php');
36
37 $DB_sql = new DB_Sql();
38 $DB_sql->appname = 'Renapsus';
39 $DB_sql->database = $database;
40 $DB_sql->connect($servername, $username, $password, $usepconnect);
41 define('DEVDEBUG', $debug);
42 define('TABLE_PREFIX', $tableprefix);
43 define('COOKIE_PREFIX', $cookieprefix);
44 unset($database, $servername, $username, $password, $usepconnect, $tableprefix, $cookieprefix);
45
46 // ###################################################################
47 // Initialize our environment
48 require_once('./includes/functions_datastore.php');
49 require_once('./includes/functions.php');
50 class BugTracker
51 {
52 var $options = array();
53 var $userinfo = array();
54 var $language = array();
55 var $datastore = array();
56
57 function BugTracker()
58 {
59 global $DB_sql, $vars;
60
61 // Fetch all the datastore caches
62 $datastoretemp = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
63 while ($store = $DB_sql->fetch_array($datastoretemp))
64 {
65 $this->datastore["$store[title]"] = unserialize($store['data']);
66 }
67
68 // Assign options and fetch the userinfo
69 $this->options = $this->datastore['setting'];
70 unset($this->datastore['setting']);
71 $this->userinfo = (array)$this->fetch_userinfo(-1, true);
72
73 // Pull our languageid
74 if ($this->userinfo['userid'])
75 {
76 $languageid = $this->userinfo['languageid'];
77 $language = $this->datastore['language']["$languageid"];
78 }
79 if (!$languageid)
80 {
81 foreach ($this->datastore['language'] AS $language)
82 {
83 if ($language['default'])
84 {
85 $languageid = $language['languageid'];
86 $language = $this->datastore['language']["$languageid"];
87 break;
88 }
89 }
90 }
91
92 $this->options['lang_id'] = $language['languageid'];
93 $this->options['lang_charset'] = $language['charset'];
94 $this->options['lang_dir'] = $language['direction'];
95 $this->options['lang_code'] = $language['languagecode'];
96
97 /*
98 // can't use this because not everyone has MySQL >= 4.0.17 ... one day, one day
99 $phrases = $DB_sql->query("
100 (SELECT varname, phrasetext FROM " . TABLE_PREFIX . "phrase)
101 UNION DISTINCT
102 (SELECT varname AS lvarname, phrasetext AS lphrasetext FROM " . TABLE_PREFIX . "locale AS locale WHERE languageid = " . $this->options['lang_id'] . ")"
103 );
104 while ($phrase = $DB_sql->fetch_array($phrases))
105 {
106 $this->language["$phrase[varname]"] = $phrase['phrasetext'];
107 }
108 $DB_sql->free_result($phrases);
109 */
110
111 // load master language
112 $phrases = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "phrase");
113 while ($phrase = $DB_sql->fetch_array($phrases))
114 {
115 $this->language["$phrase[varname]"] = $phrase['phrasetext'];
116 }
117 $DB_sql->free_result($phrases);
118
119 // load locale data
120 $locale = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "locale WHERE languageid = " . $this->options['lang_id']);
121 while ($phrase = $DB_sql->fetch_array($locale))
122 {
123 $this->language["$phrase[varname]"] = $phrase['phrasetext'];
124 }
125 $DB_sql->free_result($phrases);
126
127 // get the templateset
128 if ($this->userinfo['userid'])
129 {
130 $templatesetid = $this->userinfo['templatesetid'];
131 $templateset = $this->datastore['templateset']["$templatesetid"];
132 }
133 if (!$templatesetid)
134 {
135 foreach ($this->datastore['templateset'] AS $templateset)
136 {
137 if ($templateset['default'])
138 {
139 $templatesetid = $templateset['templatesetid'];
140 $templateset = $this->datastore['templateset']["$templatesetid"];
141 }
142 }
143 }
144
145 // load the template system
146 if (file_exists("./templates/$templateset[shortname]/tsinfo.php"))
147 {
148 $this->options['ts_includepath'] = "./templates/$templateset[shortname]/";
149 }
150 else
151 {
152 echo "template set info (templates/$templateset[shortname]/tsinfo.php) could not be loaded!";
153 exit;
154 }
155 }
156
157 function fetch_userinfo($userid = -1, $verify_password = false)
158 {
159 global $DB_sql;
160
161 // Get the userid if not specified
162 if ($userid == -1)
163 {
164 $userid = intval($_COOKIE[COOKIE_PREFIX . 'userid']);
165 }
166
167 // Set the falseinfo stuff
168 $falseinfo = array(
169 'usergroupid' => 1,
170 'userid' => 0,
171 'email' => '',
172 'displayname' => '',
173 'permissions' => $this->datastore['usergroup'][1]['permissions'],
174 'displaytitle' => $this->datastore['usergroup'][1]['displaytitle'],
175 'mdisplayname' => $this->datastore['usergroup'][1]['opentag'] . '' . $this->datastore['usergroup'][1]['closetag']
176 );
177
178 // Get the userinfo
179 $userinfo = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = $userid");
180 if (is_array($userinfo))
181 {
182 $userinfo['permissions'] = (int)$this->datastore['usergroup']["$userinfo[usergroupid]"]['permissions'];
183 $userinfo['displaytitle'] = $this->datastore['usergroup']["$userinfo[usergroupid]"]['displaytitle'];
184 fetch_user_display_name($userinfo);
185 $userinfo['mdisplayname'] = $this->datastore['usergroup']["$userinfo[usergroupid]"]['opentag'] . $userinfo['displayname'] . $this->datastore['usergroup']["$userinfo[usergroupid]"]['closetag'];
186 // Verify that the cookie isn't fake
187 if ($verify_password)
188 {
189 if ($_COOKIE[COOKIE_PREFIX . 'authkey'] == $userinfo['authkey'])
190 {
191 return $userinfo;
192 }
193 else
194 {
195 mysetcookie(COOKIE_PREFIX . 'userid');
196 mysetcookie(COOKIE_PREFIX . 'authkey');
197 return $falseinfo;
198 }
199 }
200 else
201 {
202 return $userinfo;
203 }
204 }
205 else
206 {
207 mysetcookie(COOKIE_PREFIX . 'userid');
208 mysetcookie(COOKIE_PREFIX . 'authkey');
209 return $falseinfo;
210 }
211 }
212 }
213
214 $bugsys = new BugTracker();
215
216 // ###################################################################
217 // Initialize usergroup system
218 $_PERMISSION = array(
219 'canviewbugs' => 1, // can view bugs
220 'cansearch' => 2, // can use the search
221 'cansubscribe' => 4, // can email subscribe
222 'canvote' => 8, // can vote on bugs
223 'cansubmitbugs' => 16, // can submit new bugs
224 'canpostcomments' => 32, // can post new comments
225 'cangetattach' => 64, // can dl attachments
226 'canputattach' => 128, // can ul attachments
227 'caneditown' => 256, // can edit own comments
228 'caneditothers' => 512, // can edit others' comments
229 'caneditinfo' => 1024, // can edit bug info -- works in conjunction with canedit(own|others)
230 'canassign' => 2048, // can assign bug
231 'canchangestatus' => 4096, // can change bug status
232 'canadminpanel' => 8192, // can view admin panel
233 'canadminbugs' => 16384, // can administrate bug functions
234 'canadminversions' => 32768, // can admin version info
235 'canadminusers' => 65536, // can admin users
236 'canadmingroups' => 131072, // can admin permission masks
237 'canadmintools' => 262144, // can use admin tools
238 'canadminfields' => 524288, // can admin custom bug fields
239 'canbeassignedto' => 1048576 // can be assigned bugs
240 );
241
242 foreach ($_PERMISSION AS $name => $maskvalue)
243 {
244 define(strtoupper($name), $maskvalue);
245 }
246
247 /*=====================================================================*\
248 || ###################################################################
249 || # $HeadURL$
250 || # $Id$
251 || ###################################################################
252 \*=====================================================================*/
253 ?>