Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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('/admin/webservice/service_user_settings.php', ['serviceid' => $serviceid, 'userid'  => $userid]);
37
$node = $PAGE->settingsnav->find('externalservices', navigation_node::TYPE_SETTING);
38
if ($node) {
39
    $node->make_active();
40
}
41
 
42
$returnurl = new moodle_url('/admin/webservice/service_users.php', ['id' => $serviceid]);
43
$PAGE->navbar->add(get_string('serviceusers', 'webservice'), $returnurl);
44
$PAGE->navbar->add(get_string('serviceusersettings', 'webservice'));
45
 
46
$formaction = new moodle_url('', array('id' => $serviceid, 'userid' => $userid));
47
 
48
$webservicemanager = new webservice();
49
$serviceuser = $webservicemanager->get_ws_authorised_user($serviceid, $userid);
50
$usersettingsform = new external_service_authorised_user_settings_form($formaction, $serviceuser);
51
$settingsformdata = $usersettingsform->get_data();
52
 
53
if ($usersettingsform->is_cancelled()) {
54
    redirect($returnurl);
55
 
56
} else if (!empty($settingsformdata) and confirm_sesskey()) {
57
    /// save user settings (administrator clicked on update button)
58
    $settingsformdata = (object)$settingsformdata;
59
 
60
    $serviceuserinfo = new stdClass();
61
    $serviceuserinfo->id = $serviceuser->serviceuserid;
62
    $serviceuserinfo->iprestriction = $settingsformdata->iprestriction;
63
    $serviceuserinfo->validuntil = $settingsformdata->validuntil;
64
 
65
    $webservicemanager->update_ws_authorised_user($serviceuserinfo);
66
 
67
    //TODO: assign capability
68
 
69
    //display successful notification
70
    $notification = $OUTPUT->notification(get_string('usersettingssaved', 'webservice'), 'notifysuccess');
71
}
72
 
73
echo $OUTPUT->header();
74
echo $OUTPUT->heading(get_string('serviceusersettings', 'webservice'), 3, 'main');
75
if (!empty($notification)) {
76
    echo $notification;
77
}
78
$usersettingsform->display();
79
 
80
echo $OUTPUT->footer();