[Bio] / FigWebServices / frame.cgi Repository:
ViewVC logotype

View of /FigWebServices/frame.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (download) (annotate)
Thu Feb 23 21:38:42 2006 UTC (14 years, 3 months ago) by paczian
Branch: MAIN
Changes since 1.5: +37 -27 lines
*** empty log message ***

##################################################
# includes
##################################################
use warnings;
use strict;

use CGI qw(:standard);
use HTML::Template;
use Data::Dumper;

use FIG;
use FIG_Config;
use FIG_CGI;
use UserData;

use FigWebServices::SeedComponents;

##################################################
# handle exceptions
##################################################

eval {
  &main();
};

if($@) {
  print header(),start_html();
  print STDERR "EXCEPTION: $@\n";
  print "EXCEPTION: $@\n",end_html();
}

1;

##################################################
# main subroutine
##################################################

sub main {
  
  # set environment variables
  if (! $ENV{"BLASTMAT"}) { $ENV{"BLASTMAT"} = "$FIG_Config::blastmat" }

  # constant variables
  use constant DOCUMENT_ROOT => "$FIG_Config::fig/CGI/Html/";
  use constant TEMPLATE_PATH => DOCUMENT_ROOT;
  use constant USER_DIR      => "$FIG_Config::global/Users/";
  use constant FIG_DISK      => "$FIG_Config::fig_disk/";
  use constant FIG_TEMP      => "$FIG_Config::temp/";
  use constant FIG_ORGANISMS => "$FIG_Config::organisms/";
  use constant FIG_EXTBIN    => "$FIG_Config::ext_bin/";
  use constant FIG_NR        => "$FIG_Config::global/nr";


  # check if the user directory exists, else create it
  mkdir USER_DIR, 0777 unless (-e USER_DIR);

  # initialize content variables
  my $document_base = "./Html/";
  my $image_base    = $document_base;
  my $configuration = "";

  my $title         = "";
  my $menu          = "";
  my $session       = "";
  my $logo          = "";
  my $content       = "";
  my $action        = "";

  
  # initialize fig object
  my ($fig, $cgi, $user) = FIG_CGI::init(debug_save   => 0,
					 debug_load   => 0,
					 print_params => 0);

  # initialize params hash
  my $params = { document_base  => $document_base,
		 image_base     => $image_base,
		 cgi            => $cgi,
		 fig            => $fig,
		 fig_disk       => FIG_DISK,
		 fig_temp       => FIG_TEMP,
		 fig_organisms  => FIG_ORGANISMS,
		 fig_extbin     => FIG_EXTBIN,
		 fig_nr         => FIG_NR,
		 user_directory => USER_DIR
	       };

  # check for logged in user
  $user = "Guest";
  if (defined($cgi->param("user"))) {
    $user = $cgi->param("user");
  }
  $params->{user} = $user;

  # load configuration
  my $preferences = FigWebServices::SeedComponents::Framework::get_preferences($params);

  # set preferences params
  my $preferences_params = { preferences    => $preferences,
			     user           => $user,
			     user_directory => USER_DIR };

  # check for new user  
  unless (exists($preferences->{'framework:start_page'})) {
    
    # set default preferences
    $preferences = get_defaultpreferences($params);
    $preferences_params->{preferences} = $preferences;
    
    # write preferences to file
    FigWebServices::SeedComponents::Framework::set_preferences($preferences_params);
  }

  # check for change of preferences
  if (defined($cgi->param("set_startpage"))) {
    $preferences->{'framework:start_page'} = $cgi->param("page");
    FigWebServices::SeedComponents::Framework::set_preferences($preferences_params);
    $content .= FigWebServices::SeedComponents::Framework::get_message("You have successfully set your startpage to this page.");
  } elsif (defined($cgi->param("config"))) {
    $preferences->{'framework:menu_layout'} = $cgi->param("layout");
    FigWebServices::SeedComponents::Framework::set_preferences($preferences_params);
    $content .= FigWebServices::SeedComponents::Framework::get_message("You have successfully changed your settings");
  }
  
  # set configuration variable
  $configuration = $preferences->{'framework:menu_layout'};

  # set background information for all forms to post
  $params->{background_information} = "<input type='hidden' name='user' value='" . $user . "'>";

  # store user preferences
  $params->{user_preferences} = $preferences;

  # create configuration button
  my $config_button = qq~<td id='login'><img src="~ . $params->{image_base} . qq~config.gif" onclick="go_configmode();" class="login"></td>~;

  # check for action, otherwise set action to startpage
  if (defined($cgi->param("action"))) {
    $action = $cgi->param("action");
  } else {
    
    # workaround for links to the protein page to pipe through frame.cgi
    if (defined($cgi->param("prot"))) {
      $action = "proteinpage";
    } else {
      $action = $params->{user_preferences}->{'framework:start_page'};
    }
  }
  $params->{action} = $action;

  # disable configuration for user Guest
  if ($user eq "Guest") {
    $config_button = "";
  }
  
  # set session html
  $session = qq~
<form method='post' action='frame.cgi' name='login_form'>
<table width=100%>
   <tr><td colspan=3 style="border-top: 1px solid lightblue;"></td></tr>
   <tr style="vertical-align: bottom;">
      <td width='40px' height='28px'><b>User:</b></td><td width='100%'><input type='text' name='user' value='~ . $user . qq~' style="width: 100px;">~;

  # store current cgi
  my @old_cgi;
  my @names = $cgi->param;
  foreach my $name (@names) {
    unless (($name eq "layout") or ($name eq "config")) {
      push(@old_cgi, { 'preserve_name' => $name, 'preserve_value' => $cgi->param($name) } );

      # store current params in login form
      unless ($name eq "user") {
	$session .= "<input type='hidden' name='" . $name . "' value='" . $cgi->param($name) . "'>";
      }
    }
  }

  # finish session html
  $session .= qq~</td>~ . $config_button . qq~
   </tr>
</table>
</form>
~;

#################
# Modify this section to add new actions
#################


  # process current action
  if ($action eq "welcome") {
    $content .= FigWebServices::SeedComponents::Framework::get_welcome($params);
    $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
  } elsif ($action eq "overview") {
    $content .= FigWebServices::SeedComponents::Framework::get_overview($params);
    $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
  } elsif ($action eq "show_organism") {
    if ($cgi->param("organism_action") eq "statistics") {
      $content .= qq~<img src="~ . $params->{image_base} . qq~clear.gif" onload="window.top.location='genome_statistics.cgi?genome=~ . $cgi->param("genome") . qq~&user=~ . $user . qq~'">~;
    } else {
      $content .= qq~<img src="~ . $params->{image_base} . qq~clear.gif" onload="window.top.location='genome_statistics.cgi?genome=~ . $cgi->param("genome") . qq~&request=show_subsystems&user=~ . $user . qq~'">~; 
    }
    $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
  } elsif ($action eq "align_sequences") {
    $content .= FigWebServices::SeedComponents::Framework::get_alignsequences($params);
    $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
  } elsif ($action eq "funcrole_candidates") {
    $content .= FigWebServices::SeedComponents::Framework::get_funcrolecandidates($params);
    $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
  } elsif ($action eq "locate_pegs") {
    $content .= FigWebServices::SeedComponents::Framework::get_locatepegs($params);
    $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
  } elsif ($action eq "export_assignments") {
    $content .= FigWebServices::SeedComponents::Framework::get_exportassignments($params);
    $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
  } elsif ($action eq "process_assignments") {
    $content .= FigWebServices::SeedComponents::Framework::get_processassignments($params);
    $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
  } elsif ($action eq "execute_blast") {
    $content .= FigWebServices::SeedComponents::Basic::get_blastresult($params);
    $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
  } elsif ($action eq "proteinpage") {
    my ($main, $functions) = FigWebServices::SeedComponents::Protein::get_proteinpage($params);
    $content .= $main;
    $menu .= $functions;
  }

  # generate common content
  $title .= FigWebServices::SeedComponents::Framework::get_title($params);
  $logo  .= FigWebServices::SeedComponents::Framework::get_logo($params);
  $menu  .= FigWebServices::SeedComponents::Framework::get_menu($params);

  # create output template
  my $template = HTML::Template->new(filename => TEMPLATE_PATH . 'frame.tmpl');

  # insert content into template
  $template->param(document_base => $document_base);
  $template->param(image_base    => $image_base);
  $template->param(configuration => $configuration);
  $template->param(title         => $title);
  $template->param(menu          => $menu);
  $template->param(session       => $session);
  $template->param(logo          => $logo);
  $template->param(content       => $content);
  $template->param(preserve      => \@old_cgi);

  # output the page
  print header();
  print $template->output();
}

sub get_defaultpreferences {
  my ($params) = @_;
  
  my $preferences = {};

  $preferences->{'framework:start_page'}              = "welcome";
  $preferences->{'framework:menu_layout'}             = "extlinks,element,1,1,blue;intlinks,element,1,1,blue;services,element,1,1,blue;neighborhood,group,1,0,0,1,0,0,1,1,0,0,0,1,1;contig_context,section,0;identicalproteins,section,0;compare_region,section,0;subsystems_connections,section,0;relatedlinks,section,0;proteinfamilies,section,0;identicalproteins_table,group,1,1,1,1,1;proteinfamilies_table,group,1,1,1;subsystems_connections_table,group,1,1,1;relatedlinks_table,group,1,1,1,1,1;similarities_table,group,1,1,1,1,1,1,1,1,1,1,1;";
  $preferences->{'framework:sort_subsystem'}          = "by_phylo";
  $preferences->{'framework:show_clusters_subsystem'} = "1";

  return $preferences;
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3