index.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. <h2>Racing Australia</h2>
  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
  45. ORDER BY race_date, venue, race;", $conn->quote($date->format('Y-m-d')));
  46. $stmt2 = $conn->query( $query );
  47. ?>
  48. <nav class="nav nav-tabs" style="margin: 24px 0;">
  49. <a class="nav-link active" data-toggle="tab" href="#scratchings">Scratchings</a>
  50. <a class="nav-link" data-toggle="tab" href="#tornraces">Races on Torn</a>
  51. <a class="nav-link" data-toggle="tab" href="#allraces">All races</a>
  52. </nav>
  53. <div class="tab-content">
  54. <div class="tab-pane container fade" id="tornraces">
  55. <h4>Races featured on Torn</h4>
  56. <table class="table table-striped table-bordered">
  57. <caption>Races featured on Torn</caption>
  58. <thead>
  59. <tr>
  60. <th>venue</th>
  61. <th>state</th>
  62. <th>date</th>
  63. <th>race</th>
  64. <th>start</th>
  65. <th>utc</th>
  66. </tr>
  67. </thead>
  68. <tbody>
  69. <?php
  70. while ( $row = $stmt2->fetch( PDO::FETCH_ASSOC ) ) : ?>
  71. <tr>
  72. <!-- <td><?php // echo htmlspecialchars($row['id']); ?></td> -->
  73. <td><?php echo htmlspecialchars($row['venue']); ?></td>
  74. <td><?php echo htmlspecialchars($row['state']); ?></td>
  75. <td><?php echo htmlspecialchars($row['race_date']); ?></td>
  76. <td><?php echo htmlspecialchars($row['race']); ?></td>
  77. <td><?php echo htmlspecialchars(substr($row['start_time'], 0, -3)); ?></td>
  78. <td><?php $t = strtotime($row['utctime']); echo gmdate('H:i', $t); ?></td>
  79. </tr>
  80. <?php endwhile; ?>
  81. </tbody>
  82. </table>
  83. </div>
  84. <div class="tab-pane container fade" id="allraces">
  85. <?php
  86. $query = sprintf("SELECT * FROM race_program
  87. WHERE race_date >= %s ORDER BY utctime;", $conn->quote($date->format('Y-m-d')));
  88. $stmt3 = $conn->query( $query );
  89. ?>
  90. <h4>All races featured on Racing Australia</h4>
  91. <table class="table table-striped table-bordered">
  92. <caption>All races</caption>
  93. <thead>
  94. <tr>
  95. <th>venue</th>
  96. <th>state</th>
  97. <th>date</th>
  98. <th>race</th>
  99. <th>start</th>
  100. <th>utc</th>
  101. </tr>
  102. </thead>
  103. <tbody>
  104. <?php
  105. while ( $row = $stmt3->fetch( PDO::FETCH_ASSOC ) ) : ?>
  106. <tr>
  107. <!-- <td><?php // echo htmlspecialchars($row['id']); ?></td> -->
  108. <td><?php echo htmlspecialchars($row['venue']); ?></td>
  109. <td><?php echo htmlspecialchars($row['state']); ?></td>
  110. <td><?php echo htmlspecialchars($row['race_date']); ?></td>
  111. <td><?php echo htmlspecialchars($row['race']); ?></td>
  112. <td><?php echo htmlspecialchars(substr($row['start_time'], 0, -3)); ?></td>
  113. <td><?php $t = strtotime($row['utctime']); echo gmdate('H:i', $t); ?></td>
  114. </tr>
  115. <?php endwhile; ?>
  116. </tbody>
  117. </table>
  118. </div>
  119. <div class="tab-pane container active" id="scratchings">
  120. <h4>Scratchings</h4>
  121. <table class="table table-striped table-bordered">
  122. <?php
  123. $table_head = <<<TABLEHEAD
  124. <thead>
  125. <tr>
  126. <!-- <th>id</th> -->
  127. <th>venue</th>
  128. <th>state</th>
  129. <th>date</th>
  130. <th>race</th>
  131. <th>start</th>
  132. <th>utc</th>
  133. <th>horse</th>
  134. <th>torn</th>
  135. </tr>
  136. </thead>
  137. <tbody>
  138. TABLEHEAD;
  139. $table_foot = <<<TABLEFOOT
  140. </tbody>
  141. TABLEFOOT;
  142. echo( $table_head );
  143. $new_venue = '';
  144. $new_day = '';
  145. $img = '48px-Commons-emblem-success.svg.png';
  146. $img = <<<'TAG'
  147. <img alt="File:Commons-emblem-success.svg"
  148. src="//upload.wikimedia.org/wikipedia/commons/thumb/3/3f/Commons-emblem-success.svg/48px-Commons-emblem-success.svg.png"
  149. width="24"
  150. height="24" />
  151. TAG;
  152. $head_displayed = False;
  153. while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : ?>
  154. <?php
  155. if ( $new_day != '' ) {
  156. if ( $new_day != $row['race_date'] ) {
  157. echo '</table>';
  158. echo '<h4>' . htmlspecialchars($row['race_date']) . '</h4>';
  159. echo ' <table class="table table-striped table-bordered">';
  160. $new_day = $row['race_date'];
  161. $head_displayed = True;
  162. }
  163. } else {
  164. $new_day = $row['race_date'];
  165. }
  166. if ( $new_venue != '' ) {
  167. if ( $new_venue != $row['venue'] ) {
  168. echo $table_foot;
  169. echo $table_head;
  170. $new_venue = $row['venue'];
  171. }
  172. } else {
  173. $new_venue = $row['venue'];
  174. }
  175. ?>
  176. <tr>
  177. <!-- <td><?php // echo htmlspecialchars($row['id']); ?></td> -->
  178. <td><?php echo htmlspecialchars($row['venue']); ?></td>
  179. <td><?php echo htmlspecialchars($row['state']); ?></td>
  180. <td><?php echo htmlspecialchars($row['race_date']); ?></td>
  181. <td><?php echo htmlspecialchars($row['race']); ?></td>
  182. <td><?php echo htmlspecialchars(substr($row['start_time'], 0, -3)); ?></td>
  183. <td><?php $t = strtotime($row['utctime']); echo gmdate('H:i', $t); ?></td>
  184. <td><?php echo htmlspecialchars($row['horse_no'] . ' ' . $row['horse_display_name']); ?></td>
  185. <td><?php if ($row['torn']) { echo $img; }; ?></td>
  186. </tr>
  187. <?php endwhile; ?>
  188. </table>
  189. <?php
  190. echo $table_foot;
  191. }catch (PDOException $e){
  192. // report error message
  193. echo $e->getMessage();
  194. }
  195. ?>
  196. </div>
  197. </div>
  198. </div>
  199. <!-- Optional JavaScript -->
  200. <!-- jQuery first, then Popper.js, then Bootstrap JS -->
  201. <script src="//code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  202. <script src="//cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
  203. <script src="//stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  204. </body>
  205. </html>