/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1134 - (hide 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 dpavlin 1122 package App::RoomReservation::Confirmation;
2 dpavlin 1098 use Moose;
3    
4     extends 'App::RoomReservation';
5    
6 dpavlin 1134 with 'App::RoomReservation::Email';
7    
8 dpavlin 1098 has token => (
9     is => 'ro',
10     isa => 'Str',
11     required => 1,
12     );
13    
14     sub verify_as_markup {
15     my ($self) = @_;
16    
17 dpavlin 1121 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 dpavlin 1098 where md5(id||email) = ? and _confirmed is false
34     });
35 dpavlin 1121
36 dpavlin 1098 $sth->execute( $self->token );
37    
38     if ( $sth->rows == 1 ) {
39 dpavlin 1121
40     $sth = $dbh->prepare(qq{
41 dpavlin 1134 select ime||' '||prezime,_seat_number,email
42 dpavlin 1121 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 dpavlin 1134 my ($name, $seat, $email) = $sth->fetchrow_array;
48 dpavlin 1121
49 dpavlin 1134 my $html =
50 dpavlin 1121 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 dpavlin 1134
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 dpavlin 1098 } else {
70 dpavlin 1121 die "Problem with confirmation.\n";
71 dpavlin 1098 }
72     }
73    
74     sub cancel_as_markup {
75     my ($self) = @_;
76    
77 dpavlin 1121 my $dbh = $self->dbh;
78    
79     my $sth = $dbh->prepare(qq{
80     update reservation
81     set
82     _confirmed = false,
83     _seat_number = null
84 dpavlin 1098 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 dpavlin 1121 die "Problem with cancelation.\n";
92 dpavlin 1098 }
93     }
94    
95 dpavlin 1133 __PACKAGE__->meta->make_immutable;
96     no Moose;
97    
98 dpavlin 1098 1;

  ViewVC Help
Powered by ViewVC 1.1.26