<?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 == 5) {
    $sem_title = "V";
}
if ($sem_now == 6) {
    $sem_title = "VI";
}
if ($sem_now == 7) {
    $sem_title = "VII";
}
if ($sem_now == 8) {
    $sem_title = "VIII";
}
if ($sem_now == 9) {
    $sem_title = "IX";
}
if ($sem_now == 10) {
    $sem_title = "X";
}
?>
<title>IISER Pune: Semester <?php echo $sem_title; ?> Transcript of <?php echo $stu_name; ?>(<?php echo $stu_roll; ?>)</title>




<CENTER><IMG SRC="../image/Transcript_head_1_transparent.png" WIDTH="700" BORDER="0" ALT=""></CENTER>
<BR><BR>



<!-- Student Ref Start  -->
<table border=0 cellspacing=0 cellpadding=1 align=center width=600 class=noborder>
    <tr><td class=noborder width=130>Name of the student<td 270><B><?php echo strtoupper($stu_name); ?></B><td width=120>Year of Joining<td><?php echo substr($stu_roll, 0, 4); ?>
    <tr><td class=noborder>Roll Number<td><B><?php echo $stu_roll; ?></B><td>Year of completion<td><?php echo $complition_year; ?>
</table>
<!-- Student Ref Ends  -->

<CENTER>(Semester: <?php echo $sem_now; ?>, <?php echo $exam_year; ?>)</CENTER><BR>

<BR>
<table align=center cellspacing=0 cellpadding=0 border = 0 width=600 class=this>
    <tr><td class=this>&nbsp;<td class=this>Course code<td class=this>Course title<td class=this>Credits<td class=this>Grade</tr>
    <?php
    $query = "SELECT a.sub_code, a.grade, a.grade_flag, a.sub_flag, b.sub_title,  b.sub_crdit from $reg_file a, curr b where b.sub_list  = a.sub_list and a.sub_flag in ('Y','T') and a.sem = '$sem_now' and a.stu_roll = '$stu_roll' and a.sub_code = b.sub_code order by a.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($batch == 'b1' or $batch == 'b2' or $batch == 'b3' or $batch == 'b4' or $batch == 't1' or $batch == 't2') {
          $sub_title = $row["sub_title_old"];
          }
          if($batch == 'b7') {
          $sub_title = $row["sub_title_new"];
          }
         */
        if ($sub_credit == 0) {
            $grade2 = "P";
        }
        echo "<TR><TD width=20 class=this>&nbsp;" . $j++;
        echo "<TD width=80 class=this>&nbsp;" . $sub_code;
        echo "<TD width=400 class=this2>&nbsp;" . $sub_title;
        echo "<TD width=50 class=this>&nbsp;" . $sub_credit;
        echo "<TD width=50 class=this>&nbsp;" . $grade2;
        if ($grade_flag == "R") {
            echo "<sub> R</sub>";
        }
        if ($grade_flag == "A") {
            echo "<sub> A</sub>";
        }
    }
    echo "</table>";
    ?>
                    <?php
                    $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;";
                        }
                    }
                    ?>
    <BR>
    <table border=0 align=center cellspacing=0 cellpadding=2 class=this width=450>
        <tr><td align=center class=this2>Grade Values:&nbsp;<? echo $keyStr ?></td></tr>
    </table>


    <BR>
    <TABLE width=600 align=center cellpadding=0 cellspacing=0 class=noborder><tr><td  class=noborder style="text-align:left">
                <ol style="font-family:arial; font-size:12px; ">

<?php if ($batch == 'b1' or $batch == 'b2' or $batch == 'b3' or $batch == 'b4' or $batch == 't1' or $batch == 't2') { ?>
                        <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).
<?php } else if ($batch == 'b13') { ?>
                        <li>Grades: A+, A, B+, B, C+, 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).

<?php } else { ?>
                        <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).
        <?php } ?>

                    <li>GPA: calculated by dividing grade points by credits, on a ten point scale.
                    <li>Suffix R indicates repeated course.  Suffix A indicates low attendance in class.
                </ol>
            </td></tr></table>

    <table border=0 cellspacing=0 cellpadding=1 align=center class=this>
        <tr><td width=60 class=this>Semester</td>
            <td width=25 class=this>I</td>
            <td width=25 class=this>II</td>
            <td width=25 class=this>III</td>
            <td width=25 class=this>IV</td>
            <td width=25 class=this>V</td>
            <td width=25 class=this>VI</td>
            <td width=25 class=this>VII</td>
            <td width=25 class=this>VIII</td>
            <!--<td width=25>IX</td>
            <td width=25>X</td>-->
            <td width=70 class=this>Cumulative</td>
        </tr>

        <?php
        $total_credits = 0;
        $total_credits_value = 0;
        echo "<TR><TD class=this>Credits</TD>";
        for ($sem = 1; $sem < 11; $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 in ('Y') and a.stu_roll = '$stu_roll' and a.sem = '$sem' and a.sub_code = b.sub_code order by a.sub_code";
                $ObjDB->sproc_name = $query1;
                $res_query1 = $ObjDB->SelectQuery();

                $numberofrows = mysqli_num_rows($res_query1);
//		echo $sem."=".$numberofrows;
                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 in ('Y','T')";
                    $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)
                echo "<TD class=this>&nbsp;" . $sum_credit[$sem] . "</TD>";
            else
                echo "<TD class=this> -- </TD>";
            $total_credits = $total_credits + $sum_credit[$sem];
            $total_credits_value = $total_credits_value + $sum_credit_value[$sem];
        }
        echo "<TD class=this>" . $total_credits;

        $total_credits = 0;
        $total_credits_value = 0;
        echo "<TR><TD class=this>GPA</TD>";
        for ($sem = 1; $sem < 11; $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 in ('Y') and a.stu_roll = '$stu_roll' and a.sem = '$sem' and a.sub_code = b.sub_code order by a.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($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 in ('Y','T')";
                    $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)
                echo "<TD class=this>" . round($sum_credit_value[$sem] / $sum_credit[$sem], 1);
            else
                echo "<TD class=this> -- ";
            $total_credits = $total_credits + $sum_credit[$sem];
            $total_credits_value = $total_credits_value + $sum_credit_value[$sem];
        }
        if ($total_credits != 0)
            echo "<TD class=this>" . round($total_credits_value / $total_credits, 1);
        else
            echo "<TD class=this> -- ";
        ?>
    </table>
    <TABLE width=600 align=center cellpadding=0 cellspacing=0 class=noborder>
        <TR>
            <TD width=200 style="text-align:left" class=noborder>

                <br/><br/>Date of Approval: <?php echo $approval_date; ?>
                <br/><br/>Date of Download: <?php echo $issuedate; ?>

            </TD>
            <TD width=200 class=noborder>&nbsp;</TD>
            <TD width=200 style="text-align:right" class=noborder><BR><BR><BR><FONT COLOR="red">Dean, Academics</FONT></TD>
        </TR>
        <!-- <TR>
                <TD colspan=2 style="text-align:left" class=noborder>Date of issue: <? echo date("d/m/Y") ?></TD>
                <TD></TD>
                <TD></TD>
        </TR>
        --></TABLE>