| 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/Instructor/PGProblemEditor.pm,v 1.21 2003/12/09 01:12:31 sh002i Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm,v 1.22 2003/12/12 02:24:30 gage 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. |
| … | |
… | |
| 37 | sub title { |
37 | sub title { |
| 38 | my $self = shift; |
38 | my $self = shift; |
| 39 | #FIXME don't need the entire path ?? |
39 | #FIXME don't need the entire path ?? |
| 40 | return "Instructor Tools - PG Problem Editor "; |
40 | return "Instructor Tools - PG Problem Editor "; |
| 41 | } |
41 | } |
| 42 | sub go { |
42 | |
|
|
43 | sub header { #FIXME this should be moved up to ContentGenerator |
|
|
44 | my $self = shift; |
|
|
45 | return REDIRECT if $self->{noContent}; |
|
|
46 | my $r = $self->{r}; |
|
|
47 | $r->content_type('text/html'); |
|
|
48 | $r->send_http_header(); |
|
|
49 | return OK; |
|
|
50 | } |
|
|
51 | |
|
|
52 | ########################################################### |
|
|
53 | # This editor will edit problem files or set header files or files, such as course_info |
|
|
54 | # whose name is defined in the global.conf database |
|
|
55 | # |
|
|
56 | # Only files under the template directory ( or linked to this location) can be edited. |
|
|
57 | # |
|
|
58 | # The course information and problems are located in the course templates directory. |
|
|
59 | # Course information has the name defined by courseFiles->{course_info} |
|
|
60 | # |
|
|
61 | # Only files under the template directory ( or linked to this location) can be edited. |
|
|
62 | # |
|
|
63 | # editMode = temporaryFile (view the temp file defined by course_info.txt.user_name.tmp |
|
|
64 | # instead of the file course_info.txt) |
|
|
65 | # The editFileSuffix is "user_name.tmp" by default. It's definition should be moved to Instructor.pm #FIXME |
|
|
66 | ########################################################### |
|
|
67 | |
|
|
68 | sub pre_header_initialize { |
| 43 | my $self = shift; |
69 | my $self = shift; |
| 44 | my ($setName, $problemNumber) = @_; |
70 | my ($setName, $problemNumber) = @_; |
| 45 | my $r = $self->{r}; |
71 | my $r = $self->{r}; |
| 46 | my $ce = $self->{ce}; |
72 | my $ce = $self->{ce}; |
| 47 | my $submit_button = $r->param('submit'); # obtain submit command from form |
73 | my $submit_button = $r->param('submit'); # obtain submit command from form |
| 48 | |
74 | |
| 49 | # various actions depending on state. |
75 | ##################################################### |
|
|
76 | # Save problem to permanent or temporary file |
|
|
77 | # Then redirect for viewing |
|
|
78 | ##################################################### |
| 50 | if ( defined($submit_button) and ($submit_button eq 'Save' or $submit_button eq 'Refresh') ) { |
79 | if ( defined($submit_button) and ($submit_button eq 'Save' or $submit_button eq 'Refresh') ) { |
| 51 | |
80 | |
| 52 | $self->initialize($setName,$problemNumber); # write the necessary files |
81 | $self->saveFileChanges($setName,$problemNumber); # write the necessary files |
| 53 | # return file path for viewing problem |
82 | # return file path for viewing problem |
| 54 | # in $self->{currentSourceFilePath} |
83 | # in $self->{currentSourceFilePath} |
|
|
84 | # obtain the appropriate seed. |
| 55 | #redirect to view the problem |
85 | #redirect to view the problem |
| 56 | |
86 | |
| 57 | my $hostname = $r->hostname(); |
87 | my $hostname = $r->hostname(); |
| 58 | my $port = $r->get_server_port(); |
88 | my $port = $r->get_server_port(); |
| 59 | my $uri = $r->uri; |
89 | my $uri = $r->uri; |
| 60 | my $courseName = $self->{ce}->{courseName}; |
90 | my $courseName = $self->{ce}->{courseName}; |
| 61 | my $problemSeed = ($r->param('problemSeed')) ? $r->param('problemSeed') : ''; |
91 | my $problemSeed = ($r->param('problemSeed')) ? $r->param('problemSeed') : ''; |
| 62 | my $displayMode = ($r->param('displayMode')) ? $r->param('displayMode') : ''; |
92 | my $displayMode = ($r->param('displayMode')) ? $r->param('displayMode') : ''; |
| 63 | my $viewURL = ''; |
93 | my $viewURL = ''; |
| 64 | if ($self->{file_type} eq 'problem') { |
94 | if ($self->{file_type} eq 'problem') { |
| 65 | # redirect to have problem read by Problem.pm |
95 | # redirect to have problem read by Problem.pm |
| 66 | $viewURL = "http://$hostname:$port"; |
96 | $viewURL = "http://$hostname:$port"; |
| 67 | $viewURL .= $ce->{webworkURLs}->{root}."/$courseName/$setName/$problemNumber/?"; |
97 | $viewURL .= $ce->{webworkURLs}->{root}."/$courseName/$setName/$problemNumber/?"; |
| 68 | $viewURL .= $self->url_authen_args; |
98 | $viewURL .= $self->url_authen_args; |
| 69 | $viewURL .= "&displayMode=$displayMode&problemSeed=$problemSeed"; # optional displayMode and problemSeed overrides |
99 | $viewURL .= "&displayMode=$displayMode&problemSeed=$problemSeed"; # optional displayMode and problemSeed overrides |
| 70 | if ($submit_button eq 'Save') { |
100 | if ($submit_button eq 'Save') { |
| 71 | $viewURL .= "&editMode=savedFile"; |
101 | $viewURL .= "&editMode=savedFile"; |
| 72 | } else { |
102 | } else { |
| 73 | $viewURL .= "&editMode=temporaryFile"; |
103 | $viewURL .= "&editMode=temporaryFile"; |
| 74 | } |
104 | } |
| 75 | $viewURL .= '&sourceFilePath='. $self->{currentSourceFilePath}; # path to pg text for viewing |
105 | $viewURL .= '&sourceFilePath='. $self->{currentSourceFilePath}; # path to pg text for viewing |
| 76 | # allows Problem.pg to recognize state |
106 | # allows Problem.pg to recognize state |
| 77 | # of problem being viewed. |
107 | # of problem being viewed. |
| 78 | } elsif ($self->{file_type} eq 'set_header') { |
108 | } elsif ($self->{file_type} eq 'set_header') { |
| … | |
… | |
| 80 | $viewURL = "http://$hostname:$port"; |
110 | $viewURL = "http://$hostname:$port"; |
| 81 | $viewURL .= $ce->{webworkURLs}->{root}."/$courseName/$setName/?"; |
111 | $viewURL .= $ce->{webworkURLs}->{root}."/$courseName/$setName/?"; |
| 82 | $viewURL .= $self->url_authen_args; |
112 | $viewURL .= $self->url_authen_args; |
| 83 | $viewURL .= "&displayMode=$displayMode&problemSeed=$problemSeed"; # optional displayMode and problemSeed overrides |
113 | $viewURL .= "&displayMode=$displayMode&problemSeed=$problemSeed"; # optional displayMode and problemSeed overrides |
| 84 | if ($submit_button eq 'Save') { |
114 | if ($submit_button eq 'Save') { |
| 85 | $viewURL .= "&editMode=savedFile"; |
115 | $viewURL .= "&editMode=savedFile"; |
|
|
116 | } else { |
|
|
117 | $viewURL .= "&editMode=temporaryFile"; |
| 86 | } |
118 | } |
|
|
119 | } elsif ($self->{file_type} eq 'course_info' ) { |
|
|
120 | $viewURL = "http://$hostname:$port"; |
|
|
121 | $viewURL .= $ce->{webworkURLs}->{root}."/$courseName/?"; |
|
|
122 | $viewURL .= $self->url_authen_args; |
|
|
123 | if ($submit_button eq 'Save') { |
|
|
124 | $viewURL .= "&editMode=savedFile"; |
|
|
125 | } else { |
|
|
126 | $viewURL .= "&editMode=temporaryFile"; |
|
|
127 | } |
|
|
128 | } else { |
|
|
129 | warn "PGProblemEditor does not have facilities for editing files with file_type ".$self->{file_type}; |
| 87 | } |
130 | } |
|
|
131 | |
| 88 | $r->header_out(Location => $viewURL ); |
132 | $r->header_out(Location => $viewURL ); |
| 89 | return REDIRECT; |
133 | $self->{noContent} = 1; # forces redirect |
| 90 | } else { |
134 | return; |
| 91 | # initialize and |
|
|
| 92 | # display the editing window |
|
|
| 93 | |
|
|
| 94 | $self->SUPER::go(@_); |
|
|
| 95 | } |
135 | } |
| 96 | |
136 | |
| 97 | } |
137 | } |
| 98 | |
138 | |
| 99 | sub initialize { |
139 | sub initialize { |
|
|
140 | my $self = shift; |
|
|
141 | my ($setName, $problemNumber) = @_; |
|
|
142 | $self -> saveFileChanges(@_); |
|
|
143 | |
|
|
144 | |
|
|
145 | |
|
|
146 | } |
|
|
147 | |
|
|
148 | sub saveFileChanges { |
| 100 | |
149 | |
| 101 | my ($self, $setName, $problemNumber) = @_; |
150 | my ($self, $setName, $problemNumber) = @_; |
| 102 | my $ce = $self->{ce}; |
151 | my $ce = $self->{ce}; |
| 103 | my $r = $self->{r}; |
152 | my $r = $self->{r}; |
| 104 | my $path_info = $r->path_info || ""; |
153 | my $path_info = $r->path_info || ""; |
| 105 | my $db = $self->{db}; |
154 | my $db = $self->{db}; |
| 106 | my $user = $r->param('user'); |
155 | my $user = $r->param('user'); |
| 107 | my $effectiveUserName = $r->param('effectiveUser'); |
156 | my $effectiveUserName = $r->param('effectiveUser'); |
| 108 | my $courseName = $ce->{courseName}; |
157 | my $courseName = $ce->{courseName}; |
| 109 | |
158 | |
|
|
159 | $setName = '' unless defined $setName; |
|
|
160 | $problemNumber = '' unless defined $problemNumber; |
| 110 | |
161 | |
| 111 | # Find URL for viewing problem |
162 | ################################################## |
| 112 | |
163 | # Determine path to the file to be edited. |
| 113 | # find path to pg file for the problem |
164 | ################################################## |
| 114 | |
|
|
| 115 | my $templateDirectory = $ce->{courseDirs}->{templates}; |
165 | my $templateDirectory = $ce->{courseDirs}->{templates}; |
| 116 | my $problemPath = $templateDirectory; |
166 | my $editFilePath = $templateDirectory; |
| 117 | my $problem_record = undef; |
167 | my $problem_record = undef; |
|
|
168 | |
|
|
169 | my $file_type = $r->param("file_type") || ''; |
|
|
170 | |
|
|
171 | if ($file_type eq 'course_info' ) { |
|
|
172 | $editFilePath .= '/'. $ce->{courseFiles}->{course_info}; |
|
|
173 | $self->{file_type} = 'course_info'; |
|
|
174 | # no problem_record is defined in this case |
|
|
175 | |
|
|
176 | } else { # we areediting a problem file or a set header file |
|
|
177 | |
| 118 | # FIXME there is a discrepancy in the way that the problems are found. |
178 | # FIXME there is a discrepancy in the way that the problems are found. |
| 119 | # FIXME more error checking is needed in case the problem doesn't exist. |
179 | # FIXME more error checking is needed in case the problem doesn't exist. |
| 120 | if (defined($problemNumber) and $problemNumber) { |
180 | if (defined($problemNumber) and $problemNumber) { |
| 121 | $problem_record = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked |
181 | $problem_record = $db->getMergedProblem($effectiveUserName, $setName, $problemNumber); # checked |
| 122 | # If there is no global_user defined problem, (i.e. the sets haven't been assigned yet), |
182 | # If there is no global_user defined problem, (i.e. the sets haven't been assigned yet), |
| 123 | # look for a global version of the problem. |
183 | # look for a global version of the problem. |
| 124 | $problem_record = $db->getGlobalProblem($setName, $problemNumber) unless defined($problem_record); # checked |
184 | $problem_record = $db->getGlobalProblem($setName, $problemNumber) unless defined($problem_record); # checked |
| 125 | # bail if no problem is found |
185 | # bail if no problem is found |
| 126 | die "Cannot find a problem record for set $setName / problem $problemNumber" |
186 | die "Cannot find a problem record for set $setName / problem $problemNumber" |
| 127 | unless defined($problem_record); |
187 | unless defined($problem_record); |
| 128 | $problemPath .= '/'.$problem_record->source_file; |
188 | $editFilePath .= '/'.$problem_record->source_file; |
| 129 | $self->{file_type} = 'problem'; |
189 | $self->{file_type} = 'problem'; |
| 130 | } elsif (defined($problemNumber) and $problemNumber==0) { # we are editing a header file |
190 | } elsif (defined($problemNumber) and $problemNumber==0) { # we are editing a header file |
| 131 | my $set_record = $db->getMergedSet($effectiveUserName, $setName); # checked |
191 | my $set_record = $db->getMergedSet($effectiveUserName, $setName); # checked |
| 132 | die "Cannot find a set record for set $setName" unless defined($set_record); |
192 | die "Cannot find a set record for set $setName" unless defined($set_record); |
| 133 | $problemPath .= '/'.$set_record->set_header; |
193 | $editFilePath .= '/'.$set_record->set_header; |
| 134 | $self->{file_type} = 'set_header'; |
194 | $self->{file_type} = 'set_header'; |
|
|
195 | } |
| 135 | } |
196 | } |
|
|
197 | |
|
|
198 | |
|
|
199 | |
| 136 | |
200 | |
| 137 | my $editFileSuffix = $user.'.tmp'; |
201 | my $editFileSuffix = $user.'.tmp'; |
| 138 | my $submit_button = $r->param('submit'); |
202 | my $submit_button = $r->param('submit'); |
| 139 | |
203 | |
|
|
204 | |
|
|
205 | ############################################################################## |
|
|
206 | # Determine the display mode |
|
|
207 | # try to get problem seed from the input parameter, or from the problem record |
|
|
208 | # This will be needed for viewing the problem via redirect. |
|
|
209 | # They are also two of the parameters which can be set by the editor |
|
|
210 | ############################################################################## |
| 140 | my $displayMode = ( defined($r->param('displayMode')) ) ? $r->param('displayMode') : $ce->{pg}->{options}->{displayMode}; |
211 | my $displayMode = ( defined($r->param('displayMode')) ) ? $r->param('displayMode') : $ce->{pg}->{options}->{displayMode}; |
| 141 | # try to get problem seed from the input parameter, or from the problem record |
212 | |
| 142 | my $problemSeed; |
213 | my $problemSeed; |
| 143 | if ( defined($r->param('problemSeed')) ) { |
214 | if ( defined($r->param('problemSeed')) ) { |
| 144 | $problemSeed = $r->param('problemSeed'); |
215 | $problemSeed = $r->param('problemSeed'); |
| 145 | } elsif (defined($problem_record) and $problem_record->can('problem_seed')) { |
216 | } elsif (defined($problem_record) and $problem_record->can('problem_seed')) { |
| 146 | $problemSeed = $problem_record->problem_seed; |
217 | $problemSeed = $problem_record->problem_seed; |
| 147 | } |
218 | } |
| 148 | # make absolutely sure that the problem seed is defined, if it hasn't been. |
219 | # make absolutely sure that the problem seed is defined, if it hasn't been. |
| 149 | $problemSeed = '123456' unless defined($problemSeed) and $problemSeed =~/\S/; |
220 | $problemSeed = '123456' unless defined($problemSeed) and $problemSeed =~/\S/; |
| 150 | |
221 | |
|
|
222 | ############################################################################## |
|
|
223 | # read and update the targetFile and targetFile.tmp files in the directory |
|
|
224 | # if a .tmp file already exists use that, unless the revert button has been pressed. |
|
|
225 | # These .tmp files are |
|
|
226 | # removed when the file is finally saved. |
|
|
227 | ############################################################################## |
|
|
228 | |
| 151 | my $problemContents = ''; |
229 | my $problemContents = ''; |
| 152 | my $currentSourceFilePath = ''; |
230 | my $currentSourceFilePath = ''; |
| 153 | my $editErrors = ''; |
231 | my $editErrors = ''; |
| 154 | |
232 | |
| 155 | # update the .pg and .pg.tmp files in the directory |
|
|
| 156 | # if a .tmp file already exists use that, unless the revert button has been pressed. |
|
|
| 157 | # These .tmp files are |
|
|
| 158 | # removed when the file is finally saved. |
|
|
| 159 | my $inputFilePath = (-r "$problemPath.$editFileSuffix")?"$problemPath.$editFileSuffix" : $problemPath; |
233 | my $inputFilePath = (-r "$editFilePath.$editFileSuffix")?"$editFilePath.$editFileSuffix" : $editFilePath; |
| 160 | $inputFilePath = $problemPath if defined($submit_button) and $submit_button eq 'Revert'; |
234 | $inputFilePath = $editFilePath if defined($submit_button) and $submit_button eq 'Revert'; |
| 161 | |
235 | |
| 162 | if (not defined($submit_button) or $submit_button eq 'Revert' ) { |
236 | if (not defined($submit_button) or $submit_button eq 'Revert' ) { |
| 163 | # this is a fresh editing job |
237 | # this is a fresh editing job |
| 164 | # copy the pg file to a new file with the same name with .tmp added |
238 | # copy the pg file to a new file with the same name with .tmp added |
| 165 | # store this name in the $self->currentSourceFilePath for use in body |
239 | # store this name in the $self->currentSourceFilePath for use in body |
| 166 | eval { $problemContents = WeBWorK::Utils::readFile($inputFilePath) }; |
240 | eval { $problemContents = WeBWorK::Utils::readFile($inputFilePath) }; |
| 167 | # try to read file |
241 | # try to read file |
| 168 | $problemContents = $@ if $@; |
242 | $problemContents = $@ if $@; |
| 169 | $editErrors .= $problemContents; |
243 | $editErrors .= $problemContents; |
| 170 | $currentSourceFilePath = "$problemPath.$editFileSuffix"; |
244 | $currentSourceFilePath = "$editFilePath.$editFileSuffix"; |
| 171 | $self->{currentSourceFilePath} = $currentSourceFilePath; |
245 | $self->{currentSourceFilePath} = $currentSourceFilePath; |
| 172 | } elsif ($submit_button eq 'Refresh' ) { |
246 | } elsif ($submit_button eq 'Refresh' ) { |
| 173 | # grab the problemContents from the form in order to save it to the tmp file |
247 | # grab the problemContents from the form in order to save it to the tmp file |
| 174 | # store tmp file name in the $self->currentSourceFilePath for use in body |
248 | # store tmp file name in the $self->currentSourceFilePath for use in body |
| 175 | |
249 | |
| 176 | $problemContents = $r->param('problemContents'); |
250 | $problemContents = $r->param('problemContents'); |
| 177 | $currentSourceFilePath = "$problemPath.$editFileSuffix"; |
251 | $currentSourceFilePath = "$editFilePath.$editFileSuffix"; |
| 178 | $self->{currentSourceFilePath} = $currentSourceFilePath; |
252 | $self->{currentSourceFilePath} = $currentSourceFilePath; |
| 179 | } elsif ($submit_button eq 'Save') { |
253 | } elsif ($submit_button eq 'Save') { |
| 180 | # grab the problemContents from the form in order to save it to the permanent file |
254 | # grab the problemContents from the form in order to save it to the permanent file |
| 181 | # later we will unlink (delete) the temporary file |
255 | # later we will unlink (delete) the temporary file |
| 182 | # store permanent file name in the $self->currentSourceFilePath for use in body |
256 | # store permanent file name in the $self->currentSourceFilePath for use in body |
| 183 | |
257 | |
| 184 | $problemContents = $r->param('problemContents'); |
258 | $problemContents = $r->param('problemContents'); |
| 185 | $currentSourceFilePath = "$problemPath"; |
259 | $currentSourceFilePath = "$editFilePath"; |
| 186 | $self->{currentSourceFilePath} = $currentSourceFilePath; |
260 | $self->{currentSourceFilePath} = $currentSourceFilePath; |
| 187 | } else { |
261 | } else { |
| 188 | # give a warning |
262 | # give a warning |
| 189 | die "Unrecognized submit command $submit_button"; |
263 | die "Unrecognized submit command $submit_button"; |
| 190 | } |
264 | } |
| 191 | |
265 | |
| 192 | # Handle the problem of line endings. Make sure that all of the line endings. Convert \r\n to \n |
266 | # Handle the problem of line endings. Make sure that all of the line endings. Convert \r\n to \n |
| 193 | $problemContents =~ s/\r\n/\n/g; |
267 | $problemContents =~ s/\r\n/\n/g; |
| 194 | $problemContents =~ s/\r/\n/g; |
268 | $problemContents =~ s/\r/\n/g; |
| 195 | |
269 | |
| 196 | # print changed pg files |
270 | # FIXME convert all double returns to paragraphs |
|
|
271 | $problemContents =~ s/\n\n/\n<p>\n/g; |
|
|
272 | ############################################################################## |
|
|
273 | # |
|
|
274 | # write changes to the approriate files |
| 197 | # FIXME make sure that the permissions are set correctly!!! |
275 | # FIXME make sure that the permissions are set correctly!!! |
| 198 | # Make sure that the warning is being transmitted properly. |
276 | # Make sure that the warning is being transmitted properly. |
| 199 | |
277 | ############################################################################## |
| 200 | eval { |
278 | eval { |
| 201 | local *OUTPUTFILE; |
279 | local *OUTPUTFILE; |
| 202 | open OUTPUTFILE, ">", $currentSourceFilePath |
280 | open OUTPUTFILE, ">", $currentSourceFilePath |
| 203 | or die "Failed to write to $currentSourceFilePath. |
281 | or die "Failed to write to $currentSourceFilePath. |
| 204 | It is likely that the permissions in the template directory have not been set correctly.". |
282 | It is likely that the permissions in the template directory have not been set correctly.". |
| … | |
… | |
| 206 | $!"; |
284 | $!"; |
| 207 | print OUTPUTFILE $problemContents; |
285 | print OUTPUTFILE $problemContents; |
| 208 | close OUTPUTFILE; |
286 | close OUTPUTFILE; |
| 209 | }; |
287 | }; |
| 210 | # record an error string for later use if there was a difficulty in writing to the file |
288 | # record an error string for later use if there was a difficulty in writing to the file |
| 211 | # FIXME is this string every inspected? |
289 | # FIXME is this string ever inspected? |
| 212 | |
290 | |
| 213 | my $openTempFileErrors = $@ if $@; |
291 | my $openTempFileErrors = $@ if $@; |
| 214 | |
292 | |
| 215 | if ( $openTempFileErrors) { |
293 | if ( $openTempFileErrors) { |
| 216 | |
294 | |
| … | |
… | |
| 226 | |
304 | |
| 227 | } else { |
305 | } else { |
| 228 | # unlink the temporary file if there are no errors and the save button has been pushed |
306 | # unlink the temporary file if there are no errors and the save button has been pushed |
| 229 | |
307 | |
| 230 | $self->{openTempFileErrors} = ''; |
308 | $self->{openTempFileErrors} = ''; |
| 231 | unlink("$problemPath.$editFileSuffix") if defined($submit_button) and $submit_button eq 'Save'; |
309 | unlink("$editFilePath.$editFileSuffix") if defined($submit_button) and $submit_button eq 'Save'; |
| 232 | }; |
310 | }; |
| 233 | |
311 | |
| 234 | |
312 | |
| 235 | # return values for use in the body subroutine |
313 | # return values for use in the body subroutine |
| 236 | $self->{problemPath} = $problemPath; |
314 | $self->{problemPath} = $editFilePath; |
| 237 | $self->{inputFilePath} = $inputFilePath; |
315 | $self->{inputFilePath} = $inputFilePath; |
| 238 | $self->{displayMode} = $displayMode; |
316 | $self->{displayMode} = $displayMode; |
| 239 | $self->{problemSeed} = $problemSeed; |
317 | $self->{problemSeed} = $problemSeed; |
| 240 | $self->{r_problemContents} = \$problemContents; |
318 | $self->{r_problemContents} = \$problemContents; |
| 241 | # FIXME there is no way to edit in a temporary file -- all editing takes place on disk!!! |
319 | $self->{editFileSuffix} = $editFileSuffix; |
| 242 | |
320 | |
| 243 | |
|
|
| 244 | |
|
|
| 245 | } |
|
|
| 246 | |
321 | |
|
|
322 | |
|
|
323 | |
|
|
324 | } |
|
|
325 | sub saveFile { |
|
|
326 | my $self = shift; |
|
|
327 | |
|
|
328 | |
|
|
329 | |
|
|
330 | |
|
|
331 | |
|
|
332 | |
|
|
333 | } |
| 247 | sub path { |
334 | sub path { |
| 248 | my $self = shift; |
335 | my $self = shift; |
|
|
336 | my $r = $self->{r}; |
|
|
337 | my $set_id = ''; |
|
|
338 | my $problem_id = ''; |
|
|
339 | unless (defined( $r->param("file_type") and $r->param("file_type") eq 'course_info' ) ){ |
| 249 | my $set_id = shift; |
340 | $set_id = shift; |
| 250 | my $problem_id = shift; |
341 | $problem_id = shift; |
|
|
342 | } |
|
|
343 | #FIXME this is a bad way to pass the args, since it's position changes if the set/problem info |
|
|
344 | # isn't there |
| 251 | my $args = $_[-1]; |
345 | my $args = $_[-1]; |
| 252 | |
346 | |
| 253 | my $ce = $self->{ce}; |
347 | my $ce = $self->{ce}; |
| 254 | my $root = $ce->{webworkURLs}->{root}; |
348 | my $root = $ce->{webworkURLs}->{root}; |
| 255 | my $courseName = $ce->{courseName}; |
349 | my $courseName = $ce->{courseName}; |
| 256 | return $self->pathMacro($args, |
350 | return $self->pathMacro($args, |
| 257 | "Home" => "$root", |
351 | "Home" => "$root", |
| … | |
… | |
| 275 | |
369 | |
| 276 | |
370 | |
| 277 | ################ |
371 | ################ |
| 278 | # Gathering info |
372 | # Gathering info |
| 279 | # What is needed |
373 | # What is needed |
| 280 | # $problemPath -- |
374 | # $editFilePath -- |
| 281 | # $formURL -- given by $r->uri |
375 | # $formURL -- given by $r->uri |
| 282 | # $tmpProblemPath |
376 | # $tmpProblemPath |
| 283 | my $problemPath = $self->{problemPath}; |
377 | my $editFilePath = $self->{problemPath}; # path to the permanent file to be edited |
| 284 | my $inputFilePath = $self->{inputFilePath}; |
378 | my $inputFilePath = $self->{inputFilePath}; # path to the file currently being worked with (might be a .tmp file) |
| 285 | |
379 | |
| 286 | |
380 | |
| 287 | |
|
|
| 288 | |
381 | |
| 289 | |
382 | |
| 290 | |
383 | |
| 291 | my $header = CGI::i("Editing problem: $inputFilePath"); |
384 | my $header = CGI::i("Editing problem: $inputFilePath"); |
| 292 | |
385 | |
| … | |
… | |
| 294 | # Find the text for the problem, either in the tmp file, if it exists |
387 | # Find the text for the problem, either in the tmp file, if it exists |
| 295 | # or in the original file in the template directory |
388 | # or in the original file in the template directory |
| 296 | ######################################################################### |
389 | ######################################################################### |
| 297 | my $problemContents = ${$self->{r_problemContents}}; |
390 | my $problemContents = ${$self->{r_problemContents}}; |
| 298 | |
391 | |
| 299 | # eval { $problemContents = WeBWorK::Utils::readFile($problemPath) }; # try to read file |
392 | # eval { $problemContents = WeBWorK::Utils::readFile($editFilePath) }; # try to read file |
| 300 | # $problemContents = $@ if $@; |
393 | # $problemContents = $@ if $@; |
| 301 | |
394 | |
| 302 | |
395 | |
| 303 | |
396 | |
| 304 | ######################################################################### |
397 | ######################################################################### |
| … | |
… | |
| 321 | ######################################################################### |
414 | ######################################################################### |
| 322 | |
415 | |
| 323 | |
416 | |
| 324 | warn "Errors in the problem ".CGI::br().$self->{editErrors} if $self->{editErrors}; |
417 | warn "Errors in the problem ".CGI::br().$self->{editErrors} if $self->{editErrors}; |
| 325 | |
418 | |
| 326 | |
419 | |
| 327 | return CGI::p($header), |
420 | return CGI::p($header), |
| 328 | #CGI::start_form("POST",$r->uri,-target=>'_problem'), doesn't pass on the target parameter??? |
421 | #CGI::start_form("POST",$r->uri,-target=>'_problem'), doesn't pass on the target parameter??? |
| 329 | qq!<form method="POST" action="$uri" enctype="application/x-www-form-urlencoded", target="_problem">!, |
422 | qq!<form method="POST" action="$uri" enctype="application/x-www-form-urlencoded", target="_problem">!, |
| 330 | $self->hidden_authen_fields, |
423 | $self->hidden_authen_fields, |
| 331 | CGI::hidden(-name=>'file_type',-default=>$self->{file_type}), |
424 | CGI::hidden(-name=>'file_type',-default=>$self->{file_type}), |
| 332 | CGI::div( |
425 | CGI::div( |
| 333 | 'Seed: ', |
426 | 'Seed: ', |
| 334 | CGI::textfield(-name=>'problemSeed',-value=>$problemSeed), |
427 | CGI::textfield(-name=>'problemSeed',-value=>$problemSeed), |
| … | |
… | |
| 344 | CGI::textarea(-name => 'problemContents', -default => $problemContents, |
437 | CGI::textarea(-name => 'problemContents', -default => $problemContents, |
| 345 | -rows => $rows, -columns => $columns, -override => 1, |
438 | -rows => $rows, -columns => $columns, -override => 1, |
| 346 | ), |
439 | ), |
| 347 | ), |
440 | ), |
| 348 | CGI::p( |
441 | CGI::p( |
| 349 | ( ($self->{file_type} eq 'problem') ? CGI::submit(-value=>'Refresh',-name=>'submit') : '' ), |
442 | CGI::submit(-value=>'Refresh',-name=>'submit'), |
| 350 | CGI::submit(-value=>'Save',-name=>'submit'), |
443 | CGI::submit(-value=>'Save',-name=>'submit'), |
| 351 | CGI::submit(-value=>'Revert',-name=>'submit'), |
444 | CGI::submit(-value=>'Revert',-name=>'submit'), |
| 352 | ), |
445 | ), |
| 353 | CGI::end_form(), |
446 | CGI::end_form(), |
| 354 | |
447 | |