<?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['student_gturegno'] == "")
{
?>
	<script language="javascript" type="text/javascript">
		location.href='report-student-overall-perfomance.php';
	</script>
<?php
}
elseif($_SESSION['VedantnrCollegeId']!="" && isset($_SESSION['VedantnrCollegeId'])) 
{ 
	ob_start();
	dbquery("SET group_concat_max_len = 102400");
		
	function curmonth_days($branch_id,$semester_id,$div_id,$monthname,$year_id,$subject_id,$batch_id)
	{
		/* START PRESENT DAYS CODE */ 
		  $sql_days = "
			SELECT 
				*
			FROM 
				cms_presentmaster 
			WHERE 
				day_working = 1 
				AND branch_id = '".$branch_id."'
				AND semester_id = '".$semester_id."'
				AND div_id = '".$div_id."'
				AND subject_id = '".$subject_id."'
				AND college_id = '".$_SESSION['VedantnrCollegeId']."'
				AND year_id = ".$year_id.
				" AND batch_id IN ('".$batch_id."',0)";
		
		$res_days = dbQuery($sql_days);	
		//echo	dbRows($res_days);
		return dbRows($res_days);
		/*$rec_days = dbArray($res_days);
		$rec_days = explode(",",$rec_days['day_present']);
		$rec_days = array_count_values($rec_days);
		return $rec_days[$student_id];*/
		/* END PRESENT DAYS CODE */
	}
	
	function curmonth_presentdays($branch_id,$semester_id,$div_id,$monthname,$year_id,$student_id,$subject_id,$batch_id)
	{
		/* START PRESENT DAYS CODE */ 
		 $sql_days = "
			SELECT 
				GROUP_CONCAT(day_present) AS day_present
			FROM 
				cms_presentmaster 
			WHERE 
				day_working = 1 
				AND branch_id = '".$branch_id."'
				AND semester_id = '".$semester_id."'
				AND div_id = '".$div_id."'
				AND subject_id = '".$subject_id."'
				AND college_id = '".$_SESSION['VedantnrCollegeId']."'
				AND year_id = ".$year_id.
				" AND batch_id IN ('".$batch_id."',0)";
		$res_days = dbQuery($sql_days);		
		$rec_days = dbArray($res_days);
		$rec_days = explode(",",$rec_days['day_present']);
		 $rec_days = array_count_values($rec_days);
		//print_r($rec_days);
		if($rec_days[$student_id] > 0)
			return $rec_days[$student_id];
		return 0;	
		/* END PRESENT DAYS CODE */
	}
			
	$sql_studentdata = "SELECT sd.student_id,cur_branchid,batch_id,cur_semesterid,cur_divison,year_id FROM `cms_studentmaster` sm,cms_studentdetail sd where sm.student_id=sd.student_id and sm.student_gturegno='".Escape($_REQUEST['student_gturegno'])."' order by sd.year_id";
	$res_studentdata = dbQuery($sql_studentdata);

	if(dbRows($res_studentdata)>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>Student Overall Report</h4></center>
        <br />
    <?php
	$studentprofileflag=0;
		while($rec_studentdata = dbArray($res_studentdata))
		{
			
			
	$branch_id 		= $rec_studentdata['cur_branchid'];
	$semester_id	= $rec_studentdata['cur_semesterid'];
	$division_id	= $rec_studentdata['cur_divison'];
	$batch_id 		= $rec_studentdata['batch_id'];
	$year_id 		= $rec_studentdata['year_id'];
	
	$gturegno		= Escape($_REQUEST['student_gturegno']);
	
	$order_by = 'student_gturegno';
	$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.batch_id,
			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 = ".$year_id;
	
	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 != ""){ 
		$SQL_CONDITION .= " AND sm.student_gturegno = '".$gturegno."' ";
	}
	
	
	$SQL_CONDITION .= " ORDER BY sd.cur_branchid ASC, sd.cur_semesterid ASC , sd.cur_divison ASC ";
	
	if($order_by != "" && $order_by != "undefined"){
		$SQL_CONDITION .= ",".$order_by." ASC ";
	}
	else{
		$SQL_CONDITION .= " ,student_gturegno ASC ";
	}
	
	if($SQL_CONDITION != ""){
		 $SQL_STUDENT .= $SQL_CONDITION;
	}
	
		
	  
		
	$RES_STUDENT = dbQuery($SQL_STUDENT);
	
	if(dbRows($RES_STUDENT)>0){?>
    	
        <?php
		
		while($REC_STUDENT = dbArray($RES_STUDENT))
		{
			?>
                   
        
        
        <?php if($studentprofileflag==0)
		{$studentprofileflag=1;?>
        <h3>Student Profile Detail </h3>
        
        <table class="table-report" border="1" cellpadding="0" cellspacing="0" width="90%">
		
         <tr>
        	<th style="text-align:left;" width="20%"  >Student Name</th>
            <td style="text-align:left;" width="40%"  ><?php echo $REC_STUDENT['student_name']; ?></td>
            <th style="text-align:left;" width="15%"  >Enrollment No</th>
            <td style="text-align:left;" width="25%"  ><?php echo $REC_STUDENT['student_gturegno']; ?></td>
            
         </tr>
         
         <tr>
        	<th style="text-align:left;"    >Address</th>
            <td style="text-align:left;" colspan="3"   ><?php echo $REC_STUDENT['student_address']; ?></td>
          </tr>
          <tr>
        	  </tr>
          
           <tr>
            <th style="text-align:left;"   >Phone(Parents)</th>
            <td style="text-align:left;"   ><?php echo $REC_STUDENT['student_mobileparents']; ?></td>
            <th style="text-align:left;"   >Phone(Student)</th>
            <td style="text-align:left;"   ><?php echo $REC_STUDENT['student_mobilestudents']; ?></td>
          </tr>
           <tr>
           <th style="text-align:left;"   >Email ID</th>
            <td style="text-align:left;"   ><?php echo $REC_STUDENT['student_emailid']; ?></td>
        	<th style="text-align:left;"   >DOB</th>
            <td style="text-align:left;"   ><?php echo date('d-m-Y',strtotime($REC_STUDENT['student_birthdate'])); ?></td>
          </tr>
         
        </table>
        <br />
        <hr />
        <br />
        <?php } ?>
        
 		
        <div style="float:left; margin-left:48px; font-size:12px"><b>Branch:-</b><?php echo $REC_STUDENT['branch_name'];  ?></div>
		<div style="float:right; margin-right:48px; font-size:12px"><b>Sem:-</b><?php echo  $REC_STUDENT['semester_name'].'-'.$REC_STUDENT['cur_divison']; ?></div>
        <h3>Student Present Detail</h3>
        <table class="table-report" border="1" cellpadding="0" cellspacing="0" width="90%">	
                                	<tr>
                                    	<th style="padding:2px;text-align:center;font-weight:bold;width:80%">Subject</th>
                                        <th style="padding:2px;text-align:center;font-weight:bold;width:20%">Total %</th>
                                    </tr>
                                    <?php
										$count_present = 0;
										$count_absent = 0;
										$count_present1 = 0;
										$count_absent1 = 0;
										$temp_wdays = 0;
										$temp_pdays = 0;
										$totalmark= 0;
										$totalpassing= 0;
										$totalobtain= 0;
										
										$student_id = $REC_STUDENT['student_id'];
										$branch_id = $REC_STUDENT['cur_branchid'];
										$semester_id= $REC_STUDENT['cur_semesterid'];
										$division_id= $REC_STUDENT['cur_divison'];
										$batch_id= $REC_STUDENT['batch_id'];
                                   
									  $sql_subject = "
										SELECT
											DISTINCT sm.subject_name,sm.subject_id
										FROM
											cms_presentmaster pm,
											cms_subjectmaster sm
										WHERE
											sm.subject_id = pm.subject_id AND
											pm.branch_id = '".$branch_id."' AND
											pm.semester_id = '".$semester_id."' AND
											pm.div_id = '".$division_id."' AND
											pm.college_id = '".$_SESSION['VedantnrCollegeId']."' AND
											pm.year_id = ".$year_id." 
									  ORDER BY
											sm.subject_id ASC ";
				
											$res_subject = dbQuery($sql_subject);
											while($rec_subject = dbArray($res_subject)){
												$subject_id = $rec_subject['subject_id'];
											?>
												<tr>
									<td style="padding:2px;text-align:left;"><?php echo $rec_subject['subject_name']; ?></td>
							<?php
							$wdays = curmonth_days($branch_id,$semester_id,$division_id,$monthname,$year_id,$subject_id,$batch_id);	
													$temp_wdays += $wdays; 
													 ?>
                                         <?php 
													$pdays = curmonth_presentdays($branch_id,$semester_id,$division_id,$monthname,$year_id,$student_id,$subject_id,$batch_id);
                                                    $temp_pdays += $pdays; 
													 ?>
                                               	<td style="text-align:center;"><?php echo round(($pdays*100)/$wdays)."%"; ?></td>
												</tr><?php
											}?>
									<tr>
                                    	<th style="text-align:right;padding-right:10px;" >Total</th>
                                        <th style="text-align:center;"><?php echo number_format(($temp_pdays*100)/$temp_wdays,0)."%"; ?></th>
                                    </tr>
                                    <?php		
										
									?>
                                    
                                </table>
         
        
                                    <?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;
									
									
									 $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 ='".$year_id."'	
															AND res.branch_id 	='".$branch_id."'
															AND res.semester_id ='".$semester_id."'	
															AND res.exam_id ='1'
															AND res.student_id='".$student_id."'  ";
										
									$res_result = dbQuery($sql_result);
									$res_result_count=dbRows($res_result);		 
									if($res_result_count>0)
									{ ?>
                                    <h3>Student Result Detail</h3> 
        							<h5>First Test</h5>
                                    <table class="table-report" border="1" cellpadding="0" cellspacing="0" width="90%">	
                                	<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" >Percentage:-&nbsp;<?php echo number_format(($totalobtain*100)/$totalmark,0).'%'; ?></th>
                                    </tr>
                               </table>
                                    
									<?php }
									?>
									
                                
                                <?php
								$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 ='".$year_id."'	
															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>Retest Result</h5>
										<table class="table-report" border="1" cellpadding="0" cellspacing="0" width="90%">	
                                	<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" >Percentage:-&nbsp;<?php echo number_format(($totalobtain*100)/$totalmark,0).'%'; ?></th>
                                    </tr>
                               </table>
												 <?php }
															?>
           						 <h5>Enrollment Result</h5>
                                 <?php $flag=0;?>
                                 <table class="table-report" border="1" cellpadding="0" cellspacing="0" width="90%">
                                  <?php if(file_exists('gtu result pdfs/'.$year_id.'/'.$branch_id.'/'.$semester_id.'/General/'.$gturegno.'.pdf'))
				   				{ $flag=1;
							?>
                             <tr>
                                 <td>
                               
                                 <a href="gtu result pdfs/<?php echo $year_id.'/'.$branch_id.'/'.$semester_id.'/General/'.$gturegno.'.pdf'; ?>" target="_blank">Click to see General Exam Result</a></td>
                                 </tr>
                            
                            <?php  } ?>
										
                                 <?php if(file_exists('gtu result pdfs/'.$year_id.'/'.$branch_id.'/'.$semester_id.'/Retest/'.$gturegno.'.pdf'))
				   				{ $flag=1;
							?>
                             <tr>
                                 <td>
                               
                                 <a href="gtu result pdfs/<?php echo $year_id.'/'.$branch_id.'/'.$semester_id.'/Retest/'.$gturegno.'.pdf'; ?>" target="_blank">Click to see Retest Result</a></td>
                                 </tr>
                            
                            <?php  } ?>
                            
                            	 <?php if($flag==0)
				   				{ 
							?>
                             <tr>
                                 <td>
                               Sorry, No Link available!
                                </td>
                                 </tr>
                            
                            <?php  } ?>
                                 </table>
          
                              
      
        
          <?php
		}
		
	}
	else{
		echo "NO DATA FOUND!";	
	}?><br /><br /><hr /><br /><br />
	<?php
	} }
?>

<?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";
?>