Annotation of loncom/interface/lonmeta.pm, revision 1.74
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.74 ! matthew 4: # $Id: lonmeta.pm,v 1.73 2004/04/16 21:43:56 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.64 matthew 349: # Language
1.48 www 350: if ($type eq 'language') {
351: return &selectbox($fieldname,
352: $value,
353: \&Apache::loncommon::languagedescription,
1.54 www 354: (&Apache::loncommon::languageids)).
1.64 matthew 355: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 356: }
1.64 matthew 357: # Copyright
1.48 www 358: if ($type eq 'copyright') {
359: return &selectbox($fieldname,
360: $value,
361: \&Apache::loncommon::copyrightdescription,
1.54 www 362: (&Apache::loncommon::copyrightids)).
1.64 matthew 363: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 364: }
1.64 matthew 365: # Gradelevels
1.48 www 366: if (($type eq 'lowestgradelevel') ||
367: ($type eq 'highestgradelevel')) {
1.54 www 368: return &Apache::loncommon::select_level_form($value,$fieldname).
1.64 matthew 369: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 370: }
1.64 matthew 371: # Obsolete
1.48 www 372: if ($type eq 'obsolete') {
373: return '<input type="checkbox" name="'.$fieldname.'"'.
1.54 www 374: ($value?' checked="1"':'').' />'.
1.64 matthew 375: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 376: }
1.64 matthew 377: # Obsolete replacement file
1.48 www 378: if ($type eq 'obsoletereplacement') {
379: return '<input type="text" name="'.$fieldname.
380: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
381: "('".$formname."','".$fieldname."'".
1.54 www 382: ",'')\">".&mt('Select').'</a>'.
1.64 matthew 383: &relatedfield(0,$relatedsearchflag,$relatedsep);
384: }
385: # Customdistribution file
1.48 www 386: if ($type eq 'customdistributionfile') {
387: return '<input type="text" name="'.$fieldname.
388: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
389: "('".$formname."','".$fieldname."'".
1.54 www 390: ",'rights')\">".&mt('Select').'</a>'.
1.64 matthew 391: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 392: }
1.64 matthew 393: # Dates
1.48 www 394: if (($type eq 'creationdate') ||
395: ($type eq 'lastrevisiondate')) {
1.64 matthew 396: return
397: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
398: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 399: }
1.64 matthew 400: # No pretty input found
1.48 www 401: $value=~s/^\s+//gs;
402: $value=~s/\s+$//gs;
403: $value=~s/\s+/ /gs;
404: $value=~s/\"/\&quod\;/gs;
1.54 www 405: return
1.74 ! matthew 406: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
1.64 matthew 407: 'value="'.$value.'" />'.
408: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
409: $relatedvalue);
1.46 www 410: }
411:
1.64 matthew 412: # Main Handler
1.1 www 413: sub handler {
1.64 matthew 414: my $r=shift;
415: #
1.67 matthew 416: my $uri=$r->uri;
417: #
418: # Check to see if this server is overloaded
1.20 www 419: my $loaderror=&Apache::lonnet::overloaderror($r);
1.67 matthew 420: if ($loaderror) {
421: return $loaderror;
422: }
1.64 matthew 423: #
1.67 matthew 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;
1.64 matthew 437: #
1.67 matthew 438: $r->print('<html><head><title>'.
439: 'Catalog Information'.
440: '</title></head>');
1.66 matthew 441: if ($uri=~m:/adm/bombs/(.*)$:) {
1.67 matthew 442: $r->print(&Apache::loncommon::bodytag('Error Messages'));
1.66 matthew 443: # Looking for all bombs?
444: &report_bombs($r,$uri);
445: } elsif ($uri=~/^\/\~/) {
446: # Construction space
1.67 matthew 447: $r->print(&Apache::loncommon::bodytag
448: ('Edit Catalog Information','','','',$resdomain));
1.66 matthew 449: &present_editable_metadata($r,$uri);
450: } else {
1.67 matthew 451: $r->print(&Apache::loncommon::bodytag
452: ('Catalog Information','','','',$resdomain));
1.66 matthew 453: &present_uneditable_metadata($r,$uri);
454: }
1.67 matthew 455: $r->print('</body></html>');
1.66 matthew 456: return OK;
457: }
458:
1.67 matthew 459: #####################################################
460: #####################################################
461: ### ###
462: ### Report Bombs ###
463: ### ###
464: #####################################################
465: #####################################################
1.66 matthew 466: sub report_bombs {
467: my ($r,$uri) = @_;
468: # Set document type
1.67 matthew 469: $uri =~ s:/adm/bombs/::;
470: $uri = &Apache::lonnet::declutter($uri);
1.66 matthew 471: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
472: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
473: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
1.67 matthew 474: my %brokenurls =
475: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
476: foreach (sort(keys(%brokenurls))) {
1.66 matthew 477: if ($_=~/^\Q$uri\E/) {
1.70 matthew 478: $r->print
479: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
480: &Apache::lonmsg::retrieve_author_res_msg($_).
481: '<hr />');
1.64 matthew 482: }
483: }
1.66 matthew 484: } else {
485: $r->print(&mt('Not authorized'));
486: }
487: return;
488: }
489:
1.67 matthew 490: #####################################################
491: #####################################################
492: ### ###
493: ### Uneditable Metadata Display ###
494: ### ###
495: #####################################################
496: #####################################################
1.66 matthew 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: }
1.72 matthew 522: # crumbify displayed URL uri target prefix form size
523: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
524: $disuri =~ s:<br />::g;
1.66 matthew 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='';
1.72 matthew 536: my $title = $content{'title'};
537: if (! defined($title)) {
538: $title = 'Untitled Resource';
539: }
1.66 matthew 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);
1.72 matthew 565: <h2>$title</h2>
566: <p>
567: $disuri<br />
1.36 www 568: $obsoletewarning
1.72 matthew 569: $versiondisplay
570: </p>
1.11 www 571: <table cellspacing=2 border=0>
1.45 www 572: $table
1.11 www 573: </table>
1.1 www 574: ENDHEAD
1.66 matthew 575: if ($ENV{'user.adv'}) {
1.68 matthew 576: &print_dynamic_metadata($r,$uri,\%content);
1.67 matthew 577: }
578: return;
579: }
580:
581: sub print_dynamic_metadata {
1.68 matthew 582: my ($r,$uri,$content) = @_;
583: #
1.69 matthew 584: my %content = %$content;
1.68 matthew 585: my %lt=&fieldnames();
1.67 matthew 586: #
587: my $description = 'Dynamic Metadata (updated periodically)';
588: $r->print('<h3>'.&mt($description).'</h3>'.
1.70 matthew 589: &mt('Processing'));
1.67 matthew 590: $r->rflush();
591: my %items=&fieldnames();
592: my %dynmeta=&dynamicmeta($uri);
1.73 matthew 593: &Apache::lonnet::logthis('dynamic metadata keys:'.$/.
594: join("\n",keys(%dynmeta)));
1.67 matthew 595: #
596: # General Access and Usage Statistics
1.70 matthew 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>');
1.67 matthew 616: }
1.69 matthew 617: #
618: # Assessment statistics
1.73 matthew 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>'.
1.66 matthew 630: '<td bgcolor="#CCCCCC">'.
1.73 matthew 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.');
1.66 matthew 692: }
1.70 matthew 693: } else {
1.73 matthew 694: $r->print('<h4>'.
695: &mt('No Assessment Statistical Data is available for this resource').
696: '</h4>');
1.67 matthew 697: }
1.73 matthew 698:
699: #
700: #
1.70 matthew 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>');
1.67 matthew 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})) {
1.70 matthew 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: }
1.67 matthew 736: }
1.69 matthew 737: #
1.67 matthew 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: }
1.64 matthew 758: }
1.67 matthew 759: $r->print('<b>'.$display.':</b> '.$content{$name});
760: if ($otherinfo) {
761: $r->print(' ('.$otherinfo.')');
1.64 matthew 762: }
1.67 matthew 763: $r->print("<br />\n");
1.64 matthew 764: }
1.66 matthew 765: }
1.67 matthew 766: return;
1.66 matthew 767: }
768:
1.67 matthew 769: #####################################################
770: #####################################################
771: ### ###
772: ### Editable metadata display ###
773: ### ###
774: #####################################################
775: #####################################################
1.66 matthew 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');
1.64 matthew 794: }
1.66 matthew 795: }
796: my $del=&mt('Delete Messages');
797: $r->print(<<ENDBOMBS);
1.52 www 798: <h1>$disuri</h1>
799: <form method="post" name="defaultmeta">
1.59 www 800: <input type="submit" name="delmsg" value="$del" />
1.52 www 801: <br />$bombs
802: ENDBOMBS
1.66 matthew 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);
1.23 www 818: <html><head><title>Edit Catalog Information</title></head>
819: $bodytag
820: <h1>$displayfile</h1>
1.48 www 821: <form method="post" name="defaultmeta">
1.23 www 822: ENDEDIT
1.66 matthew 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';
1.64 matthew 839: }
1.66 matthew 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) {
1.67 matthew 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(/\,/,
1.64 matthew 860: $Apache::lonpublisher::metadatakeys{$unikey})
1.67 matthew 861: ) {
862: my $value=
863: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
864: $value=~s/\"/\'\'/g;
865: print $mfh ' '.$_.'="'.$value.'"';
1.64 matthew 866: }
1.67 matthew 867: print $mfh '>'.
868: &HTML::Entities::encode
869: ($Apache::lonpublisher::metadatafields{$unikey},
870: '<>&"').
871: '</'.$tag.'>';
1.64 matthew 872: }
1.66 matthew 873: $r->print('<p>'.&mt('Wrote Metadata'));
1.64 matthew 874: }
875: }
1.66 matthew 876: $r->print('<br /><input type="submit" name="store" value="'.
1.67 matthew 877: &mt('Store Catalog Information').'">');
1.64 matthew 878: }
1.67 matthew 879: $r->print('</form>');
1.66 matthew 880: return;
1.1 www 881: }
1.64 matthew 882:
1.1 www 883: 1;
884: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>