Diff for /loncom/interface/lonmeta.pm between versions 1.35 and 1.44

version 1.35, 2003/09/22 00:48:32 version 1.44, 2003/12/28 20:12:59
Line 24 Line 24
 # /home/httpd/html/adm/gpl.txt  # /home/httpd/html/adm/gpl.txt
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  
 # (TeX Content Handler  
 #  
 # 05/29/00,05/30,10/11 Gerd Kortemeyer)  
 #  
 # 10/19,10/21,10/23,11/27,08/09/01,12/22,12/24,12/25 Gerd Kortemeyer  
   
 package Apache::lonmeta;  package Apache::lonmeta;
   
Line 40  use Apache::loncommon(); Line 35  use Apache::loncommon();
 use Apache::lonmsg;  use Apache::lonmsg;
 use Apache::lonpublisher;  use Apache::lonpublisher;
 use Apache::lonlocal;  use Apache::lonlocal;
   use Apache::lonmysql;
   
   # MySQL table columns
   
   my @columns;
   
 # ----------------------------------------- Fetch and evaluate dynamic metadata  # ----------------------------------------- Fetch and evaluate dynamic metadata
   
Line 55  sub dynamicmeta { Line 55  sub dynamicmeta {
     my %sum=();      my %sum=();
     my %cnt=();      my %cnt=();
     my %concat=();      my %concat=();
     my %listitems=('count'        => 'add',      my %listitems=(
                    'course'       => 'add',                     'course'       => 'add',
                    'goto'         => 'add',                     'goto'         => 'add',
                    'comefrom'     => 'add',                     'comefrom'     => 'add',
Line 70  sub dynamicmeta { Line 70  sub dynamicmeta {
                    'comments'     => 'app',                     'comments'     => 'app',
                    'usage'        => 'cnt'                     'usage'        => 'cnt'
                    );                     );
     foreach (keys %evaldata) {      while ($_=each(%evaldata)) {
  my ($item,$purl,$cat)=&Apache::lonnet::decode_symb($_);   my ($item,$purl,$cat)=split(/___/,$_);
 ### print "\n".$_.' - '.$item.'<br />';   ### Apache->request->print("\n".$_.' - '.$item.'<br />');
         if (defined($cnt{$cat})) { $cnt{$cat}++; } else { $cnt{$cat}=1; }   if (defined($cnt{$cat})) { $cnt{$cat}++; } else { $cnt{$cat}=1; }
         unless ($listitems{$cat} eq 'app') {          unless ($listitems{$cat} eq 'app') {
             if (defined($sum{$cat})) {              if (defined($sum{$cat})) {
                $sum{$cat}+=$evaldata{$_};                 $sum{$cat}+=$evaldata{$_};
Line 93  sub dynamicmeta { Line 93  sub dynamicmeta {
  }   }
     }      }
     my %returnhash=();      my %returnhash=();
     foreach (keys %cnt) {      while ($_=each(%cnt)) {
        if ($listitems{$_} eq 'avg') {         if ($listitems{$_} eq 'avg') {
    $returnhash{$_}=int(($sum{$_}/$cnt{$_})*100.0+0.5)/100.0;     $returnhash{$_}=int(($sum{$_}/$cnt{$_})*100.0+0.5)/100.0;
        } elsif ($listitems{$_} eq 'cnt') {         } elsif ($listitems{$_} eq 'cnt') {
Line 102  sub dynamicmeta { Line 102  sub dynamicmeta {
            $returnhash{$_}=$sum{$_};             $returnhash{$_}=$sum{$_};
        }         }
        $returnhash{$_.'_list'}=$concat{$_};         $returnhash{$_.'_list'}=$concat{$_};
 ### print "\n<hr />".$_.': '.$returnhash{$_}.'<br />'.$returnhash{$_.'_list'};         ### Apache->request->print("\n<hr />".$_.': '.$returnhash{$_}.'<br />'.$returnhash{$_.'_list'});
     }      }
       #
       # Deal with 'count' seperately
       $returnhash{'count'} = &access_count($url,$aauthor,$adomain);
   
     return %returnhash;      return %returnhash;
 }  }
   
   sub access_count {
       my ($src,$author,$adomain) = @_;
       my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
                                           $author,$src);
       if (! exists($countdata{$src})) {
           return 'Not Available';
       } else {
           return $countdata{$src};
       }
   }
   
 # ------------------------------------- Try to make an alt tag if there is none  # ------------------------------------- Try to make an alt tag if there is none
   
 sub alttag {  sub alttag {
Line 175  sub diffgraph { Line 190  sub diffgraph {
     return $output;      return $output;
 }  }
   
   # ==================================================== Turn MySQL row into hash
   
   sub metadata_col_to_hash {
       my @cols=@_;
       my %hash=();
       for (my $i=0; $i<=$#columns; $i++) {
    $hash{$columns[$i]}=$cols[$i];
       }
       return %hash;
   }
   
 # ================================================================ Main Handler  # ================================================================ Main Handler
   
 sub handler {  sub handler {
Line 219  sub handler { Line 245  sub handler {
   
 # --------------------------------------------------------------- Render Output  # --------------------------------------------------------------- Render Output
   my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);    my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
 my $creationdate=localtime(  my $creationdate=&Apache::lonlocal::locallocaltime(
  &Apache::loncommon::unsqltime($content{'creationdate'}));   &Apache::lonmysql::unsqltime($content{'creationdate'}));
 my $lastrevisiondate=localtime(  my $lastrevisiondate=&Apache::lonlocal::locallocaltime(
  &Apache::loncommon::unsqltime($content{'lastrevisiondate'}));   &Apache::lonmysql::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);
Line 234  my $owner=$content{'owner'}; Line 260  my $owner=$content{'owner'};
 $owner=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;  $owner=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
 my $versiondisplay='';  my $versiondisplay='';
 if ($thisversion) {  if ($thisversion) {
     $versiondisplay='Version: '.$thisversion.      $versiondisplay=&mt('Version').': '.$thisversion.
     ' (most recent version: '.$currentversion.')';      ' ('.&mt('most recent version').': '.$currentversion.')';
 } else {  } else {
     $versiondisplay='Version: '.$currentversion;      $versiondisplay='Version: '.$currentversion;
 }  }
Line 244  if ($content{'customdistributionfile'}) Line 270  if ($content{'customdistributionfile'})
    $customdistributionfile='<a href="'.$content{'customdistributionfile'}.     $customdistributionfile='<a href="'.$content{'customdistributionfile'}.
      '"><tt>'.$content{'customdistributionfile'}.'</tt></a>';       '"><tt>'.$content{'customdistributionfile'}.'</tt></a>';
 }  }
   
   my $obsolete=$content{'obsolete'};
   my $obsoletereplace=$content{'obsoletereplacement'};
   my $obsoletewarning='';
   if (($obsolete) && ($ENV{'user.adv'})) {
       $obsoletewarning='<p><font color="red">'.&mt('This resource has been marked obsolete by the author(s)').'</font></p>';
   }
   
 my %lt=&Apache::lonlocal::texthash(  my %lt=&Apache::lonlocal::texthash(
    'au' =>'Author(s)',     'au' =>'Author(s)',
    'sb' => 'Subject',     'sb' => 'Subject',
    'kw' => 'Keyword(s)',     'kw' => 'Keyword(s)',
    'no' => 'Notes',     'no' => 'Notes',
    'ab' => 'Abstract',     'ab' => 'Abstract',
                                      'lg' => 'Lowest Grade Level',
                                      'hg' => 'Highest Grade Level',
                                      'st' => 'Standards',
    'mi' => 'MIME Type',     'mi' => 'MIME Type',
    'la' => 'Language',     'la' => 'Language',
    'cd' => 'Creation Date',     'cd' => 'Creation Date',
    'pu' => 'Publisher/Owner',     'pu' => 'Publisher/Owner',
                                    'co' => 'Copyright/Distribution',                                     'co' => 'Copyright/Distribution',
    'cf' => 'Custom Distribution File');     'cf' => 'Custom Distribution File',
                                      'ob' => 'Obsolete',
                                      'or' => 
                                       'Suggested Replacement for Obsolete File');
 my $bodytag=&Apache::loncommon::bodytag  my $bodytag=&Apache::loncommon::bodytag
             ('Catalog Information','','','',$resdomain);              ('Catalog Information','','','',$resdomain);
   $r->print(<<ENDHEAD);    $r->print(<<ENDHEAD);
Line 263  my $bodytag=&Apache::loncommon::bodytag Line 303  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>
   $obsoletewarning
 $versiondisplay<br />  $versiondisplay<br />
 <table cellspacing=2 border=0>  <table cellspacing=2 border=0>
 <tr><td bgcolor='#AAAAAA'>$lt{'au'}</td>  <tr><td bgcolor='#AAAAAA'>$lt{'au'}</td>
Line 275  $versiondisplay<br /> Line 316  $versiondisplay<br />
 <td bgcolor="#CCCCCC">$content{'notes'}&nbsp;</td></tr>  <td bgcolor="#CCCCCC">$content{'notes'}&nbsp;</td></tr>
 <tr><td bgcolor='#AAAAAA'>$lt{'ab'}</td>  <tr><td bgcolor='#AAAAAA'>$lt{'ab'}</td>
 <td bgcolor="#CCCCCC">$content{'abstract'}&nbsp;</td></tr>  <td bgcolor="#CCCCCC">$content{'abstract'}&nbsp;</td></tr>
   <tr><td bgcolor='#AAAAAA'>$lt{'lg'}</td>
   <td bgcolor="#CCCCCC">$content{'lowestgradelevel'}&nbsp;</td></tr>
   <tr><td bgcolor='#AAAAAA'>$lt{'hg'}</td>
   <td bgcolor="#CCCCCC">$content{'highestgradelevel'}&nbsp;</td></tr>
   <tr><td bgcolor='#AAAAAA'>$lt{'st'}</td>
   <td bgcolor="#CCCCCC">$content{'standards'}&nbsp;</td></tr>
 <tr><td bgcolor='#AAAAAA'>$lt{'mi'}</td>  <tr><td bgcolor='#AAAAAA'>$lt{'mi'}</td>
 <td bgcolor="#CCCCCC">$mime ($content{'mime'})&nbsp;</td></tr>  <td bgcolor="#CCCCCC">$mime ($content{'mime'})&nbsp;</td></tr>
 <tr><td bgcolor='#AAAAAA'>$lt{'la'}</td>  <tr><td bgcolor='#AAAAAA'>$lt{'la'}</td>
Line 289  Last Revision Date</td><td bgcolor="#CCC Line 336  Last Revision Date</td><td bgcolor="#CCC
 <td bgcolor="#CCCCCC">$content{'copyright'}&nbsp;</td></tr>  <td bgcolor="#CCCCCC">$content{'copyright'}&nbsp;</td></tr>
 <tr><td bgcolor='#AAAAAA'>$lt{'cf'}</td>  <tr><td bgcolor='#AAAAAA'>$lt{'cf'}</td>
 <td bgcolor="#CCCCCC">$customdistributionfile&nbsp;</td></tr>  <td bgcolor="#CCCCCC">$customdistributionfile&nbsp;</td></tr>
   <tr><td bgcolor='#AAAAAA'>$lt{'ob'}</td>
   <td bgcolor="#CCCCCC">$obsolete&nbsp;</td></tr>
   <tr><td bgcolor='#AAAAAA'>$lt{'or'}</td>
   <td bgcolor="#CCCCCC">$obsoletereplace&nbsp;</td></tr>
 </table>  </table>
 ENDHEAD  ENDHEAD
   delete($content{'title'});    delete($content{'title'});
Line 304  ENDHEAD Line 355  ENDHEAD
   delete($content{'owner'});    delete($content{'owner'});
   delete($content{'copyright'});    delete($content{'copyright'});
   delete($content{'customdistributionfile'});    delete($content{'customdistributionfile'});
     delete($content{'obsolete'});
     delete($content{'obsoletereplacement'});
   if ($ENV{'user.adv'}) {    if ($ENV{'user.adv'}) {
 # ------------------------------------------------------------ Dynamic Metadata  # ------------------------------------------------------------ Dynamic Metadata
    $r->print(     $r->print(
Line 383  $dynmeta{$_}."&nbsp;</td></tr>\n"); Line 436  $dynmeta{$_}."&nbsp;</td></tr>\n");
   '<h4>'.&mt('Evaluation Comments').' ('.&mt('visible to author and co-authors only').')</h4>'.    '<h4>'.&mt('Evaluation Comments').' ('.&mt('visible to author and co-authors only').')</h4>'.
       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');        '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
       $r->print(        $r->print(
    '<h4>Error Messages (visible to author and co-authors only)</h4>');     '<h4>'.&mt('Error Messages').' ('.
             &mt('visible to author and co-authors only').')</h4>');
       my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$1,$2);        my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$1,$2);
       foreach (keys %errormsgs) {        foreach (keys %errormsgs) {
  if ($_=~/^\Q$disuri\E\_\d+$/) {   if ($_=~/^\Q$disuri\E\_\d+$/) {
Line 436  $dynmeta{$_}."&nbsp;</td></tr>\n"); Line 490  $dynmeta{$_}."&nbsp;</td></tr>\n");
   if ($disuri=~/\/default$/) {    if ($disuri=~/\/default$/) {
       my $dir=$disuri;        my $dir=$disuri;
       $dir=~s/default$//;        $dir=~s/default$//;
       $displayfile='Default Cataloging Information for Directory '.$dir;        $displayfile=&mt('Default Cataloging Information for Directory').' '.
     $dir;
   }    }
   %Apache::lonpublisher::metadatafields=();    %Apache::lonpublisher::metadatafields=();
   %Apache::lonpublisher::metadatakeys=();    %Apache::lonpublisher::metadatakeys=();
Line 448  $bodytag Line 503  $bodytag
 <form method="post">  <form method="post">
 ENDEDIT  ENDEDIT
    foreach ('author','title','subject','keywords','abstract','notes',     foreach ('author','title','subject','keywords','abstract','notes',
             'copyright','customdistributionfile','language') {              'copyright','customdistributionfile','language',
               'obsolete','obsoletereplacement') {
        if ($ENV{'form.new_'.$_}) {         if ($ENV{'form.new_'.$_}) {
    $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};     $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};
        }         }
        if (m/copyright/) {         if (m/copyright/) {
    $r->print(&Apache::lonpublisher::selectbox($_,'new_'.$_,     $r->print(&Apache::lonpublisher::selectbox($_,'new_'.$_,
        $Apache::lonpublisher::metadatafields{$_},         ($Apache::lonpublisher::metadatafields{$_}?
    $Apache::lonpublisher::metadatafields{$_}:'default'),
        \&Apache::loncommon::copyrightdescription,         \&Apache::loncommon::copyrightdescription,
        (&Apache::loncommon::copyrightids)));         (&Apache::loncommon::copyrightids)));
        } elsif (m/language/) {         } elsif (m/language/) {
Line 471  ENDEDIT Line 528  ENDEDIT
       my $mfh;        my $mfh;
       unless ($mfh=Apache::File->new('>'.$fn)) {        unless ($mfh=Apache::File->new('>'.$fn)) {
             $r->print(              $r->print(
             '<p><font color=red>Could not write metadata, FAIL</font>');              '<p><font color=red>'.&mt('Could not write metadata').', '.
         &mt('FAIL').'</font>');
       } else {        } else {
           foreach (sort keys %Apache::lonpublisher::metadatafields) {            foreach (sort keys %Apache::lonpublisher::metadatafields) {
             unless ($_=~/\./) {              unless ($_=~/\./) {
Line 492  ENDEDIT Line 550  ENDEDIT
                         .'</'.$tag.'>';                          .'</'.$tag.'>';
             }              }
   }    }
           $r->print('<p>Wrote Metadata');            $r->print('<p>'.&mt('Wrote Metadata'));
       }        }
     }      }
     $r->print(      $r->print(
  '<br /><input type="submit" name="store" value="Store Catalog Information"></form></body></html>');   '<br /><input type="submit" name="store" value="'.
   &mt('Store Catalog Information').'"></form></body></html>');
     return OK;      return OK;
   }    }
 }  }
   
   # ================================================================= BEGIN Block
   BEGIN {
   # Get columns of MySQL metadata table
       @columns=&Apache::lonmysql::col_order('metadata');
   }
 1;  1;
 __END__  __END__
   

Removed from v.1.35  
changed lines
  Added in v.1.44


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