<?php
include_once '../session/admin-session.php';
include_once '../classes/class_admin.php';
include_once '../classes/validation.php';
include_once '../classes/common.php';
include_once 'read-configration.php';

$ObjDB = new class_db();
$log = new common();
$objadm = new class_admin();
$val = new validation();

$admin_roll = $_SESSION['user_sesroll'];

$sub_code = $val->ValidateString($_POST['sub_code']);
$qc ="select a.*, b.batch from reg_repeat a, stu_main b where a.sub_code = '$sub_code' and a.reg_status in ('P', 'T') and a.stu_roll = b.roll order by a.stu_roll";
$ObjDB->sproc_name = $qc;
$res_qc = $ObjDB->SelectQuery();

$i = 0;
while ($rc = mysqli_fetch_array($res_qc)) {
	$stu_roll = $rc['stu_roll'];
	$batch = $rc['batch'];
	$new_grade = $rc['new_grade'];
	if($new_grade <> '') {
		$reg_file = 'isr_reg_'.$batch."_tbl";
		$qup = "update $reg_file set grade = '$new_grade' where stu_roll = '$stu_roll' and sub_code = '$sub_code'";
		$ObjDB->sproc_name = $qup;
                $ObjDB->ExecuteQuery();
		$i++;
	}
}
$qin = "insert into isr_reg_repeat_approved_tbl (sub_code, app_num, admin_roll) values('$sub_code', '$i', '$admin_roll')";
$ObjDB->sproc_name = $qin;
$ObjDB->ExecuteQuery();

header("location:control-repeat-exam.php");
?>