-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.cgi
executable file
·152 lines (130 loc) · 5.02 KB
/
index.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
use CGI;
use WTPA;
use Config::Abstract::Ini;
my $cgi = new CGI();
my $action = $cgi->param('action') || "";
my $index = join( "", <DATA> );
our $ini = (new Config::Abstract::Ini( 'config.ini' ))->get_all_settings;
utilInit( $ini );
if ( $action eq 'add' ) {
my $err = addEvent({
name => $cgi->param('name'),
place => $cgi->param('place'),
when => $cgi->param('date') . ' ' . $cgi->param('time') . $cgi->param('ampm')
}) || "Event saved.";
$index =~ s/MSG/$err/g;
} elsif ( $action eq 'update' ) {
my $err = updateEvent($cgi->param('old'), "", {
name => $cgi->param('name'),
place => $cgi->param('place'),
when => $cgi->param('date') . ' ' . $cgi->param('time') . $cgi->param('ampm')
}) || "Event updated.";
$index =~ s/MSG/$err/g;
} elsif ( $action eq 'cancel' ) {
my $err = cancelEvent($cgi->param('old')) || "Event cancelled.";
$index =~ s/MSG/$err/g;
} elsif ( $action eq 'addplace' ) {
addPlace( $cgi->param('name'), $cgi->param('address') );
$index =~ s/MSG/Place added./g;
} elsif ( $action eq 'updateplace' ) {
updatePlace( $cgi->param('old'), $cgi->param('name'), $cgi->param('address') );
$index =~ s/MSG/Place updated./g;
}
my $toUpdate = "";
foreach my $event ( @WTPA::events ) {
my $when = getTime( $event->{when} );
my $name = $event->{name};
my $place = $event->{place} || "";
my $date = $when->strftime("%D");
my $time = $when->strftime("%I:%M");
my $ampm = $when->strftime("%P");
my $nice_date = $when->strftime("%b %e");
my $nice_time = ($when->hour > 0 ? " " . $when->strftime(
# Don't display the minutes when they're :00
$when->minute > 0 ? "%l:%M%P" : "%l%P" ) : "");
my $nice_place = $place;
my $dbPlace = placeURL( findPlace( $event ), $event );
my $namePlace = $nice_place ? "$event->{name} @ $nice_place" : $event->{name};
$namePlace = $dbPlace ?
"<a href='$dbPlace'>$namePlace</a>" :
$namePlace;
$name =~ s/"/\\"/g;
$place =~ s/"/\\"/g;
# Display the name and location of the event
$toUpdate .= qq~<li><span class="date">$nice_date $nice_time:</span> $namePlace
<span class='buttons'>
<input type='button' value='Update' class="update"/>
<form action="" method="POST" class="cance">
<input type="hidden" name="action" value="cancel"/>
<input type="hidden" name="old" value="' + data.name + '"/>
<input type="submit" value="Cancel"/>
</form>
</span>
<form action="" method="POST" class="update">
<input type="hidden" name="action" value="update"/>
<input type="hidden" name="old" value="$name"/>
<label for="name">Name:</label><input type="text" name="name" value="$name"/><br/>
<label for="place">Place:</label><input type="text" name="place" value="$place"/><br/>
<label for="date">Date:</label><input type="text" name="date" value="$date"/><br/>
<label for="time">Time:</label><input type="text" name="time" value="$time"/> <select name="ampm">
<option>$ampm</option><option>pm</option><option>am</option></select><br/>
<label></label><input type="submit" value="Update Event"/> <input type="reset" value="Cancel"/>
</form>
</li>~;
}
my $placeList = "";
foreach my $place ( sort { lc($a) cmp lc($b) } keys %WTPA::places ) {
$placeList .= qq~<li><form action="" method="POST">
<input type="hidden" name="action" value="updateplace"/>
<input type="hidden" name="old" value="$place"/>
<label for="name">Name:</label><input type="text" name="name" value="$place"/>
<label for="address">Address:</label><input type="text" name="address" value="$WTPA::places{$place}"/>
<input type="submit" value="Update"/>
</form></li>~;
}
$index =~ s/TODAY/getTime(time())->strftime("%D")/ge;
$index =~ s/UPCOMING/$toUpdate/g;
$index =~ s/PLACES/$placeList/g;
$index =~ s/MSG//g;
print "Content-type: text/html\n\n";
print $index;
__DATA__
<!DOCTYPE html>
<html>
<head>
<meta name="ROBOTS" content="NOINDEX, NOFOLLOW"/>
<title>Update WTPA</title>
<link rel="stylesheet" href="main.css"/>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="main.js"></script>
</head>
<body>
<h1>Where is the Party at?</h1>
<p style="color:red;">MSG</p>
<h2>Events:</h2>
<ul id="upcoming">UPCOMING</ul>
<h2>Add New Event:</h2>
<form action="" method="POST">
<input type="hidden" name="action" value="add"/>
<label for="name">Name:</label><input type="text" name="name"/><br/>
<label for="place">Place:</label><input type="text" name="place"/><br/>
<label for="date">Date:</label><input type="text" name="date" value="TODAY"/><br/>
<label for="time">Time:</label><input type="text" name="time" value="7:00"/> <select name="ampm">
<option>pm</option><option>am</option></select><br/>
<label></label><input type="submit" value="Add Event"/>
</form>
<h2>Places:</h2>
<ul id="places">PLACES</ul>
<h2>Add New Place:</h2>
<form action="" method="POST">
<input type="hidden" name="action" value="addplace"/>
<label for="name">Name:</label><input type="text" name="name"/>
<label for="address">Address:</label><input type="text" name="address"/>
<input type="submit" value="Add Place"/>
</form>
</body>
</html>