<?php
  //檢查 cookie 中的 passed 變數是否等於 TRUE 
  $passed = $_COOKIE{"passed"};
  
  //如果 cookie 中的 passed 變數不等於 TRUE
  //表示尚未登入網站，將使用者導向首頁 index.html
  if ($passed != "TRUE")
  {
    header("location:register.html");
    exit();
  }
  
  //如果 cookie 中的 passed 變數等於 TRUE
  //表示已經登入網站，取得使用者資料  
  else
  {
    require_once("dbtools.inc.php");
    
    $id = $_COOKIE{"id"};
    
    //建立資料連接
    $link = create_connection();
        
    //執行 SELECT 陳述式取得使用者資料
    $sql = "SELECT * FROM register Where id = $id";
    $result = execute_sql($link, "book4105", $sql);

    $row = mysqli_fetch_assoc($result);
  } 
    $city="";
?>

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>二手交易網站</title>
    <meta name="keywords" content="" />
    <meta name="description" content="" />

    <link href="default.css" rel="stylesheet" type="text/css" media="all" />
    
  </head>

  <body bgcolor="lightyellow">

    <div id="header-wrapper">
    <div id="logo">
    <h1><a href="#">二手交易網站</a></h1>
    </div>
    <div id="triangle-up"></div>
    </div>

    <div id="menu-wrapper">
    <div id="menu">
      <ul>
        <li class="current_page_item"><a href="index2.html" accesskey="1" title="">首頁</a></li>
        <li><a href="Categories2.php" accesskey="2" title="">我要找書</a></li>
        <li><a href="main.php" accesskey="3" title="">會員中心</a></li>
        <li><a href="bookch.html" accesskey="4" title="">刊登商品</a></li>
      </ul>
    </div>
    </div>

    <div id="log">
      <p align="right">
        <a href="login2.html"><font color="#666666" size="3">註冊</font></a>
        <a href="logout.php" onClick="return(confirm('你確定要登出嗎？'))"><font color="#666666" size="3">登出</font></a>
      </p>

    </div>

    <div id="wrapper">
    <div id="featured-wrapper">



<div id="Sidebar">
</br>
    <div style="text-align:center;"><span class="byline"><font size="5"><font color=#470024><b>商品分類</b></font></font></span>
    </div>
</br>
         <td width='162' height=15 colspan=3 valign=top style="text-align:left"> <img src=book.jpg>&nbsp;
              <a href='#'><font color=#325189  size=4"><B>人文暨社會科學院</B></a></font></a></td>
        </td>
    
    <tr>
        <td colspan=5 align=center>
            <TABLE border=0 width=155>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='中國文學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">中文系</font>
                    </a>
                </td>
                <td align=center WIDTH=5><font color=gray>|</font></td><td align=left width=80 class='dfont'>
                    <a href='社會工作與兒童少年福利學系.php'>
                        <font color=blue  style="font-size: 17px;font-family: Times New Roman">社工系</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='台灣文學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">台文系</font>
                    </a>
                </td>
                <td align=center WIDTH=5><font color=gray>|</font></td><td align=left width=80 class='dfont'>
                    <a href='法律學系.php'>
                        <font color=blue  style="font-size: 17px;font-family: Times New Roman">法律系</font>
                    </a>
                </td>
            </tr>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='生態人文學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">生態系</font>
                    </a>
                </td>
                <td align=center WIDTH=5><font color=gray>|</font></td><td align=left width=80 class='dfont'>
                    <a href='大眾傳播學系.php'>
                        <font color=blue  style="font-size: 17px;font-family: Times New Roman">大傳系</font>
                    </a>
                </td>
        </td>
    </tr>       


<tr><td width=167 colspan=4 height=1 bgcolor=#BEC7C4></td></tr>

        
        <tr>
            <td width='162' height=15 colspan=3 valign=top><img src=book.jpg>&nbsp;   
                <a href='#'><font color=#325189  size=4"><B>外語學院</B></a>
            </td>
        </tr>

    <tr>
        <td colspan=5 align=center>
            <TABLE border=0 width=155>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='英國語文學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">英文系</font>
                    </a>
                </td>
                <td align=center WIDTH=5><font color=gray>|</font></td><td align=left width=80 class='dfont'>
                    <a href='西班牙語文學系.php'>
                        <font color=blue  style="font-size: 17px;font-family: Times New Roman">西文系</font>
                    </a>
                </td>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='日本語文學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">日文系</font>
                    </a>
                </td>   
        </td>
    </tr>


<tr><td width=167 colspan=4 height=1 bgcolor=#BEC7C4></td></tr>


        <tr>
            <td width='162' height=15 colspan=3 valign=top><img src=book.jpg>&nbsp;   
                <a href='#'><font color=#325189  size=4"><B>理學院</B></a>
            </td>
        </tr>

    <tr>
        <td colspan=5 align=center>
            <TABLE border=0 width=155>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='財務工程學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">財工系</font>
                    </a>
                </td>
                <td align=center WIDTH=5><font color=gray>|</font></td><td align=left width=80 class='dfont'>
                    <a href='應用化學系.php'>
                        <font color=blue  style="font-size: 17px;font-family: Times New Roman">應化系</font>
                    </a>
                </td>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='食品營養學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">食營系</font>
                    </a>
                </td>
                <td align=center WIDTH=5><font color=gray>|</font></td><td align=left width=80 class='dfont'>
                    <a href='化妝品科學系.php'>
                        <font color=blue  style="font-size: 17px;font-family: Times New Roman">化科系</font>
                    </a>
                </td> 
        </td>
    </tr>



<tr><td width=167 colspan=4 height=1 bgcolor=#BEC7C4></td></tr>


        <td width='162' height=15 colspan=3 valign=top> <img src=book.jpg>&nbsp;
                <a href='#'><font color=#325189  size=4"><B>管理學院</B></a>
        </td>
    
    <tr>
        <td colspan=5 align=center>
            <TABLE border=0 width=155>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='企業管理學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">企管系</font>
                    </a>
                </td>
                <td align=center WIDTH=5><font color=gray>|</font></td><td align=left width=80 class='dfont'>
                    <a href='國際企業學系.php'>
                        <font color=blue  style="font-size: 17px;font-family: Times New Roman">國企系</font>
                    </a>
                </td>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='會計學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">會計系</font>
                    </a>
                </td>
                <td align=center WIDTH=5><font color=gray>|</font></td><td align=left width=80 class='dfont'>
                    <a href='觀光事業學系.php'>
                        <font color=blue  style="font-size: 17px;font-family: Times New Roman">觀光系</font>
                    </a>
                </td>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='財務金融學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">財金系</font>
                    </a>
                </td>
                

<tr><td width=167 colspan=4 height=1 bgcolor=#BEC7C4></td></tr>


        <td width='162' height=15 colspan=3 valign=top> <img src=book.jpg>&nbsp;
                <a href='#'><font color=#325189  size=4"><B>資訊學院</B></a>
        </td>
    
    <tr>
        <td colspan=5 align=center>
            <TABLE border=0 width=155>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='資訊管理學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">資管系</font>
                    </a>
                </td>
                <td align=center WIDTH=5><font color=gray>|</font></td><td align=left width=80 class='dfont'>
                    <a href='資訊工程學系.php'>
                        <font color=blue  style="font-size: 17px;font-family: Times New Roman">資工系</font>
                    </a>
                </td>
            <tr>
                <td width=80 align= right class='dfont' valign=top>
                    <a href='資訊傳播學系.php'>
                        <font color=blue style="font-size: 17px;font-family: Times New Roman">資傳系</font>
                    </a>
                </td>

        </td>
    </tr>

</div></tr></td></td></tr></TABLE></td></tr></font></a></td></td></tr></td></td></tr></td></td></tr></TABLE></td></tr></font></a></td></td></tr></td></td></tr></TABLE></td></tr></font></a></td></tr></tr></td></td></tr></TABLE></td></tr></font></a></td></tr></td></tr></td></td></tr></td></td></tr></TABLE></td></tr></font></a></td></font></font></span>
    
</div>

<div class="title"><div class="hexagon"></div>
                    <form id="form1" name="form1" method="post" action="">
      <p>書名：
        <input name="city" type="text" id="city" value="<?php echo $city?>"/>
  
        <input type="submit" name="button" id="button" value="搜尋" /><br>
        <div class="custom-select" style="top:-100;">
      </p>
    </from>
    <table border="0" align="center" width="800" cellspacing="2"> 
      <tr bgcolor="#BABA76" height="30" align="center">
        <td>書號</td>
        <td>書名</td>
        <td>定價</td> 
        <td>數量</td>     
        <!--<td>書本資料</td>-->
                                          
      </tr>
        <?php
          require_once("dbtools.inc.php");
      

          //$records_per_page = 20;
      
          //取得要顯示第幾頁的記錄
          /*if (isset($_GET["page"]))
          $page = $_GET["page"];
          else
           $page = 1;*/

          //建立資料連接
          $link = create_connection();
              
          //篩選出所有產品資料

          /* $_POST['city']!=''){$city=$_POST['city'];*/
          if(isset($_POST["city"])) $city = $_POST["city"] ;
          else $city = "";
          $sql = "SELECT * FROM books WHERE name like '%$city%'";
          $result = execute_sql($link, "book4105", $sql);

          /*
          //計算總記錄數
          $total_records = mysqli_num_rows($result);

          //取得欄位數
          $total_fields = mysqli_num_fields($result);
      
          //取得記錄數
          $total_records = mysqli_num_rows($result);
      
          //計算總頁數
          $total_pages = ceil($total_records / $records_per_page);
      
          //計算本頁第一筆記錄的序號
          $started_record = $records_per_page * ($page - 1);
      
          //將記錄指標移至本頁第一筆記錄的序號
          mysqli_data_seek($result, $started_record);
          */        
          //列出所有產品資料
          $total_records = mysqli_num_rows($result);
          for ($i = 0; $i < $total_records; $i++)
          {
            //取得產品資料
            $row = mysqli_fetch_assoc($result);
            
            if($row["amount"] >= 0){      
              //顯示產品各欄位的資料
              //echo "<form method='post' action='book173.php?book_id=" . 
              //$row["book_id"] .">";
              echo "<tr align='center' bgcolor='#EDEAB1'>";
              echo "<td>" . $row["ISBN"] . "</td>";
              echo '<td>';
              echo '<a href="book12345.php?book_id='.$row["book_id"].'">'.$row['name'].'</a>';
              echo '</td>';     
              echo "<td>$" . $row["price"] . "</td>";
              echo "<td>" . $row["amount"] . "</td>";
              echo "</tr>";
            }  
          }
      
      /*
          //產生導覽列
          echo "<p align='center'>";
          if ($page > 1)
           echo "<a href='Categories3.php?page=". ($page - 1) . "'>上一頁</a> ";
        
          for ($i = 1; $i <= $total_pages; $i++)
         {
            if ($i == $page)
             echo "$i ";
          else
             echo "<a href='Categories3.php?page=$i'>$i</a> ";    
         }
      
          if ($page < $total_pages)
             echo "<a href='Categories3.php?page=". ($page + 1) . "'>下一頁</a> "; 
        
          echo "</p>";    
          */      
          //釋放資源及關閉資料連接
          mysqli_free_result($result);
          mysqli_close($link);
        ?>
    </table>
                    
                </div>
    
  </body>                                                                                 
</html>