MDL-33575 choice module: add label to checkbox element when privacy of results is...
[moodle.git] / cohort / assign.php
blobb7f65896a5f7b0afb38a01d954c32aaa1dce8400
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 * Cohort related management functions, this file needs to be included manually.
21 * @package core
22 * @subpackage cohort
23 * @copyright 2010 Petr Skoda {@link http://skodak.org}
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 require_once('../config.php');
28 require_once($CFG->dirroot.'/cohort/lib.php');
30 $id = required_param('id', PARAM_INT);
32 require_login();
34 $cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST);
35 $context = get_context_instance_by_id($cohort->contextid, MUST_EXIST);
37 require_capability('moodle/cohort:assign', $context);
39 $PAGE->set_context($context);
40 $PAGE->set_url('/cohort/assign.php', array('id'=>$id));
42 $returnurl = new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid));
44 if (!empty($cohort->component)) {
45 // we can not manually edit cohorts that were created by external systems, sorry
46 redirect($returnurl);
49 if (optional_param('cancel', false, PARAM_BOOL)) {
50 redirect($returnurl);
53 if ($context->contextlevel == CONTEXT_COURSECAT) {
54 $category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST);
55 navigation_node::override_active_url(new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid)));
56 $PAGE->set_pagelayout('report');
58 } else {
59 navigation_node::override_active_url(new moodle_url('/cohort/index.php', array()));
60 $PAGE->set_pagelayout('admin');
62 $PAGE->navbar->add(get_string('assign', 'cohort'));
64 $PAGE->set_title(get_string('cohort:assign', 'cohort'));
65 $PAGE->set_heading($COURSE->fullname);
67 echo $OUTPUT->header();
68 echo $OUTPUT->heading(get_string('assignto', 'cohort', format_string($cohort->name)));
70 echo $OUTPUT->notification(get_string('removeuserwarning', 'core_cohort'));
72 // Get the user_selector we will need.
73 $potentialuserselector = new cohort_candidate_selector('addselect', array('cohortid'=>$cohort->id));
74 $existinguserselector = new cohort_existing_selector('removeselect', array('cohortid'=>$cohort->id));
76 // Process incoming user assignments to the cohort
78 if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
79 $userstoassign = $potentialuserselector->get_selected_users();
80 if (!empty($userstoassign)) {
82 foreach ($userstoassign as $adduser) {
83 // no duplicates please
84 if (!$DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$adduser->id))) {
85 cohort_add_member($cohort->id, $adduser->id);
89 $potentialuserselector->invalidate_selected_users();
90 $existinguserselector->invalidate_selected_users();
94 // Process removing user assignments to the cohort
95 if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
96 $userstoremove = $existinguserselector->get_selected_users();
97 if (!empty($userstoremove)) {
98 foreach ($userstoremove as $removeuser) {
99 cohort_remove_member($cohort->id, $removeuser->id);
101 $potentialuserselector->invalidate_selected_users();
102 $existinguserselector->invalidate_selected_users();
106 // Print the form.
108 <form id="assignform" method="post" action="<?php echo $PAGE->url ?>"><div>
109 <input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
111 <table summary="" class="generaltable generalbox boxaligncenter" cellspacing="0">
112 <tr>
113 <td id="existingcell">
114 <p><label for="removeselect"><?php print_string('currentusers', 'cohort'); ?></label></p>
115 <?php $existinguserselector->display() ?>
116 </td>
117 <td id="buttonscell">
118 <div id="addcontrols">
119 <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.s(get_string('add')); ?>" title="<?php p(get_string('add')); ?>" /><br />
120 </div>
122 <div id="removecontrols">
123 <input name="remove" id="remove" type="submit" value="<?php echo s(get_string('remove')).'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php p(get_string('remove')); ?>" />
124 </div>
125 </td>
126 <td id="potentialcell">
127 <p><label for="addselect"><?php print_string('potusers', 'cohort'); ?></label></p>
128 <?php $potentialuserselector->display() ?>
129 </td>
130 </tr>
131 <tr><td colspan="3" id='backcell'>
132 <input type="submit" name="cancel" value="<?php p(get_string('backtocohorts', 'cohort')); ?>" />
133 </td></tr>
134 </table>
135 </div></form>
137 <?php
139 echo $OUTPUT->footer();