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

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

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