<?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>
<Script Language="javascript" src="control/calendar.js"></Script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<?php

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

$actionOp = $_GET["actionOp"];

$CMemo = "";
$CNewFileName = "";
$COrgFileName = "";
$id = "";
$CCreator = "";
$rowAdminUser = null;
$CFileCount = $_POST["CFileCount"];

$db = new DBOperation();

if($actionOp == "Update")
{  
  $id = $_GET["id"];
  $db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
  $db->query("SELECT * FROM FileData where CId = '".$db->mysql_real_escape_string($id)."'");
  $row = $db->fetch_row();
  $CMemo = $row[1];
  $CNewFileName = $row[2];
  $COrgFileName = $row[3];
  
  $db->close_db();
}

$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);

$querySql = "";
if($_SESSION['rightLevel'] == "0")
{
	$querySql = "select * from AdminUser,GroupRights where AFlag = '1' and AGroupId = GId order by ACreateTime,GRightLevel";
}
elseif($_SESSION['rightLevel'] == "1")
{
	$querySql = "select AId,AName,AAccount,AFlag,GName from AdminUser,GroupRights where AFlag = '1' and AGroupId = GId And AGroupId = ".$_SESSION['groupId']." order by AId";
}
if($querySql != "")
{
	$db->query($querySql);
}

?>
<SCRIPT language="JavaScript">
function validateForm(objThisUi) 
{
	return true;  
}
</SCRIPT>
<body>
<form name="FileForm" method="post" action="FileDataUpdateDeal.php" id="FileForm"
 onSubmit="return validateForm(this);" enctype="multipart/form-data">
<input type="hidden" name="actionOp" id="actionOp" value="<?php echo $actionOp ?>"/>
<input type="hidden" name="id" id="id" value="<?php echo $id ?>"/>
<input type="hidden" name="CFileCount" id="CFileCount" value="<?php echo $CFileCount ?>"/>
<table border="0" cellspacing="0" cellspadding="0" width="100%">
<tr>
<td align="left" colspan="2">
&nbsp;
</td>
</tr>
<tr>
<td align="left" colspan="2">
<span class="t14b"><b>新增/修改檔案資料</b></span>
</td>
</tr>
<tr>
<td align="left" colspan="2">
<table border="3" cellspacing="2" cellspadding="2" width="100%">
<tr>
<td align="left" width="20%">
<span class="t12">誰的檔案資料</span>
</td>
<td align="left" width="80%">
<?php
if($querySql != "")
{
$i = 0;
while($myrow = $db->fetch_array())
{
	$i = $i + 1;
?>
<input type="radio" value="<?php echo $myrow['AId'];?>" <?php if($i == 1) echo "checked"; ?> name="AId">
<span class="t12"><?php echo $myrow['AName'];?></span>
<?php
	if($i%6 == 0)
	{
		echo "<br>";
	}
}
$db->close_db();
}
else
{
?>
<span class="t12"><?php echo $_SESSION['username'];?></span>
<?php	
}
?>
</td>
</tr>
<?php
if($actionOp == "Update")
{
?>
<tr>
<td align="left" width="20%">
<span class="t12">備註</span>
</td>
<td align="left" width="80%">
<input type="text" value="<?php echo $CMemo ?>" name="CMemo" id="CMemo" size="70" maxlength="70" style="font-size: 12.0pt;font-family: 微軟正黑體;"/>
</td>
</tr>
<tr>
<td align="left" width="20%">
<span class="t12">原檔案</span>
</td>
<td align="left" width="80%">
<span class="t12"><?php echo $COrgFileName; ?></span>
</td>
</tr>
<tr>
<td align="left" width="20%">
<span class="t12">新檔案</span>
</td>
<td align="left" width="80%">
<input type="file" name="myfile" id="myfile" size="50"/>
<br>
<span class="t12r"><b>注意 : 若檔案未變更，則不用上傳檔案!!!</b></span>
</td>
</tr>
<?php
}
else
{
	for($x=1;$x<=$CFileCount;$x++)
	{
?>
<tr>
<td align="left" width="16%">
<span class="t12">檔案資料<?php echo $x;?></span>
</td>
<td align="left" width="84%">
<table border="0" cellspacing="5" cellspadding="5" width="80%">
<tr>
<td align="left" width="55%">
<span class="t12">備註</span>
<br>
<input type="text" name="CMemo<?php echo $x;?>" id="CMemo<?php echo $x;?>" size="30" maxlength="70" class="t12"/>
<br>
<span class="t12">檔案上傳</span>
<br>
<input type="file" name="myfile<?php echo $x;?>" id="myfile<?php echo $x;?>" size="50" class="t12"/>
</td>
</tr>
</table>
</td>
</tr>
<?php
  }
}
?>
<tr>
<td  align="center" colspan="2">
<input type="submit" name="btnSub" id="btnSub" value="<?php if($actionOp == "Insert") echo "確定新增"; else echo "確定修改" ?>" class="t12" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
