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

Diff of /FigWebServices/frame.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2, Tue Feb 14 19:54:22 2006 UTC revision 1.3, Wed Feb 22 19:54:17 2006 UTC
# Line 1  Line 1 
   
1  ##################################################  ##################################################
2  # includes  # includes
3  ##################################################  ##################################################
# Line 7  Line 6 
6    
7  use CGI qw(:standard);  use CGI qw(:standard);
8  use HTML::Template;  use HTML::Template;
9    use Data::Dumper;
10    
11  use FIG;  use FIG;
12  use FIG_Config;  use FIG_Config;
13  use FIG_CGI;  use FIG_CGI;
14    use UserData;
15    
16  use FigWebServices::SeedComponents;  use FigWebServices::SeedComponents;
17    
# Line 23  Line 24 
24  };  };
25    
26  if($@) {  if($@) {
     my $ex = $@;  
27    print header(),start_html();    print header(),start_html();
28    print STDERR "EXCEPTION: $ex\n";    print STDERR "EXCEPTION: $@\n";
29    print "EXCEPTION: $ex\n",end_html();    print "EXCEPTION: $@\n",end_html();
30  }  }
31    
32  1;  1;
# Line 37  Line 37 
37    
38  sub main {  sub main {
39    
40      # set environment variables
41      if (! $ENV{"BLASTMAT"}) { $ENV{"BLASTMAT"} = "$FIG_Config::blastmat" }
42    
43    # constant variables    # constant variables
44    use constant DOCUMENT_ROOT => "$FIG_Config::fig/CGI/Html/";    use constant DOCUMENT_ROOT => "$FIG_Config::fig/CGI/Html/";
45    use constant TEMPLATE_PATH => DOCUMENT_ROOT;    use constant TEMPLATE_PATH => DOCUMENT_ROOT;
46    use constant USER_DIR      => "$FIG_Config::fig/var/Users/";    use constant USER_DIR      => "$FIG_Config::global/Users/";
47      use constant FIG_DISK      => "$FIG_Config::fig_disk/";
48      use constant FIG_TEMP      => "$FIG_Config::temp/";
49      use constant FIG_ORGANISMS => "$FIG_Config::organisms/";
50      use constant FIG_EXTBIN    => "$FIG_Config::ext_bin/";
51      use constant FIG_NR        => "$FIG_Config::global/nr";
52    
53    # initialize content variables    # initialize content variables
54    my $document_base = "./Html/";    my $document_base = "./Html/";
55    my $image_base    = $document_base;    my $image_base    = $document_base;
 #  my $image_base    = $document_base . "images/";  
56    my $configuration = "";    my $configuration = "";
   my $preferences   = {};  
57    
58    my $title         = "";    my $title         = "";
59    my $menu          = "";    my $menu          = "";
60    my $session       = "";    my $session       = "";
61    my $logo          = "";    my $logo          = "";
62    my $content       = "";    my $content       = "";
63      my $action        = "";
64    
65    
66    # initialize fig object    # initialize fig object
67    my ($fig, $cgi, $user) = FIG_CGI::init(debug_save   => 0,    my ($fig, $cgi, $user) = FIG_CGI::init(debug_save   => 0,
# Line 63  Line 71 
71    # initialize params hash    # initialize params hash
72    my $params = { document_base => $document_base,    my $params = { document_base => $document_base,
73                   image_base    => $image_base,                   image_base    => $image_base,
74                     cgi            => $cgi,
75                   fig           => $fig,                   fig           => $fig,
76                   cgi           => $cgi            };                   fig_disk       => FIG_DISK,
77                     fig_temp       => FIG_TEMP,
78                     fig_organisms  => FIG_ORGANISMS,
79                     fig_extbin     => FIG_EXTBIN,
80                     fig_nr         => FIG_NR,
81                     user_directory => USER_DIR
82                   };
83    
84    # check for logged in user    # check for logged in user
85    $user = "Guest";    $user = "Guest";
# Line 73  Line 88 
88    }    }
89    $params->{user} = $user;    $params->{user} = $user;
90    
91      # load configuration
92      my $preferences = FigWebServices::SeedComponents::Framework::get_preferences($params);
93    
94      # set preferences params
95      my $preferences_params = { preferences    => $preferences,
96                                 user           => $user,
97                                 user_directory => USER_DIR };
98    
99      # check for new user
100      unless (exists($preferences->{'framework:start_page'})) {
101    
102        # set default preferences
103        $preferences = get_defaultpreferences($params);
104        $preferences_params->{preferences} = $preferences;
105    
106        # write preferences to file
107        FigWebServices::SeedComponents::Framework::set_preferences($preferences_params);
108      }
109    
110      # check for change of preferences
111      if (defined($cgi->param("set_startpage"))) {
112        $preferences->{'framework:start_page'} = $cgi->param("page");
113        FigWebServices::SeedComponents::Framework::set_preferences($preferences_params);
114        $content .= FigWebServices::SeedComponents::Framework::get_message("You have successfully set your startpage to this page.");
115      } elsif (defined($cgi->param("config"))) {
116        $preferences->{'framework:menu_layout'} = $cgi->param("layout");
117        FigWebServices::SeedComponents::Framework::set_preferences($preferences_params);
118        $content .= FigWebServices::SeedComponents::Framework::get_message("You have successfully changed your settings");
119      }
120    
121      # set configuration variable
122      $configuration = $preferences->{'framework:menu_layout'};
123    
124      # set background information for all forms to post
125      $params->{background_information} = "<input type='hidden' name='user' value='" . $user . "'>";
126    
127      # store user preferences
128      $params->{user_preferences} = $preferences;
129    
130      # create configuration button
131      my $config_button = qq~<td id='login'><img src="~ . $params->{image_base} . qq~config.gif" onclick="go_configmode();" class="login"></td>~;
132    
133      # disable configuration for user Guest
134      if ($user eq "Guest") {
135        $config_button = "";
136      }
137    
138    # set session html    # set session html
139    $session = qq~    $session = qq~
140  <form method='post' action='frame.cgi' name='login_form'>  <form method='post' action='frame.cgi' name='login_form'>
141  <table width=100%>  <table width=100%>
142     <tr><td colspan=3 style="border-top: 1px solid #000088;"></td></tr>     <tr><td colspan=3 style="border-top: 1px solid #000088;"></td></tr>
143     <tr style="vertical-align: bottom;">     <tr style="vertical-align: bottom;">
144        <td width='40px' height='28px'><b>User:</b></td><td width='100%'><input type='text' name='user' value='~ . $user . qq~' style="width: 100px;"></td><td id='login'><img src="~ . $params->{image_base} . qq~power.jpg" onclick="document.forms.login_form.submit();" class="login"></td>        <td width='40px' height='28px'><b>User:</b></td><td width='100%'><input type='text' name='user' value='~ . $user . qq~' style="width: 100px;"></td>~ . $config_button . qq~
145     </tr>     </tr>
146  </table>  </table>
147  </form>  </form>
148  ~;  ~;
149    
150    # Ensure config dir and at least Guest's config file is present.    # check for action, otherwise set action to startpage
151      if (defined($cgi->param("action"))) {
152    &FIG::verify_dir(USER_DIR);      $action = $cgi->param("action");
153      } else {
154    my $user_conf = USER_DIR . $user;  
155    if (! -f $user_conf)      # workaround for links to the protein page to pipe through frame.cgi
156    {      if (defined($cgi->param("prot"))) {
157        open(FH, ">$user_conf");        $action = "proteinpage";
158        print FH qq(extlinks,element,1,1,blue;intlinks,element,1,1,blue;services,element,1,1,blue;\n);      } else {
159        print FH qq({start_page=>"get_welcome",sort_subsystem=>"by_phylo",show_clusters_subsystem=>1}\n);        $action = $params->{user_preferences}->{'framework:start_page'};
160  END      }
161    }    }
162      $params->{action} = $action;
163    # load configuration  
164    open(FH, USER_DIR . $user) or die "Could not open configuration file";  #################
165    my @conf;  # Modify this section to add new actions
166    while (<FH>) {  #################
     push(@conf, $_);  
   }  
   $configuration = $conf[0];  
   $preferences   = $conf[1];  
   
   # set background information for all forms to post  
   $params->{background_information} = "<input type='hidden' name='user' value='" . $user . "'>";  
167    
   # store user preferences  
   $params->{user_preferences} = eval($preferences);  
168    
169    # process current action    # process current action
170    unless (defined($cgi->param("action"))) {    if ($action eq "welcome") {
171      $content = eval("FigWebServices::SeedComponents::Basic::" . $params->{user_preferences}->{start_page} . "(\$params)");      $content .= FigWebServices::SeedComponents::Framework::get_welcome($params);
172    } elsif ($cgi->param("action") eq "textsearch") {      $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
173      $content = "You searched for " . $cgi->param("textsearch");    } elsif ($action eq "overview") {
174    } elsif ($cgi->param("action") eq "select_organism") {      $content .= FigWebServices::SeedComponents::Framework::get_overview($params);
175      $content = "You want to browse " . $cgi->param("organism");      $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
176    } elsif ($cgi->param("action") eq "select_subsystem") {    } elsif ($action eq "show_organism") {
177      $content = "You want to browse " . $cgi->param("subsystem");      if ($cgi->param("organism_action") eq "statistics") {
178          $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~'">~;
179        } else {
180          $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~'">~;
181        }
182        $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
183      } elsif ($action eq "align_sequences") {
184        $content .= FigWebServices::SeedComponents::Framework::get_alignsequences($params);
185        $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
186      } elsif ($action eq "funcrole_candidates") {
187        $content .= FigWebServices::SeedComponents::Framework::get_funcrolecandidates($params);
188        $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
189      } elsif ($action eq "locate_pegs") {
190        $content .= FigWebServices::SeedComponents::Framework::get_locatepegs($params);
191        $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
192      } elsif ($action eq "export_assignments") {
193        $content .= FigWebServices::SeedComponents::Framework::get_exportassignments($params);
194        $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
195      } elsif ($action eq "process_assignments") {
196        $content .= FigWebServices::SeedComponents::Framework::get_processassignments($params);
197        $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
198      } elsif ($action eq "execute_blast") {
199        $content .= FigWebServices::SeedComponents::Basic::get_blastresult($params);
200        $menu .= FigWebServices::SeedComponents::Framework::get_actionmenu($params);
201      } elsif ($action eq "proteinpage") {
202        my ($main, $functions) = FigWebServices::SeedComponents::Protein::get_proteinpage($params);
203        $content .= $main;
204        $menu .= $functions;
205    }    }
206    
207    # generate common content    # generate common content
208    $title = FigWebServices::SeedComponents::Framework::get_title($params);    $title .= FigWebServices::SeedComponents::Framework::get_title($params);
209    $logo  = FigWebServices::SeedComponents::Framework::get_logo($params);    $logo  .= FigWebServices::SeedComponents::Framework::get_logo($params);
210    $menu  = FigWebServices::SeedComponents::Framework::get_menu($params);    $menu  .= FigWebServices::SeedComponents::Framework::get_menu($params);
211    
212      # store current cgi
213      my @old_cgi;
214      my @names = $cgi->param;
215      foreach my $name (@names) {
216        unless (($name eq "layout") or ($name eq "config")) {
217          push(@old_cgi, { 'preserve_name' => $name, 'preserve_value' => $cgi->param($name) } );
218        }
219      }
220    
221    # create output template    # create output template
222    my $template = HTML::Template->new(filename => TEMPLATE_PATH . 'frame.tmpl');    my $template = HTML::Template->new(filename => TEMPLATE_PATH . 'frame.tmpl');
# Line 141  Line 230 
230    $template->param(session       => $session);    $template->param(session       => $session);
231    $template->param(logo          => $logo);    $template->param(logo          => $logo);
232    $template->param(content       => $content);    $template->param(content       => $content);
233      $template->param(preserve      => \@old_cgi);
234    
235    # output the page    # output the page
236    print header();    print header();
237    print $template->output();    print $template->output();
238  }  }
239    
240    sub get_defaultpreferences {
241      my ($params) = @_;
242    
243      my $preferences = {};
244    
245      $preferences->{'framework:start_page'}              = "welcome";
246      $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,1;";
247      $preferences->{'framework:sort_subsystem'}          = "by_phylo";
248      $preferences->{'framework:show_clusters_subsystem'} = "1";
249    
250      return $preferences;
251    }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3