Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <?php
- session_start();
- if(isset($_SESSION['status']) && $_SESSION['type']==="coach") {
- echo "<br>currently logged in: " . $_SESSION["name"] . ".<br>";
- }
- else
- {
- session_destroy();
- header("Location: runnerLoginForm.html");
- }
- ?>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Untitled Document</title>
- </head>
- <body>
- <style>
- .content {
- margin: auto;
- }
- body, html {
- height: 100%;
- background-color: azure;
- font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
- text-align: center;
- }
- div {
- border: 1px solid gray;
- padding: 8px;
- }
- h1 {
- text-align: center;
- text-transform: uppercase;
- color: #4CAF50;
- letter-spacing: 10px;
- text-size: 20px;
- }
- p {
- text-align: center;
- letter-spacing: 3px;
- }
- td, th {
- border: 1px solid green;
- padding: 0.5rem;
- text-align: center;
- }
- table {
- border-collapse: collapse;
- text-align: center;
- }
- a:link, a:visited {
- background-color: #4CAF50;
- color: white;
- padding: 14px 25px;
- text-align: center;
- text-decoration: none;
- display: inline-block;
- }
- a:hover, a:active {
- background-color: #4CAF50;
- }
- </style>
- </style>
- <h1>XC Attendance
- </h1>
- <h2>Unreviewed Absences</h2>
- <p>
- <a href="coachHome.php">Roster</a>
- <a href="coachUnreviewedAbsences.php">Unreviewed Absences</a>
- <a href="coachReviewedAbsences.php">Reviewed Absences</a>
- <a href="coachHome.php?hello=true">Logout</a>
- </p>
- <br>
- <?php
- function logout() {
- session_destroy();
- //echo "refreshing";
- header("Location: runnerLoginForm.html");
- }
- if (isset($_GET['hello']))
- {
- logout();
- //setcookie("user", "", time() - 3600);
- }
- echo "<table align='center'>";
- 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>";
- class TableRows extends RecursiveIteratorIterator
- {
- function __construct($it)
- {
- parent::__construct($it, self::LEAVES_ONLY);
- }
- function current()
- {
- return "<td style='width:150px;border:1px solid green;'>" . parent::current() . "</td>";
- }
- function beginChildren()
- {
- echo "<tr>";
- }
- function endChildren()
- {
- echo "</tr>" . "\n";
- }
- }
- $servername = "localhost";
- $username = "playground18";
- $password = "Cdz5SOVrY2p8fnWS";
- $dbname = "playground18";
- try
- {
- $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $sql = "SELECT count(*) FROM `tanay_xcatt_absences` WHERE id>0";
- $result = $conn->prepare($sql);
- $result->execute();
- $number_of_rows = $result->fetchColumn();
- for ($x = 1; $x <= $number_of_rows; $x++)
- {
- // $stmt->execute();
- // set the resulting array to associative
- /*$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
- foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v)
- {
- echo $v;
- }
- */
- $ifDquery = "SELECT deleted FROM `tanay_xcatt_absences` WHERE id=$x";
- $deleteR = $conn->prepare($ifDquery);
- $deleteR->execute();
- $deleted = $deleteR->fetchColumn();
- if ($deleted == 0)
- {
- $ifPquery = "SELECT person FROM `tanay_xcatt_absences` WHERE id=$x";
- $P = $conn->prepare($ifPquery);
- $P->execute();
- $person = $P->fetchColumn();
- if (strlen($person) == 0)
- {
- $sql = "UPDATE tanay_xcatt_absences SET deleted = 1 WHERE id='$x'";
- $conn->exec($sql);
- }
- }
- $ifDquery = "SELECT deleted FROM `tanay_xcatt_absences` WHERE id=$x";
- $deleteR = $conn->prepare($ifDquery);
- $deleteR->execute();
- $deleted = $deleteR->fetchColumn();
- $ifRquery = "SELECT review_status FROM `tanay_xcatt_absences` WHERE id=$x";
- $Rstatus = $conn->prepare($ifRquery);
- $Rstatus->execute();
- $R = $Rstatus->fetchColumn();
- if ($deleted == 0 && $R === "unreviewed")
- {
- $stmt = $conn->prepare("SELECT id, person, absence_date, explanation, time, review_status, review_date FROM tanay_xcatt_absences WHERE id='$x'");
- $stmt->execute();
- // set the resulting array to associative
- $result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
- foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k => $v)
- {
- if ($k === "id")
- {
- echo "<form action='coachReviewExcuse.php' method='get'>";
- echo "<td><input name='ID' type='hidden' value='$x'><input type='submit' value='excuse'></form></td>";
- echo "<form action='coachReviewDeny.php' method='get'>";
- echo "<td><input name='ID' type='hidden' value='$x'><input type='submit' value='deny'></form></td>";
- }
- else
- {
- echo $v;
- }
- }
- }
- }
- }
- catch(PDOException $e)
- {
- echo "Error: " . $e->getMessage();
- }
- $conn = null;
- echo "</table>";
- ?>
- </body>
- </html>
Add Comment
Please, Sign In to add comment