<?php 

	session_start();
	include('../db.php');

	

  	// PARAM $mode : 1 = show in browser
	//               2 = force download (provide the file name in $save)
	//               3 = save on server (provide the absolute path and file name in $save)
	//       $save : output filename

		// MPDF
		require __DIR__ . DIRECTORY_SEPARATOR . "MPDF" . DIRECTORY_SEPARATOR . "autoload.php";
		$mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8','autoMarginPadding' => 1]);
		
		
		
		$account_holder_id=$_GET['account_holder_id'];
	    $customerQ = mysqli_query($conn,"select *from `customer` where account_holder_id = '$account_holder_id' ");
	    $customerData = mysqli_fetch_assoc($customerQ);
	   
	
	  
		  
		 $url = $_SERVER['REQUEST_URI']; //returns the current URL
$parts = explode('/',$url);
$dir = $_SERVER['SERVER_NAME'];
for ($i = 0; $i < count($parts) - 1; $i++) {
 $dir .= $parts[$i] . "/";
}




            

      $full_url="http://".$dir."mini_statement_html.php?type=pdf&account_holder_id=".$account_holder_id;
	  
	  $content = file_get_contents($full_url);
		
	      $mpdf->WriteHTML($content);
		  
		  
		  $view_type='';
		  if(isset($_GET['view_type']))
		  {
			  
			  $view_type = $_GET['view_type'];
			  
		  }
		  
		  
		    if($view_type == 'view')
		  {
		    $mpdf->Output();
			
		  }
		  
		  else
		  {
			 $mpdf->Output('statement_'.str_replace('#','',$account_holder_id).'.pdf','D');

		  }
		  
		  
		 
		  
		  if($view_type == 'view')
		  {
		    $mpdf->Output();
			
		  }
		  else if($view_type == 'create')
		  {
		    $mpdf->Output('mini_statements/Statement_'.str_replace(' ','_',$customerData['name']).'.pdf','F');


			
		  }
		  else
		  {
			 $mpdf->Output('Statement_'.str_replace(' ','_',$customerData['name']).'.pdf','D');

		  }
		  
		 
 
		
		
?>