<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/status_nikah/business/AppStatusNikah.class.php';

class ViewStatusNikah extends HtmlResponse {

	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/status_nikah/template');
		$this->SetTemplateFile('view_status_nikah.html');
	}
	
	function ProcessRequest() {
		$statusNikahObj = new AppStatusNikah();
		
    if($_POST || isset($_GET['cari'])) {
			if(isset($_POST['status_nikah'])) {
				$status_nikah = $_POST['status_nikah'];
			} elseif(isset($_GET['status_nikah'])) {
				$status_nikah = Dispatcher::Instance()->Decrypt($_GET['status_nikah']);
			} else {
				$status_nikah = '';
			}
		}
		
	//view
		$totalData = $statusNikahObj->GetCountDataStatusNikah($status_nikah);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
		if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
		$dataStatusNikah = $statusNikahObj->getDataStatusNikah($startRec, $itemViewed, $status_nikah);
#		print_r($dataStatusNikah);
		$url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&status_nikah=' . Dispatcher::Instance()->Encrypt($status_nikah) . '&cari=' . Dispatcher::Instance()->Encrypt(1));

		Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed,$totalData, $url, $currPage), Messenger::CurrentRequest);

		$msg = Messenger::Instance()->Receive(__FILE__);
		$return['Pesan'] = $msg[0][1];
		$return['css'] = $msg[0][2];
		
		$return['siaPesan'] = $msg[1][1];
		$return['siaCss'] = $msg[1][2];

		$return['dataStatusNikah'] = $dataStatusNikah;
		$return['start'] = $startRec+1;

		$return['search']['status_nikah'] = $status_nikah;
		return $return;
	}
	
	function ParseTemplate($data = NULL) {
		$search = $data['search'];
		$this->mrTemplate->AddVar('content', 'STATUS_NIKAH', $search['status_nikah']);
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('status_nikah', 'statusNikah', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('status_nikah', 'inputStatusNikah', 'view', 'html'));
		
      if($data['Pesan']) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['Pesan']);
			$this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $data['css']);
		}
      
      if($data['siaPesan']) {
			$this->mrTemplate->SetAttribute('warning_connection', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_connection', 'ISI_PESAN', $data['siaPesan']);
			$this->mrTemplate->AddVar('warning_connection', 'CLASS_PESAN', $data['siaCss']);
		}
      
		if (empty($data['dataStatusNikah'])) {
			$this->mrTemplate->AddVar('data_status_nikah', 'STATUS_NIKAH_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_status_nikah', 'STATUS_NIKAH_EMPTY', 'NO');
			$dataStatusNikah = $data['dataStatusNikah'];
		
//mulai bikin tombol delete
			$label = "Data Status Nikah";
			$urlDelete = Dispatcher::Instance()->GetUrl('status_nikah', 'deleteStatusNikah', 'do', 'html');
			$urlReturn = Dispatcher::Instance()->GetUrl('status_nikah', 'statusNikah', 'view', 'html');
			Messenger::Instance()->Send('confirm', 'confirmDelete', 'do', 'html', array($label, $urlDelete, $urlReturn),Messenger::NextRequest);
			$this->mrTemplate->AddVar('content', 'URL_DELETE', Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html'));

			for ($i=0; $i<sizeof($dataStatusNikah); $i++) {
				$no = $i+$data['start'];
				$dataStatusNikah[$i]['number'] = $no;
				if ($no % 2 != 0) $dataStatusNikah[$i]['class_name'] = 'table-common-even';
				else $dataStatusNikah[$i]['class_name'] = '';
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataStatusNikah)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$idEnc = Dispatcher::Instance()->Encrypt($dataStatusNikah[$i]['status_nikah_id']);

            $urlAccept = 'status_nikah|deleteStatusNikah|do|html-cari-'.$cari;
            $urlReturn = 'status_nikah|statusNikah|view|html-cari-'.$cari;
            $dataName = $dataStatusNikah[$i]['status_nikah_nama'];
				$dataStatusNikah[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('status_nikah', 'inputStatusNikah', 'view', 'html') . '&dataId=' . $idEnc . '&page=' . $encPage . '&cari='.$cari;
            $dataStatusNikah[$i]['url_delete'] = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$idEnc.'&label='.$label.'&dataName='.$dataName;
				
            $this->mrTemplate->AddVars('data_status_nikah_item', $dataStatusNikah[$i], 'STATUS_NIKAH_');
				$this->mrTemplate->parseTemplate('data_status_nikah_item', 'a');	 
			}
		}
	}
}
?>
