<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/cetak_dokumen/business/AppCetakDokumen.class.php';
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .'main/function/date.php';

class PrintCetakDokumen extends HtmlResponse {	
	function TemplateModule() {

	}
	function ProcessRequest() {
      $dokObj=new AppCetakDokumen();
      
      $idMhs = Dispatcher::Instance()->Decrypt($_GET['idMhs']);
      $idTpl = Dispatcher::Instance()->Decrypt($_GET['idTpl']);
      
      $dataTemplate=$dokObj->GetTemplateCetakById($idTpl);
      $varTemplate=$dokObj->GetVariableTemplate();
      $tahunAjaran=$dokObj->GetTahunAjaran();
      $dataCetak=$dokObj->GetDataCetak($idMhs);
      $dataPeriode=$dokObj->GetTahunAjaran();
      $dataCetak[0]['TEMPAT/TANGGAL_LAHIR']=$dataCetak[0]['tpt_lahir'].', '. IndonesianDate($dataCetak[0]['tgl_lahir'],"YYYY-MM-DD");
      $dataCetak[0]['TTL_ORTU']=IndonesianDate($dataCetak[0]['TL_ORTU'],"YYYY-MM-DD");
      $dataCetak[0]['NAMA_INSTANSI_KAPITAL']=strtoupper(GTFWConfiguration::GetValue( 'organization','company_name'));
      $dataCetak[0]['NAMA_INSTANSI']=GTFWConfiguration::GetValue( 'organization','company_name');
      $dataCetak[0]['NAMA_SINGKAT_INSTANSI']=GTFWConfiguration::GetValue( 'organization','company_short_name');
      $dataCetak[0]['KOTA_INSTANSI']=GTFWConfiguration::GetValue( 'organization','company_city');
      $dataCetak[0]['TAHUN_AJARAN']=$dataPeriode[0]['TAHUN_AJARAN'];
      $dataCetak[0]['NAMA_PERIODE']=strtoupper($dataPeriode[0]['NAMA_PERIODE']);
      $dataCetak[0]['ALAMAT_INSTANSI']=GTFWConfiguration::GetValue( 'organization','company_address');
      $dataCetak[0]['YAYASAN_INSTANSI']=GTFWConfiguration::GetValue( 'organization','company_foundation');
      $dataCetak[0]['TELP_INSTANSI']=GTFWConfiguration::GetValue( 'organization','company_telp');
      $dataCetak[0]['EMAIL_INSTANSI']=GTFWConfiguration::GetValue( 'organization','company_email');
      //print_r($dataCetak[0]);exit;
      foreach($varTemplate as  $data){
         $arrVariable[]=str_replace(' ','_',$data['var_nama']);
      }
      //print_r($arrVariable);exit;
      
      $contents = file_get_contents(GTFWConfiguration::GetValue( 'application','docroot')."file/template_cetak/".$dataTemplate[0]['tpl_path']);
      $contents = str_replace('[TANGGAL]', date("d-M-Y"),$contents);
      $contents = str_replace('[TAHUN_AJARAN]', $tahunAjaran[0]['TAHUN_AJARAN'],$contents);
      
      for($i=0;$i<sizeOf($arrVariable);$i++){
         $contents = str_replace('['.$arrVariable[$i].']', $dataCetak[0][$arrVariable[$i]], $contents); 
         //echo '['.$arrVariable[$i].']'.':  '.$dataCetak[0][$arrVariable[$i]].'<br />';
         //if ($arrVariable[$i] == 'ALAMAT_INSTANSI') exit;
      }
      
      $nama=strtolower(preg_replace(
         '/[^a-zA-Z0-9\.\$\%\'\`\-\@\{\}\~\!\#\(\)\&\_\^]/'
         ,'',str_replace(array(' ','%20'),array('_','_'),$dataCetak[0]['NAMA'])));      
      
      
      header("Content-type: application/msword");
      header("Content-disposition: inline; filename=".$nama."_".$dataTemplate[0]['tpl_path']);
      //header("Content-length: " . strlen($contents));
      echo($contents); 
   } 
    function Parsetemplate($data=null){
    
    }
}
?>
