#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "global.h"
#include "survey.h"

#include "manhat-lib/shared_survey_xml_parser.h"
#include "manhat-lib/shared_file_util.h"
#include "manhat-lib/shared_survey_page.h"
#include "manhat-lib/shared_util.h"
#include "manhat-lib/shared_cs_util.h"


void
read_parameters( char *count, char *key)
{
    cs_get_required_parameter ("id", count, MAX_PATH);
    cs_get_optional_parameter ("key", key, MAX_KEY);
}

void
do_action(const char *count, const char *key)
{
    SURVEY_LIST  *list;
    char fname[MAX_PATH +1];

    snprintf(fname, MAX_PATH +1, "../%s/%s/%s/%s", 
		    SURVEY_DIR, SURVEY_WWW_DIR, count, SURVEY_XML_FNAME); 
    if(!file_exists (fname))
         cs_critical_error(ERR_NO_SURVEYS, "");
    list = survey_data_parser(fname);
    set_survey_content(list); /* shared_survey_page.c */
    free_survey_data_list(list);
    if(strlen(key))
      cs_set_int_value("Query.mode", MODE_PREVIEW_PUBLIC);    /** see survey.h */
    else
      cs_set_int_value("Query.mode", MODE_TAKE_WEB_DELIVERED);

}


int
main()
{
    char count[MAX_PATH +1];
    char key[MAX_KEY +1];
    
    cs_cgi_init();
    read_parameters(count, key);
    do_action(count, key);
    cs_cgi_display("survey_page", 1);
    cs_cgi_destroy();

    return 0;
}

       
    
	
