--- rat/lonsequence.pm 2006/06/08 13:56:40 1.27 +++ rat/lonsequence.pm 2009/02/16 13:52:04 1.37 @@ -2,7 +2,7 @@ # # Sequence Handler # -# $Id: lonsequence.pm,v 1.27 2006/06/08 13:56:40 www Exp $ +# $Id: lonsequence.pm,v 1.37 2009/02/16 13:52:04 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,17 +27,20 @@ # http://www.lon-capa.org/ # + + package Apache::lonsequence; use strict; use Apache::lonnet; use Apache::Constants qw(:common :http REDIRECT); use GDBM_File; -use Apache::lonratedt; -use Apache::lonratsrv; -use Apache::lonpageflip; -use Apache::loncommon; +use LONCAPA::map(); +use Apache::lonpageflip(); +use Apache::loncommon(); +use Apache::groupsort(); use Apache::lonlocal; +use HTML::Entities(); my %selhash; my $successtied; @@ -45,10 +48,10 @@ my $successtied; # ----------------------------------------- Attempt to read from resource space sub attemptread { - my $fn=shift; + my ($fn,$unsorted)=@_; &Apache::lonnet::repcopy($fn); if (-e $fn) { - return &Apache::lonratedt::attemptread($fn); + return &LONCAPA::map::attemptread($fn,$unsorted); } else { return (); } @@ -58,7 +61,7 @@ sub mapread { my $fn=shift; &Apache::lonnet::repcopy($fn); if (-e $fn) { - return &Apache::lonratedt::mapread($fn,''); + return &LONCAPA::map::mapread($fn,''); } else { return (); } @@ -114,53 +117,18 @@ ENDSELECT $successtied=1; # - Evaluate actions from previous page (both cumulatively and chronologically) - if ($env{'form.catalogmode'} eq 'import') { - my $acts=$env{'form.acts'}; - my @Acts=split(/b/,$acts); - my %ahash; - my %achash; - my $ac=0; - # some initial hashes for working with data - foreach (@Acts) { - my ($state,$ref)=split(/a/); - $ahash{$ref}=$state; - $achash{$ref}=$ac; - $ac++; - } - # sorting through the actions and changing the tied database hash - foreach (sort {$achash{$a}<=>$achash{$b}} (keys %ahash)) { - my $key=$_; - if ($ahash{$key} eq '1') { - $selhash{'store_'.$selhash{'pre_'.$key.'_link'}}= - $selhash{'pre_'.$key.'_title'}; - $selhash{'storectr_'.$selhash{'pre_'.$key.'_link'}}= - $selhash{'storectr'}+0; - $selhash{'storectr'}++; - } - if ($ahash{$key} eq '0') { - if ($selhash{'store_'.$selhash{'pre_'.$key.'_link'}}) { - delete $selhash{'store_'.$selhash{'pre_'.$key.'_link'}}; - } - } - } - # deleting the previously cached listing - foreach (keys %selhash) { - if ($_ =~ /^pre_/ && $_ =~/link$/) { - my $key = $_; - $key =~ s/^pre_//; - $key =~ s/_[^_]*$//; - delete $selhash{'pre_'.$key.'_title'}; - delete $selhash{'pre_'.$key.'_link'}; - } + if ($env{'form.catalogmode'} eq 'import') { + &Apache::groupsort::update_actions_hash(\%selhash); } - } # - } } # ----------------------------- successtied is now '1' if in working selectmode my ($errtext,$fatal)=&mapread(&Apache::lonnet::filelocation('',$url),''); if ($fatal==1) { - $r->print('

'.&mt('Map contents are not shown in order.').'


'); + $r->print('

' + .&mt('Map contents are not shown in order.') + .'


'); } my $idx=0; foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) { @@ -170,10 +138,15 @@ ENDSELECT $r->print('
'); } my ($title,$url)=split(/\:/,$_); - $title=~s/\&colon\;/\:/g; - $url=~s/\&colon\;/\:/g; - unless ($title) { $title=(split(/\//,$url))[-1] }; - unless ($title) { $title=''.&mt('Empty').''; } + $title = &LONCAPA::map::qtescape($title); + unless ($title) { $title=(split(/\//,$url))[-1] }; + my $enc_title = &HTML::Entities::encode($title,'\'"<>&'); + unless ($title) { + $title=''.&mt('Empty').''; + $enc_title = &mt('Empty'); + } + $url = &LONCAPA::map::qtescape($url); + my $enc_url = &HTML::Entities::encode($url,'\'"<>&'); if ($url) { if ($successtied) { my $checked=''; @@ -182,16 +155,17 @@ ENDSELECT } $selhash{"pre_${idx}_link"}=$url; $selhash{"pre_${idx}_title"}=$title; - + + $url = &HTML::Entities::encode($url, '\'"<>&'); $r->print(< - +value='$enc_url' onClick='javascript:queue("form$idx")'$checked /> + ENDCHECKBOX } - $r->print(''); + $r->print(''); } - $r->print(&Apache::lonratsrv::qtescape($title)); + $r->print($enc_title); if ($url) { $r->print(''); } if ($successtied) { $r->print(''); @@ -308,7 +282,8 @@ sub handler { &Apache::lonnet::symblist($requrl,$disurl => [$disurl,$dismapid], 'last_known' => [$disurl,$dismapid]); &Apache::loncommon::content_type($r,'text/html'); - $r->header_out(Location => 'http://'.$ENV{'HTTP_HOST'}.$disurl); + $r->header_out(Location => &Apache::lonnet::absolute_url($ENV{'SERVER_NAME'}). + $disurl); return REDIRECT; } else { &Apache::loncommon::content_type($r,'text/html'); @@ -352,7 +327,35 @@ ENDNONE 1; __END__ +=head1 NAME + +Apache::lonsequence + +=head1 SYNOPSIS + +Handler for showing sequence objects of +educational resources. + +This is part of the LearningOnline Network with CAPA project +described at http://www.lon-capa.org. + +=head1 SUBROUTINES + +=over + +=item handler() + +=item viewmap() + +=item attemptread() + +=item mapread() + +=item start_fresh_session() + +=back +=cut