File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.63: download - view: text, annotated - select for diffs
Mon Apr 12 21:13:13 2004 UTC (20 years, 1 month ago) by matthew
Branches: MAIN
CVS tags: HEAD
Rewrote &dynamicmeta (old version was cut & paste of old searchcat.pl) to
call lonmetadata::process_reseval_data and process_dynamic_metadata.

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

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