⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 categories.php

📁 完善的PHP/MySQL电子商务方案
💻 PHP
字号:
<?/* categories.php (c) 2000 Ying Zhang (ying@zippydesign.com) * * TERMS OF USAGE: * This file was written and developed by Ying Zhang (ying@zippydesign.com) * for educational and demonstration purposes only.  You are hereby granted the * rights to use, modify, and redistribute this file as you like.  The only * requirement is that you must retain this notice, without modifications, at * the top of your source code.  No warranties or guarantees are expressed or * implied. DO NOT use this code in a production environment without * understanding the limitations and weaknesses pretaining to or caused by the * use of these scripts, directly or indirectly. USE AT YOUR OWN RISK! *//****************************************************************************** * MAIN *****************************************************************************/include("../application.php");require_login();require_priv("admin");$DOC_TITLE = "MyMarket Category Management";include("templates/header.php");switch (nvl($mode)) {	case "add" :		print_add_category_form(nvl($id, 0));		break;	case "edit" :		print_edit_category_form($id);		break;	case "del" :		delete_category($id);		print_category_list();		break;	case "insert" :		insert_subcategory($id, $HTTP_POST_VARS);		print_category_list();		break;	case "update" :		update_category($id, $HTTP_POST_VARS);		print_category_list();		break;	default :		print_category_list();		break;}include("templates/footer.php");/****************************************************************************** * FUNCTIONS *****************************************************************************/function print_add_category_form($id) {/* print a blank category form so we can add a new category */	global $CFG, $ME;	/* set default values for the reset of the fields */	$frm["parent"] = array($id);	$frm["newmode"] = "insert";	$frm["name"] = "";	$frm["description"] = "";	$frm["submit_caption"] = "Add Subcategory";	/* build the categories listbox options, preselect the selected item */	build_category_tree($category_options, $frm["parent"]);	include("templates/category_form.php");}function print_edit_category_form($id) {/* print a category form so we can add a edit the selected category */	global $CFG, $ME;	/* load up the information for the category */	$qid = db_query("	SELECT name, description, parent_id	FROM categories	WHERE id = $id	");	$frm = db_fetch_array($qid);	/* set values for the form */	$frm["parent"] = array($frm["parent_id"]);	$frm["newmode"] = "update";	$frm["submit_caption"] = "Save Changes";	/* build the categories listbox options, preselect the selected item */	build_category_tree($category_options, $frm["parent"]);	include("templates/category_form.php");}function delete_category($id) {/* delete the category specified by $id, and move all the products under * that category to the immediate parent.  this should be wrapped inside a * transaction, unfortunately MySQL currently does not support transactions. */	global $CFG, $ME;	/* find the parent of this category */	$qid = db_query("	SELECT cat.name, cat.parent_id, parent.name AS parent	FROM categories cat, categories parent	WHERE parent.id = cat.parent_id		AND cat.id = $id	");	$cat = db_fetch_object($qid);	/* delete this category */	$qid = db_query("	DELETE FROM categories	WHERE id = $id	");	/* re-assign all the products in this category to the parent category */	$qid = db_query("	UPDATE products_categories	SET category_id = $cat->parent_id	WHERE category_id = $id	");	/* re-assign all sub categories of this category to the parent category */	$qid = db_query("	UPDATE categories	SET parent_id = $cat->parent_id	WHERE parent_id = $id	");	include("templates/category_deleted.php");}function insert_subcategory($id, $frm) {/* add a new subcategory under the parent $id.  all the fields that we want are * going to in the variable $frm */	global $CFG, $ME;	$qid = db_query("	INSERT INTO categories (parent_id, name, description)	VALUES ($frm[parent], '$frm[name]', '$frm[description]')	");}function update_category($id, $frm) {/* update the category $id with new values.  all the fields that we want are * going to in the variable $frm */	global $CFG, $ME;	$qid = db_query("	UPDATE categories SET		 parent_id = '$frm[parent]'		,name = '$frm[name]'		,description = '$frm[description]'	WHERE id = $id	");}function print_category_list() {/* read all the categories from the database and print them into a table.  we * will use a template to display the listings to keep this main script clean */	global $CFG, $ME;	$qid = db_query("	SELECT cat.id, cat.name, cat.description, parent.name AS parent	FROM categories cat, categories parent	WHERE parent.id = cat.parent_id		AND cat.id > 0	");	include("templates/category_list.php");}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -