| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm,v 1.47 2005/07/30 00:13:44 jj Exp $ |
| 5 | # |
5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify it under |
6 | # This program is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of either: (a) the GNU General Public License as published by the |
7 | # the terms of either: (a) the GNU General Public License as published by the |
| 8 | # Free Software Foundation; either version 2, or (at your option) any later |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
| 9 | # version, or (b) the "Artistic License" which comes with this package. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
| 10 | # |
10 | # |
| 11 | # This program is distributed in the hope that it will be useful, but WITHOUT |
11 | # This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 | # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the |
13 | # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the |
| 14 | # Artistic License for more details. |
14 | # Artistic License for more details. |
| 15 | ################################################################################ |
15 | ################################################################################ |
| 16 | |
16 | |
| 17 | |
17 | |
| 18 | package WeBWorK::ContentGenerator::Instructor::SetMaker; |
18 | package WeBWorK::ContentGenerator::Instructor::SetMaker; |
| … | |
… | |
| 27 | use strict; |
27 | use strict; |
| 28 | use warnings; |
28 | use warnings; |
| 29 | |
29 | |
| 30 | use CGI::Pretty qw(); |
30 | use CGI::Pretty qw(); |
| 31 | use WeBWorK::Form; |
31 | use WeBWorK::Form; |
| 32 | use WeBWorK::Utils qw(readDirectory max); |
32 | use WeBWorK::Utils qw(readDirectory max sortByName); |
| 33 | use WeBWorK::Utils::Tasks qw(renderProblems); |
33 | use WeBWorK::Utils::Tasks qw(renderProblems); |
|
|
34 | use File::Find; |
| 34 | |
35 | |
| 35 | require WeBWorK::Utils::ListingDB; |
36 | require WeBWorK::Utils::ListingDB; |
| 36 | |
37 | |
| 37 | |
|
|
| 38 | use constant MAX_SHOW => 20; |
38 | use constant MAX_SHOW_DEFAULT => 20; |
|
|
39 | use constant NO_LOCAL_SET_STRING => 'No sets in this course yet'; |
|
|
40 | use constant SELECT_SET_STRING => 'Select a Set from this Course'; |
|
|
41 | use constant SELECT_LOCAL_STRING => 'Select a Problem Collection'; |
|
|
42 | use constant MY_PROBLEMS => ' My Problems '; |
|
|
43 | use constant MAIN_PROBLEMS => ' Main Problems '; |
|
|
44 | use constant CREATE_SET_BUTTON => 'Create New Set'; |
|
|
45 | use constant ALL_CHAPTERS => 'All Chapters'; |
|
|
46 | use constant ALL_SUBJECTS => 'All Subjects'; |
|
|
47 | use constant ALL_SECTIONS => 'All Sections'; |
|
|
48 | use constant ALL_TEXTBOOKS => 'All Textbooks'; |
| 39 | |
49 | |
|
|
50 | use constant LIB2_DATA => { |
|
|
51 | 'dbchapter' => {name => 'library_chapters', all => 'All Chapters'}, |
|
|
52 | 'dbsection' => {name => 'library_sections', all =>'All Sections' }, |
|
|
53 | 'dbsubject' => {name => 'library_subjects', all => 'All Subjects' }, |
|
|
54 | 'textbook' => {name => 'library_textbook', all => 'All Textbooks'}, |
|
|
55 | 'textchapter' => {name => 'library_textchapter', all => 'All Chapters'}, |
|
|
56 | 'textsection' => {name => 'library_textsection', all => 'All Sections'}, |
|
|
57 | 'keywords' => {name => 'library_keywords', all => '' }, |
|
|
58 | }; |
|
|
59 | |
|
|
60 | ## Flags for operations on files |
|
|
61 | |
|
|
62 | use constant ADDED => 1; |
|
|
63 | use constant HIDDEN => (1 << 1); |
|
|
64 | use constant SUCCESS => (1 << 2); |
|
|
65 | |
|
|
66 | ## for additional problib buttons |
|
|
67 | my %problib; ## filled in in global.conf |
|
|
68 | my %ignoredir = ( |
|
|
69 | '.' => 1, '..' => 1, 'Library' => 1, |
|
|
70 | 'headers' => 1, 'macros' => 1, 'email' => 1, |
|
|
71 | ); |
|
|
72 | |
|
|
73 | ## This is for searching the disk for directories containing pg files. |
| 40 | ## to make the recursion work, this returns an array where the first |
74 | ## to make the recursion work, this returns an array where the first |
| 41 | ## item is 1 or 0 depending on whether or not the current |
75 | ## item is the number of pg files in the directory. The second is a |
| 42 | ## directory has any pg files. The second is a list of directories |
76 | ## list of directories which contain pg files. |
| 43 | ## which contain pg files. |
77 | ## |
|
|
78 | ## If a directory contains only one pg file and at least one other |
|
|
79 | ## file, the directory is considered to be part of the parent |
|
|
80 | ## directory (it is probably in a separate directory only because |
|
|
81 | ## it has auxiliarly files that want to be kept together with the |
|
|
82 | ## pg file). |
|
|
83 | ## |
|
|
84 | ## If a directory has a file named "=library-ignore", it is never |
|
|
85 | ## included in the directory menu. If a directory contains a file |
|
|
86 | ## called "=library-combine-up", then its pg are included with those |
|
|
87 | ## in the parent directory (and the directory does not appear in the |
|
|
88 | ## menu). If it has a file called "=library-no-combine" then it is |
|
|
89 | ## always listed as a separate directory even if it contains only one |
|
|
90 | ## pg file. |
|
|
91 | |
| 44 | sub get_library_sets { |
92 | sub get_library_sets { |
| 45 | my $topdir = shift; |
93 | my $top = shift; my $dir = shift; |
|
|
94 | # ignore directories that give us an error |
|
|
95 | my @lis = eval { readDirectory($dir) }; |
|
|
96 | if ($@) { |
|
|
97 | warn $@; |
|
|
98 | return (0); |
|
|
99 | } |
|
|
100 | return (0) if grep /^=library-ignore$/, @lis; |
|
|
101 | |
|
|
102 | my @pgdirs; |
|
|
103 | |
|
|
104 | my $pgcount = scalar(grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$dir/$_"} @lis); |
|
|
105 | my $others = scalar(grep { (!m/\.pg$/ || m/(Header|-text)\.pg$/) && |
|
|
106 | !m/(\.(tmp|bak)|~)$/ && -f "$dir/$_" } @lis); |
|
|
107 | |
|
|
108 | my @dirs = grep {!$ignoredir{$_} and -d "$dir/$_"} @lis; |
|
|
109 | if ($top == 1) {@dirs = grep {!$problib{$_}} @dirs} |
|
|
110 | foreach my $subdir (@dirs) { |
|
|
111 | my @results = get_library_sets(0, "$dir/$subdir"); |
|
|
112 | $pgcount += shift @results; push(@pgdirs,@results); |
|
|
113 | } |
|
|
114 | |
|
|
115 | return ($pgcount, @pgdirs) if $top || $pgcount == 0 || grep /^=library-combine-up$/, @lis; |
|
|
116 | return (0,@pgdirs,$dir) if $pgcount > 1 || $others == 0 || grep /^=library-no-combine$/, @lis; |
|
|
117 | return ($pgcount, @pgdirs); |
|
|
118 | } |
|
|
119 | |
|
|
120 | sub get_library_pgs { |
|
|
121 | my $top = shift; my $base = shift; my $dir = shift; |
| 46 | my @lis = readDirectory($topdir); |
122 | my @lis = readDirectory("$base/$dir"); |
|
|
123 | return () if grep /^=library-ignore$/, @lis; |
|
|
124 | return () if !$top && grep /^=library-no-combine$/, @lis; |
|
|
125 | |
| 47 | my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$topdir/$_"} @lis; |
126 | my @pgs = grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$base/$dir/$_"} @lis; |
| 48 | my $havepg = scalar(@pgs)>0 ? 1 : 0; |
127 | my $others = scalar(grep { (!m/\.pg$/ || m/(Header|-text)\.pg$/) && |
| 49 | my @mdirs = grep {$_ ne "." and $_ ne ".." and $_ ne "Library" |
128 | !m/(\.(tmp|bak)|~)$/ && -f "$base/$dir/$_" } @lis); |
| 50 | and -d "$topdir/$_"} @lis; |
|
|
| 51 | my ($adir, @results, @thisresult); |
|
|
| 52 | for $adir (@mdirs) { |
|
|
| 53 | @results = get_library_sets("$topdir/$adir"); |
|
|
| 54 | my $isadirok = shift @results; |
|
|
| 55 | @thisresult = (@thisresult, @results); |
|
|
| 56 | if ($isadirok) { |
|
|
| 57 | @thisresult = ("$topdir/$adir", @thisresult); |
|
|
| 58 | } |
|
|
| 59 | } |
|
|
| 60 | return(($havepg, @thisresult)); |
|
|
| 61 | } |
|
|
| 62 | |
129 | |
| 63 | ## List all the pg files in the requested directory |
130 | my @dirs = grep {!$ignoredir{$_} and -d "$base/$dir/$_"} @lis; |
|
|
131 | if ($top == 1) {@dirs = grep {!$problib{$_}} @dirs} |
|
|
132 | foreach my $subdir (@dirs) {push(@pgs, get_library_pgs(0,"$base/$dir",$subdir))} |
|
|
133 | |
|
|
134 | return () unless $top || (scalar(@pgs) == 1 && $others) || grep /^=library-combine-up$/, @lis; |
|
|
135 | return (map {"$dir/$_"} @pgs); |
|
|
136 | } |
|
|
137 | |
| 64 | sub list_pg_files { |
138 | sub list_pg_files { |
| 65 | my $templatedir = shift; |
139 | my ($templates,$dir) = @_; |
|
|
140 | my $top = ($dir eq '.')? 1 : 2; |
|
|
141 | my @pgs = get_library_pgs($top,$templates,$dir); |
|
|
142 | return sortByName(undef,@pgs); |
|
|
143 | } |
|
|
144 | |
|
|
145 | ## Search for set definition files |
|
|
146 | |
|
|
147 | # initialize global variable for search |
|
|
148 | my @found_set_defs = (); |
|
|
149 | |
|
|
150 | sub get_set_defs_wanted { |
|
|
151 | my $fn = $_; |
|
|
152 | my $fdir = $File::Find::dir; |
|
|
153 | return() if($fn !~ /^set.*\.def$/); |
|
|
154 | #return() if(not -T $fn); |
|
|
155 | push @found_set_defs, "$fdir/$fn"; |
|
|
156 | } |
|
|
157 | |
|
|
158 | sub get_set_defs { |
| 66 | my $topdir = shift; |
159 | my $topdir = shift; |
|
|
160 | @found_set_defs = (); |
|
|
161 | find({ wanted => \&get_set_defs_wanted, follow_fast=>1}, $topdir); |
|
|
162 | map { $_ =~ s|^$topdir/?|| } @found_set_defs; |
|
|
163 | return @found_set_defs; |
|
|
164 | } |
| 67 | |
165 | |
| 68 | my @lis = readDirectory("$templatedir/$topdir"); |
166 | ## Try to make reading of set defs more flexible. Additional strategies |
| 69 | my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$templatedir/$topdir/$_"} @lis; |
167 | ## for fixing a path can be added here. |
| 70 | @pgs = map { "$topdir/$_" } @pgs; |
168 | |
|
|
169 | sub munge_pg_file_path { |
|
|
170 | my $self = shift; |
|
|
171 | my $pg_path = shift; |
|
|
172 | my $path_to_set_def = shift; |
|
|
173 | my $end_path = $pg_path; |
|
|
174 | # if the path is ok, don't fix it |
|
|
175 | return($pg_path) if(-e $self->r->ce->{courseDirs}{templates}."/$pg_path"); |
|
|
176 | # if we have followed a link into a self contained course to get |
|
|
177 | # to the set.def file, we need to insert the start of the path to |
|
|
178 | # the set.def file |
|
|
179 | $end_path = "$path_to_set_def/$pg_path"; |
|
|
180 | return($end_path) if(-e $self->r->ce->{courseDirs}{templates}."/$end_path"); |
|
|
181 | # if we got this far, this path is bad, but we let it produce |
|
|
182 | # an error so the user knows there is a troublesome path in the |
|
|
183 | # set.def file. |
|
|
184 | return($pg_path); |
|
|
185 | } |
|
|
186 | |
|
|
187 | ## Read a set definition file. This could be abstracted since it happens |
|
|
188 | ## elsewhere. Here we don't have to process so much of the file. |
|
|
189 | |
|
|
190 | sub read_set_def { |
|
|
191 | my $self = shift; |
|
|
192 | my $r = $self->r; |
|
|
193 | my $filePathOrig = shift; |
|
|
194 | my $filePath = $r->ce->{courseDirs}{templates}."/$filePathOrig"; |
|
|
195 | $filePathOrig =~ s/set.*\.def$//; |
|
|
196 | $filePathOrig =~ s|/$||; |
|
|
197 | $filePathOrig = "." if ($filePathOrig !~ /\S/); |
|
|
198 | my @pg_files = (); |
|
|
199 | my ($line, $got_to_pgs, $name, @rest) = ("", 0, ""); |
|
|
200 | if ( open (SETFILENAME, "$filePath") ) { |
|
|
201 | while($line = <SETFILENAME>) { |
|
|
202 | chomp($line); |
|
|
203 | $line =~ s|(#.*)||; # don't read past comments |
|
|
204 | if($got_to_pgs) { |
|
|
205 | unless ($line =~ /\S/) {next;} # skip blank lines |
|
|
206 | ($name,@rest) = split (/\s*,\s*/,$line); |
|
|
207 | $name =~ s/\s*//g; |
|
|
208 | push @pg_files, $name; |
|
|
209 | } else { |
|
|
210 | $got_to_pgs = 1 if ($line =~ /problemList\s*=/); |
|
|
211 | } |
|
|
212 | } |
|
|
213 | } else { |
|
|
214 | $self->addbadmessage("Cannot open $filePath"); |
|
|
215 | } |
|
|
216 | # This is where we would potentially munge the pg file paths |
|
|
217 | # One possibility |
|
|
218 | @pg_files = map { $self->munge_pg_file_path($_, $filePathOrig) } @pg_files; |
| 71 | return(@pgs); |
219 | return(@pg_files); |
| 72 | } |
|
|
| 73 | |
|
|
| 74 | ## Maybe I should use this instead, returns a list |
|
|
| 75 | sub get_global_set_defs { |
|
|
| 76 | my $db = shift; |
|
|
| 77 | |
|
|
| 78 | my @globalSetIDs = $db->listGlobalSets; |
|
|
| 79 | return(@globalSetIDs); |
|
|
| 80 | } |
220 | } |
| 81 | |
221 | |
| 82 | ## go through past page getting a list of identifiers for the problems |
222 | ## go through past page getting a list of identifiers for the problems |
| 83 | ## and whether or not they are selected, and whether or not they should |
223 | ## and whether or not they are selected, and whether or not they should |
| 84 | ## be hidden |
224 | ## be hidden |
| 85 | |
225 | |
| 86 | sub get_past_problem_files { |
226 | sub get_past_problem_files { |
| 87 | my $r = shift; |
227 | my $r = shift; |
| 88 | my @found=(); |
228 | my @found=(); |
| 89 | my $count =1; |
229 | my $count =1; |
| 90 | while (defined($r->param("filetrial$count"))) { |
230 | while (defined($r->param("filetrial$count"))) { |
|
|
231 | my $val = 0; |
|
|
232 | $val |= ADDED if($r->param("trial$count")); |
|
|
233 | $val |= HIDDEN if($r->param("hideme$count")); |
| 91 | push @found, [$r->param("filetrial$count"), |
234 | push @found, [$r->param("filetrial$count"), $val]; |
| 92 | defined($r->param("trial$count")) ? $r->param("trial$count"):0, |
|
|
| 93 | defined($r->param("hideme$count")) ?$r->param("hideme$count"):0]; |
|
|
| 94 | $count++; |
235 | $count++; |
| 95 | } |
236 | } |
| 96 | return(@found); |
237 | return(\@found); |
| 97 | } |
238 | } |
| 98 | |
239 | |
| 99 | #### For adding new problems |
240 | #### For adding new problems |
| 100 | |
241 | |
| 101 | sub add_selected { |
242 | sub add_selected { |
| 102 | my $self = shift; |
243 | my $self = shift; |
| 103 | my $db = shift; |
244 | my $db = shift; |
| 104 | my $setName = shift; |
245 | my $setName = shift; |
| 105 | my @selected = @_; |
246 | my @past_problems = @{$self->{past_problems}}; |
|
|
247 | my @selected = @past_problems; |
| 106 | my (@path, $file, $selected, $freeProblemID); |
248 | my (@path, $file, $selected, $freeProblemID); |
| 107 | $freeProblemID = max($db->listGlobalProblems($setName)) + 1; |
249 | $freeProblemID = max($db->listGlobalProblems($setName)) + 1; |
|
|
250 | my $addedcount=0; |
| 108 | |
251 | |
| 109 | for $selected (@selected) { |
252 | for $selected (@selected) { |
|
|
253 | if($selected->[1] & ADDED) { |
| 110 | $file = $selected; |
254 | $file = $selected->[0]; |
| 111 | @path = split "/", $selected; |
255 | my $problemRecord = $self->addProblemToSet(setName => $setName, |
| 112 | pop @path; # Remove the file name from the path |
256 | sourceFile => $file, problemID => $freeProblemID); |
| 113 | shift @path if $path[0] eq ""; # remove the null element from the begining |
257 | $freeProblemID++; |
| 114 | my $problemRecord = $db->newGlobalProblem(); |
|
|
| 115 | $problemRecord->problem_id($freeProblemID++); |
|
|
| 116 | $problemRecord->set_id($setName); |
|
|
| 117 | $problemRecord->source_file($file); |
|
|
| 118 | $problemRecord->value("1"); |
|
|
| 119 | $problemRecord->max_attempts("-1"); |
|
|
| 120 | $db->addGlobalProblem($problemRecord); |
|
|
| 121 | $self->assignProblemToAllSetUsers($problemRecord); |
258 | $self->assignProblemToAllSetUsers($problemRecord); |
| 122 | } |
259 | $selected->[1] |= SUCCESS; |
|
|
260 | $addedcount++; |
|
|
261 | } |
|
|
262 | } |
|
|
263 | return($addedcount); |
| 123 | } |
264 | } |
| 124 | |
265 | |
| 125 | |
266 | |
| 126 | ############# List of library sets |
267 | ############# List of sets of problems in templates directory |
| 127 | |
268 | |
| 128 | sub getalllibsets { |
269 | sub get_problem_directories { |
| 129 | my $ce = shift; |
270 | my $ce = shift; |
| 130 | my @all_library_sets = get_library_sets($ce->{courseDirs}->{templates}); |
271 | my $lib = shift; |
| 131 | shift @all_library_sets; |
272 | my $source = $ce->{courseDirs}{templates}; |
|
|
273 | my $main = MY_PROBLEMS; my $isTop = 1; |
|
|
274 | if ($lib) {$source .= "/$lib"; $main = MAIN_PROBLEMS; $isTop = 2} |
|
|
275 | my @all_problem_directories = get_library_sets($isTop, $source); |
|
|
276 | my $includetop = shift @all_problem_directories; |
| 132 | my $j; |
277 | my $j; |
| 133 | for ($j=0; $j<scalar(@all_library_sets); $j++) { |
278 | for ($j=0; $j<scalar(@all_problem_directories); $j++) { |
| 134 | $all_library_sets[$j] =~ s|^$ce->{courseDirs}->{templates}/?||; |
279 | $all_problem_directories[$j] =~ s|^$ce->{courseDirs}->{templates}/?||; |
| 135 | } |
280 | } |
| 136 | @all_library_sets = sort @all_library_sets; |
281 | @all_problem_directories = sortByName(undef, @all_problem_directories); |
| 137 | return (\@all_library_sets); |
282 | unshift @all_problem_directories, $main if($includetop); |
|
|
283 | return (\@all_problem_directories); |
| 138 | } |
284 | } |
|
|
285 | |
|
|
286 | ############# Everyone has a view problems line. Abstract it |
|
|
287 | sub view_problems_line { |
|
|
288 | my $internal_name = shift; |
|
|
289 | my $label = shift; |
|
|
290 | my $r = shift; # so we can get parameter values |
|
|
291 | my $result = CGI::submit(-name=>"$internal_name", -value=>$label); |
|
|
292 | |
|
|
293 | my %display_modes = %{WeBWorK::PG::DISPLAY_MODES()}; |
|
|
294 | my @active_modes = grep { exists $display_modes{$_} } |
|
|
295 | @{$r->ce->{pg}->{displayModes}}; |
|
|
296 | push @active_modes, 'None'; |
|
|
297 | # We have our own displayMode since its value may be None, which is illegal |
|
|
298 | # in other modules. |
|
|
299 | my $mydisplayMode = $r->param('mydisplayMode') || $r->ce->{pg}->{options}->{displayMode}; |
|
|
300 | $result .= ' Display Mode: '.CGI::popup_menu(-name=> 'mydisplayMode', |
|
|
301 | -values=>\@active_modes, |
|
|
302 | -default=> $mydisplayMode); |
|
|
303 | # Now we give a choice of the number of problems to show |
|
|
304 | my $defaultMax = $r->param('max_shown') || MAX_SHOW_DEFAULT; |
|
|
305 | $result .= ' Max. Shown: '. |
|
|
306 | CGI::popup_menu(-name=> 'max_shown', |
|
|
307 | -values=>[5,10,15,20,25,30,50,'All'], |
|
|
308 | -default=> $defaultMax); |
|
|
309 | |
|
|
310 | return($result); |
|
|
311 | } |
|
|
312 | |
| 139 | |
313 | |
| 140 | ### The browsing panel has three versions |
314 | ### The browsing panel has three versions |
| 141 | ##### Version 1 is local problems |
315 | ##### Version 1 is local problems |
| 142 | sub browse_local_panel { |
316 | sub browse_local_panel { |
| 143 | my $self = shift; |
317 | my $self = shift; |
| 144 | my $library_selected = shift; |
318 | my $library_selected = shift; |
|
|
319 | my $lib = shift || ''; $lib =~ s/^browse_//; |
|
|
320 | my $name = ($lib eq '')? 'Local' : $problib{$lib}; |
| 145 | |
321 | |
| 146 | my $list_of_sets= getalllibsets($self->r->ce); |
322 | my $list_of_prob_dirs= get_problem_directories($self->r->ce,$lib); |
| 147 | my $libstr = ""; |
323 | if(scalar(@$list_of_prob_dirs) == 0) { |
| 148 | my $default_value = "Select a Local Problem Collection"; |
324 | $library_selected = "Found no directories containing problems"; |
| 149 | $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg}); |
325 | unshift @{$list_of_prob_dirs}, $library_selected; |
| 150 | |
326 | } else { |
|
|
327 | my $default_value = SELECT_LOCAL_STRING; |
| 151 | if (not $library_selected or $library_selected eq $default_value) { |
328 | if (not $library_selected or $library_selected eq $default_value) { |
| 152 | unshift @{$list_of_sets}, $default_value; |
329 | unshift @{$list_of_prob_dirs}, $default_value; |
| 153 | $library_selected = $default_value; |
330 | $library_selected = $default_value; |
| 154 | } |
331 | } |
| 155 | |
332 | } |
| 156 | |
333 | my $view_problem_line = view_problems_line('view_local_set', 'View Problems', $self->r); |
| 157 | print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Local Problems: ", |
334 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, "$name Problems: ", |
| 158 | CGI::popup_menu(-name=> 'library_sets', |
335 | CGI::popup_menu(-name=> 'library_sets', |
| 159 | -values=>$list_of_sets, |
336 | -values=>$list_of_prob_dirs, |
| 160 | -default=> $library_selected), |
337 | -default=> $library_selected), |
| 161 | CGI::br(), |
338 | CGI::br(), |
| 162 | CGI::submit(-name=>"view_local_set", -value=>"View Problems"), |
339 | $view_problem_line, |
| 163 | $libstr |
340 | )); |
| 164 | )); |
|
|
| 165 | } |
341 | } |
| 166 | |
342 | |
| 167 | ##### Version 2 is local problem sets |
343 | ##### Version 2 is local problem sets |
| 168 | sub browse_mysets_panel { |
344 | sub browse_mysets_panel { |
| 169 | my $self = shift; |
345 | my $self = shift; |
| 170 | my $library_selected = shift; |
346 | my $library_selected = shift; |
| 171 | my $list_of_local_sets = shift; |
347 | my $list_of_local_sets = shift; |
| 172 | my $default_value = "Select a Problem Set"; |
348 | my $default_value = "Select a Homework Set"; |
| 173 | |
349 | |
| 174 | my $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg}); |
350 | if(scalar(@$list_of_local_sets) == 0) { |
| 175 | |
351 | $list_of_local_sets = [NO_LOCAL_SET_STRING]; |
| 176 | if (not $library_selected or $library_selected eq $default_value) { |
352 | } elsif (not $library_selected or $library_selected eq $default_value) { |
| 177 | unshift @{$list_of_local_sets}, $default_value; |
353 | unshift @{$list_of_local_sets}, $default_value; |
| 178 | $library_selected = $default_value; |
354 | $library_selected = $default_value; |
| 179 | } |
355 | } |
| 180 | |
356 | |
|
|
357 | my $view_problem_line = view_problems_line('view_mysets_set', 'View Problems', $self->r); |
| 181 | print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Browse from: ", |
358 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, "Browse from: ", |
| 182 | CGI::popup_menu(-name=> 'library_sets', |
359 | CGI::popup_menu(-name=> 'library_sets', |
| 183 | -values=>$list_of_local_sets, |
360 | -values=>$list_of_local_sets, |
| 184 | -default=> $library_selected), |
361 | -default=> $library_selected), |
| 185 | CGI::br(), |
362 | CGI::br(), |
| 186 | CGI::submit(-name=>"view_mysets_set", -value=>"View This Set"), |
363 | $view_problem_line |
| 187 | $libstr |
364 | )); |
| 188 | )); |
|
|
| 189 | } |
365 | } |
| 190 | |
366 | |
| 191 | ##### Version 3 is the problem library |
367 | ##### Version 3 is the problem library |
|
|
368 | # |
|
|
369 | # This comes in 3 forms, problem library version 1, and for version 2 there |
|
|
370 | # is the basic, and the advanced interfaces. This function checks what we are |
|
|
371 | # supposed to do, or aborts if the problem library has not been installed. |
| 192 | |
372 | |
| 193 | |
|
|
| 194 | # There a different levels, and you can pick a new chapter, |
|
|
| 195 | # pick a new section, pick all from chapter, pick all from section |
|
|
| 196 | # |
|
|
| 197 | # Incoming data - current chapter, current section |
|
|
| 198 | sub browse_library_panel { |
373 | sub browse_library_panel { |
| 199 | my $self = shift; |
374 | my $self=shift; |
| 200 | my $r = $self->r; |
375 | my $r = $self->r; |
|
|
376 | my $ce = $r->ce; |
| 201 | |
377 | |
| 202 | my $libraryRoot = $r->{ce}->{webworkDirs}->{libraryRoot}; |
378 | # See if the problem library is installed |
|
|
379 | my $libraryRoot = $r->{ce}->{problemLibrary}->{root}; |
| 203 | |
380 | |
| 204 | unless($libraryRoot) { |
381 | unless($libraryRoot) { |
| 205 | print CGI::Tr(CGI::td(CGI::div({class=>'ResultsWithError', align=>"center"}, |
382 | print CGI::Tr(CGI::td(CGI::div({class=>'ResultsWithError', align=>"center"}, |
| 206 | "The problem library has not been installed."))); |
383 | "The problem library has not been installed."))); |
| 207 | return; |
384 | return; |
| 208 | } |
385 | } |
|
|
386 | # Test if the Library directory link exists. If not, try to make it |
|
|
387 | unless(-d "$ce->{courseDirs}->{templates}/Library") { |
|
|
388 | unless(symlink($libraryRoot, "$ce->{courseDirs}->{templates}/Library")) { |
|
|
389 | my $msg = <<"HERE"; |
|
|
390 | You are missing the directory <code>templates/Library</code>, which is needed |
|
|
391 | for the Problem Library to function. It should be a link pointing to |
|
|
392 | <code>$libraryRoot</code>, which you set in <code>conf/global.conf</code>. |
|
|
393 | I tried to make the link for you, but that failed. Check the permissions |
|
|
394 | in your <code>templates</code> directory. |
|
|
395 | HERE |
|
|
396 | $self->addbadmessage($msg); |
|
|
397 | } |
|
|
398 | } |
| 209 | |
399 | |
| 210 | my $default_chap = "All Chapters"; |
400 | # Now check what version we are supposed to use |
| 211 | my $default_sect = "All Sections"; |
401 | my $libraryVersion = $r->{ce}->{problemLibrary}->{version} || 1; |
|
|
402 | if($libraryVersion == 1) { |
|
|
403 | return $self->browse_library_panel1; |
|
|
404 | } elsif($libraryVersion == 2) { |
|
|
405 | return $self->browse_library_panel2 if($self->{library_basic}==1); |
|
|
406 | return $self->browse_library_panel2adv; |
|
|
407 | } else { |
|
|
408 | print CGI::Tr(CGI::td(CGI::div({class=>'ResultsWithError', align=>"center"}, |
|
|
409 | "The problem library version is set to an illegal value."))); |
|
|
410 | return; |
|
|
411 | } |
|
|
412 | } |
| 212 | |
413 | |
| 213 | my $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg}); |
414 | sub browse_library_panel1 { |
| 214 | |
415 | my $self = shift; |
|
|
416 | my $r = $self->r; |
|
|
417 | my $ce = $r->ce; |
|
|
418 | |
| 215 | my @chaps = WeBWorK::Utils::ListingDB::getAllChapters($r->{ce}); |
419 | my @chaps = WeBWorK::Utils::ListingDB::getAllChapters($r->{ce}); |
| 216 | unshift @chaps, $default_chap; |
420 | unshift @chaps, LIB2_DATA->{dbchapter}{all}; |
| 217 | my $chapter_selected = $r->param('library_chapters') || $default_chap; |
421 | my $chapter_selected = $r->param('library_chapters') || LIB2_DATA->{dbchapter}->{all}; |
| 218 | |
422 | |
| 219 | my @sects=(); |
423 | my @sects=(); |
| 220 | if ($chapter_selected ne $default_chap) { |
424 | if ($chapter_selected ne LIB2_DATA->{dbchapter}{all}) { |
| 221 | @sects = WeBWorK::Utils::ListingDB::getAllSections($r->{ce}, $chapter_selected); |
425 | @sects = WeBWorK::Utils::ListingDB::getAllSections($r->{ce}, $chapter_selected); |
| 222 | } |
426 | } |
| 223 | |
427 | |
| 224 | my @textbooks = ('Textbook info not ready'); |
428 | unshift @sects, ALL_SECTIONS; |
| 225 | |
|
|
| 226 | unshift @sects, $default_sect; |
|
|
| 227 | my $section_selected = $r->param('library_sections') || $default_sect; |
429 | my $section_selected = $r->param('library_sections') || LIB2_DATA->{dbsection}{all}; |
| 228 | |
430 | |
|
|
431 | my $view_problem_line = view_problems_line('lib_view', 'View Problems', $self->r); |
|
|
432 | |
| 229 | print CGI::Tr(CGI::td({-class=>"InfoPanel"}, |
433 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, |
| 230 | CGI::start_table(), |
434 | CGI::start_table(), |
| 231 | CGI::Tr( |
435 | CGI::Tr( |
| 232 | CGI::td(["Chapter:", |
436 | CGI::td(["Chapter:", |
| 233 | CGI::popup_menu(-name=> 'library_chapters', |
437 | CGI::popup_menu(-name=> 'library_chapters', |
| 234 | -values=>\@chaps, |
438 | -values=>\@chaps, |
| 235 | -default=> $chapter_selected, |
439 | -default=> $chapter_selected, |
| 236 | -onchange=>"submit();return true" |
440 | -onchange=>"submit();return true" |
| 237 | ), |
441 | ), |
| 238 | CGI::submit(-name=>"lib_select_chapter", -value=>"Update Section List")])), |
442 | CGI::submit(-name=>"lib_select_chapter", -value=>"Update Section List")])), |
| 239 | CGI::Tr( |
443 | CGI::Tr( |
| 240 | CGI::td("Section:"), |
444 | CGI::td("Section:"), |
| 241 | CGI::td({-colspan=>2}, |
445 | CGI::td({-colspan=>2}, |
| 242 | CGI::popup_menu(-name=> 'library_sections', |
446 | CGI::popup_menu(-name=> 'library_sections', |
| 243 | -values=>\@sects, |
447 | -values=>\@sects, |
| 244 | -default=> $section_selected |
448 | -default=> $section_selected |
| 245 | ))), |
449 | ))), |
| 246 | |
450 | |
| 247 | # CGI::Tr( |
451 | CGI::Tr(CGI::td({-colspan=>3}, $view_problem_line)), |
| 248 | # CGI::td("Textbook:"), |
|
|
| 249 | # CGI::td({-colspan=>2}, |
|
|
| 250 | # CGI::popup_menu(-name=> 'library_textbooks', |
|
|
| 251 | # -values=>\@textbooks, |
|
|
| 252 | # # -default=> $section_selected |
|
|
| 253 | # ))), |
|
|
| 254 | |
|
|
| 255 | # CGI::Tr( |
|
|
| 256 | # CGI::td("Keywords:"), |
|
|
| 257 | # CGI::td({-colspan=>2}, CGI::textfield(-name=>"keywords", |
|
|
| 258 | # -default=>"Keywords not implemented yet", |
|
|
| 259 | # -override=>1, -size=>60))), |
|
|
| 260 | CGI::Tr(CGI::td({-colspan=>3},CGI::submit(-name=>"lib_view", -value=>"View Problems"))), |
|
|
| 261 | CGI::end_table(), |
452 | CGI::end_table(), |
| 262 | $libstr |
453 | )); |
| 263 | )); |
454 | } |
|
|
455 | |
|
|
456 | sub browse_library_panel2 { |
|
|
457 | my $self = shift; |
|
|
458 | my $r = $self->r; |
|
|
459 | my $ce = $r->ce; |
|
|
460 | |
|
|
461 | my @subjs = WeBWorK::Utils::ListingDB::getAllDBsubjects($r); |
|
|
462 | unshift @subjs, LIB2_DATA->{dbsubject}{all}; |
|
|
463 | |
|
|
464 | my @chaps = WeBWorK::Utils::ListingDB::getAllDBchapters($r); |
|
|
465 | unshift @chaps, LIB2_DATA->{dbchapter}{all}; |
|
|
466 | |
|
|
467 | my @sects=(); |
|
|
468 | @sects = WeBWorK::Utils::ListingDB::getAllDBsections($r); |
|
|
469 | unshift @sects, LIB2_DATA->{dbsection}{all}; |
|
|
470 | |
|
|
471 | my $subject_selected = $r->param('library_subjects') || LIB2_DATA->{dbsubject}{all}; |
|
|
472 | my $chapter_selected = $r->param('library_chapters') || LIB2_DATA->{dbchapter}{all}; |
|
|
473 | my $section_selected = $r->param('library_sections') || LIB2_DATA->{dbsection}{all}; |
|
|
474 | |
|
|
475 | my $view_problem_line = view_problems_line('lib_view', 'View Problems', $self->r); |
|
|
476 | |
|
|
477 | my $count_line = WeBWorK::Utils::ListingDB::countDBListings($r); |
|
|
478 | if($count_line==0) { |
|
|
479 | $count_line = "There are no matching pg files"; |
|
|
480 | } else { |
|
|
481 | $count_line = "There are $count_line matching WeBWorK problem files"; |
|
|
482 | } |
|
|
483 | |
|
|
484 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, |
|
|
485 | CGI::hidden(-name=>"library_is_basic", -default=>[1]), |
|
|
486 | CGI::start_table({-width=>"100%"}), |
|
|
487 | CGI::Tr( |
|
|
488 | CGI::td(["Subject:", |
|
|
489 | CGI::popup_menu(-name=> 'library_subjects', |
|
|
490 | -values=>\@subjs, |
|
|
491 | -default=> $subject_selected, |
|
|
492 | -onchange=>"submit();return true" |
|
|
493 | )]), |
|
|
494 | CGI::td({-colspan=>2, -align=>"right"}, |
|
|
495 | CGI::submit(-name=>"lib_select_subject", -value=>"Update Chapter/Section Lists")) |
|
|
496 | ), |
|
|
497 | CGI::Tr( |
|
|
498 | CGI::td(["Chapter:", |
|
|
499 | CGI::popup_menu(-name=> 'library_chapters', |
|
|
500 | -values=>\@chaps, |
|
|
501 | -default=> $chapter_selected, |
|
|
502 | -onchange=>"submit();return true" |
|
|
503 | )]), |
|
|
504 | CGI::td({-colspan=>2, -align=>"right"}, |
|
|
505 | CGI::submit(-name=>"library_advanced", -value=>"Advanced Search")) |
|
|
506 | ), |
|
|
507 | CGI::Tr( |
|
|
508 | CGI::td(["Section:", |
|
|
509 | CGI::popup_menu(-name=> 'library_sections', |
|
|
510 | -values=>\@sects, |
|
|
511 | -default=> $section_selected, |
|
|
512 | -onchange=>"submit();return true" |
|
|
513 | )]), |
|
|
514 | ), |
|
|
515 | CGI::Tr(CGI::td({-colspan=>3}, $view_problem_line)), |
|
|
516 | CGI::Tr(CGI::td({-colspan=>3, -align=>"center"}, $count_line)), |
|
|
517 | CGI::end_table(), |
|
|
518 | )); |
|
|
519 | |
|
|
520 | } |
|
|
521 | |
|
|
522 | sub browse_library_panel2adv { |
|
|
523 | my $self = shift; |
|
|
524 | my $r = $self->r; |
|
|
525 | my $ce = $r->ce; |
|
|
526 | my $right_button_style = "width: 18ex"; |
|
|
527 | |
|
|
528 | my @subjs = WeBWorK::Utils::ListingDB::getAllDBsubjects($r); |
|
|
529 | if(! grep { $_ eq $r->param('library_subjects') } @subjs) { |
|
|
530 | $r->param('library_subjects', ''); |
|
|
531 | } |
|
|
532 | unshift @subjs, LIB2_DATA->{dbsubject}{all}; |
|
|
533 | |
|
|
534 | my @chaps = WeBWorK::Utils::ListingDB::getAllDBchapters($r); |
|
|
535 | if(! grep { $_ eq $r->param('library_chapters') } @chaps) { |
|
|
536 | $r->param('library_chapters', ''); |
|
|
537 | } |
|
|
538 | unshift @chaps, LIB2_DATA->{dbchapter}{all}; |
|
|
539 | |
|
|
540 | my @sects = WeBWorK::Utils::ListingDB::getAllDBsections($r); |
|
|
541 | if(! grep { $_ eq $r->param('library_sections') } @sects) { |
|
|
542 | $r->param('library_sections', ''); |
|
|
543 | } |
|
|
544 | unshift @sects, LIB2_DATA->{dbsection}{all}; |
|
|
545 | |
|
|
546 | my $texts = WeBWorK::Utils::ListingDB::getDBTextbooks($r); |
|
|
547 | my @textarray = map { $_->[0] } @{$texts}; |
|
|
548 | my %textlabels = (); |
|
|
549 | for my $ta (@{$texts}) { |
|
|
550 | $textlabels{$ta->[0]} = $ta->[1]." by ".$ta->[2]." (edition ".$ta->[3].")"; |
|
|
551 | } |
|
|
552 | if(! grep { $_ eq $r->param('library_textbook') } @textarray) { |
|
|
553 | $r->param('library_textbook', ''); |
|
|
554 | } |
|
|
555 | unshift @textarray, LIB2_DATA->{textbook}{all}; |
|
|
556 | my $atb = LIB2_DATA->{textbook}{all}; $textlabels{$atb} = LIB2_DATA->{textbook}{all}; |
|
|
557 | |
|
|
558 | my $textchap_ref = WeBWorK::Utils::ListingDB::getDBTextbooks($r, 'textchapter'); |
|
|
559 | my @textchaps = map { $_->[0] } @{$textchap_ref}; |
|
|
560 | if(! grep { $_ eq $r->param('library_textchapter') } @textchaps) { |
|
|
561 | $r->param('library_textchapter', ''); |
|
|
562 | } |
|
|
563 | unshift @textchaps, LIB2_DATA->{textchapter}{all}; |
|
|
564 | |
|
|
565 | my $textsec_ref = WeBWorK::Utils::ListingDB::getDBTextbooks($r, 'textsection'); |
|
|
566 | my @textsecs = map { $_->[0] } @{$textsec_ref}; |
|
|
567 | if(! grep { $_ eq $r->param('library_textsection') } @textsecs) { |
|
|
568 | $r->param('library_textsection', ''); |
|
|
569 | } |
|
|
570 | unshift @textsecs, LIB2_DATA->{textsection}{all}; |
|
|
571 | |
|
|
572 | my %selected = (); |
|
|
573 | for my $j (qw( dbsection dbchapter dbsubject textbook textchapter textsection )) { |
|
|
574 | $selected{$j} = $r->param(LIB2_DATA->{$j}{name}) || LIB2_DATA->{$j}{all}; |
|
|
575 | } |
|
|
576 | |
|
|
577 | my $text_popup = CGI::popup_menu(-name => 'library_textbook', |
|
|
578 | -values =>\@textarray, |
|
|
579 | -labels => \%textlabels, |
|
|
580 | -default=>$selected{textbook}, |
|
|
581 | -onchange=>"submit();return true"); |
|
|
582 | |
|
|
583 | |
|
|
584 | my $library_keywords = $r->param('library_keywords') || ''; |
|
|
585 | |
|
|
586 | my $view_problem_line = view_problems_line('lib_view', 'View Problems', $self->r); |
|
|
587 | |
|
|
588 | my $count_line = WeBWorK::Utils::ListingDB::countDBListings($r); |
|
|
589 | if($count_line==0) { |
|
|
590 | $count_line = "There are no matching pg files"; |
|
|
591 | } else { |
|
|
592 | $count_line = "There are $count_line matching WeBWorK problem files"; |
|
|
593 | } |
|
|
594 | |
|
|
595 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, |
|
|
596 | CGI::hidden(-name=>"library_is_basic", -default=>[2]), |
|
|
597 | CGI::start_table({-width=>"100%"}), |
|
|
598 | # Html done by hand since it is temporary |
|
|
599 | CGI::Tr(CGI::td({-colspan=>4, -align=>"center"}, 'All Selected Constraints Joined by "And"')), |
|
|
600 | CGI::Tr( |
|
|
601 | CGI::td(["Subject:", |
|
|
602 | CGI::popup_menu(-name=> 'library_subjects', |
|
|
603 | -values=>\@subjs, |
|
|
604 | -default=> $selected{dbsubject}, |
|
|
605 | -onchange=>"submit();return true" |
|
|
606 | )]), |
|
|
607 | CGI::td({-colspan=>2, -align=>"right"}, |
|
|
608 | CGI::submit(-name=>"lib_select_subject", -value=>"Update Menus", |
|
|
609 | -style=> $right_button_style))), |
|
|
610 | CGI::Tr( |
|
|
611 | CGI::td(["Chapter:", |
|
|
612 | CGI::popup_menu(-name=> 'library_chapters', |
|
|
613 | -values=>\@chaps, |
|
|
614 | -default=> $selected{dbchapter}, |
|
|
615 | -onchange=>"submit();return true" |
|
|
616 | )]), |
|
|
617 | CGI::td({-colspan=>2, -align=>"right"}, |
|
|
618 | CGI::submit(-name=>"library_reset", -value=>"Reset", |
|
|
619 | -style=>$right_button_style)) |
|
|
620 | ), |
|
|
621 | CGI::Tr( |
|
|
622 | CGI::td(["Section:", |
|
|
623 | CGI::popup_menu(-name=> 'library_sections', |
|
|
624 | -values=>\@sects, |
|
|
625 | -default=> $selected{dbsection}, |
|
|
626 | -onchange=>"submit();return true" |
|
|
627 | )]), |
|
|
628 | CGI::td({-colspan=>2, -align=>"right"}, |
|
|
629 | CGI::submit(-name=>"library_basic", -value=>"Basic Search", |
|
|
630 | -style=>$right_button_style)) |
|
|
631 | ), |
|
|
632 | CGI::Tr( |
|
|
633 | CGI::td(["Textbook:", $text_popup]), |
|
|
634 | ), |
|
|
635 | CGI::Tr( |
|
|
636 | CGI::td(["Text chapter:", |
|
|
637 | CGI::popup_menu(-name=> 'library_textchapter', |
|
|
638 | -values=>\@textchaps, |
|
|
639 | -default=> $selected{textchapter}, |
|
|
640 | -onchange=>"submit();return true" |
|
|
641 | )]), |
|
|
642 | ), |
|
|
643 | CGI::Tr( |
|
|
644 | CGI::td(["Text section:", |
|
|
645 | CGI::popup_menu(-name=> 'library_textsection', |
|
|
646 | -values=>\@textsecs, |
|
|
647 | -default=> $selected{textsection}, |
|
|
648 | -onchange=>"submit();return true" |
|
|
649 | )]), |
|
|
650 | ), |
|
|
651 | CGI::Tr(CGI::td("Keywords:"),CGI::td({-colspan=>2}, |
|
|
652 | CGI::textfield(-name=>"library_keywords", |
|
|
653 | -default=>$library_keywords, |
|
|
654 | -override=>1, |
|
|
655 | -size=>40))), |
|
|
656 | CGI::Tr(CGI::td({-colspan=>3}, $view_problem_line)), |
|
|
657 | CGI::Tr(CGI::td({-colspan=>3, -align=>"center"}, $count_line)), |
|
|
658 | CGI::end_table(), |
|
|
659 | )); |
|
|
660 | |
|
|
661 | } |
|
|
662 | |
|
|
663 | |
|
|
664 | ##### Version 4 is the set definition file panel |
|
|
665 | |
|
|
666 | sub browse_setdef_panel { |
|
|
667 | my $self = shift; |
|
|
668 | my $r = $self->r; |
|
|
669 | my $ce = $r->ce; |
|
|
670 | my $library_selected = shift; |
|
|
671 | my $default_value = "Select a Set Definition File"; |
|
|
672 | my @list_of_set_defs = get_set_defs($ce->{courseDirs}{templates}); |
|
|
673 | if(scalar(@list_of_set_defs) == 0) { |
|
|
674 | @list_of_set_defs = (NO_LOCAL_SET_STRING); |
|
|
675 | } elsif (not $library_selected or $library_selected eq $default_value) { |
|
|
676 | unshift @list_of_set_defs, $default_value; |
|
|
677 | $library_selected = $default_value; |
|
|
678 | } |
|
|
679 | my $view_problem_line = view_problems_line('view_setdef_set', 'View Problems', $self->r); |
|
|
680 | my $popupetc = CGI::popup_menu(-name=> 'library_sets', |
|
|
681 | -values=>\@list_of_set_defs, |
|
|
682 | -default=> $library_selected). |
|
|
683 | CGI::br(). $view_problem_line; |
|
|
684 | if($list_of_set_defs[0] eq NO_LOCAL_SET_STRING) { |
|
|
685 | $popupetc = "there are no set definition files in this course to look at." |
|
|
686 | } |
|
|
687 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, "Browse from: ", |
|
|
688 | $popupetc |
|
|
689 | )); |
| 264 | } |
690 | } |
| 265 | |
691 | |
| 266 | sub make_top_row { |
692 | sub make_top_row { |
| 267 | my $self = shift; |
693 | my $self = shift; |
| 268 | my $r = $self->r; |
694 | my $r = $self->r; |
|
|
695 | my $ce = $r->ce; |
| 269 | my %data = @_; |
696 | my %data = @_; |
| 270 | |
697 | |
| 271 | my $list_of_local_sets = $data{all_set_defs}; |
698 | my $list_of_local_sets = $data{all_db_sets}; |
|
|
699 | my $have_local_sets = scalar(@$list_of_local_sets); |
| 272 | my $browse_which = $data{browse_which}; |
700 | my $browse_which = $data{browse_which}; |
| 273 | my $library_selected = $r->param('library_sets'); |
701 | my $library_selected = $r->param('library_sets'); |
| 274 | my $set_selected = $r->param('local_sets'); |
702 | my $set_selected = $r->param('local_sets'); |
| 275 | |
703 | |
| 276 | my $list_of_sets; |
|
|
| 277 | my ($dis1, $dis2, $dis3) = ("","",""); |
704 | my ($dis1, $dis2, $dis3, $dis4) = ("","","", ""); |
| 278 | $dis1 = '-disabled' if($browse_which eq 'browse_library'); |
705 | $dis1 = '-disabled' if($browse_which eq 'browse_library'); |
| 279 | $dis2 = '-disabled' if($browse_which eq 'browse_local'); |
706 | $dis2 = '-disabled' if($browse_which eq 'browse_local'); |
| 280 | $dis3 = '-disabled' if($browse_which eq 'browse_mysets'); |
707 | $dis3 = '-disabled' if($browse_which eq 'browse_mysets'); |
|
|
708 | $dis4 = '-disabled' if($browse_which eq 'browse_setdefs'); |
| 281 | |
709 | |
| 282 | my $locstr = ""; |
710 | ## Make buttons for additional problem libraries |
| 283 | $locstr = CGI::br() . CGI::em($self->{localmsg}) if($self->{localmsg}); |
711 | my $libs = ''; |
|
|
712 | foreach my $lib (sort(keys(%problib))) { |
|
|
713 | $libs .= ' '. CGI::submit(-name=>"browse_$lib", -value=>$problib{$lib}, |
|
|
714 | ($browse_which eq "browse_$lib")? '-disabled': '') |
|
|
715 | if (-d "$ce->{courseDirs}{templates}/$lib"); |
|
|
716 | } |
|
|
717 | $libs = CGI::br()."or Problems from".$libs if $libs ne ''; |
| 284 | |
718 | |
| 285 | my $these_widths = "width: 27ex"; |
719 | my $these_widths = "width: 23ex"; |
|
|
720 | |
|
|
721 | if($have_local_sets ==0) { |
|
|
722 | $list_of_local_sets = [NO_LOCAL_SET_STRING]; |
|
|
723 | } elsif (not $set_selected or $set_selected eq SELECT_SET_STRING) { |
|
|
724 | unshift @{$list_of_local_sets}, SELECT_SET_STRING; |
|
|
725 | $set_selected = SELECT_SET_STRING; |
|
|
726 | } |
|
|
727 | my $myjs = 'document.mainform.selfassign.value=confirm("Should I assign the new set to you now?\nUse OK for yes and Cancel for no.");true;'; |
|
|
728 | |
| 286 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"center"}, |
729 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, "Add problems to ", |
| 287 | CGI::submit(-name=>"browse_library", -value=>"Browse Problem Library", -style=>$these_widths, $dis1), |
730 | CGI::b("Target Set: "), |
| 288 | CGI::submit(-name=>"browse_local", -value=>"Browse Local Problems", -style=>$these_widths, $dis2), |
|
|
| 289 | CGI::submit(-name=>"browse_mysets", -value=>"Browse From This Course", -style=>$these_widths, $dis3), |
|
|
| 290 | )); |
|
|
| 291 | |
|
|
| 292 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
|
|
| 293 | |
|
|
| 294 | if ($browse_which eq 'browse_local') { |
|
|
| 295 | browse_local_panel($self, $library_selected); |
|
|
| 296 | } elsif ($browse_which eq 'browse_mysets') { |
|
|
| 297 | browse_mysets_panel($self, $library_selected, $list_of_local_sets); |
|
|
| 298 | } else { |
|
|
| 299 | browse_library_panel($self); |
|
|
| 300 | } |
|
|
| 301 | |
|
|
| 302 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
|
|
| 303 | |
|
|
| 304 | if (not $set_selected or $set_selected eq "Select a Set for This Course") { |
|
|
| 305 | if ($list_of_local_sets->[0] eq "Select a Problem Set") { |
|
|
| 306 | shift @{$list_of_local_sets}; |
|
|
| 307 | } |
|
|
| 308 | unshift @{$list_of_local_sets}, "Select a Set for This Course"; |
|
|
| 309 | $set_selected = "Select a Set for This Course"; |
|
|
| 310 | } |
|
|
| 311 | |
|
|
| 312 | print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Current Set: ", |
|
|
| 313 | CGI::popup_menu(-name=> 'local_sets', |
731 | CGI::popup_menu(-name=> 'local_sets', |
| 314 | -values=>$list_of_local_sets, |
732 | -values=>$list_of_local_sets, |
| 315 | -default=> $set_selected), |
733 | -default=> $set_selected), |
| 316 | CGI::submit(-name=>"edit_local", -value=>"Edit Current Set"), |
734 | CGI::submit(-name=>"edit_local", -value=>"Edit Target Set"), |
|
|
735 | CGI::hidden(-name=>"selfassign", -default=>[0]). |
| 317 | CGI::br(), |
736 | CGI::br(), |
| 318 | CGI::br(), |
737 | CGI::br(), |
| 319 | CGI::submit(-name=>"new_local_set", -value=>"Create New Local Set:"), |
738 | CGI::submit(-name=>"new_local_set", -value=>"Create a New Set in This Course:", |
|
|
739 | -onclick=>$myjs |
|
|
740 | ), |
| 320 | " ", |
741 | " ", |
| 321 | CGI::textfield(-name=>"new_set_name", |
742 | CGI::textfield(-name=>"new_set_name", |
| 322 | -default=>"Name for new set here", |
743 | -default=>"Name for new set here", |
| 323 | -override=>1, -size=>30), |
744 | -override=>1, -size=>30), |
| 324 | CGI::br(), |
745 | )); |
| 325 | $locstr |
|
|
| 326 | )); |
|
|
| 327 | |
746 | |
| 328 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
747 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
| 329 | |
748 | |
|
|
749 | # Tidy this list up since it is used in two different places |
|
|
750 | if ($list_of_local_sets->[0] eq SELECT_SET_STRING) { |
|
|
751 | shift @{$list_of_local_sets}; |
|
|
752 | } |
|
|
753 | |
| 330 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"center"}, |
754 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"center"}, |
|
|
755 | "Browse ", |
|
|
756 | CGI::submit(-name=>"browse_library", -value=>"Problem Library", -style=>$these_widths, $dis1), |
|
|
757 | CGI::submit(-name=>"browse_local", -value=>"Local Problems", -style=>$these_widths, $dis2), |
|
|
758 | CGI::submit(-name=>"browse_mysets", -value=>"From This Course", -style=>$these_widths, $dis3), |
|
|
759 | CGI::submit(-name=>"browse_setdefs", -value=>"Set Definition Files", -style=>$these_widths, $dis4), |
|
|
760 | $libs, |
|
|
761 | )); |
|
|
762 | |
|
|
763 | #print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
|
|
764 | print CGI::hr(); |
|
|
765 | |
|
|
766 | if ($browse_which eq 'browse_local') { |
|
|
767 | $self->browse_local_panel($library_selected); |
|
|
768 | } elsif ($browse_which eq 'browse_mysets') { |
|
|
769 | $self->browse_mysets_panel($library_selected, $list_of_local_sets); |
|
|
770 | } elsif ($browse_which eq 'browse_library') { |
|
|
771 | $self->browse_library_panel(); |
|
|
772 | } elsif ($browse_which eq 'browse_setdefs') { |
|
|
773 | $self->browse_setdef_panel($library_selected); |
|
|
774 | } else { ## handle other problem libraries |
|
|
775 | $self->browse_local_panel($library_selected,$browse_which); |
|
|
776 | } |
|
|
777 | |
|
|
778 | print CGI::Tr(CGI::td({-bgcolor=>"black"})); |
|
|
779 | |
|
|
780 | print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"center"}, |
|
|
781 | CGI::start_table({-border=>"0"}), |
|
|
782 | CGI::Tr( CGI::td({ -align=>"center"}, |
|
|
783 | CGI::submit(-name=>"select_all", -style=>$these_widths, |
|
|
784 | -value=>"Mark All For Adding"), |
| 331 | CGI::submit(-name=>"update", -style=>$these_widths, |
785 | CGI::submit(-name=>"select_none", -style=>$these_widths, |
| 332 | -value=>"Act on Marked Problems"), |
786 | -value=>"Clear All Marks"), |
|
|
787 | )), |
|
|
788 | CGI::Tr(CGI::td( |
|
|
789 | CGI::submit(-name=>"update", -style=>$these_widths. "; font-weight:bold", |
|
|
790 | -value=>"Update Set"), |
| 333 | CGI::submit(-name=>"rerandomize", |
791 | CGI::submit(-name=>"rerandomize", |
| 334 | -style=>$these_widths, |
792 | -style=>$these_widths, |
| 335 | -value=>"Rerandomize"), |
793 | -value=>"Rerandomize"), |
| 336 | CGI::submit(-name=>"cleardisplay", |
794 | CGI::submit(-name=>"cleardisplay", |
| 337 | -style=>$these_widths, |
795 | -style=>$these_widths, |
| 338 | -value=>"Clear Problem Display"))); |
796 | -value=>"Clear Problem Display") |
| 339 | |
797 | )), |
|
|
798 | CGI::end_table())); |
| 340 | } |
799 | } |
| 341 | |
800 | |
| 342 | sub make_data_row { |
801 | sub make_data_row { |
| 343 | my $self = shift; |
802 | my $self = shift; |
| 344 | my $sourceFileName = shift; |
803 | my $sourceFileName = shift; |
| 345 | my $pg = shift; |
804 | my $pg = shift; |
| 346 | my $cnt = shift; |
805 | my $cnt = shift; |
|
|
806 | my $mark = shift || 0; |
| 347 | |
807 | |
|
|
808 | $sourceFileName =~ s|^./||; # clean up top ugliness |
|
|
809 | |
| 348 | my $urlpath = $self->r->urlpath; |
810 | my $urlpath = $self->r->urlpath; |
| 349 | my $problem_output = $pg->{flags}->{error_flag} ? |
811 | my $problem_output = $pg->{flags}->{error_flag} ? |
| 350 | CGI::em("This problem produced an error") |
812 | CGI::div({class=>"ResultsWithError"}, CGI::em("This problem produced an error")) |
| 351 | : CGI::div({class=>"RenderSolo"}, $pg->{body_text}); |
813 | : CGI::div({class=>"RenderSolo"}, $pg->{body_text}); |
| 352 | |
814 | |
| 353 | |
815 | |
|
|
816 | #if($self->{r}->param('browse_which') ne 'browse_library') { |
|
|
817 | my $problem_seed = $self->{r}->param('problem_seed') || 0; |
| 354 | my $edit_link = CGI::a({href=>$self->systemLink( |
818 | my $edit_link = CGI::a({href=>$self->systemLink( |
| 355 | $urlpath->new(type=>'instructor_problem_editor_withset_withproblem', |
819 | $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", |
| 356 | args=>{courseID =>$urlpath->arg("courseID"), |
820 | courseID =>$urlpath->arg("courseID"), |
| 357 | setID=>"Undefined_Set", problemID=>"1" } |
821 | setID=>"Undefined_Set", |
| 358 | ), params=>{sourceFilePath => "$sourceFileName"} |
822 | problemID=>"1"), |
|
|
823 | params=>{sourceFilePath => "$sourceFileName", problemSeed=> $problem_seed} |
| 359 | )}, "Edit it" ); |
824 | )}, "Edit it" ); |
| 360 | |
825 | |
| 361 | my $try_link = CGI::a({href=>$self->systemLink( $urlpath->new(type=>'problem_detail', |
826 | my $try_link = CGI::a({href=>$self->systemLink( |
|
|
827 | $urlpath->newFromModule("WeBWorK::ContentGenerator::Problem", |
| 362 | args=>{courseID =>$urlpath->arg("courseID"), |
828 | courseID =>$urlpath->arg("courseID"), |
| 363 | setID=>"Undefined_Set", problemID=>"1"} |
829 | setID=>"Undefined_Set", |
| 364 | ), |
830 | problemID=>"1"), |
|
|
831 | params =>{ |
| 365 | params =>{effectiveUser => $self->r->param('user'), |
832 | effectiveUser => scalar($self->r->param('user')), |
| 366 | editMode => "SetMaker", |
833 | editMode => "SetMaker", |
|
|
834 | problemSeed=> $problem_seed, |
| 367 | sourceFilePath => "$sourceFileName"} )}, "Try it"); |
835 | sourceFilePath => "$sourceFileName" |
|
|
836 | } |
|
|
837 | )}, "Try it"); |
| 368 | |
838 | |
| 369 | |
839 | my %add_box_data = ( -name=>"trial$cnt",-value=>1,-label=>"Add this problem to the current set on the next update"); |
|
|
840 | if($mark & SUCCESS) { |
|
|
841 | $add_box_data{ -label } .= " (just added this problem)"; |
|
|
842 | } elsif($mark & ADDED) { |
|
|
843 | $add_box_data{ -checked } = 1; |
|
|
844 | } |
| 370 | |
845 | |
| 371 | print CGI::Tr({-align=>"left"}, CGI::td( |
846 | print CGI::Tr({-align=>"left"}, CGI::td( |
| 372 | |
847 | CGI::div({-style=>"background-color: #DDDDDD; margin: 0px auto"}, |
| 373 | CGI::div({-style=>"background-color: #DDDDDD"},"File name: $sourceFileName ", |
848 | CGI::span({-style=>"float:left ; text-align: left"},"File name: $sourceFileName "), |
| 374 | #$edit_link, " ", |
849 | CGI::span({-style=>"float:right ; text-align: right"}, $edit_link, " ", $try_link) |
| 375 | $try_link |
850 | ), CGI::br(), |
| 376 | ), |
|
|
| 377 | |
|
|
| 378 | |
|
|
| 379 | |
|
|
| 380 | |
|
|
| 381 | CGI::checkbox(-name=>"hideme$cnt",-value=>1,-label=>"Don't show me on the next update"), |
851 | CGI::checkbox(-name=>"hideme$cnt",-value=>1,-label=>"Don't show this problem on the next update"), |
| 382 | CGI::br(), |
852 | CGI::br(), |
| 383 | CGI::checkbox(-name=>"trial$cnt",-value=>1,-label=>"Add me to the current set on the next update"), |
853 | CGI::checkbox((%add_box_data)), |
| 384 | CGI::hidden(-name=>"filetrial$cnt", -default=>[$sourceFileName]). |
854 | CGI::hidden(-name=>"filetrial$cnt", -default=>[$sourceFileName]). |
| 385 | CGI::p($problem_output), |
855 | CGI::p($problem_output), |
| 386 | )); |
856 | )); |
| 387 | } |
857 | } |
|
|
858 | |
|
|
859 | sub clear_default { |
|
|
860 | my $r = shift; |
|
|
861 | my $param = shift; |
|
|
862 | my $default = shift; |
|
|
863 | my $newvalue = $r->param($param) || ''; |
|
|
864 | $newvalue = '' if($newvalue eq $default); |
|
|
865 | $r->param($param, $newvalue); |
|
|
866 | } |
|
|
867 | |
|
|
868 | sub pre_header_initialize { |
|
|
869 | my ($self) = @_; |
|
|
870 | my $r = $self->r; |
|
|
871 | ## For all cases, lets set some things |
|
|
872 | $self->{error}=0; |
|
|
873 | my $ce = $r->ce; |
|
|
874 | my $db = $r->db; |
|
|
875 | my $maxShown = $r->param('max_shown') || MAX_SHOW_DEFAULT; |
|
|
876 | $maxShown = 10000000 if($maxShown eq 'All'); # let's hope there aren't more |
|
|
877 | my $library_basic = $r->param('library_is_basic') || 1; |
|
|
878 | |
|
|
879 | ## Fix some parameters |
|
|
880 | clear_default($r,'library_subjects', ALL_SUBJECTS); |
|
|
881 | clear_default($r,'library_chapters', ALL_CHAPTERS); |
|
|
882 | clear_default($r,'library_sections', ALL_SECTIONS); |
|
|
883 | clear_default($r,'library_textbook', ALL_TEXTBOOKS); |
|
|
884 | |
|
|
885 | ## These directories will have individual buttons |
|
|
886 | %problib = %{$ce->{courseFiles}{problibs}} if $ce->{courseFiles}{problibs}; |
|
|
887 | |
|
|
888 | my $userName = $r->param('user'); |
|
|
889 | my $user = $db->getUser($userName); # checked |
|
|
890 | die "record for user $userName (real user) does not exist." |
|
|
891 | unless defined $user; |
|
|
892 | my $authz = $r->authz; |
|
|
893 | unless ($authz->hasPermissions($userName, "modify_problem_sets")) { |
|
|
894 | return(""); # Error message already produced in the body |
|
|
895 | } |
|
|
896 | |
|
|
897 | ## Now one action we have to deal with here |
|
|
898 | if ($r->param('edit_local')) { |
|
|
899 | my $urlpath = $r->urlpath; |
|
|
900 | my $db = $r->db; |
|
|
901 | my $checkset = $db->getGlobalSet($r->param('local_sets')); |
|
|
902 | if (not defined($checkset)) { |
|
|
903 | $self->{error} = 1; |
|
|
904 | $self->addbadmessage('You need to select a "Target Set" before you can edit it.'); |
|
|
905 | } else { |
|
|
906 | my $page = $urlpath->newFromModule('WeBWorK::ContentGenerator::Instructor::ProblemSetDetail', setID=>$r->param('local_sets'), courseID=>$urlpath->arg("courseID")); |
|
|
907 | my $url = $self->systemLink($page); |
|
|
908 | $self->reply_with_redirect($url); |
|
|
909 | } |
|
|
910 | } |
|
|
911 | |
|
|
912 | ## Next, lots of set up so that errors can be reported with message() |
|
|
913 | |
|
|
914 | ############# List of problems we have already printed |
|
|
915 | |
|
|
916 | $self->{past_problems} = get_past_problem_files($r); |
|
|
917 | # if we don't end up reusing problems, this will be wiped out |
|
|
918 | # if we do redisplay the same problems, we must adjust this accordingly |
|
|
919 | my @past_marks = map {$_->[1]} @{$self->{past_problems}}; |
|
|
920 | my $none_shown = scalar(@{$self->{past_problems}})==0; |
|
|
921 | my @pg_files=(); |
|
|
922 | my $use_previous_problems = 1; |
|
|
923 | my $first_shown = $r->param('first_shown') || 0; |
|
|
924 | my $last_shown = $r->param('last_shown'); |
|
|
925 | if (not defined($last_shown)) { |
|
|
926 | $last_shown = -1; |
|
|
927 | } |
|
|
928 | my @all_past_list = (); # these are include requested, but not shown |
|
|
929 | my $j = 0; |
|
|
930 | while (defined($r->param("all_past_list$j"))) { |
|
|
931 | push @all_past_list, $r->param("all_past_list$j"); |
|
|
932 | $j++; |
|
|
933 | } |
|
|
934 | |
|
|
935 | ############# Default of which problem selector to display |
|
|
936 | |
|
|
937 | my $browse_which = $r->param('browse_which') || 'browse_local'; |
|
|
938 | |
|
|
939 | my $problem_seed = $r->param('problem_seed') || 0; |
|
|
940 | $r->param('problem_seed', $problem_seed); # if it wasn't defined before |
|
|
941 | |
|
|
942 | ## check for problem lib buttons |
|
|
943 | my $browse_lib = ''; |
|
|
944 | foreach my $lib (keys %problib) { |
|
|
945 | if ($r->param("browse_$lib")) { |
|
|
946 | $browse_lib = "browse_$lib"; |
|
|
947 | last; |
|
|
948 | } |
|
|
949 | } |
|
|
950 | |
|
|
951 | ########### Start the logic through if elsif elsif ... |
|
|
952 | |
|
|
953 | ##### Asked to browse certain problems |
|
|
954 | if ($browse_lib ne '') { |
|
|
955 | $browse_which = $browse_lib; |
|
|
956 | $r->param('library_sets', ""); |
|
|
957 | $use_previous_problems = 0; @pg_files = (); ## clear old problems |
|
|
958 | } elsif ($r->param('browse_library')) { |
|
|
959 | $browse_which = 'browse_library'; |
|
|
960 | $r->param('library_sets', ""); |
|
|
961 | $use_previous_problems = 0; @pg_files = (); ## clear old problems |
|
|
962 | } elsif ($r->param('browse_local')) { |
|
|
963 | $browse_which = 'browse_local'; |
|
|
964 | $r->param('library_sets', ""); |
|
|
965 | $use_previous_problems = 0; @pg_files = (); ## clear old problems |
|
|
966 | } elsif ($r->param('browse_mysets')) { |
|
|
967 | $browse_which = 'browse_mysets'; |
|
|
968 | $r->param('library_sets', ""); |
|
|
969 | $use_previous_problems = 0; @pg_files = (); ## clear old problems |
|
|
970 | } elsif ($r->param('browse_setdefs')) { |
|
|
971 | $browse_which = 'browse_setdefs'; |
|
|
972 | $r->param('library_sets', ""); |
|
|
973 | $use_previous_problems = 0; @pg_files = (); ## clear old problems |
|
|
974 | |
|
|
975 | ##### Change the seed value |
|
|
976 | |
|
|
977 | } elsif ($r->param('rerandomize')) { |
|
|
978 | $problem_seed++; |
|
|
979 | $r->param('problem_seed', $problem_seed); |
|
|
980 | $self->addbadmessage('Changing the problem seed for display, but there are no problems showing.') if $none_shown; |
|
|
981 | |
|
|
982 | ##### Clear the display |
|
|
983 | |
|
|
984 | } elsif ($r->param('cleardisplay')) { |
|
|
985 | @pg_files = (); |
|
|
986 | $use_previous_problems=0; |
|
|
987 | $self->addbadmessage('The display was already cleared.') if $none_shown; |
|
|
988 | |
|
|
989 | ##### View problems selected from the local list |
|
|
990 | |
|
|
991 | } elsif ($r->param('view_local_set')) { |
|
|
992 | |
|
|
993 | my $set_to_display = $r->param('library_sets'); |
|
|
994 | if (not defined($set_to_display) or $set_to_display eq SELECT_LOCAL_STRING or $set_to_display eq "Found no directories containing problems") { |
|
|
995 | $self->addbadmessage('You need to select a set to view.'); |
|
|
996 | } else { |
|
|
997 | $set_to_display = '.' if $set_to_display eq MY_PROBLEMS; |
|
|
998 | $set_to_display = substr($browse_which,7) if $set_to_display eq MAIN_PROBLEMS; |
|
|
999 | @pg_files = list_pg_files($ce->{courseDirs}->{templates}, |
|
|
1000 | "$set_to_display"); |
|
|
1001 | $use_previous_problems=0; |
|
|
1002 | } |
|
|
1003 | |
|
|
1004 | ##### View problems selected from the a set in this course |
|
|
1005 | |
|
|
1006 | } elsif ($r->param('view_mysets_set')) { |
|
|
1007 | |
|
|
1008 | my $set_to_display = $r->param('library_sets'); |
|
|
1009 | if (not defined($set_to_display) |
|
|
1010 | or $set_to_display eq "Select a Homework Set" |
|
|
1011 | or $set_to_display eq NO_LOCAL_SET_STRING) { |
|
|
1012 | $self->addbadmessage("You need to select a set from this course to view."); |
|
|
1013 | } else { |
|
|
1014 | my @problemList = $db->listGlobalProblems($set_to_display); |
|
|
1015 | my $problem; |
|
|
1016 | @pg_files=(); |
|
|
1017 | for $problem (@problemList) { |
|
|
1018 | my $problemRecord = $db->getGlobalProblem($set_to_display, $problem); # checked |
|
|
1019 | die "global $problem for set $set_to_display not found." unless |
|
|
1020 | $problemRecord; |
|
|
1021 | push @pg_files, $problemRecord->source_file; |
|
|
1022 | |
|
|
1023 | } |
|
|
1024 | $use_previous_problems=0; |
|
|
1025 | } |
|
|
1026 | |
|
|
1027 | ##### View from the library database |
|
|
1028 | |
|
|
1029 | } elsif ($r->param('lib_view')) { |
|
|
1030 | |
|
|
1031 | @pg_files=(); |
|
|
1032 | my @dbsearch = WeBWorK::Utils::ListingDB::getSectionListings($r); |
|
|
1033 | my ($result, $tolibpath); |
|
|
1034 | for $result (@dbsearch) { |
|
|
1035 | $tolibpath = "Library/$result->{path}/$result->{filename}"; |
|
|
1036 | |
|
|
1037 | ## Too clunky!!!! |
|
|
1038 | push @pg_files, $tolibpath; |
|
|
1039 | } |
|
|
1040 | $use_previous_problems=0; |
|
|
1041 | |
|
|
1042 | ##### View a set from a set*.def |
|
|
1043 | |
|
|
1044 | } elsif ($r->param('view_setdef_set')) { |
|
|
1045 | |
|
|
1046 | my $set_to_display = $r->param('library_sets'); |
|
|
1047 | if (not defined($set_to_display) |
|
|
1048 | or $set_to_display eq "Select a Set Definition File" |
|
|
1049 | or $set_to_display eq NO_LOCAL_SET_STRING) { |
|
|
1050 | $self->addbadmessage("You need to select a set from this course to view."); |
|
|
1051 | } else { |
|
|
1052 | @pg_files= $self->read_set_def($set_to_display); |
|
|
1053 | } |
|
|
1054 | $use_previous_problems=0; |
|
|
1055 | |
|
|
1056 | ##### Edit the current local problem set |
|
|
1057 | |
|
|
1058 | } elsif ($r->param('edit_local')) { ## Jump to set edit page |
|
|
1059 | |
|
|
1060 | ; # already handled |
|
|
1061 | |
|
|
1062 | |
|
|
1063 | ##### Make a new local problem set |
|
|
1064 | |
|
|
1065 | } elsif ($r->param('new_local_set')) { |
|
|
1066 | if ($r->param('new_set_name') !~ /^[\w .-]*$/) { |
|
|
1067 | $self->addbadmessage("The name ".$r->param('new_set_name')." is not a valid set name. Use only letters, digits, -, _, and ."); |
|
|
1068 | } else { |
|
|
1069 | my $newSetName = $r->param('new_set_name'); |
|
|
1070 | # if we want to munge the input set name, do it here |
|
|
1071 | $newSetName =~ s/\s/_/g; |
|
|
1072 | $r->param('local_sets',$newSetName); |
|
|
1073 | my $newSetRecord = $db->getGlobalSet($newSetName); |
|
|
1074 | if (defined($newSetRecord)) { |
|
|
1075 | $self->addbadmessage("The set name $newSetName is already in use. Pick a different name if you would like to start a new set."); |
|
|
1076 | } else { # Do it! |
|
|
1077 | $newSetRecord = $db->{set}->{record}->new(); |
|
|
1078 | $newSetRecord->set_id($newSetName); |
|
|
1079 | $newSetRecord->set_header(""); |
|
|
1080 | $newSetRecord->hardcopy_header(""); |
|
|
1081 | $newSetRecord->open_date(time()+60*60*24*7); # in one week |
|
|
1082 | $newSetRecord->due_date(time()+60*60*24*7*2); # in two weeks |
|
|
1083 | $newSetRecord->answer_date(time()+60*60*24*7*3); # in three weeks |
|
|
1084 | eval {$db->addGlobalSet($newSetRecord)}; |
|
|
1085 | if ($@) { |
|
|
1086 | $self->addbadmessage("Problem creating set $newSetName<br> $@"); |
|
|
1087 | } else { |
|
|
1088 | $self->addgoodmessage("Set $newSetName has been created."); |
|
|
1089 | my $selfassign = $r->param('selfassign') || ""; |
|
|
1090 | $selfassign = "" if($selfassign =~ /false/i); # deal with javascript false |
|
|
1091 | if($selfassign) { |
|
|
1092 | $self->assignSetToUser($userName, $newSetRecord); |
|
|
1093 | $self->addgoodmessage("Set $newSetName was assigned to $userName."); |
|
|
1094 | } |
|
|
1095 | } |
|
|
1096 | } |
|
|
1097 | } |
|
|
1098 | |
|
|
1099 | ##### Add selected problems to the current local set |
|
|
1100 | |
|
|
1101 | } elsif ($r->param('update')) { |
|
|
1102 | ## first handle problems to be added before we hide them |
|
|
1103 | my($localSet, @selected); |
|
|
1104 | |
|
|
1105 | @pg_files = grep {($_->[1] & ADDED) != 0 } @{$self->{past_problems}}; |
|
|
1106 | @selected = map {$_->[0]} @pg_files; |
|
|
1107 | |
|
|
1108 | my @action_files = grep {$_->[1] > 0 } @{$self->{past_problems}}; |
|
|
1109 | # There are now good reasons to do an update without selecting anything. |
|
|
1110 | #if(scalar(@action_files) == 0) { |
|
|
1111 | # $self->addbadmessage('Update requested, but no problems were marked.'); |
|
|
1112 | #} |
|
|
1113 | |
|
|
1114 | if (scalar(@selected)>0) { # if some are to be added, they need a place to go |
|
|
1115 | $localSet = $r->param('local_sets'); |
|
|
1116 | if (not defined($localSet) or |
|
|
1117 | $localSet eq SELECT_SET_STRING or |
|
|
1118 | $localSet eq NO_LOCAL_SET_STRING) { |
|
|
1119 | $self->addbadmessage('You are trying to add problems to something, but you did not select a "Target Set" name as a target.'); |
|
|
1120 | } else { |
|
|
1121 | my $newSetRecord = $db->getGlobalSet($localSet); |
|
|
1122 | if (not defined($newSetRecord)) { |
|
|
1123 | $self->addbadmessage("You are trying to add problems to $localSet, but that set does not seem to exist! I bet you used your \"Back\" button."); |
|
|
1124 | } else { |
|
|
1125 | my $addcount = add_selected($self, $db, $localSet); |
|
|
1126 | if($addcount > 0) { |
|
|
1127 | $self->addgoodmessage("Added $addcount problem".(($addcount>1)?'s':''). |
|
|
1128 | " to $localSet."); |
|
|
1129 | } |
|
|
1130 | } |
|
|
1131 | } |
|
|
1132 | } |
|
|
1133 | ## now handle problems to be hidden |
|
|
1134 | |
|
|
1135 | ## only keep the ones which are not hidden |
|
|
1136 | @pg_files = grep {($_->[1] & HIDDEN) ==0 } @{$self->{past_problems}}; |
|
|
1137 | @past_marks = map {$_->[1]} @pg_files; |
|
|
1138 | @pg_files = map {$_->[0]} @pg_files; |
|
|
1139 | @all_past_list = (@all_past_list[0..($first_shown-1)], |
|
|
1140 | @pg_files, |
|
|
1141 | @all_past_list[($last_shown+1)..(scalar(@all_past_list)-1)]); |
|
|
1142 | $last_shown = $first_shown+$maxShown -1; |
|
|
1143 | $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list)); |
|
|
1144 | |
|
|
1145 | } elsif ($r->param('next_page')) { |
|
|
1146 | $first_shown = $last_shown+1; |
|
|
1147 | $last_shown = $first_shown+$maxShown-1; |
|
|
1148 | $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list)); |
|
|
1149 | @past_marks = (); |
|
|
1150 | } elsif ($r->param('prev_page')) { |
|
|
1151 | $last_shown = $first_shown-1; |
|
|
1152 | $first_shown = $last_shown - $maxShown+1; |
|
|
1153 | |
|
|
1154 | $first_shown = 0 if($first_shown<0); |
|
|
1155 | @past_marks = (); |
|
|
1156 | |
|
|
1157 | } elsif ($r->param('select_all')) { |
|
|
1158 | @past_marks = map {1} @past_marks; |
|
|
1159 | } elsif ($r->param('library_basic')) { |
|
|
1160 | $library_basic = 1; |
|
|
1161 | for my $jj (qw(textchapter textsection textbook)) { |
|
|
1162 | $r->param('library_'.$jj,''); |
|
|
1163 | } |
|
|
1164 | } elsif ($r->param('library_advanced')) { |
|
|
1165 | $library_basic = 2; |
|
|
1166 | } elsif ($r->param('library_reset')) { |
|
|
1167 | for my $jj (qw(chapters sections subjects textbook keywords)) { |
|
|
1168 | $r->param('library_'.$jj,''); |
|
|
1169 | } |
|
|
1170 | } elsif ($r->param('select_none')) { |
|
|
1171 | @past_marks = (); |
|
|
1172 | |
|
|
1173 | ##### No action requested, probably our first time here |
|
|
1174 | |
|
|
1175 | } else { |
|
|
1176 | #my $c = $r->connection; |
|
|
1177 | #print "Debug info: ". $r->get_remote_host ."<p>". $c->remote_ip ; |
|
|
1178 | ; |
|
|
1179 | } ##### end of the if elsif ... |
|
|
1180 | |
|
|
1181 | |
|
|
1182 | ############# List of local sets |
|
|
1183 | |
|
|
1184 | my @all_db_sets = $db->listGlobalSets; |
|
|
1185 | @all_db_sets = sortByName(undef, @all_db_sets); |
|
|
1186 | |
|
|
1187 | if ($use_previous_problems) { |
|
|
1188 | @pg_files = @all_past_list; |
|
|
1189 | } else { |
|
|
1190 | $first_shown = 0; |
|
|
1191 | $last_shown = scalar(@pg_files)<$maxShown ? scalar(@pg_files) : $maxShown; |
|
|
1192 | $last_shown--; # to make it an array index |
|
|
1193 | @past_marks = (); |
|
|
1194 | } |
|
|
1195 | ############# Now store data in self for retreival by body |
|
|
1196 | $self->{first_shown} = $first_shown; |
|
|
1197 | $self->{last_shown} = $last_shown; |
|
|
1198 | $self->{browse_which} = $browse_which; |
|
|
1199 | $self->{problem_seed} = $problem_seed; |
|
|
1200 | $self->{pg_files} = \@pg_files; |
|
|
1201 | $self->{past_marks} = \@past_marks; |
|
|
1202 | $self->{all_db_sets} = \@all_db_sets; |
|
|
1203 | $self->{library_basic} = $library_basic; |
|
|
1204 | } |
|
|
1205 | |
| 388 | |
1206 | |
| 389 | sub title { |
1207 | sub title { |
| 390 | return "Problem Set Maker"; |
1208 | return "Library Browser"; |
| 391 | } |
1209 | } |
| 392 | |
1210 | |
| 393 | sub body { |
1211 | sub body { |
| 394 | my ($self) = @_; |
1212 | my ($self) = @_; |
| 395 | |
1213 | |
| 396 | my $r = $self->r; |
1214 | my $r = $self->r; |
| 397 | my $ce = $r->ce; # course environment |
1215 | my $ce = $r->ce; # course environment |
| 398 | my $db = $r->db; # database |
1216 | my $db = $r->db; # database |
| 399 | my $j; # garden variety counter |
1217 | my $j; # garden variety counter |
| 400 | |
1218 | |
| 401 | my $userName = $r->param('user'); |
1219 | my $userName = $r->param('user'); |
| 402 | |
1220 | |
| 403 | my $user = $db->getUser($userName); # checked |
1221 | my $user = $db->getUser($userName); # checked |
| 404 | die "record for user $userName (real user) does not exist." |
1222 | die "record for user $userName (real user) does not exist." |
| 405 | unless defined $user; |
1223 | unless defined $user; |
| 406 | |
1224 | |
| 407 | ### Check that this is a professor |
1225 | ### Check that this is a professor |
| 408 | my $authz = $r->authz; |
1226 | my $authz = $r->authz; |
| 409 | unless ($authz->hasPermissions($userName, "modify_problem_sets")) { |
1227 | unless ($authz->hasPermissions($userName, "modify_problem_sets")) { |
| 410 | print "User $userName returned " . |
1228 | print "User $userName returned " . |
| 411 | $authz->hasPermissions($user, "modify_problem_sets") . |
1229 | $authz->hasPermissions($user, "modify_problem_sets") . |
| 412 | " for permission"; |
1230 | " for permission"; |
|
|
1231 | return(CGI::div({class=>'ResultsWithError'}, |
| 413 | return(CGI::em("You are not authorized to access the Instructor tools.")); |
1232 | CGI::em("You are not authorized to access the Instructor tools."))); |
| 414 | } |
1233 | } |
| 415 | |
1234 | |
|
|
1235 | ########## Extract information computed in pre_header_initialize |
| 416 | |
1236 | |
| 417 | ############# List of problems we have already printed |
1237 | my $first_shown = $self->{first_shown}; |
| 418 | |
|
|
| 419 | my @past_problems = get_past_problem_files($r); |
|
|
| 420 | my (@pg_files, @pg_html); |
|
|
| 421 | my $use_previous_problems = 1; |
|
|
| 422 | my $first_shown = $r->param('first_shown') || 0; |
|
|
| 423 | my $last_shown = $r->param('last_shown'); |
1238 | my $last_shown = $self->{last_shown}; |
| 424 | if (not defined($last_shown)) { |
1239 | my $browse_which = $self->{browse_which}; |
| 425 | $last_shown = -1; |
1240 | my $problem_seed = $self->{problem_seed}; |
| 426 | } |
1241 | my @pg_files = @{$self->{pg_files}}; |
| 427 | my @all_past_list = (); # these are include requested, but not shown |
1242 | my @all_db_sets = @{$self->{all_db_sets}}; |
| 428 | $j = 0; |
|
|
| 429 | while (defined($r->param("all_past_list$j"))) { |
|
|
| 430 | push @all_past_list, $r->param("all_past_list$j"); |
|
|
| 431 | $j++; |
|
|
| 432 | } |
|
|
| 433 | |
1243 | |
| 434 | ############# Default of which problem selector to display |
|
|
| 435 | |
|
|
| 436 | my $browse_which = 'browse_local'; |
|
|
| 437 | $browse_which = $r->param('browse_which') if defined($r->param('browse_which')); |
|
|
| 438 | |
|
|
| 439 | my $problem_seed = $r->param('problem_seed') || 0; |
|
|
| 440 | $r->param('problem_seed', $problem_seed); # if it wasn't defined before |
|
|
| 441 | |
|
|
| 442 | ########### Start the logic through if elsif elsif ... |
|
|
| 443 | |
|
|
| 444 | ##### Asked to browse certain problems |
|
|
| 445 | if ($r->param('browse_library')) { |
|
|
| 446 | $browse_which = 'browse_library'; |
|
|
| 447 | $r->param('library_sets', ""); |
|
|
| 448 | } elsif ($r->param('browse_local')) { |
|
|
| 449 | $browse_which = 'browse_local'; |
|
|
| 450 | $r->param('library_sets', ""); |
|
|
| 451 | } elsif ($r->param('browse_mysets')) { |
|
|
| 452 | $browse_which = 'browse_mysets'; |
|
|
| 453 | $r->param('library_sets', ""); |
|
|
| 454 | |
|
|
| 455 | ##### Change the seed value |
|
|
| 456 | |
|
|
| 457 | } elsif ($r->param('rerandomize')) { |
|
|
| 458 | $problem_seed++; |
|
|
| 459 | $r->param('problem_seed', $problem_seed); |
|
|
| 460 | |
|
|
| 461 | ##### Clear the display |
|
|
| 462 | |
|
|
| 463 | } elsif ($r->param('cleardisplay')) { |
|
|
| 464 | @pg_files = (); |
|
|
| 465 | $use_previous_problems=0; |
|
|
| 466 | |
|
|
| 467 | ##### View problems selected from the local list |
|
|
| 468 | |
|
|
| 469 | } elsif ($r->param('view_local_set')) { |
|
|
| 470 | |
|
|
| 471 | my $set_to_display = $r->param('library_sets'); |
|
|
| 472 | if (not defined($set_to_display) or $set_to_display eq "Select a Local Problem Collection") { |
|
|
| 473 | $self->{libmsg} = "You need to select a set to view."; |
|
|
| 474 | } else { |
|
|
| 475 | @pg_files = list_pg_files($ce->{courseDirs}->{templates}, |
|
|
| 476 | "$set_to_display"); |
|
|
| 477 | $use_previous_problems=0; |
|
|
| 478 | } |
|
|
| 479 | |
|
|
| 480 | ##### View problems selected from the a set in this course |
|
|
| 481 | |
|
|
| 482 | } elsif ($r->param('view_mysets_set')) { |
|
|
| 483 | |
|
|
| 484 | my $set_to_display = $r->param('library_sets'); |
|
|
| 485 | if (not defined($set_to_display) or $set_to_display eq "Select a Problem Set") { |
|
|
| 486 | $self->{libmsg} = "You need to select a set from this course to view."; |
|
|
| 487 | } else { |
|
|
| 488 | my @problemList = $db->listGlobalProblems($set_to_display); |
|
|
| 489 | my $problem; |
|
|
| 490 | @pg_files=(); |
|
|
| 491 | for $problem (@problemList) { |
|
|
| 492 | my $problemRecord = $db->getGlobalProblem($set_to_display, $problem); # checked |
|
|
| 493 | die "global $problem for set $set_to_display not found." unless |
|
|
| 494 | $problemRecord; |
|
|
| 495 | push @pg_files, $problemRecord->source_file; |
|
|
| 496 | |
|
|
| 497 | } |
|
|
| 498 | $use_previous_problems=0; |
|
|
| 499 | } |
|
|
| 500 | |
|
|
| 501 | ##### View whole chapter from the library |
|
|
| 502 | ## This will change somewhat later |
|
|
| 503 | |
|
|
| 504 | } elsif ($r->param('lib_view')) { |
|
|
| 505 | |
|
|
| 506 | @pg_files=(); |
|
|
| 507 | my $chap = $r->param('library_chapters') || ""; |
|
|
| 508 | $chap = "" if($chap eq "All Chapters"); |
|
|
| 509 | my $sect = $r->param('library_sections') || ""; |
|
|
| 510 | $sect = "" if($sect eq "All Sections"); |
|
|
| 511 | my @dbsearch = WeBWorK::Utils::ListingDB::getSectionListings($r->{ce}, "$chap", "$sect"); |
|
|
| 512 | my ($result, $tolibpath); |
|
|
| 513 | for $result (@dbsearch) { |
|
|
| 514 | $tolibpath = "Library/$result->{path}/$result->{filename}"; |
|
|
| 515 | |
|
|
| 516 | ## Too clunky!!!! |
|
|
| 517 | push @pg_files, $tolibpath; |
|
|
| 518 | } |
|
|
| 519 | $use_previous_problems=0; |
|
|
| 520 | |
|
|
| 521 | ##### Edit the current local problem set |
|
|
| 522 | |
|
|
| 523 | } elsif ($r->param('edit_local')) { ## Jump to set edit page |
|
|
| 524 | # This is handled in pre_header_initialize -- it redirects |
|
|
| 525 | # If there is an error, so no redirect, we want to be ready |
|
|
| 526 | # and do something here |
|
|
| 527 | |
|
|
| 528 | ##### Make a new local problem set |
|
|
| 529 | |
|
|
| 530 | } elsif ($r->param('new_local_set')) { |
|
|
| 531 | if ($r->param('new_set_name') !~ /^[\w.-]*$/) { |
|
|
| 532 | $self->{localmsg} = "The name ".$r->param('new_set_name')." is not a valid set name. Use only letters, digits, -, _, and ."; |
|
|
| 533 | } else { |
|
|
| 534 | my $newSetName = $r->param('new_set_name'); |
|
|
| 535 | $newSetName =~ s/^set//; |
|
|
| 536 | $newSetName =~ s/\.def$//; |
|
|
| 537 | my $newSetRecord = $db->getGlobalSet($newSetName); |
|
|
| 538 | if (defined($newSetRecord)) { |
|
|
| 539 | $self->{localmsg} = "The set name $newSetName is already in use. Pick a different name if you would like to start a new set."; |
|
|
| 540 | } else { # Do it! |
|
|
| 541 | $newSetRecord = $db->{set}->{record}->new(); |
|
|
| 542 | $newSetRecord->set_id($newSetName); |
|
|
| 543 | $newSetRecord->set_header(""); |
|
|
| 544 | $newSetRecord->problem_header(""); |
|
|
| 545 | $newSetRecord->open_date(time()+60*60*24*7); # in one week |
|
|
| 546 | $newSetRecord->due_date(time()+60*60*24*7*2); # in two weeks |
|
|
| 547 | $newSetRecord->answer_date(time()+60*60*24*7*3); # in three weeks |
|
|
| 548 | eval {$db->addGlobalSet($newSetRecord)}; |
|
|
| 549 | } |
|
|
| 550 | } |
|
|
| 551 | |
|
|
| 552 | ##### Add selected problems to the current local set |
|
|
| 553 | |
|
|
| 554 | } elsif ($r->param('update')) { |
|
|
| 555 | ## first handle problems to be added before we hide them |
|
|
| 556 | my($localSet, @selected); |
|
|
| 557 | |
|
|
| 558 | @pg_files = grep {$_->[1] != 0 } @past_problems; |
|
|
| 559 | @selected = map {$_->[0]} @pg_files; |
|
|
| 560 | |
|
|
| 561 | if (scalar(@selected)>0) { # if some are to be added, they need a place to go |
|
|
| 562 | $localSet = $r->param('local_sets'); |
|
|
| 563 | if (not defined($localSet)) { |
|
|
| 564 | $self->{localmsg} = "Trying to add problems to something, you did not select a current set name as a target."; |
|
|
| 565 | } else { |
|
|
| 566 | my $newSetRecord = $db->getGlobalSet($localSet); |
|
|
| 567 | if (not defined($newSetRecord)) { |
|
|
| 568 | $self->{localmsg} = "You need to select a local problem set to add the problems to."; |
|
|
| 569 | } else { |
|
|
| 570 | add_selected($self, $db, $localSet, @selected); |
|
|
| 571 | } |
|
|
| 572 | } |
|
|
| 573 | } |
|
|
| 574 | ## now handle problems to be hidden |
|
|
| 575 | |
|
|
| 576 | @pg_files = grep {$_->[2]==0 } @past_problems; |
|
|
| 577 | @pg_files = map {$_->[0]} @pg_files; |
|
|
| 578 | @all_past_list = (@all_past_list[0..($first_shown-1)], |
|
|
| 579 | @pg_files, |
|
|
| 580 | @all_past_list[($last_shown+1)..(scalar(@all_past_list)-1)]); |
|
|
| 581 | $last_shown = $first_shown+MAX_SHOW -1; |
|
|
| 582 | $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list)); |
|
|
| 583 | |
|
|
| 584 | ## FIXME: you should say something if no problems are selected |
|
|
| 585 | ## maybe the add button should be disabled if there are no problems |
|
|
| 586 | ## showing |
|
|
| 587 | |
|
|
| 588 | |
|
|
| 589 | } elsif ($r->param('next_page')) { |
|
|
| 590 | $first_shown = $last_shown+1; |
|
|
| 591 | $last_shown = $first_shown+MAX_SHOW-1; |
|
|
| 592 | $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list)); |
|
|
| 593 | } elsif ($r->param('prev_page')) { |
|
|
| 594 | $last_shown = $first_shown-1; |
|
|
| 595 | $first_shown = $last_shown - MAX_SHOW+1; |
|
|
| 596 | |
|
|
| 597 | $first_shown = 0 if($first_shown<0); |
|
|
| 598 | |
|
|
| 599 | ##### No action requested, probably our first time here |
|
|
| 600 | |
|
|
| 601 | } else { |
|
|
| 602 | #my $c = $r->connection; |
|
|
| 603 | #print "Debug info: ". $r->get_remote_host ."<p>". $c->remote_ip ; |
|
|
| 604 | ; |
|
|
| 605 | } ##### end of the if elsif ... |
|
|
| 606 | |
|
|
| 607 | |
|
|
| 608 | ############# List of local sets |
|
|
| 609 | |
|
|
| 610 | my @all_set_defs = get_global_set_defs($db); |
|
|
| 611 | for ($j=0; $j<scalar(@all_set_defs); $j++) { |
|
|
| 612 | $all_set_defs[$j] =~ s|^set||; |
|
|
| 613 | $all_set_defs[$j] =~ s|\.def||; |
|
|
| 614 | } |
|
|
| 615 | |
|
|
| 616 | if ($use_previous_problems) { |
|
|
| 617 | @pg_files = @all_past_list; |
|
|
| 618 | } else { |
|
|
| 619 | $first_shown = 0; |
|
|
| 620 | $last_shown = scalar(@pg_files)<MAX_SHOW ? scalar(@pg_files) : MAX_SHOW; |
|
|
| 621 | $last_shown--; # to make it an array index |
|
|
| 622 | } |
|
|
| 623 | |
|
|
| 624 | @pg_html=($last_shown>=$first_shown) ? |
1244 | my @pg_html=($last_shown>=$first_shown) ? |
| 625 | renderProblems($r,$user, @pg_files[$first_shown..$last_shown]) : (); |
1245 | renderProblems(r=> $r, |
|
|
1246 | user => $user, |
|
|
1247 | problem_list => [@pg_files[$first_shown..$last_shown]], |
|
|
1248 | displayMode => $r->param('mydisplayMode')) : (); |
| 626 | |
1249 | |
| 627 | ########## Top part |
1250 | ########## Top part |
| 628 | print CGI::startform({-method=>"POST", -action=>$r->uri}), |
1251 | print CGI::startform({-method=>"POST", -action=>$r->uri, -name=>'mainform'}), |
| 629 | $self->hidden_authen_fields, |
1252 | $self->hidden_authen_fields, |
| 630 | '<div align="center">', |
1253 | '<div align="center">', |
| 631 | CGI::start_table({-border=>2}); |
1254 | CGI::start_table({-border=>2}); |
| 632 | make_top_row($self, 'all_set_defs'=>\@all_set_defs, |
1255 | $self->make_top_row('all_db_sets'=>\@all_db_sets, |
| 633 | 'browse_which'=> $browse_which); |
1256 | 'browse_which'=> $browse_which); |
| 634 | print CGI::hidden(-name=>'browse_which', -default=>[$browse_which]), |
1257 | print CGI::hidden(-name=>'browse_which', -default=>[$browse_which]), |
| 635 | CGI::hidden(-name=>'problem_seed', -default=>[$problem_seed]); |
1258 | CGI::hidden(-name=>'problem_seed', -default=>[$problem_seed]); |
| 636 | for ($j = 0 ; $j < scalar(@pg_files) ; $j++) { |
1259 | for ($j = 0 ; $j < scalar(@pg_files) ; $j++) { |
| 637 | print CGI::hidden(-name=>"all_past_list$j", -default=>$pg_files[$j]); |
1260 | print CGI::hidden(-name=>"all_past_list$j", -default=>$pg_files[$j]); |
| 638 | } |
1261 | } |
| 639 | |
1262 | |
| 640 | print CGI::hidden(-name=>'first_shown', -default=>[$first_shown]); |
1263 | print CGI::hidden(-name=>'first_shown', -default=>[$first_shown]); |
| 641 | print CGI::hidden(-name=>'last_shown', -default=>[$last_shown]); |
1264 | print CGI::hidden(-name=>'last_shown', -default=>[$last_shown]); |
| 642 | |
1265 | |
| 643 | |
1266 | |
| 644 | ########## Now print problems |
1267 | ########## Now print problems |
| 645 | my $jj; |
1268 | my $jj; |
| 646 | for ($jj=0; $jj<scalar(@pg_html); $jj++) { |
1269 | for ($jj=0; $jj<scalar(@pg_html); $jj++) { |
| 647 | $pg_files[$jj] =~ s|^$ce->{courseDirs}->{templates}/?||; |
1270 | $pg_files[$jj] =~ s|^$ce->{courseDirs}->{templates}/?||; |
| 648 | make_data_row($self, $pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1); |
1271 | $self->make_data_row($pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1, $self->{past_marks}->[$jj]); |
| 649 | } |
1272 | } |
| 650 | |
1273 | |
| 651 | ########## Finish things off |
1274 | ########## Finish things off |
| 652 | print CGI::end_table(); |
1275 | print CGI::end_table(); |
| 653 | print '</div>'; |
1276 | print '</div>'; |
| 654 | # if($first_shown>0 or (1+$last_shown)<scalar(@pg_files)) { |
1277 | # if($first_shown>0 or (1+$last_shown)<scalar(@pg_files)) { |
| 655 | my ($next_button, $prev_button) = ("", ""); |
1278 | my ($next_button, $prev_button) = ("", ""); |
| 656 | if ($first_shown > 0) { |
1279 | if ($first_shown > 0) { |
| 657 | $prev_button = CGI::submit(-name=>"prev_page", -style=>"width:15ex", |
1280 | $prev_button = CGI::submit(-name=>"prev_page", -style=>"width:15ex", |
| 658 | -value=>"Previous page"); |
1281 | -value=>"Previous page"); |
| 659 | } |
1282 | } |
| 660 | if ((1+$last_shown)<scalar(@pg_files)) { |
1283 | if ((1+$last_shown)<scalar(@pg_files)) { |
| 661 | $next_button = CGI::submit(-name=>"next_page", -style=>"width:15ex", |
1284 | $next_button = CGI::submit(-name=>"next_page", -style=>"width:15ex", |
| 662 | -value=>"Next page"); |
1285 | -value=>"Next page"); |
| 663 | } |
1286 | } |
| 664 | if (scalar(@pg_files)>0) { |
1287 | if (scalar(@pg_files)>0) { |
| 665 | print CGI::p(($first_shown+1)."-".($last_shown+1)." of ".scalar(@pg_files). |
1288 | print CGI::p(($first_shown+1)."-".($last_shown+1)." of ".scalar(@pg_files). |
| 666 | " shown.", $prev_button, " ", $next_button); |
1289 | " shown.", $prev_button, " ", $next_button); |
| 667 | } |
1290 | } |
| 668 | # } |
1291 | # } |
| 669 | print CGI::endform(), "\n"; |
1292 | print CGI::endform(), "\n"; |
| 670 | |
1293 | |
| 671 | return ""; |
|
|
| 672 | } |
|
|
| 673 | |
|
|
| 674 | ############################################## End of Body |
|
|
| 675 | |
|
|
| 676 | sub pre_header_initialize { |
|
|
| 677 | my ($self) = @_; |
|
|
| 678 | my $r = $self->r; |
|
|
| 679 | ## For all cases, lets set some things |
|
|
| 680 | $self->{error}=0; |
|
|
| 681 | $self->{libmsg}=""; |
|
|
| 682 | $self->{localmsg}=""; |
|
|
| 683 | |
|
|
| 684 | |
|
|
| 685 | ### Maybe FIXME: this needs to check permissions before doing anything |
|
|
| 686 | |
|
|
| 687 | ## Now one action we have to deal with here |
|
|
| 688 | if ($r->param('edit_local')) { |
|
|
| 689 | my $urlpath = $r->urlpath; |
|
|
| 690 | my $db = $r->db; |
|
|
| 691 | my $checkset = $db->getGlobalSet($r->param('local_sets')); |
|
|
| 692 | if (not defined($checkset)) { |
|
|
| 693 | $self->{error} = 1; |
|
|
| 694 | $self->{localmsg} = "You need to select a local set before you can edit it."; |
|
|
| 695 | return(); |
|
|
| 696 | } |
|
|
| 697 | my $page = $urlpath->newFromModule('WeBWorK::ContentGenerator::Instructor::ProblemSetEditor', setID=>$r->param('local_sets'), courseID=>$urlpath->arg("courseID")); |
|
|
| 698 | my $url = $self->systemLink($page); |
|
|
| 699 | $self->reply_with_redirect($url); |
|
|
| 700 | } |
|
|
| 701 | } |
|
|
| 702 | |
|
|
| 703 | |
|
|
| 704 | # SKEL: To emit your own HTTP header, uncomment this: |
|
|
| 705 | # |
|
|
| 706 | #sub header { |
|
|
| 707 | # my ($self) = @_; |
|
|
| 708 | # |
|
|
| 709 | # # Generate your HTTP header here. |
|
|
| 710 | # |
|
|
| 711 | # # If you return something, it will be used as the HTTP status code for this |
|
|
| 712 | # # request. The Apache::Constants module might be useful for gerating status |
|
|
| 713 | # # codes. If you don't return anything, the status code "OK" will be used. |
|
|
| 714 | # return ""; |
1294 | return ""; |
| 715 | #} |
1295 | } |
| 716 | |
|
|
| 717 | # SKEL: If you need to do any processing after the HTTP header is sent, but before |
|
|
| 718 | # any template processing occurs, or you need to calculate values that will be |
|
|
| 719 | # used in multiple methods, do it in this method: |
|
|
| 720 | # |
|
|
| 721 | #sub initialize { |
|
|
| 722 | #my ($self) = @_; |
|
|
| 723 | #} |
|
|
| 724 | |
|
|
| 725 | # SKEL: If you need to add tags to the document <HEAD>, uncomment this method: |
|
|
| 726 | # |
|
|
| 727 | #sub head { |
|
|
| 728 | # my ($self) = @_; |
|
|
| 729 | # |
|
|
| 730 | # # You can print head tags here, like <META>, <SCRIPT>, etc. |
|
|
| 731 | # |
|
|
| 732 | # return ""; |
|
|
| 733 | #} |
|
|
| 734 | |
|
|
| 735 | # SKEL: To fill in the "info" box (to the right of the main body), use this |
|
|
| 736 | # method: |
|
|
| 737 | # |
|
|
| 738 | #sub info { |
|
|
| 739 | # my ($self) = @_; |
|
|
| 740 | # |
|
|
| 741 | # # Print HTML here. |
|
|
| 742 | # |
|
|
| 743 | # return ""; |
|
|
| 744 | #} |
|
|
| 745 | |
|
|
| 746 | # SKEL: To provide navigation links, use this method: |
|
|
| 747 | # |
|
|
| 748 | #sub nav { |
|
|
| 749 | # my ($self, $args) = @_; |
|
|
| 750 | # |
|
|
| 751 | # # See the documentation of path() and pathMacro() in |
|
|
| 752 | # # WeBWorK::ContentGenerator for more information. |
|
|
| 753 | # |
|
|
| 754 | # return ""; |
|
|
| 755 | #} |
|
|
| 756 | |
|
|
| 757 | # SKEL: For a little box for display options, etc., use this method: |
|
|
| 758 | # |
|
|
| 759 | #sub options { |
|
|
| 760 | # my ($self) = @_; |
|
|
| 761 | # |
|
|
| 762 | # # Print HTML here. |
|
|
| 763 | # |
|
|
| 764 | # return ""; |
|
|
| 765 | #} |
|
|
| 766 | |
|
|
| 767 | # SKEL: For a list of sibling objects, use this method: |
|
|
| 768 | # |
|
|
| 769 | #sub siblings { |
|
|
| 770 | # my ($self, $args) = @_; |
|
|
| 771 | # |
|
|
| 772 | # # See the documentation of siblings() and siblingsMacro() in |
|
|
| 773 | # # WeBWorK::ContentGenerator for more information. |
|
|
| 774 | # # |
|
|
| 775 | # # Refer to implementations in ProblemSet and Problem. |
|
|
| 776 | # |
|
|
| 777 | # return ""; |
|
|
| 778 | #} |
|
|
| 779 | |
1296 | |
| 780 | =head1 AUTHOR |
1297 | =head1 AUTHOR |
| 781 | |
1298 | |
| 782 | Written by John Jones, jj (at) asu.edu. |
1299 | Written by John Jones, jj (at) asu.edu. |
| 783 | |
1300 | |
| 784 | =cut |
1301 | =cut |
| 785 | |
1302 | |
| 786 | |
|
|
| 787 | |
|
|
| 788 | 1; |
1303 | 1; |