r610: Add help link
[bugdar.git] / admin / product.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # BugStrike [#]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 delete all the bugs with this version.'), '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'));
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']));
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 sub-versions and components (as well as any bugs contained within those groups)?'), '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['shortname']) OR empty($bugsys->in['title']))
197 {
198 $admin->error($lang->string('Please go back and fill in both fields.'));
199 }
200
201 $db->query("
202 INSERT INTO " . TABLE_PREFIX . "product
203 (shortname, title, componentmother, description, displayorder)
204 VALUES
205 ('" . $bugsys->in['shortname'] . "', '" . $bugsys->in['title'] . "',
206 " . intval($bugsys->in['componentmother']) . ", '" . $bugsys->in['description'] . "', " . intval($bugsys->in['displayorder']) . ")"
207 );
208 build_products();
209
210 $admin->redirect('product.php?do=modify');
211 }
212
213 // ###################################################################
214
215 if ($_REQUEST['do'] == 'addproduct')
216 {
217 $admin->page_start($lang->string('Add New Product'));
218
219 $admin->form_start('product.php', 'insertproduct');
220 $admin->form_hidden_field('componentmother', intval($bugsys->in['productid']));
221 $admin->table_start();
222 $admin->table_head($lang->string('Add Product'));
223 $admin->row_input($lang->string('Short Name<div><dfn>The name that can be used to submit email reports. This should be unique.</dfn></div>'), 'shortname');
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['shortname']) OR empty($bugsys->in['title']))
239 {
240 $admin->error($lang->string('Please go back and fill in both fields.'));
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'] . "', shortname = '" . $bugsys->in['shortname'] . "', 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']));
270 $admin->row_input($lang->string('Title'), 'title', $product['title']);
271 $admin->row_input($lang->string('Short Name<div><dfn>The name that can be used to submit email reports. This should be unique.</dfn></div>'), 'shortname', $product['shortname']);
272 $admin->row_textarea($lang->string('Description<div><dfn>A short description of this product.</dfn></div>'), 'description', $product['description']);
273 $admin->row_input($lang->string('Display Order<div><dfn>The order in which the products are displayed.</dfn></div>'), 'displayorder', $product['displayorder']);
274 $admin->row_submit();
275 $admin->table_end();
276 $admin->form_end();
277
278 $admin->page_end();
279 }
280
281 // ###################################################################
282
283 if ($_POST['do'] == 'displayorder')
284 {
285 foreach ((array)$_POST['displayorder'] AS $namebit => $displayorder)
286 {
287 $name = explode('_', $namebit);
288 if ($name[0] == 'product' OR $name[0] == 'version')
289 {
290 $id = intval($name[1]);
291 $order = intval($displayorder);
292 $db->query("UPDATE " . TABLE_PREFIX . "$name[0] SET displayorder = $order WHERE $name[0]id = $id");
293 }
294 }
295 build_products();
296 build_versions();
297 $admin->redirect('product.php?do=modify');
298 }
299
300 // ###################################################################
301
302 if ($_REQUEST['do'] == 'modify')
303 {
304 $admin->page_start($lang->string('Products and Versions'));
305
306 $javascript = <<<EOF
307 <script type="text/javascript">
308 <!--
309 function exec_action(name)
310 {
311 window.location = document.getElementById(name).value;
312 }
313 //-->
314 </script>
315 EOF;
316
317 $admin->page_code($javascript);
318
319 $admin->form_start('product.php', 'displayorder');
320
321 $products = $db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC");
322 while ($prod = $db->fetch_array($products))
323 {
324 if (!$prod['componentmother'])
325 {
326 $product["$prod[productid]"] = $prod;
327 }
328 else
329 {
330 $component["$prod[componentmother]"][] = $prod;
331 }
332 $version["$prod[productid]"] = array();
333 }
334 $products = (array)$product;
335
336 $versions = $db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC");
337 while ($vers = $db->fetch_array($versions))
338 {
339 $version["$vers[productid]"]["$vers[versionid]"] = $vers;
340 }
341 $versions = (array)$version;
342
343 $admin->table_start();
344 $admin->table_head($lang->string('Products / Versions'), 2, 'products_and_versions');
345
346 // Handle our global versions
347 if (is_array($versions['0']))
348 {
349 $admin->row_text($lang->string('Global Versions'), construct_option_list($lang->string('Product'), -1, 0, 0, 1, 0, -1), 'middle', 2, 'alt3');
350 foreach ($versions['0'] AS $version)
351 {
352 $admin->row_text('-- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
353 }
354 }
355
356 // Now let's do the rest of the versions
357 foreach ($products AS $product)
358 {
359 // Product
360 $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');
361
362 // Versions
363 foreach ($versions["$product[productid]"] AS $version)
364 {
365 $admin->row_text('-- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
366 }
367
368 // Components
369 foreach ((array)$component["$product[productid]"] AS $comp)
370 {
371 $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');
372
373 // Component versions
374 foreach ($versions["$comp[productid]"] AS $version)
375 {
376 $admin->row_text('---- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
377 }
378 }
379 }
380
381 $admin->row_submit('<a href="product.php?do=addproduct">[' . $lang->string('Add New Product') . ']</a>', $lang->string('Save Display Order'), null);
382
383 $admin->table_end();
384
385 $admin->form_end();
386
387 $admin->page_end();
388 }
389
390 /*=====================================================================*\
391 || ###################################################################
392 || # $HeadURL$
393 || # $Id$
394 || ###################################################################
395 \*=====================================================================*/
396 ?>