<?cs include:"util.cs" ?>

<?cs def:print_search_form() ?>
<?cs with:lang=lang.admin_search_form ?>
<table width="100%">
<tr><td align="center">
<br />
<br />
<fieldset style="width:50%">
<legend class="fieldset_legend">
   <?cs if:add_type=="student" ?><?cs var:lang.add_student_heading ?><?cs else ?><?cs var:lang.add_teacher_heading ?><?cs /if ?>
</legend>
<table border="0">
<tr>
 <td valign="middle"> 
  <div><form method="post" action="admin_search_form" onsubmit="return validate_search()" >
     <div> 
     <?cs each:this=form ?>
         <input type="hidden" name="<?cs name:this?>" value="<?cs var:this ?>" />
     <?cs /each ?>
     </div>
  <div class="center_msg">
    <span class="regheading"><?cs var:lang.search_string_prompt ?></span>
    <input type="text" name="search" id="search" size="12" maxlength="<?cs var:maximum_search_len ?>" title="<?cs var:lang.search_box_title ?>" />
    <input type="submit" name="search_button" value="<?cs var:lang.search_button ?>" title="<?cs var:lang.search_button_title ?>" />
  </div>
  </form></div>
 </td>
<td width="50%"><span class="instructions"><?cs var:lang.search_instructions ?></span></td>
</tr>
</table>
</fieldset>
</td></tr></table>
<?cs /with ?>
<?cs /def ?>




<?cs def:print_course_lookup_form() ?>
<?cs with:lang=lang.admin_search_form ?>
<?cs if:include_course_search_form ?>
<hr />
<table width="100%">
<tr><td align="center">
  <div class="instructions">
  <?cs var:lang.lookup_description  ?>
 </div>
 <div><form method="post" action="admin_course_search_form">
     <div> 
      <input type="hidden" name="crs" value="<?cs var:form.crs ?>" />
      <input type="hidden" name="id" value="<?cs var:form.id ?>" />
      <input type="hidden" name="group" value="<?cs var:form.group ?>" />
     </div>
     <div class="center_msg">
     <input type="submit" value="<?cs var:lang.lookup_submit_button ?>" title="<?cs var:lang.lookup_submit_help ?>" />
     </div>
 </form></div>
</tr></tr></table>
<?cs /if ?>
<?cs /with ?>
<?cs /def ?>




<?cs def:print_result() ?>
<?cs if:Query.search_button && user_count == #0?>
   <div class="center_msg"><?cs var:lang.admin_search_form.no_matches_found ?></div>
<?cs elif:user_count > 0 ?>
  <table width="100%">
  <tr><td align="center">
    <div><form method="post" action="admin_add_group_students" onsubmit="return validate_add_from_list()">
      <div>
      <input type="hidden" name="crs" value="<?cs var:form.crs ?>" />
      <input type="hidden" name="id" value="<?cs var:form.id ?>" />
      <input type="hidden" name="group" value="<?cs var:form.group ?>" />
      </div> 
     <table border="1" cellspacing="0" cellpadding="4">
     <caption><i><?cs var:user_count ?> <?cs var:lang.admin_search_form.match ?></i> 
     <?cs if:max_matches_exceeded ?>
       <br /><i><?cs var:lang.admin_search_form.not_all_displayed ?></i>
     <?cs /if ?>
     </caption>
     <tr class="table_heading">

       <td class="regheading" align="center"><?cs var:lang.admin_search_form.table.select ?></td>
       <?cs if:!hide_manhattan_username ?>
       <td class="regheading" align="center"><?cs var:lang.admin_search_form.table.username ?></td>
        <?cs /if ?>
       <?cs each:this = lang.admin_search_form.table ?>
       <td class="regheading" align="center"><?cs var:this ?></td>
       <?cs /each ?>
     </tr>
     <?cs set:num_users = #0 ?>
     <?cs each:person = user ?>
     <tr>
         <?cs if:!person.in_class ?>
            <?cs set:num_users = #1 + num_users ?>
            <td align="center"><input type="checkbox" name="users" id="users" value="<?cs var:person.username ?>:<?cs var:person.realname ?>:<?cs var:person.id ?>" title="<?cs var:person.realname ?> : <?cs var:lang.admin_search_form.select_help ?>" /></td>
         <?cs else ?>
           <td><a href="javascript:openwindow('<?cs var:person.password_file_url ?>', 'win')" title="<?cs var:lang.admin_search_form.password_file_help ?>" ><?cs var:lang.admin_search_form.in_your_class ?></a></td>
        <?cs /if ?>

         <?cs if:!hide_manhattan_username ?><td><?cs var:person.display_username ?></td> <?cs /if ?> 
         <td><?cs var:person.display_realname ?></td>  
         <td><?cs var:person.display_id ?></td>  

        <?cs if:!person.in_class ?>
        <td>
         <select name="<?cs var:person.username ?>" title=" <?cs var:person.realname ?> : <?cs var:lang.admin_search_form.select_team_help ?>" >
         <?cs each:this = team_letter ?>
             <option value="<?cs var:this.internal ?>" <?cs if:default_team ==  this.internal ?>selected="selected"<?cs /if ?>><?cs var:this.display ?></option>
         <?cs /each ?>
         </select></td>
        <?cs else ?>
         <?cs each:this = team_letter ?>
           <?cs if:this.internal == person.team ?>
             <td align="center" ><?cs var:this.display ?></td>
           <?cs /if ?>
         <?cs /each ?>
        <?cs /if ?>
     </tr> 
     <?cs /each ?>
     <?cs if:num_users > #0 ?>
     <tr>
       <td colspan="5" align="center">
          <input type="submit" value="<?cs var:lang.admin_search_form.add_user_button ?>" title="<?cs var:lang.admin_search_form.add_user_button ?>" />
       </td>
     </tr> 
     <?cs /if ?>
     </table>
    </form></div>
  </td></tr>
  </table>
<?cs /if ?>
<?cs /def ?>







<?cs def:print_text(name, value, max) ?>
  <tr>
     <td class="regheading"><?cs var:value ?></td>
     <td><input type="text" name="<?cs var:name ?>" id="<?cs var:name ?>" title="<?cs var:value.help ?>" size="15" maxlength="<?cs var:max ?>" /></td>
  </tr>
<?cs /def ?>





<?cs def:print_new_account_form() ?>
<?cs with:lang=lang.admin_search_form ?>
 <?cs if:show_new_form ?>
  <table width="100%" border="0">
  <tr><td align="center">
   <div><form method="post" action="admin_add_new_student" onsubmit="return validate_new_add()"  >
      <div>
      <input type="hidden" name="crs" value="<?cs var:form.crs ?>" />
      <input type="hidden" name="id" value="<?cs var:form.id ?>" />
      <input type="hidden" name="group" value="<?cs var:form.group ?>" />
      </div> 
  <fieldset style="width:35%">
  <legend class="fieldset_legend"><?cs var:lang.create_new_account_heading ?></legend>
   <table border="0">
      <?cs call:print_text("first", lang.first_name_label, max_name) ?>
      <?cs call:print_text("last", lang.last_name_label, max_name) ?>
      <?cs call:print_text("user_id", lang.id_label, max_id) ?>
      <tr>
        <td class="regheading"><?cs var:lang.team_label ?></td>
        <td><select name="team" title="<?cs var:lang.team_label.help ?>" >
        <?cs each:this = team_letter ?>
              <option value="<?cs var:this.internal ?>" <?cs if:this.internal==default_team ?>selected="selected"<?cs /if ?>><?cs var:this.display ?></option>
        <?cs /each ?>
       </select></td>
     </tr> 
     <tr><td colspan="2" align="center">
         <input type="submit" value="<?cs var:lang.new_user_submit_button ?>" title="<?cs var:lang.new_user_submit_button_help ?>" />
        </td>
     </tr>
   </table> 
   </fieldset>
   </form></div>
  </td></tr>
  </table>
 <?cs /if ?> 
<?cs /with ?>
<?cs /def ?>

<?cs call:html_heading() ?>
<head>
      <title><?cs var:course_title ?> <?cs var:course_no ?> <?cs var:semester ?>
   <?cs if:add_type=="student" ?><?cs var:lang.admin_search_form.add_student_heading ?><?cs else ?><?cs var:lang.admin_search_form.add_teacher_heading ?><?cs /if ?>
   </title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <link rel="StyleSheet" href="<?cs var:image_path ?>common.css" type="text/css"  />
   <script type="text/javascript" src="<?cs var:image_path ?>form_validation.js"></script>
<script type="text/javascript">
function openwindow(some_url,winname)
{
 var new_window = window.open(some_url, winname,'menubar=0,toolbar=0,status=0,scrollbars=yes,resizable=yes,width=650,height=600');
 new_window.focus();
}

function validate_search()
{
 if(window.document.getElementById('search').value.length < <?cs var:minimum_search_len ?> )
   {
        window.alert('<?cs var:lang.admin_search_form.search_too_short ?>');
        return false;
   }
 else
        return true;
}




function validate_add_from_list()
{
  var obj = document.forms[1].users;
  if(obj.checked)
    return true;
  else 
  {
     if(obj.length >0)
     {
         for(i =0; i<obj.length; i++)
         {
             if(obj[i].checked)
               return true;
         }
     }
     window.alert('<?cs var:lang.admin_search_form.no_users_selected ?>');
     return false;
  }
}






<?cs ## include a validation script for adding a completely new user,
        if that form will be presented in the first place
## ?>

<?cs if:show_new_form ?>
function validate_new_add()
{
  var value = document.getElementById('first').value;
 if( is_whitespace(value)  )
  {
   window.alert('<?cs var:lang.admin_search_form.first_name_blank ?>');
   return false;
  }

  value = document.getElementById('last').value;
 if(is_whitespace(value))
  {
   window.alert('<?cs var:lang.admin_search_form.last_name_blank ?>');
   return false;
  }
  value = document.getElementById('user_id').value;

 if( is_whitespace(value))
  {
   window.alert('<?cs var:lang.admin_search_form.id_number_blank ?>');
   return false;
  }

 return true;

} 
<?cs /if ?>
</script>
</head>
<?cs call:define_onload_body("search") ?>
<?cs call:print_course_heading(back_url, lang.admin_search_form.goback) ?>
<?cs call:print_search_form() ?>
<?cs call:print_result() ?>
<?cs call:print_new_account_form() ?>
<?cs call:print_course_lookup_form() ?>
</body>
</html>
<?cs call:runtime() ?>

