--- trunk/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm 2004/05/22 01:50:35 2152 +++ trunk/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm 2004/10/11 13:32:01 2892 @@ -1,7 +1,7 @@ ################################################################################ # WeBWorK Online Homework Delivery System # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ -# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm,v 1.13 2004/05/22 00:38:44 sh002i Exp $ +# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm,v 1.28 2004/10/08 19:58:18 jj Exp $ # # This program is free software; you can redistribute it and/or modify it under # the terms of either: (a) the GNU General Public License as published by the @@ -29,15 +29,17 @@ use CGI::Pretty qw(); use WeBWorK::Form; -use WeBWorK::Utils qw(readDirectory max); +use WeBWorK::Utils qw(readDirectory max sortByName); use WeBWorK::Utils::Tasks qw(renderProblems); require WeBWorK::Utils::ListingDB; -use constant MAX_SHOW => 20; +use constant MAX_SHOW_DEFAULT => 20; use constant NO_LOCAL_SET_STRING => 'There are no local sets yet'; use constant SELECT_SET_STRING => 'Select a Set for This Course'; -use constant SELECT_LOCAL_STRING => 'Select a Local Problem Collection'; +use constant SELECT_LOCAL_STRING => 'Select a Problem Collection'; +use constant MY_PROBLEMS => ' My Problems '; +use constant MAIN_PROBLEMS => ' Main Problems '; ## Flags for operations on files @@ -45,43 +47,78 @@ use constant HIDDEN => (1 << 1); use constant SUCCESS => (1 << 2); +## for additional problib buttons +my %problib; ## filled in in global.conf +my %ignoredir = ( + '.' => 1, '..' => 1, 'Library' => 1, + 'headers' => 1, 'macros' => 1, 'email' => 1, +); + +## ## This is for searching the disk for directories containing pg files. ## to make the recursion work, this returns an array where the first -## item is 1 or 0 depending on whether or not the current -## directory has any pg files. The second is a list of directories -## which contain pg files. +## item is the number of pg files in the directory. The second is a +## list of directories which contain pg files. +## +## If a directory contains only one pg file and at least one other +## file, the directory is considered to be part of the parent +## directory (it is probably in a separate directory only because +## it has auxiliarly files that want to be kept together with the +## pg file). +## +## If a directory has a file named "=library-ignore", it is never +## included in the directory menu. If a directory contains a file +## called "=library-combine-up", then its pg are included with those +## in the parent directory (and the directory does not appear in the +## menu). If it has a file called "=library-no-combine" then it is +## always listed as a separate directory even if it contains only one +## pg file. +## + sub get_library_sets { - my $amtop = shift; - my $topdir = shift; - my @lis = readDirectory($topdir); - my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$topdir/$_"} @lis; - my $havepg = scalar(@pgs)>0 ? 1 : 0; - my @mdirs = grep {$_ ne "." and $_ ne ".." and $_ ne "Library" - and -d "$topdir/$_"} @lis; - if($amtop) { # we don't want the library - @mdirs = grep {$_ ne "Library"} @mdirs; - } - my ($adir, @results, @thisresult); - for $adir (@mdirs) { - @results = get_library_sets(0, "$topdir/$adir"); - my $isadirok = shift @results; - @thisresult = (@thisresult, @results); - if ($isadirok) { - @thisresult = ("$topdir/$adir", @thisresult); - } - } - return(($havepg, @thisresult)); + my $top = shift; my $dir = shift; + my @lis = readDirectory($dir); my @pgdirs; + return (0) if grep /^=library-ignore$/, @lis; + + my $pgcount = scalar(grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$dir/$_"} @lis); + my $others = scalar(grep { (!m/\.pg$/ || m/(Header|-text)\.pg$/) && + !m/(\.(tmp|bak)|~)$/ && -f "$dir/$_" } @lis); + + my @dirs = grep {!$ignoredir{$_} and -d "$dir/$_"} @lis; + if ($top == 1) {@dirs = grep {!$problib{$_}} @dirs} + foreach my $subdir (@dirs) { + my @results = get_library_sets(0, "$dir/$subdir"); + $pgcount += shift @results; push(@pgdirs,@results); + } + + return ($pgcount, @pgdirs) if $top || $pgcount == 0 || grep /^=library-combine-up$/, @lis; + return (0,@pgdirs,$dir) if $pgcount > 1 || $others == 0 || grep /^=library-no-combine$/, @lis; + return ($pgcount, @pgdirs); +} + +sub get_library_pgs { + my $top = shift; my $base = shift; my $dir = shift; + my @lis = readDirectory("$base/$dir"); + return () if grep /^=library-ignore$/, @lis; + return () if !$top && grep /^=library-no-combine$/, @lis; + + my @pgs = grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$base/$dir/$_"} @lis; + my $others = scalar(grep { (!m/\.pg$/ || m/(Header|-text)\.pg$/) && + !m/(\.(tmp|bak)|~)$/ && -f "$base/$dir/$_" } @lis); + + my @dirs = grep {!$ignoredir{$_} and -d "$base/$dir/$_"} @lis; + if ($top == 1) {@dirs = grep {!$problib{$_}} @dirs} + foreach my $subdir (@dirs) {push(@pgs, get_library_pgs(0,"$base/$dir",$subdir))} + + return () unless $top || (scalar(@pgs) == 1 && $others) || grep /^=library-combine-up$/, @lis; + return (map {"$dir/$_"} @pgs); } -## List all the pg files in the requested directory sub list_pg_files { - my $templatedir = shift; - my $topdir = shift; - - my @lis = readDirectory("$templatedir/$topdir"); - my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$templatedir/$topdir/$_"} @lis; - @pgs = map { "$topdir/$_" } @pgs; - return(@pgs); + my ($templates,$dir) = @_; + my $top = ($dir eq '.')? 1 : 2; + my @pgs = get_library_pgs($top,$templates,$dir); + return sortByName(undef,@pgs); } ## go through past page getting a list of identifiers for the problems @@ -117,18 +154,11 @@ for $selected (@selected) { if($selected->[1] & ADDED) { $file = $selected->[0]; - @path = split "/", $selected->[0]; - pop @path; # Remove the file name from the path - shift @path if $path[0] eq ""; # remove the null element from the begining - my $problemRecord = $db->newGlobalProblem(); - $problemRecord->problem_id($freeProblemID++); - $problemRecord->set_id($setName); - $problemRecord->source_file($file); - $problemRecord->value("1"); - $problemRecord->max_attempts("-1"); - $db->addGlobalProblem($problemRecord); + my $problemRecord = $self->addProblemToSet(setName => $setName, + sourceFile => $file, problemID => $freeProblemID); + $freeProblemID++; $self->assignProblemToAllSetUsers($problemRecord); - $selected->[1] &= SUCCESS; + $selected->[1] |= SUCCESS; $addedcount++; } } @@ -140,24 +170,58 @@ sub get_problem_directories { my $ce = shift; - my @all_problem_directories = get_library_sets(1, $ce->{courseDirs}->{templates}); + my $lib = shift; + my $source = $ce->{courseDirs}{templates}; + my $main = MY_PROBLEMS; my $isTop = 1; + if ($lib) {$source .= "/$lib"; $main = MAIN_PROBLEMS; $isTop = 2} + my @all_problem_directories = get_library_sets($isTop, $source); my $includetop = shift @all_problem_directories; my $j; for ($j=0; $j{courseDirs}->{templates}/?||; } - @all_problem_directories = sort @all_problem_directories; - unshift @all_problem_directories, ' -- Top -- ' if($includetop); + @all_problem_directories = sortByName(undef, @all_problem_directories); + unshift @all_problem_directories, $main if($includetop); return (\@all_problem_directories); } +############# Everyone has a view problems line. Abstract it +sub view_problems_line { + my $internal_name = shift; + my $label = shift; + my $r = shift; # so we can get parameter values + my $result = CGI::submit(-name=>"$internal_name", -value=>$label); + + my %display_modes = %{WeBWorK::PG::DISPLAY_MODES()}; + my @active_modes = grep { exists $display_modes{$_} } + @{$r->ce->{pg}->{displayModes}}; + push @active_modes, 'None'; + # We have our own displayMode since its value may be None, which is illegal + # in other modules. + my $mydisplayMode = $r->param('mydisplayMode') || $r->ce->{pg}->{options}->{displayMode}; + $result .= ' Display Mode: '.CGI::popup_menu(-name=> 'mydisplayMode', + -values=>\@active_modes, + -default=> $mydisplayMode); + # Now we give a choice of the number of problems to show + my $defaultMax = $r->param('max_shown') || MAX_SHOW_DEFAULT; + $result .= ' Max. Shown: '. + CGI::popup_menu(-name=> 'max_shown', + -values=>[5,10,15,20,25,30,50,'All'], + -default=> $defaultMax); + + return($result); +} + + ### The browsing panel has three versions ##### Version 1 is local problems sub browse_local_panel { my $self = shift; my $library_selected = shift; + my $lib = shift || ''; $lib =~ s/^browse_//; + my $name = ($lib eq '')? 'Local' : $problib{$lib}; - my $list_of_prob_dirs= get_problem_directories($self->r->ce); + my $list_of_prob_dirs= get_problem_directories($self->r->ce,$lib); if(scalar(@$list_of_prob_dirs) == 0) { $library_selected = "Found no directories containing problems"; unshift @{$list_of_prob_dirs}, $library_selected; @@ -168,13 +232,13 @@ $library_selected = $default_value; } } - - print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Local Problems: ", + my $view_problem_line = view_problems_line('view_local_set', 'View Problems', $self->r); + print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, "$name Problems: ", CGI::popup_menu(-name=> 'library_sets', -values=>$list_of_prob_dirs, -default=> $library_selected), CGI::br(), - CGI::submit(-name=>"view_local_set", -value=>"View Problems"), + $view_problem_line, )); } @@ -192,12 +256,13 @@ $library_selected = $default_value; } - print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Browse from: ", + my $view_problem_line = view_problems_line('view_mysets_set', 'View Problems', $self->r); + print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, "Browse from: ", CGI::popup_menu(-name=> 'library_sets', -values=>$list_of_local_sets, -default=> $library_selected), CGI::br(), - CGI::submit(-name=>"view_mysets_set", -value=>"View This Set"), + $view_problem_line )); } @@ -250,8 +315,9 @@ unshift @sects, $default_sect; my $section_selected = $r->param('library_sections') || $default_sect; + my $view_problem_line = view_problems_line('lib_view', 'View Problems', $self->r); - print CGI::Tr(CGI::td({-class=>"InfoPanel"}, + print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, CGI::start_table(), CGI::Tr( CGI::td(["Chapter:", @@ -282,7 +348,8 @@ # CGI::td({-colspan=>2}, CGI::textfield(-name=>"keywords", # -default=>"Keywords not implemented yet", # -override=>1, -size=>60))), - CGI::Tr(CGI::td({-colspan=>3},CGI::submit(-name=>"lib_view", -value=>"View Problems"))), + CGI::Tr(CGI::td({-colspan=>3}, + $view_problem_line)), CGI::end_table(), )); } @@ -290,6 +357,7 @@ sub make_top_row { my $self = shift; my $r = $self->r; + my $ce = $r->ce; my %data = @_; my $list_of_local_sets = $data{all_set_defs}; @@ -303,11 +371,22 @@ $dis2 = '-disabled' if($browse_which eq 'browse_local'); $dis3 = '-disabled' if($browse_which eq 'browse_mysets'); - my $these_widths = "width: 27ex"; + ## Make buttons for additional problem libraries + my $libs = ''; + foreach my $lib (sort(keys(%problib))) { + $libs .= ' '. CGI::submit(-name=>"browse_$lib", -value=>$problib{$lib}, + ($browse_which eq "browse_$lib")? '-disabled': '') + if (-d "$ce->{courseDirs}{templates}/$lib"); + } + $libs = CGI::br()."or Problems from".$libs if $libs ne ''; + + my $these_widths = "width: 20ex"; print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"center"}, - CGI::submit(-name=>"browse_library", -value=>"Browse Problem Library", -style=>$these_widths, $dis1), - CGI::submit(-name=>"browse_local", -value=>"Browse Local Problems", -style=>$these_widths, $dis2), - CGI::submit(-name=>"browse_mysets", -value=>"Browse From This Course", -style=>$these_widths, $dis3), + "Browse ", + CGI::submit(-name=>"browse_library", -value=>"Problem Library", -style=>$these_widths, $dis1), + CGI::submit(-name=>"browse_local", -value=>"Local Problems", -style=>$these_widths, $dis2), + CGI::submit(-name=>"browse_mysets", -value=>"From This Course", -style=>$these_widths, $dis3), + $libs, )); print CGI::Tr(CGI::td({-bgcolor=>"black"})); @@ -316,8 +395,10 @@ $self->browse_local_panel($library_selected); } elsif ($browse_which eq 'browse_mysets') { $self->browse_mysets_panel($library_selected, $list_of_local_sets); - } else { + } elsif ($browse_which eq 'browse_library') { $self->browse_library_panel(); + } else { ## handle other problem libraries + $self->browse_local_panel($library_selected,$browse_which); } print CGI::Tr(CGI::td({-bgcolor=>"black"})); @@ -331,16 +412,20 @@ unshift @{$list_of_local_sets}, SELECT_SET_STRING; $set_selected = SELECT_SET_STRING; } + 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;'; - print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Adding Problems to ", - CGI::b("Current Set: "), + print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"left"}, "Adding Problems to ", + CGI::b("Target Set: "), CGI::popup_menu(-name=> 'local_sets', -values=>$list_of_local_sets, -default=> $set_selected), - CGI::submit(-name=>"edit_local", -value=>"Edit Current Set"), + CGI::submit(-name=>"edit_local", -value=>"Edit Target Set"), + CGI::hidden(-name=>"selfassign", -default=>[0]). CGI::br(), CGI::br(), - CGI::submit(-name=>"new_local_set", -value=>"Create a New Set in This Course:"), + CGI::submit(-name=>"new_local_set", -value=>"Create a New Set in This Course:", + -onclick=>$myjs + ), " ", CGI::textfield(-name=>"new_set_name", -default=>"Name for new set here", @@ -351,14 +436,24 @@ print CGI::Tr(CGI::td({-bgcolor=>"black"})); print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"center"}, - CGI::submit(-name=>"update", -style=>$these_widths, - -value=>"Act on Marked Problems"), - CGI::submit(-name=>"rerandomize", + CGI::start_table({-border=>"0"}), + CGI::Tr( CGI::td({ -align=>"center"}, + CGI::submit(-name=>"select_all", -style=>$these_widths, + -value=>"Mark All For Adding"), + CGI::submit(-name=>"select_none", -style=>$these_widths, + -value=>"Clear All Marks"), + )), + CGI::Tr( CGI::td( + CGI::submit(-name=>"update", -style=>$these_widths. "; font-weight:bold", + -value=>"Update"), + CGI::submit(-name=>"rerandomize", -style=>$these_widths, -value=>"Rerandomize"), - CGI::submit(-name=>"cleardisplay", + CGI::submit(-name=>"cleardisplay", -style=>$these_widths, - -value=>"Clear Problem Display"))); + -value=>"Clear Problem Display") + )), + CGI::end_table())); } @@ -367,23 +462,26 @@ my $sourceFileName = shift; my $pg = shift; my $cnt = shift; + my $mark = shift || 0; $sourceFileName =~ s|^./||; # clean up top ugliness my $urlpath = $self->r->urlpath; my $problem_output = $pg->{flags}->{error_flag} ? - CGI::em("This problem produced an error") + CGI::div({class=>"ResultsWithError"}, CGI::em("This problem produced an error")) : CGI::div({class=>"RenderSolo"}, $pg->{body_text}); my $edit_link = ''; #if($self->{r}->param('browse_which') ne 'browse_library') { + my $problem_seed = $self->{r}->param('problem_seed') || 0; if($sourceFileName !~ /^Library\//) { $edit_link = CGI::a({href=>$self->systemLink($urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor", courseID =>$urlpath->arg("courseID"), setID=>"Undefined_Set", problemID=>"1"), - params=>{sourceFilePath => "$sourceFileName"} + params=>{sourceFilePath => "$sourceFileName", + problemSeed=> $problem_seed} )}, "Edit it" ); } @@ -391,11 +489,17 @@ courseID =>$urlpath->arg("courseID"), setID=>"Undefined_Set", problemID=>"1"), - params =>{effectiveUser => $self->r->param('user'), + params =>{effectiveUser => scalar($self->r->param('user')), editMode => "SetMaker", + problemSeed=> $problem_seed, sourceFilePath => "$sourceFileName"} )}, "Try it"); - + my %add_box_data = ( -name=>"trial$cnt",-value=>1,-label=>"Add this problem to the current set on the next update"); + if($mark & SUCCESS) { + $add_box_data{ -label } .= " (just added this problem)"; + } elsif($mark & ADDED) { + $add_box_data{ -checked } = 1; + } print CGI::Tr({-align=>"left"}, CGI::td( @@ -407,9 +511,9 @@ - CGI::checkbox(-name=>"hideme$cnt",-value=>1,-label=>"Don't show me on the next update"), + CGI::checkbox(-name=>"hideme$cnt",-value=>1,-label=>"Don't show this problem on the next update"), CGI::br(), - CGI::checkbox(-name=>"trial$cnt",-value=>1,-label=>"Add me to the current set on the next update"), + CGI::checkbox((%add_box_data)), CGI::hidden(-name=>"filetrial$cnt", -default=>[$sourceFileName]). CGI::p($problem_output), )); @@ -423,7 +527,11 @@ $self->{error}=0; my $ce = $r->ce; my $db = $r->db; + my $maxShown = $r->param('max_shown') || MAX_SHOW_DEFAULT; + $maxShown = 10000000 if($maxShown eq 'All'); # let's hope there aren't more + ## These directories will have individual buttons + %problib = %{$ce->{courseFiles}{problibs}} if $ce->{courseFiles}{problibs}; my $userName = $r->param('user'); my $user = $db->getUser($userName); # checked @@ -441,9 +549,9 @@ my $checkset = $db->getGlobalSet($r->param('local_sets')); if (not defined($checkset)) { $self->{error} = 1; - $self->addbadmessage('You need to select a "Current Set" before you can edit it.'); + $self->addbadmessage('You need to select a "Target Set" before you can edit it.'); } else { - my $page = $urlpath->newFromModule('WeBWorK::ContentGenerator::Instructor::ProblemSetEditor', setID=>$r->param('local_sets'), courseID=>$urlpath->arg("courseID")); + my $page = $urlpath->newFromModule('WeBWorK::ContentGenerator::Instructor::ProblemSetDetail', setID=>$r->param('local_sets'), courseID=>$urlpath->arg("courseID")); my $url = $self->systemLink($page); $self->reply_with_redirect($url); } @@ -454,6 +562,9 @@ ############# List of problems we have already printed $self->{past_problems} = get_past_problem_files($r); + # if we don't end up reusing problems, this will be wiped out + # if we do redisplay the same problems, we must adjust this accordingly + my @past_marks = map {$_->[1]} @{$self->{past_problems}}; my $none_shown = scalar(@{$self->{past_problems}})==0; my @pg_files=(); my $use_previous_problems = 1; @@ -476,18 +587,34 @@ my $problem_seed = $r->param('problem_seed') || 0; $r->param('problem_seed', $problem_seed); # if it wasn't defined before + ## check for problem lib buttons + my $browse_lib = ''; + foreach my $lib (keys %problib) { + if ($r->param("browse_$lib")) { + $browse_lib = "browse_$lib"; + last; + } + } + ########### Start the logic through if elsif elsif ... ##### Asked to browse certain problems - if ($r->param('browse_library')) { + if ($browse_lib ne '') { + $browse_which = $browse_lib; + $r->param('library_sets', ""); + $use_previous_problems = 0; @pg_files = (); ## clear old problems + } elsif ($r->param('browse_library')) { $browse_which = 'browse_library'; $r->param('library_sets', ""); + $use_previous_problems = 0; @pg_files = (); ## clear old problems } elsif ($r->param('browse_local')) { $browse_which = 'browse_local'; $r->param('library_sets', ""); + $use_previous_problems = 0; @pg_files = (); ## clear old problems } elsif ($r->param('browse_mysets')) { $browse_which = 'browse_mysets'; $r->param('library_sets', ""); + $use_previous_problems = 0; @pg_files = (); ## clear old problems ##### Change the seed value @@ -511,7 +638,8 @@ if (not defined($set_to_display) or $set_to_display eq SELECT_LOCAL_STRING or $set_to_display eq "Found no directories containing problems") { $self->addbadmessage('You need to select a set to view.'); } else { - $set_to_display = '.' if $set_to_display eq ' -- Top -- '; + $set_to_display = '.' if $set_to_display eq MY_PROBLEMS; + $set_to_display = substr($browse_which,7) if $set_to_display eq MAIN_PROBLEMS; @pg_files = list_pg_files($ce->{courseDirs}->{templates}, "$set_to_display"); $use_previous_problems=0; @@ -543,7 +671,7 @@ ##### View whole chapter from the library ## This will change somewhat later - } elsif ($r->param('lib_view')) { + } elsif ($r->param('lib_view')) { @pg_files=(); my $chap = $r->param('library_chapters') || ""; @@ -584,11 +712,18 @@ $newSetRecord = $db->{set}->{record}->new(); $newSetRecord->set_id($newSetName); $newSetRecord->set_header(""); - $newSetRecord->problem_header(""); + $newSetRecord->hardcopy_header(""); $newSetRecord->open_date(time()+60*60*24*7); # in one week $newSetRecord->due_date(time()+60*60*24*7*2); # in two weeks $newSetRecord->answer_date(time()+60*60*24*7*3); # in three weeks eval {$db->addGlobalSet($newSetRecord)}; + $self->addgoodmessage("Set $newSetName has been created."); + my $selfassign = $r->param('selfassign') || ""; + $selfassign = "" if($selfassign =~ /false/i); # deal with javascript false + if($selfassign) { + $self->assignSetToUser($userName, $newSetRecord); + $self->addgoodmessage("Set $newSetName was assigned to $userName."); + } } } @@ -602,16 +737,17 @@ @selected = map {$_->[0]} @pg_files; my @action_files = grep {$_->[1] > 0 } @{$self->{past_problems}}; - if(scalar(@action_files) == 0) { - $self->addbadmessage('Act on marked problems requested, but no problems were marked.'); - } + # There are now good reasons to do an update without selecting anything. + #if(scalar(@action_files) == 0) { + # $self->addbadmessage('Update requested, but no problems were marked.'); + #} if (scalar(@selected)>0) { # if some are to be added, they need a place to go $localSet = $r->param('local_sets'); if (not defined($localSet) or $localSet eq SELECT_SET_STRING or $localSet eq NO_LOCAL_SET_STRING) { - $self->addbadmessage('You are trying to add problems to something, but you did not select a "Current Set" name as a target.'); + $self->addbadmessage('You are trying to add problems to something, but you did not select a "Target Set" name as a target.'); } else { my $newSetRecord = $db->getGlobalSet($localSet); if (not defined($newSetRecord)) { @@ -629,27 +765,30 @@ ## only keep the ones which are not hidden @pg_files = grep {($_->[1] & HIDDEN) ==0 } @{$self->{past_problems}}; + @past_marks = map {$_->[1]} @pg_files; @pg_files = map {$_->[0]} @pg_files; @all_past_list = (@all_past_list[0..($first_shown-1)], @pg_files, @all_past_list[($last_shown+1)..(scalar(@all_past_list)-1)]); - $last_shown = $first_shown+MAX_SHOW -1; + $last_shown = $first_shown+$maxShown -1; $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list)); - ## FIXME: you should say something if no problems are selected - ## maybe the add button should be disabled if there are no problems - ## showing - - } elsif ($r->param('next_page')) { $first_shown = $last_shown+1; - $last_shown = $first_shown+MAX_SHOW-1; + $last_shown = $first_shown+$maxShown-1; $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list)); + @past_marks = (); } elsif ($r->param('prev_page')) { $last_shown = $first_shown-1; - $first_shown = $last_shown - MAX_SHOW+1; + $first_shown = $last_shown - $maxShown+1; $first_shown = 0 if($first_shown<0); + @past_marks = (); + + } elsif ($r->param('select_all')) { + @past_marks = map {1} @past_marks; + } elsif ($r->param('select_none')) { + @past_marks = (); ##### No action requested, probably our first time here @@ -663,17 +802,15 @@ ############# List of local sets my @all_set_defs = $db->listGlobalSets; - for ($j=0; $j{first_shown} = $first_shown; @@ -681,6 +818,7 @@ $self->{browse_which} = $browse_which; $self->{problem_seed} = $problem_seed; $self->{pg_files} = \@pg_files; + $self->{past_marks} = \@past_marks; $self->{all_set_defs} = \@all_set_defs; } @@ -724,10 +862,13 @@ my @all_set_defs = @{$self->{all_set_defs}}; my @pg_html=($last_shown>=$first_shown) ? - renderProblems($r,$user, @pg_files[$first_shown..$last_shown]) : (); + renderProblems(r=> $r, + user => $user, + problem_list => [@pg_files[$first_shown..$last_shown]], + displayMode => $r->param('mydisplayMode')) : (); ########## Top part - print CGI::startform({-method=>"POST", -action=>$r->uri}), + print CGI::startform({-method=>"POST", -action=>$r->uri, -name=>'mainform'}), $self->hidden_authen_fields, '
', CGI::start_table({-border=>2}); @@ -747,7 +888,7 @@ my $jj; for ($jj=0; $jj{courseDirs}->{templates}/?||; - $self->make_data_row($pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1); + $self->make_data_row($pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1, $self->{past_marks}->[$jj]); } ########## Finish things off