[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/admin/tool/langimport/ -> index.php (source)

   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   * Fetches language packages from download.moodle.org server
  19   *
  20   * Language packages are available at https://download.moodle.org/langpack/
  21   * in ZIP format together with a file languages.md5 containing their hashes
  22   * and meta info.
  23   * Locally, language packs are saved into $CFG->dataroot/lang/
  24   *
  25   * @package    tool
  26   * @subpackage langimport
  27   * @copyright  2005 Yu Zhang
  28   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  
  31  require(__DIR__.'/../../../config.php');
  32  require_once($CFG->libdir.'/adminlib.php');
  33  
  34  admin_externalpage_setup('toollangimport');
  35  
  36  if (empty($CFG->langotherroot)) {
  37      throw new moodle_exception('missingcfglangotherroot', 'tool_langimport');
  38  }
  39  
  40  $mode               = optional_param('mode', 0, PARAM_INT);              // action
  41  $pack               = optional_param_array('pack', array(), PARAM_SAFEDIR);    // pack to install
  42  $uninstalllang      = optional_param_array('uninstalllang', array(), PARAM_LANG);// installed pack to uninstall
  43  $confirmtounistall  = optional_param('confirmtouninstall', '', PARAM_ALPHAEXT);  // uninstallation confirmation
  44  $purgecaches        = optional_param('purgecaches', false, PARAM_BOOL);  // explicit caches reset
  45  
  46  if ($purgecaches) {
  47      require_sesskey();
  48      get_string_manager()->reset_caches();
  49      redirect($PAGE->url);
  50  }
  51  
  52  if (!empty($CFG->skiplangupgrade)) {
  53      echo $OUTPUT->header();
  54      echo $OUTPUT->box(get_string('langimportdisabled', 'tool_langimport'));
  55      echo $OUTPUT->single_button(new moodle_url($PAGE->url, array('purgecaches' => 1)), get_string('purgestringcaches', 'tool_langimport'));
  56      echo $OUTPUT->footer();
  57      die;
  58  }
  59  
  60  define('INSTALLATION_OF_SELECTED_LANG', 2);
  61  define('DELETION_OF_SELECTED_LANG', 4);
  62  define('UPDATE_ALL_LANG', 5);
  63  
  64  get_string_manager()->reset_caches();
  65  
  66  $controller = new tool_langimport\controller();
  67  
  68  if (($mode == INSTALLATION_OF_SELECTED_LANG) and confirm_sesskey() and !empty($pack)) {
  69      core_php_time_limit::raise();
  70      $controller->install_languagepacks($pack);
  71  }
  72  
  73  if ($mode == DELETION_OF_SELECTED_LANG and (!empty($uninstalllang) or !empty($confirmtounistall))) {
  74      // Actually deleting languages, languages to delete are passed as GET parameter as string
  75      // ...need to populate them to array.
  76      if (empty($uninstalllang)) {
  77          $uninstalllang = explode('-', $confirmtounistall);
  78      }
  79  
  80      if (in_array('en', $uninstalllang)) {
  81          // TODO.
  82          $controller->errors[] = get_string('noenglishuninstall', 'tool_langimport');
  83  
  84      } else if (empty($confirmtounistall) and confirm_sesskey()) { // User chose langs to be deleted, show confirmation.
  85          echo $OUTPUT->header();
  86          echo $OUTPUT->confirm(get_string('uninstallconfirm', 'tool_langimport', implode(', ', $uninstalllang)),
  87                       'index.php?mode='.DELETION_OF_SELECTED_LANG.'&confirmtouninstall='.implode('-', $uninstalllang),
  88                       'index.php');
  89          echo $OUTPUT->footer();
  90          die;
  91  
  92      } else if (confirm_sesskey()) {   // Deleting languages.
  93          foreach ($uninstalllang as $ulang) {
  94              $controller->uninstall_language($ulang);
  95          }
  96  
  97      }
  98  }
  99  
 100  if ($mode == UPDATE_ALL_LANG) {
 101      core_php_time_limit::raise();
 102      $controller->update_all_installed_languages();
 103  }
 104  get_string_manager()->reset_caches();
 105  
 106  echo $OUTPUT->header();
 107  echo $OUTPUT->heading(get_string('langimport', 'tool_langimport'));
 108  
 109  $installedlangs = get_string_manager()->get_list_of_translations(true);
 110  
 111  $missingparents = array();
 112  foreach ($installedlangs as $installedlang => $unused) {
 113      $parent = get_parent_language($installedlang);
 114      if (empty($parent)) {
 115          continue;
 116      }
 117      if (!isset($installedlangs[$parent])) {
 118          $missingparents[$installedlang] = $parent;
 119      }
 120  }
 121  
 122  if ($availablelangs = $controller->availablelangs) {
 123      $remote = true;
 124  } else {
 125      $remote = false;
 126      $availablelangs = array();
 127      echo $OUTPUT->box_start();
 128      print_string('remotelangnotavailable', 'tool_langimport', $CFG->dataroot.'/lang/');
 129      echo $OUTPUT->box_end();
 130  }
 131  
 132  if ($controller->info) {
 133      $info = implode('<br />', $controller->info);
 134      echo $OUTPUT->notification($info, 'notifysuccess');
 135  }
 136  
 137  if ($controller->errors) {
 138      $info = implode('<br />', $controller->errors);
 139      echo $OUTPUT->notification($info, 'notifyproblem');
 140  }
 141  
 142  if ($missingparents) {
 143      foreach ($missingparents as $l => $parent) {
 144          $a = new stdClass();
 145          $a->lang   = $installedlangs[$l];
 146          $a->parent = $parent;
 147          foreach ($availablelangs as $alang) {
 148              if ($alang[0] == $parent) {
 149                  $shortlang = $alang[0];
 150                  $a->parent = $alang[2].' ('.$shortlang.')';
 151              }
 152          }
 153          $info = get_string('missinglangparent', 'tool_langimport', $a);
 154          echo $OUTPUT->notification($info, 'notifyproblem');
 155      }
 156  }
 157  
 158  echo $OUTPUT->box_start();
 159  
 160  echo html_writer::start_tag('table');
 161  echo html_writer::start_tag('tr');
 162  
 163  // list of installed languages
 164  $url = new moodle_url('/admin/tool/langimport/index.php', array('mode' => DELETION_OF_SELECTED_LANG));
 165  echo html_writer::start_tag('td', array('valign' => 'top'));
 166  echo html_writer::start_tag('form', array('id' => 'uninstallform', 'action' => $url->out(), 'method' => 'post'));
 167  echo html_writer::start_tag('fieldset');
 168  echo html_writer::label(get_string('installedlangs', 'tool_langimport'), 'menuuninstalllang');
 169  echo html_writer::empty_tag('br');
 170  echo html_writer::select($installedlangs, 'uninstalllang[]', '', false, array('size' => 15, 'multiple' => 'multiple'));
 171  echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
 172  echo html_writer::empty_tag('br');
 173  echo html_writer::empty_tag('input', array('id' => 'languninstallbutton',
 174                                           'type' => 'submit',
 175                                           'value' => get_string('uninstall', 'tool_langimport'))
 176                              );
 177  echo html_writer::end_tag('fieldset');
 178  echo html_writer::end_tag('form');
 179  if ($remote) {
 180      $url = new moodle_url('/admin/tool/langimport/index.php', array('mode' => UPDATE_ALL_LANG));
 181      echo html_writer::start_tag('form', array('id' => 'updateform', 'action' => $url->out(), 'method' => 'post'));
 182      echo html_writer::tag('fieldset', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('updatelangs','tool_langimport'))));
 183      echo html_writer::end_tag('form');
 184  }
 185  echo html_writer::end_tag('td');
 186  
 187  // list of available languages
 188  $options = array();
 189  foreach ($availablelangs as $alang) {
 190      if (!empty($alang[0]) and trim($alang[0]) !== 'en' and !$controller->is_installed_lang($alang[0], $alang[1])) {
 191          $options[$alang[0]] = $alang[2].' &lrm;('.$alang[0].')&lrm;';
 192      }
 193  }
 194  if (!empty($options)) {
 195      echo html_writer::start_tag('td', array('valign' => 'top'));
 196      $url = new moodle_url('/admin/tool/langimport/index.php', array('mode' => INSTALLATION_OF_SELECTED_LANG));
 197      echo html_writer::start_tag('form', array('id' => 'installform', 'action' => $url->out(), 'method' => 'post'));
 198      echo html_writer::start_tag('fieldset');
 199      echo html_writer::label(get_string('availablelangs','install'), 'menupack');
 200      echo html_writer::empty_tag('br');
 201      echo html_writer::select($options, 'pack[]', '', false, array('size' => 15, 'multiple' => 'multiple'));
 202      echo html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
 203      echo html_writer::empty_tag('br');
 204      echo html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('install','tool_langimport')));
 205      echo html_writer::end_tag('fieldset');
 206      echo html_writer::end_tag('form');
 207      echo html_writer::end_tag('td');
 208  }
 209  
 210  echo html_writer::end_tag('tr');
 211  echo html_writer::end_tag('table');
 212  echo $OUTPUT->box_end();
 213  
 214  $uninstallurl = new moodle_url('/admin/tool/langimport/index.php');
 215  $PAGE->requires->strings_for_js(array('uninstallconfirm', 'uninstall', 'selectlangs', 'noenglishuninstall'),
 216                                  'tool_langimport');
 217  $PAGE->requires->yui_module('moodle-core-languninstallconfirm',
 218                              'Y.M.core.languninstallconfirm.init',
 219                               array(array('uninstallUrl' => $uninstallurl->out()))
 220                              );
 221  echo $OUTPUT->footer();
 222  die();


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1