<?php
/*
   @ClassName : ViewUnitList
   @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 ViewUnitList extends HtmlResponse {

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

   function ProcessRequest() {
      $objUnit = 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'] = $objUnit->GetUnitList($offset, $limit, $pencarian);

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

      #pagging url
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule,
         Dispatcher::Instance()->mSubModule,
         Dispatcher::Instance()->mAction,
         Dispatcher::Instance()->mType)
         .'&pencarian='.Dispatcher::Instance()->Encrypt($pencarian)
         ;

      $destination_id = "unit-list"; # 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 (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'] = '';
				$dataList[$i]['unitkerjaNama'] = addslashes($dataList[$i]['unitkerjaNama']);
            $this->mrTemplate->AddVars('data_item', $dataList[$i], '');
            $this->mrTemplate->parseTemplate('data_item', 'a');
         }
      }
   }
}
?>