From 31cac4e4235fa36e46dc089aa1b7a3bc18e52ca0 Mon Sep 17 00:00:00 2001 From: Teppy Date: Thu, 13 Mar 2025 23:01:20 -0400 Subject: [PATCH] changes --- foftickets.js | 27 +++++++++++++++++++++++---- views/partials/nav.ejs~ | 12 ++++++++++++ views/settings.ejs | 5 +++++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 views/partials/nav.ejs~ diff --git a/foftickets.js b/foftickets.js index 837237a..10f69e6 100644 --- a/foftickets.js +++ b/foftickets.js @@ -71,6 +71,7 @@ const QRSalt ="!SaltyMagic5392370662"; // Make sure open camping tickets actually send email // Don't hardcode MainURL and PORT // Limit number of Open Camping tickets +// + Make sure subsequent FB imports don't add duplicate tickets // Maybe: // Deactivate individual magic links (User) // Option to "Email me my QR Code" @@ -183,7 +184,7 @@ app.use((req, res, next) => { let users={}; let tickets={}; let camps={}; -let settings={ "enable-transfer":true }; +let settings={ "enable-transfer":true, "open-limit":0 }; function InitDatabase() { for (const key in users ) delete users[key]; @@ -658,13 +659,29 @@ app.post('/qrcodesu',requireSuperUser,async (req,res) => { return res.send({ owner:username, qrcode: URL, magiclink:GetMagicLink(username) }); }) +function opencount() { + let rval=0; + for (t in tickets) if (t.startsWith("open-")) if (tickets[t].status!='r') rval++; + return rval; + } + app.get('/settings',requireSuperUser, (req,res) => { - res.render('settings',{ username:req.session.username, superuser:req.session.superuser, settings:settings, message: "" }) + res.render('settings',{ username:req.session.username, superuser:req.session.superuser, settings:settings, opencount:opencount(), message: "" }) + }); + +app.post('/addopen',requireSuperUser,(req,res) => { + settings['open-limit']+=Number(req.body.addopen); + return res.redirect('/settings'); }); app.post('/importfb',requireSuperUser,upload.single("file"),(req,res) => { console.log("File name:", req.file.originalname); + let emails={}; + for (t in tickets) { + if (tickets[t].offered) emails[tickets[t].offered]=1; + if (tickets[t].owner ) emails[tickets[t].owner ]=1; + } const contents=req.file.buffer.toString(); csvParse.parse(contents, { columns: true, trim: true }, (err, records) => { if (err) { @@ -673,13 +690,14 @@ app.post('/importfb',requireSuperUser,upload.single("file"),(req,res) => { return res.redirect("/settings"); } let count=0; - for (const item of records) { + for (const item of records) if (item.email in emails) { if (!camps[item.camp]) camps[item.camp]={ leader:"", lastid:0 }; camps[item.camp].lastid++; const ticket=item.camp+"-"+camps[item.camp].lastid; tickets[ticket]={ owner:"", offered: item.email, paid:0.00, status:"i" }; console.log("Offered ",ticket," to ",item.email); count++; + emails[item.email]=1; } req.session.message="Imported "+count+" Frostburn-style records."; return res.redirect("/settings"); @@ -698,7 +716,7 @@ app.post('/serialize',requireSuperUser, async (req,res) => { app.post('/deserialize',requireSuperUser, (req,res) => { DeserializeAll(); - return res.redirect("/"); // Since we may be overwriting session + return res.redirect("/settings"); // Since we may be overwriting session }); app.post('/purge',requireSuperUser, (req,res) => { @@ -753,6 +771,7 @@ function do_payforwhat(payforwhat) { camps[payforwhat.camp].lastid++; tickets[payforwhat.camp+"-"+camps[payforwhat.camp].lastid]={ owner:payforwhat.email, offered:"",paid:100.0*payforwhat.amounteach,status:"i" }; } + EmailTickets(payforwhat.email); } } diff --git a/views/partials/nav.ejs~ b/views/partials/nav.ejs~ new file mode 100644 index 0000000..63a0399 --- /dev/null +++ b/views/partials/nav.ejs~ @@ -0,0 +1,12 @@ + + diff --git a/views/settings.ejs b/views/settings.ejs index 700fd3b..79c0aaa 100644 --- a/views/settings.ejs +++ b/views/settings.ejs @@ -28,6 +28,11 @@ +
+ Open Camping Tickets: <%=opencount%> / <%=settings['open-limit']%> + + +
Import Tickets (Frostburn Format):