Diff for /loncom/interface/lonmeta.pm between versions 1.48 and 1.57

version 1.48, 2003/12/29 21:17:00 version 1.57, 2004/01/04 00:28:22
Line 37  use Apache::lonmsg; Line 37  use Apache::lonmsg;
 use Apache::lonpublisher;  use Apache::lonpublisher;
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonmysql;  use Apache::lonmysql;
   use Apache::lonmsg;
   
 # MySQL table columns  # MySQL table columns
   
Line 211  sub fieldnames { Line 212  sub fieldnames {
     return &Apache::lonlocal::texthash(      return &Apache::lonlocal::texthash(
    'title' => 'Title',     'title' => 'Title',
    'author' =>'Author(s)',     'author' =>'Author(s)',
      'authorspace' => 'Author Space',
      'modifyinguser' => 'Last Modifying User',
    'subject' => 'Subject',     'subject' => 'Subject',
    'keywords' => 'Keyword(s)',     'keywords' => 'Keyword(s)',
    'notes' => 'Notes',     'notes' => 'Notes',
Line 259  sub prettyprint { Line 262  sub prettyprint {
 # Dates  # Dates
     if (($type eq 'creationdate') ||      if (($type eq 'creationdate') ||
  ($type eq 'lastrevisiondate')) {   ($type eq 'lastrevisiondate')) {
  return &Apache::lonlocal::locallocaltime(   return ($value?&Apache::lonlocal::locallocaltime(
   &Apache::lonmysql::unsqltime($value));    &Apache::lonmysql::unsqltime($value)):
    &mt('not available'));
     }      }
 # Language  # Language
     if ($type eq 'language') {      if ($type eq 'language') {
Line 297  sub prettyprint { Line 301  sub prettyprint {
  ($type eq 'comefrom_list') ||   ($type eq 'comefrom_list') ||
  ($type eq 'sequsage_list')) {   ($type eq 'sequsage_list')) {
  return join('<br />',map {   return join('<br />',map {
        &Apache::lonnet::gettitle($_).' ['.         my $url=&Apache::lonnet::clutter($_);
        &Apache::lonhtmlcommon::crumbs(&Apache::lonnet::clutter($_),'preview').']';         '<br /><b>'.&Apache::lonnet::gettitle($url).'</b>'.
          &Apache::lonhtmlcommon::crumbs($url,'preview','');
     } split(/\s*\,\s*/,$value));      } split(/\s*\,\s*/,$value));
     }      }
 # Evaluations  # Evaluations
Line 327  sub prettyprint { Line 332  sub prettyprint {
 }  }
 # ============================================== Pretty input of metadata field  # ============================================== Pretty input of metadata field
   
   sub direct {
       return shift;
   }
   
 sub selectbox {  sub selectbox {
     my ($name,$value,$functionref,@idlist)=@_;      my ($name,$value,$functionref,@idlist)=@_;
       unless (defined($functionref)) { $functionref=\&direct; }
     my $selout='<select name="'.$name.'">';      my $selout='<select name="'.$name.'">';
     foreach (@idlist) {      foreach (@idlist) {
         $selout.='<option value=\''.$_.'\'';          $selout.='<option value=\''.$_.'\'';
Line 340  sub selectbox { Line 350  sub selectbox {
     return $selout.'</select>';      return $selout.'</select>';
 }  }
   
   sub relatedfield {
       my ($show,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue)=@_;
       unless ($relatedsearchflag) { return ''; }
       unless (defined($relatedsep)) { $relatedsep=' '; }
       unless ($show) { return $relatedsep.'&nbsp;'; }
       return $relatedsep.'<input type="checkbox" name="'.$fieldname.'_related"'.
    ($relatedvalue?' checked="1"':'').' />';
   }
   
 sub prettyinput {  sub prettyinput {
     my ($type,$value,$fieldname,$formname)=@_;      my ($type,$value,$fieldname,$formname,
    $relatedsearchflag,$relatedsep,$relatedvalue)=@_;
 # Language  # Language
     if ($type eq 'language') {      if ($type eq 'language') {
  return &selectbox($fieldname,   return &selectbox($fieldname,
   $value,    $value,
   \&Apache::loncommon::languagedescription,    \&Apache::loncommon::languagedescription,
   (&Apache::loncommon::languageids));    (&Apache::loncommon::languageids)).
          &relatedfield(0,$relatedsearchflag,$relatedsep);
     }      }
 # Copyright  # Copyright
     if ($type eq 'copyright') {      if ($type eq 'copyright') {
  return &selectbox($fieldname,   return &selectbox($fieldname,
   $value,    $value,
   \&Apache::loncommon::copyrightdescription,    \&Apache::loncommon::copyrightdescription,
   (&Apache::loncommon::copyrightids));    (&Apache::loncommon::copyrightids)).
          &relatedfield(0,$relatedsearchflag,$relatedsep);
     }      }
 # Gradelevels  # Gradelevels
     if (($type eq 'lowestgradelevel') ||      if (($type eq 'lowestgradelevel') ||
  ($type eq 'highestgradelevel')) {   ($type eq 'highestgradelevel')) {
  return &Apache::loncommon::select_level_form($value,$fieldname);   return &Apache::loncommon::select_level_form($value,$fieldname).
          &relatedfield(0,$relatedsearchflag,$relatedsep);
     }      }
 # Obsolete  # Obsolete
     if ($type eq 'obsolete') {      if ($type eq 'obsolete') {
  return '<input type="checkbox" name="'.$fieldname.'"'.   return '<input type="checkbox" name="'.$fieldname.'"'.
     ($value?' checked="1"':'').' />';       ($value?' checked="1"':'').' />'.
          &relatedfield(0,$relatedsearchflag,$relatedsep); 
     }      }
 # Obsolete replacement file  # Obsolete replacement file
     if ($type eq 'obsoletereplacement') {      if ($type eq 'obsoletereplacement') {
  return '<input type="text" name="'.$fieldname.   return '<input type="text" name="'.$fieldname.
     '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.      '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
     "('".$formname."','".$fieldname."'".      "('".$formname."','".$fieldname."'".
     ",'')\">".&mt('Select').'</a>';       ",'')\">".&mt('Select').'</a>'.
          &relatedfield(0,$relatedsearchflag,$relatedsep); 
    }     }
 # Customdistribution file  # Customdistribution file
     if ($type eq 'customdistributionfile') {      if ($type eq 'customdistributionfile') {
  return '<input type="text" name="'.$fieldname.   return '<input type="text" name="'.$fieldname.
     '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.      '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
     "('".$formname."','".$fieldname."'".      "('".$formname."','".$fieldname."'".
     ",'rights')\">".&mt('Select').'</a>';       ",'rights')\">".&mt('Select').'</a>'.
          &relatedfield(0,$relatedsearchflag,$relatedsep); 
     }      }
 # Dates  # Dates
     if (($type eq 'creationdate') ||      if (($type eq 'creationdate') ||
  ($type eq 'lastrevisiondate')) {   ($type eq 'lastrevisiondate')) {
  return &Apache::lonhtmlcommon::date_setter($formname,   return &Apache::lonhtmlcommon::date_setter($formname,
    $fieldname,$value);     $fieldname,$value).
          &relatedfield(0,$relatedsearchflag,$relatedsep);
     }      }
 # No pretty input found  # No pretty input found
     $value=~s/^\s+//gs;      $value=~s/^\s+//gs;
     $value=~s/\s+$//gs;      $value=~s/\s+$//gs;
     $value=~s/\s+/ /gs;      $value=~s/\s+/ /gs;
     $value=~s/\"/\&quod\;/gs;      $value=~s/\"/\&quod\;/gs;
     return '<input type="text" name="'.$fieldname.'" size="80" value="'.$value.'" />';       return 
       '<input type="text" name="'.$fieldname.'" size="80" value="'.$value.'" />'.
       &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue); 
 }  }
   
 # ================================================================ Main Handler  # ================================================================ Main Handler
Line 432  sub handler { Line 460  sub handler {
 # --------------------------------------------------------------- Render Output  # --------------------------------------------------------------- Render Output
 # displayed url  # displayed url
     my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);      my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
       $uri=~s/\.meta$//;
     my $disuri=&Apache::lonnet::clutter($uri);      my $disuri=&Apache::lonnet::clutter($uri);
     $disuri=~s/\.meta$//;  
     $disuri=&Apache::lonhtmlcommon::crumbs($disuri);  
 # version  # version
     my $currentversion=&Apache::lonnet::getversion($disuri);      my $currentversion=&Apache::lonnet::getversion($disuri);
     my $versiondisplay='';      my $versiondisplay='';
Line 445  sub handler { Line 472  sub handler {
     } else {      } else {
  $versiondisplay='Version: '.$currentversion;   $versiondisplay='Version: '.$currentversion;
     }      }
   # crumbify displayed URL
       $disuri=&Apache::lonhtmlcommon::crumbs($disuri);
 # obsolete  # obsolete
     my $obsolete=$content{'obsolete'};      my $obsolete=$content{'obsolete'};
     my $obsoletewarning='';      my $obsoletewarning='';
Line 462  sub handler { Line 491  sub handler {
      'subject',        'subject', 
      'keywords',        'keywords', 
      'notes',        'notes', 
      'abstract',        'abstract',
        'lowestgradelevel',
        'highestgradelevel',
        'standards', 
      'mime',        'mime', 
      'language',        'language', 
      'creationdate',        'creationdate', 
Line 525  ENDHEAD Line 557  ENDHEAD
     &prettyprint($dynmeta{$_})."</td></tr>\n");      &prettyprint($dynmeta{$_})."</td></tr>\n");
      }           }    
       $r->print('</table>');        $r->print('</table>');
       $disuri=~/^(\w+)\/(\w+)\//;           $uri=~/^\/res\/(\w+)\/(\w+)\//; 
       if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))        if ((($ENV{'user.domain'} eq $1) && ($ENV{'user.name'} eq $2))
   || ($ENV{'user.role.ca./'.$1.'/'.$2})) {    || ($ENV{'user.role.ca./'.$1.'/'.$2})) {
   $r->print(    $r->print('<h4>'.&mt('Evaluation Comments').' ('.
     '<h4>'.&mt('Evaluation Comments').' ('.&mt('visible to author and co-authors only').')</h4>'.      &mt('visible to author and co-authors only').')</h4>'.
     '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');      '<blockquote>'.$dynmeta{'comments'}.'</blockquote>');
   $r->print('<h4>'.&mt('Error Messages').' ('.    $r->print('<a name="bombs" /><h4>'.&mt('Error Messages').' ('.
     &mt('visible to author and co-authors only').')</h4>');      &mt('visible to author and co-authors only').')</h4>'.
   my %errormsgs=&Apache::lonnet::dump('nohist_res_msgs',$1,$2);      &Apache::lonmsg::retrieve_author_res_msg($uri));
   foreach (keys %errormsgs) {  
       if ($_=~/^\Q$disuri\E\_\d+$/) {  
   my %content=&Apache::lonmsg::unpackagemsg($errormsgs{$_});  
   $r->print('<b>'.$content{'time'}.'</b>: '.$content{'message'}.  
     '<br />');  
       }  
   }        
       }        }
 # ------------------------------------------------------------- All other stuff  # ------------------------------------------------------------- All other stuff
       $r->print(        $r->print(
Line 576  ENDHEAD Line 601  ENDHEAD
   
   return OK if $r->header_only;    return OK if $r->header_only;
 # ---------------------------------------------------------------------- Header  # ---------------------------------------------------------------------- Header
   my $bodytag=&Apache::loncommon::bodytag('Edit Catalog Information');  
   my $disuri=$uri;    my $disuri=$uri;
   my $fn=&Apache::lonnet::filelocation('',$uri);    my $fn=&Apache::lonnet::filelocation('',$uri);
   $disuri=~s/^\/\~\w+//;    $disuri=~s/^\/\~/\/priv\//;
   $disuri=~s/\.meta$//;    $disuri=~s/\.meta$//;
   my $displayfile='Catalog Information for '.$disuri;    my $target=$uri;
   if ($disuri=~/\/default$/) {    $target=~s/^\/\~/\/res\/$ENV{'request.role.domain'}\//;
       my $dir=$disuri;    $target=~s/\.meta$//;
       $dir=~s/default$//;    my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
       $displayfile=&mt('Default Cataloging Information for Directory').' '.    if ($bombs) {
   $dir;        if ($ENV{'form.delmsg'}) {
   }    if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
   %Apache::lonpublisher::metadatafields=();        $bombs=&mt('Messages deleted.');
   %Apache::lonpublisher::metadatakeys=();    } else {
   &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));        $bombs=&mt('Error deleting messages');
   $r->print(<<ENDEDIT);    }
         }
         my $bodytag=&Apache::loncommon::bodytag('Error Messages');
         my $del=&mt('Delete Messages');
         $r->print(<<ENDBOMBS);
   <html><head><title>Edit Catalog Information</title></head>
   $bodytag
   <h1>$disuri</h1>
   <form method="post" name="defaultmeta">
   <input type="submit" name="delmsg" value="$del" />
   <br />$bombs
   </form>
   </body>
   </html>
   ENDBOMBS
     } else {
         my $displayfile='Catalog Information for '.$disuri;
         if ($disuri=~/\/default$/) {
     my $dir=$disuri;
     $dir=~s/default$//;
     $displayfile=&mt('Default Cataloging Information for Directory').' '.
         $dir;
         }
         my $bodytag=&Apache::loncommon::bodytag('Edit Catalog Information');
         %Apache::lonpublisher::metadatafields=();
         %Apache::lonpublisher::metadatakeys=();
         &Apache::lonpublisher::metaeval(&Apache::lonnet::getfile($fn));
         $r->print(<<ENDEDIT);
 <html><head><title>Edit Catalog Information</title></head>  <html><head><title>Edit Catalog Information</title></head>
 $bodytag  $bodytag
 <h1>$displayfile</h1>  <h1>$displayfile</h1>
 <form method="post" name="defaultmeta">  <form method="post" name="defaultmeta">
 ENDEDIT  ENDEDIT
   $r->print('<script language="JavaScript">'.        $r->print('<script language="JavaScript">'.
     &Apache::loncommon::browser_and_searcher_javascript.   &Apache::loncommon::browser_and_searcher_javascript.
     '</script>');   '</script>');
    my %lt=&fieldnames();        my %lt=&fieldnames();
    foreach ('author','title','subject','keywords','abstract','notes',        foreach ('author','title','subject','keywords','abstract','notes',
             'copyright','customdistributionfile','language','standards',         'copyright','customdistributionfile','language','standards',
     'lowestgradelevel','highestgradelevel',         'lowestgradelevel','highestgradelevel',
             'obsolete','obsoletereplacement') {         'obsolete','obsoletereplacement') {
        $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};    if (defined($ENV{'form.new_'.$_})) {
        unless ($Apache::lonpublisher::metadatafields{'copyright'}) {        $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};
    $Apache::lonpublisher::metadatafields{'copyright'}='default';  
        }  
        $r->print('<p>'.$lt{$_}.': '.&prettyinput($_,  
   $Apache::lonpublisher::metadatafields{$_},  
   'new_'.$_,'defaultmeta').'</p>');  
    }  
    if ($ENV{'form.store'}) {  
       my $mfh;  
       unless ($mfh=Apache::File->new('>'.$fn)) {  
             $r->print(  
             '<p><font color=red>'.&mt('Could not write metadata').', '.  
       &mt('FAIL').'</font>');  
       } else {  
           foreach (sort keys %Apache::lonpublisher::metadatafields) {  
             unless ($_=~/\./) {  
                 my $unikey=$_;  
                 $unikey=~/^([A-Za-z]+)/;  
                 my $tag=$1;  
                 $tag=~tr/A-Z/a-z/;  
                 print $mfh "\n\<$tag";  
                 foreach   
                   (split(/\,/,$Apache::lonpublisher::metadatakeys{$unikey})) {  
                     my $value=  
                        $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};  
                     $value=~s/\"/\'\'/g;  
                     print $mfh ' '.$_.'="'.$value.'"';  
                 }  
                 print $mfh '>'.  
         &HTML::Entities::encode($Apache::lonpublisher::metadatafields{$unikey})  
                         .'</'.$tag.'>';  
             }  
   }    }
           $r->print('<p>'.&mt('Wrote Metadata'));    unless ($Apache::lonpublisher::metadatafields{'copyright'}) {
         $Apache::lonpublisher::metadatafields{'copyright'}='default';
     }
     $r->print('<p>'.$lt{$_}.': '.&prettyinput($_,
       $Apache::lonpublisher::metadatafields{$_},
       'new_'.$_,'defaultmeta').'</p>');
       }        }
     }        if ($ENV{'form.store'}) {
     $r->print(    my $mfh;
  '<br /><input type="submit" name="store" value="'.    unless ($mfh=Apache::File->new('>'.$fn)) {
 &mt('Store Catalog Information').'"></form></body></html>');        $r->print(
     return OK;   '<p><font color=red>'.&mt('Could not write metadata').', '.
    &mt('FAIL').'</font>');
     } else {
         foreach (sort keys %Apache::lonpublisher::metadatafields) {
     unless ($_=~/\./) {
         my $unikey=$_;
         $unikey=~/^([A-Za-z]+)/;
         my $tag=$1;
         $tag=~tr/A-Z/a-z/;
         print $mfh "\n\<$tag";
         foreach 
     (split(/\,/,$Apache::lonpublisher::metadatakeys{$unikey})) {
         my $value=
     $Apache::lonpublisher::metadatafields{$unikey.'.'.$_};
         $value=~s/\"/\'\'/g;
         print $mfh ' '.$_.'="'.$value.'"';
     }
         print $mfh '>'.
     &HTML::Entities::encode($Apache::lonpublisher::metadatafields{$unikey})
     .'</'.$tag.'>';
     }
         }
         $r->print('<p>'.&mt('Wrote Metadata'));
     }
         }
         $r->print(
    '<br /><input type="submit" name="store" value="'.
    &mt('Store Catalog Information').'"></form></body></html>');
   }    }
       return OK;
    }
 }  }
   
 # ================================================================= BEGIN Block  # ================================================================= BEGIN Block

Removed from v.1.48  
changed lines
  Added in v.1.57


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>