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