1 | <?php
|
---|
2 |
|
---|
3 | class PageRideDetail extends Page
|
---|
4 | {
|
---|
5 | function ShowDetail()
|
---|
6 | {
|
---|
7 | $RideId = $_GET['id'];
|
---|
8 | $DbResult = $this->Database->query('SELECT Ride.Details, Ride.Id, Ride.SeatCount, '.
|
---|
9 | 'RideStopFrom.Id AS RideStopFromId, RideStopTo.Id AS RideStopToId, '.
|
---|
10 | '(SELECT Name FROM User WHERE User.Id=Ride.Driver) AS DriverName, '.
|
---|
11 | 'CONCAT(CarManufacturer.Name, " ", CarModel.Name) AS CarName FROM Ride '.
|
---|
12 | 'JOIN RideStop AS RideStopFrom ON (RideStopFrom.Ride = Ride.Id) AND (RideStopFrom.Place LIKE "%'.$_GET['from'].'%") '.
|
---|
13 | 'JOIN RideStop AS RideStopTo ON (RideStopTo.Ride = Ride.Id) AND (RideStopTo.Place LIKE "%'.$_GET['to'].'%") '.
|
---|
14 | 'LEFT JOIN Car ON Car.Id = Ride.Car '.
|
---|
15 | 'LEFT JOIN CarModel ON CarModel.Id = Car.Model '.
|
---|
16 | 'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '.
|
---|
17 | 'WHERE Ride.Id='.$RideId);
|
---|
18 | $DbRow = $DbResult->fetch_assoc();
|
---|
19 | $Track = array();
|
---|
20 | $Stops = array();
|
---|
21 | $DbResult2 = $this->Database->query('SELECT * FROM RideStop WHERE Ride='.$DbRow['Id'].' ORDER BY Sequence');
|
---|
22 | while ($DbRow2 = $DbResult2->fetch_assoc())
|
---|
23 | {
|
---|
24 | $Track[] = $DbRow2;
|
---|
25 | $Stops[] = $DbRow2['Place'];
|
---|
26 | }
|
---|
27 |
|
---|
28 | $Output = '<h3>Detail jízdy</h3><table>'.
|
---|
29 | '<tr><td>Trasa:</td><td>'.implode(' → ', $Stops).'</td></tr>'.
|
---|
30 | '<tr><td>Odjezd z:</td><td>'.$Track[0]['Place'].'</td></tr>'.
|
---|
31 | '<tr><td>Příjezd do:</td><td>'.$Track[count($Track) - 1]['Place'].'</td></tr>'.
|
---|
32 | '<tr><td>Čas odjezdu:</td><td>'.$Track[0]['Time'].'</td></tr>'.
|
---|
33 | '<tr><td>Podrobnosti:</td><td>'.$DbRow['Details'].'</td></tr>';
|
---|
34 | $Output .= '</table>';
|
---|
35 | $Output .= '<form action="?step=2" method="post">'.
|
---|
36 | 'Počet míst: <input type="text" name="seats" value="1"/>'.
|
---|
37 | '<input type="hidden" name="id" value="'.$RideId.'"/>'.
|
---|
38 | '<input type="hidden" name="fromid" value="'.$DbRow['RideStopFromId'].'"/>'.
|
---|
39 | '<input type="hidden" name="toid" value="'.$DbRow['RideStopToId'].'"/>'.
|
---|
40 | '<input type="submit" value="Rezervovat"/>'.
|
---|
41 | '</form>';
|
---|
42 |
|
---|
43 | $Output .= '<h3>Cestující</h3>'.
|
---|
44 | '<table class="WideTable">';
|
---|
45 |
|
---|
46 | // Load passengers table
|
---|
47 | $Table = array_fill(0, count($Track), array_fill(0, $DbRow['SeatCount'], NULL));
|
---|
48 | $Passengers = array();
|
---|
49 | $DbResult = $this->System->Database->query('SELECT User.Name AS UserName, PassengerRideStopFrom.Sequence AS SequenceFrom, '.
|
---|
50 | 'PassengerRideStopTo.Sequence AS SequenceTo FROM Passenger '.
|
---|
51 | 'LEFT JOIN RideStop AS PassengerRideStopFrom ON PassengerRideStopFrom.Id=Passenger.RideStopFrom '.
|
---|
52 | 'LEFT JOIN RideStop AS PassengerRideStopTo ON PassengerRideStopTo.Id=Passenger.RideStopTo '.
|
---|
53 | 'LEFT JOIN User ON User.Id=Passenger.User '.
|
---|
54 | 'WHERE Passenger.Ride='.$RideId);
|
---|
55 | while ($Passenger = $DbResult->fetch_assoc())
|
---|
56 | {
|
---|
57 | $Passengers[] = $Passenger;
|
---|
58 | $Seat = 0;
|
---|
59 | do {
|
---|
60 | $Check = true;
|
---|
61 | for ($I = $Passenger['SequenceFrom']; $I < $Passenger['SequenceTo']; $I++)
|
---|
62 | {
|
---|
63 | if ($Table[$I][$Seat] != 0) $Check = false;
|
---|
64 | }
|
---|
65 | if (!$Check) $Seat++;
|
---|
66 | } while (!$Check);
|
---|
67 | for ($I = $Passenger['SequenceFrom']; $I < $Passenger['SequenceTo']; $I++)
|
---|
68 | $Table[$I][$Seat] = count($Passengers) - 1;
|
---|
69 | }
|
---|
70 |
|
---|
71 | $Output .= '<tr><th>Zastávka / Čas</th><th style="width: 80px">Řidič</th>';
|
---|
72 | for ($I = 0; $I < $DbRow['SeatCount']; $I++)
|
---|
73 | $Output .= '<th style="width: 80px">Cestující</th>';
|
---|
74 | $Output .= '</tr>';
|
---|
75 | foreach ($Track as $Index => $TrackItem)
|
---|
76 | {
|
---|
77 | $Output .= '<tr><td style="height: 100px">'.$TrackItem['Place'].'<br/>'.$TrackItem['Time'].'</td>';
|
---|
78 | if ($Index == 0) $Output .= '<td rowspan="'.count($Track).'">Řidič</td>';
|
---|
79 | for ($I = 0; $I < $DbRow['SeatCount']; $I++)
|
---|
80 | {
|
---|
81 | if (!is_null($Table[$Index][$I])) {
|
---|
82 | $Passenger = $Passengers[$Table[$Index][$I]];
|
---|
83 | if ($Index == $Passenger['SequenceFrom'])
|
---|
84 | $Output .= '<td rowspan="'.($Passenger['SequenceTo'] - $Passenger['SequenceFrom']).'">'.$Passenger['UserName'].'</td>';
|
---|
85 | } else {
|
---|
86 | // Show unused space
|
---|
87 | if (($Index == 0) or ((($Index - 1) >= 0) and (!is_null($Table[$Index - 1][$I]))))
|
---|
88 | {
|
---|
89 | $J = 1;
|
---|
90 | while ((($Index + $J) < count($Table)) and is_null($Table[$Index + $J][$I])) $J++;
|
---|
91 | $Output .= '<td rowspan="'.$J.'"> </td>';
|
---|
92 | }
|
---|
93 | }
|
---|
94 | }
|
---|
95 | $Output .= '</tr>';
|
---|
96 | }
|
---|
97 | $Output .= '</table>';
|
---|
98 |
|
---|
99 |
|
---|
100 | return $Output;
|
---|
101 | }
|
---|
102 |
|
---|
103 | function Show(): string
|
---|
104 | {
|
---|
105 | if (!array_key_exists('step', $_GET)) $Output = $this->ShowDetail();
|
---|
106 | else {
|
---|
107 | if ($_GET['step'] == 2) {
|
---|
108 | $this->System->Database->insert('Passenger', array(
|
---|
109 | 'Ride' => $_POST['id'],
|
---|
110 | 'User' => Core::Cast($this->System)->User->User['Id'],
|
---|
111 | 'SeatCount' => $_POST['seats'],
|
---|
112 | 'RideStopFrom' => $_POST['fromid'],
|
---|
113 | 'RideStopTo' => $_POST['toid'],
|
---|
114 | ));
|
---|
115 | $this->System->ModuleManager->Modules['Ride']->UpdatePassengerCount($_POST['id']);
|
---|
116 | $Output = 'Rezervace dokončena';
|
---|
117 | }
|
---|
118 | }
|
---|
119 | return $Output;
|
---|
120 | }
|
---|
121 | }
|
---|