File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.47: download - view: text, annotated - select for diffs
Mon Dec 29 19:01:27 2003 UTC (20 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Correct language headers in loncfile
Improved filename crumbs
Better prettyprint

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

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