2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
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 // TODO - add API for product.php
24 require_once('./global.php');
25 require_once('./includes/functions_datastore.php');
27 NavLinks
::productsAdd();
28 $navigator->set_focus('tab', 'products', null
);
30 if (!can_perform('canadminversions'))
35 function construct_option_list($type_display, $type, $id, $edit, $addcomponent, $addversion, $delete, $displayorder)
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(_('Edit %1$s'), $type_display) . '</option>';
49 $opt .= '<option value="product.php?do=delete' . $type . '&' . $type_action . '=' . $id . '">' . sprintf(_('Delete %1$s'), $type_display) . '</option>';
54 $opt .= '<option value="product.php?do=addproduct&productid=' . $id . '">' . _('Add Component') . '</option>';
59 $opt .= '<option value="product.php?do=addversion&productid=' . $id . '">' . _('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=" ' . _('Go') . ' " onclick="exec_action(\'' . $name . '\')" />';
71 // ###################################################################
73 if (empty($_REQUEST['do']))
75 $_REQUEST['do'] = 'modify';
78 // ###################################################################
80 if ($_REQUEST['do'] == 'killversion')
82 $bugsys->input_clean('versionid', TYPE_UINT
);
83 $db->query("DELETE FROM " . TABLE_PREFIX
. "version WHERE versionid = " . $bugsys->in
['versionid']);
84 $db->query("DELETE FROM " . TABLE_PREFIX
. "bug WHERE version = " . $bugsys->in
['versionid']);
88 $admin->redirect('product.php?do=modify');
91 // ###################################################################
93 if ($_REQUEST['do'] == 'deleteversion')
95 $admin->page_confirm(_('Are you sure you want to delete this version? Doing so will do <strong>delete all the bugs with this version</strong>.'), 'product.php', 'killversion', array('versionid' => $bugsys->input_clean('versionid', TYPE_UINT
)));
98 // ###################################################################
100 if ($_REQUEST['do'] == 'insertversion')
102 $db->query("INSERT INTO " . TABLE_PREFIX
. "version (productid, version, displayorder) VALUES (" . $bugsys->input_clean('productid', TYPE_UINT
) . ", '" . $bugsys->input_escape('version') . "', " . $bugsys->input_clean('displayorder', TYPE_UINT
) . ")");
104 $admin->redirect('product.php?do=modify');
107 // ###################################################################
109 if ($_REQUEST['do'] == 'addversion')
111 NavLinks
::productsEdit($bugsys->input_clean('productid', TYPE_UINT
));
112 $navigator->set_focus('link', 'products-edit-version', 'products-edit');
114 $admin->page_start(_('Add Version'));
116 if ($bugsys->in
['productid'] != -1)
118 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $bugsys->in
['productid']);
119 if (!is_array($product))
121 $admin->error(L_INVALID_ID
);
126 $bugsys->in
['productid'] = 0;
129 $admin->form_start('product.php', 'insertversion');
130 $admin->form_hidden_field('productid', $bugsys->in
['productid']);
131 $admin->table_start();
132 $admin->table_head(_('Add New Version'));
133 $admin->row_input(_('Version Number<div><dfn>This is the version string for this product.</dfn></div>'), 'version');
134 $admin->row_input(_('Display Order<div><dfn>The order in which the versions are displayed.</dfn></div>'), 'displayorder');
135 $admin->row_submit();
142 // ###################################################################
144 if ($_REQUEST['do'] == 'updateversion')
146 if (empty($bugsys->in
['version']))
148 $admin->error(_('Please fill in a version number.'));
151 $db->query("UPDATE " . TABLE_PREFIX
. "version SET version = '" . $bugsys->input_escape('version') . "', displayorder = " . $bugsys->input_clean('displayorder', TYPE_UINT
) . " WHERE versionid = " . $bugsys->input_clean('versionid', TYPE_UINT
));
154 $admin->redirect('product.php?do=modify');
157 // ###################################################################
159 if ($_REQUEST['do'] == 'editversion')
161 $admin->page_start(_('Edit Version'));
163 $version = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "version WHERE versionid = " . $bugsys->input_clean('versionid', TYPE_UINT
));
164 if (!is_array($version))
166 $admin->error(L_INVALID_ID
);
169 $admin->form_start('product.php', 'updateversion');
170 $admin->form_hidden_field('versionid', $version['versionid']);
171 $admin->table_start();
172 $admin->table_head(sprintf(_('Edit Version - %1$s'), $version['version']));
173 $admin->row_input(_('Version Number<div><dfn>This is the version string for this product.</dfn></div>'), 'version', $version['version']);
174 $admin->row_input(_('Display Order<div><dfn>The order in which the versions are displayed.</dfn></div>'), 'displayorder', $version['displayorder']);
175 $admin->row_submit();
182 // ###################################################################
184 if ($_REQUEST['do'] == 'killproduct')
186 $bugsys->input_clean('productid', TYPE_UINT
);
187 $allprods = $db->query("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $bugsys->in
['productid'] . " OR componentmother = " . $bugsys->in
['productid']);
188 while ($prod = $db->fetch_array($allprods))
190 $list[] = $prod['productid'];
193 $db->query("DELETE FROM " . TABLE_PREFIX
. "product WHERE productid IN (" . implode(', ', $list) . ")");
194 $db->query("DELETE FROM " . TABLE_PREFIX
. "version WHERE productid IN (" . implode(', ', $list) . ")");
195 $db->query("DELETE FROM " . TABLE_PREFIX
. "bug WHERE product IN (" . implode(', ', $list) . ")");
199 $admin->redirect('product.php?do=modify');
202 // ###################################################################
204 if ($_REQUEST['do'] == 'deleteproduct')
206 $admin->page_confirm(_('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', 'killproduct', array('productid' => $bugsys->input_clean('productid', TYPE_UINT
)));
209 // ###################################################################
211 if ($_REQUEST['do'] == 'insertproduct')
213 if (empty($bugsys->in
['title']))
215 $admin->error(_('Please go back and fill in the title field.'));
219 INSERT INTO " . TABLE_PREFIX
. "product
220 (title, componentmother, description, displayorder)
222 ('" . $bugsys->input_escape('title') . "', " . $bugsys->input_clean('componentmother', TYPE_UINT
) . ",
223 '" . $bugsys->input_escape('description') . "', " . $bugsys->input_clean('displayorder', TYPE_UINT
) . "
228 $admin->redirect('product.php?do=modify');
231 // ###################################################################
233 if ($_REQUEST['do'] == 'addproduct')
235 if ($bugsys->input_clean('productid', TYPE_UINT
))
237 NavLinks
::productsEdit($bugsys->in
['productid']);
241 NavLinks
::productsAdd();
243 $navigator->set_focus('link', 'products-add', 'products');
245 $admin->page_start(_('Add New Product'));
247 $admin->form_start('product.php', 'insertproduct');
248 $admin->form_hidden_field('componentmother', $bugsys->in
['productid']);
249 $admin->table_start();
250 $admin->table_head(_('Add Product'));
251 $admin->row_input(_('Title'), 'title');
252 $admin->row_textarea(_('Description<div><dfn>A short description of this product.</dfn></div>'), 'description');
253 $admin->row_input(_('Display Order<div><dfn>The order in which the products are displayed.</dfn></div>'), 'displayorder');
254 $admin->row_submit();
261 // ###################################################################
263 if ($_REQUEST['do'] == 'updateproduct')
265 if (empty($bugsys->in
['title']))
267 $admin->error(_('Please go back and fill in the title field.'));
270 if (empty($bugsys->in
['productid']))
272 $admin->error(L_INVALID_ID
);
275 $db->query("UPDATE " . TABLE_PREFIX
. "product SET title = '" . $bugsys->input_escape('title') . "', description = '" . $bugsys->input_escape('description') . "', displayorder = " . $bugsys->input_clean('displayorder', TYPE_UINT
) . " WHERE productid = " . $bugsys->input_clean('productid', TYPE_UINT
));
278 $admin->redirect('product.php?do=modify');
281 // ###################################################################
283 if ($_REQUEST['do'] == 'editproduct')
285 NavLinks
::productsEdit($bugsys->input_clean('productid', TYPE_UINT
));
286 $navigator->set_focus('link', 'products-edit', 'products-edit');
288 $admin->page_start(_('Edit Product'));
290 $product = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "product WHERE productid = " . $bugsys->in
['productid']);
291 if (!is_array($product))
293 $admin->error(L_INVALID_ID
);
296 $admin->form_start('product.php', 'updateproduct');
297 $admin->form_hidden_field('productid', $product['productid']);
298 $admin->table_start();
299 $admin->table_head(sprintf(_('Edit Product - %1$s'), $product['title']));
300 $admin->row_input(_('Title'), 'title', $product['title']);
301 $admin->row_textarea(_('Description<div><dfn>A short description of this product.</dfn></div>'), 'description', $product['description']);
302 $admin->row_input(_('Display Order<div><dfn>The order in which the products are displayed.</dfn></div>'), 'displayorder', $product['displayorder']);
303 $admin->row_submit();
310 // ###################################################################
312 if ($_POST['do'] == 'displayorder')
314 $bugsys->input_clean('displayorder', TYPE_UINT
);
315 if (is_array($bugsys->in
['displayorder']))
317 foreach ($bugsys->in
['displayorder'] AS $namebit => $displayorder)
319 $name = explode('_', $namebit);
320 if ($name[0] == 'product' OR $name[0] == 'version')
322 $id = $bugsys->clean($name[1], TYPE_UINT
);
323 $order = $displayorder;
324 $db->query("UPDATE " . TABLE_PREFIX
. "$name[0] SET displayorder = $order WHERE $name[0]id = $id");
330 $admin->redirect('product.php?do=modify');
333 // ###################################################################
335 if ($_REQUEST['do'] == 'modify')
337 $navigator->set_focus('link', 'products-manage', 'products');
339 $admin->page_start(_('Products and Versions'));
342 <script type
="text/javascript">
344 function exec_action(name
)
346 window
.location
= document
.getElementById(name
).value
;
352 $admin->page_code($javascript);
354 $admin->form_start('product.php', 'displayorder');
356 $products_get = $db->query("SELECT * FROM " . TABLE_PREFIX
. "product ORDER BY displayorder ASC");
358 while ($prod = $db->fetch_array($products_get))
360 if (!$prod['componentmother'])
362 $products["$prod[productid]"] = $prod;
366 $components["$prod[componentmother]"][] = $prod;
368 $version["$prod[productid]"] = array();
371 $versions_get = $db->query("SELECT * FROM " . TABLE_PREFIX
. "version ORDER BY displayorder ASC");
373 while ($vers = $db->fetch_array($versions_get))
375 $versions["$vers[productid]"]["$vers[versionid]"] = $vers;
378 $admin->table_start();
379 $admin->table_head(_('Products / Versions'));
381 // Handle our global versions
382 if (is_array($versions['0']))
384 $admin->row_text(_('Global Versions'), construct_option_list(_('Product'), 'product', -1, 0, 0, 1, 0, -1), 'middle', 2, 'alt3');
385 foreach ($versions['0'] AS $version)
387 $admin->row_text('-- ' . $version['version'], construct_option_list(_('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
391 // Now let's do the rest of the versions
392 foreach ($products AS $product)
395 $admin->row_text("<a href=\"product.php?do=editproduct&productid=$product[productid]\">$product[title]</a>", construct_option_list(_('Product'), 'product', $product['productid'], 1, 1, 1, 1, $product['displayorder']), 'middle', 2, 'alt3');
398 if (is_array($versions["$product[productid]"]))
400 foreach ($versions["$product[productid]"] AS $version)
402 $admin->row_text('-- ' . $version['version'], construct_option_list(_('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
407 if (is_array($components["$product[productid]"]))
409 foreach ($components["$product[productid]"] AS $comp)
411 $admin->row_text("-- <a href=\"product.php?do=editproduct&productid=$comp[productid]\">$comp[title]</a>", construct_option_list(_('Component'), 'component', $comp['productid'], 1, 0, 1, 1, $comp['displayorder']), 'middle', 2, 'alt1');
413 // Component versions
414 if (is_array($versions["$comp[productid]"]))
416 foreach ($versions["$comp[productid]"] AS $version)
418 $admin->row_text('---- ' . $version['version'], construct_option_list(_('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
425 $admin->row_submit(null
, _('Save Display Order'), null
);
434 /*=====================================================================*\
435 || ###################################################################
438 || ###################################################################
439 \*=====================================================================*/