/
CMS_AJAX_FetchEvents.php
116 lines (108 loc) · 5 KB
/
CMS_AJAX_FetchEvents.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
<?php
/**
* Created by PhpStorm.
* User: Christian
* Date: 3/23/2019
* Time: 11:34 PM
*/
include_once('GLOBAL_CLASS_CRUD.php');
$crud = new GLOBAL_CLASS_CRUD();
if(isset($_POST['requestType'])){
$requestType = $_POST['requestType'];
if($requestType == 'ALL'){
$query = "SELECT e.*, p.permalink FROM facultyassocnew.events e LEFT JOIN post_ref_events ref ON e.id = ref.eventId LEFT JOIN posts p ON ref.postId = p.id ORDER BY startTime DESC;";
$rows = $crud->getData($query);
$data = [];
foreach ((array) $rows as $key => $row) {
$status = 'CONFIRMED';
if($row['statusId'] == '2'){
$status = 'CANCELLED';
}
$permalink = $row['permalink'];
$button = '';
if($permalink != ''){
$button = '<a href="http://localhost/FRAP_sd/read.php?pl='.$permalink.'" target="_blank" class="btn btn-default">View Post</a>';
}else{
$button = 'NONE';
}
$data[] = array(
'event' => '<b>'.$row['title'].'</b>',
'start' => date("F j, Y g:i:s A ", strtotime($row['startTime'])),
'end' => date("F j, Y g:i:s A ", strtotime($row['endTime'])),
'status' => $status,
'permalink' => $button,
'added_by' => $crud->getUserName($row['posterId']),
'added_on' => $crud->friendlyDate($row['firstCreated']),
'action'=> '<a class="btn btn-default" href="'.$row['GOOGLE_EVENTLINK'].'" target="_blank" title="View in Google Calendar"><i class="fa fa-google fa-calendar"></i></a>'
);
}
echo json_encode($data);
}else if($requestType == 'UPCOMING'){
$query = "SELECT * FROM facultyassocnew.events WHERE startTime > NOW() AND statusId = 1 ORDER BY startTime DESC;";
$rows = $crud->getData($query);
$data = [];
foreach ((array) $rows as $key => $row) {
$status = 'CONFIRMED';
if($row['statusId'] == '2'){
$status = 'CANCELLED';
}
$data[] = array(
'event' => '<b>'.$row['title'].'</b>',
'start' => date("F j, Y g:i:s A ", strtotime($row['startTime'])),
'end' => date("F j, Y g:i:s A ", strtotime($row['endTime'])),
'action'=> '<button type="button" class="btn btn-default"><a href="'.$row['GOOGLE_EVENTLINK'].'" target="_blank"> Google </a></button>'
);
}
echo json_encode($data);
}else if($requestType == 'POST_ATTACHED_EVENTS' && isset($_POST['postId'])){
$postId = $_POST['postId'];
$query = "SELECT * FROM events e JOIN post_ref_events ref ON e.id = ref.eventId WHERE ref.postId = '$postId' ORDER BY startTime DESC;";
$rows = $crud->getData($query);
$data = [];
foreach ((array) $rows as $key => $row) {
$status = 'CONFIRMED';
if($row['statusId'] == '2'){
$status = 'CANCELLED';
}
$data[] = array(
'event' => '<div class="card">
<div class="card-body"><small>
Event: '.$row['title'].'
<br>Start: '.$crud->friendlyDate($row['startTime']).'
<br>End: '.$crud->friendlyDate($row['endTime']).'
<br>Created by: '.$crud->getUserName($row['posterId']).'
<br>Created on: '.$crud->friendlyDate($row['firstCreated']).'
<br><a href="'.$row['GOOGLE_EVENTLINK'].'" target="_blank" title="View in Google Calendar" class="btn btn-info btn-sm"><i class="fa fa-calendar"> View on GCal</i></a>
</small>
</div>
</div>
'
);
}
echo json_encode($data);
}else if($requestType == 'ADD_POST_EVENT' && isset($_POST['postId'])){
$postId = $_POST['postId'];
$title = $crud->escape_string($_POST['event_title']);
$body = $crud->escape_string($_POST['event_content']);
$startTime = $_POST['event_start'];
$endTime = $_POST['event_end'];
$userId = $_POST['userId'];
$email_array = [];
if(isset($_POST['toAddEmails'])){
$email_array = $_POST['toAddEmails'];
}
$startTime = preg_replace('/\s+/', 'T', $startTime);
$endTime = preg_replace('/\s+/', 'T', $endTime);
$bool = $crud->insertCalendarEvent($userId, $title, $body, $startTime, $endTime, $email_array, 'DAILY','1');
if(is_numeric($bool)){
$bool2 = $crud->executeGetKey("INSERT INTO post_ref_events (postId, eventId) VALUES('$postId','$bool')");
if($bool2 != false){
echo 'success';
}else{
echo $bool2;
}
}else{
echo $bool;
}
}
}