1 |
296 |
ahitrov |
|
2 |
|
|
<& comps/header.msn &> |
3 |
|
|
<div align="center"> |
4 |
|
|
<table width="435" border="0" cellspacing="0" cellpadding="0"> |
5 |
|
|
<tr> |
6 |
|
|
<td valign="top" align="left"> |
7 |
|
|
|
8 |
|
|
% if($ARGS{send_ok}) { |
9 |
|
|
<table width="435" cellspacing="0" cellpadding="10" border="0"> |
10 |
|
|
<tr> |
11 |
|
|
<td><img src="/i/escape/ok.jpg"></td> |
12 |
|
|
<td align=center class="text"> |
13 |
|
|
Ваша анкета отправлена, спасибо за Ваше участие. |
14 |
|
|
</td> |
15 |
|
|
</tr> |
16 |
|
|
</table> |
17 |
|
|
% } |
18 |
|
|
|
19 |
|
|
% if(keys(%errors) > 0) { |
20 |
|
|
<table width="435" cellspacing="0" cellpadding="10" border="0"> |
21 |
|
|
<tr> |
22 |
|
|
<td><img src="/i/escape/error.jpg"></td> |
23 |
|
|
<td align=center class="text"> |
24 |
|
|
При заполнении анкеты произошли ошибки, неправильно заполненные поля выделены цветом. |
25 |
|
|
</td> |
26 |
|
|
</tr> |
27 |
|
|
</table> |
28 |
|
|
% } |
29 |
|
|
|
30 |
|
|
% if(!$ARGS{posted} || ($ARGS{posted} && keys(%errors) > 0)) { |
31 |
|
|
|
32 |
|
|
<form action="anket.html" method="post"> |
33 |
|
|
<input type="hidden" name="posted" value="1"> |
34 |
|
|
<table width="435" border="0" cellspacing="0" cellpadding="10"> |
35 |
|
|
% my $j = 0; |
36 |
|
|
% foreach my $field (@fields) { |
37 |
|
|
% my $fname = (keys(%$field))[0]; |
38 |
|
|
<tr bgcolor="<% color('#E9F6FE', '#ffffff') %>" <%exists($errors{$fname}) ? 'class=required' : ''%> title="<%$errors{$fname}%>"> |
39 |
|
|
<td valign="top" class="text" <% $j == 10 ? ' colspan=2 ' : undef %>><%$fname%> |
40 |
|
|
|
41 |
|
|
% if($j != 10) { |
42 |
|
|
</td><td valign="top" class="text"> |
43 |
|
|
% } else { |
44 |
|
|
<br><div id="list"><ul> |
45 |
|
|
%} |
46 |
|
|
% my $index = 1; |
47 |
|
|
% foreach my $fields (@{$field->{$fname}}) { |
48 |
|
|
% if($fields->{type} eq 'textarea') { |
49 |
|
|
<textarea name="<%$fields->{name}%>" rows="<%$fields->{rows}%>"><%$ARGS{$fields->{name}}%></textarea> |
50 |
|
|
% } elsif($fields->{type} ne 'text') { |
51 |
|
|
% my $label_id = int rand(999); |
52 |
|
|
% my @options = ref($ARGS{$fields->{name}}) ? @{$ARGS{$fields->{name}}} : $ARGS{$fields->{name}}; |
53 |
|
|
% my $checked; |
54 |
|
|
% for my $idx (@options) { |
55 |
|
|
% if($index == $idx) { $checked = 'checked'; last } |
56 |
|
|
% } |
57 |
|
|
<% $j == 10 ? '<li>' : undef %><input id="l<%$label_id%>" type="<%$fields->{type}%>" name="<%$fields->{name}%>" value="<%$index%>" style="<%$fields->{style}%>" <%$checked%>><label for="l<%$label_id%>" > <%$fields->{text}%><br></label><% $j == 10 ? '</li>' : undef %> |
58 |
|
|
% } else { |
59 |
|
|
% my $value = $ARGS{$fields->{name}}; |
60 |
|
|
% if(!$value && $fields->{"check"} eq 'http') { |
61 |
|
|
% $value = 'http://'; |
62 |
|
|
% } |
63 |
|
|
<input type="<%$fields->{type}%>" name="<%$fields->{name}%>" value="<%$value%>" style="<%$fields->{style}%>"><%$fields->{text}%> |
64 |
|
|
% } |
65 |
|
|
% $index++; |
66 |
|
|
% } |
67 |
|
|
% if($j == 10) { |
68 |
|
|
</ul></div> |
69 |
|
|
% } |
70 |
|
|
</td> |
71 |
|
|
</tr> |
72 |
|
|
% $j++; |
73 |
|
|
% } |
74 |
|
|
<tr> |
75 |
|
|
<td align="right" class="text"><label> |
76 |
|
|
<input type="submit" name="Submit" value="Отправить анкету"> |
77 |
|
|
</label></td> |
78 |
|
|
<td valign="top" class="text"> </td> |
79 |
|
|
</tr> |
80 |
|
|
<tr> |
81 |
|
|
<td valign="top" class="text"><font color="#CC0000">*</font> Если у тебя нет блога - заведи. Это обязательное |
82 |
|
|
условие. </td> |
83 |
|
|
<td valign="top" class="text"> </td> |
84 |
|
|
</tr> |
85 |
|
|
</table> |
86 |
|
|
<br> |
87 |
|
|
</form> |
88 |
|
|
% } |
89 |
|
|
|
90 |
|
|
|
91 |
|
|
</td> |
92 |
|
|
</tr> |
93 |
|
|
</table> |
94 |
|
|
|
95 |
|
|
</div> |
96 |
|
|
|
97 |
|
|
|
98 |
|
|
<& comps/footer.msn &> |
99 |
|
|
|
100 |
|
|
|
101 |
|
|
<%once> |
102 |
|
|
use Encode; |
103 |
|
|
</%once> |
104 |
|
|
|
105 |
|
|
<%init> |
106 |
|
|
|
107 |
|
|
my @fields = $m->comp("subs/form-data.msn"); |
108 |
|
|
|
109 |
|
|
my %errors; |
110 |
|
|
my %data; |
111 |
|
|
|
112 |
|
|
my $ic = 'utf8'; |
113 |
|
|
my $cd = $ARGS{"Submit"}; |
114 |
|
|
|
115 |
|
|
for (qw(cp1251 koi8-r utf8)) { |
116 |
|
|
next unless encode('utf8', decode($_, $cd||'')) eq "Отправить анкету"; |
117 |
|
|
$ic = $_; |
118 |
|
|
last; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
for(keys %ARGS) |
122 |
|
|
{ |
123 |
|
|
$ARGS{$_} = encode("utf8", decode($ic, $ARGS{$_})); |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
if($ARGS{posted}) |
127 |
|
|
{ |
128 |
|
|
|
129 |
|
|
# die Dumper (\%ARGS); |
130 |
|
|
|
131 |
|
|
foreach my $field (@fields) |
132 |
|
|
{ |
133 |
|
|
my $fname = (keys(%$field))[0]; |
134 |
|
|
foreach my $fields (@{$field->{$fname}}) |
135 |
|
|
{ |
136 |
|
|
if(($fields->{type} eq 'radio') or ($fields->{type} eq 'checkbox')) |
137 |
|
|
{ |
138 |
|
|
my @options = ref($ARGS{$fields->{name}}) ? @{$ARGS{$fields->{name}}} : $ARGS{$fields->{name}}; |
139 |
|
|
if($fname eq "Отметь страны/регионы, в которых ты был") |
140 |
|
|
{ |
141 |
|
|
$data{$fname} = join ", ", map {$_->{text}} (@{$field->{$fname}})[ map {$_ - 1} @options ]; |
142 |
|
|
} else { |
143 |
|
|
if(!$options[0]) |
144 |
|
|
{ |
145 |
|
|
$errors{$fname} = "Выберите вариант"; |
146 |
|
|
next; |
147 |
|
|
} |
148 |
|
|
else |
149 |
|
|
{ |
150 |
|
|
$data{$fname} = join ", ", map {$_->{text}} (@{$field->{$fname}})[ map {$_ - 1} @options ]; |
151 |
|
|
}} |
152 |
|
|
} |
153 |
|
|
else |
154 |
|
|
{ |
155 |
|
|
my $value = $ARGS{$fields->{name}}; |
156 |
|
|
$value =~ s/\s+$//; |
157 |
|
|
$value =~ s/^\s+$//; |
158 |
|
|
|
159 |
|
|
if($fields->{check} eq 'int') |
160 |
|
|
{ |
161 |
|
|
$value =~ s/^0//; |
162 |
|
|
if($value !~ /^\d+$/) |
163 |
|
|
{ |
164 |
|
|
$errors{$fname} = "Поле может содержать только цифры"; |
165 |
|
|
next; |
166 |
|
|
} |
167 |
|
|
else { push @{$data{$fname}}, $value; } |
168 |
|
|
} |
169 |
|
|
elsif($fields->{"check"} eq 'http') |
170 |
|
|
{ |
171 |
|
|
if($value !~ m!^http://\S{5,}$!) |
172 |
|
|
{ |
173 |
|
|
$errors{$fname} = "Некорретная ссылка"; |
174 |
|
|
last; |
175 |
|
|
} else { $data{$fname} = $value } |
176 |
|
|
} |
177 |
|
|
elsif($fields->{"check"} eq 'email') |
178 |
|
|
{ |
179 |
|
|
if($value !~ m!^\S+@\S+\.\S+$!) |
180 |
|
|
{ |
181 |
|
|
$errors{$fname} = "Неправильный адрес электронной почты"; |
182 |
|
|
last; |
183 |
|
|
} else { $data{$fname} = $value } |
184 |
|
|
} |
185 |
|
|
else { |
186 |
|
|
unless(length($value)) |
187 |
|
|
{ |
188 |
|
|
$errors{$fname} = "Поле не заполнено"; |
189 |
|
|
last; |
190 |
|
|
} else |
191 |
|
|
{ |
192 |
|
|
$data{$fname} = $value; |
193 |
|
|
} |
194 |
|
|
} |
195 |
|
|
} |
196 |
|
|
} |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
# Особая проверка на дату, кривовато, но что поделать... |
200 |
|
|
my $key = "Дата рождения"; |
201 |
|
|
my $birth_time; |
202 |
|
|
|
203 |
|
|
if(!$errors{$key}) |
204 |
|
|
{ |
205 |
|
|
my($day, $mon, $year) = @{$data{$key}}; |
206 |
|
|
$mon--; |
207 |
|
|
|
208 |
|
|
eval qq{ |
209 |
|
|
\$birth_time = Time::Local::timelocal(0, 0, 0, \$day, \$mon, \$year); |
210 |
|
|
}; |
211 |
|
|
|
212 |
|
|
if($@) |
213 |
|
|
{ |
214 |
|
|
$errors{$key} = "Ошибочная дата рождения"; |
215 |
|
|
} |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
if(keys(%errors) == 0) |
221 |
|
|
{ |
222 |
|
|
# проверки на непрохождение анкеты |
223 |
|
|
# my $age = ((( time() - $birth_time) / 60) / 60) / 24; |
224 |
|
|
# if( ($age < 7300 || $age > 10950) || # Возраст от 20 до 30 лет |
225 |
|
|
# ($ARGS{education} == 1 or $ARGS{education} == 2) || # Образование: среднее, среднее специально |
226 |
|
|
# ($ARGS{digital_photo} == 2) || # Цифровая фотография: нет |
227 |
|
|
# ($ARGS{sickness} == 1) || # Хронические заболевания: да |
228 |
|
|
# ($ARGS{ready_for_action} == 2) || # Рюкзак, 25 кг на собственном горбу: нет, |
229 |
|
|
# ($ARGS{countries} >= 12)) # Страны "больше" австралии |
230 |
|
|
# { |
231 |
|
|
# # Посылка сообщения о том, что анкета не прошла по критериям |
232 |
|
|
# my $msg = $m->comp("comps/sendmail-out-of-restrictions.msn", |
233 |
|
|
# from => "escape\@rambler-co.ru", |
234 |
|
|
# to => $data{"E-mail адрес"}, |
235 |
|
|
# data => \%data, |
236 |
|
|
# fields => \@fields |
237 |
|
|
# ); |
238 |
|
|
# $m->comp("subs/sendmail.msn", |
239 |
|
|
# msg => $msg |
240 |
|
|
# ); |
241 |
|
|
# } |
242 |
|
|
|
243 |
|
|
my $msg = $m->comp("comps/sendmail.msn", |
244 |
|
|
from => "escape\@rambler-co.ru", |
245 |
|
|
to => "pobeg\@prt.ru", |
246 |
|
|
data => \%data, |
247 |
|
|
fields => \@fields |
248 |
|
|
); |
249 |
|
|
|
250 |
|
|
$m->comp("subs/sendmail.msn", |
251 |
|
|
msg => $msg |
252 |
|
|
); |
253 |
|
|
|
254 |
|
|
$r->header_out('Location', "anket.html?send_ok=1"); |
255 |
|
|
$r->status(302); |
256 |
|
|
$r->send_http_header; |
257 |
|
|
$m->abort; |
258 |
|
|
} |
259 |
|
|
} |
260 |
|
|
</%init> |