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