Annotation of loncom/interface/lonmeta.pm, revision 1.216
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.216 ! jms 4: # $Id: lonmeta.pm,v 1.215 2008/11/18 19:14:22 jms 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.71 matthew 167: $output.='<td width="20" bgcolor="#555555">  </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.71 matthew 177: $output.='<td width="20" bgcolor="#555555">  </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="" >');
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.167 banghart 354: $r->print('<br /><br /><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().
392: '<th>Copy to notes?</th>'."\n".
393: '<th>Field name</th>'."\n".
394: '<th>Values</th>'."\n".
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.82 www 428: my ($type,$value,$target,$prefix,$form,$noformat)=@_;
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') {
435: return '<font size="+1" face="arial">'.$value.'</font>';
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.64 matthew 458: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
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.151 www 485: return '<font size="-1"><ul>'.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.' '.
503: &Apache::lonhtmlcommon::crumbs($url,$target,$prefix,$form,'-1',$noformat).
504: '</li>'
505: } split(/\s*\,\s*/,$value)).'</ul></font>';
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.151 www 522: my $Str='<font size="-1"><ul>';
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.151 www 541: return $Str.'</ul></font>';
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 {
553: my ($name,$value,$functionref,@idlist)=@_;
1.65 matthew 554: if (! defined($functionref)) {
555: $functionref=\&direct;
556: }
1.48 www 557: my $selout='<select name="'.$name.'">';
558: foreach (@idlist) {
559: $selout.='<option value=\''.$_.'\'';
560: if ($_ eq $value) {
561: $selout.=' selected>'.&{$functionref}($_).'</option>';
562: }
563: else {$selout.='>'.&{$functionref}($_).'</option>';}
564: }
565: return $selout.'</select>';
566: }
567:
1.54 www 568: sub relatedfield {
569: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
1.65 matthew 570: if (! $relatedsearchflag) {
571: return '';
572: }
573: if (! defined($relatedsep)) {
574: $relatedsep=' ';
575: }
576: if (! $show) {
577: return $relatedsep.' ';
578: }
1.54 www 579: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
580: ($relatedvalue?' checked="1"':'').' />';
581: }
1.48 www 582:
1.46 www 583: sub prettyinput {
1.54 www 584: my ($type,$value,$fieldname,$formname,
1.116 banghart 585: $relatedsearchflag,$relatedsep,$relatedvalue,$size,$course_key)=@_;
1.75 matthew 586: if (! defined($size)) {
587: $size = 80;
588: }
1.128 banghart 589: my $output;
1.150 albertel 590: if (defined($course_key)
591: && exists($env{$course_key.'.metadata.'.$type.'.options'})) {
1.116 banghart 592: my $stu_add;
593: my $only_one;
1.128 banghart 594: my %meta_options;
595: my @cur_values_inst;
596: my $cur_values_stu;
1.132 banghart 597: my $values = $env{$course_key.'.metadata.'.$type.'.values'};
598: if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/stuadd/) {
1.116 banghart 599: $stu_add = 'true';
600: }
1.132 banghart 601: if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/onlyone/) {
1.116 banghart 602: $only_one = 'true';
603: }
1.128 banghart 604: # need to take instructor values out of list where instructor and student
605: # values may be mixed.
1.133 banghart 606: if ($values) {
1.132 banghart 607: foreach my $item (split(/,/,$values)) {
608: $item =~ s/^\s+//;
1.133 banghart 609: $meta_options{$item} = $item;
1.128 banghart 610: }
1.132 banghart 611: foreach my $item (split(/,/,$value)) {
612: $item =~ s/^\s+//;
613: if ($meta_options{$item}) {
614: push(@cur_values_inst,$item);
1.128 banghart 615: } else {
1.201 raeburn 616: if ($item ne '') {
1.198 banghart 617: $cur_values_stu .= $item.',';
618: }
1.128 banghart 619: }
620: }
1.202 raeburn 621: $cur_values_stu =~ s/,$//;
1.197 banghart 622: my @key_order = sort(keys(%meta_options));
1.203 albertel 623: unshift(@key_order,'');
1.201 raeburn 624: $meta_options{''} = 'Not specified';
1.197 banghart 625: $meta_options{'select_form_order'} = \@key_order;
1.129 banghart 626: } else {
627: $cur_values_stu = $value;
1.128 banghart 628: }
1.121 banghart 629: if ($type eq 'courserestricted') {
1.138 banghart 630: return (&select_course());
631: # return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
1.121 banghart 632: }
1.130 banghart 633: if (($type eq 'keywords') || ($type eq 'subject')
634: || ($type eq 'author')||($type eq 'notes')
1.174 banghart 635: || ($type eq 'abstract')|| ($type eq 'title')|| ($type eq 'standards')
1.199 raeburn 636: || (exists($env{$course_key.'.metadata.'.$type.'.added'}))) {
1.197 banghart 637:
1.129 banghart 638: if ($values) {
639: if ($only_one) {
1.134 banghart 640: $output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options));
1.129 banghart 641: } else {
1.130 banghart 642: $output .= (&Apache::loncommon::multiple_select_form('new_'.$type,\@cur_values_inst,undef,\%meta_options));
1.129 banghart 643: }
1.128 banghart 644: }
645: if ($stu_add) {
646: $output .= '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
647: 'value="'.$cur_values_stu.'" />'.
648: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
649: $relatedvalue);
1.119 banghart 650: }
1.128 banghart 651: return ($output);
1.176 banghart 652: }
1.116 banghart 653: if (($type eq 'lowestgradelevel') ||
654: ($type eq 'highestgradelevel')) {
655: return &Apache::loncommon::select_level_form($value,$fieldname).
656: &relatedfield(0,$relatedsearchflag,$relatedsep);
657: }
658: return();
659: }
1.64 matthew 660: # Language
1.48 www 661: if ($type eq 'language') {
662: return &selectbox($fieldname,
663: $value,
664: \&Apache::loncommon::languagedescription,
1.54 www 665: (&Apache::loncommon::languageids)).
1.64 matthew 666: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 667: }
1.64 matthew 668: # Copyright
1.48 www 669: if ($type eq 'copyright') {
670: return &selectbox($fieldname,
671: $value,
672: \&Apache::loncommon::copyrightdescription,
1.54 www 673: (&Apache::loncommon::copyrightids)).
1.64 matthew 674: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 675: }
1.78 taceyjo1 676: # Source Copyright
677: if ($type eq 'sourceavail') {
678: return &selectbox($fieldname,
679: $value,
680: \&Apache::loncommon::source_copyrightdescription,
681: (&Apache::loncommon::source_copyrightids)).
682: &relatedfield(0,$relatedsearchflag,$relatedsep);
683: }
1.64 matthew 684: # Gradelevels
1.48 www 685: if (($type eq 'lowestgradelevel') ||
686: ($type eq 'highestgradelevel')) {
1.54 www 687: return &Apache::loncommon::select_level_form($value,$fieldname).
1.64 matthew 688: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 689: }
1.64 matthew 690: # Obsolete
1.48 www 691: if ($type eq 'obsolete') {
692: return '<input type="checkbox" name="'.$fieldname.'"'.
1.54 www 693: ($value?' checked="1"':'').' />'.
1.64 matthew 694: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 695: }
1.64 matthew 696: # Obsolete replacement file
1.48 www 697: if ($type eq 'obsoletereplacement') {
698: return '<input type="text" name="'.$fieldname.
699: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
700: "('".$formname."','".$fieldname."'".
1.54 www 701: ",'')\">".&mt('Select').'</a>'.
1.64 matthew 702: &relatedfield(0,$relatedsearchflag,$relatedsep);
703: }
704: # Customdistribution file
1.48 www 705: if ($type eq 'customdistributionfile') {
706: return '<input type="text" name="'.$fieldname.
707: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
708: "('".$formname."','".$fieldname."'".
1.54 www 709: ",'rights')\">".&mt('Select').'</a>'.
1.64 matthew 710: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 711: }
1.78 taceyjo1 712: # Source Customdistribution file
713: if ($type eq 'sourcerights') {
714: return '<input type="text" name="'.$fieldname.
715: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
716: "('".$formname."','".$fieldname."'".
717: ",'rights')\">".&mt('Select').'</a>'.
718: &relatedfield(0,$relatedsearchflag,$relatedsep);
719: }
1.135 banghart 720: if ($type eq 'courserestricted') {
1.138 banghart 721: return (&select_course());
722: #return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
1.135 banghart 723: }
724:
1.64 matthew 725: # Dates
1.48 www 726: if (($type eq 'creationdate') ||
727: ($type eq 'lastrevisiondate')) {
1.64 matthew 728: return
729: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
730: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 731: }
1.64 matthew 732: # No pretty input found
1.48 www 733: $value=~s/^\s+//gs;
734: $value=~s/\s+$//gs;
735: $value=~s/\s+/ /gs;
1.77 matthew 736: $value=~s/\"/\"\;/gs;
1.54 www 737: return
1.74 matthew 738: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
1.64 matthew 739: 'value="'.$value.'" />'.
740: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
741: $relatedvalue);
1.46 www 742: }
743:
1.64 matthew 744: # Main Handler
1.1 www 745: sub handler {
1.64 matthew 746: my $r=shift;
1.169 banghart 747: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.188 banghart 748: ['currentpath','changecourse']);
1.67 matthew 749: my $uri=$r->uri;
750: #
751: # Set document type
752: &Apache::loncommon::content_type($r,'text/html');
753: $r->send_http_header;
754: return OK if $r->header_only;
1.76 matthew 755: my ($resdomain,$resuser)=
1.190 albertel 756: (&Apache::lonnet::declutter($uri)=~/^($match_domain)\/($match_username)\//);
1.66 matthew 757: if ($uri=~m:/adm/bombs/(.*)$:) {
1.153 albertel 758: $r->print(&Apache::loncommon::start_page('Error Messages'));
1.66 matthew 759: # Looking for all bombs?
760: &report_bombs($r,$uri);
1.162 albertel 761: } elsif ($uri=~m|^/editupload/[^/]+/[^/]+/portfolio/|) {
1.140 banghart 762: ($resdomain,$resuser)=
1.190 albertel 763: (&Apache::lonnet::declutter($uri)=~m|^($match_domain)/($match_name)/portfolio|);
1.153 albertel 764: $r->print(&Apache::loncommon::start_page('Edit Portfolio File Catalog Information',
765: undef,
766: {'domain' => $resdomain,}));
1.140 banghart 767: if ($env{'form.store'}) {
768: &present_editable_metadata($r,$uri,'portfolio');
769: } else {
1.186 banghart 770: my $fn=&Apache::lonnet::filelocation('',$uri);
771: %Apache::lonpublisher::metadatafields=();
772: %Apache::lonpublisher::metadatakeys=();
773: my $result=&Apache::lonnet::getfile($fn);
774: &Apache::lonpublisher::metaeval($result);
1.188 banghart 775: if ((!$Apache::lonpublisher::metadatafields{'courserestricted'}) ||
776: ($env{'form.changecourse'} eq 'true')) {
1.186 banghart 777: &pre_select_course($r,$uri);
778: } else {
779: &present_editable_metadata($r,$uri,'portfolio');
780: }
1.140 banghart 781: }
1.171 banghart 782: } elsif ($uri=~m|^/editupload/[^/]+/[^/]+/groups/|) {
1.172 banghart 783: $r->print(&Apache::loncommon::start_page('Edit Group Portfolio File Catalog Information',
1.171 banghart 784: undef,
785: {'domain' => $resdomain,}));
1.172 banghart 786: &present_editable_metadata($r,$uri,'groups');
1.162 albertel 787: } elsif ($uri=~m|^/~|) {
1.66 matthew 788: # Construction space
1.204 banghart 789: $r->print(&Apache::loncommon::start_page('Edit Catalog Information',
790: "\n".'<script type="text/javascript">'."\n".
791: &Apache::loncommon::browser_and_searcher_javascript().
792: "\n".'</script>',
1.153 albertel 793: {'domain' => $resdomain,}));
1.66 matthew 794: &present_editable_metadata($r,$uri);
795: } else {
1.214 schafran 796: $r->print(&Apache::loncommon::start_page('Metadata',
1.153 albertel 797: undef,
798: {'domain' => $resdomain,}));
1.66 matthew 799: &present_uneditable_metadata($r,$uri);
800: }
1.153 albertel 801: $r->print(&Apache::loncommon::end_page());
1.66 matthew 802: return OK;
803: }
804:
1.67 matthew 805: #####################################################
806: #####################################################
807: ### ###
808: ### Report Bombs ###
809: ### ###
810: #####################################################
811: #####################################################
1.66 matthew 812: sub report_bombs {
813: my ($r,$uri) = @_;
814: # Set document type
1.67 matthew 815: $uri =~ s:/adm/bombs/::;
816: $uri = &Apache::lonnet::declutter($uri);
1.66 matthew 817: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
1.190 albertel 818: my ($domain,$author)=($uri=~/^($match_domain)\/($match_username)\//);
1.66 matthew 819: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
1.98 www 820: if ($env{'form.clearbombs'}) {
821: &Apache::lonmsg::clear_author_res_msg($uri);
822: }
823: my $clear=&mt('Clear all Messages in Subdirectory');
1.212 www 824: my $cancel=&mt('Back to Directory');
825: my $cancelurl=$uri;
826: $cancelurl=~s/^\Q$domain\E/\/priv/;
827: $r->print(<<ENDCLEAR);
1.98 www 828: <form method="post">
829: <input type="submit" name="clearbombs" value="$clear" />
1.212 www 830: <a href="$cancelurl">$cancel</a>
831: </form><hr />
1.98 www 832: ENDCLEAR
1.67 matthew 833: my %brokenurls =
834: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
835: foreach (sort(keys(%brokenurls))) {
1.66 matthew 836: if ($_=~/^\Q$uri\E/) {
1.70 matthew 837: $r->print
838: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
839: &Apache::lonmsg::retrieve_author_res_msg($_).
840: '<hr />');
1.64 matthew 841: }
842: }
1.66 matthew 843: } else {
844: $r->print(&mt('Not authorized'));
845: }
846: return;
847: }
848:
1.67 matthew 849: #####################################################
850: #####################################################
851: ### ###
852: ### Uneditable Metadata Display ###
853: ### ###
854: #####################################################
855: #####################################################
1.66 matthew 856: sub present_uneditable_metadata {
857: my ($r,$uri) = @_;
858: #
1.162 albertel 859: my $uploaded = ($uri =~ m|/uploaded/|);
1.66 matthew 860: my %content=();
861: # Read file
862: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
863: $content{$_}=&Apache::lonnet::metadata($uri,$_);
864: }
865: # Render Output
866: # displayed url
867: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
868: $uri=~s/\.meta$//;
1.183 albertel 869: my $disuri=&Apache::lonnet::clutter_with_no_wrapper($uri);
1.66 matthew 870: # version
871: my $versiondisplay='';
1.162 albertel 872: if (!$uploaded) {
873: my $currentversion=&Apache::lonnet::getversion($disuri);
874: if ($thisversion) {
875: $versiondisplay=&mt('Version').': '.$thisversion.
876: ' ('.&mt('most recent version').': '.
877: ($currentversion>0 ?
878: $currentversion :
879: &mt('information not available')).')';
880: } else {
881: $versiondisplay='Version: '.$currentversion;
882: }
1.66 matthew 883: }
1.72 matthew 884: # crumbify displayed URL uri target prefix form size
885: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
886: $disuri =~ s:<br />::g;
1.66 matthew 887: # obsolete
888: my $obsolete=$content{'obsolete'};
889: my $obsoletewarning='';
1.96 albertel 890: if (($obsolete) && ($env{'user.adv'})) {
1.66 matthew 891: $obsoletewarning='<p><font color="red">'.
892: &mt('This resource has been marked obsolete by the author(s)').
893: '</font></p>';
894: }
895: #
896: my %lt=&fieldnames();
897: my $table='';
1.72 matthew 898: my $title = $content{'title'};
899: if (! defined($title)) {
900: $title = 'Untitled Resource';
901: }
1.163 albertel 902: my @fields;
903: if ($uploaded) {
904: @fields = ('title','author','subject','keywords','notes','abstract',
905: 'lowestgradelevel','highestgradelevel','standards','mime',
906: 'owner');
907: } else {
908: @fields = ('title',
909: 'author',
910: 'subject',
911: 'keywords',
912: 'notes',
913: 'abstract',
914: 'lowestgradelevel',
915: 'highestgradelevel',
916: 'standards',
917: 'mime',
918: 'language',
919: 'creationdate',
920: 'lastrevisiondate',
921: 'owner',
922: 'copyright',
923: 'customdistributionfile',
924: 'sourceavail',
925: 'sourcerights',
926: 'obsolete',
927: 'obsoletereplacement');
928: }
929: foreach my $field (@fields) {
930: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$field}.
1.66 matthew 931: '</td><td bgcolor="#CCCCCC">'.
1.163 albertel 932: &prettyprint($field,$content{$field}).'</td></tr>';
933: delete($content{$field});
1.66 matthew 934: }
935: #
936: $r->print(<<ENDHEAD);
1.72 matthew 937: <h2>$title</h2>
938: <p>
939: $disuri<br />
1.36 www 940: $obsoletewarning
1.72 matthew 941: $versiondisplay
942: </p>
1.88 banghart 943: <table cellspacing="2" border="0">
1.45 www 944: $table
1.11 www 945: </table>
1.1 www 946: ENDHEAD
1.162 albertel 947: if (!$uploaded && $env{'user.adv'}) {
1.68 matthew 948: &print_dynamic_metadata($r,$uri,\%content);
1.67 matthew 949: }
950: return;
951: }
952:
953: sub print_dynamic_metadata {
1.68 matthew 954: my ($r,$uri,$content) = @_;
955: #
1.69 matthew 956: my %content = %$content;
1.68 matthew 957: my %lt=&fieldnames();
1.67 matthew 958: #
959: my $description = 'Dynamic Metadata (updated periodically)';
960: $r->print('<h3>'.&mt($description).'</h3>'.
1.70 matthew 961: &mt('Processing'));
1.67 matthew 962: $r->rflush();
963: my %items=&fieldnames();
964: my %dynmeta=&dynamicmeta($uri);
965: #
966: # General Access and Usage Statistics
1.70 matthew 967: if (exists($dynmeta{'count'}) ||
968: exists($dynmeta{'sequsage'}) ||
969: exists($dynmeta{'comefrom'}) ||
970: exists($dynmeta{'goto'}) ||
971: exists($dynmeta{'course'})) {
972: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
1.88 banghart 973: '<table cellspacing="2" border="0">');
1.70 matthew 974: foreach ('count',
975: 'sequsage','sequsage_list',
976: 'comefrom','comefrom_list',
977: 'goto','goto_list',
978: 'course','course_list') {
979: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
980: '<td bgcolor="#CCCCCC">'.
981: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
982: }
983: $r->print('</table>');
984: } else {
985: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
1.67 matthew 986: }
1.69 matthew 987: #
988: # Assessment statistics
1.73 matthew 989: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
990: if (exists($dynmeta{'stdno'}) ||
991: exists($dynmeta{'avetries'}) ||
992: exists($dynmeta{'difficulty'}) ||
993: exists($dynmeta{'disc'})) {
994: # This is an assessment, print assessment data
995: $r->print('<h4>'.
996: &mt('Overall Assessment Statistical Data').
997: '</h4>'.
1.88 banghart 998: '<table cellspacing="2" border="0">');
1.73 matthew 999: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
1.66 matthew 1000: '<td bgcolor="#CCCCCC">'.
1.73 matthew 1001: &prettyprint('stdno',$dynmeta{'stdno'}).
1002: '</td>'."</tr>\n");
1003: foreach ('avetries','difficulty','disc') {
1004: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
1005: '<td bgcolor="#CCCCCC">'.
1006: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
1007: '</td>'."</tr>\n");
1008: }
1009: $r->print('</table>');
1010: }
1011: if (exists($dynmeta{'stats'})) {
1012: #
1013: # New assessment statistics
1014: $r->print('<h4>'.
1.207 albertel 1015: &mt('Recent Detailed Assessment Statistical Data').
1.73 matthew 1016: '</h4>');
1.88 banghart 1017: my $table = '<table cellspacing="2" border="0">'.
1.73 matthew 1018: '<tr>'.
1.207 albertel 1019: '<th>'.&mt('Course').'</th>'.
1020: '<th>'.&mt('Section(s)').'</th>'.
1021: '<th>'.&mt('Num Student').'s</th>'.
1022: '<th>'.&mt('Mean Tries').'</th>'.
1023: '<th>'.&mt('Degree of Difficulty').'</th>'.
1024: '<th>'.&mt('Degree of Discrimination').'</th>'.
1025: '<th>'.&mt('Time of computation').'</th>'.
1.73 matthew 1026: '</tr>'.$/;
1027: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
1028: my $data = $dynmeta{'stats'}->{$identifier};
1029: my $course = $data->{'course'};
1.154 albertel 1030: my %courseinfo =
1031: &Apache::lonnet::coursedescription($course,
1032: {'one_time' => 1});
1.73 matthew 1033: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
1034: &Apache::lonnet::logthis('lookup for '.$course.' failed');
1035: next;
1036: }
1037: $table .= '<tr>';
1038: $table .=
1039: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
1040: $table .=
1041: '<td align="right">'.$data->{'sections'}.'</td>';
1042: $table .=
1043: '<td align="right">'.$data->{'stdno'}.'</td>';
1044: foreach ('avetries','difficulty','disc') {
1045: $table .= '<td align="right">';
1046: if (exists($data->{$_})) {
1047: $table .= sprintf('%.2f',$data->{$_}).' ';
1048: } else {
1049: $table .= '';
1050: }
1051: $table .= '</td>';
1052: }
1053: $table .=
1054: '<td><nobr>'.
1055: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
1056: '</nobr></td>';
1057: $table .=
1058: '</tr>'.$/;
1059: }
1060: $table .= '</table>'.$/;
1061: $r->print($table);
1062: } else {
1.210 bisitz 1063: $r->print(&mt('No new dynamic data found.'));
1.66 matthew 1064: }
1.70 matthew 1065: } else {
1.73 matthew 1066: $r->print('<h4>'.
1067: &mt('No Assessment Statistical Data is available for this resource').
1068: '</h4>');
1.67 matthew 1069: }
1.73 matthew 1070:
1071: #
1072: #
1.70 matthew 1073: if (exists($dynmeta{'clear'}) ||
1074: exists($dynmeta{'depth'}) ||
1075: exists($dynmeta{'helpful'}) ||
1076: exists($dynmeta{'correct'}) ||
1077: exists($dynmeta{'technical'})){
1078: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
1.88 banghart 1079: '<table cellspacing="2" border="0">');
1.70 matthew 1080: foreach ('clear','depth','helpful','correct','technical') {
1081: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
1082: '<td bgcolor="#CCCCCC">'.
1083: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
1084: }
1085: $r->print('</table>');
1086: } else {
1087: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1.67 matthew 1088: }
1.190 albertel 1089: $uri=~/^\/res\/($match_domain)\/($match_username)\//;
1.96 albertel 1090: if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
1091: || ($env{'user.role.ca./'.$1.'/'.$2})) {
1.70 matthew 1092: if (exists($dynmeta{'comments'})) {
1093: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
1094: &mt('visible to author and co-authors only').
1095: ')</h4>'.
1096: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
1097: } else {
1098: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
1099: }
1100: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
1101: if (defined($bombs) && $bombs ne '') {
1102: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
1103: &mt('visible to author and co-authors only').')'.
1104: '</h4>'.$bombs);
1105: } else {
1106: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
1107: }
1.67 matthew 1108: }
1.69 matthew 1109: #
1.67 matthew 1110: # All other stuff
1111: $r->print('<h3>'.
1112: &mt('Additional Metadata (non-standard, parameters, exports)').
1.81 www 1113: '</h3><table border="0" cellspacing="1">');
1.67 matthew 1114: foreach (sort(keys(%content))) {
1115: my $name=$_;
1116: if ($name!~/\.display$/) {
1117: my $display=&Apache::lonnet::metadata($uri,
1118: $name.'.display');
1119: if (! $display) {
1120: $display=$name;
1121: };
1122: my $otherinfo='';
1123: foreach ('name','part','type','default') {
1124: if (defined(&Apache::lonnet::metadata($uri,
1125: $name.'.'.$_))) {
1126: $otherinfo.=' '.$_.'='.
1127: &Apache::lonnet::metadata($uri,
1128: $name.'.'.$_).'; ';
1129: }
1.64 matthew 1130: }
1.81 www 1131: $r->print('<tr><td bgcolor="#bbccbb"><font size="-1" color="#556655">'.$display.'</font></td><td bgcolor="#ccddcc"><font size="-1" color="#556655">'.$content{$name});
1.67 matthew 1132: if ($otherinfo) {
1133: $r->print(' ('.$otherinfo.')');
1.64 matthew 1134: }
1.81 www 1135: $r->print("</font></td></tr>\n");
1.64 matthew 1136: }
1.66 matthew 1137: }
1.81 www 1138: $r->print("</table>");
1.67 matthew 1139: return;
1.66 matthew 1140: }
1.105 banghart 1141:
1.102 banghart 1142:
1143:
1.67 matthew 1144: #####################################################
1145: #####################################################
1146: ### ###
1147: ### Editable metadata display ###
1148: ### ###
1149: #####################################################
1150: #####################################################
1.66 matthew 1151: sub present_editable_metadata {
1.172 banghart 1152: my ($r,$uri,$file_type) = @_;
1.66 matthew 1153: # Construction Space Call
1154: # Header
1155: my $disuri=$uri;
1156: my $fn=&Apache::lonnet::filelocation('',$uri);
1.155 albertel 1157: $disuri=~s{^/\~}{/priv/};
1.66 matthew 1158: $disuri=~s/\.meta$//;
1.141 albertel 1159: my $meta_uri = $disuri;
1.147 albertel 1160: my $path;
1.141 albertel 1161: if ($disuri =~ m|/portfolio/|) {
1.147 albertel 1162: ($disuri, $meta_uri, $path) = &portfolio_display_uri($disuri,1);
1.141 albertel 1163: }
1.66 matthew 1164: my $target=$uri;
1.155 albertel 1165: $target=~s{^/\~}{/res/$env{'request.role.domain'}/};
1.66 matthew 1166: $target=~s/\.meta$//;
1167: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
1168: if ($bombs) {
1.99 www 1169: my $showdel=1;
1.96 albertel 1170: if ($env{'form.delmsg'}) {
1.66 matthew 1171: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
1172: $bombs=&mt('Messages deleted.');
1.99 www 1173: $showdel=0;
1.66 matthew 1174: } else {
1175: $bombs=&mt('Error deleting messages');
1.64 matthew 1176: }
1.66 matthew 1177: }
1.98 www 1178: if ($env{'form.clearmsg'}) {
1179: my $cleardir=$target;
1180: $cleardir=~s/\/[^\/]+$/\//;
1181: if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
1182: $bombs=&mt('Messages cleared.');
1.99 www 1183: $showdel=0;
1.98 www 1184: } else {
1185: $bombs=&mt('Error clearing messages');
1186: }
1187: }
1188: my $del=&mt('Delete Messages for this Resource');
1189: my $clear=&mt('Clear all Messages in Subdirectory');
1.99 www 1190: my $goback=&mt('Back to Source File');
1.66 matthew 1191: $r->print(<<ENDBOMBS);
1.52 www 1192: <h1>$disuri</h1>
1.169 banghart 1193: <form method="post" action="" name="defaultmeta">
1.99 www 1194: ENDBOMBS
1195: if ($showdel) {
1196: $r->print(<<ENDDEL);
1.59 www 1197: <input type="submit" name="delmsg" value="$del" />
1.98 www 1198: <input type="submit" name="clearmsg" value="$clear" />
1.99 www 1199: ENDDEL
1200: } else {
1.208 albertel 1201: $r->print('<p><a href="'.$disuri.'">'.$goback.'</a></p>');
1.203 albertel 1202: if ($env{'form.clearmsg'}) {
1203: my ($diruri) = ($disuri =~ m{(.*/)[^/]*});
1.208 albertel 1204: $r->print('<p><a href="'.$diruri.'">'.
1.203 albertel 1205: &mt('Back To Directory').'</a></p>');
1206: }
1.99 www 1207: }
1208: $r->print('<br />'.$bombs);
1.66 matthew 1209: } else {
1.214 schafran 1210: my $displayfile=&mt('Metadata for [_1]',$disuri);
1.66 matthew 1211: if ($disuri=~/\/default$/) {
1212: my $dir=$disuri;
1213: $dir=~s/default$//;
1.214 schafran 1214: $displayfile=&mt('Default Metadata for Directory [_1]',$dir);
1.66 matthew 1215: }
1216: %Apache::lonpublisher::metadatafields=();
1217: %Apache::lonpublisher::metadatakeys=();
1.94 banghart 1218: my $result=&Apache::lonnet::getfile($fn);
1219: if ($result == -1){
1.141 albertel 1220: $r->print(&mt('Creating new file [_1]'),$meta_uri);
1.94 banghart 1221: } else {
1222: &Apache::lonpublisher::metaeval($result);
1223: }
1.200 raeburn 1224: if ($env{'form.new_courserestricted'}) {
1225: my $new_assoc_course = $env{'form.new_courserestricted'};
1226: my $prev_courserestricted = $Apache::lonpublisher::metadatafields{'courserestricted'};
1227: if (($prev_courserestricted) &&
1228: ($prev_courserestricted ne $new_assoc_course)) {
1229: my $transfers = [];
1230: foreach my $key (keys(%env)) {
1231: if ($key =~ /^form\.transfer_(.+)$/) {
1232: push(@{$transfers},$1);
1233: }
1234: }
1235: if (@{$transfers} > 0) {
1236: &store_transferred_addedfields($fn,$uri,$transfers);
1237: }
1238: }
1239: }
1.66 matthew 1240: $r->print(<<ENDEDIT);
1.23 www 1241: <h1>$displayfile</h1>
1.169 banghart 1242: <form method="post" action="" name="defaultmeta">
1.23 www 1243: ENDEDIT
1.90 banghart 1244: my %lt=&fieldnames($file_type);
1.87 albertel 1245: my $output;
1.90 banghart 1246: my @fields;
1.174 banghart 1247: my $added_metadata_fields;
1.184 banghart 1248: my @added_order;
1.195 raeburn 1249: if ($file_type eq 'groups') {
1250: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1251: 'course.'.$env{'request.course.id'};
1252: }
1253: if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
1254: (! $env{'form.new_courserestricted'}) && (! $file_type eq 'groups')) {
1255: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1256: 'none';
1257: } elsif ($env{'form.new_courserestricted'}) {
1258: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1259: $env{'form.new_courserestricted'};
1260: }
1.178 raeburn 1261: if ($file_type eq 'portfolio' || $file_type eq 'groups') {
1.174 banghart 1262: if(exists ($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'})) {
1263: # retrieve fieldnames (in order) from the course restricted list
1.185 albertel 1264: @fields = (split(/,/,$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'}));
1.174 banghart 1265: } else {
1266: # no saved field list, use default list
1267: @fields = ('author','title','subject','keywords','abstract',
1268: 'notes','lowestgradelevel',
1269: 'highestgradelevel','standards');
1.195 raeburn 1270: if ($Apache::lonpublisher::metadatafields{'courserestricted'} =~ /^course\.($match_domain\_$match_courseid)$/) {
1271: my $assoc_crs = $1;
1272: $added_metadata_fields = &Apache::lonparmset::get_added_meta_fieldnames($assoc_crs);
1273: if ($env{'course.'.$assoc_crs.'.metadata.addedorder'}) {
1274: @added_order = split(/,/,$env{'course.'.$assoc_crs.'.metadata.addedorder'});
1275: }
1276: $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.fieldlist'} = join(",",@fields);
1277: }
1.174 banghart 1278: }
1.90 banghart 1279: } else {
1280: @fields = ('author','title','subject','keywords','abstract','notes',
1.185 albertel 1281: 'copyright','customdistributionfile','language',
1282: 'standards',
1283: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1284: 'obsolete','obsoletereplacement');
1.90 banghart 1285: }
1.120 banghart 1286: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
1287: $Apache::lonpublisher::metadatafields{'copyright'}=
1.163 albertel 1288: 'default';
1.120 banghart 1289: }
1.172 banghart 1290: if (($file_type eq 'portfolio') || ($file_type eq 'groups')) {
1.163 albertel 1291: if (! $Apache::lonpublisher::metadatafields{'mime'}) {
1292: ($Apache::lonpublisher::metadatafields{'mime'}) =
1293: ( $target=~/\.(\w+)$/ );
1294: }
1295: if (! $Apache::lonpublisher::metadatafields{'owner'}) {
1296: $Apache::lonpublisher::metadatafields{'owner'} =
1297: $env{'user.name'}.':'.$env{'user.domain'};
1298: }
1.209 albertel 1299: if (! $Apache::lonpublisher::metadatafields{'author'}) {
1300: $Apache::lonpublisher::metadatafields{'author'} =
1301: &Apache::loncommon::plainname($env{'user.name'},
1302: $env{'user.domain'});
1303: }
1.197 banghart 1304: if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
1.163 albertel 1305:
1.191 raeburn 1306: if ($file_type eq 'portfolio') {
1307: $r->print(&mt('Associated with course [_1]',
1.188 banghart 1308: '<strong><a href="'.$uri.'?changecourse=true">'.
1309: $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.
1310: ".description"}.
1311: '</a></strong>').'<br />');
1.191 raeburn 1312: } else {
1313: $r->print(&mt('Associated with course [_1]',
1314: '<strong>'.
1315: $env{$Apache::lonpublisher::metadatafields{'courserestricted'}.
1316: ".description"}.'</strong>').'<br />');
1317: }
1.149 albertel 1318: } else {
1.210 bisitz 1319: $r->print('<a href="'.$uri.'?changecourse=true">'.&mt('This resource is not associated with a course.').'</a><br />');
1.149 albertel 1320: }
1321: }
1.184 banghart 1322: if (@added_order) {
1.185 albertel 1323: foreach my $field_name (@added_order) {
1324: push(@fields,$field_name);
1.184 banghart 1325: $lt{$field_name} = $$added_metadata_fields{$field_name};
1326: }
1327: } else {
1.185 albertel 1328: foreach my $field_name (keys(%$added_metadata_fields)) {
1329: push(@fields,$field_name);
1.184 banghart 1330: $lt{$field_name} = $$added_metadata_fields{$field_name};
1331: }
1.176 banghart 1332: }
1.189 banghart 1333: $output .= &Apache::loncommon::start_data_table();
1.187 banghart 1334: my $row_alt = 1;
1.143 albertel 1335: foreach my $field_name (@fields) {
1.132 banghart 1336: if (defined($env{'form.new_'.$field_name})) {
1.201 raeburn 1337: my @values = &Apache::loncommon::get_env_multiple('form.new_'.$field_name);
1338: my $newvalue = '';
1339: foreach my $item (@values) {
1340: if ($item ne '') {
1341: $newvalue .= $item.',';
1342: }
1343: }
1344: $newvalue =~ s/,$//;
1345: $Apache::lonpublisher::metadatafields{$field_name}=$newvalue;
1.66 matthew 1346: }
1.150 albertel 1347: if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none'
1348: && exists($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'})) {
1.115 banghart 1349: # handle restrictions here
1.181 banghart 1350: if ((($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
1351: ($field_name eq 'courserestricted'))&&
1352: (!($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/deleted/))){
1.187 banghart 1353:
1.189 banghart 1354: $output .= "\n".&Apache::loncommon::start_data_table_row();
1355: $output .= ('<td><span class="LC_metadata">'.$lt{$field_name}.':</span></td><td> '.
1.132 banghart 1356: &prettyinput($field_name,
1357: $Apache::lonpublisher::metadatafields{$field_name},
1.138 banghart 1358: 'new_'.$field_name,'defaultmeta',
1359: undef,undef,undef,undef,
1.189 banghart 1360: $Apache::lonpublisher::metadatafields{'courserestricted'}).'</td>');
1361: $output .= &Apache::loncommon::end_data_table_row();
1.127 banghart 1362: }
1.115 banghart 1363: } else {
1.138 banghart 1364:
1.189 banghart 1365: $output.=(&Apache::loncommon::start_data_table_row().'<td><span class="LC_metadata">'.$lt{$field_name}.':</span></td><td> '.
1.185 albertel 1366: &prettyinput($field_name,
1367: $Apache::lonpublisher::metadatafields{$field_name},
1.189 banghart 1368: 'new_'.$field_name,'defaultmeta').'</td>'.&Apache::loncommon::end_data_table_row());
1.138 banghart 1369:
1.115 banghart 1370: }
1.66 matthew 1371: }
1.189 banghart 1372: $output .= &Apache::loncommon::end_data_table();
1.143 albertel 1373: if ($env{'form.store'}) {
1.200 raeburn 1374: my ($outcome,$result) = &store_metadata($fn,$uri,'store');
1375: $r->print($result);
1.142 albertel 1376: }
1.214 schafran 1377: $r->print($output.'<br /><input type="submit" title="Save Metadata" name="store" value="'.
1378: &mt('Save').'" />');
1.147 albertel 1379:
1.191 raeburn 1380: if ($file_type eq 'portfolio' || $file_type eq 'groups') {
1.156 albertel 1381: my ($port_path,$group) = &get_port_path_and_group($uri);
1.191 raeburn 1382: if ($group ne '') {
1.159 raeburn 1383: $r->print('<input type="hidden" name="group" value="'.$group.'" />');
1384: }
1.169 banghart 1385: $r->print('<input type="hidden" name="currentpath" value="'.$env{'form.currentpath'}.'" />');
1.175 banghart 1386: $r->print('</form><br /><br /><form method="post" action="'.$port_path.'">');
1.191 raeburn 1387: if ($group ne '') {
1.175 banghart 1388: $r->print('<input type="hidden" name="group" value="'.$group.'" />');
1.191 raeburn 1389: }
1.175 banghart 1390: $r->print('<input type="hidden" name="currentpath" value="'.$path.'" />'.
1.169 banghart 1391: '<input type="submit" name="cancel" value="'.&mt('Discard Edits and Return to Portfolio').'" />');
1.149 albertel 1392: }
1.142 albertel 1393: }
1.149 albertel 1394:
1.143 albertel 1395: $r->print('</form>');
1396:
1.66 matthew 1397: return;
1.1 www 1398: }
1.64 matthew 1399:
1.200 raeburn 1400: sub store_metadata {
1401: my ($fn,$uri,$caller) = @_;
1402: my $mfh;
1403: my $formname='store';
1404: my ($file_content,$output,$outcome);
1405: if (&Apache::loncommon::get_env_multiple('form.new_keywords')) {
1406: $Apache::lonpublisher::metadatafields{'keywords'} =
1407: join (',', &Apache::loncommon::get_env_multiple('form.new_keywords'));
1408: }
1409: foreach my $field (sort(keys(%Apache::lonpublisher::metadatafields))) {
1410: next if ($field =~ /\./);
1411: my $unikey=$field;
1412: $unikey=~/^([A-Za-z_]+)/;
1413: my $tag=$1;
1414: $tag=~tr/A-Z/a-z/;
1415: $file_content.= "\n\<$tag";
1416: foreach my $key (split(/\,/,$Apache::lonpublisher::metadatakeys{$unikey})) {
1417: my $value = $Apache::lonpublisher::metadatafields{$unikey.'.'.$key};
1418: $value=~s/\"/\'\'/g;
1419: $file_content.=' '.$key.'="'.$value.'"' ;
1420: }
1421: $file_content.= '>'.
1422: &HTML::Entities::encode
1423: ($Apache::lonpublisher::metadatafields{$unikey},'<>&"').
1424: '</'.$tag.'>';
1425: }
1426: if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles|) {
1427: my ($path, $new_fn);
1428: if ($fn =~ m|$match_name/groups/\w+/portfolio/|) {
1429: ($path, $new_fn) = ($fn =~ m|/(groups/\w+/portfolio.*)/([^/]*)$|);
1430: } else {
1431: ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|);
1432: }
1433: ($outcome,my $result) =
1434: &store_portfolio_metadata($formname,$file_content,
1435: $path,$new_fn,$uri,$caller);
1436: $output .= $result;
1437: } else {
1438: if (! ($mfh=Apache::File->new('>'.$fn))) {
1439: $output .= '<p><font color="red">';
1440: if ($caller eq 'transfer') {
1441: $output .= &mt('Could not transfer data in added fields to notes');
1442: } else {
1443: $output .= &mt('Could not write metadata');
1444: }
1445: $output .= ', '.&mt('FAIL').'</font></p>';
1446: $outcome = 'fail';
1447: } else {
1448: print $mfh ($file_content);
1449: close($mfh);
1450: &update_metadata_table($uri);
1451: $output .= '<p><font color="blue">';
1452: if ($caller eq 'transfer') {
1453: $output .= &mt('Transferred data in added fields to notes');
1454: } else {
1455: $output .= &mt('Wrote Metadata');
1456: }
1457: $output .= ' '.&Apache::lonlocal::locallocaltime(time).
1458: '</font></p>';
1459: $outcome = 'ok';
1460: }
1461: }
1462: return ($outcome,$output);
1463: }
1464:
1465: sub store_transferred_addedfields {
1466: my ($fn,$uri,$transfers) = @_;
1467: foreach my $item (@{$transfers}) {
1468: $Apache::lonpublisher::metadatafields{'notes'} .=
1469: ' '.$item.' = '.$Apache::lonpublisher::metadatafields{$item};
1470: }
1471: my ($outcome,$output) = &store_metadata($fn,$uri,'transfer');
1472: if ($outcome eq 'ok') {
1473: foreach my $item (@{$transfers}) {
1474: delete($Apache::lonpublisher::metadatafields{$item});
1475: }
1476: }
1477: }
1478:
1.159 raeburn 1479: sub store_portfolio_metadata {
1.200 raeburn 1480: my ($formname,$content,$path,$new_fn,$uri,$caller) = @_;
1481: my ($outcome,$output);
1.159 raeburn 1482: $env{'form.'.$formname}=$content."\n";
1483: $env{'form.'.$formname.'.filename'}=$new_fn;
1484: my $result =&Apache::lonnet::userfileupload($formname,'',$path);
1485: if ($result =~ /(error|notfound)/) {
1.200 raeburn 1486: $output = '<p><font color="red">';
1487: if ($caller eq 'transfer') {
1488: $output .=
1489: &mt('Could not transfer data in added fields to notes');
1490: } else {
1491: $output .= &mt('Could not write metadata');
1492: }
1493: $output .= ', '.&mt('FAIL').'</font></p>';
1494: $outcome = 'fail';
1.159 raeburn 1495: } else {
1.192 raeburn 1496: &update_metadata_table($uri);
1.200 raeburn 1497: $output = '<p><font color="blue">';
1498: if ($caller eq 'transfer') {
1499: $output .= &mt('Transferred data in added fields to notes');
1500: } else {
1501: $output .= &mt('Wrote Metadata');
1502: }
1503: $output .= ' '.&Apache::lonlocal::locallocaltime(time).
1504: '</font></p>';
1505: $outcome = 'ok';
1.159 raeburn 1506: }
1.200 raeburn 1507: return ($outcome,$output);
1.159 raeburn 1508: }
1509:
1.192 raeburn 1510: sub update_metadata_table {
1511: my ($uri) = @_;
1.196 albertel 1512: my ($type,$udom,$uname,$file_name,$group) =
1513: &Apache::lonnet::parse_portfolio_url($uri);
1.192 raeburn 1514: $file_name =~ s/\.meta$//;
1515: my $current_permissions =
1516: &Apache::lonnet::get_portfile_permissions($udom,$uname);
1517: my %access_controls =
1518: &Apache::lonnet::get_access_controls($current_permissions,$group,
1.196 albertel 1519: $file_name);
1.192 raeburn 1520: my $access_hash = $access_controls{$file_name};
1521: my $available = 0;
1522: if (ref($access_hash) eq 'HASH') {
1523: foreach my $key (keys(%{$access_hash})) {
1524: my ($num,$scope,$end,$start) =
1525: ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1526: if ($scope eq 'public' || $scope eq 'guest') {
1527: $available = 1;
1528: last;
1529: }
1530: }
1531: }
1532: if ($available) {
1533: my $result =
1534: &Apache::lonnet::update_portfolio_table($uname,$udom,
1.194 raeburn 1535: $file_name,'portfolio_metadata',$group,'update');
1.192 raeburn 1536: }
1537: }
1538:
1539:
1.1 www 1540: 1;
1541: __END__
1.97 banghart 1542:
1.216 ! jms 1543:
! 1544: =head1 NAME
! 1545:
! 1546: Apache::lonmeta - display meta data
! 1547:
! 1548: =head1 SYNOPSIS
! 1549:
! 1550: Handler to display meta data
! 1551:
! 1552: This is part of the LearningOnline Network with CAPA project
! 1553: described at http://www.lon-capa.org.
! 1554:
! 1555: =head1 SUBROUTINES
! 1556:
! 1557: =over
! 1558:
! 1559: =item &get_dynamic_metadata_from_sql($url) :
! 1560:
! 1561: Queries sql database for dynamic metdata
! 1562: Returns a hash of hashes, with keys of urls which match $url
! 1563: Returned fields are given below.
! 1564:
! 1565: Examples:
! 1566:
! 1567: %DynamicMetadata = &Apache::lonmeta::get_dynmaic_metadata_from_sql
! 1568: ('/res/msu/korte/');
! 1569:
! 1570: $DynamicMetadata{'/res/msu/korte/example.problem'}->{$field}
! 1571:
! 1572: =item dynamicmeta()
! 1573:
! 1574: Fetch and evaluate dynamic metadata
! 1575:
! 1576: =item access_count()
! 1577:
! 1578: =item alttag()
! 1579:
! 1580: Try to make an alt tag if there is none
! 1581:
! 1582: =item authordisplay()
! 1583:
! 1584: Author display
! 1585:
! 1586: =item evalgraph()
! 1587:
! 1588: Pretty display
! 1589:
! 1590: =item diffgraph()
! 1591:
! 1592: =item fieldnames()
! 1593:
! 1594: =item portfolio_linked_path()
! 1595:
! 1596: =item get_port_path_and_group()
! 1597:
! 1598: =item portfolio_display_uri()
! 1599:
! 1600: =item pre_select_course()
! 1601:
! 1602: =item select_course()
! 1603:
! 1604: =item prettyprint()
! 1605:
! 1606: Pretty printing of metadata field
! 1607:
! 1608: =item direct()
! 1609:
! 1610: Pretty input of metadata field
! 1611:
! 1612: =item selectbox()
! 1613:
! 1614: =item relatedfield()
! 1615:
! 1616: =item prettyinput()
! 1617:
! 1618: =item report_bombs()
! 1619:
! 1620: =item present_uneditable_metadata()
! 1621:
! 1622: =item present_editable_metadata()
! 1623:
! 1624: =item store_metadata()
! 1625:
! 1626: =item store_transferred_addedfields()
! 1627:
! 1628: =item store_portfolio_metadata()
! 1629:
! 1630: =item update_metadata_table()
! 1631:
! 1632: =back
! 1633:
! 1634: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>