Annotation of rat/lonsequence.pm, revision 1.32.2.1
1.1 www 1: # The LearningOnline Network with CAPA
2: #
3: # Sequence Handler
4: #
1.32.2.1! raeburn 5: # $Id: lonsequence.pm,v 1.32 2007/12/01 01:59:54 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:
1.3 www 30: package Apache::lonsequence;
1.1 www 31:
32: use strict;
33: use Apache::lonnet;
1.3 www 34: use Apache::Constants qw(:common :http REDIRECT);
1.1 www 35: use GDBM_File;
1.28 albertel 36: use LONCAPA::map();
37: use Apache::lonpageflip();
38: use Apache::loncommon();
1.31 albertel 39: use Apache::groupsort();
1.16 www 40: use Apache::lonlocal;
1.30 albertel 41: use HTML::Entities();
1.1 www 42:
1.12 www 43: my %selhash;
44: my $successtied;
1.8 www 45:
46: # ----------------------------------------- Attempt to read from resource space
47:
48: sub attemptread {
1.32 albertel 49: my ($fn,$unsorted)=@_;
1.8 www 50: &Apache::lonnet::repcopy($fn);
51: if (-e $fn) {
1.32 albertel 52: return &LONCAPA::map::attemptread($fn,$unsorted);
1.8 www 53: } else {
54: return ();
55: }
56: }
57:
1.15 www 58: sub mapread {
59: my $fn=shift;
60: &Apache::lonnet::repcopy($fn);
61: if (-e $fn) {
1.28 albertel 62: return &LONCAPA::map::mapread($fn,'');
1.15 www 63: } else {
64: return ();
65: }
66: }
67:
1.8 www 68: # ---------------------------------------------------------------- View Handler
69:
70: sub viewmap {
1.9 www 71: my ($r,$url)=@_;
1.26 albertel 72:
73: my $js;
74: if ($env{'form.forceselect'}) {
75: $js = (<<ENDSCRIPT);
76: <script type="text/javascript">
1.8 www 77:
78: function select_group() {
1.12 www 79: window.location="/adm/groupsort?catalogmode=groupsec&mode=rat&acts="+document.forms.fileattr.acts.value;
1.8 www 80: }
81:
82: function queue(val) {
83: if (eval("document.forms."+val+".filelink.checked")) {
84: var l=val.length;
85: var v=val.substring(4,l);
86: document.forms.fileattr.acts.value+='1a'+v+'b';
87: }
88: else {
89: var l=val.length;
90: var v=val.substring(4,l);
91: document.forms.fileattr.acts.value+='0a'+v+'b';
92: }
93: }
94:
95: </script>
96: ENDSCRIPT
97: }
1.26 albertel 98:
99: $r->print(&Apache::loncommon::start_page('Map Contents',$js).
100: '<h1>'.$url.'</h1>');
1.12 www 101: # ------------------ This is trying to select. Provide buttons and tie %selhash
1.24 albertel 102: if ($env{'form.forceselect'}) { $r->print(<<ENDSELECT);
1.8 www 103: <form name=fileattr><input type=hidden name=acts value=''>
104: <input type="button" name="close" value='CLOSE' onClick="self.close()">
105: <input type="button" name="groupimport" value='GROUP IMPORT'
106: onClick="javascript:select_group()">
107: </form>
108: ENDSELECT
1.12 www 109: my $diropendb =
1.27 www 110: "/home/httpd/perl/tmp/$env{'user.domain'}\_$env{'user.name'}_sel_res.db";
1.13 albertel 111: if (tie(%selhash,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
1.24 albertel 112: if ($env{'form.launch'} eq '1') {
1.12 www 113: &start_fresh_session();
114: }
115: $successtied=1;
116:
117: # - Evaluate actions from previous page (both cumulatively and chronologically)
1.31 albertel 118: if ($env{'form.catalogmode'} eq 'import') {
119: &Apache::groupsort::update_actions_hash(\%selhash);
1.12 www 120: }
121: # -
122: }
1.8 www 123: }
1.12 www 124: # ----------------------------- successtied is now '1' if in working selectmode
1.15 www 125: my ($errtext,$fatal)=&mapread(&Apache::lonnet::filelocation('',$url),'');
126: if ($fatal==1) {
1.16 www 127: $r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
1.15 www 128: }
1.8 www 129: my $idx=0;
130: foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
131: if (defined($_)) {
132: $idx++;
1.12 www 133: if ($successtied) {
1.8 www 134: $r->print('<form name="form'.$idx.'">');
135: }
136: my ($title,$url)=split(/\:/,$_);
1.30 albertel 137: $title = &LONCAPA::map::qtescape($title);
138: unless ($title) { $title=(split(/\//,$url))[-1] };
139: my $enc_title = &HTML::Entities::encode($title,'\'"<>&');
140: unless ($title) {
141: $title='<i>'.&mt('Empty').'</i>';
142: $enc_title = &mt('Empty');
143: }
144: $url = &LONCAPA::map::qtescape($url);
145: my $enc_url = &HTML::Entities::encode($url,'\'"<>&');
1.8 www 146: if ($url) {
1.12 www 147: if ($successtied) {
148: my $checked='';
149: if ($selhash{'store_'.$url}) {
150: $checked=" checked";
151: }
152: $selhash{"pre_${idx}_link"}=$url;
153: $selhash{"pre_${idx}_title"}=$title;
1.30 albertel 154:
155: $url = &HTML::Entities::encode($url, '\'"<>&');
1.8 www 156: $r->print(<<ENDCHECKBOX);
157: <input type='checkbox' name='filelink'
1.30 albertel 158: value='$enc_url' onClick='javascript:queue("form$idx")'$checked />
159: <input type='hidden' name='title' value='$enc_title' />
1.8 www 160: ENDCHECKBOX
161: }
1.30 albertel 162: $r->print('<a href="'.$enc_url.'">');
1.8 www 163: }
1.30 albertel 164: $r->print($enc_title);
1.8 www 165: if ($url) { $r->print('</a>'); }
1.12 www 166: if ($successtied) {
1.8 www 167: $r->print('</form>');
168: } else {
169: $r->print('<br>');
170: }
171: }
172: }
1.26 albertel 173: $r->print(&Apache::loncommon::end_page());
1.12 www 174: if ($successtied) {
175: untie %selhash;
176: }
1.8 www 177: }
178:
1.12 www 179: # ----------------------------------------------------------- Clean out selhash
180: sub start_fresh_session {
181: foreach (keys %selhash) {
182: if ($_ =~ /^pre_/) {
183: delete $selhash{$_};
184: }
185: if ($_ =~ /^store/) {
186: delete $selhash{$_};
187: }
188: }
189: }
190:
191:
1.1 www 192: # ================================================================ Main Handler
193:
194: sub handler {
195: my $r=shift;
196:
197: if ($r->header_only) {
1.16 www 198: &Apache::loncommon::content_type($r,'text/html');
1.1 www 199: $r->send_http_header;
200: return OK;
201: }
1.8 www 202:
203: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.12 www 204: ['forceselect','launch']);
1.1 www 205:
1.2 www 206: my %hash;
1.1 www 207: my %bighash;
1.2 www 208: my $requrl=$r->uri;
209:
1.12 www 210: $successtied=0;
1.3 www 211: # ------------------------------------------------------------ Tie symb db file
1.9 www 212: my $disurl='';
213: my $dismapid='';
1.18 raeburn 214: my $exitdisid = '';
215: my $arrow_dir = '';
1.9 www 216:
1.24 albertel 217: if (($env{'request.course.fn'}) && (!$env{'form.forceselect'})) {
1.2 www 218: my $last;
1.24 albertel 219: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1.13 albertel 220: &GDBM_READER(),0640)) {
1.2 www 221: $last=$hash{'last_direction'};
222: untie(%hash);
223: }
1.3 www 224: my $direction='';
225: my $prevmap='';
226: if ($last) {
1.23 albertel 227: ($prevmap,undef,$direction)=&Apache::lonnet::decode_symb($last);
1.3 www 228: }
229: # ------------------------------------------------------------- Tie big db file
1.24 albertel 230: if (tie(%bighash,'GDBM_File',$env{'request.course.fn'}.'.db',
1.13 albertel 231: &GDBM_READER(),0640)) {
1.3 www 232: my $disid='';
1.17 raeburn 233: my $randomout ='';
1.10 www 234:
1.3 www 235: if ($direction eq 'back') {
236: $disid=$bighash{'map_finish_'.$requrl};
237: } else {
238: $disid=$bighash{'map_start_'.$requrl};
1.18 raeburn 239: }
1.3 www 240: if ($disid) {
241: $disurl=$bighash{'src_'.$disid};
1.4 www 242: $dismapid=(split(/\./,$disid))[1];
1.25 albertel 243: if (!$env{'request.role.adv'}) {
244: $randomout = $bighash{'randomout_'.$disid};
245: }
1.24 albertel 246: } elsif (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
1.18 raeburn 247: &GDBM_READER(),0640)) {
248: $last=$hash{'last_known'};
249: untie(%hash);
1.3 www 250: }
1.18 raeburn 251:
252:
1.17 raeburn 253: # ----------- If this is an empty one, or hidden, skip to next non-empty or non-hidden one
1.18 raeburn 254: while ( ((!$disurl) && ($disid)) || ($randomout && $disid) ) {
1.11 www 255: $direction=($direction?$direction:'forward');
256: ($disid,$requrl)=
257: &Apache::lonpageflip::fullmove($disid,
258: &Apache::lonnet::declutter($requrl),$direction);
259: if ($disid) {
260: $disurl=$bighash{'src_'.$disid};
261: $dismapid=(split(/\./,$disid))[1];
1.25 albertel 262: if (!$env{'request.role.adv'}) {
263: $randomout = $bighash{'randomout_'.$disid};
264: }
1.11 www 265: }
266: }
1.18 raeburn 267: $exitdisid = $disid;
268: $arrow_dir = $direction;
1.11 www 269:
1.3 www 270: # --------------------------------------- Untie hash, make sure to come by here
271: untie(%bighash);
1.9 www 272: }
273: }
274:
275: # now either disurl is set (going to first page), or we need another display
276: if ($disurl) {
1.3 www 277: # -------------------------------------------------- Has first or last resource
1.23 albertel 278: &Apache::lonnet::symblist($requrl,$disurl => [$disurl,$dismapid],
279: 'last_known' => [$disurl,$dismapid]);
1.16 www 280: &Apache::loncommon::content_type($r,'text/html');
1.32.2.1! raeburn 281: $r->header_out(Location => &Apache::lonnet::absolute_url($ENV{'SERVER_NAME'}).
! 282: $disurl);
1.9 www 283: return REDIRECT;
1.1 www 284: } else {
1.16 www 285: &Apache::loncommon::content_type($r,'text/html');
1.9 www 286: $r->send_http_header;
1.21 albertel 287: if ($exitdisid eq '' && $arrow_dir ne '') {
1.18 raeburn 288: my %lt =&Apache::lonlocal::texthash(
289: 'back' => 'beginning',
290: 'forward' => 'end',
291: 'nere' => 'Next resource could not be displayed',
292: 'goba' => 'Go Back',
293: 'nacc' => 'Navigate Course Content',
294: );
1.26 albertel 295: my $warnmsg = &mt('As all folders and sequences ');
1.18 raeburn 296: if ($arrow_dir eq 'forward') {
297: $warnmsg .= &mt('following the current resource were empty').',';
298: } elsif ($arrow_dir eq 'back') {
299: $warnmsg .= &mt('preceding the current resource were empty').',';
300: }
301: $warnmsg .= &mt('you have now reached the').' '.$lt{$arrow_dir}.' '.&mt('of the course.');
1.26 albertel 302: my $start_page=
303: &Apache::loncommon::start_page('Empty Folder/Sequence');
304: my $end_page=
305: &Apache::loncommon::end_page();
1.18 raeburn 306: $r->print(<<ENDNONE);
1.26 albertel 307: $start_page
1.18 raeburn 308: <h3>$lt{'nere'}</h3>
309: <p>$warnmsg</p>
310: <ul>
311: <li><a href="javascript:history.go(-1)">$lt{'goba'}</a></li>
312: <li><a href="/adm/navmaps">$lt{'nacc'}</a></li>
313: </ul>
1.26 albertel 314: $end_page
1.18 raeburn 315: ENDNONE
316: } else {
317: &viewmap($r,$requrl);
318: }
1.9 www 319: return OK;
1.1 www 320: }
321: }
322:
323: 1;
324: __END__
325:
326:
327:
328:
329:
330:
331:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>