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

if ($_POST['reg_search_btn']) {
    $stu_roll = $roll_number = $val->ValidateString($_REQUEST['roll_number']);

    $objadm->roll_number = $roll_number;
    $rowStudent = $objadm->GetStudentDetailsbyRollNumber();

    while ($row = mysqli_fetch_array($rowStudent)) {
        $stu_name = $row["name"];
        $batch = $row["batch"];
        $sem_now = $row["sem_now"];
        $reg_status = $row["reg_status"];
        $reg_file = "isr_reg_" . $batch . "_tbl";
    }

    $curr_file = "curr";
    $sub_list = 'c5';
    $reg_closed = "N";

    if (substr($batch, 0, 1) == 'r') {
        $jj = 11;
    } else {
        $jj = 1;
    }

    $query_str = "SELECT distinct sem from $reg_file";
    $ObjDB->sproc_name = $query_str;
    $result_str = $ObjDB->SelectQuery();

    $num_rows = mysqli_num_rows($result_str);
    $tot_credit = 0;
    $tot_credit_value = 0;
    for ($i = $jj; $i <= $num_rows + $jj - 1; $i++) {
        $show_sem = $i;
        if ($i > 10) {
            $show_sem = $i - 10;
        }

        $table_view .= '<table class="table table-striped table-bordered table-condensed">';
        $table_view .= '<tr><th colspan="5"><div class="stu_name"> Semester : ' . $show_sem . '</th></tr>';

        $to_cal = 1;
        $query_str1 = "SELECT $reg_file.reg_sr, $reg_file.sub_code, $reg_file.grade, $reg_file.grade_flag, $reg_file.sub_flag, curr.sub_title, curr.sub_crdit from $reg_file, isr_curriculum_tbl as curr where curr.sub_list = $reg_file.sub_list and $reg_file.sem = '$i' and $reg_file.stu_roll = '$stu_roll' and $reg_file.sub_code = curr.sub_code order by $curr_file.sub_crdit desc, sub_code";

        $ObjDB->sproc_name = $query_str1;
        $result_str1 = $ObjDB->SelectQuery();

        $j = 1;
        $sum_credit = 0;
        $sum_credit_value = 0;
        while ($row = mysqli_fetch_array($result_str1)) {
            $reg_sr = $row["reg_sr"];
            $sub_code = $row["sub_code"];
            $grade = $row["grade"];
            $grade_flag = $row["grade_flag"];
            $sub_flag = $row["sub_flag"];
            $table_view .= '<TR><TD width="20">' . $j++;
            $table_view .= '<TD wodth="80">' . $sub_code;
            $sub_credit = $row["sub_crdit"];
            $sum_credit = $sum_credit + $sub_credit;
            $sub_title = $row["sub_title"];
            $table_view .= '<TD width="400">';
            if ($sub_flag == "S" or $sub_flag == "D") {
                $table_view .= "<S>" . $sub_title . "</S>";
            } else {
                $table_view .= $sub_title;
            }
            $table_view .= "<TD width=50>" . $sub_credit;
        }
        $table_view .= "</table>";
        $table_view .= "<BR>";
    }
}
?>
<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">Student Search By Roll Number</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-lg-2"></div>
                        <div class="col-lg-8">                        
                            <form action="" method="POST">
                                <div class="mb-3" style="padding-left: 0px;">
                                    Roll Number
                                </div>
                                <div class="mb-9" style="padding-left: 0px;">
                                    <input type="text" name="roll_number" id="roll_number"  class="form-control" value="<?php echo $roll_number; ?>"/>
                                </div>
                                <input type="submit" class="btn btn-danger" style="background: #a9181b;
                                       border: #a9181b; text-align: center;" value="Submit" name="reg_search_btn"/>

                            </form>

                        </div>
                        <div class="col-lg-2"></div><br/><br/>
                    </div>
                    <?php if($_POST){ ?>
                    <div class="row">
                        <br/>
                        <div class="table-responsive">
                            <table class="table table-bordered align-middle">
                                <tr>
                                    <td><b>Name of the Student</b></td>
                                    <td><?php echo $stu_name; ?></td> 
                                </tr>
                                <tr>
                                    <td><b>Roll No</b></td>
                                    <td><?php echo $roll_number; ?></td>
                                </tr>
                                <tr>
                                    <td><b>Current Semester</b></td>
                                    <td><?php echo $sem_now; ?></td>
                                </tr>
                                <tr>
                                    <td><b>Current Batch</b></td>
                                    <td><?php echo $batch; ?></td>
                                </tr>
                            </table>
                            <br/>
                            <?php echo $table_view; ?>
                        </div>
                    </div>
                    <?php } ?>
                </div>
            </div>
        </div>
    </div>
</div>

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