<?php

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/status_bayar/business/AppStatusBayar.class.php';

class ViewStatusBayar extends HtmlResponse{
	function TemplateModule() {
		$this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/status_bayar/template');
		$this->SetTemplateFile('view_status_bayar.html');
	}

   function ProcessRequest() {
      $msg = Messenger::Instance()->Receive(__FILE__);		
      $byrObj = new AppStatusBayar();
      $paging = Dispatcher::Instance()->Decrypt($_GET['paging']);
		
		if($_POST['isCari'] == '1'){
			$tahun = $_POST['tahun'];
			$semester = $_POST['semester'];
			$prodi = $_POST['prodi'];
			$notes_nim = $_POST['notes_nim'];
			$nama = $_POST['nama'];
			$status_byr = $_POST['status_byr'];
			$status_reg = $_POST['status_reg'];
		}else{
			if($paging != ''){
				$tahun = Dispatcher::Instance()->Decrypt($_GET['tahun']);
				$semester = Dispatcher::Instance()->Decrypt($_GET['semester']);
				$prodi = Dispatcher::Instance()->Decrypt($_GET['prodi']);
            $notes_nim = Dispatcher::Instance()->Decrypt($_GET['notes_nim']);
            $nama = Dispatcher::Instance()->Decrypt($_GET['nama']);
            $status_byr = Dispatcher::Instance()->Decrypt($_GET['status_byr']);
            $status_reg = Dispatcher::Instance()->Decrypt($_GET['status_reg']);	
			}else{
				$tahun = 'all';
				$semester = 'all';
				$prodi = 'all';
            $notes_nim = '';
            $nama = '';
            $status_byr = 'all';
            $status_reg = 'all';
			}
		}						
		
      $totalData = $byrObj->GetCountStatusBayarMahasiswa($tahun,$semester,$prodi,$nama,$notes_nim,$status_byr,$status_reg);
		$itemViewed = 20;
		$currPage = 1;
		$startRec = 0 ;
      if(isset($_GET['page'])) {
			$currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
			$startRec =($currPage-1) * $itemViewed;
		}
      $dataStatusBayar = $byrObj->GetDataStatusBayarMahasiswa($tahun,$semester,$prodi,$nama,$notes_nim,$status_byr,$status_reg,$startRec,$itemViewed);
      
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
            Dispatcher::Instance()->mSubModule, 
            Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . 
            '&tahun=' . Dispatcher::Instance()->Encrypt($tahun) .
            '&semester=' . Dispatcher::Instance()->Encrypt($semester) .
            '&prodi=' . Dispatcher::Instance()->Encrypt($prodi) . 
            '&notes_nim=' . Dispatcher::Instance()->Encrypt($notes_nim) . 
            '&nama=' . Dispatcher::Instance()->Encrypt($nama) . 
            '&status_byr=' . Dispatcher::Instance()->Encrypt($status_byr) .
            '&status_reg=' . Dispatcher::Instance()->Encrypt($status_reg) .  
            '&paging=' . 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__);
      
      $dataPeriodeAktif = $byrObj->GetPeriodeAktif();
      $dataNamaPeriode = $byrObj->GetNamaPeriode();
      $dataPeriode=$byrObj->GetDataPeriode();
		$dataProdi=$byrObj->GetDataProdi();     
      $dataTahunMasuk=$byrObj->GetDataTahun();
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'tahun',
         array('tahun',$dataTahunMasuk,$tahun,'true',''), Messenger::CurrentRequest);
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'semester',
         array('semester',$dataNamaPeriode,$semester,'true',''), Messenger::CurrentRequest);

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'prodi',
         array('prodi',$dataProdi,$prodi,'true',''), Messenger::CurrentRequest);
         
      $statusBayar=$byrObj->GetStatusBayar();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status_byr',
            array('status_byr',$statusBayar,$status_byr,'true',''), Messenger::CurrentRequest);
      
      $statusRegistrasi=$byrObj->GetStatusRegistrasi();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status_reg',
            array('status_reg',$statusRegistrasi,$status_reg,'true',''), Messenger::CurrentRequest);
            
		
      $return['pesan'] = $msg[0][1];
		$return['css'] = $msg[0][2];
		$return['start'] = $startRec+1;
		$return['search']['tahun'] = $tahun;
		$return['search']['prodi'] = $prodi;
		$return['search']['semester'] = $semester;      
      $return['search']['notes_nim']=$notes_nim;
      $return['search']['nama']=$nama;
      $return['search']['status_byr']=$status_byr;
      $return['search']['status_reg']=$status_reg;
      $return['dataStatusBayar'] = $dataStatusBayar;
      $return['dataPeriodeAktif'] = $dataPeriodeAktif;
      $return['dataNamaPeriode'] = $dataNamaPeriode;
      $return['dataPeriode'] = $dataPeriode;

		return $return;
   }

   function ParseTemplate($data = NULL) {
      $search = $data['search'];
      $dataStatusBayar = $data['dataStatusBayar'];
      $dataPeriodeAktif = $data['dataPeriodeAktif'];
		$dataNamaPeriode = $data['dataNamaPeriode'];				
		
      $this->mrTemplate->AddVar('content', 'NOTES_NIM', $search['notes_nim']);
      $this->mrTemplate->AddVar('content', 'NAMA', $search['nama']);
		$this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('status_bayar', 'statusBayar', 'view', 'html'));
		#print_r($dataStatusBayar);
		
      if(!empty($data['dataPeriodeAktif'])){
         $this->mrTemplate->SetAttribute('periode', 'visibility', 'visible');
         $this->mrTemplate->AddVars('periode', $data['dataPeriodeAktif'][0], '');
      }
		if(!empty($data['dataNamaPeriode'])){
         $this->mrTemplate->SetAttribute('periode', 'visibility', 'visible');
         $this->mrTemplate->AddVars('periode', $data['dataNamaPeriode'][0], '');   
      }

      if (empty($data['dataStatusBayar'])) {
			$this->mrTemplate->AddVar('data_status_bayar', 'STS_BYR_EMPTY', 'YES');
		} else {
			$decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
			$encPage = Dispatcher::Instance()->Encrypt($decPage);
			$this->mrTemplate->AddVar('data_status_bayar', 'STS_BYR_EMPTY', 'NO');
			$dataStatusBayar = $data['dataStatusBayar'];

         for ($i=0; $i<sizeof($dataStatusBayar); $i++) {
				$no = $i+$data['start'];
				$dataStatusBayar[$i]['number'] = $no;
				if ($no % 2 != 0) $dataRegistrasi[$i]['class_name'] = 'table-common-even';
				else $dataStatusBayar[$i]['class_name'] = '';
				
				$idEnc = Dispatcher::Instance()->Encrypt($dataStatusBayar[$i]['id']);

            $dataStatusBayar[$i]['url_detil'] = Dispatcher::Instance()->GetUrl('status_bayar', 'detilStatusBayar', 'view', 'html') . 
               '&dataId=' . $idEnc . '&id=' . $idEnc; 								
				
				if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);				
				if($i == sizeof($dataStatusBayar)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
				$this->mrTemplate->AddVars('data_status_bayar_item', $dataStatusBayar[$i], 'STS_BYR_');
				$this->mrTemplate->parseTemplate('data_status_bayar_item', 'a');	 
         }
      }
   }
}
?>