<?
$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;
}

if($_FILES['cms_cat_file2']['name'] != ""){
//หาเอกเทนชั่นของภาพ
$bdoc_filename = stripslashes($_FILES['cms_cat_file2']['name']);
$bdoc_extension = getExtension($bdoc_filename);
//upload doc
$bnewdocname="../datacenter/banner/ibanner".$name_time.".".$bdoc_extension;
copy($_FILES['cms_cat_file2']['tmp_name'], $bnewdocname);
$cms_cat_file2 = "ibanner".$name_time.".".$bdoc_extension;
}




$sql = "INSERT INTO ann_cms_cat (cms_cat_name, cms_cat_file, cms_cat_icon)VALUES('".$cms_cat_name."','".$cms_cat_file."','".$cms_cat_file2."')";
$query = mysql_query($sql) or die($sql);
if($query){
jsalert("Category add already!");
Gotourl("index.php?option=tourcat");
}
}
elseif($subsection =="edit")
{
 $asql="SELECT * FROM ann_cms_cat WHERE idann_cms_cat='".$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"];
}


if($_FILES['cms_cat_file2']['name'] != ""){
//หาเอกเทนชั่นของภาพ
$bdoc_filename = stripslashes($_FILES['cms_cat_file2']['name']);
$bdoc_extension = getExtension($bdoc_filename);
//upload doc
$bnewdocname="../datacenter/banner/gbanner".$name_time.".".$bdoc_extension;
copy($_FILES['cms_cat_file2']['tmp_name'], $bnewdocname);
$cms_cat_file2 = "gbanner".$name_time.".".$bdoc_extension;
if($ROW["cms_cat_icon"]!=""){unlink("../datacenter/banner/".$ROW["cms_cat_icon"]);}
}
else
{
$cms_cat_file2 = $ROW["cms_cat_icon"];
}





$sql = "UPDATE ann_cms_cat SET cms_cat_name = '".$cms_cat_name."' , cms_cat_file = '".$cms_cat_file."', cms_cat_icon = '".$cms_cat_file2."'  WHERE idann_cms_cat = '".$itemid."'";
$query = mysql_query($sql) or die($sql);
if($query){
jsalert("Category edit already!");
Gotourl("index.php?option=tourcat");
}
}
elseif($subsection =="del")
{
$sql = "DELETE FROM ann_cms_cat WHERE idann_cms_cat = '".$itemid."'";
$query = mysql_query($sql) or die($sql);
if($query){
jsalert("Category delete already!");
Gotourl("index.php?option=tourcat");
}
}
?>