Annotation of loncom/interface/lonmeta.pm, revision 1.32
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.32 ! albertel 4: # $Id: lonmeta.pm,v 1.31 2003/04/15 00:53:04 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">'.
1.31 www 323: $dynmeta{$cat}.'<font size="-1"><ul>'.join("\n",
324: map { my $murl=$_;
325: '<li><a href="'.&Apache::lonnet::clutter($murl).'" target="preview">'.
326: &Apache::lonnet::gettitle($murl).' [<tt>'.$murl
327: .'</tt>]</a></li>' }
328: split(/\,/,$dynmeta{$cat.'_list'}))."</ul></font></td></tr>\n");
1.30 www 329: }
1.31 www 330: foreach my $cat ('course') {
1.11 www 331: $r->print(
1.31 www 332: '<tr><td bgcolor="#AAAAAA">'.$items{$cat}.'</td><td bgcolor="#CCCCCC">'.
333: $dynmeta{$cat}.'<font size="-1"><ul>'.join("\n",
334: map { my %courseinfo=&Apache::lonnet::coursedescription($_);
335: '<li><a href="/public/'.
336: $courseinfo{'domain'}.'/'.$courseinfo{'num'}.'/syllabus" target="preview">'.
337: $courseinfo{'description'}.'</a></li>' }
338: split(/\,/,$dynmeta{$cat.'_list'}))."</ul></font></td></tr>\n");
1.11 www 339: }
340: $r->print('</table>');
1.10 www 341: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
1.11 www 342: $r->print(
343: '<h4>Assessment Statistical Data</h4><table cellspacing=2 border=0>');
1.12 www 344: foreach ('stdno','avetries') {
1.11 www 345: $r->print(
346: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
347: $dynmeta{$_}." </td></tr>\n");
348: }
1.12 www 349: foreach ('difficulty') {
350: $r->print(
351: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
352: &diffgraph($dynmeta{$_})."</td></tr>\n");
353: }
1.11 www 354: $r->print('</table>');
1.10 www 355: }
1.11 www 356: $r->print('<h4>Evaluation Data</h4><table cellspacing=2 border=0>');
1.10 www 357: foreach ('clear','depth','helpful','correct','technical') {
1.11 www 358: $r->print(
359: '<tr><td bgcolor="#AAAAAA">'.$items{$_}.'</td><td bgcolor="#CCCCCC">'.
1.12 www 360: &evalgraph($dynmeta{$_})."</td></tr>\n");
1.10 www 361: }
1.11 www 362: $r->print('</table>');
363: $disuri=~/^(\w+)\/(\w+)\//;
1.10 www 364: if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
365: || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
366: $r->print(
367: '<h4>Evaluation Comments (visible to author and co-authors only)</h4>'.
1.23 www 368: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
369: $r->print(
370: '<h4>Error Messages (visible to author and co-authors only)</h4>');
371: my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$1,$2);
372: foreach (keys %errormsgs) {
1.28 albertel 373: if ($_=~/^\Q$disuri\E\_\d+$/) {
1.23 www 374: my %content=&Apache::lonmsg::unpackagemsg($errormsgs{$_});
375: $r->print('<b>'.$content{'time'}.'</b>: '.$content{'message'}.
376: '<br />');
377: }
378: }
1.10 www 379: }
1.11 www 380: # ------------------------------------------------------------- All other stuff
1.10 www 381: $r->print(
382: '<h3>Additional Metadata (non-standard, parameters, exports)</h3>');
383: foreach (sort keys %content) {
1.3 www 384: my $name=$_;
385: my $display=&Apache::lonnet::metadata($uri,$name.'.display');
1.5 www 386: unless ($display) { $display=$name; };
387: my $otherinfo='';
1.14 harris41 388: foreach ('name','part','type','default') {
1.5 www 389: if (defined(&Apache::lonnet::metadata($uri,$name.'.'.$_))) {
390: $otherinfo.=' '.$_.'='.
391: &Apache::lonnet::metadata($uri,$name.'.'.$_).'; ';
392: }
1.14 harris41 393: }
1.5 www 394: $r->print('<b>'.$display.':</b> '.$content{$name});
395: if ($otherinfo) {
396: $r->print(' ('.$otherinfo.')');
397: }
398: $r->print("<br>\n");
1.10 www 399: }
1.7 www 400: }
1.23 www 401: # ===================================================== End Resource Space Call
402: } else {
403: # ===================================================== Construction Space Call
404:
405: # ----------------------------------------------------------- Set document type
406:
407: $r->content_type('text/html');
408: $r->send_http_header;
409:
410: return OK if $r->header_only;
411: # ---------------------------------------------------------------------- Header
412: my $bodytag=&Apache::loncommon::bodytag('Edit Catalog Information');
413: my $disuri=$uri;
414: my $fn=&Apache::lonnet::filelocation('',$uri);
415: $disuri=~s/^\/\~\w+//;
416: $disuri=~s/\.meta$//;
417: my $displayfile='Catalog Information for '.$disuri;
418: if ($disuri=~/\/default$/) {
419: my $dir=$disuri;
420: $dir=~s/default$//;
421: $displayfile='Default Cataloging Information for Directory '.$dir;
422: }
423: %Apache::lonpublisher::metadatafields=();
424: %Apache::lonpublisher::metadatakeys=();
425: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
426: $r->print(<<ENDEDIT);
427: <html><head><title>Edit Catalog Information</title></head>
428: $bodytag
429: <h1>$displayfile</h1>
1.24 www 430: <form method="post">
1.23 www 431: ENDEDIT
1.24 www 432: foreach ('author','title','subject','keywords','abstract','notes',
1.27 www 433: 'copyright','customdistributionfile','language') {
1.24 www 434: if ($ENV{'form.new_'.$_}) {
435: $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};
436: }
1.32 ! albertel 437: if (m/copyright/) {
! 438: $r->print(&Apache::lonpublisher::selectbox($_,'new_'.$_,
! 439: $Apache::lonpublisher::metadatafields{$_},
! 440: \&Apache::loncommon::copyrightdescription,
! 441: (&Apache::loncommon::copyrightids)));
! 442: } elsif (m/language/) {
! 443: $r->print(&Apache::lonpublisher::selectbox($_,'new_'.$_,
! 444: $Apache::lonpublisher::metadatafields{$_},
! 445: \&Apache::loncommon::languagedescription,
! 446: (&Apache::loncommon::languageids)));
! 447: } else {
! 448: $r->print(&Apache::lonpublisher::textfield($_,'new_'.$_,
! 449: $Apache::lonpublisher::metadatafields{$_}));
! 450: }
1.23 www 451: }
1.24 www 452: if ($ENV{'form.store'}) {
453: my $mfh;
454: unless ($mfh=Apache::File->new('>'.$fn)) {
455: $r->print(
456: '<p><font color=red>Could not write metadata, FAIL</font>');
457: } else {
458: foreach (sort keys %Apache::lonpublisher::metadatafields) {
459: unless ($_=~/\./) {
460: my $unikey=$_;
461: $unikey=~/^([A-Za-z]+)/;
462: my $tag=$1;
463: $tag=~tr/A-Z/a-z/;
464: print $mfh "\n\<$tag";
465: foreach
466: (split(/\,/,$Apache::lonpublisher::metadatakeys{$unikey})) {
467: my $value=
468: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
469: $value=~s/\"/\'\'/g;
470: print $mfh ' '.$_.'="'.$value.'"';
471: }
472: print $mfh '>'.
473: &HTML::Entities::encode($Apache::lonpublisher::metadatafields{$unikey})
474: .'</'.$tag.'>';
475: }
476: }
477: $r->print('<p>Wrote Metadata');
478: }
479: }
480: $r->print(
481: '<br /><input type="submit" name="store" value="Store Catalog Information"></form></body></html>');
482: return OK;
483: }
1.1 www 484: }
485:
486: 1;
487: __END__
488:
489:
490:
491:
492:
493:
494:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>