<?
include "functions.php";
include "mysqlcon.php";

$n = basename($_SERVER['PHP_SELF']);
$admin_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_admin"));
if($admin_info[debug_mode] == "on") {
error_reporting(E_ALL ^ E_NOTICE);
} else {
error_reporting(0);
}

if($n != "login.php" & $n != "signup.php" & $n != "forgot.php" & $n != "paypal.php" & $n != "signup_result.php") {
  if(isset($_COOKIE['admin_cookie']) & isset($_COOKIE['pass_cookie']) & isset($_COOKIE['admk_cookie']) & isset($_COOKIE['admk_u_id'])) {
      if(stripslashes($_COOKIE['admin_cookie']) != encrypt($admin_info[login_name]) | stripslashes($_COOKIE['pass_cookie']) != encrypt($admin_info[password]) | stripslashes($_COOKIE['admk_cookie']) != encrypt($admin_info[special_code])) {
      header("Location: login.php");
      exit;
      }
    $users = mysql_num_rows(mysql_query("SELECT * FROM ims WHERE u_id='$_COOKIE[admk_u_id]'"));
      if($users != 1) {
      header("Location: login.php");
      exit;
      }
   $user_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims WHERE u_id = '$_COOKIE[admk_u_id]'"));
  
  } elseif(isset($_COOKIE['ims_email']) & isset($_COOKIE['ims_password']) & isset($_COOKIE['ims_u_id'])) {
    $user_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims WHERE u_id = '$_COOKIE[ims_u_id]'"));

if($n != "logout.php") { $loggedin = "true"; }

      if(stripslashes($_COOKIE['ims_email']) != u_encrypt($user_info[email]) | stripslashes($_COOKIE['ims_password']) != u_encrypt($user_info[password])) {
      header("Location: login.php");
      exit;
      }
    $other_cookie = "";

  } else {
    header("Location: login.php");
    exit;
  }
}

if($n != "first_login.php" & $n != "login.php" & $n != "logout.php" & $n != "signup.php" & $n != "forgot.php" & $n != "paypal.php" & $n != "signup_result.php") {
if($user_info[price] > 0 & $user_info[subscribed] != "yes") { 
header("Location: first_login.php"); 
exit; 
}}

$admin_info = mysql_fetch_assoc(mysql_query("SELECT * FROM ims_admin"));

include "vars.php";


?>