[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/admin/ -> timezoneimport.php (source)

   1  <?php // $Id: timezoneimport.php,v 1.10.4.4 2007/12/31 15:24:22 stronk7 Exp $
   2  
   3      // Automatic update of Timezones from a new source
   4      
   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');
   9      
  10      admin_externalpage_setup('timezoneimport');
  11  
  12      $ok = optional_param('ok', 0, PARAM_BOOL);
  13  
  14  
  15  /// Print headings
  16  
  17      $strimporttimezones = get_string('importtimezones', 'admin');
  18  
  19      admin_externalpage_print_header();
  20  
  21      print_heading($strimporttimezones);
  22  
  23      if (!$ok or !confirm_sesskey()) {
  24          $message = '<br /><br />';
  25          $message .= $CFG->dataroot.'/temp/olson.txt<br />';
  26          $message .= $CFG->dataroot.'/temp/timezone.txt<br />';
  27          $message .= '<a href="http://download.moodle.org/timezone/">http://download.moodle.org/timezone/</a><br />';
  28          $message .= '<a href="'.$CFG->wwwroot.'/lib/timezone.txt">'.$CFG->dirroot.'/lib/timezone.txt</a><br />';
  29          $message .= '<br />';
  30  
  31          $message = get_string("configintrotimezones", 'admin', $message);
  32  
  33          notice_yesno($message, 'timezoneimport.php?ok=1&amp;sesskey='.sesskey(), 'index.php');
  34  
  35          admin_externalpage_print_footer();
  36          exit;
  37      }
  38  
  39  
  40  /// Try to find a source of timezones to import from
  41  
  42      $importdone = false;
  43  
  44  /// First, look for an Olson file locally
  45  
  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;
  51          }
  52      }
  53  
  54  /// Next, look for a CSV file locally
  55  
  56      $source = $CFG->dataroot.'/temp/timezone.txt';
  57      if (!$importdone and is_readable($source)) {
  58          if ($timezones = get_records_csv($source, 'timezone')) {
  59              update_timezone_records($timezones);
  60              $importdone = $source;
  61          }
  62      }
  63  
  64  /// Otherwise, let's try moodle.org's copy
  65      $source = 'http://download.moodle.org/timezone/';
  66      if (!$importdone && ($content=download_file_content($source))) {
  67          if ($file = fopen($CFG->dataroot.'/temp/timezone.txt', 'w')) {            // Make local copy
  68              fwrite($file, $content);
  69              fclose($file);
  70              if ($timezones = get_records_csv($CFG->dataroot.'/temp/timezone.txt', 'timezone')) {  // Parse it
  71                  update_timezone_records($timezones);
  72                  $importdone = $source;
  73              }
  74              unlink($CFG->dataroot.'/temp/timezone.txt');
  75          }
  76      }
  77  
  78  
  79  /// Final resort, use the copy included in Moodle
  80      $source = $CFG->dirroot.'/lib/timezone.txt';
  81      if (!$importdone and is_readable($source)) {  // Distribution file
  82          if ($timezones = get_records_csv($source, 'timezone')) {
  83              update_timezone_records($timezones);
  84              $importdone = $source;
  85          }
  86      }
  87  
  88  
  89  /// That's it!
  90  
  91      if ($importdone) {
  92          $a = null;
  93          $a->count = count($timezones);
  94          $a->source  = $importdone;
  95          print_heading(get_string('importtimezonescount', 'admin', $a), '', 3);
  96  
  97          print_continue('index.php');
  98  
  99          $timezonelist = array();
 100          foreach ($timezones as $timezone) {
 101              if (is_array($timezone)) {
 102                  $timezone = (object)$timezone;
 103              }
 104              if (isset($timezonelist[$timezone->name])) {
 105                  $timezonelist[$timezone->name]++;
 106              } else {
 107                  $timezonelist[$timezone->name] = 1;
 108              }
 109          }
 110          ksort($timezonelist);
 111  
 112          echo "<br />";
 113          print_simple_box_start('center');
 114          foreach ($timezonelist as $name => $count) {
 115              echo "$name ($count)<br />";
 116          }
 117          print_simple_box_end();
 118  
 119      } else {
 120          print_heading(get_string('importtimezonesfailed', 'admin'), '', 3);
 121          print_continue('index.php');
 122      }
 123  
 124      admin_externalpage_print_footer();
 125  
 126  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7