File:
[LON-CAPA] /
loncom /
interface /
lonmeta.pm
Revision
1.113:
download - view:
text,
annotated -
select for diffs
Mon Oct 17 21:36:44 2005 UTC (18 years, 10 months ago) by
banghart
Branches:
MAIN
CVS tags:
HEAD
Create separate fieldname sets for non-course restricted metadata
and restricted metadata.
Read courses from %env where restricted are defined, and
display choice of courses. Not working yet.
1: # The LearningOnline Network with CAPA
2: # Metadata display handler
3: #
4: # $Id: lonmeta.pm,v 1.113 2005/10/17 21:36:44 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: if ($file_type eq 'portfolio') {
242: %fields =
243: (%fields,
244: 'title' => 'Title',
245: 'author' =>'Author(s)',
246: 'authorspace' => 'Author Space',
247: 'modifyinguser' => 'Last Modifying User',
248: 'subject' => 'Subject',
249: 'keywords' => 'Keyword(s)',
250: 'notes' => 'Notes',
251: 'abstract' => 'Abstract',
252: 'lowestgradelevel' => 'Lowest Grade Level',
253: 'highestgradelevel' => 'Highest Grade Level');
254: }
255: if ($file_type eq 'restrictedportfolio') {
256: %fields =
257: (%fields,
258: 'metadata.title' => 'Title',
259: 'metadata.author' =>'Author(s)',
260: 'metadata.authorspace' => 'Author Space',
261: 'metadata.modifyinguser' => 'Last Modifying User',
262: 'metadata.subject' => 'Subject',
263: 'metadata.keywords' => 'Keyword(s)',
264: 'metadata.notes' => 'Notes',
265: 'metadata.abstract' => 'Abstract',
266: 'metadata.lowestgradelevel' => 'Lowest Grade Level',
267: 'metadata.highestgradelevel' => 'Highest Grade Level');
268: }
269: if (! defined($file_type) || $file_type ne 'portfolio') {
270: %fields =
271: (%fields,
272: 'domain' => 'Domain',
273: 'standards' => 'Standards',
274: 'mime' => 'MIME Type',
275: 'language' => 'Language',
276: 'creationdate' => 'Creation Date',
277: 'lastrevisiondate' => 'Last Revision Date',
278: 'owner' => 'Publisher/Owner',
279: 'copyright' => 'Copyright/Distribution',
280: 'customdistributionfile' => 'Custom Distribution File',
281: 'sourceavail' => 'Source Available',
282: 'sourcerights' => 'Source Custom Distribution File',
283: 'obsolete' => 'Obsolete',
284: 'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
285: 'count' => 'Network-wide number of accesses (hits)',
286: 'course' => 'Network-wide number of courses using resource',
287: 'course_list' => 'Network-wide courses using resource',
288: 'sequsage' => 'Number of resources using or importing resource',
289: 'sequsage_list' => 'Resources using or importing resource',
290: 'goto' => 'Number of resources that follow this resource in maps',
291: 'goto_list' => 'Resources that follow this resource in maps',
292: 'comefrom' => 'Number of resources that lead up to this resource in maps',
293: 'comefrom_list' => 'Resources that lead up to this resource in maps',
294: 'clear' => 'Material presented in clear way',
295: 'depth' => 'Material covered with sufficient depth',
296: 'helpful' => 'Material is helpful',
297: 'correct' => 'Material appears to be correct',
298: 'technical' => 'Resource is technically correct',
299: 'avetries' => 'Average number of tries till solved',
300: 'stdno' => 'Total number of students who have worked on this problem',
301: 'difficulty' => 'Degree of difficulty',
302: 'disc' => 'Degree of discrimination',
303: 'dependencies' => 'Resources used by this resource',
304: );
305: }
306: return &Apache::lonlocal::texthash(%fields);
307: }
308:
309: sub select_course {
310: my ($r)=@_;
311: my %courses;
312: foreach my $key (keys (%env)) {
313: if ($key =~ m/\.metadata\./) {
314: $key =~ m/^course\.(.+)(\.metadata.+$)/;
315: my $course = $1;
316: my $coursekey = 'course.'.$course.'.description';
317: my $value = $env{$coursekey};
318: $courses{$coursekey} = $value;
319: }
320: }
321: $r->print('<h3>Course Related Meta-Data</h3><br />');
322: $r->print('<form action="" method="post">');
323: $r->print('Select your test course<br />');
324: $r->print('<select name="metacourse" >');
325: my $meta_not_found = 1;
326: foreach my $key (keys (%courses)) {
327: if ($meta_not_found) {
328: undef($meta_not_found);
329: $r->print('<h3>Portfolio Meta-Data</h3><br />');
330: $r->print('<form action="" method="post">');
331: $r->print('Select your course<br />');
332: $r->print('<select name="metacourse" >');
333: }
334: $r->print('<option value="'.$key.'">');
335: $r->print($courses{$key});
336: $r->print('</option>');
337: }
338: unless ($meta_not_found) {
339: $r->print('</select><br />');
340: $r->print('<input type="submit" value="Assign Portfolio Metadata" />');
341: $r->print('</form>');
342: }
343: return 'ok';
344: }
345: # Pretty printing of metadata field
346:
347: sub prettyprint {
348: my ($type,$value,$target,$prefix,$form,$noformat)=@_;
349: # $target,$prefix,$form are optional and for filecrumbs only
350: if (! defined($value)) {
351: return ' ';
352: }
353: # Title
354: if ($type eq 'title') {
355: return '<font size="+1" face="arial">'.$value.'</font>';
356: }
357: # Dates
358: if (($type eq 'creationdate') ||
359: ($type eq 'lastrevisiondate')) {
360: return ($value?&Apache::lonlocal::locallocaltime(
361: &Apache::lonmysql::unsqltime($value)):
362: &mt('not available'));
363: }
364: # Language
365: if ($type eq 'language') {
366: return &Apache::loncommon::languagedescription($value);
367: }
368: # Copyright
369: if ($type eq 'copyright') {
370: return &Apache::loncommon::copyrightdescription($value);
371: }
372: # Copyright
373: if ($type eq 'sourceavail') {
374: return &Apache::loncommon::source_copyrightdescription($value);
375: }
376: # MIME
377: if ($type eq 'mime') {
378: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
379: &Apache::loncommon::filedescription($value);
380: }
381: # Person
382: if (($type eq 'author') ||
383: ($type eq 'owner') ||
384: ($type eq 'modifyinguser') ||
385: ($type eq 'authorspace')) {
386: $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
387: return $value;
388: }
389: # Gradelevel
390: if (($type eq 'lowestgradelevel') ||
391: ($type eq 'highestgradelevel')) {
392: return &Apache::loncommon::gradeleveldescription($value);
393: }
394: # Only for advance users below
395: if (! $env{'user.adv'}) {
396: return '<i>- '.&mt('not displayed').' -</i>';
397: }
398: # File
399: if (($type eq 'customdistributionfile') ||
400: ($type eq 'obsoletereplacement') ||
401: ($type eq 'goto_list') ||
402: ($type eq 'comefrom_list') ||
403: ($type eq 'sequsage_list') ||
404: ($type eq 'dependencies')) {
405: return '<ul><font size="-1">'.join("\n",map {
406: my $url = &Apache::lonnet::clutter($_);
407: my $title = &Apache::lonnet::gettitle($url);
408: if ($title eq '') {
409: $title = 'Untitled';
410: if ($url =~ /\.sequence$/) {
411: $title .= ' Sequence';
412: } elsif ($url =~ /\.page$/) {
413: $title .= ' Page';
414: } elsif ($url =~ /\.problem$/) {
415: $title .= ' Problem';
416: } elsif ($url =~ /\.html$/) {
417: $title .= ' HTML document';
418: } elsif ($url =~ m:/syllabus$:) {
419: $title .= ' Syllabus';
420: }
421: }
422: $_ = '<li>'.$title.' '.
423: &Apache::lonhtmlcommon::crumbs($url,$target,$prefix,$form,'-1',$noformat).
424: '</li>'
425: } split(/\s*\,\s*/,$value)).'</ul></font>';
426: }
427: # Evaluations
428: if (($type eq 'clear') ||
429: ($type eq 'depth') ||
430: ($type eq 'helpful') ||
431: ($type eq 'correct') ||
432: ($type eq 'technical')) {
433: return &evalgraph($value);
434: }
435: # Difficulty
436: if ($type eq 'difficulty' || $type eq 'disc') {
437: return &diffgraph($value);
438: }
439: # List of courses
440: if ($type=~/\_list/) {
441: my @Courses = split(/\s*\,\s*/,$value);
442: my $Str;
443: foreach my $course (@Courses) {
444: my %courseinfo = &Apache::lonnet::coursedescription($course);
445: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
446: next;
447: }
448: if ($Str ne '') { $Str .= '<br />'; }
449: $Str .= '<a href="/public/'.$courseinfo{'domain'}.'/'.
450: $courseinfo{'num'}.'/syllabus" target="preview">'.
451: $courseinfo{'description'}.'</a>';
452: }
453: return $Str;
454: }
455: # No pretty print found
456: return $value;
457: }
458:
459: # Pretty input of metadata field
460: sub direct {
461: return shift;
462: }
463:
464: sub selectbox {
465: my ($name,$value,$functionref,@idlist)=@_;
466: if (! defined($functionref)) {
467: $functionref=\&direct;
468: }
469: my $selout='<select name="'.$name.'">';
470: foreach (@idlist) {
471: $selout.='<option value=\''.$_.'\'';
472: if ($_ eq $value) {
473: $selout.=' selected>'.&{$functionref}($_).'</option>';
474: }
475: else {$selout.='>'.&{$functionref}($_).'</option>';}
476: }
477: return $selout.'</select>';
478: }
479:
480: sub relatedfield {
481: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
482: if (! $relatedsearchflag) {
483: return '';
484: }
485: if (! defined($relatedsep)) {
486: $relatedsep=' ';
487: }
488: if (! $show) {
489: return $relatedsep.' ';
490: }
491: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
492: ($relatedvalue?' checked="1"':'').' />';
493: }
494:
495: sub prettyinput {
496: my ($type,$value,$fieldname,$formname,
497: $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
498: if (! defined($size)) {
499: $size = 80;
500: }
501: # Language
502: if ($type eq 'language') {
503: return &selectbox($fieldname,
504: $value,
505: \&Apache::loncommon::languagedescription,
506: (&Apache::loncommon::languageids)).
507: &relatedfield(0,$relatedsearchflag,$relatedsep);
508: }
509: # Copyright
510: if ($type eq 'copyright') {
511: return &selectbox($fieldname,
512: $value,
513: \&Apache::loncommon::copyrightdescription,
514: (&Apache::loncommon::copyrightids)).
515: &relatedfield(0,$relatedsearchflag,$relatedsep);
516: }
517: # Source Copyright
518: if ($type eq 'sourceavail') {
519: return &selectbox($fieldname,
520: $value,
521: \&Apache::loncommon::source_copyrightdescription,
522: (&Apache::loncommon::source_copyrightids)).
523: &relatedfield(0,$relatedsearchflag,$relatedsep);
524: }
525: # Gradelevels
526: if (($type eq 'lowestgradelevel') ||
527: ($type eq 'highestgradelevel')) {
528: return &Apache::loncommon::select_level_form($value,$fieldname).
529: &relatedfield(0,$relatedsearchflag,$relatedsep);
530: }
531: # Obsolete
532: if ($type eq 'obsolete') {
533: return '<input type="checkbox" name="'.$fieldname.'"'.
534: ($value?' checked="1"':'').' />'.
535: &relatedfield(0,$relatedsearchflag,$relatedsep);
536: }
537: # Obsolete replacement file
538: if ($type eq 'obsoletereplacement') {
539: return '<input type="text" name="'.$fieldname.
540: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
541: "('".$formname."','".$fieldname."'".
542: ",'')\">".&mt('Select').'</a>'.
543: &relatedfield(0,$relatedsearchflag,$relatedsep);
544: }
545: # Customdistribution file
546: if ($type eq 'customdistributionfile') {
547: return '<input type="text" name="'.$fieldname.
548: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
549: "('".$formname."','".$fieldname."'".
550: ",'rights')\">".&mt('Select').'</a>'.
551: &relatedfield(0,$relatedsearchflag,$relatedsep);
552: }
553: # Source Customdistribution file
554: if ($type eq 'sourcerights') {
555: return '<input type="text" name="'.$fieldname.
556: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
557: "('".$formname."','".$fieldname."'".
558: ",'rights')\">".&mt('Select').'</a>'.
559: &relatedfield(0,$relatedsearchflag,$relatedsep);
560: }
561: # Dates
562: if (($type eq 'creationdate') ||
563: ($type eq 'lastrevisiondate')) {
564: return
565: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
566: &relatedfield(0,$relatedsearchflag,$relatedsep);
567: }
568: # No pretty input found
569: $value=~s/^\s+//gs;
570: $value=~s/\s+$//gs;
571: $value=~s/\s+/ /gs;
572: $value=~s/\"/\"\;/gs;
573: return
574: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
575: 'value="'.$value.'" />'.
576: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
577: $relatedvalue);
578: }
579:
580: # Main Handler
581: sub handler {
582: my $r=shift;
583: #
584: my $uri=$r->uri;
585: #
586: # Set document type
587: &Apache::loncommon::content_type($r,'text/html');
588: $r->send_http_header;
589: return OK if $r->header_only;
590: #
591: my ($resdomain,$resuser)=
592: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
593: my $html=&Apache::lonxml::xmlbegin();
594: $r->print($html.'<head><title>'.
595: 'Catalog Information'.
596: '</title></head>');
597: if ($uri=~m:/adm/bombs/(.*)$:) {
598: $r->print(&Apache::loncommon::bodytag('Error Messages'));
599: # Looking for all bombs?
600: &report_bombs($r,$uri);
601: } elsif ($uri=~/\/portfolio\//) {
602: ($resdomain,$resuser)=
603: (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
604: $r->print(&Apache::loncommon::bodytag
605: ('Edit Portfolio File Information','','','',$resdomain));
606: &present_editable_metadata($r,$uri,'portfolio');
607: &select_course($r);
608: } elsif ($uri=~/^\/\~/) {
609: # Construction space
610: $r->print(&Apache::loncommon::bodytag
611: ('Edit Catalog Information','','','',$resdomain));
612: &present_editable_metadata($r,$uri);
613: } else {
614: $r->print(&Apache::loncommon::bodytag
615: ('Catalog Information','','','',$resdomain));
616: &present_uneditable_metadata($r,$uri);
617: }
618: $r->print('</body></html>');
619: return OK;
620: }
621:
622: #####################################################
623: #####################################################
624: ### ###
625: ### Report Bombs ###
626: ### ###
627: #####################################################
628: #####################################################
629: sub report_bombs {
630: my ($r,$uri) = @_;
631: # Set document type
632: $uri =~ s:/adm/bombs/::;
633: $uri = &Apache::lonnet::declutter($uri);
634: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
635: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
636: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
637: if ($env{'form.clearbombs'}) {
638: &Apache::lonmsg::clear_author_res_msg($uri);
639: }
640: my $clear=&mt('Clear all Messages in Subdirectory');
641: $r->print(<<ENDCLEAR);
642: <form method="post">
643: <input type="submit" name="clearbombs" value="$clear" />
644: </form>
645: ENDCLEAR
646: my %brokenurls =
647: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
648: foreach (sort(keys(%brokenurls))) {
649: if ($_=~/^\Q$uri\E/) {
650: $r->print
651: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
652: &Apache::lonmsg::retrieve_author_res_msg($_).
653: '<hr />');
654: }
655: }
656: } else {
657: $r->print(&mt('Not authorized'));
658: }
659: return;
660: }
661:
662: #####################################################
663: #####################################################
664: ### ###
665: ### Uneditable Metadata Display ###
666: ### ###
667: #####################################################
668: #####################################################
669: sub present_uneditable_metadata {
670: my ($r,$uri) = @_;
671: #
672: my %content=();
673: # Read file
674: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
675: $content{$_}=&Apache::lonnet::metadata($uri,$_);
676: }
677: # Render Output
678: # displayed url
679: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
680: $uri=~s/\.meta$//;
681: my $disuri=&Apache::lonnet::clutter($uri);
682: # version
683: my $currentversion=&Apache::lonnet::getversion($disuri);
684: my $versiondisplay='';
685: if ($thisversion) {
686: $versiondisplay=&mt('Version').': '.$thisversion.
687: ' ('.&mt('most recent version').': '.
688: ($currentversion>0 ?
689: $currentversion :
690: &mt('information not available')).')';
691: } else {
692: $versiondisplay='Version: '.$currentversion;
693: }
694: # crumbify displayed URL uri target prefix form size
695: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
696: $disuri =~ s:<br />::g;
697: # obsolete
698: my $obsolete=$content{'obsolete'};
699: my $obsoletewarning='';
700: if (($obsolete) && ($env{'user.adv'})) {
701: $obsoletewarning='<p><font color="red">'.
702: &mt('This resource has been marked obsolete by the author(s)').
703: '</font></p>';
704: }
705: #
706: my %lt=&fieldnames();
707: my $table='';
708: my $title = $content{'title'};
709: if (! defined($title)) {
710: $title = 'Untitled Resource';
711: }
712: foreach ('title',
713: 'author',
714: 'subject',
715: 'keywords',
716: 'notes',
717: 'abstract',
718: 'lowestgradelevel',
719: 'highestgradelevel',
720: 'standards',
721: 'mime',
722: 'language',
723: 'creationdate',
724: 'lastrevisiondate',
725: 'owner',
726: 'copyright',
727: 'customdistributionfile',
728: 'sourceavail',
729: 'sourcerights',
730: 'obsolete',
731: 'obsoletereplacement') {
732: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
733: '</td><td bgcolor="#CCCCCC">'.
734: &prettyprint($_,$content{$_}).'</td></tr>';
735: delete $content{$_};
736: }
737: #
738: $r->print(<<ENDHEAD);
739: <h2>$title</h2>
740: <p>
741: $disuri<br />
742: $obsoletewarning
743: $versiondisplay
744: </p>
745: <table cellspacing="2" border="0">
746: $table
747: </table>
748: ENDHEAD
749: if ($env{'user.adv'}) {
750: &print_dynamic_metadata($r,$uri,\%content);
751: }
752: return;
753: }
754:
755: sub print_dynamic_metadata {
756: my ($r,$uri,$content) = @_;
757: #
758: my %content = %$content;
759: my %lt=&fieldnames();
760: #
761: my $description = 'Dynamic Metadata (updated periodically)';
762: $r->print('<h3>'.&mt($description).'</h3>'.
763: &mt('Processing'));
764: $r->rflush();
765: my %items=&fieldnames();
766: my %dynmeta=&dynamicmeta($uri);
767: #
768: # General Access and Usage Statistics
769: if (exists($dynmeta{'count'}) ||
770: exists($dynmeta{'sequsage'}) ||
771: exists($dynmeta{'comefrom'}) ||
772: exists($dynmeta{'goto'}) ||
773: exists($dynmeta{'course'})) {
774: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
775: '<table cellspacing="2" border="0">');
776: foreach ('count',
777: 'sequsage','sequsage_list',
778: 'comefrom','comefrom_list',
779: 'goto','goto_list',
780: 'course','course_list') {
781: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
782: '<td bgcolor="#CCCCCC">'.
783: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
784: }
785: $r->print('</table>');
786: } else {
787: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
788: }
789: #
790: # Assessment statistics
791: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
792: if (exists($dynmeta{'stdno'}) ||
793: exists($dynmeta{'avetries'}) ||
794: exists($dynmeta{'difficulty'}) ||
795: exists($dynmeta{'disc'})) {
796: # This is an assessment, print assessment data
797: $r->print('<h4>'.
798: &mt('Overall Assessment Statistical Data').
799: '</h4>'.
800: '<table cellspacing="2" border="0">');
801: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
802: '<td bgcolor="#CCCCCC">'.
803: &prettyprint('stdno',$dynmeta{'stdno'}).
804: '</td>'."</tr>\n");
805: foreach ('avetries','difficulty','disc') {
806: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
807: '<td bgcolor="#CCCCCC">'.
808: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
809: '</td>'."</tr>\n");
810: }
811: $r->print('</table>');
812: }
813: if (exists($dynmeta{'stats'})) {
814: #
815: # New assessment statistics
816: $r->print('<h4>'.
817: &mt('Detailed Assessment Statistical Data').
818: '</h4>');
819: my $table = '<table cellspacing="2" border="0">'.
820: '<tr>'.
821: '<th>Course</th>'.
822: '<th>Section(s)</th>'.
823: '<th>Num Students</th>'.
824: '<th>Mean Tries</th>'.
825: '<th>Degree of Difficulty</th>'.
826: '<th>Degree of Discrimination</th>'.
827: '<th>Time of computation</th>'.
828: '</tr>'.$/;
829: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
830: my $data = $dynmeta{'stats'}->{$identifier};
831: my $course = $data->{'course'};
832: my %courseinfo = &Apache::lonnet::coursedescription($course);
833: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
834: &Apache::lonnet::logthis('lookup for '.$course.' failed');
835: next;
836: }
837: $table .= '<tr>';
838: $table .=
839: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
840: $table .=
841: '<td align="right">'.$data->{'sections'}.'</td>';
842: $table .=
843: '<td align="right">'.$data->{'stdno'}.'</td>';
844: foreach ('avetries','difficulty','disc') {
845: $table .= '<td align="right">';
846: if (exists($data->{$_})) {
847: $table .= sprintf('%.2f',$data->{$_}).' ';
848: } else {
849: $table .= '';
850: }
851: $table .= '</td>';
852: }
853: $table .=
854: '<td><nobr>'.
855: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
856: '</nobr></td>';
857: $table .=
858: '</tr>'.$/;
859: }
860: $table .= '</table>'.$/;
861: $r->print($table);
862: } else {
863: $r->print('No new dynamic data found.');
864: }
865: } else {
866: $r->print('<h4>'.
867: &mt('No Assessment Statistical Data is available for this resource').
868: '</h4>');
869: }
870:
871: #
872: #
873: if (exists($dynmeta{'clear'}) ||
874: exists($dynmeta{'depth'}) ||
875: exists($dynmeta{'helpful'}) ||
876: exists($dynmeta{'correct'}) ||
877: exists($dynmeta{'technical'})){
878: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
879: '<table cellspacing="2" border="0">');
880: foreach ('clear','depth','helpful','correct','technical') {
881: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
882: '<td bgcolor="#CCCCCC">'.
883: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
884: }
885: $r->print('</table>');
886: } else {
887: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
888: }
889: $uri=~/^\/res\/(\w+)\/(\w+)\//;
890: if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
891: || ($env{'user.role.ca./'.$1.'/'.$2})) {
892: if (exists($dynmeta{'comments'})) {
893: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
894: &mt('visible to author and co-authors only').
895: ')</h4>'.
896: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
897: } else {
898: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
899: }
900: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
901: if (defined($bombs) && $bombs ne '') {
902: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
903: &mt('visible to author and co-authors only').')'.
904: '</h4>'.$bombs);
905: } else {
906: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
907: }
908: }
909: #
910: # All other stuff
911: $r->print('<h3>'.
912: &mt('Additional Metadata (non-standard, parameters, exports)').
913: '</h3><table border="0" cellspacing="1">');
914: foreach (sort(keys(%content))) {
915: my $name=$_;
916: if ($name!~/\.display$/) {
917: my $display=&Apache::lonnet::metadata($uri,
918: $name.'.display');
919: if (! $display) {
920: $display=$name;
921: };
922: my $otherinfo='';
923: foreach ('name','part','type','default') {
924: if (defined(&Apache::lonnet::metadata($uri,
925: $name.'.'.$_))) {
926: $otherinfo.=' '.$_.'='.
927: &Apache::lonnet::metadata($uri,
928: $name.'.'.$_).'; ';
929: }
930: }
931: $r->print('<tr><td bgcolor="#bbccbb"><font size="-1" color="#556655">'.$display.'</font></td><td bgcolor="#ccddcc"><font size="-1" color="#556655">'.$content{$name});
932: if ($otherinfo) {
933: $r->print(' ('.$otherinfo.')');
934: }
935: $r->print("</font></td></tr>\n");
936: }
937: }
938: $r->print("</table>");
939: return;
940: }
941:
942:
943:
944: #####################################################
945: #####################################################
946: ### ###
947: ### Editable metadata display ###
948: ### ###
949: #####################################################
950: #####################################################
951: sub present_editable_metadata {
952: my ($r,$uri, $file_type) = @_;
953: # Construction Space Call
954: # Header
955: my $disuri=$uri;
956: my $fn=&Apache::lonnet::filelocation('',$uri);
957: $disuri=~s/^\/\~/\/priv\//;
958: $disuri=~s/\.meta$//;
959: $disuri=~s|^/editupload||;
960: my $target=$uri;
961: $target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;
962: $target=~s/\.meta$//;
963: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
964: if ($bombs) {
965: my $showdel=1;
966: if ($env{'form.delmsg'}) {
967: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
968: $bombs=&mt('Messages deleted.');
969: $showdel=0;
970: } else {
971: $bombs=&mt('Error deleting messages');
972: }
973: }
974: if ($env{'form.clearmsg'}) {
975: my $cleardir=$target;
976: $cleardir=~s/\/[^\/]+$/\//;
977: if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
978: $bombs=&mt('Messages cleared.');
979: $showdel=0;
980: } else {
981: $bombs=&mt('Error clearing messages');
982: }
983: }
984: my $del=&mt('Delete Messages for this Resource');
985: my $clear=&mt('Clear all Messages in Subdirectory');
986: my $goback=&mt('Back to Source File');
987: $r->print(<<ENDBOMBS);
988: <h1>$disuri</h1>
989: <form method="post" name="defaultmeta">
990: ENDBOMBS
991: if ($showdel) {
992: $r->print(<<ENDDEL);
993: <input type="submit" name="delmsg" value="$del" />
994: <input type="submit" name="clearmsg" value="$clear" />
995: ENDDEL
996: } else {
997: $r->print('<a href="'.$disuri.'" />'.$goback.'</a>');
998: }
999: $r->print('<br />'.$bombs);
1000: } else {
1001: my $displayfile='Catalog Information for '.$disuri;
1002: if ($disuri=~/\/default$/) {
1003: my $dir=$disuri;
1004: $dir=~s/default$//;
1005: $displayfile=
1006: &mt('Default Cataloging Information for Directory').' '.
1007: $dir;
1008: }
1009: %Apache::lonpublisher::metadatafields=();
1010: %Apache::lonpublisher::metadatakeys=();
1011: my $result=&Apache::lonnet::getfile($fn);
1012: if ($result == -1){
1013: $r->print('Creating new '.$disuri);
1014: } else {
1015: &Apache::lonpublisher::metaeval($result);
1016: }
1017: $r->print(<<ENDEDIT);
1018: <h1>$displayfile</h1>
1019: <form method="post" name="defaultmeta">
1020: ENDEDIT
1021: $r->print('<script language="JavaScript">'.
1022: &Apache::loncommon::browser_and_searcher_javascript().
1023: '</script>');
1024: my %lt=&fieldnames($file_type);
1025: my $output;
1026: my @fields;
1027: if ($file_type eq 'portfolio') {
1028: @fields = ('author','title','subject','keywords','abstract','notes','lowestgradelevel',
1029: 'highestgradelevel');
1030: } else {
1031: @fields = ('author','title','subject','keywords','abstract','notes',
1032: 'copyright','customdistributionfile','language',
1033: 'standards',
1034: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1035: 'obsolete','obsoletereplacement');
1036: }
1037: foreach (@fields) {
1038: if (defined($env{'form.new_'.$_})) {
1039: $Apache::lonpublisher::metadatafields{$_}=
1040: $env{'form.new_'.$_};
1041: }
1042: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
1043: $Apache::lonpublisher::metadatafields{'copyright'}=
1044: 'default';
1045: }
1046: $output.=('<p>'.$lt{$_}.': '.
1047: &prettyinput($_,
1048: $Apache::lonpublisher::metadatafields{$_},
1049: 'new_'.$_,'defaultmeta').'</p>');
1050: if ($env{'form.metacourse'}) {
1051: $r->print('This is the instructor metadata area<br />');
1052: # have to find all the metadata items, so we'll loop through and find them
1053: $r->print('<form method="post" action="" size="3" >');
1054: $r->print('The course is: '.$env{'form.metacourse'}.'<br>');
1055: foreach my $key (sort keys %env) {
1056: if ($key=~m/^($env{'form.metacourse'}\.metadata\.)(\d+)\.title/) {
1057: my $key_base = $1;
1058: my $item_num = $2;
1059: # found one, so let's display it
1060: my $title = $env{$key_base.$item_num.'.title'};
1061: my $type = $env{$key_base.$item_num.'.type'};
1062: my @choices = sort(split /, /,$env{$key_base.$item_num.'.values'});
1063: $r->print($title.'<br />');
1064: $r->print($type.'<br />');
1065:
1066: foreach my $word (@choices) {
1067: my $checked;
1068: if ($Apache::lonpublisher::metadatafields{'coursekeyword'}=~ m/$word/) {
1069: $checked = 1;
1070: } else {
1071: undef($checked);
1072: }
1073: $r->print(&Apache::lonhtmlcommon::checkbox('instmeta_'.$env{'form.metacourse'}.'_'.$item_num,$checked,$word).$word.'<br />');
1074: }
1075: }
1076: }
1077: $r->print('<br /><input type="submit" name="store" value="Assign Meta-data" />');
1078: $r->print('</form>');
1079: return 'ok';
1080: }
1081: }
1082: if ($env{'form.store'}) {
1083: my $mfh;
1084: my $formname='store';
1085: my $file_content;
1086: foreach my $meta_field (keys %env) {
1087: if ($meta_field=~m/^form.instmeta_(.+)_(\d+)$/) {
1088: $r->print('Found a field<br>');
1089: }
1090: if (&Apache::loncommon::get_env_multiple('form.keywords')) {
1091: $Apache::lonpublisher::metadatafields{'coursekeyword'} =
1092: join (', ', &Apache::loncommon::get_env_multiple('form.keywords'));
1093: }
1094: }
1095: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1096: next if ($_ =~ /\./);
1097: my $unikey=$_;
1098: $unikey=~/^([A-Za-z]+)/;
1099: my $tag=$1;
1100: $tag=~tr/A-Z/a-z/;
1101: $file_content.= "\n\<$tag";
1102: foreach (split(/\,/,
1103: $Apache::lonpublisher::metadatakeys{$unikey})
1104: ) {
1105: my $value=
1106: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
1107: $value=~s/\"/\'\'/g;
1108: $file_content.=' '.$_.'="'.$value.'"' ;
1109: # print $mfh ' '.$_.'="'.$value.'"';
1110: }
1111: $file_content.= '>'.
1112: &HTML::Entities::encode
1113: ($Apache::lonpublisher::metadatafields{$unikey},
1114: '<>&"').
1115: '</'.$tag.'>';
1116: }
1117: if ($fn =~ /\/portfolio\//) {
1118: $fn =~ /\/portfolio\/(.*)$/;
1119: my $new_fn = '/'.$1;
1120: $env{'form.'.$formname}=$file_content;
1121: $env{'form.'.$formname.'.filename'}=$new_fn;
1122: &Apache::lonnet::userfileupload('uploaddoc','',
1123: 'portfolio'.$env{'form.currentpath'});
1124: my $status =&Apache::lonnet::userfileupload($formname,'','portfolio');
1125: if (&Apache::lonnet::userfileupload($formname,'','portfolio') eq 'error: no uploaded file') {
1126: $r->print('<p><font color="red">'.
1127: &mt('Could not write metadata').', '.
1128: &mt('FAIL').'</font></p>');
1129: } else {
1130: $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
1131: ' '.&Apache::lonlocal::locallocaltime(time).
1132: '</font></p>');
1133: }
1134: } else {
1135: if (! ($mfh=Apache::File->new('>'.$fn))) {
1136: $r->print('<p><font color="red">'.
1137: &mt('Could not write metadata').', '.
1138: &mt('FAIL').'</font></p>');
1139: } else {
1140: print $mfh $file_content;
1141: $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
1142: ' '.&Apache::lonlocal::locallocaltime(time).
1143: '</font></p>');
1144: }
1145: }
1146: }
1147: $r->print($output.'<br /><input type="submit" name="store" value="'.
1148: &mt('Store Catalog Information').'">');
1149: }
1150: $r->print('</form>');
1151: return;
1152: }
1153:
1154: 1;
1155: __END__
1156:
1157:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>