File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.72: download - view: text, annotated - select for diffs
Thu Apr 15 18:06:29 2004 UTC (20 years, 2 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Neater prettyprint output for resources and less whitespace in the
output from &print_dynamic_metadata.

    1: # The LearningOnline Network with CAPA
    2: # Metadata display handler
    3: #
    4: # $Id: lonmeta.pm,v 1.72 2004/04/15 18:06:29 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:             my $title = &Apache::lonnet::gettitle($url);
  257:             if ($title eq '') {
  258:                 $title = 'Untitled';
  259:                 if ($url =~ /\.sequence$/) {
  260:                     $title .= ' Sequence';
  261:                 } elsif ($url =~ /\.page$/) {
  262:                     $title .= ' Page';
  263:                 } elsif ($url =~ /\.problem$/) {
  264:                     $title .= ' Problem';
  265:                 } elsif ($url =~ /\.html$/) {
  266:                     $title .= ' HTML document';
  267:                 } elsif ($url =~ m:/syllabus$:) {
  268:                     $title .= ' Syllabus';
  269:                 } 
  270:             }
  271:             $_ = '<b>'.$title.'</b> '.
  272:                 '<a href="'.$url.'" target="preview">'.
  273:                 '<font size="-1">'.$url.'</font>'.
  274:                 '</a>'
  275:         } split(/\s*\,\s*/,$value));
  276:     }
  277:     # Evaluations
  278:     if (($type eq 'clear') ||
  279: 	($type eq 'depth') ||
  280: 	($type eq 'helpful') ||
  281: 	($type eq 'correct') ||
  282: 	($type eq 'technical')) {
  283: 	return &evalgraph($value);
  284:     }
  285:     # Difficulty
  286:     if ($type eq 'difficulty') {
  287: 	return &diffgraph($value);
  288:     }
  289:     # List of courses
  290:     if ($type=~/\_list/) {
  291:         my @Courses = split(/\s*\,\s*/,$value);
  292:         my $Str;
  293:         foreach my $course (@Courses) {
  294:             my %courseinfo = &Apache::lonnet::coursedescription($course);
  295:             if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
  296:                 next;
  297:             }
  298:             if ($Str ne '') { $Str .= '<br />'; }
  299:             $Str .= '<a href="/public/'.$courseinfo{'domain'}.'/'.
  300:                 $courseinfo{'num'}.'/syllabus" target="preview">'.
  301:                 $courseinfo{'description'}.'</a>';
  302:         }
  303: 	return $Str;
  304:     }
  305:     # No pretty print found
  306:     return $value;
  307: }
  308: 
  309: # Pretty input of metadata field
  310: sub direct {
  311:     return shift;
  312: }
  313: 
  314: sub selectbox {
  315:     my ($name,$value,$functionref,@idlist)=@_;
  316:     if (! defined($functionref)) {
  317:         $functionref=\&direct;
  318:     }
  319:     my $selout='<select name="'.$name.'">';
  320:     foreach (@idlist) {
  321:         $selout.='<option value=\''.$_.'\'';
  322:         if ($_ eq $value) {
  323: 	    $selout.=' selected>'.&{$functionref}($_).'</option>';
  324: 	}
  325:         else {$selout.='>'.&{$functionref}($_).'</option>';}
  326:     }
  327:     return $selout.'</select>';
  328: }
  329: 
  330: sub relatedfield {
  331:     my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
  332:     if (! $relatedsearchflag) { 
  333:         return '';
  334:     }
  335:     if (! defined($relatedsep)) {
  336:         $relatedsep=' ';
  337:     }
  338:     if (! $show) {
  339:         return $relatedsep.'&nbsp;';
  340:     }
  341:     return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
  342: 	($relatedvalue?' checked="1"':'').' />';
  343: }
  344: 
  345: sub prettyinput {
  346:     my ($type,$value,$fieldname,$formname,
  347: 	$relatedsearchflag,$relatedsep,$relatedvalue)=@_;
  348:     # Language
  349:     if ($type eq 'language') {
  350: 	return &selectbox($fieldname,
  351: 			  $value,
  352: 			  \&Apache::loncommon::languagedescription,
  353: 			  (&Apache::loncommon::languageids)).
  354:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
  355:     }
  356:     # Copyright
  357:     if ($type eq 'copyright') {
  358: 	return &selectbox($fieldname,
  359: 			  $value,
  360: 			  \&Apache::loncommon::copyrightdescription,
  361: 			  (&Apache::loncommon::copyrightids)).
  362:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
  363:     }
  364:     # Gradelevels
  365:     if (($type eq 'lowestgradelevel') ||
  366: 	($type eq 'highestgradelevel')) {
  367: 	return &Apache::loncommon::select_level_form($value,$fieldname).
  368:             &relatedfield(0,$relatedsearchflag,$relatedsep);
  369:     }
  370:     # Obsolete
  371:     if ($type eq 'obsolete') {
  372: 	return '<input type="checkbox" name="'.$fieldname.'"'.
  373: 	    ($value?' checked="1"':'').' />'.
  374:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  375:     }
  376:     # Obsolete replacement file
  377:     if ($type eq 'obsoletereplacement') {
  378: 	return '<input type="text" name="'.$fieldname.
  379: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  380: 	    "('".$formname."','".$fieldname."'".
  381: 	    ",'')\">".&mt('Select').'</a>'.
  382:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  383:     }
  384:     # Customdistribution file
  385:     if ($type eq 'customdistributionfile') {
  386: 	return '<input type="text" name="'.$fieldname.
  387: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  388: 	    "('".$formname."','".$fieldname."'".
  389: 	    ",'rights')\">".&mt('Select').'</a>'.
  390:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  391:     }
  392:     # Dates
  393:     if (($type eq 'creationdate') ||
  394: 	($type eq 'lastrevisiondate')) {
  395: 	return 
  396:             &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
  397:             &relatedfield(0,$relatedsearchflag,$relatedsep);
  398:     }
  399:     # No pretty input found
  400:     $value=~s/^\s+//gs;
  401:     $value=~s/\s+$//gs;
  402:     $value=~s/\s+/ /gs;
  403:     $value=~s/\"/\&quod\;/gs;
  404:     return 
  405:         '<input type="text" name="'.$fieldname.'" size="80" '.
  406:         'value="'.$value.'" />'.
  407:         &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
  408:                       $relatedvalue); 
  409: }
  410: 
  411: # Main Handler
  412: sub handler {
  413:     my $r=shift;
  414:     #
  415:     my $uri=$r->uri;
  416:     #
  417:     # Check to see if this server is overloaded
  418:     my $loaderror=&Apache::lonnet::overloaderror($r);
  419:     if ($loaderror) { 
  420:         return $loaderror;
  421:     }
  422:     #
  423:     # Check to see if original resource server is overloaded
  424:     my ($resdomain,$resuser)=
  425:         (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
  426:     $loaderror=&Apache::lonnet::overloaderror
  427:         ($r,&Apache::lonnet::homeserver($resuser,$resdomain));
  428:     if ($loaderror) { 
  429:         return $loaderror;
  430:     }
  431:     #
  432:     # Set document type
  433:     &Apache::loncommon::content_type($r,'text/html');
  434:     $r->send_http_header;
  435:     return OK if $r->header_only;
  436:     #
  437:     $r->print('<html><head><title>'.
  438:               'Catalog Information'.
  439:               '</title></head>');
  440:     if ($uri=~m:/adm/bombs/(.*)$:) {
  441:         $r->print(&Apache::loncommon::bodytag('Error Messages'));
  442:         # Looking for all bombs?
  443:         &report_bombs($r,$uri);
  444:     } elsif ($uri=~/^\/\~/) { 
  445:         # Construction space
  446:         $r->print(&Apache::loncommon::bodytag
  447:                   ('Edit Catalog Information','','','',$resdomain));
  448:         &present_editable_metadata($r,$uri);
  449:     } else {
  450:         $r->print(&Apache::loncommon::bodytag
  451:                   ('Catalog Information','','','',$resdomain));
  452:         &present_uneditable_metadata($r,$uri);
  453:     }
  454:     $r->print('</body></html>');
  455:     return OK;
  456: }
  457: 
  458: #####################################################
  459: #####################################################
  460: ###                                               ###
  461: ###                Report Bombs                   ###
  462: ###                                               ###
  463: #####################################################
  464: #####################################################
  465: sub report_bombs {
  466:     my ($r,$uri) = @_;
  467:     # Set document type
  468:     $uri =~ s:/adm/bombs/::;
  469:     $uri = &Apache::lonnet::declutter($uri);
  470:     $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
  471:     my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
  472:     if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
  473:         my %brokenurls = 
  474:             &Apache::lonmsg::all_url_author_res_msg($author,$domain);
  475:         foreach (sort(keys(%brokenurls))) {
  476:             if ($_=~/^\Q$uri\E/) {
  477:                 $r->print
  478:                     ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
  479:                      &Apache::lonmsg::retrieve_author_res_msg($_).
  480:                      '<hr />');
  481:             }
  482:         }
  483:     } else {
  484:         $r->print(&mt('Not authorized'));
  485:     }
  486:     return;
  487: }
  488: 
  489: #####################################################
  490: #####################################################
  491: ###                                               ###
  492: ###        Uneditable Metadata Display            ###
  493: ###                                               ###
  494: #####################################################
  495: #####################################################
  496: sub present_uneditable_metadata {
  497:     my ($r,$uri) = @_;
  498:     #
  499:     my %content=();
  500:     # Read file
  501:     foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
  502:         $content{$_}=&Apache::lonnet::metadata($uri,$_);
  503:     }
  504:     # Render Output
  505:     # displayed url
  506:     my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
  507:     $uri=~s/\.meta$//;
  508:     my $disuri=&Apache::lonnet::clutter($uri);
  509:     # version
  510:     my $currentversion=&Apache::lonnet::getversion($disuri);
  511:     my $versiondisplay='';
  512:     if ($thisversion) {
  513:         $versiondisplay=&mt('Version').': '.$thisversion.
  514:             ' ('.&mt('most recent version').': '.
  515:             ($currentversion>0 ? 
  516:              $currentversion   :
  517:              &mt('information not available')).')';
  518:     } else {
  519:         $versiondisplay='Version: '.$currentversion;
  520:     }
  521:     # crumbify displayed URL               uri     target prefix form  size
  522:     $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
  523:     $disuri =~ s:<br />::g;
  524:     # obsolete
  525:     my $obsolete=$content{'obsolete'};
  526:     my $obsoletewarning='';
  527:     if (($obsolete) && ($ENV{'user.adv'})) {
  528:         $obsoletewarning='<p><font color="red">'.
  529:             &mt('This resource has been marked obsolete by the author(s)').
  530:             '</font></p>';
  531:     }
  532:     #
  533:     my %lt=&fieldnames();
  534:     my $table='';
  535:     my $title = $content{'title'};
  536:     if (! defined($title)) {
  537:         $title = 'Untitled Resource';
  538:     }
  539:     foreach ('title', 
  540:              'author', 
  541:              'subject', 
  542:              'keywords', 
  543:              'notes', 
  544:              'abstract',
  545:              'lowestgradelevel',
  546:              'highestgradelevel',
  547:              'standards', 
  548:              'mime', 
  549:              'language', 
  550:              'creationdate', 
  551:              'lastrevisiondate', 
  552:              'owner', 
  553:              'copyright', 
  554:              'customdistributionfile', 
  555:              'obsolete', 
  556:              'obsoletereplacement') {
  557:         $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
  558:             '</td><td bgcolor="#CCCCCC">'.
  559:             &prettyprint($_,$content{$_}).'</td></tr>';
  560:         delete $content{$_};
  561:     }
  562:     #
  563:     $r->print(<<ENDHEAD);
  564: <h2>$title</h2>
  565: <p>
  566: $disuri<br />
  567: $obsoletewarning
  568: $versiondisplay
  569: </p>
  570: <table cellspacing=2 border=0>
  571: $table
  572: </table>
  573: ENDHEAD
  574:     if ($ENV{'user.adv'}) {
  575:         &print_dynamic_metadata($r,$uri,\%content);
  576:     }
  577:     return;
  578: }
  579: 
  580: sub print_dynamic_metadata {
  581:     my ($r,$uri,$content) = @_;
  582:     #
  583:     my %content = %$content;
  584:     my %lt=&fieldnames();
  585:     #
  586:     my $description = 'Dynamic Metadata (updated periodically)';
  587:     $r->print('<h3>'.&mt($description).'</h3>'.
  588:               &mt('Processing'));
  589:     $r->rflush();
  590:     my %items=&fieldnames();
  591:     my %dynmeta=&dynamicmeta($uri);
  592:     #
  593:     # General Access and Usage Statistics
  594:     if (exists($dynmeta{'count'}) ||
  595:         exists($dynmeta{'sequsage'}) ||
  596:         exists($dynmeta{'comefrom'}) ||
  597:         exists($dynmeta{'goto'}) ||
  598:         exists($dynmeta{'course'})) {
  599:         $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
  600:                   '<table cellspacing=2 border=0>');
  601:         foreach ('count',
  602:                  'sequsage','sequsage_list',
  603:                  'comefrom','comefrom_list',
  604:                  'goto','goto_list',
  605:                  'course','course_list') {
  606:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  607:                       '<td bgcolor="#CCCCCC">'.
  608:                       &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  609:         }
  610:         $r->print('</table>');
  611:     } else {
  612:         $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
  613:     }
  614:     #
  615:     # Assessment statistics
  616:     if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/ &&
  617:         (exists($dynmeta{'stdno'}) ||
  618:          exists($dynmeta{'avetries'}) ||
  619:          exists($dynmeta{'difficulty'}))) {
  620:         # This is an assessment, print assessment data
  621:         $r->print('<h4>'.&mt('Assessment Statistical Data').'</h4>'.
  622:                   '<table cellspacing=2 border=0>');
  623:         foreach ('stdno','avetries','difficulty') {
  624:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  625:                       '<td bgcolor="#CCCCCC">'.
  626:                       &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).'</td>'.
  627:                       "</tr>\n");
  628:         }
  629:         $r->print('</table>');    
  630:     } else {
  631:         $r->print('<h4>'.&mt('No Assessment Statistical Data is available for this resource').'</h4>');
  632:     }
  633:     if (exists($dynmeta{'clear'})   || 
  634:         exists($dynmeta{'depth'})   || 
  635:         exists($dynmeta{'helpful'}) || 
  636:         exists($dynmeta{'correct'}) || 
  637:         exists($dynmeta{'technical'})){ 
  638:         $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
  639:                   '<table cellspacing=2 border=0>');
  640:         foreach ('clear','depth','helpful','correct','technical') {
  641:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  642:                       '<td bgcolor="#CCCCCC">'.
  643:                       &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  644:         }
  645:         $r->print('</table>');
  646:     } else {
  647:         $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
  648:     }
  649:     $uri=~/^\/res\/(\w+)\/(\w+)\//; 
  650:     if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
  651:         || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
  652:         if (exists($dynmeta{'comments'})) {
  653:             $r->print('<h4>'.&mt('Evaluation Comments').' ('.
  654:                       &mt('visible to author and co-authors only').
  655:                       ')</h4>'.
  656:                       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
  657:         } else {
  658:             $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
  659:         }
  660:         my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
  661:         if (defined($bombs) && $bombs ne '') {
  662:             $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
  663:                       &mt('visible to author and co-authors only').')'.
  664:                       '</h4>'.$bombs);
  665:         } else {
  666:             $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
  667:         }
  668:     }
  669:     #
  670:     # All other stuff
  671:     $r->print('<h3>'.
  672:               &mt('Additional Metadata (non-standard, parameters, exports)').
  673:               '</h3>');
  674:     foreach (sort(keys(%content))) {
  675:         my $name=$_;
  676:         if ($name!~/\.display$/) {
  677:             my $display=&Apache::lonnet::metadata($uri,
  678:                                                   $name.'.display');
  679:             if (! $display) { 
  680:                 $display=$name;
  681:             };
  682:             my $otherinfo='';
  683:             foreach ('name','part','type','default') {
  684:                 if (defined(&Apache::lonnet::metadata($uri,
  685:                                                       $name.'.'.$_))) {
  686:                     $otherinfo.=' '.$_.'='.
  687:                         &Apache::lonnet::metadata($uri,
  688:                                                   $name.'.'.$_).'; ';
  689:                 }
  690:             }
  691:             $r->print('<b>'.$display.':</b> '.$content{$name});
  692:             if ($otherinfo) {
  693:                 $r->print(' ('.$otherinfo.')');
  694:             }
  695:             $r->print("<br />\n");
  696:         }
  697:     }
  698:     return;
  699: }
  700: 
  701: #####################################################
  702: #####################################################
  703: ###                                               ###
  704: ###          Editable metadata display            ###
  705: ###                                               ###
  706: #####################################################
  707: #####################################################
  708: sub present_editable_metadata {
  709:     my ($r,$uri) = @_;
  710:     # Construction Space Call
  711:     # Header
  712:     my $disuri=$uri;
  713:     my $fn=&Apache::lonnet::filelocation('',$uri);
  714:     $disuri=~s/^\/\~/\/priv\//;
  715:     $disuri=~s/\.meta$//;
  716:     my $target=$uri;
  717:     $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
  718:     $target=~s/\.meta$//;
  719:     my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
  720:     if ($bombs) {
  721:         if ($ENV{'form.delmsg'}) {
  722:             if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
  723:                 $bombs=&mt('Messages deleted.');
  724:             } else {
  725:                 $bombs=&mt('Error deleting messages');
  726:             }
  727:         }
  728:         my $del=&mt('Delete Messages');
  729:         $r->print(<<ENDBOMBS);
  730: <h1>$disuri</h1>
  731: <form method="post" name="defaultmeta">
  732: <input type="submit" name="delmsg" value="$del" />
  733: <br />$bombs
  734: ENDBOMBS
  735:     } else {
  736:         my $displayfile='Catalog Information for '.$disuri;
  737:         if ($disuri=~/\/default$/) {
  738:             my $dir=$disuri;
  739:             $dir=~s/default$//;
  740:             $displayfile=
  741:                 &mt('Default Cataloging Information for Directory').' '.
  742:                 $dir;
  743:         }
  744:         my $bodytag=
  745:             &Apache::loncommon::bodytag('Edit Catalog Information');
  746:         %Apache::lonpublisher::metadatafields=();
  747:         %Apache::lonpublisher::metadatakeys=();
  748:         &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
  749:         $r->print(<<ENDEDIT);
  750: <html><head><title>Edit Catalog Information</title></head>
  751: $bodytag
  752: <h1>$displayfile</h1>
  753: <form method="post" name="defaultmeta">
  754: ENDEDIT
  755:         $r->print('<script language="JavaScript">'.
  756:                   &Apache::loncommon::browser_and_searcher_javascript.
  757:                   '</script>');
  758:         my %lt=&fieldnames();
  759:         foreach ('author','title','subject','keywords','abstract','notes',
  760:                  'copyright','customdistributionfile','language',
  761:                  'standards',
  762:                  'lowestgradelevel','highestgradelevel',
  763:                  'obsolete','obsoletereplacement') {
  764:             if (defined($ENV{'form.new_'.$_})) {
  765:                 $Apache::lonpublisher::metadatafields{$_}=
  766:                     $ENV{'form.new_'.$_};
  767:             }
  768:             if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
  769:                 $Apache::lonpublisher::metadatafields{'copyright'}=
  770:                     'default';
  771:             }
  772:             $r->print('<p>'.$lt{$_}.': '.
  773:                       &prettyinput
  774:                       ($_,$Apache::lonpublisher::metadatafields{$_},
  775:                        'new_'.$_,'defaultmeta').'</p>');
  776:         }
  777:         if ($ENV{'form.store'}) {
  778:             my $mfh;
  779:             if (!  ($mfh=Apache::File->new('>'.$fn))) {
  780:                 $r->print('<p><font color=red>'.
  781:                           &mt('Could not write metadata').', '.
  782:                           &mt('FAIL').'</font>');
  783:             } else {
  784:                 foreach (sort keys %Apache::lonpublisher::metadatafields) {
  785:                     next if ($_ =~ /\./);
  786:                     my $unikey=$_;
  787:                     $unikey=~/^([A-Za-z]+)/;
  788:                     my $tag=$1;
  789:                     $tag=~tr/A-Z/a-z/;
  790:                     print $mfh "\n\<$tag";
  791:                     foreach (split(/\,/,
  792:                                  $Apache::lonpublisher::metadatakeys{$unikey})
  793:                              ) {
  794:                         my $value=
  795:                          $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
  796:                         $value=~s/\"/\'\'/g;
  797:                         print $mfh ' '.$_.'="'.$value.'"';
  798:                     }
  799:                     print $mfh '>'.
  800:                         &HTML::Entities::encode
  801:                         ($Apache::lonpublisher::metadatafields{$unikey},
  802:                          '<>&"').
  803:                          '</'.$tag.'>';
  804:                 }
  805:                 $r->print('<p>'.&mt('Wrote Metadata'));
  806:             }
  807:         }
  808:         $r->print('<br /><input type="submit" name="store" value="'.
  809:                   &mt('Store Catalog Information').'">');
  810:     }
  811:     $r->print('</form>');
  812:     return;
  813: }
  814: 
  815: 1;
  816: __END__

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