| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * The main group management user interface. 4 * 5 * @copyright © 2006 The Open University 6 * @author N.D.Freear AT open.ac.uk 7 * @author J.White AT open.ac.uk 8 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 9 * @package groups 10 */ 11 require_once ('../config.php'); 12 require_once ('lib.php'); 13 require_once($CFG->libdir.'/pear/HTML/AJAX/JSON.php'); 14 15 require_js('yui_yahoo'); 16 require_js('yui_dom'); 17 require_js('yui_utilities'); 18 require_js('yui_connection'); 19 require_js($CFG->wwwroot.'/group/clientlib.js'); 20 21 $courseid = required_param('id', PARAM_INT); 22 $groupid = optional_param('group', false, PARAM_INT); 23 $userid = optional_param('user', false, PARAM_INT); 24 $action = groups_param_action(); 25 26 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid; 27 28 // Get the course information so we can print the header and 29 // check the course id is valid 30 31 if (!$course = get_record('course', 'id',$courseid)) { 32 $success = false; 33 print_error('invalidcourse'); //'The course ID is invalid' 34 } 35 36 // Make sure that the user has permissions to manage groups. 37 require_login($course); 38 39 $context = get_context_instance(CONTEXT_COURSE, $courseid); 40 if (! has_capability('moodle/course:managegroups', $context)) { 41 redirect(); //"group.php?id=$course->id"); // Not allowed to see all groups 42 } 43 44 switch ($action) { 45 case false: //OK, display form. 46 break; 47 48 case 'ajax_getmembersingroup': 49 $roles = array(); 50 if ($groupmemberroles = groups_get_members_by_role($groupid,$courseid,'u.id,u.firstname,u.lastname')) { 51 foreach($groupmemberroles as $roleid=>$roledata) { 52 $shortroledata=new StdClass; 53 $shortroledata->name=$roledata->name; 54 $shortroledata->users=array(); 55 foreach($roledata->users as $member) { 56 $shortmember=new StdClass; 57 $shortmember->id=$member->id; 58 $shortmember->name=fullname($member, true); 59 $shortroledata->users[]=$shortmember; 60 } 61 $roles[]=$shortroledata; 62 } 63 } 64 echo json_encode($roles); 65 die; // Client side JavaScript takes it from here. 66 67 case 'deletegroup': 68 redirect('group.php?delete=1&courseid='.$courseid.'&id='.$groupid); 69 break; 70 71 case 'showcreateorphangroupform': 72 redirect('group.php?courseid='.$courseid); 73 break; 74 75 case 'showautocreategroupsform': 76 redirect('autogroup.php?courseid='.$courseid); 77 break; 78 79 case 'showgroupsettingsform': 80 redirect('group.php?courseid='.$courseid.'&id='.$groupid); 81 break; 82 83 case 'updategroups': //Currently reloading. 84 break; 85 86 case 'removemembers': 87 break; 88 89 case 'showaddmembersform': 90 redirect('members.php?group='.$groupid); 91 break; 92 93 case 'updatemembers': //Currently reloading. 94 break; 95 96 default: //ERROR. 97 if (debugging()) { 98 error('Error, unknown button/action. Probably a user-interface bug!', $returnurl); 99 break; 100 } 101 } 102 103 // Print the page and form 104 $strgroups = get_string('groups'); 105 $strparticipants = get_string('participants'); 106 107 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'), 108 array('name'=>$strgroups, 'link'=>'', 'type'=>'misc')); 109 $navigation = build_navigation($navlinks); 110 111 /// Print header 112 print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course)); 113 // Add tabs 114 $currenttab = 'groups'; 115 require ('tabs.php'); 116 117 $disabled = 'disabled="disabled"'; 118 119 $showeditgroupsettingsform_disabled = $disabled; 120 $deletegroup_disabled = $disabled; 121 $showcreategroupform_disabled = $disabled; 122 123 if (!empty($groupid)) { 124 $showaddmembersform_disabled = ''; 125 $showeditgroupsettingsform_disabled = ''; 126 $deletegroup_disabled = ''; 127 } else { 128 $deletegroup_disabled = $disabled; 129 $showeditgroupsettingsform_disabled = $disabled; 130 $showaddmembersform_disabled = $disabled; 131 } 132 133 print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3); 134 echo '<form id="groupeditform" action="index.php" method="post">'."\n"; 135 echo '<div>'."\n"; 136 echo '<input type="hidden" name="id" value="' . $courseid . '" />'."\n"; 137 138 echo '<table cellpadding="6" class="generaltable generalbox groupmanagementtable boxaligncenter" summary="">'."\n"; 139 echo '<tr>'."\n"; 140 141 142 echo "<td>\n"; 143 // NO GROUPINGS YET! 144 echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping"> </span></label></p>'."\n"; 145 146 if (ajaxenabled()) { 147 $onchange = 'membersCombo.refreshMembers(this.options[this.selectedIndex].value);'; 148 } else { 149 $onchange = ''; 150 } 151 152 153 echo '<select name="group" id="groups" size="15" class="select" onchange="'.$onchange.'"'."\n"; 154 echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n"; 155 156 $groups = groups_get_all_groups($courseid); 157 158 $sel_groupid = 0; 159 160 if ($groups) { 161 // Print out the HTML 162 foreach ($groups as $group) { 163 $select = ''; 164 if ($groupid == $group->id) { 165 $select = ' selected="selected"'; 166 $sel_groupid = $group->id; 167 } 168 $usercount = (int)count_records('groups_members', 'groupid', $group->id); 169 $groupname = format_string($group->name).' ('.$usercount.')'; 170 171 echo "<option value=\"{$group->id}\"$select title=\"$groupname\">$groupname</option>\n"; 172 } 173 } else { 174 // Print an empty option to avoid the XHTML error of having an empty select element 175 echo '<option> </option>'; 176 } 177 178 echo '</select>'."\n"; 179 echo '<p><input type="submit" name="act_updatemembers" id="updatemembers" value="' 180 . get_string('showmembersforgroup', 'group') . '" /></p>'."\n"; 181 echo '<p><input type="submit" '. $showeditgroupsettingsform_disabled . ' name="act_showgroupsettingsform" id="showeditgroupsettingsform" value="' 182 . get_string('editgroupsettings', 'group') . '" /></p>'."\n"; 183 echo '<p><input type="submit" '. $deletegroup_disabled . ' name="act_deletegroup" onclick="onDeleteGroup()" id="deletegroup" value="' 184 . get_string('deleteselectedgroup', 'group') . '" /></p>'."\n"; 185 186 echo '<p><input type="submit" name="act_showcreateorphangroupform" id="showcreateorphangroupform" value="' 187 . get_string('creategroup', 'group') . '" /></p>'."\n"; 188 189 echo '<p><input type="submit" name="act_showautocreategroupsform" id="showautocreategroupsform" value="' 190 . get_string('autocreategroups', 'group') . '" /></p>'."\n"; 191 192 echo '</td>'."\n"; 193 echo '<td>'."\n"; 194 echo '<p><label for="members"><span id="memberslabel">'.get_string('membersofselectedgroup', 'group').' </span><span id="thegroup"> </span></label></p>'."\n"; 195 //NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick. 196 echo '<select name="user" id="members" size="15" class="select"'."\n"; 197 echo ' onclick="window.status=this.options[this.selectedIndex].title;" onmouseout="window.status=\'\';">'."\n"; 198 199 $member_names = array(); 200 201 $atleastonemember = false; 202 if ($sel_groupid) { 203 204 if ($groupmemberroles = groups_get_members_by_role($groupid,$courseid,'u.id,u.firstname,u.lastname')) { 205 foreach($groupmemberroles as $roleid=>$roledata) { 206 echo '<optgroup label="'.htmlspecialchars($roledata->name).'">'; 207 foreach($roledata->users as $member) { 208 echo '<option value="'.$member->id.'">'.fullname($member, true).'</option>'; 209 $atleastonemember = true; 210 } 211 echo '</optgroup>'; 212 } 213 } 214 } 215 216 if (!$atleastonemember) { 217 // Print an empty option to avoid the XHTML error of having an empty select element 218 echo '<option> </option>'; 219 } 220 221 echo '</select>'."\n"; 222 223 echo '<p><input type="submit" ' . $showaddmembersform_disabled . ' name="act_showaddmembersform" ' 224 . 'id="showaddmembersform" value="' . get_string('adduserstogroup', 'group'). '" /></p>'."\n"; 225 echo '</td>'."\n"; 226 echo '</tr>'."\n"; 227 echo '</table>'."\n"; 228 229 //<input type="hidden" name="rand" value="om" /> 230 echo '</div>'."\n"; 231 echo '</form>'."\n"; 232 233 if (ajaxenabled()) { 234 echo '<script type="text/javascript">'."\n"; 235 echo '//<![CDATA['."\n"; 236 echo 'var groupsCombo = new UpdatableGroupsCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n"; 237 echo 'var membersCombo = new UpdatableMembersCombo("'.$CFG->wwwroot.'", '.$course->id.');'."\n"; 238 echo '//]]>'."\n"; 239 echo '</script>'."\n"; 240 } 241 242 print_footer($course); 243 244 /** 245 * Returns the first button action with the given prefix, taken from 246 * POST or GET, otherwise returns false. 247 * See /lib/moodlelib.php function optional_param. 248 * @param $prefix 'act_' as in 'action'. 249 * @return string The action without the prefix, or false if no action found. 250 */ 251 function groups_param_action($prefix = 'act_') { 252 $action = false; 253 //($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/ 254 255 if ($_POST) { 256 $form_vars = $_POST; 257 } 258 elseif ($_GET) { 259 $form_vars = $_GET; 260 } 261 if ($form_vars) { 262 foreach ($form_vars as $key => $value) { 263 if (preg_match("/$prefix(.+)/", $key, $matches)) { 264 $action = $matches[1]; 265 break; 266 } 267 } 268 } 269 if ($action && !preg_match('/^\w+$/', $action)) { 270 $action = false; 271 error('Action had wrong type.'); 272 } 273 ///if (debugging()) echo 'Debug: '.$action; 274 return $action; 275 } 276 277 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |