[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/options/form/field_types/date/ -> date.php (source)

   1  <?php
   2  class MP_Form_field_type_date extends MP_form_field_type_
   3  {
   4      var $file            = __FILE__;
   5  
   6      var $id            = 'date';
   7      var $field_not_input     = true;
   8  
   9      var $category = 'composite';
  10      var $order            = 70;
  11  
  12  	function get_name($field) { return $this->prefix.'['.$field->form_id . ']['. $field->id . ']' . ( (isset($field->settings['options']['is'])) ? '[' . $field->settings['options']['is'] . ']' : '' ); }
  13  	function get_id($field)   { return $this->prefix  .  $field->form_id . '_' . $field->id .       ( (isset($field->settings['options']['is'])) ? '_' . $field->settings['options']['is'] : '' ); }
  14  	public static function valid_date($y, $m, $d) { $feb = ((($y % 4 == 0) && ( (!($y % 100 == 0)) || ($y % 400 == 0))) ? 29 : 28 );  $maxd = array(31,$feb,31,30,31,30,31,31,30,31,30,31); if ($d > $maxd[$m - 1]) return false; return true; }
  15  
  16  	function submitted($field)
  17      {
  18          $value    = $_POST[$this->prefix][$field->form_id][$field->id];
  19  
  20          $required     = (isset($field->settings['controls']['required']) && $field->settings['controls']['required']);
  21          $empty     = ( empty($value['y']) || empty($value['m']) || empty($value['d']) );
  22  
  23          if ($required && $empty)
  24          {
  25              $field->submitted['on_error'] = 1;
  26              return $field;
  27          }
  28          if (!$empty)
  29          {
  30              if (!self::valid_date( $value['y'], $value['m'], $value['d']))
  31              {
  32                  $field->submitted['on_error'] = 1;
  33                  return $field;
  34              }
  35          }
  36  
  37          $format = $field->settings['options']['mail_date_format'];
  38          if (empty($format)) $format = get_option('date_format');
  39  
  40          $field->submitted['value'] = $value;
  41          $field->submitted['text']  =  mysql2date($format, mktime(0, 0, 0, $value['m'], $value['d'], $value['y'] ));
  42  
  43          return $field;
  44      }
  45  
  46  	function attributes_filter($no_reset)
  47      {
  48          $this->field->settings['options']['is'] = 'y';
  49          $id_y = $this->get_id($this->field);
  50  
  51          $this->field->settings['options']['is'] = 'm';
  52          $id_m = $this->get_id($this->field);
  53  
  54          $this->field->settings['options']['is'] = 'd';
  55          $id_d = $this->get_id($this->field);
  56  
  57          $onchange = "var y=document.getElementById('" . $id_y . "').value;var feb=(((y%4==0)&&((!(y%100==0))||(y%400==0)))?29:28);var maxd=new Array(31,feb,31,30,31,30,31,31,30,31,30,31);var m=document.getElementById('" . $id_m . "').value;var d=document.getElementById('" . $id_d . "');for(var j=31;j>28;j--){var x=document.getElementById('" . $id_d . "_'+j);if(x){if(j>maxd[m-1]){x.style.display='none';if(d.value==j)d.selectedIndex=maxd[m-1]-1}else{x.style.display='block'}}}";
  58          $onchange = "onchange=\"$onchange\"";
  59          $this->field->settings['attributes']['misc'] = (isset($this->field->settings['attributes']['misc'])) ? $this->field->settings['attributes']['misc'] . " $onchange" : $onchange;
  60  
  61  // years
  62          $start    = (isset($this->field->settings['options']['year_start_c'])) ? date('Y') : $this->field->settings['options']['year_start'];
  63          $max        = (isset($this->field->settings['options']['year_end_c']))   ? date('Y') : $this->field->settings['options']['year_end'];
  64             $selected_y    = (isset($this->field->settings['options']['value']['y']))   ? $this->field->settings['options']['value']['y'] : date('Y');
  65          $this->field->settings['options']['tag_content_y'] = MP_::select_number($start, $max, $selected_y, 1, false);
  66  // months
  67          $start    = 0;
  68          $month_f    = $this->field->settings['options']['form_month_format'];
  69             $selected_m     = (isset($this->field->settings['options']['value']['m']))   ? $this->field->settings['options']['value']['m'] : date('m');
  70          if ($month_f != 'n') $wpl = new WP_Locale();
  71          do { $start++; $k = $start; if ($k < 10) $k = '0' . $k; $v = $k; if ('s' == $month_f) $v = $wpl->get_month_abbrev($wpl->get_month($start)); if ('f' == $month_f) $v = $wpl->get_month($start); $list[$k] = $v; } while ($start < 12);
  72          $this->field->settings['options']['tag_content_m'] = MP_::select_option($list, $selected_m, false);
  73  // days
  74          $start = 0; $days = '';
  75          $selected_d = (isset($this->field->settings['options']['value']['d']))   ? $this->field->settings['options']['value']['d'] : date('d');
  76          $feb = ((($selected_y % 4 == 0) && ( (!($selected_y % 100 == 0)) || ($selected_y % 400 == 0))) ? 29 : 28 ); $maxd = array(31,$feb,31,30,31,30,31,31,30,31,30,31); if ($selected_d > $maxd[$selected_m - 1]) $selected_d = $maxd[$selected_m - 1] - 1;
  77          do { $start++; $k = $start; if ($k < 10) $k = '0' . $k; $v = $k; $style = ($start > $maxd[$selected_m - 1]) ? " style='display:none;'" : ''; $days .="<option id=\"" . $id_d . '_' . $k . "\" value=\"$k\"" . MP_::selected($selected_d, $k, false)  . "$style>$k</option>"; } while ($start < 31); $days = "\n$days\n";
  78          $this->field->settings['options']['tag_content_d'] = $days;
  79  
  80          if (!$no_reset) return;
  81          
  82          $this->field->settings['options']['value'] = $_POST[$this->prefix][$this->field->form_id][$this->field->id];
  83  
  84          $html = MP_Form_field_type_select::no_reset( $this->field->settings['options']['tag_content_y'], $this->field->settings['options']['value']['y'] );
  85          $this->field->settings['options']['tag_content_y'] = ($html) ? $html : '<!-- ' . htmlspecialchars( __('invalid select options', MP_TXTDOM) ) . ' -->';
  86          $html = MP_Form_field_type_select::no_reset( $this->field->settings['options']['tag_content_m'], $this->field->settings['options']['value']['m'] );
  87          $this->field->settings['options']['tag_content_m'] = ($html) ? $html : '<!-- ' . htmlspecialchars( __('invalid select options', MP_TXTDOM) ) . ' -->';
  88          $html = MP_Form_field_type_select::no_reset( $this->field->settings['options']['tag_content_d'], $this->field->settings['options']['value']['d'] );
  89          $this->field->settings['options']['tag_content_d'] = ($html) ? $html : '<!-- ' . htmlspecialchars( __('invalid select options', MP_TXTDOM) ) . ' -->';
  90  
  91          $this->attributes_filter_css();
  92      }
  93  
  94  	function build_tag()
  95      {
  96  
  97          $this->field->type = 'select';
  98  // years
  99          $this->field->settings['attributes']['tag_content'] = $this->field->settings['options']['tag_content_y'];
 100          $this->field->settings['options']['is'] = 'y';
 101          $id_y = $this->get_id($this->field);
 102          $tag_y = parent::build_tag();
 103  // months
 104          $this->field->settings['attributes']['tag_content'] = $this->field->settings['options']['tag_content_m'];
 105          $this->field->settings['options']['is'] = 'm';
 106          $id_m = $this->get_id($this->field);
 107          $tag_m = parent::build_tag();
 108  // days
 109          $this->field->settings['attributes']['tag_content'] = $this->field->settings['options']['tag_content_d'];
 110          $this->field->settings['options']['is'] = 'd';
 111          $id_d = $this->get_id($this->field);
 112          $tag_d = parent::build_tag();
 113  
 114          $this->field->type = $this->id;
 115  
 116          $form_formats['ymd'] = '{{y}}&#160;{{m}}&#160;{{d}}';
 117          $form_formats['dmy'] = '{{d}}&#160;{{m}}&#160;{{y}}';
 118          $form_formats['mdy'] = '{{m}}&#160;{{d}}&#160;{{y}}';
 119  
 120          $form_formats = $this->get_formats($form_formats);
 121  
 122          $search[] = '{{y}}';    $replace[] = '%1$s';
 123          $search[] = '{{id_y}}';    $replace[] = '%2$s';
 124          $search[] = '{{m}}';     $replace[] = '%3$s';
 125          $search[] = '{{id_m}}';    $replace[] = '%4$s';
 126          $search[] = '{{d}}';     $replace[] = '%5$s';
 127          $search[] = '{{id_d}}';    $replace[] = '%6$s';
 128  
 129          $html = str_replace($search, $replace, $form_formats[$this->field->settings['options']['form_date_format']] );
 130          return sprintf($html, $tag_y, $id_y, $tag_m, $id_m, $tag_d, $id_d);
 131      }
 132  }
 133  new MP_Form_field_type_date(__('Date', MP_TXTDOM));


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1