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