<?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');
}
$cn = db_connect();
$lng = ( isset($_REQUEST['lang']) ? 'lang='.$_REQUEST['lang'] : '');
$lngid = db_getLanguageID($cn, getLanguage());
$contlng = 'lang='.db_getLanguageShortByID($cn, $_SESSION['user_idlanguagecontent']);
$contlngid = $_SESSION['user_idlanguagecontent'];
session_write_close();

$usr_arr = GetUserIDs();
if (!isUserAdmin() && !db_isUserAdminToPolls($cn, $usr_arr)){ 
	ob_end_flush();
	exit;
}
$urlWO = getCurPageURLWO('service');
$branches = db_getBranchesRootsForTreetoUser($cn, $usr_arr, $contlngid);
foreach ($branches as $branch) {
	echo '<li id="'.$branch['skbranch'].'" name="'.$branch['rft_columnname_text'].'" class="root-branch"><nobr style="top:1px"><span>'.$branch['rft_columnname_text'].'</span></nobr>';
	echo '<ul>';											
	$tr_arr = db_getObjectTreetoUser($cn, 0, $usr_arr, $contlngid, $branch['skbranch']);
	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']).'"/><input type="checkbox" name="searchinobj[]" id="'.$node['idobject'].'" class="searchinobj" value="'.$node['idobject'].'" />'.$node['o_name'].'</span></nobr>';
		if (sizeof(db_getObjectTreetoSearchForPollstoUser($cn, $node['idobject'],  $usr_arr, $contlngid, $branch['skbranch'])) > 0){
			echo '<ul>';
			echo '	<li><span class="placeholder">&nbsp;</span></li>';
			echo '</ul>';
		}
		echo '</li>';
	}
	echo '</ul>';
	echo '</li>';
}
db_disconnect($cn);
ob_end_flush();
?>