<?
/*VAR*/

if(isset($_POST["subsection"]))
{
$subsection		= $_POST["subsection"];
}
else
{
$subsection		= $_GET["subsection"];
}
if(isset($_POST["itemid"]))
{
$itemid		    = base64_decode($_POST["itemid"]);
}
else
{
$itemid		    = base64_decode($_GET["itemid"]);
}

$cmsdisplay         = $_POST["cmsdisplay"];
$clearstatus	    = $_POST["clearstatus"];
/**/
$cms_cat_id			= $_POST["cms_cat_id"];
$cms_subj_id		= $_POST["cms_subj_id"];
$cms_name			= $_POST["cms_name"];
$cms_title			= $_POST["cms_title"];
$cms_title_eng		= $_POST["cms_title_eng"];
$cms_content		= $_POST["cms_content"];
$cms_content_eng	= $_POST["cms_content_eng"];
$name_time          = time() ;

$sql="SELECT * FROM ann_cms_tour WHERE cms_id='".$itemid."'";
$result=mysql_query($sql) or die ($sql);
$ROW=mysql_fetch_array($result);
if($subsection=="addcms")
{
if($_FILES['cms_banner']['name'] != ""){
//หาเอกเทนชั่นของภาพ
$bdoc_filename = stripslashes($_FILES['cms_banner']['name']);
$bdoc_extension = getExtension($bdoc_filename);
//upload doc
$bnewdocname="../datacenter/doc/doc". $name_time.".".$bdoc_extension;
copy($_FILES['cms_banner']['tmp_name'], $bnewdocname);
$cms_banner = "doc".$name_time.".".$bdoc_extension;
}
if($_FILES['cms_banner_eng']['name'] != ""){
//หาเอกเทนชั่นของภาพ
$bdoc_filename = stripslashes($_FILES['cms_banner_eng']['name']);
$bdoc_extension = getExtension($bdoc_filename);
//upload doc
$bnewdocname="../datacenter/banner/banner_eng". $name_time.".".$bdoc_extension;
copy($_FILES['cms_banner_eng']['tmp_name'], $bnewdocname);
$cms_banner_eng = "banner_eng".$name_time.".".$bdoc_extension;
}
$sqladd="INSERT INTO ann_cms_tour (cms_cat_id, cms_subj_id,
cms_name, cms_title, cms_title_eng,
cms_banner, cms_banner_eng, cms_content,
cms_content_eng, cms_sug, cms_display, cms_url)
VALUES ('".$cms_cat_id."','".$cms_subj_id."','".$cms_name."', '".$cms_title."', '".$cms_title_eng."', '".$cms_banner."', '".$cms_banner_eng."', '".$cms_content."', '".$cms_content_eng."', 'N', '".$cms_display."', '".$cms_url."')";
mysql_query($sqladd) or die ($sqladd);
jsalert("การเิ่พิ่มสินค้าสำเร็จ");
GoToURL("index.php?option=product");
}
if($subsection=="delcms")
{
$sqladd="DELETE FROM ann_cms_tour WHERE cms_id='".$itemid."'";
mysql_query($sqladd) or die ($sqladd);
jsalert("การลบสินค้าสำเร็จ");
GoToURL("index.php?option=product");
}
if($subsection=="chstatus")
{
if($ROW["cms_sug"]=="Y"){$difst="N";}elseif($ROW["cms_sug"]=="N"){$difst="Y";}else{$difst="N";}
$sqladd="UPDATE ann_cms_tour SET cms_sug = '".$difst."' WHERE cms_id='".$itemid."'";
mysql_query($sqladd) or die ($sqladd);
jsalert("เปลี่ยนสถานะทัวร์แนะนำสำเร็จ");
GoToURL("index.php?option=product");
}




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



if($_FILES['cms_banner_eng']['name'] != ""){
//หาเอกเทนชั่นของภาพ
$bdoc_filename = stripslashes($_FILES['cms_banner_eng']['name']);
$bdoc_extension = getExtension($bdoc_filename);
//upload doc
$bnewdocname="../datacenter/banner/banner_eng". $name_time.".".$bdoc_extension;
copy($_FILES['cms_banner_eng']['tmp_name'], $bnewdocname);
$cms_banner_eng = "banner_eng".$name_time.".".$bdoc_extension;
if($ROW["cms_banner_eng"] != "")
	{
unlink("../datacenter/banner/".$ROW["cms_banner_eng"]);
	}
}
else
{
$cms_banner_eng = $ROW["cms_banner_eng"];
}
$sqlupd = "update ann_cms_tour set cms_title = '$cms_title', cms_title_eng = '$cms_title_eng', cms_content = '$cms_content', cms_content_eng = '$cms_content_eng', cms_banner = '$cms_banner', cms_banner_eng = '$cms_banner_eng' , cms_cat_id = '$cms_cat_id', cms_subj_id = '$cms_subj_id', cms_name = '$cms_name' WHERE cms_id ='$itemid'";
mysql_query($sqlupd) or die ($sqlupd);
jsalert("การอัพเดทสินค้า์สำเร็จ");
GoToURL("index.php?option=product&action=editcms&itemid=$itemid");
}

?>