<?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;
	}
	.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>
<div id="main-report">
<?php
if($_REQUEST['branch_hidden'] == "")
{
?>
	<script language="javascript" type="text/javascript">
		location.href='report-student-retest.php';
	</script>
<?php
}
elseif($_SESSION['VedantnrCollegeId']!="" && isset($_SESSION['VedantnrCollegeId'])) 
{ 
	ob_start();
	
	$branch_id 		 = Escape($_REQUEST['branch_hidden']);
	$semester_id	   = Escape($_REQUEST['semester_hidden']);
	$division_id	   = Escape($_REQUEST['division_id']);
	$gturegno_start	= Escape($_REQUEST['gturegno_start']);
	$gturegno_end	  = Escape($_REQUEST['gturegno_end']);
	$branch_disp 	   = Escape($_REQUEST['branch_disp']);
	$semester_disp	 = Escape($_REQUEST['semester_disp']);
	$exam_id		   = Escape($_REQUEST['exam_hidden']);
	
	$test_type=$_REQUEST['test_hidden']=='retest'?'r':'f';
	
	
	$order_by = $_REQUEST['hid_orderby'];
	$SQL_CONDITION  = "";
	$sub= array();
		$qry="select subject_id from cms_examsetup 
					where 
					branch_id = '".$branch_id."' AND ";
					if($semester_id != "" ){
						$qry .= " semester_id = '".$semester_id."'  AND";
					}
			$qry .= "  year_id = '".$_SESSION["VedantnrYearId"]."' AND 
					total_marks = 0 AND 
					passing_marks = 0 AND 
					subject_id != 0";
			
					
			$rs = dbQuery($qry);		
			while($rec_tamount = dbArray($rs)){
				$sub []  =  $rec_tamount['subject_id'];
			}
			$sub1= implode(',',$sub);
	/*group_concat(res.subject_id) Group By res.subject_id*/
	$SQL_STUDENT = "
		SELECT 
			sm.student_id,
			sd.cur_semesterid,
			sd.cur_branchid,
			CONCAT(student_surname,' ',student_firstname,' ',SUBSTR(student_lastname,1,1),'.') AS student_name,
			student_gturegno,
			SUBSTR(student_gender,1,1) AS student_gender,
			semester_name,
			branch.branch_name,
			sd.cur_divison,
			Group_CONCAT(res.subject_id)as subject_ids,
			Group_CONCAT(sub.short_name SEPARATOR ', ')AS subject_names
			
		FROM
			cms_studentmaster sm,
			cms_studentdetail sd,
			cms_semestermaster sem,
			cms_resultmaster res,
			cms_subjectmaster sub,
			cms_branchmaster branch
		WHERE 
			sm.student_active = 1 AND 
			sm.student_id = sd.student_id AND
			sm.student_id=res.student_id AND
			res.subject_id=sub.subject_id AND
			res.subject_id NOT IN ('".$sub1."') AND 
			sd.cur_semesterid = sem.semester_id AND
			sd.cur_branchid = branch.branch_id 	 AND
			res.exam_id ='".$exam_id."'  AND
			res.result='Fail' AND 
			res.test_type='".$test_type."' AND 
		
			sd.year_id = ".$_SESSION["VedantnrYearId"] ;
	
	if($branch_id != "" &&  $branch_id != "All"){
		$SQL_CONDITION .= " AND sd.cur_branchid = ".$branch_id;
	}
	if($semester_id != "" && $semester_id != "undefined"){
		$SQL_CONDITION .= " AND sd.cur_semesterid = ".$semester_id;
	}
	
	if($division_id != "" && $division_id != "undefined"){
		$SQL_CONDITION .= " AND sd.cur_divison = '".$division_id."'";
	}
	
	if($gturegno_start != "" && $gturegno_start != "Start From"){ 
		$SQL_CONDITION .= " AND sm.student_gturegno >= '".$gturegno_start."' ";
	}
	if($gturegno_end != "" && $gturegno_start != "End To"){
		$SQL_CONDITION .= " AND sm.student_gturegno <= '".$gturegno_end."' ";
	}
	$SQL_CONDITION .= " AND res.year_id=".$_SESSION["VedantnrYearId"];
	$SQL_CONDITION .= " Group By sm.student_id ORDER BY sd.cur_branchid , sd.cur_semesterid ,sd.cur_divison ";
	
	if($order_by != "" && $order_by != "undefined"){
		$SQL_CONDITION .= ",".$order_by." ASC ";
	}
	else{
		$SQL_CONDITION .= " ,student_gturegno ASC ";
	}
	
	
	if($SQL_CONDITION != ""){
		$SQL_STUDENT .= $SQL_CONDITION;
	}
	
	//echo $SQL_STUDENT;
	$RES_STUDENT = dbQuery($SQL_STUDENT);
	
	if(dbRows($RES_STUDENT)>0){?>
         <div class="college_name"><?php echo $_SESSION["VedantnrCollegeName"]; ?></div>
                    <div class="college_address"><?php echo $_SESSION["VedantnrCollegeAddress"]; ?></div>
                    <div class="college_address">
                        Web Site: <?php echo $_SESSION["VedantnrCollegeUrl"] ;?> 
                        &nbsp;&nbsp; 
                        Email: <?php echo $_SESSION["VedantnrCollegeEmail"] ;?> 
                        &nbsp;&nbsp; 
                        Phone: <?php echo $_SESSION["VedantnrCollegePhone"] ;?> 
        </div>
        <center><h4>Retest Student List</h4></center>
       <table class="table-report" border="1" cellpadding="0" cellspacing="0" style="width:100%">
        <tr>
           <th style="text-align:left;" width="80%"><b>Branch</b> : 
			<?php 
			echo $branch_disp;
			if($semester_disp != ""){
				echo " - ".$semester_disp;	
			}if($division_id != ""){
				echo " - ".$division_id;	
			}?></th>
           <th style="text-align:center;" width="20%">Total</th>
        </tr></table>
		
		<table class="table-report" border="1" cellpadding="0" cellspacing="0" width="100%">
        <tr>
        	<th style="text-align:center;" width="5%">Sr.</th>
           <th style="text-align:center;" width="10%">Enrollment Reg No</th>
            <th style="text-align:left;"   width="35%">Student Name</th>
            <th style="text-align:center;" width="10%">Total Subject</th>
            <th style="text-align:center;" width="40%">Retest Subject</th>
        </tr>
		<?php
		$i = 1;
		$temp = "";
		$temp1="";
		$temp_div="";
		
		while($REC_STUDENT = dbArray($RES_STUDENT)){
			 if(($REC_STUDENT['branch_name'] != $temp && $branch_disp==':: All ::') 
			 || ($REC_STUDENT['semester_name'] != $temp1 && $semester_disp=='' )
			 || ($REC_STUDENT['cur_divison'] != $temp_div && $division_id=='' )
			  ){
				$temp = $REC_STUDENT['branch_name'];
				$temp1 = $REC_STUDENT['semester_name'];
				$temp_div=$REC_STUDENT['cur_divison'];
				$i = 1;?>
                <tr><th colspan="5"><?php echo strtoupper($temp)."  ".$REC_STUDENT['semester_name'].'-'.$REC_STUDENT['cur_divison']; ?></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 $result = substr_count($REC_STUDENT['subject_names'], ', ')+1; ?></td>
                <td style="text-align:left;">&nbsp;<?php echo $REC_STUDENT['subject_names']; ?></td>
                
       		</tr><?php
		}
		?>                       
                
		</table>
		<?php
	}
	else{
		echo "NO DATA FOUND!";	
	}
	
?>

<?php
	$HtmlCode = ob_get_contents();
	ob_end_flush();
	$header_row_string="Student Attendance Sheet";
	$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";
?>