<?
/*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_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_data 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/banner/banner". $name_time.".".$bdoc_extension;
copy($_FILES['cms_banner']['tmp_name'], $bnewdocname);
$cms_banner = "banner".$name_time.".".$bdoc_extension;
}

$sqladd = "INSERT INTO ann_cms_data(cms_name,
cms_title,cms_title_eng,cms_banner,cms_banner_eng,
cms_content,cms_content_eng,cms_display,
cms_url)VALUES ('".$cms_name."', '".$cms_title."', '".$cms_title_eng."', '".$cms_banner."', '".$cms_banner_eng."', '".$cms_content."', '".$cms_content_eng."', '".$cmsdisplay."', '".$cms_url."')";
mysql_query($sqladd) or die ($sqladd);
jsalert("การเพิ่ม DATA สำเร็จ");
GoToURL("index.php?option=bc-cms&cmsdisplay=$cmsdisplay");

}
if($subsection=="delcms")
{
$sqladd="DELETE FROM ann_cms_tour WHERE cms_id='".$itemid."'";
mysql_query($sqladd) or die ($sqladd);
jsalert("การลบ DATA สำเร็จ");
GoToURL("index.php?option=bc-cms&cmsdisplay=$cmsdisplay");
}
if($subsection=="editcms")
{
if($_FILES['cms_banner']['name'] != ""){
//หาเอกเทนชั่นของภาพ
$bdoc_filename = stripslashes($_FILES['cms_banner']['name']);
$bdoc_extension = getExtension($bdoc_filename);
//upload doc
$bnewdocname="../datacenter/banner/banner". $name_time.".".$bdoc_extension;
copy($_FILES['cms_banner']['tmp_name'], $bnewdocname);
$cms_banner = "banner".$name_time.".".$bdoc_extension;
if($ROW["cms_banner"] != "")
	{
unlink("../datacenter/banner/".$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_data set cms_name='$cms_name',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'  WHERE cms_id ='$itemid'";
$pim = mysql_query($sqlupd) or die ($sqlupd);
if($pim){
jsalert("การอัพเดท DATA  สำเร็จ");
GoToURL("index.php?option=bc-cms&action=editcms&itemid=$itemid&cmsdisplay=$cmsdisplay");
}
}

?>