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