<?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 '../classes/transcriptcal.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">Transcript CGPA</h5>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-bordered align-middle">
                            <thead>
                                <tr>
                                    <th>&nbsp;</th>
                                    <th>Roll Number</th>
                                    <th>Credit Earned</th>
                                </tr>
                            </thead>
                            <tbody>
                                
                                <?php while($row0 = mysqli_fetch_array($BatchArr)){ 
                                    $stu_roll = $row0["roll"];
$stu_name = $row0["name"];
$batch = $row0["batch"];
$sem_now = $row0["sem_now"];

$reg_status = $row0["reg_status"];

$sem_reg = $sem_now + 1;
$reg_file = "isr_reg_" . $batch."_tbl";
$reg_set = 0;
$total_credit_earned = 0;
$cr_cgpa = 0;
$mul_cgpa = 0;
                                    ?> 
                                <tr>
                                    <td>
                                        <?php echo $i; ?>
                                    </td>
                                    <td>
                                        <?php echo $stu_roll; ?>
                                    </td>
                                    <td>
                                        <?php
                                        for ($sem = 1; $sem <= 4; $sem++) {


	$query = "SELECT sum(b.sub_crdit) as aaa from $reg_file a, isr_curriculum_tbl b where b.sub_list = a.sub_list and a.sub_flag = 'Y' and a.sem = '$sem' and a.stu_roll = '$stu_roll' and a.sub_code = b.sub_code and a.grade in ('A+', 'A', 'B+', 'B', 'C+',  'C', 'D', 'P') order by a.sub_code";
	$ObjDB->sproc_name = $query;
        $res_Query = $ObjDB->SelectQuery();
        list($credit_earned) = mysqli_fetch_row($res_Query);
	$total_credit_earned = $total_credit_earned + $credit_earned;

	$query_1 = "SELECT a.sub_code, a.grade, 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.sem = '$sem' and a.stu_roll = '$stu_roll' and a.sub_code = b.sub_code and a.grade in ('A+', 'A', 'B+', 'B', 'C+',  'C', 'D', 'F') order by a.sub_code";
        $ObjDB->sproc_name = $query_1;
        $res_Query_1 = $ObjDB->SelectQuery();
        
	$cr_sem = 0;
	$mul_sem = 0;
    while ($row = mysqli_fetch_array($res_Query_1)) {
		$sub_code = $row["sub_code"];
		$sub_title = $row["sub_title"];
		$grade = $row["grade"];
		$credit = $row["sub_crdit"];
		$grade_value = GetGradeValue($reg_file, $grade);
        $credit_value = $grade_value * $credit;
		$cr_sem = $cr_sem + $credit;
		$mul_sem = $mul_sem + $credit_value;

		$cr_cgpa = $cr_cgpa + $credit;
		$mul_cgpa = $mul_cgpa + $credit_value;
	}

	$sgpa = round(($mul_sem/$cr_sem),2);
	$cgpa = round(($mul_cgpa/$cr_cgpa),2);
	$sgpa = number_format($sgpa,2);
	$cgpa = number_format($cgpa,2);
}
echo $total_credit_earned;
?>
                                    </td>
                                </tr>
                                <?php } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

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