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