<?php

CLASS BasicSetting extends RasioProject
{
	protected $set;
	protected $enableCk = true;

	public function __construct($config)
	{
		$this->getConfig($config);
		$this->validation();
		$this->set();
	}

	protected function set()
	{
		$this->set->em 			= $this->em;
		$this->set->modul 		= 'Setting';
		$this->set->dBaseH 		= 'setting';
		$this->set->dBaseD 		= false;
		$this->set->dBasePk 	= array('id_setting');
		$this->set->dSort 		= 'asc';
		$this->set->form 		= $this->setForm();
		$this->set->clearForm 	= array();
		$this->set->notNull 	= array("id_1");
		$this->set->button 		= array("Save", "Edit");
		$this->set->addClear 	= true;
		return $this->set;
	}
	
	protected function setForm()
	{
		$tgl = $this->em->getFind("setting", "*", array("id_setting = '1'")); 
		
		$form[] = array('row' => 0, 'col' => 25, "label" => array("name" => "Tanggal Kunci", "width" => 100), "input" => array("type" => 'text',	'attr' => array("name" => 'id_1', "size" => 10, "class" => 'tanggal', 'value' => date("d/m/Y", strtotime($tgl->value)))));
		
		
		
		return $form;
	}
	
	
	public function Index()
	{
		$this->data = $this->set;
		$this->view = "default/index";
	}
	
	
	protected function validasi()
	{
		$basic = new Basic;
		$error[] = $basic->validasiBasic($_POST, $this->set, false);
		
		$date = new Date;
		$tgl = $date->serialDate($_POST['id_1']);
		$tgl = date("Y-m-d", strtotime($tgl));
		if($tgl == '1970-01-01'){
			echo "<script>$('#_displayErrorPopUp').html('Tanggal Tidak di kenal')</script>";
			$error[] = false;
		}
		
		return $basic->getError($error);
	}
	
	public function proses()
	{
		$basic = new Basic;
		$validasi = $this->validasi();
		if($validasi == true){
			
			$date = new Date;
			$tgl = $date->serialDate($_POST['id_1']);
			$tgl = date("d-M-Y", strtotime($tgl));
			
			$basic = new Basic;
			$sql = $this->em->addUpdate($this->set->dBaseH);
			$sql = $this->em->addAttrUp(array("value" => $tgl));
			$sql = $this->em->getWhere("id_setting = '1'");

			$qb = array();
			$qb[] = $sql;
			$qb[] = $basic->getRecord($_POST, $this->set, array(), $qb);
			$save = $this->em->getFlush($qb);
			
			if($save != false){
				echo "<script>";
				echo "alert('Proses Sukses');";
				echo "window.location = ''";
				echo "</script>";
			}else{
				echo "<script>$('#_displayErrorPopUp').html('Error! Silahkan Coba Lagi')</script>";
			}
			
		}
		$this->layout = "null";
	}
}