1: # The LearningOnline Network with CAPA
2: # Metadata display handler
3: #
4: # $Id: lonmeta.pm,v 1.101 2005/08/02 17:01:20 banghart 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 LONCAPA::lonmetadata();
33: use Apache::Constants qw(:common);
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonhtmlcommon();
37: use Apache::lonmsg;
38: use Apache::lonpublisher;
39: use Apache::lonlocal;
40: use Apache::lonmysql;
41: use Apache::lonmsg;
42:
43:
44: ############################################################
45: ############################################################
46: ##
47: ## &get_dynamic_metadata_from_sql($url)
48: ##
49: ## Queries sql database for dynamic metdata
50: ## Returns a hash of hashes, with keys of urls which match $url
51: ## Returned fields are given below.
52: ##
53: ## Examples:
54: ##
55: ## %DynamicMetadata = &Apache::lonmeta::get_dynmaic_metadata_from_sql
56: ## ('/res/msu/korte/');
57: ##
58: ## $DynamicMetadata{'/res/msu/korte/example.problem'}->{$field}
59: ##
60: ############################################################
61: ############################################################
62: sub get_dynamic_metadata_from_sql {
63: my ($url) = shift();
64: my ($authordom,$author)=($url=~m:^/res/(\w+)/(\w+)/:);
65: if (! defined($authordom)) {
66: $authordom = shift();
67: }
68: if (! defined($author)) {
69: $author = shift();
70: }
71: if (! defined($authordom) || ! defined($author)) {
72: return ();
73: }
74: my @Fields = ('url','count','course',
75: 'goto','goto_list',
76: 'comefrom','comefrom_list',
77: 'sequsage','sequsage_list',
78: 'stdno','stdno_list',
79: 'dependencies',
80: 'avetries','avetries_list',
81: 'difficulty','difficulty_list',
82: 'disc','disc_list',
83: 'clear','technical','correct',
84: 'helpful','depth');
85: #
86: my $query = 'SELECT '.join(',',@Fields).
87: ' FROM metadata WHERE url LIKE "'.$url.'%"';
88: my $server = &Apache::lonnet::homeserver($author,$authordom);
89: my $reply = &Apache::lonnet::metadata_query($query,undef,undef,
90: ,[$server]);
91: return () if (! defined($reply) || ref($reply) ne 'HASH');
92: my $filename = $reply->{$server};
93: if (! defined($filename) || $filename =~ /^error/) {
94: return ();
95: }
96: my $max_time = time + 10; # wait 10 seconds for results at most
97: my %ReturnHash;
98: #
99: # Look for results
100: my $finished = 0;
101: while (! $finished && time < $max_time) {
102: my $datafile=$Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/'.$filename;
103: if (! -e "$datafile.end") { next; }
104: my $fh;
105: if (!($fh=Apache::File->new($datafile))) { next; }
106: while (my $result = <$fh>) {
107: chomp($result);
108: next if (! $result);
109: my @Data =
110: map {
111: &Apache::lonnet::unescape($_);
112: } split(',',$result);
113: my $url = $Data[0];
114: for (my $i=0;$i<=$#Fields;$i++) {
115: $ReturnHash{$url}->{$Fields[$i]}=$Data[$i];
116: }
117: }
118: $finished = 1;
119: }
120: #
121: return %ReturnHash;
122: }
123:
124:
125: # Fetch and evaluate dynamic metadata
126: sub dynamicmeta {
127: my $url=&Apache::lonnet::declutter(shift);
128: $url=~s/\.meta$//;
129: my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
130: my $regexp=$url;
131: $regexp=~s/(\W)/\\$1/g;
132: $regexp='___'.$regexp.'___';
133: my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
134: $aauthor,$regexp);
135: my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
136: my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
137: \%DynamicData);
138: #
139: # Deal with 'count' separately
140: $Data{'count'} = &access_count($url,$aauthor,$adomain);
141: #
142: # Debugging code I will probably need later
143: if (0) {
144: &Apache::lonnet::logthis('Dynamic Metadata');
145: while(my($k,$v)=each(%Data)){
146: &Apache::lonnet::logthis(' "'.$k.'"=>"'.$v.'"');
147: }
148: &Apache::lonnet::logthis('-------------------');
149: }
150: return %Data;
151: }
152:
153: sub access_count {
154: my ($src,$author,$adomain) = @_;
155: my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
156: $author,$src);
157: if (! exists($countdata{$src})) {
158: return &mt('Not Available');
159: } else {
160: return $countdata{$src};
161: }
162: }
163:
164: # Try to make an alt tag if there is none
165: sub alttag {
166: my ($base,$src)=@_;
167: my $fullpath=&Apache::lonnet::hreflocation($base,$src);
168: my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
169: &Apache::lonnet::metadata($fullpath,'subject').' '.
170: &Apache::lonnet::metadata($fullpath,'abstract');
171: $alttag=~s/\s+/ /gs;
172: $alttag=~s/\"//gs;
173: $alttag=~s/\'//gs;
174: $alttag=~s/\s+$//gs;
175: $alttag=~s/^\s+//gs;
176: if ($alttag) {
177: return $alttag;
178: } else {
179: return &mt('No information available');
180: }
181: }
182:
183: # Author display
184: sub authordisplay {
185: my ($aname,$adom)=@_;
186: return &Apache::loncommon::aboutmewrapper
187: (&Apache::loncommon::plainname($aname,$adom),
188: $aname,$adom,'preview').' <tt>['.$aname.'@'.$adom.']</tt>';
189: }
190:
191: # Pretty display
192: sub evalgraph {
193: my $value=shift;
194: if (! $value) {
195: return '';
196: }
197: my $val=int($value*10.+0.5)-10;
198: my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
199: if ($val>=20) {
200: $output.='<td width="20" bgcolor="#555555">  </td>';
201: } else {
202: $output.='<td width="'.($val).'" bgcolor="#555555"> </td>'.
203: '<td width="'.(20-$val).'" bgcolor="#FF3333"> </td>';
204: }
205: $output.='<td bgcolor="#FFFF33"> </td>';
206: if ($val>20) {
207: $output.='<td width="'.($val-20).'" bgcolor="#33FF33"> </td>'.
208: '<td width="'.(40-$val).'" bgcolor="#555555"> </td>';
209: } else {
210: $output.='<td width="20" bgcolor="#555555">  </td>';
211: }
212: $output.='<td> ('.sprintf("%5.2f",$value).') </td></tr></table>';
213: return $output;
214: }
215:
216: sub diffgraph {
217: my $value=shift;
218: if (! $value) {
219: return '';
220: }
221: my $val=int(40.0*$value+0.5);
222: my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
223: '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
224: my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
225: for (my $i=0;$i<8;$i++) {
226: if ($val>$i*5) {
227: $output.='<td width="5" bgcolor="'.$colors[$i].'"> </td>';
228: } else {
229: $output.='<td width="5" bgcolor="#555555"> </td>';
230: }
231: }
232: $output.='<td> ('.sprintf("%3.2f",$value).') </td></tr></table>';
233: return $output;
234: }
235:
236:
237: # The field names
238: sub fieldnames {
239: my $file_type=shift;
240: my %fields =
241: ('title' => 'Title',
242: 'author' =>'Author(s)',
243: 'authorspace' => 'Author Space',
244: 'modifyinguser' => 'Last Modifying User',
245: 'subject' => 'Subject',
246: 'keywords' => 'Keyword(s)',
247: 'notes' => 'Notes',
248: 'abstract' => 'Abstract',
249: 'lowestgradelevel' => 'Lowest Grade Level',
250: 'highestgradelevel' => 'Highest Grade Level');
251: if (! defined($file_type) || $file_type ne 'portfolio') {
252: %fields =
253: (%fields,
254: 'domain' => 'Domain',
255: 'standards' => 'Standards',
256: 'mime' => 'MIME Type',
257: 'language' => 'Language',
258: 'creationdate' => 'Creation Date',
259: 'lastrevisiondate' => 'Last Revision Date',
260: 'owner' => 'Publisher/Owner',
261: 'copyright' => 'Copyright/Distribution',
262: 'customdistributionfile' => 'Custom Distribution File',
263: 'sourceavail' => 'Source Available',
264: 'sourcerights' => 'Source Custom Distribution File',
265: 'obsolete' => 'Obsolete',
266: 'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
267: 'count' => 'Network-wide number of accesses (hits)',
268: 'course' => 'Network-wide number of courses using resource',
269: 'course_list' => 'Network-wide courses using resource',
270: 'sequsage' => 'Number of resources using or importing resource',
271: 'sequsage_list' => 'Resources using or importing resource',
272: 'goto' => 'Number of resources that follow this resource in maps',
273: 'goto_list' => 'Resources that follow this resource in maps',
274: 'comefrom' => 'Number of resources that lead up to this resource in maps',
275: 'comefrom_list' => 'Resources that lead up to this resource in maps',
276: 'clear' => 'Material presented in clear way',
277: 'depth' => 'Material covered with sufficient depth',
278: 'helpful' => 'Material is helpful',
279: 'correct' => 'Material appears to be correct',
280: 'technical' => 'Resource is technically correct',
281: 'avetries' => 'Average number of tries till solved',
282: 'stdno' => 'Total number of students who have worked on this problem',
283: 'difficulty' => 'Degree of difficulty',
284: 'disc' => 'Degree of discrimination',
285: 'dependencies' => 'Resources used by this resource',
286: );
287: }
288: return &Apache::lonlocal::texthash(%fields);
289: }
290:
291: sub select_course {
292: my ($r)=@_;
293: $r->print('<h3>Instructor Selected Meta-Data</h3><br />');
294: $r->print('<form action="" method="post">');
295: $r->print('Select your course<br>'.$env{'user.domain'});
296: $r->print('<select name="metacourse" >');
297: $r->print('<input type="submit" >');
298: $r->print('</form>');
299:
300: foreach my $key (keys %env) {
301:
302: if ($key =~ /\.metadata\./) {
303: my $course_key = $key;
304: $course_key =~ s/\.metadata\..*//;
305: $r->print('<option>');
306: $r->print($env{$course_key.'.description'});
307: $r->print('</option>');
308: }
309: }
310: $r->print('</select><br />');
311: $r->print('<input type="submit" >');
312: $r->print('</form>');
313: return 'ok';
314: }
315: # Pretty printing of metadata field
316:
317: sub prettyprint {
318: my ($type,$value,$target,$prefix,$form,$noformat)=@_;
319: # $target,$prefix,$form are optional and for filecrumbs only
320: if (! defined($value)) {
321: return ' ';
322: }
323: # Title
324: if ($type eq 'title') {
325: return '<font size="+1" face="arial">'.$value.'</font>';
326: }
327: # Dates
328: if (($type eq 'creationdate') ||
329: ($type eq 'lastrevisiondate')) {
330: return ($value?&Apache::lonlocal::locallocaltime(
331: &Apache::lonmysql::unsqltime($value)):
332: &mt('not available'));
333: }
334: # Language
335: if ($type eq 'language') {
336: return &Apache::loncommon::languagedescription($value);
337: }
338: # Copyright
339: if ($type eq 'copyright') {
340: return &Apache::loncommon::copyrightdescription($value);
341: }
342: # Copyright
343: if ($type eq 'sourceavail') {
344: return &Apache::loncommon::source_copyrightdescription($value);
345: }
346: # MIME
347: if ($type eq 'mime') {
348: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
349: &Apache::loncommon::filedescription($value);
350: }
351: # Person
352: if (($type eq 'author') ||
353: ($type eq 'owner') ||
354: ($type eq 'modifyinguser') ||
355: ($type eq 'authorspace')) {
356: $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
357: return $value;
358: }
359: # Gradelevel
360: if (($type eq 'lowestgradelevel') ||
361: ($type eq 'highestgradelevel')) {
362: return &Apache::loncommon::gradeleveldescription($value);
363: }
364: # Only for advance users below
365: if (! $env{'user.adv'}) {
366: return '<i>- '.&mt('not displayed').' -</i>';
367: }
368: # File
369: if (($type eq 'customdistributionfile') ||
370: ($type eq 'obsoletereplacement') ||
371: ($type eq 'goto_list') ||
372: ($type eq 'comefrom_list') ||
373: ($type eq 'sequsage_list') ||
374: ($type eq 'dependencies')) {
375: return '<ul><font size="-1">'.join("\n",map {
376: my $url = &Apache::lonnet::clutter($_);
377: my $title = &Apache::lonnet::gettitle($url);
378: if ($title eq '') {
379: $title = 'Untitled';
380: if ($url =~ /\.sequence$/) {
381: $title .= ' Sequence';
382: } elsif ($url =~ /\.page$/) {
383: $title .= ' Page';
384: } elsif ($url =~ /\.problem$/) {
385: $title .= ' Problem';
386: } elsif ($url =~ /\.html$/) {
387: $title .= ' HTML document';
388: } elsif ($url =~ m:/syllabus$:) {
389: $title .= ' Syllabus';
390: }
391: }
392: $_ = '<li>'.$title.' '.
393: &Apache::lonhtmlcommon::crumbs($url,$target,$prefix,$form,'-1',$noformat).
394: '</li>'
395: } split(/\s*\,\s*/,$value)).'</ul></font>';
396: }
397: # Evaluations
398: if (($type eq 'clear') ||
399: ($type eq 'depth') ||
400: ($type eq 'helpful') ||
401: ($type eq 'correct') ||
402: ($type eq 'technical')) {
403: return &evalgraph($value);
404: }
405: # Difficulty
406: if ($type eq 'difficulty' || $type eq 'disc') {
407: return &diffgraph($value);
408: }
409: # List of courses
410: if ($type=~/\_list/) {
411: my @Courses = split(/\s*\,\s*/,$value);
412: my $Str;
413: foreach my $course (@Courses) {
414: my %courseinfo = &Apache::lonnet::coursedescription($course);
415: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
416: next;
417: }
418: if ($Str ne '') { $Str .= '<br />'; }
419: $Str .= '<a href="/public/'.$courseinfo{'domain'}.'/'.
420: $courseinfo{'num'}.'/syllabus" target="preview">'.
421: $courseinfo{'description'}.'</a>';
422: }
423: return $Str;
424: }
425: # No pretty print found
426: return $value;
427: }
428:
429: # Pretty input of metadata field
430: sub direct {
431: return shift;
432: }
433:
434: sub selectbox {
435: my ($name,$value,$functionref,@idlist)=@_;
436: if (! defined($functionref)) {
437: $functionref=\&direct;
438: }
439: my $selout='<select name="'.$name.'">';
440: foreach (@idlist) {
441: $selout.='<option value=\''.$_.'\'';
442: if ($_ eq $value) {
443: $selout.=' selected>'.&{$functionref}($_).'</option>';
444: }
445: else {$selout.='>'.&{$functionref}($_).'</option>';}
446: }
447: return $selout.'</select>';
448: }
449:
450: sub relatedfield {
451: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
452: if (! $relatedsearchflag) {
453: return '';
454: }
455: if (! defined($relatedsep)) {
456: $relatedsep=' ';
457: }
458: if (! $show) {
459: return $relatedsep.' ';
460: }
461: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
462: ($relatedvalue?' checked="1"':'').' />';
463: }
464:
465: sub prettyinput {
466: my ($type,$value,$fieldname,$formname,
467: $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
468: if (! defined($size)) {
469: $size = 80;
470: }
471: # Language
472: if ($type eq 'language') {
473: return &selectbox($fieldname,
474: $value,
475: \&Apache::loncommon::languagedescription,
476: (&Apache::loncommon::languageids)).
477: &relatedfield(0,$relatedsearchflag,$relatedsep);
478: }
479: # Copyright
480: if ($type eq 'copyright') {
481: return &selectbox($fieldname,
482: $value,
483: \&Apache::loncommon::copyrightdescription,
484: (&Apache::loncommon::copyrightids)).
485: &relatedfield(0,$relatedsearchflag,$relatedsep);
486: }
487: # Source Copyright
488: if ($type eq 'sourceavail') {
489: return &selectbox($fieldname,
490: $value,
491: \&Apache::loncommon::source_copyrightdescription,
492: (&Apache::loncommon::source_copyrightids)).
493: &relatedfield(0,$relatedsearchflag,$relatedsep);
494: }
495: # Gradelevels
496: if (($type eq 'lowestgradelevel') ||
497: ($type eq 'highestgradelevel')) {
498: return &Apache::loncommon::select_level_form($value,$fieldname).
499: &relatedfield(0,$relatedsearchflag,$relatedsep);
500: }
501: # Obsolete
502: if ($type eq 'obsolete') {
503: return '<input type="checkbox" name="'.$fieldname.'"'.
504: ($value?' checked="1"':'').' />'.
505: &relatedfield(0,$relatedsearchflag,$relatedsep);
506: }
507: # Obsolete replacement file
508: if ($type eq 'obsoletereplacement') {
509: return '<input type="text" name="'.$fieldname.
510: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
511: "('".$formname."','".$fieldname."'".
512: ",'')\">".&mt('Select').'</a>'.
513: &relatedfield(0,$relatedsearchflag,$relatedsep);
514: }
515: # Customdistribution file
516: if ($type eq 'customdistributionfile') {
517: return '<input type="text" name="'.$fieldname.
518: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
519: "('".$formname."','".$fieldname."'".
520: ",'rights')\">".&mt('Select').'</a>'.
521: &relatedfield(0,$relatedsearchflag,$relatedsep);
522: }
523: # Source Customdistribution file
524: if ($type eq 'sourcerights') {
525: return '<input type="text" name="'.$fieldname.
526: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
527: "('".$formname."','".$fieldname."'".
528: ",'rights')\">".&mt('Select').'</a>'.
529: &relatedfield(0,$relatedsearchflag,$relatedsep);
530: }
531: # Dates
532: if (($type eq 'creationdate') ||
533: ($type eq 'lastrevisiondate')) {
534: return
535: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
536: &relatedfield(0,$relatedsearchflag,$relatedsep);
537: }
538: # No pretty input found
539: $value=~s/^\s+//gs;
540: $value=~s/\s+$//gs;
541: $value=~s/\s+/ /gs;
542: $value=~s/\"/\"\;/gs;
543: return
544: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
545: 'value="'.$value.'" />'.
546: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
547: $relatedvalue);
548: }
549:
550: # Main Handler
551: sub handler {
552: my $r=shift;
553: #
554: my $uri=$r->uri;
555: #
556: # Set document type
557: &Apache::loncommon::content_type($r,'text/html');
558: $r->send_http_header;
559: return OK if $r->header_only;
560: #
561: my ($resdomain,$resuser)=
562: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
563: my $html=&Apache::lonxml::xmlbegin();
564: $r->print($html.'<head><title>'.
565: 'Catalog Information'.
566: '</title></head>');
567: if ($uri=~m:/adm/bombs/(.*)$:) {
568: $r->print(&Apache::loncommon::bodytag('Error Messages'));
569: # Looking for all bombs?
570: &report_bombs($r,$uri);
571: } elsif ($uri=~/\/portfolio\//) {
572: $r->print(&Apache::loncommon::bodytag
573: ('Edit Portfolio File Information','','','',$resdomain));
574: &present_editable_metadata($r,$uri,'portfolio');
575: &select_course($r);
576:
577: } elsif ($uri=~/^\/\~/) {
578: # Construction space
579: $r->print(&Apache::loncommon::bodytag
580: ('Edit Catalog Information','','','',$resdomain));
581: &present_editable_metadata($r,$uri);
582: } else {
583: $r->print(&Apache::loncommon::bodytag
584: ('Catalog Information','','','',$resdomain));
585: &present_uneditable_metadata($r,$uri);
586: }
587: $r->print('</body></html>');
588: return OK;
589: }
590:
591: #####################################################
592: #####################################################
593: ### ###
594: ### Report Bombs ###
595: ### ###
596: #####################################################
597: #####################################################
598: sub report_bombs {
599: my ($r,$uri) = @_;
600: # Set document type
601: $uri =~ s:/adm/bombs/::;
602: $uri = &Apache::lonnet::declutter($uri);
603: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
604: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
605: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
606: if ($env{'form.clearbombs'}) {
607: &Apache::lonmsg::clear_author_res_msg($uri);
608: }
609: my $clear=&mt('Clear all Messages in Subdirectory');
610: $r->print(<<ENDCLEAR);
611: <form method="post">
612: <input type="submit" name="clearbombs" value="$clear" />
613: </form>
614: ENDCLEAR
615: my %brokenurls =
616: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
617: foreach (sort(keys(%brokenurls))) {
618: if ($_=~/^\Q$uri\E/) {
619: $r->print
620: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
621: &Apache::lonmsg::retrieve_author_res_msg($_).
622: '<hr />');
623: }
624: }
625: } else {
626: $r->print(&mt('Not authorized'));
627: }
628: return;
629: }
630:
631: #####################################################
632: #####################################################
633: ### ###
634: ### Uneditable Metadata Display ###
635: ### ###
636: #####################################################
637: #####################################################
638: sub present_uneditable_metadata {
639: my ($r,$uri) = @_;
640: #
641: my %content=();
642: # Read file
643: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
644: $content{$_}=&Apache::lonnet::metadata($uri,$_);
645: }
646: # Render Output
647: # displayed url
648: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
649: $uri=~s/\.meta$//;
650: my $disuri=&Apache::lonnet::clutter($uri);
651: # version
652: my $currentversion=&Apache::lonnet::getversion($disuri);
653: my $versiondisplay='';
654: if ($thisversion) {
655: $versiondisplay=&mt('Version').': '.$thisversion.
656: ' ('.&mt('most recent version').': '.
657: ($currentversion>0 ?
658: $currentversion :
659: &mt('information not available')).')';
660: } else {
661: $versiondisplay='Version: '.$currentversion;
662: }
663: # crumbify displayed URL uri target prefix form size
664: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
665: $disuri =~ s:<br />::g;
666: # obsolete
667: my $obsolete=$content{'obsolete'};
668: my $obsoletewarning='';
669: if (($obsolete) && ($env{'user.adv'})) {
670: $obsoletewarning='<p><font color="red">'.
671: &mt('This resource has been marked obsolete by the author(s)').
672: '</font></p>';
673: }
674: #
675: my %lt=&fieldnames();
676: my $table='';
677: my $title = $content{'title'};
678: if (! defined($title)) {
679: $title = 'Untitled Resource';
680: }
681: foreach ('title',
682: 'author',
683: 'subject',
684: 'keywords',
685: 'notes',
686: 'abstract',
687: 'lowestgradelevel',
688: 'highestgradelevel',
689: 'standards',
690: 'mime',
691: 'language',
692: 'creationdate',
693: 'lastrevisiondate',
694: 'owner',
695: 'copyright',
696: 'customdistributionfile',
697: 'sourceavail',
698: 'sourcerights',
699: 'obsolete',
700: 'obsoletereplacement') {
701: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
702: '</td><td bgcolor="#CCCCCC">'.
703: &prettyprint($_,$content{$_}).'</td></tr>';
704: delete $content{$_};
705: }
706: #
707: $r->print(<<ENDHEAD);
708: <h2>$title</h2>
709: <p>
710: $disuri<br />
711: $obsoletewarning
712: $versiondisplay
713: </p>
714: <table cellspacing="2" border="0">
715: $table
716: </table>
717: ENDHEAD
718: if ($env{'user.adv'}) {
719: &print_dynamic_metadata($r,$uri,\%content);
720: }
721: return;
722: }
723:
724: sub print_dynamic_metadata {
725: my ($r,$uri,$content) = @_;
726: #
727: my %content = %$content;
728: my %lt=&fieldnames();
729: #
730: my $description = 'Dynamic Metadata (updated periodically)';
731: $r->print('<h3>'.&mt($description).'</h3>'.
732: &mt('Processing'));
733: $r->rflush();
734: my %items=&fieldnames();
735: my %dynmeta=&dynamicmeta($uri);
736: #
737: # General Access and Usage Statistics
738: if (exists($dynmeta{'count'}) ||
739: exists($dynmeta{'sequsage'}) ||
740: exists($dynmeta{'comefrom'}) ||
741: exists($dynmeta{'goto'}) ||
742: exists($dynmeta{'course'})) {
743: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
744: '<table cellspacing="2" border="0">');
745: foreach ('count',
746: 'sequsage','sequsage_list',
747: 'comefrom','comefrom_list',
748: 'goto','goto_list',
749: 'course','course_list') {
750: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
751: '<td bgcolor="#CCCCCC">'.
752: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
753: }
754: $r->print('</table>');
755: } else {
756: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
757: }
758: #
759: # Assessment statistics
760: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
761: if (exists($dynmeta{'stdno'}) ||
762: exists($dynmeta{'avetries'}) ||
763: exists($dynmeta{'difficulty'}) ||
764: exists($dynmeta{'disc'})) {
765: # This is an assessment, print assessment data
766: $r->print('<h4>'.
767: &mt('Overall Assessment Statistical Data').
768: '</h4>'.
769: '<table cellspacing="2" border="0">');
770: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
771: '<td bgcolor="#CCCCCC">'.
772: &prettyprint('stdno',$dynmeta{'stdno'}).
773: '</td>'."</tr>\n");
774: foreach ('avetries','difficulty','disc') {
775: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
776: '<td bgcolor="#CCCCCC">'.
777: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
778: '</td>'."</tr>\n");
779: }
780: $r->print('</table>');
781: }
782: if (exists($dynmeta{'stats'})) {
783: #
784: # New assessment statistics
785: $r->print('<h4>'.
786: &mt('Detailed Assessment Statistical Data').
787: '</h4>');
788: my $table = '<table cellspacing="2" border="0">'.
789: '<tr>'.
790: '<th>Course</th>'.
791: '<th>Section(s)</th>'.
792: '<th>Num Students</th>'.
793: '<th>Mean Tries</th>'.
794: '<th>Degree of Difficulty</th>'.
795: '<th>Degree of Discrimination</th>'.
796: '<th>Time of computation</th>'.
797: '</tr>'.$/;
798: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
799: my $data = $dynmeta{'stats'}->{$identifier};
800: my $course = $data->{'course'};
801: my %courseinfo = &Apache::lonnet::coursedescription($course);
802: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
803: &Apache::lonnet::logthis('lookup for '.$course.' failed');
804: next;
805: }
806: $table .= '<tr>';
807: $table .=
808: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
809: $table .=
810: '<td align="right">'.$data->{'sections'}.'</td>';
811: $table .=
812: '<td align="right">'.$data->{'stdno'}.'</td>';
813: foreach ('avetries','difficulty','disc') {
814: $table .= '<td align="right">';
815: if (exists($data->{$_})) {
816: $table .= sprintf('%.2f',$data->{$_}).' ';
817: } else {
818: $table .= '';
819: }
820: $table .= '</td>';
821: }
822: $table .=
823: '<td><nobr>'.
824: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
825: '</nobr></td>';
826: $table .=
827: '</tr>'.$/;
828: }
829: $table .= '</table>'.$/;
830: $r->print($table);
831: } else {
832: $r->print('No new dynamic data found.');
833: }
834: } else {
835: $r->print('<h4>'.
836: &mt('No Assessment Statistical Data is available for this resource').
837: '</h4>');
838: }
839:
840: #
841: #
842: if (exists($dynmeta{'clear'}) ||
843: exists($dynmeta{'depth'}) ||
844: exists($dynmeta{'helpful'}) ||
845: exists($dynmeta{'correct'}) ||
846: exists($dynmeta{'technical'})){
847: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
848: '<table cellspacing="2" border="0">');
849: foreach ('clear','depth','helpful','correct','technical') {
850: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
851: '<td bgcolor="#CCCCCC">'.
852: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
853: }
854: $r->print('</table>');
855: } else {
856: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
857: }
858: $uri=~/^\/res\/(\w+)\/(\w+)\//;
859: if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
860: || ($env{'user.role.ca./'.$1.'/'.$2})) {
861: if (exists($dynmeta{'comments'})) {
862: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
863: &mt('visible to author and co-authors only').
864: ')</h4>'.
865: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
866: } else {
867: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
868: }
869: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
870: if (defined($bombs) && $bombs ne '') {
871: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
872: &mt('visible to author and co-authors only').')'.
873: '</h4>'.$bombs);
874: } else {
875: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
876: }
877: }
878: #
879: # All other stuff
880: $r->print('<h3>'.
881: &mt('Additional Metadata (non-standard, parameters, exports)').
882: '</h3><table border="0" cellspacing="1">');
883: foreach (sort(keys(%content))) {
884: my $name=$_;
885: if ($name!~/\.display$/) {
886: my $display=&Apache::lonnet::metadata($uri,
887: $name.'.display');
888: if (! $display) {
889: $display=$name;
890: };
891: my $otherinfo='';
892: foreach ('name','part','type','default') {
893: if (defined(&Apache::lonnet::metadata($uri,
894: $name.'.'.$_))) {
895: $otherinfo.=' '.$_.'='.
896: &Apache::lonnet::metadata($uri,
897: $name.'.'.$_).'; ';
898: }
899: }
900: $r->print('<tr><td bgcolor="#bbccbb"><font size="-1" color="#556655">'.$display.'</font></td><td bgcolor="#ccddcc"><font size="-1" color="#556655">'.$content{$name});
901: if ($otherinfo) {
902: $r->print(' ('.$otherinfo.')');
903: }
904: $r->print("</font></td></tr>\n");
905: }
906: }
907: $r->print("</table>");
908: return;
909: }
910:
911: #####################################################
912: #####################################################
913: ### ###
914: ### Editable metadata display ###
915: ### ###
916: #####################################################
917: #####################################################
918: sub present_editable_metadata {
919: my ($r,$uri, $file_type) = @_;
920: # Construction Space Call
921: # Header
922: my $disuri=$uri;
923: my $fn=&Apache::lonnet::filelocation('',$uri);
924: $disuri=~s/^\/\~/\/priv\//;
925: $disuri=~s/\.meta$//;
926: my $target=$uri;
927: $target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;
928: $target=~s/\.meta$//;
929: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
930: if ($bombs) {
931: my $showdel=1;
932: if ($env{'form.delmsg'}) {
933: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
934: $bombs=&mt('Messages deleted.');
935: $showdel=0;
936: } else {
937: $bombs=&mt('Error deleting messages');
938: }
939: }
940: if ($env{'form.clearmsg'}) {
941: my $cleardir=$target;
942: $cleardir=~s/\/[^\/]+$/\//;
943: if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
944: $bombs=&mt('Messages cleared.');
945: $showdel=0;
946: } else {
947: $bombs=&mt('Error clearing messages');
948: }
949: }
950: my $del=&mt('Delete Messages for this Resource');
951: my $clear=&mt('Clear all Messages in Subdirectory');
952: my $goback=&mt('Back to Source File');
953: $r->print(<<ENDBOMBS);
954: <h1>$disuri</h1>
955: <form method="post" name="defaultmeta">
956: ENDBOMBS
957: if ($showdel) {
958: $r->print(<<ENDDEL);
959: <input type="submit" name="delmsg" value="$del" />
960: <input type="submit" name="clearmsg" value="$clear" />
961: ENDDEL
962: } else {
963: $r->print('<a href="'.$disuri.'" />'.$goback.'</a>');
964: }
965: $r->print('<br />'.$bombs);
966: } else {
967: my $displayfile='Catalog Information for '.$disuri;
968: if ($disuri=~/\/default$/) {
969: my $dir=$disuri;
970: $dir=~s/default$//;
971: $displayfile=
972: &mt('Default Cataloging Information for Directory').' '.
973: $dir;
974: }
975: %Apache::lonpublisher::metadatafields=();
976: %Apache::lonpublisher::metadatakeys=();
977: my $result=&Apache::lonnet::getfile($fn);
978: if ($result == -1){
979: $r->print('Creating new '.$fn);
980: } else {
981: &Apache::lonpublisher::metaeval($result);
982: }
983: $r->print(<<ENDEDIT);
984: <h1>$displayfile</h1>
985: <form method="post" name="defaultmeta">
986: ENDEDIT
987: $r->print('<script language="JavaScript">'.
988: &Apache::loncommon::browser_and_searcher_javascript().
989: '</script>');
990: my %lt=&fieldnames($file_type);
991: my $output;
992: my @fields;
993: if ($file_type eq 'portfolio') {
994: @fields = ('author','title','subject','keywords','abstract','notes','lowestgradelevel',
995: 'highestgradelevel');
996: } else {
997: @fields = ('author','title','subject','keywords','abstract','notes',
998: 'copyright','customdistributionfile','language',
999: 'standards',
1000: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1001: 'obsolete','obsoletereplacement');
1002: }
1003: foreach (@fields) {
1004: if (defined($env{'form.new_'.$_})) {
1005: $Apache::lonpublisher::metadatafields{$_}=
1006: $env{'form.new_'.$_};
1007: }
1008: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
1009: $Apache::lonpublisher::metadatafields{'copyright'}=
1010: 'default';
1011: }
1012: $output.=('<p>'.$lt{$_}.': '.
1013: &prettyinput($_,
1014: $Apache::lonpublisher::metadatafields{$_},
1015: 'new_'.$_,'defaultmeta').'</p>');
1016: }
1017: if ($env{'form.store'}) {
1018: my $mfh;
1019: my $formname='store';
1020: my $file_content;
1021: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1022: next if ($_ =~ /\./);
1023: my $unikey=$_;
1024: $unikey=~/^([A-Za-z]+)/;
1025: my $tag=$1;
1026: $tag=~tr/A-Z/a-z/;
1027: $file_content.= "\n\<$tag";
1028: foreach (split(/\,/,
1029: $Apache::lonpublisher::metadatakeys{$unikey})
1030: ) {
1031: my $value=
1032: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
1033: $value=~s/\"/\'\'/g;
1034: $file_content.=' '.$_.'="'.$value.'"' ;
1035: # print $mfh ' '.$_.'="'.$value.'"';
1036: }
1037: $file_content.= '>'.
1038: &HTML::Entities::encode
1039: ($Apache::lonpublisher::metadatafields{$unikey},
1040: '<>&"').
1041: '</'.$tag.'>';
1042: }
1043: if ($fn =~ /\/portfolio\//) {
1044: $fn =~ /\/portfolio\/(.*)$/;
1045: my $new_fn = '/'.$1;
1046: $env{'form.'.$formname}=$file_content;
1047: $env{'form.'.$formname.'.filename'}=$new_fn;
1048: &Apache::lonnet::userfileupload('uploaddoc','',
1049: 'portfolio'.$env{'form.currentpath'});
1050: my $status =&Apache::lonnet::userfileupload($formname,'','portfolio');
1051: if (&Apache::lonnet::userfileupload($formname,'','portfolio') eq 'error: no uploaded file') {
1052: $r->print('<p><font color="red">'.
1053: &mt('Could not write metadata').', '.
1054: &mt('FAIL').'</font></p>');
1055: } else {
1056: $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
1057: ' '.&Apache::lonlocal::locallocaltime(time).
1058: '</font></p>');
1059: }
1060: } else {
1061: if (! ($mfh=Apache::File->new('>'.$fn))) {
1062: $r->print('<p><font color="red">'.
1063: &mt('Could not write metadata').', '.
1064: &mt('FAIL').'</font></p>');
1065: } else {
1066: print $mfh $file_content;
1067: $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
1068: ' '.&Apache::lonlocal::locallocaltime(time).
1069: '</font></p>');
1070: }
1071: }
1072: }
1073: $r->print($output.'<br /><input type="submit" name="store" value="'.
1074: &mt('Store Catalog Information').'">');
1075: }
1076: $r->print('</form>');
1077: return;
1078: }
1079:
1080: 1;
1081: __END__
1082:
1083:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>