Diff for /loncom/interface/lonsource.pm between versions 1.12 and 1.19

version 1.12, 2005/06/23 23:07:04 version 1.19, 2007/08/28 22:23:22
Line 40  use Apache::lonmeta; Line 40  use Apache::lonmeta;
 use Apache::File;  use Apache::File;
 use Apache::lonlocal;  use Apache::lonlocal;
 use HTML::Entities;  use HTML::Entities;
   use LONCAPA;
   
 sub make_link {  sub make_link {
     my ($filename, $listname) = @_;      my ($filename, $listname) = @_;
     my $sourcelink = "/adm/source?filename=".$filename."&listname=".$listname;      my $sourcelink = "/adm/source?inhibitmenu=yes&filename=".$filename."&listname=".$listname;
   
     return $sourcelink;      return $sourcelink;
 }  }
Line 54  sub stage_2 { Line 55  sub stage_2 {
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     my ($uname, $udom) = &Apache::loncacc::constructaccess('/~'.$author.'/',$r->dir_config('lonDefDomain'));      my ($uname, $udom) = &Apache::loncacc::constructaccess('/~'.$author.'/',$r->dir_config('lonDefDomain'));
     $r->send_http_header;      $r->send_http_header;
     my $html=&Apache::lonxml::xmlbegin();      $r->print(&Apache::loncommon::start_page('Problem source code moving operation'));
     $r->print($html.'<head><title>LON-CAPA Move source to construction space</title>');  
     $r->print(&Apache::loncommon::bodytag('Problem source code moving operation'));  
     $r->print("Please enter the directory that you would like the source code to go into, a default has also been provided <br />");      $r->print("Please enter the directory that you would like the source code to go into, a default has also been provided <br />");
     $r->print("Also note, the path is in reference to the root of your construction space, and new directories will be automatically created. <br /><br />");      $r->print("Also note, the path is in reference to the root of your construction space, and new directories will be automatically created. <br /><br />");
     $r->print('<form name="copy" action="/adm/source/" target="_parent" method="post">      $r->print('<form name="copy" action="/adm/source" target="_parent" method="post">
               <input type="hidden" name="filename" value="'.$filename.'" />                <input type="hidden" name="filename" value="'.$filename.'" />
               <input type="hidden" name="listname" value="'.$listname.'" />                <input type="hidden" name="listname" value="'.$listname.'" />
               <input type="hidden" name="action" value="copy_stage" />                <input type="hidden" name="action" value="copy_stage" />
               <input type="text" name="newpath" value="/shared_source/'.$author.'" />&nbsp;                <input type="text" size="50" name="newpath" value="/shared_source/'.$author.'" />&nbsp;
               <input type="submit" value="Copy" />                <input type="submit" value="Copy" />
               </form>');                </form>');
     return OK;      return OK;
Line 77  sub copy_stage { Line 76  sub copy_stage {
     my $author_name;      my $author_name;
 #Figure out if we are author or co-author  #Figure out if we are author or co-author
   
     if($env{'request.role'} =~ m|ca.|) {      if ($env{'request.role'} =~ m{^ca\.}) {
         ($role, $domain, $author_name) = split(/\//,$env{'request.role'});          ($role, $domain, $author_name) = split(/\//,$env{'request.role'});
     } else {      } else {
         $role = "au.";          $role = "au.";
Line 94  sub copy_stage { Line 93  sub copy_stage {
     }      }
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $r->send_http_header;
     my $html=&Apache::lonxml::xmlbegin();      $r->print(&Apache::loncommon::start_page('Copying Source'));
     $r->print($html.'<head><title>LON-CAPA Move source to construction space</title>');  
     $r->print(&Apache::loncommon::bodytag('Copying Source'));  
     my $result = &Apache::loncfile::exists($uname, $udom, $path_to_new_file);      my $result = &Apache::loncfile::exists($uname, $udom, $path_to_new_file);
     $r->print($result);      $r->print($result);
     if(($result) && ($result =~ m|published|) ) {      if(($result) && ($result =~ m|published|) ) {
Line 114  sub copy_stage { Line 111  sub copy_stage {
 sub confirm {  sub confirm {
     my ($r, $author_name, $newpath, $filename, $path_to_new_file) = @_;      my ($r, $author_name, $newpath, $filename, $path_to_new_file) = @_;
     $r->print("<b>Press delete to remove file and replace it with a copy of the source you are viewing</b><br /><br / >");      $r->print("<b>Press delete to remove file and replace it with a copy of the source you are viewing</b><br /><br / >");
     $r->print('<form name="delete_confirm" action="/adm/source/" target="_parent" method="post">      $r->print('<form name="delete_confirm" action="/adm/source" target="_parent" method="post">
               <input type="hidden" name="filename" value="'.$filename.'" />                <input type="hidden" name="filename" value="'.$filename.'" />
               <input type="hidden" name="path" value="'.$path_to_new_file.'" />                <input type="hidden" name="path" value="'.$path_to_new_file.'" />
               <input type="hidden" name="author" value="'.$author_name.'" />                <input type="hidden" name="author" value="'.$author_name.'" />
Line 170  sub copy_file { Line 167  sub copy_file {
     }      }
     $r->print("<br /><b>Copying File</b>");      $r->print("<br /><b>Copying File</b>");
     my $problem_filename = $Apache::lonnet::perlvar{'lonDocRoot'}.$filename;      my $problem_filename = $Apache::lonnet::perlvar{'lonDocRoot'}.$filename;
     my $file_output = &Apache::lonnet::getfile($problem_filename);      my $file_output = &includemeta(&Apache::lonnet::getfile($problem_filename),$filename);
     my $fs=Apache::File->new(">$path_to_new_file");      my $fs=Apache::File->new(">$path_to_new_file");
     if (defined($fs)) {      if (defined($fs)) {
         print $fs $file_output;          print $fs $file_output;
Line 182  sub copy_file { Line 179  sub copy_file {
   
 sub print_item {  sub print_item {
     my ($r, $filename) = @_;      my ($r, $filename) = @_;
     $filename = $Apache::lonnet::perlvar{'lonDocRoot'}.$filename;      my $file_output = &includemeta(&Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$filename),$filename);
     &Apache::lonnet::logthis("print_item filename = $filename");  
     my $file_output = &Apache::lonnet::getfile($filename);  
     my $count=0;      my $count=0;
     my $maxlength=-1;      my $maxlength=-1;
     foreach (split ("\n", $file_output)) {      foreach (split ("\n", $file_output)) {
Line 202  sub print_item { Line 197  sub print_item {
   
 }  }
   
   sub includemeta {
       my ($file_output,$orgfilename)=@_;
       my $escfilename=&escape($orgfilename);
       my $copytime=time;
       if ($file_output=~/\<meta\s*name\=\"isbasedonres\"/i) {
    $file_output=~s/(\<meta\s*name\=\"isbasedonres\"\s*content\=\"[^\"]*)\"/$1\,\Q$escfilename\E\"/i;
       } else {
    $file_output=~s/(\<(?:html|problem)[^\>]*\>)/$1\n\<meta name=\"isbasedonres\" content=\"\Q$escfilename\E\" \/\>/i;
       }
       if ($file_output=~/\<meta\s*name\=\"isbasedontime\"/i) {
    $file_output=~s/(\<meta\s*name\=\"isbasedontime\"\s*content\=\"[^\"]*)\"/$1\,\Q$copytime\E\"/i;
       } else {
    $file_output=~s/(\<(?:html|problem)[^\>]*\>)/$1\n\<meta name=\"isbasedontime\" content=\"\Q$copytime\E\" \/\>/i;
       }
       return $file_output;
   }
   
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
Line 214  sub handler { Line 225  sub handler {
         $env{'user.error.msg'}="$filename:cre:1:1:Source code not available";          $env{'user.error.msg'}="$filename:cre:1:1:Source code not available";
         return HTTP_NOT_ACCEPTABLE;          return HTTP_NOT_ACCEPTABLE;
     }       } 
     if ((!&Apache::lonnet::allowed('cre',$filename)) ||      unless ((&Apache::lonnet::allowed('bre',$filename)) &&
             (!&Apache::lonnet::allowed('bre',$filename))) {      (&Apache::lonnet::allowed('cre','/'))) {
         $env{'user.error.msg'}="$filename:bre:1:1:Access to resource denied";          $env{'user.error.msg'}="$filename:bre:1:1:Access to resource denied";
         return HTTP_NOT_ACCEPTABLE;          return HTTP_NOT_ACCEPTABLE;
     }       } 
Line 232  sub handler { Line 243  sub handler {
     } else {      } else {
         &Apache::loncommon::content_type($r,'text/html');          &Apache::loncommon::content_type($r,'text/html');
         $r->send_http_header;          $r->send_http_header;
         $r->print('<form name="copy" action="/adm/source/" target="_parent" method="post">          $r->print('<form name="copy" action="/adm/source" target="_parent" method="post">
                   <input type="button" value="Close Window" name="close" onClick="window.close()" />                    <input type="button" value="Close Window" name="close" onClick="window.close()" />
                   <input type="hidden" name="filename" value="'.$filename.'" />                    <input type="hidden" name="filename" value="'.$filename.'" />
                   <input type="hidden" name="listname" value="'.$listname.'" />                    <input type="hidden" name="listname" value="'.$listname.'" />

Removed from v.1.12  
changed lines
  Added in v.1.19


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