<?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;
	}
</style>
<div id="main-report">
	<?php
	if ($_SESSION['VedantnrCollegeId'] != "" && isset($_SESSION['VedantnrCollegeId'])) {
		ob_start();
		$branch_id = Escape($_REQUEST['branch_hidden']);
		$branchyear_id = Escape($_REQUEST['branchyear_hidden']);
		$year_id = Escape($_REQUEST['year_hidden']);
		$semester_id = Escape($_REQUEST['semester_hidden']);
		$branch_name = Escape($_REQUEST['branch_disp']);
		$year_name = Escape($_REQUEST['year_disp']);
		$branchyear_name = Escape($_REQUEST['branchyear_disp']);
		$semester_name = Escape($_REQUEST['semester_disp']);

		$condition = "";
		/*$qry = "";
		$qry = "SELECT DISTINCT(sm.student_gturegno),
	  			sm.student_id,
				sm.student_admdate, 
				CONCAT(sm.student_surname , ' ' , sm.student_firstname , ' ' ,sm.student_lastname) AS student_name,
				sm.student_birthdate,
				sm.student_gender,
				sm.student_admby,
				sm.student_category,	
				sm.student_mobileother,
				sm.student_fathermobile,
				sm.tfw_scheme,  		  
			  	sd.batch_id, 
				sm.leave_type,
				(SELECT branch_name FROM cms_branchmaster sec WHERE sec.branch_id = sd.cur_branchid) AS branch_name,
	  		(SELECT year_name FROM cms_yearmaster ym  WHERE ym.year_id = sd.year_id) AS year_name,
			(SELECT semester_name FROM cms_semestermaster sem  WHERE sem.semester_id = sd.cur_semesterid) AS semester_name,
			(SELECT branchyear_name FROM cms_branchyear bry 
			     WHERE   bry.branchyear_id = sd.cur_branchyearid) AS branchyear_name   	 
		  	  FROM
			  	cms_studentmaster sm,
				cms_studentdetail sd				
		  	  WHERE								
				sm.college_id  = '" . $_SESSION["VedantnrCollegeId"] . "' 
				AND sm.student_id=sd.student_id  ";*/

		if ($_REQUEST['curYear'] != "") {
			$condition .= " AND sm.student_active=1 ";
		}
		if ($_REQUEST['cancel'] == "on") {
			$condition .= " AND sm.leave_type = 'c'";
		}
		if ($_REQUEST['suspend'] == "on") {
			$condition .= " AND sm.leave_type = 's'";
		}
		if ($_REQUEST['detain'] == "on") {
			$condition .= " AND sm.leave_type = 'd'";
		}
		if ($_REQUEST['alumni'] == "on") {
			$condition .= " AND sm.leave_type = 'a'";
		}
		if ($_REQUEST['branch_hidden'] != "" && $_REQUEST['branch_hidden'] != "All") {
			$condition .= " and sd.cur_branchid = '" . Escape($_REQUEST['branch_hidden']) . "'";
		}

		if ($_REQUEST['student_birthdate'] != "") {
			$startdate = DateConversion(Escape($_REQUEST['student_birthdate']), "Y-m-d", "d/m/Y");
			$condition .= " and sm.student_birthdate = '" . $startdate . "'";
		}
		if ($_REQUEST['student_cast'] != "") {
			$condition .= " and sm.student_cast = '" . Escape($_REQUEST['student_cast']) . "'";
		}
		if ($_REQUEST['student_admby'] != "") {
			$condition .= " and sm.student_admby = '" . Escape($_REQUEST['student_admby']) . "'";
		}
		if ($_REQUEST['student_admyear'] != "") {
			$condition .= " and YEAR(sm.student_admdate) = '" . Escape($_REQUEST['student_admyear']) . "'";
		}
		if ($_REQUEST['shift'] != "") {
			$condition .= " and sm.shift = '" . Escape($_REQUEST['shift']) . "'";
		}
		if ($_REQUEST['student_lastname'] != "" && $_REQUEST['student_lastname'] != "Last Name") {
			$condition .= " and sm.student_lastname LIKE '%" . Escape($_REQUEST['student_lastname']) . "%'";
		}
		if ($_REQUEST['student_surname'] != "" && $_REQUEST['student_surname'] != "Surname") {
			$condition .= " and sm.student_surname LIKE '%" . Escape($_REQUEST['student_surname']) . "%'";
		}
		if ($_REQUEST['student_firstname'] != "" && $_REQUEST['student_firstname'] != "First Name") {
			$condition .= " and sm.student_firstname LIKE  '%" . Escape($_REQUEST['student_firstname']) . "%'";
		}
		if ($_REQUEST['student_gender'] != "") {
			$condition .= " and sm.student_gender = '" . Escape($_REQUEST['student_gender']) . "'";
		}
		if ($_REQUEST['student_gturegno'] != "") {
			$condition .= " and sm.student_gturegno = '" . Escape($_REQUEST['student_gturegno']) . "'";
		}

		if ($_REQUEST['student_category'] != "") {
			$condition .= " and sm.student_category = '" . Escape($_REQUEST['student_category']) . "'";
		}
		if ($_REQUEST['chkTFW'] == "on") {
			$condition .= " and sm.tfw_scheme = '1'";
		}

		$condition .= " order By sd.year_id,student_name ASC";

		//echo $qry; exit;
		//$RES_STUDENT = dbQuery($qry);

		$objStudentMgmt = new StudentMgmt();
		$RES_STUDENT = $objStudentMgmt->getstudentsearchlist($condition);
		if (dbRows($RES_STUDENT) > 0) { ?>
			<center>
				<h4>Student List</h4>
			</center>
			<br />
			<table class="table-report" border="1" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<th style="text-align:center;" width="2%">Sr.</th>
					<th style="text-align:center;" width="5%">Enrollment No</th>
					<th style="text-align:center;" width="20%">Student Name</th>
					<th style="text-align:center;" width="5%">Admis. Date</th>
					<th style="text-align:center;" width="5%">Birth Date</th>
					<th style="text-align:center;" width="2%">Gen</th>
					<th style="text-align:center;" width="5%">Category</th>
					<th style="text-align:center;" width="5%">Adm Type</th>
					<th style="text-align:center;" width="5%">TFW Sch.</th>
					<th style="text-align:center;" width="5%">Leave Type</th>
					<th style="text-align:center;" width="10%">Par. Mo.</th>
					<th style="text-align:center;" width="10%">Stud. Mo.</th>
				</tr>
				<?php
				$i = 1;
				$temp = "";
				$temp1 = "";
				$temp2 = "";
				$temp3 = "";
				while ($REC_STUDENT = dbArray($RES_STUDENT)) {
					if (($REC_STUDENT['branch_name'] != $temp) || ($REC_STUDENT['year_name'] != $temp1) || ($REC_STUDENT['branchyear_name'] != $temp2) || ($REC_STUDENT['semester_name'] != $temp3)) {
						$temp = $REC_STUDENT['branch_name'];
						$temp1 = $REC_STUDENT['year_name'];
						$temp2 = $REC_STUDENT['branchyear_name'];
						$temp3 = $REC_STUDENT['semester_name'];
						$i = 1; ?>
						<tr><th colspan="12" style="border-bottom: hidden; " >&nbsp;</th></tr>
						<tr><th colspan="12" style= "border-bottom: hidden ;"><?php echo strtoupper($temp) .'-'. $temp1 .' - '. $temp2.'  '. $temp3; ?></th></tr>
						<tr><th colspan="12">&nbsp;</th></tr>
						<?php
					} ?>
					
					<tr>
						<td style="text-align:center;">&nbsp;<?php echo $i++; ?></td>
						<td style="text-align:center;">&nbsp;<?php echo $REC_STUDENT['student_gturegno']; ?></td>
						<td style="text-align:left;">&nbsp;<?php echo $REC_STUDENT['student_name']; ?></td>
						<td style="text-align:center;">&nbsp;<?php echo date("d-m-Y", strtotime($REC_STUDENT['student_admdate'])); ?></td>
						<td style="text-align:center;">
							&nbsp;<?php echo date("d-m-Y", strtotime($REC_STUDENT['student_birthdate'])); ?></td>
						<td style="text-align:center;">&nbsp;<?php echo $REC_STUDENT['student_gender']; ?></td>
						<td style="text-align:left;">&nbsp;<?php echo $REC_STUDENT['student_category']; ?></td>
						<td style="text-align:left;">&nbsp;<?php echo $REC_STUDENT['student_admby']; ?></td>
						<td style="text-align:center;">&nbsp;<?php echo $REC_STUDENT['tfw_scheme']; ?></td>
						<td style="text-align:center;">&nbsp;<?php
						$value = $REC_STUDENT['leave_type'];
						if ($value == 'r') {
							echo '<b><span class="comp">Reshuffling</span></b>';
						} else if ($value == 's') {
							echo '<b><span class="comp">Suspend</span></b>';
						} else if ($value == 'd') {
							echo '<b><span class="comp">Detain</span></b>';
						} else if ($value == 'c') {
							echo '<b><span class="comp">Cancel</span></b>';
						} else {
							echo '<b>Active</b>';
						}
						?></td>
						<td style="text-align:center;">&nbsp;<?php echo $REC_STUDENT['student_fathermobile']; ?></td>
						<td style="text-align:center;">&nbsp;<?php echo $REC_STUDENT['student_mobileother']; ?></td>
					</tr><?php
				}
				?>
			</table>
			<?php
		} else {
			echo "NO DATA FOUND!";
		}

		?>

		<?php
		$HtmlCode = ob_get_contents();
		ob_end_flush();
		$header_row_string = "";
		$HtmlUrl = "studentlist-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');" />
			<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 == "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";
?>