Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/tool/timezoneimport/index.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00026     require_once('../../../config.php');
00027     require_once($CFG->libdir.'/adminlib.php');
00028     require_once($CFG->libdir.'/filelib.php');
00029     require_once($CFG->libdir.'/olson.php');
00030 
00031     admin_externalpage_setup('tooltimezoneimport');
00032 
00033     $ok = optional_param('ok', 0, PARAM_BOOL);
00034 
00035 
00037 
00038     $strimporttimezones = get_string('importtimezones', 'tool_timezoneimport');
00039 
00040     echo $OUTPUT->header();
00041 
00042     echo $OUTPUT->heading($strimporttimezones);
00043 
00044     if (!$ok or !confirm_sesskey()) {
00045         $message = '<br /><br />';
00046         $message .= $CFG->tempdir.'/olson.txt<br />';
00047         $message .= $CFG->tempdir.'/timezone.txt<br />';
00048         $message .= '<a href="http://download.moodle.org/timezone/">http://download.moodle.org/timezone/</a><br />';
00049         $message .= '<a href="'.$CFG->wwwroot.'/lib/timezone.txt">'.$CFG->dirroot.'/lib/timezone.txt</a><br />';
00050         $message .= '<br />';
00051 
00052         $message = get_string("configintrotimezones", 'tool_timezoneimport', $message);
00053 
00054         echo $OUTPUT->confirm($message, 'index.php?ok=1', new moodle_url('/admin/index.php'));
00055 
00056         echo $OUTPUT->footer();
00057         exit;
00058     }
00059 
00060 
00062 
00063     $importdone = false;
00064 
00066 
00067     $source = $CFG->tempdir.'/olson.txt';
00068     if (!$importdone and is_readable($source)) {
00069         if ($timezones = olson_to_timezones($source)) {
00070             update_timezone_records($timezones);
00071             $importdone = $source;
00072         }
00073     }
00074 
00076 
00077     $source = $CFG->tempdir.'/timezone.txt';
00078     if (!$importdone and is_readable($source)) {
00079         if ($timezones = get_records_csv($source, 'timezone')) {
00080             update_timezone_records($timezones);
00081             $importdone = $source;
00082         }
00083     }
00084 
00086     $source = 'http://download.moodle.org/timezone/';
00087     if (!$importdone && ($content=download_file_content($source))) {
00088         if ($file = fopen($CFG->tempdir.'/timezone.txt', 'w')) {            // Make local copy
00089             fwrite($file, $content);
00090             fclose($file);
00091             if ($timezones = get_records_csv($CFG->tempdir.'/timezone.txt', 'timezone')) {  // Parse it
00092                 update_timezone_records($timezones);
00093                 $importdone = $source;
00094             }
00095             unlink($CFG->tempdir.'/timezone.txt');
00096         }
00097     }
00098 
00099 
00101     $source = $CFG->dirroot.'/lib/timezone.txt';
00102     if (!$importdone and is_readable($source)) {  // Distribution file
00103         if ($timezones = get_records_csv($source, 'timezone')) {
00104             update_timezone_records($timezones);
00105             $importdone = $source;
00106         }
00107     }
00108 
00109 
00111 
00112     if ($importdone) {
00113         $a = new stdClass();
00114         $a->count = count($timezones);
00115         $a->source  = $importdone;
00116         echo $OUTPUT->heading(get_string('importtimezonescount', 'tool_timezoneimport', $a), 3);
00117 
00118         echo $OUTPUT->continue_button(new moodle_url('/admin/index.php'));
00119 
00120         $timezonelist = array();
00121         foreach ($timezones as $timezone) {
00122             if (is_array($timezone)) {
00123                 $timezone = (object)$timezone;
00124             }
00125             if (isset($timezonelist[$timezone->name])) {
00126                 $timezonelist[$timezone->name]++;
00127             } else {
00128                 $timezonelist[$timezone->name] = 1;
00129             }
00130         }
00131         ksort($timezonelist);
00132 
00133         echo "<br />";
00134         echo $OUTPUT->box_start();
00135         foreach ($timezonelist as $name => $count) {
00136             echo "$name ($count)<br />";
00137         }
00138         echo $OUTPUT->box_end();
00139 
00140     } else {
00141         echo $OUTPUT->heading(get_string('importtimezonesfailed', 'tool_timezoneimport'), 3);
00142         echo $OUTPUT->continue_button(new moodle_url('/admin/index.php'));
00143     }
00144 
00145     echo $OUTPUT->footer();
00146 
00147 
 All Data Structures Namespaces Files Functions Variables Enumerations