1 |
296 |
ahitrov |
<pre><% Dumper(\%ARGS) %></pre> |
2 |
|
|
<pre><% Dumper($voistruct) %></pre> |
3 |
|
|
<%once> |
4 |
|
|
|
5 |
|
|
use Apache::Cookie; |
6 |
|
|
|
7 |
|
|
</%once> |
8 |
|
|
<%args> |
9 |
|
|
|
10 |
|
|
$vote => undef |
11 |
|
|
|
12 |
|
|
</%args> |
13 |
|
|
<%init> |
14 |
|
|
|
15 |
|
|
&abort404 unless $vote && $vote =~ /^\d+$/; |
16 |
|
|
my $cs = Apache::Cookie->parse($r->header_in('Cookie') || ''); |
17 |
|
|
my $sid = ref $cs && ref $cs->{ruid} && $cs->{ruid}->value ? $cs->{ruid}->value : $r->header_in('X-Real-IP'); |
18 |
|
|
my ($voting, $voice, $vstruct, $voistruct); |
19 |
|
|
my $answers = 0; |
20 |
|
|
if ( $sid ) { |
21 |
|
|
$voting = $keeper->get_document_by_id ( $vote, |
22 |
|
|
class => 'promosuite::Voting', |
23 |
|
|
status => 1, |
24 |
|
|
); |
25 |
|
|
&abort404 unless ref $voting; |
26 |
|
|
$vstruct = $voting->get_image ('voting'); |
27 |
|
|
$voice = promosuite::Voice->new($keeper); |
28 |
|
|
$voice->session_id($sid); |
29 |
|
|
$voice->status(1); |
30 |
|
|
$voice->object_id($vote); |
31 |
|
|
|
32 |
|
|
$voistruct = {}; |
33 |
|
|
while ( my ($key, $value) = each %ARGS ) { |
34 |
|
|
next unless $key =~ /^question/; |
35 |
|
|
$answers++; |
36 |
|
|
if ( $key =~ /question(\d+)_(\d+)/ ) { |
37 |
|
|
my $qnum = $1; |
38 |
|
|
my $anum = $2; |
39 |
|
|
$voistruct->{$qnum}{$anum} = $value; |
40 |
|
|
} elsif ( $key =~ /question(\d+)/ ) { |
41 |
|
|
my $qnum = $1; |
42 |
|
|
my $anum = $value; |
43 |
|
|
if ( ref $anum eq 'ARRAY' ) { |
44 |
|
|
map { $voistruct->{$qnum}{$_} = 1 } @$anum; |
45 |
|
|
} else { |
46 |
|
|
$voistruct->{$qnum}{$anum} = 1; |
47 |
|
|
} |
48 |
|
|
} |
49 |
|
|
} |
50 |
|
|
local $Data::Dumper::Indent = 0; |
51 |
|
|
$voice->voting(Dumper($voistruct)); |
52 |
|
|
my $dbh = $keeper->SQL; |
53 |
|
|
if ( $answers ) { |
54 |
|
|
my $previous_handler = $dbh->{HandleError}; |
55 |
|
|
$dbh->{HandleError} = sub { return 1 if $_[0] =~ /duplicate key/; goto &$previous_handler(@_) if $previous_handler; }; |
56 |
|
|
my $sth = $dbh->prepare("INSERT INTO enquesta (class, session_id, status, object_id, voting) VALUES (?,?,?,?,?)"); |
57 |
|
|
my $json = JSON::XS->new; |
58 |
|
|
$sth->execute('promosuite::Voice', $sid, 1, $vote, $json->encode($voistruct)); |
59 |
|
|
} |
60 |
|
|
} |
61 |
|
|
if ( $answers ) { |
62 |
|
|
$m->redirect('./?voted=1'); |
63 |
|
|
} else { |
64 |
|
|
$m->redirect('./'); |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
</%init> |