| … | |
… | |
| 16 | our $libraryName; |
16 | our $libraryName; |
| 17 | our $rowheight; |
17 | our $rowheight; |
| 18 | |
18 | |
| 19 | sub title { |
19 | sub title { |
| 20 | my $self = shift; |
20 | my $self = shift; |
|
|
21 | #FIXME don't need the entire path ?? |
| 21 | return "Instructor Tools - PG Problem Editor for ?????"; |
22 | return "Instructor Tools - PG Problem Editor for ". $self->{ce}->{problemPath}; |
| 22 | } |
23 | } |
| 23 | |
24 | |
| 24 | sub body { |
25 | sub body { |
| 25 | my $self = shift; |
26 | my $self = shift; |
| 26 | |
27 | |
| 27 | # test area |
28 | # test area |
| 28 | my $r = $self->{r}; |
29 | my $r = $self->{r}; |
| 29 | my $db = $self->{db}; |
30 | my $db = $self->{db}; |
| 30 | |
31 | my $ce = $self->{ce}; |
| 31 | my $user = $r->param('user'); |
32 | my $user = $r->param('user'); |
| 32 | my $key = $db->getKey($user)->key(); |
33 | my $key = $db->getKey($user)->key(); |
| 33 | |
34 | |
| 34 | |
35 | |
| 35 | ################ |
36 | ################ |
| 36 | # Gathering info |
37 | # Gathering info |
| 37 | # What is needed |
38 | # What is needed |
| 38 | # $problemPath -- |
39 | # $problemPath -- |
| 39 | # $formURL -- the action URL for the form |
40 | # $formURL -- given by $r->uri |
| 40 | # $tmpProblemPath |
41 | # $tmpProblemPath |
| 41 | my ($problemPath,$formURL,$tmpProblemPath) = $self->initialize(); |
42 | #my ($problemPath,$formURL,$tmpProblemPath) = $self->initialize(); |
|
|
43 | my $problemPath = $ce->{problemPath}; |
|
|
44 | |
|
|
45 | my $tmpProblemPath = $ce->{tmpProblemPath}; |
|
|
46 | |
| 42 | |
47 | |
| 43 | |
48 | |
| 44 | |
49 | |
| 45 | |
50 | |
| 46 | |
51 | |
| 47 | my $header = 'Problem Editor'; |
52 | my $header = 'Problem Editor'; |
| 48 | |
53 | |
| 49 | |
|
|
| 50 | ######################################################################### |
54 | ######################################################################### |
| 51 | # Define the popup strings used for selecting the library set directory, and the problem from that directory |
55 | # Find the text for the problem, either in the tmp file, if it exists |
| 52 | #fix me |
56 | # or in the original file in the template directory |
| 53 | # he problem of multiple selections needs to be handled properly. |
|
|
| 54 | ######################################################################### |
57 | ######################################################################### |
| 55 | # my $popUpSetDirectoryString = $self->fetchSetDirectories($setDirectory); #pass default choice as current directory |
58 | my $problemContents = ''; |
| 56 | # my $popUpPGProblemString = $self->fetchPGproblems($setDirectory); |
59 | my $editMode = (defined($r->param('problemContents')))? |
|
|
60 | 'tmpMode':'stdMode'; |
| 57 | |
61 | |
|
|
62 | if ( $editMode eq 'tmpMode') { |
|
|
63 | $problemContents = $r->param('problemContents'); |
|
|
64 | |
|
|
65 | } else { |
|
|
66 | eval { |
|
|
67 | $problemContents = WeBWorK::Utils::readFile($problemPath); |
|
|
68 | }; |
|
|
69 | $problemContents = $@ if $@; |
|
|
70 | |
|
|
71 | # create tmp file version for later use |
|
|
72 | # So that you don't need duplicate information in forms |
|
|
73 | # FIXME |
|
|
74 | # open(FILE,">$tmpProblemPath") || die "Failed to open $tmpProblemPath"; |
|
|
75 | # print FILE "tmpfileVersion\n\n" . $problemContents; |
|
|
76 | # close(FILE); |
|
|
77 | } |
|
|
78 | |
|
|
79 | # Define parameters for textarea |
|
|
80 | my $rows = 40; |
|
|
81 | my $columns = 80; |
| 58 | |
82 | |
| 59 | ######################################################################### |
83 | ######################################################################### |
| 60 | # Define a link to view the problem |
84 | # Define a link to view the problem |
| 61 | #fix me: |
85 | #fix me: |
| 62 | # Currently this link used the webwork problem library, which might be out of |
86 | # Currently this link used the webwork problem library, which might be out of |
| … | |
… | |
| 68 | ######################################################################### |
92 | ######################################################################### |
| 69 | # Format the page |
93 | # Format the page |
| 70 | ######################################################################### |
94 | ######################################################################### |
| 71 | |
95 | |
| 72 | return CGI::p($header), |
96 | return CGI::p($header), |
| 73 | |
97 | CGI::startform("POST",$r->uri), |
|
|
98 | $self->hidden_authen_fields, |
|
|
99 | CGI::textarea(-name => 'problemContents', -default => $problemContents, |
|
|
100 | -rows => $rows, -columns => $columns, -override => 1, |
|
|
101 | ), |
| 74 | "<p> the parameters passed are " #fix me -- debugging code |
102 | "<p> the parameters passed are " #FIXME -- debugging code |
| 75 | . join("<BR>", %{$r->param()}) . |
103 | . join("<BR>", %{$r->param()}) . |
| 76 | "</p> and the gatheredInfo is ", |
104 | "</p> and the gatheredInfo is ", |
| 77 | join("<br>",$self->initialize() ), |
105 | "problemPath=$problemPath<br> formURL=".$r->uri . "<br> tmpProblemPath=$tmpProblemPath<br>" , |
|
|
106 | |
| 78 | ; |
107 | ; |
| 79 | |
108 | |
| 80 | } |
109 | } |
| 81 | |
110 | |
| 82 | sub initialize { |
111 | sub initialize { |
| … | |
… | |
| 84 | my ($self, @path_components) = @_; |
113 | my ($self, @path_components) = @_; |
| 85 | my $ce = $self->{ce}; |
114 | my $ce = $self->{ce}; |
| 86 | my $r = $self->{r}; |
115 | my $r = $self->{r}; |
| 87 | my $path_info = $r->path_info || ""; |
116 | my $path_info = $r->path_info || ""; |
| 88 | |
117 | |
| 89 | ## Determine the set name |
118 | ## Determine relative path to the file to be edited |
| 90 | my $remaining_path = $path_info; |
|
|
| 91 | $remaining_path =~ s/^.*pgProblemEditor//; |
|
|
| 92 | my($junk, @components) = split "/", $remaining_path; |
|
|
| 93 | my $problemPath = $remaining_path; |
|
|
| 94 | # Find the URL for the form |
|
|
| 95 | $path_info =~s|pgProblemEditor.*$|pgProblemEditor/|; # remove trailing info, if any, from the path |
|
|
| 96 | my $formURL = "/webwork$path_info"; |
|
|
| 97 | |
119 | |
| 98 | my $tmpProblemPath = "unknown"; |
120 | my $templateDirectory = $self->{ce}->{courseDirs}->{templates}; |
|
|
121 | my $problemPath = join("/",$templateDirectory,@path_components) .'.pg'; |
| 99 | |
122 | |
| 100 | ($problemPath,$formURL,$tmpProblemPath); |
123 | |
|
|
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; |
|
|
129 | $ce->{tmpProblemPath} = $tmpProblemPath; |
| 101 | } |
130 | } |
| 102 | |
131 | |
| 103 | # sub gatherProblemList { #workaround for obtaining the definition of a problem set (awaiting implementation of db function) |
132 | # sub gatherProblemList { #workaround for obtaining the definition of a problem set (awaiting implementation of db function) |
| 104 | # my $self = shift; |
133 | # my $self = shift; |
| 105 | # my $setName = shift; |
134 | # my $setName = shift; |