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

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

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