Diff for /loncom/publisher/lonretrieve.pm between versions 1.26 and 1.31

version 1.26, 2005/01/05 17:38:27 version 1.31, 2006/09/13 21:43:26
Line 37  use Apache::Constants qw(:common :http : Line 37  use Apache::Constants qw(:common :http :
 use Apache::loncacc;  use Apache::loncacc;
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonlocal;  use Apache::lonlocal;
   use Apache::lonnet;
   
 # ------------------------------------ Interface for selecting previous version  # ------------------------------------ Interface for selecting previous version
 sub phaseone {  sub phaseone {
Line 50  sub phaseone { Line 51  sub phaseone {
     my $resdir=$resfn;      my $resdir=$resfn;
     $resdir=~s/\/[^\/]+$/\//;      $resdir=~s/\/[^\/]+$/\//;
   
     $fn=~/\/([^\/]+)\.(\w+)$/;      my ($main,$suffix,$is_meta) = &get_file_info($fn);
     my $main=$1;      
     my $suffix=$2;  
   
     if (-e $resfn) {        if (-e $resfn) {  
     $r->print('<form action=/adm/retrieve method=post>'.      $r->print('<form action=/adm/retrieve method=post>'.
       '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.        '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.
               '<input type=hidden name=phase value=two>'.                '<input type=hidden name=phase value=two>'.
               '<table border=2><tr><th>'.&mt('Select').'</th><th>'.                '<table border=2><tr><th>'.&mt('Select').'</th><th>'.
       &mt('Version').'</th>'.        &mt('Version').'</th>'.
               '<th>'.&mt('Published on ...').'</th>'.                '<th>'.&mt('Published on ...').'</th>');
               '<th>'.&mt('Metadata').'</th></tr>');      if (!$is_meta) {
     my $filename;   $r->print('<th>'.&mt('Metadata').'</th>');
       }
       if ($is_meta
    || &Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
    $r->print('<th>'.&mt('Diffs').'</th>');
       }
       $r->print('</tr>');
       
     opendir(DIR,$resdir);      opendir(DIR,$resdir);
     while ($filename=readdir(DIR)) {      my @files = grep(/^\Q$main\E\.(\d+)\.\Q$suffix\E$/,readdir(DIR));
       @files = sort {
    my ($aver) = ($a=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/);
    my ($bver) = ($b=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/);
    return $aver <=> $bver;
       } (@files);
       closedir(DIR);
   
       foreach my $filename (@files) {
         if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {          if ($filename=~/^\Q$main\E\.(\d+)\.\Q$suffix\E$/) {
    my $version=$1;     my $version=$1;
            my $rmtime=&Apache::lonnet::metadata($resdir.'/'.$filename,'lastrevisiondate');             my $rmtime=&Apache::lonnet::metadata($resdir.'/'.$filename,'lastrevisiondate');
            $r->print('<tr><td><input type=radio name=version value="'.             $r->print('<tr><td><input type=radio name=version value="'.
                      $version.'"></td><td>'.&mt('Previously published version').' '.$version.'</td><td>'.                       $version.'"></td><td>'.&mt('Previously published version').' '.$version.'</td><td>'.
                      localtime($rmtime).'</td><td>'.                       localtime($rmtime).'</td>');
                      '<a href="'.$urldir.$filename.'.meta" target=cat>'.       
                      &mt('Metadata Version').' '.$version.'</a>');     if (!$is_meta) {
            if (&Apache::loncommon::fileembstyle($suffix) eq 'ssi') {         $r->print('<td><a href="'.$urldir.$filename.'.meta" target=cat>'.
    &mt('Metadata Version').' '.$version.'</a></td>');
      }
              if ($is_meta
          || &Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
                $r->print(                 $r->print(
                     '&nbsp;&nbsp;<a target=cat href="/adm/diff?filename=/~'.                      '<td><a target=cat href="/adm/diff?filename=/~'.
                         $uname.$fn.                          $uname.$fn.
                         '&versiontwo=priv&versionone='.$version.                          '&versiontwo=priv&versionone='.$version.
                         '">'.&mt('Diffs with Version').' '.$version.'</a>');   '">'.&mt('Diffs with Version').' '.$version.
    '</a></td>');
            }             }
            $r->print('</a></td></tr>');             $r->print('</tr>');
         }          }
     }      }
     closedir(DIR);      closedir(DIR);
     my $rmtime=&Apache::lonnet::metadata($resfn,'lastrevisiondate');      my $rmtime=&Apache::lonnet::metadata($resfn,'lastrevisiondate');
     $r->print('<tr><td><input type=radio name=version value="new"></td>'.      $r->print('<tr><td><input type=radio name=version value="new"></td>'.
               '<th>'.&mt('Currently public version').'</th><td>'.localtime($rmtime).                '<th>'.&mt('Currently published version').'</th><td>'.localtime($rmtime).
            '</td><td><a href="'.$urldir.$main.'.'.$suffix.'.meta" target=cat>'.             '</td>');
               &mt('Metadata current version').'</a>');                 if (!$is_meta) {
            if (&Apache::loncommon::fileembstyle($suffix) eq 'ssi') {   $r->print('<td><a href="'.$urldir.$main.'.'.$suffix.'.meta" target=cat>'.
     &mt('Metadata current version').'</a></td>');           
       }
              if ($is_meta 
          || &Apache::loncommon::fileembstyle($suffix) eq 'ssi') {
                $r->print(                 $r->print(
                     '&nbsp;&nbsp;<a target=cat href="/adm/diff?filename=/~'.                      '<td><a target=cat href="/adm/diff?filename=/~'.
                         $uname.$fn.                          $uname.$fn.
                         '&versiontwo=priv'.                          '&versiontwo=priv'.
                         '">'.&mt('Diffs with current Version').'</a>');                          '">'.&mt('Diffs with current Version').'</a></td>');
            }             }
            $r->print('</td></tr></table><p>'.             $r->print('</tr></table><p>'.
            '<font size=+1 color=red>'.             '<font size=+1 color=red>'.
 &mt('Retrieval of an old version will overwrite the file currently in construction space').'</font><p>'.  &mt('Retrieval of an old version will overwrite the file currently in construction space').'</font><p>'.
            '<input type=submit value="'.&mt('Retrieve version').'"></form>');             '<input type=submit value="'.&mt('Retrieve version').'"></form>');
Line 110  sub phaseone { Line 133  sub phaseone {
 # ---------------------------------- Interface for presenting specified version  # ---------------------------------- Interface for presenting specified version
 sub phasetwo {  sub phasetwo {
     my ($r,$fn,$uname,$udom)=@_;      my ($r,$fn,$uname,$udom)=@_;
     if ($ENV{'form.version'}) {      if ($env{'form.version'}) {
         my $version=$ENV{'form.version'};          my $version=$env{'form.version'};
  if ($version eq 'new') {   if ($version eq 'new') {
     $r->print('<h3>'.&mt('Retrieving current (most recent) version').'</h3>');      $r->print('<h3>'.&mt('Retrieving current (most recent) version').'</h3>');
         } else {          } else {
             $r->print('<h3>'.&mt('Retrieving old version').' '.$version.'</h3>');              $r->print('<h3>'.&mt('Retrieving old version').' '.$version.'</h3>');
         }          }
    my ($main,$suffix,$is_meta) = &get_file_info($fn);
   
         my $logfile;          my $logfile;
         my $ctarget='/home/'.$uname.'/public_html'.$fn;          my $ctarget='/home/'.$uname.'/public_html'.$fn;
         my $vfn=$fn;          my $vfn=$fn;
         if ($version ne 'new') {          if ($version ne 'new') {
     $vfn=~s/\.(\w+)$/\.$version\.$1/;      $vfn=~s/\.(\Q$suffix\E)$/\.$version\.$1/;
         }          }
   
         my $csource=$r->dir_config('lonDocRoot').'/res/'.$udom.'/'.$uname.$vfn;          my $csource=$r->dir_config('lonDocRoot').'/res/'.$udom.'/'.$uname.$vfn;
         unless ($logfile=Apache::File->new('>>'.$ctarget.'.log')) {  
    my $logname = $ctarget;
    if ($is_meta) { $logname =~ s/\.meta$//; }
    $logname = $ctarget.'.log';
           unless ($logfile=Apache::File->new('>>'.$logname)) {
   $r->print(    $r->print(
          '<font color=red>'.&mt('No write permission to user directory, FAIL').'</font>');           '<font color=red>'.&mt('No write permission to user directory, FAIL').'</font>');
         }          }
Line 132  sub phasetwo { Line 162  sub phasetwo {
 "\n\n================= Retrieve ".localtime()." ================\n".  "\n\n================= Retrieve ".localtime()." ================\n".
 "Version: $version\nSource: $csource\nTarget: $ctarget\n";  "Version: $version\nSource: $csource\nTarget: $ctarget\n";
         $r->print('<p>'.&mt('Copying file').': ');          $r->print('<p>'.&mt('Copying file').': ');
         if (copy($csource,$ctarget)) {   if (copy($csource,$ctarget)) {
     $r->print('ok<p>');      $r->print('ok<p>');
             print $logfile "Copied sucessfully.\n\n";              print $logfile "Copied sucessfully.\n\n";
         } else {          } else {
Line 149  sub phasetwo { Line 179  sub phasetwo {
     }      }
 }  }
   
   sub get_file_info {
       my ($fn) = @_;
       my ($main,$suffix) = ($fn=~/\/([^\/]+)\.(\w+)$/);
       my $is_meta=0;
       if ($suffix eq 'meta') {
    $is_meta = 1;
    ($main,$suffix) = ($main=~/(.+)\.(\w+)$/);    
    $suffix .= '.meta';
       }
       return ($main,$suffix,$is_meta);
   }
   
 # ---------------------------------------------------------------- Main Handler  # ---------------------------------------------------------------- Main Handler
 sub handler {  sub handler {
   
Line 162  sub handler { Line 204  sub handler {
   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   ['filename']);    ['filename']);
   
   if ($ENV{'form.filename'}) {    if ($env{'form.filename'}) {
       $fn=$ENV{'form.filename'};        $fn=$env{'form.filename'};
       $fn=~s/^http\:\/\/[^\/]+//;        $fn=~s/^http\:\/\/[^\/]+//;
   } 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 retrieval', $r->filename);            ' unspecified filename for retrieval', $r->filename); 
      return HTTP_NOT_FOUND;       return HTTP_NOT_FOUND;
   }    }
   
   unless ($fn) {     unless ($fn) { 
      $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.       $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
          ' trying to retrieve non-existing file', $r->filename);            ' trying to retrieve non-existing file', $r->filename); 
      return HTTP_NOT_FOUND;       return HTTP_NOT_FOUND;
   }     } 
Line 185  sub handler { Line 227  sub handler {
     &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));      &Apache::loncacc::constructaccess($fn,$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'}.
          ' ('.$fn.') - not authorized',            ' ('.$fn.') - not authorized', 
          $r->filename);            $r->filename); 
      return HTTP_NOT_ACCEPTABLE;       return HTTP_NOT_ACCEPTABLE;
Line 196  sub handler { Line 238  sub handler {
   &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></head>');    $r->print(&Apache::loncommon::start_page('Retrieve Published Resources'));
   
   $r->print(&Apache::loncommon::bodytag('Retrieve Published Resources'));  
   
       
   $r->print('<h1>'.&mt('Retrieve previous versions of').' <tt>'.$fn.'</tt></h1>');    $r->print('<h1>'.&mt('Retrieve previous versions of').' <tt>'.$fn.'</tt></h1>');
       
   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.      &mt(' at ').$udom.
                '</font></h3>');                 '</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.26  
changed lines
  Added in v.1.31


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