From efe4c3d42f7f64d0ffd59644a7c15641a70f7aba Mon Sep 17 00:00:00 2001 From: jhuesser Date: Thu, 7 Jun 2018 15:36:57 +0200 Subject: [PATCH] mange subscriptions --- classes/incident.php | 1 - subscriptions.php | 53 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/classes/incident.php b/classes/incident.php index b1d4f62..be08731 100644 --- a/classes/incident.php +++ b/classes/incident.php @@ -170,7 +170,6 @@ class Incident implements JsonSerializable $tg_message = urlencode('Hi ' . $firstname . chr(10) . 'There is a status update on a service that you have subscribed. View online'); $response = json_decode(file_get_contents("https://api.telegram.org/bot" . TG_BOT_API_TOKEN . "/sendMessage?chat_id=" . $telegramID . "&parse_mode=HTML&text=" . $tg_message)); - print_r($response); } } diff --git a/subscriptions.php b/subscriptions.php index cd319d7..ef6eb58 100644 --- a/subscriptions.php +++ b/subscriptions.php @@ -7,22 +7,67 @@ $tg_user = getTelegramUserData(); if($tg_user !== false){ + if(isset($_GET['add'])){ + $service = $_GET['add']; + $query = $mysqli->query("SELECT * FROM subscribers WHERE telegramID=" . $tg_user['id']); + while($subscriber = $query->fetch_assoc()){ + $subscriberID = $subscriber['subscriberID']; + } + $stmt = $mysqli->prepare("INSERT INTO services_subscriber VALUES (NULL,?, ?)"); + $stmt->bind_param("ii", $subscriberID, $service); + $stmt->execute(); + $query = $stmt->get_result(); + header("Location: index.php?do=subscriptions"); + } + + if(isset($_GET['remove'])){ + $service = $_GET['remove']; + $query = $mysqli->query("SELECT * FROM subscribers WHERE telegramID=" . $tg_user['id']); + while($subscriber = $query->fetch_assoc()){ + $subscriberID = $subscriber['subscriberID']; + } + $stmt = $mysqli->prepare("DELETE FROM services_subscriber WHERE subscriberIDFK = ? AND serviceIDFK = ?"); + $stmt->bind_param("ii", $subscriberID, $service); + $stmt->execute(); + $query = $stmt->get_result(); + header("Location: index.php?do=subscriptions"); + } + $query = $mysqli->query("SELECT services.id, services.name, subscribers.subscriberID, subscribers.telegramID FROM services LEFT JOIN services_subscriber ON services_subscriber.serviceIDFK = services.id LEFT JOIN subscribers ON services_subscriber.subscriberIDFK = subscribers.subscriberID WHERE subscribers.telegramID =" . $tg_user['id']); -//$query = $mysqli->query("SELECT id, name FROM services"); if ($query->num_rows){ $timestamp = time(); echo '

' . _("Your subscriptions") . "

"; - echo '"; + echo ""; } + +echo '

' . _("Add new subscription") . '

'; + +$query = $mysqli->query("SELECT services.id, services.name from services"); +if ($query->num_rows){ + echo '
'; + + while($result = $query->fetch_assoc()){ + if(empty($subs)){ + echo '' . $result['name'] . ''; + + } elseif(!in_array($result['name'], $subs)){ + echo '' . $result['name'] . ''; + } + } + echo '
'; +} + } else{ header('Location: index.php'); }