Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

   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  
  39  admin_externalpage_setup('toolcustomlang');
  40  $langs = get_string_manager()->get_list_of_translations();
  41  
  42  // pre-output actions
  43  if ($action === 'checkout') {
  44      require_sesskey();
  45      require_capability('tool/customlang:edit', context_system::instance());
  46      if (empty($lng)) {
  47          print_error('missingparameter');
  48      }
  49  
  50      $PAGE->set_cacheable(false);    // progress bar is used here
  51      $output = $PAGE->get_renderer('tool_customlang');
  52      echo $output->header();
  53      echo $output->heading(get_string('pluginname', 'tool_customlang'));
  54      $progressbar = new progress_bar();
  55      $progressbar->create();         // prints the HTML code of the progress bar
  56  
  57      // we may need a bit of extra execution time and memory here
  58      core_php_time_limit::raise(HOURSECS);
  59      raise_memory_limit(MEMORY_EXTRA);
  60      tool_customlang_utils::checkout($lng, $progressbar);
  61  
  62      echo $output->continue_button(new moodle_url('/admin/tool/customlang/edit.php', array('lng' => $lng)), 'get');
  63      echo $output->footer();
  64      exit;
  65  }
  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  }
 136  echo $output->render(new tool_customlang_menu($menu));
 137  
 138  echo $output->footer();