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