| … | |
… | |
| 19 | our $rowheight; |
19 | our $rowheight; |
| 20 | |
20 | |
| 21 | sub title { |
21 | sub title { |
| 22 | my $self = shift; |
22 | my $self = shift; |
| 23 | #FIXME don't need the entire path ?? |
23 | #FIXME don't need the entire path ?? |
| 24 | return "Instructor Tools - PG Problem Editor for ". $self->{problemPath}; |
24 | return "Instructor Tools - PG Problem Editor "; |
| 25 | } |
25 | } |
| 26 | sub go { |
26 | sub go { |
| 27 | my $self = shift; |
27 | my $self = shift; |
| 28 | my ($setName, $problemNumber) = @_; |
28 | my ($setName, $problemNumber) = @_; |
| 29 | my $r = $self->{r}; |
29 | my $r = $self->{r}; |
| … | |
… | |
| 40 | |
40 | |
| 41 | my $hostname = $r->hostname(); |
41 | my $hostname = $r->hostname(); |
| 42 | my $port = $r->get_server_port(); |
42 | my $port = $r->get_server_port(); |
| 43 | my $uri = $r->uri; |
43 | my $uri = $r->uri; |
| 44 | my $courseName = $self->{ce}->{courseName}; |
44 | my $courseName = $self->{ce}->{courseName}; |
| 45 | my $editFileSuffix = $self->{ce}->{editFileSuffix}; |
|
|
| 46 | my $problemSeed = ($r->param('problemSeed')) ? $r->param('problemSeed') : ''; |
45 | my $problemSeed = ($r->param('problemSeed')) ? $r->param('problemSeed') : ''; |
| 47 | my $displayMode = ($r->param('displayMode')) ? $r->param('displayMode') : ''; |
46 | my $displayMode = ($r->param('displayMode')) ? $r->param('displayMode') : ''; |
| 48 | my $viewURL = ''; |
47 | my $viewURL = ''; |
| 49 | if ($self->{file_type} eq 'problem') { |
48 | if ($self->{file_type} eq 'problem') { |
| 50 | # redirect to have problem read by Problem.pm |
49 | # redirect to have problem read by Problem.pm |
| … | |
… | |
| 56 | $viewURL .= "&editMode=savedFile"; |
55 | $viewURL .= "&editMode=savedFile"; |
| 57 | } else { |
56 | } else { |
| 58 | $viewURL .= "&editMode=temporaryFile"; |
57 | $viewURL .= "&editMode=temporaryFile"; |
| 59 | } |
58 | } |
| 60 | $viewURL .= '&sourceFilePath='. $self->{currentSourceFilePath}; # path to pg text for viewing |
59 | $viewURL .= '&sourceFilePath='. $self->{currentSourceFilePath}; # path to pg text for viewing |
| 61 | #$viewURL .= "&submit_button=$submit_button"; # allows Problem.pg to recognize state |
60 | # allows Problem.pg to recognize state |
| 62 | # $viewURL .= '&editErrors='.$self->{editErrors}; |
|
|
| 63 | # of problem being viewed. |
61 | # of problem being viewed. |
| 64 | } elsif ($self->{file_type} eq 'set_header') { |
62 | } elsif ($self->{file_type} eq 'set_header') { |
| 65 | # redirect set headers to ProblemList page |
63 | # redirect set headers to ProblemList page |
| 66 | $viewURL = "http://$hostname:$port"; |
64 | $viewURL = "http://$hostname:$port"; |
| 67 | $viewURL .= $ce->{webworkURLs}->{root}."/$courseName/$setName/?"; |
65 | $viewURL .= $ce->{webworkURLs}->{root}."/$courseName/$setName/?"; |
| 68 | $viewURL .= $self->url_authen_args; |
66 | $viewURL .= $self->url_authen_args; |
| … | |
… | |
| 91 | my $db = $self->{db}; |
89 | my $db = $self->{db}; |
| 92 | my $user = $r->param('user'); |
90 | my $user = $r->param('user'); |
| 93 | my $effectiveUserName = $r->param('effectiveUser'); |
91 | my $effectiveUserName = $r->param('effectiveUser'); |
| 94 | my $courseName = $ce->{courseName}; |
92 | my $courseName = $ce->{courseName}; |
| 95 | |
93 | |
| 96 | # FIXME -- sometimes this doesn't find a set |
|
|
| 97 | # my $set = $db->getMergedSet($effectiveUserName, $setName); |
|
|
| 98 | # my $setID = $set->set_id; |
|
|
| 99 | |
94 | |
| 100 | # Find URL for viewing problem |
95 | # Find URL for viewing problem |
| 101 | |
96 | |
| 102 | # find path to pg file for the problem |
97 | # find path to pg file for the problem |
| 103 | |
98 | |
| … | |
… | |
| 121 | die "Cannot find a set record for set $setName" unless defined($set_record); |
116 | die "Cannot find a set record for set $setName" unless defined($set_record); |
| 122 | $problemPath .= '/'.$set_record->set_header; |
117 | $problemPath .= '/'.$set_record->set_header; |
| 123 | $self->{file_type} = 'set_header'; |
118 | $self->{file_type} = 'set_header'; |
| 124 | } |
119 | } |
| 125 | |
120 | |
| 126 | my $editFileSuffix = 'tmp'; |
121 | my $editFileSuffix = $user.'.tmp'; |
| 127 | my $submit_button = $r->param('submit'); |
122 | my $submit_button = $r->param('submit'); |
| 128 | |
123 | |
| 129 | my $displayMode = ( defined($r->param('displayMode')) ) ? $r->param('displayMode') : $ce->{pg}->{options}->{displayMode}; |
124 | my $displayMode = ( defined($r->param('displayMode')) ) ? $r->param('displayMode') : $ce->{pg}->{options}->{displayMode}; |
| 130 | # try to get problem seed from the input parameter, or from the problem record |
125 | # try to get problem seed from the input parameter, or from the problem record |
| 131 | my $problemSeed; |
126 | my $problemSeed; |
| … | |
… | |
| 137 | # make absolutely sure that the problem seed is defined, if it hasn't been. |
132 | # make absolutely sure that the problem seed is defined, if it hasn't been. |
| 138 | $problemSeed = '123456' unless defined($problemSeed) and $problemSeed =~/\S/; |
133 | $problemSeed = '123456' unless defined($problemSeed) and $problemSeed =~/\S/; |
| 139 | |
134 | |
| 140 | my $problemContents = ''; |
135 | my $problemContents = ''; |
| 141 | my $currentSourceFilePath = ''; |
136 | my $currentSourceFilePath = ''; |
| 142 | my $editErrors = ''; |
137 | my $editErrors = ''; |
|
|
138 | |
| 143 | # update the .pg and .pg.tmp files in the directory |
139 | # update the .pg and .pg.tmp files in the directory |
| 144 | if (not defined($submit_button) ) { |
140 | # if a .tmp file already exists use that, unless the revert button has been pressed. |
|
|
141 | # These .tmp files are |
|
|
142 | # removed when the file is finally saved. |
|
|
143 | my $inputFilePath = (-r "$problemPath.$editFileSuffix")?"$problemPath.$editFileSuffix" : $problemPath; |
|
|
144 | $inputFilePath = $problemPath if defined($submit_button) and $submit_button eq 'Revert'; |
|
|
145 | |
|
|
146 | if (not defined($submit_button) or $submit_button eq 'Revert' ) { |
| 145 | # this is a fresh editing job |
147 | # this is a fresh editing job |
| 146 | # copy the pg file to a new file with the same name with .tmp added |
148 | # copy the pg file to a new file with the same name with .tmp added |
| 147 | # store this name in the $self->currentSourceFilePath for use in body |
149 | # store this name in the $self->currentSourceFilePath for use in body |
| 148 | |
|
|
| 149 | eval { $problemContents = WeBWorK::Utils::readFile($problemPath) |
150 | eval { $problemContents = WeBWorK::Utils::readFile($inputFilePath) }; |
| 150 | }; # try to read file |
151 | # try to read file |
| 151 | $problemContents = $@ if $@; |
152 | $problemContents = $@ if $@; |
| 152 | $editErrors .= $problemContents; |
153 | $editErrors .= $problemContents; |
| 153 | $currentSourceFilePath = "$problemPath.$editFileSuffix"; |
154 | $currentSourceFilePath = "$problemPath.$editFileSuffix"; |
| 154 | $self->{currentSourceFilePath} = $currentSourceFilePath; |
155 | $self->{currentSourceFilePath} = $currentSourceFilePath; |
| 155 | } elsif ($submit_button eq 'Refresh' ) { |
156 | } elsif ($submit_button eq 'Refresh' ) { |
| … | |
… | |
| 164 | # later we will unlink (delete) the temporary file |
165 | # later we will unlink (delete) the temporary file |
| 165 | # store permanent file name in the $self->currentSourceFilePath for use in body |
166 | # store permanent file name in the $self->currentSourceFilePath for use in body |
| 166 | |
167 | |
| 167 | $problemContents = $r->param('problemContents'); |
168 | $problemContents = $r->param('problemContents'); |
| 168 | $currentSourceFilePath = "$problemPath"; |
169 | $currentSourceFilePath = "$problemPath"; |
| 169 | $self->{currentSourceFilePath} = $currentSourceFilePath; |
170 | $self->{currentSourceFilePath} = $currentSourceFilePath; |
| 170 | } else { |
171 | } else { |
| 171 | # give a warning |
172 | # give a warning |
| 172 | die "Unrecognized submit command $submit_button"; |
173 | die "Unrecognized submit command $submit_button"; |
| 173 | } |
174 | } |
| 174 | |
175 | |
| … | |
… | |
| 214 | unlink("$problemPath.$editFileSuffix") if defined($submit_button) and $submit_button eq 'Save'; |
215 | unlink("$problemPath.$editFileSuffix") if defined($submit_button) and $submit_button eq 'Save'; |
| 215 | }; |
216 | }; |
| 216 | |
217 | |
| 217 | |
218 | |
| 218 | # return values for use in the body subroutine |
219 | # return values for use in the body subroutine |
| 219 | $self->{problemPath} = $problemPath; |
220 | $self->{problemPath} = $problemPath; |
|
|
221 | $self->{inputFilePath} = $inputFilePath; |
| 220 | $self->{displayMode} = $displayMode; |
222 | $self->{displayMode} = $displayMode; |
| 221 | $self->{problemSeed} = $problemSeed; |
223 | $self->{problemSeed} = $problemSeed; |
| 222 | |
224 | $self->{r_problemContents} = \$problemContents; |
| 223 | # FIXME there is no way to edit in a temporary file -- all editing takes place on disk!!! |
225 | # FIXME there is no way to edit in a temporary file -- all editing takes place on disk!!! |
| 224 | |
226 | |
| 225 | |
227 | |
| 226 | |
228 | |
| 227 | } |
229 | } |
| … | |
… | |
| 238 | return $self->pathMacro($args, |
240 | return $self->pathMacro($args, |
| 239 | "Home" => "$root", |
241 | "Home" => "$root", |
| 240 | $courseName => "$root/$courseName", |
242 | $courseName => "$root/$courseName", |
| 241 | 'instructor' => "$root/$courseName/instructor", |
243 | 'instructor' => "$root/$courseName/instructor", |
| 242 | 'sets' => "$root/$courseName/instructor/sets/", |
244 | 'sets' => "$root/$courseName/instructor/sets/", |
| 243 | "$set_id" => "$root/$courseName/instructor/sets/$set_id/", |
245 | "$set_id" => "$root/$courseName/instructor/sets/$set_id/", |
| 244 | "problems" => "$root/$courseName/instructor/sets/$set_id/problems", |
246 | "problems" => "$root/$courseName/instructor/sets/$set_id/problems", |
| 245 | "$problem_id" => '' |
247 | "$problem_id" => '' |
| 246 | ); |
248 | ); |
| 247 | } |
249 | } |
| 248 | sub body { |
250 | sub body { |
| … | |
… | |
| 260 | # Gathering info |
262 | # Gathering info |
| 261 | # What is needed |
263 | # What is needed |
| 262 | # $problemPath -- |
264 | # $problemPath -- |
| 263 | # $formURL -- given by $r->uri |
265 | # $formURL -- given by $r->uri |
| 264 | # $tmpProblemPath |
266 | # $tmpProblemPath |
| 265 | my $problemPath = $self->{problemPath}; |
267 | my $problemPath = $self->{problemPath}; |
| 266 | |
268 | my $inputFilePath = $self->{inputFilePath}; |
| 267 | |
269 | |
| 268 | |
270 | |
| 269 | |
271 | |
| 270 | |
272 | |
| 271 | |
273 | |
| 272 | |
274 | |
| 273 | my $header = "Editing problem: $problemPath"; |
275 | my $header = CGI::i("Editing problem: $inputFilePath"); |
| 274 | |
276 | |
| 275 | ######################################################################### |
277 | ######################################################################### |
| 276 | # Find the text for the problem, either in the tmp file, if it exists |
278 | # Find the text for the problem, either in the tmp file, if it exists |
| 277 | # or in the original file in the template directory |
279 | # or in the original file in the template directory |
| 278 | ######################################################################### |
280 | ######################################################################### |
| 279 | my $problemContents = ''; |
281 | my $problemContents = ${$self->{r_problemContents}}; |
| 280 | |
282 | |
| 281 | eval { $problemContents = WeBWorK::Utils::readFile($problemPath) }; # try to read file |
283 | # eval { $problemContents = WeBWorK::Utils::readFile($problemPath) }; # try to read file |
| 282 | $problemContents = $@ if $@; |
284 | # $problemContents = $@ if $@; |
| 283 | |
285 | |
| 284 | |
286 | |
| 285 | |
287 | |
| 286 | ######################################################################### |
288 | ######################################################################### |
| 287 | # Format the page |
289 | # Format the page |
| … | |
… | |
| 328 | ), |
330 | ), |
| 329 | ), |
331 | ), |
| 330 | CGI::p( |
332 | CGI::p( |
| 331 | ( ($self->{file_type} eq 'problem') ? CGI::submit(-value=>'Refresh',-name=>'submit') : '' ), |
333 | ( ($self->{file_type} eq 'problem') ? CGI::submit(-value=>'Refresh',-name=>'submit') : '' ), |
| 332 | CGI::submit(-value=>'Save',-name=>'submit'), |
334 | CGI::submit(-value=>'Save',-name=>'submit'), |
| 333 | # $actionString |
335 | CGI::submit(-value=>'Revert',-name=>'submit'), |
| 334 | ), |
336 | ), |
| 335 | |
|
|
| 336 | #CGI::a({-href=>$ce->{viewProblemURL},-target=>'_viewProblem'},'view problem'), |
|
|
| 337 | CGI::end_form(), |
337 | CGI::end_form(), |
| 338 | # "<p> the parameters passed are " #FIXME -- debugging code |
|
|
| 339 | # . join("<BR>", %{$r->param()}) . |
|
|
| 340 | # "</p> and the gatheredInfo is ", |
|
|
| 341 | # "problemPath=$problemPath<br> formURL=".$r->uri . "<br>" , |
|
|
| 342 | # "viewProblemURL ".$ce->{viewProblemURL}."<br>", |
|
|
| 343 | # "problem_obj =". $ce->{problem_obj}."<br>", |
|
|
| 344 | # "path_components ". $ce->{path_components}.'<br>', |
|
|
| 345 | # "hostname =$hostname<br>", |
|
|
| 346 | # "port =$port <br>", |
|
|
| 347 | # "uri = $uri <br>", |
|
|
| 348 | # "viewURL =".$ce->{viewURL}."<br>", |
|
|
| 349 | |
|
|
| 350 | ; |
|
|
| 351 | |
338 | |
| 352 | |
339 | |
| 353 | } |
340 | } |
| 354 | |
341 | |
| 355 | |
342 | |