<?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;
		background-color:#eee; 
		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-mark.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']);
	$batch_id 		 = Escape($_REQUEST['batch_idhidden']);
	$exam_id		  = Escape($_REQUEST['exam_hidden']);
	$test_type		= Escape($_REQUEST['test_hidden']);
	$subject_name	 = Escape($_REQUEST['subject_hidden']);
	$branch_disp 	  = Escape($_REQUEST['branch_disp']);
	$semester_disp	= Escape($_REQUEST['semester_disp']);
	$exam_disp 		= Escape($_REQUEST['exam_disp']);
	$subject_disp 	 = Escape($_REQUEST['subject_disp']);
	
	$SQL_CONDITION  = "";
	if($test_type == "firsttest"){
		
		$sql = "
			SELECT
				CONCAT(sm.student_surname,' ',sm.student_firstname) AS student_name,
				sm.student_id,
				sm.student_gturegno,
				rm.obtain_mark,
				rm.present
			FROM
				cms_studentmaster sm LEFT JOIN cms_resultmaster rm ON sm.student_id = rm.student_id 
					AND rm.exam_id = ".$exam_id."
					AND rm.subject_id = ".$subject_name."
					AND rm.test_type='f'
					AND year_id = ".$_SESSION["VedantnrYearId"].",
				   cms_studentdetail sd	 
			WHERE 
				sm.student_id = sd.student_id AND
				sm.student_active = 1 AND
				
				sd.cur_branchid = ".$branch_id." AND 
				sd.cur_semesterid = ".$semester_id." AND 
				sd.cur_divison = '".$division_id."' AND 
				sd.year_id = ".$_SESSION["VedantnrYearId"]." 
				ORDER BY student_gturegno ASC, student_name ASC";	
	}
	 else if($test_type == "retest"){
		
		$qry = "SELECT
				CONCAT(sm.student_surname,' ',sm.student_firstname) AS student_name,
				sm.student_id,
				sm.student_gturegno,
				rm.obtain_mark,
				rm.present
			FROM
				cms_studentmaster sm,
				cms_resultmaster rm,
				cms_studentdetail sd	 
			WHERE 
				sm.student_id = sd.student_id AND
				sm.student_id = rm.student_id AND 
				rm.year_id = ".$_SESSION["VedantnrYearId"]." AND
				sd.year_id = ".$_SESSION["VedantnrYearId"]." AND
				rm.test_type='r' AND
				rm.exam_id = ".$exam_id." AND 
				rm.subject_id = ".$subject_name." AND 
				
				sm.student_active = 1 AND
				sd.cur_branchid = ".$branch_id." AND 
				sd.cur_semesterid = ".$semester_id." AND
				sd.cur_divison = '".$division_id."' 
			    ORDER BY student_gturegno ASC,student_name ASC";
			
			$result = dbQuery($qry);
			$result_count=dbRows($result);		 
			if($result_count>0)
			{
				$sql=$qry;	
				
		  }
		
	}
	else{
	
		
		$sql = "SELECT
				CONCAT(sm.student_surname,' ',sm.student_firstname) AS student_name,
				sm.student_id,
				sm.student_gturegno,
				(case when test_type = 'f' then obtain_mark end) as obtain_mark,
				rm.present,
				rm.present_pr,
				rm.obtain_marks_pr_ese,
				rm.obtain_marks_pr_pa,
				group_concat((case when test_type = 'r' then obtain_mark end)) obtain_mark_re
			FROM
				cms_studentmaster sm,
				cms_resultmaster rm,
				cms_studentdetail sd	 
			WHERE 
				sm.student_id = sd.student_id AND
				sm.student_id = rm.student_id AND 
				rm.year_id = ".$_SESSION["VedantnrYearId"]." AND
				sd.year_id = ".$_SESSION["VedantnrYearId"]." AND
				rm.exam_id = ".$exam_id." AND 
				rm.subject_id = ".$subject_name." AND 
				
				sm.student_active = 1 AND
				sd.cur_branchid = ".$branch_id." AND 
				sd.cur_semesterid = ".$semester_id." AND
				sd.cur_divison = '".$division_id."' 
			    group by rm.student_id
				ORDER BY student_gturegno ASC,student_name ASC";
			   
	}
		
	
		
	$RES_STUDENT = dbQuery($sql);		
	$total = dbRows($rs);
	$sql_pmark = "SELECT total_marks,passing_marks,total_marks_pr_ese,passing_marks_pr_ese,total_marks_pr_pa,passing_marks_pr_pa FROM cms_examsetup WHERE branch_id = ".$branch_id." AND 
	  semester_id = ".$semester_id." AND exam_id = ".$exam_id." 
	  AND subject_id = ".$subject_name." AND year_id = ".$_SESSION["VedantnrYearId"];
	$res_pmark = dbQuery($sql_pmark);			
	$rec_pmark = dbArray($res_pmark);
	$total_marks = $rec_pmark['total_marks'];
	$passing_marks = $rec_pmark['passing_marks'];
	$total_marks_pr_ese = $rec_pmark['total_marks_pr_ese'];
	$passing_marks_pr_ese = $rec_pmark['passing_marks_pr_ese'];
	$total_marks_pr_pa = $rec_pmark['total_marks_pr_pa'];
	$passing_marks_pr_pa = $rec_pmark['passing_marks_pr_pa'];
	$result_type=$_REQUEST['result'];
	if(dbRows($RES_STUDENT)>0){?>
        <div class="college_name"><?php echo $_SESSION["VedantnrCollegeName"]; ?></div>
        <div class="college_address"><?php echo $_SESSION["VedantnrCollegeAddress"]; ?></div>
        <center><h4>Student Exam Marks Report</h4></center>
        <div>
                <div class="left"><b>Branch</b> : <?php echo $branch_disp." - ".$semester_disp." - ".$division_id; ?></div>
                <div class="right"><b>Exam</b> : <?php echo $subject_disp.' ,'.$exam_disp.'&nbsp;('.ucfirst($_REQUEST['test_hidden']).')'; ?></div>
            </div>
        <table class="table-report" border="1" cellpadding="0" cellspacing="0" width="100%">	
        <tr>
        <th style="text-align:left;" width="%3">Sr No</th>
        <th style="text-align:left;" width="8%"  >GTU NO</th>
        <th style="text-align:left;" width="15%"  >Student Name</th>
        <th style="padding:2px;text-align:center;font-weight:bold;width:7%">Theory Total</th>
        <th style="padding:2px;text-align:center;font-weight:bold;width:9%">Theory Passing</th>
        <th style="padding:2px;text-align:center;font-weight:bold;width:7%">First Obtain</th>
        <th style="padding:2px;text-align:center;font-weight:bold;width:8%">Retest Obtain</th>
        <th style="padding:2px;text-align:center;font-weight:bold;width:7%">Total [ESE]</th>
        <th style="padding:2px;text-align:center;font-weight:bold;width:9%">Passing [ESE]</th>
        <th style="padding:2px;text-align:center;font-weight:bold;width:7%">Obtain [ESE]</th>
        <th style="padding:2px;text-align:center;font-weight:bold;width:6%">Total [PA]</th>
        <th style="padding:2px;text-align:center;font-weight:bold;width:7%">Passing [PA]</th>
        <th style="padding:2px;text-align:center;font-weight:bold;width:8%">Obtain [PA]</th>
        </tr>
    <?php
	$i=1;
		while($REC_STUDENT = dbArray($RES_STUDENT)){
			
			if($result_type=='Pass'){
				if($REC_STUDENT["obtain_mark"]>=$passing_marks){
				
				}else{
					continue;
				}
			
			}else if($result_type=='Fail'){
			
				if($REC_STUDENT["obtain_mark"]<$passing_marks){
				}else{
					continue;
				}
			
			}
			
			?>
        
                                   <tr>
                                   <td style="text-align:center;"><?php echo $i; ?></td>
                                   <td style="text-align:left;"><?php echo $REC_STUDENT['student_gturegno']; ?></td>
                                   <td style="text-align:left;"><?php echo $REC_STUDENT['student_name']; ?></td>
                                   <td style="text-align:center;"><?php echo $total_marks; ?></td>
                                   <td style="text-align:center;"><?php echo $passing_marks; ?></td>
									<?php
									if($REC_STUDENT["obtain_mark"] >= $passing_marks){
										$obtain_mark= $REC_STUDENT["obtain_mark"];
									}else{
									 $obtain_mark='<span style="color:red;font-weight:bold;text-decoration:underline;">'.$REC_STUDENT["obtain_mark"].'</span>';
									 $obtain_mark=($REC_STUDENT["obtain_mark"]==""?'--':$obtain_mark);
									}
									
									if($REC_STUDENT['obtain_mark_re'] >= $passing_marks){
									$obtain_mark_re = $REC_STUDENT['obtain_mark_re'];   
									}else{
									 $obtain_mark_re='<span style="color:red;font-weight:bold;text-decoration:underline;">'.$REC_STUDENT['obtain_mark_re'].'</span>';
									 $obtain_mark_re=($REC_STUDENT['obtain_mark_re']==""?'--':$obtain_mark_re);
									}
									
									if($REC_STUDENT['obtain_marks_pr_ese'] >= $passing_marks_pr_ese){
									$obtain_marks_pr_ese = $REC_STUDENT['obtain_marks_pr_ese'];   
									}else{
									 $obtain_marks_pr_ese='<span style="color:red;font-weight:bold;text-decoration:underline;">'.$REC_STUDENT['obtain_marks_pr_ese'].'</span>';
									 $obtain_marks_pr_ese=($REC_STUDENT['obtain_marks_pr_ese']==""?'--':$obtain_marks_pr_ese);
									}
									
									if($REC_STUDENT['obtain_marks_pr_pa'] >= $passing_marks_pr_pa){
									$obtain_marks_pr_pa = $REC_STUDENT['obtain_marks_pr_pa'];   
									}else{
									 $obtain_marks_pr_pa='<span style="color:red;font-weight:bold;text-decoration:underline;">'.$REC_STUDENT['obtain_marks_pr_pa'].'</span>';
									 $obtain_marks_pr_pa=($REC_STUDENT['obtain_marks_pr_pa']==""?'--':$obtain_marks_pr_pa);
									}
									
								   ?>
                                   <td style="text-align:center;"><?php echo $obtain_mark; ?></td>
                                   <td style="text-align:center;"><?php echo $obtain_mark_re; ?></td>
                                   <td style="text-align:center;"><?php echo $total_marks_pr_ese; ?></td>
                                   <td style="text-align:center;"><?php echo $passing_marks_pr_ese ?></td>
                                   <td style="text-align:center;"><?php echo $obtain_marks_pr_ese; ?></td>
                                   <td style="text-align:center;"><?php echo $total_marks_pr_pa; ?></td>
                                   <td style="text-align:center;"><?php echo $passing_marks_pr_pa; ?></td>
                                   <td style="text-align:center;"><?php echo $obtain_marks_pr_pa; ?></td>
                                   </tr>
<?php $i++; } ?>
</table>
<?php }
	else{
		echo "NO DATA FOUND!";	
	}
	
?>

<?php
	$HtmlCode = ob_get_contents();
	ob_end_flush();
	$header_row_string="";
	$HtmlUrl = "student-overall-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 } ?>
<?php 
	require "_footer.php";
?>