1: # The LearningOnline Network with CAPA
2: # Metadata display handler
3: #
4: # $Id: lonmeta.pm,v 1.160 2006/07/19 15:31:05 albertel 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 $result = &Apache::portfolio::make_anchor($port_path,$start,'/');
291:
292: my $fullpath = '/';
293: my (undef,@tree) = split('/',$path);
294: my $filename = pop(@tree);
295: foreach my $dir (@tree) {
296: $fullpath .= $dir.'/';
297: $result .= '/';
298: $result .= &Apache::portfolio::make_anchor($port_path,$dir,$fullpath);
299: }
300: $result .= "/$filename";
301: return $result;
302: }
303:
304: sub get_port_path_and_group {
305: my ($uri)=@_;
306:
307: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
308: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
309:
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: }
317: if ($env{'form.group'} ne $group) {
318: $env{'form.group'} = $group) {
319: }
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:
328: $uri =~ s|.*/(portfolio/.*)$|$1|;
329: my ($res_uri,$meta_uri) = ($uri,$uri);
330: if ($uri =~ /\.meta$/) {
331: $res_uri =~ s/\.meta//;
332: } else {
333: $meta_uri .= '.meta';
334: }
335:
336: my ($path) = ($res_uri =~ m|^portfolio(.*/)[^/]*$|);
337: if ($as_links) {
338: $res_uri = &portfolio_linked_path($res_uri,$group,$port_path);
339: $meta_uri = &portfolio_linked_path($meta_uri,$group,$port_path);
340: }
341: return ($res_uri,$meta_uri,$path);
342: }
343:
344: sub pre_select_course {
345: my ($r,$uri) = @_;
346: my $output;
347: my $fn=&Apache::lonnet::filelocation('',$uri);
348: my ($res_uri,$meta_uri,$path) = &portfolio_display_uri($uri);
349: %Apache::lonpublisher::metadatafields=();
350: %Apache::lonpublisher::metadatakeys=();
351: my $result=&Apache::lonnet::getfile($fn);
352: if ($result == -1){
353: $r->print(&mt('Creating new file [_1]'),$meta_uri);
354: } else {
355: &Apache::lonpublisher::metaeval($result);
356: }
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>');
359: $output = &select_course();
360: $r->print($output.'<br /><input type="submit" name="store" value="'.
361: &mt('Associate Resource With Selected Course').'">');
362: $r->print('</form>');
363:
364: my ($port_path,$group) = &get_port_path_and_group($uri);
365: $r->print('<br /><br /><form method="POST" action="'.$port_path.'">'.
366: '<input type="hidden" name="currentpath" value="'.$path.'" />'.
367: '<input type="hidden" name="group" value="'.$group.'" />'.
368: '<input type="submit" name="cancel" value="'.&mt('Cancel').'">'.
369: '</form>');
370:
371: return;
372: }
373: sub select_course {
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>'.$/;
383: my %courses;
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 = '';
399: }
400: $output .= '</select><br />';
401: return ($output);
402: }
403: # Pretty printing of metadata field
404:
405: sub prettyprint {
406: my ($type,$value,$target,$prefix,$form,$noformat)=@_;
407: # $target,$prefix,$form are optional and for filecrumbs only
408: if (! defined($value)) {
409: return ' ';
410: }
411: # Title
412: if ($type eq 'title') {
413: return '<font size="+1" face="arial">'.$value.'</font>';
414: }
415: # Dates
416: if (($type eq 'creationdate') ||
417: ($type eq 'lastrevisiondate')) {
418: return ($value?&Apache::lonlocal::locallocaltime(
419: &Apache::lonmysql::unsqltime($value)):
420: &mt('not available'));
421: }
422: # Language
423: if ($type eq 'language') {
424: return &Apache::loncommon::languagedescription($value);
425: }
426: # Copyright
427: if ($type eq 'copyright') {
428: return &Apache::loncommon::copyrightdescription($value);
429: }
430: # Copyright
431: if ($type eq 'sourceavail') {
432: return &Apache::loncommon::source_copyrightdescription($value);
433: }
434: # MIME
435: if ($type eq 'mime') {
436: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
437: &Apache::loncommon::filedescription($value);
438: }
439: # Person
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: }
447: # Gradelevel
448: if (($type eq 'lowestgradelevel') ||
449: ($type eq 'highestgradelevel')) {
450: return &Apache::loncommon::gradeleveldescription($value);
451: }
452: # Only for advance users below
453: if (! $env{'user.adv'}) {
454: return '<i>- '.&mt('not displayed').' -</i>';
455: }
456: # File
457: if (($type eq 'customdistributionfile') ||
458: ($type eq 'obsoletereplacement') ||
459: ($type eq 'goto_list') ||
460: ($type eq 'comefrom_list') ||
461: ($type eq 'sequsage_list') ||
462: ($type eq 'dependencies')) {
463: return '<font size="-1"><ul>'.join("\n",map {
464: my $url = &Apache::lonnet::clutter($_);
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: }
480: $_ = '<li>'.$title.' '.
481: &Apache::lonhtmlcommon::crumbs($url,$target,$prefix,$form,'-1',$noformat).
482: '</li>'
483: } split(/\s*\,\s*/,$value)).'</ul></font>';
484: }
485: # Evaluations
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: }
493: # Difficulty
494: if ($type eq 'difficulty' || $type eq 'disc') {
495: return &diffgraph($value);
496: }
497: # List of courses
498: if ($type=~/\_list/) {
499: my @Courses = split(/\s*\,\s*/,$value);
500: my $Str='<font size="-1"><ul>';
501: foreach my $course (@Courses) {
502: my %courseinfo =
503: &Apache::lonnet::coursedescription($course,
504: {'one_time' => 1});
505: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
506: next;
507: }
508: $Str .= '<li><a href="/public/'.$courseinfo{'domain'}.'/'.
509: $courseinfo{'num'}.'/syllabus" target="preview">'.
510: $courseinfo{'description'}.'</a></li>';
511: }
512: return $Str.'</ul></font>';
513: }
514: # No pretty print found
515: return $value;
516: }
517:
518: # Pretty input of metadata field
519: sub direct {
520: return shift;
521: }
522:
523: sub selectbox {
524: my ($name,$value,$functionref,@idlist)=@_;
525: if (! defined($functionref)) {
526: $functionref=\&direct;
527: }
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:
539: sub relatedfield {
540: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
541: if (! $relatedsearchflag) {
542: return '';
543: }
544: if (! defined($relatedsep)) {
545: $relatedsep=' ';
546: }
547: if (! $show) {
548: return $relatedsep.' ';
549: }
550: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
551: ($relatedvalue?' checked="1"':'').' />';
552: }
553:
554: sub prettyinput {
555: my ($type,$value,$fieldname,$formname,
556: $relatedsearchflag,$relatedsep,$relatedvalue,$size,$course_key)=@_;
557: if (! defined($size)) {
558: $size = 80;
559: }
560: my $output;
561: if (defined($course_key)
562: && exists($env{$course_key.'.metadata.'.$type.'.options'})) {
563: my $stu_add;
564: my $only_one;
565: my %meta_options;
566: my @cur_values_inst;
567: my $cur_values_stu;
568: my $values = $env{$course_key.'.metadata.'.$type.'.values'};
569: if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/stuadd/) {
570: $stu_add = 'true';
571: }
572: if ($env{$course_key.'.metadata.'.$type.'.options'} =~ m/onlyone/) {
573: $only_one = 'true';
574: }
575: # need to take instructor values out of list where instructor and student
576: # values may be mixed.
577: if ($values) {
578: foreach my $item (split(/,/,$values)) {
579: $item =~ s/^\s+//;
580: $meta_options{$item} = $item;
581: }
582: foreach my $item (split(/,/,$value)) {
583: $item =~ s/^\s+//;
584: if ($meta_options{$item}) {
585: push(@cur_values_inst,$item);
586: } else {
587: $cur_values_stu .= $item.',';
588: }
589: }
590: } else {
591: $cur_values_stu = $value;
592: }
593: if ($type eq 'courserestricted') {
594: return (&select_course());
595: # return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
596: }
597: if (($type eq 'keywords') || ($type eq 'subject')
598: || ($type eq 'author')||($type eq 'notes')
599: || ($type eq 'abstract')|| ($type eq 'title')|| ($type eq 'standards')) {
600: if ($values) {
601: if ($only_one) {
602: $output .= (&Apache::loncommon::select_form($cur_values_inst[0],'new_'.$type,%meta_options));
603: } else {
604: $output .= (&Apache::loncommon::multiple_select_form('new_'.$type,\@cur_values_inst,undef,\%meta_options));
605: }
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);
612: }
613: return ($output);
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: }
622: # Language
623: if ($type eq 'language') {
624: return &selectbox($fieldname,
625: $value,
626: \&Apache::loncommon::languagedescription,
627: (&Apache::loncommon::languageids)).
628: &relatedfield(0,$relatedsearchflag,$relatedsep);
629: }
630: # Copyright
631: if ($type eq 'copyright') {
632: return &selectbox($fieldname,
633: $value,
634: \&Apache::loncommon::copyrightdescription,
635: (&Apache::loncommon::copyrightids)).
636: &relatedfield(0,$relatedsearchflag,$relatedsep);
637: }
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: }
646: # Gradelevels
647: if (($type eq 'lowestgradelevel') ||
648: ($type eq 'highestgradelevel')) {
649: return &Apache::loncommon::select_level_form($value,$fieldname).
650: &relatedfield(0,$relatedsearchflag,$relatedsep);
651: }
652: # Obsolete
653: if ($type eq 'obsolete') {
654: return '<input type="checkbox" name="'.$fieldname.'"'.
655: ($value?' checked="1"':'').' />'.
656: &relatedfield(0,$relatedsearchflag,$relatedsep);
657: }
658: # Obsolete replacement file
659: if ($type eq 'obsoletereplacement') {
660: return '<input type="text" name="'.$fieldname.
661: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
662: "('".$formname."','".$fieldname."'".
663: ",'')\">".&mt('Select').'</a>'.
664: &relatedfield(0,$relatedsearchflag,$relatedsep);
665: }
666: # Customdistribution file
667: if ($type eq 'customdistributionfile') {
668: return '<input type="text" name="'.$fieldname.
669: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
670: "('".$formname."','".$fieldname."'".
671: ",'rights')\">".&mt('Select').'</a>'.
672: &relatedfield(0,$relatedsearchflag,$relatedsep);
673: }
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: }
682: if ($type eq 'courserestricted') {
683: return (&select_course());
684: #return ('<input type="hidden" name="new_courserestricted" value="'.$course_key.'" />');
685: }
686:
687: # Dates
688: if (($type eq 'creationdate') ||
689: ($type eq 'lastrevisiondate')) {
690: return
691: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
692: &relatedfield(0,$relatedsearchflag,$relatedsep);
693: }
694: # No pretty input found
695: $value=~s/^\s+//gs;
696: $value=~s/\s+$//gs;
697: $value=~s/\s+/ /gs;
698: $value=~s/\"/\"\;/gs;
699: return
700: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
701: 'value="'.$value.'" />'.
702: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
703: $relatedvalue);
704: }
705:
706: # Main Handler
707: sub handler {
708: my $r=shift;
709: #
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;
716: #
717: my ($resdomain,$resuser)=
718: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
719:
720: if ($uri=~m:/adm/bombs/(.*)$:) {
721: $r->print(&Apache::loncommon::start_page('Error Messages'));
722: # Looking for all bombs?
723: &report_bombs($r,$uri);
724: } elsif ($uri=~/\/portfolio\//) {
725: ($resdomain,$resuser)=
726: (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
727: $r->print(&Apache::loncommon::start_page('Edit Portfolio File Catalog Information',
728: undef,
729: {'domain' => $resdomain,}));
730: if ($env{'form.store'}) {
731: &present_editable_metadata($r,$uri,'portfolio');
732: } else {
733: &pre_select_course($r,$uri);
734: }
735: } elsif ($uri=~/^\/\~/) {
736: # Construction space
737: $r->print(&Apache::loncommon::start_page('Edit Catalog nformation',
738: undef,
739: {'domain' => $resdomain,}));
740: &present_editable_metadata($r,$uri);
741: } else {
742: $r->print(&Apache::loncommon::start_page('Catalog Information',
743: undef,
744: {'domain' => $resdomain,}));
745: &present_uneditable_metadata($r,$uri);
746: }
747: $r->print(&Apache::loncommon::end_page());
748: return OK;
749: }
750:
751: #####################################################
752: #####################################################
753: ### ###
754: ### Report Bombs ###
755: ### ###
756: #####################################################
757: #####################################################
758: sub report_bombs {
759: my ($r,$uri) = @_;
760: # Set document type
761: $uri =~ s:/adm/bombs/::;
762: $uri = &Apache::lonnet::declutter($uri);
763: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
764: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
765: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
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
775: my %brokenurls =
776: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
777: foreach (sort(keys(%brokenurls))) {
778: if ($_=~/^\Q$uri\E/) {
779: $r->print
780: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
781: &Apache::lonmsg::retrieve_author_res_msg($_).
782: '<hr />');
783: }
784: }
785: } else {
786: $r->print(&mt('Not authorized'));
787: }
788: return;
789: }
790:
791: #####################################################
792: #####################################################
793: ### ###
794: ### Uneditable Metadata Display ###
795: ### ###
796: #####################################################
797: #####################################################
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);
811: $disuri=~s/^\/adm\/wrapper//;
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: }
824: # crumbify displayed URL uri target prefix form size
825: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
826: $disuri =~ s:<br />::g;
827: # obsolete
828: my $obsolete=$content{'obsolete'};
829: my $obsoletewarning='';
830: if (($obsolete) && ($env{'user.adv'})) {
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='';
838: my $title = $content{'title'};
839: if (! defined($title)) {
840: $title = 'Untitled Resource';
841: }
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',
857: 'customdistributionfile',
858: 'sourceavail',
859: 'sourcerights',
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);
869: <h2>$title</h2>
870: <p>
871: $disuri<br />
872: $obsoletewarning
873: $versiondisplay
874: </p>
875: <table cellspacing="2" border="0">
876: $table
877: </table>
878: ENDHEAD
879: if ($env{'user.adv'}) {
880: &print_dynamic_metadata($r,$uri,\%content);
881: }
882: return;
883: }
884:
885: sub print_dynamic_metadata {
886: my ($r,$uri,$content) = @_;
887: #
888: my %content = %$content;
889: my %lt=&fieldnames();
890: #
891: my $description = 'Dynamic Metadata (updated periodically)';
892: $r->print('<h3>'.&mt($description).'</h3>'.
893: &mt('Processing'));
894: $r->rflush();
895: my %items=&fieldnames();
896: my %dynmeta=&dynamicmeta($uri);
897: #
898: # General Access and Usage Statistics
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>'.
905: '<table cellspacing="2" border="0">');
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>');
918: }
919: #
920: # Assessment statistics
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>'.
930: '<table cellspacing="2" border="0">');
931: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
932: '<td bgcolor="#CCCCCC">'.
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>');
949: my $table = '<table cellspacing="2" border="0">'.
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'};
962: my %courseinfo =
963: &Apache::lonnet::coursedescription($course,
964: {'one_time' => 1});
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.');
996: }
997: } else {
998: $r->print('<h4>'.
999: &mt('No Assessment Statistical Data is available for this resource').
1000: '</h4>');
1001: }
1002:
1003: #
1004: #
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>'.
1011: '<table cellspacing="2" border="0">');
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>');
1020: }
1021: $uri=~/^\/res\/(\w+)\/(\w+)\//;
1022: if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
1023: || ($env{'user.role.ca./'.$1.'/'.$2})) {
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: }
1040: }
1041: #
1042: # All other stuff
1043: $r->print('<h3>'.
1044: &mt('Additional Metadata (non-standard, parameters, exports)').
1045: '</h3><table border="0" cellspacing="1">');
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: }
1062: }
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});
1064: if ($otherinfo) {
1065: $r->print(' ('.$otherinfo.')');
1066: }
1067: $r->print("</font></td></tr>\n");
1068: }
1069: }
1070: $r->print("</table>");
1071: return;
1072: }
1073:
1074:
1075:
1076: #####################################################
1077: #####################################################
1078: ### ###
1079: ### Editable metadata display ###
1080: ### ###
1081: #####################################################
1082: #####################################################
1083: sub present_editable_metadata {
1084: my ($r,$uri, $file_type) = @_;
1085: # Construction Space Call
1086: # Header
1087: my $disuri=$uri;
1088: my $fn=&Apache::lonnet::filelocation('',$uri);
1089: $disuri=~s{^/\~}{/priv/};
1090: $disuri=~s/\.meta$//;
1091: my $meta_uri = $disuri;
1092: my $path;
1093: if ($disuri =~ m|/portfolio/|) {
1094: ($disuri, $meta_uri, $path) = &portfolio_display_uri($disuri,1);
1095: }
1096: my $target=$uri;
1097: $target=~s{^/\~}{/res/$env{'request.role.domain'}/};
1098: $target=~s/\.meta$//;
1099: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
1100: if ($bombs) {
1101: my $showdel=1;
1102: if ($env{'form.delmsg'}) {
1103: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
1104: $bombs=&mt('Messages deleted.');
1105: $showdel=0;
1106: } else {
1107: $bombs=&mt('Error deleting messages');
1108: }
1109: }
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.');
1115: $showdel=0;
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');
1122: my $goback=&mt('Back to Source File');
1123: $r->print(<<ENDBOMBS);
1124: <h1>$disuri</h1>
1125: <form method="post" name="defaultmeta">
1126: ENDBOMBS
1127: if ($showdel) {
1128: $r->print(<<ENDDEL);
1129: <input type="submit" name="delmsg" value="$del" />
1130: <input type="submit" name="clearmsg" value="$clear" />
1131: ENDDEL
1132: } else {
1133: $r->print('<a href="'.$disuri.'" />'.$goback.'</a>');
1134: }
1135: $r->print('<br />'.$bombs);
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=();
1147: my $result=&Apache::lonnet::getfile($fn);
1148: if ($result == -1){
1149: $r->print(&mt('Creating new file [_1]'),$meta_uri);
1150: } else {
1151: &Apache::lonpublisher::metaeval($result);
1152: }
1153: $r->print(<<ENDEDIT);
1154: <h1>$displayfile</h1>
1155: <form method="post" name="defaultmeta">
1156: ENDEDIT
1157: $r->print('<script language="JavaScript">'.
1158: &Apache::loncommon::browser_and_searcher_javascript().
1159: '</script>');
1160: my %lt=&fieldnames($file_type);
1161: my $output;
1162: my @fields;
1163: if ($file_type eq 'portfolio') {
1164: @fields = ('author','title','subject','keywords','abstract','notes','lowestgradelevel',
1165: 'highestgradelevel','standards');
1166: } else {
1167: @fields = ('author','title','subject','keywords','abstract','notes',
1168: 'copyright','customdistributionfile','language',
1169: 'standards',
1170: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1171: 'obsolete','obsoletereplacement');
1172: }
1173: if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
1174: (! $env{'form.new_courserestricted'})) {
1175: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1176: 'none';
1177: } elsif ($env{'form.new_courserestricted'}) {
1178: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1179: $env{'form.new_courserestricted'};
1180: }
1181: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
1182: $Apache::lonpublisher::metadatafields{'copyright'}=
1183: 'default';
1184: }
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: }
1193: foreach my $field_name (@fields) {
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));
1198: }
1199: if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none'
1200: && exists($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'})) {
1201: # handle restrictions here
1202: if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
1203: ($field_name eq 'courserestricted')){
1204: $output.=("\n".'<p>'.$lt{$field_name}.': '.
1205: &prettyinput($field_name,
1206: $Apache::lonpublisher::metadatafields{$field_name},
1207: 'new_'.$field_name,'defaultmeta',
1208: undef,undef,undef,undef,
1209: $Apache::lonpublisher::metadatafields{'courserestricted'}).'</p>'."\n");
1210: }
1211: } else {
1212:
1213: $output.=('<p>'.$lt{$field_name}.': '.
1214: &prettyinput($field_name,
1215: $Apache::lonpublisher::metadatafields{$field_name},
1216: 'new_'.$field_name,'defaultmeta').'</p>');
1217:
1218: }
1219: }
1220: if ($env{'form.store'}) {
1221: my $mfh;
1222: my $formname='store';
1223: my $file_content;
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: }
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.'>';
1250: }
1251: if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/portfolio/|) {
1252: my ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|);
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));
1258: } else {
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: }
1269: }
1270: }
1271:
1272: $r->print($output.'<br /><input type="submit" name="store" value="'.
1273: &mt('Store Catalog Information').'">');
1274:
1275: if ($file_type eq 'portfolio') {
1276: my ($port_path,$group) = &get_port_path_and_group($uri);
1277: if ($group) {
1278: $r->print('<input type="hidden" name="group" value="'.$group.'" />');
1279: }
1280: $r->print('</form>
1281: <br /><br /><form method="POST" action="'.$port_path.'">'.
1282: '<input type="hidden" name="group" value="'.$group.'" />'.
1283: '<input type="hidden" name="currentpath" value="'.$path.'" />'.
1284: '<input type="submit" name="cancel" value="'.&mt('Discard Edits and Return to Portfolio').'">');
1285: }
1286: }
1287:
1288: $r->print('</form>');
1289:
1290: return;
1291: }
1292:
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:
1308: 1;
1309: __END__
1310:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>