tmen

runnerHome.php

Jan 7th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. <!doctype html>
  2. <?php
  3. session_start();
  4. if(isset($_SESSION['status'])) {
  5. echo "<br>currently logged in: " . $_SESSION["name"] . ".<br>";
  6. }
  7. else
  8. {
  9. session_destroy();
  10. header("Location: runnerLoginForm.html");
  11. }
  12. ?>
  13. <html>
  14. <head>
  15. <meta charset="utf-8">
  16. <title>Untitled Document</title>
  17. </head>
  18.  
  19. <body>
  20. <style>
  21. body, html {
  22. height: 100%;
  23. background-color: azure;
  24. font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  25. text-align: center;
  26. }
  27. div {
  28. border: 1px solid gray;
  29. padding: 8px;
  30. }
  31. h1 {
  32. text-align: center;
  33. text-transform: uppercase;
  34. color: #4CAF50;
  35. letter-spacing: 10px;
  36. text-size: 20px;
  37. }
  38. p {
  39. text-align: center;
  40. letter-spacing: 3px;
  41. }
  42. td, th {
  43. border: 1px solid green;
  44. padding: 0.5rem;
  45. text-align: center;
  46. }
  47. table {
  48. border-collapse: collapse;
  49. }
  50. a:link, a:visited {
  51. background-color: #4CAF50;
  52. color: white;
  53. padding: 14px 25px;
  54. text-align: center;
  55. text-decoration: none;
  56. display: inline-block;
  57. }
  58. a:hover, a:active {
  59. background-color: #4CAF50;
  60. }
  61. </style>
  62. <h1>XC Attendance
  63. </h1>
  64. <p>
  65. <a href="runnerHome.php">Your Log</a>
  66. <a href="runnerAbsencePostForm.html">Post your absence</a>
  67. <a href="runnerHome.php?hello=true">Logout</a>
  68. </p>
  69. <br>
  70. <h1>Dates Absent</h1>
  71. <br>
  72. <?php
  73. $name = $_SESSION["name"];
  74.  
  75. function logout()
  76. {
  77. session_destroy();
  78.  
  79. // echo "refreshing";
  80.  
  81. header("Location: runnerLoginForm.html");
  82. }
  83.  
  84. if (isset($_GET['hello']))
  85. {
  86. logout();
  87.  
  88. // setcookie("user", "", time() - 3600);
  89.  
  90. }
  91.  
  92. echo "<table align='center'>";
  93. echo "<tr><th>id</th><th>absence_date</th><th>explanation</th><th>time</th><th>review status</th><th>review date</th></tr>";
  94. class TableRows extends RecursiveIteratorIterator
  95.  
  96. {
  97. function __construct($it)
  98. {
  99. parent::__construct($it, self::LEAVES_ONLY);
  100. }
  101.  
  102. function current()
  103. {
  104. return "<td style='width:150px;border:1px solid green;'>" . parent::current() . "</td>";
  105. }
  106.  
  107. function beginChildren()
  108. {
  109. echo "<tr>";
  110. }
  111.  
  112. function endChildren()
  113. {
  114. echo "</tr>" . "\n";
  115. }
  116. }
  117.  
  118. $servername = "localhost";
  119. $username = "playground18";
  120. $password = "Cdz5SOVrY2p8fnWS";
  121. $dbname = "playground18";
  122.  
  123. try
  124. {
  125. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  126. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  127. $stmt = $conn->prepare("SELECT * ");
  128.  
  129. // $stmt->execute();
  130. // set the resulting array to associative
  131.  
  132. /*$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  133. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v)
  134. {
  135. echo $v;
  136. }
  137.  
  138. */
  139. $sql = "SELECT count(*) FROM `tanay_auction_items` WHERE id>0";
  140. $result = $conn->prepare($sql);
  141. $result->execute();
  142. $number_of_rows = $result->fetchColumn();
  143. $stmt = $conn->prepare("SELECT id, absence_date, explanation, time, review_status, review_date FROM tanay_xcatt_absences WHERE person='$name'");
  144. $stmt->execute();
  145.  
  146. // set the resulting array to associative
  147.  
  148. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  149. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k => $v)
  150. {
  151.  
  152. echo $v;
  153. }
  154.  
  155. }
  156.  
  157. catch(PDOException $e)
  158. {
  159. echo "Error: " . $e->getMessage();
  160. }
  161.  
  162.  
  163.  
  164. $conn = null;
  165. echo "</table>";
  166.  
  167. ?>
  168. </body>
  169. </html>
Add Comment
Please, Sign In to add comment