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