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

<?cs def:print_list(data) ?>
<table width="100%">
 <tr><td align="center">
  <br />
  <br />
  <fieldset style="width: 50%">
  <legend class="fieldset_legend"><?cs var:data.title ?></legend>
  <div><form method="post" action="admin_chg_form" onsubmit="return select_user_warn()" >
   <div>
     <input type="hidden" name="id" value="<?cs var:id ?>" />
     <input type="hidden" name="crs" value="<?cs var:crs ?>" />
   </div>
  <table cellspacing="0" cellpadding="4">
   <tr><td><select name="student" size="10" title="<?cs var:data.select.help ?>" id="student">
    <?cs each:this = user ?>
     <option value="<?cs var:this.value ?>"><?cs var:this.realname ?></option>
    <?cs /each ?>
    </select></td>
    <td valign="middle" class="regheading" align="center">
     <?cs var:data.check[0] ?><br />
      <input type="submit" name="oper" value="<?cs var:data.check[1] ?>" title="<?cs var:data.check[3] ?>" /><br />
      <?cs var:data.check[2] ?>
    </td>
   </tr>
  </table> 
  </form></div>
 </fieldset>
 </td></tr>
</table>
<?cs /def ?>

<?cs def:print_row(label, name, value) ?>
 <tr>
    <td class="regheading"><?cs var:label.msg ?></td>
    <td><input type="text" name="<?cs var:name ?>" id="<?cs var:name ?>" value="<?cs var:value ?>" title="<?cs var:label.help ?>" /></td>
   <td class="instructions"><?cs var:label.desc ?></td>
 </tr>
<?cs /def ?>

<?cs def:print_hidden() ?>
  <div>
   <input type="hidden" name="id" id="id" value="<?cs var:id ?>" />
   <input type="hidden" name="crs" id="crs" value="<?cs var:crs ?>" />
   <input type="hidden" name="username" id="username" value="<?cs var:username ?>" />
   <input type="hidden" name="realname" id="realname" value="<?cs var:realname ?>" />
   <input type="hidden" name="group" id="group" value="<?cs var:group ?>" />
   <input type="hidden" name="ssn" id="ssn" value="<?cs var:ssn ?>" />
   <input type="hidden" name="is_standalone" id="is_standalone" value="<?cs var:is_standalone ?>" />
   <input type="hidden" name="team" id="team" value="<?cs var:team ?>" />
   <input type="hidden" name="alias" id="alias" value="<?cs var:alias ?>" />
  </div>
<?cs /def ?>

<?cs def:print_team(label, name, value) ?>
 <tr>
   <td class="regheading"><?cs var:label.msg ?></td>
   <td><select name="<?cs var:name ?>" title="<?cs var:label.help ?>" id="<?cs var:name ?>">
      <?cs each:this = team_letter ?>
         <?cs if:this.internal == value ?>
          <option value="<?cs var:this.internal ?>" selected="selected"><?cs var:this.display ?></option>
         <?cs else ?>
          <option value="<?cs var:this.internal ?>"><?cs var:this.display ?></option>
         <?cs /if ?>
      <?cs /each ?> 
     </select></td>
    <td class="instructions"><?cs var:label.desc ?></td>
  </tr>
<?cs /def ?>

<?cs def:print_submit(change) ?>
 <tr>
   <td colspan="2" align="center">
    <input type="hidden" name="new_ssn" value="<?cs var:user_id ?>" />
    <input type="submit" value="<?cs var:change.msg ?>" title="<?cs var:change.help ?>" />
   </td><td>&nbsp;</td>
 </tr>
<?cs /def ?>

<?cs def:print_notes(data) ?>  
 <div class="notes">
 <?cs each:this = data.notes.entry ?>
  <div class="instructions">
  <div><b><?cs var:this.msg ?></b></div>
  <div style="margin-bottom:1em"><?cs var:this.desc ?></div>
   </div>
 <?cs /each ?>
</div>
<?cs /def ?>
 
<?cs def:print_form(data) ?>
<table width="100%">
<tr><td align="center">
  <br />
  <br />
 <fieldset style="width:80%">
  <legend class="fieldset_legend"><?cs var:data.title ?></legend>
 <div><form method="post" action="admin_chg_student" onsubmit="return validate_user_data()">
   <?cs call:print_hidden() ?>
  <table cellspacing="0" cellpadding="4">
   <tr>
      <?cs if:!hide_manhattan_username ?>
       <td class="regheading"><?cs var:data.label[0].msg ?></td>
       <td><?cs var:username ?></td>
      <?cs /if ?>
   </tr>  
   <?cs call:print_row(data.label[1], "new_realname", realname) ?>
   <?cs call:print_row(data.label[2], "new_alias", alias) ?>
   <?cs call:print_team(data.label[3], "new_team", team) ?>
   <?cs call:print_submit(data.change) ?>
  </table>
 </form></div> 
<?cs call:print_notes(data) ?>  
 </fieldset>
</td></tr>
</table>
<?cs /def ?>

<?cs def:print_s_row(label, value) ?>
 <tr>
   <td class="regheading"><?cs var:label.msg ?></td>
   <td><?cs var:value ?></td>
 </tr>
<?cs /def ?>

<?cs def:print_success(data) ?>
<table width="100%">
<tr><td align="center">
  <br />
  <br />
  <fieldset style="width:50%"> 
  <legend class="fieldset_legend"><?cs var:data.success_title ?></legend>
  <table cellspacing="0" cellpadding="4" border="1">
   <?cs if:!hide_manhattan_username ?>
   <?cs call:print_s_row(data.label[0], username) ?>
   <?cs /if ?>
   <?cs call:print_s_row(data.label[1], realname) ?>
   <?cs call:print_s_row(data.label[2], alias) ?>
   <?cs call:print_s_row(data.label[3], team) ?>
  </table> 
 <?cs if:team_chg == #0 || team_chg == #1 ?>
  <div>
   <?cs var:data.team_chg[team_chg] ?>
  </div>
 <?cs /if ?> 
 </fieldset>
</td></tr>
</table>
<?cs /def ?>


<?cs call:html_heading() ?>
 <head>
   <title><?cs var:lang.admin_chg_form.title ?></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 select_user_warn()
  {
      var index = document.getElementById('student').selectedIndex;
      if(index < 0)
      {
          window.alert('<?cs var:lang.admin_chg_form.select_user_warn ?>');
          return false;
      }
      return true;
  } 
  function validate_user_data()
  {
      var n_realname = document.getElementById('new_realname').value;
      var n_alias = document.getElementById('new_alias').value;
      var index = document.getElementById('new_team').selectedIndex;
      var n_team = document.getElementById('new_team').value;
      
      if(is_whitespace(n_realname) || is_whitespace(n_alias) || index < 0)
      {
          window.alert('<?cs var:lang.admin_chg_form.new_data_warn ?>');
          return false; 
      }
      var realname = document.getElementById('realname').value;
      var alias = document.getElementById('alias').value;
      var team = document.getElementById('team').value;
      if(realname == n_realname && alias == n_alias && team == n_team)
      {
          window.alert('<?cs var:lang.admin_chg_form.no_change_warn ?>');
          return false; 
          
      } 
      return window.confirm('<?cs var:lang.admin_chg_form.confirm_warn ?>');
     
  }
 </script> 
  </head>
<?cs call:define_body() ?>

<?cs call:print_course_heading(back_url, lang.admin_chg_form.goback) ?>
<?cs if:display ?>
 <?cs call:print_form(lang.admin_chg_form) ?>
<?cs elif:success ?>
 <?cs call:print_success(lang.admin_chg_form) ?>
<?cs else ?>
 <?cs call:print_list(lang.admin_chg_form) ?>
<?cs /if ?>
</body>
</html>
<?cs call:runtime() ?>
