Annotation of loncom/interface/lonmeta.pm, revision 1.113
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.113 ! banghart 4: # $Id: lonmeta.pm,v 1.112 2005/10/14 16:34:17 banghart Exp $
1.8 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
1.1 www 14: #
1.8 albertel 15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
1.100 banghart 20: # You should have received a copy of the GNU General Public License
1.8 albertel 21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
1.44 www 27:
1.1 www 28:
29: package Apache::lonmeta;
30:
31: use strict;
1.63 matthew 32: use LONCAPA::lonmetadata();
1.1 www 33: use Apache::Constants qw(:common);
1.96 albertel 34: use Apache::lonnet;
1.10 www 35: use Apache::loncommon();
1.100 banghart 36: use Apache::lonhtmlcommon();
1.23 www 37: use Apache::lonmsg;
38: use Apache::lonpublisher;
1.35 www 39: use Apache::lonlocal;
1.43 www 40: use Apache::lonmysql;
1.49 www 41: use Apache::lonmsg;
1.1 www 42:
1.44 www 43:
1.80 matthew 44: ############################################################
45: ############################################################
46: ##
47: ## &get_dynamic_metadata_from_sql($url)
48: ##
49: ## Queries sql database for dynamic metdata
50: ## Returns a hash of hashes, with keys of urls which match $url
51: ## Returned fields are given below.
52: ##
53: ## Examples:
54: ##
55: ## %DynamicMetadata = &Apache::lonmeta::get_dynmaic_metadata_from_sql
56: ## ('/res/msu/korte/');
57: ##
58: ## $DynamicMetadata{'/res/msu/korte/example.problem'}->{$field}
59: ##
60: ############################################################
61: ############################################################
62: sub get_dynamic_metadata_from_sql {
63: my ($url) = shift();
64: my ($authordom,$author)=($url=~m:^/res/(\w+)/(\w+)/:);
65: if (! defined($authordom)) {
66: $authordom = shift();
67: }
68: if (! defined($author)) {
69: $author = shift();
70: }
71: if (! defined($authordom) || ! defined($author)) {
72: return ();
73: }
1.83 www 74: my @Fields = ('url','count','course',
1.80 matthew 75: 'goto','goto_list',
76: 'comefrom','comefrom_list',
77: 'sequsage','sequsage_list',
78: 'stdno','stdno_list',
1.83 www 79: 'dependencies',
1.80 matthew 80: 'avetries','avetries_list',
81: 'difficulty','difficulty_list',
82: 'disc','disc_list',
83: 'clear','technical','correct',
84: 'helpful','depth');
85: #
86: my $query = 'SELECT '.join(',',@Fields).
87: ' FROM metadata WHERE url LIKE "'.$url.'%"';
88: my $server = &Apache::lonnet::homeserver($author,$authordom);
89: my $reply = &Apache::lonnet::metadata_query($query,undef,undef,
90: ,[$server]);
91: return () if (! defined($reply) || ref($reply) ne 'HASH');
92: my $filename = $reply->{$server};
93: if (! defined($filename) || $filename =~ /^error/) {
94: return ();
95: }
96: my $max_time = time + 10; # wait 10 seconds for results at most
97: my %ReturnHash;
98: #
99: # Look for results
100: my $finished = 0;
101: while (! $finished && time < $max_time) {
102: my $datafile=$Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/'.$filename;
103: if (! -e "$datafile.end") { next; }
104: my $fh;
105: if (!($fh=Apache::File->new($datafile))) { next; }
106: while (my $result = <$fh>) {
107: chomp($result);
108: next if (! $result);
109: my @Data =
110: map {
111: &Apache::lonnet::unescape($_);
112: } split(',',$result);
113: my $url = $Data[0];
114: for (my $i=0;$i<=$#Fields;$i++) {
115: $ReturnHash{$url}->{$Fields[$i]}=$Data[$i];
116: }
117: }
118: $finished = 1;
119: }
120: #
121: return %ReturnHash;
122: }
123:
124:
1.64 matthew 125: # Fetch and evaluate dynamic metadata
1.9 www 126: sub dynamicmeta {
127: my $url=&Apache::lonnet::declutter(shift);
128: $url=~s/\.meta$//;
129: my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
1.19 www 130: my $regexp=$url;
1.9 www 131: $regexp=~s/(\W)/\\$1/g;
1.10 www 132: $regexp='___'.$regexp.'___';
1.16 albertel 133: my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
134: $aauthor,$regexp);
1.63 matthew 135: my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
136: my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
137: \%DynamicData);
1.40 matthew 138: #
1.46 www 139: # Deal with 'count' separately
1.63 matthew 140: $Data{'count'} = &access_count($url,$aauthor,$adomain);
1.67 matthew 141: #
142: # Debugging code I will probably need later
143: if (0) {
144: &Apache::lonnet::logthis('Dynamic Metadata');
145: while(my($k,$v)=each(%Data)){
146: &Apache::lonnet::logthis(' "'.$k.'"=>"'.$v.'"');
147: }
148: &Apache::lonnet::logthis('-------------------');
149: }
1.63 matthew 150: return %Data;
1.40 matthew 151: }
152:
153: sub access_count {
154: my ($src,$author,$adomain) = @_;
155: my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
156: $author,$src);
157: if (! exists($countdata{$src})) {
1.47 www 158: return &mt('Not Available');
1.40 matthew 159: } else {
160: return $countdata{$src};
161: }
1.25 www 162: }
163:
1.64 matthew 164: # Try to make an alt tag if there is none
1.25 www 165: sub alttag {
1.26 www 166: my ($base,$src)=@_;
167: my $fullpath=&Apache::lonnet::hreflocation($base,$src);
168: my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
1.64 matthew 169: &Apache::lonnet::metadata($fullpath,'subject').' '.
170: &Apache::lonnet::metadata($fullpath,'abstract');
1.26 www 171: $alttag=~s/\s+/ /gs;
172: $alttag=~s/\"//gs;
173: $alttag=~s/\'//gs;
174: $alttag=~s/\s+$//gs;
175: $alttag=~s/^\s+//gs;
1.64 matthew 176: if ($alttag) {
177: return $alttag;
178: } else {
179: return &mt('No information available');
180: }
1.9 www 181: }
1.1 www 182:
1.64 matthew 183: # Author display
1.29 www 184: sub authordisplay {
185: my ($aname,$adom)=@_;
1.64 matthew 186: return &Apache::loncommon::aboutmewrapper
187: (&Apache::loncommon::plainname($aname,$adom),
188: $aname,$adom,'preview').' <tt>['.$aname.'@'.$adom.']</tt>';
1.29 www 189: }
190:
1.64 matthew 191: # Pretty display
1.12 www 192: sub evalgraph {
193: my $value=shift;
1.65 matthew 194: if (! $value) {
195: return '';
196: }
1.12 www 197: my $val=int($value*10.+0.5)-10;
1.71 matthew 198: my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
1.12 www 199: if ($val>=20) {
1.71 matthew 200: $output.='<td width="20" bgcolor="#555555">  </td>';
1.12 www 201: } else {
1.71 matthew 202: $output.='<td width="'.($val).'" bgcolor="#555555"> </td>'.
203: '<td width="'.(20-$val).'" bgcolor="#FF3333"> </td>';
1.12 www 204: }
205: $output.='<td bgcolor="#FFFF33"> </td>';
206: if ($val>20) {
1.71 matthew 207: $output.='<td width="'.($val-20).'" bgcolor="#33FF33"> </td>'.
208: '<td width="'.(40-$val).'" bgcolor="#555555"> </td>';
1.12 www 209: } else {
1.71 matthew 210: $output.='<td width="20" bgcolor="#555555">  </td>';
1.12 www 211: }
1.71 matthew 212: $output.='<td> ('.sprintf("%5.2f",$value).') </td></tr></table>';
1.12 www 213: return $output;
214: }
215:
216: sub diffgraph {
217: my $value=shift;
1.65 matthew 218: if (! $value) {
219: return '';
220: }
1.12 www 221: my $val=int(40.0*$value+0.5);
1.13 www 222: my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
223: '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
1.71 matthew 224: my $output='<table border="0" cellpadding="0" cellspacing="0"><tr>';
1.12 www 225: for (my $i=0;$i<8;$i++) {
226: if ($val>$i*5) {
1.71 matthew 227: $output.='<td width="5" bgcolor="'.$colors[$i].'"> </td>';
1.12 www 228: } else {
1.71 matthew 229: $output.='<td width="5" bgcolor="#555555"> </td>';
1.12 www 230: }
231: }
1.71 matthew 232: $output.='<td> ('.sprintf("%3.2f",$value).') </td></tr></table>';
1.12 www 233: return $output;
234: }
235:
1.44 www 236:
1.64 matthew 237: # The field names
1.45 www 238: sub fieldnames {
1.90 banghart 239: my $file_type=shift;
1.113 ! banghart 240: my %fields;
! 241: if ($file_type eq 'portfolio') {
! 242: %fields =
! 243: (%fields,
! 244: 'title' => 'Title',
! 245: 'author' =>'Author(s)',
! 246: 'authorspace' => 'Author Space',
! 247: 'modifyinguser' => 'Last Modifying User',
! 248: 'subject' => 'Subject',
! 249: 'keywords' => 'Keyword(s)',
! 250: 'notes' => 'Notes',
! 251: 'abstract' => 'Abstract',
! 252: 'lowestgradelevel' => 'Lowest Grade Level',
! 253: 'highestgradelevel' => 'Highest Grade Level');
! 254: }
! 255: if ($file_type eq 'restrictedportfolio') {
! 256: %fields =
! 257: (%fields,
! 258: 'metadata.title' => 'Title',
1.112 banghart 259: 'metadata.author' =>'Author(s)',
260: 'metadata.authorspace' => 'Author Space',
261: 'metadata.modifyinguser' => 'Last Modifying User',
262: 'metadata.subject' => 'Subject',
263: 'metadata.keywords' => 'Keyword(s)',
264: 'metadata.notes' => 'Notes',
265: 'metadata.abstract' => 'Abstract',
266: 'metadata.lowestgradelevel' => 'Lowest Grade Level',
267: 'metadata.highestgradelevel' => 'Highest Grade Level');
1.113 ! banghart 268: }
1.93 matthew 269: if (! defined($file_type) || $file_type ne 'portfolio') {
270: %fields =
271: (%fields,
272: 'domain' => 'Domain',
1.64 matthew 273: 'standards' => 'Standards',
274: 'mime' => 'MIME Type',
275: 'language' => 'Language',
276: 'creationdate' => 'Creation Date',
277: 'lastrevisiondate' => 'Last Revision Date',
278: 'owner' => 'Publisher/Owner',
279: 'copyright' => 'Copyright/Distribution',
280: 'customdistributionfile' => 'Custom Distribution File',
1.84 banghart 281: 'sourceavail' => 'Source Available',
1.78 taceyjo1 282: 'sourcerights' => 'Source Custom Distribution File',
1.64 matthew 283: 'obsolete' => 'Obsolete',
284: 'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
285: 'count' => 'Network-wide number of accesses (hits)',
286: 'course' => 'Network-wide number of courses using resource',
287: 'course_list' => 'Network-wide courses using resource',
288: 'sequsage' => 'Number of resources using or importing resource',
289: 'sequsage_list' => 'Resources using or importing resource',
290: 'goto' => 'Number of resources that follow this resource in maps',
291: 'goto_list' => 'Resources that follow this resource in maps',
292: 'comefrom' => 'Number of resources that lead up to this resource in maps',
293: 'comefrom_list' => 'Resources that lead up to this resource in maps',
294: 'clear' => 'Material presented in clear way',
295: 'depth' => 'Material covered with sufficient depth',
296: 'helpful' => 'Material is helpful',
297: 'correct' => 'Material appears to be correct',
298: 'technical' => 'Resource is technically correct',
299: 'avetries' => 'Average number of tries till solved',
300: 'stdno' => 'Total number of students who have worked on this problem',
1.73 matthew 301: 'difficulty' => 'Degree of difficulty',
302: 'disc' => 'Degree of discrimination',
1.83 www 303: 'dependencies' => 'Resources used by this resource',
1.64 matthew 304: );
1.93 matthew 305: }
306: return &Apache::lonlocal::texthash(%fields);
1.45 www 307: }
1.46 www 308:
1.100 banghart 309: sub select_course {
310: my ($r)=@_;
1.113 ! banghart 311: my %courses;
1.111 banghart 312: foreach my $key (keys (%env)) {
1.113 ! banghart 313: if ($key =~ m/\.metadata\./) {
! 314: $key =~ m/^course\.(.+)(\.metadata.+$)/;
! 315: my $course = $1;
! 316: my $coursekey = 'course.'.$course.'.description';
! 317: my $value = $env{$coursekey};
! 318: $courses{$coursekey} = $value;
1.111 banghart 319: }
320: }
1.113 ! banghart 321: $r->print('<h3>Course Related Meta-Data</h3><br />');
1.100 banghart 322: $r->print('<form action="" method="post">');
1.111 banghart 323: $r->print('Select your test course<br />');
1.100 banghart 324: $r->print('<select name="metacourse" >');
1.103 banghart 325: my $meta_not_found = 1;
1.113 ! banghart 326: foreach my $key (keys (%courses)) {
! 327: if ($meta_not_found) {
! 328: undef($meta_not_found);
! 329: $r->print('<h3>Portfolio Meta-Data</h3><br />');
! 330: $r->print('<form action="" method="post">');
! 331: $r->print('Select your course<br />');
! 332: $r->print('<select name="metacourse" >');
! 333: }
! 334: $r->print('<option value="'.$key.'">');
! 335: $r->print($courses{$key});
! 336: $r->print('</option>');
1.100 banghart 337: }
1.103 banghart 338: unless ($meta_not_found) {
339: $r->print('</select><br />');
1.111 banghart 340: $r->print('<input type="submit" value="Assign Portfolio Metadata" />');
1.103 banghart 341: $r->print('</form>');
342: }
1.100 banghart 343: return 'ok';
344: }
1.64 matthew 345: # Pretty printing of metadata field
1.46 www 346:
347: sub prettyprint {
1.82 www 348: my ($type,$value,$target,$prefix,$form,$noformat)=@_;
349: # $target,$prefix,$form are optional and for filecrumbs only
1.65 matthew 350: if (! defined($value)) {
351: return ' ';
352: }
1.64 matthew 353: # Title
1.46 www 354: if ($type eq 'title') {
355: return '<font size="+1" face="arial">'.$value.'</font>';
356: }
1.64 matthew 357: # Dates
1.46 www 358: if (($type eq 'creationdate') ||
359: ($type eq 'lastrevisiondate')) {
1.55 www 360: return ($value?&Apache::lonlocal::locallocaltime(
361: &Apache::lonmysql::unsqltime($value)):
362: &mt('not available'));
1.46 www 363: }
1.64 matthew 364: # Language
1.46 www 365: if ($type eq 'language') {
366: return &Apache::loncommon::languagedescription($value);
367: }
1.64 matthew 368: # Copyright
1.46 www 369: if ($type eq 'copyright') {
370: return &Apache::loncommon::copyrightdescription($value);
371: }
1.78 taceyjo1 372: # Copyright
373: if ($type eq 'sourceavail') {
374: return &Apache::loncommon::source_copyrightdescription($value);
375: }
1.64 matthew 376: # MIME
1.46 www 377: if ($type eq 'mime') {
1.64 matthew 378: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
379: &Apache::loncommon::filedescription($value);
380: }
381: # Person
1.46 www 382: if (($type eq 'author') ||
383: ($type eq 'owner') ||
384: ($type eq 'modifyinguser') ||
385: ($type eq 'authorspace')) {
386: $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
387: return $value;
388: }
1.64 matthew 389: # Gradelevel
1.48 www 390: if (($type eq 'lowestgradelevel') ||
391: ($type eq 'highestgradelevel')) {
392: return &Apache::loncommon::gradeleveldescription($value);
393: }
1.64 matthew 394: # Only for advance users below
1.96 albertel 395: if (! $env{'user.adv'}) {
1.65 matthew 396: return '<i>- '.&mt('not displayed').' -</i>';
397: }
1.64 matthew 398: # File
1.46 www 399: if (($type eq 'customdistributionfile') ||
400: ($type eq 'obsoletereplacement') ||
401: ($type eq 'goto_list') ||
402: ($type eq 'comefrom_list') ||
1.82 www 403: ($type eq 'sequsage_list') ||
1.83 www 404: ($type eq 'dependencies')) {
1.82 www 405: return '<ul><font size="-1">'.join("\n",map {
1.70 matthew 406: my $url = &Apache::lonnet::clutter($_);
1.72 matthew 407: my $title = &Apache::lonnet::gettitle($url);
408: if ($title eq '') {
409: $title = 'Untitled';
410: if ($url =~ /\.sequence$/) {
411: $title .= ' Sequence';
412: } elsif ($url =~ /\.page$/) {
413: $title .= ' Page';
414: } elsif ($url =~ /\.problem$/) {
415: $title .= ' Problem';
416: } elsif ($url =~ /\.html$/) {
417: $title .= ' HTML document';
418: } elsif ($url =~ m:/syllabus$:) {
419: $title .= ' Syllabus';
420: }
421: }
1.82 www 422: $_ = '<li>'.$title.' '.
423: &Apache::lonhtmlcommon::crumbs($url,$target,$prefix,$form,'-1',$noformat).
424: '</li>'
425: } split(/\s*\,\s*/,$value)).'</ul></font>';
1.46 www 426: }
1.64 matthew 427: # Evaluations
1.46 www 428: if (($type eq 'clear') ||
429: ($type eq 'depth') ||
430: ($type eq 'helpful') ||
431: ($type eq 'correct') ||
432: ($type eq 'technical')) {
433: return &evalgraph($value);
434: }
1.64 matthew 435: # Difficulty
1.73 matthew 436: if ($type eq 'difficulty' || $type eq 'disc') {
1.46 www 437: return &diffgraph($value);
438: }
1.64 matthew 439: # List of courses
1.46 www 440: if ($type=~/\_list/) {
1.72 matthew 441: my @Courses = split(/\s*\,\s*/,$value);
442: my $Str;
443: foreach my $course (@Courses) {
444: my %courseinfo = &Apache::lonnet::coursedescription($course);
445: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
446: next;
447: }
448: if ($Str ne '') { $Str .= '<br />'; }
449: $Str .= '<a href="/public/'.$courseinfo{'domain'}.'/'.
450: $courseinfo{'num'}.'/syllabus" target="preview">'.
451: $courseinfo{'description'}.'</a>';
452: }
453: return $Str;
1.46 www 454: }
1.64 matthew 455: # No pretty print found
1.46 www 456: return $value;
457: }
458:
1.64 matthew 459: # Pretty input of metadata field
1.54 www 460: sub direct {
461: return shift;
462: }
463:
1.48 www 464: sub selectbox {
465: my ($name,$value,$functionref,@idlist)=@_;
1.65 matthew 466: if (! defined($functionref)) {
467: $functionref=\&direct;
468: }
1.48 www 469: my $selout='<select name="'.$name.'">';
470: foreach (@idlist) {
471: $selout.='<option value=\''.$_.'\'';
472: if ($_ eq $value) {
473: $selout.=' selected>'.&{$functionref}($_).'</option>';
474: }
475: else {$selout.='>'.&{$functionref}($_).'</option>';}
476: }
477: return $selout.'</select>';
478: }
479:
1.54 www 480: sub relatedfield {
481: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
1.65 matthew 482: if (! $relatedsearchflag) {
483: return '';
484: }
485: if (! defined($relatedsep)) {
486: $relatedsep=' ';
487: }
488: if (! $show) {
489: return $relatedsep.' ';
490: }
1.54 www 491: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
492: ($relatedvalue?' checked="1"':'').' />';
493: }
1.48 www 494:
1.46 www 495: sub prettyinput {
1.54 www 496: my ($type,$value,$fieldname,$formname,
1.74 matthew 497: $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;
1.75 matthew 498: if (! defined($size)) {
499: $size = 80;
500: }
1.64 matthew 501: # Language
1.48 www 502: if ($type eq 'language') {
503: return &selectbox($fieldname,
504: $value,
505: \&Apache::loncommon::languagedescription,
1.54 www 506: (&Apache::loncommon::languageids)).
1.64 matthew 507: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 508: }
1.64 matthew 509: # Copyright
1.48 www 510: if ($type eq 'copyright') {
511: return &selectbox($fieldname,
512: $value,
513: \&Apache::loncommon::copyrightdescription,
1.54 www 514: (&Apache::loncommon::copyrightids)).
1.64 matthew 515: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 516: }
1.78 taceyjo1 517: # Source Copyright
518: if ($type eq 'sourceavail') {
519: return &selectbox($fieldname,
520: $value,
521: \&Apache::loncommon::source_copyrightdescription,
522: (&Apache::loncommon::source_copyrightids)).
523: &relatedfield(0,$relatedsearchflag,$relatedsep);
524: }
1.64 matthew 525: # Gradelevels
1.48 www 526: if (($type eq 'lowestgradelevel') ||
527: ($type eq 'highestgradelevel')) {
1.54 www 528: return &Apache::loncommon::select_level_form($value,$fieldname).
1.64 matthew 529: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 530: }
1.64 matthew 531: # Obsolete
1.48 www 532: if ($type eq 'obsolete') {
533: return '<input type="checkbox" name="'.$fieldname.'"'.
1.54 www 534: ($value?' checked="1"':'').' />'.
1.64 matthew 535: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 536: }
1.64 matthew 537: # Obsolete replacement file
1.48 www 538: if ($type eq 'obsoletereplacement') {
539: return '<input type="text" name="'.$fieldname.
540: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
541: "('".$formname."','".$fieldname."'".
1.54 www 542: ",'')\">".&mt('Select').'</a>'.
1.64 matthew 543: &relatedfield(0,$relatedsearchflag,$relatedsep);
544: }
545: # Customdistribution file
1.48 www 546: if ($type eq 'customdistributionfile') {
547: return '<input type="text" name="'.$fieldname.
548: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
549: "('".$formname."','".$fieldname."'".
1.54 www 550: ",'rights')\">".&mt('Select').'</a>'.
1.64 matthew 551: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 552: }
1.78 taceyjo1 553: # Source Customdistribution file
554: if ($type eq 'sourcerights') {
555: return '<input type="text" name="'.$fieldname.
556: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
557: "('".$formname."','".$fieldname."'".
558: ",'rights')\">".&mt('Select').'</a>'.
559: &relatedfield(0,$relatedsearchflag,$relatedsep);
560: }
1.64 matthew 561: # Dates
1.48 www 562: if (($type eq 'creationdate') ||
563: ($type eq 'lastrevisiondate')) {
1.64 matthew 564: return
565: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
566: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 567: }
1.64 matthew 568: # No pretty input found
1.48 www 569: $value=~s/^\s+//gs;
570: $value=~s/\s+$//gs;
571: $value=~s/\s+/ /gs;
1.77 matthew 572: $value=~s/\"/\"\;/gs;
1.54 www 573: return
1.74 matthew 574: '<input type="text" name="'.$fieldname.'" size="'.$size.'" '.
1.64 matthew 575: 'value="'.$value.'" />'.
576: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
577: $relatedvalue);
1.46 www 578: }
579:
1.64 matthew 580: # Main Handler
1.1 www 581: sub handler {
1.64 matthew 582: my $r=shift;
583: #
1.67 matthew 584: my $uri=$r->uri;
585: #
586: # Set document type
587: &Apache::loncommon::content_type($r,'text/html');
588: $r->send_http_header;
589: return OK if $r->header_only;
1.64 matthew 590: #
1.76 matthew 591: my ($resdomain,$resuser)=
592: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
1.92 albertel 593: my $html=&Apache::lonxml::xmlbegin();
594: $r->print($html.'<head><title>'.
1.67 matthew 595: 'Catalog Information'.
596: '</title></head>');
1.66 matthew 597: if ($uri=~m:/adm/bombs/(.*)$:) {
1.67 matthew 598: $r->print(&Apache::loncommon::bodytag('Error Messages'));
1.66 matthew 599: # Looking for all bombs?
600: &report_bombs($r,$uri);
1.89 banghart 601: } elsif ($uri=~/\/portfolio\//) {
1.109 albertel 602: ($resdomain,$resuser)=
603: (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
1.89 banghart 604: $r->print(&Apache::loncommon::bodytag
605: ('Edit Portfolio File Information','','','',$resdomain));
1.106 banghart 606: &present_editable_metadata($r,$uri,'portfolio');
607: &select_course($r);
1.66 matthew 608: } elsif ($uri=~/^\/\~/) {
609: # Construction space
1.67 matthew 610: $r->print(&Apache::loncommon::bodytag
611: ('Edit Catalog Information','','','',$resdomain));
1.66 matthew 612: &present_editable_metadata($r,$uri);
613: } else {
1.67 matthew 614: $r->print(&Apache::loncommon::bodytag
1.85 albertel 615: ('Catalog Information','','','',$resdomain));
1.66 matthew 616: &present_uneditable_metadata($r,$uri);
617: }
1.67 matthew 618: $r->print('</body></html>');
1.66 matthew 619: return OK;
620: }
621:
1.67 matthew 622: #####################################################
623: #####################################################
624: ### ###
625: ### Report Bombs ###
626: ### ###
627: #####################################################
628: #####################################################
1.66 matthew 629: sub report_bombs {
630: my ($r,$uri) = @_;
631: # Set document type
1.67 matthew 632: $uri =~ s:/adm/bombs/::;
633: $uri = &Apache::lonnet::declutter($uri);
1.66 matthew 634: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
635: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
636: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
1.98 www 637: if ($env{'form.clearbombs'}) {
638: &Apache::lonmsg::clear_author_res_msg($uri);
639: }
640: my $clear=&mt('Clear all Messages in Subdirectory');
641: $r->print(<<ENDCLEAR);
642: <form method="post">
643: <input type="submit" name="clearbombs" value="$clear" />
644: </form>
645: ENDCLEAR
1.67 matthew 646: my %brokenurls =
647: &Apache::lonmsg::all_url_author_res_msg($author,$domain);
648: foreach (sort(keys(%brokenurls))) {
1.66 matthew 649: if ($_=~/^\Q$uri\E/) {
1.70 matthew 650: $r->print
651: ('<a href="'.&Apache::lonnet::clutter($_).'">'.$_.'</a>'.
652: &Apache::lonmsg::retrieve_author_res_msg($_).
653: '<hr />');
1.64 matthew 654: }
655: }
1.66 matthew 656: } else {
657: $r->print(&mt('Not authorized'));
658: }
659: return;
660: }
661:
1.67 matthew 662: #####################################################
663: #####################################################
664: ### ###
665: ### Uneditable Metadata Display ###
666: ### ###
667: #####################################################
668: #####################################################
1.66 matthew 669: sub present_uneditable_metadata {
670: my ($r,$uri) = @_;
671: #
672: my %content=();
673: # Read file
674: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
675: $content{$_}=&Apache::lonnet::metadata($uri,$_);
676: }
677: # Render Output
678: # displayed url
679: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
680: $uri=~s/\.meta$//;
681: my $disuri=&Apache::lonnet::clutter($uri);
682: # version
683: my $currentversion=&Apache::lonnet::getversion($disuri);
684: my $versiondisplay='';
685: if ($thisversion) {
686: $versiondisplay=&mt('Version').': '.$thisversion.
687: ' ('.&mt('most recent version').': '.
688: ($currentversion>0 ?
689: $currentversion :
690: &mt('information not available')).')';
691: } else {
692: $versiondisplay='Version: '.$currentversion;
693: }
1.72 matthew 694: # crumbify displayed URL uri target prefix form size
695: $disuri=&Apache::lonhtmlcommon::crumbs($disuri,undef, undef, undef,'+1');
696: $disuri =~ s:<br />::g;
1.66 matthew 697: # obsolete
698: my $obsolete=$content{'obsolete'};
699: my $obsoletewarning='';
1.96 albertel 700: if (($obsolete) && ($env{'user.adv'})) {
1.66 matthew 701: $obsoletewarning='<p><font color="red">'.
702: &mt('This resource has been marked obsolete by the author(s)').
703: '</font></p>';
704: }
705: #
706: my %lt=&fieldnames();
707: my $table='';
1.72 matthew 708: my $title = $content{'title'};
709: if (! defined($title)) {
710: $title = 'Untitled Resource';
711: }
1.66 matthew 712: foreach ('title',
713: 'author',
714: 'subject',
715: 'keywords',
716: 'notes',
717: 'abstract',
718: 'lowestgradelevel',
719: 'highestgradelevel',
720: 'standards',
721: 'mime',
722: 'language',
723: 'creationdate',
724: 'lastrevisiondate',
725: 'owner',
726: 'copyright',
1.78 taceyjo1 727: 'customdistributionfile',
728: 'sourceavail',
729: 'sourcerights',
1.66 matthew 730: 'obsolete',
731: 'obsoletereplacement') {
732: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
733: '</td><td bgcolor="#CCCCCC">'.
734: &prettyprint($_,$content{$_}).'</td></tr>';
735: delete $content{$_};
736: }
737: #
738: $r->print(<<ENDHEAD);
1.72 matthew 739: <h2>$title</h2>
740: <p>
741: $disuri<br />
1.36 www 742: $obsoletewarning
1.72 matthew 743: $versiondisplay
744: </p>
1.88 banghart 745: <table cellspacing="2" border="0">
1.45 www 746: $table
1.11 www 747: </table>
1.1 www 748: ENDHEAD
1.96 albertel 749: if ($env{'user.adv'}) {
1.68 matthew 750: &print_dynamic_metadata($r,$uri,\%content);
1.67 matthew 751: }
752: return;
753: }
754:
755: sub print_dynamic_metadata {
1.68 matthew 756: my ($r,$uri,$content) = @_;
757: #
1.69 matthew 758: my %content = %$content;
1.68 matthew 759: my %lt=&fieldnames();
1.67 matthew 760: #
761: my $description = 'Dynamic Metadata (updated periodically)';
762: $r->print('<h3>'.&mt($description).'</h3>'.
1.70 matthew 763: &mt('Processing'));
1.67 matthew 764: $r->rflush();
765: my %items=&fieldnames();
766: my %dynmeta=&dynamicmeta($uri);
767: #
768: # General Access and Usage Statistics
1.70 matthew 769: if (exists($dynmeta{'count'}) ||
770: exists($dynmeta{'sequsage'}) ||
771: exists($dynmeta{'comefrom'}) ||
772: exists($dynmeta{'goto'}) ||
773: exists($dynmeta{'course'})) {
774: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
1.88 banghart 775: '<table cellspacing="2" border="0">');
1.70 matthew 776: foreach ('count',
777: 'sequsage','sequsage_list',
778: 'comefrom','comefrom_list',
779: 'goto','goto_list',
780: 'course','course_list') {
781: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
782: '<td bgcolor="#CCCCCC">'.
783: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
784: }
785: $r->print('</table>');
786: } else {
787: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
1.67 matthew 788: }
1.69 matthew 789: #
790: # Assessment statistics
1.73 matthew 791: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
792: if (exists($dynmeta{'stdno'}) ||
793: exists($dynmeta{'avetries'}) ||
794: exists($dynmeta{'difficulty'}) ||
795: exists($dynmeta{'disc'})) {
796: # This is an assessment, print assessment data
797: $r->print('<h4>'.
798: &mt('Overall Assessment Statistical Data').
799: '</h4>'.
1.88 banghart 800: '<table cellspacing="2" border="0">');
1.73 matthew 801: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
1.66 matthew 802: '<td bgcolor="#CCCCCC">'.
1.73 matthew 803: &prettyprint('stdno',$dynmeta{'stdno'}).
804: '</td>'."</tr>\n");
805: foreach ('avetries','difficulty','disc') {
806: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
807: '<td bgcolor="#CCCCCC">'.
808: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
809: '</td>'."</tr>\n");
810: }
811: $r->print('</table>');
812: }
813: if (exists($dynmeta{'stats'})) {
814: #
815: # New assessment statistics
816: $r->print('<h4>'.
817: &mt('Detailed Assessment Statistical Data').
818: '</h4>');
1.88 banghart 819: my $table = '<table cellspacing="2" border="0">'.
1.73 matthew 820: '<tr>'.
821: '<th>Course</th>'.
822: '<th>Section(s)</th>'.
823: '<th>Num Students</th>'.
824: '<th>Mean Tries</th>'.
825: '<th>Degree of Difficulty</th>'.
826: '<th>Degree of Discrimination</th>'.
827: '<th>Time of computation</th>'.
828: '</tr>'.$/;
829: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
830: my $data = $dynmeta{'stats'}->{$identifier};
831: my $course = $data->{'course'};
832: my %courseinfo = &Apache::lonnet::coursedescription($course);
833: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
834: &Apache::lonnet::logthis('lookup for '.$course.' failed');
835: next;
836: }
837: $table .= '<tr>';
838: $table .=
839: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
840: $table .=
841: '<td align="right">'.$data->{'sections'}.'</td>';
842: $table .=
843: '<td align="right">'.$data->{'stdno'}.'</td>';
844: foreach ('avetries','difficulty','disc') {
845: $table .= '<td align="right">';
846: if (exists($data->{$_})) {
847: $table .= sprintf('%.2f',$data->{$_}).' ';
848: } else {
849: $table .= '';
850: }
851: $table .= '</td>';
852: }
853: $table .=
854: '<td><nobr>'.
855: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
856: '</nobr></td>';
857: $table .=
858: '</tr>'.$/;
859: }
860: $table .= '</table>'.$/;
861: $r->print($table);
862: } else {
863: $r->print('No new dynamic data found.');
1.66 matthew 864: }
1.70 matthew 865: } else {
1.73 matthew 866: $r->print('<h4>'.
867: &mt('No Assessment Statistical Data is available for this resource').
868: '</h4>');
1.67 matthew 869: }
1.73 matthew 870:
871: #
872: #
1.70 matthew 873: if (exists($dynmeta{'clear'}) ||
874: exists($dynmeta{'depth'}) ||
875: exists($dynmeta{'helpful'}) ||
876: exists($dynmeta{'correct'}) ||
877: exists($dynmeta{'technical'})){
878: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
1.88 banghart 879: '<table cellspacing="2" border="0">');
1.70 matthew 880: foreach ('clear','depth','helpful','correct','technical') {
881: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
882: '<td bgcolor="#CCCCCC">'.
883: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
884: }
885: $r->print('</table>');
886: } else {
887: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1.67 matthew 888: }
889: $uri=~/^\/res\/(\w+)\/(\w+)\//;
1.96 albertel 890: if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
891: || ($env{'user.role.ca./'.$1.'/'.$2})) {
1.70 matthew 892: if (exists($dynmeta{'comments'})) {
893: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
894: &mt('visible to author and co-authors only').
895: ')</h4>'.
896: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
897: } else {
898: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
899: }
900: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
901: if (defined($bombs) && $bombs ne '') {
902: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
903: &mt('visible to author and co-authors only').')'.
904: '</h4>'.$bombs);
905: } else {
906: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
907: }
1.67 matthew 908: }
1.69 matthew 909: #
1.67 matthew 910: # All other stuff
911: $r->print('<h3>'.
912: &mt('Additional Metadata (non-standard, parameters, exports)').
1.81 www 913: '</h3><table border="0" cellspacing="1">');
1.67 matthew 914: foreach (sort(keys(%content))) {
915: my $name=$_;
916: if ($name!~/\.display$/) {
917: my $display=&Apache::lonnet::metadata($uri,
918: $name.'.display');
919: if (! $display) {
920: $display=$name;
921: };
922: my $otherinfo='';
923: foreach ('name','part','type','default') {
924: if (defined(&Apache::lonnet::metadata($uri,
925: $name.'.'.$_))) {
926: $otherinfo.=' '.$_.'='.
927: &Apache::lonnet::metadata($uri,
928: $name.'.'.$_).'; ';
929: }
1.64 matthew 930: }
1.81 www 931: $r->print('<tr><td bgcolor="#bbccbb"><font size="-1" color="#556655">'.$display.'</font></td><td bgcolor="#ccddcc"><font size="-1" color="#556655">'.$content{$name});
1.67 matthew 932: if ($otherinfo) {
933: $r->print(' ('.$otherinfo.')');
1.64 matthew 934: }
1.81 www 935: $r->print("</font></td></tr>\n");
1.64 matthew 936: }
1.66 matthew 937: }
1.81 www 938: $r->print("</table>");
1.67 matthew 939: return;
1.66 matthew 940: }
1.105 banghart 941:
1.102 banghart 942:
943:
1.67 matthew 944: #####################################################
945: #####################################################
946: ### ###
947: ### Editable metadata display ###
948: ### ###
949: #####################################################
950: #####################################################
1.66 matthew 951: sub present_editable_metadata {
1.90 banghart 952: my ($r,$uri, $file_type) = @_;
1.66 matthew 953: # Construction Space Call
954: # Header
955: my $disuri=$uri;
956: my $fn=&Apache::lonnet::filelocation('',$uri);
957: $disuri=~s/^\/\~/\/priv\//;
958: $disuri=~s/\.meta$//;
1.110 albertel 959: $disuri=~s|^/editupload||;
1.66 matthew 960: my $target=$uri;
1.96 albertel 961: $target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;
1.66 matthew 962: $target=~s/\.meta$//;
963: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
964: if ($bombs) {
1.99 www 965: my $showdel=1;
1.96 albertel 966: if ($env{'form.delmsg'}) {
1.66 matthew 967: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
968: $bombs=&mt('Messages deleted.');
1.99 www 969: $showdel=0;
1.66 matthew 970: } else {
971: $bombs=&mt('Error deleting messages');
1.64 matthew 972: }
1.66 matthew 973: }
1.98 www 974: if ($env{'form.clearmsg'}) {
975: my $cleardir=$target;
976: $cleardir=~s/\/[^\/]+$/\//;
977: if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
978: $bombs=&mt('Messages cleared.');
1.99 www 979: $showdel=0;
1.98 www 980: } else {
981: $bombs=&mt('Error clearing messages');
982: }
983: }
984: my $del=&mt('Delete Messages for this Resource');
985: my $clear=&mt('Clear all Messages in Subdirectory');
1.99 www 986: my $goback=&mt('Back to Source File');
1.66 matthew 987: $r->print(<<ENDBOMBS);
1.52 www 988: <h1>$disuri</h1>
989: <form method="post" name="defaultmeta">
1.99 www 990: ENDBOMBS
991: if ($showdel) {
992: $r->print(<<ENDDEL);
1.59 www 993: <input type="submit" name="delmsg" value="$del" />
1.98 www 994: <input type="submit" name="clearmsg" value="$clear" />
1.99 www 995: ENDDEL
996: } else {
997: $r->print('<a href="'.$disuri.'" />'.$goback.'</a>');
998: }
999: $r->print('<br />'.$bombs);
1.66 matthew 1000: } else {
1001: my $displayfile='Catalog Information for '.$disuri;
1002: if ($disuri=~/\/default$/) {
1003: my $dir=$disuri;
1004: $dir=~s/default$//;
1005: $displayfile=
1006: &mt('Default Cataloging Information for Directory').' '.
1007: $dir;
1008: }
1009: %Apache::lonpublisher::metadatafields=();
1010: %Apache::lonpublisher::metadatakeys=();
1.94 banghart 1011: my $result=&Apache::lonnet::getfile($fn);
1012: if ($result == -1){
1.110 albertel 1013: $r->print('Creating new '.$disuri);
1.94 banghart 1014: } else {
1015: &Apache::lonpublisher::metaeval($result);
1016: }
1.66 matthew 1017: $r->print(<<ENDEDIT);
1.23 www 1018: <h1>$displayfile</h1>
1.48 www 1019: <form method="post" name="defaultmeta">
1.23 www 1020: ENDEDIT
1.66 matthew 1021: $r->print('<script language="JavaScript">'.
1.86 albertel 1022: &Apache::loncommon::browser_and_searcher_javascript().
1.66 matthew 1023: '</script>');
1.90 banghart 1024: my %lt=&fieldnames($file_type);
1.87 albertel 1025: my $output;
1.90 banghart 1026: my @fields;
1027: if ($file_type eq 'portfolio') {
1.113 ! banghart 1028: @fields = ('author','title','subject','keywords','abstract','notes','lowestgradelevel',
1.91 banghart 1029: 'highestgradelevel');
1.90 banghart 1030: } else {
1031: @fields = ('author','title','subject','keywords','abstract','notes',
1.66 matthew 1032: 'copyright','customdistributionfile','language',
1033: 'standards',
1.78 taceyjo1 1034: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1.90 banghart 1035: 'obsolete','obsoletereplacement');
1036: }
1037: foreach (@fields) {
1.96 albertel 1038: if (defined($env{'form.new_'.$_})) {
1.66 matthew 1039: $Apache::lonpublisher::metadatafields{$_}=
1.96 albertel 1040: $env{'form.new_'.$_};
1.66 matthew 1041: }
1042: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
1043: $Apache::lonpublisher::metadatafields{'copyright'}=
1044: 'default';
1.64 matthew 1045: }
1.87 albertel 1046: $output.=('<p>'.$lt{$_}.': '.
1047: &prettyinput($_,
1048: $Apache::lonpublisher::metadatafields{$_},
1049: 'new_'.$_,'defaultmeta').'</p>');
1.106 banghart 1050: if ($env{'form.metacourse'}) {
1.108 banghart 1051: $r->print('This is the instructor metadata area<br />');
1052: # have to find all the metadata items, so we'll loop through and find them
1053: $r->print('<form method="post" action="" size="3" >');
1054: $r->print('The course is: '.$env{'form.metacourse'}.'<br>');
1055: foreach my $key (sort keys %env) {
1056: if ($key=~m/^($env{'form.metacourse'}\.metadata\.)(\d+)\.title/) {
1057: my $key_base = $1;
1058: my $item_num = $2;
1059: # found one, so let's display it
1060: my $title = $env{$key_base.$item_num.'.title'};
1061: my $type = $env{$key_base.$item_num.'.type'};
1062: my @choices = sort(split /, /,$env{$key_base.$item_num.'.values'});
1063: $r->print($title.'<br />');
1064: $r->print($type.'<br />');
1065:
1066: foreach my $word (@choices) {
1067: my $checked;
1068: if ($Apache::lonpublisher::metadatafields{'coursekeyword'}=~ m/$word/) {
1069: $checked = 1;
1070: } else {
1071: undef($checked);
1072: }
1073: $r->print(&Apache::lonhtmlcommon::checkbox('instmeta_'.$env{'form.metacourse'}.'_'.$item_num,$checked,$word).$word.'<br />');
1074: }
1.107 banghart 1075: }
1.108 banghart 1076: }
1.106 banghart 1077: $r->print('<br /><input type="submit" name="store" value="Assign Meta-data" />');
1078: $r->print('</form>');
1079: return 'ok';
1080: }
1.66 matthew 1081: }
1.96 albertel 1082: if ($env{'form.store'}) {
1.66 matthew 1083: my $mfh;
1.107 banghart 1084: my $formname='store';
1.94 banghart 1085: my $file_content;
1.108 banghart 1086: foreach my $meta_field (keys %env) {
1087: if ($meta_field=~m/^form.instmeta_(.+)_(\d+)$/) {
1088: $r->print('Found a field<br>');
1089: }
1090: if (&Apache::loncommon::get_env_multiple('form.keywords')) {
1091: $Apache::lonpublisher::metadatafields{'coursekeyword'} =
1.106 banghart 1092: join (', ', &Apache::loncommon::get_env_multiple('form.keywords'));
1.108 banghart 1093: }
1.106 banghart 1094: }
1.94 banghart 1095: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1096: next if ($_ =~ /\./);
1097: my $unikey=$_;
1098: $unikey=~/^([A-Za-z]+)/;
1099: my $tag=$1;
1100: $tag=~tr/A-Z/a-z/;
1101: $file_content.= "\n\<$tag";
1102: foreach (split(/\,/,
1103: $Apache::lonpublisher::metadatakeys{$unikey})
1104: ) {
1105: my $value=
1106: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
1107: $value=~s/\"/\'\'/g;
1108: $file_content.=' '.$_.'="'.$value.'"' ;
1109: # print $mfh ' '.$_.'="'.$value.'"';
1110: }
1111: $file_content.= '>'.
1112: &HTML::Entities::encode
1113: ($Apache::lonpublisher::metadatafields{$unikey},
1114: '<>&"').
1115: '</'.$tag.'>';
1116: }
1117: if ($fn =~ /\/portfolio\//) {
1118: $fn =~ /\/portfolio\/(.*)$/;
1119: my $new_fn = '/'.$1;
1.96 albertel 1120: $env{'form.'.$formname}=$file_content;
1121: $env{'form.'.$formname.'.filename'}=$new_fn;
1.94 banghart 1122: &Apache::lonnet::userfileupload('uploaddoc','',
1.96 albertel 1123: 'portfolio'.$env{'form.currentpath'});
1.94 banghart 1124: my $status =&Apache::lonnet::userfileupload($formname,'','portfolio');
1125: if (&Apache::lonnet::userfileupload($formname,'','portfolio') eq 'error: no uploaded file') {
1126: $r->print('<p><font color="red">'.
1127: &mt('Could not write metadata').', '.
1128: &mt('FAIL').'</font></p>');
1129: } else {
1130: $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
1131: ' '.&Apache::lonlocal::locallocaltime(time).
1132: '</font></p>');
1133: }
1.66 matthew 1134: } else {
1.94 banghart 1135: if (! ($mfh=Apache::File->new('>'.$fn))) {
1136: $r->print('<p><font color="red">'.
1137: &mt('Could not write metadata').', '.
1138: &mt('FAIL').'</font></p>');
1139: } else {
1140: print $mfh $file_content;
1.95 albertel 1141: $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
1142: ' '.&Apache::lonlocal::locallocaltime(time).
1143: '</font></p>');
1.64 matthew 1144: }
1145: }
1146: }
1.87 albertel 1147: $r->print($output.'<br /><input type="submit" name="store" value="'.
1.67 matthew 1148: &mt('Store Catalog Information').'">');
1.64 matthew 1149: }
1.67 matthew 1150: $r->print('</form>');
1.66 matthew 1151: return;
1.1 www 1152: }
1.64 matthew 1153:
1.1 www 1154: 1;
1155: __END__
1.97 banghart 1156:
1.98 www 1157:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>