Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.inc |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | * @author Yaron Koren |
7 | 7 | * @author Nils Oppermann |
8 | 8 | * @author Jeffrey Stuckman |
| 9 | + * @author Matt Williamson |
9 | 10 | */ |
10 | 11 | |
11 | 12 | class SFFormPrinter { |
— | — | @@ -373,12 +374,23 @@ |
374 | 375 | $yes = $words_for_true[0]; |
375 | 376 | } |
376 | 377 | $cur_value_in_template = $yes; |
377 | | - } elseif (count($cur_value) == 3) { |
| 378 | + // if it's 3 or greater, assume it's a date or datetime |
| 379 | + } elseif (count($cur_value) >= 3) { |
378 | 380 | $month = $cur_value['month']; |
379 | 381 | $day = $cur_value['day']; |
380 | 382 | $year = $cur_value['year']; |
| 383 | + if (isset($cur_value['hour'])) $hour = $cur_value['hour']; |
| 384 | + if (isset($cur_value['minute'])) $minute = $cur_value['minute']; |
| 385 | + if (isset($cur_value['second'])) $second = $cur_value['second']; |
| 386 | + if (isset($cur_value['ampm24h'])) $ampm24h = $cur_value['ampm24h']; |
| 387 | + if (isset($cur_value['timezone'])) $timezone = $cur_value['timezone']; |
381 | 388 | if ($month != '' && $day != '' && $year != '') { |
382 | 389 | $cur_value_in_template = "$month $day, $year"; |
| 390 | + # include whatever time information we have |
| 391 | + if(isset($hour)) $cur_value_in_template .= " " . str_pad(intval(substr($hour,0,2)),2,'0',STR_PAD_LEFT) . ":" . str_pad(intval(substr($minute,0,2)),2,'0',STR_PAD_LEFT); |
| 392 | + if(isset($second)) $cur_value_in_template .= ":" . str_pad(intval(substr($second,0,2)),2,'0',STR_PAD_LEFT); |
| 393 | + if(isset($ampm24h)) $cur_value_in_template .= " $ampm24h"; |
| 394 | + if(isset($timezone)) $cur_value_in_template .= " $timezone"; |
383 | 395 | } else { |
384 | 396 | $cur_value_in_template = ""; |
385 | 397 | } |
— | — | @@ -427,10 +439,16 @@ |
428 | 440 | if ($is_mandatory) { |
429 | 441 | $input_id = "input_" . $gTabIndex; |
430 | 442 | $info_id = "info_" . $gTabIndex; |
431 | | - if ($input_type == 'date') { |
| 443 | + if ($input_type == 'date' || $input_type == 'datetime' || $input_type == 'datetime with timezone') { |
432 | 444 | $js_validation_calls[] = "validate_mandatory_field ('$input_id" . "_1', '$info_id')"; |
433 | 445 | $js_validation_calls[] = "validate_mandatory_field ('$input_id" . "_2', '$info_id')"; |
434 | 446 | $js_validation_calls[] = "validate_mandatory_field ('$input_id" . "_3', '$info_id')"; |
| 447 | + if ($input_type == 'datetime' || $input_type == 'datetime with timezone') { |
| 448 | + // TODO - validate the time fields |
| 449 | + if ($input_type == 'datetime with timezone') { |
| 450 | + // TODO - validate the timezone |
| 451 | + } |
| 452 | + } |
435 | 453 | } else { |
436 | 454 | $js_validation_calls[] = "validate_mandatory_field ('$input_id', '$info_id')"; |
437 | 455 | } |
— | — | @@ -831,6 +849,10 @@ |
832 | 850 | $text = SFFormPrinter::textAreaHTML($num_rows, $num_cols, $template_field->input_name, $cur_value); |
833 | 851 | } elseif ($template_field->input_type == 'date') { |
834 | 852 | $text = SFFormPrinter::dateEntryHTML($template_field->input_name, $cur_value); |
| 853 | + } elseif ($template_field->input_type == 'datetime') { |
| 854 | + $text = SFFormPrinter::dateTimeEntryHTML($template_field->input_name, $cur_value, false); |
| 855 | + } elseif ($template_field->input_type == 'datetime with timezone') { |
| 856 | + $text = SFFormPrinter::dateTimeEntryHTML($template_field->input_name, $cur_value, true); |
835 | 857 | } elseif ($template_field->input_type == 'checkbox') { |
836 | 858 | $text = SFFormPrinter::checkboxHTML($template_field->input_name, $cur_value); |
837 | 859 | } elseif ($template_field->input_type == 'radiobutton') { |
— | — | @@ -1018,7 +1040,11 @@ |
1019 | 1041 | $month = $date['month']; |
1020 | 1042 | $day = $date['day']; |
1021 | 1043 | } else { |
1022 | | - $actual_date = strtotime($date); |
| 1044 | + if ($date == 'now') { // special value |
| 1045 | + $actual_date = time(); |
| 1046 | + } else { |
| 1047 | + $actual_date = strtotime($date); |
| 1048 | + } |
1023 | 1049 | $year = date("Y", $actual_date); |
1024 | 1050 | $month = date("F", $actual_date); |
1025 | 1051 | $day = date("j", $actual_date); |
— | — | @@ -1037,6 +1063,63 @@ |
1038 | 1064 | return $text; |
1039 | 1065 | } |
1040 | 1066 | |
| 1067 | + function dateTimeEntryHTML($input_name, $datetime, $include_timezone) { |
| 1068 | + global $gTabIndex, $gDisabledText; |
| 1069 | + |
| 1070 | + if ($datetime) { |
| 1071 | + // can show up here either as an array or a string, depending on |
| 1072 | + // whether it came from user input or a wiki page |
| 1073 | + if (is_array($datetime)) { |
| 1074 | + if (isset($datetime['hour'])) $hour = $cur_value['hour']; |
| 1075 | + if (isset($datetime['minute'])) $minute = $cur_value['minute']; |
| 1076 | + if (isset($datetime['second'])) $second = $cur_value['second']; |
| 1077 | + if (isset($datetime['ampm24h'])) $ampm24h = $cur_value['ampm24h']; |
| 1078 | + if (isset($datetime['timezone'])) $timezone = $cur_value['timezone']; |
| 1079 | + } else { |
| 1080 | + if ($datetime == 'now') { // special value |
| 1081 | + $actual_date = time(); |
| 1082 | + } else { |
| 1083 | + $actual_date = strtotime($datetime); |
| 1084 | + } |
| 1085 | + $hour = date("g", $actual_date); |
| 1086 | + $minute = date("i", $actual_date); |
| 1087 | + $second = date("s", $actual_date); |
| 1088 | + $ampm24h = date("A", $actual_date); |
| 1089 | + $timezone = date("T", $actual_date); |
| 1090 | + } |
| 1091 | + } else { |
| 1092 | + $cur_date = getdate(); |
| 1093 | + $hour = null; |
| 1094 | + $minute = null; |
| 1095 | + $second = "00"; // default at least this value |
| 1096 | + $timezone = ""; |
| 1097 | + } |
| 1098 | + |
| 1099 | + $text = SFFormPrinter::dateEntryHTML($input_name, $datetime); |
| 1100 | + $text .= ' <input tabindex="' . $gTabIndex . '" name="' . $input_name . '[hour]" type="text" value="' . $hour . '" size="2"/ ' . $gDisabledText . '>'; |
| 1101 | + $gTabIndex++; |
| 1102 | + $text .= ' :<input tabindex="' . $gTabIndex . '" name="' . $input_name . '[minute]" type="text" value="' . $minute . '" size="2"/ ' . $gDisabledText . '>'; |
| 1103 | + $gTabIndex++; |
| 1104 | + $text .= ':<input tabindex="' . $gTabIndex . '" name="' . $input_name . '[second]" type="text" value="' . $second . '" size="2"/ ' . $gDisabledText . '>' . "\n"; |
| 1105 | + |
| 1106 | + $gTabIndex++; |
| 1107 | + $text .= ' <select tabindex="' . $gTabIndex . '" name="' . $input_name . "[ampm24h]\" $gDisabledText>\n"; |
| 1108 | + $ampm24h_options = array('', 'AM', 'PM'); |
| 1109 | + foreach ($ampm24h_options as $value) { |
| 1110 | + $text .= " <option value=\"$value\""; |
| 1111 | + if ($value == $ampm24h) {$text .= " selected=\"selected\""; } |
| 1112 | + $text .= ">$value</option>\n"; |
| 1113 | + } |
| 1114 | + $text .= " </select>\n"; |
| 1115 | + |
| 1116 | + if ($include_timezone) { |
| 1117 | + $gTabIndex++; |
| 1118 | + $text .= ' <input tabindex="' . $gTabIndex . '" name="' . $input_name . '[timezone]" type="text" value="' . $timezone . '" size="2"/ ' . $gDisabledText . '>' . "\n"; |
| 1119 | + } |
| 1120 | + |
| 1121 | + return $text; |
| 1122 | + } |
| 1123 | + |
1041 | 1124 | function radioButtonHTML($input_name, $cur_value, $include_none, $options_array) { |
1042 | 1125 | global $gTabIndex, $gDisabledText; |
1043 | 1126 | |