<?php
	if($this->session->userdata('is_logged_in')===FALSE){
		redirect('login');
	}

	$no_ac=$data->row(0)->no_ac;
	$nama_satker=ucwords(strtolower($this->templatehelper->standradnaming($data->row(0)->nama_satker)));
	$tgl_ac=$data->row(0)->tgl_ac;
	if ($data->row(0)->jenis_perkara_id==346 and $is_islam_ikrar > 1) {
        $jenis_putusan="Putusan";
	} else {
        $jenis_putusan=$data->row(0)->jenis_putusan;
    }

	$nomor_perkara=$data->row(0)->nomor_perkara;
    if ($data->row(0)->jenis_perkara_id==346 and $is_islam_ikrar > 1) {
        $tanggal_putusan=$this->templatehelper->convertKeTglIndo($data->row(0)->tgl_putusan);
    } else {
        $tanggal_putusan=$this->templatehelper->convertKeTglIndo($data->row(0)->tanggal_putusan);
    }
	$nama_p=$data->row(0)->nama_p;
	$umur_p=$data->row(0)->umur_p;
	$agama_p=$data->row(0)->agama_p;
	$pekerjaan_p=$data->row(0)->pekerjaan_p;
	$alamat_p=$data->row(0)->alamat_p;
	$nama_t=$data->row(0)->nama_t;
	$umur_t=$data->row(0)->umur_t;
	$agama_t=$data->row(0)->agama_t;
	$pekerjaan_t=$data->row(0)->pekerjaan_t;
	$alamat_t=$data->row(0)->alamat_t;
	$jenis_perkara=$data->row(0)->jenis_perkara;
	$perceraian_ke=$data->row(0)->perceraian_ke;
	$istri_sebagai=$data->row(0)->istri_sebagai;
	$qobla_bada=$data->row(0)->qobla_bada;
	$keadaan_istri=$data->row(0)->keadaan_istri;
	$kua_tempat_nikah=$data->row(0)->kua_tempat_nikah;
	$no_kutipan_akta_nikah=$data->row(0)->no_kutipan_akta_nikah;
	$tgl_kutipan_akta_nikah=$this->templatehelper->convertKeTglIndo($data->row(0)->tgl_kutipan_akta_nikah);
	$nama_pan=$data->row(0)->nama_pan;
	$nip_pan=$data->row(0)->nip_pan;

	switch ($keadaan_istri) {
		case 1:
			$keadaan_istri = "suci";
		break;
		case 2:
			$keadaan_istri = "haid";
		break;
		case 3:
			$keadaan_istri = "hamil";
		break;
		case 4:
			$keadaan_istri = "tidak diketahui";
		break;
	}

	$terbilang=$this->templatehelper->Terbilang($perceraian_ke);
	$hari=$this->templatehelper->getHari($tgl_ac);
	$hijriah=$this->templatehelper->convertToHijriah($tgl_ac);
	$tgl_ac=$this->templatehelper->convertKeTglIndo($tgl_ac);
	$tmp = explode('/', $no_ac);
	$nomor_akta=$tmp[0];
	$tahun_akta=$tmp[2];
	$kode_akta=str_replace('PA.','',str_replace('MS.','',str_replace(' ','',$tmp[3])));
	$pa='==';
	$ms='====';
	if(substr($tmp[3], 0,3)=='MS.'){
		$ms='';
	}else{
		$pa='';
	}
	$temp='akta_cerai';
	if($blangko==0){
		$temp.='_blangko_lama';
	}

	$url = base_url("resources/template/akta_cerai/".$temp.".rtf");
	$Template = file_get_contents($url);

	$Template = str_replace("#NOMOR_AC#",$no_ac,$Template);
	$Template = str_replace("#NA#",$nomor_akta,$Template);
	$Template = str_replace("#TA#",$tahun_akta,$Template);
	$Template = str_replace("#KP#",$kode_akta,$Template);
	$Template = str_replace("#MS#",$ms,$Template);
	$Template = str_replace("#PA#",$pa,$Template);
	$Template = str_replace("#SATKER#",''.$nama_satker,$Template);
	$Template = str_replace("#NOMOR_PERKARA#",$nomor_perkara,$Template);
	$Template = str_replace("#HARI_SEKARANG#",$hari,$Template);
	$Template = str_replace("#TANGGAL_AC#",$tgl_ac,$Template);
	$Template = str_replace("#TGL_HIJRIAH#",$hijriah,$Template);
	$Template = str_replace("#PUTUSAN_PENETAPAN#",$jenis_putusan,$Template);
	$Template = str_replace("#TGL_PUTUSAN#",$tanggal_putusan,$Template);
	$Template = str_replace("#NAMA_P#",$nama_p,$Template);
	$Template = str_replace("#UMUR_P#",$umur_p,$Template);
	$Template = str_replace("#AGAMA_P#",$agama_p,$Template);
	$Template = str_replace("#PEKERJAAN_P#",$pekerjaan_p,$Template);
	$Template = str_replace("#ALAMAT_P#",$alamat_p,$Template);
	$Template = str_replace("#NAMA_T#",$nama_t,$Template);
	$Template = str_replace("#UMUR_T#",$umur_t,$Template);
	$Template = str_replace("#AGAMA_T#",$agama_t,$Template);
	$Template = str_replace("#PEKERJAAN_T#",$pekerjaan_t,$Template);
	$Template = str_replace("#ALAMAT_T#",$alamat_t,$Template);
	$Template = str_replace("#TALAKDIC#",$jenis_perkara,$Template);
	$Template = str_replace("#PERCERAIAN_KE#",$perceraian_ke,$Template);
	$Template = str_replace("#PERCERAIAN_KE_TERBILANG#",$terbilang,$Template);
	$Template = str_replace("#ISTRI_SEBAGAI#",$istri_sebagai,$Template);
	$Template = str_replace("#QOBLADIC#",$qobla_bada,$Template);
	$Template = str_replace("#SUCIDIC#",$keadaan_istri,$Template);
	$Template = str_replace("#KUA_TEMPAT_NIKAH#",$kua_tempat_nikah,$Template);
	$Template = str_replace("#NO_KUTIPAN_AKTA_NIKAH#",$no_kutipan_akta_nikah,$Template);
	$Template = str_replace("#TGL_KUTIPAN_AKTA_NIKAH#",$tgl_kutipan_akta_nikah,$Template);
	$Template = str_replace("#NAMA_PANITERA#",$nama_pan,$Template);
	$Template = str_replace("#NIP_PANITERA#",$nip_pan,$Template);

	header("Content-Type: application/vnd.ms-word");
	header("Expires: 0");
	header("Cache-Control:  must-revalidate, post-check=0, pre-check=0");
	header("Content-disposition: attachment; filename=\"Akta Cerai -".$nomor_perkara.".rtf\"");
	echo $Template;
?>