File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.79: download - view: text, annotated - select for diffs
Wed Jun 16 14:30:15 2004 UTC (20 years ago) by matthew
Branches: MAIN
CVS tags: HEAD
Remove debugging spew.

    1: # The LearningOnline Network with CAPA
    2: # Metadata display handler
    3: #
    4: # $Id: lonmeta.pm,v 1.79 2004/06/16 14:30:15 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:          'sourceavail' => 'Source Availible',
  179:          'sourcerights' => 'Source Custom Distribution File',
  180:          'obsolete' => 'Obsolete',
  181:          'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
  182:          'count'      => 'Network-wide number of accesses (hits)',
  183:          'course'     => 'Network-wide number of courses using resource',
  184:          'course_list' => 'Network-wide courses using resource',
  185:          'sequsage'      => 'Number of resources using or importing resource',
  186:          'sequsage_list' => 'Resources using or importing resource',
  187:          'goto'       => 'Number of resources that follow this resource in maps',
  188:          'goto_list'  => 'Resources that follow this resource in maps',
  189:          'comefrom'   => 'Number of resources that lead up to this resource in maps',
  190:          'comefrom_list' => 'Resources that lead up to this resource in maps',
  191:          'clear'      => 'Material presented in clear way',
  192:          'depth'      => 'Material covered with sufficient depth',
  193:          'helpful'    => 'Material is helpful',
  194:          'correct'    => 'Material appears to be correct',
  195:          'technical'  => 'Resource is technically correct', 
  196:          'avetries'   => 'Average number of tries till solved',
  197:          'stdno'      => 'Total number of students who have worked on this problem',
  198:          'difficulty' => 'Degree of difficulty',
  199:          'disc'       => 'Degree of discrimination',
  200:          );
  201: }
  202: 
  203: # Pretty printing of metadata field
  204: 
  205: sub prettyprint {
  206:     my ($type,$value)=@_;
  207:     if (! defined($value)) { 
  208:         return '&nbsp;'; 
  209:     }
  210:     # Title
  211:     if ($type eq 'title') {
  212: 	return '<font size="+1" face="arial">'.$value.'</font>';
  213:     }
  214:     # Dates
  215:     if (($type eq 'creationdate') ||
  216: 	($type eq 'lastrevisiondate')) {
  217: 	return ($value?&Apache::lonlocal::locallocaltime(
  218: 			  &Apache::lonmysql::unsqltime($value)):
  219: 		&mt('not available'));
  220:     }
  221:     # Language
  222:     if ($type eq 'language') {
  223: 	return &Apache::loncommon::languagedescription($value);
  224:     }
  225:     # Copyright
  226:     if ($type eq 'copyright') {
  227: 	return &Apache::loncommon::copyrightdescription($value);
  228:     }
  229:     # Copyright
  230:     if ($type eq 'sourceavail') {
  231: 	return &Apache::loncommon::source_copyrightdescription($value);
  232:     }
  233:     # MIME
  234:     if ($type eq 'mime') {
  235:         return '<img src="'.&Apache::loncommon::icon($value).'" />&nbsp;'.
  236:             &Apache::loncommon::filedescription($value);
  237:     }
  238:     # Person
  239:     if (($type eq 'author') || 
  240: 	($type eq 'owner') ||
  241: 	($type eq 'modifyinguser') ||
  242: 	($type eq 'authorspace')) {
  243: 	$value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
  244: 	return $value;
  245:     }
  246:     # Gradelevel
  247:     if (($type eq 'lowestgradelevel') ||
  248: 	($type eq 'highestgradelevel')) {
  249: 	return &Apache::loncommon::gradeleveldescription($value);
  250:     }
  251:     # Only for advance users below
  252:     if (! $ENV{'user.adv'}) { 
  253:         return '<i>- '.&mt('not displayed').' -</i>';
  254:     }
  255:     # File
  256:     if (($type eq 'customdistributionfile') ||
  257: 	($type eq 'obsoletereplacement') ||
  258: 	($type eq 'goto_list') ||
  259: 	($type eq 'comefrom_list') ||
  260: 	($type eq 'sequsage_list')) {
  261: 	return join('<br />',map {
  262:             my $url = &Apache::lonnet::clutter($_);
  263:             my $title = &Apache::lonnet::gettitle($url);
  264:             if ($title eq '') {
  265:                 $title = 'Untitled';
  266:                 if ($url =~ /\.sequence$/) {
  267:                     $title .= ' Sequence';
  268:                 } elsif ($url =~ /\.page$/) {
  269:                     $title .= ' Page';
  270:                 } elsif ($url =~ /\.problem$/) {
  271:                     $title .= ' Problem';
  272:                 } elsif ($url =~ /\.html$/) {
  273:                     $title .= ' HTML document';
  274:                 } elsif ($url =~ m:/syllabus$:) {
  275:                     $title .= ' Syllabus';
  276:                 } 
  277:             }
  278:             $_ = '<b>'.$title.'</b> '.
  279:                 '<a href="'.$url.'" target="preview">'.
  280:                 '<font size="-1">'.$url.'</font>'.
  281:                 '</a>'
  282:         } split(/\s*\,\s*/,$value));
  283:     }
  284:     # Evaluations
  285:     if (($type eq 'clear') ||
  286: 	($type eq 'depth') ||
  287: 	($type eq 'helpful') ||
  288: 	($type eq 'correct') ||
  289: 	($type eq 'technical')) {
  290: 	return &evalgraph($value);
  291:     }
  292:     # Difficulty
  293:     if ($type eq 'difficulty' || $type eq 'disc') {
  294: 	return &diffgraph($value);
  295:     }
  296:     # List of courses
  297:     if ($type=~/\_list/) {
  298:         my @Courses = split(/\s*\,\s*/,$value);
  299:         my $Str;
  300:         foreach my $course (@Courses) {
  301:             my %courseinfo = &Apache::lonnet::coursedescription($course);
  302:             if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
  303:                 next;
  304:             }
  305:             if ($Str ne '') { $Str .= '<br />'; }
  306:             $Str .= '<a href="/public/'.$courseinfo{'domain'}.'/'.
  307:                 $courseinfo{'num'}.'/syllabus" target="preview">'.
  308:                 $courseinfo{'description'}.'</a>';
  309:         }
  310: 	return $Str;
  311:     }
  312:     # No pretty print found
  313:     return $value;
  314: }
  315: 
  316: # Pretty input of metadata field
  317: sub direct {
  318:     return shift;
  319: }
  320: 
  321: sub selectbox {
  322:     my ($name,$value,$functionref,@idlist)=@_;
  323:     if (! defined($functionref)) {
  324:         $functionref=\&direct;
  325:     }
  326:     my $selout='<select name="'.$name.'">';
  327:     foreach (@idlist) {
  328:         $selout.='<option value=\''.$_.'\'';
  329:         if ($_ eq $value) {
  330: 	    $selout.=' selected>'.&{$functionref}($_).'</option>';
  331: 	}
  332:         else {$selout.='>'.&{$functionref}($_).'</option>';}
  333:     }
  334:     return $selout.'</select>';
  335: }
  336: 
  337: sub relatedfield {
  338:     my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
  339:     if (! $relatedsearchflag) { 
  340:         return '';
  341:     }
  342:     if (! defined($relatedsep)) {
  343:         $relatedsep=' ';
  344:     }
  345:     if (! $show) {
  346:         return $relatedsep.'&nbsp;';
  347:     }
  348:     return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
  349: 	($relatedvalue?' checked="1"':'').' />';
  350: }
  351: 
  352: sub prettyinput {
  353:     my ($type,$value,$fieldname,$formname,
  354: 	$relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
  355:     if (! defined($size)) {
  356:         $size = 80;
  357:     }
  358:     # Language
  359:     if ($type eq 'language') {
  360: 	return &selectbox($fieldname,
  361: 			  $value,
  362: 			  \&Apache::loncommon::languagedescription,
  363: 			  (&Apache::loncommon::languageids)).
  364:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
  365:     }
  366:     # Copyright
  367:     if ($type eq 'copyright') {
  368: 	return &selectbox($fieldname,
  369: 			  $value,
  370: 			  \&Apache::loncommon::copyrightdescription,
  371: 			  (&Apache::loncommon::copyrightids)).
  372:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
  373:     }
  374:     # Source Copyright
  375:     if ($type eq 'sourceavail') {
  376: 	return &selectbox($fieldname,
  377: 			  $value,
  378: 			  \&Apache::loncommon::source_copyrightdescription,
  379: 			  (&Apache::loncommon::source_copyrightids)).
  380:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
  381:     }
  382:     # Gradelevels
  383:     if (($type eq 'lowestgradelevel') ||
  384: 	($type eq 'highestgradelevel')) {
  385: 	return &Apache::loncommon::select_level_form($value,$fieldname).
  386:             &relatedfield(0,$relatedsearchflag,$relatedsep);
  387:     }
  388:     # Obsolete
  389:     if ($type eq 'obsolete') {
  390: 	return '<input type="checkbox" name="'.$fieldname.'"'.
  391: 	    ($value?' checked="1"':'').' />'.
  392:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  393:     }
  394:     # Obsolete replacement file
  395:     if ($type eq 'obsoletereplacement') {
  396: 	return '<input type="text" name="'.$fieldname.
  397: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  398: 	    "('".$formname."','".$fieldname."'".
  399: 	    ",'')\">".&mt('Select').'</a>'.
  400:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  401:     }
  402:     # Customdistribution file
  403:     if ($type eq 'customdistributionfile') {
  404: 	return '<input type="text" name="'.$fieldname.
  405: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  406: 	    "('".$formname."','".$fieldname."'".
  407: 	    ",'rights')\">".&mt('Select').'</a>'.
  408:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  409:     }
  410:     # Source Customdistribution file
  411:     if ($type eq 'sourcerights') {
  412: 	return '<input type="text" name="'.$fieldname.
  413: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  414: 	    "('".$formname."','".$fieldname."'".
  415: 	    ",'rights')\">".&mt('Select').'</a>'.
  416:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  417:     }
  418:     # Dates
  419:     if (($type eq 'creationdate') ||
  420: 	($type eq 'lastrevisiondate')) {
  421: 	return 
  422:             &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
  423:             &relatedfield(0,$relatedsearchflag,$relatedsep);
  424:     }
  425:     # No pretty input found
  426:     $value=~s/^\s+//gs;
  427:     $value=~s/\s+$//gs;
  428:     $value=~s/\s+/ /gs;
  429:     $value=~s/\"/\&quot\;/gs;
  430:     return 
  431:         '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
  432:         'value="'.$value.'" />'.
  433:         &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
  434:                       $relatedvalue); 
  435: }
  436: 
  437: # Main Handler
  438: sub handler {
  439:     my $r=shift;
  440:     #
  441:     my $uri=$r->uri;
  442:     #
  443:     # Set document type
  444:     &Apache::loncommon::content_type($r,'text/html');
  445:     $r->send_http_header;
  446:     return OK if $r->header_only;
  447:     #
  448:     my ($resdomain,$resuser)=
  449:         (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
  450:     $r->print('<html><head><title>'.
  451:               'Catalog Information'.
  452:               '</title></head>');
  453:     if ($uri=~m:/adm/bombs/(.*)$:) {
  454:         $r->print(&Apache::loncommon::bodytag('Error Messages'));
  455:         # Looking for all bombs?
  456:         &report_bombs($r,$uri);
  457:     } elsif ($uri=~/^\/\~/) { 
  458:         # Construction space
  459:         $r->print(&Apache::loncommon::bodytag
  460:                   ('Edit Catalog Information','','','',$resdomain));
  461:         &present_editable_metadata($r,$uri);
  462:     } else {
  463:         $r->print(&Apache::loncommon::bodytag
  464:                   ('Catalog Information','','','',$resdomain));
  465:         &present_uneditable_metadata($r,$uri);
  466:     }
  467:     $r->print('</body></html>');
  468:     return OK;
  469: }
  470: 
  471: #####################################################
  472: #####################################################
  473: ###                                               ###
  474: ###                Report Bombs                   ###
  475: ###                                               ###
  476: #####################################################
  477: #####################################################
  478: sub report_bombs {
  479:     my ($r,$uri) = @_;
  480:     # Set document type
  481:     $uri =~ s:/adm/bombs/::;
  482:     $uri = &Apache::lonnet::declutter($uri);
  483:     $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
  484:     my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
  485:     if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
  486:         my %brokenurls = 
  487:             &Apache::lonmsg::all_url_author_res_msg($author,$domain);
  488:         foreach (sort(keys(%brokenurls))) {
  489:             if ($_=~/^\Q$uri\E/) {
  490:                 $r->print
  491:                     ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
  492:                      &Apache::lonmsg::retrieve_author_res_msg($_).
  493:                      '<hr />');
  494:             }
  495:         }
  496:     } else {
  497:         $r->print(&mt('Not authorized'));
  498:     }
  499:     return;
  500: }
  501: 
  502: #####################################################
  503: #####################################################
  504: ###                                               ###
  505: ###        Uneditable Metadata Display            ###
  506: ###                                               ###
  507: #####################################################
  508: #####################################################
  509: sub present_uneditable_metadata {
  510:     my ($r,$uri) = @_;
  511:     #
  512:     my %content=();
  513:     # Read file
  514:     foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
  515:         $content{$_}=&Apache::lonnet::metadata($uri,$_);
  516:     }
  517:     # Render Output
  518:     # displayed url
  519:     my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
  520:     $uri=~s/\.meta$//;
  521:     my $disuri=&Apache::lonnet::clutter($uri);
  522:     # version
  523:     my $currentversion=&Apache::lonnet::getversion($disuri);
  524:     my $versiondisplay='';
  525:     if ($thisversion) {
  526:         $versiondisplay=&mt('Version').': '.$thisversion.
  527:             ' ('.&mt('most recent version').': '.
  528:             ($currentversion>0 ? 
  529:              $currentversion   :
  530:              &mt('information not available')).')';
  531:     } else {
  532:         $versiondisplay='Version: '.$currentversion;
  533:     }
  534:     # crumbify displayed URL               uri     target prefix form  size
  535:     $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
  536:     $disuri =~ s:<br />::g;
  537:     # obsolete
  538:     my $obsolete=$content{'obsolete'};
  539:     my $obsoletewarning='';
  540:     if (($obsolete) && ($ENV{'user.adv'})) {
  541:         $obsoletewarning='<p><font color="red">'.
  542:             &mt('This resource has been marked obsolete by the author(s)').
  543:             '</font></p>';
  544:     }
  545:     #
  546:     my %lt=&fieldnames();
  547:     my $table='';
  548:     my $title = $content{'title'};
  549:     if (! defined($title)) {
  550:         $title = 'Untitled Resource';
  551:     }
  552:     foreach ('title', 
  553:              'author', 
  554:              'subject', 
  555:              'keywords', 
  556:              'notes', 
  557:              'abstract',
  558:              'lowestgradelevel',
  559:              'highestgradelevel',
  560:              'standards', 
  561:              'mime', 
  562:              'language', 
  563:              'creationdate', 
  564:              'lastrevisiondate', 
  565:              'owner', 
  566:              'copyright', 
  567:              'customdistributionfile',
  568:              'sourceavail',
  569:              'sourcerights', 
  570:              'obsolete', 
  571:              'obsoletereplacement') {
  572:         $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
  573:             '</td><td bgcolor="#CCCCCC">'.
  574:             &prettyprint($_,$content{$_}).'</td></tr>';
  575:         delete $content{$_};
  576:     }
  577:     #
  578:     $r->print(<<ENDHEAD);
  579: <h2>$title</h2>
  580: <p>
  581: $disuri<br />
  582: $obsoletewarning
  583: $versiondisplay
  584: </p>
  585: <table cellspacing=2 border=0>
  586: $table
  587: </table>
  588: ENDHEAD
  589:     if ($ENV{'user.adv'}) {
  590:         &print_dynamic_metadata($r,$uri,\%content);
  591:     }
  592:     return;
  593: }
  594: 
  595: sub print_dynamic_metadata {
  596:     my ($r,$uri,$content) = @_;
  597:     #
  598:     my %content = %$content;
  599:     my %lt=&fieldnames();
  600:     #
  601:     my $description = 'Dynamic Metadata (updated periodically)';
  602:     $r->print('<h3>'.&mt($description).'</h3>'.
  603:               &mt('Processing'));
  604:     $r->rflush();
  605:     my %items=&fieldnames();
  606:     my %dynmeta=&dynamicmeta($uri);
  607:     #
  608:     # General Access and Usage Statistics
  609:     if (exists($dynmeta{'count'}) ||
  610:         exists($dynmeta{'sequsage'}) ||
  611:         exists($dynmeta{'comefrom'}) ||
  612:         exists($dynmeta{'goto'}) ||
  613:         exists($dynmeta{'course'})) {
  614:         $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
  615:                   '<table cellspacing=2 border=0>');
  616:         foreach ('count',
  617:                  'sequsage','sequsage_list',
  618:                  'comefrom','comefrom_list',
  619:                  'goto','goto_list',
  620:                  'course','course_list') {
  621:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  622:                       '<td bgcolor="#CCCCCC">'.
  623:                       &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  624:         }
  625:         $r->print('</table>');
  626:     } else {
  627:         $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
  628:     }
  629:     #
  630:     # Assessment statistics
  631:     if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  632:         if (exists($dynmeta{'stdno'}) ||
  633:             exists($dynmeta{'avetries'}) ||
  634:             exists($dynmeta{'difficulty'}) ||
  635:             exists($dynmeta{'disc'})) {
  636:             # This is an assessment, print assessment data
  637:             $r->print('<h4>'.
  638:                       &mt('Overall Assessment Statistical Data').
  639:                       '</h4>'.
  640:                       '<table cellspacing=2 border=0>');
  641:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
  642:                       '<td bgcolor="#CCCCCC">'.
  643:                       &prettyprint('stdno',$dynmeta{'stdno'}).
  644:                       '</td>'."</tr>\n");
  645:             foreach ('avetries','difficulty','disc') {
  646:                 $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  647:                           '<td bgcolor="#CCCCCC">'.
  648:                           &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
  649:                           '</td>'."</tr>\n");
  650:             }
  651:             $r->print('</table>');    
  652:         }
  653:         if (exists($dynmeta{'stats'})) {
  654:             #
  655:             # New assessment statistics
  656:             $r->print('<h4>'.
  657:                       &mt('Detailed Assessment Statistical Data').
  658:                       '</h4>');
  659:             my $table = '<table cellspacing=2 border=0>'.
  660:                 '<tr>'.
  661:                 '<th>Course</th>'.
  662:                 '<th>Section(s)</th>'.
  663:                 '<th>Num Students</th>'.
  664:                 '<th>Mean Tries</th>'.
  665:                 '<th>Degree of Difficulty</th>'.
  666:                 '<th>Degree of Discrimination</th>'.
  667:                 '<th>Time of computation</th>'.
  668:                 '</tr>'.$/;
  669:             foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
  670:                 my $data = $dynmeta{'stats'}->{$identifier};
  671:                 my $course = $data->{'course'};
  672:                 my %courseinfo = &Apache::lonnet::coursedescription($course);
  673:                 if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
  674:                     &Apache::lonnet::logthis('lookup for '.$course.' failed');
  675:                     next;
  676:                 }
  677:                 $table .= '<tr>';
  678:                 $table .= 
  679:                     '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
  680:                 $table .= 
  681:                     '<td align="right">'.$data->{'sections'}.'</td>';
  682:                 $table .=
  683:                     '<td align="right">'.$data->{'stdno'}.'</td>';
  684:                 foreach ('avetries','difficulty','disc') {
  685:                     $table .= '<td align="right">';
  686:                     if (exists($data->{$_})) {
  687:                         $table .= sprintf('%.2f',$data->{$_}).'&nbsp;';
  688:                     } else {
  689:                         $table .= '';
  690:                     }
  691:                     $table .= '</td>';
  692:                 }
  693:                 $table .=
  694:                     '<td><nobr>'.
  695:                     &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
  696:                     '</nobr></td>';
  697:                 $table .=
  698:                     '</tr>'.$/;
  699:             }
  700:             $table .= '</table>'.$/;
  701:             $r->print($table);
  702:         } else {
  703:             $r->print('No new dynamic data found.');
  704:         }
  705:     } else {
  706:         $r->print('<h4>'.
  707:           &mt('No Assessment Statistical Data is available for this resource').
  708:                   '</h4>');
  709:     }
  710: 
  711:     #
  712:     #
  713:     if (exists($dynmeta{'clear'})   || 
  714:         exists($dynmeta{'depth'})   || 
  715:         exists($dynmeta{'helpful'}) || 
  716:         exists($dynmeta{'correct'}) || 
  717:         exists($dynmeta{'technical'})){ 
  718:         $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
  719:                   '<table cellspacing=2 border=0>');
  720:         foreach ('clear','depth','helpful','correct','technical') {
  721:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  722:                       '<td bgcolor="#CCCCCC">'.
  723:                       &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  724:         }
  725:         $r->print('</table>');
  726:     } else {
  727:         $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
  728:     }
  729:     $uri=~/^\/res\/(\w+)\/(\w+)\//; 
  730:     if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
  731:         || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
  732:         if (exists($dynmeta{'comments'})) {
  733:             $r->print('<h4>'.&mt('Evaluation Comments').' ('.
  734:                       &mt('visible to author and co-authors only').
  735:                       ')</h4>'.
  736:                       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
  737:         } else {
  738:             $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
  739:         }
  740:         my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
  741:         if (defined($bombs) && $bombs ne '') {
  742:             $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
  743:                       &mt('visible to author and co-authors only').')'.
  744:                       '</h4>'.$bombs);
  745:         } else {
  746:             $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
  747:         }
  748:     }
  749:     #
  750:     # All other stuff
  751:     $r->print('<h3>'.
  752:               &mt('Additional Metadata (non-standard, parameters, exports)').
  753:               '</h3>');
  754:     foreach (sort(keys(%content))) {
  755:         my $name=$_;
  756:         if ($name!~/\.display$/) {
  757:             my $display=&Apache::lonnet::metadata($uri,
  758:                                                   $name.'.display');
  759:             if (! $display) { 
  760:                 $display=$name;
  761:             };
  762:             my $otherinfo='';
  763:             foreach ('name','part','type','default') {
  764:                 if (defined(&Apache::lonnet::metadata($uri,
  765:                                                       $name.'.'.$_))) {
  766:                     $otherinfo.=' '.$_.'='.
  767:                         &Apache::lonnet::metadata($uri,
  768:                                                   $name.'.'.$_).'; ';
  769:                 }
  770:             }
  771:             $r->print('<b>'.$display.':</b> '.$content{$name});
  772:             if ($otherinfo) {
  773:                 $r->print(' ('.$otherinfo.')');
  774:             }
  775:             $r->print("<br />\n");
  776:         }
  777:     }
  778:     return;
  779: }
  780: 
  781: #####################################################
  782: #####################################################
  783: ###                                               ###
  784: ###          Editable metadata display            ###
  785: ###                                               ###
  786: #####################################################
  787: #####################################################
  788: sub present_editable_metadata {
  789:     my ($r,$uri) = @_;
  790:     # Construction Space Call
  791:     # Header
  792:     my $disuri=$uri;
  793:     my $fn=&Apache::lonnet::filelocation('',$uri);
  794:     $disuri=~s/^\/\~/\/priv\//;
  795:     $disuri=~s/\.meta$//;
  796:     my $target=$uri;
  797:     $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
  798:     $target=~s/\.meta$//;
  799:     my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
  800:     if ($bombs) {
  801:         if ($ENV{'form.delmsg'}) {
  802:             if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
  803:                 $bombs=&mt('Messages deleted.');
  804:             } else {
  805:                 $bombs=&mt('Error deleting messages');
  806:             }
  807:         }
  808:         my $del=&mt('Delete Messages');
  809:         $r->print(<<ENDBOMBS);
  810: <h1>$disuri</h1>
  811: <form method="post" name="defaultmeta">
  812: <input type="submit" name="delmsg" value="$del" />
  813: <br />$bombs
  814: ENDBOMBS
  815:     } else {
  816:         my $displayfile='Catalog Information for '.$disuri;
  817:         if ($disuri=~/\/default$/) {
  818:             my $dir=$disuri;
  819:             $dir=~s/default$//;
  820:             $displayfile=
  821:                 &mt('Default Cataloging Information for Directory').' '.
  822:                 $dir;
  823:         }
  824:         my $bodytag=
  825:             &Apache::loncommon::bodytag('Edit Catalog Information');
  826:         %Apache::lonpublisher::metadatafields=();
  827:         %Apache::lonpublisher::metadatakeys=();
  828:         &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
  829:         $r->print(<<ENDEDIT);
  830: <html><head><title>Edit Catalog Information</title></head>
  831: $bodytag
  832: <h1>$displayfile</h1>
  833: <form method="post" name="defaultmeta">
  834: ENDEDIT
  835:         $r->print('<script language="JavaScript">'.
  836:                   &Apache::loncommon::browser_and_searcher_javascript.
  837:                   '</script>');
  838:         my %lt=&fieldnames();
  839:         foreach ('author','title','subject','keywords','abstract','notes',
  840:                  'copyright','customdistributionfile','language',
  841:                  'standards',
  842:                  'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
  843:                  'obsolete','obsoletereplacement') {
  844:             if (defined($ENV{'form.new_'.$_})) {
  845:                 $Apache::lonpublisher::metadatafields{$_}=
  846:                     $ENV{'form.new_'.$_};
  847:             }
  848:             if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
  849:                 $Apache::lonpublisher::metadatafields{'copyright'}=
  850:                     'default';
  851:             }
  852:             $r->print('<p>'.$lt{$_}.': '.
  853:                       &prettyinput
  854:                       ($_,$Apache::lonpublisher::metadatafields{$_},
  855:                        'new_'.$_,'defaultmeta').'</p>');
  856:         }
  857:         if ($ENV{'form.store'}) {
  858:             my $mfh;
  859:             if (!  ($mfh=Apache::File->new('>'.$fn))) {
  860:                 $r->print('<p><font color=red>'.
  861:                           &mt('Could not write metadata').', '.
  862:                           &mt('FAIL').'</font>');
  863:             } else {
  864:                 foreach (sort keys %Apache::lonpublisher::metadatafields) {
  865:                     next if ($_ =~ /\./);
  866:                     my $unikey=$_;
  867:                     $unikey=~/^([A-Za-z]+)/;
  868:                     my $tag=$1;
  869:                     $tag=~tr/A-Z/a-z/;
  870:                     print $mfh "\n\<$tag";
  871:                     foreach (split(/\,/,
  872:                                  $Apache::lonpublisher::metadatakeys{$unikey})
  873:                              ) {
  874:                         my $value=
  875:                          $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
  876:                         $value=~s/\"/\'\'/g;
  877:                         print $mfh ' '.$_.'="'.$value.'"';
  878:                     }
  879:                     print $mfh '>'.
  880:                         &HTML::Entities::encode
  881:                         ($Apache::lonpublisher::metadatafields{$unikey},
  882:                          '<>&"').
  883:                          '</'.$tag.'>';
  884:                 }
  885:                 $r->print('<p>'.&mt('Wrote Metadata'));
  886:             }
  887:         }
  888:         $r->print('<br /><input type="submit" name="store" value="'.
  889:                   &mt('Store Catalog Information').'">');
  890:     }
  891:     $r->print('</form>');
  892:     return;
  893: }
  894: 
  895: 1;
  896: __END__

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