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