Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/group/assign.php
Go to the documentation of this file.
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 
00026 require_once('../config.php');
00027 require_once('lib.php');
00028 
00029 $groupingid = required_param('id', PARAM_INT);
00030 
00031 $PAGE->set_url('/group/assign.php', array('id'=>$groupingid));
00032 
00033 if (!$grouping = $DB->get_record('groupings', array('id'=>$groupingid))) {
00034     print_error('invalidgroupid');
00035 }
00036 
00037 if (!$course = $DB->get_record('course', array('id'=>$grouping->courseid))) {
00038     print_error('invalidcourse');
00039 }
00040 $courseid = $course->id;
00041 
00042 require_login($course);
00043 $context = get_context_instance(CONTEXT_COURSE, $courseid);
00044 require_capability('moodle/course:managegroups', $context);
00045 
00046 $returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$courseid;
00047 
00048 
00049 if ($frm = data_submitted() and confirm_sesskey()) {
00050 
00051     if (isset($frm->cancel)) {
00052         redirect($returnurl);
00053 
00054     } else if (isset($frm->add) and !empty($frm->addselect)) {
00055         foreach ($frm->addselect as $groupid) {
00056             groups_assign_grouping($grouping->id, (int)$groupid);
00057         }
00058 
00059     } else if (isset($frm->remove) and !empty($frm->removeselect)) {
00060         foreach ($frm->removeselect as $groupid) {
00061             groups_unassign_grouping($grouping->id, (int)$groupid);
00062         }
00063     }
00064 }
00065 
00066 
00067 $currentmembers = array();
00068 $potentialmembers  = array();
00069 
00070 if ($groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name')) {
00071     if ($assignment = $DB->get_records('groupings_groups', array('groupingid'=>$grouping->id))) {
00072         foreach ($assignment as $ass) {
00073             $currentmembers[$ass->groupid] = $groups[$ass->groupid];
00074             unset($groups[$ass->groupid]);
00075         }
00076     }
00077     $potentialmembers = $groups;
00078 }
00079 
00080 $currentmembersoptions = '';
00081 $currentmemberscount = 0;
00082 if ($currentmembers) {
00083     foreach($currentmembers as $group) {
00084         $currentmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
00085         $currentmemberscount ++;
00086     }
00087 
00088     // Get course managers so they can be highlighted in the list
00089     if ($managerroles = get_config('', 'coursecontact')) {
00090         $coursecontactroles = explode(',', $managerroles);
00091         foreach ($coursecontactroles as $roleid) {
00092             $role = $DB->get_record('role', array('id'=>$roleid));
00093             $managers = get_role_users($roleid, $context, true, 'u.id', 'u.id ASC');
00094         }
00095     }
00096 } else {
00097     $currentmembersoptions .= '<option>&nbsp;</option>';
00098 }
00099 
00100 $potentialmembersoptions = '';
00101 $potentialmemberscount = 0;
00102 if ($potentialmembers) {
00103     foreach($potentialmembers as $group) {
00104         $potentialmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
00105         $potentialmemberscount ++;
00106     }
00107 } else {
00108     $potentialmembersoptions .= '<option>&nbsp;</option>';
00109 }
00110 
00111 // Print the page and form
00112 $strgroups = get_string('groups');
00113 $strparticipants = get_string('participants');
00114 $straddgroupstogroupings = get_string('addgroupstogroupings', 'group');
00115 
00116 $groupingname = format_string($grouping->name);
00117 
00118 navigation_node::override_active_url(new moodle_url('/group/index.php', array('id'=>$course->id)));
00119 $PAGE->set_pagelayout('standard');
00120 
00121 $PAGE->navbar->add($strparticipants, new moodle_url('/user/index.php', array('id'=>$courseid)));
00122 $PAGE->navbar->add($strgroups, new moodle_url('/group/index.php', array('id'=>$courseid)));
00123 $PAGE->navbar->add($straddgroupstogroupings);
00124 
00126 $PAGE->set_title("$course->shortname: $strgroups");
00127 $PAGE->set_heading($course->fullname);
00128 echo $OUTPUT->header();
00129 
00130 ?>
00131 <div id="addmembersform">
00132     <h3 class="main"><?php print_string('addgroupstogroupings', 'group'); echo ": $groupingname"; ?></h3>
00133 
00134     <form id="assignform" method="post" action="">
00135     <div>
00136     <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
00137 
00138     <table summary="" cellpadding="5" cellspacing="0">
00139     <tr>
00140       <td valign="top">
00141           <label for="removeselect"><?php print_string('existingmembers', 'group', $currentmemberscount); ?></label>
00142           <br />
00143           <select name="removeselect[]" size="20" id="removeselect" multiple="multiple"
00144                   onfocus="document.getElementById('assignform').add.disabled=true;
00145                            document.getElementById('assignform').remove.disabled=false;
00146                            document.getElementById('assignform').addselect.selectedIndex=-1;">
00147           <?php echo $currentmembersoptions ?>
00148           </select></td>
00149       <td valign="top">
00150 
00151         <p class="arrow_button">
00152             <input name="add" id="add" type="submit" value="<?php echo '&nbsp;'.$OUTPUT->larrow().' &nbsp; &nbsp; '.get_string('add'); ?>" title="<?php print_string('add'); ?>" />
00153             <br />
00154             <input name="remove" id="remove" type="submit" value="<?php echo '&nbsp; '.$OUTPUT->rarrow().' &nbsp; &nbsp; '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" />
00155         </p>
00156       </td>
00157       <td valign="top">
00158           <label for="addselect"><?php print_string('potentialmembers', 'group', $potentialmemberscount); ?></label>
00159           <br />
00160           <select name="addselect[]" size="20" id="addselect" multiple="multiple"
00161                   onfocus="document.getElementById('assignform').add.disabled=false;
00162                            document.getElementById('assignform').remove.disabled=true;
00163                            document.getElementById('assignform').removeselect.selectedIndex=-1;">
00164          <?php echo $potentialmembersoptions ?>
00165          </select>
00166          <br />
00167        </td>
00168     </tr>
00169     <tr><td>
00170         <input type="submit" name="cancel" value="<?php print_string('backtogroupings', 'group'); ?>" />
00171     </td></tr>
00172     </table>
00173     </div>
00174     </form>
00175 </div>
00176 
00177 <?php
00178     echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations