File:  [LON-CAPA] / rat / lonpageflip.pm
Revision 1.5: download - view: text, annotated - select for diffs
Wed Oct 11 18:31:00 2000 UTC (23 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
lonuserstate cleans up symb table, lonpageflip contributes to it

    1: # The LearningOnline Network with CAPA
    2: #
    3: # Page flip handler
    4: #
    5: # (Page Handler
    6: #
    7: # (TeX Content Handler
    8: #
    9: # 05/29/00,05/30 Gerd Kortemeyer)
   10: # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
   11: # 10/02 Gerd Kortemeyer)
   12: #
   13: # 10/03,10/05,10/06,10/07,10/09,10/10,10/11 Gerd Kortemeyer
   14: 
   15: package Apache::lonpageflip;
   16: 
   17: use strict;
   18: use Apache::Constants qw(:common :http REDIRECT);
   19: use Apache::lonnet();
   20: use HTML::TokeParser;
   21: use GDBM_File;
   22: 
   23: # ========================================================== Module Global Hash
   24:   
   25: my %hash;
   26: 
   27: sub addrid {
   28:     my ($current,$new,$condid)=@_;
   29:     unless ($condid) { $condid=0; }
   30:     if (&Apache::lonnet::allowed('bre',$hash{'src_'.$new})) {
   31: 	if ($current) {
   32: 	    $current.=','.$new;
   33:         } else {
   34:             $current=''.$new;
   35:         }
   36:     }
   37:     return $current;
   38: }
   39: 
   40: # ================================================================ Main Handler
   41: 
   42: sub handler {
   43:    my $r=shift;
   44: 
   45: # ------------------------------------------- Set document type for header only
   46: 
   47:   if ($r->header_only) {
   48:      $r->content_type('text/html');
   49:      $r->send_http_header;
   50:      return OK;
   51:   }
   52: 
   53:   my %cachehash=(); 
   54:   my $multichoice=0;
   55:   my %multichoicehash=();
   56:   my $redirecturl='';
   57:   my $next='';
   58:   my @possibilities=();
   59: 
   60:   if (($ENV{'form.postdata'})&&($ENV{'request.course.fn'})) {
   61:       $ENV{'form.postdata'}=~/(\w+)\:(.*)/;
   62:       my $direction=$1;
   63:       my $currenturl=$2;
   64:       $currenturl=~s/^http\:\/\///;
   65:       $currenturl=~s/^[^\/]+//;
   66: # ------------------------------------------- Do we have any idea where we are?
   67:       my $position;
   68:       if ($position=Apache::lonnet::symbread($currenturl)) {
   69: # ------------------------------------------------------------------------- Yes
   70: 	  my ($mapurl,$mapnum,$thisurl)=split(/\_\_\_/,$position);
   71:           $cachehash{$thisurl}=$mapnum;
   72: # ============================================================ Tie the big hash
   73:           if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
   74:                         &GDBM_READER,0640)) {
   75:               my $rid=$hash{'map_pc_/res/'.$mapurl}.'.'.$mapnum;
   76:               my $next='';
   77:               my $mincond=1;
   78:               my $posnext='';
   79:               if ($direction eq 'forward') {
   80: # --------------------------------------------------------------------- Forward
   81:                   map {
   82:                       my $thiscond=
   83:       &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
   84:                       if ($thiscond>=$mincond) {
   85: 		          if ($posnext) {
   86: 		             $posnext.=','.$_.':'.$thiscond;
   87:                           } else {
   88:                              $posnext=$_.':'.$thiscond;
   89: 		          }
   90:                           if ($thiscond>$mincond) { $mincond=$thiscond; }
   91: 	              }
   92:                   } split(/\,/,$hash{'to_'.$rid});
   93:                   map {
   94:                       my ($linkid,$condval)=split(/\:/,$_);
   95:                       if ($condval>=$mincond) {
   96: 		          $next=&addrid($next,$hash{'goesto_'.$linkid},
   97:                                 $hash{'condid_'.$hash{'undercond_'.$linkid}});
   98:                       }
   99:                   } split(/\,/,$posnext);
  100:               } elsif ($direction eq 'back') {
  101: # ------------------------------------------------------------------- Backwards
  102:                   map {
  103:                       my $thiscond=
  104:       &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
  105:                       if ($thiscond>=$mincond) {
  106: 		          if ($posnext) {
  107: 		             $posnext.=','.$_.':'.$thiscond;
  108:                           } else {
  109:                              $posnext=$_.':'.$thiscond;
  110: 		          }
  111:                           if ($thiscond>$mincond) { $mincond=$thiscond; }
  112: 	              }
  113:                   } split(/\,/,$hash{'from_'.$rid});
  114:                   map {
  115:                       my ($linkid,$condval)=split(/\:/,$_);
  116:                       if ($condval>=$mincond) {
  117: 		          $next=&addrid($next,$hash{'comesfrom_'.$linkid},
  118:                                 $hash{'condid_'.$hash{'undercond_'.$linkid}});
  119:                       }
  120:                   } split(/\,/,$posnext);
  121:  	      } elsif ($direction eq 'up') {
  122: # -------------------------------------------------------------------------- Up
  123:               } elsif ($direction eq 'down') {
  124: # ------------------------------------------------------------------------ Down
  125:               }
  126: # ----------------------------------------------------- Check out possibilities
  127:               if ($next) {
  128:                   @possibilities=split(/\,/,$next);
  129:                   if ($#possibilities==0) {
  130: # ---------------------------------------------- Only one possibility, redirect
  131: 	              $redirecturl=$hash{'src_'.$next};
  132:                       $cachehash{&Apache::lonnet::declutter($redirecturl)}
  133: 		                                 =(split(/\./,$next))[1];
  134:                   } else {
  135: # ------------------------ There are multiple possibilities for a next resource
  136:                       $multichoice=1;
  137:                       map {
  138: 			  $multichoicehash{'src_'.$_}=$hash{'src_'.$_};
  139:                           $multichoicehash{'title_'.$_}=$hash{'title_'.$_};
  140:                           $cachehash
  141:                             {&Apache::lonnet::declutter(
  142: 						      $multichoicehash
  143:                                                          {'src_'.$_}
  144:                                                        )}
  145: 		                                 =(split(/\./,$_))[1];
  146:                       } @possibilities;
  147:                   }
  148: 	      } else {
  149: # -------------------------------------------------------------- No place to go
  150:                   $multichoice=-1;
  151:               }
  152: # ----------------- The program must come past this point to untie the big hash
  153: 	      untie(%hash);
  154: # --------------------------------------------------------- Store position info
  155:               $cachehash{'last_direction'}=$direction;
  156:               &Apache::lonnet::symblist($mapurl,%cachehash);
  157: # ============================================== Do not return before this line
  158:               if ($redirecturl) {
  159: # ----------------------------------------------------- There is a URL to go to
  160: 		  $r->content_type('text/html');
  161:                   $r->header_out(Location => 
  162:                                 'http://'.$ENV{'HTTP_HOST'}.$redirecturl);
  163:                   return REDIRECT;
  164: 	      } else {
  165: # --------------------------------------------------------- There was a problem
  166:               }
  167: 	  } else {
  168: # ------------------------------------------------- Problem, could not tie hash
  169:               $ENV{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
  170:               return HTTP_NOT_ACCEPTABLE; 
  171:           }
  172:       } else {
  173: # ---------------------------------------- No, could not determine where we are
  174:       }
  175:   } else {
  176: # -------------------------- Class was not initialized or page fliped strangely
  177:       $ENV{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
  178:       return HTTP_NOT_ACCEPTABLE; 
  179:   } 
  180: }
  181: 
  182: 1;
  183: __END__
  184: 
  185: 
  186: 
  187: 
  188: 
  189: 
  190: 

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