- Timestamp:
- Sep 8, 2016, 11:03:23 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/.htaccess
r1 r3 7 7 RewriteCond %{REQUEST_FILENAME} !-f 8 8 RewriteCond %{REQUEST_FILENAME} !-d 9 RewriteRule ^(.*)$ %{CONTEXT_PREFIX} /index.php?$19 RewriteRule ^(.*)$ %{CONTEXT_PREFIX}index.php?$1 10 10 11 11 #ErrorDocument 403 "index.php?page=403" -
trunk/Application/Core.php
r1 r3 30 30 $this->ShowPage = true; 31 31 $this->BaseURL = $_SERVER['SCRIPT_NAME']; 32 if(substr($this->BaseURL, -10, 10) == '/index.php') 33 $this->BaseURL = substr($this->BaseURL, 0, -10); 32 $BaseScriptName = '/index.php'; 33 if(substr($this->BaseURL, -strlen($BaseScriptName), strlen($BaseScriptName)) == $BaseScriptName) 34 $this->BaseURL = substr($this->BaseURL, 0, -strlen($BaseScriptName)); 34 35 $this->FormManager = new FormManager($this->Database); 35 36 } … … 62 63 63 64 $this->RegisterPageBar('Top'); 65 $this->RegisterPageBar('TopLeft'); 64 66 65 67 // Register and start existing modules … … 164 166 { 165 167 Header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); 166 return('<h3 align="center">'.T('Required page not found') );168 return('<h3 align="center">'.T('Required page not found').'</h3>'); 167 169 } 168 170 } -
trunk/Application/View.php
r1 r3 35 35 { 36 36 $Output = '<div>'; 37 $Output .= '<div class="MenuItem">'; 38 $Bar = ''; 39 foreach($this->System->Bars['TopLeft'] as $BarItem) 40 $Bar .= call_user_func($BarItem); 41 if(trim($Bar) != '') $Output .= $Bar; 42 else $Output .= ' '; 43 $Output .= '</div><div class="MenuItem2">'; 37 44 $Bar = ''; 38 45 foreach($this->System->Bars['Top'] as $BarItem) … … 40 47 if(trim($Bar) != '') $Output .= $Bar; 41 48 else $Output .= ' '; 42 $Output .= '</div> ';49 $Output .= '</div></div>'; 43 50 return($Output); 44 51 } -
trunk/Modules/Ride/Ride.php
r1 r3 19 19 $this->System->RegisterPage('nova-jizda', 'PageNewRide'); 20 20 $this->System->RegisterPage('jizda', 'PageRideDetail'); 21 $this->System->RegisterPageBarItem('TopLeft', 'Logo', array($this, 'ShowLogo')); 21 22 } 22 23 … … 69 70 `Sequence` int(11) NOT NULL, 70 71 `Price` int(11) NOT NULL, 72 `PassengerCount` int(11) NOT NULL, 71 73 PRIMARY KEY (`Id`), 72 74 KEY `Ride` (`Ride`) … … 123 125 124 126 } 127 128 function ShowLogo() 129 { 130 $Output = '<img src="" width="200" height="50" alt="Logo"/> '. 131 '<a href="'.$this->System->Link('/hledat/').'">Hledat jízdu</a> nebo '. 132 '<a href="'.$this->System->Link('/nabídnout/').'">Nabídnout jízdu</a>'; 133 return($Output); 134 } 135 136 function UpdatePassengerCount($RideId) 137 { 138 $DbResult = $this->System->Database->select('RideStop', 'COUNT(*) AS RideStopCount', 'Ride='.$RideId); 139 $DbRow = $DbResult->fetch_assoc(); 140 141 $Stops = array_fill(0, $DbRow['RideStopCount'], 0); 142 $this->System->Database->update('RideStop', 'Ride='.$RideId, array('PassengerCount' => 0)); 143 $DbResult = $this->System->Database->query('SELECT PassengerRideStopFrom.Sequence AS SequenceFrom, '. 144 'PassengerRideStopTo.Sequence AS SequenceTo, Passenger.SeatCount FROM Passenger '. 145 'LEFT JOIN RideStop AS PassengerRideStopFrom ON PassengerRideStopFrom.Id=Passenger.RideStopFrom '. 146 'LEFT JOIN RideStop AS PassengerRideStopTo ON PassengerRideStopTo.Id=Passenger.RideStopTo '. 147 'WHERE Passenger.Ride='.$RideId); 148 while($DbRow = $DbResult->fetch_assoc()) 149 { 150 for($I = $DbRow['SequenceFrom'] + 1; $I <= $DbRow['SequenceTo']; $I++) 151 { 152 $Stops[$I] = $Stops[$I] + $DbRow['SeatCount']; 153 } 154 } 155 foreach($Stops as $Index => $Stop) 156 { 157 $this->System->Database->update('RideStop', 'Ride='.$RideId.' AND Sequence='.$Index, array('PassengerCount' => $Stop)); 158 } 159 } 125 160 } 161 126 162 class PageRideDetail extends Page 127 163 { 128 164 function ShowDetail() 129 165 { 166 $RideId = $_GET['id']; 130 167 $DbResult = $this->Database->query('SELECT Ride.Details, Ride.Id, Ride.SeatCount, '. 131 168 'RideStopFrom.Id AS RideStopFromId, RideStopTo.Id AS RideStopToId, '. … … 137 174 'LEFT JOIN CarModel ON CarModel.Id = Car.Model '. 138 175 'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '. 139 'WHERE Ride.Id='.$ _GET['id']);176 'WHERE Ride.Id='.$RideId); 140 177 $DbRow = $DbResult->fetch_assoc(); 141 178 $Track = array(); … … 157 194 $Output .= '<form action="?step=2" method="post">'. 158 195 'Počet míst: <input type="text" name="seats" value="1"/>'. 159 '<input type="hidden" name="id" value="'.$ _GET['id'].'"/>'.196 '<input type="hidden" name="id" value="'.$RideId.'"/>'. 160 197 '<input type="hidden" name="fromid" value="'.$DbRow['RideStopFromId'].'"/>'. 161 198 '<input type="hidden" name="toid" value="'.$DbRow['RideStopToId'].'"/>'. … … 166 203 '<table class="WideTable">'; 167 204 168 /* $DbResult2 = $this->Database->query('SELECT * FROM RideStop WHERE Ride='.$DbRow['Id'].' ORDER BY Sequence'); 169 while($DbRow2 = $DbResult2->fetch_assoc()) 170 { 171 $Track[] = $DbRow2; 172 $Stops[] = $DbRow2['Place']; 173 } 174 */ 205 // Load passengers table 206 $Table = array_fill(0, count($Track), array_fill(0, $DbRow['SeatCount'], NULL)); 207 $Passengers = array(); 208 $DbResult = $this->System->Database->query('SELECT User.Name AS UserName, PassengerRideStopFrom.Sequence AS SequenceFrom, '. 209 'PassengerRideStopTo.Sequence AS SequenceTo FROM Passenger '. 210 'LEFT JOIN RideStop AS PassengerRideStopFrom ON PassengerRideStopFrom.Id=Passenger.RideStopFrom '. 211 'LEFT JOIN RideStop AS PassengerRideStopTo ON PassengerRideStopTo.Id=Passenger.RideStopTo '. 212 'LEFT JOIN User ON User.Id=Passenger.User '. 213 'WHERE Passenger.Ride='.$RideId); 214 while($Passenger = $DbResult->fetch_assoc()) 215 { 216 $Passengers[] = $Passenger; 217 $Seat = 0; 218 do { 219 $Check = true; 220 for($I = $Passenger['SequenceFrom']; $I < $Passenger['SequenceTo']; $I++) 221 { 222 if($Table[$I][$Seat] != 0) $Check = false; 223 } 224 if (!$Check) $Seat++; 225 } while(!$Check); 226 for($I = $Passenger['SequenceFrom']; $I < $Passenger['SequenceTo']; $I++) 227 $Table[$I][$Seat] = count($Passengers) - 1; 228 } 229 230 $Output .= '<tr><th>Zastávka / Čas</th><th>Řidič</th>'; 231 for ($I = 0; $I < $DbRow['SeatCount']; $I++) 232 $Output .= '<th>Cestující</th>'; 233 $Output .= '</tr>'; 175 234 foreach($Track as $Index => $TrackItem) 176 235 { 177 $Output .= '<tr><td>'.$TrackItem['Place'].'<br/>'.$TrackItem['Time'].'</td>'; 236 $Output .= '<tr><td style="height: 100px">'.$TrackItem['Place'].'<br/>'.$TrackItem['Time'].'</td>'; 237 if($Index == 0) $Output .= '<td rowspan="'.count($Track).'">Řidič</td>'; 178 238 for ($I = 0; $I < $DbRow['SeatCount']; $I++) 179 239 { 180 $Output .= '<td>'.'s'.'</td>'; 240 if (!is_null($Table[$Index][$I])) { 241 $Passenger = $Passengers[$Table[$Index][$I]]; 242 if ($Index == $Passenger['SequenceFrom']) 243 $Output .= '<td rowspan="'.($Passenger['SequenceTo'] - $Passenger['SequenceFrom']).'">'.$Passenger['UserName'].'</td>'; 244 } else { 245 // Show unused space 246 if(($Index == 0) or ((($Index - 1) >= 0) and (!is_null($Table[$Index - 1][$I])))) 247 { 248 $J = 1; 249 while((($Index + $J) < count($Table)) and is_null($Table[$Index + $J][$I])) $J++; 250 $Output .= '<td rowspan="'.$J.'"> </td>'; 251 } 252 } 181 253 } 182 254 $Output .= '</tr>'; … … 200 272 'RideStopTo' => $_POST['toid'], 201 273 )); 274 $this->System->ModuleManager->Modules['Ride']->UpdatePassengerCount($_POST['id']); 202 275 $Output = 'Rezervace dokončena'; 203 276 } … … 223 296 if (array_key_exists('from', $_GET) and array_key_exists('to', $_GET)) { 224 297 $Output .= $this->ShowRides($_GET['from'], $_GET['to']); 225 } 298 } else $Output .= $this->ShowRides('', ''); 226 299 return($Output); 227 300 } … … 231 304 $Output = '<h3>Jízdy:</h3>'; 232 305 $Output .= '<table>'; 233 if((trim($PlaceFrom) == '') or (trim($PlaceTo == ''))) return "Zadejte odkud kam."; 234 $DbResult = $this->Database->query('SELECT Ride.Id, Ride.SeatCount, (SELECT Name FROM User WHERE User.Id=Ride.Driver) AS DriverName, '. 235 'CONCAT(CarManufacturer.Name, " ", CarModel.Name) AS CarName FROM Ride '. 236 'JOIN RideStop AS RideStopFrom ON (RideStopFrom.Ride = Ride.Id) AND (RideStopFrom.Place LIKE "%'.$PlaceFrom.'%") '. 237 'JOIN RideStop AS RideStopTo ON (RideStopTo.Ride = Ride.Id) AND (RideStopTo.Place LIKE "%'.$PlaceTo.'%") '. 306 $Query = 'SELECT Ride.Id, Ride.SeatCount, (SELECT Name FROM User WHERE User.Id=Ride.Driver) AS DriverName, '. 307 'CONCAT(CarManufacturer.Name, " ", CarModel.Name) AS CarName '; 308 if((trim($PlaceFrom) != '') and (trim($PlaceTo != ''))) 309 $Query .= ', (SELECT COALESCE(MAX(RideStop.PassengerCount), 0) FROM RideStop '. 310 'WHERE (RideStop.Ride=Ride.Id) AND (RideStop.Sequence > RideStopFrom.Sequence) AND '. 311 '(RideStop.Sequence <= RideStopTo.Sequence)) AS PassengerCount '; 312 else 313 $Query .= ', (SELECT COALESCE(MAX(RideStop.PassengerCount), 0) FROM RideStop '. 314 'WHERE (RideStop.Ride=Ride.Id)) AS PassengerCount '; 315 316 $Query .= 'FROM Ride '. 238 317 'LEFT JOIN Car ON Car.Id = Ride.Car '. 239 318 'LEFT JOIN CarModel ON CarModel.Id = Car.Model '. 240 'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '. 241 'WHERE RideStopFrom.Sequence < RideStopTo.Sequence '. 242 'LIMIT 10'); 319 'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '; 320 if((trim($PlaceFrom) != '') and (trim($PlaceTo != ''))) 321 $Query .= 'JOIN RideStop AS RideStopFrom ON (RideStopFrom.Ride = Ride.Id) AND (RideStopFrom.Place LIKE "%'.$PlaceFrom.'%") '. 322 'JOIN RideStop AS RideStopTo ON (RideStopTo.Ride = Ride.Id) AND (RideStopTo.Place LIKE "%'.$PlaceTo.'%") '. 323 'WHERE (RideStopFrom.Sequence < RideStopTo.Sequence)'; 324 $Query .= 'LIMIT 10'; 325 $DbResult = $this->Database->query($Query); 243 326 while($DbRow = $DbResult->fetch_assoc()) 244 327 { … … 251 334 $Price += $DbRow2['Price']; 252 335 } 253 $AvailSpace = $DbRow['SeatCount'];254 $DbResult2 = $this->Database->query('SELECT * FROM Passenger WHERE Ride='.$DbRow['Id']);255 while($DbRow2 = $DbResult2->fetch_assoc())256 {257 $AvailSpace -= $DbRow2['SeatCount'];258 }259 336 260 337 $Output .= '<tr><td>Řidič:</td><td>'.$DbRow['DriverName'].'</td>'. 261 '<td colspan="4"><a href="'.$this->System->Link('/jizda/?id='.$DbRow['Id'].'&from='.$ _GET['from'].'&to='.$_GET['to']).'">Ukázat</a></td></tr>'.338 '<td colspan="4"><a href="'.$this->System->Link('/jizda/?id='.$DbRow['Id'].'&from='.$PlaceFrom.'&to='.$PlaceTo).'">Ukázat</a></td></tr>'. 262 339 '<tr><td>Trasa:</td><td>'.implode(' → ', $Stops).'</td></tr>'. 263 340 '<tr><td>Cena:</td><td>'.$Price.' Kč</td></tr>'. 264 '<tr><td>Volných míst:</td><td>'.$AvailSpace.'</td></tr>'. 265 '<tr><td>Auto:</td><td>'.$DbRow['CarName'].'</td></tr>'; 341 '<tr><td>Volných míst:</td><td>'.($DbRow['SeatCount'] - $DbRow['PassengerCount']).'</td></tr>'. 342 '<tr><td>Auto:</td><td>'.$DbRow['CarName'].'</td></tr>'. 343 '<tr><td> </td></tr>'; 266 344 } 267 345 $Output .= '</table'; … … 331 409 $Map->Width = 400; 332 410 $Map->Height = 300; 333 $Map->Path = array($_GET['from'], 'Pardubice',$_GET['to']);334 $Map->Path = array('Praha', 'Brno', 'Zlín', 'Vsetín');411 $Map->Path = array($_GET['from'], $_GET['to']); 412 //$Map->Path = array('Praha', 'Brno', 'Zlín', 'Vsetín'); 335 413 $Track = $Map->Route(); 336 414 $Output .= '<h3>Trasa</h3>';
Note:
See TracChangeset
for help on using the changeset viewer.