function show_role_form($role, $roles) {
for ($i = 0; $i < count($roles); $i++) {
- echo " <input type=\"checkbox\" name=\"role_$i\"";
+ echo " <input type=\"checkbox\" id=\"role_$i\" name=\"role_$i\"";
if ($role & (1 << $i)) echo " checked";
- echo ">$roles[$i]\n";
+ echo "><label for=\"role_$i\">$roles[$i]</label>\n";
}
}
}
function show_date_form($name, $date = null) {
- $past = 60;
- $future = 60;
- echo "<select name=\"$name\">\n";
- $now = date('Y-m-d', time());
- list($y, $m, $d) = explode('-', $now);
- $today = mktime(0, 0, 0, $m, $d, $y);
- if (isset($date)) {
- list($y, $m, $d) = explode('-', $date);
- $then = mktime(0, 0, 0, $m, $d, $y);
- if ($then < $today - 86400 * $past || $then > $today + 86400 * $future) {
- option($name, $date, date('l j F Y', $then), $date);
- }
+ if (! isset($date)) $date = date('Y-m-d', time());
+ datepicker($name, $date);
+ }
+
+ function validate_postcode($postcode, &$outward = null, &$inward = null) {
+ /*
+ Valid postcode formats (BS7666):
+
+ AN NLL
+ ABN NLL
+ ANN NLL
+ ABNN NLL
+ ABND NLL
+ ANC NLL
+
+ Where N is a number; A is a letter not including Q, V, X;
+ B is a letter not including I, J, Z; C is a letter from the set
+ ABCDEFGHJKSTUW; D is a letter from the set ABEHMNPRVWXY;
+ L is a letter from the set ABDEFGHJLNPQRSTUWXYZ.
+
+ The postcode GIR 0AA is also valid.
+ */
+ $outward = $inward = null;
+
+ /* Treat blank as valid for convenience. */
+ $postcode = trim($postcode);
+ if (! $postcode) return true;
+
+ $A = '[ABCDEFGHIJKLMNOPRSTUWYZ]';
+ $B = '[ABCDEFGHKLMNOPQRSTUVWXY]';
+ $C = '[ABCDEFGHJKSTUW]';
+ $D = '[ABEHMNPRVWXY]';
+ $L = '[ABDEFGHJLNPQRSTUWXYZ]';
+ $N = '\d';
+ if (! preg_match("/^($A$N|$A$B$N|$A$N$N|$A$B$N$N|$A$B$N$D|$A$N$C|GIR)\s*($N$L$L)$/", $postcode, $m)) return false;
+ if ($m[1] == "GIR" && $m[2] != "0AA") return false;
+ list($ignored, $outward, $inward) = $m;
+ return true;
+ }
+
+ function format_postcode($postcode, $complain = true) {
+ if (validate_postcode($postcode, $outward, $inward)) {
+ return "$outward $inward";
}
- else $date = $now;
- for ($i = -$past; $i < $future; $i++) {
- $then = $today + 86400 * $i;
- option($name, date('Y-m-d', $then), date('l j F Y', $then), $date);
+ if ($complain) {
+ echo "<p>Invalid postcode!</p>\n";
+ return null;
}
- echo "</select>\n";
- return;
- if (! isset($date)) $date = date('Y-m-d');
- list($y, $m, $d) = iso8601_to_ymd($date);
-
- echo "Year: <input name=\"$name" . "_y\" value=\"$y\" size=4 maxlen=4> ";
- echo "Month: <input name=\"$name" . "_m\" value=\"$m\" size=2 maxlen=2> ";
- echo "Day: <input name=\"$name" . "_d\" value=\"$d\" size=2 maxlen=2> ";
}
function get_small_link() {