mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-20 05:35:12 +00:00
Merge pull request #649 from pafcu/master
Improvements to date selection
This commit is contained in:
commit
5ded3d5247
3 changed files with 58 additions and 111 deletions
|
@ -130,144 +130,95 @@ 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');
|
||||
$f = get_config('system','birthday_input_format');
|
||||
if(! $f)
|
||||
$f = 'ymd';
|
||||
$o = datesel($f,'dob',1920,$y,true,$year,$month,$day);
|
||||
|
||||
$o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),mktime(0,0,0,$month,$day,$year),'dob');
|
||||
|
||||
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
|
||||
* @param $format
|
||||
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param $min
|
||||
* unix timestamp of minimum date
|
||||
* @param $max
|
||||
* unix timestap of maximum date
|
||||
* @param $default
|
||||
* unix timestamp of default date
|
||||
* @param $id
|
||||
* id and name of datetimepicker (defaults to "datepicker")
|
||||
* @param $ymin
|
||||
* first year shown in selector dropdown
|
||||
* @param $ymax
|
||||
* last year shown in selector dropdown
|
||||
* @param $allow_blank
|
||||
* allow an empty response on any field. Not currently supported
|
||||
* @param $y
|
||||
* already selected year
|
||||
* @param $m
|
||||
* already selected month
|
||||
* @param $d
|
||||
* already selected day
|
||||
* id and name of datetimepicker (defaults to "datetimepicker")
|
||||
*/
|
||||
function datesel($format, $id, $ymin, $ymax, $allow_blank, $y, $m, $d) {
|
||||
if($ymin > $ymax) list($ymin,$ymax) = array($ymax,$ymin);
|
||||
|
||||
if($id == '') $id = 'datepicker';
|
||||
|
||||
$o = '';
|
||||
|
||||
$dateformat = 'YYYY-MM-DD';
|
||||
$mindate = $ymin ? "new Date($ymin,1,1)" : '';
|
||||
$maxdate = $ymin ? "new Date($ymax,11,31)" : ''; // Yes, JS months really go from 0 to 11.
|
||||
|
||||
$m = $m -1; // Because JavaScript month weirdness
|
||||
|
||||
$defaultDate = ($y != 0 && $m != 0 && $d != 0) ? ", defaultDate: new Date($y,$m,$d)" : '';
|
||||
|
||||
$o .= "<div class='date' id='$id'><input type='text' placeholder='$dateformat' name='$id'/></div>";
|
||||
$o .= "<script type='text/javascript'>\$(function () {\$('#$id').datetimepicker({pickTime: false, minDate: $mindate, maxDate: $maxdate, format: '$dateformat', useCurrent: false $defaultDate}); });</script>";
|
||||
return $o;
|
||||
function datesel($format, $min, $max, $default,$id = 'datepicker') {
|
||||
return datetimesel($format,$min,$max,$default,$id,true,false);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a date selector
|
||||
* @param $format
|
||||
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param $id
|
||||
* id and name of datetimepicker (defaults to "timepicker")
|
||||
* @param $h
|
||||
* already selected hour
|
||||
* @param $m
|
||||
* already selected minute
|
||||
* @param $id
|
||||
* id and name of datetimepicker (defaults to "timepicker")
|
||||
*/
|
||||
function timesel($format,$id,$h,$m) {
|
||||
if($id == '') $id = 'timepicker';
|
||||
|
||||
$timeformat = 'HH:mm';
|
||||
|
||||
$o = '';
|
||||
$o .= "<div class='date' id='$id'><input type='text' placeholder='$timeformat' name='$id'/></div>";
|
||||
$o .= "<script type='text/javascript'>\$(function () {\$('#$id').datetimepicker({pickDate: false, format: '$timeformat', useCurrent: false, defaultDate: new Date(0,0,0,$h,$m)}); });</script>";
|
||||
return $o;
|
||||
function timesel($format,$h,$m,$id='timepicker') {
|
||||
return datetimesel($format,mktime(),mktime(),mktime($h,$m),$id,false,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a datetime selector
|
||||
* @param $format
|
||||
* format string, e.g. 'ymd' or 'mdy'. Not currently supported
|
||||
* @param $min
|
||||
* unix timestamp of minimum date
|
||||
* @param $max
|
||||
* unix timestap of maximum date
|
||||
* @param $default
|
||||
* unix timestamp of default date
|
||||
* @param $id
|
||||
* id and name of datetimepicker (defaults to "datetimepicker")
|
||||
* @param $ymin
|
||||
* first year shown in selector dropdown
|
||||
* @param $ymax
|
||||
* last year shown in selector dropdown
|
||||
* @param $allow_blank
|
||||
* allow an empty response on any field. Not currently supported
|
||||
* @param $y
|
||||
* already selected year
|
||||
* @param $m
|
||||
* already selected month
|
||||
* @param $d
|
||||
* already selected day
|
||||
* @param $h
|
||||
* already selected hour
|
||||
* @param $min
|
||||
* already selected minute
|
||||
* @param $pickdate
|
||||
* true to show date picker (default)
|
||||
* @param $picktime
|
||||
* true to show time picker (default)
|
||||
* @param $minfrom
|
||||
* set minimum date from picker with id $minfrom (none by default)
|
||||
* @param $maxfrom
|
||||
* set maximum date from picker with id $maxfrom (none by default)
|
||||
*/
|
||||
function datetimesel($format, $id, $ymin, $ymax, $allow_blank, $y, $m, $d, $h, $min) {
|
||||
if($ymin > $ymax) list($ymin,$ymax) = array($ymax,$ymin);
|
||||
|
||||
if($id == '') $id = 'datetimepicker';
|
||||
|
||||
function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pickdate = true, $picktime = true, $minfrom = '', $maxfrom = '') {
|
||||
$o = '';
|
||||
|
||||
$dateformat = 'YYYY-MM-DD HH:mm';
|
||||
$mindate = $ymin ? "new Date($ymin,1,1)" : '';
|
||||
$maxdate = $ymin ? "new Date($ymax,11,31)" : '';
|
||||
$dateformat = '';
|
||||
if($pickdate) $dateformat .= 'YYYY-MM-DD';
|
||||
if($pickdate && $picktime) $dateformat .= ' ';
|
||||
if($picktime) $dateformat .= 'HH:mm';
|
||||
|
||||
$mindate = $min ? "new Date($min*1000)" : '';
|
||||
$maxdate = $max ? "new Date($max*1000)" : '';
|
||||
|
||||
$defaultDate = ($y != 0 && $m != 0 && $d != 0) ? ", defaultDate: new Date($y, $m, $d, $h, $min)" : '';
|
||||
$defaultDate = $default ? ", defaultDate: new Date($default*1000)" : '';
|
||||
|
||||
$pickers = '';
|
||||
if(!$pickdate) $pickers .= 'pickDate: false,';
|
||||
if(!$picktime) $pickers .= 'pickTime: false,';
|
||||
|
||||
$extra_js = '';
|
||||
if($minfrom != '')
|
||||
$extra_js .= "\$('#$minfrom').on('dp.change',function (e) { \$('#$id').data('DateTimePicker').setMinDate(e.date); });";
|
||||
|
||||
if($maxfrom != '')
|
||||
$extra_js .= "\$('#$maxfrom').on('dp.change',function (e) { \$('#$id').data('DateTimePicker').setMaxDate(e.date); });";
|
||||
|
||||
$o .= "<div class='date' id='$id'><input type='text' placeholder='$dateformat' name='$id'/></div>";
|
||||
$o .= "<script type='text/javascript'>\$(function () {\$('#$id').datetimepicker({sideBySide: true, minDate: $mindate, maxDate: $maxdate, format: '$dateformat', useCurrent: false $defaultDate}); });</script>";
|
||||
$o .= "<script type='text/javascript'>\$(function () {\$('#$id').datetimepicker({sideBySide: true, $pickers minDate: $mindate, maxDate: $maxdate, format: '$dateformat', useCurrent: false $defaultDate}); $extra_js});</script>";
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,8 +67,10 @@ function events_post(&$a) {
|
|||
// and we'll waste a bunch of time responding to it. Time that
|
||||
// could've been spent doing something else.
|
||||
|
||||
if(strcmp($finish,$start) < 0)
|
||||
$finish = $start;
|
||||
if(strcmp($finish,$start) < 0) {
|
||||
notice( t('Event can not end before it has started.') . EOL);
|
||||
goaway($a->get_baseurl() . '/events/new');
|
||||
}
|
||||
|
||||
$summary = escape_tags(trim($_POST['summary']));
|
||||
$desc = escape_tags(trim($_POST['desc']));
|
||||
|
@ -518,11 +520,6 @@ function events_content(&$a) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$dateformat = datesel_format($f);
|
||||
$timeformat = t('hour:minute');
|
||||
|
||||
require_once('include/acl_selectors.php');
|
||||
|
||||
$perm_defaults = array(
|
||||
|
@ -542,7 +539,6 @@ function events_content(&$a) {
|
|||
'$mid' => $mid,
|
||||
|
||||
'$title' => t('Event details'),
|
||||
'$format_desc' => sprintf( t('Format is %s %s.'),$dateformat,$timeformat),
|
||||
'$desc' => t('Starting date and Title are required.'),
|
||||
'$catsenabled' => $catsenabled,
|
||||
'$placeholdercategory' => t('Categories (comma-separated list)'),
|
||||
|
@ -552,11 +548,11 @@ function events_content(&$a) {
|
|||
'$ftext' => $ftext,
|
||||
'$ModalCANCEL' => t('Cancel'),
|
||||
'$ModalOK' => t('OK'),
|
||||
'$s_dsel' => datetimesel($f,'start_text',$syear+5,$syear,false,$syear,$smonth,$sday,$shour,$sminute),
|
||||
'$s_dsel' => datetimesel($f,mktime(),mktime(0,0,0,0,0,$syear+5),mktime(),'start_text'),
|
||||
'$n_text' => t('Finish date/time is not known or not relevant'),
|
||||
'$n_checked' => $n_checked,
|
||||
'$f_text' => t('Event Finishes:'),
|
||||
'$f_dsel' => datetimesel($f,'finish_text',$fyear+5,$fyear,false,$fyear,$fmonth,$fday,$fhour,$fminute),
|
||||
'$f_dsel' => datetimesel($f,mktime(),mktime(0,0,0,0,0,$fyear+5),mktime(),'finish_text',true,true,'start_text'),
|
||||
'$a_text' => t('Adjust for viewer timezone'),
|
||||
'$a_checked' => $a_checked,
|
||||
'$d_text' => t('Description:'),
|
||||
|
|
|
@ -626,7 +626,7 @@ logger('extra_fields: ' . print_r($extra_fields,true));
|
|||
'$lbl_fullname' => t('Your Full Name:'),
|
||||
'$lbl_title' => t('Title/Description:'),
|
||||
'$lbl_gender' => t('Your Gender:'),
|
||||
'$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
|
||||
'$lbl_bd' => t("Birthday :"),
|
||||
'$lbl_address' => t('Street Address:'),
|
||||
'$lbl_city' => t('Locality/City:'),
|
||||
'$lbl_zip' => t('Postal/Zip Code:'),
|
||||
|
|
Loading…
Reference in a new issue