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

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

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