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 NavLinks
::productsAdd();
26 $navigator->set_focus('tab', 'products', null);
28 if (!can_perform('canadminversions'))
33 function construct_option_list($type, $id, $edit, $addcomponent, $addversion, $delete, $displayorder)
37 $type_display = $type;
38 $type = strtolower($type);
39 $type = ($type == 'component' ? 'product' : $type);
40 $type_action = (($type == 'version') ? 'versionid' : 'productid');
44 $opt .= '<option value="product.php?do=edit' . $type . '&' . $type_action . '=' . $id . '">' . sprintf($bugsys->lang
->string('Edit %1$s'), $type_display) . '</option
>';
49 $opt .= '<option value
="product.php?do=delete' . $type . '&' . $type_action . '=' . $id . '">' . sprintf($bugsys->lang->string('Delete %
1$s'), $type_display) . '</option>';
54 $opt .= '<option value="product.php?do=addproduct&productid=' . $id . '">' . $bugsys->lang
->string('Add Component') . '</option>';
59 $opt .= '<option value="product.php?do=addversion&productid=' . $id . '">' . $bugsys->lang
->string('Add Version') . '</option>';
62 $type = strtolower($type);
64 $name = $type . '_' . $id;
66 $displayorder = (($displayorder != -1) ? '<input type="text" name="displayorder[' . $name . ']" value="' . $displayorder . '" size="4" class="input" /> ' : '');
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 . '\')" />';
71 // ###################################################################
73 if (empty($_REQUEST['do']))
75 $_REQUEST['do'] = 'modify';
78 // ###################################################################
80 if ($_REQUEST['do'] == 'killversion')
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']));
87 $admin->redirect('product.php?do=modify');
90 // ###################################################################
92 if ($_REQUEST['do'] == 'deleteversion')
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&versionid=' . intval($bugsys->in
['versionid']));
97 // ###################################################################
99 if ($_REQUEST['do'] == 'insertversion')
101 $db->query("INSERT INTO " . TABLE_PREFIX
. "version (productid, version, displayorder) VALUES (" . intval($bugsys->in
['productid']) . ", '" . $bugsys->in
['version'] . "', " . intval($bugsys->in
['displayorder']) . ")");
103 $admin->redirect('product.php?do=modify');
106 // ###################################################################
108 if ($_REQUEST['do'] == 'addversion')
110 NavLinks
::productsEdit($bugsys->input_clean('productid', TYPE_UINT
));
111 $navigator->set_focus('link', 'products-edit-version', 'products-edit');
113 $admin->page_start($lang->string('Add Version'));
115 if ($bugsys->in
['productid'] != -1)
117 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $bugsys->in
['productid']);
118 if (!is_array($product))
120 $admin->error($lang->getlex('error_invalid_id'));
125 $bugsys->in
['productid'] = 0;
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();
141 // ###################################################################
143 if ($_REQUEST['do'] == 'updateversion')
145 if (empty($bugsys->in
['version']))
147 $admin->error($lang->string('Please fill in a version number.'));
150 $db->query("UPDATE " . TABLE_PREFIX
. "version SET version = '" . $bugsys->in
['version'] . "', displayorder = " . intval($bugsys->in
['displayorder']) . " WHERE versionid = " . intval($bugsys->in
['versionid']));
153 $admin->redirect('product.php?do=modify');
156 // ###################################################################
158 if ($_REQUEST['do'] == 'editversion')
160 $admin->page_start($lang->string('Edit Version'));
162 $version = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "version WHERE versionid = " . intval($bugsys->in
['versionid']));
163 if (!is_array($version))
165 $admin->error($lang->getlex('error_invalid_id'));
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();
181 // ###################################################################
183 if ($_REQUEST['do'] == 'killproduct
')
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))
188 $list[] = $prod['productid
'];
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) . ")");
197 $admin->redirect('product
.php
?do=modify
');
200 // ###################################################################
202 if ($_REQUEST['do'] == 'deleteproduct
')
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
&
;productid
=' . intval($bugsys->in['productid
']));
207 // ###################################################################
209 if ($_REQUEST['do'] == 'insertproduct
')
211 if (empty($bugsys->in['title
']))
213 $admin->error($lang->string('Please go back
and fill in the title field
.'));
217 INSERT INTO " . TABLE_PREFIX . "product
218 (title, componentmother, description, displayorder)
220 ('" . $bugsys->in['title'] . "', " . intval($bugsys->in['componentmother
']) . ",
221 '" . $bugsys->in['description'] . "', " . intval($bugsys->in['displayorder
']) . "
226 $admin->redirect('product
.php
?do=modify
');
229 // ###################################################################
231 if ($_REQUEST['do'] == 'addproduct
')
233 if ($bugsys->input_clean('productid
', TYPE_UINT))
235 NavLinks::productsEdit($bugsys->in['productid
']);
239 NavLinks::productsAdd();
241 $navigator->set_focus('link
', 'products
-add
', 'products
');
243 $admin->page_start($lang->string('Add
New Product
'));
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();
259 // ###################################################################
261 if ($_REQUEST['do'] == 'updateproduct
')
263 if (empty($bugsys->in['title
']))
265 $admin->error($lang->string('Please go back
and fill in the title field
.'));
268 if (empty($bugsys->in['productid
']))
270 $admin->error($lang->getlex('error_invalid_id
'));
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
']));
276 $admin->redirect('product
.php
?do=modify
');
279 // ###################################################################
281 if ($_REQUEST['do'] == 'editproduct
')
283 NavLinks::productsEdit($bugsys->input_clean('productid
', TYPE_UINT));
284 $navigator->set_focus('link
', 'products
-edit
', 'products
-edit
');
286 $admin->page_start($lang->string('Edit Product
'));
288 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $bugsys->in['productid
']);
289 if (!is_array($product))
291 $admin->error($lang->getlex('error_invalid_id
'));
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();
308 // ###################################################################
310 if ($_POST['do'] == 'displayorder')
312 foreach ((array)$_POST['displayorder'] AS $namebit => $displayorder)
314 $name = explode('_', $namebit);
315 if ($name[0] == 'product' OR $name[0] == 'version')
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");
324 $admin->redirect('product.php?do=modify');
327 // ###################################################################
329 if ($_REQUEST['do'] == 'modify')
331 $navigator->set_focus('link', 'products-manage', 'products');
333 $admin->page_start($lang->string('Products and Versions'));
336 <script type="text
/javascript
">
338 function exec_action(name)
340 window.location = document.getElementById(name).value;
346 $admin->page_code($javascript);
348 $admin->form_start('product.php', 'displayorder');
350 $products = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "product ORDER BY displayorder ASC
");
351 while ($prod = $db->fetch_array($products))
353 if (!$prod['componentmother'])
355 $product["$prod[productid
]"] = $prod;
359 $component["$prod[componentmother
]"][] = $prod;
361 $version["$prod[productid
]"] = array();
363 $products = (array)$product;
365 $versions = $db->query("SELECT
* FROM
" . TABLE_PREFIX . "version ORDER BY displayorder ASC
");
366 while ($vers = $db->fetch_array($versions))
368 $version["$vers[productid
]"]["$vers[versionid
]"] = $vers;
370 $versions = (array)$version;
372 $admin->table_start();
373 $admin->table_head($lang->string('Products / Versions'), 2, 'products_and_versions');
375 // Handle our global versions
376 if (is_array($versions['0']))
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)
381 $admin->row_text('-- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
385 // Now let's do the rest of the versions
386 foreach ($products AS $product)
389 $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');
392 foreach ($versions["$product[productid
]"] AS $version)
394 $admin->row_text('-- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
398 foreach ((array)$component["$product[productid
]"] AS $comp)
400 $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');
402 // Component versions
403 foreach ($versions["$comp[productid
]"] AS $version)
405 $admin->row_text('---- ' . $version['version'], construct_option_list($lang->string('Version'), $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
410 $admin->row_submit(null, $lang->string('Save Display Order'), null);
419 /*=====================================================================*\
420 || ###################################################################
423 || ###################################################################
424 \*=====================================================================*/