File:  [LON-CAPA] / rat / lonpageflip.pm
Revision 1.8: download - view: text, annotated - select for diffs
Tue Oct 17 10:36:17 2000 UTC (23 years, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
Work on user dialogues

    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,10/16,10/17 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:       unless ($currenturl=~/\/res\//) {
   67: 	 my $last;
   68:          if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
   69:                     &GDBM_READER,0640)) {
   70: 	     $last=$hash{'last_known'};
   71:              untie(%hash);
   72:          }
   73:          if ($last) {
   74: 	     $currenturl='/res/'.(split(/\_\_\_/,$last))[1];
   75: 	 } else {
   76: 	     $r->content_type('text/html');
   77:              $r->header_out(Location => 
   78:                                'http://'.$ENV{'HTTP_HOST'}.'/adm/noidea.html');
   79:          }
   80:          return REDIRECT;
   81:       }
   82: # ------------------------------------------- Do we have any idea where we are?
   83:       my $position;
   84:       if ($position=Apache::lonnet::symbread($currenturl)) {
   85: # ------------------------------------------------------------------------- Yes
   86: 	  my ($mapurl,$mapnum,$thisurl)=split(/\_\_\_/,$position);
   87:           $cachehash{$thisurl}=$mapnum;
   88: # ============================================================ Tie the big hash
   89:           if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
   90:                         &GDBM_READER,0640)) {
   91:               my $rid=$hash{'map_pc_/res/'.$mapurl}.'.'.$mapnum;
   92:               my $next='';
   93:               my $mincond=1;
   94:               my $posnext='';
   95:               if ($direction eq 'forward') {
   96: # --------------------------------------------------------------------- Forward
   97:                   map {
   98:                       my $thiscond=
   99:       &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
  100:                       if ($thiscond>=$mincond) {
  101: 		          if ($posnext) {
  102: 		             $posnext.=','.$_.':'.$thiscond;
  103:                           } else {
  104:                              $posnext=$_.':'.$thiscond;
  105: 		          }
  106:                           if ($thiscond>$mincond) { $mincond=$thiscond; }
  107: 	              }
  108:                   } split(/\,/,$hash{'to_'.$rid});
  109:                   map {
  110:                       my ($linkid,$condval)=split(/\:/,$_);
  111:                       if ($condval>=$mincond) {
  112: 		          $next=&addrid($next,$hash{'goesto_'.$linkid},
  113:                                 $hash{'condid_'.$hash{'undercond_'.$linkid}});
  114:                       }
  115:                   } split(/\,/,$posnext);
  116:               } elsif ($direction eq 'back') {
  117: # ------------------------------------------------------------------- Backwards
  118:                   map {
  119:                       my $thiscond=
  120:       &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
  121:                       if ($thiscond>=$mincond) {
  122: 		          if ($posnext) {
  123: 		             $posnext.=','.$_.':'.$thiscond;
  124:                           } else {
  125:                              $posnext=$_.':'.$thiscond;
  126: 		          }
  127:                           if ($thiscond>$mincond) { $mincond=$thiscond; }
  128: 	              }
  129:                   } split(/\,/,$hash{'from_'.$rid});
  130:                   map {
  131:                       my ($linkid,$condval)=split(/\:/,$_);
  132:                       if ($condval>=$mincond) {
  133: 		          $next=&addrid($next,$hash{'comesfrom_'.$linkid},
  134:                                 $hash{'condid_'.$hash{'undercond_'.$linkid}});
  135:                       }
  136:                   } split(/\,/,$posnext);
  137:  	      } elsif ($direction eq 'up') {
  138: # -------------------------------------------------------------------------- Up
  139:               } elsif ($direction eq 'down') {
  140: # ------------------------------------------------------------------------ Down
  141:               }
  142: # ----------------------------------------------------- Check out possibilities
  143:               if ($next) {
  144:                   @possibilities=split(/\,/,$next);
  145:                   if ($#possibilities==0) {
  146: # ---------------------------------------------- Only one possibility, redirect
  147: 	              $redirecturl=$hash{'src_'.$next};
  148:                       $cachehash{&Apache::lonnet::declutter($redirecturl)}
  149: 		                                 =(split(/\./,$next))[1];
  150:                   } else {
  151: # ------------------------ There are multiple possibilities for a next resource
  152:                       $multichoice=1;
  153:                       map {
  154: 			  $multichoicehash{'src_'.$_}=$hash{'src_'.$_};
  155:                           $multichoicehash{'title_'.$_}=$hash{'title_'.$_};
  156:                           $multichoicehash{'type_'.$_}=$hash{'type_'.$_};
  157:                           $cachehash
  158:                             {&Apache::lonnet::declutter(
  159: 						      $multichoicehash
  160:                                                          {'src_'.$_}
  161:                                                        )}
  162: 		                                 =(split(/\./,$_))[1];
  163:                       } @possibilities;
  164:                   }
  165: 	      } else {
  166: # -------------------------------------------------------------- No place to go
  167:                   $multichoice=-1;
  168:               }
  169: # ----------------- The program must come past this point to untie the big hash
  170: 	      untie(%hash);
  171: # --------------------------------------------------------- Store position info
  172:               $cachehash{'last_direction'}=$direction;
  173:               $cachehash{'last_known'}=&Apache::lonnet::declutter($currenturl);
  174:               &Apache::lonnet::symblist($mapurl,%cachehash);
  175: # ============================================== Do not return before this line
  176:               if ($redirecturl) {
  177: # ----------------------------------------------------- There is a URL to go to
  178: 		  $r->content_type('text/html');
  179:                   $r->header_out(Location => 
  180:                                 'http://'.$ENV{'HTTP_HOST'}.$redirecturl);
  181:                   return REDIRECT;
  182: 	      } else {
  183: # --------------------------------------------------------- There was a problem
  184:                   $r->content_type('text/html');
  185:                   $r->send_http_header;
  186:                   if ($#possibilities>0) {
  187:                      $r->print(<<ENDSTART);
  188: <head><title>Choose Next Location</title></head>
  189: <body bgcolor="#FFFFFF">
  190: <h1>LON-CAPA</h1>
  191: There are several possibilities of where to go next.
  192: <p>
  193: Please click on the the resource you intend to access:
  194: <p>
  195: <table border=2>
  196: <tr><th>Title</th><th>Type</th></tr>
  197: ENDSTART
  198:                      map {
  199:                         $r->print(
  200:                               '<tr><td><a href="'.
  201:                               $multichoicehash{'src_'.$_}.'">'.
  202:                               $multichoicehash{'title_'.$_}.
  203:                               '</a></td><td>'.$multichoicehash{'type_'.$_}.
  204: 			      '</td></tr>');
  205:                      } @possibilities;
  206:                      $r->print('</table></body></html>');
  207: 		     return OK;
  208:                   } else {
  209:                      $r->print(<<ENDNONE);
  210: <head><title>Choose Next Location</title></head>
  211: <body bgcolor="#FFFFFF">
  212: <img src="/adm/lonKaputt/lonlogo_broken.gif" align=left>
  213: <h1>Sorry!</h1>
  214: <h2>Next resource could not be identified.</h2>
  215: </body>
  216: </html>
  217: ENDNONE
  218:                      return OK;
  219: 	         }
  220: 	     }
  221: 	  } else {
  222: # ------------------------------------------------- Problem, could not tie hash
  223:               $ENV{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
  224:               return HTTP_NOT_ACCEPTABLE; 
  225:           }
  226:       } else {
  227: # ---------------------------------------- No, could not determine where we are
  228:          $r->internal_redirect('/adm/ambiguous');
  229:       }
  230:   } else {
  231: # -------------------------- Class was not initialized or page fliped strangely
  232:       $ENV{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
  233:       return HTTP_NOT_ACCEPTABLE; 
  234:   } 
  235: }
  236: 
  237: 1;
  238: __END__
  239: 
  240: 
  241: 
  242: 
  243: 
  244: 
  245: 

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