* $sql = sprintf("DELETE FROM categories WHERE id = %d", $catid); * $res = $pdb->query($sql); */ $msg = "The selected category was totally removed."; // send back to self with messageness header("Location: {$_SERVER['PHP_SELF']}?info=" . base64_encode($msg)); } if ($SHOWFORM) { $fex = new formex('POST'); $fex->js_src_inline = true; $fex->add_element($colmap); // all those things in $colmap are in the form now $fex->set_element_opts('ship_class_id', $shipTypes); $fex->add_element('op', array($ACTION, 'submit')); // the button $fex->set_element_opts('parent_cat_id', cshopUtils::get_all_parent_categories($pdb)); if ($ACTION == OP_EDIT) { $sql = sprintf("SELECT name, descrip, ship_class_id, is_taxable, level, feature_rank, is_active, parent_cat_id , order_weight\n , m.filename AS icon_media_id\n FROM cm_categories c LEFT JOIN cm_media_files m ON (m.id = c.icon_media_id)\n WHERE c.id = %d", $catid); $fex->elem_vals = $pdb->getRow($sql); $fex->add_element('id', array('hid id', 'hidden', $catid, null)); // important $cat_name = $fex->elem_vals['name']; /** if there are zero products in this category, let them delete it **/ $sql = sprintf("SELECT COUNT(*) FROM cm_products_categories WHERE cm_categories_id = %d", $catid); $product_count = $pdb->getOne($sql); if ($product_count) { $confirm_msg = "There are {$product_count} products that are in this category. If you delete the category, they may be hidden from customers. Are you sure?"; } else { $confirm_msg = 'This will remove this category from the site permanently. Are you sure?'; } $fex->add_element('op_kill', array(OP_KILL, 'submit', null, null, 'onclick="return confirm(\'' . $confirm_msg . '\')"'));