<?php require "_header.php";
?>
<script language="javascript" type="text/javascript">
</script>
<div id="main-report" align="center">
	<style type="text/css">
		.table-report {
			font-family: Verdana, Geneva, sans-serif;
			font-size: 12px;
			text-align: center;
			border-right: 0px none;
			border-bottom: 0px none;
		}

		.table-report-inner {
			font-family: Verdana, Geneva, sans-serif;
			font-size: 12px;
		}

		.table-report tr {
			padding: 5px 5px 5px 5px;
		}

		.table-report td {
			padding: 5px 5px 5px 5px;
			border-top: 0px none;
			border-left: 0px none;
		}

		.table-report th {
			padding: 5px 5px 5px 5px;
			font-weight: bold;
			text-align: center;
			border-top: 0px none;
			border-left: 0px none;
		}

		.college_name {
			font-family: QTAbbie;
			font-size: 24x;
			font-weight: bold;
			padding: 2px 2px 2px 2px;
			text-align: center;
		}

		.college_address {
			font-family: Tahoma, Geneva, sans-serif;
			font-size: 11px;
			text-align: center;
			padding: 2px 2px 2px 2px;
		}

		.report_name {
			font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
			font-size: 13px;
			background-color: #CCC;
			text-align: center;
			font-weight: bold;
			padding: 2px 2px 2px 2px;
		}

		.left {
			float: left;
			width: 50%;
		}

		.right {
			float: right;
			width: 50%;
		}
	</style>

	<?php
	$branch_id = "";
	if ($_SESSION["VedantnrUserRole"] == 'Hod') {
		//$hod_sql = " SELECT branch_name FROM `cms_employeemaster` WHERE `user_id` ='" . $_SESSION["VedantnrUserId"] . "'";
		//$hod_out = dbQuery($hod_sql);
		$condition ="";
		$objEmployeeMgmt = new EmployeeMgmt();
		$hod_out = $objEmployeeMgmt->getbranchemp($condition);
		
		$branch_id = dbArray($hod_out);
		$branch_id = $branch_id['branch_id'];
	}
	dbquery("SET group_concat_max_len = 102400");
	

	/*$qry = "SELECT 
				que_ids,
				group_concat(answer_arr SEPARATOR '|||') as all_answer,
				sub.subject_name,
				emp.employee_name,
				count(*)as total_row,
				(Select branch_name from cms_branchmaster where cms_branchmaster.branch_id = sub.branch_id)as branch_name,
(Select year_name from cms_yearmaster where cms_yearmaster.year_id = sub.year_id)as year_name,
(Select branchyear_name from cms_branchyear where cms_branchyear.branchyear_id = sub.branchyear_id)as branchyear_name,
(Select semester_name from cms_semestermaster where cms_semestermaster.semester_id = sub.semester_id)as semester_name
				
			FROM 
				 feedback_que_result fb,
				 cms_subjectmaster sub,
				 cms_employeemaster emp
			WHERE 
				fb.employee_id = emp.employee_id AND
				fb.subject_id = sub.subject_id AND
				fb.student_id !=0 AND
				fb.employee_id !=0 AND emp.employee_active = 'YES'";

	$result1 = dbQuery($qry);*/


	$condition1 = "";
	if ($_REQUEST['branch_hidden'] != "" && $_REQUEST['branch_hidden'] != "undefined") {
		$condition1 .= " AND sub.branch_id = '" . Escape($_REQUEST['branch_hidden']) . "' ";
	}
	if ($branch_id != "") {
		$condition1 .= " AND sub.branch_id = '" . $branch_id . "' ";
	}
	if ($_REQUEST['year_hidden'] != "" && $_REQUEST['year_hidden'] != "undefined") {
		$condition1 .= " AND sub.year_id = '" . Escape($_REQUEST['year_hidden']) . "' ";
	}
	if ($_REQUEST['branchyear_hidden'] != "" && $_REQUEST['branchyear_hidden'] != "undefined") {
		$condition1 .= " AND sub.branchyear_id = '" . Escape($_REQUEST['branchyear_hidden']) . "' ";
	}
	if ($_REQUEST['semester_hidden'] != "" && $_REQUEST['semester_hidden'] != "undefined") {
		$condition1 .= " AND sub.semester_id = '" . Escape($_REQUEST['semester_hidden']) . "' ";
	}
	if ($_REQUEST['subject_hidden'] != "" && $_REQUEST['subject_hidden'] != "undefined") {
		$condition1 .= " AND sub.subject_id = '" . Escape($_REQUEST['subject_hidden']) . "' ";
	}
	if ($_REQUEST['employee_id_hid'] != "" && $_REQUEST['employee_id_hid'] != "undefined") {
		$condition1 .= "  AND fb.employee_id = '" . Escape($_REQUEST['employee_id_hid']) . "' ";
	}
	if ($_SESSION["VedantnrUserRole"] == 'Faculty' && $_SESSION["Employee_Id"] != "") {
		$condition1 .= " AND fb.employee_id  = '" . Escape($_SESSION["Employee_Id"]) . "' ";
	}
	$condition1 .= " group by fb.subject_id,fb.employee_id ";


	$objfeedback_que_masterMgmt = new feedback_que_masterMgmt();
	$result1 = $objfeedback_que_masterMgmt->getemployeefeedback($condition1);
	if (dbRows($result1) > 0) {
		ob_start();
		while ($row = dbArray($result1)) {
			$srno = 1;
			$all_student_answer = explode('|||', $row['all_answer']);
			$Questions = explode(",", $row['que_ids']);
			$Answers = explode(",", $row['answer_arr']);
			?>
			<div style="display: inline-block; vertical-align: middle;">
									<b style="font-size: 30px;"><?php echo $_SESSION["VedantnrCollegeName"]; ?></b><br>
									<?php echo $_SESSION["VedantnrCollegeAddress"]; ?><br>
									Phone: <?php echo $_SESSION["VedantnrCollegePhone"]; ?>&nbsp;&nbsp;
									Email: <?php echo $_SESSION["VedantnrCollegeEmail"]; ?>
								</div>
			<center>
				<h4>Faculty Feedback Report-<?php echo $_SESSION["VedantnrYearName"] ?></h4>
			</center>
			<br />
			<table width="100%">
				<tr>
					<td align="left" style="border:solid 0px red;"><b>Name of Faculty: </b>
						<?php echo $row['employee_name']; ?><br /><b>Subject: </b><?php echo $row['subject_name']; ?></td>
					<td align="right" style="border:solid 0px red;"><b>Department</b>
						:<?php echo $row['branch_name'] . '&nbsp;<b>Semester: </b>' . $row['semester_name']; ?><br /><b>No of
							Votes:
						</b><?php echo $row['total_row'] ?></td>
				</tr>
			</table>
			<table class="table-report" border="1" cellpadding="0" cellspacing="0" width="100%">
				<tr>
				<tr style="background-color:#CCC;">
					<th width="5%" style="text-align:center; font-weight:bold;font-size:12px ">Sr.</th>
					<th width="50%" style="text-align:center; font-weight:bold;font-size:12px ">Questions</th>
					<th width="10%" style="text-align:center; font-weight:bold;font-size:12px ">A: Strongly Agree</th>
					<th width="10%" style="text-align:center; font-weight:bold;font-size:12px ">B: Agree</th>
					<th width="15%" style="text-align:center; font-weight:bold;font-size:12px ">C: Neither agree nor disagree
					</th>
					<th width="10%" style="text-align:center; font-weight:bold;font-size:12px ">D: Disagree</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 = 0;
				while ($row_ques = dbArray($res_ques)) {

					?>
					<tr>
						<td style="text-align:center;"><?php echo $srno; ?></td>
						<td style="text-align:left;">&nbsp;<?php echo $row_ques['question']; ?></td>
						<?php if ($Questions[$i] == $row_ques['que_id']) {
							$string = "";
							for ($k = 0; $k < count($all_student_answer); $k++) {
								$saprate_array = explode(',', $all_student_answer[$k]);
								$string .= $saprate_array[$i] . ',';
							}
							?>
							<td style="text-align:center;"><?php echo substr_count($string, 'a'); ?></td>
							<td style="text-align:center;"><?php echo substr_count($string, 'b'); ?></td>
							<td style="text-align:center;"><?php echo substr_count($string, 'c'); ?></td>
							<td style="text-align:center;"><?php echo substr_count($string, 'd'); ?></td>
						<?php } ?>

					</tr>
					<?php $srno++;
					$i++;

				} ?>
			</table><br />
			<table width="100%">
				<tr>
					<td colspan="3" style="text-align: left;border:none;height:80px;text-align: left;vertical-align: top;">
						<b>Comments:-</b>
					</td>
				</tr>
				<tr>
					<td style="text-align:left;border:none;" width="33%"><b>Signature Faculty</b></td>
					<td style="text-align:center;border:none;" width="33%"><b>Signature HOD</b> </td>
					<td style="text-align:right;border:none;" width="33%"><b>Signature Principal</b></td>
				</tr>
			</table><br />
			<div class="break">&nbsp;</div>
		<?php } ?>

		<?php
		$HtmlCode = ob_get_contents();
		ob_end_flush();
		$HtmlUrl = "hallticket-report.html";
		$HtmlPath = "report/" . $HtmlUrl;
		createHTMLReportPage($header_row_string, $HtmlUrl, $HtmlPath, $HtmlCode);
		?>
		<br />
		<form name="frm" id="frm" action="" method="post">
			<input type="hidden" name="txtFile" id="txtFile" value="<?php echo $HtmlUrl; ?>" />
			<!--<input type="button" name="btnPdf" id="btnPdf" value="Print" onClick="SetPageAction('PRINT');"/>-->
			<input type="button" name="btnPdf" id="btnPdf" value="Create PDF" onClick="SetPageAction('PDF');" />
			<!--<input type="button" name="btnHtml" id="btnHtml" value="Create HTML" onClick="SetPageAction('HTML');"/>-->
		</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 } else {
		echo "NO DATA FOUND!";
	} ?>
</div>
<?php require "_footer.php"; ?>