<?php
/**
* @package ViewInputUsulanBarang
* @copyright Copyright (c) PT Gamatechno Indonesia
* @Analyzed Dyan Galih <galih@gamatechno.com>
* @version 0.1
* @startDate 2011-01-19
* @lastUpdate 2011-01-19
* @description View Input Usulan Barang
*/

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/pb_usulan/business/Usulan.class.php';

class ViewInputUsulanBarang extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue( 'application', 'docroot').'module/pb_usulan/template');
      $this->SetTemplateFile('view_input_usulan_barang.html');
   }

   function ProcessRequest() {
		
		$Obj = new Usulan;
      
      // 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;
      elseif (isset($_GET['id']))
      {
         $result = $Obj->getDataUsulanBarangById($_GET['id']->Integer()->Raw());
         if ($result === false) unset($_GET['id']);
         else
         {
            $result[0]['filePath'] = "images/usulan/".$result[0]['file'];
            $data = $result[0];
				$dataJson = $result;
         }
      }
      
		if (!isset($data['pic']))
      {
         $data['pic'] = $_SESSION['username'];
      }
		
		if (!isset($data['tanggal']))
      {
         $data['tanggal'] = date('Y-m-d');
      }
		
		Messenger::Instance()->SendToComponent('tanggal', 'Tanggal', 'view', 'html', 'tanggal_usulan',array($data['tanggal'], '2000', date('Y')+1), Messenger::CurrentRequest);
		
		$data['json_detail_barang'] = json_encode((!empty($dataJson)) ? $dataJson : new stdClass);
      unset($dataJson);
		
		$return['url']['unit'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'popupUnit', 'view', 'html');
		$return['url']['action'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'addUsulanBarang', 'do', 'json');
		$return['url']['kodefikasi'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'popupKodefikasi', 'view', 'html');
		$return['url']['back'] = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'usulanBarang', 'view', 'html');
		$return['data'] = $data;
		return $return;
   }

   function ParseTemplate($data = NULL) {
		if(empty($data['data']['usulanId'])){
			$data['data']['label'] = "Input";
		} else {
			$data['data']['label'] = "Edit";
		}
		
		if(empty($data['data']['file'])){
			$data['data']['display'] = "none";
		}
		
      $dataValue = $data['data'];
		$dataUrl = $data['url'];
		
		$this->mrTemplate->AddVar('content', 'FILEOLD', $dataValue['file']);
		$this->mrTemplate->AddVars('content', $dataValue,'');
      $this->mrTemplate->AddVars('content', $dataUrl, 'URL_');
   }
}
?>