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