Annotation of rat/lonsequence.pm, revision 1.14
1.1 www 1: # The LearningOnline Network with CAPA
2: #
3: # Sequence Handler
4: #
1.14 ! www 5: # $Id: lonsequence.pm,v 1.13 2002/08/12 18:21:42 albertel Exp $
1.5 www 6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: #
1.1 www 29: # (Handler to resolve ambiguous file locations
30: #
31: # (TeX Content Handler
32: #
33: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
34: #
35: # 10/11,10/12 Gerd Kortemeyer)
36: #
37: # 10/16 Gerd Kortemeyer
38:
1.3 www 39: package Apache::lonsequence;
1.1 www 40:
41: use strict;
42: use Apache::lonnet;
1.3 www 43: use Apache::Constants qw(:common :http REDIRECT);
1.1 www 44: use GDBM_File;
1.8 www 45: use Apache::lonratedt;
46: use Apache::lonratsrv;
1.11 www 47: use Apache::lonpageflip;
1.14 ! www 48: use Apache::loncommon;
1.1 www 49:
1.12 www 50: my %selhash;
51: my $successtied;
1.8 www 52:
53: # ----------------------------------------- Attempt to read from resource space
54:
55: sub attemptread {
56: my $fn=shift;
57: &Apache::lonnet::repcopy($fn);
58: if (-e $fn) {
59: return &Apache::lonratedt::attemptread($fn);
60: } else {
61: return ();
62: }
63: }
64:
65: # ---------------------------------------------------------------- View Handler
66:
67: sub viewmap {
1.9 www 68: my ($r,$url)=@_;
1.8 www 69: $r->print('<html>');
70: if ($ENV{'form.forceselect'}) { $r->print(<<ENDSCRIPT);
71: <script>
72:
73: function select_group() {
1.12 www 74: window.location="/adm/groupsort?catalogmode=groupsec&mode=rat&acts="+document.forms.fileattr.acts.value;
1.8 www 75: }
76:
77: function queue(val) {
78: if (eval("document.forms."+val+".filelink.checked")) {
79: var l=val.length;
80: var v=val.substring(4,l);
81: document.forms.fileattr.acts.value+='1a'+v+'b';
82: }
83: else {
84: var l=val.length;
85: var v=val.substring(4,l);
86: document.forms.fileattr.acts.value+='0a'+v+'b';
87: }
88: }
89:
90: </script>
91: ENDSCRIPT
92: }
1.14 ! www 93: $r->print(&Apache::loncommon::bodytag('Map Contents').'<h1>'.$url.'</h1>');
1.12 www 94: # ------------------ This is trying to select. Provide buttons and tie %selhash
1.8 www 95: if ($ENV{'form.forceselect'}) { $r->print(<<ENDSELECT);
96: <form name=fileattr><input type=hidden name=acts value=''>
97: <input type="button" name="close" value='CLOSE' onClick="self.close()">
98: <input type="button" name="groupimport" value='GROUP IMPORT'
99: onClick="javascript:select_group()">
100: </form>
101: ENDSELECT
1.12 www 102: my $diropendb =
103: "/home/httpd/perl/tmp/$ENV{'user.domain'}\_$ENV{'user.name'}_groupsec.db";
1.13 albertel 104: if (tie(%selhash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
1.12 www 105: if ($ENV{'form.launch'} eq '1') {
106: &start_fresh_session();
107: }
108: $successtied=1;
109:
110: # - Evaluate actions from previous page (both cumulatively and chronologically)
111: if ($ENV{'form.catalogmode'} eq 'groupimport') {
112: my $acts=$ENV{'form.acts'};
113: my @Acts=split(/b/,$acts);
114: my %ahash;
115: my %achash;
116: my $ac=0;
117: # some initial hashes for working with data
118: foreach (@Acts) {
119: my ($state,$ref)=split(/a/);
120: $ahash{$ref}=$state;
121: $achash{$ref}=$ac;
122: $ac++;
123: }
124: # sorting through the actions and changing the tied database hash
125: foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
126: my $key=$_;
127: if ($ahash{$key} eq '1') {
128: $selhash{'store_'.$selhash{'pre_'.$key.'_link'}}=
129: $selhash{'pre_'.$key.'_title'};
130: $selhash{'storectr_'.$selhash{'pre_'.$key.'_link'}}=
131: $selhash{'storectr'}+0;
132: $selhash{'storectr'}++;
133: }
134: if ($ahash{$key} eq '0') {
135: if ($selhash{'store_'.$selhash{'pre_'.$key.'_link'}}) {
136: delete $selhash{'store_'.$selhash{'pre_'.$key.'_link'}};
137: }
138: }
139: }
140: # deleting the previously cached listing
141: foreach (keys %selhash) {
142: if ($_ =~ /^pre_/ && $_ =~/link$/) {
143: my $key = $_;
144: $key =~ s/^pre_//;
145: $key =~ s/_[^_]*$//;
146: delete $selhash{'pre_'.$key.'_title'};
147: delete $selhash{'pre_'.$key.'_link'};
148: }
149: }
150: }
151: # -
152: }
1.8 www 153: }
1.12 www 154: # ----------------------------- successtied is now '1' if in working selectmode
1.8 www 155: my $idx=0;
156: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
157: if (defined($_)) {
158: $idx++;
1.12 www 159: if ($successtied) {
1.8 www 160: $r->print('<form name="form'.$idx.'">');
161: }
162: my ($title,$url)=split(/\:/,$_);
163: $title=~s/\&colon\;/\:/g;
164: $url=~s/\&colon\;/\:/g;
165: unless ($title) { $title=(split(/\//,$url))[-1] };
166: unless ($title) { $title='<i>Empty</i>'; }
167: if ($url) {
1.12 www 168: if ($successtied) {
169: my $checked='';
170: if ($selhash{'store_'.$url}) {
171: $checked=" checked";
172: }
173: $selhash{"pre_${idx}_link"}=$url;
174: $selhash{"pre_${idx}_title"}=$title;
175:
1.8 www 176: $r->print(<<ENDCHECKBOX);
177: <input type='checkbox' name='filelink'
1.12 www 178: value='$url' onClick='javascript:queue("form$idx")'$checked>
1.8 www 179: <input type='hidden' name='title' value='$title'>
180: ENDCHECKBOX
181: }
182: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
183: }
184: $r->print(&Apache::lonratsrv::qtescape($title));
185: if ($url) { $r->print('</a>'); }
1.12 www 186: if ($successtied) {
1.8 www 187: $r->print('</form>');
188: } else {
189: $r->print('<br>');
190: }
191: }
192: }
193: $r->print('</body></html>');
1.12 www 194: if ($successtied) {
195: untie %selhash;
196: }
1.8 www 197: }
198:
1.12 www 199: # ----------------------------------------------------------- Clean out selhash
200: sub start_fresh_session {
201: foreach (keys %selhash) {
202: if ($_ =~ /^pre_/) {
203: delete $selhash{$_};
204: }
205: if ($_ =~ /^store/) {
206: delete $selhash{$_};
207: }
208: }
209: }
210:
211:
1.1 www 212: # ================================================================ Main Handler
213:
214: sub handler {
215: my $r=shift;
216:
217: if ($r->header_only) {
218: $r->content_type('text/html');
219: $r->send_http_header;
220: return OK;
221: }
1.8 www 222:
223: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.12 www 224: ['forceselect','launch']);
1.1 www 225:
1.2 www 226: my %hash;
1.1 www 227: my %bighash;
1.2 www 228: my $requrl=$r->uri;
229:
1.12 www 230: $successtied=0;
1.3 www 231: # ------------------------------------------------------------ Tie symb db file
1.9 www 232: my $disurl='';
233: my $dismapid='';
234:
235: if (($ENV{'request.course.fn'}) && (!$ENV{'form.forceselect'})) {
1.2 www 236: my $last;
237: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
1.13 albertel 238: &GDBM_READER(),0640)) {
1.2 www 239: $last=$hash{'last_direction'};
240: untie(%hash);
241: }
1.3 www 242: my $direction='';
243: my $prevmap='';
244: if ($last) {
245: ($prevmap,$direction)=(split(/\_\_\_/,$last));
246: }
247: # ------------------------------------------------------------- Tie big db file
1.1 www 248: if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
1.13 albertel 249: &GDBM_READER(),0640)) {
1.3 www 250: my $disid='';
1.10 www 251:
1.3 www 252: if ($direction eq 'back') {
253: $disid=$bighash{'map_finish_'.$requrl};
254: } else {
255: $disid=$bighash{'map_start_'.$requrl};
256: }
257: if ($disid) {
258: $disurl=$bighash{'src_'.$disid};
1.4 www 259: $dismapid=(split(/\./,$disid))[1];
1.3 www 260: }
1.11 www 261: # ------------------------- If this is an empty one, skip to next non-empty one
262: if ((!$disurl) && ($disid)) {
263: $direction=($direction?$direction:'forward');
264: ($disid,$requrl)=
265: &Apache::lonpageflip::fullmove($disid,
266: &Apache::lonnet::declutter($requrl),$direction);
267: if ($disid) {
268: $disurl=$bighash{'src_'.$disid};
269: $dismapid=(split(/\./,$disid))[1];
270: }
271: }
272:
1.3 www 273: # --------------------------------------- Untie hash, make sure to come by here
274: untie(%bighash);
1.9 www 275: }
276: }
277:
278: # now either disurl is set (going to first page), or we need another display
279:
280: if ($disurl) {
1.3 www 281: # -------------------------------------------------- Has first or last resource
1.9 www 282: &Apache::lonnet::symblist($requrl,$disurl => $dismapid,
1.7 www 283: 'last_known' => &Apache::lonnet::declutter($disurl));
1.9 www 284: $r->content_type('text/html');
285: $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
286: return REDIRECT;
1.1 www 287: } else {
1.9 www 288: $r->content_type('text/html');
289: $r->send_http_header;
290: &viewmap($r,$requrl);
291: return OK;
1.1 www 292: }
293: }
294:
295: 1;
296: __END__
297:
298:
299:
300:
301:
302:
303:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>