<?php //Task 61629
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 (!isset($_REQUEST['idpollingobject']) && !isset($_REQUEST['idpolltype']) && !isset($_REQUEST['idbranch'])) {
	RedirectToPageNotFound();
}

$cn = db_connect();

if (isset($_REQUEST['idbranch'])) {
	$sk_arr = db_getPollSKbyIDBranch($cn, $_REQUEST['idbranch']);
	if (!is_array($sk_arr) || sizeof($sk_arr) < 1 || sizeof($sk_arr[0]) < 1 ) {
		db_disconnect($cn);
		RedirectToPageNotFound();
	}
	$skpolltype = $sk_arr[0]['skpolltype'];
	$skpollingobject = $sk_arr[0]['skpollingobject'];
} else {
	$skpolltype = db_getSKPollType($cn, $_REQUEST['idpolltype']);
	$skpollingobject = db_getSKPollingObject($cn, $_REQUEST['idpollingobject']);
}

if ($skpolltype < 1 || $skpollingobject < 1)  {
	db_disconnect($cn);
	RedirectToPageNotFound();
}

$resarr = db_getGuidsByPollingObject($cn, $skpollingobject);

if (!is_array($resarr) || sizeof($resarr) < 1)  {
	db_disconnect($cn);
	RedirectToPageNotFound();
}

if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'admin'){
	$idpolltype = db_getIDPollTypeBySK($cn, $skpolltype);
	header("Location: ".getCurPageURLWO()."/adminpoll.php?idpolltype=".$idpolltype.
		(isset($resarr[0]['skbranch']) ? "&skbranch=".$resarr[0]['skbranch'] : (isset($resarr[0]['skproject']) ? "&skproject=".$resarr[0]['skproject'] : "")).
		"&detail&skpollingobject=".$skpollingobject."&skpolltype=".$skpolltype);
} else {
	header("Location: ".getCurPageURLWO()."/pollobject.php?skpollingobject=".$skpollingobject."&skpolltype=".$skpolltype.
		(isset($resarr[0]['skbranch']) ? "&skbranch=".$resarr[0]['skbranch'] : "").(isset($resarr[0]['skproject']) ? "&skproject=".$resarr[0]['skproject'] : "").
		(isset($_REQUEST['oguid']) ? "&oguid=".$_REQUEST['oguid'] : (isset($resarr[0]['o_guid']) ? "&oguid=".$resarr[0]['o_guid'] : "")).
		(isset($_REQUEST['rguid']) ? "&rguid=".$_REQUEST['rguid'] : (isset($resarr[0]['r_guid']) ? "&rguid=".$resarr[0]['r_guid'] : "")).
		(isset($_REQUEST['idpolltype']) ? "&idpolltype=".$_REQUEST['idpolltype'] : "").
		(isset($_REQUEST['lang']) ? "&lang=".$_REQUEST['lang'] : "").
		"&reportInHistory=true" );
}
db_disconnect($cn);
ob_end_flush();
?>