Advertisement
tmen

coachHome.php

Jan 7th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.59 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>Roster</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>id</th><th>name</th><th># of excused</th><th># of unexcused</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. $stmt = $conn->prepare("SELECT * ");
  125.  
  126. // $stmt->execute();
  127. // set the resulting array to associative
  128.  
  129. /*$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  130. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v)
  131. {
  132. echo $v;
  133. }
  134.  
  135. */
  136. $stmt = $conn->prepare("SELECT id, name, excused_absences, unexcused_absences FROM tanay_xcatt_runners WHERE id>10");
  137. $stmt->execute();
  138.  
  139. // set the resulting array to associative
  140.  
  141. $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
  142. foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k => $v)
  143. {
  144. echo $v;
  145. }
  146. }
  147.  
  148. catch(PDOException $e)
  149. {
  150. echo "Error: " . $e->getMessage();
  151. }
  152.  
  153.  
  154.  
  155. $conn = null;
  156. echo "</table>";
  157. ?>
  158. </body>
  159. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement