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