<?php
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class.php");
$obj=new my_class();
// ============

extract($_GET);

$section_id;
$ct_id;
$session;
$exam_term;
//echo 'hello from get_modeltest_report';
//$start;
//$end;
//"section_id="+section_id+"&quiz_type_id="+quiz_type_id+"&start="+start+"&end="+end;

//$from 	= date('Y-m-d',strtotime(str_replace("/","-",$start)));
//$to 	= date('Y-m-d',strtotime(str_replace("/","-",$end)));

$det_in = $obj->Details_By_Cond("_int_institute_setup_vw","section_id='$section_id'");

//$data = $obj->View_all_data_row_column_By_Cond("_qz_quize_subject qs","_id , _sub_full_name",1);
$data = $obj->View_all_data_row_column_By_Cond("_qz_mark_sheet ms left join _int_subject qs on ms._subject_id =qs._id","ms._subject_id , qs._subject_full_name,qs._subject_short_name","ms._qz_type_id=$quiz_type_id AND qs._status ='A' group by ms._subject_id ORDER BY qs._id ASC");
extract($data);


?>

<style type="text/css">
	.sub-select {
	    border: 2px solid red;
	    color: blue;
	    font-size: 16px;
	}
</style>


<div class="row-fluid" style="margin-top:10px;">
	<legend>
		<div class="row-fluid">
			<div class="span12">
				<?php echo 'Shift: '.$det_in['shift'].', Medium: '.$det_in['medium'].', Class: '.$det_in['class'].', Department: '.$det_in['department'].', Student Type: '.$det_in['student_type'].', Section: '.$det_in['section'].', Quiz Type: '.$qt['_quize_type'].', Session: '.$session; ?>.


				<a target="blank" href="module/quize/pdf_modeltest_report.php?section_id=<?php echo $section_id;?>&quiz_type_id=<?php echo $quiz_type_id;?>&session=<?php echo $session;?>" ><button class="btn btn-small btn-primary" type="button" style="float:right;text-align:center;"><i class='icon-print '></i>Print</button></a>

			</div>
		</div>

	</legend>
</div>


<div class="row-fluid">
	<div class="row-fluid">
		<div  class="row-fluid" id="form_data">
			<!-- <table id="sample-table-121" class="table table-striped table-bordered table-hover">	class="span12 " -->			
			<table id="sample_table" class="table table-striped table-bordered table-hover">		
				<tr>
					<th><?php echo "SL" ?></th>
					<th><?php echo "Publish Date"; ?></th>
					<th><?php echo "Student roll" ?></th>
					<th><?php echo "Student name" ?></th>
					<?php
						//$where = "inv.section_id='$section_id' AND (ms._date BETWEEN '".$from."' AND '".$to."') GROUP BY ms._std_id ORDER BY SUM(ms._mark) DESC";				
					$i=0;
					foreach($data as $column1){
					?>
						<th><?php echo $column1['_subject_short_name']; ?></th>
						
					<?php
						$subject_id_array[$i] = $column1['_subject_id'];
						$i++;
					}		
					?>
					<th><?php echo "Total"; ?></th>
					<!--<th><?php echo "Average"; ?></th>-->
					<th><?php echo "Position"; ?></th>
						
				</tr>
				<?php
				  
				//$student_roll_2darray = $obj->View_All("_qz_mark_sheet ms left join _pf_std_personal_info pf on pf._id = ms._std_id group by ms._std_id ","ms._std_id , pf._full_name , pf._uniq_id, pf._section_roll");  
				//if($quiz_type_id == 'all'){
					//$student_roll_2darray = $obj->View_all_data_row_column_By_Cond("_qz_master_result mr left join _pf_std_personal_info pf on pf._id = mr._std_id left join pf_std_basic_info bsf on pf._id=bsf._pid","mr._std_id , mr._position , mr._total_mark , mr._publish_date , pf._full_name , pf._uniq_id , pf._section_roll" , "pf._status = 'A' AND mr._section_id =$section_id AND mr._status = 'A' AND bsf._session='$session' group by mr._std_id ORDER BY mr._position ASC");  
					
				//}else{
					//$student_roll_2darray = $obj->View_all_data_row_column_By_Cond("_qz_master_result mr left join _pf_std_personal_info pf on pf._id = mr._std_id ","mr._std_id , pf._full_name , pf._uniq_id , pf._section_roll" , "pf._status = 'A' AND mr._section_id =$section_id AND mr._qz_type_id =$quiz_type_id group by mr._std_id ORDER BY pf._section_roll ASC");  
					$student_roll_2darray = $obj->View_all_data_row_column_By_Cond("_qz_master_result mr left join _pf_std_personal_info pf on pf._id = mr._std_id","mr._std_id , mr._position , mr._total_mark , mr._publish_date , pf._full_name , pf._uniq_id , pf._section_roll" , "pf._status = 'A' AND mr._section_id =$section_id AND mr._qz_type_id =$quiz_type_id  AND mr._status = 'A' AND mr._session='$session' group by mr._std_id ORDER BY mr._position,pf._section_roll ASC");  
					
				//}
				extract($student_roll_2darray);
				$j=0;
				foreach($student_roll_2darray as $student_roll_array){
				
					$student_roll = $student_roll_array['_section_roll'];	
					$student_uniq_id = $student_roll_array['_uniq_id'];	
					$student_id = $student_roll_array['_std_id'];	
					$student_name = $student_roll_array['_full_name'];	
					$student_total_mark = $student_roll_array['_total_mark'];
					$student_avg = $student_roll_array['_total_mark']/$i;
					$student_publish_date = $student_roll_array['_publish_date'];	
					$student_position = $student_roll_array['_position'];	
					$total =0;
				?>
					<tr>
						<td><?php echo $j+1; ?></td>
						<td><?php echo $student_publish_date; ?></td>
						<td><?php echo $student_roll; ?></td>
						<td><?php echo $student_name; ?></td>
					<?php 
						$k =0;
						while($k<$i){ // here $i is total subject counted number
							
							$subject_id = $subject_id_array[$k];
							//echo '<br>';
							//echo "select _subject_id ,sum(_mark) mark from _qz_mark_sheet ms where ms._subject_id = $subject_id AND ms._std_id = $student_roll AND (ms._date BETWEEN '".$from."' AND '".$to."') group by _subject_id";
							//if($quiz_type_id == 'all'){
								//$subject_mark_2darray = $obj->View_all_data_row_column_By_Cond("_qz_mark_sheet ms","_subject_id ,sum(_mark) mark"," ms._subject_id = $subject_id AND ms._status ='A' AND ms._std_id = $student_id AND ms._section_id =$section_id  AND (ms._date BETWEEN '".$from."' AND '".$to."') group by _subject_id ");
							//}else{
								$subject_mark_2darray = $obj->View_all_data_row_column_By_Cond("_qz_mark_sheet ms","_subject_id ,sum(_mark) mark"," ms._subject_id = $subject_id AND ms._status ='A' AND ms._std_id = $student_id  AND ms._section_id =$section_id AND ms._qz_type_id =$quiz_type_id group by _subject_id ");
							//}
							
							//if(!$subject_mark_2darray){
								 //echo '<td>n/a</td>';
							//}else{							
								extract($subject_mark_2darray);
								?>
								<td>
									<?php 
										$total = $total + $subject_mark_2darray[0]['mark'];	
										echo $subject_mark_2darray[0]['mark'];
									?>
								</td>
								<?php
								
							//}?>
							
						<?php
						$k++;
						}
						 //echo '<td>'.'('.$student_total_mark.')'.$total.'</td>';
						 echo '<td>'.$student_total_mark.'</td>';
						 //echo '<td>'.number_format((float)$student_avg, 2, '.', '').'</td>';
						 echo '<td>'.$student_position.'</td>';
						?>
					</tr>
					<?php
					$j++;
				}
				
				?>
			</table>	
		</div>
	</div>
</div>
