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

<?cs def:print_form(name,  type, label, size, max) ?>
    <tr>
     <th align="left"><?cs var:label.msg ?></th>
       <td><input type="<?cs var:type ?>" size="<?cs var:size ?>" maxlength="<?cs var:max ?>"  name="<?cs var:name ?>" id="<?cs var:name ?>"  title="<?cs var:label.help ?>"  />
       </td>
    </tr>
<?cs /def ?>

<?cs def:print_checkbox(name, value, label, selected) ?>
    <tr>
     <td align="right">
      <?cs if:selected ?>
      <input type="checkbox" name="<?cs var:name ?>" value="<?cs var:value ?>" title="<?cs var:label.help ?>"  checked="checked" />
      <?cs else ?> 
      <input type="checkbox" name="<?cs var:name ?>" value="<?cs var:value ?>" title="<?cs var:label.help ?>"  />
      <?cs /if ?> 
     </td>
    <td><?cs var:label.name ?></td>
   </tr>
<?cs /def ?>        

<?cs def:print_row(label, value) ?> 
  <tr>
    <th align="left"><?cs var:label ?></th>
    <td><?cs var:value ?></td>
  </tr>
<?cs /def ?>        
   
       

<?cs def:print_success() ?> 
  <table width="100%">
  <tr><td align="center">
  <table border="1" cellspacing="0" cellpadding="4">
   <caption><?cs var:current_time ?></caption>
    <?cs call:print_row(lang.super_add_admin_form.user[0].msg, username) ?> 
    <tr>
      <th colspan="2" > 
      <?cs var:lang.super_add_admin_form.granted_privilege ?>
      </th>
    </tr>
    <?cs each:this = conf_course ?>
    <tr>
      <td>&nbsp;</td>
       <?cs if:this == "surveys" ?>
      <td><?cs var:lang.super_menu[this].name ?></td>
       <?cs else ?>
      <td><?cs var:lang.super_menu.course[this].name ?></td>
      <?cs /if ?>
    </tr>
    <?cs /each ?>
    <?cs each:this = conf_people ?>
    <tr>
      <td>&nbsp;</td>
      <td><?cs var:lang.super_menu.people[this].name ?></td>
    </tr>
    <?cs /each ?>
    <?cs each:this = conf_usageReport ?>
    <tr>
      <td>&nbsp;</td>
      <td><?cs var:lang.super_menu.usageReport[this].name ?></td>
    </tr>
    <?cs /each ?>

    <?cs each:this = conf_server ?>
    <tr>
      <td>&nbsp;</td>
      <td><?cs var:lang.super_menu.server[this].name ?></td>
    </tr>
    <?cs /each ?>
    <?cs each:this = conf_cleanup ?>
    <tr>
      <td>&nbsp;</td>
      <td><?cs var:lang.super_menu.cleanup[this].name ?></td>
    </tr>
    <?cs /each ?>

  </table> 
  <h4><br />
   <a href="<?cs var:url ?>" ><?cs var:url ?></a>
  </h4>
  </td></tr>
  </table> 
<?cs /def ?>        

<?cs def:print_operation() ?>
   <tr><th align="left"><?cs var:lang.super_menu.course["name"] ?></th></tr> 
   <?cs call:print_checkbox("create_new_course", #1, lang.super_menu.course["create_course"], conf_course.0.selected) ?>
   <?cs call:print_checkbox("delete_courses", #1, lang.super_menu.course["delete_course"], conf_course.1.selected) ?>
   <?cs call:print_checkbox("config_courses", #1, lang.super_menu.course["configure_course"], conf_course.2.selected) ?>
   <?cs call:print_checkbox("change_courses", #1, lang.super_menu.course["change_course_access"], conf_course.3.selected) ?>
   <?cs call:print_checkbox("archive_courses", #1, lang.super_menu.course["archive_courses"], conf_course.4.selected) ?>
   <?cs call:print_checkbox("admin_survey", #1, lang.super_menu["surveys"], conf_course.5.selected) ?>
   <tr><th align="left"><?cs var:lang.super_menu.people["name"] ?></th></tr> 
   <?cs call:print_checkbox("search_profile", #1, lang.super_menu.people["profile"], conf_people.0.selected) ?>
   <?cs call:print_checkbox("whos_on", #1, lang.super_menu.people["who_is_on_manhattan"], conf_people.1.selected) ?>
   <?cs call:print_checkbox("statistics", #1, lang.super_menu.people["login_logs"], conf_people.2.selected) ?>
   <tr><th align="left"><?cs var:lang.super_menu.server["name"] ?></th></tr> 

   <?cs call:print_checkbox("disk_space", #1, lang.super_menu.usageReport["disk_space"], conf_server.0.selected) ?>
   <?cs call:print_checkbox("course_disk_usage", #1, lang.super_menu.usageReport["course_disk_usage"], conf_server.1.selected) ?>
   <?cs call:print_checkbox("chat_server", #1, lang.super_menu.server["manage_chat"], conf_server.2.selected) ?>
   <?cs call:print_checkbox("lock_server", #1, lang.super_menu.server["lock_server"], conf_server.3.selected) ?>
   <?cs call:print_checkbox("clean_up", #1, lang.super_menu.cleanup["clean_up"], conf_server.4.selected) ?>
   <?cs call:print_checkbox("purge_postoffice_message", #1, lang.super_menu.cleanup["purge_postoffice_message"], conf_server.5.selected) ?>
<?cs /def ?>

<?cs def:print_grant_form() ?>
  <div><form method="post" action="super_grant" onsubmit="return validate_all_form()">
  <div>
      <input type="hidden" name="id" value="<?cs var:Query.id ?>" />
      <input type="hidden" name="username" value="<?cs var:username ?>" />
      <input type="hidden" name="realname" value="<?cs var:realname ?>" />
  </div>
  <table cellspacing="0" cellpadding="4">
  <?cs call:print_operation() ?>
   <tr><th colspan="2" >
    <input type="submit" value="<?cs var:lang.super_add_admin_form.grant ?>" title="<?cs var:lang.super_add_admin_form.grant_help ?>" class="super_color_button" />
   </th></tr> 
  </table>
<?cs /def ?>

<?cs def:print_content() ?>
<fieldset>
<?cs if:display_add_success || grant_success ?>
  <?cs if:display_add_success ?>
    <legend><?cs var:realname ?> <?cs var:lang.super_add_admin_form.has_been_added ?></legend>
  <?cs else ?>
   <legend><?cs var:realname ?> <?cs var:lang.super_add_admin_form.grant_success ?></legend>
  <?cs /if ?>
<?cs elif:grant_display ?>
   <legend> <?cs var:lang.super_add_admin_form.grant_msg ?></legend>
<?cs else ?>
  <legend><?cs var:lang.super_add_admin_form.page_title ?></legend>
<?cs /if ?>
  <?cs if:display_add_success || grant_success ?>
    <?cs call:print_success() ?> 
  <?cs elif:grant_display ?>
     <?cs call:print_grant_form() ?>
  <?cs else ?>
  <div><form method="post" action="super_add_admin"  onsubmit="return  validate_all_form()" >
   <div><input type="hidden" name="id" value="<?cs var:Query.id ?>" />
   </div>
  <table cellspacing="0" cellpadding="4">
   <?cs call:print_form("username", "text", lang.super_add_admin_form.user[0], #15, maxusername) ?>
   <?cs call:print_form("passwd", "password", lang.super_add_admin_form.user[1], #15, maxpass) ?>
   <?cs call:print_form("passwd2", "password", lang.super_add_admin_form.user[2], #15, maxpass) ?>
   <?cs call:print_form("first_name", "text", lang.super_add_admin_form.user[3], #20, maxusername) ?>
   <?cs call:print_form("last_name", "text", lang.super_add_admin_form.user[4], #20, maxusername) ?>
   <tr><th colspan="2" ><br /><?cs var:lang.super_add_admin_form.select ?></th></tr>
   <?cs call:print_operation() ?>
   <tr><td colspan="2" align="center">
    <input type="submit" value="<?cs var:lang.super_add_admin_form.submit ?>" title="<?cs var:lang.super_add_admin_form.submit_help ?>" class="super_color_button" />
   </td></tr> 
  </table>
   </form></div>
   <script type="text/javascript"> document.forms[0].username.focus(); </script> 
  <?cs /if ?>
</fieldset>
<?cs /def ?>

<?cs call:html_header() ?> 
   <head>
     <?cs if:grant_display || grant_sucess ?>
      <title><?cs var:lang.super_add_admin_form.grant_msg ?></title>
     <?cs else ?>
      <title><?cs var:lang.super_add_admin_form.page_title ?></title>
     <?cs /if ?>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <link rel="StyleSheet" href="<?cs var:image_path ?>super_template.css" type="text/css"  />
   <script type="text/javascript" src="<?cs var:image_path ?>form_validation.js"></script>
   <?cs call:addDoIMenu() ?>
   <script type="text/javascript">
    function check_operations()
    {
        var count =0;
        var check = document.forms[0].create_new_course.checked;
        if(check)
           count++;
        check = document.forms[0].delete_courses.checked;
        if(check)
           count++;
        check = document.forms[0].config_courses.checked;
        if(check)
           count++;
        check = document.forms[0].change_courses.checked;
        if(check)
           count++;
        check = document.forms[0].archive_courses.checked;
        if(check)
           count++;

        check = document.forms[0].course_disk_usage.checked;
        if(check)
           count++;
        check = document.forms[0].purge_postoffice_message.checked;
        if(check)
           count++;

        check = document.forms[0].admin_survey.checked;
        if(check)
           count++;
        check = document.forms[0].search_profile.checked;
        if(check)
           count++;
        check = document.forms[0].whos_on.checked;
        if(check)
           count++;
        check = document.forms[0].statistics.checked;
        if(check)
           count++;
        check = document.forms[0].disk_space.checked;
        if(check)
           count++;
        check = document.forms[0].chat_server.checked;
        if(check)
           count++;
        check = document.forms[0].lock_server.checked;
        if(check)
           count++;
        check = document.forms[0].clean_up.checked;
        if(check)
           count++;
        if(count)
          return true;
       return false; 
       
    }
    function validate_all_form()
    {
       
      <?cs if:!grant_display ?>
        var value = document.getElementById('username').value;
        if(is_whitespace(value))
        {
            window.alert('<?cs var:lang.super_add_admin_form.username_must_filled ?>');
            return false;
        }
        if(value.length <= 4 )
        {
            window.alert('<?cs var:lang.super_add_admin_form.username_certain_num ?>');
            return false;
        }

        value = document.getElementById('passwd').value;
        if(is_whitespace(value))
        {
            window.alert('<?cs var:lang.super_add_admin_form.password_must_filled ?>');
            return false;
        }
        if(value.length <= 5 )
        {
            window.alert('<?cs var:lang.super_add_admin_form.password_certain_num ?>');
            return false;
        }
       
        var value2 = document.getElementById('passwd2').value;
        if(is_whitespace(value))
        {
            window.alert('<?cs var:lang.super_add_admin_form.password2_must_filled ?>');
            return false;
        }
        if(value != value2)
        {
            window.alert('<?cs var:lang.super_add_admin_form.password2_equals_password ?>');
            return false;
        }

        value = document.getElementById('first_name').value;
        if(is_whitespace(value))
        {
            window.alert('<?cs var:lang.super_add_admin_form.firstname_must_filled ?>');
            return false;
        }
        value = document.getElementById('last_name').value;
        if(is_whitespace(value))
        {
            window.alert('<?cs var:lang.super_add_admin_form.lastname_must_filled ?>');
            return false;
        }
        <?cs /if ?>
       if(!check_operations())
        {
            window.alert('<?cs var:lang.super_add_admin_form.must_grant_user_one_operation ?>');
            return false;
        }
      <?cs if:grant_display ?>
       return window.confirm('<?cs var:lang.super_add_admin_form.modify_admin_warn_msg ?>'); 
      <?cs else ?>
       return window.confirm('<?cs var:lang.super_add_admin_form.add_admin_warn_msg ?>'); 
      <?cs /if ?> 
    }   
   </script> 
  </head>

<body>
<?cs if:super_action ?>
    <?cs call:print_success() ?> 
<?cs else ?>
<div id="container">
 <?cs call:top_container() ?>
 <?cs call:doIMenu() ?>
 <div id="content">

  <?cs call:print_content() ?>
 </div>
</div>

<?cs /if ?>
</body>
</html>
<?cs call:runtime() ?>
