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

class PopupSmta extends HtmlResponse {
   
   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/mahasiswa/template');
      $this->SetTemplateFile('popup_smta.html');
   }
   
   function TemplateBase() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application', 'docroot') . 'main/template/');
      $this->SetTemplateFile('document-common-popup.html');
      $this->SetTemplateFile('layout-common-popup.html');
   }      
   
   function ProcessRequest() {   

         if((isset($_POST['propinsi_smta']))or(isset($_POST['kota_smta']))or(isset($_POST['nama_smta']))) {
            $propSmta=$_POST['propinsi_smta'];
            $kotaSmta=$_POST['kota_smta'];
            $namaSmta=$_POST['nama_smta'];

            
         }elseif(isset($_GET['propinsi_smta'])){
            $propSmta= Dispatcher::Instance()->Decrypt($_GET['propinsi_smta']);
            $kotaSmta= Dispatcher::Instance()->Decrypt($_GET['kota_smta']);
            $namaSmta= Dispatcher::Instance()->Decrypt($_GET['nama_smta']);

            
         }else{
            $propSmta="";
            $kotaSmta="";
            $namaSmta="";
         }


     $mhsObj=new AppMahasiswa();
     
      $itemViewed = 20;
      $currPage = 1;
      $startRec = 0 ;
      if(isset($_GET['page'])) {
         $currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();  
         $startRec =($currPage-1) * $itemViewed;
      }
     
      $dataGrid  = $mhsObj->GetSmta($propSmta,$kotaSmta,$namaSmta,$startRec,$itemViewed);
      $totalData = $mhsObj->GetCountSmta($propSmta,$kotaSmta,$namaSmta,$startRec,$itemViewed);
      $dataPropinsi=$mhsObj->GetPropinsi();
      
      $dataKota=$mhsObj->GetKotaByKodePropinsi($propinsi);
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
               Dispatcher::Instance()->mSubModule, 
               Dispatcher::Instance()->mAction, 
               Dispatcher::Instance()->mType).
               '&propinsi_smta='.$propSmta.
               '&kota_smta'.$kotaSmta.
               '&nama_smta'.$namaSmta;
               
      $dest = "popup-subcontent";      
      
      Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', 
         array($itemViewed,$totalData, $url, $currPage, $dest), 
         Messenger::CurrentRequest);       
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'propinsi',
         array('propinsi_smta',$dataPropinsi,$propinsiLahir,'false','onChange="updateComboKotaSmta();" id="prop_smta"'), 
         Messenger::CurrentRequest); 
         
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'kota',
               array('kota_smta',$dataKota,$kota,'false','disabled'), Messenger::CurrentRequest); 

      $return['dataGrid'] = $dataGrid;
      $return['namaSmta']=$namaSmta;
      $return['start'] = $startRec+1;
   
   return $return;
   }
   
   function ParseTemplate($data = NULL) {      

      $this->mrTemplate->AddVar('content', 'NAMA_SMTA', $data['namaSmta']);         
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('mahasiswa', 'smta', 'popup', 'html'));           
          
     
      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');
         }
      }
   } 
}
?>
