<?php
include("CheckSession.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="馬戲團" />
<title>馬戲團</title>
</head>
<?php
require_once("class/DBConfig.php");
require_once("class/DBOperation.php");
require_once("class/MacOperation.php");

$actionOp = $_POST["actionOp"];
$id = $_POST["id"];

$CCId = $_POST['CCId'];
$CNickname = $_POST['CNickname'];
$CMiss = $_POST['CMiss'];
$CMissDate = $_POST['CMissDate'];
$CUser = $_SESSION['userId'];

$db = new DBOperation();
$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
				
if($actionOp == "Insert")
{
	$insertSql = "INSERT INTO CMissContent (CCId, CMiss,CPayDate,CCreateDateTime,CUpdateDateTime,CCreateAcc)"
	              ."VALUES ('".$db->mysql_real_escape_string($CCId)."'"
	              .",'".$db->mysql_real_escape_string($CMiss)."'"
	              .",'".$db->mysql_real_escape_string($CMissDate)."'"
	              .",'".Date('Y-m-d H:i:s')."'"
	              .",'".Date('Y-m-d H:i:s')."'"
	              .",'".$db->mysql_real_escape_string($CUser)."')";
	$db->query($insertSql);
	
	//更新次數
  $updateSql = "UPDATE Customer set ConTimes = ConTimes + 1 where CId = '".$db->mysql_real_escape_string($CCId)."'";
  $db->query($updateSql);
  $db->close_db();
  
  $url = "CMissContentIndex.php?CCId=".$CCId."&CNickname=".$CNickname;
  
	echo '<script type="text/javascript">';
  echo 'alert("新增成功!!!!");';
  echo 'self.location.href= "'.$url.'";';
  echo '</script>';
}
else
{
	$updateSql = "UPDATE CMissContent set CMiss = '".$db->mysql_real_escape_string($CMiss)."'"
	             .",CPayDate = '".$db->mysql_real_escape_string($CMissDate)."'"
	             .",CUpdateDateTime = '".Date('Y-m-d H:i:s')."'";
	$updateSql = $updateSql." where CId = ".$id;
	$db->query($updateSql);
  $db->close_db();  
  $url = "CMissContentIndex.php?CCId=".$CCId."&CNickname=".$CNickname;  
	echo '<script type="text/javascript">';
  echo 'alert("更新成功!!!!");';
  echo 'self.location.href= "'.$url.'";';
  echo '</script>';
}
?>
</html>
