<?
require("config.inc");

$adminID = $_SESSION['AdminID'];
$adminID2 = $_GET['adminID'];
$noticeID1 = $_GET['noticeID'];
$content1 = $_POST['content'];
$action = $_POST['value'];
//echo "<script>alert('".$action."');</script>";
if($action == 'POST'){
$result = mysql_query("update tbl_notice SET content='$content1' where noticeID='$noticeID1'");
//$row = mysql_fetch_array($result);
date_default_timezone_set('Etc/GMT-8');
$timeNow = date('h:i:s a', time());

if($result-->0){
echo "<script>alert('Update Success');</script>";
echo "<script>window.location='intro.php?adminID=".$adminID."';</script>";
}
else{echo "<script>alert('Failed to update');</script>";
echo "<script>window.location='intro.php?adminID=".$adminID."';</script>";}
}
else if($action == 'DELETE'){
$dateToday = date('d-m-Y');
date_default_timezone_set('Etc/GMT-8');
$timeNow = date('h:i:s a', time());
$getContent = mysql_query("Select * from tbl_notice where noticeID='$noticeID1'");
$getRow = mysql_fetch_array($getContent);
$contentH = $getRow['content'];
$result = mysql_query("update tbl_notice SET content='' where noticeID='$noticeID1'");
//$row = mysql_fetch_array($result);
if($result-->0){
$result1 = mysql_query("insert into noticehistory (userID, date, time, content) value ('$adminID2', '$dateToday', '$timeNow', '$contentH')");
echo "<script>alert('Delete Success');</script>";
echo "<script>window.location='intro.php?adminID=".$adminID."';</script>";
}
else{echo "<script>alert('Failed to delete');</script>";
echo "<script>window.location='intro.php?adminID=".$adminID."';</script>";}
}
?>