#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <time.h>

#include "ClearSilver.h"
#include "sqlite3.h"
#include "global.h"
#include "custom.h"		/* for date FORMAT strings */
#include "grade.h"		/* for date FORMAT strings */
#include "manhat-lib/shared_util.h"
#include "manhat-lib/shared_grade_book_menu.h"
#include "manhat-lib/shared_grade_book_util.h"
#include "manhat-lib/shared_grade_book_db.h"


void
read_parameters ( char *course, char *key)
{
     cs_get_required_parameter("crs", course, MAX_PATH);
     cs_get_required_parameter("id", key, MAX_KEY);

}

void
set_basic_values()
{
   cs_set_int_value("cat_name_len",MAX_CAT_LEN);
   cs_set_int_value("number_categories", 10);
   cs_set_int_value("no_category", 1);
      
}



void
do_action(CONFIG_STRUCT *conf)
{
   
    get_categories(conf, GRADE_BOOK_DB);   /* shared_grade_book_db.h */
    
    if(global_cat_list && global_cat_list->head)
    {
	set_cat_list_values();   /* shared_grade_book_util.h */
	free_category_list(global_cat_list);  /* shared_grade_book_util.h */
    }
    else
       set_basic_values();
	 
}

int
main ()
{
  char course[MAX_PATH +1];
  char key[MAX_KEY +1];

  SESSION user;
  CONFIG_STRUCT conf;
  
  cs_cgi_init();   /* shared_cs_util.h */
  read_parameters ( course, key);
  read_configuration_file (course, &conf);	
  validate_key (key, &user, &conf);	
  
  if(user.group != FACULTY)
     cs_critical_error(ERR_REQUEST_DENIED, "");

  cs_set_course_info(&conf);  
  set_grade_book_menu("grade_book_categories", key, course); /* shared_grade_book_menu.h */
  cs_load_lang("grade_book_menu_util");
  do_action(&conf);
  cs_cgi_display ("grade_book_categories", 1);
  cs_cgi_destroy();      

  return 0;			

}




