/[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 1134 - (show annotations)
Tue Jun 30 15:59:41 2009 UTC (14 years, 10 months ago) by dpavlin
File size: 2021 byte(s)
added e-mail sending
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 $token = $self->token;
57 $self->send( $email,
58 "Lecture seat $seat is assigned to you",
59 $html . <<__EMAIL__
60
61 If you wish to cancel your reservation please click on link below:
62
63 http://FREY_HOSTNAME/App::RoomReservation::Confirmation/cancel_as_markup?token=$token
64 __EMAIL__
65 );
66
67 return $html;
68
69 } else {
70 die "Problem with confirmation.\n";
71 }
72 }
73
74 sub cancel_as_markup {
75 my ($self) = @_;
76
77 my $dbh = $self->dbh;
78
79 my $sth = $dbh->prepare(qq{
80 update reservation
81 set
82 _confirmed = false,
83 _seat_number = null
84 where md5(id||email) = ? and _confirmed is true
85 });
86 $sth->execute( $self->token );
87
88 if ( $sth->rows == 1 ) {
89 qq|Your <em>reservation is canceled</em>, thanks for your effort to provide seat to somebody else|;
90 } else {
91 die "Problem with cancelation.\n";
92 }
93 }
94
95 __PACKAGE__->meta->make_immutable;
96 no Moose;
97
98 1;

  ViewVC Help
Powered by ViewVC 1.1.26