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

View of /branches/rel-2-4-dev/webwork2/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2015 - (download) (as text) (annotate)
Thu May 6 21:38:58 2004 UTC (9 years ago) by jj
Original Path: trunk/webwork2/lib/WeBWorK/ContentGenerator/Instructor/SetMaker.pm
File size: 24563 byte(s)
Commented out features which are not used yet in the problem library.
Uncommented Try it and Edit it links.

    1 ################################################################################
    2 # WeBWorK Online Homework Delivery System
    3 # Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
    4 # $CVSHeader:$
    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::SetMaker;
   19 use base qw(WeBWorK::ContentGenerator::Instructor);
   20 
   21 =head1 NAME
   22 
   23 WeBWorK::ContentGenerator::Instructor::SetMaker - Make problem sets.
   24 
   25 =cut
   26 
   27 use strict;
   28 use warnings;
   29 
   30 use CGI::Pretty qw();
   31 use WeBWorK::Form;
   32 use WeBWorK::Utils qw(readDirectory max);
   33 use WeBWorK::Utils::Tasks qw(renderProblems);
   34 
   35 require WeBWorK::Utils::ListingDB;
   36 
   37 
   38 use constant MAX_SHOW => 20;
   39 
   40 ## to make the recursion work, this returns an array where the first
   41 ## item is 1 or 0 depending on whether or not the current
   42 ## directory has any pg files.  The second is a list of directories
   43 ## which contain pg files.
   44 sub get_library_sets {
   45   my $topdir =  shift;
   46   my @lis = readDirectory($topdir);
   47   my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$topdir/$_"} @lis;
   48   my $havepg = scalar(@pgs)>0 ? 1 : 0;
   49   my @mdirs = grep {$_ ne "." and $_ ne ".." and $_ ne "Library"
   50           and -d "$topdir/$_"} @lis;
   51   my ($adir, @results, @thisresult);
   52   for $adir (@mdirs) {
   53     @results = get_library_sets("$topdir/$adir");
   54     my $isadirok = shift @results;
   55     @thisresult = (@thisresult, @results);
   56     if ($isadirok) {
   57       @thisresult = ("$topdir/$adir", @thisresult);
   58     }
   59   }
   60   return(($havepg, @thisresult));
   61 }
   62 
   63 ## List all the pg files in the requested directory
   64 sub list_pg_files {
   65   my $templatedir = shift;
   66   my $topdir = shift;
   67 
   68   my @lis = readDirectory("$templatedir/$topdir");
   69   my @pgs = grep { m/\.pg$/ and (not m/Header\.pg/) and -f "$templatedir/$topdir/$_"} @lis;
   70   @pgs = map { "$topdir/$_" } @pgs;
   71   return(@pgs);
   72 }
   73 
   74 ## Maybe I should use this instead, returns a list
   75 sub get_global_set_defs {
   76   my $db = shift;
   77 
   78   my @globalSetIDs = $db->listGlobalSets;
   79   return(@globalSetIDs);
   80 }
   81 
   82 ## go through past page getting a list of identifiers for the problems
   83 ## and whether or not they are selected, and whether or not they should
   84 ## be hidden
   85 
   86 sub get_past_problem_files {
   87   my $r = shift;
   88   my @found=();
   89   my $count =1;
   90   while (defined($r->param("filetrial$count"))) {
   91     push @found, [$r->param("filetrial$count"),
   92       defined($r->param("trial$count")) ? $r->param("trial$count"):0,
   93       defined($r->param("hideme$count")) ?$r->param("hideme$count"):0];
   94     $count++;
   95   }
   96   return(@found);
   97 }
   98 
   99 #### For adding new problems
  100 
  101 sub add_selected {
  102   my $self = shift;
  103   my $db = shift;
  104   my $setName = shift;
  105   my @selected = @_;
  106   my (@path, $file, $selected, $freeProblemID);
  107   $freeProblemID = max($db->listGlobalProblems($setName)) + 1;
  108 
  109   for $selected (@selected) {
  110     $file = $selected;
  111     @path = split "/", $selected;
  112     pop @path;      # Remove the file name from the path
  113     shift @path if $path[0] eq ""; # remove the null element from the begining
  114     my $problemRecord = $db->newGlobalProblem();
  115     $problemRecord->problem_id($freeProblemID++);
  116     $problemRecord->set_id($setName);
  117     $problemRecord->source_file($file);
  118     $problemRecord->value("1");
  119     $problemRecord->max_attempts("-1");
  120     $db->addGlobalProblem($problemRecord);
  121     $self->assignProblemToAllSetUsers($problemRecord);
  122   }
  123 }
  124 
  125 
  126 ############# List of library sets
  127 
  128 sub getalllibsets {
  129   my $ce = shift;
  130   my @all_library_sets = get_library_sets($ce->{courseDirs}->{templates});
  131   shift @all_library_sets;
  132   my $j;
  133   for ($j=0; $j<scalar(@all_library_sets); $j++) {
  134     $all_library_sets[$j] =~ s|^$ce->{courseDirs}->{templates}/?||;
  135   }
  136   @all_library_sets = sort @all_library_sets;
  137   return (\@all_library_sets);
  138 }
  139 
  140 ### The browsing panel has three versions
  141 #####  Version 1 is local problems
  142 sub browse_local_panel {
  143   my $self = shift;
  144   my $library_selected = shift;
  145 
  146   my $list_of_sets= getalllibsets($self->r->ce);
  147   my $libstr = "";
  148   my $default_value = "Select a Local Problem Collection";
  149   $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg});
  150 
  151   if (not $library_selected or $library_selected eq $default_value) {
  152     unshift @{$list_of_sets},  $default_value;
  153     $library_selected = $default_value;
  154   }
  155 
  156 
  157   print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Local Problems: ",
  158       CGI::popup_menu(-name=> 'library_sets',
  159           -values=>$list_of_sets,
  160           -default=> $library_selected),
  161       CGI::br(),
  162       CGI::submit(-name=>"view_local_set", -value=>"View Problems"),
  163       $libstr
  164            ));
  165 }
  166 
  167 #####  Version 2 is local problem sets
  168 sub browse_mysets_panel {
  169   my $self = shift;
  170   my $library_selected = shift;
  171   my $list_of_local_sets = shift;
  172   my $default_value = "Select a Problem Set";
  173 
  174   my $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg});
  175 
  176   if (not $library_selected or $library_selected eq $default_value) {
  177     unshift @{$list_of_local_sets},  $default_value;
  178     $library_selected = $default_value;
  179   }
  180 
  181   print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Browse from: ",
  182       CGI::popup_menu(-name=> 'library_sets',
  183           -values=>$list_of_local_sets,
  184           -default=> $library_selected),
  185       CGI::br(),
  186       CGI::submit(-name=>"view_mysets_set", -value=>"View This Set"),
  187       $libstr
  188            ));
  189 }
  190 
  191 #####  Version 3 is the problem library
  192 
  193 
  194 # There a different levels, and you can pick a new chapter,
  195 # pick a new section, pick all from chapter, pick all from section
  196 #
  197 # Incoming data - current chapter, current section
  198 sub browse_library_panel {
  199   my $self = shift;
  200   my $r = $self->r;
  201 
  202   my $libraryRoot = $r->{ce}->{webworkDirs}->{libraryRoot};
  203 
  204   unless($libraryRoot) {
  205     print CGI::Tr(CGI::td(CGI::div({class=>'ResultsWithError', align=>"center"},
  206         "The problem library has not been installed.")));
  207     return;
  208   }
  209 
  210   my $default_chap = "All Chapters";
  211   my $default_sect = "All Sections";
  212 
  213   my $libstr = CGI::br() . CGI::em($self->{libmsg}) if($self->{libmsg});
  214 
  215   my @chaps = WeBWorK::Utils::ListingDB::getAllChapters($r->{ce});
  216   unshift @chaps, $default_chap;
  217   my $chapter_selected = $r->param('library_chapters') || $default_chap;
  218 
  219   my @sects=();
  220   if ($chapter_selected ne $default_chap) {
  221     @sects = WeBWorK::Utils::ListingDB::getAllSections($r->{ce}, $chapter_selected);
  222   }
  223 
  224   my @textbooks = ('Textbook info not ready');
  225 
  226   unshift @sects, $default_sect;
  227   my $section_selected =  $r->param('library_sections') || $default_sect;
  228 
  229   print CGI::Tr(CGI::td({-class=>"InfoPanel"},
  230       CGI::start_table(),
  231                         CGI::Tr(
  232         CGI::td(["Chapter:",
  233            CGI::popup_menu(-name=> 'library_chapters',
  234                -values=>\@chaps,
  235                -default=> $chapter_selected,
  236                -onchange=>"submit();return true"
  237               ),
  238            CGI::submit(-name=>"lib_select_chapter", -value=>"Update Section List")])),
  239       CGI::Tr(
  240         CGI::td("Section:"),
  241         CGI::td({-colspan=>2},
  242           CGI::popup_menu(-name=> 'library_sections',
  243               -values=>\@sects,
  244               -default=> $section_selected
  245                    ))),
  246 
  247 #       CGI::Tr(
  248 #         CGI::td("Textbook:"),
  249 #         CGI::td({-colspan=>2},
  250 #           CGI::popup_menu(-name=> 'library_textbooks',
  251 #               -values=>\@textbooks,
  252 #               #            -default=> $section_selected
  253 #                    ))),
  254 
  255 #       CGI::Tr(
  256 #         CGI::td("Keywords:"),
  257 #                                 CGI::td({-colspan=>2}, CGI::textfield(-name=>"keywords",
  258 #                       -default=>"Keywords not implemented yet",
  259 #                       -override=>1, -size=>60))),
  260       CGI::Tr(CGI::td({-colspan=>3},CGI::submit(-name=>"lib_view", -value=>"View Problems"))),
  261       CGI::end_table(),
  262       $libstr
  263            ));
  264 }
  265 
  266 sub make_top_row {
  267   my $self = shift;
  268   my $r = $self->r;
  269   my %data = @_;
  270 
  271   my $list_of_local_sets = $data{all_set_defs};
  272   my $browse_which = $data{browse_which};
  273   my $library_selected = $r->param('library_sets');
  274   my $set_selected = $r->param('local_sets');
  275 
  276   my $list_of_sets;
  277   my ($dis1, $dis2, $dis3) = ("","","");
  278   $dis1 =  '-disabled' if($browse_which eq 'browse_library');
  279   $dis2 =  '-disabled' if($browse_which eq 'browse_local');
  280   $dis3 =  '-disabled' if($browse_which eq 'browse_mysets');
  281 
  282   my $locstr = "";
  283   $locstr = CGI::br() . CGI::em($self->{localmsg}) if($self->{localmsg});
  284 
  285   my $these_widths = "width: 27ex";
  286   print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"center"},
  287       CGI::submit(-name=>"browse_library", -value=>"Browse Problem Library", -style=>$these_widths, $dis1),
  288       CGI::submit(-name=>"browse_local", -value=>"Browse Local Problems", -style=>$these_widths, $dis2),
  289       CGI::submit(-name=>"browse_mysets", -value=>"Browse From This Course", -style=>$these_widths, $dis3),
  290            ));
  291 
  292   print CGI::Tr(CGI::td({-bgcolor=>"black"}));
  293 
  294   if ($browse_which eq 'browse_local') {
  295     browse_local_panel($self, $library_selected);
  296   } elsif ($browse_which eq 'browse_mysets') {
  297     browse_mysets_panel($self, $library_selected, $list_of_local_sets);
  298   } else {
  299     browse_library_panel($self);
  300   }
  301 
  302   print CGI::Tr(CGI::td({-bgcolor=>"black"}));
  303 
  304   if (not $set_selected or $set_selected eq "Select a Set for This Course") {
  305     if ($list_of_local_sets->[0] eq "Select a Problem Set") {
  306       shift @{$list_of_local_sets};
  307     }
  308     unshift @{$list_of_local_sets}, "Select a Set for This Course";
  309     $set_selected = "Select a Set for This Course";
  310   }
  311 
  312   print CGI::Tr(CGI::td({-class=>"InfoPanel"}, "Current Set: ",
  313       CGI::popup_menu(-name=> 'local_sets',
  314           -values=>$list_of_local_sets,
  315           -default=> $set_selected),
  316       CGI::submit(-name=>"edit_local", -value=>"Edit Current Set"),
  317       CGI::br(),
  318       CGI::br(),
  319       CGI::submit(-name=>"new_local_set", -value=>"Create New Local Set:"),
  320       "  ",
  321       CGI::textfield(-name=>"new_set_name",
  322                -default=>"Name for new set here",
  323                -override=>1, -size=>30),
  324       CGI::br(),
  325       $locstr
  326            ));
  327 
  328   print CGI::Tr(CGI::td({-bgcolor=>"black"}));
  329 
  330   print CGI::Tr(CGI::td({-class=>"InfoPanel", -align=>"center"},
  331       CGI::submit(-name=>"update", -style=>$these_widths,
  332             -value=>"Act on Marked Problems"),
  333       CGI::submit(-name=>"rerandomize",
  334             -style=>$these_widths,
  335             -value=>"Rerandomize"),
  336       CGI::submit(-name=>"cleardisplay",
  337             -style=>$these_widths,
  338             -value=>"Clear Problem Display")));
  339 
  340 }
  341 
  342 sub make_data_row {
  343   my $self = shift;
  344   my $sourceFileName = shift;
  345   my $pg = shift;
  346   my $cnt = shift;
  347 
  348   my $urlpath = $self->r->urlpath;
  349   my $problem_output = $pg->{flags}->{error_flag} ?
  350     CGI::em("This problem produced an error")
  351     : CGI::div({class=>"RenderSolo"}, $pg->{body_text});
  352 
  353 
  354   my $edit_link =  CGI::a({href=>$self->systemLink(
  355                $urlpath->new(type=>'instructor_problem_editor_withset_withproblem',
  356                  args=>{courseID =>$urlpath->arg("courseID"),
  357                   setID=>"Undefined_Set", problemID=>"1" }
  358                 ), params=>{sourceFilePath => "$sourceFileName"}
  359               )}, "Edit it" );
  360 
  361   my $try_link = CGI::a({href=>$self->systemLink( $urlpath->new(type=>'problem_detail',
  362                 args=>{courseID =>$urlpath->arg("courseID"),
  363                        setID=>"Undefined_Set", problemID=>"1"}
  364                      ),
  365               params =>{effectiveUser => $self->r->param('user'),
  366                   editMode => "temporaryFile",
  367                   sourceFilePath => "$sourceFileName"}  )}, "Try it");
  368 
  369 
  370 
  371   print CGI::Tr({-align=>"left"}, CGI::td(
  372 
  373             CGI::div({-style=>"background-color: #DDDDDD"},"File name: $sourceFileName ",
  374                $edit_link, " ", $try_link
  375               ),
  376 
  377 
  378 
  379 
  380             CGI::checkbox(-name=>"hideme$cnt",-value=>1,-label=>"Don't show me on the next update"),
  381             CGI::br(),
  382             CGI::checkbox(-name=>"trial$cnt",-value=>1,-label=>"Add me to the current set on the next update"),
  383             CGI::hidden(-name=>"filetrial$cnt", -default=>[$sourceFileName]).
  384             CGI::p($problem_output),
  385            ));
  386 }
  387 
  388 sub title {
  389   return "Problem Set Maker";
  390 }
  391 
  392 sub body {
  393   my ($self) = @_;
  394 
  395   my $r = $self->r;
  396   my $ce = $r->ce;    # course environment
  397   my $db = $r->db;    # database
  398   my $j;      # garden variety counter
  399 
  400   my $userName = $r->param('user');
  401 
  402   my $user = $db->getUser($userName); # checked
  403   die "record for user $userName (real user) does not exist."
  404     unless defined $user;
  405 
  406   ### Check that this is a professor
  407   my $authz = $r->authz;
  408   unless ($authz->hasPermissions($userName, "modify_problem_sets")) {
  409     print "User $userName returned " .
  410       $authz->hasPermissions($user, "modify_problem_sets") .
  411   " for permission";
  412     return(CGI::em("You are not authorized to access the Instructor tools."));
  413   }
  414 
  415 
  416   ############# List of problems we have already printed
  417 
  418   my @past_problems = get_past_problem_files($r);
  419   my (@pg_files, @pg_html);
  420   my $use_previous_problems = 1;
  421   my $first_shown = $r->param('first_shown') || 0;
  422   my $last_shown = $r->param('last_shown');
  423   if (not defined($last_shown)) {
  424     $last_shown = -1;
  425   }
  426   my @all_past_list = (); # these are include requested, but not shown
  427   $j = 0;
  428   while (defined($r->param("all_past_list$j"))) {
  429     push @all_past_list, $r->param("all_past_list$j");
  430     $j++;
  431   }
  432 
  433   ############# Default of which problem selector to display
  434 
  435   my $browse_which = 'browse_local';
  436   $browse_which = $r->param('browse_which') if defined($r->param('browse_which'));
  437 
  438   my $problem_seed = $r->param('problem_seed') || 0;
  439   $r->param('problem_seed', $problem_seed); # if it wasn't defined before
  440 
  441   ########### Start the logic through if elsif elsif ...
  442 
  443   ##### Asked to browse certain problems
  444   if ($r->param('browse_library')) {
  445     $browse_which = 'browse_library';
  446     $r->param('library_sets', "");
  447   } elsif ($r->param('browse_local')) {
  448     $browse_which = 'browse_local';
  449     $r->param('library_sets', "");
  450   } elsif ($r->param('browse_mysets')) {
  451     $browse_which = 'browse_mysets';
  452     $r->param('library_sets', "");
  453 
  454     ##### Change the seed value
  455 
  456   } elsif ($r->param('rerandomize')) {
  457     $problem_seed++;
  458     $r->param('problem_seed', $problem_seed);
  459 
  460     ##### Clear the display
  461 
  462   } elsif ($r->param('cleardisplay')) {
  463     @pg_files = ();
  464     $use_previous_problems=0;
  465 
  466     ##### View problems selected from the local list
  467 
  468   } elsif ($r->param('view_local_set')) {
  469 
  470     my $set_to_display = $r->param('library_sets');
  471     if (not defined($set_to_display) or $set_to_display eq "Select a Local Problem Collection") {
  472       $self->{libmsg} = "You need to select a set to view.";
  473     } else {
  474       @pg_files = list_pg_files($ce->{courseDirs}->{templates},
  475         "$set_to_display");
  476       $use_previous_problems=0;
  477     }
  478 
  479     ##### View problems selected from the a set in this course
  480 
  481   } elsif ($r->param('view_mysets_set')) {
  482 
  483     my $set_to_display = $r->param('library_sets');
  484     if (not defined($set_to_display) or $set_to_display eq "Select a Problem Set") {
  485       $self->{libmsg} = "You need to select a set from this course to view.";
  486     } else {
  487       my @problemList = $db->listGlobalProblems($set_to_display);
  488       my $problem;
  489       @pg_files=();
  490       for $problem (@problemList) {
  491   my $problemRecord = $db->getGlobalProblem($set_to_display, $problem); # checked
  492   die "global $problem for set $set_to_display not found." unless
  493     $problemRecord;
  494   push @pg_files, $problemRecord->source_file;
  495 
  496       }
  497       $use_previous_problems=0;
  498     }
  499 
  500     ##### View whole chapter from the library
  501     ## This will change somewhat later
  502 
  503   } elsif ($r->param('lib_view')) {
  504 
  505     @pg_files=();
  506     my $chap = $r->param('library_chapters') || "";
  507     $chap = "" if($chap eq "All Chapters");
  508     my $sect = $r->param('library_sections') || "";
  509     $sect = "" if($sect eq "All Sections");
  510     my @dbsearch = WeBWorK::Utils::ListingDB::getSectionListings($r->{ce}, "$chap", "$sect");
  511     my ($result, $tolibpath);
  512     for $result (@dbsearch) {
  513       $tolibpath = "Library/$result->{path}/$result->{filename}";
  514 
  515       ## Too clunky!!!!
  516       push @pg_files, $tolibpath;
  517     }
  518     $use_previous_problems=0;
  519 
  520     ##### Edit the current local problem set
  521 
  522   } elsif ($r->param('edit_local')) { ## Jump to set edit page
  523     # This is handled in pre_header_initialize -- it redirects
  524     # If there is an error, so no redirect, we want to be ready
  525     # and do something here
  526 
  527     ##### Make a new local problem set
  528 
  529   } elsif ($r->param('new_local_set')) {
  530     if ($r->param('new_set_name') !~ /^[\w.-]*$/) {
  531       $self->{localmsg} = "The name ".$r->param('new_set_name')." is not a valid set name.  Use only letters, digits, -, _, and .";
  532     } else {
  533       my $newSetName = $r->param('new_set_name');
  534       $newSetName =~ s/^set//;
  535       $newSetName =~ s/\.def$//;
  536       my $newSetRecord   = $db->getGlobalSet($newSetName);
  537       if (defined($newSetRecord)) {
  538   $self->{localmsg} = "The set name $newSetName is already in use.  Pick a different name if you would like to start a new set.";
  539       } else {      # Do it!
  540   $newSetRecord = $db->{set}->{record}->new();
  541   $newSetRecord->set_id($newSetName);
  542   $newSetRecord->set_header("");
  543   $newSetRecord->problem_header("");
  544   $newSetRecord->open_date(time()+60*60*24*7); # in one week
  545   $newSetRecord->due_date(time()+60*60*24*7*2); # in two weeks
  546   $newSetRecord->answer_date(time()+60*60*24*7*3); # in three weeks
  547   eval {$db->addGlobalSet($newSetRecord)};
  548       }
  549     }
  550 
  551     ##### Add selected problems to the current local set
  552 
  553   } elsif ($r->param('update')) {
  554     ## first handle problems to be added before we hide them
  555     my($localSet, @selected);
  556 
  557     @pg_files = grep {$_->[1] != 0 } @past_problems;
  558     @selected = map {$_->[0]} @pg_files;
  559 
  560     if (scalar(@selected)>0) {  # if some are to be added, they need a place to go
  561       $localSet = $r->param('local_sets');
  562       if (not defined($localSet)) {
  563   $self->{localmsg} = "Trying to add problems to something, you did not select a current set name as a target.";
  564       } else {
  565   my $newSetRecord   = $db->getGlobalSet($localSet);
  566   if (not defined($newSetRecord)) {
  567     $self->{localmsg} = "You need to select a local problem set to add the problems to.";
  568   } else {
  569     add_selected($self, $db, $localSet, @selected);
  570   }
  571       }
  572     }
  573     ## now handle problems to be hidden
  574 
  575     @pg_files = grep {$_->[2]==0 } @past_problems;
  576     @pg_files = map {$_->[0]} @pg_files;
  577     @all_past_list = (@all_past_list[0..($first_shown-1)],
  578           @pg_files,
  579           @all_past_list[($last_shown+1)..(scalar(@all_past_list)-1)]);
  580     $last_shown = $first_shown+MAX_SHOW -1;
  581     $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list));
  582 
  583     ## FIXME: you should say something if no problems are selected
  584     ##        maybe the add button should be disabled if there are no problems
  585     ##        showing
  586 
  587 
  588   } elsif ($r->param('next_page')) {
  589     $first_shown = $last_shown+1;
  590     $last_shown = $first_shown+MAX_SHOW-1;
  591     $last_shown = (scalar(@all_past_list)-1) if($last_shown>=scalar(@all_past_list));
  592   } elsif ($r->param('prev_page')) {
  593     $last_shown = $first_shown-1;
  594     $first_shown = $last_shown - MAX_SHOW+1;
  595 
  596     $first_shown = 0 if($first_shown<0);
  597 
  598     ##### No action requested, probably our first time here
  599 
  600   } else {
  601     #my $c = $r->connection;
  602     #print "Debug info: ". $r->get_remote_host ."<p>".  $c->remote_ip ;
  603     ;
  604   }       ##### end of the if elsif ...
  605 
  606 
  607   ############# List of local sets
  608 
  609   my @all_set_defs = get_global_set_defs($db);
  610   for ($j=0; $j<scalar(@all_set_defs); $j++) {
  611     $all_set_defs[$j] =~ s|^set||;
  612     $all_set_defs[$j] =~ s|\.def||;
  613   }
  614 
  615   if ($use_previous_problems) {
  616     @pg_files = @all_past_list;
  617   } else {
  618     $first_shown = 0;
  619     $last_shown = scalar(@pg_files)<MAX_SHOW ? scalar(@pg_files) : MAX_SHOW;
  620     $last_shown--;    # to make it an array index
  621   }
  622 
  623   @pg_html=($last_shown>=$first_shown) ?
  624     renderProblems($r,$user, @pg_files[$first_shown..$last_shown]) : ();
  625 
  626   ##########  Top part
  627   print CGI::startform({-method=>"POST", -action=>$r->uri}),
  628     $self->hidden_authen_fields,
  629       '<div align="center">',
  630   CGI::start_table({-border=>2});
  631   make_top_row($self, 'all_set_defs'=>\@all_set_defs,
  632          'browse_which'=> $browse_which);
  633   print CGI::hidden(-name=>'browse_which', -default=>[$browse_which]),
  634     CGI::hidden(-name=>'problem_seed', -default=>[$problem_seed]);
  635   for ($j = 0 ; $j < scalar(@pg_files) ; $j++) {
  636     print CGI::hidden(-name=>"all_past_list$j", -default=>$pg_files[$j]);
  637   }
  638 
  639   print CGI::hidden(-name=>'first_shown', -default=>[$first_shown]);
  640   print CGI::hidden(-name=>'last_shown', -default=>[$last_shown]);
  641 
  642 
  643   ########## Now print problems
  644   my $jj;
  645   for ($jj=0; $jj<scalar(@pg_html); $jj++) {
  646     $pg_files[$jj] =~ s|^$ce->{courseDirs}->{templates}/?||;
  647     make_data_row($self, $pg_files[$jj+$first_shown], $pg_html[$jj], $jj+1);
  648   }
  649 
  650   ########## Finish things off
  651   print CGI::end_table();
  652   print '</div>';
  653   #  if($first_shown>0 or (1+$last_shown)<scalar(@pg_files)) {
  654   my ($next_button, $prev_button) = ("", "");
  655   if ($first_shown > 0) {
  656     $prev_button = CGI::submit(-name=>"prev_page", -style=>"width:15ex",
  657              -value=>"Previous page");
  658   }
  659   if ((1+$last_shown)<scalar(@pg_files)) {
  660     $next_button = CGI::submit(-name=>"next_page", -style=>"width:15ex",
  661              -value=>"Next page");
  662   }
  663   if (scalar(@pg_files)>0) {
  664     print CGI::p(($first_shown+1)."-".($last_shown+1)." of ".scalar(@pg_files).
  665      " shown.", $prev_button, " ", $next_button);
  666   }
  667   #  }
  668   print CGI::endform(), "\n";
  669 
  670   return "";
  671 }
  672 
  673 ############################################## End of Body
  674 
  675 sub pre_header_initialize {
  676   my ($self) = @_;
  677   my $r = $self->r;
  678   ## For all cases, lets set some things
  679   $self->{error}=0;
  680   $self->{libmsg}="";
  681   $self->{localmsg}="";
  682 
  683 
  684   ### Maybe FIXME: this needs to check permissions before doing anything
  685 
  686   ## Now one action we have to deal with here
  687   if ($r->param('edit_local')) {
  688     my $urlpath = $r->urlpath;
  689     my $db = $r->db;
  690     my $checkset = $db->getGlobalSet($r->param('local_sets'));
  691     if (not defined($checkset)) {
  692       $self->{error} = 1;
  693       $self->{localmsg} = "You need to select a local set before you can edit it.";
  694       return();
  695     }
  696     my $page = $urlpath->newFromModule('WeBWorK::ContentGenerator::Instructor::ProblemSetEditor', setID=>$r->param('local_sets'), courseID=>$urlpath->arg("courseID"));
  697     my $url = $self->systemLink($page);
  698     $self->reply_with_redirect($url);
  699   }
  700 }
  701 
  702 
  703 # SKEL: To emit your own HTTP header, uncomment this:
  704 #
  705 #sub header {
  706 # my ($self) = @_;
  707 #
  708 # # Generate your HTTP header here.
  709 #
  710 # # If you return something, it will be used as the HTTP status code for this
  711 # # request. The Apache::Constants module might be useful for gerating status
  712 # # codes. If you don't return anything, the status code "OK" will be used.
  713 # return "";
  714 #}
  715 
  716 # SKEL: If you need to do any processing after the HTTP header is sent, but before
  717 # any template processing occurs, or you need to calculate values that will be
  718 # used in multiple methods, do it in this method:
  719 #
  720 #sub initialize {
  721 #my ($self) = @_;
  722 #}
  723 
  724 # SKEL: If you need to add tags to the document <HEAD>, uncomment this method:
  725 #
  726 #sub head {
  727 # my ($self) = @_;
  728 #
  729 # # You can print head tags here, like <META>, <SCRIPT>, etc.
  730 #
  731 # return "";
  732 #}
  733 
  734 # SKEL: To fill in the "info" box (to the right of the main body), use this
  735 # method:
  736 #
  737 #sub info {
  738 # my ($self) = @_;
  739 #
  740 # # Print HTML here.
  741 #
  742 # return "";
  743 #}
  744 
  745 # SKEL: To provide navigation links, use this method:
  746 #
  747 #sub nav {
  748 # my ($self, $args) = @_;
  749 #
  750 # # See the documentation of path() and pathMacro() in
  751 # # WeBWorK::ContentGenerator for more information.
  752 #
  753 # return "";
  754 #}
  755 
  756 # SKEL: For a little box for display options, etc., use this method:
  757 #
  758 #sub options {
  759 # my ($self) = @_;
  760 #
  761 # # Print HTML here.
  762 #
  763 # return "";
  764 #}
  765 
  766 # SKEL: For a list of sibling objects, use this method:
  767 #
  768 #sub siblings {
  769 # my ($self, $args) = @_;
  770 #
  771 # # See the documentation of siblings() and siblingsMacro() in
  772 # # WeBWorK::ContentGenerator for more information.
  773 # #
  774 # # Refer to implementations in ProblemSet and Problem.
  775 #
  776 # return "";
  777 #}
  778 
  779 =head1 AUTHOR
  780 
  781 Written by John Jones, jj (at) asu.edu.
  782 
  783 =cut
  784 
  785 
  786 
  787 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9