index.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <!-- Required meta tags -->
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7. <!-- Bootstrap CSS -->
  8. <link rel="stylesheet" href="//stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  9. <title>Racing Australia</title>
  10. </head>
  11. <body>
  12. <div class="container">
  13. <h1>Racing Australia</h1>
  14. <?php
  15. require_once 'dbconfig.php';
  16. $dsn = "pgsql:host=$host;port=5432;dbname=$db;user=$username;password=$password";
  17. try{
  18. // create a PostgreSQL database connection
  19. $conn = new PDO($dsn);
  20. // display a message if connected to the PostgreSQL successfully
  21. if($conn){
  22. echo "Connected to the <strong>$db</strong> database successfully!";
  23. }
  24. try {
  25. $date = new DateTime("now", new DateTimeZone('Australia/Melbourne'));
  26. } catch (Exception $e) {
  27. echo $e->getMessage();
  28. exit(1);
  29. }
  30. $query = sprintf("SELECT * FROM horses JOIN race_program
  31. ON horses.race_date = race_program.race_date
  32. AND horses.venue = race_program.venue
  33. AND horses.race = race_program.race
  34. WHERE horses.race_date >= %s
  35. ORDER BY horses.race_date, horses.venue, horses.race, horses.horse_no;", $conn->quote($date->format('Y-m-d')));
  36. $stmt = $conn->query($query);
  37. /*
  38. $r = $stmt->fetch(PDO::FETCH_ASSOC);
  39. print "<pre>" ;
  40. print_r($r);
  41. print "</pre>";
  42. */
  43. $query = sprintf("SELECT * FROM race_program
  44. WHERE race_date >= %s AND torn = TRUE;", $conn->quote($date->format('Y-m-d')));
  45. $stmt2 = $conn->query( $query );
  46. ?>
  47. <table class="table table-striped table-bordered">
  48. <caption>Races featured on Torn</caption>
  49. <thead>
  50. <tr>
  51. <th>venue</th>
  52. <th>state</th>
  53. <th>date</th>
  54. <th>race</th>
  55. <th>start</th>
  56. <th>utc></th>
  57. </tr>
  58. </thead>
  59. <tbody>
  60. <?php
  61. while ( $row = $stmt2->fetch( PDO::FETCH_ASSOC ) ) : ?>
  62. <tr>
  63. <!-- <td><?php // echo htmlspecialchars($row['id']); ?></td> -->
  64. <td><?php echo htmlspecialchars($row['venue']); ?></td>
  65. <td><?php echo htmlspecialchars($row['state']); ?></td>
  66. <td><?php echo htmlspecialchars($row['race_date']); ?></td>
  67. <td><?php echo htmlspecialchars($row['race']); ?></td>
  68. <td><?php echo htmlspecialchars(substr($row['start_time'], 0, -3)); ?></td>
  69. <td><?php $t = strtotime($row['utctime']); echo gmdate('H:i', $t); ?></td>
  70. </tr>
  71. <?php endwhile; ?>
  72. </tbody>
  73. \</table>
  74. <table class="table table-striped table-bordered">
  75. <?php
  76. $table_head = <<<TABLEHEAD
  77. <thead>
  78. <tr>
  79. <!-- <th>id</th> -->
  80. <th>venue</th>
  81. <th>state</th>
  82. <th>date</th>
  83. <th>race</th>
  84. <th>start</th>
  85. <th>utc</th>
  86. <th>horse</th>
  87. <th>torn</th>
  88. </tr>
  89. </thead>
  90. <tbody>
  91. TABLEHEAD;
  92. $table_foot = <<<TABLEFOOT
  93. </tbody>
  94. TABLEFOOT;
  95. echo( $table_head );
  96. $new_venue = '';
  97. $new_day = '';
  98. $img = '48px-Commons-emblem-success.svg.png';
  99. $img = <<<'TAG'
  100. <img alt="File:Commons-emblem-success.svg"
  101. src="//upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Commons-emblem-success.svg/48px-Commons-emblem-success.svg.png"
  102. width="24"
  103. height="24" />
  104. TAG;
  105. $head_displayed = False;
  106. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : ?>
  107. <?php
  108. if ( $new_day != '' ) {
  109. if ( $new_day != $row['race_date'] ) {
  110. echo '</table>';
  111. echo '<h4>' . htmlspecialchars($row['race_date']) . '</h4>';
  112. echo ' <table class="table table-striped table-bordered">';
  113. $new_day = $row['race_date'];
  114. $head_displayed = True;
  115. }
  116. } else {
  117. $new_day = $row['race_date'];
  118. }
  119. if ( $new_venue != '' ) {
  120. if ( $new_venue != $row['venue'] ) {
  121. echo $table_foot;
  122. echo $table_head;
  123. $new_venue = $row['venue'];
  124. }
  125. } else {
  126. $new_venue = $row['venue'];
  127. }
  128. ?>
  129. <tr>
  130. <!-- <td><?php // echo htmlspecialchars($row['id']); ?></td> -->
  131. <td><?php echo htmlspecialchars($row['venue']); ?></td>
  132. <td><?php echo htmlspecialchars($row['state']); ?></td>
  133. <td><?php echo htmlspecialchars($row['race_date']); ?></td>
  134. <td><?php echo htmlspecialchars($row['race']); ?></td>
  135. <td><?php echo htmlspecialchars(substr($row['start_time'], 0, -3)); ?></td>
  136. <td><?php $t = strtotime($row['utctime']); echo gmdate('H:i', $t); ?></td>
  137. <td><?php echo htmlspecialchars($row['horse_no'] . ' ' . $row['horse_display_name']); ?></td>
  138. <td><?php if ($row['torn']) { echo $img; }; ?></td>
  139. </tr>
  140. <?php endwhile; ?>
  141. </table>
  142. <?php
  143. echo $table_foot;
  144. }catch (PDOException $e){
  145. // report error message
  146. echo $e->getMessage();
  147. }
  148. ?>
  149. </div>
  150. <!-- Optional JavaScript -->
  151. <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  152. <script src="//code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  153. <script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  154. <script src="//stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  155. </body>
  156. </html>