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

class PopupProgramStudi extends HtmlResponse {
   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/mahasiswa/template');
      $this->SetTemplateFile('popup_program_studi.html');
   }
   
   function ProcessRequest(){
      if(isset($_POST['nama_prodi'])){
         //proses dari form cari
         $nama_prodi = $_POST['nama_prodi'];
      }elseif(isset($_GET['nama_prodi'])){
         //buat nangkap variabel search dari paging
         $nama_prodi = Dispatcher::Instance()->Decrypt($_GET['nama_prodi']);
      }else{
         $nama_prodi = "";
      }
      
      $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->GetProgramStudi($nama_prodi,$startRec,$itemViewed);
      $totalDataGrid = $mhsObj->GetCountProgramStudi($nama_prodi);
      $totalDataGrid = $totalDataGrid[0]['BANYAK'];
      
      //bentuk url
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule,Dispatcher::Instance()->mSubModule,Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType.'&nama_prodi='.$nama_prodi);
      $dest = "popup-subcontent"; 
      Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top',array($itemViewed,$totalDataGrid,$url,$currPage,$dest), Messenger::CurrentRequest);
      
      $return['dataGrid'] = $dataGrid;      
      $return['start'] = $startRec+1;
      $return['nama_prodi'] = $nama_prodi;
      return $return;
   }
   
   function ParseTemplate($data=NULL){
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('mahasiswa', 'programStudi', 'popup', 'html'));
      $this->mrTemplate->AddVar('content', 'NAMA_PRODI', $data['nama_prodi']);
      
      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');
         }      
      }         
   }   
}
?>
