File:  [LON-CAPA] / rat / lonpageflip.pm
Revision 1.4: download - view: text, annotated - select for diffs
Mon Oct 9 19:37:35 2000 UTC (23 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Actually flips pages now for non-ambigous situations!

# The LearningOnline Network with CAPA
#
# Page flip handler
#
# (Page Handler
#
# (TeX Content Handler
#
# 05/29/00,05/30 Gerd Kortemeyer)
# 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
# 10/02 Gerd Kortemeyer)
#
# 10/03,10/05,10/06,10/07,10/09 Gerd Kortemeyer

package Apache::lonpageflip;

use strict;
use Apache::Constants qw(:common :http REDIRECT);
use Apache::lonnet();
use HTML::TokeParser;
use GDBM_File;

# ========================================================== Module Global Hash
  
my %hash;

sub addrid {
    my ($current,$new,$condid)=@_;
    unless ($condid) { $condid=0; }
    if (&Apache::lonnet::allowed('bre',$hash{'src_'.$new})) {
	if ($current) {
	    $current.=','.$new.':'.$condid;
        } else {
            $current=''.$new.':'.$condid;
        }
    }
    return $current;
}

# ================================================================ Main Handler

sub handler {
   my $r=shift;

# ------------------------------------------- Set document type for header only

  if ($r->header_only) {
     $r->content_type('text/html');
     $r->send_http_header;
     return OK;
  }

  my %cachehash=();
  my $redirecturl='';
  my $next='';
  my @possibilities=();

  if (($ENV{'form.postdata'})&&($ENV{'request.course.fn'})) {
      $ENV{'form.postdata'}=~/(\w+)\:(.*)/;
      my $direction=$1;
      my $currenturl=$2;
      my $redirecturl=$currenturl;
      $currenturl=~s/^http\:\/\///;
      $currenturl=~s/^[^\/]+//;
# ------------------------------------------- Do we have any idea where we are?
      my $position;
      if ($position=Apache::lonnet::symbread($currenturl)) {
# ------------------------------------------------------------------------- Yes
	  my ($mapurl,$mapnum,$thisurl)=split(/\_\_\_/,$position);
          $cachehash{$thisurl}=$mapnum;
          if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
                        &GDBM_READER,0640)) {
              my $rid=$hash{'map_pc_/res/'.$mapurl}.'.'.$mapnum;
              my $next='';
              if ($direction eq 'forward') {
                 map {
		    $next=&addrid($next,$hash{'goesto_'.$_},
                                  $hash{'condid_'.$hash{'undercond_'.$_}});
                  } split(/\,/,$hash{'to_'.$rid});
              } elsif ($direction eq 'back') {
                map {
		    $next=&addrid($next,$hash{'comesfrom_'.$_},
                                  $hash{'condid_'.$hash{'undercond_'.$_}});
                  } split(/\,/,$hash{'from_'.$rid});
 	      } elsif ($direction eq 'up') {
              } elsif ($direction eq 'down') {
              }
              my $redirectid='';
# ----------------------------------------------------- Check out possibilities
              if ($next) {
                  @possibilities=split(/\,/,$next);
                  if ($#possibilities==0) {
		      $redirectid=(split(/\:/,$next))[0];
                  } else {
                  }
	      }
              if ($redirectid) {
		  $redirecturl=$hash{'src_'.$redirectid};
              }
	      untie(%hash);
              if ($redirecturl) {
		  $r->content_type('text/html');
                  $r->header_out(Location => 
                                'http://'.$ENV{'HTTP_HOST'}.$redirecturl);
                  return REDIRECT;
              }
          }
      }
# -------------------------------------------------------- No, could not decide
      }
    $r->content_type('text/html');
     $r->send_http_header;

  $r->print('<html><body>');

# -------------------------- Class was not initialized or page fliped strangely
  } else {
      $ENV{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
      return HTTP_NOT_ACCEPTABLE; 
  } 




# ------TRASH BELOW
# --------------------------- TRASH

  $r->print('</body></html>');
  return OK;


# ========================================================= TOTAL TRASH

#                  &Apache::lonnet::symblist($requrl,%symbhash);

}

1;
__END__








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