'; 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; } /** * @brief Generating a Timezone selector * * 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' * * @param string $name Name of the selector * @param string $label Label for the selector * @param string $current Timezone * @param string $help Help text * * @return string Parsed HTML */ 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), )); } /** * @brief General purpose date parse/convert function. * * @param string $from Source timezone * @param string $to Dest timezone * @param string $s Some parseable date/time string * @param string $fmt Output format recognised from php's DateTime class * http://www.php.net/manual/en/datetime.format.php * * @return string Formatted date according to given format */ 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)); } /** * @brief Wrapper for date selector, tailored for use in birthday fields. * * @param string $dob Date of Birth * @return string */ 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; } /** * @brief Returns a date selector * * @param string $format * Format string, e.g. 'ymd' or 'mdy'. Not currently supported * @param string $min * Unix timestamp of minimum date * @param string $max * Unix timestap of maximum date * @param string $default * Unix timestamp of default date * @param string $id * ID and name of datetimepicker (defaults to "datetimepicker") * * @return string Parsed HTML output. */ function datesel($format, $min, $max, $default, $id = 'datepicker') { return datetimesel($format,$min,$max,$default,'',$id,true,false, '',''); } /** * @brief Returns a time selector * * @param string $format * Format string, e.g. 'ymd' or 'mdy'. Not currently supported * @param $h * Already selected hour * @param $m * Already selected minute * @param string $id * ID and name of datetimepicker (defaults to "timepicker") * * @return string Parsed HTML output. */ 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 string $format * format string, e.g. 'ymd' or 'mdy'. Not currently supported * @param string $min * unix timestamp of minimum date * @param string $max * unix timestap of maximum date * @param string $default * unix timestamp of default date * @param string $id * id and name of datetimepicker (defaults to "datetimepicker") * @param bool $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 bool $required default false * * @return string Parsed HTML output. * * @todo Once browser support is better this could probably be replaced with * native HTML5 date picker. */ function datetimesel($format, $min, $max, $default, $label, $id = 'datetimepicker', $pickdate = true, $picktime = true, $minfrom = '', $maxfrom = '', $required = false) { // First day of the week (0 = Sunday) $firstDay = get_pconfig(local_user(),'system','first_day_of_week'); if ($firstDay === false) $firstDay=0; $lang = substr(get_browser_language(), 0, 2); // Check if the detected language is supported by the picker if (!in_array($lang, array("ar", "ro", "id", "bg", "fa", "ru", "uk", "en", "el", "de", "nl", "tr", "fr", "es", "th", "pl", "pt", "ch", "se", "kr", "it", "da", "no", "ja", "vi", "sl", "cs", "hu"))) $lang = ((isset($a->config['system']['language'])) ? $a->config['system']['language'] : 'en'); $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 = ''; $pickers .= ",dayOfWeekStart: ".$firstDay.",lang:'".$lang."'"; if($minfrom != '') $extra_js .= "\$('id_#$minfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#id_$id').data('xdsoft_datetimepicker').setOptions({minDate: currentDateTime})}})"; if($maxfrom != '') $extra_js .= "\$('#id_$maxfrom').data('xdsoft_datetimepicker').setOptions({onChangeDateTime: function (currentDateTime) { \$('#id_$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); $tpl = get_markup_template('field_input.tpl'); $o .= replace_macros($tpl,array( '$field' => array($id, $label, $input_text, '', (($required) ? '*' : ''), 'placeholder="' . $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 .= ' |