Annotation of loncom/interface/lonmeta.pm, revision 1.130

1.1       www         1: # The LearningOnline Network with CAPA
1.8       albertel    2: # Metadata display handler
                      3: #
1.130   ! banghart    4: # $Id: lonmeta.pm,v 1.129 2005/11/19 00:00:38 banghart Exp $
1.8       albertel    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.
1.1       www        14: #
1.8       albertel   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: #
1.100     banghart   20: # You should have received a copy of the GNU General Public License 
1.8       albertel   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/
1.44      www        27: 
1.1       www        28: 
                     29: package Apache::lonmeta;
                     30: 
                     31: use strict;
1.63      matthew    32: use LONCAPA::lonmetadata();
1.1       www        33: use Apache::Constants qw(:common);
1.96      albertel   34: use Apache::lonnet;
1.10      www        35: use Apache::loncommon();
1.100     banghart   36: use Apache::lonhtmlcommon(); 
1.23      www        37: use Apache::lonmsg;
                     38: use Apache::lonpublisher;
1.35      www        39: use Apache::lonlocal;
1.43      www        40: use Apache::lonmysql;
1.49      www        41: use Apache::lonmsg;
1.1       www        42: 
1.44      www        43: 
1.80      matthew    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:     }
1.83      www        74:     my @Fields = ('url','count','course',
1.80      matthew    75:                   'goto','goto_list',
                     76:                   'comefrom','comefrom_list',
                     77:                   'sequsage','sequsage_list',
                     78:                   'stdno','stdno_list',
1.83      www        79: 		  'dependencies',
1.80      matthew    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: 
1.64      matthew   125: # Fetch and evaluate dynamic metadata
1.9       www       126: sub dynamicmeta {
                    127:     my $url=&Apache::lonnet::declutter(shift);
                    128:     $url=~s/\.meta$//;
                    129:     my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
1.19      www       130:     my $regexp=$url;
1.9       www       131:     $regexp=~s/(\W)/\\$1/g;
1.10      www       132:     $regexp='___'.$regexp.'___';
1.16      albertel  133:     my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
                    134: 				       $aauthor,$regexp);
1.63      matthew   135:     my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
                    136:     my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
                    137:                                                                \%DynamicData);
1.40      matthew   138:     #
1.46      www       139:     # Deal with 'count' separately
1.63      matthew   140:     $Data{'count'} = &access_count($url,$aauthor,$adomain);
1.67      matthew   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:     }
1.63      matthew   150:     return %Data;
1.40      matthew   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})) {
1.47      www       158:         return &mt('Not Available');
1.40      matthew   159:     } else {
                    160:         return $countdata{$src};
                    161:     }
1.25      www       162: }
                    163: 
1.64      matthew   164: # Try to make an alt tag if there is none
1.25      www       165: sub alttag {
1.26      www       166:     my ($base,$src)=@_;
                    167:     my $fullpath=&Apache::lonnet::hreflocation($base,$src);
                    168:     my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
1.64      matthew   169:         &Apache::lonnet::metadata($fullpath,'subject').' '.
                    170:         &Apache::lonnet::metadata($fullpath,'abstract');
1.26      www       171:     $alttag=~s/\s+/ /gs;
                    172:     $alttag=~s/\"//gs;
                    173:     $alttag=~s/\'//gs;
                    174:     $alttag=~s/\s+$//gs;
                    175:     $alttag=~s/^\s+//gs;
1.64      matthew   176:     if ($alttag) { 
                    177:         return $alttag; 
                    178:     } else { 
                    179:         return &mt('No information available'); 
                    180:     }
1.9       www       181: }
1.1       www       182: 
1.64      matthew   183: # Author display
1.29      www       184: sub authordisplay {
                    185:     my ($aname,$adom)=@_;
1.64      matthew   186:     return &Apache::loncommon::aboutmewrapper
                    187:         (&Apache::loncommon::plainname($aname,$adom),
                    188:          $aname,$adom,'preview').' <tt>['.$aname.'@'.$adom.']</tt>';
1.29      www       189: }
                    190: 
1.64      matthew   191: # Pretty display
1.12      www       192: sub evalgraph {
                    193:     my $value=shift;
1.65      matthew   194:     if (! $value) { 
                    195:         return '';
                    196:     }
1.12      www       197:     my $val=int($value*10.+0.5)-10;
1.71      matthew   198:     my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
1.12      www       199:     if ($val>=20) {
1.71      matthew   200: 	$output.='<td width="20" bgcolor="#555555">&nbsp&nbsp;</td>';
1.12      www       201:     } else {
1.71      matthew   202:         $output.='<td width="'.($val).'" bgcolor="#555555">&nbsp;</td>'.
                    203:                  '<td width="'.(20-$val).'" bgcolor="#FF3333">&nbsp;</td>';
1.12      www       204:     }
                    205:     $output.='<td bgcolor="#FFFF33">&nbsp;</td>';
                    206:     if ($val>20) {
1.71      matthew   207: 	$output.='<td width="'.($val-20).'" bgcolor="#33FF33">&nbsp;</td>'.
                    208:                  '<td width="'.(40-$val).'" bgcolor="#555555">&nbsp;</td>';
1.12      www       209:     } else {
1.71      matthew   210:         $output.='<td width="20" bgcolor="#555555">&nbsp&nbsp;</td>';
1.12      www       211:     }
1.71      matthew   212:     $output.='<td> ('.sprintf("%5.2f",$value).') </td></tr></table>';
1.12      www       213:     return $output;
                    214: }
                    215: 
                    216: sub diffgraph {
                    217:     my $value=shift;
1.65      matthew   218:     if (! $value) { 
                    219:         return '';
                    220:     }
1.12      www       221:     my $val=int(40.0*$value+0.5);
1.13      www       222:     my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
                    223:                 '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
1.71      matthew   224:     my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
1.12      www       225:     for (my $i=0;$i<8;$i++) {
                    226: 	if ($val>$i*5) {
1.71      matthew   227:             $output.='<td width="5" bgcolor="'.$colors[$i].'">&nbsp;</td>';
1.12      www       228:         } else {
1.71      matthew   229: 	    $output.='<td width="5" bgcolor="#555555">&nbsp;</td>';
1.12      www       230: 	}
                    231:     }
1.71      matthew   232:     $output.='<td> ('.sprintf("%3.2f",$value).') </td></tr></table>';
1.12      www       233:     return $output;
                    234: }
                    235: 
1.44      www       236: 
1.64      matthew   237: # The field names
1.45      www       238: sub fieldnames {
1.90      banghart  239:     my $file_type=shift;
1.115     banghart  240:     my %fields = 
                    241:         ('title' => 'Title',
1.113     banghart  242:          'author' =>'Author(s)',
                    243:          'subject' => 'Subject',
                    244:          'keywords' => 'Keyword(s)',
                    245:          'notes' => 'Notes',
                    246:          'abstract' => 'Abstract',
                    247:          'lowestgradelevel' => 'Lowest Grade Level',
1.120     banghart  248:          'highestgradelevel' => 'Highest Grade Level',
                    249:          'courserestricted' => 'Course Restricting Metadata');
                    250:          
1.93      matthew   251:     if (! defined($file_type) || $file_type ne 'portfolio') {
                    252:         %fields = 
                    253:         (%fields,
                    254:          'domain' => 'Domain',
1.64      matthew   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',
1.84      banghart  263:          'sourceavail' => 'Source Available',
1.78      taceyjo1  264:          'sourcerights' => 'Source Custom Distribution File',
1.64      matthew   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',
1.73      matthew   283:          'difficulty' => 'Degree of difficulty',
                    284:          'disc'       => 'Degree of discrimination',
1.83      www       285: 	 'dependencies' => 'Resources used by this resource',
1.64      matthew   286:          );
1.93      matthew   287:     }
                    288:     return &Apache::lonlocal::texthash(%fields);
1.45      www       289: }
1.46      www       290: 
1.100     banghart  291: sub select_course {
                    292:     my ($r)=@_;
1.113     banghart  293:     my %courses;
1.111     banghart  294:     foreach my $key (keys (%env)) { 
1.113     banghart  295:         if ($key =~ m/\.metadata\./) {
                    296:             $key =~ m/^course\.(.+)(\.metadata.+$)/;
                    297:             my $course = $1;
                    298:             my $coursekey = 'course.'.$course.'.description';
                    299:             my $value = $env{$coursekey};
                    300:             $courses{$coursekey} = $value;
1.111     banghart  301:         }
                    302:     }
1.113     banghart  303:     $r->print('<h3>Course Related Meta-Data</h3><br />');
1.100     banghart  304:     $r->print('<form action="" method="post">');
1.125     banghart  305:     $r->print('Select course restrictions<br />');
1.100     banghart  306:     $r->print('<select name="metacourse" >');
1.103     banghart  307:     my $meta_not_found = 1;
1.113     banghart  308:     foreach my $key (keys (%courses)) {    
                    309:         if ($meta_not_found) {
                    310:             undef($meta_not_found);
                    311:             $r->print('<h3>Portfolio Meta-Data</h3><br />');
                    312:             $r->print('<form action="" method="post">');
                    313:             $r->print('Select your course<br />');
                    314:             $r->print('<select name="metacourse" >');
                    315:         }
1.120     banghart  316:         $key =~ m/(^.+)\.description$/;
                    317:         $r->print('<option value="'.$1.'">');
1.113     banghart  318:         $r->print($courses{$key});
                    319:         $r->print('</option>');
1.100     banghart  320:     }
1.103     banghart  321:     unless ($meta_not_found) {
                    322:         $r->print('</select><br />');
1.111     banghart  323:         $r->print('<input type="submit" value="Assign Portfolio Metadata" />');
1.103     banghart  324:         $r->print('</form>');
                    325:     }
1.100     banghart  326:     return 'ok';
                    327: }
1.64      matthew   328: # Pretty printing of metadata field
1.46      www       329: 
                    330: sub prettyprint {
1.82      www       331:     my ($type,$value,$target,$prefix,$form,$noformat)=@_;
                    332: # $target,$prefix,$form are optional and for filecrumbs only
1.65      matthew   333:     if (! defined($value)) { 
                    334:         return '&nbsp;'; 
                    335:     }
1.64      matthew   336:     # Title
1.46      www       337:     if ($type eq 'title') {
                    338: 	return '<font size="+1" face="arial">'.$value.'</font>';
                    339:     }
1.64      matthew   340:     # Dates
1.46      www       341:     if (($type eq 'creationdate') ||
                    342: 	($type eq 'lastrevisiondate')) {
1.55      www       343: 	return ($value?&Apache::lonlocal::locallocaltime(
                    344: 			  &Apache::lonmysql::unsqltime($value)):
                    345: 		&mt('not available'));
1.46      www       346:     }
1.64      matthew   347:     # Language
1.46      www       348:     if ($type eq 'language') {
                    349: 	return &Apache::loncommon::languagedescription($value);
                    350:     }
1.64      matthew   351:     # Copyright
1.46      www       352:     if ($type eq 'copyright') {
                    353: 	return &Apache::loncommon::copyrightdescription($value);
                    354:     }
1.78      taceyjo1  355:     # Copyright
                    356:     if ($type eq 'sourceavail') {
                    357: 	return &Apache::loncommon::source_copyrightdescription($value);
                    358:     }
1.64      matthew   359:     # MIME
1.46      www       360:     if ($type eq 'mime') {
1.64      matthew   361:         return '<img src="'.&Apache::loncommon::icon($value).'" />&nbsp;'.
                    362:             &Apache::loncommon::filedescription($value);
                    363:     }
                    364:     # Person
1.46      www       365:     if (($type eq 'author') || 
                    366: 	($type eq 'owner') ||
                    367: 	($type eq 'modifyinguser') ||
                    368: 	($type eq 'authorspace')) {
                    369: 	$value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
                    370: 	return $value;
                    371:     }
1.64      matthew   372:     # Gradelevel
1.48      www       373:     if (($type eq 'lowestgradelevel') ||
                    374: 	($type eq 'highestgradelevel')) {
                    375: 	return &Apache::loncommon::gradeleveldescription($value);
                    376:     }
1.64      matthew   377:     # Only for advance users below
1.96      albertel  378:     if (! $env{'user.adv'}) { 
1.65      matthew   379:         return '<i>- '.&mt('not displayed').' -</i>';
                    380:     }
1.64      matthew   381:     # File
1.46      www       382:     if (($type eq 'customdistributionfile') ||
                    383: 	($type eq 'obsoletereplacement') ||
                    384: 	($type eq 'goto_list') ||
                    385: 	($type eq 'comefrom_list') ||
1.82      www       386: 	($type eq 'sequsage_list') ||
1.83      www       387: 	($type eq 'dependencies')) {
1.82      www       388: 	return '<ul><font size="-1">'.join("\n",map {
1.70      matthew   389:             my $url = &Apache::lonnet::clutter($_);
1.72      matthew   390:             my $title = &Apache::lonnet::gettitle($url);
                    391:             if ($title eq '') {
                    392:                 $title = 'Untitled';
                    393:                 if ($url =~ /\.sequence$/) {
                    394:                     $title .= ' Sequence';
                    395:                 } elsif ($url =~ /\.page$/) {
                    396:                     $title .= ' Page';
                    397:                 } elsif ($url =~ /\.problem$/) {
                    398:                     $title .= ' Problem';
                    399:                 } elsif ($url =~ /\.html$/) {
                    400:                     $title .= ' HTML document';
                    401:                 } elsif ($url =~ m:/syllabus$:) {
                    402:                     $title .= ' Syllabus';
                    403:                 } 
                    404:             }
1.82      www       405:             $_ = '<li>'.$title.' '.
                    406: 		&Apache::lonhtmlcommon::crumbs($url,$target,$prefix,$form,'-1',$noformat).
                    407:                 '</li>'
                    408: 	    } split(/\s*\,\s*/,$value)).'</ul></font>';
1.46      www       409:     }
1.64      matthew   410:     # Evaluations
1.46      www       411:     if (($type eq 'clear') ||
                    412: 	($type eq 'depth') ||
                    413: 	($type eq 'helpful') ||
                    414: 	($type eq 'correct') ||
                    415: 	($type eq 'technical')) {
                    416: 	return &evalgraph($value);
                    417:     }
1.64      matthew   418:     # Difficulty
1.73      matthew   419:     if ($type eq 'difficulty' || $type eq 'disc') {
1.46      www       420: 	return &diffgraph($value);
                    421:     }
1.64      matthew   422:     # List of courses
1.46      www       423:     if ($type=~/\_list/) {
1.72      matthew   424:         my @Courses = split(/\s*\,\s*/,$value);
                    425:         my $Str;
                    426:         foreach my $course (@Courses) {
                    427:             my %courseinfo = &Apache::lonnet::coursedescription($course);
                    428:             if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
                    429:                 next;
                    430:             }
                    431:             if ($Str ne '') { $Str .= '<br />'; }
                    432:             $Str .= '<a href="/public/'.$courseinfo{'domain'}.'/'.
                    433:                 $courseinfo{'num'}.'/syllabus" target="preview">'.
                    434:                 $courseinfo{'description'}.'</a>';
                    435:         }
                    436: 	return $Str;
1.46      www       437:     }
1.64      matthew   438:     # No pretty print found
1.46      www       439:     return $value;
                    440: }
                    441: 
1.64      matthew   442: # Pretty input of metadata field
1.54      www       443: sub direct {
                    444:     return shift;
                    445: }
                    446: 
1.48      www       447: sub selectbox {
                    448:     my ($name,$value,$functionref,@idlist)=@_;
1.65      matthew   449:     if (! defined($functionref)) {
                    450:         $functionref=\&direct;
                    451:     }
1.48      www       452:     my $selout='<select name="'.$name.'">';
                    453:     foreach (@idlist) {
                    454:         $selout.='<option value=\''.$_.'\'';
                    455:         if ($_ eq $value) {
                    456: 	    $selout.=' selected>'.&{$functionref}($_).'</option>';
                    457: 	}
                    458:         else {$selout.='>'.&{$functionref}($_).'</option>';}
                    459:     }
                    460:     return $selout.'</select>';
                    461: }
                    462: 
1.54      www       463: sub relatedfield {
                    464:     my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
1.65      matthew   465:     if (! $relatedsearchflag) { 
                    466:         return '';
                    467:     }
                    468:     if (! defined($relatedsep)) {
                    469:         $relatedsep=' ';
                    470:     }
                    471:     if (! $show) {
                    472:         return $relatedsep.'&nbsp;';
                    473:     }
1.54      www       474:     return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
                    475: 	($relatedvalue?' checked="1"':'').' />';
                    476: }
1.48      www       477: 
1.46      www       478: sub prettyinput {
1.54      www       479:     my ($type,$value,$fieldname,$formname,
1.116     banghart  480: 	$relatedsearchflag,$relatedsep,$relatedvalue,$size,$course_key)=@_;
1.75      matthew   481:     if (! defined($size)) {
                    482:         $size = 80;
                    483:     }
1.128     banghart  484:     my $output;
1.116     banghart  485:     if (defined($course_key)) {
                    486:         my $stu_add;
                    487:         my $only_one;
1.128     banghart  488:         my %meta_options;
                    489:         my @cur_values_inst;
                    490:         my $cur_values_stu;
1.119     banghart  491:         my $values = $env{$course_key.'.metadata.'.$_.'.values'};
1.116     banghart  492:         if ($env{$course_key.'.metadata.'.$_.'.options'} =~ m/stuadd/) {
                    493:             $stu_add = 'true';
                    494:         }
                    495:         if ($env{$course_key.'.metadata.'.$_.'.options'} =~ m/onlyone/) {
                    496:             $only_one = 'true';
                    497:         }
1.128     banghart  498:         # need to take instructor values out of list where instructor and student
                    499:         # values may be mixed.
                    500:         if ($values && $stu_add) {
                    501:             foreach (split(/,/,$values)) {
                    502:                 $_ =~ s/^\s+//;
                    503:                 $meta_options{$_} = $_;
                    504:             }
                    505:             foreach (split(/,/,$value)) {
                    506:                 $_ =~ s/^\s+//;
                    507:                 if ($meta_options{$_}) {
                    508:                     push(@cur_values_inst,$_);
                    509:                 } else {
                    510:                     $cur_values_stu .= $_.',';
                    511:                 }
                    512:             }
1.129     banghart  513:         } else {
                    514:             $cur_values_stu = $value;
1.128     banghart  515:         }
1.121     banghart  516:         if ($type eq 'courserestricted') {
                    517:             return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
                    518:         }
1.130   ! banghart  519:         if (($type eq 'keywords') || ($type eq 'subject')
        !           520:              || ($type eq 'author')||($type eq  'notes')
        !           521:              || ($type eq  'abstract')|| ($type eq  'title')) {
1.129     banghart  522:             if ($values) {
                    523:                 if ($only_one) {
1.130   ! banghart  524:                     $output .= (&Apache::loncommon::select_form($value,'new_'.$type,%meta_options));
1.129     banghart  525:                 } else {
1.130   ! banghart  526:                     $output .= (&Apache::loncommon::multiple_select_form('new_'.$type,\@cur_values_inst,undef,\%meta_options));
1.129     banghart  527:                 }
1.128     banghart  528:             }
                    529:             if ($stu_add) {
                    530:                 $output .= '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
                    531:                 'value="'.$cur_values_stu.'" />'.
                    532:                 &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
                    533:                       $relatedvalue); 
1.119     banghart  534:             }
1.128     banghart  535:             return ($output);
1.116     banghart  536:         }
                    537:         if (($type eq 'lowestgradelevel') ||
                    538: 	    ($type eq 'highestgradelevel')) {
                    539: 	    return &Apache::loncommon::select_level_form($value,$fieldname).
                    540:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
                    541:         }
                    542:         return(); 
                    543:     }
1.64      matthew   544:     # Language
1.48      www       545:     if ($type eq 'language') {
                    546: 	return &selectbox($fieldname,
                    547: 			  $value,
                    548: 			  \&Apache::loncommon::languagedescription,
1.54      www       549: 			  (&Apache::loncommon::languageids)).
1.64      matthew   550:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48      www       551:     }
1.64      matthew   552:     # Copyright
1.48      www       553:     if ($type eq 'copyright') {
                    554: 	return &selectbox($fieldname,
                    555: 			  $value,
                    556: 			  \&Apache::loncommon::copyrightdescription,
1.54      www       557: 			  (&Apache::loncommon::copyrightids)).
1.64      matthew   558:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48      www       559:     }
1.78      taceyjo1  560:     # Source Copyright
                    561:     if ($type eq 'sourceavail') {
                    562: 	return &selectbox($fieldname,
                    563: 			  $value,
                    564: 			  \&Apache::loncommon::source_copyrightdescription,
                    565: 			  (&Apache::loncommon::source_copyrightids)).
                    566:                               &relatedfield(0,$relatedsearchflag,$relatedsep);
                    567:     }
1.64      matthew   568:     # Gradelevels
1.48      www       569:     if (($type eq 'lowestgradelevel') ||
                    570: 	($type eq 'highestgradelevel')) {
1.54      www       571: 	return &Apache::loncommon::select_level_form($value,$fieldname).
1.64      matthew   572:             &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48      www       573:     }
1.64      matthew   574:     # Obsolete
1.48      www       575:     if ($type eq 'obsolete') {
                    576: 	return '<input type="checkbox" name="'.$fieldname.'"'.
1.54      www       577: 	    ($value?' checked="1"':'').' />'.
1.64      matthew   578:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
1.48      www       579:     }
1.64      matthew   580:     # Obsolete replacement file
1.48      www       581:     if ($type eq 'obsoletereplacement') {
                    582: 	return '<input type="text" name="'.$fieldname.
                    583: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
                    584: 	    "('".$formname."','".$fieldname."'".
1.54      www       585: 	    ",'')\">".&mt('Select').'</a>'.
1.64      matthew   586:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
                    587:     }
                    588:     # Customdistribution file
1.48      www       589:     if ($type eq 'customdistributionfile') {
                    590: 	return '<input type="text" name="'.$fieldname.
                    591: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
                    592: 	    "('".$formname."','".$fieldname."'".
1.54      www       593: 	    ",'rights')\">".&mt('Select').'</a>'.
1.64      matthew   594:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
1.48      www       595:     }
1.78      taceyjo1  596:     # Source Customdistribution file
                    597:     if ($type eq 'sourcerights') {
                    598: 	return '<input type="text" name="'.$fieldname.
                    599: 	    '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
                    600: 	    "('".$formname."','".$fieldname."'".
                    601: 	    ",'rights')\">".&mt('Select').'</a>'.
                    602:             &relatedfield(0,$relatedsearchflag,$relatedsep); 
                    603:     }
1.64      matthew   604:     # Dates
1.48      www       605:     if (($type eq 'creationdate') ||
                    606: 	($type eq 'lastrevisiondate')) {
1.64      matthew   607: 	return 
                    608:             &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
                    609:             &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48      www       610:     }
1.64      matthew   611:     # No pretty input found
1.48      www       612:     $value=~s/^\s+//gs;
                    613:     $value=~s/\s+$//gs;
                    614:     $value=~s/\s+/ /gs;
1.77      matthew   615:     $value=~s/\"/\&quot\;/gs;
1.54      www       616:     return 
1.74      matthew   617:         '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
1.64      matthew   618:         'value="'.$value.'" />'.
                    619:         &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
                    620:                       $relatedvalue); 
1.46      www       621: }
                    622: 
1.64      matthew   623: # Main Handler
1.1       www       624: sub handler {
1.64      matthew   625:     my $r=shift;
                    626:     #
1.67      matthew   627:     my $uri=$r->uri;
                    628:     #
                    629:     # Set document type
                    630:     &Apache::loncommon::content_type($r,'text/html');
                    631:     $r->send_http_header;
                    632:     return OK if $r->header_only;
1.64      matthew   633:     #
1.76      matthew   634:     my ($resdomain,$resuser)=
                    635:         (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
1.92      albertel  636:     my $html=&Apache::lonxml::xmlbegin();
                    637:     $r->print($html.'<head><title>'.
1.67      matthew   638:               'Catalog Information'.
                    639:               '</title></head>');
1.66      matthew   640:     if ($uri=~m:/adm/bombs/(.*)$:) {
1.67      matthew   641:         $r->print(&Apache::loncommon::bodytag('Error Messages'));
1.66      matthew   642:         # Looking for all bombs?
                    643:         &report_bombs($r,$uri);
1.89      banghart  644:     } elsif ($uri=~/\/portfolio\//) {
1.109     albertel  645: 	($resdomain,$resuser)=
                    646: 	    (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
1.89      banghart  647:         $r->print(&Apache::loncommon::bodytag
                    648:           ('Edit Portfolio File Information','','','',$resdomain));
1.106     banghart  649:         &present_editable_metadata($r,$uri,'portfolio');
                    650:         &select_course($r);
1.66      matthew   651:     } elsif ($uri=~/^\/\~/) { 
                    652:         # Construction space
1.67      matthew   653:         $r->print(&Apache::loncommon::bodytag
                    654:                   ('Edit Catalog Information','','','',$resdomain));
1.66      matthew   655:         &present_editable_metadata($r,$uri);
                    656:     } else {
1.67      matthew   657:         $r->print(&Apache::loncommon::bodytag
1.85      albertel  658: 		  ('Catalog Information','','','',$resdomain));
1.66      matthew   659:         &present_uneditable_metadata($r,$uri);
                    660:     }
1.67      matthew   661:     $r->print('</body></html>');
1.66      matthew   662:     return OK;
                    663: }
                    664: 
1.67      matthew   665: #####################################################
                    666: #####################################################
                    667: ###                                               ###
                    668: ###                Report Bombs                   ###
                    669: ###                                               ###
                    670: #####################################################
                    671: #####################################################
1.66      matthew   672: sub report_bombs {
                    673:     my ($r,$uri) = @_;
                    674:     # Set document type
1.67      matthew   675:     $uri =~ s:/adm/bombs/::;
                    676:     $uri = &Apache::lonnet::declutter($uri);
1.66      matthew   677:     $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
                    678:     my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
                    679:     if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
1.98      www       680: 	if ($env{'form.clearbombs'}) {
                    681: 	    &Apache::lonmsg::clear_author_res_msg($uri);
                    682: 	}
                    683:         my $clear=&mt('Clear all Messages in Subdirectory');
                    684: 	$r->print(<<ENDCLEAR);
                    685: <form method="post">
                    686: <input type="submit" name="clearbombs" value="$clear" />
                    687: </form>
                    688: ENDCLEAR
1.67      matthew   689:         my %brokenurls = 
                    690:             &Apache::lonmsg::all_url_author_res_msg($author,$domain);
                    691:         foreach (sort(keys(%brokenurls))) {
1.66      matthew   692:             if ($_=~/^\Q$uri\E/) {
1.70      matthew   693:                 $r->print
                    694:                     ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
                    695:                      &Apache::lonmsg::retrieve_author_res_msg($_).
                    696:                      '<hr />');
1.64      matthew   697:             }
                    698:         }
1.66      matthew   699:     } else {
                    700:         $r->print(&mt('Not authorized'));
                    701:     }
                    702:     return;
                    703: }
                    704: 
1.67      matthew   705: #####################################################
                    706: #####################################################
                    707: ###                                               ###
                    708: ###        Uneditable Metadata Display            ###
                    709: ###                                               ###
                    710: #####################################################
                    711: #####################################################
1.66      matthew   712: sub present_uneditable_metadata {
                    713:     my ($r,$uri) = @_;
                    714:     #
                    715:     my %content=();
                    716:     # Read file
                    717:     foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
                    718:         $content{$_}=&Apache::lonnet::metadata($uri,$_);
                    719:     }
                    720:     # Render Output
                    721:     # displayed url
                    722:     my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
                    723:     $uri=~s/\.meta$//;
                    724:     my $disuri=&Apache::lonnet::clutter($uri);
                    725:     # version
                    726:     my $currentversion=&Apache::lonnet::getversion($disuri);
                    727:     my $versiondisplay='';
                    728:     if ($thisversion) {
                    729:         $versiondisplay=&mt('Version').': '.$thisversion.
                    730:             ' ('.&mt('most recent version').': '.
                    731:             ($currentversion>0 ? 
                    732:              $currentversion   :
                    733:              &mt('information not available')).')';
                    734:     } else {
                    735:         $versiondisplay='Version: '.$currentversion;
                    736:     }
1.72      matthew   737:     # crumbify displayed URL               uri     target prefix form  size
                    738:     $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
                    739:     $disuri =~ s:<br />::g;
1.66      matthew   740:     # obsolete
                    741:     my $obsolete=$content{'obsolete'};
                    742:     my $obsoletewarning='';
1.96      albertel  743:     if (($obsolete) && ($env{'user.adv'})) {
1.66      matthew   744:         $obsoletewarning='<p><font color="red">'.
                    745:             &mt('This resource has been marked obsolete by the author(s)').
                    746:             '</font></p>';
                    747:     }
                    748:     #
                    749:     my %lt=&fieldnames();
                    750:     my $table='';
1.72      matthew   751:     my $title = $content{'title'};
                    752:     if (! defined($title)) {
                    753:         $title = 'Untitled Resource';
                    754:     }
1.66      matthew   755:     foreach ('title', 
                    756:              'author', 
                    757:              'subject', 
                    758:              'keywords', 
                    759:              'notes', 
                    760:              'abstract',
                    761:              'lowestgradelevel',
                    762:              'highestgradelevel',
                    763:              'standards', 
                    764:              'mime', 
                    765:              'language', 
                    766:              'creationdate', 
                    767:              'lastrevisiondate', 
                    768:              'owner', 
                    769:              'copyright', 
1.78      taceyjo1  770:              'customdistributionfile',
                    771:              'sourceavail',
                    772:              'sourcerights', 
1.66      matthew   773:              'obsolete', 
                    774:              'obsoletereplacement') {
                    775:         $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
                    776:             '</td><td bgcolor="#CCCCCC">'.
                    777:             &prettyprint($_,$content{$_}).'</td></tr>';
                    778:         delete $content{$_};
                    779:     }
                    780:     #
                    781:     $r->print(<<ENDHEAD);
1.72      matthew   782: <h2>$title</h2>
                    783: <p>
                    784: $disuri<br />
1.36      www       785: $obsoletewarning
1.72      matthew   786: $versiondisplay
                    787: </p>
1.88      banghart  788: <table cellspacing="2" border="0">
1.45      www       789: $table
1.11      www       790: </table>
1.1       www       791: ENDHEAD
1.96      albertel  792:     if ($env{'user.adv'}) {
1.68      matthew   793:         &print_dynamic_metadata($r,$uri,\%content);
1.67      matthew   794:     }
                    795:     return;
                    796: }
                    797: 
                    798: sub print_dynamic_metadata {
1.68      matthew   799:     my ($r,$uri,$content) = @_;
                    800:     #
1.69      matthew   801:     my %content = %$content;
1.68      matthew   802:     my %lt=&fieldnames();
1.67      matthew   803:     #
                    804:     my $description = 'Dynamic Metadata (updated periodically)';
                    805:     $r->print('<h3>'.&mt($description).'</h3>'.
1.70      matthew   806:               &mt('Processing'));
1.67      matthew   807:     $r->rflush();
                    808:     my %items=&fieldnames();
                    809:     my %dynmeta=&dynamicmeta($uri);
                    810:     #
                    811:     # General Access and Usage Statistics
1.70      matthew   812:     if (exists($dynmeta{'count'}) ||
                    813:         exists($dynmeta{'sequsage'}) ||
                    814:         exists($dynmeta{'comefrom'}) ||
                    815:         exists($dynmeta{'goto'}) ||
                    816:         exists($dynmeta{'course'})) {
                    817:         $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
1.88      banghart  818:                   '<table cellspacing="2" border="0">');
1.70      matthew   819:         foreach ('count',
                    820:                  'sequsage','sequsage_list',
                    821:                  'comefrom','comefrom_list',
                    822:                  'goto','goto_list',
                    823:                  'course','course_list') {
                    824:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
                    825:                       '<td bgcolor="#CCCCCC">'.
                    826:                       &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
                    827:         }
                    828:         $r->print('</table>');
                    829:     } else {
                    830:         $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
1.67      matthew   831:     }
1.69      matthew   832:     #
                    833:     # Assessment statistics
1.73      matthew   834:     if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    835:         if (exists($dynmeta{'stdno'}) ||
                    836:             exists($dynmeta{'avetries'}) ||
                    837:             exists($dynmeta{'difficulty'}) ||
                    838:             exists($dynmeta{'disc'})) {
                    839:             # This is an assessment, print assessment data
                    840:             $r->print('<h4>'.
                    841:                       &mt('Overall Assessment Statistical Data').
                    842:                       '</h4>'.
1.88      banghart  843:                       '<table cellspacing="2" border="0">');
1.73      matthew   844:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
1.66      matthew   845:                       '<td bgcolor="#CCCCCC">'.
1.73      matthew   846:                       &prettyprint('stdno',$dynmeta{'stdno'}).
                    847:                       '</td>'."</tr>\n");
                    848:             foreach ('avetries','difficulty','disc') {
                    849:                 $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
                    850:                           '<td bgcolor="#CCCCCC">'.
                    851:                           &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
                    852:                           '</td>'."</tr>\n");
                    853:             }
                    854:             $r->print('</table>');    
                    855:         }
                    856:         if (exists($dynmeta{'stats'})) {
                    857:             #
                    858:             # New assessment statistics
                    859:             $r->print('<h4>'.
                    860:                       &mt('Detailed Assessment Statistical Data').
                    861:                       '</h4>');
1.88      banghart  862:             my $table = '<table cellspacing="2" border="0">'.
1.73      matthew   863:                 '<tr>'.
                    864:                 '<th>Course</th>'.
                    865:                 '<th>Section(s)</th>'.
                    866:                 '<th>Num Students</th>'.
                    867:                 '<th>Mean Tries</th>'.
                    868:                 '<th>Degree of Difficulty</th>'.
                    869:                 '<th>Degree of Discrimination</th>'.
                    870:                 '<th>Time of computation</th>'.
                    871:                 '</tr>'.$/;
                    872:             foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
                    873:                 my $data = $dynmeta{'stats'}->{$identifier};
                    874:                 my $course = $data->{'course'};
                    875:                 my %courseinfo = &Apache::lonnet::coursedescription($course);
                    876:                 if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
                    877:                     &Apache::lonnet::logthis('lookup for '.$course.' failed');
                    878:                     next;
                    879:                 }
                    880:                 $table .= '<tr>';
                    881:                 $table .= 
                    882:                     '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
                    883:                 $table .= 
                    884:                     '<td align="right">'.$data->{'sections'}.'</td>';
                    885:                 $table .=
                    886:                     '<td align="right">'.$data->{'stdno'}.'</td>';
                    887:                 foreach ('avetries','difficulty','disc') {
                    888:                     $table .= '<td align="right">';
                    889:                     if (exists($data->{$_})) {
                    890:                         $table .= sprintf('%.2f',$data->{$_}).'&nbsp;';
                    891:                     } else {
                    892:                         $table .= '';
                    893:                     }
                    894:                     $table .= '</td>';
                    895:                 }
                    896:                 $table .=
                    897:                     '<td><nobr>'.
                    898:                     &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
                    899:                     '</nobr></td>';
                    900:                 $table .=
                    901:                     '</tr>'.$/;
                    902:             }
                    903:             $table .= '</table>'.$/;
                    904:             $r->print($table);
                    905:         } else {
                    906:             $r->print('No new dynamic data found.');
1.66      matthew   907:         }
1.70      matthew   908:     } else {
1.73      matthew   909:         $r->print('<h4>'.
                    910:           &mt('No Assessment Statistical Data is available for this resource').
                    911:                   '</h4>');
1.67      matthew   912:     }
1.73      matthew   913: 
                    914:     #
                    915:     #
1.70      matthew   916:     if (exists($dynmeta{'clear'})   || 
                    917:         exists($dynmeta{'depth'})   || 
                    918:         exists($dynmeta{'helpful'}) || 
                    919:         exists($dynmeta{'correct'}) || 
                    920:         exists($dynmeta{'technical'})){ 
                    921:         $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
1.88      banghart  922:                   '<table cellspacing="2" border="0">');
1.70      matthew   923:         foreach ('clear','depth','helpful','correct','technical') {
                    924:             $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
                    925:                       '<td bgcolor="#CCCCCC">'.
                    926:                       &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
                    927:         }
                    928:         $r->print('</table>');
                    929:     } else {
                    930:         $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1.67      matthew   931:     }
                    932:     $uri=~/^\/res\/(\w+)\/(\w+)\//; 
1.96      albertel  933:     if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
                    934:         || ($env{'user.role.ca./'.$1.'/'.$2})) {
1.70      matthew   935:         if (exists($dynmeta{'comments'})) {
                    936:             $r->print('<h4>'.&mt('Evaluation Comments').' ('.
                    937:                       &mt('visible to author and co-authors only').
                    938:                       ')</h4>'.
                    939:                       '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
                    940:         } else {
                    941:             $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
                    942:         }
                    943:         my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
                    944:         if (defined($bombs) && $bombs ne '') {
                    945:             $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
                    946:                       &mt('visible to author and co-authors only').')'.
                    947:                       '</h4>'.$bombs);
                    948:         } else {
                    949:             $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
                    950:         }
1.67      matthew   951:     }
1.69      matthew   952:     #
1.67      matthew   953:     # All other stuff
                    954:     $r->print('<h3>'.
                    955:               &mt('Additional Metadata (non-standard, parameters, exports)').
1.81      www       956:               '</h3><table border="0" cellspacing="1">');
1.67      matthew   957:     foreach (sort(keys(%content))) {
                    958:         my $name=$_;
                    959:         if ($name!~/\.display$/) {
                    960:             my $display=&Apache::lonnet::metadata($uri,
                    961:                                                   $name.'.display');
                    962:             if (! $display) { 
                    963:                 $display=$name;
                    964:             };
                    965:             my $otherinfo='';
                    966:             foreach ('name','part','type','default') {
                    967:                 if (defined(&Apache::lonnet::metadata($uri,
                    968:                                                       $name.'.'.$_))) {
                    969:                     $otherinfo.=' '.$_.'='.
                    970:                         &Apache::lonnet::metadata($uri,
                    971:                                                   $name.'.'.$_).'; ';
                    972:                 }
1.64      matthew   973:             }
1.81      www       974:             $r->print('<tr><td bgcolor="#bbccbb"><font size="-1" color="#556655">'.$display.'</font></td><td bgcolor="#ccddcc"><font size="-1" color="#556655">'.$content{$name});
1.67      matthew   975:             if ($otherinfo) {
                    976:                 $r->print(' ('.$otherinfo.')');
1.64      matthew   977:             }
1.81      www       978:             $r->print("</font></td></tr>\n");
1.64      matthew   979:         }
1.66      matthew   980:     }
1.81      www       981:     $r->print("</table>");
1.67      matthew   982:     return;
1.66      matthew   983: }
1.105     banghart  984: 
1.102     banghart  985: 
                    986: 
1.67      matthew   987: #####################################################
                    988: #####################################################
                    989: ###                                               ###
                    990: ###          Editable metadata display            ###
                    991: ###                                               ###
                    992: #####################################################
                    993: #####################################################
1.66      matthew   994: sub present_editable_metadata {
1.90      banghart  995:     my ($r,$uri, $file_type) = @_;
1.66      matthew   996:     # Construction Space Call
                    997:     # Header
                    998:     my $disuri=$uri;
                    999:     my $fn=&Apache::lonnet::filelocation('',$uri);
                   1000:     $disuri=~s/^\/\~/\/priv\//;
                   1001:     $disuri=~s/\.meta$//;
1.110     albertel 1002:     $disuri=~s|^/editupload||;
1.66      matthew  1003:     my $target=$uri;
1.96      albertel 1004:     $target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;
1.66      matthew  1005:     $target=~s/\.meta$//;
                   1006:     my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
                   1007:     if ($bombs) {
1.99      www      1008:         my $showdel=1;
1.96      albertel 1009:         if ($env{'form.delmsg'}) {
1.66      matthew  1010:             if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
                   1011:                 $bombs=&mt('Messages deleted.');
1.99      www      1012: 		$showdel=0;
1.66      matthew  1013:             } else {
                   1014:                 $bombs=&mt('Error deleting messages');
1.64      matthew  1015:             }
1.66      matthew  1016:         }
1.98      www      1017:         if ($env{'form.clearmsg'}) {
                   1018: 	    my $cleardir=$target;
                   1019: 	    $cleardir=~s/\/[^\/]+$/\//;
                   1020:             if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
                   1021:                 $bombs=&mt('Messages cleared.');
1.99      www      1022: 		$showdel=0;
1.98      www      1023:             } else {
                   1024:                 $bombs=&mt('Error clearing messages');
                   1025:             }
                   1026:         }
                   1027:         my $del=&mt('Delete Messages for this Resource');
                   1028: 	my $clear=&mt('Clear all Messages in Subdirectory');
1.99      www      1029: 	my $goback=&mt('Back to Source File');
1.66      matthew  1030:         $r->print(<<ENDBOMBS);
1.52      www      1031: <h1>$disuri</h1>
                   1032: <form method="post" name="defaultmeta">
1.99      www      1033: ENDBOMBS
                   1034:         if ($showdel) {
                   1035: 	    $r->print(<<ENDDEL);
1.59      www      1036: <input type="submit" name="delmsg" value="$del" />
1.98      www      1037: <input type="submit" name="clearmsg" value="$clear" />
1.99      www      1038: ENDDEL
                   1039:         } else {
                   1040:             $r->print('<a href="'.$disuri.'" />'.$goback.'</a>');
                   1041: 	}
                   1042: 	$r->print('<br />'.$bombs);
1.66      matthew  1043:     } else {
                   1044:         my $displayfile='Catalog Information for '.$disuri;
                   1045:         if ($disuri=~/\/default$/) {
                   1046:             my $dir=$disuri;
                   1047:             $dir=~s/default$//;
                   1048:             $displayfile=
                   1049:                 &mt('Default Cataloging Information for Directory').' '.
                   1050:                 $dir;
                   1051:         }
                   1052:         %Apache::lonpublisher::metadatafields=();
                   1053:         %Apache::lonpublisher::metadatakeys=();
1.94      banghart 1054:         my $result=&Apache::lonnet::getfile($fn);
                   1055:         if ($result == -1){
1.110     albertel 1056:             $r->print('Creating new '.$disuri);
1.94      banghart 1057:         } else {
                   1058:             &Apache::lonpublisher::metaeval($result);
                   1059:         }
1.66      matthew  1060:         $r->print(<<ENDEDIT);
1.23      www      1061: <h1>$displayfile</h1>
1.48      www      1062: <form method="post" name="defaultmeta">
1.23      www      1063: ENDEDIT
1.66      matthew  1064:         $r->print('<script language="JavaScript">'.
1.86      albertel 1065:                   &Apache::loncommon::browser_and_searcher_javascript().
1.66      matthew  1066:                   '</script>');
1.90      banghart 1067:         my %lt=&fieldnames($file_type);
1.87      albertel 1068: 	my $output;
1.90      banghart 1069: 	my @fields;
                   1070: 	if ($file_type eq 'portfolio') {
1.113     banghart 1071: 	    @fields =  ('author','title','subject','keywords','abstract','notes','lowestgradelevel',
1.120     banghart 1072: 	                'highestgradelevel','courserestricted');
1.90      banghart 1073: 	} else {
                   1074: 	    @fields = ('author','title','subject','keywords','abstract','notes',
1.66      matthew  1075:                  'copyright','customdistributionfile','language',
                   1076:                  'standards',
1.78      taceyjo1 1077:                  'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1.90      banghart 1078:                  'obsolete','obsoletereplacement');
                   1079:         }
1.120     banghart 1080:         my $metacourse;
                   1081:         if ($env{'form.metacourse'} ) {
                   1082:             $Apache::lonpublisher::metadatafields{'courserestricted'} = $env{'form.metacourse'};
                   1083:             $metacourse = $env{'form.metacourse'};
                   1084:          } else {
                   1085:             if (! $Apache::lonpublisher::metadatafields{'courserestricted'}) {
                   1086:                 $Apache::lonpublisher::metadatafields{'courserestricted'}=
                   1087:                     'none';
                   1088:                 $metacourse = 'none';
                   1089:             } else {
                   1090:                 $metacourse = $Apache::lonpublisher::metadatafields{'courserestricted'};
                   1091:             }
                   1092:         }
                   1093:         if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
                   1094:                 $Apache::lonpublisher::metadatafields{'copyright'}=
                   1095:                 'default';
                   1096:         }
1.125     banghart 1097:         if ($metacourse ne 'none') {
                   1098:              $r->print('Document metadata restricted by :<strong> '.$env{$metacourse.".description"}."</strong><br />");
                   1099:         }
                   1100:         
1.90      banghart 1101:         foreach (@fields) {
1.96      albertel 1102:             if (defined($env{'form.new_'.$_})) {
1.66      matthew  1103:                 $Apache::lonpublisher::metadatafields{$_}=
1.123     banghart 1104:                     join(',',&Apache::loncommon::get_env_multiple('form.new_'.$_));
1.66      matthew  1105:             }
1.127     banghart 1106:             my $field_name = $_;
1.120     banghart 1107:             if ($metacourse ne 'none') {
1.115     banghart 1108:                 # handle restrictions here
1.127     banghart 1109:                 if ($env{$metacourse.'.metadata.'.$_.'.options'} =~ m/active/){
1.115     banghart 1110:                     $output.=('<p>'.$lt{$_}.': '.
1.127     banghart 1111:                               &prettyinput($_,
1.87      albertel 1112: 				   $Apache::lonpublisher::metadatafields{$_},
1.120     banghart 1113: 				   'new_'.$_,'defaultmeta',undef,undef,undef,undef,$metacourse).'</p>');
1.127     banghart 1114:                  } elsif ($_ eq 'courserestricted') {
                   1115:                             $output.=(
                   1116:                                 &prettyinput($field_name,
                   1117: 				    $Apache::lonpublisher::metadatafields{$_},
                   1118: 				    'new_'.$field_name,'defaultmeta',undef,undef,undef,undef,$metacourse));
                   1119:                  }
1.115     banghart 1120:             } else {
1.127     banghart 1121:                 if ($_ ne 'courserestricted') {
                   1122:                     $output.=('<p>'.$lt{$_}.': '.
1.115     banghart 1123:                             &prettyinput($_,
                   1124: 				   $Apache::lonpublisher::metadatafields{$_},
                   1125: 				   'new_'.$_,'defaultmeta').'</p>');
1.127     banghart 1126: 	        } else {
                   1127:                     $output.=&prettyinput($field_name,
                   1128: 				   $Apache::lonpublisher::metadatafields{$_},
                   1129: 				   'new_'.$field_name,'defaultmeta');
                   1130:                 }
1.115     banghart 1131:             }
1.66      matthew  1132:         }
1.127     banghart 1133:         $output.=('<p>'.$lt{$_}.': '.
                   1134:                  &prettyinput($_,
                   1135: 		 $Apache::lonpublisher::metadatafields{$_},
                   1136: 		 'new_'.$_,'defaultmeta',undef,undef,undef,undef,$metacourse).'</p>');
                   1137: 
1.96      albertel 1138:         if ($env{'form.store'}) {
1.66      matthew  1139:             my $mfh;
1.107     banghart 1140:             my $formname='store'; 
1.94      banghart 1141:             my $file_content;
1.108     banghart 1142:             foreach my $meta_field (keys %env) {
1.122     banghart 1143:                 if (&Apache::loncommon::get_env_multiple('form.new_keywords')) {
1.123     banghart 1144:                     $Apache::lonpublisher::metadatafields{'keywords'} = 
1.122     banghart 1145:                         join (',', &Apache::loncommon::get_env_multiple('form.new_keywords'));
1.108     banghart 1146:                 }
1.106     banghart 1147:             }
1.94      banghart 1148:             foreach (sort keys %Apache::lonpublisher::metadatafields) {
                   1149:                 next if ($_ =~ /\./);
                   1150:                 my $unikey=$_;
                   1151:                 $unikey=~/^([A-Za-z]+)/;
                   1152:                 my $tag=$1;
                   1153:                 $tag=~tr/A-Z/a-z/;
                   1154:                 $file_content.= "\n\<$tag";
                   1155:                 foreach (split(/\,/,
                   1156:                              $Apache::lonpublisher::metadatakeys{$unikey})
                   1157:                          ) {
                   1158:                     my $value=
                   1159:                      $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
                   1160:                     $value=~s/\"/\'\'/g;
                   1161:                     $file_content.=' '.$_.'="'.$value.'"' ;
                   1162:                     # print $mfh ' '.$_.'="'.$value.'"';
                   1163:                 }
                   1164:                 $file_content.= '>'.
                   1165:                     &HTML::Entities::encode
                   1166:                     ($Apache::lonpublisher::metadatafields{$unikey},
                   1167:                      '<>&"').
                   1168:                      '</'.$tag.'>';
                   1169:             }
                   1170:             if ($fn =~ /\/portfolio\//) {
                   1171:                 $fn =~ /\/portfolio\/(.*)$/;
                   1172:                 my $new_fn = '/'.$1;
1.96      albertel 1173:                 $env{'form.'.$formname}=$file_content;
                   1174:                 $env{'form.'.$formname.'.filename'}=$new_fn;
1.94      banghart 1175:                 &Apache::lonnet::userfileupload('uploaddoc','',
1.96      albertel 1176: 	        	 'portfolio'.$env{'form.currentpath'});
1.94      banghart 1177:                 if (&Apache::lonnet::userfileupload($formname,'','portfolio') eq 'error: no uploaded file') {
                   1178:                     $r->print('<p><font color="red">'.
                   1179:                       &mt('Could not write metadata').', '.
                   1180:                      &mt('FAIL').'</font></p>');
                   1181:                 } else {
                   1182:                     $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
                   1183: 		  ' '.&Apache::lonlocal::locallocaltime(time).
                   1184: 		  '</font></p>');
                   1185:                 }
1.66      matthew  1186:             } else {
1.94      banghart 1187:                 if (!  ($mfh=Apache::File->new('>'.$fn))) {
                   1188:                     $r->print('<p><font color="red">'.
                   1189:                         &mt('Could not write metadata').', '.
                   1190:                         &mt('FAIL').'</font></p>');
                   1191:                 } else {
                   1192:                     print $mfh $file_content;
1.95      albertel 1193: 		    $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
                   1194: 			      ' '.&Apache::lonlocal::locallocaltime(time).
                   1195: 			      '</font></p>');
1.64      matthew  1196:                 }
                   1197:             }
                   1198:         }
1.87      albertel 1199: 	$r->print($output.'<br /><input type="submit" name="store" value="'.
1.67      matthew  1200:                   &mt('Store Catalog Information').'">');
1.64      matthew  1201:     }
1.67      matthew  1202:     $r->print('</form>');
1.66      matthew  1203:     return;
1.1       www      1204: }
1.64      matthew  1205: 
1.1       www      1206: 1;
                   1207: __END__
1.97      banghart 1208: 
1.98      www      1209:      

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