2005-04-10 07:08:03 +00:00
|
|
|
<?php // $Id$
|
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
// Automatic update of Timezones from a new source
|
2006-08-18 07:25:17 +00:00
|
|
|
|
2005-04-10 07:08:03 +00:00
|
|
|
require_once('../config.php');
|
2006-09-03 13:10:56 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2005-04-10 07:08:03 +00:00
|
|
|
require_once($CFG->libdir.'/filelib.php');
|
|
|
|
require_once($CFG->libdir.'/olson.php');
|
2007-12-06 18:12:42 +00:00
|
|
|
require_once($CFG->libdir.'/snoopy/Snoopy.class.inc');
|
|
|
|
|
2007-04-30 17:08:34 +00:00
|
|
|
admin_externalpage_setup('timezoneimport');
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2006-08-18 07:25:17 +00:00
|
|
|
$ok = optional_param('ok', 0, PARAM_BOOL);
|
2005-04-10 07:08:03 +00:00
|
|
|
|
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
/// Print headings
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
$strimporttimezones = get_string('importtimezones', 'admin');
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2007-04-30 17:08:34 +00:00
|
|
|
admin_externalpage_print_header();
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
print_heading($strimporttimezones);
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
if (!$ok or !confirm_sesskey()) {
|
2006-11-30 09:16:36 +00:00
|
|
|
$message = '<br /><br />';
|
2005-04-10 09:31:58 +00:00
|
|
|
$message .= $CFG->dataroot.'/temp/olson.txt<br />';
|
|
|
|
$message .= $CFG->dataroot.'/temp/timezones.txt<br />';
|
|
|
|
$message .= '<a href="http://download.moodle.org/timezones/">http://download.moodle.org/timezones/</a><br />';
|
|
|
|
$message .= '<a href="'.$CFG->wwwroot.'/lib/timezones.txt">'.$CFG->dirroot.'/lib/timezones.txt</a><br />';
|
2006-11-30 09:16:36 +00:00
|
|
|
$message .= '<br />';
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
$message = get_string("configintrotimezones", 'admin', $message);
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2006-11-30 09:16:36 +00:00
|
|
|
notice_yesno($message, 'timezoneimport.php?ok=1&sesskey='.sesskey(), 'index.php');
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2007-04-30 17:08:34 +00:00
|
|
|
admin_externalpage_print_footer();
|
2005-04-10 09:31:58 +00:00
|
|
|
exit;
|
|
|
|
}
|
2005-04-10 07:08:03 +00:00
|
|
|
|
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
/// Try to find a source of timezones to import from
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
$importdone = false;
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
/// First, look for an Olson file locally
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
$source = $CFG->dataroot.'/temp/olson.txt';
|
|
|
|
if (!$importdone and is_readable($source)) {
|
|
|
|
if ($timezones = olson_to_timezones($source)) {
|
|
|
|
update_timezone_records($timezones);
|
|
|
|
$importdone = $source;
|
2005-04-10 07:08:03 +00:00
|
|
|
}
|
2005-04-10 09:31:58 +00:00
|
|
|
}
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
/// Next, look for a CSV file locally
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
$source = $CFG->dataroot.'/temp/timezones.txt';
|
|
|
|
if (!$importdone and is_readable($source)) {
|
|
|
|
if ($timezones = get_records_csv($source, 'timezone')) {
|
|
|
|
update_timezone_records($timezones);
|
|
|
|
$importdone = $source;
|
|
|
|
}
|
|
|
|
}
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
/// Otherwise, let's try moodle.org's copy
|
2007-12-06 18:12:42 +00:00
|
|
|
$snoopy = new Snoopy;
|
|
|
|
$snoopy->proxy_host = $CFG->proxyhost;
|
|
|
|
$snoopy->proxy_port = $CFG->proxyport;
|
2005-04-10 09:31:58 +00:00
|
|
|
|
|
|
|
$source = 'http://download.moodle.org/timezones/';
|
2007-12-06 18:12:42 +00:00
|
|
|
if (!$importdone && $snoopy->fetch($source)) {
|
|
|
|
if ($file = fopen($CFG->dataroot.'/temp/timezones.txt', 'w')) { // Make local copy
|
|
|
|
fwrite($file, $snoopy->results);
|
|
|
|
fclose($file);
|
|
|
|
if ($timezones = get_records_csv($CFG->dataroot.'/temp/timezones.txt', 'timezone')) { // Parse it
|
|
|
|
update_timezone_records($timezones);
|
|
|
|
$importdone = $source;
|
2005-04-10 07:08:03 +00:00
|
|
|
}
|
2007-12-06 18:12:42 +00:00
|
|
|
unlink($CFG->dataroot.'/temp/timezones.txt');
|
2005-04-10 09:31:58 +00:00
|
|
|
}
|
|
|
|
}
|
2005-04-10 07:08:03 +00:00
|
|
|
|
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
/// Final resort, use the copy included in Moodle
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
$source = $CFG->dirroot.'/lib/timezones.txt';
|
|
|
|
if (!$importdone and is_readable($source)) { // Distribution file
|
2005-04-10 20:28:48 +00:00
|
|
|
if ($timezones = get_records_csv($source, 'timezone')) {
|
2005-04-10 09:31:58 +00:00
|
|
|
update_timezone_records($timezones);
|
|
|
|
$importdone = $source;
|
2005-04-10 07:08:03 +00:00
|
|
|
}
|
2005-04-10 09:31:58 +00:00
|
|
|
}
|
2005-04-10 07:08:03 +00:00
|
|
|
|
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
/// That's it!
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
if ($importdone) {
|
|
|
|
$a = null;
|
|
|
|
$a->count = count($timezones);
|
|
|
|
$a->source = $importdone;
|
|
|
|
print_heading(get_string('importtimezonescount', 'admin', $a), '', 3);
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2006-08-18 07:25:17 +00:00
|
|
|
print_continue('index.php');
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
$timezonelist = array();
|
|
|
|
foreach ($timezones as $timezone) {
|
|
|
|
if (isset($timezonelist[$timezone->name])) {
|
|
|
|
$timezonelist[$timezone->name]++;
|
|
|
|
} else {
|
|
|
|
$timezonelist[$timezone->name] = 1;
|
2005-04-10 07:08:03 +00:00
|
|
|
}
|
2005-04-10 09:31:58 +00:00
|
|
|
}
|
|
|
|
ksort($timezonelist);
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
echo "<br />";
|
|
|
|
print_simple_box_start('center');
|
|
|
|
foreach ($timezonelist as $name => $count) {
|
|
|
|
echo "$name ($count)<br />";
|
2005-04-10 07:08:03 +00:00
|
|
|
}
|
2005-04-10 09:31:58 +00:00
|
|
|
print_simple_box_end();
|
2005-04-10 07:08:03 +00:00
|
|
|
|
2005-04-10 09:31:58 +00:00
|
|
|
} else {
|
|
|
|
print_heading(get_string('importtimezonesfailed', 'admin'), '', 3);
|
2006-08-18 07:25:17 +00:00
|
|
|
print_continue('index.php');
|
2005-04-10 07:08:03 +00:00
|
|
|
}
|
2005-04-10 09:31:58 +00:00
|
|
|
|
2007-04-30 17:08:34 +00:00
|
|
|
admin_externalpage_print_footer();
|
2005-04-10 07:08:03 +00:00
|
|
|
|
|
|
|
?>
|