Annotation of loncom/interface/lonmeta.pm, revision 1.65
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.65 ! matthew 4: # $Id: lonmeta.pm,v 1.64 2004/04/13 14:42:24 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: # MySQL table columns
44:
45: my @columns;
46:
1.64 matthew 47: # Fetch and evaluate dynamic metadata
1.9 www 48: sub dynamicmeta {
49: my $url=&Apache::lonnet::declutter(shift);
50: $url=~s/\.meta$//;
51: my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
1.19 www 52: my $regexp=$url;
1.9 www 53: $regexp=~s/(\W)/\\$1/g;
1.10 www 54: $regexp='___'.$regexp.'___';
1.16 albertel 55: my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
56: $aauthor,$regexp);
1.63 matthew 57: my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
58: my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
59: \%DynamicData);
1.40 matthew 60: #
1.46 www 61: # Deal with 'count' separately
1.63 matthew 62: $Data{'count'} = &access_count($url,$aauthor,$adomain);
63: return %Data;
1.40 matthew 64: }
65:
66: sub access_count {
67: my ($src,$author,$adomain) = @_;
68: my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
69: $author,$src);
70: if (! exists($countdata{$src})) {
1.47 www 71: return &mt('Not Available');
1.40 matthew 72: } else {
73: return $countdata{$src};
74: }
1.25 www 75: }
76:
1.64 matthew 77: # Try to make an alt tag if there is none
1.25 www 78: sub alttag {
1.26 www 79: my ($base,$src)=@_;
80: my $fullpath=&Apache::lonnet::hreflocation($base,$src);
81: my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
1.64 matthew 82: &Apache::lonnet::metadata($fullpath,'subject').' '.
83: &Apache::lonnet::metadata($fullpath,'abstract');
1.26 www 84: $alttag=~s/\s+/ /gs;
85: $alttag=~s/\"//gs;
86: $alttag=~s/\'//gs;
87: $alttag=~s/\s+$//gs;
88: $alttag=~s/^\s+//gs;
1.64 matthew 89: if ($alttag) {
90: return $alttag;
91: } else {
92: return &mt('No information available');
93: }
1.9 www 94: }
1.1 www 95:
1.64 matthew 96: # Author display
1.29 www 97: sub authordisplay {
98: my ($aname,$adom)=@_;
1.64 matthew 99: return &Apache::loncommon::aboutmewrapper
100: (&Apache::loncommon::plainname($aname,$adom),
101: $aname,$adom,'preview').' <tt>['.$aname.'@'.$adom.']</tt>';
1.29 www 102: }
103:
1.64 matthew 104: # Pretty display
1.12 www 105: sub evalgraph {
106: my $value=shift;
1.65 ! matthew 107: if (! $value) {
! 108: return '';
! 109: }
1.12 www 110: my $val=int($value*10.+0.5)-10;
111: my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
112: if ($val>=20) {
113: $output.='<td width=20 bgcolor="#555555">  </td>';
114: } else {
115: $output.='<td width='.($val).' bgcolor="#555555"> </td>'.
116: '<td width='.(20-$val).' bgcolor="#FF3333"> </td>';
117: }
118: $output.='<td bgcolor="#FFFF33"> </td>';
119: if ($val>20) {
120: $output.='<td width='.($val-20).' bgcolor="#33FF33"> </td>'.
121: '<td width='.(40-$val).' bgcolor="#555555"> </td>';
122: } else {
1.64 matthew 123: $output.='<td width=20 bgcolor="#555555">  </td>';
1.12 www 124: }
125: $output.='<td> ('.$value.') </td></tr></table>';
126: return $output;
127: }
128:
129: sub diffgraph {
130: my $value=shift;
1.65 ! matthew 131: if (! $value) {
! 132: return '';
! 133: }
1.12 www 134: my $val=int(40.0*$value+0.5);
1.13 www 135: my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
136: '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
1.12 www 137: my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
138: for (my $i=0;$i<8;$i++) {
139: if ($val>$i*5) {
140: $output.='<td width=5 bgcolor="'.$colors[$i].'"> </td>';
141: } else {
142: $output.='<td width=5 bgcolor="#555555"> </td>';
143: }
144: }
145: $output.='<td> ('.$value.') </td></tr></table>';
146: return $output;
147: }
148:
1.64 matthew 149: # Turn MySQL row into hash
1.44 www 150: sub metadata_col_to_hash {
151: my @cols=@_;
152: my %hash=();
153: for (my $i=0; $i<=$#columns; $i++) {
154: $hash{$columns[$i]}=$cols[$i];
155: }
156: return %hash;
157: }
158:
1.64 matthew 159: # The field names
1.45 www 160: sub fieldnames {
1.64 matthew 161: return &Apache::lonlocal::texthash
162: (
163: 'title' => 'Title',
164: 'author' =>'Author(s)',
165: 'authorspace' => 'Author Space',
166: 'modifyinguser' => 'Last Modifying User',
167: 'subject' => 'Subject',
168: 'keywords' => 'Keyword(s)',
169: 'notes' => 'Notes',
170: 'abstract' => 'Abstract',
171: 'lowestgradelevel' => 'Lowest Grade Level',
172: 'highestgradelevel' => 'Highest Grade Level',
173: 'standards' => 'Standards',
174: 'mime' => 'MIME Type',
175: 'language' => 'Language',
176: 'creationdate' => 'Creation Date',
177: 'lastrevisiondate' => 'Last Revision Date',
178: 'owner' => 'Publisher/Owner',
179: 'copyright' => 'Copyright/Distribution',
180: 'customdistributionfile' => 'Custom Distribution File',
181: 'obsolete' => 'Obsolete',
182: 'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
183: 'count' => 'Network-wide number of accesses (hits)',
184: 'course' => 'Network-wide number of courses using resource',
185: 'course_list' => 'Network-wide courses using resource',
186: 'sequsage' => 'Number of resources using or importing resource',
187: 'sequsage_list' => 'Resources using or importing resource',
188: 'goto' => 'Number of resources that follow this resource in maps',
189: 'goto_list' => 'Resources that follow this resource in maps',
190: 'comefrom' => 'Number of resources that lead up to this resource in maps',
191: 'comefrom_list' => 'Resources that lead up to this resource in maps',
192: 'clear' => 'Material presented in clear way',
193: 'depth' => 'Material covered with sufficient depth',
194: 'helpful' => 'Material is helpful',
195: 'correct' => 'Material appears to be correct',
196: 'technical' => 'Resource is technically correct',
197: 'avetries' => 'Average number of tries till solved',
198: 'stdno' => 'Total number of students who have worked on this problem',
199: 'difficulty' => 'Degree of difficulty'
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.64 matthew 229: # MIME
1.46 www 230: if ($type eq 'mime') {
1.64 matthew 231: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
232: &Apache::loncommon::filedescription($value);
233: }
234: # Person
1.46 www 235: if (($type eq 'author') ||
236: ($type eq 'owner') ||
237: ($type eq 'modifyinguser') ||
238: ($type eq 'authorspace')) {
239: $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
240: return $value;
241: }
1.64 matthew 242: # Gradelevel
1.48 www 243: if (($type eq 'lowestgradelevel') ||
244: ($type eq 'highestgradelevel')) {
245: return &Apache::loncommon::gradeleveldescription($value);
246: }
1.64 matthew 247: # Only for advance users below
1.65 ! matthew 248: if (! $ENV{'user.adv'}) {
! 249: return '<i>- '.&mt('not displayed').' -</i>';
! 250: }
1.64 matthew 251: # File
1.46 www 252: if (($type eq 'customdistributionfile') ||
253: ($type eq 'obsoletereplacement') ||
254: ($type eq 'goto_list') ||
255: ($type eq 'comefrom_list') ||
256: ($type eq 'sequsage_list')) {
257: return join('<br />',map {
1.64 matthew 258: my $url=&Apache::lonnet::clutter($_);
259: '<b>'.&Apache::lonnet::gettitle($url).'</b>'.
260: &Apache::lonhtmlcommon::crumbs($url,'preview','',undef,'+0');
261: } split(/\s*\,\s*/,$value));
1.46 www 262: }
1.64 matthew 263: # Evaluations
1.46 www 264: if (($type eq 'clear') ||
265: ($type eq 'depth') ||
266: ($type eq 'helpful') ||
267: ($type eq 'correct') ||
268: ($type eq 'technical')) {
269: return &evalgraph($value);
270: }
1.64 matthew 271: # Difficulty
1.46 www 272: if ($type eq 'difficulty') {
273: return &diffgraph($value);
274: }
1.64 matthew 275: # List of courses
1.46 www 276: if ($type=~/\_list/) {
277: return join('<br />',map {
278: my %courseinfo=&Apache::lonnet::coursedescription($_);
279: '<a href="/public/'.
280: $courseinfo{'domain'}.'/'.$courseinfo{'num'}.'/syllabus" target="preview">'.
281: $courseinfo{'description'}.'</a>';
282: } split(/\s*\,\s*/,$value));
283: }
1.64 matthew 284: # No pretty print found
1.46 www 285: return $value;
286: }
287:
1.64 matthew 288: # Pretty input of metadata field
1.54 www 289: sub direct {
290: return shift;
291: }
292:
1.48 www 293: sub selectbox {
294: my ($name,$value,$functionref,@idlist)=@_;
1.65 ! matthew 295: if (! defined($functionref)) {
! 296: $functionref=\&direct;
! 297: }
1.48 www 298: my $selout='<select name="'.$name.'">';
299: foreach (@idlist) {
300: $selout.='<option value=\''.$_.'\'';
301: if ($_ eq $value) {
302: $selout.=' selected>'.&{$functionref}($_).'</option>';
303: }
304: else {$selout.='>'.&{$functionref}($_).'</option>';}
305: }
306: return $selout.'</select>';
307: }
308:
1.54 www 309: sub relatedfield {
310: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
1.65 ! matthew 311: if (! $relatedsearchflag) {
! 312: return '';
! 313: }
! 314: if (! defined($relatedsep)) {
! 315: $relatedsep=' ';
! 316: }
! 317: if (! $show) {
! 318: return $relatedsep.' ';
! 319: }
1.54 www 320: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
321: ($relatedvalue?' checked="1"':'').' />';
322: }
1.48 www 323:
1.46 www 324: sub prettyinput {
1.54 www 325: my ($type,$value,$fieldname,$formname,
326: $relatedsearchflag,$relatedsep,$relatedvalue)=@_;
1.64 matthew 327: # Language
1.48 www 328: if ($type eq 'language') {
329: return &selectbox($fieldname,
330: $value,
331: \&Apache::loncommon::languagedescription,
1.54 www 332: (&Apache::loncommon::languageids)).
1.64 matthew 333: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 334: }
1.64 matthew 335: # Copyright
1.48 www 336: if ($type eq 'copyright') {
337: return &selectbox($fieldname,
338: $value,
339: \&Apache::loncommon::copyrightdescription,
1.54 www 340: (&Apache::loncommon::copyrightids)).
1.64 matthew 341: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 342: }
1.64 matthew 343: # Gradelevels
1.48 www 344: if (($type eq 'lowestgradelevel') ||
345: ($type eq 'highestgradelevel')) {
1.54 www 346: return &Apache::loncommon::select_level_form($value,$fieldname).
1.64 matthew 347: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 348: }
1.64 matthew 349: # Obsolete
1.48 www 350: if ($type eq 'obsolete') {
351: return '<input type="checkbox" name="'.$fieldname.'"'.
1.54 www 352: ($value?' checked="1"':'').' />'.
1.64 matthew 353: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 354: }
1.64 matthew 355: # Obsolete replacement file
1.48 www 356: if ($type eq 'obsoletereplacement') {
357: return '<input type="text" name="'.$fieldname.
358: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
359: "('".$formname."','".$fieldname."'".
1.54 www 360: ",'')\">".&mt('Select').'</a>'.
1.64 matthew 361: &relatedfield(0,$relatedsearchflag,$relatedsep);
362: }
363: # Customdistribution file
1.48 www 364: if ($type eq 'customdistributionfile') {
365: return '<input type="text" name="'.$fieldname.
366: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
367: "('".$formname."','".$fieldname."'".
1.54 www 368: ",'rights')\">".&mt('Select').'</a>'.
1.64 matthew 369: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 370: }
1.64 matthew 371: # Dates
1.48 www 372: if (($type eq 'creationdate') ||
373: ($type eq 'lastrevisiondate')) {
1.64 matthew 374: return
375: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
376: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 377: }
1.64 matthew 378: # No pretty input found
1.48 www 379: $value=~s/^\s+//gs;
380: $value=~s/\s+$//gs;
381: $value=~s/\s+/ /gs;
382: $value=~s/\"/\&quod\;/gs;
1.54 www 383: return
1.64 matthew 384: '<input type="text" name="'.$fieldname.'" size="80" '.
385: 'value="'.$value.'" />'.
386: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
387: $relatedvalue);
1.46 www 388: }
389:
1.64 matthew 390: # Main Handler
1.1 www 391: sub handler {
1.64 matthew 392: my $r=shift;
393: #
1.20 www 394: my $loaderror=&Apache::lonnet::overloaderror($r);
395: if ($loaderror) { return $loaderror; }
1.64 matthew 396: #
1.20 www 397: my $uri=$r->uri;
1.64 matthew 398: #
399: # Looking for all bombs?
400: if ($uri=~/\/adm\/bombs\/(.*)$/) {
401: # Set document type
402: $uri=&Apache::lonnet::declutter($1);
403: &Apache::loncommon::content_type($r,'text/html');
404: $r->send_http_header;
405: #
406: return OK if $r->header_only;
407: $r->print(&Apache::loncommon::bodytag('Error Messages'));
408: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
409: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
410: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
411: my %brokenurls=&Apache::lonmsg::all_url_author_res_msg($author,
412: $domain);
413: foreach (sort keys %brokenurls) {
414: if ($_=~/^\Q$uri\E/) {
415: $r->print(&Apache::lonhtmlcommon::crumbs
416: (&Apache::lonnet::clutter($_)).
417: &Apache::lonmsg::retrieve_author_res_msg($_).
418: '<hr />');
419: }
420: }
421: } else {
422: $r->print(&mt('Not authorized'));
423: }
424: $r->print('</body></html>');
425: } elsif ($uri!~/^\/\~/) {
426: # This is not in construction space
427: my ($resdomain,$resuser)=
428: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
429: $loaderror=&Apache::lonnet::overloaderror
430: ($r,
431: &Apache::lonnet::homeserver($resuser,$resdomain));
432: if ($loaderror) { return $loaderror; }
433: #
434: my %content=();
435: # Set document type
436: &Apache::loncommon::content_type($r,'text/html');
437: $r->send_http_header;
438: return OK if $r->header_only;
439: # Read file
440: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
441: $content{$_}=&Apache::lonnet::metadata($uri,$_);
442: }
443: # Render Output
444: # displayed url
445: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
446: $uri=~s/\.meta$//;
447: my $disuri=&Apache::lonnet::clutter($uri);
448: # version
449: my $currentversion=&Apache::lonnet::getversion($disuri);
450: my $versiondisplay='';
451: if ($thisversion) {
452: $versiondisplay=&mt('Version').': '.$thisversion.
453: ' ('.&mt('most recent version').': '.
454: ($currentversion>0 ?
455: $currentversion :
456: &mt('information not available')).')';
457: } else {
458: $versiondisplay='Version: '.$currentversion;
459: }
460: # crumbify displayed URL
461: $disuri=&Apache::lonhtmlcommon::crumbs($disuri);
462: # obsolete
463: my $obsolete=$content{'obsolete'};
464: my $obsoletewarning='';
465: if (($obsolete) && ($ENV{'user.adv'})) {
466: $obsoletewarning='<p><font color="red">'.
467: &mt('This resource has been marked obsolete by the author(s)').
468: '</font></p>';
469: }
470: #
471: my %lt=&fieldnames();
472: my $table='';
473: my $bodytag=&Apache::loncommon::bodytag
1.45 www 474: ('Catalog Information','','','',$resdomain);
1.64 matthew 475: foreach ('title',
476: 'author',
477: 'subject',
478: 'keywords',
479: 'notes',
480: 'abstract',
481: 'lowestgradelevel',
482: 'highestgradelevel',
483: 'standards',
484: 'mime',
485: 'language',
486: 'creationdate',
487: 'lastrevisiondate',
488: 'owner',
489: 'copyright',
490: 'customdistributionfile',
491: 'obsolete',
492: 'obsoletereplacement') {
493: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
1.45 www 494: '</td><td bgcolor="#CCCCCC">'.
1.46 www 495: &prettyprint($_,$content{$_}).'</td></tr>';
1.64 matthew 496: delete $content{$_};
497: }
498: #
499: $r->print(<<ENDHEAD);
1.1 www 500: <html><head><title>Catalog Information</title></head>
1.17 www 501: $bodytag
1.1 www 502: <h2>$content{'title'}</h2>
1.11 www 503: <h3><tt>$disuri</tt></h3>
1.36 www 504: $obsoletewarning
1.21 www 505: $versiondisplay<br />
1.11 www 506: <table cellspacing=2 border=0>
1.45 www 507: $table
1.11 www 508: </table>
1.1 www 509: ENDHEAD
1.64 matthew 510: if ($ENV{'user.adv'}) {
511: # Dynamic Metadata
512: $r->print(
513: '<h3>'.&mt('Dynamic Metadata').' ('.
514: &mt('updated periodically').')</h3>'.&mt('Processing').
515: ' ...<br />');
516: $r->rflush();
517: my %items=&fieldnames();
518: my %dynmeta=&dynamicmeta($uri);
519: # General Access and Usage Statistics
520: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
521: '<table cellspacing=2 border=0>');
522: foreach ('count',
523: 'sequsage','sequsage_list',
524: 'comefrom','comefrom_list',
525: 'goto','goto_list',
526: 'course','course_list') {
527: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
528: '<td bgcolor="#CCCCCC">'.
529: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
530: }
531: $r->print('</table>');
532: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
533: # This is an assessment, print assessment data
534: $r->print(
535: '<h4>'.&mt('Assessment Statistical Data').'</h4>'.
536: '<table cellspacing=2 border=0>');
537: foreach ('stdno','avetries','difficulty') {
538: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
539: '<td bgcolor="#CCCCCC">'.
540: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
541: }
542: $r->print('</table>');
543: }
544: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
545: '<table cellspacing=2 border=0>');
546: foreach ('clear','depth','helpful','correct','technical') {
547: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
548: '<td bgcolor="#CCCCCC">'.
549: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
550: }
551: $r->print('</table>');
552: $uri=~/^\/res\/(\w+)\/(\w+)\//;
553: if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
554: || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
555: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
556: &mt('visible to author and co-authors only').
557: ')</h4>'.
558: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
559: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
560: &mt('visible to author and co-authors only').')'.
561: '</h4>'.
562: &Apache::lonmsg::retrieve_author_res_msg($uri));
563: }
564: # All other stuff
565: $r->print('<h3>'.
566: &mt('Additional Metadata (non-standard, parameters, exports)').
567: '</h3>');
568: foreach (sort keys %content) {
569: my $name=$_;
1.65 ! matthew 570: if ($name!~/\.display$/) {
1.64 matthew 571: my $display=&Apache::lonnet::metadata($uri,
572: $name.'.display');
1.65 ! matthew 573: if (! $display) {
! 574: $display=$name;
! 575: };
1.64 matthew 576: my $otherinfo='';
577: foreach ('name','part','type','default') {
578: if (defined(&Apache::lonnet::metadata($uri,
579: $name.'.'.$_))) {
580: $otherinfo.=' '.$_.'='.
581: &Apache::lonnet::metadata($uri,
582: $name.'.'.$_).'; ';
583: }
584: }
585: $r->print('<b>'.$display.':</b> '.$content{$name});
586: if ($otherinfo) {
587: $r->print(' ('.$otherinfo.')');
588: }
589: $r->print("<br />\n");
590: }
591: }
592: }
593: # End Resource Space Call
594: } else {
595: # Construction Space Call
596: # Set document type
597: &Apache::loncommon::content_type($r,'text/html');
598: $r->send_http_header;
599: #
600: return OK if $r->header_only;
601: # Header
602: my $disuri=$uri;
603: my $fn=&Apache::lonnet::filelocation('',$uri);
604: $disuri=~s/^\/\~/\/priv\//;
605: $disuri=~s/\.meta$//;
606: my $target=$uri;
607: $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
608: $target=~s/\.meta$//;
609: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
610: if ($bombs) {
611: if ($ENV{'form.delmsg'}) {
612: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
613: $bombs=&mt('Messages deleted.');
614: } else {
615: $bombs=&mt('Error deleting messages');
616: }
617: }
618: my $bodytag=&Apache::loncommon::bodytag('Error Messages');
619: my $del=&mt('Delete Messages');
620: $r->print(<<ENDBOMBS);
1.52 www 621: <html><head><title>Edit Catalog Information</title></head>
622: $bodytag
623: <h1>$disuri</h1>
624: <form method="post" name="defaultmeta">
1.59 www 625: <input type="submit" name="delmsg" value="$del" />
1.52 www 626: <br />$bombs
627: </form>
628: </body>
629: </html>
630: ENDBOMBS
1.64 matthew 631: } else {
632: my $displayfile='Catalog Information for '.$disuri;
633: if ($disuri=~/\/default$/) {
634: my $dir=$disuri;
635: $dir=~s/default$//;
636: $displayfile=
637: &mt('Default Cataloging Information for Directory').' '.
638: $dir;
639: }
640: my $bodytag=
641: &Apache::loncommon::bodytag('Edit Catalog Information');
642: %Apache::lonpublisher::metadatafields=();
643: %Apache::lonpublisher::metadatakeys=();
644: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
645: $r->print(<<ENDEDIT);
1.23 www 646: <html><head><title>Edit Catalog Information</title></head>
647: $bodytag
648: <h1>$displayfile</h1>
1.48 www 649: <form method="post" name="defaultmeta">
1.23 www 650: ENDEDIT
1.64 matthew 651: $r->print('<script language="JavaScript">'.
652: &Apache::loncommon::browser_and_searcher_javascript.
653: '</script>');
654: my %lt=&fieldnames();
655: foreach ('author','title','subject','keywords','abstract','notes',
656: 'copyright','customdistributionfile','language',
657: 'standards',
658: 'lowestgradelevel','highestgradelevel',
659: 'obsolete','obsoletereplacement') {
660: if (defined($ENV{'form.new_'.$_})) {
661: $Apache::lonpublisher::metadatafields{$_}=
662: $ENV{'form.new_'.$_};
663: }
1.65 ! matthew 664: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
1.64 matthew 665: $Apache::lonpublisher::metadatafields{'copyright'}=
666: 'default';
667: }
668: $r->print('<p>'.$lt{$_}.': '.
669: &prettyinput
670: ($_,$Apache::lonpublisher::metadatafields{$_},
671: 'new_'.$_,'defaultmeta').'</p>');
672: }
673: if ($ENV{'form.store'}) {
674: my $mfh;
1.65 ! matthew 675: if (! ($mfh=Apache::File->new('>'.$fn))) {
1.64 matthew 676: $r->print('<p><font color=red>'.
677: &mt('Could not write metadata').', '.
678: &mt('FAIL').'</font>');
679: } else {
680: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1.65 ! matthew 681: if ($_!~/\./) {
1.64 matthew 682: my $unikey=$_;
683: $unikey=~/^([A-Za-z]+)/;
684: my $tag=$1;
685: $tag=~tr/A-Z/a-z/;
686: print $mfh "\n\<$tag";
687: foreach (split(/\,/,
688: $Apache::lonpublisher::metadatakeys{$unikey})
689: ) {
690: my $value=
691: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
692: $value=~s/\"/\'\'/g;
693: print $mfh ' '.$_.'="'.$value.'"';
694: }
695: print $mfh '>'.
696: &HTML::Entities::encode($Apache::lonpublisher::metadatafields{$unikey},'<>&"').
697: '</'.$tag.'>';
698: }
699: }
700: $r->print('<p>'.&mt('Wrote Metadata'));
701: }
702: }
703: $r->print('<br /><input type="submit" name="store" value="'.
704: &mt('Store Catalog Information').'"></form>'.
705: '</body></html>');
706: }
707: }
708: return OK;
1.1 www 709: }
710:
1.64 matthew 711: # BEGIN Block
1.44 www 712: BEGIN {
1.64 matthew 713: # Get columns of MySQL metadata table
1.44 www 714: @columns=&Apache::lonmysql::col_order('metadata');
715: }
1.64 matthew 716:
1.1 www 717: 1;
718: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>