From 1cc0111ca6c629c863492a061c2af4ed77d286e9 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 24 Mar 2009 13:47:11 -0400 Subject: [PATCH] Update admin/product.php to use the new admin templates * product.php * templates/nav.html: Link up product.php * templates/product.html: New file * templates/product_edit.html: New file * templates/version_edit.html: New file --- admin/product.php | 223 ++++++------------------------ admin/templates/nav.html | 4 +- admin/templates/product.html | 90 ++++++++++++ admin/templates/product_edit.html | 71 ++++++++++ admin/templates/version_edit.html | 76 ++++++++++ 5 files changed, 283 insertions(+), 181 deletions(-) create mode 100644 admin/templates/product.html create mode 100644 admin/templates/product_edit.html create mode 100644 admin/templates/version_edit.html diff --git a/admin/product.php b/admin/product.php index dcd02db..4fac001 100755 --- a/admin/product.php +++ b/admin/product.php @@ -19,14 +19,17 @@ || ################################################################### \*=====================================================================*/ +$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(); @@ -63,7 +66,7 @@ function construct_option_list($type_display, $type, $id, $edit, $addcomponent, $name = $type . '_' . $id; - $displayorder = (($displayorder != -1) ? ' ' : ''); + $displayorder = (($displayorder != -1) ? ' ' : ''); return $displayorder . ' '; } @@ -99,7 +102,7 @@ if ($_REQUEST['do'] == 'deleteversion') 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'); } @@ -108,36 +111,15 @@ if ($_REQUEST['do'] == 'insertversion') 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
This is the version string for this product.
'), 'version'); - $admin->row_input(T('Display Order
The order in which the versions are displayed.
'), 'displayorder'); - $admin->row_yesno(T('Obsolete
An 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(); + $tpl = new BSTemplate('version_edit'); + $tpl->vars['product'] = $product; + $tpl->evaluate()->flush(); } // ################################################################### @@ -149,7 +131,7 @@ if ($_REQUEST['do'] == 'updateversion') $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'); @@ -159,26 +141,15 @@ if ($_REQUEST['do'] == 'updateversion') 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
This is the version string for this product.
'), 'version', $version['version']); - $admin->row_input(T('Display Order
The order in which the versions are displayed.
'), 'displayorder', $version['displayorder']); - $admin->row_yesno(T('Obsolete
An 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(); + $tpl->evaluate()->flush(); } // ################################################################### @@ -221,8 +192,8 @@ if ($_REQUEST['do'] == 'insertproduct') 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(); @@ -234,30 +205,9 @@ if ($_REQUEST['do'] == 'insertproduct') 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
A short description of this product.
'), 'description'); - $admin->row_input(T('Display Order
The order in which the products are displayed.
'), '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(); } // ################################################################### @@ -274,7 +224,7 @@ if ($_REQUEST['do'] == 'updateproduct') $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'); @@ -284,29 +234,15 @@ if ($_REQUEST['do'] == 'updateproduct') 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
A short description of this product.
'), 'description', $product['description']); - $admin->row_input(T('Display Order
The order in which the products are displayed.
'), '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(); } // ################################################################### @@ -316,121 +252,50 @@ if ($_POST['do'] == 'displayorder') $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; - - $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("$product[title]", 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("-- $comp[title]", 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 diff --git a/admin/templates/nav.html b/admin/templates/nav.html index 0b05df3..b70f900 100644 --- a/admin/templates/nav.html +++ b/admin/templates/nav.html @@ -19,10 +19,10 @@ -
  • <%- T('Fields') %>
  • +
    • -
    • <%- T('Products') %>
    • +
    • <%- T('Custom Fields') %>
    • <%- T('Priorities') %>
    • <%- T('Resolutions') %>
    • diff --git a/admin/templates/product.html b/admin/templates/product.html new file mode 100644 index 0000000..083ae73 --- /dev/null +++ b/admin/templates/product.html @@ -0,0 +1,90 @@ +<%- $templates['doctype'] %> + + + <%- $templates['headinclude'] %> + <%- $templates['title'] %> - <%- T('Products and Versions') %> + + + + + + +<%- $templates['nav'] %> + +
      <%- T('Products and Versions') %>
      + +
      + +<%- admin_flash() %> + +
      + + + + + + + +<% foreach ($products as $product): %> + + + + + + + <% foreach ($versions[$product['productid']] as $version): %> + + + + + <% endforeach %> + + + + <% if (is_array($components[$product['productid']])): %> + <% foreach ($components[$product['productid']] as $comp): %> + + + + + + + <% if (is_array($versions[$comp['productid']])): %> + <% foreach ($versions[$comp['productid']] as $version): %> + + + + + <% endforeach %> + <% endif %> + + <% endforeach %> + <% endif %> + +<% endforeach %> + + + +
      <%- T('Products / Versions') %>
      <%- $product['title'] %><%- construct_option_list(T('Product'), 'product', $product['productid'], 1, 1, 1, 1, $product['displayorder']) %>
      -- <%- $version['version'] %><%- construct_option_list(T('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']) %>
      -- <%- $comp['title'] %><%- construct_option_list(T('Component'), 'component', $comp['productid'], 1, 0, 1, 1, $comp['displayorder']) %>
      ---- <%- $version['version'] %><%- construct_option_list(T('Version'), 'version', $version['versionid'], 1, 0, 0, 1, $version['displayorder']) %>
      + <%- T('Add New Product') %> + +
      + +
      + +<%- admin_footer() %> + +
      + + + + + + \ No newline at end of file diff --git a/admin/templates/product_edit.html b/admin/templates/product_edit.html new file mode 100644 index 0000000..82e0879 --- /dev/null +++ b/admin/templates/product_edit.html @@ -0,0 +1,71 @@ +<%- $templates['doctype'] %> + + + <%- $templates['headinclude'] %> + <%- $templates['title'] %> - <%- T('Manage Products') %> + + + + +<%- $templates['nav'] %> + +
      <%- T('Manage Products') %>
      + +
      + +<%- admin_flash() %> + +
      + +<% if ($product): %><% endif %> +<% if (!$product): %><% endif %> + +
      + <%- ($product ? T('Edit Product') : T('Add New Product')) %> + +
      + + <% if ($parent): %> +
      +
      <%- $parent['title'] %>
      + <% endif %> + +
      +
      + +
      + +
      +
      + +
      + +
      +
      + +
      +
      + +
      + + + <% if ($product): %><%- T('Delete') %><% endif %> +
      + +<%- admin_footer() %> + +
      + + + + + + + + \ No newline at end of file diff --git a/admin/templates/version_edit.html b/admin/templates/version_edit.html new file mode 100644 index 0000000..49aca9f --- /dev/null +++ b/admin/templates/version_edit.html @@ -0,0 +1,76 @@ +<%- $templates['doctype'] %> + + + <%- $templates['headinclude'] %> + <%- $templates['title'] %> - <%- ($version ? T('Edit Version') : T('Add New Version')) %> + + + + +<%- $templates['nav'] %> + +
      <%- ($version ? T('Edit Version') : T('Add New Version')) %>
      + +
      + +<%- admin_flash() %> + + + +<% if ($version): %><% endif %> +<% if (!$version): %><% endif %> + +
      + <%- ($version ? T('Edit Version') : T('Add New Version')) %> + +
      + + <% if (!$version): %> +
      +
      <%- $product['title'] %>
      + <% endif %> + +
      + +
      +
      + +
      + +
      +
      + +
      + +
      +
      <%- BSDecorator::yesno('obsolete', $version['obsolete']) %>
      + +
      +
      + +
      + + + <% if ($version): %><%- T('Delete') %><% endif %> +
      + +<%- admin_footer() %> + +
      + + + + + + + + \ No newline at end of file -- 2.43.5