PageRenderTime 65ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/delete.php

https://gitlab.com/jonz94/2016NCU_FreshWeb_HW
PHP | 113 lines | 100 code | 5 blank | 8 comment | 12 complexity | ddb1e5fb8e056294f318ce7474037343 MD5 | raw file
  1. <!--必須要先登入-->
  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_RecComment = "SELECT * FROM `comment` WHERE `id`=".$_GET["id"];
  12. $RecComment = mysql_query($query_RecComment);
  13. $row_RecComment = mysql_fetch_assoc($RecComment);
  14. /* 提取 user_id & permission */
  15. $query_RecUser = "SELECT `id`,`permission` FROM `user` WHERE `username`='".$username."'";
  16. $RecUser = mysql_query($query_RecUser);
  17. $row_RecUser = mysql_fetch_assoc($RecUser);
  18. // 確認此留言是否登入者的留言
  19. if( $row_RecUser["permission"] != "admin" && $row_RecComment["user_id"] != $row_RecUser["id"] ){ ?>
  20. <script type="text/javascript">
  21. window.alert("這不是你的留言!\n你將被移動至首頁");
  22. window.location.assign("index.php");
  23. </script>
  24. <?php
  25. }
  26. $query_RecNickname = "SELECT `nickname` FROM `user` WHERE `user`.`id` = ".$row_RecComment["user_id"];
  27. if(!$RecNickname=mysql_query($query_RecNickname)){ ?>
  28. <script type="text/javascript">
  29. window.alert("該留言不存在!\n將被轉移至首頁!");
  30. window.location.assign("index.php");
  31. </script>
  32. <?php
  33. }
  34. $row_RecNickname = mysql_fetch_assoc($RecNickname);
  35. }else{
  36. //尚未登入,轉到登入畫面 ?>
  37. <script type="text/javascript">
  38. window.alert("你尚未登入!");
  39. window.location.assign("login.php");
  40. </script>
  41. <?php
  42. }
  43. /* 執行刪除動作 */
  44. if(isset($_POST["action"])&&($_POST["action"]=="delete")){
  45. if( $row_RecUser["permission"] != "admin" && $row_RecComment["user_id"] != $_POST["id"] ){ ?>
  46. <script type="text/javascript">
  47. window.alert("這不是你的留言!\n你將被移動至首頁");
  48. window.location.assign("index.php");
  49. </script>
  50. <?php
  51. }else{
  52. $sql_query = "DELETE FROM `comment` WHERE `id`=".$_POST["id"];
  53. mysql_query($sql_query);
  54. //重新導向回到主畫面 ?>
  55. <script type="text/javascript">
  56. window.alert("刪除留言成功!");
  57. window.location.assign("index.php");
  58. </script>
  59. <?php
  60. }
  61. }
  62. ?>
  63. <!DOCTYPE html>
  64. <html lang="zh-Hant-TW">
  65. <head>
  66. <meta charset="utf-8">
  67. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  68. <meta name="viewport" content="width=device-width, initial-scale=1">
  69. <meta name="description" content="">
  70. <meta name="author" content="">
  71. <title>刪除留言</title>
  72. <link rel="icon" href="/images/icon.jpg">
  73. <link href="/css/bootstrap.min.css" rel="stylesheet">
  74. <link href="/css/index.css" rel="stylesheet">
  75. <script src="/js/ie-emulation-modes-warning.js"></script>
  76. </head>
  77. <body class="custom-signin">
  78. <div class="container">
  79. <form class="form-signin" role="form" method="post" action="">
  80. <h2 class="form-signin-heading">確定要刪除此留言?</h2>
  81. <label for=inputNickname class=sr-only>發文者</label>
  82. <div class="input-group">
  83. <span class="input-group-addon">發文者 </span>
  84. <input name="subject" id="subject" type="text" class="form-control" placeholder="<?php echo $row_RecNickname["nickname"]; ?>" readonly>
  85. </div><br>
  86. <label for=inputNickname class=sr-only>發文時間</label>
  87. <div class="input-group">
  88. <span class="input-group-addon">發文時間</span>
  89. <input name="subject" id="subject" type="text" class="form-control" placeholder="<?php echo $row_RecComment["time"]; ?>" readonly>
  90. </div><br>
  91. <label for=inputNickname class=sr-only>標題  </label>
  92. <div class="input-group">
  93. <span class="input-group-addon">標題  </span>
  94. <input name="subject" id="subject" type="text" class="form-control" value="<?php echo $row_RecComment["subject"];?>" readonly>
  95. </div>
  96. <div class="form-group">
  97. <textarea name="content" class="form-control" rows="10" id="content" disabled><?php echo $row_RecComment["content"];?></textarea>
  98. </div>
  99. <input name="id" type="hidden" id="id" value="<?php echo $row_RecComment["id"]?>"></input>
  100. <input name="action" type="hidden" id="action" value="delete"></input>
  101. <button class="btn btn-lg btn-danger btn-block" type="submit">刪除 Delete</button>
  102. <a class="btn btn-lg btn-success btn-block" href="index.php" role=button>取消 Cancel</a>
  103. </form>
  104. </div>
  105. <script src="https://use.typekit.net/ova0edr.js"></script>
  106. <script>try{Typekit.load({ async: true });}catch(e){}</script>
  107. <script src="/js/ie10-viewport-bug-workaround.js"></script>
  108. </body>