Merge branch 'MDL-65026-37' of git://github.com/jleyva/moodle into MOODLE_37_STABLE
[moodle.git] / admin / webservice / service_user_settings.php
blob8a87fdb619e0b6bd44d1f4caa466a3f8d889e9c2
1 <?php
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.
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/>.
18 /**
19 * Web services user settings UI
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
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');
30 $serviceid = required_param('serviceid', PARAM_INT);
31 $userid = required_param('userid', PARAM_INT);
33 admin_externalpage_setup('externalserviceusersettings');
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();
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'));
46 $formaction = new moodle_url('', array('id' => $serviceid, 'userid' => $userid));
47 $returnurl = new moodle_url('/' . $CFG->admin . '/webservice/service_users.php', array('id' => $serviceid));
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();
54 if ($usersettingsform->is_cancelled()) {
55 redirect($returnurl);
57 } else if (!empty($settingsformdata) and confirm_sesskey()) {
58 /// save user settings (administrator clicked on update button)
59 $settingsformdata = (object)$settingsformdata;
61 $serviceuserinfo = new stdClass();
62 $serviceuserinfo->id = $serviceuser->serviceuserid;
63 $serviceuserinfo->iprestriction = $settingsformdata->iprestriction;
64 $serviceuserinfo->validuntil = $settingsformdata->validuntil;
66 $webservicemanager->update_ws_authorised_user($serviceuserinfo);
68 //TODO: assign capability
70 //display successful notification
71 $notification = $OUTPUT->notification(get_string('usersettingssaved', 'webservice'), 'notifysuccess');
74 echo $OUTPUT->header();
75 echo $OUTPUT->heading(get_string('serviceusersettings', 'webservice'), 3, 'main');
76 if (!empty($notification)) {
77 echo $notification;
79 $usersettingsform->display();
81 echo $OUTPUT->footer();