Annotation of loncom/interface/lonmeta.pm, revision 1.68

1.1       www         1: # The LearningOnline Network with CAPA
1.8       albertel    2: # Metadata display handler
                      3: #
1.68    ! matthew     4: # $Id: lonmeta.pm,v 1.67 2004/04/14 16:14:29 matthew Exp $
1.8       albertel    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.
1.1       www        14: #
1.8       albertel   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/
1.44      www        27: 
1.1       www        28: 
                     29: package Apache::lonmeta;
                     30: 
                     31: use strict;
1.63      matthew    32: use LONCAPA::lonmetadata();
1.1       www        33: use Apache::Constants qw(:common);
1.3       www        34: use Apache::lonnet();
1.10      www        35: use Apache::loncommon();
1.46      www        36: use Apache::lonhtmlcommon();
1.23      www        37: use Apache::lonmsg;
                     38: use Apache::lonpublisher;
1.35      www        39: use Apache::lonlocal;
1.43      www        40: use Apache::lonmysql;
1.49      www        41: use Apache::lonmsg;
1.1       www        42: 
1.44      www        43: 
1.64      matthew    44: # Fetch and evaluate dynamic metadata
1.9       www        45: sub dynamicmeta {
                     46:     my $url=&Apache::lonnet::declutter(shift);
                     47:     $url=~s/\.meta$//;
                     48:     my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
1.19      www        49:     my $regexp=$url;
1.9       www        50:     $regexp=~s/(\W)/\\$1/g;
1.10      www        51:     $regexp='___'.$regexp.'___';
1.16      albertel   52:     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
                     53: 				       $aauthor,$regexp);
1.63      matthew    54:     my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
                     55:     my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
                     56:                                                                \%DynamicData);
1.40      matthew    57:     #
1.46      www        58:     # Deal with 'count' separately
1.63      matthew    59:     $Data{'count'} = &access_count($url,$aauthor,$adomain);
1.67      matthew    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:     }
1.63      matthew    69:     return %Data;
1.40      matthew    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})) {
1.47      www        77:         return &mt('Not Available');
1.40      matthew    78:     } else {
                     79:         return $countdata{$src};
                     80:     }
1.25      www        81: }
                     82: 
1.64      matthew    83: # Try to make an alt tag if there is none
1.25      www        84: sub alttag {
1.26      www        85:     my ($base,$src)=@_;
                     86:     my $fullpath=&Apache::lonnet::hreflocation($base,$src);
                     87:     my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
1.64      matthew    88:         &Apache::lonnet::metadata($fullpath,'subject').' '.
                     89:         &Apache::lonnet::metadata($fullpath,'abstract');
1.26      www        90:     $alttag=~s/\s+/ /gs;
                     91:     $alttag=~s/\"//gs;
                     92:     $alttag=~s/\'//gs;
                     93:     $alttag=~s/\s+$//gs;
                     94:     $alttag=~s/^\s+//gs;
1.64      matthew    95:     if ($alttag) { 
                     96:         return $alttag; 
                     97:     } else { 
                     98:         return &mt('No information available'); 
                     99:     }
1.9       www       100: }
1.1       www       101: 
1.64      matthew   102: # Author display
1.29      www       103: sub authordisplay {
                    104:     my ($aname,$adom)=@_;
1.64      matthew   105:     return &Apache::loncommon::aboutmewrapper
                    106:         (&Apache::loncommon::plainname($aname,$adom),
                    107:          $aname,$adom,'preview').' <tt>['.$aname.'@'.$adom.']</tt>';
1.29      www       108: }
                    109: 
1.64      matthew   110: # Pretty display
1.12      www       111: sub evalgraph {
                    112:     my $value=shift;
1.65      matthew   113:     if (! $value) { 
                    114:         return '';
                    115:     }
1.12      www       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 {
1.64      matthew   129:         $output.='<td width=20 bgcolor="#555555">&nbsp&nbsp;</td>';
1.12      www       130:     }
                    131:     $output.='<td> ('.$value.') </td></tr></table>';
                    132:     return $output;
                    133: }
                    134: 
                    135: sub diffgraph {
                    136:     my $value=shift;
1.65      matthew   137:     if (! $value) { 
                    138:         return '';
                    139:     }
1.12      www       140:     my $val=int(40.0*$value+0.5);
1.13      www       141:     my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
                    142:                 '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
1.12      www       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> ('.$value.') </td></tr></table>';
                    152:     return $output;
                    153: }
                    154: 
1.44      www       155: 
1.64      matthew   156: # The field names
1.45      www       157: sub fieldnames {
1.64      matthew   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:          );
1.45      www       198: }
1.46      www       199: 
1.64      matthew   200: # Pretty printing of metadata field
1.46      www       201: 
                    202: sub prettyprint {
                    203:     my ($type,$value)=@_;
1.65      matthew   204:     if (! defined($value)) { 
                    205:         return '&nbsp;'; 
                    206:     }
1.64      matthew   207:     # Title
1.46      www       208:     if ($type eq 'title') {
                    209: 	return '<font size="+1" face="arial">'.$value.'</font>';
                    210:     }
1.64      matthew   211:     # Dates
1.46      www       212:     if (($type eq 'creationdate') ||
                    213: 	($type eq 'lastrevisiondate')) {
1.55      www       214: 	return ($value?&Apache::lonlocal::locallocaltime(
                    215: 			  &Apache::lonmysql::unsqltime($value)):
                    216: 		&mt('not available'));
1.46      www       217:     }
1.64      matthew   218:     # Language
1.46      www       219:     if ($type eq 'language') {
                    220: 	return &Apache::loncommon::languagedescription($value);
                    221:     }
1.64      matthew   222:     # Copyright
1.46      www       223:     if ($type eq 'copyright') {
                    224: 	return &Apache::loncommon::copyrightdescription($value);
                    225:     }
1.64      matthew   226:     # MIME
1.46      www       227:     if ($type eq 'mime') {
1.64      matthew   228:         return '<img src="'.&Apache::loncommon::icon($value).'" />&nbsp;'.
                    229:             &Apache::loncommon::filedescription($value);
                    230:     }
                    231:     # Person
1.46      www       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:     }
1.64      matthew   239:     # Gradelevel
1.48      www       240:     if (($type eq 'lowestgradelevel') ||
                    241: 	($type eq 'highestgradelevel')) {
                    242: 	return &Apache::loncommon::gradeleveldescription($value);
                    243:     }
1.64      matthew   244:     # Only for advance users below
1.65      matthew   245:     if (! $ENV{'user.adv'}) { 
                    246:         return '<i>- '.&mt('not displayed').' -</i>';
                    247:     }
1.64      matthew   248:     # File
1.46      www       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 {
1.64      matthew   255:             my $url=&Apache::lonnet::clutter($_);
                    256:             '<b>'.&Apache::lonnet::gettitle($url).'</b>'.
                    257:                 &Apache::lonhtmlcommon::crumbs($url,'preview','',undef,'+0');
                    258:         } split(/\s*\,\s*/,$value));
1.46      www       259:     }
1.64      matthew   260:     # Evaluations
1.46      www       261:     if (($type eq 'clear') ||
                    262: 	($type eq 'depth') ||
                    263: 	($type eq 'helpful') ||
                    264: 	($type eq 'correct') ||
                    265: 	($type eq 'technical')) {
                    266: 	return &evalgraph($value);
                    267:     }
1.64      matthew   268:     # Difficulty
1.46      www       269:     if ($type eq 'difficulty') {
                    270: 	return &diffgraph($value);
                    271:     }
1.64      matthew   272:     # List of courses
1.46      www       273:     if ($type=~/\_list/) {
                    274: 	return join('<br />',map {
                    275: 	    my %courseinfo=&Apache::lonnet::coursedescription($_);  
                    276: 	    '<a href="/public/'.
                    277: 		$courseinfo{'domain'}.'/'.$courseinfo{'num'}.'/syllabus" target="preview">'.
                    278: 		$courseinfo{'description'}.'</a>';
                    279: 	} split(/\s*\,\s*/,$value));
                    280:     }
1.64      matthew   281:     # No pretty print found
1.46      www       282:     return $value;
                    283: }
                    284: 
1.64      matthew   285: # Pretty input of metadata field
1.54      www       286: sub direct {
                    287:     return shift;
                    288: }
                    289: 
1.48      www       290: sub selectbox {
                    291:     my ($name,$value,$functionref,@idlist)=@_;
1.65      matthew   292:     if (! defined($functionref)) {
                    293:         $functionref=\&direct;
                    294:     }
1.48      www       295:     my $selout='<select name="'.$name.'">';
                    296:     foreach (@idlist) {
                    297:         $selout.='<option value=\''.$_.'\'';
                    298:         if ($_ eq $value) {
                    299: 	    $selout.=' selected>'.&{$functionref}($_).'</option>';
                    300: 	}
                    301:         else {$selout.='>'.&{$functionref}($_).'</option>';}
                    302:     }
                    303:     return $selout.'</select>';
                    304: }
                    305: 
1.54      www       306: sub relatedfield {
                    307:     my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
1.65      matthew   308:     if (! $relatedsearchflag) { 
                    309:         return '';
                    310:     }
                    311:     if (! defined($relatedsep)) {
                    312:         $relatedsep=' ';
                    313:     }
                    314:     if (! $show) {
                    315:         return $relatedsep.'&nbsp;';
                    316:     }
1.54      www       317:     return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
                    318: 	($relatedvalue?' checked="1"':'').' />';
                    319: }
1.48      www       320: 
1.46      www       321: sub prettyinput {
1.54      www       322:     my ($type,$value,$fieldname,$formname,
                    323: 	$relatedsearchflag,$relatedsep,$relatedvalue)=@_;
1.64      matthew   324:     # Language
1.48      www       325:     if ($type eq 'language') {
                    326: 	return &selectbox($fieldname,
                    327: 			  $value,
                    328: 			  \&Apache::loncommon::languagedescription,
1.54      www       329: 			  (&Apache::loncommon::languageids)).
1.64      matthew   330:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48      www       331:     }
1.64      matthew   332:     # Copyright
1.48      www       333:     if ($type eq 'copyright') {
                    334: 	return &selectbox($fieldname,
                    335: 			  $value,
                    336: 			  \&Apache::loncommon::copyrightdescription,
1.54      www       337: 			  (&Apache::loncommon::copyrightids)).
1.64      matthew   338:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48      www       339:     }
1.64      matthew   340:     # Gradelevels
1.48      www       341:     if (($type eq 'lowestgradelevel') ||
                    342: 	($type eq 'highestgradelevel')) {
1.54      www       343: 	return &Apache::loncommon::select_level_form($value,$fieldname).
1.64      matthew   344:             &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48      www       345:     }
1.64      matthew   346:     # Obsolete
1.48      www       347:     if ($type eq 'obsolete') {
                    348: 	return '<input type="checkbox" name="'.$fieldname.'"'.
1.54      www       349: 	    ($value?' checked="1"':'').' />'.
1.64      matthew   350:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
1.48      www       351:     }
1.64      matthew   352:     # Obsolete replacement file
1.48      www       353:     if ($type eq 'obsoletereplacement') {
                    354: 	return '<input type="text" name="'.$fieldname.
                    355: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
                    356: 	    "('".$formname."','".$fieldname."'".
1.54      www       357: 	    ",'')\">".&mt('Select').'</a>'.
1.64      matthew   358:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
                    359:     }
                    360:     # Customdistribution file
1.48      www       361:     if ($type eq 'customdistributionfile') {
                    362: 	return '<input type="text" name="'.$fieldname.
                    363: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
                    364: 	    "('".$formname."','".$fieldname."'".
1.54      www       365: 	    ",'rights')\">".&mt('Select').'</a>'.
1.64      matthew   366:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
1.48      www       367:     }
1.64      matthew   368:     # Dates
1.48      www       369:     if (($type eq 'creationdate') ||
                    370: 	($type eq 'lastrevisiondate')) {
1.64      matthew   371: 	return 
                    372:             &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
                    373:             &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48      www       374:     }
1.64      matthew   375:     # No pretty input found
1.48      www       376:     $value=~s/^\s+//gs;
                    377:     $value=~s/\s+$//gs;
                    378:     $value=~s/\s+/ /gs;
                    379:     $value=~s/\"/\&quod\;/gs;
1.54      www       380:     return 
1.64      matthew   381:         '<input type="text" name="'.$fieldname.'" size="80" '.
                    382:         'value="'.$value.'" />'.
                    383:         &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
                    384:                       $relatedvalue); 
1.46      www       385: }
                    386: 
1.64      matthew   387: # Main Handler
1.1       www       388: sub handler {
1.64      matthew   389:     my $r=shift;
                    390:     #
1.67      matthew   391:     my $uri=$r->uri;
                    392:     #
                    393:     # Check to see if this server is overloaded
1.20      www       394:     my $loaderror=&Apache::lonnet::overloaderror($r);
1.67      matthew   395:     if ($loaderror) { 
                    396:         return $loaderror;
                    397:     }
1.64      matthew   398:     #
1.67      matthew   399:     # Check to see if original resource server is overloaded
                    400:     my ($resdomain,$resuser)=
                    401:         (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
                    402:     $loaderror=&Apache::lonnet::overloaderror
                    403:         ($r,&Apache::lonnet::homeserver($resuser,$resdomain));
                    404:     if ($loaderror) { 
                    405:         return $loaderror;
                    406:     }
                    407:     #
                    408:     # Set document type
                    409:     &Apache::loncommon::content_type($r,'text/html');
                    410:     $r->send_http_header;
                    411:     return OK if $r->header_only;
1.64      matthew   412:     #
1.67      matthew   413:     $r->print('<html><head><title>'.
                    414:               'Catalog Information'.
                    415:               '</title></head>');
1.66      matthew   416:     if ($uri=~m:/adm/bombs/(.*)$:) {
1.67      matthew   417:         $r->print(&Apache::loncommon::bodytag('Error Messages'));
1.66      matthew   418:         # Looking for all bombs?
                    419:         &report_bombs($r,$uri);
                    420:     } elsif ($uri=~/^\/\~/) { 
                    421:         # Construction space
1.67      matthew   422:         $r->print(&Apache::loncommon::bodytag
                    423:                   ('Edit Catalog Information','','','',$resdomain));
1.66      matthew   424:         &present_editable_metadata($r,$uri);
                    425:     } else {
1.67      matthew   426:         $r->print(&Apache::loncommon::bodytag
                    427:                   ('Catalog Information','','','',$resdomain));
1.66      matthew   428:         &present_uneditable_metadata($r,$uri);
                    429:     }
1.67      matthew   430:     $r->print('</body></html>');
1.66      matthew   431:     return OK;
                    432: }
                    433: 
1.67      matthew   434: #####################################################
                    435: #####################################################
                    436: ###                                               ###
                    437: ###                Report Bombs                   ###
                    438: ###                                               ###
                    439: #####################################################
                    440: #####################################################
1.66      matthew   441: sub report_bombs {
                    442:     my ($r,$uri) = @_;
                    443:     # Set document type
1.67      matthew   444:     $uri =~ s:/adm/bombs/::;
                    445:     $uri = &Apache::lonnet::declutter($uri);
1.66      matthew   446:     $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
                    447:     my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
                    448:     if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
1.67      matthew   449:         my %brokenurls = 
                    450:             &Apache::lonmsg::all_url_author_res_msg($author,$domain);
                    451:         foreach (sort(keys(%brokenurls))) {
1.66      matthew   452:             if ($_=~/^\Q$uri\E/) {
                    453:                 $r->print(&Apache::lonhtmlcommon::crumbs
                    454:                           (&Apache::lonnet::clutter($_)).
                    455:                           &Apache::lonmsg::retrieve_author_res_msg($_).
                    456:                           '<hr />');
1.64      matthew   457:             }
                    458:         }
1.66      matthew   459:     } else {
                    460:         $r->print(&mt('Not authorized'));
                    461:     }
                    462:     return;
                    463: }
                    464: 
1.67      matthew   465: #####################################################
                    466: #####################################################
                    467: ###                                               ###
                    468: ###        Uneditable Metadata Display            ###
                    469: ###                                               ###
                    470: #####################################################
                    471: #####################################################
1.66      matthew   472: sub present_uneditable_metadata {
                    473:     my ($r,$uri) = @_;
                    474:     #
                    475:     my %content=();
                    476:     # Read file
                    477:     foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
                    478:         $content{$_}=&Apache::lonnet::metadata($uri,$_);
                    479:     }
                    480:     # Render Output
                    481:     # displayed url
                    482:     my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
                    483:     $uri=~s/\.meta$//;
                    484:     my $disuri=&Apache::lonnet::clutter($uri);
                    485:     # version
                    486:     my $currentversion=&Apache::lonnet::getversion($disuri);
                    487:     my $versiondisplay='';
                    488:     if ($thisversion) {
                    489:         $versiondisplay=&mt('Version').': '.$thisversion.
                    490:             ' ('.&mt('most recent version').': '.
                    491:             ($currentversion>0 ? 
                    492:              $currentversion   :
                    493:              &mt('information not available')).')';
                    494:     } else {
                    495:         $versiondisplay='Version: '.$currentversion;
                    496:     }
                    497:     # crumbify displayed URL
                    498:     $disuri=&Apache::lonhtmlcommon::crumbs($disuri);
                    499:     # obsolete
                    500:     my $obsolete=$content{'obsolete'};
                    501:     my $obsoletewarning='';
                    502:     if (($obsolete) && ($ENV{'user.adv'})) {
                    503:         $obsoletewarning='<p><font color="red">'.
                    504:             &mt('This resource has been marked obsolete by the author(s)').
                    505:             '</font></p>';
                    506:     }
                    507:     #
                    508:     my %lt=&fieldnames();
                    509:     my $table='';
                    510:     foreach ('title', 
                    511:              'author', 
                    512:              'subject', 
                    513:              'keywords', 
                    514:              'notes', 
                    515:              'abstract',
                    516:              'lowestgradelevel',
                    517:              'highestgradelevel',
                    518:              'standards', 
                    519:              'mime', 
                    520:              'language', 
                    521:              'creationdate', 
                    522:              'lastrevisiondate', 
                    523:              'owner', 
                    524:              'copyright', 
                    525:              'customdistributionfile', 
                    526:              'obsolete', 
                    527:              'obsoletereplacement') {
                    528:         $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
                    529:             '</td><td bgcolor="#CCCCCC">'.
                    530:             &prettyprint($_,$content{$_}).'</td></tr>';
                    531:         delete $content{$_};
                    532:     }
                    533:     #
                    534:     $r->print(<<ENDHEAD);
1.1       www       535: <h2>$content{'title'}</h2>
1.11      www       536: <h3><tt>$disuri</tt></h3>
1.36      www       537: $obsoletewarning
1.21      www       538: $versiondisplay<br />
1.11      www       539: <table cellspacing=2 border=0>
1.45      www       540: $table
1.11      www       541: </table>
1.1       www       542: ENDHEAD
1.66      matthew   543:     if ($ENV{'user.adv'}) {
1.68    ! matthew   544:         &print_dynamic_metadata($r,$uri,\%content);
1.67      matthew   545:     }
                    546:     return;
                    547: }
                    548: 
                    549: sub print_dynamic_metadata {
1.68    ! matthew   550:     my ($r,$uri,$content) = @_;
        !           551:     #
        !           552:     my %content = \$content;
        !           553:     my %lt=&fieldnames();
1.67      matthew   554:     #
                    555:     my $description = 'Dynamic Metadata (updated periodically)';
                    556:     $r->print('<h3>'.&mt($description).'</h3>'.
                    557:               &mt('Processing').' ...<br />');
                    558:     $r->rflush();
                    559:     my %items=&fieldnames();
                    560:     my %dynmeta=&dynamicmeta($uri);
                    561:     #
                    562:     # General Access and Usage Statistics
                    563:     $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
                    564:               '<table cellspacing=2 border=0>');
                    565:     foreach ('count',
                    566:              'sequsage','sequsage_list',
                    567:              'comefrom','comefrom_list',
                    568:              'goto','goto_list',
                    569:              'course','course_list') {
                    570:         $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
                    571:                   '<td bgcolor="#CCCCCC">'.
                    572:                   &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
                    573:     }
                    574:     $r->print('</table>');
                    575:     if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    576:         # This is an assessment, print assessment data
1.66      matthew   577:         $r->print(
1.67      matthew   578:                   '<h4>'.&mt('Assessment Statistical Data').'</h4>'.
1.66      matthew   579:                   '<table cellspacing=2 border=0>');
1.67      matthew   580:         foreach ('stdno','avetries','difficulty') {
1.66      matthew   581:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
                    582:                       '<td bgcolor="#CCCCCC">'.
                    583:                       &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
                    584:         }
1.67      matthew   585:         $r->print('</table>');    
                    586:     }
                    587:     
                    588:     $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
                    589:               '<table cellspacing=2 border=0>');
                    590:     foreach ('clear','depth','helpful','correct','technical') {
                    591:         $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
                    592:                   '<td bgcolor="#CCCCCC">'.
                    593:                   &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
                    594:     }
                    595:     $r->print('</table>');
                    596:     $uri=~/^\/res\/(\w+)\/(\w+)\//; 
                    597:     if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
                    598:         || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
                    599:         $r->print('<h4>'.&mt('Evaluation Comments').' ('.
                    600:                   &mt('visible to author and co-authors only').
                    601:                   ')</h4>'.
                    602:                   '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
                    603:         $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
                    604:                   &mt('visible to author and co-authors only').')'.
                    605:                   '</h4>'.
                    606:                   &Apache::lonmsg::retrieve_author_res_msg($uri));
                    607:     }
                    608:     # All other stuff
                    609:     $r->print('<h3>'.
                    610:               &mt('Additional Metadata (non-standard, parameters, exports)').
                    611:               '</h3>');
                    612:     foreach (sort(keys(%content))) {
                    613:         my $name=$_;
                    614:         if ($name!~/\.display$/) {
                    615:             my $display=&Apache::lonnet::metadata($uri,
                    616:                                                   $name.'.display');
                    617:             if (! $display) { 
                    618:                 $display=$name;
                    619:             };
                    620:             my $otherinfo='';
                    621:             foreach ('name','part','type','default') {
                    622:                 if (defined(&Apache::lonnet::metadata($uri,
                    623:                                                       $name.'.'.$_))) {
                    624:                     $otherinfo.=' '.$_.'='.
                    625:                         &Apache::lonnet::metadata($uri,
                    626:                                                   $name.'.'.$_).'; ';
                    627:                 }
1.64      matthew   628:             }
1.67      matthew   629:             $r->print('<b>'.$display.':</b> '.$content{$name});
                    630:             if ($otherinfo) {
                    631:                 $r->print(' ('.$otherinfo.')');
1.64      matthew   632:             }
1.67      matthew   633:             $r->print("<br />\n");
1.64      matthew   634:         }
1.66      matthew   635:     }
1.67      matthew   636:     return;
1.66      matthew   637: }
                    638: 
1.67      matthew   639: #####################################################
                    640: #####################################################
                    641: ###                                               ###
                    642: ###          Editable metadata display            ###
                    643: ###                                               ###
                    644: #####################################################
                    645: #####################################################
1.66      matthew   646: sub present_editable_metadata {
                    647:     my ($r,$uri) = @_;
                    648:     # Construction Space Call
                    649:     # Header
                    650:     my $disuri=$uri;
                    651:     my $fn=&Apache::lonnet::filelocation('',$uri);
                    652:     $disuri=~s/^\/\~/\/priv\//;
                    653:     $disuri=~s/\.meta$//;
                    654:     my $target=$uri;
                    655:     $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
                    656:     $target=~s/\.meta$//;
                    657:     my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
                    658:     if ($bombs) {
                    659:         if ($ENV{'form.delmsg'}) {
                    660:             if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
                    661:                 $bombs=&mt('Messages deleted.');
                    662:             } else {
                    663:                 $bombs=&mt('Error deleting messages');
1.64      matthew   664:             }
1.66      matthew   665:         }
                    666:         my $del=&mt('Delete Messages');
                    667:         $r->print(<<ENDBOMBS);
1.52      www       668: <h1>$disuri</h1>
                    669: <form method="post" name="defaultmeta">
1.59      www       670: <input type="submit" name="delmsg" value="$del" />
1.52      www       671: <br />$bombs
                    672: ENDBOMBS
1.66      matthew   673:     } else {
                    674:         my $displayfile='Catalog Information for '.$disuri;
                    675:         if ($disuri=~/\/default$/) {
                    676:             my $dir=$disuri;
                    677:             $dir=~s/default$//;
                    678:             $displayfile=
                    679:                 &mt('Default Cataloging Information for Directory').' '.
                    680:                 $dir;
                    681:         }
                    682:         my $bodytag=
                    683:             &Apache::loncommon::bodytag('Edit Catalog Information');
                    684:         %Apache::lonpublisher::metadatafields=();
                    685:         %Apache::lonpublisher::metadatakeys=();
                    686:         &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
                    687:         $r->print(<<ENDEDIT);
1.23      www       688: <html><head><title>Edit Catalog Information</title></head>
                    689: $bodytag
                    690: <h1>$displayfile</h1>
1.48      www       691: <form method="post" name="defaultmeta">
1.23      www       692: ENDEDIT
1.66      matthew   693:         $r->print('<script language="JavaScript">'.
                    694:                   &Apache::loncommon::browser_and_searcher_javascript.
                    695:                   '</script>');
                    696:         my %lt=&fieldnames();
                    697:         foreach ('author','title','subject','keywords','abstract','notes',
                    698:                  'copyright','customdistributionfile','language',
                    699:                  'standards',
                    700:                  'lowestgradelevel','highestgradelevel',
                    701:                  'obsolete','obsoletereplacement') {
                    702:             if (defined($ENV{'form.new_'.$_})) {
                    703:                 $Apache::lonpublisher::metadatafields{$_}=
                    704:                     $ENV{'form.new_'.$_};
                    705:             }
                    706:             if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
                    707:                 $Apache::lonpublisher::metadatafields{'copyright'}=
                    708:                     'default';
1.64      matthew   709:             }
1.66      matthew   710:             $r->print('<p>'.$lt{$_}.': '.
                    711:                       &prettyinput
                    712:                       ($_,$Apache::lonpublisher::metadatafields{$_},
                    713:                        'new_'.$_,'defaultmeta').'</p>');
                    714:         }
                    715:         if ($ENV{'form.store'}) {
                    716:             my $mfh;
                    717:             if (!  ($mfh=Apache::File->new('>'.$fn))) {
                    718:                 $r->print('<p><font color=red>'.
                    719:                           &mt('Could not write metadata').', '.
                    720:                           &mt('FAIL').'</font>');
                    721:             } else {
                    722:                 foreach (sort keys %Apache::lonpublisher::metadatafields) {
1.67      matthew   723:                     next if ($_ =~ /\./);
                    724:                     my $unikey=$_;
                    725:                     $unikey=~/^([A-Za-z]+)/;
                    726:                     my $tag=$1;
                    727:                     $tag=~tr/A-Z/a-z/;
                    728:                     print $mfh "\n\<$tag";
                    729:                     foreach (split(/\,/,
1.64      matthew   730:                                  $Apache::lonpublisher::metadatakeys{$unikey})
1.67      matthew   731:                              ) {
                    732:                         my $value=
                    733:                          $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
                    734:                         $value=~s/\"/\'\'/g;
                    735:                         print $mfh ' '.$_.'="'.$value.'"';
1.64      matthew   736:                     }
1.67      matthew   737:                     print $mfh '>'.
                    738:                         &HTML::Entities::encode
                    739:                         ($Apache::lonpublisher::metadatafields{$unikey},
                    740:                          '<>&"').
                    741:                          '</'.$tag.'>';
1.64      matthew   742:                 }
1.66      matthew   743:                 $r->print('<p>'.&mt('Wrote Metadata'));
1.64      matthew   744:             }
                    745:         }
1.66      matthew   746:         $r->print('<br /><input type="submit" name="store" value="'.
1.67      matthew   747:                   &mt('Store Catalog Information').'">');
1.64      matthew   748:     }
1.67      matthew   749:     $r->print('</form>');
1.66      matthew   750:     return;
1.1       www       751: }
1.64      matthew   752: 
1.1       www       753: 1;
                    754: __END__

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