mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Centralised timezone list to a function
This commit is contained in:
parent
05097bb889
commit
1bb1333b0b
@ -55,14 +55,14 @@
|
||||
<td>
|
||||
<div><?php print_string('helpforcetimezone', 'admin'); ?></div>
|
||||
<p>
|
||||
<?php if(empty($presets)) { print_string('notimezonesexist', 'admin'); } else { ?>
|
||||
<?php if(empty($timezones)) { print_string('notimezonesexist', 'admin'); } else { ?>
|
||||
<div>
|
||||
<input type="radio" id="timezone1" name="forcetimezone" value="no" <?php if(empty($CFG->forcetimezone)) echo 'checked="checked"';?> /> <label for="timezone1"><?php print_string('timezonenotforced', 'admin'); ?></label>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<input type="radio" id="timezone2" name="forcetimezone" value="force" <?php if(!empty($CFG->forcetimezone)) echo 'checked="checked"';?> /> <label for="timezone2"><?php print_string('timezoneisforcedto', 'admin'); ?></label>
|
||||
<?php choose_from_menu($presets, 'timezonepreset', (empty($CFG->forcetimezone) ? '' : $CFG->forcetimezone), get_string('choose').'...', 'form.timezone2.checked=\'checked\'', ''); ?>
|
||||
<?php choose_from_menu($timezones, 'timezonepreset', (empty($CFG->forcetimezone) ? '' : $CFG->forcetimezone), get_string('choose').'...', 'form.timezone2.checked=\'checked\'', ''); ?>
|
||||
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
@ -83,32 +83,7 @@
|
||||
require_once($CFG->dirroot.'/calendar/lib.php');
|
||||
|
||||
// Populate some variables we 're going to need in calendar.html
|
||||
$records = get_records_sql('SELECT id, name FROM '.$CFG->prefix.'timezone GROUP BY name');
|
||||
$presets = array();
|
||||
|
||||
if (!empty($records)) {
|
||||
foreach($records as $preset) {
|
||||
if (!empty($preset->name)) {
|
||||
$presets[$preset->name] = get_string(strtolower($preset->name), 'timezones');
|
||||
if (substr($presets[$preset->name], 0, 1) == '[') { // No translation found
|
||||
$presets[$preset->name] = $preset->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
asort($presets); // Sort before adding trivial presets because string sorts mess up their order
|
||||
|
||||
for ($i = -13; $i <= 13; $i += .5) {
|
||||
$tzstring = 'GMT';
|
||||
if ($i < 0) {
|
||||
$presets[sprintf("%.1f", $i)] = $tzstring . $i;
|
||||
} else if ($i > 0) {
|
||||
$presets[sprintf("%.1f", $i)] = $tzstring . '+' . $i;
|
||||
} else {
|
||||
$presets[sprintf("%.1f", $i)] = $tzstring;
|
||||
}
|
||||
}
|
||||
$timezones = get_list_of_timezones();
|
||||
|
||||
$weekdays = array(
|
||||
0 => get_string('sunday', 'calendar'),
|
||||
|
@ -225,32 +225,9 @@ class configvarrss extends configvar {
|
||||
'<input name="locale" type="text" size="10" value="'.s($config->locale).'" alt="locale" />' );
|
||||
|
||||
/// timezone
|
||||
$records = get_records_sql('SELECT id, name FROM '.$CFG->prefix.'timezone GROUP BY name');
|
||||
$timezones = array();
|
||||
|
||||
if(!empty($records)) {
|
||||
foreach($records as $preset) {
|
||||
$timezones[$preset->name] = get_string($preset->name, 'timezones');
|
||||
}
|
||||
}
|
||||
|
||||
asort($timezones); // Sort before adding trivial presets because string sorts mess up their order
|
||||
|
||||
for($i = -13; $i <= 13; $i += .5) {
|
||||
$tzstring = get_string('unspecifiedlocation', 'timezones').' / GMT';
|
||||
if($i < 0) {
|
||||
$timezones[sprintf("%.1f", $i)] = $tzstring . $i;
|
||||
}
|
||||
else if($i > 0) {
|
||||
$timezones[sprintf("%.1f", $i)] = $tzstring . '+' . $i;
|
||||
}
|
||||
else {
|
||||
$timezones[sprintf("%.1f", $i)] = $tzstring;
|
||||
}
|
||||
}
|
||||
|
||||
$interface['timezone'] = new configvar ( get_string('configtimezone', 'admin'),
|
||||
choose_from_menu ($timezones, 'timezone', $config->timezone, get_string('serverlocaltime'), '', '99', true ) );
|
||||
choose_from_menu (get_list_of_timezones(), 'timezone', $config->timezone, get_string('serverlocaltime'), '', '99', true ) );
|
||||
|
||||
/// country
|
||||
$interface['country'] = new configvar ( get_string('configcountry', 'admin'),
|
||||
|
@ -4282,6 +4282,48 @@ function get_list_of_pixnames() {
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of picture names in the current language
|
||||
*
|
||||
* @uses $CFG
|
||||
* @return string?
|
||||
* @todo Finish documenting this function.
|
||||
*/
|
||||
function get_list_of_timezones() {
|
||||
global $CFG;
|
||||
|
||||
$lang = current_language();
|
||||
|
||||
if (!file_exists($CFG->dirroot .'/lang/'. $lang .'/timezones.php')) {
|
||||
if ($parentlang = get_string('parentlanguage')) {
|
||||
if (file_exists($CFG->dirroot .'/lang/'. $parentlang .'/timezones.php')) {
|
||||
$lang = $parentlang;
|
||||
} else {
|
||||
$lang = 'en'; // timezones.php must exist in this pack
|
||||
}
|
||||
} else {
|
||||
$lang = 'en'; // timezones.php must exist in this pack
|
||||
}
|
||||
}
|
||||
|
||||
include_once($CFG->dirroot .'/lang/'. $lang .'/timezones.php');
|
||||
|
||||
asort($string);
|
||||
|
||||
for ($i = -13; $i <= 13; $i += .5) {
|
||||
$tzstring = 'GMT';
|
||||
if ($i < 0) {
|
||||
$string[sprintf("%.1f", $i)] = $tzstring . $i;
|
||||
} else if ($i > 0) {
|
||||
$string[sprintf("%.1f", $i)] = $tzstring . '+' . $i;
|
||||
} else {
|
||||
$string[sprintf("%.1f", $i)] = $tzstring;
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can include a given document file (depends on second
|
||||
* parameter) or just return info about it.
|
||||
|
@ -208,34 +208,11 @@ if (isadmin()) {
|
||||
<th><?php print_string('timezone')?>:</th>
|
||||
<td>
|
||||
<?php
|
||||
$records = get_records_sql('SELECT id, name FROM '.$CFG->prefix.'timezone GROUP BY name');
|
||||
$presets = array();
|
||||
|
||||
if(!empty($records)) {
|
||||
foreach($records as $preset) {
|
||||
$presets[$preset->name] = get_string($preset->name, 'timezones');
|
||||
}
|
||||
}
|
||||
|
||||
asort($presets); // Sort before adding trivial presets because string sorts mess up their order
|
||||
|
||||
for($i = -13; $i <= 13; $i += .5) {
|
||||
$tzstring = get_string('unspecifiedlocation', 'timezones').' / GMT';
|
||||
if($i < 0) {
|
||||
$presets[sprintf("%.1f", $i)] = $tzstring . $i;
|
||||
}
|
||||
else if($i > 0) {
|
||||
$presets[sprintf("%.1f", $i)] = $tzstring . '+' . $i;
|
||||
}
|
||||
else {
|
||||
$presets[sprintf("%.1f", $i)] = $tzstring;
|
||||
}
|
||||
}
|
||||
if(!empty($CFG->forcetimezone)) {
|
||||
choose_from_menu($presets, 'timezone', $CFG->forcetimezone, get_string('serverlocaltime'), '', '99', false, true);
|
||||
}
|
||||
else {
|
||||
choose_from_menu($presets, 'timezone', $user->timezone, get_string('serverlocaltime'), '', '99');
|
||||
$timezones = get_list_of_timezones();
|
||||
if (!empty($CFG->forcetimezone)) {
|
||||
choose_from_menu($timezones, 'timezone', $CFG->forcetimezone, get_string('serverlocaltime'), '', '99', false, true);
|
||||
} else {
|
||||
choose_from_menu($timezones, 'timezone', $user->timezone, get_string('serverlocaltime'), '', '99');
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
|
Loading…
x
Reference in New Issue
Block a user