<?php
include("../connect.php");
include("../session.php");
date_default_timezone_set ("Singapore"); 



////////////////////////////////////////////////////////////////////////
$user=$_GET["user"];
$promotionid=$_POST["promotionId"];
$productid=$_POST["productId"];
$productname=$_POST["promotionName"];
$normalprice=$_POST["normalPrice"];
$promotionprice=$_POST["promotionprice"];
$startdate=$_POST["startdate"];
$enddate=$_POST["enddate"];
$pcondition=$_POST["pcondition"];
/////////////////////////////////////////////////////////////////////////
$date=date("d-m-Y", time());
$time=date("h:i:sa", time());



/////////////////////////////////////////////////////////////////////////////////
$checkquery = mysql_query("SELECT * FROM promotion where pID='$productid'"); 

if(mysql_num_rows($checkquery)==0){
	
	mysql_query("INSERT INTO promotion(pmtID,pID,pname,startdate,enddate,normalprice,promotionprice,pcondition)VALUES ('$promotionid','$productid','$productname','$startdate','$enddate','$normalprice','$promotionprice','$pcondition')");
	
	echo "<script language=javascript>alert('Insert Complete');window.location='viewproduct.php?user=$user';</script>";
}
else{
	
	
	mysql_query("UPDATE promotion SET startdate='$startdate', enddate='$enddate', promotionprice='$promotionprice', pcondition='$pcondition' WHERE pID='$productid'");
	
	echo "<script language=javascript>alert('Update Complete');window.location='viewproduct.php?user=$user';</script>";
}


	

die();
	
include("../closeconnection.php");	

?>