-
Notifications
You must be signed in to change notification settings - Fork 4
/
snapshot.php
279 lines (250 loc) · 11.5 KB
/
snapshot.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
<?php
/*
This file is part of Church Rota.
Copyright (C) 2011 David Bunce, Benjamin Schmitt
Church Rota 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 3 of the License, or
(at your option) any later version.
Church Rota is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Church Rota. If not, see <http://www.gnu.org/licenses/>.
*/
// Include files, including the database connection
include('includes/dbConfig.php');
include('includes/functions.php');
$filter = $_GET['filter'];
$show = $_GET['show'];
// Start the session. This checks whether someone is logged in and if not redirects them
session_start();
if (isset($_SESSION['is_logged_in']) || $_SESSION['db_is_logged_in'] == true) {
// Just continue the code
//check users maximal skillgroup (maxGroup), if logged in.
$sql = "select max(formatgroup) as max_group from cr_skills s, cr_groups g where s.groupID=g.groupID and s.userID=". $_SESSION['userid'];
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$maxGroup = $row['max_group'];
if ($maxGroup=='') $maxGroup=1;
}
else
{
//if not logged in, only show skills of skillgroup 1
$maxGroup=1;
}
//echo "maxGroup=".$maxGroup."<br>";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Snapshot view</title>
<link rel="stylesheet" href="includes/style.css" type="text/css" />
</head>
<?php
$sqlSettings = "SELECT * FROM cr_settings";
$resultSettings = mysql_query($sqlSettings) or die(mysql_error());
$rowSettings = mysql_fetch_array($resultSettings, MYSQL_ASSOC);
$lang_locale = $rowSettings['lang_locale'];
$time_format_short = $rowSettings['time_format_short'];
$userTZ=$rowSettings['time_zone'];
$google_group_calendar=$rowSettings['google_group_calendar'];
if ((isAdmin()) || ($rowSettings['snapshot_reduce_skills_by_group']=='0')) {
$maxGroup=999; //show all skill groups, if admin or option not used
}
if ($rowSettings['snapshot_show_two_month']=='1') {
$whereTwoMonth = "Year(date) = Year(Now()) AND ((Month(date) = Month(Now())) OR ((Month(date) = Month(Now())+1) AND (Day(Now())>20)))";
$whereTwoMonth = $whereTwoMonth . " and cr_events.date >= DATE(NOW())";
}else{
if ($show=='all')
$whereTwoMonth = "1=1";
else
$whereTwoMonth = "cr_events.date >= DATE(NOW())";
}
if ($show=='current_year')
$whereTwoMonth = "Year(date) = Year(Now())";
if ($rowSettings['group_sorting_name']=='1') {
$group_sorting_name = "formatgroup,description";
}else{
$group_sorting_name = "groupID";
}
$sql = "SELECT count(*) as colcount FROM cr_groups where formatgroup<=" . $maxGroup;
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$colCnt = $row['colcount']+2;
if (isset($_GET['column_width'])) {
$colWidth=$_GET['column_width'];
}
else{
$colWidth=0; //full-size table, backward compatibility
}
?>
<body>
<div id="header">
<a href="index.php" id="logo"><img src="graphics/logo.jpg" alt="Church Rota Logo" width="263" height="48" /></a>
<ul>
<?php if(isLoggedIn()) { ?>
<li <?php echo (basename($_SERVER['SCRIPT_FILENAME'])=='index.php'? 'class="active"' : '');?>><a href="index.php">Home</a></li>
<li <?php echo (basename($_SERVER['SCRIPT_FILENAME'])=='resources.php'? 'class="active"' : '');?> ><a href="resources.php">Resources</a></li>
<li <?php echo (basename($_SERVER['SCRIPT_FILENAME'])=='discussion.php'? 'class="active"' : '');?>
<?php if(!isAdmin()) { ?><li <?php echo (basename($_SERVER['SCRIPT_FILENAME'])=='addUser.php'? 'class="active"' : '');?>><a href="addUser.php?action=edit&id=<?php echo $_SESSION['userid']; ?>">My account</a></li><?php } ?>
<?php }
if(isAdmin()) { ?>
<li <?php echo (basename($_SERVER['SCRIPT_FILENAME'])=='viewUsers.php'? 'class="active"' : '');
echo (basename($_SERVER['SCRIPT_FILENAME'])=='addUser.php'? 'class="active"' : ''); ?> ><a href="viewUsers.php">Users</a></li>
<li <?php echo (basename($_SERVER['SCRIPT_FILENAME'])=='settings.php'? 'class="active"' : '');
echo (basename($_SERVER['SCRIPT_FILENAME'])=='editeventtype.php'? 'class="active"' : '');
echo (basename($_SERVER['SCRIPT_FILENAME'])=='editSkills.php'? 'class="active"' : '');
echo (basename($_SERVER['SCRIPT_FILENAME'])=='locations.php'? 'class="active"' : '');?>><a href="settings.php">Settings</a></li>
<?php } ?>
<?php if(isLoggedIn()) { ?>
<li <?php echo (basename($_SERVER['SCRIPT_FILENAME'])=='logout.php'? 'class="active"' : '');?>><a href="logout.php">Logout</a></li>
<?php } ?>
</ul>
</div>
<div class="filtersnapshot">
<h1>Snapshot view - <?php echo $owner; ?></h1>
<h2>Filter events by:</h2>
<p>
<a class="eventTypeButton
<?php
if($show == "" and $filter == "") {
echo "activefilter";
}
?>" href="snapshot.php">All:open</a>
<a class="eventTypeButton
<?php
if($show == "current_year") {
echo "activefilter";
}
?>" href="snapshot.php?show=current_year">All:<?php echo date("Y"); ?></a>
<?php
if ((isAdmin()) && ($rowSettings['snapshot_show_two_month']=='0')) {
?>
<a class="eventTypeButton
<?php
if($show == "all") {
echo "activefilter";
}
?>" href="snapshot.php?show=all">All</a>
<?php
}
$filter_sql = "SELECT * FROM cr_eventTypes where id in
(select `cr_events`.`type` FROM cr_events
WHERE ".$whereTwoMonth."
AND cr_events.deleted = 0)
ORDER BY description";
$result = mysql_query($filter_sql) or die(mysql_error());
?>
<br>
<?php
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<a class="eventTypeButton
<?php
if($filter == $row['id']) {
echo "activefilter";
}
?>" href="snapshot.php?filter=<?php echo $row['id']; ?>&show=<?php echo $show; ?>"><?php echo $row['description']; ?></a>
<?php
}
?>
</p>
</div>
<table class="snapshot" width='<?php echo (($colCnt)*$colWidth); ?>'>
<tr>
<td ><strong>Event</strong></td>
<?php
$sql = "SELECT * FROM cr_groups where formatgroup <= " . $maxGroup . " ORDER BY " . $group_sorting_name;
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<td><strong>";
echo $row['description'];
$categoryID[] = $row['groupID'];
echo "</strong></td>";
}
echo "<td><strong>Export</strong></td>";
if( $filter == "") {
$sql = "SELECT *,
(SELECT `description` FROM cr_eventTypes WHERE cr_eventTypes.id = `cr_events`.`type`) AS eventType,
(SELECT `description` FROM cr_locations WHERE cr_locations.id = `cr_events`.`location`) AS eventLocation,
DATE_FORMAT(date,'%m/%d/%Y %H:%i:%S') AS sundayDate, DATE_FORMAT(rehearsalDate,'%m/%d/%Y %H:%i:%S') AS rehearsalDateFormatted ,
DATE_FORMAT(DATE_ADD(date, INTERVAL 90 MINUTE),'%m/%d/%Y %H:%i:%S') AS sundayEndDate
FROM cr_events
WHERE " . $whereTwoMonth . "
AND cr_events.deleted = 0
ORDER BY date";
} else if($filter != "") {
$sql = "SELECT *,
(SELECT `description` FROM cr_eventTypes WHERE cr_eventTypes.id = `cr_events`.`type`) AS eventType,
(SELECT `description` FROM cr_locations WHERE cr_locations.id = `cr_events`.`location`) AS eventLocation,
DATE_FORMAT(date,'%m/%d/%Y %H:%i:%S') AS sundayDate, DATE_FORMAT(rehearsalDate,'%m/%d/%Y %H:%i:%S') AS rehearsalDateFormatted,
DATE_FORMAT(DATE_ADD(date, INTERVAL 90 MINUTE),'%m/%d/%Y %H:%i:%S') AS sundayEndDate
FROM cr_events
WHERE `cr_events`.`type` = '$filter'
AND " . $whereTwoMonth . "
AND cr_events.deleted = 0
ORDER BY date";
}
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$eventID = $row['id'];
$comment = $row['comment'];
$preacher="";
$leader="";
$band="";
echo "<tr>";
echo "<td >";
setlocale(LC_TIME, $lang_locale); //de_DE
echo strftime($time_format_short,strtotime($row['sundayDate'])); // %a, <strong>%e. %b</strong>, KW%V
//$row['sundayDate']
echo "<br /><em> " . $row['eventType'] . "<br /><em> " . $row['eventLocation']. "</td><td >";
$sqlPeople = "SELECT *,
(SELECT TRIM(TRIM(LEADING '.' FROM CONCAT(if(`firstname`='Team',`firstname`,concat(LEFT(`firstname`,1),'.')), ' ', `lastname`))) FROM cr_users WHERE `cr_users`.id = `cr_skills`.`userID` ORDER BY `cr_users`.firstname)
AS `name`,
(SELECT `description` FROM cr_groups WHERE `cr_skills`.`groupID` = `cr_groups`.`groupID`) AS `category`,
GROUP_CONCAT(skill) AS joinedskill
FROM cr_skills WHERE skillID IN (SELECT skillID FROM cr_eventPeople WHERE eventID = '$eventID' and groupID in (select groupID from cr_groups where formatgroup<=" . $maxGroup . "))
GROUP BY skillID ORDER BY groupID, name";
for ($i=0;$i<count($categoryID);$i++)
{
$resultPeople = mysql_query($sqlPeople) or die(mysql_error());
while($viewPeople = mysql_fetch_array($resultPeople, MYSQL_ASSOC)) {
$groupID = $viewPeople['groupID'];
if ($groupID==$categoryID[$i])
{
//writing name/s into snapshot cell
echo $viewPeople['name'];
echo "<br />";
//no break or continue, because there could be other viewPeople with same categoryID
}
}
echo "</td><td>";
}
//generate google calendar urls
putenv("TZ=".$userTZ);
$eventDate = $row['sundayDate'];
$eventDateGMT = gmdate("Ymd\THis\Z",strtotime($eventDate." ".date("T",strtotime($eventDate))));
//echo $eventDateGMT."<br>";
$eventDate = $row['sundayEndDate'];
$eventDateEndGMT = gmdate("Ymd\THis\Z",strtotime($eventDate." ".date("T",strtotime($eventDate))));
//echo $eventDateEndGMT;
if (isAdmin()) {
if ($comment<>"")
$comment = "; " . $comment;
$comment = str_replace("\r\n","; ",$comment);
echo "<a href=\"http://www.google.com/calendar/event?action=TEMPLATE&text=".urlencode(utf8_wrapper(getEventDetails($eventID, " / ",1)." (".$row['eventType'].")"))."&dates=".$eventDateGMT."/".$eventDateEndGMT."&details=".urlencode(utf8_wrapper(ltrim(getEventDetails($eventID, "; ",0,false) . $comment,"; ")))."&location=".urlencode(utf8_wrapper($row['eventLocation']))."&trp=false&sprop=&sprop=name:&src=".$google_group_calendar."&ctz=".$userTZ."\" target=\"_blank\">";
echo "<img src=\"//www.google.com/calendar/images/ext/gc_button1.gif\" border=0></a><BR>";
//echo "iCal";
}else{
echo "<a href=\"http://www.google.com/calendar/event?action=TEMPLATE&text=".urlencode(utf8_wrapper($row['eventType']))."&dates=".$eventDateGMT."/".$eventDateEndGMT."&details=&location=".urlencode(utf8_wrapper($row['eventLocation']))."&trp=false&sprop=&sprop=name:&ctz=".$userTZ."\" target=\"_blank\">";
echo "<img src=\"//www.google.com/calendar/images/ext/gc_button1.gif\" border=0></a>";
}
echo "</td></tr>\r\n";
}
?>
</table>
</body>
</html>