<?php

$pro_titile			= $_POST["pro_titile"]; 	
$pro_titile_eng		= $_POST["pro_titile_eng"];
$pro_period			= $_POST["pro_period"];	
$pro_period_eng		= $_POST["pro_period_eng"];
$pro_duct			= $_POST["pro_duct"];
$pro_duct_eng		= $_POST["pro_duct_eng"];
$subsection			= $_REQUEST["subsection"];
$itemid				= base64_decode($_REQUEST["itemid"]);
$name_time			= time();

if($subsection=="add"){
if($pro_titile==""){jsalert("error"); jsback(); exit();}

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

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

$sqladd="INSERT INTO bbv_project_index(pro_titile, pro_titile_eng, pro_period,
pro_period_eng, pro_duct, pro_duct_eng, pro_banner, pro_banner_eng)
VALUES ( '".$pro_titile."', '".$pro_titile_eng."', '".$pro_period."', '".$pro_period_eng."', '".$pro_duct."', '".$pro_duct_eng."', '".$pro_banner."', '".$pro_banner_eng."')";


$iquery = mysql_query($sqladd) or die ($sqladd);
if($iquery){
jsalert("Add project already!");
GotoURL("index.php?option=project-index");
}//end add

}elseif($subsection=="edit"){

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


if($itemid==""){jsalert("error"); jsback(); exit();}

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



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




$sqledit = "UPDATE bbv_project_index SET 
pro_titile			=	'".$pro_titile."',
pro_titile_eng		=	'".$pro_titile_eng."',
pro_period			=	'".$pro_period."',
pro_period_eng		=	'".$pro_period_eng."',
pro_duct			=	'".$pro_duct."',
pro_duct_eng		=	'".$pro_duct_eng."' ,
pro_banner			=	'".$pro_banner."',
pro_banner_eng		=	'".$pro_banner_eng."'
WHERE project_index_id ='".$itemid."' LIMIT 1" ;

$iquery = mysql_query($sqledit) or die ($sqledit);
if($iquery){               
jsalert("Edit project already!");
GotoURL("index.php?option=project-index");
}
}//ENDEDIT
elseif($subsection=="del"){
if($itemid==""){jsalert("error"); jsback(); exit();}

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

unlink("../datacenter/banner/".$ROW["pro_banner_eng"]);
unlink("../datacenter/banner/".$ROW["pro_banner"]);


$sqldel = "DELETE FROM bbv_project_index WHERE project_index_id = '".$itemid."' LIMIT 1";
mysql_query($sqldel) or die ($sqldel);

jsalert("Delete already!");
GoToURL("index.php?option=project-index");
}
?>