PageRenderTime 38ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/view.php

https://gitlab.com/jonz94/2016NCU_FreshWeb_HW
PHP | 240 lines | 219 code | 6 blank | 15 comment | 22 complexity | 1b84e2cec9c635506b4fbb3c0b2fb9b0 MD5 | raw file
  1. <!DOCTYPE html>
  2. <!-- 會員系統 PHP CODE -->
  3. <?php
  4. header("Content-Type: text/html; charset=utf-8");
  5. require_once("connMysql.php");
  6. //啟用 SESSION
  7. session_start();
  8. //檢查是否經過登入
  9. if(isset($_SESSION["loginUser"]) && ($_SESSION["loginUser"]!="")){
  10. //有登入
  11. $username = $_SESSION["loginUser"];
  12. $query_RecUser = "SELECT `nickname`, `permission` FROM `user` WHERE `username`='".$username."'";
  13. $RecUser = mysql_query($query_RecUser);
  14. $row_RecUser = mysql_fetch_assoc($RecUser);
  15. $nickname = $row_RecUser["nickname"];
  16. //帳號等級為 member
  17. if($row_RecUser["permission"]=="member"){
  18. $lv="member";
  19. //帳號等級為 admin
  20. }else{
  21. $lv="admin";
  22. }
  23. //沒登入、為 guest
  24. }else{
  25. $lv="guest";
  26. }
  27. //執行會員登入
  28. if(isset($_POST["username"]) && isset($_POST["password"])){
  29. //繫結登入會員資料
  30. $query_Login = "SELECT * FROM `user` WHERE `username`='".$_POST["username"]."'";
  31. $Login = mysql_query($query_Login);
  32. //取出帳號密碼的值
  33. $row_Login=mysql_fetch_assoc($Login);
  34. $username = $row_Login["username"];
  35. $password = $row_Login["password"];
  36. //比對密碼,若登入成功則呈現登入狀態
  37. if(md5($_POST["password"])==$password){
  38. //設定登入者的名稱及等級
  39. $_SESSION["loginUser"]=$username;
  40. //登入後重新載入
  41. if (isset($_GET['id'])) {
  42. $id = $_GET['id'];
  43. }else{
  44. ?>
  45. <script type="text/javascript">
  46. window.alert("登入成功!");
  47. window.location.assign("index.php");
  48. </script>
  49. <?php
  50. }
  51. ?>
  52. <script type="text/javascript">
  53. window.alert("登入成功!");
  54. window.location.assign("view.php?id=<?php echo $id;?>");
  55. </script>
  56. <?php
  57. }else{
  58. ?>
  59. <script type="text/javascript">
  60. window.alert("錯誤的帳號或密碼! 請重新登入!\n將被轉移至登入畫面!");
  61. window.location.assign("login.php");
  62. </script>
  63. <?php
  64. }
  65. }
  66. //執行登出動作
  67. if(isset($_GET["logout"]) && ($_GET["logout"]=="true")){
  68. unset($_SESSION["loginUser"]);
  69. header("Location: index.php");
  70. }
  71. /* 顯示留言 */
  72. // $id 顯示第幾筆留言
  73. if (isset($_GET['id'])) {
  74. $id = $_GET['id'];
  75. }else{
  76. $id = 1;
  77. }
  78. $query_RecComment = "SELECT `comment`.*, `user`.`nickname`, `user`.`username`, `user`.`sex` FROM `comment`,`user` WHERE `comment`.`id`='".$id."' AND `comment`.`user_id`=`user`.`id`";
  79. $RecComment = mysql_query($query_RecComment);
  80. if(!$row_RecComment=mysql_fetch_assoc($RecComment)){ ?>
  81. <script type="text/javascript">
  82. window.alert("該留言不存在!\n將被轉移至首頁!");
  83. window.location.assign("index.php");
  84. </script>
  85. <?php
  86. }
  87. ?>
  88. <html lang="zh-Hant-TW">
  89. <head>
  90. <meta charset="utf-8">
  91. <meta http-equiv=X-UA-Compatible content="IE=edge">
  92. <meta name=viewport content="width=device-width, initial-scale=1">
  93. <meta name=description content="">
  94. <meta name=author content="">
  95. <link rel="icon" href="/images/icon.jpg">
  96. <title>查看留言</title>
  97. <link href="/css/bootstrap.min.css" rel="stylesheet">
  98. <link href="/css/index.css" rel="stylesheet">
  99. <!--[if lt IE 9]><script src=~/Scripts/AssetsBS3/ie8-responsive-file-warning.js></script><![endif]-->
  100. <script src="/js/ie-emulation-modes-warning.js"></script>
  101. <!--[if lt IE 9]><script src=https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js></script><script src=https://oss.maxcdn.com/respond/1.4.2/respond.min.js></script><![endif]-->
  102. </head>
  103. <body class="custom-homepage">
  104. <nav class="navbar navbar-inverse navbar-fixed-top" role=navigation>
  105. <div class=container>
  106. <div class=navbar-header>
  107. <button type=button class="navbar-toggle collapsed" data-toggle=collapse data-target=#navbar aria-expanded=false aria-controls=navbar> <span class=sr-only>Toggle navigation</span> <span class=icon-bar></span> <span class=icon-bar></span> <span class=icon-bar></span> </button> <a class=navbar-brand href="/">小卓的留言板</a>
  108. </div>
  109. <div id=navbar class="navbar-collapse collapse">
  110. <ul class="nav navbar-nav">
  111. <li class="active"><a href="#">留言板</a></li>
  112. <li><a href="about.php#">關於此站</a></li>
  113. <li class="dropdown"><a href="./" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">To Do List<span class="caret"></span></a>
  114. <ul class="dropdown-menu dropdown-inverse" role="menu">
  115. <li><a href="todolist.php">ver. ul</a></li>
  116. <li><a href="todolist2.php">ver. table</a></li>
  117. <li><a href="todolist3.php">ver. div</a></li>
  118. </ul>
  119. </li>
  120. <li class="dropdown"><a href="./" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">網站地圖<span class="caret"></span></a>
  121. <ul class="dropdown-menu dropdown-inverse" role="menu">
  122. <li class="dropdown-header">留言板</li>
  123. <li><a href="index.php#">觀看留言</a></li>
  124. <li><a href="post.php">發表留言</a></li>
  125. <li class="divider"></li>
  126. <li class="dropdown-header">To Do List</a></li>
  127. <li><a href="todolist.php">ver. ul</a></li>
  128. <li><a href="todolist2.php">ver. table</a></li>
  129. <li><a href="todolist3.php">ver. div</a></li>
  130. <li class="divider"></li>
  131. <li class="dropdown-header">會員相關</li>
  132. <!--下拉式選單選項根據是否有登入而有不同顯示-->
  133. <?php if($lv=="guest"){ ?>
  134. <li><a href="login.php">登入</a></li>
  135. <li><a href="signup.php">註冊</a></li>
  136. <?php }else{ ?>
  137. <li><a href="update.php">更新資料</a></li>
  138. <li><a href="?logout=true">登出</a></li>
  139. <?php } ?>
  140. </ul>
  141. </li>
  142. <?php if( $lv == "admin" ){ ?>
  143. <li><a href="/phpmyadmin/" target="_blank">資料庫管理</a></li>
  144. <?php } ?>
  145. </ul>
  146. <!--導覽列左側根據是否有登入而有不同顯示-->
  147. <?php if($lv=="guest"){ ?>
  148. <form class="navbar-form navbar-right" role="form" method="post" action="">
  149. <div class=form-group>
  150. <input name="username" id="username" placeholder="帳號" class=form-control>
  151. </div>
  152. <div class=form-group>
  153. <input name="password" id="password" type=password placeholder="密碼" class=form-control>
  154. </div>
  155. <button type=submit class="btn btn-primary">登入</button>
  156. <a class="btn btn-info" href="signup.php" role=button>註冊</a>
  157. </form>
  158. <?php }else{ ?>
  159. <form class="navbar-form navbar-right" role="form">
  160. <font color="white">歡迎 <?php echo $nickname; ?> さん 
  161. <a class="btn btn-success" href="post.php" role=button>留言</a>
  162. <a class="btn btn-info" href="update.php" role=button>設定</a>
  163. <a class="btn btn-danger" href="?logout=true" role=button>登出</a></font>
  164. </form>
  165. <?php } ?>
  166. </div>
  167. </div>
  168. </nav>
  169. <div class=jumbotron>
  170. <div class=container>
  171. <div class="panel panel-default">
  172. <div id="comment_subject" class="panel-heading" >
  173. <h2 style="margin-left: 30px;">
  174. <small>#Author : </small>
  175. <?php if($row_RecComment["sex"]=="女"){ ?>
  176. <img src="/images/Female.svg" style="width: 30px; height: 30px; padding-bottom: 5px;">
  177. <?php }else{ ?>
  178. <img src="/images/Male.svg" style="width: 30px; height: 30px; padding-bottom: 5px;">
  179. <?php }
  180. echo $row_RecComment["nickname"];?> さん
  181. </h2>
  182. </div>
  183. <div class="panel-body">
  184. <div class="panel panel-default" style="margin: 20px 20px; padding-bottom: 10px;">
  185. <div class="panel-body">
  186. <div class="col-md-6">
  187. <h2><small>#Title : </small><?php echo $row_RecComment["subject"];?></h2>
  188. </div>
  189. <div id="comment_time" align="right" class="col-md-6">
  190. <h2><small>#Time : </small><?php echo $row_RecComment["time"]; ?></h2>
  191. </div>
  192. </div>
  193. </div>
  194. <div class="panel panel-default" style="margin: 20px 20px; padding: 0px 20px 0px;">
  195. <div class="panel-body">
  196. <h2><small>#content:</small></h2>
  197. <p><?php echo nl2br($row_RecComment["content"]);?></p>
  198. </div>
  199. </div>
  200. <div align="right" style="padding-right: 20px;">
  201. <!--根據權限顯示不同東西-->
  202. <?php if( $lv!="guest" ){ ?>
  203. <a class="btn btn-lg btn-success" href="recomment.php" role=button>回覆 &raquo;</a>
  204. <?php if ( $lv=="admin" || $row_RecComment["username"]==$username) { ?>
  205. <a class="btn btn-lg btn-primary" href="edit.php?id=<?php echo $id;?>" role=button>修改 &raquo;</a>
  206. <a class="btn btn-lg btn-danger" href="delete.php?id=<?php echo $id;?>" role=button>刪除 &raquo;</a>
  207. <?php } } ?>
  208. </div>
  209. </div>
  210. </div>
  211. </div>
  212. </div>
  213. <div class=container>
  214. <hr>
  215. <footer>
  216. <p>
  217. <!--根據權限顯示不同東西-->
  218. <?php if ( $lv == "admin"){ ?>
  219. <span class="label label-primary">管理員</span>
  220. <?php }elseif( $lv == "member"){ ?>
  221. <span class="label label-success">會員</span>
  222. <?php }else{ ?>
  223. <span class="label label-warning">訪客</span>
  224. <?php } ?>
  225. &copy; NoCopyright 2016
  226. </p>
  227. </footer>
  228. </div>
  229. <script src="https://use.typekit.net/ova0edr.js"></script>
  230. <script>try{Typekit.load({ async: true });}catch(e){}</script>
  231. <script src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js></script>
  232. <script src=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js></script>
  233. <script src=/Scripts/AssetsBS3/ie10-viewport-bug-workaround.js></script>
  234. </body>