Annotation of loncom/interface/lonmeta.pm, revision 1.66
1.1 www 1: # The LearningOnline Network with CAPA
1.8 albertel 2: # Metadata display handler
3: #
1.66 ! matthew 4: # $Id: lonmeta.pm,v 1.65 2004/04/13 15:41:19 matthew 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: #
20: # You should have received a copy of the GNU General Public License
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.3 www 34: use Apache::lonnet();
1.10 www 35: use Apache::loncommon();
1.46 www 36: use Apache::lonhtmlcommon();
1.23 www 37: use Apache::lonmsg;
38: use Apache::lonpublisher;
1.35 www 39: use Apache::lonlocal;
1.43 www 40: use Apache::lonmysql;
1.49 www 41: use Apache::lonmsg;
1.1 www 42:
1.44 www 43: # MySQL table columns
44:
45: my @columns;
46:
1.64 matthew 47: # Fetch and evaluate dynamic metadata
1.9 www 48: sub dynamicmeta {
49: my $url=&Apache::lonnet::declutter(shift);
50: $url=~s/\.meta$//;
51: my ($adomain,$aauthor)=($url=~/^(\w+)\/(\w+)\//);
1.19 www 52: my $regexp=$url;
1.9 www 53: $regexp=~s/(\W)/\\$1/g;
1.10 www 54: $regexp='___'.$regexp.'___';
1.16 albertel 55: my %evaldata=&Apache::lonnet::dump('nohist_resevaldata',$adomain,
56: $aauthor,$regexp);
1.63 matthew 57: my %DynamicData = &LONCAPA::lonmetadata::process_reseval_data(\%evaldata);
58: my %Data = &LONCAPA::lonmetadata::process_dynamic_metadata($url,
59: \%DynamicData);
1.40 matthew 60: #
1.46 www 61: # Deal with 'count' separately
1.63 matthew 62: $Data{'count'} = &access_count($url,$aauthor,$adomain);
63: return %Data;
1.40 matthew 64: }
65:
66: sub access_count {
67: my ($src,$author,$adomain) = @_;
68: my %countdata=&Apache::lonnet::dump('nohist_accesscount',$adomain,
69: $author,$src);
70: if (! exists($countdata{$src})) {
1.47 www 71: return &mt('Not Available');
1.40 matthew 72: } else {
73: return $countdata{$src};
74: }
1.25 www 75: }
76:
1.64 matthew 77: # Try to make an alt tag if there is none
1.25 www 78: sub alttag {
1.26 www 79: my ($base,$src)=@_;
80: my $fullpath=&Apache::lonnet::hreflocation($base,$src);
81: my $alttag=&Apache::lonnet::metadata($fullpath,'title').' '.
1.64 matthew 82: &Apache::lonnet::metadata($fullpath,'subject').' '.
83: &Apache::lonnet::metadata($fullpath,'abstract');
1.26 www 84: $alttag=~s/\s+/ /gs;
85: $alttag=~s/\"//gs;
86: $alttag=~s/\'//gs;
87: $alttag=~s/\s+$//gs;
88: $alttag=~s/^\s+//gs;
1.64 matthew 89: if ($alttag) {
90: return $alttag;
91: } else {
92: return &mt('No information available');
93: }
1.9 www 94: }
1.1 www 95:
1.64 matthew 96: # Author display
1.29 www 97: sub authordisplay {
98: my ($aname,$adom)=@_;
1.64 matthew 99: return &Apache::loncommon::aboutmewrapper
100: (&Apache::loncommon::plainname($aname,$adom),
101: $aname,$adom,'preview').' <tt>['.$aname.'@'.$adom.']</tt>';
1.29 www 102: }
103:
1.64 matthew 104: # Pretty display
1.12 www 105: sub evalgraph {
106: my $value=shift;
1.65 matthew 107: if (! $value) {
108: return '';
109: }
1.12 www 110: my $val=int($value*10.+0.5)-10;
111: my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
112: if ($val>=20) {
113: $output.='<td width=20 bgcolor="#555555">  </td>';
114: } else {
115: $output.='<td width='.($val).' bgcolor="#555555"> </td>'.
116: '<td width='.(20-$val).' bgcolor="#FF3333"> </td>';
117: }
118: $output.='<td bgcolor="#FFFF33"> </td>';
119: if ($val>20) {
120: $output.='<td width='.($val-20).' bgcolor="#33FF33"> </td>'.
121: '<td width='.(40-$val).' bgcolor="#555555"> </td>';
122: } else {
1.64 matthew 123: $output.='<td width=20 bgcolor="#555555">  </td>';
1.12 www 124: }
125: $output.='<td> ('.$value.') </td></tr></table>';
126: return $output;
127: }
128:
129: sub diffgraph {
130: my $value=shift;
1.65 matthew 131: if (! $value) {
132: return '';
133: }
1.12 www 134: my $val=int(40.0*$value+0.5);
1.13 www 135: my @colors=('#FF9933','#EEAA33','#DDBB33','#CCCC33',
136: '#BBDD33','#CCCC33','#DDBB33','#EEAA33');
1.12 www 137: my $output='<table border=0 cellpadding=0 cellspacing=0><tr>';
138: for (my $i=0;$i<8;$i++) {
139: if ($val>$i*5) {
140: $output.='<td width=5 bgcolor="'.$colors[$i].'"> </td>';
141: } else {
142: $output.='<td width=5 bgcolor="#555555"> </td>';
143: }
144: }
145: $output.='<td> ('.$value.') </td></tr></table>';
146: return $output;
147: }
148:
1.66 ! matthew 149: #
1.64 matthew 150: # Turn MySQL row into hash
1.66 ! matthew 151: # This routine is here for historic reasons. Probably should be moved to
! 152: # a more generic place since it has nothing to do with metadata
1.44 www 153: sub metadata_col_to_hash {
154: my @cols=@_;
155: my %hash=();
156: for (my $i=0; $i<=$#columns; $i++) {
157: $hash{$columns[$i]}=$cols[$i];
158: }
159: return %hash;
160: }
161:
1.64 matthew 162: # The field names
1.45 www 163: sub fieldnames {
1.64 matthew 164: return &Apache::lonlocal::texthash
165: (
166: 'title' => 'Title',
167: 'author' =>'Author(s)',
168: 'authorspace' => 'Author Space',
169: 'modifyinguser' => 'Last Modifying User',
170: 'subject' => 'Subject',
171: 'keywords' => 'Keyword(s)',
172: 'notes' => 'Notes',
173: 'abstract' => 'Abstract',
174: 'lowestgradelevel' => 'Lowest Grade Level',
175: 'highestgradelevel' => 'Highest Grade Level',
176: 'standards' => 'Standards',
177: 'mime' => 'MIME Type',
178: 'language' => 'Language',
179: 'creationdate' => 'Creation Date',
180: 'lastrevisiondate' => 'Last Revision Date',
181: 'owner' => 'Publisher/Owner',
182: 'copyright' => 'Copyright/Distribution',
183: 'customdistributionfile' => 'Custom Distribution File',
184: 'obsolete' => 'Obsolete',
185: 'obsoletereplacement' => 'Suggested Replacement for Obsolete File',
186: 'count' => 'Network-wide number of accesses (hits)',
187: 'course' => 'Network-wide number of courses using resource',
188: 'course_list' => 'Network-wide courses using resource',
189: 'sequsage' => 'Number of resources using or importing resource',
190: 'sequsage_list' => 'Resources using or importing resource',
191: 'goto' => 'Number of resources that follow this resource in maps',
192: 'goto_list' => 'Resources that follow this resource in maps',
193: 'comefrom' => 'Number of resources that lead up to this resource in maps',
194: 'comefrom_list' => 'Resources that lead up to this resource in maps',
195: 'clear' => 'Material presented in clear way',
196: 'depth' => 'Material covered with sufficient depth',
197: 'helpful' => 'Material is helpful',
198: 'correct' => 'Material appears to be correct',
199: 'technical' => 'Resource is technically correct',
200: 'avetries' => 'Average number of tries till solved',
201: 'stdno' => 'Total number of students who have worked on this problem',
202: 'difficulty' => 'Degree of difficulty'
203: );
1.45 www 204: }
1.46 www 205:
1.64 matthew 206: # Pretty printing of metadata field
1.46 www 207:
208: sub prettyprint {
209: my ($type,$value)=@_;
1.65 matthew 210: if (! defined($value)) {
211: return ' ';
212: }
1.64 matthew 213: # Title
1.46 www 214: if ($type eq 'title') {
215: return '<font size="+1" face="arial">'.$value.'</font>';
216: }
1.64 matthew 217: # Dates
1.46 www 218: if (($type eq 'creationdate') ||
219: ($type eq 'lastrevisiondate')) {
1.55 www 220: return ($value?&Apache::lonlocal::locallocaltime(
221: &Apache::lonmysql::unsqltime($value)):
222: &mt('not available'));
1.46 www 223: }
1.64 matthew 224: # Language
1.46 www 225: if ($type eq 'language') {
226: return &Apache::loncommon::languagedescription($value);
227: }
1.64 matthew 228: # Copyright
1.46 www 229: if ($type eq 'copyright') {
230: return &Apache::loncommon::copyrightdescription($value);
231: }
1.64 matthew 232: # MIME
1.46 www 233: if ($type eq 'mime') {
1.64 matthew 234: return '<img src="'.&Apache::loncommon::icon($value).'" /> '.
235: &Apache::loncommon::filedescription($value);
236: }
237: # Person
1.46 www 238: if (($type eq 'author') ||
239: ($type eq 'owner') ||
240: ($type eq 'modifyinguser') ||
241: ($type eq 'authorspace')) {
242: $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
243: return $value;
244: }
1.64 matthew 245: # Gradelevel
1.48 www 246: if (($type eq 'lowestgradelevel') ||
247: ($type eq 'highestgradelevel')) {
248: return &Apache::loncommon::gradeleveldescription($value);
249: }
1.64 matthew 250: # Only for advance users below
1.65 matthew 251: if (! $ENV{'user.adv'}) {
252: return '<i>- '.&mt('not displayed').' -</i>';
253: }
1.64 matthew 254: # File
1.46 www 255: if (($type eq 'customdistributionfile') ||
256: ($type eq 'obsoletereplacement') ||
257: ($type eq 'goto_list') ||
258: ($type eq 'comefrom_list') ||
259: ($type eq 'sequsage_list')) {
260: return join('<br />',map {
1.64 matthew 261: my $url=&Apache::lonnet::clutter($_);
262: '<b>'.&Apache::lonnet::gettitle($url).'</b>'.
263: &Apache::lonhtmlcommon::crumbs($url,'preview','',undef,'+0');
264: } split(/\s*\,\s*/,$value));
1.46 www 265: }
1.64 matthew 266: # Evaluations
1.46 www 267: if (($type eq 'clear') ||
268: ($type eq 'depth') ||
269: ($type eq 'helpful') ||
270: ($type eq 'correct') ||
271: ($type eq 'technical')) {
272: return &evalgraph($value);
273: }
1.64 matthew 274: # Difficulty
1.46 www 275: if ($type eq 'difficulty') {
276: return &diffgraph($value);
277: }
1.64 matthew 278: # List of courses
1.46 www 279: if ($type=~/\_list/) {
280: return join('<br />',map {
281: my %courseinfo=&Apache::lonnet::coursedescription($_);
282: '<a href="/public/'.
283: $courseinfo{'domain'}.'/'.$courseinfo{'num'}.'/syllabus" target="preview">'.
284: $courseinfo{'description'}.'</a>';
285: } split(/\s*\,\s*/,$value));
286: }
1.64 matthew 287: # No pretty print found
1.46 www 288: return $value;
289: }
290:
1.64 matthew 291: # Pretty input of metadata field
1.54 www 292: sub direct {
293: return shift;
294: }
295:
1.48 www 296: sub selectbox {
297: my ($name,$value,$functionref,@idlist)=@_;
1.65 matthew 298: if (! defined($functionref)) {
299: $functionref=\&direct;
300: }
1.48 www 301: my $selout='<select name="'.$name.'">';
302: foreach (@idlist) {
303: $selout.='<option value=\''.$_.'\'';
304: if ($_ eq $value) {
305: $selout.=' selected>'.&{$functionref}($_).'</option>';
306: }
307: else {$selout.='>'.&{$functionref}($_).'</option>';}
308: }
309: return $selout.'</select>';
310: }
311:
1.54 www 312: sub relatedfield {
313: my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
1.65 matthew 314: if (! $relatedsearchflag) {
315: return '';
316: }
317: if (! defined($relatedsep)) {
318: $relatedsep=' ';
319: }
320: if (! $show) {
321: return $relatedsep.' ';
322: }
1.54 www 323: return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
324: ($relatedvalue?' checked="1"':'').' />';
325: }
1.48 www 326:
1.46 www 327: sub prettyinput {
1.54 www 328: my ($type,$value,$fieldname,$formname,
329: $relatedsearchflag,$relatedsep,$relatedvalue)=@_;
1.64 matthew 330: # Language
1.48 www 331: if ($type eq 'language') {
332: return &selectbox($fieldname,
333: $value,
334: \&Apache::loncommon::languagedescription,
1.54 www 335: (&Apache::loncommon::languageids)).
1.64 matthew 336: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 337: }
1.64 matthew 338: # Copyright
1.48 www 339: if ($type eq 'copyright') {
340: return &selectbox($fieldname,
341: $value,
342: \&Apache::loncommon::copyrightdescription,
1.54 www 343: (&Apache::loncommon::copyrightids)).
1.64 matthew 344: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 345: }
1.64 matthew 346: # Gradelevels
1.48 www 347: if (($type eq 'lowestgradelevel') ||
348: ($type eq 'highestgradelevel')) {
1.54 www 349: return &Apache::loncommon::select_level_form($value,$fieldname).
1.64 matthew 350: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 351: }
1.64 matthew 352: # Obsolete
1.48 www 353: if ($type eq 'obsolete') {
354: return '<input type="checkbox" name="'.$fieldname.'"'.
1.54 www 355: ($value?' checked="1"':'').' />'.
1.64 matthew 356: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 357: }
1.64 matthew 358: # Obsolete replacement file
1.48 www 359: if ($type eq 'obsoletereplacement') {
360: return '<input type="text" name="'.$fieldname.
361: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
362: "('".$formname."','".$fieldname."'".
1.54 www 363: ",'')\">".&mt('Select').'</a>'.
1.64 matthew 364: &relatedfield(0,$relatedsearchflag,$relatedsep);
365: }
366: # Customdistribution file
1.48 www 367: if ($type eq 'customdistributionfile') {
368: return '<input type="text" name="'.$fieldname.
369: '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
370: "('".$formname."','".$fieldname."'".
1.54 www 371: ",'rights')\">".&mt('Select').'</a>'.
1.64 matthew 372: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 373: }
1.64 matthew 374: # Dates
1.48 www 375: if (($type eq 'creationdate') ||
376: ($type eq 'lastrevisiondate')) {
1.64 matthew 377: return
378: &Apache::lonhtmlcommon::date_setter($formname,$fieldname,$value).
379: &relatedfield(0,$relatedsearchflag,$relatedsep);
1.48 www 380: }
1.64 matthew 381: # No pretty input found
1.48 www 382: $value=~s/^\s+//gs;
383: $value=~s/\s+$//gs;
384: $value=~s/\s+/ /gs;
385: $value=~s/\"/\&quod\;/gs;
1.54 www 386: return
1.64 matthew 387: '<input type="text" name="'.$fieldname.'" size="80" '.
388: 'value="'.$value.'" />'.
389: &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,
390: $relatedvalue);
1.46 www 391: }
392:
1.64 matthew 393: # Main Handler
1.1 www 394: sub handler {
1.64 matthew 395: my $r=shift;
396: #
1.20 www 397: my $loaderror=&Apache::lonnet::overloaderror($r);
398: if ($loaderror) { return $loaderror; }
1.64 matthew 399: #
1.20 www 400: my $uri=$r->uri;
1.64 matthew 401: #
1.66 ! matthew 402: if ($uri=~m:/adm/bombs/(.*)$:) {
! 403: # Looking for all bombs?
! 404: &report_bombs($r,$uri);
! 405: } elsif ($uri=~/^\/\~/) {
! 406: # Construction space
! 407: &present_editable_metadata($r,$uri);
! 408: } else {
! 409: &present_uneditable_metadata($r,$uri);
! 410: }
! 411: return OK;
! 412: }
! 413:
! 414: sub report_bombs {
! 415: my ($r,$uri) = @_;
! 416: # Set document type
! 417: $uri=~ s:/adm/bombs/::;
! 418: $uri=&Apache::lonnet::declutter($uri);
! 419: &Apache::loncommon::content_type($r,'text/html');
! 420: $r->send_http_header;
! 421: #
! 422: return OK if $r->header_only;
! 423: $r->print(&Apache::loncommon::bodytag('Error Messages'));
! 424: $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
! 425: my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
! 426: if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
! 427: my %brokenurls=&Apache::lonmsg::all_url_author_res_msg($author,
! 428: $domain);
! 429: foreach (sort keys %brokenurls) {
! 430: if ($_=~/^\Q$uri\E/) {
! 431: $r->print(&Apache::lonhtmlcommon::crumbs
! 432: (&Apache::lonnet::clutter($_)).
! 433: &Apache::lonmsg::retrieve_author_res_msg($_).
! 434: '<hr />');
1.64 matthew 435: }
436: }
1.66 ! matthew 437: } else {
! 438: $r->print(&mt('Not authorized'));
! 439: }
! 440: $r->print('</body></html>');
! 441: return;
! 442: }
! 443:
! 444: sub present_uneditable_metadata {
! 445: my ($r,$uri) = @_;
! 446: my ($resdomain,$resuser)=
! 447: (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
! 448: my $loaderror=&Apache::lonnet::overloaderror
! 449: ($r,
! 450: &Apache::lonnet::homeserver($resuser,$resdomain));
! 451: if ($loaderror) {
! 452: return $loaderror;
! 453: }
! 454: #
! 455: my %content=();
! 456: # Set document type
! 457: &Apache::loncommon::content_type($r,'text/html');
! 458: $r->send_http_header;
! 459: return OK if $r->header_only;
! 460: # Read file
! 461: foreach (split(/\,/,&Apache::lonnet::metadata($uri,'keys'))) {
! 462: $content{$_}=&Apache::lonnet::metadata($uri,$_);
! 463: }
! 464: # Render Output
! 465: # displayed url
! 466: my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
! 467: $uri=~s/\.meta$//;
! 468: my $disuri=&Apache::lonnet::clutter($uri);
! 469: # version
! 470: my $currentversion=&Apache::lonnet::getversion($disuri);
! 471: my $versiondisplay='';
! 472: if ($thisversion) {
! 473: $versiondisplay=&mt('Version').': '.$thisversion.
! 474: ' ('.&mt('most recent version').': '.
! 475: ($currentversion>0 ?
! 476: $currentversion :
! 477: &mt('information not available')).')';
! 478: } else {
! 479: $versiondisplay='Version: '.$currentversion;
! 480: }
! 481: # crumbify displayed URL
! 482: $disuri=&Apache::lonhtmlcommon::crumbs($disuri);
! 483: # obsolete
! 484: my $obsolete=$content{'obsolete'};
! 485: my $obsoletewarning='';
! 486: if (($obsolete) && ($ENV{'user.adv'})) {
! 487: $obsoletewarning='<p><font color="red">'.
! 488: &mt('This resource has been marked obsolete by the author(s)').
! 489: '</font></p>';
! 490: }
! 491: #
! 492: my %lt=&fieldnames();
! 493: my $table='';
! 494: my $bodytag=&Apache::loncommon::bodytag
! 495: ('Catalog Information','','','',$resdomain);
! 496: foreach ('title',
! 497: 'author',
! 498: 'subject',
! 499: 'keywords',
! 500: 'notes',
! 501: 'abstract',
! 502: 'lowestgradelevel',
! 503: 'highestgradelevel',
! 504: 'standards',
! 505: 'mime',
! 506: 'language',
! 507: 'creationdate',
! 508: 'lastrevisiondate',
! 509: 'owner',
! 510: 'copyright',
! 511: 'customdistributionfile',
! 512: 'obsolete',
! 513: 'obsoletereplacement') {
! 514: $table.='<tr><td bgcolor="#AAAAAA">'.$lt{$_}.
! 515: '</td><td bgcolor="#CCCCCC">'.
! 516: &prettyprint($_,$content{$_}).'</td></tr>';
! 517: delete $content{$_};
! 518: }
! 519: #
! 520: $r->print(<<ENDHEAD);
1.1 www 521: <html><head><title>Catalog Information</title></head>
1.17 www 522: $bodytag
1.1 www 523: <h2>$content{'title'}</h2>
1.11 www 524: <h3><tt>$disuri</tt></h3>
1.36 www 525: $obsoletewarning
1.21 www 526: $versiondisplay<br />
1.11 www 527: <table cellspacing=2 border=0>
1.45 www 528: $table
1.11 www 529: </table>
1.1 www 530: ENDHEAD
1.66 ! matthew 531: if ($ENV{'user.adv'}) {
! 532: # Dynamic Metadata
! 533: $r->print(
! 534: '<h3>'.&mt('Dynamic Metadata').' ('.
! 535: &mt('updated periodically').')</h3>'.&mt('Processing').
! 536: ' ...<br />');
! 537: $r->rflush();
! 538: my %items=&fieldnames();
! 539: my %dynmeta=&dynamicmeta($uri);
! 540: # General Access and Usage Statistics
! 541: $r->print('<h4>'.&mt('Access and Usage Statistics').'</h4>'.
! 542: '<table cellspacing=2 border=0>');
! 543: foreach ('count',
! 544: 'sequsage','sequsage_list',
! 545: 'comefrom','comefrom_list',
! 546: 'goto','goto_list',
! 547: 'course','course_list') {
! 548: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
! 549: '<td bgcolor="#CCCCCC">'.
! 550: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
! 551: }
! 552: $r->print('</table>');
! 553: if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
! 554: # This is an assessment, print assessment data
1.64 matthew 555: $r->print(
1.66 ! matthew 556: '<h4>'.&mt('Assessment Statistical Data').'</h4>'.
1.64 matthew 557: '<table cellspacing=2 border=0>');
1.66 ! matthew 558: foreach ('stdno','avetries','difficulty') {
1.64 matthew 559: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
560: '<td bgcolor="#CCCCCC">'.
561: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
562: }
1.66 ! matthew 563: $r->print('</table>');
! 564: }
! 565: $r->print('<h4>'.&mt('Evaluation Data').'</h4>'.
! 566: '<table cellspacing=2 border=0>');
! 567: foreach ('clear','depth','helpful','correct','technical') {
! 568: $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td>'.
! 569: '<td bgcolor="#CCCCCC">'.
! 570: &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
! 571: }
! 572: $r->print('</table>');
! 573: $uri=~/^\/res\/(\w+)\/(\w+)\//;
! 574: if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
! 575: || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
! 576: $r->print('<h4>'.&mt('Evaluation Comments').' ('.
! 577: &mt('visible to author and co-authors only').
! 578: ')</h4>'.
! 579: '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
! 580: $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
! 581: &mt('visible to author and co-authors only').')'.
! 582: '</h4>'.
! 583: &Apache::lonmsg::retrieve_author_res_msg($uri));
! 584: }
! 585: # All other stuff
! 586: $r->print('<h3>'.
! 587: &mt('Additional Metadata (non-standard, parameters, exports)').
! 588: '</h3>');
! 589: foreach (sort keys %content) {
! 590: my $name=$_;
! 591: if ($name!~/\.display$/) {
! 592: my $display=&Apache::lonnet::metadata($uri,
! 593: $name.'.display');
! 594: if (! $display) {
! 595: $display=$name;
! 596: };
! 597: my $otherinfo='';
! 598: foreach ('name','part','type','default') {
! 599: if (defined(&Apache::lonnet::metadata($uri,
! 600: $name.'.'.$_))) {
! 601: $otherinfo.=' '.$_.'='.
! 602: &Apache::lonnet::metadata($uri,
! 603: $name.'.'.$_).'; ';
! 604: }
1.64 matthew 605: }
1.66 ! matthew 606: $r->print('<b>'.$display.':</b> '.$content{$name});
! 607: if ($otherinfo) {
! 608: $r->print(' ('.$otherinfo.')');
1.64 matthew 609: }
1.66 ! matthew 610: $r->print("<br />\n");
1.64 matthew 611: }
612: }
1.66 ! matthew 613: }
! 614: }
! 615:
! 616: sub present_editable_metadata {
! 617: my ($r,$uri) = @_;
! 618: # Construction Space Call
! 619: # Set document type
! 620: &Apache::loncommon::content_type($r,'text/html');
! 621: $r->send_http_header;
! 622: #
! 623: return OK if $r->header_only;
! 624: # Header
! 625: my $disuri=$uri;
! 626: my $fn=&Apache::lonnet::filelocation('',$uri);
! 627: $disuri=~s/^\/\~/\/priv\//;
! 628: $disuri=~s/\.meta$//;
! 629: my $target=$uri;
! 630: $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
! 631: $target=~s/\.meta$//;
! 632: my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
! 633: if ($bombs) {
! 634: if ($ENV{'form.delmsg'}) {
! 635: if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
! 636: $bombs=&mt('Messages deleted.');
! 637: } else {
! 638: $bombs=&mt('Error deleting messages');
1.64 matthew 639: }
1.66 ! matthew 640: }
! 641: my $bodytag=&Apache::loncommon::bodytag('Error Messages');
! 642: my $del=&mt('Delete Messages');
! 643: $r->print(<<ENDBOMBS);
1.52 www 644: <html><head><title>Edit Catalog Information</title></head>
645: $bodytag
646: <h1>$disuri</h1>
647: <form method="post" name="defaultmeta">
1.59 www 648: <input type="submit" name="delmsg" value="$del" />
1.52 www 649: <br />$bombs
650: </form>
651: </body>
652: </html>
653: ENDBOMBS
1.66 ! matthew 654: } else {
! 655: my $displayfile='Catalog Information for '.$disuri;
! 656: if ($disuri=~/\/default$/) {
! 657: my $dir=$disuri;
! 658: $dir=~s/default$//;
! 659: $displayfile=
! 660: &mt('Default Cataloging Information for Directory').' '.
! 661: $dir;
! 662: }
! 663: my $bodytag=
! 664: &Apache::loncommon::bodytag('Edit Catalog Information');
! 665: %Apache::lonpublisher::metadatafields=();
! 666: %Apache::lonpublisher::metadatakeys=();
! 667: &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
! 668: $r->print(<<ENDEDIT);
1.23 www 669: <html><head><title>Edit Catalog Information</title></head>
670: $bodytag
671: <h1>$displayfile</h1>
1.48 www 672: <form method="post" name="defaultmeta">
1.23 www 673: ENDEDIT
1.66 ! matthew 674: $r->print('<script language="JavaScript">'.
! 675: &Apache::loncommon::browser_and_searcher_javascript.
! 676: '</script>');
! 677: my %lt=&fieldnames();
! 678: foreach ('author','title','subject','keywords','abstract','notes',
! 679: 'copyright','customdistributionfile','language',
! 680: 'standards',
! 681: 'lowestgradelevel','highestgradelevel',
! 682: 'obsolete','obsoletereplacement') {
! 683: if (defined($ENV{'form.new_'.$_})) {
! 684: $Apache::lonpublisher::metadatafields{$_}=
! 685: $ENV{'form.new_'.$_};
! 686: }
! 687: if (! $Apache::lonpublisher::metadatafields{'copyright'}) {
! 688: $Apache::lonpublisher::metadatafields{'copyright'}=
! 689: 'default';
1.64 matthew 690: }
1.66 ! matthew 691: $r->print('<p>'.$lt{$_}.': '.
! 692: &prettyinput
! 693: ($_,$Apache::lonpublisher::metadatafields{$_},
! 694: 'new_'.$_,'defaultmeta').'</p>');
! 695: }
! 696: if ($ENV{'form.store'}) {
! 697: my $mfh;
! 698: if (! ($mfh=Apache::File->new('>'.$fn))) {
! 699: $r->print('<p><font color=red>'.
! 700: &mt('Could not write metadata').', '.
! 701: &mt('FAIL').'</font>');
! 702: } else {
! 703: foreach (sort keys %Apache::lonpublisher::metadatafields) {
! 704: if ($_!~/\./) {
! 705: my $unikey=$_;
! 706: $unikey=~/^([A-Za-z]+)/;
! 707: my $tag=$1;
! 708: $tag=~tr/A-Z/a-z/;
! 709: print $mfh "\n\<$tag";
! 710: foreach (split(/\,/,
1.64 matthew 711: $Apache::lonpublisher::metadatakeys{$unikey})
1.66 ! matthew 712: ) {
! 713: my $value=
1.64 matthew 714: $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
1.66 ! matthew 715: $value=~s/\"/\'\'/g;
! 716: print $mfh ' '.$_.'="'.$value.'"';
1.64 matthew 717: }
1.66 ! matthew 718: print $mfh '>'.
! 719: &HTML::Entities::encode
! 720: ($Apache::lonpublisher::metadatafields{$unikey},
! 721: '<>&"').
! 722: '</'.$tag.'>';
1.64 matthew 723: }
724: }
1.66 ! matthew 725: $r->print('<p>'.&mt('Wrote Metadata'));
1.64 matthew 726: }
727: }
1.66 ! matthew 728: $r->print('<br /><input type="submit" name="store" value="'.
! 729: &mt('Store Catalog Information').'"></form>'.
! 730: '</body></html>');
1.64 matthew 731: }
1.66 ! matthew 732: return;
1.1 www 733: }
734:
1.64 matthew 735: # BEGIN Block
1.44 www 736: BEGIN {
1.64 matthew 737: # Get columns of MySQL metadata table
1.44 www 738: @columns=&Apache::lonmysql::col_order('metadata');
739: }
1.64 matthew 740:
1.1 www 741: 1;
742: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>