Changeset 8 for branches/2/user.php
- Timestamp:
- May 9, 2008, 10:39:00 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2/user.php
r7 r8 16 16 class User extends Module 17 17 { 18 var $Roles = array( 'Člen', 'Uživatel', 'Administrator');18 var $Roles = array(); 19 19 var $User = array(); 20 var $DefaultRole = 2; 20 21 21 22 function Check() 22 23 { 23 24 $SID = session_id(); 25 24 26 // Lookup user record 25 27 $Query = $this->Database->select('UserOnline', '*', 'SessionId="'.$SID.'"'); … … 28 30 // Refresh time of last access 29 31 $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()))); 31 33 32 34 // Odeber neaktivní uživatele … … 38 40 if($Row['User'] != 0) 39 41 { 40 $Query = $this->Database->select('User', '*', "Id= '".$Row['User']."'");42 $Query = $this->Database->select('User', '*', "Id=".$Row['User'].""); 41 43 $this->User = $Query->fetch_array(); 42 44 $Result = USER_LOGGED; 43 45 } 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(); 45 48 $Result = USER_NOT_LOGGED; 46 49 } 50 $this->LoadPermission($this->User['Role']); 51 52 // Role and permission 53 $this->LoadRoles(); 54 47 55 } 48 56 … … 59 67 else 60 68 { 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)); 62 70 $Result = USER_REGISTRATED; 63 71 } … … 89 97 { 90 98 $SID = session_id(); 91 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => 0));99 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('User' => 1)); 92 100 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); 93 132 } 94 133 }
Note:
See TracChangeset
for help on using the changeset viewer.