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
00035 class Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Datetime extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Date
00036 {
00037
00038 const END_OF_DAY_IN_SECONDS = 86399;
00039
00040 public function getValue($index=null)
00041 {
00042 if ($index) {
00043 if ($data = $this->getData('value', 'orig_'.$index)) {
00044 return $data;
00045 }
00046 return null;
00047 }
00048 $value = $this->getData('value');
00049 if (is_array($value)) {
00050 $value['datetime'] = true;
00051 }
00052 if (!empty($value['to']) && !$this->getColumn()->getFilterTime()) {
00053 $datetimeTo = $value['to'];
00054
00055 $datetimeTo->addSecond(self::END_OF_DAY_IN_SECONDS);
00056 }
00057 return $value;
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067 protected function _convertDate($date, $locale)
00068 {
00069 if ($this->getColumn()->getFilterTime()) {
00070 try {
00071 $dateObj = $this->getLocale()->date(null, null, $locale, false);
00072
00073
00074 $dateObj->setTimezone(Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE));
00075
00076
00077 $dateObj->set(
00078 $date,
00079 $this->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
00080 $locale
00081 );
00082
00083
00084 $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
00085
00086 return $dateObj;
00087 }
00088 catch (Exception $e) {
00089 return null;
00090 }
00091 }
00092
00093 return parent::_convertDate($date, $locale);
00094 }
00095
00096
00097
00098
00099
00100
00101 public function getHtml()
00102 {
00103 $htmlId = $this->_getHtmlId() . microtime(true);
00104 $format = $this->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
00105
00106 if ($this->getColumn()->getFilterTime()) {
00107 $format .= ' ' . $this->getLocale()->getTimeStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
00108 }
00109
00110 $html = '<div class="range"><div class="range-line date">
00111 <span class="label">' . Mage::helper('adminhtml')->__('From').':</span>
00112 <input type="text" name="'.$this->_getHtmlName().'[from]" id="'.$htmlId.'_from" value="'.$this->getEscapedValue('from').'" class="input-text no-changes"/>
00113 <img src="' . Mage::getDesign()->getSkinUrl('images/grid-cal.gif') . '" alt="" class="v-middle" id="'.$htmlId.'_from_trig" title="'.$this->htmlEscape(Mage::helper('adminhtml')->__('Date selector')).'"/>
00114 </div>';
00115 $html.= '<div class="range-line date">
00116 <span class="label">' . Mage::helper('adminhtml')->__('To').' :</span>
00117 <input type="text" name="'.$this->_getHtmlName().'[to]" id="'.$htmlId.'_to" value="'.$this->getEscapedValue('to').'" class="input-text no-changes"/>
00118 <img src="' . Mage::getDesign()->getSkinUrl('images/grid-cal.gif') . '" alt="" class="v-middle" id="'.$htmlId.'_to_trig" title="'.$this->htmlEscape(Mage::helper('adminhtml')->__('Date selector')).'"/>
00119 </div></div>';
00120 $html.= '<input type="hidden" name="'.$this->_getHtmlName().'[locale]" value="'.$this->getLocale()->getLocaleCode().'"/>';
00121 $html.= '<script type="text/javascript">
00122 Calendar.setup({
00123 inputField : "'.$htmlId.'_from",
00124 ifFormat : "'.$format.'",
00125 button : "'.$htmlId.'_from_trig",
00126 showsTime: '. ( $this->getColumn()->getFilterTime() ? 'true' : 'false') .',
00127 align : "Bl",
00128 singleClick : true
00129 });
00130 Calendar.setup({
00131 inputField : "'.$htmlId.'_to",
00132 ifFormat : "'.$format.'",
00133 button : "'.$htmlId.'_to_trig",
00134 showsTime: '. ( $this->getColumn()->getFilterTime() ? 'true' : 'false') .',
00135 align : "Bl",
00136 singleClick : true
00137 });
00138 </script>';
00139 return $html;
00140 }
00141
00142
00143
00144
00145
00146
00147
00148 public function getEscapedValue($index=null)
00149 {
00150 if ($this->getColumn()->getFilterTime()) {
00151 $value = $this->getValue($index);
00152 if ($value instanceof Zend_Date) {
00153 return $value->toString($this->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
00154 }
00155 return $value;
00156 }
00157
00158 return parent::getEscapedValue($index);
00159 }
00160
00161 }