r380: Converting some hard-coded text to the language system
[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 $type_display = substr_replace($type, strtoupper($type{0}), 0, 1);
24 $type = (($type == 'component') ? 'product' : $type);
25 $type_action = (($type == 'version') ? 'versionid' : 'productid');
26
27 if ($edit)
28 {
29 $opt .= '<option value="product.php?do=edit' . $type . '&' . $type_action . '=' . $id . '">' . lang::p('edit') . ' ' . $type_display . '</option>';
30 }
31
32 if ($delete)
33 {
34 $opt .= '<option value="product.php?do=delete' . $type . '&' . $type_action . '=' . $id . '">' . lang::r('Delete') . ' ' . $type_display . '</option>';
35 }
36
37 if ($addcomponent)
38 {
39 $opt .= '<option value="product.php?do=addproduct&productid=' . $id . '">' . lang::p('add_component') . '</option>';
40 }
41
42 if ($addversion)
43 {
44 $opt .= '<option value="product.php?do=addversion&productid=' . $id . '">' . lang::p('add_version') . '</option>';
45 }
46
47 $type = strtolower($type);
48
49 $name = $type . '_' . $id;
50
51 $displayorder = (($displayorder != -1) ? '<input type="text" name="displayorder[' . $name . ']" value="' . $displayorder . '" size="4" /> ' : '');
52
53 return $displayorder . '<select id="' . $name . '" name="' . $name . '" onchange="exec_action(\'' . $name . '\')">' . $opt . '</select> <input type="button" name="gobutton" value=" ' . lang::p('go') . ' " onclick="exec_action(\'' . $name . '\')" />';
54 }
55
56 // ###################################################################
57
58 if (empty($_REQUEST['do']))
59 {
60 $_REQUEST['do'] = 'modify';
61 }
62
63 // ###################################################################
64
65 if ($_REQUEST['do'] == 'killversion')
66 {
67 $db->query("DELETE FROM " . TABLE_PREFIX . "version WHERE versionid = " . intval($bugsys->in['versionid']));
68 $db->query("DELETE FROM " . TABLE_PREFIX . "bug WHERE versionid = " . intval($bugsys->in['versionid']));
69
70 build_versions();
71
72 $admin->redirect('product.php?do=modify');
73 }
74
75 // ###################################################################
76
77 if ($_REQUEST['do'] == 'deleteversion')
78 {
79 $admin->page_confirm(lang::p('confirm_delete_version'), 'product.php?do=killversion&amp;versionid=' . intval($bugsys->in['versionid']));
80 }
81
82 // ###################################################################
83
84 if ($_REQUEST['do'] == 'insertversion')
85 {
86 $db->query("INSERT INTO " . TABLE_PREFIX . "version (productid, version, displayorder) VALUES (" . intval($bugsys->in['productid']) . ", '" . $bugsys->in['version'] . "', " . intval($bugsys->in['displayorder']) . ")");
87 build_versions();
88 $admin->redirect('product.php?do=modify');
89 }
90
91 // ###################################################################
92
93 if ($_REQUEST['do'] == 'addversion')
94 {
95 $admin->page_start(lang::p('add_version'));
96
97 if ($bugsys->in['productid'] != -1)
98 {
99 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . intval($bugsys->in['productid']));
100 if (!is_array($product))
101 {
102 $admin->error(lang::p('error_invalid_id'));
103 }
104 }
105 else
106 {
107 $bugsys->in['productid'] = 0;
108 }
109
110 $admin->form_start('product.php', 'insertversion');
111 $admin->form_hidden_field('productid', intval($bugsys->in['productid']));
112 $admin->table_start();
113 $admin->table_head(lang::p('add_new_version'));
114 $admin->row_input(lang::p('version_title'), 'version');
115 $admin->row_input(lang::p('version_display_order'), 'displayorder');
116 $admin->row_submit();
117 $admin->table_end();
118 $admin->form_end();
119
120 $admin->page_end();
121 }
122
123 // ###################################################################
124
125 if ($_REQUEST['do'] == 'updateversion')
126 {
127 if (empty($bugsys->in['version']))
128 {
129 $admin->error(lang::p('fill_in_version_number'));
130 }
131
132 $db->query("UPDATE " . TABLE_PREFIX . "version SET version = '" . $bugsys->in['version'] . "', displayorder = " . intval($bugsys->in['displayorder']) . " WHERE versionid = " . intval($bugsys->in['versionid']));
133 build_versions();
134
135 $admin->redirect('product.php?do=modify');
136 }
137
138 // ###################################################################
139
140 if ($_REQUEST['do'] == 'editversion')
141 {
142 $admin->page_start(lang::p('edit_version'));
143
144 $version = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "version WHERE versionid = " . intval($bugsys->in['versionid']));
145 if (!is_array($version))
146 {
147 $admin->error(lang::p('error_invalid_id'));
148 }
149
150 $admin->form_start('product.php', 'updateversion');
151 $admin->form_hidden_field('versionid', $version['versionid']);
152 $admin->table_start();
153 $admin->table_head(lang::p('edit_version_title', $version['version']));
154 $admin->row_input(lang::p('version_title'), 'version', $version['version']);
155 $admin->row_input(lang::p('version_display_order'), 'displayorder', $version['displayorder']);
156 $admin->row_submit();
157 $admin->table_end();
158 $admin->form_end();
159
160 $admin->page_end();
161 }
162
163 // ###################################################################
164
165 if ($_REQUEST['do'] == 'killproduct')
166 {
167 $allprods = $db->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . intval($bugsys->in['productid']) . " OR componentmother = " . intval($bugsys->in['productid']));
168 while ($prod = $db->fetch_array($allprods))
169 {
170 $list[] = $prod['productid'];
171 }
172
173 $db->query("DELETE FROM " . TABLE_PREFIX . "product WHERE productid IN (" . implode(', ', $list) . ")");
174 $db->query("DELETE FROM " . TABLE_PREFIX . "version WHERE productid IN (" . implode(', ', $list) . ")");
175 $db->query("DELETE FROM " . TABLE_PREFIX . "bug WHERE productid IN (" . implode(', ', $list) . ")");
176
177 build_products();
178
179 $admin->redirect('product.php?do=modify');
180 }
181
182 // ###################################################################
183
184 if ($_REQUEST['do'] == 'deleteproduct')
185 {
186 $admin->page_confirm(lang::p('confirm_delete_product'), 'product.php?do=killproduct&amp;productid=' . intval($bugsys->in['productid']));
187 }
188
189 // ###################################################################
190
191 if ($_REQUEST['do'] == 'insertproduct')
192 {
193 if (empty($bugsys->in['shortname']) OR empty($bugsys->in['title']))
194 {
195 $admin->error(lang::p('go_back_and_fill_both_fields'));
196 }
197
198 $db->query("
199 INSERT INTO " . TABLE_PREFIX . "product
200 (shortname, title, componentmother, description, displayorder)
201 VALUES
202 ('" . $bugsys->in['shortname'] . "', '" . $bugsys->in['title'] . "',
203 " . intval($bugsys->in['componentmother']) . ", '" . $bugsys->in['description'] . "', " . intval($bugsys->in['displayorder']) . ")"
204 );
205 build_products();
206
207 $admin->redirect('product.php?do=modify');
208 }
209
210 // ###################################################################
211
212 if ($_REQUEST['do'] == 'addproduct')
213 {
214 $admin->page_start(lang::p('add_new_product'));
215
216 $admin->form_start('product.php', 'insertproduct');
217 $admin->form_hidden_field('componentmother', intval($bugsys->in['productid']));
218 $admin->table_start();
219 $admin->table_head(lang::p('add_product'));
220 $admin->row_input(lang::p('product_shortname'), 'shortname');
221 $admin->row_input(lang::p('product_title'), 'title');
222 $admin->row_textarea(lang::p('product_description'), 'description');
223 $admin->row_input(lang::p('product_display_order'), 'displayorder');
224 $admin->row_submit();
225 $admin->table_end();
226 $admin->form_end();
227
228 $admin->page_end();
229 }
230
231 // ###################################################################
232
233 if ($_REQUEST['do'] == 'updateproduct')
234 {
235 if (empty($bugsys->in['shortname']) OR empty($bugsys->in['title']))
236 {
237 $admin->error(lang::p('go_back_and_fill_both_fields'));
238 }
239
240 if (empty($bugsys->in['productid']))
241 {
242 $admin->error(lang::p('error_invalid_id'));
243 }
244
245 $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']));
246 build_products();
247
248 $admin->redirect('product.php?do=modify');
249 }
250
251 // ###################################################################
252
253 if ($_REQUEST['do'] == 'editproduct')
254 {
255 $admin->page_start(lang::p('edit_product'));
256
257 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . intval($bugsys->in['productid']));
258 if (!is_array($product))
259 {
260 $admin->error(lang::p('error_invalid_id'));
261 }
262
263 $admin->form_start('product.php', 'updateproduct');
264 $admin->form_hidden_field('productid', $product['productid']);
265 $admin->table_start();
266 $admin->table_head(lang::p('edit_product_title', $product['title']));
267 $admin->row_input(lang::p('product_title'), 'title', $product['title']);
268 $admin->row_input(lang::p('product_shortname'), 'shortname', $product['shortname']);
269 $admin->row_textarea(lang::p('product_description'), 'description', $product['description']);
270 $admin->row_input(lang::p('product_display_order'), 'displayorder', $product['displayorder']);
271 $admin->row_submit();
272 $admin->table_end();
273 $admin->form_end();
274
275 $admin->page_end();
276 }
277
278 // ###################################################################
279
280 if ($_POST['do'] == 'displayorder')
281 {
282 foreach ((array)$_POST['displayorder'] AS $namebit => $displayorder)
283 {
284 $name = explode('_', $namebit);
285 if ($name[0] == 'product' OR $name[0] == 'version')
286 {
287 $id = intval($name[1]);
288 $order = intval($displayorder);
289 $db->query("UPDATE " . TABLE_PREFIX . "$name[0] SET displayorder = $order WHERE $name[0]id = $id");
290 }
291 }
292 build_products();
293 build_versions();
294 $admin->redirect('product.php?do=modify');
295 }
296
297 // ###################################################################
298
299 if ($_REQUEST['do'] == 'modify')
300 {
301 $admin->page_start(lang::p('products_and_versions'));
302
303 $javascript = <<<EOF
304 <script type="text/javascript">
305 <!--
306 function exec_action(name)
307 {
308 window.location = document.getElementById(name).value;
309 }
310 //-->
311 </script>
312 EOF;
313
314 $admin->page_code($javascript);
315
316 $admin->form_start('product.php', 'displayorder');
317
318 $products = $db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC");
319 while ($prod = $db->fetch_array($products))
320 {
321 if (!$prod['componentmother'])
322 {
323 $product["$prod[productid]"] = $prod;
324 }
325 else
326 {
327 $component["$prod[componentmother]"][] = $prod;
328 }
329 $version["$prod[productid]"] = array();
330 }
331 $products = (array)$product;
332
333 $versions = $db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC");
334 while ($vers = $db->fetch_array($versions))
335 {
336 $version["$vers[productid]"]["$vers[versionid]"] = $vers;
337 }
338 $versions = (array)$version;
339
340 $admin->table_start();
341 $admin->table_head(lang::p('products_versions'));
342
343 // Handle our global versions
344 if (is_array($versions['0']))
345 {
346 $admin->row_text(lang::p('global_versions'), construct_option_list('product', -1, 0, 0, 1, 0, -1), 'middle', 2, 'alt3');
347 foreach ($versions['0'] AS $version)
348 {
349 $admin->row_text('-- ' . $version['version'], construct_option_list('version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
350 }
351 }
352
353 // Now let's do the rest of the versions
354 foreach ($products AS $product)
355 {
356 // Product
357 $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');
358
359 // Versions
360 foreach ($versions["$product[productid]"] AS $version)
361 {
362 $admin->row_text('-- ' . $version['version'], construct_option_list('version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
363 }
364
365 // Components
366 foreach ((array)$component["$product[productid]"] AS $comp)
367 {
368 $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');
369
370 // Component versions
371 foreach ($versions["$comp[productid]"] AS $version)
372 {
373 $admin->row_text('---- ' . $version['version'], construct_option_list('version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
374 }
375 }
376 }
377
378 $admin->row_span('<input type="submit" name="button" value=" ' . lang::p('save_display_order') . ' " accesskey="s" /> <input type="button" name="addproduct" value=" ' . lang::p('add_new_product') . ' " onclick="window.location = \'product.php?do=addproduct\';" />', 'tfoot', 'center');
379
380 $admin->table_end();
381
382 $admin->form_end();
383
384 $admin->page_end();
385 }
386
387 /*=====================================================================*\
388 || ###################################################################
389 || # $HeadURL$
390 || # $Id$
391 || ###################################################################
392 \*=====================================================================*/
393 ?>