/**
 * Returns the set of fields defined by the plugin
 *
 * @param string $type 'limited' returns only the fields the admin has
 *   whitelisted. 'all' returns all fields (mainly for Dashboard)
 */
function thatcamp_registrations_fields($type = 'limited')
{
    $fields = array(array('id' => 'first_name', 'name' => __('First Name', 'thatcamp-registrations'), 'required' => true, 'public' => true), array('id' => 'last_name', 'name' => __('Last Name', 'thatcamp-registrations'), 'required' => true, 'public' => true), array('id' => 'user_email', 'name' => __('Email', 'thatcamp-registrations'), 'required' => true, 'public' => false), array('id' => 'description', 'name' => __('Biography', 'thatcamp-registrations'), 'required' => true, 'explanation' => __('Tell us a little about yourself.', 'thatcamp-registrations'), 'type' => 'textarea', 'public' => true), array('id' => 'user_url', 'name' => __('Website', 'thatcamp-registrations'), 'explanation' => __('Example: thatcamp.org', 'thatcamp-registrations'), 'public' => true), array('id' => 'user_twitter', 'name' => __('Twitter Screenname', 'thatcamp-registrations'), 'explanation' => __('Example: @thatcamp', 'thatcamp-registrations'), 'public' => true), array('id' => 'user_title', 'name' => __('Position/Job Title', 'thatcamp-registrations'), 'explanation' => __('Examples: Assistant Professor, Instructional Technologist, Archivist, Software Engineer, Graduate student', 'thatcamp-registrations'), 'public' => true), array('id' => 'user_organization', 'name' => __('Organization', 'thatcamp-registrations'), 'explanation' => __('Examples: George Mason University, New York Public Library, Automattic', 'thatcamp-registrations'), 'public' => true), array('id' => 'discipline', 'name' => __('Discipline', 'thatcamp-registrations'), 'explanation' => __('e.g., Art History, English, Library Science', 'thatcamp-registrations'), 'public' => true), array('id' => 'days_attending', 'name' => __('Days Attending', 'thatcamp-registrations'), 'explanation' => __('Which days do you plan to attend this THATCamp?', 'thatcamp-registrations'), 'public' => false, 'type' => 'select', 'options' => array(array('value' => 'all', 'text' => __('All days', 'thatcamp-registrations')), array('value' => 'first-day', 'text' => __('First day only', 'thatcamp-registrations')), array('value' => 'second-day', 'text' => __('Second day only', 'thatcamp-registrations')))), array('id' => 'technology_skill_level', 'name' => __('Technology Skill Level', 'thatcamp-registrations'), 'explanation' => __('I consider my technology skill level to be:', 'thatcamp-registrations'), 'public' => false, 'type' => 'select', 'options' => array(array('value' => '', 'text' => __('Select an answer', 'thatcamp-registrations')), array('value' => 'beginner', 'text' => __('Beginner (interested in learning more)', 'thatcamp-registrations')), array('value' => 'intermediate', 'text' => __('Intermediate (can get things up on the web)', 'thatcamp-registrations')), array('value' => 'advanced', 'text' => __('Advanced (can code)', 'thatcamp-registrations'))), 'checked' => false), array('id' => 'tshirt_size', 'name' => __('T-shirt Size', 'thatcamp-registrations'), 'public' => false, 'type' => 'select', 'options' => array(array('value' => '', 'text' => __('Select a t-shirt size', 'thatcamp-registrations')), array('value' => 'mens_xs', 'text' => __('Men\'s XS - Chest 30-32', 'thatcamp-registrations')), array('value' => 'mens_s', 'text' => __('Men\'s S - Chest 34-36', 'thatcamp-registrations')), array('value' => 'mens_m', 'text' => __('Men\'s M - Chest 38-40', 'thatcamp-registrations')), array('value' => 'mens_l', 'text' => __('Men\'s L - Chest 42-44', 'thatcamp-registrations')), array('value' => 'mens_xl', 'text' => __('Men\'s XL - Chest 46-48', 'thatcamp-registrations')), array('value' => 'mens_xxl', 'text' => __('Men\'s XXL - Chest 50-52', 'thatcamp-registrations')), array('value' => 'mens_xxxl', 'text' => __('Men\'s XXXL - Chest 54-55', 'thatcamp-registrations')), array('value' => 'womens_xs', 'text' => __('Women\'s XS - Chest 32-33', 'thatcamp-registrations')), array('value' => 'womens_s', 'text' => __('Women\'s S - Chest 34-35', 'thatcamp-registrations')), array('value' => 'womens_m', 'text' => __('Women\'s M - Chest 36-37', 'thatcamp-registrations')), array('value' => 'womens_l', 'text' => __('Women\'s L - Chest 38-40', 'thatcamp-registrations')), array('value' => 'womens_xl', 'text' => __('Women\'s XL - Chest 41-44', 'thatcamp-registrations')), array('value' => 'womens_xxl', 'text' => __('Women\'s XXL - Chest 45-47', 'thatcamp-registrations'))), 'checked' => false), array('id' => 'children', 'name' => __('Children', 'thatcamp-registrations'), 'explanation' => __('Kids are welcome! Let us know how many you plan to bring.', 'thatcamp-registrations'), 'public' => false, 'checked' => false), array('id' => 'particular_needs', 'name' => __('Particular Needs', 'thatcamp-registrations'), 'explanation' => __('If you have dietary, language, spatial, accessibility, or other needs, please describe them here. We will make every effort to accommodate you.', 'thatcamp-registrations'), 'public' => false, 'type' => 'textarea'));
    if ('limited' == $type) {
        $limited = thatcamp_registrations_selected_fields();
        foreach ($fields as $field_key => $field) {
            if (empty($field['required']) && !in_array($field['id'], $limited)) {
                unset($fields[$field_key]);
            }
        }
        $fields = array_values($fields);
    }
    return $fields;
}
        function settings_display()
        {
            if (isset($_POST['thatcamp_registrations_save_changes'])) {
                $newOptions = array('open_registration' => $_POST['open_registration'], 'pending_application_email' => $_POST['pending_application_email'], 'approved_application_email' => $_POST['approved_application_email'], 'rejected_application_email' => $_POST['rejected_application_email']);
                $admin_notify_emails = $_POST['admin_notify_emails'];
                $admin_notify_emails = array_map('trim', explode("\n", $admin_notify_emails));
                $newOptions['admin_notify_emails'] = $admin_notify_emails;
                update_option('thatcamp_registrations_options', $newOptions);
                $fields = isset($_POST['fields']) ? $_POST['fields'] : array();
                update_option('thatcamp_registrations_selected_fields', $fields);
            }
            $options = thatcamp_registrations_options();
            ?>
        <div class="wrap">

            <h2><?php 
            echo _e('Settings for THATCamp Registrations', 'thatcamp-registrations');
            ?>
</h2>
            <h3><?php 
            echo _e('To enable registration, create a registration page and type the shortcode [thatcamp-registration] on the page.');
            ?>
</h3>

            <form action="" method="post">
                <table class="form-table">
                    <tr valign="top">
                        <th scope="row"><label for="open_registration"><?php 
            _e('Open registration?', 'thatcamp-registrations');
            ?>
</label></th>
                        <td>
                            <select name="open_registration">
                                <option value="0"><?php 
            _e('No');
            ?>
 </option>
                                <option value="1"<?php 
            if ($options['open_registration'] == 1) {
                echo ' selected="selected"';
            }
            ?>
><?php 
            _e('Yes');
            ?>
 </option>
                            </select>
                            <p class="description"><?php 
            _e('Before you open registration, create a page called (for instance) &#8220;Register&#8221; and type the shortcode &#x5b;thatcamp-registration&#x5d; on the page. When you open registrations, the registration form will be generated on that page. ', 'thatcamp-registrations');
            ?>
</p>
                        </td>
                    </tr>

		    <tr>
                        <th scope="row"><label for="admin_notify_emails"><?php 
            _e('Application notification addresses', 'thatcamp-registrations');
            ?>
</label></th>
                        <td>
                            <textarea name="admin_notify_emails"><?php 
            thatcamp_registrations_application_notification_emails_textarea();
            ?>
</textarea>

                            <p class="description"><?php 
            _e('These addresses will receive a notification whenever a new registration is submitted. One per line.', 'thatcamp-registrations');
            ?>
</p>
                        </td>
                    </tr>

                    <?php 
            /* Removing require login before registering because no one needs that. ?>
               <tr valign="top">
                   <th scope="row"><label for="require_login"><?php _e( 'Require login before registering?', 'thatcamp-registrations' ) ?></label></th>
                   <td>
                       <select name="require_login">
                           <option value="0"><?php _e('No'); ?> </option>
                           <option value="1"<?php if($options['require_login'] == 1) { echo ' selected="selected"';} ?>><?php _e('Yes'); ?> </option>
                       </select>
                       <p class="description"><?php _e('If &#8220;Yes&#8221; users will be required to log in before completing the registration form.'); ?></p>
                   </td>
               </tr>
               <?php */
            ?>


                    <?php 
            /* Removing auto-approve field until this feature works. ?>
               <tr valign="top">
                   <th scope="row"><label for="auto_approve_applications"><?php _e('Automatically approve registrations', 'thatcamp-registrations'); ?></label></th>
                   <td>
                       <input type="text" name="auto_approve_applications" value="<?php echo $options['auto_approve_applications']; ?>" />
                       <p class="description"><?php _e('If you wish THATCamp Registrations to automatically approve a certain number of registrations, fill in that number here. If left blank, or set to 0, no registrations will be automatically approved.', 'thatcamp-registrations'); ?></p>
                   </td>
               </tr>
               <?php */
            ?>
                    <tr valign="top">
                        <th scope="row"><label for="pending_application_email"><?php 
            _e('Pending registration email', 'thatcamp-registrations');
            ?>
</label></th>
                        <td>
                            <textarea name="pending_application_email" id="pending_application_email" rows="5" cols="50"><?php 
            if (!empty($options['pending_application_email'])) {
                echo stripslashes($options['pending_application_email']);
            }
            ?>
</textarea>
                            <p class="description"><?php 
            _e('This e-mail will be sent by the system from an automated account; you may therefore wish to include your own name and e-mail address in the message itself so that users may contact you. The e-mail will be composed in HTML format, so links and e-mail addresses will automatically be hyperlinked, and no additional HTML codes are necessary. If no text is entered, no e-mail will be sent.');
            ?>
</p>
                        </td>
                    </tr>
                    <tr valign="top">
                        <th scope="row"><label for="approved_application_email"><?php 
            _e('Approved registration email', 'thatcamp-registrations');
            ?>
</label></th>
                        <td>
                            <textarea name="approved_application_email" id="approved_application_email" rows="5" cols="50"><?php 
            if (!empty($options['approved_application_email'])) {
                echo stripslashes($options['approved_application_email']);
            }
            ?>
</textarea>
                             <p class="description"><?php 
            _e('This e-mail will be sent by the system from an automated account; you may therefore wish to include your own name and e-mail address in the message itself so that users may contact you. The e-mail will be composed in HTML format, so links and e-mail addresses will automatically be hyperlinked, and no additional HTML codes are necessary. If no text is entered, no e-mail will be sent.');
            ?>
</p>
                        </td>
                    </tr>
                    <tr valign="top">
                        <th scope="row"><label for="rejected_application_email"><?php 
            _e('Rejected registration email', 'thatcamp-registrations');
            ?>
</label></th>
                        <td>
                            <textarea name="rejected_application_email" id="rejected_application_email" rows="5" cols="50"><?php 
            if (!empty($options['rejected_application_email'])) {
                echo stripslashes($options['rejected_application_email']);
            }
            ?>
</textarea>
                            <p class="description"><?php 
            _e('This e-mail will be sent by the system from an automated account; you may therefore wish to include your own name and e-mail address in the message itself so that users may contact you. The e-mail will be composed in HTML format, so links and e-mail addresses will automatically be hyperlinked, and no additional HTML codes are necessary. If no text is entered, no e-mail will be sent.');
            ?>
</p>

                        </td>
                    </tr>

                    <tr valign="top">
                        <th scope="row"><?php 
            _e('Registration fields', 'thatcamp-registrations');
            ?>
</th>
                        <td>
				<?php 
            $fields = thatcamp_registrations_fields('all');
            ?>
				<?php 
            $selected = thatcamp_registrations_selected_fields();
            ?>
				<?php 
            foreach ($fields as $field) {
                ?>
					<?php 
                $checked = !empty($field['required']) || in_array($field['id'], $selected) ? ' checked="checked"' : '';
                $disabled = !empty($field['required']) ? ' disabled="disabled"' : '';
                ?>

					<input type="checkbox" name="fields[]" value="<?php 
                echo esc_attr($field['id']);
                ?>
"<?php 
                echo $checked;
                ?>
 <?php 
                echo $disabled;
                ?>
 /> <?php 
                echo esc_html($field['name']);
                ?>
 <?php 
                if ($disabled) {
                    ?>
<em><?php 
                    _e('(required)', 'thatcamp-registrations');
                    ?>
</em><?php 
                }
                ?>
<br />
				<?php 
            }
            ?>
			</td>
		    </tr>

                    <tr valign="top">
                        <th scope="row"></th>
                        <td>
                            <input type="submit" name="thatcamp_registrations_save_changes" class="button-primary" value="<?php 
            _e('Save Changes');
            ?>
" />
                        </td>
                    </tr>
                </table>
                <br />
            </form>
        </div>
    <?php 
        }