Annotation of capa/capa51/pProj/capaCgiUtils.c, revision 1.8

1.1       albertel    1: /* ===================================================================== */
                      2: /*   copyrighted by Isaac Tsai, 1998, 1999, 2000    */
                      3: /* ===================================================================== */
                      4: #include <stdio.h>
                      5: #include <ctype.h>
                      6: #ifndef NO_STDLIB_H
                      7: #include <stdlib.h>
                      8: #else
                      9: char *getenv();
                     10: #endif
                     11: #include <stdio.h>
                     12: 
                     13: #include "capaToken.h"
                     14: #include "capaParser.h"
                     15: #include "capaCommon.h"
                     16: #include "ranlib.h"
                     17: 
                     18: #ifdef _MAIN_PROGRAM_
                     19: #undef _MAIN_PROGRAM_
                     20: #endif
                     21: 
                     22: #include "capaCGI.h"
                     23: 
                     24: void getword
                     25: CAPA_ARG((char *word, char *line, char stop))
                     26: {
                     27:     int x = 0,y;
                     28: 
                     29:     for(x=0;((line[x]) && (line[x] != stop));x++)
                     30:         word[x] = line[x];
                     31: 
                     32:     word[x] = '\0';
                     33:     if(line[x]) ++x;
                     34:     y=0;
                     35: 
                     36:     while((line[y++] = line[x++]));
                     37: }
                     38: 
                     39: char *makeword
                     40: CAPA_ARG((char *line, char stop))
                     41: {
                     42:     int x = 0,y;
                     43:     char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1));
                     44: 
                     45:     for(x=0;((line[x]) && (line[x] != stop));x++)
                     46:         word[x] = line[x];
                     47: 
                     48:     word[x] = '\0';
                     49:     if(line[x]) ++x;
                     50:     y=0;
                     51: 
                     52:     while((line[y++] = line[x++]));
                     53:     return word;
                     54: }
                     55: 
                     56: char *fmakeword
                     57: CAPA_ARG((FILE *f,char  stop,int * cl))
                     58: {
                     59:     int wsize;
                     60:     char *word;
                     61:     int ll;
                     62: 
                     63:     wsize = 102400;
                     64:     ll=0;
                     65:     word = (char *) malloc(sizeof(char) * (wsize + 1));
                     66: 
                     67:     while(1) {
                     68:         word[ll] = (char)fgetc(f);
                     69:         if(ll==wsize) {
                     70:             word[ll+1] = '\0';
                     71:             wsize+=102400;
                     72:             word = (char *)realloc(word,sizeof(char)*(wsize+1));
                     73:         }
                     74:         --(*cl);
                     75:         if((word[ll] == stop) || (feof(f)) || (!(*cl))) {
                     76:             if(word[ll] != stop) ll++;
                     77:             word[ll] = '\0';
                     78:             return word;
                     79:         }
                     80:         ++ll;
                     81:     }
                     82: }
                     83: 
                     84: char x2c
                     85: CAPA_ARG((char *what))
                     86: {
                     87:     register char digit;
                     88: 
                     89:     digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
                     90:     digit *= 16;
                     91:     digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
                     92:     return(digit);
                     93: }
                     94: 
                     95: void unescape_url
                     96: CAPA_ARG((char *url))
                     97: {
                     98:     register int x,y;
                     99: 
                    100:     for(x=0,y=0;url[y];++x,++y) {
                    101:         if((url[x] = url[y]) == '%') {
                    102:             url[x] = x2c(&url[y+1]);
                    103:             y+=2;
                    104:         }
                    105:     }
                    106:     url[x] = '\0';
                    107: }
                    108: 
                    109: void plustospace
                    110: CAPA_ARG((char *str))
                    111: {
                    112:     register int x;
                    113: 
                    114:     for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' ';
                    115: }
                    116: 
                    117: int rind
                    118: CAPA_ARG((char *s,char c))
                    119: {
                    120:     register int x;
                    121:     for(x=strlen(s) - 1;x != -1; x--)
                    122:         if(s[x] == c) return x;
                    123:     return -1;
                    124: }
                    125: 
                    126: int getline
                    127: CAPA_ARG((char *s,int n,FILE *f)) 
                    128: {
                    129:     register int i=0;
                    130: 
                    131:     while(1) {
                    132:         s[i] = (char)fgetc(f);
                    133: 
                    134:         if(s[i] == CR)
                    135:             s[i] = fgetc(f);
                    136: 
                    137:         if((s[i] == 0x4) || (s[i] == LF) || (i == (n-1))) {
                    138:             s[i] = '\0';
                    139:             return (feof(f) ? 1 : 0);
                    140:         }
                    141:         ++i;
                    142:     }
                    143: }
                    144: 
                    145: void send_fd
                    146: CAPA_ARG((FILE *f, FILE *fd))
                    147: {
                    148:     char c;
                    149: 
                    150:     while (1) {
                    151:         c = fgetc(f);
                    152:         if(feof(f)) return;
                    153:         fputc(c,fd);
                    154:     }
                    155: }
                    156: 
                    157: int ind
                    158: CAPA_ARG((char *s,char c))
                    159: {
                    160:     register int x;
                    161: 
                    162:     for(x=0;s[x];x++)
                    163:         if(s[x] == c) return x;
                    164: 
                    165:     return -1;
                    166: }
                    167: 
                    168: void escape_shell_cmd
                    169: CAPA_ARG((char *cmd))
                    170: {
                    171:     register int x,y,l;
                    172: 
                    173:     l=strlen(cmd);
                    174:     for(x=0;cmd[x];x++) {
                    175:         if(ind("&;`'\"|*?~<>^()[]{}$\\",cmd[x]) != -1){
                    176:             for(y=l+1;y>x;y--)
                    177:                 cmd[y] = cmd[y-1];
                    178:             l++; /* length has been increased */
                    179:             cmd[x] = '\\';
                    180:             x++; /* skip the character */
                    181:         }
                    182:     }
                    183: }
                    184: 
                    185: /* ==========================================  Updated according to Frank Wolfs 
                    186:    description on July 7 1997 */
                    187: char *c_getpath
                    188: CAPA_ARG((FILE *f)) 
                    189: {
                    190:   register int c;
                    191:   register int idx;
                    192:   char     tmp_string[MAX_BUFFER_SIZE];
                    193:   char     *new_string;
                    194: 
                    195:   idx = 0;
                    196:   tmp_string[0]='\0';
                    197:   c_ignorewhite(f);
                    198:   do {  
                    199:     c = getc(f);
                    200:     tmp_string[idx] = c;
                    201:     idx++;
                    202:   } while (isalnum(c) || c == '{' || c == '}' || c == '-' || c == '\\' ||
                    203: 	   c == '^'   || c == '_' || c == '/' || c == '.' || c == ':' ||
                    204: 	   c == '+'   || c == '*' || c == '#' || c == '!' || c == '=' || 
                    205: 	   c == ';'   || c == '$' || c == '(' || c == ')' || c == '[' ||
                    206: 	   c == ']'   || c == '?' || c == '>' || c == '<' || c == ',');
                    207:   ungetc(c,f); idx--;
                    208:   tmp_string[idx] = 0;
                    209:   new_string = (char *)malloc( (idx+1)*sizeof(char) );
                    210:   strncpy(new_string,tmp_string, (idx+1) );
                    211:   return (new_string);
                    212: }
                    213: 
                    214: /* ------------------------------------------------------------------------- */
                    215: 
                    216: void web_printheader(FILE *out)
                    217: {
                    218:   FILE *header;
                    219:   char *buf[MAX_BUFFER_SIZE];
                    220:   int amt=0;
                    221: 
                    222:   if ((capa_access("HTMLheader",F_OK|R_OK)!=-1) &&
                    223:       (NULL!=(header=fopen("HTMLheader","r")))) {
                    224:     while(0 < (amt=fread(buf,1,MAX_BUFFER_SIZE,header))) {
                    225:       fwrite(buf,1,amt,out);
                    226:     }
                    227:     fclose(header);
                    228:   } else {
                    229:     fprintf(out,"<HTML><HEAD>\n");
                    230:     fprintf(out,"<BODY BGCOLOR=\"#FFFFFF\" LINK=\"#0000EE\" VLINK=\"#EE1100\">\n");
                    231:   }
                    232: 
                    233: #ifdef  CAPA_WEB
                    234:   fprintf(out,"<!-- capasbin, CAPA Version %s, %s -->\n",
                    235: 	  CAPA_VER,COMPILE_DATE);
                    236: #else
                    237:   fprintf(out,"<!-- capahtml, CAPA Version %s, %s -->\n",
                    238: 	  CAPA_VER,COMPILE_DATE);
                    239: #endif
                    240: }
                    241: 
                    242: void web_printfooter(FILE *out)
                    243: {
                    244:   FILE *footer;
                    245:   char *buf[MAX_BUFFER_SIZE];
                    246:   int amt=0;
                    247: 
                    248:   if ((capa_access("HTMLfooter",F_OK|R_OK)!=-1) &&
                    249:       (NULL!=(footer=fopen("HTMLfooter","r")))) {
                    250:     while(0 < (amt=fread(buf,1,MAX_BUFFER_SIZE,footer))) {
                    251:       fwrite(buf,1,amt,out);
                    252:     }
                    253:     fclose(footer);
                    254:   } else {
                    255:     fprintf(out,"</BODY></HTML>\n");
                    256:   }
                    257: }
                    258: 
                    259: int  web_getclassdir
                    260: CAPA_ARG((char **cpath_p, char **cown_p, char *class))
                    261: {
                    262:     FILE     *fp;
                    263:     char      filename[FILE_NAME_LENGTH];
                    264:     char     *cname_p;
                    265:     int       done;
                    266:     char      c;
                    267:     
                    268:     sprintf(filename,"class.conf");
                    269:     if ((fp=fopen(filename,"r"))==NULL) {
                    270:       sprintf(filename,"../class.conf");
                    271:       if ((fp=fopen(filename,"r"))==NULL) {
                    272:         fprintf(stdout,"<!-- Error: can't open %s --> \n",filename); fflush(stdout);
                    273:         return (2);
                    274:       }
                    275:     }
                    276:     do {
                    277:       c_ignorewhite(fp);
                    278:       c = getc(fp); ungetc(c,fp);
                    279:       if( c != EOF ) {
                    280:         cname_p = c_getword(fp);
                    281:        *cpath_p = c_getpath(fp);
                    282:        *cown_p  = c_getword(fp);
                    283:         throwaway_line(fp);
                    284:         if( ! strcasecmp(cname_p, class) ) {
                    285:           done = 1;
                    286:         } else {
                    287:           free(cname_p); free(*cpath_p); free(*cown_p);
                    288:           done = 0;
                    289:         }
                    290:       } else {
                    291:         done = 1;
                    292:       }
                    293:     } while ( ! done );
                    294:     fclose(fp);
                    295:     free(cname_p);
                    296:     return (1);
                    297: }
                    298: 
                    299: int web_log(log_str)char *log_str;
                    300: {
                    301:    FILE  *fp;       
                    302:    char   filename[FILE_NAME_LENGTH];
                    303: 
                    304:    sprintf(filename,"web_access.log");
                    305:    if ((fp=fopen(filename,"a"))==NULL) {
                    306:      return -1; 
                    307:    }
                    308:    flockstream(fp);
                    309:    fprintf(fp,"%s",log_str);fflush(fp);
                    310:    funlockstream(fp);
                    311:    fclose(fp);
                    312:    return 0;
                    313: }
                    314: 
                    315: int  w_log_timing(student_number,set,section,log_string)
                    316: char  student_number[MAX_STUDENT_NUMBER+1];     
                    317: int   set;  
                    318: int   section;                                    
                    319: char *log_string;                                
                    320: {                                                  
                    321:    char   filename[FILE_NAME_LENGTH],            
                    322:          *ct;                                    
                    323:    FILE  *fp;                                     
                    324:    time_t t;                                 
                    325: 
                    326:    sprintf(filename,"records/webtiming%d.log",set);
                    327:    if ((fp=fopen(filename,"a"))==NULL) {
                    328:       return (-1);
                    329:    }
                    330:    /* CREATE LOG ENTRY */
                    331:    time(&t);
                    332:    ct=ctime(&t);
                    333:    ct[ strlen(ct)-1 ]=0; /* Trash newline */
                    334:    fprintf(fp,"%s %s %s\n",student_number,ct,log_string); fflush(fp);
                    335:    fclose(fp);
                    336:    return (0);
                    337: }
                    338: 
                    339: int  w_log_attempt(student_number,set,log_string)
                    340: char  student_number[MAX_STUDENT_NUMBER+1];     
                    341: int   set;  
                    342: char *log_string;                                
                    343: {                                                  
                    344:    char   filename[FILE_NAME_LENGTH],            
                    345:          *ct;                                    
                    346:    FILE  *fp;                                     
                    347:    time_t t;                                 
                    348: 
                    349:    sprintf(filename,"records/weblog%d.db",set);
                    350:    if ((fp=fopen(filename,"a"))==NULL) {
                    351:       return (-1);
                    352:    }
                    353: 
                    354:    /* CREATE LOG ENTRY */
                    355:    time(&t);
                    356:    ct=ctime(&t);
                    357:    ct[ strlen(ct)-1 ]=0; /* Trash newline */
                    358:    fprintf(fp,"%s %s %s\n",student_number,ct,log_string); fflush(fp);
                    359:    fclose(fp);
                    360:    return (0);
                    361: }
                    362: 
                    363: int  w_log_submissions(student_number,set,log_string)
                    364: char  student_number[MAX_STUDENT_NUMBER+1];     
                    365: int   set;  
                    366: char *log_string;                                
                    367: {                                                  
                    368:    char   filename[FILE_NAME_LENGTH],timeStr[FILE_NAME_LENGTH],buf2[MAX_BUFFER_SIZE];
                    369:    FILE  *fp;                                     
                    370:    time_t t;            
                    371:    struct tm     *tmtime;
                    372:    int do_log_submissions=1,result;
                    373:    char buf[MAX_BUFFER_SIZE];
                    374: 
                    375:    result=read_capa_config("do_log_submissions",buf);
                    376:    if (result != 0 && result != -1) 
                    377:      if (strcasecmp(buf2,"no")==0) 
                    378:        do_log_submissions=0;
                    379:    if (!do_log_submissions) return 0;
                    380: 
                    381:    sprintf(filename,"records/websubmissions%d.db",set);
                    382:    if ((fp=fopen(filename,"a"))==NULL) {
                    383:      return (-1);
                    384:    }
                    385: 
                    386:    /* CREATE LOG ENTRY */
                    387:    time(&t);
                    388:    tmtime=localtime(&t);
                    389:    strftime(timeStr,FILE_NAME_LENGTH,"%d/%m %X",tmtime);
                    390:    /*ct[ strlen(ct)-1 ]=0;*/ /* Trash newline */
                    391:    protect_log_string(log_string);
                    392:    fprintf(fp,"%s\t%s\t%s\n",student_number,timeStr,log_string); fflush(fp);
                    393:    fclose(fp);
                    394:    return (0);
                    395: }
                    396: 
                    397: 
                    398: void w_get_responses(int x,int q_idx,char* submissions_str)
                    399: {
                    400:   int leng, sub_idx;
                    401:   char buf[MAX_BUFFER_SIZE];
                    402:   if( !strncmp(g_entries[x].name,"INPUT",5) ) {
                    403:     if( index(g_entries[x].name, ',' ) == NULL ) {  /* only one answer */
                    404:       sscanf(g_entries[x].name,"INPUT%d",&q_idx);
                    405:       if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) {
                    406: 	if ( ! is_all_ws(g_entries[x].val) ) {
                    407: 	  g_stu_ans_pp[q_idx] = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1);
                    408: 	  (g_stu_ans_pp[q_idx])->a_idx  = 1;
                    409: 	  (g_stu_ans_pp[q_idx])->a_str  = strsave(g_entries[x].val);
                    410: 	  (g_stu_ans_pp[q_idx])->a_next = NULL;
                    411: 	  trim_response_ws((g_stu_ans_pp[q_idx])->a_str);
                    412: 	}
                    413: 	leng = strlen( g_entries[x].val );
                    414: 	if ( leng > 0 ) {
                    415: 	  sprintf(buf,"%d\t%s\t",q_idx,g_entries[x].val);
                    416: 	  strcat(submissions_str,buf);
                    417: 	}
                    418:       }
                    419:     } else { /* this answer belongs to /AND answers */
                    420:       sscanf(g_entries[x].name,"INPUT%d,%d",&q_idx,&sub_idx);
                    421:       if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) {
                    422: 	if ( ! is_all_ws(g_entries[x].val) ) { 
                    423: 	  StudentAnswer_t *sa_p;
                    424: 	  sa_p = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1);
                    425: 	  sa_p->a_idx  = sub_idx;
                    426: 	  sa_p->a_str  = strsave(g_entries[x].val);
                    427: 	  sa_p->a_next = NULL;
                    428: 	  if( g_stu_ans_pp[q_idx] == NULL ) {
                    429: 	    g_stu_ans_pp[q_idx] = sa_p;
                    430: 	  } else { 
                    431: 	    StudentAnswer_t *sb_p;
                    432: 	    for(sb_p=g_stu_ans_pp[q_idx]; sb_p->a_next; sb_p=sb_p->a_next);
                    433: 	    sb_p->a_next = sa_p;
                    434: 	  }
                    435: 	}
                    436: 	leng = strlen( g_entries[x].val );
                    437: 	if ( leng > 0 ) {
                    438: 	  sprintf(buf,"%d\t%s\t",q_idx,g_entries[x].val);
                    439: 	  strcat(submissions_str,buf);
                    440: 	}
                    441:       }
                    442:     }
                    443:   }
                    444:   if( !strncmp(g_entries[x].name,"LAST",4) ) {  
                    445:     StudentAnswer_t *sa_p;  
                    446:     if( index(g_entries[x].name, ',' ) == NULL ) {  /* only one answer */
                    447:       sscanf(g_entries[x].name,"LAST%d",&q_idx);
                    448:       if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) {
                    449: 	sa_p = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1);
                    450: 	sa_p->a_idx  = 1;
                    451: 	sa_p->a_str  = strsave(g_entries[x].val);
                    452: 	sa_p->a_next = NULL;
                    453: 	g_last_ans_pp[q_idx] = sa_p;
                    454:       }
                    455:     } else {
                    456:       sscanf(g_entries[x].name,"LAST%d,%d",&q_idx,&sub_idx);
                    457:       if( q_idx > 0 && q_idx < MAX_PROBLEM_CNT ) {
                    458: 	sa_p = (StudentAnswer_t *)capa_malloc(sizeof(StudentAnswer_t),1);
                    459: 	sa_p->a_idx  = sub_idx;
                    460: 	sa_p->a_str  = strsave(g_entries[x].val);
                    461: 	sa_p->a_next = NULL;
                    462: 	if( g_last_ans_pp[q_idx] == NULL) {
                    463: 	  g_last_ans_pp[q_idx] = sa_p;
                    464: 	} else {
                    465: 	    StudentAnswer_t *sb_p;
                    466: 	    for(sb_p=g_last_ans_pp[q_idx]; sb_p->a_next; sb_p=sb_p->a_next);
                    467: 	    sb_p->a_next = sa_p;
                    468: 	}
                    469:       }
                    470:     }
                    471:   }
                    472: }
                    473: 
                    474: /* ========================================================================= */
                    475: /* Check in:      Class name     (CLASS)
                    476:                   Student Number (SNUM)
                    477:                   CAPA ID        (CAPAID)
                    478:                   M=1
                    479:    Try set:       Class name     (CLASS)
                    480:                   Student Number (SNUM)
                    481:                   CAPA ID        (CAPAID)
                    482: 		  First question to print (STARTNUM)
                    483:                   M=2
                    484:    View previous: Class name     (CLASS)
                    485:                   Student Number (SNUM)
                    486:                   CAPA ID        (CAPAID)
                    487: 		  First question to print (STARTNUM)
                    488:                   View set       (VSET)
                    489:                   M=3
                    490:    Set summary:   
                    491:                   
                    492:  --------------------------------------------------------------------------- */
                    493:              
                    494: int  w_get_input() 
                    495: {
                    496:   register  int   x,m=0;
                    497:   int             cl, q_idx, result = 1;
                    498:   T_header        header; 
                    499:   char            log_str[MAX_BUFFER_SIZE],buf[MAX_BUFFER_SIZE];
                    500:   char            submissions_str[MAX_BUFFER_SIZE];
                    501:   time_t          curtime;
                    502:   char           *time_str,*UNKNOWN="UNKNOWN";
                    503:   int             error=0;
                    504:   char           *envPtr=NULL,*envPtr2=NULL;
                    505: #ifdef CGI_DBUG
                    506:   fprintf(g_cgi,"Entered get_input()\n"); fflush(g_cgi);
                    507: #endif /* CGI_DBUG */
                    508: 
                    509:   envPtr=getenv("REQUEST_METHOD");
                    510:   if(!envPtr) { 
                    511:     fprintf(stdout,"Enviroment variable REQUEST_METHOD not set.\n");
                    512:     fprintf(stdout,"CAPA is improperly installed or run, please let your \
                    513: instructor know about this error.\n");
                    514:     fprintf(stdout,"No tries have been deducted for the last submission.\n");
                    515:     error |= 1;
                    516:     return error;
                    517:   }
                    518:   if(strcmp(envPtr,"POST")) {
                    519:         fprintf(stdout,"This script should be referenced with a METHOD of POST.\n");
                    520: 	fprintf(stdout,"CAPA is improperly installed or run, please let your \
                    521: instructor know about this error.\n");
                    522: 	fprintf(stdout,"No tries have been deducted for the last submission.\n");
                    523:         fflush(stdout);
                    524: #ifdef CGI_DBUG
                    525:   fprintf(g_cgi,"Request_method is not POST\n"); fflush(g_cgi);
                    526: #endif /* CGI_DBUG */        
                    527:         error |= 2; return (error);
                    528:   }
                    529:   
                    530:   envPtr=getenv("CONTENT_TYPE");
                    531:   if(!envPtr) { 
                    532:     fprintf(stdout,"Enviroment variable CONTENT_TYPE not set.\n");
                    533:     fprintf(stdout,"CAPA is improperly installed or run, please let your \
                    534: instructor know about this error.\n");
                    535:     fprintf(stdout,"No tries have been deducted for the last submission.\n");
                    536:     fflush(stdout);
                    537:     error |= 4;
                    538:     return error;
                    539:   }
                    540:   if(strncmp(envPtr,"application/x-www-form-urlencoded",33)) {
                    541:         fprintf(stdout,"This script can only be used to decode form results. \n");
                    542: 	fprintf(stdout,"CAPA is improperly installed or run, please let your \
                    543: instructor know about this error.\n");
                    544: 	fprintf(stdout,"No tries have been deducted for the last submission.\n");
                    545:         fflush(stdout);
                    546: #ifdef CGI_DBUG
                    547: 	fprintf(g_cgi,"CONTENT_TYPE is not application/x-www-form-urlencoded\n"); fflush(g_cgi);
                    548: #endif /* CGI_DBUG */              
                    549:         error |= 8; return (error);
                    550:   }
                    551: 
                    552:   envPtr=getenv("CONTENT_LENGTH");
                    553:   if(!envPtr) { 
                    554:     fprintf(stdout,"Enviroment variable CONTENT_LENGTH not set.\n");
                    555:     fprintf(stdout,"CAPA is improperly installed or run, please let your \
                    556: instructor know about this error.\n");
                    557:     fprintf(stdout,"No tries have been deducted for the last submission.\n");
                    558:     error |= 16;
                    559:     return error;
                    560:   }
                    561:   cl = atoi(envPtr);
                    562: #ifdef CGI_DBUG
                    563:   fprintf(g_cgi,"CONTENT_LENGTH is %d\n",cl); fflush(g_cgi);
                    564: #endif /* CGI_DBUG */
                    565:   for(x=0;cl && (!feof(stdin));x++) {
                    566:     m=x;
                    567:     g_entries[x].val = fmakeword(stdin,'&',&cl);
                    568:     plustospace(g_entries[x].val);
                    569:     unescape_url(g_entries[x].val);
                    570:     g_entries[x].name = makeword(g_entries[x].val,'=');
                    571:   }
                    572:   /* ---------------------------------------------------- */
                    573:   g_entered_pin = 0; g_run_mode =0;
                    574:   submissions_str[0]='\0';
                    575:   for(x=0; x <= m; x++) {
                    576:       if( !strcmp(g_entries[x].name,"CLASS") ) {
                    577:         strncpy(g_class_name,g_entries[x].val,MAX_CLASS_CHAR);
                    578:       }
                    579:       if( !strcmp(g_entries[x].name,"M") ) {  /* run mode */
                    580:         sscanf(g_entries[x].val,"%d",&g_run_mode);
                    581:       }
                    582:       if( !strcmp(g_entries[x].name,"STARTNUM")) {
                    583: 	sscanf(g_entries[x].val,"%d",&g_start_question);
                    584:       }
                    585:       if( !strcmp(g_entries[x].name,"SNUM") ) {
                    586:         strncpy(g_student_number,g_entries[x].val,MAX_STUDENT_NUMBER+4);
                    587:       }
                    588:       if( !strcmp(g_entries[x].name,"CAPAID") ) {
                    589:         sscanf(g_entries[x].val,"%d",&g_entered_pin);
                    590:       }
                    591:       if( !strcmp(g_entries[x].name,"SET") ) {
                    592:         sscanf(g_entries[x].val,"%d",&g_set);
                    593:       }
                    594:       if( !strcmp(g_entries[x].name,"VSET") ) {
                    595: 	if (g_entries[x].val[0] == '\0') {
                    596: 	  g_vset=0;
                    597: 	} else {
                    598: 	  sscanf(g_entries[x].val,"%d",&g_vset);
                    599: 	}
                    600:       }
                    601:       if( !strcmp(g_entries[x].name,"KND") ) {
                    602:         sscanf(g_entries[x].val,"%d",&g_skind);
                    603:       }
                    604:       w_get_responses(x,q_idx,submissions_str);
                    605:       free(g_entries[x].val);
                    606:       free(g_entries[x].name);
                    607:   }
                    608:   
                    609: #ifdef CGI_DBUG
                    610:   fprintf(g_cgi,"DONE: Parse input\n"); fflush(g_cgi);
                    611: #endif /* CGI_DBUG */
                    612:   /* --------------------------------------------------------- */
                    613:   /* if( strcasecmp(g_prog_name,"capacheckin") == 0 ) { */
                    614:   if( g_run_mode == M_CHECKIN ) { /* capa_checkin */
                    615:     time(&curtime); time_str = ctime(&curtime);
                    616:     time_str[ strlen(time_str)-1 ] = 0;
                    617:     envPtr=getenv("REMOTE_HOST");
                    618:     if(!envPtr) { 
                    619:       fprintf(stdout,"<!-- Enviroment variable REMOTE_HOST not set.-->\n");
                    620:       envPtr=getenv("REMOTE_ADDR");
                    621:       if(!envPtr) { 
                    622: 	fprintf(stdout,"<!-- Enviroment variable REMOTE_ADDR not set.-->\n");
                    623: 	envPtr=UNKNOWN;
                    624: 	error |= 32;
                    625:       }
                    626:     }
                    627: #ifdef CGI_DBUG
                    628:   fprintf(g_cgi,"DONE: REMOTE_HOST\n"); fflush(g_cgi);
                    629: #endif /* CGI_DBUG */
                    630: 
                    631:     envPtr2=getenv("HTTP_USER_AGENT");
                    632:     if(!envPtr2) { 
                    633:       fprintf(stdout,"<!-- Enviroment variable HTTP_USER_AGENT not set. -->\n");
                    634:       envPtr2=UNKNOWN;
                    635:       error |= 64;
                    636:     }
                    637:     sprintf(log_str,"%s\t%s\t%s\t%s\t%s\n",g_class_name,g_student_number,time_str,envPtr,envPtr2);
                    638:     if (web_log(log_str) == -1 ) {
                    639:       fprintf(stdout,"Unable to log access to the system. Please notify instructor\n.");
                    640:       fprintf(stdout,"No tries have been deducted for the last submission.\n");
                    641:       error |= 128;
                    642:       return error;
                    643:     }
                    644:     
                    645:   }
                    646: #if defined(NeXT) 
                    647:    getwd(g_cwd);
                    648: #else
                    649:    getcwd(g_cwd,255);
                    650: #endif
                    651:   web_getclassdir(&g_cpath, &g_cowner, g_class_name);
                    652:   sprintf(g_class_fullpath,"%s/%s",g_cpath,g_class_name);
                    653: #ifdef CGI_DBUG
                    654:   fprintf(g_cgi,"DONE: getclassdir() [%s]\n",g_class_fullpath); fflush(g_cgi);
                    655: #endif /* CGI_DBUG */
                    656:   if( !capa_access(g_class_fullpath, F_OK) == 0 ) {
                    657:     fprintf(stdout,"ACCESS: could not access the class directory [%s]!\n",g_class_fullpath);
                    658:     fprintf(stdout,"Please exit the web browser and try accessing the system again\n");
                    659:     fprintf(stdout,"No tries have been deducted for the last submission.\n");
                    660:     fflush(stdout);
                    661:     sprintf(log_str,"Failed to access class dir, g_class_fullpath: %s\tg_cpath: %s\tg_class_name: %s\tg_cowner: %s\tg_cwd: %s\t",
                    662: 	    g_class_fullpath,g_cpath,g_class_name,g_cowner,g_cwd);
                    663:     if (web_log(log_str) == -1 ) {
                    664:       fprintf(stdout,"Unable to log access to the system. Please notify instructor\n.");
                    665:       fflush(stdout);
                    666:       error |= 256;
                    667:       return error;
                    668:     } 
                    669: #ifdef CGI_DBUG
                    670:     fprintf(g_cgi,"NO ACCESS: cannot access() [%s]\n",g_class_fullpath); fflush(g_cgi);
                    671: #endif /* CGI_DBUG */      
                    672:     error |= 512;
                    673:     return (error);
                    674:   }
                    675:   /* ---------------------------------------------------- */
                    676:   /*      change working directory to the class           */
                    677:   /* ---------------------------------------------------- */
                    678:   chdir(g_class_fullpath); /* before performing any capa*() calls */
                    679: #ifdef CGI_DBUG
                    680:   fprintf(g_cgi,"DONE cd to [%s]\n",g_class_fullpath); fflush(g_cgi);
                    681: #endif /* CGI_DBUG */
                    682: 
                    683:   /* Now in proper directory, can log submissions */
                    684:   if ( g_run_mode == M_CHECKANS) {
                    685:     if (w_log_submissions(g_student_number,g_set,submissions_str) == -1 ) {
                    686:       fprintf(stdout,"Unable to log submissions. Please notify instructor\n.");
                    687:       fprintf(stdout,"No tries have been deducted for the last submission.\n");
                    688:       error |= 1024;
                    689:       return error; 
                    690:     }
                    691:   }
                    692: 
                    693:   result=read_capa_config("capaweb_cgibin_path",buf);
                    694:   if (result != 0 && result != -1) {
                    695:     g_cgibin_path=capa_malloc(strlen(buf)+1,1);
                    696:     strcpy(g_cgibin_path,buf);
                    697:   } else {
                    698:     g_cgibin_path=capa_malloc(strlen("capa-bin")+1,1);
                    699:     strcpy(g_cgibin_path,"capa-bin");
                    700:   }
                    701: 
                    702:   if( g_entered_pin != 0 ) {
                    703:       g_login_set = capa_PIN(g_student_number,999,g_entered_pin);
                    704: #ifdef CGI_DBUG
                    705:   fprintf(g_cgi,"Succeed in login to set %d with pin %d\n",g_login_set,g_entered_pin); fflush(g_cgi);
                    706: #endif /* CGI_DBUG */   
                    707:     /* ---------------------------------------------------- 
                    708:       printf("Your entered capa id %d, login to set %d\n", g_entered_pin, g_login_set);
                    709:       printf("The real capa id for %s is %d\n",g_student_number,capa_PIN(g_student_number,1,0));
                    710:     ---------------------------------------------------- */
                    711:     
                    712:   } else {
                    713:     fprintf(stdout,"CAPA ID entered was zero, this is not valid.\n");
                    714:     fprintf(stdout,"No tries have been deducted for the last submission.\n");
                    715:     fflush(stdout);
                    716:     error |= 2048; return (error);
                    717:   }
                    718: 
                    719:   if (!g_login_set) { 
                    720:         fprintf(stdout,"The student ID (%s) or CAPA ID (%d) that you entered \
                    721: is not listed for the class (%s) that you have selected. Please check that \
                    722: you have selected the correct class on the CAPA logon page and that the \
                    723: student ID and CAPA ID are correct.\n", 
                    724: 		g_student_number, g_entered_pin, g_class_name);
                    725:         fflush(stdout);
                    726: #ifdef CGI_DBUG
                    727: 	fprintf(g_cgi,"CAPA ID or student number is not valid.\n"); 
                    728: 	fflush(g_cgi);
                    729: #endif /* CGI_DBUG */   
                    730:         error |= 4096;  return (error);
                    731:   } else {
                    732:       if ( g_login_set > 99 )  { 
                    733:         fprintf(stdout,"The student ID (%s) or CAPA ID (%d) that you entered \
                    734: is not listed for the class (%s) that you have selected. Please check that \
                    735: you have selected the correct class on the CAPA logon page and that the \
                    736: student ID and CAPA ID are correct.\n", 
                    737: 		g_student_number, g_entered_pin, g_class_name);
                    738:            fflush(stdout);
                    739: #ifdef CGI_DBUG
                    740: 	   fprintf(g_cgi,"CAPA ID is not valid.\n"); fflush(g_cgi);
                    741: #endif /* CGI_DBUG */            
                    742:            error |= 8192; return (error);
                    743:       }
                    744:       if(g_login_set < g_vset ) {
                    745:            fprintf(stdout,"Your CAPA ID (for set %d) does not allow you to view set %d.\n",g_login_set, g_vset);
                    746:            fflush(stdout);
                    747: #ifdef CGI_DBUG
                    748: 	   fprintf(g_cgi,"Login set %d is less than view set %d.\n",g_login_set,g_vset); fflush(g_cgi);
                    749: #endif /* CGI_DBUG */ 
                    750:            error |= 16384; return (error);
                    751:       }
                    752:       chdir(g_class_fullpath);  /* again, to make sure */
                    753:       
                    754:       if ( capa_get_student(g_student_number,&g_student_data) == 0 ) {
                    755:            fprintf(stdout,"Entered student id is not in the class list.\n");
                    756: 	   fprintf(stdout,"Please check that have selected the correct class \
                    757: and have entered you student id correctly.\n");
                    758:            fflush(stdout);
                    759: #ifdef CGI_DBUG
                    760: 	   fprintf(g_cgi,"get_student(): Student id not in the classl file.\n"); fflush(g_cgi);
                    761: #endif /* CGI_DBUG */               
                    762:             error |= 32768; return (error);
                    763:       } else {
                    764: 	 time(&curtime);
                    765: 	 if (capa_get_header(&header, g_login_set))  {
                    766: 	   fprintf(stdout,"This problem set is not ready yet.\n"); 
                    767: 	   fflush(stdout);
                    768: 	  
                    769: #ifdef CGI_DBUG
                    770: 	   fprintf(g_cgi,"get_header(): Problem set not ready.\n"); fflush(g_cgi);
                    771: #endif /* CGI_DBUG */            
                    772: 	   error |= 65536; return (error);
                    773:  	 }
                    774: 	 capa_mfree(header.weight);
                    775: 	 capa_mfree(header.partial_credit);
                    776:          /* ===> if (compare_datetime(curtime,header.open_date) < 0 ) { */
                    777:          if( capa_check_date(CHECK_OPEN_DATE,g_student_number,
                    778: 			     g_student_data.s_sec,g_login_set) < 0 ) {
                    779:             fprintf(stdout,"This set(%d) is not yet open. Please try back later.\n",g_login_set); 
                    780: 	    fflush(stdout);
                    781: #ifdef CGI_DBUG
                    782: 	    fprintf(g_cgi,"check_date(): Problem set not open.\n"); 
                    783: 	    fflush(g_cgi);
                    784: #endif /* CGI_DBUG */    
                    785:             error |= 131072; return (error);
                    786:          }
                    787:       }
                    788:   }
                    789:   return (error);
                    790: }
                    791: 
                    792: /* ============================================================================= */
                    793: void        append_qtext(new_str) char *new_str;
                    794: {
                    795:   int ii,len;
                    796:   if (new_str==NULL) return;
                    797:   len=strlen(new_str);
                    798: #ifdef CGI_DBUG
                    799:   fprintf(g_cgi,"before: len %d; g_qchar_cnt %d; g_qsize %d\n",
                    800: 	  len,g_qchar_cnt,g_qsize);
                    801:   fflush(g_cgi);
                    802: #endif /* CGI_DBUG */    
                    803:   if (g_qchar_cnt+len>g_qsize-1) {
                    804:     char *temp_text;
                    805:     g_qsize=(g_qchar_cnt+len)*2;
                    806:     temp_text=capa_malloc(g_qsize,sizeof(char));
                    807:     strncpy(temp_text,g_question_txt,g_qchar_cnt);
                    808:     capa_mfree(g_question_txt);
                    809:     g_question_txt=temp_text;
                    810:   }
                    811:   for(ii=0;ii<len;ii++) {
                    812:     g_question_txt[g_qchar_cnt+ii]=new_str[ii];
                    813:   }
                    814:   g_qchar_cnt += len;
                    815:   g_question_txt[g_qchar_cnt+1]='\0';
                    816: #ifdef CGI_DBUG
                    817:   fprintf(g_cgi,"after: len %d; g_qchar_cnt %d; g_qsize %d\n",len,g_qchar_cnt,g_qsize);
                    818:   fflush(g_cgi);
                    819: #endif /* CGI_DBUG */    
                    820: }
                    821: void        append_stext(new_str) char *new_str;
                    822: {
                    823:   int ii,len;
                    824:   if (new_str==NULL) return;
                    825:   len=strlen(new_str);
                    826: #ifdef CGI_DBUG
                    827:   fprintf(g_cgi,"appending status{%s}\nlen %d; g_schar_cnt %d; g_ssize %d\n",
                    828: 	  new_str,len,g_schar_cnt,g_ssize);
                    829:   fflush(g_cgi);
                    830: #endif /* CGI_DBUG */    
                    831:   if (g_schar_cnt+len>g_ssize-1) {
                    832:     char *temp_text;
                    833:     g_ssize=(g_schar_cnt+len)*2;
                    834:     temp_text=capa_malloc(g_ssize,sizeof(char));
                    835:     strncpy(temp_text,g_status_txt,g_schar_cnt);
                    836:     capa_mfree(g_status_txt);
                    837:     g_status_txt=temp_text;
                    838:   }
                    839:   for(ii=0;ii<len;ii++) {
                    840:     g_status_txt[g_schar_cnt+ii]=new_str[ii];
                    841:   }
                    842:   g_schar_cnt += len;
                    843:   g_status_txt[g_schar_cnt+1]='\0';
                    844: #ifdef CGI_DBUG
                    845:   fprintf(g_cgi,"len %d; g_schar_cnt %d; g_ssize %d\n",len,g_schar_cnt,g_ssize);
                    846:   fflush(g_cgi);
                    847: #endif /* CGI_DBUG */    
                    848: }
                    849: /* ============================================================================= */
                    850: /* ------------------------------------------------------------
                    851:   printf("ENV<br>\n");
                    852:   printf("SERVER_PROTOCOL:%s<br>",getenv("SERVER_PROTOCOL"));
                    853:   printf("PATH_INFO:%s<br>",getenv("PATH_INFO"));
                    854:   printf("PATH_TRANSLATED:%s<br>\n",getenv("PATH_TRANSLATED"));
                    855:   printf("SCRIPT_NAME:%s<br>\n",getenv("SCRIPT_NAME"));
                    856:   printf("QUERY_STRING:%s<br>\n",getenv("QUERY_STRING"));
                    857:   printf("REMOTE_HOST:%s<br>\n",getenv("REMOTE_HOST"));
                    858:   printf("REMOTE_USER:%s<br>\n",getenv("REMOTE_USER"));
                    859:   printf("REMOTE_IDENT:%s<br>\n",getenv("REMOTE_IDENT"));
                    860:   printf("USER_AGENT:%s<br>\n",getenv("USER_AGENT"));
                    861:   printf("HTTP_USER_AGENT:%s<br>\n",getenv("HTTP_USER_AGENT"));
                    862:   ------------------------------------------------------------
                    863: */
                    864: 
                    865: /* ------------------------------------------------------ */
                    866: /*   A class directory must have   */
                    867: /*     records/                    */
                    868: /*                                 */
                    869: /*  returns: 0  structure is correct, but no set.db files */
                    870: /*          -1  structure is not correct                  */
                    871: /*          >=1 the last set.db                           */
                    872: 
                    873: int
                    874: check_class_get_maxset(dir_path) char  *dir_path;
                    875: {
                    876:   char   f_name[1024];
                    877:   int    set;
                    878:   
                    879:   if( capa_access(dir_path, F_OK) == 0 ) { /* class dir exists */
                    880:     sprintf(f_name,"%s/records",dir_path);
                    881:     if( capa_access(f_name, F_OK) == 0 ) { /* class/records dir exists */
                    882:       for(set = 1; ; set++ ) {
                    883:         sprintf(f_name,"%s/records/set%d.db",dir_path,set);
                    884:         if(capa_access(f_name, F_OK) == -1 )  break;
                    885:       }
                    886:       set--;
                    887:     } else {
                    888:       set = -1;
                    889:     }
                    890:   } else {
                    891:     set = -1;
                    892:   } 
                    893:   return (set);
                    894: }
                    895: 
                    896: /* ------------------------------------------------------------------------- */
                    897: /* Get Exam and Quiz Path                                                    */
                    898: /*   return  0, 1, 2, 3                                                      */
                    899: /* 0: Neither exist                                                          */
                    900: /* 1: Exam.path exists                                                       */
                    901: /* 2: Quiz.path exists                                                       */
                    902: /* 3: Both Exam.path and Quiz.path exists                                    */
                    903: /* ------------------------------------------------------------------------- */
                    904: int
                    905: check_exam_quiz_path()
                    906: {
                    907:   char  buf[MAX_BUFFER_SIZE];
                    908:   int   result = 0, configResult=0;
                    909:   
                    910:   configResult=read_capa_config("exam_path",buf);
                    911:   if (configResult != 0 && configResult != -1) {
                    912:     g_exam_set = check_class_get_maxset(buf);
                    913:     if(g_exam_set > 0 )  {
                    914:       result = 1;
                    915:       sprintf(g_exam_path,buf);
                    916:     }
                    917:   }
                    918:   configResult=read_capa_config("quiz_path",buf);
                    919:   if (configResult != 0 && configResult != -1) {
                    920:     g_quiz_set = check_class_get_maxset(buf);
                    921:     if(g_quiz_set > 0 )  {
                    922:       result = (result | 2);
                    923:       sprintf(g_quiz_path,buf);
                    924:     }
                    925:   }
                    926:   return (result);
                    927: }
                    928: 
                    929: 
                    930: int
                    931: check_termscore_option()
                    932: {
                    933:   char  buf[MAX_BUFFER_SIZE];
                    934:   int   result = 0, configResult=0;
                    935:   
                    936:   configResult=read_capa_config("term_score_applet",buf);
                    937:   if (configResult != 0 && configResult != -1) {
                    938:     fprintf(stdout,"<!-- term_score_applet is in capa.config file -->\n");
                    939:     if (strcasecmp(buf,"yes")==0) {
                    940:       fprintf(stdout,"<!-- term_score_applet is YES -->\n");
                    941:       result=1;
                    942:     }
                    943:   }
                    944:   return (result);
                    945: }
                    946: 
                    947: 
                    948: 
                    949: 
                    950: /* ============================================================================= */
                    951: void
                    952: print_mainmenu(class,sn,pin)char *class; char *sn;int pin;
                    953: {
                    954:   char  buf[MAX_BUFFER_SIZE];
                    955:   int   outcome,configResult,term_summary_button=1;
                    956:   char *serverName;
                    957: 
                    958:   serverName=getenv("SERVER_NAME");
                    959:   if (!serverName) {
                    960:     fprintf(stdout,"Enviroment variable SERVER_NAME not set.\n");
                    961:     fprintf(stdout,"Unable to complete actions.\n");
                    962:     return;
                    963:   }
                    964:   
                    965:   fprintf(stdout,"<TITLE>%s main menu</TITLE>\n",g_class_name);
                    966:   fprintf(stdout,"<h3>%s</h3><br>\n",g_student_name);
                    967:   fprintf(stdout,"<menu>\n");
                    968:   fprintf(stdout,"<li><form method=\"get\" action=\"http://%s/CAPA/help.html\">",serverName);
                    969:   fprintf(stdout,"<input type=\"submit\" value=\"Help\" ></form>\n");
                    970: 
                    971:   fprintf(stdout,"<li><form method=\"post\" ");
                    972:   /* fprintf(stdout," target=\"right_frame\" "); */
                    973:   sprintf(buf,"action=\"http://%s/%s/%s/capasbin\">",serverName,g_cgibin_path,g_cowner);
                    974:   fprintf(stdout,"%s\n", buf);
                    975:   fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",class);
                    976:   fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",sn);
                    977:   fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",pin);
                    978:   fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_TRYSET);
                    979:   fprintf(stdout,"<input type=\"hidden\" name=\"STARTNUM\" value=\"%d\">\n",1);
                    980:   fprintf(stdout,"<input type=\"submit\" value=\"Try current set\" ></form>\n");
                    981:   
                    982:   fprintf(stdout,"<li><form method=\"post\" ");
                    983:   /* fprintf(stdout," target=\"right_frame\" "); */
                    984:   sprintf(buf,"action=\"http://%s/%s/%s/capasbin\">",serverName,g_cgibin_path,g_cowner);
                    985:   fprintf(stdout,"%s\n", buf);
                    986:   fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",class);
                    987:   fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",sn);
                    988:   fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",pin);
                    989:   fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_VIEWPREV);
                    990:   fprintf(stdout,"<input type=\"hidden\" name=\"STARTNUM\" value=\"%d\">\n",1);
                    991:   fprintf(stdout,"<input type=\"submit\" value=\"View previous set:\" >");
                    992:   fprintf(stdout,"<b> set:</b><input name=\"VSET\" value=\"\" size=4></form>\n");
                    993:   
                    994:   /*Term Summary*/
                    995:   configResult=read_capa_config("term_summary_button",buf);
                    996:   if (configResult != 0 && configResult != -1 ) {
                    997:     if (strcasecmp(buf,"no")==0) {
                    998:       term_summary_button=0;
                    999:     }
                   1000:   }
                   1001:   if (term_summary_button) {
                   1002:     fprintf(stdout,"<li><form method=\"post\" ");
                   1003:     /* fprintf(stdout," target=\"right_frame\" "); */
                   1004:     sprintf(buf,"action=\"http://%s/%s/capahtml\">",serverName,g_cgibin_path);
                   1005:     fprintf(stdout,"%s\n", buf);
                   1006:     fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",class);
                   1007:     fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",sn);
                   1008:     fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",pin);
                   1009:     fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_VIEWSUMM);
                   1010:     fprintf(stdout,"<input type=\"submit\" value=\"Display term summary\" ></form>\n");
                   1011:   }
                   1012: 
                   1013:   outcome = check_exam_quiz_path();
                   1014:   if( outcome & 1 ) {  /* exam summary */
                   1015:     fprintf(stdout,"<li><form method=\"post\" ");
                   1016:     /* fprintf(stdout," target=\"right_frame\" "); */
                   1017:     sprintf(buf,"action=\"http://%s/%s/capahtml\">",serverName,g_cgibin_path);
                   1018:     fprintf(stdout,"%s\n", buf);
                   1019:     fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",class);
                   1020:     fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",sn);
                   1021:     fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",pin);
                   1022:     fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_EXAMSUMM);
                   1023:     fprintf(stdout,"<input type=\"submit\" value=\"Display Exam summary\" ></form>\n");
                   1024:   }
                   1025:   if( outcome & 2 ) { /* Quiz summary */
                   1026:     fprintf(stdout,"<li><form method=\"post\" ");
                   1027:     /* fprintf(stdout," target=\"right_frame\" "); */
                   1028:     sprintf(buf,"action=\"http://%s/%s/capahtml\">",serverName,g_cgibin_path);
                   1029:     fprintf(stdout,"%s\n", buf);
                   1030:     fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",class);
                   1031:     fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",sn);
                   1032:     fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",pin);
                   1033:     fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\" >\n",M_QUIZSUMM );
                   1034:     fprintf(stdout,"<input type=\"submit\" value=\"Display Quiz summary\" ></form>\n");
                   1035:   }
                   1036:   outcome = check_termscore_option();
1.6       albertel 1037:   fprintf(stdout,"<!-- Outcome of check_termscore_option()=%d -->\n",outcome);
1.1       albertel 1038:   /*Termscore Button*/
                   1039:   if( outcome ) {
                   1040:     fprintf(stdout,"<li><form method=\"post\" ");
1.7       albertel 1041:    sprintf(buf,"action=\"http://%s/%s/%s/capasbin\">",serverName,g_cgibin_path,g_cowner);
1.1       albertel 1042:     fprintf(stdout,"%s\n", buf);
                   1043:     fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",class);
                   1044:     fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",sn);
                   1045:     fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",pin);
                   1046:     fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\" >\n",M_TERMSCORE );
                   1047:     fprintf(stdout,"<input type=\"submit\" value=\"Extrapolate Term score\" ></form>\n");
                   1048:   }
                   1049:   /*Exit Button*/
                   1050:   fprintf(stdout,"<TD><form method=\"get\" action=\"http://%s/CAPA/class.html\">",serverName);
                   1051:   fprintf(stdout,"<input type=\"button\" value=\"Exit\" onclick=\"window.close()\"></form></TD>");
                   1052: 
                   1053:   fprintf(stdout,"</menu>\n"); fflush(stdout);
                   1054:   
                   1055: }
                   1056: 
                   1057: /* ====================================================================================== */
                   1058: void
                   1059: print_page_header(mode,num_quest) int mode;int num_quest;
                   1060: {
1.2       albertel 1061:   char   buf[MAX_BUFFER_SIZE], discussdir[MAX_BUFFER_SIZE];
1.1       albertel 1062:   char *serverName;
                   1063:   int    configResult,term_summary_button=1;
                   1064: 
                   1065:   serverName=getenv("SERVER_NAME");
                   1066:   if (!serverName) {
                   1067:     fprintf(stdout,"Enviroment variable SERVER_NAME not set.\n");
                   1068:     fprintf(stdout,"Unable to complete actions.\n");
                   1069:     return;
                   1070:   }
                   1071:   
                   1072:   /* now done in the .qz file
                   1073:   fprintf(stdout,"<TITLE>%s set%d</TITLE>",g_class_name,g_login_set);
                   1074:   if( mode == VIEW_PREVIOUS_MODE ) {
                   1075:     fprintf(stdout,"<H2>%s set%d</H2>\n",g_class_name,g_vset);
                   1076:   } else {
                   1077:     fprintf(stdout,"<H2>%s set%d</H2>\n",g_class_name,g_login_set);
                   1078:   }
                   1079:   fprintf(stdout,"<H3>%s</H3>\n",g_student_data.s_nm);
                   1080:   */
                   1081:   
                   1082:   fprintf(stdout,"<A NAME=\"TOP\"></A>");
                   1083:   fprintf(stdout,"<TABLE cellpadding=0 cellspacing=0 border=0>\n<TR><TD>");
                   1084: 
                   1085: 
                   1086:   /*Term summary button*/
                   1087:   configResult=read_capa_config("term_summary_button",buf);
                   1088:   if (configResult != 0 && configResult != -1 ) {
                   1089:     if (strcasecmp(buf,"no")==0) {
                   1090:       term_summary_button=0;
                   1091:     }
                   1092:   }
                   1093: #ifdef CGI_DBUG
                   1094:   fprintf(g_cgi,"buf: %s\ntermsum: %d\n",buf,term_summary_button); fflush(g_cgi);
                   1095: #endif /* CGI_DBUG */ 
                   1096: 
                   1097:   if (term_summary_button) {
                   1098:     fprintf(stdout,"<form method=\"post\" ");
                   1099:     sprintf(buf,"action=\"http://%s/%s/capahtml\">",serverName,g_cgibin_path);
                   1100:     fprintf(stdout,"%s\n", buf);
                   1101:     fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",g_class_name);
                   1102:     fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",g_student_number);
                   1103:     fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",g_entered_pin);
                   1104:     fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_VIEWSUMM);
                   1105:     fprintf(stdout,"<input type=\"submit\" value=\"Term summary\" ></form></TD>\n");
                   1106:   }
                   1107: 
                   1108:   /*Exit Button*/
                   1109:   fprintf(stdout,"<TD><form method=\"get\" action=\"http://%s/CAPA/class.html\">",serverName);
                   1110:   fprintf(stdout,"<input type=\"button\" value=\"Exit\" onclick=\"window.close()\"></form></TD>");
                   1111:   /*help button*/
                   1112:   if (mode != VIEW_PREVIOUS_MODE) {
                   1113:     fprintf(stdout,"<TD><form method=\"get\" action=\"http://%s/CAPA/help.html\">",serverName);
                   1114:     fprintf(stdout,"<input type=\"submit\" value=\"Help\"></form></TD>");
                   1115:   }
                   1116: 
                   1117:   /*Reload button*/
                   1118:   fprintf(stdout,"<TD><form method=\"post\" ");
                   1119:   sprintf(buf,"action=\"http://%s/%s/%s/capasbin\">",serverName,g_cgibin_path,g_cowner);
                   1120:   fprintf(stdout,"%s\n", buf);
                   1121:   fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",g_class_name);
                   1122:   fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",g_student_number);
                   1123:   fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",g_entered_pin);
                   1124:   fprintf(stdout,"<input type=\"hidden\" name=\"STARTNUM\" value=\"%d\">\n",g_start_question);
                   1125:   if (mode == VIEW_PREVIOUS_MODE ) {
                   1126:     fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_VIEWPREV);
                   1127:     fprintf(stdout,"<input type=\"hidden\" name=\"VSET\" value=\"%d\" size=4>\n",g_vset);
                   1128:   } else {
                   1129:     fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_TRYSET);
                   1130:   }
                   1131:   fprintf(stdout,"<input type=\"submit\" value=\"Reload\" >\n</form></TD>");
                   1132: #ifdef NOT_DEFINED
                   1133:   /* Next Button */
                   1134:   if ( (!(g_num_questions_per_page==ALL_QUESTIONS)) && 
                   1135:        ((g_num_questions_per_page+g_start_question)<num_quest)) {
                   1136:     fprintf(stdout,"<TD><form method=\"post\" ");
                   1137:     sprintf(buf,"action=\"http://%s/%s/%s/capasbin\">",serverName,g_cgibin_path,g_cowner);
                   1138:     fprintf(stdout,"%s\n", buf);
                   1139:     fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",g_class_name);
                   1140:     fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",g_student_number);
                   1141:     fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",g_entered_pin);
                   1142:     fprintf(stdout,"<input type=\"hidden\" name=\"STARTNUM\" value=\"%d\">\n",g_start_question+g_num_questions_per_page);
                   1143:     if (mode == VIEW_PREVIOUS_MODE ) {
                   1144:       fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_VIEWPREV);
                   1145:       fprintf(stdout,"<input type=\"hidden\" name=\"VSET\" value=\"%d\" size=4>\n",g_vset);
                   1146:     } else {
                   1147:       fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_TRYSET);
                   1148:     }
                   1149:     fprintf(stdout,"<input type=\"submit\" value=\"Next Page\" >\n</form></TD>");
                   1150:   }
                   1151: 
                   1152:   /* Previous Button */
                   1153:   if ( (!(g_num_questions_per_page==ALL_QUESTIONS)) && (g_start_question > 1)) {
                   1154:     fprintf(stdout,"<TD><form method=\"post\" ");
                   1155:     sprintf(buf,"action=\"http://%s/%s/%s/capasbin\">",serverName,g_cgibin_path,g_cowner);
                   1156:     fprintf(stdout,"%s\n", buf);
                   1157:     fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",g_class_name);
                   1158:     fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",g_student_number);
                   1159:     fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",g_entered_pin);
                   1160:     fprintf(stdout,"<input type=\"hidden\" name=\"STARTNUM\" value=\"%d\">\n",g_start_question-g_num_questions_per_page);
                   1161:     if (mode == VIEW_PREVIOUS_MODE ) {
                   1162:       fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_VIEWPREV);
                   1163:       fprintf(stdout,"<input type=\"hidden\" name=\"VSET\" value=\"%d\" size=4>\n",g_vset);
                   1164:     } else {
                   1165:       fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_TRYSET);
                   1166:     }
                   1167:     fprintf(stdout,"<input type=\"submit\" value=\"Previous Page\" >\n</form></TD>");
                   1168:   }
                   1169: #endif
                   1170:   /* Goto Button */
                   1171:   if (!(g_num_questions_per_page==ALL_QUESTIONS)) {
                   1172:     int idx,numquest;
                   1173:     T_header header;
                   1174:     fprintf(stdout,"<TD><form method=\"post\" ");
                   1175:     sprintf(buf,"action=\"http://%s/%s/%s/capasbin\">",serverName,g_cgibin_path,g_cowner);
                   1176:     fprintf(stdout,"%s\n", buf);
                   1177:     fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",g_class_name);
                   1178:     fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",g_student_number);
                   1179:     fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",g_entered_pin);
                   1180:     fprintf(stdout,"<input type=\"submit\" value=\"Goto\" >");
                   1181:     fprintf(stdout,"<b>Problem:</b><input name=\"STARTNUM\" value=\"\" size=4>\n");
                   1182:     if (mode == VIEW_PREVIOUS_MODE ) {
                   1183:       fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_VIEWPREV);
                   1184:       fprintf(stdout,"<input type=\"hidden\" name=\"VSET\" value=\"%d\" size=4>\n",g_vset);
                   1185:     } else {
                   1186:       fprintf(stdout,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_TRYSET);
                   1187:     }
                   1188: 
                   1189:     if (!capa_get_header(&header, g_login_set)) {
                   1190:       numquest=atoi(header.num_questions);
                   1191:       capa_mfree(header.weight);
                   1192:       capa_mfree(header.partial_credit);
                   1193:       for(idx=0;idx<numquest;idx++) {
                   1194: 	preserve_last_answer(idx,1);
                   1195:       }
                   1196:     }
                   1197:     fprintf(stdout,"</form></TD>");
1.2       albertel 1198:   }
                   1199: 
                   1200:   /*Discuss Button*/
                   1201: 
                   1202:   sprintf(discussdir,"%s/discussion/%d",g_class_fullpath,g_login_set);
                   1203:   if ( access(discussdir,F_OK) == 0 ) {
                   1204:     fprintf(stdout,"<TD><form method=\"post\" ");
                   1205:     sprintf(buf,"action=\"http://%s/%s/%s/capadiscuss\">",serverName,g_cgibin_path,g_cowner);
                   1206:     fprintf(stdout,"%s\n", buf);
                   1207:     fprintf(stdout,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",g_class_name);
                   1208:     fprintf(stdout,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",g_student_number);
                   1209:     fprintf(stdout,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",g_entered_pin);
                   1210:     fprintf(stdout,"<input type=\"hidden\" name=\"SETID\" value=\"%d\">\n",g_login_set);
                   1211:     fprintf(stdout,"<input type=\"submit\" value=\"Discuss\" >\n</form></TD>");
1.1       albertel 1212:   }
                   1213: 
                   1214:   fprintf(stdout,"\n</TR></TABLE>\n");
                   1215:   fflush(stdout);    
                   1216: }
                   1217: 
                   1218: void create_status_line(int mode,int question_cnt, T_entry* entry)
                   1219: {
                   1220:   char          buf[MAX_BUFFER_SIZE];
                   1221:   int           idx,configResult,status_line_length;
                   1222: 
                   1223:   configResult=read_capa_config("web_status_line_length",buf);
                   1224:   if (configResult != 0 && configResult != -1 ) {
                   1225:     if (sscanf(buf,"%d",&status_line_length)==0) {
                   1226:       status_line_length=question_cnt;
                   1227:     }
                   1228:   } else {
                   1229:     status_line_length=question_cnt;
                   1230:   }
                   1231: 
                   1232:   append_stext("<TABLE cellpadding=0 cellspacing=0 border=0><TR>");
                   1233:   append_stext("<TD><b><u>Go to problem</u>  </b></TD><TD></TD>");
                   1234:   for(idx=0; idx < status_line_length;idx++ ) {
                   1235:     sprintf(buf,"<TD ALIGN=center VALIGN=bottom>[%d]</TD>",idx+1);
                   1236:     append_stext(buf);
                   1237:   }
                   1238:   for(idx = 0; idx < question_cnt; idx++ ) {
                   1239:     if ( !(idx%status_line_length) ) {
                   1240:       sprintf(buf,"</TR><TR><TD ALIGN=left>%d-%d</TD><TD ALIGN=right>Status: </TD>",
                   1241: 		   idx+1,idx+status_line_length);
                   1242:       append_stext(buf);
                   1243:     }
                   1244:     if ((idx >= g_start_question-1) && 
                   1245: 	 (((g_num_questions_per_page == ALL_QUESTIONS)) || 
                   1246: 	   (idx < (g_start_question+g_num_questions_per_page-1)))) {
                   1247:       sprintf(buf,"<TD ALIGN=center VALIGN=bottom><A href=\"#P%d\">",idx+1);
                   1248:     } else {
                   1249:       sprintf(buf,"<TD ALIGN=center VALIGN=bottom>");
                   1250:     }
                   1251:     append_stext(buf);
                   1252:     if ( (mode == CHECK_ANSWER_MODE) && g_log_string[idx] == '-') {
                   1253:       if (g_inhibit_response && (entry->answers[idx]!='-')) {
                   1254: 	sprintf(buf,"A");
                   1255:       } else {
                   1256: 	sprintf(buf,"%c",entry->answers[idx]); 
                   1257:       }
                   1258:     } else {
                   1259:       if (g_inhibit_response && (entry->answers[idx]!='-')) {
                   1260: 	sprintf(buf,"<b>A</b>");
                   1261:       } else {
                   1262: 	if ( mode == CHECK_ANSWER_MODE ) {
                   1263: 	  sprintf(buf,"<b>%c</b>",g_log_string[idx]);
                   1264: 	} else {
                   1265: 	  sprintf(buf,"<b>%c</b>",entry->answers[idx]);
                   1266: 	}
                   1267:       }
                   1268:     }
                   1269:     append_stext(buf);
                   1270:     if ((idx >= g_start_question-1) && 
                   1271: 	 (((g_num_questions_per_page == ALL_QUESTIONS)) || 
                   1272: 	   (idx < (g_start_question+g_num_questions_per_page-1)))) {
                   1273:       sprintf(buf,"</A></TD>");
                   1274:     } else {
                   1275:       sprintf(buf,"</TD>");
                   1276:     }
                   1277:     append_stext(buf);
                   1278:   }
                   1279:   append_stext("</TR></TABLE>\n");
                   1280: }
                   1281: 
                   1282: /* -------------------------------- called by try set, view previous, check answer */
                   1283: void
                   1284: print_quizz(class_dir,c_owner,class,sn,pin,set,mode)
                   1285: char *class_dir; char *c_owner;char *class;char *sn;int pin;int set;int mode;
                   1286: {
                   1287:   extern int    Parsemode_f;
                   1288:   extern char  *StartText_p;
                   1289:   extern char  *EndText_p;
                   1290:   Problem_t    *first_prob, *prob_idx;
                   1291:   int           result, question_idx, question_cnt, idx, view_assignment_after_due=1;
                   1292:   int           q_leng, display_ans=1, configResult;
                   1293:   int           view_assignments_after_due=1;
                   1294:   char          buf[MAX_BUFFER_SIZE];
                   1295:   char          class_fullpath[FILE_NAME_LENGTH];
                   1296:   T_entry       entry;
                   1297:   T_header      header;
                   1298:   long          offset;
                   1299:   double        a;
                   1300:   char          cmp_ans[MAX_BUFFER_SIZE],date_str[DATE_BUFFER];
                   1301:   time_t        curtime;
                   1302:   char         *serverName;
                   1303: 
                   1304:   serverName=getenv("SERVER_NAME");
                   1305:   if (!serverName) {
                   1306:     fprintf(stdout,"Enviroment variable SERVER_NAME not set.\n");
                   1307:     fprintf(stdout,"Unable to complete actions.\n");
                   1308:     return;
                   1309:   }
                   1310: 
                   1311:   sprintf(class_fullpath,"%s/%s",class_dir,class);
                   1312:   
                   1313:   /*
                   1314:   chdir(class_fullpath);
                   1315:   */
                   1316: #ifdef CGI_DBUG
                   1317:   fprintf(g_cgi,"enter print_quizz() %s, mode:%d\n",class_fullpath,mode); fflush(g_cgi);
                   1318: #endif /* CGI_DBUG */ 
                   1319: 
                   1320:   /* get configuration options */
                   1321:   configResult=read_capa_config("num_questions_per_page",buf);
                   1322:   if (configResult != 0 && configResult != -1 ) {
                   1323:     if (sscanf(buf,"%d",&g_num_questions_per_page)==0) {
                   1324:       g_num_questions_per_page=ALL_QUESTIONS;
                   1325:     }
                   1326:   } else {
                   1327:     g_num_questions_per_page=ALL_QUESTIONS;
                   1328:   }
                   1329: 
                   1330:   view_assignments_after_due=capa_check_option(OPTION_VIEW_PROBLEMS_AFTER_DUE,
                   1331: 					       set,g_student_data.s_sec);
                   1332:   if (view_assignments_after_due < 0 ) view_assignments_after_due=1;
                   1333:   g_inhibit_response=capa_check_option(OPTION_INHIBIT_RESPONSE,set,g_student_data.s_sec);
                   1334:   if (g_inhibit_response < 0 ) g_inhibit_response=0;
                   1335: 
                   1336: #ifdef CGI_DBUG
                   1337:   fprintf(g_cgi,"Set %d, Section%d, ViewAssign? %d, Inhibit Resp? %d\n",set,
                   1338: 	  g_student_data.s_sec,view_assignments_after_due,
                   1339: 	  g_inhibit_response); 
                   1340:   fflush(g_cgi);
                   1341: #endif /* CGI_DBUG */ 
                   1342: 
                   1343:   time(&curtime);
                   1344:   offset=capa_get_entry(&entry,sn,set);          /* <-------- capa*() call  ---- */
                   1345:   if( mode == VIEW_PREVIOUS_MODE ) {
                   1346:     if( view_assignment_after_due ) {
                   1347:       if( capa_check_date(CHECK_OPEN_DATE,g_student_number,
                   1348: 			  g_student_data.s_sec,set) < 0 ) {
                   1349: 	append_qtext("This set is not yet open.\n");
                   1350: 	return ;
                   1351:       }
                   1352:     } else {
                   1353:       if( (capa_check_date(CHECK_ANS_DATE,g_student_number,
                   1354: 			   g_student_data.s_sec,set) < 0) &&
                   1355: 	  (capa_check_date(CHECK_DUE_DATE,g_student_number,
                   1356: 			   g_student_data.s_sec,set) > 0) ) {
                   1357: 	append_qtext("This set is not yet available to be viewed.\n");
                   1358: 	return ;
                   1359:       }
                   1360:     }
                   1361:     if( capa_check_date(CHECK_ANS_DATE,g_student_number,
                   1362: 			g_student_data.s_sec,set) < 0 ) {
                   1363:       display_ans = 0;
                   1364:     }
                   1365:   } 
                   1366:   g_passdue = 0;
                   1367:   if( mode == CHECK_ANSWER_MODE || 
                   1368:       ( (!view_assignment_after_due) && mode == TRY_SET_MODE)) {
                   1369:     if( capa_check_date(CHECK_DUE_DATE,g_student_number,
                   1370: 			g_student_data.s_sec,set) > 0 ) {
                   1371:        capa_get_date(CHECK_DUE_DATE,g_student_number,
                   1372: 		     g_student_data.s_sec,set,date_str);
                   1373:        sprintf(buf,"SORRY, the due date was: %s\n",date_str);
                   1374:        append_qtext(buf);
                   1375:        g_passdue = 1;
                   1376:     }
                   1377:   }
                   1378: 
                   1379:   if ((mode==CHECK_ANSWER_MODE) || (mode== TRY_SET_MODE))
                   1380:     capa_set_login_time(g_student_number,set);
                   1381: 
                   1382:   capa_get_header(&header,set);
                   1383: 
                   1384:   sscanf(header.num_questions,"%d",&question_cnt);
                   1385:   print_page_header(mode,question_cnt);
                   1386: 
                   1387: #ifdef CGI_DBUG
                   1388:   fprintf(g_cgi,"DONE page header\n"); fflush(g_cgi);
                   1389: #endif /* CGI_DBUG */
                   1390: 
                   1391:   if(offset < 0 ) offset = - offset;
                   1392:   
                   1393:   Parsemode_f = HTML_MODE; /* WEB_MODE */
                   1394:   result = capa_parse(set, &first_prob, sn, &question_cnt,NULL);  /* <-- capa*() call */
                   1395: 
                   1396: #ifdef CGI_DBUG
                   1397:   fprintf(g_cgi,"DONE capa_parse() [%d], pass due=%d\n",result,g_passdue); fflush(g_cgi);
                   1398: #endif /* CGI_DBUG */
                   1399: 
                   1400:   if (StartText_p) printf(StartText_p);
                   1401:  
                   1402: #ifdef CGI_DBUG
                   1403:   fprintf(g_cgi,"DONE Start Text\n"); fflush(g_cgi);
                   1404: #endif /* CGI_DBUG */
                   1405: 
                   1406:   if ( result != 0 ) {
                   1407:      if( !g_passdue ) {
                   1408:        append_qtext("<FORM method=\"post\" ");
                   1409:        sprintf(buf,"action=\"http://%s/%s/%s/capasbin\">",serverName,
                   1410: 	       g_cgibin_path,c_owner);
                   1411:        append_qtext(buf);
                   1412:        sprintf(buf,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",class); append_qtext(buf);
                   1413:        sprintf(buf,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",sn);          append_qtext(buf);
                   1414:        sprintf(buf,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",pin);       append_qtext(buf);
                   1415:        sprintf(buf,"<input type=\"hidden\" name=\"SET\" value=\"%d\">\n",set);          append_qtext(buf);
                   1416:        sprintf(buf,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_CHECKANS); append_qtext(buf);
                   1417:        sprintf(buf,"<input type=\"hidden\" name=\"STARTNUM\" value=\"%d\">\n",g_start_question); append_qtext(buf);
                   1418:        append_qtext("\n<OL>\n");
                   1419:      }
                   1420: 
                   1421:      for(idx=0;idx<question_cnt;idx++) {         /* prepare log string and new database entry */
                   1422:        g_new_answerdb[idx] = entry.answers[idx];
                   1423:        g_log_string[idx]   = '-';
                   1424:        sscanf(entry.tries + 3*idx,"%d,",&(g_tried[idx]) );
                   1425:      }
                   1426:      g_new_answerdb[question_cnt]=0;  g_log_string[question_cnt]=0;
                   1427:      prob_idx = first_prob;
                   1428:      for( question_idx = 0; question_idx < question_cnt; 
                   1429: 	  question_idx++,prob_idx = prob_idx->next ) {
                   1430: #ifdef CGI_DBUG
                   1431:   fprintf(g_cgi,"quetion_idx: %d, g_start_question:%d, g_num_que: %d\n",
                   1432: 	  question_idx,g_start_question,g_num_questions_per_page); fflush(g_cgi);
                   1433: #endif /* CGI_DBUG */        
                   1434:          if ((question_idx < g_start_question-1) 
                   1435: 	     ||
                   1436: 	     (((!(g_num_questions_per_page == ALL_QUESTIONS)) 
                   1437: 	       && 
                   1438: 	       (question_idx >= (g_start_question+g_num_questions_per_page-1))))) {
                   1439: 	   preserve_last_answer(question_idx,0);
                   1440: 	   continue;
                   1441: 	 }
                   1442:          if( !g_passdue ) {
                   1443:            sprintf(buf,"<A NAME=\"P%d\"></A>",question_idx+1);  append_qtext(buf);
                   1444: 	   /*	   if (!((question_idx == (g_start_question-1)) || (question_idx == 0))) {
                   1445: 	     append_qtext("<A href=\"#TOP\">Top</A>");
                   1446: 	     sprintf(buf,"&nbsp;&nbsp;<A href=\"#P%d\">Next</A>",question_idx+2);  append_qtext(buf);
                   1447: 	     }*/
1.4       albertel 1448: 	   if (prob_idx->question != NULL) {
                   1449: 	     q_leng = strlen(prob_idx->question);
                   1450: 	     if ( !prob_idx->show_br ) {
                   1451: 	       append_qtext(prob_idx->question);
                   1452: 	     } else {
                   1453: 	       for(idx=0;idx<q_leng;idx++) {
                   1454: 		 if ( g_qchar_cnt+2 >= g_qsize ) {
                   1455: 		   char *temp_text;
                   1456: 		   g_qsize=g_qchar_cnt*2;
                   1457: 		   temp_text=capa_malloc(g_qsize,sizeof(char));
                   1458: 		   strncpy(temp_text,g_question_txt,g_qsize);
                   1459: 		   capa_mfree(g_question_txt);
                   1460: 		   g_question_txt=temp_text;		 
                   1461: 		 }
                   1462: 		 g_question_txt[g_qchar_cnt]=prob_idx->question[idx];
                   1463: 		 g_qchar_cnt++;
                   1464: 		 if(prob_idx->question[idx] == '\n' ) {
                   1465: 		   append_qtext("<br>\n");
                   1466: 		 }
1.1       albertel 1467: 	       }
                   1468: 	     }
                   1469: 	   }
                   1470:          }
                   1471:          if(mode == VIEW_PREVIOUS_MODE) { /* VIEW_PREVIOUS_MODE */
                   1472:            if( display_ans ) {
                   1473:              if( prob_idx->ans_type == ANSWER_IS_FLOAT ) {
                   1474:                  a = (double)atof(prob_idx->answer);
                   1475:                  sprintf(cmp_ans,prob_idx->ans_fmt, a);
                   1476:              } else {
                   1477:                  strcpy(cmp_ans,prob_idx->answer);
                   1478:              }
                   1479:              if( prob_idx->ans_unit ) {
                   1480:                  sprintf(buf,"<p><tt><b>Answer:</b> %s %s</tt><br>\n",cmp_ans, prob_idx->unit_str); 
                   1481:              } else {
                   1482:                  sprintf(buf,"<p><tt><b>Answer:</b> %s</tt><br>\n",cmp_ans); 
                   1483:              }
                   1484:              append_qtext(buf);
                   1485: 	     if ( prob_idx->explain) {
                   1486: 	       sprintf(buf,"<p><b>Explanation: </b>\n<p>%s<br>\n",prob_idx->explain);
                   1487: 	       append_qtext(buf);
                   1488: 	     }
                   1489:            }
                   1490:          } else { /* could be TRY_SET_MODE, CHECK_ANSWER_MODE */
                   1491:            
                   1492:            if( g_passdue ) {
                   1493:              get_response(header.partial_credit[question_idx],entry.answers[question_idx],question_idx,prob_idx);
                   1494:            }else{
                   1495: 	     if (g_inhibit_response) {
                   1496: 	       print_inhibited_response(header.partial_credit[question_idx],entry.answers[question_idx],question_idx,prob_idx);
                   1497: 	     } else {
                   1498: 	       print_response(header.partial_credit[question_idx],entry.answers[question_idx],question_idx,prob_idx); 
                   1499: 	     }
                   1500:              append_qtext("<br>\n");
                   1501:              if( (g_tried[question_idx] >= prob_idx->show_hint) || 
                   1502: 		 (entry.answers[question_idx]=='Y') ||
                   1503: 		 (entry.answers[question_idx]=='y')) {
                   1504:                if( prob_idx->hint ) {
                   1505:                  sprintf(buf,"<p><B>Hint: </B>%s\n<br>\n", prob_idx->hint);
                   1506:                  append_qtext(buf);
                   1507:                }
                   1508:              }
                   1509:            }
                   1510:          }
                   1511:      }   /* ------------------------------------- end displaying each problem */
                   1512:      append_qtext("\n</OL>\n");
                   1513:      if( EndText_p )   append_qtext(EndText_p);
                   1514:      free_problems(first_prob);
                   1515: 
                   1516: #ifdef CGI_DBUG
                   1517:   fprintf(g_cgi,"End display each problem\n"); fflush(g_cgi);
                   1518: #endif /* CGI_DBUG */
                   1519: 
                   1520:      if( mode == CHECK_ANSWER_MODE ) {  /* update the record database */
                   1521:        if( !g_passdue ) {
                   1522:          for(idx=0;idx<question_cnt;idx++){
                   1523:            if( g_new_answerdb[idx] != entry.answers[idx]) { 
                   1524:              entry.answers[idx] = g_new_answerdb[idx];
                   1525:            }
                   1526:            if(g_tried[idx] < 10 ) {
                   1527:              entry.tries[3*idx]   = ' ';
                   1528:              entry.tries[3*idx+1] = g_tried[idx] + '0';
                   1529:              if(idx < question_cnt-1)  entry.tries[3*idx+2] = ',';
                   1530:            } else {
                   1531:              entry.tries[3*idx]   = (int)(g_tried[idx]/10) + '0';
                   1532:              entry.tries[3*idx+1] = (g_tried[idx] % 10) + '0';
                   1533:              if(idx < question_cnt-1)  entry.tries[3*idx+2] = ',';
                   1534:            }
                   1535:          }
                   1536:          capa_set_entry(&entry,sn,set,offset);                     /* <-------- capa*() call */
                   1537: 
                   1538: #ifdef CGI_DBUG
                   1539: 	 fprintf(g_cgi,"DONE set db entry\n"); fflush(g_cgi);
                   1540: #endif /* CGI_DBUG */
                   1541: 
                   1542: 	 create_status_line(mode,question_cnt,&entry);
                   1543:        } 
                   1544:        if (w_log_attempt(g_student_number,set,g_log_string) == -1 ) {
                   1545: 	 fprintf(stdout,"<BOLD>Unable to log attempt. Please notify instructor.</BOLD>\n");
                   1546:        }
                   1547:      }
                   1548: #ifdef CGI_DBUG
                   1549:      fprintf(g_cgi,"DONE check answer mode\n"); fflush(g_cgi);
                   1550: #endif /* CGI_DBUG */
                   1551:      
                   1552:      if( (mode == TRY_SET_MODE && !g_passdue)  || 
                   1553: 	 mode == VIEW_PREVIOUS_MODE) {
                   1554:        create_status_line(mode,question_cnt,&entry);
                   1555:      }
                   1556:      
                   1557:      if( !g_passdue ) {
                   1558:        sprintf(buf,"</ul></form>\n"); append_qtext(buf);
                   1559:      }
                   1560:   }
                   1561: }
                   1562: 
1.8     ! albertel 1563: /*if the assignment is passedue we come here to get what the answer was just in case*/
1.1       albertel 1564: void
                   1565: get_response(char pcr,char u_db,int q_idx,Problem_t *p)
                   1566: {
                   1567:   if( pcr == '0' || p->ans_type==ANSWER_IS_SUBJECTIVE ) { /* not hand-graded question */
                   1568:      switch(u_db) {  /* what's from the user record */
                   1569:        case 'Y': break;
                   1570:        case 'y': break;
                   1571:        case '-':
                   1572:                if(g_stu_ans_pp[q_idx+1] != NULL ) log_user_ans(q_idx,p);
                   1573:                break;
                   1574:        case 'E':
                   1575:        case 'e': break;
                   1576:        case 'n': break;
                   1577:        case 'N':
                   1578:        case '0': case '1': case '2': case '3': case '4': 
                   1579:        case '5': case '6': case '7': case '8': case '9':
                   1580:                if(g_stu_ans_pp[q_idx+1] != NULL ) log_user_ans(q_idx,p);
                   1581:                break;
                   1582:        default:
                   1583: 	      break;
                   1584:      }
                   1585:    }
                   1586: }
                   1587: 
                   1588: void display_last_answer(int q_idx)
                   1589: {
                   1590:   char       buf[MAX_BUFFER_SIZE];  
                   1591:   StudentAnswer_t  *sa_p;
                   1592: #ifdef CGI_DBUG
                   1593:   fprintf(g_cgi,"Enter display_last_answer() [%d]\n",q_idx); fflush(g_cgi);
                   1594: #endif /* CGI_DBUG */
                   1595:   if(g_stu_ans_pp[q_idx+1] != NULL) {
                   1596:     sa_p=g_stu_ans_pp[q_idx+1];
                   1597:   } else {
                   1598:     if (g_last_ans_pp[q_idx+1] != NULL) {
                   1599:       sa_p=g_last_ans_pp[q_idx+1];
                   1600:     } else {
                   1601:       return;
                   1602:     }
                   1603:   }
                   1604:   if (sa_p->a_next == NULL) {
                   1605:     sprintf(buf,"<input type=\"hidden\" name=\"LAST%02d\" value=\"%s\">\n",
                   1606: 	    q_idx+1,sa_p->a_str);
                   1607:     append_qtext(buf);
                   1608:     sprintf(buf," <b>Last Answer:</b> %s\n",sa_p->a_str);
                   1609:     append_qtext(buf);
                   1610:   } else {
                   1611:     while(sa_p) {
                   1612:       sprintf(buf,"<input type=\"hidden\" name=\"LAST%02d,%02d\" value=\"%s\">\n",
                   1613: 	      q_idx+1,sa_p->a_idx,sa_p->a_str);
                   1614:       append_qtext(buf);
                   1615:       sprintf(buf," <b>Last Answer %d:</b> %s\n",sa_p->a_idx,sa_p->a_str);
                   1616:       append_qtext(buf);
                   1617:       sa_p=sa_p->a_next;
                   1618:     }
                   1619:   }
                   1620: }
                   1621: 
                   1622: void preserve_last_answer(int q_idx,int print)
                   1623: {
                   1624:   char       buf[MAX_BUFFER_SIZE];  
                   1625:   StudentAnswer_t  *sa_p;
                   1626: #ifdef CGI_DBUG
                   1627:   fprintf(g_cgi,"Enter preserve_last_answer() [%d]\n",q_idx); fflush(g_cgi);
                   1628: #endif /* CGI_DBUG */
                   1629:   if(g_stu_ans_pp[q_idx+1] != NULL) {
                   1630:     sa_p=g_stu_ans_pp[q_idx+1];
                   1631:   } else {
                   1632:     if (g_last_ans_pp[q_idx+1] != NULL) {
                   1633:       sa_p=g_last_ans_pp[q_idx+1];
                   1634:     } else {
                   1635:       return;
                   1636:     }
                   1637:   }
                   1638:   if (sa_p->a_next == NULL) {
                   1639:     sprintf(buf,"<input type=\"hidden\" name=\"LAST%02d\" value=\"%s\">\n",
                   1640: 	    q_idx+1,sa_p->a_str);
                   1641:     if (print) printf(buf); else append_qtext(buf);
                   1642:   } else {
                   1643:     while(sa_p) {
                   1644:       sprintf(buf,"<input type=\"hidden\" name=\"LAST%02d,%02d\" value=\"%s\">\n",
                   1645: 	      q_idx+1,sa_p->a_idx,sa_p->a_str);
                   1646:       if (print) printf(buf); else append_qtext(buf);
                   1647:       sa_p=sa_p->a_next;
                   1648:     }
                   1649:   }
                   1650: }
                   1651: 
                   1652: void display_last_subjective(int q_idx)
                   1653: {
                   1654:   char      *buf;
                   1655:   char      *answer;
                   1656: #ifdef CGI_DBUG
                   1657:   fprintf(g_cgi,"Enter display_last_subjective() [%d]\n",q_idx); fflush(g_cgi);
                   1658: #endif /* CGI_DBUG */
                   1659:   answer=capa_get_subjective(g_login_set,q_idx+1,g_student_number);
                   1660:   if (answer==NULL) return;
                   1661: #ifdef CGI_DBUG
                   1662:   fprintf(g_cgi,"Found answer %s\n",answer); fflush(g_cgi);
                   1663: #endif /* CGI_DBUG */
                   1664:   buf=capa_malloc(MAX_BUFFER_SIZE+strlen(answer),1);
                   1665:   /* don't need to stick in a last since we always get it from the files */
                   1666:   /*  sprintf(buf,"<input type=\"hidden\" name=\"LAST%02d\" value=\"%s\">\n",q_idx+1,answer);*/
                   1667:   append_qtext(buf);
                   1668:   append_qtext("<b>Current Submission:</b><br>\n");
                   1669:   append_qtext("<TABLE BORDER=1 CELLSPACING=0>\n<TR><TD>\n");
                   1670:   append_qtext("<PRE>");
                   1671:   append_qtext(answer);
                   1672:   append_qtext("</PRE>");
                   1673:   append_qtext("</TD></TR></TABLE>\n");
                   1674:   capa_mfree(buf);
                   1675:   capa_mfree(answer);
                   1676: }
                   1677: 
                   1678: void create_answer_area(Problem_t *p,int q_idx) 
                   1679: {
1.4       albertel 1680:   int ii=0;
1.1       albertel 1681:   char       buf[MAX_BUFFER_SIZE];  
1.4       albertel 1682:   AnswerInfo_t *ai;
1.1       albertel 1683: #ifdef CGI_DBUG
                   1684:   fprintf(g_cgi,"Enter create_answer_area() [%d]\n",q_idx); fflush(g_cgi);
                   1685: #endif /* CGI_DBUG */
                   1686: 
                   1687:   if ( p->ans_type==ANSWER_IS_SUBJECTIVE ) {
                   1688:     display_last_subjective(q_idx);
                   1689:   }
                   1690:   if ( p->show_ans_box ) { 
                   1691:     if ( p->ans_op == ANS_AND ) {
1.4       albertel 1692:       if (p->ans_type == ANSWER_IS_FORMULA) {
                   1693: 	/* first answer is stored in p, the rest are linked off of p->ans_list */
1.1       albertel 1694: 	sprintf(buf,"<p><B>Answer %d of %d:</B><input size=80 name=\"INPUT%02d,%02d\" value=\"\">\n",ii+1,p->ans_cnt,q_idx+1,ii+1);
1.4       albertel 1695:       } else {
                   1696: 	sprintf(buf,"<p><B>Answer %d of %d:</B><input name=\"INPUT%02d,%02d\" value=\"\">\n",ii+1,p->ans_cnt,q_idx+1,ii+1);
                   1697:       }
                   1698:       append_qtext(buf);
                   1699:       for(ii=1, ai=p->ans_list;ii<p->ans_cnt;ai=ai->ans_next,ii++) {
                   1700: 	if (ai->ans_type == ANSWER_IS_FORMULA) {
                   1701: 	  sprintf(buf,"<p><B>Answer %d of %d:</B><input size=80 name=\"INPUT%02d,%02d\" value=\"\">\n",ii+1,p->ans_cnt,q_idx+1,ii+1);
1.1       albertel 1702: 	} else {
                   1703: 	  sprintf(buf,"<p><B>Answer %d of %d:</B><input name=\"INPUT%02d,%02d\" value=\"\">\n",ii+1,p->ans_cnt,q_idx+1,ii+1);
                   1704: 	}
                   1705: 	append_qtext(buf);
                   1706:       }
                   1707:     } else { /* single answer, or /OR answers, or subjective answer */
                   1708:       if (p->ans_type == ANSWER_IS_SUBJECTIVE ) {
                   1709: 	sprintf(buf,"<p><B>Answer:</B><br><TEXTAREA name=\"INPUT%02d\" rows=\"15\" cols=\"80\"></TEXTAREA>\n",q_idx+1);
                   1710:       } else {
                   1711: 	if (p->ans_type == ANSWER_IS_FORMULA) {
                   1712: 	  sprintf(buf,"<p><B>Answer:</B><input size=80 name=\"INPUT%02d\" value=\"\">\n",q_idx+1);
                   1713: 	} else {
                   1714: 	  sprintf(buf,"<p><B>Answer:</B><input name=\"INPUT%02d\" value=\"\">\n",q_idx+1);
                   1715: 	}
                   1716:       }
                   1717:       append_qtext(buf);
                   1718:     }
                   1719:   }
                   1720:   append_qtext("<input type=\"submit\" value=\"Submit All Answers\" >\n");
                   1721:   if ( p->ans_type!=ANSWER_IS_SUBJECTIVE ) {
                   1722:     display_last_answer(q_idx);
                   1723:   }
                   1724: }
                   1725: 
                   1726: void
                   1727: print_response(char pcr,char u_db,int q_idx,Problem_t *p)
                   1728: {
                   1729: int   a_tpe;
                   1730: char *c_ans,*response,*answered="Answered",*nycorrect="Not yet correct";
                   1731: int   t_tpe;
                   1732: double tol;
                   1733: int    sig_l;
                   1734: int    sig_u;
                   1735: char  *a_fmt, *c_answer_str;
                   1736: int    tries;
                   1737: 
                   1738:     char       buf[MAX_BUFFER_SIZE];
                   1739: 
                   1740:  a_tpe = p->ans_type;
                   1741:  c_ans = p->answer;
                   1742:  t_tpe = p->tol_type;
                   1743:  tol   = p->tolerance;
                   1744:  sig_l = p->sig_lbound;
                   1745:  sig_u = p->sig_ubound;
                   1746:  a_fmt = p->ans_fmt;
                   1747:  tries = p->tries;
                   1748:  response=nycorrect;
                   1749: 
                   1750: #ifdef CGI_DBUG
                   1751:   fprintf(g_cgi,"Enter print_response() [%c]\n",u_db); fflush(g_cgi);
                   1752: #endif /* CGI_DBUG */
                   1753:   if( pcr == '0' || a_tpe==ANSWER_IS_SUBJECTIVE ) { /* not hand-graded question */
                   1754:      switch(u_db) {  /* this is from the user record */
                   1755:        case 'Y':
                   1756:                c_answer_str = answers_string(ANSWER_STRING_MODE, p);
                   1757:                sprintf(buf,"<p><tt>Correct, computer gets: %s</tt>\n", c_answer_str);
                   1758:                append_qtext(buf);
                   1759:                capa_mfree((char *)c_answer_str);
                   1760:                break;
                   1761:        case 'y':
                   1762:                append_qtext("<p><tt>Hand-graded Correct</tt>\n");
                   1763:                break;
                   1764:        case '-':
                   1765:                if(g_stu_ans_pp[q_idx+1] == NULL ) {
                   1766: 		 create_answer_area(p,q_idx);
                   1767: 	       } else {
                   1768:                  check_user_ans(q_idx,p);
                   1769:                }
                   1770:                break;
                   1771:        case 'E':
                   1772:        case 'e': append_qtext("<p><tt>Excused</tt>\n");               break;
                   1773:        case 'n': append_qtext("<p><tt>Hand-graded Incorrect</tt>\n"); break;
                   1774:        case '0': case '1': case '2': case '3': case '4': 
                   1775:        case '5': case '6': case '7': case '8': case '9':
                   1776: 	 response=answered;
                   1777:        case 'N':
                   1778:                if(g_stu_ans_pp[q_idx+1] == NULL ) {
                   1779: 		 if( g_tried[q_idx] < tries) {
                   1780: 		   create_answer_area(p,q_idx);
                   1781: 		   if( tries - g_tried[q_idx] == 1) {
                   1782: 		     sprintf(buf,"<br><tt>%s, ONE try left!!</tt>\n",response);
                   1783: 		   }else{
                   1784: 		     sprintf(buf,"<br><tt>%s, tries %d/%d</tt>\n",response,
                   1785: 			     g_tried[q_idx],tries);
                   1786: 		   }  
                   1787: 		   append_qtext(buf);
                   1788: 		 }else{
                   1789: 		   if (p->ans_type==ANSWER_IS_SUBJECTIVE)
                   1790: 		     display_last_answer(q_idx);
                   1791: 		   else
                   1792: 		     display_last_subjective(q_idx);
                   1793: 		   append_qtext("<br><tt>No more tries.</tt>\n");
                   1794: 		 } 
                   1795:                } else { /* answering this question */
                   1796: 		 if( g_tried[q_idx] < tries) {
                   1797: 		   check_user_ans(q_idx,p);
                   1798: 		 } else {
                   1799: 		   if (p->ans_type==ANSWER_IS_SUBJECTIVE)
                   1800: 		     display_last_answer(q_idx);
                   1801: 		   else
                   1802: 		     display_last_subjective(q_idx);
                   1803: 		   append_qtext("<br><tt>No more tries.</tt>\n");
                   1804: 		 }
                   1805: 	       }
                   1806:                break;
                   1807:      }
                   1808:    } else {
                   1809:      append_qtext("<p><tt>Question to be Graded Manually.</tt>\n");
                   1810:      
                   1811:    }
                   1812: 
                   1813: }
                   1814: 
                   1815: void
                   1816: print_inhibited_response(char pcr,char u_db,int q_idx,Problem_t *p)
                   1817: {
                   1818: int   a_tpe;
                   1819: char *c_ans;
                   1820: int   t_tpe;
                   1821: double tol;
                   1822: int    sig_l;
                   1823: int    sig_u;
                   1824: char  *a_fmt;
                   1825: int    tries;
                   1826: char       buf[MAX_BUFFER_SIZE];
                   1827: 
                   1828:  a_tpe = p->ans_type;
                   1829:  c_ans = p->answer;
                   1830:  t_tpe = p->tol_type;
                   1831:  tol   = p->tolerance;
                   1832:  sig_l = p->sig_lbound;
                   1833:  sig_u = p->sig_ubound;
                   1834:  a_fmt = p->ans_fmt;
                   1835:  tries = p->tries;
                   1836: 
                   1837: #ifdef CGI_DBUG
                   1838:   fprintf(g_cgi,"Enter print_inhibited_response() [%c]\n",u_db); fflush(g_cgi);
                   1839: #endif /* CGI_DBUG */
                   1840: 
                   1841:   if( pcr == '0' || a_tpe==ANSWER_IS_SUBJECTIVE ) { /* not hand-graded question */
                   1842:      switch(u_db) {  /* this is from the user record */
                   1843:        case '-': 
                   1844:                if(g_stu_ans_pp[q_idx+1] == NULL ) {
                   1845: 		 create_answer_area(p,q_idx);
                   1846:                } else {
                   1847:                  check_inhibited_user_ans(q_idx,p);
                   1848:                }
                   1849:                break;
                   1850:        case 'Y': case 'y':
                   1851:        case 'E': case 'e': 
                   1852:        case 'n': case 'N': 
                   1853:        case '0': case '1': case '2': case '3': case '4': 
                   1854:        case '5': case '6': case '7': case '8': case '9':
                   1855:                if(g_stu_ans_pp[q_idx+1] == NULL ) {
                   1856: 		 if( g_tried[q_idx] < tries) {
                   1857: 		   create_answer_area(p,q_idx);	
                   1858: 		   if( tries - g_tried[q_idx] == 1) {
                   1859: 		     append_qtext("<br><tt>Answered, ONE try left!!</tt>\n");
                   1860: 		   }else{
                   1861: 		     sprintf(buf,"<br><tt>Answered, tries %d/%d</tt>\n",g_tried[q_idx],tries);
                   1862: 		     append_qtext(buf);
                   1863: 		   }  
                   1864: 		 }else{
                   1865: 		   if (p->ans_type==ANSWER_IS_SUBJECTIVE)
                   1866: 		     display_last_answer(q_idx);
                   1867: 		   else
                   1868: 		     display_last_subjective(q_idx);
                   1869: 		   append_qtext("<br><tt>Answered,No more tries.</tt>\n");
                   1870: 		 } 
                   1871: 	       } else { /* answering this question */
                   1872: 		 if( g_tried[q_idx] < tries) {
                   1873: 		   check_inhibited_user_ans(q_idx,p);
                   1874: 		 } else {
                   1875: 		   if (p->ans_type==ANSWER_IS_SUBJECTIVE)
                   1876: 		     display_last_answer(q_idx);
                   1877: 		   else
                   1878: 		     display_last_subjective(q_idx);
                   1879: 		   append_qtext("<br><tt>Answered, No more tries.</tt>\n");
                   1880: 		 }
                   1881:                }
                   1882:                break;
                   1883:      }
                   1884:    } else {
                   1885:      append_qtext("<p><tt>Question to be Graded Manually.</tt>\n"); 
                   1886:    }
                   1887: }
                   1888: 
                   1889: /* returns a -1 if there were not enough answers, otherwise the number of responses
1.5       albertel 1890:    for the question is returned
                   1891:    !!!!!AS A SIDEEFFECT IT ALSO CROPS ANSWERS TO ANSWER_STRING_LENG!!!!!!!
                   1892: */
1.1       albertel 1893: int gather_answers(char ***ans,int q_idx,Problem_t *p)
                   1894: {
                   1895:   int cnt;
                   1896:   if(p->ans_op==ANS_AND) {
                   1897:     int i; StudentAnswer_t *sa_p;
                   1898:     *ans=(char**)capa_malloc(p->ans_cnt,1);
                   1899:     sa_p= g_stu_ans_pp[q_idx+1];
                   1900:     for(i=0;((i<p->ans_cnt)&&(sa_p));i++){
                   1901:       ans[0][i]=sa_p->a_str;
1.5       albertel 1902:       if ((strlen(ans[0][i])+1) > ANSWER_STRING_LENG) ans[0][i][ANSWER_STRING_LENG]='\0';
1.1       albertel 1903:       sa_p=sa_p->a_next;
                   1904:     }
                   1905:     cnt=p->ans_cnt;
                   1906:     if (i<p->ans_cnt) return -1;
                   1907:   } else {
                   1908:     *ans=(char**)capa_malloc(p->ans_cnt,1);
                   1909:     ans[0][0]=g_stu_ans_pp[q_idx+1]->a_str;
1.5       albertel 1910:     if ((strlen(ans[0][0])+1) > ANSWER_STRING_LENG) ans[0][0][ANSWER_STRING_LENG]='\0';
1.1       albertel 1911:     cnt=1;
                   1912:   }
                   1913:   return cnt;
                   1914: }
                   1915: 
1.8     ! albertel 1916: /*logging user's answer when it is passed due.*/
1.1       albertel 1917: void
                   1918: log_user_ans(int q_idx,Problem_t *p)
                   1919: {
                   1920:   char **ans;
                   1921:   int cnt;
                   1922:   if (p->ans_type==ANSWER_IS_SUBJECTIVE) {
1.8     ! albertel 1923:       /*capa_set_subjective(g_login_set,q_idx+1,g_student_number,
        !          1924: 	g_stu_ans_pp[q_idx+1]->a_str);*/
1.1       albertel 1925:   } else {
                   1926:     if (-1 != (cnt=gather_answers(&ans,q_idx,p))) {
                   1927:       switch( capa_check_answers(p,ans,cnt) ) {
                   1928:         case  EXACT_ANS:  g_log_string[q_idx]='Y'; break;
                   1929:         case  APPROX_ANS: g_log_string[q_idx]='Y'; break;
                   1930:         case  SIG_FAIL:   g_log_string[q_idx]='S'; break;
                   1931:         case  UNIT_FAIL:  g_log_string[q_idx]='U'; break;
                   1932:         case  UNIT_NOTNEEDED:  g_log_string[q_idx]='U'; break;
                   1933:         case  NO_UNIT:    g_log_string[q_idx]='u'; break;
                   1934:         case  BAD_FORMULA:  g_log_string[q_idx]='F'; break;
                   1935:         case  INCORRECT:  g_log_string[q_idx]='N'; break;
                   1936:       }
                   1937:     }
                   1938:   }
                   1939: }
                   1940: 
                   1941: void submit_subjective(int q_idx,Problem_t *p)
                   1942: {
                   1943:   char buf[MAX_BUFFER_SIZE];
                   1944:   if (capa_set_subjective(g_login_set,q_idx+1,g_student_number,
                   1945: 			  g_stu_ans_pp[q_idx+1]->a_str)<0){
                   1946:     sprintf(buf,"<p><tt>Falied to record last submission.</tt><br>\n");
                   1947:     g_tried[q_idx]--;
                   1948:   } else {
                   1949:     sprintf(buf,"<p><tt>Current submission recorded.</tt><br>\n");
                   1950:     g_new_answerdb[q_idx] = '0';
                   1951:     g_log_string[q_idx]='A';
                   1952:   }
                   1953:   append_qtext(buf);
                   1954:   if (g_tried[q_idx]<p->tries) {
                   1955:     create_answer_area(p,q_idx);
                   1956:     if( p->tries - g_tried[q_idx] == 1) {
                   1957:       append_qtext("<br><tt>ONE try left</tt>\n");
                   1958:     }else{
                   1959:       sprintf(buf,"<br><tt>tries %d/%d</tt>\n",g_tried[q_idx],p->tries);
                   1960:       append_qtext(buf);
                   1961:     }  
                   1962:   }else{
                   1963:     display_last_answer(q_idx);
                   1964:     append_qtext("<br><tt>No more tries.</tt>\n");
                   1965:   } 
                   1966: }
                   1967: 
                   1968: void
                   1969: check_user_ans(int q_idx,Problem_t *p)
                   1970: {
                   1971: int a_tpe,cnt;
                   1972: char *c_ans,**ans;
                   1973: int   t_tpe;
                   1974: double tol;
                   1975: int    sig_l;
                   1976: int    sig_u;
                   1977: char  *a_fmt;
                   1978: int    tries;
                   1979:   char       buf[MAX_BUFFER_SIZE];
                   1980:   
                   1981:   a_tpe = p->ans_type;
                   1982:   t_tpe = p->tol_type;
                   1983:   tol   = p->tolerance;
                   1984:   sig_l = p->sig_lbound;
                   1985:   sig_u = p->sig_ubound;
                   1986:   a_fmt = p->ans_fmt;
                   1987:   tries = p->tries;
                   1988: 
                   1989: #ifdef CGI_DBUG
                   1990:   fprintf(g_cgi,"Enter check_user_ans() anstype=%d\n",a_tpe); fflush(g_cgi);
                   1991: #endif /* CGI_DBUG */
                   1992: 
                   1993:   g_tried[q_idx]++;
                   1994: 
                   1995: #ifdef CGI_DBUG
                   1996:   fprintf(g_cgi,"Call capa_check_answer() with [%s]\n",g_stu_ans_pp[q_idx+1]->a_str); fflush(g_cgi);
                   1997: #endif /* CGI_DBUG */
                   1998:   if (a_tpe==ANSWER_IS_SUBJECTIVE) {
                   1999:     submit_subjective(q_idx,p);
                   2000:     return;
                   2001:   }
1.5       albertel 2002:   
1.1       albertel 2003:   cnt=gather_answers(&ans,q_idx,p);
                   2004:   if (cnt == -1) {
                   2005:     g_tried[q_idx]--;
                   2006:     create_answer_area(p,q_idx);
                   2007:     if( (tries - g_tried[q_idx]) == 1 ) {
                   2008:       append_qtext("<br><tt>Not all answers submitted, ONE try left!!</tt>\n");
                   2009:     }else{
                   2010:       sprintf(buf,"<br><tt>Not all answers submitted, tries %d/%d.</tt>\n",
                   2011: 	      g_tried[q_idx],tries);
                   2012:       append_qtext(buf);
                   2013:     }
                   2014:     return;
                   2015:   }
                   2016: 
                   2017:   switch( capa_check_answers(p,ans,cnt) ) {
                   2018:     case  EXACT_ANS:    
                   2019:     case  APPROX_ANS: 
                   2020:                    c_ans=answers_string(ANSWER_STRING_MODE, p);
                   2021:                    sprintf(buf,"<p><tt>Yes, Computer gets: %s</tt>\n", c_ans);
                   2022:                    append_qtext(buf);
                   2023:                    g_new_answerdb[q_idx] = 'Y';
                   2024:                    g_log_string[q_idx]='Y';
                   2025: 		   capa_mfree(c_ans);
                   2026: 		   break;
                   2027:     case  SIG_FAIL:
                   2028:                    create_answer_area(p,q_idx);
                   2029: 		   g_tried[q_idx]--;  /* don't count as a try */
                   2030: 		   sprintf(buf,"<br><tt>Please adjust significant figures, tries %d/%d.</tt>\n",g_tried[q_idx],tries);
                   2031: 		   append_qtext(buf);
                   2032: 		   g_new_answerdb[q_idx] = 'N';
                   2033:                    g_log_string[q_idx]='S';
                   2034:                    break;
                   2035:     case  UNIT_FAIL:
                   2036:                    create_answer_area(p,q_idx);
                   2037:                    g_tried[q_idx]--;  /* don't count as a try */
                   2038: 		   sprintf(buf,"<br><tt>Units incorrect, tries %d/%d.</tt>\n",g_tried[q_idx],tries);
                   2039: 		   append_qtext(buf);
                   2040: 		   g_new_answerdb[q_idx] = 'N';
                   2041:                    g_log_string[q_idx]='U';
                   2042:                    break;
                   2043:     case  UNIT_NOTNEEDED:
                   2044:                    create_answer_area(p,q_idx);
                   2045:                    g_tried[q_idx]--;  /* don't count as a try */
                   2046:                    if(tries > 0) {
                   2047:                      sprintf(buf,"<br><tt>Only a number required, tries %d/%d.</tt>\n",g_tried[q_idx],tries);
                   2048:                      append_qtext(buf);
                   2049:                    }
                   2050:                    g_new_answerdb[q_idx] = 'N';
                   2051:                    g_log_string[q_idx]='U';
                   2052:                    break;
                   2053:     case  NO_UNIT: 
                   2054:                    create_answer_area(p,q_idx);
                   2055:                    g_tried[q_idx]--;  /* don't count as a try */
                   2056: 		   sprintf(buf,"<br><tt>Units required, tries %d/%d.</tt>\n",g_tried[q_idx],tries);
                   2057: 		   append_qtext(buf);
                   2058: 		   g_new_answerdb[q_idx] = 'N';
                   2059:                    g_log_string[q_idx]='u';
                   2060:                    break;
                   2061:     case  BAD_FORMULA: 
                   2062:                    create_answer_area(p,q_idx);
                   2063:                    g_tried[q_idx]--;  /* don't count as a try */
                   2064: 		   sprintf(buf,"<br><tt>Unable to understand formula, tries %d/%d.</tt>\n",g_tried[q_idx],tries);
                   2065: 		   append_qtext(buf);
                   2066: 		   g_new_answerdb[q_idx] = 'N';
                   2067:                    g_log_string[q_idx]='F';
                   2068:                    break;
                   2069:     case  INCORRECT:
                   2070:                    if( g_tried[q_idx] < tries ) {
                   2071: 		     create_answer_area(p,q_idx);
                   2072: 		     if( (tries - g_tried[q_idx]) == 1 ) {
                   2073: 		       append_qtext("<br><tt>Incorrect, ONE try left!!</tt>\n");
                   2074: 		     }else{
                   2075: 		       sprintf(buf,"<br><tt>Incorrect, tries %d/%d.</tt>\n",g_tried[q_idx],tries);
                   2076: 		       append_qtext(buf);
                   2077: 		     }
                   2078: 		   } else {
                   2079: 		     display_last_answer(q_idx);
                   2080: 		     append_qtext("<br><tt>Incorrect, no more tries.</tt>\n");
                   2081: 		   }
                   2082:                    g_new_answerdb[q_idx] = 'N';
                   2083:                    g_log_string[q_idx]='N';
                   2084:                    break;
                   2085:   }
                   2086: }
                   2087: 
                   2088: void
                   2089: check_inhibited_user_ans(int q_idx,Problem_t *p)
                   2090: {
                   2091: int a_tpe,cnt;
                   2092: char *c_ans,**ans;
                   2093: int   t_tpe;
                   2094: double tol;
                   2095: int    sig_l;
                   2096: int    sig_u;
                   2097: char  *a_fmt;
                   2098: int    tries;
                   2099:   char       buf[MAX_BUFFER_SIZE];
                   2100:   
                   2101:   a_tpe = p->ans_type;
                   2102:   c_ans = p->answer;
                   2103:   t_tpe = p->tol_type;
                   2104:   tol   = p->tolerance;
                   2105:   sig_l = p->sig_lbound;
                   2106:   sig_u = p->sig_ubound;
                   2107:   a_fmt = p->ans_fmt;
                   2108:   tries = p->tries;
                   2109:   
                   2110: #ifdef CGI_DBUG
                   2111:   fprintf(g_cgi,"Enter check_inhibited_user_ans() anstype=%d\n",a_tpe); fflush(g_cgi);
                   2112: #endif /* CGI_DBUG */
                   2113: 
                   2114:   g_tried[q_idx]++;
                   2115: 
                   2116: #ifdef CGI_DBUG
                   2117:   fprintf(g_cgi,"Call capa_check_answer() with [%s]\n",g_stu_ans_pp[q_idx+1]->a_str); 
                   2118:   fflush(g_cgi);
                   2119: #endif /* CGI_DBUG */
                   2120:   if (a_tpe==ANSWER_IS_SUBJECTIVE) {
                   2121:     submit_subjective(q_idx,p);
                   2122:     return;
                   2123:   }
                   2124: 
                   2125:   cnt=gather_answers(&ans,q_idx,p);
                   2126:   if (cnt == -1) {
                   2127:     g_tried[q_idx]--;
                   2128:     create_answer_area(p,q_idx);
                   2129:     if( (tries - g_tried[q_idx]) == 1 ) {
                   2130:       append_qtext("<br><tt>Not all answers submitted, ONE try left!!</tt>\n");
                   2131:     }else{
                   2132:       sprintf(buf,"<br><tt>Not all answers submitted, tries %d/%d.</tt>\n",
                   2133: 	      g_tried[q_idx],tries);
                   2134:       append_qtext(buf);
                   2135:     }
                   2136:     return;
                   2137:   }
                   2138: 
                   2139:   switch( capa_check_answers(p,ans,cnt) ) {
                   2140:     case  EXACT_ANS:
                   2141:     case  APPROX_ANS: 
                   2142:                    g_new_answerdb[q_idx] = 'Y';
                   2143:                    g_log_string[q_idx]='Y';
                   2144:                    break;
                   2145:     case  SIG_FAIL:
                   2146:                    g_new_answerdb[q_idx] = 'N';
                   2147:                    g_log_string[q_idx]='S';
                   2148:                    break;
                   2149:     case  UNIT_FAIL:
                   2150:                    g_new_answerdb[q_idx] = 'N';
                   2151:                    g_log_string[q_idx]='U';
                   2152:                    break;
                   2153:     case  UNIT_NOTNEEDED:
                   2154:                    g_new_answerdb[q_idx] = 'N';
                   2155:                    g_log_string[q_idx]='U';
                   2156:                    break;
                   2157:     case  NO_UNIT:
                   2158:                    g_new_answerdb[q_idx] = 'N';
                   2159:                    g_log_string[q_idx]='u';
                   2160:                    break;
                   2161:     case  BAD_FORMULA:
                   2162:                    g_new_answerdb[q_idx] = 'N';
                   2163:                    g_log_string[q_idx]='F';
                   2164:                    break;
                   2165:     case  INCORRECT:
                   2166:                    g_new_answerdb[q_idx] = 'N';
                   2167:                    g_log_string[q_idx]='N';
                   2168:                    break;
                   2169:   }
                   2170: 
                   2171:   if( g_tried[q_idx] < tries ) {
                   2172:     create_answer_area(p,q_idx);
                   2173:     if( (tries - g_tried[q_idx]) == 1 ) {
                   2174:       append_qtext("<br><tt>Answered, ONE try left!!</tt>\n");
                   2175:     }else{
                   2176:       sprintf(buf,"<br><tt>Answered, tries %d/%d.</tt>\n",g_tried[q_idx],tries);
                   2177:       append_qtext(buf);
                   2178:     }
                   2179:   } else {
                   2180:     display_last_answer(q_idx);
                   2181:     append_qtext("<br><tt>Answered, no more tries.</tt>\n");
                   2182:   }
                   2183: }
                   2184: 
                   2185: void                                     /* RETURNS: (nothing)          */
                   2186: print_summary(class_dir,class,student_number,pin,set)
                   2187: char *class_dir;char *class;char *student_number;int pin;int set;
                   2188: {                                       /* LOCAL VARIABLES:            */
                   2189:   int      set_idx,                     /*    Set counter              */
                   2190:            i,                           /*    Question counter         */
                   2191:            set_score,                   /*    Score on a set           */
                   2192:            term_score=0,                /*    Total points received    */
                   2193:            term_valid=0,                /*    Total points possible    */
1.4       albertel 2194:            result,
                   2195:            tot_num_sets=0;
1.1       albertel 2196:   T_entry  entry;                       /*    Database entry for a set */
                   2197:   char     buf[MAX_BUFFER_SIZE]; /* Output line buffer  */
                   2198:   char     buf2[MAX_BUFFER_SIZE]; /* Output line buffer  */
                   2199:   T_header header;                      /*    Problem set header       */
                   2200:   int      question_cnt,valid_wgt, rate,configResult,
                   2201:     status_line_length=DEFAULT_STATUS_LINE_LENGTH,row;
                   2202:   char     class_fullpath[ONE_K],*serverName;
                   2203: 
                   2204:   serverName=getenv("SERVER_NAME");
                   2205:   if (!serverName) {
                   2206:     fprintf(stdout,"Enviroment variable SERVER_NAME not set.\n");
                   2207:     fprintf(stdout,"Unable to complete actions.\n");
                   2208:     return;
                   2209:   }
1.4       albertel 2210:   printf("<!--print_summary-->");
1.1       albertel 2211:   sprintf(class_fullpath,"%s/%s",class_dir,class);
                   2212:   chdir(class_fullpath);
                   2213:   configResult=read_capa_config("web_status_line_length",buf);
                   2214:   if (configResult != 0 && configResult != -1 ) {
                   2215:     if (sscanf(buf,"%d",&status_line_length)==0) {
                   2216:       status_line_length=DEFAULT_STATUS_LINE_LENGTH;
                   2217:     }
                   2218:   } else {
                   2219:     status_line_length=DEFAULT_STATUS_LINE_LENGTH;
                   2220:   }
                   2221:   
                   2222:   printf("<TABLE>\n<TR><TD></TD>\n");
                   2223:   for(i=0;i<status_line_length;i++) {
                   2224:     printf("<TD align=center valign=bottom>%d</TD>\n",i+1);
                   2225:   }
                   2226:   printf("</TR>");
                   2227: 
                   2228:   for (set_idx=1; set_idx<=set; set_idx++) {
                   2229:     g_inhibit_response=capa_check_option(OPTION_INHIBIT_RESPONSE,set_idx,
                   2230: 					 g_student_data.s_sec);
1.4       albertel 2231:     if (g_inhibit_response > 0) {
                   2232:       printf("<!-- Set %d is inhibited -->\n",set_idx);
                   2233:       continue;
                   2234:     }
                   2235:     if ( capa_check_date(CHECK_OPEN_DATE,g_student_number,
                   2236: 			     g_student_data.s_sec,set_idx) < 0 ){
                   2237:       printf("<!-- Set %d is not open -->\n",set_idx);
                   2238:       continue;
                   2239:     }
1.1       albertel 2240: 
                   2241:     if (capa_get_header(&header,set_idx))  return;
1.4       albertel 2242:     tot_num_sets++;
1.1       albertel 2243:     capa_get_entry(&entry,student_number,set_idx);
                   2244:     sscanf(header.num_questions,"%d", &(question_cnt) );
                   2245:     valid_wgt = 0; set_score = 0;
                   2246:     header.weight[question_cnt] = '\0';
                   2247:     header.partial_credit[question_cnt] = '\0';
                   2248:     for (i=0; i<question_cnt; i++) {
                   2249:       valid_wgt +=  (header.weight[i] - '0');
                   2250:       if((entry.answers[i]=='Y') || (entry.answers[i]=='y'))  
                   2251: 	set_score += (header.weight[i]-'0');
                   2252:       if((entry.answers[i]=='E') || (entry.answers[i]=='e'))  
                   2253: 	valid_wgt -= (header.weight[i] - '0');
                   2254:       if((entry.answers[i]>='0') && (entry.answers[i]<='9'))  
                   2255: 	set_score += (entry.answers[i] - '0');
                   2256:     }
                   2257:     term_valid += valid_wgt;
                   2258:     term_score += set_score;
                   2259: 
                   2260:     if( valid_wgt != 0 ) {
                   2261:       rate = 100*set_score / valid_wgt;
                   2262:       printf("<TR><TD nowrap align=center valign=bottom>set <B>%d</B>, %d/%d(%d %%)  </TD>",set_idx,set_score,valid_wgt,rate);
                   2263:     } else {
                   2264:       printf("<TR><TD nowrap align=center valign=bottom>set <B>%d</B>,   0/0(0 %%)   </TD>",set_idx);
                   2265:     }
                   2266:     for(row=0;row<=(question_cnt/status_line_length);row++) {
                   2267:       for(i=(row*status_line_length);
                   2268: 	  ((i<question_cnt)&&(i<((row+1)*status_line_length))); i++) {
                   2269: 	if (i != 0 && (!(i%status_line_length))) { printf("</TR><TD></TD>"); }
                   2270: 	printf("<TD align=center valign=bottom><tt>%c</tt></TD>\n",entry.answers[i]);
                   2271:       }
                   2272:       printf("</TR>\n<TR><TD></TD>");
                   2273:       for(i=(row*status_line_length);
                   2274: 	  ((i<question_cnt)&&(i<((row+1)*status_line_length))); i++) {
                   2275: 	if (i != 0 && (!(i%status_line_length))) { printf("</TR><TD></TD>"); }
                   2276: 	printf("<TD align=center valign=bottom><tt>%c</tt></TD>\n",header.weight[i]);
                   2277:       }
                   2278:     }
                   2279:     printf("</TR>");
                   2280:     capa_mfree(header.weight);
                   2281:     capa_mfree(header.partial_credit);
                   2282:   }
                   2283:   printf("\n</TABLE>\n<hr>\n");
                   2284:   /* SHOW TOTALS */
                   2285:   /* if capalogin_show_summary_score is set to none don't show it */
1.4       albertel 2286:   if (term_valid > 0) {
                   2287:     sprintf(buf,"%d sets, total = %3d/%3d (%d%%)\n", tot_num_sets, term_score, term_valid, 100*term_score/term_valid);
                   2288:   } else {
                   2289:     sprintf(buf,"%d sets, total = %3d/%3d\n", tot_num_sets, term_score, term_valid);
                   2290:   }
1.1       albertel 2291:   result=read_capa_config("capalogin_show_summary_score",buf2);
                   2292:   if (result != 0 && result != -1) {
                   2293:     if (strcasecmp(buf2,"none")==0) {
                   2294:     } else {
                   2295:       printf("%s",buf);
                   2296:     }
                   2297:   } else {
                   2298:     printf("%s",buf);
                   2299:   }
                   2300: 
                   2301:   printf("<TABLE cellpadding=0 cellspacing=0 border=0>\n<TR><TD>");
                   2302:   printf("<form method=\"post\" ");
                   2303:   sprintf(buf,"action=\"http://%s/%s/%s/capasbin\">",serverName,g_cgibin_path,g_cowner);
                   2304:   printf("%s\n", buf);
                   2305:   printf("<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",g_class_name);
                   2306:   printf("<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",g_student_number);
                   2307:   printf("<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",g_entered_pin);
                   2308:   printf("<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_CHECKIN);
                   2309:   printf("<input type=\"submit\" value=\"Main menu\" ></form></TD>\n");
                   2310:   printf("<TD><form method=\"get\" action=\"http://%s/CAPA/class.html\">",serverName); 
                   2311:   printf("<input type=\"button\" value=\"Exit\" onclick=\"window.close()\"></form></TD>");
                   2312:   printf("\n</TABLE>\n");
                   2313: }
                   2314: 
                   2315: 
                   2316: void
                   2317: process_mode(int mode) {
                   2318: 
                   2319: #ifdef CGI_DBUG
                   2320:   fprintf(g_cgi,"entered process_mode[%d]\n",mode); fflush(g_cgi);
                   2321: #endif /* CGI_DBUG */
                   2322:   g_qchar_cnt=g_schar_cnt=0;
                   2323:   g_qsize=TEXT_BUF_SIZE*sizeof(char);
                   2324:   g_ssize=STATUS_BUF_SIZE*sizeof(char);
                   2325:   g_question_txt=capa_malloc(TEXT_BUF_SIZE,sizeof(char));
                   2326:   g_status_txt  =capa_malloc(STATUS_BUF_SIZE,sizeof(char));
                   2327: #ifdef CGI_DBUG
                   2328:   fprintf(g_cgi,"alloced everything\n"); fflush(g_cgi);
                   2329: #endif /* CGI_DBUG */
                   2330:   if( mode == VIEW_PREVIOUS_MODE ) {
                   2331:     print_quizz(g_cpath,g_cowner,g_class_name,g_student_number, g_entered_pin, g_vset,mode); 
                   2332:   } else if( mode == TRY_SET_MODE ) {
                   2333:     print_quizz(g_cpath,g_cowner,g_class_name,g_student_number, g_entered_pin, g_login_set,mode);
                   2334:   } else {
                   2335:     print_quizz(g_cpath,g_cowner,g_class_name,g_student_number,g_entered_pin,g_login_set,CHECK_ANSWER_MODE);
                   2336:   }
                   2337:   g_status_txt[g_schar_cnt]=0;
                   2338:   g_question_txt[g_qchar_cnt]=0;
                   2339:   if( g_schar_cnt != 0 ) {
                   2340:          fprintf(stdout,"%s",g_status_txt);
                   2341: #ifdef CGI_DBUG
                   2342:   fprintf(g_cgi,"print status [%s]\n",g_status_txt); fflush(g_cgi);
                   2343: #endif /* CGI_DBUG */
                   2344:   }
                   2345:   if( g_qchar_cnt != 0) {
                   2346:          fprintf(stdout,"%s",g_question_txt);
                   2347: #ifdef CGI_DBUG
                   2348:   fprintf(g_cgi,"print question [%s]\n",g_question_txt); fflush(g_cgi);
                   2349: #endif /* CGI_DBUG */
                   2350:   }
                   2351:   if( g_schar_cnt != 0 ) {
                   2352:          fprintf(stdout,"%s",g_status_txt);
                   2353:   }
                   2354:   fflush(stdout);
                   2355:   capa_mfree(g_status_txt);
                   2356:   capa_mfree(g_question_txt);
                   2357: 
                   2358: }
                   2359: 
                   2360: /*  mode could be exam summary, show or not show percentage */
                   2361: /*                quiz summary, show or not show percentage */
                   2362: void
                   2363: process_summary(int mode)
                   2364: {
                   2365:   int   outcome;
                   2366:   int   i, len;
                   2367:   char *c_name;
                   2368:   char  c_path[512];
                   2369:   
                   2370:   outcome = check_exam_quiz_path();
                   2371:   if( (mode == M_EXAMSUMM) && (outcome & 1) ) {  /* exam summary */
                   2372:     c_name = rindex(g_exam_path,'/');
                   2373:     c_name++;
                   2374:     i = strlen(c_name);
                   2375:     len = strlen(g_exam_path) - i - 1;
                   2376:     for(i=0;i<len;i++) {
                   2377:       c_path[i]=g_exam_path[i];
                   2378:     }
                   2379:     c_path[len]=0;
                   2380:     print_summary(c_path,c_name,g_student_number, g_entered_pin, g_exam_set);
                   2381:   }
                   2382:   if( (mode == M_QUIZSUMM) && (outcome & 2) ) {  /* quiz summary */
                   2383:     c_name = rindex(g_quiz_path,'/');
                   2384:     c_name++;
                   2385:     i = strlen(c_name);
                   2386:     len = strlen(g_quiz_path) - i - 1;
                   2387:     for(i=0;i<len;i++) {
                   2388:       c_path[i]=g_quiz_path[i];
                   2389:     }
                   2390:     c_path[len]=0;
                   2391:     print_summary(c_path,c_name,g_student_number, g_entered_pin, g_quiz_set);
                   2392:   }
                   2393:   
                   2394: }
                   2395: 
                   2396: /* ---------------- JAVA TScore.class page print out ----------------- */
                   2397: void                                     /* RETURNS: (nothing)          */
                   2398: print_termscore_page(class_dir,class,student_number,pin,set,out)
                   2399: char *class_dir;char *class;char *student_number;int pin;int set; /* student login set */
                   2400: FILE *out;
                   2401: {                                       /* LOCAL VARIABLES:            */
                   2402:   int      set_idx,                     /*    Set counter              */
                   2403:            i,                           /*    Question counter         */
                   2404:            set_score,                   /*    Score on a set           */
                   2405:            term_score=0,                /*    Total points received    */
1.3       albertel 2406:            term_valid=0;                /*    Total points possible    */
1.1       albertel 2407:   T_entry  entry;                       /*    Database entry for a set */
                   2408:   char     buf[MAX_BUFFER_SIZE]; /* Output line buffer  */
                   2409:   T_header header;                      /*    Problem set header       */
1.3       albertel 2410:   int      question_cnt,valid_wgt,configResult;
1.1       albertel 2411:   char     class_fullpath[ONE_K],*serverName;
                   2412:   int      hw_c, hw_r, qz_c, qz_r, fs, homework_count, quiz_count;
                   2413:   float    hw_w, qz_w, ex_w, fe_w, pc_w;
                   2414:   int      idx, entry_count, tmp_len;
                   2415:   float    *S, *F;
1.7       albertel 2416:   int      *X; /* array controlling whether to extrapolate scores */
1.3       albertel 2417:   char     *capa_server;
1.7       albertel 2418:   int      max_set[4], width=600,height=750; /* width and height of applet*/
1.1       albertel 2419:   char     **c_path_pp;
1.3       albertel 2420: 
                   2421:   /*Unused Vars  
                   2422:     char     buf2[MAX_BUFFER_SIZE]; 
                   2423:     char *qz_p, *ex_p, *epc_p; 
                   2424:     int      ex_c, epc_c, result;
                   2425:     int  rate, status_line_length=DEFAULT_STATUS_LINE_LENGTH,row;
                   2426:   */
                   2427: 
1.1       albertel 2428:   serverName=getenv("SERVER_NAME");
                   2429:   if (!serverName) {
                   2430:     fprintf(out,"Enviroment variable SERVER_NAME not set.\n");
                   2431:     fprintf(out,"Unable to complete actions.\n");
                   2432:     return;
                   2433:   }
                   2434: 
                   2435:   sprintf(class_fullpath,"%s/%s",class_dir,class);
                   2436:   chdir(class_fullpath);
                   2437:   
                   2438:   /*
                   2439:      change the working director to the major homework directory and begin to
                   2440:      read off the remaining path informations from this capa.config file 
                   2441:      homework_path   = 
                   2442:      quiz_path   = 
                   2443:      exam_path   = 
                   2444:      correction_path = 
                   2445:      homework_weight   = 0.3
                   2446:      quiz_weight       = 0.7
                   2447:      exam_weight       = 0.3
                   2448:      final_weight      = 0.35
                   2449:      correction_weight = 0.3
                   2450:      final_exam_set_number = 4
                   2451:      homework_count    = 12
                   2452:      quiz_count        = 24
                   2453:      
                   2454:   */
                   2455:   
                   2456:   configResult=read_capa_config("capa_server",buf);
                   2457:   if (configResult != 0 && configResult != -1 ) {
                   2458:     tmp_len = strlen(buf) + 1;
                   2459:     capa_server =   (char *)capa_malloc( tmp_len, sizeof(char));
                   2460:     sprintf(capa_server,"%s",buf);
                   2461:   } else { /* if capa_server is not set then we won't do anything further */
                   2462:     fprintf(out,"Parameter: capa_server in capa.config file are not properly set.\n");
                   2463:     return ;
                   2464:   }
                   2465:   if( get_termscore_params(&hw_w,&qz_w,&ex_w,&fe_w,&pc_w,&homework_count,&quiz_count,&fs) == -1 ) {
                   2466:     fprintf(out,"Parameters in capa.config file are not properly set.\n");
                   2467:     fprintf(out," such as homework_weight, quiz_weight, exam_weight, final_weight, correction_weight.\n");
                   2468:     
                   2469:     return;
                   2470:   }
1.7       albertel 2471: 
                   2472:   get_tscore_width_height(&width,&height);
                   2473: 
1.1       albertel 2474:   c_path_pp = (char **)capa_malloc( 4, sizeof(char *));
                   2475:   tmp_len = strlen(class_fullpath) + 1;
                   2476:   c_path_pp[0] = (char *)capa_malloc(tmp_len,sizeof(char));
                   2477:   sprintf(c_path_pp[0],"%s",class_fullpath); /* c_path_pp[0] should always be there */
                   2478:   
                   2479:   entry_count = fs*2 + 1;
                   2480:   S = (float *)capa_malloc( ((fs+1)*2), sizeof(float));
                   2481:   F = (float *)capa_malloc( ((fs+1)*2), sizeof(float));
                   2482:   X =   (int *)capa_malloc( ((fs+1)*2), sizeof(int));
                   2483:   
                   2484:   max_set[0] = set;  /* the login set number */
                   2485:   hw_c = max_set[0];
                   2486:   hw_r = homework_count - set;
                   2487:   
                   2488:   
                   2489:   configResult=read_capa_config("quiz_path",buf);
                   2490:   if (configResult != 0 && configResult != -1 ) {
                   2491:     tmp_len = strlen(buf)+1;
                   2492:     c_path_pp[1] = (char *)capa_malloc(tmp_len,sizeof(char));
                   2493:     sprintf(c_path_pp[1],"%s",buf);
                   2494:     max_set[1] = check_class_get_maxset(c_path_pp[1]);
                   2495:     if( max_set[1] <= 0 ) {
                   2496:       /* should we continue ? */
                   2497:       max_set[1] = 1;
                   2498:       X[1] = 1;
                   2499:     }
                   2500:     qz_c = max_set[1];
                   2501:     qz_r = quiz_count - max_set[1];
                   2502:   } else { /* if quiz_path is not in capa.config, then we will skip quizz */
                   2503:     qz_c = 0;
                   2504:     qz_r = 0;
                   2505:   }
                   2506:   
                   2507:   
                   2508:   configResult=read_capa_config("exam_path",buf);
                   2509:   if (configResult != 0 && configResult != -1 ) {
                   2510:     tmp_len = strlen(buf)+1;
                   2511:     c_path_pp[2] = (char *)capa_malloc( (tmp_len),sizeof(char));
                   2512:     sprintf(c_path_pp[2],"%s",buf);
                   2513:     max_set[2] = check_class_get_maxset(c_path_pp[2]);
1.7       albertel 2514:     printf("<!-- for %s max_set %d -->\n",c_path_pp[2],max_set[2]);
1.1       albertel 2515:     if( max_set[2] <= 0 ) {
1.7       albertel 2516: 	/* no sets */
                   2517: 	max_set[2] = 0;
                   2518:     }
                   2519:     /* start extrapolation with sets that don't yet exist */
                   2520:     for(idx=2+(max_set[2]*2);idx <= (fs*2); idx++) {
1.1       albertel 2521:         X[idx] = 1;
                   2522:     }
                   2523:   } else { /* if exam_path is not in capa.config, then skip exams */
                   2524:     fs = 0;
                   2525:   }
                   2526:   configResult=read_capa_config("correction_path",buf);
                   2527:   if (configResult != 0 && configResult != -1 ) {
                   2528:     tmp_len = strlen(buf)+1;
                   2529:     c_path_pp[3] = (char *)capa_malloc(tmp_len,sizeof(char));
                   2530:     sprintf(c_path_pp[3],"%s",buf);
                   2531:     max_set[3] = check_class_get_maxset(c_path_pp[3]);
                   2532:     if( max_set[3] <= 0 ) {
                   2533:       /* should we continue ? */
                   2534:       max_set[3] = 0;
                   2535:       
                   2536:     }
                   2537:   } else { /* if correction_path is not in capa.config, then skip corrections */
                   2538:     pc_w = 0.0;
                   2539:   }
                   2540:   
                   2541:   
                   2542:   
                   2543:   for( idx = 0; idx < 4; idx++) {
                   2544:      if( c_path_pp[idx] != NULL ) {
                   2545:        chdir(c_path_pp[idx]);
                   2546:        term_score=0;
                   2547:        term_valid=0;
                   2548:        for (set_idx=1; set_idx<=max_set[idx]; set_idx++) {
                   2549:           if (capa_get_header(&header,set_idx))  return;
                   2550:           capa_get_entry(&entry,student_number,set_idx);
                   2551:           sscanf(header.num_questions,"%d", &(question_cnt) );
                   2552:           valid_wgt = 0; set_score = 0;
                   2553:           header.weight[question_cnt] = '\0';
                   2554:           header.partial_credit[question_cnt] = '\0';
                   2555:           for (i=0; i<question_cnt; i++) {
                   2556:             valid_wgt +=  (header.weight[i] - '0');
                   2557:             if((entry.answers[i]=='Y') || (entry.answers[i]=='y'))  
                   2558: 	       set_score += (header.weight[i]-'0');
                   2559:             if((entry.answers[i]=='E') || (entry.answers[i]=='e'))  
                   2560: 	       valid_wgt -= (header.weight[i] - '0');
                   2561:             if((entry.answers[i]>='0') && (entry.answers[i]<='9'))  
                   2562: 	       set_score += (entry.answers[i] - '0');
                   2563:           }
                   2564:           term_valid += valid_wgt;
                   2565:           term_score += set_score;
                   2566:           capa_mfree(header.weight);
                   2567:           capa_mfree(header.partial_credit);
1.7       albertel 2568: 	  printf("<!-- %s %d %d -->\n",c_path_pp[idx],set_score,valid_wgt);
1.1       albertel 2569:           if(idx==2) { /* exam sets */
                   2570:             S[set_idx*2] = (float)set_score;
                   2571:             F[set_idx*2] = (float)valid_wgt;
1.7       albertel 2572:             if (valid_wgt == 0) {
                   2573: 		X[set_idx*2] = 1;
                   2574: 	    } else {
                   2575: 		X[set_idx*2] = 0;
                   2576: 	    }
1.1       albertel 2577:           }
                   2578:           if(idx==3) { /* correction sets */
                   2579:             S[set_idx*2+1] = (float)set_score;
                   2580:             F[set_idx*2+1] = (float)valid_wgt;
1.7       albertel 2581: 	    if (valid_wgt == 0 ) {
                   2582: 		X[set_idx*2+1] = 1;
                   2583: 	    } else {
                   2584: 		X[set_idx*2+1] = 0;
                   2585: 	    }
1.1       albertel 2586:           }
                   2587:        }
                   2588:        if( (idx == 0) || (idx==1) ) { /* homeworks and quizzes */
                   2589:          S[idx] = (float)term_score;
                   2590:          F[idx] = (float)term_valid;
                   2591:          X[idx] = 1;
                   2592:        }
                   2593:      }
                   2594:   }
                   2595:   
                   2596:   
                   2597: 
                   2598:   
                   2599:   fprintf(out,"<CENTER>\n");
1.7       albertel 2600:   fprintf(out,"<APPLET CODE=TScore.class CODEBASE=\"http://%s\" width=%d height=%d>\n",capa_server,width,height);
1.1       albertel 2601:   fprintf(out,"<PARAM NAME=\"HW_W\"  VALUE=\"%f\">\n", hw_w);
                   2602:   fprintf(out,"<PARAM NAME=\"QZ_W\"  VALUE=\"%f\">\n", qz_w);
                   2603:   fprintf(out,"<PARAM NAME=\"EX_W\"  VALUE=\"%f\">\n", ex_w);
                   2604:   fprintf(out,"<PARAM NAME=\"FE_W\"  VALUE=\"%f\">\n", fe_w);
                   2605:   fprintf(out,"<PARAM NAME=\"PC_W\"  VALUE=\"%f\">\n", pc_w);
                   2606:   fprintf(out,"<PARAM NAME=\"HW_C\"  VALUE=\"%d\">\n", hw_c);
                   2607:   fprintf(out,"<PARAM NAME=\"HW_R\"  VALUE=\"%d\">\n", hw_r);
                   2608:   fprintf(out,"<PARAM NAME=\"FS\"    VALUE=\"%d\">\n", fs);
                   2609:   fprintf(out,"<PARAM NAME=\"QZ_C\"  VALUE=\"%d\">\n", qz_c);
                   2610:   fprintf(out,"<PARAM NAME=\"QZ_R\"  VALUE=\"%d\">\n", qz_r);
                   2611:   
                   2612: 
                   2613:   for(idx=0;idx<entry_count;idx++) {
                   2614:     fprintf(out,"<PARAM NAME=\"S%d\"  VALUE=\"%f\">\n",idx,S[idx]);
                   2615:     fprintf(out,"<PARAM NAME=\"F%d\"  VALUE=\"%f\">\n",idx,F[idx]);
                   2616:     fprintf(out,"<PARAM NAME=\"X%d\"  VALUE=\"%d\">\n",idx,X[idx]);
                   2617:   }
                   2618:   
                   2619:   fprintf(out,"</APPLET> </CENTER>\n");
                   2620:   
                   2621:   fprintf(out,"<TABLE cellpadding=0 cellspacing=0 border=0>\n<TR><TD>");
                   2622:   fprintf(out,"<form method=\"post\" ");
                   2623:   sprintf(buf,"action=\"http://%s/%s/%s/capasbin\">",serverName,g_cgibin_path,g_cowner);
                   2624:   fprintf(out,"%s\n", buf);
                   2625:   fprintf(out,"<input type=\"hidden\" name=\"CLASS\" value=\"%s\">\n",g_class_name);
                   2626:   fprintf(out,"<input type=\"hidden\" name=\"SNUM\" value=\"%s\">\n",g_student_number);
                   2627:   fprintf(out,"<input type=\"hidden\" name=\"CAPAID\" value=\"%d\">\n",g_entered_pin);
                   2628:   fprintf(out,"<input type=\"hidden\" name=\"M\" value=\"%d\">\n",M_CHECKIN);
                   2629:   fprintf(out,"<input type=\"submit\" value=\"Main menu\" ></form></TD>\n");
                   2630:   fprintf(out,"<TD><form method=\"get\" action=\"http://%s/CAPA/class.html\">",serverName); 
                   2631:   fprintf(out,"<input type=\"button\" value=\"Exit\" onclick=\"window.close()\"></form></TD>");
                   2632:   fprintf(out,"\n</TABLE>\n");
                   2633:   
                   2634:   capa_mfree((char *)S);
                   2635:   capa_mfree((char *)F);
                   2636:   capa_mfree((char *)X);
                   2637:   for(idx=0;idx<4;idx++) {
                   2638:     if( c_path_pp[idx] != NULL )  capa_mfree((char *)c_path_pp[idx]);
                   2639:   }
                   2640:   capa_mfree((char *)c_path_pp);
                   2641:   capa_mfree((char *)capa_server);
                   2642: }
                   2643: 
1.7       albertel 2644: int
                   2645: get_tscore_width_height(width,height) 
                   2646: int *width;int *height;
                   2647: {
                   2648:   char     buf[MAX_BUFFER_SIZE]; 
                   2649:   int      configResult;
                   2650:   
                   2651:   configResult=read_capa_config("tscore_width",buf);
                   2652:   if (configResult != 0 && configResult != -1 ) {
                   2653:     sscanf(buf,"%d", width);
                   2654:     if (*width <= 0 )  { *width = DEFAULT_WIDTH; }
                   2655:   } else {
                   2656:       printf("<!-- tscore_width not found. %d-->\n",configResult);
                   2657:   }
                   2658:   configResult=read_capa_config("tscore_height",buf);
                   2659:   if (configResult != 0 && configResult != -1 ) {
                   2660:     sscanf(buf,"%d", height);
                   2661:     if (*height <= 0 )  { *height = DEFAULT_HEIGHT; }
                   2662:   } else {
                   2663:       printf("<!-- tscore_height not found. %d-->\n",configResult);
                   2664:   }
                   2665: }
1.1       albertel 2666: 
                   2667: int
                   2668: get_termscore_params(hw,qw,ew,fw,pw,hc,qc,fs) 
                   2669: float *hw;float *qw;float *ew;float *fw;float *pw;
                   2670: int   *hc;int   *qc;int   *fs;
                   2671: {
                   2672:   char     buf[MAX_BUFFER_SIZE]; /* Output line buffer  */
                   2673:   int      hw_c, qz_c, fe_s;
                   2674:   float    hw_w, qz_w, ex_w, fe_w, pc_w;
                   2675:   int      configResult;
                   2676:   
                   2677:   configResult=read_capa_config("homework_weight",buf);
                   2678:   if (configResult != 0 && configResult != -1 ) {
                   2679:     sscanf(buf,"%f", &hw_w);
                   2680:     if(hw_w <= 0.0 )  {
                   2681:       hw_w = DEFAULT_HW_W;
                   2682:     }
                   2683:   } else {
                   2684:     return (-1);
                   2685:   }
                   2686:   configResult=read_capa_config("quiz_weight",buf);
                   2687:   if (configResult != 0 && configResult != -1 ) {
                   2688:     sscanf(buf,"%f", &qz_w);
                   2689:     if(qz_w <= 0.0 )  {
                   2690:       qz_w = DEFAULT_QZ_W;
                   2691:     }
                   2692:   } else {
                   2693:     return (-1);
                   2694:   }
                   2695:   configResult=read_capa_config("exam_weight",buf);
                   2696:   if (configResult != 0 && configResult != -1 ) {
                   2697:     sscanf(buf,"%f", &ex_w);
                   2698:     if(ex_w <= 0.0 )  {
                   2699:       ex_w = DEFAULT_EX_W;
                   2700:     }
                   2701:   } else {
                   2702:     return (-1);
                   2703:   }
                   2704:   configResult=read_capa_config("final_weight",buf);
                   2705:   if (configResult != 0 && configResult != -1 ) {
                   2706:     sscanf(buf,"%f", &fe_w);
                   2707:     if(fe_w <= 0.0 )  {
                   2708:       fe_w = DEFAULT_FE_W;
                   2709:     }
                   2710:   } else {
                   2711:     return (-1);
                   2712:   }
                   2713:   configResult=read_capa_config("correction_weight",buf);
                   2714:   if (configResult != 0 && configResult != -1 ) {
                   2715:     sscanf(buf,"%f", &pc_w);
                   2716:     if(pc_w <= 0.0 )  {
                   2717:       pc_w = DEFAULT_PC_W;
                   2718:     }
                   2719:   } else {
                   2720:     return (-1);
                   2721:   }
                   2722:   configResult=read_capa_config("final_exam_set_number",buf);
                   2723:   if (configResult != 0 && configResult != -1 ) {
                   2724:     sscanf(buf,"%d", &fe_s);
                   2725:     if(fe_s <= 0 )  {
                   2726:       fe_s = DEFAULT_FE_NUMBER;
                   2727:     }
                   2728:   } else {
                   2729:     return (-1);
                   2730:   }
                   2731:   configResult=read_capa_config("homework_count",buf);
                   2732:   if (configResult != 0 && configResult != -1 ) {
                   2733:     sscanf(buf,"%d", &hw_c);
                   2734:     if(hw_c <= 0 )  {
                   2735:       hw_c = DEFAULT_HW_COUNT;
                   2736:     }
                   2737:   } else {
                   2738:     return (-1);
                   2739:   }
                   2740:   configResult=read_capa_config("quiz_count",buf);
                   2741:   if (configResult != 0 && configResult != -1 ) {
                   2742:     sscanf(buf,"%d", &qz_c);
                   2743:     if(qz_c <= 0 )  {
                   2744:       qz_c = DEFAULT_QZ_COUNT;
                   2745:     }
                   2746:   } else {
                   2747:     return (-1);
                   2748:   }
                   2749:   *hw = hw_w; *qw = qz_w; *ew = ex_w; *fw = fe_w; *pw = pc_w;
                   2750:   *hc = hw_c; *qc = qz_c; *fs = fe_s;
                   2751:   return (0);
                   2752: 
                   2753: }
                   2754: 
                   2755: /* =================================================================================================== */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>