Location: PHPKode > projects > Php4dvd - movie database > php4dvd/includes/users.inc.php
<?php
/**
================================================================================ 
 LISENCE
================================================================================

    This file is part of php4dvd.

    php4dvd is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    php4dvd is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with php4dvd. If not, see <http://www.gnu.org/licenses/>.
**/

/**
 * Some important variables for other users to work with in code or templates:
 * - 'users' are all users
 */
// Datamanagers
require_once($loc."/lib/db/UserDataManager.class.php");
$userdm = new UserDataManager($db, $settings);

// If the user logged, it can update user information
if($loggedin) {
	// If this is an admin user, it can modify other user information
	if($User->isAdmin()) {
		/***********************************************************
		 * Retrieve all users
		 ***********************************************************/
		$users = $userdm->getAllUsers();
		$w->assign("users", $users);
		
		/***********************************************************
		 * Retrieve the user
		 ***********************************************************/
		if(isset($_GET["id"])) {
			$theuser = $userdm->getUser($_GET["id"]);
			if($theuser)
				$w->assign("theuser", $theuser);
			else
				unset($theuser);
		}
		
		/***********************************************************
		 * Add new user
		 ***********************************************************/
		if($User->isAdmin() && isset($_POST["add"]) && $_POST["add"] == "1") {
			$newuser = new User();
			$newuser = Factory::fillObject($newuser, $_POST);
			$newuser->password = md5($newuser->password);
			
			// No other user with this username?
			if($userdm->existsUser($newuser->username, $newuser->email)) {
				$w->assign("username_error", true);
				$w->assign("newuser", $newuser);
			} else {
				$userdm->add($newuser);
			
				// Go back
				goBack();
			}
		}
		
		/***********************************************************
		 * Remove a user
		 ***********************************************************/
		if(isset($_GET["delete"])) {
			$deleteuser = $userdm->getUser($_GET["delete"]);
			if($deleteuser && $deleteuser->username != "admin")
				$userdm->remove($deleteuser);
			
			// Go back
			goBack();
		}
	}
	
	/***********************************************************
	 * Update user information
	 ***********************************************************/
	if(isset($_POST["update"])) {
		// What user should be updated? 
		if(isset($theuser))
			$updateuser = $theuser;
		else
			$updateuser = $User;
			
		// Save old password
		$oldpassword = $updateuser->password;
		$updateuser = Factory::fillObject($updateuser, $_POST);
		// If the password is set, change it
		if($_POST["password"] != "") {
			$updateuser->password = md5($_POST["password"]);
		}
		// Else, restore old password
		else {
			$updateuser->password = $oldpassword;
		}
		$updateuser->update();
		
		// Go back
		goBack();
	}
}
?>
Return current item: Php4dvd - movie database