<?php
//error_reporting(0); 
session_start();
// ============
include("../../php_crud/my_class.php");
$obj = new my_class();
// ============

extract($_GET);
//print_r($_SESSION);

	$section_ids=$obj->View_All_child($class_id,'SC');
	$section_ids="0".$section_ids;
	
	
	$branch_id = isset($_SESSION['LOGIN_BRANCHES']) ? $_SESSION['LOGIN_BRANCHES'] : '';
	if ($branch_id != '') {
	
		$brans_obj =  $obj->View_branch_details_By_Cond($branch_id, 'B');
		$inst_name = $brans_obj->insName;
		$ins_code_name = $brans_obj->insCodeName;
		$extablishd_year = $brans_obj->_establish_year;
		$ins_logo = $brans_obj->_logo_location;
		$ins_address = $brans_obj->_address;
		$inst_thanta = $brans_obj->thana_name;
		$ins_district = $brans_obj->distrinc_name;
		$ins_division = $brans_obj->division_name;
		$ins_web = $brans_obj->_web_address != '' ? $brans_obj->_web_address   : '';
		$ins_email = $brans_obj->_email_add != '' ? $brans_obj->_email_add : '';
	}
	
	if ($ins_logo != '') {
		$img = '<img src="../../' . $ins_logo . '" style="width:100px;height:100px; float:left;margin-left: 30px;" title="logo" alt="institute logo" id="image" />';
	} else {
		// alternate iamge
		$img = '';
	}
	
	
	require_once('../../asset/custom/mpdf/mpdf.php');		
	$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0, 'L'); 
	 	 
	$mpdf->SetDisplayMode('fullpage');		 
	$mpdf->list_indent_first_level = 0;  // 1 or 0 - whether to indent the first level of a list
	$class = $obj->Details_By_Cond("_int_institute_setup_vw", "class_id='$class_id'");
  
    $ct_list = array();
	foreach ($obj->View_colmn_By_Cond("_ct_class_test_add", "*", "_sub_id='$sub_id' AND _dep_id='$department_id' AND _exam_term='$exam_term'") AS $up) 
	{	
		$ct_id = $up['_id'];
		$ct_name = $up['_ct_name'];	
		$ct_list[] = $ct_id .'#'. $up['_assign_mark'] .'#'.$ct_name;
	}	
	
	$contents = '<style>
	.theading_2LB{ 
	border-left:1px solid #000;
	border-bottom:1px solid #000;
     font-size:10px;
    text-align:center;
	}
	.theading_2LBR{ 
	border-left:1px solid #000;
	border-bottom:1px solid #000;
    border-right:1px solid #000;
    text-align:center;
	font-size:10px;
	}
	.theading_4{
   border-left:1px solid #000;
   border-top:1px solid #000;
   border-bottom:1px solid #000;
   border-right:1px solid #000;
   text-align:center;
   font-size:10px;
}
.theading_3{    
   border-top:1px solid #000;
   border-bottom:1px solid #000;
   border-right:1px solid #000;
   text-align:center;
   font-size:10px;
}
	</style>';

	
		$term = $obj->Details_By_Cond("_int_exam_term", "_id='$exam_term' and _branch_id='$branch_id'");
		$dept = $obj->Details_By_Cond("_int_institute_setup_vw", "department_id='$department_id'");
		$class = $obj->Details_By_Cond("_int_institute_setup_vw", "class_id='$class_id'");

		$contents .='<table border="0" width="100%"> 
					<tr valign="top"> 		
                        <td width="10%" > '.$img .'</td>					
						<td width="80%" align="center"> 							
							<table border="0" align="right" width="100%">							
							<tr>
							<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
							<td style="text-transform: uppercase;font-size:18px;text-align:center;font-weight:bold;">							
							'. $inst_name .'</td></tr>
							<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td align="center" style="font-size:15px;">
							'. $ins_address .' , '. $inst_thanta .' , ' . $ins_division.' <br/>
							Email: '. $ins_email .', Website: '. $ins_web .' <br/>	
							Class Test Report: '.($term['_term_name']).'<br/>'.
							'Class: '. $class['class'] .', Department: '. $dept['department']
							.'</td></tr>
							</table>						
						</td> 
					    <td width="10%" > &nbsp;</td> 			
					</tr>					 
					</table><br/>'; 

	
	$contents .= "<table cellpadding='0' cellspacing='0' align='center' width='97%'>"; 
	$contents .= "<tr><th class='theading_4'>Student ID</th><th class='theading_3' width='20%'>Name</th><th class='theading_3'>Section Roll</th>";
	for($i=0;$i<count($ct_list);$i++)
	{
	   $cstr =	$ct_list[$i];
	   $parsing = explode("#",$cstr);
	   $contents .= "<th class='theading_3' width='10%'>". $parsing[2] ." Mark</th>"; 
	 
	}
	$contents .= "<th class='theading_3'>Total</th><th class='theading_3'>Converted Total</th>";	 
	$contents .= "</tr>";
	
	
	
	
   	$table = "_pf_std_basic_info b LEFT JOIN _pf_std_personal_info p ON (b._pid = p._id)";
	foreach ($obj->View_All_By_Cond($table, "b._section_id IN ($section_ids) ORDER BY p._section_roll ASC") as $value) 
 	{
		 
		$std_id = $value['_pid'];
		$section_roll = $value['_section_roll'];				 		
		$name = $value['_full_name']; 
			
		$contents .= "<tr><td class='theading_2LB'>".  $std_id ."</td><td class='theading_2LB' style='text-align:left;'>&nbsp;".  $name ."</td><td class='theading_2LB'>". $section_roll . "</td>";
		$total_mark = 0;
		for($i=0;$i<count($ct_list);$i++)
		{		   
		   $cts = $ct_list[$i];
		   $parse = explode("#",$cts);
		   $ctID = $parse[0];
		   $ct_assign_mark = $parse[1];
		    
		   $ct_det = $obj->Details_By_Cond("_ct_mark_sheet", "_subject_id='$sub_id' AND _std_id='$std_id' AND _exam_term='$exam_term' AND _exam_session='2017' and _ct_id='$ctID'");
		   $mark   = $ct_det['_mark'];
  		   
		   $total_mark		    += $mark;
		   $converted_mark = (floatval($total_mark) * floatval($ct_assign_mark))/100;	
		   $contents .=  "<td class='theading_2LB'>". $mark . "</td>";
		}
		
		$contents .=  "<td class='theading_2LB'>".$total_mark."</td>";
		$contents .=  "<td class='theading_2LBR'>". $converted_mark . "</td>";		   
		$contents .= "</tr>"; 
		 
	}  
	$contents .= "</table>"; 
        
 
	
	$mpdf->showWatermarkImage = true;
	$mpdf->SetWatermarkImage('../../'.$ins_logo  , .10,50,150);
	//$mpdf->SetFooter('Print Date:{DATE j-m-Y}|Powered By Leotech|Page{PAGENO}');
	$mpdf->WriteHTML($contents);
	$mpdf->Output();
 

	?>
 
 