/
test
executable file
·121 lines (115 loc) · 3.17 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/perl -wT
# -*- Mode: perl; tab-width: 4; indent-tabs-mode: nil; -*-
#
# repeat-01: Repetition Template Feature demo script
#
# Copyright (c) 2002 by Ian Hickson
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
use strict;
use utf8;
use CGI;
my $query = new CGI;
my @IDs = $query->param('id');
my $add = $query->param('add');
my $remove = $query->param('remove');
if ($add) {
my $max = 0;
foreach (@IDs) {
if (m/^[0-9]+$/os and $_ > $max) {
$max = $_;
}
}
push(@IDs, $max + 1);
}
if ($remove) {
foreach (@IDs) {
if ($_ eq $remove) {
$_ = undef;
}
}
}
if ($add or $remove) {
local *FILE;
print <<end;
Content-Type: text/html
end
open(FILE, 'index');
while (defined($_ = <FILE>) and $_ !~ m/<tbody>/os) {
print $_;
}
print $_;
foreach (@IDs) {
next unless defined $_;
use HTML::Entities;
my $player = encode_entities($_, '<>&"');
my $name = encode_entities($query->param("player$_.name") || '', '<>&"');
my $bid = encode_entities($query->param("player$_.bid") || 0, '<>&"');
print <<end;
<tr>
<td> <input name="player${player}.name" type="text" class="name" value="${name}" required="required"> </td>
<td> \$<input name="player${player}.bid" type="number" class="bid" value="${bid}" required="required"> </td>
<td>
<input name="id" value="${player}" type="hidden">
<button name="remove" value="${player}" type="remove"> Remove </button>
</td>
</tr>
end
}
while (defined($_ = <FILE>) and $_ !~ m/<\/tbody>/os) {
# skip;
}
print $_;
while (defined ($_ = <FILE>)) {
print $_;
}
close FILE;
} else {
print <<end;
Content-Type: text/html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html lang="en">
<head>
<title>Repetition Model Demo 01: Results</title>
</head>
<body>
<p>The bidders were:</p>
<ol>
end
my %IDs = ();
foreach (@IDs) {
next unless defined $_;
$IDs{$_} = {
name => $query->param("player$_.name") || '',
bid => $query->param("player$_.bid") || 0,
};
}
foreach (sort { $IDs{$a}->{bid} <=> $IDs{$b}->{bid} } keys %IDs) {
use HTML::Entities;
my $player = encode_entities($_, '<>&"');
my $name = encode_entities($IDs{$_}->{name}, '<>&"');
my $bid = encode_entities($IDs{$_}->{bid}, '<>&"');
print <<end;
<li>
$name (\$$bid)
</li>
end
}
print <<end;
</ol>
</body>
</html>
end
}