- Get the email system to work for register.php
[bugdar.git] / includes / functions_datastore.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 // ###################### Start build_languages ######################
23 function build_languages()
24 {
25 global $bugsys;
26
27 $languages = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "language");
28 foreach ($languages as $language)
29 {
30 $tempstore["$language[languageid]"] = $language;
31 }
32
33 BSApp::$db->query("
34 ### replacing the language cache ###
35 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
36 VALUES ('language', '" . BSApp::$input->escape(serialize($tempstore)) . "')"
37 );
38
39 bugdar::$datastore['language'] = $tempstore;
40 }
41
42 // ####################### Start build_settings ######################
43 function build_settings()
44 {
45 global $bugsys;
46
47 $settings = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "setting");
48 foreach ($settings as $setting)
49 {
50 $options["$setting[varname]"] = $setting['value'];
51 }
52
53 BSApp::$db->query("
54 ### replacing the setting cache ###
55 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
56 VALUES ('setting', '" . BSApp::$input->escape(serialize($options)) . "')"
57 );
58
59 bugdar::$datastore['setting'] = $options;
60 }
61
62 // ###################### Start build_usergroups #####################
63 function build_usergroups()
64 {
65 global $bugsys;
66
67 $usergroups = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup");
68 foreach ($usergroups as $usergroup)
69 {
70 $groups["$usergroup[usergroupid]"] = $usergroup;
71 }
72
73 BSApp::$db->query("
74 ### replacing usergroup cache ###
75 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
76 VALUES ('usergroup', '" . BSApp::$input->escape(serialize($groups)) . "')"
77 );
78
79 bugdar::$datastore['usergroup'] = $groups;
80 }
81
82 // ####################### Start build_statuses ######################
83 function build_statuses()
84 {
85 global $bugsys;
86
87 $statuses = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "status ORDER BY displayorder ASC");
88 foreach ($statuses as $status)
89 {
90 $tempstore["$status[statusid]"] = $status;
91 }
92
93 BSApp::$db->query("
94 ### replacing status cache ###
95 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
96 VALUES ('status', '" . BSApp::$input->escape(serialize($tempstore)) . "')"
97 );
98
99 bugdar::$datastore['status'] = $tempstore;
100 }
101
102 // ###################### Start build_severities #####################
103 function build_severities()
104 {
105 global $bugsys;
106
107 $severities = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "severity ORDER BY displayorder ASC");
108 foreach ($severities as $severity)
109 {
110 $tempstore["$severity[severityid]"] = $severity;
111 }
112
113 BSApp::$db->query("
114 ### replacing severity cache ###
115 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
116 VALUES ('severity', '" . BSApp::$input->escape(serialize($tempstore)) . "')"
117 );
118
119 bugdar::$datastore['severity'] = $tempstore;
120 }
121
122 // ###################### Start build_priorities #####################
123 function build_priorities()
124 {
125 global $bugsys;
126
127 $priorities = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "priority ORDER BY displayorder ASC");
128 foreach ($priorities as $priority)
129 {
130 $tempstore["$priority[priorityid]"] = $priority;
131 }
132
133 BSApp::$db->query("
134 ### replacing priority cache ###
135 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
136 VALUES ('priority', '" . BSApp::$input->escape(serialize($tempstore)) . "')"
137 );
138
139 bugdar::$datastore['priority'] = $tempstore;
140 }
141
142 // ###################### Start build_assignedto #####################
143 function build_assignedto()
144 {
145 global $bugsys;
146
147 // determine the groups that are assignable
148 $ids = $exprs = array();
149 foreach (bugdar::$datastore['usergroup'] AS $id => $group)
150 {
151 if ($group['permissions'] & bugdar::$permissions['canbeassignedto'])
152 {
153 $ids[] = $id;
154 $exprs[] = "FIND_IN_SET($id, groupids)";
155 }
156 }
157
158 $ids = implode(',', $ids);
159 $exprs = implode(' OR ', $exprs);
160 $users = BSApp::$db->query("
161 SELECT email, displayname, userid, showemail
162 FROM " . TABLE_PREFIX . "user AS user
163 WHERE usergroupid IN ($ids) OR $exprs"
164 );
165 foreach ($users as $user)
166 {
167 $devs["$user[userid]"] = $user;
168 }
169
170 BSApp::$db->query("
171 ### replacing developer / assign to cache ###
172 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
173 VALUES ('assignto', '" . BSApp::$input->escape(serialize($devs)) . "')"
174 );
175
176 bugdar::$datastore['assignto'] = $devs;
177 }
178
179 // ##################### Start build_resolutions #####################
180 function build_resolutions()
181 {
182 global $bugsys;
183
184 $resolutions = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "resolution ORDER BY displayorder ASC");
185 foreach ($resolutions as $resolution)
186 {
187 $tempstore["$resolution[resolutionid]"] = $resolution;
188 }
189
190 BSApp::$db->query("
191 ### replacing resolution cache ###
192 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
193 VALUES ('resolution', '" . BSApp::$input->escape(serialize($tempstore)) . "')"
194 );
195
196 bugdar::$datastore['resolution'] = $tempstore;
197 }
198
199 // ####################### Start build_versions ######################
200 function build_versions()
201 {
202 global $bugsys;
203
204 $versions = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC");
205 foreach ($versions as $version)
206 {
207 $tempstore["$version[versionid]"] = $version;
208 }
209
210 BSApp::$db->query("
211 ### replacing version cache ###
212 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
213 VALUES ('version', '" . BSApp::$input->escape(serialize($tempstore)) . "')"
214 );
215
216 bugdar::$datastore['version'] = $tempstore;
217 }
218
219 // ####################### Start build_products ######################
220 function build_products()
221 {
222 global $bugsys;
223
224 $products = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC");
225 foreach ($products as $product)
226 {
227 if ($product['parentid'])
228 {
229 $tempstore['component']["$product[productid]"] = $product;
230 }
231 else
232 {
233 $tempstore['product']["$product[productid]"] = $product;
234 }
235 }
236
237 BSApp::$db->query("
238 ### replacing product / component cache ###
239 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
240 VALUES
241 ('product', '" . BSApp::$input->escape(serialize($tempstore['product'])) . "'),
242 ('component', '" . BSApp::$input->escape(serialize($tempstore['component'])) . "')"
243 );
244
245 bugdar::$datastore['product'] = $tempstore['product'];
246 bugdar::$datastore['component'] = $tempstore['component'];
247 }
248
249 // ##################### Start build_permissions #####################
250 function build_permissions()
251 {
252 global $bugsys;
253
254 $permissions = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "permission ORDER BY usergroupid, productid");
255 foreach ($permissions as $permission)
256 {
257 $tempstore["$permission[usergroupid]"]["$permission[productid]"] = $permission['mask'];
258 }
259
260 BSApp::$db->query("
261 ### replacing permissions cache ###
262 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
263 VALUES ('permission', '" . BSApp::$input->escape(serialize($tempstore)) . "')"
264 );
265
266 bugdar::$datastore['permission'] = $tempstore;
267 }
268
269 // ##################### Start build_automations ####################
270 function build_automations()
271 {
272 global $bugsys;
273
274 $automations = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "automation ORDER BY name ASC");
275 foreach ($automations as $automation)
276 {
277 $actions["$automation[actionid]"] = $automation;
278 }
279
280 BSApp::$db->query("
281 ### replacing automation cache ###
282 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
283 VALUES ('automation', '" . BSApp::$input->escape(serialize($actions)) . "')"
284 );
285
286 bugdar::$datastore['automation'] = $actions;
287 }
288
289 // ###################### Start build_user_help ######################
290 function build_user_help()
291 {
292 global $bugsys;
293
294 // custom field descriptions
295 $descriptions = BSApp::$db->query("SELECT fieldid, name, description FROM " . TABLE_PREFIX . "bugfield");
296 foreach ($descriptions as $field)
297 {
298 $help["field$field[fieldid]"] = array('title' => $field['name'], 'body' => $field['description']);
299 }
300
301 // standard help texts
302 $texts = BSApp::$db->query("SELECT * FROM " . TABLE_PREFIX . "fieldhelp");
303 foreach ($texts as $field)
304 {
305 $help["$field[keystring]"] = $field;
306 }
307
308 BSApp::$db->query("
309 ### replacing user help cache ###
310 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
311 VALUES ('help', '" . BSApp::$input->escape(serialize($help)) . "')"
312 );
313
314 bugdar::$datastore['help'] = $help;
315 }
316
317 /*=====================================================================*\
318 || ###################################################################
319 || # $HeadURL$
320 || # $Id$
321 || ###################################################################
322 \*=====================================================================*/
323 ?>