<?php 
session_start();
// ============
include("../../asset/theme/css/myfunc.php");
include("../../php_crud/my_class_for_web.php");
$obj = new my_class();
$branch_id = isset($_SESSION['LOGIN_BRANCH']) ? $_SESSION['LOGIN_BRANCH']: '';
extract($_POST);


$table = '';
	

	
$column = 'current_session';
$where_cond= "branch_id =".$branch_id;
$info=$obj->View_column_details_By_Cond("_students_admission_mark_settings",$column,$where_cond);
$current_session = $info['current_session'] ;




// echo 'SELECT * FROM '.$table_name.' WHERE'.$where_cond ;	$br_id = $_SESSION['LOGIN_BRANCH'];
$powered = $_SESSION["powred"];
$design = ''; 


 

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 !=''){
				  $image = '<img src="../../'.$ins_logo.'" style="top:20px;height:150px; float:left;margin-left: -12px;" title="logo" alt="" id="image" />';
				/*  $image1 = ../../../../.$ins_logo.; */
				 }



require_once('../../asset/custom/tcpdf/examples/tcpdf_include.php');
require_once('../../asset/custom/tcpdf/tcpdf.php');



 $PDF_HEADER_LOGO = "logo_example.jpg";//any image file. check correct path.

$your_width=210;
$your_height=297;
$custom_layout = array($your_width, $your_height);


class MYPDF extends TCPDF {
	
	
	protected $image1 ;
	 public function setImagesrc($sr) {
		 $this->image1 = $sr;
	 }
	public function Header() {
		$this->SetAlpha(0.09);
	$this->Image($this->image1, 70, 100, 70, 100, '', '', '', true, 50);
       /*  */
	
		
		/*  */
       
     /* $this->SetAlpha(0.09);
		//$img_file = 'Untitled-1.jpg';
       $this->Image($this->image1, 70, 100, 70, 100, '', '', '', true, 50);     
      $this->SetAlpha(1); */

	 
    }
	
	
    public function Footer() {
		
		
		/*  */
		
		$this->SetFont('helvetica', 'N', 10);
		
		$this->Line(15, 290, 205, 290);
			/*  */

		
		
	
		
		//$this->Line(15, 290, 205, 290);
		//$this->Line(15, 200, 285, 200);
		
		
		$this->SetY(-7);
		$this->SetX(15);
		$by = 'Generated By:'.$_SESSION["LOGIN_USER"];
        $this->SetFont('helvetica', 'N', 8);
        $this->Cell(0, 5,$by, 0, false, '', 0, '', 0, false, 'T', 'M');
		
		
		
		
		
		$this->SetY(-4);
		$this->SetX(15);
		$date = 'Printed Date:';
        $this->SetFont('helvetica', 'N', 6);
        $this->Cell(0, 5,$date.   date(" d/m/Y H\hi:s"), 0, false, '', 0, '', 0, false, 'T', 'M');
		
		
		
        $this->SetY(-5);
        $this->SetFont('helvetica', 'N', 10);
		$a = 'Powred by:'.$_SESSION["powred"];
        $this->Cell(0, 5, $a, 0, false, 'C', 0, '', 0, false, 'T', 'M');
		
		$this->SetY(-7);
    // Set font
    $this->SetFont('helvetica', 'I', 8);
    // Page number
    $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');

		
		
		/*  */
		
		
		
		
		
		
		
		
		
    }
}

$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, $custom_layout, true, 'UTF-8', false);

$pdf->setImagesrc('../../'.$ins_logo);


// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);




$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
	require_once(dirname(__FILE__).'/lang/eng.php');
	$pdf->setLanguageArray($l);
}

// ---------------------------------------------------------






// set font
 $pdf->SetFont('times', '', 10);

  
  
 
 
 /* if(isset($size)?$size:NULL!=''){
if(isset($type_id)?$type_id:NULL!=''){

$pdf->AddPage($type_id, $size);
}

}
 */


// add a page
$pdf->AddPage();

/* ============ */

$tbl_header = '<table style="width: 100%;height:10%;"  cellspacing="">';
$tbl_footer = '</table>';
// create columns content
$tbl = '<tr>
        <td style=" height:150px;width:150px;">
		'.$image.'
		                 
		               
						 
		</td>
        <td style=" width: 60%;">
						<h1 style="font-size: 25px;text-align: center;line-height: 10px;margin-bottom: 3px; margin-top: 20px;;"><b>  '.$inst_name.'</b>
						  ('.$ins_code_name.')
						</h1>
						<h5 style="text-align:center;font-size:14px;margin-top:6px"> '.$ins_address.' , '.$inst_thanta.' , '.$ins_district.' , '.$ins_division.'  </h5>
						 <h5 style="text-align:center;font-size:10px;line-height: 5px;">'.$ins_web.'  '.$ins_email.' </h5>
						 
						 <h2 style="font-size:18px;text-align:center; margin-top: 30px;padding-bottom: 1px;width:100%;">Examen Candidate List - '.$current_session.'</h2>
						
						
		</td>
        <td style=" height:150px;width:150px;">
		</td>
        
    </tr>';








$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, true, false, '');







/*  */
$departname = '';


 $design .= '<table style="color:garay;" > 
   				<tr>
					<td style="font-size:14px;" align="left;" >Class :'.$class_name.' '.$departname.'</td>
      				</tr></table> ';

$design .='	<br/><br/>';	
$design .= '<table  style="width:100%" cellspacing="0" cellpadding="55%" >
		<tr>
			<th style="font-size:11px; border:1px solid #000000 " align="left;" width="10%"><b>Sr. No </b></th>
			<th style="font-size:11px; border:1px solid #000000" align="left;" width="15%"><b>Name </b></th>
			<th style="font-size:11px; border:1px solid #000000" align="left;" width="15%"><b>From No </b></th>
            <th style="font-size:11px; border:1px solid #000000" align="left;" width="15%"><b>Roll </b></th>
			<th style="font-size:11px; border:1px solid #000000" align="left;" width="10%"><b>Image </b></th>
			<th style="font-size:11px; border:1px solid #000000" align="left;" width="30%"><b>Signatur </b></th>
            
		</tr>
		 ' ;



$where_cond=" _session='".$current_session."' AND branch_id=".$branch_id." AND _class='".$class_name."' AND _approve_status='A' ";


if($dpt_num && $dpt_num!='undefined'){
	 $where_cond= $where_cond." AND _department='".$dpt_num."' ";

	}
$where_cond =$where_cond.' ORDER BY admission_exam_roll ASC';	
 //echo 'SELECT * FROM _students_admission_form WHERE'.$where_cond ;	
$can_list=$obj->View_All_By_Cond('_students_admission_form',$where_cond);
	
	
	
	$j = 1;
	

if(!empty($can_list)){
		foreach($can_list as $value ){
			
		$serial_num = $value['serial_num'];
		$_candidate_name = $value['_candidate_name'];
		$exam_roll = $value['admission_exam_roll'];
		$admission_form_id = $value['admission_form_id'];
		$_std_photo = $value['_std_photo'];
		$img_loc = '';
		if(is_file('../../'.$_std_photo)){
			  $img_loc = '<img src="../../'.$_std_photo.'" width="30" height="20"  />';
			}	 				               
      $design .= ' <tr>
				 <td style="border:1px solid #000000" align="left;font-size:11px;">'.$j.'  </td>
				 <td style="border:1px solid #000000" align="left;font-size:11px;">'.$_candidate_name.'</td>
				 <td style="border:1px solid #000000" align="left;font-size:11px;">'.$admission_form_id.'</td>
				 <td style="border:1px solid #000000" align="left;font-size:11px;">'.$exam_roll.'</td>
				 <td style="border:1px solid #000000" align="left;font-size:11px;">'.$img_loc.'</td>
				 <td style="border:1px solid #000000" align="left;font-size:11px;"></td>
				 
			</tr> 
 ' ;
		$j++;

		}
		 
}
		
$design .= ' </table> ';	

$design .='	<br/><br/>';
$design .= '	
	<table width="100%"><tr><td> :  </td></tr></table>
	<br/>
	<table width="100%">
		<tr>
			<th width="30%" style="" align="center;font-size:11px;"> ... </th>
			<th width="30%" style="" align="center;font-size:11px;">...</th>
			<th width="30%" style="" align="center;font-size:11px;">...</th>
		</tr>
		<tbody> 
			</tr>
		</tbody>	
	</table>
 ';






$pdf->writeHTML($design, true, false, true, false, '');
$pdf->lastPage();

// ---------------------------------------------------------

//Close and output PDF document

/*  

   $pdf->Output(__DIR__."/student_information.pdf", 'F'); */



 //if (!file_exists(__DIR__."/student_information.pdf"))
   //             mkdir(__DIR__."/student_information.pdf"); 
	if (file_exists(__DIR__."/Candidate-List.pdf"))
                unlink(__DIR__."/Candidate-List.pdf"); 
				
   $pdf->Output(__DIR__."/Candidate-List.pdf", 'F');





        /* if (!file_exists($base_url."/school_new2/module/profile/report"))
        mkdir($base_url."/school_new2/module/profile/report");

    $pdf->Output($base_url."/school_new2/module/profile/report/filename.pdf", 'F'); */
	//save pdf
   // $pdf->Output('filename.pdf', 'I'); // show pdf


//============================================================+
// END OF FILE
//============================================================+
$json = array('d'=>'success');
 echo json_encode($json);
?>