tmen

coachUnreviewedAbsences.php

Jan 7th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. <!doctype html>
  2. <?php
  3. session_start();
  4. if(isset($_SESSION['status']) && $_SESSION['type']==="coach") {
  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. .content {
  22. margin: auto;
  23. }
  24. body, html {
  25. height: 100%;
  26. background-color: azure;
  27. font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  28. text-align: center;
  29. }
  30. div {
  31. border: 1px solid gray;
  32. padding: 8px;
  33. }
  34. h1 {
  35. text-align: center;
  36. text-transform: uppercase;
  37. color: #4CAF50;
  38. letter-spacing: 10px;
  39. text-size: 20px;
  40. }
  41. p {
  42. text-align: center;
  43. letter-spacing: 3px;
  44. }
  45. td, th {
  46. border: 1px solid green;
  47. padding: 0.5rem;
  48. text-align: center;
  49. }
  50. table {
  51. border-collapse: collapse;
  52. text-align: center;
  53. }
  54. a:link, a:visited {
  55. background-color: #4CAF50;
  56. color: white;
  57. padding: 14px 25px;
  58. text-align: center;
  59. text-decoration: none;
  60. display: inline-block;
  61. }
  62. a:hover, a:active {
  63. background-color: #4CAF50;
  64. }
  65. </style>
  66. </style>
  67. <h1>XC Attendance
  68. </h1>
  69. <h2>Unreviewed Absences</h2>
  70. <p>
  71. <a href="coachHome.php">Roster</a>
  72. <a href="coachUnreviewedAbsences.php">Unreviewed Absences</a>
  73. <a href="coachReviewedAbsences.php">Reviewed Absences</a>
  74. <a href="coachHome.php?hello=true">Logout</a>
  75. </p>
  76. <br>
  77. <?php
  78. function logout() {
  79. session_destroy();
  80. //echo "refreshing";
  81. header("Location: runnerLoginForm.html");
  82. }
  83. if (isset($_GET['hello']))
  84. {
  85. logout();
  86. //setcookie("user", "", time() - 3600);
  87. }
  88.  
  89. echo "<table align='center'>";
  90. echo "<tr><th>excuse</th><th>deny</th><th>person</th><th>absence_date</th><th>explanation</th><th>Time of submission</th><th>review status</th><th>review date</th></tr>";
  91. class TableRows extends RecursiveIteratorIterator
  92.  
  93. {
  94. function __construct($it)
  95. {
  96. parent::__construct($it, self::LEAVES_ONLY);
  97. }
  98.  
  99. function current()
  100. {
  101. return "<td style='width:150px;border:1px solid green;'>" . parent::current() . "</td>";
  102. }
  103.  
  104. function beginChildren()
  105. {
  106. echo "<tr>";
  107. }
  108.  
  109. function endChildren()
  110. {
  111. echo "</tr>" . "\n";
  112. }
  113. }
  114.  
  115. $servername = "localhost";
  116. $username = "playground18";
  117. $password = "Cdz5SOVrY2p8fnWS";
  118. $dbname = "playground18";
  119.  
  120. try
  121. {
  122. $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  123. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  124. $sql = "SELECT count(*) FROM `tanay_xcatt_absences` WHERE id>0";
  125. $result = $conn->prepare($sql);
  126. $result->execute();
  127. $number_of_rows = $result->fetchColumn();
  128. for ($x = 1; $x <= $number_of_rows; $x++)
  129. {
  130.  
  131. // $stmt->execute();
  132. // set the resulting array to associative
  133.  
  134. /*$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  135. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v)
  136. {
  137. echo $v;
  138. }
  139.  
  140. */
  141. $ifDquery = "SELECT deleted FROM `tanay_xcatt_absences` WHERE id=$x";
  142. $deleteR = $conn->prepare($ifDquery);
  143. $deleteR->execute();
  144. $deleted = $deleteR->fetchColumn();
  145. if ($deleted == 0)
  146. {
  147. $ifPquery = "SELECT person FROM `tanay_xcatt_absences` WHERE id=$x";
  148. $P = $conn->prepare($ifPquery);
  149. $P->execute();
  150. $person = $P->fetchColumn();
  151. if (strlen($person) == 0)
  152. {
  153. $sql = "UPDATE tanay_xcatt_absences SET deleted = 1 WHERE id='$x'";
  154. $conn->exec($sql);
  155. }
  156. }
  157. $ifDquery = "SELECT deleted FROM `tanay_xcatt_absences` WHERE id=$x";
  158. $deleteR = $conn->prepare($ifDquery);
  159. $deleteR->execute();
  160. $deleted = $deleteR->fetchColumn();
  161. $ifRquery = "SELECT review_status FROM `tanay_xcatt_absences` WHERE id=$x";
  162. $Rstatus = $conn->prepare($ifRquery);
  163. $Rstatus->execute();
  164. $R = $Rstatus->fetchColumn();
  165. if ($deleted == 0 && $R === "unreviewed")
  166. {
  167. $stmt = $conn->prepare("SELECT id, person, absence_date, explanation, time, review_status, review_date FROM tanay_xcatt_absences WHERE id='$x'");
  168. $stmt->execute();
  169.  
  170. // set the resulting array to associative
  171.  
  172. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  173. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k => $v)
  174. {
  175. if ($k === "id")
  176. {
  177.  
  178. echo "<form action='coachReviewExcuse.php' method='get'>";
  179. echo "<td><input name='ID' type='hidden' value='$x'><input type='submit' value='excuse'></form></td>";
  180. echo "<form action='coachReviewDeny.php' method='get'>";
  181. echo "<td><input name='ID' type='hidden' value='$x'><input type='submit' value='deny'></form></td>";
  182. }
  183.  
  184. else
  185. {
  186. echo $v;
  187. }
  188. }
  189. }
  190. }
  191. }
  192.  
  193. catch(PDOException $e)
  194. {
  195. echo "Error: " . $e->getMessage();
  196. }
  197.  
  198.  
  199.  
  200. $conn = null;
  201. echo "</table>";
  202. ?>
  203. </body>
  204. </html>
Add Comment
Please, Sign In to add comment