r765: Say hello to the GPL
[bugdar.git] / includes / functions_datastore.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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 [#]gpl[#] 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 = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "language");
28 while ($language = $bugsys->db->fetch_array($languages))
29 {
30 $tempstore["$language[languageid]"] = $language;
31 }
32
33 $bugsys->db->query("
34 ### replacing the language cache ###
35 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
36 VALUES ('language', '" . $bugsys->escape(serialize($tempstore)) . "')"
37 );
38
39 $bugsys->datastore['language'] = $tempstore;
40 }
41
42 // ####################### Start build_settings ######################
43 function build_settings()
44 {
45 global $bugsys;
46
47 $settings = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "setting");
48 while ($setting = $bugsys->db->fetch_array($settings))
49 {
50 $options["$setting[varname]"] = $setting['value'];
51 }
52
53 $bugsys->db->query("
54 ### replacing the setting cache ###
55 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
56 VALUES ('setting', '" . $bugsys->escape(serialize($options)) . "')"
57 );
58
59 $bugsys->datastore['setting'] = $options;
60 }
61
62 // ###################### Start build_usergroups #####################
63 function build_usergroups()
64 {
65 global $bugsys;
66
67 $usergroups = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "usergroup");
68 while ($usergroup = $bugsys->db->fetch_array($usergroups))
69 {
70 $groups["$usergroup[usergroupid]"] = $usergroup;
71 }
72
73 $bugsys->db->query("
74 ### replacing usergroup cache ###
75 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
76 VALUES ('usergroup', '" . $bugsys->escape(serialize($groups)) . "')"
77 );
78
79 $bugsys->datastore['usergroup'] = $groups;
80 }
81
82 // ####################### Start build_statuses ######################
83 function build_statuses()
84 {
85 global $bugsys;
86
87 $statuses = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "status ORDER BY displayorder ASC");
88 while ($status = $bugsys->db->fetch_array($statuses))
89 {
90 $tempstore["$status[statusid]"] = $status;
91 }
92
93 $bugsys->db->query("
94 ### replacing status cache ###
95 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
96 VALUES ('status', '" . $bugsys->escape(serialize($tempstore)) . "')"
97 );
98
99 $bugsys->datastore['status'] = $tempstore;
100 }
101
102 // ###################### Start build_severities #####################
103 function build_severities()
104 {
105 global $bugsys;
106
107 $severities = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "severity ORDER BY displayorder ASC");
108 while ($severity = $bugsys->db->fetch_array($severities))
109 {
110 $tempstore["$severity[severityid]"] = $severity;
111 }
112
113 $bugsys->db->query("
114 ### replacing severity cache ###
115 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
116 VALUES ('severity', '" . $bugsys->escape(serialize($tempstore)) . "')"
117 );
118
119 $bugsys->datastore['severity'] = $tempstore;
120 }
121
122 // ###################### Start build_priorities #####################
123 function build_priorities()
124 {
125 global $bugsys;
126
127 $priorities = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "priority ORDER BY displayorder ASC");
128 while ($priority = $bugsys->db->fetch_array($priorities))
129 {
130 $tempstore["$priority[priorityid]"] = $priority;
131 }
132
133 $bugsys->db->query("
134 ### replacing priority cache ###
135 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
136 VALUES ('priority', '" . $bugsys->escape(serialize($tempstore)) . "')"
137 );
138
139 $bugsys->datastore['priority'] = $tempstore;
140 }
141
142 // ###################### Start build_assignedto #####################
143 function build_assignedto()
144 {
145 global $bugsys;
146
147 $users = $bugsys->db->query("
148 SELECT user.email, user.displayname, user.userid, user.showemail
149 FROM " . TABLE_PREFIX . "user AS user
150 LEFT JOIN " . TABLE_PREFIX . "usergroup AS usergroup ON (user.usergroupid = usergroup.usergroupid)
151 WHERE (usergroup.permissions & " . CANBEASSIGNEDTO . ")"
152 );
153 while ($user = $bugsys->db->fetch_array($users))
154 {
155 $devs["$user[userid]"] = $user;
156 }
157
158 $bugsys->db->query("
159 ### replacing developer / assign to cache ###
160 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
161 VALUES ('assignto', '" . $bugsys->escape(serialize($devs)) . "')"
162 );
163
164 $bugsys->datastore['assignto'] = $devs;
165 }
166
167 // ##################### Start build_resolutions #####################
168 function build_resolutions()
169 {
170 global $bugsys;
171
172 $resolutions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "resolution ORDER BY displayorder ASC");
173 while ($resolution = $bugsys->db->fetch_array($resolutions))
174 {
175 $tempstore["$resolution[resolutionid]"] = $resolution;
176 }
177
178 $bugsys->db->query("
179 ### replacing resolution cache ###
180 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
181 VALUES ('resolution', '" . $bugsys->escape(serialize($tempstore)) . "')"
182 );
183
184 $bugsys->datastore['resolution'] = $tempstore;
185 }
186
187 // ####################### Start build_versions ######################
188 function build_versions()
189 {
190 global $bugsys;
191
192 $versions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC");
193 while ($version = $bugsys->db->fetch_array($versions))
194 {
195 $tempstore["$version[versionid]"] = $version;
196 }
197
198 $bugsys->db->query("
199 ### replacing version cache ###
200 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
201 VALUES ('version', '" . $bugsys->escape(serialize($tempstore)) . "')"
202 );
203
204 $bugsys->datastore['version'] = $tempstore;
205 }
206
207 // ####################### Start build_products ######################
208 function build_products()
209 {
210 global $bugsys;
211
212 $products = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC");
213 while ($product = $bugsys->db->fetch_array($products))
214 {
215 $tempstore["$product[productid]"] = $product;
216 }
217
218 $bugsys->db->query("
219 ### replacing product / component cache ###
220 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
221 VALUES ('product', '" . $bugsys->escape(serialize($tempstore)) . "')"
222 );
223
224 $bugsys->datastore['product'] = $tempstore;
225 }
226
227 // ##################### Start build_permissions #####################
228 function build_permissions()
229 {
230 global $bugsys;
231
232 $permissions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "permission ORDER BY usergroupid, productid");
233 while ($permission = $bugsys->db->fetch_array($permissions))
234 {
235 $tempstore["$permission[usergroupid]"]["$permission[productid]"] = $permission['mask'];
236 }
237
238 $bugsys->db->query("
239 ### replacing permissions cache ###
240 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
241 VALUES ('permission', '" . $bugsys->escape(serialize($tempstore)) . "')"
242 );
243
244 $bugsys->datastore['permission'] = $tempstore;
245 }
246
247 // ##################### Start build_auto_actions ####################
248 function build_auto_actions()
249 {
250 global $bugsys;
251
252 $autoactions = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "autoaction ORDER BY name ASC");
253 while ($autoaction = $bugsys->db->fetch_array($autoactions))
254 {
255 $actions["$autoaction[actionid]"] = $autoaction;
256 }
257
258 $bugsys->db->query("
259 ### replacing auto action cache ###
260 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
261 VALUES ('autoaction', '" . $bugsys->escape(serialize($actions)) . "')"
262 );
263
264 $bugsys->datastore['autoaction'] = $actions;
265 }
266
267 // ###################### Start build_user_help ######################
268 function build_user_help()
269 {
270 global $bugsys;
271
272 // custom field descriptions
273 $descriptions = $bugsys->db->query("SELECT fieldid, name, description FROM " . TABLE_PREFIX . "bugfield");
274 while ($field = $bugsys->db->fetch_array($descriptions))
275 {
276 $help["field$field[fieldid]"] = array('title' => $field['name'], 'body' => $field['description']);
277 }
278
279 // standard help texts
280 $texts = $bugsys->db->query("SELECT * FROM " . TABLE_PREFIX . "fieldhelp");
281 while ($field = $bugsys->db->fetch_array($texts))
282 {
283 $help["$field[keystring]"] = $field;
284 }
285
286 $bugsys->db->query("
287 ### replacing user help cache ###
288 REPLACE INTO " . TABLE_PREFIX . "datastore (title, data)
289 VALUES ('help', '" . $bugsys->escape(serialize($help)) . "')"
290 );
291
292 $bugsys->datastore['help'] = $help;
293 }
294
295 /*=====================================================================*\
296 || ###################################################################
297 || # $HeadURL$
298 || # $Id$
299 || ###################################################################
300 \*=====================================================================*/
301 ?>