<?php
/**
 * Goweb Sitemanager 5 Framework
 *
 * @version    5.1.3
 * @category   Goweb
 * @package    Zend_View
 * @subpackage Helper
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2010 (c) Goweb (http://www.goweb.pt)
 */

goweb::loadClass('Zend_View_Helper_FormText');

/**
 * Helper to generate a 'text' elements for date separated by day, month and year.
 *
 * @version    5.1.3
 * @category   Goweb
 * @package    Zend_View
 * @subpackage Helper
 * @author     I&D <dev@goweb.pt>, Pedro Pinto <ppinto@goweb.pt>
 * @copyright  2010 (c) Goweb (http://www.goweb.pt)
 */
class Zend_View_Helper_formDateSeparated extends Zend_View_Helper_FormText {
    /**
     * Generates 'text' elements for date separated by day, month and year.
     *
     * @access public
     *
     * @param string $name the element name
     *
     * @param mixed $value The element value.
     *
     * @param array $attribs Attributes for the element tag.
     *
     * @return string The element XHTML.
     */
    public function formDateSeparated($name, $value = null, $attribs = null){
        $return = '<span class="date_separated">';
        Goweb::loadCSS('/admin/media/js/date-picker/css/datepicker.css');
        Goweb::loadJavascript('/admin/media/js/date-picker/js/datepicker.packed.js');
        Goweb::loadCSS('/media/css/date_separated.css');
        if (is_null($attribs) || !isset($attribs['class'])){
            $attribs['class'] = 'date_separated_year split-date fill-grid statusformat-l-cc-sp-d-sp-F-sp-Y show-weeks no-today-button';
        }
        if (isset($attribs['jscalendar'])) unset($attribs['jscalendar']);
        $arrayName = '';
        if (strstr($name, ']')){
            preg_match('/\[(.*)]/', $name, $matches);
            if (isset($matches[0])){
                $arrayName = $matches[0];
                $name = str_replace($arrayName, '', $name);
            }
        }
        $return .= $this->formText($name . $arrayName . '[dia]', $value, array('class' => 'date_separated_day', 'id' => $this->_normalizeId($name . $arrayName) . '-dd'));
        $return .= '<span class="date_separator"></span>';
        $return .= $this->formText($name . $arrayName . '[mes]', $value, array('class' => 'date_separated_month', 'id' => $this->_normalizeId($name . $arrayName) . '-mm'));
        $return .= '<span class="date_separator"></span>';
        $attribs = array_merge(array('id' => $this->_normalizeId($name . $arrayName . '-yyyy')), $attribs);
        $return .= $this->formText($name. $arrayName . '[ano]', $value, $attribs);
        $return .= '</span>';
        return $return;
    }
}