<?php require "_header.php";
error_reporting(1);
?>
<script language="javascript" type="text/javascript">
	document.getElementById("main-content").style.display = 'none';
</script>
<div id="main-report" align="center">
	<style>
		.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;
		}

		.college_name {
			font-family: QTAbbie;
			font-size: 22px;
			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;
		}
	</style>
	<!--start main body  -->
	<?php
	if ($_REQUEST['branch_hidden'] == "") {
		?>
		<script language="javascript" type="text/javascript">
			location.href = 'report-form-student-selection.php';
		</script>
		<?php
	} elseif ($_SESSION['VedantnrCollegeId'] != "" && isset($_SESSION['VedantnrCollegeId'])) {
		$dateFieldArray = array("employee_birthdate", "student_birthdate", "employee_deptjoindate", "employee_schooljoindate", "student_admdate", "employee_incrdate", "employee_schooljoindate", "student_sinceinstd", "student_lcissuedate", "employee_retddate");

		$branch_id = Escape($_REQUEST['branch_hidden']);
		$semester_id = Escape($_REQUEST['semester_hidden']);
		$year_id = Escape($_REQUEST['year_hidden']);
		$branchyear_id = Escape($_REQUEST['branchyear_hidden']);

		$selectedstudents = Escape($_REQUEST['itemselector']);
		$columnlist = Escape($_REQUEST['columnselector']);

		$college_id = $_SESSION['VedantnrCollegeId'];
		//$std_name		  = Escape($_REQUEST['standerd_name']);
		$objStudentMgmt = new StudentMgmt();
		if ($selectedstudents != "") {

			$title_array = array();
			$title_array_val = array();

			if ($columnlist != "") {
				/*$qry = "SELECT * FROM cms_displaytable WHERE displayid in (".$columnlist.") order by FIELD(displayid,".$columnlist.")";
						   $result=dbQuery($qry);*/
				$condition = "";
				$condition .= " And displayid in (" . $columnlist . ") order by FIELD(displayid," . $columnlist . ")";
				$result = $objStudentMgmt->getstudentdisplay($condition);

				$table_append = "";
				if (dbRows($result) > 0) {

					$i = 0;
					while ($row = dbArray($result)) {

						$title_array[$i] = $row["displayname"];

						if (in_array($row["displayvalue"], $dateFieldArray)) {
							$fields .= "DATE_FORMAT(" . $row["displayvalue"] . ",'$SQLDateFormat'),";
						} else {
							$fields .= $row["displayvalue"] . ",";
						}
						$i++;
					}
					$fields = substr($fields, 0, strlen($fields) - 1);
				}
			}

			if ($fields != "") {
				/*    $query ="SELECT ".$fields." FROM cms_studentmaster stu ".$table_append." 
										WHERE stu.student_id in($selectedstudents) and stu.college_id = '$college_id' ";
							  //echo $query ;
							  if($condition != ""){
								 echo $query .= $condition ;
							  }*/
				$condition1 = "";

				$condition1 .= "AND stu.student_id in($selectedstudents) and stu.college_id = '$college_id'";
				$result = $objStudentMgmt->getstudentselection($fields, $table_append, $condition1);

				$header_row_string = "Student Selection Report";

				if ($branch_id != "") {
					$header_row_string .= "<br/>&nbsp; " . $branch_id;
				}

				if ($year_id != "") {
					$header_row_string .= "&nbsp;&nbsp; " . $year_id;
				}

				if ($branchyear_id != "") {
					$header_row_string .= "&nbsp;&nbsp;" . $branchyear_id;
				}

				if ($semester_id != "") {
					$header_row_string .= "&nbsp;&nbsp;" . $semester_id;
				}

				$obj = new Query2Report();

				$obj->reportid = "report-table";
				//table heading...
				$obj->createHeaderRow($header_row_string, $Title = true);

				//generates report from $query_1 
				$obj->generateReport($result, $title_array, $footer = false, $field = "", $counter = true, $footer1 = true);

				//disply the report..
				$obj->displayReportData();

			}
		} //end if
		if ($obj->rowCount > 0) {
			$HtmlUrl = "student-selection-report-" . $_SESSION["VedantnrUserId"] . ".html";
			$HtmlPath = "report/" . $HtmlUrl;

			$obj->setHtmlUrl($HtmlUrl);
			$obj->setHtmlPath($HtmlPath);
			$obj->saveReportData();
			?>

			<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="Create PDF" onclick="SetPageAction('PDF');" />
				<input type="button" name="btnHtml" id="btnHtml" value="Create HTML" onclick="SetPageAction('HTML');" />
				<input type="button" name="btnWord" id="btnWord" value="Create WORD" onclick="SetPageAction('WORD');" />
				<input type="button" name="btnExcel" id="btnExcel" value="Create EXCEL" onclick="SetPageAction('Excel');" />
			</form>
			<script language="javascript" type="text/javascript">
				function SetPageAction(varAction) {
					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 "<br/><b>No Data Found</b>";
		}
	}  //end session
	else {
		echo "Session Expired";

	}
	?>

	<!--end main bdy  -->
</div>
<?php require "_footer.php"; ?>