'; usort($timezone_identifiers, 'timezone_cmp'); $continent = ''; foreach($timezone_identifiers as $value) { $ex = explode("/", $value); if(count($ex) > 1) { if($ex[0] != $continent) { if($continent != '') $o .= ''; $continent = $ex[0]; $o .= ''; $continent = t('Miscellaneous'); $o .= ''; return $o; }} // return a select using 'field_select_raw' template, with timezones // groupped (primarily) by continent // arguments follow convetion as other field_* template array: // 'name', 'label', $value, 'help' if (!function_exists('field_timezone')){ function field_timezone($name='timezone', $label='', $current = 'America/Los_Angeles', $help){ $options = select_timezone($current); $options = str_replace('','', $options); $tpl = get_markup_template('field_select_raw.tpl'); return replace_macros($tpl, array( '$field' => array($name, $label, $current, $help, $options), )); }} // General purpose date parse/convert function. // $from = source timezone // $to = dest timezone // $s = some parseable date/time string // $fmt = output format if(! function_exists('datetime_convert')) { function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d H:i:s") { // Defaults to UTC if nothing is set, but throws an exception if set to empty string. // Provide some sane defaults regardless. if($from === '') $from = 'UTC'; if($to === '') $to = 'UTC'; if( ($s === '') || (! is_string($s)) ) $s = 'now'; // Slight hackish adjustment so that 'zero' datetime actually returns what is intended // otherwise we end up with -0001-11-30 ... // add 32 days so that we at least get year 00, and then hack around the fact that // months and days always start with 1. if(substr($s,0,10) == '0000-00-00') { $d = new DateTime($s . ' + 32 days', new DateTimeZone('UTC')); return str_replace('1','0',$d->format($fmt)); } try { $from_obj = new DateTimeZone($from); } catch(Exception $e) { $from_obj = new DateTimeZone('UTC'); } try { $d = new DateTime($s, $from_obj); } catch(Exception $e) { logger('datetime_convert: exception: ' . $e->getMessage()); $d = new DateTime('now', $from_obj); } try { $to_obj = new DateTimeZone($to); } catch(Exception $e) { $to_obj = new DateTimeZone('UTC'); } $d->setTimeZone($to_obj); return($d->format($fmt)); }} // wrapper for date selector, tailored for use in birthday fields function dob($dob) { list($year,$month,$day) = sscanf($dob,'%4d-%2d-%2d'); $f = get_config('system','birthday_input_format'); if(! $f) $f = 'ymd'; if($dob === '0000-00-00') $value = ''; else $value = (($year) ? datetime_convert('UTC','UTC',$dob,'Y-m-d') : datetime_convert('UTC','UTC',$dob,'m-d')); $o = ''; // 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; } /** * 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 "datetimepicker") */ if(! function_exists('datesel')) { function datesel($format, $min, $max, $default, $id = 'datepicker') { return datetimesel($format,$min,$max,$default,$id,true,false, '',''); }} /** * returns a time selector * @param $format * format string, e.g. 'ymd' or 'mdy'. Not currently supported * @param $h * already selected hour * @param $m * already selected minute * @param $id * id and name of datetimepicker (defaults to "timepicker") */ if(! function_exists('timesel')) { function timesel($format, $h, $m, $id='timepicker') { return datetimesel($format,new DateTime(),new DateTime(),new DateTime("$h:$m"),$id,false,true); }} /** * @brief 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 string $id * id and name of datetimepicker (defaults to "datetimepicker") * @param boolean $pickdate * true to show date picker (default) * @param boolean $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) * @param boolean $required default false * @return string Parsed HTML output. * * @todo Once browser support is better this could probably be replaced with * native HTML5 date picker. */ if(! function_exists('datetimesel')) { function datetimesel($format, $min, $max, $default, $id = 'datetimepicker', $pickdate = true, $picktime = true, $minfrom = '', $maxfrom = '', $required = false) { $o = ''; $dateformat = ''; if($pickdate) $dateformat .= 'Y-m-d'; if($pickdate && $picktime) $dateformat .= ' '; if($picktime) $dateformat .= 'H:i'; $minjs = $min ? ",minDate: new Date({$min->getTimestamp()}*1000), yearStart: " . $min->format('Y') : ''; $maxjs = $max ? ",maxDate: new Date({$max->getTimestamp()}*1000), yearEnd: " . $max->format('Y') : ''; $input_text = $default ? 'value="' . date($dateformat, $default->getTimestamp()) . '"' : ''; $defaultdatejs = $default ? ",defaultDate: new Date({$default->getTimestamp()}*1000)" : ''; $pickers = ''; if(!$pickdate) $pickers .= ',datepicker: false'; if(!$picktime) $pickers .= ',timepicker: false'; $extra_js = ''; if($minfrom != '') $extra_js .= "\$('#$minfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#$id').data('xdsoft_datetimepicker').setOptions({minDate: currentDateTime})}})"; if($maxfrom != '') $extra_js .= "\$('#$maxfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#$id').data('xdsoft_datetimepicker').setOptions({maxDate: currentDateTime})}})"; $readable_format = $dateformat; $readable_format = str_replace('Y','yyyy',$readable_format); $readable_format = str_replace('m','mm',$readable_format); $readable_format = str_replace('d','dd',$readable_format); $readable_format = str_replace('H','HH',$readable_format); $readable_format = str_replace('i','MM',$readable_format); $o .= "
' . mb_substr(day_translate($dn[$a]),0,3,'UTF-8') . ' | '; $o .= '
---|
"; $day = str_replace(' ',' ',sprintf('%2.2d', $d)); if($started) { if(is_array($links) && isset($links[$d])) $o .= "$day"; else $o .= $day; $d ++; } else $o .= ' '; $o .= ' | '; $dow ++; if(($dow == 7) && ($d <= $l)) { $dow = 0; $o .= '
'; $o .= ' |