X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=cgi%2Fpersons.cgi;fp=cgi%2Fpersons.cgi;h=0a845087e4fcc33daacdc7fc3ce7de980aa61c44;hb=582478ebeca009066b0445dca96d56c10d6a2f6e;hp=df22cededa9fcc06aa8f8a0bbd63207d6b47eae7;hpb=a6888a97f2573cf8c5ca89670dd33bd849080faf;p=technostate.git
diff --git a/cgi/persons.cgi b/cgi/persons.cgi
index df22ced..0a84508 100755
--- a/cgi/persons.cgi
+++ b/cgi/persons.cgi
@@ -1,5 +1,5 @@
#!/usr/bin/perl -Tw
-# $Id: persons.cgi,v 1.5 1999-04-22 04:34:46 ivan Exp $
+# $Id: persons.cgi,v 1.6 1999-04-22 05:54:53 ivan Exp $
# Copyright (c) 1999 Ivan Kohler. All rights reserved.
# This program is free software; you can redistribute it and/or modify it under
# the same terms as perl itself
@@ -9,7 +9,7 @@ use vars qw ( $data_source $user $password $table @fields
$cgi $dbh
);
use subs qw( print_form );
-use CGI;
+use CGI qw(tr th td);
use CGI::Carp qw(fatalsToBrowser);
use DBI;
@@ -27,30 +27,42 @@ $dbh = DBI->connect( $data_source, $user, $password )
unless ( $cgi->param('magic') ) { #first time through
- my $sth = $dbh->do( "SELECT * FROM PERSONS" ) or die $dbh->errstr;
+ my $sth = $dbh->prepare( "SELECT * FROM PERSONS" )
+ or die $dbh->errstr;
+ my $rv = $sth->execute;
+ die $sth->errstr unless $rv;
- print $cgi->header,
+ print $cgi->header( '-expires' => 'now' ),
$cgi->start_html('Person listing'),
$cgi->h1('Person listing'),
;
unless ( $sth eq '0E0' ) {
+ my @columns = @{ $sth->{'NAME'} };
+
print $cgi->start_table,
$cgi->tr(
map {
$cgi->th($_)
- } @{$sth->{NAME}}
- ),
- map {
- $cgi->tr(
- map {
- $cgi->td( $_ )
- } @{ $_ }
- )
- } @{ $sth->fetchall_arrayref },
- $cgi->end_table,
+ } @columns
+ )
;
+
+ my %hash = ();
+ my $hashref = undef;
+ while ( $hashref = $sth->fetchrow_hashref ) {
+ %hash = %{$hashref};
+ $hash{'EMAIL'} = ''.
+ $hash{'EMAIL'}. "";
+ $hash{'HOMEPAGE'} = 'http://'. $hash{'HOMEPAGE'}
+ unless $hash{'HOMEPAGE'} =~ /^http\:\/\//;
+ $hash{'HOMEPAGE'} = ''.
+ $hash{'HOMEPAGE'}. "";
+ print $cgi->tr( map { $cgi->td( $hash{$_} ) } @columns );
+ }
+ print $cgi->end_table;
+
}
$cgi->param('magic', 'new_form');
@@ -76,7 +88,7 @@ unless ( $cgi->param('magic') ) { #first time through
my $statement = 'INSERT INTO PERSONS ( '.
join(', ', @fields ).
' ) VALUES ( '.
- join( ', ', map { $cgi->param($_) } @fields ).
+ join( ', ', map { $dbh->quote($cgi->param($_)) } @fields ).
' )'
;
my $sth = $dbh->prepare($statement)
@@ -84,15 +96,15 @@ unless ( $cgi->param('magic') ) { #first time through
my $rv = $sth->execute;
die $sth->errstr unless $rv;
- print $cgi->header,
- "person added?"
- ;
+ my $url = $cgi->url;
+ $url =~ s/^\/[\/]+$//;
+ print $cgi->redirect($url);
}
sub print_form {
my $cgi = shift;
my $action = shift;
- print $cgi->header,
+ print $cgi->header( '-expires' => 'now' ),
$cgi->start_html($action),
$cgi->h1($action),
$cgi->start_form,