📄 editproduct.php
字号:
<?php
/**************************************************
editproduct.php
Version : 1.2
Author : Tracemouse (tracemouse@msn.com)
Copyright:
Writed : 2003/08/09
Modified : 2004/04/13
***************************************************/
require "./include/base.php";
require "./include/catalog.php";
//if(!$isadmin) showmessage('low_value');
if (!$editsubmit) //未发送表单
{
if($action == 'new')
{
if(!checkallow($_login_user,'allownewprd'))
showmessage('low_value');
$ourprice=$marketprice='0.00';
$query = $db->query("SELECT paraid,paraname FROM $table_parameters ORDER BY paraid");
$para_select = "<select size=1 name=paraid>";
$isselected='';
$paraid=0;
while($dbq_rec = $db->fetch_array($query))
{
$isselected = ($dbq_rec['paraid'] == $paraid)?"selected":"";
$para_select = $para_select."<option ".$isselected." value=".$dbq_rec['paraid'].">".$dbq_rec['paraname']."</option>";
}
$para_select = $para_select."</select>";
$sortid=0;
$sort_select = getsortselect($sortid,1);
}
elseif($action == 'edit')
{
if(!checkallow($_login_user,'alloweditprd'))
showmessage('low_value');
$productid=intval($productid);
$query = $db->query("SELECT * FROM $table_products WHERE productid=$productid ");
if($dbq_rec = $db->fetch_array($query))
{
$productname = $dbq_rec['productname']; $sortid = $dbq_rec['sortid']; $postdate = $dbq_rec['postdate'];
$unit = $dbq_rec['unit'];
$ourprice = $dbq_rec['ourprice']; $marketprice = $dbq_rec['marketprice']; $finalprice=$dbq_rec['finalprice'];
$smallimg=$dbq_rec['smallimg'];$largeimg=$dbq_rec['largeimg'];$subject=$dbq_rec['subject'];
$notes=$dbq_rec['notes'];
$paraid=$dbq_rec['paraid'];
$producticons=$dbq_rec['icons'];
}
$query = $db->query("SELECT paraid,paraname FROM $table_parameters");
$para_select = "<select size=1 name=paraid>";
$isselected='';
while($dbq_rec = $db->fetch_array($query))
{
$isselected = ($dbq_rec['paraid'] == $paraid)?"selected":"";
$para_select = $para_select."<option ".$isselected." value=".$dbq_rec['paraid'].">".$dbq_rec['paraname']."</option>";
}
$para_select = $para_select."</select>";
$sort_select = getsortselect($sortid);
}
elseif($action == 'delete')
{
if(!checkallow($_login_user,'alloweditprd'))
showmessage('low_value');
$query=$db->query("SELECT * FROM $table_products WHERE productid=$productid");
if ($dbq_rec = $db->fetch_array($query))
{
if (!empty($dbq_rec['smallimg']))
{
$simg=$shop_root.$dbq_rec['smallimg'];
if (file_exists($simg)) unlink($simg);
unset($simg);
}
if (!empty($dbq_rec['largeimg']))
{
$limg=$shop_root.$dbq_rec['largeimg'];
if (file_exists($limg)) unlink($limg);
unset($limg);unset($dbq_rec);
}
}
$productid=intval($productid);
$sqlstr="delete from $table_products where productid=$productid";
$query=@$db->query($sqlstr);
$sqlstr="delete from $table_paravals where productid=$productid";
$query=@$db->query($sqlstr);
showmessage('delsuccess','productdisplay.php?sortid='.$sortid);
}
}
elseif ($editsubmit) //发送表单处理
{
if($action == 'new')
{
if(!checkallow($_login_user,'allownewprd'))
showmessage('low_value');
if(empty($productname))
showmessage('alt_null_productname');
if(empty($productname))
showmessage('alt_null_unit');
if(($ourprice <= 0)||($marketprice <= 0))
showmessage('alt_err_price');
$sel_sortid=intval($sel_sortid);$ourprice=intval($ourprice);$market=intval($marketprice);
$paraid=intval($paraid);
$productname=daddslashes($productname);$smallimg=daddslashes($smallimg);
$largeimg=daddslashes($largeimg);$post=daddslashes($post);$icons=daddslashes($icons);
$sqlstr="insert into $table_products(productname,sortid,posttime,ourprice,marketprice,".
"smallimg,largeimg,notes,paraid,poster,editer,edittime,icons) ".
"values('$productname',$sel_sortid,$timestamp,$ourprice,".
"$marketprice,'$smallimg','$largeimg','$post',$paraid,'$_login_user',$timestamp,'$_login_user','$icons')";
if(!($query=$db->query($sqlstr)))
showmessage($language['db_err']."<br>".$sqlstr);
$productid=$db->insert_id();
if ($paraid > 1)
showmessage('product add success','./editpara.php?productid='.$productid);
else
showmessage('product add success','viewproduct.php?productid='.$productid);
}
elseif($action == 'edit')
{
if(!checkallow($_login_user,'allownewprd'))
showmessage('low_value');
if(empty($productname))
showmessage('alt_null_productname');
if(empty($productname))
showmessage('alt_null_unit');
if(($ourprice <= 0)||($marketprice <= 0))
showmessage('alt_err_price');
$sel_sortid=intval($sel_sortid);$ourprice=intval($ourprice);$market=intval($marketprice);
$paraid=intval($paraid);
$productname=daddslashes($productname);$smallimg=daddslashes($smallimg);
$largeimg=daddslashes($largeimg);$post=daddslashes($post);$icons=daddslashes($icons);
$sqlstr="update $table_products SET productname='$productname',sortid=$sel_sortid,
unit='$unit',ourprice=$ourprice,marketprice=$marketprice,
smallimg='$smallimg',largeimg='$largeimg',notes='$Post',paraid=$paraid,
edittime=$timestamp,editer='$_login_user',icons='$icons'
where productid = $productid";
if(!($query=$db->query($sqlstr,1)))
showmessage($language['db_err'].":<br>".$sqlstr);
if(($oldparaid != $paraid)&&($oldparaid > 1))
{
$sqlstr = "DELETE FROM $table_paravals WHERE productid=$productid AND paraid = $oldparaid";
if(!($query = $db->query($sqlstr)))
showmessage($language['db_err'].":<br>".$sqlstr);
}
if ($paraid > 1)
showmessage('product add success','./editpara.php?productid='.$productid);
else
showmessage('product add success','viewproduct.php?productid='.$productid);
}
}
$query=$db->query("select * from $table_icons order by id");
$iconslist=array();
while($dbq_rec=$db->fetch_array($query))
{
$dbq_rec['ischecked']=($producticons == $dbq_rec['url'])?"checked":"";
$iconslist[]=$dbq_rec;
}
unset($query);unset($dbq_rec);
if($action == 'new')
{
$nav .= SEPARATER.$language['newproduct'];
$noiconschecked="checked";
}
elseif($action == 'edit')
{
$nav .= SEPARATER."<a href='viewproduct.php?productid=".$productid."'>".$productname."</a>".SEPARATER.$language['editproduct'];
$noiconschecked=(empty($producticon))?"checked":"";
}
include template('editproduct');
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -