<?php
ob_start();
if(!(is_readable(realpath(dirname(__FILE__))."/include/includesroutines.inc"))) {
    die("Error - Could not open or read file ".realpath(dirname(__FILE__))."/include/includesroutines.inc");
} else {
    include_once(realpath(dirname(__FILE__))."/include/includesroutines.inc");
}

checkUserAndRedirectToLogin();

if ( GetSetting('portal','useRights',0) == 0 ){
	if( !IsUserLogin() ){
		header("Location: ".getCurPageURLWO()."/businessmodel.php");
		ob_end_flush();
		exit;
	}
} else {
	if( !IsUserLogin() ){
		header("Location: ".getCurPageURLWO()."/login.php?returl=admin.php");
		ob_end_flush();
		exit;
	}
	$cn = db_connect();
	if (!isUserAdmin()){ 
		if (db_isUserAdminToPolls($cn, GetUserIDs())) {
			header("Location: ".getCurPageURLWO()."/adminpollobject.php");
			ob_end_flush();
			exit;
		} else {
			header("Location: ".getCurPageURLWO()."/personal.php");
			ob_end_flush();
			exit;
		}
	}
}

$page = "";
if (isset($_COOKIE['last_admin_page'])){
	$page = $_COOKIE['last_admin_page'];
}

switch ($page) {
    case "admingeneral":
		header("Location: ".getCurPageURLWO()."/admingeneral.php");
		ob_end_flush();
		exit;
        break;
    case "admin":
		header("Location: ".getCurPageURLWO()."/admin.php");
		ob_end_flush();
		exit;
        break;
    case "adminconsole":
		header("Location: ".getCurPageURLWO()."/adminconsole.php");
		ob_end_flush();
		exit;
        break;
	case "adminpollobject":
		header("Location: ".getCurPageURLWO()."/adminpollobject.php");
		ob_end_flush();
		exit;
		break;
    default:
		header("Location: ".getCurPageURLWO()."/admin.php");
		ob_end_flush();
		exit;
        break;
}
ob_end_flush();
?>


