Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 401 and 402] [Versions 401 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   * This file defines settingpages and externalpages under the "courses" category
  19   *
  20   * @package core
  21   * @copyright 2002 onwards Martin Dougiamas (http://dougiamas.com)
  22   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  use core_admin\local\settings\filesize;
  26  
  27  $capabilities = array(
  28      'moodle/backup:backupcourse',
  29      'moodle/category:manage',
  30      'moodle/course:create',
  31      'moodle/site:approvecourse',
  32      'moodle/restore:restorecourse'
  33  );
  34  if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
  35      // Speedup for non-admins, add all caps used on this page.
  36      $ADMIN->add('courses',
  37          new admin_externalpage('coursemgmt', new lang_string('coursemgmt', 'admin'),
  38              $CFG->wwwroot . '/course/management.php',
  39              array('moodle/category:manage', 'moodle/course:create')
  40          )
  41      );
  42      $ADMIN->add('courses',
  43          new admin_externalpage('course_customfield', new lang_string('course_customfield', 'admin'),
  44              $CFG->wwwroot . '/course/customfield.php',
  45              array('moodle/course:configurecustomfields')
  46          )
  47      );
  48      $ADMIN->add('courses',
  49          new admin_externalpage('addcategory', new lang_string('addcategory', 'admin'),
  50              new moodle_url('/course/editcategory.php', array('parent' => 0)),
  51              array('moodle/category:manage')
  52          )
  53      );
  54      $ADMIN->add('courses',
  55          new admin_externalpage('addnewcourse', new lang_string('addnewcourse'),
  56              new moodle_url('/course/edit.php', array('category' => 0)),
  57              array('moodle/category:manage')
  58          )
  59      );
  60      $ADMIN->add('courses',
  61          new admin_externalpage('restorecourse', new lang_string('restorecourse', 'admin'),
  62              new moodle_url('/backup/restorefile.php', array('contextid' => context_system::instance()->id)),
  63              array('moodle/restore:restorecourse')
  64          )
  65      );
  66  
  67      // Course Default Settings Page.
  68      // NOTE: these settings must be applied after all other settings because they depend on them.
  69  
  70      // Main course settings.
  71      $temp = new admin_settingpage('coursesettings', new lang_string('coursesettings'));
  72      require_once($CFG->dirroot.'/course/lib.php');
  73  
  74      $choices = array();
  75      $choices['0'] = new lang_string('hide');
  76      $choices['1'] = new lang_string('show');
  77      $temp->add(new admin_setting_configselect('moodlecourse/visible', new lang_string('visible'), new lang_string('visible_help'),
  78          1, $choices));
  79  
  80      // Enable/disable download course content.
  81      $choices = [
  82          DOWNLOAD_COURSE_CONTENT_DISABLED => new lang_string('no'),
  83          DOWNLOAD_COURSE_CONTENT_ENABLED => new lang_string('yes'),
  84      ];
  85      $downloadcontentsitedefault = new admin_setting_configselect('moodlecourse/downloadcontentsitedefault',
  86              new lang_string('enabledownloadcoursecontent', 'course'),
  87              new lang_string('downloadcoursecontent_help', 'course'), 0, $choices);
  88      $downloadcontentsitedefault->add_dependent_on('downloadcoursecontentallowed');
  89      $temp->add($downloadcontentsitedefault);
  90  
  91      $temp->add(
  92              new admin_setting_configtext(
  93                  'moodlecourse/participantsperpage',
  94                  new lang_string('participants:perpage', 'course'),
  95                  new lang_string('participants:perpage_help', 'course'),
  96                  20
  97              )
  98          );
  99  
 100      // Course format.
 101      $temp->add(new admin_setting_heading('courseformathdr', new lang_string('type_format', 'plugin'), ''));
 102  
 103      $courseformats = get_sorted_course_formats(true);
 104      $formcourseformats = array();
 105      foreach ($courseformats as $courseformat) {
 106          $formcourseformats[$courseformat] = new lang_string('pluginname', "format_$courseformat");
 107      }
 108      $temp->add(new admin_setting_configselect('moodlecourse/format', new lang_string('format'), new lang_string('coursehelpformat'),
 109          'topics', $formcourseformats));
 110  
 111      $temp->add(new admin_setting_configtext('moodlecourse/maxsections', new lang_string('maxnumberweeks'),
 112          new lang_string('maxnumberweeks_desc'), 52));
 113  
 114      $temp->add(new admin_settings_num_course_sections('moodlecourse/numsections', new lang_string('numberweeks'),
 115          new lang_string('coursehelpnumberweeks'), 4));
 116  
 117      $choices = array();
 118      $choices['0'] = new lang_string('hiddensectionscollapsed');
 119      $choices['1'] = new lang_string('hiddensectionsinvisible');
 120      $temp->add(new admin_setting_configselect('moodlecourse/hiddensections', new lang_string('hiddensections'),
 121          new lang_string('coursehelphiddensections'), 1, $choices));
 122  
 123      $choices = array();
 124      $choices[COURSE_DISPLAY_SINGLEPAGE] = new lang_string('coursedisplay_single');
 125      $choices[COURSE_DISPLAY_MULTIPAGE] = new lang_string('coursedisplay_multi');
 126      $temp->add(new admin_setting_configselect('moodlecourse/coursedisplay', new lang_string('coursedisplay'),
 127          new lang_string('coursedisplay_help'), COURSE_DISPLAY_SINGLEPAGE, $choices));
 128  
 129      $temp->add(new admin_setting_configcheckbox('moodlecourse/courseenddateenabled', get_string('courseenddateenabled'),
 130          get_string('courseenddateenabled_desc'), 1));
 131  
 132      $temp->add(new admin_setting_configduration('moodlecourse/courseduration', get_string('courseduration'),
 133          get_string('courseduration_desc'), YEARSECS));
 134  
 135      // Appearance.
 136      $temp->add(new admin_setting_heading('appearancehdr', new lang_string('appearance'), ''));
 137  
 138      $languages = array();
 139      $languages[''] = new lang_string('forceno');
 140      $languages += get_string_manager()->get_list_of_translations();
 141      $temp->add(new admin_setting_configselect('moodlecourse/lang', new lang_string('forcelanguage'), '', key($languages),
 142          $languages));
 143  
 144      $options = range(0, 10);
 145      $temp->add(new admin_setting_configselect('moodlecourse/newsitems', new lang_string('newsitemsnumber'),
 146          new lang_string('coursehelpnewsitemsnumber'), 5, $options));
 147      $temp->add(new admin_setting_configselect('moodlecourse/showgrades', new lang_string('showgrades'),
 148          new lang_string('coursehelpshowgrades'), 1, array(0 => new lang_string('no'), 1 => new lang_string('yes'))));
 149      $temp->add(new admin_setting_configselect('moodlecourse/showreports', new lang_string('showreports'), '', 0,
 150          array(0 => new lang_string('no'), 1 => new lang_string('yes'))));
 151      $temp->add(new admin_setting_configselect('moodlecourse/showactivitydates',
 152          new lang_string('showactivitydates'),
 153          new lang_string('showactivitydates_help'), 1, [
 154              0 => new lang_string('no'),
 155              1 => new lang_string('yes')
 156          ]
 157      ));
 158  
 159      // Files and uploads.
 160      $temp->add(new admin_setting_heading('filesanduploadshdr', new lang_string('filesanduploads'), ''));
 161  
 162      if (!empty($CFG->legacyfilesinnewcourses)) {
 163          $choices = array('0'=>new lang_string('no'), '2'=>new lang_string('yes'));
 164          $temp->add(new admin_setting_configselect('moodlecourse/legacyfiles', new lang_string('courselegacyfiles'),
 165              new lang_string('courselegacyfiles_help'), key($choices), $choices));
 166      }
 167  
 168      $currentmaxbytes = get_config('moodlecourse', 'maxbytes');
 169      if (isset($CFG->maxbytes)) {
 170          $choices = get_max_upload_sizes($CFG->maxbytes, 0, 0, $currentmaxbytes);
 171      } else {
 172          $choices = get_max_upload_sizes(0, 0, 0, $currentmaxbytes);
 173      }
 174      $temp->add(new admin_setting_configselect('moodlecourse/maxbytes', new lang_string('maximumupload'),
 175          new lang_string('coursehelpmaximumupload'), key($choices), $choices));
 176  
 177      // Completion tracking.
 178      $temp->add(new admin_setting_heading('progress', new lang_string('completion','completion'), ''));
 179      $temp->add(new admin_setting_configselect('moodlecourse/enablecompletion', new lang_string('completion', 'completion'),
 180          new lang_string('enablecompletion_help', 'completion'), 1, array(0 => new lang_string('no'), 1 => new lang_string('yes'))));
 181  
 182      // Display completion conditions.
 183      $temp->add(new admin_setting_configselect('moodlecourse/showcompletionconditions',
 184          new lang_string('showcompletionconditions', 'completion'),
 185          new lang_string('showcompletionconditions_help', 'completion'), 1, [
 186              0 => new lang_string('no'),
 187              1 => new lang_string('yes')
 188          ]
 189      ));
 190  
 191      // Groups.
 192      $temp->add(new admin_setting_heading('groups', new lang_string('groups', 'group'), ''));
 193      $choices = array();
 194      $choices[NOGROUPS] = new lang_string('groupsnone', 'group');
 195      $choices[SEPARATEGROUPS] = new lang_string('groupsseparate', 'group');
 196      $choices[VISIBLEGROUPS] = new lang_string('groupsvisible', 'group');
 197      $temp->add(new admin_setting_configselect('moodlecourse/groupmode', new lang_string('groupmode'), '', key($choices),$choices));
 198      $temp->add(new admin_setting_configselect('moodlecourse/groupmodeforce', new lang_string('force'), new lang_string('coursehelpforce'), 0,array(0 => new lang_string('no'), 1 => new lang_string('yes'))));
 199  
 200      $ADMIN->add('courses', $temp);
 201  
 202      // Download course content.
 203      $downloadcoursedefaulturl = new moodle_url('/admin/settings.php', ['section' => 'coursesettings']);
 204      $temp = new admin_settingpage('downloadcoursecontent', new lang_string('downloadcoursecontent', 'course'));
 205      $temp->add(new admin_setting_configcheckbox('downloadcoursecontentallowed',
 206              new lang_string('downloadcoursecontentallowed', 'admin'),
 207              new lang_string('downloadcoursecontentallowed_desc', 'admin', $downloadcoursedefaulturl->out()), 0));
 208  
 209      // 50MB default maximum size per file when downloading course content.
 210      $defaultmaxdownloadsize = 50 * filesize::UNIT_MB;
 211      $temp->add(new filesize('maxsizeperdownloadcoursefile', new lang_string('maxsizeperdownloadcoursefile', 'admin'),
 212              new lang_string('maxsizeperdownloadcoursefile_desc', 'admin'), $defaultmaxdownloadsize, filesize::UNIT_MB));
 213      $temp->hide_if('maxsizeperdownloadcoursefile', 'downloadcoursecontentallowed');
 214  
 215      $ADMIN->add('courses', $temp);
 216  
 217      // "courserequests" settingpage.
 218      $temp = new admin_settingpage('courserequest', new lang_string('courserequest'));
 219      $temp->add(new admin_setting_configcheckbox('enablecourserequests',
 220          new lang_string('enablecourserequests', 'admin'),
 221          new lang_string('configenablecourserequests', 'admin'), 1));
 222      $temp->add(new admin_settings_coursecat_select('defaultrequestcategory',
 223          new lang_string('defaultrequestcategory', 'admin'),
 224          new lang_string('configdefaultrequestcategory', 'admin'), 1));
 225      $temp->add(new admin_setting_configcheckbox('lockrequestcategory',
 226          new lang_string('lockrequestcategory', 'admin'),
 227          new lang_string('configlockrequestcategory', 'admin'), 0));
 228      $temp->add(new admin_setting_users_with_capability('courserequestnotify', new lang_string('courserequestnotify', 'admin'), new lang_string('configcourserequestnotify2', 'admin'), array(), 'moodle/site:approvecourse'));
 229      $ADMIN->add('courses', $temp);
 230  
 231      // Pending course requests.
 232      if (!empty($CFG->enablecourserequests)) {
 233          $ADMIN->add('courses', new admin_externalpage('coursespending', new lang_string('pendingrequests'),
 234                  $CFG->wwwroot . '/course/pending.php', array('moodle/site:approvecourse')));
 235      }
 236  
 237      // Add a category for the Activity Chooser.
 238      $ADMIN->add('courses', new admin_category('activitychooser', new lang_string('activitychoosercategory', 'course')));
 239      $temp = new admin_settingpage('activitychoosersettings', new lang_string('activitychoosersettings', 'course'));
 240      // Tab mode for the activity chooser.
 241      $temp->add(
 242          new admin_setting_configselect(
 243              'activitychoosertabmode',
 244              new lang_string('activitychoosertabmode', 'course'),
 245              new lang_string('activitychoosertabmode_desc', 'course'),
 246              0,
 247              [
 248                  0 => new lang_string('activitychoosertabmodeone', 'course'),
 249                  1 => new lang_string('activitychoosertabmodetwo', 'course'),
 250                  2 => new lang_string('activitychoosertabmodethree', 'course'),
 251              ]
 252          )
 253      );
 254  
 255      // Build a list of plugins that use the footer callback.
 256      $pluginswithfunction = get_plugins_with_function('custom_chooser_footer', 'lib.php');
 257      $pluginsoptions = [];
 258      $pluginsoptions[COURSE_CHOOSER_FOOTER_NONE] = get_string('activitychooserhidefooter', 'course');
 259      if ($pluginswithfunction) {
 260          foreach ($pluginswithfunction as $plugintype => $plugins) {
 261              foreach ($plugins as $pluginname => $pluginfunction) {
 262                  $plugin = $plugintype.'_'.$pluginname;
 263                  $pluginsoptions[$plugin] = get_string('pluginname', $plugin);
 264              }
 265          }
 266      }
 267  
 268      // Select what plugin to show in the footer.
 269      $temp->add(
 270          new admin_setting_configselect(
 271              'activitychooseractivefooter',
 272              new lang_string('activitychooseractivefooter', 'course'),
 273              new lang_string('activitychooseractivefooter_desc', 'course'),
 274              COURSE_CHOOSER_FOOTER_NONE,
 275              $pluginsoptions
 276          )
 277      );
 278  
 279      $ADMIN->add('activitychooser', $temp);
 280      $ADMIN->add('activitychooser',
 281          new admin_externalpage('activitychooserrecommended', new lang_string('activitychooserrecommendations', 'course'),
 282              new moodle_url('/course/recommendations.php'),
 283              array('moodle/course:recommendactivity')
 284          )
 285      );
 286  
 287      // Add a category for backups.
 288      $ADMIN->add('courses', new admin_category('backups', new lang_string('backups','admin')));
 289  
 290      // Create a page for general backups configuration and defaults.
 291      $temp = new admin_settingpage('backupgeneralsettings', new lang_string('generalbackdefaults', 'backup'), 'moodle/backup:backupcourse');
 292  
 293      // General configuration section.
 294      $temp->add(new admin_setting_configselect('backup/loglifetime', new lang_string('loglifetime', 'backup'), new lang_string('configloglifetime', 'backup'), 30, array(
 295          1   => new lang_string('numdays', '', 1),
 296          2   => new lang_string('numdays', '', 2),
 297          3   => new lang_string('numdays', '', 3),
 298          5   => new lang_string('numdays', '', 5),
 299          7   => new lang_string('numdays', '', 7),
 300          10  => new lang_string('numdays', '', 10),
 301          14  => new lang_string('numdays', '', 14),
 302          20  => new lang_string('numdays', '', 20),
 303          30  => new lang_string('numdays', '', 30),
 304          60  => new lang_string('numdays', '', 60),
 305          90  => new lang_string('numdays', '', 90),
 306          120 => new lang_string('numdays', '', 120),
 307          180 => new lang_string('numdays', '', 180),
 308          365 => new lang_string('numdays', '', 365)
 309      )));
 310  
 311      // General defaults section.
 312      $temp->add(new admin_setting_heading('generalsettings', new lang_string('generalsettings', 'backup'), ''));
 313      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_users', new lang_string('generalusers','backup'), new lang_string('configgeneralusers','backup'), array('value'=>1, 'locked'=>0)));
 314      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_anonymize', new lang_string('generalanonymize','backup'), new lang_string('configgeneralanonymize','backup'), array('value'=>0, 'locked'=>0)));
 315      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_role_assignments', new lang_string('generalroleassignments','backup'), new lang_string('configgeneralroleassignments','backup'), array('value'=>1, 'locked'=>0)));
 316      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_activities', new lang_string('generalactivities','backup'), new lang_string('configgeneralactivities','backup'), array('value'=>1, 'locked'=>0)));
 317      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_blocks', new lang_string('generalblocks','backup'), new lang_string('configgeneralblocks','backup'), array('value'=>1, 'locked'=>0)));
 318      $temp->add(new admin_setting_configcheckbox_with_lock(
 319              'backup/backup_general_files',
 320              new lang_string('generalfiles', 'backup'),
 321              new lang_string('configgeneralfiles', 'backup'),
 322              array('value' => '1', 'locked' => 0)));
 323      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_filters', new lang_string('generalfilters','backup'), new lang_string('configgeneralfilters','backup'), array('value'=>1, 'locked'=>0)));
 324      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_comments', new lang_string('generalcomments','backup'), new lang_string('configgeneralcomments','backup'), array('value'=>1, 'locked'=>0)));
 325      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_badges', new lang_string('generalbadges','backup'), new lang_string('configgeneralbadges','backup'), array('value'=>1,'locked'=>0)));
 326      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_calendarevents', new lang_string('generalcalendarevents','backup'), new lang_string('configgeneralcalendarevents','backup'), array('value'=>1, 'locked'=>0)));
 327      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_userscompletion', new lang_string('generaluserscompletion','backup'), new lang_string('configgeneraluserscompletion','backup'), array('value'=>1, 'locked'=>0)));
 328      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_logs', new lang_string('generallogs','backup'), new lang_string('configgenerallogs','backup'), array('value'=>0, 'locked'=>0)));
 329      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_histories', new lang_string('generalhistories','backup'), new lang_string('configgeneralhistories','backup'), array('value'=>0, 'locked'=>0)));
 330      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_questionbank', new lang_string('generalquestionbank','backup'), new lang_string('configgeneralquestionbank','backup'), array('value'=>1, 'locked'=>0)));
 331      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_groups',
 332              new lang_string('generalgroups', 'backup'), new lang_string('configgeneralgroups', 'backup'),
 333              array('value' => 1, 'locked' => 0)));
 334      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_competencies', new lang_string('generalcompetencies','backup'), new lang_string('configgeneralcompetencies','backup'), array('value'=>1, 'locked'=>0)));
 335      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_contentbankcontent',
 336          new lang_string('generalcontentbankcontent', 'backup'),
 337          new lang_string('configgeneralcontentbankcontent', 'backup'),
 338          ['value' => 1, 'locked' => 0])
 339      );
 340  
 341      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_general_legacyfiles',
 342          new lang_string('generallegacyfiles', 'backup'),
 343          new lang_string('configlegacyfiles', 'backup'), array('value' => 1, 'locked' => 0)));
 344      $ADMIN->add('backups', $temp);
 345  
 346      // Create a page for general import configuration and defaults.
 347      $temp = new admin_settingpage('importgeneralsettings', new lang_string('importgeneralsettings', 'backup'), 'moodle/backup:backupcourse');
 348      $temp->add(new admin_setting_configtext('backup/import_general_maxresults', new lang_string('importgeneralmaxresults', 'backup'), new lang_string('importgeneralmaxresults_desc', 'backup'), 10));
 349      $temp->add(new admin_setting_configcheckbox('backup/import_general_duplicate_admin_allowed',
 350              new lang_string('importgeneralduplicateadminallowed', 'backup'),
 351              new lang_string('importgeneralduplicateadminallowed_desc', 'backup'), 0));
 352  
 353      // Import defaults section.
 354      $temp->add(new admin_setting_heading('importsettings', new lang_string('importsettings', 'backup'), ''));
 355      $temp->add(new admin_setting_configcheckbox_with_lock(
 356              'backup/backup_import_permissions',
 357              new lang_string('generalpermissions', 'backup'),
 358              new lang_string('configgeneralpermissions', 'backup'),
 359              array('value' => 0, 'locked' => 0)));
 360      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_activities', new lang_string('generalactivities','backup'), new lang_string('configgeneralactivities','backup'), array('value'=>1, 'locked'=>0)));
 361      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_blocks', new lang_string('generalblocks','backup'), new lang_string('configgeneralblocks','backup'), array('value'=>1, 'locked'=>0)));
 362      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_filters', new lang_string('generalfilters','backup'), new lang_string('configgeneralfilters','backup'), array('value'=>1, 'locked'=>0)));
 363      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_calendarevents', new lang_string('generalcalendarevents','backup'), new lang_string('configgeneralcalendarevents','backup'), array('value'=>1, 'locked'=>0)));
 364      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_questionbank', new lang_string('generalquestionbank','backup'), new lang_string('configgeneralquestionbank','backup'), array('value'=>1, 'locked'=>0)));
 365      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_groups',
 366              new lang_string('generalgroups', 'backup'), new lang_string('configgeneralgroups', 'backup'),
 367              array('value' => 1, 'locked' => 0)));
 368      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_competencies', new lang_string('generalcompetencies','backup'), new lang_string('configgeneralcompetencies','backup'), array('value'=>1, 'locked'=>0)));
 369      $temp->add(new admin_setting_configcheckbox_with_lock(
 370          'backup/backup_import_contentbankcontent',
 371          new lang_string('generalcontentbankcontent', 'backup'),
 372          new lang_string('configgeneralcontentbankcontent', 'backup'),
 373          ['value' => 1, 'locked' => 0])
 374      );
 375      $temp->add(new admin_setting_configcheckbox_with_lock('backup/backup_import_legacyfiles',
 376          new lang_string('generallegacyfiles', 'backup'),
 377          new lang_string('configlegacyfiles', 'backup'), array('value' => 1, 'locked' => 0)));
 378  
 379      $ADMIN->add('backups', $temp);
 380  
 381      // Create a page for automated backups configuration and defaults.
 382      $temp = new admin_settingpage('automated', new lang_string('automatedsetup','backup'), 'moodle/backup:backupcourse');
 383  
 384      // Automated configuration section.
 385      $temp->add(new admin_setting_configselect('backup/backup_auto_active', new lang_string('active'),  new lang_string('autoactivedescription', 'backup'), 0, array(
 386          0 => new lang_string('autoactivedisabled', 'backup'),
 387          1 => new lang_string('autoactiveenabled', 'backup'),
 388          2 => new lang_string('autoactivemanual', 'backup')
 389      )));
 390      $temp->add(new admin_setting_special_backupdays());
 391      $temp->add(new admin_setting_configtime('backup/backup_auto_hour', 'backup_auto_minute', new lang_string('executeat'),
 392              new lang_string('backupexecuteathelp'), array('h' => 0, 'm' => 0)));
 393      $storageoptions = array(
 394          0 => new lang_string('storagecourseonly', 'backup'),
 395          1 => new lang_string('storageexternalonly', 'backup'),
 396          2 => new lang_string('storagecourseandexternal', 'backup')
 397      );
 398      $temp->add(new admin_setting_configselect('backup/backup_auto_storage', new lang_string('automatedstorage', 'backup'), new lang_string('automatedstoragehelp', 'backup'), 0, $storageoptions));
 399      $temp->add(new admin_setting_special_backup_auto_destination());
 400  
 401      $maxkeptoptions = array(
 402          0 => new lang_string('all'), 1 => '1',
 403          2 => '2',
 404          3 => '3',
 405          4 => '4',
 406          5 => '5',
 407          10 => '10',
 408          20 => '20',
 409          30 => '30',
 410          40 => '40',
 411          50 => '50',
 412          100 => '100',
 413          200 => '200',
 414          300 => '300',
 415          400 => '400',
 416          500 => '500');
 417      $temp->add(new admin_setting_configselect('backup/backup_auto_max_kept', new lang_string('automatedmaxkept', 'backup'),
 418              new lang_string('automatedmaxkepthelp', 'backup'), 1, $maxkeptoptions));
 419  
 420      $automateddeletedaysoptions = array(
 421          0 => new lang_string('never'),
 422          1000 => new lang_string('numdays', '', 1000),
 423          365  => new lang_string('numdays', '', 365),
 424          180  => new lang_string('numdays', '', 180),
 425          150  => new lang_string('numdays', '', 150),
 426          120  => new lang_string('numdays', '', 120),
 427          90   => new lang_string('numdays', '', 90),
 428          60   => new lang_string('numdays', '', 60),
 429          35   => new lang_string('numdays', '', 35),
 430          10   => new lang_string('numdays', '', 10),
 431          5    => new lang_string('numdays', '', 5),
 432          2    => new lang_string('numdays', '', 2)
 433      );
 434      $temp->add(new admin_setting_configselect('backup/backup_auto_delete_days', new lang_string('automateddeletedays', 'backup'),
 435              '', 0, $automateddeletedaysoptions));
 436  
 437      $minkeptoptions = array(
 438          0 => new lang_string('none'),
 439          1 => '1',
 440          2 => '2',
 441          5 => '5',
 442          10 => '10',
 443          20 => '20',
 444          30 => '30',
 445          40 => '40',
 446          50 => '50',
 447          100 => '100',
 448          200 => '200',
 449          300 => '300',
 450          400 => '400'
 451      );
 452      $temp->add(new admin_setting_configselect('backup/backup_auto_min_kept', new lang_string('automatedminkept', 'backup'),
 453              new lang_string('automatedminkepthelp', 'backup'), 0, $minkeptoptions));
 454  
 455      $temp->add(new admin_setting_configcheckbox('backup/backup_shortname', new lang_string('backup_shortname', 'admin'), new lang_string('backup_shortnamehelp', 'admin'), 0));
 456      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_skip_hidden', new lang_string('skiphidden', 'backup'), new lang_string('skiphiddenhelp', 'backup'), 1));
 457      $temp->add(new admin_setting_configselect('backup/backup_auto_skip_modif_days', new lang_string('skipmodifdays', 'backup'), new lang_string('skipmodifdayshelp', 'backup'), 30, array(
 458          0 => new lang_string('never'),
 459          1 => new lang_string('numdays', '', 1),
 460          2 => new lang_string('numdays', '', 2),
 461          3 => new lang_string('numdays', '', 3),
 462          5 => new lang_string('numdays', '', 5),
 463          7 => new lang_string('numdays', '', 7),
 464          10 => new lang_string('numdays', '', 10),
 465          14 => new lang_string('numdays', '', 14),
 466          20 => new lang_string('numdays', '', 20),
 467          30 => new lang_string('numdays', '', 30),
 468          60 => new lang_string('numdays', '', 60),
 469          90 => new lang_string('numdays', '', 90),
 470          120 => new lang_string('numdays', '', 120),
 471          180 => new lang_string('numdays', '', 180),
 472          365 => new lang_string('numdays', '', 365)
 473      )));
 474      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_skip_modif_prev', new lang_string('skipmodifprev', 'backup'), new lang_string('skipmodifprevhelp', 'backup'), 0));
 475  
 476      // Automated defaults section.
 477      $temp->add(new admin_setting_heading('automatedsettings', new lang_string('automatedsettings','backup'), new lang_string('recyclebin_desc', 'backup')));
 478      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_users', new lang_string('generalusers', 'backup'), new lang_string('configgeneralusers', 'backup'), 1));
 479      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_role_assignments', new lang_string('generalroleassignments','backup'), new lang_string('configgeneralroleassignments','backup'), 1));
 480      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_activities', new lang_string('generalactivities', 'backup'),
 481          new lang_string('backupautoactivitiesdescription', 'backup'), 1));
 482      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_blocks', new lang_string('generalblocks','backup'), new lang_string('configgeneralblocks','backup'), 1));
 483      $temp->add(new admin_setting_configcheckbox(
 484              'backup/backup_auto_files',
 485              new lang_string('generalfiles', 'backup'),
 486              new lang_string('configgeneralfiles', 'backup'), '1'));
 487      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_filters', new lang_string('generalfilters','backup'), new lang_string('configgeneralfilters','backup'), 1));
 488      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_comments', new lang_string('generalcomments','backup'), new lang_string('configgeneralcomments','backup'), 1));
 489      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_badges', new lang_string('generalbadges','backup'), new lang_string('configgeneralbadges','backup'), 1));
 490      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_calendarevents', new lang_string('generalcalendarevents','backup'), new lang_string('configgeneralcalendarevents','backup'), 1));
 491      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_userscompletion', new lang_string('generaluserscompletion','backup'), new lang_string('configgeneraluserscompletion','backup'), 1));
 492      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_logs', new lang_string('generallogs', 'backup'), new lang_string('configgenerallogs', 'backup'), 0));
 493      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_histories', new lang_string('generalhistories','backup'), new lang_string('configgeneralhistories','backup'), 0));
 494      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_questionbank', new lang_string('generalquestionbank','backup'), new lang_string('configgeneralquestionbank','backup'), 1));
 495      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_groups', new lang_string('generalgroups', 'backup'),
 496              new lang_string('configgeneralgroups', 'backup'), 1));
 497      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_competencies', new lang_string('generalcompetencies','backup'), new lang_string('configgeneralcompetencies','backup'), 1));
 498      $temp->add(new admin_setting_configcheckbox(
 499          'backup/backup_auto_contentbankcontent',
 500          new lang_string('generalcontentbankcontent', 'backup'),
 501          new lang_string('configgeneralcontentbankcontent', 'backup'),
 502          1)
 503      );
 504  
 505      $temp->add(new admin_setting_configcheckbox('backup/backup_auto_legacyfiles',
 506          new lang_string('generallegacyfiles', 'backup'),
 507          new lang_string('configlegacyfiles', 'backup'), 1));
 508  
 509      //$temp->add(new admin_setting_configcheckbox('backup/backup_auto_messages', new lang_string('messages', 'message'), new lang_string('backupmessageshelp','message'), 0));
 510      //$temp->add(new admin_setting_configcheckbox('backup/backup_auto_blogs', new lang_string('blogs', 'blog'), new lang_string('backupblogshelp','blog'), 0));
 511  
 512      $ADMIN->add('backups', $temp);
 513  
 514      // Create a page for general restore configuration and defaults.
 515      $temp = new admin_settingpage('restoregeneralsettings', new lang_string('generalrestoredefaults', 'backup'));
 516  
 517      // General restore defaults.
 518      $temp->add(new admin_setting_heading('generalsettings', new lang_string('generalrestoresettings', 'backup'), ''));
 519  
 520      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_users',
 521          new lang_string('generalusers', 'backup'), new lang_string('configrestoreusers', 'backup'),
 522          array('value' => 1, 'locked' => 0)));
 523      // Can not use actual constants here because we'd need to include 100 of backup/restore files.
 524      $options = [
 525          0/*backup::ENROL_NEVER*/     => get_string('rootsettingenrolments_never', 'backup'),
 526          1/*backup::ENROL_WITHUSERS*/ => get_string('rootsettingenrolments_withusers', 'backup'),
 527          2/*backup::ENROL_ALWAYS*/    => get_string('rootsettingenrolments_always', 'backup'),
 528      ];
 529      $temp->add(new admin_setting_configselect_with_lock('restore/restore_general_enrolments',
 530          new lang_string('generalenrolments', 'backup'), new lang_string('configrestoreenrolments', 'backup'),
 531          array('value' => 1/*backup::ENROL_WITHUSERS*/, 'locked' => 0), $options));
 532      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_role_assignments',
 533          new lang_string('generalroleassignments', 'backup'),
 534          new lang_string('configrestoreroleassignments', 'backup'), array('value' => 1, 'locked' => 0)));
 535      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_permissions',
 536          new lang_string('generalpermissions', 'backup'),
 537          new lang_string('configrestorepermissions', 'backup'), array('value' => 1, 'locked' => 0)));
 538      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_activities',
 539          new lang_string('generalactivities', 'backup'),
 540          new lang_string('configrestoreactivities', 'backup'), array('value' => 1, 'locked' => 0)));
 541      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_blocks',
 542          new lang_string('generalblocks', 'backup'),
 543          new lang_string('configrestoreblocks', 'backup'), array('value' => 1, 'locked' => 0)));
 544      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_filters',
 545          new lang_string('generalfilters', 'backup'),
 546          new lang_string('configrestorefilters', 'backup'), array('value' => 1, 'locked' => 0)));
 547      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_comments',
 548          new lang_string('generalcomments', 'backup'),
 549          new lang_string('configrestorecomments', 'backup'), array('value' => 1, 'locked' => 0)));
 550      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_badges',
 551          new lang_string('generalbadges', 'backup'),
 552          new lang_string('configrestorebadges', 'backup'), array('value' => 1, 'locked' => 0)));
 553      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_calendarevents',
 554          new lang_string('generalcalendarevents', 'backup'),
 555          new lang_string('configrestorecalendarevents', 'backup'), array('value' => 1, 'locked' => 0)));
 556      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_userscompletion',
 557          new lang_string('generaluserscompletion', 'backup'),
 558          new lang_string('configrestoreuserscompletion', 'backup'), array('value' => 1, 'locked' => 0)));
 559      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_logs',
 560          new lang_string('generallogs', 'backup'),
 561          new lang_string('configrestorelogs', 'backup'), array('value' => 1, 'locked' => 0)));
 562      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_histories',
 563          new lang_string('generalhistories', 'backup'),
 564          new lang_string('configrestorehistories', 'backup'), array('value' => 1, 'locked' => 0)));
 565      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_groups',
 566          new lang_string('generalgroups', 'backup'), new lang_string('configrestoregroups', 'backup'),
 567          array('value' => 1, 'locked' => 0)));
 568      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_competencies',
 569          new lang_string('generalcompetencies', 'backup'),
 570          new lang_string('configrestorecompetencies', 'backup'), array('value' => 1, 'locked' => 0)));
 571      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_contentbankcontent',
 572          new lang_string('generalcontentbankcontent', 'backup'),
 573          new lang_string('configrestorecontentbankcontent', 'backup'), array('value' => 1, 'locked' => 0)));
 574      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_general_legacyfiles',
 575          new lang_string('generallegacyfiles', 'backup'),
 576          new lang_string('configlegacyfiles', 'backup'), array('value' => 1, 'locked' => 0)));
 577  
 578      // Restore defaults when merging into another course.
 579      $temp->add(new admin_setting_heading('mergerestoredefaults', new lang_string('mergerestoredefaults', 'backup'), ''));
 580  
 581      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_merge_overwrite_conf',
 582          new lang_string('setting_overwrite_conf', 'backup'),
 583      new lang_string('config_overwrite_conf', 'backup'), array('value' => 0, 'locked' => 0)));
 584  
 585      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_merge_course_fullname',
 586          new lang_string('setting_overwrite_course_fullname', 'backup'),
 587          new lang_string('config_overwrite_course_fullname', 'backup'), array('value' => 1, 'locked' => 0)));
 588      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_merge_course_shortname',
 589          new lang_string('setting_overwrite_course_shortname', 'backup'),
 590          new lang_string('config_overwrite_course_shortname', 'backup'), array('value' => 1, 'locked' => 0)));
 591      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_merge_course_startdate',
 592          new lang_string('setting_overwrite_course_startdate', 'backup'),
 593          new lang_string('config_overwrite_course_startdate', 'backup'), array('value' => 1, 'locked' => 0)));
 594  
 595      // Restore defaults when replacing course contents.
 596      $temp->add(new admin_setting_heading('replacerestoredefaults', new lang_string('replacerestoredefaults', 'backup'), ''));
 597  
 598      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_replace_overwrite_conf',
 599          new lang_string('setting_overwrite_conf', 'backup'),
 600          new lang_string('config_overwrite_conf', 'backup'), array('value' => 0, 'locked' => 0)));
 601  
 602      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_replace_course_fullname',
 603          new lang_string('setting_overwrite_course_fullname', 'backup'),
 604          new lang_string('config_overwrite_course_fullname', 'backup'), array('value' => 1, 'locked' => 0)));
 605      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_replace_course_shortname',
 606          new lang_string('setting_overwrite_course_shortname', 'backup'),
 607          new lang_string('config_overwrite_course_shortname', 'backup'), array('value' => 1, 'locked' => 0)));
 608      $temp->add(new admin_setting_configcheckbox_with_lock('restore/restore_replace_course_startdate',
 609          new lang_string('setting_overwrite_course_startdate', 'backup'),
 610          new lang_string('config_overwrite_course_startdate', 'backup'), array('value' => 1, 'locked' => 0)));
 611  
 612      $temp->add(new admin_setting_configselect_with_lock('restore/restore_replace_keep_roles_and_enrolments',
 613          new lang_string('setting_keep_roles_and_enrolments', 'backup'),
 614          new lang_string('config_keep_roles_and_enrolments', 'backup'), array('value' => 0, 'locked' => 0),
 615          array(1 => get_string('yes'), 0 => get_string('no'))));
 616      $temp->add(new admin_setting_configselect_with_lock('restore/restore_replace_keep_groups_and_groupings',
 617          new lang_string('setting_keep_groups_and_groupings', 'backup'),
 618          new lang_string('config_keep_groups_and_groupings', 'backup'), array('value' => 0, 'locked' => 0),
 619          array(1 => get_string('yes'), 0 => get_string('no'))));
 620  
 621      $ADMIN->add('backups', $temp);
 622  
 623      // Create a page for asynchronous backup and restore configuration and defaults.
 624      $temp = new admin_settingpage('asyncgeneralsettings', new lang_string('asyncgeneralsettings', 'backup'));
 625  
 626      $temp->add(new admin_setting_configcheckbox('enableasyncbackup', new lang_string('enableasyncbackup', 'backup'),
 627              new lang_string('enableasyncbackup_help', 'backup'), 0, 1, 0));
 628  
 629      $temp->add(new admin_setting_configcheckbox(
 630              'backup/backup_async_message_users',
 631              new lang_string('asyncemailenable', 'backup'),
 632              new lang_string('asyncemailenabledetail', 'backup'), 0));
 633      $temp->hide_if('backup/backup_async_message_users', 'enableasyncbackup');
 634  
 635      $temp->add(new admin_setting_configtext(
 636              'backup/backup_async_message_subject',
 637              new lang_string('asyncmessagesubject', 'backup'),
 638              new lang_string('asyncmessagesubjectdetail', 'backup'),
 639              new lang_string('asyncmessagesubjectdefault', 'backup')));
 640      $temp->hide_if('backup/backup_async_message_subject', 'backup/backup_async_message_users');
 641  
 642      $temp->add(new admin_setting_confightmleditor(
 643              'backup/backup_async_message',
 644              new lang_string('asyncmessagebody', 'backup'),
 645              new lang_string('asyncmessagebodydetail', 'backup'),
 646              new lang_string('asyncmessagebodydefault', 'backup')));
 647      $temp->hide_if('backup/backup_async_message', 'backup/backup_async_message_users');
 648  
 649      $ADMIN->add('backups', $temp);
 650  
 651  }