/
mobilepp.php
270 lines (248 loc) · 8.42 KB
/
mobilepp.php
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
# This is the *MOBILE* view of the Pedalpalooza calendar. It can be
# called two ways: Without a "date=..." parameter, it returns the whole
# page complete with headers. With a "date=..." parameter, it returns info
# about the requested date.
date_default_timezone_set('America/Los_Angeles');
include("include/common.php");
# Open the connection to MySQL
$conn = mysql_connect(DBHOST, DBUSER, DBPASSWORD) or die(mysql_error());
mysql_select_db(DBDATABASE, $conn);
# Fetch the events for a given day, and return them as a mysql resource.
function fetchevents($date)
{
global $conn;
$day = date("Y-m-d", $date);
$events = mysql_query("SELECT * FROM calevent, caldaily WHERE calevent.id=caldaily.id AND eventdate=\"${day}\" AND eventstatus<>\"E\" AND eventstatus<>\"S\" AND eventstatus<>\"C\" ORDER BY eventtime", $conn) or die(mysql_error());
return $events;
}
# Output the details for events. The events have already been fetched and are
# located in a mysql resource.
function listevents($events)
{
if (mysql_num_rows($events) == 0)
print '<em>No events</em>';
else while ($record = mysql_fetch_array($events)) {
$eventid = substr($record["eventdate"], -2).'-'.$record['id'];
print '<div class="event">';
print "<a class=\"timetitle\" href=\"#\" onClick='return clickevent(\"$eventid\")'>".hmmpm($record['eventtime']).' '.htmlspecialchars($record['title']).'</a>';
print "<div class=\"detail\" id=\"$eventid\">";
#time
if ($record['eventduration'] || $record['timedetails']) {
if ($record['eventduration']) {
print hmmpm($record['eventtime']).'-'.endtime($record['eventtime'],$record['eventduration']);
if ($record['timedetails'])
print ', ';
}
if ($record['timedetails'])
print htmlspecialchars($record['timedetails']);
print '<br />';
}
#place
if ($record['locname'])
print htmlspecialchars($record['locname']).', ';
print htmlspecialchars($record['address']);
if ($record['locdetails'])
print ', '.htmlspecialchars($record['locdetails']);
print '<br />';
#description
print htmlspecialchars($record['printdescr']);
print '<br />';
#contact
$name = htmlspecialchars(ucwords($record["name"]));
$email = $record["hideemail"] ? "" : htmlspecialchars($record["email"]);
$email = mangleemail($email);
$phone = $record["hidephone"] ? "" : htmlspecialchars($record["phone"]);
$contact = $record["hidecontact"] ? "" : htmlspecialchars($record["contact"]);
$weburl = $record["weburl"];
$webname = $record["webname"];
if ($webname == "" || $_REQUEST["p"] != "")
$webname = $weburl;
$webname = htmlspecialchars($webname);
print "$name";
if ($email)
print ", $email";
if ($phone)
print ", <a href=\"tel:$phone\">$phone</a>";
if ($contact)
print ", $contact";
if ($weburl)
print ", <a href=\"$weburl\">$webname</a>";
print '</div>'; # class="detail"
print '</div>'; # class="event"
}
}
# Special case: If passed a date=... parameter, return only its events.
if ($_REQUEST['date']) {
# The first line is the id of the <div> into which the data should go
print $_REQUEST['id']."\n";
# Fetch the events and return them in HTML format
$events = fetchevents(strtotime($_REQUEST['date']));
listevents($events);
# Don't do the normal page stuff!
exit(0);
}
####include("include/view.php");
?>
<html>
<head>
<title>
<?php
print PPNAME.' '.substr(PPSTART, 0, 4);
?>
</title>
<style type="text/css">
body { margin: 0; padding: 0; background: #ffc969; }
div.today { padding-top: 2px; border-top: 1px solid orange; border-bottom: 2px solid #ffc969; background: url(images/orangecorner.gif) no-repeat;}
div.date { padding-top: 2px; border-top: 1px solid orange; border-bottom: 2px solid #ffc969; background: url(images/oocorner.gif) no-repeat;}
div.dateevents { border-left: 3px solid orange; padding-left: 5px; display: none; }
div.event { }
div.detail { display: none; }
a.date { text-decoration: none; }
a.date:focus { font-size: larger; }
a.timetitle { text-decoration: none; }
a.timetitle:focus { font-size: larger; }
span.clipped { white-space: nowrap; overflow: hidden; }
</style>
<script type="text/JavaScript" src="include/xmlextras.js"></script>
<script type="text/JavaScript">
// List of pending fetches
var getting = Array();
// Scan getting[] for completed fetches
function gotevents()
{
for (i = 0; i < getting.length; i++) {
if (getting[i].readyState == 4) {
var text = getting[i].responseText;
getting.splice(i, 1);
var newline = text.indexOf('\n');
var dateid = text.slice(0, newline);
var html = text.slice(newline + 1);
var div = document.getElementById(dateid);
div.innerHTML = html;
}
}
}
// When a date is clicked, toggle its visibility
function clickdate(date, dateid)
{
var div = document.getElementById(dateid);
if (div.style.display != "block") {
div.style.display = "block";
if (div.innerHTML == "") {
div.innerHTML = "<img src=\"images/spinner.gif\" alt=\"Fetching data...\" />";
var conn = XmlHttp.create();
conn.open("GET", "mobilepp.php?date="+date+"&id="+dateid, true);
i = getting.push(conn);
conn.onreadystatechange = gotevents;
conn.send(null);
}
} else
div.style.display = "none";
return false;
}
// When a time/title is clicked, toggle its visibility
function clickevent(eventid)
{
var div = document.getElementById(eventid);
if (div.style.display != "block")
div.style.display = "block";
else
div.style.display = "none";
return false;
}
</script>
</head>
<body>
<span class="clipped">Mobile PP! Click any line to expand/shrink it.</span>
<br />
<?php
# for each day...
$today = strtotime(date("Y-m-d"));
$tomorrow = $today + 86400;
$enddate = strtotime(PPEND);
for ($thisdate = strtotime(PPSTART); $thisdate <= $enddate; $thisdate += 86400) {
#decide how to output this day
$dateclass = ($thisdate == $today) ? "today" : "date";
$dayofweek = date("D", $thisdate);
$preload = ($thisdate == $today || $thisdate == $tomorrow ||
(($dayofweek == 'Sat' || $dayofweek == 'Sun') && $thisdate < $today + 7 * 86400));
# fetch the events
$events = fetchevents($thisdate);
# scan the events for tinytitles to append after the date. We'll
# do this in three passes, with the most important first
$headline = '';
$len = 0;
if (mysql_num_rows($events) > 0) {
while (($record = mysql_fetch_array($events)) && $len < 80) {
if ($record['highlight']) {
if ($headline) {
$headline .= ', '.htmlspecialchars($record['tinytitle']);
$len += 2;
} else
$headline = htmlspecialchars($record['tinytitle']);
$len += strlen($record['tinytitle']);
}
}
mysql_data_seek($events, 0);
while (($record = mysql_fetch_array($events)) && $len < 80) {
if (!$record['highlight'] && $record['image']) {
if ($headline) {
$headline .= ', '.htmlspecialchars($record['tinytitle']);
$len += 2;
} else
$headline = htmlspecialchars($record['tinytitle']);
$len += strlen($record['tinytitle']);
}
}
mysql_data_seek($events, 0);
while (($record = mysql_fetch_array($events))) {
if (!$record['highlight'] && !$record['image']) {
if ($headline) {
$headline .= ', '.htmlspecialchars($record['tinytitle']);
$len += 2;
} else
$headline = htmlspecialchars($record['tinytitle']);
$len += strlen($record['tinytitle']);
}
}
mysql_data_seek($events, 0);
}
#output the day
$datestr = date('D M j', $thisdate);
$datearg = date('Y-m-d', $thisdate);
$dateid = date("Mj", $thisdate);
print "<div class=\"$dateclass\">";
print '<span class="clipped">';
print "<a class=\"date\" href=\"#\" onClick=\"return clickdate('$datearg', '$dateid')\"><strong>$datestr</strong>";
if ($headline)
print ": $headline";
print '</a>';
print '</span>';
print "<div id=\"$dateid\" class=\"dateevents\">";
if ($preload) {
listevents($events);
}
print '</div>';
print "</div>\n";
# if today, then output JavaScript code to show today's events and
# to scroll to today. (We want to do this as soon as possible when
# loading the page, since that's what the user probably wants to see.)
if ($thisdate == $today) {
print "<script type=\"text/javascript\">\n";
print "clickdate('$datearg', '$dateid');\n";
#!!! scroll!
print "</script>\n";
}
}
?>
<script type="text/JavaScript">
//Preload the "spinner" graphic image
var spinner = new Image();
spinner.src = "images/spinner.gif";
</script>
</body>
</html>
<?php
#ex:set sw=4 it=s:
?>