<?php
$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"];


?>
 <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>Joining Semester<td><?php echo $admission_period_name; ?>
<tr><td class=noborder>Roll Number<td><B><?php echo $stu_roll; ?></B><td>Residence Semester <td><?php echo $residence_semester; ?>
</table>
<!-- Student Ref Ends  -->
<BR>
<CENTER><div style="font-family:arial; font-size:14px;">Chronological Transcript: <?php echo $trans_period_name; ?></div></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.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"; }
	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=500>
<tr><td align=center class=this2><CENTER>
<?php 
$grade_value = "Grade Values: A+ = 10; A = 9, B+ = 8, B = 7; C+ = 6; C = 5; D = 4; P = 0; I = 0; F = 0<BR>P: Pass, but credits not counted towards GPA; I: incomplete; F: Fail.";
echo $grade_value;
?>
</CENTER> </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; ">

<li>Students are expected to complete the entire course work in 8 semesters of residence and the MS project in the 9<sup>th</sup> and 10<sup>th</sup> semesters of residence.</li>

<li>A student is expected to complete 96 credits in semesters 1-4 and 84 credits in semesters 5-8. The MS project carries 36 credits.</li>

<li>The first digit in the course code signifies the year in which student are expected to take that course.  Some courses of level 3 may be taken in year 4, and vice-versa.</li>

<li>GPA: average grade value, weighed by the credits of the course, on a 10-point scale.</li>

<li>The semester GPA is calculated on the basis of the credits registered for.</li>

<li>The cumulative GPA is calculated on the basis of the credits completed.</li>

</ol>
</td></tr></table>

<?php
$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, curr 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) ;
?>
<table border=0 cellspacing=0 cellpadding=1 align=center class=this>
<tr>
<td class=this>&nbsp;&nbsp;Semester&nbsp;&nbsp;
<td class=this>&nbsp;&nbsp;Credits Registered&nbsp;
<td class=this>&nbsp;&nbsp;Credits Completed&nbsp;&nbsp;
<td class=this>&nbsp;&nbsp;GPA&nbsp;&nbsp;
</tr>
<?php
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);
	?>
	<tr>
	<td class=this>&nbsp;&nbsp;&nbsp;<?php echo $sem_name; ?>&nbsp;&nbsp;&nbsp;</td>
	<td class=this><?php echo $credit_registered[$jj]; ?></td>
	<td class=this><?php echo $credit_cleared[$jj]; ?></td>
	<td class=this><?php echo number_format($gpa[$jj],1); ?></td>
	<?php } ?>
<tr>
<td class=this>Cumulative
<td class=this><?php echo $total_credit_registered; ?></td>
<td class=this><?php echo $total_credit_cleared ?></td>
<td class=this><?php echo number_format($cgpa,1); ?></td>
</tr>
</table>

<BR><BR>

<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 issue: <?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>
</TABLE>
