| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Problem.pm,v 1.142 2004/06/04 23:21:48 jj Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Problem.pm,v 1.143 2004/06/08 17:07:25 toenail Exp $ |
| 5 | # |
5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify it under |
6 | # This program is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of either: (a) the GNU General Public License as published by the |
7 | # the terms of either: (a) the GNU General Public License as published by the |
| 8 | # Free Software Foundation; either version 2, or (at your option) any later |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
| 9 | # version, or (b) the "Artistic License" which comes with this package. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
| … | |
… | |
| 68 | sub pre_header_initialize { |
68 | sub pre_header_initialize { |
| 69 | my ($self) = @_; |
69 | my ($self) = @_; |
| 70 | my $r = $self->r; |
70 | my $r = $self->r; |
| 71 | my $ce = $r->ce; |
71 | my $ce = $r->ce; |
| 72 | my $db = $r->db; |
72 | my $db = $r->db; |
|
|
73 | my $authz = $r->authz; |
| 73 | my $urlpath = $r->urlpath; |
74 | my $urlpath = $r->urlpath; |
| 74 | |
75 | |
| 75 | my $setName = $urlpath->arg("setID"); |
76 | my $setName = $urlpath->arg("setID"); |
| 76 | my $problemNumber = $r->urlpath->arg("problemID"); |
77 | my $problemNumber = $r->urlpath->arg("problemID"); |
| 77 | my $userName = $r->param('user'); |
78 | my $userName = $r->param('user'); |
| … | |
… | |
| 97 | # obtain the merged problem for $effectiveUser |
98 | # obtain the merged problem for $effectiveUser |
| 98 | my $problem = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked |
99 | my $problem = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked |
| 99 | |
100 | |
| 100 | my $editMode = $r->param("editMode"); |
101 | my $editMode = $r->param("editMode"); |
| 101 | |
102 | |
| 102 | if ($permissionLevel > 0) { |
103 | if ($authz->hasPermissions($userName, "modify_problem_sets")) { |
| 103 | # professors are allowed to fabricate sets and problems not |
104 | # professors are allowed to fabricate sets and problems not |
| 104 | # assigned to them (or anyone). this allows them to use the |
105 | # assigned to them (or anyone). this allows them to use the |
| 105 | # editor to |
106 | # editor to |
| 106 | |
107 | |
| 107 | # if that is not yet defined obtain the global set, convert |
108 | # if that is not yet defined obtain the global set, convert |
| … | |
… | |
| 172 | my $publishedClass = ($set->published) ? "Published" : "Unpublished"; |
173 | my $publishedClass = ($set->published) ? "Published" : "Unpublished"; |
| 173 | my $publishedText = ($set->published) ? "visible to students." : "hidden from students."; |
174 | my $publishedText = ($set->published) ? "visible to students." : "hidden from students."; |
| 174 | $self->addmessage(CGI::p("This set is " . CGI::font({class=>$publishedClass}, $publishedText))); |
175 | $self->addmessage(CGI::p("This set is " . CGI::font({class=>$publishedClass}, $publishedText))); |
| 175 | } else { |
176 | } else { |
| 176 | |
177 | |
| 177 | $self->addmessage(CGI::div({class=>"ResultsWithError"}, CGI::p("This problem will not count towards your grade."))) unless $problem->value;; |
|
|
| 178 | # students can't view problems not assigned to them |
178 | # students can't view problems not assigned to them |
| 179 | |
179 | |
| 180 | # A set is valid if it exists and if it is either published or the user is privileged. |
180 | # A set is valid if it exists and if it is either published or the user is privileged. |
| 181 | $self->{invalidSet} = (grep /$setName/, $db->listUserSets($effectiveUserName)) == 0 || !($set->published || $permissionLevel->permission > 0); # this is redundant because of the above if |
181 | $self->{invalidSet} = (grep /$setName/, $db->listUserSets($effectiveUserName)) == 0 || !($set->published || $authz->hasPermissions($userName, "access_instructor_tools")); |
| 182 | $self->{invalidProblem} = (grep /$problemNumber/, $db->listUserProblems($effectiveUserName, $setName)) == 0 || !($set->published || $permissionLevel->permission > 0);; |
182 | $self->{invalidProblem} = (grep /$problemNumber/, $db->listUserProblems($effectiveUserName, $setName)) == 0 || !($set->published || $authz->hasPermissions($userName, "access_instructor_tools")); |
|
|
183 | |
|
|
184 | $self->addbadmessage(CGI::p("This problem will not count towards your grade.")) if $problem and not $problem->value;; |
| 183 | |
185 | |
| 184 | } |
186 | } |
| 185 | |
187 | |
| 186 | $self->{userName} = $userName; |
188 | $self->{userName} = $userName; |
| 187 | $self->{effectiveUserName} = $effectiveUserName; |
189 | $self->{effectiveUserName} = $effectiveUserName; |
| … | |
… | |
| 497 | sub body { |
499 | sub body { |
| 498 | my $self = shift; |
500 | my $self = shift; |
| 499 | my $r = $self->r; |
501 | my $r = $self->r; |
| 500 | my $ce = $r->ce; |
502 | my $ce = $r->ce; |
| 501 | my $db = $r->db; |
503 | my $db = $r->db; |
|
|
504 | my $authz = $r->authz; |
| 502 | my $urlpath = $r->urlpath; |
505 | my $urlpath = $r->urlpath; |
|
|
506 | my $user = $r->param('user'); |
| 503 | |
507 | |
| 504 | if ($self->{invalidSet}) { |
508 | if ($self->{invalidSet}) { |
| 505 | return CGI::div({class=>"ResultsWithError"}, |
509 | return CGI::div({class=>"ResultsWithError"}, |
| 506 | CGI::p("The selected problem set (" . $urlpath->arg("setID") . ") is not a valid set for " . $r->param("effectiveUser") . ".")); |
510 | CGI::p("The selected problem set (" . $urlpath->arg("setID") . ") is not a valid set for " . $r->param("effectiveUser") . ".")); |
| 507 | } |
511 | } |
| … | |
… | |
| 669 | ##### output ##### |
673 | ##### output ##### |
| 670 | |
674 | |
| 671 | print CGI::start_div({class=>"problemHeader"}); |
675 | print CGI::start_div({class=>"problemHeader"}); |
| 672 | |
676 | |
| 673 | # custom message for editor |
677 | # custom message for editor |
| 674 | if ($permissionLevel >= 10 and defined $editMode) { |
678 | if ($authz->hasPermissions($user, "modify_problem_sets") and defined $editMode) { |
| 675 | if ($editMode eq "temporaryFile") { |
679 | if ($editMode eq "temporaryFile") { |
| 676 | print CGI::p(CGI::i("Editing temporary file: ", $problem->source_file)); |
680 | print CGI::p(CGI::i("Editing temporary file: ", $problem->source_file)); |
| 677 | } elsif ($editMode eq "savedFile") { |
681 | } elsif ($editMode eq "savedFile") { |
| 678 | # FIXME: this is all done automatically if submitError exists. |
682 | # taken care of in the initialization phase |
| 679 | #if ( defined($r->param('submiterror')) and $r->param('submiterror') ) { |
|
|
| 680 | # FIXME The following line doesn't work because the submiterror hook has already been called. |
|
|
| 681 | # The actions below should take place during the initialization phase. |
|
|
| 682 | # $self->{submiterror} .= $r->param('submiterror'); |
|
|
| 683 | # print CGI::p(CGI::div({class=>'ResultsWithError'},$self->{submiterror})); |
|
|
| 684 | #} else { |
|
|
| 685 | # print CGI::p(CGI::div({ class=>'ResultsWithoutError'}, "Problem saved to: ", $problem->source_file)); |
|
|
| 686 | #} |
|
|
| 687 | } |
683 | } |
| 688 | } |
684 | } |
| 689 | #FIXME we need error messages here if the problem was really not saved. |
685 | |
| 690 | # attempt summary |
686 | # attempt summary |
| 691 | #FIXME -- the following is a kludge: if showPartialCorrectAnswers is negative don't show anything. |
687 | #FIXME -- the following is a kludge: if showPartialCorrectAnswers is negative don't show anything. |
| 692 | # until after the due date |
688 | # until after the due date |
| 693 | # do I need to check $wills{howCorrectAnswers} to make preflight work?? |
689 | # do I need to check $wills{howCorrectAnswers} to make preflight work?? |
| 694 | if (($pg->{flags}->{showPartialCorrectAnswers}>= 0 and $submitAnswers) ) { |
690 | if (($pg->{flags}->{showPartialCorrectAnswers}>= 0 and $submitAnswers) ) { |
| … | |
… | |
| 1155 | |
1151 | |
| 1156 | sub mustRecordAnswers($) { |
1152 | sub mustRecordAnswers($) { |
| 1157 | my ($permissionLevel) = @_; |
1153 | my ($permissionLevel) = @_; |
| 1158 | return $permissionLevel == 0; |
1154 | return $permissionLevel == 0; |
| 1159 | } |
1155 | } |
| 1160 | |
|
|
| 1161 | |
|
|
| 1162 | # FIXME: does this even get used? |
|
|
| 1163 | sub submiterror { |
|
|
| 1164 | my $self = shift; |
|
|
| 1165 | my $submiterror = (defined($self->{submiterror}) ) ? $self->{submiterror} : ''; |
|
|
| 1166 | $submiterror; |
|
|
| 1167 | } |
|
|
| 1168 | 1; |
1156 | 1; |