2009-10-12 21:46:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Web services function UI
|
|
|
|
*
|
|
|
|
* @package webservice
|
|
|
|
* @copyright 2009 Moodle Pty Ltd (http://moodle.com)
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2009-10-21 19:58:50 +00:00
|
|
|
require_once('../../config.php');
|
2009-10-12 21:46:16 +00:00
|
|
|
require_once($CFG->libdir.'/adminlib.php');
|
2009-10-14 09:47:48 +00:00
|
|
|
require_once($CFG->dirroot.'/admin/webservice/lib.php');
|
2009-10-12 21:46:16 +00:00
|
|
|
|
|
|
|
$id = required_param('id', PARAM_INT);
|
|
|
|
|
2009-10-21 19:58:50 +00:00
|
|
|
$PAGE->set_url('admin/webservice/service_users.php', array('id'=>$id));
|
|
|
|
$PAGE->requires->js($CFG->admin.'/webservice/script.js');
|
2009-10-12 21:46:16 +00:00
|
|
|
|
|
|
|
admin_externalpage_setup('externalserviceusers');
|
2009-10-14 09:47:48 +00:00
|
|
|
admin_externalpage_print_header();
|
2009-10-16 08:50:02 +00:00
|
|
|
global $DB;
|
2009-10-14 09:47:48 +00:00
|
|
|
/// Get the user_selector we will need.
|
2009-10-15 02:34:21 +00:00
|
|
|
$potentialuserselector = new service_user_selector('addselect', array('serviceid' => $id, 'displayallowedusers' => 0));
|
|
|
|
$alloweduserselector = new service_user_selector('removeselect', array('serviceid' => $id, 'displayallowedusers' => 1));
|
2009-10-14 09:47:48 +00:00
|
|
|
|
|
|
|
/// Process incoming user assignments to the service
|
|
|
|
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
|
|
|
|
$userstoassign = $potentialuserselector->get_selected_users();
|
|
|
|
if (!empty($userstoassign)) {
|
|
|
|
|
|
|
|
foreach ($userstoassign as $adduser) {
|
|
|
|
$serviceuser = new object();
|
|
|
|
$serviceuser->externalserviceid = $id;
|
|
|
|
$serviceuser->userid = $adduser->id;
|
|
|
|
$serviceuser->timecreated = mktime();
|
|
|
|
$DB->insert_record('external_services_users', $serviceuser);
|
2009-10-21 19:58:50 +00:00
|
|
|
add_to_log(1, 'core', 'assign', $CFG->admin.'/webservice/service_users.php?id='.$id, 'add', '', $adduser->id);
|
2009-10-14 09:47:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$potentialuserselector->invalidate_selected_users();
|
|
|
|
$alloweduserselector->invalidate_selected_users();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Process removing user assignments to the service
|
|
|
|
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
|
|
|
|
$userstoremove = $alloweduserselector->get_selected_users();
|
|
|
|
if (!empty($userstoremove)) {
|
|
|
|
|
2009-11-01 10:55:31 +00:00
|
|
|
foreach ($userstoremove as $removeuser) {
|
2009-10-14 09:47:48 +00:00
|
|
|
$DB->delete_records('external_services_users', array('externalserviceid' => $id, 'userid' => $removeuser->id));
|
2009-10-21 19:58:50 +00:00
|
|
|
add_to_log(1, 'core', 'assign', $CFG->admin.'/webservice/service_users.php?id='.$id, 'remove', '', $removeuser->id);
|
2009-10-14 09:47:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$potentialuserselector->invalidate_selected_users();
|
|
|
|
$alloweduserselector->invalidate_selected_users();
|
|
|
|
}
|
|
|
|
}
|
2009-10-20 06:34:46 +00:00
|
|
|
/// Print the form.
|
2009-10-14 09:47:48 +00:00
|
|
|
/// display the UI
|
|
|
|
?>
|
2009-10-21 19:58:50 +00:00
|
|
|
<form id="assignform" method="post" action="service_users.php?id=<?php echo $id ?>"><div>
|
2009-10-14 09:47:48 +00:00
|
|
|
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
|
|
|
|
|
|
|
|
<table summary="" class="roleassigntable generaltable generalbox boxaligncenter" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td id="existingcell">
|
|
|
|
<p><label for="removeselect"><?php print_string('serviceusers', 'webservice'); ?></label></p>
|
|
|
|
<?php $alloweduserselector->display() ?>
|
|
|
|
</td>
|
|
|
|
<td id="buttonscell">
|
|
|
|
<div id="addcontrols">
|
2009-11-01 10:55:31 +00:00
|
|
|
<input name="add" id="add" type="submit" value="<?php echo $THEME->larrow.' '.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
|
2009-10-14 09:47:48 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="removecontrols">
|
|
|
|
<input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').' '.$THEME->rarrow; ?>" title="<?php print_string('remove'); ?>" />
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td id="potentialcell">
|
|
|
|
<p><label for="addselect"><?php print_string('potusers', 'webservice'); ?></label></p>
|
|
|
|
<?php $potentialuserselector->display() ?>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</div></form>
|
|
|
|
|
|
|
|
<?php
|
2009-10-12 21:46:16 +00:00
|
|
|
|
2009-10-16 08:50:02 +00:00
|
|
|
/// save user settings (administrator clicked on update button)
|
|
|
|
if (optional_param('updateuser', false, PARAM_BOOL) && confirm_sesskey()) {
|
2009-10-20 14:33:01 +00:00
|
|
|
$useridtoupdate = optional_param('userid', false, PARAM_INT);
|
2009-10-16 08:50:02 +00:00
|
|
|
$iprestriction = optional_param('iprestriction', '', PARAM_TEXT);
|
|
|
|
$serviceuserid = optional_param('serviceuserid', '', PARAM_INT);
|
2009-10-20 14:33:01 +00:00
|
|
|
$fromday = optional_param('fromday'.$useridtoupdate, '', PARAM_INT);
|
|
|
|
$frommonth = optional_param('frommonth'.$useridtoupdate, '', PARAM_INT);
|
|
|
|
$fromyear = optional_param('fromyear'.$useridtoupdate, '', PARAM_INT);
|
2009-10-16 08:50:02 +00:00
|
|
|
$addcap = optional_param('addcap', false, PARAM_INT);
|
2009-10-20 06:34:46 +00:00
|
|
|
$enablevaliduntil = optional_param('enablevaliduntil', false, PARAM_INT);
|
2009-10-20 14:33:01 +00:00
|
|
|
if (!empty($fromday) && !empty($frommonth) && !empty($fromyear)) {
|
|
|
|
$validuntil = mktime(23, 59, 59, $frommonth, $fromday, $fromyear);
|
2009-10-21 19:58:50 +00:00
|
|
|
} else {
|
2009-10-20 14:33:01 +00:00
|
|
|
$validuntil = "";
|
|
|
|
}
|
2009-10-16 08:50:02 +00:00
|
|
|
|
|
|
|
$serviceuser = new object();
|
|
|
|
$serviceuser->id = $serviceuserid;
|
2009-10-20 06:34:46 +00:00
|
|
|
if ($enablevaliduntil) {
|
|
|
|
$serviceuser->validuntil = $validuntil;
|
|
|
|
} else {
|
|
|
|
$serviceuser->validuntil = null; //the valid until field is disabled, we reset the value
|
|
|
|
}
|
2009-10-16 08:50:02 +00:00
|
|
|
$serviceuser->iprestriction = $iprestriction;
|
|
|
|
$DB->update_record('external_services_users', $serviceuser);
|
|
|
|
|
|
|
|
//TODO: assign capability
|
|
|
|
}
|
|
|
|
|
|
|
|
//display the list of allowed users with their options (ip/timecreated / validuntil...)
|
|
|
|
//check that the user has the service required capability (if needed)
|
|
|
|
$sql = " SELECT u.id as id, esu.id as serviceuserid, u.email as email, u.firstname as firstname, u.lastname as lastname,
|
|
|
|
esu.iprestriction as iprestriction, esu.validuntil as validuntil,
|
|
|
|
esu.timecreated as timecreated
|
|
|
|
FROM {user} u, {external_services_users} esu
|
|
|
|
WHERE username <> 'guest' AND deleted = 0 AND confirmed = 1
|
|
|
|
AND esu.userid = u.id
|
|
|
|
AND esu.externalserviceid = ?";
|
|
|
|
$allowedusers = $DB->get_records_sql($sql, array($id));
|
|
|
|
if (!empty($allowedusers)) {
|
|
|
|
echo $OUTPUT->box_start('generalbox', 'alloweduserlist');
|
2009-11-01 10:55:31 +00:00
|
|
|
|
2009-10-16 08:50:02 +00:00
|
|
|
echo "<label><strong>".get_string('serviceuserssettings', 'webservice').":</strong></label>";
|
2009-10-20 06:34:46 +00:00
|
|
|
echo "<br/><br/><span style=\"font-size:85%\">"; //reduce font of the user settings
|
2009-10-16 08:50:02 +00:00
|
|
|
foreach($allowedusers as $user) {
|
|
|
|
|
|
|
|
echo print_collapsible_region_start('', 'usersettings'.$user->id,$user->firstname." ".$user->lastname.", ".$user->email,false,true,true);
|
2009-12-09 06:54:05 +00:00
|
|
|
|
2009-10-16 08:50:02 +00:00
|
|
|
//user settings form
|
|
|
|
$contents = "<div class=\"fcontainer clearfix\">";
|
|
|
|
$form = new html_form();
|
2009-10-21 19:58:50 +00:00
|
|
|
$form->url = new moodle_url('service_users.php', array('id' => $id, 'userid' => $user->id, 'updateuser' => 1, 'serviceuserid' => $user->serviceuserid)); // Required
|
2009-10-16 08:50:02 +00:00
|
|
|
$form->button = new html_button();
|
|
|
|
$form->button->text = get_string('update'); // Required
|
|
|
|
$form->button->disabled = false;
|
|
|
|
$form->button->title = get_string('update');
|
|
|
|
$form->method = 'post';
|
|
|
|
$form->id = 'usersetting'.$user->id;
|
|
|
|
//ip restriction textfield
|
|
|
|
$contents .= "<div class=\"fitem\"><div class=\"fitemtitle\"><label>".get_string('iprestriction','webservice')." </label></div><div class=\"felement\">";
|
|
|
|
$field = new html_field();
|
|
|
|
$field->name = 'iprestriction';
|
|
|
|
$field->value = $user->iprestriction;
|
|
|
|
$field->style = 'width: 30em;';
|
|
|
|
$contents .= $OUTPUT->textfield($field);
|
|
|
|
$contents .= "</div></div>";
|
|
|
|
//valid until date selector
|
|
|
|
$contents .= "<div class=\"fitem\"><div class=\"fitemtitle\"><label>".get_string('validuntil','webservice')." </label></div><div class=\"felement\">";
|
2009-10-20 14:33:01 +00:00
|
|
|
// the following date selector needs to have specific day/month/year field ids because we use javascript (enable/disable).
|
|
|
|
$selectors = html_select::make_time_selectors(array('days' => 'fromday'.$user->id,'months' => 'frommonth'.$user->id, 'years' => 'fromyear'.$user->id),$user->validuntil);
|
2009-10-16 08:50:02 +00:00
|
|
|
foreach ($selectors as $select) {
|
2009-10-20 14:33:01 +00:00
|
|
|
if (empty($user->validuntil)) {
|
|
|
|
$select->disabled = true;
|
|
|
|
}
|
2009-10-16 08:50:02 +00:00
|
|
|
$contents .= $OUTPUT->select($select);
|
2009-10-20 14:33:01 +00:00
|
|
|
}
|
|
|
|
$checkbox = new html_select_option();
|
2009-10-20 06:34:46 +00:00
|
|
|
$checkbox->value = 1;
|
2009-10-20 14:33:01 +00:00
|
|
|
$checkbox->id = 'enablevaliduntil'.$user->id;
|
|
|
|
$checkbox->name = 'enablevaliduntil';
|
2009-10-20 06:34:46 +00:00
|
|
|
$checkbox->selected = empty($user->validuntil)?false:true;
|
|
|
|
$checkbox->text = get_string('enabled', 'webservice');
|
|
|
|
$checkbox->label->text = get_string('enabled', 'webservice');
|
|
|
|
$checkbox->alt = get_string('enabled', 'webservice');
|
2009-10-21 20:01:00 +00:00
|
|
|
$checkbox->add_action('change', 'external_disablevaliduntil', array($user->id)); //into admin/webservice/script.js
|
2009-10-20 06:34:46 +00:00
|
|
|
$contents .= $OUTPUT->checkbox($checkbox, 'enablevaliduntil');
|
2009-10-20 14:33:01 +00:00
|
|
|
$contents .= ""; //init date selector disable status
|
|
|
|
|
2009-10-16 08:50:02 +00:00
|
|
|
$contents .= "</div></div>";
|
|
|
|
//TO IMPLEMENT : assign the required capability (if needed)
|
|
|
|
$contents .= "<div class=\"fitem\"><div class=\"fitemtitle\"><label>".get_string('addrequiredcapability','webservice')." </label></div><div class=\"felement fcheckbox\">";
|
|
|
|
$checkbox = new html_select_option();
|
2009-11-01 10:55:31 +00:00
|
|
|
$checkbox->value = $user->id;
|
2009-10-16 08:50:02 +00:00
|
|
|
$checkbox->selected = false;
|
|
|
|
$checkbox->text = ' ';
|
|
|
|
$checkbox->label->text = ' ';
|
|
|
|
$checkbox->alt = 'TODO:'.get_string('addrequiredcapability', 'webservice');
|
|
|
|
$contents .= $OUTPUT->checkbox($checkbox, 'addcap')."</div></div>";
|
|
|
|
$contents .= "</div>";
|
|
|
|
echo $OUTPUT->form($form, $contents);
|
2009-11-01 10:55:31 +00:00
|
|
|
|
2009-10-16 08:50:02 +00:00
|
|
|
echo print_collapsible_region_end(true);
|
2009-12-09 06:54:05 +00:00
|
|
|
|
2009-10-16 08:50:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
echo "</span>";
|
|
|
|
echo $OUTPUT->box_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-01 10:42:45 +00:00
|
|
|
echo $OUTPUT->footer();
|