annotate query.pl @ 2:791e87929f83 default tip

Added tag RELENG_1_0 for changeset d95e74cd12f4
author darius@midget.dons.net.au
date Tue, 23 Oct 2007 10:07:21 +0930
parents d95e74cd12f4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
1 #!/usr/local/bin/perl
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
2
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
3 require "cgi-lib.pl";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
4 use DBI;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
5
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
6 $user = "";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
7 $passwd = "";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
8 $dbname = "scs";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
9
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
10 MAIN:
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
11 {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
12 # Read in all the variables set by the form
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
13 &ReadParse(*input);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
14
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
15 print &PrintHeader;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
16 print "<BODY BGCOLOR=\"#00000\" TEXT=\"#CCCCCC\" LINK=\"#00EE20\"";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
17 print " VLINK=\"#55FF8B\" ALINK=\"#FFFF00\">";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
18 print "<META HTTP-EQUIV=\"Pragma\" content=\"no-cache\">\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
19 print "<TITLE>Query the SCS Database</TITLE>";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
20 print "<H2>Query the SCS Database</H2>";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
21
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
22 $id = $input{'id'};
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
23
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
24 # Connect to the Database
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
25 $dbh = DBI->connect("dbi:Pg:dbname=$dbname", $user, $passwd) || bad_exit($sth->errstr);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
26
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
27 # Prepare the select statement
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
28 $sth = $dbh->prepare("SELECT * FROM members WHERE memberid = $id") || bad_exit($sth->errstr);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
29
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
30 # Execute it
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
31 $numrows = $sth->execute || bad_exit($sth->errstr);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
32
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
33 # Get one row. Only one.. if there is more than one, bad things have happened :)
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
34 if (@array = $sth->fetchrow_array) {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
35 $memberid = dtrail(@array[0]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
36 $firstname = dtrail(@array[1]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
37 $lastname = dtrail(@array[2]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
38 $nickname = dtrail(@array[3]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
39 $pin = dtrail(@array[4]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
40 $age = dtrail(@array[5]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
41 $phone1 = dtrail(@array[6]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
42 $ph1_pub = dtrail(@array[7]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
43 $phone2 = dtrail(@array[8]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
44 $ph2_pub = dtrail(@array[9]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
45 $email = dtrail(@array[10]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
46 $email_pub = dtrail(@array[11]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
47 $address1 = dtrail(@array[12]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
48 $address2 = dtrail(@array[13]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
49 $address3 = dtrail(@array[14]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
50 $addy_pub = dtrail(@array[15]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
51 $comments = dtrail(@array[16]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
52 $joined = dtrail(@array[17]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
53 $lstmemfee = dtrail(@array[18]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
54 $lstpddate = dtrail(@array[19]);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
55
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
56 print "<TABLE WIDTH=\"100%\">\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
57 printf "<TR><TD ALIGN=RIGHT><B>First Name</B><TD>%s</TR>\n", $firstname;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
58 printf "<TR><TD ALIGN=RIGHT><B>Last Name</B><TD>%s</TR>\n", $lastname;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
59 printf "<TR><TD ALIGN=RIGHT><B>Nick Name</B><TD>%s</TR>\n", $nickname;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
60 printf "<TR><TD ALIGN=RIGHT><B>Member ID</B><TD>%s</TR>\n", $memberid;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
61 printf "<TR><TD ALIGN=RIGHT><B>Age</B><TD>%s</TR>\n", $age;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
62
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
63 if ($ph1_pub eq '1') {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
64 printf "<TR><TD ALIGN=RIGHT><B>Phone 1</B><TD>%s</TR>\n", $phone1;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
65 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
66 if ($ph2_pub eq '1') {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
67 printf "<TR><TD ALIGN=RIGHT><B>Phone 2</B><TD>%s</TR>\n", $phone2;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
68 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
69 if ($email_pub eq '1') {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
70 printf "<TR><TD ALIGN=RIGHT><B>Email</B><TD>%s</TR>\n", $email;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
71 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
72 if ($addy_pub eq '1') {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
73 printf "<TR><TD ALIGN=RIGHT><B>Address 1</B><TD>%s</TR>\n", $address1;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
74 printf "<TR><TD ALIGN=RIGHT><B>Address 2</B><TD>%s</TR>\n", $address2;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
75 printf "<TR><TD ALIGN=RIGHT><B>Address 3</B><TD>%s</TR>\n", $address3;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
76 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
77 printf "<TR><TD ALIGN=RIGHT><B>Comments</B><TD>%s</TR>\n", $comments;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
78 printf "<TR><TD ALIGN=RIGHT><B>Joined</B><TD>%s</TR>\n", $joined;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
79 printf "<TR><TD ALIGN=RIGHT><B>Last Membership Fee</B><TD>%s</TR>\n", $lstmemfee;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
80 printf "<TR><TD ALIGN=RIGHT><B>Paid last membership on</B><TD>%s</TR>\n", $lstpddate;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
81 print "</TABLE>\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
82 print "<A HREF=\"/scs/games/query.html\">Go back to the Query page</A>\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
83 print "<P>\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
84 } else {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
85 # Couldn't find the member ID given
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
86 print "No such member ID $id<P>\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
87 print "<A HREF=\"/scs/games/query.html\">Try again</A>\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
88 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
89
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
90 # Close down DB stuff
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
91 $sth->finish || bad_exit($sth->errstr);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
92
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
93 $dbh->disconnect || bad_exit($sth->errstr);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
94 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
95
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
96
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
97 sub bad_exit
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
98 {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
99 print "<H2>An internal error has occurred</H2><BR>\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
100 print "Please mail <A HREF=\"mailto:darius\@dons.net.au\">The Administrator</A> and<BR>\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
101 print "say the following error occured - $_[0]<P>\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
102 print "<A HREF=\"/scs/games/query.html\">Back to the Query Page</A>\n";
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
103
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
104 print &HtmlBot;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
105
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
106 exit(0);
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
107 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
108
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
109 sub dtrail
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
110 {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
111 $_[0] =~ s/(\ *)$//g;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
112 return $_[0];
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
113 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
114
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
115 sub san_str
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
116 {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
117 $_[0] =~ s/\\/\\\\/g;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
118 $_[0] =~ s/'/\\'/g;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
119 $_[0] =~ s/"/\\"/g;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
120 return $_[0];
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
121 }
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
122
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
123 sub san_num
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
124 {
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
125 # $_[0] =~ s/'/\\'/g;
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
126 return $_[0];
d95e74cd12f4 Initial commit
darius
parents:
diff changeset
127 }