[system] / branches / dg_dev / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / SetMaker2.pm Repository:
ViewVC logotype

View of /branches/dg_dev/webwork2/lib/WeBWorK/ContentGenerator/Instructor/SetMaker2.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6579 - (download) (as text) (annotate)
Sat Nov 27 06:02:51 2010 UTC (2 years, 5 months ago) by david gage
File size: 61882 byte(s)
fixed bug 1865

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm,v 1.85 2008/07/01 13:18:52 glarose Exp $
    5 #
    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
    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.
   10 #
   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
   13 # FOR A PARTICULAR PURPOSE.  See either the GNU General Public License or the
   14 # Artistic License for more details.
   15 ################################################################################
   16 
   17 
   18 package WeBWorK::ContentGenerator::Instructor::SetMaker2;
   19 use base qw(WeBWorK::ContentGenerator::Instructor);
   20 
   21 =head1 NAME
   22 
   23 WeBWorK::ContentGenerator::Instructor::SetMaker2 - Make homework sets.
   24 
   25 =cut
   26 
   27 use strict;
   28 use warnings;
   29 
   30 
   31 #use CGI qw(-nosticky);
   32 use WeBWorK::CGI;
   33 use WeBWorK::Debug;
   34 use WeBWorK::Form;
   35 use WeBWorK::Utils qw(readDirectory max sortByName);
   36 use WeBWorK::Utils::Tasks qw(renderProblems);
   37 use File::Find;
   38 
   39 require WeBWorK::Utils::ListingDB;
   40 
   41 use constant SHOW_HINTS_DEFAULT => 0;
   42 use constant SHOW_SOLUTIONS_DEFAULT => 0;
   43 use constant MAX_SHOW_DEFAULT => 20;
   44 use constant NO_LOCAL_SET_STRING => 'No sets in this course yet';
   45 use constant SELECT_SET_STRING => 'Select a Set from this Course';
   46 use constant SELECT_LOCAL_STRING => 'Select a Problem Collection';
   47 use constant MY_PROBLEMS => '  My Problems  ';
   48 use constant MAIN_PROBLEMS => '  Unclassified Problems  ';
   49 use constant CREATE_SET_BUTTON => 'Create New Set';
   50 use constant ALL_CHAPTERS => 'All Chapters';
   51 use constant ALL_SUBJECTS => 'All Subjects';
   52 use constant ALL_SECTIONS => 'All Sections';
   53 use constant ALL_TEXTBOOKS => 'All Textbooks';
   54 
   55 use constant LIB2_DATA => {
   56   'dbchapter' => {name => 'library_chapters', all => 'All Chapters'},
   57   'dbsection' =>  {name => 'library_sections', all =>'All Sections' },
   58   'dbsubject' =>  {name => 'library_subjects', all => 'All Subjects' },
   59   'textbook' =>  {name => 'library_textbook', all =>  'All Textbooks'},
   60   'textchapter' => {name => 'library_textchapter', all => 'All Chapters'},
   61   'textsection' => {name => 'library_textsection', all => 'All Sections'},
   62   'keywords' =>  {name => 'library_keywords', all => '' },
   63   };
   64 
   65 ## Flags for operations on files
   66 
   67 use constant ADDED => 1;
   68 use constant HIDDEN => (1 << 1);
   69 use constant SUCCESS => (1 << 2);
   70 use constant DELETED => (1 << 3);
   71 use constant MOVED => (1 << 4);
   72 
   73 ##  for additional problib buttons
   74 my %problib;  ## filled in in global.conf
   75 my %ignoredir = (
   76   '.' => 1, '..' => 1, 'Library' => 1, 'CVS' => 1, 'tmpEdit' => 1,
   77   'headers' => 1, 'macros' => 1, 'email' => 1, '.svn' => 1,
   78 );
   79 
   80 sub prepare_activity_entry {
   81   my $self=shift;
   82   my $r = $self->r;
   83   my $user = $self->r->param('user') || 'NO_USER';
   84   return("In SetMaker as user $user");
   85 }
   86 
   87 ## This is for searching the disk for directories containing pg files.
   88 ## to make the recursion work, this returns an array where the first
   89 ## item is the number of pg files in the directory.  The second is a
   90 ## list of directories which contain pg files.
   91 ##
   92 ## If a directory contains only one pg file and the directory name
   93 ## is the same as the file name, then the directory is considered
   94 ## to be part of the parent directory (it is probably in a separate
   95 ## directory only because it has auxiliary files that want to be
   96 ## kept together with the pg file).
   97 ##
   98 ## If a directory has a file named "=library-ignore", it is never
   99 ## included in the directory menu.  If a directory contains a file
  100 ## called "=library-combine-up", then its pg are included with those
  101 ## in the parent directory (and the directory does not appear in the
  102 ## menu).  If it has a file called "=library-no-combine" then it is
  103 ## always listed as a separate directory even if it contains only one
  104 ## pg file.
  105 
  106 sub get_library_sets {
  107   my $top = shift; my $dir = shift;
  108   # ignore directories that give us an error
  109   my @lis = eval { readDirectory($dir) };
  110   if ($@) {
  111     warn $@;
  112     return (0);
  113   }
  114   return (0) if grep /^=library-ignore$/, @lis;
  115 
  116   my @pgfiles = grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$dir/$_"} @lis;
  117   my $pgcount = scalar(@pgfiles);
  118   my $pgname = $dir; $pgname =~ s!.*/!!; $pgname .= '.pg';
  119   my $combineUp = ($pgcount == 1 && $pgname eq $pgfiles[0] && !(grep /^=library-no-combine$/, @lis));
  120 
  121   my @pgdirs;
  122   my @dirs = grep {!$ignoredir{$_} and -d "$dir/$_"} @lis;
  123   if ($top == 1) {@dirs = grep {!$problib{$_}} @dirs}
  124   foreach my $subdir (@dirs) {
  125     my @results = get_library_sets(0, "$dir/$subdir");
  126     $pgcount += shift @results; push(@pgdirs,@results);
  127   }
  128 
  129   return ($pgcount, @pgdirs) if $top || $combineUp || grep /^=library-combine-up$/, @lis;
  130   return (0,@pgdirs,$dir);
  131 }
  132 
  133 sub get_library_pgs {
  134   my $top = shift; my $base = shift; my $dir = shift;
  135   my @lis = readDirectory("$base/$dir");
  136   return () if grep /^=library-ignore$/, @lis;
  137   return () if !$top && grep /^=library-no-combine$/, @lis;
  138 
  139   my @pgs = grep { m/\.pg$/ and (not m/(Header|-text)\.pg$/) and -f "$base/$dir/$_"} @lis;
  140   my $others = scalar(grep { (!m/\.pg$/ || m/(Header|-text)\.pg$/) &&
  141                               !m/(\.(tmp|bak)|~)$/ && -f "$base/$dir/$_" } @lis);
  142 
  143   my @dirs = grep {!$ignoredir{$_} and -d "$base/$dir/$_"} @lis;
  144   if ($top == 1) {@dirs = grep {!$problib{$_}} @dirs}
  145   foreach my $subdir (@dirs) {push(@pgs, get_library_pgs(0,"$base/$dir",$subdir))}
  146 
  147   return () unless $top || (scalar(@pgs) == 1 && $others) || grep /^=library-combine-up$/, @lis;
  148   return (map {"$dir/$_"} @pgs);
  149 }
  150 
  151 sub list_pg_files {
  152   my ($templates,$dir) = @_;
  153   my $top = ($dir eq '.')? 1 : 2;
  154   my @pgs = get_library_pgs($top,$templates,$dir);
  155   return sortByName(undef,@pgs);
  156 }
  157 
  158 ## Search for set definition files
  159 
  160 sub get_set_defs {
  161   my $topdir = shift;
  162   my @found_set_defs;
  163   # get_set_defs_wanted is a closure over @found_set_defs
  164   my $get_set_defs_wanted = sub {
  165     #my $fn = $_;
  166     #my $fdir = $File::Find::dir;
  167     #return() if($fn !~ /^set.*\.def$/);
  168     ##return() if(not -T $fn);
  169     #push @found_set_defs, "$fdir/$fn";
  170     push @found_set_defs, $_ if m|/set[^/]*\.def$|;
  171   };
  172   find({ wanted => $get_set_defs_wanted, follow_fast=>1, no_chdir=>1}, $topdir);
  173   map { $_ =~ s|^$topdir/?|| } @found_set_defs;
  174   return @found_set_defs;
  175 }
  176 
  177 ## Try to make reading of set defs more flexible.  Additional strategies
  178 ## for fixing a path can be added here.
  179 
  180 sub munge_pg_file_path {
  181   my $self = shift;
  182   my $pg_path = shift;
  183   my $path_to_set_def = shift;
  184   my $end_path = $pg_path;
  185   # if the path is ok, don't fix it
  186   return($pg_path) if(-e $self->r->ce->{courseDirs}{templates}."/$pg_path");
  187   # if we have followed a link into a self contained course to get
  188   # to the set.def file, we need to insert the start of the path to
  189   # the set.def file
  190   $end_path = "$path_to_set_def/$pg_path";
  191   return($end_path) if(-e $self->r->ce->{courseDirs}{templates}."/$end_path");
  192   # if we got this far, this path is bad, but we let it produce
  193   # an error so the user knows there is a troublesome path in the
  194   # set.def file.
  195   return($pg_path);
  196 }
  197 
  198 ## Read a set definition file.  This could be abstracted since it happens
  199 ## elsewhere.  Here we don't have to process so much of the file.
  200 
  201 sub read_set_def {
  202   my $self = shift;
  203   my $r = $self->r;
  204   my $filePathOrig = shift;
  205   my $filePath = $r->ce->{courseDirs}{templates}."/$filePathOrig";
  206   $filePathOrig =~ s/set.*\.def$//;
  207   $filePathOrig =~ s|/$||;
  208   $filePathOrig = "." if ($filePathOrig !~ /\S/);
  209   my @pg_files = ();
  210   my ($line, $got_to_pgs, $name, @rest) = ("", 0, "");
  211   if ( open (SETFILENAME, "$filePath") )    {
  212     while($line = <SETFILENAME>) {
  213       chomp($line);
  214       $line =~ s|(#.*)||; # don't read past comments
  215       if($got_to_pgs) {
  216         unless ($line =~ /\S/) {next;} # skip blank lines
  217         ($name,@rest) = split (/\s*,\s*/,$line);
  218         $name =~ s/\s*//g;
  219         push @pg_files, $name;
  220       } else {
  221         $got_to_pgs = 1 if ($line =~ /problemList\s*=/);
  222       }
  223     }
  224   } else {
  225     $self->addbadmessage("Cannot open $filePath");
  226   }
  227   # This is where we would potentially munge the pg file paths
  228   # One possibility
  229   @pg_files = map { $self->munge_pg_file_path($_, $filePathOrig) } @pg_files;
  230   return(@pg_files);
  231 }
  232 
  233 ## go through past page getting a list of identifiers for the problems
  234 ## and whether or not they are selected, and whether or not they should
  235 ## be hidden
  236 
  237 sub get_past_problem_files {
  238   my $r = shift;
  239   my @found=();
  240   my $count =1;
  241   while (defined($r->param("filetrial$count"))) {
  242     my $val = 0;
  243     $val |= ADDED if($r->param("trial$count"));
  244     $val |= HIDDEN if($r->param("hideme$count"));
  245     $val |= MOVED if($r->param("moved$count"));
  246     push @found, [$r->param("filetrial$count"), $val];
  247     $count++;
  248   }
  249   $count = 1;
  250   while (defined($r->param("mysetfiletrial$count"))) {
  251     my $val = 0;
  252     $val |= DELETED if($r->param("deleted$count"));
  253     push @found, [$r->param("mysetfiletrial$count"), $val];
  254     $count++;
  255   }
  256   return(\@found);
  257 }
  258 
  259 #### For adding new problems
  260 
  261 sub add_selected {
  262   my $self = shift;
  263   my $db = shift;
  264   my $setName = shift;
  265   my @past_problems = @{$self->{past_problems}};
  266   my @selected = @past_problems;
  267   my (@path, $file, $selected, $freeProblemID);
  268   # DBFIXME count would work just as well
  269   $freeProblemID = max($db->listGlobalProblems($setName)) + 1;
  270   my $addedcount=0;
  271 
  272   for $selected (@selected) {
  273     if($selected->[1] & ADDED || $selected->[1] & MOVED) {
  274       $file = $selected->[0];
  275       #print "$file";
  276       my $problemRecord = $self->addProblemToSet(setName => $setName,
  277         sourceFile => $file, problemID => $freeProblemID);
  278       $freeProblemID++;
  279       $self->assignProblemToAllSetUsers($problemRecord);
  280       if(!($selected->[1] & MOVED)){
  281         $selected->[1] |= SUCCESS;
  282       }
  283       $addedcount++;
  284     }
  285   }
  286   return($addedcount);
  287 }
  288 
  289 sub delete_selected {
  290   my $self = shift;
  291   my $db = shift;
  292   my $setName = shift;
  293   my @past_problems = @{$self->{past_problems}};
  294   my @selected = @past_problems;
  295   my (@path, $file, $selected);
  296   # DBFIXME count would work just as well
  297   my $deletedcount=0;
  298 
  299   for $selected (@selected) {
  300     if($selected->[1] & DELETED || $selected->[1] & MOVED) {
  301       foreach my $problem ($db->listGlobalProblems($setName)) {
  302         my $problemRecord = $db->getGlobalProblem($setName, $problem);
  303         if($problemRecord->source_file eq $selected->[0]){
  304           $db->deleteGlobalProblem($setName, $problemRecord->problem_id);
  305         }
  306       }
  307       if(!($selected->[1] & MOVED)){
  308         $selected->[1] |= SUCCESS;
  309       }
  310       $deletedcount++;
  311     }
  312   }
  313   return($deletedcount);
  314 }
  315 
  316 
  317 ############# List of sets of problems in templates directory
  318 
  319 sub get_problem_directories {
  320   my $ce = shift;
  321   my $lib = shift;
  322   my $source = $ce->{courseDirs}{templates};
  323   my $main = MY_PROBLEMS; my $isTop = 1;
  324   if ($lib) {$source .= "/$lib"; $main = MAIN_PROBLEMS; $isTop = 2}
  325   my @all_problem_directories = get_library_sets($isTop, $source);
  326   my $includetop = shift @all_problem_directories;
  327   my $j;
  328   for ($j=0; $j<scalar(@all_problem_directories); $j++) {
  329     $all_problem_directories[$j] =~ s|^$ce->{courseDirs}->{templates}/?||;
  330   }
  331   @all_problem_directories = sortByName(undef, @all_problem_directories);
  332   unshift @all_problem_directories, $main if($includetop);
  333   return (\@all_problem_directories);
  334 }
  335 
  336 ############# Everyone has a view problems line.  Abstract it
  337 sub view_problems_line {
  338   my $internal_name = shift;
  339   my $label = shift;
  340   my $r = shift; # so we can get parameter values
  341   my $result = CGI::submit(-name=>"$internal_name", -value=>$label);
  342 
  343   my %display_modes = %{WeBWorK::PG::DISPLAY_MODES()};
  344   my @active_modes = grep { exists $display_modes{$_} }
  345     @{$r->ce->{pg}->{displayModes}};
  346   push @active_modes, 'None';
  347   # We have our own displayMode since its value may be None, which is illegal
  348   # in other modules.
  349   my $mydisplayMode = $r->param('mydisplayMode') || $r->ce->{pg}->{options}->{displayMode};
  350   $result .= '&nbsp;Display&nbsp;Mode:&nbsp;'.CGI::popup_menu(-name=> 'mydisplayMode',
  351                                                               -values=>\@active_modes,
  352                                                               -default=> $mydisplayMode);
  353   # Now we give a choice of the number of problems to show
  354   my $defaultMax = $r->param('max_shown') || MAX_SHOW_DEFAULT;
  355   $result .= '&nbsp;Max. Shown:&nbsp'.
  356     CGI::popup_menu(-name=> 'max_shown',
  357                     -values=>[5,10,15,20,25,30,50,'All'],
  358                     -default=> $defaultMax);
  359   # Option of whether to show hints and solutions
  360   my $defaultHints = $r->param('showHints') || SHOW_HINTS_DEFAULT;
  361   $result .= "&nbsp;".CGI::checkbox(-name=>"showHints",-checked=>$defaultHints,-label=>"Hints");
  362   my $defaultSolutions = $r->param('showSolutions') || SHOW_SOLUTIONS_DEFAULT;
  363   $result .= "&nbsp;".CGI::checkbox(-name=>"showSolutions",-checked=>$defaultSolutions,-label=>"Solutions");
  364 
  365   return($result);
  366 }
  367 
  368 
  369 ### The browsing panel has three versions
  370 #####  Version 1 is local problems
  371 sub browse_local_panel {
  372   my $self = shift;
  373   my $library_selected = shift;
  374   my $lib = shift || ''; $lib =~ s/^browse_//;
  375   my $name = ($lib eq '')? 'Local' : $problib{$lib};
  376 
  377   my $list_of_prob_dirs= get_problem_directories($self->r->ce,$lib);
  378   if(scalar(@$list_of_prob_dirs) == 0) {
  379     $library_selected = "Found no directories containing problems";
  380     unshift @{$list_of_prob_dirs}, $library_selected;
  381   } else {
  382     my $default_value = SELECT_LOCAL_STRING;
  383     if (not $library_selected or $library_selected eq $default_value) {
  384       unshift @{$list_of_prob_dirs},  $default_value;
  385       $library_selected = $default_value;
  386     }
  387   }
  388   debug("library is $lib and sets are $library_selected");
  389   my $view_problem_line = view_problems_line('view_local_set', 'View Problems', $self->r);
  390   my @popup_menu_args = (
  391     -name => 'library_sets',
  392     -values => $list_of_prob_dirs,
  393     -default => $library_selected,
  394   );
  395   # make labels without the $lib prefix -- reduces the width of the popup menu
  396   if (length($lib)) {
  397     my %labels = map { my($l)=$_=~/^$lib\/(.*)$/;$_=>$l } @$list_of_prob_dirs;
  398     push @popup_menu_args, -labels => \%labels;
  399   }
  400   print CGI::div({-class=>"InfoPanel", -align=>"left"}, "$name Problems: ",
  401                   CGI::popup_menu(@popup_menu_args),
  402                   CGI::br(),
  403                   $view_problem_line,
  404   );
  405 }
  406 
  407 #####  Version 2 is local homework sets
  408 sub browse_mysets_panel {
  409   my $self = shift;
  410   my $library_selected = shift;
  411   my $list_of_local_sets = shift;
  412   my $remember_local_set = shift;
  413   my $default_value = "Select a Homework Set";
  414 
  415   if(scalar(@$list_of_local_sets) == 0) {
  416     $list_of_local_sets = [NO_LOCAL_SET_STRING];
  417   } elsif (not $library_selected or $library_selected eq $default_value) {
  418     unshift @{$list_of_local_sets},  $default_value;
  419     $library_selected = $default_value;
  420   }
  421 
  422   #my $view_problem_line = view_problems_line('view_mysets_set', 'View Problems', $self->r);
  423   print CGI::div({-class=>"InfoPanel", -align=>"left"},
  424     CGI::submit(-name=>"update", -style=>"width: 25ex; font-weight:bold;",
  425                   -value=>"Update Set"),
  426     CGI::popup_menu(-name=> 'myset_sets',
  427                     -values=>$list_of_local_sets,
  428                     -default=> $library_selected),
  429     CGI::hidden(-name=> 'local_sets', -value=>$remember_local_set),
  430     CGI::br(),
  431     "<span>",
  432     CGI::submit(-name=>"view_mysets_set", -value=>"View Set"),
  433     "<span id='problem_counter' style='float:right;'>0</span>",
  434     "</span>"
  435   );
  436 }
  437 
  438 #####  Version 2.1 is local homework sets
  439 sub edit_mysets_panel {
  440   my $self = shift;
  441   my $library_selected = shift;
  442   my $list_of_local_sets = shift;
  443   my $default_value = "Select a Homework Set";
  444 
  445   if(scalar(@$list_of_local_sets) == 0) {
  446     $list_of_local_sets = [NO_LOCAL_SET_STRING];
  447   } elsif (not $library_selected or $library_selected eq $default_value) {
  448     unshift @{$list_of_local_sets},  $default_value;
  449     $library_selected = $default_value;
  450   }
  451 
  452   my $view_problem_line = view_problems_line('edit_mysets_set', 'View Problems', $self->r);
  453   print CGI::Tr({},
  454     CGI::td({-class=>"InfoPanel", -align=>"left"}, "Browse from: ",
  455     CGI::popup_menu(-name=> 'library_sets',
  456                     -values=>$list_of_local_sets,
  457                     -default=> $library_selected),
  458     CGI::br(),
  459     $view_problem_line
  460   ));
  461 }
  462 
  463 #####  Version 3 is the problem library
  464 #
  465 # This comes in 3 forms, problem library version 1, and for version 2 there
  466 # is the basic, and the advanced interfaces.  This function checks what we are
  467 # supposed to do, or aborts if the problem library has not been installed.
  468 
  469 sub browse_library_panel {
  470   my $self=shift;
  471   my $r = $self->r;
  472   my $ce = $r->ce;
  473 
  474   # See if the problem library is installed
  475   my $libraryRoot = $r->{ce}->{problemLibrary}->{root};
  476 
  477   unless($libraryRoot) {
  478     print CGI::div({class=>'ResultsWithError', align=>"center"},
  479       "The problem library has not been installed.");
  480     return;
  481   }
  482   # Test if the Library directory link exists.  If not, try to make it
  483   unless(-d "$ce->{courseDirs}->{templates}/Library") {
  484     unless(symlink($libraryRoot, "$ce->{courseDirs}->{templates}/Library")) {
  485       my $msg =  <<"HERE";
  486 You are missing the directory <code>templates/Library</code>, which is needed
  487 for the Problem Library to function.  It should be a link pointing to
  488 <code>$libraryRoot</code>, which you set in <code>conf/global.conf</code>.
  489 I tried to make the link for you, but that failed.  Check the permissions
  490 in your <code>templates</code> directory.
  491 HERE
  492       $self->addbadmessage($msg);
  493     }
  494   }
  495 
  496   # Now check what version we are supposed to use
  497   my $libraryVersion = $r->{ce}->{problemLibrary}->{version} || 1;
  498   if($libraryVersion == 1) {
  499     return $self->browse_library_panel1;
  500   } elsif($libraryVersion == 2) {
  501     return $self->browse_library_panel2 if($self->{library_basic}==1);
  502     return $self->browse_library_panel2adv;
  503   } else {
  504     print CGI::div({class=>'ResultsWithError', align=>"center"},
  505       "The problem library version is set to an illegal value.");
  506     return;
  507   }
  508 }
  509 
  510 sub browse_library_panel1 {
  511   my $self = shift;
  512   my $r = $self->r;
  513   my $ce = $r->ce;
  514 
  515   my @chaps = WeBWorK::Utils::ListingDB::getAllChapters($r->{ce});
  516   unshift @chaps, LIB2_DATA->{dbchapter}{all};
  517   my $chapter_selected = $r->param('library_chapters') || LIB2_DATA->{dbchapter}->{all};
  518 
  519   my @sects=();
  520   if ($chapter_selected ne LIB2_DATA->{dbchapter}{all}) {
  521     @sects = WeBWorK::Utils::ListingDB::getAllSections($r->{ce}, $chapter_selected);
  522   }
  523 
  524   unshift @sects, ALL_SECTIONS;
  525   my $section_selected =  $r->param('library_sections') || LIB2_DATA->{dbsection}{all};
  526 
  527   my $view_problem_line = view_problems_line('lib_view', 'View Problems', $self->r);
  528 
  529   print CGI::div({-class=>"InfoPanel", -align=>"left"},
  530         CGI::div(["Chapter:",
  531           CGI::popup_menu(-name=> 'library_chapters',
  532                           -values=>\@chaps,
  533                           -default=> $chapter_selected,
  534                           -onchange=>"submit();return true"
  535           ),
  536           CGI::submit(-name=>"lib_select_chapter", -value=>"Update Section List")]),
  537         CGI::div("Section:",
  538           CGI::popup_menu(-name=> 'library_sections',
  539                           -values=>\@sects,
  540                           -default=> $section_selected
  541       )),
  542       CGI::div($view_problem_line)
  543     );
  544 }
  545 
  546 sub browse_library_panel2 {
  547   my $self = shift;
  548   my $r = $self->r;
  549   my $ce = $r->ce;
  550 
  551   my @subjs = WeBWorK::Utils::ListingDB::getAllDBsubjects($r);
  552   unshift @subjs, LIB2_DATA->{dbsubject}{all};
  553 
  554   my @chaps = WeBWorK::Utils::ListingDB::getAllDBchapters($r);
  555   unshift @chaps, LIB2_DATA->{dbchapter}{all};
  556 
  557   my @sects=();
  558   @sects = WeBWorK::Utils::ListingDB::getAllDBsections($r);
  559   unshift @sects, LIB2_DATA->{dbsection}{all};
  560 
  561   my $subject_selected = $r->param('library_subjects') || LIB2_DATA->{dbsubject}{all};
  562   my $chapter_selected = $r->param('library_chapters') || LIB2_DATA->{dbchapter}{all};
  563   my $section_selected =  $r->param('library_sections') || LIB2_DATA->{dbsection}{all};
  564 
  565   my $view_problem_line = view_problems_line('lib_view', 'View Problems', $self->r);
  566 
  567   my $count_line = WeBWorK::Utils::ListingDB::countDBListings($r);
  568   if($count_line==0) {
  569     $count_line = "There are no matching pg files";
  570   } else {
  571     $count_line = "There are $count_line matching WeBWorK problem files";
  572   }
  573 
  574   print CGI::div({-class=>"InfoPanel", -align=>"left"},
  575     CGI::hidden(-name=>"library_is_basic", -default=>1,-override=>1),
  576     CGI::div({-style=>"float:left;"},["Subject:",
  577         CGI::popup_menu(-name=> 'library_subjects',
  578                       -values=>\@subjs,
  579                       -default=> $subject_selected,
  580                        -onchange=>"submit();return true;"
  581     )]),
  582     CGI::div({-style=>"float:left;"},["Chapter:",
  583       CGI::popup_menu(-name=> 'library_chapters',
  584                       -values=>\@chaps,
  585                       -default=> $chapter_selected,
  586                        -onchange=>"submit();return true;"
  587     )]),
  588     CGI::div({-style=>"float:left;"},["Section:",
  589       CGI::popup_menu(-name=> 'library_sections',
  590                   -values=>\@sects,
  591                   -default=> $section_selected,
  592               -onchange=>"submit();return true"
  593     )]),
  594     CGI::div({-colspan=>2, -align=>"right"},
  595       CGI::submit(-name=>"library_advanced", -value=>"Advanced Search")),
  596     CGI::div({-colspan=>2, -align=>"right"},
  597       CGI::submit(-name=>"lib_select_subject", -value=>"Update Chapter/Section Lists")),
  598     CGI::div({-colspan=>3}, $view_problem_line),
  599     CGI::div({-colspan=>3, -align=>"center"}, $count_line)
  600    );
  601 
  602 }
  603 
  604 sub browse_library_panel2adv {
  605   my $self = shift;
  606   my $r = $self->r;
  607   my $ce = $r->ce;
  608   my $right_button_style = "width: 18ex";
  609 
  610   my @subjs = WeBWorK::Utils::ListingDB::getAllDBsubjects($r);
  611   if(! grep { $_ eq $r->param('library_subjects') } @subjs) {
  612     $r->param('library_subjects', '');
  613   }
  614   unshift @subjs, LIB2_DATA->{dbsubject}{all};
  615 
  616   my @chaps = WeBWorK::Utils::ListingDB::getAllDBchapters($r);
  617   if(! grep { $_ eq $r->param('library_chapters') } @chaps) {
  618     $r->param('library_chapters', '');
  619   }
  620   unshift @chaps, LIB2_DATA->{dbchapter}{all};
  621 
  622   my @sects = WeBWorK::Utils::ListingDB::getAllDBsections($r);
  623   if(! grep { $_ eq $r->param('library_sections') } @sects) {
  624     $r->param('library_sections', '');
  625   }
  626   unshift @sects, LIB2_DATA->{dbsection}{all};
  627 
  628   my $texts = WeBWorK::Utils::ListingDB::getDBTextbooks($r);
  629   my @textarray = map { $_->[0] }  @{$texts};
  630   my %textlabels = ();
  631   for my $ta (@{$texts}) {
  632     $textlabels{$ta->[0]} = $ta->[1]." by ".$ta->[2]." (edition ".$ta->[3].")";
  633   }
  634   if(! grep { $_ eq $r->param('library_textbook') } @textarray) {
  635     $r->param('library_textbook', '');
  636   }
  637   unshift @textarray, LIB2_DATA->{textbook}{all};
  638   my $atb = LIB2_DATA->{textbook}{all}; $textlabels{$atb} = LIB2_DATA->{textbook}{all};
  639 
  640   my $textchap_ref = WeBWorK::Utils::ListingDB::getDBTextbooks($r, 'textchapter');
  641   my @textchaps = map { $_->[0] } @{$textchap_ref};
  642   if(! grep { $_ eq $r->param('library_textchapter') } @textchaps) {
  643     $r->param('library_textchapter', '');
  644   }
  645   unshift @textchaps, LIB2_DATA->{textchapter}{all};
  646 
  647   my $textsec_ref = WeBWorK::Utils::ListingDB::getDBTextbooks($r, 'textsection');
  648   my @textsecs = map { $_->[0] } @{$textsec_ref};
  649   if(! grep { $_ eq $r->param('library_textsection') } @textsecs) {
  650     $r->param('library_textsection', '');
  651   }
  652   unshift @textsecs, LIB2_DATA->{textsection}{all};
  653 
  654   my %selected = ();
  655   for my $j (qw( dbsection dbchapter dbsubject textbook textchapter textsection )) {
  656     $selected{$j} = $r->param(LIB2_DATA->{$j}{name}) || LIB2_DATA->{$j}{all};
  657   }
  658 
  659   my $text_popup = CGI::popup_menu(-name => 'library_textbook',
  660                    -values =>\@textarray,
  661                    -labels => \%textlabels,
  662                    -default=>$selected{textbook},
  663                    -onchange=>"submit();return true");
  664 
  665 
  666   my $library_keywords = $r->param('library_keywords') || '';
  667 
  668   my $view_problem_line = view_problems_line('lib_view', 'View Problems', $self->r);
  669 
  670   my $count_line = WeBWorK::Utils::ListingDB::countDBListings($r);
  671   if($count_line==0) {
  672     $count_line = "There are no matching pg files";
  673   } else {
  674     $count_line = "There are $count_line matching WeBWorK problem files";
  675   }
  676 
  677   print CGI::div({-class=>"InfoPanel", -align=>"left"},
  678     CGI::hidden(-name=>"library_is_basic", -default=>2,-override=>1),
  679     # Html done by hand since it is temporary
  680     CGI::div({-colspan=>4, -align=>"center"}, 'All Selected Constraints Joined by "And"'),
  681       CGI::div(["Subject:",
  682         CGI::popup_menu(-name=> 'library_subjects',
  683                       -values=>\@subjs,
  684                       -default=> $selected{dbsubject},
  685                        -onchange=>"submit();return true"
  686         )]),
  687       CGI::div({-colspan=>2, -align=>"right"},
  688         CGI::submit(-name=>"lib_select_subject", -value=>"Update Menus",
  689           -style=> $right_button_style)),
  690       CGI::div(["Chapter:",
  691         CGI::popup_menu(-name=> 'library_chapters',
  692                       -values=>\@chaps,
  693                       -default=> $selected{dbchapter},
  694                        -onchange=>"submit();return true"
  695         )]),
  696       CGI::div({-colspan=>2, -align=>"right"},
  697           CGI::submit(-name=>"library_reset", -value=>"Reset",
  698           -style=>$right_button_style)),
  699       CGI::div(["Section:",
  700       CGI::popup_menu(-name=> 'library_sections',
  701                   -values=>\@sects,
  702                   -default=> $selected{dbsection},
  703               -onchange=>"submit();return true"
  704         )]),
  705       CGI::div({-colspan=>2, -align=>"right"},
  706           CGI::submit(-name=>"library_basic", -value=>"Basic Search",
  707           -style=>$right_button_style)),
  708       CGI::div(["Textbook:", $text_popup]),
  709       CGI::div(["Text chapter:",
  710       CGI::popup_menu(-name=> 'library_textchapter',
  711                   -values=>\@textchaps,
  712                   -default=> $selected{textchapter},
  713               -onchange=>"submit();return true"
  714         )]),
  715       CGI::div(["Text section:",
  716       CGI::popup_menu(-name=> 'library_textsection',
  717                   -values=>\@textsecs,
  718                   -default=> $selected{textsection},
  719               -onchange=>"submit();return true"
  720         )]),
  721          CGI::div("Keywords:"),CGI::div({-colspan=>2},
  722        CGI::textfield(-name=>"library_keywords",
  723               -default=>$library_keywords,
  724               -override=>1,
  725               -size=>40)),
  726       CGI::div({-colspan=>3}, $view_problem_line),
  727       CGI::div({-colspan=>3, -align=>"center"}, $count_line)
  728    );
  729 
  730 }
  731 
  732 
  733 #####  Version 4 is the set definition file panel
  734 
  735 sub browse_setdef_panel {
  736   my $self = shift;
  737   my $r = $self->r;
  738   my $ce = $r->ce;
  739   my $library_selected = shift;
  740   my $default_value = "Select a Set Definition File";
  741   # in the following line, the parens after sort are important. if they are
  742   # omitted, sort will interpret get_set_defs as the name of the comparison
  743   # function, and ($ce->{courseDirs}{templates}) as a single element list to
  744   # be sorted. *barf*
  745   my @list_of_set_defs = sort(get_set_defs($ce->{courseDirs}{templates}));
  746   if(scalar(@list_of_set_defs) == 0) {
  747     @list_of_set_defs = (NO_LOCAL_SET_STRING);
  748   } elsif (not $library_selected or $library_selected eq $default_value) {
  749     unshift @list_of_set_defs, $default_value;
  750     $library_selected = $default_value;
  751   }
  752   my $view_problem_line = view_problems_line('view_setdef_set', 'View Problems', $self->r);
  753   my $popupetc = CGI::popup_menu(-name=> 'library_sets',
  754                                 -values=>\@list_of_set_defs,
  755                                 -default=> $library_selected).
  756     CGI::br().  $view_problem_line;
  757   if($list_of_set_defs[0] eq NO_LOCAL_SET_STRING) {
  758     $popupetc = "there are no set definition files in this course to look at."
  759   }
  760   print CGI::div({-class=>"InfoPanel", -align=>"left"}, "Browse from: ",
  761     $popupetc
  762   );
  763 }
  764 
  765 sub make_mysets_row {
  766   my $self = shift;
  767   my $r = $self->r;
  768   my $ce = $r->ce;
  769   my %data = @_;
  770 
  771   my $list_of_local_sets = $data{all_db_sets};
  772   my $have_local_sets = scalar(@$list_of_local_sets);
  773   my $browse_which = 'browse_mysets';
  774   my $library_selected = $self->{current_myset_set};
  775   my $set_selected = $r->param('myset_sets');
  776   my $remember_local_set = $r->param('local_sets');
  777 
  778   ##  Make buttons for additional problem libraries
  779   #my $libs = '';
  780   #foreach my $lib (sort(keys(%problib))) {
  781   # $libs .= ' '. CGI::submit(-name=>"browse_$lib", -value=>$problib{$lib},
  782   #                              ($browse_which eq "browse_$lib")? (-disabled=>1): ())
  783   #   if (-d "$ce->{courseDirs}{templates}/$lib");
  784   #}
  785   #$libs = CGI::br()."or Problems from".$libs if $libs ne '';
  786 
  787   my $these_widths = "width: 25ex";
  788 
  789   if($have_local_sets ==0) {
  790     $list_of_local_sets = [NO_LOCAL_SET_STRING];
  791   } elsif (not defined($set_selected) or $set_selected eq ""
  792     or $set_selected eq SELECT_SET_STRING) {
  793     unshift @{$list_of_local_sets}, SELECT_SET_STRING;
  794     $set_selected = SELECT_SET_STRING;
  795   }
  796   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;';
  797   ## edited this, as a demo for the current set problem list
  798   print CGI::div({-class=>"InfoPanel"},
  799     CGI::submit(-name=>"new_local_set", -value=>"Create a New Set in This Course:",
  800     -onclick=>$myjs
  801     ),
  802     "  ",
  803     CGI::textfield(-name=>"new_set_name",
  804              -default=>"Name for new set here",
  805              -override=>1, -size=>30),
  806   );
  807   # Tidy this list up since it is used in two different places
  808   if ($list_of_local_sets->[0] eq SELECT_SET_STRING) {
  809     shift @{$list_of_local_sets};
  810   }
  811 
  812   #print CGI::div(CGI::div({-bgcolor=>"black"}));
  813   #print CGI::hr();
  814 
  815   $self->browse_mysets_panel($library_selected, $list_of_local_sets, $remember_local_set);
  816 }
  817 
  818 sub make_top_row {
  819   my $self = shift;
  820   my $r = $self->r;
  821   my $ce = $r->ce;
  822   my %data = @_;
  823 
  824   my $list_of_local_sets = $data{all_db_sets};
  825   my $have_local_sets = scalar(@$list_of_local_sets);
  826   my $browse_which = $data{browse_which};
  827   my $library_selected = $self->{current_library_set};
  828   my $set_selected = $r->param('local_sets');
  829   my (@dis1, @dis2, @dis3, @dis4) = ();
  830   @dis1 =  (-disabled=>1) if($browse_which eq 'browse_npl_library');
  831   @dis2 =  (-disabled=>1) if($browse_which eq 'browse_local');
  832   @dis3 =  (-disabled=>1) if($browse_which eq 'edit_mysets');
  833   @dis4 =  (-disabled=>1) if($browse_which eq 'browse_setdefs');
  834 
  835   ##  Make buttons for additional problem libraries
  836   my $libs = '';
  837   foreach my $lib (sort(keys(%problib))) {
  838     $libs .= ' '. CGI::submit(-name=>"browse_$lib", -value=>$problib{$lib},
  839                                  ($browse_which eq "browse_$lib")? (-disabled=>1): ())
  840       if (-d "$ce->{courseDirs}{templates}/$lib");
  841   }
  842   $libs = CGI::br()."or Problems from".$libs if $libs ne '';
  843 
  844   my $these_widths = "width: 25ex";
  845 
  846   if($have_local_sets ==0) {
  847     $list_of_local_sets = [NO_LOCAL_SET_STRING];
  848   } elsif (not defined($set_selected) or $set_selected eq ""
  849     or $set_selected eq SELECT_SET_STRING) {
  850     unshift @{$list_of_local_sets}, SELECT_SET_STRING;
  851     $set_selected = SELECT_SET_STRING;
  852   }
  853 
  854   # Tidy this list up since it is used in two different places
  855   if ($list_of_local_sets->[0] eq SELECT_SET_STRING) {
  856     shift @{$list_of_local_sets};
  857   }
  858 
  859   print CGI::div({-class=>"InfoPanel"},
  860     "Browse ",
  861     CGI::submit(-name=>"browse_npl_library", -value=>"National Problem Library", -style=>$these_widths, @dis1),
  862     CGI::submit(-name=>"browse_local", -value=>"Local Problems", -style=>$these_widths, @dis2),
  863     CGI::submit(-name=>"edit_mysets", -value=>"From This Course", -style=>$these_widths, @dis3),
  864     CGI::submit(-name=>"browse_setdefs", -value=>"Set Definition Files", -style=>$these_widths, @dis4),
  865     $libs,
  866   );
  867 
  868   if ($browse_which eq 'browse_local') {
  869     $self->browse_local_panel($library_selected);
  870   } elsif ($browse_which eq 'edit_mysets') {
  871     $self->edit_mysets_panel($library_selected, $list_of_local_sets);
  872   } elsif ($browse_which eq 'browse_npl_library') {
  873     $self->browse_library_panel();
  874   } elsif ($browse_which eq 'browse_setdefs') {
  875     $self->browse_setdef_panel($library_selected);
  876   } else { ## handle other problem libraries
  877     $self->browse_local_panel($library_selected,$browse_which);
  878   }
  879 
  880   print CGI::div({-class=>"InfoPanel"},
  881              CGI::submit(-name=>"select_all", -style=>$these_widths,
  882                   -value=>"Mark All For Adding"),
  883              CGI::submit(-name=>"select_none", -style=>$these_widths,
  884                   -value=>"Clear All Marks"),
  885          ),
  886     CGI::div({},
  887         CGI::submit(-name=>"rerandomize",
  888                     -style=>$these_widths,
  889                     -value=>"Rerandomize"),
  890         CGI::submit(-name=>"cleardisplay",
  891                 -style=>$these_widths,
  892                 -value=>"Clear Problem Display")
  893     );
  894 }
  895 
  896 sub make_data_row {
  897   my $self = shift;
  898   my $sourceFileName = shift;
  899   my $pg = shift;
  900   my $cnt = shift;
  901   my $mark = shift || 0;
  902 
  903   $sourceFileName =~ s|^./||; # clean up top ugliness
  904 
  905   my $urlpath = $self->r->urlpath;
  906   my $db = $self->r->db;
  907 
  908   ## to set up edit and try links elegantly we want to know if
  909   ##    any target set is a gateway assignment or not
  910   my $localSet = $self->r->param('local_sets');
  911   my $setRecord;
  912   if ( defined($localSet) && $localSet ne SELECT_SET_STRING &&
  913        $localSet ne NO_LOCAL_SET_STRING ) {
  914     $setRecord = $db->getGlobalSet( $localSet );
  915   }
  916   my $isGatewaySet = ( defined($setRecord) &&
  917            $setRecord->assignment_type =~ /gateway/ );
  918 
  919   my $problem_output = $pg->{flags}->{error_flag} ?
  920     CGI::div({class=>"ResultsWithError"}, CGI::em("This problem produced an error"))
  921     : CGI::div({class=>"RenderSolo"}, $pg->{body_text});
  922   $problem_output .= $pg->{flags}->{comment} if($pg->{flags}->{comment});
  923 
  924 
  925   #if($self->{r}->param('browse_which') ne 'browse_npl_library') {
  926   my $problem_seed = $self->{'problem_seed'} || 1234;
  927   my $edit_link = CGI::a({href=>$self->systemLink(
  928      $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor",
  929         courseID =>$urlpath->arg("courseID"),
  930         setID=>"Undefined_Set",
  931         problemID=>"1"),
  932       params=>{sourceFilePath => "$sourceFileName", problemSeed=> $problem_seed}
  933       ), target=>"WW_Editor"}, "Edit it" );
  934 
  935   my $displayMode = $self->r->param("mydisplayMode");
  936   $displayMode = $self->r->ce->{pg}->{options}->{displayMode}
  937     if not defined $displayMode or $displayMode eq "None";
  938   my $module = ( $isGatewaySet ) ? "GatewayQuiz" : "Problem";
  939   my %pathArgs = ( courseID =>$urlpath->arg("courseID"),
  940       setID=>"Undefined_Set" );
  941   $pathArgs{problemID} = "1" if ( ! $isGatewaySet );
  942 
  943   my $try_link = CGI::a({href=>$self->systemLink(
  944     $urlpath->newFromModule("WeBWorK::ContentGenerator::$module",
  945       %pathArgs ),
  946       params =>{
  947         effectiveUser => scalar($self->r->param('user')),
  948         editMode => "SetMaker",
  949         problemSeed=> $problem_seed,
  950         sourceFilePath => "$sourceFileName",
  951         displayMode => $displayMode,
  952       }
  953     ), target=>"WW_View"}, "Try it");
  954 
  955   my %add_box_data = ( -id=>"trial$cnt" ,-name=>"trial$cnt",-value=>1,-label=>"Add this problem to the target set on the next update");
  956   #allow for a move command from one problem set to anoter
  957   my $move_box_data;
  958   if($self->r->param('edit_mysets_set')){
  959     $move_box_data = CGI::checkbox( -id=>"moved$cnt" ,-name=>"moved$cnt",-value=>1,,-override=>1,-label=>"Move this problem from this set to the target set on the next update");
  960   }
  961   else{
  962     $move_box_data = "";
  963   }
  964   if($mark & SUCCESS) {
  965     $add_box_data{ -label } .= " (just added this problem)";
  966   } elsif($mark & ADDED) {
  967     $add_box_data{ -checked } = 1;
  968   }
  969 
  970   if(!($self->{isInSet}{$sourceFileName})){
  971 
  972     print CGI::div({-class=>"problem libraryProblem", -align=>"left", -draggable=>"true", -href=>"#", -id=>"$cnt"},
  973       CGI::p({},"File name: $sourceFileName "),
  974       CGI::p({}, $edit_link, " ", $try_link),
  975       CGI::p(CGI::checkbox(-id=>"hideme$cnt", -name=>"hideme$cnt",-value=>1,-label=>"Don't show this problem on the next update",-override=>1)),
  976       CGI::p(CGI::checkbox((%add_box_data),-override=>1)),
  977       CGI::p($move_box_data),
  978       CGI::hidden(-name=>"filetrial$cnt", -default=>$sourceFileName,-override=>1).
  979       CGI::p($problem_output)
  980     );
  981   }
  982   else{
  983     print CGI::div({-class=>"problem libraryProblem used", -align=>"left", -draggable=>"true", -href=>"#", -id=>"$cnt"},
  984       CGI::p({},"File name: $sourceFileName "),
  985       CGI::p({}, $edit_link, " ", $try_link),
  986       CGI::p(CGI::checkbox(-id=>"hideme$cnt", -name=>"hideme$cnt",-value=>1,-label=>"Don't show this problem on the next update",-override=>1)),
  987       CGI::p(CGI::checkbox((%add_box_data),-override=>1)),
  988       CGI::p($move_box_data),
  989       CGI::hidden(-name=>"filetrial$cnt", -default=>$sourceFileName,-override=>1).
  990       CGI::p($problem_output),
  991       CGI::b("(This problem is in the target set)")
  992     );
  993   }
  994 }
  995 
  996 sub make_myset_data_row {
  997   my $self = shift;
  998   my $sourceFileName = shift;
  999   my $pg = shift;
 1000   my $cnt = shift;
 1001   my $mark = shift || 0;
 1002 
 1003   $sourceFileName =~ s|^./||; # clean up top ugliness
 1004 
 1005   my $urlpath = $self->r->urlpath;
 1006   my $db = $self->r->db;
 1007 
 1008   ## to set up edit and try links elegantly we want to know if
 1009   ##    any target set is a gateway assignment or not
 1010   my $localSet = $self->r->param('local_sets');
 1011   my $setRecord;
 1012   if ( defined($localSet) && $localSet ne SELECT_SET_STRING &&
 1013        $localSet ne NO_LOCAL_SET_STRING ) {
 1014     $setRecord = $db->getGlobalSet( $localSet );
 1015   }
 1016   my $isGatewaySet = ( defined($setRecord) &&
 1017            $setRecord->assignment_type =~ /gateway/ );
 1018 
 1019   my $problem_output = $pg->{flags}->{error_flag} ?
 1020     CGI::div({class=>"ResultsWithError"}, CGI::em("This problem produced an error"))
 1021     : CGI::div({class=>"RenderSolo"}, $pg->{body_text});
 1022   $problem_output .= $pg->{flags}->{comment} if($pg->{flags}->{comment});
 1023 
 1024 
 1025   #if($self->{r}->param('browse_which') ne 'browse_npl_library') {
 1026   my $problem_seed = $self->{'problem_seed'} || 1234;
 1027   my $edit_link = CGI::a({href=>$self->systemLink(
 1028      $urlpath->newFromModule("WeBWorK::ContentGenerator::Instructor::PGProblemEditor",
 1029         courseID =>$urlpath->arg("courseID"),
 1030         setID=>"Undefined_Set",
 1031         problemID=>"1"),
 1032       params=>{sourceFilePath => "$sourceFileName", problemSeed=> $problem_seed}
 1033       ), target=>"WW_Editor"}, "Edit it" );
 1034 
 1035   my %delete_box_data = ( -id=>"deleted$cnt".'myset' ,-name=>"deleted$cnt",-value=>1,-label=>"Delete this problem from the target set on the next update");
 1036 
 1037   my $displayMode = $self->r->param("mydisplayMode");
 1038   $displayMode = $self->r->ce->{pg}->{options}->{displayMode}
 1039     if not defined $displayMode or $displayMode eq "None";
 1040   my $module = ( $isGatewaySet ) ? "GatewayQuiz" : "Problem";
 1041   my %pathArgs = ( courseID =>$urlpath->arg("courseID"),
 1042       setID=>"Undefined_Set" );
 1043   $pathArgs{problemID} = "1" if ( ! $isGatewaySet );
 1044 
 1045   my $try_link = CGI::a({href=>$self->systemLink(
 1046     $urlpath->newFromModule("WeBWorK::ContentGenerator::$module",
 1047       %pathArgs ),
 1048       params =>{
 1049         effectiveUser => scalar($self->r->param('user')),
 1050         editMode => "SetMaker",
 1051         problemSeed=> $problem_seed,
 1052         sourceFilePath => "$sourceFileName",
 1053         displayMode => $displayMode,
 1054       }
 1055     ), target=>"WW_View"}, "Try it");
 1056 
 1057   print CGI::div({-class=>"problem myProblem", -draggable=>"true", -href=>"#", -id=>("$cnt".'myset')},
 1058     CGI::p({},"File name: $sourceFileName "),
 1059     CGI::p({}, $edit_link, " ", $try_link),
 1060     CGI::p(CGI::checkbox((%delete_box_data),-override=>1)),
 1061     CGI::hidden(-name=>"mysetfiletrial$cnt", -default=>$sourceFileName,-override=>1).
 1062     CGI::p($problem_output),
 1063   );
 1064 }
 1065 
 1066 sub clear_default {
 1067   my $r = shift;
 1068   my $param = shift;
 1069   my $default = shift;
 1070   my $newvalue = $r->param($param) || '';
 1071   $newvalue = '' if($newvalue eq $default);
 1072   $r->param($param, $newvalue);
 1073 }
 1074 
 1075 sub pre_header_initialize {
 1076   my ($self) = @_;
 1077   my $r = $self->r;
 1078   ## For all cases, lets set some things
 1079   $self->{error}=0;
 1080   my $ce = $r->ce;
 1081   my $db = $r->db;
 1082   my $maxShown = $r->param('max_shown') || MAX_SHOW_DEFAULT;
 1083   $maxShown = 10000000 if($maxShown eq 'All'); # let's hope there aren't more
 1084   my $library_basic = $r->param('library_is_basic') || 1;
 1085   $self->{problem_seed} = $r->param('problem_seed') || 1234;
 1086   ## Fix some parameters
 1087   for my $key (keys(%{ LIB2_DATA() })) {
 1088     clear_default($r, LIB2_DATA->{$key}->{name}, LIB2_DATA->{$key}->{all} );
 1089   }
 1090     ##  Grab library sets to display from parameters list.  We will modify this
 1091     ##  as we go through the if/else tree
 1092     $self->{current_library_set} =  $r->param('library_sets');
 1093     $self->{current_myset_set} = $r->param('myset_sets');
 1094     if (not defined($self->{current_myset_set})
 1095     or $self->{current_myset_set} eq "Select a Homework Set"
 1096     or $self->{current_myset_set} eq NO_LOCAL_SET_STRING) {
 1097       my @all_db_sets = $db->listGlobalSets;
 1098       @all_db_sets = sortByName(undef, @all_db_sets);
 1099       $self->{current_myset_set} = shift(@all_db_sets);
 1100     }
 1101 
 1102   ##  These directories will have individual buttons
 1103   %problib = %{$ce->{courseFiles}{problibs}} if $ce->{courseFiles}{problibs};
 1104 
 1105   my $userName = $r->param('user');
 1106   my $user = $db->getUser($userName); # checked
 1107   die "record for user $userName (real user) does not exist."
 1108     unless defined $user;
 1109   my $authz = $r->authz;
 1110   unless ($authz->hasPermissions($userName, "modify_problem_sets")) {
 1111     return(""); # Error message already produced in the body
 1112   }
 1113 
 1114   ## Now one action we have to deal with here
 1115   if ($r->param('edit_local')) {
 1116     my $urlpath = $r->urlpath;
 1117     my $db = $r->db;
 1118     my $checkset = $db->getGlobalSet($r->param('local_sets'));
 1119     if (not defined($checkset)) {
 1120       $self->{error} = 1;
 1121       $self->addbadmessage('You need to select a "Target Set" before you can edit it.');
 1122     } else {
 1123       my $page = $urlpath->newFromModule('WeBWorK::ContentGenerator::Instructor::ProblemSetDetail', setID=>$r->param('local_sets'), courseID=>$urlpath->arg("courseID"));
 1124       my $url = $self->systemLink($page);
 1125       $self->reply_with_redirect($url);
 1126     }
 1127   }
 1128 
 1129   ## Next, lots of set up so that errors can be reported with message()
 1130 
 1131   ############# List of problems we have already printed
 1132 
 1133   $self->{past_problems} = get_past_problem_files($r);
 1134   # if we don't end up reusing problems, this will be wiped out
 1135   # if we do redisplay the same problems, we must adjust this accordingly
 1136   my @past_marks = map {$_->[1]} @{$self->{past_problems}};
 1137   my $none_shown = scalar(@{$self->{past_problems}})==0;
 1138   my @pg_files=();
 1139   my @myset_files=();
 1140   my $use_previous_problems = 1;
 1141   my $first_shown = $r->param('first_shown') || 0;
 1142   my $last_shown = $r->param('last_shown');
 1143   if (not defined($last_shown)) {
 1144     $last_shown = -1;
 1145   }
 1146   my @all_past_list = (); # these are include requested, but not shown
 1147   my $j = 0;
 1148   while (defined($r->param("all_past_list$j"))) {
 1149     push @all_past_list, $r->param("all_past_list$j");
 1150     $j++;
 1151   }
 1152 
 1153   ############# Default of which problem selector to display
 1154 
 1155   my $browse_which = $r->param('browse_which') || 'browse_npl_library';
 1156 
 1157 
 1158 
 1159   ## check for problem lib buttons
 1160   my $browse_lib = '';
 1161   foreach my $lib (keys %problib) {
 1162     if ($r->param("browse_$lib")) {
 1163       $browse_lib = "browse_$lib";
 1164       last;
 1165     }
 1166   }
 1167 
 1168 
 1169   ########### Start the logic through if elsif elsif ...
 1170     debug("browse_lib", $r->param("$browse_lib"));
 1171     debug("browse_npl_library", $r->param("browse_npl_library"));
 1172     debug("edit_mysets", $r->param("edit_mysets"));
 1173     debug("browse_setdefs", $r->param("browse_setdefs"));
 1174   ##### Asked to browse certain problems
 1175   if ($browse_lib ne '') {
 1176     $browse_which = $browse_lib;
 1177     $self->{current_library_set} = "";
 1178     $use_previous_problems = 0; @pg_files = (); ## clear old problems
 1179   } elsif ($r->param('browse_npl_library')) {
 1180     $browse_which = 'browse_npl_library';
 1181     $self->{current_library_set} = "";
 1182     $use_previous_problems = 0; @pg_files = (); ## clear old problems
 1183   } elsif ($r->param('browse_local')) {
 1184     $browse_which = 'browse_local';
 1185     #$self->{current_library_set} = "";
 1186     $use_previous_problems = 0; @pg_files = (); ## clear old problems
 1187   } elsif ($r->param('edit_mysets')) {
 1188     $browse_which = 'edit_mysets';
 1189     $self->{current_library_set} = "";
 1190     $use_previous_problems = 0; @pg_files = (); ## clear old problems
 1191   } elsif ($r->param('browse_setdefs')) {
 1192     $browse_which = 'browse_setdefs';
 1193     $self->{current_library_set} = "";
 1194     $use_previous_problems = 0; @pg_files = (); ## clear old problems
 1195 
 1196     ##### Change the seed value
 1197 
 1198   } elsif ($r->param('rerandomize')) {
 1199     $self->{problem_seed}= 1+$self->{problem_seed};
 1200     #$r->param('problem_seed', $problem_seed);
 1201     $self->addbadmessage('Changing the problem seed for display, but there are no problems showing.') if $none_shown;
 1202 
 1203     ##### Clear the display
 1204 
 1205   } elsif ($r->param('cleardisplay')) {
 1206     @pg_files = ();
 1207     $use_previous_problems=0;
 1208     $self->addbadmessage('The display was already cleared.') if $none_shown;
 1209 
 1210     ##### View problems selected from the local list
 1211 
 1212   } elsif ($r->param('view_local_set')) {
 1213 
 1214     my $set_to_display = $self->{current_library_set};
 1215     if (not defined($set_to_display) or $set_to_display eq SELECT_LOCAL_STRING or $set_to_display eq "Found no directories containing problems") {
 1216       $self->addbadmessage('You need to select a set to view.');
 1217     } else {
 1218       $set_to_display = '.' if $set_to_display eq MY_PROBLEMS;
 1219       $set_to_display = substr($browse_which,7) if $set_to_display eq MAIN_PROBLEMS;
 1220       @pg_files = list_pg_files($ce->{courseDirs}->{templates},
 1221         "$set_to_display");
 1222       $use_previous_problems=0;
 1223     }
 1224 
 1225     ##### View problems selected from the a set in this course
 1226   } elsif ($r->param('edit_mysets_set')){
 1227 
 1228     my $set_to_display = $self->{current_library_set};
 1229       debug("set_to_display is $set_to_display");
 1230       if (not defined($set_to_display)
 1231           or $set_to_display eq "Select a Homework Set"
 1232           or $set_to_display eq NO_LOCAL_SET_STRING) {
 1233         $self->addbadmessage("You need to select a set from this course to view.");
 1234       } else {
 1235         # DBFIXME don't use ID list, use an iterator
 1236         my @problemList = $db->listGlobalProblems($set_to_display);
 1237         my $problem;
 1238         @pg_files=();
 1239         for $problem (@problemList) {
 1240           my $problemRecord = $db->getGlobalProblem($set_to_display, $problem); # checked
 1241           die "global $problem for set $set_to_display not found." unless
 1242             $problemRecord;
 1243           push @pg_files, $problemRecord->source_file;
 1244 
 1245         }
 1246         @pg_files = sortByName(undef,@pg_files);
 1247         $use_previous_problems=0;
 1248       }
 1249 
 1250     ##### View from the library database
 1251 
 1252   } elsif ($r->param('lib_view')) {
 1253     @pg_files=();
 1254     my @dbsearch = WeBWorK::Utils::ListingDB::getSectionListings($r);
 1255     my ($result, $tolibpath);
 1256     for $result (@dbsearch) {
 1257       $tolibpath = "Library/$result->{path}/$result->{filename}";
 1258 
 1259       ## Too clunky!!!!
 1260       push @pg_files, $tolibpath;
 1261     }
 1262     $use_previous_problems=0;
 1263 
 1264     ##### View a set from a set*.def
 1265 
 1266   } elsif ($r->param('view_setdef_set')) {
 1267 
 1268     my $set_to_display = $self->{current_library_set};
 1269     debug("set_to_display is $set_to_display");
 1270     if (not defined($set_to_display)
 1271         or $set_to_display eq "Select a Set Definition File"
 1272         or $set_to_display eq NO_LOCAL_SET_STRING) {
 1273       $self->addbadmessage("You need to select a set definition file to view.");
 1274     } else {
 1275       @pg_files= $self->read_set_def($set_to_display);
 1276     }
 1277     $use_previous_problems=0;
 1278 
 1279     ##### Edit the current local homework set
 1280 
 1281   } elsif ($r->param('edit_local')) { ## Jump to set edit page
 1282 
 1283     ; # already handled
 1284 
 1285 
 1286     ##### Make a new local homework set
 1287 
 1288   } elsif ($r->param('new_local_set')) {
 1289     if ($r->param('new_set_name') !~ /^[\w .-]*$/) {
 1290       $self->addbadmessage("The name ".$r->param('new_set_name')." is not a valid set name.  Use only letters, digits, -, _, and .");
 1291     } else {
 1292       my $newSetName = $r->param('new_set_name');
 1293       # if we want to munge the input set name, do it here
 1294       $newSetName =~ s/\s/_/g;
 1295       debug("local_sets was ", $r->param('local_sets'));
 1296       $r->param('local_sets',$newSetName);  ## use of two parameter param
 1297       debug("new value of local_sets is ", $r->param('local_sets'));
 1298       my $newSetRecord   = $db->getGlobalSet($newSetName);
 1299       if (defined($newSetRecord)) {
 1300               $self->addbadmessage("The set name $newSetName is already in use.
 1301               Pick a different name if you would like to start a new set.");
 1302       } else {      # Do it!
 1303         # DBFIXME use $db->newGlobalSet
 1304         $newSetRecord = $db->{set}->{record}->new();
 1305         $newSetRecord->set_id($newSetName);
 1306         $newSetRecord->set_header("");
 1307         $newSetRecord->hardcopy_header("");
 1308         $newSetRecord->open_date(time()+60*60*24*7); # in one week
 1309         $newSetRecord->due_date(time()+60*60*24*7*2); # in two weeks
 1310         $newSetRecord->answer_date(time()+60*60*24*7*3); # in three weeks
 1311         eval {$db->addGlobalSet($newSetRecord)};
 1312         if ($@) {
 1313           $self->addbadmessage("Problem creating set $newSetName<br> $@");
 1314         } else {
 1315           $self->addgoodmessage("Set $newSetName has been created.");
 1316           my $selfassign = $r->param('selfassign') || "";
 1317           $selfassign = "" if($selfassign =~ /false/i); # deal with javascript false
 1318           if($selfassign) {
 1319             $self->assignSetToUser($userName, $newSetRecord);
 1320             $self->addgoodmessage("Set $newSetName was assigned to $userName.");
 1321           }
 1322         }
 1323       }
 1324     }
 1325 
 1326     ##### Add selected problems to the current local set
 1327 
 1328   } elsif ($r->param('update')) {
 1329     ## first handle problems to be added before we hide them
 1330     my($localSet, @selected);
 1331 
 1332     my @add_pg_files = grep {(($_->[1] & ADDED)) != 0 } @{$self->{past_problems}};
 1333     my @add_selected = map {$_->[0]} @add_pg_files;
 1334 
 1335     my @delete_pg_files = grep {(($_->[1] & DELETED)) != 0} @{$self->{past_problems}};
 1336     my @delete_selected = map {$_->[0]} @delete_pg_files;
 1337 
 1338     my @move_pg_files = grep {(($_->[1] & MOVED)) != 0} @{$self->{past_problems}};
 1339     my @move_selected = map {$_->[0]} @move_pg_files;
 1340 
 1341     my @action_files = grep {$_->[1] > 0 } @{$self->{past_problems}};
 1342     # There are now good reasons to do an update without selecting anything.
 1343     #if(scalar(@action_files) == 0) {
 1344     #  $self->addbadmessage('Update requested, but no problems were marked.');
 1345     #}
 1346 
 1347     if (scalar(@add_selected)>0) {  # if some are to be added, they need a place to go
 1348       $localSet = $r->param('myset_sets');
 1349       if (not defined($localSet) or
 1350           $localSet eq SELECT_SET_STRING or
 1351                 $localSet eq NO_LOCAL_SET_STRING) {
 1352         $self->addbadmessage('You are trying to add problems to something,
 1353         but you did not select a "Target Set" name as a target.');
 1354       } else {
 1355         my $newSetRecord  = $db->getGlobalSet($localSet);
 1356         if (not defined($newSetRecord)) {
 1357           $self->addbadmessage("You are trying to add problems to $localSet,
 1358           but that set does not seem to exist!  I bet you used your \"Back\" button.");
 1359         } else {
 1360           my $addcount = add_selected($self, $db, $localSet);
 1361           if($addcount > 0) {
 1362             $self->addgoodmessage("Added $addcount problem".(($addcount>1)?'s':'').
 1363               " to $localSet.");
 1364           }
 1365         }
 1366       }
 1367     }
 1368     if (scalar(@delete_selected)>0) { # if some are to be added, they need a place to go
 1369       $localSet = $r->param('myset_sets');
 1370       if (not defined($localSet) or
 1371           $localSet eq SELECT_SET_STRING or
 1372                 $localSet eq NO_LOCAL_SET_STRING) {
 1373         $self->addbadmessage('You are trying to add problems to something,
 1374         but you did not select a "Target Set" name as a target.');
 1375       } else {
 1376         my $newSetRecord  = $db->getGlobalSet($localSet);
 1377         if (not defined($newSetRecord)) {
 1378           $self->addbadmessage("You are trying to delete problems to $localSet,
 1379           but that set does not seem to exist!  I bet you used your \"Back\" button.");
 1380         } else {
 1381           my $deletecount = delete_selected($self, $db, $localSet);
 1382           if($deletecount > 0) {
 1383             $self->addgoodmessage("Deleted $deletecount problem".(($deletecount>1)?'s':'').
 1384               " to $localSet.");
 1385           }
 1386         }
 1387       }
 1388     }
 1389     if (scalar(@move_selected)>0) { # if some are to be added, they need a place to go
 1390       $localSet = $r->param('myset_sets');
 1391       my $otherSet = $self->{current_library_set};
 1392       if (not defined($localSet) or not defined($otherSet) or
 1393           $localSet eq SELECT_SET_STRING or
 1394                 $localSet eq NO_LOCAL_SET_STRING) {
 1395         $self->addbadmessage('You are trying to add problems to something,
 1396         but you did not select a "Target Set" name as a target.');
 1397       } else {
 1398         my $newSetRecord  = $db->getGlobalSet($localSet);
 1399         my $otherNewSetRecord = $db->getGlobalSet($otherSet);
 1400         if (not defined($newSetRecord) or not defined($otherNewSetRecord)) {
 1401           $self->addbadmessage("You are trying to move problems from $otherNewSetRecord to $localSet,
 1402           but that set does not seem to exist!  I bet you used your \"Back\" button.");
 1403         } else {
 1404           my $addcount = add_selected($self, $db, $localSet);
 1405           my $deletecount = delete_selected($self, $db, $otherSet);
 1406           if($addcount > 0 && $deletecount > 0) {
 1407             $self->addgoodmessage("Moved $addcount problem".(($addcount>1)?'s':'').
 1408               " from $otherSet to $localSet.");
 1409           }
 1410         }
 1411       }
 1412     }
 1413     ## now handle problems to be hidden
 1414 
 1415     ## only keep the ones which are not hidden
 1416     @pg_files = grep {($_->[1] & HIDDEN) ==0 } @{$self->{past_problems}};
 1417     @pg_files = grep {(($_->[1] & DELETED)) != 0 } @pg_files;
 1418     @past_marks = map {$_->[1]} @pg_files;
 1419     @pg_files = map {$_->[0]} @pg_files;
 1420     @all_past_list = (@all_past_list[0..($first_shown-1)],
 1421           @pg_files,
 1422           @all_past_list[($last_shown+1)..(scalar(@all_past_list)-1)]);
 1423     $last_shown = $first_shown+$maxShown -1; debug("last_shown 3: ", $last_shown);
 1424     $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list)); debug("last_shown 4: ", $last_shown);
 1425 
 1426   } elsif ($r->param('next_page')) {
 1427     $first_shown = $last_shown+1;
 1428     $last_shown = $first_shown+$maxShown-1; debug("last_shown 5: ", $last_shown);
 1429     $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list)); debug("last_shown 6: ", $last_shown);
 1430     @past_marks = ();
 1431   } elsif ($r->param('prev_page')) {
 1432     $last_shown = $first_shown-1;
 1433     $first_shown = $last_shown - $maxShown+1;
 1434 
 1435     $first_shown = 0 if($first_shown<0);
 1436     @past_marks = ();
 1437 
 1438   } elsif ($r->param('select_all')) {
 1439     @past_marks = map {1} @past_marks;
 1440   } elsif ($r->param('library_basic')) {
 1441     $library_basic = 1;
 1442     for my $jj (qw(textchapter textsection textbook)) {
 1443       $r->param('library_'.$jj,'');
 1444     }
 1445   } elsif ($r->param('library_advanced')) {
 1446     $library_basic = 2;
 1447   } elsif ($r->param('library_reset')) {
 1448     for my $jj (qw(chapters sections subjects textbook keywords)) {
 1449       $r->param('library_'.$jj,'');
 1450     }
 1451   } elsif ($r->param('select_none')) {
 1452     @past_marks = ();
 1453   } else {
 1454     #nothing
 1455   }       ##### end of the if elsif ...
 1456 
 1457   my $default_set = $self->{current_myset_set};
 1458     #debug("set_to_display is $default_set");
 1459     if (not defined($default_set)
 1460       or $default_set eq "Select a Homework Set"
 1461       or $default_set eq NO_LOCAL_SET_STRING) {
 1462       $self->addbadmessage("You need to select a set from this course to view.");
 1463     } else {
 1464       # DBFIXME don't use ID list, use an iterator
 1465       my @problemList = $db->listGlobalProblems($default_set);
 1466       my $problem;
 1467       @myset_files=();
 1468       for $problem (@problemList) {
 1469         my $problemRecord = $db->getGlobalProblem($default_set, $problem); # checked
 1470         die "global $problem for set $default_set not found." unless
 1471           $problemRecord;
 1472         push @myset_files, $problemRecord->source_file;
 1473 
 1474       }
 1475       @myset_files = sortByName(undef,@myset_files);
 1476       $use_previous_problems=0;
 1477     }
 1478 
 1479   ############# List of local sets
 1480 
 1481   # DBFIXME sorting in database, please!
 1482   my @all_db_sets = $db->listGlobalSets;
 1483   @all_db_sets = sortByName(undef, @all_db_sets);
 1484 
 1485   if ($use_previous_problems) {
 1486     @pg_files = @all_past_list;
 1487   } else {
 1488     $first_shown = 0;
 1489     $last_shown = scalar(@pg_files)<$maxShown ? scalar(@pg_files) : $maxShown;
 1490     $last_shown--;    # to make it an array index
 1491     @past_marks = ();
 1492   }
 1493   ############# Now store data in self for retreival by body
 1494   $self->{first_shown} = $first_shown;
 1495   $self->{last_shown} = $last_shown;
 1496   $self->{browse_which} = $browse_which;
 1497   #$self->{problem_seed} = $problem_seed;
 1498   $self->{pg_files} = \@pg_files;
 1499   $self->{myset_files} = \@myset_files;
 1500   $self->{past_marks} = \@past_marks;
 1501   $self->{all_db_sets} = \@all_db_sets;
 1502   $self->{library_basic} = $library_basic;
 1503   debug("past_marks is ", join(" ", @{$self->{past_marks}}));
 1504 }
 1505 
 1506 
 1507 sub title {
 1508   return "Library Browser v2";
 1509 }
 1510 
 1511 # hide view options panel since it distracts from SetMaker's built-in view options
 1512 sub options {
 1513   return "";
 1514 }
 1515 
 1516 sub head {
 1517   print '<script src="/webwork2_files/js/dnd.js"></script>';
 1518   print '<script src="/webwork2_files/js/problem_grid.js"></script>';
 1519   print '<link rel="stylesheet" type="text/css" href="/webwork2_files/css/setmaker2.css" />';
 1520   print '<script>window.addEventListener("load", setup, false);</script>';
 1521   return "";
 1522 }
 1523 
 1524 sub body {
 1525   my ($self) = @_;
 1526 
 1527   my $r = $self->r;
 1528   my $ce = $r->ce;    # course environment
 1529   my $db = $r->db;    # database
 1530   my $j;      # garden variety counter
 1531 
 1532   my $userName = $r->param('user');
 1533 
 1534   my $user = $db->getUser($userName); # checked
 1535   die "record for user $userName (real user) does not exist."
 1536     unless defined $user;
 1537 
 1538   ### Check that this is a professor
 1539   my $authz = $r->authz;
 1540   unless ($authz->hasPermissions($userName, "modify_problem_sets")) {
 1541     print "User $userName returned " .
 1542       $authz->hasPermissions($user, "modify_problem_sets") .
 1543   " for permission";
 1544     return(CGI::div({class=>'ResultsWithError'},
 1545     CGI::em("You are not authorized to access the Instructor tools.")));
 1546   }
 1547 
 1548   my $showHints = $r->param('showHints');
 1549   my $showSolutions = $r->param('showSolutions');
 1550 
 1551   ##########  Extract information computed in pre_header_initialize
 1552 
 1553   my $first_shown = $self->{first_shown};
 1554   my $last_shown = $self->{last_shown};
 1555   my $browse_which = $self->{browse_which};
 1556   my $problem_seed = $self->{problem_seed}||1234;
 1557   my @pg_files = @{$self->{pg_files}};
 1558   my @myset_files =@{$self->{myset_files}};
 1559   my @all_db_sets = @{$self->{all_db_sets}};
 1560 
 1561   my @pg_html;
 1562   if ($last_shown >= $first_shown) {
 1563     @pg_html = renderProblems(
 1564       r=> $r,
 1565       user => $user,
 1566       problem_list => [@pg_files[$first_shown..$last_shown]],
 1567       displayMode => 'images',
 1568       showHints => $showHints,
 1569       showSolutions => $showSolutions,
 1570     );
 1571   }
 1572   my @myset_html;
 1573   my $displayModePlaceholder;
 1574   if (not defined($r->param('mydisplayMode'))){
 1575     $displayModePlaceholder = "None";
 1576   }
 1577   else{
 1578     $displayModePlaceholder = $r->param('mydisplayMode');
 1579   }
 1580   if (scalar(@myset_files) >= $first_shown) {
 1581     @myset_html = renderProblems(
 1582       r=> $r,
 1583       user => $user,
 1584       problem_list => [@myset_files[$first_shown..(scalar(@myset_files)-1)]],
 1585       displayMode => 'images',
 1586       showHints => $showHints,
 1587       showSolutions => $showSolutions,
 1588     );
 1589   }
 1590 
 1591   my %isInSet;
 1592   my $setName = $r->param("myset_sets");
 1593   if ($setName) {
 1594     # DBFIXME where clause, iterator
 1595     # DBFIXME maybe instead of hashing here, query when checking source files?
 1596     # DBFIXME definitely don't need to be making full record objects
 1597     # DBFIXME SELECT source_file FROM whatever_problem WHERE set_id=? GROUP BY source_file ORDER BY NULL;
 1598     # DBFIXME (and stick result directly into hash)
 1599     foreach my $problem ($db->listGlobalProblems($setName)) {
 1600       my $problemRecord = $db->getGlobalProblem($setName, $problem);
 1601       $isInSet{$problemRecord->source_file} = 1;
 1602     }
 1603   }
 1604   $self->{isInSet} = \%isInSet;
 1605   my $jj;
 1606   ##########  Top part
 1607   print '<button id="gridifyButton" onclick="gridify();">Gridify!!</button>';
 1608   print '<div id="editor-form">';
 1609     print CGI::start_form({-method=>"POST", -action=>$r->uri, -name=>'mainform'}),
 1610       $self->hidden_authen_fields;
 1611       print '<div id="control_panel">';
 1612         print '<div id="myset_control" class="mysets control">';
 1613           $self->make_mysets_row('all_db_sets'=>\@all_db_sets);
 1614         print '</div>';
 1615         print '<div id="library_control" class="setmaker_library control">';
 1616                 $self->make_top_row('all_db_sets'=>\@all_db_sets, 'browse_which'=> $browse_which);
 1617         print '</div>';
 1618       print '</div>';
 1619       print '<div style="clear:both;padding:0px;margin:0px;"></div>';
 1620       #########  Table of mysets problems
 1621       print '<div id="problem_container">';
 1622         print '<div id="mysets_problems" class="problemList mysets">';
 1623           for ($jj=0; $jj<scalar(@myset_html); $jj++) {
 1624             $myset_files[$jj] =~ s|^$ce->{courseDirs}->{templates}/?||;
 1625             $self->make_myset_data_row($myset_files[$jj+$first_shown], $myset_html[$jj], $jj+1, $self->{past_marks}->[$jj]);
 1626           }
 1627         print '</div>';
 1628 
 1629         print '<div id="size_slider"><p>||</p></div>';
 1630 
 1631         print '<div id="setmaker_library_box" class="setmaker_library">';
 1632           print CGI::hidden(-name=>'browse_which', -value=>$browse_which,-override=>1),
 1633           CGI::hidden(-name=>'problem_seed', -value=>$problem_seed, -override=>1);
 1634           for ($j = 0 ; $j < scalar(@pg_files) ; $j++) {
 1635             print CGI::hidden(-name=>"all_past_list$j", -value=>$pg_files[$j],-override=>1);
 1636           }
 1637           print CGI::hidden(-name=>'first_shown', -value=>$first_shown,-override=>1);
 1638           print CGI::hidden(-name=>'last_shown', -value=>$last_shown, -override=>1);
 1639           print '<div id="setmaker_library_problems" class="problemList">';
 1640           ########## Now print problems
 1641             for ($jj=0; $jj<scalar(@pg_html); $jj++) {
 1642               $pg_files[$jj] =~ s|^$ce->{courseDirs}->{templates}/?||;
 1643               $self->make_data_row($pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1,         $self->{past_marks}->[$jj]);
 1644             }
 1645           print '</div>';
 1646           ########## Finish things off
 1647           my ($next_button, $prev_button) = ("", "");
 1648           if ($first_shown > 0) {
 1649             $prev_button = CGI::submit(-name=>"prev_page", -style=>"width:15ex", -value=>"Previous page");
 1650           }
 1651           if ((1+$last_shown)<scalar(@pg_files)) {
 1652             $next_button = CGI::submit(-name=>"next_page", -style=>"width:15ex", -value=>"Next page");
 1653           }
 1654           if (scalar(@pg_files)>0) {
 1655             print CGI::p(($first_shown+1)."-".($last_shown+1)." of ".scalar(@pg_files)." shown.", $prev_button, " ", $next_button,
 1656             CGI::submit(-name=>"update", -style=>"width:15ex; font-weight:bold", -value=>"Update Set"));
 1657           }
 1658           #close setmaker_library
 1659         print '</div>';
 1660       #close problem_container
 1661       print '</div>';
 1662     print CGI::endform(), "\n";
 1663     #close form-editor
 1664   print '</div>';
 1665   print '<div style="clear:both;"></div>';
 1666   #  if($first_shown>0 or (1+$last_shown)<scalar(@pg_files)) {
 1667 
 1668   #  }
 1669 
 1670 
 1671   return "";
 1672 }
 1673 
 1674 =head1 AUTHOR
 1675 
 1676 Written by John Jones, jj (at) asu.edu.
 1677 Edited by David Gage
 1678 
 1679 =cut
 1680 
 1681 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9