File:  [LON-CAPA] / loncom / interface / lonmeta.pm
Revision 1.112: download - view: text, annotated - select for diffs
Fri Oct 14 16:34:17 2005 UTC (18 years, 7 months ago) by banghart
Branches: MAIN
CVS tags: HEAD
	Add 'metadata' to all key values for retricted metadata

    1: # The LearningOnline Network with CAPA
    2: # Metadata display handler
    3: #
    4: # $Id: lonmeta.pm,v 1.112 2005/10/14 16:34:17 banghart 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: 
   44: ############################################################
   45: ############################################################
   46: ##
   47: ## &get_dynamic_metadata_from_sql($url)
   48: ## 
   49: ## Queries sql database for dynamic metdata
   50: ## Returns a hash of hashes, with keys of urls which match $url
   51: ## Returned fields are given below.
   52: ##
   53: ## Examples:
   54: ## 
   55: ## %DynamicMetadata = &Apache::lonmeta::get_dynmaic_metadata_from_sql
   56: ##     ('/res/msu/korte/');
   57: ##
   58: ## $DynamicMetadata{'/res/msu/korte/example.problem'}->{$field}
   59: ##
   60: ############################################################
   61: ############################################################
   62: sub get_dynamic_metadata_from_sql {
   63:     my ($url) = shift();
   64:     my ($authordom,$author)=($url=~m:^/res/(\w+)/(\w+)/:);
   65:     if (! defined($authordom)) {
   66:         $authordom = shift();
   67:     }
   68:     if  (! defined($author)) { 
   69:         $author = shift();
   70:     }
   71:     if (! defined($authordom) || ! defined($author)) {
   72:         return ();
   73:     }
   74:     my @Fields = ('url','count','course',
   75:                   'goto','goto_list',
   76:                   'comefrom','comefrom_list',
   77:                   'sequsage','sequsage_list',
   78:                   'stdno','stdno_list',
   79: 		  'dependencies',
   80:                   'avetries','avetries_list',
   81:                   'difficulty','difficulty_list',
   82:                   'disc','disc_list',
   83:                   'clear','technical','correct',
   84:                   'helpful','depth');
   85:     #
   86:     my $query = 'SELECT '.join(',',@Fields).
   87:         ' FROM metadata WHERE url LIKE "'.$url.'%"';
   88:     my $server = &Apache::lonnet::homeserver($author,$authordom);
   89:     my $reply = &Apache::lonnet::metadata_query($query,undef,undef,
   90:                                                 ,[$server]);
   91:     return () if (! defined($reply) || ref($reply) ne 'HASH');
   92:     my $filename = $reply->{$server};
   93:     if (! defined($filename) || $filename =~ /^error/) {
   94:         return ();
   95:     }
   96:     my $max_time = time + 10; # wait 10 seconds for results at most
   97:     my %ReturnHash;
   98:     #
   99:     # Look for results
  100:     my $finished = 0;
  101:     while (! $finished && time < $max_time) {
  102:         my $datafile=$Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/'.$filename;
  103:         if (! -e "$datafile.end") { next; }
  104:         my $fh;
  105:         if (!($fh=Apache::File->new($datafile))) { next; }
  106:         while (my $result = <$fh>) {
  107:             chomp($result);
  108:             next if (! $result);
  109:             my @Data = 
  110:                 map { 
  111:                     &Apache::lonnet::unescape($_); 
  112:                 } split(',',$result);
  113:             my $url = $Data[0];
  114:             for (my $i=0;$i<=$#Fields;$i++) {
  115:                 $ReturnHash{$url}->{$Fields[$i]}=$Data[$i];
  116:             }
  117:         }
  118:         $finished = 1;
  119:     }
  120:     #
  121:     return %ReturnHash;
  122: }
  123: 
  124: 
  125: # Fetch and evaluate dynamic metadata
  126: sub dynamicmeta {
  127:     my $url=&Apache::lonnet::declutter(shift);
  128:     $url=~s/\.meta$//;
  129:     my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
  130:     my $regexp=$url;
  131:     $regexp=~s/(\W)/\\$1/g;
  132:     $regexp='___'.$regexp.'___';
  133:     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
  134: 				       $aauthor,$regexp);
  135:     my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
  136:     my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
  137:                                                                \%DynamicData);
  138:     #
  139:     # Deal with 'count' separately
  140:     $Data{'count'} = &access_count($url,$aauthor,$adomain);
  141:     #
  142:     # Debugging code I will probably need later
  143:     if (0) {
  144:         &Apache::lonnet::logthis('Dynamic Metadata');
  145:         while(my($k,$v)=each(%Data)){
  146:             &Apache::lonnet::logthis('    "'.$k.'"=>"'.$v.'"');
  147:         }
  148:         &Apache::lonnet::logthis('-------------------');
  149:     }
  150:     return %Data;
  151: }
  152: 
  153: sub access_count {
  154:     my ($src,$author,$adomain) = @_;
  155:     my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
  156:                                         $author,$src);
  157:     if (! exists($countdata{$src})) {
  158:         return &mt('Not Available');
  159:     } else {
  160:         return $countdata{$src};
  161:     }
  162: }
  163: 
  164: # Try to make an alt tag if there is none
  165: sub alttag {
  166:     my ($base,$src)=@_;
  167:     my $fullpath=&Apache::lonnet::hreflocation($base,$src);
  168:     my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
  169:         &Apache::lonnet::metadata($fullpath,'subject').' '.
  170:         &Apache::lonnet::metadata($fullpath,'abstract');
  171:     $alttag=~s/\s+/ /gs;
  172:     $alttag=~s/\"//gs;
  173:     $alttag=~s/\'//gs;
  174:     $alttag=~s/\s+$//gs;
  175:     $alttag=~s/^\s+//gs;
  176:     if ($alttag) { 
  177:         return $alttag; 
  178:     } else { 
  179:         return &mt('No information available'); 
  180:     }
  181: }
  182: 
  183: # Author display
  184: sub authordisplay {
  185:     my ($aname,$adom)=@_;
  186:     return &Apache::loncommon::aboutmewrapper
  187:         (&Apache::loncommon::plainname($aname,$adom),
  188:          $aname,$adom,'preview').' <tt>['.$aname.'@'.$adom.']</tt>';
  189: }
  190: 
  191: # Pretty display
  192: sub evalgraph {
  193:     my $value=shift;
  194:     if (! $value) { 
  195:         return '';
  196:     }
  197:     my $val=int($value*10.+0.5)-10;
  198:     my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
  199:     if ($val>=20) {
  200: 	$output.='<td width="20" bgcolor="#555555">&nbsp&nbsp;</td>';
  201:     } else {
  202:         $output.='<td width="'.($val).'" bgcolor="#555555">&nbsp;</td>'.
  203:                  '<td width="'.(20-$val).'" bgcolor="#FF3333">&nbsp;</td>';
  204:     }
  205:     $output.='<td bgcolor="#FFFF33">&nbsp;</td>';
  206:     if ($val>20) {
  207: 	$output.='<td width="'.($val-20).'" bgcolor="#33FF33">&nbsp;</td>'.
  208:                  '<td width="'.(40-$val).'" bgcolor="#555555">&nbsp;</td>';
  209:     } else {
  210:         $output.='<td width="20" bgcolor="#555555">&nbsp&nbsp;</td>';
  211:     }
  212:     $output.='<td> ('.sprintf("%5.2f",$value).') </td></tr></table>';
  213:     return $output;
  214: }
  215: 
  216: sub diffgraph {
  217:     my $value=shift;
  218:     if (! $value) { 
  219:         return '';
  220:     }
  221:     my $val=int(40.0*$value+0.5);
  222:     my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
  223:                 '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
  224:     my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
  225:     for (my $i=0;$i<8;$i++) {
  226: 	if ($val>$i*5) {
  227:             $output.='<td width="5" bgcolor="'.$colors[$i].'">&nbsp;</td>';
  228:         } else {
  229: 	    $output.='<td width="5" bgcolor="#555555">&nbsp;</td>';
  230: 	}
  231:     }
  232:     $output.='<td> ('.sprintf("%3.2f",$value).') </td></tr></table>';
  233:     return $output;
  234: }
  235: 
  236: 
  237: # The field names
  238: sub fieldnames {
  239:     my $file_type=shift;
  240:     my %fields = 
  241:         ('metadata.title' => 'Title',
  242:          'metadata.author' =>'Author(s)',
  243:          'metadata.authorspace' => 'Author Space',
  244:          'metadata.modifyinguser' => 'Last Modifying User',
  245:          'metadata.subject' => 'Subject',
  246:          'metadata.keywords' => 'Keyword(s)',
  247:          'metadata.notes' => 'Notes',
  248:          'metadata.abstract' => 'Abstract',
  249:          'metadata.lowestgradelevel' => 'Lowest Grade Level',
  250:          'metadata.highestgradelevel' => 'Highest Grade Level');
  251:     if (! defined($file_type) || $file_type ne 'portfolio') {
  252:         %fields = 
  253:         (%fields,
  254:          'domain' => 'Domain',
  255:          'standards' => 'Standards',
  256:          'mime' => 'MIME Type',
  257:          'language' => 'Language',
  258:          'creationdate' => 'Creation Date',
  259:          'lastrevisiondate' => 'Last Revision Date',
  260:          'owner' => 'Publisher/Owner',
  261:          'copyright' => 'Copyright/Distribution',
  262:          'customdistributionfile' => 'Custom Distribution File',
  263:          'sourceavail' => 'Source Available',
  264:          'sourcerights' => 'Source Custom Distribution File',
  265:          'obsolete' => 'Obsolete',
  266:          'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
  267:          'count'      => 'Network-wide number of accesses (hits)',
  268:          'course'     => 'Network-wide number of courses using resource',
  269:          'course_list' => 'Network-wide courses using resource',
  270:          'sequsage'      => 'Number of resources using or importing resource',
  271:          'sequsage_list' => 'Resources using or importing resource',
  272:          'goto'       => 'Number of resources that follow this resource in maps',
  273:          'goto_list'  => 'Resources that follow this resource in maps',
  274:          'comefrom'   => 'Number of resources that lead up to this resource in maps',
  275:          'comefrom_list' => 'Resources that lead up to this resource in maps',
  276:          'clear'      => 'Material presented in clear way',
  277:          'depth'      => 'Material covered with sufficient depth',
  278:          'helpful'    => 'Material is helpful',
  279:          'correct'    => 'Material appears to be correct',
  280:          'technical'  => 'Resource is technically correct', 
  281:          'avetries'   => 'Average number of tries till solved',
  282:          'stdno'      => 'Total number of students who have worked on this problem',
  283:          'difficulty' => 'Degree of difficulty',
  284:          'disc'       => 'Degree of discrimination',
  285: 	 'dependencies' => 'Resources used by this resource',
  286:          );
  287:     }
  288:     return &Apache::lonlocal::texthash(%fields);
  289: }
  290: 
  291: sub select_course {
  292:     my ($r)=@_;
  293:     my @courses;
  294:     foreach my $key (keys (%env)) { 
  295:         
  296:         if ($key =~ m/^(course\..+)\.metadata\..+\.options/) {
  297:             my $course_key = $1;
  298:             $course_key .= '.description';
  299:             $r->print($env{$course_key}.' of '.$course_key.'<br />');
  300:             push @courses, $key;
  301:         }
  302:     }
  303:     foreach (@courses) {
  304:         $r->print($_.' was found<br />');
  305:     }
  306:     $r->print('<h3>Portfolio Meta-Data</h3><br />');
  307:     $r->print('<form action="" method="post">');
  308:     $r->print('Select your test course<br />');
  309:     $r->print('<select name="metacourse" >');
  310:     my $meta_not_found = 1;
  311:     foreach my $key (keys (%env)) {    
  312:         
  313:         if ($key =~ /\.metadata\./) {
  314:             if ($meta_not_found) {
  315:                 undef($meta_not_found);
  316:                 $r->print('<h3>Portfolio Meta-Data</h3><br />');
  317:                 $r->print('<form action="" method="post">');
  318:                 $r->print('Select your course<br />');
  319:                 $r->print('<select name="metacourse" >');
  320:             }
  321:             my $course_key = $key;
  322:             $course_key =~ s/\.metadata\..*//;
  323:             $r->print('<option value="'.$course_key.'">');
  324:             $r->print($env{$course_key.'.description'});
  325:             $r->print('</option>');
  326:         }
  327:     }
  328:     unless ($meta_not_found) {
  329:         $r->print('</select><br />');
  330:         $r->print('<input type="submit" value="Assign Portfolio Metadata" />');
  331:         $r->print('</form>');
  332:     }
  333:     return 'ok';
  334: }
  335: # Pretty printing of metadata field
  336: 
  337: sub prettyprint {
  338:     my ($type,$value,$target,$prefix,$form,$noformat)=@_;
  339: # $target,$prefix,$form are optional and for filecrumbs only
  340:     if (! defined($value)) { 
  341:         return '&nbsp;'; 
  342:     }
  343:     # Title
  344:     if ($type eq 'title') {
  345: 	return '<font size="+1" face="arial">'.$value.'</font>';
  346:     }
  347:     # Dates
  348:     if (($type eq 'creationdate') ||
  349: 	($type eq 'lastrevisiondate')) {
  350: 	return ($value?&Apache::lonlocal::locallocaltime(
  351: 			  &Apache::lonmysql::unsqltime($value)):
  352: 		&mt('not available'));
  353:     }
  354:     # Language
  355:     if ($type eq 'language') {
  356: 	return &Apache::loncommon::languagedescription($value);
  357:     }
  358:     # Copyright
  359:     if ($type eq 'copyright') {
  360: 	return &Apache::loncommon::copyrightdescription($value);
  361:     }
  362:     # Copyright
  363:     if ($type eq 'sourceavail') {
  364: 	return &Apache::loncommon::source_copyrightdescription($value);
  365:     }
  366:     # MIME
  367:     if ($type eq 'mime') {
  368:         return '<img src="'.&Apache::loncommon::icon($value).'" />&nbsp;'.
  369:             &Apache::loncommon::filedescription($value);
  370:     }
  371:     # Person
  372:     if (($type eq 'author') || 
  373: 	($type eq 'owner') ||
  374: 	($type eq 'modifyinguser') ||
  375: 	($type eq 'authorspace')) {
  376: 	$value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
  377: 	return $value;
  378:     }
  379:     # Gradelevel
  380:     if (($type eq 'lowestgradelevel') ||
  381: 	($type eq 'highestgradelevel')) {
  382: 	return &Apache::loncommon::gradeleveldescription($value);
  383:     }
  384:     # Only for advance users below
  385:     if (! $env{'user.adv'}) { 
  386:         return '<i>- '.&mt('not displayed').' -</i>';
  387:     }
  388:     # File
  389:     if (($type eq 'customdistributionfile') ||
  390: 	($type eq 'obsoletereplacement') ||
  391: 	($type eq 'goto_list') ||
  392: 	($type eq 'comefrom_list') ||
  393: 	($type eq 'sequsage_list') ||
  394: 	($type eq 'dependencies')) {
  395: 	return '<ul><font size="-1">'.join("\n",map {
  396:             my $url = &Apache::lonnet::clutter($_);
  397:             my $title = &Apache::lonnet::gettitle($url);
  398:             if ($title eq '') {
  399:                 $title = 'Untitled';
  400:                 if ($url =~ /\.sequence$/) {
  401:                     $title .= ' Sequence';
  402:                 } elsif ($url =~ /\.page$/) {
  403:                     $title .= ' Page';
  404:                 } elsif ($url =~ /\.problem$/) {
  405:                     $title .= ' Problem';
  406:                 } elsif ($url =~ /\.html$/) {
  407:                     $title .= ' HTML document';
  408:                 } elsif ($url =~ m:/syllabus$:) {
  409:                     $title .= ' Syllabus';
  410:                 } 
  411:             }
  412:             $_ = '<li>'.$title.' '.
  413: 		&Apache::lonhtmlcommon::crumbs($url,$target,$prefix,$form,'-1',$noformat).
  414:                 '</li>'
  415: 	    } split(/\s*\,\s*/,$value)).'</ul></font>';
  416:     }
  417:     # Evaluations
  418:     if (($type eq 'clear') ||
  419: 	($type eq 'depth') ||
  420: 	($type eq 'helpful') ||
  421: 	($type eq 'correct') ||
  422: 	($type eq 'technical')) {
  423: 	return &evalgraph($value);
  424:     }
  425:     # Difficulty
  426:     if ($type eq 'difficulty' || $type eq 'disc') {
  427: 	return &diffgraph($value);
  428:     }
  429:     # List of courses
  430:     if ($type=~/\_list/) {
  431:         my @Courses = split(/\s*\,\s*/,$value);
  432:         my $Str;
  433:         foreach my $course (@Courses) {
  434:             my %courseinfo = &Apache::lonnet::coursedescription($course);
  435:             if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
  436:                 next;
  437:             }
  438:             if ($Str ne '') { $Str .= '<br />'; }
  439:             $Str .= '<a href="/public/'.$courseinfo{'domain'}.'/'.
  440:                 $courseinfo{'num'}.'/syllabus" target="preview">'.
  441:                 $courseinfo{'description'}.'</a>';
  442:         }
  443: 	return $Str;
  444:     }
  445:     # No pretty print found
  446:     return $value;
  447: }
  448: 
  449: # Pretty input of metadata field
  450: sub direct {
  451:     return shift;
  452: }
  453: 
  454: sub selectbox {
  455:     my ($name,$value,$functionref,@idlist)=@_;
  456:     if (! defined($functionref)) {
  457:         $functionref=\&direct;
  458:     }
  459:     my $selout='<select name="'.$name.'">';
  460:     foreach (@idlist) {
  461:         $selout.='<option value=\''.$_.'\'';
  462:         if ($_ eq $value) {
  463: 	    $selout.=' selected>'.&{$functionref}($_).'</option>';
  464: 	}
  465:         else {$selout.='>'.&{$functionref}($_).'</option>';}
  466:     }
  467:     return $selout.'</select>';
  468: }
  469: 
  470: sub relatedfield {
  471:     my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
  472:     if (! $relatedsearchflag) { 
  473:         return '';
  474:     }
  475:     if (! defined($relatedsep)) {
  476:         $relatedsep=' ';
  477:     }
  478:     if (! $show) {
  479:         return $relatedsep.'&nbsp;';
  480:     }
  481:     return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
  482: 	($relatedvalue?' checked="1"':'').' />';
  483: }
  484: 
  485: sub prettyinput {
  486:     my ($type,$value,$fieldname,$formname,
  487: 	$relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
  488:     if (! defined($size)) {
  489:         $size = 80;
  490:     }
  491:     # Language
  492:     if ($type eq 'language') {
  493: 	return &selectbox($fieldname,
  494: 			  $value,
  495: 			  \&Apache::loncommon::languagedescription,
  496: 			  (&Apache::loncommon::languageids)).
  497:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
  498:     }
  499:     # Copyright
  500:     if ($type eq 'copyright') {
  501: 	return &selectbox($fieldname,
  502: 			  $value,
  503: 			  \&Apache::loncommon::copyrightdescription,
  504: 			  (&Apache::loncommon::copyrightids)).
  505:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
  506:     }
  507:     # Source Copyright
  508:     if ($type eq 'sourceavail') {
  509: 	return &selectbox($fieldname,
  510: 			  $value,
  511: 			  \&Apache::loncommon::source_copyrightdescription,
  512: 			  (&Apache::loncommon::source_copyrightids)).
  513:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
  514:     }
  515:     # Gradelevels
  516:     if (($type eq 'lowestgradelevel') ||
  517: 	($type eq 'highestgradelevel')) {
  518: 	return &Apache::loncommon::select_level_form($value,$fieldname).
  519:             &relatedfield(0,$relatedsearchflag,$relatedsep);
  520:     }
  521:     # Obsolete
  522:     if ($type eq 'obsolete') {
  523: 	return '<input type="checkbox" name="'.$fieldname.'"'.
  524: 	    ($value?' checked="1"':'').' />'.
  525:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  526:     }
  527:     # Obsolete replacement file
  528:     if ($type eq 'obsoletereplacement') {
  529: 	return '<input type="text" name="'.$fieldname.
  530: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  531: 	    "('".$formname."','".$fieldname."'".
  532: 	    ",'')\">".&mt('Select').'</a>'.
  533:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  534:     }
  535:     # Customdistribution file
  536:     if ($type eq 'customdistributionfile') {
  537: 	return '<input type="text" name="'.$fieldname.
  538: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  539: 	    "('".$formname."','".$fieldname."'".
  540: 	    ",'rights')\">".&mt('Select').'</a>'.
  541:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  542:     }
  543:     # Source Customdistribution file
  544:     if ($type eq 'sourcerights') {
  545: 	return '<input type="text" name="'.$fieldname.
  546: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
  547: 	    "('".$formname."','".$fieldname."'".
  548: 	    ",'rights')\">".&mt('Select').'</a>'.
  549:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
  550:     }
  551:     # Dates
  552:     if (($type eq 'creationdate') ||
  553: 	($type eq 'lastrevisiondate')) {
  554: 	return 
  555:             &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
  556:             &relatedfield(0,$relatedsearchflag,$relatedsep);
  557:     }
  558:     # No pretty input found
  559:     $value=~s/^\s+//gs;
  560:     $value=~s/\s+$//gs;
  561:     $value=~s/\s+/ /gs;
  562:     $value=~s/\"/\&quot\;/gs;
  563:     return 
  564:         '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
  565:         'value="'.$value.'" />'.
  566:         &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
  567:                       $relatedvalue); 
  568: }
  569: 
  570: # Main Handler
  571: sub handler {
  572:     my $r=shift;
  573:     #
  574:     my $uri=$r->uri;
  575:     #
  576:     # Set document type
  577:     &Apache::loncommon::content_type($r,'text/html');
  578:     $r->send_http_header;
  579:     return OK if $r->header_only;
  580:     #
  581:     my ($resdomain,$resuser)=
  582:         (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
  583:     my $html=&Apache::lonxml::xmlbegin();
  584:     $r->print($html.'<head><title>'.
  585:               'Catalog Information'.
  586:               '</title></head>');
  587:     if ($uri=~m:/adm/bombs/(.*)$:) {
  588:         $r->print(&Apache::loncommon::bodytag('Error Messages'));
  589:         # Looking for all bombs?
  590:         &report_bombs($r,$uri);
  591:     } elsif ($uri=~/\/portfolio\//) {
  592: 	($resdomain,$resuser)=
  593: 	    (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
  594:         $r->print(&Apache::loncommon::bodytag
  595:           ('Edit Portfolio File Information','','','',$resdomain));
  596:         &present_editable_metadata($r,$uri,'portfolio');
  597:         &select_course($r);
  598:     } elsif ($uri=~/^\/\~/) { 
  599:         # Construction space
  600:         $r->print(&Apache::loncommon::bodytag
  601:                   ('Edit Catalog Information','','','',$resdomain));
  602:         &present_editable_metadata($r,$uri);
  603:     } else {
  604:         $r->print(&Apache::loncommon::bodytag
  605: 		  ('Catalog Information','','','',$resdomain));
  606:         &present_uneditable_metadata($r,$uri);
  607:     }
  608:     $r->print('</body></html>');
  609:     return OK;
  610: }
  611: 
  612: #####################################################
  613: #####################################################
  614: ###                                               ###
  615: ###                Report Bombs                   ###
  616: ###                                               ###
  617: #####################################################
  618: #####################################################
  619: sub report_bombs {
  620:     my ($r,$uri) = @_;
  621:     # Set document type
  622:     $uri =~ s:/adm/bombs/::;
  623:     $uri = &Apache::lonnet::declutter($uri);
  624:     $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
  625:     my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
  626:     if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
  627: 	if ($env{'form.clearbombs'}) {
  628: 	    &Apache::lonmsg::clear_author_res_msg($uri);
  629: 	}
  630:         my $clear=&mt('Clear all Messages in Subdirectory');
  631: 	$r->print(<<ENDCLEAR);
  632: <form method="post">
  633: <input type="submit" name="clearbombs" value="$clear" />
  634: </form>
  635: ENDCLEAR
  636:         my %brokenurls = 
  637:             &Apache::lonmsg::all_url_author_res_msg($author,$domain);
  638:         foreach (sort(keys(%brokenurls))) {
  639:             if ($_=~/^\Q$uri\E/) {
  640:                 $r->print
  641:                     ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
  642:                      &Apache::lonmsg::retrieve_author_res_msg($_).
  643:                      '<hr />');
  644:             }
  645:         }
  646:     } else {
  647:         $r->print(&mt('Not authorized'));
  648:     }
  649:     return;
  650: }
  651: 
  652: #####################################################
  653: #####################################################
  654: ###                                               ###
  655: ###        Uneditable Metadata Display            ###
  656: ###                                               ###
  657: #####################################################
  658: #####################################################
  659: sub present_uneditable_metadata {
  660:     my ($r,$uri) = @_;
  661:     #
  662:     my %content=();
  663:     # Read file
  664:     foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
  665:         $content{$_}=&Apache::lonnet::metadata($uri,$_);
  666:     }
  667:     # Render Output
  668:     # displayed url
  669:     my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
  670:     $uri=~s/\.meta$//;
  671:     my $disuri=&Apache::lonnet::clutter($uri);
  672:     # version
  673:     my $currentversion=&Apache::lonnet::getversion($disuri);
  674:     my $versiondisplay='';
  675:     if ($thisversion) {
  676:         $versiondisplay=&mt('Version').': '.$thisversion.
  677:             ' ('.&mt('most recent version').': '.
  678:             ($currentversion>0 ? 
  679:              $currentversion   :
  680:              &mt('information not available')).')';
  681:     } else {
  682:         $versiondisplay='Version: '.$currentversion;
  683:     }
  684:     # crumbify displayed URL               uri     target prefix form  size
  685:     $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
  686:     $disuri =~ s:<br />::g;
  687:     # obsolete
  688:     my $obsolete=$content{'obsolete'};
  689:     my $obsoletewarning='';
  690:     if (($obsolete) && ($env{'user.adv'})) {
  691:         $obsoletewarning='<p><font color="red">'.
  692:             &mt('This resource has been marked obsolete by the author(s)').
  693:             '</font></p>';
  694:     }
  695:     #
  696:     my %lt=&fieldnames();
  697:     my $table='';
  698:     my $title = $content{'title'};
  699:     if (! defined($title)) {
  700:         $title = 'Untitled Resource';
  701:     }
  702:     foreach ('title', 
  703:              'author', 
  704:              'subject', 
  705:              'keywords', 
  706:              'notes', 
  707:              'abstract',
  708:              'lowestgradelevel',
  709:              'highestgradelevel',
  710:              'standards', 
  711:              'mime', 
  712:              'language', 
  713:              'creationdate', 
  714:              'lastrevisiondate', 
  715:              'owner', 
  716:              'copyright', 
  717:              'customdistributionfile',
  718:              'sourceavail',
  719:              'sourcerights', 
  720:              'obsolete', 
  721:              'obsoletereplacement') {
  722:         $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
  723:             '</td><td bgcolor="#CCCCCC">'.
  724:             &prettyprint($_,$content{$_}).'</td></tr>';
  725:         delete $content{$_};
  726:     }
  727:     #
  728:     $r->print(<<ENDHEAD);
  729: <h2>$title</h2>
  730: <p>
  731: $disuri<br />
  732: $obsoletewarning
  733: $versiondisplay
  734: </p>
  735: <table cellspacing="2" border="0">
  736: $table
  737: </table>
  738: ENDHEAD
  739:     if ($env{'user.adv'}) {
  740:         &print_dynamic_metadata($r,$uri,\%content);
  741:     }
  742:     return;
  743: }
  744: 
  745: sub print_dynamic_metadata {
  746:     my ($r,$uri,$content) = @_;
  747:     #
  748:     my %content = %$content;
  749:     my %lt=&fieldnames();
  750:     #
  751:     my $description = 'Dynamic Metadata (updated periodically)';
  752:     $r->print('<h3>'.&mt($description).'</h3>'.
  753:               &mt('Processing'));
  754:     $r->rflush();
  755:     my %items=&fieldnames();
  756:     my %dynmeta=&dynamicmeta($uri);
  757:     #
  758:     # General Access and Usage Statistics
  759:     if (exists($dynmeta{'count'}) ||
  760:         exists($dynmeta{'sequsage'}) ||
  761:         exists($dynmeta{'comefrom'}) ||
  762:         exists($dynmeta{'goto'}) ||
  763:         exists($dynmeta{'course'})) {
  764:         $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
  765:                   '<table cellspacing="2" border="0">');
  766:         foreach ('count',
  767:                  'sequsage','sequsage_list',
  768:                  'comefrom','comefrom_list',
  769:                  'goto','goto_list',
  770:                  'course','course_list') {
  771:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  772:                       '<td bgcolor="#CCCCCC">'.
  773:                       &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  774:         }
  775:         $r->print('</table>');
  776:     } else {
  777:         $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
  778:     }
  779:     #
  780:     # Assessment statistics
  781:     if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
  782:         if (exists($dynmeta{'stdno'}) ||
  783:             exists($dynmeta{'avetries'}) ||
  784:             exists($dynmeta{'difficulty'}) ||
  785:             exists($dynmeta{'disc'})) {
  786:             # This is an assessment, print assessment data
  787:             $r->print('<h4>'.
  788:                       &mt('Overall Assessment Statistical Data').
  789:                       '</h4>'.
  790:                       '<table cellspacing="2" border="0">');
  791:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
  792:                       '<td bgcolor="#CCCCCC">'.
  793:                       &prettyprint('stdno',$dynmeta{'stdno'}).
  794:                       '</td>'."</tr>\n");
  795:             foreach ('avetries','difficulty','disc') {
  796:                 $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  797:                           '<td bgcolor="#CCCCCC">'.
  798:                           &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
  799:                           '</td>'."</tr>\n");
  800:             }
  801:             $r->print('</table>');    
  802:         }
  803:         if (exists($dynmeta{'stats'})) {
  804:             #
  805:             # New assessment statistics
  806:             $r->print('<h4>'.
  807:                       &mt('Detailed Assessment Statistical Data').
  808:                       '</h4>');
  809:             my $table = '<table cellspacing="2" border="0">'.
  810:                 '<tr>'.
  811:                 '<th>Course</th>'.
  812:                 '<th>Section(s)</th>'.
  813:                 '<th>Num Students</th>'.
  814:                 '<th>Mean Tries</th>'.
  815:                 '<th>Degree of Difficulty</th>'.
  816:                 '<th>Degree of Discrimination</th>'.
  817:                 '<th>Time of computation</th>'.
  818:                 '</tr>'.$/;
  819:             foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
  820:                 my $data = $dynmeta{'stats'}->{$identifier};
  821:                 my $course = $data->{'course'};
  822:                 my %courseinfo = &Apache::lonnet::coursedescription($course);
  823:                 if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
  824:                     &Apache::lonnet::logthis('lookup for '.$course.' failed');
  825:                     next;
  826:                 }
  827:                 $table .= '<tr>';
  828:                 $table .= 
  829:                     '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
  830:                 $table .= 
  831:                     '<td align="right">'.$data->{'sections'}.'</td>';
  832:                 $table .=
  833:                     '<td align="right">'.$data->{'stdno'}.'</td>';
  834:                 foreach ('avetries','difficulty','disc') {
  835:                     $table .= '<td align="right">';
  836:                     if (exists($data->{$_})) {
  837:                         $table .= sprintf('%.2f',$data->{$_}).'&nbsp;';
  838:                     } else {
  839:                         $table .= '';
  840:                     }
  841:                     $table .= '</td>';
  842:                 }
  843:                 $table .=
  844:                     '<td><nobr>'.
  845:                     &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
  846:                     '</nobr></td>';
  847:                 $table .=
  848:                     '</tr>'.$/;
  849:             }
  850:             $table .= '</table>'.$/;
  851:             $r->print($table);
  852:         } else {
  853:             $r->print('No new dynamic data found.');
  854:         }
  855:     } else {
  856:         $r->print('<h4>'.
  857:           &mt('No Assessment Statistical Data is available for this resource').
  858:                   '</h4>');
  859:     }
  860: 
  861:     #
  862:     #
  863:     if (exists($dynmeta{'clear'})   || 
  864:         exists($dynmeta{'depth'})   || 
  865:         exists($dynmeta{'helpful'}) || 
  866:         exists($dynmeta{'correct'}) || 
  867:         exists($dynmeta{'technical'})){ 
  868:         $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
  869:                   '<table cellspacing="2" border="0">');
  870:         foreach ('clear','depth','helpful','correct','technical') {
  871:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
  872:                       '<td bgcolor="#CCCCCC">'.
  873:                       &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
  874:         }
  875:         $r->print('</table>');
  876:     } else {
  877:         $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
  878:     }
  879:     $uri=~/^\/res\/(\w+)\/(\w+)\//; 
  880:     if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
  881:         || ($env{'user.role.ca./'.$1.'/'.$2})) {
  882:         if (exists($dynmeta{'comments'})) {
  883:             $r->print('<h4>'.&mt('Evaluation Comments').' ('.
  884:                       &mt('visible to author and co-authors only').
  885:                       ')</h4>'.
  886:                       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
  887:         } else {
  888:             $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
  889:         }
  890:         my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
  891:         if (defined($bombs) && $bombs ne '') {
  892:             $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
  893:                       &mt('visible to author and co-authors only').')'.
  894:                       '</h4>'.$bombs);
  895:         } else {
  896:             $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
  897:         }
  898:     }
  899:     #
  900:     # All other stuff
  901:     $r->print('<h3>'.
  902:               &mt('Additional Metadata (non-standard, parameters, exports)').
  903:               '</h3><table border="0" cellspacing="1">');
  904:     foreach (sort(keys(%content))) {
  905:         my $name=$_;
  906:         if ($name!~/\.display$/) {
  907:             my $display=&Apache::lonnet::metadata($uri,
  908:                                                   $name.'.display');
  909:             if (! $display) { 
  910:                 $display=$name;
  911:             };
  912:             my $otherinfo='';
  913:             foreach ('name','part','type','default') {
  914:                 if (defined(&Apache::lonnet::metadata($uri,
  915:                                                       $name.'.'.$_))) {
  916:                     $otherinfo.=' '.$_.'='.
  917:                         &Apache::lonnet::metadata($uri,
  918:                                                   $name.'.'.$_).'; ';
  919:                 }
  920:             }
  921:             $r->print('<tr><td bgcolor="#bbccbb"><font size="-1" color="#556655">'.$display.'</font></td><td bgcolor="#ccddcc"><font size="-1" color="#556655">'.$content{$name});
  922:             if ($otherinfo) {
  923:                 $r->print(' ('.$otherinfo.')');
  924:             }
  925:             $r->print("</font></td></tr>\n");
  926:         }
  927:     }
  928:     $r->print("</table>");
  929:     return;
  930: }
  931: 
  932: 
  933: 
  934: #####################################################
  935: #####################################################
  936: ###                                               ###
  937: ###          Editable metadata display            ###
  938: ###                                               ###
  939: #####################################################
  940: #####################################################
  941: sub present_editable_metadata {
  942:     my ($r,$uri, $file_type) = @_;
  943:     # Construction Space Call
  944:     # Header
  945:     my $disuri=$uri;
  946:     my $fn=&Apache::lonnet::filelocation('',$uri);
  947:     $disuri=~s/^\/\~/\/priv\//;
  948:     $disuri=~s/\.meta$//;
  949:     $disuri=~s|^/editupload||;
  950:     my $target=$uri;
  951:     $target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;
  952:     $target=~s/\.meta$//;
  953:     my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
  954:     if ($bombs) {
  955:         my $showdel=1;
  956:         if ($env{'form.delmsg'}) {
  957:             if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
  958:                 $bombs=&mt('Messages deleted.');
  959: 		$showdel=0;
  960:             } else {
  961:                 $bombs=&mt('Error deleting messages');
  962:             }
  963:         }
  964:         if ($env{'form.clearmsg'}) {
  965: 	    my $cleardir=$target;
  966: 	    $cleardir=~s/\/[^\/]+$/\//;
  967:             if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
  968:                 $bombs=&mt('Messages cleared.');
  969: 		$showdel=0;
  970:             } else {
  971:                 $bombs=&mt('Error clearing messages');
  972:             }
  973:         }
  974:         my $del=&mt('Delete Messages for this Resource');
  975: 	my $clear=&mt('Clear all Messages in Subdirectory');
  976: 	my $goback=&mt('Back to Source File');
  977:         $r->print(<<ENDBOMBS);
  978: <h1>$disuri</h1>
  979: <form method="post" name="defaultmeta">
  980: ENDBOMBS
  981:         if ($showdel) {
  982: 	    $r->print(<<ENDDEL);
  983: <input type="submit" name="delmsg" value="$del" />
  984: <input type="submit" name="clearmsg" value="$clear" />
  985: ENDDEL
  986:         } else {
  987:             $r->print('<a href="'.$disuri.'" />'.$goback.'</a>');
  988: 	}
  989: 	$r->print('<br />'.$bombs);
  990:     } else {
  991:         my $displayfile='Catalog Information for '.$disuri;
  992:         if ($disuri=~/\/default$/) {
  993:             my $dir=$disuri;
  994:             $dir=~s/default$//;
  995:             $displayfile=
  996:                 &mt('Default Cataloging Information for Directory').' '.
  997:                 $dir;
  998:         }
  999:         %Apache::lonpublisher::metadatafields=();
 1000:         %Apache::lonpublisher::metadatakeys=();
 1001:         my $result=&Apache::lonnet::getfile($fn);
 1002:         if ($result == -1){
 1003:             $r->print('Creating new '.$disuri);
 1004:         } else {
 1005:             &Apache::lonpublisher::metaeval($result);
 1006:         }
 1007:         $r->print(<<ENDEDIT);
 1008: <h1>$displayfile</h1>
 1009: <form method="post" name="defaultmeta">
 1010: ENDEDIT
 1011:         $r->print('<script language="JavaScript">'.
 1012:                   &Apache::loncommon::browser_and_searcher_javascript().
 1013:                   '</script>');
 1014:         my %lt=&fieldnames($file_type);
 1015: 	my $output;
 1016: 	my @fields;
 1017: 	if ($file_type eq 'portfolio') {
 1018: 	    @fields =  ('author','metadata.title','metadata.subject','metadata.keywords','abstract','notes','lowestgradelevel',
 1019: 	                'highestgradelevel');
 1020: 	} else {
 1021: 	    @fields = ('author','title','subject','keywords','abstract','notes',
 1022:                  'copyright','customdistributionfile','language',
 1023:                  'standards',
 1024:                  'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
 1025:                  'obsolete','obsoletereplacement');
 1026:         }
 1027:         foreach (@fields) {
 1028:             if (defined($env{'form.new_'.$_})) {
 1029:                 $Apache::lonpublisher::metadatafields{$_}=
 1030:                     $env{'form.new_'.$_};
 1031:             }
 1032:             if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
 1033:                 $Apache::lonpublisher::metadatafields{'copyright'}=
 1034:                     'default';
 1035:             }
 1036:             $output.=('<p>'.$lt{$_}.': '.
 1037:                       &prettyinput($_,
 1038: 				   $Apache::lonpublisher::metadatafields{$_},
 1039: 				   'new_'.$_,'defaultmeta').'</p>');
 1040:             if ($env{'form.metacourse'}) {
 1041:                 $r->print('This is the instructor metadata area<br />');
 1042:                 # have to find all the metadata items, so we'll loop through and find them
 1043:                 $r->print('<form method="post" action="" size="3" >');
 1044:                 $r->print('The course is: '.$env{'form.metacourse'}.'<br>');
 1045:                 foreach my $key (sort keys %env) {
 1046:                     if ($key=~m/^($env{'form.metacourse'}\.metadata\.)(\d+)\.title/) {
 1047:                         my $key_base = $1;
 1048:                         my $item_num = $2;
 1049:                         # found one, so let's display it
 1050:                         my $title = $env{$key_base.$item_num.'.title'};
 1051:                         my $type = $env{$key_base.$item_num.'.type'};
 1052:                         my @choices = sort(split /, /,$env{$key_base.$item_num.'.values'});
 1053:                         $r->print($title.'<br />');
 1054:                         $r->print($type.'<br />');
 1055:             
 1056:             foreach my $word (@choices) {
 1057:                 my $checked;
 1058:                 if ($Apache::lonpublisher::metadatafields{'coursekeyword'}=~ m/$word/) {
 1059:                     $checked = 1;
 1060:                 } else {
 1061:                     undef($checked);
 1062:                 }
 1063:                 $r->print(&Apache::lonhtmlcommon::checkbox('instmeta_'.$env{'form.metacourse'}.'_'.$item_num,$checked,$word).$word.'<br />');
 1064:             }
 1065:         }
 1066:     }   
 1067:     $r->print('<br /><input type="submit" name="store" value="Assign Meta-data" />');
 1068:     $r->print('</form>');
 1069:     return 'ok';
 1070:             }
 1071:         }
 1072:         if ($env{'form.store'}) {
 1073:             my $mfh;
 1074:             my $formname='store'; 
 1075:             my $file_content;
 1076:             foreach my $meta_field (keys %env) {
 1077:                 if ($meta_field=~m/^form.instmeta_(.+)_(\d+)$/) {
 1078:                     $r->print('Found a field<br>');
 1079:                 }
 1080:                 if (&Apache::loncommon::get_env_multiple('form.keywords')) {
 1081:                 $Apache::lonpublisher::metadatafields{'coursekeyword'} = 
 1082:                         join (', ', &Apache::loncommon::get_env_multiple('form.keywords'));
 1083:                 }
 1084:             }
 1085:             foreach (sort keys %Apache::lonpublisher::metadatafields) {
 1086:                 next if ($_ =~ /\./);
 1087:                 my $unikey=$_;
 1088:                 $unikey=~/^([A-Za-z]+)/;
 1089:                 my $tag=$1;
 1090:                 $tag=~tr/A-Z/a-z/;
 1091:                 $file_content.= "\n\<$tag";
 1092:                 foreach (split(/\,/,
 1093:                              $Apache::lonpublisher::metadatakeys{$unikey})
 1094:                          ) {
 1095:                     my $value=
 1096:                      $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
 1097:                     $value=~s/\"/\'\'/g;
 1098:                     $file_content.=' '.$_.'="'.$value.'"' ;
 1099:                     # print $mfh ' '.$_.'="'.$value.'"';
 1100:                 }
 1101:                 $file_content.= '>'.
 1102:                     &HTML::Entities::encode
 1103:                     ($Apache::lonpublisher::metadatafields{$unikey},
 1104:                      '<>&"').
 1105:                      '</'.$tag.'>';
 1106:             }
 1107:             if ($fn =~ /\/portfolio\//) {
 1108:                 $fn =~ /\/portfolio\/(.*)$/;
 1109:                 my $new_fn = '/'.$1;
 1110:                 $env{'form.'.$formname}=$file_content;
 1111:                 $env{'form.'.$formname.'.filename'}=$new_fn;
 1112:                 &Apache::lonnet::userfileupload('uploaddoc','',
 1113: 	        	 'portfolio'.$env{'form.currentpath'});
 1114: 	        my $status =&Apache::lonnet::userfileupload($formname,'','portfolio');
 1115:                 if (&Apache::lonnet::userfileupload($formname,'','portfolio') eq 'error: no uploaded file') {
 1116:                     $r->print('<p><font color="red">'.
 1117:                       &mt('Could not write metadata').', '.
 1118:                      &mt('FAIL').'</font></p>');
 1119:                 } else {
 1120:                     $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
 1121: 		  ' '.&Apache::lonlocal::locallocaltime(time).
 1122: 		  '</font></p>');
 1123:                 }
 1124:             } else {
 1125:                 if (!  ($mfh=Apache::File->new('>'.$fn))) {
 1126:                     $r->print('<p><font color="red">'.
 1127:                         &mt('Could not write metadata').', '.
 1128:                         &mt('FAIL').'</font></p>');
 1129:                 } else {
 1130:                     print $mfh $file_content;
 1131: 		    $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
 1132: 			      ' '.&Apache::lonlocal::locallocaltime(time).
 1133: 			      '</font></p>');
 1134:                 }
 1135:             }
 1136:         }
 1137: 	$r->print($output.'<br /><input type="submit" name="store" value="'.
 1138:                   &mt('Store Catalog Information').'">');
 1139:     }
 1140:     $r->print('</form>');
 1141:     return;
 1142: }
 1143: 
 1144: 1;
 1145: __END__
 1146: 
 1147:      

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