18 require_once SQ_INCLUDE_PATH.
'/asset_attribute.inc';
19 require_once SQ_FUDGE_PATH.
'/datetime_field/datetime_field.inc';
20 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
88 $this->_edit_params[
'allow_null'] = TRUE;
89 $this->_edit_params[
'max'] =
'2030-12-31 23:59:59';
90 $this->_edit_params[
'min'] =
'1970-01-01 00:00:00';
91 $this->_edit_params[
'allow_circa'] =
'0';
92 $this->_edit_params[
'print_format'] =
'l, F jS, Y H:i:s';
93 $this->_edit_params[
'allow_period'] = FALSE;
94 $this->_edit_params[
'allow_period_today'] = FALSE;
95 $this->_edit_params[
'use_picker'] = FALSE;
98 $this->_edit_params[
'show'] = Array(
'y',
'm',
'd',
'h',
'i',
's');
99 $this->_edit_params[
'style'] = Array(
107 $this->_edit_params[
'extras'] = Array(
115 $this->_edit_params[
'null'] = Array();
131 if (!parent::setEditParams($node))
return FALSE;
133 if (!empty($node->attributes()->min)) {
134 $this->_edit_params[
'min'] = (string)$node->attributes()->min;
136 if (!empty($node->attributes()->max)) {
137 $this->_edit_params[
'max'] = (string)$node->attributes()->max;
139 if (!empty($node->attributes()->allow_circa)) {
140 $this->_edit_params[
'allow_circa'] = (string)$node->attributes()->allow_circa;
142 if (!empty($node->attributes()->print_format)) {
143 $this->_edit_params[
'print_format'] = (string)$node->attributes()->print_format;
148 $this->_edit_params[
'show'] = Array();
149 $this->_edit_params[
'style'] = Array();
150 foreach ($node->children() as $c => $child) {
151 if ($child->getName() ==
'show') {
152 foreach ($child->children() as $i => $format) {
153 $this->_edit_params[
'show'][] = $format->getName();
154 $this->_edit_params[
'style'][(string) $format->getName()] = (string)$format->attributes()->style;
155 if (isset($format->attributes()->allow_null) && (
string)$format->attributes()->allow_null) {
156 $this->_edit_params[
'null'][] = $format->getName();
163 if (isset($node->attributes()->allow_period) && (
string)$node->attributes()->allow_period) {
164 $this->_edit_params[
'allow_period'] = TRUE;
167 if (isset($node->attributes()->use_picker) && (
string)$node->attributes()->use_picker) {
168 $this->_edit_params[
'use_picker'] = TRUE;
171 if (isset($node->attributes()->allow_period_today) && (
string)$node->attributes()->allow_period_today) {
172 $this->_edit_params[
'allow_period_today'] = TRUE;
176 if (empty($this->_edit_params[
'show'])) {
177 $this->_edit_params[
'show'] = Array(
'y',
'm',
'd',
'h',
'i',
's');
178 foreach ($this->_edit_params[
'show'] as $u) {
179 $this->_edit_params[
'style'][$u] =
's';
197 function paint($prefix, $read_only=FALSE)
207 $base_time =
'00:00:00';
212 if (substr($this->value, 0, 2) ===
'c.') {
214 $date_value = substr($this->value, 2);
217 $date_value = $this->value;
220 if ((empty($date_value) === TRUE) || (is_iso8601($date_value) === TRUE)) {
223 $date_option =
'single_date';
228 $found = preg_match(
'/^([\-\+])([0-9]+)(['.implode(
'', array_keys($period_options)).
'])$/', $date_value, $matches);
232 $date_option =
'date_period';
233 list(, $period_age, $period_num, $period_type) = $matches;
238 $found = preg_match(
'/^([0-9]{2}):([0-9]{2}):([0-9]{2}) ([\-\+])([0-9]+)(['.implode(
'', array_keys($period_options)).
'])$/', $date_value, $matches);
242 list($period_age, $period_num, $period_type) = array_slice($matches, 4, 3);
243 $date_option =
'date_period_today';
247 $date_value =
'0000-00-00 00:00:00';
248 $date_value = str_replace(
'0',
'-', $date_value);
249 $date_option =
'single_date';
259 switch ($date_option) {
261 $date_field_value = $date_value;
263 if (empty($date_field_value) === TRUE) {
265 $date_field_value = ts_iso8601(time());
266 $date_period_value =
'';
268 }
else if ($date_field_value !==
'---------- --:--:--') {
271 $timestamp = strtotime(str_replace(
'--',
'0', $date_field_value));
273 if ($timestamp < time()) {
274 $format = easy_time_total(time() - $timestamp, FALSE, TRUE);
278 $format = easy_time_total($timestamp - time(), FALSE, TRUE);
283 if (empty($format) === FALSE) {
284 if ($format[
'd'] > 0) {
285 $period_num = $format[
'd'];
288 }
else if ($format[
'h'] > 0) {
289 $period_num = $format[
'h'];
292 }
else if ($format[
'm'] > 0) {
293 $period_num = $format[
'm'];
296 }
else if ($format[
's'] > 0) {
297 $period_num = $format[
's'];
304 $date_period_value = $period_age.$period_num.$period_type;
306 $date_period_value =
'';
312 $date_period_value = $period_age.$period_num.$period_type;
313 $date_period = $period_age.$period_num.
' '.$period_options[$period_type];
314 $date_field_value = ts_iso8601(strtotime($date_period));
315 $base_time =
'00:00:00';
318 case 'date_period_today':
319 $date_period_value = $period_age.$period_num.$period_type;
320 $date_period = $period_age.$period_num.
' '.$period_options[$period_type];
321 $base_time = $matches[1].
':'.$matches[2].
':'.$matches[3];
322 $date_field_value = ts_iso8601(strtotime($base_time.
' '.$date_period));
327 if (!empty($this->_params[
'print_format'])) {
328 $this->_edit_params[
'print_format'] = $this->_params[
'print_format'];
331 if ($read_only === TRUE) {
332 switch ($date_option) {
334 if ($this->_edit_params[
'allow_circa'] ===
'1') {
335 if ($circa === TRUE) {
336 $date_field_value .=
' 1';
338 $date_field_value .=
' 0';
341 $field =
new Datetime_Field($prefix, $date_field_value, $this->_edit_params);
342 echo $field->format();
346 if ((
int)$period_num === 0) {
347 echo translate(
'attribute_datetime_period_age_0', $period_num, $period_options[$period_type]);
349 echo translate(
'attribute_datetime_period_age_'.$period_age, $period_num, $period_options[$period_type]);
353 case 'date_period_today':
354 if ((
int)$period_num === 0) {
355 echo translate(
'attribute_datetime_today_age_0', $period_num, $period_options[$period_type], $base_time);
357 echo translate(
'attribute_datetime_today_age_'.$period_age, $period_num, $period_options[$period_type], $base_time);
365 'single_date' => translate(
'attribute_datetime_option_single_date'),
366 'date_period' => translate(
'attribute_datetime_option_date_period'),
367 'date_period_today' => translate(
'attribute_datetime_option_date_period_today'),
370 if ((
boolean)$this->_edit_params[
'allow_period'] === FALSE) {
371 unset($options[
'date_period']);
373 if ((
boolean)$this->_edit_params[
'allow_period_today'] === FALSE) {
374 unset($options[
'date_period_today']);
377 $edit_fields = Array();
378 foreach ($options as $option_key => $option_name) {
379 $edit_fields[$option_key] = $this->
_getDateOptionEditInterface($prefix, $option_key, $date_field_value, $date_period_value, $circa);
382 if (count($edit_fields) > 1) {
386 <select name=
"<?php echo $prefix ?>_period_select" id=
"<?php echo $prefix ?>_period_select" onchange=
"items = document.getElementsByClassName('sq-datetime-field-date-option-<?php echo $prefix; ?>'); for (var x = 0; x < items.length; x++) {items[x].style.display = (items[x].id == ('<?php echo $prefix; ?>_field_' + this.value)) ? 'block' : 'none' };">
387 <?php
foreach ($options as $option_key => $option_name) {
388 ?><option value=
"<?php echo $option_key ?>"<?php echo ($option_key === $date_option) ?
' selected="selected"' :
''; ?>><?php echo $option_name ?></option>
395 foreach ($options as $option_key => $option_name) {
396 ?><div
id=
"<?php echo $prefix; ?>_field_<?php echo $option_key ?>" class=
"sq-datetime-field-date-option-<?php echo $prefix; ?>" style=
"display: <?php echo ($option_key === $date_option) ? 'block' : 'none'; ?>;">
397 <p><?php echo $edit_fields[$option_key]; ?></p>
398 <p><em><?php echo translate(
'attribute_datetime_select_'.$option_key); ?></em></p></div><?php
401 if (count($edit_fields) > 1) {
422 $date_option = array_get_index($_REQUEST, $prefix.
'_period_select',
'single_date');
423 $field_value = $this->value;
425 switch ($date_option) {
427 $this->processed = FALSE;
431 if (is_iso8601($field_value) === FALSE) {
432 $field_value =
'---------- --:--:--';
435 $field =
new Datetime_Field($prefix, $field_value, $this->_edit_params);
436 if ($field->processField() === TRUE) {
437 if ($this->_edit_params[
'allow_circa'] ===
'1') {
438 $value_bits = explode(
' ', $field_value);
439 if ($value_bits[2] ===
'0') {
440 $field_value = $value_bits[0].
' '.$value_bits[1];
442 $field_value =
'c.'.$value_bits[0].
' '.$value_bits[1];
447 if ($this->value !== $field_value) {
448 $ok = $this->
setValue($field_value);
451 $this->processed = TRUE;
458 $this->processed = FALSE;
461 $period_num = (int) array_get_index($_REQUEST, $prefix.
'period_num', 1);
462 $period_type = (string) array_get_index($_REQUEST, $prefix.
'_period_type',
'd');
463 $period_age = (string) array_get_index($_REQUEST, $prefix.
'_period_age',
'-');
469 if (isset($period_options[$period_type]) === FALSE) {
472 if (isset($age_options[$period_age]) === FALSE) {
476 $field_value = $period_age.$period_num.$period_type;
478 if ($this->value !== $field_value) {
479 $ok = $this->
setValue($field_value);
482 $this->processed = TRUE;
488 case 'date_period_today':
489 $this->processed = FALSE;
492 $period_num = (int) array_get_index($_REQUEST, $prefix.
'_today_period_num', 0);
493 $period_type = (string) array_get_index($_REQUEST, $prefix.
'_today_period_type',
'd');
494 $period_age = (string) array_get_index($_REQUEST, $prefix.
'_today_period_age',
'-');
495 $base_time =
'00:00:00';
501 unset($period_options[
'h']);
502 unset($period_options[
'i']);
504 if (isset($period_options[$period_type]) === FALSE) {
507 if (isset($age_options[$period_age]) === FALSE) {
513 $edit_params = $this->_edit_params;
514 $edit_params[
'show'] = Array(
'h',
'i',
's');
515 $field =
new Datetime_Field($prefix.
'_today_time', $base_time, $edit_params);
517 if ($field->processField() === TRUE) {
518 $base_time = iso8601_time_component($base_time);
519 $field_value = $base_time.
' '.$period_age.$period_num.$period_type;
521 if ($this->value !== $field_value) {
522 $ok = $this->
setValue($field_value);
525 $this->processed = TRUE;
547 $date_field_value = NULL;
549 if (is_iso8601($this->value) === TRUE) {
551 $date_field_value = $this->value;
553 }
else if (substr($this->value, 0, 2) ===
'c.') {
555 if (is_iso8601(substr($this->value, 2)) === TRUE) {
556 $date_field_value = substr($this->value, 2);
564 $found = preg_match(
'/^([\-\+])([0-9]+)(['.implode(
'', array_keys($period_options)).
'])$/', $this->value, $matches);
567 list(, $period_age, $period_num, $period_type) = $matches;
568 $date_field_value = date(
'Y-m-d H:i:s', strtotime($period_age.$period_num.
' '.$period_options[$period_type]));
571 $found = preg_match(
'/^([0-9]{2}:[0-9]{2}:[0-9]{2}) ([\-\+])([0-9]+)(['.implode(
'', array_keys($period_options)).
'])$/', $this->value, $matches);
574 list(, $base_time, $period_age, $period_num, $period_type) = $matches;
575 $date_field_value = date(
'Y-m-d H:i:s', strtotime($base_time.
' '.$period_age.$period_num.
' '.$period_options[$period_type]));
577 $date_field_value = NULL;
585 if ($date_field_value === NULL) {
588 $field =
new Datetime_Field(
'blah', $date_field_value, $this->_edit_params);
589 $units = $field->strToUnitsArray($date_field_value);
590 foreach (Array(
'y',
'm',
'd') as $u) {
591 if ($units[$u] == -1) {
596 if ($timestamp !== -1) {
598 $strtotime = $units[
'm'].
'/'.$units[
'd'].
'/'.$units[
'y'];
601 foreach (Array(
'h',
'i',
's') as $u) {
602 if ($units[$u] == -1) $dotime = FALSE;
605 $strtotime .=
' '.$units[
'h'].
':'.$units[
'i'].
':'.$units[
's'];
608 $timestamp = strtotime($strtotime);
625 if (is_iso8601($this->value) === TRUE) {
628 $time_zone_designater = date(
'O');
629 $tzd_iso8601 = substr($time_zone_designater, 0, 3).
':'.substr($time_zone_designater, -2);
631 return date(
'Y-m-d\TH:i:s', $this->
getTimestamp()).$tzd_iso8601;
648 if (!empty($this->_params[
'allow_null']) && ($value ==
'---------- --:--:--' || $value ==
'')) {
655 $found = preg_match(
'/^(c(irc(a)?)?[\.]?[ ]?)?(.*)$/', $value, $matches);
657 $date_value = $matches[4];
659 if (empty($matches[1]) === FALSE) {
663 $date_value = $value;
666 if (is_iso8601($date_value) === TRUE) {
668 $field =
new Datetime_Field(
'blah', $ref, $this->_edit_params);
669 $value = $field->validateValue($value);
670 if ($this->_edit_params[
'allow_circa'] ===
'1') {
671 $value_bits = explode(
' ', $value);
672 if ($value_bits[2] ===
'0') {
673 $value = $value_bits[0].
' '.$value_bits[1];
675 $value =
'c.'.$value_bits[0].
' '.$value_bits[1];
680 if (!empty($date_value) && !preg_match(
'|([0-9]{2}:[0-9]{2}:[0-9]{2} )?[\-\+][0-9]+['.implode(
'', array_keys($this->
_getPeriodOptions())).
']|', $date_value)) {
699 'i' => translate(
'minutes'),
700 'h' => translate(
'hours'),
701 'd' => translate(
'days'),
702 'w' => translate(
'weeks'),
703 'm' => translate(
'months'),
704 'y' => translate(
'years'),
719 '-' =>
'in the past',
720 '+' =>
'in the future',
735 '-' =>
'before today',
736 '+' =>
'after today',
752 if ($format !==
'') {
757 $format_value = format_date($ts, $format);
759 return $format_value;
763 return parent::getKeywordValue($format);
784 switch ($option_name) {
786 if ($this->_edit_params[
'allow_circa'] ===
'1') {
787 if ($circa === TRUE) {
788 $default_date .=
' 1';
790 $default_date .=
' 0';
794 $field =
new Datetime_Field($prefix, $default_date, $this->_edit_params);
795 $field->printField();
797 if ($this->_edit_params[
'use_picker']) {
799 require_once SQ_LIB_PATH.
'/js_calendar/js_calendar.inc';
802 $calendar->changeSetting(
'onDayClick',
'datetime_set_date');
803 $calendar->paint($prefix, $prefix.
'_cal_picker', TRUE);
811 $found = preg_match(
'/^([\-\+])([0-9]+)(['.implode(
'', array_keys($period_options)).
'])$/', $default_period, $matches);
813 list(, $period_age, $period_num, $period_type) = $matches;
815 list($period_age, $period_num, $period_type) = Array(
'-',
'',
'd');
819 int_text_box($prefix.
'period_num', $period_num, FALSE, 3);
820 $cb_period_num = ob_get_clean();
823 combo_box($prefix.
'_period_type', $period_options, FALSE, $period_type);
824 $cb_period_type = ob_get_clean();
827 combo_box($prefix.
'_period_age', $age_options, FALSE, $period_age);
828 $cb_period_age = ob_get_clean();
830 echo translate(
'attribute_datetime_date_period_edit_format', $cb_period_num, $cb_period_type, $cb_period_age);
834 case 'date_period_today':
838 $found = preg_match(
'/^[0-9]{2}:[0-9]{2}:[0-9]{2} ([\-\+])([0-9]+)(['.implode(
'', array_keys($period_options)).
'])$/', date(
'H:i:s', strtotime($default_date)).
' '.$default_period, $matches);
840 list(, $period_age, $period_num, $period_type) = $matches;
842 list($period_age, $period_num, $period_type) = Array(
'-',
'',
'd');
848 if ($period_type ===
'i') {
849 $period_num = floor($period_num / 1440);
851 }
else if ($period_type ===
'h') {
852 $period_num = floor($period_num / 24);
857 int_text_box($prefix.
'_today_period_num', $period_num, FALSE, 3);
858 $cb_period_num = ob_get_clean();
862 unset($period_options[
'i']);
863 unset($period_options[
'h']);
864 combo_box($prefix.
'_today_period_type', $period_options, FALSE, $period_type);
865 $cb_period_type = ob_get_clean();
868 combo_box($prefix.
'_today_period_age', $age_options, FALSE, $period_age);
869 $cb_period_age = ob_get_clean();
872 $edit_params = $this->_edit_params;
873 $edit_params[
'show'] = Array(
'h',
'i',
's');
875 $field =
new Datetime_Field($prefix.
'_today_time', $default_date, $edit_params);
876 $field->printField();
877 $datetime_field_output = ob_get_clean();
879 echo translate(
'attribute_datetime_today_period_edit_format', $cb_period_num, $cb_period_type, $cb_period_age, $datetime_field_output);
885 $output = ob_get_clean();
888 if (empty($output) === TRUE) {