<?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();
}

?>
<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="center" colspan="2">
<span class="title"><b>檔案資料管理</b></span>
</td>
</tr>
-->
<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%">
<?php
if($_SESSION['username'] == "admin")
{
	$db->connect_db($_DB['host'], $_DB['username'], $_DB['password'], $_DB['dbname']);
  $db->query("SELECT * FROM AdminUser where AFlag = '1'");  
?>
<tr>
<td align="left" width="20%">
<span class="t12">誰的檔案資料</span>
</td>
<td align="left" width="80%">
<Select name="CUser">
<?php
  $i = "0";
	while($rowAdminUser = $db->fetch_array())
  {
?>
<Option Value="<?php echo $rowAdminUser['AId']; ?>" <?php if($CCreator == $rowAdminUser['AId']) echo "selected"; elseif($CCreator == "" && $i == "0") echo "selected";?>><?php echo $rowAdminUser['AName']."-".$rowAdminUser['AAccount']; ?></Option>
<?php
		$i = "1";
	}
?>
</Select>
</td>
</tr>
<?php
	$db->close_db();
}
?>
<?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>
