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

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

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