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