<?php
    
class attr_datetimereal extends attr {
    function getDBType() {
    	return "datetime";
    }
    
    function render_input() {
		if ($this->getAttrSetting('mand'))
	    		$defval = date('Y-m-d\TH:i:00');
	    	  else 
		    	$defval = '';
		
		$cv = $this->getCurVal();
		    	
	    $tpl = '<input type="datetime-local" class="form-control" name="'.$this->attr_name.'"  id="'.$this->attr_name.'" value="'.($cv?date('Y-m-d\TH:i:s', $cv):$defval).'">';
		return $tpl;
    }
    
    
    function lPost() {
    	$time  = strtotime($_POST[$this->attr_name]);
    	if ( $time == false ) {
    			$time = $_POST[$this->attr_name];
    	}
        
        if (empty($_POST[$this->attr_name]) && !$this->getAttrSetting('mand') ) {
            $time = 0;
        } 
        
       	$this->obj->set($this->attr_name, date('Y-m-d H:i:s', $time));
    }

    function render_text( $crop = false ) {
        if ( $this->getCurVal() ) {
    	    return $this->getCurVal();
        } else {
            return '';
        }
    }
    
}

?>