Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 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::AUTOLOGOUT_DISABLED => new lang_string('never'),
 107          tool_mobile\api::AUTOLOGOUT_INMEDIATE => new lang_string('autologoutinmediate', 'tool_mobile'),
 108          tool_mobile\api::AUTOLOGOUT_CUSTOM => new lang_string('autologoutcustom', 'tool_mobile'),
 109      ];
 110      $temp->add(new admin_setting_configselect('tool_mobile/autologout',
 111          new lang_string('autologout', 'tool_mobile'),
 112          new lang_string('autologout_desc', 'tool_mobile'), 0, $options));
 113  
 114      $temp->add(new admin_setting_configduration('tool_mobile/autologouttime',
 115          new lang_string('autologouttime', 'tool_mobile'), '', DAYSECS));
 116      $temp->hide_if('tool_mobile/autologouttime', 'tool_mobile/autologout', 'neq', tool_mobile\api::AUTOLOGOUT_CUSTOM);
 117  
 118      $options = [
 119          tool_mobile\api::QR_CODE_DISABLED => new lang_string('qrcodedisabled', 'tool_mobile'),
 120          tool_mobile\api::QR_CODE_URL => new lang_string('qrcodetypeurl', 'tool_mobile'),
 121      ];
 122      $qrcodetypedefault = tool_mobile\api::QR_CODE_URL;
 123  
 124      if (is_https()) {   // Allow QR login for https sites.
 125          $options[tool_mobile\api::QR_CODE_LOGIN] = new lang_string('qrcodetypelogin', 'tool_mobile');
 126          $qrcodetypedefault = tool_mobile\api::QR_CODE_LOGIN;
 127      }
 128  
 129      $temp->add(new admin_setting_configselect('tool_mobile/qrcodetype',
 130                  new lang_string('qrcodetype', 'tool_mobile'),
 131                  new lang_string('qrcodetype_desc', 'tool_mobile'), $qrcodetypedefault, $options));
 132  
 133      $temp->add(new admin_setting_configduration('tool_mobile/qrkeyttl',
 134          new lang_string('qrkeyttl', 'tool_mobile'),
 135          new lang_string('qrkeyttl_desc', 'tool_mobile'), tool_mobile\api::LOGIN_QR_KEY_TTL, MINSECS));
 136      $temp->hide_if('tool_mobile/qrkeyttl', 'tool_mobile/qrcodetype', 'neq', tool_mobile\api::QR_CODE_LOGIN);
 137  
 138      $temp->add(new admin_setting_configcheckbox('tool_mobile/qrsameipcheck',
 139                  new lang_string('qrsameipcheck', 'tool_mobile'),
 140                  new lang_string('qrsameipcheck_desc', 'tool_mobile'), 1));
 141      $temp->hide_if('tool_mobile/qrsameipcheck', 'tool_mobile/qrcodetype', 'neq', tool_mobile\api::QR_CODE_LOGIN);
 142  
 143      $temp->add(new admin_setting_configtext('tool_mobile/forcedurlscheme',
 144                  new lang_string('forcedurlscheme_key', 'tool_mobile'),
 145                  new lang_string('forcedurlscheme', 'tool_mobile'), 'moodlemobile', PARAM_NOTAGS));
 146  
 147      $temp->add(new admin_setting_configtext('tool_mobile/minimumversion',
 148                  new lang_string('minimumversion_key', 'tool_mobile'),
 149                  new lang_string('minimumversion', 'tool_mobile'), '', PARAM_NOTAGS));
 150  
 151      $options = [
 152          60 => new lang_string('numminutes', '', 1),
 153          180 => new lang_string('numminutes', '', 3),
 154          360 => new lang_string('numminutes', '', 6),
 155          900 => new lang_string('numminutes', '', 15),
 156          1800 => new lang_string('numminutes', '', 30),
 157          3600 => new lang_string('numminutes', '', 60)
 158      ];
 159      $temp->add(new admin_setting_configselect('tool_mobile/autologinmintimebetweenreq',
 160          new lang_string('autologinmintimebetweenreq', 'tool_mobile'),
 161          new lang_string('autologinmintimebetweenreq_desc', 'tool_mobile'), 360, $options));
 162  
 163      $ADMIN->add('mobileapp', $temp);
 164  
 165      // Appearance related settings.
 166      $temp = new admin_settingpage(
 167          'mobileappearance',
 168          new lang_string('mobileappearance', 'tool_mobile'),
 169          'moodle/site:config',
 170          $ismobilewsdisabled
 171      );
 172  
 173      if (!empty($featuresnotice)) {
 174          $temp->add(new admin_setting_heading('tool_mobile/moodleappsportalfeaturesappearance', '', $featuresnotice));
 175      }
 176  
 177      $temp->add(new admin_setting_configtext('mobilecssurl', new lang_string('mobilecssurl', 'tool_mobile'),
 178                  new lang_string('configmobilecssurl', 'tool_mobile'), '', PARAM_URL));
 179  
 180      // Reference to Branded Mobile App.
 181      if (empty($CFG->disableserviceads_branded)) {
 182          $temp->add(new admin_setting_description('moodlebrandedappreference',
 183              new lang_string('moodlebrandedapp', 'admin'),
 184              new lang_string('moodlebrandedappreference', 'admin')
 185          ));
 186      }
 187  
 188      $temp->add(new admin_setting_heading('tool_mobile/smartappbanners',
 189                  new lang_string('smartappbanners', 'tool_mobile'), ''));
 190  
 191      $temp->add(new admin_setting_configcheckbox('tool_mobile/enablesmartappbanners',
 192                  new lang_string('enablesmartappbanners', 'tool_mobile'),
 193                  new lang_string('enablesmartappbanners_desc', 'tool_mobile'), 0));
 194  
 195      $temp->add(new admin_setting_configtext('tool_mobile/iosappid', new lang_string('iosappid', 'tool_mobile'),
 196                  new lang_string('iosappid_desc', 'tool_mobile'), tool_mobile\api::DEFAULT_IOS_APP_ID, PARAM_ALPHANUM));
 197  
 198      $temp->add(new admin_setting_configtext('tool_mobile/androidappid', new lang_string('androidappid', 'tool_mobile'),
 199                  new lang_string('androidappid_desc', 'tool_mobile'), tool_mobile\api::DEFAULT_ANDROID_APP_ID, PARAM_NOTAGS));
 200  
 201      $temp->add(new admin_setting_configtext('tool_mobile/setuplink', new lang_string('setuplink', 'tool_mobile'),
 202          new lang_string('setuplink_desc', 'tool_mobile'), 'https://download.moodle.org/mobile', PARAM_URL));
 203  
 204      $ADMIN->add('mobileapp', $temp);
 205  
 206      // Features related settings.
 207      $temp = new admin_settingpage(
 208          'mobilefeatures',
 209          new lang_string('mobilefeatures', 'tool_mobile'),
 210          'moodle/site:config',
 211          $ismobilewsdisabled
 212      );
 213  
 214      if (!empty($featuresnotice)) {
 215          $temp->add(new admin_setting_heading('tool_mobile/moodleappsportalfeatures', '', $featuresnotice));
 216      }
 217  
 218      $temp->add(new admin_setting_heading('tool_mobile/logout',
 219                  new lang_string('logout'), ''));
 220  
 221      $temp->add(new admin_setting_configcheckbox('tool_mobile/forcelogout',
 222                  new lang_string('forcelogout', 'tool_mobile'),
 223                  new lang_string('forcelogout_desc', 'tool_mobile'), 0));
 224  
 225      $temp->add(new admin_setting_heading('tool_mobile/features',
 226                  new lang_string('mobilefeatures', 'tool_mobile'), ''));
 227  
 228      $options = tool_mobile\api::get_features_list();
 229      $temp->add(new admin_setting_configmultiselect('tool_mobile/disabledfeatures',
 230                  new lang_string('disabledfeatures', 'tool_mobile'),
 231                  new lang_string('disabledfeatures_desc', 'tool_mobile'), array(), $options));
 232  
 233      $temp->add(new admin_setting_configtextarea('tool_mobile/custommenuitems',
 234                  new lang_string('custommenuitems', 'tool_mobile'),
 235                  new lang_string('custommenuitems_desc', 'tool_mobile'), '', PARAM_RAW, '50', '10'));
 236  
 237      // File type exclusionlist.
 238      $choices = [];
 239      foreach (core_filetypes::get_types() as $key => $info) {
 240          $text = '.' . $key;
 241          if (!empty($info['type'])) {
 242              $text .= ' (' . $info['type'] . ')';
 243          }
 244          $choices[$key] = $text;
 245      }
 246  
 247      $attributes = [
 248          'manageurl' => new \moodle_url('/admin/tool/filetypes/index.php'),
 249          'managetext' => get_string('managefiletypes', 'tool_mobile'),
 250          'multiple' => true,
 251          'delimiter' => ',',
 252          'placeholder' => get_string('filetypeexclusionlistplaceholder', 'tool_mobile')
 253      ];
 254      $temp->add(new autocomplete('tool_mobile/filetypeexclusionlist',
 255          new lang_string('filetypeexclusionlist', 'tool_mobile'),
 256          new lang_string('filetypeexclusionlist_desc', 'tool_mobile'), array(), $choices, $attributes));
 257  
 258      $temp->add(new admin_setting_heading('tool_mobile/language',
 259                  new lang_string('language'), ''));
 260  
 261      $temp->add(new admin_setting_configtextarea('tool_mobile/customlangstrings',
 262                  new lang_string('customlangstrings', 'tool_mobile'),
 263                  new lang_string('customlangstrings_desc', 'tool_mobile'), '', PARAM_RAW, '50', '10'));
 264  
 265      $ADMIN->add('mobileapp', $temp);
 266  }