--- /dev/null
+<?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 (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 'Winter Event Tickets';
+}
+
+function additional_stylesheets() {
+ stylesheet('fields');
+}
+
+function content() {?>
+ <h1>Winter 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', 'dietary_requirements']);
+ 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=1')) {?>
+ <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', 'dietary_requirements'] as $key)
+ if (!empty($_POST[$key])) $details[$key] = $_POST[$key];
+ else $details[$key] = null;
+
+ insert_array('event_tickets',
+ ['event_id'=>'1','member_id'=>$id,'date_added'=>date('Y-m-d H:i:s'),
+ 'details'=>json_encode($details)]);?>
+ <p>Your details have been submitted successfully.</p>
+ <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 inaugural ringing event in Birmingham on Saturday,
+ 15 January 2022. There will be the opportunity to ring at some great towers in
+ Birmingham, including hopefully ringing on 16 at the bullring!</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, 'dietary_requirements', 'Do you have any dietary requirements?');?>
+
+ <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 <?php href('docs/privacy-policy.pdf');?>>YCRA privacy policy</a>.
+ </label>
+ </div>
+
+ <input type="submit" name="ticket" value="Request ticket" />
+ </form><?php
+
+}
+
+
+require_once('includes/template.php');
+?>