Annotation of loncom/interface/lonmeta.pm, revision 1.78
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.78 ! taceyjo1 4: # $Id: lonmeta.pm,v 1.77 2004/05/07 17:17:58 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',
1.78 ! taceyjo1 178: 'sourceavail' => 'Source Availible',
! 179: 'sourcerights' => 'Source Custom Distribution File',
1.64 matthew 180: 'obsolete' => 'Obsolete',
181: 'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
182: 'count' => 'Network-wide number of accesses (hits)',
183: 'course' => 'Network-wide number of courses using resource',
184: 'course_list' => 'Network-wide courses using resource',
185: 'sequsage' => 'Number of resources using or importing resource',
186: 'sequsage_list' => 'Resources using or importing resource',
187: 'goto' => 'Number of resources that follow this resource in maps',
188: 'goto_list' => 'Resources that follow this resource in maps',
189: 'comefrom' => 'Number of resources that lead up to this resource in maps',
190: 'comefrom_list' => 'Resources that lead up to this resource in maps',
191: 'clear' => 'Material presented in clear way',
192: 'depth' => 'Material covered with sufficient depth',
193: 'helpful' => 'Material is helpful',
194: 'correct' => 'Material appears to be correct',
195: 'technical' => 'Resource is technically correct',
196: 'avetries' => 'Average number of tries till solved',
197: 'stdno' => 'Total number of students who have worked on this problem',
1.73 matthew 198: 'difficulty' => 'Degree of difficulty',
199: 'disc' => 'Degree of discrimination',
1.64 matthew 200: );
1.45 www 201: }
1.46 www 202:
1.64 matthew 203: # Pretty printing of metadata field
1.46 www 204:
205: sub prettyprint {
206: my ($type,$value)=@_;
1.65 matthew 207: if (! defined($value)) {
208: return ' ';
209: }
1.64 matthew 210: # Title
1.46 www 211: if ($type eq 'title') {
212: return '<font size="+1" face="arial">'.$value.'</font>';
213: }
1.64 matthew 214: # Dates
1.46 www 215: if (($type eq 'creationdate') ||
216: ($type eq 'lastrevisiondate')) {
1.55 www 217: return ($value?&Apache::lonlocal::locallocaltime(
218: &Apache::lonmysql::unsqltime($value)):
219: &mt('not available'));
1.46 www 220: }
1.64 matthew 221: # Language
1.46 www 222: if ($type eq 'language') {
223: return &Apache::loncommon::languagedescription($value);
224: }
1.64 matthew 225: # Copyright
1.46 www 226: if ($type eq 'copyright') {
227: return &Apache::loncommon::copyrightdescription($value);
228: }
1.78 ! taceyjo1 229: # Copyright
! 230: if ($type eq 'sourceavail') {
! 231: return &Apache::loncommon::source_copyrightdescription($value);
! 232: }
1.64 matthew 233: # MIME
1.46 www 234: if ($type eq 'mime') {
1.64 matthew 235: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
236: &Apache::loncommon::filedescription($value);
237: }
238: # Person
1.46 www 239: if (($type eq 'author') ||
240: ($type eq 'owner') ||
241: ($type eq 'modifyinguser') ||
242: ($type eq 'authorspace')) {
243: $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
244: return $value;
245: }
1.64 matthew 246: # Gradelevel
1.48 www 247: if (($type eq 'lowestgradelevel') ||
248: ($type eq 'highestgradelevel')) {
249: return &Apache::loncommon::gradeleveldescription($value);
250: }
1.64 matthew 251: # Only for advance users below
1.65 matthew 252: if (! $ENV{'user.adv'}) {
253: return '<i>- '.&mt('not displayed').' -</i>';
254: }
1.64 matthew 255: # File
1.46 www 256: if (($type eq 'customdistributionfile') ||
257: ($type eq 'obsoletereplacement') ||
258: ($type eq 'goto_list') ||
259: ($type eq 'comefrom_list') ||
260: ($type eq 'sequsage_list')) {
261: return join('<br />',map {
1.70 matthew 262: my $url = &Apache::lonnet::clutter($_);
1.72 matthew 263: my $title = &Apache::lonnet::gettitle($url);
264: if ($title eq '') {
265: $title = 'Untitled';
266: if ($url =~ /\.sequence$/) {
267: $title .= ' Sequence';
268: } elsif ($url =~ /\.page$/) {
269: $title .= ' Page';
270: } elsif ($url =~ /\.problem$/) {
271: $title .= ' Problem';
272: } elsif ($url =~ /\.html$/) {
273: $title .= ' HTML document';
274: } elsif ($url =~ m:/syllabus$:) {
275: $title .= ' Syllabus';
276: }
277: }
278: $_ = '<b>'.$title.'</b> '.
1.70 matthew 279: '<a href="'.$url.'" target="preview">'.
280: '<font size="-1">'.$url.'</font>'.
281: '</a>'
1.64 matthew 282: } split(/\s*\,\s*/,$value));
1.46 www 283: }
1.64 matthew 284: # Evaluations
1.46 www 285: if (($type eq 'clear') ||
286: ($type eq 'depth') ||
287: ($type eq 'helpful') ||
288: ($type eq 'correct') ||
289: ($type eq 'technical')) {
290: return &evalgraph($value);
291: }
1.64 matthew 292: # Difficulty
1.73 matthew 293: if ($type eq 'difficulty' || $type eq 'disc') {
1.46 www 294: return &diffgraph($value);
295: }
1.64 matthew 296: # List of courses
1.46 www 297: if ($type=~/\_list/) {
1.72 matthew 298: my @Courses = split(/\s*\,\s*/,$value);
299: my $Str;
300: foreach my $course (@Courses) {
301: my %courseinfo = &Apache::lonnet::coursedescription($course);
302: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
303: next;
304: }
305: if ($Str ne '') { $Str .= '<br />'; }
306: $Str .= '<a href="/public/'.$courseinfo{'domain'}.'/'.
307: $courseinfo{'num'}.'/syllabus" target="preview">'.
308: $courseinfo{'description'}.'</a>';
309: }
310: return $Str;
1.46 www 311: }
1.64 matthew 312: # No pretty print found
1.46 www 313: return $value;
314: }
315:
1.64 matthew 316: # Pretty input of metadata field
1.54 www 317: sub direct {
318: return shift;
319: }
320:
1.48 www 321: sub selectbox {
322: my ($name,$value,$functionref,@idlist)=@_;
1.65 matthew 323: if (! defined($functionref)) {
324: $functionref=\&direct;
325: }
1.48 www 326: my $selout='<select name="'.$name.'">';
327: foreach (@idlist) {
328: $selout.='<option value=\''.$_.'\'';
329: if ($_ eq $value) {
330: $selout.=' selected>'.&{$functionref}($_).'</option>';
331: }
332: else {$selout.='>'.&{$functionref}($_).'</option>';}
333: }
334: return $selout.'</select>';
335: }
336:
1.54 www 337: sub relatedfield {
338: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
1.65 matthew 339: if (! $relatedsearchflag) {
340: return '';
341: }
342: if (! defined($relatedsep)) {
343: $relatedsep=' ';
344: }
345: if (! $show) {
346: return $relatedsep.' ';
347: }
1.54 www 348: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
349: ($relatedvalue?' checked="1"':'').' />';
350: }
1.48 www 351:
1.46 www 352: sub prettyinput {
1.54 www 353: my ($type,$value,$fieldname,$formname,
1.74 matthew 354: $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
1.75 matthew 355: if (! defined($size)) {
356: $size = 80;
357: }
1.64 matthew 358: # Language
1.48 www 359: if ($type eq 'language') {
360: return &selectbox($fieldname,
361: $value,
362: \&Apache::loncommon::languagedescription,
1.54 www 363: (&Apache::loncommon::languageids)).
1.64 matthew 364: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 365: }
1.64 matthew 366: # Copyright
1.48 www 367: if ($type eq 'copyright') {
368: return &selectbox($fieldname,
369: $value,
370: \&Apache::loncommon::copyrightdescription,
1.54 www 371: (&Apache::loncommon::copyrightids)).
1.64 matthew 372: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 373: }
1.78 ! taceyjo1 374: # Source Copyright
! 375: if ($type eq 'sourceavail') {
! 376: return &selectbox($fieldname,
! 377: $value,
! 378: \&Apache::loncommon::source_copyrightdescription,
! 379: (&Apache::loncommon::source_copyrightids)).
! 380: &relatedfield(0,$relatedsearchflag,$relatedsep);
! 381: }
1.64 matthew 382: # Gradelevels
1.48 www 383: if (($type eq 'lowestgradelevel') ||
384: ($type eq 'highestgradelevel')) {
1.54 www 385: return &Apache::loncommon::select_level_form($value,$fieldname).
1.64 matthew 386: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 387: }
1.64 matthew 388: # Obsolete
1.48 www 389: if ($type eq 'obsolete') {
390: return '<input type="checkbox" name="'.$fieldname.'"'.
1.54 www 391: ($value?' checked="1"':'').' />'.
1.64 matthew 392: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 393: }
1.64 matthew 394: # Obsolete replacement file
1.48 www 395: if ($type eq 'obsoletereplacement') {
396: return '<input type="text" name="'.$fieldname.
397: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
398: "('".$formname."','".$fieldname."'".
1.54 www 399: ",'')\">".&mt('Select').'</a>'.
1.64 matthew 400: &relatedfield(0,$relatedsearchflag,$relatedsep);
401: }
402: # Customdistribution file
1.48 www 403: if ($type eq 'customdistributionfile') {
404: return '<input type="text" name="'.$fieldname.
405: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
406: "('".$formname."','".$fieldname."'".
1.54 www 407: ",'rights')\">".&mt('Select').'</a>'.
1.64 matthew 408: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 409: }
1.78 ! taceyjo1 410: # Source Customdistribution file
! 411: if ($type eq 'sourcerights') {
! 412: return '<input type="text" name="'.$fieldname.
! 413: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
! 414: "('".$formname."','".$fieldname."'".
! 415: ",'rights')\">".&mt('Select').'</a>'.
! 416: &relatedfield(0,$relatedsearchflag,$relatedsep);
! 417: }
1.64 matthew 418: # Dates
1.48 www 419: if (($type eq 'creationdate') ||
420: ($type eq 'lastrevisiondate')) {
1.64 matthew 421: return
422: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
423: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 424: }
1.64 matthew 425: # No pretty input found
1.48 www 426: $value=~s/^\s+//gs;
427: $value=~s/\s+$//gs;
428: $value=~s/\s+/ /gs;
1.77 matthew 429: $value=~s/\"/\"\;/gs;
1.54 www 430: return
1.74 matthew 431: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
1.64 matthew 432: 'value="'.$value.'" />'.
433: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
434: $relatedvalue);
1.46 www 435: }
436:
1.64 matthew 437: # Main Handler
1.1 www 438: sub handler {
1.64 matthew 439: my $r=shift;
440: #
1.67 matthew 441: my $uri=$r->uri;
442: #
443: # Set document type
444: &Apache::loncommon::content_type($r,'text/html');
445: $r->send_http_header;
446: return OK if $r->header_only;
1.64 matthew 447: #
1.76 matthew 448: my ($resdomain,$resuser)=
449: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
1.67 matthew 450: $r->print('<html><head><title>'.
451: 'Catalog Information'.
452: '</title></head>');
1.66 matthew 453: if ($uri=~m:/adm/bombs/(.*)$:) {
1.67 matthew 454: $r->print(&Apache::loncommon::bodytag('Error Messages'));
1.66 matthew 455: # Looking for all bombs?
456: &report_bombs($r,$uri);
457: } elsif ($uri=~/^\/\~/) {
458: # Construction space
1.67 matthew 459: $r->print(&Apache::loncommon::bodytag
460: ('Edit Catalog Information','','','',$resdomain));
1.66 matthew 461: &present_editable_metadata($r,$uri);
462: } else {
1.67 matthew 463: $r->print(&Apache::loncommon::bodytag
464: ('Catalog Information','','','',$resdomain));
1.66 matthew 465: &present_uneditable_metadata($r,$uri);
466: }
1.67 matthew 467: $r->print('</body></html>');
1.66 matthew 468: return OK;
469: }
470:
1.67 matthew 471: #####################################################
472: #####################################################
473: ### ###
474: ### Report Bombs ###
475: ### ###
476: #####################################################
477: #####################################################
1.66 matthew 478: sub report_bombs {
479: my ($r,$uri) = @_;
480: # Set document type
1.67 matthew 481: $uri =~ s:/adm/bombs/::;
482: $uri = &Apache::lonnet::declutter($uri);
1.66 matthew 483: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
484: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
485: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
1.67 matthew 486: my %brokenurls =
487: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
488: foreach (sort(keys(%brokenurls))) {
1.66 matthew 489: if ($_=~/^\Q$uri\E/) {
1.70 matthew 490: $r->print
491: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
492: &Apache::lonmsg::retrieve_author_res_msg($_).
493: '<hr />');
1.64 matthew 494: }
495: }
1.66 matthew 496: } else {
497: $r->print(&mt('Not authorized'));
498: }
499: return;
500: }
501:
1.67 matthew 502: #####################################################
503: #####################################################
504: ### ###
505: ### Uneditable Metadata Display ###
506: ### ###
507: #####################################################
508: #####################################################
1.66 matthew 509: sub present_uneditable_metadata {
510: my ($r,$uri) = @_;
511: #
512: my %content=();
513: # Read file
514: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
515: $content{$_}=&Apache::lonnet::metadata($uri,$_);
516: }
517: # Render Output
518: # displayed url
519: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
520: $uri=~s/\.meta$//;
521: my $disuri=&Apache::lonnet::clutter($uri);
522: # version
523: my $currentversion=&Apache::lonnet::getversion($disuri);
524: my $versiondisplay='';
525: if ($thisversion) {
526: $versiondisplay=&mt('Version').': '.$thisversion.
527: ' ('.&mt('most recent version').': '.
528: ($currentversion>0 ?
529: $currentversion :
530: &mt('information not available')).')';
531: } else {
532: $versiondisplay='Version: '.$currentversion;
533: }
1.72 matthew 534: # crumbify displayed URL uri target prefix form size
535: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
536: $disuri =~ s:<br />::g;
1.66 matthew 537: # obsolete
538: my $obsolete=$content{'obsolete'};
539: my $obsoletewarning='';
540: if (($obsolete) && ($ENV{'user.adv'})) {
541: $obsoletewarning='<p><font color="red">'.
542: &mt('This resource has been marked obsolete by the author(s)').
543: '</font></p>';
544: }
545: #
546: my %lt=&fieldnames();
547: my $table='';
1.72 matthew 548: my $title = $content{'title'};
549: if (! defined($title)) {
550: $title = 'Untitled Resource';
551: }
1.66 matthew 552: foreach ('title',
553: 'author',
554: 'subject',
555: 'keywords',
556: 'notes',
557: 'abstract',
558: 'lowestgradelevel',
559: 'highestgradelevel',
560: 'standards',
561: 'mime',
562: 'language',
563: 'creationdate',
564: 'lastrevisiondate',
565: 'owner',
566: 'copyright',
1.78 ! taceyjo1 567: 'customdistributionfile',
! 568: 'sourceavail',
! 569: 'sourcerights',
1.66 matthew 570: 'obsolete',
571: 'obsoletereplacement') {
572: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
573: '</td><td bgcolor="#CCCCCC">'.
574: &prettyprint($_,$content{$_}).'</td></tr>';
575: delete $content{$_};
576: }
577: #
578: $r->print(<<ENDHEAD);
1.72 matthew 579: <h2>$title</h2>
580: <p>
581: $disuri<br />
1.36 www 582: $obsoletewarning
1.72 matthew 583: $versiondisplay
584: </p>
1.11 www 585: <table cellspacing=2 border=0>
1.45 www 586: $table
1.11 www 587: </table>
1.1 www 588: ENDHEAD
1.66 matthew 589: if ($ENV{'user.adv'}) {
1.68 matthew 590: &print_dynamic_metadata($r,$uri,\%content);
1.67 matthew 591: }
592: return;
593: }
594:
595: sub print_dynamic_metadata {
1.68 matthew 596: my ($r,$uri,$content) = @_;
597: #
1.69 matthew 598: my %content = %$content;
1.68 matthew 599: my %lt=&fieldnames();
1.67 matthew 600: #
601: my $description = 'Dynamic Metadata (updated periodically)';
602: $r->print('<h3>'.&mt($description).'</h3>'.
1.70 matthew 603: &mt('Processing'));
1.67 matthew 604: $r->rflush();
605: my %items=&fieldnames();
606: my %dynmeta=&dynamicmeta($uri);
1.73 matthew 607: &Apache::lonnet::logthis('dynamic metadata keys:'.$/.
608: join("\n",keys(%dynmeta)));
1.67 matthew 609: #
610: # General Access and Usage Statistics
1.70 matthew 611: if (exists($dynmeta{'count'}) ||
612: exists($dynmeta{'sequsage'}) ||
613: exists($dynmeta{'comefrom'}) ||
614: exists($dynmeta{'goto'}) ||
615: exists($dynmeta{'course'})) {
616: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
617: '<table cellspacing=2 border=0>');
618: foreach ('count',
619: 'sequsage','sequsage_list',
620: 'comefrom','comefrom_list',
621: 'goto','goto_list',
622: 'course','course_list') {
623: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
624: '<td bgcolor="#CCCCCC">'.
625: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
626: }
627: $r->print('</table>');
628: } else {
629: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
1.67 matthew 630: }
1.69 matthew 631: #
632: # Assessment statistics
1.73 matthew 633: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
634: if (exists($dynmeta{'stdno'}) ||
635: exists($dynmeta{'avetries'}) ||
636: exists($dynmeta{'difficulty'}) ||
637: exists($dynmeta{'disc'})) {
638: # This is an assessment, print assessment data
639: $r->print('<h4>'.
640: &mt('Overall Assessment Statistical Data').
641: '</h4>'.
642: '<table cellspacing=2 border=0>');
643: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
1.66 matthew 644: '<td bgcolor="#CCCCCC">'.
1.73 matthew 645: &prettyprint('stdno',$dynmeta{'stdno'}).
646: '</td>'."</tr>\n");
647: foreach ('avetries','difficulty','disc') {
648: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
649: '<td bgcolor="#CCCCCC">'.
650: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
651: '</td>'."</tr>\n");
652: }
653: $r->print('</table>');
654: }
655: if (exists($dynmeta{'stats'})) {
656: #
657: # New assessment statistics
658: $r->print('<h4>'.
659: &mt('Detailed Assessment Statistical Data').
660: '</h4>');
661: my $table = '<table cellspacing=2 border=0>'.
662: '<tr>'.
663: '<th>Course</th>'.
664: '<th>Section(s)</th>'.
665: '<th>Num Students</th>'.
666: '<th>Mean Tries</th>'.
667: '<th>Degree of Difficulty</th>'.
668: '<th>Degree of Discrimination</th>'.
669: '<th>Time of computation</th>'.
670: '</tr>'.$/;
671: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
672: my $data = $dynmeta{'stats'}->{$identifier};
673: my $course = $data->{'course'};
674: my %courseinfo = &Apache::lonnet::coursedescription($course);
675: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
676: &Apache::lonnet::logthis('lookup for '.$course.' failed');
677: next;
678: }
679: $table .= '<tr>';
680: $table .=
681: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
682: $table .=
683: '<td align="right">'.$data->{'sections'}.'</td>';
684: $table .=
685: '<td align="right">'.$data->{'stdno'}.'</td>';
686: foreach ('avetries','difficulty','disc') {
687: $table .= '<td align="right">';
688: if (exists($data->{$_})) {
689: $table .= sprintf('%.2f',$data->{$_}).' ';
690: } else {
691: $table .= '';
692: }
693: $table .= '</td>';
694: }
695: $table .=
696: '<td><nobr>'.
697: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
698: '</nobr></td>';
699: $table .=
700: '</tr>'.$/;
701: }
702: $table .= '</table>'.$/;
703: $r->print($table);
704: } else {
705: $r->print('No new dynamic data found.');
1.66 matthew 706: }
1.70 matthew 707: } else {
1.73 matthew 708: $r->print('<h4>'.
709: &mt('No Assessment Statistical Data is available for this resource').
710: '</h4>');
1.67 matthew 711: }
1.73 matthew 712:
713: #
714: #
1.70 matthew 715: if (exists($dynmeta{'clear'}) ||
716: exists($dynmeta{'depth'}) ||
717: exists($dynmeta{'helpful'}) ||
718: exists($dynmeta{'correct'}) ||
719: exists($dynmeta{'technical'})){
720: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
721: '<table cellspacing=2 border=0>');
722: foreach ('clear','depth','helpful','correct','technical') {
723: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
724: '<td bgcolor="#CCCCCC">'.
725: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
726: }
727: $r->print('</table>');
728: } else {
729: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1.67 matthew 730: }
731: $uri=~/^\/res\/(\w+)\/(\w+)\//;
732: if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
733: || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
1.70 matthew 734: if (exists($dynmeta{'comments'})) {
735: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
736: &mt('visible to author and co-authors only').
737: ')</h4>'.
738: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
739: } else {
740: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
741: }
742: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
743: if (defined($bombs) && $bombs ne '') {
744: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
745: &mt('visible to author and co-authors only').')'.
746: '</h4>'.$bombs);
747: } else {
748: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
749: }
1.67 matthew 750: }
1.69 matthew 751: #
1.67 matthew 752: # All other stuff
753: $r->print('<h3>'.
754: &mt('Additional Metadata (non-standard, parameters, exports)').
755: '</h3>');
756: foreach (sort(keys(%content))) {
757: my $name=$_;
758: if ($name!~/\.display$/) {
759: my $display=&Apache::lonnet::metadata($uri,
760: $name.'.display');
761: if (! $display) {
762: $display=$name;
763: };
764: my $otherinfo='';
765: foreach ('name','part','type','default') {
766: if (defined(&Apache::lonnet::metadata($uri,
767: $name.'.'.$_))) {
768: $otherinfo.=' '.$_.'='.
769: &Apache::lonnet::metadata($uri,
770: $name.'.'.$_).'; ';
771: }
1.64 matthew 772: }
1.67 matthew 773: $r->print('<b>'.$display.':</b> '.$content{$name});
774: if ($otherinfo) {
775: $r->print(' ('.$otherinfo.')');
1.64 matthew 776: }
1.67 matthew 777: $r->print("<br />\n");
1.64 matthew 778: }
1.66 matthew 779: }
1.67 matthew 780: return;
1.66 matthew 781: }
782:
1.67 matthew 783: #####################################################
784: #####################################################
785: ### ###
786: ### Editable metadata display ###
787: ### ###
788: #####################################################
789: #####################################################
1.66 matthew 790: sub present_editable_metadata {
791: my ($r,$uri) = @_;
792: # Construction Space Call
793: # Header
794: my $disuri=$uri;
795: my $fn=&Apache::lonnet::filelocation('',$uri);
796: $disuri=~s/^\/\~/\/priv\//;
797: $disuri=~s/\.meta$//;
798: my $target=$uri;
799: $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
800: $target=~s/\.meta$//;
801: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
802: if ($bombs) {
803: if ($ENV{'form.delmsg'}) {
804: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
805: $bombs=&mt('Messages deleted.');
806: } else {
807: $bombs=&mt('Error deleting messages');
1.64 matthew 808: }
1.66 matthew 809: }
810: my $del=&mt('Delete Messages');
811: $r->print(<<ENDBOMBS);
1.52 www 812: <h1>$disuri</h1>
813: <form method="post" name="defaultmeta">
1.59 www 814: <input type="submit" name="delmsg" value="$del" />
1.52 www 815: <br />$bombs
816: ENDBOMBS
1.66 matthew 817: } else {
818: my $displayfile='Catalog Information for '.$disuri;
819: if ($disuri=~/\/default$/) {
820: my $dir=$disuri;
821: $dir=~s/default$//;
822: $displayfile=
823: &mt('Default Cataloging Information for Directory').' '.
824: $dir;
825: }
826: my $bodytag=
827: &Apache::loncommon::bodytag('Edit Catalog Information');
828: %Apache::lonpublisher::metadatafields=();
829: %Apache::lonpublisher::metadatakeys=();
830: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
831: $r->print(<<ENDEDIT);
1.23 www 832: <html><head><title>Edit Catalog Information</title></head>
833: $bodytag
834: <h1>$displayfile</h1>
1.48 www 835: <form method="post" name="defaultmeta">
1.23 www 836: ENDEDIT
1.66 matthew 837: $r->print('<script language="JavaScript">'.
838: &Apache::loncommon::browser_and_searcher_javascript.
839: '</script>');
840: my %lt=&fieldnames();
841: foreach ('author','title','subject','keywords','abstract','notes',
842: 'copyright','customdistributionfile','language',
843: 'standards',
1.78 ! taceyjo1 844: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1.66 matthew 845: 'obsolete','obsoletereplacement') {
846: if (defined($ENV{'form.new_'.$_})) {
847: $Apache::lonpublisher::metadatafields{$_}=
848: $ENV{'form.new_'.$_};
849: }
850: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
851: $Apache::lonpublisher::metadatafields{'copyright'}=
852: 'default';
1.64 matthew 853: }
1.66 matthew 854: $r->print('<p>'.$lt{$_}.': '.
855: &prettyinput
856: ($_,$Apache::lonpublisher::metadatafields{$_},
857: 'new_'.$_,'defaultmeta').'</p>');
858: }
859: if ($ENV{'form.store'}) {
860: my $mfh;
861: if (! ($mfh=Apache::File->new('>'.$fn))) {
862: $r->print('<p><font color=red>'.
863: &mt('Could not write metadata').', '.
864: &mt('FAIL').'</font>');
865: } else {
866: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1.67 matthew 867: next if ($_ =~ /\./);
868: my $unikey=$_;
869: $unikey=~/^([A-Za-z]+)/;
870: my $tag=$1;
871: $tag=~tr/A-Z/a-z/;
872: print $mfh "\n\<$tag";
873: foreach (split(/\,/,
1.64 matthew 874: $Apache::lonpublisher::metadatakeys{$unikey})
1.67 matthew 875: ) {
876: my $value=
877: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
878: $value=~s/\"/\'\'/g;
879: print $mfh ' '.$_.'="'.$value.'"';
1.64 matthew 880: }
1.67 matthew 881: print $mfh '>'.
882: &HTML::Entities::encode
883: ($Apache::lonpublisher::metadatafields{$unikey},
884: '<>&"').
885: '</'.$tag.'>';
1.64 matthew 886: }
1.66 matthew 887: $r->print('<p>'.&mt('Wrote Metadata'));
1.64 matthew 888: }
889: }
1.66 matthew 890: $r->print('<br /><input type="submit" name="store" value="'.
1.67 matthew 891: &mt('Store Catalog Information').'">');
1.64 matthew 892: }
1.67 matthew 893: $r->print('</form>');
1.66 matthew 894: return;
1.1 www 895: }
1.64 matthew 896:
1.1 www 897: 1;
898: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>