Search moodle.org's
Developer Documentation

See Release Notes

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

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

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