2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
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.
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
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 \*=====================================================================*/
22 require_once('./global.php');
23 require_once('./includes/functions_datastore.php');
25 if (!can_perform('canadminversions'))
30 function construct_option_list($type, $id, $edit, $addcomponent, $addversion, $delete, $displayorder)
34 $type_display = $type;
35 $type = strtolower($type);
36 $type = ($type == 'component' ? 'product' : $type);
37 $type_action = (($type == 'version') ? 'versionid' : 'productid');
41 $opt .= '<option value="product.php?do=edit' . $type . '&' . $type_action . '=' . $id . '">' . sprintf($bugsys->lang
->string('Edit %1$s'), $type_display) . '</option
>';
46 $opt .= '<option value
="product.php?do=delete' . $type . '&' . $type_action . '=' . $id . '">' . sprintf($bugsys->lang->string('Delete %
1$s'), $type_display) . '</option>';
51 $opt .= '<option value="product.php?do=addproduct&productid=' . $id . '">' . $bugsys->lang
->string('Add Component') . '</option>';
56 $opt .= '<option value="product.php?do=addversion&productid=' . $id . '">' . $bugsys->lang
->string('Add Version') . '</option>';
59 $type = strtolower($type);
61 $name = $type . '_' . $id;
63 $displayorder = (($displayorder != -1) ? '<input type="text" name="displayorder[' . $name . ']" value="' . $displayorder . '" size="4" class="input" /> ' : '');
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 . '\')" />';
68 // ###################################################################
70 if (empty($_REQUEST['do']))
72 $_REQUEST['do'] = 'modify';
75 // ###################################################################
77 if ($_REQUEST['do'] == 'killversion')
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']));
84 $admin->redirect('product.php?do=modify');
87 // ###################################################################
89 if ($_REQUEST['do'] == 'deleteversion')
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&versionid=' . intval($bugsys->in
['versionid']));
94 // ###################################################################
96 if ($_REQUEST['do'] == 'insertversion')
98 $db->query("INSERT INTO " . TABLE_PREFIX
. "version (productid, version, displayorder) VALUES (" . intval($bugsys->in
['productid']) . ", '" . $bugsys->in
['version'] . "', " . intval($bugsys->in
['displayorder']) . ")");
100 $admin->redirect('product.php?do=modify');
103 // ###################################################################
105 if ($_REQUEST['do'] == 'addversion')
107 $admin->page_start($lang->string('Add Version'));
109 if ($bugsys->in
['productid'] != -1)
111 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . intval($bugsys->in
['productid']));
112 if (!is_array($product))
114 $admin->error($lang->getlex('error_invalid_id'));
119 $bugsys->in
['productid'] = 0;
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();
135 // ###################################################################
137 if ($_REQUEST['do'] == 'updateversion')
139 if (empty($bugsys->in
['version']))
141 $admin->error($lang->string('Please fill in a version number.'));
144 $db->query("UPDATE " . TABLE_PREFIX
. "version SET version = '" . $bugsys->in
['version'] . "', displayorder = " . intval($bugsys->in
['displayorder']) . " WHERE versionid = " . intval($bugsys->in
['versionid']));
147 $admin->redirect('product.php?do=modify');
150 // ###################################################################
152 if ($_REQUEST['do'] == 'editversion')
154 $admin->page_start($lang->string('Edit Version'));
156 $version = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "version WHERE versionid = " . intval($bugsys->in
['versionid']));
157 if (!is_array($version))
159 $admin->error($lang->getlex('error_invalid_id'));
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();
175 // ###################################################################
177 if ($_REQUEST['do'] == 'killproduct
')
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))
182 $list[] = $prod['productid
'];
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) . ")");
191 $admin->redirect('product
.php
?do=modify
');
194 // ###################################################################
196 if ($_REQUEST['do'] == 'deleteproduct
')
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
&
;productid
=' . intval($bugsys->in['productid
']));
201 // ###################################################################
203 if ($_REQUEST['do'] == 'insertproduct
')
205 if (empty($bugsys->in['title
']))
207 $admin->error($lang->string('Please go back
and fill in the title field
.'));
211 INSERT INTO " . TABLE_PREFIX . "product
212 (title, componentmother, description, displayorder)
214 ('" . $bugsys->in['title'] . "', " . intval($bugsys->in['componentmother
']) . ",
215 '" . $bugsys->in['description'] . "', " . intval($bugsys->in['displayorder
']) . "
220 $admin->redirect('product
.php
?do=modify
');
223 // ###################################################################
225 if ($_REQUEST['do'] == 'addproduct
')
227 $admin->page_start($lang->string('Add
New Product
'));
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();
243 // ###################################################################
245 if ($_REQUEST['do'] == 'updateproduct
')
247 if (empty($bugsys->in['title
']))
249 $admin->error($lang->string('Please go back
and fill in the title field
.'));
252 if (empty($bugsys->in['productid
']))
254 $admin->error($lang->getlex('error_invalid_id
'));
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
']));
260 $admin->redirect('product
.php
?do=modify
');
263 // ###################################################################
265 if ($_REQUEST['do'] == 'editproduct
')
267 $admin->page_start($lang->string('Edit Product
'));
269 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . intval($bugsys->in['productid
']));
270 if (!is_array($product))
272 $admin->error($lang->getlex('error_invalid_id
'));
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();
289 // ###################################################################
291 if ($_POST['do'] == 'displayorder')
293 foreach ((array)$_POST['displayorder'] AS $namebit => $displayorder)
295 $name = explode('_', $namebit);
296 if ($name[0] == 'product' OR $name[0] == 'version')
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");
305 $admin->redirect('product.php?do=modify');
308 // ###################################################################
310 if ($_REQUEST['do'] == 'modify')
312 $admin->page_start($lang->string('Products and Versions'));
315 <script type="text
/javascript
">
317 function exec_action(name)
319 window.location = document.getElementById(name).value;
325 $admin->page_code($javascript);
327 $admin->form_start('product.php', 'displayorder');
329 $products = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "product ORDER BY displayorder ASC
");
330 while ($prod = $db->fetch_array($products))
332 if (!$prod['componentmother'])
334 $product["$prod[productid
]"] = $prod;
338 $component["$prod[componentmother
]"][] = $prod;
340 $version["$prod[productid
]"] = array();
342 $products = (array)$product;
344 $versions = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "version ORDER BY displayorder ASC
");
345 while ($vers = $db->fetch_array($versions))
347 $version["$vers[productid
]"]["$vers[versionid
]"] = $vers;
349 $versions = (array)$version;
351 $admin->table_start();
352 $admin->table_head($lang->string('Products / Versions'), 2, 'products_and_versions');
354 // Handle our global versions
355 if (is_array($versions['0']))
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)
360 $admin->row_text('-- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
364 // Now let's do the rest of the versions
365 foreach ($products AS $product)
368 $admin->row_text("<a href
=\"product
.php
?do=editproduct
&
;productid
=$product[productid
]\">$product[title
]</a
>", construct_option_list($lang->string('Product'), $product['productid'], 1, 1, 1, 1, $product['displayorder']), 'middle', 2, 'alt3');
371 foreach ($versions["$product[productid
]"] AS $version)
373 $admin->row_text('-- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
377 foreach ((array)$component["$product[productid
]"] AS $comp)
379 $admin->row_text("-- <a href
=\"product
.php
?do=editproduct
&
;productid
=$comp[productid
]\">$comp[title
]</a
>", construct_option_list($lang->string('Component'), $comp['productid'], 1, 0, 1, 1, $comp['displayorder']), 'middle', 2, 'alt1');
381 // Component versions
382 foreach ($versions["$comp[productid
]"] AS $version)
384 $admin->row_text('---- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
389 $admin->row_submit('<a href="product
.php
?do=addproduct
">[' . $lang->string('Add New Product') . ']</a>', $lang->string('Save Display Order'), null);
398 /*=====================================================================*\
399 || ###################################################################
402 || ###################################################################
403 \*=====================================================================*/