<?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']);
	
	
	$order_by = $_REQUEST['hid_orderby'];
	$SQL_CONDITION  = "";
		
	$SQL_STUDENT = "
		SELECT 
			sm.student_id,
			sd.cur_semesterid,
			sd.cur_branchid,
			student_admdate,
			CONCAT(student_surname,' ',student_firstname,' ',SUBSTR(student_lastname,1,1),'.') AS student_name,
			student_address,
			student_emailid,
			student_birthdate,
			student_gturegno,
			SUBSTR(student_gender,1,1) AS student_gender,
			student_mobilestudents,
			student_mobileparents,
			semester_name,
			branch.branch_name,
			sm.student_admby,
			sm.tfw_scheme ,
			sd.cur_divison
		FROM
			cms_studentmaster sm,
			cms_studentdetail sd,
			cms_semestermaster sem,
			cms_branchmaster branch
		WHERE 
			sm.student_active = 1 AND 
			sm.student_id = sd.student_id AND
			
			sd.cur_semesterid = sem.semester_id AND
			sd.cur_branchid = branch.branch_id 	 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."'";
	}
				
	$SQL_CONDITION .= " ORDER BY sm.student_gturegno ASC, sd.cur_branchid , sd.cur_semesterid ";
	$SQL_STUDENT.=$SQL_CONDITION;
	$RES_STUDENT = dbQuery($SQL_STUDENT);
	
	if(dbRows($RES_STUDENT)>0){?>
        <?php
		while($REC_STUDENT = dbArray($RES_STUDENT)){
			?>
             <?php
									$student_id = $REC_STUDENT['student_id'];
									$branch_id = $REC_STUDENT['cur_branchid'];
									$semester_id= $REC_STUDENT['cur_semesterid'];
									$division_id= $REC_STUDENT['cur_divison'];
									$failflg=0;
									$totalmark=0;
										$totalobtain=0;
									?>
                <div class="college_name"><?php echo $_SESSION["VedantnrCollegeName"]; ?></div>
                <div class="college_address"><?php echo $_SESSION["VedantnrCollegeAddress"]; ?></div>
                                            <center><h4>Student Marksheet Report</h4></center>
               
        <table class="table-report" border="1" cellpadding="0" cellspacing="0" width="90%">
		
         <tr>
        	<th style="text-align:left;" width="15%"  >Branch</th>
            <td style="text-align:left;" width="40%"  ><?php echo $REC_STUDENT['branch_name']; ?></td>
            <th style="text-align:left;" width="10%"  >Semester</th>
            <td style="text-align:left;" width="35%"  ><?php echo $REC_STUDENT['semester_name'].'-'.$REC_STUDENT['cur_divison']; ?></td>
         </tr>
         <tr>
        	<th style="text-align:left;" width="15%"  >Student Name</th>
            <td style="text-align:left;" width="40%"  ><?php echo $REC_STUDENT['student_name']; ?></td>
            <th style="text-align:left;" width="10%"  >Enrollment NO</th>
            <td style="text-align:left;" width="35%"  ><?php echo $REC_STUDENT['student_gturegno']; ?></td>
         </tr>
         <tr>
        	<td colspan="4" >
                                   
                                    <?php
									if($test_type=="" || $test_type=='firsttest')
									{
									 $sql_result="select   res.*,
														  setup.total_marks,
														  setup.passing_marks,
														  sub.subject_name
													 FROM 
															cms_resultmaster res,
															cms_examsetup setup,
															cms_subjectmaster sub
													 Where 
													 		res.subject_id = sub.subject_id
															AND setup.subject_id = sub.subject_id
															AND res.test_type = 'f'
															AND res.exam_id = setup.exam_id
															AND res.branch_id = setup.branch_id
															AND res.semester_id = setup.semester_id
															AND res.year_id = setup.year_id
															AND res.college_id = setup.college_id
															AND res.college_id = '".$_SESSION['VedantnrCollegeId']."'
															AND res.year_id ='".$_SESSION["VedantnrYearId"]."'	
															AND res.branch_id 	='".$branch_id."'
															AND res.semester_id ='".$semester_id."'	
															AND res.exam_id ='".$exam_id."' 
															AND res.student_id='".$student_id."'  ";
										
									$res_result = dbQuery($sql_result);
									$res_result_count=dbRows($res_result);		 
									if($res_result_count>0)
									{ ?>
                
                    
<table class="table-report" border="1" cellpadding="0" cellspacing="0" width="100%">	
                                	<tr>
                                    	<th style="padding:2px;text-align:center;font-weight:bold;width:40%">Subject</th>
                                        <th style="padding:2px;text-align:center;font-weight:bold;width:20%">Total Mark</th>
                                        <th style="padding:2px;text-align:center;font-weight:bold;width:20%">Passing Mark</th>
                                        <th style="padding:2px;text-align:center;font-weight:bold;width:20%">Obtain Mark</th>
                                    </tr>
                                    <?php
									while($rec_result = dbArray($res_result))	
									{
										
                                   ?>
                                   <tr>
                                   <td><?php echo $rec_result['subject_name']; ?></td>
                                   <td style="text-align:center;"><?php echo $rec_result['total_marks']; ?></td>
                                   <td style="text-align:center;"><?php echo $rec_result['passing_marks']; ?></td>
                                   <td style="text-align:center;"><?php echo $rec_result['obtain_mark']; ?></td>
                                   </tr>
                                    <?php 
									$totalmark+=$rec_result['total_marks'];
									$totalpassing+=$rec_result['passing_marks'];
									$totalobtain+=$rec_result['obtain_mark'];
									if($rec_result['obtain_mark']<$rec_result['passing_marks'])
									{
										$failflg=1;								
									}
											
									}
									?>
                                    <tr>
                                    	<th style="text-align:right;padding-right:10px;" >Total</th>
                                        <th style="text-align:center;"><?php echo $totalmark; ?></th>
                                        <th style="text-align:center;">--</th>
                                        <th style="text-align:center;"><?php echo $totalobtain; ?></th>
                                    </tr>
                                    <tr>
                                    
                          <th style="text-align:center;" colspan="2" >Result:-&nbsp;<?php echo $failflg=='1'?"<span style='color:#F00'>Fail</span>":"<span style='color:#090'>Pass</span>"; ?></th>
         <th style="text-align:center;" colspan="2" >Percontage:-&nbsp;<?php echo number_format(($totalobtain*100)/$totalmark,0).'%'; ?></th>
                                    </tr>
                               </table>
                               
                                    
									
									
                       <?php
									}} 
                        			if($test_type=="" || $test_type=='retest')
									{
										
										
										$sql_retest_result="select   res.*,
														  setup.total_marks,
														  setup.passing_marks,
														  sub.subject_name
													 FROM 
															cms_resultmaster res,
															cms_examsetup setup,
															cms_subjectmaster sub
													 Where 
													 		res.subject_id = sub.subject_id
															AND setup.subject_id = sub.subject_id
															AND res.test_type = 'r'
															AND res.exam_id = setup.exam_id
															AND res.branch_id = setup.branch_id
															AND res.semester_id = setup.semester_id
															AND res.year_id = setup.year_id
															AND res.college_id = setup.college_id
															AND res.college_id = '".$_SESSION['VedantnrCollegeId']."'
															AND res.year_id ='".$_SESSION["VedantnrYearId"]."'	
															AND res.branch_id 	='".$branch_id."'
															AND res.semester_id ='".$semester_id."'	
															AND res.exam_id ='1'
															AND res.student_id='".$student_id."'  ";
												
												$retest_result = dbQuery($sql_retest_result);
												$retest_result_count=dbRows($retest_result);		 
												if($retest_result_count>0)
												{
												$totalmark= 0;
										$totalpassing= 0;
										$totalobtain= 0;
												 ?>
                                                 <h5 style="text-align:center">Retest Result</h5>
										<table class="table-report" border="1" cellpadding="0" cellspacing="0" width="100%">	
                                	<tr>
                                    	<th style="padding:2px;text-align:center;font-weight:bold;width:40%">Subject</th>
                                        <th style="padding:2px;text-align:center;font-weight:bold;width:20%">Total Mark</th>
                                        <th style="padding:2px;text-align:center;font-weight:bold;width:20%">Passing Mark</th>
                                        <th style="padding:2px;text-align:center;font-weight:bold;width:20%">Obtain Mark</th>
                                    </tr>
                                    <?php
									$student_id = $REC_STUDENT['student_id'];
									$branch_id = $REC_STUDENT['cur_branchid'];
									$semester_id= $REC_STUDENT['cur_semesterid'];
									$division_id= $REC_STUDENT['cur_divison'];
									$failflg=0;
									
										
									$res_result = dbQuery($sql_retest_result);
									while($rec_result = dbArray($res_result))	
									{
                                   ?>
                                   <tr>
                                   <td><?php echo $rec_result['subject_name']; ?></td>
                                   <td style="text-align:center;"><?php echo $rec_result['total_marks']; ?></td>
                                   <td style="text-align:center;"><?php echo $rec_result['passing_marks']; ?></td>
                                   <td style="text-align:center;"><?php echo $rec_result['obtain_mark']; ?></td>
                                   </tr>
                                    <?php 
									$totalmark+=$rec_result['total_marks'];
									$totalpassing+=$rec_result['passing_marks'];
									$totalobtain+=$rec_result['obtain_mark'];
									if($rec_result['obtain_mark']<$rec_result['passing_marks'])
									{
										$failflg=1;								
									}
											
									} ?>
											<tr>
                                    	<th style="text-align:right;padding-right:10px;" >Total</th>
                                        <th style="text-align:center;"><?php echo $totalmark; ?></th>
                                        <th style="text-align:center;">--</th>
                                        <th style="text-align:center;"><?php echo $totalobtain; ?></th>
                                    </tr>
                                    <tr>
                                     <th style="text-align:center;" colspan="2" >Result:-&nbsp;<?php echo $failflg=='1'?"<span style='color:#F00'>Fail</span>":"<span style='color:#090'>Pass</span>"; ?></th>
         <th style="text-align:center;" colspan="2" >Percontage:-&nbsp;<?php echo number_format(($totalobtain*100)/$totalmark,0).'%'; ?></th>
                                    </tr>
                                  </table>
                                    <?php } 
									}
									?>
                                    </td>
         </tr>
         </table>
         <br/>
        <div class="break">&nbsp;</div> 
		<?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";
?>