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