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