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