<?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 '../classes/sgpa.php';
include_once 'read-configration.php';

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

 require_once('../tcpdf/tcpdf.php');
 
$issuedate = $_REQUEST["issuedate"];
$stu_roll = $val->ValidateString($_REQUEST["rollno"]);


$pdf = new TCPDF(PDF_PAGE_ORIENTATION, 'pt', PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('IISER Pune');
$pdf->SetTitle('IISER Pune');
$pdf->SetSubject('Learning');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(35, 35, 35, true);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

  $objadm->roll_number = $stu_roll;
  $res_StudentDet = $objadm->GetStudentDetailsbyRollNumber();

$num = mysqli_num_rows($res_StudentDet);
if ($num != 1)
    die("Incorrect Roll Number");
$row = mysqli_fetch_array($res_StudentDet);
$stu_name = $row["name"];
$dob = $row["dob"];
$dob_pass = substr($dob, 8, 2) . substr($dob, 5, 2) . substr($dob, 0, 4);
$batch = $row["batch"];
$file_name = $stu_roll . '.pdf';
// $file_pass = $stu_roll . $dob_pass;
// $file_pass = "12345";
$file_pass = "";

$pdf->SetFont('helvetica', '', 10);
$pdf->AddPage();
$pdf->SetProtection(array('print-high', 'copy'), $file_pass, null, 0, null);
$pdf->SetAlpha(0.1);

// $pdf->Image('../image/IISER_RoundStamp7', $myX, $myY, $ImageW, $ImageH, '', '', '', true, 150);

//$pdf->Image('../image/IISER_RoundStamp7.png', '150', '150', '300', '300', '', '', '', true, 150);

$pdf->SetAlpha(1);

$view_tbl = "";

include "sub-list-finder.php";

$add_period = $val->ValidateString($_REQUEST["sem_now"]);
$sem_now = $add_period;

$roll_year = substr($stu_roll, 0, 4);
$batch_no = $roll_year - 2005;
$exam_year = $roll_year + floor($sem_now / 2);
$reg_file = "isr_reg_" . $batch."_tbl";

$base_period = (($roll_year - 2006) * 2);
$admission_period = $base_period + 1;
// $period = $base_period + $add_period;

$period = $add_period;

$residence_semester = $sem_now - $base_period;
$curr_file = "curr";

if (substr($batch, 0, 1) == 'b') {
    if ($batch == 'b13' or $batch == 'b14' or $batch == 'b15' or $batch == 'b16' or $batch == 'b17' or $batch == 'b18' or $batch == 'b19') {

$queryb1 = "SELECT * FROM isr_iiser_sem_tbl where sem_num = '$admission_period'";
$ObjDB->sproc_name = $queryb1;
$res_queryb1 = $ObjDB->SelectQuery();
$rowb1 = mysqli_fetch_array($res_queryb1);
$admission_period_name = $rowb1["sem_name"];

$queryb1 = "SELECT * FROM isr_iiser_sem_tbl where sem_num = '$period'";
$ObjDB->sproc_name = $queryb1;
$res_queryb1 = $ObjDB->SelectQuery();
$rowb1 = mysqli_fetch_array($res_queryb1);
$trans_period_name = $rowb1["sem_name"];

$queryb1 = "SELECT * FROM isr_result_date_tbl where abs_sem = '$period' and batch = '$batch'";
$ObjDB->sproc_name = $queryb1;
$res_queryb1 = $ObjDB->SelectQuery();
$rowb1 = mysqli_fetch_array($res_queryb1);
$approval_date = $rowb1["approval_date"];

        $view_tbl .= '<html><body><style type="text/css">
                    body, html{
                        font-family: arial;
                        font-size: 12px;
                    }
                    td{
                        padding: 5px;
                    }
                </style>
                <center>
                <IMG SRC="../image/Transcript_head_1_transparent.png" WIDTH="700" BORDER="0" ALT=""> 
                </center>
            <br/><br/>
            <table cellspacing="0" cellpadding="3" width = "100%" align="center">
                <tr><td width="130" align="left">Name of the student</td><td align="left"><b>' . strtoupper($stu_name) . '</b></td><td width="120" align="left">Joining Semester</td><td align="left">' . $admission_period_name . '</td></tr>
                <tr><td align="left">Roll Number</td><td align="left"><b>' . $stu_roll . '</b></td><td align="left">Residence Semester</td><td align="left">' . $residence_semester . '</td></tr>
            </table>
            <br/>
            <div align="center"><strong>Chronological Transcript: ' . $trans_period_name . '</strong></div><br/>
            <table cellspacing="0" cellpadding="3" align="center">
                <tr><td width="30" style="border: 1px #ddd solid;">&nbsp;</td><td style="border: 1px #ddd solid;" width="100" align="center">Course code</td>
                    <td width="350" style="border: 1px #ddd solid;" align="center">Course title</td><td style="border: 1px #ddd solid;" width="50" align="center">Credits</td>
                    <td style="border: 1px #ddd solid;" width="50" align="center">Grade</td></tr>';

        $query = "SELECT a.sub_code, a.grade, a.grade_flag, a.sub_flag, 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 in ('Y','T') and a.b1_sem = '$period' and a.stu_roll = '$stu_roll' and a.sub_code = b.sub_code order by b.sub_crdit desc, b.sub_code";
        $ObjDB->sproc_name = $query;
        $res_Query = $ObjDB->SelectQuery();
        $j = 1;
        $add_3 = 0;
        while ($row = mysqli_fetch_array($res_Query)) {
            $sub_code = $row["sub_code"];
            $grade2 = $row["grade"];
            $grade_flag = $row["grade_flag"];
            $sub_credit = $row["sub_crdit"];
            $sub_title = $row["sub_title"];
            if ($sub_code == 'HS1113') {
                if ($grade2 == 'P') {
                    $add_3 = 3;
                }
            }

            if ($sub_credit == 0) {
                $grade2 = "P";
            }

            $view_tbl .= '<tr><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $j++ . '</td><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $sub_code . '</td><td style="border: 1px #ddd solid;" align="left">&nbsp;' . $sub_title . '</td>
            <td style="border: 1px #ddd solid;" align="center">&nbsp;' . $sub_credit . '</td><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $grade2;
            if ($grade_flag == "R") {
                $view_tbl .= '<sub> R</sub>';
            }
            if ($grade_flag == "A") {
                $view_tbl .= '<sub> A</sub>';
            }
            $view_tbl .= '</td></tr>';
        }
        $view_tbl .= '</table><br/>';

        $allGrades = GetGrades($reg_file);
        $keyStr = "";
        $valStr = "";
        for ($i = 0; $i < count($allGrades) - 1; $i++) {
            if ($i == ((count($allGrades) - 1) - 1)) {
                $keyStr .= $allGrades[$i]["key"] . " = " . $allGrades[$i]["value"];
            } else {
                $keyStr .= $allGrades[$i]["key"] . " = " . $allGrades[$i]["value"] . ";&nbsp;&nbsp;";
            }
        }

        $view_tbl .= '<br/><center>
	<table align="center" cellspacing="0" cellpadding="5" width = "90%" style="font-size: 12px;margin: 0 auto;">
    <tr><td align="center" style="width: 580px; border: 1px #ddd solid;">';
        $view_tbl .= 'Grade Values: A+ = 10;  A = 9, B+ = 8, B = 7;  C+ = 6;  C = 5; D = 4;<br/>P = pass, but credits not counted towards GPA; I = incomplete, 0 credits; F = fail, 0 credits.';
        $view_tbl .= '</td></tr>
            </table>
        </center>
        <table width = "100%" align="center" cellpadding="3" cellspacing="0"><tr><td style="text-align:left" style="font-size: 12px;">
                </td></tr></table><br/><br/>';

        $total_credit_registered = 0;
        $total_credit_cleared = 0;
        $total_credit_gpa = 0;
        $total_total_mul = 0;
        $total_credit_cgpa = 0;
        $total_total_mul_cgpa = 0;
        for ($peri = $admission_period; $peri <= $period; $peri++) {
            $qry = "SELECT distinct a.sub_code, a.grade, b.sub_crdit, b.sub_title FROM $reg_file a, isr_curriculum_tbl b where b.sub_list = a.sub_list and a.sub_code = b.sub_code and a.sub_flag in ('Y','T') and a.stu_roll = '$stu_roll' and a.b1_sem = '$peri' order by a.sub_code";
              $ObjDB->sproc_name = $qry;
        $res_qry = $ObjDB->SelectQuery();
         

            $credit_registered[$peri] = 0;
            $credit_cleared[$peri] = 0;
            $credit_gpa[$peri] = 0;
            $total_mul[$peri] = 0;
            $total_mul_cgpa[$peri] = 0;

            while ($row = mysqli_fetch_array($res_qry)) {
                $sub_code = $row['sub_code'];
                $sub_credit = $row['sub_crdit'];
                $sub_title = $row['sub_title'];
                $grade = $row['grade'];

                if ($grade == "A+") {
                    $var = 10;
                }
                if ($grade == "A") {
                    $var = 9;
                }
                if ($grade == "B+") {
                    $var = 8;
                }
                if ($grade == "B") {
                    $var = 7;
                }
                if ($grade == "C+") {
                    $var = 6;
                }
                if ($grade == "C") {
                    $var = 5;
                }
                if ($grade == "D") {
                    $var = 4;
                }
                if ($grade == "F") {
                    $var = 0;
                }
                if ($grade == "I") {
                    $var = 0;
                }
                if ($grade == "P") {
                    $var = 0;
                }

                $mul_value = $sub_credit * $var;
                $credit_registered[$peri] = $credit_registered[$peri] + $sub_credit;
                if ($grade == "A+" or $grade == "A" or $grade == "B+" or $grade == "B" or $grade == "C+" or $grade == "C" or $grade == "D" or $grade == "P") {
                    $credit_cleared[$peri] = $credit_cleared[$peri] + $sub_credit;
                }
                if ($grade == "A+" or $grade == "A" or $grade == "B+" or $grade == "B" or $grade == "C+" or $grade == "C" or $grade == "D" or $grade == "F") {
                    $credit_gpa[$peri] = $credit_gpa[$peri] + $sub_credit;
                    $total_mul[$peri] = $total_mul[$peri] + $mul_value;
                }
                if ($grade == "A+" or $grade == "A" or $grade == "B+" or $grade == "B" or $grade == "C+" or $grade == "C" or $grade == "D" or $grade == "F") {
                    $credit_cgpa[$peri] = $credit_cgpa[$peri] + $sub_credit;
                    $total_mul_cgpa[$peri] = $total_mul_cgpa[$peri] + $mul_value;
                }
            }
            $gpa[$peri] = round(($total_mul[$peri] / $credit_gpa[$peri]), 1);

            $total_credit_registered = $total_credit_registered + $credit_registered[$peri];
            $total_credit_cleared = $total_credit_cleared + $credit_cleared[$peri];
            $total_credit_gpa = $total_credit_gpa + $credit_gpa[$peri];
            $total_total_mul = $total_total_mul + $total_mul[$peri];

            $total_credit_cgpa = $total_credit_cgpa + $credit_cgpa[$peri];
            $total_total_mul_cgpa = $total_total_mul_cgpa + $total_mul_cgpa[$peri];
        }
        $cgpa = round(($total_total_mul_cgpa / $total_credit_cgpa), 1);

        /* -------------------------------   

          $view_tbl .= '<center>
          <table align="center" cellspacing="0" cellpadding="2" width = "70%" style="font-size: 12px;margin: 0 auto;">
          <tr><td style="width: 80px;"></td>
          <td width="140" style="border: 1px #ddd solid;" align="left">Residence Semester</td>';
          for ($jj = 1; $jj <= $add_period; $jj++) {
          $view_tbl .= '<td width="40" style="border: 1px #ddd solid;">' . $jj . '</td>';
          }
          $view_tbl .= '<td width="80" style="border: 1px #ddd solid;">Cumulative</td>
          </tr>
          <tr><td style="width: 80px;"></td><td style="border: 1px #ddd solid;" align="left">Credits Registered for</td>';
          for ($jj = $admission_period; $jj <= $period; $jj++) {
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $credit_registered[$jj] . '</td>';
          }
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $total_credit_registered . '</td></tr>
          <tr><td style="width: 80px;"></td><td style="border: 1px #ddd solid;" align="left">Credits Completed</td>';
          for ($jj = $admission_period; $jj <= $period; $jj++) {
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $credit_cleared[$jj] . '</td>';
          }
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $total_credit_cleared . '</td></tr>
          <tr><td style="width: 80px;"></td><td style="border: 1px #ddd solid;" align="left">GPA</td>';
          for ($jj = $admission_period; $jj <= $period; $jj++) {
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $gpa[$jj] . '</td>';
          }
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $cgpa . '</td></tr>
          </table>
          </center>';

          ------------------------------------------- */

        $view_tbl .= '<center><table border="1" cellspacing="0" cellpadding="1" align="center" width="600" style="font-size: 12px;margin: 0 auto;">
<tr>
<td>&nbsp;&nbsp;Semester&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;Credits Registered&nbsp;</td>
<td>&nbsp;&nbsp;Credits Completed&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;GPA&nbsp;&nbsp;</td>
</tr>';

        for ($jj = $admission_period; $jj <= $period; $jj++) {
               $qsem = "select new_name from isr_iiser_sem_tbl where sem_num = '$jj'";
    $ObjDB->sproc_name = $qsem;
    $res_qsem = $ObjDB->SelectQuery();
    list($sem_name) = mysqli_fetch_row($res_qsem);
            $view_tbl .= '<tr>
	<td>&nbsp;&nbsp;&nbsp;' . $sem_name . '&nbsp;&nbsp;&nbsp;</td>
	<td>' . $credit_registered[$jj] . '</td>
	<td>' . $credit_cleared[$jj] . '</td>
	<td>' . number_format($gpa[$jj], 1) . '</td></tr>';
        }
        $view_tbl .= '<tr>
<td>Cumulative</td>
<td>' . $total_credit_registered . '</td>
<td>' . $total_credit_cleared . '</td>
<td>' . number_format($cgpa, 1) . '</td></tr>
</table></center>';

        $view_tbl .= '<br/><br/>
<table width = "600" align="center" cellpadding="0" cellspacing="0">
<tr>
	<td width="300">
	<br/><br/>Date of Approval: ' . $approval_date . '
	<br/><br/>Date of Download: ' . $issuedate . '
    
    </td>
    <td width="300" style="text-align:right"><br/><br/><br/>
    <img src="../image/new_dean3.jpg" border="0" alt="" width="120px;" HEIGHT="41" style="float:right;">
    </td>
</tr>
<tr><td colspan="2" width="600"><hr></td></tr>
<tr><td colspan="2" width="600">This is an electronically generated transcript.</td></tr>
</table></body></html>';
    } else {
        die("Chronological transcript is not available for this roll number.");
    }
} elseif (substr($batch, 0, 1) == 'r') {
    if ($batch == 'r11' or $batch == 'r12') {

        $queryb1 = "SELECT * FROM isr_iiser_sem_tbl where sem_num = '$admission_period'";
$ObjDB->sproc_name = $queryb1;
$res_queryb1 = $ObjDB->SelectQuery();
$rowb1 = mysqli_fetch_array($res_queryb1);
$admission_period_name = $rowb1["sem_name"];

$queryb1 = "SELECT * FROM isr_iiser_sem_tbl where sem_num = '$period'";
$ObjDB->sproc_name = $queryb1;
$res_queryb1 = $ObjDB->SelectQuery();
$rowb1 = mysqli_fetch_array($res_queryb1);
$trans_period_name = $rowb1["sem_name"];

$queryb1 = "SELECT * FROM isr_result_date_tbl where abs_sem = '$period' and batch = '$batch'";
$ObjDB->sproc_name = $queryb1;
$res_queryb1 = $ObjDB->SelectQuery();
$rowb1 = mysqli_fetch_array($res_queryb1);
$approval_date = $rowb1["approval_date"];

        $view_tbl .= '<html><body><style type="text/css">
                    body, html{
                        font-family: arial;
                        font-size: 12px;
                    }
                    td{
                        padding: 5px;
                    }
                </style>
            <center><IMG SRC="../image/MScTranscript_head_1_transparent.png" WIDTH="700" BORDER="0" ALT=""></center>
            <br/><br/>
            <table cellspacing="0" cellpadding="3" width = "100%" align="center">
                <tr><td width="130" align="left">Name of the student</td><td align="left"><b>' . strtoupper($stu_name) . '</b></td><td width="120" align="left">Joining Semester</td><td align="left">' . $admission_period_name . '</td></tr>
                <tr><td align="left">Roll Number</td><td align="left"><b>' . $stu_roll . '</b></td><td align="left">Residence Semester</td><td align="left">' . $residence_semester . '</td></tr>
            </table>
            <br/>
            <div align="center"><strong>Chronological Transcript: ' . $trans_period_name . '</strong></div><br/>
            <table cellspacing="0" cellpadding="3" align="center">
                <tr><td width="30" style="border: 1px #ddd solid;">&nbsp;</td><td style="border: 1px #ddd solid;" width="100" align="center">Course code</td>
                    <td width="350" style="border: 1px #ddd solid;" align="center">Course title</td><td style="border: 1px #ddd solid;" width="50" align="center">Credits</td>
                    <td style="border: 1px #ddd solid;" width="50" align="center">Grade</td></tr>';

        $query = "SELECT a.sub_code, a.grade, a.grade_flag, a.sub_flag, 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 in ('Y','T') and a.b1_sem = '$period' and a.stu_roll = '$stu_roll' and a.sub_code = b.sub_code order by b.sub_crdit desc, b.sub_code";
        $ObjDB->sproc_name = $query;
        $res_query = $ObjDB->SelectQuery();
    
        $j = 1;
        $add_3 = 0;
        while ($row = mysqli_fetch_array($res_query)) {
            $sub_code = $row["sub_code"];
            $grade2 = $row["grade"];
            $grade_flag = $row["grade_flag"];
            $sub_credit = $row["sub_crdit"];
            $sub_title = $row["sub_title"];
            if ($sub_code == 'HS1113') {
                if ($grade2 == 'P') {
                    $add_3 = 3;
                }
            }

            if ($sub_credit == 0) {
                $grade2 = "P";
            }

            $view_tbl .= '<tr><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $j++ . '</td><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $sub_code . '</td><td style="border: 1px #ddd solid;" align="left">&nbsp;' . $sub_title . '</td>
            <td style="border: 1px #ddd solid;" align="center">&nbsp;' . $sub_credit . '</td><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $grade2;
            if ($grade_flag == "R") {
                $view_tbl .= '<sub> R</sub>';
            }
            if ($grade_flag == "A") {
                $view_tbl .= '<sub> A</sub>';
            }
            $view_tbl .= '</td></tr>';
        }
        $view_tbl .= '</table><br/>';

        $allGrades = GetGrades($reg_file);
        $keyStr = "";
        $valStr = "";
        for ($i = 0; $i < count($allGrades) - 1; $i++) {
            if ($i == ((count($allGrades) - 1) - 1)) {
                $keyStr .= $allGrades[$i]["key"] . " = " . $allGrades[$i]["value"];
            } else {
                $keyStr .= $allGrades[$i]["key"] . " = " . $allGrades[$i]["value"] . ";&nbsp;&nbsp;";
            }
        }

        $view_tbl .= '<br/><center>
	<table align="center" cellspacing="0" cellpadding="5" width = "90%" style="font-size: 12px;margin: 0 auto;">
    <tr><td align="center" style="width: 580px; border: 1px #ddd solid;">';
        $view_tbl .= 'Grade Values: A+ = 10;  A = 9, B+ = 8, B = 7;  C+ = 6;  C = 5; D = 4;<br/>P = pass, but credits not counted towards GPA; I = incomplete, 0 credits; F = fail, 0 credits.';
        $view_tbl .= '</td></tr>
            </table>
        </center>
        <br/><br/>
        <table width = "100%" align="center" cellpadding="3" cellspacing="0"><tr><td style="text-align:left" style="font-size: 12px;">
                </td></tr></table>';

        $total_credit_registered = 0;
        $total_credit_cleared = 0;
        $total_credit_gpa = 0;
        $total_total_mul = 0;
        $total_credit_cgpa = 0;
        $total_total_mul_cgpa = 0;
        for ($peri = $admission_period; $peri <= $period; $peri++) {
            $qry = "SELECT distinct a.sub_code, a.grade, b.sub_crdit, b.sub_title FROM $reg_file a, isr_curriculum_tbl b where b.sub_list = a.sub_list and a.sub_code = b.sub_code and a.sub_flag in ('Y','T') and a.stu_roll = '$stu_roll' and a.b1_sem = '$peri' order by a.sub_code";
             $ObjDB->sproc_name = $query;
        $res_query = $ObjDB->SelectQuery();

            $credit_registered[$peri] = 0;
            $credit_cleared[$peri] = 0;
            $credit_gpa[$peri] = 0;
            $total_mul[$peri] = 0;
            $total_mul_cgpa[$peri] = 0;

            while ($row = mysqli_fetch_array($res_query)) {
                $sub_code = $row['sub_code'];
                $sub_credit = $row['sub_crdit'];
                $sub_title = $row['sub_title'];
                $grade = $row['grade'];

                if ($grade == "A+") {
                    $var = 10;
                }
                if ($grade == "A") {
                    $var = 9;
                }
                if ($grade == "B+") {
                    $var = 8;
                }
                if ($grade == "B") {
                    $var = 7;
                }
                if ($grade == "C+") {
                    $var = 6;
                }
                if ($grade == "C") {
                    $var = 5;
                }
                if ($grade == "D") {
                    $var = 4;
                }
                if ($grade == "F") {
                    $var = 0;
                }
                if ($grade == "I") {
                    $var = 0;
                }
                if ($grade == "P") {
                    $var = 0;
                }

                $mul_value = $sub_credit * $var;
                $credit_registered[$peri] = $credit_registered[$peri] + $sub_credit;
                if ($grade == "A+" or $grade == "A" or $grade == "B+" or $grade == "B" or $grade == "C+" or $grade == "C" or $grade == "D" or $grade == "P") {
                    $credit_cleared[$peri] = $credit_cleared[$peri] + $sub_credit;
                }
                if ($grade == "A+" or $grade == "A" or $grade == "B+" or $grade == "B" or $grade == "C+" or $grade == "C" or $grade == "D" or $grade == "F" or $grade == "I") {
                    $credit_gpa[$peri] = $credit_gpa[$peri] + $sub_credit;
                    $total_mul[$peri] = $total_mul[$peri] + $mul_value;
                }
                if ($grade == "A+" or $grade == "A" or $grade == "B+" or $grade == "B" or $grade == "C+" or $grade == "C" or $grade == "D") {
                    $credit_cgpa[$peri] = $credit_cgpa[$peri] + $sub_credit;
                    $total_mul_cgpa[$peri] = $total_mul_cgpa[$peri] + $mul_value;
                }
            }
            $gpa[$peri] = round(($total_mul[$peri] / $credit_gpa[$peri]), 1);

            $total_credit_registered = $total_credit_registered + $credit_registered[$peri];
            $total_credit_cleared = $total_credit_cleared + $credit_cleared[$peri];
            $total_credit_gpa = $total_credit_gpa + $credit_gpa[$peri];
            $total_total_mul = $total_total_mul + $total_mul[$peri];

            $total_credit_cgpa = $total_credit_cgpa + $credit_cgpa[$peri];
            $total_total_mul_cgpa = $total_total_mul_cgpa + $total_mul_cgpa[$peri];
        }
        $cgpa = round(($total_total_mul_cgpa / $total_credit_cgpa), 1);

        /* -------------------------------   

          $view_tbl .= '<center>
          <table align="center" cellspacing="0" cellpadding="2" width = "70%" style="font-size: 12px;margin: 0 auto;">
          <tr><td style="width: 80px;"></td>
          <td width="140" style="border: 1px #ddd solid;" align="left">Residence Semester</td>';
          for ($jj = 1; $jj <= $add_period; $jj++) {
          $view_tbl .= '<td width="40" style="border: 1px #ddd solid;">' . $jj . '</td>';
          }
          $view_tbl .= '<td width="80" style="border: 1px #ddd solid;">Cumulative</td>
          </tr>
          <tr><td style="width: 80px;"></td><td style="border: 1px #ddd solid;" align="left">Credits Registered for</td>';
          for ($jj = $admission_period; $jj <= $period; $jj++) {
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $credit_registered[$jj] . '</td>';
          }
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $total_credit_registered . '</td></tr>
          <tr><td style="width: 80px;"></td><td style="border: 1px #ddd solid;" align="left">Credits Completed</td>';
          for ($jj = $admission_period; $jj <= $period; $jj++) {
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $credit_cleared[$jj] . '</td>';
          }
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $total_credit_cleared . '</td></tr>
          <tr><td style="width: 80px;"></td><td style="border: 1px #ddd solid;" align="left">GPA</td>';
          for ($jj = $admission_period; $jj <= $period; $jj++) {
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $gpa[$jj] . '</td>';
          }
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $cgpa . '</td></tr>
          </table>
          </center>';

          ------------------------------------------- */

        $view_tbl .= '<center><table border="1" cellspacing="0" cellpadding="1" align="center" width="600" style="font-size: 12px;margin: 0 auto;">
<tr>
<td>&nbsp;&nbsp;Semester&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;Credits Registered&nbsp;</td>
<td>&nbsp;&nbsp;Credits Completed&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;GPA&nbsp;&nbsp;</td>
</tr>';

        for ($jj = $admission_period; $jj <= $period; $jj++) {
            $qsem = "select new_name from isr_iiser_sem_tbl where sem_num = '$jj'";
              $ObjDB->sproc_name = $qsem;
    $res_qsem = $ObjDB->SelectQuery();
    list($sem_name) = mysqli_fetch_row($res_qsem);

            $view_tbl .= '<tr>
	<td>&nbsp;&nbsp;&nbsp;' . $sem_name . '&nbsp;&nbsp;&nbsp;</td>
	<td>' . $credit_registered[$jj] . '</td>
	<td>' . $credit_cleared[$jj] . '</td>
	<td>' . number_format($gpa[$jj], 1) . '</td></tr>';
        }
        $view_tbl .= '<tr>
<td>Cumulative</td>
<td>' . $total_credit_registered . '</td>
<td>' . $total_credit_cleared . '</td>
<td>' . number_format($cgpa, 1) . '</td></tr>
</table></center>';

        $view_tbl .= '<br/><br/>
<table width = "600" align="center" cellpadding="0" cellspacing="0">
<tr>
	<td width="300">
	<br/><br/>Date of Approval: ' . $approval_date . '
	<br/><br/>Date of Download: ' . $issuedate . '
    
    </td>
    <td width="300" style="text-align:right"><br/><br/><br/>
    <img src="../image/new_dean3.jpg" border="0" alt="" width="120px;" HEIGHT="41" style="float:right;">
    </td>
</tr>
<tr><td colspan="2" width="600"><hr></td></tr>
<tr><td colspan="2" width="600">This is an electronically generated transcript.</td></tr>
</table></body></html>';
    } else {
        die("Chronological transcript is not available for this roll number.");
    }
} elseif (substr($batch, 0, 1) == 'm') {
    if ($batch == 'm1') {

     $queryb1 = "SELECT * FROM isr_iiser_sem_tbl where sem_num = '$admission_period'";
$ObjDB->sproc_name = $queryb1;
$res_queryb1 = $ObjDB->SelectQuery();
$rowb1 = mysqli_fetch_array($res_queryb1);
$admission_period_name = $rowb1["sem_name"];

$queryb1 = "SELECT * FROM isr_iiser_sem_tbl where sem_num = '$period'";
$ObjDB->sproc_name = $queryb1;
$res_queryb1 = $ObjDB->SelectQuery();
$rowb1 = mysqli_fetch_array($res_queryb1);
$trans_period_name = $rowb1["sem_name"];

$queryb1 = "SELECT * FROM isr_result_date_tbl where abs_sem = '$period' and batch = '$batch'";
$ObjDB->sproc_name = $queryb1;
$res_queryb1 = $ObjDB->SelectQuery();
$rowb1 = mysqli_fetch_array($res_queryb1);
$approval_date = $rowb1["approval_date"];

        $view_tbl .= '<html><body><style type="text/css">
                    body, html{
                        font-family: arial;
                        font-size: 12px;
                    }
                    td{
                        padding: 5px;
                    }
                </style>
				<CENTER><IMG SRC="../image/MScTranscript_head_1_transparent.png" WIDTH="700" BORDER="0" ALT=""></CENTER>
            <br/><br/>
            <table cellspacing="0" cellpadding="3" width = "100%" align="center">
                <tr><td width="130" align="left">Name of the student</td><td align="left"><b>' . strtoupper($stu_name) . '</b></td><td width="120" align="left">Joining Semester</td><td align="left">' . $admission_period_name . '</td></tr>
                <tr><td align="left">Roll Number</td><td align="left"><b>' . $stu_roll . '</b></td><td align="left">Residence Semester</td><td align="left">' . $residence_semester . '</td></tr>
            </table>
            <br/>
            <div align="center"><strong>Chronological Transcript: ' . $trans_period_name . '</strong></div><br/>
            <table cellspacing="0" cellpadding="3" align="center">
                <tr><td width="30" style="border: 1px #ddd solid;">&nbsp;</td><td style="border: 1px #ddd solid;" width="100" align="center">Course code</td>
                    <td width="350" style="border: 1px #ddd solid;" align="center">Course title</td><td style="border: 1px #ddd solid;" width="50" align="center">Credits</td>
                    <td style="border: 1px #ddd solid;" width="50" align="center">Grade</td></tr>';

        $query = "SELECT a.sub_code, a.grade, a.grade_flag, a.sub_flag, 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 in ('Y','T') and a.b1_sem = '$period' and a.stu_roll = '$stu_roll' and a.sub_code = b.sub_code order by b.sub_crdit desc, b.sub_code";
        $ObjDB->sproc_name = $query;
    $res_query = $ObjDB->SelectQuery();
        
        
        $j = 1;
        $add_3 = 0;
        while ($row = mysqli_fetch_array($res_query)) {
            $sub_code = $row["sub_code"];
            $grade2 = $row["grade"];
            $grade_flag = $row["grade_flag"];
            $sub_credit = $row["sub_crdit"];
            $sub_title = $row["sub_title"];
            if ($sub_code == 'HS1113') {
                if ($grade2 == 'P') {
                    $add_3 = 3;
                }
            }

            if ($sub_credit == 0) {
                $grade2 = "P";
            }

            $view_tbl .= '<tr><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $j++ . '</td><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $sub_code . '</td><td style="border: 1px #ddd solid;" align="left">&nbsp;' . $sub_title . '</td>
            <td style="border: 1px #ddd solid;" align="center">&nbsp;' . $sub_credit . '</td><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $grade2;
            if ($grade_flag == "R") {
                $view_tbl .= '<sub> R</sub>';
            }
            if ($grade_flag == "A") {
                $view_tbl .= '<sub> A</sub>';
            }
            $view_tbl .= '</td></tr>';
        }
        $view_tbl .= '</table><br/>';

        $allGrades = GetGrades($reg_file);
        $keyStr = "";
        $valStr = "";
        for ($i = 0; $i < count($allGrades) - 1; $i++) {
            if ($i == ((count($allGrades) - 1) - 1)) {
                $keyStr .= $allGrades[$i]["key"] . " = " . $allGrades[$i]["value"];
            } else {
                $keyStr .= $allGrades[$i]["key"] . " = " . $allGrades[$i]["value"] . ";&nbsp;&nbsp;";
            }
        }

        $view_tbl .= '<br/><center>
	<table align="center" cellspacing="0" cellpadding="5" width = "90%" style="font-size: 12px;margin: 0 auto;">
    <tr><td align="center" style="width: 580px; border: 1px #ddd solid;">';
        $view_tbl .= 'Grade Values: A+ = 10;  A = 9, B+ = 8, B = 7;  C+ = 6;  C = 5; D = 4;<br/>P = pass, but credits not counted towards GPA; I = incomplete, 0 credits; F = fail, 0 credits.';
        $view_tbl .= '</td></tr>
            </table>
        </center>
        <br/><br/>
        <table width = "100%" align="center" cellpadding="3" cellspacing="0"><tr><td style="text-align:left" style="font-size: 12px;">
                </td></tr></table>';

        $total_credit_registered = 0;
        $total_credit_cleared = 0;
        $total_credit_gpa = 0;
        $total_total_mul = 0;
        $total_credit_cgpa = 0;
        $total_total_mul_cgpa = 0;
        for ($peri = $admission_period; $peri <= $period; $peri++) {
            $qry = "SELECT distinct a.sub_code, a.grade, b.sub_crdit, b.sub_title FROM $reg_file a, isr_curriculum_tbl b where b.sub_list = a.sub_list and a.sub_code = b.sub_code and a.sub_flag in ('Y','T') and a.stu_roll = '$stu_roll' and a.b1_sem = '$peri' order by a.sub_code";
            $ObjDB->sproc_name = $qry;
            $res_qry = $ObjDB->SelectQuery();

            $credit_registered[$peri] = 0;
            $credit_cleared[$peri] = 0;
            $credit_gpa[$peri] = 0;
            $total_mul[$peri] = 0;
            $total_mul_cgpa[$peri] = 0;

            while ($row = mysqli_fetch_array($res_qry)) {
                $sub_code = $row['sub_code'];
                $sub_credit = $row['sub_crdit'];
                $sub_title = $row['sub_title'];
                $grade = $row['grade'];

                if ($grade == "A+") {
                    $var = 10;
                }
                if ($grade == "A") {
                    $var = 9;
                }
                if ($grade == "B+") {
                    $var = 8;
                }
                if ($grade == "B") {
                    $var = 7;
                }
                if ($grade == "C+") {
                    $var = 6;
                }
                if ($grade == "C") {
                    $var = 5;
                }
                if ($grade == "D") {
                    $var = 4;
                }
                if ($grade == "F") {
                    $var = 0;
                }
                if ($grade == "I") {
                    $var = 0;
                }
                if ($grade == "P") {
                    $var = 0;
                }

                $mul_value = $sub_credit * $var;
                $credit_registered[$peri] = $credit_registered[$peri] + $sub_credit;
                if ($grade == "A+" or $grade == "A" or $grade == "B+" or $grade == "B" or $grade == "C+" or $grade == "C" or $grade == "D" or $grade == "P") {
                    $credit_cleared[$peri] = $credit_cleared[$peri] + $sub_credit;
                }
                if ($grade == "A+" or $grade == "A" or $grade == "B+" or $grade == "B" or $grade == "C+" or $grade == "C" or $grade == "D" or $grade == "F" or $grade == "I") {
                    $credit_gpa[$peri] = $credit_gpa[$peri] + $sub_credit;
                    $total_mul[$peri] = $total_mul[$peri] + $mul_value;
                }
                if ($grade == "A+" or $grade == "A" or $grade == "B+" or $grade == "B" or $grade == "C+" or $grade == "C" or $grade == "D") {
                    $credit_cgpa[$peri] = $credit_cgpa[$peri] + $sub_credit;
                    $total_mul_cgpa[$peri] = $total_mul_cgpa[$peri] + $mul_value;
                }
            }
            $gpa[$peri] = round(($total_mul[$peri] / $credit_gpa[$peri]), 1);

            $total_credit_registered = $total_credit_registered + $credit_registered[$peri];
            $total_credit_cleared = $total_credit_cleared + $credit_cleared[$peri];
            $total_credit_gpa = $total_credit_gpa + $credit_gpa[$peri];
            $total_total_mul = $total_total_mul + $total_mul[$peri];

            $total_credit_cgpa = $total_credit_cgpa + $credit_cgpa[$peri];
            $total_total_mul_cgpa = $total_total_mul_cgpa + $total_mul_cgpa[$peri];
        }
        $cgpa = round(($total_total_mul_cgpa / $total_credit_cgpa), 1);

        /* -------------------------------   

          $view_tbl .= '<center>
          <table align="center" cellspacing="0" cellpadding="2" width = "70%" style="font-size: 12px;margin: 0 auto;">
          <tr><td style="width: 80px;"></td>
          <td width="140" style="border: 1px #ddd solid;" align="left">Residence Semester</td>';
          for ($jj = 1; $jj <= $add_period; $jj++) {
          $view_tbl .= '<td width="40" style="border: 1px #ddd solid;">' . $jj . '</td>';
          }
          $view_tbl .= '<td width="80" style="border: 1px #ddd solid;">Cumulative</td>
          </tr>
          <tr><td style="width: 80px;"></td><td style="border: 1px #ddd solid;" align="left">Credits Registered for</td>';
          for ($jj = $admission_period; $jj <= $period; $jj++) {
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $credit_registered[$jj] . '</td>';
          }
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $total_credit_registered . '</td></tr>
          <tr><td style="width: 80px;"></td><td style="border: 1px #ddd solid;" align="left">Credits Completed</td>';
          for ($jj = $admission_period; $jj <= $period; $jj++) {
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $credit_cleared[$jj] . '</td>';
          }
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $total_credit_cleared . '</td></tr>
          <tr><td style="width: 80px;"></td><td style="border: 1px #ddd solid;" align="left">GPA</td>';
          for ($jj = $admission_period; $jj <= $period; $jj++) {
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $gpa[$jj] . '</td>';
          }
          $view_tbl .= '<td style="border: 1px #ddd solid;">' . $cgpa . '</td></tr>
          </table>
          </center>';

          ------------------------------------------- */

        $view_tbl .= '<center><table border="1" cellspacing="0" cellpadding="1" align="center" width="600" style="font-size: 12px;margin: 0 auto;">
<tr>
<td>&nbsp;&nbsp;Semester&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;Credits Registered&nbsp;</td>
<td>&nbsp;&nbsp;Credits Completed&nbsp;&nbsp;</td>
<td>&nbsp;&nbsp;GPA&nbsp;&nbsp;</td>
</tr>';

        for ($jj = $admission_period; $jj <= $period; $jj++) {
            $qsem = "select new_name from isr_iiser_sem_tbl where sem_num = '$jj'";
                $ObjDB->sproc_name = $qsem;
    $res_qsem = $ObjDB->SelectQuery();
    list($sem_name) = mysqli_fetch_row($res_qsem);

            $view_tbl .= '<tr>
	<td>&nbsp;&nbsp;&nbsp;' . $sem_name . '&nbsp;&nbsp;&nbsp;</td>
	<td>' . $credit_registered[$jj] . '</td>
	<td>' . $credit_cleared[$jj] . '</td>
	<td>' . number_format($gpa[$jj], 1) . '</td></tr>';
        }
        $view_tbl .= '<tr>
<td>Cumulative</td>
<td>' . $total_credit_registered . '</td>
<td>' . $total_credit_cleared . '</td>
<td>' . number_format($cgpa, 1) . '</td></tr>
</table></center>';

        $view_tbl .= '<br/><br/>
<table width = "600" align="center" cellpadding="0" cellspacing="0">
<tr>
	<td width="300">
	<br/><br/>Date of Approval: ' . $approval_date . '
	<br/><br/>Date of Download: ' . $issuedate . '
    
    </td>
    <td width="300" style="text-align:right"><br/><br/><br/>
    <img src="../image/new_dean3.jpg" border="0" alt="" width="120px;" HEIGHT="41"  style="float:right;">
    </td>
</tr>
<tr><td colspan="2" width="600"><hr></td></tr>
<tr><td colspan="2" width="600">This is an electronically generated transcript.</td></tr>
</table></body></html>';
    } else {
        die("Chronological transcript is not available for this roll number.");
    }
} else {
    die("Chronological transcript is not available for this roll number.");
//    include ("sem_IPHD.php");
    if ($sem_now == 1) {
        $sem_title = "I";
    }
    if ($sem_now == 2) {
        $sem_title = "II";
    }
    if ($sem_now == 3) {
        $sem_title = "III";
    }
    if ($sem_now == 4) {
        $sem_title = "IV";
    }

    if ($sem_now > 4) {
        die("Transcript only upto Semester 4 for Integrated Ph.D. students");
    }

    $this_sem = $sem_now + 10;

    $view_tbl .= '<html><body><style type="text/css">
            body, html{
                font-family: arial;
                font-size: 12px;
            }
            td{
                padding: 5px;
            }
        </style>
<CENTER><IMG SRC="../image/MScTranscript_head_1_transparent.png" WIDTH="700" BORDER="0" ALT=""></CENTER>
        <br/><br/>
        <table cellspacing="0" cellpadding="3" width = "100%" align="center">
            <tr><td width="130" align="left">Name of the student</td><td align="left"><b>' . strtoupper($stu_name) . '</b></td><td width="120" align="left">Year of Joining</td><td align="left">' . substr($stu_roll, 0, 4) . '</td></tr>
            <tr><td align="left">Roll Number</td><td align="left"><b>' . $stu_roll . '</b></td><td align="left">Year of completion</td><td align="left">' . $complition_year . '</td></tr>
        </table>
        <br/>
        <div align="center"><strong>(Semester: ' . $sem_now . ', ' . $exam_year . ')</strong></div><br/>
            <table cellspacing="0" cellpadding="3" align="center">
           <tr><td width="30" style="border: 1px #ddd solid;">&nbsp;</td><td style="border: 1px #ddd solid;" width="100" align="center">Course code</td>
            <td width="350" style="border: 1px #ddd solid;" align="center">Course title</td><td style="border: 1px #ddd solid;" width="50" align="center">Credits</td>
            <td style="border: 1px #ddd solid;" width="50" align="center">Grade</td></tr>';

    $query = "SELECT a.sub_code, a.grade, a.grade_flag, a.sub_flag, 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 = '$this_sem' and a.stu_roll = '$stu_roll' and a.sub_code = b.sub_code order by b.sub_crdit desc, b.sub_code";
     $ObjDB->sproc_name = $query;
    $res_query = $ObjDB->SelectQuery();
    
    $j = 1;
    while ($row = mysqli_fetch_array($res_query)) {
        $sub_code = $row["sub_code"];
        $grade2 = $row["grade"];
        $grade_flag = $row["grade_flag"];
        $sub_credit = $row["sub_crdit"];
        $sub_title = $row["sub_title"];
        if ($sub_credit == 0) {
            $grade2 = "P";
        }

        $view_tbl .= '<tr><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $j++ . '</td><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $sub_code . '</td><td style="border: 1px #ddd solid;" align="left">&nbsp;' . $sub_title . '</td>
            <td style="border: 1px #ddd solid;" align="center">&nbsp;' . $sub_credit . '</td><td style="border: 1px #ddd solid;" align="center">&nbsp;' . $grade2;
        if ($grade_flag == "R") {
            $view_tbl .= '<sub> R</sub>';
        }
        $view_tbl .= '</td></tr>';
    }
    $view_tbl .= '</table><br/><br/>';

    $allGrades = GetGrades($reg_file);
    $keyStr = "";
    $valStr = "";
    for ($i = 0; $i < count($allGrades) - 2; $i++) {
        if ($i == ((count($allGrades) - 2) - 1)) {
            $keyStr .= $allGrades[$i]["key"] . " = " . $allGrades[$i]["value"];
        } else {
            $keyStr .= $allGrades[$i]["key"] . " = " . $allGrades[$i]["value"] . ";&nbsp;&nbsp;";
        }
    }
    $view_tbl .= '<br/>
            <center>
         <table align="center" cellspacing="0" cellpadding="5" width = "70%" style="font-size: 12px;margin: 0 auto;">
            <tr><td style="width: 100px;"></td><td align="center" style="width: 400px; border: 1px #ddd solid;">Grade Values:&nbsp;' . $keyStr . '</td></tr>
        </table>
        </center>
        <br/><br/>
        <table width = "100%" align="center" cellpadding="3" cellspacing="0"><tr><td style="text-align:left" style="font-size: 12px;">
                    <ol style="font-family:arial; font-size:12px;">';
    if ($batch == 'b1' or $batch == 'b2' or $batch == 'b3' or $batch == 'b4' or $batch == 't1' or $batch == 't2') {
        $view_tbl .= '<li>Grades: A, B, C & D are passing grades, while F indicates failure of the course. Grade I signifies incomplete course work, which will be replaced by actual grade after completion of the same.  Credit is earned by P but not included in the calculation of Grade Point Average (GPA).</li>';
    } else {
        $view_tbl .= '<li>Grades: O, A, B, C & D are passing grades, while F indicates failure of the course. Grade I signifies incomplete course work, which will be replaced by actual grade after completion of the same.  Credit is earned by P but not included in the calculation of Grade Point Average (GPA).</li>';
    }

    $view_tbl .= '<li>GPA: calculated by dividing grade points by credits, on a ten point scale.</li>
                    <li>Suffix R indicates repeated course.</li>
                </ol>
            </td></tr></table><br/><br/>
            <table cellspacing="0" cellpadding="1" align="center">
            <tr><td style="width: 150px;">&nbsp;</td>
                <td width="60" style="border: 1px #ddd solid;">Semester</td>
                <td width="25" style="border: 1px #ddd solid;">I</td>
                <td width="25" style="border: 1px #ddd solid;">II</td>
                <td width="25" style="border: 1px #ddd solid;">III</td>
                <td width="25" style="border: 1px #ddd solid;">IV</td>
                <td width="70" style="border: 1px #ddd solid;">Cumulative</td>
            </tr>';

    $total_credits = 0;
    $total_credits_value = 0;
    $view_tbl .= '<tr><td style="width: 150px;">&nbsp;</td><td style="border: 1px #ddd solid;">Credits</td>';
    for ($sem = 11; $sem < 15; $sem++) {
        if ($sem <= $this_sem) {
            $sum_credit[$sem] = 0;
            $sum_credit_value[$sem] = 0;
            $query1 = "SELECT distinct a.sub_code, 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.sem = '$sem' and a.sub_code = b.sub_code order by b.sub_crdit desc, b.sub_code";
             $ObjDB->sproc_name = $query1;
             $res_query1 = $ObjDB->SelectQuery();
            $numberofrows = mysqli_num_rows($res_query1);
            for ($i = 0; $i < $numberofrows; $i++) {
                $row1 = mysqli_fetch_array($res_query1);
                $sub_code1[$i] = $row1["sub_code"];
                $xxx[$i] = $row1["sub_crdit"];
            }
            for ($i = 0; $i < $numberofrows; $i++) {
                $query3 = "SELECT grade FROM $reg_file where $reg_file.sem = '$sem' and  sub_code = '$sub_code1[$i]' and stu_roll = '$stu_roll' AND $reg_file.sub_flag = 'Y'";
                $res_query3 = $ObjDB->SelectQuery();
                $numberofrows = mysqli_num_rows($res_query3);
            
                $row3 = mysql_fetch_array($res_query3);
                $grade = $row3["grade"];
                if ($grade != '') {
                    $sum_credit[$sem] = $sum_credit[$sem] + $xxx[$i];
                    $grade_value = GetGradeValue($reg_file, $grade);
                    $credit_value = $grade_value * $xxx[$i];
                    $sum_credit_value[$sem] = $sum_credit_value[$sem] + $credit_value;
                }
            }
        }
        if ($sem == 9 || $sem == 10) {
            
        } else if ($sum_credit[$sem] != 0)
            $view_tbl .= '<td style="border: 1px #ddd solid;">&nbsp;' . $sum_credit[$sem] . '</td>';
        else
            $view_tbl .= '<td style="border: 1px #ddd solid;"> -- </td>';
        $total_credits = $total_credits + $sum_credit[$sem];
        $total_credits_value = $total_credits_value + $sum_credit_value[$sem];
    }
    $view_tbl .= '<td style="border: 1px #ddd solid;">' . $total_credits . '</td></tr>';

    $total_credits = 0;
    $total_credits_value = 0;
    $view_tbl .= '<tr><td style="width: 150px;">&nbsp;</td><td style="border: 1px #ddd solid;">GPA</td>';
    for ($sem = 11; $sem < 15; $sem++) {
        if ($sem <= $sem_now) {
            $sum_credit[$sem] = 0;
            $sum_credit_value[$sem] = 0;
            $query1 = "SELECT distinct a.sub_code, 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.sem = '$sem' and a.sub_code = b.sub_code order by b.sub_crdit desc, b.sub_code";
            $ObjDB->sproc_name = $query1;
            $res_query1 = $ObjDB->SelectQuery();
            $numberofrows = mysqli_num_rows($res_query1);
            
            for ($i = 0; $i < $numberofrows; $i++) {
                $row1 = mysqli_fetch_array($res_query1);
                $sub_code1[$i] = $row1["sub_code"];
                $sub_credit[$i] = $row1["sub_crdit"];
            }
            for ($i = 0; $i < $numberofrows; $i++) {
                $query3 = "SELECT grade FROM $reg_file where $reg_file.sem = '$sem' and  sub_code = '$sub_code1[$i]' and stu_roll = '$stu_roll' AND $reg_file.sub_flag = 'Y'";
                $ObjDB->sproc_name = $query3;
                $res_query3 = $ObjDB->SelectQuery();
            
                $row3 = mysqli_fetch_array($res_query3);
                $grade = $row3["grade"];
                if ($grade != '') {
                    $sum_credit[$sem] = $sum_credit[$sem] + $sub_credit[$i];
                    $grade_value = GetGradeValue($reg_file, $grade);
                    $credit_value = $grade_value * $sub_credit[$i];
                    $sum_credit_value[$sem] = $sum_credit_value[$sem] + $credit_value;
                }
            }
        }
        if ($sem == 9 || $sem == 10) {
            
        } else if ($sum_credit[$sem] != 0)
            $view_tbl .= '<td style="border: 1px #ddd solid;">' . round($sum_credit_value[$sem] / $sum_credit[$sem], 1) . '</td>';
        else
            $view_tbl .= '<td style="border: 1px #ddd solid;"> -- </td>';
        $total_credits = $total_credits + $sum_credit[$sem];
        $total_credits_value = $total_credits_value + $sum_credit_value[$sem];
    }
    if ($total_credits != 0)
        $view_tbl .= '<td style="border: 1px #ddd solid;">' . round($total_credits_value / $total_credits, 1) . '</td>';
    else
        $view_tbl .= '<td style="border: 1px #ddd solid;"> --</td>';
    $view_tbl .= '</tr></table></center>
    <table width = "600" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td width="300"><BR><BR><BR>
                <img src="../image/IISER_RoundStamp5.jpg" border="0" alt="" width="150px;">
                </td>
                <td width="300" style="text-align:right"><BR><BR><BR><BR><BR><BR>
                <img src="../image/new_dean3.jpg" border="0" alt="" width="120px;" HEIGHT="41"  style="float:right;">
                </td>
            </tr>
            </table></body></html>';
}

$pdf->writeHTML($view_tbl, true, false, true, false, '');
//$pdf->Output();
$pdf->Output($file_name, 'D');
exit();
?>