Add Spring event sign-up page (with consent form prompt) and responses admin page.
authorSam White <webmaster@ycra.org.uk>
Mon, 11 Apr 2022 20:02:22 +0000 (20:02 +0000)
committerSam White <webmaster@ycra.org.uk>
Mon, 11 Apr 2022 20:02:22 +0000 (20:02 +0000)
public_html/docs/consent-form.docx [new file with mode: 0644]
public_html/login.php
public_html/spring-event-responses.php [new file with mode: 0644]
public_html/spring-event.php [new file with mode: 0644]

diff --git a/public_html/docs/consent-form.docx b/public_html/docs/consent-form.docx
new file mode 100644 (file)
index 0000000..f701da4
Binary files /dev/null and b/public_html/docs/consent-form.docx differ
index 67d0f223eeb6d944ad307643aa19730580a699ed..d66d42c1d0ab8688f5028703d4c766309b04c344 100644 (file)
@@ -43,9 +43,11 @@ function content() {
     if ($uid) {
       esc('Login successful!.');
       $_SESSION['user'] = $uid;?>
-      <p>Click <a <?php href('members.php');?>>here</a> to view the membership list.</p>
-      <p>Click <a <?php href('winter-event-responses.php');?>>here</a> to view 
-      the responses for the winter event.</p><?php
+      <ul>
+        <li><a <?php href('members.php');?>>Membership list</a></li>
+        <li><a <?php href('spring-event-responses.php');?>>Spring event responses</a></li>
+        <li><a <?php href('winter-event-responses.php');?>>Winter event responses</a></li>
+      </ul><?php
       return;
     }
     $params['email_address'] = $_POST['email_address'];
diff --git a/public_html/spring-event-responses.php b/public_html/spring-event-responses.php
new file mode 100644 (file)
index 0000000..55a3c2f
--- /dev/null
@@ -0,0 +1,103 @@
+<?php
+require_once('includes/utils.php');
+require_once('includes/html-templating.php');
+require_once('includes/database.php');
+require_once('includes/auth.php');
+
+session_start();
+
+function page_title() {
+  return 'Members list';
+}
+
+function content() {
+  if (!check_logged_in()) {?>
+    <h1>Restricted access page</h1><?php
+    return;
+  }?>
+
+  <h1>YCRA Spring Event Responses</h1>
+
+  <p>Below is a list of the spring event ticket form responses (ordered by most
+  recent first).</p>
+
+  <p>Click <a <?php href('spring-event-responses.php?csv=emails');?>>here</a> to download a CSV
+  file containing the email addresses of all members that have replied to this form.</p>
+
+  <p>Click <a <?php href('spring-event-responses.php?csv=responses');?>>here</a>
+  to download a CSV file containing the responses to this form.</p>
+
+  <p>Please note this is still a work in progress.</p><?php
+
+  $result = run_sql('SELECT members.first_name,members.surname,members.email_address,EXISTS(SELECT member_id FROM event_tickets WHERE member_id=members.id AND event_id=1) AS at_winter_event,event_tickets.* FROM event_tickets JOIN members ON members.id=member_id WHERE event_id=2 ORDER BY event_tickets.date_added DESC');
+  $members_num = 0;?>
+
+  <table>
+    <tr>
+      <th>Name</th>
+      <th>Email address</th>
+      <th>Date replied</th>
+      <th>Accompanying Adults</th>
+      <th>Ringing Level</th>
+      <th>Completed Consent form</th>
+      <th>At Winter event</th>
+    </tr><?php
+    while ($member = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+      $members_num++;?>
+      <tr>
+        <td><?php esc($member['first_name'] . ' ' . $member['surname']);?></td>
+        <td><?php esc($member['email_address']);?></td>
+        <td><?php
+          esc($member['date_added']
+                      ? date('j M Y', strtotime($member['date_added']))
+                      : '');?>
+        </td><?php
+        $details = json_decode($member['details'], true);
+        foreach ($details as $d) {?>
+          <td><?php if ($d) echo nl2br(esc_str($d));?></td><?php
+        }?>
+        <td><?php esc($member['at_winter_event'] ? 'Yes' : 'No');?></td>
+      </tr><?php
+    }?>
+  </table><?php
+
+  esc('Total number of responses: ' . $members_num);
+}
+
+if (!empty($_GET['csv']) && $_GET['csv'] == 'emails' && check_logged_in()) {
+  $result = run_sql('SELECT members.email_address FROM event_tickets JOIN members ON members.id=member_id WHERE event_id=2 ORDER BY event_tickets.date_added DESC');
+
+  header('Content-Type: text/csv');
+  header('Content-Disposition: inline; filename="ycra-spring-event-2022-member-emails.csv"');
+
+  while ($member = mysqli_fetch_array($result, MYSQLI_ASSOC))
+    esc($member['email_address'] . ',');
+
+  exit;
+}
+
+if (!empty($_GET['csv']) && $_GET['csv'] == 'responses' && check_logged_in()) {
+  $result = run_sql('SELECT members.first_name,members.surname,members.email_address,EXISTS(SELECT member_id FROM event_tickets WHERE member_id=members.id AND event_id=1) AS at_winter_event,event_tickets.* FROM event_tickets JOIN members ON members.id=member_id WHERE event_id=2 ORDER BY event_tickets.date_added DESC');
+
+  header('Content-Type: text/csv');
+  header('Content-Disposition: inline; filename="ycra-spring-event-2022-responses.csv"');
+
+  echo '"First name","Surname","Email address","Response date","Accompanying Adults",'
+      .'"Ringing level","Consent form filled-in","At Winter Event"'."\n";
+  while ($member = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
+    esc($member['first_name'] . ',');
+    esc($member['surname'] . ',');
+    esc($member['email_address'] . ',');
+    esc($member['date_added'] ? date('j M Y', strtotime($member['date_added'])) : '');
+    esc(',');
+    $details = json_decode($member['details'], true);
+    foreach ($details as $d)
+      echo '"'.str_replace('"','\'',$d).'",';
+    esc($member['at_winter_event'] ? 'Yes' : 'No');
+    esc("\n");
+  }
+  exit;
+}
+
+require_once('includes/template.php');
+?>
diff --git a/public_html/spring-event.php b/public_html/spring-event.php
new file mode 100644 (file)
index 0000000..f852e8d
--- /dev/null
@@ -0,0 +1,120 @@
+<?php
+require_once('includes/utils.php');
+require_once('includes/html-templating.php');
+require_once('includes/fields.php');
+require_once('includes/forms.php');
+require_once('includes/form-validation.php');
+require_once('includes/database.php');
+
+function validate_submission(&$errors, $data) {
+  if (validate_email_address($errors, $data['email_address'])) {
+    if (!record_exists('members', simple_where('email_address', $data['email_address'])))
+      $errors[] = 'Please enter the email address you used to sign up for membership. '
+                . 'If you have forgotten this email address, please contact us at events@ycra.org.uk so we can assist you.';
+  }
+  if (empty($data['consent']) && !array_key_exists('confirm', $data))
+    $errors[] = 'You must give your consent for us to process your data.';
+
+  return empty($errors);
+}
+
+function page_title() { return 'Spring Event Tickets'; }
+
+function additional_stylesheets() { stylesheet('fields'); }
+
+function content() {?>
+  <h1>Spring event tickets</h1>
+
+  <?php
+  $errors = $params = [];
+
+  if (array_key_exists('ticket', $_POST)) {
+    if (validate_submission($errors, $_POST)) {
+      confirm_sent_form_data($_POST, ['email_address', 'accompanying_adults', 'ringing_level',
+                                      'consent_form_completed']);
+      return;
+    }
+  }
+
+  if (array_key_exists('confirm', $_POST) && validate_submission($errors, $_POST)) {
+    $record = fetch_record('members', 'id', simple_where('email_address', $_POST['email_address'])
+                           . ' ORDER BY id DESC LIMIT 1');
+    $id = $record['id'];
+
+    if (record_exists('event_tickets', simple_where('member_id', $id) . ' AND event_id=2')) {?>
+      <p>You have already signed up to this event.</p>
+
+      <p>If you would like to amend the information you previously submitted,
+         please email us at <a href="mailto:events@ycra.org.uk">events@ycra.org.uk</a>.</p><?php
+      return;
+    }
+    foreach (['accompanying_adults', 'ringing_level', 'consent_form_completed'] as $key)
+      if (!empty($_POST[$key])) $details[$key] = $_POST[$key];
+      else $details[$key] = null;
+
+    insert_array('event_tickets',
+                 ['event_id'=>'2','member_id'=>$id,'date_added'=>date('Y-m-d H:i:s'),
+                  'details'=>json_encode($details)]);?>
+    <p>Your details have been submitted successfully.</p><?php
+
+    if (empty($details['consent_form_completed'])) {?>
+      <p>Please download and complete our
+      <a <?php document_href('consent-form.docx');?>>consent form</a>, then send it to
+      <a href="mailto:contact@ycra.org.uk">contact@ycra.org.uk</a> before
+      <b>Wednesday 20th April 2022</b>. You must complete a consent form,
+      irrespective of your age. We require the information you provide in this form to
+      keep you safe at our events.</p>
+
+      <p>You do not need to complete this consent form if you already filled one
+      out and returned it to us previously, for example, at our Winter event in
+      Birmingham.</p><?php
+    }?>
+
+    <p>We will email you with more details about the event soon.</p><?php
+    return;
+  }
+
+  if ($_POST) $params = $_POST;?>
+
+  <p>We will be holding our Spring ringing event in Bristol on Saturday,
+  23rd April 2022.</p>
+
+  <p>Please see the <a <?php href('events.php#spring-event-2022');?>>events page</a>
+  for more information about this event.</p>
+
+  <p>Please use the form below to book your place at this event. It will be free
+  for YCRA members to attend this event.</p>
+
+  <?php show_error_list($errors);?>
+
+  <form method="post" action=""><?php
+    email_field($params, 'email_address',
+                'Email address used for membership sign-up', ['required'=>'']);
+
+    textarea($params, 'accompanying_adults',
+            'Please enter the full names of any adults who will be accompanying you',
+            ['rows'=>'2']);
+
+    textarea($params, 'ringing_level', 'What sorts of things can you currently ring?',
+            ['rows'=>1, 'required'=>'']);
+
+    checkbox_field($params, 'consent_form_completed',
+                   'I have already completed a consent form (e.g. for our Winter event)');?>
+
+    <div class="field">
+      <input type="checkbox" name="consent" id="consent" value="1" />
+      <label for="consent">
+        I agree for the data I submit with this form to be processed in
+        accordance with the
+        <a target="_blank" <?php document_href('privacy-policy-v2.pdf');?>>YCRA privacy policy</a>.
+      </label>
+    </div>
+
+    <input type="submit" name="ticket" value="Request ticket" />
+  </form--><?php
+
+}
+
+
+require_once('includes/template.php');
+?>