#include <stdio.h>


#include "global.h"

#include "manhat-lib/shared_util.h"
#include "manhat-lib/shared_super_util.h"
#include "manhat-lib/shared_authenticate.h"
#include "manhat-lib/shared_strtrm.h"
#include "manhat-lib/shared_cs_util.h"
#include "manhat-lib/shared_super_menu.h"


void
read_parameters( char *username, char *realname,  char *key, ADMIN_CONFIG_STRUCT *conf)
{

   cs_get_required_parameter("id", key, MAX_KEY);
   
   cs_get_required_parameter("username", username, MAX_USERNAME);

   cs_get_required_parameter("realname", realname, MAX_NAME);
   
   get_cgi_admin_config_values(conf);   /* shared_super_util.c */
   snprintf(conf->page_title, MAX_ADMIN_PAGE_TITLE + 1, "%s", realname);

}






void
show_success(ADMIN_CONFIG_STRUCT *conf, const char *key,  char *username,  char *realname)
{
    
    super_conf_info_table(conf, username, realname);  /*shared_super_util.c */
    cs_set_int_value("grant_success", 1);
}




int
main()
{
    char key[MAX_KEY +1];
    SESSION user;
    ADMIN_CONFIG_STRUCT  new_conf;
    char username[MAX_USERNAME + 1];
    char realname[MAX_NAME + 1];


    cs_cgi_init();


    read_parameters( username, realname, key, &new_conf);
    validate_super_key(key, &user);    
    set_admin_page(&user, key, 0, "super_grant_admin_form");  /* shared_super_menu.c */



    write_super_configuration_file(username, &new_conf);
    show_success(&new_conf,key, username, realname);
    cs_cgi_display("super_add_admin_form", 1);
    cs_cgi_destroy();
    return 0;
}
