Changeset 27 for branches/3/class/user.php
- Timestamp:
- Oct 13, 2008, 6:52:24 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3/class/user.php
r26 r27 1 1 <?php 2 2 3 class User3 class user 4 4 { // BEGIN class User 5 5 // variables 6 var $ID,$Permission, $ User,$Database;6 var $ID,$Permission, $user,$Database; 7 7 var $AnonymousUserId = 1; 8 var $DefaultRole = 1; 9 var $IPAddress = ' '; 8 10 9 11 // constructor 10 function User($Database)12 function user($Database) 11 13 { // BEGIN constructor 12 14 $this->Database = $Database; … … 18 20 { 19 21 $SID = session_id(); 20 $ IPAddress = gethostbyaddr($_SERVER['REMOTE_ADDR']).' '.$_SERVER['REMOTE_ADDR'];22 $this->IPAddress = gethostbyaddr($_SERVER['REMOTE_ADDR']).' '.$_SERVER['REMOTE_ADDR']; 21 23 // Lookup user record 22 24 $Query = $this->Database->select('UserOnline', '*', 'SessionId="'.$SID.'"'); … … 24 26 { 25 27 // Refresh time of last access 26 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('Time' => 'NOW()','IpAddress' => $ IPAddress));28 $this->Database->update('UserOnline', 'SessionId="'.$SID.'"', array('Time' => 'NOW()','IpAddress' => $this->IPAddress)); 27 29 } else { 28 $this->Database->insert('UserOnline', array('SessionId' => $SID, 'User' => $this->AnonymousUserId, 'Time' => 'NOW()', 'IpAddress' => $ IPAddress));30 $this->Database->insert('UserOnline', array('SessionId' => $SID, 'User' => $this->AnonymousUserId, 'Time' => 'NOW()', 'IpAddress' => $this->IPAddress)); 29 31 } 30 32 // Odeber neaktivní uživatele … … 37 39 { 38 40 $Query = $this->Database->select('User', '*', "Id=".$Row['User'].""); 39 $this-> User = $Query->fetch_array();41 $this->user = $Query->fetch_array(); 40 42 $Result = USER_LOGGED; 41 $this->LoadPermission($this-> User['Permission']);43 $this->LoadPermission($this->user['Permission']); 42 44 } else { 43 45 $Query = $this->Database->select('User', '*', "Id=".$this->AnonymousUserId); 44 $this-> User = $Query->fetch_array();46 $this->user = $Query->fetch_array(); 45 47 $Result = USER_NOT_LOGGED; 46 48 } … … 48 50 } 49 51 50 function Register($ Nick, $Password, $Password2, $Email, $FullName)52 function Register($Date) 51 53 { 52 54 global $Options; 53 if(($ Email == '') || ($Nick == '') || ($Password == '') || ($Password2== '')) $Result = DATA_MISSING;54 else if($ Password != $Password2) $Result = PASSWORDS_UNMATCHED;55 if(($Date['Email'] == '') || ($Date['Nick'] == '') || ($Date['Password'] == '') || ($Date['Password2'] == '')) $Result = DATA_MISSING; 56 else if($Date['Password'] != $Date['Password2']) $Result = PASSWORDS_UNMATCHED; 55 57 else 56 58 { 57 59 // Je uživatel registrován? 58 $Query = $this->Database->select('User', '*', 'Name = "'.$ Nick.'"');59 if($ Query->num_rows()> 0) $Result = NICK_USED;60 $Query = $this->Database->select('User', '*', 'Name = "'.$Date['Nick'].'"'); 61 if($this->Database->Last_num_rows > 0) $Result = NICK_USED; 60 62 else 61 63 { 62 $this->Database->insert('User', array('Name' => addslashes($Nick), 'FullName' => addslashes($FullName), 'Password' => addslashes($Password), 'Email' => htmlspecialchars($Email), 'Role' => $this->DefaultRole)); 64 $this->Database->insert('User', array('Name' => addslashes($Date['Nick']), 'FullName' => addslashes($Date['FullName']), 'Password' => addslashes($Date['Password']), 'Email' => htmlspecialchars($Date['Email']), 'Permission' => $this->DefaultRole, 'TranslationLanguage' => $Date['Language'], 'LastIpAddress' => $this->IPAddress, 'LastLoginTime' => 'NOW()')); 65 //echo $this->Database->LastQuery; 63 66 $Result = USER_REGISTRATED; 64 67 } … … 96 99 function LoadPermission($Permission) 97 100 { 98 $this-> User['Permission'] = array();101 $this->user['Permission'] = array(); 99 102 $DbResult = $this->Database->select('Permission','*','ID='.$Permission); 100 103 if($DbResult->num_rows > 0) 101 104 while($DbRow = $DbResult->fetch_array()) 102 $this-> User['Permission'] = $DbRow;105 $this->user['Permission'] = $DbRow; 103 106 } 104 107 105 108 function WriteRegistration() 106 109 { // BEGIN function WriteRegistration 107 echo '< div id="content"><h2>'.REGISTRATION_PAGE_TITLE.'</h2>108 <form action=" ?reg" method="post">110 echo '<h2>'.REGISTRATION_PAGE_TITLE.'</h2> 111 <form action="" method="post"> 109 112 <table> 110 <tr><td>'.REGISTRATION_PAGE_NAME.'</td><td><input name=" User" type="text" /></td></tr>111 <tr><td>'.REGISTRATION_PAGE_PASS.'</td><td><input name="Pass " type="password" /></td></tr>112 <tr><td>'.REGISTRATION_PAGE_PASS2.'</td><td><input name="Pass 2" type="password" /></td></tr>113 <tr><td>'.REGISTRATION_PAGE_NAME.'</td><td><input name="Nick" type="text" /></td></tr> 114 <tr><td>'.REGISTRATION_PAGE_PASS.'</td><td><input name="Password" type="password" /></td></tr> 115 <tr><td>'.REGISTRATION_PAGE_PASS2.'</td><td><input name="Password2" type="password" /></td></tr> 113 116 <tr><td>'.REGISTRATION_PAGE_EMAIL.'</td><td><input name="Email" type="text" /></td></tr> 114 117 <tr><td>'.REGISTRATION_PAGE_FULLNAME.'</td><td><input name="FullName" type="text" /></td></tr> … … 124 127 <tr><td></td><td><input value="'.REGISTRATION_PAGE_BUTTON.'" type="submit" /></td></tr> 125 128 </table> 126 </form> </div>';129 </form>'; 127 130 } // END function WriteRegistration 128 131
Note:
See TracChangeset
for help on using the changeset viewer.