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


$sql = "INSERT INTO ann_cms_subj (cms_subj_name,cms_cat_id,  cms_subj_file)VALUES('".$cms_subj_name."','".$cms_cat_id."','".$cms_subj_file."')";
$query = mysql_query($sql) or die($sql);
if($query){
jsalert("Subject add already!");
Gotourl("index.php?option=toursubj");
}
}
elseif($subsection =="edit")
{
 $asql="SELECT * FROM ann_cms_subj WHERE idann_cms_subj='".$itemid."'";
 $aresult=mysql_query($asql) or die ($asql);
 $ROW=mysql_fetch_array($aresult);

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