#!/usr/bin/perl # Create Functions for Perl/PostgreSQL version 1.0 # Copyright 2001, Mark Nielsen # All rights reserved. # This Copyright notice was copied and modified from the Perl # Copyright notice. # This program is free software; you can redistribute it and/or modify # it under the terms of either: # a) the GNU General Public License as published by the Free # Software Foundation; either version 1, or (at your option) any # later version, or # b) the "Artistic License" which comes with this Kit. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either # the GNU General Public License or the Artistic License for more details. # You should have received a copy of the Artistic License with this # Kit, in the file named "Artistic". If not, I'll be glad to provide one. # You should also have received a copy of the GNU General Public License # along with this program in the file named "Copying". If not, write to the # Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA # 02111-1307, USA or visit their web page on the internet at # http://www.gnu.org/copyleft/gpl.html. ### PACKAGE TABLENAME SCRIPTNAME #print "Content-type: text/html\n\n\n"; #------------------------------------------------- # Load the standard modules and initiaize variables. use strict; use PACKAGE::Misc; use PACKAGE::Constants; use PACKAGE::Get_Info; use PACKAGE::Set_Info; use CGI; my $Global = PACKAGE::Constants::Get_Constants; ### Get the database connection. my $dbh = $Global->{'dbh'}; ## Load the get info module. my $Info = new PACKAGE::Get_Info; ## Grab the user_id, if we don't get one, abort. my $User_Id = $Info->{'users'}->{'users_id'}; ## If $ENV{'REMOTE_USER'} is not defined, and that username doesn't ## exist in the users table, abort. We assume that is $ENV{'REMOTE_USER'} ## is defined that they logged in correctly. my $User_Okay = 1; if ($User_Id < 1) {print "Location: Error_No_User.pl\n\n";} #------------------------------------------------------------ # Print Content-Type and get the queried variables. print "Content-type: text/html\n\n\n"; my $query = new CGI; my $Update = $query->param('update'); my $Action = $query->param('action'); my @Params = $query->param(); my $Id_Encrypted = $query->param('id'); my $Id = 0; if ($Id_Encrypted ne "") {$Id = PACKAGE::Misc->Decrypt($Id_Encrypted);} my $Ids = {}; my $Ids_Encrypted= {}; OTHERIDS #------------------------------------------- # Execute any perl methods, which in turn correspond to a database method. # We could create a generic perl method for this for any table. # All we would have to do is submit a list of fields for "new" and # "update" plus the id. if ($Action eq "new") {$Id = "";} elsif ($Action eq "delete") { my $Delete = new PACKAGE::Set_Info; my $Result = $Delete->Set_TABLENAME('id'=>$Id,'command'=>'delete'); $Id = ""; } elsif ($Action eq "undelete") { my $Undelete = new PACKAGE::Set_Info; my $Result = $Undelete->Set_TABLENAME('id'=>$Id,'command'=>'undelete'); } elsif ($Action eq "purge") { my $Purge = new PACKAGE::Set_Info; my $Result = $Purge->Set_TABLENAME('id'=>$Id,'command'=>'delete'); my $Result = $Purge->Set_TABLENAME('id'=>$Id,'command'=>'purgeone'); $Id = ""; } elsif ($Update eq "update") { ### Update the title of the list my $Update = new PACKAGE::Set_Info; ### Create the array that we want to submit to the function. my $Fields = {}; DEFINEFIELDS ### Update the table and submit the $Fields array. my $Result = $Update->Set_TABLENAME('id'=>$Id,'command'=>'change','fields'=>$Fields); } elsif ($Update eq "new") { my $Insert = new PACKAGE::Set_Info; ### Insert new thing into TABLENAME table. $Id = $Insert->Set_TABLENAME('command'=>'insert'); ### Create the array that we want to submit to the function. my $Fields = {}; DEFINEFIELDS ### Hardcode the users_id if you don't want it to change. # $Fields->{'users_id'} = $User_Id; # $query->param(-delete=>'users_id'); # $query->param(-name=>'users_id',value=>$Info->{'users'}->{'users_id'}); my $Result = $Insert->Set_TABLENAME('id'=>$Id,'command'=>'change',"fields"=>$Fields); } #---------------------------------------------------------------------- # Now create a list of all the items in this table. Then we can choose # which ones we want to edit. This could be put into a perl method # instead of duplicating it for each webpage. ### Now taken care of by the module Get_TABLENAME ### Create the main list of items we are editing. ### If there is a users_id in the table, only select the ones that we own. my $List = ""; my $Id_Values = {}; ### You might want to modify this sql so that you use more descriptive titles. my $Temp_List = $Info->List('TABLENAME','all','none'); foreach my $Key (sort keys %$Temp_List) { my $ref = $Temp_List->{$Key}; my $Selected = ""; if ($ref->{'TABLENAME_id'} eq $Id) {$Selected = " selected";} my $Id_Encrypt = PACKAGE::Misc->Encrypt($ref->{'TABLENAME_id'}); my $Status = "Active"; if ($ref->{'active'} == 0) {$Status = "Inactive";} my $Title = $ref->{'TABLENAME_id'}; ### We are looking for the field "title", but change it so what the field ### should be. This is just an example. if (exists $ref->{'title'}) {$Title = $ref->{'title'}} $List .= qq(