/
function.php
157 lines (140 loc) · 4.63 KB
/
function.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
<?php
include 'config.php';
if(!isset($_SESSION['client'])){
header('Location: callback.php');
}
$client = $_SESSION['client'];
function people_table() {
global $client, $baseApiUrl;
$response = $client->fetch($baseApiUrl . '/api/v1/people');
echo "<table class='table table-striped'>";
echo "<tr><th>id</th><th>First</th><th>Last</th><th>Email</th><th>Actions</th></tr>";
foreach( $response['result']['results'] as $k => $v){
echo "<tr>";
echo '<td>'.$v['id'].'</td>';
echo '<td>'.$v['first_name'].'</td>';
echo '<td>'.$v['last_name'].'</td>';
echo '<td>'.$v['email'].'</td>';
echo '<td>';
echo '<a href="function.php?delete='.$v['id'].'" onclick="return confirm(\'Are you sure you want to delete this user?\')" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-trash"></span></a> ';
echo '<a href="edit_person.php?id='.$v['id'].'" class="btn btn-sm btn-success"><span class="glyphicon glyphicon-pencil"></span></a>';
echo '</td>';
echo "</tr>";
}
echo "</table>";
}
function event_table() {
global $client, $baseApiUrl, $baseSiteSlug;
$response = $client->fetch($baseApiUrl . '/api/v1/sites/'.$baseSiteSlug.'/pages/events');
echo "<table class='table table-striped'>";
echo "<tr><th>id</th><th>Event Name</th><th>Starts</th><th>Ends</th><th>Actions</th></tr>";
foreach( $response['result']['results'] as $k => $v){
echo "<tr>";
echo '<td>'.$v['id'].'</td>';
echo '<td>'.$v['name'].'</td>';
echo '<td>'.date('m/d/Y H:m', strtotime($v['start_time'])).'</td>';
echo '<td>'.date('m/d/Y H:m', strtotime($v['end_time'])).'</td>';
echo '<td>';
echo '<a href="event.php?id='.$v['id'].'" class="btn btn-sm btn-success"><span class="glyphicon glyphicon-pencil"></span></a>';
echo '</td>';
echo "</tr>";
}
echo "</table>";
}
function create_person($details){
global $client, $baseApiUrl;
$params = array(
'person'=> array(
'email'=>$details['email'],
'first_name'=>$details['fname'],
'last_name'=>$details['lname']
)
);
$header = array(
'Authorization' => $_SESSION['token'],
'Content-Type' => 'application/json',
'Accept' => 'application/json'
);
$response = $client->fetch($baseApiUrl . '/api/v1/people',json_encode($params),'POST',$header,0);
header('Location: index.php');
}
function create_event($details){
global $client, $baseApiUrl, $baseSiteSlug;
$params = array(
'event'=> array(
'name'=>$details['name'],
'status'=>$details['status'],
'start_time'=>$details['start_time'],
'end_time'=>$details['end_time']
)
);
$header = array(
'Authorization' => $_SESSION['token'],
'Content-Type' => 'application/json',
'Accept' => 'application/json'
);
$response = $client->fetch($baseApiUrl . '/api/v1/sites/'.$baseSiteSlug.'/pages/events',json_encode($params),'POST',$header,0);
header('Location: index.php');
}
function read_person($id){
global $client, $baseApiUrl;
return $client->fetch($baseApiUrl . '/api/v1/people/'.$id);
}
function read_event($id){
global $client, $baseApiUrl, $baseSiteSlug;
return $client->fetch($baseApiUrl . '/api/v1/sites/'.$baseSiteSlug.'/pages/events/'.$id);
}
function update_person($details){
global $client, $baseApiUrl;
$params = array(
'person'=> array(
'email'=>$details['email'],
'first_name'=>$details['fname'],
'last_name'=>$details['lname']
),
);
$header = array(
'Authorization' => $_SESSION['token'],
'Content-Type' => 'application/json',
'Accept' => 'application/json'
);
$response = $client->fetch($baseApiUrl . '/api/v1/people/'.$details['id'],json_encode($params),'PUT',$header,0);
header('Location: index.php');
}
function update_event($details){
global $client, $baseApiUrl, $baseSiteSlug;
$params = array(
'event'=> array(
'name'=>$details['name'],
'status'=>$details['status'],
'start_time'=>$details['start_time'],
'end_time'=>$details['end_time']
)
);
$header = array(
'Authorization' => $_SESSION['token'],
'Content-Type' => 'application/json',
'Accept' => 'application/json'
);
$response = $client->fetch($baseApiUrl . '/api/v1/sites/'.$baseSiteSlug.'/pages/events/'.$details['id'],json_encode($params),'PUT',$header,0);
header('Location: index.php');
}
function delete_person($id){
global $client, $baseApiUrl;
$response = $client->fetch($baseApiUrl . '/api/v1/people/'.$id,array(),'DELETE');
header('Location: index.php');
}
if(isset($_GET['create']) && $_GET['create'] == 'create'){
create_person($_GET);
}elseif(isset($_GET['update']) && $_GET['update'] == 'update'){
update_person($_GET);
}elseif(isset($_GET['delete'])){
delete_person($_GET['delete']);
}elseif (isset($_GET['updateEvent'])) {
if(isset($_GET['id'])){
update_event($_GET);
}else{
create_event($_GET);
}
}
?>