From 7c4f55af9f8e28a761155eaf6d0d379b28d88f23 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sat, 18 Oct 2014 22:17:49 +0200 Subject: Oops, forgot one file --- include/datetime.php | 158 +++++++++++++++++++++++++++------------------------ 1 file changed, 85 insertions(+), 73 deletions(-) (limited to 'include/datetime.php') diff --git a/include/datetime.php b/include/datetime.php index 84ab1e2fa..3d0ae0404 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -134,7 +134,7 @@ function dob($dob) { $f = get_config('system','birthday_input_format'); if(! $f) $f = 'ymd'; - $o = datesel($f,'',1920,$y,true,$year,$month,$day); + $o = datesel($f,'dob',1920,$y,true,$year,$month,$day); return $o; } @@ -169,95 +169,107 @@ function datesel_format($f) { return $o; } +/** + * 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 "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 + */ +function datesel($format, $id, $ymin, $ymax, $allow_blank, $y, $m, $d) { + if($ymin > $ymax) list($ymin,$ymax) = array($ymax,$ymin); -// 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 -// $allow_blank = allow an empty response on any field -// $y = already selected year -// $m = already selected month -// $d = already selected day - - -function datesel($f,$pre,$ymin,$ymax,$allow_blank,$y,$m,$d) { + if($id == '') $id = 'datepicker'; $o = ''; - if(strlen($f)) { - for($z = 0; $z < strlen($f); $z ++) { - if($f[$z] === 'y') { - - $o .= " "; + $o .= "
"; + $o .= ""; return $o; } +/** + * 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 + */ +function timesel($format,$id,$h,$m) { + if($id == '') $id = 'timepicker'; -function timesel($pre,$h,$m) { + $timeformat = 'HH:mm'; $o = ''; - $o .= " : "; + $o .= "
"; + $o .= ""; return $o; } +/** + * returns a datetime selector + * @param $format + * format string, e.g. 'ymd' or 'mdy'. Not currently supported + * @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 + */ +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'; + $o = ''; + $dateformat = 'YYYY-MM-DD HH:mm'; + $mindate = $ymin ? "new Date($ymin,1,1)" : ''; + $maxdate = $ymin ? "new Date($ymax,11,31)" : ''; + + $defaultDate = ($y != 0 && $m != 0 && $d != 0) ? ", defaultDate: new Date($y, $m, $d, $h, $min)" : ''; - - + $o .= "
"; + $o .= ""; + return $o; +} // implements "3 seconds ago" etc. // based on $posted_date, (UTC). @@ -516,4 +528,4 @@ function update_birthdays() { } } } -} \ No newline at end of file +} -- cgit v1.2.3 From 519ef4850021c929764f1175a9aae569d1ae36a6 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sun, 19 Oct 2014 10:47:42 +0200 Subject: Changes in the datetimesel api, prevent user from picking event end date earlier than start date --- include/datetime.php | 121 ++++++++++++++++++++++----------------------------- 1 file changed, 51 insertions(+), 70 deletions(-) (limited to 'include/datetime.php') diff --git a/include/datetime.php b/include/datetime.php index 3d0ae0404..76c3ddb25 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -130,11 +130,12 @@ 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; } @@ -173,101 +174,81 @@ function datesel_format($f) { * 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 .= "
"; - $o .= ""; - 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 .= "
"; - $o .= ""; - 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 .= "
"; - $o .= ""; + $o .= ""; return $o; } -- cgit v1.2.3 From a6c4ae186e9e9962ce9ea364a95b49b5e2cbc81d Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sun, 19 Oct 2014 11:09:51 +0200 Subject: Don't display date format, it's already in the placeholder text --- include/datetime.php | 30 ------------------------------ 1 file changed, 30 deletions(-) (limited to 'include/datetime.php') diff --git a/include/datetime.php b/include/datetime.php index 76c3ddb25..fe0f29c7a 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -140,36 +140,6 @@ function dob($dob) { } -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 -- cgit v1.2.3 From d9f2944565f3bc17b21ddbbde85b3083a003f477 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Fri, 31 Oct 2014 16:09:48 +0100 Subject: Fix problem with default birth date --- include/datetime.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include/datetime.php') diff --git a/include/datetime.php b/include/datetime.php index fe0f29c7a..00bac8ad1 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -134,7 +134,10 @@ function dob($dob) { if(! $f) $f = 'ymd'; - $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),mktime(0,0,0,$month,$day,$year),'dob'); + if ($dob && $dob != '0000-00-00') + $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),mktime(0,0,0,$month,$day,$year),'dob'); + else + $o = datesel($f,mktime(0,0,0,0,0,1900),mktime(),false,'dob'); return $o; } -- cgit v1.2.3