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