Diff for /loncom/interface/lonmeta.pm between versions 1.50 and 1.61

version 1.50, 2003/12/30 20:39:30 version 1.61, 2004/03/31 05:24:00
Line 212  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 260  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 298  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 328  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 341  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 407  sub handler { Line 434  sub handler {
   
     my $uri=$r->uri;      my $uri=$r->uri;
   
   unless ($uri=~/^\/\~/) {   # ====================================================== Looking for all bombs?
     if ($uri=~/\/adm\/bombs\/(.*)$/) {
   # ----------------------------------------------------------- Set document type
         $uri=&Apache::lonnet::declutter($1);
         &Apache::loncommon::content_type($r,'text/html');
         $r->send_http_header;
         
         return OK if $r->header_only;
         $r->print(&Apache::loncommon::bodytag('Error Messages'));
         $r->print('<h1>'.&Apache::lonnet::clutter($uri).'</h1>');
         my ($domain,$author)=($uri=~/^(\w+)\/(\w+)\//);
         if (&Apache::loncacc::constructaccess('/~'.$author.'/',$domain)) {
     my %brokenurls=&Apache::lonmsg::all_url_author_res_msg($author,$domain);
     foreach (sort keys %brokenurls) {
         if ($_=~/^\Q$uri\E/) {
     $r->print(&Apache::lonhtmlcommon::crumbs(&Apache::lonnet::clutter($_)).
       &Apache::lonmsg::retrieve_author_res_msg($_).'<hr />');
         }
     }
         } else {
     $r->print(&mt('Not authorized'));
         }
         $r->print('</body></html>');
     } elsif ($uri!~/^\/\~/) { 
 # =========================================== This is not in construction space  # =========================================== This is not in construction space
     my ($resdomain,$resuser)=      my ($resdomain,$resuser)=
            (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);             (&Apache::lonnet::declutter($uri)=~/^(\w+)\/(\w+)\//);
Line 435  sub handler { Line 485  sub handler {
     my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);      my ($thisversion)=($uri=~/\.(\d+)\.(\w+)\.meta$/);
     $uri=~s/\.meta$//;      $uri=~s/\.meta$//;
     my $disuri=&Apache::lonnet::clutter($uri);      my $disuri=&Apache::lonnet::clutter($uri);
     $disuri=&Apache::lonhtmlcommon::crumbs($disuri);  
 # version  # version
     my $currentversion=&Apache::lonnet::getversion($disuri);      my $currentversion=&Apache::lonnet::getversion($disuri);
     my $versiondisplay='';      my $versiondisplay='';
Line 446  sub handler { Line 495  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 463  sub handler { Line 514  sub handler {
      'subject',        'subject', 
      'keywords',        'keywords', 
      'notes',        'notes', 
      'abstract',        'abstract',
        'lowestgradelevel',
        'highestgradelevel',
        'standards', 
      'mime',        'mime', 
      'language',        'language', 
      'creationdate',        'creationdate', 
Line 507  ENDHEAD Line 561  ENDHEAD
        'goto','goto_list',         'goto','goto_list',
        'course','course_list') {         'course','course_list') {
   $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td><td bgcolor="#CCCCCC">'.    $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td><td bgcolor="#CCCCCC">'.
     &prettyprint($dynmeta{$_})."</td></tr>\n");      &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
       }        }
       $r->print('</table>');        $r->print('</table>');
       if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {        if ($uri=~/\.(problem|exam|quiz|assess|survey|form)\.meta$/) {
Line 516  ENDHEAD Line 570  ENDHEAD
     '<h4>'.&mt('Assessment Statistical Data').'</h4><table cellspacing=2 border=0>');      '<h4>'.&mt('Assessment Statistical Data').'</h4><table cellspacing=2 border=0>');
   foreach ('stdno','avetries','difficulty') {    foreach ('stdno','avetries','difficulty') {
       $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td><td bgcolor="#CCCCCC">'.        $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td><td bgcolor="#CCCCCC">'.
  &prettyprint($dynmeta{$_})."</td></tr>\n");   &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
   }    }
   $r->print('</table>');        $r->print('</table>');    
       }        }
       $r->print('<h4>'.&mt('Evaluation Data').'</h4><table cellspacing=2 border=0>');        $r->print('<h4>'.&mt('Evaluation Data').'</h4><table cellspacing=2 border=0>');
       foreach ('clear','depth','helpful','correct','technical') {        foreach ('clear','depth','helpful','correct','technical') {
   $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td><td bgcolor="#CCCCCC">'.    $r->print('<tr><td bgcolor="#AAAAAA">'.$lt{$_}.'</td><td bgcolor="#CCCCCC">'.
     &prettyprint($dynmeta{$_})."</td></tr>\n");      &prettyprint($_,$dynmeta{$_})."</td></tr>\n");
      }           }    
       $r->print('</table>');        $r->print('</table>');
       $uri=~/^\/res\/(\w+)\/(\w+)\//;         $uri=~/^\/res\/(\w+)\/(\w+)\//; 
Line 532  ENDHEAD Line 586  ENDHEAD
   $r->print('<h4>'.&mt('Evaluation Comments').' ('.    $r->print('<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>'.
     &Apache::lonmsg::retrieve_author_res_msg($2,$1,$uri));      &Apache::lonmsg::retrieve_author_res_msg($uri));
       }        }
 # ------------------------------------------------------------- All other stuff  # ------------------------------------------------------------- All other stuff
       $r->print(        $r->print(
Line 570  ENDHEAD Line 624  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';    }
        }    unless ($Apache::lonpublisher::metadatafields{'copyright'}) {
        $r->print('<p>'.$lt{$_}.': '.&prettyinput($_,        $Apache::lonpublisher::metadatafields{'copyright'}='default';
   $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'));    $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.50  
changed lines
  Added in v.1.61


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