<?php require "_header.php";?>
<script language="javascript" type="text/javascript">
document.getElementById("main-content").style.display = 'none';
</script>
<style type="text/css">
	.table-report{
		font-family:Verdana, Geneva, sans-serif;
		font-size:12px;
		text-align:left;
		border-right:0px none;
		border-bottom:0px none;
	}
	.table-report-inner{
		font-family:Verdana, Geneva, sans-serif;
		font-size:12px;
	}
	.table-report tr{
		padding:2px 2px 2px 2px;
	}
	.table-report td{
		padding:2px 2px 2px 2px;
		border-top:0px none;
		border-left:0px none;
	}
	.table-report th{
		padding:2px 2px 2px 2px;
		font-weight:bold;
		text-align:left;
		border-top:0px none;
		border-left:0px none;
	}	
	.break { page-break-before: always; }
</style>
<div id="main-report">
<?php
if($_SESSION['VedantnrCollegeId']!="" && isset($_SESSION['VedantnrCollegeId'])) 
{ 	
	ob_start();
	$Employee_Id 	= $_SESSION['Employee_Id'];
	$Employee_Name 	= $_SESSION['aUserName'];
?>
	<center><h4>Feedback Report Information</h4></center>
    <br /><br/>
<?php 
	/*echo "<pre>";
	print_r($_SESSION);
	exit;*/
	$qry ="SELECT 
				fb.*, 
				sub.`subject_name`,
				GROUP_CONCAT(fb.`answer_arr`) as Answer_ids,
				bm.`branch_name` 
			FROM 
				`feedback_que_result` fb ,
				`cms_subjectmaster` sub
				left join `cms_branchmaster` bm on sub.`branch_id`= bm.`branch_id` 
			WHERE 
				fb.`subject_id`= sub.`subject_id` AND 
				fb.`employee_id`= '".$Employee_Id."' 
			GROUP BY subject_id 
			ORDER BY subject_id ";
	$result1=dbQuery($qry);
	if(dbRows($result1)>0) {
?>
<br />
	<div style="text-align:left;font-size:12px" ><b>Employee Name</b> : <?php echo $Employee_Name; ?></div>
<br/>
	<table class="table-report" border="1" cellpadding="0" cellspacing="0" width="100%" >
		<tr style="background-color:#CCC;">
            <th width="6%" style="text-align:center; font-weight:bold;font-size:12px ">SrNo.</th>
            <th width="54%" style="text-align:center; font-weight:bold;font-size:12px ">Questions</th>
            <th width="20%" style="text-align:center; font-weight:bold;font-size:12px ">Options</th>
            <th width="20%" style="text-align:center; font-weight:bold;font-size:12px ">Votes</th>
        </tr>
        <?php 	$srno = 1;
				$count_ans=0;
				$count_quwstion=0;
				$counts = 0;
				$vote_a=0;
				$vote_b=0;
				$vote_c=0;
				$vote_d=0;
				while($row_emp=dbArray($result1))
				{	
					$Questions = explode(",", $row_emp['que_ids']);
					$Answers = explode(",", $row_emp['Answer_ids']);
					$count_quwstion = count($Questions);
					$ANS_arrays = array_chunk($Answers, $count_quwstion);
					$count_ans = count($ANS_arrays);
					/*echo $count_quwstion;
					echo $count_ans;
					exit;*/
				
		?>
		<tr>
        	<th colspan="4" style="font-weight:bold;font-size:10px;font-size:12px;"><b> Branch  & Subject Name :  </b><?php echo $row_emp['branch_name'].'  -  '.$row_emp['subject_name']; ?></th>
        </tr>
		<?php $que = "SELECT que_id,question,ans_a,ans_b,ans_c,ans_d
						FROM `feedback_que_master` 
						ORDER BY que_id" ;
			$res_ques=  dbQuery($que); 
			$i_ques=0;
			while($row_ques=dbArray($res_ques))
			{
		?>
		<tr>
        	<td style="text-align:center;"><?php echo $srno; ?></td>
            <td style="text-align:left;">&nbsp;&nbsp;<?php echo $row_ques['question']; ?></td>
            <td>
                <table width="100%" >
               		<tr>
                		<td>A:</td><td><?php echo $row_ques['ans_a'];?></td>
               		</tr>
                    <tr>
                        <td>B:</td><td><?php echo $row_ques['ans_b'];?></td>
                    </tr>
                    <tr>
                        <td>C:</td><td><?php echo $row_ques['ans_c'];?></td>
                    </tr>
                    <tr>
                    	<td>D:</td><td><?php echo $row_ques['ans_d'];?></td>
                   </tr> 
                </table>
            </td>
            <?php 
			for($i=0; $i < $count_quwstion; $i++){
				if($Questions[$i] == $row_ques['que_id']){ 
					for($j=0; $j < $count_ans; $j++){
						if($ANS_arrays[$j][$i]== 'a'){$vote_a++;}
						if($ANS_arrays[$j][$i]== 'b'){$vote_b++ ;}
						if($ANS_arrays[$j][$i]== 'c'){$vote_c++;}
						if($ANS_arrays[$j][$i]== 'd'){$$vote_d++;}
					}
				}
			}
			//echo $vote_a;
			?>
            <?php 
				for($i=0; $i < $count_quwstion; $i++){
					if($Questions[$i] == $row_ques['que_id']){ ?>
            <td style="text-align:center;">
				<?php 
					for($j=0; $j < $count_ans; $j++){
							//echo $ANS_arrays[$j][$i];
							if($ANS_arrays[$j][$i]== 'a'){echo $vote_a;}
							if($ANS_arrays[$j][$i]== 'b'){echo $vote_b;}
							if($ANS_arrays[$j][$i]== 'c'){echo $vote_c;}
							if($ANS_arrays[$j][$i]== 'd'){echo $$vote_d;}
				}  ?>
            </td>
            <?php } }$srno ++; ?>
        </tr>
        <?php  }
		} ?>
</table>
<?php
	}
	else{
		echo "NO DATA FOUND!";	
	}
	?>
<?php
	$HtmlCode = ob_get_contents();
	ob_end_flush();
	$header_row_string="Employee Feedback Report";
	$HtmlUrl = "employee-feedback-report.html";
	$HtmlPath =	"report/".$HtmlUrl;
	createHTMLReportPage($header_row_string,$HtmlUrl,$HtmlPath,$HtmlCode,false);
?>
<br/>
<form name="frm" id="frm" action="" method="post">		
    <input type="hidden"   name="txtFile" id="txtFile" value="<?php echo $HtmlUrl ;?>" />
    <input type="button"  name="btnPrint" id="btnPrint" value="Print" onClick="SetPageAction('PRINT');"/>
    <input type="button"  name="btnPdf" id="btnPdf" value="Create PDF" onClick="SetPageAction('PDF');"/>
</form>
<script language="javascript" type="text/javascript">
function SetPageAction(varAction) {
	if(varAction=="PRINT"){			
		document.frm.action="print/create-print.php";
		document.frm.target = "_blank";
		document.frm.submit();
	}
	else if(varAction=="PDF"){			
		document.frm.action="convertpdf/create-pdf.php";
		document.frm.target = "_blank";
		document.frm.submit();
	}
	else if(varAction=="HTML"){
		document.frm.action="<?php echo $HtmlPath ;?>";
		document.frm.target = "_blank";
		document.frm.submit();
	}
	else if(varAction=="WORD"){
		document.frm.action="convertword/create-word.php";
		document.frm.target="_blank";
		document.frm.submit();
	}
	else if(varAction=="Excel"){
		document.frm.action="convertword/create-excel.php";
		document.frm.target="_blank";
		document.frm.submit();
	}
}
</script>
<?php } ?>
</div>
<?php 
	require "_footer.php";
?>
