#!/usr/local/bin/perl ############################################################################### # Program : ManageTable.cgi # Author : Eric Deutsch # $Id: ManageTable.cgi 4503 2006-03-07 23:45:26Z edeutsch $ # # Description : This CGI program that allows users to # manage the contents of a table. # This means viewing, inserting, updating, # and deleting records. # # SBEAMS is Copyright (C) 2000-2005 Institute for Systems Biology # This program is governed by the terms of the GNU General Public License (GPL) # version 2 as published by the Free Software Foundation. It is provided # WITHOUT ANY WARRANTY. See the full description of GPL terms in the # LICENSE file distributed with this software. # ############################################################################### ############################################################################### # Set up all needed modules and objects ############################################################################### use strict; use Getopt::Long; use FindBin; use lib "$FindBin::Bin/../../lib/perl"; use vars qw ($sbeams $sbeamsMOD $utilities $q $dbh $current_contact_id $current_username $PROG_NAME $USAGE %OPTIONS $QUIET $VERBOSE $DEBUG $DATABASE $current_work_group_id $current_work_group_name $current_project_id $current_project_name $TABLE_NAME $PROGRAM_FILE_NAME $CATEGORY $DB_TABLE_NAME $PK_COLUMN_NAME @MENU_OPTIONS); use DBI; #use CGI; use CGI::Carp qw(fatalsToBrowser croak); use Data::Dumper; use SBEAMS::Connection qw($q); use SBEAMS::Connection::Settings; use SBEAMS::Connection::Tables; use SBEAMS::Connection::TableInfo; #$q = new CGI; $sbeams = new SBEAMS::Connection; use SBEAMS::SolexaTrans; use SBEAMS::SolexaTrans::Settings; use SBEAMS::SolexaTrans::Tables; use SBEAMS::SolexaTrans::TableInfo; use SBEAMS::SolexaTrans::SolexaUtilities; $sbeamsMOD = new SBEAMS::SolexaTrans; $utilities = new SBEAMS::SolexaTrans::SolexaUtilities; $sbeamsMOD->setSBEAMS($sbeams); $utilities->setSBEAMS($sbeams); $sbeams->setSBEAMS_SUBDIR($SBEAMS_SUBDIR); require 'ManageTable.pllib'; ############################################################################### # Set program name and usage banner for command like use ############################################################################### $PROG_NAME = $FindBin::Script; $USAGE = <InterfaceEntry with pointer to the subroutine to execute if # the authentication succeeds. ############################################################################### sub main { #### Do the SBEAMS authentication and exit if a username is not returned exit unless ($current_username = $sbeams->Authenticate( #connect_read_only=>1, #allow_anonymous_access=>1, #permitted_work_groups_ref=>['Proteomics_user','Proteomics_admin'], )); #### Read in the default input parameters my %parameters; my $n_params_found = $sbeams->parse_input_parameters( q=>$q,parameters_ref=>\%parameters); #$sbeams->printDebuggingInfo($q); #### Process generic "state" parameters before we start $sbeams->processStandardParameters(parameters_ref=>\%parameters); my $project_id = $current_project_id || $sbeams->getCurrent_project_id(); $TABLE_NAME = $parameters{'TABLE_NAME'} || croak "TABLE_NAME not specified."; croak "This TABLE_NAME=$TABLE_NAME cannot be managed by this program." unless ($sbeamsMOD->returnTableInfo($TABLE_NAME, "ManageTableAllowed"))[0] eq "YES"; ($CATEGORY) = $sbeamsMOD->returnTableInfo($TABLE_NAME,"CATEGORY"); ($PROGRAM_FILE_NAME) = $sbeamsMOD->returnTableInfo($TABLE_NAME, "PROGRAM_FILE_NAME"); ($DB_TABLE_NAME) = $sbeamsMOD->returnTableInfo($TABLE_NAME,"DB_TABLE_NAME"); ($PK_COLUMN_NAME) = $sbeamsMOD->returnTableInfo($TABLE_NAME, "PK_COLUMN_NAME"); @MENU_OPTIONS = $sbeamsMOD->returnTableInfo($TABLE_NAME,"MENU_OPTIONS"); # Limit the table below based on info if ($parameters{where_clause}) { if ($parameters{'where_clause'} !~ /project_id/) { my $val = $parameters{'where_clause'}; $val .= "AND project_id = '$project_id'"; $q->param(-name=>'where_clause', -value=>$val); } } else { if ($parameters{"$PK_COLUMN_NAME"}) { $q->param(-name=>'where_clause', -value=>"project_id = '$project_id' AND $PK_COLUMN_NAME = '".$parameters{"$PK_COLUMN_NAME"}."'"); } else { $q->param(-name=>'where_clause', -value=>"project_id = '$project_id'"); } } if ($parameters{'slimseq_sample_id'}) { # $q->param(-name=>'where_clause', -value=>"slimseq_sample_id = '".$parameters{slimseq_sample_id}."'"); my $solexa_sample_id = $utilities->check_sbeams_sample(slimseq_id => $parameters{slimseq_sample_id}); $parameters{solexa_sample_id} = $solexa_sample_id; $q->param(-name=>'solexa_sample_id', -value=>"$solexa_sample_id"); } #### Decide what action to take based on information so far if ($parameters{"GetFile"} && $parameters{"$PK_COLUMN_NAME"}) { getFile(); return; } $sbeamsMOD->printPageHeader(); if ($parameters{action} eq 'VIEWRESULTSET') { printOptions(); } elsif ($parameters{action} eq 'REFRESH') { printEntryForm(); } elsif ($parameters{action} eq 'SAVE TEMPLATE') { saveTemplate(); } elsif ($parameters{action} eq 'SET FIELDS TO THIS TEMPLATE') { printEntryForm(); } elsif ($parameters{action} eq 'DELETE THIS TEMPLATE') { deleteTemplate( selected_template => $parameters{selected_template}, program_file_name => $PROGRAM_FILE_NAME, ); } elsif ($parameters{action}) { processEntryForm(); } elsif ($q->param('apply_action_hidden')) { printEntryForm(); } elsif ($q->param('ShowEntryForm')) { printEntryForm(); } elsif ($parameters{"$PK_COLUMN_NAME"}) { printEntryForm(); } else { printOptions(parameters_ref=>\%parameters); } $sbeamsMOD->printPageFooter(); } # end main ############################################################################### # preFormHook # # This is a hook to do some processing before all the lines of data entry # form have been displayed based on the current table name. This might be # used to set some defaults or something. ############################################################################### sub preFormHook { my %args = @_; my $query_parameters_ref = $args{'parameters_ref'}; #### If table XXXX if ($TABLE_NAME eq "XXXX") { $query_parameters_ref->{YYYY} = 'XXXX' unless ($query_parameters_ref->{YYYY}); } #### Otherwise, no special processing, so just return undef return; } # end preFormHook ############################################################################### # postFormHook # # This is a hook to do some processing after all the lines of data entry # form have been displayed but before the table has been closed based on # the current table name. ############################################################################### sub postFormHook { my %args = @_; my $query_parameters_ref = $args{'parameters_ref'}; my %parameters = %{$query_parameters_ref}; #### If table XXXX if ($TABLE_NAME eq "XXXX") { return "An error of some sort $parameters{something} invalid"; } #### Otherwise, no special processing, so just return undef return; } # end postFormHook ############################################################################### # preUpdateDataCheck # # For certain tables, there are additional checks that should be made before # an INSERT or UPDATE is performed. ############################################################################### sub preUpdateDataCheck { my %args = @_; my $query_parameters_ref = $args{'parameters_ref'}; my %parameters = %{$query_parameters_ref}; if ( $parameters{project_id} ) { # General mechanism for tables w/ project_id my $errstr = checkProjectPermission( param_ref => $query_parameters_ref, tname => $TABLE_NAME, dbtname => $DB_TABLE_NAME ); return ( $errstr ) if $errstr; } elsif ($TABLE_NAME eq "XXXX") { return "An error of some sort $parameters{something} invalid"; # } elsif ($TABLE_NAME eq 'ST_SOLEXA_SAMPLE') { # return "Solexa Sample ID not specified" if !$parameters{solexa_sample_id}; # my $errstr = checkPermission(fkey => 'solexa_sample_id', # fval => $parameters{solexa_sample_id}, # pval => $parameters{solexa_sample_id}, # action => $parameters{action}, # tname => $TABLE_NAME # ); # return($errstr) if $errstr; } #### Otherwise, no special processing, so just return empty string return ''; } # end preUpdateDataCheck ############################################################################### # postUpdateOrInsertHook # # This is a hook to do some processing after the record has been updated # or inserted. ############################################################################### sub postUpdateOrInsertHook { my %args = @_; my $query_parameters_ref = $args{'parameters_ref'}; my %parameters = %{$query_parameters_ref}; my $pk_value = $args{'pk_value'}; #### If table XXXX if ($TABLE_NAME eq "XXXX") { return "An error of some sort $parameters{something} invalid"; } #### Otherwise, no special processing, so just return undef return; } # end postUpdateOrInsertHook