r321: Only query the user table if there is a user ID present.
[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 three
61 $bugsys->options = array();
62 $bugsys->userinfo = array();
63 $bugsys->datastore = array();
64
65 // ###################################################################
66 // populate our caches
67 $datastoretemp = $db->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
68 while ($store = $db->fetch_array($datastoretemp))
69 {
70 $bugsys->datastore["$store[title]"] = unserialize($store['data']);
71 }
72 $bugsys->options = $bugsys->datastore['setting'];
73 unset($bugsys->datastore['setting']);
74
75 //$mail->from = $bugsys->options['webmasteremail'];
76 //$mail->fromname = 'BugStrike Notification';
77
78 // ###################################################################
79 // load userinfo
80 $userid = intval($bugsys->in[COOKIE_PREFIX . 'userid']);
81
82 if ($userid)
83 {
84 $userinfo = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = $userid");
85 if (is_array($userinfo) AND $bugsys->in[COOKIE_PREFIX . 'authkey'] == $userinfo['authkey'])
86 {
87 $userinfo['permissions'] = (int)$bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['permissions'];
88 $userinfo['displaytitle'] = $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['displaytitle'];
89 fetch_user_display_name($userinfo);
90 $userinfo['mdisplayname'] = $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['opentag'] . $userinfo['displayname'] . $bugsys->datastore['usergroup']["$userinfo[usergroupid]"]['closetag'];
91 $bugsys->userinfo = $userinfo;
92 $funct->cookie(COOKIE_PREFIX . 'userid', $bugsys->userinfo['userid']);
93 $funct->cookie(COOKIE_PREFIX . 'authkey', $bugsys->userinfo['authkey']);
94 }
95 }
96
97 if (!$userinfo)
98 {
99 $funct->cookie(COOKIE_PREFIX . 'userid');
100 $funct->cookie(COOKIE_PREFIX . 'authkey');
101 $bugsys->userinfo = array(
102 'usergroupid' => 1,
103 'userid' => 0,
104 'email' => '',
105 'displayname' => '',
106 'permissions' => $bugsys->datastore['usergroup'][1]['permissions'],
107 'displaytitle' => $bugsys->datastore['usergroup'][1]['displaytitle'],
108 'mdisplayname' => $bugsys->datastore['usergroup'][1]['opentag'] . '' . $bugsys->datastore['usergroup'][1]['closetag']
109 );
110 }
111
112 // ###################################################################
113 // load language information
114 require_once('./includes/class_language.php');
115 $bugsys->lang =& lang::init();
116
117 // ###################################################################
118 // initialize the date system
119 $bugsys->load('date');
120 $datef->usertz = $bugsys->userinfo['timezone'];
121 $datef->fetch_offset();
122
123 // ###################################################################
124 // Initialize usergroup system
125 $_PERMISSION = array(
126 'canviewbugs' => 1, // can view bugs
127 'cansearch' => 2, // can use the search
128 'cansubscribe' => 4, // can email subscribe
129 'canvote' => 8, // can vote on bugs
130 'cansubmitbugs' => 16, // can submit new bugs
131 'canpostcomments' => 32, // can post new comments
132 'cangetattach' => 64, // can dl attachments
133 'canputattach' => 128, // can ul attachments
134 'caneditown' => 256, // can edit own comments
135 'caneditothers' => 512, // can edit others' comments
136 'caneditinfo' => 1024, // can edit bug info -- works in conjunction with canedit(own|others)
137 'canassign' => 2048, // can assign bug
138 'canchangestatus' => 4096, // can change bug status
139 'canadminpanel' => 8192, // can view admin panel
140 'canadminbugs' => 16384, // can administrate bug functions
141 'canadminversions' => 32768, // can admin version info
142 'canadminusers' => 65536, // can admin users
143 'canadmingroups' => 131072, // can admin permission masks
144 'canadmintools' => 262144, // can use admin tools
145 'canadminfields' => 524288, // can admin custom bug fields
146 'canbeassignedto' => 1048576, // can be assigned bugs,
147 'caneditattach' => 2097152, // can edit attachments
148 'canviewhidden' => 4194304 // can see hidden bugs
149 );
150
151 foreach ($_PERMISSION AS $name => $maskvalue)
152 {
153 define(strtoupper($name), $maskvalue);
154 }
155
156 /*=====================================================================*\
157 || ###################################################################
158 || # $HeadURL$
159 || # $Id$
160 || ###################################################################
161 \*=====================================================================*/
162 ?>