|| ###################################################################
\*=====================================================================*/
+$fetchtemplates = array(
+ 'product',
+ 'product_edit',
+ 'version_edit'
+);
+
// TODO - add API for product.php
require_once('./global.php');
require_once('./includes/functions_datastore.php');
-NavLinks::productsAdd();
-$navigator->set_focus('tab', 'products', null);
-
if (!can_perform('canadminversions'))
{
admin_login();
$name = $type . '_' . $id;
- $displayorder = (($displayorder != -1) ? '<input type="text" name="displayorder[' . $name . ']" value="' . $displayorder . '" size="4" class="input" /> ' : '');
+ $displayorder = (($displayorder != -1) ? '<input type="text" name="displayorder[' . $name . ']" value="' . $displayorder . '" size="4" class="input" style="width:25px" /> ' : '');
return $displayorder . '<select id="' . $name . '" name="' . $name . '" onchange="exec_action(\'' . $name . '\')" class="input">' . $opt . '</select> <input type="button" class="button" name="gobutton" value=" ' . T('Go') . ' " onclick="exec_action(\'' . $name . '\')" />';
}
if ($_REQUEST['do'] == 'insertversion')
{
- $db->query("INSERT INTO " . TABLE_PREFIX . "version (productid, version, displayorder, obsolete) VALUES (" . $input->inputClean('productid', TYPE_UINT) . ", '" . $bugsys->input_escape('version') . "', " . $input->inputClean('displayorder', TYPE_UINT) . ", " . $input->inputClean('obsolete', TYPE_UINT) . ")");
+ $db->query("INSERT INTO " . TABLE_PREFIX . "version (productid, version, displayorder, obsolete) VALUES (" . $input->inputClean('productid', TYPE_UINT) . ", '" . $input->input_escape('version') . "', " . $input->inputClean('displayorder', TYPE_UINT) . ", " . $input->inputClean('obsolete', TYPE_UINT) . ")");
build_versions();
$admin->redirect('product.php?do=modify');
}
if ($_REQUEST['do'] == 'addversion')
{
- NavLinks::productsEdit($input->inputClean('productid', TYPE_UINT));
- $navigator->set_focus('link', 'products-edit-version', 'products-edit');
-
- if ($input->in['productid'] != -1)
- {
- $product = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $input->in['productid']);
- if (!is_array($product))
- {
- $admin->error(L_INVALID_ID);
- }
- }
- else
+ $product = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $input->inputClean('productid', TYPE_UINT));
+ if (!$product)
{
- $input->in['productid'] = 0;
+ $admin->error(L_INVALID_ID);
}
- $admin->page_start(T('Add Version'));
-
- $admin->form_start('product.php', 'insertversion');
- $admin->form_hidden_field('productid', $input->in['productid']);
- $admin->table_start();
- $admin->table_head(T('Add New Version'));
- $admin->row_input(T('Version Number<div><dfn>This is the version string for this product.</dfn></div>'), 'version');
- $admin->row_input(T('Display Order<div><dfn>The order in which the versions are displayed.</dfn></div>'), 'displayorder');
- $admin->row_yesno(T('Obsolete<div><dfn>An obsolete version cannot have new bugs filed against it, but existing ones can be set to it.</dfn></div>'), 'obsolete', false);
- $admin->row_submit();
- $admin->table_end();
- $admin->form_end();
-
- $admin->page_end();
+ $tpl = new BSTemplate('version_edit');
+ $tpl->vars['product'] = $product;
+ $tpl->evaluate()->flush();
}
// ###################################################################
$admin->error(T('Please fill in a version number.'));
}
- $db->query("UPDATE " . TABLE_PREFIX . "version SET version = '" . $bugsys->input_escape('version') . "', displayorder = " . $input->inputClean('displayorder', TYPE_UINT) . ", obsolete = " . $input->inputClean('obsolete', TYPE_UINT) . " WHERE versionid = " . $input->inputClean('versionid', TYPE_UINT));
+ $db->query("UPDATE " . TABLE_PREFIX . "version SET version = '" . $input->inputEscape('version') . "', displayorder = " . $input->inputClean('displayorder', TYPE_UINT) . ", obsolete = " . $input->inputClean('obsolete', TYPE_UINT) . " WHERE versionid = " . $input->inputClean('versionid', TYPE_UINT));
build_versions();
$admin->redirect('product.php?do=modify');
if ($_REQUEST['do'] == 'editversion')
{
- $admin->page_start(T('Edit Version'));
+ $tpl = new BSTemplate('version_edit');
- $version = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "version WHERE versionid = " . $input->inputClean('versionid', TYPE_UINT));
- if (!is_array($version))
+ $tpl->vars['version'] = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "version WHERE versionid = " . $input->inputClean('versionid', TYPE_UINT));
+ if (!$tpl->vars['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(T('Edit Version - %1$s'), $version['version']));
- $admin->row_input(T('Version Number<div><dfn>This is the version string for this product.</dfn></div>'), 'version', $version['version']);
- $admin->row_input(T('Display Order<div><dfn>The order in which the versions are displayed.</dfn></div>'), 'displayorder', $version['displayorder']);
- $admin->row_yesno(T('Obsolete<div><dfn>An obsolete version cannot have new bugs filed against it, but existing ones can be set to it.</dfn></div>'), 'obsolete', $version['obsolete']);
- $admin->row_submit();
- $admin->table_end();
- $admin->form_end();
-
- $admin->page_end();
+ $tpl->evaluate()->flush();
}
// ###################################################################
INSERT INTO " . TABLE_PREFIX . "product
(title, parentid, description, displayorder)
VALUES
- ('" . $bugsys->input_escape('title') . "', " . $input->inputClean('parentid', TYPE_UINT) . ",
- '" . $bugsys->input_escape('description') . "', " . $input->inputClean('displayorder', TYPE_UINT) . "
+ ('" . $input->inputEscape('title') . "', " . $input->inputClean('parentid', TYPE_UINT) . ",
+ '" . $input->inputEscape('description') . "', " . $input->inputClean('displayorder', TYPE_UINT) . "
)"
);
build_products();
if ($_REQUEST['do'] == 'addproduct')
{
- if ($input->inputClean('productid', TYPE_UINT))
- {
- NavLinks::productsEdit($input->in['productid']);
- }
- else
- {
- NavLinks::productsAdd();
- }
- $navigator->set_focus('link', 'products-add', 'products');
-
- $admin->page_start(T('Add New Product'));
-
- $admin->form_start('product.php', 'insertproduct');
- $admin->form_hidden_field('parentid', $input->in['productid']);
- $admin->table_start();
- $admin->table_head(T('Add Product'));
- $admin->row_input(T('Title'), 'title');
- $admin->row_textarea(T('Description<div><dfn>A short description of this product.</dfn></div>'), 'description');
- $admin->row_input(T('Display Order<div><dfn>The order in which the products are displayed.</dfn></div>'), 'displayorder');
- $admin->row_submit();
- $admin->table_end();
- $admin->form_end();
-
- $admin->page_end();
+ $tpl = new BSTemplate('product_edit');
+ $tpl->vars['parent'] = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $input->inputClean('productid', TYPE_UINT));
+ $tpl->evaluate()->flush();
}
// ###################################################################
$admin->error(L_INVALID_ID);
}
- $db->query("UPDATE " . TABLE_PREFIX . "product SET title = '" . $bugsys->input_escape('title') . "', description = '" . $bugsys->input_escape('description') . "', displayorder = " . $input->inputClean('displayorder', TYPE_UINT) . " WHERE productid = " . $input->inputClean('productid', TYPE_UINT));
+ $db->query("UPDATE " . TABLE_PREFIX . "product SET title = '" . $input->inputEscape('title') . "', description = '" . $input->inputEscape('description') . "', displayorder = " . $input->inputClean('displayorder', TYPE_UINT) . " WHERE productid = " . $input->inputClean('productid', TYPE_UINT));
build_products();
$admin->redirect('product.php?do=modify');
if ($_REQUEST['do'] == 'editproduct')
{
- NavLinks::productsEdit($input->inputClean('productid', TYPE_UINT));
- $navigator->set_focus('link', 'products-edit', 'products-edit');
-
- $admin->page_start(T('Edit Product'));
-
- $product = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $input->in['productid']);
- if (!is_array($product))
+ $tpl = new BSTemplate('product_edit');
+ $tpl->vars['product'] = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $input->in['productid']);
+ if (!is_array($tpl->vars['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(T('Edit Product - %1$s'), $product['title']));
- $admin->row_input(T('Title'), 'title', $product['title']);
- $admin->row_textarea(T('Description<div><dfn>A short description of this product.</dfn></div>'), 'description', $product['description']);
- $admin->row_input(T('Display Order<div><dfn>The order in which the products are displayed.</dfn></div>'), 'displayorder', $product['displayorder']);
- $admin->row_submit();
- $admin->table_end();
- $admin->form_end();
-
- $admin->page_end();
+ $tpl->vars['parent'] = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = {$tpl->vars['product']['parentid']}");
+
+ $tpl->evaluate()->flush();
}
// ###################################################################
$input->inputClean('displayorder', TYPE_UINT);
if (is_array($input->in['displayorder']))
{
- foreach ($input->in['displayorder'] AS $namebit => $displayorder)
+ foreach ($input->in['displayorder'] as $namebit => $order)
{
$name = explode('_', $namebit);
- if ($name[0] == 'product' OR $name[0] == 'version')
+ if ($name[0] == 'product' || $name[0] == 'version')
{
- $id = $bugsys->clean($name[1], TYPE_UINT);
- $order = $displayorder;
+ $id = $input->clean($name[1], TYPE_UINT);
$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');
+
+ admin_flash_redirect('product.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'modify')
{
- $navigator->set_focus('link', 'products-manage', 'products');
-
- $admin->page_start(T('Products and Versions'));
-
- $javascript = <<<EOF
-<script type="text/javascript">
-<!--
- function exec_action(name)
- {
- window.location = document.getElementById(name).value;
- }
-//-->
-</script>
-EOF;
-
- $admin->page_code($javascript);
-
- $admin->form_start('product.php', 'displayorder');
+ $tpl = new BSTemplate('product');
$products_get = $db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC");
- $products = array();
+ $tpl->vars['products'] = $tpl->vars['components'] = $tpl->vars['version'] = array();
foreach ($products_get as $prod)
{
if (!$prod['parentid'])
{
- $products["$prod[productid]"] = $prod;
+ $tpl->vars['products'][$prod['productid']] = $prod;
}
else
{
- $components["$prod[parentid]"][] = $prod;
+ $tpl->vars['components'][$prod['parentid']][] = $prod;
}
- $version["$prod[productid]"] = array();
+ $tpl->vars['version'][$prod['productid']] = array();
}
$versions_get = $db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC");
- $versions = array();
foreach ($versions_get as $vers)
{
- $versions["$vers[productid]"]["$vers[versionid]"] = $vers;
- }
-
- $admin->table_start();
- $admin->table_head(T('Products / Versions'));
-
- // Handle our global versions
- if (is_array($versions['0']))
- {
- $admin->row_text(T('Global Versions'), construct_option_list(T('Product'), 'product', -1, 0, 0, 1, 0, -1), 'middle', 2, 'alt3');
- foreach ($versions['0'] AS $version)
- {
- $admin->row_text('-- ' . $version['version'], construct_option_list(T('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("<a href=\"product.php?do=editproduct&productid=$product[productid]\">$product[title]</a>", construct_option_list(T('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(T('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("-- <a href=\"product.php?do=editproduct&productid=$comp[productid]\">$comp[title]</a>", construct_option_list(T('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(T('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']), 'middle', 2, 'alt2');
- }
- }
- }
- }
+ $tpl->vars['versions'][$vers['productid']][$vers['versionid']] = $vers;
}
-
- $admin->row_submit(null, T('Save Display Order'), null);
-
- $admin->table_end();
-
- $admin->form_end();
-
- $admin->page_end();
+
+ $tpl->evaluate()->flush();
}
?>
\ No newline at end of file
--- /dev/null
+<%- $templates['doctype'] %>
+<html xmlns="http://www.w3.org/1999/xhtml" lang="<%- $stylevar['lang'] %>" xml:lang="<%- $stylevar['lang'] %>" dir="<%- $stylevar['lang_dir'] %>">
+<head>
+ <%- $templates['headinclude'] %>
+ <title><%- $templates['title'] %> - <%- T('Products and Versions') %></title>
+
+ <script type="text/javascript" charset="utf-8">
+ /*<![CDATA[*/
+ function exec_action(name)
+ {
+ window.location = document.getElementById(name).value;
+ }
+ /*]]>*/
+ </script>
+</head>
+
+<body>
+
+<%- $templates['nav'] %>
+
+<div id="title"><%- T('Products and Versions') %></div>
+
+<div id="body">
+
+<%- admin_flash() %>
+
+<form action="product.php" method="post">
+<input type="hidden" name="do" value="displayorder" />
+
+<table>
+<thead>
+ <tr><td colspan="2"><%- T('Products / Versions') %></td></tr>
+</thead>
+
+<% foreach ($products as $product): %>
+<tr class="headings">
+ <td><a href="product.php?do=editproduct&productid=<%- $product['productid'] %>"><%- $product['title'] %></a></td>
+ <td><%- construct_option_list(T('Product'), 'product', $product['productid'], 1, 1, 1, 1, $product['displayorder']) %></td>
+</tr>
+
+ <!-- non-component versions -->
+ <% foreach ($versions[$product['productid']] as $version): %>
+ <tr class="alt2">
+ <td>-- <%- $version['version'] %></td>
+ <td><%- construct_option_list(T('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']) %></td>
+ </tr>
+ <% endforeach %>
+ <!-- / non-component versions -->
+
+ <!-- components -->
+ <% if (is_array($components[$product['productid']])): %>
+ <% foreach ($components[$product['productid']] as $comp): %>
+ <tr class="alt1">
+ <td>-- <a href="product.php?do=editproduct&productid=<%- $comp['productid'] %>"><%- $comp['title'] %></a></td>
+ <td><%- construct_option_list(T('Component'), 'component', $comp['productid'], 1, 0, 1, 1, $comp['displayorder']) %></td>
+ </tr>
+
+ <!-- component versions -->
+ <% if (is_array($versions[$comp['productid']])): %>
+ <% foreach ($versions[$comp['productid']] as $version): %>
+ <tr class="alt2">
+ <td>---- <%- $version['version'] %></td>
+ <td><%- construct_option_list(T('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']) %></td>
+ </tr>
+ <% endforeach %>
+ <% endif %>
+ <!-- / component versions -->
+ <% endforeach %>
+ <% endif %>
+ <!-- / components -->
+<% endforeach %>
+<tr class="submit">
+ <td colspan="2" style="text-align:center">
+ <a href="product.php?do=addproduct" class="button"><%- T('Add New Product') %></a>
+ <input type="submit" value="<%- T('Save Display Order') %>" />
+ </td>
+</tr>
+</table>
+
+</form>
+
+<%- admin_footer() %>
+
+</div>
+
+<script type="text/javascript"> nav_init("fields", "fields_product"); </script>
+
+</body>
+
+</html>
\ No newline at end of file