r1: Initial import from CVS head.
[bugdar.git] / includes / init.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # [#]app[#] [#]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 // set quotes runtime
16 set_magic_quotes_runtime(0);
17
18 // ###################################################################
19 // Initialize the database
20 if (!file_exists('./includes/config.php'))
21 {
22 echo 'includes/config.php needs to be present!';
23 exit;
24 }
25
26 require_once('./includes/config.php');
27 require_once('./includes/db_mysql.php');
28
29 $DB_sql = new DB_Sql();
30 $DB_sql->appname = '[#]app[#]';
31 $DB_sql->database = $database;
32 $DB_sql->connect($servername, $username, $password, $usepconnect);
33 define('DEVDEBUG', $debug);
34 define('TABLE_PREFIX', $tableprefix);
35 define('COOKIE_PREFIX', $cookieprefix);
36 unset($database, $servername, $username, $password, $usepconnect, $tableprefix, $cookieprefix);
37
38 // ###################################################################
39 // Initialize our environment
40 require_once('./includes/functions_datastore.php');
41 require_once('./includes/functions.php');
42 class Environment
43 {
44 var $options = array();
45 var $userinfo = array();
46 var $language = array();
47 var $datastore = array();
48
49 function Environment()
50 {
51 global $DB_sql, $vars;
52
53 // Fetch all the datastore caches
54 $datastoretemp = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "datastore");
55 while ($store = $DB_sql->fetch_array($datastoretemp))
56 {
57 $this->datastore["$store[title]"] = unserialize($store['data']);
58 }
59
60 // Assign options and fetch the userinfo
61 $this->options = $this->datastore['setting'];
62 unset($this->datastore['setting']);
63 $this->userinfo = (array)$this->fetch_userinfo(-1, true);
64
65 // Pull our languageid
66 if ($this->userinfo['userid'])
67 {
68 $languageid = $this->userinfo['languageid'];
69 $language = $this->datastore['language']["$languageid"];
70 }
71 if (!$languageid)
72 {
73 foreach ($this->datastore['language'] AS $language)
74 {
75 if ($language['default'])
76 {
77 $languageid = $language['languageid'];
78 $language = $this->datastore['language']["$languageid"];
79 break;
80 }
81 }
82 }
83
84 // Load language system
85 if (file_exists("./locale/$language[filename]"))
86 {
87 require_once("./locale/$language[filename]");
88 $this->language = $language;
89 $this->options['lang_charset'] = $cfg['charset'];
90 $this->options['lang_dir'] = $cfg['direction'];
91 $this->options['lang_code'] = $cfg['languagecode'];
92 unset($language);
93 }
94 else
95 {
96 echo "language file (locale/$language[filename]) could not be loaded!";
97 exit;
98 }
99 }
100
101 function fetch_userinfo($userid = -1, $verify_password = false)
102 {
103 global $DB_sql;
104
105 // Get the userid if not specified
106 if ($userid == -1)
107 {
108 $userid = intval($_COOKIE[COOKIE_PREFIX . 'userid']);
109 }
110
111 // Set the falseinfo stuff
112 $falseinfo = array(
113 'usergroupid' => 1,
114 'userid' => 0,
115 'email' => '',
116 'displayname' => '',
117 'permissions' => $this->datastore['usergroup'][1]['permissions'],
118 'displaytitle' => $this->datastore['usergroup'][1]['displaytitle'],
119 'mdisplayname' => $this->datastore['usergroup'][1]['opentag'] . '' . $this->datastore['usergroup'][1]['closetag']
120 );
121
122 // Get the userinfo
123 $userinfo = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = $userid");
124 if (is_array($userinfo))
125 {
126 $userinfo['permissions'] = (int)$this->datastore['usergroup']["$userinfo[usergroupid]"]['permissions'];
127 $userinfo['displaytitle'] = $this->datastore['usergroup']["$userinfo[usergroupid]"]['displaytitle'];
128 fetch_user_display_name($userinfo);
129 $userinfo['mdisplayname'] = $this->datastore['usergroup']["$userinfo[usergroupid]"]['opentag'] . $userinfo['displayname'] . $this->datastore['usergroup']["$userinfo[usergroupid]"]['closetag'];
130 // Verify that the cookie isn't fake
131 if ($verify_password)
132 {
133 if ($_COOKIE[COOKIE_PREFIX . 'authkey'] == $userinfo['authkey'])
134 {
135 return $userinfo;
136 }
137 else
138 {
139 mysetcookie(COOKIE_PREFIX . 'userid');
140 mysetcookie(COOKIE_PREFIX . 'authkey');
141 return $falseinfo;
142 }
143 }
144 else
145 {
146 return $userinfo;
147 }
148 }
149 else
150 {
151 mysetcookie(COOKIE_PREFIX . 'userid');
152 mysetcookie(COOKIE_PREFIX . 'authkey');
153 return $falseinfo;
154 }
155 }
156 }
157
158 $env = new Environment();
159
160 // ###################################################################
161 // Initialize usergroup system
162 $_PERMISSION = array(
163 'canviewbugs' => 1,
164 'cansearch' => 2,
165 'cansubscribe' => 4,
166 'canvote' => 8,
167 'cansubmitbugs' => 16, // 5
168 'canpostcomments' => 32,
169 'cangetattach' => 64,
170 'canputattach' => 128,
171 'caneditown' => 256,
172 'caneditothers' => 512, // 10
173 'caneditinfo' => 1024,
174 'canassign' => 2048,
175 'canchangestatus' => 4096,
176 'canadminpanel' => 8192,
177 'canadminbugs' => 16384, // 15
178 'canadminversions' => 32768,
179 'canadminusers' => 65536,
180 'canadmingroups' => 131072,
181 'canadmintools' => 262144,
182 'canadminfields' => 524288, // 20
183 'canbeassignedto' => 1048576
184 );
185
186 foreach ($_PERMISSION AS $name => $maskvalue)
187 {
188 define(strtoupper($name), $maskvalue);
189 }
190
191 /*=====================================================================*\
192 || ###################################################################
193 || # $HeadURL$
194 || # $Id$
195 || ###################################################################
196 \*=====================================================================*/
197 ?>