Changeset 8 for trunk/Modules


Ignore:
Timestamp:
Jun 1, 2023, 12:18:18 AM (19 months ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
  • Modified: Form types made as separate FormManager package.
  • Fixed: PHP 8.1 support.
Location:
trunk/Modules
Files:
10 added
2 edited
1 copied
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Map/Map.php

    r7 r8  
    11<?php
    2 
    3 class ModuleMap extends AppModule
    4 {
    5   function __construct($System)
    6   {
    7     parent::__construct($System);
    8     $this->Name = 'Map';
    9     $this->Version = '1.0';
    10     $this->Creator = 'Chronos';
    11     $this->License = 'GNU/GPL';
    12     $this->Description = 'Map';
    13     $this->Dependencies = array();
    14   }
    15 
    16   function DoStart()
    17   {
    18   }
    19 
    20   function DoInstall()
    21   {
    22   }
    23 
    24   function DoUninstall()
    25   {
    26   }
    27 
    28   function DoUpgrade()
    29   {
    30 
    31   }
    32 }
    332
    343class Map extends Model
     
    4110  var $Key;
    4211
    43   function __construct(Application $System)
     12  function __construct(Core $System)
    4413  {
    4514    parent::__construct($System);
     
    7039}
    7140
    72 class MapSeznam extends Map
    73 {
    74   function Geolocate($Text)
    75   {
    76     //new SMap.Geocoder(query, odpoved);
    77   }
    7841
    79   function Show()
    80   {
    81     $Output .= '<div id="m" style="height:380px"></div>';
    82     $Output .= '<script type="text/javascript">
    83             var centerMap = SMap.Coords.fromWGS84(14.40, 50.08);
    84 var m = new SMap(JAK.gel("m"), centerMap, 16);
    85 var l = m.addDefaultLayer(SMap.DEF_BASE).enable();
    86 m.addDefaultControls();
    87 
    88 
    89 var nalezeno = function(route) {
    90     var vrstva = new SMap.Layer.Geometry();
    91     m.addLayer(vrstva).enable();
    92 
    93     var coords = route.getResults().geometry;
    94     var cz = m.computeCenterZoom(coords);
    95     m.setCenterZoom(cz[0], cz[1]);
    96     var g = new SMap.Geometry(SMap.GEOMETRY_POLYLINE, null, coords);
    97     vrstva.addGeometry(g);
    98 }
    99 
    100 var coords = [
    101     SMap.Coords.fromWGS84(14.434, 50.084),
    102     SMap.Coords.fromWGS84(16.600, 49.195)
    103 ];
    104 var route = new SMap.Route(coords, nalezeno);
    105             </script>';
    106     $this->System->HeadItems[] = '<script src="//api.mapy.cz/loader.js"></script>
    107         <script>Loader.load()</script>';
    108 
    109     return $Output;
    110   }
    111 }
    112 
    113 class MapGoogle extends Map
    114 {
    115   function Route()
    116   {
    117     $Origins = array();
    118     $Destinations = array();
    119     foreach ($this->Path as $Index => $PathItem)
    120     if ($Index > 0)
    121     {
    122        if ($Index == 1) $Origins[] = $this->Path[$Index - 1];
    123        $Destinations[] = $this->Path[$Index];
    124     }
    125     $URL = 'https://maps.googleapis.com/maps/api/distancematrix/json'.
    126       '?origins='.implode('|', $Origins).'&destinations='.implode('|', $Destinations).'&key='.$this->Key;
    127     $Result = file_get_contents($URL);
    128     $Points = array(array('Destination' => $this->Path[0], 'Distance' => 0, 'Duration' => 0));
    129     $I = 1;
    130     while (strpos($Result, '"distance"') !== false) {
    131       $Distance = trim($this->Parse($Result, '"value" :', '}'));
    132       $Duration = trim($this->Parse($Result, '"value" :', '}'));
    133       $Points[] = array('Destination' => $this->Path[$I], 'Distance' => $Distance, 'Duration' => $Duration);
    134       $I++;
    135     }
    136     return $Points;
    137   }
    138 
    139   function Show()
    140   {
    141     $WayPoints = $this->Path;
    142     array_shift($WayPoints);
    143     array_pop($WayPoints);
    144     if (count($WayPoints) > 0)
    145       $WaypointsQuery = '&waypoints='.implode('|', $WayPoints);
    146       else $WaypointsQuery = '';
    147 
    148     $Output = '<iframe width="'.$this->Width.'" height="'.$this->Height.'" frameborder="0" scrolling="no" '.
    149       'marginheight="0" marginwidth="0" src="'.'https://www.google.com/maps/embed/v1/directions'.
    150       '?key='.$this->Key.'&origin='.$this->Path[0].$WaypointsQuery.
    151       '&destination='.$this->Path[count($this->Path) - 1].''.
    152       '" style="border: 1px solid black"></iframe>';
    153     return $Output;
    154   }
    155 }
    156 
    157 class MapOSM extends Map
    158 {
    159   function Geolocate($Text)
    160   {
    161     // http://wiki.openstreetmap.org/wiki/Nominatim
    162     $URL = 'http://nominatim.openstreetmap.org/search.php?q='.urlencode($Text).'&viewbox=&format=xml&limit=1';
    163     $Result = file_get_contents($URL);
    164     $Result = substr($Result, strpos($Result, 'boundingbox="') + 13);
    165     $BoundingBox = substr($Result, 0, strpos($Result, '"') - 1);
    166     $Parts = explode(',', $BoundingBox);
    167     $Zoom = 1 / ($Parts[1] - $Parts[0]) * 2;
    168     $Result = substr($Result, strpos($Result, 'lat=\'') + 5);
    169     $Latitude = substr($Result, 0, strpos($Result, '\'') - 1);
    170     $Result = substr($Result, strpos($Result, 'lon=\'') + 5);
    171     $Longitude = substr($Result, 0, strpos($Result, '\'') - 1);
    172     return array('Latitude' => $Latitude, 'Longitude' => $Longitude, 'BoundingBox' => $BoundingBox, 'Zoom' => $Zoom);
    173   }
    174 
    175   function Route($TextPathItems)
    176   {
    177     $this->Points = array();
    178     foreach ($TextPathItems as $TextPathItem)
    179     {
    180       $Result = $this->Geolocate($TextPathItem);
    181       $this->Points[] = array('Longitude' => $Result['Longitude'],
    182         'Latitude' => $Result['Latitude']);
    183     }
    184 
    185     $WayPoints = array();
    186     foreach ($this->Points as $Point)
    187     {
    188       $WayPoints[] = $Point['Longitude'];
    189       $WayPoints[] = $Point['Latitude'];
    190     }
    191 
    192     // http://wiki.openstreetmap.org/wiki/OpenRouteService#OpenRouteService_API
    193     $this->Key = 'ee0b8233adff52ce9fd6afc2a2859a28';
    194     $URL = 'http://openls.geog.uni-heidelberg.de/route?api_key='.
    195       $this->Key.'&start='.implode(',', $this->Points[0]).'&end='.implode(',', $this->Points[count($this->Points) - 1]).
    196       '&via='.implode(',', $WayPoints).'&lang=en&distunit=M&routepref=Car&weighting=Fastest&avoidAreas='.
    197       '&useTMC=false&noMotorways=false&noTollways=false&noUnpavedroads=false&noSteps=false'.
    198       '&noFerries=false&elevation=false&surface=false&instructions=false';
    199     $Result = file_get_contents($URL);
    200     echo($Result);
    201     $Separator = '<xls:TotalDistance uom="M" value="';
    202     $Result = substr($Result, strpos($Result, $Separator) + strlen($Separator));
    203     $TotalDistance = substr($Result, 0, strpos($Result, '"/>') - 1);
    204     $Separator = '<xls:TotalTime>PT2H3M48S';
    205     $Result = substr($Result, strpos($Result, $Separator) + strlen($Separator));
    206     $TotalTime = substr($Result, 0, strpos($Result, '"/>') - 1);
    207 
    208     $Points = array();
    209     $Separator = '<gml:pos>';
    210     while (strpos($Result, $Separator) !== false)
    211     {
    212       $Result = substr($Result, strpos($Result, $Separator) + strlen($Separator));
    213       $Pos = substr($Result, 0, strpos($Result, '</gml:pos>') - 1);
    214       $PosParts = explode(' ', $Pos);
    215       $Points[] = array('Longitude' => $PosParts[0], 'Latitude' => $PosParts[1]);
    216     }
    217     return array('TotalDistance' => $TotalDistance, 'TotalTime' => $TotalTime,
    218       'Points' => $Points);
    219   }
    220 
    221   function Show()
    222   {
    223     $WayPoints = array();
    224     foreach ($this->Points as $Point)
    225     {
    226       $WayPoints[] = $Point['Longitude'];
    227       $WayPoints[] = $Point['Latitude'];
    228     }
    229 
    230     $Output = '<iframe width="'.$this->Width.'" height="'.$this->Height.'" frameborder="0" scrolling="no" '.
    231       'marginheight="0" marginwidth="0" src="'.
    232       'http://www.openrouteservice.org/?pos=8.925670599999979,52.28150333376007&zoom='.
    233       $this->Zoom.'&layer=0B00&routeOpt=Car&wp='.implode(',', $WayPoints).
    234       '&lang=en&routeLang=en&distUnit=m&routeWeight=Fastest'.
    235       'style="border: 1px solid black"></iframe>';
    236 /*    $Latitude = $this->Pos['Latitude'];
    237     $Longitude = $this->Pos['Longitude'];
    238     $Zoom = $this->Zoom;
    239     $BoundingBox = array($Longitude - 1 / $Zoom, $Latitude - 1 / $Zoom, $Longitude + 1 / $Zoom, $Latitude + 1 / $Zoom);
    240     $Output = '<iframe width="'.$this->Width.'" height="'.$this->Height.'" frameborder="0" scrolling="no" '.
    241       'marginheight="0" marginwidth="0" src="http://www.openstreetmap.org/export/embed.html'.
    242       '?bbox='.implode(',', $BoundingBox).'&amp;layer=mapnik&amp;marker='.$Latitude.','.$Longitude.'" '.
    243       'style="border: 1px solid black"></iframe>'.
    244       '<p><small><a href="http://www.openstreetmap.org/'.
    245       '?lat='.$Latitude.'&amp;lon='.$Longitude.';zoom='.$Zoom.'&amp;layers=M&amp;mlat='.$Latitude.'&amp;mlon='.$Longitude.'">View Larger Map</a></small></p>';
    246       */
    247     return $Output;
    248   }
    249 }
  • trunk/Modules/Ride/Ride.php

    r7 r8  
    11<?php
    22
    3 include_once(dirname(__FILE__).'/RideModel.php');
     3class Ride extends Model
     4{
     5  function Add($Track, $SeatCount, $Car, $Details)
     6  {
     7    $this->Database->insert('Ride', array('SeatCount' => $SeatCount, 'Details' => $Details,
     8      'Car' => $Car, 'Driver' => $this->System->ModuleManager->Modules['User']->User['Id']));
     9    $RideId = $this->Database->insert_id;
    410
    5 class ModuleRide extends AppModule
    6 {
    7   function __construct($System)
    8   {
    9     parent::__construct($System);
    10     $this->Name = 'Ride';
    11     $this->Version = '1.0';
    12     $this->Creator = 'Chronos';
    13     $this->License = 'GNU/GPL';
    14     $this->Description = 'Ride management';
    15     $this->Dependencies = array('User', 'Map');
    16   }
    17 
    18   function DoStart()
    19   {
    20     $this->System->RegisterPage('', 'PageMain');
    21     $this->System->RegisterPage('nova-jizda', 'PageNewRide');
    22     $this->System->RegisterPage('jizda', 'PageRideDetail');
    23     $this->System->RegisterPage('jizdy', 'PageRideList');
    24     $this->System->RegisterPageBarItem('TopLeft', 'Logo', array($this, 'ShowLogo'));
    25   }
    26 
    27   function DoInstall()
    28   {
    29     $this->Database->query('CREATE TABLE `CarManufacturer` (
    30   `Id` int(11) NOT NULL AUTO_INCREMENT,
    31   `Name` varchar(255) NOT NULL,
    32   PRIMARY KEY (`Id`)
    33 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
    34     $this->Database->query('CREATE TABLE `CarModel` (
    35   `Id` int(11) NOT NULL AUTO_INCREMENT,
    36   `Name` varchar(255) NOT NULL,
    37   `Manufacturer` int(11) NOT NULL,
    38   PRIMARY KEY (`Id`),
    39   KEY `Manufacturer` (`Manufacturer`)
    40 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
    41     $this->Database->query('ALTER TABLE `CarModel`
    42     ADD CONSTRAINT `CarModel_ibfk_1` FOREIGN KEY (`Manufacturer`) REFERENCES `CarManufacturer` (`Id`);');
    43     $this->Database->query('CREATE TABLE `Car` (
    44   `Id` int(11) NOT NULL AUTO_INCREMENT,
    45   `Owner` int(11) NOT NULL,
    46   `Photo` int(11) DEFAULT NULL,
    47   `Model` int(11) NOT NULL,
    48   PRIMARY KEY (`Id`),
    49   KEY `Owner` (`Owner`),
    50   KEY `Model` (`Model`)
    51 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
    52    $this->Database->query('ALTER TABLE `Car`
    53   ADD CONSTRAINT `Car_ibfk_1` FOREIGN KEY (`Owner`) REFERENCES `User` (`Id`),
    54   ADD CONSTRAINT `Car_ibfk_2` FOREIGN KEY (`Model`) REFERENCES `CarModel` (`Id`);');
    55      $this->Database->query('CREATE TABLE `Ride` (
    56   `Id` int(11) NOT NULL AUTO_INCREMENT,
    57   `Driver` int(11) NOT NULL,
    58   `SeatCount` int(11) NOT NULL,
    59   `Car` int(11) NOT NULL,
    60   `Details` text NOT NULL,
    61   PRIMARY KEY (`Id`),
    62   KEY `Driver` (`Driver`),
    63   KEY `Car` (`Car`)
    64 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
    65     $this->Database->query('ALTER TABLE `Ride`
    66   ADD CONSTRAINT `Ride_ibfk_1` FOREIGN KEY (`Driver`) REFERENCES `User` (`Id`),
    67   ADD CONSTRAINT `Ride_ibfk_2` FOREIGN KEY (`Car`) REFERENCES `Car` (`Id`);');
    68     $this->Database->query('CREATE TABLE `RideStop` (
    69   `Id` int(11) NOT NULL AUTO_INCREMENT,
    70   `Ride` int(11) NOT NULL,
    71   `Time` datetime NOT NULL,
    72   `Place` varchar(255) NOT NULL,
    73   `Sequence` int(11) NOT NULL,
    74   `Price` int(11) NOT NULL,
    75   `PassengerCount` int(11) NOT NULL,
    76   PRIMARY KEY (`Id`),
    77   KEY `Ride` (`Ride`)
    78 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
    79     $this->Database->query('ALTER TABLE `RideStop`
    80   ADD CONSTRAINT `RideStop_ibfk_1` FOREIGN KEY (`Ride`) REFERENCES `Ride` (`Id`);');
    81    $this->Database->query('CREATE TABLE `Passenger` (
    82   `Id` int(11) NOT NULL AUTO_INCREMENT,
    83   `Ride` int(11) NOT NULL,
    84   `User` int(11) NOT NULL,
    85   `SeatCount` int(11) NOT NULL,
    86   `RideStopFrom` int(11) NOT NULL,
    87   `RideStopTo` int(11) NOT NULL,
    88   PRIMARY KEY (`Id`),
    89   KEY `User` (`User`),
    90   KEY `Ride` (`Ride`),
    91   KEY `RideStopFrom` (`RideStopFrom`),
    92   KEY `RideStopTo` (`RideStopTo`)
    93 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
    94    $this->Database->query('ALTER TABLE `Passenger`
    95   ADD CONSTRAINT `Passenger_ibfk_1` FOREIGN KEY (`Ride`) REFERENCES `Ride` (`Id`),
    96   ADD CONSTRAINT `Passenger_ibfk_2` FOREIGN KEY (`User`) REFERENCES `User` (`Id`),
    97   ADD CONSTRAINT `Passenger_ibfk_3` FOREIGN KEY (`RideStopFrom`) REFERENCES `RideStop` (`Id`),
    98   ADD CONSTRAINT `Passenger_ibfk_4` FOREIGN KEY (`RideStopTo`) REFERENCES `RideStop` (`Id`);');
    99     $this->InsertData();
    100   }
    101 
    102   function InsertData()
    103   {
    104     $this->Database->query('INSERT INTO `CarManufacturer` (`Id`, `Name`) VALUES '.
    105       '(NULL, "Škoda"), (NULL, "Nissan"), (NULL, "Mitsubishi"), (NULL, "Fiat"), '.
    106       '(NULL, "Dacia"), (NULL, "KIA"), (NULL, "Hyundai"), (NULL, "Ford"), '.
    107       '(NULL, "Opel"), (NULL, "Volkswagen"), (NULL, "Citroen"), (NULL, "Peugeot"), '.
    108       '(NULL, "Tesla"), (NULL, "Audi"), (NULL, "BMW"), (NULL, "Chevrolet"), '.
    109       '(NULL, "Suzuki"), (NULL, "Toyota"), (NULL, "Mercedes-benz"), (NULL, "Seat"),'.
    110       '(NULL, "Volvo"), (NULL, "Renault"), (NULL, "Mazda");');
    111     $this->Database->query('INSERT INTO `CarModel` (`Id`, `Name`, `Manufacturer`) VALUES '.
    112       '(NULL, "Rapid", 1), (NULL, "Octavia", 1), (NULL, "Fabia", 1), (NULL, "Felicia", 1), '.
    113       '(NULL, "Superb", 1);');
    114   }
    115 
    116   function DoUninstall()
    117   {
    118     $this->Database->query('DROP TABLE IF EXISTS `Passenger`');
    119     $this->Database->query('DROP TABLE IF EXISTS `RideStop`');
    120     $this->Database->query('DROP TABLE IF EXISTS `Ride`');
    121     $this->Database->query('DROP TABLE IF EXISTS `Car`');
    122     $this->Database->query('DROP TABLE IF EXISTS `CarModel`');
    123     $this->Database->query('DROP TABLE IF EXISTS `CarManufacturer`');
    124   }
    125 
    126   function DoUpgrade()
    127   {
    128 
    129   }
    130 
    131   function InsertSampleData()
    132   {
    133     $Cities = array('Praha', 'Brno', 'Ostrava', 'Olomouc', 'Liberec', 'Plzeň',
    134       'Humpolec', 'Zlín', 'Přerov', 'České Budějovice', 'Jihlava', 'Ústí nad Labem',
    135       'Hradec Králové', 'Pardubice', 'Mohelnice', 'Břeclav', 'Znojmo', 'Semily',
    136       'Tábor', 'Opava', 'Karviná', 'Pelhřimov', 'Osoblaha', 'Broumov', 'Jirkov',
    137       'Aš', 'Kutná Hora', 'Kolín', 'Strakonice', 'Tachov', 'Domažlice', 'Beroun',
    138       'Most', 'Chomutov', 'Mělník', 'Mladá Boleslav', 'Svitavy', 'Šumperk',
    139       'Litomyšl', 'Chrudim', 'Blansko', 'Hodonín', 'Rosice', 'Uherský Brod',
    140       'Vsetín', 'Nový Jičín', 'Prostějov', 'Vyškov', 'Mohelnice', 'Ústí nad Orlicí');
    141 
    142     for ($I = 0; $I < 100; $I++)
     11    foreach($_SESSION['Track'] as $Index => $TrackItem)
    14312    {
    144       $Stops = array_fill(0, random(5), '');
    145       for ($J = 0; $J < count($Stops); $J++)
    146         $Stops[$J] = $Cities[random(count($Cities))];
    147 
    148       $Ride = new Ride();
    149       $StartTime = time() - random(60*60*24*365);
    150       $StopCount = random(5);
    151       $Ride->Add($Stops, $StartTime, $SeatCount);
     13      $this->Database->insert('RideStop', array(
     14        'Ride' => $RideId,
     15        'Place' => $TrackItem['Destination'],
     16        'Time' => TimeToMysqlDateTime($TrackItem['Time']),
     17        'Price' => $TrackItem['Price'],
     18        'Sequence' => $Index,
     19        'PassengerCount' => 0,
     20      ));
    15221    }
    15322  }
    15423
    155   function ShowLogo()
     24  function GetTrack()
    15625  {
    157     $Output = '<img src="" width="200" height="50" alt="Logo"/> '.
    158       '<a href="'.$this->System->Link('/jizdy/').'">Hledat jízdu</a> nebo '.
    159       '<a href="'.$this->System->Link('/nova-jizda/').'">Nabídnout jízdu</a>';
    160     return $Output;
     26    return($Track);
    16127  }
    16228
    163   function UpdatePassengerCount($RideId)
     29  function Remove($Id)
    16430  {
    165     $DbResult = $this->System->Database->select('RideStop', 'COUNT(*) AS RideStopCount', 'Ride='.$RideId);
    166     $DbRow = $DbResult->fetch_assoc();
    167 
    168     $Stops = array_fill(0, $DbRow['RideStopCount'], 0);
    169     $this->System->Database->update('RideStop', 'Ride='.$RideId, array('PassengerCount' => 0));
    170     $DbResult = $this->System->Database->query('SELECT PassengerRideStopFrom.Sequence AS SequenceFrom, '.
    171         'PassengerRideStopTo.Sequence AS SequenceTo, Passenger.SeatCount FROM Passenger '.
    172         'LEFT JOIN RideStop AS PassengerRideStopFrom ON PassengerRideStopFrom.Id=Passenger.RideStopFrom '.
    173         'LEFT JOIN RideStop AS PassengerRideStopTo ON PassengerRideStopTo.Id=Passenger.RideStopTo '.
    174         'WHERE Passenger.Ride='.$RideId);
    175     while ($DbRow = $DbResult->fetch_assoc())
    176     {
    177       for ($I = $DbRow['SequenceFrom'] + 1; $I <= $DbRow['SequenceTo']; $I++)
    178       {
    179         $Stops[$I] = $Stops[$I] + $DbRow['SeatCount'];
    180       }
    181     }
    182     foreach ($Stops as $Index => $Stop)
    183     {
    184       $this->System->Database->update('RideStop', 'Ride='.$RideId.' AND Sequence='.$Index, array('PassengerCount' => $Stop));
    185     }
     31    $this->Database->delete('Passenger', 'Ride='.$Id);
     32    $this->Database->delete('RideStop', 'Ride='.$Id);
     33    $this->Database->delete('Ride', 'Id='.$Id);
    18634  }
    18735}
    188 
    189 class PageRideDetail extends Page
    190 {
    191   function ShowDetail()
    192   {
    193     $RideId = $_GET['id'];
    194     $DbResult = $this->Database->query('SELECT Ride.Details, Ride.Id, Ride.SeatCount, '.
    195       'RideStopFrom.Id AS RideStopFromId, RideStopTo.Id AS RideStopToId, '.
    196       '(SELECT Name FROM User WHERE User.Id=Ride.Driver) AS DriverName, '.
    197       'CONCAT(CarManufacturer.Name, " ", CarModel.Name) AS CarName FROM Ride '.
    198       'JOIN RideStop AS RideStopFrom ON (RideStopFrom.Ride = Ride.Id) AND (RideStopFrom.Place LIKE "%'.$_GET['from'].'%") '.
    199       'JOIN RideStop AS RideStopTo ON (RideStopTo.Ride = Ride.Id) AND (RideStopTo.Place LIKE "%'.$_GET['to'].'%") '.
    200         'LEFT JOIN Car ON Car.Id = Ride.Car '.
    201       'LEFT JOIN CarModel ON CarModel.Id = Car.Model '.
    202       'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '.
    203       'WHERE Ride.Id='.$RideId);
    204     $DbRow = $DbResult->fetch_assoc();
    205     $Track = array();
    206     $Stops = array();
    207     $DbResult2 = $this->Database->query('SELECT * FROM RideStop WHERE Ride='.$DbRow['Id'].' ORDER BY Sequence');
    208     while ($DbRow2 = $DbResult2->fetch_assoc())
    209     {
    210       $Track[] = $DbRow2;
    211       $Stops[] = $DbRow2['Place'];
    212     }
    213 
    214     $Output = '<h3>Detail jízdy</h3><table>'.
    215       '<tr><td>Trasa:</td><td>'.implode(' → ', $Stops).'</td></tr>'.
    216       '<tr><td>Odjezd z:</td><td>'.$Track[0]['Place'].'</td></tr>'.
    217       '<tr><td>Příjezd do:</td><td>'.$Track[count($Track) - 1]['Place'].'</td></tr>'.
    218       '<tr><td>Čas odjezdu:</td><td>'.$Track[0]['Time'].'</td></tr>'.
    219       '<tr><td>Podrobnosti:</td><td>'.$DbRow['Details'].'</td></tr>';
    220     $Output .= '</table>';
    221     $Output .= '<form action="?step=2" method="post">'.
    222       'Počet míst: <input type="text" name="seats" value="1"/>'.
    223       '<input type="hidden" name="id" value="'.$RideId.'"/>'.
    224       '<input type="hidden" name="fromid" value="'.$DbRow['RideStopFromId'].'"/>'.
    225       '<input type="hidden" name="toid" value="'.$DbRow['RideStopToId'].'"/>'.
    226       '<input type="submit" value="Rezervovat"/>'.
    227       '</form>';
    228 
    229     $Output .= '<h3>Cestující</h3>'.
    230       '<table class="WideTable">';
    231 
    232     // Load passengers table
    233     $Table = array_fill(0, count($Track), array_fill(0, $DbRow['SeatCount'], NULL));
    234     $Passengers = array();
    235     $DbResult = $this->System->Database->query('SELECT User.Name AS UserName, PassengerRideStopFrom.Sequence AS SequenceFrom, '.
    236       'PassengerRideStopTo.Sequence AS SequenceTo FROM Passenger '.
    237       'LEFT JOIN RideStop AS PassengerRideStopFrom ON PassengerRideStopFrom.Id=Passenger.RideStopFrom '.
    238       'LEFT JOIN RideStop AS PassengerRideStopTo ON PassengerRideStopTo.Id=Passenger.RideStopTo '.
    239       'LEFT JOIN User ON User.Id=Passenger.User '.
    240       'WHERE Passenger.Ride='.$RideId);
    241     while ($Passenger = $DbResult->fetch_assoc())
    242     {
    243       $Passengers[] = $Passenger;
    244       $Seat = 0;
    245       do {
    246         $Check = true;
    247         for ($I = $Passenger['SequenceFrom']; $I < $Passenger['SequenceTo']; $I++)
    248         {
    249           if ($Table[$I][$Seat] != 0) $Check = false;
    250         }
    251         if (!$Check) $Seat++;
    252       } while (!$Check);
    253       for ($I = $Passenger['SequenceFrom']; $I < $Passenger['SequenceTo']; $I++)
    254         $Table[$I][$Seat] = count($Passengers) - 1;
    255     }
    256 
    257     $Output .= '<tr><th>Zastávka / Čas</th><th style="width: 80px">Řidič</th>';
    258     for ($I = 0; $I < $DbRow['SeatCount']; $I++)
    259       $Output .= '<th style="width: 80px">Cestující</th>';
    260     $Output .= '</tr>';
    261     foreach ($Track as $Index => $TrackItem)
    262     {
    263       $Output .= '<tr><td style="height: 100px">'.$TrackItem['Place'].'<br/>'.$TrackItem['Time'].'</td>';
    264       if ($Index == 0) $Output .= '<td rowspan="'.count($Track).'">Řidič</td>';
    265       for ($I = 0; $I < $DbRow['SeatCount']; $I++)
    266       {
    267         if (!is_null($Table[$Index][$I])) {
    268           $Passenger = $Passengers[$Table[$Index][$I]];
    269           if ($Index == $Passenger['SequenceFrom'])
    270           $Output .= '<td rowspan="'.($Passenger['SequenceTo'] - $Passenger['SequenceFrom']).'">'.$Passenger['UserName'].'</td>';
    271         } else {
    272           // Show unused space
    273           if (($Index == 0) or ((($Index - 1) >= 0) and (!is_null($Table[$Index - 1][$I]))))
    274           {
    275             $J = 1;
    276             while ((($Index + $J) < count($Table)) and is_null($Table[$Index + $J][$I])) $J++;
    277             $Output .= '<td rowspan="'.$J.'">&nbsp;</td>';
    278           }
    279         }
    280       }
    281       $Output .= '</tr>';
    282     }
    283     $Output .= '</table>';
    284 
    285 
    286     return $Output;
    287   }
    288 
    289   function Show()
    290   {
    291     if (!array_key_exists('step', $_GET)) $Output = $this->ShowDetail();
    292     else {
    293       if ($_GET['step'] == 2) {
    294         $this->System->Database->insert('Passenger', array(
    295           'Ride' => $_POST['id'],
    296           'User' => $this->System->User->User['Id'],
    297           'SeatCount' => $_POST['seats'],
    298           'RideStopFrom' => $_POST['fromid'],
    299           'RideStopTo' => $_POST['toid'],
    300         ));
    301         $this->System->ModuleManager->Modules['Ride']->UpdatePassengerCount($_POST['id']);
    302         $Output = 'Rezervace dokončena';
    303       }
    304     }
    305     return $Output;
    306   }
    307 }
    308 
    309 class PageMain extends Page
    310 {
    311   function Show()
    312   {
    313     if (array_key_exists('from', $_GET)) $PlaceFrom = $_GET['from'];
    314       else $PlaceFrom = '';
    315     if (array_key_exists('to', $_GET)) $PlaceTo = $_GET['to'];
    316       else $PlaceTo = '';
    317     if (array_key_exists('time', $_GET)) $Time = $_GET['time'];
    318       else $Time = '';
    319     $Output = '<table style="width: 100%; margin-top: 100px; margin-bottom: 100px;"><tr><td style="text-align: center">'.
    320       '<div><h3>Vyhledat jízdu</h3>'.
    321       '<form style="display: inline;" method="get" action="'.$this->System->Link('/jizdy/').'">'.
    322       'Odkud: <input type="text" name="from" value="'.$PlaceFrom.'"/> '.
    323       'Kam: <input type="text" name="to" value="'.$PlaceTo.'"/> '.
    324       'Čas: <input type="text" name="time" value="'.$Time.'"/> '.
    325       '<input type="submit" value="Hledat"/>'.
    326       '</form></div></td></tr></table>';
    327     return $Output;
    328   }
    329 }
    330 
    331 class PageRideList extends Page
    332 {
    333   function Show()
    334   {
    335     if (array_key_exists('from', $_GET)) $PlaceFrom = $_GET['from'];
    336       else $PlaceFrom = '';
    337     if (array_key_exists('to', $_GET)) $PlaceTo = $_GET['to'];
    338       else $PlaceTo = '';
    339     if (array_key_exists('time', $_GET)) $Time = $_GET['time'];
    340       else $Time = '';
    341     $Output = '<table style="width: 100%"><tr><td style="text-align: center;">'.
    342       '<form style="display: inline;" method="get" action="'.$this->System->Link('/').'">'.
    343       'Odkud: <input type="text" name="from" value="'.$PlaceFrom.'"/> '.
    344       'Kam: <input type="text" name="to" value="'.$PlaceTo.'"/> '.
    345       'Čas: <input type="text" name="time" value="'.$Time.'"/> '.
    346       '<input type="submit" value="Hledat"/>'.
    347       '</form></td></tr></table>';
    348     if (array_key_exists('from', $_GET) and array_key_exists('to', $_GET)) {
    349       $Output .= $this->ShowRides($_GET['from'], $_GET['to']);
    350     } else $Output .= $this->ShowRides('', '');
    351     return $Output;
    352   }
    353 
    354   function ShowRides($PlaceFrom, $PlaceTo)
    355   {
    356     $Output = '<h3>Jízdy:</h3>';
    357     $Output .= '<table>';
    358     $Query = 'SELECT Ride.Id, Ride.SeatCount, User.Name AS DriverName, User.BirthDate, '.
    359       'CONCAT(CarManufacturer.Name, " ", CarModel.Name) AS CarName ';
    360     if ((trim($PlaceFrom) != '') and (trim($PlaceTo != '')))
    361       $Query .= ', (SELECT COALESCE(MAX(RideStop.PassengerCount), 0) FROM RideStop '.
    362       'WHERE (RideStop.Ride=Ride.Id) AND (RideStop.Sequence > RideStopFrom.Sequence) AND '.
    363       '(RideStop.Sequence <= RideStopTo.Sequence)) AS PassengerCount ';
    364     else
    365       $Query .= ', (SELECT COALESCE(MAX(RideStop.PassengerCount), 0) FROM RideStop '.
    366        'WHERE (RideStop.Ride=Ride.Id)) AS PassengerCount ';
    367 
    368     $Query .= 'FROM Ride '.
    369       'LEFT JOIN Car ON Car.Id = Ride.Car '.
    370       'LEFT JOIN CarModel ON CarModel.Id = Car.Model '.
    371       'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '.
    372       'LEFT JOIN User ON User.Id=Ride.Driver ';
    373     if ((trim($PlaceFrom) != '') and (trim($PlaceTo != '')))
    374       $Query .= 'JOIN RideStop AS RideStopFrom ON (RideStopFrom.Ride = Ride.Id) AND (RideStopFrom.Place LIKE "%'.$PlaceFrom.'%") '.
    375         'JOIN RideStop AS RideStopTo ON (RideStopTo.Ride = Ride.Id) AND (RideStopTo.Place LIKE "%'.$PlaceTo.'%") '.
    376         'WHERE (RideStopFrom.Sequence < RideStopTo.Sequence)';
    377     $Query .= 'LIMIT 10';
    378     $DbResult = $this->Database->query($Query);
    379     while ($DbRow = $DbResult->fetch_assoc())
    380     {
    381       $Stops = array();
    382       $Price = 0;
    383       $DbResult2 = $this->Database->query('SELECT * FROM RideStop WHERE Ride='.$DbRow['Id'].' ORDER BY Sequence');
    384       while ($DbRow2 = $DbResult2->fetch_assoc())
    385       {
    386         $Stops[] = $DbRow2['Place'];
    387         $Price += $DbRow2['Price'];
    388       }
    389 
    390       if ($DbRow['BirthDate'] != '') $Age = ' ('.round((time() - MysqlDateToTime($DbRow['BirthDate'])) / (3600*24*364.25)).' let)';
    391         else $Age = '';
    392       $Output .= '<tr><td>Řidič:</td><td>'.$DbRow['DriverName'].$Age.'</td>'.
    393         '<td colspan="4"><a href="'.$this->System->Link('/jizda/?id='.$DbRow['Id'].'&from='.$PlaceFrom.'&to='.$PlaceTo).'">Ukázat</a></td></tr>'.
    394         '<tr><td>Trasa:</td><td>'.implode(' → ', $Stops).'</td></tr>'.
    395         '<tr><td>Cena:</td><td>'.$Price.' Kč</td></tr>'.
    396         '<tr><td>Volných míst:</td><td>'.($DbRow['SeatCount'] - $DbRow['PassengerCount']).'</td></tr>'.
    397         '<tr><td>Auto:</td><td>'.$DbRow['CarName'].'</td></tr>'.
    398         '<tr><td>&nbsp;</td></tr>';
    399     }
    400     $Output .= '</table>';
    401 
    402     return $Output;
    403   }
    404 }
    405 
    406 function time_elapsed($secs)
    407 {
    408   $bit = array(
    409     'y' => $secs / 31556926 % 12,
    410     'w' => $secs / 604800 % 52,
    411     'd' => $secs / 86400 % 7,
    412     'h' => $secs / 3600 % 24,
    413     'm' => $secs / 60 % 60,
    414     's' => $secs % 60
    415   );
    416 
    417   $ret = array();
    418   foreach ($bit as $k => $v)
    419     if ($v > 0)$ret[] = $v . $k;
    420 
    421   return join(' ', $ret);
    422 }
    423 
    424 class PageNewRide extends Page
    425 {
    426   function Show()
    427   {
    428     if (!array_key_exists('step', $_GET))
    429     {
    430       $Output = '<script>
    431 function insertAfter(referenceNode, newNode)
    432 {
    433     referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
    434 }
    435 
    436 function add_before(name)
    437 {
    438     var objTo = document.getElementById(name)
    439     var divtest = document.createElement("div");
    440     divtest.innerHTML = \'<tr><td>Zastávka:</td><td><input type="text" name="ridestop1"/></td></tr>\';
    441 
    442     objTo.parentNode.insertBefore(divtest, objTo.childNodes[0])
    443 }
    444 
    445 function add_after(name)
    446 {
    447     var objTo = document.getElementById(name)
    448     var divtest = document.createElement("div");
    449     divtest.innerHTML = \'<tr><td>Zastávka:</td><td><input type="text" name="ridestop1"/></td></tr>\';
    450 
    451     insertAfter(objTo, divtest)
    452 }
    453           </script>'.
    454         '<form method="get" action="'.$this->System->Link('/nova-jizda/').'">'.
    455         '<table>'.
    456         '<tr><td colspan="2"><strong>Trasa:</strong></td></tr>'.
    457 
    458         '<tr><td>Počátek:</td><td><input type="text" name="from"/></td></tr>'.
    459         '<tr><td>Zastávka:</td><td><input type="text" name="middle"/></td></tr>'.
    460         '<tr><td>Konec:</td><td><input type="text" name="to"/></td></tr>'.
    461 
    462         '<tr><td colspan="2"><br><strong>Parametry jízdy:</strong></td></tr>'.
    463         '<tr><td>Čas odjezdu:</td><td><input type="text" name="time-from"/></td></tr>'.
    464         '<tr><td>Počet míst pro cestující:</td><td><input type="text" name="seats"/></td></tr>'.
    465         '</table>'.
    466         '<input type="hidden" name="step" value="2"/><br/>'.
    467         '<input type="submit" value="Pokračovat"/>'.
    468         '</form>';
    469     } else {
    470       if ($_GET['step'] == '2') {
    471         $TimeFrom = strtotime($_GET['time-from']);
    472         $Output = '<table style="width: 100%"><tr><td>';
    473         $Output .= '<form method="post" action="'.$this->System->Link('/nova-jizda/?step=3').'">'.
    474         '<input type="hidden" name="from" value="'.$_GET['from'].'"/><br/>'.
    475         '<input type="hidden" name="to" value="'.$_GET['to'].'"/><br/>'.
    476         '<input type="hidden" name="time-from" value="'.$_GET['time-from'].'"/><br/>'.
    477         '<input type="hidden" name="seats" value="'.$_GET['seats'].'"/><br/>'.
    478         '<input type="hidden" name="step" value="3"/><br/>'.
    479         'Popis:<br/><textarea name="desc"></textarea><br/>'.
    480         'Auto: <select name="car">';
    481         $DbResult = $this->Database->query('SELECT Car.Id, CONCAT(CarManufacturer.Name, " ", CarModel.Name) AS ModelName FROM Car '.
    482           'LEFT JOIN CarModel ON CarModel.Id=Car.Model '.
    483           'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '.
    484           'WHERE Car.Owner='.$this->System->User->User['Id']);
    485         while ($DbRow = $DbResult->fetch_assoc())
    486         {
    487           $Output .= '<option value="'.$DbRow['Id'].'"/>'.$DbRow['ModelName'].'</option>';
    488         }
    489         $Output .= '</select>'.
    490           '<input type="submit" value="Vytvořit"/>'.
    491           '</form>';
    492         $Map = new MapGoogle($this->System);
    493         $Map->Key = 'AIzaSyDQ-tOjP9mO8ZpSEuBc5_oCRg30rpQZiBI';
    494         $Map->Width = 400;
    495         $Map->Height = 300;
    496         $Map->Path = array($_GET['from'], $_GET['to']);
    497         //$Map->Path = array('Praha', 'Brno', 'Zlín', 'Vsetín');
    498         $Track = $Map->Route();
    499         $Output .= '<h3>Trasa</h3>';
    500         $PricePerKm = 0.8;
    501         $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>';
    502         foreach ($Track as $Index => $TrackItem)
    503         {
    504           if ($Index > 0)
    505           {
    506             $Track[$Index]['Time'] = $TimeFrom + $Track[$Index - 1]['Duration'];
    507             $RelDistance = $TrackItem['Distance'] - $Track[$Index - 1]['Distance'];
    508             $RelDuration = $TrackItem['Duration'] - $Track[$Index - 1]['Duration'];
    509             $Track[$Index]['Price'] = round($PricePerKm * $RelDistance / 1000);
    510             $Output .= '<tr><td>'.$Map->Path[$Index - 1].' → '.$TrackItem['Destination'].'</td>'.
    511               '<td>'.TimeToMysqlDateTime($Track[$Index]['Time']).'</td>'.
    512               '<td>'.time_elapsed($RelDuration).'</td>'.
    513               '<td>'.round($RelDistance / 1000).'</td>'.
    514               '<td>'.$Track[$Index]['Price'].'</td></tr>';
    515 
    516           } else {
    517             $Track[$Index]['Time'] = $TimeFrom;
    518             $Track[$Index]['Price'] = 0;
    519           }
    520         }
    521         $Output .= '<tr><td>'.$Map->Path[0].' → '.$Map->Path[count($Map->Path) - 1].'</td>'.
    522           '<td>'.TimeToMysqlDateTime($Track[0]['Time']).'</td>'.
    523           '<td>'.time_elapsed($Track[count($Track) - 1]['Duration']).'</td>'.
    524           '<td>'.round($Track[count($Track) - 1]['Distance'] / 1000).'</td>'.
    525           '<td>'.round($PricePerKm * $Track[count($Track) - 1]['Distance'] / 1000).'</td></tr>';
    526         $Output .= '</table><br/>';
    527         $Output .= 'Vzdálenost: '.round($Track[count($Track) - 1]['Distance'] / 1000, 1).' km<br/>';
    528         $Output .= 'Délka jízdy: '.time_elapsed($Track[count($Track) - 1]['Duration']).'<br/>';
    529         $Output .= '</td><td>';
    530         $Map->Key = 'AIzaSyDwKYuEdkXAl9Y2RyDLf5m03n-ItHaqdKs';
    531         $Output .= $Map->Show();
    532         $Output .= '</td></tr></table>';
    533         $_SESSION['Track'] = $Track;
    534         $_SESSION['SeatCount'] = $_GET['seats'];
    535       } else
    536       if ($_GET['step'] == '3') {
    537         $this->Database->insert('Ride', array(
    538           'Driver' => $this->System->User->User['Id'],
    539           'SeatCount' => $_POST['seats'],
    540           'Car' => $_POST['car'],
    541           'Details' => $_POST['desc'],
    542         ));
    543         $RideId = $this->Database->insert_id;
    544         foreach ($_SESSION['Track'] as $Index => $TrackItem)
    545         {
    546           $this->Database->insert('RideStop', array(
    547             'Ride' => $RideId,
    548             'Place' => $TrackItem['Destination'],
    549             'Time' => TimeToMysqlDateTime($TrackItem['Time']),
    550             'Price' => $TrackItem['Price'],
    551             'Sequence' => $Index,
    552             'PassengerCount' => 0,
    553           ));
    554         }
    555         $Output = 'Nová jízda přidána.';
    556       }
    557     }
    558     return $Output;
    559   }
    560 }
    561 
  • trunk/Modules/User/ModuleUser.php

    r7 r8  
    11<?php
    22
    3 include_once(dirname(__FILE__).'/UserModel.php');
    4 include_once(dirname(__FILE__).'/UserList.php');
    5 include_once(dirname(__FILE__).'/UserPage.php');
    6 
    7 class ModuleUser extends AppModule
     3include_once(dirname(__FILE__).'/User.php');
     4include_once(dirname(__FILE__).'/PageUserList.php');
     5include_once(dirname(__FILE__).'/PageUser.php');
     6
     7class ModuleUser extends Module
    88{
    99  var $UserPanel;
     
    2121  }
    2222
    23   function DoInstall()
     23  function DoInstall(): void
    2424  {
    2525    $this->Database->query('CREATE TABLE IF NOT EXISTS `User` ('.
     
    107107  }
    108108
    109   function DoUninstall()
     109  function DoUninstall(): void
    110110  {
    111111    $this->Database->query('DROP TABLE `PermissionUserAssignment`');
     
    117117  }
    118118
    119   function DoUpgrade()
     119  function DoUpgrade(): string
    120120  {
    121121    /*
     
    126126    }
    127127    */
    128   }
    129 
    130   function DoStart()
     128    return '';
     129  }
     130
     131  function DoStart(): void
    131132  {
    132133    $this->System->User = new User($this->System);
     
    281282  }
    282283
    283   function DoStop()
     284  function DoStop(): void
    284285  {
    285286  }
  • trunk/Modules/User/PageUser.php

    r7 r8  
    33class PageUser extends Page
    44{
    5   var $FullTitle = 'Uživatel';
    6   var $ShortTitle = 'Uživatel';
    7   var $ParentClass = 'PagePortal';
     5  function __construct(System $System)
     6  {
     7    parent::__construct($System);
     8    $this->Title = 'Uživatel';
     9    $this->Description = 'Uživatel';
     10    $this->ParentClass = 'PagePortal';
     11  }
    812
    913  function Panel($Title, $Content, $Menu = array())
     
    8892  }
    8993
    90   function Show()
     94  function Show(): string
    9195  {
    9296    $Output = '';
  • trunk/Modules/User/PageUserList.php

    r7 r8  
    33class PageUserList extends Page
    44{
    5   var $FullTitle = 'Seznam registrovaných uživatelů';
    6   var $ShortTitle = 'Seznam uživatelů';
    7   var $ParentClass = 'PagePortal';
     5  function __construct(System $System)
     6  {
     7    parent::__construct($System);
     8    $this->Title = 'Seznam uživatelů';
     9    $this->Description = 'Seznam registrovaných uživatelů';
     10    $this->ParentClass = 'PagePortal';
     11  }
    812
    9   function Show()
     13  function Show(): string
    1014  {
    1115    if (!$this->System->User->CheckPermission('User', 'ShowList'))
  • trunk/Modules/User/User.php

    r7 r8  
    11<?php
     2
     3include_once(dirname(__FILE__).'/PasswordHash.php');
    24
    35define('LOGIN_USED', 'Přihlašovací jméno již použito.');
     
    2830define('DEFAULT_GROUP', 1);
    2931
    30 class PasswordHash
    31 {
    32   function Hash($Password, $Salt)
    33   {
    34     return sha1(sha1($Password).$Salt);
    35   }
    36 
    37   function Verify($Password, $Salt, $StoredHash)
    38   {
    39     return $this->Hash($Password, $Salt) == $StoredHash;
    40   }
    41 
    42   function GetSalt()
    43   {
    44     mt_srand(microtime(true) * 100000 + memory_get_usage(true));
    45     return sha1(uniqid(mt_rand(), true));
    46   }
    47 }
    48 
    4932// TODO: Make User class more general without dependencies to System, Mail, Log
    5033
Note: See TracChangeset for help on using the changeset viewer.