-
Notifications
You must be signed in to change notification settings - Fork 1
/
calendar.php
223 lines (187 loc) · 6.82 KB
/
calendar.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
<?php
date_default_timezone_set('UTC');
if (isset($_GET['m'])) {
$requestedMonthDiff = $_GET['m'];
}else{
$requestedMonthDiff = 0;
}
$requestedDateFull = date("Y-m", strtotime($requestedMonthDiff." months"));
$requestedYear = date("Y", strtotime($requestedMonthDiff." months"));
$requestedMonth = date("m", strtotime($requestedMonthDiff." months"));
$requestedDateFullText = date("F Y", strtotime($requestedMonthDiff." months"));
$currentDate = Date("Y-m");
$currentDay = Date("d");
$previousMonth = date("m", strtotime(($requestedMonthDiff-1)." months"));
$nDaysCurrent = cal_days_in_month(CAL_GREGORIAN, date("m", strtotime($requestedMonthDiff." months")), date("Y", strtotime($requestedMonthDiff." months")));
$nDaysPrevious = cal_days_in_month(CAL_GREGORIAN, $previousMonth, date("Y", strtotime($requestedMonthDiff." months")));
$firstDayOfCurrentMonth = $requestedDateFull.'-1';
$weekDayMonthStart = date('N', strtotime( $firstDayOfCurrentMonth));
$A=$nDaysPrevious;
$B=$nDaysCurrent;
$C=$weekDayMonthStart-1;
$M;
$x = 0;
$con = mysqli_connect("127.0.0.1", "jeremix", "Bn@n@s666", "bnanas");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
//get all friends name->distance for entire month, put into map. use map in javascript to color tiles.
mysqli_query($con, "SET CHARACTER SET utf8");
if ($results = mysqli_query($con, "SELECT user.Id, user.FirstName, user.LastName, location.Name, location.lat, location.long, day_user_location.Date
FROM user,location,user_location,day_user_location
WHERE user.Id = user_location.user_Id
AND location.Id = user_location.location_Id
AND day_user_location.User_location_Id = user_location.Id
AND DATE_FORMAT(day_user_location.Date,'%Y-%m') = '".$requestedDateFull."'
AND location_Id IN (
SELECT Id
FROM location
WHERE Id IN (
SELECT User_Location_Id
FROM day_user_location
WHERE Id IN (
SELECT day_user_location_Id
FROM day_user_location_visibility
WHERE User_Id = 2)))
")) {
$num_rows = $results->num_rows;
class calendarFriendsLocation
{
public $Id = '';
public $FirstName = '';
public $LastName = '';
public $Name = '';
public $Date = '';
public $lat = '';
public $long = '';
}
$fullResultsList = array();
$groupedResults = array();
while($result = mysqli_fetch_array($results)) {
$temp = new calendarFriendsLocation();
$temp->Id = $result['Id'];
$temp->FirstName = $result['FirstName'];
$temp->LastName = $result['LastName'];
$temp->Name = $result['Name'];
$temp->Date = $result['Date'];
$temp->lat = $result['lat'];
$temp->long = $result['long'];
if(array_key_exists($temp->Date , $groupedResults )){
$groupedResults[$temp->Date][]=$temp;
}
else{
$aux[] = $temp;
$groupedResults[$temp->Date] = $aux;
}
}
if (!empty($groupedResults)){
echo "<script>
var calendarFriendsLocation = JSON.parse('".json_encode($groupedResults)."');
for (date in calendarFriendsLocation){
$('#'+date).addClass('hasFriendsNearby0');
console.log(calendarFriendsLocation);
console.log(date);
}
</script>";
}
}
$endofprevius = false;
$endofcurrent = false;
for($i=0;$i<6;$i++){
for($j=0;$j<7;$j++){
if(!$endofprevius){
$day=$A-$C+$x+1;
$month= date("m", strtotime(($requestedMonthDiff-1)." months"));
$M[$i][$j][0]=$A-$C+$x+1;
$M[$i][$j][1]='prev';
$M[$i][$j][2]=$requestedYear.'-'.$month.'-'.$day;
//[2]=queryResultObject ??
$x++;
if($A-$C+$x == $A+1){
$endofprevius = true;
$x = 1;
}
}
if($endofprevius && !$endofcurrent){
$day=$x;
$month=$requestedMonth;
$M[$i][$j][0]=$x;
if(($currentDate == $requestedDateFull) && ($x == $currentDay)){
$M[$i][$j][1]='currDay';
}
else{
$M[$i][$j][1]='curr';
}
$M[$i][$j][2]=$requestedYear.'-'.$month.'-'.$day;
$x++;
if($x-1 == $B+1){
$endofcurrent = true;
$x = 1;
}
}
if($endofprevius && $endofcurrent){
$day=$x;
$month=date("m", strtotime(($requestedMonthDiff+1)." months"));
$M[$i][$j][0]=$x;
$M[$i][$j][1]='next';
$M[$i][$j][2]=$requestedYear.'-'.$month.'-'.$day;
$x++;
}
}
}
$W = array('Mon','Tue','Wed','Thu','Fri','Sat','Sun');
//<button onclick="window.location.href=\'http://localhost/bnanas/?m='.($requestedMonthDiff-1).'\'">p</button>'.
echo '<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>
<div class="datePicker">
<button onclick="changeMonth('.($requestedMonthDiff-1).');" title="Previous month"> <img class="previmage" src="i/play45.png"/>
</button> <p id="selectedDateTitle" class="noselect">'.
$requestedDateFullText .
'</p> <button onclick="changeMonth('.($requestedMonthDiff+1).');" title="Next month"> <img class="nextimage" src="i/play45.png"/>
</button>
</div>
<div class="calendarContainer">';
for($j=0;$j<7;$j++){
echo '<div class="columnContainer">
<div class="rowElement noselect myHeader">'
.$W[$j].'
</div>';
for($i=0;$i<6;$i++){
echo '<div id="'.$M[$i][$j][2].'" class="DateSquare noselect rowElement '.$M[$i][$j][1].'">
'.$M[$i][$j][0].'
</div> ';
}
echo '</div>';
}
echo '</div>';
/*{{content['.$i.']['.$j.']}}*/
/*
$link = mysqli_connect("127.0.0.1", "jeremix", "Bn@n@s666", "bnanas");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
*/
$p1 = array("lat" => "38.5836479","lng" => "-7.9069337"); //Evora
$p2 = array("lat" => "48.8666667","lng" => "2.3333333"); // Paris
$km = distanceCalculation($p1, $p2, 2); // Calculate distance in kilometres (default)
//echo $km;
function distanceCalculation($point1, $point2, $decimals) {
// Calculate the distance in degrees
$degrees = rad2deg(acos((sin(deg2rad($point1['lat']))*sin(deg2rad($point2['lat']))) + (cos(deg2rad($point1['lat']))*cos(deg2rad($point2['lat']))*cos(deg2rad($point1['lng']-$point2['lng'])))));
return round($degrees * 111.13384, $decimals);
}
?>
<script>
function changeMonth(value){
$('.mainCalendarContainer').load('calendar.php?m='+value);
}
function makeCalendarclickable(){
$(".DateSquare").click(function() {
//console.log(this.id);
$(".popUpDayDetailContainer").toggleClass( "hidden" );
$('.popUpDayDetailContainer').load('daydetail.php?d='+this.id);
return false;
});
}
makeCalendarclickable();
</script>