
<form id="assignform" method="post" action="">
<div id="trustedhosts"><!-- See theme/standard/styles_layout.css #trustedhosts .generaltable for rules -->
<input type="hidden" name="previoussearch" value="<?php p($previoussearch) ?>" />
<input type="hidden" name="courseid" value="<?php p($courseid) ?>" />
<input type="hidden" name="host" value="<?php p($mnet_peer->id) ?>" />
<input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
  <table class="generaltable" border="0" cellpadding="5" cellspacing="0">
    <tr>
      <td valign="top">
          <?php print_string('existingusers', 'role', count($mnetenrolledusers)); ?>
      </td>
      <td></td>
      <td valign="top">
          <?php print_string('potentialusers', 'role', $availableusers->_numOfRows); ?>
      </td>
    </tr>
    <tr>
      <td valign="top">
          <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
            foreach ($mnetenrolledusers as $enrolleduser) {
                $fullname = fullname($enrolleduser, true);
                echo "<option value=\"$enrolleduser->id\">".s($fullname)." (".s($enrolleduser->rolename).")</option>\n";
            }
          ?>

          </select></td>
      <td valign="top">
        <br />
        <input name="add" type="submit" id="add" value="&larr;" />
        <br />
        <input name="remove" type="submit" id="remove" value="&rarr;" />
        <br />
      </td>
      <td valign="top">
          <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

              if (!empty($searchtext)) {
                  echo "<optgroup label=\"$strsearchresults (" . $availableusers->_numOfRows . ")\">\n";
                  while ($user = rs_fetch_next_record($availableusers)) {
                      if (!isset($enrolledusers[$user->id])) {
                          $fullname = fullname($user, true);
                          echo "<option value=\"$user->id\">".$fullname.", ".$user->email."</option>\n";
                      }
                  }
                  echo "</optgroup>\n";

              } else {
                  if ($availableusers->_numOfRows > 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";
                      }
                  }
              }
          ?>
         </select>
         <br />
         <input type="text" name="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($searchusers)) {
                  echo '<input name="showall" id="showall" type="submit" value="'.$strshowall.'" />'."\n";
              }
         ?>
       </td>
    </tr>
    <tr>
      <td valign="top"><?php print_string('otherenrolledusers', 'mnet'); ?>:<br />
          <ul>
          <?php
            foreach ($remtenrolledusers as $enrolleduser) {
                $fullname = fullname($enrolleduser, true);
                print '<li>'
                    . s($fullname) . ' (' . s($enrolleduser->rolename) . ') '
                    . s($enrolleduser->enroltype)."</li>\n";
            }
          ?></ul></td>
      <td valign="top"></td>
      <td valign="top"></td>
    </tr>
  </table>
  </div>
</form>
