View file FFDB/Admin/user.php

File size: 8.6Kb
<?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: March 13, 2003                                         |
// | Last Modified: March 13, 2003                                        |
// +----------------------------------------------------------------------+
Class User {
	//*************************************************/
    // Just seing what we are doing
    //*************************************************/
    function User() {
        global $tpl,$mysql,$ffdb,$CONFIG,$admin;
		if ($_REQUEST['action']=="edit_user") {
			$this->UserList();
		}elseif ($_REQUEST['action']=="edit_user_form") {
			$this->EditUserForm();
		}elseif (isset($_REQUEST['edit_user'])) {
			$this->EditUser();
		}elseif ($_REQUEST['action']=="confirm_delete_user") {
			$this->ConfirmDeleteUser();
		}elseif ($_REQUEST['action']=="delete_user") {
			$this->DeleteUser();
		}
	}
	//*************************************************/
    // User List
    //*************************************************/
	function UserList() {
		global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
		if ($_REQUEST['page']) {
			$page=$_REQUEST['page'];
		} else {
			$page=1;
		}
		$ffdb->DivideData("SELECT * FROM ffdb_users WHERE user_id !=".$CONFIG['guest_id']." AND username !='Deleted User' ORDER BY username",$page,50);
        $ffdb->MakePages("<a href=\"admin.php?page={eachpage}&action=edit_user&id=$show_user[user_id]\">{eachpage}</a>&nbsp;","<b>({page})</b>&nbsp;","<a href=\"admin.php?page=1&action=edit_user&id=$show_user[user_id]\">« First Page</a>&nbsp;","<a href=\"admin.php?page={eachpage}&action=edit_user&id=$show_user[user_id]\">Last Page »</a>",$page,$ffdb->num_pages);
		$tpl->LoadTemplate("user_list","Admin/templates/$admin_skin/user_list.tpl");
		$mysql->Query("SELECT * FROM ffdb_users WHERE user_id !=".$CONFIG['guest_id']." AND username !='Deleted User' ORDER BY username LIMIT $ffdb->data_bottom,$ffdb->data_top");
		while ($show_user=mysql_fetch_array($mysql->result_id)) {
			$user_list_array = array(
				'username'=>$show_user[username],
				'email'=>$show_user[email],
				'user_id'=>$show_user[user_id]
			);
			$tpl->ParseTemplate("user_list",$user_list_array,"Yes");
		}
		$tpl->PrintTemplate("user_list");
		echo "<p align=\"center\">$ffdb->pages</p>";
	}
	//*************************************************/
    // Edit User Form
    //*************************************************/
	function EditUserForm() {
		global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
		$mysql->Query("SELECT * FROM ffdb_users WHERE user_id=".$_REQUEST['id']."");
		$show_user=mysql_fetch_array($mysql->result_id);
		if (preg_match("/@1/",$show_user[user_level])) {
			$download_files="<option selected>Yes</option><option>No</option>";
		} else {
			$download_files="<option selected> No</option><option>Yes</option>";
		}
		if (preg_match("/@2/",$show_user[user_level])) {
			$post_comments="<option selected>Yes</option><option>No</option>";
		} else {
			$post_comments="<option selected> No</option><option>Yes</option>";
		}
		if (preg_match("/@3/",$show_user[user_level])) {
			$comments_admin="<option selected>Yes</option><option>No</option>";
		} else {
			$comments_admin="<option selected> No</option><option>Yes</option>";
		}
		if (preg_match("/@4/",$show_user[user_level])) {
			$category_admin="<option selected>Yes</option><option>No</option>";
		} else {
			$category_admin="<option selected> No</option><option>Yes</option>";
		}
		if (preg_match("/@5/",$show_user[user_level])) {
			$sub_category_admin="<option selected>Yes</option><option>No</option>";
		} else {
			$sub_category_admin="<option selected> No</option><option>Yes</option>";
		}
		if (preg_match("/@6/",$show_user[user_level])) {
			$add_file="<option selected>Yes</option><option>No</option>";
		} else {
			$add_file="<option selected> No</option><option>Yes</option>";
		}
		if (preg_match("/@7/",$show_user[user_level])) {
			$edit_file="<option selected>Yes</option><option>No</option>";
		} else {
			$edit_file="<option selected> No</option><option>Yes</option>";
		}
		if (preg_match("/@8/",$show_user[user_level])) {
			$admin_options="<option selected>Yes</option><option>No</option>";
		} else {
			$admin_options="<option selected> No</option><option>Yes</option>";
		}
		$mysql->Query("SELECT * FROM ffdb_skins ORDER BY skin_name");
		while ($show_skin=mysql_fetch_array($mysql->result_id)) {
			$skin_list .="<option value=\"$show_skin[skin_id]\">$show_skin[skin_name]</option>";
		}
		$tpl->LoadTemplate("edit_user_form","Admin/templates/$admin_skin/edit_user_form.tpl");
		$edit_user_form_array = array(
			'skin_list'=> $skin_list,
			'download_files'=>$download_files,
			'post_comments'=>$post_comments,
			'comments_admin'=>$comments_admin,
			'category_admin'=>$category_admin,
			'sub_category_admin'=>$sub_category_admin,
			'add_file'=>$add_file,
			'edit_file'=>$edit_file,
			'admin_options'=>$admin_options,
			'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],
			'user_id'=>$show_user[user_id]
		);
		$tpl->ParseTemplate("edit_user_form",$edit_user_form_array,"No");
		$tpl->PrintTemplate("edit_user_form");
	}
	//*************************************************/
    // Updates User
    //*************************************************/
	function EditUser() {
		global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
		$mysql->Query("SELECT * FROM ffdb_users WHERE user_id=".$_REQUEST['id']."");
		$show_user=mysql_fetch_array($mysql->result_id);
		if ($_POST['new_password']) {
			$password=md5($_POST['new_password']);
		} else {
			$password=$show_user[password];
		}
		if ($_POST['download_files']) {
			$user_level .="@1";
		}
		if ($_POST['post_comments']) {
			$user_level .="@2";
		}
		if ($_POST['comments_admin']) {
			$user_level .="@3";
		}
		if ($_POST['category_admin']) {
			$user_level .="@4";
		}
		if ($_POST['sub_category_admin']) {
			$user_level .="@5";
		}
		if ($_POST['add_file']) {
			$user_level .="@6";
		}
		if ($_POST['edit_file']) {
			$user_level .="@7";
		}
		if ($_POST['admin_options']) {
			$user_level .="@8";
		}
		$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'],
			'user_level'=>$user_level
		);
		$mysql->MakeUpdateString($update_user_array);
		$mysql->Query("UPDATE ffdb_users SET $mysql->update_string WHERE user_id='".$_POST['id']."'");
		$admin->Success("User Updated successfully");
	}
	//*************************************************/
    // Confirms that they want to delete the user
    //*************************************************/
	function ConfirmDeleteUser() {
		global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
		$admin->Confirm("Are you sure you want to delete this user?<br>","admin.php?action=delete_user&id=".$_REQUEST['id']."");

	}
	//*************************************************/
    // Deletes User from database
    //*************************************************/
	function DeleteUser() {
		global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin,$admin;
		$mysql->Query("UPDATE ffdb_users SET username='Deleted User', password='CMsiXAAk33', user_level='' WHERE user_id=".$_REQUEST['id']."");
		$admin->Success("User Deleted Sucessfully");
	}
}
?>