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

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

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