【php开源代码栏目提醒】:网学会员鉴于大家对php开源代码十分关注,论文会员在此为大家搜集整理了“BookMaint.php”一文,供大家参考学习
<?php
/*********************************************************************************
* Filename: BookMaint.php
* Generated with CodeCharge 1.1.19
* PHP & Templates build 03/28/2001
*********************************************************************************/
include ("./common.php");
include ("./Header.php");
include ("./Footer.php");
session_start();
$filename = "BookMaint.php";
check_security(2);
$tpl = new Template($app_path);
$tpl->load_file("BookMaint.html", "main");
$tpl->load_file($header_filename, "Header");
$tpl->load_file($footer_filename, "Footer");
$tpl->set_var("FileName", $filename);
$sBookErr = "";
$sAction = get_param("FormAction");
$sForm = get_param("FormName");
switch ($sForm) {
case "Book":
Book_action($sAction);
break;
}Menu_show();
Footer_show();
Book_show();
$tpl->parse("Header", false);
$tpl->parse("Footer", false);
$tpl->pparse("main", false);
//********************************************************************************
function Book_action($sAction)
{
global $db;
global $tpl;
global $sForm;
global $sBookErr;
$sParams = "";
$sActionFileName = "AdminBooks.php";
$sParams = "?";
$sParams .= "category_id=" . tourl(get_param("Trn_category_id")) . "&";
$sParams .= "is_recommended=" . tourl(get_param("Trn_is_recommended"));
$sWhere = "";
$bErr = false;
if($sAction == "cancel")
header("Location: " . $sActionFileName . $sParams);
// Create WHERE statement
if($sAction == "update" || $sAction == "delete")
{
$pPKitem_id = get_param("PK_item_id");
if( !strlen($pPKitem_id)) return;
$sWhere = "item_id=" . tosql($pPKitem_id, "Number");
}
// Load all form fields into variables
$fldname = get_param("name");
$fldauthor = get_param("author");
$fldcategory_id = get_param("category_id");
$fldprice = get_param("price");
$fldproduct_url = get_param("product_url");
$fldimage_url = get_param("image_url");
$fldnotes = get_param("notes");
$fldis_rec = get_checkbox_value(get_param("is_rec"), "1", "0", "Number");
// Validate fields
if($sAction == "insert" || $sAction == "update")
{
if(!strlen($fldname))
$sBookErr .= "The value in field Title is required.<br>";
if(!strlen($fldcategory_id))
$sBookErr .= "The value in field Category is required.<br>";
if(!strlen($fldprice))
$sBookErr .= "The value in field Price is required.<br>";
if(!is_number($fldcategory_id))
$sBookErr .= "The value in field Category is incorrect.<br>";
if(!is_number($fldprice))
$sBookErr .= "The value in field Price is incorrect.<br>";
if(strlen($sBookErr)) return;
}
$sSQL = "";
// Create SQL statement
switch(strtolower($sAction))
{
case "insert":
$sSQL = "insert into items (" .
"name," .
"author," .
"category_id," .
"price," .
"product_url," .
"image_url," .
"notes," .
"is_recommended)" .
" values (" .
tosql($fldname, "Text") . "," .
tosql($fldauthor, "Text") . "," .
tosql($fldcategory_id, "Number") . "," .
tosql($fldprice, "Number") . "," .
tosql($fldproduct_url, "Text") . "," .
tosql($fldimage_url, "Text") . "," .
tosql($fldnotes, "Text") . "," .
$fldis_rec . ")";
break;
case "update":
$sSQL = "update items set " .
"name=" . tosql($fldname, "Text") .
",author=" . tosql($fldauthor, "Text") .
",category_id=" . tosql($fldcategory_id, "Number") .
",price=" . tosql($fldprice, "Number") .
",product_url=" . tosql($fldproduct_url, "Text") .
",image_url=" . tosql($fldimage_url, "Text") .
",notes=" . tosql($fldnotes, "Text") .
",is_recommended=" . $fldis_rec;
$sSQL .= " where " . $sWhere;
break;
case "delete":
$sSQL = "delete from items where " . $sWhere;
break;
}
// Execute SQL statement
if(strlen($sBookErr)) return;
$db