diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4bd0210 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +temp/* +config/config.php +edit/apn-2022.crt +edit/apn-2022.key diff --git a/config/config.php b/config/config.php.dist similarity index 100% rename from config/config.php rename to config/config.php.dist diff --git a/edit/notifications.php b/edit/notifications.php index 872cf9a..0758d9d 100755 --- a/edit/notifications.php +++ b/edit/notifications.php @@ -1,5 +1,4 @@ fetch(PDO::FETCH_ASSOC)) { + echo '
'; echo '
X
'; - echo '
Subject:
'; - echo '
Message:
'; + echo '
Subject:
'; + echo '
Message:
'; echo '
Date:
'; echo '
Time:
'; + $title = attrstr($get_notification_res["title"]); + $body = htmlstr($get_notification_res["body"]); + echo '
Send IOS Notification
'; echo '
'; } ?> @@ -95,22 +98,44 @@ + + diff --git a/edit/post.php b/edit/post.php new file mode 100644 index 0000000..12eb4d2 --- /dev/null +++ b/edit/post.php @@ -0,0 +1,52 @@ +prepare("SELECT token FROM device_tokens d JOIN event e on d.event_ID = e.ID where e.internal_ID=:id"); + $get_tokens->bindValue(":id",$_POST['id']); + $get_tokens->execute(); + + + + + + + + while($get_notification_res = $get_tokens->fetch(PDO::FETCH_ASSOC)){ + + + $token = $get_notification_res['token']; + + $var = json_encode($_POST); + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.push.apple.com/3/device/'. $token); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n\"aps\": {\n \"alert\": {\n \"title\": \" " . $_POST["title"] . " \",\n \"body\": \" " . $_POST["body"] . " \"\n }\n},\n\"aditional-info\": \"Test\",\n\"attachment-url\": \"https://google.com\"\n}"); + curl_setopt($ch, CURLOPT_SSLCERT, "apn-2022.crt"); + curl_setopt($ch, CURLOPT_SSLKEY, "apn-2022.key"); + curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2); + curl_setopt($ch, CURLOPT_VERBOSE, true); + + $headers = array(); + $headers[] = 'Apns-Topic: org.LightSys.iOSEventAppLS88'; + $headers[] = 'Content-Type: application/x-www-form-urlencoded'; + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + + + + $result = curl_exec($ch); + if (curl_errno($ch)) { + echo 'Error:' . curl_error($ch); + } + curl_close($ch); + + } + +?> \ No newline at end of file diff --git a/eventApp-data.sql b/eventApp-data.sql index b26fb55..a46767e 100755 --- a/eventApp-data.sql +++ b/eventApp-data.sql @@ -1,19 +1,20 @@ -- Recreates database with event data SET FOREIGN_KEY_CHECKS = 0; -drop table event; -drop table contact_page_sections; -drop table contacts; -drop table schedule_items; -drop table info_page; -drop table info_page_sections; -drop table housing; -drop table prayer_partners; -drop table attendees; -drop table notifications; -drop table themes; -drop table users; -drop table event_users; +drop table if exists event; +drop table if exists contact_page_sections; +drop table if exists contacts; +drop table if exists schedule_items; +drop table if exists info_page; +drop table if exists info_page_sections; +drop table if exists housing; +drop table if exists prayer_partners; +drop table if exists attendees; +drop table if exists notifications; +drop table if exists device_tokens; +drop table if exists themes; +drop table if exists users; +drop table if exists event_users; SET FOREIGN_KEY_CHECKS = 1; -- Contains general information about events and data needed @@ -167,6 +168,19 @@ create table notifications ( on delete cascade ) ENGINE = INNODB; +--Stores the device tokens for the event +create table device_tokens ( + ID int AUTO_INCREMENT, + event_ID varchar(36) , + token varchar(512), + + primary key (ID), + foreign key (event_ID) references event(ID) + on delete cascade + +) ENGINE = INNODB; + + -- Defines a link on the nav bar for a user-defined page create table info_page ( ID int AUTO_INCREMENT, diff --git a/store-token.php b/store-token.php new file mode 100644 index 0000000..a3d58ae --- /dev/null +++ b/store-token.php @@ -0,0 +1,22 @@ +prepare('INSERT into device_tokens(event_ID, token) values(:event_id, :token)'); +$stmt->bindValue(':event_id', $event_id); +$stmt->bindValue(':token', $token); +//echo "THIS IS TEH QUERY: " . $stmt; +$stmt->execute(); + +// echo "\nTHIS MEANS THAT WE WIN"; + + +?>