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