<form id="assignform" method="post" action="">
<div style="text-align:center;">
<label for="extendperiod"><?php print_string('enrolperiod') ?></label> <?php choose_from_menu($periodmenu, "extendperiod", $defaultperiod, $unlimitedperiod); ?>
<label for="extendbase"><?php print_string('startingfrom') ?></label> <?php choose_from_menu($basemenu, "extendbase", 3, ""); ?>

<input type="hidden" name="previoussearch" value="<?php p($previoussearch) ?>" />
<input type="hidden" name="userid" value="<?php p($userid) ?>" />
<input type="hidden" name="courseid" value="<?php p($courseid) ?>" />
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
<input type="hidden" name="contextid" value="<?php p($contextid) ?>" />
<input type="hidden" name="roleid" value="<?php p($roleid) ?>" />
  <table summary="" style="margin-left:auto;margin-right:auto" border="0" cellpadding="5" cellspacing="0">
    <tr>
      <td valign="top">
          <label for="removeselect"><?php print_string('existingusers', 'role', count($contextusers)); ?></label>
          <br />
          <select name="removeselect[]" size="20" id="removeselect" multiple="multiple"
                  onfocus="getElementById('assignform').add.disabled=true;
                           getElementById('assignform').remove.disabled=false;
                           getElementById('assignform').addselect.selectedIndex=-1;">

          <?php
            $i = 0;
            foreach ($contextusers as $contextuser) {
                $fullname = fullname($contextuser, true);
                if ($contextuser->hidden) {
                    $hidden=' ('.get_string('hiddenassign').') ';
                } else {
                    $hidden="";
                }
                echo "<option value=\"$contextuser->id\">".$fullname.", ".$contextuser->email.$hidden."</option>\n";
                $i++;    
            }
            if ($i==0) {
                echo '<option/>'; // empty select breaks xhtml strict
            }
          ?>
          
          </select></td>
      <td valign="top">
        <br />
        <label title="<?php print_string('hiddenassign') ?>">
            <input type="checkbox" name="hidden" value="1" />
            <img src="<?php echo $CFG->pixpath; ?>/t/hide.gif" alt="<?php print_string('hiddenassign') ?>" class="hide-show-image" />
            <?php helpbutton('hiddenassign', get_string('hiddenassign')); ?>
        </label>
        <?php check_theme_arrows(); ?>
        <p class="arrow_button">
            <input name="add" id="add" type="submit" value="<?php echo $THEME->larrow.'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
            <input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$THEME->rarrow; ?>" title="<?php print_string('remove'); ?>" />
        </p>
      </td>
      <td valign="top">
          <label for="addselect"><?php print_string('potentialusers', 'role', $usercount); ?></label>
          <br />
          <select name="addselect[]" size="20" id="addselect" multiple="multiple"
                  onfocus="getElementById('assignform').add.disabled=false;
                           getElementById('assignform').remove.disabled=true;
                           getElementById('assignform').removeselect.selectedIndex=-1;">
          <?php
            $i=0;
            if (!empty($searchtext)) {
                echo "<optgroup label=\"$strsearchresults (" . $usercount . ")\">\n";
                while ($user = rs_fetch_next_record($availableusers)) {
                    $fullname = fullname($user, true);
                    echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
                    $i++;
                }
                echo "</optgroup>\n";

            } else {
                if ($usercount > MAX_USERS_PER_PAGE) {
                    echo '<optgroup label="'.get_string('toomanytoshow').'"><option></option></optgroup>'."\n"
                          .'<optgroup label="'.get_string('trysearching').'"><option></option></optgroup>'."\n";
                } else {
                    while ($user = rs_fetch_next_record($availableusers)) {
                        $fullname = fullname($user, true);
                        echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
                        $i++;
                    }
                }
            }
            if ($i==0) {
                echo '<option/>'; // empty select breaks xhtml strict
            }
          ?>
         </select>
         <br />
         <label for="searchtext" class="accesshide"><?php p($strsearch) ?></label>
         <input type="text" name="searchtext" id="searchtext" size="30" value="<?php p($searchtext, true) ?>"
                  onfocus ="getElementById('assignform').add.disabled=true;
                            getElementById('assignform').remove.disabled=true;
                            getElementById('assignform').removeselect.selectedIndex=-1;
                            getElementById('assignform').addselect.selectedIndex=-1;"
                  onkeydown = "var keyCode = event.which ? event.which : event.keyCode;
                               if (keyCode == 13) {
                                    getElementById('assignform').previoussearch.value=1;
                                    getElementById('assignform').submit();
                               } " />
         <input name="search" id="search" type="submit" value="<?php p($strsearch) ?>" />
         <?php
              if (!empty($searchtext)) {
                  echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
              }
         ?>
       </td>
    </tr>
  </table>
</div>
</form>


