<?
/*for allow*/
ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '10M');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);
/*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     = $_REQUEST["cmsdisplay"];
$clearstatus	= $_POST["clearstatus"];
/**/
$cms_name			= $_POST["cms_name"];
$cms_title			= $_POST["cms_title"];
$cms_title_eng		= $_POST["cms_title_eng"];
$cms_date			= strtotime($_POST["cms_date"]);
$cms_content		= $_POST["cms_content"];
$cms_content_eng	= $_POST["cms_content_eng"];
$cms_shortdes		= $_POST["cms_shortdes"];
$cms_shortdes_eng	= $_POST["cms_shortdes_eng"];
$cms_cate_id		= $_POST["cms_cate_id"];
$cms_subject_id = $_POST["project_subject_id"];
$name_time          = time() ;

$sql="SELECT * FROM sbs_cms_nev WHERE cms_id='".$itemid."'";
$result=mysql_query($sql) or die ($sql);
$ROW=mysql_fetch_array($result);

if($subsection=="del")
{
$sqldel = "DELETE FROM sbs_cms_nev WHERE cms_id = '$itemid' LIMIT 1";
mysql_query($sqldel) or die ($sqldel);
if($ROW["cms_banner"] != "")
	{
unlink("../datacenter/banner/".$ROW["cms_banner"]);
	}
if($ROW["cms_banner_eng"] != "")
	{
unlink("../datacenter/banner/".$ROW["cms_banner_eng"]);
	}
if($ROW["cms_pv"] != "")
	{
unlink("../datacenter/banner/".$ROW["cms_pv"]);
	}
jsalert("การลบ CMS สำเร็จ");
GoToURL("index.php?option=nev-cms&cmsdisplay=$cmsdisplay");
}

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


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($_FILES['cms_pv']['name'] != ""){
//หาเอกเทนชั่นของภาพ
$bdoc_filename = stripslashes($_FILES['cms_pv']['name']);
$bdoc_extension = getExtension($bdoc_filename);
//upload doc
$bnewdocname="../datacenter/banner/banner_pv". $name_time.".".$bdoc_extension;
copy($_FILES['cms_pv']['tmp_name'], $bnewdocname);
$cms_pv = "banner_pv".$name_time.".".$bdoc_extension;
}


$sqlbb="INSERT INTO sbs_cms_nev (cms_name, cms_title, cms_date
,cms_title_eng, cms_banner, cms_banner_eng, cms_pv,
cms_content, cms_content_eng, cms_display, cms_url,
cms_sort, cms_cate_id ,cms_subject_id , cms_shortdes , cms_shortdes_eng ) VALUES ('".$cms_name."', '".$cms_title."', '".$cms_date."','".$cms_title_eng."', '".$cms_banner."', '".$cms_banner_eng."', '".$cms_pv."' , '".$cms_content."', '".$cms_content_eng."', '".$cmsdisplay."','','', '".$cms_cate_id."','".$cms_subject_id."','".$cms_shortdes."' , '".$cms_shortdes_eng."')";

mysql_query($sqlbb) or die ($sqlbb);
jsalert("การเพิ่ม CMS สำเร็จ");
GoToURL("index.php?option=nev-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"];
}

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


$sqlupd = "update sbs_cms_nev set cms_title = '$cms_title', cms_title_eng = '$cms_title_eng', cms_content = '$cms_content', cms_content_eng = '$cms_content_eng',cms_date = '$cms_date', 	cms_display ='$cmsdisplay', cms_banner = '$cms_banner', cms_banner_eng = '$cms_banner_eng' ,cms_pv = '$cms_pv',  cms_cate_id ='$cms_cate_id' , cms_subject_id ='$cms_subject_id',cms_shortdes = '$cms_shortdes', cms_shortdes_eng =  '$cms_shortdes_eng'   WHERE cms_id ='$itemid'";
mysql_query($sqlupd) or die ($sqlupd);
jsalert("การอัพเดท CMS สำเร็จ");
GoToURL("index.php?option=nev-cms&action=editcms&itemid=$itemid&cmsdisplay=$cmsdisplay");
}
if($subsection=="status")
{
if($ROW["cms_status"]=="Y"){$alterrow="N";}elseif($ROW["cms_status"]=="N"){$alterrow="Y";}elseif($ROW["cms_status"]==""){$alterrow="Y";}
$update = "UPDATE sbs_cms_nev SET cms_status='".$alterrow."' WHERE cms_id='".$itemid."'";
mysql_query($update);
jsalert("เปลี่ยนสถานะ CMS สำเร็จ");
GoToURL("index.php?option=nev-cms&cmsdisplay=$cmsdisplay");
}

if($subsection=="trimstatus")
{
if($ROW["cms_trim_status"]=="Y"){$alterrow="N";}elseif($ROW["cms_trim_status"]=="N"){$alterrow="Y";}elseif($ROW["cms_trim_status"]==""){$alterrow="Y";}
$update = "UPDATE sbs_cms_nev SET cms_trim_status='".$alterrow."' WHERE cms_id='".$itemid."'";
mysql_query($update);
jsalert("เปลี่ยนสถานะเนื้อหาเด่น CMS สำเร็จ");
GoToURL("index.php?option=nev-cms&cmsdisplay=$cmsdisplay");
}

?>