r33: Named product Renapsus.
[bugdar.git] / includes / init.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Renapsus [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # All parts of this file are ©2003-[#]year[#] Iris Studios, Inc. No # ||
7 || # part of this file may be reproduced in any way: part or whole. # ||
8 || # --------------------------------------------------------------- # ||
9 || # ©2003 - [#]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 // Load language system
93 if (file_exists("./locale/$language[filename]"))
94 {
95 require_once("./locale/$language[filename]");
96 $this->language = $language;
97 $this->options['lang_charset'] = $cfg['charset'];
98 $this->options['lang_dir'] = $cfg['direction'];
99 $this->options['lang_code'] = $cfg['languagecode'];
100 unset($language);
101 }
102 else
103 {
104 echo "language file (locale/$language[filename]) could not be loaded!";
105 exit;
106 }
107
108 // get the templateset
109 if ($this->userinfo['userid'])
110 {
111 $templatesetid = $this->userinfo['templatesetid'];
112 $templateset = $this->datastore['templateset']["$templatesetid"];
113 }
114 if (!$templatesetid)
115 {
116 foreach ($this->datastore['templateset'] AS $templateset)
117 {
118 if ($templateset['default'])
119 {
120 $templatesetid = $templateset['templatesetid'];
121 $templateset = $this->datastore['templateset']["$templatesetid"];
122 }
123 }
124 }
125
126 // load the template system
127 if (file_exists("./templates/$templateset[shortname]/tsinfo.php"))
128 {
129 $this->options['ts_includepath'] = "./templates/$templateset[shortname]/";
130 }
131 else
132 {
133 echo "template set info (templates/$templateset[shortname]/tsinfo.php) could not be loaded!";
134 exit;
135 }
136 }
137
138 function fetch_userinfo($userid = -1, $verify_password = false)
139 {
140 global $DB_sql;
141
142 // Get the userid if not specified
143 if ($userid == -1)
144 {
145 $userid = intval($_COOKIE[COOKIE_PREFIX . 'userid']);
146 }
147
148 // Set the falseinfo stuff
149 $falseinfo = array(
150 'usergroupid' => 1,
151 'userid' => 0,
152 'email' => '',
153 'displayname' => '',
154 'permissions' => $this->datastore['usergroup'][1]['permissions'],
155 'displaytitle' => $this->datastore['usergroup'][1]['displaytitle'],
156 'mdisplayname' => $this->datastore['usergroup'][1]['opentag'] . '' . $this->datastore['usergroup'][1]['closetag']
157 );
158
159 // Get the userinfo
160 $userinfo = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = $userid");
161 if (is_array($userinfo))
162 {
163 $userinfo['permissions'] = (int)$this->datastore['usergroup']["$userinfo[usergroupid]"]['permissions'];
164 $userinfo['displaytitle'] = $this->datastore['usergroup']["$userinfo[usergroupid]"]['displaytitle'];
165 fetch_user_display_name($userinfo);
166 $userinfo['mdisplayname'] = $this->datastore['usergroup']["$userinfo[usergroupid]"]['opentag'] . $userinfo['displayname'] . $this->datastore['usergroup']["$userinfo[usergroupid]"]['closetag'];
167 // Verify that the cookie isn't fake
168 if ($verify_password)
169 {
170 if ($_COOKIE[COOKIE_PREFIX . 'authkey'] == $userinfo['authkey'])
171 {
172 return $userinfo;
173 }
174 else
175 {
176 mysetcookie(COOKIE_PREFIX . 'userid');
177 mysetcookie(COOKIE_PREFIX . 'authkey');
178 return $falseinfo;
179 }
180 }
181 else
182 {
183 return $userinfo;
184 }
185 }
186 else
187 {
188 mysetcookie(COOKIE_PREFIX . 'userid');
189 mysetcookie(COOKIE_PREFIX . 'authkey');
190 return $falseinfo;
191 }
192 }
193 }
194
195 $bugsys = new BugTracker();
196
197 // ###################################################################
198 // Initialize usergroup system
199 $_PERMISSION = array(
200 'canviewbugs' => 1, // can view bugs
201 'cansearch' => 2, // can use the search
202 'cansubscribe' => 4, // can email subscribe
203 'canvote' => 8, // can vote on bugs
204 'cansubmitbugs' => 16, // can submit new bugs
205 'canpostcomments' => 32, // can post new comments
206 'cangetattach' => 64, // can dl attachments
207 'canputattach' => 128, // can ul attachments
208 'caneditown' => 256, // can edit own comments
209 'caneditothers' => 512, // can edit others' comments
210 'caneditinfo' => 1024, // can edit bug info -- works in conjunction with canedit(own|others)
211 'canassign' => 2048, // can assign bug
212 'canchangestatus' => 4096, // can change bug status
213 'canadminpanel' => 8192, // can view admin panel
214 'canadminbugs' => 16384, // can administrate bug functions
215 'canadminversions' => 32768, // can admin version info
216 'canadminusers' => 65536, // can admin users
217 'canadmingroups' => 131072, // can admin permission masks
218 'canadmintools' => 262144, // can use admin tools
219 'canadminfields' => 524288, // can admin custom bug fields
220 'canbeassignedto' => 1048576 // can be assigned bugs
221 );
222
223 foreach ($_PERMISSION AS $name => $maskvalue)
224 {
225 define(strtoupper($name), $maskvalue);
226 }
227
228 /*=====================================================================*\
229 || ###################################################################
230 || # $HeadURL$
231 || # $Id$
232 || ###################################################################
233 \*=====================================================================*/
234 ?>