r2: Changed Environment object to be BugTrack ($env --> $bugsys).. hopefully this...
[bugdar.git] / admin / product.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 require_once('./global.php');
14
15 if (!($bugsys->userinfo['permissions'] & CANADMINVERSIONS))
16 {
17 admin_login();
18 }
19
20 function construct_option_list($type, $id, $edit, $addcomponent, $addversion, $delete, $displayorder)
21 {
22 $type_display = substr_replace($type, strtoupper($type{0}), 0, 1);
23 $type = iff($type == 'component', 'product', $type);
24 $type_action = iff($type == 'version', 'versionid', 'productid');
25
26 if ($edit)
27 {
28 $opt .= '<option value="product.php?do=edit' . $type . '&' . $type_action . '=' . $id . '">Edit ' . $type_display . '</option>';
29 }
30
31 if ($delete)
32 {
33 $opt .= '<option value="product.php?do=delete' . $type . '&' . $type_action . '=' . $id . '">Delete ' . $type_display . '</option>';
34 }
35
36 if ($addcomponent)
37 {
38 $opt .= '<option value="product.php?do=addproduct&productid=' . $id . '">Add Component</option>';
39 }
40
41 if ($addversion)
42 {
43 $opt .= '<option value="product.php?do=addversion&productid=' . $id . '">Add Version</option>';
44 }
45
46 $type = strtolower($type);
47
48 $name = $type . '_' . $id;
49
50 $displayorder = iff($displayorder != -1, '<input type="text" name="displayorder[' . $name . ']" value="' . $displayorder . '" size="4" /> ', '');
51
52 return $displayorder . '<select id="' . $name . '" name="' . $name . '" onchange="exec_action(\'' . $name . '\')">' . $opt . '</select> <input type="button" name="gobutton" value=" Go " onclick="exec_action(\'' . $name . '\')" />';
53 }
54
55 // ###################################################################
56
57 if (empty($_REQUEST['do']))
58 {
59 $_REQUEST['do'] = 'modify';
60 }
61
62 // ###################################################################
63
64 if ($_REQUEST['do'] == 'killversion')
65 {
66 sanitize(array('versionid' => INT));
67
68 $DB_sql->query("DELETE FROM " . TABLE_PREFIX . "version WHERE versionid = $vars[versionid]");
69 // #*# figure out what we do with bugs
70
71 $admin->redirect('product.php?do=modify');
72 }
73
74 // ###################################################################
75
76 if ($_REQUEST['do'] == 'deleteversion')
77 {
78 sanitize(array('versionid' => INT));
79 $admin->page_confirm('Are you sure you want to delete this version? Doing so will do x to the bugs with this version.', 'product.php?do=killversion&amp;versionid=' . $vars['versionid']);
80 }
81
82 // ###################################################################
83
84 if ($_REQUEST['do'] == 'insertversion')
85 {
86 sanitize(array('productid' => INT, 'version' => STR, 'displayorder' => INT));
87 $DB_sql->query("INSERT INTO " . TABLE_PREFIX . "version (productid, version, displayorder) VALUES ($vars[productid], '" . addslasheslike($vars['version']) . "', $vars[displayorder])");
88 $admin->redirect('product.php?do=modify');
89 }
90
91 // ###################################################################
92
93 if ($_REQUEST['do'] == 'addversion')
94 {
95 sanitize(array('productid' => INT));
96
97 $admin->page_start('Add Version');
98
99 if ($vars['productid'] != -1)
100 {
101 $product = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = $vars[productid]");
102 if (!is_array($product))
103 {
104 $admin->error('-1');
105 }
106 }
107 else
108 {
109 $vars['productid'] = 0;
110 }
111
112 $admin->form_start('product.php', 'insertversion');
113 $admin->form_hidden_field('productid', $vars['productid']);
114 $admin->table_start();
115 $admin->table_head('Add New Version');
116 $admin->row_input('Version Number<div><dfn>This is the version string for this product.</dfn></div>', 'version');
117 $admin->row_input('Display Order<div><dfn>The order in which the versions are displayed.</dfn></div>', 'displayorder');
118 $admin->row_submit();
119 $admin->table_end();
120 $admin->form_end();
121
122 $admin->page_end();
123 }
124
125 // ###################################################################
126
127 if ($_REQUEST['do'] == 'updateversion')
128 {
129 sanitize(array('versionid' => INT, 'version' => STR, 'displayorder' => INT));
130
131 if (empty($vars['version']))
132 {
133 $admin->error('Please fill in a version number.');
134 }
135
136 $DB_sql->query("UPDATE " . TABLE_PREFIX . "version SET version = '" . addslasheslike($vars['version']) . "', displayorder = $vars[displayorder] WHERE versionid = $vars[versionid]");
137
138 $admin->redirect('product.php?do=modify');
139 }
140
141 // ###################################################################
142
143 if ($_REQUEST['do'] == 'editversion')
144 {
145 sanitize(array('versionid' => INT));
146
147 $admin->page_start('Edit Version');
148
149 $version = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "version WHERE versionid = $vars[versionid]");
150 if (!is_array($version))
151 {
152 $admin->error('-1');
153 }
154
155 $admin->form_start('product.php', 'updateversion');
156 $admin->form_hidden_field('versionid', $version['versionid']);
157 $admin->table_start();
158 $admin->table_head('Edit Version - ' . $version['version']);
159 $admin->row_input('Version Number<div><dfn>This is the version string for this product.</dfn></div>', 'version', $version['version']);
160 $admin->row_input('Display Order<div><dfn>The order in which the versions are displayed.</dfn></div>', 'displayorder', $version['displayorder']);
161 $admin->row_submit();
162 $admin->table_end();
163 $admin->form_end();
164
165 $admin->page_end();
166 }
167
168 // ###################################################################
169
170 if ($_REQUEST['do'] == 'killproduct')
171 {
172 sanitize(array('productid' => INT));
173
174 $allprods = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = $vars[productid] OR componentmother = $vars[productid]");
175 while ($prod = $DB_sql->fetch_array($allprods))
176 {
177 $list[] = $prod['productid'];
178 }
179
180 $DB_sql->query("DELETE FROM " . TABLE_PREFIX . "product WHERE productid IN (" . implode(', ', $list) . ")");
181 $DB_sql->query("DELETE FROM " . TABLE_PREFIX . "version WHERE productid IN (" . implode(', ', $list) . ")");
182 // #*# do bug kills here
183
184 $admin->redirect('product.php?do=modify');
185 }
186
187 // ###################################################################
188
189 if ($_REQUEST['do'] == 'deleteproduct')
190 {
191 sanitize(array('productid' => INT));
192 $admin->page_confirm('Are you sure you want to delete this product and all of it\'s sub-versions and components (as well as any bugs contained within those groups)?', 'product.php?do=killproduct&amp;productid=' . $vars['productid']);
193 }
194
195 // ###################################################################
196
197 if ($_REQUEST['do'] == 'insertproduct')
198 {
199 sanitize(array('shortname' => STR, 'title' => STR, 'componentmother' => INT, 'description' => STR, 'displayorder' => INT));
200
201 if (empty($vars['shortname']) OR empty($vars['title']))
202 {
203 $admin->error('please go back and enter both fields');
204 }
205
206 $DB_sql->query("
207 INSERT INTO " . TABLE_PREFIX . "product
208 (shortname, title, componentmother, description, displayorder)
209 VALUES
210 ('" . addslasheslike($vars['shortname']) . "', '" . addslasheslike($vars['title']) . "',
211 $vars[componentmother], '" . addslasheslike($vars['description']) . "', $vars[displayorder])");
212
213 $admin->redirect('product.php?do=modify');
214 }
215
216 // ###################################################################
217
218 if ($_REQUEST['do'] == 'addproduct')
219 {
220 sanitize(array('productid' => INT));
221
222 $admin->page_start('Add New Product');
223
224 $admin->form_start('product.php', 'insertproduct');
225 $admin->form_hidden_field('componentmother', $vars['productid']);
226 $admin->table_start();
227 $admin->table_head('Add Product');
228 $admin->row_input('Short Name<div><dfn>The name that can be used to submit email reports. This should be unique.</dfn></div>', 'shortname');
229 $admin->row_input('Product Title', 'title');
230 $admin->row_textarea('Description<div><dfn>A short description of this product.</dfn></div>', 'description');
231 $admin->row_input('Display Order<div><dfn>The order in which the products are displayed.</dfn></div>', 'displayorder');
232 $admin->row_submit();
233 $admin->table_end();
234 $admin->form_end();
235
236 $admin->page_end();
237 }
238
239 // ###################################################################
240
241 if ($_REQUEST['do'] == 'updateproduct')
242 {
243 sanitize(array('productid' => INT, 'title' => STR, 'shortname' => STR, 'description' => STR, 'displayorder' => INT));
244
245 if (empty($vars['shortname']) OR empty($vars['title']))
246 {
247 $admin->error('please go back and fill in both fields');
248 }
249
250 if (empty($vars['productid']))
251 {
252 $admin->error('-1');
253 }
254
255 $DB_sql->query("UPDATE " . TABLE_PREFIX . "product SET title = '" . addslasheslike($vars['title']) . "', shortname = '" . addslasheslike($vars['shortname']) . "', description = '" . addslasheslike($vars['description']) . "', displayorder = $vars[displayorder] WHERE productid = $vars[productid]");
256
257 $admin->redirect('product.php?do=modify');
258 }
259
260 // ###################################################################
261
262 if ($_REQUEST['do'] == 'editproduct')
263 {
264 sanitize(array('productid' => INT));
265
266 $admin->page_start('Edit Product');
267
268 $product = $DB_sql->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = $vars[productid]");
269
270 if (!is_array($product))
271 {
272 $admin->error('-1');
273 }
274
275 $admin->form_start('product.php', 'updateproduct');
276 $admin->form_hidden_field('productid', $product['productid']);
277 $admin->table_start();
278 $admin->table_head('Edit Product - ' . $product['title']);
279 $admin->row_input('Product Title', 'title', $product['title']);
280 $admin->row_input('Short Name<div><dfn>The name that can be used to submit email reports. This should be unique.</dfn></div>', 'shortname', $product['shortname']);
281 $admin->row_textarea('Description<div><dfn>A short description of this product.</dfn></div>', 'description', $product['description']);
282 $admin->row_input('Display Order<div><dfn>The order in which the products are displayed.</dfn></div>', 'displayorder', $product['displayorder']);
283 $admin->row_submit();
284 $admin->table_end();
285 $admin->form_end();
286
287 $admin->page_end();
288 }
289
290 // ###################################################################
291
292 if ($_POST['do'] == 'displayorder')
293 {
294 foreach ((array)$_POST['displayorder'] AS $namebit => $displayorder)
295 {
296 $name = explode('_', $namebit);
297 if ($name[0] == 'product' OR $name[0] == 'version')
298 {
299 $id = intval($name[1]);
300 $order = intval($displayorder);
301 $DB_sql->query("UPDATE " . TABLE_PREFIX . "$name[0] SET displayorder = $order WHERE $name[0]id = $id");
302 }
303 }
304 $admin->redirect('product.php?do=modify');
305 }
306
307 // ###################################################################
308
309 if ($_REQUEST['do'] == 'modify')
310 {
311 $admin->page_start('Products and Versions');
312
313 $javascript = <<<EOF
314 <script type="text/javascript">
315 <!--
316 function exec_action(name)
317 {
318 window.location = document.getElementById(name).value;
319 }
320 //-->
321 </script>
322 EOF;
323
324 $admin->page_code($javascript);
325
326 $admin->form_start('product.php', 'displayorder');
327
328 $products = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC");
329 while ($prod = $DB_sql->fetch_array($products))
330 {
331 if (!$prod['componentmother'])
332 {
333 $product["$prod[productid]"] = $prod;
334 }
335 else
336 {
337 $component["$prod[componentmother]"][] = $prod;
338 }
339 $version["$prod[productid]"] = array();
340 }
341 $products = (array)$product;
342
343 $versions = $DB_sql->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC");
344 while ($vers = $DB_sql->fetch_array($versions))
345 {
346 $version["$vers[productid]"]["$vers[versionid]"] = $vers;
347 }
348 $versions = (array)$version;
349
350 $admin->table_start();
351 $admin->table_head('Products / Versions');
352
353 // Handle our global versions
354 if (is_array($versions['0']))
355 {
356 $admin->row_text('Global Versions', construct_option_list('product', -1, 0, 0, 1, 0, -1), 'middle', 2, 'alt3');
357 foreach ($versions['0'] AS $version)
358 {
359 $admin->row_text('-- ' . $version['version'], construct_option_list('version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
360 }
361 }
362
363 // Now let's do the rest of the versions
364 foreach ($products AS $product)
365 {
366 // Product
367 $admin->row_text("<a href=\"product.php?do=editproduct&amp;productid=$product[productid]\">$product[title]</a>", construct_option_list('product', $product['productid'], 1, 1, 1, 1, $product['displayorder']), 'middle', 2, 'alt3');
368
369 // Versions
370 foreach ($versions["$product[productid]"] AS $version)
371 {
372 $admin->row_text('-- ' . $version['version'], construct_option_list('version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
373 }
374
375 // Components
376 foreach ((array)$component["$product[productid]"] AS $comp)
377 {
378 $admin->row_text("-- <a href=\"product.php?do=editproduct&amp;productid=$comp[productid]\">$comp[title]</a>", construct_option_list('component', $comp['productid'], 1, 0, 1, 1, $comp['displayorder']), 'middle', 2, 'alt1');
379
380 // Component versions
381 foreach ($versions["$comp[productid]"] AS $version)
382 {
383 $admin->row_text('---- ' . $version['version'], construct_option_list('version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
384 }
385 }
386 }
387
388 $admin->row_span('<input type="submit" name="button" value=" Save Display Order" accesskey="s" /> <input type="button" name="addproduct" value=" Add New Product " onclick="window.location = \'product.php?do=addproduct\';" />', 'tfoot', 'center');
389
390 $admin->table_end();
391
392 $admin->form_end();
393
394 $admin->page_end();
395 }
396
397 /*=====================================================================*\
398 || ###################################################################
399 || # $HeadURL$
400 || # $Id$
401 || ###################################################################
402 \*=====================================================================*/
403 ?>