Diff for /loncom/interface/lonmeta.pm between versions 1.20 and 1.32

version 1.20, 2002/09/16 21:01:41 version 1.32, 2003/06/30 17:17:30
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 49  sub dynamicmeta { Line 51  sub dynamicmeta {
     $regexp='___'.$regexp.'___';      $regexp='___'.$regexp.'___';
     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,      my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
        $aauthor,$regexp);         $aauthor,$regexp);
     my %sum;      my %sum=();
     my %cnt;      my %cnt=();
       my %concat=();
     my %listitems=('count'        => 'add',      my %listitems=('count'        => 'add',
                    'course'       => 'add',                     'course'       => 'add',
                      'goto'         => 'add',
                      'comefrom'     => 'add',
                    'avetries'     => 'avg',                     'avetries'     => 'avg',
                    'stdno'        => 'add',                     'stdno'        => 'add',
                    'difficulty'   => 'avg',                     'difficulty'   => 'avg',
Line 65  sub dynamicmeta { Line 70  sub dynamicmeta {
                    'usage'        => 'cnt'                     'usage'        => 'cnt'
                    );                     );
     foreach (keys %evaldata) {      foreach (keys %evaldata) {
  $_=~/___(\w+)$/;   my ($item,$purl,$cat)=split(/\_\_\_/,$_);
         if (defined($cnt{$1})) { $cnt{$1}++; } else { $cnt{$1}=1; }  ### print "\n".$_.' - '.$item.'<br />';
         unless ($listitems{$1} eq 'app') {          if (defined($cnt{$cat})) { $cnt{$cat}++; } else { $cnt{$cat}=1; }
             if (defined($sum{$1})) {          unless ($listitems{$cat} eq 'app') {
                $sum{$1}+=$evaldata{$_};              if (defined($sum{$cat})) {
                  $sum{$cat}+=$evaldata{$_};
                  $concat{$cat}.=','.$item;
     } else {      } else {
                $sum{$1}=$evaldata{$_};                 $sum{$cat}=$evaldata{$_};
                  $concat{$cat}=$item;
     }      }
         } else {          } else {
             if (defined($sum{$1})) {              if (defined($sum{$cat})) {
                if ($evaldata{$_}) {                 if ($evaldata{$_}) {
                   $sum{$1}.='<hr>'.$evaldata{$_};                    $sum{$cat}.='<hr>'.$evaldata{$_};
        }         }
      } else {       } else {
        $sum{$1}=''.$evaldata{$_};         $sum{$cat}=''.$evaldata{$_};
     }      }
  }   }
     }      }
Line 92  sub dynamicmeta { Line 100  sub dynamicmeta {
        } else {         } else {
            $returnhash{$_}=$sum{$_};             $returnhash{$_}=$sum{$_};
        }         }
          $returnhash{$_.'_list'}=$concat{$_};
   ### print "\n<hr />".$_.': '.$returnhash{$_}.'<br />'.$returnhash{$_.'_list'};
     }      }
     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'; }
   }
   
   # -------------------------------------------------------------- Author display
   
   sub authordisplay {
       my ($aname,$adom)=@_;
       return &Apache::loncommon::aboutmewrapper(
                   &Apache::loncommon::plainname($aname,$adom),
                       $aname,$adom).' <tt>['.$aname.'@'.$adom.']</tt>';
   }
   
 # -------------------------------------------------------------- Pretty display  # -------------------------------------------------------------- Pretty display
   
 sub evalgraph {  sub evalgraph {
Line 149  sub handler { Line 185  sub handler {
   
     my $uri=$r->uri;      my $uri=$r->uri;
   
     unless ($uri=~/^\/\~/) { 
   # =========================================== This is not in construction space
     my ($resdomain,$resuser)=      my ($resdomain,$resuser)=
            (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);             (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
   
Line 179  sub handler { Line 217  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 $author=$content{'author'};
   $author=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
   my $owner=$content{'owner'};
   $owner=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
   my $versiondisplay='';
   if ($thisversion) {
       $versiondisplay='Version: '.$thisversion.
       ' (most recent version: '.$currentversion.')';
   } else {
       $versiondisplay='Version: '.$currentversion;
   }
   my $customdistributionfile='';
   if ($content{'customdistributionfile'}) {
      $customdistributionfile='<a href="'.$content{'customdistributionfile'}.
        '"><tt>'.$content{'customdistributionfile'}.'</tt></a>';
   }
 my $bodytag=&Apache::loncommon::bodytag  my $bodytag=&Apache::loncommon::bodytag
             ('Catalog Information','','','',$resdomain);              ('Catalog Information','','','',$resdomain);
   $r->print(<<ENDHEAD);    $r->print(<<ENDHEAD);
Line 193  my $bodytag=&Apache::loncommon::bodytag Line 250  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">$author&nbsp;</td></tr>
 <tr><td bgcolor='#AAAAAA'>Subject</td>  <tr><td bgcolor='#AAAAAA'>Subject</td>
 <td bgcolor="#CCCCCC">$content{'subject'}&nbsp;</td></tr>  <td bgcolor="#CCCCCC">$content{'subject'}&nbsp;</td></tr>
 <tr><td bgcolor='#AAAAAA'>Keyword(s)</td>  <tr><td bgcolor='#AAAAAA'>Keyword(s)</td>
Line 213  $bodytag Line 271  $bodytag
 <tr><td bgcolor='#AAAAAA'>  <tr><td bgcolor='#AAAAAA'>
 Last Revision Date</td><td bgcolor="#CCCCCC">$lastrevisiondate&nbsp;</td></tr>  Last Revision Date</td><td bgcolor="#CCCCCC">$lastrevisiondate&nbsp;</td></tr>
 <tr><td bgcolor='#AAAAAA'>Publisher/Owner</td>  <tr><td bgcolor='#AAAAAA'>Publisher/Owner</td>
 <td bgcolor="#CCCCCC">$content{'owner'}&nbsp;</td></tr>  <td bgcolor="#CCCCCC">$owner&nbsp;</td></tr>
 <tr><td bgcolor='#AAAAAA'>Copyright/Distribution</td>  <tr><td bgcolor='#AAAAAA'>Copyright/Distribution</td>
 <td bgcolor="#CCCCCC">$content{'copyright'}  <td bgcolor="#CCCCCC">$content{'copyright'}&nbsp;</td></tr>
   <tr><td bgcolor='#AAAAAA'>Custom Distribution File</td>
   <td bgcolor="#CCCCCC">$customdistributionfile&nbsp;</td></tr>
 </table>  </table>
 ENDHEAD  ENDHEAD
   delete($content{'title'});    delete($content{'title'});
Line 239  ENDHEAD Line 299  ENDHEAD
  'count'      => 'Network-wide number of accesses (hits)',   'count'      => 'Network-wide number of accesses (hits)',
  'course'     => 'Network-wide number of courses using resource',   'course'     => 'Network-wide number of courses using resource',
  'usage'      => 'Number of resources using or importing resource',   'usage'      => 'Number of resources using or importing resource',
    'goto'       => 'Number of resources that follow this resource in maps',
    'comefrom'   => 'Number of resources that lead up to this resource in maps',
  'clear'      => 'Material presented in clear way',   'clear'      => 'Material presented in clear way',
  'depth'      => 'Material covered with sufficient depth',   'depth'      => 'Material covered with sufficient depth',
  'helpful'    => 'Material is helpful',   'helpful'    => 'Material is helpful',
Line 250  ENDHEAD Line 312  ENDHEAD
    my %dynmeta=&dynamicmeta($uri);     my %dynmeta=&dynamicmeta($uri);
    $r->print(     $r->print(
 '</table><h4>Access and Usage Statistics</h4><table cellspacing=2 border=0>');  '</table><h4>Access and Usage Statistics</h4><table cellspacing=2 border=0>');
    foreach ('count','usage','course') {     foreach ('count') {
        $r->print(         $r->print(
 '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.  '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
 $dynmeta{$_}."&nbsp;</td></tr>\n");  $dynmeta{$_}."&nbsp;</td></tr>\n");
    }     }
      foreach my $cat ('usage','comefrom','goto') {
          $r->print(
   '<tr><td bgcolor="#AAAAAA">'.$items{$cat}.'</td><td bgcolor="#CCCCCC">'.
   $dynmeta{$cat}.'<font size="-1"><ul>'.join("\n",
         map { my $murl=$_; 
    '<li><a href="'.&Apache::lonnet::clutter($murl).'" target="preview">'.
                           &Apache::lonnet::gettitle($murl).' [<tt>'.$murl
                           .'</tt>]</a></li>' }
         split(/\,/,$dynmeta{$cat.'_list'}))."</ul></font></td></tr>\n");
      }
      foreach my $cat ('course') {
          $r->print(
   '<tr><td bgcolor="#AAAAAA">'.$items{$cat}.'</td><td bgcolor="#CCCCCC">'.
   $dynmeta{$cat}.'<font size="-1"><ul>'.join("\n",
         map { my %courseinfo=&Apache::lonnet::coursedescription($_);  
    '<li><a href="/public/'.
     $courseinfo{'domain'}.'/'.$courseinfo{'num'}.'/syllabus" target="preview">'.
     $courseinfo{'description'}.'</a></li>' }
         split(/\,/,$dynmeta{$cat.'_list'}))."</ul></font></td></tr>\n");
      }
        $r->print('</table>');         $r->print('</table>');
    if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {     if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
       $r->print(        $r->print(
Line 283  $dynmeta{$_}."&nbsp;</td></tr>\n"); Line 365  $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 306  $dynmeta{$_}."&nbsp;</td></tr>\n"); Line 398  $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_'.$_};
          }
          if (m/copyright/) {
      $r->print(&Apache::lonpublisher::selectbox($_,'new_'.$_,
          $Apache::lonpublisher::metadatafields{$_},
          \&Apache::loncommon::copyrightdescription,
          (&Apache::loncommon::copyrightids)));
          } elsif (m/language/) {
      $r->print(&Apache::lonpublisher::selectbox($_,'new_'.$_,
         $Apache::lonpublisher::metadatafields{$_},
         \&Apache::loncommon::languagedescription,
         (&Apache::loncommon::languageids)));
          } else {
      $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.20  
changed lines
  Added in v.1.32


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