/[Frey]/trunk/lib/App/RoomReservation/Confirmation.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/lib/App/RoomReservation/Confirmation.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1147 - (show annotations)
Wed Jul 1 17:35:48 2009 UTC (14 years, 9 months ago) by dpavlin
File size: 2026 byte(s)
added url_for to genrate and verify urls
1 package App::RoomReservation::Confirmation;
2 use Moose;
3
4 extends 'App::RoomReservation';
5
6 with 'App::RoomReservation::Email';
7
8 has token => (
9 is => 'ro',
10 isa => 'Str',
11 required => 1,
12 );
13
14 sub verify_as_markup {
15 my ($self) = @_;
16
17 my $dbh = $self->dbh;
18
19 my $sth = $dbh->prepare(qq{
20 update reservation
21 set
22 _confirmed = true,
23 _seat_number = (
24 select
25 min(seat.nr)
26 from (select generate_series(1,600) as nr) as seat
27 full join reservation on reservation._seat_number = seat.nr
28 where id is null
29 group by seat.nr
30 order by seat.nr asc
31 limit 1
32 )
33 where md5(id||email) = ? and _confirmed is false
34 });
35
36 $sth->execute( $self->token );
37
38 if ( $sth->rows == 1 ) {
39
40 $sth = $dbh->prepare(qq{
41 select ime||' '||prezime,_seat_number,email
42 from reservation
43 where md5(id||email) = ? and _confirmed is true and _seat_number is not null
44 });
45
46 $sth->execute( $self->token );
47 my ($name, $seat, $email) = $sth->fetchrow_array;
48
49 my $html =
50 qq|
51 $name, <em>reservation has been confirmed</em> and seat number <big>$seat</big> is waiting for you.
52 <br>
53 Please print this notice and show it when entering lecture.
54 |;
55
56 my $url = $self->url_for( 'Confirmation/cancel_as_markup?token=' . $self->token );
57
58 my $token = $self->token;
59 $self->send( $email,
60 "Lecture seat $seat is assigned to you",
61 $html . <<__EMAIL__
62
63 If you wish to cancel your reservation please click on link below:
64
65 $url
66 __EMAIL__
67 );
68
69 return $html;
70
71 } else {
72 die "Problem with confirmation.\n";
73 }
74 }
75
76 sub cancel_as_markup {
77 my ($self) = @_;
78
79 my $dbh = $self->dbh;
80
81 my $sth = $dbh->prepare(qq{
82 update reservation
83 set
84 _confirmed = false,
85 _seat_number = null
86 where md5(id||email) = ? and _confirmed is true
87 });
88 $sth->execute( $self->token );
89
90 if ( $sth->rows == 1 ) {
91 qq|Your <em>reservation is canceled</em>, thanks for your effort to provide seat to somebody else|;
92 } else {
93 die "Problem with cancelation.\n";
94 }
95 }
96
97 __PACKAGE__->meta->make_immutable;
98 no Moose;
99
100 1;

  ViewVC Help
Powered by ViewVC 1.1.26