[system] / trunk / webwork-modperl / lib / WeBWorK / ContentGenerator / Instructor / ProblemSetEditor.pm Repository:
ViewVC logotype

View of /trunk/webwork-modperl/lib/WeBWorK/ContentGenerator/Instructor/ProblemSetEditor.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 875 - (download) (as text) (annotate)
Wed May 21 18:41:51 2003 UTC (10 years ago) by gage
File size: 10980 byte(s)
Factored some code  into gatherInfo() method.
The three dates are now sticky
a problem address of the form  /prob1.pg  won't enter into the set def textarea
This solves the problem that the directory might not yet be defined (but not elegantly).
-- Mike

    1 package WeBWorK::ContentGenerator::Instructor::ProblemSetEditor;
    2 use base qw(WeBWorK::ContentGenerator::Instructor);
    3 
    4 =head1 NAME
    5 
    6 WeBWorK::ContentGenerator::Instructor::ProblemSetEditor - Edit a set definition list
    7 
    8 =cut
    9 
   10 use strict;
   11 use warnings;
   12 use CGI qw();
   13 
   14 
   15 our $rowheight = 20;  #controls the length of the popup menus.
   16 our $libraryName;  #library directory name
   17 sub title {
   18   my $self = shift;
   19   return "Instructor Tools - Problem Set Editor for ".$self->{ce}->{courseName};
   20 }
   21 
   22 sub body {
   23   my $self = shift;
   24 
   25   # test area
   26   my $r = $self->{r};
   27   my $db = $self->{db};
   28 
   29   my $user = $r->param('user');
   30   my $key = $db->getKey($user)->key();
   31 
   32 
   33   ################
   34   # Gathering info
   35   # What is needed
   36   #     $setName  -- formerly the name of the set definition file
   37   #     $formURL -- the action URL for the form
   38   #     $libraryName  -- the name of the available library
   39   #     $setDirectory  -- the current library directory
   40   #     $oldSetDirectory -- the previous library directory
   41   #     $problemName    -- the name of the library problem (in the previous library directory)
   42   #     $problemList    -- the contents of the textarea form
   43   #     answer dates
   44   my ($setName,$formURL,
   45     $libraryName,$setDirectory,$oldSetDirectory,
   46     $problemName,$problemList,
   47     $openDate,$dueDate,$answerDate) = $self->gatherInfo();
   48 
   49   #########################################################################
   50   # Determine a name for this set
   51   #########################################################################
   52   # Determine the set number, if there is one. Otherwise make setName = "new set".
   53   # fix me
   54 # my ($path_info,@components) = $self->gatherInfo();
   55 # my $setName = $components[0];  # get GET  address for set name
   56 
   57   # Override the setName if it is defined in a form.
   58 # $setName = $r->param('setName') if defined($r->param('setName'));
   59 
   60 
   61   #########################################################################
   62   # determine the library set directory
   63   #########################################################################
   64 #   $libraryName = $self->{ce}->{courseDirs}->{templates};
   65 #   my $setDirectory = $r->param('setDirectory');
   66 # my $oldSetDirectory = $r->param('oldSetDirectory');
   67 
   68   #fix me
   69   # A user can select a new set AND a problem (in the old set) but the problem won't be in the new set!
   70   # In other words we must prevent the user from changing the problem and the set simultaneously.
   71   # We solve this by defining a hidden variable oldSetDirectory which matches the currently displayed problem list
   72   # the problem entry for the textarea element and the viewProblem url are
   73   # formed using this old version of setDefinition
   74 
   75 
   76 
   77   # Determine  values for strings
   78   #########################################################################
   79   #text area region, adding problems to the list
   80   #########################################################################
   81 
   82   my $textAreaString;
   83   #fix me  -- this does not handle multiple problem selections correctly.
   84 #   my $problemName = $r->param('pgProblem');
   85 #   my $problemList = $r->param('problemList');
   86 
   87   # Initialize the textarea string if it is empty or hasn't been defined.
   88   $problemList = "# List problems to be included in the set here???\r\n\r\n" unless defined($problemList) and $problemList =~/\S/;
   89   my $problemEntry = $oldSetDirectory.'/'.$problemName.", 1, -1 \r\n";
   90   # add the new problem entry if the address is complete. (still buggy -- how do insure that oldSetDirectory is not empty?
   91   $problemList .= $problemEntry unless $problemEntry =~ m|^/|;  # don't print if oldSetDirectory name is empy (fix me -- more checks are needed?)
   92   # format the complete textArea string
   93   $textAreaString = qq!<textarea name="problemList", cols="40", rows="$rowheight">$problemList</textarea>!;
   94 
   95 
   96   #Determine the headline for the page
   97 
   98 
   99   #fix me   Debugging code
  100 #   my $header = "Choose problems from $libraryName directory" .
  101 #     "<p>This form is not yet operational.
  102 #     <p>SetDirectory is $setDirectory.
  103 #     <p>formURL is $formURL
  104 #     <p>path_info  is $path_info";
  105   my $header = '';
  106 
  107 
  108   #########################################################################
  109   # Define the popup strings used for selecting the library set directory, and the problem from that directory
  110   #fix me
  111   # he problem of multiple selections needs to be handled properly.
  112   #########################################################################
  113   my $popUpSetDirectoryString = $self->fetchSetDirectories($setDirectory);  #pass default choice as current directory
  114   my $popUpPGProblemString = $self->fetchPGproblems($setDirectory);
  115 
  116 
  117   #########################################################################
  118   # Define a link to view the problem
  119   #fix me:
  120   # Currently this link used the webwork problem library, which might be out of
  121   # sync with the local library
  122   #########################################################################
  123 
  124 
  125   my $viewProblemLink;
  126   if ( (defined($oldSetDirectory) and defined($problemName)) ) {
  127     $viewProblemLink = qq!View : <a href=! .
  128              qq!"http://webhost.math.rochester.edu/webworkdocs/ww/pgView/$oldSetDirectory/$problemName"! .
  129              qq! target = "_probwindow">! .
  130              qq!$oldSetDirectory/$problemName</a>!;
  131   } else {
  132     $viewProblemLink = '';
  133 
  134   }
  135   #########################################################################
  136   # Format the page
  137   #########################################################################
  138 
  139   return CGI::p($header),
  140     #CGI::start_form(-action=>"/webwork/mth143/instructor/problemSetEditor/"),
  141     CGI::start_form(-action=>$formURL),
  142     CGI::table( {-border=>2},
  143       CGI::Tr({-align=>'CENTER',-valign=>'TOP'},
  144         CGI::th('Editing set : '),
  145         CGI::td(CGI::textfield(  -name=>'setName',-size=>'20',-value=>$setName,-override=>1)),
  146         CGI::td(CGI::submit(-name=>'submitButton',-value=>'Save'))
  147       ),
  148       CGI::Tr({-align=>'CENTER',-valign=>'TOP'},
  149         CGI::td($textAreaString),
  150         CGI::td($popUpSetDirectoryString),
  151         CGI::td($popUpPGProblemString)
  152 
  153             ),
  154              #(defined($viewProblemLink)) ?
  155              #  qq!<tr align="CENTER" valign="TOP"><th colspan="3">$viewProblemLink</th></tr>!
  156              #  : '',
  157             CGI::Tr( {-align=>'CENTER',-valign=>'TOP'},
  158               CGI::th([ $viewProblemLink,
  159                     CGI::submit(-name=>'submitButton'  , -value =>'Select set'),
  160                     CGI::submit(-name=>'submitButton'  , -value =>'Choose problem')
  161                   ])
  162             ),
  163 
  164             CGI::Tr({-align=>'CENTER',-valign=>'TOP'},
  165               CGI::th(["Open date","Due date", "Answer date"]),
  166 
  167             ),
  168 
  169             CGI::Tr({-align=>'CENTER',-valign=>'TOP'},
  170           CGI::td(CGI::textfield(-name=>'open_date', -size=>'20', -value=>$openDate) ),
  171               CGI::td(CGI::textfield(-name=>'due_date', -size=>'20',  -value=>$dueDate) ),
  172               CGI::td(CGI::textfield(-name=>'answer_date', -size=>'20',-value=>$answerDate) ),
  173             ),
  174             qq!<tr align="center" valign="top"><td colspan="3">View entire set (pdf format) -- not yet implemented</td></tr>!,
  175         ),
  176         CGI::hidden(-name=>'user', -value=>$user),
  177         CGI::hidden(-name=>'key',-value=>$key),
  178         CGI::hidden(-name=>'oldSetDirectory', -value=>$setDirectory),
  179 
  180     CGI::end_form(),
  181     "<p> the parameters passed are "  #fix me -- debugging code
  182     . join("<BR>", %{$r->param()})
  183   ;
  184 
  185 }
  186 
  187 sub gatherInfo {
  188   #fix me.  This is very much hacked together.  In particular can we pass the key inside the post?
  189   my $self      = shift;
  190   my $ce        =   $self->{ce};
  191   my $r       = $self->{r};
  192   my $path_info     = $r->path_info || "";
  193 
  194   ## Determine the set name
  195   my $remaining_path  = $path_info;
  196   $remaining_path =~ s/^.*problemSetEditor//;
  197   my($junk, $setName, @components) = split "/", $remaining_path;
  198   # Override the setName if it is defined in a form.
  199   $setName = $r->param('setName') if defined($r->param('setName'));
  200 
  201   # Find the URL for the form
  202   $path_info =~s|problemSetEditor.*$|problemSetEditor/|;   # remove the setName, if any, from the path
  203   my $formURL = "/webwork$path_info";   # . $setName$self->url_authen_args();
  204 
  205   #########################################################################
  206   # determine the library name and set directory
  207   #########################################################################
  208   $libraryName = $ce->{courseDirs}->{templates};
  209   my $setDirectory = $r->param('setDirectory');
  210   my $oldSetDirectory = $r->param('oldSetDirectory');
  211 
  212   # Determine the problem name
  213   #fix me  -- this does not handle multiple problem selections correctly.
  214   my $problemName = $r->param('pgProblem');
  215   # Determine the text area string (contents of set definition "file")
  216   my $problemList = $r->param('problemList');
  217 
  218   # get answer dates
  219 
  220   my $openDate  = $r->param('open_date');
  221   $openDate   = "" unless defined($openDate);
  222   my $dueDate   = $r->param('due_date');
  223   $dueDate    = "" unless defined($dueDate);
  224   my $answerDate  = $r->param('answer_date');
  225   $answerDate   = "" unless defined($answerDate);
  226 
  227   ($setName,$formURL,$libraryName,$setDirectory,$oldSetDirectory,$problemName,$problemList,$openDate,$dueDate,$answerDate);
  228 }
  229 sub fetchSetDirectories {
  230 
  231   my $self = shift;
  232   my $defaultChoice = shift;
  233   my $templateDirectory = $self->{ce}->{courseDirs}->{templates};
  234   opendir SETDEFDIR, $templateDirectory
  235     or return "Can't open directory $templateDirectory";
  236 
  237   my @allFiles = grep !/^\./, readdir SETDEFDIR;
  238   closedir  SETDEFDIR;
  239 
  240   ## filter to find only the set directories
  241   ## -- it is assumed that these directories don't contain a period in their names
  242   ## and that all other files do.  Directories names must also begin with "set".
  243   ## A better plan would be to read only the names of directories, not files.
  244 
  245   ## sort the directories
  246   my @setDefFiles = grep /^set[^\.]*$/, @allFiles;
  247   my @sortedNames = sort @setDefFiles;
  248 
  249   return "$libraryName/" . CGI::br(). CGI::popup_menu(-name=>'setDirectory', -size=>$rowheight,
  250    -values=>\@sortedNames, -default=>$defaultChoice ) .CGI::br() ;
  251 }
  252 
  253 sub fetchPGproblems {
  254 
  255   my $self = shift;
  256   my $setDirectory = shift;
  257 
  258   # Handle default for setDirectory
  259   # fix me -- this is not bullet proof
  260   $setDirectory = "set0" unless defined($setDirectory);
  261   my $templateDirectory = $self->{ce}->{courseDirs}->{templates};
  262 
  263   ##
  264   opendir SETDEFDIR, "$templateDirectory/$setDirectory"
  265     or return "Can't open directory $templateDirectory/$setDirectory";
  266 
  267   my @allFiles = grep !/^\./, readdir SETDEFDIR;
  268   closedir  SETDEFDIR;
  269 
  270   ## filter to find only pg problems
  271   ## Some problems are themselves in directories (if they have auxiliary
  272   ## .png's for example.  This eventuallity needs to be handled.
  273 
  274   ## sort the directories
  275   my @pgFiles = grep /\.pg$/, @allFiles;
  276   my @sortedNames = sort @pgFiles;
  277 
  278   return "$setDirectory ". CGI::br() .
  279   CGI::popup_menu(-name=>'pgProblem', -size=>$rowheight, -multiple=>undef, -values=>\@sortedNames,  ) .
  280   CGI::br() ;
  281 }
  282 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9