Implement downloading of CSV of members emails and link to members page from login...
authorSam White <webmaster@ycra.org.uk>
Sat, 11 Dec 2021 14:10:39 +0000 (14:10 +0000)
committerSam White <webmaster@ycra.org.uk>
Sat, 11 Dec 2021 14:10:39 +0000 (14:10 +0000)
public_html/login.php
public_html/members.php

index 36c1b393ad2ab05b04145792e5bd1385f229c0f4..b6400a79ba17bcb32fe0d86c615cb9b7c1a9b6a8 100644 (file)
@@ -42,7 +42,8 @@ function content() {
     $uid = validate_login($errors, $_POST);
     if ($uid) {
       esc('Login successful!.');
-      $_SESSION['user'] = $uid;
+      $_SESSION['user'] = $uid;?>
+      <p>Click <a <?php href('members.php');?>>here</a> to view the membership list.</p><?php
       return;
     }
     $params['email_address'] = $_POST['email_address'];
index b1db2aa3877b2fae256a256cb844b45a72843f3d..0cd3f49e10e52128464659cba8beeecc29ce22b3 100644 (file)
@@ -4,9 +4,7 @@ require_once('includes/html-templating.php');
 require_once('includes/database.php');
 require_once('includes/auth.php');
 
-function pre_html() {
-  session_start();
-}
+session_start();
 
 function page_title() {
   return 'Members list';
@@ -24,6 +22,9 @@ function content() {
   tried to submit the membership form more than once (with the same email
   address), only the latest submitted information is shown.</p>
 
+  <p>Click <a <?php href('members.php?csv=emails');?>>here</a> to download a CSV
+  file containing the email addresses of all members.</p>
+
   <p>Please note this is a work in progress and the membership records will be
   fully reconciled at some point.</p><?php
 
@@ -70,5 +71,17 @@ function content() {
   esc('Total number of members: ' . $members_num);
 }
 
+if (!empty($_GET['csv']) && $_GET['csv'] == 'emails' && check_logged_in()) {
+  $result = run_sql('SELECT * FROM members GROUP BY(email_address) ORDER BY id DESC');
+
+  header('Content-Type: text/csv');
+  header('Content-Disposition: inline; filename="ycra-member-emails.csv"');
+
+  while ($member = mysqli_fetch_array($result, MYSQLI_ASSOC))
+    esc($member['email_address'] . ',');
+
+  exit;
+}
+
 require_once('includes/template.php');
 ?>