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