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

class ViewWaktuKuliah extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/waktu_kuliah/template');
      $this->SetTemplateFile('view_waktu_kuliah.html');
   }
   
   function ProcessRequest() {
      $wktKuliahObj = new AppWaktuKuliahToSia();
      $dataWaktuKuliah = $wktKuliahObj->GetDataWaktuKuliah();
	  $totalData = count($dataWaktuKuliah);
	  $itemViewed = $totalData;
      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['dataWaktuKuliah'] = $dataWaktuKuliah;
      return $return;
   }
   
   function ParseTemplate($data = NULL) {
      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('content', 'URL_ADD', Dispatcher::Instance()->GetUrl('waktu_kuliah', 'inputWaktuKuliah', 'view', 'html'));
      if (empty($data['dataWaktuKuliah'])) {
         $this->mrTemplate->AddVar('data_waktu_kuliah', 'WKT_EMPTY', 'YES');
      } else {
         $decPage = Dispatcher::Instance()->Decrypt($_REQUEST['page']);
         $encPage = Dispatcher::Instance()->Encrypt($decPage);
         $this->mrTemplate->AddVar('data_waktu_kuliah', 'WKT_EMPTY', 'NO');
         $dataWaktuKuliah = $data['dataWaktuKuliah'];
      
//mulai bikin tombol delete
         $label = "Manajemen Waktu Kuliah";
         $urlDelete = Dispatcher::Instance()->GetUrl('waktu_kuliah', 'deleteWaktuKuliah', 'do', 'html');
         $urlReturn = Dispatcher::Instance()->GetUrl('waktu_kuliah', 'waktuKuliah', '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'));

         $max = sizeof($dataWaktuKuliah);
		 for ($i=0; $i<$max; $i++) {
			$dataWaktuKuliah[$i]["NUMBER"] = $i+1;
            if($i == 0) $this->mrTemplate->AddVar('content', 'FIRST_NUMBER', $no);            
            if($i == $max-1) $this->mrTemplate->AddVar('content', 'LAST_NUMBER', $no);
            $idEnc = Dispatcher::Instance()->Encrypt($dataWaktuKuliah[$i]['ID']);
            $urlAccept = 'waktu_kuliah|deleteWaktuKuliah|do|html';
            $urlReturn = 'waktu_kuliah|waktuKuliah|view|html';
            $dataWaktuKuliah[$i]['url_edit'] = Dispatcher::Instance()->GetUrl('waktu_kuliah', 'inputWaktuKuliah', 'view', 'html') . '&dataId=' . $idEnc;
            $dataWaktuKuliah[$i]['url_delete'] =  Dispatcher::Instance()->GetUrl('confirm', 'confirmDelete', 'do', 'html').'&urlDelete='. $urlAccept.'&urlReturn='.$urlReturn.'&id='.$dataWaktuKuliah[$i]['ID'].'&label='.$label.'&dataName='.$dataWaktuKuliah[$i]['NAMA'];

            $this->mrTemplate->AddVars('data_waktu_kuliah_item', $dataWaktuKuliah[$i], 'WKT_');
            $this->mrTemplate->parseTemplate('data_waktu_kuliah_item', 'a');    
         }
      }
   }
}
?>
