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