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

Размер файла: 11Kb
<?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           |
// +----------------------------------------------------------------------+
// | functions.php                                                        |
// | Date Started: February 18, 2003                                      |
// | Last Modified: March 11, 2003                                        |
// +----------------------------------------------------------------------+
Class Admin {
	var $user_level;
	//********************************************/
	// Header for all Admin Pages
	//*******************************************/
	function Header() {
		global $tpl,$admin_skin;
		$tpl->LoadTemplate("header","Admin/templates/$admin_skin/header.tpl");
		$tpl->ParseTemplate("header",$header_array,"No");
		$tpl->PrintTemplate("header");

	}
	//********************************************/
	// Footer for all Admin Pages
	//*******************************************/
	function Footer() {
		global $version,$tpl,$ffdb,$admin_skin;
		$ffdb->StopTimer();
		$tpl->LoadTemplate("footer","Admin/templates/$admin_skin/footer.tpl");
		$footer_array = array(
			'version'=> $version,
			'total_time'=>$ffdb->total_time
		);
		$tpl->ParseTemplate("footer",$footer_array,"No");
		$tpl->PrintTemplate("footer");

	}
	//********************************************/
	// Error page for all admin pages
	//*******************************************/
	function Error($error) {
		global $tpl,$admin_skin;
		$tpl->LoadTemplate("error","Admin/templates/$admin_skin/error.tpl");
		$error_array = array(
			'error'=> $error
		);
		$this->Header();
		$tpl->ParseTemplate("error",$error_array,"No");
		$tpl->PrintTemplate("error");
		$this->Footer();
		exit();

	}

	//********************************************/
	// Success Page for all admin pages
	//*******************************************/
	function Success($success) {
		global $tpl,$admin_skin;
		$tpl->LoadTemplate("success","Admin/templates/$admin_skin/success.tpl");
		$success_array = array(
			'success'=> $success
		);
		$tpl->ParseTemplate("success",$success_array,"No");
		$tpl->PrintTemplate("success");

	}

	//********************************************/
	// Confirm pages for all admin options that
	// require confirmation so deleting files
	// categorys and such
	//*******************************************/
	function Confirm($message,$url) {
		global $tpl,$admin_skin;
		$tpl->LoadTemplate("confirm","Admin/templates/$admin_skin/confirm.tpl");
		$confirm_array = array(
			'message'=> $message,
			'url'=>$url
		);
		$tpl->ParseTemplate("confirm",$confirm_array,"No");
		$tpl->PrintTemplate("confirm");
	}
	//********************************************/
	// Checks the Users Login
	//********************************************/
	function CheckLogin() {
		global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
		if (isset($_POST['login'])) {
			$_SESSION['username']="";
			$_SESSION['password']="";
			$_SESSION['username']=$_POST['username'];
			$_SESSION['password']=md5($_POST['password']);
		}
		$mysql->Query("SELECT * FROM ffdb_users WHERE username='".$_SESSION['username']."' AND password='".$_SESSION['password']."'");
		$show_user=mysql_fetch_array($mysql->result_id);
		if (!$show_user[username] OR !$show_user[password]) {
			$this->Header();
			$this->Error("Login Failed Incorrect Username and/or Password");
			$this->Footer();
			session_destroy();
			exit();
		}
		$this->username=$show_user[username];
		$this->user_level=$show_user[user_level];
		$this->password=$show_user[password];
		$this->user_id=$show_user[user_id];
	}
	//********************************************/
	// Login Form for the Admin Area
	//********************************************/
	function LoginForm() {
		global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
		$tpl->LoadTemplate("login_form","Admin/templates/$admin_skin/login_form.tpl");
		$tpl->ParseTemplate("login_form",$login_form_array,"No");
		$tpl->PrintTemplate("login_form");
	}
	//********************************************/
	// Menu for Admin Area
	//********************************************/
	function Menu() {
		global $tpl,$mysql,$ffdb,$CONFIG,$admin_skin;
		if (preg_match("/@4/",$this->user_level)) {
			$options.="<div align=\"center\">
					  <center>
					  <table id=\"AutoNumber6\" style=\"BORDER-COLLAPSE: collapse\" borderColor=\"#111111\" cellSpacing=\"0\" cellPadding=\"4\" width=\"100%\" bgColor=\"#009999\" border=\"1\">
					<tr>
					  <td>
					  <p align=\"center\"><font size=\"1\"><b>Category Options</b></font></td>
					</tr>
					<tr>
					 <td bgcolor=\"#008080\">
					 <font size=\"1\"><a href=\"admin.php?action=add_category\">Add Category </a></font></td>
					</tr>
					<tr>
					<td bgcolor=\"#008080\">
					<font size=\"1\"><a href=\"admin.php?action=edit_category\">Edit Category</a></font></td>
					</tr>";
				if (preg_match("/@5/",$this->user_level)) {
					$options .="
								<tr>
								<td bgcolor=\"#008080\">
								<font size=\"1\"><a href=\"admin.php?action=display_order\">Change Display Order</a></font></td>
								</tr>";

				}
				$options .="</table>
							  </center>
								</div>";
				
		}
		if (preg_match("/@5/",$this->user_level)) {
			$options.="<br><div align=\"center\">
					  <center>
					  <table id=\"AutoNumber6\" style=\"BORDER-COLLAPSE: collapse\" borderColor=\"#111111\" cellSpacing=\"0\" cellPadding=\"4\" width=\"100%\" bgColor=\"#009999\" border=\"1\">
					<tr>
					  <td>
					  <p align=\"center\"><font size=\"1\"><b>Sub Category Options</b></font></td>
					</tr>
					<tr>
					 <td bgcolor=\"#008080\">
					 <font size=\"1\"><a href=\"admin.php?action=add_sub_category\">Add Sub Category </a></font></td>
					</tr>
					<tr>
					<td bgcolor=\"#008080\">
					<font size=\"1\"><a href=\"admin.php?action=edit_sub_category\">Edit Sub Category</a></font></td>
					</tr>";
				if (preg_match("/@4/",$this->user_level)) {
					$options .="
								<tr>
								<td bgcolor=\"#008080\">
								<font size=\"1\"><a href=\"admin.php?action=display_order\">Change Display Order</a></font></td>
								</tr>";

				}
				$options .="</table>
							  </center>
								</div>";
		}
		if (preg_match("/@6/",$this->user_level) || preg_match("/@7/",$this->user_level)) {
			$options.="<br><div align=\"center\">
					  <center>
					  <table id=\"AutoNumber6\" style=\"BORDER-COLLAPSE: collapse\" borderColor=\"#111111\" cellSpacing=\"0\" cellPadding=\"4\" width=\"100%\" bgColor=\"#009999\" border=\"1\">
					<tr>
					  <td>
					  <p align=\"center\"><font size=\"1\"><b>File Options</b></font></td>
					</tr>";
				if (preg_match("/@6/",$this->user_level)) {
					$options .="
								<tr>
								<td bgcolor=\"#008080\">
								<font size=\"1\"><a href=\"admin.php?action=add_file\">Add File</a></font></td>
								</tr>";
				}
				if (preg_match("/@7/",$this->user_level)) {
					$options .="
								<tr>
								<td bgcolor=\"#008080\">
								<font size=\"1\"><a href=\"admin.php?action=edit_file\">Edit File</a></font></td>
								</tr>";
				}
				$options .="</table>
							  </center>
								</div>";
		}
		if (preg_match("/@8/",$this->user_level)) {
			$options.="<br><div align=\"center\">
					  <center>
					  <table id=\"AutoNumber6\" style=\"BORDER-COLLAPSE: collapse\" borderColor=\"#111111\" cellSpacing=\"0\" cellPadding=\"4\" width=\"100%\" bgColor=\"#009999\" border=\"1\">
					<tr>
					  <td>
					  <p align=\"center\"><font size=\"1\"><b>Administration Options</b></font></td>
					</tr>
						<tr>
						<td bgcolor=\"#008080\">
						<font size=\"1\"><a href=\"admin.php?action=change_settings\">Change General Settings</a></font></td>
						</tr>
							<tr>
						<td bgcolor=\"#008080\">
						<font size=\"1\"><a href=\"admin.php?action=add_skin\">Add Skin</a></font></td>
						</tr>
							<tr>
						<td bgcolor=\"#008080\">
						<font size=\"1\"><a href=\"admin.php?action=edit_skin\">Edit Skin</a></font></td>
						</tr>
						<tr>
						<td bgcolor=\"#008080\">
						<font size=\"1\"><a href=\"admin.php?action=edit_templates\">Edit Templates</a></font></td>
						</tr>
							<tr>
						<td bgcolor=\"#008080\">
						<font size=\"1\"><a href=\"admin.php?action=edit_user\">Edit User</a></font></td>
						</tr>
								<tr>
						<td bgcolor=\"#008080\">
						<font size=\"1\"><a href=\"admin.php?action=add_license\">Add License</a></font></td>
						</tr>
								<tr>
						<td bgcolor=\"#008080\">
						<font size=\"1\"><a href=\"admin.php?action=edit_license\">Edit License</a></font></td>
						</tr>
						</table>
							  </center>
								</div>";
		}
		$menu_array = array(
			'options'=> $options
		);
		$tpl->LoadTemplate("menu","Admin/templates/$admin_skin/menu.tpl");
		$tpl->ParseTemplate("menu",$menu_array,"No");
		$tpl->PrintTemplate("menu");
	}
	//********************************************/
	// Main For the admin area
	//********************************************/
	function Main() {
		global $tpl,$mysql,$ffdb,$CONFIG,$version,$admin_skin;
		if (file_exists('/proc/loadavg')) {
			if ($fh = @fopen( '/proc/loadavg', 'r' )){
				$data = @fread($fh,6);
				@fclose($fh);
				$load_avg = explode( " ", $data );
				$server_load=trim($load_avg[0]);
			}
		} else {
			$server_load="N/A";
		}
		$latest_version="<SCRIPT language=\"JavaScript\" src=\"http://fscripts.com/ffdb_version.php\"></SCRIPT>";
		$phpversion = phpversion();
		$mysql->Query("SELECT VERSION() AS version");
		$show_version=mysql_fetch_array($mysql->result_id);
		$mysqlversion=$show_version[version];
		if (extension_loaded("zlib")) {
			$gzip="Yes";
		} else {
			$gzip="No";
		}
		$mysql->Query("SELECT * FROM ffdb_stats");
		$show_stats=mysql_fetch_array($mysql->result_id);
		$main_array = array(
			'server_load'=> $server_load,
			'latest_version'=>$latest_version,
			'phpversion'=>$phpversion,
			'mysqlversion'=>$mysqlversion,
			'gzip'=>$gzip,
			'version'=>$version,
			'total_users'=>$show_stats[num_users],
			'num_files'=>$show_stats[num_files],
			'num_categorys'=>$show_stats[num_categorys],
			'num_sub_categorys'=>$show_stats[num_sub_categorys],
			'num_comments'=>$show_stats[num_comments],
			'num_ratings'=>$show_stats[num_ratings],
		);
		$tpl->LoadTemplate("main","Admin/templates/$admin_skin/main.tpl");
		$tpl->ParseTemplate("main",$main_array,"No");
		$tpl->PrintTemplate("main");
	}
}
?>