#include <stdio.h>
#include <string.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_cs_util.h"
#include "manhat-lib/shared_super_menu.h"

       
    
DEL_COURSE_NODE *
read_parameters(char *key)
{
     DEL_COURSE_NODE *head;     /*shared_super_util.c */

     cs_get_required_parameter ("id", key, MAX_KEY);   /* shared_cs_util.c */
     cs_set_value ("id", key);   /* shared_cs_util.c */
     head = build_selected_course_list();               /* shared_super_util.c */
     return head;
}
	

void
set_confirmation_data( const char *key, DEL_COURSE_NODE *head)
{
   #define MAX_TMP_NAME 50
    DEL_COURSE_NODE *ptr;
    char name[MAX_TMP_NAME];
    int i =0;
    
   if(!head)
        cs_critical_error( ERR_NO_COURSE_MSG, "");

   for(ptr = head; ptr; ptr = ptr->next)
    {
	snprintf(name, MAX_TMP_NAME, "course_list.%d.id", i);
	cs_set_value(name, ptr->del_id);
	snprintf(name, MAX_TMP_NAME, "course_list.%d.info", i);
	cs_set_value(name, ptr->del_info);
        i++;
    }
#undef MAX_TMP_NAME 
	    
}


int main()
{
    char key[MAX_KEY +1];
    SESSION user;
    DEL_COURSE_NODE *head;
    
    cs_cgi_init();      /* shared_cs_util.h */
    head = read_parameters(key);
    validate_super_key(key, &user);    /* shared_super_util.c */
    set_admin_page(&user, key, 0, "super_delete_course_form"); /* shared_super_menu.c */
    set_confirmation_data (key, head);
    free_del_list(head); /* shared_super_util.c */
    cs_cgi_display("super_delete_course_confirm", 1);
    cs_cgi_destroy(); 
    return 0;
}

