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