Annotation of loncom/interface/lonmeta.pm, revision 1.163
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.163 ! albertel 4: # $Id: lonmeta.pm,v 1.162 2006/08/04 19:42:55 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.163 ! albertel 844: my @fields;
! 845: if ($uploaded) {
! 846: @fields = ('title','author','subject','keywords','notes','abstract',
! 847: 'lowestgradelevel','highestgradelevel','standards','mime',
! 848: 'owner');
! 849: } else {
! 850: @fields = ('title',
! 851: 'author',
! 852: 'subject',
! 853: 'keywords',
! 854: 'notes',
! 855: 'abstract',
! 856: 'lowestgradelevel',
! 857: 'highestgradelevel',
! 858: 'standards',
! 859: 'mime',
! 860: 'language',
! 861: 'creationdate',
! 862: 'lastrevisiondate',
! 863: 'owner',
! 864: 'copyright',
! 865: 'customdistributionfile',
! 866: 'sourceavail',
! 867: 'sourcerights',
! 868: 'obsolete',
! 869: 'obsoletereplacement');
! 870: }
! 871: foreach my $field (@fields) {
! 872: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$field}.
1.66 matthew 873: '</td><td bgcolor="#CCCCCC">'.
1.163 ! albertel 874: &prettyprint($field,$content{$field}).'</td></tr>';
! 875: delete($content{$field});
1.66 matthew 876: }
877: #
878: $r->print(<<ENDHEAD);
1.72 matthew 879: <h2>$title</h2>
880: <p>
881: $disuri<br />
1.36 www 882: $obsoletewarning
1.72 matthew 883: $versiondisplay
884: </p>
1.88 banghart 885: <table cellspacing="2" border="0">
1.45 www 886: $table
1.11 www 887: </table>
1.1 www 888: ENDHEAD
1.162 albertel 889: if (!$uploaded && $env{'user.adv'}) {
1.68 matthew 890: &print_dynamic_metadata($r,$uri,\%content);
1.67 matthew 891: }
892: return;
893: }
894:
895: sub print_dynamic_metadata {
1.68 matthew 896: my ($r,$uri,$content) = @_;
897: #
1.69 matthew 898: my %content = %$content;
1.68 matthew 899: my %lt=&fieldnames();
1.67 matthew 900: #
901: my $description = 'Dynamic Metadata (updated periodically)';
902: $r->print('<h3>'.&mt($description).'</h3>'.
1.70 matthew 903: &mt('Processing'));
1.67 matthew 904: $r->rflush();
905: my %items=&fieldnames();
906: my %dynmeta=&dynamicmeta($uri);
907: #
908: # General Access and Usage Statistics
1.70 matthew 909: if (exists($dynmeta{'count'}) ||
910: exists($dynmeta{'sequsage'}) ||
911: exists($dynmeta{'comefrom'}) ||
912: exists($dynmeta{'goto'}) ||
913: exists($dynmeta{'course'})) {
914: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
1.88 banghart 915: '<table cellspacing="2" border="0">');
1.70 matthew 916: foreach ('count',
917: 'sequsage','sequsage_list',
918: 'comefrom','comefrom_list',
919: 'goto','goto_list',
920: 'course','course_list') {
921: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
922: '<td bgcolor="#CCCCCC">'.
923: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
924: }
925: $r->print('</table>');
926: } else {
927: $r->print('<h4>'.&mt('No Access or Usages Statistics are available for this resource.').'</h4>');
1.67 matthew 928: }
1.69 matthew 929: #
930: # Assessment statistics
1.73 matthew 931: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)$/) {
932: if (exists($dynmeta{'stdno'}) ||
933: exists($dynmeta{'avetries'}) ||
934: exists($dynmeta{'difficulty'}) ||
935: exists($dynmeta{'disc'})) {
936: # This is an assessment, print assessment data
937: $r->print('<h4>'.
938: &mt('Overall Assessment Statistical Data').
939: '</h4>'.
1.88 banghart 940: '<table cellspacing="2" border="0">');
1.73 matthew 941: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{'stdno'}.'</td>'.
1.66 matthew 942: '<td bgcolor="#CCCCCC">'.
1.73 matthew 943: &prettyprint('stdno',$dynmeta{'stdno'}).
944: '</td>'."</tr>\n");
945: foreach ('avetries','difficulty','disc') {
946: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
947: '<td bgcolor="#CCCCCC">'.
948: &prettyprint($_,sprintf('%5.2f',$dynmeta{$_})).
949: '</td>'."</tr>\n");
950: }
951: $r->print('</table>');
952: }
953: if (exists($dynmeta{'stats'})) {
954: #
955: # New assessment statistics
956: $r->print('<h4>'.
957: &mt('Detailed Assessment Statistical Data').
958: '</h4>');
1.88 banghart 959: my $table = '<table cellspacing="2" border="0">'.
1.73 matthew 960: '<tr>'.
961: '<th>Course</th>'.
962: '<th>Section(s)</th>'.
963: '<th>Num Students</th>'.
964: '<th>Mean Tries</th>'.
965: '<th>Degree of Difficulty</th>'.
966: '<th>Degree of Discrimination</th>'.
967: '<th>Time of computation</th>'.
968: '</tr>'.$/;
969: foreach my $identifier (sort(keys(%{$dynmeta{'stats'}}))) {
970: my $data = $dynmeta{'stats'}->{$identifier};
971: my $course = $data->{'course'};
1.154 albertel 972: my %courseinfo =
973: &Apache::lonnet::coursedescription($course,
974: {'one_time' => 1});
1.73 matthew 975: if (! exists($courseinfo{'num'}) || $courseinfo{'num'} eq '') {
976: &Apache::lonnet::logthis('lookup for '.$course.' failed');
977: next;
978: }
979: $table .= '<tr>';
980: $table .=
981: '<td><nobr>'.$courseinfo{'description'}.'</nobr></td>';
982: $table .=
983: '<td align="right">'.$data->{'sections'}.'</td>';
984: $table .=
985: '<td align="right">'.$data->{'stdno'}.'</td>';
986: foreach ('avetries','difficulty','disc') {
987: $table .= '<td align="right">';
988: if (exists($data->{$_})) {
989: $table .= sprintf('%.2f',$data->{$_}).' ';
990: } else {
991: $table .= '';
992: }
993: $table .= '</td>';
994: }
995: $table .=
996: '<td><nobr>'.
997: &Apache::lonlocal::locallocaltime($data->{'timestamp'}).
998: '</nobr></td>';
999: $table .=
1000: '</tr>'.$/;
1001: }
1002: $table .= '</table>'.$/;
1003: $r->print($table);
1004: } else {
1005: $r->print('No new dynamic data found.');
1.66 matthew 1006: }
1.70 matthew 1007: } else {
1.73 matthew 1008: $r->print('<h4>'.
1009: &mt('No Assessment Statistical Data is available for this resource').
1010: '</h4>');
1.67 matthew 1011: }
1.73 matthew 1012:
1013: #
1014: #
1.70 matthew 1015: if (exists($dynmeta{'clear'}) ||
1016: exists($dynmeta{'depth'}) ||
1017: exists($dynmeta{'helpful'}) ||
1018: exists($dynmeta{'correct'}) ||
1019: exists($dynmeta{'technical'})){
1020: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
1.88 banghart 1021: '<table cellspacing="2" border="0">');
1.70 matthew 1022: foreach ('clear','depth','helpful','correct','technical') {
1023: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
1024: '<td bgcolor="#CCCCCC">'.
1025: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
1026: }
1027: $r->print('</table>');
1028: } else {
1029: $r->print('<h4>'.&mt('No Evaluation Data is available for this resource.').'</h4>');
1.67 matthew 1030: }
1031: $uri=~/^\/res\/(\w+)\/(\w+)\//;
1.96 albertel 1032: if ((($env{'user.domain'} eq $1) && ($env{'user.name'} eq $2))
1033: || ($env{'user.role.ca./'.$1.'/'.$2})) {
1.70 matthew 1034: if (exists($dynmeta{'comments'})) {
1035: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
1036: &mt('visible to author and co-authors only').
1037: ')</h4>'.
1038: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
1039: } else {
1040: $r->print('<h4>'.&mt('There are no Evaluation Comments on this resource.').'</h4>');
1041: }
1042: my $bombs = &Apache::lonmsg::retrieve_author_res_msg($uri);
1043: if (defined($bombs) && $bombs ne '') {
1044: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
1045: &mt('visible to author and co-authors only').')'.
1046: '</h4>'.$bombs);
1047: } else {
1048: $r->print('<h4>'.&mt('There are currently no Error Messages for this resource.').'</h4>');
1049: }
1.67 matthew 1050: }
1.69 matthew 1051: #
1.67 matthew 1052: # All other stuff
1053: $r->print('<h3>'.
1054: &mt('Additional Metadata (non-standard, parameters, exports)').
1.81 www 1055: '</h3><table border="0" cellspacing="1">');
1.67 matthew 1056: foreach (sort(keys(%content))) {
1057: my $name=$_;
1058: if ($name!~/\.display$/) {
1059: my $display=&Apache::lonnet::metadata($uri,
1060: $name.'.display');
1061: if (! $display) {
1062: $display=$name;
1063: };
1064: my $otherinfo='';
1065: foreach ('name','part','type','default') {
1066: if (defined(&Apache::lonnet::metadata($uri,
1067: $name.'.'.$_))) {
1068: $otherinfo.=' '.$_.'='.
1069: &Apache::lonnet::metadata($uri,
1070: $name.'.'.$_).'; ';
1071: }
1.64 matthew 1072: }
1.81 www 1073: $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 1074: if ($otherinfo) {
1075: $r->print(' ('.$otherinfo.')');
1.64 matthew 1076: }
1.81 www 1077: $r->print("</font></td></tr>\n");
1.64 matthew 1078: }
1.66 matthew 1079: }
1.81 www 1080: $r->print("</table>");
1.67 matthew 1081: return;
1.66 matthew 1082: }
1.105 banghart 1083:
1.102 banghart 1084:
1085:
1.67 matthew 1086: #####################################################
1087: #####################################################
1088: ### ###
1089: ### Editable metadata display ###
1090: ### ###
1091: #####################################################
1092: #####################################################
1.66 matthew 1093: sub present_editable_metadata {
1.90 banghart 1094: my ($r,$uri, $file_type) = @_;
1.66 matthew 1095: # Construction Space Call
1096: # Header
1097: my $disuri=$uri;
1098: my $fn=&Apache::lonnet::filelocation('',$uri);
1.155 albertel 1099: $disuri=~s{^/\~}{/priv/};
1.66 matthew 1100: $disuri=~s/\.meta$//;
1.141 albertel 1101: my $meta_uri = $disuri;
1.147 albertel 1102: my $path;
1.141 albertel 1103: if ($disuri =~ m|/portfolio/|) {
1.147 albertel 1104: ($disuri, $meta_uri, $path) = &portfolio_display_uri($disuri,1);
1.141 albertel 1105: }
1.66 matthew 1106: my $target=$uri;
1.155 albertel 1107: $target=~s{^/\~}{/res/$env{'request.role.domain'}/};
1.66 matthew 1108: $target=~s/\.meta$//;
1109: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
1110: if ($bombs) {
1.99 www 1111: my $showdel=1;
1.96 albertel 1112: if ($env{'form.delmsg'}) {
1.66 matthew 1113: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
1114: $bombs=&mt('Messages deleted.');
1.99 www 1115: $showdel=0;
1.66 matthew 1116: } else {
1117: $bombs=&mt('Error deleting messages');
1.64 matthew 1118: }
1.66 matthew 1119: }
1.98 www 1120: if ($env{'form.clearmsg'}) {
1121: my $cleardir=$target;
1122: $cleardir=~s/\/[^\/]+$/\//;
1123: if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
1124: $bombs=&mt('Messages cleared.');
1.99 www 1125: $showdel=0;
1.98 www 1126: } else {
1127: $bombs=&mt('Error clearing messages');
1128: }
1129: }
1130: my $del=&mt('Delete Messages for this Resource');
1131: my $clear=&mt('Clear all Messages in Subdirectory');
1.99 www 1132: my $goback=&mt('Back to Source File');
1.66 matthew 1133: $r->print(<<ENDBOMBS);
1.52 www 1134: <h1>$disuri</h1>
1135: <form method="post" name="defaultmeta">
1.99 www 1136: ENDBOMBS
1137: if ($showdel) {
1138: $r->print(<<ENDDEL);
1.59 www 1139: <input type="submit" name="delmsg" value="$del" />
1.98 www 1140: <input type="submit" name="clearmsg" value="$clear" />
1.99 www 1141: ENDDEL
1142: } else {
1143: $r->print('<a href="'.$disuri.'" />'.$goback.'</a>');
1144: }
1145: $r->print('<br />'.$bombs);
1.66 matthew 1146: } else {
1147: my $displayfile='Catalog Information for '.$disuri;
1148: if ($disuri=~/\/default$/) {
1149: my $dir=$disuri;
1150: $dir=~s/default$//;
1151: $displayfile=
1152: &mt('Default Cataloging Information for Directory').' '.
1153: $dir;
1154: }
1155: %Apache::lonpublisher::metadatafields=();
1156: %Apache::lonpublisher::metadatakeys=();
1.94 banghart 1157: my $result=&Apache::lonnet::getfile($fn);
1158: if ($result == -1){
1.141 albertel 1159: $r->print(&mt('Creating new file [_1]'),$meta_uri);
1.94 banghart 1160: } else {
1161: &Apache::lonpublisher::metaeval($result);
1162: }
1.66 matthew 1163: $r->print(<<ENDEDIT);
1.23 www 1164: <h1>$displayfile</h1>
1.48 www 1165: <form method="post" name="defaultmeta">
1.23 www 1166: ENDEDIT
1.66 matthew 1167: $r->print('<script language="JavaScript">'.
1.86 albertel 1168: &Apache::loncommon::browser_and_searcher_javascript().
1.66 matthew 1169: '</script>');
1.90 banghart 1170: my %lt=&fieldnames($file_type);
1.87 albertel 1171: my $output;
1.90 banghart 1172: my @fields;
1173: if ($file_type eq 'portfolio') {
1.163 ! albertel 1174: @fields = ('author','title','subject','keywords','abstract',
! 1175: 'notes','lowestgradelevel',
1.140 banghart 1176: 'highestgradelevel','standards');
1.90 banghart 1177: } else {
1178: @fields = ('author','title','subject','keywords','abstract','notes',
1.66 matthew 1179: 'copyright','customdistributionfile','language',
1180: 'standards',
1.78 taceyjo1 1181: 'lowestgradelevel','highestgradelevel','sourceavail','sourcerights',
1.90 banghart 1182: 'obsolete','obsoletereplacement');
1183: }
1.139 banghart 1184: if ((! $Apache::lonpublisher::metadatafields{'courserestricted'}) &&
1185: (! $env{'form.new_courserestricted'})) {
1.138 banghart 1186: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1187: 'none';
1.139 banghart 1188: } elsif ($env{'form.new_courserestricted'}) {
1189: $Apache::lonpublisher::metadatafields{'courserestricted'}=
1190: $env{'form.new_courserestricted'};
1191: }
1.120 banghart 1192: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
1193: $Apache::lonpublisher::metadatafields{'copyright'}=
1.163 ! albertel 1194: 'default';
1.120 banghart 1195: }
1.149 albertel 1196: if ($file_type eq 'portfolio') {
1.163 ! albertel 1197: if (! $Apache::lonpublisher::metadatafields{'mime'}) {
! 1198: ($Apache::lonpublisher::metadatafields{'mime'}) =
! 1199: ( $target=~/\.(\w+)$/ );
! 1200: }
! 1201: if (! $Apache::lonpublisher::metadatafields{'owner'}) {
! 1202: $Apache::lonpublisher::metadatafields{'owner'} =
! 1203: $env{'user.name'}.':'.$env{'user.domain'};
! 1204: }
! 1205:
1.149 albertel 1206: if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none') {
1207: $r->print(&mt('Associated with course [_1]','<strong>'.$env{$Apache::lonpublisher::metadatafields{'courserestricted'}.".description"}.
1208: '</strong>').'<br />');
1209: } else {
1210: $r->print("This resource is not associated with a course.<br />");
1211: }
1212: }
1.143 albertel 1213: foreach my $field_name (@fields) {
1.132 banghart 1214:
1215: if (defined($env{'form.new_'.$field_name})) {
1216: $Apache::lonpublisher::metadatafields{$field_name}=
1217: join(',',&Apache::loncommon::get_env_multiple('form.new_'.$field_name));
1.66 matthew 1218: }
1.150 albertel 1219: if ($Apache::lonpublisher::metadatafields{'courserestricted'} ne 'none'
1220: && exists($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'})) {
1.115 banghart 1221: # handle restrictions here
1.138 banghart 1222: if (($env{$Apache::lonpublisher::metadatafields{'courserestricted'}.'.metadata.'.$field_name.'.options'} =~ m/active/) ||
1223: ($field_name eq 'courserestricted')){
1.143 albertel 1224: $output.=("\n".'<p>'.$lt{$field_name}.': '.
1.132 banghart 1225: &prettyinput($field_name,
1226: $Apache::lonpublisher::metadatafields{$field_name},
1.138 banghart 1227: 'new_'.$field_name,'defaultmeta',
1228: undef,undef,undef,undef,
1.143 albertel 1229: $Apache::lonpublisher::metadatafields{'courserestricted'}).'</p>'."\n");
1.127 banghart 1230: }
1.115 banghart 1231: } else {
1.138 banghart 1232:
1.132 banghart 1233: $output.=('<p>'.$lt{$field_name}.': '.
1234: &prettyinput($field_name,
1235: $Apache::lonpublisher::metadatafields{$field_name},
1236: 'new_'.$field_name,'defaultmeta').'</p>');
1.138 banghart 1237:
1.115 banghart 1238: }
1.66 matthew 1239: }
1.143 albertel 1240: if ($env{'form.store'}) {
1241: my $mfh;
1242: my $formname='store';
1243: my $file_content;
1.142 albertel 1244: if (&Apache::loncommon::get_env_multiple('form.new_keywords')) {
1245: $Apache::lonpublisher::metadatafields{'keywords'} =
1246: join (',', &Apache::loncommon::get_env_multiple('form.new_keywords'));
1247: }
1.143 albertel 1248:
1249: foreach (sort keys %Apache::lonpublisher::metadatafields) {
1250: next if ($_ =~ /\./);
1251: my $unikey=$_;
1252: $unikey=~/^([A-Za-z]+)/;
1253: my $tag=$1;
1254: $tag=~tr/A-Z/a-z/;
1255: $file_content.= "\n\<$tag";
1256: foreach (split(/\,/,
1257: $Apache::lonpublisher::metadatakeys{$unikey})
1258: ) {
1259: my $value=
1260: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
1261: $value=~s/\"/\'\'/g;
1262: $file_content.=' '.$_.'="'.$value.'"' ;
1263: # print $mfh ' '.$_.'="'.$value.'"';
1264: }
1265: $file_content.= '>'.
1266: &HTML::Entities::encode
1267: ($Apache::lonpublisher::metadatafields{$unikey},
1268: '<>&"').
1269: '</'.$tag.'>';
1.142 albertel 1270: }
1.159 raeburn 1271: if ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/portfolio/|) {
1.143 albertel 1272: my ($path, $new_fn) = ($fn =~ m|/(portfolio.*)/([^/]*)$|);
1.159 raeburn 1273: $r->print(&store_portfolio_metadata($formname,$file_content,$path,
1274: $new_fn));
1275: } elsif ($fn =~ m|^$Apache::lonnet::perlvar{'lonDocRoot'}/userfiles/groups/\w+/portfolio/|) {
1276: my ($path, $new_fn) = ($fn =~ m|/(groups/\w+/portfolio.*)/([^/]*)$|);
1277: $r->print(&store_portfolio_metadata($formname,$file_content,$path,$new_fn));
1.142 albertel 1278: } else {
1.143 albertel 1279: if (! ($mfh=Apache::File->new('>'.$fn))) {
1280: $r->print('<p><font color="red">'.
1281: &mt('Could not write metadata').', '.
1282: &mt('FAIL').'</font></p>');
1283: } else {
1284: print $mfh $file_content;
1285: $r->print('<p><font color="blue">'.&mt('Wrote Metadata').
1286: ' '.&Apache::lonlocal::locallocaltime(time).
1287: '</font></p>');
1288: }
1.142 albertel 1289: }
1290: }
1.143 albertel 1291:
1292: $r->print($output.'<br /><input type="submit" name="store" value="'.
1293: &mt('Store Catalog Information').'">');
1.147 albertel 1294:
1.149 albertel 1295: if ($file_type eq 'portfolio') {
1.156 albertel 1296: my ($port_path,$group) = &get_port_path_and_group($uri);
1.159 raeburn 1297: if ($group) {
1298: $r->print('<input type="hidden" name="group" value="'.$group.'" />');
1299: }
1.149 albertel 1300: $r->print('</form>
1.156 albertel 1301: <br /><br /><form method="POST" action="'.$port_path.'">'.
1302: '<input type="hidden" name="group" value="'.$group.'" />'.
1.149 albertel 1303: '<input type="hidden" name="currentpath" value="'.$path.'" />'.
1304: '<input type="submit" name="cancel" value="'.&mt('Discard Edits and Return to Portfolio').'">');
1305: }
1.142 albertel 1306: }
1.149 albertel 1307:
1.143 albertel 1308: $r->print('</form>');
1309:
1.66 matthew 1310: return;
1.1 www 1311: }
1.64 matthew 1312:
1.159 raeburn 1313: sub store_portfolio_metadata {
1314: my ($formname,$content,$path,$new_fn) = @_;
1315: $env{'form.'.$formname}=$content."\n";
1316: $env{'form.'.$formname.'.filename'}=$new_fn;
1317: my $result =&Apache::lonnet::userfileupload($formname,'',$path);
1318: if ($result =~ /(error|notfound)/) {
1319: return '<p><font color="red">'.
1320: &mt('Could not write metadata').', '.
1321: &mt('FAIL').'</font></p>';
1322: } else {
1323: return '<p><font color="blue">'.&mt('Wrote Metadata').
1324: ' '.&Apache::lonlocal::locallocaltime(time).'</font></p>';
1325: }
1326: }
1327:
1.1 www 1328: 1;
1329: __END__
1.97 banghart 1330:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>