| 1 | #!/usr/bin/perl |
1 | #!/usr/local/bin/webwork-perl |
| 2 | |
2 | |
| 3 | # This file is processProblem8.pl |
3 | # This file is processProblem8.pl |
| 4 | # This is a special version of processProblem.pl |
4 | # This is a special version of processProblem.pl |
| 5 | # made to be used as an editor |
5 | # made to be used as an editor |
| 6 | |
6 | |
| … | |
… | |
| 10 | # 'course' |
10 | # 'course' |
| 11 | # 'probSetKey' and |
11 | # 'probSetKey' and |
| 12 | # 'probNum' |
12 | # 'probNum' |
| 13 | # and in addition |
13 | # and in addition |
| 14 | # 'Mode' (for either TeX mode or HTML mode or Latex2HTML mode) |
14 | # 'Mode' (for either TeX mode or HTML mode or Latex2HTML mode) |
|
|
15 | # 'show_old_answers' (whether or not student's old answers should be filled in) |
| 15 | # 'ShowAns' (asks for answer to be shown -- only available for instructors) |
16 | # 'ShowAns' (asks for answer to be shown -- only available for instructors) |
| 16 | # 'answer$i' (the answers -- if any --provided to the questions) |
17 | # 'answer$i' (the answers -- if any --provided to the questions) |
| 17 | # 'showEdit' (checks if the ShowEditor button should be shown and clicked) |
18 | # 'showEdit' (checks if the ShowEditor button should be shown and clicked) |
| 18 | # 'showSol' (checks if the solution button ishould be shown and clicked) |
19 | # 'showSol' (checks if the solution button ishould be shown and clicked) |
| 19 | # as well as |
20 | # as well as |
| … | |
… | |
| 24 | # 'Submit Answers' or 'Preview Answers' or 'Preview Again' |
25 | # 'Submit Answers' or 'Preview Answers' or 'Preview Again' |
| 25 | # 'probFileName' |
26 | # 'probFileName' |
| 26 | # 'languageType' |
27 | # 'languageType' |
| 27 | |
28 | |
| 28 | use strict; |
29 | use strict; |
| 29 | use lib '/ww/webwork/development/'; # mainWeBWorKDirectory; |
30 | use lib '.'; use webworkInit; # WeBWorKInitLine |
| 30 | |
31 | |
| 31 | use CGI qw(:standard); |
32 | use CGI qw(:standard); |
| 32 | use Net::SMTP; |
33 | use Net::SMTP; |
| 33 | use Global; |
34 | use Global; |
| 34 | use Auth; |
35 | use Auth; |
| … | |
… | |
| 108 | my $previousProbNum = $probNum -1 if defined($probNum); |
109 | my $previousProbNum = $probNum -1 if defined($probNum); |
| 109 | my $mode = "HTML"; |
110 | my $mode = "HTML"; |
| 110 | $mode = $inputs{'Mode'} if defined( $inputs{'Mode'} ); |
111 | $mode = $inputs{'Mode'} if defined( $inputs{'Mode'} ); |
| 111 | $main::display_mode = $mode; # this is only used for the timing messages. |
112 | $main::display_mode = $mode; # this is only used for the timing messages. |
| 112 | my $showEdit = $inputs{'showEdit'}; |
113 | my $showEdit = $inputs{'showEdit'}; |
|
|
114 | my $show_old_answers = 0; |
|
|
115 | $show_old_answers = $inputs{'show_old_answers'} if defined($inputs{'show_old_answers'}); |
| 113 | |
116 | |
| 114 | # verify that information has been received |
117 | # verify that information has been received |
| 115 | unless($Course && $User && $Session_key && $psvn) { |
118 | unless($Course && $User && $Session_key && $psvn) { |
| 116 | my $error_msg = $cgi -> remote_host() . ' ' . |
119 | my $error_msg = $cgi -> remote_host() . ' ' . |
| 117 | $cgi -> user_agent() . ' ' . $cgi -> query_string(); |
120 | $cgi -> user_agent() . ' ' . $cgi -> query_string(); |
| … | |
… | |
| 134 | |
137 | |
| 135 | |
138 | |
| 136 | |
139 | |
| 137 | require "${courseScriptsDirectory}$Global::displayMacros_pl"; |
140 | require "${courseScriptsDirectory}$Global::displayMacros_pl"; |
| 138 | require "${scriptDirectory}$Global::DBglue_pl"; |
141 | require "${scriptDirectory}$Global::DBglue_pl"; |
|
|
142 | require "${scriptDirectory}$Global::classlist_DBglue_pl"; |
| 139 | require "${scriptDirectory}$Global::HTMLglue_pl"; |
143 | require "${scriptDirectory}$Global::HTMLglue_pl"; |
| 140 | require "${scriptDirectory}$Global::FILE_pl"; |
144 | require "${scriptDirectory}$Global::FILE_pl"; |
| 141 | |
145 | |
| 142 | my $permissionsFile = &Global::getCoursePermissionsFile($Course); |
146 | my $permissionsFile = &Global::getCoursePermissionsFile($Course); |
| 143 | my $permissions = &get_permissions($User,$permissionsFile); |
147 | my $permissions = &get_permissions($User,$permissionsFile); |
| … | |
… | |
| 212 | $setNumber = &getSetNumber($psvn); |
216 | $setNumber = &getSetNumber($psvn); |
| 213 | $numberOfProblems = &getAllProblemsForProbSetRecord($psvn); |
217 | $numberOfProblems = &getAllProblemsForProbSetRecord($psvn); |
| 214 | |
218 | |
| 215 | |
219 | |
| 216 | # If answers have not been submitted and previous answers have been saved, patch them in |
220 | # If answers have not been submitted and previous answers have been saved, patch them in |
| 217 | unless ($answers_submitted) { |
221 | # unless $show_old_answers = 0 |
|
|
222 | |
|
|
223 | unless ($answers_submitted or !$show_old_answers) { |
| 218 | my $student_answers = getProblemStudentAnswer($probNum,$psvn); |
224 | my $student_answers = getProblemStudentAnswer($probNum,$psvn); |
| 219 | if (defined $student_answers) { |
225 | if (defined $student_answers) { |
| 220 | my $rh_answer_hash = decode_submitted_answers($student_answers); |
226 | my $rh_answer_hash = decode_submitted_answers($student_answers); |
| 221 | my %answer_hash = %$rh_answer_hash; |
227 | my %answer_hash = %$rh_answer_hash; |
| 222 | my ($label, $value); |
228 | my ($label, $value); |
| … | |
… | |
| 491 | else {#this is the default set by the translator and used if no flag is set. |
497 | else {#this is the default set by the translator and used if no flag is set. |
| 492 | #$pt->rf_problem_grader($pt->rf_std_problem_grader); } |
498 | #$pt->rf_problem_grader($pt->rf_std_problem_grader); } |
| 493 | } |
499 | } |
| 494 | |
500 | |
| 495 | # creates and stores a hash of answer results: $rh_answer_results |
501 | # creates and stores a hash of answer results: $rh_answer_results |
|
|
502 | if ($answers_submitted == 1) { |
| 496 | $pt -> process_answers(\%inputs); |
503 | $pt -> process_answers(\%inputs); |
| 497 | |
504 | } |
| 498 | #################################################################### |
505 | #################################################################### |
| 499 | # If preview mode has been selected, build the preview page and exit |
506 | # If preview mode has been selected, build the preview page and exit |
| 500 | #################################################################### |
507 | #################################################################### |
| 501 | |
508 | |
| 502 | if (($preview_mode ==1) and ($answers_submitted ==1)) { |
509 | if (($preview_mode ==1) and ($answers_submitted ==1)) { |
| … | |
… | |
| 767 | |
774 | |
| 768 | ############# print hidden information about problem and set |
775 | ############# print hidden information about problem and set |
| 769 | |
776 | |
| 770 | print $cgi -> hidden( -name => 'probNum', -value => $probNum ), "\n\t", |
777 | print $cgi -> hidden( -name => 'probNum', -value => $probNum ), "\n\t", |
| 771 | $cgi -> hidden( -name => 'probSetKey', -value => $psvn ), "\n\t", |
778 | $cgi -> hidden( -name => 'probSetKey', -value => $psvn ), "\n\t", |
|
|
779 | $cgi->hidden( -name=>'show_old_answers', -value=>$show_old_answers), "\n\t", |
| 772 | $cgi -> hidden( -name => 'answer_form_submitted', -value => 1 ); # alerts the problem to show answers. |
780 | $cgi -> hidden( -name => 'answer_form_submitted', -value => 1 ); # alerts the problem to show answers. |
| 773 | |
781 | |
| 774 | #sessionKeyInputs() in scripts/HTMLglue.pl |
782 | #sessionKeyInputs() in scripts/HTMLglue.pl |
| 775 | print &sessionKeyInputs(\%inputs), |
783 | print &sessionKeyInputs(\%inputs), |
| 776 | "<BR>", |
784 | "<BR>", |
| … | |
… | |
| 1081 | <TABLE><TR><TD ALIGN=CENTER VALIGN=MIDDLE> |
1089 | <TABLE><TR><TD ALIGN=CENTER VALIGN=MIDDLE> |
| 1082 | }; |
1090 | }; |
| 1083 | |
1091 | |
| 1084 | unless($previousProbNum <= 0) { |
1092 | unless($previousProbNum <= 0) { |
| 1085 | $navigation_bar .= $cgi->startform(-method=>'POST', -action=>"$Global::processProblem_CGI"). "\n". |
1093 | $navigation_bar .= $cgi->startform(-method=>'POST', -action=>"$Global::processProblem_CGI"). "\n". |
| 1086 | $cgi->input({-type=>'IMAGE', -src=>"$Global::previousImgUrl", -alt=>'<--Previous Problem'}). "\n". |
1094 | $cgi->input({-type=>'IMAGE', -src=>"$Global::previousImgUrl", -alt=>'<--Previous Problem'}). "\n". |
| 1087 | $cgi->hidden(-name=>'probSetKey', -value=>"$inputs{probSetKey}"). "\n". |
1095 | $cgi->hidden(-name=>'probSetKey', -value=>"$inputs{probSetKey}"). "\n". |
| 1088 | $cgi->hidden(-name=>'probNum', -value=>"$previousProbNum", -override=>1). "\n". |
1096 | $cgi->hidden(-name=>'probNum', -value=>"$previousProbNum", -override=>1). "\n". |
| 1089 | $cgi->hidden(-name=>'Mode', -value=>"$inputs{Mode}"). "\n". |
1097 | $cgi->hidden(-name=>'Mode', -value=>"$inputs{Mode}"). "\n". |
|
|
1098 | $cgi->hidden(-name=>'show_old_answers', -value=>$show_old_answers). "\n". |
| 1090 | $cgi->hidden(-name=>'user', -value=>"$inputs{user}"). "\n". |
1099 | $cgi->hidden(-name=>'user', -value=>"$inputs{user}"). "\n". |
| 1091 | $cgi->hidden(-name=>'key', -value=>"$inputs{key}"). "\n". |
1100 | $cgi->hidden(-name=>'key', -value=>"$inputs{key}"). "\n". |
| 1092 | $cgi->hidden(-name=>'course', -value=>"$inputs{course}"). "\n". |
1101 | $cgi->hidden(-name=>'course', -value=>"$inputs{course}"). "\n". |
| 1093 | $cgi->endform(). "\n"; |
1102 | $cgi->endform(). "\n"; |
| 1094 | |
1103 | |
| 1095 | # $navigation_bar .= qq{ |
1104 | # $navigation_bar .= qq{ |
| 1096 | # <A HREF="$Global::processProblem_CGI?probSetKey=$inputs{'probSetKey'}&probNum=$previousProbNum&Mode=$inputs{'Mode'}&course=$inputs{'course'}&user=$inputs{'user'}&key=$inputs{'key'}"> |
1105 | # <A HREF="$Global::processProblem_CGI?probSetKey=$inputs{'probSetKey'}&probNum=$previousProbNum&Mode=$inputs{'Mode'}&course=$inputs{'course'}&user=$inputs{'user'}&key=$inputs{'key'}"> |
| 1097 | # <IMG SRC="$Global::previousImgUrl" ALT="<--Previous Problem"></A> |
1106 | # <IMG SRC="$Global::previousImgUrl" ALT="<--Previous Problem"></A> |
| 1098 | # }; |
1107 | # }; |
| … | |
… | |
| 1123 | <TD ALIGN=CENTER VALIGN=MIDDLE> |
1132 | <TD ALIGN=CENTER VALIGN=MIDDLE> |
| 1124 | }; |
1133 | }; |
| 1125 | |
1134 | |
| 1126 | unless($nextProbNum > $numberOfProblems) { |
1135 | unless($nextProbNum > $numberOfProblems) { |
| 1127 | |
1136 | |
| 1128 | $navigation_bar .= $cgi->startform(-method=>'POST', -action=>"$Global::processProblem_CGI"). "\n". |
1137 | $navigation_bar .= $cgi->startform(-method=>'POST', -action=>"$Global::processProblem_CGI"). "\n". |
| 1129 | $cgi->input({-type=>'IMAGE', -src=>"$Global::nextImgUrl", -alt=>'Next Problem-->'}). "\n". |
1138 | $cgi->input({-type=>'IMAGE', -src=>"$Global::nextImgUrl", -alt=>'Next Problem-->'}). "\n". |
| 1130 | $cgi->hidden(-name=>'probSetKey', -value=>"$inputs{probSetKey}"). "\n". |
1139 | $cgi->hidden(-name=>'probSetKey', -value=>"$inputs{probSetKey}"). "\n". |
| 1131 | $cgi->hidden(-name=>'probNum', -value=>"$nextProbNum", -override=>1). "\n". |
1140 | $cgi->hidden(-name=>'probNum', -value=>"$nextProbNum", -override=>1). "\n". |
| 1132 | $cgi->hidden(-name=>'Mode', -value=>"$inputs{Mode}"). "\n". |
1141 | $cgi->hidden(-name=>'Mode', -value=>"$inputs{Mode}"). "\n". |
|
|
1142 | $cgi->hidden(-name=>'show_old_answers', -value=>$show_old_answers). "\n". |
| 1133 | $cgi->hidden(-name=>'user', -value=>"$inputs{user}"). "\n". |
1143 | $cgi->hidden(-name=>'user', -value=>"$inputs{user}"). "\n". |
| 1134 | $cgi->hidden(-name=>'key', -value=>"$inputs{key}"). "\n". |
1144 | $cgi->hidden(-name=>'key', -value=>"$inputs{key}"). "\n". |
| 1135 | $cgi->hidden(-name=>'course', -value=>"$inputs{course}"). "\n". |
1145 | $cgi->hidden(-name=>'course', -value=>"$inputs{course}"). "\n". |
| 1136 | $cgi->endform(). "\n"; |
1146 | $cgi->endform(). "\n"; |
| 1137 | |
1147 | |
| 1138 | # $navigation_bar .= qq{ |
1148 | # $navigation_bar .= qq{ |
| 1139 | # <A HREF="$Global::processProblem_CGI?probSetKey=$inputs{'probSetKey'}&probNum=$nextProbNum&Mode=$inputs{'Mode'}&course=$inputs{'course'}&user=$inputs{'user'}&key=$inputs{'key'}"> |
1149 | # <A HREF="$Global::processProblem_CGI?probSetKey=$inputs{'probSetKey'}&probNum=$nextProbNum&Mode=$inputs{'Mode'}&course=$inputs{'course'}&user=$inputs{'user'}&key=$inputs{'key'}"> |
| 1140 | # <IMG SRC="$Global::nextImgUrl" ALT="Next Problem-->"></A> |
1150 | # <IMG SRC="$Global::nextImgUrl" ALT="Next Problem-->"></A> |
| 1141 | # }; |
1151 | # }; |
| … | |
… | |
| 1175 | $navigation_bar .= $cgi->startform(-method=>'POST', -action=>"$Global::processProblem_CGI"). "\n". |
1185 | $navigation_bar .= $cgi->startform(-method=>'POST', -action=>"$Global::processProblem_CGI"). "\n". |
| 1176 | $cgi->input({-type=>'IMAGE', -src=>"$Global::currentImgUrl", -alt=>'Current Problem'}). "\n". |
1186 | $cgi->input({-type=>'IMAGE', -src=>"$Global::currentImgUrl", -alt=>'Current Problem'}). "\n". |
| 1177 | $cgi->hidden(-name=>'probSetKey', -value=>"$inputs{probSetKey}"). "\n". |
1187 | $cgi->hidden(-name=>'probSetKey', -value=>"$inputs{probSetKey}"). "\n". |
| 1178 | $cgi->hidden(-name=>'probNum', -value=>"$curentProbNum", -override=>1). "\n". |
1188 | $cgi->hidden(-name=>'probNum', -value=>"$curentProbNum", -override=>1). "\n". |
| 1179 | $cgi->hidden(-name=>'Mode', -value=>"$inputs{Mode}"). "\n". |
1189 | $cgi->hidden(-name=>'Mode', -value=>"$inputs{Mode}"). "\n". |
|
|
1190 | $cgi->hidden(-name=>'show_old_answers', -value=>$show_old_answers). "\n". |
| 1180 | $cgi->hidden(-name=>'user', -value=>"$inputs{user}"). "\n". |
1191 | $cgi->hidden(-name=>'user', -value=>"$inputs{user}"). "\n". |
| 1181 | $cgi->hidden(-name=>'key', -value=>"$inputs{key}"). "\n". |
1192 | $cgi->hidden(-name=>'key', -value=>"$inputs{key}"). "\n". |
| 1182 | $cgi->hidden(-name=>'course', -value=>"$inputs{course}"). "\n". |
1193 | $cgi->hidden(-name=>'course', -value=>"$inputs{course}"). "\n". |
| 1183 | $cgi->endform(). "\n"; |
1194 | $cgi->endform(). "\n"; |
| 1184 | |
1195 | |
| … | |
… | |
| 1344 | $s = ''; |
1355 | $s = ''; |
| 1345 | if( $expected_answer_count > 1) {$s = 's'; } |
1356 | if( $expected_answer_count > 1) {$s = 's'; } |
| 1346 | print $cgi -> hidden(-name=>'probNum', -value=>$probNum), |
1357 | print $cgi -> hidden(-name=>'probNum', -value=>$probNum), |
| 1347 | $cgi -> hidden(-name=>'probSetKey', -value=>$psvn), |
1358 | $cgi -> hidden(-name=>'probSetKey', -value=>$psvn), |
| 1348 | $cgi -> hidden(-name=>'answer_form_submitted', -value=>1), # alerts the problem to show answers. |
1359 | $cgi -> hidden(-name=>'answer_form_submitted', -value=>1), # alerts the problem to show answers. |
| 1349 | $cgi -> hidden(-name=>'Mode', -value=>$mode); |
1360 | $cgi -> hidden(-name=>'Mode', -value=>$mode); |
| 1350 | |
1361 | $cgi -> hidden(-name=>'show_old_answers', -value=>$show_old_answers); |
| 1351 | print &sessionKeyInputs(\%inputs), |
1362 | print &sessionKeyInputs(\%inputs), |
| 1352 | '<BR>', |
1363 | '<BR>', |
| 1353 | $cgi -> submit( -name => 'action', -value=>"Submit Answer$s" ),' ', |
1364 | $cgi -> submit( -name => 'action', -value=>"Submit Answer$s" ),' ', |
| 1354 | $cgi -> submit( -name => 'action', -value=>"Preview Again" ),"\n"; |
1365 | $cgi -> submit( -name => 'action', -value=>"Preview Again" ),"\n"; |
| 1355 | |
1366 | |
| … | |
… | |
| 1415 | } |
1426 | } |
| 1416 | |
1427 | |
| 1417 | sub defineProblemEnvir { |
1428 | sub defineProblemEnvir { |
| 1418 | my ($mode,$probNum,$psvn,$courseName) = @_; |
1429 | my ($mode,$probNum,$psvn,$courseName) = @_; |
| 1419 | my %envir=(); |
1430 | my %envir=(); |
|
|
1431 | my $loginName = &getStudentLogin($psvn); |
| 1420 | ##how to put an array submittedAnswers in a hash?? |
1432 | ##how to put an array submittedAnswers in a hash?? |
| 1421 | # $envir{'refSubmittedAnswers'} = $refSubmittedAnswers if defined($refSubmittedAnswers); |
1433 | # $envir{'refSubmittedAnswers'} = $refSubmittedAnswers if defined($refSubmittedAnswers); |
| 1422 | $envir{'psvnNumber'} = $psvn; |
1434 | $envir{'psvnNumber'} = $psvn; |
| 1423 | $envir{'psvn'} = $psvn; |
1435 | $envir{'psvn'} = $psvn; |
| 1424 | $envir{'studentName'} = &getStudentName($psvn); |
1436 | $envir{'studentName'} = &CL_getStudentName($loginName); |
| 1425 | $envir{'studentLogin'} = &getStudentLogin($psvn); |
1437 | $envir{'studentLogin'} = &getStudentLogin($psvn); |
| 1426 | $envir{'sectionName'} = &getClassSection($psvn); |
1438 | $envir{'sectionName'} = &CL_getClassSection($loginName); |
| 1427 | $envir{'sectionNumber'} = &getClassSection($psvn); |
1439 | $envir{'sectionNumber'} = &CL_getClassSection($loginName); |
| 1428 | $envir{'recitationName'} = &getClassRecitation($psvn); |
1440 | $envir{'recitationName'} = &CL_getClassRecitation($loginName); |
| 1429 | $envir{'recitationNumber'} = &getClassRecitation($psvn); |
1441 | $envir{'recitationNumber'} = &CL_getClassRecitation($loginName); |
| 1430 | $envir{'setNumber'} = &getSetNumber($psvn); |
1442 | $envir{'setNumber'} = &getSetNumber($psvn); |
| 1431 | $envir{'questionNumber'} = $probNum; |
1443 | $envir{'questionNumber'} = $probNum; |
| 1432 | $envir{'probNum'} = $probNum; |
1444 | $envir{'probNum'} = $probNum; |
| 1433 | $envir{'openDate'} = &getOpenDate($psvn); |
1445 | $envir{'openDate'} = &getOpenDate($psvn); |
| 1434 | $envir{'formattedOpenDate'} = &formatDateAndTime(&getOpenDate($psvn)); |
1446 | $envir{'formattedOpenDate'} = &formatDateAndTime(&getOpenDate($psvn)); |