| … | |
… | |
| 51 | $viewURL .= $self->url_authen_args; |
51 | $viewURL .= $self->url_authen_args; |
| 52 | $viewURL .= "&displayMode=$displayMode&problemSeed=$problemSeed"; # optional displayMode and problemSeed overrides |
52 | $viewURL .= "&displayMode=$displayMode&problemSeed=$problemSeed"; # optional displayMode and problemSeed overrides |
| 53 | $viewURL .= "&editMode=temporaryFile"; |
53 | $viewURL .= "&editMode=temporaryFile"; |
| 54 | $viewURL .= '&sourceFilePath='. $self->{currentSourceFilePath}; # path to pg text for viewing |
54 | $viewURL .= '&sourceFilePath='. $self->{currentSourceFilePath}; # path to pg text for viewing |
| 55 | $viewURL .= "&submit_button=$submit_button"; # allows Problem.pg to recognize state |
55 | $viewURL .= "&submit_button=$submit_button"; # allows Problem.pg to recognize state |
| 56 | $viewURL .= '&editErrors='.$self->{editErrors}; # of problem being viewed. |
56 | # $viewURL .= '&editErrors='.$self->{editErrors}; # of problem being viewed. |
| 57 | $r->header_out(Location => $viewURL ); |
57 | $r->header_out(Location => $viewURL ); |
| 58 | return REDIRECT; |
58 | return REDIRECT; |
| 59 | } else { |
59 | } else { |
| 60 | # initialize and |
60 | # initialize and |
| 61 | # display the editing window |
61 | # display the editing window |
| … | |
… | |
| 75 | my $user = $r->param('user'); |
75 | my $user = $r->param('user'); |
| 76 | my $effectiveUserName = $r->param('effectiveUser'); |
76 | my $effectiveUserName = $r->param('effectiveUser'); |
| 77 | my $courseName = $ce->{courseName}; |
77 | my $courseName = $ce->{courseName}; |
| 78 | |
78 | |
| 79 | # FIXME -- sometimes this doesn't find a set |
79 | # FIXME -- sometimes this doesn't find a set |
| 80 | # my $set = $db->getGlobalUserSet($effectiveUserName, $setName); |
80 | # my $set = $db->getMergedSet($effectiveUserName, $setName); |
| 81 | # my $setID = $set->set_id; |
81 | # my $setID = $set->set_id; |
| 82 | |
82 | |
| 83 | # Find URL for viewing problem |
83 | # Find URL for viewing problem |
| 84 | |
84 | |
| 85 | # find path to pg file for the problem |
85 | # find path to pg file for the problem |
| 86 | # FIXME there is a discrepancy in the way that the problems are found. |
86 | # FIXME there is a discrepancy in the way that the problems are found. |
| 87 | # FIXME more error checking is needed in case the problem doesn't exist. |
87 | # FIXME more error checking is needed in case the problem doesn't exist. |
| 88 | # my $problem_record = $db->getUserProblem($user,$setID,1); |
88 | # my $problem_record = $db->getUserProblem($user,$setID,1); |
| 89 | my $problem_record = $db->getGlobalUserProblem($effectiveUserName, $setName, $problemNumber); |
89 | my $problem_record = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); |
| 90 | # If there is no global_user defined problem, (i.e. the sets haven't been assigned yet), then look for a global version of the problem. |
90 | # If there is no global_user defined problem, (i.e. the sets haven't been assigned yet), then look for a global version of the problem. |
| 91 | $problem_record = $db->getGlobalProblem($setName, $problemNumber) unless defined($problem_record); |
91 | $problem_record = $db->getGlobalProblem($setName, $problemNumber) unless defined($problem_record); |
| 92 | die "Cannot find a problem record for set $setName / problem $problemNumber" |
92 | die "Cannot find a problem record for set $setName / problem $problemNumber" |
| 93 | unless defined($problem_record); |
93 | unless defined($problem_record); |
| 94 | my $templateDirectory = $ce->{courseDirs}->{templates}; |
94 | my $templateDirectory = $ce->{courseDirs}->{templates}; |
| … | |
… | |
| 157 | print OUTPUTFILE $problemContents; |
157 | print OUTPUTFILE $problemContents; |
| 158 | close OUTPUTFILE; |
158 | close OUTPUTFILE; |
| 159 | }; |
159 | }; |
| 160 | # record an error string for later use if there was a difficulty in writing to the file |
160 | # record an error string for later use if there was a difficulty in writing to the file |
| 161 | # FIXME is this string every inspected? |
161 | # FIXME is this string every inspected? |
| 162 | $editErrors .= $@ if $@; |
162 | |
|
|
163 | my $openTempFileErrors = $@ if $@; |
|
|
164 | |
| 163 | if ( $editErrors) { |
165 | if ( $openTempFileErrors) { |
| 164 | |
166 | |
| 165 | $self->{editErrors} = "Unable to write to $currentSourceFilePath: $editErrors"; |
167 | $self->{openTempFileErrors} = "Unable to write to $currentSourceFilePath: $openTempFileErrors"; |
| 166 | #diagnose errors: |
168 | #diagnose errors: |
| 167 | warn "Editing errors: $editErrors\n"; |
169 | warn "Editing errors: $openTempFileErrors\n"; |
| 168 | warn "The file $currentSourceFilePath exists. \n " if -e $currentSourceFilePath; |
170 | warn "The file $currentSourceFilePath exists. \n " if -e $currentSourceFilePath; #FIXME |
| 169 | warn "The file $currentSourceFilePath cannot be found. \n " unless -e $currentSourceFilePath; |
171 | warn "The file $currentSourceFilePath cannot be found. \n " unless -e $currentSourceFilePath; |
| 170 | warn "The file $currentSourceFilePath does not have write permissions. \n" |
172 | warn "The file $currentSourceFilePath does not have write permissions. \n" |
| 171 | if -e $currentSourceFilePath and not -w $currentSourceFilePath; |
173 | if -e $currentSourceFilePath and not -w $currentSourceFilePath; |
| 172 | |
174 | |
| 173 | |
175 | |
| 174 | |
176 | |
| 175 | } else { |
177 | } else { |
| 176 | # unlink the temporary file if there are no errors and the save button has been pushed |
178 | # unlink the temporary file if there are no errors and the save button has been pushed |
| 177 | |
179 | |
| 178 | $self->{editErrors} = ''; |
180 | $self->{openTempFileErrors} = ''; |
| 179 | unlink("$problemPath.$editFileSuffix") if defined($submit_button) and $submit_button eq 'Save'; |
181 | unlink("$problemPath.$editFileSuffix") if defined($submit_button) and $submit_button eq 'Save'; |
| 180 | }; |
182 | }; |
| 181 | |
183 | |
| 182 | |
184 | |
| 183 | # return values for use in the body subroutine |
185 | # return values for use in the body subroutine |
| … | |
… | |
| 247 | #FIXME |
249 | #FIXME |
| 248 | |
250 | |
| 249 | ######################################################################### |
251 | ######################################################################### |
| 250 | |
252 | |
| 251 | |
253 | |
| 252 | |
254 | warn "Errors in the problem ".$self->{editErrors} if $self->{editErrors}; |
| 253 | |
255 | |
| 254 | |
256 | |
| 255 | return CGI::p($header), |
257 | return CGI::p($header), |
| 256 | #CGI::start_form("POST",$r->uri,-target=>'_problem'), doesn't pass on the target parameter??? |
258 | #CGI::start_form("POST",$r->uri,-target=>'_problem'), doesn't pass on the target parameter??? |
| 257 | qq!<form method="POST" action="$uri" enctype="application/x-www-form-urlencoded", target="_problem">!, |
259 | qq!<form method="POST" action="$uri" enctype="application/x-www-form-urlencoded", target="_problem">!, |