Annotation of loncom/interface/lonmeta.pm, revision 1.42
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.42 ! www 4: # $Id: lonmeta.pm,v 1.41 2003/12/22 21:44:17 www 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.1 www 27: #
28: # (TeX Content Handler
29: #
30: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
31: #
1.13 www 32: # 10/19,10/21,10/23,11/27,08/09/01,12/22,12/24,12/25 Gerd Kortemeyer
1.1 www 33:
34: package Apache::lonmeta;
35:
36: use strict;
37: use Apache::Constants qw(:common);
1.3 www 38: use Apache::lonnet();
1.10 www 39: use Apache::loncommon();
1.23 www 40: use Apache::lonmsg;
41: use Apache::lonpublisher;
1.35 www 42: use Apache::lonlocal;
1.1 www 43:
1.9 www 44: # ----------------------------------------- Fetch and evaluate dynamic metadata
45:
46: sub dynamicmeta {
47: my $url=&Apache::lonnet::declutter(shift);
48: $url=~s/\.meta$//;
49: my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
1.19 www 50: my $regexp=$url;
1.9 www 51: $regexp=~s/(\W)/\\$1/g;
1.10 www 52: $regexp='___'.$regexp.'___';
1.16 albertel 53: my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
54: $aauthor,$regexp);
1.30 www 55: my %sum=();
56: my %cnt=();
57: my %concat=();
1.40 matthew 58: my %listitems=(
1.10 www 59: 'course' => 'add',
1.29 www 60: 'goto' => 'add',
61: 'comefrom' => 'add',
1.10 www 62: 'avetries' => 'avg',
63: 'stdno' => 'add',
64: 'difficulty' => 'avg',
65: 'clear' => 'avg',
66: 'technical' => 'avg',
67: 'helpful' => 'avg',
68: 'correct' => 'avg',
69: 'depth' => 'avg',
70: 'comments' => 'app',
71: 'usage' => 'cnt'
72: );
1.39 albertel 73: while ($_=each(%evaldata)) {
74: my ($item,$purl,$cat)=split(/___/,$_);
75: ### Apache->request->print("\n".$_.' - '.$item.'<br />');
76: if (defined($cnt{$cat})) { $cnt{$cat}++; } else { $cnt{$cat}=1; }
1.30 www 77: unless ($listitems{$cat} eq 'app') {
78: if (defined($sum{$cat})) {
79: $sum{$cat}+=$evaldata{$_};
80: $concat{$cat}.=','.$item;
1.10 www 81: } else {
1.30 www 82: $sum{$cat}=$evaldata{$_};
83: $concat{$cat}=$item;
1.10 www 84: }
85: } else {
1.30 www 86: if (defined($sum{$cat})) {
1.10 www 87: if ($evaldata{$_}) {
1.30 www 88: $sum{$cat}.='<hr>'.$evaldata{$_};
1.10 www 89: }
90: } else {
1.30 www 91: $sum{$cat}=''.$evaldata{$_};
1.10 www 92: }
93: }
94: }
1.9 www 95: my %returnhash=();
1.39 albertel 96: while ($_=each(%cnt)) {
1.11 www 97: if ($listitems{$_} eq 'avg') {
98: $returnhash{$_}=int(($sum{$_}/$cnt{$_})*100.0+0.5)/100.0;
99: } elsif ($listitems{$_} eq 'cnt') {
100: $returnhash{$_}=$cnt{$_};
101: } else {
102: $returnhash{$_}=$sum{$_};
103: }
1.30 www 104: $returnhash{$_.'_list'}=$concat{$_};
1.39 albertel 105: ### Apache->request->print("\n<hr />".$_.': '.$returnhash{$_}.'<br />'.$returnhash{$_.'_list'});
1.9 www 106: }
1.40 matthew 107: #
108: # Deal with 'count' seperately
109: $returnhash{'count'} = &access_count($url,$aauthor,$adomain);
110:
1.9 www 111: return %returnhash;
1.40 matthew 112: }
113:
114: sub access_count {
115: my ($src,$author,$adomain) = @_;
116: my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
117: $author,$src);
118: if (! exists($countdata{$src})) {
119: return 'Not Available';
120: } else {
121: return $countdata{$src};
122: }
1.25 www 123: }
124:
125: # ------------------------------------- Try to make an alt tag if there is none
126:
127: sub alttag {
1.26 www 128: my ($base,$src)=@_;
129: my $fullpath=&Apache::lonnet::hreflocation($base,$src);
130: my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
131: &Apache::lonnet::metadata($fullpath,'subject').' '.
132: &Apache::lonnet::metadata($fullpath,'abstract');
133: $alttag=~s/\s+/ /gs;
134: $alttag=~s/\"//gs;
135: $alttag=~s/\'//gs;
136: $alttag=~s/\s+$//gs;
137: $alttag=~s/^\s+//gs;
138: if ($alttag) { return $alttag; } else
139: { return 'No information available'; }
1.9 www 140: }
1.1 www 141:
1.29 www 142: # -------------------------------------------------------------- Author display
143:
144: sub authordisplay {
145: my ($aname,$adom)=@_;
146: return &Apache::loncommon::aboutmewrapper(
147: &Apache::loncommon::plainname($aname,$adom),
148: $aname,$adom).' <tt>['.$aname.'@'.$adom.']</tt>';
149: }
150:
1.12 www 151: # -------------------------------------------------------------- Pretty display
152:
153: sub evalgraph {
154: my $value=shift;
1.13 www 155: unless ($value) { return ''; }
1.12 www 156: my $val=int($value*10.+0.5)-10;
157: my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
158: if ($val>=20) {
159: $output.='<td width=20 bgcolor="#555555">  </td>';
160: } else {
161: $output.='<td width='.($val).' bgcolor="#555555"> </td>'.
162: '<td width='.(20-$val).' bgcolor="#FF3333"> </td>';
163: }
164: $output.='<td bgcolor="#FFFF33"> </td>';
165: if ($val>20) {
166: $output.='<td width='.($val-20).' bgcolor="#33FF33"> </td>'.
167: '<td width='.(40-$val).' bgcolor="#555555"> </td>';
168: } else {
169: $output.='<td width=20 bgcolor="#555555">  </td>';
170: }
171: $output.='<td> ('.$value.') </td></tr></table>';
172: return $output;
173: }
174:
175: sub diffgraph {
176: my $value=shift;
1.13 www 177: unless ($value) { return ''; }
1.12 www 178: my $val=int(40.0*$value+0.5);
1.13 www 179: my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
180: '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
1.12 www 181: my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
182: for (my $i=0;$i<8;$i++) {
183: if ($val>$i*5) {
184: $output.='<td width=5 bgcolor="'.$colors[$i].'"> </td>';
185: } else {
186: $output.='<td width=5 bgcolor="#555555"> </td>';
187: }
188: }
189: $output.='<td> ('.$value.') </td></tr></table>';
190: return $output;
191: }
192:
1.1 www 193: # ================================================================ Main Handler
194:
195: sub handler {
196: my $r=shift;
1.20 www 197:
198: my $loaderror=&Apache::lonnet::overloaderror($r);
199: if ($loaderror) { return $loaderror; }
200:
201:
202: my $uri=$r->uri;
203:
1.23 www 204: unless ($uri=~/^\/\~/) {
205: # =========================================== This is not in construction space
1.20 www 206: my ($resdomain,$resuser)=
207: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
208:
209: $loaderror=
210: &Apache::lonnet::overloaderror($r,
211: &Apache::lonnet::homeserver($resuser,$resdomain));
212: if ($loaderror) { return $loaderror; }
213:
1.3 www 214: my %content=();
1.1 www 215:
216: # ----------------------------------------------------------- Set document type
217:
1.35 www 218: &Apache::loncommon::content_type($r,'text/html');
1.1 www 219: $r->send_http_header;
220:
221: return OK if $r->header_only;
222:
223: # ------------------------------------------------------------------- Read file
1.14 harris41 224: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
1.3 www 225: $content{$_}=&Apache::lonnet::metadata($uri,$_);
1.14 harris41 226: }
1.6 albertel 227: # ------------------------------------------------------------------ Hide stuff
1.7 www 228:
229: unless ($ENV{'user.adv'}) {
1.14 harris41 230: foreach ('keywords','notes','abstract','subject') {
1.35 www 231: $content{$_}='<i>- '.&mt('not displayed').' -</i>';
1.14 harris41 232: }
1.6 albertel 233: }
234:
1.1 www 235: # --------------------------------------------------------------- Render Output
1.23 www 236: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
1.38 www 237: my $creationdate=&Apache::lonlocal::locallocaltime(
1.22 www 238: &Apache::loncommon::unsqltime($content{'creationdate'}));
1.38 www 239: my $lastrevisiondate=&Apache::lonlocal::locallocaltime(
1.22 www 240: &Apache::loncommon::unsqltime($content{'lastrevisiondate'}));
1.10 www 241: my $language=&Apache::loncommon::languagedescription($content{'language'});
242: my $mime=&Apache::loncommon::filedescription($content{'mime'});
1.11 www 243: my $disuri=&Apache::lonnet::declutter($uri);
244: $disuri=~s/\.meta$//;
1.21 www 245: my $currentversion=&Apache::lonnet::getversion($disuri);
1.29 www 246: my $author=$content{'author'};
247: $author=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
248: my $owner=$content{'owner'};
249: $owner=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
1.21 www 250: my $versiondisplay='';
251: if ($thisversion) {
1.38 www 252: $versiondisplay=&mt('Version').': '.$thisversion.
253: ' ('.&mt('most recent version').': '.$currentversion.')';
1.21 www 254: } else {
255: $versiondisplay='Version: '.$currentversion;
256: }
1.29 www 257: my $customdistributionfile='';
258: if ($content{'customdistributionfile'}) {
259: $customdistributionfile='<a href="'.$content{'customdistributionfile'}.
260: '"><tt>'.$content{'customdistributionfile'}.'</tt></a>';
261: }
1.36 www 262:
263: my $obsolete=$content{'obsolete'};
264: my $obsoletereplace=$content{'obsoletereplacement'};
265: my $obsoletewarning='';
266: if (($obsolete) && ($ENV{'user.adv'})) {
267: $obsoletewarning='<p><font color="red">'.&mt('This resource has been marked obsolete by the author(s)').'</font></p>';
268: }
269:
1.35 www 270: my %lt=&Apache::lonlocal::texthash(
271: 'au' =>'Author(s)',
272: 'sb' => 'Subject',
273: 'kw' => 'Keyword(s)',
274: 'no' => 'Notes',
275: 'ab' => 'Abstract',
1.42 ! www 276: 'lg' => 'Lowest Grade Level',
! 277: 'hg' => 'Highest Grade Level',
! 278: 'st' => 'Standards',
1.35 www 279: 'mi' => 'MIME Type',
280: 'la' => 'Language',
281: 'cd' => 'Creation Date',
282: 'pu' => 'Publisher/Owner',
283: 'co' => 'Copyright/Distribution',
1.36 www 284: 'cf' => 'Custom Distribution File',
285: 'ob' => 'Obsolete',
286: 'or' =>
287: 'Suggested Replacement for Obsolete File');
1.17 www 288: my $bodytag=&Apache::loncommon::bodytag
289: ('Catalog Information','','','',$resdomain);
1.1 www 290: $r->print(<<ENDHEAD);
291: <html><head><title>Catalog Information</title></head>
1.17 www 292: $bodytag
1.1 www 293: <h2>$content{'title'}</h2>
1.11 www 294: <h3><tt>$disuri</tt></h3>
1.36 www 295: $obsoletewarning
1.21 www 296: $versiondisplay<br />
1.11 www 297: <table cellspacing=2 border=0>
1.35 www 298: <tr><td bgcolor='#AAAAAA'>$lt{'au'}</td>
1.29 www 299: <td bgcolor="#CCCCCC">$author </td></tr>
1.35 www 300: <tr><td bgcolor='#AAAAAA'>$lt{'sb'}</td>
1.11 www 301: <td bgcolor="#CCCCCC">$content{'subject'} </td></tr>
1.35 www 302: <tr><td bgcolor='#AAAAAA'>$lt{'kw'}</td>
1.11 www 303: <td bgcolor="#CCCCCC">$content{'keywords'} </td></tr>
1.35 www 304: <tr><td bgcolor='#AAAAAA'>$lt{'no'}</td>
1.11 www 305: <td bgcolor="#CCCCCC">$content{'notes'} </td></tr>
1.35 www 306: <tr><td bgcolor='#AAAAAA'>$lt{'ab'}</td>
1.11 www 307: <td bgcolor="#CCCCCC">$content{'abstract'} </td></tr>
1.42 ! www 308: <tr><td bgcolor='#AAAAAA'>$lt{'lg'}</td>
! 309: <td bgcolor="#CCCCCC">$content{'lowestgradelevel'} </td></tr>
! 310: <tr><td bgcolor='#AAAAAA'>$lt{'hg'}</td>
! 311: <td bgcolor="#CCCCCC">$content{'highestgradelevel'} </td></tr>
! 312: <tr><td bgcolor='#AAAAAA'>$lt{'st'}</td>
! 313: <td bgcolor="#CCCCCC">$content{'standards'} </td></tr>
1.35 www 314: <tr><td bgcolor='#AAAAAA'>$lt{'mi'}</td>
1.11 www 315: <td bgcolor="#CCCCCC">$mime ($content{'mime'}) </td></tr>
1.35 www 316: <tr><td bgcolor='#AAAAAA'>$lt{'la'}</td>
1.11 www 317: <td bgcolor="#CCCCCC">$language </td></tr>
1.35 www 318: <tr><td bgcolor='#AAAAAA'>$lt{'cd'}</td>
1.11 www 319: <td bgcolor="#CCCCCC">$creationdate </td></tr>
320: <tr><td bgcolor='#AAAAAA'>
321: Last Revision Date</td><td bgcolor="#CCCCCC">$lastrevisiondate </td></tr>
1.35 www 322: <tr><td bgcolor='#AAAAAA'>$lt{'pu'}</td>
1.29 www 323: <td bgcolor="#CCCCCC">$owner </td></tr>
1.35 www 324: <tr><td bgcolor='#AAAAAA'>$lt{'co'}</td>
1.29 www 325: <td bgcolor="#CCCCCC">$content{'copyright'} </td></tr>
1.35 www 326: <tr><td bgcolor='#AAAAAA'>$lt{'cf'}</td>
1.29 www 327: <td bgcolor="#CCCCCC">$customdistributionfile </td></tr>
1.36 www 328: <tr><td bgcolor='#AAAAAA'>$lt{'ob'}</td>
329: <td bgcolor="#CCCCCC">$obsolete </td></tr>
330: <tr><td bgcolor='#AAAAAA'>$lt{'or'}</td>
331: <td bgcolor="#CCCCCC">$obsoletereplace </td></tr>
1.11 www 332: </table>
1.1 www 333: ENDHEAD
334: delete($content{'title'});
335: delete($content{'author'});
336: delete($content{'subject'});
337: delete($content{'keywords'});
338: delete($content{'notes'});
339: delete($content{'abstract'});
340: delete($content{'mime'});
341: delete($content{'language'});
342: delete($content{'creationdate'});
343: delete($content{'lastrevisiondate'});
344: delete($content{'owner'});
345: delete($content{'copyright'});
1.33 www 346: delete($content{'customdistributionfile'});
1.36 www 347: delete($content{'obsolete'});
348: delete($content{'obsoletereplacement'});
1.7 www 349: if ($ENV{'user.adv'}) {
1.11 www 350: # ------------------------------------------------------------ Dynamic Metadata
1.15 www 351: $r->print(
1.35 www 352: '<h3>'.&mt('Dynamic Metadata').' ('.
353: &mt('updated periodically').')</h3>'.&mt('Processing').
354: ' ...<br>');
1.15 www 355: $r->rflush();
1.35 www 356: my %items=&Apache::lonlocal::texthash(
1.10 www 357: 'count' => 'Network-wide number of accesses (hits)',
358: 'course' => 'Network-wide number of courses using resource',
359: 'usage' => 'Number of resources using or importing resource',
1.30 www 360: 'goto' => 'Number of resources that follow this resource in maps',
361: 'comefrom' => 'Number of resources that lead up to this resource in maps',
1.11 www 362: 'clear' => 'Material presented in clear way',
363: 'depth' => 'Material covered with sufficient depth',
364: 'helpful' => 'Material is helpful',
365: 'correct' => 'Material appears to be correct',
366: 'technical' => 'Resource is technically correct',
1.10 www 367: 'avetries' => 'Average number of tries till solved',
368: 'stdno' => 'Total number of students who have worked on this problem',
369: 'difficulty' => 'Degree of difficulty');
370: my %dynmeta=&dynamicmeta($uri);
1.11 www 371: $r->print(
1.35 www 372: '</table><h4>'.&mt('Access and Usage Statistics').'</h4><table cellspacing=2 border=0>');
1.30 www 373: foreach ('count') {
374: $r->print(
375: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
376: $dynmeta{$_}." </td></tr>\n");
377: }
378: foreach my $cat ('usage','comefrom','goto') {
379: $r->print(
380: '<tr><td bgcolor="#AAAAAA">'.$items{$cat}.'</td><td bgcolor="#CCCCCC">'.
1.31 www 381: $dynmeta{$cat}.'<font size="-1"><ul>'.join("\n",
382: map { my $murl=$_;
383: '<li><a href="'.&Apache::lonnet::clutter($murl).'" target="preview">'.
384: &Apache::lonnet::gettitle($murl).' [<tt>'.$murl
385: .'</tt>]</a></li>' }
386: split(/\,/,$dynmeta{$cat.'_list'}))."</ul></font></td></tr>\n");
1.30 www 387: }
1.31 www 388: foreach my $cat ('course') {
1.11 www 389: $r->print(
1.31 www 390: '<tr><td bgcolor="#AAAAAA">'.$items{$cat}.'</td><td bgcolor="#CCCCCC">'.
391: $dynmeta{$cat}.'<font size="-1"><ul>'.join("\n",
392: map { my %courseinfo=&Apache::lonnet::coursedescription($_);
393: '<li><a href="/public/'.
394: $courseinfo{'domain'}.'/'.$courseinfo{'num'}.'/syllabus" target="preview">'.
395: $courseinfo{'description'}.'</a></li>' }
396: split(/\,/,$dynmeta{$cat.'_list'}))."</ul></font></td></tr>\n");
1.11 www 397: }
398: $r->print('</table>');
1.10 www 399: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
1.11 www 400: $r->print(
1.35 www 401: '<h4>'.&mt('Assessment Statistical Data').'</h4><table cellspacing=2 border=0>');
1.12 www 402: foreach ('stdno','avetries') {
1.11 www 403: $r->print(
404: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
405: $dynmeta{$_}." </td></tr>\n");
406: }
1.12 www 407: foreach ('difficulty') {
408: $r->print(
409: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
410: &diffgraph($dynmeta{$_})."</td></tr>\n");
411: }
1.11 www 412: $r->print('</table>');
1.10 www 413: }
1.35 www 414: $r->print('<h4>'.&mt('Evaluation Data').'</h4><table cellspacing=2 border=0>');
1.10 www 415: foreach ('clear','depth','helpful','correct','technical') {
1.11 www 416: $r->print(
417: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
1.12 www 418: &evalgraph($dynmeta{$_})."</td></tr>\n");
1.10 www 419: }
1.11 www 420: $r->print('</table>');
421: $disuri=~/^(\w+)\/(\w+)\//;
1.10 www 422: if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
423: || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
424: $r->print(
1.35 www 425: '<h4>'.&mt('Evaluation Comments').' ('.&mt('visible to author and co-authors only').')</h4>'.
1.23 www 426: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
427: $r->print(
1.37 www 428: '<h4>'.&mt('Error Messages').' ('.
429: &mt('visible to author and co-authors only').')</h4>');
1.23 www 430: my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$1,$2);
431: foreach (keys %errormsgs) {
1.28 albertel 432: if ($_=~/^\Q$disuri\E\_\d+$/) {
1.23 www 433: my %content=&Apache::lonmsg::unpackagemsg($errormsgs{$_});
434: $r->print('<b>'.$content{'time'}.'</b>: '.$content{'message'}.
435: '<br />');
436: }
437: }
1.10 www 438: }
1.11 www 439: # ------------------------------------------------------------- All other stuff
1.10 www 440: $r->print(
1.35 www 441: '<h3>'.&mt('Additional Metadata (non-standard, parameters, exports)').'</h3>');
1.10 www 442: foreach (sort keys %content) {
1.3 www 443: my $name=$_;
1.33 www 444: unless ($name=~/\.display$/) {
445: my $display=&Apache::lonnet::metadata($uri,$name.'.display');
446: unless ($display) { $display=$name; };
447: my $otherinfo='';
448: foreach ('name','part','type','default') {
449: if (defined(&Apache::lonnet::metadata($uri,$name.'.'.$_))) {
450: $otherinfo.=' '.$_.'='.
451: &Apache::lonnet::metadata($uri,$name.'.'.$_).'; ';
452: }
453: }
454: $r->print('<b>'.$display.':</b> '.$content{$name});
455: if ($otherinfo) {
456: $r->print(' ('.$otherinfo.')');
457: }
458: $r->print("<br>\n");
1.14 harris41 459: }
1.10 www 460: }
1.7 www 461: }
1.23 www 462: # ===================================================== End Resource Space Call
463: } else {
464: # ===================================================== Construction Space Call
465:
466: # ----------------------------------------------------------- Set document type
467:
468: $r->content_type('text/html');
469: $r->send_http_header;
470:
471: return OK if $r->header_only;
472: # ---------------------------------------------------------------------- Header
473: my $bodytag=&Apache::loncommon::bodytag('Edit Catalog Information');
474: my $disuri=$uri;
475: my $fn=&Apache::lonnet::filelocation('',$uri);
476: $disuri=~s/^\/\~\w+//;
477: $disuri=~s/\.meta$//;
478: my $displayfile='Catalog Information for '.$disuri;
479: if ($disuri=~/\/default$/) {
480: my $dir=$disuri;
481: $dir=~s/default$//;
1.37 www 482: $displayfile=&mt('Default Cataloging Information for Directory').' '.
483: $dir;
1.23 www 484: }
485: %Apache::lonpublisher::metadatafields=();
486: %Apache::lonpublisher::metadatakeys=();
487: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
488: $r->print(<<ENDEDIT);
489: <html><head><title>Edit Catalog Information</title></head>
490: $bodytag
491: <h1>$displayfile</h1>
1.24 www 492: <form method="post">
1.23 www 493: ENDEDIT
1.24 www 494: foreach ('author','title','subject','keywords','abstract','notes',
1.37 www 495: 'copyright','customdistributionfile','language',
496: 'obsolete','obsoletereplacement') {
1.24 www 497: if ($ENV{'form.new_'.$_}) {
498: $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};
499: }
1.32 albertel 500: if (m/copyright/) {
501: $r->print(&Apache::lonpublisher::selectbox($_,'new_'.$_,
1.41 www 502: ($Apache::lonpublisher::metadatafields{$_}?
503: $Apache::lonpublisher::metadatafields{$_}:'default'),
1.32 albertel 504: \&Apache::loncommon::copyrightdescription,
505: (&Apache::loncommon::copyrightids)));
506: } elsif (m/language/) {
507: $r->print(&Apache::lonpublisher::selectbox($_,'new_'.$_,
508: $Apache::lonpublisher::metadatafields{$_},
509: \&Apache::loncommon::languagedescription,
510: (&Apache::loncommon::languageids)));
511: } else {
512: $r->print(&Apache::lonpublisher::textfield($_,'new_'.$_,
513: $Apache::lonpublisher::metadatafields{$_}));
514: }
1.23 www 515: }
1.24 www 516: if ($ENV{'form.store'}) {
517: my $mfh;
518: unless ($mfh=Apache::File->new('>'.$fn)) {
519: $r->print(
1.37 www 520: '<p><font color=red>'.&mt('Could not write metadata').', '.
521: &mt('FAIL').'</font>');
1.24 www 522: } else {
523: foreach (sort keys %Apache::lonpublisher::metadatafields) {
524: unless ($_=~/\./) {
525: my $unikey=$_;
526: $unikey=~/^([A-Za-z]+)/;
527: my $tag=$1;
528: $tag=~tr/A-Z/a-z/;
529: print $mfh "\n\<$tag";
530: foreach
531: (split(/\,/,$Apache::lonpublisher::metadatakeys{$unikey})) {
532: my $value=
533: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
534: $value=~s/\"/\'\'/g;
535: print $mfh ' '.$_.'="'.$value.'"';
536: }
537: print $mfh '>'.
538: &HTML::Entities::encode($Apache::lonpublisher::metadatafields{$unikey})
539: .'</'.$tag.'>';
540: }
541: }
1.37 www 542: $r->print('<p>'.&mt('Wrote Metadata'));
1.24 www 543: }
544: }
545: $r->print(
1.37 www 546: '<br /><input type="submit" name="store" value="'.
547: &mt('Store Catalog Information').'"></form></body></html>');
1.24 www 548: return OK;
549: }
1.1 www 550: }
551:
552: 1;
553: __END__
554:
555:
556:
557:
558:
559:
560:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>