Annotation of rat/lonpageflip.pm, revision 1.5
1.1 www 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: #
1.5 ! www 13: # 10/03,10/05,10/06,10/07,10/09,10/10,10/11 Gerd Kortemeyer
1.1 www 14:
15: package Apache::lonpageflip;
16:
17: use strict;
1.4 www 18: use Apache::Constants qw(:common :http REDIRECT);
1.1 www 19: use Apache::lonnet();
20: use HTML::TokeParser;
21: use GDBM_File;
22:
1.3 www 23: # ========================================================== Module Global Hash
24:
1.1 www 25: my %hash;
26:
1.3 www 27: sub addrid {
1.4 www 28: my ($current,$new,$condid)=@_;
29: unless ($condid) { $condid=0; }
1.3 www 30: if (&Apache::lonnet::allowed('bre',$hash{'src_'.$new})) {
31: if ($current) {
1.5 ! www 32: $current.=','.$new;
1.3 www 33: } else {
1.5 ! www 34: $current=''.$new;
1.3 www 35: }
1.1 www 36: }
1.3 www 37: return $current;
1.1 www 38: }
39:
40: # ================================================================ Main Handler
41:
42: sub handler {
1.2 www 43: my $r=shift;
1.1 www 44:
45: # ------------------------------------------- Set document type for header only
46:
1.2 www 47: if ($r->header_only) {
1.1 www 48: $r->content_type('text/html');
49: $r->send_http_header;
1.2 www 50: return OK;
51: }
52:
1.5 ! www 53: my %cachehash=();
! 54: my $multichoice=0;
! 55: my %multichoicehash=();
1.4 www 56: my $redirecturl='';
57: my $next='';
58: my @possibilities=();
1.2 www 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/^[^\/]+//;
1.3 www 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;
1.5 ! www 72: # ============================================================ Tie the big hash
1.3 www 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='';
1.5 ! www 77: my $mincond=1;
! 78: my $posnext='';
1.3 www 79: if ($direction eq 'forward') {
1.5 ! www 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: }
1.3 www 92: } split(/\,/,$hash{'to_'.$rid});
1.5 ! www 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);
1.3 www 100: } elsif ($direction eq 'back') {
1.5 ! www 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: }
1.4 www 113: } split(/\,/,$hash{'from_'.$rid});
1.5 ! www 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);
1.4 www 121: } elsif ($direction eq 'up') {
1.5 ! www 122: # -------------------------------------------------------------------------- Up
1.3 www 123: } elsif ($direction eq 'down') {
1.5 ! www 124: # ------------------------------------------------------------------------ Down
1.3 www 125: }
1.4 www 126: # ----------------------------------------------------- Check out possibilities
127: if ($next) {
128: @possibilities=split(/\,/,$next);
129: if ($#possibilities==0) {
1.5 ! www 130: # ---------------------------------------------- Only one possibility, redirect
! 131: $redirecturl=$hash{'src_'.$next};
! 132: $cachehash{&Apache::lonnet::declutter($redirecturl)}
! 133: =(split(/\./,$next))[1];
1.4 www 134: } else {
1.5 ! www 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;
1.4 www 147: }
1.5 ! www 148: } else {
! 149: # -------------------------------------------------------------- No place to go
! 150: $multichoice=-1;
1.4 www 151: }
1.5 ! www 152: # ----------------- The program must come past this point to untie the big hash
1.3 www 153: untie(%hash);
1.5 ! www 154: # --------------------------------------------------------- Store position info
! 155: $cachehash{'last_direction'}=$direction;
! 156: &Apache::lonnet::symblist($mapurl,%cachehash);
! 157: # ============================================== Do not return before this line
1.4 www 158: if ($redirecturl) {
1.5 ! www 159: # ----------------------------------------------------- There is a URL to go to
1.4 www 160: $r->content_type('text/html');
161: $r->header_out(Location =>
162: 'http://'.$ENV{'HTTP_HOST'}.$redirecturl);
163: return REDIRECT;
1.5 ! www 164: } else {
! 165: # --------------------------------------------------------- There was a problem
1.4 www 166: }
1.5 ! www 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;
1.3 www 171: }
1.5 ! www 172: } else {
! 173: # ---------------------------------------- No, could not determine where we are
1.2 www 174: }
1.5 ! www 175: } else {
1.2 www 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: }
1.1 www 180: }
181:
182: 1;
183: __END__
184:
185:
186:
187:
188:
189:
190:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>