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