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

extract($_REQUEST);

$section_id;
$ct_id;
$exam_session;
$exam_term;
$pub_date = date('Y-m-d',strtotime(str_replace("/","-",$publish_date)));
//$from = date('Y-m-d',strtotime(str_replace("/","-",$from_date)));
//$to = date('Y-m-d',strtotime(str_replace("/","-",$to_date)));

$qt = $obj->Details_By_Cond("_ct_class_test_add","_id='$ct_id'");

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

if($quiz_type_id){
//$delstatus = $obj->Delete_Data("_qz_master_result","_br_id='".$_SESSION['LOGIN_BRANCH']."' AND _qz_type_id='$quiz_type_id' AND _section_id='$section_id' AND _from_date='$from' AND _to_date='$to'");
$delstatus = $obj->Delete_Data("_qz_master_result","_br_id='".$_SESSION['LOGIN_BRANCH']."' AND _qz_type_id='$quiz_type_id' AND _section_id='$section_id' AND _session='$session'");
}


				
//$where = "inv.section_id='$section_id' AND ms._qz_type_id='$quiz_type_id' AND (ms._date BETWEEN '".$from."' AND '".$to."') GROUP BY ms._std_id ORDER BY SUM(ms._mark) DESC";

//$where = "inv.section_id='$section_id' AND (ms._date BETWEEN '".$from."' AND '".$to."') GROUP BY ms._std_id ORDER BY SUM(ms._mark) DESC";
$where = "inv.section_id='$section_id' AND ms._session='$session' AND qt._id='$quiz_type_id' GROUP BY ms._std_id ORDER BY SUM(ms._mark) DESC";

$i=0;
foreach($obj->Quize_Merit_List($where) as $v1){
	if($tempmark==$v1['_total_mark']){
		$j = $i;
	}
	else{
		$j = ++$i;
	}
	//echo $v1['sec_id'].'--'.$v1['quiz_id'].'--'.$v1['_std_id'].'--'.$v1['_total_mark'];
	$form_data2=array(
	'_br_id'=>$_SESSION['LOGIN_BRANCH'],
	'_qz_type_id'=>$v1['quiz_id'],
	'_section_id'=>$v1['sec_id'],
	'_session'=>$session,
	'_std_id'=>$v1['_std_id'],
	'_total_mark'=>$v1['_total_mark'],
	'_position'=>$j,
	//'_from_date'=>$from,
	//'_to_date'=>$to,
	'_publish_date'=>$pub_date
	);
	
	$entry1 = $obj->Insert_Data("_qz_master_result",$form_data2);

	//echo $j.'='.$v1['_section_roll'].'='.$v1['_total_mark'].',';

	$tempmark = $v1['_total_mark'];
	}

echo "Result Published Successful";
?>
