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

Diff of /branches/rel-2-4-dev/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm

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

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

Legend:
Removed from v.2154  
changed lines
  Added in v.3449

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9