Diff for /loncom/interface/lonmeta.pm between versions 1.98 and 1.118

version 1.98, 2005/07/08 10:39:49 version 1.118, 2005/10/25 18:47:49
Line 17 Line 17
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.  # GNU General Public License for more details.
 #  #
 # You should have received a copy of the GNU General Public License  # You should have received a copy of the GNU General Public License 
 # along with LON-CAPA; if not, write to the Free Software  # along with LON-CAPA; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #  #
Line 33  use LONCAPA::lonmetadata(); Line 33  use LONCAPA::lonmetadata();
 use Apache::Constants qw(:common);  use Apache::Constants qw(:common);
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonhtmlcommon();  use Apache::lonhtmlcommon(); 
 use Apache::lonmsg;  use Apache::lonmsg;
 use Apache::lonpublisher;  use Apache::lonpublisher;
 use Apache::lonlocal;  use Apache::lonlocal;
Line 288  sub fieldnames { Line 288  sub fieldnames {
     return &Apache::lonlocal::texthash(%fields);      return &Apache::lonlocal::texthash(%fields);
 }  }
   
   sub select_course {
       my ($r)=@_;
       my %courses;
       foreach my $key (keys (%env)) { 
           if ($key =~ m/\.metadata\./) {
               $key =~ m/^course\.(.+)(\.metadata.+$)/;
               my $course = $1;
               my $coursekey = 'course.'.$course.'.description';
               my $value = $env{$coursekey};
               $courses{$coursekey} = $value;
           }
       }
       $r->print('<h3>Course Related Meta-Data</h3><br />');
       $r->print('<form action="" method="post">');
       $r->print('Select your test course<br />');
       $r->print('<select name="metacourse" >');
       my $meta_not_found = 1;
       foreach my $key (keys (%courses)) {    
           if ($meta_not_found) {
               undef($meta_not_found);
               $r->print('<h3>Portfolio Meta-Data</h3><br />');
               $r->print('<form action="" method="post">');
               $r->print('Select your course<br />');
               $r->print('<select name="metacourse" >');
           }
           $r->print('<option value="'.$key.'">');
           $r->print($courses{$key});
           $r->print('</option>');
       }
       unless ($meta_not_found) {
           $r->print('</select><br />');
           $r->print('<input type="submit" value="Assign Portfolio Metadata" />');
           $r->print('</form>');
       }
       return 'ok';
   }
 # Pretty printing of metadata field  # Pretty printing of metadata field
   
 sub prettyprint {  sub prettyprint {
Line 440  sub relatedfield { Line 476  sub relatedfield {
   
 sub prettyinput {  sub prettyinput {
     my ($type,$value,$fieldname,$formname,      my ($type,$value,$fieldname,$formname,
  $relatedsearchflag,$relatedsep,$relatedvalue,$size)=@_;   $relatedsearchflag,$relatedsep,$relatedvalue,$size,$course_key)=@_;
     if (! defined($size)) {      if (! defined($size)) {
         $size = 80;          $size = 80;
     }      }
       if (defined($course_key)) {
           my $stu_add;
           my $only_one;
           if ($env{$course_key.'.metadata.'.$_.'.options'} =~ m/stuadd/) {
               $stu_add = 'true';
           }
           if ($env{$course_key.'.metadata.'.$_.'.options'} =~ m/onlyone/) {
               $only_one = 'true';
           }
           if ($type eq 'author') {
           }
           if ($type eq 'authorspace') {
           }
           if ($type eq 'modifyinguser') {
           }
           if ($type eq 'subject') {
           }
           if ($type eq 'keywords') {
           }
           if ($type eq  'notes') {
           }
           if ($type eq  'abstract') {
    }
           if (($type eq 'lowestgradelevel') ||
       ($type eq 'highestgradelevel')) {
       return &Apache::loncommon::select_level_form($value,$fieldname).
               &relatedfield(0,$relatedsearchflag,$relatedsep); 
           }
           return(); 
       }
     # Language      # Language
     if ($type eq 'language') {      if ($type eq 'language') {
  return &selectbox($fieldname,   return &selectbox($fieldname,
Line 545  sub handler { Line 611  sub handler {
         # Looking for all bombs?          # Looking for all bombs?
         &report_bombs($r,$uri);          &report_bombs($r,$uri);
     } elsif ($uri=~/\/portfolio\//) {      } elsif ($uri=~/\/portfolio\//) {
    ($resdomain,$resuser)=
       (&Apache::lonnet::declutter($uri)=~m|^(\w+)/(\w+)/portfolio|);
         $r->print(&Apache::loncommon::bodytag          $r->print(&Apache::loncommon::bodytag
           ('Edit Portfolio File Information','','','',$resdomain));            ('Edit Portfolio File Information','','','',$resdomain));
         &present_editable_metadata($r,$uri,'portfolio');          &present_editable_metadata($r,$uri,'portfolio');
                   &select_course($r);
     } elsif ($uri=~/^\/\~/) {       } elsif ($uri=~/^\/\~/) { 
         # Construction space          # Construction space
         $r->print(&Apache::loncommon::bodytag          $r->print(&Apache::loncommon::bodytag
Line 883  sub print_dynamic_metadata { Line 951  sub print_dynamic_metadata {
     return;      return;
 }  }
   
   
   
 #####################################################  #####################################################
 #####################################################  #####################################################
 ###                                               ###  ###                                               ###
Line 898  sub present_editable_metadata { Line 968  sub present_editable_metadata {
     my $fn=&Apache::lonnet::filelocation('',$uri);      my $fn=&Apache::lonnet::filelocation('',$uri);
     $disuri=~s/^\/\~/\/priv\//;      $disuri=~s/^\/\~/\/priv\//;
     $disuri=~s/\.meta$//;      $disuri=~s/\.meta$//;
       $disuri=~s|^/editupload||;
     my $target=$uri;      my $target=$uri;
     $target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;      $target=~s/^\/\~/\/res\/$env{'request.role.domain'}\//;
     $target=~s/\.meta$//;      $target=~s/\.meta$//;
     my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);      my $bombs=&Apache::lonmsg::retrieve_author_res_msg($target);
     if ($bombs) {      if ($bombs) {
           my $showdel=1;
         if ($env{'form.delmsg'}) {          if ($env{'form.delmsg'}) {
             if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {              if (&Apache::lonmsg::del_url_author_res_msg($target) eq 'ok') {
                 $bombs=&mt('Messages deleted.');                  $bombs=&mt('Messages deleted.');
    $showdel=0;
             } else {              } else {
                 $bombs=&mt('Error deleting messages');                  $bombs=&mt('Error deleting messages');
             }              }
Line 915  sub present_editable_metadata { Line 988  sub present_editable_metadata {
     $cleardir=~s/\/[^\/]+$/\//;      $cleardir=~s/\/[^\/]+$/\//;
             if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {              if (&Apache::lonmsg::clear_author_res_msg($cleardir) eq 'ok') {
                 $bombs=&mt('Messages cleared.');                  $bombs=&mt('Messages cleared.');
    $showdel=0;
             } else {              } else {
                 $bombs=&mt('Error clearing messages');                  $bombs=&mt('Error clearing messages');
             }              }
         }          }
         my $del=&mt('Delete Messages for this Resource');          my $del=&mt('Delete Messages for this Resource');
  my $clear=&mt('Clear all Messages in Subdirectory');   my $clear=&mt('Clear all Messages in Subdirectory');
    my $goback=&mt('Back to Source File');
         $r->print(<<ENDBOMBS);          $r->print(<<ENDBOMBS);
 <h1>$disuri</h1>  <h1>$disuri</h1>
 <form method="post" name="defaultmeta">  <form method="post" name="defaultmeta">
   ENDBOMBS
           if ($showdel) {
       $r->print(<<ENDDEL);
 <input type="submit" name="delmsg" value="$del" />  <input type="submit" name="delmsg" value="$del" />
 <input type="submit" name="clearmsg" value="$clear" />  <input type="submit" name="clearmsg" value="$clear" />
 <br />$bombs  ENDDEL
 ENDBOMBS          } else {
               $r->print('<a href="'.$disuri.'" />'.$goback.'</a>');
    }
    $r->print('<br />'.$bombs);
     } else {      } else {
         my $displayfile='Catalog Information for '.$disuri;          my $displayfile='Catalog Information for '.$disuri;
         if ($disuri=~/\/default$/) {          if ($disuri=~/\/default$/) {
Line 941  ENDBOMBS Line 1022  ENDBOMBS
         %Apache::lonpublisher::metadatakeys=();          %Apache::lonpublisher::metadatakeys=();
         my $result=&Apache::lonnet::getfile($fn);          my $result=&Apache::lonnet::getfile($fn);
         if ($result == -1){          if ($result == -1){
             $r->print('Creating new '.$fn);              $r->print('Creating new '.$disuri);
         } else {          } else {
             &Apache::lonpublisher::metaeval($result);              &Apache::lonpublisher::metaeval($result);
         }          }
Line 974  ENDEDIT Line 1055  ENDEDIT
                 $Apache::lonpublisher::metadatafields{'copyright'}=                  $Apache::lonpublisher::metadatafields{'copyright'}=
                     'default';                      'default';
             }              }
             $output.=('<p>'.$lt{$_}.': '.              if ($env{'form.metacourse'}) {
                       &prettyinput($_,                  # handle restrictions here
                   $env{'form.metacourse'} =~ m/(^.+)\.description$/;
                   my $key_base = $1;
                   if ($env{$key_base.'.metadata.'.$_.'.options'} =~ m/active/) {
                       $output.=('<p>'.$lt{$_}.': '.
                               &prettyinput($_,
      $Apache::lonpublisher::metadatafields{$_},
      'new_'.$_,'defaultmeta',undef,undef,undef,undef,$key_base).'</p>');
                   }
               } else {
                   $output.=('<p>'.$lt{$_}.': '.
                               &prettyinput($_,
    $Apache::lonpublisher::metadatafields{$_},     $Apache::lonpublisher::metadatafields{$_},
    'new_'.$_,'defaultmeta').'</p>');     'new_'.$_,'defaultmeta').'</p>');
               }
         }          }
         if ($env{'form.store'}) {          if ($env{'form.store'}) {
             my $mfh;              my $mfh;
             my $formname='store';              my $formname='store'; 
             my $file_content;              my $file_content;
               foreach my $meta_field (keys %env) {
                   if (&Apache::loncommon::get_env_multiple('form.keywords')) {
                   $Apache::lonpublisher::metadatafields{'coursekeyword'} = 
                           join (', ', &Apache::loncommon::get_env_multiple('form.keywords'));
                   }
               }
             foreach (sort keys %Apache::lonpublisher::metadatafields) {              foreach (sort keys %Apache::lonpublisher::metadatafields) {
                 next if ($_ =~ /\./);                  next if ($_ =~ /\./);
                 my $unikey=$_;                  my $unikey=$_;
Line 1012  ENDEDIT Line 1111  ENDEDIT
                 $env{'form.'.$formname.'.filename'}=$new_fn;                  $env{'form.'.$formname.'.filename'}=$new_fn;
                 &Apache::lonnet::userfileupload('uploaddoc','',                  &Apache::lonnet::userfileupload('uploaddoc','',
          'portfolio'.$env{'form.currentpath'});           'portfolio'.$env{'form.currentpath'});
         my $status =&Apache::lonnet::userfileupload($formname,'','portfolio');  
                 if (&Apache::lonnet::userfileupload($formname,'','portfolio') eq 'error: no uploaded file') {                  if (&Apache::lonnet::userfileupload($formname,'','portfolio') eq 'error: no uploaded file') {
                     $r->print('<p><font color="red">'.                      $r->print('<p><font color="red">'.
                       &mt('Could not write metadata').', '.                        &mt('Could not write metadata').', '.

Removed from v.1.98  
changed lines
  Added in v.1.118


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