]> src.bluestatic.org Git - bugdar.git/blob - admin/product.php
r496: Removing #submitrow from report.css to global.css
[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 = (($type == 'component') ? 'product' : $type);
27 $type_action = (($type == 'version') ? 'versionid' : 'productid');
28
29 if ($edit)
30 {
31 $opt .= '<option value="product.php?do=edit' . $type . '&' . $type_action . '=' . $id . '">' . $bugsys->lang->string('Edit') . ' ' . $type_display . '</option>';
32 }
33
34 if ($delete)
35 {
36 $opt .= '<option value="product.php?do=delete' . $type . '&' . $type_action . '=' . $id . '">' . $bugsys->lang->string('Delete') . ' ' . $type_display . '</option>';
37 }
38
39 if ($addcomponent)
40 {
41 $opt .= '<option value="product.php?do=addproduct&productid=' . $id . '">' . $bugsys->lang->string('Add Component') . '</option>';
42 }
43
44 if ($addversion)
45 {
46 $opt .= '<option value="product.php?do=addversion&productid=' . $id . '">' . $bugsys->lang->string('Add Version') . '</option>';
47 }
48
49 $type = strtolower($type);
50
51 $name = $type . '_' . $id;
52
53 $displayorder = (($displayorder != -1) ? '<input type="text" name="displayorder[' . $name . ']" value="' . $displayorder . '" size="4" /> ' : '');
54
55 return $displayorder . '<select id="' . $name . '" name="' . $name . '" onchange="exec_action(\'' . $name . '\')">' . $opt . '</select> <input type="button" name="gobutton" value=" ' . $bugsys->lang->string('Go') . ' " onclick="exec_action(\'' . $name . '\')" />';
56 }
57
58 // ###################################################################
59
60 if (empty($_REQUEST['do']))
61 {
62 $_REQUEST['do'] = 'modify';
63 }
64
65 // ###################################################################
66
67 if ($_REQUEST['do'] == 'killversion')
68 {
69 $db->query("DELETE FROM " . TABLE_PREFIX . "version WHERE versionid = " . intval($bugsys->in['versionid']));
70 $db->query("DELETE FROM " . TABLE_PREFIX . "bug WHERE versionid = " . intval($bugsys->in['versionid']));
71
72 build_versions();
73
74 $admin->redirect('product.php?do=modify');
75 }
76
77 // ###################################################################
78
79 if ($_REQUEST['do'] == 'deleteversion')
80 {
81 $admin->page_confirm($lang->string('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=' . intval($bugsys->in['versionid']));
82 }
83
84 // ###################################################################
85
86 if ($_REQUEST['do'] == 'insertversion')
87 {
88 $db->query("INSERT INTO " . TABLE_PREFIX . "version (productid, version, displayorder) VALUES (" . intval($bugsys->in['productid']) . ", '" . $bugsys->in['version'] . "', " . intval($bugsys->in['displayorder']) . ")");
89 build_versions();
90 $admin->redirect('product.php?do=modify');
91 }
92
93 // ###################################################################
94
95 if ($_REQUEST['do'] == 'addversion')
96 {
97 $admin->page_start($lang->string('Add Version'));
98
99 if ($bugsys->in['productid'] != -1)
100 {
101 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . intval($bugsys->in['productid']));
102 if (!is_array($product))
103 {
104 $admin->error($lang->getlex('error_invalid_id'));
105 }
106 }
107 else
108 {
109 $bugsys->in['productid'] = 0;
110 }
111
112 $admin->form_start('product.php', 'insertversion');
113 $admin->form_hidden_field('productid', intval($bugsys->in['productid']));
114 $admin->table_start();
115 $admin->table_head($lang->string('Add New Version'));
116 $admin->row_input($lang->string('Version Number<div><dfn>This is the version string for this product.</dfn></div>'), 'version');
117 $admin->row_input($lang->string('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 if (empty($bugsys->in['version']))
130 {
131 $admin->error($lang->string('Please fill in a version number.'));
132 }
133
134 $db->query("UPDATE " . TABLE_PREFIX . "version SET version = '" . $bugsys->in['version'] . "', displayorder = " . intval($bugsys->in['displayorder']) . " WHERE versionid = " . intval($bugsys->in['versionid']));
135 build_versions();
136
137 $admin->redirect('product.php?do=modify');
138 }
139
140 // ###################################################################
141
142 if ($_REQUEST['do'] == 'editversion')
143 {
144 $admin->page_start($lang->string('Edit Version'));
145
146 $version = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "version WHERE versionid = " . intval($bugsys->in['versionid']));
147 if (!is_array($version))
148 {
149 $admin->error($lang->getlex('error_invalid_id'));
150 }
151
152 $admin->form_start('product.php', 'updateversion');
153 $admin->form_hidden_field('versionid', $version['versionid']);
154 $admin->table_start();
155 $admin->table_head(sprintf($lang->string('Edit Version - %1$s'), $version['version']));
156 $admin->row_input($lang->string('Version Number<div><dfn>This is the version string for this product.</dfn></div>'), 'version', $version['version']);
157 $admin->row_input($lang->string('Display Order<div><dfn>The order in which the versions are displayed.</dfn></div>'), 'displayorder', $version['displayorder']);
158 $admin->row_submit();
159 $admin->table_end();
160 $admin->form_end();
161
162 $admin->page_end();
163 }
164
165 // ###################################################################
166
167 if ($_REQUEST['do'] == 'killproduct')
168 {
169 $allprods = $db->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . intval($bugsys->in['productid']) . " OR componentmother = " . intval($bugsys->in['productid']));
170 while ($prod = $db->fetch_array($allprods))
171 {
172 $list[] = $prod['productid'];
173 }
174
175 $db->query("DELETE FROM " . TABLE_PREFIX . "product WHERE productid IN (" . implode(', ', $list) . ")");
176 $db->query("DELETE FROM " . TABLE_PREFIX . "version WHERE productid IN (" . implode(', ', $list) . ")");
177 $db->query("DELETE FROM " . TABLE_PREFIX . "bug WHERE productid IN (" . implode(', ', $list) . ")");
178
179 build_products();
180
181 $admin->redirect('product.php?do=modify');
182 }
183
184 // ###################################################################
185
186 if ($_REQUEST['do'] == 'deleteproduct')
187 {
188 $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']));
189 }
190
191 // ###################################################################
192
193 if ($_REQUEST['do'] == 'insertproduct')
194 {
195 if (empty($bugsys->in['shortname']) OR empty($bugsys->in['title']))
196 {
197 $admin->error($lang->string('Please go back and fill in both fields.'));
198 }
199
200 $db->query("
201 INSERT INTO " . TABLE_PREFIX . "product
202 (shortname, title, componentmother, description, displayorder)
203 VALUES
204 ('" . $bugsys->in['shortname'] . "', '" . $bugsys->in['title'] . "',
205 " . intval($bugsys->in['componentmother']) . ", '" . $bugsys->in['description'] . "', " . intval($bugsys->in['displayorder']) . ")"
206 );
207 build_products();
208
209 $admin->redirect('product.php?do=modify');
210 }
211
212 // ###################################################################
213
214 if ($_REQUEST['do'] == 'addproduct')
215 {
216 $admin->page_start($lang->string('Add New Product'));
217
218 $admin->form_start('product.php', 'insertproduct');
219 $admin->form_hidden_field('componentmother', intval($bugsys->in['productid']));
220 $admin->table_start();
221 $admin->table_head($lang->string('Add Product'));
222 $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');
223 $admin->row_input($lang->string('Title'), 'title');
224 $admin->row_textarea($lang->string('Description<div><dfn>A short description of this product.</dfn></div>'), 'description');
225 $admin->row_input($lang->string('Display Order<div><dfn>The order in which the products are displayed.</dfn></div>'), 'displayorder');
226 $admin->row_submit();
227 $admin->table_end();
228 $admin->form_end();
229
230 $admin->page_end();
231 }
232
233 // ###################################################################
234
235 if ($_REQUEST['do'] == 'updateproduct')
236 {
237 if (empty($bugsys->in['shortname']) OR empty($bugsys->in['title']))
238 {
239 $admin->error($lang->string('Please go back and fill in both fields.'));
240 }
241
242 if (empty($bugsys->in['productid']))
243 {
244 $admin->error($lang->getlex('error_invalid_id'));
245 }
246
247 $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']));
248 build_products();
249
250 $admin->redirect('product.php?do=modify');
251 }
252
253 // ###################################################################
254
255 if ($_REQUEST['do'] == 'editproduct')
256 {
257 $admin->page_start($lang->string('Edit Product'));
258
259 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . intval($bugsys->in['productid']));
260 if (!is_array($product))
261 {
262 $admin->error($lang->getlex('error_invalid_id'));
263 }
264
265 $admin->form_start('product.php', 'updateproduct');
266 $admin->form_hidden_field('productid', $product['productid']);
267 $admin->table_start();
268 $admin->table_head(sprintf($lang->string('Edit Product - %1$s'), $product['title']));
269 $admin->row_input($lang->string('Title'), 'title', $product['title']);
270 $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']);
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'));
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_span('<input type="submit" name="button" value=" ' . $lang->string('Save Display Order') . ' " accesskey="s" /> <a href="product.php?do=addproduct">[' . $lang->string('Add New Product') . ']</a>', 'tfoot', 'center');
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 ?>