[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/group/ -> assign.php (source)

   1  <?php  // $Id: assign.php,v 1.18.2.1 2007/11/19 20:27:50 skodak Exp $
   2  /**
   3   * Add/remove group from grouping.
   4   * @package groups
   5   */
   6  require_once ('../config.php');
   7  require_once ('lib.php');
   8  
   9  $groupingid = required_param('id', PARAM_INT);
  10  
  11  if (!$grouping = get_record('groupings', 'id', $groupingid)) {
  12      error('Incorrect group id');
  13  }
  14  
  15  if (! $course = get_record('course', 'id', $grouping->courseid)) {
  16      print_error('invalidcourse');
  17  }
  18  $courseid = $course->id;
  19  
  20  require_login($course);
  21  $context = get_context_instance(CONTEXT_COURSE, $courseid);
  22  require_capability('moodle/course:managegroups', $context);
  23  
  24  $returnurl = $CFG->wwwroot.'/group/groupings.php?id='.$courseid;
  25  
  26  
  27  if ($frm = data_submitted() and confirm_sesskey()) {
  28  
  29      if (isset($frm->cancel)) {
  30          redirect($returnurl);
  31  
  32      } else if (isset($frm->add) and !empty($frm->addselect)) {
  33          foreach ($frm->addselect as $groupid) {
  34              groups_assign_grouping($grouping->id, (int)$groupid);
  35          }
  36  
  37      } else if (isset($frm->remove) and !empty($frm->removeselect)) {
  38          foreach ($frm->removeselect as $groupid) {
  39              groups_unassign_grouping($grouping->id, (int)$groupid);
  40          }
  41      }
  42  }
  43  
  44  
  45  $currentmembers = array();
  46  $potentialmembers  = array();
  47  
  48  if ($groups = get_records('groups', 'courseid', $courseid, 'name')) {
  49      if ($assignment = get_records('groupings_groups', 'groupingid', $grouping->id)) {
  50          foreach ($assignment as $ass) {
  51              $currentmembers[$ass->groupid] = $groups[$ass->groupid];
  52              unset($groups[$ass->groupid]);
  53          }
  54      }
  55      $potentialmembers = $groups;
  56  }
  57  
  58  $currentmembersoptions = '';
  59  $currentmemberscount = 0;
  60  if ($currentmembers) {
  61      foreach($currentmembers as $group) {
  62          $currentmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
  63          $currentmemberscount ++;
  64      }
  65  
  66      // Get course managers so they can be hilited in the list
  67      if ($managerroles = get_config('', 'coursemanager')) {
  68          $coursemanagerroles = split(',', $managerroles);
  69          foreach ($coursemanagerroles as $roleid) {
  70              $role = get_record('role','id',$roleid);
  71              $canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
  72              $managers = get_role_users($roleid, $context, true, 'u.id', 'u.id ASC', $canseehidden);
  73          }
  74      }
  75  } else {
  76      $currentmembersoptions .= '<option>&nbsp;</option>';
  77  }
  78  
  79  $potentialmembersoptions = '';
  80  $potentialmemberscount = 0;
  81  if ($potentialmembers) {
  82      foreach($potentialmembers as $group) {
  83          $potentialmembersoptions .= '<option value="'.$group->id.'.">'.format_string($group->name).'</option>';
  84          $potentialmemberscount ++;
  85      }
  86  } else {
  87      $potentialmembersoptions .= '<option>&nbsp;</option>';
  88  }
  89  
  90  // Print the page and form
  91  $strgroups = get_string('groups');
  92  $strparticipants = get_string('participants');
  93  $straddgroupstogroupings = get_string('addgroupstogroupings', 'group');
  94  
  95  $groupingname = format_string($grouping->name);
  96  
  97  $navlinks = array();
  98  $navlinks[] = array('name' => $strparticipants, 'link' => "$CFG->wwwroot/user/index.php?id=$courseid", 'type' => 'misc');
  99  $navlinks[] = array('name' => $strgroups, 'link' => "$CFG->wwwroot/group/index.php?id=$courseid", 'type' => 'misc');
 100  $navlinks[] = array('name' => $straddgroupstogroupings, 'link' => null, 'type' => 'misc');
 101  $navigation = build_navigation($navlinks);
 102  
 103  print_header("$course->shortname: $strgroups", $course->fullname, $navigation, '', '', true, '', user_login_string($course, $USER));
 104  
 105  ?>
 106  <div id="addmembersform">
 107      <h3 class="main"><?php print_string('addgroupstogroupings', 'group'); echo ": $groupingname"; ?></h3>
 108  
 109      <form id="assignform" method="post" action="">
 110      <div>
 111      <input type="hidden" name="sesskey" value="<?php p(sesskey()); ?>" />
 112  
 113      <table summary="" cellpadding="5" cellspacing="0">
 114      <tr>
 115        <td valign="top">
 116            <label for="removeselect"><?php print_string('existingmembers', 'group', $currentmemberscount); //count($contextusers) ?></label>
 117            <br />
 118            <select name="removeselect[]" size="20" id="removeselect" multiple="multiple"
 119                    onfocus="document.getElementById('assignform').add.disabled=true;
 120                             document.getElementById('assignform').remove.disabled=false;
 121                             document.getElementById('assignform').addselect.selectedIndex=-1;">
 122            <?php echo $currentmembersoptions ?>
 123            </select></td>
 124        <td valign="top">
 125  
 126          <?php check_theme_arrows(); ?>
 127          <p class="arrow_button">
 128              <input name="add" id="add" type="submit" value="<?php echo '&nbsp;'.$THEME->larrow.' &nbsp; &nbsp; '.get_string('add'); ?>" title="<?php print_string('add'); ?>" />
 129              <br />
 130              <input name="remove" id="remove" type="submit" value="<?php echo '&nbsp; '.$THEME->rarrow.' &nbsp; &nbsp; '.get_string('remove'); ?>" title="<?php print_string('remove'); ?>" />
 131          </p>
 132        </td>
 133        <td valign="top">
 134            <label for="addselect"><?php print_string('potentialmembers', 'group', $potentialmemberscount); //$usercount ?></label>
 135            <br />
 136            <select name="addselect[]" size="20" id="addselect" multiple="multiple"
 137                    onfocus="document.getElementById('assignform').add.disabled=false;
 138                             document.getElementById('assignform').remove.disabled=true;
 139                             document.getElementById('assignform').removeselect.selectedIndex=-1;">
 140           <?php echo $potentialmembersoptions ?>
 141           </select>
 142           <br />
 143         </td>
 144      </tr>
 145      <tr><td>
 146          <input type="submit" name="cancel" value="<?php print_string('backtogroupings', 'group'); ?>" />
 147      </td></tr>
 148      </table>
 149      </div>
 150      </form>
 151  </div>
 152  
 153  <?php
 154      print_footer($course);
 155  
 156  
 157  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7