source: trunk/Modules/Ride/PageNewRide.php

Last change on this file was 10, checked in by chronos, 18 months ago
  • Fixed: More class type casting.
File size: 6.0 KB
Line 
1<?php
2
3class PageNewRide extends Page
4{
5 function Show(): string
6 {
7 if (!array_key_exists('step', $_GET))
8 {
9 $Output = '<script>
10function insertAfter(referenceNode, newNode)
11{
12 referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
13}
14
15function add_before(name)
16{
17 var objTo = document.getElementById(name)
18 var divtest = document.createElement("div");
19 divtest.innerHTML = \'<tr><td>Zastávka:</td><td><input type="text" name="ridestop1"/></td></tr>\';
20
21 objTo.parentNode.insertBefore(divtest, objTo.childNodes[0])
22}
23
24function add_after(name)
25{
26 var objTo = document.getElementById(name)
27 var divtest = document.createElement("div");
28 divtest.innerHTML = \'<tr><td>Zastávka:</td><td><input type="text" name="ridestop1"/></td></tr>\';
29
30 insertAfter(objTo, divtest)
31}
32 </script>'.
33 '<form method="get" action="'.$this->System->Link('/nova-jizda/').'">'.
34 '<table>'.
35 '<tr><td colspan="2"><strong>Trasa:</strong></td></tr>'.
36
37 '<tr><td>Počátek:</td><td><input type="text" name="from"/></td></tr>'.
38 '<tr><td>Zastávka:</td><td><input type="text" name="middle"/></td></tr>'.
39 '<tr><td>Konec:</td><td><input type="text" name="to"/></td></tr>'.
40
41 '<tr><td colspan="2"><br><strong>Parametry jízdy:</strong></td></tr>'.
42 '<tr><td>Čas odjezdu:</td><td><input type="text" name="time-from"/></td></tr>'.
43 '<tr><td>Počet míst pro cestující:</td><td><input type="text" name="seats"/></td></tr>'.
44 '</table>'.
45 '<input type="hidden" name="step" value="2"/><br/>'.
46 '<input type="submit" value="Pokračovat"/>'.
47 '</form>';
48 } else {
49 if ($_GET['step'] == '2') {
50 $TimeFrom = strtotime($_GET['time-from']);
51 $Output = '<table style="width: 100%"><tr><td>';
52 $Output .= '<form method="post" action="'.$this->System->Link('/nova-jizda/?step=3').'">'.
53 '<input type="hidden" name="from" value="'.$_GET['from'].'"/><br/>'.
54 '<input type="hidden" name="to" value="'.$_GET['to'].'"/><br/>'.
55 '<input type="hidden" name="time-from" value="'.$_GET['time-from'].'"/><br/>'.
56 '<input type="hidden" name="seats" value="'.$_GET['seats'].'"/><br/>'.
57 '<input type="hidden" name="step" value="3"/><br/>'.
58 'Popis:<br/><textarea name="desc"></textarea><br/>'.
59 'Auto: <select name="car">';
60 $DbResult = $this->Database->query('SELECT Car.Id, CONCAT(CarManufacturer.Name, " ", CarModel.Name) AS ModelName FROM Car '.
61 'LEFT JOIN CarModel ON CarModel.Id=Car.Model '.
62 'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '.
63 'WHERE Car.Owner='.Core::Cast($this->System)->User->User['Id']);
64 while ($DbRow = $DbResult->fetch_assoc())
65 {
66 $Output .= '<option value="'.$DbRow['Id'].'"/>'.$DbRow['ModelName'].'</option>';
67 }
68 $Output .= '</select>'.
69 '<input type="submit" value="Vytvořit"/>'.
70 '</form>';
71 $Map = new MapGoogle($this->System);
72 $Map->Key = 'AIzaSyDQ-tOjP9mO8ZpSEuBc5_oCRg30rpQZiBI';
73 $Map->Width = 400;
74 $Map->Height = 300;
75 $Map->Path = array($_GET['from'], $_GET['to']);
76 //$Map->Path = array('Praha', 'Brno', 'Zlín', 'Vsetín');
77 $Track = $Map->Route();
78 $Output .= '<h3>Trasa</h3>';
79 $PricePerKm = 0.8;
80 $Output .= '<table class="WideTable"><tr><th>Úsek</th><th>Odjezd</th><th>Trvání</th><th>Vzdálenost [km]</th><th>Cena [Kč]</th></tr>';
81 foreach ($Track as $Index => $TrackItem)
82 {
83 if ($Index > 0)
84 {
85 $Track[$Index]['Time'] = $TimeFrom + $Track[$Index - 1]['Duration'];
86 $RelDistance = $TrackItem['Distance'] - $Track[$Index - 1]['Distance'];
87 $RelDuration = $TrackItem['Duration'] - $Track[$Index - 1]['Duration'];
88 $Track[$Index]['Price'] = round($PricePerKm * $RelDistance / 1000);
89 $Output .= '<tr><td>'.$Map->Path[$Index - 1].' → '.$TrackItem['Destination'].'</td>'.
90 '<td>'.TimeToMysqlDateTime($Track[$Index]['Time']).'</td>'.
91 '<td>'.time_elapsed($RelDuration).'</td>'.
92 '<td>'.round($RelDistance / 1000).'</td>'.
93 '<td>'.$Track[$Index]['Price'].'</td></tr>';
94
95 } else {
96 $Track[$Index]['Time'] = $TimeFrom;
97 $Track[$Index]['Price'] = 0;
98 }
99 }
100 $Output .= '<tr><td>'.$Map->Path[0].' → '.$Map->Path[count($Map->Path) - 1].'</td>'.
101 '<td>'.TimeToMysqlDateTime($Track[0]['Time']).'</td>'.
102 '<td>'.time_elapsed($Track[count($Track) - 1]['Duration']).'</td>'.
103 '<td>'.round($Track[count($Track) - 1]['Distance'] / 1000).'</td>'.
104 '<td>'.round($PricePerKm * $Track[count($Track) - 1]['Distance'] / 1000).'</td></tr>';
105 $Output .= '</table><br/>';
106 $Output .= 'Vzdálenost: '.round($Track[count($Track) - 1]['Distance'] / 1000, 1).' km<br/>';
107 $Output .= 'Délka jízdy: '.time_elapsed($Track[count($Track) - 1]['Duration']).'<br/>';
108 $Output .= '</td><td>';
109 $Map->Key = 'AIzaSyDwKYuEdkXAl9Y2RyDLf5m03n-ItHaqdKs';
110 $Output .= $Map->Show();
111 $Output .= '</td></tr></table>';
112 $_SESSION['Track'] = $Track;
113 $_SESSION['SeatCount'] = $_GET['seats'];
114 } else
115 if ($_GET['step'] == '3') {
116 $this->Database->insert('Ride', array(
117 'Driver' => Core::Cast($this->System)->User->User['Id'],
118 'SeatCount' => $_POST['seats'],
119 'Car' => $_POST['car'],
120 'Details' => $_POST['desc'],
121 ));
122 $RideId = $this->Database->insert_id;
123 foreach ($_SESSION['Track'] as $Index => $TrackItem)
124 {
125 $this->Database->insert('RideStop', array(
126 'Ride' => $RideId,
127 'Place' => $TrackItem['Destination'],
128 'Time' => TimeToMysqlDateTime($TrackItem['Time']),
129 'Price' => $TrackItem['Price'],
130 'Sequence' => $Index,
131 'PassengerCount' => 0,
132 ));
133 }
134 $Output = 'Nová jízda přidána.';
135 }
136 }
137 return $Output;
138 }
139}
Note: See TracBrowser for help on using the repository browser.