<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/program_studi/business/AppProgramStudiToAdmisi.class.php';
class ViewProgramStudi extends HtmlResponse{
   
   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/program_studi/template');
      $this->SetTemplateFile('view_program_studi.html');
   }
   
   function ProcessRequest(){
         $prodiObj=new AppProgramStudiToAdmisi();


      if($_POST || isset($_GET['cari'])) {
         if((isset($_POST['kode_prodi']))or (isset($_POST['nama_prodi']))or (isset($_POST['jenjang']))or (isset($_POST['kode_prodi_univ']))or (isset($_POST['ekstakta']))or (isset($_POST['model']))) {
            $kodeProdi = $_POST['kode_prodi'];
            $kodeProdiUniv=$_POST['kode_prodi_univ'];
            $namaProdi=$_POST['nama_prodi'];
            $jurusan=$_POST['jurusan'];
            $jenjang=$_POST['jenjang'];
            $ekstakta=$_POST['ekstakta'];
            $model=$_POST['model'];
         } elseif((isset($_GET['kode_prodi']))or (isset($_GET['nama_prodi']))or (isset($_GET['jenjang']))or (isset($_GET['ekstakta']))or (isset($_GET['model']))) {
            $kodeProdi = Dispatcher::Instance()->Decrypt($_GET['kode_prodi']);
            $kodeProdiUniv = Dispatcher::Instance()->Decrypt($_GET['kode_prodi_univ']);
            $namaProdi = Dispatcher::Instance()->Decrypt($_GET['nama_prodi']);
            $jurusan = Dispatcher::Instance()->Decrypt($_GET['jurusan']);
            $jenjang = Dispatcher::Instance()->Decrypt($_GET['jenjang']);
            $ekstakta = Dispatcher::Instance()->Decrypt($_GET['ekstakta']);
            $model = Dispatcher::Instance()->Decrypt($_GET['model']);
         } else {
            $kodeProdi = '';
            $kodeProdiUniv = '';
            $kodeUniv ='';
            $namaProdi ='';
            $jurusan ='';
            $jenjang = '';
            $ekstakta='';
            $model='';
         }
      }

      if($ekstakta=='all'){
         $ekstakta='';
      }
      
      if($jurusan=='all'){
         $jurusan='';
      }
      
      if($jenjang=='all'){
         $jenjang='';
      }
      
      if($model=='all'){
         $model='';
      }
      
      $totalData = $prodiObj->GetCountDataProgramStudi($kodeProdi,$kodeProdiUniv,$namaProdi,$jenjang,$ekstakta,$model,$jurusan);

      $itemViewed = 20;
      $currPage = 1;
      $startRec = 0 ;
      if(isset($_GET['page'])) {
         $currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
         $startRec =($currPage-1) * $itemViewed;
      }

      $dataProdi=$prodiObj->GetDataProgramStudi($kodeProdi,$kodeProdiUniv,$namaProdi,$jenjang,$ekstakta,$model,$jurusan,$startRec,$itemViewed);

      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 
               Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, 
               Dispatcher::Instance()->mType . '&kode_prodi=' . Dispatcher::Instance()->Encrypt($kodeProdi) . 
               '&nama_prodi=' . Dispatcher::Instance()->Encrypt($namaProdi) . 
               '&jenjang=' . Dispatcher::Instance()->Encrypt($jenjang) . 
               '&cari=' . Dispatcher::Instance()->Encrypt(1));
      
      Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', 
            array($itemViewed,$totalData, $url, $currPage), Messenger::CurrentRequest);

      $dataComboJenjang=$prodiObj->GetDataJenjangAkademik();
  
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jenjang',
            array('jenjang',$dataComboJenjang,$jenjang,'true',''), Messenger::CurrentRequest);
      
      $dataModel=$prodiObj->GetDataModel();      

      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'model',
         array('model',$dataModel,$model,'true',''), Messenger::CurrentRequest);      
      
      $dataComboJur=$prodiObj->GetJurusan();
      
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jurusan',
         array('jurusan',$dataComboJur,$jurusan,'true',''), Messenger::CurrentRequest);
         
      $dataKelompok=$prodiObj->GetKelompok();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'ekstakta',
         array('ekstakta',$dataKelompok,$ekstakta,'true',''), Messenger::CurrentRequest);

      $msg = Messenger::Instance()->Receive(__FILE__);

      $return['pesan']=$msg[0][1];
      $return['css']=$msg[0][2];
      $return['dataProdi']=$dataProdi;
      $return['search']['kodeProdi']=$kodeProdi;
      $return['search']['kodeProdiUniv']=$kodeProdiUniv;
      $return['search']['namaProdi']=$namaProdi;
      $return['search']['jenjangAkademik']=$jenjangAkademik;
      $return['search']['ekstakta']=$ekstakta;
      $return['start'] = $startRec+1;
      return $return;
   }

   function ParseTemplate($data = NULL) {
      $search=$data['search'];

      $this->mrTemplate->AddVar('content', 'KODE_PRODI', $search['kodeProdi']);
      $this->mrTemplate->AddVar('content', 'KODE_PRODI_UNIV', $search['kodeProdiUniv']);
      $this->mrTemplate->AddVar('content', 'NAMA_PRODI', $search['namaProdi']);
      $this->mrTemplate->AddVar('content', 'JENJANG_AKADEMIK', $search['jenjangAkademik']);
      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl('program_studi', 'programStudi', 'view', 'html'));
      $this->mrTemplate->AddVar('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('program_studi', 'inputProgramStudi', '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['dataProdi'])) {
         $this->mrTemplate->AddVar('data_prodi', 'PRODI_EMPTY', 'YES');
      } else {
         $decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
         $encPage = Dispatcher::Instance()->Encrypt($decPage);
         $this->mrTemplate->AddVar('data_prodi', 'PRODI_EMPTY', 'NO');
         $dataProdi = $data['dataProdi'];

         $label = "Data Program Studi";
         
         $urlDelete = Dispatcher::Instance()->GetUrl('program_studi', 'deleteProgramStudi', 'do', 'html');
         $urlReturn = Dispatcher::Instance()->GetUrl('program_studi', 'programStudi', '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($dataProdi); $i++) {
            $no = $i+$data['start'];
            $dataProdi[$i]['number'] = $no;
            if ($no % 2 != 0) $dataProdi[$i]['class_name'] = 'table-common-even';
            else $dataProdi[$i]['class_name'] = '';
            
            if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);            
            if($i == sizeof($dataProdi)-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
            $idEnc = Dispatcher::Instance()->Encrypt($dataProdi[$i]['kode_prodi']);
            $urlAccept = 'program_studi|deleteProgramStudi|do|html-cari-'.$cari;
            $urlReturn = 'program_studi|programStudi|view|html-cari-'.$cari;

            $dataProdi[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('program_studi', 'inputProgramStudi', 'view', 'html') . '&dataId=' . $idEnc. '&page=' . $encPage  ;
            $dataProdi[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataProdi[$i]['kode_prodi'].'&label='.$label.'&dataName='.$dataProdi[$i]['nama_prodi'].' ('.$dataProdi[$i]['kode_prodi'].')';
            
            if (empty($dataProdi[$i]['user_ubah'])and empty($dataProdi[$i]['tgl_ubah'])){
               $dataProdi[$i]['keterangan']="";
            }else{
               $dataProdi[$i]['keterangan']=$dataProdi[$i]['user_ubah']." (".$dataProdi[$i]['tgl_ubah'].")";
            }
            $nameConfirm=$dataProdi[$i]['nama_prodi'].' ('.$dataProdi[$i]['kode_prodi'].')';
            $dataProdi[$i]['name_confirm']=$nameConfirm;
            $this->mrTemplate->AddVars('data_prodi_item', $dataProdi[$i], 'PRODI_');
            $this->mrTemplate->parseTemplate('data_prodi_item', 'a');    
         }
      }
   }
}
?>
