################################################################################ # WeBWorK Online Homework Delivery System # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm,v 1.29 2004/05/06 21:53:41 jj Exp $ # # This program is free software; you can redistribute it and/or modify it under # the terms of either: (a) the GNU General Public License as published by the # Free Software Foundation; either version 2, or (at your option) any later # version, or (b) the "Artistic License" which comes with this package. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the # Artistic License for more details. ################################################################################ package WeBWorK::ContentGenerator::Instructor::PGProblemEditor; use base qw(WeBWorK::ContentGenerator::Instructor); =head1 NAME WeBWorK::ContentGenerator::Instructor::ProblemSetEditor - Edit a set definition list =cut use strict; use warnings; use CGI qw(); use WeBWorK::Utils qw(readFile); use Apache::Constants qw(:common REDIRECT); use HTML::Entities; use WeBWorK::Utils::Tasks qw(fake_set fake_problem); ########################################################### # This editor will edit problem files or set header files or files, such as course_info # whose name is defined in the global.conf database # # Only files under the template directory ( or linked to this location) can be edited. # # The course information and problems are located in the course templates directory. # Course information has the name defined by courseFiles->{course_info} # # Only files under the template directory ( or linked to this location) can be edited. # # editMode = temporaryFile (view the temp file defined by course_info.txt.user_name.tmp # instead of the file course_info.txt) # The editFileSuffix is "user_name.tmp" by default. It's definition should be moved to Instructor.pm #FIXME ########################################################### #our $libraryName; #our $rowheight; sub pre_header_initialize { my ($self) = @_; my $r = $self->r; my $ce = $r->ce; my $urlpath = $r->urlpath; my $submit_button = $r->param('submit'); # obtain submit command from form # Save problem to permanent or temporary file, then redirect for viewing if (defined($submit_button) and ($submit_button eq 'Save' or $submit_button eq 'Refresh')) { my $setName = $r->urlpath->arg("setID"); my $problemNumber = $r->urlpath->arg("problemID"); # write the necessary files # return file path for viewing problem in $self->{currentSourceFilePath} # obtain the appropriate seed $self->saveFileChanges($setName, $problemNumber); ##### calculate redirect URL based on file type ##### # get some information #my $hostname = $r->hostname(); #my $port = $r->get_server_port(); #my $uri = $r->uri; my $courseName = $urlpath->arg("courseID"); my $problemSeed = ($r->param('problemSeed')) ? $r->param('problemSeed') : ''; my $displayMode = ($r->param('displayMode')) ? $r->param('displayMode') : ''; my $viewURL = ''; # problems redirect to Problem.pm $self->{file_type} eq 'problem' and do { my $problemPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::Problem", courseID => $courseName, setID => $setName, problemID => $problemNumber); $viewURL = $self->systemLink($problemPage, params => { displayMode => $displayMode, problemSeed => $problemSeed, editMode => ($submit_button eq "Save" ? "savedFile" : "temporaryFile"), sourceFilePath => $self->{currentSourceFilePath}, submiterror => $self->{submiterror}, } ); }; # set headers redirect to ProblemSet.pm $self->{file_type} eq 'set_header' and do { my $problemSetPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSet", courseID => $courseName, setID => $setName); $viewURL = $self->systemLink($problemSetPage, params => { displayMode => $displayMode, problemSeed => $problemSeed, editMode => ($submit_button eq "Save" ? "savedFile" : "temporaryFile"), } ); }; # course info redirects to ProblemSets.pm $self->{file_type} eq 'course_info' and do { my $problemSetsPage = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets", courseID => $courseName); $viewURL = $self->systemLink($problemSetsPage, params => { editMode => ($submit_button eq "Save" ? "savedFile" : "temporaryFile"), } ); }; if ($viewURL) { $self->reply_with_redirect($viewURL); } else { die "Invalid file_type ", $self->{file_type}, " specified by saveFileChanges"; } } } sub initialize { my ($self) = @_; my $r = $self->r; my $setName = $r->urlpath->arg("setID"); my $problemNumber = $r->urlpath->arg("problemID"); # if we got to initialize(), then saveFileChanges was not called in pre_header_initialize(). # therefore we call it here: $self->saveFileChanges($setName, $problemNumber); } sub title { my $self = shift; my $r = $self->r; my $problemNumber = $r->urlpath->arg("problemID"); my $file_type = $self->{'file_type'} || ''; return "Set Header" if($file_type eq 'set_header'); return "Course Information" if($file_type eq 'course_info'); return 'Problem ' . $r->{urlpath}->name; } sub body { my ($self) = @_; my $r = $self->r; my $db = $r->db; my $ce = $r->ce; # Gathering info my $editFilePath = $self->{problemPath}; # path to the permanent file to be edited my $inputFilePath = $self->{inputFilePath}; # path to the file currently being worked with (might be a .tmp file) my $header = CGI::i("Editing problem: $inputFilePath"); ######################################################################### # Find the text for the problem, either in the tmp file, if it exists # or in the original file in the template directory ######################################################################### my $problemContents = ${$self->{r_problemContents}}; ######################################################################### # Format the page ######################################################################### # Define parameters for textarea # FIXME # Should the seed be set from some particular user instance?? # The mode list should be obtained from global.conf ultimately my $rows = 20; my $columns = 80; my $mode_list = ['plainText','formattedText','images']; my $displayMode = $self->{displayMode}; my $problemSeed = $self->{problemSeed}; my $uri = $r->uri; my $force_field = defined($r->param('sourceFilePath')) ? CGI::hidden(-name=>'sourceFilePath', -default=>$r->param('sourceFilePath')) : ''; return CGI::p($header), #CGI::start_form("POST",$r->uri,-target=>'_problem'), doesn't pass on the target parameter??? # THIS IS BECAUSE TARGET IS NOT A PARAMETER OF