Annotation of loncom/interface/lonmeta.pm, revision 1.79
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.79 ! matthew 4: # $Id: lonmeta.pm,v 1.78 2004/06/11 02:21:45 taceyjo1 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);
607: #
608: # General Access and Usage Statistics
1.70 matthew 609: if (exists($dynmeta{'count'}) ||
610: exists($dynmeta{'sequsage'}) ||
611: exists($dynmeta{'comefrom'}) ||
612: exists($dynmeta{'goto'}) ||
613: exists($dynmeta{'course'})) {
614: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
615: '<table cellspacing=2 border=0>');
616: foreach ('count',
617: 'sequsage','sequsage_list',
618: 'comefrom','comefrom_list',
619: 'goto','goto_list',
620: 'course','course_list') {
621: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
622: '<td bgcolor="#CCCCCC">'.
623: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
624: }
625: $r->print('</table>');
626: } else {
627: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
1.67 matthew 628: }
1.69 matthew 629: #
630: # Assessment statistics
1.73 matthew 631: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
632: if (exists($dynmeta{'stdno'}) ||
633: exists($dynmeta{'avetries'}) ||
634: exists($dynmeta{'difficulty'}) ||
635: exists($dynmeta{'disc'})) {
636: # This is an assessment, print assessment data
637: $r->print('<h4>'.
638: &mt('Overall Assessment Statistical Data').
639: '</h4>'.
640: '<table cellspacing=2 border=0>');
641: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
1.66 matthew 642: '<td bgcolor="#CCCCCC">'.
1.73 matthew 643: &prettyprint('stdno',$dynmeta{'stdno'}).
644: '</td>'."</tr>\n");
645: foreach ('avetries','difficulty','disc') {
646: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
647: '<td bgcolor="#CCCCCC">'.
648: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
649: '</td>'."</tr>\n");
650: }
651: $r->print('</table>');
652: }
653: if (exists($dynmeta{'stats'})) {
654: #
655: # New assessment statistics
656: $r->print('<h4>'.
657: &mt('Detailed Assessment Statistical Data').
658: '</h4>');
659: my $table = '<table cellspacing=2 border=0>'.
660: '<tr>'.
661: '<th>Course</th>'.
662: '<th>Section(s)</th>'.
663: '<th>Num Students</th>'.
664: '<th>Mean Tries</th>'.
665: '<th>Degree of Difficulty</th>'.
666: '<th>Degree of Discrimination</th>'.
667: '<th>Time of computation</th>'.
668: '</tr>'.$/;
669: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
670: my $data = $dynmeta{'stats'}->{$identifier};
671: my $course = $data->{'course'};
672: my %courseinfo = &Apache::lonnet::coursedescription($course);
673: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
674: &Apache::lonnet::logthis('lookup for '.$course.' failed');
675: next;
676: }
677: $table .= '<tr>';
678: $table .=
679: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
680: $table .=
681: '<td align="right">'.$data->{'sections'}.'</td>';
682: $table .=
683: '<td align="right">'.$data->{'stdno'}.'</td>';
684: foreach ('avetries','difficulty','disc') {
685: $table .= '<td align="right">';
686: if (exists($data->{$_})) {
687: $table .= sprintf('%.2f',$data->{$_}).' ';
688: } else {
689: $table .= '';
690: }
691: $table .= '</td>';
692: }
693: $table .=
694: '<td><nobr>'.
695: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
696: '</nobr></td>';
697: $table .=
698: '</tr>'.$/;
699: }
700: $table .= '</table>'.$/;
701: $r->print($table);
702: } else {
703: $r->print('No new dynamic data found.');
1.66 matthew 704: }
1.70 matthew 705: } else {
1.73 matthew 706: $r->print('<h4>'.
707: &mt('No Assessment Statistical Data is available for this resource').
708: '</h4>');
1.67 matthew 709: }
1.73 matthew 710:
711: #
712: #
1.70 matthew 713: if (exists($dynmeta{'clear'}) ||
714: exists($dynmeta{'depth'}) ||
715: exists($dynmeta{'helpful'}) ||
716: exists($dynmeta{'correct'}) ||
717: exists($dynmeta{'technical'})){
718: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
719: '<table cellspacing=2 border=0>');
720: foreach ('clear','depth','helpful','correct','technical') {
721: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
722: '<td bgcolor="#CCCCCC">'.
723: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
724: }
725: $r->print('</table>');
726: } else {
727: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1.67 matthew 728: }
729: $uri=~/^\/res\/(\w+)\/(\w+)\//;
730: if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
731: || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
1.70 matthew 732: if (exists($dynmeta{'comments'})) {
733: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
734: &mt('visible to author and co-authors only').
735: ')</h4>'.
736: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
737: } else {
738: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
739: }
740: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
741: if (defined($bombs) && $bombs ne '') {
742: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
743: &mt('visible to author and co-authors only').')'.
744: '</h4>'.$bombs);
745: } else {
746: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
747: }
1.67 matthew 748: }
1.69 matthew 749: #
1.67 matthew 750: # All other stuff
751: $r->print('<h3>'.
752: &mt('Additional Metadata (non-standard, parameters, exports)').
753: '</h3>');
754: foreach (sort(keys(%content))) {
755: my $name=$_;
756: if ($name!~/\.display$/) {
757: my $display=&Apache::lonnet::metadata($uri,
758: $name.'.display');
759: if (! $display) {
760: $display=$name;
761: };
762: my $otherinfo='';
763: foreach ('name','part','type','default') {
764: if (defined(&Apache::lonnet::metadata($uri,
765: $name.'.'.$_))) {
766: $otherinfo.=' '.$_.'='.
767: &Apache::lonnet::metadata($uri,
768: $name.'.'.$_).'; ';
769: }
1.64 matthew 770: }
1.67 matthew 771: $r->print('<b>'.$display.':</b> '.$content{$name});
772: if ($otherinfo) {
773: $r->print(' ('.$otherinfo.')');
1.64 matthew 774: }
1.67 matthew 775: $r->print("<br />\n");
1.64 matthew 776: }
1.66 matthew 777: }
1.67 matthew 778: return;
1.66 matthew 779: }
780:
1.67 matthew 781: #####################################################
782: #####################################################
783: ### ###
784: ### Editable metadata display ###
785: ### ###
786: #####################################################
787: #####################################################
1.66 matthew 788: sub present_editable_metadata {
789: my ($r,$uri) = @_;
790: # Construction Space Call
791: # Header
792: my $disuri=$uri;
793: my $fn=&Apache::lonnet::filelocation('',$uri);
794: $disuri=~s/^\/\~/\/priv\//;
795: $disuri=~s/\.meta$//;
796: my $target=$uri;
797: $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
798: $target=~s/\.meta$//;
799: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
800: if ($bombs) {
801: if ($ENV{'form.delmsg'}) {
802: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
803: $bombs=&mt('Messages deleted.');
804: } else {
805: $bombs=&mt('Error deleting messages');
1.64 matthew 806: }
1.66 matthew 807: }
808: my $del=&mt('Delete Messages');
809: $r->print(<<ENDBOMBS);
1.52 www 810: <h1>$disuri</h1>
811: <form method="post" name="defaultmeta">
1.59 www 812: <input type="submit" name="delmsg" value="$del" />
1.52 www 813: <br />$bombs
814: ENDBOMBS
1.66 matthew 815: } else {
816: my $displayfile='Catalog Information for '.$disuri;
817: if ($disuri=~/\/default$/) {
818: my $dir=$disuri;
819: $dir=~s/default$//;
820: $displayfile=
821: &mt('Default Cataloging Information for Directory').' '.
822: $dir;
823: }
824: my $bodytag=
825: &Apache::loncommon::bodytag('Edit Catalog Information');
826: %Apache::lonpublisher::metadatafields=();
827: %Apache::lonpublisher::metadatakeys=();
828: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
829: $r->print(<<ENDEDIT);
1.23 www 830: <html><head><title>Edit Catalog Information</title></head>
831: $bodytag
832: <h1>$displayfile</h1>
1.48 www 833: <form method="post" name="defaultmeta">
1.23 www 834: ENDEDIT
1.66 matthew 835: $r->print('<script language="JavaScript">'.
836: &Apache::loncommon::browser_and_searcher_javascript.
837: '</script>');
838: my %lt=&fieldnames();
839: foreach ('author','title','subject','keywords','abstract','notes',
840: 'copyright','customdistributionfile','language',
841: 'standards',
1.78 taceyjo1 842: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1.66 matthew 843: 'obsolete','obsoletereplacement') {
844: if (defined($ENV{'form.new_'.$_})) {
845: $Apache::lonpublisher::metadatafields{$_}=
846: $ENV{'form.new_'.$_};
847: }
848: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
849: $Apache::lonpublisher::metadatafields{'copyright'}=
850: 'default';
1.64 matthew 851: }
1.66 matthew 852: $r->print('<p>'.$lt{$_}.': '.
853: &prettyinput
854: ($_,$Apache::lonpublisher::metadatafields{$_},
855: 'new_'.$_,'defaultmeta').'</p>');
856: }
857: if ($ENV{'form.store'}) {
858: my $mfh;
859: if (! ($mfh=Apache::File->new('>'.$fn))) {
860: $r->print('<p><font color=red>'.
861: &mt('Could not write metadata').', '.
862: &mt('FAIL').'</font>');
863: } else {
864: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1.67 matthew 865: next if ($_ =~ /\./);
866: my $unikey=$_;
867: $unikey=~/^([A-Za-z]+)/;
868: my $tag=$1;
869: $tag=~tr/A-Z/a-z/;
870: print $mfh "\n\<$tag";
871: foreach (split(/\,/,
1.64 matthew 872: $Apache::lonpublisher::metadatakeys{$unikey})
1.67 matthew 873: ) {
874: my $value=
875: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
876: $value=~s/\"/\'\'/g;
877: print $mfh ' '.$_.'="'.$value.'"';
1.64 matthew 878: }
1.67 matthew 879: print $mfh '>'.
880: &HTML::Entities::encode
881: ($Apache::lonpublisher::metadatafields{$unikey},
882: '<>&"').
883: '</'.$tag.'>';
1.64 matthew 884: }
1.66 matthew 885: $r->print('<p>'.&mt('Wrote Metadata'));
1.64 matthew 886: }
887: }
1.66 matthew 888: $r->print('<br /><input type="submit" name="store" value="'.
1.67 matthew 889: &mt('Store Catalog Information').'">');
1.64 matthew 890: }
1.67 matthew 891: $r->print('</form>');
1.66 matthew 892: return;
1.1 www 893: }
1.64 matthew 894:
1.1 www 895: 1;
896: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>