diff --git a/site/blueprints/pages/white-papers.yml b/site/blueprints/pages/white-papers.yml index a219c50..d780d71 100644 --- a/site/blueprints/pages/white-papers.yml +++ b/site/blueprints/pages/white-papers.yml @@ -48,62 +48,68 @@ tabs: dataTab: label: Contacts icon: chart - fields: - contactDatabase: - label: Ont téléchargé un livre blanc - type: structure - translate: false - columns: - firstName: - label: Prénom - width: 1/4 - lastName: - label: Nom - width: 1/4 - email: - label: Email - width: 1/4 - company: - label: Entreprise - width: 1/4 - role: - label: Fonction - whitePaper: - label: Livres blancs - downloadedAt: - label: Date + sections: + export: + type: csv-export + contacts: + type: fields fields: - firstName: - label: Prénom - type: text + contactDatabase: + label: Ont téléchargé un livre blanc + type: structure translate: false - required: true - lastName: - label: Nom - type: text - translate: false - required: true - company: - label: Société - type: text - translate: false - role: - label: Fonction - type: text - translate: false - email: - type: email - translate: false - required: true - whitePaper: - label: Livres blancs - type: pages - translate: false - query: site.find('livres-blancs').children - downloadedAt: - type: text - translate: false - label: Date + columns: + firstName: + label: Prénom + width: 1/5 + lastName: + label: Nom + width: 1/5 + email: + label: Email + width: 1/5 + company: + label: Entreprise + width: 1/5 + role: + label: Fonction + width: 1/5 + whitePaper: + label: Livres blancs + downloadedAt: + label: Date + fields: + firstName: + label: Prénom + type: text + translate: false + required: true + lastName: + label: Nom + type: text + translate: false + required: true + company: + label: Société + type: text + translate: false + role: + label: Fonction + type: text + translate: false + email: + type: email + translate: false + required: true + whitePaper: + label: Livres blancs + type: pages + translate: false + query: site.find('livres-blancs').children + downloadedAt: + type: text + translate: false + label: Date files: tabs/files seo: seo/page diff --git a/site/plugins/csv-export/index.css b/site/plugins/csv-export/index.css new file mode 100644 index 0000000..09ad8c1 --- /dev/null +++ b/site/plugins/csv-export/index.css @@ -0,0 +1,3 @@ +.csv-export-btn { + margin-bottom: 2rem; +} diff --git a/site/plugins/csv-export/index.js b/site/plugins/csv-export/index.js new file mode 100644 index 0000000..07ca4c4 --- /dev/null +++ b/site/plugins/csv-export/index.js @@ -0,0 +1,17 @@ +panel.plugin("world-game/csv-export", { + sections: { + "csv-export": { + template: ` + + `, + }, + }, +}); diff --git a/site/plugins/csv-export/index.php b/site/plugins/csv-export/index.php new file mode 100644 index 0000000..0bc5508 --- /dev/null +++ b/site/plugins/csv-export/index.php @@ -0,0 +1,50 @@ + [ + 'csv-export' => [], + ], + + 'routes' => [ + [ + 'pattern' => 'wg-export/contacts', + 'method' => 'GET', + 'action' => function () { + if (!kirby()->user()) { + http_response_code(403); + exit; + } + + $entries = page('livres-blancs')->contactDatabase()->toStructure(); + + header('Content-Type: text/csv; charset=UTF-8'); + header('Content-Disposition: attachment; filename="' . date('ymd') . '-contacts.csv"'); + header('Cache-Control: no-cache'); + + $out = fopen('php://output', 'w'); + fputs($out, "\xEF\xBB\xBF"); // BOM pour Excel + fputcsv($out, ['Prénom', 'Nom', 'Email', 'Entreprise', 'Fonction', 'Livres blancs', 'Date'], ';'); + + foreach ($entries as $entry) { + $titles = []; + foreach ($entry->whitePaper()->toPages() as $wp) { + $titles[] = $wp->title()->value(); + } + + fputcsv($out, [ + $entry->firstName()->value(), + $entry->lastName()->value(), + $entry->email()->value(), + $entry->company()->value(), + $entry->role()->value(), + implode(' | ', $titles), + $entry->downloadedAt()->value(), + ], ';'); + } + + fclose($out); + exit; + }, + ], + ], +]);