PageRenderTime 129ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/todolist.php

https://gitlab.com/jonz94/2016NCU_FreshWeb_HW
PHP | 187 lines | 171 code | 3 blank | 13 comment | 15 complexity | 7115e4cb85c28720cbe7e65e84c2fd7f MD5 | raw file
  1. <!-- 會員系統 PHP CODE -->
  2. <?php
  3. header("Content-Type: text/html; charset=utf-8");
  4. require_once("connMysql.php");
  5. //啟用 SESSION
  6. session_start();
  7. //檢查是否經過登入
  8. if(isset($_SESSION["loginUser"]) && ($_SESSION["loginUser"]!="")){
  9. //有登入
  10. $username = $_SESSION["loginUser"];
  11. $query_RecUser = "SELECT `nickname`,`permission` FROM `user` WHERE `username`='".$username."'";
  12. $RecUser = mysql_query($query_RecUser);
  13. $row_RecUser = mysql_fetch_assoc($RecUser);
  14. $nickname = $row_RecUser["nickname"];
  15. //帳號等級為 member
  16. if($row_RecUser["permission"]=="member"){
  17. $lv="member";
  18. //帳號等級為 admin
  19. }else{
  20. $lv="admin";
  21. }
  22. //沒登入、為 guest
  23. }else{
  24. $lv="guest";
  25. }
  26. //執行會員登入
  27. if(isset($_POST["username"]) && isset($_POST["password"])){
  28. //繫結登入會員資料
  29. $query_RecLogin = "SELECT * FROM `user` WHERE `username`='".$_POST["username"]."'";
  30. $RecLogin = mysql_query($query_RecLogin);
  31. //取出帳號密碼的值
  32. $row_RecLogin=mysql_fetch_assoc($RecLogin);
  33. $username = $row_RecLogin["username"];
  34. //比對密碼,若登入成功則呈現登入狀態
  35. if(md5($_POST["password"])==$row_RecLogin["password"]){
  36. //設定登入者的名稱及等級
  37. $_SESSION["loginUser"]=$username;
  38. //登入後重新載入畫面 ?>
  39. <script type="text/javascript">
  40. window.alert("登入成功!");
  41. window.location.assign("todolist.php");
  42. </script>
  43. <?php
  44. }else{?>
  45. <script type="text/javascript">
  46. window.alert("錯誤的帳號或密碼! 請重新登入!\n將被轉移至登入畫面!");
  47. window.location.assign("login.php");
  48. </script>
  49. <?php
  50. }
  51. }
  52. //執行登出動作
  53. if(isset($_GET["logout"]) && ($_GET["logout"]=="true")){
  54. unset($_SESSION["loginUser"]);
  55. header("Location: todolist.php");
  56. }
  57. ?>
  58. <!DOCTYPE html>
  59. <html lang="zh-Hant-TW">
  60. <head>
  61. <meta charset="utf-8">
  62. <meta http-equiv=X-UA-Compatible content="IE=edge">
  63. <meta name=viewport content="width=device-width, initial-scale=1">
  64. <meta name=description content="">
  65. <meta name=author content="">
  66. <link rel="icon" href="/images/icon.jpg">
  67. <title>備忘錄(ver. ul)</title>
  68. <link href="/css/bootstrap.min.css" rel="stylesheet">
  69. <link href="/css/index.css" rel="stylesheet">
  70. <!--[if lt IE 9]><script src=~/Scripts/AssetsBS3/ie8-responsive-file-warning.js></script><![endif]-->
  71. <script src="/js/ie-emulation-modes-warning.js"></script>
  72. <!--[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]-->
  73. </head>
  74. <body class="custom-homepage">
  75. <nav class="navbar navbar-inverse navbar-fixed-top" role=navigation>
  76. <div class=container>
  77. <div class=navbar-header>
  78. <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>
  79. </div>
  80. <div id=navbar class="navbar-collapse collapse">
  81. <ul class="nav navbar-nav">
  82. <li><a href="index.php#">留言板</a></li>
  83. <li><a href="about.php">關於此站</a></li>
  84. <li class="dropdown active"><a href="./" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">To Do List<span class="caret"></span></a>
  85. <ul class="dropdown-menu dropdown-inverse" role="menu">
  86. <li class="active"><a href="#">ver. ul</a></li>
  87. <li><a href="todolist2.php">ver. table</a></li>
  88. <li><a href="todolist3.php">ver. div</a></li>
  89. </ul>
  90. </li>
  91. <li class="dropdown"><a href="./" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">網站地圖<span class="caret"></span></a>
  92. <ul class="dropdown-menu dropdown-inverse" role="menu">
  93. <li class="dropdown-header">留言板</li>
  94. <li><a href="index.php#">觀看留言</a></li>
  95. <li><a href="post.php">發表留言</a></li>
  96. <li class="divider"></li>
  97. <li class="dropdown-header">To Do List</a></li>
  98. <li><a href="#">ver. ul</a></li>
  99. <li><a href="todolist2.php">ver. table</a></li>
  100. <li><a href="todolist3.php">ver. div</a></li>
  101. <li class="divider"></li>
  102. <li class="dropdown-header">會員相關</li>
  103. <!--下拉式選單選項根據是否有登入而有不同顯示-->
  104. <?php if($lv=="guest"){ ?>
  105. <li><a href="login.php">登入</a></li>
  106. <li><a href="signup.php">註冊</a></li>
  107. <?php }else{ ?>
  108. <li><a href="update.php">更新資料</a></li>
  109. <li><a href="?logout=true">登出</a></li>
  110. <?php } ?>
  111. </ul>
  112. </li>
  113. <?php if( $lv == "admin" ){ ?>
  114. <li><a href="/phpmyadmin/" target="_blank">資料庫管理</a></li>
  115. <?php } ?>
  116. </ul>
  117. <!--導覽列左側根據是否有登入而有不同顯示-->
  118. <?php if($lv=="guest"){ ?>
  119. <form class="navbar-form navbar-right" role="form" method="post" action="">
  120. <div class=form-group>
  121. <input name="username" id="username" placeholder="帳號" class=form-control>
  122. </div>
  123. <div class=form-group>
  124. <input name="password" id="password" type=password placeholder="密碼" class=form-control>
  125. </div>
  126. <button type=submit class="btn btn-primary">登入</button>
  127. <a class="btn btn-info" href="signup.php" role=button>註冊</a>
  128. </form>
  129. <?php }else{ ?>
  130. <form class="navbar-form navbar-right" role="form">
  131. <font color="white">歡迎 <?php echo $nickname; ?> さん 
  132. <a class="btn btn-info" href="update.php" role=button>設定</a>
  133. <a class="btn btn-danger" href="?logout=true" role=button>登出</a></font>
  134. </form>
  135. <?php } ?>
  136. </div>
  137. </div>
  138. </nav>
  139. <div class=jumbotron>
  140. <div class=container>
  141. <h1>To Do List <small>(ver. ul)</small></h1>
  142. <p>備忘錄です</p><br>
  143. </div>
  144. </div>
  145. <div class=container>
  146. <div class=row>
  147. <div class=col-md-4></div>
  148. <div class=col-md-4>
  149. <div class="panel panel-default" align="center" style="padding: 40px 60px 30px;">
  150. <div class="row">
  151. <div class="input-group">
  152. <input type="text" class="form-control" id="userInput" placeholder="要做的事...">
  153. <span class="input-group-btn">
  154. <button type="button" class="btn btn-success" id="add">新增</button>
  155. </span>
  156. </div>
  157. </div>
  158. <br>
  159. <ul id="toDoList" style="list-style-type:none"></ul>
  160. </div>
  161. </div>
  162. <div class=col-md-4></div>
  163. </div>
  164. <hr>
  165. <footer>
  166. <p>
  167. <?php if ( $lv == "admin"){ ?>
  168. <span class="label label-primary">管理員</span>
  169. <?php }elseif( $lv == "member"){ ?>
  170. <span class="label label-success">會員</span>
  171. <?php }else{ ?>
  172. <span class="label label-warning">訪客</span>
  173. <?php } ?>
  174. &copy; NoCopyright 2016
  175. </p>
  176. </footer>
  177. </div>
  178. <script src="https://use.typekit.net/ova0edr.js"></script>
  179. <script>try{Typekit.load({ async: true });}catch(e){}</script>
  180. <script src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js></script>
  181. <script src=https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js></script>
  182. <script src=/Scripts/AssetsBS3/ie10-viewport-bug-workaround.js></script>
  183. <script src=/js/to-do-list.js></script>
  184. </body>