Annotation of loncom/interface/lonmeta.pm, revision 1.88
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);
540: } elsif ($uri=~/^\/\~/) {
541: # Construction space
1.67 matthew 542: $r->print(&Apache::loncommon::bodytag
543: ('Edit Catalog Information','','','',$resdomain));
1.66 matthew 544: &present_editable_metadata($r,$uri);
545: } else {
1.67 matthew 546: $r->print(&Apache::loncommon::bodytag
1.85 albertel 547: ('Catalog Information','','','',$resdomain));
1.66 matthew 548: &present_uneditable_metadata($r,$uri);
549: }
1.67 matthew 550: $r->print('</body></html>');
1.66 matthew 551: return OK;
552: }
553:
1.67 matthew 554: #####################################################
555: #####################################################
556: ### ###
557: ### Report Bombs ###
558: ### ###
559: #####################################################
560: #####################################################
1.66 matthew 561: sub report_bombs {
562: my ($r,$uri) = @_;
563: # Set document type
1.67 matthew 564: $uri =~ s:/adm/bombs/::;
565: $uri = &Apache::lonnet::declutter($uri);
1.66 matthew 566: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
567: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
568: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
1.67 matthew 569: my %brokenurls =
570: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
571: foreach (sort(keys(%brokenurls))) {
1.66 matthew 572: if ($_=~/^\Q$uri\E/) {
1.70 matthew 573: $r->print
574: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
575: &Apache::lonmsg::retrieve_author_res_msg($_).
576: '<hr />');
1.64 matthew 577: }
578: }
1.66 matthew 579: } else {
580: $r->print(&mt('Not authorized'));
581: }
582: return;
583: }
584:
1.67 matthew 585: #####################################################
586: #####################################################
587: ### ###
588: ### Uneditable Metadata Display ###
589: ### ###
590: #####################################################
591: #####################################################
1.66 matthew 592: sub present_uneditable_metadata {
593: my ($r,$uri) = @_;
594: #
595: my %content=();
596: # Read file
597: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
598: $content{$_}=&Apache::lonnet::metadata($uri,$_);
599: }
600: # Render Output
601: # displayed url
602: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
603: $uri=~s/\.meta$//;
604: my $disuri=&Apache::lonnet::clutter($uri);
605: # version
606: my $currentversion=&Apache::lonnet::getversion($disuri);
607: my $versiondisplay='';
608: if ($thisversion) {
609: $versiondisplay=&mt('Version').': '.$thisversion.
610: ' ('.&mt('most recent version').': '.
611: ($currentversion>0 ?
612: $currentversion :
613: &mt('information not available')).')';
614: } else {
615: $versiondisplay='Version: '.$currentversion;
616: }
1.72 matthew 617: # crumbify displayed URL uri target prefix form size
618: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
619: $disuri =~ s:<br />::g;
1.66 matthew 620: # obsolete
621: my $obsolete=$content{'obsolete'};
622: my $obsoletewarning='';
623: if (($obsolete) && ($ENV{'user.adv'})) {
624: $obsoletewarning='<p><font color="red">'.
625: &mt('This resource has been marked obsolete by the author(s)').
626: '</font></p>';
627: }
628: #
629: my %lt=&fieldnames();
630: my $table='';
1.72 matthew 631: my $title = $content{'title'};
632: if (! defined($title)) {
633: $title = 'Untitled Resource';
634: }
1.66 matthew 635: foreach ('title',
636: 'author',
637: 'subject',
638: 'keywords',
639: 'notes',
640: 'abstract',
641: 'lowestgradelevel',
642: 'highestgradelevel',
643: 'standards',
644: 'mime',
645: 'language',
646: 'creationdate',
647: 'lastrevisiondate',
648: 'owner',
649: 'copyright',
1.78 taceyjo1 650: 'customdistributionfile',
651: 'sourceavail',
652: 'sourcerights',
1.66 matthew 653: 'obsolete',
654: 'obsoletereplacement') {
655: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
656: '</td><td bgcolor="#CCCCCC">'.
657: &prettyprint($_,$content{$_}).'</td></tr>';
658: delete $content{$_};
659: }
660: #
661: $r->print(<<ENDHEAD);
1.72 matthew 662: <h2>$title</h2>
663: <p>
664: $disuri<br />
1.36 www 665: $obsoletewarning
1.72 matthew 666: $versiondisplay
667: </p>
1.88 ! banghart 668: <table cellspacing="2" border="0">
1.45 www 669: $table
1.11 www 670: </table>
1.1 www 671: ENDHEAD
1.66 matthew 672: if ($ENV{'user.adv'}) {
1.68 matthew 673: &print_dynamic_metadata($r,$uri,\%content);
1.67 matthew 674: }
675: return;
676: }
677:
678: sub print_dynamic_metadata {
1.68 matthew 679: my ($r,$uri,$content) = @_;
680: #
1.69 matthew 681: my %content = %$content;
1.68 matthew 682: my %lt=&fieldnames();
1.67 matthew 683: #
684: my $description = 'Dynamic Metadata (updated periodically)';
685: $r->print('<h3>'.&mt($description).'</h3>'.
1.70 matthew 686: &mt('Processing'));
1.67 matthew 687: $r->rflush();
688: my %items=&fieldnames();
689: my %dynmeta=&dynamicmeta($uri);
690: #
691: # General Access and Usage Statistics
1.70 matthew 692: if (exists($dynmeta{'count'}) ||
693: exists($dynmeta{'sequsage'}) ||
694: exists($dynmeta{'comefrom'}) ||
695: exists($dynmeta{'goto'}) ||
696: exists($dynmeta{'course'})) {
697: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
1.88 ! banghart 698: '<table cellspacing="2" border="0">');
1.70 matthew 699: foreach ('count',
700: 'sequsage','sequsage_list',
701: 'comefrom','comefrom_list',
702: 'goto','goto_list',
703: 'course','course_list') {
704: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
705: '<td bgcolor="#CCCCCC">'.
706: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
707: }
708: $r->print('</table>');
709: } else {
710: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
1.67 matthew 711: }
1.69 matthew 712: #
713: # Assessment statistics
1.73 matthew 714: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
715: if (exists($dynmeta{'stdno'}) ||
716: exists($dynmeta{'avetries'}) ||
717: exists($dynmeta{'difficulty'}) ||
718: exists($dynmeta{'disc'})) {
719: # This is an assessment, print assessment data
720: $r->print('<h4>'.
721: &mt('Overall Assessment Statistical Data').
722: '</h4>'.
1.88 ! banghart 723: '<table cellspacing="2" border="0">');
1.73 matthew 724: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
1.66 matthew 725: '<td bgcolor="#CCCCCC">'.
1.73 matthew 726: &prettyprint('stdno',$dynmeta{'stdno'}).
727: '</td>'."</tr>\n");
728: foreach ('avetries','difficulty','disc') {
729: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
730: '<td bgcolor="#CCCCCC">'.
731: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
732: '</td>'."</tr>\n");
733: }
734: $r->print('</table>');
735: }
736: if (exists($dynmeta{'stats'})) {
737: #
738: # New assessment statistics
739: $r->print('<h4>'.
740: &mt('Detailed Assessment Statistical Data').
741: '</h4>');
1.88 ! banghart 742: my $table = '<table cellspacing="2" border="0">'.
1.73 matthew 743: '<tr>'.
744: '<th>Course</th>'.
745: '<th>Section(s)</th>'.
746: '<th>Num Students</th>'.
747: '<th>Mean Tries</th>'.
748: '<th>Degree of Difficulty</th>'.
749: '<th>Degree of Discrimination</th>'.
750: '<th>Time of computation</th>'.
751: '</tr>'.$/;
752: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
753: my $data = $dynmeta{'stats'}->{$identifier};
754: my $course = $data->{'course'};
755: my %courseinfo = &Apache::lonnet::coursedescription($course);
756: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
757: &Apache::lonnet::logthis('lookup for '.$course.' failed');
758: next;
759: }
760: $table .= '<tr>';
761: $table .=
762: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
763: $table .=
764: '<td align="right">'.$data->{'sections'}.'</td>';
765: $table .=
766: '<td align="right">'.$data->{'stdno'}.'</td>';
767: foreach ('avetries','difficulty','disc') {
768: $table .= '<td align="right">';
769: if (exists($data->{$_})) {
770: $table .= sprintf('%.2f',$data->{$_}).' ';
771: } else {
772: $table .= '';
773: }
774: $table .= '</td>';
775: }
776: $table .=
777: '<td><nobr>'.
778: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
779: '</nobr></td>';
780: $table .=
781: '</tr>'.$/;
782: }
783: $table .= '</table>'.$/;
784: $r->print($table);
785: } else {
786: $r->print('No new dynamic data found.');
1.66 matthew 787: }
1.70 matthew 788: } else {
1.73 matthew 789: $r->print('<h4>'.
790: &mt('No Assessment Statistical Data is available for this resource').
791: '</h4>');
1.67 matthew 792: }
1.73 matthew 793:
794: #
795: #
1.70 matthew 796: if (exists($dynmeta{'clear'}) ||
797: exists($dynmeta{'depth'}) ||
798: exists($dynmeta{'helpful'}) ||
799: exists($dynmeta{'correct'}) ||
800: exists($dynmeta{'technical'})){
801: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
1.88 ! banghart 802: '<table cellspacing="2" border="0">');
1.70 matthew 803: foreach ('clear','depth','helpful','correct','technical') {
804: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
805: '<td bgcolor="#CCCCCC">'.
806: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
807: }
808: $r->print('</table>');
809: } else {
810: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1.67 matthew 811: }
812: $uri=~/^\/res\/(\w+)\/(\w+)\//;
813: if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
814: || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
1.70 matthew 815: if (exists($dynmeta{'comments'})) {
816: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
817: &mt('visible to author and co-authors only').
818: ')</h4>'.
819: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
820: } else {
821: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
822: }
823: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
824: if (defined($bombs) && $bombs ne '') {
825: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
826: &mt('visible to author and co-authors only').')'.
827: '</h4>'.$bombs);
828: } else {
829: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
830: }
1.67 matthew 831: }
1.69 matthew 832: #
1.67 matthew 833: # All other stuff
834: $r->print('<h3>'.
835: &mt('Additional Metadata (non-standard, parameters, exports)').
1.81 www 836: '</h3><table border="0" cellspacing="1">');
1.67 matthew 837: foreach (sort(keys(%content))) {
838: my $name=$_;
839: if ($name!~/\.display$/) {
840: my $display=&Apache::lonnet::metadata($uri,
841: $name.'.display');
842: if (! $display) {
843: $display=$name;
844: };
845: my $otherinfo='';
846: foreach ('name','part','type','default') {
847: if (defined(&Apache::lonnet::metadata($uri,
848: $name.'.'.$_))) {
849: $otherinfo.=' '.$_.'='.
850: &Apache::lonnet::metadata($uri,
851: $name.'.'.$_).'; ';
852: }
1.64 matthew 853: }
1.81 www 854: $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 855: if ($otherinfo) {
856: $r->print(' ('.$otherinfo.')');
1.64 matthew 857: }
1.81 www 858: $r->print("</font></td></tr>\n");
1.64 matthew 859: }
1.66 matthew 860: }
1.81 www 861: $r->print("</table>");
1.67 matthew 862: return;
1.66 matthew 863: }
864:
1.67 matthew 865: #####################################################
866: #####################################################
867: ### ###
868: ### Editable metadata display ###
869: ### ###
870: #####################################################
871: #####################################################
1.66 matthew 872: sub present_editable_metadata {
873: my ($r,$uri) = @_;
874: # Construction Space Call
875: # Header
876: my $disuri=$uri;
877: my $fn=&Apache::lonnet::filelocation('',$uri);
878: $disuri=~s/^\/\~/\/priv\//;
879: $disuri=~s/\.meta$//;
880: my $target=$uri;
881: $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
882: $target=~s/\.meta$//;
883: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
884: if ($bombs) {
885: if ($ENV{'form.delmsg'}) {
886: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
887: $bombs=&mt('Messages deleted.');
888: } else {
889: $bombs=&mt('Error deleting messages');
1.64 matthew 890: }
1.66 matthew 891: }
892: my $del=&mt('Delete Messages');
893: $r->print(<<ENDBOMBS);
1.52 www 894: <h1>$disuri</h1>
895: <form method="post" name="defaultmeta">
1.59 www 896: <input type="submit" name="delmsg" value="$del" />
1.52 www 897: <br />$bombs
898: ENDBOMBS
1.66 matthew 899: } else {
900: my $displayfile='Catalog Information for '.$disuri;
901: if ($disuri=~/\/default$/) {
902: my $dir=$disuri;
903: $dir=~s/default$//;
904: $displayfile=
905: &mt('Default Cataloging Information for Directory').' '.
906: $dir;
907: }
908: %Apache::lonpublisher::metadatafields=();
909: %Apache::lonpublisher::metadatakeys=();
910: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
911: $r->print(<<ENDEDIT);
1.23 www 912: <h1>$displayfile</h1>
1.48 www 913: <form method="post" name="defaultmeta">
1.23 www 914: ENDEDIT
1.66 matthew 915: $r->print('<script language="JavaScript">'.
1.86 albertel 916: &Apache::loncommon::browser_and_searcher_javascript().
1.66 matthew 917: '</script>');
918: my %lt=&fieldnames();
1.87 albertel 919: my $output;
1.66 matthew 920: foreach ('author','title','subject','keywords','abstract','notes',
921: 'copyright','customdistributionfile','language',
922: 'standards',
1.78 taceyjo1 923: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1.66 matthew 924: 'obsolete','obsoletereplacement') {
925: if (defined($ENV{'form.new_'.$_})) {
926: $Apache::lonpublisher::metadatafields{$_}=
927: $ENV{'form.new_'.$_};
928: }
929: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
930: $Apache::lonpublisher::metadatafields{'copyright'}=
931: 'default';
1.64 matthew 932: }
1.87 albertel 933: $output.=('<p>'.$lt{$_}.': '.
934: &prettyinput($_,
935: $Apache::lonpublisher::metadatafields{$_},
936: 'new_'.$_,'defaultmeta').'</p>');
1.66 matthew 937: }
938: if ($ENV{'form.store'}) {
939: my $mfh;
940: if (! ($mfh=Apache::File->new('>'.$fn))) {
1.87 albertel 941: $r->print('<p><font color="red">'.
1.66 matthew 942: &mt('Could not write metadata').', '.
1.87 albertel 943: &mt('FAIL').'</font></p>');
1.66 matthew 944: } else {
945: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1.67 matthew 946: next if ($_ =~ /\./);
947: my $unikey=$_;
948: $unikey=~/^([A-Za-z]+)/;
949: my $tag=$1;
950: $tag=~tr/A-Z/a-z/;
951: print $mfh "\n\<$tag";
952: foreach (split(/\,/,
1.64 matthew 953: $Apache::lonpublisher::metadatakeys{$unikey})
1.67 matthew 954: ) {
955: my $value=
956: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
957: $value=~s/\"/\'\'/g;
958: print $mfh ' '.$_.'="'.$value.'"';
1.64 matthew 959: }
1.67 matthew 960: print $mfh '>'.
961: &HTML::Entities::encode
962: ($Apache::lonpublisher::metadatafields{$unikey},
963: '<>&"').
964: '</'.$tag.'>';
1.64 matthew 965: }
1.87 albertel 966: $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
967: ' '.&Apache::lonlocal::locallocaltime(time).
968: '</font></p>');
1.64 matthew 969: }
970: }
1.87 albertel 971: $r->print($output.'<br /><input type="submit" name="store" value="'.
1.67 matthew 972: &mt('Store Catalog Information').'">');
1.64 matthew 973: }
1.67 matthew 974: $r->print('</form>');
1.66 matthew 975: return;
1.1 www 976: }
1.64 matthew 977:
1.1 www 978: 1;
979: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>