File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.64: download - view: text, annotated - select for diffs
Tue Apr 13 14:42:24 2004 UTC (20 years, 1 month ago) by matthew
Branches: MAIN
CVS tags: HEAD
Retabination.

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

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