Annotation of rat/lonpageflip.pm, revision 1.12
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.11 www 13: # 10/03,10/05,10/06,10/07,10/09,10/10,10/11,10/16,10/17,11/14 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.12 ! www 170: if ($hash{'param_'.$next}) {
! 171: my ($mapid,$resid)=split(/\./,$next);
! 172: &Apache::lonnet::appendparms(
! 173: &Apache::lonnet::declutter($hash{'map_id_'.$mapid}).
! 174: '___'.$resid.'___'.
! 175: &Apache::lonnet::declutter($redirecturl),
! 176: $hash{'param_'.$next});
! 177: }
1.4 www 178: } else {
1.5 www 179: # ------------------------ There are multiple possibilities for a next resource
180: $multichoice=1;
181: map {
182: $multichoicehash{'src_'.$_}=$hash{'src_'.$_};
183: $multichoicehash{'title_'.$_}=$hash{'title_'.$_};
1.6 www 184: $multichoicehash{'type_'.$_}=$hash{'type_'.$_};
1.5 www 185: $cachehash
186: {&Apache::lonnet::declutter(
187: $multichoicehash
188: {'src_'.$_}
189: )}
190: =(split(/\./,$_))[1];
1.12 ! www 191: if ($hash{'param_'.$_}) {
! 192: my ($mapid,$resid)=split(/\./,$_);
! 193: &Apache::lonnet::appendparms(
! 194: &Apache::lonnet::declutter($hash{'map_id_'.$mapid}).
! 195: '___'.$resid.'___'.
! 196: &Apache::lonnet::declutter($hash{'src_'.$_}),
! 197: $hash{'param_'.$_});
! 198: }
1.5 www 199: } @possibilities;
1.4 www 200: }
1.5 www 201: } else {
202: # -------------------------------------------------------------- No place to go
203: $multichoice=-1;
1.4 www 204: }
1.5 www 205: # ----------------- The program must come past this point to untie the big hash
1.3 www 206: untie(%hash);
1.5 www 207: # --------------------------------------------------------- Store position info
208: $cachehash{'last_direction'}=$direction;
1.7 www 209: $cachehash{'last_known'}=&Apache::lonnet::declutter($currenturl);
1.5 www 210: &Apache::lonnet::symblist($mapurl,%cachehash);
211: # ============================================== Do not return before this line
1.4 www 212: if ($redirecturl) {
1.5 www 213: # ----------------------------------------------------- There is a URL to go to
1.4 www 214: $r->content_type('text/html');
215: $r->header_out(Location =>
216: 'http://'.$ENV{'HTTP_HOST'}.$redirecturl);
217: return REDIRECT;
1.5 www 218: } else {
219: # --------------------------------------------------------- There was a problem
1.8 www 220: $r->content_type('text/html');
221: $r->send_http_header;
222: if ($#possibilities>0) {
223: $r->print(<<ENDSTART);
224: <head><title>Choose Next Location</title></head>
225: <body bgcolor="#FFFFFF">
226: <h1>LON-CAPA</h1>
227: There are several possibilities of where to go next.
228: <p>
229: Please click on the the resource you intend to access:
230: <p>
231: <table border=2>
232: <tr><th>Title</th><th>Type</th></tr>
233: ENDSTART
234: map {
235: $r->print(
236: '<tr><td><a href="'.
237: $multichoicehash{'src_'.$_}.'">'.
238: $multichoicehash{'title_'.$_}.
239: '</a></td><td>'.$multichoicehash{'type_'.$_}.
240: '</td></tr>');
241: } @possibilities;
242: $r->print('</table></body></html>');
243: return OK;
244: } else {
245: $r->print(<<ENDNONE);
246: <head><title>Choose Next Location</title></head>
247: <body bgcolor="#FFFFFF">
248: <img src="/adm/lonKaputt/lonlogo_broken.gif" align=left>
249: <h1>Sorry!</h1>
250: <h2>Next resource could not be identified.</h2>
251: </body>
252: </html>
253: ENDNONE
254: return OK;
255: }
256: }
1.5 www 257: } else {
258: # ------------------------------------------------- Problem, could not tie hash
259: $ENV{'user.error.msg'}="/adm/flip:bre:0:1:Course Data Missing";
260: return HTTP_NOT_ACCEPTABLE;
1.3 www 261: }
1.5 www 262: } else {
263: # ---------------------------------------- No, could not determine where we are
1.6 www 264: $r->internal_redirect('/adm/ambiguous');
1.2 www 265: }
1.5 www 266: } else {
1.2 www 267: # -------------------------- Class was not initialized or page fliped strangely
268: $ENV{'user.error.msg'}="/adm/flip:bre:0:0:Choose Course";
269: return HTTP_NOT_ACCEPTABLE;
270: }
1.1 www 271: }
272:
273: 1;
274: __END__
275:
276:
277:
278:
279:
280:
281:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>