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