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