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