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

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9