Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / timezoneimport.php
blob33400b659c4d4c0b653abe253cb1f30c2d40169d
1 <?php // $Id$
3 // Automatic update of Timezones from a new source
5 require_once('../config.php');
6 require_once($CFG->libdir.'/adminlib.php');
7 require_once($CFG->libdir.'/filelib.php');
8 require_once($CFG->libdir.'/olson.php');
10 admin_externalpage_setup('timezoneimport');
12 $ok = optional_param('ok', 0, PARAM_BOOL);
15 /// Print headings
17 $strimporttimezones = get_string('importtimezones', 'admin');
19 admin_externalpage_print_header();
21 print_heading($strimporttimezones);
23 if (!$ok or !confirm_sesskey()) {
24 $message = '<br /><br />';
25 $message .= $CFG->dataroot.'/temp/olson.txt<br />';
26 $message .= $CFG->dataroot.'/temp/timezones.txt<br />';
27 $message .= '<a href="http://download.moodle.org/timezones/">http://download.moodle.org/timezones/</a><br />';
28 $message .= '<a href="'.$CFG->wwwroot.'/lib/timezones.txt">'.$CFG->dirroot.'/lib/timezones.txt</a><br />';
29 $message .= '<br />';
31 $message = get_string("configintrotimezones", 'admin', $message);
33 notice_yesno($message, 'timezoneimport.php?ok=1&amp;sesskey='.sesskey(), 'index.php');
35 admin_externalpage_print_footer();
36 exit;
40 /// Try to find a source of timezones to import from
42 $importdone = false;
44 /// First, look for an Olson file locally
46 $source = $CFG->dataroot.'/temp/olson.txt';
47 if (!$importdone and is_readable($source)) {
48 if ($timezones = olson_to_timezones($source)) {
49 update_timezone_records($timezones);
50 $importdone = $source;
54 /// Next, look for a CSV file locally
56 $source = $CFG->dataroot.'/temp/timezones.txt';
57 if (!$importdone and is_readable($source)) {
58 if ($timezones = get_records_csv($source, 'timezone')) {
59 update_timezone_records($timezones);
60 $importdone = $source;
64 /// Otherwise, let's try moodle.org's copy
66 $source = 'http://download.moodle.org/timezones/';
67 if (!$importdone and ini_get('allow_url_fopen')) {
68 if (is_readable($source) && $contents = file_get_contents($source)) { // Grab whole page
69 if ($file = fopen($CFG->dataroot.'/temp/timezones.txt', 'w')) { // Make local copy
70 fwrite($file, $contents);
71 fclose($file);
72 if ($timezones = get_records_csv($CFG->dataroot.'/temp/timezones.txt', 'timezone')) { // Parse it
73 update_timezone_records($timezones);
74 $importdone = $source;
76 unlink($CFG->dataroot.'/temp/timezones.txt');
82 /// Final resort, use the copy included in Moodle
84 $source = $CFG->dirroot.'/lib/timezones.txt';
85 if (!$importdone and is_readable($source)) { // Distribution file
86 if ($timezones = get_records_csv($source, 'timezone')) {
87 update_timezone_records($timezones);
88 $importdone = $source;
93 /// That's it!
95 if ($importdone) {
96 $a = null;
97 $a->count = count($timezones);
98 $a->source = $importdone;
99 print_heading(get_string('importtimezonescount', 'admin', $a), '', 3);
101 print_continue('index.php');
103 $timezonelist = array();
104 foreach ($timezones as $timezone) {
105 if (isset($timezonelist[$timezone->name])) {
106 $timezonelist[$timezone->name]++;
107 } else {
108 $timezonelist[$timezone->name] = 1;
111 ksort($timezonelist);
113 echo "<br />";
114 print_simple_box_start('center');
115 foreach ($timezonelist as $name => $count) {
116 echo "$name ($count)<br />";
118 print_simple_box_end();
120 } else {
121 print_heading(get_string('importtimezonesfailed', 'admin'), '', 3);
122 print_continue('index.php');
125 admin_externalpage_print_footer();