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