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