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); our $libraryName; our $rowheight; sub title { my $self = shift; #FIXME don't need the entire path ?? return "Instructor Tools - PG Problem Editor for ". $self->{ce}->{problemPath}; } sub go { my $self = shift; my ($setName, $problemNumber) = @_; my $r = $self->{r}; my $ce = $self->{ce}; my $submit_button = $r->param('submit'); # obtain submit command from form # various actions depending on state. if ( defined($submit_button) and ($submit_button eq 'Save' or $submit_button eq 'Refresh') ) { $self->initialize($setName,$problemNumber); # write the necessary files # return file path for viewing problem # in $self->{ce}->{currentSourceFilePath} #redirect to view the problem my $hostname = $r->hostname(); my $port = $r->get_server_port(); my $uri = $r->uri; my $courseName = $self->{ce}->{courseName}; my $editFileSuffix = $self->{ce}->{editFileSuffix}; my $seed = ($r->param('seed')) ? $r->param('seed') : ''; my $displayMode = ($r->param('displayMode')) ? $r->param('displayMode') : ''; my $viewURL = "http://$hostname:$port"; $viewURL .= "/webwork/$courseName/$setName/$problemNumber/?"; $viewURL .= $self->url_authen_args; $viewURL .= "&displayMode=$displayMode&seed=$seed"; # optional displayMode and seed overrides $viewURL .= "&editMode=temporaryFile"; $viewURL .= '&sourceFilePath='.$self->{ce}->{currentSourceFilePath}; # path to pg text for viewing $viewURL .= "&submit_button=$submit_button"; # allows Problem.pg to recognize state $viewURL .= '&editErrors='.$self->{ce}->{editErrors}; # of problem being viewed. $r->header_out(Location => $viewURL ); return REDIRECT; } else { # initialize and # display the editing window $self->SUPER::go(@_); } } sub body { my $self = shift; # test area my $r = $self->{r}; my $db = $self->{db}; my $ce = $self->{ce}; my $user = $r->param('user'); my $key = $db->getKey($user)->key(); ################ # Gathering info # What is needed # $problemPath -- # $formURL -- given by $r->uri # $tmpProblemPath #my ($problemPath,$formURL,$tmpProblemPath) = $self->initialize(); my $problemPath = $ce->{problemPath}; #my $tmpProblemPath = $ce->{tmpProblemPath}; my $header = "Problem Editor: $problemPath"; ######################################################################### # 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 = ''; # my $editMode = (defined($r->param('problemContents')))? # 'tmpMode':'startMode'; # # if ( $editMode eq 'tmpMode') { # $problemContents = $r->param('problemContents'); # # } else{ eval { $problemContents = WeBWorK::Utils::readFile($problemPath) }; # try to read file $problemContents = $@ if $@; # } # save Action FIXME -- is this the write place for this? # my $actionString = ''; # if ($r->param('submit') eq 'Save') { # $actionString = "File saved to $problemPath"; # #FIXME it would be MUCH better to work with temporary files # open(FILE,">$problemPath") or die "Can't open $problemPath"; # print FILE $problemContents; # close(FILE); # # } ######################################################################### # Format the page ######################################################################### # Define parameters for textarea # FIXME these parameters should be capable of being updated dynamically. my $rows = 20; my $columns = 80; my $mode_list = ['HTML', 'HTML_tth','HTML_dpng', 'Latex2HTML']; my $mode = ( defined($r->param('mode')) ) ? $r->param('mode') : 'HTML_tth'; my $seed = ( defined($r->param('seed')) ) ? $r->param('seed') : '1234'; my $uri = $r->uri; ######################################################################## # Define a link to view the problem #FIXME ######################################################################### return CGI::p($header), #CGI::start_form("POST",$r->uri,-target=>'_problem'), doesn't pass on the target parameter??? qq!