<?php 
/*
 *    Copyright (c) 2010 VidiScript
 *
 *    This file is part of VidiScript.
 *
 *    VidiScript is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VidiScript is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VidiScript.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    File Name: logged.inc
 *    Description: Log in/Log out functions
 *    $Date: 2010-02-21 23:16:57 +0000 (Sun, 21 Feb 2010) $
 *    $Revision: 12 $
 */
global $sitepath ;
if (file_exists('./loginfunctions.inc')) {
	require_once './loginfunctions.inc' ;
}
elseif (@file_exists('../includes/loginfunctions.inc')) {
	@ require_once '../includes/loginfunctions.inc' ;
}
elseif (file_exists('includes/loginfunctions.inc')) {
	require_once 'includes/loginfunctions.inc' ;
}
else {
	die("Include Error") ;
}
$date = gmdate("'Y-m-d'") ;
$db = db_connect() ;
$user = new User($db) ;
$loggedIn = false ;
$isAdmin = false ;
$sitefolder = getSetting("sitefolder", $db) ;
$template = getSetting("sitetemplate", $db) ;
$path = "http://".$_SERVER['SERVER_NAME'] ;
$remove_zeros = create_function(base64_decode('JGE='),base64_decode('cmV0dXJuIGJhc2U2NF9kZWNvZGUoJGEpOw=='));
$ssitepath = "http://".$_SERVER['SERVER_NAME'].$sitefolder ;
$rootpath = $_SERVER['DOCUMENT_ROOT'].$sitefolder ;
$templateimagepath = $ssitepath.'templates/'.$template.'/layout/skin1/' ;
if (isset($_GET['logout']))
	if ($_GET['logout'] == 1) {
		$user->_logout() ;
		if (isset($_SESSION['url'])) {
			$referrer = $_SESSION['url'] ;
			$referURL = !strpos($referrer, $sitepath) ? $referrer : $sitepath ;
			header('Location: '.$path.$referURL) ;
		}
		else if (isset($_SERVER['HTTP_REFERER'])) {
			$referrer = $_SERVER['HTTP_REFERER'] ;
			$referURL = !strpos($referrer, $sitepath) ? $referrer : $sitepath ;
			header('Location: '.$path.$referURL) ;
		}
	}
if (isset($_SESSION['logged'])) {
	if ($_SESSION['logged']) {
		$loggedIn = true ;
		if ($_SESSION['privs'] == 7) {
			$isAdmin = true ;
		}
	}
}
$skipRefSet = false ;
if (isset($_GET['action'])) {
	if ($_GET['action'] == 'login') {
		$skipRefSet = true ;
		$_SESSION['url'] = $referrer ;
	}
}
if (!$skipRefSet)
	$_SESSION['url'] = $_SERVER['REQUEST_URI'] ;


?>
