<?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();
$hideheader = (isset($_COOKIE['hideheader']) ?  $_COOKIE['hideheader'] : 0);
$cn = db_connect();

$contlng = null;
$contlngid = null;

if (getSetting('portal','useRights',0) == 1){
	$contlng = 'lang='.db_getLanguageShortByID($cn, $_SESSION['user_idlanguagecontent']);
	$contlngid = $_SESSION['user_idlanguagecontent'];
}

$oLSize = '200';

if (isset($_COOKIE['admin_layout_west'])) {
	$oLSize	= $_COOKIE['admin_layout_west'];
}

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;
		}
	}
}


if(!(is_readable(realpath(dirname(__FILE__)).'/classes/tree.php'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__)).'/classes/tree.php');
} else {
	include_once(realpath(dirname(__FILE__)).'/classes/tree.php');
}

$usr_arr = GetUserIDs();
setCookieAdminLastPage('admin');
?>
<!doctype html>
<html>
<head>
	<title><?php echo renderTitle();?></title>
	<? 
	renderCommonMeta(renderTitle()); 
	renderCommonCSS(); 
	?>
</head>
<body>
	<?php renderModalHourGlassDiv();?>
	<div id="container" class="layout-resizing-hook">
	<?php  renderLoginBlock(); ?>
	<div id="main" role="main" class="ui-layout-center" style="padding-right: 20px;">
		<?php renderMainMenu(strtolower(pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME)), FALSE); ?>
			<div id="box-tabs">
				<ul class="list-tabs">
					<li><a href="admingeneral.php"><?php getResource("button.admin.general");?></a></li>
					<li class="active"><a href="#"><?php getResource("button.admin.statistic");?></a></li>
					<li><a href="adminconsole.php"><?php getResource("button.admin.console");?></a></li>
					<li><a href="adminpollobject.php"><?php getResource("button.admin.polls");?></a></li>					
				</ul>
			</div>
		</section>

		<section id="box-tree" class="pane ui-layout-west">

			<header class="clearfix">
				<h1><?php getResource("field.navigator");?></h1>
			</header>

<div id="box-tree-int" class="content">
<div id="sidetree">
<div class="treeheader">&nbsp;</div>
<ul id="mixed">

<?php
$tr_arr = array();
	$tr_arr = db_getTreeDataObjectTreetoAdmin($cn, 0, $contlngid);
	foreach ($tr_arr as $node) {
		echo '<li id="'.$node['idobject'].'" name="'.$node['o_guid'].'" class="hasChildren"><nobr><span><img src="'.$urlWO.''.getImgIcon($node['o_icon']).'" class="navigation_image"/><a href=\'javascript:loadstatistic("'.$node['idobject'].'", null);\' title="'.$node['o_name'].'">'.$node['o_name'].'</a></span></nobr>';
		if (($node['o_iright'] - $node['o_ileft']) != 1 ){
			echo '<ul>';
			echo '	<li><span class="placeholder">&nbsp;</span></li>';
			echo '</ul>';
		}
		echo '</li>';
	}
?>
</ul>
</div>
</div>
   	</section>
		<section id="box-frame" class="pane ui-layout-center">
		</section>
	</div>
</div>

<a href="javascript:void(0)" id="btn-tree-open"><span class="btn-left-open-span"><?php getResource("field.navigator");?></span></a>
<script>
    // cookie to layout
   	var oLSize = <?php echo $oLSize; ?> ;
   	var wstHide = <?php if (isset($_COOKIE['admin_layout_west_hide']) && $_COOKIE['admin_layout_west_hide'] == '1') { echo '1'; } else {echo '0';} ?>;

	// global params
	var gCloseTitle = "<?php getResource('title.close');?>";
	var gOpenTitle = "<?php getResource('title.open');?>";
	var gResizeTitle = "<?php getResource('title.resize');?>";

	var docName = "service/empty.php";
	function loadstatistic(oid){
		var urlp =  "adminstatistic.php?<?php echo $contlng ?>&oid=" + oid;
		loadDoc(urlp);
	}
</script>
<script src="js/libs/jquery.cookie.js"></script>
<script src="js/libs/jquery.layout.js"></script>
<script src="js/libs/jquery.treeview.js"></script>
<script src="js/libs/jquery.treeview.edit.js"></script>
<script src="js/libs/jquery.treeview.async.admin.js"></script>
<script src="js/libs/jquery.scrollTo.js"></script>
<script src="js/script.js"></script>
<script src="js/administration.js"></script>
<!-- <link rel="stylesheet" href='css/jquery-ui.css' /> -->
<link rel="stylesheet" href='css/ui-lightness/jquery-ui-1.8.20.custom.css' />

<script>
 	$(document).ready(function(){
		$("#box-menu").css("right","0px");
		initTrees("service/treeStructServiceAdmin.php<?php echo '?'.$contlng ?>");
		<?php
				if ( $hideheader == 1 ){
					echo '$("#btn-toggle-header").click();';
				}
		?>
	});
</script>
<?php
	if(!(is_readable(realpath(dirname(__FILE__)).'/templates/languagesbox.template'))) {
		die('Error - Could not open or read file '.realpath(dirname(__FILE__)).'/templates/languagesbox.template');
	} else {
		include_once(realpath(dirname(__FILE__)).'/templates/languagesbox.template');
	}
?>
<?php renderFooterTemplate(); ?>
</body>
</html>
<?php ob_end_flush(); ?>