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