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