File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.51: download - view: text, annotated - select for diffs
Tue Dec 30 22:19:18 2003 UTC (20 years, 5 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #2444: show bombs in construction space.

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

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