index.php 7.2 KB

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