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.
   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * Web services user settings UI
  20   *
  21   * @package   webservice
  22   * @copyright 2009 Moodle Pty Ltd (http://moodle.com)
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  require_once('../../config.php');
  26  require_once($CFG->libdir . '/adminlib.php');
  27  require_once($CFG->dirroot . '/webservice/lib.php');
  28  require_once($CFG->dirroot . '/' . $CFG->admin . '/webservice/forms.php');
  29  
  30  $serviceid = required_param('serviceid', PARAM_INT);
  31  $userid = required_param('userid', PARAM_INT);
  32  
  33  admin_externalpage_setup('externalserviceusersettings');
  34  
  35  //define nav bar
  36  $PAGE->set_url('/' . $CFG->admin . '/webservice/service_user_settings.php',
  37          array('id' => $serviceid, 'userid'  => $userid));
  38  $node = $PAGE->settingsnav->find('externalservices', navigation_node::TYPE_SETTING);
  39  if ($node) {
  40      $node->make_active();
  41  }
  42  $PAGE->navbar->add(get_string('serviceusers', 'webservice'),
  43          new moodle_url('/' . $CFG->admin . '/webservice/service_users.php', array('id' => $serviceid)));
  44  $PAGE->navbar->add(get_string('serviceusersettings', 'webservice'));
  45  
  46  $formaction = new moodle_url('', array('id' => $serviceid, 'userid' => $userid));
  47  $returnurl = new moodle_url('/' . $CFG->admin . '/webservice/service_users.php', array('id' => $serviceid));
  48  
  49  $webservicemanager = new webservice();
  50  $serviceuser = $webservicemanager->get_ws_authorised_user($serviceid, $userid);
  51  $usersettingsform = new external_service_authorised_user_settings_form($formaction, $serviceuser);
  52  $settingsformdata = $usersettingsform->get_data();
  53  
  54  if ($usersettingsform->is_cancelled()) {
  55      redirect($returnurl);
  56  
  57  } else if (!empty($settingsformdata) and confirm_sesskey()) {
  58      /// save user settings (administrator clicked on update button)
  59      $settingsformdata = (object)$settingsformdata;
  60  
  61      $serviceuserinfo = new stdClass();
  62      $serviceuserinfo->id = $serviceuser->serviceuserid;
  63      $serviceuserinfo->iprestriction = $settingsformdata->iprestriction;
  64      $serviceuserinfo->validuntil = $settingsformdata->validuntil;
  65  
  66      $webservicemanager->update_ws_authorised_user($serviceuserinfo);
  67  
  68      //TODO: assign capability
  69  
  70      //display successful notification
  71      $notification = $OUTPUT->notification(get_string('usersettingssaved', 'webservice'), 'notifysuccess');
  72  }
  73  
  74  echo $OUTPUT->header();
  75  echo $OUTPUT->heading(get_string('serviceusersettings', 'webservice'), 3, 'main');
  76  if (!empty($notification)) {
  77      echo $notification;
  78  }
  79  $usersettingsform->display();
  80  
  81  echo $OUTPUT->footer();