<?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 mangrove1 (Mangrove,photo) VALUES (%s,%s)",
                       GetSQLValueString($_POST['Mangrove'], "text"),
                       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_mangrove1 = "SELECT * FROM mangrove1";
$mangrove1 = mysql_query($query_mangrove1, $WWF) or die(mysql_error());
$row_mangrove1 = mysql_fetch_assoc($mangrove1);
$totalRows_mangrove1 = mysql_num_rows($mangrove1);
?>
<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;
}
.style26 {font-size: 12pt; }
.style27 {	font-size: 12pt;
	color: #006600;
	font-weight: bold;
}
-->
</style>
</head>

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

<p align="center"><img src="mangrove/KandeliaObovata.jpg" width="230" height="95"></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="665" border="1" bordercolor="#006600" bgcolor="#FFFFF0">
<tr>
  <td colspan="2" bordercolor="#FF3300" bgcolor="#FFF8F4"><span class="style26" style="margin-top: 0; margin-bottom: 0"><font color="#FF6600">試在指定範圍內找出圖中植物部份，拍攝並上載至電腦內。</font></span></td>
  </tr>
<tr>
            <td width="285" bordercolor="#FF3300" bgcolor="#FFF8F4"><p>
              <div align="center"><img src="leave5.jpg" width="250" height="294"><br>
                  <br>
              </div>
            </p></p></td>
              <td width="364" bordercolor="#FF3300" bgcolor="#FFF8F4"><p>
                <?php if ($totalRows_mangrove1 == 0) { // Show if recordset empty ?>
                  <input type="file" name="image_file" size="40">
                  <?php } // Show if recordset empty ?>
              </p>
                <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/mangrove1/" . $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>
                  <input name="Mangrove" type="hidden" id="Mangrove" value="Mangrove1">
                </p>
            <p>  
              <?php if ($totalRows_mangrove1 > 0) { // Show if recordset not empty ?>
                <img src = "images/mangrove1/<?php echo $row_mangrove1['photo']; ?>" width="220" height="180">
            <?php } // Show if recordset not empty ?></p></td>
</tr>
        </table>
      </td>
	
    <tr> </MM:DECORATION>
      </MM_HIDDENREGION>
      <br>

    <tr>
      <MM_HIDDENREGION>
      <?php if ($totalRows_mangrove1 == 0) { // Show if recordset empty ?>
      <MM:DECORATION OUTLINE="%E5%A6%82%E6%9E%9C%E6%9C%89%E4%B8%8B%E5%88%97%E6%83%85%E6%B3%81%EF%BC%8C%E5%8D%B3%E9%A1%AF%E7%A4%BA..." OUTLINEID=1>
      <input type="submit" value="Save" name="action">
      <?php } // Show if recordset empty ?>
      </p>
      <input type="hidden" name="MM_insert" value="image_upload_form">
</form>
</div>			
<div align="center" class="style6"></div>
<p align="center"><span class="style27">
  <?php if ($totalRows_mangrove1 > 0) { // Show if recordset not empty ?>
  <a href="Mangrove.php">回到植物尋寶圖
  <?php } // Show if recordset not empty ?>
</a></span></p>
<p align="center"><a href="map.html"><img src="main.jpg" width="172" height="56" border="0"></a></p>
</body>

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