Diff for /loncom/interface/lonmeta.pm between versions 1.18 and 1.28

version 1.18, 2002/08/26 17:02:47 version 1.28, 2003/03/14 19:29:36
Line 37  use strict; Line 37  use strict;
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::lonnet();  use Apache::lonnet();
 use Apache::loncommon();  use Apache::loncommon();
   use Apache::lonmsg;
   use Apache::lonpublisher;
   
 # ----------------------------------------- Fetch and evaluate dynamic metadata  # ----------------------------------------- Fetch and evaluate dynamic metadata
   
Line 44  sub dynamicmeta { Line 46  sub dynamicmeta {
     my $url=&Apache::lonnet::declutter(shift);      my $url=&Apache::lonnet::declutter(shift);
     $url=~s/\.meta$//;      $url=~s/\.meta$//;
     my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);      my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
     my $regexp=&Apache::lonnet::escape($url);      my $regexp=$url;
     $regexp=~s/(\W)/\\$1/g;      $regexp=~s/(\W)/\\$1/g;
     $regexp='___'.$regexp.'___';      $regexp='___'.$regexp.'___';
     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,      my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
Line 96  sub dynamicmeta { Line 98  sub dynamicmeta {
     return %returnhash;      return %returnhash;
 }  }
   
   # ------------------------------------- Try to make an alt tag if there is none
   
   sub alttag {
       my ($base,$src)=@_;
       my $fullpath=&Apache::lonnet::hreflocation($base,$src);
       my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
                  &Apache::lonnet::metadata($fullpath,'subject').' '.
                  &Apache::lonnet::metadata($fullpath,'abstract');
       $alttag=~s/\s+/ /gs;
       $alttag=~s/\"//gs;
       $alttag=~s/\'//gs;
       $alttag=~s/\s+$//gs;
       $alttag=~s/^\s+//gs;
       if ($alttag) { return $alttag; } else 
                    { return 'No information available'; }
   }
   
 # -------------------------------------------------------------- Pretty display  # -------------------------------------------------------------- Pretty display
   
 sub evalgraph {  sub evalgraph {
Line 142  sub diffgraph { Line 161  sub diffgraph {
   
 sub handler {  sub handler {
   my $r=shift;    my $r=shift;
   
       my $loaderror=&Apache::lonnet::overloaderror($r);
       if ($loaderror) { return $loaderror; }
   
   
       my $uri=$r->uri;
   
     unless ($uri=~/^\/\~/) { 
   # =========================================== This is not in construction space
       my ($resdomain,$resuser)=
              (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
   
       $loaderror=
          &Apache::lonnet::overloaderror($r,
            &Apache::lonnet::homeserver($resuser,$resdomain));
       if ($loaderror) { return $loaderror; }
   
   my %content=();    my %content=();
   
 # ----------------------------------------------------------- Set document type  # ----------------------------------------------------------- Set document type
Line 152  sub handler { Line 188  sub handler {
   return OK if $r->header_only;    return OK if $r->header_only;
   
 # ------------------------------------------------------------------- Read file  # ------------------------------------------------------------------- Read file
   
   my $uri=$r->uri;  
   foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {    foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
       $content{$_}=&Apache::lonnet::metadata($uri,$_);        $content{$_}=&Apache::lonnet::metadata($uri,$_);
   }    }
   my ($resdomain)=(&Apache::lonnet::declutter($uri)=~/^(\w+)\//);  
 # ------------------------------------------------------------------ Hide stuff  # ------------------------------------------------------------------ Hide stuff
   
   unless ($ENV{'user.adv'}) {    unless ($ENV{'user.adv'}) {
Line 167  sub handler { Line 200  sub handler {
   }    }
   
 # --------------------------------------------------------------- Render Output  # --------------------------------------------------------------- Render Output
     my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
 my $creationdate=localtime($content{'creationdate'});  my $creationdate=localtime(
 my $lastrevisiondate=localtime($content{'lastrevisiondate'});   &Apache::loncommon::unsqltime($content{'creationdate'}));
   my $lastrevisiondate=localtime(
    &Apache::loncommon::unsqltime($content{'lastrevisiondate'}));
 my $language=&Apache::loncommon::languagedescription($content{'language'});  my $language=&Apache::loncommon::languagedescription($content{'language'});
 my $mime=&Apache::loncommon::filedescription($content{'mime'});   my $mime=&Apache::loncommon::filedescription($content{'mime'}); 
 my $disuri=&Apache::lonnet::declutter($uri);  my $disuri=&Apache::lonnet::declutter($uri);
   $disuri=~s/\.meta$//;    $disuri=~s/\.meta$//;
   my $currentversion=&Apache::lonnet::getversion($disuri);
   my $versiondisplay='';
   if ($thisversion) {
       $versiondisplay='Version: '.$thisversion.
       ' (most recent version: '.$currentversion.')';
   } else {
       $versiondisplay='Version: '.$currentversion;
   }
 my $bodytag=&Apache::loncommon::bodytag  my $bodytag=&Apache::loncommon::bodytag
             ('Catalog Information','','','',$resdomain);              ('Catalog Information','','','',$resdomain);
   $r->print(<<ENDHEAD);    $r->print(<<ENDHEAD);
Line 181  my $bodytag=&Apache::loncommon::bodytag Line 224  my $bodytag=&Apache::loncommon::bodytag
 $bodytag  $bodytag
 <h2>$content{'title'}</h2>  <h2>$content{'title'}</h2>
 <h3><tt>$disuri</tt></h3>  <h3><tt>$disuri</tt></h3>
   $versiondisplay<br />
 <table cellspacing=2 border=0>  <table cellspacing=2 border=0>
 <tr><td bgcolor='#AAAAAA'>Author(s)</td>  <tr><td bgcolor='#AAAAAA'>Author(s)</td>
 <td bgcolor="#CCCCCC">$content{'author'}&nbsp;</td></tr>  <td bgcolor="#CCCCCC">$content{'author'}&nbsp;</td></tr>
Line 271  $dynmeta{$_}."&nbsp;</td></tr>\n"); Line 315  $dynmeta{$_}."&nbsp;</td></tr>\n");
        || ($ENV{'user.role.ca./'.$1.'/'.$2})) {         || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
       $r->print(        $r->print(
   '<h4>Evaluation Comments (visible to author and co-authors only)</h4>'.    '<h4>Evaluation Comments (visible to author and co-authors only)</h4>'.
       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');              '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
         $r->print(
      '<h4>Error Messages (visible to author and co-authors only)</h4>');
         my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$1,$2);
         foreach (keys %errormsgs) {
    if ($_=~/^\Q$disuri\E\_\d+$/) {
             my %content=&Apache::lonmsg::unpackagemsg($errormsgs{$_});
     $r->print('<b>'.$content{'time'}.'</b>: '.$content{'message'}.
                       '<br />');
           }
         }      
    }     }
 # ------------------------------------------------------------- All other stuff  # ------------------------------------------------------------- All other stuff
    $r->print(     $r->print(
Line 294  $dynmeta{$_}."&nbsp;</td></tr>\n"); Line 348  $dynmeta{$_}."&nbsp;</td></tr>\n");
       $r->print("<br>\n");        $r->print("<br>\n");
    }     }
   }    }
   $r->print('</body></html>');  # ===================================================== End Resource Space Call
   return OK;   } else {
   # ===================================================== Construction Space Call
   
   # ----------------------------------------------------------- Set document type
   
     $r->content_type('text/html');
     $r->send_http_header;
   
     return OK if $r->header_only;
   # ---------------------------------------------------------------------- Header
     my $bodytag=&Apache::loncommon::bodytag('Edit Catalog Information');
     my $disuri=$uri;
     my $fn=&Apache::lonnet::filelocation('',$uri);
     $disuri=~s/^\/\~\w+//;
     $disuri=~s/\.meta$//;
     my $displayfile='Catalog Information for '.$disuri;
     if ($disuri=~/\/default$/) {
         my $dir=$disuri;
         $dir=~s/default$//;
         $displayfile='Default Cataloging Information for Directory '.$dir;
     }
     %Apache::lonpublisher::metadatafields=();
     %Apache::lonpublisher::metadatakeys=();
     &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
     $r->print(<<ENDEDIT);
   <html><head><title>Edit Catalog Information</title></head>
   $bodytag
   <h1>$displayfile</h1>
   <form method="post">
   ENDEDIT
      foreach ('author','title','subject','keywords','abstract','notes',
               'copyright','customdistributionfile','language') {
          if ($ENV{'form.new_'.$_}) {
      $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};
          }
          $r->print(
            &Apache::lonpublisher::textfield($_,'new_'.$_,
                                    $Apache::lonpublisher::metadatafields{$_}));
      }
      if ($ENV{'form.store'}) {
         my $mfh;
         unless ($mfh=Apache::File->new('>'.$fn)) {
               $r->print(
               '<p><font color=red>Could not write metadata, FAIL</font>');
         } else {
             foreach (sort keys %Apache::lonpublisher::metadatafields) {
               unless ($_=~/\./) {
                   my $unikey=$_;
                   $unikey=~/^([A-Za-z]+)/;
                   my $tag=$1;
                   $tag=~tr/A-Z/a-z/;
                   print $mfh "\n\<$tag";
                   foreach 
                     (split(/\,/,$Apache::lonpublisher::metadatakeys{$unikey})) {
                       my $value=
                          $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
                       $value=~s/\"/\'\'/g;
                       print $mfh ' '.$_.'="'.$value.'"';
                   }
                   print $mfh '>'.
           &HTML::Entities::encode($Apache::lonpublisher::metadatafields{$unikey})
                           .'</'.$tag.'>';
               }
     }
             $r->print('<p>Wrote Metadata');
         }
       }
       $r->print(
    '<br /><input type="submit" name="store" value="Store Catalog Information"></form></body></html>');
       return OK;
     }
 }  }
   
 1;  1;

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


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