1 #!/usr/bin/perl -w -CSDA
7 use CGI
::Fast qw
/header param/;
9 use Email
::Sender
::Simple qw
/sendmail/;
10 use File
::Slurp qw
/append_file/;
11 use JSON qw
/encode_json/;
12 use YAML
::Any qw
/Dump LoadFile/;
14 use Fcntl qw
/LOCK_EX LOCK_UN/;
15 use List
::Util qw
/sum/;
17 ##################################################
22 date
=> '35 jebruarie 2059',
23 locul
=> 'Strada speranţei, nr 1',
24 sala
=> 'sala IDT de la etajul 10',
26 link => 'http://ieval.ro/',
27 image
=> 'http://0.tqn.com/d/animatedtv/1/0/M/H/1/annoying_orange.jpg.jpg',
31 date
=> '35 jebruarie 2059',
32 locul
=> 'Strada speranţei, nr 1',
33 sala
=> 'sala IDT de la etajul 10',
35 link => 'http://ieval.ro/',
36 image
=> 'http://tasty-dishes.com/data_images/encyclopedia/orange/orange-03.jpg',
40 date
=> '35 jebruarie 2059',
41 locul
=> 'Strada speranţei, nr 1',
42 sala
=> 'sala IDT de la etajul 10',
44 link => 'http://ieval.ro/',
45 image
=> 'http://blog.clove.co.uk/wp-content/uploads/2013/07/Samsung-Logo.jpg',
49 date
=> '35 jebruarie 2059',
50 locul
=> 'Strada speranţei, nr 1',
51 sala
=> 'sala IDT de la etajul 10',
53 link => 'http://ieval.ro/',
54 image
=> 'http://images.moneysavingexpert.com/images/OrangeLogo.jpg',
58 date
=> '35 jebruarie 2059',
59 locul
=> 'Strada speranţei, nr 1',
60 sala
=> 'sala IDT de la etajul 10',
62 link => 'http://ieval.ro/',
63 image
=> 'https://lh3.ggpht.com/-Dsy_8YO5Ais/UCxPnnfMOgI/AAAAAAAAAJ4/1iRXOKWACo8/s200/fresh_orange_slice.jpg',
67 use constant EMAIL_FROM
=> 'Robotul Verde <bot@ieval.ro>';
68 use constant ADMIN_EMAIL
=> 'Marius Gavrilescu <marius@ieval.ro>';
69 use constant DATAFILE
=> '/var/www/dir/data.yml';
72 ##################################################
74 open LOCK
, '<', DATAFILE
;
76 sub nr_participanti
{ my $event = shift; sum
0, map { $_->{numar
} } grep { $_->{event
} eq $event } @_ }
82 my $prenume = param
('prenume') or die 'Nu ati completat campul "Prenume"';
83 utf8
::decode
($prenume);
84 my $nume = param
('nume') // '';
86 my $email = param
('email') or die 'Nu ati completat campul "Email"';
88 my $event = param
('oras') or die 'Nu ati ales orasul evenimentului';
89 die 'Ziua Libertatii Programelor nu se tine in orasul ales' unless exists $events{$event};
90 my $numar = int param
('numar') or die 'Nu ati ales nuamrul de participanti';
91 die 'Numarul de participanti trebuie sa fie intre 1 si 5' unless $numar >= 1 && $numar <= 5;
92 my $captcha = param
('captcha') or die 'Nu ati completat anul de lansare al proiectului GNU';
93 die 'Ati completat gresit anul de lansare al proiectului GNU' unless $captcha == 83;
94 my $spam = param
('spam') or 0;
95 my @db = grep { $_->{event
} eq $event } LoadFile DATAFILE
;
96 die 'Aceasta adresa de poşta electronica este deja folosita' if grep { $_->{email
} eq $email } @db;
97 my $participanti = nr_participanti
$event, @db;
98 die 'Nu sunt suficiente locuri libere' if $events{$event}{locuri
} < $participanti + $numar;
106 spam
=> defined($spam) && $spam ?
1 : 0,
108 my $success_email = Email
::Simple
->create(
110 To
=> "$nume <$email>",
111 Subject
=> 'Inscriere la Ziua Libertatii Programelor',
114 body
=> "Aceasta este o confirmare de inscriere la Ziua Libertatii Programelor\n\n" . Dump \
%entry,
116 sendmail
$success_email, { to
=> [$email, ADMIN_EMAIL
]};
117 append_file DATAFILE
, Dump \
%entry;
122 my $eroare = $@
=~ s/ at .*//r;
123 my $error_email = Email
::Simple
->create(
125 To
=> "Administrator <" . ADMIN_EMAIL
. ">",
126 Subject
=> 'Eroare in inscrierea la Ziua Libertatii Programelor',
129 body
=> "Eroare: $eroare",
131 sendmail
$error_email;
132 print header
('text/html; charset=utf-8', '500 Internal Server Error');
135 print header
('text/html; charset=utf-8');
136 print 'Aţi fost inregistrat cu succes';
141 my $event = param
('event');
144 die 'Eveniment inexistent' unless defined $event && exists $events{$event};
145 my %out = %{$events{$event}};
146 my $participanti = nr_participanti
$event, LoadFile DATAFILE
;
147 $out{locuri
} = $out{locuri
} - $participanti;
148 print header
('application/json; charset=utf-8');
149 print encode_json \
%out;
154 print header
('text/html; charset=utf-8', '500 Internal Server Error');
160 my $event = param
('event');
162 unless (exists $events{$event}) {
163 print header
('text/html; charset=utf-8', '500 Internal Server Error');
164 print 'Acest eveniment nu exista';
168 my @db = grep { $_->{event
} eq $event } LoadFile DATAFILE
;
169 my $participanti = nr_participanti
$event, @db;
170 print header
('text/html; charset=utf-8');
171 print "Sunt $participanti participanti inscrisi<p>";
173 print "Nume: $p->{nume}<br>Prenume: $p->{prenume}<br>Email: $p->{email}<br>Event: $p->{event}<br>Numar: $p->{numar}<br>Spam: $p->{spam}<p>";
177 while (CGI
::Fast
->new) {
178 my $op = param
'op' // '';
179 append
if $op eq 'append';
180 info
if $op eq 'info';
181 view
if $op eq 'view';
189 zlp - Inscrieri Ziua Libertatii Programelor
193 Marius Gavrilescu E<lt>marius@ieval.roE<gt>
195 =head1 COPYRIGHT AND LICENSE
197 Copyright (C) 2013 by Fundatia Ceata
199 This program is free software: you can redistribute it and/or modify
200 it under the terms of the GNU Affero General Public License as published by
201 the Free Software Foundation, either version 3 of the License, or
202 (at your option) any later version.
204 This program is distributed in the hope that it will be useful,
205 but WITHOUT ANY WARRANTY; without even the implied warranty of
206 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
207 GNU Affero General Public License for more details.
209 You should have received a copy of the GNU Affero General Public License
210 along with this program. If not, see <http://www.gnu.org/licenses/>.
This page took 0.03782 seconds and 4 git commands to generate.