|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 require_once('../config.php'); 00028 require_once($CFG->dirroot.'/cohort/lib.php'); 00029 00030 $id = required_param('id', PARAM_INT); 00031 00032 require_login(); 00033 00034 $cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST); 00035 $context = get_context_instance_by_id($cohort->contextid, MUST_EXIST); 00036 00037 require_capability('moodle/cohort:assign', $context); 00038 00039 $PAGE->set_context($context); 00040 $PAGE->set_url('/cohort/assign.php', array('id'=>$id)); 00041 00042 $returnurl = new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid)); 00043 00044 if (!empty($cohort->component)) { 00045 // we can not manually edit cohorts that were created by external systems, sorry 00046 redirect($returnurl); 00047 } 00048 00049 if (optional_param('cancel', false, PARAM_BOOL)) { 00050 redirect($returnurl); 00051 } 00052 00053 if ($context->contextlevel == CONTEXT_COURSECAT) { 00054 $category = $DB->get_record('course_categories', array('id'=>$context->instanceid), '*', MUST_EXIST); 00055 navigation_node::override_active_url(new moodle_url('/cohort/index.php', array('contextid'=>$cohort->contextid))); 00056 $PAGE->set_pagelayout('report'); 00057 00058 } else { 00059 navigation_node::override_active_url(new moodle_url('/cohort/index.php', array())); 00060 $PAGE->set_pagelayout('admin'); 00061 } 00062 $PAGE->navbar->add(get_string('assign', 'cohort')); 00063 00064 $PAGE->set_title(get_string('cohort:assign', 'cohort')); 00065 $PAGE->set_heading($COURSE->fullname); 00066 00067 echo $OUTPUT->header(); 00068 echo $OUTPUT->heading(get_string('assignto', 'cohort', format_string($cohort->name))); 00069 00070 echo $OUTPUT->notification(get_string('removeuserwarning', 'core_cohort')); 00071 00072 // Get the user_selector we will need. 00073 $potentialuserselector = new cohort_candidate_selector('addselect', array('cohortid'=>$cohort->id)); 00074 $existinguserselector = new cohort_existing_selector('removeselect', array('cohortid'=>$cohort->id)); 00075 00076 // Process incoming user assignments to the cohort 00077 00078 if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { 00079 $userstoassign = $potentialuserselector->get_selected_users(); 00080 if (!empty($userstoassign)) { 00081 00082 foreach ($userstoassign as $adduser) { 00083 // no duplicates please 00084 if (!$DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$adduser->id))) { 00085 cohort_add_member($cohort->id, $adduser->id); 00086 } 00087 } 00088 00089 $potentialuserselector->invalidate_selected_users(); 00090 $existinguserselector->invalidate_selected_users(); 00091 } 00092 } 00093 00094 // Process removing user assignments to the cohort 00095 if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) { 00096 $userstoremove = $existinguserselector->get_selected_users(); 00097 if (!empty($userstoremove)) { 00098 foreach ($userstoremove as $removeuser) { 00099 cohort_remove_member($cohort->id, $removeuser->id); 00100 } 00101 $potentialuserselector->invalidate_selected_users(); 00102 $existinguserselector->invalidate_selected_users(); 00103 } 00104 } 00105 00106 // Print the form. 00107 ?> 00108 <form id="assignform" method="post" action="<?php echo $PAGE->url ?>"><div> 00109 <input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" /> 00110 00111 <table summary="" class="generaltable generalbox boxaligncenter" cellspacing="0"> 00112 <tr> 00113 <td id="existingcell"> 00114 <p><label for="removeselect"><?php print_string('currentusers', 'cohort'); ?></label></p> 00115 <?php $existinguserselector->display() ?> 00116 </td> 00117 <td id="buttonscell"> 00118 <div id="addcontrols"> 00119 <input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().' '.s(get_string('add')); ?>" title="<?php p(get_string('add')); ?>" /><br /> 00120 </div> 00121 00122 <div id="removecontrols"> 00123 <input name="remove" id="remove" type="submit" value="<?php echo s(get_string('remove')).' '.$OUTPUT->rarrow(); ?>" title="<?php p(get_string('remove')); ?>" /> 00124 </div> 00125 </td> 00126 <td id="potentialcell"> 00127 <p><label for="addselect"><?php print_string('potusers', 'cohort'); ?></label></p> 00128 <?php $potentialuserselector->display() ?> 00129 </td> 00130 </tr> 00131 <tr><td colspan="3" id='backcell'> 00132 <input type="submit" name="cancel" value="<?php p(get_string('backtocohorts', 'cohort')); ?>" /> 00133 </td></tr> 00134 </table> 00135 </div></form> 00136 00137 <?php 00138 00139 echo $OUTPUT->footer();