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