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