Diff for /loncom/publisher/testbankimport.pm between versions 1.2 and 1.8

version 1.2, 2004/02/18 21:50:00 version 1.8, 2006/04/06 19:31:03
Line 1 Line 1
   # Handler for parsing text upload problem descriptions into .problems
   # $Id$
   #
   # Copyright Michigan State University Board of Trustees
   #
   # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   #
   # LON-CAPA is free software; you can redistribute it and/or modify
   # it under the terms of the GNU General Public License as published by
   # the Free Software Foundation; either version 2 of the License, or
   # (at your option) any later version.
   #
   # LON-CAPA is distributed in the hope that it will be useful,
   # but WITHOUT ANY WARRANTY; without even the implied warranty of
   # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   # GNU General Public License for more details.
   #
   # You should have received a copy of the GNU General Public License
   # along with LON-CAPA; if not, write to the Free Software
   # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   #
   # /home/httpd/html/adm/gpl.txt
   #
   # http://www.lon-capa.org/
   #
   
 package Apache::testbankimport;  package Apache::testbankimport;
   
     use strict;  use strict;
     use Apache::Constants qw(:common :http :methods);  use Apache::Constants qw(:common :http :methods);
     use Apache::loncacc;  use Apache::loncacc;
     use Apache::loncommon();  use Apache::loncommon();
     use Apache::Log();  use Apache::lonnet;
     use Apache::lonnet;  use HTML::Entities();
     use HTML::Entities();  use Apache::lonlocal;
     use Apache::lonlocal;  use Apache::lonupload;
     use Apache::lonupload;  use File::Basename();
     use File::Basename();  
   
 # ---------------------------------------------------------------- Display Control  # ---------------------------------------------------------------- Display Control
 sub display_control {  sub display_control {
 # figure out what page we're on and where we're heading.  # figure out what page we're on and where we're heading.
     my $page = $ENV{'form.page'};      my $page = $env{'form.page'};
     my $command = $ENV{'form.go'};      my $command = $env{'form.go'};
     my $current_page = &calculate_page($page,$command);      my $current_page = &calculate_page($page,$command);
     return $current_page;      return $current_page;
 }  }
Line 60  function setElements() { Line 85  function setElements() {
     var iter = 0      var iter = 0
     var selParam = 0      var selParam = 0
 END_SCRIPT  END_SCRIPT
     if (exists($ENV{'form.blocks'}) ) {      if (exists($env{'form.blocks'}) ) {
         $$jsref .= qq|          $$jsref .= qq|
     document.forms.display.blocks.value = $ENV{'form.blocks'}\n|;      document.forms.display.blocks.value = $env{'form.blocks'}\n|;
     } elsif (exists($ENV{'form.qnumformat'}) ) {      } elsif (exists($env{'form.qnumformat'}) ) {
         $$jsref .= <<"TO_HERE";          $$jsref .= <<"TO_HERE";
     for (iter=0; iter<document.forms.display.qnumformat.length; iter++) {      for (iter=0; iter<document.forms.display.qnumformat.length; iter++) {
         if(document.forms.display.qnumformat.options[iter].value == "$ENV{'form.qnumformat'}") {          if(document.forms.display.qnumformat.options[iter].value == "$env{'form.qnumformat'}") {
             selParam = iter              selParam = iter
         }          }
     }      }
Line 82  TO_HERE Line 107  TO_HERE
 sub jscript_two {  sub jscript_two {
     my ($jsref,$qcount) = @_;      my ($jsref,$qcount) = @_;
     my $blocks = 0;      my $blocks = 0;
     if ( exists( $ENV{'form.blocks'}) ) {      if ( exists( $env{'form.blocks'}) ) {
         $blocks = $ENV{'form.blocks'};          $blocks = $env{'form.blocks'};
     }      }
     $$jsref = <<"END_SCRIPT";      $$jsref = <<"END_SCRIPT";
 function verify() {  function verify() {
Line 222  function colSet(caller) { Line 247  function colSet(caller) {
             poolForm.elements[caller*5+4].options[2] = new Option("A.","ucperiod",false,false)              poolForm.elements[caller*5+4].options[2] = new Option("A.","ucperiod",false,false)
             poolForm.elements[caller*5+4].options[3] = new Option("(a)","lcparen",false,false)              poolForm.elements[caller*5+4].options[3] = new Option("(a)","lcparen",false,false)
             poolForm.elements[caller*5+4].options[4] = new Option("(A)","ucparen",false,false)              poolForm.elements[caller*5+4].options[4] = new Option("(A)","ucparen",false,false)
             poolForm.elements[caller*5+4].options[5] = new Option("(i)","romparen",false,false)              poolForm.elements[caller*5+4].options[5] = new Option("a)","lconeparen",false,false)
             poolForm.elements[caller*5+4].options[6] = new Option("i.","romperiod",false,false)              poolForm.elements[caller*5+4].options[6] = new Option("A)","uconeparen",false,false)
               poolForm.elements[caller*5+4].options[7] = new Option("a.)","lcdotparen",false,false)
               poolForm.elements[caller*5+4].options[8] = new Option("A.)","ucdotparen",false,false)
               poolForm.elements[caller*5+4].options[9] = new Option("(i)","romparen",false,false)
               poolForm.elements[caller*5+4].options[10] = new Option("i)","romoneparen",false,false)
               poolForm.elements[caller*5+4].options[11] = new Option("i.)","romdotparen",false,false)
               poolForm.elements[caller*5+4].options[12] = new Option("i.","romperiod",false,false)
             poolForm.elements[caller*5+4].selectedIndex = 0              poolForm.elements[caller*5+4].selectedIndex = 0
         }          }
         else {          else {
Line 255  function colSet(caller) { Line 286  function colSet(caller) {
                 if (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "TF") {                  if (poolForm.elements[caller*5+3].options[poolForm.elements[caller*5+3].selectedIndex].value == "TF") {
                     poolForm.elements[caller*5+5].options[0] = new Option("Please Select","-1",true,true)                      poolForm.elements[caller*5+5].options[0] = new Option("Please Select","-1",true,true)
                     poolForm.elements[caller*5+5].options[1] = new Option("True or False","word",false,false)                      poolForm.elements[caller*5+5].options[1] = new Option("True or False","word",false,false)
                     poolForm.elements[caller*5+5].options[2] = new Option("T or F","lett",false,false)                      poolForm.elements[caller*5+5].options[2] = new Option("true or false","word",false,false)
                       poolForm.elements[caller*5+5].options[3] = new Option("TRUE or FALSE","word",false,false)
                       poolForm.elements[caller*5+5].options[4] = new Option("T or F","lett",false,false)
                       poolForm.elements[caller*5+5].options[5] = new Option("t or f","lett",false,false)
                 }                  }
                 else {                  else {
                     poolForm.elements[caller*5+5].options[0] = new Option("Not required","0",true,true)                      poolForm.elements[caller*5+5].options[0] = new Option("Not required","0",true,true)
Line 273  END_SCRIPT Line 307  END_SCRIPT
     for (my $x=0; $x<$blocks; $x++) {      for (my $x=0; $x<$blocks; $x++) {
         foreach my $name (@names) {          foreach my $name (@names) {
             my $parname = $name.$x;              my $parname = $name.$x;
             my $value = $ENV{"form.$parname"};              my $value = $env{"form.$parname"};
             if ($value ne "") {              if ($value ne "") {
                 if (($name eq "start_")  || ($name eq "end_")) {                  if (($name eq "start_")  || ($name eq "end_")) {
                     $$jsref .= qq|                      $$jsref .= qq|
Line 310  TO_HERE Line 344  TO_HERE
 sub jscript_three {  sub jscript_three {
     my ($fullpath,$jsref) = @_;      my ($fullpath,$jsref) = @_;
     my $source = '';      my $source = '';
     if (exists($ENV{'form.go'}) ) {      if (exists($env{'form.go'}) ) {
         $source = $ENV{'form.go'};          $source = $env{'form.go'};
     }      }
   
       my $start_page = 
    &Apache::loncommon::start_page('Create IMS import directory',undef,
          {'only_body'   => 1,
    'add_entries' => "topmargin='0' leftmargin='0' marginheight='0'marginwidth='0' rightmargin='0'",
    'js_ready'    => 1,});
       my $end_page = 
    &Apache::loncommon::end_page({'js_ready' => 1,});
     $$jsref = <<"END_OF_ONE";      $$jsref = <<"END_OF_ONE";
 function verify() {  function verify() {
     if ((document.forms.dataForm.newdir.value == '')  || (!document.forms.dataForm.newdir.value)) {      if ((document.forms.dataForm.newdir.value == '')  || (!document.forms.dataForm.newdir.value)) {
Line 337  function createWin() { Line 379  function createWin() {
     document.dataForm.newdir.value = "";      document.dataForm.newdir.value = "";
     newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes")      newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes")
     newWindow.document.open()      newWindow.document.open()
     newWindow.document.write("<html><head><title>Create Testbank directory</title><meta http-equiv='pragma' content='no-cache'>\\n")      newWindow.document.write('$start_page')
     newWindow.document.write("</head><body bgcolor='#CCFFDD' topmargin='0' leftmargin='0' marginheight='0'marginwidth='0' rightmargin='0'>\\n")  
     newWindow.document.write("<img border='0' src='/adm/lonInterFace/author.jpg' alt='[Author Header]'>\\n")      newWindow.document.write("<img border='0' src='/adm/lonInterFace/author.jpg' alt='[Author Header]'>\\n")
     newWindow.document.write("<table border='0' cellspacing='0' cellpadding='0' width='430' bgcolor='#CCFFDD'>\\n")      newWindow.document.write("<table border='0' cellspacing='0' cellpadding='0' width='430' bgcolor='#CCFFDD'>\\n")
     newWindow.document.write("<tr><td width='2'>&nbsp;</td><td width='3'>&nbsp;</td>\\n")      newWindow.document.write("<tr><td width='2'>&nbsp;</td><td width='3'>&nbsp;</td>\\n")
Line 352  function createWin() { Line 393  function createWin() {
     newWindow.document.write("$fullpath<input type='text' name='newfilename' value=''/>")      newWindow.document.write("$fullpath<input type='text' name='newfilename' value=''/>")
     newWindow.document.write("<input type='button' value='Go' onClick='document.fileaction.submit();' />")      newWindow.document.write("<input type='button' value='Go' onClick='document.fileaction.submit();' />")
     newWindow.document.write("</td></tr>\\n")      newWindow.document.write("</td></tr>\\n")
     newWindow.document.write("</table></body></html>")      newWindow.document.write("</table>")
       newWindow.document.write('$end_page')
     newWindow.document.close()      newWindow.document.close()
     newWindow.focus()      newWindow.focus()
 }  }
Line 363  function setElements() { Line 405  function setElements() {
     var iter = 0      var iter = 0
     var selParam = 0      var selParam = 0
         |;          |;
         foreach my $item (keys %ENV) {          foreach my $item (keys %env) {
             if ($item =~ m/^form\.(\w+)$/) {              if ($item =~ m/^form\.(\w+)$/) {
                 my $name = $1;                   my $name = $1; 
                 my $value = $ENV{"form.$name"};                  my $value = $env{"form.$name"};
                 unless ($value eq "") {                  unless ($value eq "") {
                     if ($name eq "newdir") {                      if ($name eq "newdir") {
                      $$jsref .= qq(    document.forms.dataForm.$name.value = "$value"\n);                       $$jsref .= qq(    document.forms.dataForm.$name.value = "$value"\n);
Line 619  Please indicate the number of blocks of Line 661  Please indicate the number of blocks of
   
 sub display_two {  sub display_two {
     my ($r,$uname,$fn,$page,$textref,$qcount) = @_;      my ($r,$uname,$fn,$page,$textref,$qcount) = @_;
     my $blocks = $ENV{'form.blocks'};      my $blocks = $env{'form.blocks'};
     my $qnumformat = $ENV{'form.qnumformat'};      my $qnumformat = $env{'form.qnumformat'};
     my @types = ("MC","MA","TF","Ess","FIB","Ord");      my @types = ("MC","MA","TF","Ess","FIB","Ord");
     my %typenames = (      my %typenames = (
              MC => "Multiple Choice",               MC => "Multiple Choice",
Line 832  END_OF_FUNC Line 874  END_OF_FUNC
 # ---------------------------------------------------------------- Display Three  # ---------------------------------------------------------------- Display Three
 sub display_three {   sub display_three { 
     my ($r,$uname,$fn,$page,$textref,$qcount) = @_;      my ($r,$uname,$fn,$page,$textref,$qcount) = @_;
     my $qnumformat = $ENV{'form.qnumformat'};      my $qnumformat = $env{'form.qnumformat'};
     my $filename = $ENV{'form.filename'};      my $filename = $env{'form.filename'};
     my $source = $ENV{'form.go'};      my $source = $env{'form.go'};
     my $blocks = $ENV{'form.blocks'};      my $blocks = $env{'form.blocks'};
     my @items = ();      my @items = ();
     my @bgcolors = ('#ffffff','#eeeeee');      my @bgcolors = ('#ffffff','#eeeeee');
     my @types = ("MC","MA","TF","Ess","FIB","Ord");      my @types = ("MC","MA","TF","Ess","FIB","Ord");
Line 850  sub display_three { Line 892  sub display_three {
     my %multparts = ();      my %multparts = ();
     my $numitems = 0;      my $numitems = 0;
     for (my $i=0; $i<$blocks; $i++) {      for (my $i=0; $i<$blocks; $i++) {
         if (($ENV{"form.start_$i"} ne '') && ($ENV{"form.end_$i"} ne '')) {          if (($env{"form.start_$i"} ne '') && ($env{"form.end_$i"} ne '')) {
             $start[$i] = $ENV{"form.start_$i"};              $start[$i] = $env{"form.start_$i"};
             $end[$i] = $ENV{"form.end_$i"};              $end[$i] = $env{"form.end_$i"};
             $nums[$i] = $end[$i]-$start[$i] +1;              $nums[$i] = $end[$i]-$start[$i] +1;
             $qtype[$i] = $ENV{"form.qtype_$i"};              $qtype[$i] = $env{"form.qtype_$i"};
             if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {              if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
                 $foilformats[$i] = $ENV{"form.foilformat_$i"};                  $foilformats[$i] = $env{"form.foilformat_$i"};
             } else {              } else {
                 $foilformats[$i] = '';                  $foilformats[$i] = '';
             }               } 
             if (($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "TF") || ($qtype[$i] eq "Ord")) {              if (($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "TF") || ($qtype[$i] eq "Ord")) {
                 $ansrtypes[$i] = $ENV{"form.ansr_$i"};                  $ansrtypes[$i] = $env{"form.ansr_$i"};
             } else {              } else {
                 $ansrtypes[$i] = '';                  $ansrtypes[$i] = '';
             }                }  
Line 924  END_OF_ONE Line 966  END_OF_ONE
                                     $foiltag = $alphabet[$k-1].'.';                                       $foiltag = $alphabet[$k-1].'.'; 
                                 } elsif ($foilformats[$i] eq "lcparen") {                                  } elsif ($foilformats[$i] eq "lcparen") {
                                     $foiltag = '('.$alphabet[$k-1].')';                                      $foiltag = '('.$alphabet[$k-1].')';
                                   } elsif ($foilformats[$i] eq "lconeparen") {
                                       $foiltag = $alphabet[$k-1].')';
                                   } elsif ($foilformats[$i] eq "lcdotparen") {
                                       $foiltag = $alphabet[$k-1].'.)';
                                 } elsif ($foilformats[$i] eq "ucperiod") {                                  } elsif ($foilformats[$i] eq "ucperiod") {
                                     $foiltag = $alphabet[$k-1].'.';                                      $foiltag = $alphabet[$k-1].'.';
                                     $foiltag =~ tr/a-z/A-Z/;                                      $foiltag =~ tr/a-z/A-Z/;
                                 } elsif ($foilformats[$i] eq "ucparen") {                                  } elsif ($foilformats[$i] eq "ucparen") {
                                     $foiltag = '('.$alphabet[$k-1].')';                                      $foiltag = '('.$alphabet[$k-1].')';
                                     $foiltag =~ tr/a-z/A-Z/;                                      $foiltag =~ tr/a-z/A-Z/;
                                   } elsif ($foilformats[$i] eq "uconeparen") {
                                       $foiltag = $alphabet[$k-1].')';
                                       $foiltag =~ tr/a-z/A-Z/;
                                   } elsif ($foilformats[$i] eq "ucdotparen") {
                                       $foiltag = $alphabet[$k-1].'.)';
                                       $foiltag =~ tr/a-z/A-Z/;
                                 } elsif ($foilformats[$i] eq "romperiod") {                                  } elsif ($foilformats[$i] eq "romperiod") {
                                     $foiltag = $romans[$k-1].'.';                                      $foiltag = $romans[$k-1].'.';
                                 } elsif ($foilformats[$i] eq "romparen") {                                  } elsif ($foilformats[$i] eq "romparen") {
                                     $foiltag = '('.$romans[$k-1].')';                                      $foiltag = '('.$romans[$k-1].')';
                                 }                                  } elsif ($foilformats[$i] eq "romoneparen") {
                                       $foiltag = $romans[$k-1].')';
                                   } elsif ($foilformats[$i] eq "romdotparen") {
                                       $foiltag = $romans[$k-1].'.)';
                                   } 
                                 $r->print(qq|$foiltag $multparts{$j}[$k]<br>\n|);                                  $r->print(qq|$foiltag $multparts{$j}[$k]<br>\n|);
                             }                              }
                         }                          }
Line 1045  Please choose a destination LON-CAPA dir Line 1101  Please choose a destination LON-CAPA dir
 # ---------------------------------------------------------------- Final Display  # ---------------------------------------------------------------- Final Display
 sub final_display {  sub final_display {
     my ($r,$uname,$fn,$page,$textref) = @_;      my ($r,$uname,$fn,$page,$textref) = @_;
     my $qnumformat = $ENV{'form.qnumformat'};      my $qnumformat = $env{'form.qnumformat'};
     my $blocks = $ENV{'form.blocks'};      my $blocks = $env{'form.blocks'};
     my $newdir = $ENV{'form.newdir'};      my $newdir = $env{'form.newdir'};
     my $linkdir = $newdir;      my $linkdir = $newdir;
     if ($linkdir =~ m#^/home/$uname/public_html/(.+)$#) {      if ($linkdir =~ m#^/home/$uname/public_html/(.+)$#) {
         $linkdir = '/priv/'.$uname.'/'.$1;          $linkdir = '/priv/'.$uname.'/'.$1;
Line 1064  sub final_display { Line 1120  sub final_display {
     my %multparts = ();      my %multparts = ();
     my $numitems = 0;      my $numitems = 0;
     for (my $i=0; $i<$blocks; $i++) {      for (my $i=0; $i<$blocks; $i++) {
         $start[$i] = $ENV{"form.start_$i"};          $start[$i] = $env{"form.start_$i"};
         $end[$i] = $ENV{"form.end_$i"};          $end[$i] = $env{"form.end_$i"};
         if (($end[$i] - $start[$i]) >= 0) {          if (($end[$i] - $start[$i]) >= 0) {
             $nums[$i] = $end[$i] - $start[$i]+1;              $nums[$i] = $end[$i] - $start[$i]+1;
         } else {          } else {
             $nums[$i] = 0;              $nums[$i] = 0;
         }          }
         $qtype[$i] = $ENV{"form.qtype_$i"};          $qtype[$i] = $env{"form.qtype_$i"};
         if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {          if (($qtype[$i] eq "MC") || ($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
             $foilformats[$i] = $ENV{"form.foilformat_$i"};              $foilformats[$i] = $env{"form.foilformat_$i"};
         } else {          } else {
             $foilformats[$i] = '';              $foilformats[$i] = '';
         }          }
         if (($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "TF") || ($qtype[$i] eq "Ord")) {          if (($qtype[$i] eq "MA") || ($qtype[$i] eq "FIB") || ($qtype[$i] eq "TF") || ($qtype[$i] eq "Ord")) {
             $ansrtypes[$i] = $ENV{"form.ansr_$i"};              $ansrtypes[$i] = $env{"form.ansr_$i"};
         }          }
         $numitems += $nums[$i];          $numitems += $nums[$i];
     }      }
Line 1104  sub final_display { Line 1160  sub final_display {
                 for (my $k=$numitems+$start[$i]-1; $k<$numitems+$end[$i]; $k++) {                  for (my $k=$numitems+$start[$i]-1; $k<$numitems+$end[$i]; $k++) {
                     @{$answers{$k}} = ();                      @{$answers{$k}} = ();
                     if ($qtype[$i] eq "MC") {                      if ($qtype[$i] eq "MC") {
                         lc $items[$k];                          $items[$k] =~ tr/A-Z/a-z/;
                         $items[$k] =~ s/\W//g;                          $items[$k] =~ s/\W//g;
                         if ($foilformats[$i] eq "lcperiod" || $foilformats[$i] eq "lcparen" || $foilformats[$i] eq "ucparen" || $foilformats[$i] eq "ucperiod") {                          if ($foilformats[$i] eq "lcperiod" || $foilformats[$i] eq "lcparen" || $foilformats[$i] eq "lconeparen" || $foilformats[$i] eq "lcdotparen" || $foilformats[$i] eq "ucparen" || $foilformats[$i] eq "ucperiod" || $foilformats[$i] eq "uconeparen" || $foilformats[$i] eq "ucdotparen") {
                             for (my $j=0; $j<@alphabet; $j++) {                              for (my $j=0; $j<@alphabet; $j++) {
                                 if ($alphabet[$j] eq $items[$k]) {                                  if ($alphabet[$j] eq $items[$k]) {
                                     push @{$answers{$k}}, $j;                                      push @{$answers{$k}}, $j;
                                     last;                                      last;
                                 }                                  }
                             }                              }
                         } elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod")) {                          } elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod") || ($foilformats[$i] eq "romoneparen") || ($foilformats[$i] eq "romdotparen")) {
                             for (my $j=0; $j<@romans; $j++) {                              for (my $j=0; $j<@romans; $j++) {
                                 if ($romans[$j] eq $items[$k]) {                                  if ($romans[$j] eq $items[$k]) {
                                     push @{$answers{$k}}, $j;                                      push @{$answers{$k}}, $j;
Line 1122  sub final_display { Line 1178  sub final_display {
                             }                              }
                         }                          }
                     } elsif (($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {                      } elsif (($qtype[$i] eq "MA") || ($qtype[$i] eq "Ord")) {
                         lc $items[$k];                          $items[$k] =~ tr/A-Z/a-z/;
                         my @corrects = split/$patterns{$ansrtypes[$i]}/,$items[$k];                          my @corrects = split/$patterns{$ansrtypes[$i]}/,$items[$k];
                         foreach my $correct (@corrects) {                          foreach my $correct (@corrects) {
                             $correct =~s/\W//g;                              $correct =~s/\W//g;
Line 1133  sub final_display { Line 1189  sub final_display {
                                         last;                                          last;
                                     }                                      }
                                 }                                  }
                             } elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod")) {                              } elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod") || ($foilformats[$i] eq "romoneparen") || ($foilformats[$i] eq "romdotparen")) {
                                 for (my $j=0; $j<@romans; $j++) {                                  for (my $j=0; $j<@romans; $j++) {
                                     if ($romans[$j] eq $correct) {                                      if ($romans[$j] eq $correct) {
                                         push @{$answers{$k}}, $j;                                          push @{$answers{$k}}, $j;
Line 1292  END_OF_BLOCK Line 1348  END_OF_BLOCK
    </tr>     </tr>
   </table>    </table>
  </form>   </form>
 </body>  
 </html>  
 END_OF_FAIL  END_OF_FAIL
     return;      return;
   }    }
Line 1384  sub file_split { Line 1438  sub file_split {
     } elsif ($qnumformat eq "trailparen") {      } elsif ($qnumformat eq "trailparen") {
         $qpattern = '\d{1'.$numpat.'\)';          $qpattern = '\d{1'.$numpat.'\)';
     }      }
     my @questions = split/[\r\n\f]+\s?$qpattern\s?/,$text_in;      my @questions = split/[\r\n\f]+\s*$qpattern\s*/,$text_in;
 # my @questions = split/\n\s\d{1,3}\.\s/,$text_in;  # my @questions = split/\n\s\d{1,3}\.\s/,$text_in;
     shift @questions;      shift @questions;
     my %multparts = ();      my %multparts = ();
Line 1396  sub file_split { Line 1450  sub file_split {
                     $splitstr = '[a-z]\.';                      $splitstr = '[a-z]\.';
                 } elsif (${$foilsref}[$i] eq "lcparen") {                  } elsif (${$foilsref}[$i] eq "lcparen") {
                     $splitstr = '\([a-z]\)';                      $splitstr = '\([a-z]\)';
                   } elsif (${$foilsref}[$i] eq "lconeparen") {
                       $splitstr = '[a-z]\)';
                   } elsif (${$foilsref}[$i] eq "lcdotparen") {
                       $splitstr = '[a-z]\.\)';
                 } elsif (${$foilsref}[$i] eq "ucperiod") {                  } elsif (${$foilsref}[$i] eq "ucperiod") {
                     $splitstr = '[A-Z]\.';                      $splitstr = '[A-Z]\.';
                 } elsif (${$foilsref}[$i] eq "ucparen") {                  } elsif (${$foilsref}[$i] eq "ucparen") {
                     $splitstr = '\([A-Z]\)';                      $splitstr = '\([A-Z]\)';
                   } elsif (${$foilsref}[$i] eq "uconeparen") {
                       $splitstr = '[A-Z]\)';
                   } elsif (${$foilsref}[$i] eq "ucdotparen") {
                       $splitstr = '[A-Z]\.\)';
                 } elsif (${$foilsref}[$i] eq "romperiod") {                  } elsif (${$foilsref}[$i] eq "romperiod") {
                     $splitstr = '[ivx]+\.';                      $splitstr = '[ivx]+\.';
                 } elsif (${$foilsref}[$i] eq "romparen") {                  } elsif (${$foilsref}[$i] eq "romparen") {
                     $splitstr = '\([ivx]+\)';                      $splitstr = '\([ivx]+\)';
                   } elsif (${$foilsref}[$i] eq "romoneparen") {
                       $splitstr = '[ivx]+\)';
                   } elsif (${$foilsref}[$i] eq "romdotparen") {
                       $splitstr = '[ivx]+\.\)';
                 }                  }
                 for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) {                  for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) {
                     @{$multparts{$j}} = split/[\r\n\f]+\s?$splitstr\s?/,$questions[$j];                      @{$multparts{$j}} = split/[\r\n\f]+\s*$splitstr\s*/,$questions[$j];
                     chomp(@{$multparts{$j}});                      chomp(@{$multparts{$j}});
                     foreach my $foil (@{$multparts{$j}}) {  
                     }   
                 }                  }
             } elsif (${$qtyperef}[$i] eq "FIB") {               } elsif (${$qtyperef}[$i] eq "FIB") { 
                 for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) {                  for (my $j=${$startsref}[$i]-1; $j<${$endsref}[$i]; $j++) {
Line 1646  sub handler { Line 1710  sub handler {
 #  #
 # phase two: re-attach user  # phase two: re-attach user
 #  #
     if ($ENV{'form.uploaduname'}) {      if ($env{'form.uploaduname'}) {
         $ENV{'form.filename'}='/priv/'.$ENV{'form.uploaduname'}.'/'.          $env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'.
             $ENV{'form.filename'};              $env{'form.filename'};
     }      }
     ($uname,$udom)=      ($uname,$udom)=
         &Apache::loncacc::constructaccess($ENV{'form.filename'},          &Apache::loncacc::constructaccess($env{'form.filename'},
                                           $r->dir_config('lonDefDomain'));                                            $r->dir_config('lonDefDomain'));
     unless (($uname) && ($udom)) {      unless (($uname) && ($udom)) {
         $r->log_reason($uname.' at '.$udom.          $r->log_reason($uname.' at '.$udom.
                        ' trying to publish file '.$ENV{'form.filename'}.                         ' trying to publish file '.$env{'form.filename'}.
                        ' - not authorized',                         ' - not authorized',
                        $r->filename);                         $r->filename);
         return HTTP_NOT_ACCEPTABLE;          return HTTP_NOT_ACCEPTABLE;
Line 1663  sub handler { Line 1727  sub handler {
                                                                                                                                                             
     my $fn;      my $fn;
     my $badfile = 0;      my $badfile = 0;
     if ($ENV{'form.filename'}) {      if ($env{'form.filename'}) {
         $fn=$ENV{'form.filename'};          $fn=$env{'form.filename'};
         $fn=~s/^http\:\/\/[^\/]+\///;          $fn=~s/^http\:\/\/[^\/]+\///;
         $fn=~s/^\///;          $fn=~s/^\///;
         $fn=~s/(\~|priv\/)(\w+)//;          $fn=~s/(\~|priv\/)(\w+)//;
         $fn=~s/\/+/\//g;          $fn=~s/\/+/\//g;
     } else {      } else {
         $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.          $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
                        ' unspecified filename for upload', $r->filename);                         ' unspecified filename for upload', $r->filename);
         return HTTP_NOT_FOUND;          return HTTP_NOT_FOUND;
     }      }
Line 1684  sub handler { Line 1748  sub handler {
   
     my @text = ();      my @text = ();
     my $loadentries = '';      my $loadentries = '';
     if ($ENV{'form.phase'} eq 'three') {          if ($env{'form.phase'} eq 'three') {    
         if (-e "$dirpath$fn") {          if (-e "$dirpath$fn") {
             open(TESTBANK,"<$dirpath$fn");              open(TESTBANK,"<$dirpath$fn");
             @text = <TESTBANK>;              @text = <TESTBANK>;
Line 1698  sub handler { Line 1762  sub handler {
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
   
     if ($ENV{'form.phase'} eq 'three') {      if ($env{'form.phase'} eq 'three') {
         $current_page = &display_control();          $current_page = &display_control();
         my @PAGES = ('Welcome','Blocks','Format','Target','Confirmation');          my @PAGES = ('Welcome','Blocks','Format','Target','Confirmation');
         $page_name = $PAGES[$current_page];          $page_name = $PAGES[$current_page];
Line 1707  sub handler { Line 1771  sub handler {
             $loadentries = 'onLoad= "setElements()"';              $loadentries = 'onLoad= "setElements()"';
             &jscript_one(\$javascript);              &jscript_one(\$javascript);
         } elsif ($page_name eq 'Format') {           } elsif ($page_name eq 'Format') { 
             $qcount = question_count($ENV{'form.qnumformat'},\@text);              $qcount = question_count($env{'form.qnumformat'},\@text);
      &jscript_two(\$javascript,$qcount);       &jscript_two(\$javascript,$qcount);
          } elsif ($page_name eq 'Target') {           } elsif ($page_name eq 'Target') {
              if ($ENV{'form.go'} eq "PreviousPage") {               if ($env{'form.go'} eq "PreviousPage") {
                  $loadentries =  'onLoad = "setElements()"';                   $loadentries =  'onLoad = "setElements()"';
       }        }
      &jscript_three($fullpath,\$javascript);       &jscript_three($fullpath,\$javascript);
         } elsif ($page_name eq 'Confirmation') {          } elsif ($page_name eq 'Confirmation') {
     &jscript_four(\$javascript,$fullpath);      &jscript_four(\$javascript,$fullpath);
         }          }
     }                                                                                      }
   
       $javascript = "<script type=\"text/javascript\">\n//<!--\n".
    $javascript."\n// --></script>\n";
   
       $r->print(&Apache::loncommon::start_page('Upload testbank questions to Construction Space',
        $javascript,
        {'add_entries' => $loadentries}));
   
     $r->print("<html><head><title>LON-CAPA Construction Space</title><script type=\"text/javascript\">\n//<!--\n$javascript\n// --></script>\n</head>");      if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                                                                                     
     $r->print(&Apache::loncommon::bodytag('Upload testbank questions to Construction Space',undef,$loadentries));  
                                                                                     
     if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {  
         $r->print('<h3><font color=red>'.&mt('Co-Author').': '.$uname.          $r->print('<h3><font color=red>'.&mt('Co-Author').': '.$uname.
                   &mt(' at ').$udom.'</font></h3>');                    &mt(' at ').$udom.'</font></h3>');
     }      }
   
     if ($ENV{'form.phase'} eq 'three') {      if ($env{'form.phase'} eq 'three') {
         if ($badfile) {          if ($badfile) {
             &file_error($r,$uname,$fn,$current_page);              &file_error($r,$uname,$fn,$current_page);
         } else {                  } else {        
Line 1738  sub handler { Line 1805  sub handler {
             &display_three ($r,$uname,$fn,$current_page,\@text,$qcount) if $page_name eq 'Target';              &display_three ($r,$uname,$fn,$current_page,\@text,$qcount) if $page_name eq 'Target';
             &final_display ($r,$uname,$fn,$current_page,\@text) if $page_name eq 'Confirmation';              &final_display ($r,$uname,$fn,$current_page,\@text) if $page_name eq 'Confirmation';
         }          }
     } elsif ($ENV{'form.phase'} eq 'two') {      } elsif ($env{'form.phase'} eq 'two') {
         my $flag = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'testbank');          my $flag = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'testbank');
         if ($flag eq 'ok') {          if ($flag eq 'ok') {
             my $current_page = 0;              my $current_page = 0;
Line 1747  sub handler { Line 1814  sub handler {
     } else {      } else {
         &Apache::lonupload::phaseone($r,$fn,$uname,$udom,'testbank');          &Apache::lonupload::phaseone($r,$fn,$uname,$udom,'testbank');
     }      }
     $r->print('</body></html>');      $r->print(&Apache::loncommon::end_page());
     return OK;      return OK;
 }  }
 1;  1;

Removed from v.1.2  
changed lines
  Added in v.1.8


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>