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