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