<?php require_once('../../Connections/WWF.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "image_upload_form")) {
  $insertSQL = sprintf("INSERT INTO planktonvideo (Video) VALUES (%s)",
                       GetSQLValueString($_FILES['image_file']['name'], "text"));
  mysql_select_db($database_WWF, $WWF);
  $Result1 = mysql_query($insertSQL, $WWF) or die(mysql_error());
}



?>
<?php
mysql_select_db($database_WWF, $WWF);
$query_planktonvideo = "SELECT * FROM planktonvideo";
$planktonvideo = mysql_query($query_planktonvideo, $WWF) or die(mysql_error());
$row_planktonvideo = mysql_fetch_assoc($planktonvideo);
$totalRows_planktonvideo = mysql_num_rows($planktonvideo);
?>
<html>

<head>
<meta http-equiv="Content-Language" content="zh-tw">
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>浮遊生物多面睇</title>
<base target="_self">
<style type="text/css">
<!--
.style4 {
	font-size: 12px;
	font-family: "新細明體";
}
.style6 {font-size: 12px}
.style9 {font-size: 10px}
.style11 {font-size: 10}
.style12 {color: #FF6600}
.style23 {
	font-size: 16px;
	font-weight: bold;
}
.style24 {font-family: "Comic Sans MS"}
.style25 {	color: #006600;
	font-size: 12pt;
}
-->
</style>
</head>

<body style="background-attachment: fixed" bgcolor="#FFFFCC">

<p align="center"><img src="planktonvideo.jpg" width="220" height="70"></p>
<div align="center"><form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="image_upload_form">
  <tr>
	  <td width="43%">
			<table width="598" border="1" bordercolor="#006600" bgcolor="#FFFFF0">
<tr>
            <td width="588"><p>
                  <?php if ($totalRows_planktonvideo == 0) { // Show if recordset empty ?>
                      <div align="center">
                        <input type="file" name="image_file" size="40">
                  </div>
                    <?php } // Show if recordset empty ?>
</p>
                  
                  <?
//print_r($_POST);

if($_POST["action"] == "Save")
{
unset($imagename);

if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;

if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";


$imagename = basename($_FILES['image_file']['name']);
//echo $imagename;

if(empty($imagename))
$error["imagename"] = "The name of the image was not found.";

if(empty($error))
{
$newimage = "images/planktonvideo/" . $imagename;
//echo "<img src= '$newimage' width='160' height='120' >"  ;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result))
$error["result"] = "There was an error moving the uploaded file.";
}

}

?>
                    <span class="style4">
                    <?
if(is_array($error))
{
while(list($key, $val) = each($error))
{
echo $val;
echo "<br>\n";
}
}
?></span>
                    <p>

                    <div align="center">
                      <?php if ($totalRows_planktonvideo > 0) { // Show if recordset not empty ?>
                      <embed width='320' height='260' src="<?php echo $row_planktonvideo['Video']; ?>">                    
                          <?php } // Show if recordset not empty ?>
              </div>
            </p></td>
              </tr>
        </table>
      </td>
	
    <tr>
        <?php if ($totalRows_planktonvideo == 0) { // Show if recordset empty ?>
          <input type="submit" value="Save" name="action">
          </p>
          <input type="hidden" name="MM_insert" value="image_upload_form">
        <?php } // Show if recordset empty ?></form>
</div>			
<div align="center" class="style6">
  <p>
    <?php if ($totalRows_planktonvideo > 0) { // Show if recordset not empty ?>
  <p class="style3"><font face="Times New Roman"><a href="javascript:self.close()"><font size="5">關閉視窗</font></a> </font></p>
  <?php } // Show if recordset not empty ?>&nbsp;</p>
</div>
</body>

</html>
<?php
mysql_free_result($planktonvideo);
?>
