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

class ViewGelombang extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/gelombang/template');
      $this->SetTemplateFile('view_gelombang.html');
   }
   
   function ProcessRequest() {
      $gelombangObj = new AppGelombangToAdmisi();
      if($_POST || isset($_GET['cari'])) {
         if(isset($_POST['gelombang'])) {
            $gelombang = $_POST['gelombang'];
         } elseif(isset($_GET['gelombang'])) {
            $gelombang = Dispatcher::Instance()->Decrypt($_GET['gelombang']);
         } else {
            $gelombang = '';
         }
      }
      
      
   //view
      $totalData = $gelombangObj->GetCountDataGelombang($gelombang);
      $itemViewed = 20;
      $currPage = 1;
      $startRec = 0 ;
      if(isset($_GET['page'])) {
         $currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
         $startRec =($currPage-1) * $itemViewed;
      }
      $dataGelombang = $gelombangObj->getDataGelombang($startRec, $itemViewed, $gelombang);
//      print_r($dataGelombang);
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType . '&gelombang=' . Dispatcher::Instance()->Encrypt($gelombang) . '&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['dataGelombang'] = $dataGelombang;
      $return['start'] = $startRec+1;

      $return['search']['gelombang'] = $gelombang;
      return $return;
   }
   
   function ParseTemplate($data = NULL) {
      $search = $data['search'];
      $this->mrTemplate->AddVar('content', 'GELOMBANG', $search['gelombang']);
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('gelombang', 'gelombang', 'view', 'html'));
      $this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('gelombang', 'inputGelombang', '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 (empty($data['dataGelombang'])) {
         $this->mrTemplate->AddVar('data_gelombang', 'GELOMBANG_EMPTY', 'YES');
      } else {
         $decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
         $encPage = Dispatcher::Instance()->Encrypt($decPage);
         $this->mrTemplate->AddVar('data_gelombang', 'GELOMBANG_EMPTY', 'NO');
         $dataGelombang = $data['dataGelombang'];
      
//mulai bikin tombol delete
         $label = "Manajemen Gelombang";
         $urlDelete = Dispatcher::Instance()->GetUrl('gelombang', 'deleteGelombang', 'do', 'html');
         $urlReturn = Dispatcher::Instance()->GetUrl('gelombang', 'gelombang', '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($dataGelombang); $i++) {
            $no = $i+$data['start'];
            $dataGelombang[$i]['number'] = $no;
            if ($no % 2 != 0) $dataGelombang[$i]['class_name'] = 'table-common-even';
            else $dataGelombang[$i]['class_name'] = '';
            
            if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);            
            if($i == sizeof($dataGelombang)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
            $idEnc = Dispatcher::Instance()->Encrypt($dataGelombang[$i]['gelombang_id']);
            $urlAccept = 'gelombang|deleteGelombang|do|html-cari-'.$cari;
            $urlReturn = 'gelombang|gelombang|view|html-cari-'.$cari;
            $dataGelombang[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('gelombang', 'inputGelombang', 'view', 'html') . '&dataId=' . $idEnc . '&page=' . $encPage . '&cari='.$cari;
            $dataGelombang[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataGelombang[$i]['gelombang_id'].'&label='.$label.'&dataName='.$dataGelombang[$i]['gelombang_nama'];

            $this->mrTemplate->AddVars('data_gelombang_item', $dataGelombang[$i], 'GELOMBANG_');
            $this->mrTemplate->parseTemplate('data_gelombang_item', 'a');    
         }
      }
   }
}
?>
