MDL-50154 behat: Resize pdf window so toolbar is always visible
[moodle.git] / cohort / assign.php
blobc50e3a06672d2fc7844c973f3270f134add87f98
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.
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/>.
17 /**
18 * Cohort related management functions, this file needs to be included manually.
20 * @package core_cohort
21 * @copyright 2010 Petr Skoda {@link http://skodak.org}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require('../config.php');
26 require_once($CFG->dirroot.'/cohort/locallib.php');
28 $id = required_param('id', PARAM_INT);
30 require_login();
32 $cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST);
33 $context = context::instance_by_id($cohort->contextid, MUST_EXIST);
35 require_capability('moodle/cohort:assign', $context);
37 $PAGE->set_context($context);
38 $PAGE->set_url('/cohort/assign.php', array('id'=>$id));
39 $PAGE->set_pagelayout('admin');
41 $returnurl = new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid));
43 if (!empty($cohort->component)) {
44 // We can not manually edit cohorts that were created by external systems, sorry.
45 redirect($returnurl);
48 if (optional_param('cancel', false, PARAM_BOOL)) {
49 redirect($returnurl);
52 if ($context->contextlevel == CONTEXT_COURSECAT) {
53 $category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
54 navigation_node::override_active_url(new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid)));
55 } else {
56 navigation_node::override_active_url(new moodle_url('/cohort/index.php', array()));
58 $PAGE->navbar->add(get_string('assign', 'cohort'));
60 $PAGE->set_title(get_string('cohort:assign', 'cohort'));
61 $PAGE->set_heading($COURSE->fullname);
63 echo $OUTPUT->header();
64 echo $OUTPUT->heading(get_string('assignto', 'cohort', format_string($cohort->name)));
66 echo $OUTPUT->notification(get_string('removeuserwarning', 'core_cohort'));
68 // Get the user_selector we will need.
69 $potentialuserselector = new cohort_candidate_selector('addselect', array('cohortid'=>$cohort->id, 'accesscontext'=>$context));
70 $existinguserselector = new cohort_existing_selector('removeselect', array('cohortid'=>$cohort->id, 'accesscontext'=>$context));
72 // Process incoming user assignments to the cohort
74 if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
75 $userstoassign = $potentialuserselector->get_selected_users();
76 if (!empty($userstoassign)) {
78 foreach ($userstoassign as $adduser) {
79 cohort_add_member($cohort->id, $adduser->id);
82 $potentialuserselector->invalidate_selected_users();
83 $existinguserselector->invalidate_selected_users();
87 // Process removing user assignments to the cohort
88 if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
89 $userstoremove = $existinguserselector->get_selected_users();
90 if (!empty($userstoremove)) {
91 foreach ($userstoremove as $removeuser) {
92 cohort_remove_member($cohort->id, $removeuser->id);
94 $potentialuserselector->invalidate_selected_users();
95 $existinguserselector->invalidate_selected_users();
99 // Print the form.
101 <form id="assignform" method="post" action="<?php echo $PAGE->url ?>"><div>
102 <input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
104 <table summary="" class="generaltable generalbox boxaligncenter" cellspacing="0">
105 <tr>
106 <td id="existingcell">
107 <p><label for="removeselect"><?php print_string('currentusers', 'cohort'); ?></label></p>
108 <?php $existinguserselector->display() ?>
109 </td>
110 <td id="buttonscell">
111 <div id="addcontrols">
112 <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.s(get_string('add')); ?>" title="<?php p(get_string('add')); ?>" /><br />
113 </div>
115 <div id="removecontrols">
116 <input name="remove" id="remove" type="submit" value="<?php echo s(get_string('remove')).'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php p(get_string('remove')); ?>" />
117 </div>
118 </td>
119 <td id="potentialcell">
120 <p><label for="addselect"><?php print_string('potusers', 'cohort'); ?></label></p>
121 <?php $potentialuserselector->display() ?>
122 </td>
123 </tr>
124 <tr><td colspan="3" id='backcell'>
125 <input type="submit" name="cancel" value="<?php p(get_string('backtocohorts', 'cohort')); ?>" />
126 </td></tr>
127 </table>
128 </div></form>
130 <?php
132 echo $OUTPUT->footer();