configurable format for date input selectors
This commit is contained in:
parent
1441fce04e
commit
454ff3c7f0
|
@ -84,12 +84,47 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d
|
|||
function dob($dob) {
|
||||
list($year,$month,$day) = sscanf($dob,'%4d-%2d-%2d');
|
||||
$y = datetime_convert('UTC',date_default_timezone_get(),'now','Y');
|
||||
$o = datesel('',1920,$y,true,$year,$month,$day);
|
||||
$f = get_config('system','birthday_input_format');
|
||||
if(! $f)
|
||||
$f = 'ymd';
|
||||
$o = datesel($f,'',1920,$y,true,$year,$month,$day);
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
function datesel_format($f) {
|
||||
|
||||
$o = '';
|
||||
|
||||
if(strlen($f)) {
|
||||
for($x = 0; $x < strlen($f); $x ++) {
|
||||
switch($f[$x]) {
|
||||
case 'y':
|
||||
if(strlen($o))
|
||||
$o .= '-';
|
||||
$o .= t('year');
|
||||
break;
|
||||
case 'm':
|
||||
if(strlen($o))
|
||||
$o .= '-';
|
||||
$o .= t('month');
|
||||
break;
|
||||
case 'd':
|
||||
if(strlen($o))
|
||||
$o .= '-';
|
||||
$o .= t('day');
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
// returns a date selector.
|
||||
// $f = format string, e.g. 'ymd' or 'mdy'
|
||||
// $pre = prefix (if needed) for HTML name and class fields
|
||||
// $ymin = first year shown in selector dropdown
|
||||
// $ymax = last year shown in selector dropdown
|
||||
|
@ -99,9 +134,14 @@ function dob($dob) {
|
|||
// $d = already selected day
|
||||
|
||||
if(! function_exists('datesel')) {
|
||||
function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) {
|
||||
function datesel($f,$pre,$ymin,$ymax,$allow_blank,$y,$m,$d) {
|
||||
|
||||
$o = '';
|
||||
|
||||
if(strlen($f)) {
|
||||
for($z = 0; $z < strlen($f); $z ++) {
|
||||
if($f[$z] === 'y') {
|
||||
|
||||
$o .= "<select name=\"{$pre}year\" class=\"{$pre}year\" size=\"1\">";
|
||||
if($allow_blank) {
|
||||
$sel = (($y == '0000') ? " selected=\"selected\" " : "");
|
||||
|
@ -120,6 +160,8 @@ function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) {
|
|||
$o .= "<option value=\"$x\" $sel>$x</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif($f[$z] == 'm') {
|
||||
|
||||
$o .= "</select> <select name=\"{$pre}month\" class=\"{$pre}month\" size=\"1\">";
|
||||
for($x = (($allow_blank) ? 0 : 1); $x <= 12; $x ++) {
|
||||
|
@ -127,6 +169,8 @@ function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) {
|
|||
$y = (($x) ? $x : '');
|
||||
$o .= "<option value=\"$x\" $sel>$y</option>";
|
||||
}
|
||||
}
|
||||
elseif($f[$z] == 'd') {
|
||||
|
||||
$o .= "</select> <select name=\"{$pre}day\" class=\"{$pre}day\" size=\"1\">";
|
||||
for($x = (($allow_blank) ? 0 : 1); $x <= 31; $x ++) {
|
||||
|
@ -134,6 +178,9 @@ function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) {
|
|||
$y = (($x) ? $x : '');
|
||||
$o .= "<option value=\"$x\" $sel>$y</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$o .= "</select>";
|
||||
return $o;
|
||||
|
|
|
@ -297,6 +297,12 @@ function events_content(&$a) {
|
|||
$fhour = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'H') : 0);
|
||||
$fminute = ((x($orig_event)) ? datetime_convert('UTC', $tz, $fdt, 'i') : 0);
|
||||
|
||||
$f = get_config('system','event_input_format');
|
||||
if(! $f)
|
||||
$f = 'ymd';
|
||||
|
||||
$dateformat = datesel_format($f);
|
||||
$timeformat = t('hour:minute');
|
||||
|
||||
require_once('include/acl_selectors.php');
|
||||
|
||||
|
@ -306,14 +312,14 @@ function events_content(&$a) {
|
|||
'$cid' => $cid,
|
||||
'$uri' => $uri,
|
||||
'$e_text' => t('Event details'),
|
||||
'$e_desc' => t('Format is year-month-day hour:minute. Starting date and Description are required.'),
|
||||
'$e_desc' => sprintf( t('Format is %s %s. Starting date and Description are required.'),$dateformat,$timeformat),
|
||||
'$s_text' => t('Event Starts:') . ' <span class="required">*</span> ',
|
||||
'$s_dsel' => datesel('start',$syear+5,$syear,false,$syear,$smonth,$sday),
|
||||
'$s_dsel' => datesel($f,'start',$syear+5,$syear,false,$syear,$smonth,$sday),
|
||||
'$s_tsel' => timesel('start',$shour,$sminute),
|
||||
'$n_text' => t('Finish date/time is not known or not relevant'),
|
||||
'$n_checked' => $n_checked,
|
||||
'$f_text' => t('Event Finishes:'),
|
||||
'$f_dsel' => datesel('finish',$fyear+5,$fyear,false,$fyear,$fmonth,$fday),
|
||||
'$f_dsel' => datesel($f,'finish',$fyear+5,$fyear,false,$fyear,$fmonth,$fday),
|
||||
'$f_tsel' => timesel('finish',$fhour,$fminute),
|
||||
'$a_text' => t('Adjust for viewer timezone'),
|
||||
'$a_checked' => $a_checked,
|
||||
|
|
|
@ -361,6 +361,9 @@ function profiles_content(&$a) {
|
|||
$a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
|
||||
$a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"include/country.js\" ></script>";
|
||||
|
||||
$f = get_config('system','birthday_input_format');
|
||||
if(! $f)
|
||||
$f = 'ymd';
|
||||
|
||||
$is_default = (($r[0]['is-default']) ? 1 : 0);
|
||||
$tpl = get_markup_template("profile_edit.tpl");
|
||||
|
@ -375,7 +378,7 @@ function profiles_content(&$a) {
|
|||
'$lbl_fullname' => t('Your Full Name:'),
|
||||
'$lbl_title' => t('Title/Description:'),
|
||||
'$lbl_gender' => t('Your Gender:'),
|
||||
'$lbl_bd' => t("Birthday \x28y/m/d\x29:"),
|
||||
'$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
|
||||
'$lbl_address' => t('Street Address:'),
|
||||
'$lbl_city' => t('Locality/City:'),
|
||||
'$lbl_zip' => t('Postal/Zip Code:'),
|
||||
|
|
Loading…
Reference in a new issue