/[Frey]/branches/zimbardo/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 /branches/zimbardo/lib/App/RoomReservation/Confirmation.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1147 - (hide annotations)
Wed Jul 1 17:35:48 2009 UTC (14 years, 10 months ago) by dpavlin
Original Path: trunk/lib/App/RoomReservation/Confirmation.pm
File size: 2026 byte(s)
added url_for to genrate and verify urls
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 dpavlin 1147 my $url = $self->url_for( 'Confirmation/cancel_as_markup?token=' . $self->token );
57    
58 dpavlin 1134 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 dpavlin 1147 $url
66 dpavlin 1134 __EMAIL__
67     );
68    
69     return $html;
70    
71 dpavlin 1098 } else {
72 dpavlin 1121 die "Problem with confirmation.\n";
73 dpavlin 1098 }
74     }
75    
76     sub cancel_as_markup {
77     my ($self) = @_;
78    
79 dpavlin 1121 my $dbh = $self->dbh;
80    
81     my $sth = $dbh->prepare(qq{
82     update reservation
83     set
84     _confirmed = false,
85     _seat_number = null
86 dpavlin 1098 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 dpavlin 1121 die "Problem with cancelation.\n";
94 dpavlin 1098 }
95     }
96    
97 dpavlin 1133 __PACKAGE__->meta->make_immutable;
98     no Moose;
99    
100 dpavlin 1098 1;

  ViewVC Help
Powered by ViewVC 1.1.26