index.php 7.4 KB

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