Annotation of loncom/interface/lonmeta.pm, revision 1.81
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.81 ! www 4: # $Id: lonmeta.pm,v 1.80 2004/06/16 18:33:46 matthew 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 {
286: my ($type,$value)=@_;
1.65 matthew 287: if (! defined($value)) {
288: return ' ';
289: }
1.64 matthew 290: # Title
1.46 www 291: if ($type eq 'title') {
292: return '<font size="+1" face="arial">'.$value.'</font>';
293: }
1.64 matthew 294: # Dates
1.46 www 295: if (($type eq 'creationdate') ||
296: ($type eq 'lastrevisiondate')) {
1.55 www 297: return ($value?&Apache::lonlocal::locallocaltime(
298: &Apache::lonmysql::unsqltime($value)):
299: &mt('not available'));
1.46 www 300: }
1.64 matthew 301: # Language
1.46 www 302: if ($type eq 'language') {
303: return &Apache::loncommon::languagedescription($value);
304: }
1.64 matthew 305: # Copyright
1.46 www 306: if ($type eq 'copyright') {
307: return &Apache::loncommon::copyrightdescription($value);
308: }
1.78 taceyjo1 309: # Copyright
310: if ($type eq 'sourceavail') {
311: return &Apache::loncommon::source_copyrightdescription($value);
312: }
1.64 matthew 313: # MIME
1.46 www 314: if ($type eq 'mime') {
1.64 matthew 315: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
316: &Apache::loncommon::filedescription($value);
317: }
318: # Person
1.46 www 319: if (($type eq 'author') ||
320: ($type eq 'owner') ||
321: ($type eq 'modifyinguser') ||
322: ($type eq 'authorspace')) {
323: $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
324: return $value;
325: }
1.64 matthew 326: # Gradelevel
1.48 www 327: if (($type eq 'lowestgradelevel') ||
328: ($type eq 'highestgradelevel')) {
329: return &Apache::loncommon::gradeleveldescription($value);
330: }
1.64 matthew 331: # Only for advance users below
1.65 matthew 332: if (! $ENV{'user.adv'}) {
333: return '<i>- '.&mt('not displayed').' -</i>';
334: }
1.64 matthew 335: # File
1.46 www 336: if (($type eq 'customdistributionfile') ||
337: ($type eq 'obsoletereplacement') ||
338: ($type eq 'goto_list') ||
339: ($type eq 'comefrom_list') ||
340: ($type eq 'sequsage_list')) {
341: return join('<br />',map {
1.70 matthew 342: my $url = &Apache::lonnet::clutter($_);
1.72 matthew 343: my $title = &Apache::lonnet::gettitle($url);
344: if ($title eq '') {
345: $title = 'Untitled';
346: if ($url =~ /\.sequence$/) {
347: $title .= ' Sequence';
348: } elsif ($url =~ /\.page$/) {
349: $title .= ' Page';
350: } elsif ($url =~ /\.problem$/) {
351: $title .= ' Problem';
352: } elsif ($url =~ /\.html$/) {
353: $title .= ' HTML document';
354: } elsif ($url =~ m:/syllabus$:) {
355: $title .= ' Syllabus';
356: }
357: }
358: $_ = '<b>'.$title.'</b> '.
1.70 matthew 359: '<a href="'.$url.'" target="preview">'.
360: '<font size="-1">'.$url.'</font>'.
361: '</a>'
1.64 matthew 362: } split(/\s*\,\s*/,$value));
1.46 www 363: }
1.64 matthew 364: # Evaluations
1.46 www 365: if (($type eq 'clear') ||
366: ($type eq 'depth') ||
367: ($type eq 'helpful') ||
368: ($type eq 'correct') ||
369: ($type eq 'technical')) {
370: return &evalgraph($value);
371: }
1.64 matthew 372: # Difficulty
1.73 matthew 373: if ($type eq 'difficulty' || $type eq 'disc') {
1.46 www 374: return &diffgraph($value);
375: }
1.64 matthew 376: # List of courses
1.46 www 377: if ($type=~/\_list/) {
1.72 matthew 378: my @Courses = split(/\s*\,\s*/,$value);
379: my $Str;
380: foreach my $course (@Courses) {
381: my %courseinfo = &Apache::lonnet::coursedescription($course);
382: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
383: next;
384: }
385: if ($Str ne '') { $Str .= '<br />'; }
386: $Str .= '<a href="/public/'.$courseinfo{'domain'}.'/'.
387: $courseinfo{'num'}.'/syllabus" target="preview">'.
388: $courseinfo{'description'}.'</a>';
389: }
390: return $Str;
1.46 www 391: }
1.64 matthew 392: # No pretty print found
1.46 www 393: return $value;
394: }
395:
1.64 matthew 396: # Pretty input of metadata field
1.54 www 397: sub direct {
398: return shift;
399: }
400:
1.48 www 401: sub selectbox {
402: my ($name,$value,$functionref,@idlist)=@_;
1.65 matthew 403: if (! defined($functionref)) {
404: $functionref=\&direct;
405: }
1.48 www 406: my $selout='<select name="'.$name.'">';
407: foreach (@idlist) {
408: $selout.='<option value=\''.$_.'\'';
409: if ($_ eq $value) {
410: $selout.=' selected>'.&{$functionref}($_).'</option>';
411: }
412: else {$selout.='>'.&{$functionref}($_).'</option>';}
413: }
414: return $selout.'</select>';
415: }
416:
1.54 www 417: sub relatedfield {
418: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
1.65 matthew 419: if (! $relatedsearchflag) {
420: return '';
421: }
422: if (! defined($relatedsep)) {
423: $relatedsep=' ';
424: }
425: if (! $show) {
426: return $relatedsep.' ';
427: }
1.54 www 428: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
429: ($relatedvalue?' checked="1"':'').' />';
430: }
1.48 www 431:
1.46 www 432: sub prettyinput {
1.54 www 433: my ($type,$value,$fieldname,$formname,
1.74 matthew 434: $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
1.75 matthew 435: if (! defined($size)) {
436: $size = 80;
437: }
1.64 matthew 438: # Language
1.48 www 439: if ($type eq 'language') {
440: return &selectbox($fieldname,
441: $value,
442: \&Apache::loncommon::languagedescription,
1.54 www 443: (&Apache::loncommon::languageids)).
1.64 matthew 444: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 445: }
1.64 matthew 446: # Copyright
1.48 www 447: if ($type eq 'copyright') {
448: return &selectbox($fieldname,
449: $value,
450: \&Apache::loncommon::copyrightdescription,
1.54 www 451: (&Apache::loncommon::copyrightids)).
1.64 matthew 452: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 453: }
1.78 taceyjo1 454: # Source Copyright
455: if ($type eq 'sourceavail') {
456: return &selectbox($fieldname,
457: $value,
458: \&Apache::loncommon::source_copyrightdescription,
459: (&Apache::loncommon::source_copyrightids)).
460: &relatedfield(0,$relatedsearchflag,$relatedsep);
461: }
1.64 matthew 462: # Gradelevels
1.48 www 463: if (($type eq 'lowestgradelevel') ||
464: ($type eq 'highestgradelevel')) {
1.54 www 465: return &Apache::loncommon::select_level_form($value,$fieldname).
1.64 matthew 466: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 467: }
1.64 matthew 468: # Obsolete
1.48 www 469: if ($type eq 'obsolete') {
470: return '<input type="checkbox" name="'.$fieldname.'"'.
1.54 www 471: ($value?' checked="1"':'').' />'.
1.64 matthew 472: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 473: }
1.64 matthew 474: # Obsolete replacement file
1.48 www 475: if ($type eq 'obsoletereplacement') {
476: return '<input type="text" name="'.$fieldname.
477: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
478: "('".$formname."','".$fieldname."'".
1.54 www 479: ",'')\">".&mt('Select').'</a>'.
1.64 matthew 480: &relatedfield(0,$relatedsearchflag,$relatedsep);
481: }
482: # Customdistribution file
1.48 www 483: if ($type eq 'customdistributionfile') {
484: return '<input type="text" name="'.$fieldname.
485: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
486: "('".$formname."','".$fieldname."'".
1.54 www 487: ",'rights')\">".&mt('Select').'</a>'.
1.64 matthew 488: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 489: }
1.78 taceyjo1 490: # Source Customdistribution file
491: if ($type eq 'sourcerights') {
492: return '<input type="text" name="'.$fieldname.
493: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
494: "('".$formname."','".$fieldname."'".
495: ",'rights')\">".&mt('Select').'</a>'.
496: &relatedfield(0,$relatedsearchflag,$relatedsep);
497: }
1.64 matthew 498: # Dates
1.48 www 499: if (($type eq 'creationdate') ||
500: ($type eq 'lastrevisiondate')) {
1.64 matthew 501: return
502: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
503: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 504: }
1.64 matthew 505: # No pretty input found
1.48 www 506: $value=~s/^\s+//gs;
507: $value=~s/\s+$//gs;
508: $value=~s/\s+/ /gs;
1.77 matthew 509: $value=~s/\"/\"\;/gs;
1.54 www 510: return
1.74 matthew 511: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
1.64 matthew 512: 'value="'.$value.'" />'.
513: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
514: $relatedvalue);
1.46 www 515: }
516:
1.64 matthew 517: # Main Handler
1.1 www 518: sub handler {
1.64 matthew 519: my $r=shift;
520: #
1.67 matthew 521: my $uri=$r->uri;
522: #
523: # Set document type
524: &Apache::loncommon::content_type($r,'text/html');
525: $r->send_http_header;
526: return OK if $r->header_only;
1.64 matthew 527: #
1.76 matthew 528: my ($resdomain,$resuser)=
529: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
1.67 matthew 530: $r->print('<html><head><title>'.
531: 'Catalog Information'.
532: '</title></head>');
1.66 matthew 533: if ($uri=~m:/adm/bombs/(.*)$:) {
1.67 matthew 534: $r->print(&Apache::loncommon::bodytag('Error Messages'));
1.66 matthew 535: # Looking for all bombs?
536: &report_bombs($r,$uri);
537: } elsif ($uri=~/^\/\~/) {
538: # Construction space
1.67 matthew 539: $r->print(&Apache::loncommon::bodytag
540: ('Edit Catalog Information','','','',$resdomain));
1.66 matthew 541: &present_editable_metadata($r,$uri);
542: } else {
1.67 matthew 543: $r->print(&Apache::loncommon::bodytag
544: ('Catalog Information','','','',$resdomain));
1.66 matthew 545: &present_uneditable_metadata($r,$uri);
546: }
1.67 matthew 547: $r->print('</body></html>');
1.66 matthew 548: return OK;
549: }
550:
1.67 matthew 551: #####################################################
552: #####################################################
553: ### ###
554: ### Report Bombs ###
555: ### ###
556: #####################################################
557: #####################################################
1.66 matthew 558: sub report_bombs {
559: my ($r,$uri) = @_;
560: # Set document type
1.67 matthew 561: $uri =~ s:/adm/bombs/::;
562: $uri = &Apache::lonnet::declutter($uri);
1.66 matthew 563: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
564: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
565: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
1.67 matthew 566: my %brokenurls =
567: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
568: foreach (sort(keys(%brokenurls))) {
1.66 matthew 569: if ($_=~/^\Q$uri\E/) {
1.70 matthew 570: $r->print
571: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
572: &Apache::lonmsg::retrieve_author_res_msg($_).
573: '<hr />');
1.64 matthew 574: }
575: }
1.66 matthew 576: } else {
577: $r->print(&mt('Not authorized'));
578: }
579: return;
580: }
581:
1.67 matthew 582: #####################################################
583: #####################################################
584: ### ###
585: ### Uneditable Metadata Display ###
586: ### ###
587: #####################################################
588: #####################################################
1.66 matthew 589: sub present_uneditable_metadata {
590: my ($r,$uri) = @_;
591: #
592: my %content=();
593: # Read file
594: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
595: $content{$_}=&Apache::lonnet::metadata($uri,$_);
596: }
597: # Render Output
598: # displayed url
599: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
600: $uri=~s/\.meta$//;
601: my $disuri=&Apache::lonnet::clutter($uri);
602: # version
603: my $currentversion=&Apache::lonnet::getversion($disuri);
604: my $versiondisplay='';
605: if ($thisversion) {
606: $versiondisplay=&mt('Version').': '.$thisversion.
607: ' ('.&mt('most recent version').': '.
608: ($currentversion>0 ?
609: $currentversion :
610: &mt('information not available')).')';
611: } else {
612: $versiondisplay='Version: '.$currentversion;
613: }
1.72 matthew 614: # crumbify displayed URL uri target prefix form size
615: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
616: $disuri =~ s:<br />::g;
1.66 matthew 617: # obsolete
618: my $obsolete=$content{'obsolete'};
619: my $obsoletewarning='';
620: if (($obsolete) && ($ENV{'user.adv'})) {
621: $obsoletewarning='<p><font color="red">'.
622: &mt('This resource has been marked obsolete by the author(s)').
623: '</font></p>';
624: }
625: #
626: my %lt=&fieldnames();
627: my $table='';
1.72 matthew 628: my $title = $content{'title'};
629: if (! defined($title)) {
630: $title = 'Untitled Resource';
631: }
1.66 matthew 632: foreach ('title',
633: 'author',
634: 'subject',
635: 'keywords',
636: 'notes',
637: 'abstract',
638: 'lowestgradelevel',
639: 'highestgradelevel',
640: 'standards',
641: 'mime',
642: 'language',
643: 'creationdate',
644: 'lastrevisiondate',
645: 'owner',
646: 'copyright',
1.78 taceyjo1 647: 'customdistributionfile',
648: 'sourceavail',
649: 'sourcerights',
1.66 matthew 650: 'obsolete',
651: 'obsoletereplacement') {
652: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
653: '</td><td bgcolor="#CCCCCC">'.
654: &prettyprint($_,$content{$_}).'</td></tr>';
655: delete $content{$_};
656: }
657: #
658: $r->print(<<ENDHEAD);
1.72 matthew 659: <h2>$title</h2>
660: <p>
661: $disuri<br />
1.36 www 662: $obsoletewarning
1.72 matthew 663: $versiondisplay
664: </p>
1.11 www 665: <table cellspacing=2 border=0>
1.45 www 666: $table
1.11 www 667: </table>
1.1 www 668: ENDHEAD
1.66 matthew 669: if ($ENV{'user.adv'}) {
1.68 matthew 670: &print_dynamic_metadata($r,$uri,\%content);
1.67 matthew 671: }
672: return;
673: }
674:
675: sub print_dynamic_metadata {
1.68 matthew 676: my ($r,$uri,$content) = @_;
677: #
1.69 matthew 678: my %content = %$content;
1.68 matthew 679: my %lt=&fieldnames();
1.67 matthew 680: #
681: my $description = 'Dynamic Metadata (updated periodically)';
682: $r->print('<h3>'.&mt($description).'</h3>'.
1.70 matthew 683: &mt('Processing'));
1.67 matthew 684: $r->rflush();
685: my %items=&fieldnames();
686: my %dynmeta=&dynamicmeta($uri);
687: #
688: # General Access and Usage Statistics
1.70 matthew 689: if (exists($dynmeta{'count'}) ||
690: exists($dynmeta{'sequsage'}) ||
691: exists($dynmeta{'comefrom'}) ||
692: exists($dynmeta{'goto'}) ||
693: exists($dynmeta{'course'})) {
694: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
695: '<table cellspacing=2 border=0>');
696: foreach ('count',
697: 'sequsage','sequsage_list',
698: 'comefrom','comefrom_list',
699: 'goto','goto_list',
700: 'course','course_list') {
701: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
702: '<td bgcolor="#CCCCCC">'.
703: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
704: }
705: $r->print('</table>');
706: } else {
707: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
1.67 matthew 708: }
1.69 matthew 709: #
710: # Assessment statistics
1.73 matthew 711: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
712: if (exists($dynmeta{'stdno'}) ||
713: exists($dynmeta{'avetries'}) ||
714: exists($dynmeta{'difficulty'}) ||
715: exists($dynmeta{'disc'})) {
716: # This is an assessment, print assessment data
717: $r->print('<h4>'.
718: &mt('Overall Assessment Statistical Data').
719: '</h4>'.
720: '<table cellspacing=2 border=0>');
721: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
1.66 matthew 722: '<td bgcolor="#CCCCCC">'.
1.73 matthew 723: &prettyprint('stdno',$dynmeta{'stdno'}).
724: '</td>'."</tr>\n");
725: foreach ('avetries','difficulty','disc') {
726: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
727: '<td bgcolor="#CCCCCC">'.
728: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
729: '</td>'."</tr>\n");
730: }
731: $r->print('</table>');
732: }
733: if (exists($dynmeta{'stats'})) {
734: #
735: # New assessment statistics
736: $r->print('<h4>'.
737: &mt('Detailed Assessment Statistical Data').
738: '</h4>');
739: my $table = '<table cellspacing=2 border=0>'.
740: '<tr>'.
741: '<th>Course</th>'.
742: '<th>Section(s)</th>'.
743: '<th>Num Students</th>'.
744: '<th>Mean Tries</th>'.
745: '<th>Degree of Difficulty</th>'.
746: '<th>Degree of Discrimination</th>'.
747: '<th>Time of computation</th>'.
748: '</tr>'.$/;
749: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
750: my $data = $dynmeta{'stats'}->{$identifier};
751: my $course = $data->{'course'};
752: my %courseinfo = &Apache::lonnet::coursedescription($course);
753: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
754: &Apache::lonnet::logthis('lookup for '.$course.' failed');
755: next;
756: }
757: $table .= '<tr>';
758: $table .=
759: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
760: $table .=
761: '<td align="right">'.$data->{'sections'}.'</td>';
762: $table .=
763: '<td align="right">'.$data->{'stdno'}.'</td>';
764: foreach ('avetries','difficulty','disc') {
765: $table .= '<td align="right">';
766: if (exists($data->{$_})) {
767: $table .= sprintf('%.2f',$data->{$_}).' ';
768: } else {
769: $table .= '';
770: }
771: $table .= '</td>';
772: }
773: $table .=
774: '<td><nobr>'.
775: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
776: '</nobr></td>';
777: $table .=
778: '</tr>'.$/;
779: }
780: $table .= '</table>'.$/;
781: $r->print($table);
782: } else {
783: $r->print('No new dynamic data found.');
1.66 matthew 784: }
1.70 matthew 785: } else {
1.73 matthew 786: $r->print('<h4>'.
787: &mt('No Assessment Statistical Data is available for this resource').
788: '</h4>');
1.67 matthew 789: }
1.73 matthew 790:
791: #
792: #
1.70 matthew 793: if (exists($dynmeta{'clear'}) ||
794: exists($dynmeta{'depth'}) ||
795: exists($dynmeta{'helpful'}) ||
796: exists($dynmeta{'correct'}) ||
797: exists($dynmeta{'technical'})){
798: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
799: '<table cellspacing=2 border=0>');
800: foreach ('clear','depth','helpful','correct','technical') {
801: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
802: '<td bgcolor="#CCCCCC">'.
803: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
804: }
805: $r->print('</table>');
806: } else {
807: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1.67 matthew 808: }
809: $uri=~/^\/res\/(\w+)\/(\w+)\//;
810: if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
811: || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
1.70 matthew 812: if (exists($dynmeta{'comments'})) {
813: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
814: &mt('visible to author and co-authors only').
815: ')</h4>'.
816: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
817: } else {
818: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
819: }
820: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
821: if (defined($bombs) && $bombs ne '') {
822: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
823: &mt('visible to author and co-authors only').')'.
824: '</h4>'.$bombs);
825: } else {
826: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
827: }
1.67 matthew 828: }
1.69 matthew 829: #
1.67 matthew 830: # All other stuff
831: $r->print('<h3>'.
832: &mt('Additional Metadata (non-standard, parameters, exports)').
1.81 ! www 833: '</h3><table border="0" cellspacing="1">');
1.67 matthew 834: foreach (sort(keys(%content))) {
835: my $name=$_;
836: if ($name!~/\.display$/) {
837: my $display=&Apache::lonnet::metadata($uri,
838: $name.'.display');
839: if (! $display) {
840: $display=$name;
841: };
842: my $otherinfo='';
843: foreach ('name','part','type','default') {
844: if (defined(&Apache::lonnet::metadata($uri,
845: $name.'.'.$_))) {
846: $otherinfo.=' '.$_.'='.
847: &Apache::lonnet::metadata($uri,
848: $name.'.'.$_).'; ';
849: }
1.64 matthew 850: }
1.81 ! www 851: $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 852: if ($otherinfo) {
853: $r->print(' ('.$otherinfo.')');
1.64 matthew 854: }
1.81 ! www 855: $r->print("</font></td></tr>\n");
1.64 matthew 856: }
1.66 matthew 857: }
1.81 ! www 858: $r->print("</table>");
1.67 matthew 859: return;
1.66 matthew 860: }
861:
1.67 matthew 862: #####################################################
863: #####################################################
864: ### ###
865: ### Editable metadata display ###
866: ### ###
867: #####################################################
868: #####################################################
1.66 matthew 869: sub present_editable_metadata {
870: my ($r,$uri) = @_;
871: # Construction Space Call
872: # Header
873: my $disuri=$uri;
874: my $fn=&Apache::lonnet::filelocation('',$uri);
875: $disuri=~s/^\/\~/\/priv\//;
876: $disuri=~s/\.meta$//;
877: my $target=$uri;
878: $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
879: $target=~s/\.meta$//;
880: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
881: if ($bombs) {
882: if ($ENV{'form.delmsg'}) {
883: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
884: $bombs=&mt('Messages deleted.');
885: } else {
886: $bombs=&mt('Error deleting messages');
1.64 matthew 887: }
1.66 matthew 888: }
889: my $del=&mt('Delete Messages');
890: $r->print(<<ENDBOMBS);
1.52 www 891: <h1>$disuri</h1>
892: <form method="post" name="defaultmeta">
1.59 www 893: <input type="submit" name="delmsg" value="$del" />
1.52 www 894: <br />$bombs
895: ENDBOMBS
1.66 matthew 896: } else {
897: my $displayfile='Catalog Information for '.$disuri;
898: if ($disuri=~/\/default$/) {
899: my $dir=$disuri;
900: $dir=~s/default$//;
901: $displayfile=
902: &mt('Default Cataloging Information for Directory').' '.
903: $dir;
904: }
905: my $bodytag=
906: &Apache::loncommon::bodytag('Edit Catalog Information');
907: %Apache::lonpublisher::metadatafields=();
908: %Apache::lonpublisher::metadatakeys=();
909: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
910: $r->print(<<ENDEDIT);
1.23 www 911: <html><head><title>Edit Catalog Information</title></head>
912: $bodytag
913: <h1>$displayfile</h1>
1.48 www 914: <form method="post" name="defaultmeta">
1.23 www 915: ENDEDIT
1.66 matthew 916: $r->print('<script language="JavaScript">'.
917: &Apache::loncommon::browser_and_searcher_javascript.
918: '</script>');
919: my %lt=&fieldnames();
920: foreach ('author','title','subject','keywords','abstract','notes',
921: 'copyright','customdistributionfile','language',
922: 'standards',
1.78 taceyjo1 923: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1.66 matthew 924: 'obsolete','obsoletereplacement') {
925: if (defined($ENV{'form.new_'.$_})) {
926: $Apache::lonpublisher::metadatafields{$_}=
927: $ENV{'form.new_'.$_};
928: }
929: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
930: $Apache::lonpublisher::metadatafields{'copyright'}=
931: 'default';
1.64 matthew 932: }
1.66 matthew 933: $r->print('<p>'.$lt{$_}.': '.
934: &prettyinput
935: ($_,$Apache::lonpublisher::metadatafields{$_},
936: 'new_'.$_,'defaultmeta').'</p>');
937: }
938: if ($ENV{'form.store'}) {
939: my $mfh;
940: if (! ($mfh=Apache::File->new('>'.$fn))) {
941: $r->print('<p><font color=red>'.
942: &mt('Could not write metadata').', '.
943: &mt('FAIL').'</font>');
944: } else {
945: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1.67 matthew 946: next if ($_ =~ /\./);
947: my $unikey=$_;
948: $unikey=~/^([A-Za-z]+)/;
949: my $tag=$1;
950: $tag=~tr/A-Z/a-z/;
951: print $mfh "\n\<$tag";
952: foreach (split(/\,/,
1.64 matthew 953: $Apache::lonpublisher::metadatakeys{$unikey})
1.67 matthew 954: ) {
955: my $value=
956: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
957: $value=~s/\"/\'\'/g;
958: print $mfh ' '.$_.'="'.$value.'"';
1.64 matthew 959: }
1.67 matthew 960: print $mfh '>'.
961: &HTML::Entities::encode
962: ($Apache::lonpublisher::metadatafields{$unikey},
963: '<>&"').
964: '</'.$tag.'>';
1.64 matthew 965: }
1.66 matthew 966: $r->print('<p>'.&mt('Wrote Metadata'));
1.64 matthew 967: }
968: }
1.66 matthew 969: $r->print('<br /><input type="submit" name="store" value="'.
1.67 matthew 970: &mt('Store Catalog Information').'">');
1.64 matthew 971: }
1.67 matthew 972: $r->print('</form>');
1.66 matthew 973: return;
1.1 www 974: }
1.64 matthew 975:
1.1 www 976: 1;
977: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>