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