<?php
/*
 * This file is part of a larger software package. Please read the License file 
 * in the root of this installation for terms of usage and distribution.
 * 
 * @author The Web Pro Miami, Inc. <info@thewebpro.com>
 * @copyright The Web Pro Miami, Inc. <info@thewebpro.com>, http://www.thewebpro.com/
 * 
 * FILE: manage/inc/secure_page.php
*/

if(!isset($_SESSION)){ session_start(); }

// Get server and session info
$nPHPSelf = (isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : NULL);
$nQueryStr = (isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : NULL);
$ValidUser = (isset($_SESSION['ValidUser']) ? $_SESSION['ValidUser'] : NULL);

if($nPHPSelf && $nQueryStr){ $nQueryStr = str_replace("=","~~",$nQueryStr); $nPHPSelf.="?$nQueryStr"; }
if($_SESSION["uID"]){ $UID = base64_decode($_SESSION["uID"]); } else { $UID = ""; }
$UID = preg_replace("/[[:^digit:]]/", '',$UID);

// If no user or ID, logout user
if(!$ValidUser || !$UID){ header ("Location: index.php?r=$nPHPSelf"); exit; }

// Get admin and section-level access vars
$nAccessPages = $nAccessLibrary = $nAccessSettings = $nAdmin = $nAdminAccess = FALSE;

$nSQL = "SELECT * FROM nEditor WHERE nID='$UID' LIMIT 1";
mysql_select_db($DBName); $Result = mysql_query($nSQL,$Link);
if($Row = mysql_fetch_array($Result)){
	$nID = $Row["nID"];
	$nAdmin = $nAdminAccess = $Row["nAdmin"];
	$nAccessPages = $Row["nAccessPages"];
	$nAccessLibrary = $Row["nAccessLibrary"];
	$nAccessSettings = $Row["nAccessSettings"];
} else {
	header ("Location: index.php?r=$nPHPSelf"); exit;
}

if($nAdmin){ $nAccessPages = $nAccessLibrary = $nAccessSettings = TRUE; }

if(!isset($nAdminOnlyPg)){ $nAdminOnlyPg = 0; }
if($nAdminOnlyPg && !$nAdmin) {
	header ("Location: index.php?error=7"); exit;
}

$nUserLangChoice = (isset($_SESSION['nUserLang']) ? $_SESSION['nUserLang'] : NULL);
?>
