#include #include /* for rand() */ #include #include /* Directory information. */ #include #include #include #include "global.h" #include "custom.h" /* for date FORMAT strings */ #include "ClearSilver.h" #include "grade.h" #include "manhat-lib/shared_util.h" #include "manhat-lib/shared_strtrm.h" #include "manhat-lib/shared_news_util.h" #include "manhat-lib/shared_cs_util.h" #include "manhat-lib/shared_lock.h" #include "manhat-lib/shared_file_util.h" #include "manhat-lib/shared_person_list.h" #include "manhat-lib/shared_grade_book_release.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 find_html_file(const char *path, char *filename) { DIR *dir_p; struct dirent *dir_entry_p; int found =0; dir_p = opendir(path); if(!dir_p) cs_critical_error(ERR_OPENDIR_FAILED, "find html file"); while (NULL != (dir_entry_p = readdir(dir_p))) { if(strstr(dir_entry_p->d_name, ".html")) { strncpy(filename, dir_entry_p->d_name, MAX_PATH +1); found = 1; break; } } if(!found) cs_critical_error(ERR_GENERAL_ERROR, "no html file was found"); } char *add_send_file(char *msg, const char *course) { int len; char search_str[] = "src="; char add_str[MAX_PATH + 1]; char *new_str; char *ptr, *ptr2; len = strlen(msg) * 4; ptr2 = msg; snprintf(add_str, MAX_PATH +1, "send_img?crs=%s&file=", course); new_str = (char *) malloc (sizeof(char) * len +1); if(!new_str) cs_critical_error(ERR_MALLOC_FAILED, "add send file"); *new_str = '\0'; do { ptr = strstr(ptr2, search_str); if(ptr) { ptr = ptr + strlen(search_str) + 1; strncat(new_str, ptr2, ptr-ptr2); strncat(new_str, add_str, strlen(add_str)); ptr2 = strchr(ptr, '\"'); strncat(new_str, ptr, ptr2 - ptr +1); ptr2++; } else break; }while(ptr2); if(ptr2) strncat(new_str, ptr2, strlen(ptr2)); return new_str; } /*** When the GradeQuick file is printed to a PDF file on a MACintosh, the **** ID number winds up in a different place, on the line above the line **** that contains the "ID:" string. This function is called when the usual **** routine can't find the ID number. returns 1 if successful, else 0 ***/ static void extract_mac_id(char *end, char *start, char *id) { char *ptr; char *id_start; int eol_count; *id = '\0'; for(ptr=end, eol_count = 0; (ptr > start) && eol_count != 2; ptr--) if(*ptr == '\n') eol_count++; if(eol_count == 2) { ptr = strstr(ptr, ""); if(ptr && (ptr < end)) { for(id_start = ptr - 1; (*id_start != '>') && (id_start > start); id_start--); if(*id_start == '>') { id_start++; *ptr = '\0'; strncpy(id, id_start, MAX_NAME); *ptr = '<'; strtrm(id); } } } if(!strlen(id)) cs_critical_error(ERR_GENERAL_ERROR, "Cannot extract Student ID. Did you enable the Student ID option for the GradeQuick report?"); } char *add_id_tags(char *send_buffer) { #define START_PAGE_COMMENT "\n" #define MARKER_STRING ">ID:" #define ID_START "ID:" #define ID_END "" char *new_str; char pre_name[MAX_NAME +1]; char new_name[MAX_NAME +1]; char *ptr, *unprocessed_ptr, *ptr3, *ptr4, *pre_ptr =0; unprocessed_ptr = send_buffer; memset(pre_name, 0, MAX_NAME + 1); memset(new_name, 0, MAX_NAME + 1); new_str = (char *)malloc(sizeof(char) * ( (2 * strlen(send_buffer)) + 1)); /* allocate plenty of extra space */ if(!new_str) cs_critical_error(ERR_MALLOC_FAILED, "add_id_tags()"); *new_str = '\0'; do { ptr = strstr(unprocessed_ptr, START_PAGE_COMMENT); /* find the start of a page eg. comment */ unprocessed_ptr = ptr; do { ptr3 = strstr(ptr,MARKER_STRING); if(ptr3) { ptr4 = strstr(ptr3, ID_START); // if(ptr4... ) why no test to see if last was successful? */ ptr4 = ptr4 + strlen(ID_START); ptr = strstr(ptr4, ID_END); if(!ptr) cs_critical_error(ERR_GENERAL_ERROR, "Cannot extract Student ID. Did you enable the Student ID option for the GradeQuick report?"); strncpy(new_name, ptr4, ptr - ptr4); strtrm(new_name); if(!strlen(new_name)) extract_mac_id(ptr4, unprocessed_ptr, new_name); if(!strlen(pre_name)) { strncpy(pre_name, new_name, MAX_NAME + 1); pre_ptr = ptr4; } if(!strcmp(new_name, pre_name)) pre_ptr = ptr4; } }while(ptr3 && !strcmp(pre_name, new_name)); if(strlen(pre_name)) { strcat(new_str, "<"); strcat(new_str, pre_name); strcat(new_str, ">\n"); ptr4 = strstr(pre_ptr, START_PAGE_COMMENT); if(ptr4) { strncat(new_str, unprocessed_ptr, ptr4-unprocessed_ptr); unprocessed_ptr = ptr4 -1; strcat(new_str, "\n"); } else { ptr4 = strstr(pre_ptr, CLOSE_BODY_TAG); strncat(new_str, unprocessed_ptr, ptr4-unprocessed_ptr); strcat(new_str, "\n"); unprocessed_ptr = ptr4; break; } memset(pre_name, 0, MAX_NAME +1); memset(new_name, 0, MAX_NAME +1); } } } else /* if