![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/lavocat.ca/private_html/.next/server/pages/api/admin/ |
"use strict";(()=>{var e={};e.id=2605,e.ids=[2605],e.modules={238:(e,t,n)=>{n.a(e,async(e,a)=>{try{n.r(t),n.d(t,{default:()=>g});var r=n(65515),i=n(83501),o=n(29021),l=n.n(o),s=n(33873),d=n.n(s),c=e([i]);i=(c.then?(await c)():c)[0];let f=d().join(process.cwd(),"registrations.json");async function g(e,t){if("POST"!==e.method)return t.status(405).json({message:"Method not allowed"});try{let{format:d,dateRange:c,includeNotes:g,includeActivity:h}=e.body,p=l().readFileSync(f,"utf-8"),u=JSON.parse(p);if(console.log(`Initial registrations read: ${u.length}`),console.log("Date range for filtering:",c),console.log("First registration date (before filter): ",u.length>0?u[0].date:"N/A"),console.log("Last registration date (before filter): ",u.length>0?u[u.length-1].date:"N/A"),c&&(u=u.filter(e=>{let t=new Date(e.date);return t>=new Date(c.start)&&t<=new Date(c.end)})),console.log(`Registrations after filtering: ${u.length}`),console.log("First registration date (after filter): ",u.length>0?u[0].date:"N/A"),console.log("Last registration date (after filter): ",u.length>0?u[u.length-1].date:"N/A"),u.sort((e,t)=>new Date(t.date).getTime()-new Date(e.date).getTime()),"pdf"===d)return function(e,t,n,a){try{let n=[...e];if(!n||!Array.isArray(n)||0===n.length)throw Error("No registrations found for export");n.sort((e,t)=>new Date(t.date).getTime()-new Date(e.date).getTime());let o=new r.jsPDF({orientation:"landscape",unit:"mm",format:"a4"});o.setFontSize(16),o.text("Registrations Report",14,15);let l=n.map(e=>[String(e.name||""),String(e.email||""),String(e.phone||""),String(e.birthDate||""),String(e.relationship||""),[e.address?.street||"",e.address?.city||"",e.address?.state||"",e.address?.postalCode||"",e.address?.country||""].filter(Boolean).join(", ")||"N/A",[e.detaineeInfo?.name||"",e.detaineeInfo?.facility||"",e.detaineeInfo?.inmateId||"",e.detaineeInfo?.incarcerationDate||"",e.detaineeInfo?.expectedReleaseDate||""].filter(Boolean).join(", ")||"N/A",`Lang: ${e.preferredLanguage||"N/A"}, Contact: ${e.preferredContactMethod||"N/A"}`,e.legalRepresentation?.hasLawyer?`Yes (${e.legalRepresentation.lawyerName||"N/A"})`:"No",e.additionalContacts?.map(e=>`${e.name||"N/A"} (${e.relationship||"N/A"})`).join(", ")||"N/A",String(e.status||"pending"),e.date?new Date(e.date).toLocaleString():"",e.reviewedAt?new Date(e.reviewedAt).toLocaleString():""]);(0,i.default)(o,{head:[["Name","Email","Phone","Birth Date","Relationship","Address","Detainee Info","Preferences","Legal Rep","Additional Contacts","Status","Registration Date","Reviewed At"]],body:l,startY:25,styles:{fontSize:7,cellPadding:2,overflow:"linebreak",cellWidth:"wrap",lineColor:[200,200,200],lineWidth:.1},alternateRowStyles:{fillColor:[245,245,245]},columnStyles:{0:{cellWidth:20},1:{cellWidth:25},2:{cellWidth:18},3:{cellWidth:18},4:{cellWidth:18},5:{cellWidth:35},6:{cellWidth:35},7:{cellWidth:20},8:{cellWidth:20},9:{cellWidth:35},10:{cellWidth:15},11:{cellWidth:22},12:{cellWidth:22}},headStyles:{fillColor:[41,128,185],textColor:255,fontSize:7,fontStyle:"bold",halign:"center"},bodyStyles:{halign:"left",valign:"middle"},margin:{top:25},didDrawPage:function(e){o.setFontSize(8),o.text(`Page ${e.pageNumber}`,e.settings.margin.left,o.internal.pageSize.height-10)}}),t&&n.forEach(e=>{if(e.notes&&Array.isArray(e.notes)&&e.notes.length>0){o.addPage(),o.setFontSize(14),o.text(`Notes for ${e.name||"Unknown"}`,14,15);let t=e.notes.map(e=>[String(e.content||""),String(e.createdBy||""),e.createdAt?new Date(e.createdAt).toLocaleString():""]);(0,i.default)(o,{head:[["Note","Created By","Created At"]],body:t,startY:25,styles:{fontSize:8,cellPadding:2,overflow:"linebreak",cellWidth:"wrap",lineColor:[200,200,200],lineWidth:.1},alternateRowStyles:{fillColor:[245,245,245]},columnStyles:{0:{cellWidth:120},1:{cellWidth:30},2:{cellWidth:40}},headStyles:{fillColor:[41,128,185],textColor:255,fontSize:8,fontStyle:"bold",halign:"center"},bodyStyles:{halign:"left",valign:"middle"},margin:{top:25}})}});let s=o.output("arraybuffer");if(!s||0===s.byteLength)throw Error("Failed to generate PDF content");a.setHeader("Content-Type","application/pdf"),a.setHeader("Content-Disposition","attachment; filename=registrations.pdf"),a.setHeader("Content-Length",s.byteLength),a.status(200).send(Buffer.from(s))}catch(e){console.error("PDF export error:",e),a.status(500).json({error:"Failed to generate PDF",details:e instanceof Error?e.message:"Unknown error"})}}(u,!!g,0,t);var n=u,a=0,o=0,s=t;let m=n.map(e=>[e.name,e.email,e.phone,e.relationship,e.message,new Date(e.date).toLocaleString(),e.status,e.reviewedBy||"",e.reviewedAt?new Date(e.reviewedAt).toLocaleString():""]),y=["Name,Email,Phone,Relationship,Message,Date,Status,Reviewed By,Reviewed At",...m.map(e=>e.join(","))].join("\n");s.setHeader("Content-Type","text/csv"),s.setHeader("Content-Disposition","attachment; filename=registrations.csv"),s.send(y);return}catch(e){return console.error("Export error:",e),t.status(500).json({message:"Error exporting data"})}}a()}catch(e){a(e)}})},8667:(e,t)=>{Object.defineProperty(t,"A",{enumerable:!0,get:function(){return n}});var n=function(e){return e.PAGES="PAGES",e.PAGES_API="PAGES_API",e.APP_PAGE="APP_PAGE",e.APP_ROUTE="APP_ROUTE",e.IMAGE="IMAGE",e}({})},25300:(e,t,n)=>{n.a(e,async(e,a)=>{try{n.r(t),n.d(t,{config:()=>c,default:()=>d,routeModule:()=>g});var r=n(33480),i=n(8667),o=n(86435),l=n(238),s=e([l]);l=(s.then?(await s)():s)[0];let d=(0,o.M)(l,"default"),c=(0,o.M)(l,"config"),g=new r.PagesAPIRouteModule({definition:{kind:i.A.PAGES_API,page:"/api/admin/export",pathname:"/api/admin/export",bundlePath:"",filename:""},userland:l});a()}catch(e){a(e)}})},29021:e=>{e.exports=require("fs")},33480:(e,t,n)=>{e.exports=n(75600)},33873:e=>{e.exports=require("path")},65515:e=>{e.exports=require("jspdf")},75600:e=>{e.exports=require("next/dist/compiled/next-server/pages-api.runtime.prod.js")},83501:e=>{e.exports=import("jspdf-autotable")},86435:(e,t)=>{Object.defineProperty(t,"M",{enumerable:!0,get:function(){return function e(t,n){return n in t?t[n]:"then"in t&&"function"==typeof t.then?t.then(t=>e(t,n)):"function"==typeof t&&"default"===n?t:void 0}}})}};var t=require("../../../webpack-api-runtime.js");t.C(e);var n=t(t.s=25300);module.exports=n})();