File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.61: download - view: text, annotated - select for diffs
Wed Mar 31 05:24:00 2004 UTC (20 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- trying to be UTF8 transparent

    1: # The LearningOnline Network with CAPA
    2: # Metadata display handler
    3: #
    4: # $Id: lonmeta.pm,v 1.61 2004/03/31 05:24:00 albertel 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: 				   'authorspace' => 'Author Space',
  216: 				   'modifyinguser' => 'Last Modifying User',
  217: 				   'subject' => 'Subject',
  218: 				   'keywords' => 'Keyword(s)',
  219: 				   'notes' => 'Notes',
  220: 				   'abstract' => 'Abstract',
  221:                                    'lowestgradelevel' => 'Lowest Grade Level',
  222:                                    'highestgradelevel' => 'Highest Grade Level',
  223:                                    'standards' => 'Standards',
  224: 				   'mime' => 'MIME Type',
  225: 				   'language' => 'Language',
  226: 				   'creationdate' => 'Creation Date',
  227: 				   'lastrevisiondate' => 'Last Revision Date',
  228: 				   'owner' => 'Publisher/Owner',
  229:                                    'copyright' => 'Copyright/Distribution',
  230: 				   'customdistributionfile' => 'Custom Distribution File',
  231:                                    'obsolete' => 'Obsolete',
  232: 				   'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
  233: 				   'count'      => 'Network-wide number of accesses (hits)',
  234: 				   'course'     => 'Network-wide number of courses using resource',
  235: 				   'course_list' => 'Network-wide courses using resource',
  236: 				   'sequsage'      => 'Number of resources using or importing resource',
  237: 				   'sequsage_list' => 'Resources using or importing resource',
  238: 				   'goto'       => 'Number of resources that follow this resource in maps',
  239: 				   'goto_list'  => 'Resources that follow this resource in maps',
  240: 				   'comefrom'   => 'Number of resources that lead up to this resource in maps',
  241: 				   'comefrom_list' => 'Resources that lead up to this resource in maps',
  242: 				   'clear'      => 'Material presented in clear way',
  243: 				   'depth'      => 'Material covered with sufficient depth',
  244: 				   'helpful'    => 'Material is helpful',
  245: 				   'correct'    => 'Material appears to be correct',
  246: 				   'technical'  => 'Resource is technically correct', 
  247: 				   'avetries'   => 'Average number of tries till solved',
  248: 				   'stdno'      => 'Total number of students who have worked on this problem',
  249: 				   'difficulty' => 'Degree of difficulty'
  250: 				       );
  251: }
  252: 
  253: # =========================================== Pretty printing of metadata field
  254: 
  255: sub prettyprint {
  256:     my ($type,$value)=@_;
  257:     unless (defined($value)) { return '&nbsp;'; }
  258: # Title
  259:     if ($type eq 'title') {
  260: 	return '<font size="+1" face="arial">'.$value.'</font>';
  261:     }
  262: # Dates
  263:     if (($type eq 'creationdate') ||
  264: 	($type eq 'lastrevisiondate')) {
  265: 	return ($value?&Apache::lonlocal::locallocaltime(
  266: 			  &Apache::lonmysql::unsqltime($value)):
  267: 		&mt('not available'));
  268:     }
  269: # Language
  270:     if ($type eq 'language') {
  271: 	return &Apache::loncommon::languagedescription($value);
  272:     }
  273: # Copyright
  274:     if ($type eq 'copyright') {
  275: 	return &Apache::loncommon::copyrightdescription($value);
  276:     }
  277: # MIME
  278:     if ($type eq 'mime') {
  279:        return '<img src="'.&Apache::loncommon::icon($value).'" />&nbsp;'.
  280: 	   &Apache::loncommon::filedescription($value);
  281:    }
  282: # Person
  283:     if (($type eq 'author') || 
  284: 	($type eq 'owner') ||
  285: 	($type eq 'modifyinguser') ||
  286: 	($type eq 'authorspace')) {
  287: 	$value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
  288: 	return $value;
  289:     }
  290: # Gradelevel
  291:     if (($type eq 'lowestgradelevel') ||
  292: 	($type eq 'highestgradelevel')) {
  293: 	return &Apache::loncommon::gradeleveldescription($value);
  294:     }
  295: # Only for advance users below
  296:     unless ($ENV{'user.adv'}) { return '<i>- '.&mt('not displayed').' -</i>' };
  297: # File
  298:     if (($type eq 'customdistributionfile') ||
  299: 	($type eq 'obsoletereplacement') ||
  300: 	($type eq 'goto_list') ||
  301: 	($type eq 'comefrom_list') ||
  302: 	($type eq 'sequsage_list')) {
  303: 	return join('<br />',map {
  304: 	       my $url=&Apache::lonnet::clutter($_);
  305: 	       '<br /><b>'.&Apache::lonnet::gettitle($url).'</b>'.
  306: 	       &Apache::lonhtmlcommon::crumbs($url,'preview','');
  307: 	    } split(/\s*\,\s*/,$value));
  308:     }
  309: # Evaluations
  310:     if (($type eq 'clear') ||
  311: 	($type eq 'depth') ||
  312: 	($type eq 'helpful') ||
  313: 	($type eq 'correct') ||
  314: 	($type eq 'technical')) {
  315: 	return &evalgraph($value);
  316:     }
  317: # Difficulty
  318:     if ($type eq 'difficulty') {
  319: 	return &diffgraph($value);
  320:     }
  321: # List of courses
  322:     if ($type=~/\_list/) {
  323: 	return join('<br />',map {
  324: 	    my %courseinfo=&Apache::lonnet::coursedescription($_);  
  325: 	    '<a href="/public/'.
  326: 		$courseinfo{'domain'}.'/'.$courseinfo{'num'}.'/syllabus" target="preview">'.
  327: 		$courseinfo{'description'}.'</a>';
  328: 	} split(/\s*\,\s*/,$value));
  329:     }
  330: # No pretty print found
  331:     return $value;
  332: }
  333: # ============================================== Pretty input of metadata field
  334: 
  335: sub direct {
  336:     return shift;
  337: }
  338: 
  339: sub selectbox {
  340:     my ($name,$value,$functionref,@idlist)=@_;
  341:     unless (defined($functionref)) { $functionref=\&direct; }
  342:     my $selout='<select name="'.$name.'">';
  343:     foreach (@idlist) {
  344:         $selout.='<option value=\''.$_.'\'';
  345:         if ($_ eq $value) {
  346: 	    $selout.=' selected>'.&{$functionref}($_).'</option>';
  347: 	}
  348:         else {$selout.='>'.&{$functionref}($_).'</option>';}
  349:     }
  350:     return $selout.'</select>';
  351: }
  352: 
  353: sub relatedfield {
  354:     my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
  355:     unless ($relatedsearchflag) { return ''; }
  356:     unless (defined($relatedsep)) { $relatedsep=' '; }
  357:     unless ($show) { return $relatedsep.'&nbsp;'; }
  358:     return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
  359: 	($relatedvalue?' checked="1"':'').' />';
  360: }
  361: 
  362: sub prettyinput {
  363:     my ($type,$value,$fieldname,$formname,
  364: 	$relatedsearchflag,$relatedsep,$relatedvalue)=@_;
  365: # Language
  366:     if ($type eq 'language') {
  367: 	return &selectbox($fieldname,
  368: 			  $value,
  369: 			  \&Apache::loncommon::languagedescription,
  370: 			  (&Apache::loncommon::languageids)).
  371: 	       &relatedfield(0,$relatedsearchflag,$relatedsep);
  372:     }
  373: # Copyright
  374:     if ($type eq 'copyright') {
  375: 	return &selectbox($fieldname,
  376: 			  $value,
  377: 			  \&Apache::loncommon::copyrightdescription,
  378: 			  (&Apache::loncommon::copyrightids)).
  379: 	       &relatedfield(0,$relatedsearchflag,$relatedsep);
  380:     }
  381: # Gradelevels
  382:     if (($type eq 'lowestgradelevel') ||
  383: 	($type eq 'highestgradelevel')) {
  384: 	return &Apache::loncommon::select_level_form($value,$fieldname).
  385: 	       &relatedfield(0,$relatedsearchflag,$relatedsep);
  386:     }
  387: # Obsolete
  388:     if ($type eq 'obsolete') {
  389: 	return '<input type="checkbox" name="'.$fieldname.'"'.
  390: 	    ($value?' checked="1"':'').' />'.
  391: 	       &relatedfield(0,$relatedsearchflag,$relatedsep); 
  392:     }
  393: # Obsolete replacement file
  394:     if ($type eq 'obsoletereplacement') {
  395: 	return '<input type="text" name="'.$fieldname.
  396: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  397: 	    "('".$formname."','".$fieldname."'".
  398: 	    ",'')\">".&mt('Select').'</a>'.
  399: 	       &relatedfield(0,$relatedsearchflag,$relatedsep); 
  400:    }
  401: # Customdistribution file
  402:     if ($type eq 'customdistributionfile') {
  403: 	return '<input type="text" name="'.$fieldname.
  404: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  405: 	    "('".$formname."','".$fieldname."'".
  406: 	    ",'rights')\">".&mt('Select').'</a>'.
  407: 	       &relatedfield(0,$relatedsearchflag,$relatedsep); 
  408:     }
  409: # Dates
  410:     if (($type eq 'creationdate') ||
  411: 	($type eq 'lastrevisiondate')) {
  412: 	return &Apache::lonhtmlcommon::date_setter($formname,
  413: 						   $fieldname,$value).
  414: 	       &relatedfield(0,$relatedsearchflag,$relatedsep);
  415:     }
  416: # No pretty input found
  417:     $value=~s/^\s+//gs;
  418:     $value=~s/\s+$//gs;
  419:     $value=~s/\s+/ /gs;
  420:     $value=~s/\"/\&quod\;/gs;
  421:     return 
  422:     '<input type="text" name="'.$fieldname.'" size="80" value="'.$value.'" />'.
  423:     &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue); 
  424: }
  425: 
  426: # ================================================================ Main Handler
  427: 
  428: sub handler {
  429:   my $r=shift;
  430: 
  431:     my $loaderror=&Apache::lonnet::overloaderror($r);
  432:     if ($loaderror) { return $loaderror; }
  433: 
  434: 
  435:     my $uri=$r->uri;
  436: 
  437: # ====================================================== Looking for all bombs?
  438:   if ($uri=~/\/adm\/bombs\/(.*)$/) {
  439: # ----------------------------------------------------------- Set document type
  440:       $uri=&Apache::lonnet::declutter($1);
  441:       &Apache::loncommon::content_type($r,'text/html');
  442:       $r->send_http_header;
  443:       
  444:       return OK if $r->header_only;
  445:       $r->print(&Apache::loncommon::bodytag('Error Messages'));
  446:       $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
  447:       my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
  448:       if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
  449: 	  my %brokenurls=&Apache::lonmsg::all_url_author_res_msg($author,$domain);
  450: 	  foreach (sort keys %brokenurls) {
  451: 	      if ($_=~/^\Q$uri\E/) {
  452: 		  $r->print(&Apache::lonhtmlcommon::crumbs(&Apache::lonnet::clutter($_)).
  453: 		    &Apache::lonmsg::retrieve_author_res_msg($_).'<hr />');
  454: 	      }
  455: 	  }
  456:       } else {
  457: 	  $r->print(&mt('Not authorized'));
  458:       }
  459:       $r->print('</body></html>');
  460:   } elsif ($uri!~/^\/\~/) { 
  461: # =========================================== This is not in construction space
  462:     my ($resdomain,$resuser)=
  463:            (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
  464: 
  465:     $loaderror=
  466:        &Apache::lonnet::overloaderror($r,
  467:          &Apache::lonnet::homeserver($resuser,$resdomain));
  468:     if ($loaderror) { return $loaderror; }
  469: 
  470:   my %content=();
  471: 
  472: # ----------------------------------------------------------- Set document type
  473: 
  474:   &Apache::loncommon::content_type($r,'text/html');
  475:   $r->send_http_header;
  476: 
  477:   return OK if $r->header_only;
  478: 
  479: # ------------------------------------------------------------------- Read file
  480:   foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
  481:       $content{$_}=&Apache::lonnet::metadata($uri,$_);
  482:   }
  483: # --------------------------------------------------------------- Render Output
  484: # displayed url
  485:     my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
  486:     $uri=~s/\.meta$//;
  487:     my $disuri=&Apache::lonnet::clutter($uri);
  488: # version
  489:     my $currentversion=&Apache::lonnet::getversion($disuri);
  490:     my $versiondisplay='';
  491:     if ($thisversion) {
  492: 	$versiondisplay=&mt('Version').': '.$thisversion.
  493: 	    ' ('.&mt('most recent version').': '.
  494: 	    ($currentversion>0?$currentversion:&mt('information not available')).')';
  495:     } else {
  496: 	$versiondisplay='Version: '.$currentversion;
  497:     }
  498: # crumbify displayed URL
  499:     $disuri=&Apache::lonhtmlcommon::crumbs($disuri);
  500: # obsolete
  501:     my $obsolete=$content{'obsolete'};
  502:     my $obsoletewarning='';
  503:     if (($obsolete) && ($ENV{'user.adv'})) {
  504: 	$obsoletewarning='<p><font color="red">'.
  505: 	    &mt('This resource has been marked obsolete by the author(s)').'</font></p>';
  506:     }
  507: 
  508:     my %lt=&fieldnames();
  509:     my $table='';
  510:     my $bodytag=&Apache::loncommon::bodytag
  511:             ('Catalog Information','','','',$resdomain);
  512:     foreach ('title', 
  513: 	     'author', 
  514: 	     'subject', 
  515: 	     'keywords', 
  516: 	     'notes', 
  517: 	     'abstract',
  518: 	     'lowestgradelevel',
  519: 	     'highestgradelevel',
  520: 	     'standards', 
  521: 	     'mime', 
  522: 	     'language', 
  523: 	     'creationdate', 
  524: 	     'lastrevisiondate', 
  525: 	     'owner', 
  526: 	     'copyright', 
  527: 	     'customdistributionfile', 
  528: 	     'obsolete', 
  529: 	     'obsoletereplacement') {
  530: 	$table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
  531: 	        '</td><td bgcolor="#CCCCCC">'.
  532:                 &prettyprint($_,$content{$_}).'</td></tr>';
  533: 	delete $content{$_};
  534:     }
  535: 
  536:   $r->print(<<ENDHEAD);
  537: <html><head><title>Catalog Information</title></head>
  538: $bodytag
  539: <h2>$content{'title'}</h2>
  540: <h3><tt>$disuri</tt></h3>
  541: $obsoletewarning
  542: $versiondisplay<br />
  543: <table cellspacing=2 border=0>
  544: $table
  545: </table>
  546: ENDHEAD
  547:   if ($ENV{'user.adv'}) {
  548: # ------------------------------------------------------------ Dynamic Metadata
  549:       $r->print(
  550: 		'<h3>'.&mt('Dynamic Metadata').' ('.
  551: 		&mt('updated periodically').')</h3>'.&mt('Processing').
  552: 		' ...<br />');
  553:       $r->rflush();
  554:       my %items=&fieldnames();
  555:       my %dynmeta=&dynamicmeta($uri);
  556: # General Access and Usage Statistics
  557:       $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4><table cellspacing=2 border=0>');
  558:       foreach ('count',
  559: 	       'sequsage','sequsage_list',
  560: 	       'comefrom','comefrom_list',
  561: 	       'goto','goto_list',
  562: 	       'course','course_list') {
  563: 	  $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td><td bgcolor="#CCCCCC">'.
  564: 		    &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  565:       }
  566:       $r->print('</table>');
  567:       if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
  568: # This is an assessment, print assessment data
  569: 	  $r->print(
  570: 		    '<h4>'.&mt('Assessment Statistical Data').'</h4><table cellspacing=2 border=0>');
  571: 	  foreach ('stdno','avetries','difficulty') {
  572: 	      $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td><td bgcolor="#CCCCCC">'.
  573: 			&prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  574: 	  }
  575: 	  $r->print('</table>');    
  576:       }
  577:       $r->print('<h4>'.&mt('Evaluation Data').'</h4><table cellspacing=2 border=0>');
  578:       foreach ('clear','depth','helpful','correct','technical') {
  579: 	  $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td><td bgcolor="#CCCCCC">'.
  580: 		    &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  581:      }    
  582:       $r->print('</table>');
  583:       $uri=~/^\/res\/(\w+)\/(\w+)\//; 
  584:       if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
  585: 	  || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
  586: 	  $r->print('<h4>'.&mt('Evaluation Comments').' ('.
  587: 		    &mt('visible to author and co-authors only').')</h4>'.
  588: 		    '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
  589: 	  $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
  590: 		    &mt('visible to author and co-authors only').')</h4>'.
  591: 		    &Apache::lonmsg::retrieve_author_res_msg($uri));
  592:       }
  593: # ------------------------------------------------------------- All other stuff
  594:       $r->print(
  595: 		'<h3>'.&mt('Additional Metadata (non-standard, parameters, exports)').'</h3>');
  596:       foreach (sort keys %content) {
  597: 	  my $name=$_;
  598: 	  unless ($name=~/\.display$/) {
  599: 	      my $display=&Apache::lonnet::metadata($uri,$name.'.display');
  600: 	      unless ($display) { $display=$name; };
  601: 	      my $otherinfo='';
  602: 	      foreach ('name','part','type','default') {
  603: 		  if (defined(&Apache::lonnet::metadata($uri,$name.'.'.$_))) {
  604: 		      $otherinfo.=' '.$_.'='.
  605: 			  &Apache::lonnet::metadata($uri,$name.'.'.$_).'; ';
  606: 		  }
  607: 	      }
  608: 	      $r->print('<b>'.$display.':</b> '.$content{$name});
  609: 	      if ($otherinfo) {
  610: 		  $r->print(' ('.$otherinfo.')');
  611: 	      }
  612: 	      $r->print("<br />\n");
  613: 	  }
  614:       }
  615:   }
  616: # ===================================================== End Resource Space Call
  617:  } else {
  618: # ===================================================== Construction Space Call
  619: 
  620: # ----------------------------------------------------------- Set document type
  621: 
  622:   &Apache::loncommon::content_type($r,'text/html');
  623:   $r->send_http_header;
  624: 
  625:   return OK if $r->header_only;
  626: # ---------------------------------------------------------------------- Header
  627:   my $disuri=$uri;
  628:   my $fn=&Apache::lonnet::filelocation('',$uri);
  629:   $disuri=~s/^\/\~/\/priv\//;
  630:   $disuri=~s/\.meta$//;
  631:   my $target=$uri;
  632:   $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
  633:   $target=~s/\.meta$//;
  634:   my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
  635:   if ($bombs) {
  636:       if ($ENV{'form.delmsg'}) {
  637: 	  if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
  638: 	      $bombs=&mt('Messages deleted.');
  639: 	  } else {
  640: 	      $bombs=&mt('Error deleting messages');
  641: 	  }
  642:       }
  643:       my $bodytag=&Apache::loncommon::bodytag('Error Messages');
  644:       my $del=&mt('Delete Messages');
  645:       $r->print(<<ENDBOMBS);
  646: <html><head><title>Edit Catalog Information</title></head>
  647: $bodytag
  648: <h1>$disuri</h1>
  649: <form method="post" name="defaultmeta">
  650: <input type="submit" name="delmsg" value="$del" />
  651: <br />$bombs
  652: </form>
  653: </body>
  654: </html>
  655: ENDBOMBS
  656:   } else {
  657:       my $displayfile='Catalog Information for '.$disuri;
  658:       if ($disuri=~/\/default$/) {
  659: 	  my $dir=$disuri;
  660: 	  $dir=~s/default$//;
  661: 	  $displayfile=&mt('Default Cataloging Information for Directory').' '.
  662: 	      $dir;
  663:       }
  664:       my $bodytag=&Apache::loncommon::bodytag('Edit Catalog Information');
  665:       %Apache::lonpublisher::metadatafields=();
  666:       %Apache::lonpublisher::metadatakeys=();
  667:       &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
  668:       $r->print(<<ENDEDIT);
  669: <html><head><title>Edit Catalog Information</title></head>
  670: $bodytag
  671: <h1>$displayfile</h1>
  672: <form method="post" name="defaultmeta">
  673: ENDEDIT
  674:       $r->print('<script language="JavaScript">'.
  675: 		&Apache::loncommon::browser_and_searcher_javascript.
  676: 		'</script>');
  677:       my %lt=&fieldnames();
  678:       foreach ('author','title','subject','keywords','abstract','notes',
  679: 	       'copyright','customdistributionfile','language','standards',
  680: 	       'lowestgradelevel','highestgradelevel',
  681: 	       'obsolete','obsoletereplacement') {
  682: 	  if (defined($ENV{'form.new_'.$_})) {
  683: 	      $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};
  684: 	  }
  685: 	  unless ($Apache::lonpublisher::metadatafields{'copyright'}) {
  686: 	      $Apache::lonpublisher::metadatafields{'copyright'}='default';
  687: 	  }
  688: 	  $r->print('<p>'.$lt{$_}.': '.&prettyinput($_,
  689: 						    $Apache::lonpublisher::metadatafields{$_},
  690: 						    'new_'.$_,'defaultmeta').'</p>');
  691:       }
  692:       if ($ENV{'form.store'}) {
  693: 	  my $mfh;
  694: 	  unless ($mfh=Apache::File->new('>'.$fn)) {
  695: 	      $r->print(
  696: 			'<p><font color=red>'.&mt('Could not write metadata').', '.
  697: 			&mt('FAIL').'</font>');
  698: 	  } else {
  699: 	      foreach (sort keys %Apache::lonpublisher::metadatafields) {
  700: 		  unless ($_=~/\./) {
  701: 		      my $unikey=$_;
  702: 		      $unikey=~/^([A-Za-z]+)/;
  703: 		      my $tag=$1;
  704: 		      $tag=~tr/A-Z/a-z/;
  705: 		      print $mfh "\n\<$tag";
  706: 		      foreach 
  707: 			  (split(/\,/,$Apache::lonpublisher::metadatakeys{$unikey})) {
  708: 			      my $value=
  709: 				  $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
  710: 			      $value=~s/\"/\'\'/g;
  711: 			      print $mfh ' '.$_.'="'.$value.'"';
  712: 			  }
  713: 		      print $mfh '>'.
  714: 			  &HTML::Entities::encode($Apache::lonpublisher::metadatafields{$unikey},'<>&"')
  715: 			  .'</'.$tag.'>';
  716: 		  }
  717: 	      }
  718: 	      $r->print('<p>'.&mt('Wrote Metadata'));
  719: 	  }
  720:       }
  721:       $r->print(
  722: 		'<br /><input type="submit" name="store" value="'.
  723: 		&mt('Store Catalog Information').'"></form></body></html>');
  724:    }
  725:   }
  726:   return OK;
  727: }
  728: 
  729: # ================================================================= BEGIN Block
  730: BEGIN {
  731: # Get columns of MySQL metadata table
  732:     @columns=&Apache::lonmysql::col_order('metadata');
  733: }
  734: 1;
  735: __END__
  736: 
  737: 
  738: 
  739: 
  740: 
  741: 
  742: 

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