Changeset 7 for trunk/Modules


Ignore:
Timestamp:
Apr 14, 2020, 11:13:32 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
Location:
trunk/Modules
Files:
6 edited

Legend:

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

    r4 r7  
    5353  function Geolocate($Text)
    5454  {
    55     return(null);
    56   }
    57 
    58   function Show()
    59   {
    60     return('');
     55    return null;
     56  }
     57
     58  function Show()
     59  {
     60    return '';
    6161  }
    6262
     
    6666    $Result = substr($Text, 0, strpos($Text, $End) - 1);
    6767    $Text = substr($Text, strlen($End));
    68     return($Result);
     68    return $Result;
    6969  }
    7070}
     
    107107        <script>Loader.load()</script>';
    108108
    109     return($Output);
     109    return $Output;
    110110  }
    111111}
     
    117117    $Origins = array();
    118118    $Destinations = array();
    119     foreach($this->Path as $Index => $PathItem)
     119    foreach ($this->Path as $Index => $PathItem)
    120120    if ($Index > 0)
    121121    {
     
    134134      $I++;
    135135    }
    136     return($Points);
     136    return $Points;
    137137  }
    138138
     
    142142    array_shift($WayPoints);
    143143    array_pop($WayPoints);
    144     if(count($WayPoints) > 0)
     144    if (count($WayPoints) > 0)
    145145      $WaypointsQuery = '&waypoints='.implode('|', $WayPoints);
    146146      else $WaypointsQuery = '';
     
    151151      '&destination='.$this->Path[count($this->Path) - 1].''.
    152152      '" style="border: 1px solid black"></iframe>';
    153     return($Output);
     153    return $Output;
    154154  }
    155155}
     
    176176  {
    177177    $this->Points = array();
    178     foreach($TextPathItems as $TextPathItem)
     178    foreach ($TextPathItems as $TextPathItem)
    179179    {
    180180      $Result = $this->Geolocate($TextPathItem);
     
    184184
    185185    $WayPoints = array();
    186     foreach($this->Points as $Point)
     186    foreach ($this->Points as $Point)
    187187    {
    188188      $WayPoints[] = $Point['Longitude'];
     
    208208    $Points = array();
    209209    $Separator = '<gml:pos>';
    210     while(strpos($Result, $Separator) !== false)
     210    while (strpos($Result, $Separator) !== false)
    211211    {
    212212      $Result = substr($Result, strpos($Result, $Separator) + strlen($Separator));
     
    215215      $Points[] = array('Longitude' => $PosParts[0], 'Latitude' => $PosParts[1]);
    216216    }
    217     return(array('TotalDistance' => $TotalDistance, 'TotalTime' => $TotalTime,
    218       'Points' => $Points));
     217    return array('TotalDistance' => $TotalDistance, 'TotalTime' => $TotalTime,
     218      'Points' => $Points);
    219219  }
    220220
     
    222222  {
    223223    $WayPoints = array();
    224     foreach($this->Points as $Point)
     224    foreach ($this->Points as $Point)
    225225    {
    226226      $WayPoints[] = $Point['Longitude'];
  • trunk/Modules/Ride/Ride.php

    r6 r7  
    140140      'Vsetín', 'Nový Jičín', 'Prostějov', 'Vyškov', 'Mohelnice', 'Ústí nad Orlicí');
    141141
    142     for($I = 0; $I < 100; $I++)
     142    for ($I = 0; $I < 100; $I++)
    143143    {
    144144      $Stops = array_fill(0, random(5), '');
    145       for($J = 0; $J < count($Stops); $J++)
     145      for ($J = 0; $J < count($Stops); $J++)
    146146        $Stops[$J] = $Cities[random(count($Cities))];
    147147
     
    158158      '<a href="'.$this->System->Link('/jizdy/').'">Hledat jízdu</a> nebo '.
    159159      '<a href="'.$this->System->Link('/nova-jizda/').'">Nabídnout jízdu</a>';
    160     return($Output);
     160    return $Output;
    161161  }
    162162
     
    173173        'LEFT JOIN RideStop AS PassengerRideStopTo ON PassengerRideStopTo.Id=Passenger.RideStopTo '.
    174174        'WHERE Passenger.Ride='.$RideId);
    175     while($DbRow = $DbResult->fetch_assoc())
    176     {
    177       for($I = $DbRow['SequenceFrom'] + 1; $I <= $DbRow['SequenceTo']; $I++)
     175    while ($DbRow = $DbResult->fetch_assoc())
     176    {
     177      for ($I = $DbRow['SequenceFrom'] + 1; $I <= $DbRow['SequenceTo']; $I++)
    178178      {
    179179        $Stops[$I] = $Stops[$I] + $DbRow['SeatCount'];
    180180      }
    181181    }
    182     foreach($Stops as $Index => $Stop)
     182    foreach ($Stops as $Index => $Stop)
    183183    {
    184184      $this->System->Database->update('RideStop', 'Ride='.$RideId.' AND Sequence='.$Index, array('PassengerCount' => $Stop));
     
    206206    $Stops = array();
    207207    $DbResult2 = $this->Database->query('SELECT * FROM RideStop WHERE Ride='.$DbRow['Id'].' ORDER BY Sequence');
    208     while($DbRow2 = $DbResult2->fetch_assoc())
     208    while ($DbRow2 = $DbResult2->fetch_assoc())
    209209    {
    210210      $Track[] = $DbRow2;
     
    239239      'LEFT JOIN User ON User.Id=Passenger.User '.
    240240      'WHERE Passenger.Ride='.$RideId);
    241     while($Passenger = $DbResult->fetch_assoc())
     241    while ($Passenger = $DbResult->fetch_assoc())
    242242    {
    243243      $Passengers[] = $Passenger;
     
    245245      do {
    246246        $Check = true;
    247         for($I = $Passenger['SequenceFrom']; $I < $Passenger['SequenceTo']; $I++)
     247        for ($I = $Passenger['SequenceFrom']; $I < $Passenger['SequenceTo']; $I++)
    248248        {
    249           if($Table[$I][$Seat] != 0) $Check = false;
     249          if ($Table[$I][$Seat] != 0) $Check = false;
    250250        }
    251251        if (!$Check) $Seat++;
    252       } while(!$Check);
    253       for($I = $Passenger['SequenceFrom']; $I < $Passenger['SequenceTo']; $I++)
     252      } while (!$Check);
     253      for ($I = $Passenger['SequenceFrom']; $I < $Passenger['SequenceTo']; $I++)
    254254        $Table[$I][$Seat] = count($Passengers) - 1;
    255255    }
     
    259259      $Output .= '<th style="width: 80px">Cestující</th>';
    260260    $Output .= '</tr>';
    261     foreach($Track as $Index => $TrackItem)
     261    foreach ($Track as $Index => $TrackItem)
    262262    {
    263263      $Output .= '<tr><td style="height: 100px">'.$TrackItem['Place'].'<br/>'.$TrackItem['Time'].'</td>';
    264       if($Index == 0) $Output .= '<td rowspan="'.count($Track).'">Řidič</td>';
     264      if ($Index == 0) $Output .= '<td rowspan="'.count($Track).'">Řidič</td>';
    265265      for ($I = 0; $I < $DbRow['SeatCount']; $I++)
    266266      {
     
    271271        } else {
    272272          // Show unused space
    273           if(($Index == 0) or ((($Index - 1) >= 0) and (!is_null($Table[$Index - 1][$I]))))
     273          if (($Index == 0) or ((($Index - 1) >= 0) and (!is_null($Table[$Index - 1][$I]))))
    274274          {
    275275            $J = 1;
    276             while((($Index + $J) < count($Table)) and is_null($Table[$Index + $J][$I])) $J++;
     276            while ((($Index + $J) < count($Table)) and is_null($Table[$Index + $J][$I])) $J++;
    277277            $Output .= '<td rowspan="'.$J.'">&nbsp;</td>';
    278278          }
     
    284284
    285285
    286     return($Output);
     286    return $Output;
    287287  }
    288288
     
    303303      }
    304304    }
    305     return($Output);
     305    return $Output;
    306306  }
    307307}
     
    311311  function Show()
    312312  {
    313     if(array_key_exists('from', $_GET)) $PlaceFrom = $_GET['from'];
     313    if (array_key_exists('from', $_GET)) $PlaceFrom = $_GET['from'];
    314314      else $PlaceFrom = '';
    315     if(array_key_exists('to', $_GET)) $PlaceTo = $_GET['to'];
     315    if (array_key_exists('to', $_GET)) $PlaceTo = $_GET['to'];
    316316      else $PlaceTo = '';
    317     if(array_key_exists('time', $_GET)) $Time = $_GET['time'];
     317    if (array_key_exists('time', $_GET)) $Time = $_GET['time'];
    318318      else $Time = '';
    319319    $Output = '<table style="width: 100%; margin-top: 100px; margin-bottom: 100px;"><tr><td style="text-align: center">'.
     
    325325      '<input type="submit" value="Hledat"/>'.
    326326      '</form></div></td></tr></table>';
    327     return($Output);
     327    return $Output;
    328328  }
    329329}
     
    333333  function Show()
    334334  {
    335     if(array_key_exists('from', $_GET)) $PlaceFrom = $_GET['from'];
     335    if (array_key_exists('from', $_GET)) $PlaceFrom = $_GET['from'];
    336336      else $PlaceFrom = '';
    337     if(array_key_exists('to', $_GET)) $PlaceTo = $_GET['to'];
     337    if (array_key_exists('to', $_GET)) $PlaceTo = $_GET['to'];
    338338      else $PlaceTo = '';
    339     if(array_key_exists('time', $_GET)) $Time = $_GET['time'];
     339    if (array_key_exists('time', $_GET)) $Time = $_GET['time'];
    340340      else $Time = '';
    341341    $Output = '<table style="width: 100%"><tr><td style="text-align: center;">'.
     
    349349      $Output .= $this->ShowRides($_GET['from'], $_GET['to']);
    350350    } else $Output .= $this->ShowRides('', '');
    351     return($Output);
     351    return $Output;
    352352  }
    353353
     
    358358    $Query = 'SELECT Ride.Id, Ride.SeatCount, User.Name AS DriverName, User.BirthDate, '.
    359359      'CONCAT(CarManufacturer.Name, " ", CarModel.Name) AS CarName ';
    360     if((trim($PlaceFrom) != '') and (trim($PlaceTo != '')))
     360    if ((trim($PlaceFrom) != '') and (trim($PlaceTo != '')))
    361361      $Query .= ', (SELECT COALESCE(MAX(RideStop.PassengerCount), 0) FROM RideStop '.
    362362      'WHERE (RideStop.Ride=Ride.Id) AND (RideStop.Sequence > RideStopFrom.Sequence) AND '.
     
    371371      'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '.
    372372      'LEFT JOIN User ON User.Id=Ride.Driver ';
    373     if((trim($PlaceFrom) != '') and (trim($PlaceTo != '')))
     373    if ((trim($PlaceFrom) != '') and (trim($PlaceTo != '')))
    374374      $Query .= 'JOIN RideStop AS RideStopFrom ON (RideStopFrom.Ride = Ride.Id) AND (RideStopFrom.Place LIKE "%'.$PlaceFrom.'%") '.
    375375        'JOIN RideStop AS RideStopTo ON (RideStopTo.Ride = Ride.Id) AND (RideStopTo.Place LIKE "%'.$PlaceTo.'%") '.
     
    377377    $Query .= 'LIMIT 10';
    378378    $DbResult = $this->Database->query($Query);
    379     while($DbRow = $DbResult->fetch_assoc())
     379    while ($DbRow = $DbResult->fetch_assoc())
    380380    {
    381381      $Stops = array();
    382382      $Price = 0;
    383383      $DbResult2 = $this->Database->query('SELECT * FROM RideStop WHERE Ride='.$DbRow['Id'].' ORDER BY Sequence');
    384       while($DbRow2 = $DbResult2->fetch_assoc())
     384      while ($DbRow2 = $DbResult2->fetch_assoc())
    385385      {
    386386        $Stops[] = $DbRow2['Place'];
     
    400400    $Output .= '</table>';
    401401
    402     return($Output);
     402    return $Output;
    403403  }
    404404}
     
    416416
    417417  $ret = array();
    418   foreach($bit as $k => $v)
    419     if($v > 0)$ret[] = $v . $k;
     418  foreach ($bit as $k => $v)
     419    if ($v > 0)$ret[] = $v . $k;
    420420
    421421  return join(' ', $ret);
     
    483483          'LEFT JOIN CarManufacturer ON CarManufacturer.Id = CarModel.Manufacturer '.
    484484          'WHERE Car.Owner='.$this->System->User->User['Id']);
    485         while($DbRow = $DbResult->fetch_assoc())
     485        while ($DbRow = $DbResult->fetch_assoc())
    486486        {
    487487          $Output .= '<option value="'.$DbRow['Id'].'"/>'.$DbRow['ModelName'].'</option>';
     
    500500        $PricePerKm = 0.8;
    501501        $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)
     502        foreach ($Track as $Index => $TrackItem)
    503503        {
    504           if($Index > 0)
     504          if ($Index > 0)
    505505          {
    506506            $Track[$Index]['Time'] = $TimeFrom + $Track[$Index - 1]['Duration'];
     
    542542        ));
    543543        $RideId = $this->Database->insert_id;
    544         foreach($_SESSION['Track'] as $Index => $TrackItem)
     544        foreach ($_SESSION['Track'] as $Index => $TrackItem)
    545545        {
    546546          $this->Database->insert('RideStop', array(
     
    556556      }
    557557    }
    558     return($Output);
    559   }
    560 }
    561 
     558    return $Output;
     559  }
     560}
     561
  • trunk/Modules/User/User.php

    r5 r7  
    121121    /*
    122122
    123      if($this->InstalledVersion == '1.0') {
     123     if ($this->InstalledVersion == '1.0') {
    124124      $this->System->Database->Query('SELECT * FROM User WHERE Id=1');
    125125      $this->InstalledVersion = '1.1';
     
    131131  {
    132132    $this->System->User = new User($this->System);
    133     if(isset($_SERVER['REMOTE_ADDR'])) $this->System->User->Check();
     133    if (isset($_SERVER['REMOTE_ADDR'])) $this->System->User->Check();
    134134    $this->System->RegisterPage('userlist', 'PageUserList');
    135135    $this->System->RegisterPage('user', 'PageUser');
     
    287287  function TopBarCallback()
    288288  {
    289     if($this->System->User->User['Id'] == null)
     289    if ($this->System->User->User['Id'] == null)
    290290    {
    291291      $Output = '<a href="'.$this->System->Link('/user/?Action=LoginForm').'">Přihlášení</a> '.
     
    298298      //   <a href="'.$this->System->Link('/?Action=UserOptions').'">Nastavení</a>';
    299299    }
    300     return($Output);
     300    return $Output;
    301301  }
    302302}
  • trunk/Modules/User/UserList.php

    r1 r7  
    99  function Show()
    1010  {
    11     if(!$this->System->User->CheckPermission('User', 'ShowList'))
    12       return('Nemáte oprávnění');
     11    if (!$this->System->User->CheckPermission('User', 'ShowList'))
     12      return 'Nemáte oprávnění';
    1313
    1414    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `User`');
     
    3030
    3131    $DbResult = $this->Database->query($Query);
    32     while($User = $DbResult->fetch_assoc())
     32    while ($User = $DbResult->fetch_assoc())
    3333    {
    3434      $Devices = array();
    3535      $DbResult2 = $this->Database->query('SELECT `Id` FROM `Member` WHERE `Member`.`ResponsibleUser` = '.$User['Id']);
    36       while($Member = $DbResult2->fetch_assoc())
     36      while ($Member = $DbResult2->fetch_assoc())
    3737      {
    3838        $DbResult3 = $this->Database->query('SELECT `Name`, `Id` FROM `NetworkDevice` '.
    3939          'WHERE `Member` = '.$Member['Id'].' AND `Used`=1 ORDER BY `Name`');
    40         while($Device = $DbResult3->fetch_assoc())
     40        while ($Device = $DbResult3->fetch_assoc())
    4141        {
    4242          $Devices[] = $Device['Name'];
     
    5252    $Output .= $PageList['Output'];
    5353
    54     return($Output);
     54    return $Output;
    5555  }
    5656}
  • trunk/Modules/User/UserModel.php

    r6 r7  
    3232  function Hash($Password, $Salt)
    3333  {
    34     return(sha1(sha1($Password).$Salt));
     34    return sha1(sha1($Password).$Salt);
    3535  }
    3636
    3737  function Verify($Password, $Salt, $StoredHash)
    3838  {
    39     return($this->Hash($Password, $Salt) == $StoredHash);
     39    return $this->Hash($Password, $Salt) == $StoredHash;
    4040  }
    4141
     
    7373    // Lookup user record
    7474    $Query = $this->Database->select('UserOnline', '*', 'SessionId="'.$SID.'"');
    75     if($Query->num_rows > 0)
     75    if ($Query->num_rows > 0)
    7676    {
    7777      // Refresh time of last access
     
    8383
    8484    // Logged permanently?
    85     if(array_key_exists('LoginHash', $_COOKIE))
     85    if (array_key_exists('LoginHash', $_COOKIE))
    8686    {
    8787      $DbResult = $this->Database->query('SELECT * FROM `UserOnline` WHERE `User`='.$_COOKIE['LoginUserId'].
    8888        ' AND `StayLogged`=1 AND SessionId!="'.$SID.'"');
    89       if($DbResult->num_rows > 0)
     89      if ($DbResult->num_rows > 0)
    9090      {
    9191        $DbRow = $DbResult->fetch_assoc();
    92         if(sha1($_COOKIE['LoginUserId'].$DbRow['StayLoggedHash']) == $_COOKIE['LoginHash'])
     92        if (sha1($_COOKIE['LoginUserId'].$DbRow['StayLoggedHash']) == $_COOKIE['LoginHash'])
    9393        {
    9494          $this->Database->query('DELETE FROM `UserOnline` WHERE `SessionId`="'.$SID.'"');
     
    101101    $Query = $this->Database->select('UserOnline', '*', '`SessionId`="'.$SID.'"');
    102102    $Row = $Query->fetch_assoc();
    103     if($Row['User'] != '')
     103    if ($Row['User'] != '')
    104104    {
    105105      $Query = $this->Database->query('SELECT `User`.* FROM `User` '.
     
    116116    // Remove nonactive users
    117117    $DbResult = $this->Database->select('UserOnline', '`Id`, `User`', '(`ActivityTime` < DATE_SUB(NOW(), INTERVAL '.$this->OnlineStateTimeout.' SECOND)) AND (`StayLogged` = 0)');
    118     while($DbRow = $DbResult->fetch_array())
     118    while ($DbRow = $DbResult->fetch_array())
    119119    {
    120120      $this->Database->delete('UserOnline', 'Id='.$DbRow['Id']);
    121       if(($DbRow['User'] != null) and $this->System->ModuleManager->ModulePresent('Log'))
     121      if (($DbRow['User'] != null) and $this->System->ModuleManager->ModulePresent('Log'))
    122122        $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Logout');
    123123    }
     
    130130  function Register($Login, $Password, $Password2, $Email, $Name)
    131131  {
    132     if(($Email == '') || ($Login == '') || ($Password == '') || ($Password2 == '')  || ($Name == '')) $Result = DATA_MISSING;
    133     else if($Password != $Password2) $Result = PASSWORDS_UNMATCHED;
     132    if (($Email == '') || ($Login == '') || ($Password == '') || ($Password2 == '')  || ($Name == '')) $Result = DATA_MISSING;
     133    else if ($Password != $Password2) $Result = PASSWORDS_UNMATCHED;
    134134    else
    135135    {
    136136      // Is user registred yet?
    137137      $Query = $this->Database->select('User', '*', 'Login = "'.$Login.'"');
    138       if($Query->num_rows > 0) $Result = LOGIN_USED;
     138      if ($Query->num_rows > 0) $Result = LOGIN_USED;
    139139      else
    140140      {
    141141        $Query = $this->Database->select('User', '*', 'Name = "'.$Name.'"');
    142         if($Query->num_rows > 0) $Result = NAME_USED;
     142        if ($Query->num_rows > 0) $Result = NAME_USED;
    143143        else
    144144        {
    145145          $Query = $this->Database->select('User', '*', 'Email = "'.$Email.'"');
    146           if($Query->num_rows > 0) $Result = EMAIL_USED;
     146          if ($Query->num_rows > 0) $Result = EMAIL_USED;
    147147          else
    148148          {
     
    175175
    176176            $Result = USER_REGISTRATED;
    177             if($this->System->ModuleManager->ModulePresent('Log'))
     177            if ($this->System->ModuleManager->ModulePresent('Log'))
    178178              $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'NewRegistration', $Login);
    179179          }
     
    181181      }
    182182    }
    183     return($Result);
     183    return $Result;
    184184  }
    185185
     
    187187  {
    188188    $DbResult = $this->Database->select('User', 'Id, Login, Password', 'Id = '.$Id);
    189     if($DbResult->num_rows > 0)
     189    if ($DbResult->num_rows > 0)
    190190    {
    191191      $Row = $DbResult->fetch_array();
    192192      $NewPassword = substr(sha1(strtoupper($Row['Login'])), 0, 7);
    193       if($Hash == $NewPassword)
     193      if ($Hash == $NewPassword)
    194194      {
    195195        $this->Database->update('User', 'Id='.$Row['Id'], array('Locked' => 0));
    196196        $Output = USER_REGISTRATION_CONFIRMED;
    197         if($this->System->ModuleManager->ModulePresent('Log'))
     197        if ($this->System->ModuleManager->ModulePresent('Log'))
    198198          $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'RegisterConfirm', 'Login='.
    199199            $Row['Login'].', Id='.$Row['Id']);
    200200      } else $Output = PASSWORDS_UNMATCHED;
    201201    } else $Output = USER_NOT_FOUND;
    202     return($Output);
     202    return $Output;
    203203  }
    204204
    205205  function Login($Login, $Password, $StayLogged = false)
    206206  {
    207     if($StayLogged) $StayLogged = 1; else $StayLogged = 0;
     207    if ($StayLogged) $StayLogged = 1; else $StayLogged = 0;
    208208    $SID = session_id();
    209209    $Query = $this->Database->select('User', '*', 'Login="'.$Login.'"');
    210     if($Query->num_rows > 0)
     210    if ($Query->num_rows > 0)
    211211    {
    212212      $Row = $Query->fetch_assoc();
    213213      $PasswordHash = new PasswordHash();
    214       if(!$PasswordHash->Verify($Password, $Row['Salt'], $Row['Password'])) $Result = BAD_PASSWORD;
    215       else if($Row['Locked'] == 1) $Result = ACCOUNT_LOCKED;
     214      if (!$PasswordHash->Verify($Password, $Row['Salt'], $Row['Password'])) $Result = BAD_PASSWORD;
     215      else if ($Row['Locked'] == 1) $Result = ACCOUNT_LOCKED;
    216216      else
    217217      {
     
    222222        $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array(
    223223          'User' => $Row['Id'], 'StayLogged' => $StayLogged, 'StayLoggedHash' => $StayLoggedSalt));
    224         if($StayLogged)
     224        if ($StayLogged)
    225225        {
    226226          setcookie('LoginUserId', $Row['Id'], time()+365*24*60*60, $this->System->Link('/'));
     
    233233        $Result = USER_LOGGED_IN;
    234234        $this->Check();
    235         if(array_key_exists('Log', $this->System->ModuleManager->Modules))
     235        if (array_key_exists('Log', $this->System->ModuleManager->Modules))
    236236          $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Login', 'Login='.$Login.',Host='.gethostbyaddr(GetRemoteAddress()));
    237237      }
    238238    } else $Result = USER_NOT_REGISTRED;
    239     return($Result);
     239    return $Result;
    240240  }
    241241
     
    244244    $SID = session_id();
    245245    $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => null));
    246     if($this->System->ModuleManager->ModulePresent('Log'))
     246    if ($this->System->ModuleManager->ModulePresent('Log'))
    247247      $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'Logout', $this->User['Login']);
    248248    $this->Check();
    249     return(USER_LOGGED_OUT);
     249    return USER_LOGGED_OUT;
    250250  }
    251251
     
    254254    $this->Roles = array();
    255255    $DbResult = $this->Database->select('UserRole', '*');
    256     while($DbRow = $DbResult->fetch_array())
     256    while ($DbRow = $DbResult->fetch_array())
    257257      $this->Roles[] = $DbRow;
    258258  }
     
    262262    $this->User['Permission'] = array();
    263263    $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description` FROM `UserRolePermission` JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` WHERE `UserRolePermission`.`Role` = '.$Role);
    264     if($DbResult->num_rows > 0)
    265     while($DbRow = $DbResult->fetch_array())
     264    if ($DbResult->num_rows > 0)
     265    while ($DbRow = $DbResult->fetch_array())
    266266      $this->User['Permission'][$DbRow['Operation']] = $DbRow;
    267267  }
     
    271271    $Result = array();
    272272    $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description`, `UserRole`.`Title` FROM `UserRolePermission` LEFT JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` LEFT JOIN `UserRole` ON `UserRole`.`Id` = `UserRolePermission`.`Role`');
    273     while($DbRow = $DbResult->fetch_array())
     273    while ($DbRow = $DbResult->fetch_array())
    274274    {
    275275      $Value = '';
    276       if($DbRow['Read']) $Value .= 'R';
    277       if($DbRow['Write']) $Value .= 'W';
     276      if ($DbRow['Read']) $Value .= 'R';
     277      if ($DbRow['Write']) $Value .= 'W';
    278278      $Result[$DbRow['Description']][$DbRow['Title']] = $Value;
    279279    }
    280     return($Result);
     280    return $Result;
    281281  }
    282282
     
    285285    $PermissionExists = false;
    286286    // First try to check cache group-group relation
    287     if(array_key_exists($GroupId, $this->PermissionGroupCache))
     287    if (array_key_exists($GroupId, $this->PermissionGroupCache))
    288288    {
    289289      $PermissionExists = true;
     
    294294        '") AND (`AssignedGroup` IS NOT NULL)');
    295295      $DbRow = array();
    296       while($DbRow[] = $DbResult->fetch_array());
     296      while ($DbRow[] = $DbResult->fetch_array());
    297297        $this->PermissionGroupCache[$GroupId] = $DbRow;
    298298      $PermissionExists = true;
    299299    }
    300     if($PermissionExists)
    301     {
    302       foreach($this->PermissionGroupCache[$GroupId] as $DbRow)
    303       {
    304         if($DbRow['AssignedGroup'] != '')
    305         if($this->CheckGroupPermission($DbRow['AssignedGroup'], $OperationId) == true) return(true);
     300    if ($PermissionExists)
     301    {
     302      foreach ($this->PermissionGroupCache[$GroupId] as $DbRow)
     303      {
     304        if ($DbRow['AssignedGroup'] != '')
     305        if ($this->CheckGroupPermission($DbRow['AssignedGroup'], $OperationId) == true) return true;
    306306      }
    307307    }
    308308
    309309    // Check group-operation relation
    310     if(array_key_exists($GroupId.','.$OperationId, $this->PermissionGroupCacheOp))
     310    if (array_key_exists($GroupId.','.$OperationId, $this->PermissionGroupCacheOp))
    311311    {
    312312      $PermissionExists = true;
     
    315315      // If no permission combination exists in cache, do new check of database items
    316316      $DbResult = $this->Database->select('PermissionGroupAssignment', '*', '`Group`="'.$GroupId.'" AND `AssignedOperation`="'.$OperationId.'"');
    317       if($DbResult->num_rows > 0) $this->PermissionGroupCacheOp[$GroupId.','.$OperationId] = true;
     317      if ($DbResult->num_rows > 0) $this->PermissionGroupCacheOp[$GroupId.','.$OperationId] = true;
    318318        else $this->PermissionGroupCacheOp[$GroupId.','.$OperationId] = false;
    319319      $PermissionExists = true;
    320320    }
    321     if($PermissionExists)
    322     {
    323       return($this->PermissionGroupCacheOp[$GroupId.','.$OperationId]);
    324     }
    325     return(false);
     321    if ($PermissionExists)
     322    {
     323      return $this->PermissionGroupCacheOp[$GroupId.','.$OperationId];
     324    }
     325    return false;
    326326  }
    327327
     
    330330    // Get module id
    331331    $DbResult = $this->Database->select('Module', 'Id', '`Name`="'.$Module.'"');
    332     if($DbResult->num_rows > 0)
     332    if ($DbResult->num_rows > 0)
    333333    {
    334334      $DbRow = $DbResult->fetch_assoc();
    335335      $ModuleId = $DbRow['Id'];
    336     } else return(false);
     336    } else return false;
    337337
    338338    // First try to check cache
    339     if(in_array(array($Module, $Operation, $ItemType, $ItemType), $this->PermissionCache))
     339    if (in_array(array($Module, $Operation, $ItemType, $ItemType), $this->PermissionCache))
    340340    {
    341341      $OperationId = array_search(array($Module, $Operation, $ItemType, $ItemIndex), $this->PermissionCache);
     
    346346      $DbResult = $this->Database->select('PermissionOperation', 'Id', '(`Module`="'.$ModuleId.
    347347        '") AND (`Item`="'.$ItemType.'") AND (`ItemId`='.$ItemIndex.') AND (`Operation`="'.$Operation.'")');
    348       if($DbResult->num_rows > 0)
     348      if ($DbResult->num_rows > 0)
    349349      {
    350350        $DbRow = $DbResult->fetch_array();
     
    359359    }
    360360
    361     if($PermissionExists)
    362     {
    363       if($this->User['Id'] == null) $UserCondition = '(`User` IS NULL)';
     361    if ($PermissionExists)
     362    {
     363      if ($this->User['Id'] == null) $UserCondition = '(`User` IS NULL)';
    364364        else $UserCondition = '(`User`="'.$this->User['Id'].'")';
    365365      // Check user-operation relation
    366366      $DbResult = $this->Database->select('PermissionUserAssignment', '*', $UserCondition.' AND (`AssignedOperation`="'.$OperationId.'")');
    367       if($DbResult->num_rows > 0) return(true);
     367      if ($DbResult->num_rows > 0) return true;
    368368
    369369      // Check user-group relation
    370370      $DbResult = $this->Database->select('PermissionUserAssignment', 'AssignedGroup', $UserCondition);
    371       while($DbRow = $DbResult->fetch_array())
    372       {
    373        if($this->CheckGroupPermission($DbRow['AssignedGroup'], $OperationId) == true) return(true);
    374       }
    375       return(false);
    376     } else return(false);
     371      while ($DbRow = $DbResult->fetch_array())
     372      {
     373       if ($this->CheckGroupPermission($DbRow['AssignedGroup'], $OperationId) == true) return true;
     374      }
     375      return false;
     376    } else return false;
    377377  }
    378378
     
    380380  {
    381381    $DbResult = $this->Database->select('User', 'Login, Name, Id, Email, Password', '`Login`="'.$Login.'" AND `Email`="'.$Email.'"');
    382     if($DbResult->num_rows > 0)
     382    if ($DbResult->num_rows > 0)
    383383    {
    384384      $Row = $DbResult->fetch_array();
     
    399399
    400400      $Output = USER_PASSWORD_RECOVERY_SUCCESS;
    401       if($this->System->ModuleManager->ModulePresent('Log'))
     401      if ($this->System->ModuleManager->ModulePresent('Log'))
    402402        $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'PasswordRecoveryRequest', 'Login='.$Login.',Email='.$Email);
    403403    } else $Output = USER_PASSWORD_RECOVERY_FAIL;
    404     return($Output);
     404    return $Output;
    405405  }
    406406
     
    408408  {
    409409    $DbResult = $this->Database->select('User', 'Id, Login, Password', 'Id = '.$Id);
    410     if($DbResult->num_rows > 0)
     410    if ($DbResult->num_rows > 0)
    411411    {
    412412      $Row = $DbResult->fetch_array();
    413413      $NewPassword2 = substr(sha1(strtoupper($Row['Login'])), 0, 7);
    414       if(($NewPassword == $NewPassword2) and ($Hash == $Row['Password']))
     414      if (($NewPassword == $NewPassword2) and ($Hash == $Row['Password']))
    415415      {
    416416        $PasswordHash = new PasswordHash();
     
    418418        $this->Database->update('User', 'Id='.$Row['Id'], array('Password' => $PasswordHash->Hash($NewPassword, $Salt),
    419419          'Salt' => $Salt, 'Locked' => 0));
    420         if($this->System->ModuleManager->ModulePresent('Log'))
     420        if ($this->System->ModuleManager->ModulePresent('Log'))
    421421          $this->System->ModuleManager->Modules['Log']->NewRecord('User', 'PasswordRecoveryConfirm', 'Login='.$Row['Login']);
    422422      } else $Output = PASSWORDS_UNMATCHED;
    423423    } else $Output = USER_NOT_FOUND;
    424     return($Output);
     424    return $Output;
    425425  }
    426426
     
    428428  {
    429429    $DbResult = $this->Database->select('APIToken', 'User', '`Token`="'.$Token.'"');
    430     if($DbResult->num_rows > 0)
     430    if ($DbResult->num_rows > 0)
    431431    {
    432432      $DbRow = $DbResult->fetch_assoc();
    433433      $User = new User($this->System);
    434434      $User->User = array('Id' => $DbRow['User']);
    435       return($User->CheckPermission($Module, $Operation));
    436     } else return(false);
     435      return $User->CheckPermission($Module, $Operation);
     436    } else return false;
    437437  }
    438438}
  • trunk/Modules/User/UserPage.php

    r1 r7  
    99  function Panel($Title, $Content, $Menu = array())
    1010  {
    11     if(count($Menu) > 0)
    12       foreach($Menu as $Item)
     11    if (count($Menu) > 0)
     12      foreach ($Menu as $Item)
    1313        $Title .= '<div class="Action">'.$Item.'</div>';
    14     return('<div class="Panel"><div class="Title">'.$Title.'</div><div class="Content">'.$Content.'</div></div>');
     14    return '<div class="Panel"><div class="Title">'.$Title.'</div><div class="Content">'.$Content.'</div></div>';
    1515  }
    1616
     
    3939
    4040    $DbResult = $this->Database->query($Query);
    41     while($Contact = $DbResult->fetch_assoc())
     41    while ($Contact = $DbResult->fetch_assoc())
    4242    {
    4343      $Output .= '<tr>'.
     
    5050    $Output .= $PageList['Output'];
    5151
    52     return($Output);
     52    return $Output;
    5353  }
    5454
     
    5656  {
    5757    $Output = '';
    58     if($this->System->User->User['Id'] != null)
     58    if ($this->System->User->User['Id'] != null)
    5959    {
    6060      $Actions = '';
    61       foreach($this->System->ModuleManager->Modules['User']->UserPanel as $Action)
    62       {
    63         if(is_string($Action[0]))
     61      foreach ($this->System->ModuleManager->Modules['User']->UserPanel as $Action)
     62      {
     63        if (is_string($Action[0]))
    6464        {
    6565          $Class = new $Action[0]($this->System);
     
    7171      $Output .= $this->Panel('Nabídka uživatele', $Actions);
    7272      $Output .= '</td><td style="vertical-align:top;">';
    73       if($this->System->User->User['Id'] != null)
     73      if ($this->System->User->User['Id'] != null)
    7474        {
    7575          $Form = new Form($this->System->FormManager);
     
    8585      $Output .= '</td></tr></table></div>';
    8686    } else $Output .= $this->SystemMessage('Oprávnění', 'Nejste přihlášen');
    87     return($Output);
     87    return $Output;
    8888  }
    8989
     
    9191  {
    9292    $Output = '';
    93     if(array_key_exists('Action', $_GET))
     93    if (array_key_exists('Action', $_GET))
    9494    {
    9595      $Action = $_GET['Action'];
    96       if($Action == 'LoginForm')
     96      if ($Action == 'LoginForm')
    9797      {
    9898        $Form = new Form($this->System->FormManager);
     
    103103        '<a href="?Action=PasswordRecovery">Obnova zapomenutého hesla</a></div>';
    104104      } else
    105       if($Action == 'Login')
    106       {
    107         if(array_key_exists('Username', $_POST) and array_key_exists('Password', $_POST))
     105      if ($Action == 'Login')
     106      {
     107        if (array_key_exists('Username', $_POST) and array_key_exists('Password', $_POST))
    108108        {
    109109          $Form = new Form($this->System->FormManager);
    110110          $Form->SetClass('UserLogin');
    111111          $Form->OnSubmit = '?Action=Login';
    112           if(array_key_exists('StayLogged', $_POST) and ($_POST['StayLogged'] == 'on')) $StayLogged = true;
     112          if (array_key_exists('StayLogged', $_POST) and ($_POST['StayLogged'] == 'on')) $StayLogged = true;
    113113            else $StayLogged = false;
    114114          $Result = $this->System->User->Login($_POST['Username'], $_POST['Password'], $StayLogged);
    115115          $Output .= $this->SystemMessage('Přihlášení', $Result);
    116           if($Result <> USER_LOGGED_IN)
     116          if ($Result <> USER_LOGGED_IN)
    117117          {
    118118            $Form->LoadValuesFromForm();
     
    128128        } else $Output .= $this->SystemMessage('Přihlášení', 'Nezadány přihlašovací údaje');
    129129      } else
    130       if($Action == 'Logout')
    131       {
    132         if($this->System->User->User['Id'] != null)
     130      if ($Action == 'Logout')
     131      {
     132        if ($this->System->User->User['Id'] != null)
    133133        {
    134134          $Output .= $this->SystemMessage('Odhlášení', $this->System->User->Logout());
    135135        } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
    136136      } else
    137       if($Action == 'UserOptions')
    138       {
    139         if($this->System->User->User['Id'] != null)
     137      if ($Action == 'UserOptions')
     138      {
     139        if ($this->System->User->User['Id'] != null)
    140140        {
    141141          $Form = new Form($this->System->FormManager);
     
    146146        } else $Output .= $this->SystemMessage('Nastavení uživatele', 'Nejste přihlášen');
    147147      } else
    148       if($Action == 'UserOptionsSave')
     148      if ($Action == 'UserOptionsSave')
    149149      {
    150150        $Form = new Form($this->System->FormManager);
     
    158158        $Output .= $Form->ShowEditForm();
    159159      } else
    160       if($Action == 'UserRegister')
     160      if ($Action == 'UserRegister')
    161161      {
    162162        $Form = new Form($this->System->FormManager);
     
    166166        $Output .= $Form->ShowEditForm();
    167167      } else
    168       if($Action == 'UserRegisterConfirm')
     168      if ($Action == 'UserRegisterConfirm')
    169169      {
    170170        $Output .= $this->SystemMessage('Potvrzení registrace',
    171171          $this->System->User->RegisterConfirm($_GET['User'], $_GET['H']));
    172172      } else
    173       if($Action == 'PasswordRecovery')
     173      if ($Action == 'PasswordRecovery')
    174174      {
    175175        $Form = new Form($this->System->FormManager);
     
    178178        $Output .= $Form->ShowEditForm();
    179179      } else
    180       if($Action == 'PasswordRecovery2')
     180      if ($Action == 'PasswordRecovery2')
    181181      {
    182182        $Form = new Form($this->System->FormManager);
     
    185185        $Result = $this->System->User->PasswordRecoveryRequest($Form->Values['Name'], $Form->Values['Email']);
    186186        $Output .= $this->SystemMessage('Obnova hesla', $Result);
    187         if($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
     187        if ($Result <> USER_PASSWORD_RECOVERY_SUCCESS)
    188188        {
    189189          $Output .= $Form->ShowEditForm();
    190190        }
    191191      } else
    192       if($Action == 'PasswordRecoveryConfirm')
     192      if ($Action == 'PasswordRecoveryConfirm')
    193193      {
    194194        $Output .= $this->SystemMessage('Obnova hesla', $this->System->User->PasswordRecoveryConfirm($_GET['User'], $_GET['H'], $_GET['P']));
    195195      } else
    196       if($Action == 'UserRegisterSave')
     196      if ($Action == 'UserRegisterSave')
    197197      {
    198198        $Form = new Form($this->System->FormManager);
     
    202202          $Form->Values['Password2'], $Form->Values['Email'], $Form->Values['Name']);
    203203        $Output .= $this->SystemMessage('Registrace nového účtu', $Result);
    204         if($Result <> USER_REGISTRATED)
     204        if ($Result <> USER_REGISTRATED)
    205205        {
    206206          $Form->OnSubmit = '?Action=UserRegisterSave';
     
    208208        }
    209209      } else
    210       if($Action == 'UserMenu')
     210      if ($Action == 'UserMenu')
    211211      {
    212212        $Output = $this->ShowUserPanel();
    213213      } else $Output = $this->ShowMain();
    214214    } else $Output = $this->ShowMain();
    215     return($Output);
     215    return $Output;
    216216  }
    217217
     
    219219  {
    220220    $Output = 'Nebyla vybrána akce';
    221     return($Output);
     221    return $Output;
    222222  }
    223223}
Note: See TracChangeset for help on using the changeset viewer.