[system] / branches / rel-2-1-patches / webwork-modperl / lib / WeBWorK / ContentGenerator / Instructor / PGProblemEditor.pm Repository:
ViewVC logotype

Diff of /branches/rel-2-1-patches/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2126 Revision 2134
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.34 2004/05/12 14:29:36 toenail Exp $ 4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm,v 1.35 2004/05/18 05:19:33 jj 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.
132 params => { 132 params => {
133 editMode => ($submit_button eq "Save" ? "savedFile" : "temporaryFile"), 133 editMode => ($submit_button eq "Save" ? "savedFile" : "temporaryFile"),
134 } 134 }
135 ); 135 );
136 }; 136 };
137 137
138 # don't redirect on bad save attempts
139 # FIXME: even with an error we still open a new page because of the target specified in the form
140 return if $self->{failure};
141
138 if ($viewURL) { 142 if ($viewURL) {
139 $self->reply_with_redirect($viewURL); 143 $self->reply_with_redirect($viewURL);
140 } else { 144 } else {
141 die "Invalid file_type ", $self->{file_type}, " specified by saveFileChanges"; 145 die "Invalid file_type ", $self->{file_type}, " specified by saveFileChanges";
142 } 146 }
147 my ($self) = @_; 151 my ($self) = @_;
148 my $r = $self->r; 152 my $r = $self->r;
149 153
150 my $setName = $r->urlpath->arg("setID"); 154 my $setName = $r->urlpath->arg("setID");
151 my $problemNumber = $r->urlpath->arg("problemID"); 155 my $problemNumber = $r->urlpath->arg("problemID");
152 156
153 # if we got to initialize(), then saveFileChanges was not called in pre_header_initialize(). 157 # if we got to initialize(), then saveFileChanges was not called in pre_header_initialize().
154 # therefore we call it here: 158 # therefore we call it here unless there has been an error already:
155 $self->saveFileChanges($setName, $problemNumber); 159 $self->saveFileChanges($setName, $problemNumber) unless $self->{failure};
156} 160}
157 161
158sub title { 162sub title {
159 my $self = shift; 163 my $self = shift;
160 my $r = $self->r; 164 my $r = $self->r;
201 my $edit_level = $r->param('edit_level') || 0; 205 my $edit_level = $r->param('edit_level') || 0;
202 206
203 my $force_field = defined($r->param('sourceFilePath')) ? 207 my $force_field = defined($r->param('sourceFilePath')) ?
204 CGI::hidden(-name=>'sourceFilePath', 208 CGI::hidden(-name=>'sourceFilePath',
205 -default=>$r->param('sourceFilePath')) : ''; 209 -default=>$r->param('sourceFilePath')) : '';
210
206 return CGI::p($header), 211 return CGI::p($header),
207 #CGI::start_form("POST",$r->uri,-target=>'_problem'), doesn't pass on the target parameter??? 212 #CGI::start_form("POST",$r->uri,-target=>'_problem'), doesn't pass on the target parameter???
208 # THIS IS BECAUSE TARGET IS NOT A PARAMETER OF <FORM>!!!!!!!! 213 # THIS IS BECAUSE TARGET IS NOT A PARAMETER OF <FORM>!!!!!!!!
209 qq!<form method="POST" action="$uri" enctype="application/x-www-form-urlencoded", target="problem$edit_level">!, 214 qq!<form method="POST" action="$uri" enctype="application/x-www-form-urlencoded", target="problem$edit_level">!,
210 $self->hidden_authen_fields, 215 $self->hidden_authen_fields,
406 } elsif ($submit_button eq 'Save as') { 411 } elsif ($submit_button eq 'Save as') {
407 # grab the problemContents from the form in order to save it to a new permanent file 412 # grab the problemContents from the form in order to save it to a new permanent file
408 # later we will unlink (delete) the current temporary file 413 # later we will unlink (delete) the current temporary file
409 # store new permanent file name in the $self->currentSourceFilePath for use in body 414 # store new permanent file name in the $self->currentSourceFilePath for use in body
410 $problemContents = $r->param('problemContents'); 415 $problemContents = $r->param('problemContents');
411 $currentSourceFilePath = $ce->{courseDirs}->{templates} . '/' .$r->param('save_to_new_file'); 416 $currentSourceFilePath = $ce->{courseDirs}->{templates} . '/' . $r->param('save_to_new_file');
412 $self->{currentSourceFilePath} = $currentSourceFilePath; 417 $self->{currentSourceFilePath} = $currentSourceFilePath;
413 $self->{problemPath} = $currentSourceFilePath; 418 $self->{problemPath} = $currentSourceFilePath;
414 } else { 419 } else {
415 die "Unrecognized submit command: $submit_button"; 420 die "Unrecognized submit command: $submit_button";
416 } 421 }
423 # instead of doing this here, it should be done n the PLACE WHERE THE FILE IS DISPLAYED!!! 428 # instead of doing this here, it should be done n the PLACE WHERE THE FILE IS DISPLAYED!!!
424 #if ($self->{file_type} eq 'course_info' ) { 429 #if ($self->{file_type} eq 'course_info' ) {
425 # $problemContents =~ s/\n\n/\n<p>\n/g; 430 # $problemContents =~ s/\n\n/\n<p>\n/g;
426 #} 431 #}
427 432
433
428 ############################################################################## 434 ##############################################################################
429 # write changes to the approriate files 435 # write changes to the approriate files
430 # FIXME make sure that the permissions are set correctly!!! 436 # FIXME make sure that the permissions are set correctly!!!
431 # Make sure that the warning is being transmitted properly. 437 # Make sure that the warning is being transmitted properly.
432 ############################################################################## 438 ##############################################################################
433 439
434 # FIXME set a local state rather continue to call on the submit button. 440 # FIXME set a local state rather continue to call on the submit button.
441 if (defined $submit_button and $submit_button eq 'Save as' and $r->param('save_to_new_file') !~ /\w/) {
442 # setting $self->{failure} stops any future redirects
443 $self->{failure} = "Please specify a file to save to.";
444 $self->addmessage(CGI::div({class=>"ResultsWithError"}, CGI::p("Please specify a file to save to.")));
435 if (defined $submit_button and $submit_button eq 'Save as' and defined $currentSourceFilePath and -e $currentSourceFilePath) { 445 } elsif (defined $submit_button and $submit_button eq 'Save as' and defined $currentSourceFilePath and -e $currentSourceFilePath) {
446 # setting $self->{failure} stops any future redirects
436 warn "File $currentSourceFilePath exists. File not saved."; 447 $self->{failure} = "File $currentSourceFilePath exists. File not saved.";
448 $self->addmessage(CGI::div({class=>"ResultsWithError"}, CGI::p("File $currentSourceFilePath exists. File not saved.")));
437 } else { 449 } else {
438 # make sure any missing directories are created 450 # make sure any missing directories are created
439 $currentSourceFilePath = WeBWorK::Utils::surePathToFile($ce->{courseDirs}->{templates},$currentSourceFilePath); 451 $currentSourceFilePath = WeBWorK::Utils::surePathToFile($ce->{courseDirs}->{templates},$currentSourceFilePath);
440 eval { 452 eval {
441 local *OUTPUTFILE; 453 local *OUTPUTFILE;
442 open OUTPUTFILE, ">", $currentSourceFilePath 454 open OUTPUTFILE, ">", $currentSourceFilePath
443 or die "Failed to open $currentSourceFilePath"; 455 or die "Failed to open $currentSourceFilePath";
444 print OUTPUTFILE $problemContents; 456 print OUTPUTFILE $problemContents;
445 close OUTPUTFILE; 457 close OUTPUTFILE;
446 }; # any errors are caught in the next block 458 }; # any errors are caught in the next block
447
448 } 459 }
449 460
450 ########################################################### 461 ###########################################################
451 # Catch errors in saving files, clean up temp files 462 # Catch errors in saving files, clean up temp files
452 ########################################################### 463 ###########################################################
453 464
454 my $openTempFileErrors = $@ if $@; 465 my $openTempFileErrors = $@ if $@;
455 466
456 if ($openTempFileErrors) { 467 if ($openTempFileErrors) {
457 $self->{failure} = "Unable to write to $currentSourceFilePath: It is likely that the permissions in the template directory have not been set correctly. See log for details."; 468 $self->{failure} = "Unable to write to $currentSourceFilePath: It is likely that the permissions in the template directory have not been set correctly. See log for details.";
458 #diagnose errors: 469 #diagnose errors:
459 warn "Unable to write to $currentSourceFilePath: $openTempFileErrors"; 470 # FIXME: these error messages tend to be redundand
460 warn "The file $currentSourceFilePath exists. \n " if -e $currentSourceFilePath; #FIXME 471 #$self->addmessage(CGI::div({class=>"ResultsWithError"}, CGI::p("Unable to write to $currentSourceFilePath: $openTempFileErrors")));
461 warn "The file $currentSourceFilePath cannot be found. \n " unless -e $currentSourceFilePath; 472 #$self->addmessage(CGI::div({class=>"ResultsWithError"}, CGI::p("The file $currentSourceFilePath exists. \n "))) if -e $currentSourceFilePath; #FIXME
462 warn "The file $currentSourceFilePath does not have write permissions. \n" 473 #$self->addmessage(CGI::div({class=>"ResultsWithError"}, CGI::p("The file $currentSourceFilePath cannot be found. \n "))) unless -e $currentSourceFilePath;
474 $self->addmessage(CGI::div({class=>"ResultsWithError"}, CGI::p("Unable to write to $currentSourceFilePath: It is likely that the permissions in the template directory have not been set correctly.")))
463 if -e $currentSourceFilePath and not -w $currentSourceFilePath; 475 if -e $currentSourceFilePath and not -w $currentSourceFilePath;
464 } else { 476 } else {
465 $self->{success} = "Problem saved to: $currentSourceFilePath"; 477 $self->{success} = "Problem saved to: $currentSourceFilePath";
466 # unlink the temporary file if there are no errors and the save button has been pushed 478 # unlink the temporary file if there are no errors and the save button has been pushed
467 unlink("$editFilePath.$editFileSuffix") 479 unlink("$editFilePath.$editFileSuffix")

Legend:
Removed from v.2126  
changed lines
  Added in v.2134

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9