<?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;
	}	
	.break { page-break-before: always; }
</style>
<div id="main-report">
<?php
if($_SESSION['aCollegeId']!="" && isset($_SESSION['aCollegeId'])) 
{ 
	ob_start();
	
	$student_id 	= $_SESSION['student_id'];
	$order_by = $_REQUEST['hid_orderby'];
	$SQL_CONDITION  = "";
	
	$SQL_YEAR = "SELECT max(year_id)as year_id FROM cms_studentdetail sd	WHERE sd.current_active = 1 and sd.student_id = ".$_SESSION["student_id"]." ";
	$RES_YEAR = dbQuery($SQL_YEAR);
	$REC_YEAR = dbArray($RES_YEAR);
	$year_id  = $REC_YEAR['year_id'];
	$SQL_STUDENT = "
		SELECT 
			sbm.subject_name,
			rm.test_type,
			rm.obtain_mark,
			rm.present,
			rm.result,
			es.total_marks,
			es.passing_marks,
			(select obtain_mark from cms_resultmaster resin  WHERE  resin.student_id = ".$_SESSION["student_id"]." AND rm.subject_id = resin.subject_id AND resin.test_type='r' AND resin.year_id = ".$year_id." limit 0,1)as obtain_mark_re,
			(select present from cms_resultmaster resin  WHERE  resin.student_id = ".$_SESSION["student_id"]." AND rm.subject_id = resin.subject_id AND resin.test_type='r' AND resin.year_id = ".$year_id." limit 0,1)as present_re
		FROM
			cms_examsetup es,
			cms_resultmaster rm,
			cms_subjectmaster sbm
		WHERE 
			rm.subject_id = sbm.subject_id AND
			sbm.subject_id = es.subject_id AND
			rm.student_id = ".$_SESSION["student_id"]." AND
			rm.year_id = es.year_id 
			AND es.total_marks != 0
			and rm.year_id='".$year_id."'
			AND rm.test_type='f'
			group by rm.subject_id
			order by es.exam_id,rm.subject_id ";
		
	
	//echo $SQL_STUDENT;
	
	$RES_STUDENT = dbQuery($SQL_STUDENT);
	
	if(dbRows($RES_STUDENT)>0){?>
        <center><h4>All Exams Result Information</h4></center>
      <br />
		<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="20%">Subject</th>
            <th style="text-align:center;"   width="10%">Total Marks</th>
            <th style="text-align:center;"   width="10%">Passing Marks</th>
            <th style="text-align:center;" width="10%" >First</th>
            <?php if($Show_retestmark_to_student==1){ ?>
            <th style="text-align:center;" width="10%" >Retest</th>
			<?php } ?>
        
        </tr>
		<?php
		$i = 1;
		$temp = "";
	    $total_masrks=0;
		$total_obtain=0;
		$total_obtain_re=0;
		while($REC_STUDENT = dbArray($RES_STUDENT)){
			$passing_marks=$REC_STUDENT['passing_marks'];
			$obtain_mark=$REC_STUDENT['obtain_mark'];
			$obtain_mark_re=$REC_STUDENT['obtain_mark_re'];
			$present=$REC_STUDENT['present'];
			$present_re=$REC_STUDENT['present_re'];
			if($obtain_mark_re>$passing_marks){
				$obtain_mark_re=$passing_marks;
			}
			$total_masrks+=$REC_STUDENT['total_marks'];
			$total_obtain+=$REC_STUDENT['obtain_mark'];
			$total_obtain_re+=$obtain_mark_re;
			?>
            <tr>
				<td style="text-align:center;">&nbsp;<?php echo $i++; ?></td>
                <td style="text-align:left;">&nbsp;<?php echo $REC_STUDENT['subject_name'];?></td>
                <td style="text-align:center;">&nbsp;<?php echo $REC_STUDENT['total_marks']; ?></td>
                <td style="text-align:center;">&nbsp;<?php echo $REC_STUDENT['passing_marks']; ?></td>
               <?php 
			   if($present==1){
	
				   if($obtain_mark<$passing_marks){
						$obtain_mark="<span style='color: #FF0000;font-weight: bold;text-decoration: underline;'>".$obtain_mark."</span>";  
					}
			   
			   }else{
					$obtain_mark="<span style='color: #FF0000;font-weight: bold;text-decoration: underline;'>A</span>";
			   }
			   
			   if($present_re==1){
	
				   if($obtain_mark_re<$passing_marks){
						$obtain_mark="<span style='color: #FF0000;font-weight: bold;text-decoration: underline;'>".$obtain_mark_re."</span>";  
					}
			   
			   }else{
				 
				  if($present==0 || $REC_STUDENT['obtain_mark']  < $passing_marks){
							$obtain_mark_re="<span style='color: #FF0000;font-weight: bold;text-decoration: underline;'>A</span>";						
					}else{
						$obtain_mark_re='-';
					}
					
			   }
			   ?>
                <td style="text-align:center;">&nbsp;<?php echo $obtain_mark; ?></td>
                <?php if($Show_retestmark_to_student==1){ ?>
                <td style="text-align:center;">&nbsp;<?php echo $obtain_mark_re; ?></td>
                <?php } ?>
       		</tr><?php
		}
		?>
        <tr>
        <th style="text-align:center;" colspan="2">&nbsp;Total</th>
        <th style="text-align:center;">&nbsp;<?php echo $total_masrks; ?></th>
        <th style="text-align:center;">&nbsp;-</th>
        <th style="text-align:center;">&nbsp;<?php echo $total_obtain; ?></th>
        <?php if($Show_retestmark_to_student==1){ ?>
        <th style="text-align:center;">&nbsp;<?php echo $total_obtain_re; ?></th>
        <?php }?>
        </tr>
		</table>
		<?php
	}
	else{
		echo "NO DATA FOUND!";	
	}
	
?>

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