Diff for /rat/lonsequence.pm between versions 1.26 and 1.39

version 1.26, 2006/04/04 15:32:12 version 1.39, 2009/05/16 23:21:12
Line 26 Line 26
 #  #
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
 # (Handler to resolve ambiguous file locations  
 #  
   
 package Apache::lonsequence;  package Apache::lonsequence;
   
Line 35  use strict; Line 35  use strict;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::Constants qw(:common :http REDIRECT);  use Apache::Constants qw(:common :http REDIRECT);
 use GDBM_File;  use GDBM_File;
 use Apache::lonratedt;  use LONCAPA::map();
 use Apache::lonratsrv;  use Apache::lonpageflip();
 use Apache::lonpageflip;  use Apache::loncommon();
 use Apache::loncommon;  use Apache::groupsort();
 use Apache::lonlocal;  use Apache::lonlocal;
   use HTML::Entities();
   
 my %selhash;  my %selhash;
 my $successtied;  my $successtied;
Line 47  my $successtied; Line 48  my $successtied;
 # ----------------------------------------- Attempt to read from resource space  # ----------------------------------------- Attempt to read from resource space
   
 sub attemptread {  sub attemptread {
     my $fn=shift;      my ($fn,$unsorted)=@_;
     &Apache::lonnet::repcopy($fn);      &Apache::lonnet::repcopy($fn);
     if (-e $fn) {      if (-e $fn) {
  return &Apache::lonratedt::attemptread($fn);   return &LONCAPA::map::attemptread($fn,$unsorted);
     } else {      } else {
         return ();          return ();
     }      }
Line 60  sub mapread { Line 61  sub mapread {
     my $fn=shift;      my $fn=shift;
     &Apache::lonnet::repcopy($fn);      &Apache::lonnet::repcopy($fn);
     if (-e $fn) {      if (-e $fn) {
  return &Apache::lonratedt::mapread($fn,'');   return &LONCAPA::map::mapread($fn,'');
     } else {      } else {
         return ();          return ();
     }      }
Line 101  ENDSCRIPT Line 102  ENDSCRIPT
       '<h1>'.$url.'</h1>');        '<h1>'.$url.'</h1>');
 # ------------------ This is trying to select. Provide buttons and tie %selhash  # ------------------ This is trying to select. Provide buttons and tie %selhash
     if ($env{'form.forceselect'}) { $r->print(<<ENDSELECT);      if ($env{'form.forceselect'}) { $r->print(<<ENDSELECT);
 <form name=fileattr><input type=hidden name=acts value=''>  <form name="fileattr"><input type="hidden" name="acts" value="" />
 <input type="button" name="close" value='CLOSE' onClick="self.close()">  <input type="button" name="close" value="CLOSE" onClick="self.close()" />
 <input type="button" name="groupimport" value='GROUP IMPORT'  <input type="button" name="groupimport" value="GROUP IMPORT"
 onClick="javascript:select_group()">  onClick="javascript:select_group()" />
 </form>     </form>   
 ENDSELECT  ENDSELECT
     my $diropendb =       my $diropendb = 
     "/home/httpd/perl/tmp/$env{'user.domain'}\_$env{'user.name'}_groupsec.db";      "/home/httpd/perl/tmp/$env{'user.domain'}\_$env{'user.name'}_sel_res.db";
         if (tie(%selhash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {          if (tie(%selhash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
     if ($env{'form.launch'} eq '1') {      if ($env{'form.launch'} eq '1') {
        &start_fresh_session();         &start_fresh_session();
Line 116  ENDSELECT Line 117  ENDSELECT
             $successtied=1;              $successtied=1;
   
 # - Evaluate actions from previous page (both cumulatively and chronologically)  # - Evaluate actions from previous page (both cumulatively and chronologically)
         if ($env{'form.catalogmode'} eq 'groupimport') {      if ($env{'form.catalogmode'} eq 'import') {
     my $acts=$env{'form.acts'};   &Apache::groupsort::update_actions_hash(\%selhash);
     my @Acts=split(/b/,$acts);  
     my %ahash;  
     my %achash;  
     my $ac=0;  
     # some initial hashes for working with data  
     foreach (@Acts) {  
  my ($state,$ref)=split(/a/);  
  $ahash{$ref}=$state;  
  $achash{$ref}=$ac;  
  $ac++;  
     }  
     # sorting through the actions and changing the tied database hash  
     foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {  
  my $key=$_;  
  if ($ahash{$key} eq '1') {  
     $selhash{'store_'.$selhash{'pre_'.$key.'_link'}}=  
  $selhash{'pre_'.$key.'_title'};  
     $selhash{'storectr_'.$selhash{'pre_'.$key.'_link'}}=  
  $selhash{'storectr'}+0;  
     $selhash{'storectr'}++;  
  }  
  if ($ahash{$key} eq '0') {  
     if ($selhash{'store_'.$selhash{'pre_'.$key.'_link'}}) {  
        delete $selhash{'store_'.$selhash{'pre_'.$key.'_link'}};  
     }  
  }  
     }  
     # deleting the previously cached listing  
     foreach (keys %selhash) {  
  if ($_ =~ /^pre_/ && $_ =~/link$/) {  
     my $key = $_;  
     $key =~ s/^pre_//;  
     $key =~ s/_[^_]*$//;  
     delete $selhash{'pre_'.$key.'_title'};  
     delete $selhash{'pre_'.$key.'_link'};  
  }  
     }      }
  }  
 # -  # -
         }          }
     }      }
 # ----------------------------- successtied is now '1' if in working selectmode  # ----------------------------- successtied is now '1' if in working selectmode
     my ($errtext,$fatal)=&mapread(&Apache::lonnet::filelocation('',$url),'');      my ($errtext,$fatal)=&mapread(&Apache::lonnet::filelocation('',$url),'');
     if ($fatal==1) {      if ($fatal==1) {
        $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');         $r->print('<p class="LC_warning">'
                   .&mt('Map contents are not shown in order.')
                   .'</p><br />');
     }      }
     my $idx=0;      my $idx=0;
     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {      foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
Line 172  ENDSELECT Line 138  ENDSELECT
  $r->print('<form name="form'.$idx.'">');   $r->print('<form name="form'.$idx.'">');
             }              }
     my ($title,$url)=split(/\:/,$_);      my ($title,$url)=split(/\:/,$_);
             $title=~s/\&colon\;/\:/g;      $title = &LONCAPA::map::qtescape($title);
             $url=~s/\&colon\;/\:/g;      unless ($title) { $title=(split(/\//,$url))[-1] };
             unless ($title) { $title=(split(/\//,$url))[-1] };              my $enc_title = &HTML::Entities::encode($title,'\'"<>&');
             unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }      unless ($title) {
    $title='<i>'.&mt('Empty').'</i>';
    $enc_title = &mt('Empty');
       }
       $url  = &LONCAPA::map::qtescape($url);
               my $enc_url = &HTML::Entities::encode($url,'\'"<>&');
             if ($url) {              if ($url) {
  if ($successtied) {   if ($successtied) {
     my $checked='';      my $checked='';
            if ($selhash{'store_'.$url}) {             if ($selhash{'store_'.$url}) {
             $checked=" checked";              $checked=' checked="checked"';
            }             }
            $selhash{"pre_${idx}_link"}=$url;             $selhash{"pre_${idx}_link"}=$url;
            $selhash{"pre_${idx}_title"}=$title;             $selhash{"pre_${idx}_title"}=$title;
       
       $url  = &HTML::Entities::encode($url, '\'"<>&');
     $r->print(<<ENDCHECKBOX);      $r->print(<<ENDCHECKBOX);
 <input type='checkbox' name='filelink'   <input type='checkbox' name='filelink' 
 value='$url' onClick='javascript:queue("form$idx")'$checked>  value='$enc_url' onClick='javascript:queue("form$idx")'$checked />
 <input type='hidden' name='title' value='$title'>  <input type='hidden' name='title' value='$enc_title' />
 ENDCHECKBOX  ENDCHECKBOX
                 }                  }
  $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');   $r->print('<a href="'.$enc_url.'">');
             }              }
             $r->print(&Apache::lonratsrv::qtescape($title));              $r->print($enc_title);
             if ($url) { $r->print('</a>'); }              if ($url) { $r->print('</a>'); }
             if ($successtied) {              if ($successtied) {
  $r->print('</form>');   $r->print('</form>');
             } else {              } else {
  $r->print('<br>');   $r->print('<br />');
             }              }
         }          }
     }      }
Line 310  sub handler { Line 282  sub handler {
       &Apache::lonnet::symblist($requrl,$disurl => [$disurl,$dismapid],        &Apache::lonnet::symblist($requrl,$disurl => [$disurl,$dismapid],
  'last_known' => [$disurl,$dismapid]);    'last_known' => [$disurl,$dismapid]); 
       &Apache::loncommon::content_type($r,'text/html');        &Apache::loncommon::content_type($r,'text/html');
       $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);        $r->header_out(Location => &Apache::lonnet::absolute_url($ENV{'SERVER_NAME'}).
                                    $disurl);
       return REDIRECT;        return REDIRECT;
    } else {     } else {
        &Apache::loncommon::content_type($r,'text/html');         &Apache::loncommon::content_type($r,'text/html');
Line 354  ENDNONE Line 327  ENDNONE
 1;  1;
 __END__  __END__
   
   =head1 NAME
   
   Apache::lonsequence
   
   =head1 SYNOPSIS
   
   Handler for showing sequence objects of
   educational resources.
   
   This is part of the LearningOnline Network with CAPA project
   described at http://www.lon-capa.org.
   
   =head1 SUBROUTINES
   
   =over
   
   =item handler()
   
   =item viewmap()
   
   =item attemptread()
   
   =item mapread()
   
   =item start_fresh_session()
   
   =back
   
   =cut
   
   
   

Removed from v.1.26  
changed lines
  Added in v.1.39


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