<?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
date_default_timezone_set('Asia/Taipei');

require_once("class/DBConfig.php");
require_once("class/DBOperation.php");

$action = $_POST["action"];

$id = $_POST["id"];
$GroupName = $_POST["GroupName"];
$RightA1 = $_POST["chkA1"];
$RightA2 = $_POST["chkA2"];
$RightA3 = $_POST["chkA3"];
//$RightA4 = $_POST["chkA4"];
$RightB1I = $_POST["chkB1I"];
$RightB1U = $_POST["chkB1U"];
$RightB1D = $_POST["chkB1D"];
$RightB2 = $_POST["chkB2"];
$RightB3 = $_POST["chkB3"];
$RightC1I = $_POST["chkC1I"];
$RightC1U = $_POST["chkC1U"];
$RightC1D = $_POST["chkC1D"];
$RightC1Q = $_POST["chkC1Q"];

$Rights = "";
if($RightA1 != null && $RightA1 != "")
{
	if($Rights == "")
	{
		$Rights = $RightA1;
	}
	else
	{
		$Rights = $Rights.",".$RightA1;
	}
}
if($RightA2 != null && $RightA2 != "")
{
	if($Rights == "")
	{
		$Rights = $RightA2;
	}
	else
	{
		$Rights = $Rights.",".$RightA2;
	}
}
if($RightA3 != null && $RightA3 != "")
{
	if($Rights == "")
	{
		$Rights = $RightA3;
	}
	else
	{
		$Rights = $Rights.",".$RightA3;
	}
}
//if($RightA4 != null && $RightA4 != "")
//{
//	if($Rights == "")
//	{
//		$Rights = $RightA4;
//	}
//	else
//	{
//		$Rights = $Rights.",".$RightA4;
//	}
//}

if($RightB1I != null && $RightB1I != "")
{
	if($Rights == "")
	{
		$Rights = $RightB1I;
	}
	else
	{
		$Rights = $Rights.",".$RightB1I;
	}
}

if($RightB1U != null && $RightB1U != "")
{
	if($Rights == "")
	{
		$Rights = $RightB1U;
	}
	else
	{
		$Rights = $Rights.",".$RightB1U;
	}
}

if($RightB1D!= null && $RightB1D != "")
{
	if($Rights == "")
	{
		$Rights = $RightB1D;
	}
	else
	{
		$Rights = $Rights.",".$RightB1D;
	}
}

if($RightB2!= null && $RightB2 != "")
{
	if($Rights == "")
	{
		$Rights = $RightB2;
	}
	else
	{
		$Rights = $Rights.",".$RightB2;
	}
}

if($RightB3!= null && $RightB3 != "")
{
	if($Rights == "")
	{
		$Rights = $RightB3;
	}
	else
	{
		$Rights = $Rights.",".$RightB3;
	}
}

if($RightC1I != null && $RightC1I != "")
{
	if($Rights == "")
	{
		$Rights = $RightC1I;
	}
	else
	{
		$Rights = $Rights.",".$RightC1I;
	}
}
if($RightC1U != null && $RightC1U != "")
{
	if($Rights == "")
	{
		$Rights = $RightC1U;
	}
	else
	{
		$Rights = $Rights.",".$RightC1U;
	}
}
if($RightC1D != null && $RightC1D != "")
{
	if($Rights == "")
	{
		$Rights = $RightC1D;
	}
	else
	{
		$Rights = $Rights.",".$RightC1D;
	}
}
if($RightC1Q != null && $RightC1Q != "")
{
	if($Rights == "")
	{
		$Rights = $RightC1Q;
	}
	else
	{
		$Rights = $Rights.",".$RightC1Q;
	}
}

//$RightCNickname = $_POST["chkCNickname"];
//$RightCArea = $_POST["chkCArea"];
$RightCSource = $_POST["chkCSource"];
$RightCGreenTel = $_POST["chkCGreenTel"];
$RightCBlackTel = $_POST["chkCBlackTel"];
$RightCRedTel = $_POST["chkCRedTel"];
$RightCMemo = $_POST["chkCMemo"];
$RightCMiss = $_POST["chkCMiss"];
$RightCClass = $_POST["chkCClass"];

$RightFields = "";

//if($RightCArea!= null && $RightCArea != "")
//{
//	if($RightFields == "")
//	{
//		$RightFields = $RightCArea;
//	}
//	else
//	{
//		$RightFields = $RightFields.",".$RightCArea;
//	}
//}

if($RightCSource!= null && $RightCSource != "")
{
	if($RightFields == "")
	{
		$RightFields = $RightCSource;
	}
	else
	{
		$RightFields = $RightFields.",".$RightCSource;
	}
}

if($RightCClass!= null && $RightCClass != "")
{
	if($RightFields == "")
	{
		$RightFields = $RightCClass;
	}
	else
	{
		$RightFields = $RightFields.",".$RightCClass;
	}
}

if($RightCGreenTel!= null && $RightCGreenTel != "")
{
	if($RightFields == "")
	{
		$RightFields = $RightCGreenTel;
	}
	else
	{
		$RightFields = $RightFields.",".$RightCGreenTel;
	}
}

if($RightCBlackTel!= null && $RightCBlackTel != "")
{
	if($RightFields == "")
	{
		$RightFields = $RightCBlackTel;
	}
	else
	{
		$RightFields = $RightFields.",".$RightCBlackTel;
	}
}

if($RightCRedTel!= null && $RightCRedTel != "")
{
	if($RightFields == "")
	{
		$RightFields = $RightCRedTel;
	}
	else
	{
		$RightFields = $RightFields.",".$RightCRedTel;
	}
}

if($RightCMemo!= null && $RightCMemo != "")
{
	if($RightFields == "")
	{
		$RightFields = $RightCMemo;
	}
	else
	{
		$RightFields = $RightFields.",".$RightCMemo;
	}
}

if($RightCMiss!= null && $RightCMiss != "")
{
	if($RightFields == "")
	{
		$RightFields = $RightCMiss;
	}
	else
	{
		$RightFields = $RightFields.",".$RightCMiss;
	}
}

$ViewData = $_POST["ViewData"];
$UpdateViewData = $_POST["UpdateViewData"];
$ViewFileData = $_POST["ViewFileData"];
$RightLevel = $_POST["RightLevel"];
$Uplevel = $_POST["Uplevel"];

$ViewData = "1";
$UpdateViewData = "1";
$ViewFileData = "1";
$RightLevel = "1";
$Uplevel = "1";

$db = new DBOperation();
$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
 
if($action == "Insert")
{
	$insertSql = "INSERT INTO GroupRights (GName, GRights,GFieldRights,GViewData,GCreateAcc,"
	              ."GCreateName,GCreateTime,GUpdateTime,GUpdateViewData,GViewFileData,GRightLevel,GUplevel)"
	              ."VALUES ('".$db->mysql_real_escape_string($GroupName)."'"
	              .",'".$db->mysql_real_escape_string($Rights)."'"
	              .",'".$db->mysql_real_escape_string($RightFields)."'"
	              .",'".$db->mysql_real_escape_string($ViewData)."'"
	              .",'".$db->mysql_real_escape_string($_SESSION['username'])."'"	              
	              .",''"
	              .",'".Date('Y-m-d H:i:s')."'"
	              .",'".Date('Y-m-d H:i:s')."'"
	              .",'".$db->mysql_real_escape_string($UpdateViewData)."'"
	              .",'".$db->mysql_real_escape_string($ViewFileData)."'"
	              .",'".$db->mysql_real_escape_string($RightLevel)."'"
	              .",'".$db->mysql_real_escape_string($Uplevel)."')";
  
	$db->query($insertSql);
  $db->close_db();	
	echo '<script type="text/javascript">';
  echo 'alert("新增成功!!!!");';
  echo 'location.href="GroupRightsIndex.php?page=1"';
  echo '</script>';
}
else
{
	$updateSql = "UPDATE GroupRights set GName = '".$db->mysql_real_escape_string($GroupName)."'"
	             .",GRights = '".$db->mysql_real_escape_string($Rights)."'"
	             .",GFieldRights = '".$db->mysql_real_escape_string($RightFields)."'"
	             .",GViewData = '".$db->mysql_real_escape_string($ViewData)."'"
	             .",GUpdateTime = '".Date('Y-m-d H:i:s')."'"
	             .",GUpdateViewData = '".$db->mysql_real_escape_string($UpdateViewData)."'" 
	             .",GViewFileData = '".$db->mysql_real_escape_string($ViewFileData)."'"
	             .",GRightLevel = '".$db->mysql_real_escape_string($RightLevel)."'"  
	             .",GUplevel = '".$db->mysql_real_escape_string($Uplevel)."'"      
	             ." where GId = ".$id;
	$db->query($updateSql);
  $db->close_db();	
	echo '<script type="text/javascript">';
  echo 'alert("更新成功!!!!");';
  echo 'location.href="GroupRightsIndex.php?page=1"';
  echo '</script>';
}

//print_r($_FILES);
//echo "</pre>";



?>
</html>
