/**
 * Adds a single registration entry. This is a motley function.
 *
 * @param string The status of the registration record.
 **/
function thatcamp_registrations_add_registration($status = 'pending')
{
    global $wpdb;
    $table = $wpdb->prefix . "thatcamp_registrations";
    $_POST = stripslashes_deep($_POST);
    // The user_id is set to the posted user ID, or null.
    $user_id = isset($_POST['user_id']) ? $_POST['user_id'] : null;
    $applicant_info = array();
    $applicant_fields = wp_list_pluck(thatcamp_registrations_fields(), 'id');
    foreach ($applicant_fields as $field) {
        $applicant_info[$field] = isset($_POST[$field]) ? $_POST[$field] : null;
    }
    $date = isset($_POST['date']) ? $_POST['date'] : null;
    $applicationText = isset($_POST['application_text']) ? $_POST['application_text'] : null;
    // Lets serialize the applicant_info before putting it in the database.
    $applicant_info = maybe_serialize($applicant_info);
    $applicant_email = isset($_POST['user_email']) ? $_POST['user_email'] : null;
    // Check for an existing registration
    $user_exists = false;
    if (!is_null($user_id) && thatcamp_registrations_get_registration_by_user_id($user_id) || thatcamp_registrations_get_registration_by_applicant_email($applicant_email)) {
        $user_exists = true;
    }
    if ($user_exists) {
        return 'You have already submitted your registration.';
    } else {
        $reg_id = $wpdb->insert($table, array('applicant_info' => $applicant_info, 'applicant_email' => $applicant_email, 'application_text' => $applicationText, 'status' => $status, 'date' => $date, 'user_id' => $user_id));
        thatcamp_registrations_send_applicant_email($applicant_email);
        thatcamp_registrations_send_admin_notification($wpdb->insert_id);
    }
}
        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 
        }
        function _user_info_form()
        {
            $fields = thatcamp_registrations_fields();
            $public_fields = array();
            foreach ($fields as $field) {
                if (!empty($field['public'])) {
                    $public_fields[] = '<strong>' . $field['name'] . '</strong>';
                }
            }
            $public_fields = implode(', ', $public_fields);
            // Could be greatly improved if we more deliberately differentiate between cross-camp and per-camp registration fields.
            if (is_user_logged_in()) {
                // An array of fields whose values would be camp-specific.
                $campSpecificFields = array('days_attending', 'technology_skill_level', 'tshirt_size', 'children', 'particular_needs');
                foreach ($fields as $field_key => $field) {
                    if (!in_array($field['id'], $campSpecificFields)) {
                        unset($fields[$field_key]);
                    }
                }
            }
            if (!empty($fields)) {
                ?>

		<fieldset>
			<legend><?php 
                _e('Personal Information', 'thatcamp-registrations');
                ?>
</legend>

			<p class="explanation" style="margin: 1em 0 1em 0; color:crimson;"><?php 
                printf(__('Please note that the following information from your profile may be publicly displayed on this website: your name, biography, field of study, title, institutional affiliation, website, and Twitter handle. No other information will be publicly displayed.', 'thatcamp-registrations'), $public_fields);
                ?>
</p>

			<?php 
                foreach ($fields as $field) {
                    ?>

				<?php 
                    $required = !empty($field['required']);
                    ?>
				<?php 
                    $type = !empty($field['type']) ? $field['type'] : 'text';
                    ?>

				<div>
					<?php 
                    /* LABEL */
                    ?>
					<label for="<?php 
                    echo esc_attr($field['id']);
                    ?>
"><?php 
                    echo esc_html($field['name']);
                    if ($required) {
                        ?>
* (required)<?php 
                    }
                    ?>
</label><br />

					<?php 
                    /* EXPLANATION */
                    ?>
					<?php 
                    if (!empty($field['explanation'])) {
                        ?>
						<p class="explanation"><?php 
                        echo esc_html($field['explanation']);
                        ?>
</p>
					<?php 
                    }
                    ?>

					<?php 
                    /* INPUT */
                    ?>
					<?php 
                    if ('text' == $type) {
                        ?>

						<input type="text" name="<?php 
                        echo esc_attr($field['id']);
                        ?>
" id="<?php 
                        echo esc_attr($field['id']);
                        ?>
" class="textfield" />

					<?php 
                    } elseif ('textarea' == $type) {
                        ?>

						<textarea cols="45" rows="8" name="<?php 
                        echo esc_attr($field['id']);
                        ?>
" id="<?php 
                        echo esc_attr($field['id']);
                        ?>
"></textarea>

					<?php 
                    } elseif ('select' == $type) {
                        ?>

						<select name="<?php 
                        echo esc_attr($field['id']);
                        ?>
" id="<?php 
                        echo esc_attr($field['id']);
                        ?>
">
							<?php 
                        foreach ($field['options'] as $option) {
                            ?>
								<option value="<?php 
                            echo esc_attr($option['value']);
                            ?>
"><?php 
                            echo esc_attr($option['text']);
                            ?>
</option>
							<?php 
                        }
                        ?>
						</select>

					<?php 
                    }
                    ?>
				</div>

			<?php 
                }
                ?>
		</fieldset>

<p>&nbsp;</p>

	<style type="text/css">
		#tcppl { display: none; visibility: hidden; }
	</style>

	<div id="tcppl">
		<label for="tcppl-field"><?php 
                _e("This field should be left blank. It's a trap for spambots.", 'thatcamp-registrations');
                ?>
</label>
		<input type="text" id="tcppl-field" name="tcppl-field" />
	</div>
        <!-- Removed t-shirt size and dietary preferences fields. 10/17/2012 AF -->
    </fieldset>
    <?php 
            }
        }
Beispiel #4
0
/**
 * Filter the ajax_querystring to make the custom member search work
 */
function thatcamp_search_querystring($qs)
{
    global $bp, $wpdb;
    if (bp_is_members_component() && !empty($_GET['msearch'])) {
        $search_terms = esc_sql(like_escape(urldecode($_GET['msearch'])));
        // Find a list of matching members to pass to the 'includes' param
        // Search against: user_nicename as well as the thatcamp profile fields
        $tc_fields = function_exists('thatcamp_registrations_fields') ? thatcamp_registrations_fields('all') : array();
        $tc_fields_keys = array();
        foreach ($tc_fields as $tc_field) {
            if (!empty($tc_field['public'])) {
                $tc_fields_keys[] = "'" . $tc_field['id'] . "'";
            }
        }
        // Two separate searches, because, hey, why not
        $user_nicename_matches = $wpdb->get_col("SELECT ID FROM {$wpdb->users} WHERE user_nicename LIKE '%" . $search_terms . "%' OR display_name LIKE '%" . $search_terms . "%'");
        $user_meta_matches = $wpdb->get_col("SELECT DISTINCT user_id FROM {$wpdb->usermeta} WHERE meta_key IN (" . implode(',', $tc_fields_keys) . ") AND meta_value LIKE '%" . $search_terms . "%'");
        // Merge and sanitize
        $user_ids = wp_parse_id_list(array_unique(array_merge($user_nicename_matches, $user_meta_matches)));
        // Convert to a query arg
        if (!empty($qs)) {
            $qs .= '&';
        }
        $qs .= 'include=' . implode(',', $user_ids);
    }
    return $qs;
}