<?php
foreach ($template->result() as $template){
    $filename=$template->kdtemplate;
    $namafile=str_replace(" ","",$template->namatemplate);
}


$url = base_url("resources/template/penetapan/perdata_tun/".$filename.".rtf");
$Template = file_get_contents($url);


$pihak1 = '';
$counter1=0;
if (!empty($perkaraPihak1->num_rows)){ 
	foreach($perkaraPihak1->result() as $row){$counter1++;
		if($row->IDJenisPihak==1){
			$jenisPihak = "Perorangan";
		} else {
			$jenisPihak = "Badan Hukum";
		}

		if ($perkaraPihak1->num_rows>1) {
            $jumlahPihak1 = '\b Penggugat '.$counter1.'\b0\\par ';
        }else{
            $jumlahPihak1 = '\b Penggugat \b0\\par ';
        }

        $pihak1 .= $jumlahPihak1;
        $pihak1 .= 'a. Nama \tab : '.$this->templatehelper->standradnaming($row->namaPihak).'\\par ';
        $pihak1 .= 'b. Kewarganegaraan \tab : '.$this->templatehelper->standradnaming($row->negaraPihak).'\\par ';
        $pihak1 .= 'c. Pekerjaan \tab : '.$this->templatehelper->standradnaming($row->pekerjaanPihak).'\\par ';
        $pihak1 .= 'd. Tempat Tinggal \tab : '.$row->alamatPihak.'\\par ';
    }
}


$pihak2 = '';
$counter2=0;
if (!empty($perkaraPihak2->num_rows)){ 
	foreach($perkaraPihak2->result() as $row){$counter2++;
		if ($perkaraPihak2->num_rows>1) {
            $jumlahPihak2 = '\b Tergugat '.$counter2.'\b0\\par ';
        }else{
            $jumlahPihak2 = '\b Tergugat \b0\\par ';
        }

        $pihak2 .= $jumlahPihak2;
        $pihak2 .= 'a. Nama Jabatan \tab : '.$this->templatehelper->standradnaming($row->namaPihak).'\\par ';
        $pihak2 .= 'b. Tempat Kedudukan \tab : '.$row->alamatPihak.'\\par ';
    }
}

$pihak3 = '';
$pengacara='';
$counterPengacara=0;
if (!empty($pengacaraPihak1->num_rows)){
	$statusPengacara = "V";
	$statusKuasa = "V";
	foreach($pengacaraPihak1->result() as $row){$counterPengacara++;

		$pihak3 .= 'a. Nama \tab : '.$this->templatehelper->standradnaming($row->nama).'\\par ';
        $pihak3 .= 'b. Kewarganegaraan \tab : '.$this->templatehelper->standradnaming($row->nama).'\\par ';
        $pihak3 .= 'c. Pekerjaan \tab : '.$this->templatehelper->standradnaming($row->pekerjaan).'\\par ';
        $pihak3 .= 'd. Tempat Tinggal \tab : '.$row->alamat.'\\par ';
	}
} else {
	$statusPengacara = "";
	$statusKuasa = "";
}







$Template = str_replace('#nomorPerkara#',''.$nomorPerkara.'',$Template);
$Template = str_replace('#Pihak1#',''.$pihak1.'',$Template);
$Template = str_replace('#Pihak2#',''.$pihak2.'',$Template);
$Template = str_replace('#jenisPihak#',''.$jenisPihak.'',$Template);
$Template = str_replace('#aa#',''.$statusPengacara.'',$Template);
$Template = str_replace('#ab#',''.$statusKuasa.'',$Template);
$Template = str_replace('#ac#','V',$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=\"".$namafile."-".$nomorPerkara.".rtf\"");
header("Content-length: ".strlen($Template));
echo $Template;
exit;
?>