Annotation of rat/lonpageflip.pm, revision 1.7
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.7 ! www 13: # 10/03,10/05,10/06,10/07,10/09,10/10,10/11,10/16 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.7 ! www 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: }
1.3 www 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;
1.5 www 88: # ============================================================ Tie the big hash
1.3 www 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='';
1.5 www 93: my $mincond=1;
94: my $posnext='';
1.3 www 95: if ($direction eq 'forward') {
1.5 www 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: }
1.3 www 108: } split(/\,/,$hash{'to_'.$rid});
1.5 www 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);
1.3 www 116: } elsif ($direction eq 'back') {
1.5 www 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: }
1.4 www 129: } split(/\,/,$hash{'from_'.$rid});
1.5 www 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);
1.4 www 137: } elsif ($direction eq 'up') {
1.5 www 138: # -------------------------------------------------------------------------- Up
1.3 www 139: } elsif ($direction eq 'down') {
1.5 www 140: # ------------------------------------------------------------------------ Down
1.3 www 141: }
1.4 www 142: # ----------------------------------------------------- Check out possibilities
143: if ($next) {
144: @possibilities=split(/\,/,$next);
145: if ($#possibilities==0) {
1.5 www 146: # ---------------------------------------------- Only one possibility, redirect
147: $redirecturl=$hash{'src_'.$next};
148: $cachehash{&Apache::lonnet::declutter($redirecturl)}
149: =(split(/\./,$next))[1];
1.4 www 150: } else {
1.5 www 151: # ------------------------ There are multiple possibilities for a next resource
152: $multichoice=1;
153: map {
154: $multichoicehash{'src_'.$_}=$hash{'src_'.$_};
155: $multichoicehash{'title_'.$_}=$hash{'title_'.$_};
1.6 www 156: $multichoicehash{'type_'.$_}=$hash{'type_'.$_};
1.5 www 157: $cachehash
158: {&Apache::lonnet::declutter(
159: $multichoicehash
160: {'src_'.$_}
161: )}
162: =(split(/\./,$_))[1];
163: } @possibilities;
1.4 www 164: }
1.5 www 165: } else {
166: # -------------------------------------------------------------- No place to go
167: $multichoice=-1;
1.4 www 168: }
1.5 www 169: # ----------------- The program must come past this point to untie the big hash
1.3 www 170: untie(%hash);
1.5 www 171: # --------------------------------------------------------- Store position info
172: $cachehash{'last_direction'}=$direction;
1.7 ! www 173: $cachehash{'last_known'}=&Apache::lonnet::declutter($currenturl);
1.5 www 174: &Apache::lonnet::symblist($mapurl,%cachehash);
175: # ============================================== Do not return before this line
1.4 www 176: if ($redirecturl) {
1.5 www 177: # ----------------------------------------------------- There is a URL to go to
1.4 www 178: $r->content_type('text/html');
179: $r->header_out(Location =>
180: 'http://'.$ENV{'HTTP_HOST'}.$redirecturl);
181: return REDIRECT;
1.5 www 182: } else {
183: # --------------------------------------------------------- There was a problem
1.4 www 184: }
1.5 www 185: } else {
186: # ------------------------------------------------- Problem, could not tie hash
187: $ENV{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
188: return HTTP_NOT_ACCEPTABLE;
1.3 www 189: }
1.5 www 190: } else {
191: # ---------------------------------------- No, could not determine where we are
1.6 www 192: $r->internal_redirect('/adm/ambiguous');
1.2 www 193: }
1.5 www 194: } else {
1.2 www 195: # -------------------------- Class was not initialized or page fliped strangely
196: $ENV{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
197: return HTTP_NOT_ACCEPTABLE;
198: }
1.1 www 199: }
200:
201: 1;
202: __END__
203:
204:
205:
206:
207:
208:
209:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>