<?php

/*
@ClassName : ViewPenggunaanRuang
@Copyright : PT Gamatechno Indonesia
@Analyzed By : Nanang Ruswianto <nanang@gamatechno.com>
@Author By : Dyan Galih <galih@gamatechno.com>
@Version : 0.1
@StartDate : 2010-06-18
@LastUpdate : 2010-06-18
@Description :
*/
require_once GTFWConfiguration::GetValue('application', 'docroot') . 'module/penggunaan_ruang/business/PenggunaanRuang.class.php';

class ViewPenggunaanRuang extends HtmlResponse
{
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'module/penggunaan_ruang/template');
      $this->SetTemplateFile('view_penggunaan_ruang.html');
   }
   function ProcessRequest()
   {
      $msg = Messenger::Instance()->Receive(__FILE__);
      $return['data'] = $msg['0']['0'];
      $return['message'] = $msg['0']['1'];
      $return['css'] = $msg['0']['2'];

      $today = date("Y-m-d");

      if ($_POST->AsArray() == '')
      {
         $tglAwal = $today;
         $tglAkhir = $today;
			$search = $_POST['search']->Raw();
      }
      elseif ($_GET->AsArray() == '')
      {
         $tglAwal = $_GET['tgl_awal_year'] . '-' . $_GET['tgl_awal_mon'] . '-' . $_GET['tgl_awal_day'];
         $tglAkhir = $_GET['tgl_akhir_year'] . '-' . $_GET['tgl_akhir_mon'] . '-' . $_GET['tgl_akhir_day'];
         $search = $_GET['search']->AsArray();
      }
      else
      {
         $tglAwal = $_POST['tgl_awal_year'] . '-' . $_POST['tgl_awal_mon'] . '-' . $_POST['tgl_awal_day'];
         $tglAkhir = $_POST['tgl_akhir_year'] . '-' . $_POST['tgl_akhir_mon'] . '-' . $_POST['tgl_akhir_day'];
         $search = $_POST['search']->Raw();
      }
      $objPengRuang = new PenggunaanRuang();

      #set default pagging
      $limit = 20;
      $page = 0;
      $offset = 0;

      if (isset($_GET['page']))
      {
         $page = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
         $offset = ($page - 1) * $limit;
      }

      #fetch data
      $return['data'] = $objPengRuang->GetListPenggunaanRuang($tglAwal, $tglAkhir, $search);

      #fethc numrows
      $numrows = $objPengRuang->GetCount(); // fetch here;

      #pagging url

      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType) . '&tgl_awal_year=' . Dispatcher::Instance()->Encrypt($_POST['tgl_awal_year']) . '&tgl_awal_mon=' . Dispatcher::Instance()->Encrypt($_POST['tgl_awal_mon']) . '&tgl_awal_day=' . Dispatcher::Instance()->Encrypt($_POST['tgl_awal_day']) . '&tgl_akhir_year=' . Dispatcher::Instance()->Encrypt($_POST['tgl_akhir_year']) . '&tgl_akhir_mon=' . Dispatcher::Instance()->Encrypt($_POST['tgl_akhir_mon']) . '&tgl_akhir_day=' . Dispatcher::Instance()->Encrypt($_POST['tgl_akhir_day']) . '&search=' . Dispatcher::Instance()->Encrypt($_POST['search']);
      $destination_id = "subcontent-element"; # options: {popup-subcontent,subcontent-element}

      #send data to pagging component

      Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array(
         $limit,
         $numrows,
         $url,
         $page,
         $destination_id
      ) , Messenger::CurrentRequest);

      #send data to parse method
      $return['start'] = $offset + 1;
      $return['page'] = $page;
      $return['numrows'] = $numrows;

      return $return;
   }
   function ParseTemplate($data = NULL)
   {

      if($data['message']!=''){
         $this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
         $this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $data['message']);
         $this->mrTemplate->AddVar('warning_box', 'CLASS_PESAN', $data['css']);
      }

      if (empty($data['data']))
      {
         $this->mrTemplate->AddVar('data_grid', 'DATA_EMPTY', 'YES');
      }
      else
      {
         $this->mrTemplate->AddVar('data_grid', 'DATA_EMPTY', 'NO');
         $dataList = $data['data'];

         for ($i = 0;$i < sizeof($dataList);$i++)
         {
            $no = $i + $data['start'];
            $dataList[$i]['no'] = $no;

            if ($no % 2 != 0) $dataList[$i]['class_name'] = 'table-common-even';
            else $dataList[$i]['class_name'] = '';
            $urlAccept = 'penggunaan_ruang|DeletePenggunaanRuang|Do|html-cari-' . $cari;
            $urlReturn = 'penggunaan_ruang|SearchPenggunaanRuang|view|html-' . $cari;
            $label = 'Delete List Penggunaan Ruang';
            $dataName = $dataList[$i]['ruangKode'];
            $idEnc = $dataList[$i]['rupengId'];
            $dataList[$i]['url_delete'] = Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html') . '&urlDelete=' . $urlAccept . '&urlReturn=' . $urlReturn . '&id=' . $idEnc . '&label=' . $label . '&dataName=' . $dataName;
				if($dataList[$i]['rupengTglSelesai'].' '.$dataList[$i]['rupengJamSelesai'] <= date('Y-m-d H:i:s')){
					$dataList[$i]['class_name'] = 'table-common-warning';
				}
            $dataList[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('penggunaan_ruang', 'InputPenggunaanRuang', 'View', 'html').'&id='.Dispatcher::Instance()->Encrypt($dataList[$i]['rupengId']);

            $this->mrTemplate->AddVars('data_item', $dataList[$i], '');
            $this->mrTemplate->parseTemplate('data_item', 'a');
         }
      }
      $urlTambah = Dispatcher::Instance()->GetUrl('penggunaan_ruang', 'InputPenggunaanRuang', 'View', 'html');
		$urlRtf = Dispatcher::Instance()->GetUrl('penggunaan_ruang', 'rtfPenggunaanRuang', 'print', 'html');
		$urlXls = Dispatcher::Instance()->GetUrl('penggunaan_ruang', 'xlsPenggunaanRuang', 'print', 'xls');
      $this->mrTemplate->AddVar('content', 'URL_TAMBAH', $urlTambah);
		$this->mrTemplate->AddVar('content', 'URL_RTF', $urlRtf);
		$this->mrTemplate->AddVar('content', 'URL_XLS', $urlXls);
   }
}
?>