Changeset 8 for branches/2/user.php


Ignore:
Timestamp:
May 9, 2008, 10:39:00 AM (17 years ago)
Author:
george
Message:

Přidáno: Oprávnění pro čtení a zápis k rolím a operacím.
Přidáno: Zobrazení matice oprávnění.
Přidáno: Uživatelské menu s proměnným obsahem podle role uživatele.
Upraveno: Rozdělení importu na import z mangosu a import ze staré databáze.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2/user.php

    r7 r8  
    1616class User extends Module
    1717{
    18   var $Roles = array('Člen', 'Uživatel', 'Administrator');
     18  var $Roles = array();
    1919  var $User = array();
     20  var $DefaultRole = 2;
    2021 
    2122  function Check()
    2223  {
    2324    $SID = session_id();
     25
    2426    // Lookup user record
    2527    $Query = $this->Database->select('UserOnline', '*', 'SessionId="'.$SID.'"');
     
    2830      // Refresh time of last access
    2931      $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('Time' => 'NOW()'));
    30     } else $this->Database->insert('UserOnline', array('SessionId' => $SID, 'User' => 0, 'Time' => 'NOW()', 'IpAddress' => (gethostbyaddr(GetRemoteAddress()).' '.GetRemoteAddress()))); 
     32    } else $this->Database->insert('UserOnline', array('SessionId' => $SID, 'User' => 1, 'Time' => 'NOW()', 'IpAddress' => (gethostbyaddr(GetRemoteAddress()).' '.GetRemoteAddress()))); 
    3133
    3234    // Odeber neaktivní uživatele
     
    3840    if($Row['User'] != 0)
    3941    {
    40       $Query = $this->Database->select('User', '*', "Id='".$Row['User']."'");
     42      $Query = $this->Database->select('User', '*', "Id=".$Row['User']."");
    4143      $this->User = $Query->fetch_array();
    4244      $Result = USER_LOGGED;
    4345    } else {
    44       $this->User = array('FullName' => 'Návštěvník', 'Id' => 0, 'Name' => 'Anonym');
     46      $Query = $this->Database->select('User', '*', "Id=1");
     47      $this->User = $Query->fetch_array();
    4548      $Result = USER_NOT_LOGGED;
    4649    }
     50    $this->LoadPermission($this->User['Role']);
     51
     52    // Role and permission
     53    $this->LoadRoles();
     54   
    4755  }
    4856
     
    5967      else
    6068      {
    61         $this->Database->insert('User', array('Name' => addslashes($Nick), 'FullName' => addslashes($FullName), 'Password' => addslashes($Password), 'Email' => htmlspecialchars($Email), 'Permission' => 1));
     69        $this->Database->insert('User', array('Name' => addslashes($Nick), 'FullName' => addslashes($FullName), 'Password' => addslashes($Password), 'Email' => htmlspecialchars($Email), 'Role' => $this->DefaultRole));
    6270        $Result = USER_REGISTRATED;
    6371      }
     
    8997  {
    9098    $SID = session_id();
    91     $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => 0));
     99    $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => 1));
    92100    return(USER_LOGGED_OUT);
     101  }
     102
     103  function LoadRoles()
     104  {
     105    $this->Roles = array();
     106    $DbResult = $this->Database->select('UserRole', '*');
     107    while($DbRow = $DbResult->fetch_array())
     108      $this->Roles[] = $DbRow;
     109  }
     110
     111  function LoadPermission($Role)
     112  {
     113    $this->User['Permission'] = array();
     114    $DbResult = $this->Database->query('SELECT `UserRolePermission`.*, `PermissionOperation`.`Description` FROM `UserRolePermission` JOIN `PermissionOperation` ON `PermissionOperation`.`Id` = `UserRolePermission`.`Operation` WHERE `UserRolePermission`.`Role` = '.$Role);
     115    if($DbResult->num_rows > 0)
     116    while($DbRow = $DbResult->fetch_array())
     117      $this->User['Permission'][$DbRow['Operation']] = $DbRow;
     118  }
     119
     120  function PermissionMatrix()
     121  {
     122    $Result = array();
     123    $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`');
     124    while($DbRow = $DbResult->fetch_array())
     125    {
     126      $Value = '';
     127      if($DbRow['Read']) $Value .= 'R';
     128      if($DbRow['Write']) $Value .= 'W';
     129      $Result[$DbRow['Description']][$DbRow['Title']] = $Value;
     130    }   
     131    return($Result);
    93132  }
    94133}
Note: See TracChangeset for help on using the changeset viewer.