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

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

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