r206: Allow bugs to be hidden for security reasons or if they want to look deleted.
[bugdar.git] / includes / init.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 error_reporting(E_ALL & ~E_NOTICE);
14
15 // ###################################################################
16 // initialize the database
17
18 if (!file_exists('./includes/config.php'))
19 {
20 echo 'includes/config.php needs to be present!';
21 exit;
22 }
23
24 require_once('./includes/config.php');
25
26 define('ISSO_ESCAPE_STRINGS', 1);
27 define('ISSO_CHECK_POST_REFERER', 1);
28
29 require_once($pathtoisso . 'kernel.php');
30 $bugsys =& $_isso;
31 $bugsys->application = 'BugStrike';
32 $bugsys->apppath = $bugsys->fetch_sourcepath(getcwd());
33 $bugsys->appversion = '[#]version[#]';
34 $bugsys->debug = $debug;
35 $bugsys->sourcepath = $bugsys->fetch_sourcepath($pathtoisso);
36
37 $bugsys->load('db_mysql');
38 $db->database = $database;
39 $db->connect($servername, $username, $password, $usepconnect);
40
41 $bugsys->load('functions');
42 $bugsys->load('mail');
43 $bugsys->exec_sanitize_data();
44
45 // change cookie expiration to one hour
46 $funct->cookieexp = 3600;
47
48 define('DEVDEBUG', $debug);
49 define('TABLE_PREFIX', $tableprefix);
50 define('COOKIE_PREFIX', $cookieprefix);
51
52 unset($database, $servername, $username, $password, $usepconnect, $tableprefix, $cookieprefix);
53
54 define('LOG_TIME', time());
55
56 require_once('./includes/functions_datastore.php');
57 require_once('./includes/functions.php');
58
59 // ###################################################################
60 // init the big four
61 $bugsys->options = array();
62 $bugsys->userinfo = array();
63 $bugsys->language = array();
64 $bugsys->datastore = array();
65
66 // ###################################################################
67 // populate our caches
68 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
69 while ($store = $db->fetch_array($datastoretemp))
70 {
71 $bugsys->datastore["$store[title]"] = unserialize($store['data']);
72 }
73 $bugsys->options = $bugsys->datastore['setting'];
74 unset($bugsys->datastore['setting']);
75
76 $mail->from = $bugsys->options['webmasteremail'];
77 $mail->fromname = 'BugStrike Notification';
78
79 // ###################################################################
80 // load userinfo
81 $userid = intval($_COOKIE[COOKIE_PREFIX . 'userid']);
82
83 $userinfo = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = $userid");
84 if (is_array($userinfo) AND $_COOKIE[COOKIE_PREFIX . 'authkey'] == $userinfo['authkey'])
85 {
86 $userinfo['permissions'] = (int)$bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['permissions'];
87 $userinfo['displaytitle'] = $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['displaytitle'];
88 fetch_user_display_name($userinfo);
89 $userinfo['mdisplayname'] = $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['opentag'] . $userinfo['displayname'] . $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['closetag'];
90 $bugsys->userinfo = $userinfo;
91 $funct->cookie(COOKIE_PREFIX . 'userid', $bugsys->userinfo['userid']);
92 $funct->cookie(COOKIE_PREFIX . 'authkey', $bugsys->userinfo['authkey']);
93 }
94 else
95 {
96 $funct->cookie(COOKIE_PREFIX . 'userid');
97 $funct->cookie(COOKIE_PREFIX . 'authkey');
98 $bugsys->userinfo = array(
99 'usergroupid' => 1,
100 'userid' => 0,
101 'email' => '',
102 'displayname' => '',
103 'permissions' => $bugsys->datastore['usergroup'][1]['permissions'],
104 'displaytitle' => $bugsys->datastore['usergroup'][1]['displaytitle'],
105 'mdisplayname' => $bugsys->datastore['usergroup'][1]['opentag'] . '' . $bugsys->datastore['usergroup'][1]['closetag']
106 );
107 }
108
109 // ###################################################################
110 // pull our languageid
111 if ($bugsys->userinfo['userid'])
112 {
113 $languageid = $bugsys->userinfo['languageid'];
114 $language = $bugsys->datastore['language']["$languageid"];
115 }
116 if (!$languageid)
117 {
118 foreach ($bugsys->datastore['language'] AS $language)
119 {
120 if ($language['default'])
121 {
122 $languageid = $language['languageid'];
123 $language = $bugsys->datastore['language']["$languageid"];
124 break;
125 }
126 }
127 }
128
129 $bugsys->options['lang_id'] = $language['languageid'];
130 $bugsys->options['lang_charset'] = $language['charset'];
131 $bugsys->options['lang_dir'] = $language['direction'];
132 $bugsys->options['lang_code'] = $language['languagecode'];
133
134 // ###################################################################
135 // load master language
136 /*
137 // can't use this because not everyone has MySQL >= 4.0.17 ... one day, one day
138 $phrases = $db->query("
139 (SELECT varname, phrasetext FROM " . TABLE_PREFIX . "phrase)
140 UNION DISTINCT
141 (SELECT varname AS lvarname, phrasetext AS lphrasetext FROM " . TABLE_PREFIX . "locale AS locale WHERE languageid = " . $bugsys->options['lang_id'] . ")"
142 );
143 while ($phrase = $db->fetch_array($phrases))
144 {
145 $bugsys->language["$phrase[varname]"] = $phrase['phrasetext'];
146 }
147 $db->free_result($phrases);
148 */
149
150 $phrases = $db->query("SELECT * FROM " . TABLE_PREFIX . "phrase");
151 while ($phrase = $db->fetch_array($phrases))
152 {
153 $bugsys->language["$phrase[varname]"] = $phrase['phrasetext'];
154 }
155 $db->free_result($phrases);
156
157 // ###################################################################
158 // load locale data
159 $locale = $db->query("SELECT * FROM " . TABLE_PREFIX . "locale WHERE languageid = " . intval($bugsys->options['lang_id']));
160 while ($phrase = $db->fetch_array($locale))
161 {
162 $bugsys->language["$phrase[varname]"] = $phrase['phrasetext'];
163 }
164 $db->free_result($phrases);
165
166 // ###################################################################
167 // Initialize usergroup system
168 $_PERMISSION = array(
169 'canviewbugs' => 1, // can view bugs
170 'cansearch' => 2, // can use the search
171 'cansubscribe' => 4, // can email subscribe
172 'canvote' => 8, // can vote on bugs
173 'cansubmitbugs' => 16, // can submit new bugs
174 'canpostcomments' => 32, // can post new comments
175 'cangetattach' => 64, // can dl attachments
176 'canputattach' => 128, // can ul attachments
177 'caneditown' => 256, // can edit own comments
178 'caneditothers' => 512, // can edit others' comments
179 'caneditinfo' => 1024, // can edit bug info -- works in conjunction with canedit(own|others)
180 'canassign' => 2048, // can assign bug
181 'canchangestatus' => 4096, // can change bug status
182 'canadminpanel' => 8192, // can view admin panel
183 'canadminbugs' => 16384, // can administrate bug functions
184 'canadminversions' => 32768, // can admin version info
185 'canadminusers' => 65536, // can admin users
186 'canadmingroups' => 131072, // can admin permission masks
187 'canadmintools' => 262144, // can use admin tools
188 'canadminfields' => 524288, // can admin custom bug fields
189 'canbeassignedto' => 1048576, // can be assigned bugs,
190 'caneditattach' => 2097152, // can edit attachments
191 'canviewhiddenbugs' => 4194304 // can see hidden bugs
192 );
193
194 foreach ($_PERMISSION AS $name => $maskvalue)
195 {
196 define(strtoupper($name), $maskvalue);
197 }
198
199 /*=====================================================================*\
200 || ###################################################################
201 || # $HeadURL$
202 || # $Id$
203 || ###################################################################
204 \*=====================================================================*/
205 ?>