<?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();
$val = new validation();

$sem = $val->ValidateString($_REQUEST["sem"]);
$batch = $val->ValidateString($_REQUEST["batch_no"]);
?>
<table border="1" cellspacing="0" cellpadding="1" width="80%" align="center">
    <?php
    $reg_file = "isr_reg_" . $batch . "_tbl";
    $query1 = "SELECT distinct reg.sub_code, curr.sub_crdit FROM " . $reg_file . " as reg, isr_curriculum_tbl as curr where curr.sub_list = reg.sub_list AND reg.sub_flag = 'Y' and reg.sem = '$sem' and reg.sub_code = curr.sub_code order by reg.sub_code";
    $ObjDB->sproc_name = $query1;
    $result_str = $ObjDB->SelectQuery();

    $numberofrows = mysqli_num_rows($result_str);
    for ($i = -1; $i < $numberofrows; $i++) {
        if ($i == -1) {
            echo "<tr><td colspan=2>&nbsp;</td>";
        } else if ($i == $numberofrows - 1) {
            $row1 = mysqli_fetch_array($result_str);
            $sub_code[$i] = $row1["sub_code"];
            $sub_credit[$i] = $row1["sub_crdit"];
            echo "<TD align=center>" . substr($sub_code[$i], 0, 3) . "<BR>" . substr($sub_code[$i], 3, 3) . "<BR>" . $sub_credit[$i] . "</td>";
        } else {
            $row1 = mysqli_fetch_array($result_str);
            $sub_code[$i] = $row1["sub_code"];
            $sub_credit[$i] = $row1["sub_crdit"];
            echo "<TD align=center>" . substr($sub_code[$i], 0, 3) . "<BR>" . substr($sub_code[$i], 3, 3) . "<BR>" . $sub_credit[$i] . "</td>";
        }
    }
    echo "<td>CD</td>";
    $query2 = "SELECT * FROM isr_stu_main_tbl where batch = '$batch' order by roll";
    $ObjDB->sproc_name = $query2;
    $result_str2 = $ObjDB->SelectQuery();
    $numberofrows2 = mysqli_num_rows($result_str2);
    for ($ii = 0; $ii < $numberofrows2; $ii++) {
        $row2 = mysqli_fetch_array($result_str2);
        $stu_roll = $row2["roll"];
        $stu_name = $row2["name"];

        $stu_credit = 0;
        echo "<TR><TD>" . $stu_roll . "</TD><td>" . $stu_name . "</td>";
        for ($i = 0; $i < $numberofrows; $i++) {
            $this_reg = "&nbsp;";
            $query3 = "SELECT reg_sr, grade, grade_flag FROM " . $reg_file . " as reg where reg.sub_flag = 'Y' and sub_code = '$sub_code[$i]' and stu_roll = '$stu_roll' and sem = '$sem'";
            $ObjDB->sproc_name = $query3;
            $result_str3 = $ObjDB->SelectQuery();
            $numberofrows3 = mysqli_num_rows($result_str3);
            if ($num_reg == 1) {
                $this_reg = "Y";
                $stu_credit = $stu_credit + $sub_credit[$i];
            }
            $row3 = mysqli_fetch_array($result_str3);
            echo "<TD align=center>" . $this_reg . "</TD>";
        }
        echo "<td>" . $stu_credit . "</td>";
    }
    echo "</TR>";
    ?>
</table>