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

<?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() ?>
  <fieldset style="width:35%">
  <legend class="fieldset_legend"><?cs var:lang.admin_add_new_student.create_new_account_heading ?></legend>
   <div><form method="post" action="admin_add_new_student" onsubmit="return validate_new_add()"  >
      <div>
      <input type="hidden" name="crs" value="<?cs var:crs ?>" />
      <input type="hidden" name="id" value="<?cs var:id ?>" />
      <input type="hidden" name="group" value="<?cs var:group ?>" />
      </div> 
   <table border="0">
      <?cs call:print_text("first", lang.admin_add_new_student.first_name_label, max_name) ?>
      <?cs call:print_text("last", lang.admin_add_new_student.last_name_label, max_name) ?>
      <?cs call:print_text("user_id", lang.admin_add_new_student.id_label, max_id) ?>
      <tr>
        <td class="regheading"><?cs var:lang.admin_add_new_student.team_label ?></td>
        <td><select name="team" title="<?cs var:lang.admin_add_new_student.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.admin_add_new_student.new_user_submit_button ?>" title="<?cs var:lang.admin_add_new_student.new_user_submit_button_help ?>" />
        </td>
     </tr>
   </table> 
   </form></div>
   </fieldset>
<?cs /def ?>




<?cs def:print_existing_user() ?>
<div class="center_msg"><span class="alert_color"> <?cs if:add_type=="student" ?><?cs var:lang.admin_add_new_student.add_student_heading ?><?cs else ?><?cs var:lang.admin_add_new_student.add_teacher_heading ?><?cs /if ?></span>
</div>

  <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:Query.crs ?>" />
      <input type="hidden" name="id" value="<?cs var:Query.id ?>" />
      <input type="hidden" name="group" value="<?cs var:Query.group ?>" />
      </div> 
     <table border="1" cellspacing="0" cellpadding="4">
     <caption><i> <?cs var:lang.admin_add_new_student.existing_user ?></i> 
     </caption>
     <tr class="table_heading">
       <?cs each:this = lang.admin_add_new_student.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 ?>" checked="checked" title="<?cs var:person.realname ?> : <?cs var:lang.admin_add_new_student.select_help ?>" /></td>
         <?cs else ?>
           <td><a href="javascript:openwindow('<?cs var:person.password_file_url ?>', 'win')" title="<?cs var:lang.admin_add_new_student.password_file_help ?>" ><?cs var:lang.admin_add_new_student.in_your_class ?></a></td>
        <?cs /if ?>

         <td><?cs var:person.display_username ?></td>  
         <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_add_new_student.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_add_new_student.add_user_button ?>" title="<?cs var:lang.admin_add_new_student.add_user_button ?>" />
       </td>
     </tr> 
     <?cs /if ?>
     </table>
    </form></div>
    <?cs if:num_users == #0 ?>
     <?cs call:print_new_account_form() ?>
    <?cs /if ?>
  </td></tr>
  </table>
<?cs /def ?>


<?cs def:print_add_success() ?>
<div class="center_msg"><span class="alert_color"> <?cs if:add_type=="student" ?><?cs var:lang.admin_add_new_student.student_added_heading ?><?cs else ?><?cs var:lang.admin_add_new_student.teacher_added_heading ?><?cs /if ?></span>
</div>

<table width="100%">
<tr><td align="center">
<table cellspacing="0" cellpadding="4" border="1">
<tr>
<?cs each:this = lang.admin_add_new_student.table_heading ?>
    <td class="table_heading" align="center"><?cs var:this ?></td>
<?cs /each ?>
</tr>
   <tr>
     <td><?cs var:username ?></td>
     <td><?cs var:realname ?></td>
     <td><?cs var:id ?></td>
     <td align="center"><?cs if:add_type == "student" ?><?cs var:lang.admin_add_new_student.student ?><?cs else ?><?cs var:lang.admin_add_new_student.faculty ?><?cs /if ?></td>
     <td align="center"><?cs var:team ?></td>
  </tr>
</table>
</td></tr></table>
<?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_add_new_student.add_student_heading ?><?cs else ?><?cs var:lang.admin_add_new_student.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>

<?cs if:user_count ?>
<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_add_from_list()
{
  var obj = document.getElementById('users');
  if(obj.checked)
    return true;
  window.alert('<?cs var:lang.admin_add_new_student.no_users_selected ?>');
     return false;
  }
}

function validate_new_add()
{
  var value = document.getElementById('first').value;

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

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

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

} 
</script>
<?cs /if ?>
</head>

<?cs call:define_body() ?>
<?cs call:print_course_heading(back_url, lang.admin_add_new_student.goback) ?>
<?cs if:existing_user ?>
<?cs call:print_existing_user() ?>
<?cs else ?>
<?cs call:print_add_success() ?>
<?cs /if ?>
</body>
</html>
<?cs call:runtime() ?>

