#!/usr/bin/perl #use pgdb; use pg_db; use pg_table; use pg_record; #use CLookupTable::CGIInput; use CGI; my $HtmlDIR = "/home/chris/public_html/pgdb/"; my $login = "pgdb_login.htm"; my $IP = "ggpl.org"; MAIN: { my $query = new CGI; my @names = $query->param(); my $action = $query->param('action'); my $db_name = "test"; #"world" # $query->param('db'); if ($action eq undef) { open (FILE, "<".$HtmlDIR.$login)||die("can't open $login for input"); $temp = $/; # Save the contents of the current input record separator undef $/; # Set the current input record separator to NULL $file_contents = ; # SLURP! $/ = $temp; # Restore the contents of the current input # record separator for later close (FILE); print "Content-type: text/html\n\n"; print $file_contents; exit; } my $pg_db = new pg_db($db_name,$IP); my $pg_table; my $pg_record; if ($action eq "login") { if ($query->param('password') eq 'purple') { $pg_db->print_table_list_page(); } else { print "Content-type: text/html\n\n"; print "Sorry, you didn't get the password right. Try again!"; } } elsif ($action eq "table_list") { $pg_db->print_table_list_page(); } elsif ($action eq "list_dbs") { print "Content-type: text/html\n\n"; print "This will list all the databases.\n"; } elsif ($action eq "add_table") { $table = $query->param('table'); $pg_db->add_table($table); $pg_table = new pg_table($pg_db,$table); $pg_table->print_edit_page(); } elsif ($action eq "edit_table") { $table = $query->param('table'); $pg_table = new pg_table($pg_db,$table); $pg_table->print_edit_page(); } elsif ($action eq "delete_table") { $table = $query->param('table'); $pg_table = new pg_table($pg_db,$table); $pg_table->drop(); $pg_db->print_table_list_page(); } elsif ($action eq "list_table") { $pg_table = new pg_table($pg_db,$query->param('table')); $pg_table->print_list_page(); } elsif ($action eq "copy_table") { $table = $query->param('table'); $pg_table = new pg_table($pg_db,$table); $pg_table->copy("temp"); $pg_db->print_table_list_page(); } elsif ($action eq "wipe_table") { $table = $query->param('table'); $pg_table = new pg_table($pg_db,$table); $pg_table->wipe(); $pg_db->print_table_list_page(); } elsif ($action eq "add_field") { $table = $query->param('table'); $field = $query->param('field'); $pg_table = new pg_table($pg_db,$table); $pg_table->add_field($field); $pg_table->print_edit_page(); } elsif ($action eq "delete_field") { $id = $query->param('id'); $table = $query->param('table'); $pg_table = new pg_table($pg_db,$table); $pg_table->drop_field($id); $pg_table->print_edit_page(); } elsif ($action eq "save_fields") { $table = $query->param('table'); $pg_table = new pg_table($pg_db,$table); $pg_table->save_fields($query); $pg_table->print_edit_page(); } elsif ($action eq "edit_object") { $id = $query->param('id'); $table = $query->param('table'); $pg_record = new pg_record($pg_db->{'db'},$table,$id); $pg_record->print_edit_page(); } elsif ($action eq "delete_object") { $id = $query->param('id'); $table = $query->param('table'); $pg_table = new pg_table($pg_db,$table); $pg_record = new pg_record($pg_db->{'db'},$table,$id); $pg_record->drop(); $pg_table->print_list_page(); } elsif ($action eq "add_form") { $table = $query->param('table'); $pg_table = new pg_table($pg_db,$table); $pg_table->print_add_page(); } elsif ($action eq "insert") { $table = $query->param('table'); $pg_table = new pg_table($pg_db,$table); $pg_record = new pg_record($pg_db->{'db'},$table); $pg_record->load_input($query); $pg_record->insert(); $pg_table->print_list_page($table); } elsif ($action eq "update") { $table = $query->param('table'); $id = $query->param('id'); $pg_table = new pg_table($pg_db,$table); $pg_record = new pg_record($pg_db->{'db'},$table,$id); $pg_record->load_input($query); $pg_record->update(); $pg_table->print_list_page(); } elsif ($action eq "edit_dependents") { $parent = $query->param('parent'); $id = $query->param('id'); $table = $query->param('table'); $pg_table = new pg_table($pg_db,$table); $pg_table->print_dependents_page($parent,$id); } # endif }