00001 <?php
00010 class form_range_date extends form_range_abstract {
00011
00017 protected $dates = array();
00018
00024 protected $set = array('min'=>false, 'max'=>false);
00025
00026 protected function afterInit() {
00027 parent::afterInit();
00028 $this->dates = array(
00029 'min'=>factory::getHelper('date', array(
00030 'timestamp'=>$this->getValue('min') ? strtotime($this->getValue('min')) : $this->cfg->defaultDate,
00031 'defaultFormat'=>array(
00032 'type'=>'date',
00033 'len'=>'mysql'
00034 )
00035 )),
00036 'max'=>factory::getHelper('date', array(
00037 'timestamp'=>$this->getValue('max') ? strtotime($this->getValue('max')) : $this->cfg->defaultDate+$this->cfg->defaultRange,
00038 'defaultFormat'=>array(
00039 'type'=>'date',
00040 'len'=>'mysql'
00041 )
00042 ))
00043 );
00044 }
00045
00046 public function setValue($value, $refill=false, $key=null) {
00047 $value = utils::htmlOut($value);
00048 if (is_array($value)) {
00049 $min = array_key_exists('min', $value)? $value['min'] : (array_key_exists(0, $value)? $value[0] : null);
00050 $max = array_key_exists('max', $value)? $value['max'] : (array_key_exists(1, $value)? $value[1] : null);
00051 $this->setValue($min, $refill, 'min');
00052 $this->setValue($max, $refill, 'max');
00053 } else if (!is_null($key)) {
00054 if ($refill)
00055 $this->dates[$key]->set($value, 'formatDate', 'short2');
00056 else
00057 $this->dates[$key]->set($value);
00058 $this->cfg->setInArray('rangeValue', $key, $this->dates[$key]->format());
00059 $this->cfg->setInArray('value', $key, $value);
00060 $this->set[$key] = true;
00061 }
00062 }
00063
00064 public function getValue($key=null, $mode='raw') {
00065 if (!is_null($key)) {
00066 if ($mode == 'input') {
00067 $ret = $this->set[$key]? $this->dates[$key]->format('date', 'short2') : null;
00068 } else
00069 $ret = $this->cfg->getInArray('rangeValue', $key);
00070 } else
00071 $ret = $this->rangeValue;
00072 return utils::htmlDeOut($ret);
00073 }
00074
00075 public function toHtml() {
00076 if ($this->cfg->useJs) {
00077 $this->cfg->setInArray('html', 'class', $this->cfg->getInArray('html', 'class').' date');
00078 $resp = response::getInstance();
00079 $resp->addJs('jqueryui');
00080 if (($lang = request::get('lang')) != 'en')
00081 $resp->addJs('i18n_ui.datepicker-'.$lang);
00082 $dateImg = utils::getIcon(array(
00083 'name'=>'show_month',
00084 'type'=>'calendar',
00085 'imgTag'=>false
00086 ));
00087
00088 $minId = $this->makeId($this->name.'[0]');
00089 $maxId = $this->makeId($this->name.'[1]');
00090
00091 $minDate = $this->dates['min']->getJs(null);
00092 $maxDate = $this->dates['max']->getJs(null);
00093
00094 $resp->blockJquery('$("#'.$minId.'").datepicker({
00095 buttonImage: "'.$dateImg.'", buttonImageOnly: true, showOn: "both", '.($maxDate?'maxDate: '.$maxDate.',' : null).'
00096 onSelect: function(dateText) {$("#'.$maxId.'").datepicker("option", "minDate", $("#'.$minId.'").datepicker("getDate"));}
00097 });');
00098 $resp->blockJquery('$("#'.$maxId.'").datepicker({
00099 buttonImage: "'.$dateImg.'", buttonImageOnly: true, showOn: "both", '.($minDate?'minDate: '.$minDate.',' : null).'
00100 onSelect: function(dateText) {$("#'.$minId.'").datepicker("option", "maxDate", $("#'.$maxId.'").datepicker("getDate"));}
00101 });');
00102 }
00103
00104 return parent::toHtml();
00105 }
00106
00107 public function toXul() {
00108 return '<textbox type="number" id="'.$this->name.'" value="'.$this->value.'" min="'.$this->min.'" max="'.$this->max.'" increment="'.$this->step.'" '.utils::htmlAttribute($this->more).'/>';
00109 }
00110
00111 }