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

version 1.47, 2003/12/29 19:01:27 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 283  sub prettyprint { Line 287  sub prettyprint {
  $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;   $value=~s/(\w+)(\:|\@)(\w+)/&authordisplay($1,$3)/gse;
  return $value;   return $value;
     }      }
   # Gradelevel
       if (($type eq 'lowestgradelevel') ||
    ($type eq 'highestgradelevel')) {
    return &Apache::loncommon::gradeleveldescription($value);
       }
 # Only for advance users below  # Only for advance users below
     unless ($ENV{'user.adv'}) { return '<i>- '.&mt('not displayed').' -</i>' };      unless ($ENV{'user.adv'}) { return '<i>- '.&mt('not displayed').' -</i>' };
 # File  # File
Line 292  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 322  sub prettyprint { Line 332  sub prettyprint {
 }  }
 # ============================================== Pretty input of metadata field  # ============================================== Pretty input of metadata field
   
   sub direct {
       return shift;
   }
   
   sub selectbox {
       my ($name,$value,$functionref,@idlist)=@_;
       unless (defined($functionref)) { $functionref=\&direct; }
       my $selout='<select name="'.$name.'">';
       foreach (@idlist) {
           $selout.='<option value=\''.$_.'\'';
           if ($_ eq $value) {
       $selout.=' selected>'.&{$functionref}($_).'</option>';
    }
           else {$selout.='>'.&{$functionref}($_).'</option>';}
       }
       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)=@_;      my ($type,$value,$fieldname,$formname,
    $relatedsearchflag,$relatedsep,$relatedvalue)=@_;
   # Language
       if ($type eq 'language') {
    return &selectbox($fieldname,
     $value,
     \&Apache::loncommon::languagedescription,
     (&Apache::loncommon::languageids)).
          &relatedfield(0,$relatedsearchflag,$relatedsep);
       }
   # Copyright
       if ($type eq 'copyright') {
    return &selectbox($fieldname,
     $value,
     \&Apache::loncommon::copyrightdescription,
     (&Apache::loncommon::copyrightids)).
          &relatedfield(0,$relatedsearchflag,$relatedsep);
       }
   # Gradelevels
       if (($type eq 'lowestgradelevel') ||
    ($type eq 'highestgradelevel')) {
    return &Apache::loncommon::select_level_form($value,$fieldname).
          &relatedfield(0,$relatedsearchflag,$relatedsep);
       }
   # Obsolete
       if ($type eq 'obsolete') {
    return '<input type="checkbox" name="'.$fieldname.'"'.
       ($value?' checked="1"':'').' />'.
          &relatedfield(0,$relatedsearchflag,$relatedsep); 
       }
   # Obsolete replacement file
       if ($type eq 'obsoletereplacement') {
    return '<input type="text" name="'.$fieldname.
       '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
       "('".$formname."','".$fieldname."'".
       ",'')\">".&mt('Select').'</a>'.
          &relatedfield(0,$relatedsearchflag,$relatedsep); 
      }
   # Customdistribution file
       if ($type eq 'customdistributionfile') {
    return '<input type="text" name="'.$fieldname.
       '" size="60" value="'.$value.'" /><a href="javascript:openbrowser'.
       "('".$formname."','".$fieldname."'".
       ",'rights')\">".&mt('Select').'</a>'.
          &relatedfield(0,$relatedsearchflag,$relatedsep); 
       }
   # Dates
       if (($type eq 'creationdate') ||
    ($type eq 'lastrevisiondate')) {
    return &Apache::lonhtmlcommon::date_setter($formname,
      $fieldname,$value).
          &relatedfield(0,$relatedsearchflag,$relatedsep);
       }
   # No pretty input found
       $value=~s/^\s+//gs;
       $value=~s/\s+$//gs;
       $value=~s/\s+/ /gs;
       $value=~s/\"/\&quod\;/gs;
       return 
       '<input type="text" name="'.$fieldname.'" size="80" value="'.$value.'" />'.
       &relatedfield(1,$relatedsearchflag,$relatedsep,$fieldname,$relatedvalue); 
 }  }
   
 # ================================================================ Main Handler  # ================================================================ Main Handler
Line 363  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 376  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 393  sub handler { Line 491  sub handler {
      'subject',        'subject', 
      'keywords',        'keywords', 
      'notes',        'notes', 
      'abstract',        'abstract',
        'lowestgradelevel',
        'highestgradelevel',
        'standards', 
      'mime',        'mime', 
      'language',        'language', 
      'creationdate',        'creationdate', 
Line 456  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 507  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">  <form method="post" name="defaultmeta">
 ENDEDIT  ENDEDIT
    my %lt=&fieldnames();        $r->print('<script language="JavaScript">'.
    foreach ('author','title','subject','keywords','abstract','notes',   &Apache::loncommon::browser_and_searcher_javascript.
             'copyright','customdistributionfile','language',   '</script>');
             'obsolete','obsoletereplacement') {        my %lt=&fieldnames();
        if ($ENV{'form.new_'.$_}) {        foreach ('author','title','subject','keywords','abstract','notes',
    $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};         'copyright','customdistributionfile','language','standards',
        }         'lowestgradelevel','highestgradelevel',
        if (m/copyright/) {         'obsolete','obsoletereplacement') {
    $r->print(&Apache::lonpublisher::selectbox($lt{$_},'new_'.$_,    if (defined($ENV{'form.new_'.$_})) {
        ($Apache::lonpublisher::metadatafields{$_}?        $Apache::lonpublisher::metadatafields{$_}=$ENV{'form.new_'.$_};
  $Apache::lonpublisher::metadatafields{$_}:'default'),    }
        \&Apache::loncommon::copyrightdescription,    unless ($Apache::lonpublisher::metadatafields{'copyright'}) {
        (&Apache::loncommon::copyrightids)));        $Apache::lonpublisher::metadatafields{'copyright'}='default';
        } elsif (m/language/) {  
    $r->print(&Apache::lonpublisher::selectbox($lt{$_},'new_'.$_,  
       $Apache::lonpublisher::metadatafields{$_},  
       \&Apache::loncommon::languagedescription,  
       (&Apache::loncommon::languageids)));  
        } else {  
    $r->print(&Apache::lonpublisher::textfield($lt{$_},'new_'.$_,  
      $Apache::lonpublisher::metadatafields{$_}));  
        }  
    }  
    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'));    $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.47  
changed lines
  Added in v.1.57


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