| … | |
… | |
| 55 | # Find the text for the problem, either in the tmp file, if it exists |
55 | # Find the text for the problem, either in the tmp file, if it exists |
| 56 | # or in the original file in the template directory |
56 | # or in the original file in the template directory |
| 57 | ######################################################################### |
57 | ######################################################################### |
| 58 | my $problemContents = ''; |
58 | my $problemContents = ''; |
| 59 | my $editMode = (defined($r->param('problemContents')))? |
59 | my $editMode = (defined($r->param('problemContents')))? |
| 60 | 'tmpMode':'stdMode'; |
60 | 'tmpMode':'startMode'; |
| 61 | |
61 | |
| 62 | if ( $editMode eq 'tmpMode') { |
62 | if ( $editMode eq 'tmpMode') { |
| 63 | $problemContents = $r->param('problemContents'); |
63 | $problemContents = $r->param('problemContents'); |
| 64 | |
64 | |
| 65 | } else { |
65 | } else{ |
| 66 | eval { |
|
|
| 67 | $problemContents = WeBWorK::Utils::readFile($problemPath); |
66 | eval { $problemContents = WeBWorK::Utils::readFile($problemPath) }; # try to read file |
| 68 | }; |
|
|
| 69 | $problemContents = $@ if $@; |
67 | $problemContents = $@ if $@; |
|
|
68 | } |
|
|
69 | |
|
|
70 | # save Action FIXME -- is this the write place for this? |
|
|
71 | my $actionString = ''; |
|
|
72 | if ($r->param('submit') eq 'Save') { |
|
|
73 | $actionString = "File saved to $problemPath"; |
|
|
74 | #FIXME it would be MUCH better to work with temporary files |
|
|
75 | open(FILE,">$problemPath") or die "Can't open $problemPath"; |
|
|
76 | print FILE $problemContents; |
|
|
77 | close(FILE); |
|
|
78 | |
|
|
79 | } |
| 70 | |
80 | |
| 71 | # create tmp file version for later use |
81 | # create tmp file version for later use |
| 72 | # So that you don't need duplicate information in forms |
82 | # So that you don't need duplicate information in forms |
| 73 | # FIXME |
83 | # FIXME |
| 74 | # open(FILE,">$tmpProblemPath") || die "Failed to open $tmpProblemPath"; |
84 | # open(FILE,">$tmpProblemPath") || die "Failed to open $tmpProblemPath"; |
| 75 | # print FILE "tmpfileVersion\n\n" . $problemContents; |
85 | # print FILE "tmpfileVersion\n\n" . $problemContents; |
| 76 | # close(FILE); |
86 | # close(FILE); |
| 77 | } |
|
|
| 78 | |
87 | |
| 79 | # Define parameters for textarea |
88 | # Define parameters for textarea |
|
|
89 | # FIXME these parameters should be capable of being updated dynamically. |
| 80 | my $rows = 40; |
90 | my $rows = 20; |
| 81 | my $columns = 80; |
91 | my $columns = 80; |
| 82 | |
92 | my $mode_list = ['HTML', 'HTML_tth','HTML_dpng', 'Latex2HTML']; |
|
|
93 | my $mode = ( defined($r->param('mode')) ) ? $r->param('mode') : 'HTML_tth'; |
|
|
94 | my $seed = ( defined($r->param('seed')) ) ? $r->param('seed') : '1234'; |
| 83 | ######################################################################### |
95 | ######################################################################## |
| 84 | # Define a link to view the problem |
96 | # Define a link to view the problem |
| 85 | #fix me: |
97 | #FIXME |
| 86 | # Currently this link used the webwork problem library, which might be out of |
98 | |
| 87 | # sync with the local library |
|
|
| 88 | ######################################################################### |
99 | ######################################################################### |
| 89 | |
100 | |
| 90 | |
101 | |
| 91 | |
102 | |
| 92 | ######################################################################### |
103 | ######################################################################### |
| … | |
… | |
| 94 | ######################################################################### |
105 | ######################################################################### |
| 95 | |
106 | |
| 96 | return CGI::p($header), |
107 | return CGI::p($header), |
| 97 | CGI::startform("POST",$r->uri), |
108 | CGI::startform("POST",$r->uri), |
| 98 | $self->hidden_authen_fields, |
109 | $self->hidden_authen_fields, |
| 99 | CGI::textarea(-name => 'problemContents', -default => $problemContents, |
110 | CGI::div( |
| 100 | -rows => $rows, -columns => $columns, -override => 1, |
111 | CGI::textfield(-name=>'seed',-value=>$seed), |
|
|
112 | 'Mode: ', |
|
|
113 | CGI::popup_menu(-name=>'mode', -'values'=>$mode_list, |
|
|
114 | -default=>$mode), |
|
|
115 | CGI::a( |
|
|
116 | {-href=>'http://webwork.math.rochester.edu/docs/docs/pglanguage/manpages/',-target=>"manpage_window"}, |
|
|
117 | 'Manpages', |
|
|
118 | ) |
| 101 | ), |
119 | ), |
|
|
120 | CGI::p( |
|
|
121 | CGI::textarea(-name => 'problemContents', -default => $problemContents, |
|
|
122 | -rows => $rows, -columns => $columns, -override => 1, |
|
|
123 | ), |
|
|
124 | ), |
|
|
125 | CGI::p( |
|
|
126 | CGI::submit(-value=>'Save',-name=>'submit'), |
|
|
127 | $actionString |
|
|
128 | ), |
|
|
129 | CGI::a({-href=>$ce->{viewProblemURL},-target=>'_viewProblem'},'view problem'), |
|
|
130 | CGI::end_form(), |
| 102 | "<p> the parameters passed are " #FIXME -- debugging code |
131 | "<p> the parameters passed are " #FIXME -- debugging code |
| 103 | . join("<BR>", %{$r->param()}) . |
132 | . join("<BR>", %{$r->param()}) . |
| 104 | "</p> and the gatheredInfo is ", |
133 | "</p> and the gatheredInfo is ", |
| 105 | "problemPath=$problemPath<br> formURL=".$r->uri . "<br> tmpProblemPath=$tmpProblemPath<br>" , |
134 | "problemPath=$problemPath<br> formURL=".$r->uri . "<br> tmpProblemPath=$tmpProblemPath<br>" , |
|
|
135 | "viewProblemURL ".$ce->{viewProblemURL}."<br>", |
|
|
136 | "problem_obj =". $ce->{problem_obj}."<br>", |
|
|
137 | "path_components ". $ce->{path_components}; |
| 106 | |
138 | |
| 107 | ; |
139 | ; |
| 108 | |
140 | |
| 109 | } |
141 | } |
| 110 | |
142 | |
| 111 | sub initialize { |
143 | sub initialize { |
| 112 | #fix me. This is very much hacked together. In particular can we pass the key inside the post? |
144 | #fix me. This is very much hacked together. In particular can we pass the key inside the post? |
| 113 | my ($self, @path_components) = @_; |
145 | my ($self, $setName, $problemNumber) = @_; |
| 114 | my $ce = $self->{ce}; |
146 | my $ce = $self->{ce}; |
| 115 | my $r = $self->{r}; |
147 | my $r = $self->{r}; |
| 116 | my $path_info = $r->path_info || ""; |
148 | my $path_info = $r->path_info || ""; |
|
|
149 | my $db = $self->{db}; |
|
|
150 | my $user = $r->param('user'); |
|
|
151 | my $effectiveUserName = $r->param('effectiveUser'); |
|
|
152 | my $courseName = $ce->{courseName}; |
| 117 | |
153 | |
| 118 | ## Determine relative path to the file to be edited |
154 | my $set = $db->getGlobalUserSet($effectiveUserName, $setName); |
|
|
155 | my $setID = $set->set_id; |
|
|
156 | # Find URL for viewing problem |
|
|
157 | my $viewProblemURL = "/webwork/$courseName/".join("/",$setID,$problemNumber)."?" .$self->url_authen_args(); |
| 119 | |
158 | |
|
|
159 | my $problem_record = $db->getUserProblem($user,$setID,1); |
| 120 | my $templateDirectory = $self->{ce}->{courseDirs}->{templates}; |
160 | my $templateDirectory = $ce->{courseDirs}->{templates}; |
| 121 | my $problemPath = join("/",$templateDirectory,@path_components) .'.pg'; |
161 | my $problemPath = $templateDirectory."/".$problem_record->source_file; |
| 122 | |
162 | # return values. FIXME -- is this the right way to pass the values to body?? |
| 123 | |
163 | $ce->{viewProblemURL} = $viewProblemURL; |
| 124 | # find path to the temporary file |
|
|
| 125 | my $tmpDirectory = $ce->{courseDirs}->{html_temp}; |
|
|
| 126 | my $fileName = join("-", $r->param('user'),@path_components).'.pg'; |
|
|
| 127 | my $tmpProblemPath = "$tmpDirectory/$fileName"; |
|
|
| 128 | $ce->{problemPath} = $problemPath; |
164 | $ce->{problemPath} = $problemPath; |
| 129 | $ce->{tmpProblemPath} = $tmpProblemPath; |
165 | $ce->{path_components} = join("/",$setID,$problemNumber); |
|
|
166 | |
|
|
167 | # FIXME there is no way to edit in a temporary file -- all editing takes place on disk!!! |
|
|
168 | |
|
|
169 | |
|
|
170 | |
| 130 | } |
171 | } |
| 131 | |
172 | |
| 132 | # sub gatherProblemList { #workaround for obtaining the definition of a problem set (awaiting implementation of db function) |
173 | # sub gatherProblemList { #workaround for obtaining the definition of a problem set (awaiting implementation of db function) |
| 133 | # my $self = shift; |
174 | # my $self = shift; |
| 134 | # my $setName = shift; |
175 | # my $setName = shift; |