<?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');
}

if(!(is_readable(realpath(dirname(__FILE__).'/../').'/include/pagination.inc'))) {
	die('Error - Could not open or read file '.realpath(dirname(__FILE__).'/../').'/include/pagination.inc');
} else {
	include_once(realpath(dirname(__FILE__).'/../').'/include/pagination.inc');
}
session_write_close();
if (!isset($_REQUEST['idpolltype']) || !isset($_REQUEST['iduser'])){ 
	ob_end_flush();
	exit;
}

$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'];
$usr_arr = GetUserIDs();
if (!isUserAdmin() && !db_isUserAdminToPolls($cn, $usr_arr)){ 
	ob_end_flush();
	exit;
}
	$answersvals = [];
	db_setTimeZone($cn);
	$loc_usr_arr = array();
	array_push($loc_usr_arr, $_REQUEST[ "iduser" ]);
	db_getPollObjetcListCut($cn, (isset($_REQUEST['idpolltype']) ? $_REQUEST['idpolltype'] : NULL), (isset($_REQUEST['skproject']) ? $_REQUEST['skproject'] : NULL),  (isset($_REQUEST['skbranch']) ? $_REQUEST['skbranch'] : NULL), $loc_usr_arr, TRUE);
	$q_st = 'SELECT `poll`.* FROM `poll` ;';
	$pollObjetcList = db_runQueryAndReturnArray($cn,$q_st);
	for($p=0; $p<sizeof($pollObjetcList); $p++){
		if (db_isUserGetRightsToPoll($cn, $pollObjetcList[ $p ][ "skpollingobject" ], $usr_arr)){							
			$answers = db_getPolltypeQuestionAnswersToUser($cn, $pollObjetcList[ $p ][ "skpollingobject" ], $pollObjetcList[ $p ][ "skpolltype" ], $_REQUEST[ "iduser" ] );
			for($j=0; $j<sizeof($answers); $j++){
				$question = db_getPolltypeQuestion($cn, $pollObjetcList[ $p ][ "skpollingobject" ], $pollObjetcList[ $p ][ "skpolltype" ], $answers[ $j ]['iduser'], $contlngid );
				$ansval = '';
				if ($question[0]['idpolltypequestiontype'] == 1){
					$ansval = $question[0]['rft_columnname_text'];
				} else if ($question[0]['idpolltypequestiontype'] == 2 && sizeof($answers[$j]) > 0 && $answers[$j]['uav_value'] !== NULL && $answers[$j]['uav_value'] > 0  ){
					$ansval = db_getQuestionSelectValueByID($cn, $question[0]['skpolltypequestion'], $answers[$j]['uav_value'], $contlngid );
				}
				if (strlen($ansval) > 0) {
					array_push($answersvals,$ansval);
				}
			}
		}
	}
	foreach(array_count_values($answersvals) as $key=>$val){
		echo '<div class="resrondents-table-answer"><nobr>'.$key.': '.$val."</nobr></div>"; //61931
	}
	// 59883							
	echo "<div href='dialog-thorough-form' class='dialog-thorough dialog-html-show-link' title='";
	getResource("title.thorough");
	echo "' dialogbuttons='visible'  dialoghref='pollsassignedtouserdetails.php?iduser=".$_REQUEST[ "iduser" ].(isset($_REQUEST['idpolltype']) ? "&idpolltype=".$_REQUEST['idpolltype'] : "").(isset($_REQUEST['skproject']) ? "&skproject=".$_REQUEST['skproject'] : "").(isset($_REQUEST['skbranch']) ? "&skbranch=".$_REQUEST['skbranch'] : "")."' >";
	getResource("title.thorough");
	echo "</div>"; 

db_disconnect($cn);
ob_end_flush();
?>