| … | |
… | |
| 45 | my $editFileSuffix = $self->{ce}->{editFileSuffix}; |
45 | my $editFileSuffix = $self->{ce}->{editFileSuffix}; |
| 46 | my $problemSeed = ($r->param('problemSeed')) ? $r->param('problemSeed') : ''; |
46 | my $problemSeed = ($r->param('problemSeed')) ? $r->param('problemSeed') : ''; |
| 47 | my $displayMode = ($r->param('displayMode')) ? $r->param('displayMode') : ''; |
47 | my $displayMode = ($r->param('displayMode')) ? $r->param('displayMode') : ''; |
| 48 | |
48 | |
| 49 | my $viewURL = "http://$hostname:$port"; |
49 | my $viewURL = "http://$hostname:$port"; |
| 50 | $viewURL .= $ce->{webworkURLs}->{root}."/$courseName/$setName/$problemNumber/?"; |
50 | $viewURL .= "/webwork/$courseName/$setName/$problemNumber/?"; |
| 51 | $viewURL .= $self->url_authen_args; |
51 | $viewURL .= $self->url_authen_args; |
| 52 | $viewURL .= "&displayMode=$displayMode&problemSeed=$problemSeed"; # optional displayMode and problemSeed overrides |
52 | $viewURL .= "&displayMode=$displayMode&problemSeed=$problemSeed"; # optional displayMode and problemSeed overrides |
| 53 | $viewURL .= "&editMode=temporaryFile"; |
53 | $viewURL .= "&editMode=temporaryFile"; |
| 54 | $viewURL .= '&sourceFilePath='. $self->{currentSourceFilePath}; # path to pg text for viewing |
54 | $viewURL .= '&sourceFilePath='. $self->{currentSourceFilePath}; # path to pg text for viewing |
| 55 | $viewURL .= "&submit_button=$submit_button"; # allows Problem.pg to recognize state |
55 | $viewURL .= "&submit_button=$submit_button"; # allows Problem.pg to recognize state |
| 56 | $viewURL .= '&editErrors='.$self->{ce}->{editErrors}; # of problem being viewed. |
56 | $viewURL .= '&editErrors='.$self->{editErrors}; # of problem being viewed. |
| 57 | $r->header_out(Location => $viewURL ); |
57 | $r->header_out(Location => $viewURL ); |
| 58 | return REDIRECT; |
58 | return REDIRECT; |
| 59 | } else { |
59 | } else { |
| 60 | # initialize and |
60 | # initialize and |
| 61 | # display the editing window |
61 | # display the editing window |
| … | |
… | |
| 84 | |
84 | |
| 85 | # find path to pg file for the problem |
85 | # find path to pg file for the problem |
| 86 | # FIXME there is a discrepancy in the way that the problems are found. |
86 | # FIXME there is a discrepancy in the way that the problems are found. |
| 87 | # FIXME more error checking is needed in case the problem doesn't exist. |
87 | # FIXME more error checking is needed in case the problem doesn't exist. |
| 88 | # my $problem_record = $db->getUserProblem($user,$setID,1); |
88 | # my $problem_record = $db->getUserProblem($user,$setID,1); |
| 89 | my $problem_record = $db->getGlobalUserProblem($effectiveUserName, $setName, $problemNumber); |
89 | my $problem_record = $db->getGlobalUserProblem($effectiveUserName, $setName, $problemNumber); |
|
|
90 | # If there is no global_user defined problem, (i.e. the sets haven't been assigned yet), then look for a global version of the problem. |
|
|
91 | $problem_record = $db->getGlobalProblem($setName, $problemNumber) unless defined($problem_record); |
|
|
92 | die "Cannot find a problem record for set $setName / problem $problemNumber" |
|
|
93 | unless defined($problem_record); |
| 90 | my $templateDirectory = $ce->{courseDirs}->{templates}; |
94 | my $templateDirectory = $ce->{courseDirs}->{templates}; |
| 91 | my $problemPath = $templateDirectory."/".$problem_record->source_file; |
95 | my $problemPath = $templateDirectory."/".$problem_record->source_file; |
| 92 | my $editFileSuffix = 'tmp'; |
96 | my $editFileSuffix = 'tmp'; |
| 93 | my $submit_button = $r->param('submit'); |
97 | my $submit_button = $r->param('submit'); |
| 94 | |
98 | |
| 95 | my $displayMode = ( defined($r->param('displayMode')) ) ? $r->param('displayMode') : $ce->{pg}->{options}->{displayMode}; |
99 | my $displayMode = ( defined($r->param('displayMode')) ) ? $r->param('displayMode') : $ce->{pg}->{options}->{displayMode}; |
| 96 | my $problemSeed = ( defined($r->param('problemSeed')) ) ? $r->param('problemSeed') : $problem_record->problem_seed; |
100 | # try to get problem seed from the input parameter, or from the problem record |
|
|
101 | my $problemSeed; |
|
|
102 | if ( defined($r->param('problemSeed')) ) { |
|
|
103 | $problemSeed = $r->param('problemSeed'); |
|
|
104 | } elsif ($problem_record->can('problem_seed')) { |
|
|
105 | $problemSeed = $problem_record->problem_seed; |
|
|
106 | } |
|
|
107 | # make absolutely sure that the problem seed is defined, if it hasn't been. |
| 97 | $problemSeed = '1234' unless defined($problemSeed) and $problemSeed =~/\S/; |
108 | $problemSeed = '123456' unless defined($problemSeed) and $problemSeed =~/\S/; |
| 98 | |
109 | |
| 99 | my $problemContents = ''; |
110 | my $problemContents = ''; |
| 100 | my $currentSourceFilePath = ''; |
111 | my $currentSourceFilePath = ''; |
| 101 | # update the .pg and .pg.tmp files in the directory |
112 | # update the .pg and .pg.tmp files in the directory |
| 102 | if (not defined($submit_button) ) { |
113 | if (not defined($submit_button) ) { |