forked from rpiambulance/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack-link.php
156 lines (153 loc) · 6.63 KB
/
slack-link.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
<?php
require_once '.functions.php';
$conn = openDatabaseConnection();
if (is_null($conn)) {
echo "Database connection failed to initialize!";
return;
}
include '.db_config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (!isset($_POST['token']) || $_POST['token'] != $slacktoken) {
die("Nope.");
}
if (isset($_POST["slack_id"]) && isset($_POST['member_id'])) {
$statement = $conn->prepare("SELECT * FROM members WHERE id = :memID");
$statement->bindParam(":memID", $_POST['member_id']);
$statement->execute();
$user = $statement->fetch();
// If the given member ID isn't in our database we return a message stating that
if (!$user) {
echo "Invalid user id! Please enter another one";
return;
}
$statement = $conn->prepare("UPDATE members SET slackID = :slack WHERE id = :memID");
$statement->execute(['slack' => $_POST["slack_id"], 'memID' => $_POST['member_id']]);
echo "Successfully linked " . $_POST['slack_id'] . " to " . $user['first_name'] . " " . $user['last_name'] . " (" . $_POST['member_id'] . ")";
} else {
echo "Invalid request";
return;
}
} else {
if (!isset($_GET['token']) || $_GET['token'] != $slacktoken) {
die("Nope.");
}
if (isset($_GET['slack_id']) && isset($_GET['type'])) {
if ($_GET['type'] != "info") {
return;
}
$statement = $conn->prepare("SELECT * FROM members WHERE slackID = :slack");
$statement->bindParam(":slack", $_GET['slack_id']);
$statement->execute();
$accounts = $statement->fetchAll();
if (!$accounts) {
echo "No website accounts are associated with this ID!";
return;
} else {
foreach ($accounts as $account) {
$message = "";
// I need to move this to a separate function
if ($account['captain'] == 1) {
$message .= "*Captain*\n";
} elseif ($account['firstlt'] == 1) {
$message .= "*First Lieutenant*\n";
} elseif ($account['secondlt'] == 1) {
$message .= "*Second Lieutenant*\n";
} elseif ($account['pres'] == 1) {
$message .= "*President*\n";
} elseif ($account['vicepres'] == 1) {
$message .= "*Vice President*\n";
} elseif ($account['schedco'] == 1) {
$message .= "*Scheduling Coordinator*\n";
} elseif ($account['traincommchair'] == 1) {
$message .= "*Training Committee Chair*\n";
} elseif ($account['radioco'] == 1) {
$message .= "*Radio Coordnator*\n";
} elseif ($account['cprco'] == 1) {
$message .= "*CPR Coordinator*\n";
} elseif ($account['qaco'] == 1) {
$message .= "*QA/QI Coordinator*\n";
}
$message .= "Name: " . $account['first_name'] . " " . $account['last_name'];
// They have a radio number
if ($account['radionum'] != 0) {
$message .= " (" . $account['radionum'] . ")";
}
$message .= "\n";
if (isset($_GET['admin']) && $_GET['admin'] == 1) {
$phone_num = $account['cell_phone'];
// Removes everything except the number from the phone numbers
$phone_num = preg_replace('/[^0-9.]+/', '', $phone_num);
$phone_num = substr_replace($phone_num, '-', 3, 0);
$phone_num = substr_replace($phone_num, '-', 7, 0);
$message .= "Phone: " . $phone_num;
$message .= "\n";
}
$message .= "Email: " . $account['email'];
$message .= "\n";
$message .= "Positions:";
$attendant = $account['attendant'] == 1;
$message_length = $message.length;
// This also needs to go into another functions
if ($account['dutysup'] == 1) {
$message .= " Duty Supervisor";
echo $message;
return;
} else {
if ($account['ees'] == 1) {
$message .= " EES,";
}
if ($account['cctrainer'] == 1) {
$message .= " CC-T,";
} elseif ($account['crewchief'] == 1) {
$message .= " CC,";
} elseif ($account['backupcc'] == 1) {
$message .= " P-CC,";
} elseif ($account['clearedcc'] == 1) {
$message .= " A-CC";
}
if ($account['firstresponsecc'] == 1) {
$message .= " FR-CC,";
}
if ($account['drivertrainer'] == 1) {
$message .= " D-T,";
} elseif ($account['driver'] == 1) {
$message .= " D,";
} elseif ($account['backupdriver'] == 1) {
$message .= " P-D";
} elseif ($account['cleareddriver'] == 1) {
$message .= " A-D";
}
}
if ($attendant && $message.length == $message_length) {
$message .= " A";
} elseif ($message.length == $message_length) {
$message .= " O";
} else {
$message = rtrim($message, ',');
}
$message .= "\n";
echo $message;
return;
}
return;
}
} elseif (isset($_GET['slack_id']) && !isset($_GET['type'])) {
$statement = $conn->prepare("SELECT id, first_name, last_name FROM members WHERE slackID = :slack");
$statement->bindParam(":slack", $_GET['slack_id']);
$statement->execute();
$accounts = $statement->fetchAll();
if (!$accounts) {
echo "No website accounts are associated with this ID!";
return;
} else {
$message = $_GET['slack_id'] . " is linked with";
foreach ($accounts as $account) {
$message .= ", " . $account['first_name'] . " " . $account['last_name'] . " (" . $account['id'] . ")";
}
echo $message;
return;
}
} else {
die("You've provided an invalid request.");
}
}