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