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

1.1       www         1: # The LearningOnline Network with CAPA
1.8       albertel    2: # Metadata display handler
                      3: #
1.23    ! www         4: # $Id: lonmeta.pm,v 1.22 2002/10/18 13:49:49 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.1       www        27: #
                     28: # (TeX Content Handler
                     29: #
                     30: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
                     31: #
1.13      www        32: # 10/19,10/21,10/23,11/27,08/09/01,12/22,12/24,12/25 Gerd Kortemeyer
1.1       www        33: 
                     34: package Apache::lonmeta;
                     35: 
                     36: use strict;
                     37: use Apache::Constants qw(:common);
1.3       www        38: use Apache::lonnet();
1.10      www        39: use Apache::loncommon();
1.23    ! www        40: use Apache::lonmsg;
        !            41: use Apache::lonpublisher;
1.1       www        42: 
1.9       www        43: # ----------------------------------------- Fetch and evaluate dynamic metadata
                     44: 
                     45: sub dynamicmeta {
                     46:     my $url=&Apache::lonnet::declutter(shift);
                     47:     $url=~s/\.meta$//;
                     48:     my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
1.19      www        49:     my $regexp=$url;
1.9       www        50:     $regexp=~s/(\W)/\\$1/g;
1.10      www        51:     $regexp='___'.$regexp.'___';
1.16      albertel   52:     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
                     53: 				       $aauthor,$regexp);
1.10      www        54:     my %sum;
                     55:     my %cnt;
                     56:     my %listitems=('count'        => 'add',
                     57:                    'course'       => 'add',
                     58:                    'avetries'     => 'avg',
                     59:                    'stdno'        => 'add',
                     60:                    'difficulty'   => 'avg',
                     61:                    'clear'        => 'avg',
                     62:                    'technical'    => 'avg',
                     63:                    'helpful'      => 'avg',
                     64:                    'correct'      => 'avg',
                     65:                    'depth'        => 'avg',
                     66:                    'comments'     => 'app',
                     67:                    'usage'        => 'cnt'
                     68:                    );
                     69:     foreach (keys %evaldata) {
                     70: 	$_=~/___(\w+)$/;
                     71:         if (defined($cnt{$1})) { $cnt{$1}++; } else { $cnt{$1}=1; }
                     72:         unless ($listitems{$1} eq 'app') {
                     73:             if (defined($sum{$1})) {
                     74:                $sum{$1}+=$evaldata{$_};
                     75: 	    } else {
                     76:                $sum{$1}=$evaldata{$_};
                     77: 	    }
                     78:         } else {
                     79:             if (defined($sum{$1})) {
                     80:                if ($evaldata{$_}) {
                     81:                   $sum{$1}.='<hr>'.$evaldata{$_};
                     82: 	       }
                     83:  	    } else {
                     84: 	       $sum{$1}=''.$evaldata{$_};
                     85: 	    }
                     86: 	}
                     87:     }
1.9       www        88:     my %returnhash=();
1.10      www        89:     foreach (keys %cnt) {
1.11      www        90:        if ($listitems{$_} eq 'avg') {
                     91: 	   $returnhash{$_}=int(($sum{$_}/$cnt{$_})*100.0+0.5)/100.0;
                     92:        } elsif ($listitems{$_} eq 'cnt') {
                     93:            $returnhash{$_}=$cnt{$_};
                     94:        } else {
                     95:            $returnhash{$_}=$sum{$_};
                     96:        }
1.9       www        97:     }
                     98:     return %returnhash;
                     99: }
1.1       www       100: 
1.12      www       101: # -------------------------------------------------------------- Pretty display
                    102: 
                    103: sub evalgraph {
                    104:     my $value=shift;
1.13      www       105:     unless ($value) { return ''; }
1.12      www       106:     my $val=int($value*10.+0.5)-10;
                    107:     my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
                    108:     if ($val>=20) {
                    109: 	$output.='<td width=20 bgcolor="#555555">&nbsp&nbsp;</td>';
                    110:     } else {
                    111:         $output.='<td width='.($val).' bgcolor="#555555">&nbsp;</td>'.
                    112:                  '<td width='.(20-$val).' bgcolor="#FF3333">&nbsp;</td>';
                    113:     }
                    114:     $output.='<td bgcolor="#FFFF33">&nbsp;</td>';
                    115:     if ($val>20) {
                    116: 	$output.='<td width='.($val-20).' bgcolor="#33FF33">&nbsp;</td>'.
                    117:                  '<td width='.(40-$val).' bgcolor="#555555">&nbsp;</td>';
                    118:     } else {
                    119:        $output.='<td width=20 bgcolor="#555555">&nbsp&nbsp;</td>';
                    120:     }
                    121:     $output.='<td> ('.$value.') </td></tr></table>';
                    122:     return $output;
                    123: }
                    124: 
                    125: sub diffgraph {
                    126:     my $value=shift;
1.13      www       127:     unless ($value) { return ''; }
1.12      www       128:     my $val=int(40.0*$value+0.5);
1.13      www       129:     my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
                    130:                 '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
1.12      www       131:     my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
                    132:     for (my $i=0;$i<8;$i++) {
                    133: 	if ($val>$i*5) {
                    134:             $output.='<td width=5 bgcolor="'.$colors[$i].'">&nbsp;</td>';
                    135:         } else {
                    136: 	    $output.='<td width=5 bgcolor="#555555">&nbsp;</td>';
                    137: 	}
                    138:     }
                    139:     $output.='<td> ('.$value.') </td></tr></table>';
                    140:     return $output;
                    141: }
                    142: 
1.1       www       143: # ================================================================ Main Handler
                    144: 
                    145: sub handler {
                    146:   my $r=shift;
1.20      www       147: 
                    148:     my $loaderror=&Apache::lonnet::overloaderror($r);
                    149:     if ($loaderror) { return $loaderror; }
                    150: 
                    151: 
                    152:     my $uri=$r->uri;
                    153: 
1.23    ! www       154:   unless ($uri=~/^\/\~/) { 
        !           155: # =========================================== This is not in construction space
1.20      www       156:     my ($resdomain,$resuser)=
                    157:            (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
                    158: 
                    159:     $loaderror=
                    160:        &Apache::lonnet::overloaderror($r,
                    161:          &Apache::lonnet::homeserver($resuser,$resdomain));
                    162:     if ($loaderror) { return $loaderror; }
                    163: 
1.3       www       164:   my %content=();
1.1       www       165: 
                    166: # ----------------------------------------------------------- Set document type
                    167: 
                    168:   $r->content_type('text/html');
                    169:   $r->send_http_header;
                    170: 
                    171:   return OK if $r->header_only;
                    172: 
                    173: # ------------------------------------------------------------------- Read file
1.14      harris41  174:   foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
1.3       www       175:       $content{$_}=&Apache::lonnet::metadata($uri,$_);
1.14      harris41  176:   }
1.6       albertel  177: # ------------------------------------------------------------------ Hide stuff
1.7       www       178: 
                    179:   unless ($ENV{'user.adv'}) {
1.14      harris41  180:       foreach ('keywords','notes','abstract','subject') {
1.7       www       181:           $content{$_}='<i>- not displayed -</i>';
1.14      harris41  182:       }
1.6       albertel  183:   }
                    184: 
1.1       www       185: # --------------------------------------------------------------- Render Output
1.23    ! www       186:   my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
1.22      www       187: my $creationdate=localtime(
                    188:  &Apache::loncommon::unsqltime($content{'creationdate'}));
                    189: my $lastrevisiondate=localtime(
                    190:  &Apache::loncommon::unsqltime($content{'lastrevisiondate'}));
1.10      www       191: my $language=&Apache::loncommon::languagedescription($content{'language'});
                    192: my $mime=&Apache::loncommon::filedescription($content{'mime'}); 
1.11      www       193: my $disuri=&Apache::lonnet::declutter($uri);
                    194:   $disuri=~s/\.meta$//;
1.21      www       195: my $currentversion=&Apache::lonnet::getversion($disuri);
                    196: my $versiondisplay='';
                    197: if ($thisversion) {
                    198:     $versiondisplay='Version: '.$thisversion.
                    199:     ' (most recent version: '.$currentversion.')';
                    200: } else {
                    201:     $versiondisplay='Version: '.$currentversion;
                    202: }
1.17      www       203: my $bodytag=&Apache::loncommon::bodytag
                    204:             ('Catalog Information','','','',$resdomain);
1.1       www       205:   $r->print(<<ENDHEAD);
                    206: <html><head><title>Catalog Information</title></head>
1.17      www       207: $bodytag
1.1       www       208: <h2>$content{'title'}</h2>
1.11      www       209: <h3><tt>$disuri</tt></h3>
1.21      www       210: $versiondisplay<br />
1.11      www       211: <table cellspacing=2 border=0>
                    212: <tr><td bgcolor='#AAAAAA'>Author(s)</td>
                    213: <td bgcolor="#CCCCCC">$content{'author'}&nbsp;</td></tr>
                    214: <tr><td bgcolor='#AAAAAA'>Subject</td>
                    215: <td bgcolor="#CCCCCC">$content{'subject'}&nbsp;</td></tr>
                    216: <tr><td bgcolor='#AAAAAA'>Keyword(s)</td>
                    217: <td bgcolor="#CCCCCC">$content{'keywords'}&nbsp;</td></tr>
                    218: <tr><td bgcolor='#AAAAAA'>Notes</td>
                    219: <td bgcolor="#CCCCCC">$content{'notes'}&nbsp;</td></tr>
                    220: <tr><td bgcolor='#AAAAAA'>Abstract</td>
                    221: <td bgcolor="#CCCCCC">$content{'abstract'}&nbsp;</td></tr>
                    222: <tr><td bgcolor='#AAAAAA'>MIME Type</td>
                    223: <td bgcolor="#CCCCCC">$mime ($content{'mime'})&nbsp;</td></tr>
                    224: <tr><td bgcolor='#AAAAAA'>Language</td>
                    225: <td bgcolor="#CCCCCC">$language&nbsp;</td></tr>
                    226: <tr><td bgcolor='#AAAAAA'>Creation Date</td>
                    227: <td bgcolor="#CCCCCC">$creationdate&nbsp;</td></tr>
                    228: <tr><td bgcolor='#AAAAAA'>
                    229: Last Revision Date</td><td bgcolor="#CCCCCC">$lastrevisiondate&nbsp;</td></tr>
                    230: <tr><td bgcolor='#AAAAAA'>Publisher/Owner</td>
                    231: <td bgcolor="#CCCCCC">$content{'owner'}&nbsp;</td></tr>
                    232: <tr><td bgcolor='#AAAAAA'>Copyright/Distribution</td>
                    233: <td bgcolor="#CCCCCC">$content{'copyright'}
                    234: </table>
1.1       www       235: ENDHEAD
                    236:   delete($content{'title'});
                    237:   delete($content{'author'});
                    238:   delete($content{'subject'});
                    239:   delete($content{'keywords'});
                    240:   delete($content{'notes'});
                    241:   delete($content{'abstract'});
                    242:   delete($content{'mime'});
                    243:   delete($content{'language'});
                    244:   delete($content{'creationdate'});
                    245:   delete($content{'lastrevisiondate'});
                    246:   delete($content{'owner'});
                    247:   delete($content{'copyright'});
1.7       www       248:   if ($ENV{'user.adv'}) {
1.11      www       249: # ------------------------------------------------------------ Dynamic Metadata
1.15      www       250:    $r->print(
                    251:    '<h3>Dynamic Metadata (updated periodically)</h3>Processing ...<br>');
                    252:    $r->rflush();
1.10      www       253:     my %items=(
                    254:  'count'      => 'Network-wide number of accesses (hits)',
                    255:  'course'     => 'Network-wide number of courses using resource',
                    256:  'usage'      => 'Number of resources using or importing resource',
1.11      www       257:  'clear'      => 'Material presented in clear way',
                    258:  'depth'      => 'Material covered with sufficient depth',
                    259:  'helpful'    => 'Material is helpful',
                    260:  'correct'    => 'Material appears to be correct',
                    261:  'technical'  => 'Resource is technically correct', 
1.10      www       262:  'avetries'   => 'Average number of tries till solved',
                    263:  'stdno'      => 'Total number of students who have worked on this problem',
                    264:  'difficulty' => 'Degree of difficulty');
                    265:    my %dynmeta=&dynamicmeta($uri);
1.11      www       266:    $r->print(
                    267: '</table><h4>Access and Usage Statistics</h4><table cellspacing=2 border=0>');
1.10      www       268:    foreach ('count','usage','course') {
1.11      www       269:        $r->print(
                    270: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
                    271: $dynmeta{$_}."&nbsp;</td></tr>\n");
                    272:    }
                    273:        $r->print('</table>');
1.10      www       274:    if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
1.11      www       275:       $r->print(
                    276: '<h4>Assessment Statistical Data</h4><table cellspacing=2 border=0>');
1.12      www       277:       foreach ('stdno','avetries') {
1.11      www       278:           $r->print(
                    279: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
                    280: $dynmeta{$_}."&nbsp;</td></tr>\n");
                    281:       }
1.12      www       282:       foreach ('difficulty') {
                    283:          $r->print(
                    284: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
                    285: &diffgraph($dynmeta{$_})."</td></tr>\n");
                    286:       }
1.11      www       287:       $r->print('</table>');    
1.10      www       288:    }
1.11      www       289:    $r->print('<h4>Evaluation Data</h4><table cellspacing=2 border=0>');
1.10      www       290:    foreach ('clear','depth','helpful','correct','technical') {
1.11      www       291:        $r->print(
                    292: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
1.12      www       293: &evalgraph($dynmeta{$_})."</td></tr>\n");
1.10      www       294:    }    
1.11      www       295:    $r->print('</table>');
                    296:    $disuri=~/^(\w+)\/(\w+)\//;   
1.10      www       297:    if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
                    298:        || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
                    299:       $r->print(
                    300:   '<h4>Evaluation Comments (visible to author and co-authors only)</h4>'.
1.23    ! www       301:       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
        !           302:       $r->print(
        !           303:    '<h4>Error Messages (visible to author and co-authors only)</h4>');
        !           304:       my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$1,$2);
        !           305:       foreach (keys %errormsgs) {
        !           306: 	if ($_=~/^$disuri\_\d+$/) {
        !           307:           my %content=&Apache::lonmsg::unpackagemsg($errormsgs{$_});
        !           308: 	  $r->print('<b>'.$content{'time'}.'</b>: '.$content{'message'}.
        !           309:                     '<br />');
        !           310:         }
        !           311:       }      
1.10      www       312:    }
1.11      www       313: # ------------------------------------------------------------- All other stuff
1.10      www       314:    $r->print(
                    315:  '<h3>Additional Metadata (non-standard, parameters, exports)</h3>');
                    316:    foreach (sort keys %content) {
1.3       www       317:       my $name=$_;
                    318:       my $display=&Apache::lonnet::metadata($uri,$name.'.display');
1.5       www       319:       unless ($display) { $display=$name; };
                    320:       my $otherinfo='';
1.14      harris41  321:       foreach ('name','part','type','default') {
1.5       www       322:           if (defined(&Apache::lonnet::metadata($uri,$name.'.'.$_))) {
                    323:              $otherinfo.=' '.$_.'='.
                    324: 		 &Apache::lonnet::metadata($uri,$name.'.'.$_).'; ';
                    325:           }
1.14      harris41  326:       }
1.5       www       327:       $r->print('<b>'.$display.':</b> '.$content{$name});
                    328:       if ($otherinfo) {
                    329:          $r->print(' ('.$otherinfo.')');
                    330:       }
                    331:       $r->print("<br>\n");
1.10      www       332:    }
1.7       www       333:   }
1.23    ! www       334: # ===================================================== End Resource Space Call
        !           335:  } else {
        !           336: # ===================================================== Construction Space Call
        !           337: 
        !           338: # ----------------------------------------------------------- Set document type
        !           339: 
        !           340:   $r->content_type('text/html');
        !           341:   $r->send_http_header;
        !           342: 
        !           343:   return OK if $r->header_only;
        !           344: # ---------------------------------------------------------------------- Header
        !           345:   my $bodytag=&Apache::loncommon::bodytag('Edit Catalog Information');
        !           346:   my $disuri=$uri;
        !           347:   my $fn=&Apache::lonnet::filelocation('',$uri);
        !           348:   $disuri=~s/^\/\~\w+//;
        !           349:   $disuri=~s/\.meta$//;
        !           350:   my $displayfile='Catalog Information for '.$disuri;
        !           351:   if ($disuri=~/\/default$/) {
        !           352:       my $dir=$disuri;
        !           353:       $dir=~s/default$//;
        !           354:       $displayfile='Default Cataloging Information for Directory '.$dir;
        !           355:   }
        !           356:   %Apache::lonpublisher::metadatafields=();
        !           357:   %Apache::lonpublisher::metadatakeys=();
        !           358:   &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
        !           359:   $r->print(<<ENDEDIT);
        !           360: <html><head><title>Edit Catalog Information</title></head>
        !           361: $bodytag
        !           362: <h1>$displayfile</h1>
        !           363: ENDEDIT
        !           364:    foreach (keys %Apache::lonpublisher::metadatafields) {
        !           365:        $r->print('<br />'.$_.' '.$Apache::lonpublisher::metadatafields{$_});
        !           366:    }
        !           367:  }
        !           368:  $r->print('</body></html>');
        !           369:  return OK;
1.1       www       370: }
                    371: 
                    372: 1;
                    373: __END__
                    374: 
                    375: 
                    376: 
                    377: 
                    378: 
                    379: 
                    380: 

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