| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * Handles all data manipulation of the admin part | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | class AdminModel | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | 	 * Sets the deletion and suspension values | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | 	 * @param $suspensionInDays | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | 	 * @param $softDelete | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	 * @param $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	public static function setAccountSuspensionAndDeletionStatus($suspensionInDays, $softDelete, $userId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | 		if ($suspensionInDays > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | 			$suspensionTime = time() + ($suspensionInDays * 60 * 60 * 24); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 			$suspensionTime = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         // FYI "on" is what a checkbox delivers by default when submitted. Didn't know that for a long time :) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		if ($softDelete == "on") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 			$delete = 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | 		} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 			$delete = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 		// write the above info to the database | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 		self::writeDeleteAndSuspensionInfoToDatabase($userId, $suspensionTime, $delete); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | 		// if suspension or deletion should happen, then also kick user out of the application instantly by resetting | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 		// the user's session :) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 		if ($suspensionTime != null OR $delete = 1) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 			self::resetUserSession($userId); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 * Simply write the deletion and suspension info for the user into the database, also puts feedback into session | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | 	 * @param $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	 * @param $suspensionTime | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * @param $delete | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	private static function writeDeleteAndSuspensionInfoToDatabase($userId, $suspensionTime, $delete) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 		$database = DatabaseFactory::getFactory()->getConnection(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | 		$query = $database->prepare("UPDATE users SET user_suspension_timestamp = :user_suspension_timestamp, user_deleted = :user_deleted  WHERE user_id = :user_id LIMIT 1"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 		$query->execute(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 				':user_suspension_timestamp' => $suspensionTime, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 				':user_deleted' => $delete, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 				':user_id' => $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		if ($query->rowCount() == 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 			Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_SUSPENSION_DELETION_STATUS')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | 			return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 * Kicks the selected user out of the system instantly by resetting the user's session. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 * This means, the user will be "logged out". | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	 * @param $userId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 	 * @return bool | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 71 |  |  | 	 */ | 
            
                                                        
            
                                    
            
            
                | 72 |  |  | 	private static function resetUserSession($userId) | 
            
                                                        
            
                                    
            
            
                | 73 |  |  | 	{ | 
            
                                                        
            
                                    
            
            
                | 74 |  |  | 		$database = DatabaseFactory::getFactory()->getConnection(); | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 76 |  |  | 		$query = $database->prepare("UPDATE users SET session_id = :session_id  WHERE user_id = :user_id LIMIT 1"); | 
            
                                                        
            
                                    
            
            
                | 77 |  |  | 		$query->execute(array( | 
            
                                                        
            
                                    
            
            
                | 78 |  |  | 				':session_id' => null, | 
            
                                                        
            
                                    
            
            
                | 79 |  |  | 				':user_id' => $userId | 
            
                                                        
            
                                    
            
            
                | 80 |  |  | 		)); | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 82 |  |  | 		if ($query->rowCount() == 1) { | 
            
                                                        
            
                                    
            
            
                | 83 |  |  | 			Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_USER_SUCCESSFULLY_KICKED')); | 
            
                                                        
            
                                    
            
            
                | 84 |  |  | 			return true; | 
            
                                                        
            
                                    
            
            
                | 85 |  |  | 		} | 
            
                                                        
            
                                    
            
            
                | 86 |  |  | 	} | 
            
                                                        
            
                                    
            
            
                | 87 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |  | 
            
                        
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.