[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Automatic update of Timezones from a new source 19 * 20 * @package tool 21 * @subpackage timezoneimport 22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 require_once('../../../config.php'); 27 require_once($CFG->libdir.'/adminlib.php'); 28 require_once($CFG->libdir.'/filelib.php'); 29 require_once($CFG->libdir.'/olson.php'); 30 31 admin_externalpage_setup('tooltimezoneimport'); 32 33 $ok = optional_param('ok', 0, PARAM_BOOL); 34 35 36 /// Print headings 37 38 $strimporttimezones = get_string('importtimezones', 'tool_timezoneimport'); 39 40 echo $OUTPUT->header(); 41 42 echo $OUTPUT->heading($strimporttimezones); 43 44 if (!$ok or !confirm_sesskey()) { 45 $message = '<br /><br />'; 46 $message .= $CFG->tempdir.'/olson.txt<br />'; 47 $message .= $CFG->tempdir.'/timezone.txt<br />'; 48 $message .= '<a href="https://download.moodle.org/timezone/">https://download.moodle.org/timezone/</a><br />'; 49 $message .= '<a href="'.$CFG->wwwroot.'/lib/timezone.txt">'.$CFG->dirroot.'/lib/timezone.txt</a><br />'; 50 $message .= '<br />'; 51 52 $message = get_string("configintrotimezones", 'tool_timezoneimport', $message); 53 54 echo $OUTPUT->confirm($message, 'index.php?ok=1', new moodle_url('/admin/index.php')); 55 56 echo $OUTPUT->footer(); 57 exit; 58 } 59 60 61 /// Try to find a source of timezones to import from 62 63 $importdone = false; 64 65 /// First, look for an Olson file locally 66 67 $source = $CFG->tempdir.'/olson.txt'; 68 if (!$importdone and is_readable($source)) { 69 if ($timezones = olson_to_timezones($source)) { 70 update_timezone_records($timezones); 71 $importdone = $source; 72 } 73 } 74 75 /// Next, look for a CSV file locally 76 77 $source = $CFG->tempdir.'/timezone.txt'; 78 if (!$importdone and is_readable($source)) { 79 if ($timezones = get_records_csv($source, 'timezone')) { 80 update_timezone_records($timezones); 81 $importdone = $source; 82 } 83 } 84 85 /// Otherwise, let's try moodle.org's copy 86 $source = 'https://download.moodle.org/timezone/'; 87 if (!$importdone && ($content=download_file_content($source))) { 88 if ($file = fopen($CFG->tempdir.'/timezone.txt', 'w')) { // Make local copy 89 fwrite($file, $content); 90 fclose($file); 91 if ($timezones = get_records_csv($CFG->tempdir.'/timezone.txt', 'timezone')) { // Parse it 92 update_timezone_records($timezones); 93 $importdone = $source; 94 } 95 unlink($CFG->tempdir.'/timezone.txt'); 96 } 97 } 98 99 100 /// Final resort, use the copy included in Moodle 101 $source = $CFG->dirroot.'/lib/timezone.txt'; 102 if (!$importdone and is_readable($source)) { // Distribution file 103 if ($timezones = get_records_csv($source, 'timezone')) { 104 update_timezone_records($timezones); 105 $importdone = $source; 106 } 107 } 108 109 110 /// That's it! 111 112 if ($importdone) { 113 $a = new stdClass(); 114 $a->count = count($timezones); 115 $a->source = $importdone; 116 echo $OUTPUT->heading(get_string('importtimezonescount', 'tool_timezoneimport', $a), 3); 117 118 echo $OUTPUT->continue_button(new moodle_url('/admin/index.php')); 119 120 $timezonelist = array(); 121 foreach ($timezones as $timezone) { 122 if (is_array($timezone)) { 123 $timezone = (object)$timezone; 124 } 125 if (isset($timezonelist[$timezone->name])) { 126 $timezonelist[$timezone->name]++; 127 } else { 128 $timezonelist[$timezone->name] = 1; 129 } 130 } 131 ksort($timezonelist); 132 133 echo "<br />"; 134 echo $OUTPUT->box_start(); 135 foreach ($timezonelist as $name => $count) { 136 echo "$name ($count)<br />"; 137 } 138 echo $OUTPUT->box_end(); 139 140 } else { 141 echo $OUTPUT->heading(get_string('importtimezonesfailed', 'tool_timezoneimport'), 3); 142 echo $OUTPUT->continue_button(new moodle_url('/admin/index.php')); 143 } 144 145 echo $OUTPUT->footer(); 146 147
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |