17 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
100 $this->prefix =& $prefix;
101 $this->value =& $value;
102 $this->parameters =& $parameters;
117 $this->value =& $value;
132 $this->parameters =& $parameters;
147 if (isset($this->parameters[$code])) {
148 return $this->parameters[$code];
154 $res =
'0000-00-00 00:00:00';
157 $res =
'9999-12-31 23:59:59';
175 if (!is_array($show)) $show = Array();
176 if (!is_array($null)) $null = Array();
179 <script type=
"text/javascript">
181 if (typeof adjustDate !=
"function") {
183 adjustDate =
function(input, evt)
185 var key = evt.keyCode;
186 var value = parseInt(input.value * 1);
187 if (key == 107 || key == 109) {
188 value += (key == 109)?-1:1;
192 event.returnValue =
false;
193 event.cancelBubble =
true;
202 echo
'<input type="hidden" name="'.$this->prefix.
'show" value="'.implode(
'', $show).
'" />';
203 $this->prefix .=
'value';
204 if ($this->
getParam(
'allow_circa')) {
205 combo_box($this->prefix.
'[c]', Array(
'0'=>
'',
'1'=>
'circa.'), FALSE, $this->
getUnit(
'c'));
207 foreach (Array(
'd',
'm',
'y',
'h',
'i',
's',
'a') as $t) {
210 if (in_array($t, $show)) {
211 $this->
inputBox($t, $this->prefix, $u, in_array($t, $null));
212 }
else if ($t !=
'a') {
213 echo
'<input type="hidden" name="'.$this->prefix.
'['.$t.
']" value="'.$u.
'" />';
215 if ($t ==
'y') echo
' ';
216 if ($t ==
'h' && in_array(
'h', $show) && in_array(
'i', $show)) {
219 if ($t ==
'i' && in_array(
'i', $show) && in_array(
's', $show)) {
238 function inputBox($u, $prefix, &$value, $allow_null=FALSE)
240 $input_style =& $this->
getParam(
'style');
241 $extras =& $this->
getParam(
'extras');
242 $increments =& $this->
getParam(
'increment');
243 $min_array =& $this->
getParam(
'min');
244 $max_array =& $this->
getParam(
'max');
246 $min = (int) $this->
getUnit($u, $min_array);
247 $max = (int) $this->
getUnit($u, $max_array);
250 foreach (Array(
'y',
'm',
'd',
'h',
'i',
's') as $diff_unit) {
251 $diff[$diff_unit] = $this->
getUnit($diff_unit, $max_array) - $this->
getUnit($diff_unit, $min_array);
254 if ($allow_null && (!strlen($value) || $value ==
'--' || $value ==
'----')) {
256 }
else if ($u !=
'a') {
257 $value = (int) $value;
262 if (!empty($increments)) $increment = $increments[$u];
265 if (($u ==
'a') || ($input_style[$u] ==
's')) {
267 $options = Array(
'--' =>
'');
274 for ($i = (
int) $min; $i <= $max; $i += $increment) {
280 if (($diff[
'y']*12) + $diff[
'm'] >= 12) {
285 }
else if ($diff[
'y'] == 1) {
287 for ($i = 1; $i <= $max; $i += $increment) {
293 for ($i = (
int) $min; $i <= $max; $i += $increment) {
299 if (($diff[
'y'] > 0) || ($diff[
'm'] > 1) || (($diff[
'm'] == 1) && ($diff[
'd'] == 0)) ) {
304 }
else if ($diff[
'm'] == 1) {
306 for ($i = 1; $i <= $max; $i += $increment) {
311 $mth = (int) $this->
getUnit(
'm', $max_array);
312 $yr = (int) $this->
getUnit(
'y', $max_array);
313 $lastday = gmmktime(0, 0, 0, $mth, 0, $yr);
314 $max = (int)date(
'd', $lastday);
316 for ($i = (
int) $min; $i <= $max; $i += $increment) {
322 if (($diff[
'y'] > 0) || ($diff[
'm'] > 0) || ($diff[
'd'] > 1) || (($diff[
'd'] == 1) && ($diff[
'h'] == 0)) ) {
323 if (in_array(
'a', $this->
getParam(
'show'))) {
332 }
else if ($diff[
'd'] == 1) {
334 for ($i = 0; $i <= $max; $i += $increment) {
335 $options[$i] = sprintf(
'%02d', $i);
338 $max = (in_array(
'a', $this->
getParam(
'show'))) ? 12 : 23;
340 for ($i = (
int) $min; $i <= $max; $i += $increment) {
341 $options[$i] = sprintf(
'%02d', $i);
346 if (($diff[
'y'] > 0) || ($diff[
'm'] > 0) || ($diff[
'd'] > 0) || ($diff[
'h'] > 1) || (($diff[
'h'] == 1) && ($diff[
'i'] == 0))) {
351 }
else if ($diff[
'h'] == 1) {
353 for ($i = 0; $i <= $max; $i += $increment) {
354 $options[$i] = sprintf(
'%02d', $i);
359 for ($i = (
int) $min; $i <= $max; $i += $increment) {
360 $options[$i] = sprintf(
'%02d', $i);
365 if (($diff[
'y'] > 0) || ($diff[
'm'] > 0) || ($diff[
'd'] > 0) || ($diff[
'h'] > 0) || ($diff[
'i'] > 1) || (($diff[
'i'] == 1) && ($diff[
's'] == 0))) {
370 }
else if ($diff[
'i'] == 1) {
372 for ($i = 0; $i <= $max; $i += $increment) {
373 $options[$i] = sprintf(
'%02d', $i);
378 for ($i = (
int) $min; $i <= $max; $i += $increment) {
379 $options[$i] = sprintf(
'%02d', $i);
384 if ((($diff[
'y'] > 0) || ($diff[
'm'] > 0) || ($diff[
'd'] > 1) || (($diff[
'd'] == 1) && ($diff[
'h'] == 0)) ) || ($diff[
'd'] == 1) || (($this->
getUnit(
'h', $min_array) < 12) && ($this->
getUnit(
'h', $max_array) >= 12))) {
385 $options = Array(
'am'=>
'am',
'pm'=>
'pm');
388 $options = ($min < 12) ? Array('am'=>
'am') : Array(
'pm'=>
'pm');
394 if (($u ==
'a') || ($input_style[$u] ==
's')) {
395 if (!isset($extras[$u])) $extras[$u] =
'';
396 if (!stristr($extras[$u],
'id=')) $extras[$u] .=
' id="'.$prefix.
'_'.$u.
'"';
398 combo_box($prefix.
'['.$u.
']', $options, FALSE, $value, 0, $extras[$u]);
402 $size = (($u==
'y') ? 4 : 2);
405 if (($value !==
'') && ($u ==
'i')) {
406 $value = sprintf(
'%02d', $value);
408 if (!isset($extras[$u])) $extras[$u] =
'';
409 if (!stristr($extras[$u],
'id=')) {
410 $adjustExtra =
'onkeydown="adjustDate(this, event)" onfocus="this.select()" id="'.$prefix.
'_'.$u.
'"';
412 $adjustExtra =
'onkeydown="adjustDate(this, event)" onfocus="this.select()"';
414 int_text_box($prefix.
'['.$u.
']', $value, FALSE, $size, $min, $max, $size, FALSE, $allow_null, $extras[$u].
' '.$adjustExtra);
417 echo
'<input type="hidden" name="'.$prefix.
'['.$u.
']" value="'.$value.
'" '.$extras[$u].
' />';
434 $value = $this->value;
435 $use_am_pm = in_array(
'a', $this->
getParam(
'show'));
441 $ar_value = explode(
' ', $value);
442 $date = (isset($ar_value[0])) ? $ar_value[0] :
'';
443 $time = (isset($ar_value[1])) ? $ar_value[1] :
'';
444 $c = (isset($ar_value[2])) ? $ar_value[2] :
'';
447 if (strlen($date) == 10) {
448 $y = substr($date, 0, 4);
449 $m = substr($date, 5, 2);
450 $d = substr($date, 8, 2);
452 $ar_date = explode(
'-', $date);
453 $y = (isset($ar_date[0])) ? $ar_date[0] :
'';
454 $m = (isset($ar_date[1])) ? $ar_date[1] :
'';
455 $d = (isset($ar_date[2])) ? $ar_date[2] :
'';
459 $ar_time = explode(
':', $time);
460 $a = (isset($ar_time[0]) && ($ar_time[0] >= 12)) ?
'pm' :
'am';
461 $h = (isset($ar_time[0])) ? ($use_am_pm ? (((($ar_time[0] % 12) + 11) % 12) + 1) : $ar_time[0]) :
'';
462 $i = (isset($ar_time[1])) ? $ar_time[1] :
'';
463 $s = (isset($ar_time[2])) ? $ar_time[2] :
'';
481 $months = Array(
'',
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec');
483 $months = array_flip($months);
502 $months = Array(
'',
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December');
504 $months = array_flip($months);
520 if (!isset($_REQUEST[$this->prefix.
'value'])) {
523 $input = $_REQUEST[$this->prefix.
'value'];
526 $this->value = $validated_value;
542 if (!is_array($value)) {
543 $value = trim($value);
545 $value = preg_replace(
'/^c(irc[a]?)?\.?[\s]*/i',
'', $value);
547 if (($new_l = strlen($value)) != $l) $c = TRUE;
548 if (!preg_match(
"/^\-?[0-9\-]{4}-[0-9\-]{2}-[0-9\-]{2} ([0-9\-]{2}\:?){3}( [01]?)?$/", $value)) {
550 if (preg_match(
"/^\-?[0-9]{4}$/", $value)) {
551 $value .=
'------ --:--:--';
552 }
else if (preg_match(
"/^[0-9]+$/", $value)) {
553 $value = date(
'Y-m-d H:i:s', $value);
557 $v = Array(
'y'=>-1,
'm'=>-1,
'd'=>-1,
'h'=>-1,
'i'=>-1,
's'=>-1);
559 if (preg_match(
"/([0-9]{1,2})[\-\/]([0-9]{1,2})[\-\/]([0-9]{2,4})([^0-9].*|)$/", $value, $matches) && ($matches[0] == $value)) {
561 if ($this->
getParam(
'standard') ==
'us') {
562 $v[
'd'] = $matches[2]; $v[
'm'] = $matches[1];
564 $v[
'd'] = $matches[1]; $v[
'm'] = $matches[2];
566 $v[
'y'] = $matches[3];
567 if (strlen($v[
'y']) <= 2) {
568 $v[
'y'] += (($v[
'y'] < 20) ? 2000 : 1900);
570 }
else if (preg_match(
"/\-?([0-9]{2,4})[\-\/]([0-9]{1,2})[\-\/]([0-9]{1,2})([^0-9].*|)$/", $value, $matches) && ($matches[0] == $value)) {
572 $v[
'd'] = $matches[3];
573 $v[
'm'] = $matches[2];
574 $v[
'y'] = $matches[1];
575 if (strlen($v[
'y']) <= 2) {
576 $v[
'y'] += (($v[
'y'] < 20) ? 2000 : 1900);
578 }
else if (preg_match(
"/([0-9]{1,2})[\-\/]([0-9]{1,2})([^0-9].*|)$/", $value, $matches)) {
580 if ($this->
getParam(
'standard') ==
'us') {
581 $v[
'd'] = $matches[2]; $v[
'm'] = $matches[1];
583 $v[
'd'] = $matches[1]; $v[
'm'] = $matches[2];
585 }
else if (preg_match(
"/([0-9]{1,2})[\-\/]([0-9]{4})([^0-9].*|)$/", $value, $matches)) {
587 $v[
'm'] = $matches[1];
588 $v[
'y'] = $matches[2];
591 if (preg_match(
"/([0-9]{1,2})?([\s\,]*)(jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|jun(e)?|jul(y)?|aug(ust)?|sep(tember)?|oct(ober)?|nov(ember)?|dec(ember)?)([\s\,]*)([0-9]{1,2})?([^0-9].*|)$/i", $value, $matches)) {
593 if (strlen($tmp = $matches[3]) == 3) {
600 $v[
'd'] = $matches[1];
601 }
else if ($matches[16]) {
602 $v[
'd'] = $matches[16];
605 if (preg_match(
'/([0-9]{4})([^0-9].*|)$/', $value, $matches)) {
607 $v[
'y'] = $matches[1];
609 if ($v[
'd'] == -1 && preg_match(
'/([0-9]{1,2})(st|nd|rd|th)/i', $value, $matches)) {
611 $v[
'd'] = $matches[1];
615 if (preg_match(
"/([0-9]{1,2})[\:\.]([0-9]{1,2})[\:\.]([0-9]{1,2})([^0-9].*|)$/", $value, $matches)) {
616 $v[
'h'] = $matches[1];
617 $v[
'i'] = $matches[2];
618 $v[
's'] = $matches[3];
619 }
else if (preg_match(
'/([0-9]{1,2})[\:\.]([0-9]{1,2})([^0-9].*|)$/', $value, $matches)) {
620 if (in_array(
's', $show) && !in_array(
'h', $show)) {
621 $v[
'i'] = $matches[1];
622 $v[
's'] = $matches[2];
624 $v[
'h'] = $matches[1];
625 $v[
'i'] = $matches[2];
628 if (preg_match(
'/([0-9]{1,2})([\s]*)(p\.?m\.?|a\.?m\.?)/i', $value, $matches)) {
629 if ($v[
'h'] == -1) $v[
'h'] = $matches[1];
630 if (strtolower($matches[3][0]) ==
'p') {
631 if ($v[
'h'] <= 12) $v[
'h'] += 12;
633 if ($v[
'h'] == 12) $v[
'h'] -= 12;
645 if ($c) $value[
'c'] = 1;
652 $value_str = $this->unitsArraytoStr($value);
653 if ($value_str !=
'---------- --:--:--') {
654 $value_substr = Array(
662 foreach (array_keys($value_substr) as $value_part) {
663 $substr_length = ($value_part ==
'y') ? 4 : 2;
664 if ($value[$value_part] == -1) {
665 $min = substr_replace($min, str_repeat(
'-', $substr_length), $value_substr[$value_part], $substr_length);
666 $max = substr_replace($max, str_repeat(
'-', $substr_length), $value_substr[$value_part], $substr_length);
670 if (strcmp($value_str, $min) < 0) {
672 }
else if (strcmp($value_str, $max) > 0) {
678 $validate_day_month = ($value[
'y'] >= 1970) && ($value[
'y'] < 2038) && ($value[
'm'] >= 0) && ($value[
'd'] >= 0);
682 if ($validate_day_month) {
684 (
int) substr($value,11,2),
685 (
int) substr($value,14,2),
686 (
int) substr($value,17,2),
687 (
int) substr($value,5,2),
688 (
int) substr($value,8,2),
689 (
int) substr($value,0,4)
694 if ((strlen($old_value) == 19) &&
false === strpos($old_value,
'--')) {
696 $value = date(
'Y-m-d H:i:s', $timestamp);
697 if (strcmp($value, $old_value) != 0) {
698 trigger_localised_error(
'SYS0311', E_USER_NOTICE, $old_value);
700 }
else if (
false === strpos($old_value,
'----------')) {
702 $value = date(
'Y-m-d ', $timestamp).substr($old_value, 11);
703 if (strcmp(substr($value, 0, 10), substr($old_value, 0, 10)) != 0) {
704 trigger_localised_error(
'SYS0312', E_USER_NOTICE, substr($old_value, 0, 10));
710 if (strlen($value) > 20 && !$this->
getParam(
'allow_circa')) {
711 $value = substr($value, 20);
730 $r[
'y'] = ((($i = (int) ($s = substr($value,0,4))) || ($s{0} !=
'-' && strlen($s))) ? $i : -1);
731 $r[
'm'] = ((($i = (int) ($s = substr($value,5,2))) || ($s{0} !=
'-' && strlen($s))) ? $i : -1);
732 $r[
'd'] = ((($i = (int) ($s = substr($value,8,2))) || ($s{0} !=
'-' && strlen($s))) ? $i : -1);
733 $r[
'h'] = ((($i = (int) ($s = substr($value,11,2))) || ($s{0} !=
'-' && strlen($s))) ? $i : -1);
734 $r[
'i'] = ((($i = (int) ($s = substr($value,14,2))) || ($s{0} !=
'-' && strlen($s))) ? $i : -1);
735 $r[
's'] = ((($i = (int) ($s = substr($value,17,2))) || ($s{0} !=
'-' && strlen($s))) ? $i : -1);
736 if ($this->
getParam(
'allow_circa')) {
737 $r[
'c'] = (substr($value, 20, 1) ? 1 : 0);
755 if (isset($v[
'a']) && !empty($v[
'a'])) {
756 $v[
'h'] = ($v[
'h'] % 12) + (($v[
'a'] ==
'pm') ? 12 : 0);
758 $r = (!isset($v[
'y']) || ($v[
'y'] < 0 || !strlen($v[
'y']) || $v[
'y']{0} ==
'-') ?
'----' : sprintf(
'%04d', $v[
'y'])).
'-'
759 .(!isset($v[
'm']) || ($v[
'm'] < 0 || !strlen($v[
'm']) || $v[
'm']{0} ==
'-') ?
'--' : sprintf(
'%02d', $v[
'm'])).
'-'
760 .(!isset($v[
'd']) || ($v[
'd'] < 0 || !strlen($v[
'd']) || $v[
'd']{0} ==
'-') ?
'--' : sprintf(
'%02d', $v[
'd'])).
' '
761 .(!isset($v[
'h']) || ($v[
'h'] < 0 || !strlen($v[
'h']) || $v[
'h']{0} ==
'-') ?
'--' : sprintf(
'%02d', $v[
'h'])).
':'
762 .(!isset($v[
'i']) || ($v[
'i'] < 0 || !strlen($v[
'i']) || $v[
'i']{0} ==
'-') ?
'--' : sprintf(
'%02d', $v[
'i'])).
':'
763 .(!isset($v[
's']) || ($v[
's'] < 0 || !strlen($v[
's']) || $v[
's']{0} ==
'-') ?
'--' : sprintf(
'%02d', $v[
's']));
764 if ($this->
getParam(
'allow_circa')) {
765 $r .=
' '.(isset($v[
'c']) && $v[
'c'] ?
'1' :
'0');
782 if (is_null($format)) {
783 $print_format =& $this->
getParam(
'print_format');
784 $format = $print_format;
790 $dep=Array(
'h' =>
'aABcgGhHrU',
'd' =>
'cdDIjlOrSUwWzZ',
'm' =>
'cDFIlmMnOrtUwWzZ',
'y' =>
'cDlLrtUwWYyz',
'i' =>
'cirU',
's' =>
'crsU');
794 if ($u ==
'm' || $u ==
'd') {
808 $c = $this->
getParam(
'allow_circa');
811 if ($y < 1970 && !stristr($es,
'y')) {
815 $format = str_replace(
'Y',
'||||', $format);
816 $format = str_replace(
'y',
'~~', $format);
819 $regexp =
"/[\\s]*[^a-zA-Z\\s]*[$es][^a-zA-Z\\|\{4\}\\~\{2\}\\s]*[\\s]*/";
820 $format = preg_replace($regexp,
' ', $format);
822 $format = str_replace(
'||||', $real_y, $format);
823 $format = str_replace(
'~~', $real_y%100, $format);
828 $format = str_replace(
'C', ($c ?
'~' :
''), $format);
830 $format = date($format,mktime($h, $i, $s, $m, $d, $y));
833 $format = str_replace(
'~',
'circa.', $format);
849 'min' =>
'0000-01-01 00:00:00',
850 'max' =>
'9999-12-31 23:59:59',
851 'show' => Array(
'y',
'm',
'd',
'h',
'i',
's'),
852 'increment' => Array(),
853 'style' => $this->
getParam(
'style'),
855 $p[
'style'][
'y'] =
't';
872 'min' =>
'0000-01-01 00:00:00',
873 'max' =>
'9999-12-31 23:59:59',
874 'show' => Array(
'y',
'm',
'd',
'h',
'i',
's'),
875 'increment' => Array(),
876 'style' => $this->
getParam(
'style'),
894 'min' =>
'0000-01-01 00:00:00',
895 'max' =>
'9999-12-31 23:59:59',
896 'show' => Array(
'y',
'm',
'd',
'h',
'i',
's'),
897 'increment' => Array(),
898 'style' => $this->
getParam(
'style'),
900 $p[
'style'][
'y'] =
't';
917 'min' =>
'0000-01-01 00:00:00',
918 'max' =>
'9999-12-31 23:59:59',
919 'show' => Array(
'y',
'm',
'd',
'h',
'i',
's'),
920 'increment' => Array(),
921 'style' => $this->
getParam(
'style'),
940 if (empty($show)) $show = Array(
's',
'n',
'c',
't');
942 $us = Array(
'd'=>
'Day',
'm'=>
'Month',
'y'=>
'Year',
'h'=>
'Hour',
'i'=>
'Min.',
's'=>
'Sec.');
946 $c =& $this->
getParam(
'allow_circa');
950 <table cellspacing=
"0" cellpadding=
"2" border=
"1">
953 if (in_array(
'c', $show)) {
954 combo_box($this->prefix.
'_allow_circa', Array(
''=>
'',
'1'=>
'Allow "circa."'), FALSE, $c,
'class="smallprint"');
957 if (in_array(
't', $show)) {
958 combo_box($this->prefix.
'_standard', Array(
'int'=>
'Intl. (dd/mm/yyyy)',
'us'=>
'US (mm/dd/yyyy)'), $t,
'class="fineprint"');
963 foreach ($us as $k=>$v) {
965 <td align=center><b><?php echo $v; ?></b></td>
972 if (in_array(
's', $show)) {
977 foreach ($us as $k => $v) {
979 <td align=
"center"><input type=
"checkbox" name=
"<?php echo $this->prefix; ?>_show[]" value=<?php echo $k; ?> <?php echo ((in_array($k, $s)) ?
'checked="checked"' :
''); ?>></b>
989 if (in_array(
'n', $show)) {
992 <td><b>Allow blank</b></td>
994 foreach ($us as $k=>$v) {
995 ?><td align=
"center"><input type=
"checkbox" name=
"<?php echo $this->prefix; ?>_null[]" value=<?php echo $k; ?> <?php echo ((in_array($k, $n)) ?
'checked="checked"' :
''); ?>></b>
1004 <td><b>Select box</b></td>
1006 foreach ($us as $k=>$v) {
1009 <input type=
"radio" name=
"<?php echo $this->prefix; ?>_style[<?php echo $k; ?>]" value=
"s" <?php echo (($y[$k]==
's') ?
'checked="checked"' :
''); ?>></b>
1017 <td><b>Text box</b></td>
1019 foreach ($us as $k=>$v) {
1022 <input type=
"radio" name=
"<?php echo $this->prefix; ?>_style[<?php echo $k; ?>]" value=
"t" <?php echo (($y[$k]==
't') ?
'checked="checked"' :
''); ?>></b>
1054 $s = isset($_REQUEST[$this->prefix.
'_show']) ? $_REQUEST[$this->prefix.
'_show'] : Array();
1055 $n = isset($_REQUEST[$this->prefix.
'_null']) ? $_REQUEST[$this->prefix.
'_null'] : Array();
1056 $y = $_REQUEST[$this->prefix.
'_style'];
1057 $c = $_REQUEST[$this->prefix.
'_allow_circa'];
1058 $t = isset($_REQUEST[$this->prefix.
'_standard']) ? $_REQUEST[$this->prefix.
'_standard'] : Array();
1060 $this->parameters[
'show'] = $s;
1061 $this->parameters[
'null'] = $n;
1062 $this->parameters[
'style'] = $y;
1063 $this->parameters[
'allow_circa'] = $c;
1064 $this->parameters[
'standard'] = $t;
1082 return ($this->value ==
'---------- --:--:--');