[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 * Add/remove group from grouping. 20 * 21 * @copyright 1999 Martin Dougiamas http://dougiamas.com 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 * @package core_group 24 */ 25 26 require_once('../config.php'); 27 require_once ('lib.php'); 28 29 $groupingid = required_param('id', PARAM_INT); 30 31 $PAGE->set_url('/group/assign.php', array('id'=>$groupingid)); 32 33 if (!$grouping = $DB->get_record('groupings', array('id'=>$groupingid))) { 34 print_error('invalidgroupid'); 35 } 36 37 if (!$course = $DB->get_record('course', array('id'=>$grouping->courseid))) { 38 print_error('invalidcourse'); 39 } 40 $courseid = $course->id; 41 42 require_login($course); 43 $context = context_course::instance($courseid); 44 require_capability('moodle/course:managegroups', $context); 45 46 $returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$courseid; 47 48 49 if ($frm = data_submitted() and confirm_sesskey()) { 50 51 if (isset($frm->cancel)) { 52 redirect($returnurl); 53 54 } else if (isset($frm->add) and !empty($frm->addselect)) { 55 foreach ($frm->addselect as $groupid) { 56 // Ask this method not to purge the cache, we'll do it ourselves afterwards. 57 groups_assign_grouping($grouping->id, (int)$groupid, null, false); 58 } 59 // Invalidate the course groups cache seeing as we've changed it. 60 cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($courseid)); 61 62 } else if (isset($frm->remove) and !empty($frm->removeselect)) { 63 foreach ($frm->removeselect as $groupid) { 64 // Ask this method not to purge the cache, we'll do it ourselves afterwards. 65 groups_unassign_grouping($grouping->id, (int)$groupid, false); 66 } 67 // Invalidate the course groups cache seeing as we've changed it. 68 cache_helper::invalidate_by_definition('core', 'groupdata', array(), array($courseid)); 69 } 70 } 71 72 73 $currentmembers = array(); 74 $potentialmembers = array(); 75 76 if ($groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name')) { 77 if ($assignment = $DB->get_records('groupings_groups', array('groupingid'=>$grouping->id))) { 78 foreach ($assignment as $ass) { 79 $currentmembers[$ass->groupid] = $groups[$ass->groupid]; 80 unset($groups[$ass->groupid]); 81 } 82 } 83 $potentialmembers = $groups; 84 } 85 86 $currentmembersoptions = ''; 87 $currentmemberscount = 0; 88 if ($currentmembers) { 89 foreach($currentmembers as $group) { 90 $currentmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>'; 91 $currentmemberscount ++; 92 } 93 94 // Get course managers so they can be highlighted in the list 95 if ($managerroles = get_config('', 'coursecontact')) { 96 $coursecontactroles = explode(',', $managerroles); 97 foreach ($coursecontactroles as $roleid) { 98 $role = $DB->get_record('role', array('id'=>$roleid)); 99 $managers = get_role_users($roleid, $context, true, 'u.id', 'u.id ASC'); 100 } 101 } 102 } else { 103 $currentmembersoptions .= '<option> </option>'; 104 } 105 106 $potentialmembersoptions = ''; 107 $potentialmemberscount = 0; 108 if ($potentialmembers) { 109 foreach($potentialmembers as $group) { 110 $potentialmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>'; 111 $potentialmemberscount ++; 112 } 113 } else { 114 $potentialmembersoptions .= '<option> </option>'; 115 } 116 117 // Print the page and form 118 $strgroups = get_string('groups'); 119 $strparticipants = get_string('participants'); 120 $straddgroupstogroupings = get_string('addgroupstogroupings', 'group'); 121 122 $groupingname = format_string($grouping->name); 123 124 navigation_node::override_active_url(new moodle_url('/group/index.php', array('id'=>$course->id))); 125 $PAGE->set_pagelayout('admin'); 126 127 $PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid))); 128 $PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$courseid))); 129 $PAGE->navbar->add($straddgroupstogroupings); 130 131 /// Print header 132 $PAGE->set_title("$course->shortname: $strgroups"); 133 $PAGE->set_heading($course->fullname); 134 echo $OUTPUT->header(); 135 136 ?> 137 <div id="addmembersform"> 138 <h3 class="main"><?php print_string('addgroupstogroupings', 'group'); echo ": $groupingname"; ?></h3> 139 <form id="assignform" method="post" action=""> 140 <div> 141 <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" /> 142 <table summary="" class="generaltable generalbox groupmanagementtable boxaligncenter"> 143 <tr> 144 <td id="existingcell"> 145 <label for="removeselect"><?php print_string('existingmembers', 'group', $currentmemberscount); ?></label> 146 <div class="userselector" id="removeselect_wrapper"> 147 <select name="removeselect[]" size="20" id="removeselect" multiple="multiple" 148 onfocus="document.getElementById('assignform').add.disabled=true; 149 document.getElementById('assignform').remove.disabled=false; 150 document.getElementById('assignform').addselect.selectedIndex=-1;"> 151 <?php echo $currentmembersoptions ?> 152 </select></div></td> 153 <td id="buttonscell"> 154 <p class="arrow_button"> 155 <input name="add" id="add" type="submit" 156 value="<?php echo $OUTPUT->larrow().' '.get_string('add'); ?>" 157 title="<?php print_string('add'); ?>" /><br> 158 <input name="remove" id="remove" type="submit" 159 value="<?php echo get_string('remove').' '.$OUTPUT->rarrow(); ?>" 160 title="<?php print_string('remove'); ?>" /> 161 </p> 162 </td> 163 <td id="potentialcell"> 164 <label for="addselect"><?php print_string('potentialmembers', 'group', $potentialmemberscount); ?></label> 165 <div class="userselector" id="addselect_wrapper"> 166 <select name="addselect[]" size="20" id="addselect" multiple="multiple" 167 onfocus="document.getElementById('assignform').add.disabled=false; 168 document.getElementById('assignform').remove.disabled=true; 169 document.getElementById('assignform').removeselect.selectedIndex=-1;"> 170 <?php echo $potentialmembersoptions ?> 171 </select> 172 </div> 173 </td> 174 </tr> 175 <tr><td colspan="3" id="backcell"> 176 <input type="submit" name="cancel" value="<?php print_string('backtogroupings', 'group'); ?>" /> 177 </td></tr> 178 </table> 179 </div> 180 </form> 181 </div> 182 183 <?php 184 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |