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