Debian Codegraph @

examples/money_test.cgi

raw
1 #!c:/programme/perl/bin/perl.exe -w
2 # $Id$
3
4
5 use strict; # activate for programming/debugging only
6 use warnings; # activate for programming/debugging only
7 use CGI::Carp qw(fatalsToBrowser); # activate for programming/debugging only
8
9 use CGI 'param','redirect';
10 use DBI;
11
12 # config variables
13 our $dsn='dsn'; # Database DSN
14 our $dbuser='user'; # Database User
15 our $dbpass='pass'; # Database Password
16 our $dbtable='test1'; # ProvTable
17
18 #################################################################################################
19
20 $|=1;
21
22 my $dbh = DBI->connect("DBI:ODBC:$dsn", $dbuser, $dbpass, { Taint =>1 }) || die "$DBI::errstr";
23 $dbh->{RaiseError} = 1; # activate for programming/debugging only
24 $dbh->{PrintError} = 1; # activate for programming/debugging only
25 $dbh -> {LongReadLen} = 100000;
26 $dbh -> {LongTruncOk} = 0;
27 #$dbh -> {odbc_default_bind_type} = 12; # SQL_VARCHAR
28
29
30 my $action=param('ACTION') || '';
31 if ($action=~/[^\w]/) { die "bad chars in parameter!" }
32
33 if ($action eq 'SAVE_PROV') {&save_prov;}
34 else {&prov;}
35
36
37 sub prov {
38 print "content-type: text/html\n\n";
39
40 print "<Html><Head><Title>Title</Title></Head>\n";
41 print "<BODY><CENTER><BR><BR>\n\n\n";
42 print "<FORM NAME=A ACTION=money_test.cgi METHOD=POST><INPUT TYPE=HIDDEN NAME=ACTION VALUE=SAVE_PROV><TABLE BORDER=0 BGCOLOR=#DDDDDD>\n";
43 print "<TR><TD><B>&nbsp;Text&nbsp;</B></TD><TD><B>&nbsp;Level1&nbsp;</B></TD><TD><B>&nbsp;Level2&nbsp;</B></TD><TD>&nbsp;</TD></TR>\n";
44
45 # MsSQL
46 my $sth0 = $dbh->prepare("
47 SELECT
48 ISNULL(TypeName,'') AS TypeName,
49 ISNULL(ProvLevel1,0.00) AS ProvLevel1,
50 ISNULL(ProvLevel2,0.00) AS ProvLevel2,
51 ISNULL(Action,0) AS Action
52 FROM $dbtable with (NoLock)
53 ORDER BY Action
54 ");
55 my $rv0 = $sth0->execute();
56 while (my $ref0 = $sth0->fetchrow_hashref()) {
57 if ($ref0->{'Action'}==0) {
58 print "<TR><TD>&nbsp;$ref0->{'TypeName'}&nbsp;</TD><TD>&nbsp;<INPUT TYPE=TEXT SIZE=5 NAME='LEVEL1_$ref0->{'TypeName'}' VALUE='$ref0->{'ProvLevel1'}'>&nbsp;</TD><TD>&nbsp;<INPUT TYPE=TEXT SIZE=5 NAME='LEVEL2_$ref0->{'TypeName'}' VALUE='$ref0->{'ProvLevel2'}'>&nbsp;</TD><TD>&nbsp;</TD></TR>\n";
59 } else {
60 print "<TR><TD>&nbsp;<b>V:</b> $ref0->{'TypeName'}&nbsp;</TD><TD>&nbsp;<INPUT TYPE=TEXT SIZE=5 NAME='LEVEL1_$ref0->{'TypeName'}' VALUE='$ref0->{'ProvLevel1'}'>&nbsp;</TD><TD>&nbsp;<INPUT TYPE=TEXT SIZE=5 NAME='LEVEL2_$ref0->{'TypeName'}' VALUE='$ref0->{'ProvLevel2'}'>&nbsp;</TD><TD>&nbsp;</TD></TR>\n";
61 }
62 }
63 $sth0->finish();
64
65 print "</TABLE><BR><BR><INPUT TYPE=SUBMIT VALUE='Save'></FORM>";
66 print "</CENTER></BODY></HTML>";
67 }#///
68
69
70 sub save_prov {
71
72 my $sth8 = $dbh->prepare("SELECT ISNULL(TypeName,'') AS TypeName FROM $dbtable with (NoLock)"); # MsSQL
73 my $rv8 = $sth8->execute();
74 while (my $ref8 = $sth8->fetchrow_hashref()) {
75 my $name=$ref8->{'TypeName'};
76 my $level1=param("LEVEL1_$name") || '0';
77 $level1=~s/\,/\./i;
78 $level1=~s/[^\d.]//i;
79 my $level2=param("LEVEL2_$name") || '0';
80 $level2=~s/\,/\./i;
81 $level2=~s/[^\d.]//i;
82
83 # MsSQL
84 my $sth9 = $dbh->prepare("
85 UPDATE
86 $dbtable
87 SET
88 ProvLevel1=CONVERT(money,?),
89 ProvLevel2=CONVERT(money,?)
90 WHERE TypeName=?
91 ");
92 my $rv9=$sth9->execute($level1,$level2,$name);
93 #$sth9->bind_param(n,undef,SQL_VARCHAR); # tell DBD-ODBC this is a char
94 #$sth9->finish();
95 }
96 $sth8->finish();
97
98 my $location="./money_test.cgi";
99 print redirect(-uri=>$location);
100 print "Content-Type: text/html\n";
101 print "\n";
102 print "<HTML><HEAD><TITLE>Redirect</TITLE></HEAD><BODY>";
103 print "If your browser does not support redirection, please click ";
104 print "<A HREF=\"$location\">here</A>";
105 print "</BODY></HTML>";
106 }#///
107
108 $dbh->disconnect();