set_focus('tab', 'products', null);
if (!can_perform('canadminversions'))
{
admin_login();
}
function construct_option_list($type_display, $type, $id, $edit, $addcomponent, $addversion, $delete, $displayorder)
{
global $bugsys;
$type = ($type == 'component' ? 'product' : $type);
$type_action = (($type == 'version') ? 'versionid' : 'productid');
if ($edit)
{
$opt .= '';
}
if ($delete)
{
$opt .= '';
}
if ($addcomponent)
{
$opt .= '';
}
if ($addversion)
{
$opt .= '';
}
$type = strtolower($type);
$name = $type . '_' . $id;
$displayorder = (($displayorder != -1) ? ' ' : '');
return $displayorder . ' ';
}
// ###################################################################
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'modify';
}
// ###################################################################
if ($_REQUEST['do'] == 'killversion')
{
$bugsys->input_clean('versionid', TYPE_UINT);
$db->query("DELETE FROM " . TABLE_PREFIX . "version WHERE versionid = " . $bugsys->in['versionid']);
$db->query("DELETE FROM " . TABLE_PREFIX . "bug WHERE version = " . $bugsys->in['versionid']);
build_versions();
$admin->redirect('product.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'deleteversion')
{
$admin->page_confirm(_('Are you sure you want to delete this version? Doing so will do delete all the bugs with this version.'), 'product.php', 'killversion', array('versionid' => $bugsys->input_clean('versionid', TYPE_UINT)));
}
// ###################################################################
if ($_REQUEST['do'] == 'insertversion')
{
$db->query("INSERT INTO " . TABLE_PREFIX . "version (productid, version, displayorder, obsolete) VALUES (" . $bugsys->input_clean('productid', TYPE_UINT) . ", '" . $bugsys->input_escape('version') . "', " . $bugsys->input_clean('displayorder', TYPE_UINT) . ", " . $bugsys->input_clean('obsolete', TYPE_UINT) . ")");
build_versions();
$admin->redirect('product.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'addversion')
{
NavLinks::productsEdit($bugsys->input_clean('productid', TYPE_UINT));
$navigator->set_focus('link', 'products-edit-version', 'products-edit');
if ($bugsys->in['productid'] != -1)
{
$product = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $bugsys->in['productid']);
if (!is_array($product))
{
$admin->error(L_INVALID_ID);
}
}
else
{
$bugsys->in['productid'] = 0;
}
$admin->page_start(_('Add Version'));
$admin->form_start('product.php', 'insertversion');
$admin->form_hidden_field('productid', $bugsys->in['productid']);
$admin->table_start();
$admin->table_head(_('Add New Version'));
$admin->row_input(_('Version Number
This is the version string for this product.
'), 'version');
$admin->row_input(_('Display OrderThe order in which the versions are displayed.
'), 'displayorder');
$admin->row_yesno(_('ObsoleteAn obsolete version cannot have new bugs filed against it, but existing ones can be set to it.
'), 'obsolete', false);
$admin->row_submit();
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
// ###################################################################
if ($_REQUEST['do'] == 'updateversion')
{
if (empty($bugsys->in['version']))
{
$admin->error(_('Please fill in a version number.'));
}
$db->query("UPDATE " . TABLE_PREFIX . "version SET version = '" . $bugsys->input_escape('version') . "', displayorder = " . $bugsys->input_clean('displayorder', TYPE_UINT) . ", obsolete = " . $bugsys->input_clean('obsolete', TYPE_UINT) . " WHERE versionid = " . $bugsys->input_clean('versionid', TYPE_UINT));
build_versions();
$admin->redirect('product.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'editversion')
{
$admin->page_start(_('Edit Version'));
$version = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "version WHERE versionid = " . $bugsys->input_clean('versionid', TYPE_UINT));
if (!is_array($version))
{
$admin->error(L_INVALID_ID);
}
$admin->form_start('product.php', 'updateversion');
$admin->form_hidden_field('versionid', $version['versionid']);
$admin->table_start();
$admin->table_head(sprintf(_('Edit Version - %1$s'), $version['version']));
$admin->row_input(_('Version NumberThis is the version string for this product.
'), 'version', $version['version']);
$admin->row_input(_('Display OrderThe order in which the versions are displayed.
'), 'displayorder', $version['displayorder']);
$admin->row_yesno(_('ObsoleteAn obsolete version cannot have new bugs filed against it, but existing ones can be set to it.
'), 'obsolete', $version['obsolete']);
$admin->row_submit();
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
// ###################################################################
if ($_REQUEST['do'] == 'killproduct')
{
$bugsys->input_clean('productid', TYPE_UINT);
$allprods = $db->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $bugsys->in['productid'] . " OR parentid = " . $bugsys->in['productid']);
while ($prod = $db->fetch_array($allprods))
{
$list[] = $prod['productid'];
}
$db->query("DELETE FROM " . TABLE_PREFIX . "product WHERE productid IN (" . implode(', ', $list) . ")");
$db->query("DELETE FROM " . TABLE_PREFIX . "version WHERE productid IN (" . implode(', ', $list) . ")");
$db->query("DELETE FROM " . TABLE_PREFIX . "bug WHERE product IN (" . implode(', ', $list) . ")");
build_products();
$admin->redirect('product.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'deleteproduct')
{
$admin->page_confirm(_('Are you sure you want to delete this product and all of it\'s versions and components and any bugs that have been assigned those products or components?'), 'product.php', 'killproduct', array('productid' => $bugsys->input_clean('productid', TYPE_UINT)));
}
// ###################################################################
if ($_REQUEST['do'] == 'insertproduct')
{
if (empty($bugsys->in['title']))
{
$admin->error(_('Please go back and fill in the title field.'));
}
$db->query("
INSERT INTO " . TABLE_PREFIX . "product
(title, parentid, description, displayorder)
VALUES
('" . $bugsys->input_escape('title') . "', " . $bugsys->input_clean('parentid', TYPE_UINT) . ",
'" . $bugsys->input_escape('description') . "', " . $bugsys->input_clean('displayorder', TYPE_UINT) . "
)"
);
build_products();
$admin->redirect('product.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'addproduct')
{
if ($bugsys->input_clean('productid', TYPE_UINT))
{
NavLinks::productsEdit($bugsys->in['productid']);
}
else
{
NavLinks::productsAdd();
}
$navigator->set_focus('link', 'products-add', 'products');
$admin->page_start(_('Add New Product'));
$admin->form_start('product.php', 'insertproduct');
$admin->form_hidden_field('parentid', $bugsys->in['productid']);
$admin->table_start();
$admin->table_head(_('Add Product'));
$admin->row_input(_('Title'), 'title');
$admin->row_textarea(_('DescriptionA short description of this product.
'), 'description');
$admin->row_input(_('Display OrderThe order in which the products are displayed.
'), 'displayorder');
$admin->row_submit();
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
// ###################################################################
if ($_REQUEST['do'] == 'updateproduct')
{
if (empty($bugsys->in['title']))
{
$admin->error(_('Please go back and fill in the title field.'));
}
if (empty($bugsys->in['productid']))
{
$admin->error(L_INVALID_ID);
}
$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));
build_products();
$admin->redirect('product.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'editproduct')
{
NavLinks::productsEdit($bugsys->input_clean('productid', TYPE_UINT));
$navigator->set_focus('link', 'products-edit', 'products-edit');
$admin->page_start(_('Edit Product'));
$product = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $bugsys->in['productid']);
if (!is_array($product))
{
$admin->error(L_INVALID_ID);
}
$admin->form_start('product.php', 'updateproduct');
$admin->form_hidden_field('productid', $product['productid']);
$admin->table_start();
$admin->table_head(sprintf(_('Edit Product - %1$s'), $product['title']));
$admin->row_input(_('Title'), 'title', $product['title']);
$admin->row_textarea(_('DescriptionA short description of this product.
'), 'description', $product['description']);
$admin->row_input(_('Display OrderThe order in which the products are displayed.
'), 'displayorder', $product['displayorder']);
$admin->row_submit();
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
// ###################################################################
if ($_POST['do'] == 'displayorder')
{
$bugsys->input_clean('displayorder', TYPE_UINT);
if (is_array($bugsys->in['displayorder']))
{
foreach ($bugsys->in['displayorder'] AS $namebit => $displayorder)
{
$name = explode('_', $namebit);
if ($name[0] == 'product' OR $name[0] == 'version')
{
$id = $bugsys->clean($name[1], TYPE_UINT);
$order = $displayorder;
$db->query("UPDATE " . TABLE_PREFIX . "$name[0] SET displayorder = $order WHERE $name[0]id = $id");
}
}
build_products();
build_versions();
}
$admin->redirect('product.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'modify')
{
$navigator->set_focus('link', 'products-manage', 'products');
$admin->page_start(_('Products and Versions'));
$javascript = <<
EOF;
$admin->page_code($javascript);
$admin->form_start('product.php', 'displayorder');
$products_get = $db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC");
$products = array();
while ($prod = $db->fetch_array($products_get))
{
if (!$prod['parentid'])
{
$products["$prod[productid]"] = $prod;
}
else
{
$components["$prod[parentid]"][] = $prod;
}
$version["$prod[productid]"] = array();
}
$versions_get = $db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC");
$versions = array();
while ($vers = $db->fetch_array($versions_get))
{
$versions["$vers[productid]"]["$vers[versionid]"] = $vers;
}
$admin->table_start();
$admin->table_head(_('Products / Versions'));
// Handle our global versions
if (is_array($versions['0']))
{
$admin->row_text(_('Global Versions'), construct_option_list(_('Product'), 'product', -1, 0, 0, 1, 0, -1), 'middle', 2, 'alt3');
foreach ($versions['0'] AS $version)
{
$admin->row_text('-- ' . $version['version'], construct_option_list(_('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
}
}
// Now let's do the rest of the versions
foreach ($products AS $product)
{
// Product
$admin->row_text("$product[title]", construct_option_list(_('Product'), 'product', $product['productid'], 1, 1, 1, 1, $product['displayorder']), 'middle', 2, 'alt3');
// Versions
if (is_array($versions["$product[productid]"]))
{
foreach ($versions["$product[productid]"] AS $version)
{
$admin->row_text('-- ' . $version['version'], construct_option_list(_('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
}
}
// Components
if (is_array($components["$product[productid]"]))
{
foreach ($components["$product[productid]"] AS $comp)
{
$admin->row_text("-- $comp[title]", construct_option_list(_('Component'), 'component', $comp['productid'], 1, 0, 1, 1, $comp['displayorder']), 'middle', 2, 'alt1');
// Component versions
if (is_array($versions["$comp[productid]"]))
{
foreach ($versions["$comp[productid]"] AS $version)
{
$admin->row_text('---- ' . $version['version'], construct_option_list(_('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
}
}
}
}
}
$admin->row_submit(null, _('Save Display Order'), null);
$admin->table_end();
$admin->form_end();
$admin->page_end();
}
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>