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 400 and 401] [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   * Settings
  19   *
  20   * This file contains settings used by tool_mobile
  21   *
  22   * @package    tool_mobile
  23   * @copyright  2016 Juan Leyva
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  defined('MOODLE_INTERNAL') || die();
  28  
  29  use core_admin\local\settings\autocomplete;
  30  
  31  if ($hassiteconfig) {
  32  
  33      // We should wait to the installation to finish since we depend on some configuration values that are set once
  34      // the admin user profile is configured.
  35      if (!during_initial_install()) {
  36          $enablemobiledocurl = new moodle_url(get_docs_url('Enable_mobile_web_services'));
  37          $enablemobiledoclink = html_writer::link($enablemobiledocurl, new lang_string('documentation'));
  38          $default = is_https() ? 1 : 0;
  39          $optionalsubsystems = $ADMIN->locate('optionalsubsystems');
  40          $optionalsubsystems->add(new admin_setting_enablemobileservice('enablemobilewebservice',
  41                  new lang_string('enablemobilewebservice', 'admin'),
  42                  new lang_string('configenablemobilewebservice', 'admin', $enablemobiledoclink), $default));
  43      }
  44  
  45      $ismobilewsdisabled = empty($CFG->enablemobilewebservice);
  46      $ADMIN->add('root',
  47          new admin_category('mobileapp', new lang_string('mobileapp', 'tool_mobile'), $ismobilewsdisabled),
  48          'development'
  49      );
  50  
  51      $temp = new admin_settingpage('mobilesettings',
  52          new lang_string('mobilesettings', 'tool_mobile'),
  53          'moodle/site:config',
  54          $ismobilewsdisabled
  55      );
  56  
  57      $temp->add(new admin_setting_configtext('tool_mobile/apppolicy', new lang_string('apppolicy', 'tool_mobile'),
  58          new lang_string('apppolicy_help', 'tool_mobile'), '', PARAM_URL));
  59  
  60      $ADMIN->add('mobileapp', $temp);
  61  
  62      $featuresnotice = null;
  63      if (empty($CFG->disablemobileappsubscription)) {
  64          // General notification about limited features due to app restrictions.
  65          $subscriptionurl = (new moodle_url("/$CFG->admin/tool/mobile/subscription.php"))->out(false);
  66          $notify = new \core\output\notification(
  67              get_string('moodleappsportalfeatureswarning', 'tool_mobile', $subscriptionurl),
  68              \core\output\notification::NOTIFY_WARNING);
  69          $featuresnotice = $OUTPUT->render($notify);
  70      }
  71  
  72      $hideappsubscription = (isset($CFG->disablemobileappsubscription) && !empty($CFG->disablemobileappsubscription));
  73      $hideappsubscription = $ismobilewsdisabled || $hideappsubscription;
  74  
  75      $ADMIN->add(
  76          'mobileapp',
  77          new admin_externalpage(
  78              'mobileappsubscription',
  79              new lang_string('mobileappsubscription', 'tool_mobile'),
  80              "$CFG->wwwroot/$CFG->admin/tool/mobile/subscription.php",
  81              'moodle/site:config',
  82              $hideappsubscription
  83          )
  84      );
  85  
  86      // Type of login.
  87      $temp = new admin_settingpage(
  88          'mobileauthentication',
  89          new lang_string('mobileauthentication', 'tool_mobile'),
  90          'moodle/site:config',
  91          $ismobilewsdisabled
  92      );
  93  
  94      $temp->add(new admin_setting_heading('tool_mobile/moodleappsportalfeaturesauth', '', $featuresnotice));
  95  
  96      $options = array(
  97          tool_mobile\api::LOGIN_VIA_APP => new lang_string('loginintheapp', 'tool_mobile'),
  98          tool_mobile\api::LOGIN_VIA_BROWSER => new lang_string('logininthebrowser', 'tool_mobile'),
  99          tool_mobile\api::LOGIN_VIA_EMBEDDED_BROWSER => new lang_string('loginintheembeddedbrowser', 'tool_mobile'),
 100      );
 101      $temp->add(new admin_setting_configselect('tool_mobile/typeoflogin',
 102                  new lang_string('typeoflogin', 'tool_mobile'),
 103                  new lang_string('typeoflogin_desc', 'tool_mobile'), 1, $options));
 104  
 105      $options = [
 106          tool_mobile\api::QR_CODE_DISABLED => new lang_string('qrcodedisabled', 'tool_mobile'),
 107          tool_mobile\api::QR_CODE_URL => new lang_string('qrcodetypeurl', 'tool_mobile'),
 108      ];
 109      $qrcodetypedefault = tool_mobile\api::QR_CODE_URL;
 110  
 111      if (is_https()) {   // Allow QR login for https sites.
 112          $options[tool_mobile\api::QR_CODE_LOGIN] = new lang_string('qrcodetypelogin', 'tool_mobile');
 113          $qrcodetypedefault = tool_mobile\api::QR_CODE_LOGIN;
 114      }
 115  
 116      $temp->add(new admin_setting_configselect('tool_mobile/qrcodetype',
 117                  new lang_string('qrcodetype', 'tool_mobile'),
 118                  new lang_string('qrcodetype_desc', 'tool_mobile'), $qrcodetypedefault, $options));
 119  
 120      $temp->add(new admin_setting_configduration('tool_mobile/qrkeyttl',
 121          new lang_string('qrkeyttl', 'tool_mobile'),
 122          new lang_string('qrkeyttl_desc', 'tool_mobile'), tool_mobile\api::LOGIN_QR_KEY_TTL, MINSECS));
 123      $temp->hide_if('tool_mobile/qrkeyttl', 'tool_mobile/qrcodetype', 'neq', tool_mobile\api::QR_CODE_LOGIN);
 124  
 125      $temp->add(new admin_setting_configcheckbox('tool_mobile/qrsameipcheck',
 126                  new lang_string('qrsameipcheck', 'tool_mobile'),
 127                  new lang_string('qrsameipcheck_desc', 'tool_mobile'), 1));
 128      $temp->hide_if('tool_mobile/qrsameipcheck', 'tool_mobile/qrcodetype', 'neq', tool_mobile\api::QR_CODE_LOGIN);
 129  
 130      $temp->add(new admin_setting_configtext('tool_mobile/forcedurlscheme',
 131                  new lang_string('forcedurlscheme_key', 'tool_mobile'),
 132                  new lang_string('forcedurlscheme', 'tool_mobile'), 'moodlemobile', PARAM_NOTAGS));
 133  
 134      $temp->add(new admin_setting_configtext('tool_mobile/minimumversion',
 135                  new lang_string('minimumversion_key', 'tool_mobile'),
 136                  new lang_string('minimumversion', 'tool_mobile'), '', PARAM_NOTAGS));
 137  
 138      $options = [
 139          60 => new lang_string('numminutes', '', 1),
 140          180 => new lang_string('numminutes', '', 3),
 141          360 => new lang_string('numminutes', '', 6),
 142          900 => new lang_string('numminutes', '', 15),
 143          1800 => new lang_string('numminutes', '', 30),
 144          3600 => new lang_string('numminutes', '', 60)
 145      ];
 146      $temp->add(new admin_setting_configselect('tool_mobile/autologinmintimebetweenreq',
 147          new lang_string('autologinmintimebetweenreq', 'tool_mobile'),
 148          new lang_string('autologinmintimebetweenreq_desc', 'tool_mobile'), 360, $options));
 149  
 150      $ADMIN->add('mobileapp', $temp);
 151  
 152      // Appearance related settings.
 153      $temp = new admin_settingpage(
 154          'mobileappearance',
 155          new lang_string('mobileappearance', 'tool_mobile'),
 156          'moodle/site:config',
 157          $ismobilewsdisabled
 158      );
 159  
 160      if (!empty($featuresnotice)) {
 161          $temp->add(new admin_setting_heading('tool_mobile/moodleappsportalfeaturesappearance', '', $featuresnotice));
 162      }
 163  
 164      $temp->add(new admin_setting_configtext('mobilecssurl', new lang_string('mobilecssurl', 'tool_mobile'),
 165                  new lang_string('configmobilecssurl', 'tool_mobile'), '', PARAM_URL));
 166  
 167      // Reference to Branded Mobile App.
 168      if (empty($CFG->disableserviceads_branded)) {
 169          $temp->add(new admin_setting_description('moodlebrandedappreference',
 170              new lang_string('moodlebrandedapp', 'admin'),
 171              new lang_string('moodlebrandedappreference', 'admin')
 172          ));
 173      }
 174  
 175      $temp->add(new admin_setting_heading('tool_mobile/smartappbanners',
 176                  new lang_string('smartappbanners', 'tool_mobile'), ''));
 177  
 178      $temp->add(new admin_setting_configcheckbox('tool_mobile/enablesmartappbanners',
 179                  new lang_string('enablesmartappbanners', 'tool_mobile'),
 180                  new lang_string('enablesmartappbanners_desc', 'tool_mobile'), 0));
 181  
 182      $temp->add(new admin_setting_configtext('tool_mobile/iosappid', new lang_string('iosappid', 'tool_mobile'),
 183                  new lang_string('iosappid_desc', 'tool_mobile'), tool_mobile\api::DEFAULT_IOS_APP_ID, PARAM_ALPHANUM));
 184  
 185      $temp->add(new admin_setting_configtext('tool_mobile/androidappid', new lang_string('androidappid', 'tool_mobile'),
 186                  new lang_string('androidappid_desc', 'tool_mobile'), tool_mobile\api::DEFAULT_ANDROID_APP_ID, PARAM_NOTAGS));
 187  
 188      $temp->add(new admin_setting_configtext('tool_mobile/setuplink', new lang_string('setuplink', 'tool_mobile'),
 189          new lang_string('setuplink_desc', 'tool_mobile'), 'https://download.moodle.org/mobile', PARAM_URL));
 190  
 191      $ADMIN->add('mobileapp', $temp);
 192  
 193      // Features related settings.
 194      $temp = new admin_settingpage(
 195          'mobilefeatures',
 196          new lang_string('mobilefeatures', 'tool_mobile'),
 197          'moodle/site:config',
 198          $ismobilewsdisabled
 199      );
 200  
 201      if (!empty($featuresnotice)) {
 202          $temp->add(new admin_setting_heading('tool_mobile/moodleappsportalfeatures', '', $featuresnotice));
 203      }
 204  
 205      $temp->add(new admin_setting_heading('tool_mobile/logout',
 206                  new lang_string('logout'), ''));
 207  
 208      $temp->add(new admin_setting_configcheckbox('tool_mobile/forcelogout',
 209                  new lang_string('forcelogout', 'tool_mobile'),
 210                  new lang_string('forcelogout_desc', 'tool_mobile'), 0));
 211  
 212      $temp->add(new admin_setting_heading('tool_mobile/features',
 213                  new lang_string('mobilefeatures', 'tool_mobile'), ''));
 214  
 215      $options = tool_mobile\api::get_features_list();
 216      $temp->add(new admin_setting_configmultiselect('tool_mobile/disabledfeatures',
 217                  new lang_string('disabledfeatures', 'tool_mobile'),
 218                  new lang_string('disabledfeatures_desc', 'tool_mobile'), array(), $options));
 219  
 220      $temp->add(new admin_setting_configtextarea('tool_mobile/custommenuitems',
 221                  new lang_string('custommenuitems', 'tool_mobile'),
 222                  new lang_string('custommenuitems_desc', 'tool_mobile'), '', PARAM_RAW, '50', '10'));
 223  
 224      // File type exclusionlist.
 225      $choices = [];
 226      foreach (core_filetypes::get_types() as $key => $info) {
 227          $text = '.' . $key;
 228          if (!empty($info['type'])) {
 229              $text .= ' (' . $info['type'] . ')';
 230          }
 231          $choices[$key] = $text;
 232      }
 233  
 234      $attributes = [
 235          'manageurl' => new \moodle_url('/admin/tool/filetypes/index.php'),
 236          'managetext' => get_string('managefiletypes', 'tool_mobile'),
 237          'multiple' => true,
 238          'delimiter' => ',',
 239          'placeholder' => get_string('filetypeexclusionlistplaceholder', 'tool_mobile')
 240      ];
 241      $temp->add(new autocomplete('tool_mobile/filetypeexclusionlist',
 242          new lang_string('filetypeexclusionlist', 'tool_mobile'),
 243          new lang_string('filetypeexclusionlist_desc', 'tool_mobile'), array(), $choices, $attributes));
 244  
 245      $temp->add(new admin_setting_heading('tool_mobile/language',
 246                  new lang_string('language'), ''));
 247  
 248      $temp->add(new admin_setting_configtextarea('tool_mobile/customlangstrings',
 249                  new lang_string('customlangstrings', 'tool_mobile'),
 250                  new lang_string('customlangstrings_desc', 'tool_mobile'), '', PARAM_RAW, '50', '10'));
 251  
 252      $ADMIN->add('mobileapp', $temp);
 253  }