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