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