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