[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator / Instructor / PGProblemEditor.pm Repository:
ViewVC logotype

View of /trunk/webwork2/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 902 - (download) (as text) (annotate)
Fri May 23 21:10:57 2003 UTC (10 years ago) by gage
File size: 7895 byte(s)
The problem editor will now edit existing problems in place.  You invoke it with

http://webwork3.math.rochester.edu:1102/webwork/mth143/instructor/pgProblemEditor/0/2/
and it will edit problem 2 in set 0.

It can't edit files directly or create new files.

The problems are CHANGED!!! there is no editing in a temporary file-- the problems
are changed at every step.  BEWARE

--Mike

    1 package WeBWorK::ContentGenerator::Instructor::PGProblemEditor;
    2 use base qw(WeBWorK::ContentGenerator::Instructor);
    3 
    4 
    5 =head1 NAME
    6 
    7 WeBWorK::ContentGenerator::Instructor::ProblemSetEditor - Edit a set definition list
    8 
    9 =cut
   10 
   11 use strict;
   12 use warnings;
   13 use CGI qw();
   14 use WeBWorK::Utils qw(readFile);
   15 
   16 our $libraryName;
   17 our $rowheight;
   18 
   19 sub title {
   20   my $self = shift;
   21   #FIXME  don't need the entire path  ??
   22   return "Instructor Tools - PG Problem Editor for ". $self->{ce}->{problemPath};
   23 }
   24 
   25 sub body {
   26   my $self = shift;
   27 
   28   # test area
   29   my $r     =   $self->{r};
   30   my $db    =   $self->{db};
   31   my $ce    = $self->{ce};
   32   my $user  =   $r->param('user');
   33   my $key   =   $db->getKey($user)->key();
   34 
   35 
   36   ################
   37   # Gathering info
   38   # What is needed
   39   #     $problemPath  --
   40   #     $formURL -- given by $r->uri
   41   #     $tmpProblemPath
   42   #my ($problemPath,$formURL,$tmpProblemPath) = $self->initialize();
   43   my $problemPath   =   $ce->{problemPath};
   44 
   45   my $tmpProblemPath  = $ce->{tmpProblemPath};
   46 
   47 
   48 
   49 
   50 
   51 
   52   my $header = 'Problem Editor';
   53 
   54   #########################################################################
   55   # Find the text for the problem, either in the tmp file, if it exists
   56   # or in the original file in the template directory
   57   #########################################################################
   58   my $problemContents = '';
   59   my $editMode    = (defined($r->param('problemContents')))?
   60                 'tmpMode':'startMode';
   61 
   62   if ( $editMode eq 'tmpMode') {
   63     $problemContents  = $r->param('problemContents');
   64 
   65   } else{
   66      eval { $problemContents  = WeBWorK::Utils::readFile($problemPath)  };  # try to read file
   67      $problemContents = $@ if $@;
   68   }
   69 
   70   #  save Action  FIXME  -- is this the write place for this?
   71   my $actionString = '';
   72   if ($r->param('submit') eq 'Save') {
   73     $actionString = "File saved to $problemPath";
   74     #FIXME  it would be MUCH better to work with temporary files
   75     open(FILE,">$problemPath") or die "Can't open $problemPath";
   76     print FILE $problemContents;
   77     close(FILE);
   78 
   79   }
   80 
   81     # create tmp file version for later use
   82     # So that you don't need duplicate information in forms
   83     # FIXME
   84     # open(FILE,">$tmpProblemPath") || die "Failed to open $tmpProblemPath";
   85     # print FILE "tmpfileVersion\n\n" . $problemContents;
   86     # close(FILE);
   87 
   88   # Define parameters for textarea
   89   # FIXME these parameters should be capable of being updated dynamically.
   90   my $rows    =   20;
   91   my $columns   =   80;
   92   my $mode_list   =   ['HTML', 'HTML_tth','HTML_dpng', 'Latex2HTML'];
   93   my $mode      =   ( defined($r->param('mode'))  ) ? $r->param('mode') : 'HTML_tth';
   94   my $seed    = ( defined($r->param('seed'))  ) ? $r->param('seed') : '1234';
   95   ########################################################################
   96   # Define a link to view the problem
   97   #FIXME
   98 
   99   #########################################################################
  100 
  101 
  102 
  103   #########################################################################
  104   # Format the page
  105   #########################################################################
  106 
  107   return CGI::p($header),
  108     CGI::startform("POST",$r->uri),
  109     $self->hidden_authen_fields,
  110     CGI::div(
  111     CGI::textfield(-name=>'seed',-value=>$seed),
  112     'Mode: ',
  113     CGI::popup_menu(-name=>'mode', -'values'=>$mode_list,
  114                            -default=>$mode),
  115     CGI::a(
  116       {-href=>'http://webwork.math.rochester.edu/docs/docs/pglanguage/manpages/',-target=>"manpage_window"},
  117       'Manpages',
  118       )
  119     ),
  120     CGI::p(
  121       CGI::textarea(-name => 'problemContents', -default => $problemContents,
  122               -rows => $rows, -columns => $columns, -override => 1,
  123       ),
  124     ),
  125     CGI::p(
  126       CGI::submit(-value=>'Save',-name=>'submit'),
  127       $actionString
  128     ),
  129     CGI::a({-href=>$ce->{viewProblemURL},-target=>'_viewProblem'},'view problem'),
  130     CGI::end_form(),
  131     "<p> the parameters passed are "  #FIXME -- debugging code
  132     . join("<BR>", %{$r->param()}) .
  133     "</p> and the gatheredInfo is ",
  134     "problemPath=$problemPath<br> formURL=".$r->uri . "<br> tmpProblemPath=$tmpProblemPath<br>"   ,
  135     "viewProblemURL ".$ce->{viewProblemURL}."<br>",
  136     "problem_obj =". $ce->{problem_obj}."<br>",
  137     "path_components ". $ce->{path_components};
  138 
  139   ;
  140 
  141 }
  142 
  143 sub initialize {
  144   #fix me.  This is very much hacked together.  In particular can we pass the key inside the post?
  145   my ($self, $setName, $problemNumber) = @_;
  146   my $ce            =   $self->{ce};
  147   my $r           = $self->{r};
  148   my $path_info         =   $r->path_info || "";
  149   my $db            = $self->{db};
  150   my $user          = $r->param('user');
  151   my $effectiveUserName   = $r->param('effectiveUser');
  152   my $courseName        = $ce->{courseName};
  153 
  154   my $set                 =   $db->getGlobalUserSet($effectiveUserName, $setName);
  155   my $setID         = $set->set_id;
  156   # Find URL for viewing problem
  157   my $viewProblemURL    = "/webwork/$courseName/".join("/",$setID,$problemNumber)."?" .$self->url_authen_args();
  158 
  159   my $problem_record    = $db->getUserProblem($user,$setID,1);
  160   my $templateDirectory = $ce->{courseDirs}->{templates};
  161   my $problemPath     = $templateDirectory."/".$problem_record->source_file;
  162   # return values.  FIXME  -- is this the right way to pass the values to body??
  163   $ce->{viewProblemURL} = $viewProblemURL;
  164   $ce->{problemPath}    =   $problemPath;
  165   $ce->{path_components}  = join("/",$setID,$problemNumber);
  166 
  167   # FIXME  there is no way to edit in a temporary file -- all editing takes place on disk!!!
  168 
  169 
  170 
  171 }
  172 
  173 # sub gatherProblemList {   #workaround for obtaining the definition of a problem set (awaiting implementation of db function)
  174 #   my $self = shift;
  175 #   my $setName = shift;
  176 #   my $output = "";
  177 #   if ( defined($setName) and $setName ne "" ) {
  178 #     my $templateDirectory = $self->{ce}->{courseDirs}->{templates};
  179 #     my $fileName = "$templateDirectory/$setName.def";
  180 #     my @output =  split("\n",WeBWorK::Utils::readFile($fileName) );
  181 #     @output = grep  /\.pg/,   @output;     # only get the .pg files
  182 #     @output = grep  !/Header/, @output;   # eliminate header files
  183 #     $output = join("\n",@output);
  184 #   } else {
  185 #     $output = "No set name |$setName| is defined";
  186 #   }
  187 #
  188 #
  189 #   return  $output
  190 #
  191 #
  192 #
  193 #
  194 # }
  195 # sub fetchSetDirectories {
  196 #
  197 #   my $self = shift;
  198 #   my $defaultChoice = shift;
  199 #   my $templateDirectory = $self->{ce}->{courseDirs}->{templates};
  200 #   opendir SETDEFDIR, $templateDirectory
  201 #     or return "Can't open directory $templateDirectory";
  202 #
  203 #   my @allFiles = grep !/^\./, readdir SETDEFDIR;
  204 #   closedir  SETDEFDIR;
  205 #
  206 #   ## filter to find only the set directories
  207 #   ## -- it is assumed that these directories don't contain a period in their names
  208 #   ## and that all other files do.  Directories names must also begin with "set".
  209 #   ## A better plan would be to read only the names of directories, not files.
  210 #
  211 #   ## sort the directories
  212 #   my @setDefFiles = grep /^set[^\.]*$/, @allFiles;
  213 #   my @sortedNames = sort @setDefFiles;
  214 #
  215 #   return "$libraryName/" . CGI::br(). CGI::popup_menu(-name=>'setDirectory', -size=>$rowheight,
  216 #    -values=>\@sortedNames, -default=>$defaultChoice ) .CGI::br() ;
  217 # }
  218 #
  219 # sub fetchPGproblems {
  220 #
  221 #   my $self = shift;
  222 #   my $setDirectory = shift;
  223 #
  224 #   # Handle default for setDirectory
  225 #   # fix me -- this is not bullet proof
  226 #   $setDirectory = "set0" unless defined($setDirectory);
  227 #   my $templateDirectory = $self->{ce}->{courseDirs}->{templates};
  228 #
  229 #   ##
  230 #   opendir SETDEFDIR, "$templateDirectory/$setDirectory"
  231 #     or return "Can't open directory $templateDirectory/$setDirectory";
  232 #
  233 #   my @allFiles = grep !/^\./, readdir SETDEFDIR;
  234 #   closedir  SETDEFDIR;
  235 #
  236 #   ## filter to find only pg problems
  237 #   ## Some problems are themselves in directories (if they have auxiliary
  238 #   ## .png's for example.  This eventuallity needs to be handled.
  239 #
  240 #   ## sort the directories
  241 #   my @pgFiles = grep /\.pg$/, @allFiles;
  242 #   my @sortedNames = sort @pgFiles;
  243 #
  244 #   return "$setDirectory ". CGI::br() .
  245 #   CGI::popup_menu(-name=>'pgProblem', -size=>$rowheight, -multiple=>undef, -values=>\@sortedNames,  ) .
  246 #   CGI::br() ;
  247 # }
  248 
  249 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9