Skip to content

Commit

Permalink
add stream deletion, fix alert display, improve style
Browse files Browse the repository at this point in the history
  • Loading branch information
emnbdx committed Sep 2, 2024
1 parent d8d109d commit ffe98cd
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 32 deletions.
23 changes: 20 additions & 3 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
exit();
}

if(isset($_POST['delete'])) {
$guid = $_POST['guid'];

$repository->deleteCharityStream($guid);

header("Location: /admin/index.php");
exit();
}

// Utilisation de la fonction GetCharityStreamsList pour récupérer les données mises à jour
$charityStreams = $repository->getCharityStreamsListDB();

Expand Down Expand Up @@ -99,7 +108,9 @@
</tr>
</thead>
<tbody>
<?php foreach ($charityStreams as $stream): ?>
<?php foreach ($charityStreams as $stream):
$token = $repository->getAccessTokensDB($stream['organization_slug']);
?>
<tr>
<td><?php echo htmlspecialchars($stream['id']); ?></td>
<td><?php echo htmlspecialchars(bin2hex($stream['guid'])); ?></td>
Expand All @@ -124,8 +135,14 @@
<td>
<a href="/admin/widget_edit.php?charityStreamId=<?php echo bin2hex($stream['guid']); ?>"
class="btn btn-primary mb-3" data-bs-toggle="tooltip" data-bs-title="Édition">📝</a>
<a href="/redirect_auth_page.php?organizationSlug=<?php echo $stream['organization_slug']; ?>"
class="btn btn-success" data-bs-toggle="tooltip" data-bs-title="Mire d'authorisation" target="_blank">🔑</a>
<?php if(!isset($token)) { ?>
<a href="/redirect_auth_page.php?organizationSlug=<?php echo $stream['organization_slug']; ?>"
class="btn btn-success mb-3" data-bs-toggle="tooltip" data-bs-title="Mire d'authorisation" target="_blank">🔑</a>
<?php } ?>
<form method="POST">
<input type="hidden" name="guid" value="<?php echo bin2hex($stream['guid']) ?>"/>
<button type="submit" class="btn btn-danger" name="delete" data-bs-toggle="tooltip" data-bs-title="Suppression">🗑️</button>
</form>
</td>
</tr>
<?php endforeach; ?>
Expand Down
2 changes: 1 addition & 1 deletion admin/widget_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<label for="sound" class="form-label">Fichier de son</label>
<?php if(isset($alertBoxWidget['sound'])) { ?>
<div class="form-text">
Déjà chargé: <a href="<?php echo $fileManager->getPictureUrl($alertBoxWidget['sound']); ?>" target="_blank"><?php echo htmlspecialchars($alertBoxWidget['sound']); ?></a>
Déjà chargé: <a href="<?php echo $fileManager->getSoundUrl($alertBoxWidget['sound']); ?>" target="_blank"><?php echo htmlspecialchars($alertBoxWidget['sound']); ?></a>
</div>
<?php } ?>
<input type="file" class="form-control" id="sound" name="sound" />
Expand Down
9 changes: 5 additions & 4 deletions app/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ private function checkType($formdata, $ext, $mimes)

private function isPicture($formdata)
{
$ext = ["jpg", "jpeg", "png", "gif", "heic", "heif"];
$ext = ["gif", "heic", "heif", "jpg", "jpeg", "png", "webp"];
$mimes = [
"image/jpeg",
"image/png",
"image/gif",
"image/heic",
"image/heif"
"image/heif",
"image/jpeg",
"image/png",
"image/webp"
];
$this->checkType($formdata, $ext, $mimes);
}
Expand Down
33 changes: 31 additions & 2 deletions app/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function createCharityStreamDB($guid, $owner_email, $form_slug, $organization_sl
]);

$query = 'INSERT INTO ' . $this->prefix . 'widget_donation_goal_bar (charity_stream_guid, goal, text_color, text_content, bar_color, background_color)
VALUES (:guid, 1000, "#FFFFFF", "", "#FF0000", "#000000")';
VALUES (:guid, 1000, "#2f2f5e", "", "#49d38a", "#4c3ccf")';
$stmt = $this->db->prepare($query);
$stmt->execute([
':guid' => hex2bin($guid)
Expand All @@ -145,6 +145,31 @@ function createCharityStreamDB($guid, $owner_email, $form_slug, $organization_sl
return $password;
}

public function deleteCharityStream($guid)
{
$stream = $this->getCharityStreamByGuidDB(hex2bin($guid));

$query = 'DELETE FROM ' . $this->prefix . 'users
WHERE email = ?';
$stmt = $this->db->prepare($query);
$stmt->execute([$stream['owner_email']]);

$query = 'DELETE FROM ' . $this->prefix . 'widget_donation_goal_bar
WHERE charity_stream_guid = ?';
$stmt = $this->db->prepare($query);
$stmt->execute([$stream['guid']]);

$query = 'DELETE FROM ' . $this->prefix . 'widget_alert_box
WHERE charity_stream_guid = ?';
$stmt = $this->db->prepare($query);
$stmt->execute([$stream['guid']]);

$query = 'DELETE FROM ' . $this->prefix . 'charity_stream
WHERE guid = ?';
$stmt = $this->db->prepare($query);
$stmt->execute([$stream['guid']]);
}

function getUser($email)
{
$stmt = $this->db->prepare('SELECT * FROM ' . $this->prefix . 'users WHERE email = ?');
Expand Down Expand Up @@ -255,7 +280,11 @@ function getAccessTokensDB($organization_slug)
]);
}

return $stmt->fetch();
if ($stmt->rowCount() > 0) {
return $stmt->fetch();
}

return null;
}


Expand Down
7 changes: 2 additions & 5 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
.widget-donation-goal {
margin: 10px;
color: white;
-webkit-box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
}

#title {
Expand All @@ -13,7 +10,6 @@
font-weight: bold;
font-family: Roboto, sans-serif;
text-align: center;
text-shadow: 0px 0px 10px #000;
margin: 0;
width: 70%;
z-index: 1;
Expand All @@ -25,6 +21,7 @@
display: flex;
position: relative;
overflow: hidden;
border-radius: 20px;
}

#goal-current,
Expand All @@ -33,7 +30,6 @@
font-family: Roboto, sans-serif;
font-weight: bold;
font-size: 28px;
text-shadow: 0px 0px 10px #000;
width: 15%;
z-index: 1;
}
Expand All @@ -50,6 +46,7 @@
top: 4px;
left: 4px;
overflow: hidden;
border-radius: 13px;
}

.fade {
Expand Down
2 changes: 1 addition & 1 deletion css/main.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 36 additions & 15 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
var alertQueue = [];
var isAlertActive = false;

function displayAlertBox(pseudo, message, amount) {
alertQueue.push({ pseudo, message, amount });

if (!isAlertActive) {
processAlertQueue();
}
}

function processAlertQueue() {
if (alertQueue.length === 0) {
isAlertActive = false;
return;
}

isAlertActive = true;
const alert = alertQueue.shift();
const { pseudo, message, amount } = alert;
var container = document.querySelector('.widget-alert-box');
var oldContent = container.innerHTML;
container.innerHTML = '';
Expand All @@ -21,42 +40,44 @@ function displayAlertBox(pseudo, message, amount) {
messageTemplate.classList.add('fade');
container.appendChild(messageTemplate);

// Appliquer l'effet de fondu
setTimeout(function () {
img.classList.add('show');
messageTemplate.classList.add('show');
}, 100); // Délai pour déclencher la transition
img.classList.add('show');
messageTemplate.classList.add('show');

// Jouer le son
var audio = new Audio(window.sound);
audio.volume = window.sound_volume;
audio.play();

// Retirer l'image et le message après 3 secondes avec un effet de fondu
setTimeout(function () {
img.classList.remove('show');
messageTemplate.classList.remove('show');
audio.pause();
audio.currentTime = 0;

setTimeout(function () {
container.innerHTML = oldContent;
}, 1000); // Attendre que le fondu soit terminé avant de vider le conteneur
container.innerHTML = oldContent;
processAlertQueue();
}, window.alert_duration);
}

const options = {
separator: ' ',
separator: ' ',
decimal: ',',
suffix: ' €',
};
var counter = new countUp.CountUp('goal-current', window.currentAmount, options);

function updateDonationBar() {
const currentAmountUnit = window.currentAmount / 100;
const percentage = Math.min(100, (currentAmountUnit / window.goalAmount) * 100);
document.getElementById('goal-current').textContent = currentAmountUnit + ' €';
document.getElementById('total-bar').style.width = percentage + '%';
counter.update(currentAmountUnit);
document.getElementById('total-bar').style.width = 'calc(' + percentage + '% - 8px)';
}

function fetchDonation() {
const request = new XMLHttpRequest()
request.open("GET", 'fetch_donations.php?charityStreamId=' + window.charityStreamId +
(window.continuationToken ? ('&continuationToken=' + window.continuationToken) : '') +
(window.currentAmount ? ('&currentAmount=' + window.currentAmount) : '') +
request.open("GET", 'fetch_donations.php?charityStreamId=' + window.charityStreamId +
(window.continuationToken ? ('&continuationToken=' + window.continuationToken) : '') +
(window.currentAmount ? ('&currentAmount=' + window.currentAmount) : '') +
(window.from ? ('&from=' + window.from) : ''), true)
request.onload = () => {
if (request.status === 200) {
Expand Down
2 changes: 1 addition & 1 deletion js/main.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": {
"bootstrap": "^5.3.3",
"countup.js": "^2.8.0",
"moment": "^2.30.1"
}
}
1 change: 1 addition & 0 deletions widget_donation_goal.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
var continuationToken = '<?php echo $continuationToken; ?>';
</script>

<script src="/node_modules/countup.js/dist/countUp.umd.js"></script>
<script src="/js/main.min.js"></script>

<script>
Expand Down

0 comments on commit ffe98cd

Please sign in to comment.