#include #include #include #include "manhat-lib/shared_util.h" //#include "manhat-lib/shared_cgi_util.h" #include "manhat-lib/shared_cs_util.h" #define MAX_ACCOUNT_TYPE 15 #define MAX_NUM_PARAM_ID 3 void read_parameters(int *count, char* id[MAX_NUM_PARAM_ID], char *type[MAX_NUM_PARAM_ID], char *expire) { char temp[MAX_ACCOUNT_TYPE +1]; int i; char name[20]; cs_get_required_parameter("count", temp, MAX_ACCOUNT_TYPE); *count = atoi(temp); if(*count >0 && *count <= 3) { for(i =0; i<*count; i++) { snprintf(name, 20, "id%d", i+1); cs_get_required_parameter(name, id[i], MAX_KEY); snprintf(name, 20, "acc_type%d", i+1); cs_get_required_parameter(name, type[i], MAX_ACCOUNT_TYPE); } } cs_get_optional_parameter("expire", expire, MAX_PATH); } void init(char *data[MAX_NUM_PARAM_ID], int len, int max) { int i; for(i =0;iManhattan select page\n"); puts("


"); for(i =0; i", "mymanhattan", id[i], expire); printf("

Enter your teacher account

"); } else if(!strcmp(type[i], "student")) { printf("", "mymanhattan", id[i], expire); printf("

Enter your student account

"); } else { printf("", "mymanhattan", id[i], expire); printf("

Enter your staff account

"); } } puts(""); } int main() { char *id[MAX_NUM_PARAM_ID]; char *type[MAX_NUM_PARAM_ID]; int count; char expire[MAX_PATH +1]; cs_cgi_init(); init(id, MAX_NUM_PARAM_ID, MAX_KEY +1); init(type, MAX_NUM_PARAM_ID, MAX_ACCOUNT_TYPE +1); read_parameters(&count, id, type, expire); if(count ==0) { cs_critical_error(ERR_NO_COURSE_ON_MANHATTAN, ""); free_char(id); free_char(type); } else if(count == -1) { cs_critical_error(ERR_SERVER_LOCK_MESSAGE, ""); free_char(id); free_char(type); } else if(count==1) { printf("Location: %s?id=%s&log=1&expire=%s\n\n", "mymanhattan", id[0], expire); free_char(id); free_char(type); } else if(count >=2 && count <= 3) { print_select_page(id, type, count, expire); free_char(id); free_char(type); } else { cs_critical_error(ERR_REQUEST_DENIED, "The page can not be displayed"); free_char(id); free_char(type); } cs_cgi_destroy(); return 0; }