[system] / branches / rel-2-4-patches / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / SetMaker.pm Repository:
ViewVC logotype

Diff of /branches/rel-2-4-patches/webwork2/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.2152  
changed lines
  Added in v.3431

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9