' . sprintf(T('Edit %1$s'), $type_display) . ''; } 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') { $input->inputClean('versionid', TYPE_UINT); $db->query("DELETE FROM " . TABLE_PREFIX . "version WHERE versionid = " . $input->in['versionid']); $db->query("DELETE FROM " . TABLE_PREFIX . "bug WHERE version = " . $input->in['versionid']); build_versions(); $admin->redirect('product.php?do=modify'); } // ################################################################### if ($_REQUEST['do'] == 'deleteversion') { $admin->page_confirm(T('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' => $input->inputClean('versionid', TYPE_UINT))); } // ################################################################### if ($_REQUEST['do'] == 'insertversion') { $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') { $product = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $input->inputClean('productid', TYPE_UINT)); if (!$product) { $admin->error(L_INVALID_ID); } $tpl = new BSTemplate('version_edit'); $tpl->vars['product'] = $product; $tpl->evaluate()->flush(); } // ################################################################### if ($_REQUEST['do'] == 'updateversion') { if (empty($input->in['version'])) { $admin->error(T('Please fill in a version number.')); } $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') { $tpl = new BSTemplate('version_edit'); $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); } $tpl->evaluate()->flush(); } // ################################################################### if ($_REQUEST['do'] == 'killproduct') { $input->inputClean('productid', TYPE_UINT); $allprods = $db->query("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = " . $input->in['productid'] . " OR parentid = " . $input->in['productid']); foreach ($allprods as $prod) { $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(T('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' => $input->inputClean('productid', TYPE_UINT))); } // ################################################################### if ($_REQUEST['do'] == 'insertproduct') { if (empty($input->in['title'])) { $admin->error(T('Please go back and fill in the title field.')); } $db->query(" INSERT INTO " . TABLE_PREFIX . "product (title, parentid, description, displayorder) VALUES ('" . $input->inputEscape('title') . "', " . $input->inputClean('parentid', TYPE_UINT) . ", '" . $input->inputEscape('description') . "', " . $input->inputClean('displayorder', TYPE_UINT) . " )" ); build_products(); $admin->redirect('product.php?do=modify'); } // ################################################################### if ($_REQUEST['do'] == 'addproduct') { $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(); } // ################################################################### if ($_REQUEST['do'] == 'updateproduct') { if (empty($input->in['title'])) { $admin->error(T('Please go back and fill in the title field.')); } if (empty($input->in['productid'])) { $admin->error(L_INVALID_ID); } $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') { $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); } $tpl->vars['parent'] = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "product WHERE productid = {$tpl->vars['product']['parentid']}"); $tpl->evaluate()->flush(); } // ################################################################### if ($_POST['do'] == 'displayorder') { $input->inputClean('displayorder', TYPE_UINT); if (is_array($input->in['displayorder'])) { foreach ($input->in['displayorder'] as $namebit => $order) { $name = explode('_', $namebit); if ($name[0] == 'product' || $name[0] == 'version') { $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_flash_redirect('product.php?do=modify'); } // ################################################################### if ($_REQUEST['do'] == 'modify') { $tpl = new BSTemplate('product'); $products_get = $db->query("SELECT * FROM " . TABLE_PREFIX . "product ORDER BY displayorder ASC"); $tpl->vars['products'] = $tpl->vars['components'] = $tpl->vars['version'] = array(); foreach ($products_get as $prod) { if (!$prod['parentid']) { $tpl->vars['products'][$prod['productid']] = $prod; } else { $tpl->vars['components'][$prod['parentid']][] = $prod; } $tpl->vars['version'][$prod['productid']] = array(); } $versions_get = $db->query("SELECT * FROM " . TABLE_PREFIX . "version ORDER BY displayorder ASC"); foreach ($versions_get as $vers) { $tpl->vars['versions'][$vers['productid']][$vers['versionid']] = $vers; } $tpl->evaluate()->flush(); } ?>