r150: Updated logging system to have one entry per changed field. We then group these...
[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 define('DEVDEBUG', $debug);
46 define('TABLE_PREFIX', $tableprefix);
47 define('COOKIE_PREFIX', $cookieprefix);
48
49 unset($database, $servername, $username, $password, $usepconnect, $tableprefix, $cookieprefix);
50
51 define('LOG_TIME', time());
52
53 require_once('./includes/functions_datastore.php');
54 require_once('./includes/functions.php');
55
56 // ###################################################################
57 // init the big four
58 $bugsys->options = array();
59 $bugsys->userinfo = array();
60 $bugsys->language = array();
61 $bugsys->datastore = array();
62
63 // ###################################################################
64 // populate our caches
65 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
66 while ($store = $db->fetch_array($datastoretemp))
67 {
68 $bugsys->datastore["$store[title]"] = unserialize($store['data']);
69 }
70 $bugsys->options = $bugsys->datastore['setting'];
71 unset($bugsys->datastore['setting']);
72
73 $mail->from = $bugsys->options['webmasteremail'];
74 $mail->fromname = 'BugStrike Notification';
75
76 // ###################################################################
77 // load userinfo
78 $userid = intval($_COOKIE[COOKIE_PREFIX . 'userid']);
79
80 $userinfo = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = $userid");
81 if (is_array($userinfo) AND $_COOKIE[COOKIE_PREFIX . 'authkey'] == $userinfo['authkey'])
82 {
83 $userinfo['permissions'] = (int)$bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['permissions'];
84 $userinfo['displaytitle'] = $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['displaytitle'];
85 fetch_user_display_name($userinfo);
86 $userinfo['mdisplayname'] = $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['opentag'] . $userinfo['displayname'] . $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['closetag'];
87 $bugsys->userinfo = $userinfo;
88 }
89 else
90 {
91 $funct->cookie(COOKIE_PREFIX . 'userid');
92 $funct->cookie(COOKIE_PREFIX . 'authkey');
93 $bugsys->userinfo = array(
94 'usergroupid' => 1,
95 'userid' => 0,
96 'email' => '',
97 'displayname' => '',
98 'permissions' => $bugsys->datastore['usergroup'][1]['permissions'],
99 'displaytitle' => $bugsys->datastore['usergroup'][1]['displaytitle'],
100 'mdisplayname' => $bugsys->datastore['usergroup'][1]['opentag'] . '' . $bugsys->datastore['usergroup'][1]['closetag']
101 );
102 }
103
104 // ###################################################################
105 // pull our languageid
106 if ($bugsys->userinfo['userid'])
107 {
108 $languageid = $bugsys->userinfo['languageid'];
109 $language = $bugsys->datastore['language']["$languageid"];
110 }
111 if (!$languageid)
112 {
113 foreach ($bugsys->datastore['language'] AS $language)
114 {
115 if ($language['default'])
116 {
117 $languageid = $language['languageid'];
118 $language = $bugsys->datastore['language']["$languageid"];
119 break;
120 }
121 }
122 }
123
124 $bugsys->options['lang_id'] = $language['languageid'];
125 $bugsys->options['lang_charset'] = $language['charset'];
126 $bugsys->options['lang_dir'] = $language['direction'];
127 $bugsys->options['lang_code'] = $language['languagecode'];
128
129 // ###################################################################
130 // load master language
131 /*
132 // can't use this because not everyone has MySQL >= 4.0.17 ... one day, one day
133 $phrases = $db->query("
134 (SELECT varname, phrasetext FROM " . TABLE_PREFIX . "phrase)
135 UNION DISTINCT
136 (SELECT varname AS lvarname, phrasetext AS lphrasetext FROM " . TABLE_PREFIX . "locale AS locale WHERE languageid = " . $bugsys->options['lang_id'] . ")"
137 );
138 while ($phrase = $db->fetch_array($phrases))
139 {
140 $bugsys->language["$phrase[varname]"] = $phrase['phrasetext'];
141 }
142 $db->free_result($phrases);
143 */
144
145 $phrases = $db->query("SELECT * FROM " . TABLE_PREFIX . "phrase");
146 while ($phrase = $db->fetch_array($phrases))
147 {
148 $bugsys->language["$phrase[varname]"] = $phrase['phrasetext'];
149 }
150 $db->free_result($phrases);
151
152 // ###################################################################
153 // load locale data
154 $locale = $db->query("SELECT * FROM " . TABLE_PREFIX . "locale WHERE languageid = " . intval($bugsys->options['lang_id']));
155 while ($phrase = $db->fetch_array($locale))
156 {
157 $bugsys->language["$phrase[varname]"] = $phrase['phrasetext'];
158 }
159 $db->free_result($phrases);
160
161 // ###################################################################
162 // Initialize usergroup system
163 $_PERMISSION = array(
164 'canviewbugs' => 1, // can view bugs
165 'cansearch' => 2, // can use the search
166 'cansubscribe' => 4, // can email subscribe
167 'canvote' => 8, // can vote on bugs
168 'cansubmitbugs' => 16, // can submit new bugs
169 'canpostcomments' => 32, // can post new comments
170 'cangetattach' => 64, // can dl attachments
171 'canputattach' => 128, // can ul attachments
172 'caneditown' => 256, // can edit own comments
173 'caneditothers' => 512, // can edit others' comments
174 'caneditinfo' => 1024, // can edit bug info -- works in conjunction with canedit(own|others)
175 'canassign' => 2048, // can assign bug
176 'canchangestatus' => 4096, // can change bug status
177 'canadminpanel' => 8192, // can view admin panel
178 'canadminbugs' => 16384, // can administrate bug functions
179 'canadminversions' => 32768, // can admin version info
180 'canadminusers' => 65536, // can admin users
181 'canadmingroups' => 131072, // can admin permission masks
182 'canadmintools' => 262144, // can use admin tools
183 'canadminfields' => 524288, // can admin custom bug fields
184 'canbeassignedto' => 1048576, // can be assigned bugs,
185 'caneditattach' => 2097152 // can edit attachments
186 );
187
188 foreach ($_PERMISSION AS $name => $maskvalue)
189 {
190 define(strtoupper($name), $maskvalue);
191 }
192
193 /*=====================================================================*\
194 || ###################################################################
195 || # $HeadURL$
196 || # $Id$
197 || ###################################################################
198 \*=====================================================================*/
199 ?>