File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.46: download - view: text, annotated - select for diffs
Mon Dec 29 17:11:53 2003 UTC (20 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
New prettyprint function to produce consistent metadata output.

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

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