File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.71: download - view: text, annotated - select for diffs
Wed Apr 14 21:22:44 2004 UTC (20 years, 1 month ago) by matthew
Branches: MAIN
CVS tags: HEAD
&evalgraph and &diffgraph: Only output 2 digits beyond the decimal
point.  No need to report a degree of difficulty of 0.47474747474747.
Also xhtml-ized.

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

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