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