File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.65: download - view: text, annotated - select for diffs
Tue Apr 13 15:41:19 2004 UTC (20 years, 2 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
ununlessing.

    1: # The LearningOnline Network with CAPA
    2: # Metadata display handler
    3: #
    4: # $Id: lonmeta.pm,v 1.65 2004/04/13 15:41:19 matthew 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: 
   29: package Apache::lonmeta;
   30: 
   31: use strict;
   32: use LONCAPA::lonmetadata();
   33: use Apache::Constants qw(:common);
   34: use Apache::lonnet();
   35: use Apache::loncommon();
   36: use Apache::lonhtmlcommon();
   37: use Apache::lonmsg;
   38: use Apache::lonpublisher;
   39: use Apache::lonlocal;
   40: use Apache::lonmysql;
   41: use Apache::lonmsg;
   42: 
   43: # MySQL table columns
   44: 
   45: my @columns;
   46: 
   47: # Fetch and evaluate dynamic metadata
   48: sub dynamicmeta {
   49:     my $url=&Apache::lonnet::declutter(shift);
   50:     $url=~s/\.meta$//;
   51:     my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
   52:     my $regexp=$url;
   53:     $regexp=~s/(\W)/\\$1/g;
   54:     $regexp='___'.$regexp.'___';
   55:     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
   56: 				       $aauthor,$regexp);
   57:     my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
   58:     my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
   59:                                                                \%DynamicData);
   60:     #
   61:     # Deal with 'count' separately
   62:     $Data{'count'} = &access_count($url,$aauthor,$adomain);
   63:     return %Data;
   64: }
   65: 
   66: sub access_count {
   67:     my ($src,$author,$adomain) = @_;
   68:     my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
   69:                                         $author,$src);
   70:     if (! exists($countdata{$src})) {
   71:         return &mt('Not Available');
   72:     } else {
   73:         return $countdata{$src};
   74:     }
   75: }
   76: 
   77: # Try to make an alt tag if there is none
   78: sub alttag {
   79:     my ($base,$src)=@_;
   80:     my $fullpath=&Apache::lonnet::hreflocation($base,$src);
   81:     my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
   82:         &Apache::lonnet::metadata($fullpath,'subject').' '.
   83:         &Apache::lonnet::metadata($fullpath,'abstract');
   84:     $alttag=~s/\s+/ /gs;
   85:     $alttag=~s/\"//gs;
   86:     $alttag=~s/\'//gs;
   87:     $alttag=~s/\s+$//gs;
   88:     $alttag=~s/^\s+//gs;
   89:     if ($alttag) { 
   90:         return $alttag; 
   91:     } else { 
   92:         return &mt('No information available'); 
   93:     }
   94: }
   95: 
   96: # Author display
   97: sub authordisplay {
   98:     my ($aname,$adom)=@_;
   99:     return &Apache::loncommon::aboutmewrapper
  100:         (&Apache::loncommon::plainname($aname,$adom),
  101:          $aname,$adom,'preview').' <tt>['.$aname.'@'.$adom.']</tt>';
  102: }
  103: 
  104: # Pretty display
  105: sub evalgraph {
  106:     my $value=shift;
  107:     if (! $value) { 
  108:         return '';
  109:     }
  110:     my $val=int($value*10.+0.5)-10;
  111:     my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
  112:     if ($val>=20) {
  113: 	$output.='<td width=20 bgcolor="#555555">&nbsp&nbsp;</td>';
  114:     } else {
  115:         $output.='<td width='.($val).' bgcolor="#555555">&nbsp;</td>'.
  116:                  '<td width='.(20-$val).' bgcolor="#FF3333">&nbsp;</td>';
  117:     }
  118:     $output.='<td bgcolor="#FFFF33">&nbsp;</td>';
  119:     if ($val>20) {
  120: 	$output.='<td width='.($val-20).' bgcolor="#33FF33">&nbsp;</td>'.
  121:                  '<td width='.(40-$val).' bgcolor="#555555">&nbsp;</td>';
  122:     } else {
  123:         $output.='<td width=20 bgcolor="#555555">&nbsp&nbsp;</td>';
  124:     }
  125:     $output.='<td> ('.$value.') </td></tr></table>';
  126:     return $output;
  127: }
  128: 
  129: sub diffgraph {
  130:     my $value=shift;
  131:     if (! $value) { 
  132:         return '';
  133:     }
  134:     my $val=int(40.0*$value+0.5);
  135:     my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
  136:                 '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
  137:     my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
  138:     for (my $i=0;$i<8;$i++) {
  139: 	if ($val>$i*5) {
  140:             $output.='<td width=5 bgcolor="'.$colors[$i].'">&nbsp;</td>';
  141:         } else {
  142: 	    $output.='<td width=5 bgcolor="#555555">&nbsp;</td>';
  143: 	}
  144:     }
  145:     $output.='<td> ('.$value.') </td></tr></table>';
  146:     return $output;
  147: }
  148: 
  149: # Turn MySQL row into hash
  150: sub metadata_col_to_hash {
  151:     my @cols=@_;
  152:     my %hash=();
  153:     for (my $i=0; $i<=$#columns; $i++) {
  154: 	$hash{$columns[$i]}=$cols[$i];
  155:     }
  156:     return %hash;
  157: }
  158: 
  159: # The field names
  160: sub fieldnames {
  161:     return &Apache::lonlocal::texthash
  162:         (
  163:          'title' => 'Title',
  164:          'author' =>'Author(s)',
  165:          'authorspace' => 'Author Space',
  166:          'modifyinguser' => 'Last Modifying User',
  167:          'subject' => 'Subject',
  168:          'keywords' => 'Keyword(s)',
  169:          'notes' => 'Notes',
  170:          'abstract' => 'Abstract',
  171:          'lowestgradelevel' => 'Lowest Grade Level',
  172:          'highestgradelevel' => 'Highest Grade Level',
  173:          'standards' => 'Standards',
  174:          'mime' => 'MIME Type',
  175:          'language' => 'Language',
  176:          'creationdate' => 'Creation Date',
  177:          'lastrevisiondate' => 'Last Revision Date',
  178:          'owner' => 'Publisher/Owner',
  179:          'copyright' => 'Copyright/Distribution',
  180:          'customdistributionfile' => 'Custom Distribution File',
  181:          'obsolete' => 'Obsolete',
  182:          'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
  183:          'count'      => 'Network-wide number of accesses (hits)',
  184:          'course'     => 'Network-wide number of courses using resource',
  185:          'course_list' => 'Network-wide courses using resource',
  186:          'sequsage'      => 'Number of resources using or importing resource',
  187:          'sequsage_list' => 'Resources using or importing resource',
  188:          'goto'       => 'Number of resources that follow this resource in maps',
  189:          'goto_list'  => 'Resources that follow this resource in maps',
  190:          'comefrom'   => 'Number of resources that lead up to this resource in maps',
  191:          'comefrom_list' => 'Resources that lead up to this resource in maps',
  192:          'clear'      => 'Material presented in clear way',
  193:          'depth'      => 'Material covered with sufficient depth',
  194:          'helpful'    => 'Material is helpful',
  195:          'correct'    => 'Material appears to be correct',
  196:          'technical'  => 'Resource is technically correct', 
  197:          'avetries'   => 'Average number of tries till solved',
  198:          'stdno'      => 'Total number of students who have worked on this problem',
  199:          'difficulty' => 'Degree of difficulty'
  200:          );
  201: }
  202: 
  203: # Pretty printing of metadata field
  204: 
  205: sub prettyprint {
  206:     my ($type,$value)=@_;
  207:     if (! defined($value)) { 
  208:         return '&nbsp;'; 
  209:     }
  210:     # Title
  211:     if ($type eq 'title') {
  212: 	return '<font size="+1" face="arial">'.$value.'</font>';
  213:     }
  214:     # Dates
  215:     if (($type eq 'creationdate') ||
  216: 	($type eq 'lastrevisiondate')) {
  217: 	return ($value?&Apache::lonlocal::locallocaltime(
  218: 			  &Apache::lonmysql::unsqltime($value)):
  219: 		&mt('not available'));
  220:     }
  221:     # Language
  222:     if ($type eq 'language') {
  223: 	return &Apache::loncommon::languagedescription($value);
  224:     }
  225:     # Copyright
  226:     if ($type eq 'copyright') {
  227: 	return &Apache::loncommon::copyrightdescription($value);
  228:     }
  229:     # MIME
  230:     if ($type eq 'mime') {
  231:         return '<img src="'.&Apache::loncommon::icon($value).'" />&nbsp;'.
  232:             &Apache::loncommon::filedescription($value);
  233:     }
  234:     # Person
  235:     if (($type eq 'author') || 
  236: 	($type eq 'owner') ||
  237: 	($type eq 'modifyinguser') ||
  238: 	($type eq 'authorspace')) {
  239: 	$value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
  240: 	return $value;
  241:     }
  242:     # Gradelevel
  243:     if (($type eq 'lowestgradelevel') ||
  244: 	($type eq 'highestgradelevel')) {
  245: 	return &Apache::loncommon::gradeleveldescription($value);
  246:     }
  247:     # Only for advance users below
  248:     if (! $ENV{'user.adv'}) { 
  249:         return '<i>- '.&mt('not displayed').' -</i>';
  250:     }
  251:     # File
  252:     if (($type eq 'customdistributionfile') ||
  253: 	($type eq 'obsoletereplacement') ||
  254: 	($type eq 'goto_list') ||
  255: 	($type eq 'comefrom_list') ||
  256: 	($type eq 'sequsage_list')) {
  257: 	return join('<br />',map {
  258:             my $url=&Apache::lonnet::clutter($_);
  259:             '<b>'.&Apache::lonnet::gettitle($url).'</b>'.
  260:                 &Apache::lonhtmlcommon::crumbs($url,'preview','',undef,'+0');
  261:         } split(/\s*\,\s*/,$value));
  262:     }
  263:     # Evaluations
  264:     if (($type eq 'clear') ||
  265: 	($type eq 'depth') ||
  266: 	($type eq 'helpful') ||
  267: 	($type eq 'correct') ||
  268: 	($type eq 'technical')) {
  269: 	return &evalgraph($value);
  270:     }
  271:     # Difficulty
  272:     if ($type eq 'difficulty') {
  273: 	return &diffgraph($value);
  274:     }
  275:     # List of courses
  276:     if ($type=~/\_list/) {
  277: 	return join('<br />',map {
  278: 	    my %courseinfo=&Apache::lonnet::coursedescription($_);  
  279: 	    '<a href="/public/'.
  280: 		$courseinfo{'domain'}.'/'.$courseinfo{'num'}.'/syllabus" target="preview">'.
  281: 		$courseinfo{'description'}.'</a>';
  282: 	} split(/\s*\,\s*/,$value));
  283:     }
  284:     # No pretty print found
  285:     return $value;
  286: }
  287: 
  288: # Pretty input of metadata field
  289: sub direct {
  290:     return shift;
  291: }
  292: 
  293: sub selectbox {
  294:     my ($name,$value,$functionref,@idlist)=@_;
  295:     if (! defined($functionref)) {
  296:         $functionref=\&direct;
  297:     }
  298:     my $selout='<select name="'.$name.'">';
  299:     foreach (@idlist) {
  300:         $selout.='<option value=\''.$_.'\'';
  301:         if ($_ eq $value) {
  302: 	    $selout.=' selected>'.&{$functionref}($_).'</option>';
  303: 	}
  304:         else {$selout.='>'.&{$functionref}($_).'</option>';}
  305:     }
  306:     return $selout.'</select>';
  307: }
  308: 
  309: sub relatedfield {
  310:     my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
  311:     if (! $relatedsearchflag) { 
  312:         return '';
  313:     }
  314:     if (! defined($relatedsep)) {
  315:         $relatedsep=' ';
  316:     }
  317:     if (! $show) {
  318:         return $relatedsep.'&nbsp;';
  319:     }
  320:     return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
  321: 	($relatedvalue?' checked="1"':'').' />';
  322: }
  323: 
  324: sub prettyinput {
  325:     my ($type,$value,$fieldname,$formname,
  326: 	$relatedsearchflag,$relatedsep,$relatedvalue)=@_;
  327:     # Language
  328:     if ($type eq 'language') {
  329: 	return &selectbox($fieldname,
  330: 			  $value,
  331: 			  \&Apache::loncommon::languagedescription,
  332: 			  (&Apache::loncommon::languageids)).
  333:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
  334:     }
  335:     # Copyright
  336:     if ($type eq 'copyright') {
  337: 	return &selectbox($fieldname,
  338: 			  $value,
  339: 			  \&Apache::loncommon::copyrightdescription,
  340: 			  (&Apache::loncommon::copyrightids)).
  341:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
  342:     }
  343:     # Gradelevels
  344:     if (($type eq 'lowestgradelevel') ||
  345: 	($type eq 'highestgradelevel')) {
  346: 	return &Apache::loncommon::select_level_form($value,$fieldname).
  347:             &relatedfield(0,$relatedsearchflag,$relatedsep);
  348:     }
  349:     # Obsolete
  350:     if ($type eq 'obsolete') {
  351: 	return '<input type="checkbox" name="'.$fieldname.'"'.
  352: 	    ($value?' checked="1"':'').' />'.
  353:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  354:     }
  355:     # Obsolete replacement file
  356:     if ($type eq 'obsoletereplacement') {
  357: 	return '<input type="text" name="'.$fieldname.
  358: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  359: 	    "('".$formname."','".$fieldname."'".
  360: 	    ",'')\">".&mt('Select').'</a>'.
  361:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  362:     }
  363:     # Customdistribution file
  364:     if ($type eq 'customdistributionfile') {
  365: 	return '<input type="text" name="'.$fieldname.
  366: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  367: 	    "('".$formname."','".$fieldname."'".
  368: 	    ",'rights')\">".&mt('Select').'</a>'.
  369:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  370:     }
  371:     # Dates
  372:     if (($type eq 'creationdate') ||
  373: 	($type eq 'lastrevisiondate')) {
  374: 	return 
  375:             &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
  376:             &relatedfield(0,$relatedsearchflag,$relatedsep);
  377:     }
  378:     # No pretty input found
  379:     $value=~s/^\s+//gs;
  380:     $value=~s/\s+$//gs;
  381:     $value=~s/\s+/ /gs;
  382:     $value=~s/\"/\&quod\;/gs;
  383:     return 
  384:         '<input type="text" name="'.$fieldname.'" size="80" '.
  385:         'value="'.$value.'" />'.
  386:         &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
  387:                       $relatedvalue); 
  388: }
  389: 
  390: # Main Handler
  391: sub handler {
  392:     my $r=shift;
  393:     #
  394:     my $loaderror=&Apache::lonnet::overloaderror($r);
  395:     if ($loaderror) { return $loaderror; }
  396:     #
  397:     my $uri=$r->uri;
  398:     #
  399:     # Looking for all bombs?
  400:     if ($uri=~/\/adm\/bombs\/(.*)$/) {
  401:         # Set document type
  402:         $uri=&Apache::lonnet::declutter($1);
  403:         &Apache::loncommon::content_type($r,'text/html');
  404:         $r->send_http_header;
  405:         #
  406:         return OK if $r->header_only;
  407:         $r->print(&Apache::loncommon::bodytag('Error Messages'));
  408:         $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
  409:         my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
  410:         if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
  411:             my %brokenurls=&Apache::lonmsg::all_url_author_res_msg($author,
  412:                                                                    $domain);
  413:             foreach (sort keys %brokenurls) {
  414:                 if ($_=~/^\Q$uri\E/) {
  415:                     $r->print(&Apache::lonhtmlcommon::crumbs
  416:                               (&Apache::lonnet::clutter($_)).
  417:                               &Apache::lonmsg::retrieve_author_res_msg($_).
  418:                               '<hr />');
  419:                 }
  420:             }
  421:         } else {
  422:             $r->print(&mt('Not authorized'));
  423:         }
  424:         $r->print('</body></html>');
  425:     } elsif ($uri!~/^\/\~/) { 
  426:         # This is not in construction space
  427:         my ($resdomain,$resuser)=
  428:             (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
  429:         $loaderror=&Apache::lonnet::overloaderror
  430:             ($r,
  431:              &Apache::lonnet::homeserver($resuser,$resdomain));
  432:         if ($loaderror) { return $loaderror; }
  433:         #
  434:         my %content=();
  435:         # Set document type
  436:         &Apache::loncommon::content_type($r,'text/html');
  437:         $r->send_http_header;
  438:         return OK if $r->header_only;
  439:         # Read file
  440:         foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
  441:             $content{$_}=&Apache::lonnet::metadata($uri,$_);
  442:         }
  443:         # Render Output
  444:         # displayed url
  445:         my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
  446:         $uri=~s/\.meta$//;
  447:         my $disuri=&Apache::lonnet::clutter($uri);
  448:         # version
  449:         my $currentversion=&Apache::lonnet::getversion($disuri);
  450:         my $versiondisplay='';
  451:         if ($thisversion) {
  452:             $versiondisplay=&mt('Version').': '.$thisversion.
  453:                 ' ('.&mt('most recent version').': '.
  454:                 ($currentversion>0 ? 
  455:                  $currentversion   :
  456:                  &mt('information not available')).')';
  457:         } else {
  458:             $versiondisplay='Version: '.$currentversion;
  459:         }
  460:         # crumbify displayed URL
  461:         $disuri=&Apache::lonhtmlcommon::crumbs($disuri);
  462:         # obsolete
  463:         my $obsolete=$content{'obsolete'};
  464:         my $obsoletewarning='';
  465:         if (($obsolete) && ($ENV{'user.adv'})) {
  466:             $obsoletewarning='<p><font color="red">'.
  467:                 &mt('This resource has been marked obsolete by the author(s)').
  468:                 '</font></p>';
  469:         }
  470:         #
  471:         my %lt=&fieldnames();
  472:         my $table='';
  473:         my $bodytag=&Apache::loncommon::bodytag
  474:             ('Catalog Information','','','',$resdomain);
  475:         foreach ('title', 
  476:                  'author', 
  477:                  'subject', 
  478:                  'keywords', 
  479:                  'notes', 
  480:                  'abstract',
  481:                  'lowestgradelevel',
  482:                  'highestgradelevel',
  483:                  'standards', 
  484:                  'mime', 
  485:                  'language', 
  486:                  'creationdate', 
  487:                  'lastrevisiondate', 
  488:                  'owner', 
  489:                  'copyright', 
  490:                  'customdistributionfile', 
  491:                  'obsolete', 
  492:                  'obsoletereplacement') {
  493:             $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
  494: 	        '</td><td bgcolor="#CCCCCC">'.
  495:                 &prettyprint($_,$content{$_}).'</td></tr>';
  496:             delete $content{$_};
  497:         }
  498:         #
  499:         $r->print(<<ENDHEAD);
  500: <html><head><title>Catalog Information</title></head>
  501: $bodytag
  502: <h2>$content{'title'}</h2>
  503: <h3><tt>$disuri</tt></h3>
  504: $obsoletewarning
  505: $versiondisplay<br />
  506: <table cellspacing=2 border=0>
  507: $table
  508: </table>
  509: ENDHEAD
  510:         if ($ENV{'user.adv'}) {
  511:             # Dynamic Metadata
  512:             $r->print(
  513:                       '<h3>'.&mt('Dynamic Metadata').' ('.
  514:                       &mt('updated periodically').')</h3>'.&mt('Processing').
  515:                       ' ...<br />');
  516:             $r->rflush();
  517:             my %items=&fieldnames();
  518:             my %dynmeta=&dynamicmeta($uri);
  519:             # General Access and Usage Statistics
  520:             $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
  521:                       '<table cellspacing=2 border=0>');
  522:             foreach ('count',
  523:                      'sequsage','sequsage_list',
  524:                      'comefrom','comefrom_list',
  525:                      'goto','goto_list',
  526:                      'course','course_list') {
  527:                 $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  528:                           '<td bgcolor="#CCCCCC">'.
  529:                           &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  530:             }
  531:             $r->print('</table>');
  532:             if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
  533:                 # This is an assessment, print assessment data
  534:                 $r->print(
  535:                           '<h4>'.&mt('Assessment Statistical Data').'</h4>'.
  536:                           '<table cellspacing=2 border=0>');
  537:                 foreach ('stdno','avetries','difficulty') {
  538:                     $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  539:                               '<td bgcolor="#CCCCCC">'.
  540:                               &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  541:                 }
  542:                 $r->print('</table>');    
  543:             }
  544:             $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
  545:                       '<table cellspacing=2 border=0>');
  546:             foreach ('clear','depth','helpful','correct','technical') {
  547:                 $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  548:                           '<td bgcolor="#CCCCCC">'.
  549:                           &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  550:             }
  551:             $r->print('</table>');
  552:             $uri=~/^\/res\/(\w+)\/(\w+)\//; 
  553:             if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
  554:                 || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
  555:                 $r->print('<h4>'.&mt('Evaluation Comments').' ('.
  556:                           &mt('visible to author and co-authors only').
  557:                           ')</h4>'.
  558:                           '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
  559:                 $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
  560:                           &mt('visible to author and co-authors only').')'.
  561:                           '</h4>'.
  562:                           &Apache::lonmsg::retrieve_author_res_msg($uri));
  563:             }
  564:             # All other stuff
  565:             $r->print('<h3>'.
  566:                 &mt('Additional Metadata (non-standard, parameters, exports)').
  567:                       '</h3>');
  568:             foreach (sort keys %content) {
  569:                 my $name=$_;
  570:                 if ($name!~/\.display$/) {
  571:                     my $display=&Apache::lonnet::metadata($uri,
  572:                                                           $name.'.display');
  573:                     if (! $display) { 
  574:                         $display=$name;
  575:                     };
  576:                     my $otherinfo='';
  577:                     foreach ('name','part','type','default') {
  578:                         if (defined(&Apache::lonnet::metadata($uri,
  579:                                                               $name.'.'.$_))) {
  580:                             $otherinfo.=' '.$_.'='.
  581:                                 &Apache::lonnet::metadata($uri,
  582:                                                           $name.'.'.$_).'; ';
  583:                         }
  584:                     }
  585:                     $r->print('<b>'.$display.':</b> '.$content{$name});
  586:                     if ($otherinfo) {
  587:                         $r->print(' ('.$otherinfo.')');
  588:                     }
  589:                     $r->print("<br />\n");
  590:                 }
  591:             }
  592:         }
  593:         # End Resource Space Call
  594:     } else {
  595:         # Construction Space Call
  596:         # Set document type
  597:         &Apache::loncommon::content_type($r,'text/html');
  598:         $r->send_http_header;
  599:         #
  600:         return OK if $r->header_only;
  601:         # Header
  602:         my $disuri=$uri;
  603:         my $fn=&Apache::lonnet::filelocation('',$uri);
  604:         $disuri=~s/^\/\~/\/priv\//;
  605:         $disuri=~s/\.meta$//;
  606:         my $target=$uri;
  607:         $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
  608:         $target=~s/\.meta$//;
  609:         my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
  610:         if ($bombs) {
  611:             if ($ENV{'form.delmsg'}) {
  612:                 if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
  613:                     $bombs=&mt('Messages deleted.');
  614:                 } else {
  615:                     $bombs=&mt('Error deleting messages');
  616:                 }
  617:             }
  618:             my $bodytag=&Apache::loncommon::bodytag('Error Messages');
  619:             my $del=&mt('Delete Messages');
  620:             $r->print(<<ENDBOMBS);
  621: <html><head><title>Edit Catalog Information</title></head>
  622: $bodytag
  623: <h1>$disuri</h1>
  624: <form method="post" name="defaultmeta">
  625: <input type="submit" name="delmsg" value="$del" />
  626: <br />$bombs
  627: </form>
  628: </body>
  629: </html>
  630: ENDBOMBS
  631:         } else {
  632:             my $displayfile='Catalog Information for '.$disuri;
  633:             if ($disuri=~/\/default$/) {
  634:                 my $dir=$disuri;
  635:                 $dir=~s/default$//;
  636:                 $displayfile=
  637:                     &mt('Default Cataloging Information for Directory').' '.
  638:                     $dir;
  639:             }
  640:             my $bodytag=
  641:                 &Apache::loncommon::bodytag('Edit Catalog Information');
  642:             %Apache::lonpublisher::metadatafields=();
  643:             %Apache::lonpublisher::metadatakeys=();
  644:             &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
  645:             $r->print(<<ENDEDIT);
  646: <html><head><title>Edit Catalog Information</title></head>
  647: $bodytag
  648: <h1>$displayfile</h1>
  649: <form method="post" name="defaultmeta">
  650: ENDEDIT
  651:             $r->print('<script language="JavaScript">'.
  652:                       &Apache::loncommon::browser_and_searcher_javascript.
  653:                       '</script>');
  654:             my %lt=&fieldnames();
  655:             foreach ('author','title','subject','keywords','abstract','notes',
  656:                      'copyright','customdistributionfile','language',
  657:                      'standards',
  658:                      'lowestgradelevel','highestgradelevel',
  659:                      'obsolete','obsoletereplacement') {
  660:                 if (defined($ENV{'form.new_'.$_})) {
  661:                     $Apache::lonpublisher::metadatafields{$_}=
  662:                         $ENV{'form.new_'.$_};
  663:                 }
  664:                 if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
  665:                     $Apache::lonpublisher::metadatafields{'copyright'}=
  666:                         'default';
  667:                 }
  668:                 $r->print('<p>'.$lt{$_}.': '.
  669:                           &prettyinput
  670:                           ($_,$Apache::lonpublisher::metadatafields{$_},
  671:                            'new_'.$_,'defaultmeta').'</p>');
  672:             }
  673:             if ($ENV{'form.store'}) {
  674:                 my $mfh;
  675:                 if (!  ($mfh=Apache::File->new('>'.$fn))) {
  676:                     $r->print('<p><font color=red>'.
  677:                               &mt('Could not write metadata').', '.
  678:                               &mt('FAIL').'</font>');
  679:                 } else {
  680:                     foreach (sort keys %Apache::lonpublisher::metadatafields) {
  681:                         if ($_!~/\./) {
  682:                             my $unikey=$_;
  683:                             $unikey=~/^([A-Za-z]+)/;
  684:                             my $tag=$1;
  685:                             $tag=~tr/A-Z/a-z/;
  686:                             print $mfh "\n\<$tag";
  687:                             foreach (split(/\,/,
  688:                                  $Apache::lonpublisher::metadatakeys{$unikey})
  689:                                      ) {
  690:                                 my $value=
  691:                         $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
  692:                                 $value=~s/\"/\'\'/g;
  693:                                 print $mfh ' '.$_.'="'.$value.'"';
  694:                             }
  695:                             print $mfh '>'.
  696:                                 &HTML::Entities::encode($Apache::lonpublisher::metadatafields{$unikey},'<>&"').
  697:                                 '</'.$tag.'>';
  698:                         }
  699:                     }
  700:                     $r->print('<p>'.&mt('Wrote Metadata'));
  701:                 }
  702:             }
  703:             $r->print('<br /><input type="submit" name="store" value="'.
  704:                       &mt('Store Catalog Information').'"></form>'.
  705:                       '</body></html>');
  706:         }
  707:     }
  708:     return OK;
  709: }
  710: 
  711: # BEGIN Block
  712: BEGIN {
  713:     # Get columns of MySQL metadata table
  714:     @columns=&Apache::lonmysql::col_order('metadata');
  715: }
  716: 
  717: 1;
  718: __END__

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