1: # The LearningOnline Network with CAPA
2: # Metadata display handler
3: #
4: # $Id: lonmeta.pm,v 1.166 2006/08/08 21:32:36 banghart Exp $
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.
14: #
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: #
20: # You should have received a copy of the GNU General Public License
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/
27:
28:
29: package Apache::lonmeta;
30:
31: use strict;
32: use LONCAPA::lonmetadata();
33: use Apache::Constants qw(:common);
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonhtmlcommon();
37: use Apache::lonmsg;
38: use Apache::lonpublisher;
39: use Apache::lonlocal;
40: use Apache::lonmysql;
41: use Apache::lonmsg;
42: use lib '/home/httpd/lib/perl/';
43: use LONCAPA;
44:
45:
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: }
76: my $query = 'SELECT * FROM metadata WHERE url LIKE "'.$url.'%"';
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);
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};
101: }
102: }
103: $finished = 1;
104: }
105: #
106: return %ReturnHash;
107: }
108:
109:
110: # Fetch and evaluate dynamic metadata
111: sub dynamicmeta {
112: my $url=&Apache::lonnet::declutter(shift);
113: $url=~s/\.meta$//;
114: my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
115: my $regexp=$url;
116: $regexp=~s/(\W)/\\$1/g;
117: $regexp='___'.$regexp.'___';
118: my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
119: $aauthor,$regexp);
120: my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
121: my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
122: \%DynamicData);
123: #
124: # Deal with 'count' separately
125: $Data{'count'} = &access_count($url,$aauthor,$adomain);
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: }
135: return %Data;
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})) {
143: return &mt('Not Available');
144: } else {
145: return $countdata{$src};
146: }
147: }
148:
149: # Try to make an alt tag if there is none
150: sub alttag {
151: my ($base,$src)=@_;
152: my $fullpath=&Apache::lonnet::hreflocation($base,$src);
153: my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
154: &Apache::lonnet::metadata($fullpath,'subject').' '.
155: &Apache::lonnet::metadata($fullpath,'abstract');
156: $alttag=~s/\s+/ /gs;
157: $alttag=~s/\"//gs;
158: $alttag=~s/\'//gs;
159: $alttag=~s/\s+$//gs;
160: $alttag=~s/^\s+//gs;
161: if ($alttag) {
162: return $alttag;
163: } else {
164: return &mt('No information available');
165: }
166: }
167:
168: # Author display
169: sub authordisplay {
170: my ($aname,$adom)=@_;
171: return &Apache::loncommon::aboutmewrapper
172: (&Apache::loncommon::plainname($aname,$adom),
173: $aname,$adom,'preview').' <tt>['.$aname.':'.$adom.']</tt>';
174: }
175:
176: # Pretty display
177: sub evalgraph {
178: my $value=shift;
179: if (! $value) {
180: return '';
181: }
182: my $val=int($value*10.+0.5)-10;
183: my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
184: if ($val>=20) {
185: $output.='<td width="20" bgcolor="#555555">  </td>';
186: } else {
187: $output.='<td width="'.($val).'" bgcolor="#555555"> </td>'.
188: '<td width="'.(20-$val).'" bgcolor="#FF3333"> </td>';
189: }
190: $output.='<td bgcolor="#FFFF33"> </td>';
191: if ($val>20) {
192: $output.='<td width="'.($val-20).'" bgcolor="#33FF33"> </td>'.
193: '<td width="'.(40-$val).'" bgcolor="#555555"> </td>';
194: } else {
195: $output.='<td width="20" bgcolor="#555555">  </td>';
196: }
197: $output.='<td> ('.sprintf("%5.2f",$value).') </td></tr></table>';
198: return $output;
199: }
200:
201: sub diffgraph {
202: my $value=shift;
203: if (! $value) {
204: return '';
205: }
206: my $val=int(40.0*$value+0.5);
207: my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
208: '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
209: my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
210: for (my $i=0;$i<8;$i++) {
211: if ($val>$i*5) {
212: $output.='<td width="5" bgcolor="'.$colors[$i].'"> </td>';
213: } else {
214: $output.='<td width="5" bgcolor="#555555"> </td>';
215: }
216: }
217: $output.='<td> ('.sprintf("%3.2f",$value).') </td></tr></table>';
218: return $output;
219: }
220:
221:
222: # The field names
223: sub fieldnames {
224: my $file_type=shift;
225: my %fields =
226: ('title' => 'Title',
227: 'author' =>'Author(s)',
228: 'authorspace' => 'Author Space',
229: 'modifyinguser' => 'Last Modifying User',
230: 'subject' => 'Subject',
231: 'standards' => 'Standards',
232: 'keywords' => 'Keyword(s)',
233: 'notes' => 'Notes',
234: 'abstract' => 'Abstract',
235: 'lowestgradelevel' => 'Lowest Grade Level',
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: }
243:
244: if (! defined($file_type) || $file_type ne 'portfolio') {
245: %fields =
246: (%fields,
247: 'domain' => 'Domain',
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',
255: 'sourceavail' => 'Source Available',
256: 'sourcerights' => 'Source Custom Distribution File',
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',
275: 'difficulty' => 'Degree of difficulty',
276: 'disc' => 'Degree of discrimination',
277: 'dependencies' => 'Resources used by this resource',
278: );
279: }
280: return &Apache::lonlocal::texthash(%fields);
281: }
282:
283: sub portfolio_linked_path {
284: my ($path,$group,$port_path) = @_;
285:
286: my $start = 'portfolio';
287: if ($group) {
288: $start = "groups/$group/".$start;
289: }
290: my %anchor_fields = (
291: 'selectfile' => $start,
292: 'currentpath' => '/'
293: );
294: my $result = &Apache::portfolio::make_anchor($port_path,\%anchor_fields,$start);
295: my $fullpath = '/';
296: my (undef,@tree) = split('/',$path);
297: my $filename = pop(@tree);
298: foreach my $dir (@tree) {
299: $fullpath .= $dir.'/';
300: $result .= '/';
301: my %anchor_fields = (
302: 'selectfile' => $dir,
303: 'currentpath' => $fullpath
304: );
305: $result .= &Apache::portfolio::make_anchor($port_path,\%anchor_fields,$dir);
306: }
307: $result .= "/$filename";
308: return $result;
309: }
310:
311: sub get_port_path_and_group {
312: my ($uri)=@_;
313:
314: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
315: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
316:
317: my ($port_path,$group);
318: if ($uri =~ m{^/editupload/\Q$cdom\E/\Q$cnum\E/groups/}) {
319: $group = (split('/',$uri))[5];
320: $port_path = '/adm/coursegrp_portfolio';
321: } else {
322: $port_path = '/adm/portfolio';
323: }
324: if ($env{'form.group'} ne $group) {
325: $env{'form.group'} = $group;
326: }
327: return ($port_path,$group);
328: }
329:
330: sub portfolio_display_uri {
331: my ($uri,$as_links)=@_;
332:
333: my ($port_path,$group) = &get_port_path_and_group($uri);
334:
335: $uri =~ s|.*/(portfolio/.*)$|$1|;
336: my ($res_uri,$meta_uri) = ($uri,$uri);
337: if ($uri =~ /\.meta$/) {
338: $res_uri =~ s/\.meta//;
339: } else {
340: $meta_uri .= '.meta';
341: }
342:
343: my ($path) = ($res_uri =~ m|^portfolio(.*/)[^/]*$|);
344: if ($as_links) {
345: $res_uri = &portfolio_linked_path($res_uri,$group,$port_path);
346: $meta_uri = &portfolio_linked_path($meta_uri,$group,$port_path);
347: }
348: return ($res_uri,$meta_uri,$path);
349: }
350:
351: sub pre_select_course {
352: my ($r,$uri) = @_;
353: my $output;
354: my $fn=&Apache::lonnet::filelocation('',$uri);
355: my ($res_uri,$meta_uri,$path) = &portfolio_display_uri($uri);
356: %Apache::lonpublisher::metadatafields=();
357: %Apache::lonpublisher::metadatakeys=();
358: my $result=&Apache::lonnet::getfile($fn);
359: if ($result == -1){
360: $r->print(&mt('Creating new file [_1]'),$meta_uri);
361: } else {
362: &Apache::lonpublisher::metaeval($result);
363: }
364: $r->print('<hr /><form method="post" action="" >');
365: $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>');
366: $output = &select_course();
367: $r->print($output.'<br /><input type="submit" name="store" value="'.
368: &mt('Associate Resource With Selected Course').'">');
369: $r->print('</form>');
370:
371: my ($port_path,$group) = &get_port_path_and_group($uri);
372: $r->print('<br /><br /><form method="POST" action="'.$port_path.'">'.
373: '<input type="hidden" name="currentpath" value="'.$path.'" />'.
374: '<input type="hidden" name="group" value="'.$group.'" />'.
375: '<input type="submit" name="cancel" value="'.&mt('Cancel').'">'.
376: '</form>');
377:
378: return;
379: }
380: sub select_course {
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>'.$/;
390: my %courses;
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 = '';
406: }
407: $output .= '</select><br />';
408: return ($output);
409: }
410: # Pretty printing of metadata field
411:
412: sub prettyprint {
413: my ($type,$value,$target,$prefix,$form,$noformat)=@_;
414: # $target,$prefix,$form are optional and for filecrumbs only
415: if (! defined($value)) {
416: return ' ';
417: }
418: # Title
419: if ($type eq 'title') {
420: return '<font size="+1" face="arial">'.$value.'</font>';
421: }
422: # Dates
423: if (($type eq 'creationdate') ||
424: ($type eq 'lastrevisiondate')) {
425: return ($value?&Apache::lonlocal::locallocaltime(
426: &Apache::lonmysql::unsqltime($value)):
427: &mt('not available'));
428: }
429: # Language
430: if ($type eq 'language') {
431: return &Apache::loncommon::languagedescription($value);
432: }
433: # Copyright
434: if ($type eq 'copyright') {
435: return &Apache::loncommon::copyrightdescription($value);
436: }
437: # Copyright
438: if ($type eq 'sourceavail') {
439: return &Apache::loncommon::source_copyrightdescription($value);
440: }
441: # MIME
442: if ($type eq 'mime') {
443: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
444: &Apache::loncommon::filedescription($value);
445: }
446: # Person
447: if (($type eq 'author') ||
448: ($type eq 'owner') ||
449: ($type eq 'modifyinguser') ||
450: ($type eq 'authorspace')) {
451: $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
452: return $value;
453: }
454: # Gradelevel
455: if (($type eq 'lowestgradelevel') ||
456: ($type eq 'highestgradelevel')) {
457: return &Apache::loncommon::gradeleveldescription($value);
458: }
459: # Only for advance users below
460: if (! $env{'user.adv'}) {
461: return '<i>- '.&mt('not displayed').' -</i>';
462: }
463: # File
464: if (($type eq 'customdistributionfile') ||
465: ($type eq 'obsoletereplacement') ||
466: ($type eq 'goto_list') ||
467: ($type eq 'comefrom_list') ||
468: ($type eq 'sequsage_list') ||
469: ($type eq 'dependencies')) {
470: return '<font size="-1"><ul>'.join("\n",map {
471: my $url = &Apache::lonnet::clutter($_);
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: }
487: $_ = '<li>'.$title.' '.
488: &Apache::lonhtmlcommon::crumbs($url,$target,$prefix,$form,'-1',$noformat).
489: '</li>'
490: } split(/\s*\,\s*/,$value)).'</ul></font>';
491: }
492: # Evaluations
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: }
500: # Difficulty
501: if ($type eq 'difficulty' || $type eq 'disc') {
502: return &diffgraph($value);
503: }
504: # List of courses
505: if ($type=~/\_list/) {
506: my @Courses = split(/\s*\,\s*/,$value);
507: my $Str='<font size="-1"><ul>';
508: foreach my $course (@Courses) {
509: my %courseinfo =
510: &Apache::lonnet::coursedescription($course,
511: {'one_time' => 1});
512: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
513: next;
514: }
515: $Str .= '<li><a href="/public/'.$courseinfo{'domain'}.'/'.
516: $courseinfo{'num'}.'/syllabus" target="preview">'.
517: $courseinfo{'description'}.'</a></li>';
518: }
519: return $Str.'</ul></font>';
520: }
521: # No pretty print found
522: return $value;
523: }
524:
525: # Pretty input of metadata field
526: sub direct {
527: return shift;
528: }
529:
530: sub selectbox {
531: my ($name,$value,$functionref,@idlist)=@_;
532: if (! defined($functionref)) {
533: $functionref=\&direct;
534: }
535: my $selout='<select name="'.$name.'">';
536: foreach (@idlist) {
537: $selout.='<option value=\''.$_.'\'';
538: if ($_ eq $value) {
539: $selout.=' selected>'.&{$functionref}($_).'</option>';
540: }
541: else {$selout.='>'.&{$functionref}($_).'</option>';}
542: }
543: return $selout.'</select>';
544: }
545:
546: sub relatedfield {
547: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
548: if (! $relatedsearchflag) {
549: return '';
550: }
551: if (! defined($relatedsep)) {
552: $relatedsep=' ';
553: }
554: if (! $show) {
555: return $relatedsep.' ';
556: }
557: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
558: ($relatedvalue?' checked="1"':'').' />';
559: }
560:
561: sub prettyinput {
562: my ($type,$value,$fieldname,$formname,
563: $relatedsearchflag,$relatedsep,$relatedvalue,$size,$course_key)=@_;
564: if (! defined($size)) {
565: $size = 80;
566: }
567: my $output;
568: if (defined($course_key)
569: && exists($env{$course_key.'.metadata.'.$type.'.options'})) {
570: my $stu_add;
571: my $only_one;
572: my %meta_options;
573: my @cur_values_inst;
574: my $cur_values_stu;
575: my $values = $env{$course_key.'.metadata.'.$type.'.values'};
576: if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/stuadd/) {
577: $stu_add = 'true';
578: }
579: if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/onlyone/) {
580: $only_one = 'true';
581: }
582: # need to take instructor values out of list where instructor and student
583: # values may be mixed.
584: if ($values) {
585: foreach my $item (split(/,/,$values)) {
586: $item =~ s/^\s+//;
587: $meta_options{$item} = $item;
588: }
589: foreach my $item (split(/,/,$value)) {
590: $item =~ s/^\s+//;
591: if ($meta_options{$item}) {
592: push(@cur_values_inst,$item);
593: } else {
594: $cur_values_stu .= $item.',';
595: }
596: }
597: } else {
598: $cur_values_stu = $value;
599: }
600: if ($type eq 'courserestricted') {
601: return (&select_course());
602: # return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
603: }
604: if (($type eq 'keywords') || ($type eq 'subject')
605: || ($type eq 'author')||($type eq 'notes')
606: || ($type eq 'abstract')|| ($type eq 'title')|| ($type eq 'standards')) {
607: if ($values) {
608: if ($only_one) {
609: $output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options));
610: } else {
611: $output .= (&Apache::loncommon::multiple_select_form('new_'.$type,\@cur_values_inst,undef,\%meta_options));
612: }
613: }
614: if ($stu_add) {
615: $output .= '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
616: 'value="'.$cur_values_stu.'" />'.
617: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
618: $relatedvalue);
619: }
620: return ($output);
621: }
622: if (($type eq 'lowestgradelevel') ||
623: ($type eq 'highestgradelevel')) {
624: return &Apache::loncommon::select_level_form($value,$fieldname).
625: &relatedfield(0,$relatedsearchflag,$relatedsep);
626: }
627: return();
628: }
629: # Language
630: if ($type eq 'language') {
631: return &selectbox($fieldname,
632: $value,
633: \&Apache::loncommon::languagedescription,
634: (&Apache::loncommon::languageids)).
635: &relatedfield(0,$relatedsearchflag,$relatedsep);
636: }
637: # Copyright
638: if ($type eq 'copyright') {
639: return &selectbox($fieldname,
640: $value,
641: \&Apache::loncommon::copyrightdescription,
642: (&Apache::loncommon::copyrightids)).
643: &relatedfield(0,$relatedsearchflag,$relatedsep);
644: }
645: # Source Copyright
646: if ($type eq 'sourceavail') {
647: return &selectbox($fieldname,
648: $value,
649: \&Apache::loncommon::source_copyrightdescription,
650: (&Apache::loncommon::source_copyrightids)).
651: &relatedfield(0,$relatedsearchflag,$relatedsep);
652: }
653: # Gradelevels
654: if (($type eq 'lowestgradelevel') ||
655: ($type eq 'highestgradelevel')) {
656: return &Apache::loncommon::select_level_form($value,$fieldname).
657: &relatedfield(0,$relatedsearchflag,$relatedsep);
658: }
659: # Obsolete
660: if ($type eq 'obsolete') {
661: return '<input type="checkbox" name="'.$fieldname.'"'.
662: ($value?' checked="1"':'').' />'.
663: &relatedfield(0,$relatedsearchflag,$relatedsep);
664: }
665: # Obsolete replacement file
666: if ($type eq 'obsoletereplacement') {
667: return '<input type="text" name="'.$fieldname.
668: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
669: "('".$formname."','".$fieldname."'".
670: ",'')\">".&mt('Select').'</a>'.
671: &relatedfield(0,$relatedsearchflag,$relatedsep);
672: }
673: # Customdistribution file
674: if ($type eq 'customdistributionfile') {
675: return '<input type="text" name="'.$fieldname.
676: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
677: "('".$formname."','".$fieldname."'".
678: ",'rights')\">".&mt('Select').'</a>'.
679: &relatedfield(0,$relatedsearchflag,$relatedsep);
680: }
681: # Source Customdistribution file
682: if ($type eq 'sourcerights') {
683: return '<input type="text" name="'.$fieldname.
684: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
685: "('".$formname."','".$fieldname."'".
686: ",'rights')\">".&mt('Select').'</a>'.
687: &relatedfield(0,$relatedsearchflag,$relatedsep);
688: }
689: if ($type eq 'courserestricted') {
690: return (&select_course());
691: #return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
692: }
693:
694: # Dates
695: if (($type eq 'creationdate') ||
696: ($type eq 'lastrevisiondate')) {
697: return
698: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
699: &relatedfield(0,$relatedsearchflag,$relatedsep);
700: }
701: # No pretty input found
702: $value=~s/^\s+//gs;
703: $value=~s/\s+$//gs;
704: $value=~s/\s+/ /gs;
705: $value=~s/\"/\"\;/gs;
706: return
707: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
708: 'value="'.$value.'" />'.
709: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
710: $relatedvalue);
711: }
712:
713: # Main Handler
714: sub handler {
715: my $r=shift;
716: #
717: my $uri=$r->uri;
718: #
719: # Set document type
720: &Apache::loncommon::content_type($r,'text/html');
721: $r->send_http_header;
722: return OK if $r->header_only;
723: #
724: my ($resdomain,$resuser)=
725: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
726: if ($uri=~m:/adm/bombs/(.*)$:) {
727: $r->print(&Apache::loncommon::start_page('Error Messages'));
728: # Looking for all bombs?
729: &report_bombs($r,$uri);
730: } elsif ($uri=~m|^/editupload/[^/]+/[^/]+/portfolio/|) {
731: ($resdomain,$resuser)=
732: (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
733: $r->print(&Apache::loncommon::start_page('Edit Portfolio File Catalog Information',
734: undef,
735: {'domain' => $resdomain,}));
736: if ($env{'form.store'}) {
737: &present_editable_metadata($r,$uri,'portfolio');
738: } else {
739: &pre_select_course($r,$uri);
740: }
741: } elsif ($uri=~m|^/~|) {
742: # Construction space
743: $r->print(&Apache::loncommon::start_page('Edit Catalog nformation',
744: undef,
745: {'domain' => $resdomain,}));
746: &present_editable_metadata($r,$uri);
747: } else {
748: $r->print(&Apache::loncommon::start_page('Catalog Information',
749: undef,
750: {'domain' => $resdomain,}));
751: &present_uneditable_metadata($r,$uri);
752: }
753: $r->print(&Apache::loncommon::end_page());
754: return OK;
755: }
756:
757: #####################################################
758: #####################################################
759: ### ###
760: ### Report Bombs ###
761: ### ###
762: #####################################################
763: #####################################################
764: sub report_bombs {
765: my ($r,$uri) = @_;
766: # Set document type
767: $uri =~ s:/adm/bombs/::;
768: $uri = &Apache::lonnet::declutter($uri);
769: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
770: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
771: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
772: if ($env{'form.clearbombs'}) {
773: &Apache::lonmsg::clear_author_res_msg($uri);
774: }
775: my $clear=&mt('Clear all Messages in Subdirectory');
776: $r->print(<<ENDCLEAR);
777: <form method="post">
778: <input type="submit" name="clearbombs" value="$clear" />
779: </form>
780: ENDCLEAR
781: my %brokenurls =
782: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
783: foreach (sort(keys(%brokenurls))) {
784: if ($_=~/^\Q$uri\E/) {
785: $r->print
786: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
787: &Apache::lonmsg::retrieve_author_res_msg($_).
788: '<hr />');
789: }
790: }
791: } else {
792: $r->print(&mt('Not authorized'));
793: }
794: return;
795: }
796:
797: #####################################################
798: #####################################################
799: ### ###
800: ### Uneditable Metadata Display ###
801: ### ###
802: #####################################################
803: #####################################################
804: sub present_uneditable_metadata {
805: my ($r,$uri) = @_;
806: #
807: my $uploaded = ($uri =~ m|/uploaded/|);
808: my %content=();
809: # Read file
810: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
811: $content{$_}=&Apache::lonnet::metadata($uri,$_);
812: }
813: # Render Output
814: # displayed url
815: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
816: $uri=~s/\.meta$//;
817: my $disuri=&Apache::lonnet::clutter($uri);
818: $disuri=~s/^\/adm\/wrapper//;
819: # version
820: my $versiondisplay='';
821: if (!$uploaded) {
822: my $currentversion=&Apache::lonnet::getversion($disuri);
823: if ($thisversion) {
824: $versiondisplay=&mt('Version').': '.$thisversion.
825: ' ('.&mt('most recent version').': '.
826: ($currentversion>0 ?
827: $currentversion :
828: &mt('information not available')).')';
829: } else {
830: $versiondisplay='Version: '.$currentversion;
831: }
832: }
833: # crumbify displayed URL uri target prefix form size
834: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
835: $disuri =~ s:<br />::g;
836: # obsolete
837: my $obsolete=$content{'obsolete'};
838: my $obsoletewarning='';
839: if (($obsolete) && ($env{'user.adv'})) {
840: $obsoletewarning='<p><font color="red">'.
841: &mt('This resource has been marked obsolete by the author(s)').
842: '</font></p>';
843: }
844: #
845: my %lt=&fieldnames();
846: my $table='';
847: my $title = $content{'title'};
848: if (! defined($title)) {
849: $title = 'Untitled Resource';
850: }
851: my @fields;
852: if ($uploaded) {
853: @fields = ('title','author','subject','keywords','notes','abstract',
854: 'lowestgradelevel','highestgradelevel','standards','mime',
855: 'owner');
856: } else {
857: @fields = ('title',
858: 'author',
859: 'subject',
860: 'keywords',
861: 'notes',
862: 'abstract',
863: 'lowestgradelevel',
864: 'highestgradelevel',
865: 'standards',
866: 'mime',
867: 'language',
868: 'creationdate',
869: 'lastrevisiondate',
870: 'owner',
871: 'copyright',
872: 'customdistributionfile',
873: 'sourceavail',
874: 'sourcerights',
875: 'obsolete',
876: 'obsoletereplacement');
877: }
878: foreach my $field (@fields) {
879: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$field}.
880: '</td><td bgcolor="#CCCCCC">'.
881: &prettyprint($field,$content{$field}).'</td></tr>';
882: delete($content{$field});
883: }
884: #
885: $r->print(<<ENDHEAD);
886: <h2>$title</h2>
887: <p>
888: $disuri<br />
889: $obsoletewarning
890: $versiondisplay
891: </p>
892: <table cellspacing="2" border="0">
893: $table
894: </table>
895: ENDHEAD
896: if (!$uploaded && $env{'user.adv'}) {
897: &print_dynamic_metadata($r,$uri,\%content);
898: }
899: return;
900: }
901:
902: sub print_dynamic_metadata {
903: my ($r,$uri,$content) = @_;
904: #
905: my %content = %$content;
906: my %lt=&fieldnames();
907: #
908: my $description = 'Dynamic Metadata (updated periodically)';
909: $r->print('<h3>'.&mt($description).'</h3>'.
910: &mt('Processing'));
911: $r->rflush();
912: my %items=&fieldnames();
913: my %dynmeta=&dynamicmeta($uri);
914: #
915: # General Access and Usage Statistics
916: if (exists($dynmeta{'count'}) ||
917: exists($dynmeta{'sequsage'}) ||
918: exists($dynmeta{'comefrom'}) ||
919: exists($dynmeta{'goto'}) ||
920: exists($dynmeta{'course'})) {
921: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
922: '<table cellspacing="2" border="0">');
923: foreach ('count',
924: 'sequsage','sequsage_list',
925: 'comefrom','comefrom_list',
926: 'goto','goto_list',
927: 'course','course_list') {
928: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
929: '<td bgcolor="#CCCCCC">'.
930: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
931: }
932: $r->print('</table>');
933: } else {
934: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
935: }
936: #
937: # Assessment statistics
938: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
939: if (exists($dynmeta{'stdno'}) ||
940: exists($dynmeta{'avetries'}) ||
941: exists($dynmeta{'difficulty'}) ||
942: exists($dynmeta{'disc'})) {
943: # This is an assessment, print assessment data
944: $r->print('<h4>'.
945: &mt('Overall Assessment Statistical Data').
946: '</h4>'.
947: '<table cellspacing="2" border="0">');
948: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
949: '<td bgcolor="#CCCCCC">'.
950: &prettyprint('stdno',$dynmeta{'stdno'}).
951: '</td>'."</tr>\n");
952: foreach ('avetries','difficulty','disc') {
953: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
954: '<td bgcolor="#CCCCCC">'.
955: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
956: '</td>'."</tr>\n");
957: }
958: $r->print('</table>');
959: }
960: if (exists($dynmeta{'stats'})) {
961: #
962: # New assessment statistics
963: $r->print('<h4>'.
964: &mt('Detailed Assessment Statistical Data').
965: '</h4>');
966: my $table = '<table cellspacing="2" border="0">'.
967: '<tr>'.
968: '<th>Course</th>'.
969: '<th>Section(s)</th>'.
970: '<th>Num Students</th>'.
971: '<th>Mean Tries</th>'.
972: '<th>Degree of Difficulty</th>'.
973: '<th>Degree of Discrimination</th>'.
974: '<th>Time of computation</th>'.
975: '</tr>'.$/;
976: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
977: my $data = $dynmeta{'stats'}->{$identifier};
978: my $course = $data->{'course'};
979: my %courseinfo =
980: &Apache::lonnet::coursedescription($course,
981: {'one_time' => 1});
982: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
983: &Apache::lonnet::logthis('lookup for '.$course.' failed');
984: next;
985: }
986: $table .= '<tr>';
987: $table .=
988: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
989: $table .=
990: '<td align="right">'.$data->{'sections'}.'</td>';
991: $table .=
992: '<td align="right">'.$data->{'stdno'}.'</td>';
993: foreach ('avetries','difficulty','disc') {
994: $table .= '<td align="right">';
995: if (exists($data->{$_})) {
996: $table .= sprintf('%.2f',$data->{$_}).' ';
997: } else {
998: $table .= '';
999: }
1000: $table .= '</td>';
1001: }
1002: $table .=
1003: '<td><nobr>'.
1004: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
1005: '</nobr></td>';
1006: $table .=
1007: '</tr>'.$/;
1008: }
1009: $table .= '</table>'.$/;
1010: $r->print($table);
1011: } else {
1012: $r->print('No new dynamic data found.');
1013: }
1014: } else {
1015: $r->print('<h4>'.
1016: &mt('No Assessment Statistical Data is available for this resource').
1017: '</h4>');
1018: }
1019:
1020: #
1021: #
1022: if (exists($dynmeta{'clear'}) ||
1023: exists($dynmeta{'depth'}) ||
1024: exists($dynmeta{'helpful'}) ||
1025: exists($dynmeta{'correct'}) ||
1026: exists($dynmeta{'technical'})){
1027: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
1028: '<table cellspacing="2" border="0">');
1029: foreach ('clear','depth','helpful','correct','technical') {
1030: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
1031: '<td bgcolor="#CCCCCC">'.
1032: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
1033: }
1034: $r->print('</table>');
1035: } else {
1036: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1037: }
1038: $uri=~/^\/res\/(\w+)\/(\w+)\//;
1039: if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
1040: || ($env{'user.role.ca./'.$1.'/'.$2})) {
1041: if (exists($dynmeta{'comments'})) {
1042: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
1043: &mt('visible to author and co-authors only').
1044: ')</h4>'.
1045: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
1046: } else {
1047: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
1048: }
1049: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
1050: if (defined($bombs) && $bombs ne '') {
1051: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
1052: &mt('visible to author and co-authors only').')'.
1053: '</h4>'.$bombs);
1054: } else {
1055: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
1056: }
1057: }
1058: #
1059: # All other stuff
1060: $r->print('<h3>'.
1061: &mt('Additional Metadata (non-standard, parameters, exports)').
1062: '</h3><table border="0" cellspacing="1">');
1063: foreach (sort(keys(%content))) {
1064: my $name=$_;
1065: if ($name!~/\.display$/) {
1066: my $display=&Apache::lonnet::metadata($uri,
1067: $name.'.display');
1068: if (! $display) {
1069: $display=$name;
1070: };
1071: my $otherinfo='';
1072: foreach ('name','part','type','default') {
1073: if (defined(&Apache::lonnet::metadata($uri,
1074: $name.'.'.$_))) {
1075: $otherinfo.=' '.$_.'='.
1076: &Apache::lonnet::metadata($uri,
1077: $name.'.'.$_).'; ';
1078: }
1079: }
1080: $r->print('<tr><td bgcolor="#bbccbb"><font size="-1" color="#556655">'.$display.'</font></td><td bgcolor="#ccddcc"><font size="-1" color="#556655">'.$content{$name});
1081: if ($otherinfo) {
1082: $r->print(' ('.$otherinfo.')');
1083: }
1084: $r->print("</font></td></tr>\n");
1085: }
1086: }
1087: $r->print("</table>");
1088: return;
1089: }
1090:
1091:
1092:
1093: #####################################################
1094: #####################################################
1095: ### ###
1096: ### Editable metadata display ###
1097: ### ###
1098: #####################################################
1099: #####################################################
1100: sub present_editable_metadata {
1101: my ($r,$uri, $file_type) = @_;
1102: # Construction Space Call
1103: # Header
1104: my $disuri=$uri;
1105: my $fn=&Apache::lonnet::filelocation('',$uri);
1106: $disuri=~s{^/\~}{/priv/};
1107: $disuri=~s/\.meta$//;
1108: my $meta_uri = $disuri;
1109: my $path;
1110: if ($disuri =~ m|/portfolio/|) {
1111: ($disuri, $meta_uri, $path) = &portfolio_display_uri($disuri,1);
1112: }
1113: my $target=$uri;
1114: $target=~s{^/\~}{/res/$env{'request.role.domain'}/};
1115: $target=~s/\.meta$//;
1116: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
1117: if ($bombs) {
1118: my $showdel=1;
1119: if ($env{'form.delmsg'}) {
1120: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
1121: $bombs=&mt('Messages deleted.');
1122: $showdel=0;
1123: } else {
1124: $bombs=&mt('Error deleting messages');
1125: }
1126: }
1127: if ($env{'form.clearmsg'}) {
1128: my $cleardir=$target;
1129: $cleardir=~s/\/[^\/]+$/\//;
1130: if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
1131: $bombs=&mt('Messages cleared.');
1132: $showdel=0;
1133: } else {
1134: $bombs=&mt('Error clearing messages');
1135: }
1136: }
1137: my $del=&mt('Delete Messages for this Resource');
1138: my $clear=&mt('Clear all Messages in Subdirectory');
1139: my $goback=&mt('Back to Source File');
1140: $r->print(<<ENDBOMBS);
1141: <h1>$disuri</h1>
1142: <form method="post" name="defaultmeta">
1143: ENDBOMBS
1144: if ($showdel) {
1145: $r->print(<<ENDDEL);
1146: <input type="submit" name="delmsg" value="$del" />
1147: <input type="submit" name="clearmsg" value="$clear" />
1148: ENDDEL
1149: } else {
1150: $r->print('<a href="'.$disuri.'" />'.$goback.'</a>');
1151: }
1152: $r->print('<br />'.$bombs);
1153: } else {
1154: my $displayfile='Catalog Information for '.$disuri;
1155: if ($disuri=~/\/default$/) {
1156: my $dir=$disuri;
1157: $dir=~s/default$//;
1158: $displayfile=
1159: &mt('Default Cataloging Information for Directory').' '.
1160: $dir;
1161: }
1162: %Apache::lonpublisher::metadatafields=();
1163: %Apache::lonpublisher::metadatakeys=();
1164: my $result=&Apache::lonnet::getfile($fn);
1165: if ($result == -1){
1166: $r->print(&mt('Creating new file [_1]'),$meta_uri);
1167: } else {
1168: &Apache::lonpublisher::metaeval($result);
1169: }
1170: $r->print(<<ENDEDIT);
1171: <h1>$displayfile</h1>
1172: <form method="post" name="defaultmeta">
1173: ENDEDIT
1174: $r->print('<script language="JavaScript">'.
1175: &Apache::loncommon::browser_and_searcher_javascript().
1176: '</script>');
1177: my %lt=&fieldnames($file_type);
1178: my $output;
1179: my @fields;
1180: if ($file_type eq 'portfolio') {
1181: @fields = ('author','title','subject','keywords','abstract',
1182: 'notes','lowestgradelevel',
1183: 'highestgradelevel','standards');
1184: } else {
1185: @fields = ('author','title','subject','keywords','abstract','notes',
1186: 'copyright','customdistributionfile','language',
1187: 'standards',
1188: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1189: 'obsolete','obsoletereplacement');
1190: }
1191: if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
1192: (! $env{'form.new_courserestricted'})) {
1193: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1194: 'none';
1195: } elsif ($env{'form.new_courserestricted'}) {
1196: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1197: $env{'form.new_courserestricted'};
1198: }
1199: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
1200: $Apache::lonpublisher::metadatafields{'copyright'}=
1201: 'default';
1202: }
1203: if ($file_type eq 'portfolio') {
1204: if (! $Apache::lonpublisher::metadatafields{'mime'}) {
1205: ($Apache::lonpublisher::metadatafields{'mime'}) =
1206: ( $target=~/\.(\w+)$/ );
1207: }
1208: if (! $Apache::lonpublisher::metadatafields{'owner'}) {
1209: $Apache::lonpublisher::metadatafields{'owner'} =
1210: $env{'user.name'}.':'.$env{'user.domain'};
1211: }
1212:
1213: if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
1214: $r->print(&mt('Associated with course [_1]','<strong>'.$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.".description"}.
1215: '</strong>').'<br />');
1216: } else {
1217: $r->print("This resource is not associated with a course.<br />");
1218: }
1219: }
1220: foreach my $field_name (@fields) {
1221:
1222: if (defined($env{'form.new_'.$field_name})) {
1223: $Apache::lonpublisher::metadatafields{$field_name}=
1224: join(',',&Apache::loncommon::get_env_multiple('form.new_'.$field_name));
1225: }
1226: if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none'
1227: && exists($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'})) {
1228: # handle restrictions here
1229: if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
1230: ($field_name eq 'courserestricted')){
1231: $output.=("\n".'<p>'.$lt{$field_name}.': '.
1232: &prettyinput($field_name,
1233: $Apache::lonpublisher::metadatafields{$field_name},
1234: 'new_'.$field_name,'defaultmeta',
1235: undef,undef,undef,undef,
1236: $Apache::lonpublisher::metadatafields{'courserestricted'}).'</p>'."\n");
1237: }
1238: } else {
1239:
1240: $output.=('<p>'.$lt{$field_name}.': '.
1241: &prettyinput($field_name,
1242: $Apache::lonpublisher::metadatafields{$field_name},
1243: 'new_'.$field_name,'defaultmeta').'</p>');
1244:
1245: }
1246: }
1247: if ($env{'form.store'}) {
1248: my $mfh;
1249: my $formname='store';
1250: my $file_content;
1251: if (&Apache::loncommon::get_env_multiple('form.new_keywords')) {
1252: $Apache::lonpublisher::metadatafields{'keywords'} =
1253: join (',', &Apache::loncommon::get_env_multiple('form.new_keywords'));
1254: }
1255:
1256: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1257: next if ($_ =~ /\./);
1258: my $unikey=$_;
1259: $unikey=~/^([A-Za-z]+)/;
1260: my $tag=$1;
1261: $tag=~tr/A-Z/a-z/;
1262: $file_content.= "\n\<$tag";
1263: foreach (split(/\,/,
1264: $Apache::lonpublisher::metadatakeys{$unikey})
1265: ) {
1266: my $value=
1267: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
1268: $value=~s/\"/\'\'/g;
1269: $file_content.=' '.$_.'="'.$value.'"' ;
1270: # print $mfh ' '.$_.'="'.$value.'"';
1271: }
1272: $file_content.= '>'.
1273: &HTML::Entities::encode
1274: ($Apache::lonpublisher::metadatafields{$unikey},
1275: '<>&"').
1276: '</'.$tag.'>';
1277: }
1278: if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/portfolio/|) {
1279: my ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|);
1280: $r->print(&store_portfolio_metadata($formname,$file_content,$path,
1281: $new_fn));
1282: } elsif ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/groups/\w+/portfolio/|) {
1283: my ($path, $new_fn) = ($fn =~ m|/(groups/\w+/portfolio.*)/([^/]*)$|);
1284: $r->print(&store_portfolio_metadata($formname,$file_content,$path,$new_fn));
1285: } else {
1286: if (! ($mfh=Apache::File->new('>'.$fn))) {
1287: $r->print('<p><font color="red">'.
1288: &mt('Could not write metadata').', '.
1289: &mt('FAIL').'</font></p>');
1290: } else {
1291: print $mfh $file_content;
1292: $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
1293: ' '.&Apache::lonlocal::locallocaltime(time).
1294: '</font></p>');
1295: }
1296: }
1297: }
1298:
1299: $r->print($output.'<br /><input type="submit" name="store" value="'.
1300: &mt('Store Catalog Information').'">');
1301:
1302: if ($file_type eq 'portfolio') {
1303: my ($port_path,$group) = &get_port_path_and_group($uri);
1304: if ($group) {
1305: $r->print('<input type="hidden" name="group" value="'.$group.'" />');
1306: }
1307: $r->print('</form>
1308: <br /><br /><form method="POST" action="'.$port_path.'">'.
1309: '<input type="hidden" name="group" value="'.$group.'" />'.
1310: '<input type="hidden" name="currentpath" value="'.$path.'" />'.
1311: '<input type="submit" name="cancel" value="'.&mt('Discard Edits and Return to Portfolio').'">');
1312: }
1313: }
1314:
1315: $r->print('</form>');
1316:
1317: return;
1318: }
1319:
1320: sub store_portfolio_metadata {
1321: my ($formname,$content,$path,$new_fn) = @_;
1322: $env{'form.'.$formname}=$content."\n";
1323: $env{'form.'.$formname.'.filename'}=$new_fn;
1324: my $result =&Apache::lonnet::userfileupload($formname,'',$path);
1325: if ($result =~ /(error|notfound)/) {
1326: return '<p><font color="red">'.
1327: &mt('Could not write metadata').', '.
1328: &mt('FAIL').'</font></p>';
1329: } else {
1330: return '<p><font color="blue">'.&mt('Wrote Metadata').
1331: ' '.&Apache::lonlocal::locallocaltime(time).'</font></p>';
1332: }
1333: }
1334:
1335: 1;
1336: __END__
1337:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>