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

#include <string.h>

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

#include "manhat-lib/shared_super_key.h"
#include "manhat-lib/shared_survey_util.h"
#include "manhat-lib/shared_cs_util.h"

void
read_parameters(int *is_admin, char *key, char *crs)
{
     char tmp[10];

     cs_get_required_parameter("id", key, MAX_KEY);
     cs_get_optional_parameter("crs", crs, MAX_PATH);

     cs_get_optional_parameter("admin", tmp, 9);
     *is_admin = !(*tmp)? 0: atoi(tmp);
}



int
main()
{
   int  is_admin;
   char key[MAX_KEY +1];
   char course[MAX_PATH +1];
   SESSION user;
   CONFIG_STRUCT conf;

   cs_cgi_init();   /* shared_cs_util.c */
   read_parameters(&is_admin, key, course); 

   if(is_admin)  
      validate_super_key(key, &user);
   else
      {
       read_configuration_file(course, &conf);
       validate_key(key, &user, &conf);
      }
    
   if( (user.group != ADMIN) && (user.group != FACULTY) )
         cs_critical_error(ERR_REQUEST_DENIED, "");


   insert_survey_spell_check_button();      /* shared_survey_util.c */

   cs_set_int_value("max_link_title", MAX_SURVEY_TITLE);
   cs_cgi_display("survey_new_form", 1);    /* shared_cs_util.c */
   cs_cgi_destroy();                        /* shared_cs_util.c */
   return 0;
}

