<?php

defined('HOSTCMS') || exit('HostCMS: access denied.');

/**
 * Admin forms.
 *
 * @package HostCMS 6\Admin
 * @version 6.x
 * @author Hostmake LLC
 * @copyright © 2005-2012 ООО "Хостмэйк" (Hostmake LLC), http://www.hostcms.ru
 */
class Admin_Form_Entity_DateTime extends Admin_Form_Entity_Input
{
	/**
	 * Constructor.
	 */
	public function __construct()
	{
		parent::__construct();
		
		$this->size(18)
			->class('calendar_field');
	}

	/**
	 * Executes the business logic.
	 */
	public function execute()
	{
		$this->value = $this->value == '0000-00-00 00:00:00' || $this->value == ''
			? ''
			: Core_Date::sql2datetime($this->value);

		$aAttr = $this->getAttrsString();

		$aDefaultDivAttr = array('class' => 'item_div');
		$this->divAttr = Core_Array::union($this->divAttr, $aDefaultDivAttr);
		
		$aDivAttr = array();
		
		// Установим атрибуты div'a.
		if (is_array($this->divAttr))
		{
			foreach ($this->divAttr as $attrName => $attrValue)
			{
				$aDivAttr[] = "{$attrName}=\"" . htmlspecialchars($attrValue) . "\"";
			}
		}

		?><div <?php echo implode(' ', $aDivAttr)?>><?php

		?><span class="caption"><?php echo $this->caption?></span><?php
		?><input <?php echo implode(' ', $aAttr) ?>/>

		<script type="text/javascript">
		(function($) {
			$("#<?php echo $this->id?>")
				.datetimepicker({showOtherMonths: true, selectOtherMonths: true, changeMonth: true, changeYear: true, timeFormat: 'hh:mm:ss'});
		})(jQuery);
		</script><?php

		//$this->_showFormat();
		
		//parent::execute();
		foreach ($this->_children as $oCore_Html_Entity)
		{
			$oCore_Html_Entity->execute();
		}

		?></div><?php
	}
}
