<?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';
ob_start();

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

$semb1 = $current_sem_num;

if ($_POST['change_grade_btn']) {
    $roll_no = $val->ValidateString($_REQUEST['roll_no']);
    $subject_code = $val->ValidateString($_REQUEST['subject_code']);
    $old_code = $val->ValidateString($_REQUEST['old_code']);

    $objadm->roll_number = $roll_no;
    $res_query = $objadm->GetStudentDetailsbyRollNumber();

    $num = mysqli_num_rows($res_query);
    if ($num != 1) {
        $msg = "Incorrect Roll Number";
    } else {
        $row = mysqli_fetch_array($res_query);
        $stu_name = $row["name"];
        $batch = $row["batch"];
// echo $batch;
        $reg_file = "isr_reg_" . $batch . "_tbl";
        $curr_file = "isr_curriculum_tbl";
        $sub_list = 'c' . $semb1;

        $objadm->res_sem = $sub_list;
        $objadm->res_subject_code = $subject_code;

        $query = $objadm->GetcurriculumList();
        $num = mysqli_num_rows($query);
// if ($num != 1) die ("Incorrect Subject Code");
        $row = mysqli_fetch_array($query);
        $sub_title = $row["sub_title"];

        $query = "SELECT * from $reg_file where sub_code = '$subject_code' and b1_sem = '$semb1' and stu_roll = '$stu_roll' and sub_flag = 'Y'";
        $ObjDB->sproc_name = $query;
        $res_query_1 = $ObjDB->SelectQuery();
        $num = mysqli_num_rows($res_query_1);

        if ($num != 1) {
            $msg = "$stu_name ($stu_roll) has not registered for $sub_title ($subject_code).";
        } else {
            $row = mysqli_fetch_array($res_query_1);
            $grade = $row["grade"];
            $grade_flag = $row["grade_flag"];

            if ($grade != $old_grade) {
                $msg = "$old_grade is not the present grade of $stu_name ($stu_roll) in $sub_title ($subject_code).";
            }
        }
    }
}
?>
<div class="container-fluid">
    <div class="row">
        <div class="col-xl-12 col-xxl-12 col-sm-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title">Change Grade</h5>
                </div>
                <div class="card-body">
                    <form action="" method="POST">
                        <div class="row"><div class="col-lg-12"><?php echo $msg; ?></div></div>
                        <div class="row">
                            <div class="col-lg-3">
                                <label>Roll Number:</label>
                                <input type="text" name="roll_no" id="roll_no" class="form-control"/>
                            </div>
                            <div class="col-lg-3">
                                <label>Subject Code:</label>
                                <input type="text" name="subject_code" id="subject_code" class="form-control"/>
                            </div>
                            <div class="col-lg-3">
                                <label>Old Code:</label>
                                <input type="text" name="old_code" id="old_code" class="form-control"/>
                            </div>
                            <div class="col-lg-3">
                                <input type="submit" name="change_grade_btn" id="change_grade_btn" value="SUBMIT"/>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<?php
$pagemaincontent = ob_get_contents();
ob_clean();
$PAGENAME = 'control-change-grade';
$HTMLTITLE = '';
$HTMLDESCRIPTION = '';
$HTMLKEYWORDS = '';
include("admin-master.php");
?>