<?
$itemid			= base64_decode($_REQUEST["itemid"]);
$cms_cat_name 	= $_POST["cms_cat_name"];
$subsection		= $_REQUEST["subsection"];
$name_time		= time();
if($subsection =="add")
{
	
if($_FILES['cms_cat_file']['name'] != ""){
//หาเอกเทนชั่นของภาพ
$bdoc_filename = stripslashes($_FILES['cms_cat_file']['name']);
$bdoc_extension = getExtension($bdoc_filename);
//upload doc
$bnewdocname="../datacenter/banner/pbanner".$name_time.".".$bdoc_extension;
copy($_FILES['cms_cat_file']['tmp_name'], $bnewdocname);
$cms_cat_file = "pbanner".$name_time.".".$bdoc_extension;
}


$sql = "INSERT INTO ann_cms_lfm (cms_cat_name, cms_cat_file ,cms_cat_url)VALUES('".$cms_cat_name."','".$cms_cat_file."','".$cms_cat_url."')";
$query = mysql_query($sql) or die($sql);
if($query){
jsalert("Left menu add already!");
Gotourl("index.php?option=leftmenu");
}
}
elseif($subsection =="edit")
{
 $asql="SELECT * FROM ann_cms_lfm WHERE idann_cms_lfm='".$itemid."'";
 $aresult=mysql_query($asql) or die ($asql);
 $ROW=mysql_fetch_array($aresult);

if($_FILES['cms_cat_file']['name'] != ""){
//หาเอกเทนชั่นของภาพ
$bdoc_filename = stripslashes($_FILES['cms_cat_file']['name']);
$bdoc_extension = getExtension($bdoc_filename);
//upload doc
$bnewdocname="../datacenter/banner/pbanner".$name_time.".".$bdoc_extension;
copy($_FILES['cms_cat_file']['tmp_name'], $bnewdocname);
$cms_cat_file = "pbanner".$name_time.".".$bdoc_extension;
if($ROW["cms_cat_file"]!=""){unlink("../datacenter/banner/".$ROW["cms_cat_file"]);}
}
else
{
$cms_cat_file = $ROW["cms_cat_file"];
}
$sql = "UPDATE ann_cms_lfm SET cms_cat_name = '".$cms_cat_name."' , cms_cat_file = '".$cms_cat_file."' , cms_cat_url = '".$cms_cat_url."'  WHERE idann_cms_lfm = '".$itemid."'";
$query = mysql_query($sql) or die($sql);
if($query){
jsalert("Left menu edit already!");
Gotourl("index.php?option=leftmenu");
}
}
elseif($subsection =="del")
{
$sql = "DELETE FROM ann_cms_lfm WHERE idann_cms_lfm = '".$itemid."'";
$query = mysql_query($sql) or die($sql);
if($query){
jsalert("Left menu delete already!");
Gotourl("index.php?option=leftmenu");
}
}
?>