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

class ViewJenisSemester extends HtmlResponse {
   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/jenis_semester/template');
      $this->SetTemplateFile('view_jenis_semester.html');
   }
   function ProcessRequest(){
      $jSemsObj=new AppJenisSemesterToSia();
      $totalData = $jSemsObj->GetCountJenisSemester();
      if(!$jSemsObj->addConn)
         $return['siaConn']=false;
      else
         $return['siaConn']=true;
      $itemViewed = 10;
      $currPage = 1;
      $startRec = 0 ;
      if(isset($_GET['page'])) {
         $currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
         $startRec =($currPage-1) * $itemViewed;
      }
      
      $dataJSems=$jSemsObj->GetDataJenisSemeter($startRec, $itemViewed);
      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType .'&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['dataJSems'] = $dataJSems;
      $return['start'] = $startRec+1;
      return $return;
   }
   
   function ParseTemplate($data=null){
      $dataJSems=$data['dataJSems'];
      $siaConn=$data['siaConn'];
      if($siaConn==false){
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'NO');
         $this->mrTemplate->AddVar('warning', 'ISI_PESAN_SIA', 'Gagal Menghubungi SI Akademik');
      }elseif($siaConn==true){
         $this->mrTemplate->AddVar('status_koneksi', 'BERHASIL', 'YES');
      }
      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']);
      }
      
      $this->mrTemplate->AddVar('status_koneksi', 'URL_ADD', Dispatcher::Instance()->GetUrl('jenis_semester', 'inputJenisSemester', 'view', 'html'));

      if (empty($dataJSems)) {
         $this->mrTemplate->AddVar('data_jenis_semester', 'J_SEMESTER_EMPTY', 'YES');
      } else {
         $decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
         $encPage = Dispatcher::Instance()->Encrypt($decPage);
         $this->mrTemplate->AddVar('data_jenis_semester', 'J_SEMESTER_EMPTY', 'NO');

         $label = "Data Jenis Semester";
         $urlDelete = Dispatcher::Instance()->GetUrl('jenis_semester', 'deleteJenisSemester', 'do', 'html');
         $urlReturn = Dispatcher::Instance()->GetUrl('jenis_semester', 'jenisSemester', 'view', 'html');
         Messenger::Instance()->Send('confirm', 'confirmDelete', 'do', 'html', array($label, $urlDelete, $urlReturn),Messenger::NextRequest);
         $this->mrTemplate->AddVar('status_koneksi', 'URL_DELETE', Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html'));

         for ($i=0; $i<sizeof($dataJSems); $i++) {
            $no = $i+$data['start'];
            $dataJSems[$i]['number'] = $no;

            if ($no % 2 != 0) $dataJSems[$i]['class_name'] = 'table-common-even';
            else $dataJSems[$i]['class_name'] = '';
            
            if($i == 0) $this->mrTemplate->AddVar('status_koneksi', 'FIRST_NUMBER', $no);            
            if($i == sizeof($dataJSems)-1) $this->mrTemplate->AddVar('status_koneksi', 'LAST_NUMBER', $no);
            $idEnc = Dispatcher::Instance()->Encrypt($dataJSems[$i]['sems_id']);
            $urlAccept = 'jenis_semester|deleteJenisSemester|do|html-cari-'.$cari;
            $urlReturn = 'jenis_semester|jenisSemester|view|html-cari-'.$cari;
            $dataJSems[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('jenis_semester', 'inputJenisSemester', 'view', 'html') . '&dataId=' . $idEnc . '&page=' . $encPage ;

            $dataJSems[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$idEnc.'&label='.$label.'&dataName='.$dataJSems[$i]['sems_label'];                                                                             
            $this->mrTemplate->AddVars('data_jenis_semester_item', $dataJSems[$i], 'JSEMS_');
            $this->mrTemplate->parseTemplate('data_jenis_semester_item', 'a');    
         }
      }
   }
}
?>