Annotation of loncom/interface/lonmeta.pm, revision 1.80
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.80 ! matthew 4: # $Id: lonmeta.pm,v 1.79 2004/06/16 14:30:15 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: # &Apache::lonnet::logthis('url = '.$url);
! 65: my ($authordom,$author)=($url=~m:^/res/(\w+)/(\w+)/:);
! 66: if (! defined($authordom)) {
! 67: $authordom = shift();
! 68: }
! 69: if (! defined($author)) {
! 70: $author = shift();
! 71: }
! 72: if (! defined($authordom) || ! defined($author)) {
! 73: return ();
! 74: }
! 75: my @Fields = ('url',
! 76: 'goto','goto_list',
! 77: 'comefrom','comefrom_list',
! 78: 'sequsage','sequsage_list',
! 79: 'stdno','stdno_list',
! 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: # &Apache::lonnet::logthis(' '.$Fields[$i].' => '.$Data[$i]);
! 117: }
! 118: }
! 119: $finished = 1;
! 120: }
! 121: #
! 122: return %ReturnHash;
! 123: }
! 124:
! 125:
1.64 matthew 126: # Fetch and evaluate dynamic metadata
1.9 www 127: sub dynamicmeta {
128: my $url=&Apache::lonnet::declutter(shift);
129: $url=~s/\.meta$//;
130: my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
1.19 www 131: my $regexp=$url;
1.9 www 132: $regexp=~s/(\W)/\\$1/g;
1.10 www 133: $regexp='___'.$regexp.'___';
1.16 albertel 134: my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
135: $aauthor,$regexp);
1.63 matthew 136: my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
137: my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
138: \%DynamicData);
1.40 matthew 139: #
1.46 www 140: # Deal with 'count' separately
1.63 matthew 141: $Data{'count'} = &access_count($url,$aauthor,$adomain);
1.67 matthew 142: #
143: # Debugging code I will probably need later
144: if (0) {
145: &Apache::lonnet::logthis('Dynamic Metadata');
146: while(my($k,$v)=each(%Data)){
147: &Apache::lonnet::logthis(' "'.$k.'"=>"'.$v.'"');
148: }
149: &Apache::lonnet::logthis('-------------------');
150: }
1.63 matthew 151: return %Data;
1.40 matthew 152: }
153:
154: sub access_count {
155: my ($src,$author,$adomain) = @_;
156: my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
157: $author,$src);
158: if (! exists($countdata{$src})) {
1.47 www 159: return &mt('Not Available');
1.40 matthew 160: } else {
161: return $countdata{$src};
162: }
1.25 www 163: }
164:
1.64 matthew 165: # Try to make an alt tag if there is none
1.25 www 166: sub alttag {
1.26 www 167: my ($base,$src)=@_;
168: my $fullpath=&Apache::lonnet::hreflocation($base,$src);
169: my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
1.64 matthew 170: &Apache::lonnet::metadata($fullpath,'subject').' '.
171: &Apache::lonnet::metadata($fullpath,'abstract');
1.26 www 172: $alttag=~s/\s+/ /gs;
173: $alttag=~s/\"//gs;
174: $alttag=~s/\'//gs;
175: $alttag=~s/\s+$//gs;
176: $alttag=~s/^\s+//gs;
1.64 matthew 177: if ($alttag) {
178: return $alttag;
179: } else {
180: return &mt('No information available');
181: }
1.9 www 182: }
1.1 www 183:
1.64 matthew 184: # Author display
1.29 www 185: sub authordisplay {
186: my ($aname,$adom)=@_;
1.64 matthew 187: return &Apache::loncommon::aboutmewrapper
188: (&Apache::loncommon::plainname($aname,$adom),
189: $aname,$adom,'preview').' <tt>['.$aname.'@'.$adom.']</tt>';
1.29 www 190: }
191:
1.64 matthew 192: # Pretty display
1.12 www 193: sub evalgraph {
194: my $value=shift;
1.65 matthew 195: if (! $value) {
196: return '';
197: }
1.12 www 198: my $val=int($value*10.+0.5)-10;
1.71 matthew 199: my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
1.12 www 200: if ($val>=20) {
1.71 matthew 201: $output.='<td width="20" bgcolor="#555555">  </td>';
1.12 www 202: } else {
1.71 matthew 203: $output.='<td width="'.($val).'" bgcolor="#555555"> </td>'.
204: '<td width="'.(20-$val).'" bgcolor="#FF3333"> </td>';
1.12 www 205: }
206: $output.='<td bgcolor="#FFFF33"> </td>';
207: if ($val>20) {
1.71 matthew 208: $output.='<td width="'.($val-20).'" bgcolor="#33FF33"> </td>'.
209: '<td width="'.(40-$val).'" bgcolor="#555555"> </td>';
1.12 www 210: } else {
1.71 matthew 211: $output.='<td width="20" bgcolor="#555555">  </td>';
1.12 www 212: }
1.71 matthew 213: $output.='<td> ('.sprintf("%5.2f",$value).') </td></tr></table>';
1.12 www 214: return $output;
215: }
216:
217: sub diffgraph {
218: my $value=shift;
1.65 matthew 219: if (! $value) {
220: return '';
221: }
1.12 www 222: my $val=int(40.0*$value+0.5);
1.13 www 223: my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
224: '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
1.71 matthew 225: my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
1.12 www 226: for (my $i=0;$i<8;$i++) {
227: if ($val>$i*5) {
1.71 matthew 228: $output.='<td width="5" bgcolor="'.$colors[$i].'"> </td>';
1.12 www 229: } else {
1.71 matthew 230: $output.='<td width="5" bgcolor="#555555"> </td>';
1.12 www 231: }
232: }
1.71 matthew 233: $output.='<td> ('.sprintf("%3.2f",$value).') </td></tr></table>';
1.12 www 234: return $output;
235: }
236:
1.44 www 237:
1.64 matthew 238: # The field names
1.45 www 239: sub fieldnames {
1.64 matthew 240: return &Apache::lonlocal::texthash
241: (
242: 'title' => 'Title',
243: 'author' =>'Author(s)',
244: 'authorspace' => 'Author Space',
245: 'modifyinguser' => 'Last Modifying User',
246: 'subject' => 'Subject',
247: 'keywords' => 'Keyword(s)',
248: 'notes' => 'Notes',
249: 'abstract' => 'Abstract',
250: 'lowestgradelevel' => 'Lowest Grade Level',
251: 'highestgradelevel' => 'Highest Grade Level',
252: 'standards' => 'Standards',
253: 'mime' => 'MIME Type',
254: 'language' => 'Language',
255: 'creationdate' => 'Creation Date',
256: 'lastrevisiondate' => 'Last Revision Date',
257: 'owner' => 'Publisher/Owner',
258: 'copyright' => 'Copyright/Distribution',
259: 'customdistributionfile' => 'Custom Distribution File',
1.78 taceyjo1 260: 'sourceavail' => 'Source Availible',
261: 'sourcerights' => 'Source Custom Distribution File',
1.64 matthew 262: 'obsolete' => 'Obsolete',
263: 'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
264: 'count' => 'Network-wide number of accesses (hits)',
265: 'course' => 'Network-wide number of courses using resource',
266: 'course_list' => 'Network-wide courses using resource',
267: 'sequsage' => 'Number of resources using or importing resource',
268: 'sequsage_list' => 'Resources using or importing resource',
269: 'goto' => 'Number of resources that follow this resource in maps',
270: 'goto_list' => 'Resources that follow this resource in maps',
271: 'comefrom' => 'Number of resources that lead up to this resource in maps',
272: 'comefrom_list' => 'Resources that lead up to this resource in maps',
273: 'clear' => 'Material presented in clear way',
274: 'depth' => 'Material covered with sufficient depth',
275: 'helpful' => 'Material is helpful',
276: 'correct' => 'Material appears to be correct',
277: 'technical' => 'Resource is technically correct',
278: 'avetries' => 'Average number of tries till solved',
279: 'stdno' => 'Total number of students who have worked on this problem',
1.73 matthew 280: 'difficulty' => 'Degree of difficulty',
281: 'disc' => 'Degree of discrimination',
1.64 matthew 282: );
1.45 www 283: }
1.46 www 284:
1.64 matthew 285: # Pretty printing of metadata field
1.46 www 286:
287: sub prettyprint {
288: my ($type,$value)=@_;
1.65 matthew 289: if (! defined($value)) {
290: return ' ';
291: }
1.64 matthew 292: # Title
1.46 www 293: if ($type eq 'title') {
294: return '<font size="+1" face="arial">'.$value.'</font>';
295: }
1.64 matthew 296: # Dates
1.46 www 297: if (($type eq 'creationdate') ||
298: ($type eq 'lastrevisiondate')) {
1.55 www 299: return ($value?&Apache::lonlocal::locallocaltime(
300: &Apache::lonmysql::unsqltime($value)):
301: &mt('not available'));
1.46 www 302: }
1.64 matthew 303: # Language
1.46 www 304: if ($type eq 'language') {
305: return &Apache::loncommon::languagedescription($value);
306: }
1.64 matthew 307: # Copyright
1.46 www 308: if ($type eq 'copyright') {
309: return &Apache::loncommon::copyrightdescription($value);
310: }
1.78 taceyjo1 311: # Copyright
312: if ($type eq 'sourceavail') {
313: return &Apache::loncommon::source_copyrightdescription($value);
314: }
1.64 matthew 315: # MIME
1.46 www 316: if ($type eq 'mime') {
1.64 matthew 317: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
318: &Apache::loncommon::filedescription($value);
319: }
320: # Person
1.46 www 321: if (($type eq 'author') ||
322: ($type eq 'owner') ||
323: ($type eq 'modifyinguser') ||
324: ($type eq 'authorspace')) {
325: $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
326: return $value;
327: }
1.64 matthew 328: # Gradelevel
1.48 www 329: if (($type eq 'lowestgradelevel') ||
330: ($type eq 'highestgradelevel')) {
331: return &Apache::loncommon::gradeleveldescription($value);
332: }
1.64 matthew 333: # Only for advance users below
1.65 matthew 334: if (! $ENV{'user.adv'}) {
335: return '<i>- '.&mt('not displayed').' -</i>';
336: }
1.64 matthew 337: # File
1.46 www 338: if (($type eq 'customdistributionfile') ||
339: ($type eq 'obsoletereplacement') ||
340: ($type eq 'goto_list') ||
341: ($type eq 'comefrom_list') ||
342: ($type eq 'sequsage_list')) {
343: return join('<br />',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: }
360: $_ = '<b>'.$title.'</b> '.
1.70 matthew 361: '<a href="'.$url.'" target="preview">'.
362: '<font size="-1">'.$url.'</font>'.
363: '</a>'
1.64 matthew 364: } split(/\s*\,\s*/,$value));
1.46 www 365: }
1.64 matthew 366: # Evaluations
1.46 www 367: if (($type eq 'clear') ||
368: ($type eq 'depth') ||
369: ($type eq 'helpful') ||
370: ($type eq 'correct') ||
371: ($type eq 'technical')) {
372: return &evalgraph($value);
373: }
1.64 matthew 374: # Difficulty
1.73 matthew 375: if ($type eq 'difficulty' || $type eq 'disc') {
1.46 www 376: return &diffgraph($value);
377: }
1.64 matthew 378: # List of courses
1.46 www 379: if ($type=~/\_list/) {
1.72 matthew 380: my @Courses = split(/\s*\,\s*/,$value);
381: my $Str;
382: foreach my $course (@Courses) {
383: my %courseinfo = &Apache::lonnet::coursedescription($course);
384: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
385: next;
386: }
387: if ($Str ne '') { $Str .= '<br />'; }
388: $Str .= '<a href="/public/'.$courseinfo{'domain'}.'/'.
389: $courseinfo{'num'}.'/syllabus" target="preview">'.
390: $courseinfo{'description'}.'</a>';
391: }
392: return $Str;
1.46 www 393: }
1.64 matthew 394: # No pretty print found
1.46 www 395: return $value;
396: }
397:
1.64 matthew 398: # Pretty input of metadata field
1.54 www 399: sub direct {
400: return shift;
401: }
402:
1.48 www 403: sub selectbox {
404: my ($name,$value,$functionref,@idlist)=@_;
1.65 matthew 405: if (! defined($functionref)) {
406: $functionref=\&direct;
407: }
1.48 www 408: my $selout='<select name="'.$name.'">';
409: foreach (@idlist) {
410: $selout.='<option value=\''.$_.'\'';
411: if ($_ eq $value) {
412: $selout.=' selected>'.&{$functionref}($_).'</option>';
413: }
414: else {$selout.='>'.&{$functionref}($_).'</option>';}
415: }
416: return $selout.'</select>';
417: }
418:
1.54 www 419: sub relatedfield {
420: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
1.65 matthew 421: if (! $relatedsearchflag) {
422: return '';
423: }
424: if (! defined($relatedsep)) {
425: $relatedsep=' ';
426: }
427: if (! $show) {
428: return $relatedsep.' ';
429: }
1.54 www 430: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
431: ($relatedvalue?' checked="1"':'').' />';
432: }
1.48 www 433:
1.46 www 434: sub prettyinput {
1.54 www 435: my ($type,$value,$fieldname,$formname,
1.74 matthew 436: $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
1.75 matthew 437: if (! defined($size)) {
438: $size = 80;
439: }
1.64 matthew 440: # Language
1.48 www 441: if ($type eq 'language') {
442: return &selectbox($fieldname,
443: $value,
444: \&Apache::loncommon::languagedescription,
1.54 www 445: (&Apache::loncommon::languageids)).
1.64 matthew 446: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 447: }
1.64 matthew 448: # Copyright
1.48 www 449: if ($type eq 'copyright') {
450: return &selectbox($fieldname,
451: $value,
452: \&Apache::loncommon::copyrightdescription,
1.54 www 453: (&Apache::loncommon::copyrightids)).
1.64 matthew 454: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 455: }
1.78 taceyjo1 456: # Source Copyright
457: if ($type eq 'sourceavail') {
458: return &selectbox($fieldname,
459: $value,
460: \&Apache::loncommon::source_copyrightdescription,
461: (&Apache::loncommon::source_copyrightids)).
462: &relatedfield(0,$relatedsearchflag,$relatedsep);
463: }
1.64 matthew 464: # Gradelevels
1.48 www 465: if (($type eq 'lowestgradelevel') ||
466: ($type eq 'highestgradelevel')) {
1.54 www 467: return &Apache::loncommon::select_level_form($value,$fieldname).
1.64 matthew 468: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 469: }
1.64 matthew 470: # Obsolete
1.48 www 471: if ($type eq 'obsolete') {
472: return '<input type="checkbox" name="'.$fieldname.'"'.
1.54 www 473: ($value?' checked="1"':'').' />'.
1.64 matthew 474: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 475: }
1.64 matthew 476: # Obsolete replacement file
1.48 www 477: if ($type eq 'obsoletereplacement') {
478: return '<input type="text" name="'.$fieldname.
479: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
480: "('".$formname."','".$fieldname."'".
1.54 www 481: ",'')\">".&mt('Select').'</a>'.
1.64 matthew 482: &relatedfield(0,$relatedsearchflag,$relatedsep);
483: }
484: # Customdistribution file
1.48 www 485: if ($type eq 'customdistributionfile') {
486: return '<input type="text" name="'.$fieldname.
487: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
488: "('".$formname."','".$fieldname."'".
1.54 www 489: ",'rights')\">".&mt('Select').'</a>'.
1.64 matthew 490: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 491: }
1.78 taceyjo1 492: # Source Customdistribution file
493: if ($type eq 'sourcerights') {
494: return '<input type="text" name="'.$fieldname.
495: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
496: "('".$formname."','".$fieldname."'".
497: ",'rights')\">".&mt('Select').'</a>'.
498: &relatedfield(0,$relatedsearchflag,$relatedsep);
499: }
1.64 matthew 500: # Dates
1.48 www 501: if (($type eq 'creationdate') ||
502: ($type eq 'lastrevisiondate')) {
1.64 matthew 503: return
504: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
505: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 506: }
1.64 matthew 507: # No pretty input found
1.48 www 508: $value=~s/^\s+//gs;
509: $value=~s/\s+$//gs;
510: $value=~s/\s+/ /gs;
1.77 matthew 511: $value=~s/\"/\"\;/gs;
1.54 www 512: return
1.74 matthew 513: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
1.64 matthew 514: 'value="'.$value.'" />'.
515: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
516: $relatedvalue);
1.46 www 517: }
518:
1.64 matthew 519: # Main Handler
1.1 www 520: sub handler {
1.64 matthew 521: my $r=shift;
522: #
1.67 matthew 523: my $uri=$r->uri;
524: #
525: # Set document type
526: &Apache::loncommon::content_type($r,'text/html');
527: $r->send_http_header;
528: return OK if $r->header_only;
1.64 matthew 529: #
1.76 matthew 530: my ($resdomain,$resuser)=
531: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
1.67 matthew 532: $r->print('<html><head><title>'.
533: 'Catalog Information'.
534: '</title></head>');
1.66 matthew 535: if ($uri=~m:/adm/bombs/(.*)$:) {
1.67 matthew 536: $r->print(&Apache::loncommon::bodytag('Error Messages'));
1.66 matthew 537: # Looking for all bombs?
538: &report_bombs($r,$uri);
539: } elsif ($uri=~/^\/\~/) {
540: # Construction space
1.67 matthew 541: $r->print(&Apache::loncommon::bodytag
542: ('Edit Catalog Information','','','',$resdomain));
1.66 matthew 543: &present_editable_metadata($r,$uri);
544: } else {
1.67 matthew 545: $r->print(&Apache::loncommon::bodytag
546: ('Catalog Information','','','',$resdomain));
1.66 matthew 547: &present_uneditable_metadata($r,$uri);
548: }
1.67 matthew 549: $r->print('</body></html>');
1.66 matthew 550: return OK;
551: }
552:
1.67 matthew 553: #####################################################
554: #####################################################
555: ### ###
556: ### Report Bombs ###
557: ### ###
558: #####################################################
559: #####################################################
1.66 matthew 560: sub report_bombs {
561: my ($r,$uri) = @_;
562: # Set document type
1.67 matthew 563: $uri =~ s:/adm/bombs/::;
564: $uri = &Apache::lonnet::declutter($uri);
1.66 matthew 565: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
566: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
567: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
1.67 matthew 568: my %brokenurls =
569: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
570: foreach (sort(keys(%brokenurls))) {
1.66 matthew 571: if ($_=~/^\Q$uri\E/) {
1.70 matthew 572: $r->print
573: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
574: &Apache::lonmsg::retrieve_author_res_msg($_).
575: '<hr />');
1.64 matthew 576: }
577: }
1.66 matthew 578: } else {
579: $r->print(&mt('Not authorized'));
580: }
581: return;
582: }
583:
1.67 matthew 584: #####################################################
585: #####################################################
586: ### ###
587: ### Uneditable Metadata Display ###
588: ### ###
589: #####################################################
590: #####################################################
1.66 matthew 591: sub present_uneditable_metadata {
592: my ($r,$uri) = @_;
593: #
594: my %content=();
595: # Read file
596: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
597: $content{$_}=&Apache::lonnet::metadata($uri,$_);
598: }
599: # Render Output
600: # displayed url
601: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
602: $uri=~s/\.meta$//;
603: my $disuri=&Apache::lonnet::clutter($uri);
604: # version
605: my $currentversion=&Apache::lonnet::getversion($disuri);
606: my $versiondisplay='';
607: if ($thisversion) {
608: $versiondisplay=&mt('Version').': '.$thisversion.
609: ' ('.&mt('most recent version').': '.
610: ($currentversion>0 ?
611: $currentversion :
612: &mt('information not available')).')';
613: } else {
614: $versiondisplay='Version: '.$currentversion;
615: }
1.72 matthew 616: # crumbify displayed URL uri target prefix form size
617: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
618: $disuri =~ s:<br />::g;
1.66 matthew 619: # obsolete
620: my $obsolete=$content{'obsolete'};
621: my $obsoletewarning='';
622: if (($obsolete) && ($ENV{'user.adv'})) {
623: $obsoletewarning='<p><font color="red">'.
624: &mt('This resource has been marked obsolete by the author(s)').
625: '</font></p>';
626: }
627: #
628: my %lt=&fieldnames();
629: my $table='';
1.72 matthew 630: my $title = $content{'title'};
631: if (! defined($title)) {
632: $title = 'Untitled Resource';
633: }
1.66 matthew 634: foreach ('title',
635: 'author',
636: 'subject',
637: 'keywords',
638: 'notes',
639: 'abstract',
640: 'lowestgradelevel',
641: 'highestgradelevel',
642: 'standards',
643: 'mime',
644: 'language',
645: 'creationdate',
646: 'lastrevisiondate',
647: 'owner',
648: 'copyright',
1.78 taceyjo1 649: 'customdistributionfile',
650: 'sourceavail',
651: 'sourcerights',
1.66 matthew 652: 'obsolete',
653: 'obsoletereplacement') {
654: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
655: '</td><td bgcolor="#CCCCCC">'.
656: &prettyprint($_,$content{$_}).'</td></tr>';
657: delete $content{$_};
658: }
659: #
660: $r->print(<<ENDHEAD);
1.72 matthew 661: <h2>$title</h2>
662: <p>
663: $disuri<br />
1.36 www 664: $obsoletewarning
1.72 matthew 665: $versiondisplay
666: </p>
1.11 www 667: <table cellspacing=2 border=0>
1.45 www 668: $table
1.11 www 669: </table>
1.1 www 670: ENDHEAD
1.66 matthew 671: if ($ENV{'user.adv'}) {
1.68 matthew 672: &print_dynamic_metadata($r,$uri,\%content);
1.67 matthew 673: }
674: return;
675: }
676:
677: sub print_dynamic_metadata {
1.68 matthew 678: my ($r,$uri,$content) = @_;
679: #
1.69 matthew 680: my %content = %$content;
1.68 matthew 681: my %lt=&fieldnames();
1.67 matthew 682: #
683: my $description = 'Dynamic Metadata (updated periodically)';
684: $r->print('<h3>'.&mt($description).'</h3>'.
1.70 matthew 685: &mt('Processing'));
1.67 matthew 686: $r->rflush();
687: my %items=&fieldnames();
688: my %dynmeta=&dynamicmeta($uri);
689: #
690: # General Access and Usage Statistics
1.70 matthew 691: if (exists($dynmeta{'count'}) ||
692: exists($dynmeta{'sequsage'}) ||
693: exists($dynmeta{'comefrom'}) ||
694: exists($dynmeta{'goto'}) ||
695: exists($dynmeta{'course'})) {
696: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
697: '<table cellspacing=2 border=0>');
698: foreach ('count',
699: 'sequsage','sequsage_list',
700: 'comefrom','comefrom_list',
701: 'goto','goto_list',
702: 'course','course_list') {
703: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
704: '<td bgcolor="#CCCCCC">'.
705: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
706: }
707: $r->print('</table>');
708: } else {
709: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
1.67 matthew 710: }
1.69 matthew 711: #
712: # Assessment statistics
1.73 matthew 713: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
714: if (exists($dynmeta{'stdno'}) ||
715: exists($dynmeta{'avetries'}) ||
716: exists($dynmeta{'difficulty'}) ||
717: exists($dynmeta{'disc'})) {
718: # This is an assessment, print assessment data
719: $r->print('<h4>'.
720: &mt('Overall Assessment Statistical Data').
721: '</h4>'.
722: '<table cellspacing=2 border=0>');
723: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
1.66 matthew 724: '<td bgcolor="#CCCCCC">'.
1.73 matthew 725: &prettyprint('stdno',$dynmeta{'stdno'}).
726: '</td>'."</tr>\n");
727: foreach ('avetries','difficulty','disc') {
728: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
729: '<td bgcolor="#CCCCCC">'.
730: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
731: '</td>'."</tr>\n");
732: }
733: $r->print('</table>');
734: }
735: if (exists($dynmeta{'stats'})) {
736: #
737: # New assessment statistics
738: $r->print('<h4>'.
739: &mt('Detailed Assessment Statistical Data').
740: '</h4>');
741: my $table = '<table cellspacing=2 border=0>'.
742: '<tr>'.
743: '<th>Course</th>'.
744: '<th>Section(s)</th>'.
745: '<th>Num Students</th>'.
746: '<th>Mean Tries</th>'.
747: '<th>Degree of Difficulty</th>'.
748: '<th>Degree of Discrimination</th>'.
749: '<th>Time of computation</th>'.
750: '</tr>'.$/;
751: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
752: my $data = $dynmeta{'stats'}->{$identifier};
753: my $course = $data->{'course'};
754: my %courseinfo = &Apache::lonnet::coursedescription($course);
755: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
756: &Apache::lonnet::logthis('lookup for '.$course.' failed');
757: next;
758: }
759: $table .= '<tr>';
760: $table .=
761: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
762: $table .=
763: '<td align="right">'.$data->{'sections'}.'</td>';
764: $table .=
765: '<td align="right">'.$data->{'stdno'}.'</td>';
766: foreach ('avetries','difficulty','disc') {
767: $table .= '<td align="right">';
768: if (exists($data->{$_})) {
769: $table .= sprintf('%.2f',$data->{$_}).' ';
770: } else {
771: $table .= '';
772: }
773: $table .= '</td>';
774: }
775: $table .=
776: '<td><nobr>'.
777: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
778: '</nobr></td>';
779: $table .=
780: '</tr>'.$/;
781: }
782: $table .= '</table>'.$/;
783: $r->print($table);
784: } else {
785: $r->print('No new dynamic data found.');
1.66 matthew 786: }
1.70 matthew 787: } else {
1.73 matthew 788: $r->print('<h4>'.
789: &mt('No Assessment Statistical Data is available for this resource').
790: '</h4>');
1.67 matthew 791: }
1.73 matthew 792:
793: #
794: #
1.70 matthew 795: if (exists($dynmeta{'clear'}) ||
796: exists($dynmeta{'depth'}) ||
797: exists($dynmeta{'helpful'}) ||
798: exists($dynmeta{'correct'}) ||
799: exists($dynmeta{'technical'})){
800: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
801: '<table cellspacing=2 border=0>');
802: foreach ('clear','depth','helpful','correct','technical') {
803: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
804: '<td bgcolor="#CCCCCC">'.
805: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
806: }
807: $r->print('</table>');
808: } else {
809: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1.67 matthew 810: }
811: $uri=~/^\/res\/(\w+)\/(\w+)\//;
812: if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
813: || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
1.70 matthew 814: if (exists($dynmeta{'comments'})) {
815: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
816: &mt('visible to author and co-authors only').
817: ')</h4>'.
818: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
819: } else {
820: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
821: }
822: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
823: if (defined($bombs) && $bombs ne '') {
824: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
825: &mt('visible to author and co-authors only').')'.
826: '</h4>'.$bombs);
827: } else {
828: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
829: }
1.67 matthew 830: }
1.69 matthew 831: #
1.67 matthew 832: # All other stuff
833: $r->print('<h3>'.
834: &mt('Additional Metadata (non-standard, parameters, exports)').
835: '</h3>');
836: foreach (sort(keys(%content))) {
837: my $name=$_;
838: if ($name!~/\.display$/) {
839: my $display=&Apache::lonnet::metadata($uri,
840: $name.'.display');
841: if (! $display) {
842: $display=$name;
843: };
844: my $otherinfo='';
845: foreach ('name','part','type','default') {
846: if (defined(&Apache::lonnet::metadata($uri,
847: $name.'.'.$_))) {
848: $otherinfo.=' '.$_.'='.
849: &Apache::lonnet::metadata($uri,
850: $name.'.'.$_).'; ';
851: }
1.64 matthew 852: }
1.67 matthew 853: $r->print('<b>'.$display.':</b> '.$content{$name});
854: if ($otherinfo) {
855: $r->print(' ('.$otherinfo.')');
1.64 matthew 856: }
1.67 matthew 857: $r->print("<br />\n");
1.64 matthew 858: }
1.66 matthew 859: }
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>