Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   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   * Performs checkout of the strings into the translation table
  19   *
  20   * @package    tool
  21   * @subpackage customlang
  22   * @copyright  2010 David Mudrak <david@moodle.com>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  define('NO_OUTPUT_BUFFERING', true); // progress bar is used here
  27  
  28  require(__DIR__ . '/../../../config.php');
  29  require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/customlang/locallib.php');
  30  require_once($CFG->libdir.'/adminlib.php');
  31  
  32  require_login(null, false);
  33  require_capability('tool/customlang:view', context_system::instance());
  34  
  35  $action  = optional_param('action', '', PARAM_ALPHA);
  36  $confirm = optional_param('confirm', false, PARAM_BOOL);
  37  $lng     = optional_param('lng', '', PARAM_LANG);
  38  $next     = optional_param('next', 'edit', PARAM_ALPHA);
  39  
  40  admin_externalpage_setup('toolcustomlang');
  41  $langs = get_string_manager()->get_list_of_translations();
  42  
  43  // pre-output actions
  44  if ($action === 'checkout') {
  45      require_sesskey();
  46      require_capability('tool/customlang:edit', context_system::instance());
  47      if (empty($lng)) {
  48          print_error('missingparameter');
  49      }
  50  
  51      $PAGE->set_cacheable(false);    // progress bar is used here
  52      $output = $PAGE->get_renderer('tool_customlang');
  53      echo $output->header();
  54      echo $output->heading(get_string('pluginname', 'tool_customlang'));
  55      $progressbar = new progress_bar();
  56      $progressbar->create();         // prints the HTML code of the progress bar
  57  
  58      // we may need a bit of extra execution time and memory here
  59      core_php_time_limit::raise(HOURSECS);
  60      raise_memory_limit(MEMORY_EXTRA);
  61      tool_customlang_utils::checkout($lng, $progressbar);
  62  
  63      echo $output->continue_button(new moodle_url("/admin/tool/customlang/{$next}.php", array('lng' => $lng)), 'get');
  64      echo $output->footer();
  65      exit;
  66  }
  67  if ($action === 'checkin') {
  68      require_sesskey();
  69      require_capability('tool/customlang:edit', context_system::instance());
  70      if (empty($lng)) {
  71          print_error('missingparameter');
  72      }
  73  
  74      if (!$confirm) {
  75          $output = $PAGE->get_renderer('tool_customlang');
  76          echo $output->header();
  77          echo $output->heading(get_string('pluginname', 'tool_customlang'));
  78          echo $output->heading($langs[$lng], 3);
  79          $numofmodified = tool_customlang_utils::get_count_of_modified($lng);
  80          if ($numofmodified != 0) {
  81              echo $output->heading(get_string('modifiednum', 'tool_customlang', $numofmodified), 3);
  82              echo $output->confirm(get_string('confirmcheckin', 'tool_customlang'),
  83                                    new moodle_url($PAGE->url, array('action'=>'checkin', 'lng'=>$lng, 'confirm'=>1)),
  84                                    new moodle_url($PAGE->url, array('lng'=>$lng)));
  85          } else {
  86              echo $output->heading(get_string('modifiedno', 'tool_customlang', $numofmodified), 3);
  87              echo $output->continue_button(new moodle_url($PAGE->url, array('lng' => $lng)));
  88          }
  89          echo $output->footer();
  90          die();
  91  
  92      } else {
  93          tool_customlang_utils::checkin($lng);
  94          redirect($PAGE->url);
  95      }
  96  }
  97  
  98  $output = $PAGE->get_renderer('tool_customlang');
  99  
 100  // output starts here
 101  echo $output->header();
 102  echo $output->heading(get_string('pluginname', 'tool_customlang'));
 103  
 104  if (empty($lng)) {
 105      $s = new single_select($PAGE->url, 'lng', $langs);
 106      $s->label = get_accesshide(get_string('language'));
 107      $s->class = 'langselector';
 108      echo $output->box($OUTPUT->render($s), 'langselectorbox');
 109      echo $OUTPUT->footer();
 110      exit;
 111  }
 112  
 113  echo $output->heading($langs[$lng], 3);
 114  
 115  $numofmodified = tool_customlang_utils::get_count_of_modified($lng);
 116  
 117  if ($numofmodified != 0) {
 118      echo $output->heading(get_string('modifiednum', 'tool_customlang', $numofmodified), 3);
 119  }
 120  
 121  $menu = array();
 122  if (has_capability('tool/customlang:edit', context_system::instance())) {
 123      $menu['checkout'] = array(
 124          'title'     => get_string('checkout', 'tool_customlang'),
 125          'url'       => new moodle_url($PAGE->url, array('action' => 'checkout', 'lng' => $lng)),
 126          'method'    => 'post',
 127      );
 128      if ($numofmodified != 0) {
 129          $menu['checkin'] = array(
 130              'title'     => get_string('checkin', 'tool_customlang'),
 131              'url'       => new moodle_url($PAGE->url, array('action' => 'checkin', 'lng' => $lng)),
 132              'method'    => 'post',
 133          );
 134      }
 135      $menu['import'] = array(
 136          'title'     => get_string('import', 'tool_customlang'),
 137          'url'       => new moodle_url($PAGE->url, ['action' => 'checkout', 'lng' => $lng, 'next' => 'import']),
 138          'method'    => 'post',
 139      );
 140  }
 141  if (has_capability('tool/customlang:export', context_system::instance())) {
 142      $langdir = tool_customlang_utils::get_localpack_location($lng);
 143      if (check_dir_exists(dirname($langdir)) && count(glob("$langdir/*"))) {
 144          $menu['export'] = [
 145              'title'     => get_string('export', 'tool_customlang'),
 146              'url'       => new moodle_url("/admin/tool/customlang/export.php", ['lng' => $lng]),
 147              'method'    => 'post',
 148          ];
 149      }
 150  }
 151  echo $output->render(new tool_customlang_menu($menu));
 152  
 153  echo $output->footer();