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