<?
$itemid			= $_GET["itemid"];
$subsection		= $_GET["subsection"];
$clearstatus	= $_GET["clearstatus"];
if($itemid = "")
{
jsalert("Unknow Action");
exit();
}

$itemid = base64_decode($_GET["itemid"]);
//qurie data form DB for del vid and vidpv

if($subsection=="del")
{
$sql="SELECT * FROM ann_gall WHERE mag_id='$itemid'";
$result=mysql_query($sql) or die ( $sql);
$ROW=mysql_fetch_array($result);



// ลบไฟล์ภาพที่เกี่ยวข้อง
if($ROW["mag_thumb"] != ""){
unlink("../datacenter/upload/".$ROW["mag_thumb"]);
}
 $subcorsql="select  * from  ann_gall_page where page_mag_id = '".$itemid."'";
					 $subcorquery =mysql_query($subcorsql) or die ($subcorsql);
					 while($subcorrow = mysql_fetch_array($subcorquery)) {
unlink("../datacenter/upload/".$subcorrow["page_images"]);						
}
// del data form sql

$sqldel = "DELETE FROM ann_gall WHERE ann_gall.mag_id = '$itemid' LIMIT 1";
mysql_query($sqldel) or die ($sqldel);
$sqldel2 = "DELETE FROM ann_gall_page WHERE 	page_mag_id = '$itemid' LIMIT 1";
mysql_query($sqldel2) or die ($sqldel2);

jsalert("การลบแกลลอรี่สำเร็จ");
GoToURL("index.php?option=galllist");
}

if($subsection=="status")
{
	if($clearstatus =="N"){$newstatus = "Y";} else {$newstatus = "N";}
	
$sqlst="update ann_gall set mag_status = '$newstatus' WHERE mag_id ='$itemid'";

mysql_query($sqlst) or die ($sqlst);
jsalert("การเปลี่ยนสถานะแกลลอรี่สำเร็จ");
GoToURL("index.php?option=galllist");

}
if($subsection=="delpage")
{

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

jsalert("การลบภาพสำเร็จ");
GoToURL("index.php?option=galllist&action=editgalltail&itemid=".$_GET["mag_als"]);

}
?> 