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