Annotation of rat/lonsequence.pm, revision 1.16
1.1 www 1: # The LearningOnline Network with CAPA
2: #
3: # Sequence Handler
4: #
1.16 ! www 5: # $Id: lonsequence.pm,v 1.15 2003/04/07 20:47:06 www 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.16 ! www 49: use Apache::lonlocal;
1.1 www 50:
1.12 www 51: my %selhash;
52: my $successtied;
1.8 www 53:
54: # ----------------------------------------- Attempt to read from resource space
55:
56: sub attemptread {
57: my $fn=shift;
58: &Apache::lonnet::repcopy($fn);
59: if (-e $fn) {
60: return &Apache::lonratedt::attemptread($fn);
61: } else {
62: return ();
63: }
64: }
65:
1.15 www 66: sub mapread {
67: my $fn=shift;
68: &Apache::lonnet::repcopy($fn);
69: if (-e $fn) {
70: return &Apache::lonratedt::mapread($fn,'');
71: } else {
72: return ();
73: }
74: }
75:
1.8 www 76: # ---------------------------------------------------------------- View Handler
77:
78: sub viewmap {
1.9 www 79: my ($r,$url)=@_;
1.8 www 80: $r->print('<html>');
81: if ($ENV{'form.forceselect'}) { $r->print(<<ENDSCRIPT);
82: <script>
83:
84: function select_group() {
1.12 www 85: window.location="/adm/groupsort?catalogmode=groupsec&mode=rat&acts="+document.forms.fileattr.acts.value;
1.8 www 86: }
87:
88: function queue(val) {
89: if (eval("document.forms."+val+".filelink.checked")) {
90: var l=val.length;
91: var v=val.substring(4,l);
92: document.forms.fileattr.acts.value+='1a'+v+'b';
93: }
94: else {
95: var l=val.length;
96: var v=val.substring(4,l);
97: document.forms.fileattr.acts.value+='0a'+v+'b';
98: }
99: }
100:
101: </script>
102: ENDSCRIPT
103: }
1.14 www 104: $r->print(&Apache::loncommon::bodytag('Map Contents').'<h1>'.$url.'</h1>');
1.12 www 105: # ------------------ This is trying to select. Provide buttons and tie %selhash
1.8 www 106: if ($ENV{'form.forceselect'}) { $r->print(<<ENDSELECT);
107: <form name=fileattr><input type=hidden name=acts value=''>
108: <input type="button" name="close" value='CLOSE' onClick="self.close()">
109: <input type="button" name="groupimport" value='GROUP IMPORT'
110: onClick="javascript:select_group()">
111: </form>
112: ENDSELECT
1.12 www 113: my $diropendb =
114: "/home/httpd/perl/tmp/$ENV{'user.domain'}\_$ENV{'user.name'}_groupsec.db";
1.13 albertel 115: if (tie(%selhash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
1.12 www 116: if ($ENV{'form.launch'} eq '1') {
117: &start_fresh_session();
118: }
119: $successtied=1;
120:
121: # - Evaluate actions from previous page (both cumulatively and chronologically)
122: if ($ENV{'form.catalogmode'} eq 'groupimport') {
123: my $acts=$ENV{'form.acts'};
124: my @Acts=split(/b/,$acts);
125: my %ahash;
126: my %achash;
127: my $ac=0;
128: # some initial hashes for working with data
129: foreach (@Acts) {
130: my ($state,$ref)=split(/a/);
131: $ahash{$ref}=$state;
132: $achash{$ref}=$ac;
133: $ac++;
134: }
135: # sorting through the actions and changing the tied database hash
136: foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) {
137: my $key=$_;
138: if ($ahash{$key} eq '1') {
139: $selhash{'store_'.$selhash{'pre_'.$key.'_link'}}=
140: $selhash{'pre_'.$key.'_title'};
141: $selhash{'storectr_'.$selhash{'pre_'.$key.'_link'}}=
142: $selhash{'storectr'}+0;
143: $selhash{'storectr'}++;
144: }
145: if ($ahash{$key} eq '0') {
146: if ($selhash{'store_'.$selhash{'pre_'.$key.'_link'}}) {
147: delete $selhash{'store_'.$selhash{'pre_'.$key.'_link'}};
148: }
149: }
150: }
151: # deleting the previously cached listing
152: foreach (keys %selhash) {
153: if ($_ =~ /^pre_/ && $_ =~/link$/) {
154: my $key = $_;
155: $key =~ s/^pre_//;
156: $key =~ s/_[^_]*$//;
157: delete $selhash{'pre_'.$key.'_title'};
158: delete $selhash{'pre_'.$key.'_link'};
159: }
160: }
161: }
162: # -
163: }
1.8 www 164: }
1.12 www 165: # ----------------------------- successtied is now '1' if in working selectmode
1.15 www 166: my ($errtext,$fatal)=&mapread(&Apache::lonnet::filelocation('',$url),'');
167: if ($fatal==1) {
1.16 ! www 168: $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
1.15 www 169: }
1.8 www 170: my $idx=0;
171: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
172: if (defined($_)) {
173: $idx++;
1.12 www 174: if ($successtied) {
1.8 www 175: $r->print('<form name="form'.$idx.'">');
176: }
177: my ($title,$url)=split(/\:/,$_);
178: $title=~s/\&colon\;/\:/g;
179: $url=~s/\&colon\;/\:/g;
180: unless ($title) { $title=(split(/\//,$url))[-1] };
1.16 ! www 181: unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
1.8 www 182: if ($url) {
1.12 www 183: if ($successtied) {
184: my $checked='';
185: if ($selhash{'store_'.$url}) {
186: $checked=" checked";
187: }
188: $selhash{"pre_${idx}_link"}=$url;
189: $selhash{"pre_${idx}_title"}=$title;
190:
1.8 www 191: $r->print(<<ENDCHECKBOX);
192: <input type='checkbox' name='filelink'
1.12 www 193: value='$url' onClick='javascript:queue("form$idx")'$checked>
1.8 www 194: <input type='hidden' name='title' value='$title'>
195: ENDCHECKBOX
196: }
197: $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
198: }
199: $r->print(&Apache::lonratsrv::qtescape($title));
200: if ($url) { $r->print('</a>'); }
1.12 www 201: if ($successtied) {
1.8 www 202: $r->print('</form>');
203: } else {
204: $r->print('<br>');
205: }
206: }
207: }
208: $r->print('</body></html>');
1.12 www 209: if ($successtied) {
210: untie %selhash;
211: }
1.8 www 212: }
213:
1.12 www 214: # ----------------------------------------------------------- Clean out selhash
215: sub start_fresh_session {
216: foreach (keys %selhash) {
217: if ($_ =~ /^pre_/) {
218: delete $selhash{$_};
219: }
220: if ($_ =~ /^store/) {
221: delete $selhash{$_};
222: }
223: }
224: }
225:
226:
1.1 www 227: # ================================================================ Main Handler
228:
229: sub handler {
230: my $r=shift;
231:
232: if ($r->header_only) {
1.16 ! www 233: &Apache::loncommon::content_type($r,'text/html');
1.1 www 234: $r->send_http_header;
235: return OK;
236: }
1.8 www 237:
238: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.12 www 239: ['forceselect','launch']);
1.1 www 240:
1.2 www 241: my %hash;
1.1 www 242: my %bighash;
1.2 www 243: my $requrl=$r->uri;
244:
1.12 www 245: $successtied=0;
1.3 www 246: # ------------------------------------------------------------ Tie symb db file
1.9 www 247: my $disurl='';
248: my $dismapid='';
249:
250: if (($ENV{'request.course.fn'}) && (!$ENV{'form.forceselect'})) {
1.2 www 251: my $last;
252: if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.'_symb.db',
1.13 albertel 253: &GDBM_READER(),0640)) {
1.2 www 254: $last=$hash{'last_direction'};
255: untie(%hash);
256: }
1.3 www 257: my $direction='';
258: my $prevmap='';
259: if ($last) {
260: ($prevmap,$direction)=(split(/\_\_\_/,$last));
261: }
262: # ------------------------------------------------------------- Tie big db file
1.1 www 263: if (tie(%bighash,'GDBM_File',$ENV{'request.course.fn'}.'.db',
1.13 albertel 264: &GDBM_READER(),0640)) {
1.3 www 265: my $disid='';
1.10 www 266:
1.3 www 267: if ($direction eq 'back') {
268: $disid=$bighash{'map_finish_'.$requrl};
269: } else {
270: $disid=$bighash{'map_start_'.$requrl};
271: }
272: if ($disid) {
273: $disurl=$bighash{'src_'.$disid};
1.4 www 274: $dismapid=(split(/\./,$disid))[1];
1.3 www 275: }
1.11 www 276: # ------------------------- If this is an empty one, skip to next non-empty one
277: if ((!$disurl) && ($disid)) {
278: $direction=($direction?$direction:'forward');
279: ($disid,$requrl)=
280: &Apache::lonpageflip::fullmove($disid,
281: &Apache::lonnet::declutter($requrl),$direction);
282: if ($disid) {
283: $disurl=$bighash{'src_'.$disid};
284: $dismapid=(split(/\./,$disid))[1];
285: }
286: }
287:
1.3 www 288: # --------------------------------------- Untie hash, make sure to come by here
289: untie(%bighash);
1.9 www 290: }
291: }
292:
293: # now either disurl is set (going to first page), or we need another display
294:
295: if ($disurl) {
1.3 www 296: # -------------------------------------------------- Has first or last resource
1.9 www 297: &Apache::lonnet::symblist($requrl,$disurl => $dismapid,
1.7 www 298: 'last_known' => &Apache::lonnet::declutter($disurl));
1.16 ! www 299: &Apache::loncommon::content_type($r,'text/html');
1.9 www 300: $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl);
301: return REDIRECT;
1.1 www 302: } else {
1.16 ! www 303: &Apache::loncommon::content_type($r,'text/html');
1.9 www 304: $r->send_http_header;
305: &viewmap($r,$requrl);
306: return OK;
1.1 www 307: }
308: }
309:
310: 1;
311: __END__
312:
313:
314:
315:
316:
317:
318:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>