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

//set Label for module
require_once GTFWConfiguration::GetValue( 'application', 'docroot') .
'module/label/response/Label.proc.class.php';

class ViewInputLelangBarang extends HtmlResponse
{
	function TemplateLabeling(){
      $ObjLabel = new GetModuleLabel();
      $arrLabel = $ObjLabel->GetLabel();
      
      //patTemplate name yang memiliki label2 dinamic
      $arrContent=array("content");
      
      for($i=0;$i<count($arrContent);$i++){
         for($j=0;$j<count($arrLabel);$j++){
            $this->mrTemplate->AddVar($arrContent[$i],$arrLabel[$j]['labelCode'],$arrLabel[$j]['labelName']);
         }
      }
   }
	
   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/pelelangan_barang/template');
      $this->SetTemplateFile('view_input_lelangbarang.html');
   }
   
   function ProcessRequest()
   {
   	$Obj = new LelangBarang();
   	
      // inisialisasi messaging
		$msg = Messenger::Instance()->Receive(__FILE__);
		$this->Data = $msg[0][0];
		$this->Pesan = $msg[0][1];
		$this->css = $msg[0][2];
      // ---------
      
      // inisialisasi default value
      $data = array();
      if (is_array($this->Data))
      {
			$data = $this->Data;
			$defaultDate= $data['tanggalLelang_year']."-".$data['tanggalLelang_mon']."-".$data['tanggalLelang_day'];
      }
      elseif (isset($_GET['idLelangBarang']))
      {
         $result = $Obj->GetDataLelangBarangById ($_GET['idLelangBarang']->Integer()->Raw());
         if ($result === false) 
				unset($_GET['idLelangBarang']);
         else 
				$data = $result[0];
				$data['idLelang']=$_GET['idLelangBarang']->Integer()->Raw();
				$data['barangLelang']=$result;
				$defaultDate=$data['tanggal_lelang'];
      }	
			else 
		{
			$defaultDate=date('Y-m-d');
		}
      
      $return['data'] = $data;
      $return['json']['barang_lelang'] = json_encode($data['barangLelang']);
      unset ($return['data']['barangLelang']);
      // --------
	Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tanggalLelang',
    array($defaultDate, $tglawal, $tglakhir), Messenger::CurrentRequest);
      
		// inisialisasi url
      $return['url']['action'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'inputLelangBarang', 'do', 'html');
      if (isset($_GET['idLelangBarang'])) $return['url']['action'] .= "&id=".$_GET['idLelangBarang'];
      $return['url']['pop_up_barang'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'barang', 'popup', 'html');
      // ---------
      
      return $return;
   }
   
	function ParseTemplate($data = NULL)
   {
      $this->TemplateLabeling();
      
      // render message box
     if ($this->Pesan) {
			$this->mrTemplate->SetAttribute('warning_box', 'visibility', 'visible');
			$this->mrTemplate->AddVar('warning_box', 'ISI_PESAN', $this->Pesan);
		}
      // ---------
	 
      // Render JSON data
      $this->mrTemplate->AddVars('content', $data['json'], 'JSON_');
      // ---------
      
      // Render URL
      $this->mrTemplate->AddVars('content', $data['url'], 'URL_');
      // ---------
      
      // render default form value
		if ($_REQUEST['idLelangBarang']!="") {
			$data['data']['mode'] = "Ubah";
		}
			else 
		{
			$data['data']['mode'] = "Tambah";
			$data['data']['nomorBA']='BAL'.date('mdY-hms');
		}
		
		$this->mrTemplate->AddVars('content', $data['data'], '');
      // ---------
		$this->mrTemplate->AddVar('content', 'URL_KEMBALI', Dispatcher::Instance()->GetUrl('pelelangan_barang', 'lelangBarang', 'view', 'html'));
		$this->mrTemplate->AddVar('content', 'URL_ACTION', Dispatcher::Instance()->GetUrl('pelelangan_barang', 'addLelangBarang', 'do', 'html') . "&id=" . Dispatcher::Instance()->Encrypt($_GET['idLelangBarang']));
		$this->mrTemplate->AddVar('content', 'URL_ADD_MITRAKERJA', Dispatcher::Instance()->GetUrl('pelelangan_barang', 'mitraKerja', 'popup', 'html') );	
		$this->mrTemplate->AddVar('content', 'URL_ADD_INVDET', Dispatcher::Instance()->GetUrl('pelelangan_barang', 'invDet', 'popup', 'html') );	   
   }
}
?>
