feat!: allow registration of multiple users (#340)
feat: administration area feat: add reset password functionality
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user