view paypal/generate_paylists.pm @ 30:293275d50722 laserkard

[svn r31] Implemented Centering on the dynamic text display in a static context
author rlm
date Sun, 17 Jan 2010 08:08:20 -0500
parents 7742910e0479
children d269b63b4a54
line wrap: on
line source

2 package generate_paylists;
5 use Exporter;
7 our @ISA= qw( Exporter );
8 our @EXPORT = qw( paylist );
13 sub paylist
14 {
16 {#input stuff
17 my %args = (
18 TITLE => "Clarity LaserKard --- Classic Style",
19 NAME => 'classic_acrylic_clear',
20 FIELDS => ["Line 1", "Line 2","Line 3","Line 4","Line 5","Side"],
21 ADD_PENNY => 1,
22 COSTS_NAMES => ['40 cards -- $125', '3 cards -- $15'],
23 COSTS_CODE => ['40 cards @125.00', '3 cards @15.00'],
24 INITIAL_PRICE => '$125.00',
25 DEFAULTS => ['jbond@mi6.co.uk','123.456.7890','James Bond','MI6','Secret Agent','http://www.jamesbond.com'],
26 @_, # argument pair list goes here
27 );
28 $prod_name = $args{PRODUCT_NAME};
29 @defaults = @{$args{DEFAULTS}};
30 $name = $args{NAME};
31 @fields = @{$args{FIELDS}};
32 @costs_names = @{$args{COSTS_NAMES}};
33 @costs_code = @{$args{COSTS_CODE}};
34 $penny = $args{ADD_PENNY};
35 $title = $args{TITLE};
36 $initial_price = $args{INITIAL_PRICE};
38 }
40 {#determine the total number of fields and payment options present:
45 $num_fields = $#fields +1;
46 $payment_opts = $#costs_names +1 ;
48 }
50 {#read in the file
52 {
53 local( $/, *FH ) ;
54 open( FH, "<BASE.paylist" ) or die "sudden flaming death\n";
55 $base = <FH>;
56 }
58 }
60 #The base file has the following options:
62 #PERL::TITLE x
63 #PERL::OPT0 -- PERL::OPT9 x
64 #PERL::PAYMENT x
65 #PERL::INPUT x
66 #PERL::PENNY x
67 #PERL::INITIAL_COST x
70 {#PERL::TITLE
71 $base =~ s/PERL::TITLE/$title/g;
72 $base =~ s/PERL::PRODUCT-NAME/$prod_name/g;
74 }
76 {#PERL::OPT0 -- PERL::OPT9
77 for (0..9)
78 {
79 my $index = $_;
80 my $field = @fields[$index];
81 my $find = 'PERL::OPT'.$index;
82 my $replace = "value = \"$field\"";
85 if (!@fields[$index]){$replace = "";}
87 $base =~ s/$find/$replace/;
88 }
89 }
91 {#PERL::PAYMENT
94 my $start =
95 <<DDDDD;
97 <input type="radio" name = "whatev"
99 value="PERL::CODE" PERL::CHECKED
100 onclick = "ReadForm (this.form, false);"
101 onload = "ReadForm (this.form, false);" >
102 PERL::COST
104 <br>
106 DDDDD
109 $start2 = $start;
111 $start =~ s/PERL::COST/@costs_names[0]/;
112 $start =~ s/PERL::CODE/@costs_code[0]/;
113 $start =~ s/PERL::CHECKED/CHECKED/;
117 if (2 == $payment_opts)
118 {
120 $start2 =~ s/PERL::COST/@costs_names[1]/;
121 $start2 =~ s/PERL::CODE/@costs_code[1]/;
122 $start2 =~ s/PERL::CHECKED//;
123 $start = $start.$start2;
125 }
127 $base =~ s/PERL::PAYMENT/$start/;
129 }
131 {#PERL::INPUT
134 $start = <<OHYEAH;
135 <br>
136 PERL::OPT:&nbsp;&nbsp;
137 <input type="text" id="PERL::OPT" name="line_PERL::NUMb" size="20" value = "PERL::DEFAULT" ONFOCUS="clearDefault(this)"
138 onKeyUp="
139 tt.remove();
141 var font_size = 75;
143 tt = raphe.print(0, 145, value, raphe.getFont('HelveticaNeue', 700), font_size);
144 tt.attr('stroke', '#f00');
145 tt.attr('fill', 'TRANSPARENT');
146 var c = tt.getBBox().width;
147 tt.translate((502 - c)/2,0);
154 //document.write( c );
160 "
162 >
163 <!-- -->
164 <br>
165 OHYEAH
168 my $input = "";
170 for (0..$#fields)
171 {
172 $rrr = $_+1;
173 $t = $start;
174 $t =~ s/PERL::NUM/$rrr/;
175 $t =~ s/PERL::OPT/$fields[$_]/g;
176 $t =~ s/PERL::DEFAULT/$defaults[$_]/;
177 $input = $input.$t;
179 }
181 $base =~ s/PERL::INPUT/$input/;
183 }
185 {#PERL::PENNY
186 my $penny_text;
188 if ($penny){
189 $penny_text =
190 <<PPP
191 <br>
192 <input type = "checkbox" onclick = "ReadForm (this.form, false);" value = "( +0.01 ^__^ )">
193 Add a penny! ^__^
194 <br>
195 PPP
196 }
198 $base =~ s/PERL::PENNY/$penny_text/;
199 }
201 {#PERL::INITIAL_COST
202 $base =~ s/PERL::INITIAL_COST/\"$initial_price\"/;
203 }
207 {#print the revised paylist out
208 open(OUT,">$name.paylist") or die "DEATH $!";
209 print OUT $base;
210 }
214 }
216 1;#stupidity