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