]> git.donarmstrong.com Git - biopieces.git/blobdiff - www/index.cgi
added permalink to BGB
[biopieces.git] / www / index.cgi
index 0da25999dfc111cedc77cec42144471291e40dd1..57982acc34779854793bc5869fd29f5a837ee8e0 100755 (executable)
@@ -33,9 +33,9 @@ use Maasha::Filesys;
 use Maasha::Calc;
 use Maasha::XHTML;
 use Maasha::KISS;
-use Maasha::BBrowser::Session;
-use Maasha::BBrowser::Track;
-use Maasha::BBrowser::Draw;
+use Maasha::BGB::Session;
+use Maasha::BGB::Track;
+use Maasha::BGB::Draw;
 
 my ( $cgi, $cookie, @html );
 
@@ -109,7 +109,7 @@ sub cookie_default
     $cookie->{ 'SESSION_DIR' }     = "Sessions";
     $cookie->{ 'LIST_PAGES' }      = [ qw( clade genome assembly contig browse ) ];
 
-    $cookie->{ 'USER' }            = $cgi->param( 'user' );
+    $cookie->{ 'USER' }            = $cgi->param( 'user' ) || '';
     $cookie->{ 'PASSWORD' }        = $cgi->param( 'password' );
     $cookie->{ 'SESSION_ID' }      = $cgi->param( 'session_id' );
 
@@ -122,6 +122,8 @@ sub cookie_default
     $cookie->{ 'ASSEMBLY' }        = $cgi->param( 'assembly' ) || '';
     $cookie->{ 'CONTIG' }          = $cgi->param( 'contig' )   || '';
     $cookie->{ 'Q_ID' }            = $cgi->param( 'q_id' );
+    $cookie->{ 'NAV_START' }     ||= $cgi->param( 'nav_start' );
+    $cookie->{ 'NAV_END' }       ||= $cgi->param( 'nav_end' );
     $cookie->{ 'S_BEG' }           = $cgi->param( 's_beg' );
     $cookie->{ 'S_END' }           = $cgi->param( 's_end' );
     $cookie->{ 'STRAND' }          = $cgi->param( 'strand' );
@@ -197,12 +199,37 @@ sub cookie_session
 
     my ( $session );
 
-    $session = Maasha::BBrowser::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
-
-    $cookie->{ 'PAGE' } = 'login' if not $cookie->{ 'SESSION_ID' };
-    $cookie->{ 'PAGE' } = 'login' if $cookie->{ 'SESSION_ID' } ne $ENV{ 'SSL_SESSION_ID' };
-    $cookie->{ 'PAGE' } = 'login' if not exists $session->{ $cookie->{ 'USER' } };
-    $cookie->{ 'PAGE' } = 'login' if $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ne $cookie->{ 'SESSION_ID' };
+    $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
+
+    # if ( $cookie->{ 'SESSION_ID' } )
+    # {
+    #     if ( $cookie->{ 'SESSION_ID' } ne $ENV{ 'SSL_SESSION_ID' } ) {
+    #         $cookie->{ 'PAGE' } = 'login';
+    #         print STDERR "HER1"; # DEBUG
+    #     }
+    # }
+    # else
+    # {
+    #     $cookie->{ 'PAGE' } = 'login';
+    # 
+    #     print STDERR "HER2"; # DEBUG
+    # }
+
+    if ( exists $session->{ $cookie->{ 'USER' } } and $cookie->{ 'SESSION_ID' } )
+    {
+        if ( $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ne $cookie->{ 'SESSION_ID' } ) {
+            $cookie->{ 'PAGE' } = 'login';
+            print STDERR "HER3"; # DEBUG
+        }
+    }
+    else
+    {
+        $cookie->{ 'PAGE' } = 'login';
+        print STDERR "HER4"; # DEBUG
+        print STDERR "NO COOKIE SESSION ID\n" if not $cookie->{ 'SESSION_ID' }; # DEBUG
+        print STDERR "NO COOKIE SESSION ID\n" if not $cookie->{ 'USER' }; # DEBUG
+        print STDERR "NO SESSION USER\n"      if not exists $session->{ $cookie->{ 'USER' } }; # DEBUG
+    }
 }
 
 
@@ -220,23 +247,22 @@ sub cookie_login
 
     my ( $session );
 
-    $session = Maasha::BBrowser::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
-    
     if ( $cookie->{ 'USER' } and $cookie->{ 'PASSWORD' } )
     {
+        $session = Maasha::BGB::Session::session_restore( "$cookie->{ 'SESSION_DIR' }/sessions.txt" );
+    
         if ( exists $session->{ $cookie->{ 'USER' } } and
              $session->{ $cookie->{ 'USER' } }->{ 'PASSWORD' } eq Digest::MD5::md5_hex( $cookie->{ 'PASSWORD' } ) )
         {
-            # $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ||= Maasha::BBrowser::Session::session_new();
-            $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' }   = $ENV{ 'SSL_SESSION_ID' };
+            $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' } ||= Maasha::BGB::Session::session_new();
+            $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' }   = $ENV{ 'SSL_SESSION_ID' };
             $session->{ $cookie->{ 'USER' } }->{ 'TIME' }         = Maasha::Common::time_stamp();
 
             $cookie->{ 'SESSION_ID' } = $session->{ $cookie->{ 'USER' } }->{ 'SESSION_ID' };
             $cookie->{ 'LOGIN' }      = "OK";
-            $cookie->{ 'USER' }       = $cookie->{ 'USER' };
             $cookie->{ 'PAGE' }       = 'clade'; 
 
-            Maasha::BBrowser::Session::session_store( "$cookie->{ 'SESSION_DIR' }/sessions.txt", $session );
+            Maasha::BGB::Session::session_store( "$cookie->{ 'SESSION_DIR' }/sessions.txt", $session );
         }
         else
         {
@@ -285,7 +311,7 @@ sub cookie_end
 
     my ( $max );
     
-    $max = Maasha::Filesys::file_size( Maasha::BBrowser::Track::path_seq( $cookie ) );
+    $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
 
     if ( defined $cookie->{ 'NAV_END' } )
     {
@@ -313,7 +339,7 @@ sub cookie_zoom
 
     my ( $max, $dist, $new_dist, $dist_diff );
 
-    $max = Maasha::Filesys::file_size( Maasha::BBrowser::Track::path_seq( $cookie ) );
+    $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
 
     $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
 
@@ -356,7 +382,7 @@ sub cookie_move
 
     my ( $max, $dist, $shift, $new_start, $new_end );
 
-    $max = Maasha::Filesys::file_size( Maasha::BBrowser::Track::path_seq( $cookie ) );
+    $max = Maasha::Filesys::file_size( Maasha::BGB::Track::path_seq( $cookie ) );
 
     $dist = $cookie->{ 'NAV_END' } - $cookie->{ 'NAV_START' };
 
@@ -418,7 +444,7 @@ sub cookie_href
         last;
     }
 
-    if ( defined $cookie->{ 'NAV_START' } and defined $cookie->{ 'NAV_END' } ) {
+    if ( defined $cookie->{ 'NAV_START' } and defined $cookie->{ 'NAV_END' } and $page !~ /clade|genome|assembly|contig|browse/ ) {
         $href_hash{ "nav_search" } = "$cookie->{ 'NAV_START' }-$cookie->{ 'NAV_END' }";
     }
 
@@ -490,7 +516,9 @@ sub page
         push @html, page_taxonomy( $cookie );
     }
 
-    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => "$cookie->{ 'SESSION_ID' }" ) );
+    if ( $cookie->{ 'SESSION_ID' } ) {
+        push @html, Maasha::XHTML::p( txt => Maasha::XHTML::hidden( name => "session_id", value => "$cookie->{ 'SESSION_ID' }" ) );
+    }
 
     return wantarray ? @html : \@html;
 }
@@ -551,6 +579,7 @@ sub page_browse
     push @html, section_taxonomy_table( $cookie );
     push @html, section_navigate( $cookie );
     push @html, section_browse( $cookie );
+    push @html, section_permalink( $cookie );
 
     return wantarray ? @html : \@html;
 }
@@ -785,16 +814,16 @@ sub section_browse
 
     my ( @tracks, $i, @features, $feat, $elem, $surface, $cr, $png_data, @html, @img );
 
-    push @features, [ Maasha::BBrowser::Track::track_ruler( $cookie ) ];
-    push @features, [ Maasha::BBrowser::Track::track_seq( $cookie ) ];
+    push @features, [ Maasha::BGB::Track::track_ruler( $cookie ) ];
+    push @features, [ Maasha::BGB::Track::track_seq( $cookie ) ];
 
-    @tracks = Maasha::BBrowser::Track::path_tracks( $cookie );
+    @tracks = Maasha::BGB::Track::path_tracks( $cookie );
 
     for ( $i = 0; $i < @tracks; $i++ )
     {
-        $cookie->{ 'FEAT_COLOR' } = Maasha::BBrowser::Draw::palette( $i );
+        $cookie->{ 'FEAT_COLOR' } = Maasha::BGB::Draw::palette( $i );
 
-        push @features, [ Maasha::BBrowser::Track::track_feature( $tracks[ $i ], $cookie ) ];
+        push @features, [ Maasha::BGB::Track::track_feature( $tracks[ $i ], $cookie ) ];
     }
 
     $surface = Cairo::ImageSurface->create( 'argb32', $cookie->{ 'IMG_WIDTH' }, $cookie->{ 'TRACK_OFFSET' } );
@@ -805,10 +834,10 @@ sub section_browse
     $cr->fill;
 
     foreach $feat ( @features ) {
-        Maasha::BBrowser::Draw::draw_feature( $cr, $feat ) if $feat;
+        Maasha::BGB::Draw::draw_feature( $cr, $feat ) if $feat;
     }
 
-    $png_data = Maasha::BBrowser::Draw::base64_png( $surface );
+    $png_data = Maasha::BGB::Draw::base64_png( $surface );
 
     push @img, Maasha::XHTML::img(
         src    => "data:image/png;base64,$png_data",
@@ -853,6 +882,37 @@ sub section_browse
 }
 
 
+sub section_permalink
+{
+    # Martin A. Hansen, December 2009.
+
+    # Return HTML with a permanent link to current browser view.
+
+    my ( $cookie,   # cookie hash
+       ) = @_;
+
+    # Returns a list.
+
+    my ( $href, @html );
+
+    $href = join( "&",
+        "$cookie->{ 'SCRIPT' }?page=browse",
+        "user=$cookie->{ 'USER' }",
+        "clade=$cookie->{ 'CLADE' }",
+        "genome=$cookie->{ 'GENOME' }",
+        "assembly=$cookie->{ 'ASSEMBLY' }",
+        "contig=$cookie->{ 'CONTIG' }",
+        "nav_start=$cookie->{ 'NAV_START' }",
+        "nav_end=$cookie->{ 'NAV_END' }",
+        "session_id=$cookie->{ 'SESSION_ID' }",
+    );
+
+    push @html, Maasha::XHTML::p( txt => Maasha::XHTML::ln( txt => "Permalink", href => $href ), class => 'center' );
+
+    return wantarray ? @html : \@html;
+}
+
+
 sub section_export
 {
     # Martin A. Hansen, November 2009.
@@ -904,7 +964,7 @@ sub section_search
 
     my ( $results, $result, $count, @html, $export, $browse );
 
-    $results = Maasha::BBrowser::Track::search_tracks( $cookie );
+    $results = Maasha::BGB::Track::search_tracks( $cookie );
 
     $count = scalar @{ $results };
 
@@ -973,8 +1033,8 @@ sub section_dna
     $beg =~ tr/,//d;
     $end =~ tr/,//d;
 
-    $seq = ">$cookie->{ 'CONTIG' }_$beg" . "_$end" . "_$cookie->{ 'STRAND' }\n";
-    $seq .= Maasha::BBrowser::Track::dna_get( $cookie );
+    $seq = join ";", ">$cookie->{ 'GENOME' }", $cookie->{ 'ASSEMBLY' }, $cookie->{ 'CONTIG' }, $beg, $end, "$cookie->{ 'STRAND' }\n";
+    $seq .= Maasha::BGB::Track::dna_get( $cookie );
 
     push @html, Maasha::XHTML::h2( txt => "DNA", class => 'center' );
     push @html, Maasha::XHTML::pre( txt => $seq );