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

$batch = $val->ValidateString($_REQUEST['batch']);
$reg_file = "isr_reg_".$batch."_tbl";
include_once 'sub-list-finder.php';

$i = 1;

$objadm->batch = $batch;
$BatchArr = $objadm->GetStudentDetailsbyBatch();

?>
<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">Credit Distribution <?php echo $batch; ?></h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered align-middle">
                            <thead>
                                <tr>
                                    <th >&nbsp;
                                    <th >Roll
                                    <th >Name
                                    <th >Registered
                                    <th >Cleared
                                   
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                while ($rowm = mysqli_fetch_array($BatchArr)) {
	$stu_roll = $rowm['roll'];
	$stu_name = ucwords(strtolower($rowm['name']));
	?>
	<tr>
	<td ><?php echo $i; ?></td>
	<td ><?php echo $stu_roll; ?><Td ><?php echo $stu_name; ?>
	<?php 
	if($batch == 'b12' or $barch == 'r10') {
		$query="SELECT a.sub_code, a.grade, a.sem, b.sub_title, b.sub_crdit from $reg_file a, isr_curriculum_tbl b where b.sub_list = a.sub_list and a.sub_flag = 'Y' and a.stu_roll = '$stu_roll' and a.sub_code = b.sub_code and a.grade in ('O', 'A', 'B', 'C', 'D', 'S', 'P') order by a.sub_code";
	} else {
		$query="SELECT a.sub_code, a.grade, a.sem, b.sub_title, b.sub_crdit from $reg_file a, isr_curriculum_tbl b where b.sub_list = a.sub_list and a.sub_flag = 'Y' and a.stu_roll = '$stu_roll' and a.sub_code = b.sub_code and a.grade in ('A+', 'A', 'B+', 'B', 'C+', 'C', 'D', 'S', 'P') order by a.sub_code";
	}
        $ObjDB->sproc_name = $query;
        $res_query = $ObjDB->SelectQuery();
        $credit_cleared = 0;
        while ($row = mysqli_fetch_array($res_query)) {
		$sub_credit= $row["sub_crdit"];
		$credit_cleared = $credit_cleared + $sub_credit;
	}

	$credit_registered = 0;
	$query="SELECT a.sub_code, a.grade, b.sub_crdit from $reg_file a, isr_curriculum_tbl b where b.sub_list = a.sub_list and a.sub_flag = 'Y' and a.stu_roll = '$stu_roll' and a.sub_code = b.sub_code order by a.sub_code";

	while ($row = mysqli_fetch_array($query)) {
		$sub_credit= $row["sub_crdit"];
		$credit_registered = $credit_registered + $sub_credit;
	}


	
	?>
	<td ><?php echo $credit_registered;?></td>
	<td ><?php echo $credit_cleared;?></td>
	</tr>

	<?php
	$i++;
} ?>
                               
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php
$pagemaincontent = ob_get_contents();
ob_clean();
$PAGENAME = 'reports-credit-cleared-view';
$HTMLTITLE = '';
$HTMLDESCRIPTION = '';
$HTMLKEYWORDS = '';
include("admin-master.php");
?>