<?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 mangrove4 (Mangrove,photo,type) VALUES (%s,%s,%s)",
                       GetSQLValueString($_POST['Mangrove'], "text"),
                       GetSQLValueString($_FILES['image_file']['name'], "text"),
					   GetSQLValueString($_POST['type'],"text"));
  mysql_select_db($database_WWF, $WWF);
  $Result1 = mysql_query($insertSQL, $WWF) or die(mysql_error());
}



?>
<?php
mysql_select_db($database_WWF, $WWF);
$query_mangrove4 = "SELECT * FROM mangrove4";
$mangrove4 = mysql_query($query_mangrove4, $WWF) or die(mysql_error());
$row_mangrove4 = mysql_fetch_assoc($mangrove4);
$totalRows_mangrove4 = mysql_num_rows($mangrove4);
?>
<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}
.style26 {font-size: 12pt; }
.style27 {	font-size: 12pt;
	color: #006600;
	font-weight: bold;
}
.style28 {
	color: #FF3000;
	font-size: 12pt;
}
-->
</style>
</head>

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

<p align="center"><img src="mangrove/Cinnamomum_Camphora.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="642" border="1" bordercolor="#006600" bgcolor="#FFFFF0">
<tr>
  <td colspan="2" bordercolor="#FF3300" bgcolor="#FFF5F0"><span class="style26" style="margin-top: 0; margin-bottom: 0"><font color="#FF6600">試在指定範圍內找出圖中植物部份，拍攝並上載至電腦內。</font></span></td>
  </tr>
<tr>
            <td width="260" height="274" bordercolor="#FF3300" bgcolor="#FFF5F0"><p align="center"><img src="IMG_9456.jpg" width="331" height="238"><br>
            <br></td>
              <td width="366" bordercolor="#FF3300" bgcolor="#FFF5F0"><p>
                <?php if ($totalRows_mangrove4 == 0) { // Show if recordset empty ?>
                  <input type="file" name="image_file" size="40">
                  <?php } // Show if recordset empty ?>
              </p>
                <?php if ($totalRows_mangrove4 == 0) { // Show if recordset empty ?>
                <p class="style28">分別植物品種<br>
                  <label>
                    <input name="type" type="radio" value="mangrove">
                    紅樹</label>
                    <label>
                    <input name="type" type="radio" value="nonmangrove">
                    非紅樹</label>
                    </p>
                  <?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/mangrove4/" . $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="Mangrove4">
                </p>
                <p>
                  <?php if ($totalRows_mangrove4 > 0) { // Show if recordset not empty ?>
                <div align="center"><img src = "images/mangrove4/<?php echo $row_mangrove4['photo']; ?>" width="220" height="180"> </div>
                <?php } // Show if recordset not empty ?>
                <?php if ($totalRows_mangrove4 > 0) { // Show if recordset not empty ?>
                </p>
                <p align="center" class="style28">植物品種：
                  <? $type= $row_mangrove4['type'];
If (   $type == mangrove)
{echo '紅樹';}
else if ($type == nonmangrove)
{echo '非紅樹';} ?>
                    <?php } // Show if recordset not empty ?>
            </p></td>
</tr>
        </table>
      </td>
	
    <tr> </MM:DECORATION>
      </MM_HIDDENREGION>
      <br>

    <tr>
      <MM_HIDDENREGION>
      <?php if ($totalRows_mangrove4 == 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_mangrove4 > 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($mangrove4);
?>
