[system] / trunk / webwork / system / cgi / cgi-scripts / profChangeDates.pl Repository:
ViewVC logotype

View of /trunk/webwork/system/cgi/cgi-scripts/profChangeDates.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (download) (as text) (annotate)
Mon Aug 20 16:05:10 2001 UTC (18 years, 3 months ago) by apizer
File size: 30011 byte(s)
Moved srand(time) out of loop around line 540. Otherwise (as Zig reports)
many or all students get the same seed for new or reseeded problems.

    1 #!/usr/local/bin/webwork-perl
    2 
    3 ## $Id$
    4 
    5 ####################################################################
    6 # Copyright @ 1995-1998 University of Rochester
    7 # All Rights Reserved
    8 ####################################################################
    9 
   10 
   11 ## This file is profChangeDates.pl
   12 ## It provides access to utilities for building, correcting and viewing problem sets
   13 ##
   14 
   15 
   16 use lib '.'; use webworkInit; # WeBWorKInitLine
   17 require 5.001;
   18 use strict;
   19 
   20 
   21 use Global;
   22 use Auth;
   23 use TimeLocal;
   24 use CGI qw(:standard);
   25 
   26 
   27 # Timing code
   28 use Benchmark;
   29 my $beginTime = new Benchmark;
   30 # end Timing code
   31 
   32 # variables global to this file
   33 my ($setNumber,$setHeaderFileName,$probHeaderFileName,$dueDate,$openDate,$answerDate,$problemListref,$problemValueListref,$problemAttemptLimitListref);
   34 my (@problemList,@problemValueList,@problemAttemptLimitList);
   35 
   36 &CGI::ReadParse;
   37 my %inputs=%main::in;
   38 
   39 my ($classID, $fileName);
   40 
   41 # establish environment for this script
   42 
   43     my $Course = $inputs{'course'};
   44 &Global::getCourseEnvironment($Course);
   45 
   46 
   47 my $cgiURL              = getWebworkCgiURL($Course);
   48 my $courseScriptsDirectory  = getCourseScriptsDirectory($Course);
   49 my $databaseDirectory     = getCourseDatabaseDirectory($Course);
   50 my $htmlURL             = getCourseHtmlURL($Course);
   51 my $scriptDirectory       = getWebworkScriptDirectory($Course);
   52 my $templateDirectory       = getCourseTemplateDirectory;
   53 
   54 require "${scriptDirectory}$Global::DBglue_pl";
   55 require "${scriptDirectory}$Global::FILE_pl";
   56 require "${scriptDirectory}$Global::HTMLglue_pl";
   57 
   58 my $updateMethod =$inputs{'updateMethod'};
   59 
   60 # log access
   61   &Global::log_info('', query_string);
   62 
   63 &webDatePage;
   64 
   65 # begin Timing code
   66 my $endTime = new Benchmark;
   67 &Global::logTimingInfo($beginTime,$endTime,"profChangeDates.pl",$inputs{'course'},$inputs{'course'});
   68 # end Timing code
   69 exit;
   70 
   71 #####################################END######################################
   72 
   73 sub webDatePage {
   74 #   verify the identity of the user.
   75   my $keyFile = &Global::getCourseKeyFile($inputs{'course'});
   76   &verify_key($inputs{'user'}, $inputs{'key'}, "$keyFile", $inputs{'course'});
   77   my $permissionsFile = &Global::getCoursePermissionsFile($inputs{'course'});
   78   my $permissions = &get_permissions($inputs{'user'}, $permissionsFile);
   79   if ($permissions != $Global::instructor_permissions ) {
   80     print "permissions = $permissions instructor_permissions= $Global::instructor_permissions\n";
   81     print &html_NO_PERMISSION;
   82     exit(0);
   83     }
   84 #    if (!defined($inputs{'pCD'})) {
   85 #   print &htmlTOP("Change Open/Due/Answer Date");
   86 #        # print navigation buttons
   87 #        print qq!
   88 #        <A HREF="${cgiURL}profLogin.pl?user=$inputs{'user'}&key=$inputs{'key'}&course=$inputs{'course'}">
   89 #        <IMG SRC="${Global::upImgUrl}" align="right" BORDER=1 ALT="[Up]"></A><p>
   90 #        !;
   91 #
   92 #   &printProbSetForm;
   93 #   print &htmlBOTTOM("profChangeDates.pl", \%inputs);
   94 #   exit;
   95 #   }
   96 
   97     if ($inputs{'pCD'}==1) {
   98     print &htmlTOP("Change Open/Due/Answer Date: Page 2");
   99         # print navigation buttons
  100         print qq!
  101         <A HREF="${cgiURL}profLogin.pl?user=$inputs{'user'}&key=$inputs{'key'}&course=$inputs{'course'}">
  102         <IMG SRC="${Global::upImgUrl}" align="right" BORDER=1 ALT="[Up]"></A><p>
  103         !;
  104     $setNumber=$inputs{'setNo'};
  105     &printForms($setNumber);
  106     print &htmlBOTTOM("profChangeDates.pl", \%inputs);
  107     }
  108 
  109     else {
  110 
  111     print &htmlTOP("Change Open/Due/Answer Date: Page 3");
  112         # print navigation buttons
  113         print qq!
  114         <A HREF="${cgiURL}profLogin.pl?user=$inputs{'user'}&key=$inputs{'key'}&course=$inputs{'course'}">
  115         <IMG SRC="${Global::upImgUrl}" align="right" BORDER=1 ALT="[Up]"></A><p>
  116         !;
  117     if ($inputs{'dateMode'} eq 'READWRITE') {
  118       &changeDates();
  119       &sendBack;
  120     }
  121     else {
  122       print '<H2>Read only mode, no changes made </H2>';
  123       print 'Go back and select Read/Write mode if you want to save changes.';
  124       &sendBack;
  125       }
  126         print &htmlBOTTOM("profChangeDates.pl", \%inputs);
  127   }
  128 }
  129 
  130 
  131 
  132 
  133 
  134 #sub printProbSetForm {
  135 #    print "<form action=\"${Global::cgiURL}profChangeDates.pl\">\n";
  136 #
  137 #    my %setNumberHash=&getAllProbSetNumbersHash;
  138 #    &printProbSets("setNo",\%setNumberHash);
  139 #
  140 #    print "<input type=\"hidden\" name=\"pCD\" value=1>\n";
  141 #    print &sessionKeyInputs(\%inputs);
  142 #    print "<br><input type=\"submit\" value=\"Continue\"></form>";
  143 #}
  144 
  145 sub printForms {
  146     my ($setNumber) = @_;
  147     print qq!<FORM method="post" action="profChangeDates.pl">\n!;
  148     &printChangeOpenForm(&findOpenDateForSet($setNumber));
  149     &printChangeDueForm( &findDueDateForSet($setNumber));
  150     &printChangeAnswerForm(&findAnswerDateForSet($setNumber));
  151 
  152   &printChangeSetHeaderFileForm(&findSetHeaderFileForSet($setNumber));
  153   &printChangeProbHeaderFileForm(&findProbHeaderFileForSet($setNumber));
  154 
  155 
  156     print  qq!
  157     <TABLE><TR>\n<TD>
  158     Read Only<INPUT TYPE="RADIO" NAME="dateMode" VALUE="READONLY" CHECKED>\n
  159     </TD><TD>
  160   Read/Write<INPUT TYPE="RADIO" NAME="dateMode" VALUE="READWRITE">\n
  161   </TD><TD>
  162   <input type=submit value="Save Above Changes">\n
  163   </TD></TR></TABLE>\n
  164     <input type=hidden name="pCD" value=2>\n
  165     <input type=hidden name="setNo" value=$setNumber>\n
  166   !;
  167     print &sessionKeyInputs(\%inputs);
  168     print "</FORM>\n";
  169 
  170     &printChangeProblemFileNamesForm();
  171 
  172 
  173 }
  174 
  175 
  176 sub changeDates {
  177     my $newOpenDate=$inputs{'openDate'};
  178     my $newDueDate=$inputs{'dueDate'};
  179     my $newAnswerDate=$inputs{'ansDate'};
  180     my $newSetHeaderFile = stripWhiteSpace($inputs{'setHeaderFile'});
  181     my $newProbHeaderFile = stripWhiteSpace($inputs{'probHeaderFile'});
  182 
  183     my $time1 = &unformatDateAndTime($newOpenDate);
  184     my $time2 = &unformatDateAndTime($newDueDate);
  185     my $time3 = &unformatDateAndTime($newAnswerDate);
  186     if ($time2 < $time1 or $time3 < $time2) {
  187         &Global::error('Dates not in chronological order', "The open date: $newOpenDate,
  188         due date: $newDueDate, and answer date: $newAnswerDate must be in chronologicasl order.");
  189     }
  190 
  191     my $setNumber=$inputs{'setNo'};
  192 
  193     changeDatesAndHeaderFiles($setNumber,$newOpenDate,$newDueDate,$newAnswerDate,$newSetHeaderFile,$newProbHeaderFile);
  194 
  195 #    &changeOpenDate($newOpenDate,$setNumber);
  196 #    print "<BR><BR>\n";
  197 #    &changeDueDate($newDueDate,$setNumber);
  198 #    print "<BR><BR>\n";
  199 #    &changeAnswerDate($newAnswerDate,$setNumber);
  200 #    print "<BR><BR>\n";
  201 #    &changeSetHeaderFile($newSetHeaderFile,$setNumber);
  202 #    print "<BR><BR>\n";
  203 # &changeProbHeaderFile($newProbHeaderFile,$setNumber);
  204 #    print "<BR><BR>\n";
  205 
  206 }
  207 
  208 sub findOpenDateForSet {
  209   my ($setNumber) = @_;
  210     my (@probSetKeys)=&getAllProbSetKeysForSet($setNumber);
  211     &attachProbSetRecord($probSetKeys[0]);
  212     &detachProbSetRecord($probSetKeys[0]);
  213     &formatDateAndTime( &getOpenDate($probSetKeys[0]));
  214 }
  215 
  216 sub printChangeOpenForm {
  217   my ( $prettyOldOpenDate) = @_;
  218     print <<EOF;
  219 <H3 ALIGN ="CENTER">Class Identification: $inputs{'course'}</H3>
  220 Use this form to makes changes for an entire set.  To make changes
  221 for an individual student go back and use "Examine or change individual problem set for:"
  222 
  223 <HR SIZE =2>
  224 <H3> Change opening and closing dates for set number $setNumber</H3>
  225 Please enter the new dates in the following format:<BR>6/28/96 at
  226 9:59 AM (June 28, 1996 at 9:59 AM)<p>
  227 
  228 Select the method you want to use. If e.g. you have given a few students an extension and
  229 do not want to override those changes, select the second method. <p>
  230 <INPUT TYPE=RADIO NAME='updateMethod' VALUE='all' > Change dates for all students.<BR>
  231 <INPUT TYPE=RADIO NAME='updateMethod' VALUE='some' CHECKED>
  232 Change dates only if the new date is later than an individual student\'s current date.<P>
  233 
  234 The current openDate is
  235 $prettyOldOpenDate
  236 
  237 <input type="text" size=20 maxlength=20 name="openDate"
  238 value="$prettyOldOpenDate"> New openDate<p>
  239 
  240 EOF
  241 }
  242 
  243 sub findDueDateForSet {
  244     my (@probSetKeys)=&getAllProbSetKeysForSet($setNumber);
  245     &attachProbSetRecord($probSetKeys[0]);
  246     &detachProbSetRecord($probSetKeys[0]);
  247     &formatDateAndTime( &getDueDate($probSetKeys[0]));
  248 }
  249 
  250 sub printChangeDueForm {
  251   my ( $prettyOldDueDate) = @_;
  252     print <<EOF;
  253 
  254 
  255 <p> The current DueDate is $prettyOldDueDate
  256 
  257 <input type="text" size=20 maxlength=20 name="dueDate"
  258 value="$prettyOldDueDate"> New DueDate<p>
  259 
  260 EOF
  261 }
  262 
  263 sub findAnswerDateForSet {
  264     my (@probSetKeys)=&getAllProbSetKeysForSet($setNumber);
  265     &attachProbSetRecord($probSetKeys[0]);
  266     &detachProbSetRecord($probSetKeys[0]);
  267     &formatDateAndTime( &getAnswerDate($probSetKeys[0]));
  268 }
  269 
  270 sub printChangeAnswerForm {
  271     my ( $prettyOldAnswerDate) = @_;
  272     print <<EOF;
  273 
  274 
  275 <p> The current AnswerDate is $prettyOldAnswerDate
  276 
  277 <input type="text" size=20 maxlength=20 name="ansDate"
  278 value="$prettyOldAnswerDate"> New AnswerDate<p>
  279 
  280 EOF
  281 }
  282 
  283 sub changeDatesAndHeaderFiles {
  284   my ($setNumber,$newOpenDate,$newDueDate,$newAnswerDate,$newSetHeaderFileName,$newProbHeaderFileName) = @_;
  285 
  286     my $newOpenDateTime = &unformatDateAndTime($newOpenDate);
  287     my $newDueDateTime = &unformatDateAndTime($newDueDate);
  288     my $newAnswerDateTime = &unformatDateAndTime($newAnswerDate);
  289 
  290     my $oldOpenDateTime;
  291     my $oldDueDateTime;
  292     my $oldAnswerDateTime;
  293 
  294     my @probSetKeys=&getAllProbSetKeysForSet($setNumber);
  295     my $probSetKey;
  296 
  297     foreach $probSetKey (@probSetKeys) {
  298     &attachProbSetRecord($probSetKey);
  299 
  300     if ($updateMethod eq 'all') {
  301       &putOpenDate($newOpenDateTime,$probSetKey);
  302       &putDueDate($newDueDateTime,$probSetKey);
  303       &putAnswerDate($newAnswerDateTime,$probSetKey);
  304     }
  305     else {
  306       $oldOpenDateTime = &getOpenDate($probSetKey);
  307       &putOpenDate($newOpenDateTime,$probSetKey) unless ($oldOpenDateTime > $newOpenDateTime);
  308 
  309       $oldDueDateTime = &getDueDate($probSetKey);
  310       &putDueDate($newDueDateTime,$probSetKey) unless ($oldDueDateTime > $newDueDateTime);
  311 
  312       $oldAnswerDateTime = &getAnswerDate($probSetKey);
  313       &putAnswerDate($newAnswerDateTime,$probSetKey) unless ($oldAnswerDateTime > $newAnswerDateTime);
  314     }
  315     &putSetHeaderFileName( $newSetHeaderFileName,$probSetKey);
  316     &putProbHeaderFileName( $newProbHeaderFileName,$probSetKey);
  317 
  318     &detachProbSetRecord($probSetKey);
  319   }
  320 
  321     print "<BR><BR>The new open date is now set to: $newOpenDate  for all students\n";
  322     print "except if their original open date was later than $newOpenDate\n" unless ($updateMethod eq 'all');
  323     print "<HR><BR>\n";
  324 
  325     print "The new due date is now set to: $newDueDate for all students\n";
  326     print "except if their original due date was later than $newDueDate\n" unless ($updateMethod eq 'all');
  327     print "<HR><BR>\n";
  328 
  329     print "The new answer date is now set to: $newAnswerDate for all students\n";
  330     print "except if their original answer date was later than $newAnswerDate\n" unless ($updateMethod eq 'all');
  331     print "<HR><BR>\n";
  332 
  333     print "The new Paper HeaderFile is: $newSetHeaderFileName \n";
  334     print "<HR><BR>\n";
  335 
  336     print "The new Screen HeaderFile is: $newProbHeaderFileName \n";
  337     print "<HR><BR>\n";
  338 
  339 }
  340 
  341 #sub changeOpenDate {
  342 # my ($newOpenDate,$setNumber) = @_;
  343 #    my $newOpenDateTime = &unformatDateAndTime($newOpenDate);
  344 #    my @probSetKeys=&getAllProbSetKeysForSet($setNumber);
  345 #    my $probSetKey;
  346 #    my $oldOpenDateTime;
  347 #    foreach $probSetKey (@probSetKeys) {
  348 #   &attachProbSetRecord($probSetKey);
  349 #   if ($updateMethod eq 'all') {&putOpenDate($newOpenDateTime,$probSetKey);}
  350 #   else {
  351 #     $oldOpenDateTime = &getOpenDate($probSetKey);
  352 #     &putOpenDate($newOpenDateTime,$probSetKey) unless ($oldOpenDateTime > $newOpenDateTime);
  353 #   }
  354 #   &detachProbSetRecord($probSetKey);
  355 # }
  356 #
  357 #    print "The new open date is now set to: $newOpenDate  for all students\n";
  358 #    print "except if their original open date was later than $newOpenDate\n" unless ($updateMethod eq 'all');
  359 #    print "_"x80 . "\n";
  360 #}
  361 #
  362 #sub changeDueDate {
  363 # my ($newDueDate,$setNumber) = @_;
  364 #    my $newDueDateTime = &unformatDateAndTime($newDueDate);
  365 #    my @probSetKeys=&getAllProbSetKeysForSet($setNumber);
  366 # my $probSetKey;
  367 # my $oldDueDateTime;
  368 #    foreach $probSetKey (@probSetKeys) {
  369 #   &attachProbSetRecord($probSetKey);
  370 #   if ($updateMethod eq 'all') {&putDueDate($newDueDateTime,$probSetKey);}
  371 #   else {
  372 #     $oldDueDateTime = &getDueDate($probSetKey);
  373 #     &putDueDate($newDueDateTime,$probSetKey) unless ($oldDueDateTime > $newDueDateTime);
  374 #   }     &detachProbSetRecord($probSetKey);
  375 #     }
  376 #
  377 #    print "The new due date is now set to: $newDueDate for all students\n";
  378 #    print "except if their original due date was later than $newDueDate\n" unless ($updateMethod eq 'all');
  379 #    print "_"x80 . "\n";
  380 #
  381 #}
  382 #
  383 #sub changeAnswerDate {
  384 # my ($newAnswerDate,$setNumber) = @_;
  385 #    my $newAnswerDateTime = &unformatDateAndTime($newAnswerDate);
  386 #    my @probSetKeys=&getAllProbSetKeysForSet($setNumber);
  387 # my $probSetKey;
  388 # my $oldAnswerDateTime;
  389 #    foreach $probSetKey (@probSetKeys){
  390 #   &attachProbSetRecord($probSetKey);
  391 #   if ($updateMethod eq 'all') {&putAnswerDate($newAnswerDateTime,$probSetKey);}
  392 #   else {
  393 #     $oldAnswerDateTime = &getAnswerDate($probSetKey);
  394 #     &putAnswerDate($newAnswerDateTime,$probSetKey) unless ($oldAnswerDateTime > $newAnswerDateTime);
  395 #   }     &detachProbSetRecord($probSetKey);
  396 #     }
  397 #
  398 #    print "The new answer date is now set to: $newAnswerDate for all students\n";
  399 #    print "except if their original answer date was later than $newAnswerDate\n" unless ($updateMethod eq 'all');
  400 #    print "_"x80 . "\n";
  401 # }
  402 
  403 
  404 sub findSetHeaderFileForSet {
  405   my ($setNumber) = @_;
  406     my (@probSetKeys)=&getAllProbSetKeysForSet($setNumber);
  407     &attachProbSetRecord($probSetKeys[0]);
  408     my $setHeaderFileName = &getSetHeaderFileName($probSetKeys[0]);
  409   $setHeaderFileName;
  410   }
  411 sub findProbHeaderFileForSet {
  412   my ($setNumber) = @_;
  413     my (@probSetKeys)=&getAllProbSetKeysForSet($setNumber);
  414     &attachProbSetRecord($probSetKeys[0]);
  415     my $probHeaderFileName = &getProbHeaderFileName($probSetKeys[0]);
  416   $probHeaderFileName;
  417   }
  418 sub printChangeSetHeaderFileForm {
  419   my ( $oldSetHeaderFileName) = @_;
  420   $oldSetHeaderFileName = "" unless defined($oldSetHeaderFileName);
  421     print <<EOF;
  422 
  423 <H3> Change the  Paper and Screen HeaderFiles for set number $setNumber</H3>
  424  The current Paper HeaderFile is $oldSetHeaderFileName
  425 
  426 <input type="text" size=30 maxlength=50 name="setHeaderFile"
  427 value="$oldSetHeaderFileName"> New SetHeaderFile<p>
  428 
  429 EOF
  430 }
  431 
  432 sub printChangeProbHeaderFileForm {
  433   my ( $oldProbHeaderFileName) = @_;
  434   $oldProbHeaderFileName = "" unless defined $oldProbHeaderFileName;
  435     print <<EOF;
  436 
  437  The current Screen HeaderFile is $oldProbHeaderFileName
  438 
  439 <input type="text" size=30 maxlength=50 name="probHeaderFile"
  440 value="$oldProbHeaderFileName"> New ProbHeaderFile<p>
  441 
  442 EOF
  443 }
  444 
  445 sub changeSetHeaderFile {
  446   my ($newSetHeaderFileName,$setNumber) = @_;
  447     my @probSetKeys=&getAllProbSetKeysForSet($setNumber);
  448   my $probSetKey;
  449     foreach $probSetKey (@probSetKeys){
  450     &attachProbSetRecord($probSetKey);
  451     &deleteSetHeaderFileName($probSetKey);
  452     &putSetHeaderFileName( $newSetHeaderFileName,$probSetKey);
  453     &detachProbSetRecord($probSetKey);
  454       }
  455     &attachProbSetRecord($probSetKeys[0]);
  456     $newSetHeaderFileName = &getSetHeaderFileName($probSetKeys[0]);
  457     print "The new Paper HeaderFile is: $newSetHeaderFileName \n";
  458     print "_"x80 . "\n";
  459     &detachProbSetRecord($probSetKeys[0]);
  460   }
  461 sub changeProbHeaderFile {
  462   my ($newProbHeaderFileName,$setNumber) = @_;
  463     my @probSetKeys=&getAllProbSetKeysForSet($setNumber);
  464   my $probSetKey;
  465     foreach $probSetKey (@probSetKeys){
  466     &attachProbSetRecord($probSetKey);
  467     &deleteProbHeaderFileName($probSetKey);
  468     &putProbHeaderFileName( $newProbHeaderFileName,$probSetKey);
  469     &detachProbSetRecord($probSetKey);
  470       }
  471     &attachProbSetRecord($probSetKeys[0]);
  472     $newProbHeaderFileName = &getProbHeaderFileName($probSetKeys[0]);
  473     print "The new Screen HeaderFile is: $newProbHeaderFileName \n";
  474     print "_"x80 . "\n";
  475     &detachProbSetRecord($probSetKeys[0]);
  476   }
  477 
  478 
  479 
  480 sub sendBack {
  481 print <<EOF;
  482 <p>
  483      <A HREF="${cgiURL}profLogin.pl?user=$inputs{'user'}&key=$inputs{'key'}&course=$inputs{'course'}">
  484           <IMG SRC="$Global::upImgUrl" BORDER=1></A>
  485 EOF
  486 }
  487 
  488 
  489 
  490 sub printChangeProblemFileNamesForm {
  491 
  492   my $delete_cached_l2h_images = 0; ## if problems are deleted or reseeded, this will mess up
  493                     ## the chached latex2html image. We keep track of this so
  494                     ## we can delete them.
  495 
  496 #   Update the database if needed
  497 if ( ( defined( $inputs{'FileNameEditMode'}) && $inputs{'FileNameEditMode'} eq "ReadWrite" )
  498    ||
  499    ( defined( $inputs{'AddNewProblem'})   && $inputs{'AddNewProblem'}    eq "Add"     ) )
  500   {
  501 
  502 #   get list of changed problems submitted by the form
  503     my $i;
  504     my @changedProblems;
  505     foreach $i ( grep(/ProblemFileName/, keys %inputs) ) {
  506 
  507       if ( $i =~ /^ProblemFileName(.+)$/ ) {
  508         push(@changedProblems, $1);
  509       }
  510       if ($inputs{'AddNewProblem'} eq "Add" ) {
  511         if ( $i =~ /^NewProblemFileName(.+)$/ ) {
  512             my $label = $1;
  513             # file name cannot be blank and cannot contain a question mark.
  514             if ($inputs{"NewProblemFileName$label"} =~/\w+/ && not $inputs{"NewProblemFileName$label"} =~/\?/) {
  515             push(@changedProblems, $label) ;
  516             $inputs{"ProblemFileName$label"}=$inputs{"NewProblemFileName$label"};
  517             $inputs{"ProblemValue$label"}=$inputs{"NewProblemValue$label"};
  518           }
  519       }
  520     }
  521   }
  522 
  523  ##############################
  524 ### Later this program assumes that the problem numbers in @changedProblems are in ascending order,
  525 ### but the validity of this assumption depends on whether the hash  %inputs
  526 ### preserves the order of the form variables; in particular, do the keys
  527 ### ProblemFileName1, ProblemFileName2, ..., ProblemFileName(N), NewProblemFileName(N+1), etc.,
  528 ### occur in that order in the array    keys %inputs    .
  529 ### On harper.ucs.indiana.edu, which is a Sun running Sun OS 5.7,
  530 ### the keys do not necessarily occur in increasing order of the problem number.
  531 ### For short hashes, they do.  But for long hashes, they usually do not, and that causes
  532 ### this program to fail.  So we must have the line below to insure
  533 ### that @changedProblems is ordered in ascending order.
  534 #############################
  535      @changedProblems = sort {$a <=> $b} @changedProblems;
  536 ###############################
  537 
  538 
  539    my $psvn;
  540    my @psvn = &getAllProbSetKeysForSet($setNumber);
  541    srand(time);
  542    foreach $psvn (@psvn)  {
  543        &attachProbSetRecord($psvn);
  544        my $num =1;
  545 #       srand(time);  ## Move this out of the loop as per Zig's suggestion.
  546             ## Otherwise many students get the same seed - AKP
  547       foreach $i (@changedProblems) {
  548 
  549       ## chech if we should delete cached l2h images
  550       if  ( defined( $inputs{"problem{$i}EditMode"}) and
  551         (($inputs{"problem{$i}EditMode"} eq "ReSeed") or ($inputs{"problem{$i}EditMode"} eq "Delete"))) {
  552           $delete_cached_l2h_images = 1;
  553       }
  554 
  555             #ReadWrite
  556                     #save seed (or define it)
  557                   my  $seed = &getProblemSeed($i,$psvn);
  558                   unless (defined($seed) ){
  559                     print STDERR "profChangeDates.pl: Seed for problem $i is not defined<BR>";
  560                   $seed = int( rand(5000) );
  561                   }
  562 
  563           #save
  564           my ($filename, $status, $attempted, $pvalue, $maxNumOfIncorrectAttempts);
  565               $filename = &getProblemFileName(    $i,$psvn);
  566               $attempted = &getProblemAttempted(   $i,$psvn);
  567           $status = &getProblemStatus(   $i,$psvn);
  568                 $pvalue = &getProblemValue(       $i,$psvn);
  569           $maxNumOfIncorrectAttempts = &getProblemMaxNumOfIncorrectAttemps(  $i,$psvn);
  570 
  571                 # delete problem names and values
  572               &deleteProblemFileName(    $i,$psvn);
  573               &deleteProblemAttempted(   $i,$psvn);
  574           &deleteProblemStatus(   $i,$psvn);
  575                 &deleteProblemValue(       $i,$psvn);
  576           &deleteProblemMaxNumOfIncorrectAttemps(  $i,$psvn);
  577                 &deleteProblemSeed(        $i,$psvn);
  578                 # recreate problem using saved seed
  579                 unless (defined( $inputs{"problem{$i}EditMode"}) && $inputs{"problem{$i}EditMode"} eq "Delete" ) {
  580 
  581             if ($inputs{"ProblemFileName$i"} =~ /\w+/) {$filename = stripWhiteSpace($inputs{"ProblemFileName$i"});}
  582                   &putProblemFileName($filename ,   $num,$psvn);
  583 
  584                   if ($inputs{"ProblemAttempted$i"} =~ /\w+/) {$attempted = stripWhiteSpace($inputs{"ProblemAttempted$i"});}
  585             &putProblemAttempted($attempted,     $num,$psvn);
  586 
  587             if ($inputs{"ProblemStatus$i"} =~ /\w+/) {$status = stripWhiteSpace($inputs{"ProblemStatus$i"});}
  588             &putProblemStatus($status,     $num,$psvn);
  589 
  590             if ($inputs{"ProblemValue$i"} =~ /\w+/) {$pvalue = stripWhiteSpace($inputs{"ProblemValue$i"});}
  591                   &putProblemValue($pvalue,  $num,$psvn);
  592 
  593             if ($inputs{"ProblemMaxNumOfIncorrectAttemps$i"} =~ /\w+/) {$maxNumOfIncorrectAttempts = stripWhiteSpace($inputs{"ProblemMaxNumOfIncorrectAttemps$i"});}
  594             &putProblemMaxNumOfIncorrectAttemps($maxNumOfIncorrectAttempts,  $num,$psvn);
  595 
  596             &putProblemSeed(        $seed,$num,$psvn);
  597 
  598                   # Reseed if requested
  599                   if  ( defined( $inputs{"problem{$i}EditMode"}) && $inputs{"problem{$i}EditMode"} eq "ReSeed" ) {
  600                       $seed = int( rand(5000) );
  601                       &putProblemSeed( $seed ,  $num,$psvn);
  602                       print "Seed changed for problem number $num, psvn $psvn<BR>\n";
  603                       }
  604                     $num++;
  605                   }
  606 
  607 
  608                 }
  609         &detachProbSetRecord($psvn);
  610         }
  611 } # end of updating database
  612 
  613 ## remobe l2h images if necessary
  614 
  615 if ($delete_cached_l2h_images) {
  616   my $l2hDir = getCoursel2hDirectory();
  617   system ("rm -rf ${l2hDir}set$setNumber");
  618   print "\n<BR>deleting Latex2html tmp files and the directory:<BR>\n";
  619   print "     ${l2hDir}set$setNumber<BR>";
  620 }
  621 
  622 
  623 # print a new form
  624     print qq!<HR NOSHADE>\n
  625          <FORM method="post" action="profChangeDates.pl">
  626          !;
  627   print     &sessionKeyInputs(\%inputs);
  628   if (defined( $inputs{"FileNameEditMode"}) && $inputs{"FileNameEditMode"} eq "ReadWrite") {
  629     print     "CHANGES SAVED FOR SET $setNumber<BR>";
  630   } elsif ( defined( $inputs{'AddNewProblem'})   && $inputs{'AddNewProblem'}    eq "Add"     )   {
  631     print     "Problems added to SET $setNumber<BR>";
  632   } elsif ( defined( $inputs{"FileNameEditMode"}) && $inputs{"FileNameEditMode"} eq "ReadOnly") {
  633     print     "ReadOnly mode -- <B>NO</B> CHANGES SAVED FOR SET $setNumber<BR>";
  634   }
  635   my @psvn = &getAllProbSetKeysForSet($setNumber);
  636 
  637   print qq!
  638           <INPUT TYPE="HIDDEN" NAME="pCD" VALUE="1">\n
  639       <INPUT TYPE="HIDDEN" NAME="setNo" VALUE="$setNumber">\n
  640 
  641       <H3>Change problem file names, status, etc. for set $setNumber:</H3>\n
  642 
  643       <H4>If a Filename, "Attempted", "Status", "Value", or "MaxAttmp" cell is left blank, the corresponding
  644       individualized current values in the database will be maintained. If a value is
  645       entered, that value will be used for every student's problem. Valid values for "Attempted"
  646       are: 0 (not attempted) or 1. Valid values for "Status" are numbers in the range [0,1] where 0 represents
  647       no credit and 1 full crefit.  Valid values for "Value" are
  648       non-negative integers with 1 (1 point) being the most common.  Valid values for "MaxAttmp"
  649       are -1 and non-negative integers where -1 means allow unlimited attempts.  The Filename
  650       for a random student is listed. To see the actual data for any student, go back and use
  651       "Examine or change individual problem set for:"
  652       </H4>\n
  653 
  654       <TABLE><TR><TD>\n
  655        ReadOnly<INPUT TYPE=RADIO NAME="FileNameEditMode" VALUE="ReadOnly" CHECKED>\n
  656        </TD><TD>\n
  657        Read/Write<INPUT TYPE=RADIO NAME="FileNameEditMode" VALUE="ReadWrite" >\n
  658        </TD><TD>\n
  659            <INPUT TYPE=SUBMIT VALUE="Save Problem Changes"><p>\n
  660            </TD></TR></TABLE>
  661            <TABLE BORDER="1" CELLPADDING="1" CELLSPACING="2" >\n
  662        !;
  663 #Re-establish the order of problems from database -- they may have changed.
  664     my $psvn = $psvn[0];
  665     my $Mode = defined($inputs{'mode'}) ? $inputs{'mode'} : "HTML";
  666     my $User = $inputs{'user'};
  667     my $Key =  $inputs{'key'};
  668   &attachProbSetRecord($psvn);
  669   my @problems = sort {$a <=> $b} &getAllProblemsForProbSetRecord($psvn);
  670 
  671 
  672 # print table listing problems
  673     my $i;
  674   foreach $i (@problems) {
  675       print "<TR>";
  676           print &formatHeaderCell( qq!
  677               <A HREF="${Global::processProblem_CGI}?probSetKey=$psvn&probNum=$i&Mode=$Mode&course=$Course&user=$User&key=$Key" TARGET="VIEW_PROBLEM">
  678              Problem $i</A>
  679              !
  680              );
  681              print &formatHeaderCell( "Attempted");
  682          print &formatHeaderCell( "Status");
  683              print &formatHeaderCell( "Value");
  684          print &formatHeaderCell( "MaxAttmp");
  685              print &formatHeaderCell( "Delete" );
  686              print &formatHeaderCell( "ReSeed" );
  687              print "</TR>";
  688 
  689 
  690       print "<TR>";
  691 
  692           print &formatDataCell( "ProblemFileName$i"  , &getProblemFileName($i,$psvn),"50" );
  693           print &formatDataCell( "ProblemAttempted$i"    , ''   ,"1");
  694       print &formatDataCell( "ProblemStatus$i"    ,'' ,"5");
  695           print &formatDataCell( "ProblemValue$i"     ,''    ,"5");
  696       print &formatDataCell( "ProblemMaxNumOfIncorrectAttemps$i"     , ''    ,"4");
  697           print & formatRadioButtonCell( "problem{$i}EditMode", "Delete"   ,"5", "");
  698       print & formatRadioButtonCell( "problem{$i}EditMode", "ReSeed"   ,"5", "");
  699 
  700       print "</TR>";
  701 
  702       }
  703 
  704   print qq!
  705     </TABLE>\n
  706     <HR NOSHADE>
  707     <H3>Add problem file names for set $setNumber</H3>\n
  708     Off <INPUT TYPE="RADIO" NAME="AddNewProblem" VALUE="Off" CHECKED> \n
  709     Add <INPUT TYPE="RADIO" NAME="AddNewProblem" VALUE="Add"> \n
  710     <INPUT TYPE=SUBMIT VALUE="Add File Names to Set"><p>\n
  711     <TABLE BORDER="1" CELLPADDING="1" CELLSPACING="2" >\n
  712     !;
  713 # print table new listing problems
  714   foreach $i (101,102) {
  715       print "<TR>";
  716              print &formatHeaderCell( "New File $i");
  717              print &formatHeaderCell( "Attempted");
  718              print &formatHeaderCell( "Status");
  719          print &formatHeaderCell( "Value");
  720          print &formatHeaderCell( "MaxAttmp");
  721              print "</TR>\n";
  722 
  723 
  724       print "<TR>";
  725 
  726           print &formatDataCell( "NewProblemFileName$i"  , " " ,"30" );
  727           print &formatDataCell( "NewProblemAttempted$i"    ,  "0"  ,"1");
  728       print &formatDataCell( "NewProblemStatus$i"    ,  "0"  ,"5");
  729           print &formatDataCell( "NewProblemValue$i"     , "1" ,"5");
  730       print &formatDataCell( "ProblemMaxNumOfIncorrectAttemps$i"     ,  "-1"    ,"4");
  731 
  732       print "</TR>\n";
  733       }
  734 print qq!
  735     </TABLE>\n
  736 
  737     </FORM>\n
  738     !;
  739 #############################################
  740 # build a problem set
  741 #############################################
  742 
  743 print <<EOF;
  744 <P>
  745 <HR NOSHADE>
  746 <H4 ALIGN=LEFT>
  747 <img src="$Global::bluesquareImgUrl" border=1 alt="">
  748  Build a problem set for $Course:
  749  </H4>
  750 EOF
  751 
  752 print "<TD>",
  753 start_form('POST', "${Global::cgiWebworkURL}profBuildProblemSetPage.pl"),
  754 p,"\n",
  755 hidden('course'), "\n",
  756 hidden('user'),   "\n",
  757 hidden('key'),    "\n",
  758 submit("Enter Build Problem Set Page"),
  759 end_form,
  760 "</TD>",
  761 "You can build a problem set, edit a set definition file, etc.";
  762 
  763 # delete an entire problem set
  764 print <<EOF;
  765 <P>
  766 <HR NOSHADE>
  767 <H4 ALIGN=LEFT><A HREF="${cgiURL}profDeleteProbSet.pl?user=$inputs{'user'}&key=$inputs{'key'}&course=$inputs{'course'}">
  768          <IMG SRC="$Global::bluesquareImgUrl"
  769               BORDER=1
  770               ALT="">  Delete a problem set in $Course</A>
  771 </H4>
  772   Remove an entire problem set from the database.
  773               Individual problems can be deleted from the set using the method 2. above.
  774 
  775 EOF
  776 
  777   } #DONE printChangeProblemFileNamesForm()
  778 
  779 #sub printAddProblemFileNameForm {
  780 #
  781 # my @problems = ("new1","new2");
  782 #
  783 ## updating will be done in printChangeProblemFileNamesForm()
  784 #
  785 ## print a new form
  786 #    print qq!<HR NOSHADE>\n
  787 #        <FORM method="post" action="profChangeDates.pl">
  788 #        !;
  789 # print     &sessionKeyInputs(\%inputs);
  790 # print qq!
  791 #         <INPUT TYPE="HIDDEN" NAME="pCD" VALUE="1">\n
  792 #     <INPUT TYPE="HIDDEN" NAME="setNumber" VALUE="$setNumber">\n
  793 #     <HR NOSHADE>
  794 #     <H3>Add problem file names for set $setNumber</H3>\n
  795 #     Off <INPUT TYPE="RADIO" NAME="AddNewProblem" VALUE="Off"><BR>\n
  796 #     Add <INPUT TYPE="RADIO" NAME="AddNewProblem" VALUE="Add"><BR>\n
  797 #     <INPUT TYPE=SUBMIT VALUE="Add New Problem"><p>\n
  798 #     <TABLE BORDER="1" CELLPADDING="1" CELLSPACING="2" >\n
  799 #     !;
  800 ## print table new listing problems
  801 # foreach $i ("9998") {
  802 #     print "<TR>";
  803 #            print &formatHeaderCell( $i);
  804 #            print &formatHeaderCell( "Value"  );
  805 #            print "</TR>\n";
  806 #
  807 #
  808 #     print "<TR>";
  809 #
  810 #         print &formatDataCell( "NewProblemFileName$i"  , "???" ,"30" );
  811 #         print &formatDataCell( "NewProblemValue$i"     , "???" ,"5");
  812 #
  813 #     print "</TR>\n";
  814 #     }
  815 #print qq!
  816 #   </TABLE>\n
  817 #
  818 #   </FORM>\n
  819 #   !;
  820 #  }
  821 
  822 sub formatDataRow {
  823     my ($pAitems,$size) =@_;
  824     my $out = "<TR>\n";
  825     my $value;
  826     my $i;
  827     foreach $i (@$pAitems) {
  828         $value = eval "\$$i=&get$i($inputs{'psvn'})";
  829         $out .= &formatDataCell($i,$value,$size);
  830         }
  831     $out .= "</TR>\n";
  832     }
  833 sub formatHeaderRow {
  834     my ( $pAitems,$options) =@_;
  835     my $out = "<TR>\n";
  836     my $i;
  837     foreach $i ( @$pAitems) {
  838         $out .= &formatHeaderCell($i,$options);
  839         }
  840     $out .= "</TR>\n";
  841     }
  842 sub formatDataCell {
  843     my  ($name,$value,$size) = @_;
  844     $value = "" unless defined($value); # this value is optional
  845     $size = "" unless defined($size);     # this value is optional
  846     my $out = qq!
  847     <TD ALIGN=CENTER VALIGN=MIDDLE >
  848     <INPUT TYPE="TEXT" NAME="$name" VALUE="$value", SIZE=$size>
  849     </TD>
  850     !;
  851     $out;
  852     }
  853 sub formatRadioButtonCell {
  854     my ($name,$value,$size, $options) = @_;
  855     $options = "" unless defined($options);
  856     my $out = qq!
  857     <TD ALIGN=CENTER VALIGN=MIDDLE >
  858     <INPUT TYPE="RADIO" NAME="$name" VALUE="$value" SIZE="$size" $options>
  859     </TD>
  860     !;
  861     $out;
  862     }
  863 sub formatHeaderCell {
  864     my ($item,$options) = @_;
  865     $options = "" unless defined($options);
  866     my $out = qq!
  867     <TH ALIGN=CENTER VALIGN=MIDDLE $options>
  868     $item
  869     </TH>
  870     !;
  871 
  872     }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9