-
Notifications
You must be signed in to change notification settings - Fork 2
/
ListEvents.php
369 lines (335 loc) · 13.6 KB
/
ListEvents.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
/*******************************************************************************
*
* filename : ListEvents.php
* website : http://www.churchdb.org
* function : List all Church Events
*
* copyright : Copyright 2005 Todd Pillars
*
*
* Additional Contributors:
* 2007 Ed Davis
*
*
* Copyright Contributors
*
*
* ChurchInfo is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This file best viewed in a text editor with tabs stops set to 4 characters.
* Please configure your editor to use soft tabs (4 spaces for a tab) instead
* of hard tab characters.
*
******************************************************************************/
require 'Include/Config.php';
require 'Include/Functions.php';
$eType="All";
$ThisYear=date("Y");
if ($_POST['WhichType']){
$eType = $_POST['WhichType'];
} else {
$eType ="All";
}
if($eType!="All"){
$sSQL = "SELECT * FROM event_types WHERE type_id=$eType";
$rsOpps = RunQuery($sSQL);
$aRow = mysql_fetch_array($rsOpps, MYSQL_BOTH);
extract($aRow);
$sPageTitle = "Listing Events of Type = ".$type_name;
} else {
$sPageTitle = gettext("Listing All Church Events");
}
// retrieve the year selector
if($_POST['WhichYear'])
{
$EventYear=$_POST['WhichYear'];
} else {
$EventYear=date("Y");
}
///////////////////////
require 'Include/Header.php';
if ($_POST['Action']== "Delete" && !empty($_POST['EID']))
{
$sSQL = "DELETE FROM events_event WHERE event_id = ".$_POST['EID']." LIMIT 1";
RunQuery($sSQL);
$sSQL = "DELETE FROM eventcounts_evtcnt WHERE evtcnt_eventid = ".$_POST['EID'];
RunQuery($sSQL);
}
elseif ($_POST['Action']== "Activate" && !empty($_POST['EID']))
{
$sSQL = "UPDATE events_event SET inactive = 0 WHERE event_id = ".$_POST['EID']." LIMIT 1";
RunQuery($sSQL);
}
/// top of main form
//
$sSQL = "SELECT DISTINCT event_types.* FROM event_types RIGHT JOIN events_event ON event_types.type_id=events_event.event_type ORDER BY type_id ";
$rsOpps = RunQuery($sSQL);
$numRows = mysql_num_rows($rsOpps);
?>
<table cellpadding="1" align="center" cellspacing="0" width="100%">
<tr>
<td align="center" width="50%"><strong><?php echo gettext("Select Event Types To Display") ?></strong><br>
<form name="EventTypeSelector" method="POST" action="ListEvents.php">
<select name="WhichType" onchange="javascript:this.form.submit()">
<option value="All">All</option>
<?php
for ($r = 1; $r <= $numRows; $r++)
{
$aRow = mysql_fetch_array($rsOpps, MYSQL_BOTH);
extract($aRow);
// foreach($aRow as $t)echo "$t\n\r";
?>
<option value="<?php echo $type_id ?>" <?php if($type_id==$eType) echo "selected" ?>><?php echo $type_name; ?></option>
<?php
}
?>
</select>
</td>
<?php
// year selector
if($eType=="All"){
$sSQL = "SELECT DISTINCT YEAR(events_event.event_start) FROM events_event WHERE YEAR(events_event.event_start)";
} else {
$sSQL = "SELECT DISTINCT YEAR(events_event.event_start) FROM events_event WHERE events_event.event_type = '$eType' AND YEAR(events_event.event_start)";
}
$rsOpps = RunQuery($sSQL);
$aRow = mysql_fetch_array($rsOpps, MYSQL_BOTH);
@extract($aRow); // @ needed to suppress error messages when no church events
$rsOpps = RunQuery($sSQL);
$numRows = mysql_num_rows($rsOpps);
for($r=1; $r<=$numRows; $r++){
$aRow = mysql_fetch_array($rsOpps, MYSQL_BOTH);
extract($aRow);
$Yr[$r]=$aRow[0];
}
?>
<td align="center" width="50%"><strong><?php echo gettext("Display Events in Year") ?></strong><br>
<select name="WhichYear" onchange="javascript:this.form.submit()" >
<?php
for ($r = 1; $r <= $numRows; $r++)
{
?>
<option value="<?php echo $Yr[$r] ?>" <?php if($Yr[$r]==$EventYear) echo "selected" ?>><?php echo $Yr[$r]; ?></option>
<?php
}
?>
</select>
</form>
</td>
</tr>
</table>
<?php
// Get data for the form as it now exists..
// for this year
$currYear = date("Y");
$currMonth = date("m");
$allMonths = array("1","2","3","4","5","6","7","8","9","10","11","12");
if ($eType=="All") {
$eTypeSQL=" ";
} else {
$eTypeSQL = " AND t1.event_type=$eType";
}
foreach ($allMonths as $mKey => $mVal) {
unset($cCountSum);
$sSQL = "SELECT * FROM events_event as t1, event_types as t2 ";
if (isset($previousMonth))
{
// $sSQL .= " WHERE previous month stuff";
}
elseif (isset($nextMonth))
{
// $sSQL .= " WHERE next month stuff";
}
elseif (isset($showAll))
{
$sSQL .="";
}
else
{
//$sSQL .= " WHERE (TO_DAYS(event_start_date) - TO_DAYS(now()) < 30)";
$sSQL .= " WHERE t1.event_type = t2.type_id".$eTypeSQL." AND MONTH(t1.event_start) = ".$mVal." AND YEAR(t1.event_start)=$EventYear";
}
$sSQL .= " ORDER BY t1.event_start ";
$rsOpps = RunQuery($sSQL);
$numRows = mysql_num_rows($rsOpps);
$aAvgRows = $numRows;
// Create arrays of the fundss.
for ($row = 1; $row <= $numRows; $row++)
{
$aRow = mysql_fetch_array($rsOpps, MYSQL_BOTH);
extract($aRow);
$aEventID[$row] = $event_id;
$aEventType[$row] = $event_typename;
$aEventName[$row] = htmlentities(stripslashes($event_name),ENT_NOQUOTES, "UTF-8");
$aEventTitle[$row] = htmlentities(stripslashes($event_title),ENT_NOQUOTES, "UTF-8");
$aEventDesc[$row] = htmlentities(stripslashes($event_desc),ENT_NOQUOTES, "UTF-8");
$aEventText[$row] = htmlentities(stripslashes($event_text),ENT_NOQUOTES, "UTF-8");
$aEventStartDateTime[$row] = $event_start;
$aEventEndDateTime[$row] = $event_end;
$aEventStatus[$row] = $inactive;
// get the list of attend-counts that exists in event_attend for this
$attendSQL="SELECT * FROM event_attend WHERE event_id=$event_id";
$attOpps = RunQuery($attendSQL);
if($attOpps)
$attNumRows[$row] = mysql_num_rows($attOpps);
else
$attNumRows[$row]=0;
}
// Construct the form
?>
<table cellpadding="4" align="center" cellspacing="0" width="100%">
<?php
if ($numRows > 0)
{
?>
<caption>
<h3><?php echo gettext("There ".($numRows == 1 ? "is ".$numRows." event":"are ".$numRows." events")." for ".date("F", mktime(0, 0, 0, $mVal, 1, $currYear))); ?></h3>
</caption>
<tr class="TableHeader">
<td width="15%"><strong><?php echo gettext("Event Type"); ?></strong></td>
<td width="20%"><strong><?php echo gettext("Event Title"); ?><br></strong>
<strong><?php echo gettext("Description"); ?></strong></td>
<td width="35%" align="center"><strong><?php echo gettext("Attendance Counts"); ?></strong></td>
<td width="10%" align="center"><strong><?php echo gettext("Start Date/Time"); ?></strong></td>
<td width="5%" align="center"><strong><?php echo gettext("Active"); ?></strong></td>
<td colspan="3" width="15%" align="center"><strong><?php echo gettext("Action"); ?></strong></td>
</tr>
<?php
//Set the initial row color
$sRowClass = "RowColorA";
for ($row=1; $row <= $numRows; $row++)
{
//Alternate the row color
$sRowClass = AlternateRowStyle($sRowClass);
//Display the row
?>
<tr class="<?php echo $sRowClass; ?>">
<td><span class="SmallText"><?php echo $aEventType[$row]; ?></span></td>
<td><span class="SmallText"><?php echo $aEventTitle[$row]; ?><br>
<?php echo ($aEventDesc[$row] == '' ? " ":$aEventDesc[$row]); ?>
<?php echo ($aEventText[$row] != '' ? " <a href=\"javascript:popUp('GetText.php?EID=".$aEventID[$row]."')\"><strong>Sermon Text</strong></a>":""); ?></span>
</td>
<td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<?php
// RETRIEVE THE list of counts associated with the current event
//
$cvSQL= "SELECT * FROM eventcounts_evtcnt WHERE evtcnt_eventid='$aEventID[$row]' ORDER BY evtcnt_countid ASC";
// echo $cvSQL;
$cvOpps = RunQuery($cvSQL);
$aNumCounts = mysql_num_rows($cvOpps);
// echo "numcounts = {$aNumCounts}\n\l";
if($aNumCounts) {
for($c = 0; $c <$aNumCounts; $c++){
$cRow = mysql_fetch_array($cvOpps, MYSQL_BOTH);
extract($cRow);
$cCountID[$c] = $evtcnt_countid;
$cCountName[$c] = $evtcnt_countname;
$cCount[$c]= $evtcnt_countcount;
$cCountNotes = $evtcnt_notes;
// $cCountSum[$c]+= $evtcnt_countcount;
?>
<td align="center">
<span class="SmallText">
<strong><?php echo $evtcnt_countname; ?></strong>
<br><?php echo $evtcnt_countcount; ?></span>
</td>
<?php
}
} else {
?>
<td align="center">
<span class="SmallText">
<strong><?php echo gettext("No Attendance Recorded"); ?></strong>
</span>
</td>
<?php
// $aAvgRows -=1;
}
?>
</tr>
</table>
</td>
<td><span class="SmallText"><?php echo FormatDate($aEventStartDateTime[$row],1); ?></span></td>
<td class="SmallText" align="center"><?php echo ($aEventStatus[$row] != 0 ? "No":"Yes"); ?></span></td>
<td><span class="SmallText">
<form name="EditAttendees" action="EditEventAttendees.php" method="POST">
<input type="hidden" name="EID" value="<?php echo $aEventID[$row]; ?>">
<input type="hidden" name="EName" value="<?php echo $aEventTitle[$row]; ?>">
<input type="hidden" name="EDesc" value="<?php echo $aEventDesc[$row]; ?>">
<input type="hidden" name="EDate" value="<?php echo FormatDate($aEventStartDateTime[$row],1); ?>">
<input type="submit" name="Action" value="<?php echo gettext("Attendees(".$attNumRows[$row].")"); ?>" class="icButton" >
</form></span>
</td>
<td align="center"><span class="SmallText">
<form name="EditEvent" action="EventEditor.php" method="POST">
<input type="hidden" name="EID" value="<?php echo $aEventID[$row]; ?>">
<input class="SmallText" type="submit" name="Action" <?php echo 'value="' . gettext("Edit") . '"'; ?> class="icButton">
</form></span>
</td>
<td><span class="SmallText">
<form name="DeleteEvent" action="ListEvents.php" method="POST">
<input type="hidden" name="EID" value="<?php echo $aEventID[$row]; ?>">
<input class="SmallText" type="submit" name="Action" value="<?php echo gettext("Delete"); ?>" class="icButton" onClick="return confirm('Deleting an event will also delete all attendance counts for that event. Are you sure you want to DELETE Event ID: <?php echo $aEventID[$row]; ?>')">
</form></span>
</td>
</tr>
<?php
} // end of for loop for # rows for this month
// calculate averages if this is a single type list
if ($eType != "All" && $aNumCounts >0){
$avgSQL="SELECT evtcnt_countid, evtcnt_countname, AVG(evtcnt_countcount) from eventcounts_evtcnt, events_event WHERE eventcounts_evtcnt.evtcnt_eventid=events_event.event_id AND events_event.event_type='$eType' AND MONTH(events_event.event_start)='$mVal' GROUP BY eventcounts_evtcnt.evtcnt_countid ASC ";
$avgOpps = RunQuery($avgSQL);
$aAvgRows = mysql_num_rows($avgOpps);
?>
<tr>
<td class="LabelColumn" colspan="2"><?php echo gettext(" Monthly Averages"); ?></td>
<td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<?php
// calculate and report averages
for($c = 0; $c <$aAvgRows; $c++){
$avgRow = mysql_fetch_array($avgOpps, MYSQL_BOTH);
extract($avgRow);
$avgName = $avgRow['evtcnt_countname'];
$avgAvg = $avgRow[2];
?>
<td align="center">
<span class="SmallText">
<strong>AVG<br><?php echo $avgName;?></strong>
<br><?php echo sprintf("%01.2f",$avgAvg); ?></span>
</td>
<?php
}
?>
</tr>
</table>
</td>
<td class="TextColumn" colspan="3"></td>
</tr>
<?php }
?>
<tr><td class="TextColumn" colspan="6"> </td></tr>
<?php
}
?>
</table>
<?php
} // end for-each month loop
?>
<table width="100%">
<tr class="<?php echo $sRowClass; ?>">
<td align="center" valign="bottom">
<input type="button" Name="Action" <?php echo 'value="' . gettext("Add New Event") . '"'; ?> class="icButton" onclick="javascript:document.location='EventNames.php';">
</td>
</tr>
</table>
<?php
require 'Include/Footer.php';
?>