feat!: allow registration of multiple users (#340)
feat: administration area feat: add reset password functionality
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('session_expired', $i18n)
|
||||
]));
|
||||
}
|
||||
|
||||
// Check that user is an admin
|
||||
if ($userId !== 1) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('error', $i18n)
|
||||
]));
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$postData = file_get_contents("php://input");
|
||||
$data = json_decode($postData, true);
|
||||
|
||||
$userId = $data['userId'];
|
||||
|
||||
if ($userId == 1) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('error', $i18n)
|
||||
]));
|
||||
} else {
|
||||
// Delete user
|
||||
$stmt = $db->prepare('DELETE FROM user WHERE id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete subscriptions
|
||||
$stmt = $db->prepare('DELETE FROM subscriptions WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete settings
|
||||
$stmt = $db->prepare('DELETE FROM settings WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete fixer
|
||||
$stmt = $db->prepare('DELETE FROM fixer WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete custom colors
|
||||
$stmt = $db->prepare('DELETE FROM custom_colors WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete currencies
|
||||
$stmt = $db->prepare('DELETE FROM currencies WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete categories
|
||||
$stmt = $db->prepare('DELETE FROM categories WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete household
|
||||
$stmt = $db->prepare('DELETE FROM household WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete payment methods
|
||||
$stmt = $db->prepare('DELETE FROM payment_methods WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete email notifications
|
||||
$stmt = $db->prepare('DELETE FROM email_notifications WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete telegram notifications
|
||||
$stmt = $db->prepare('DELETE FROM telegram_notifications WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete webhook notifications
|
||||
$stmt = $db->prepare('DELETE FROM webhook_notifications WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete gotify notifications
|
||||
$stmt = $db->prepare('DELETE FROM gotify_notifications WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete pushover notifications
|
||||
$stmt = $db->prepare('DELETE FROM pushover_notifications WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Dele notification settings
|
||||
$stmt = $db->prepare('DELETE FROM notification_settings WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete last exchange update
|
||||
$stmt = $db->prepare('DELETE FROM last_exchange_update WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Delete email verification
|
||||
$stmt = $db->prepare('DELETE FROM email_verification WHERE user_id = :id');
|
||||
$stmt->bindValue(':id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
die(json_encode([
|
||||
"success" => true,
|
||||
"message" => translate('success', $i18n)
|
||||
]));
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('error', $i18n)
|
||||
]));
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('session_expired', $i18n)
|
||||
]));
|
||||
}
|
||||
|
||||
// Check that user is an admin
|
||||
if ($userId !== 1) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('error', $i18n)
|
||||
]));
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$postData = file_get_contents("php://input");
|
||||
$data = json_decode($postData, true);
|
||||
|
||||
$openRegistrations = $data['open_registrations'];
|
||||
$maxUsers = $data['max_users'];
|
||||
$requireEmailVerification = $data['require_email_validation'];
|
||||
$serverUrl = $data['server_url'];
|
||||
|
||||
if ($requireEmailVerification == 1 && $serverUrl == "") {
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('fill_all_fields', $i18n)
|
||||
]);
|
||||
die();
|
||||
}
|
||||
|
||||
$sql = "UPDATE admin SET registrations_open = :openRegistrations, max_users = :maxUsers, require_email_verification = :requireEmailVerification, server_url = :serverUrl";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':openRegistrations', $openRegistrations, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':maxUsers', $maxUsers, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':requireEmailVerification', $requireEmailVerification, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':serverUrl', $serverUrl, SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result) {
|
||||
echo json_encode([
|
||||
"success" => true,
|
||||
"message" => translate('success', $i18n)
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('error', $i18n)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('session_expired', $i18n)
|
||||
]));
|
||||
}
|
||||
|
||||
// Check that user is an admin
|
||||
if ($userId !== 1) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('error', $i18n)
|
||||
]));
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$postData = file_get_contents("php://input");
|
||||
$data = json_decode($postData, true);
|
||||
|
||||
$smtpAddress = $data['smtpaddress'];
|
||||
$smtpPort = $data['smtpport'];
|
||||
$encryption = $data['encryption'];
|
||||
$smtpUsername = $data['smtpusername'];
|
||||
$smtpPassword = $data['smtppassword'];
|
||||
$fromEmail = $data['fromemail'];
|
||||
|
||||
if (empty($smtpAddress) || empty($smtpPort)) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('fill_all_fields', $i18n)
|
||||
]));
|
||||
}
|
||||
|
||||
// Save settings
|
||||
$stmt = $db->prepare('UPDATE admin SET smtp_address = :smtp_address, smtp_port = :smtp_port, encryption = :encryption, smtp_username = :smtp_username, smtp_password = :smtp_password, from_email = :from_email');
|
||||
$stmt->bindValue(':smtp_address', $smtpAddress, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':smtp_port', $smtpPort, SQLITE3_TEXT);
|
||||
$encryption = empty($data['encryption']) ? 'tls' : $data['encryption'];
|
||||
$stmt->bindValue(':encryption', $encryption, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':smtp_username', $smtpUsername, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':smtp_password', $smtpPassword, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':from_email', $fromEmail, SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result) {
|
||||
die(json_encode([
|
||||
"success" => true,
|
||||
"message" => translate('success', $i18n)
|
||||
]));
|
||||
} else {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
"message" => translate('error', $i18n)
|
||||
]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -2,11 +2,10 @@
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
require_once '../../includes/inputvalidation.php';
|
||||
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if (isset($_GET['action']) && $_GET['action'] == "add") {
|
||||
$stmt = $db->prepare('SELECT MAX("order") as maxOrder FROM categories');
|
||||
$stmt = $db->prepare('SELECT MAX("order") as maxOrder FROM categories WHERE user_id = :userId');
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$maxOrder = $row['maxOrder'];
|
||||
@@ -18,10 +17,11 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
$order = $maxOrder + 1;
|
||||
|
||||
$categoryName = "Category";
|
||||
$sqlInsert = 'INSERT INTO categories ("name", "order") VALUES (:name, :order)';
|
||||
$sqlInsert = 'INSERT INTO categories ("name", "order", "user_id") VALUES (:name, :order, :userId)';
|
||||
$stmtInsert = $db->prepare($sqlInsert);
|
||||
$stmtInsert->bindParam(':name', $categoryName, SQLITE3_TEXT);
|
||||
$stmtInsert->bindParam(':order', $order, SQLITE3_INTEGER);
|
||||
$stmtInsert->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$resultInsert = $stmtInsert->execute();
|
||||
|
||||
if ($resultInsert) {
|
||||
@@ -42,10 +42,11 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if (isset($_GET['categoryId']) && $_GET['categoryId'] != "" && isset($_GET['name']) && $_GET['name'] != "") {
|
||||
$categoryId = $_GET['categoryId'];
|
||||
$name = validate($_GET['name']);
|
||||
$sql = "UPDATE categories SET name = :name WHERE id = :categoryId";
|
||||
$sql = "UPDATE categories SET name = :name WHERE id = :categoryId AND user_id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':name', $name, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':categoryId', $categoryId, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result) {
|
||||
@@ -71,9 +72,10 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
} else if (isset($_GET['action']) && $_GET['action'] == "delete") {
|
||||
if (isset($_GET['categoryId']) && $_GET['categoryId'] != "" && $_GET['categoryId'] != 1) {
|
||||
$categoryId = $_GET['categoryId'];
|
||||
$checkCategory = "SELECT COUNT(*) FROM subscriptions WHERE category_id = :categoryId";
|
||||
$checkCategory = "SELECT COUNT(*) FROM subscriptions WHERE category_id = :categoryId AND user_id = :userId";
|
||||
$checkStmt = $db->prepare($checkCategory);
|
||||
$checkStmt->bindParam(':categoryId', $categoryId, SQLITE3_INTEGER);
|
||||
$checkStmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$checkResult = $checkStmt->execute();
|
||||
$row = $checkResult->fetchArray();
|
||||
$count = $row[0];
|
||||
@@ -85,9 +87,10 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
];
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
$sql = "DELETE FROM categories WHERE id = :categoryId";
|
||||
$sql = "DELETE FROM categories WHERE id = :categoryId AND user_id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':categoryId', $categoryId, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
if ($result) {
|
||||
$response = [
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
$categories = $_POST['categoryIds'];
|
||||
$order = 2;
|
||||
|
||||
foreach ($categories as $categoryId) {
|
||||
$sql = "UPDATE categories SET `order` = :order WHERE id = :categoryId";
|
||||
$sql = "UPDATE categories SET `order` = :order WHERE id = :categoryId AND user_id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':order', $order, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':categoryId', $categoryId, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$order++;
|
||||
}
|
||||
|
||||
@@ -5,465 +5,501 @@
|
||||
|
||||
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';
|
||||
|
||||
$days = 1;
|
||||
$emailNotificationsEnabled = false;
|
||||
$gotifyNotificationsEnabled = false;
|
||||
$telegramNotificationsEnabled = false;
|
||||
$webhookNotificationsEnabled = false;
|
||||
$pushoverNotificationsEnabled = false;
|
||||
$discordNotificationsEnabled = false;
|
||||
require __DIR__ . '/../../libs/PHPMailer/PHPMailer.php';
|
||||
require __DIR__ . '/../../libs/PHPMailer/SMTP.php';
|
||||
require __DIR__ . '/../../libs/PHPMailer/Exception.php';
|
||||
|
||||
// Get notification settings (how many days before the subscription ends should the notification be sent)
|
||||
$query = "SELECT days FROM notification_settings";
|
||||
$result = $db->query($query);
|
||||
// Get all user ids
|
||||
$query = "SELECT id, username FROM user";
|
||||
$stmt = $db->prepare($query);
|
||||
$usersToNotify = $stmt->execute();
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$days = $row['days'];
|
||||
}
|
||||
while ($userToNotify = $usersToNotify->fetchArray(SQLITE3_ASSOC)) {
|
||||
$userId = $userToNotify['id'];
|
||||
echo "For user: " . $userToNotify['username'] . "<br />";
|
||||
|
||||
$days = 1;
|
||||
$emailNotificationsEnabled = false;
|
||||
$gotifyNotificationsEnabled = false;
|
||||
$telegramNotificationsEnabled = false;
|
||||
$webhookNotificationsEnabled = false;
|
||||
$pushoverNotificationsEnabled = false;
|
||||
$discordNotificationsEnabled = false;
|
||||
|
||||
// Check if email notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM email_notifications";
|
||||
$result = $db->query($query);
|
||||
// Get notification settings (how many days before the subscription ends should the notification be sent)
|
||||
$query = "SELECT days FROM notification_settings WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$emailNotificationsEnabled = $row['enabled'];
|
||||
$email['smtpAddress'] = $row["smtp_address"];
|
||||
$email['smtpPort'] = $row["smtp_port"];
|
||||
$email['encryption'] = $row["encryption"];
|
||||
$email['smtpUsername'] = $row["smtp_username"];
|
||||
$email['smtpPassword'] = $row["smtp_password"];
|
||||
$email['fromEmail'] = $row["from_email"] ? $row["from_email"] : "wallos@wallosapp.com";
|
||||
}
|
||||
|
||||
// Check if Discord notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM discord_notifications";
|
||||
$result = $db->query($query);
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$discordNotificationsEnabled = $row['enabled'];
|
||||
$discord['webhook_url'] = $row["webhook_url"];
|
||||
$discord['bot_username'] = $row["bot_username"];
|
||||
$discord['bot_avatar_url'] = $row["bot_avatar_url"];
|
||||
}
|
||||
|
||||
// Check if Gotify notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM gotify_notifications";
|
||||
$result = $db->query($query);
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$gotifyNotificationsEnabled = $row['enabled'];
|
||||
$gotify['serverUrl'] = $row["url"];
|
||||
$gotify['appToken'] = $row["token"];
|
||||
}
|
||||
|
||||
// Check if Telegram notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM telegram_notifications";
|
||||
$result = $db->query($query);
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$telegramNotificationsEnabled = $row['enabled'];
|
||||
$telegram['botToken'] = $row["bot_token"];
|
||||
$telegram['chatId'] = $row["chat_id"];
|
||||
}
|
||||
|
||||
// Check if Pushover notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM pushover_notifications";
|
||||
$result = $db->query($query);
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$pushoverNotificationsEnabled = $row['enabled'];
|
||||
$pushover['user_key'] = $row["user_key"];
|
||||
$pushover['token'] = $row["token"];
|
||||
}
|
||||
|
||||
// Check if Webhook notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM webhook_notifications";
|
||||
$result = $db->query($query);
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$webhookNotificationsEnabled = $row['enabled'];
|
||||
$webhook['url'] = $row["url"];
|
||||
$webhook['request_method'] = $row["request_method"];
|
||||
$webhook['headers'] = $row["headers"];
|
||||
$webhook['payload'] = $row["payload"];
|
||||
$webhook['iterator'] = $row["iterator"];
|
||||
if ($webhook['iterator'] === "") {
|
||||
$webhook['iterator'] = "subscriptions";
|
||||
}
|
||||
}
|
||||
|
||||
$notificationsEnabled = $emailNotificationsEnabled || $gotifyNotificationsEnabled || $telegramNotificationsEnabled || $webhookNotificationsEnabled || $pushoverNotificationsEnabled || $discordNotificationsEnabled;
|
||||
|
||||
// If no notifications are enabled, no need to run
|
||||
if (!$notificationsEnabled) {
|
||||
echo "Notifications are disabled. No need to run.";
|
||||
exit();
|
||||
} else {
|
||||
// Get all currencies
|
||||
$currencies = array();
|
||||
$query = "SELECT * FROM currencies";
|
||||
$result = $db->query($query);
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$currencies[$row['id']] = $row;
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$days = $row['days'];
|
||||
}
|
||||
|
||||
// Get all household members
|
||||
$stmt = $db->prepare('SELECT * FROM household');
|
||||
$resultHousehold = $stmt->execute();
|
||||
|
||||
$household = [];
|
||||
while ($rowHousehold = $resultHousehold->fetchArray(SQLITE3_ASSOC)) {
|
||||
$household[$rowHousehold['id']] = $rowHousehold;
|
||||
// Check if email notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM email_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$emailNotificationsEnabled = $row['enabled'];
|
||||
$email['smtpAddress'] = $row["smtp_address"];
|
||||
$email['smtpPort'] = $row["smtp_port"];
|
||||
$email['encryption'] = $row["encryption"];
|
||||
$email['smtpUsername'] = $row["smtp_username"];
|
||||
$email['smtpPassword'] = $row["smtp_password"];
|
||||
$email['fromEmail'] = $row["from_email"] ? $row["from_email"] : "wallos@wallosapp.com";
|
||||
}
|
||||
|
||||
// Get all categories
|
||||
$stmt = $db->prepare('SELECT * FROM categories');
|
||||
$resultCategories = $stmt->execute();
|
||||
// Check if Discord notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM discord_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
$categories = [];
|
||||
while ($rowCategory = $resultCategories->fetchArray(SQLITE3_ASSOC)) {
|
||||
$categories[$rowCategory['id']] = $rowCategory;
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$discordNotificationsEnabled = $row['enabled'];
|
||||
$discord['webhook_url'] = $row["webhook_url"];
|
||||
$discord['bot_username'] = $row["bot_username"];
|
||||
$discord['bot_avatar_url'] = $row["bot_avatar_url"];
|
||||
}
|
||||
|
||||
$stmt = $db->prepare('SELECT * FROM subscriptions WHERE notify = :notify AND inactive = :inactive ORDER BY payer_user_id ASC');
|
||||
$stmt->bindValue(':notify', 1, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':inactive', 0, SQLITE3_INTEGER);
|
||||
$resultSubscriptions = $stmt->execute();
|
||||
// Check if Gotify notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM gotify_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
$notify = []; $i = 0;
|
||||
$currentDate = new DateTime('now');
|
||||
while ($rowSubscription = $resultSubscriptions->fetchArray(SQLITE3_ASSOC)) {
|
||||
if ($rowSubscription['notify_days_before'] !== 0) {
|
||||
$daysToCompare = $rowSubscription['notify_days_before'];
|
||||
} else {
|
||||
$daysToCompare = $days;
|
||||
}
|
||||
$nextPaymentDate = new DateTime($rowSubscription['next_payment']);
|
||||
$difference = $currentDate->diff($nextPaymentDate)->days + 1;
|
||||
if ($difference === $daysToCompare) {
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['name'] = $rowSubscription['name'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['price'] = $rowSubscription['price'] . $currencies[$rowSubscription['currency_id']]['symbol'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['currency'] = $currencies[$rowSubscription['currency_id']]['name'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['category'] = $categories[$rowSubscription['category_id']]['name'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['payer'] = $household[$rowSubscription['payer_user_id']]['name'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['date'] = $rowSubscription['next_payment'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['days'] = $daysToCompare;
|
||||
$i++;
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$gotifyNotificationsEnabled = $row['enabled'];
|
||||
$gotify['serverUrl'] = $row["url"];
|
||||
$gotify['appToken'] = $row["token"];
|
||||
}
|
||||
|
||||
// Check if Telegram notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM telegram_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$telegramNotificationsEnabled = $row['enabled'];
|
||||
$telegram['botToken'] = $row["bot_token"];
|
||||
$telegram['chatId'] = $row["chat_id"];
|
||||
}
|
||||
|
||||
// Check if Pushover notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM pushover_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$pushoverNotificationsEnabled = $row['enabled'];
|
||||
$pushover['user_key'] = $row["user_key"];
|
||||
$pushover['token'] = $row["token"];
|
||||
}
|
||||
|
||||
// Check if Webhook notifications are enabled and get the settings
|
||||
$query = "SELECT * FROM webhook_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$webhookNotificationsEnabled = $row['enabled'];
|
||||
$webhook['url'] = $row["url"];
|
||||
$webhook['request_method'] = $row["request_method"];
|
||||
$webhook['headers'] = $row["headers"];
|
||||
$webhook['payload'] = $row["payload"];
|
||||
$webhook['iterator'] = $row["iterator"];
|
||||
if ($webhook['iterator'] === "") {
|
||||
$webhook['iterator'] = "subscriptions";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($notify)) {
|
||||
$notificationsEnabled = $emailNotificationsEnabled || $gotifyNotificationsEnabled || $telegramNotificationsEnabled || $webhookNotificationsEnabled || $pushoverNotificationsEnabled || $discordNotificationsEnabled;
|
||||
|
||||
// Email notifications if enabled
|
||||
if ($emailNotificationsEnabled) {
|
||||
require __DIR__ . '/../../libs/PHPMailer/PHPMailer.php';
|
||||
require __DIR__ . '/../../libs/PHPMailer/SMTP.php';
|
||||
require __DIR__ . '/../../libs/PHPMailer/Exception.php';
|
||||
// If no notifications are enabled, no need to run
|
||||
if (!$notificationsEnabled) {
|
||||
echo "Notifications are disabled. No need to run.<br />";
|
||||
continue;
|
||||
} else {
|
||||
// Get all currencies
|
||||
$currencies = array();
|
||||
$query = "SELECT * FROM currencies WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
$stmt = $db->prepare('SELECT * FROM user WHERE id = :id');
|
||||
$stmt->bindValue(':id', 1, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$defaultUser = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$defaultEmail = $defaultUser['email'];
|
||||
$defaultName = $defaultUser['username'];
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$currencies[$row['id']] = $row;
|
||||
}
|
||||
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
$message = "The following subscriptions are up for renewal:\n";
|
||||
// Get all household members
|
||||
$query = "SELECT * FROM household WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$resultHousehold = $stmt->execute();
|
||||
|
||||
foreach ($perUser as $subscription) {
|
||||
$dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
|
||||
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
|
||||
}
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
$mail->CharSet="UTF-8";
|
||||
$mail->isSMTP();
|
||||
|
||||
$mail->Host = $email['smtpAddress'];
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $email['smtpUsername'];
|
||||
$mail->Password = $email['smtpPassword'];
|
||||
$mail->SMTPSecure = $email['encryption'];
|
||||
$mail->Port = $email['smtpPort'];
|
||||
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$household = [];
|
||||
while ($rowHousehold = $resultHousehold->fetchArray(SQLITE3_ASSOC)) {
|
||||
$household[$rowHousehold['id']] = $rowHousehold;
|
||||
}
|
||||
|
||||
$emailaddress = !empty($user['email']) ? $user['email'] : $defaultEmail;
|
||||
$name = !empty($user['name']) ? $user['name'] : $defaultName;
|
||||
|
||||
$mail->setFrom($email['fromEmail'], 'Wallos App');
|
||||
$mail->addAddress($emailaddress, $name);
|
||||
|
||||
$mail->Subject = 'Wallos Notification';
|
||||
$mail->Body = $message;
|
||||
|
||||
if ($mail->send()) {
|
||||
echo "Email Notifications sent<br />";
|
||||
} else {
|
||||
echo "Error sending notifications: " . $mail->ErrorInfo;
|
||||
}
|
||||
// Get all categories
|
||||
$query = "SELECT * FROM categories WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$resultCategories = $stmt->execute();
|
||||
|
||||
$categories = [];
|
||||
while ($rowCategory = $resultCategories->fetchArray(SQLITE3_ASSOC)) {
|
||||
$categories[$rowCategory['id']] = $rowCategory;
|
||||
}
|
||||
|
||||
$query = "SELECT * FROM subscriptions WHERE user_id = :user_id AND notify = :notify AND inactive = :inactive ORDER BY payer_user_id ASC";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':user_id', $userId, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':notify', 1, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':inactive', 0, SQLITE3_INTEGER);
|
||||
$resultSubscriptions = $stmt->execute();
|
||||
|
||||
$notify = []; $i = 0;
|
||||
$currentDate = new DateTime('now');
|
||||
while ($rowSubscription = $resultSubscriptions->fetchArray(SQLITE3_ASSOC)) {
|
||||
if ($rowSubscription['notify_days_before'] !== 0) {
|
||||
$daysToCompare = $rowSubscription['notify_days_before'];
|
||||
} else {
|
||||
$daysToCompare = $days;
|
||||
}
|
||||
$nextPaymentDate = new DateTime($rowSubscription['next_payment']);
|
||||
$difference = $currentDate->diff($nextPaymentDate)->days + 1;
|
||||
if ($difference === $daysToCompare) {
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['name'] = $rowSubscription['name'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['price'] = $rowSubscription['price'] . $currencies[$rowSubscription['currency_id']]['symbol'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['currency'] = $currencies[$rowSubscription['currency_id']]['name'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['category'] = $categories[$rowSubscription['category_id']]['name'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['payer'] = $household[$rowSubscription['payer_user_id']]['name'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['date'] = $rowSubscription['next_payment'];
|
||||
$notify[$rowSubscription['payer_user_id']][$i]['days'] = $daysToCompare;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Discord notifications if enabled
|
||||
if ($discordNotificationsEnabled) {
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
// Get name of user from household table
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
if (!empty($notify)) {
|
||||
|
||||
// Email notifications if enabled
|
||||
if ($emailNotificationsEnabled) {
|
||||
|
||||
$stmt = $db->prepare('SELECT * FROM user WHERE id = :user_id');
|
||||
$stmt->bindValue(':user_id', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$defaultUser = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$defaultEmail = $defaultUser['email'];
|
||||
$defaultName = $defaultUser['username'];
|
||||
|
||||
$title = translate('wallos_notification', $i18n);
|
||||
|
||||
if ($user['name']) {
|
||||
$message = $user['name'] . ", the following subscriptions are up for renewal:\n";
|
||||
} else {
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
$message = "The following subscriptions are up for renewal:\n";
|
||||
|
||||
foreach ($perUser as $subscription) {
|
||||
$dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
|
||||
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
|
||||
}
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
$mail->CharSet="UTF-8";
|
||||
$mail->isSMTP();
|
||||
|
||||
$mail->Host = $email['smtpAddress'];
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $email['smtpUsername'];
|
||||
$mail->Password = $email['smtpPassword'];
|
||||
$mail->SMTPSecure = $email['encryption'];
|
||||
$mail->Port = $email['smtpPort'];
|
||||
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$emailaddress = !empty($user['email']) ? $user['email'] : $defaultEmail;
|
||||
$name = !empty($user['name']) ? $user['name'] : $defaultName;
|
||||
|
||||
$mail->setFrom($email['fromEmail'], 'Wallos App');
|
||||
$mail->addAddress($emailaddress, $name);
|
||||
|
||||
$mail->Subject = 'Wallos Notification';
|
||||
$mail->Body = $message;
|
||||
|
||||
if ($mail->send()) {
|
||||
echo "Email Notifications sent<br />";
|
||||
} else {
|
||||
echo "Error sending notifications: " . $mail->ErrorInfo . "<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Discord notifications if enabled
|
||||
if ($discordNotificationsEnabled) {
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
// Get name of user from household table
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$title = translate('wallos_notification', $i18n);
|
||||
|
||||
if ($user['name']) {
|
||||
$message = $user['name'] . ", the following subscriptions are up for renewal:\n";
|
||||
} else {
|
||||
$message = "The following subscriptions are up for renewal:\n";
|
||||
}
|
||||
|
||||
foreach ($perUser as $subscription) {
|
||||
$dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
|
||||
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
|
||||
}
|
||||
|
||||
$postfields = [
|
||||
'content' => $message
|
||||
];
|
||||
|
||||
if (!empty($discord['bot_username'])) {
|
||||
$postfields['username'] = $discord['bot_username'];
|
||||
}
|
||||
|
||||
if (!empty($discord['bot_avatar_url'])) {
|
||||
$postfields['avatar_url'] = $discord['bot_avatar_url'];
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $discord['webhook_url']);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postfields));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json'
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($result === false) {
|
||||
echo "Error sending notifications: " . curl_error($ch) . "<br />";
|
||||
} else {
|
||||
echo "Discord Notifications sent<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gotify notifications if enabled
|
||||
if ($gotifyNotificationsEnabled) {
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
// Get name of user from household table
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($user['name']) {
|
||||
$message = $user['name'] . ", the following subscriptions are up for renewal:\n";
|
||||
} else {
|
||||
$message = "The following subscriptions are up for renewal:\n";
|
||||
}
|
||||
|
||||
foreach ($perUser as $subscription) {
|
||||
$dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
|
||||
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'message' => $message,
|
||||
'priority' => 5
|
||||
);
|
||||
|
||||
$data_string = json_encode($data);
|
||||
|
||||
$ch = curl_init($gotify['serverUrl'] . '/message?token=' . $gotify['appToken']);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($data_string))
|
||||
);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
if ($result === false) {
|
||||
echo "Error sending notifications: " . curl_error($ch) . "<br />";
|
||||
} else {
|
||||
echo "Gotify Notifications sent<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Telegram notifications if enabled
|
||||
if ($telegramNotificationsEnabled) {
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
// Get name of user from household table
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($user['name']) {
|
||||
$message = $user['name'] . ", the following subscriptions are up for renewal:\n";
|
||||
} else {
|
||||
$message = "The following subscriptions are up for renewal:\n";
|
||||
}
|
||||
|
||||
foreach ($perUser as $subscription) {
|
||||
$dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
|
||||
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'chat_id' => $telegram['chatId'],
|
||||
'text' => $message
|
||||
);
|
||||
|
||||
$data_string = json_encode($data);
|
||||
|
||||
$ch = curl_init('https://api.telegram.org/bot' . $telegram['botToken'] . '/sendMessage');
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($data_string))
|
||||
);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
if ($result === false) {
|
||||
echo "Error sending notifications: " . curl_error($ch) . "<br />";
|
||||
} else {
|
||||
echo "Telegram Notifications sent<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pushover notifications if enabled
|
||||
if ($pushoverNotificationsEnabled) {
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
// Get name of user from household table
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($user['name']) {
|
||||
$message = $user['name'] . ", the following subscriptions are up for renewal:\n";
|
||||
} else {
|
||||
$message = "The following subscriptions are up for renewal:\n";
|
||||
}
|
||||
|
||||
foreach ($perUser as $subscription) {
|
||||
$dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
|
||||
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "https://api.pushover.net/1/messages.json");
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
|
||||
'token' => $pushover['token'],
|
||||
'user' => $pushover['user_key'],
|
||||
'message' => $message,
|
||||
]));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
if ($result === false) {
|
||||
echo "Error sending notifications: " . curl_error($ch) . "<br />";
|
||||
} else {
|
||||
echo "Pushover Notifications sent<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Webhook notifications if enabled
|
||||
if ($webhookNotificationsEnabled) {
|
||||
// Get webhook payload and turn it into a json object
|
||||
|
||||
$payload = str_replace("{{days_until}}", $days, $webhook['payload']); // The default value for all subscriptions
|
||||
$payload_json = json_decode($payload, true);
|
||||
|
||||
$subscription_template = $payload_json["{{subscriptions}}"];
|
||||
$subscriptions = [];
|
||||
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
// Get name of user from household table
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($user['name']) {
|
||||
$payer = $user['name'];
|
||||
}
|
||||
|
||||
foreach ($perUser as $k => $subscription) {
|
||||
$temp_subscription = $subscription_template[0];
|
||||
|
||||
foreach ($temp_subscription as $key => $value) {
|
||||
if (is_string($value)) {
|
||||
$temp_subscription[$key] = str_replace("{{subscription_name}}", $subscription['name'], $value);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_price}}", $subscription['price'], $temp_subscription[$key]);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_currency}}", $subscription['currency'], $temp_subscription[$key]);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_category}}", $subscription['category'], $temp_subscription[$key]);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_payer}}", $subscription['payer'], $temp_subscription[$key]);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_date}}", $subscription['date'], $temp_subscription[$key]);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_days_until_payment}}", $subscription['days'], $temp_subscription[$key]); // The de facto value for this subscription
|
||||
}
|
||||
}
|
||||
$subscriptions[] = $temp_subscription;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($perUser as $subscription) {
|
||||
$dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
|
||||
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
|
||||
}
|
||||
|
||||
$postfields = [
|
||||
'content' => $message
|
||||
];
|
||||
|
||||
if (!empty($discord['bot_username'])) {
|
||||
$postfields['username'] = $discord['bot_username'];
|
||||
}
|
||||
|
||||
if (!empty($discord['bot_avatar_url'])) {
|
||||
$postfields['avatar_url'] = $discord['bot_avatar_url'];
|
||||
}
|
||||
$payload_json["{{subscriptions}}"] = $subscriptions;
|
||||
$payload_json[$webhook['iterator']] = $subscriptions;
|
||||
unset($payload_json["{{subscriptions}}"]);
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $discord['webhook_url']);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postfields));
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
'Content-Type: application/json'
|
||||
]);
|
||||
curl_setopt($ch, CURLOPT_URL, $webhook['url']);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $webhook['request_method']);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload_json));
|
||||
if (!empty($customheaders)) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $webhook['headers']);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($result === false) {
|
||||
echo "Error sending notifications: " . curl_error($ch);
|
||||
if ($response === false) {
|
||||
echo "Error sending notifications: " . curl_error($ch) . "<br />";
|
||||
} else {
|
||||
echo "Discord Notifications sent<br />";
|
||||
echo "Webhook Notifications sent<br />";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Gotify notifications if enabled
|
||||
if ($gotifyNotificationsEnabled) {
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
// Get name of user from household table
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($user['name']) {
|
||||
$message = $user['name'] . ", the following subscriptions are up for renewal:\n";
|
||||
} else {
|
||||
$message = "The following subscriptions are up for renewal:\n";
|
||||
}
|
||||
|
||||
foreach ($perUser as $subscription) {
|
||||
$dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
|
||||
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'message' => $message,
|
||||
'priority' => 5
|
||||
);
|
||||
|
||||
$data_string = json_encode($data);
|
||||
|
||||
$ch = curl_init($gotify['serverUrl'] . '/message?token=' . $gotify['appToken']);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($data_string))
|
||||
);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
if ($result === false) {
|
||||
echo "Error sending notifications: " . curl_error($ch);
|
||||
} else {
|
||||
echo "Gotify Notifications sent<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Telegram notifications if enabled
|
||||
if ($telegramNotificationsEnabled) {
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
// Get name of user from household table
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($user['name']) {
|
||||
$message = $user['name'] . ", the following subscriptions are up for renewal:\n";
|
||||
} else {
|
||||
$message = "The following subscriptions are up for renewal:\n";
|
||||
}
|
||||
|
||||
foreach ($perUser as $subscription) {
|
||||
$dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
|
||||
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'chat_id' => $telegram['chatId'],
|
||||
'text' => $message
|
||||
);
|
||||
|
||||
$data_string = json_encode($data);
|
||||
|
||||
$ch = curl_init('https://api.telegram.org/bot' . $telegram['botToken'] . '/sendMessage');
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
||||
'Content-Type: application/json',
|
||||
'Content-Length: ' . strlen($data_string))
|
||||
);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
if ($result === false) {
|
||||
echo "Error sending notifications: " . curl_error($ch);
|
||||
} else {
|
||||
echo "Telegram Notifications sent<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pushover notifications if enabled
|
||||
if ($pushoverNotificationsEnabled) {
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
// Get name of user from household table
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($user['name']) {
|
||||
$message = $user['name'] . ", the following subscriptions are up for renewal:\n";
|
||||
} else {
|
||||
$message = "The following subscriptions are up for renewal:\n";
|
||||
}
|
||||
|
||||
foreach ($perUser as $subscription) {
|
||||
$dayText = $subscription['days'] == 1 ? "Tomorrow" : "In " . $subscription['days'] . " days";
|
||||
$message .= $subscription['name'] . " for " . $subscription['price'] . " (" . $dayText . ")\n";
|
||||
}
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, "https://api.pushover.net/1/messages.json");
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
|
||||
'token' => $pushover['token'],
|
||||
'user' => $pushover['user_key'],
|
||||
'message' => $message,
|
||||
]));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$result = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
if ($result === false) {
|
||||
echo "Error sending notifications: " . curl_error($ch);
|
||||
} else {
|
||||
echo "Pushover Notifications sent<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Webhook notifications if enabled
|
||||
if ($webhookNotificationsEnabled) {
|
||||
// Get webhook payload and turn it into a json object
|
||||
|
||||
$payload = str_replace("{{days_until}}", $days, $webhook['payload']); // The default value for all subscriptions
|
||||
$payload_json = json_decode($payload, true);
|
||||
|
||||
$subscription_template = $payload_json["{{subscriptions}}"];
|
||||
$subscriptions = [];
|
||||
|
||||
foreach ($notify as $userId => $perUser) {
|
||||
// Get name of user from household table
|
||||
$stmt = $db->prepare('SELECT * FROM household WHERE id = :userId');
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($user['name']) {
|
||||
$payer = $user['name'];
|
||||
}
|
||||
|
||||
foreach ($perUser as $k => $subscription) {
|
||||
$temp_subscription = $subscription_template[0];
|
||||
|
||||
foreach ($temp_subscription as $key => $value) {
|
||||
if (is_string($value)) {
|
||||
$temp_subscription[$key] = str_replace("{{subscription_name}}", $subscription['name'], $value);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_price}}", $subscription['price'], $temp_subscription[$key]);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_currency}}", $subscription['currency'], $temp_subscription[$key]);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_category}}", $subscription['category'], $temp_subscription[$key]);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_payer}}", $subscription['payer'], $temp_subscription[$key]);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_date}}", $subscription['date'], $temp_subscription[$key]);
|
||||
$temp_subscription[$key] = str_replace("{{subscription_days_until_payment}}", $subscription['days'], $temp_subscription[$key]); // The de facto value for this subscription
|
||||
}
|
||||
}
|
||||
$subscriptions[] = $temp_subscription;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$payload_json["{{subscriptions}}"] = $subscriptions;
|
||||
$payload_json[$webhook['iterator']] = $subscriptions;
|
||||
unset($payload_json["{{subscriptions}}"]);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $webhook['url']);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $webhook['request_method']);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload_json));
|
||||
if (!empty($customheaders)) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $webhook['headers']);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
if ($response === false) {
|
||||
echo "Error sending notifications: " . curl_error($ch);
|
||||
} else {
|
||||
echo "Webhook Notifications sent<br />";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
echo "Nothing to notify.";
|
||||
} else {
|
||||
echo "Nothing to notify.<br />";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';
|
||||
|
||||
$query = "SELECT * FROM admin";
|
||||
$stmt = $db->prepare($query);
|
||||
$result = $stmt->execute();
|
||||
$admin = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$query = "SELECT * FROM password_resets WHERE email_sent = 0";
|
||||
$stmt = $db->prepare($query);
|
||||
$result = $stmt->execute();
|
||||
|
||||
$rows = [];
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
if ($rows) {
|
||||
if ($admin['smtp_address'] && $admin['smtp_port'] && $admin['smtp_username'] && $admin['smtp_password'] && $admin['encryption']) {
|
||||
// There are SMTP settings
|
||||
$smtpAddress = $admin['smtp_address'];
|
||||
$smtpPort = $admin['smtp_port'];
|
||||
$smtpUsername = $admin['smtp_username'];
|
||||
$smtpPassword = $admin['smtp_password'];
|
||||
$fromEmail = empty($admin['from_email']) ? 'wallos@wallosapp.com' : $admin['from_email'];
|
||||
$encryption = $admin['encryption'];
|
||||
$server_url = $admin['server_url'];
|
||||
|
||||
require __DIR__ . '/../../libs/PHPMailer/PHPMailer.php';
|
||||
require __DIR__ . '/../../libs/PHPMailer/SMTP.php';
|
||||
require __DIR__ . '/../../libs/PHPMailer/Exception.php';
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $smtpAddress;
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $smtpUsername;
|
||||
$mail->Password = $smtpPassword;
|
||||
$mail->SMTPSecure = $encryption;
|
||||
$mail->Port = $smtpPort;
|
||||
$mail->setFrom($fromEmail);
|
||||
|
||||
try {
|
||||
foreach ($rows as $user) {
|
||||
$mail->addAddress($user['email']);
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = 'Wallos - Reset Password';
|
||||
$mail->Body = '<img src="' . $server_url . '/images/siteicons/blue/wallos.png" alt="Logo" />
|
||||
<br>
|
||||
A password reset was requested for your account.
|
||||
<br>
|
||||
Please click the following link to reset your password: <a href="' . $server_url . '/passwordreset.php?email=' . $user['email'] . '&token=' . $user['token'] . '">Reset Password</a>';
|
||||
|
||||
$mail->send();
|
||||
|
||||
$query = "UPDATE password_resets SET email_sent = 1 WHERE id = :id";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':id', $user['id'], SQLITE3_INTEGER);
|
||||
$stmt->execute();
|
||||
|
||||
$mail->clearAddresses();
|
||||
|
||||
echo "Password reset email sent to " . $user['email'] . "<br>";
|
||||
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo} <br>";
|
||||
}
|
||||
} else {
|
||||
// There are no SMTP settings
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
// There are no password reset emails to be sent
|
||||
exit();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';
|
||||
|
||||
$query = "SELECT * FROM admin";
|
||||
$stmt = $db->prepare($query);
|
||||
$result = $stmt->execute();
|
||||
$admin = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($admin['require_email_verification'] == 0) {
|
||||
die("Email verification is not required.");
|
||||
}
|
||||
|
||||
$query = "SELECT * FROM email_verification WHERE email_sent = 0";
|
||||
$stmt = $db->prepare($query);
|
||||
$result = $stmt->execute();
|
||||
|
||||
$rows = [];
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$rows[] = $row;
|
||||
}
|
||||
|
||||
if ($rows) {
|
||||
if ($admin['smtp_address'] && $admin['smtp_port'] && $admin['smtp_username'] && $admin['smtp_password'] && $admin['encryption']) {
|
||||
// There are SMTP settings
|
||||
$smtpAddress = $admin['smtp_address'];
|
||||
$smtpPort = $admin['smtp_port'];
|
||||
$smtpUsername = $admin['smtp_username'];
|
||||
$smtpPassword = $admin['smtp_password'];
|
||||
$fromEmail = empty($admin['from_email']) ? 'wallos@wallosapp.com' : $admin['from_email'];
|
||||
$encryption = $admin['encryption'];
|
||||
$server_url = $admin['server_url'];
|
||||
|
||||
require __DIR__ . '/../../libs/PHPMailer/PHPMailer.php';
|
||||
require __DIR__ . '/../../libs/PHPMailer/SMTP.php';
|
||||
require __DIR__ . '/../../libs/PHPMailer/Exception.php';
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
$mail->isSMTP();
|
||||
$mail->Host = $smtpAddress;
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = $smtpUsername;
|
||||
$mail->Password = $smtpPassword;
|
||||
$mail->SMTPSecure = $encryption;
|
||||
$mail->Port = $smtpPort;
|
||||
$mail->setFrom($fromEmail);
|
||||
|
||||
try {
|
||||
foreach ($rows as $user) {
|
||||
$mail->addAddress($user['email']);
|
||||
$mail->isHTML(true);
|
||||
$mail->Subject = 'Wallos - Email Verification';
|
||||
$mail->Body = '<img src="' . $server_url . '/images/siteicons/blue/wallos.png" alt="Logo" />
|
||||
<br>
|
||||
Registration on Wallos was successful.
|
||||
<br>
|
||||
Please click the following link to verify your email: <a href="' . $server_url . '/verifyemail.php?email=' . $user['email'] . '&token=' . $user['token'] . '">Verify Email</a>';
|
||||
|
||||
$mail->send();
|
||||
|
||||
$query = "UPDATE email_verification SET email_sent = 1 WHERE id = :id";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':id', $user['id'], SQLITE3_INTEGER);
|
||||
$stmt->execute();
|
||||
|
||||
$mail->clearAddresses();
|
||||
|
||||
echo "Verification email sent to " . $user['email'] . "<br>";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||
}
|
||||
} else {
|
||||
// There are no SMTP settings
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
// There are no verification emails to be sent
|
||||
exit();
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,73 +1,92 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../includes/connect_endpoint_crontabs.php';
|
||||
|
||||
$query = "SELECT api_key FROM fixer";
|
||||
$result = $db->query($query);
|
||||
// Get all user ids
|
||||
|
||||
if ($result) {
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($row) {
|
||||
$apiKey = $row['api_key'];
|
||||
$query = "SELECT id, username FROM user";
|
||||
$stmt = $db->prepare($query);
|
||||
$usersToUpdateExchange = $stmt->execute();
|
||||
|
||||
$codes = "";
|
||||
$query = "SELECT id, name, symbol, code FROM currencies";
|
||||
$result = $db->query($query);
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$codes .= $row['code'].",";
|
||||
}
|
||||
$codes = rtrim($codes, ',');
|
||||
$query = "SELECT u.main_currency, c.code FROM user u LEFT JOIN currencies c ON u.main_currency = c.id WHERE u.id = 1";
|
||||
$stmt = $db->prepare($query);
|
||||
$result = $stmt->execute();
|
||||
while ($userToUpdateExchange = $usersToUpdateExchange->fetchArray(SQLITE3_ASSOC)) {
|
||||
$userId = $userToUpdateExchange['id'];
|
||||
echo "For user: " . $userToUpdateExchange['username'] . "<br />";
|
||||
|
||||
$query = "SELECT api_key FROM fixer WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result) {
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$mainCurrencyCode = $row['code'];
|
||||
$mainCurrencyId = $row['main_currency'];
|
||||
|
||||
if ($row) {
|
||||
$apiKey = $row['api_key'];
|
||||
|
||||
$api_url = "http://data.fixer.io/api/latest?access_key=". $apiKey . "&base=EUR&symbols=" . $codes;
|
||||
$response = file_get_contents($api_url);
|
||||
$apiData = json_decode($response, true);
|
||||
|
||||
$mainCurrencyToEUR = $apiData['rates'][$mainCurrencyCode];
|
||||
|
||||
if ($apiData !== null && isset($apiData['rates'])) {
|
||||
foreach ($apiData['rates'] as $currencyCode => $rate) {
|
||||
if ($currencyCode === $mainCurrencyCode) {
|
||||
$exchangeRate = 1.0;
|
||||
} else {
|
||||
$exchangeRate = $rate / $mainCurrencyToEUR;
|
||||
}
|
||||
$updateQuery = "UPDATE currencies SET rate = :rate WHERE code = :code";
|
||||
$updateStmt = $db->prepare($updateQuery);
|
||||
$updateStmt->bindParam(':rate', $exchangeRate, SQLITE3_TEXT);
|
||||
$updateStmt->bindParam(':code', $currencyCode, SQLITE3_TEXT);
|
||||
$updateResult = $updateStmt->execute();
|
||||
|
||||
if (!$updateResult) {
|
||||
echo "Error updating rate for currency: $currencyCode";
|
||||
}
|
||||
}
|
||||
$currentDate = new DateTime();
|
||||
$formattedDate = $currentDate->format('Y-m-d');
|
||||
|
||||
$deleteQuery = "DELETE FROM last_exchange_update";
|
||||
$deleteStmt = $db->prepare($deleteQuery);
|
||||
$deleteResult = $deleteStmt->execute();
|
||||
|
||||
$query = "INSERT INTO last_exchange_update (date) VALUES (:formattedDate)";
|
||||
$codes = "";
|
||||
$query = "SELECT id, name, symbol, code FROM currencies WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':formattedDate', $formattedDate, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$codes .= $row['code'].",";
|
||||
}
|
||||
$codes = rtrim($codes, ',');
|
||||
$query = "SELECT u.main_currency, c.code FROM user u LEFT JOIN currencies c ON u.main_currency = c.id WHERE u.id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$mainCurrencyCode = $row['code'];
|
||||
$mainCurrencyId = $row['main_currency'];
|
||||
|
||||
$db->close();
|
||||
echo "Rates updated successfully!";
|
||||
$api_url = "http://data.fixer.io/api/latest?access_key=". $apiKey . "&base=EUR&symbols=" . $codes;
|
||||
$response = file_get_contents($api_url);
|
||||
$apiData = json_decode($response, true);
|
||||
|
||||
$mainCurrencyToEUR = $apiData['rates'][$mainCurrencyCode];
|
||||
|
||||
if ($apiData !== null && isset($apiData['rates'])) {
|
||||
foreach ($apiData['rates'] as $currencyCode => $rate) {
|
||||
if ($currencyCode === $mainCurrencyCode) {
|
||||
$exchangeRate = 1.0;
|
||||
} else {
|
||||
$exchangeRate = $rate / $mainCurrencyToEUR;
|
||||
}
|
||||
$updateQuery = "UPDATE currencies SET rate = :rate WHERE code = :code";
|
||||
$updateStmt = $db->prepare($updateQuery);
|
||||
$updateStmt->bindParam(':rate', $exchangeRate, SQLITE3_TEXT);
|
||||
$updateStmt->bindParam(':code', $currencyCode, SQLITE3_TEXT);
|
||||
$updateResult = $updateStmt->execute();
|
||||
|
||||
if (!$updateResult) {
|
||||
echo "Error updating rate for currency: $currencyCode <br />";
|
||||
}
|
||||
}
|
||||
$currentDate = new DateTime();
|
||||
$formattedDate = $currentDate->format('Y-m-d');
|
||||
|
||||
$deleteQuery = "DELETE FROM last_exchange_update WHERE user_id = :userId";
|
||||
$deleteStmt = $db->prepare($deleteQuery);
|
||||
$deleteResult = $deleteStmt->execute();
|
||||
|
||||
$query = "INSERT INTO last_exchange_update (date, user_id) VALUES (:formattedDate, :userId)";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':formattedDate', $formattedDate, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
$db->close();
|
||||
echo "Rates updated successfully!<br />";
|
||||
}
|
||||
} else {
|
||||
echo "Exchange rates update skipped. No fixer.io api key provided<br />";
|
||||
$apiKey = null;
|
||||
}
|
||||
} else {
|
||||
echo "Exchange rates update skipped. No fixer.io api key provided";
|
||||
echo "Exchange rates update skipped. No fixer.io api key provided<br />";
|
||||
$apiKey = null;
|
||||
}
|
||||
} else {
|
||||
echo "Exchange rates update skipped. No fixer.io api key provided";
|
||||
$apiKey = null;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -2,20 +2,19 @@
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
require_once '../../includes/inputvalidation.php';
|
||||
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if (isset($_GET['action']) && $_GET['action'] == "add") {
|
||||
$currencyName = "Currency";
|
||||
$currencySymbol = "$";
|
||||
$currencyCode = "CODE";
|
||||
$currencyRate = 1;
|
||||
$sqlInsert = "INSERT INTO currencies (name, symbol, code, rate) VALUES (:name, :symbol, :code, :rate)";
|
||||
$sqlInsert = "INSERT INTO currencies (name, symbol, code, rate, user_id) VALUES (:name, :symbol, :code, :rate, :userId)";
|
||||
$stmtInsert = $db->prepare($sqlInsert);
|
||||
$stmtInsert->bindParam(':name', $currencyName, SQLITE3_TEXT);
|
||||
$stmtInsert->bindParam(':symbol', $currencySymbol, SQLITE3_TEXT);
|
||||
$stmtInsert->bindParam(':code', $currencyCode, SQLITE3_TEXT);
|
||||
$stmtInsert->bindParam(':rate', $currencyRate, SQLITE3_TEXT);
|
||||
$stmtInsert->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$resultInsert = $stmtInsert->execute();
|
||||
|
||||
if ($resultInsert) {
|
||||
@@ -30,12 +29,13 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
$name = validate($_GET['name']);
|
||||
$symbol = validate($_GET['symbol']);
|
||||
$code = validate($_GET['code']);
|
||||
$sql = "UPDATE currencies SET name = :name, symbol = :symbol, code = :code WHERE id = :currencyId";
|
||||
$sql = "UPDATE currencies SET name = :name, symbol = :symbol, code = :code WHERE id = :currencyId AND user_id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':name', $name, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':symbol', $symbol, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':code', $code, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':currencyId', $currencyId, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result) {
|
||||
@@ -60,16 +60,18 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
}
|
||||
} else if (isset($_GET['action']) && $_GET['action'] == "delete") {
|
||||
if (isset($_GET['currencyId']) && $_GET['currencyId'] != "") {
|
||||
$query = "SELECT main_currency FROM user WHERE id = 1";
|
||||
$query = "SELECT main_currency FROM user WHERE id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$mainCurrencyId = $row['main_currency'];
|
||||
|
||||
$currencyId = $_GET['currencyId'];
|
||||
$checkQuery = "SELECT COUNT(*) FROM subscriptions WHERE currency_id = :currencyId";
|
||||
$checkQuery = "SELECT COUNT(*) FROM subscriptions WHERE currency_id = :currencyId AND user_id = :userId";
|
||||
$checkStmt = $db->prepare($checkQuery);
|
||||
$checkStmt->bindParam(':currencyId', $currencyId, SQLITE3_INTEGER);
|
||||
$checkStmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$checkResult = $checkStmt->execute();
|
||||
$row = $checkResult->fetchArray();
|
||||
$count = $row[0];
|
||||
@@ -90,9 +92,10 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
echo json_encode($response);
|
||||
exit;
|
||||
} else {
|
||||
$sql = "DELETE FROM currencies WHERE id = :currencyId";
|
||||
$sql = "DELETE FROM currencies WHERE id = :currencyId AND user_id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':currencyId', $currencyId, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
if ($result) {
|
||||
echo json_encode(["success" => true, "message" => translate('currency_removed', $i18n)]);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$newApiKey = isset($_POST["api_key"]) ? $_POST["api_key"] : "";
|
||||
$provider = isset($_POST["provider"]) ? $_POST["provider"] : 0;
|
||||
|
||||
$removeOldKey = "DELETE FROM fixer";
|
||||
$db->exec($removeOldKey);
|
||||
$removeOldKey = "DELETE FROM fixer WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($removeOldKey);
|
||||
$stmt->bindParam(":userId", $userId, SQLITE3_INTEGER);
|
||||
$stmt->execute();
|
||||
|
||||
if ($provider == 1) {
|
||||
$testKeyUrl = "https://api.apilayer.com/fixer/latest?base=USD&symbols=EUR";
|
||||
@@ -27,10 +28,11 @@
|
||||
$apiData = json_decode($response, true);
|
||||
if ($apiData['success'] && $apiData['success'] == 1) {
|
||||
if (!empty($newApiKey)) {
|
||||
$insertNewKey = "INSERT INTO fixer (api_key, provider) VALUES (:api_key, :provider)";
|
||||
$insertNewKey = "INSERT INTO fixer (api_key, provider, user_id) VALUES (:api_key, :provider, :userId)";
|
||||
$stmt = $db->prepare($insertNewKey);
|
||||
$stmt->bindParam(":api_key", $newApiKey, SQLITE3_TEXT);
|
||||
$stmt->bindParam(":provider", $provider, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(":userId", $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
if ($result) {
|
||||
echo json_encode(["success" => true, "message" => translate('api_key_saved', $i18n)]);
|
||||
|
||||
@@ -6,8 +6,10 @@ $shouldUpdate = true;
|
||||
if (isset($_GET['force']) && $_GET['force'] === "true") {
|
||||
$shouldUpdate = true;
|
||||
} else {
|
||||
$query = "SELECT date FROM last_exchange_update";
|
||||
$result = $db->querySingle($query);
|
||||
$query = "SELECT date FROM last_exchange_update WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result) {
|
||||
$lastUpdateDate = new DateTime($result);
|
||||
@@ -34,14 +36,17 @@ if ($result) {
|
||||
$provider = $row['provider'];
|
||||
|
||||
$codes = "";
|
||||
$query = "SELECT id, name, symbol, code FROM currencies";
|
||||
$result = $db->query($query);
|
||||
$query = "SELECT id, name, symbol, code FROM currencies WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$codes .= $row['code'].",";
|
||||
}
|
||||
$codes = rtrim($codes, ',');
|
||||
$query = "SELECT u.main_currency, c.code FROM user u LEFT JOIN currencies c ON u.main_currency = c.id WHERE u.id = 1";
|
||||
$query = "SELECT u.main_currency, c.code FROM user u LEFT JOIN currencies c ON u.main_currency = c.id WHERE u.id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$mainCurrencyCode = $row['code'];
|
||||
@@ -72,10 +77,11 @@ if ($result) {
|
||||
} else {
|
||||
$exchangeRate = $rate / $mainCurrencyToEUR;
|
||||
}
|
||||
$updateQuery = "UPDATE currencies SET rate = :rate WHERE code = :code";
|
||||
$updateQuery = "UPDATE currencies SET rate = :rate WHERE code = :code AND user_id = :userId";
|
||||
$updateStmt = $db->prepare($updateQuery);
|
||||
$updateStmt->bindParam(':rate', $exchangeRate, SQLITE3_TEXT);
|
||||
$updateStmt->bindParam(':code', $currencyCode, SQLITE3_TEXT);
|
||||
$updateStmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$updateResult = $updateStmt->execute();
|
||||
|
||||
if (!$updateResult) {
|
||||
@@ -85,14 +91,11 @@ if ($result) {
|
||||
$currentDate = new DateTime();
|
||||
$formattedDate = $currentDate->format('Y-m-d');
|
||||
|
||||
$deleteQuery = "DELETE FROM last_exchange_update";
|
||||
$deleteStmt = $db->prepare($deleteQuery);
|
||||
$deleteResult = $deleteStmt->execute();
|
||||
|
||||
$query = "INSERT INTO last_exchange_update (date) VALUES (:formattedDate)";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':formattedDate', $formattedDate, SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
$updateQuery = "UPDATE last_exchange_update SET date = :formattedDate WHERE user_id = :userId";
|
||||
$updateStmt = $db->prepare($updateQuery);
|
||||
$updateStmt->bindParam(':formattedDate', $formattedDate, SQLITE3_TEXT);
|
||||
$updateStmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$updateResult = $updateStmt->execute();
|
||||
|
||||
$db->close();
|
||||
echo "Rates updated successfully!";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
$result = $db->query("SELECT COUNT(*) as count FROM user");
|
||||
$row = $result->fetchArray(SQLITE3_NUM);
|
||||
|
||||
@@ -33,6 +33,15 @@ $allMigrations = glob('migrations/*.php');
|
||||
if (count($allMigrations) == 0) {
|
||||
$allMigrations = glob('../../migrations/*.php');
|
||||
}
|
||||
|
||||
$allMigrations = array_map(function($migration) {
|
||||
return str_replace('../../', '', $migration);
|
||||
}, $allMigrations);
|
||||
|
||||
$completedMigrations = array_map(function($migration) {
|
||||
return str_replace('../../', '', $migration);
|
||||
}, $completedMigrations);
|
||||
|
||||
$requiredMigrations = array_diff($allMigrations, $completedMigrations);
|
||||
|
||||
if (count($requiredMigrations) === 0) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
require_once '../../includes/inputvalidation.php';
|
||||
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if (isset($_GET['action']) && $_GET['action'] == "add") {
|
||||
$householdName = "Member";
|
||||
$sqlInsert = "INSERT INTO household (name) VALUES (:name)";
|
||||
$sqlInsert = "INSERT INTO household (name, user_id) VALUES (:name, :userId)";
|
||||
$stmtInsert = $db->prepare($sqlInsert);
|
||||
$stmtInsert->bindParam(':name', $householdName, SQLITE3_TEXT);
|
||||
$stmtInsert->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$resultInsert = $stmtInsert->execute();
|
||||
|
||||
if ($resultInsert) {
|
||||
@@ -32,11 +31,12 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
$name = validate($_GET['name']);
|
||||
$email = $_GET['email'] ? $_GET['email'] : "";
|
||||
$email = validate($email);
|
||||
$sql = "UPDATE household SET name = :name, email = :email WHERE id = :memberId";
|
||||
$sql = "UPDATE household SET name = :name, email = :email WHERE id = :memberId AND user_id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':name', $name, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':email', $email, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':memberId', $memberId, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result) {
|
||||
@@ -62,9 +62,10 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
} else if (isset($_GET['action']) && $_GET['action'] == "delete") {
|
||||
if (isset($_GET['memberId']) && $_GET['memberId'] != "" && $_GET['memberId'] != 1) {
|
||||
$memberId = $_GET['memberId'];
|
||||
$checkMember = "SELECT COUNT(*) FROM subscriptions WHERE payer_user_id = :memberId";
|
||||
$checkMember = "SELECT COUNT(*) FROM subscriptions WHERE payer_user_id = :memberId AND user_id = :userId";
|
||||
$checkStmt = $db->prepare($checkMember);
|
||||
$checkStmt->bindParam(':memberId', $memberId, SQLITE3_INTEGER);
|
||||
$checkStmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$checkResult = $checkStmt->execute();
|
||||
$row = $checkResult->fetchArray();
|
||||
$count = $row[0];
|
||||
@@ -76,9 +77,10 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
];
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
$sql = "DELETE FROM household WHERE id = :memberId";
|
||||
$sql = "DELETE FROM household WHERE id = :memberId and user_id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':memberId', $memberId, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
if ($result) {
|
||||
$response = [
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
@@ -28,8 +27,10 @@ require_once '../../includes/connect_endpoint.php';
|
||||
$bot_username = $data["bot_username"];
|
||||
$bot_avatar_url = $data["bot_avatar"];
|
||||
|
||||
$query = "SELECT COUNT(*) FROM discord_notifications";
|
||||
$result = $db->querySingle($query);
|
||||
$query = "SELECT COUNT(*) FROM discord_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(":userId", $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result === false) {
|
||||
$response = [
|
||||
@@ -38,12 +39,15 @@ require_once '../../includes/connect_endpoint.php';
|
||||
];
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
if ($result == 0) {
|
||||
$query = "INSERT INTO discord_notifications (enabled, webhook_url, bot_username, bot_avatar_url)
|
||||
VALUES (:enabled, :webhook_url, :bot_username, :bot_avatar_url)";
|
||||
$row = $result->fetchArray();
|
||||
$count = $row[0];
|
||||
if ($count == 0) {
|
||||
$query = "INSERT INTO discord_notifications (enabled, webhook_url, bot_username, bot_avatar_url, user_id)
|
||||
VALUES (:enabled, :webhook_url, :bot_username, :bot_avatar_url, :userId)";
|
||||
} else {
|
||||
$query = "UPDATE discord_notifications
|
||||
SET enabled = :enabled, webhook_url = :webhook_url, bot_username = :bot_username, bot_avatar_url = :bot_avatar_url";
|
||||
SET enabled = :enabled, webhook_url = :webhook_url, bot_username = :bot_username, bot_avatar_url = :bot_avatar_url
|
||||
WHERE user_id = :userId";
|
||||
}
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
@@ -51,6 +55,7 @@ require_once '../../includes/connect_endpoint.php';
|
||||
$stmt->bindValue(':webhook_url', $webhook_url, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':bot_username', $bot_username, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':bot_avatar_url', $bot_avatar_url, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$response = [
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
@@ -36,8 +35,10 @@
|
||||
$smtpPassword = $data["smtppassword"];
|
||||
$fromEmail = $data["fromemail"];
|
||||
|
||||
$query = "SELECT COUNT(*) FROM email_notifications";
|
||||
$result = $db->querySingle($query);
|
||||
$query = "SELECT COUNT(*) FROM email_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(":userId", $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result === false) {
|
||||
$response = [
|
||||
@@ -46,13 +47,15 @@
|
||||
];
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
if ($result == 0) {
|
||||
$query = "INSERT INTO email_notifications (enabled, smtp_address, smtp_port, smtp_username, smtp_password, from_email, encryption)
|
||||
VALUES (:enabled, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword, :fromEmail, :encryption)";
|
||||
$row = $result->fetchArray();
|
||||
$count = $row[0];
|
||||
if ($count == 0) {
|
||||
$query = "INSERT INTO email_notifications (enabled, smtp_address, smtp_port, smtp_username, smtp_password, from_email, encryption, user_id)
|
||||
VALUES (:enabled, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword, :fromEmail, :encryption, :userId)";
|
||||
} else {
|
||||
$query = "UPDATE email_notifications
|
||||
SET enabled = :enabled, smtp_address = :smtpAddress, smtp_port = :smtpPort,
|
||||
smtp_username = :smtpUsername, smtp_password = :smtpPassword, from_email = :fromEmail, encryption = :encryption";
|
||||
smtp_username = :smtpUsername, smtp_password = :smtpPassword, from_email = :fromEmail, encryption = :encryption WHERE user_id = :userId";
|
||||
}
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
@@ -63,6 +66,7 @@
|
||||
$stmt->bindValue(':smtpPassword', $smtpPassword, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':fromEmail', $fromEmail, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':encryption', $encryption, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$response = [
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
@@ -27,8 +26,10 @@
|
||||
$url = $data["gotify_url"];
|
||||
$token = $data["token"];
|
||||
|
||||
$query = "SELECT COUNT(*) FROM gotify_notifications";
|
||||
$result = $db->querySingle($query);
|
||||
$query = "SELECT COUNT(*) FROM gotify_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(":userId", $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result === false) {
|
||||
$response = [
|
||||
@@ -37,18 +38,21 @@
|
||||
];
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
if ($result == 0) {
|
||||
$query = "INSERT INTO gotify_notifications (enabled, url, token)
|
||||
VALUES (:enabled, :url, :token)";
|
||||
$row = $result->fetchArray();
|
||||
$count = $row[0];
|
||||
if ($count == 0) {
|
||||
$query = "INSERT INTO gotify_notifications (enabled, url, token, user_id)
|
||||
VALUES (:enabled, :url, :token, :userId)";
|
||||
} else {
|
||||
$query = "UPDATE gotify_notifications
|
||||
SET enabled = :enabled, url = :url, token = :token";
|
||||
SET enabled = :enabled, url = :url, token = :token WHERE user_id = :userId";
|
||||
}
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':enabled', $enabled, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':url', $url, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':token', $token, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$response = [
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
@@ -22,8 +21,10 @@
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
$days = $data["days"];
|
||||
$query = "SELECT COUNT(*) FROM notification_settings";
|
||||
$result = $db->querySingle($query);
|
||||
$query = "SELECT COUNT(*) FROM notification_settings WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(":userId", $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result === false) {
|
||||
$response = [
|
||||
@@ -32,15 +33,18 @@
|
||||
];
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
if ($result == 0) {
|
||||
$query = "INSERT INTO notification_settings (days)
|
||||
VALUES (:days)";
|
||||
$row = $result->fetchArray();
|
||||
$count = $row[0];
|
||||
if ($count == 0) {
|
||||
$query = "INSERT INTO notification_settings (days, user_id)
|
||||
VALUES (:days, :userId)";
|
||||
} else {
|
||||
$query = "UPDATE notification_settings SET days = :days";
|
||||
$query = "UPDATE notification_settings SET days = :days WHERE user_id = :userId";
|
||||
}
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':days', $days, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$response = [
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
@@ -28,8 +27,10 @@ require_once '../../includes/connect_endpoint.php';
|
||||
$user_key = $data["user_key"];
|
||||
$token = $data["token"];
|
||||
|
||||
$query = "SELECT COUNT(*) FROM pushover_notifications";
|
||||
$result = $db->querySingle($query);
|
||||
$query = "SELECT COUNT(*) FROM pushover_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(":userId", $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result === false) {
|
||||
$response = [
|
||||
@@ -38,18 +39,21 @@ require_once '../../includes/connect_endpoint.php';
|
||||
];
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
if ($result == 0) {
|
||||
$query = "INSERT INTO pushover_notifications (enabled, user_key, token)
|
||||
VALUES (:enabled, :user_key, :token)";
|
||||
$row = $result->fetchArray();
|
||||
$count = $row[0];
|
||||
if ($count == 0) {
|
||||
$query = "INSERT INTO pushover_notifications (enabled, user_key, token, user_id)
|
||||
VALUES (:enabled, :user_key, :token, :userId)";
|
||||
} else {
|
||||
$query = "UPDATE pushover_notifications
|
||||
SET enabled = :enabled, user_key = :user_key, token = :token";
|
||||
SET enabled = :enabled, user_key = :user_key, token = :token, user_id = :userId";
|
||||
}
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':enabled', $enabled, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':user_key', $user_key, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':token', $token, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$response = [
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
@@ -27,8 +26,10 @@
|
||||
$bot_token = $data["bot_token"];
|
||||
$chat_id = $data["chat_id"];
|
||||
|
||||
$query = "SELECT COUNT(*) FROM telegram_notifications";
|
||||
$result = $db->querySingle($query);
|
||||
$query = "SELECT COUNT(*) FROM telegram_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(":userId", $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result === false) {
|
||||
$response = [
|
||||
@@ -37,18 +38,21 @@
|
||||
];
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
if ($result == 0) {
|
||||
$query = "INSERT INTO telegram_notifications (enabled, bot_token, chat_id)
|
||||
VALUES (:enabled, :bot_token, :chat_id)";
|
||||
$row = $result->fetchArray();
|
||||
$count = $row[0];
|
||||
if ($count == 0) {
|
||||
$query = "INSERT INTO telegram_notifications (enabled, bot_token, chat_id, user_id)
|
||||
VALUES (:enabled, :bot_token, :chat_id, :userId)";
|
||||
} else {
|
||||
$query = "UPDATE telegram_notifications
|
||||
SET enabled = :enabled, bot_token = :bot_token, chat_id = :chat_id";
|
||||
SET enabled = :enabled, bot_token = :bot_token, chat_id = :chat_id WHERE user_id = :userId";
|
||||
}
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':enabled', $enabled, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':bot_token', $bot_token, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':chat_id', $chat_id, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$response = [
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
@@ -28,8 +27,10 @@
|
||||
$headers = $data["headers"];
|
||||
$payload = $data["payload"];
|
||||
|
||||
$query = "SELECT COUNT(*) FROM webhook_notifications";
|
||||
$result = $db->querySingle($query);
|
||||
$query = "SELECT COUNT(*) FROM webhook_notifications WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(":userId", $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result === false) {
|
||||
$response = [
|
||||
@@ -38,12 +39,14 @@
|
||||
];
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
if ($result == 0) {
|
||||
$query = "INSERT INTO webhook_notifications (enabled, url, headers, payload)
|
||||
VALUES (:enabled, :url, :headers, :payload)";
|
||||
$row = $result->fetchArray();
|
||||
$count = $row[0];
|
||||
if ($count == 0) {
|
||||
$query = "INSERT INTO webhook_notifications (enabled, url, headers, payload, user_id)
|
||||
VALUES (:enabled, :url, :headers, :payload, :userId)";
|
||||
} else {
|
||||
$query = "UPDATE webhook_notifications
|
||||
SET enabled = :enabled, url = :url, headers = :headers, payload = :payload";
|
||||
SET enabled = :enabled, url = :url, headers = :headers, payload = :payload WHERE user_id = :userId";
|
||||
}
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
@@ -51,6 +54,7 @@
|
||||
$stmt->bindValue(':url', $url, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':headers', $headers, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':payload', $payload, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$response = [
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -5,7 +5,6 @@ use PHPMailer\PHPMailer\SMTP;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
require_once '../../includes/inputvalidation.php';
|
||||
require_once '../../includes/getsettings.php';
|
||||
|
||||
session_start();
|
||||
|
||||
function sanitizeFilename($filename) {
|
||||
$filename = preg_replace("/[^a-zA-Z0-9\s]/", "", $filename);
|
||||
$filename = str_replace(" ", "-", $filename);
|
||||
@@ -193,13 +191,14 @@
|
||||
$newID = max($maxID + 1, 32);
|
||||
|
||||
// Insert the new record with the new ID
|
||||
$sql = "INSERT INTO payment_methods (id, name, icon, enabled) VALUES (:id, :name, :icon, :enabled)";
|
||||
$sql = "INSERT INTO payment_methods (id, name, icon, enabled, user_id) VALUES (:id, :name, :icon, :enabled, :userId)";
|
||||
$stmt = $db->prepare($sql);
|
||||
|
||||
$stmt->bindParam(':id', $newID, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':name', $name, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':icon', $icon, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':enabled', $enabled, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$success['success'] = true;
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if ($_SERVER["REQUEST_METHOD"] === "DELETE") {
|
||||
$paymentMethodId = $_GET["id"];
|
||||
$deleteQuery = "DELETE FROM payment_methods WHERE id = :paymentMethodId";
|
||||
$deleteQuery = "DELETE FROM payment_methods WHERE id = :paymentMethodId and user_id = :userId";
|
||||
$deleteStmt = $db->prepare($deleteQuery);
|
||||
$deleteStmt->bindParam(':paymentMethodId', $paymentMethodId, SQLITE3_INTEGER);
|
||||
$deleteStmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($deleteStmt->execute()) {
|
||||
$success['success'] = true;
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
$paymentsInUseQuery = $db->query('SELECT id FROM payment_methods WHERE id IN (SELECT DISTINCT payment_method_id FROM subscriptions)');
|
||||
$paymentsInUseQuery = $db->prepare('SELECT id FROM payment_methods WHERE id IN (SELECT DISTINCT payment_method_id FROM subscriptions) AND user_id = :userId');
|
||||
$paymentsInUseQuery->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $paymentsInUseQuery->execute();
|
||||
|
||||
$paymentsInUse = [];
|
||||
while ($row = $paymentsInUseQuery->fetchArray(SQLITE3_ASSOC)) {
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$paymentsInUse[] = $row['id'];
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM payment_methods";
|
||||
|
||||
$result = $db->query($sql);
|
||||
$sql = "SELECT * FROM payment_methods WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result) {
|
||||
$payments = array();
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
@@ -25,7 +29,7 @@ if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
}
|
||||
|
||||
foreach ($payments as $payment) {
|
||||
$paymentIconFolder = $payment['id'] <= 31 ? 'images/uploads/icons/' : 'images/uploads/logos/';
|
||||
$paymentIconFolder = (strpos($payment['icon'], 'images/uploads/icons/') !== false) ? "" : "images/uploads/logos/";
|
||||
$inUse = in_array($payment['id'], $paymentsInUse);
|
||||
?>
|
||||
<div class="payments-payment"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
@@ -17,8 +17,9 @@ if (!isset($_GET['paymentId']) || !isset($_GET['enabled'])) {
|
||||
|
||||
$paymentId = $_GET['paymentId'];
|
||||
|
||||
$stmt = $db->prepare('SELECT COUNT(*) as count FROM subscriptions WHERE payment_method_id=:paymentId');
|
||||
$stmt = $db->prepare('SELECT COUNT(*) as count FROM subscriptions WHERE payment_method_id=:paymentId and user_id=:userId');
|
||||
$stmt->bindValue(':paymentId', $paymentId, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$row = $result->fetchArray();
|
||||
$inUse = $row['count'] === 1;
|
||||
@@ -32,10 +33,11 @@ if ($inUse) {
|
||||
|
||||
$enabled = $_GET['enabled'];
|
||||
|
||||
$sqlUpdate = 'UPDATE payment_methods SET enabled=:enabled WHERE id=:id';
|
||||
$sqlUpdate = 'UPDATE payment_methods SET enabled=:enabled WHERE id=:id and user_id=:userId';
|
||||
$stmtUpdate = $db->prepare($sqlUpdate);
|
||||
$stmtUpdate->bindParam(':enabled', $enabled);
|
||||
$stmtUpdate->bindParam(':id', $paymentId);
|
||||
$stmtUpdate->bindParam(':userId', $userId);
|
||||
$resultUpdate = $stmtUpdate->execute();
|
||||
|
||||
$text = $enabled ? "enabled" : "disabled";
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
@@ -20,10 +19,11 @@ if (!isset($_POST['paymentId']) || !isset($_POST['name']) || $_POST['paymentId']
|
||||
$paymentId = $_POST['paymentId'];
|
||||
$name = $_POST['name'];
|
||||
|
||||
$sql = "UPDATE payment_methods SET name = :name WHERE id = :paymentId";
|
||||
$sql = "UPDATE payment_methods SET name = :name WHERE id = :paymentId and user_id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':name', $name, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':paymentId', $paymentId, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result) {
|
||||
|
||||
@@ -2,17 +2,16 @@
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
$paymentMethods = $_POST['paymentMethodIds'];
|
||||
$order = 1;
|
||||
|
||||
foreach ($paymentMethods as $paymentMethodId) {
|
||||
$sql = "UPDATE payment_methods SET `order` = :order WHERE id = :paymentMethodId";
|
||||
$sql = "UPDATE payment_methods SET `order` = :order WHERE id = :paymentMethodId and user_id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':order', $order, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':paymentMethodId', $paymentMethodId, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$order++;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
@@ -15,8 +15,9 @@
|
||||
|
||||
$color = $data['color'];
|
||||
|
||||
$stmt = $db->prepare('UPDATE settings SET color_theme = :color');
|
||||
$stmt = $db->prepare('UPDATE settings SET color_theme = :color WHERE user_id = :userId');
|
||||
$stmt->bindParam(':color', $color, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
@@ -14,8 +14,9 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$convert_currency = $data['value'];
|
||||
|
||||
$stmt = $db->prepare('UPDATE settings SET convert_currency = :convert_currency');
|
||||
$stmt = $db->prepare('UPDATE settings SET convert_currency = :convert_currency WHERE user_id = :userId');
|
||||
$stmt->bindParam(':convert_currency', $convert_currency, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
@@ -20,10 +20,11 @@
|
||||
$stmt = $db->prepare('DELETE FROM custom_colors');
|
||||
$stmt->execute();
|
||||
|
||||
$stmt = $db->prepare('INSERT INTO custom_colors (main_color, accent_color, hover_color) VALUES (:main_color, :accent_color, :hover_color)');
|
||||
$stmt = $db->prepare('INSERT INTO custom_colors (main_color, accent_color, hover_color, user_id) VALUES (:main_color, :accent_color, :hover_color, :userId)');
|
||||
$stmt->bindParam(':main_color', $main_color, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':accent_color', $accent_color, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':hover_color', $hover_color, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
@@ -14,8 +14,9 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$hide_disabled = $data['value'];
|
||||
|
||||
$stmt = $db->prepare('UPDATE settings SET hide_disabled = :hide_disabled');
|
||||
$stmt = $db->prepare('UPDATE settings SET hide_disabled = :hide_disabled WHERE user_id = :userId');
|
||||
$stmt->bindParam(':hide_disabled', $hide_disabled, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
@@ -14,8 +14,9 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$monthly_price = $data['value'];
|
||||
|
||||
$stmt = $db->prepare('UPDATE settings SET monthly_price = :monthly_price');
|
||||
$stmt = $db->prepare('UPDATE settings SET monthly_price = :monthly_price WHERE user_id = :userId');
|
||||
$stmt->bindParam(':monthly_price', $monthly_price, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
@@ -14,8 +14,9 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$remove_background = $data['value'];
|
||||
|
||||
$stmt = $db->prepare('UPDATE settings SET remove_background = :remove_background');
|
||||
$stmt = $db->prepare('UPDATE settings SET remove_background = :remove_background WHERE user_id = :userId');
|
||||
$stmt->bindParam(':remove_background', $remove_background, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
@@ -10,7 +10,8 @@
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "DELETE") {
|
||||
$stmt = $db->prepare('DELETE FROM custom_colors');
|
||||
$stmt = $db->prepare('DELETE FROM custom_colors WHERE user_id = :userId');
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
@@ -14,8 +14,9 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
|
||||
$theme = $data['theme'];
|
||||
|
||||
$stmt = $db->prepare('UPDATE settings SET dark_theme = :theme');
|
||||
$stmt = $db->prepare('UPDATE settings SET dark_theme = :theme WHERE user_id = :userId');
|
||||
$stmt->bindParam(':theme', $theme, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
die(json_encode([
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
require_once '../../includes/inputvalidation.php';
|
||||
require_once '../../includes/getsettings.php';
|
||||
|
||||
session_start();
|
||||
|
||||
function sanitizeFilename($filename) {
|
||||
$filename = preg_replace("/[^a-zA-Z0-9\s]/", "", $filename);
|
||||
@@ -184,20 +182,21 @@
|
||||
|
||||
if (!$isEdit) {
|
||||
$sql = "INSERT INTO subscriptions (name, logo, price, currency_id, next_payment, cycle, frequency, notes,
|
||||
payment_method_id, payer_user_id, category_id, notify, inactive, url, notify_days_before)
|
||||
payment_method_id, payer_user_id, category_id, notify, inactive, url, notify_days_before, user_id)
|
||||
VALUES (:name, :logo, :price, :currencyId, :nextPayment, :cycle, :frequency, :notes,
|
||||
:paymentMethodId, :payerUserId, :categoryId, :notify, :inactive, :url, :notifyDaysBefore)";
|
||||
:paymentMethodId, :payerUserId, :categoryId, :notify, :inactive, :url, :notifyDaysBefore, :userId)";
|
||||
} else {
|
||||
$id = $_POST['id'];
|
||||
if ($logo != "") {
|
||||
$sql = "UPDATE subscriptions SET name = :name, logo = :logo, price = :price, currency_id = :currencyId,
|
||||
next_payment = :nextPayment, cycle = :cycle, frequency = :frequency, notes = :notes, payment_method_id = :paymentMethodId,
|
||||
payer_user_id = :payerUserId, category_id = :categoryId, notify = :notify, inactive = :inactive,
|
||||
url = :url, notify_days_before = :notifyDaysBefore WHERE id = :id";
|
||||
url = :url, notify_days_before = :notifyDaysBefore WHERE id = :id AND user_id = :userId";
|
||||
} else {
|
||||
$sql = "UPDATE subscriptions SET name = :name, price = :price, currency_id = :currencyId, next_payment = :nextPayment,
|
||||
cycle = :cycle, frequency = :frequency, notes = :notes, payment_method_id = :paymentMethodId, payer_user_id = :payerUserId,
|
||||
category_id = :categoryId, notify = :notify, inactive = :inactive, url = :url,notify_days_before = :notifyDaysBefore WHERE id = :id";
|
||||
category_id = :categoryId, notify = :notify, inactive = :inactive, url = :url,notify_days_before = :notifyDaysBefore
|
||||
WHERE id = :id AND user_id = :userId";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,6 +221,7 @@
|
||||
$stmt->bindParam(':inactive', $inactive, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':url', $url, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':notifyDaysBefore', $notifyDaysBefore, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$success['status'] = "Success";
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if ($_SERVER["REQUEST_METHOD"] === "DELETE") {
|
||||
$subscriptionId = $_GET["id"];
|
||||
$deleteQuery = "DELETE FROM subscriptions WHERE id = :subscriptionId";
|
||||
$deleteQuery = "DELETE FROM subscriptions WHERE id = :subscriptionId AND user_id = :userId";
|
||||
$deleteStmt = $db->prepare($deleteQuery);
|
||||
$deleteStmt->bindParam(':subscriptionId', $subscriptionId, SQLITE3_INTEGER);
|
||||
$deleteStmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if ($deleteStmt->execute()) {
|
||||
http_response_code(204);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true) {
|
||||
if (isset($_GET['id']) && $_GET['id'] != "") {
|
||||
$subscriptionId = intval($_GET['id']);
|
||||
$query = "SELECT * FROM subscriptions WHERE id = :subscriptionId";
|
||||
$query = "SELECT * FROM subscriptions WHERE id = :subscriptionId AND user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':subscriptionId', $subscriptionId, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
$subscriptionData = array();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
session_start();
|
||||
|
||||
require_once '../../includes/currency_formatter.php';
|
||||
require_once '../../includes/getdbkeys.php';
|
||||
@@ -35,7 +34,7 @@
|
||||
}
|
||||
|
||||
$params = array();
|
||||
$sql = "SELECT * FROM subscriptions WHERE 1=1";
|
||||
$sql = "SELECT * FROM subscriptions WHERE user_id = :userId";
|
||||
|
||||
if (isset($_GET['category']) && $_GET['category'] != "") {
|
||||
$sql .= " AND category_id = :category";
|
||||
@@ -55,6 +54,7 @@
|
||||
$sql .= " ORDER BY $sort $order, inactive ASC";
|
||||
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
$stmt->bindValue($key, $value);
|
||||
@@ -84,7 +84,7 @@
|
||||
$print[$id]['currency_code'] = $currencies[$subscription['currency_id']]['code'];
|
||||
$currencyId = $subscription['currency_id'];
|
||||
$print[$id]['next_payment'] = date('M d, Y', strtotime($subscription['next_payment']));
|
||||
$paymentIconFolder = $paymentMethodId <= 31 ? 'images/uploads/icons/' : 'images/uploads/logos/';
|
||||
$paymentIconFolder = (strpos($payment_methods[$paymentMethodId]['icon'], 'images/uploads/icons/') !== false) ? "" : "images/uploads/logos/";
|
||||
$print[$id]['payment_method_icon'] = $paymentIconFolder . $payment_methods[$paymentMethodId]['icon'];
|
||||
$print[$id]['payment_method_name'] = $payment_methods[$paymentMethodId]['name'];
|
||||
$print[$id]['payment_method_id'] = $paymentMethodId;
|
||||
|
||||
@@ -3,9 +3,6 @@
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
require_once '../../includes/inputvalidation.php';
|
||||
|
||||
session_start();
|
||||
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
"success" => false,
|
||||
@@ -28,8 +25,6 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
} else {
|
||||
$budget = $data["budget"];
|
||||
|
||||
$userId = $_SESSION['userId'];
|
||||
|
||||
$sql = "UPDATE user SET budget = :budget WHERE id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindValue(':budget', $budget, SQLITE3_TEXT);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
||||
die(json_encode([
|
||||
@@ -14,8 +12,9 @@
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
if (isset($input['avatar'])) {
|
||||
$avatar = "images/uploads/logos/avatars/".$input['avatar'];
|
||||
$sql = "SELECT avatar FROM user";
|
||||
$sql = "SELECT avatar FROM user WHERE id = :userId";
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$userAvatar = $result->fetchArray(SQLITE3_ASSOC)['avatar'];
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?php
|
||||
require_once '../../includes/connect_endpoint.php';
|
||||
require_once '../../includes/inputvalidation.php';
|
||||
|
||||
session_start();
|
||||
|
||||
function update_exchange_rate($db) {
|
||||
$query = "SELECT api_key, provider FROM fixer";
|
||||
$result = $db->query($query);
|
||||
$query = "SELECT api_key, provider FROM fixer WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
|
||||
if ($result) {
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
@@ -23,8 +23,9 @@
|
||||
}
|
||||
$codes = rtrim($codes, ',');
|
||||
|
||||
$query = "SELECT u.main_currency, c.code FROM user u LEFT JOIN currencies c ON u.main_currency = c.id WHERE u.id = 1";
|
||||
$query = "SELECT u.main_currency, c.code FROM user u LEFT JOIN currencies c ON u.main_currency = c.id WHERE u.id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$mainCurrencyCode = $row['code'];
|
||||
@@ -55,23 +56,32 @@
|
||||
} else {
|
||||
$exchangeRate = $rate / $mainCurrencyToEUR;
|
||||
}
|
||||
$updateQuery = "UPDATE currencies SET rate = :rate WHERE code = :code";
|
||||
$updateQuery = "UPDATE currencies SET rate = :rate WHERE code = :code AND user_id = :userId";
|
||||
$updateStmt = $db->prepare($updateQuery);
|
||||
$updateStmt->bindParam(':rate', $exchangeRate, SQLITE3_TEXT);
|
||||
$updateStmt->bindParam(':code', $currencyCode, SQLITE3_TEXT);
|
||||
$updateStmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$updateResult = $updateStmt->execute();
|
||||
}
|
||||
$currentDate = new DateTime();
|
||||
$formattedDate = $currentDate->format('Y-m-d');
|
||||
|
||||
$deleteQuery = "DELETE FROM last_exchange_update";
|
||||
$deleteStmt = $db->prepare($deleteQuery);
|
||||
$deleteResult = $deleteStmt->execute();
|
||||
$query = "SELECT * FROM last_exchange_update WHERE user_id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($row) {
|
||||
$query = "UPDATE last_exchange_update SET date = :formattedDate WHERE user_id = :userId";
|
||||
} else {
|
||||
$query = "INSERT INTO last_exchange_update (date, user_id) VALUES (:formattedDate, :userId)";
|
||||
}
|
||||
|
||||
$query = "INSERT INTO last_exchange_update (date) VALUES (:formattedDate)";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':formattedDate', $formattedDate, SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$resutl = $stmt->execute();
|
||||
|
||||
$db->close();
|
||||
}
|
||||
@@ -79,8 +89,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
$query = "SELECT main_currency FROM user WHERE id = 1";
|
||||
$query = "SELECT main_currency FROM user WHERE id = :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$row = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$mainCurrencyId = $row['main_currency'];
|
||||
@@ -174,10 +185,39 @@
|
||||
return "";
|
||||
}
|
||||
|
||||
if (isset($_SESSION['username']) && isset($_POST['username']) && isset($_POST['email']) && isset($_POST['avatar'])) {
|
||||
$oldUsername = $_SESSION['username'];
|
||||
$username = validate($_POST['username']);
|
||||
if (isset($_SESSION['username']) && isset($_POST['email']) && $_POST['email'] !== ""
|
||||
&& isset($_POST['avatar']) && $_POST['avatar'] !== ""
|
||||
&& isset($_POST['main_currency']) && $_POST['main_currency'] !== ""
|
||||
&& isset($_POST['language']) && $_POST['language'] !== "") {
|
||||
|
||||
$email = validate($_POST['email']);
|
||||
|
||||
$query = "SELECT email FROM user WHERE id = :user_id";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':user_id', $userId, SQLITE3_TEXT);
|
||||
$result = $stmt->execute();
|
||||
$user = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$oldEmail = $user['email'];
|
||||
|
||||
if ($oldEmail != $email) {
|
||||
$query = "SELECT email FROM user WHERE email = :email AND id != :userId";
|
||||
$stmt = $db->prepare($query);
|
||||
$stmt->bindValue(':email', $email, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':userId', $userId, SQLITE3_INTEGER);
|
||||
$result = $stmt->execute();
|
||||
$otherUser = $result->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($otherUser) {
|
||||
$response = [
|
||||
"success" => false,
|
||||
"errorMessage" => translate('email_exists', $i18n)
|
||||
];
|
||||
echo json_encode($response);
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
$avatar = $_POST['avatar'];
|
||||
$main_currency = $_POST['main_currency'];
|
||||
$language = $_POST['language'];
|
||||
@@ -221,17 +261,17 @@
|
||||
}
|
||||
|
||||
if (isset($_POST['password']) && $_POST['password'] != "") {
|
||||
$sql = "UPDATE user SET avatar = :avatar, username = :username, email = :email, password = :password, main_currency = :main_currency, language = :language WHERE id = 1";
|
||||
$sql = "UPDATE user SET avatar = :avatar, email = :email, password = :password, main_currency = :main_currency, language = :language WHERE id = :userId";
|
||||
} else {
|
||||
$sql = "UPDATE user SET avatar = :avatar, username = :username, email = :email, main_currency = :main_currency, language = :language WHERE id = 1";
|
||||
$sql = "UPDATE user SET avatar = :avatar, email = :email, main_currency = :main_currency, language = :language WHERE id = :userId";
|
||||
}
|
||||
|
||||
$stmt = $db->prepare($sql);
|
||||
$stmt->bindParam(':avatar', $avatar, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':username', $username, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':email', $email, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':main_currency', $main_currency, SQLITE3_INTEGER);
|
||||
$stmt->bindParam(':language', $language, SQLITE3_TEXT);
|
||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||
|
||||
if (isset($_POST['password']) && $_POST['password'] != "") {
|
||||
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
|
||||
@@ -246,14 +286,6 @@
|
||||
$root = str_replace('/endpoints/user', '', dirname($_SERVER['PHP_SELF']));
|
||||
$root = $root == '' ? '/' : $root;
|
||||
setcookie('language', $language, $cookieExpire, $root);
|
||||
if ($username != $oldUsername) {
|
||||
$_SESSION['username'] = $username;
|
||||
if (isset($_COOKIE['wallos_login'])) {
|
||||
$cookie = explode('|', $_COOKIE['wallos_login'], 2) ;
|
||||
$token = $cookie[1];
|
||||
$cookieValue = $username . "|" . $token . "|" . $main_currency;
|
||||
}
|
||||
}
|
||||
$_SESSION['avatar'] = $avatar;
|
||||
$_SESSION['main_currency'] = $main_currency;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user