function dbem_book_seats() { $bookerName = $_POST['bookerName']; $bookerEmail = $_POST['bookerEmail']; $bookerPhone = $_POST['bookerPhone']; $bookedSeats = $_POST['bookedSeats']; $event_id = $_GET['event_id']; $booker = dbem_get_person_by_name_and_email($bookerName, $bookerEmail); if (!$booker) { $booker = dbem_add_person($bookerName, $bookerEmail, $bookerPhone); } if (dbem_are_seats_available_for($event_id, $bookedSeats)) { dbem_record_booking($event_id, $booker['person_id'], $bookedSeats); $result = __('Your booking has been recorded', 'dbem'); $mailing_is_active = get_option('dbem_rsvp_mail_notify_is_active'); if ($mailing_is_active) { dbem_email_rsvp_booking(); } } else { $result = __('Sorry, there aren\'t so many seats available!', 'dbem'); } return $result; }
function dbem_add_person($name, $email, $phone = "") { global $wpdb; $people_table = $wpdb->prefix . PEOPLE_TBNAME; $sql = "INSERT INTO {$people_table} (person_name, person_email, person_phone) VALUES ('{$name}', '{$email}', '{$phone}');"; $wpdb->query($sql); $new_person = dbem_get_person_by_name_and_email($name, $email); return $new_person; }