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