Просмотр файла FFDB/user.php

Размер файла: 6.38Kb
<?php
// +----------------------------------------------------------------------+
// |                      Fantastic File Database                         |
// +----------------------------------------------------------------------+
// |                          By Tony Baird                               |
// |                  Copyright (c) 2003 Fantastic Scripts                |
// |                          http://fscripts.com                         |
// +----------------------------------------------------------------------+
// | Fantastic File Database Can be modified freely as long as copyright  | 
// | is intact and this is left at the top of every source file           |
// +----------------------------------------------------------------------+
// | user.php                                                             |
// | Date Started: February 22, 2003                                      |
// | Last Modified: February 23, 2003                                     |
// +----------------------------------------------------------------------+
Class User {
	//*************************************************/
    // Just Initializing the Register Class sending it
	// to the right function
    //*************************************************/
    function User() {
        global $tpl,$mysql,$online,$ffdb;
		if ($_REQUEST['action']=="login") {
			$this->LoginForm();
		}elseif (isset($_REQUEST['login'])) {
			$this->Login();
		}elseif ($_REQUEST['action']=="user_cp") {
			$this->EditProfileForm();
		}elseif (isset($_REQUEST['edit_profile'])) {
			$this->EditProfile();
		}elseif ($_REQUEST['action']=="logout") {
			$this->Logout();
		}
	}
	//*************************************************/
    // Login Form
    //*************************************************/
	function LoginForm() {
		global $tpl,$mysql,$online,$ffdb;
		$tpl->LoadTemplate("login_form","templates/$online->skin/login_form.tpl");
		$tpl->ParseTemplate("login_form",$login_form_array,"No");
		$tpl->PrintTemplate("login_form");
	}
	//*************************************************/
    // Actuall Logs the User in
    //*************************************************/
	function Login() {
		global $tpl,$mysql,$online,$ffdb,$online,$CONFIG;
		$mysql->Query("SELECT * FROM ffdb_users WHERE username='".$_POST['username']."' AND password='".md5($_POST['password'])."'");
		$show_user=mysql_fetch_array($mysql->result_id);
		if (empty($show_user[user_id])) {
			$online=new Online;
			$ffdb->Header($CONFIG[guest_id]);
			$ffdb->Error("Username and/or Password are incorrect");
		}
			setcookie("username",$_POST['username'],time()+$CONFIG['cookie_time']);
			setcookie("password",md5($_POST['password']),time()+$CONFIG['cookie_time']);
			$_COOKIE['username']=$_POST['username'];
			$_COOKIE['password']=md5($_POST['password']);
			$online=new Online;
			$ffdb->Header($show_user[user_id]);
			$ffdb->Success("You have successfully logged in you can now use the usercp features");
	}
	//*************************************************/
    // Logs User Out
    //*************************************************/
	function LogOut() {
		global $tpl,$mysql,$online,$ffdb,$online,$CONFIG;
		$mysql->Query("SELECT * FROM ffdb_users WHERE username='".$_COOKIE['username']."' AND password='".$_COOKIE['password']."'");
		$show_user=mysql_fetch_array($mysql->result_id);
		if (empty($show_user[user_id])) {
			$online=new Online;
			$ffdb->Header();
			$ffdb->Error("Username and/or Password are incorrect");
		}
		$_COOKIE['username']="";
		$_COOKIE['password']="";
		setcookie("username",$_POST['username'],time()-$CONFIG['cookie_time']);
		setcookie("password",md5($_POST['password']),time()-$CONFIG['cookie_time']);
		$online=new Online;
		$ffdb->Header($show_user[user_id]);
		$ffdb->Success("You have successfully logged out");
	}
	//*************************************************/
    // Edit Profile Form
    //*************************************************/
	function EditProfileForm() {
		global $tpl,$mysql,$online,$ffdb,$online,$CONFIG;
		if ($online->user_id==$CONFIG['guest_id']) {
			$ffdb->Error("You need to be logged in to use this feature");
		}
		if ($CONFIG[user_selectable_skins]=="Yes") {
			$mysql->Query("SELECT * FROM ffdb_skins ORDER BY skin_name");
			while ($show_skin=mysql_fetch_array($mysql->result_id)) {
				$online->skin_list .="<option value=\"$show_skin[skin_id]\">$show_skin[skin_name]</option>";
			}
		} else {
			$online->skin_list ="<option value=\"$show_skin[skin_id]\">Default</option>";
		}
		$mysql->Query("SELECT * FROM ffdb_users WHERE user_id=$online->user_id");
		$show_user=mysql_fetch_array($mysql->result_id);
		$tpl->LoadTemplate("edit_profile_form","templates/$online->skin/edit_profile_form.tpl");
		$edit_profile_form_array = array(
			'skin_list'=> $online->skin_list,
			'email'=> $show_user[email],
			'user_title'=>$show_user[user_title],
			'site_name'=>$show_user[site_name],
			'site_url'=>$show_user[site_url],
			'interests'=>$show_user[interests],
			'location'=>$show_user[location],
			'icq'=>$show_user[icq],
			'aim'=>$show_user[aim],
			'msn'=>$show_user[msn],
		);
		$tpl->ParseTemplate("edit_profile_form",$edit_profile_form_array,"No");
		$tpl->PrintTemplate("edit_profile_form");
	}
	//*************************************************/
    // Actually updates the profile in the mysqldb
    //*************************************************/
	
	function EditProfile() {
		global $tpl,$mysql,$online,$ffdb,$online,$CONFIG;
		if (empty($_POST['email'])) {
			$ffdb->Error("Missing Email");
		}
		if ($_POST['new_password']) {
			$password=md5($_POST['new_password']);
		} else {
			$password=$online->password;
		}
		$ffdb->slash_array($_POST);
		$update_user_array=array (
			'password' => $password,
			'email' => $_POST['email'],
			'user_title' => $_POST['user_title'],
			'icq' => $_POST['icq'],
			'aim' => $_POST['aim'],
			'msn' => $_POST['msn'],
			'location' => $_POST['location'],
			'site_name' => $_POST['site_name'],
			'site_url' => $_POST['site_url'],
			'interests' => $_POST['interests'],
			'skin_id' => $_POST['skin'],
			'last_ip' => $_SERVER['REMOTE_ADDR']
		);
		$mysql->MakeUpdateString($update_user_array);
		$mysql->Query("UPDATE ffdb_users SET $mysql->update_string WHERE user_id='$online->user_id'");
		$ffdb->Success("Profile updated successfully");
	}
}
?>