<?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 chapter502 (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>
	<title>0502</title>

    <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>

<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">
<meta http-equiv="ImageToolBar" content="NO"> 


<link rel="stylesheet" type="text/css" href="styles/styles.css">
<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>
</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>



<p><font face="新細明體"><span style="letter-spacing: 1pt"><b><font color="#0000FF">7－2．教玄鳳說話</font></b></span></font></p>



<p><font face="新細明體"><span style="letter-spacing: 1pt"><img border="0" src="http://f.blog.xuite.net/f/b/8/2/18442063/blog_965727/txt/16421034/1.jpg" style="float: left" width="184" height="354">
如同其他鸚鵡類的寵物鳥，模仿周遭的聲音亦是玄鳳天生所具有的能力之一．雖然不似其他大型鸚鵡類能把周遭聲音模仿的唯妙唯肖，但對於簡易的單字及特定的音調，只要飼主用些心思及努力便能讓玄鳳發揮這與生具來的模作能力．然而，並非全數的玄鳳皆能發揮其模仿的能力．通常玄鳳母鳥並不具備模仿聲音的能力（當然這並非完全絕對肯定），而越年長或不親近飼主的公成鳥其學習特定單字或音調的成效便會越來得低．一般而言，由飼主親手飼養長大之亞成鳥（公鳥）是學習（訓練）模仿聲音的最佳時期．<br> 
<br>
<br>
聲音是玄鳳間彼此溝通及表達情感的方式之一，更是公鳥在繁殖季節時吸引母鳥青睞的重要因素．對生活在群居中的公鳥而言，豐富及獨特的鳴叫是獲得配偶的重要手段之一．所以，由於性別的差異，當公玄鳳逐漸性成熟時便會更加注意觀察及模仿周遭可能出現的聲音．事實上，並非一定要對玄鳳進行所謂的說話訓練才能讓所飼養的玄鳳叫出特定的單字或音調，只要玄鳳在生長（生活）過程中，其周遭頻繁出現的聲音都有可能會被玄鳳所自行習得（模仿）而鳴叫出．利用CD播放器或MP３頻繁地播放出特定聲音亦有某程度上的功效．<br>
<br>
<br>
然而，除了讓玄鳳自然學會模仿周遭聲音外，不少的飼主還是會期望能教導所飼養的玄鳳能說出特定的話或音調．這樣的期望通常能在飼主的努力及耐心下都有一定程度的達成，只是每隻鳥有屬於自己的特質，其學習或接受訓練的程度未必能達到飼主原先的期望．<br>
<br>
<br>
飼主對玄鳳訓練前應先考慮玄鳳是否已適應周遭的環境，玄鳳的健康是否良好及玄鳳與飼主的親密程度，其中以飼主與玄鳳的關係最為重要．喜歡親近飼主的玄鳳會更重視飼主的行為，除了會觀察飼主的言行舉止外，更會樂於學習或模仿飼主的聲音．若加以適切的互動行為則更能得事半功倍的效果．<br>
<br>
<br>
訓練（或互動）進行時，應讓玄鳳專注於飼主本身的行為（或聲音）上，選擇安靜的空間及無周遭其他人事物的干擾對訓練玄鳳說話是相當重要的．飼主應確保玄鳳能清楚知道飼主的行為皆是針對它所來並亦期望能得到適切的回應．有的玄鳳會在飼主對其發出特定聲音時予以回應相同的聲音（模仿），雖不能期望每次皆能得到這樣的回應，但基本的作用便是能讓玄鳳熟悉這樣的聲音並與當時之互動關係有所聯想．<br>
<br>
<br>
剛開始教導玄鳳說出特定聲音或音調時，應使用較簡短的單字或音調等以方便訓練及學習．頻繁地反覆訓練（互動）是讓玄鳳熟悉特定聲音的主要關鍵．若能讓玄鳳熟悉特定的聲音，那麼在某時機時，玄鳳便會學習試著模仿鳴叫出（特別當這聲音是來自於玄鳳所喜愛的飼主時）．飼主若能在玄鳳模仿出該聲音時給予適切的回應及互動則可以強化玄鳳對這聲音的熟悉度並更樂於鳴叫它．一旦玄鳳能模仿特定聲音後，便會將這聲音作為自己的特點而經常鳴叫．<br>
<br>
<br>
讓玄鳳熟悉並鳴叫出簡短的單字（如名字或問候語）或音律其實並非難事．若再加以用心甚至可以習得更長的語句或歌曲．然而，模仿聲音雖是玄鳳的天生能力，但對於模仿人類語言的發音，其準確及清晰度未必能達到令人滿意的效果，換言之，玄鳳對高音度的聲音（如口哨，電話聲或門鈴聲）的模仿效果會較佳．<br>
<br>
<br>
那麼，玄鳳是否了解所熟悉（或模仿）字句的代表意義呢？在飼主特定的作為下，玄鳳是可以了解這些特定聲音的意義．所謂特定的作為指的便是飼主是以何種的互動下教授玄鳳這些特定的聲音．在這樣的學習下，玄鳳便能建立起該聲音與特定行為的關係．所以當飼主呼喚玄鳳名字時，玄鳳才能夠知道飼主是在呼喚它而予以回應．</span></font></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=191897&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 chapter502 ".
		 "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 chapter502";
$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>