Diff for /loncom/publisher/lonupload.pm between versions 1.28 and 1.32

version 1.28, 2004/12/07 22:11:02 version 1.32, 2006/04/10 22:30:31
Line 37  use File::Basename; Line 37  use File::Basename;
 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::lonnet;
   
 my $DEBUG=0;  my $DEBUG=0;
   
 sub Debug {  sub Debug {
         # Put out the indicated message but only if DEBUG is true.
     # Marshall the parameters.  
     
     my $r       = shift;  
     my $log     = $r->log;  
     my $message = shift;  
     
     # Put out the indicated message butonly if DEBUG is false.  
     
     if ($DEBUG) {      if ($DEBUG) {
  $log->debug($message);   my ($r,$message) = @_;
    $r->log_reason($message);
     }      }
 }  }
   
 sub upfile_store {  sub upfile_store {
     my $r=shift;      my $r=shift;
   
     my $fname=$ENV{'form.upfile.filename'};      my $fname=$env{'form.upfile.filename'};
     $fname=~s/\W//g;      $fname=~s/\W//g;
           
     chomp($ENV{'form.upfile'});      chomp($env{'form.upfile'});
       
     my $datatoken=$ENV{'user.name'}.'_'.$ENV{'user.domain'}.      my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
   '_upload_'.$fname.'_'.time.'_'.$$;    '_upload_'.$fname.'_'.time.'_'.$$;
     {      {
        my $fh=Apache::File->new('>'.$r->dir_config('lonDaemons').         my $fh=Apache::File->new('>'.$r->dir_config('lonDaemons').
                                    '/tmp/'.$datatoken.'.tmp');                                     '/tmp/'.$datatoken.'.tmp');
        print $fh $ENV{'form.upfile'};         print $fh $env{'form.upfile'};
     }      }
     return $datatoken;      return $datatoken;
 }  }
Line 86  sub phaseone { Line 79  sub phaseone {
     } elsif ($mode eq 'imsimport') {      } elsif ($mode eq 'imsimport') {
         $action = '/adm/imsimport';          $action = '/adm/imsimport';
     }      }
     $ENV{'form.upfile.filename'}=~s/\\/\//g;      $env{'form.upfile.filename'}=~s/\\/\//g;
     $ENV{'form.upfile.filename'}=~s/^.*\/([^\/]+)$/$1/;      $env{'form.upfile.filename'}=~s/^.*\/([^\/]+)$/$1/;
     if ($ENV{'form.upfile.filename'}) {      if ($env{'form.upfile.filename'}) {
  $fn=~s/\/[^\/]+$//;   $fn=~s/\/[^\/]+$//;
  $fn=~s/([^\/])$/$1\//;   $fn=~s/([^\/])$/$1\//;
  $fn.=$ENV{'form.upfile.filename'};   $fn.=$env{'form.upfile.filename'};
  $fn=~s/^\///;   $fn=~s/^\///;
  $fn=~s/(\/)+/\//g;   $fn=~s/(\/)+/\//g;
   
Line 168  sub phasetwo { Line 161  sub phasetwo {
  $base    = &HTML::Entities::encode($base,'<>&"');   $base    = &HTML::Entities::encode($base,'<>&"');
  my $url  = $path."/".$base;    my $url  = $path."/".$base; 
  &Debug($r, "URL is now ".$url);   &Debug($r, "URL is now ".$url);
  my $datatoken=$ENV{'form.datatoken'};   my $datatoken=$env{'form.datatoken'};
  if (($fn) && ($datatoken)) {   if (($fn) && ($datatoken)) {
     if ((-e $target) && ($ENV{'form.override'} ne 'Yes')) {      if ((-e $target) && ($env{'form.override'} ne 'Yes')) {
  $r->print('<form action="'.$action.'" method="post">'.   $r->print('<form action="'.$action.'" method="post">'.
   &mt('File').' <tt>'.$fn.'</tt> '.    &mt('File').' <tt>'.$fn.'</tt> '.
   &mt('exists. Overwrite?').' '.    &mt('exists. Overwrite?').' '.
Line 250  sub handler { Line 243  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'};
     }      }
   
       unless ($env{'form.phase'} eq 'two') {
    my %body_layout = ('rightmargin'  => "0",
      'leftmargin'   => "0",
      'marginwidth'  => "0",
      'topmargin'    => "0",
      'marginheight' => "0");
    my $start_page = 
       &Apache::loncommon::start_page('Importing a Testbank file into LON-CAPA',
      undef,
      {'only_body'   => 1,
       'add_entries' => \%body_layout,
       'js_ready'    => 1,});
    my $end_page = 
       &Apache::loncommon::end_page({'js_ready' => 1,});
   
     unless ($ENV{'form.phase'} eq 'two') {  
         $javascript = qq|          $javascript = qq|
 function verifyForm() {  function verifyForm() {
     var mode = document.fileupload.filetype.options[document.fileupload.filetype.selectedIndex].value      var mode = document.fileupload.filetype.options[document.fileupload.filetype.selectedIndex].value
Line 274  function verifyForm() { Line 281  function verifyForm() {
 function testbankWin() {  function testbankWin() {
   newWindow = window.open("","testbankinfo","HEIGHT=400,WIDTH=750,scrollbars=yes")    newWindow = window.open("","testbankinfo","HEIGHT=400,WIDTH=750,scrollbars=yes")
   newWindow.document.open()    newWindow.document.open()
   newWindow.document.write("<html><head><title>'Importing a Testbank file into LON-CAPA</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='95%' bgcolor='#CCFFDD'>\\n")    newWindow.document.write("<table border='0' cellspacing='0' cellpadding='0' width='95%' 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 287  function testbankWin() { Line 293  function testbankWin() {
     newWindow.document.write("<li><i>Multiple choice</i> and <i>multiple answer correct</i> questions should consist of (i) the question number followed by (ii) a question stem beginning on the same line and (iii) two or more foils, with each foil beginning on a new line and prefixed by a unique letter, or Roman numeral, listed in alphabetic or numeric order, beginning at a (alphabetic) or i (Roman numeral), followed by a period, or enclosed in parentheses, i.e., a., (a), i., or (i) .</li>")      newWindow.document.write("<li><i>Multiple choice</i> and <i>multiple answer correct</i> questions should consist of (i) the question number followed by (ii) a question stem beginning on the same line and (iii) two or more foils, with each foil beginning on a new line and prefixed by a unique letter, or Roman numeral, listed in alphabetic or numeric order, beginning at a (alphabetic) or i (Roman numeral), followed by a period, or enclosed in parentheses, i.e., a., (a), i., or (i) .</li>")
      newWindow.document.write("<li>If <i>fill-in-the-blank</i> or <i>multiple answer</i> questions have more than one correct answer, each answer should appear in a comma-, tab-, space-, or new line-delimited list. </li></ol>")       newWindow.document.write("<li>If <i>fill-in-the-blank</i> or <i>multiple answer</i> questions have more than one correct answer, each answer should appear in a comma-, tab-, space-, or new line-delimited list. </li></ol>")
   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()
 }  }
 |;  |;
     }      }
     ($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;
     }      }
           
     my $fn;      my $fn;
     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 323  function testbankWin() { Line 330  function testbankWin() {
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
   
     $r->print("<html><head><title>LON-CAPA Construction Space</title><script type=\"text/javascript\">\n//<!--\n$javascript\n// --></script>\n</head>");     $javascript = "<script type=\"text/javascript\">\n//<!--\n".
    $javascript."\n// --></script>\n";
   
     $r->print(&Apache::loncommon::bodytag('Upload file to Construction Space'));      $r->print(&Apache::loncommon::start_page('Upload file to Construction Space',
        $javascript));
       
     if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {      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 'two') {      if ($env{'form.phase'} eq 'two') {
  &phasetwo($r,$fn,$uname,$udom);   &phasetwo($r,$fn,$uname,$udom);
     } else {      } else {
  &phaseone($r,$fn,$uname,$udom);   &phaseone($r,$fn,$uname,$udom);
     }      }
   
     $r->print('</body></html>');      $r->print(&Apache::loncommon::end_page());
     return OK;        return OK;  
 }  }
   

Removed from v.1.28  
changed lines
  Added in v.1.32


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