<?php require_once('../../Connections/WWF.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}

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_update"])) && ($_POST["MM_update"] == "form2")) {
  $updateSQL = sprintf("UPDATE birds SET Quantity=%s, place1=%s, place2=%s, place3=%s, place4=%s, place5=%s, Behaviour1=%s, Behaviour2=%s, Behaviour3=%s, Behaviour4=%s, Score=%s WHERE BirdName=%s",
                       GetSQLValueString($_POST['quantity'], "text"),
                       GetSQLValueString($_POST['place'], "text"),
                       GetSQLValueString($_POST['place2'], "text"),
                       GetSQLValueString($_POST['place3'], "text"),
                       GetSQLValueString($_POST['place4'], "text"),
                       GetSQLValueString($_POST['place5'], "text"),
                       GetSQLValueString($_POST['behaviour'], "text"),
                       GetSQLValueString($_POST['behaviour2'], "text"),
                       GetSQLValueString($_POST['behaviour3'], "text"),
                       GetSQLValueString($_POST['behaviour4'], "text"),
                       GetSQLValueString($_POST['Score'], "text"),
                       GetSQLValueString($_POST['BirdName'], "text"));

  mysql_select_db($database_WWF, $WWF);
  $Result1 = mysql_query($updateSQL, $WWF) or die(mysql_error());

  $updateGoTo = "Bird_close.html";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
?>
<!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=big5" />
<title>紅腳鷸</title>
<style type="text/css">
<!--
body {
	background-color: #E7FFF2;
}
#Layer1 {
	position:absolute;
	left:309px;
	top:124px;
	width:253px;
	height:230px;
	z-index:1;
}
.style2 {
	font-family: "新細明體";
	font-size: 16px;
}
-->
</style></head>

<body>
<div id="Layer1">
  <form id="form2" name="form2" method="POST" action="<?php echo $editFormAction; ?>">
    <p align="left" class="style2">數量:
      <select name="quantity" id="quantity">
        <option value="1 - 4" selected="selected">1-4</option>
        <option value="5 - 10">5-10</option>
        <option value="11 - 20">11-20</option>
        <option value="&gt;20">&gt;20</option>
      </select>      
      <br />
        <br />
        出沒位置 :
        <input name="place" type="checkbox" id="place" value="Water" />
水面
<input name="place2" type="checkbox" id="place2" value="Island" />
小島<br />
<input name="place3" type="checkbox" id="place3" value="Tree" />
樹上
<input name="place4" type="checkbox" id="place4" value="Sky" />
天空
<input name="place5" type="checkbox" id="place5" value="Grassland" />
草叢 <br />
<br />
行為      :
<label>
  <input name="behaviour" type="checkbox" id="behaviour" value="Eating" />
</label>
覓食
<label>
  <input name="behaviour2" type="checkbox" id="behaviour2" value="Resting" />
</label>
休息
<label>
  <input name="behaviour3" type="checkbox" id="behaviour3" value="Flying" />
</label>
飛行
<label> <br />
  <input name="behaviour4" type="checkbox" id="behaviour4" value="Swimming" />
</label>
游泳 <br />
<br />
  我的喜愛指數
  :
      <select name="Score" id="Score">
    <option value="1 Star" selected="selected">1星</option>
    <option value="2 Stars">2星</option>
    <option value="3 Stars">3星</option>
    <option value="4 Stars">4星</option>
    <option value="5 Stars">5星</option>
  </select>
      (5星最高)<br />
    <input name="BirdName" type="hidden" id="BirdName" value="22CommonRedshank" />
    <br />
    <input type="submit" name="Submit" value="儲存" />
      <input type="hidden" name="MM_update" value="form2">
    </p>
</form>
</div>
<form id="form1" name="form1" method="post" action="">
  <div align="left"><img src="new_bird_description/Common Redshank.jpg" width="550" height="350" />  </div>
</form>
</body>
</html>
