source: trunk/Modules/Ride/PageRideList.php

Last change on this file was 8, checked in by chronos, 18 months ago
  • Modified: Updated Common package.
  • Modified: Form types made as separate FormManager package.
  • Fixed: PHP 8.1 support.
File size: 3.5 KB
Line 
1<?php
2
3class PageRideList extends Page
4{
5 function Show(): string
6 {
7 if (array_key_exists('from', $_GET)) $PlaceFrom = $_GET['from'];
8 else $PlaceFrom = '';
9 if (array_key_exists('to', $_GET)) $PlaceTo = $_GET['to'];
10 else $PlaceTo = '';
11 if (array_key_exists('time', $_GET)) $Time = $_GET['time'];
12 else $Time = '';
13 $Output = '<table style="width: 100%"><tr><td style="text-align: center;">'.
14 '<form style="display: inline;" method="get" action="'.$this->System->Link('/').'">'.
15 'Odkud: <input type="text" name="from" value="'.$PlaceFrom.'"/> '.
16 'Kam: <input type="text" name="to" value="'.$PlaceTo.'"/> '.
17 'Čas: <input type="text" name="time" value="'.$Time.'"/> '.
18 '<input type="submit" value="Hledat"/>'.
19 '</form></td></tr></table>';
20 if (array_key_exists('from', $_GET) and array_key_exists('to', $_GET)) {
21 $Output .= $this->ShowRides($_GET['from'], $_GET['to']);
22 } else $Output .= $this->ShowRides('', '');
23 return $Output;
24 }
25
26 function ShowRides($PlaceFrom, $PlaceTo)
27 {
28 $Output = '<h3>Jízdy:</h3>';
29 $Output .= '<table>';
30 $Query = 'SELECT Ride.Id, Ride.SeatCount, User.Name AS DriverName, User.BirthDate, '.
31 'CONCAT(CarManufacturer.Name, " ", CarModel.Name) AS CarName ';
32 if ((trim($PlaceFrom) != '') and (trim($PlaceTo != '')))
33 $Query .= ', (SELECT COALESCE(MAX(RideStop.PassengerCount), 0) FROM RideStop '.
34 'WHERE (RideStop.Ride=Ride.Id) AND (RideStop.Sequence > RideStopFrom.Sequence) AND '.
35 '(RideStop.Sequence <= RideStopTo.Sequence)) AS PassengerCount ';
36 else
37 $Query .= ', (SELECT COALESCE(MAX(RideStop.PassengerCount), 0) FROM RideStop '.
38 'WHERE (RideStop.Ride=Ride.Id)) AS PassengerCount ';
39
40 $Query .= 'FROM Ride '.
41 'LEFT JOIN Car ON Car.Id = Ride.Car '.
42 'LEFT JOIN CarModel ON CarModel.Id = Car.Model '.
43 'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '.
44 'LEFT JOIN User ON User.Id=Ride.Driver ';
45 if ((trim($PlaceFrom) != '') and (trim($PlaceTo != '')))
46 $Query .= 'JOIN RideStop AS RideStopFrom ON (RideStopFrom.Ride = Ride.Id) AND (RideStopFrom.Place LIKE "%'.$PlaceFrom.'%") '.
47 'JOIN RideStop AS RideStopTo ON (RideStopTo.Ride = Ride.Id) AND (RideStopTo.Place LIKE "%'.$PlaceTo.'%") '.
48 'WHERE (RideStopFrom.Sequence < RideStopTo.Sequence)';
49 $Query .= 'LIMIT 10';
50 $DbResult = $this->Database->query($Query);
51 while ($DbRow = $DbResult->fetch_assoc())
52 {
53 $Stops = array();
54 $Price = 0;
55 $DbResult2 = $this->Database->query('SELECT * FROM RideStop WHERE Ride='.$DbRow['Id'].' ORDER BY Sequence');
56 while ($DbRow2 = $DbResult2->fetch_assoc())
57 {
58 $Stops[] = $DbRow2['Place'];
59 $Price += $DbRow2['Price'];
60 }
61
62 if ($DbRow['BirthDate'] != '') $Age = ' ('.round((time() - MysqlDateToTime($DbRow['BirthDate'])) / (3600*24*364.25)).' let)';
63 else $Age = '';
64 $Output .= '<tr><td>Řidič:</td><td>'.$DbRow['DriverName'].$Age.'</td>'.
65 '<td colspan="4"><a href="'.$this->System->Link('/jizda/?id='.$DbRow['Id'].'&from='.$PlaceFrom.'&to='.$PlaceTo).'">Ukázat</a></td></tr>'.
66 '<tr><td>Trasa:</td><td>'.implode(' → ', $Stops).'</td></tr>'.
67 '<tr><td>Cena:</td><td>'.$Price.' Kč</td></tr>'.
68 '<tr><td>Volných míst:</td><td>'.($DbRow['SeatCount'] - $DbRow['PassengerCount']).'</td></tr>'.
69 '<tr><td>Auto:</td><td>'.$DbRow['CarName'].'</td></tr>'.
70 '<tr><td>&nbsp;</td></tr>';
71 }
72 $Output .= '</table>';
73
74 return $Output;
75 }
76}
Note: See TracBrowser for help on using the repository browser.