00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Varien_Data_Form_Element_Date extends Varien_Data_Form_Element_Abstract
00035 {
00036
00037
00038
00039 protected $_value;
00040
00041 public function __construct($attributes=array())
00042 {
00043 parent::__construct($attributes);
00044 $this->setType('text');
00045 $this->setExtType('textfield');
00046 if (isset($attributes['value'])) {
00047 $this->setValue($attributes['value']);
00048 }
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 public function setValue($value, $format = null, $locale = null)
00062 {
00063 if (empty($value)) {
00064 $this->_value = '';
00065 return $this;
00066 }
00067 if ($value instanceof Zend_Date) {
00068 $this->_value = $value;
00069 return $this;
00070 }
00071 if (preg_match('/^[0-9]+$/', $value)) {
00072 $this->_value = new Zend_Date((int)$value);
00073 return $this;
00074 }
00075
00076 if (null === $format) {
00077 $format = Varien_Date::DATETIME_INTERNAL_FORMAT;
00078 if ($this->getInputFormat()) {
00079 $format = $this->getInputFormat();
00080 }
00081 }
00082
00083 if (null === $locale) {
00084 if (!$locale = $this->getLocale()) {
00085 $locale = null;
00086 }
00087 }
00088 try {
00089 $this->_value = new Zend_Date($value, $format, $locale);
00090 }
00091 catch (Exception $e) {
00092 $this->_value = '';
00093 }
00094 return $this;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104 public function getValue($format = null)
00105 {
00106 if (empty($this->_value)) {
00107 return '';
00108 }
00109 if (null === $format) {
00110 $format = $this->getFormat();
00111 }
00112 return $this->_value->toString($format);
00113 }
00114
00115
00116
00117
00118
00119
00120 public function getValueInstance()
00121 {
00122 if (empty($this->_value)) {
00123 return null;
00124 }
00125 return $this->_value;
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 public function getElementHtml()
00137 {
00138 $this->addClass('input-text');
00139
00140 $html = sprintf(
00141 '<input name="%s" id="%s" value="%s" %s style="width:110px;" />'
00142 .' <img src="%s" alt="" class="v-middle" id="%s_trig" title="%s" style="%s" />',
00143 $this->getName(), $this->getHtmlId(), $this->_escape($this->getValue()), $this->serialize($this->getHtmlAttributes()),
00144 $this->getImage(), $this->getHtmlId(), __('Select Date'), ($this->getDisabled() ? 'display:none;' : '')
00145 );
00146 $outputFormat = $this->getFormat();
00147 if (empty($outputFormat)) {
00148 throw new Exception(__('Output format is not specified. Please, specify "format" key in constructor, or set it using setFormat().'));
00149 }
00150 $displayFormat = Varien_Date::convertZendToStrFtime($outputFormat, true, (bool)$this->getTime());
00151
00152 $html .= sprintf('
00153 <script type="text/javascript">
00154 //<![CDATA[
00155 Calendar.setup({
00156 inputField: "%s",
00157 ifFormat: "%s",
00158 showsTime: %s,
00159 button: "%s_trig",
00160 align: "Bl",
00161 singleClick : true
00162 });
00163 //]]>
00164 </script>',
00165 $this->getHtmlId(), $displayFormat,
00166 $this->getTime() ? 'true' : 'false', $this->getHtmlId()
00167 );
00168
00169 $html .= $this->getAfterElementHtml();
00170
00171 return $html;
00172 }
00173 }