<?php
/*
   @ClassName : ViewInputPenggunaanRuang
   @Copyright : PT Gamatechno Indonesia
   @Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
   @Author By : Dyan Galih <galih@gamatechno.com>
   @Version : 0.1
   @StartDate : 2010-06-19
   @LastUpdate : 2010-06-19
   @Description :
*/

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

class ViewInputPenggunaanRuang extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/penggunaan_ruang/template');
      $this->SetTemplateFile('view_input_penggunaan_ruang.html');
   }

   function ProcessRequest() {
      $objPengRuang = new PenggunaanRuang;

      $id = Dispatcher::Instance()->Decrypt($_GET['id']);

      $hour = $objPengRuang->GetHour();
      $minute = $objPengRuang->GetMinute();

      $result = $objPengRuang->GetPenggunaanRuangById($id);
      $resultDetil = $objPengRuang->GetPenggunaanRuangUnit($id);
		$jenis = $objPengRuang->ComboJenis();

      $return['detil'] = json_encode($resultDetil);

      if(!empty($result)){
         $startDate = $result['rupengTglMulai'];
         $startHour = $result['hour_awal'];
         $startMinute = $result['minute_awal'];
			$jeniss = $result['rupengJnsPenggunaanRuangId'];

         $endDate = $result['rupengTglSelesai'];
         $endHour = $result['hour_akhir'];
         $endMinute = $result['minute_akhir'];
         $return['user']['id'] = $result['rupengUserId'];
         $return['user']['name'] = $result['realName'];
         $return['ruang']['ruang_id']= $result['rupengRuangId'];
			$return['ruang']['rupengId']= $result['rupengId'];
         $return['ruang']['ruang_nama']= $result['ruangNama'];
         $return['ruang']['keterangan']= $result['rupengKeterangan'];
			$return['ruang']['penyewa']= $result['penyewa'];
			$return['ruang']['telp']= $result['telp'];
			$return['ruang']['alamat']= $result['alamat'];
			$return['ruang']['biaya']= $result['biaya'];
			$return['ruang']['biaya_awal']= $result['biaya_awal'];
			$return['ruang']['biaya_awal_view']= $result['biaya_awal'];
			$return['ruang']['rupengpemegangkunci']= $result['rupengPemegangKunci'];
			$return['ruang']['potongan']= $result['potongan'];

      }else{
         $today = date("Y-m-d");
         $hourNow = date('H');
         $minuteNow = date('i');
			$jeniss = ' ';

         $startDate = $today;
         $startHour = $hourNow;
         $startMinute = $minuteNow;

         $endDate = $today;
         $endHour = $hourNow;
         $endMinute = $minuteNow;

         $return['user']['id'] = Security::Instance()->mAuthentication->GetCurrentUser()->GetUserId();
         $return['user']['name'] = Security::Instance()->mAuthentication->GetCurrentUser()->GetRealName();
         $return['ruang']['ruang_id']= "";
			$return['ruang']['rupengId']= "";
         $return['ruang']['ruang_nama']= "";
         $return['ruang']['keterangan']= "";
			$return['ruang']['rupengpemegangkunci']="";
			$return['ruang']['penyewa']="";
			$return['ruang']['telp']="";
			$return['ruang']['alamat']="";
			$return['ruang']['biaya']="";
			$return['ruang']['biaya_awal']="";
			$return['ruang']['biaya_awal_view']="";
			$return['ruang']['potongan']="";
      }

			Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jenis',array('jenis', $jenis, $jeniss, false, ''),Messenger::CurrentRequest);

      Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tgl_awal',array($startDate, '2000', date('Y')+1,'','','','hitung();'), Messenger::CurrentRequest);
       Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tgl_akhir',array($endDate, '2000', date('Y')+1,'','','','hitung();'), Messenger::CurrentRequest);

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jam_awal',array('jam_awal', $hour, $startHour, '', 'id="jam_awal" onchange="hitung()"'),Messenger::CurrentRequest);
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'menit_awal',array('menit_awal', $minute, $startMinute, '', 'id="menit_awal" onchange="hitung()"'),Messenger::CurrentRequest);

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jam_akhir',array('jam_akhir', $hour, $endHour, '', 'id="jam_akhir" onchange="hitung()"'),Messenger::CurrentRequest);
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'menit_akhir',array('menit_akhir', $minute, $endMinute, '', 'id="menit_akhir" onchange="hitung()"'),Messenger::CurrentRequest);

      $return['id'] = $id;
      return $return;
   }

   function ParseTemplate($data = NULL) {

      $this->mrTemplate->AddVar('content', 'JSON_DETIL', $data['detil']);

      $urlRuangSearch = Dispatcher::Instance()->GetUrl('penggunaan_ruang', 'RuangSearch', 'view', 'html');
      $this->mrTemplate->AddVar('content', 'URL_SEARCH_RUANG', $urlRuangSearch);

      $urlUnitSearch = Dispatcher::Instance()->GetUrl('penggunaan_ruang', 'UnitSearch', 'view', 'html');
      $this->mrTemplate->AddVar('content', 'URL_UNIT_SEARCH', $urlUnitSearch);


      if($data['id']=='')
         $urlAction = Dispatcher::Instance()->GetUrl('penggunaan_ruang', 'AddPenggunaanRuang', 'do', 'json');
      else
         $urlAction = Dispatcher::Instance()->GetUrl('penggunaan_ruang', 'UpdatePenggunaanRuang', 'do', 'json').'&id='.Dispatcher::Instance()->Encrypt($data['id']);
         
		$urlBack = Dispatcher::Instance()->GetUrl('penggunaan_ruang', 'SearchPenggunaanRuang', 'view', 'html');
      $this->mrTemplate->AddVar('content', 'ACTION_URL', $urlAction);
      $this->mrTemplate->AddVar('content', 'URL_BACK', $urlBack);

      $this->mrTemplate->AddVars('content', $data['user'],'USER_' );
      $this->mrTemplate->AddVars('content', $data['ruang'],'' );
   }
}
?>