Skip to content

Commit

Permalink
Add url field to subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite committed Dec 8, 2023
1 parent 2d7fb4b commit f4da6b7
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 4 deletions.
10 changes: 6 additions & 4 deletions endpoints/subscription/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) {
$payerUserId = $_POST["payer_user_id"];
$categoryId = $_POST['category_id'];
$notes = $_POST["notes"];
$url = $_POST['url'];
$logoUrl = $_POST['logo-url'];
$logo = "";
$notify = isset($_POST['notifications']) ? true : false;
Expand All @@ -158,15 +159,15 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) {

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)
payment_method_id, payer_user_id, category_id, notify, url)
VALUES (:name, :logo, :price, :currencyId, :nextPayment, :cycle, :frequency, :notes,
:paymentMethodId, :payerUserId, :categoryId, :notify)";
:paymentMethodId, :payerUserId, :categoryId, :notify, :url)";
} 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 WHERE id = :id";
$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, url = :url WHERE id = :id";
} 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 WHERE id = :id";
$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, url = :url WHERE id = :id";
}
}

Expand All @@ -188,6 +189,7 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name) {
$stmt->bindParam(':payerUserId', $payerUserId, SQLITE3_INTEGER);
$stmt->bindParam(':categoryId', $categoryId, SQLITE3_INTEGER);
$stmt->bindParam(':notify', $notify, SQLITE3_INTEGER);
$stmt->bindParam(':url', $url, SQLITE3_TEXT);

if ($stmt->execute()) {
$success['status'] = "Success";
Expand Down
1 change: 1 addition & 0 deletions endpoints/subscription/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
$subscriptionData['payer_user_id'] = $row['payer_user_id'];
$subscriptionData['category_id'] = $row['category_id'];
$subscriptionData['notify'] = $row['notify'];
$subscriptionData['url'] = $row['url'];

$subscriptionJson = json_encode($subscriptionData);
header('Content-Type: application/json');
Expand Down
1 change: 1 addition & 0 deletions endpoints/subscriptions/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
$print[$id]['category_id'] = $subscription['category_id'];
$print[$id]['payer_user_id'] = $subscription['payer_user_id'];
$print[$id]['price'] = floatval($subscription['price']);
$print[$id]['url'] = $subscription['url'];

if (isset($_COOKIE['convertCurrency']) && $_COOKIE['convertCurrency'] === 'true' && $currencyId != $mainCurrencyId) {
$print[$id]['price'] = getPriceConverted($print[$id]['price'], $currencyId, $db);
Expand Down
Binary file added images/siteicons/filter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/siteicons/web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions includes/list_subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ function printSubscriptions($subscriptions, $sort, $categories, $members) {
<span class="name"><img src="images/siteicons/subscription.png" alt="Subscription" /><?= $subscription['name'] ?></span>
<span class="payer_user" title="Paid By"><img src="images/siteicons/payment.png" alt="Paid By" /><?= $members[$subscription['payer_user_id']]['name'] ?></span>
<span class="category" title="Category" ><img src="images/siteicons/category.png" alt="Category" /><?= $categories[$subscription['category_id']]['name'] ?></span>
<?php
if ($subscription['url'] != "") {
$url = $subscription['url'];
if (!preg_match('/^https?:\/\//', $url)) {
$url = "https://" . $url;
}
?>
<span class="url" title="External Url"><a href="<?= $url ?>" target="_blank"><img src="images/siteicons/web.png" alt="URL" /></a></span>
<?php
}
?>
</div>
</div>
<?php
Expand Down
5 changes: 5 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
$print[$id]['category_id'] = $subscription['category_id'];
$print[$id]['payer_user_id'] = $subscription['payer_user_id'];
$print[$id]['price'] = floatval($subscription['price']);
$print[$id]['url'] = $subscription['url'];

if (isset($_COOKIE['convertCurrency']) && $_COOKIE['convertCurrency'] === 'true' && $currencyId != $mainCurrencyId) {
$print[$id]['price'] = getPriceConverted($print[$id]['price'], $currencyId, $db);
Expand Down Expand Up @@ -233,6 +234,10 @@
</select>
</div>

<div class="form-group">
<input type="text" id="url" name="url" placeholder="URL">
</div>

<div class="form-group">
<input type="text" id="notes" name="notes" placeholder="Notes">
</div>
Expand Down
12 changes: 12 additions & 0 deletions migrations/000004.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
// This migration adds a URL column to the subscriptions table.

/** @noinspection PhpUndefinedVariableInspection */
$columnQuery = $db->query("SELECT * FROM pragma_table_info('subscriptions') where name='url'");
$columnRequired = $columnQuery->fetchArray(SQLITE3_ASSOC) === false;

if ($columnRequired) {
$db->exec('ALTER TABLE subscriptions ADD COLUMN url VARCHAR(255);');
}

?>
2 changes: 2 additions & 0 deletions scripts/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ function fillEditFormFields(subscription) {
nextPament.value = subscription.next_payment;
const notes = document.querySelector("#notes");
notes.value = subscription.notes;
const url = document.querySelector("#url");
url.value = subscription.url;

const notifications = document.querySelector("#notifications");
if (notifications) {
Expand Down
10 changes: 10 additions & 0 deletions styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ main > .contain {
flex-basis: 33%;
}

.subscription-secondary > .url {
flex-basis: 20px;
margin-left: auto;
cursor: pointer;
}

@media (max-width: 768px) {
.subscription-main > .name {
display: none;
Expand All @@ -308,6 +314,10 @@ main > .contain {
margin-right: 10px;
}

.subscription-secondary .url img {
margin-right: 0px;;
}

.empty-page {
display: block;
max-width: 90%;
Expand Down

0 comments on commit f4da6b7

Please sign in to comment.