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