function admin_page_actions() { global $EM_Pro, $EM_Notices, $wpdb; if (!empty($_REQUEST['page']) && $_REQUEST['page'] == 'events-manager-forms-editor') { //Load the right form if (isset($_REQUEST['att_form_id'])) { $sql = $wpdb->prepare("SELECT meta_value FROM " . EM_META_TABLE . " WHERE meta_key = 'attendee-form' AND meta_id=%d", $_REQUEST['att_form_id']); $form_data = unserialize($wpdb->get_var($sql)); $EM_Form = self::$form = new EM_Form($form_data['form'], 'em_attendee_form'); self::$form_name = $form_data['name']; self::$form_id = $_REQUEST['att_form_id']; } else { $EM_Form = self::get_form(); if (!self::$form_id) { update_option('em_attendee_form_fields', 0); } } if (!empty($_REQUEST['form_name']) && $EM_Form->form_name == $_REQUEST['form_name'] && empty($_REQUEST['attendee_form_action'])) { //set up booking form field map and save/retreive previous data if ($EM_Form->editor_get_post()) { //Save into DB rather than as an option $booking_form_data = array('name' => self::$form_name, 'form' => $EM_Form->form_fields); $saved = $wpdb->update(EM_META_TABLE, array('meta_value' => serialize($booking_form_data)), array('meta_id' => self::$form_id)); //Update Values if ($saved !== false) { $EM_Notices->add_confirm(__('Changes Saved', 'em-pro')); } elseif (count($EM_Form->get_errors()) > 0) { $EM_Notices->add_error($EM_Form->get_errors()); } } } elseif (!empty($_REQUEST['attendee_form_action'])) { if ($_REQUEST['attendee_form_action'] == 'default' && wp_verify_nonce($_REQUEST['_wpnonce'], 'attendee_form_default')) { //make this booking form the default update_option('em_attendee_form_fields', $_REQUEST['att_form_id']); $EM_Notices->add_confirm(sprintf(__('The form <em>%s</em> is now the default booking form. All events without a pre-defined booking form will start using this form from now on.', 'em-pro'), self::$form_name)); } elseif ($_REQUEST['attendee_form_action'] == 'delete' && wp_verify_nonce($_REQUEST['_wpnonce'], 'attendee_form_delete')) { //load and save booking form object with new name $saved = $wpdb->query($wpdb->prepare("DELETE FROM " . EM_META_TABLE . " WHERE meta_id='%s'", $_REQUEST['att_form_id'])); if ($saved) { self::$form = false; $EM_Notices->add_confirm(sprintf(__('%s Deleted', 'dbem'), __('Booking Form', 'em-pro')), 1); } } elseif ($_REQUEST['attendee_form_action'] == 'rename' && wp_verify_nonce($_REQUEST['_wpnonce'], 'attendee_form_rename')) { //load and save booking form object with new name $booking_form_data = array('name' => wp_kses_data($_REQUEST['form_name']), 'form' => $EM_Form->form_fields); self::$form_name = $booking_form_data['name']; $saved = $wpdb->update(EM_META_TABLE, array('meta_value' => serialize($booking_form_data)), array('meta_id' => self::$form_id)); $EM_Notices->add_confirm(sprintf(__('Form renamed to <em>%s</em>.', 'em-pro'), self::$form_name)); } elseif ($_REQUEST['attendee_form_action'] == 'add' && wp_verify_nonce($_REQUEST['_wpnonce'], 'attendee_form_add')) { //create new form with this name and save first off $EM_Form = new EM_Form(self::$form_template, 'em_attendee_form'); $booking_form_data = array('name' => wp_kses_data($_REQUEST['form_name']), 'form' => $EM_Form->form_fields); self::$form = $EM_Form; self::$form_name = $booking_form_data['name']; $saved = $wpdb->insert(EM_META_TABLE, array('meta_value' => serialize($booking_form_data), 'meta_key' => 'attendee-form', 'object_id' => 0)); self::$form_id = $wpdb->insert_id; if (!get_option('em_attendee_form_fields')) { update_option('em_attendee_form_fields', self::$form_id); } $EM_Notices->add_confirm(__('New form created. You are now editing your new form.', 'em-pro'), true); wp_redirect(add_query_arg(array('att_form_id' => self::$form_id), wp_get_referer())); exit; } } } }
/** * Generates a condensed attendee form for admins, stripping away HTML fields. * @param EM_Attendee_Form $EM_Form * @param int $ticket_id */ public static function admin_form($EM_Form, $ticket_id) { ?> <table class="em-form-fields" cellspacing="0" cellpadding="0"> <?php foreach ($EM_Form->form_fields as $fieldid => $field) { if (!array_key_exists($fieldid, $EM_Form->user_fields) && $field['type'] != 'html') { ?> <tr class="input-group input-<?php echo $field['type']; ?> input-field-<?php echo $field['fieldid']; ?> "> <th><?php echo $field['label']; ?> </th> <td> <?php $value = !empty($EM_Form->field_values[$fieldid]) ? $EM_Form->field_values[$fieldid] : ''; echo str_replace('%T', $ticket_id, $EM_Form->output_field_input($field, $value)); ?> </td> </tr> <?php } } ?> </table> <?php }