<?php
// include the database configuration and
// open connection to database
include 'library/opendb.php';

// check if the form is submitted
if(isset($_POST['btnSign']))
{
	// get the input from $_POST variable
	// trim all input to remove extra spaces
	$name    = trim($_POST['txtName']);
	$email   = trim($_POST['txtEmail']);
	$url     = trim($_POST['txtUrl']);
	$message = trim($_POST['mtxMessage']);
	
	// escape the message ( if it's not already escaped )
	if(!get_magic_quotes_gpc())
	{
		$name    = addslashes($name);
		$message = addslashes($message);
	}
	
	// if the visitor do not enter the url
	// set $url to an empty string
	if ($url == 'http://')
	{
		$url = '';
	}
	
	// prepare the query string
	$query = "INSERT INTO chapter504 (name, email, url, message, entry_date) " .
	         "VALUES ('$name', '$email', '$url', '$message', current_date)";

	// execute the query to insert the input to database
	// if query fail the script will terminate		 
	mysql_query($query) or die('Error, query failed. ' . mysql_error());
	
	// redirect to current page so if we click the refresh button 
	// the form won't be resubmitted ( as that would make duplicate entries )
	header('Location: ' . $_SERVER['REQUEST_URI']);
	
	// force to quite the script. if we don't call exit the script may
	// continue before the page is redirected
	exit;
}
?>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">

<title>0504</title>
<script language="JavaScript">
/*
	This function is called when
	the 'Sign Guestbook' button is pressed
	Output : true if all input are correct, false otherwise
*/
function checkForm()
{
	// the variables below are assigned to each
	// form input 
	var gname, gemail, gurl, gmessage;
	with(window.document.guestform)
	{
		gname    = txtName;
		gemail   = txtEmail;
		gurl     = txtUrl;
		gmessage = mtxMessage;
	}
	
	// if name is empty alert the visitor
	if(trim(gname.value) == '')
	{
		alert('請輸入你的名字');
		gname.focus();
		return false;
	}
	// alert the visitor if email is empty or the format is not correct 
	else if(trim(gemail.value) != '' && !isEmail(trim(gemail.value)))
	{
		alert('請輸入正確的信箱網址或留下空白');
		gemail.focus();
		return false;
	}
	// alert the visitor if message is empty
	else if(trim(gmessage.value) == '')
	{
		alert('請輸入你的回應');
		gmessage.focus();
		return false;
	}
	else
	{
		// when all input are correct 
		// return true so the form will submit		
		return true;
	}
}

/*
Strip whitespace from the beginning and end of a string
Input  : a string
Output : the trimmed string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Check if a string is in valid email format. 
Input  : the string to check
Output : true if the string is a valid email address, false otherwise.
*/
function isEmail(str)
{
	var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
	return regex.test(str);
}
</script>

<style type="text/css">
<!--
body {scrollbar-face-color: #ffffff; 
          scrollbar-arrow-color:#ccccff; 
          scrollbar-highlight-color: #ccccff; 
          scrollbar-shadow-color: #ccccff;
          scrollbar-3dlight-color: #ccccff; 
          scrollbar-track-color: #ffffff}
          a:link, a:visited,  a:active {color=blue; text-decoration: underline;}

//-->
    </style>

<script language="JavaScript"> <!--
var message="請勿複製!!!"; // Message for the alert box
function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
// --> </script>



</head>
<script language="JavaScript1.2"> 
if (window.Event) 
document.captureEvents(Event.MOUSEUP); 
function nocontextmenu()  
{
event.cancelBubble = true
event.returnValue = false;
return false;
}
function norightclick(e)	
{
if (window.Event)	
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelBubble = true
event.returnValue = false;
return false;
}	
}
document.oncontextmenu = nocontextmenu;		
document.onmousedown = norightclick;		
</script>




<body>

 <font color="#0000FF"><b>７－４．聰明與否跟你有關</b></font><p>
 <img border="0" src="http://f.blog.xuite.net/f/b/8/2/18442063/blog_965727/txt/16421034/8.jpg" style="float: left" width="181" height="369"><span style="letter-spacing: 1pt">對有飼養寵物鳥的飼主而言，若能有個答案能清楚地告知所飼養的寵物鳥有多麼聰明，那將會是一個讓人多麼好奇的期待．然而，儘管當前的科學對鳥類研究已有相當的了解，但鳥類畢竟不能以評量人類智商數值的量化方式來測得其聰明程度．雖然如此，美國布蘭迪斯大學（Brandeis 
      University）的教授Irene Pepperberg針對鳥類的聰明程度曾進行了一長達２９年的研究，以其所飼養的非洲灰鸚（Alex）為研究對象所測得的結論為此非洲灰鸚擁有如同人類５歲孩童般的智商（然而其溝通能力僅有如２歲孩童程度）．</span></p>
 <p><span style="letter-spacing: 1pt">相信有飼養非洲灰鸚的飼主對這研究的結果並不會覺得驚訝，畢竟鸚鵡類的寵物鳥在生活上的表現及與飼主的互動行為所顯現出的就像一懵懂的人類幼童般．但被飼養的寵物鳥畢竟有許多的種類，而對於如玄鳳這般中小型鸚鵡的聰明程度是否就能等同於非洲灰鸚這種大型鸚鵡呢？在探討玄鳳是否能有等同如灰鸚這等大型鸚鵡的智商前，一個先決的考慮因素應先被思考，那便是所謂聰明才智其實並非與生俱來，而更是日後的教授或訓練而致（畢竟Irene訓練Alex長達２９年之久）．</span></p>
 <p><span style="letter-spacing: 1pt">一般飼主畢竟不具專業的教授或訓練鳥的技能，事實上，在飼養寵物鳥過程中，飼主通常都是任由寵物鳥獨自學習生活技巧或對周遭的認知及應對．或許對身為人類的飼主而言，寵物鳥原本就屬於這樣的成長（學習）模式，但若換個立場而想，當一個人從小到大卻不曾接受過知識或生存技巧方面的教授時（甚或不曾與同類相處過），那麼，我們又該如何看待這個人的聰明程度呢？一般的寵物鳥如同野地生活的同類都是依循著本能反應來對應生活上所可能面對的狀況．然而由於所處環境的不同，被人類所飼養的寵物鳥並不似野地生存的同類更能接觸到如此多複雜的未知狀況，因而導致被飼養的寵物鳥通常無法發揮其本能上應有的靈敏反應（或者聰明才智）．</span></p>
 <p><span style="letter-spacing: 1pt">然而，最近的研究指出鸚鵡類的鳥類確實是具有邏輯思考的能力．這對飼養寵物鳥的飼主或許會是一個令人興奮的訊息．在飼養的過程中，寵物鳥總是會有某些特別的行為表現證實其所具備的思考能力，如透過觀察飼主的動作而學會開籠門或鎖等．在Irene的研究結果中，她指出Alex能辯別出１百種的物品並能以簡易的問與答方式回應發問者的問題（如數量或顏色等問題）．雖然這是令人振奮的結論，但如前這所述，這等的能力並非憑空而來，其背後所付出的努力和耐心才是關鍵所在．</span></p>
 <p><span style="letter-spacing: 1pt">不管是何種的寵物鳥，其聰明才智絕大部份都是須靠日後適切的教授或訓練所激發而出．寵物鳥的聰明表現其實可以區分為兩類
 ：一為自覺性，一為強制性．自覺性高的鳥類通常其邏輯思考能力較強，在面對處處有生存威脅（或生活嚴苛）的環境中特別容易被激發，對生存於野地的鳥類而言，越聰明才能越確保生存的優勢；然而，對生存於安全無虞的寵物鳥而言，少了更迫切的刺激，其自覺性往往不及野地同類來的靈敏．而脫離自然法則而居的寵物鳥在與飼主的互動過程中，有許多的生活行為或習性尚須在飼主的特殊期待下有所改變，而這類的改變通常來自於飼主強制性的要求，如某特定行為的訓練．</span></p>
 <p><span style="letter-spacing: 1pt">寵物鳥的自覺性思考能力衰退通常會為其在生活上帶來更多的負面影響，如危機意識的不足，求生技巧的喪失，
 情緒敏感度的鈍化，甚或生活意念的薄弱等．造成寵物鳥思考能力衰退的最大主因仍是其生存的環境，其因素包括有：單一飼養，互動行為的缺乏，單調的空間及生活，
 危險因子的欠缺，缺少新鮮（刺激）事物的接觸等．</span></p>
 <p><span style="letter-spacing: 1pt">正確地闡釋寵物鳥的聰明意義對改善寵物鳥的生活品質是重要的課題之一．不少的飼主往往只依寵物鳥學習人類指定行為的能力來判斷其聰明程度，雖不能絕對將之否定，但在本質上，鳥類的聰明表現乃在於如何確保本身在野地的生存優勢及提升其生活品質上．學習與飼主特定的互動模式固然重要，但在此之前，飼主應以改善寵物鳥的生活環境以達到能培育或激發其自覺性的思考能力為重．然而畢竟飼主無法直接地教授或影響寵物鳥的心智發展，在相等的環境下，或許亦會造就每隻寵物鳥不同程度的聰明表現．</span></p>
 <p><span style="letter-spacing: 1pt">飼主雖無法直接教授寵物鳥腦智的成長，但仍可藉由改善其生活環境來達到某程度的激發效果．適切的作為可以是為其增加同伴或更頻繁與之互動，多讓其出籠在外活動及接觸家中環境（物品），定時地為其添加玩具或局部更換其生活環境，改變飲食提供方式（如將之藏匿於玩具中），將其居住之籠子擺放於可觀看家中成員活動處，若情況允許可將之攜出接觸外界環境等．寵物鳥的聰明與否其實是不應以人類的標準來判定，習得飼主所期望的特定行為，雖能增進彼此的互動，但並不能作為擔保其生命品質的依據．對一隻“聰明”的寵物鳥而言，其聰明表現若能發揮在判別屋內危險處（如吊扇，魚缸，貓狗，玻璃等），對同伴或飼主的情感敏銳度及生活困難的排除上則會更加有意義． </span></p>
 <p><span style="letter-spacing: 1pt">對飼主來言，增進飼養寵物鳥時的知識是不可缺少的課程，然而，該如何有效率地增進寵物鳥的腦智也正考驗著飼主本身的“聰明”程度．寵物鳥的聰明程度是可以被激發的，只是少了飼主的協助，寵物鳥便只能獨自摸索學習，若加上環境限制的阻礙，只怕就可惜了鸚鵡類為寵物鳥中最聰明
 之鳥的美名．</span><br>


 </p>


<table border="0" width="100%">
  <tr>
    <td width="100%">
     

     
<!-- Start of SimpleHitCounter Code -->
<div align="right"><a href="http://www.simplehitcounter.com" target="_blank"><img src="http://simplehitcounter.com/hit.asp?uid=200547&f=16777215&b=0" border="0" height="18" width="83" alt="free hit counters"></a><br><a href="http://www.simplehitcounter.com" target="_blank"><font size="-3">free hit counters</font></a></div>
<!-- End of SimpleHitCounter Code -->
</td>
  </tr>
</table>

<?php


// =======================
// Show guestbook entries
// =======================

// how many guestbook entries to show per page
$rowsPerPage = 10;

// by default we show first page
$pageNum = 1;

// if $_GET['page'] defined, use the value as page number
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}

// counting the offset ( where to start fetching the entries )
$offset = ($pageNum - 1) * $rowsPerPage;

// prepare the query string
$query = "SELECT id, name, email, url, message, DATE_FORMAT(entry_date, '%d.%m.%Y') ".
         "FROM chapter504 ".
		 "ORDER BY id DESC ".            // using ORDER BY to show the most current entry first
		 "LIMIT $offset, $rowsPerPage";  // LIMIT is the core of paging

// execute the query 
$result = mysql_query($query) or die('Error, query failed. ' . mysql_error());

// if the guestbook is empty show a message
if(mysql_num_rows($result) == 0)
{
?>
<p><br>
 <br>若你對此文章有所不同意見或觀點，誠請你在此留下回應．</p>
<?php
}
else
{
	// get all guestbook entries
	while($row = mysql_fetch_array($result))
	{
		// list() is a convenient way of assign a list of variables
		// from an array values 
		list($id, $name, $email, $url, $message, $date) = $row;

		// change all HTML special characters,
		// to prevent some nasty code injection
		$name    = htmlspecialchars($name);
		$message = htmlspecialchars($message);		

		// convert newline characters ( \n OR \r OR both ) to HTML break tag ( <br> )
		$message = nl2br($message);
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#f9fb9d">
 <tr> 
  <td width="80%" align="left"> <a href="mailto:<?=$email;?>" class="email"> 
   <?=$name;?>
   </a> </td>
  <td align="right"><small> 
   <?=$date;?>
   </small></td>
 </tr>
 <tr> 
  <td colspan="2"> 
   <?=$message;?>
   <?php
   		// if the visitor input her homepage url show it
		if($url != '')
		{   
			// make the url clickable by formatting it as HTML link
			$url = "<a href='$url' target='_blank'>$url</a>";
?>
   <br> <small>Homepage : <?=$url;?></small> 
   <?php
		}
?>
  </td>
 </tr>
</table>
<br>
<?php
	} // end while

// below is the code needed to show page numbers

// count how many rows we have in database
$query   = "SELECT COUNT(id) AS numrows FROM chapter504";
$result  = mysql_query($query) or die('Error, query failed. ' . mysql_error());
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage  = ceil($numrows/$rowsPerPage);
$nextLink = '';

// show the link to more pages ONLY IF there are 
// more than one page
if($maxPage > 1)
{
	// this page's path
	$self     = $_SERVER['PHP_SELF'];
	
	// we save each link in this array
	$nextLink = array();
	
	// create the link to browse from page 1 to page $maxPage
	for($page = 1; $page <= $maxPage; $page++)
	{
		$nextLink[] =  "<a href=%22$self?page=$page/&quot;>$page</a>";
	}
	
	// join all the link using implode() 
	$nextLink = "Go to page : " . implode(' &raquo; ', $nextLink);
}

// close the database connection since
// we no longer need it
include 'library/closedb.php';

?>
<form method="post" name="guestform">
 <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#ccff99">
  <tr> 
   <td width="15%">名字*</td> <td> 
    <input name="txtName" type="text" id="txtName" size="30" maxlength="30"></td>
 </tr>
  <tr> 
   <td width="15%">Email</td>
   <td> 
    <input name="txtEmail" type="text" id="txtEmail" size="30" maxlength="50"></td>
 </tr>
  <tr> 
   <td width="15%">網址</td>
   <td> 
    <input name="txtUrl" type="text" id="txtUrl" value="http://" size="30" maxlength="50"></td>
 </tr>
  <tr> 
   <td width="15%">內容*</td> <td> 
    <textarea name="mtxMessage" cols="72" rows="8" id="mtxMessage"></textarea></td>
 </tr>
  <tr> 
   <td width="15%">&nbsp;</td>
   <td> 
    <input name="btnSign" type="submit" id="btnSign" value="送出" onClick="return checkForm();">如要發問問題，請至留言板或討論區．</td>
 </tr>
</table>
</form>


<table width="100%" border="0" cellpadding="2" cellspacing="0">
 <tr> 
  <td align="right" class="text"> 
   <?=$nextLink;?>
  </td>
 </tr>
</table>
<?php
}
?>

</body>
</html>