From ffe98cdf57a1abff5e98dad9f6e03e0447eecbe8 Mon Sep 17 00:00:00 2001 From: emnbdx Date: Mon, 2 Sep 2024 19:04:36 +0200 Subject: [PATCH] add stream deletion, fix alert display, improve style --- admin/index.php | 23 +++++++++++++++--- admin/widget_edit.php | 2 +- app/FileManager.php | 9 +++---- app/Repository.php | 33 ++++++++++++++++++++++++-- css/main.css | 7 ++---- css/main.min.css | 2 +- js/main.js | 51 ++++++++++++++++++++++++++++------------ js/main.min.js | 2 +- package-lock.json | 6 +++++ package.json | 1 + widget_donation_goal.php | 1 + 11 files changed, 105 insertions(+), 32 deletions(-) diff --git a/admin/index.php b/admin/index.php index a99c557..440e17f 100644 --- a/admin/index.php +++ b/admin/index.php @@ -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(); @@ -99,7 +108,9 @@ - + getAccessTokensDB($stream['organization_slug']); + ?> @@ -124,8 +135,14 @@ 📝 - 🔑 + + 🔑 + +
+ + +
diff --git a/admin/widget_edit.php b/admin/widget_edit.php index 46b6b80..5eaf0ab 100644 --- a/admin/widget_edit.php +++ b/admin/widget_edit.php @@ -174,7 +174,7 @@
- Déjà chargé: + Déjà chargé:
diff --git a/app/FileManager.php b/app/FileManager.php index 970c930..9605a13 100644 --- a/app/FileManager.php +++ b/app/FileManager.php @@ -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); } diff --git a/app/Repository.php b/app/Repository.php index 8999477..f474f1f 100644 --- a/app/Repository.php +++ b/app/Repository.php @@ -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) @@ -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 = ?'); @@ -255,7 +280,11 @@ function getAccessTokensDB($organization_slug) ]); } - return $stmt->fetch(); + if ($stmt->rowCount() > 0) { + return $stmt->fetch(); + } + + return null; } diff --git a/css/main.css b/css/main.css index ff00ce1..952baff 100644 --- a/css/main.css +++ b/css/main.css @@ -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 { @@ -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; @@ -25,6 +21,7 @@ display: flex; position: relative; overflow: hidden; + border-radius: 20px; } #goal-current, @@ -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; } @@ -50,6 +46,7 @@ top: 4px; left: 4px; overflow: hidden; + border-radius: 13px; } .fade { diff --git a/css/main.min.css b/css/main.min.css index 6ca95df..5489ed1 100644 --- a/css/main.min.css +++ b/css/main.min.css @@ -1 +1 @@ -.widget-donation-goal{margin:10px;color:#fff;-webkit-box-shadow:0 0 10px 0 rgba(0,0,0,.5);-moz-box-shadow:0 0 10px 0 rgba(0,0,0,.5);box-shadow:0 0 10px 0 rgba(0,0,0,.5)}#title{font-size:28px;text-transform:uppercase;font-weight:700;font-family:Roboto,sans-serif;text-align:center;text-shadow:0 0 10px #000;margin:0;width:70%;z-index:1}#goal-bar{border:4px solid #fff;padding:16px;display:flex;position:relative;overflow:hidden}#goal-current,#goal-total{margin:0;font-family:Roboto,sans-serif;font-weight:700;font-size:28px;text-shadow:0 0 10px #000;width:15%;z-index:1}#goal-total{text-align:right}#total-bar{position:absolute;width:calc(100% - 8px);height:calc(100% - 8px);max-width:100%;top:4px;left:4px;overflow:hidden}.fade{opacity:0;transition:opacity 1s ease-in-out}.fade.show{opacity:1}.widget-alert-box{text-align:center} \ No newline at end of file +.widget-donation-goal{margin:10px;color:#fff}#title{font-size:28px;text-transform:uppercase;font-weight:700;font-family:Roboto,sans-serif;text-align:center;margin:0;width:70%;z-index:1}#goal-bar{border:4px solid #fff;padding:16px;display:flex;position:relative;overflow:hidden;border-radius:20px}#goal-current,#goal-total{margin:0;font-family:Roboto,sans-serif;font-weight:700;font-size:28px;width:15%;z-index:1}#goal-total{text-align:right}#total-bar{position:absolute;width:calc(100% - 8px);height:calc(100% - 8px);max-width:100%;top:4px;left:4px;overflow:hidden;border-radius:13px}.fade{opacity:0;transition:opacity 1s ease-in-out}.fade.show{opacity:1}.widget-alert-box{text-align:center} \ No newline at end of file diff --git a/js/main.js b/js/main.js index 847524e..340aa23 100644 --- a/js/main.js +++ b/js/main.js @@ -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 = ''; @@ -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 ? ('¤tAmount=' + window.currentAmount) : '') + + request.open("GET", 'fetch_donations.php?charityStreamId=' + window.charityStreamId + + (window.continuationToken ? ('&continuationToken=' + window.continuationToken) : '') + + (window.currentAmount ? ('¤tAmount=' + window.currentAmount) : '') + (window.from ? ('&from=' + window.from) : ''), true) request.onload = () => { if (request.status === 200) { diff --git a/js/main.min.js b/js/main.min.js index f9c22fa..d70c923 100644 --- a/js/main.min.js +++ b/js/main.min.js @@ -1 +1 @@ -function displayAlertBox(n,e,o){var t=document.querySelector(".widget-alert-box"),a=t.innerHTML;t.innerHTML="";var i=document.createElement("img");i.src=window.image,i.style.maxWidth="100%",i.classList.add("fade"),t.appendChild(i);let r=new Intl.NumberFormat("fr-FR",{style:"currency",currency:"EUR"});var d=document.createElement("p");d.innerHTML=window.message_template.replace("{pseudo}",n).replace("{message}",e).replace("{amount}",r.format(o/100)),d.style.marginTop="10px",d.classList.add("fade"),t.appendChild(d),setTimeout(function(){i.classList.add("show"),d.classList.add("show")},100);var s=new Audio(window.sound);s.volume=window.sound_volume,s.play(),setTimeout(function(){i.classList.remove("show"),d.classList.remove("show"),s.pause(),s.currentTime=0,setTimeout(function(){t.innerHTML=a},1e3)},window.alert_duration)}function updateDonationBar(){const n=window.currentAmount/100,e=Math.min(100,n/window.goalAmount*100);document.getElementById("goal-current").textContent=n+" €",document.getElementById("total-bar").style.width=e+"%"}function fetchDonation(){const n=new XMLHttpRequest;n.open("GET","fetch_donations.php?charityStreamId="+window.charityStreamId+(window.continuationToken?"&continuationToken="+window.continuationToken:"")+(window.currentAmount?"¤tAmount="+window.currentAmount:"")+(window.from?"&from="+window.from:""),!0),n.onload=(()=>{if(200===n.status){const e=JSON.parse(n.response);document.querySelector(".widget-donation-goal")&&updateDonationBar(),document.querySelector(".widget-alert-box")&&e.donations&&e.donations.length>0&&e.donations.forEach(n=>{displayAlertBox(n.pseudo,n.message,n.amount)}),window.currentAmount=e.amount,window.continuationToken=e.continuationToken}else console.error("Erreur lors de la récupération des données de donation:",n.response)}),n.send()} \ No newline at end of file +function displayAlertBox(e,n,o){alertQueue.push({pseudo:e,message:n,amount:o}),isAlertActive||processAlertQueue()}function processAlertQueue(){if(0===alertQueue.length)return void(isAlertActive=!1);isAlertActive=!0;const e=alertQueue.shift(),{pseudo:n,message:o,amount:t}=e;var r=document.querySelector(".widget-alert-box"),a=r.innerHTML;r.innerHTML="";var i=document.createElement("img");i.src=window.image,i.style.maxWidth="100%",i.classList.add("fade"),r.appendChild(i);let s=new Intl.NumberFormat("fr-FR",{style:"currency",currency:"EUR"});var u=document.createElement("p");u.innerHTML=window.message_template.replace("{pseudo}",n).replace("{message}",o).replace("{amount}",s.format(t/100)),u.style.marginTop="10px",u.classList.add("fade"),r.appendChild(u),i.classList.add("show"),u.classList.add("show");var d=new Audio(window.sound);d.volume=window.sound_volume,d.play(),setTimeout(function(){i.classList.remove("show"),u.classList.remove("show"),d.pause(),d.currentTime=0,r.innerHTML=a,processAlertQueue()},window.alert_duration)}function updateDonationBar(){const e=window.currentAmount/100,n=Math.min(100,e/window.goalAmount*100);counter.update(e),document.getElementById("total-bar").style.width="calc("+n+"% - 8px)"}function fetchDonation(){const e=new XMLHttpRequest;e.open("GET","fetch_donations.php?charityStreamId="+window.charityStreamId+(window.continuationToken?"&continuationToken="+window.continuationToken:"")+(window.currentAmount?"¤tAmount="+window.currentAmount:"")+(window.from?"&from="+window.from:""),!0),e.onload=(()=>{if(200===e.status){const n=JSON.parse(e.response);document.querySelector(".widget-donation-goal")&&updateDonationBar(),document.querySelector(".widget-alert-box")&&n.donations&&n.donations.length>0&&n.donations.forEach(e=>{displayAlertBox(e.pseudo,e.message,e.amount)}),window.currentAmount=n.amount,window.continuationToken=n.continuationToken}else console.error("Erreur lors de la récupération des données de donation:",e.response)}),e.send()}var alertQueue=[],isAlertActive=!1;const options={separator:" ",separator:" ",decimal:",",suffix:" €"};var counter=new countUp.CountUp("goal-current",window.currentAmount,options); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9c8a862..b444ac8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,6 +6,7 @@ "": { "dependencies": { "bootstrap": "^5.3.3", + "countup.js": "^2.8.0", "moment": "^2.30.1" } }, @@ -37,6 +38,11 @@ "@popperjs/core": "^2.11.8" } }, + "node_modules/countup.js": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/countup.js/-/countup.js-2.8.0.tgz", + "integrity": "sha512-f7xEhX0awl4NOElHulrl4XRfKoNH3rB+qfNSZZyjSZhaAoUk6elvhH+MNxMmlmuUJ2/QNTWPSA7U4mNtIAKljQ==" + }, "node_modules/moment": { "version": "2.30.1", "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", diff --git a/package.json b/package.json index be6c293..477aa7e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "dependencies": { "bootstrap": "^5.3.3", + "countup.js": "^2.8.0", "moment": "^2.30.1" } } diff --git a/widget_donation_goal.php b/widget_donation_goal.php index 024aaed..0bad24b 100644 --- a/widget_donation_goal.php +++ b/widget_donation_goal.php @@ -75,6 +75,7 @@ var continuationToken = ''; +