File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.41: download - view: text, annotated - select for diffs
Mon Dec 22 21:44:17 2003 UTC (20 years, 5 months ago) by www
Branches: MAIN
CVS tags: HEAD
It was way to easy to set 'custom' copyright if not paying attention

    1: # The LearningOnline Network with CAPA
    2: # Metadata display handler
    3: #
    4: # $Id: lonmeta.pm,v 1.41 2003/12/22 21:44:17 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: # (TeX Content Handler
   29: #
   30: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
   31: #
   32: # 10/19,10/21,10/23,11/27,08/09/01,12/22,12/24,12/25 Gerd Kortemeyer
   33: 
   34: package Apache::lonmeta;
   35: 
   36: use strict;
   37: use Apache::Constants qw(:common);
   38: use Apache::lonnet();
   39: use Apache::loncommon();
   40: use Apache::lonmsg;
   41: use Apache::lonpublisher;
   42: use Apache::lonlocal;
   43: 
   44: # ----------------------------------------- Fetch and evaluate dynamic metadata
   45: 
   46: sub dynamicmeta {
   47:     my $url=&Apache::lonnet::declutter(shift);
   48:     $url=~s/\.meta$//;
   49:     my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
   50:     my $regexp=$url;
   51:     $regexp=~s/(\W)/\\$1/g;
   52:     $regexp='___'.$regexp.'___';
   53:     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
   54: 				       $aauthor,$regexp);
   55:     my %sum=();
   56:     my %cnt=();
   57:     my %concat=();
   58:     my %listitems=(
   59:                    'course'       => 'add',
   60:                    'goto'         => 'add',
   61:                    'comefrom'     => 'add',
   62:                    'avetries'     => 'avg',
   63:                    'stdno'        => 'add',
   64:                    'difficulty'   => 'avg',
   65:                    'clear'        => 'avg',
   66:                    'technical'    => 'avg',
   67:                    'helpful'      => 'avg',
   68:                    'correct'      => 'avg',
   69:                    'depth'        => 'avg',
   70:                    'comments'     => 'app',
   71:                    'usage'        => 'cnt'
   72:                    );
   73:     while ($_=each(%evaldata)) {
   74: 	my ($item,$purl,$cat)=split(/___/,$_);
   75: 	### Apache->request->print("\n".$_.' - '.$item.'<br />');
   76: 	if (defined($cnt{$cat})) { $cnt{$cat}++; } else { $cnt{$cat}=1; }
   77:         unless ($listitems{$cat} eq 'app') {
   78:             if (defined($sum{$cat})) {
   79:                $sum{$cat}+=$evaldata{$_};
   80:                $concat{$cat}.=','.$item;
   81: 	    } else {
   82:                $sum{$cat}=$evaldata{$_};
   83:                $concat{$cat}=$item;
   84: 	    }
   85:         } else {
   86:             if (defined($sum{$cat})) {
   87:                if ($evaldata{$_}) {
   88:                   $sum{$cat}.='<hr>'.$evaldata{$_};
   89: 	       }
   90:  	    } else {
   91: 	       $sum{$cat}=''.$evaldata{$_};
   92: 	    }
   93: 	}
   94:     }
   95:     my %returnhash=();
   96:     while ($_=each(%cnt)) {
   97:        if ($listitems{$_} eq 'avg') {
   98: 	   $returnhash{$_}=int(($sum{$_}/$cnt{$_})*100.0+0.5)/100.0;
   99:        } elsif ($listitems{$_} eq 'cnt') {
  100:            $returnhash{$_}=$cnt{$_};
  101:        } else {
  102:            $returnhash{$_}=$sum{$_};
  103:        }
  104:        $returnhash{$_.'_list'}=$concat{$_};
  105:        ### Apache->request->print("\n<hr />".$_.': '.$returnhash{$_}.'<br />'.$returnhash{$_.'_list'});
  106:     }
  107:     #
  108:     # Deal with 'count' seperately
  109:     $returnhash{'count'} = &access_count($url,$aauthor,$adomain);
  110: 
  111:     return %returnhash;
  112: }
  113: 
  114: sub access_count {
  115:     my ($src,$author,$adomain) = @_;
  116:     my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
  117:                                         $author,$src);
  118:     if (! exists($countdata{$src})) {
  119:         return 'Not Available';
  120:     } else {
  121:         return $countdata{$src};
  122:     }
  123: }
  124: 
  125: # ------------------------------------- Try to make an alt tag if there is none
  126: 
  127: sub alttag {
  128:     my ($base,$src)=@_;
  129:     my $fullpath=&Apache::lonnet::hreflocation($base,$src);
  130:     my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
  131:                &Apache::lonnet::metadata($fullpath,'subject').' '.
  132:                &Apache::lonnet::metadata($fullpath,'abstract');
  133:     $alttag=~s/\s+/ /gs;
  134:     $alttag=~s/\"//gs;
  135:     $alttag=~s/\'//gs;
  136:     $alttag=~s/\s+$//gs;
  137:     $alttag=~s/^\s+//gs;
  138:     if ($alttag) { return $alttag; } else 
  139:                  { return 'No information available'; }
  140: }
  141: 
  142: # -------------------------------------------------------------- Author display
  143: 
  144: sub authordisplay {
  145:     my ($aname,$adom)=@_;
  146:     return &Apache::loncommon::aboutmewrapper(
  147:                 &Apache::loncommon::plainname($aname,$adom),
  148:                     $aname,$adom).' <tt>['.$aname.'@'.$adom.']</tt>';
  149: }
  150: 
  151: # -------------------------------------------------------------- Pretty display
  152: 
  153: sub evalgraph {
  154:     my $value=shift;
  155:     unless ($value) { return ''; }
  156:     my $val=int($value*10.+0.5)-10;
  157:     my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
  158:     if ($val>=20) {
  159: 	$output.='<td width=20 bgcolor="#555555">&nbsp&nbsp;</td>';
  160:     } else {
  161:         $output.='<td width='.($val).' bgcolor="#555555">&nbsp;</td>'.
  162:                  '<td width='.(20-$val).' bgcolor="#FF3333">&nbsp;</td>';
  163:     }
  164:     $output.='<td bgcolor="#FFFF33">&nbsp;</td>';
  165:     if ($val>20) {
  166: 	$output.='<td width='.($val-20).' bgcolor="#33FF33">&nbsp;</td>'.
  167:                  '<td width='.(40-$val).' bgcolor="#555555">&nbsp;</td>';
  168:     } else {
  169:        $output.='<td width=20 bgcolor="#555555">&nbsp&nbsp;</td>';
  170:     }
  171:     $output.='<td> ('.$value.') </td></tr></table>';
  172:     return $output;
  173: }
  174: 
  175: sub diffgraph {
  176:     my $value=shift;
  177:     unless ($value) { return ''; }
  178:     my $val=int(40.0*$value+0.5);
  179:     my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
  180:                 '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
  181:     my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
  182:     for (my $i=0;$i<8;$i++) {
  183: 	if ($val>$i*5) {
  184:             $output.='<td width=5 bgcolor="'.$colors[$i].'">&nbsp;</td>';
  185:         } else {
  186: 	    $output.='<td width=5 bgcolor="#555555">&nbsp;</td>';
  187: 	}
  188:     }
  189:     $output.='<td> ('.$value.') </td></tr></table>';
  190:     return $output;
  191: }
  192: 
  193: # ================================================================ Main Handler
  194: 
  195: sub handler {
  196:   my $r=shift;
  197: 
  198:     my $loaderror=&Apache::lonnet::overloaderror($r);
  199:     if ($loaderror) { return $loaderror; }
  200: 
  201: 
  202:     my $uri=$r->uri;
  203: 
  204:   unless ($uri=~/^\/\~/) { 
  205: # =========================================== This is not in construction space
  206:     my ($resdomain,$resuser)=
  207:            (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
  208: 
  209:     $loaderror=
  210:        &Apache::lonnet::overloaderror($r,
  211:          &Apache::lonnet::homeserver($resuser,$resdomain));
  212:     if ($loaderror) { return $loaderror; }
  213: 
  214:   my %content=();
  215: 
  216: # ----------------------------------------------------------- Set document type
  217: 
  218:   &Apache::loncommon::content_type($r,'text/html');
  219:   $r->send_http_header;
  220: 
  221:   return OK if $r->header_only;
  222: 
  223: # ------------------------------------------------------------------- Read file
  224:   foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
  225:       $content{$_}=&Apache::lonnet::metadata($uri,$_);
  226:   }
  227: # ------------------------------------------------------------------ Hide stuff
  228: 
  229:   unless ($ENV{'user.adv'}) {
  230:       foreach ('keywords','notes','abstract','subject') {
  231:           $content{$_}='<i>- '.&mt('not displayed').' -</i>';
  232:       }
  233:   }
  234: 
  235: # --------------------------------------------------------------- Render Output
  236:   my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
  237: my $creationdate=&Apache::lonlocal::locallocaltime(
  238:  &Apache::loncommon::unsqltime($content{'creationdate'}));
  239: my $lastrevisiondate=&Apache::lonlocal::locallocaltime(
  240:  &Apache::loncommon::unsqltime($content{'lastrevisiondate'}));
  241: my $language=&Apache::loncommon::languagedescription($content{'language'});
  242: my $mime=&Apache::loncommon::filedescription($content{'mime'}); 
  243: my $disuri=&Apache::lonnet::declutter($uri);
  244:   $disuri=~s/\.meta$//;
  245: my $currentversion=&Apache::lonnet::getversion($disuri);
  246: my $author=$content{'author'};
  247: $author=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
  248: my $owner=$content{'owner'};
  249: $owner=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
  250: my $versiondisplay='';
  251: if ($thisversion) {
  252:     $versiondisplay=&mt('Version').': '.$thisversion.
  253:     ' ('.&mt('most recent version').': '.$currentversion.')';
  254: } else {
  255:     $versiondisplay='Version: '.$currentversion;
  256: }
  257: my $customdistributionfile='';
  258: if ($content{'customdistributionfile'}) {
  259:    $customdistributionfile='<a href="'.$content{'customdistributionfile'}.
  260:      '"><tt>'.$content{'customdistributionfile'}.'</tt></a>';
  261: }
  262: 
  263: my $obsolete=$content{'obsolete'};
  264: my $obsoletereplace=$content{'obsoletereplacement'};
  265: my $obsoletewarning='';
  266: if (($obsolete) && ($ENV{'user.adv'})) {
  267:     $obsoletewarning='<p><font color="red">'.&mt('This resource has been marked obsolete by the author(s)').'</font></p>';
  268: }
  269: 
  270: my %lt=&Apache::lonlocal::texthash(
  271: 				   'au' =>'Author(s)',
  272: 				   'sb' => 'Subject',
  273: 				   'kw' => 'Keyword(s)',
  274: 				   'no' => 'Notes',
  275: 				   'ab' => 'Abstract',
  276: 				   'mi' => 'MIME Type',
  277: 				   'la' => 'Language',
  278: 				   'cd' => 'Creation Date',
  279: 				   'pu' => 'Publisher/Owner',
  280:                                    'co' => 'Copyright/Distribution',
  281: 				   'cf' => 'Custom Distribution File',
  282:                                    'ob' => 'Obsolete',
  283:                                    'or' => 
  284:                                     'Suggested Replacement for Obsolete File');
  285: my $bodytag=&Apache::loncommon::bodytag
  286:             ('Catalog Information','','','',$resdomain);
  287:   $r->print(<<ENDHEAD);
  288: <html><head><title>Catalog Information</title></head>
  289: $bodytag
  290: <h2>$content{'title'}</h2>
  291: <h3><tt>$disuri</tt></h3>
  292: $obsoletewarning
  293: $versiondisplay<br />
  294: <table cellspacing=2 border=0>
  295: <tr><td bgcolor='#AAAAAA'>$lt{'au'}</td>
  296: <td bgcolor="#CCCCCC">$author&nbsp;</td></tr>
  297: <tr><td bgcolor='#AAAAAA'>$lt{'sb'}</td>
  298: <td bgcolor="#CCCCCC">$content{'subject'}&nbsp;</td></tr>
  299: <tr><td bgcolor='#AAAAAA'>$lt{'kw'}</td>
  300: <td bgcolor="#CCCCCC">$content{'keywords'}&nbsp;</td></tr>
  301: <tr><td bgcolor='#AAAAAA'>$lt{'no'}</td>
  302: <td bgcolor="#CCCCCC">$content{'notes'}&nbsp;</td></tr>
  303: <tr><td bgcolor='#AAAAAA'>$lt{'ab'}</td>
  304: <td bgcolor="#CCCCCC">$content{'abstract'}&nbsp;</td></tr>
  305: <tr><td bgcolor='#AAAAAA'>$lt{'mi'}</td>
  306: <td bgcolor="#CCCCCC">$mime ($content{'mime'})&nbsp;</td></tr>
  307: <tr><td bgcolor='#AAAAAA'>$lt{'la'}</td>
  308: <td bgcolor="#CCCCCC">$language&nbsp;</td></tr>
  309: <tr><td bgcolor='#AAAAAA'>$lt{'cd'}</td>
  310: <td bgcolor="#CCCCCC">$creationdate&nbsp;</td></tr>
  311: <tr><td bgcolor='#AAAAAA'>
  312: Last Revision Date</td><td bgcolor="#CCCCCC">$lastrevisiondate&nbsp;</td></tr>
  313: <tr><td bgcolor='#AAAAAA'>$lt{'pu'}</td>
  314: <td bgcolor="#CCCCCC">$owner&nbsp;</td></tr>
  315: <tr><td bgcolor='#AAAAAA'>$lt{'co'}</td>
  316: <td bgcolor="#CCCCCC">$content{'copyright'}&nbsp;</td></tr>
  317: <tr><td bgcolor='#AAAAAA'>$lt{'cf'}</td>
  318: <td bgcolor="#CCCCCC">$customdistributionfile&nbsp;</td></tr>
  319: <tr><td bgcolor='#AAAAAA'>$lt{'ob'}</td>
  320: <td bgcolor="#CCCCCC">$obsolete&nbsp;</td></tr>
  321: <tr><td bgcolor='#AAAAAA'>$lt{'or'}</td>
  322: <td bgcolor="#CCCCCC">$obsoletereplace&nbsp;</td></tr>
  323: </table>
  324: ENDHEAD
  325:   delete($content{'title'});
  326:   delete($content{'author'});
  327:   delete($content{'subject'});
  328:   delete($content{'keywords'});
  329:   delete($content{'notes'});
  330:   delete($content{'abstract'});
  331:   delete($content{'mime'});
  332:   delete($content{'language'});
  333:   delete($content{'creationdate'});
  334:   delete($content{'lastrevisiondate'});
  335:   delete($content{'owner'});
  336:   delete($content{'copyright'});
  337:   delete($content{'customdistributionfile'});
  338:   delete($content{'obsolete'});
  339:   delete($content{'obsoletereplacement'});
  340:   if ($ENV{'user.adv'}) {
  341: # ------------------------------------------------------------ Dynamic Metadata
  342:    $r->print(
  343:    '<h3>'.&mt('Dynamic Metadata').' ('.
  344: 	     &mt('updated periodically').')</h3>'.&mt('Processing').
  345: 	     ' ...<br>');
  346:    $r->rflush();
  347:     my %items=&Apache::lonlocal::texthash(
  348:  'count'      => 'Network-wide number of accesses (hits)',
  349:  'course'     => 'Network-wide number of courses using resource',
  350:  'usage'      => 'Number of resources using or importing resource',
  351:  'goto'       => 'Number of resources that follow this resource in maps',
  352:  'comefrom'   => 'Number of resources that lead up to this resource in maps',
  353:  'clear'      => 'Material presented in clear way',
  354:  'depth'      => 'Material covered with sufficient depth',
  355:  'helpful'    => 'Material is helpful',
  356:  'correct'    => 'Material appears to be correct',
  357:  'technical'  => 'Resource is technically correct', 
  358:  'avetries'   => 'Average number of tries till solved',
  359:  'stdno'      => 'Total number of students who have worked on this problem',
  360:  'difficulty' => 'Degree of difficulty');
  361:    my %dynmeta=&dynamicmeta($uri);
  362:    $r->print(
  363: '</table><h4>'.&mt('Access and Usage Statistics').'</h4><table cellspacing=2 border=0>');
  364:    foreach ('count') {
  365:        $r->print(
  366: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  367: $dynmeta{$_}."&nbsp;</td></tr>\n");
  368:    }
  369:    foreach my $cat ('usage','comefrom','goto') {
  370:        $r->print(
  371: '<tr><td bgcolor="#AAAAAA">'.$items{$cat}.'</td><td bgcolor="#CCCCCC">'.
  372: $dynmeta{$cat}.'<font size="-1"><ul>'.join("\n",
  373:       map { my $murl=$_; 
  374:  '<li><a href="'.&Apache::lonnet::clutter($murl).'" target="preview">'.
  375:                         &Apache::lonnet::gettitle($murl).' [<tt>'.$murl
  376:                         .'</tt>]</a></li>' }
  377:       split(/\,/,$dynmeta{$cat.'_list'}))."</ul></font></td></tr>\n");
  378:    }
  379:    foreach my $cat ('course') {
  380:        $r->print(
  381: '<tr><td bgcolor="#AAAAAA">'.$items{$cat}.'</td><td bgcolor="#CCCCCC">'.
  382: $dynmeta{$cat}.'<font size="-1"><ul>'.join("\n",
  383:       map { my %courseinfo=&Apache::lonnet::coursedescription($_);  
  384:  '<li><a href="/public/'.
  385:   $courseinfo{'domain'}.'/'.$courseinfo{'num'}.'/syllabus" target="preview">'.
  386:   $courseinfo{'description'}.'</a></li>' }
  387:       split(/\,/,$dynmeta{$cat.'_list'}))."</ul></font></td></tr>\n");
  388:    }
  389:        $r->print('</table>');
  390:    if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
  391:       $r->print(
  392: '<h4>'.&mt('Assessment Statistical Data').'</h4><table cellspacing=2 border=0>');
  393:       foreach ('stdno','avetries') {
  394:           $r->print(
  395: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  396: $dynmeta{$_}."&nbsp;</td></tr>\n");
  397:       }
  398:       foreach ('difficulty') {
  399:          $r->print(
  400: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  401: &diffgraph($dynmeta{$_})."</td></tr>\n");
  402:       }
  403:       $r->print('</table>');    
  404:    }
  405:    $r->print('<h4>'.&mt('Evaluation Data').'</h4><table cellspacing=2 border=0>');
  406:    foreach ('clear','depth','helpful','correct','technical') {
  407:        $r->print(
  408: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
  409: &evalgraph($dynmeta{$_})."</td></tr>\n");
  410:    }    
  411:    $r->print('</table>');
  412:    $disuri=~/^(\w+)\/(\w+)\//;   
  413:    if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
  414:        || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
  415:       $r->print(
  416:   '<h4>'.&mt('Evaluation Comments').' ('.&mt('visible to author and co-authors only').')</h4>'.
  417:       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
  418:       $r->print(
  419:    '<h4>'.&mt('Error Messages').' ('.
  420:           &mt('visible to author and co-authors only').')</h4>');
  421:       my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$1,$2);
  422:       foreach (keys %errormsgs) {
  423: 	if ($_=~/^\Q$disuri\E\_\d+$/) {
  424:           my %content=&Apache::lonmsg::unpackagemsg($errormsgs{$_});
  425: 	  $r->print('<b>'.$content{'time'}.'</b>: '.$content{'message'}.
  426:                     '<br />');
  427:         }
  428:       }      
  429:    }
  430: # ------------------------------------------------------------- All other stuff
  431:    $r->print(
  432:  '<h3>'.&mt('Additional Metadata (non-standard, parameters, exports)').'</h3>');
  433:    foreach (sort keys %content) {
  434:       my $name=$_;
  435:       unless ($name=~/\.display$/) {
  436: 	  my $display=&Apache::lonnet::metadata($uri,$name.'.display');
  437: 	  unless ($display) { $display=$name; };
  438: 	  my $otherinfo='';
  439: 	  foreach ('name','part','type','default') {
  440: 	      if (defined(&Apache::lonnet::metadata($uri,$name.'.'.$_))) {
  441: 		  $otherinfo.=' '.$_.'='.
  442: 		      &Apache::lonnet::metadata($uri,$name.'.'.$_).'; ';
  443: 	      }
  444: 	  }
  445: 	  $r->print('<b>'.$display.':</b> '.$content{$name});
  446: 	  if ($otherinfo) {
  447: 	      $r->print(' ('.$otherinfo.')');
  448: 	  }
  449: 	  $r->print("<br>\n");
  450:       }
  451:    }
  452:   }
  453: # ===================================================== End Resource Space Call
  454:  } else {
  455: # ===================================================== Construction Space Call
  456: 
  457: # ----------------------------------------------------------- Set document type
  458: 
  459:   $r->content_type('text/html');
  460:   $r->send_http_header;
  461: 
  462:   return OK if $r->header_only;
  463: # ---------------------------------------------------------------------- Header
  464:   my $bodytag=&Apache::loncommon::bodytag('Edit Catalog Information');
  465:   my $disuri=$uri;
  466:   my $fn=&Apache::lonnet::filelocation('',$uri);
  467:   $disuri=~s/^\/\~\w+//;
  468:   $disuri=~s/\.meta$//;
  469:   my $displayfile='Catalog Information for '.$disuri;
  470:   if ($disuri=~/\/default$/) {
  471:       my $dir=$disuri;
  472:       $dir=~s/default$//;
  473:       $displayfile=&mt('Default Cataloging Information for Directory').' '.
  474: 	  $dir;
  475:   }
  476:   %Apache::lonpublisher::metadatafields=();
  477:   %Apache::lonpublisher::metadatakeys=();
  478:   &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
  479:   $r->print(<<ENDEDIT);
  480: <html><head><title>Edit Catalog Information</title></head>
  481: $bodytag
  482: <h1>$displayfile</h1>
  483: <form method="post">
  484: ENDEDIT
  485:    foreach ('author','title','subject','keywords','abstract','notes',
  486:             'copyright','customdistributionfile','language',
  487:             'obsolete','obsoletereplacement') {
  488:        if ($ENV{'form.new_'.$_}) {
  489: 	   $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};
  490:        }
  491:        if (m/copyright/) {
  492: 	   $r->print(&Apache::lonpublisher::selectbox($_,'new_'.$_,
  493: 			       ($Apache::lonpublisher::metadatafields{$_}?
  494: 				$Apache::lonpublisher::metadatafields{$_}:'default'),
  495: 			       \&Apache::loncommon::copyrightdescription,
  496: 			       (&Apache::loncommon::copyrightids)));
  497:        } elsif (m/language/) {
  498: 	   $r->print(&Apache::lonpublisher::selectbox($_,'new_'.$_,
  499: 			      $Apache::lonpublisher::metadatafields{$_},
  500: 			      \&Apache::loncommon::languagedescription,
  501: 			      (&Apache::loncommon::languageids)));
  502:        } else {
  503: 	   $r->print(&Apache::lonpublisher::textfield($_,'new_'.$_,
  504: 			     $Apache::lonpublisher::metadatafields{$_}));
  505:        }
  506:    }
  507:    if ($ENV{'form.store'}) {
  508:       my $mfh;
  509:       unless ($mfh=Apache::File->new('>'.$fn)) {
  510:             $r->print(
  511:             '<p><font color=red>'.&mt('Could not write metadata').', '.
  512: 		      &mt('FAIL').'</font>');
  513:       } else {
  514:           foreach (sort keys %Apache::lonpublisher::metadatafields) {
  515:             unless ($_=~/\./) {
  516:                 my $unikey=$_;
  517:                 $unikey=~/^([A-Za-z]+)/;
  518:                 my $tag=$1;
  519:                 $tag=~tr/A-Z/a-z/;
  520:                 print $mfh "\n\<$tag";
  521:                 foreach 
  522:                   (split(/\,/,$Apache::lonpublisher::metadatakeys{$unikey})) {
  523:                     my $value=
  524:                        $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
  525:                     $value=~s/\"/\'\'/g;
  526:                     print $mfh ' '.$_.'="'.$value.'"';
  527:                 }
  528:                 print $mfh '>'.
  529:         &HTML::Entities::encode($Apache::lonpublisher::metadatafields{$unikey})
  530:                         .'</'.$tag.'>';
  531:             }
  532: 	  }
  533:           $r->print('<p>'.&mt('Wrote Metadata'));
  534:       }
  535:     }
  536:     $r->print(
  537:  '<br /><input type="submit" name="store" value="'.
  538: &mt('Store Catalog Information').'"></form></body></html>');
  539:     return OK;
  540:   }
  541: }
  542: 
  543: 1;
  544: __END__
  545: 
  546: 
  547: 
  548: 
  549: 
  550: 
  551: 

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