Annotation of loncom/interface/lonmeta.pm, revision 1.165
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.165 ! banghart 4: # $Id: lonmeta.pm,v 1.164 2006/08/04 22:16:38 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: #
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.157 www 42: use lib '/home/httpd/lib/perl/';
43: use LONCAPA;
1.1 www 44:
1.44 www 45:
1.80 matthew 46: ############################################################
47: ############################################################
48: ##
49: ## &get_dynamic_metadata_from_sql($url)
50: ##
51: ## Queries sql database for dynamic metdata
52: ## Returns a hash of hashes, with keys of urls which match $url
53: ## Returned fields are given below.
54: ##
55: ## Examples:
56: ##
57: ## %DynamicMetadata = &Apache::lonmeta::get_dynmaic_metadata_from_sql
58: ## ('/res/msu/korte/');
59: ##
60: ## $DynamicMetadata{'/res/msu/korte/example.problem'}->{$field}
61: ##
62: ############################################################
63: ############################################################
64: sub get_dynamic_metadata_from_sql {
65: my ($url) = shift();
66: my ($authordom,$author)=($url=~m:^/res/(\w+)/(\w+)/:);
67: if (! defined($authordom)) {
68: $authordom = shift();
69: }
70: if (! defined($author)) {
71: $author = shift();
72: }
73: if (! defined($authordom) || ! defined($author)) {
74: return ();
75: }
1.158 www 76: my $query = 'SELECT * FROM metadata WHERE url LIKE "'.$url.'%"';
1.80 matthew 77: my $server = &Apache::lonnet::homeserver($author,$authordom);
78: my $reply = &Apache::lonnet::metadata_query($query,undef,undef,
79: ,[$server]);
80: return () if (! defined($reply) || ref($reply) ne 'HASH');
81: my $filename = $reply->{$server};
82: if (! defined($filename) || $filename =~ /^error/) {
83: return ();
84: }
85: my $max_time = time + 10; # wait 10 seconds for results at most
86: my %ReturnHash;
87: #
88: # Look for results
89: my $finished = 0;
90: while (! $finished && time < $max_time) {
91: my $datafile=$Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/'.$filename;
92: if (! -e "$datafile.end") { next; }
93: my $fh;
94: if (!($fh=Apache::File->new($datafile))) { next; }
95: while (my $result = <$fh>) {
96: chomp($result);
97: next if (! $result);
1.158 www 98: my %hash=&LONCAPA::lonmetadata::metadata_col_to_hash(map { &unescape($_) } split(/\,/,$result));
99: foreach my $key (keys(%hash)) {
100: $ReturnHash{$hash{'url'}}->{$key}=$hash{$key};
1.80 matthew 101: }
102: }
103: $finished = 1;
104: }
105: #
106: return %ReturnHash;
107: }
108:
109:
1.64 matthew 110: # Fetch and evaluate dynamic metadata
1.9 www 111: sub dynamicmeta {
112: my $url=&Apache::lonnet::declutter(shift);
113: $url=~s/\.meta$//;
114: my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
1.19 www 115: my $regexp=$url;
1.9 www 116: $regexp=~s/(\W)/\\$1/g;
1.10 www 117: $regexp='___'.$regexp.'___';
1.16 albertel 118: my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
119: $aauthor,$regexp);
1.63 matthew 120: my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
121: my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
122: \%DynamicData);
1.40 matthew 123: #
1.46 www 124: # Deal with 'count' separately
1.63 matthew 125: $Data{'count'} = &access_count($url,$aauthor,$adomain);
1.67 matthew 126: #
127: # Debugging code I will probably need later
128: if (0) {
129: &Apache::lonnet::logthis('Dynamic Metadata');
130: while(my($k,$v)=each(%Data)){
131: &Apache::lonnet::logthis(' "'.$k.'"=>"'.$v.'"');
132: }
133: &Apache::lonnet::logthis('-------------------');
134: }
1.63 matthew 135: return %Data;
1.40 matthew 136: }
137:
138: sub access_count {
139: my ($src,$author,$adomain) = @_;
140: my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
141: $author,$src);
142: if (! exists($countdata{$src})) {
1.47 www 143: return &mt('Not Available');
1.40 matthew 144: } else {
145: return $countdata{$src};
146: }
1.25 www 147: }
148:
1.64 matthew 149: # Try to make an alt tag if there is none
1.25 www 150: sub alttag {
1.26 www 151: my ($base,$src)=@_;
152: my $fullpath=&Apache::lonnet::hreflocation($base,$src);
153: my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
1.64 matthew 154: &Apache::lonnet::metadata($fullpath,'subject').' '.
155: &Apache::lonnet::metadata($fullpath,'abstract');
1.26 www 156: $alttag=~s/\s+/ /gs;
157: $alttag=~s/\"//gs;
158: $alttag=~s/\'//gs;
159: $alttag=~s/\s+$//gs;
160: $alttag=~s/^\s+//gs;
1.64 matthew 161: if ($alttag) {
162: return $alttag;
163: } else {
164: return &mt('No information available');
165: }
1.9 www 166: }
1.1 www 167:
1.64 matthew 168: # Author display
1.29 www 169: sub authordisplay {
170: my ($aname,$adom)=@_;
1.64 matthew 171: return &Apache::loncommon::aboutmewrapper
172: (&Apache::loncommon::plainname($aname,$adom),
1.164 albertel 173: $aname,$adom,'preview').' <tt>['.$aname.':'.$adom.']</tt>';
1.29 www 174: }
175:
1.64 matthew 176: # Pretty display
1.12 www 177: sub evalgraph {
178: my $value=shift;
1.65 matthew 179: if (! $value) {
180: return '';
181: }
1.12 www 182: my $val=int($value*10.+0.5)-10;
1.71 matthew 183: my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
1.12 www 184: if ($val>=20) {
1.71 matthew 185: $output.='<td width="20" bgcolor="#555555">  </td>';
1.12 www 186: } else {
1.71 matthew 187: $output.='<td width="'.($val).'" bgcolor="#555555"> </td>'.
188: '<td width="'.(20-$val).'" bgcolor="#FF3333"> </td>';
1.12 www 189: }
190: $output.='<td bgcolor="#FFFF33"> </td>';
191: if ($val>20) {
1.71 matthew 192: $output.='<td width="'.($val-20).'" bgcolor="#33FF33"> </td>'.
193: '<td width="'.(40-$val).'" bgcolor="#555555"> </td>';
1.12 www 194: } else {
1.71 matthew 195: $output.='<td width="20" bgcolor="#555555">  </td>';
1.12 www 196: }
1.71 matthew 197: $output.='<td> ('.sprintf("%5.2f",$value).') </td></tr></table>';
1.12 www 198: return $output;
199: }
200:
201: sub diffgraph {
202: my $value=shift;
1.65 matthew 203: if (! $value) {
204: return '';
205: }
1.12 www 206: my $val=int(40.0*$value+0.5);
1.13 www 207: my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
208: '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
1.71 matthew 209: my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
1.12 www 210: for (my $i=0;$i<8;$i++) {
211: if ($val>$i*5) {
1.71 matthew 212: $output.='<td width="5" bgcolor="'.$colors[$i].'"> </td>';
1.12 www 213: } else {
1.71 matthew 214: $output.='<td width="5" bgcolor="#555555"> </td>';
1.12 www 215: }
216: }
1.71 matthew 217: $output.='<td> ('.sprintf("%3.2f",$value).') </td></tr></table>';
1.12 www 218: return $output;
219: }
220:
1.44 www 221:
1.64 matthew 222: # The field names
1.45 www 223: sub fieldnames {
1.90 banghart 224: my $file_type=shift;
1.115 banghart 225: my %fields =
226: ('title' => 'Title',
1.113 banghart 227: 'author' =>'Author(s)',
1.131 albertel 228: 'authorspace' => 'Author Space',
229: 'modifyinguser' => 'Last Modifying User',
1.113 banghart 230: 'subject' => 'Subject',
1.133 banghart 231: 'standards' => 'Standards',
1.113 banghart 232: 'keywords' => 'Keyword(s)',
233: 'notes' => 'Notes',
234: 'abstract' => 'Abstract',
235: 'lowestgradelevel' => 'Lowest Grade Level',
1.149 albertel 236: 'highestgradelevel' => 'Highest Grade Level');
237:
238: if (! defined($file_type) || $file_type ne 'portfolio') {
239: %fields =
240: (%fields,
241: 'courserestricted' => 'Course Restricting Metadata');
242: }
1.120 banghart 243:
1.93 matthew 244: if (! defined($file_type) || $file_type ne 'portfolio') {
245: %fields =
246: (%fields,
247: 'domain' => 'Domain',
1.64 matthew 248: 'mime' => 'MIME Type',
249: 'language' => 'Language',
250: 'creationdate' => 'Creation Date',
251: 'lastrevisiondate' => 'Last Revision Date',
252: 'owner' => 'Publisher/Owner',
253: 'copyright' => 'Copyright/Distribution',
254: 'customdistributionfile' => 'Custom Distribution File',
1.84 banghart 255: 'sourceavail' => 'Source Available',
1.78 taceyjo1 256: 'sourcerights' => 'Source Custom Distribution File',
1.64 matthew 257: 'obsolete' => 'Obsolete',
258: 'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
259: 'count' => 'Network-wide number of accesses (hits)',
260: 'course' => 'Network-wide number of courses using resource',
261: 'course_list' => 'Network-wide courses using resource',
262: 'sequsage' => 'Number of resources using or importing resource',
263: 'sequsage_list' => 'Resources using or importing resource',
264: 'goto' => 'Number of resources that follow this resource in maps',
265: 'goto_list' => 'Resources that follow this resource in maps',
266: 'comefrom' => 'Number of resources that lead up to this resource in maps',
267: 'comefrom_list' => 'Resources that lead up to this resource in maps',
268: 'clear' => 'Material presented in clear way',
269: 'depth' => 'Material covered with sufficient depth',
270: 'helpful' => 'Material is helpful',
271: 'correct' => 'Material appears to be correct',
272: 'technical' => 'Resource is technically correct',
273: 'avetries' => 'Average number of tries till solved',
274: 'stdno' => 'Total number of students who have worked on this problem',
1.73 matthew 275: 'difficulty' => 'Degree of difficulty',
276: 'disc' => 'Degree of discrimination',
1.133 banghart 277: 'dependencies' => 'Resources used by this resource',
1.64 matthew 278: );
1.93 matthew 279: }
280: return &Apache::lonlocal::texthash(%fields);
1.45 www 281: }
1.141 albertel 282:
1.146 albertel 283: sub portfolio_linked_path {
1.155 albertel 284: my ($path,$group,$port_path) = @_;
285:
286: my $start = 'portfolio';
287: if ($group) {
288: $start = "groups/$group/".$start;
289: }
1.165 ! banghart 290: my %anchor_fields;
! 291: %anchor_fields = (
! 292: 'selectfile' => $start,
! 293: 'currentpath' => '/'
! 294: );
! 295: my $result = &Apache::portfolio::make_anchor($port_path,\%anchor_fields,$start);
1.146 albertel 296: my $fullpath = '/';
297: my (undef,@tree) = split('/',$path);
1.147 albertel 298: my $filename = pop(@tree);
1.146 albertel 299: foreach my $dir (@tree) {
300: $fullpath .= $dir.'/';
301: $result .= '/';
1.165 ! banghart 302: my %anchor_fields = ();
! 303: %anchor_fields = (
! 304: 'selectfile' => $dir,
! 305: 'currentpath' => $fullpath
! 306: );
! 307: $result .= &Apache::portfolio::make_anchor($port_path,\%anchor_fields,$dir);
1.146 albertel 308: }
1.147 albertel 309: $result .= "/$filename";
1.146 albertel 310: return $result;
311: }
312:
1.156 albertel 313: sub get_port_path_and_group {
314: my ($uri)=@_;
315:
1.155 albertel 316: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
317: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.156 albertel 318:
1.155 albertel 319: my ($port_path,$group);
320: if ($uri =~ m{^/editupload/\Q$cdom\E/\Q$cnum\E/groups/}) {
321: $group = (split('/',$uri))[5];
322: $port_path = '/adm/coursegrp_portfolio';
323: } else {
324: $port_path = '/adm/portfolio';
325: }
1.160 albertel 326: if ($env{'form.group'} ne $group) {
1.161 albertel 327: $env{'form.group'} = $group;
1.160 albertel 328: }
1.156 albertel 329: return ($port_path,$group);
330: }
331:
332: sub portfolio_display_uri {
333: my ($uri,$as_links)=@_;
334:
335: my ($port_path,$group) = &get_port_path_and_group($uri);
336:
1.144 albertel 337: $uri =~ s|.*/(portfolio/.*)$|$1|;
1.141 albertel 338: my ($res_uri,$meta_uri) = ($uri,$uri);
339: if ($uri =~ /\.meta$/) {
340: $res_uri =~ s/\.meta//;
341: } else {
342: $meta_uri .= '.meta';
343: }
1.146 albertel 344:
1.148 albertel 345: my ($path) = ($res_uri =~ m|^portfolio(.*/)[^/]*$|);
1.146 albertel 346: if ($as_links) {
1.155 albertel 347: $res_uri = &portfolio_linked_path($res_uri,$group,$port_path);
348: $meta_uri = &portfolio_linked_path($meta_uri,$group,$port_path);
1.146 albertel 349: }
1.145 albertel 350: return ($res_uri,$meta_uri,$path);
1.141 albertel 351: }
352:
1.140 banghart 353: sub pre_select_course {
354: my ($r,$uri) = @_;
355: my $output;
356: my $fn=&Apache::lonnet::filelocation('',$uri);
1.145 albertel 357: my ($res_uri,$meta_uri,$path) = &portfolio_display_uri($uri);
1.140 banghart 358: %Apache::lonpublisher::metadatafields=();
359: %Apache::lonpublisher::metadatakeys=();
360: my $result=&Apache::lonnet::getfile($fn);
361: if ($result == -1){
1.141 albertel 362: $r->print(&mt('Creating new file [_1]'),$meta_uri);
1.140 banghart 363: } else {
364: &Apache::lonpublisher::metaeval($result);
365: }
1.141 albertel 366: $r->print('<hr /><form method="post" action="" >');
367: $r->print('<p>'.&mt('If you would like to associate this resource ([_1]) with a current or previous course, please select one from the list below, otherwise select, \'None\'','<tt>'.$res_uri.'</tt>').'</p>');
1.140 banghart 368: $output = &select_course();
369: $r->print($output.'<br /><input type="submit" name="store" value="'.
1.141 albertel 370: &mt('Associate Resource With Selected Course').'">');
1.140 banghart 371: $r->print('</form>');
1.145 albertel 372:
1.156 albertel 373: my ($port_path,$group) = &get_port_path_and_group($uri);
374: $r->print('<br /><br /><form method="POST" action="'.$port_path.'">'.
1.145 albertel 375: '<input type="hidden" name="currentpath" value="'.$path.'" />'.
1.156 albertel 376: '<input type="hidden" name="group" value="'.$group.'" />'.
1.145 albertel 377: '<input type="submit" name="cancel" value="'.&mt('Cancel').'">'.
378: '</form>');
379:
1.140 banghart 380: return;
381: }
1.100 banghart 382: sub select_course {
1.150 albertel 383: my $output=$/;
384: my $current_restriction=
385: $Apache::lonpublisher::metadatafields{'courserestricted'};
386: my $selected = ($current_restriction eq 'none' ? 'selected="selected"'
387: : '');
388:
389: $output .= '<select name="new_courserestricted" >';
390: $output .= '<option value="none" '.$selected.'>'.
391: &mt('None').'</option>'.$/;
1.113 banghart 392: my %courses;
1.150 albertel 393: foreach my $key (keys(%env)) {
394: if ($key !~ m/^course\.(.+)\.description$/) { next; }
395: my $cid = $1;
396: if ($env{$key} !~ /\S/) { next; }
397: $courses{$key} = $cid;
398: }
399: foreach my $key (sort { lc($env{$a}) cmp lc($env{$b}) } (keys(%courses))) {
400: my $cid = 'course.'.$courses{$key};
401: my $selected = ($current_restriction eq $cid ? 'selected="selected"'
402: : '');
403: if ($env{$key} !~ /\S/) { next; }
404: $output .= '<option value="'.$cid.'" '.$selected.'>';
405: $output .= $env{$key};
406: $output .= '</option>'.$/;
407: $selected = '';
1.100 banghart 408: }
1.138 banghart 409: $output .= '</select><br />';
1.137 banghart 410: return ($output);
1.100 banghart 411: }
1.64 matthew 412: # Pretty printing of metadata field
1.46 www 413:
414: sub prettyprint {
1.82 www 415: my ($type,$value,$target,$prefix,$form,$noformat)=@_;
416: # $target,$prefix,$form are optional and for filecrumbs only
1.65 matthew 417: if (! defined($value)) {
418: return ' ';
419: }
1.64 matthew 420: # Title
1.46 www 421: if ($type eq 'title') {
422: return '<font size="+1" face="arial">'.$value.'</font>';
423: }
1.64 matthew 424: # Dates
1.46 www 425: if (($type eq 'creationdate') ||
426: ($type eq 'lastrevisiondate')) {
1.55 www 427: return ($value?&Apache::lonlocal::locallocaltime(
428: &Apache::lonmysql::unsqltime($value)):
429: &mt('not available'));
1.46 www 430: }
1.64 matthew 431: # Language
1.46 www 432: if ($type eq 'language') {
433: return &Apache::loncommon::languagedescription($value);
434: }
1.64 matthew 435: # Copyright
1.46 www 436: if ($type eq 'copyright') {
437: return &Apache::loncommon::copyrightdescription($value);
438: }
1.78 taceyjo1 439: # Copyright
440: if ($type eq 'sourceavail') {
441: return &Apache::loncommon::source_copyrightdescription($value);
442: }
1.64 matthew 443: # MIME
1.46 www 444: if ($type eq 'mime') {
1.64 matthew 445: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
446: &Apache::loncommon::filedescription($value);
447: }
448: # Person
1.46 www 449: if (($type eq 'author') ||
450: ($type eq 'owner') ||
451: ($type eq 'modifyinguser') ||
452: ($type eq 'authorspace')) {
453: $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
454: return $value;
455: }
1.64 matthew 456: # Gradelevel
1.48 www 457: if (($type eq 'lowestgradelevel') ||
458: ($type eq 'highestgradelevel')) {
459: return &Apache::loncommon::gradeleveldescription($value);
460: }
1.64 matthew 461: # Only for advance users below
1.96 albertel 462: if (! $env{'user.adv'}) {
1.65 matthew 463: return '<i>- '.&mt('not displayed').' -</i>';
464: }
1.64 matthew 465: # File
1.46 www 466: if (($type eq 'customdistributionfile') ||
467: ($type eq 'obsoletereplacement') ||
468: ($type eq 'goto_list') ||
469: ($type eq 'comefrom_list') ||
1.82 www 470: ($type eq 'sequsage_list') ||
1.83 www 471: ($type eq 'dependencies')) {
1.151 www 472: return '<font size="-1"><ul>'.join("\n",map {
1.70 matthew 473: my $url = &Apache::lonnet::clutter($_);
1.72 matthew 474: my $title = &Apache::lonnet::gettitle($url);
475: if ($title eq '') {
476: $title = 'Untitled';
477: if ($url =~ /\.sequence$/) {
478: $title .= ' Sequence';
479: } elsif ($url =~ /\.page$/) {
480: $title .= ' Page';
481: } elsif ($url =~ /\.problem$/) {
482: $title .= ' Problem';
483: } elsif ($url =~ /\.html$/) {
484: $title .= ' HTML document';
485: } elsif ($url =~ m:/syllabus$:) {
486: $title .= ' Syllabus';
487: }
488: }
1.82 www 489: $_ = '<li>'.$title.' '.
490: &Apache::lonhtmlcommon::crumbs($url,$target,$prefix,$form,'-1',$noformat).
491: '</li>'
492: } split(/\s*\,\s*/,$value)).'</ul></font>';
1.46 www 493: }
1.64 matthew 494: # Evaluations
1.46 www 495: if (($type eq 'clear') ||
496: ($type eq 'depth') ||
497: ($type eq 'helpful') ||
498: ($type eq 'correct') ||
499: ($type eq 'technical')) {
500: return &evalgraph($value);
501: }
1.64 matthew 502: # Difficulty
1.73 matthew 503: if ($type eq 'difficulty' || $type eq 'disc') {
1.46 www 504: return &diffgraph($value);
505: }
1.64 matthew 506: # List of courses
1.46 www 507: if ($type=~/\_list/) {
1.72 matthew 508: my @Courses = split(/\s*\,\s*/,$value);
1.151 www 509: my $Str='<font size="-1"><ul>';
1.72 matthew 510: foreach my $course (@Courses) {
1.154 albertel 511: my %courseinfo =
512: &Apache::lonnet::coursedescription($course,
513: {'one_time' => 1});
1.72 matthew 514: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
515: next;
516: }
1.151 www 517: $Str .= '<li><a href="/public/'.$courseinfo{'domain'}.'/'.
1.72 matthew 518: $courseinfo{'num'}.'/syllabus" target="preview">'.
1.151 www 519: $courseinfo{'description'}.'</a></li>';
1.72 matthew 520: }
1.151 www 521: return $Str.'</ul></font>';
1.46 www 522: }
1.64 matthew 523: # No pretty print found
1.46 www 524: return $value;
525: }
526:
1.64 matthew 527: # Pretty input of metadata field
1.54 www 528: sub direct {
529: return shift;
530: }
531:
1.48 www 532: sub selectbox {
533: my ($name,$value,$functionref,@idlist)=@_;
1.65 matthew 534: if (! defined($functionref)) {
535: $functionref=\&direct;
536: }
1.48 www 537: my $selout='<select name="'.$name.'">';
538: foreach (@idlist) {
539: $selout.='<option value=\''.$_.'\'';
540: if ($_ eq $value) {
541: $selout.=' selected>'.&{$functionref}($_).'</option>';
542: }
543: else {$selout.='>'.&{$functionref}($_).'</option>';}
544: }
545: return $selout.'</select>';
546: }
547:
1.54 www 548: sub relatedfield {
549: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
1.65 matthew 550: if (! $relatedsearchflag) {
551: return '';
552: }
553: if (! defined($relatedsep)) {
554: $relatedsep=' ';
555: }
556: if (! $show) {
557: return $relatedsep.' ';
558: }
1.54 www 559: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
560: ($relatedvalue?' checked="1"':'').' />';
561: }
1.48 www 562:
1.46 www 563: sub prettyinput {
1.54 www 564: my ($type,$value,$fieldname,$formname,
1.116 banghart 565: $relatedsearchflag,$relatedsep,$relatedvalue,$size,$course_key)=@_;
1.75 matthew 566: if (! defined($size)) {
567: $size = 80;
568: }
1.128 banghart 569: my $output;
1.150 albertel 570: if (defined($course_key)
571: && exists($env{$course_key.'.metadata.'.$type.'.options'})) {
1.116 banghart 572: my $stu_add;
573: my $only_one;
1.128 banghart 574: my %meta_options;
575: my @cur_values_inst;
576: my $cur_values_stu;
1.132 banghart 577: my $values = $env{$course_key.'.metadata.'.$type.'.values'};
578: if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/stuadd/) {
1.116 banghart 579: $stu_add = 'true';
580: }
1.132 banghart 581: if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/onlyone/) {
1.116 banghart 582: $only_one = 'true';
583: }
1.128 banghart 584: # need to take instructor values out of list where instructor and student
585: # values may be mixed.
1.133 banghart 586: if ($values) {
1.132 banghart 587: foreach my $item (split(/,/,$values)) {
588: $item =~ s/^\s+//;
1.133 banghart 589: $meta_options{$item} = $item;
1.128 banghart 590: }
1.132 banghart 591: foreach my $item (split(/,/,$value)) {
592: $item =~ s/^\s+//;
593: if ($meta_options{$item}) {
594: push(@cur_values_inst,$item);
1.128 banghart 595: } else {
1.132 banghart 596: $cur_values_stu .= $item.',';
1.128 banghart 597: }
598: }
1.129 banghart 599: } else {
600: $cur_values_stu = $value;
1.128 banghart 601: }
1.121 banghart 602: if ($type eq 'courserestricted') {
1.138 banghart 603: return (&select_course());
604: # return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
1.121 banghart 605: }
1.130 banghart 606: if (($type eq 'keywords') || ($type eq 'subject')
607: || ($type eq 'author')||($type eq 'notes')
1.133 banghart 608: || ($type eq 'abstract')|| ($type eq 'title')|| ($type eq 'standards')) {
1.129 banghart 609: if ($values) {
610: if ($only_one) {
1.134 banghart 611: $output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options));
1.129 banghart 612: } else {
1.130 banghart 613: $output .= (&Apache::loncommon::multiple_select_form('new_'.$type,\@cur_values_inst,undef,\%meta_options));
1.129 banghart 614: }
1.128 banghart 615: }
616: if ($stu_add) {
617: $output .= '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
618: 'value="'.$cur_values_stu.'" />'.
619: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
620: $relatedvalue);
1.119 banghart 621: }
1.128 banghart 622: return ($output);
1.116 banghart 623: }
624: if (($type eq 'lowestgradelevel') ||
625: ($type eq 'highestgradelevel')) {
626: return &Apache::loncommon::select_level_form($value,$fieldname).
627: &relatedfield(0,$relatedsearchflag,$relatedsep);
628: }
629: return();
630: }
1.64 matthew 631: # Language
1.48 www 632: if ($type eq 'language') {
633: return &selectbox($fieldname,
634: $value,
635: \&Apache::loncommon::languagedescription,
1.54 www 636: (&Apache::loncommon::languageids)).
1.64 matthew 637: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 638: }
1.64 matthew 639: # Copyright
1.48 www 640: if ($type eq 'copyright') {
641: return &selectbox($fieldname,
642: $value,
643: \&Apache::loncommon::copyrightdescription,
1.54 www 644: (&Apache::loncommon::copyrightids)).
1.64 matthew 645: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 646: }
1.78 taceyjo1 647: # Source Copyright
648: if ($type eq 'sourceavail') {
649: return &selectbox($fieldname,
650: $value,
651: \&Apache::loncommon::source_copyrightdescription,
652: (&Apache::loncommon::source_copyrightids)).
653: &relatedfield(0,$relatedsearchflag,$relatedsep);
654: }
1.64 matthew 655: # Gradelevels
1.48 www 656: if (($type eq 'lowestgradelevel') ||
657: ($type eq 'highestgradelevel')) {
1.54 www 658: return &Apache::loncommon::select_level_form($value,$fieldname).
1.64 matthew 659: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 660: }
1.64 matthew 661: # Obsolete
1.48 www 662: if ($type eq 'obsolete') {
663: return '<input type="checkbox" name="'.$fieldname.'"'.
1.54 www 664: ($value?' checked="1"':'').' />'.
1.64 matthew 665: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 666: }
1.64 matthew 667: # Obsolete replacement file
1.48 www 668: if ($type eq 'obsoletereplacement') {
669: return '<input type="text" name="'.$fieldname.
670: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
671: "('".$formname."','".$fieldname."'".
1.54 www 672: ",'')\">".&mt('Select').'</a>'.
1.64 matthew 673: &relatedfield(0,$relatedsearchflag,$relatedsep);
674: }
675: # Customdistribution file
1.48 www 676: if ($type eq 'customdistributionfile') {
677: return '<input type="text" name="'.$fieldname.
678: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
679: "('".$formname."','".$fieldname."'".
1.54 www 680: ",'rights')\">".&mt('Select').'</a>'.
1.64 matthew 681: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 682: }
1.78 taceyjo1 683: # Source Customdistribution file
684: if ($type eq 'sourcerights') {
685: return '<input type="text" name="'.$fieldname.
686: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
687: "('".$formname."','".$fieldname."'".
688: ",'rights')\">".&mt('Select').'</a>'.
689: &relatedfield(0,$relatedsearchflag,$relatedsep);
690: }
1.135 banghart 691: if ($type eq 'courserestricted') {
1.138 banghart 692: return (&select_course());
693: #return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
1.135 banghart 694: }
695:
1.64 matthew 696: # Dates
1.48 www 697: if (($type eq 'creationdate') ||
698: ($type eq 'lastrevisiondate')) {
1.64 matthew 699: return
700: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
701: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 702: }
1.64 matthew 703: # No pretty input found
1.48 www 704: $value=~s/^\s+//gs;
705: $value=~s/\s+$//gs;
706: $value=~s/\s+/ /gs;
1.77 matthew 707: $value=~s/\"/\"\;/gs;
1.54 www 708: return
1.74 matthew 709: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
1.64 matthew 710: 'value="'.$value.'" />'.
711: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
712: $relatedvalue);
1.46 www 713: }
714:
1.64 matthew 715: # Main Handler
1.1 www 716: sub handler {
1.64 matthew 717: my $r=shift;
718: #
1.67 matthew 719: my $uri=$r->uri;
720: #
721: # Set document type
722: &Apache::loncommon::content_type($r,'text/html');
723: $r->send_http_header;
724: return OK if $r->header_only;
1.64 matthew 725: #
1.76 matthew 726: my ($resdomain,$resuser)=
727: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
1.66 matthew 728: if ($uri=~m:/adm/bombs/(.*)$:) {
1.153 albertel 729: $r->print(&Apache::loncommon::start_page('Error Messages'));
1.66 matthew 730: # Looking for all bombs?
731: &report_bombs($r,$uri);
1.162 albertel 732: } elsif ($uri=~m|^/editupload/[^/]+/[^/]+/portfolio/|) {
1.140 banghart 733: ($resdomain,$resuser)=
1.162 albertel 734: (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
1.153 albertel 735: $r->print(&Apache::loncommon::start_page('Edit Portfolio File Catalog Information',
736: undef,
737: {'domain' => $resdomain,}));
1.140 banghart 738: if ($env{'form.store'}) {
739: &present_editable_metadata($r,$uri,'portfolio');
740: } else {
741: &pre_select_course($r,$uri);
742: }
1.162 albertel 743: } elsif ($uri=~m|^/~|) {
1.66 matthew 744: # Construction space
1.153 albertel 745: $r->print(&Apache::loncommon::start_page('Edit Catalog nformation',
746: undef,
747: {'domain' => $resdomain,}));
1.66 matthew 748: &present_editable_metadata($r,$uri);
749: } else {
1.153 albertel 750: $r->print(&Apache::loncommon::start_page('Catalog Information',
751: undef,
752: {'domain' => $resdomain,}));
1.66 matthew 753: &present_uneditable_metadata($r,$uri);
754: }
1.153 albertel 755: $r->print(&Apache::loncommon::end_page());
1.66 matthew 756: return OK;
757: }
758:
1.67 matthew 759: #####################################################
760: #####################################################
761: ### ###
762: ### Report Bombs ###
763: ### ###
764: #####################################################
765: #####################################################
1.66 matthew 766: sub report_bombs {
767: my ($r,$uri) = @_;
768: # Set document type
1.67 matthew 769: $uri =~ s:/adm/bombs/::;
770: $uri = &Apache::lonnet::declutter($uri);
1.66 matthew 771: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
772: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
773: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
1.98 www 774: if ($env{'form.clearbombs'}) {
775: &Apache::lonmsg::clear_author_res_msg($uri);
776: }
777: my $clear=&mt('Clear all Messages in Subdirectory');
778: $r->print(<<ENDCLEAR);
779: <form method="post">
780: <input type="submit" name="clearbombs" value="$clear" />
781: </form>
782: ENDCLEAR
1.67 matthew 783: my %brokenurls =
784: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
785: foreach (sort(keys(%brokenurls))) {
1.66 matthew 786: if ($_=~/^\Q$uri\E/) {
1.70 matthew 787: $r->print
788: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
789: &Apache::lonmsg::retrieve_author_res_msg($_).
790: '<hr />');
1.64 matthew 791: }
792: }
1.66 matthew 793: } else {
794: $r->print(&mt('Not authorized'));
795: }
796: return;
797: }
798:
1.67 matthew 799: #####################################################
800: #####################################################
801: ### ###
802: ### Uneditable Metadata Display ###
803: ### ###
804: #####################################################
805: #####################################################
1.66 matthew 806: sub present_uneditable_metadata {
807: my ($r,$uri) = @_;
808: #
1.162 albertel 809: my $uploaded = ($uri =~ m|/uploaded/|);
1.66 matthew 810: my %content=();
811: # Read file
812: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
813: $content{$_}=&Apache::lonnet::metadata($uri,$_);
814: }
815: # Render Output
816: # displayed url
817: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
818: $uri=~s/\.meta$//;
819: my $disuri=&Apache::lonnet::clutter($uri);
1.152 www 820: $disuri=~s/^\/adm\/wrapper//;
1.66 matthew 821: # version
822: my $versiondisplay='';
1.162 albertel 823: if (!$uploaded) {
824: my $currentversion=&Apache::lonnet::getversion($disuri);
825: if ($thisversion) {
826: $versiondisplay=&mt('Version').': '.$thisversion.
827: ' ('.&mt('most recent version').': '.
828: ($currentversion>0 ?
829: $currentversion :
830: &mt('information not available')).')';
831: } else {
832: $versiondisplay='Version: '.$currentversion;
833: }
1.66 matthew 834: }
1.72 matthew 835: # crumbify displayed URL uri target prefix form size
836: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
837: $disuri =~ s:<br />::g;
1.66 matthew 838: # obsolete
839: my $obsolete=$content{'obsolete'};
840: my $obsoletewarning='';
1.96 albertel 841: if (($obsolete) && ($env{'user.adv'})) {
1.66 matthew 842: $obsoletewarning='<p><font color="red">'.
843: &mt('This resource has been marked obsolete by the author(s)').
844: '</font></p>';
845: }
846: #
847: my %lt=&fieldnames();
848: my $table='';
1.72 matthew 849: my $title = $content{'title'};
850: if (! defined($title)) {
851: $title = 'Untitled Resource';
852: }
1.163 albertel 853: my @fields;
854: if ($uploaded) {
855: @fields = ('title','author','subject','keywords','notes','abstract',
856: 'lowestgradelevel','highestgradelevel','standards','mime',
857: 'owner');
858: } else {
859: @fields = ('title',
860: 'author',
861: 'subject',
862: 'keywords',
863: 'notes',
864: 'abstract',
865: 'lowestgradelevel',
866: 'highestgradelevel',
867: 'standards',
868: 'mime',
869: 'language',
870: 'creationdate',
871: 'lastrevisiondate',
872: 'owner',
873: 'copyright',
874: 'customdistributionfile',
875: 'sourceavail',
876: 'sourcerights',
877: 'obsolete',
878: 'obsoletereplacement');
879: }
880: foreach my $field (@fields) {
881: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$field}.
1.66 matthew 882: '</td><td bgcolor="#CCCCCC">'.
1.163 albertel 883: &prettyprint($field,$content{$field}).'</td></tr>';
884: delete($content{$field});
1.66 matthew 885: }
886: #
887: $r->print(<<ENDHEAD);
1.72 matthew 888: <h2>$title</h2>
889: <p>
890: $disuri<br />
1.36 www 891: $obsoletewarning
1.72 matthew 892: $versiondisplay
893: </p>
1.88 banghart 894: <table cellspacing="2" border="0">
1.45 www 895: $table
1.11 www 896: </table>
1.1 www 897: ENDHEAD
1.162 albertel 898: if (!$uploaded && $env{'user.adv'}) {
1.68 matthew 899: &print_dynamic_metadata($r,$uri,\%content);
1.67 matthew 900: }
901: return;
902: }
903:
904: sub print_dynamic_metadata {
1.68 matthew 905: my ($r,$uri,$content) = @_;
906: #
1.69 matthew 907: my %content = %$content;
1.68 matthew 908: my %lt=&fieldnames();
1.67 matthew 909: #
910: my $description = 'Dynamic Metadata (updated periodically)';
911: $r->print('<h3>'.&mt($description).'</h3>'.
1.70 matthew 912: &mt('Processing'));
1.67 matthew 913: $r->rflush();
914: my %items=&fieldnames();
915: my %dynmeta=&dynamicmeta($uri);
916: #
917: # General Access and Usage Statistics
1.70 matthew 918: if (exists($dynmeta{'count'}) ||
919: exists($dynmeta{'sequsage'}) ||
920: exists($dynmeta{'comefrom'}) ||
921: exists($dynmeta{'goto'}) ||
922: exists($dynmeta{'course'})) {
923: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
1.88 banghart 924: '<table cellspacing="2" border="0">');
1.70 matthew 925: foreach ('count',
926: 'sequsage','sequsage_list',
927: 'comefrom','comefrom_list',
928: 'goto','goto_list',
929: 'course','course_list') {
930: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
931: '<td bgcolor="#CCCCCC">'.
932: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
933: }
934: $r->print('</table>');
935: } else {
936: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
1.67 matthew 937: }
1.69 matthew 938: #
939: # Assessment statistics
1.73 matthew 940: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
941: if (exists($dynmeta{'stdno'}) ||
942: exists($dynmeta{'avetries'}) ||
943: exists($dynmeta{'difficulty'}) ||
944: exists($dynmeta{'disc'})) {
945: # This is an assessment, print assessment data
946: $r->print('<h4>'.
947: &mt('Overall Assessment Statistical Data').
948: '</h4>'.
1.88 banghart 949: '<table cellspacing="2" border="0">');
1.73 matthew 950: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
1.66 matthew 951: '<td bgcolor="#CCCCCC">'.
1.73 matthew 952: &prettyprint('stdno',$dynmeta{'stdno'}).
953: '</td>'."</tr>\n");
954: foreach ('avetries','difficulty','disc') {
955: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
956: '<td bgcolor="#CCCCCC">'.
957: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
958: '</td>'."</tr>\n");
959: }
960: $r->print('</table>');
961: }
962: if (exists($dynmeta{'stats'})) {
963: #
964: # New assessment statistics
965: $r->print('<h4>'.
966: &mt('Detailed Assessment Statistical Data').
967: '</h4>');
1.88 banghart 968: my $table = '<table cellspacing="2" border="0">'.
1.73 matthew 969: '<tr>'.
970: '<th>Course</th>'.
971: '<th>Section(s)</th>'.
972: '<th>Num Students</th>'.
973: '<th>Mean Tries</th>'.
974: '<th>Degree of Difficulty</th>'.
975: '<th>Degree of Discrimination</th>'.
976: '<th>Time of computation</th>'.
977: '</tr>'.$/;
978: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
979: my $data = $dynmeta{'stats'}->{$identifier};
980: my $course = $data->{'course'};
1.154 albertel 981: my %courseinfo =
982: &Apache::lonnet::coursedescription($course,
983: {'one_time' => 1});
1.73 matthew 984: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
985: &Apache::lonnet::logthis('lookup for '.$course.' failed');
986: next;
987: }
988: $table .= '<tr>';
989: $table .=
990: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
991: $table .=
992: '<td align="right">'.$data->{'sections'}.'</td>';
993: $table .=
994: '<td align="right">'.$data->{'stdno'}.'</td>';
995: foreach ('avetries','difficulty','disc') {
996: $table .= '<td align="right">';
997: if (exists($data->{$_})) {
998: $table .= sprintf('%.2f',$data->{$_}).' ';
999: } else {
1000: $table .= '';
1001: }
1002: $table .= '</td>';
1003: }
1004: $table .=
1005: '<td><nobr>'.
1006: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
1007: '</nobr></td>';
1008: $table .=
1009: '</tr>'.$/;
1010: }
1011: $table .= '</table>'.$/;
1012: $r->print($table);
1013: } else {
1014: $r->print('No new dynamic data found.');
1.66 matthew 1015: }
1.70 matthew 1016: } else {
1.73 matthew 1017: $r->print('<h4>'.
1018: &mt('No Assessment Statistical Data is available for this resource').
1019: '</h4>');
1.67 matthew 1020: }
1.73 matthew 1021:
1022: #
1023: #
1.70 matthew 1024: if (exists($dynmeta{'clear'}) ||
1025: exists($dynmeta{'depth'}) ||
1026: exists($dynmeta{'helpful'}) ||
1027: exists($dynmeta{'correct'}) ||
1028: exists($dynmeta{'technical'})){
1029: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
1.88 banghart 1030: '<table cellspacing="2" border="0">');
1.70 matthew 1031: foreach ('clear','depth','helpful','correct','technical') {
1032: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
1033: '<td bgcolor="#CCCCCC">'.
1034: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
1035: }
1036: $r->print('</table>');
1037: } else {
1038: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1.67 matthew 1039: }
1040: $uri=~/^\/res\/(\w+)\/(\w+)\//;
1.96 albertel 1041: if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
1042: || ($env{'user.role.ca./'.$1.'/'.$2})) {
1.70 matthew 1043: if (exists($dynmeta{'comments'})) {
1044: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
1045: &mt('visible to author and co-authors only').
1046: ')</h4>'.
1047: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
1048: } else {
1049: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
1050: }
1051: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
1052: if (defined($bombs) && $bombs ne '') {
1053: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
1054: &mt('visible to author and co-authors only').')'.
1055: '</h4>'.$bombs);
1056: } else {
1057: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
1058: }
1.67 matthew 1059: }
1.69 matthew 1060: #
1.67 matthew 1061: # All other stuff
1062: $r->print('<h3>'.
1063: &mt('Additional Metadata (non-standard, parameters, exports)').
1.81 www 1064: '</h3><table border="0" cellspacing="1">');
1.67 matthew 1065: foreach (sort(keys(%content))) {
1066: my $name=$_;
1067: if ($name!~/\.display$/) {
1068: my $display=&Apache::lonnet::metadata($uri,
1069: $name.'.display');
1070: if (! $display) {
1071: $display=$name;
1072: };
1073: my $otherinfo='';
1074: foreach ('name','part','type','default') {
1075: if (defined(&Apache::lonnet::metadata($uri,
1076: $name.'.'.$_))) {
1077: $otherinfo.=' '.$_.'='.
1078: &Apache::lonnet::metadata($uri,
1079: $name.'.'.$_).'; ';
1080: }
1.64 matthew 1081: }
1.81 www 1082: $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 1083: if ($otherinfo) {
1084: $r->print(' ('.$otherinfo.')');
1.64 matthew 1085: }
1.81 www 1086: $r->print("</font></td></tr>\n");
1.64 matthew 1087: }
1.66 matthew 1088: }
1.81 www 1089: $r->print("</table>");
1.67 matthew 1090: return;
1.66 matthew 1091: }
1.105 banghart 1092:
1.102 banghart 1093:
1094:
1.67 matthew 1095: #####################################################
1096: #####################################################
1097: ### ###
1098: ### Editable metadata display ###
1099: ### ###
1100: #####################################################
1101: #####################################################
1.66 matthew 1102: sub present_editable_metadata {
1.90 banghart 1103: my ($r,$uri, $file_type) = @_;
1.66 matthew 1104: # Construction Space Call
1105: # Header
1106: my $disuri=$uri;
1107: my $fn=&Apache::lonnet::filelocation('',$uri);
1.155 albertel 1108: $disuri=~s{^/\~}{/priv/};
1.66 matthew 1109: $disuri=~s/\.meta$//;
1.141 albertel 1110: my $meta_uri = $disuri;
1.147 albertel 1111: my $path;
1.141 albertel 1112: if ($disuri =~ m|/portfolio/|) {
1.147 albertel 1113: ($disuri, $meta_uri, $path) = &portfolio_display_uri($disuri,1);
1.141 albertel 1114: }
1.66 matthew 1115: my $target=$uri;
1.155 albertel 1116: $target=~s{^/\~}{/res/$env{'request.role.domain'}/};
1.66 matthew 1117: $target=~s/\.meta$//;
1118: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
1119: if ($bombs) {
1.99 www 1120: my $showdel=1;
1.96 albertel 1121: if ($env{'form.delmsg'}) {
1.66 matthew 1122: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
1123: $bombs=&mt('Messages deleted.');
1.99 www 1124: $showdel=0;
1.66 matthew 1125: } else {
1126: $bombs=&mt('Error deleting messages');
1.64 matthew 1127: }
1.66 matthew 1128: }
1.98 www 1129: if ($env{'form.clearmsg'}) {
1130: my $cleardir=$target;
1131: $cleardir=~s/\/[^\/]+$/\//;
1132: if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
1133: $bombs=&mt('Messages cleared.');
1.99 www 1134: $showdel=0;
1.98 www 1135: } else {
1136: $bombs=&mt('Error clearing messages');
1137: }
1138: }
1139: my $del=&mt('Delete Messages for this Resource');
1140: my $clear=&mt('Clear all Messages in Subdirectory');
1.99 www 1141: my $goback=&mt('Back to Source File');
1.66 matthew 1142: $r->print(<<ENDBOMBS);
1.52 www 1143: <h1>$disuri</h1>
1144: <form method="post" name="defaultmeta">
1.99 www 1145: ENDBOMBS
1146: if ($showdel) {
1147: $r->print(<<ENDDEL);
1.59 www 1148: <input type="submit" name="delmsg" value="$del" />
1.98 www 1149: <input type="submit" name="clearmsg" value="$clear" />
1.99 www 1150: ENDDEL
1151: } else {
1152: $r->print('<a href="'.$disuri.'" />'.$goback.'</a>');
1153: }
1154: $r->print('<br />'.$bombs);
1.66 matthew 1155: } else {
1156: my $displayfile='Catalog Information for '.$disuri;
1157: if ($disuri=~/\/default$/) {
1158: my $dir=$disuri;
1159: $dir=~s/default$//;
1160: $displayfile=
1161: &mt('Default Cataloging Information for Directory').' '.
1162: $dir;
1163: }
1164: %Apache::lonpublisher::metadatafields=();
1165: %Apache::lonpublisher::metadatakeys=();
1.94 banghart 1166: my $result=&Apache::lonnet::getfile($fn);
1167: if ($result == -1){
1.141 albertel 1168: $r->print(&mt('Creating new file [_1]'),$meta_uri);
1.94 banghart 1169: } else {
1170: &Apache::lonpublisher::metaeval($result);
1171: }
1.66 matthew 1172: $r->print(<<ENDEDIT);
1.23 www 1173: <h1>$displayfile</h1>
1.48 www 1174: <form method="post" name="defaultmeta">
1.23 www 1175: ENDEDIT
1.66 matthew 1176: $r->print('<script language="JavaScript">'.
1.86 albertel 1177: &Apache::loncommon::browser_and_searcher_javascript().
1.66 matthew 1178: '</script>');
1.90 banghart 1179: my %lt=&fieldnames($file_type);
1.87 albertel 1180: my $output;
1.90 banghart 1181: my @fields;
1182: if ($file_type eq 'portfolio') {
1.163 albertel 1183: @fields = ('author','title','subject','keywords','abstract',
1184: 'notes','lowestgradelevel',
1.140 banghart 1185: 'highestgradelevel','standards');
1.90 banghart 1186: } else {
1187: @fields = ('author','title','subject','keywords','abstract','notes',
1.66 matthew 1188: 'copyright','customdistributionfile','language',
1189: 'standards',
1.78 taceyjo1 1190: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1.90 banghart 1191: 'obsolete','obsoletereplacement');
1192: }
1.139 banghart 1193: if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
1194: (! $env{'form.new_courserestricted'})) {
1.138 banghart 1195: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1196: 'none';
1.139 banghart 1197: } elsif ($env{'form.new_courserestricted'}) {
1198: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1199: $env{'form.new_courserestricted'};
1200: }
1.120 banghart 1201: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
1202: $Apache::lonpublisher::metadatafields{'copyright'}=
1.163 albertel 1203: 'default';
1.120 banghart 1204: }
1.149 albertel 1205: if ($file_type eq 'portfolio') {
1.163 albertel 1206: if (! $Apache::lonpublisher::metadatafields{'mime'}) {
1207: ($Apache::lonpublisher::metadatafields{'mime'}) =
1208: ( $target=~/\.(\w+)$/ );
1209: }
1210: if (! $Apache::lonpublisher::metadatafields{'owner'}) {
1211: $Apache::lonpublisher::metadatafields{'owner'} =
1212: $env{'user.name'}.':'.$env{'user.domain'};
1213: }
1214:
1.149 albertel 1215: if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
1216: $r->print(&mt('Associated with course [_1]','<strong>'.$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.".description"}.
1217: '</strong>').'<br />');
1218: } else {
1219: $r->print("This resource is not associated with a course.<br />");
1220: }
1221: }
1.143 albertel 1222: foreach my $field_name (@fields) {
1.132 banghart 1223:
1224: if (defined($env{'form.new_'.$field_name})) {
1225: $Apache::lonpublisher::metadatafields{$field_name}=
1226: join(',',&Apache::loncommon::get_env_multiple('form.new_'.$field_name));
1.66 matthew 1227: }
1.150 albertel 1228: if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none'
1229: && exists($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'})) {
1.115 banghart 1230: # handle restrictions here
1.138 banghart 1231: if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
1232: ($field_name eq 'courserestricted')){
1.143 albertel 1233: $output.=("\n".'<p>'.$lt{$field_name}.': '.
1.132 banghart 1234: &prettyinput($field_name,
1235: $Apache::lonpublisher::metadatafields{$field_name},
1.138 banghart 1236: 'new_'.$field_name,'defaultmeta',
1237: undef,undef,undef,undef,
1.143 albertel 1238: $Apache::lonpublisher::metadatafields{'courserestricted'}).'</p>'."\n");
1.127 banghart 1239: }
1.115 banghart 1240: } else {
1.138 banghart 1241:
1.132 banghart 1242: $output.=('<p>'.$lt{$field_name}.': '.
1243: &prettyinput($field_name,
1244: $Apache::lonpublisher::metadatafields{$field_name},
1245: 'new_'.$field_name,'defaultmeta').'</p>');
1.138 banghart 1246:
1.115 banghart 1247: }
1.66 matthew 1248: }
1.143 albertel 1249: if ($env{'form.store'}) {
1250: my $mfh;
1251: my $formname='store';
1252: my $file_content;
1.142 albertel 1253: if (&Apache::loncommon::get_env_multiple('form.new_keywords')) {
1254: $Apache::lonpublisher::metadatafields{'keywords'} =
1255: join (',', &Apache::loncommon::get_env_multiple('form.new_keywords'));
1256: }
1.143 albertel 1257:
1258: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1259: next if ($_ =~ /\./);
1260: my $unikey=$_;
1261: $unikey=~/^([A-Za-z]+)/;
1262: my $tag=$1;
1263: $tag=~tr/A-Z/a-z/;
1264: $file_content.= "\n\<$tag";
1265: foreach (split(/\,/,
1266: $Apache::lonpublisher::metadatakeys{$unikey})
1267: ) {
1268: my $value=
1269: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
1270: $value=~s/\"/\'\'/g;
1271: $file_content.=' '.$_.'="'.$value.'"' ;
1272: # print $mfh ' '.$_.'="'.$value.'"';
1273: }
1274: $file_content.= '>'.
1275: &HTML::Entities::encode
1276: ($Apache::lonpublisher::metadatafields{$unikey},
1277: '<>&"').
1278: '</'.$tag.'>';
1.142 albertel 1279: }
1.159 raeburn 1280: if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/portfolio/|) {
1.143 albertel 1281: my ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|);
1.159 raeburn 1282: $r->print(&store_portfolio_metadata($formname,$file_content,$path,
1283: $new_fn));
1284: } elsif ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/groups/\w+/portfolio/|) {
1285: my ($path, $new_fn) = ($fn =~ m|/(groups/\w+/portfolio.*)/([^/]*)$|);
1286: $r->print(&store_portfolio_metadata($formname,$file_content,$path,$new_fn));
1.142 albertel 1287: } else {
1.143 albertel 1288: if (! ($mfh=Apache::File->new('>'.$fn))) {
1289: $r->print('<p><font color="red">'.
1290: &mt('Could not write metadata').', '.
1291: &mt('FAIL').'</font></p>');
1292: } else {
1293: print $mfh $file_content;
1294: $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
1295: ' '.&Apache::lonlocal::locallocaltime(time).
1296: '</font></p>');
1297: }
1.142 albertel 1298: }
1299: }
1.143 albertel 1300:
1301: $r->print($output.'<br /><input type="submit" name="store" value="'.
1302: &mt('Store Catalog Information').'">');
1.147 albertel 1303:
1.149 albertel 1304: if ($file_type eq 'portfolio') {
1.156 albertel 1305: my ($port_path,$group) = &get_port_path_and_group($uri);
1.159 raeburn 1306: if ($group) {
1307: $r->print('<input type="hidden" name="group" value="'.$group.'" />');
1308: }
1.149 albertel 1309: $r->print('</form>
1.156 albertel 1310: <br /><br /><form method="POST" action="'.$port_path.'">'.
1311: '<input type="hidden" name="group" value="'.$group.'" />'.
1.149 albertel 1312: '<input type="hidden" name="currentpath" value="'.$path.'" />'.
1313: '<input type="submit" name="cancel" value="'.&mt('Discard Edits and Return to Portfolio').'">');
1314: }
1.142 albertel 1315: }
1.149 albertel 1316:
1.143 albertel 1317: $r->print('</form>');
1318:
1.66 matthew 1319: return;
1.1 www 1320: }
1.64 matthew 1321:
1.159 raeburn 1322: sub store_portfolio_metadata {
1323: my ($formname,$content,$path,$new_fn) = @_;
1324: $env{'form.'.$formname}=$content."\n";
1325: $env{'form.'.$formname.'.filename'}=$new_fn;
1326: my $result =&Apache::lonnet::userfileupload($formname,'',$path);
1327: if ($result =~ /(error|notfound)/) {
1328: return '<p><font color="red">'.
1329: &mt('Could not write metadata').', '.
1330: &mt('FAIL').'</font></p>';
1331: } else {
1332: return '<p><font color="blue">'.&mt('Wrote Metadata').
1333: ' '.&Apache::lonlocal::locallocaltime(time).'</font></p>';
1334: }
1335: }
1336:
1.1 www 1337: 1;
1338: __END__
1.97 banghart 1339:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>