Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
temp/*
config/config.php
edit/apn-2022.crt
edit/apn-2022.key
File renamed without changes.
39 changes: 32 additions & 7 deletions edit/notifications.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

session_start();
include("../global.php");
secure();
Expand Down Expand Up @@ -78,12 +77,16 @@

//populate the form with the event notifications
while($get_notification_res = $get_notification_stmt->fetch(PDO::FETCH_ASSOC)) {

echo '<div class="card">';
echo '<div class="btn" onclick="deleteNotification('.attrstr($get_notification_res["sequential_ID"]).')">X</div>';
echo '<div class="input">Subject: <input type="text" name="title['.attrstr($get_notification_res["sequential_ID"]).']" maxlength="100" value="'.attrstr($get_notification_res["title"]) .'"></div>';
echo '<div class="input">Message: <textarea name="body['. attrstr($get_notification_res["sequential_ID"]) .']">'.htmlstr($get_notification_res["body"]).'</textarea></div>';
echo '<div class="input">Subject: <input type="text" id="title['.attrstr($get_notification_res["sequential_ID"]).']" name="title['.attrstr($get_notification_res["sequential_ID"]).']" maxlength="100" value="'.attrstr($get_notification_res["title"]) .'"></div>';
echo '<div class="input">Message: <textarea id="body['. attrstr($get_notification_res["sequential_ID"]) .']" name="body['. attrstr($get_notification_res["sequential_ID"]) .']">'.htmlstr($get_notification_res["body"]).'</textarea></div>';
echo '<div class="input">Date: <input type="date" name="date['. attrstr($get_notification_res["sequential_ID"]).']" value="'. attrstr(date("Y-m-d",strtotime($get_notification_res["date"]))).'"></div>';
echo '<div class="input">Time: <input type="time" name="time['. attrstr($get_notification_res["sequential_ID"]).']" value="'. attrstr(date("H:i",strtotime($get_notification_res["date"]))).'"></div>';
$title = attrstr($get_notification_res["title"]);
$body = htmlstr($get_notification_res["body"]);
echo '<div class="btn" onclick=\'SendNotification('.attrstr($get_notification_res["sequential_ID"]).', '.$event_id.')\'>Send IOS Notification</div>';
echo '</div>';
}
?>
Expand All @@ -95,22 +98,44 @@
</form>
</section>
</body>
<!--<p hidden> <?php //echo $response ?> </p>-->


<script>
function addNotification() {
document.forms['notificationForm']['action'].value = "addNotification";
$("#notificationForm").submit();
}

function deleteNotification(sequential_id) {
document.forms['notificationForm']['action'].value = "deleteNotification";
document.forms['notificationForm']['sequence'].value = sequential_id;
document.forms['notificationForm']['action'].value = "deleteNotification";
document.forms['notificationForm']['sequence'].value = sequential_id;
$("#notificationForm").submit();
}
function save(){
document.forms['notificationForm']['action'].value = "save";
document.forms['notificationForm']['action'].value = "save";
$("#notificationForm").submit();
}

function SendNotification(sequential_ID, event_id){

$.ajax({

url : './post.php',
type : 'POST',
data:{
title: document.getElementById(`title[${sequential_ID}]`).value,
body: document.getElementById(`body[${sequential_ID}]`).value,
id: event_id,
},
success : function (result) {
console.log (result); // Here, you need to use response by PHP file.
},
error : function () {
console.log ('error');
}

});
}
</script>
</html>

52 changes: 52 additions & 0 deletions edit/post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php


include("../global.php");




$get_tokens = $db->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);

}

?>
40 changes: 27 additions & 13 deletions eventApp-data.sql
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions store-token.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

include("global.php");

$event_id = $_POST["eventID"];
$token = $_POST["deviceToken"];

echo "THIS IS THE EVENT ECHOED:".$event_id;
echo "\nTHIS IS THE TOKEN ECHOED:". $token;

// $sql = 'insert into device_tokens (event_ID, token) values ('.$event_id.', '.$token.')';
// echo $sql;
$stmt = $db->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";


?>