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

class PopupPerguruanTinggi extends HtmlResponse {
   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/mahasiswa/template');
      $this->SetTemplateFile('popup_perguruan_tinggi.html');
   }
   
   function ProcessRequest(){   
         if((isset($_POST['propinsi_pt']))or(isset($_POST['kota_pt']))or(isset($_POST['nama_pt']))) {
            $propPT=$_POST['propinsi_pt'];
            $kotaPT=$_POST['kota_pt'];
            $namaPT=$_POST['nama_pt'];            
         }elseif(isset($_GET['propinsi_pt'])){
            $propPT= Dispatcher::Instance()->Decrypt($_GET['propinsi_pt']);
            $kotaPT= Dispatcher::Instance()->Decrypt($_GET['kota_pt']);
            $namaPT= Dispatcher::Instance()->Decrypt($_GET['nama_pt']);
         }else{
            $propPT="";
            $kotaPT="";
            $namaPT="";
         }            
      
      #$propPT = '01';
      
      $mhsObj=new AppMahasiswaSia();
      
      $itemViewed = 20;
      $currPage = 1;
      $startRec = 0 ;
      if(isset($_GET['page'])) {
         $currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();  
         $startRec =($currPage-1) * $itemViewed;
      }            
      
      $dataGrid  = $mhsObj->GetPerguruanTinggi($kotaPT,$namaPT,$propPT,$startRec,$itemViewed);      
      //print_r($dataGrid);
      $totalData = $mhsObj->GetCountPerguruanTinggi($kotaPT,$namaPT,$propPT);      
      $dataPropinsi=$mhsObj->GetPropinsi();      
      $dataKota=$mhsObj->GetKotaByKodePropinsi($propPT);      
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'propinsi',
         array('propinsi_pt',$dataPropinsi,$propPT,'false','onChange="updateComboKotaPt();" id="prop_pt"'), 
         Messenger::CurrentRequest); 
      if(empty($dataKota))
         $dis="disabled";
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'kota',
               array('kota_pt',$dataKota,$kotaPT,'false',$dis), Messenger::CurrentRequest); 
      
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
               Dispatcher::Instance()->mSubModule, 
               Dispatcher::Instance()->mAction, 
               Dispatcher::Instance()->mType).
               '&propinsi_pt='.$propPT.
               '&kota_pt'.$kotaPT.
               '&nama_pt'.$namaPT;
      
      $dest = "popup-subcontent"; 
      Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', 
         array($itemViewed,$totalData, $url, $currPage, $dest), 
         Messenger::CurrentRequest);       
         
      $return['dataGrid'] = $dataGrid;
      $return['namaPT']=$namaPT;
      $return['start'] = $startRec+1;
      return $return;
   }
   function ParseTemplate($data=null){
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('mahasiswa', 'perguruanTinggi', 'popup', 'html'));           

      $this->mrTemplate->AddVar('content', 'NAMA_PT', $data['namaPT']);  
      if (empty($data['dataGrid'])) {        
         $this->mrTemplate->AddVar('data_grid', 'IS_EMPTY', 'YES');
      } else {
      
         $this->mrTemplate->AddVar('data_grid', 'IS_EMPTY', 'NO');
         $dataGrid = $data['dataGrid'];

         $no=$data['start'];
         for ($i=0; $i<sizeof($dataGrid); $i++) {
            $dataGrid[$i]['no']=$no;
            $no++;
               
            if ($no % 2 != 0) $dataGrid[$i]['class_name'] = 'table-common-even';
            else $dataGrid[$i]['class_name'] = '';
                             
                         
            $this->mrTemplate->AddVars('data_item', $dataGrid[$i], 'DATA_');
            $this->mrTemplate->parseTemplate('data_item', 'a');
         }      
      }
   }
}

?>