#include <stdlib.h>
#include <stdio.h>
#include "global.h"
#include "survey.h"

#include "manhat-lib/shared_util.h"
#include "manhat-lib/shared_cs_course_search.h"
#include "manhat-lib/shared_survey_path_util.h"
#include "manhat-lib/shared_cs_util.h"
#include "manhat-lib/shared_time.h"



void
read_parameters( char *key, char *count, int *is_admin)
{
    char tmp[12];

     cs_get_required_parameter("id", key, MAX_KEY);
     cs_get_required_parameter("count", count, MAX_PATH);

     cs_get_required_parameter("admin", tmp, 11);
     *is_admin = atoi(tmp)? 1: 0;

     cs_set_value("id", key);
     cs_set_value("count", count);
     cs_set_int_value("admin", *is_admin);

}



void
set_form_data(const char *username)
{
    time_t now;
    struct tm time_tm;

    now = time(NULL);
    time_tm = *localtime(&now);
    set_hour_minute_ampm(&time_tm, "current");   /* shared_time.h */
    cs_set_search_form("", "", username);   /* shared_course_search.c */

}




int
main()
{
   int is_admin;
   char count[MAX_PATH+1];
   char url[MAX_PATH+1];
   char key[MAX_KEY +1];
   SESSION user;

   cs_cgi_init();
   read_parameters( key, count, &is_admin); 
   verify_key_path(&user, key, is_admin);
   set_form_data(user.username);
   snprintf(url, MAX_PATH +1, "%s?admin=%d&amp;id=%s", "survey_read_info", is_admin, key);
   cs_set_value("back_url", url);
   cs_cgi_display("survey_deliver_form", 1);
   cs_cgi_destroy();
   return 0;
}

