/** * Echos out contact form * * * @todo add provision to not display fields that no longer exist * @version 1.0 * Copyright 2011 Andy Potanin, Usability Dynamics, Inc. <*****@*****.**> */ function draw_form($form_settings) { global $wp_crm, $post; extract($form_settings); $form = $wp_crm['wp_crm_contact_system_data'][$form_slug]; if (empty($form['fields'])) { return false; } WP_CRM_F::force_script_inclusion('jquery-datepicker'); WP_CRM_F::force_script_inclusion('wp_crm_profile_editor'); $wp_crm_nonce = md5(NONCE_KEY . $form_slug); $wpc_form_id = 'wpc_' . $wp_crm_nonce . '_form'; //** Load user object if passed */ if ($use_current_user == 'true') { $current_user = wp_get_current_user(); if (0 == $current_user->ID) { $user_data = false; } else { $user_data = wp_crm_get_user($current_user->ID); } } if ($require_login_for_existing_users) { //** Get array of fields that must be checked to verify if user already exists */ $check_fields = apply_filters('wp_crm_distinct_user_fields', array('user_email')); } ?> <form id="<?php echo $wpc_form_id; ?> " class="wp_crm_contact_form wp_crm_contact_form_<?php echo $form_slug; ?> "> <ul class="wp_crm_contact_form"> <li class="wp_crm_<?php echo $wp_crm_nonce; ?> _first"> <?php /* Span Prevention */ ?> <input type="hidden" name="action" value="process_crm_message" /> <input type="text" name="wp_crm_nonce" value="<?php echo $wp_crm_nonce; ?> " /> <input type="text" name="email" /> <input type="text" name="name" /> <input type="text" name="url" /> <input type="text" name="comment" /> <input type="hidden" name="wp_crm[success_message]" value="<?php echo esc_attr($success_message); ?> " /> <?php if ($user_data) { ?> <input type="hidden" name="wp_crm[user_id]" value="<?php echo $current_user->ID; ?> " /> <?php } ?> <?php /* Span Prevention */ ?> </li> <?php $tabindex = 1; foreach ($form['fields'] as $field) { $this_attribute = $wp_crm['data_structure']['attributes'][$field]; $this_attribute['autocomplete'] = 'false'; if ($user_data && $user_data[$field]) { $values = $user_data[$field]; } else { $values = false; } ?> <li class="wp_crm_form_element <?php echo $this_attribute['required'] == 'true' ? 'wp_crm_required_field' : ''; ?> wp_crm_<?php echo $field; ?> _container"> <label class="wp_crm_input_label"><?php echo $this_attribute['title']; ?> </label> <div class="wp_crm_input_wrapper"> <?php if ($display_notes && $this_attribute['input_type'] != 'text') { ?> <span class="wp_crm_attribute_note"><?php echo nl2br($this_attribute['description']); ?> </span><?php } ?> <?php echo WP_CRM_F::user_input_field($field, $values, $this_attribute, $user_data, "tabindex={$tabindex}"); ?> <?php if ($display_notes && $this_attribute['input_type'] == 'text') { ?> <span class="wp_crm_attribute_note"><?php echo nl2br($this_attribute['description']); ?> </span><?php } ?> <span class="wp_crm_error_messages"></span> </div> </li> <?php $tabindex++; } ?> <?php if ($form['message_field'] == 'on') { ?> <li class="wp_crm_form_element wp_crm_message_field "> <div class="wp_crm_input_wrapper"> <?php echo WP_CRM_F::user_input_field('message_field', false, array('input_type' => 'textarea'), $user_data, "tabindex={$tabindex}"); ?> </div> </li> <?php } ?> <li class="wp_crm_form_response"><div class="wp_crm_response_text" style="display:none;"></li> <li class="wp_crm_submit_row"> <div class="wp_crm_input_wrapper"> <input class="<?php echo md5($wp_crm_nonce . '_submit'); ?> " type="submit" value="<?php echo $submit_text; ?> " /> </div> <input type="hidden" name="form_slug" value="<?php echo md5($form_slug); ?> " /> <input type="hidden" name="associated_object" value="<?php echo $post->ID; ?> " /> </li> </ul> </form> <style type="text/css">.wp_crm_<?php echo $wp_crm_nonce; ?> _first {display:none;}</style> <script type="text/javascript"> jQuery(document).ready(function() { if(typeof wp_crm_developer_log != 'function') { function wp_crm_developer_log() {} } if(typeof _gaq != 'object') { var _gaq = false; } if(_gaq) { _gaq.push(['_trackEvent', "Contact Form", "Viewed", "<?php echo esc_attr($form['title']); ?> "]); } var this_form = jQuery("#<?php echo $wpc_form_id; ?> "); var submit_button = jQuery("input[type=submit]", this_form); var form_response_field = jQuery(".wp_crm_form_response div", this_form); var this_form_data = {}; var validation_error = false; jQuery(this_form).change(function(event) { if(this_form_data.start_form == undefined) { this_form_data.start_form = event.timeStamp; } if(_gaq && this_form_data.interaction_logged !== undefined) { _gaq.push(['_trackEvent', "Contact Form", "Interacted With", "<?php echo esc_attr($form['title']); ?> "]); this_form_data.interaction_logged = true; } }); jQuery(this_form).submit(function(event) { event.preventDefault(); submit_this_form(); }); jQuery(submit_button).click(function(event) { event.preventDefault(); submit_this_form(); }); <?php if ($require_login_for_existing_users) { foreach ($check_fields as $attribute_slug) { ?> jQuery(".wp_crm_<?php echo $attribute_slug; ?> _field", this_form).change(function() { validation_error = true; submit_this_form('system_validate', this); }); <?php } ?> <?php } ?> function submit_this_form(crm_action, trigger_object) { var validation_error = false; var form = this_form; wp_crm_developer_log('submit_this_form() initiated.'); if(typeof wp_crm_save_user_form == 'function') { /* passed form object into wp_crm_save_user_form() is not usable */ if(!wp_crm_save_user_form(jQuery(form))) { return false; } } else { wp_crm_developer_log('wp_crm_save_user_form() function does not exist.'); } jQuery("*", form).removeClass(form).removeClass("wp_crm_input_error"); jQuery("span.wp_crm_error_messages", form).removeClass(form).text(""); <?php if (isset($form_settings['js_validation_function'])) { ?> /** Custom validation */ if(!validation_error){ t = <?php echo $form_settings['js_validation_function']; ?> (form); if(!t) { validation_error = true; } } <?php } ?> if(validation_error) { jQuery(submit_button).removeAttr("disabled"); return false; } params = jQuery(this_form).serialize(); if(crm_action != 'system_validate') { jQuery(submit_button).attr("disabled", "disabled"); jQuery(form_response_field).show(); jQuery(form_response_field).removeClass('success'); jQuery(form_response_field).removeClass('failure'); jQuery(form_response_field).text("<?php _e('Processing...', 'wp_crm'); ?> "); } if(crm_action) { params = params + "&crm_action=" + crm_action; } jQuery(submit_button).attr("disabled", "disabled"); jQuery.ajax({ url: "<?php echo admin_url('admin-ajax.php'); ?> ", dataType: "json", data: params, cache: false, success: function(result) { /* Enable submit button in case it was disabled during validation */ jQuery(submit_button).removeAttr("disabled"); /* Get conflicting fields */ if(result.bad_fields !== undefined) { jQuery.each(result.bad_fields, function(field) { /* If check started by a specific object, we only update it */ if(jQuery(trigger_object).hasClass("regular-text") && jQuery(trigger_object).attr("wp_crm_slug") != field) { return; } jQuery("div.wp_crm_"+field+"_div input.regular-text:first", form).addClass("wp_crm_input_error"); jQuery("div.wp_crm_"+field+"_div span.wp_crm_error_messages", form).text(result.bad_fields[field]); }); } /* If doing only a validation, stop here */ if(crm_action == 'system_validate') { if(result.validation_passed == true) { validation_error = true; } else { validation_error = false; } return; } if(result.success == "true") { if(_gaq) { _gaq.push(['_trackEvent', "Contact Form: <?php echo esc_attr($form['title']); ?> ", "Submitted", "Total Time", (+new Date) - this_form_data.start_time]); } jQuery(form_response_field).addClass("success"); jQuery(submit_button).removeAttr("disabled"); } else { if(_gaq) { _gaq.push(['_trackEvent', "Contact Form: <?php echo esc_attr($form['title']); ?> ", "Submission Failure", result.message]); this_form_data.interaction_logged = true; } jQuery(form_response_field).addClass("failure"); jQuery(submit_button).removeAttr("disabled"); } <?php if ($js_callback_function) { ?> if(typeof <?php echo $js_callback_function; ?> == 'function') { callback_data = {}; callback_data.form = jQuery("#<?php echo $wpc_form_id; ?> "); callback_data.result = result; <?php echo $js_callback_function; ?> (callback_data); } <?php } ?> jQuery(form_response_field).text(result.message); }, error: function(result) { jQuery(form_response_field).show(); jQuery(form_response_field).addClass("failure"); jQuery(form_response_field).text("<?php _e('A server error occurred while trying to process the form.', 'wp_crm'); ?> "); jQuery(form_response_field).addClass("failure"); jQuery(submit_button).removeAttr("disabled"); if(_gaq) { _gaq.push(['_trackEvent', "Contact Form: <?php echo esc_attr($form['title']); ?> ", "Submission Failure", "Server error."]); this_form_data.interaction_logged = true; } } }); } }); </script> <?php }
/** * Render custom attributes metabox * @global array $wp_crm * @param array $post * @param array $metabox * @return null * @author korotkov@ud * @todo Maybe we can use crm_page_wp_crm_add_new::primary_information function for this because they are similar */ static function custom_group_metabox($post, $metabox) { global $wp_crm; if (empty($metabox['args']['fields']) && !is_array($metabox['args']['fields'])) { return; } $user_role = WP_CRM_F::get_first_value($post['role']); ?> <table class="form-table"> <?php if (!empty($wp_crm['data_structure']) && is_array($wp_crm['data_structure']['attributes'])) { ?> <?php foreach ($metabox['args']['fields'] as $slug => $attribute) { $row_classes = array(); $row_classes[] = @$attribute['has_options'] ? 'wp_crm_has_options' : 'wp_crm_no_options'; $row_classes[] = @$attribute['required'] == 'true' ? 'wp_crm_required_field' : ''; $row_classes[] = @$attribute['primary'] == 'true' ? 'primary' : 'not_primary'; $row_classes[] = !empty($wp_crm['hidden_attributes'][$user_role]) && is_array($wp_crm['hidden_attributes'][$user_role]) && in_array($slug, $wp_crm['hidden_attributes'][$user_role]) ? 'hidden' : ''; $row_classes[] = 'wp_crm_user_entry_row'; $row_classes[] = "wp_crm_{$slug}_row"; $continue = apply_filters("wp_crm_before_{$slug}_frontend", array('continue' => false, 'values' => $post[$slug], 'attribute' => $attribute, 'args' => $metabox['args'])); if ($continue['continue']) { continue; } ?> <tr meta_key="<?php echo esc_attr($slug); ?> " wp_crm_input_type="<?php echo esc_attr($attribute['input_type']); ?> " class="<?php echo implode(' ', $row_classes); ?> "> <th> <?php if (@$attribute['input_type'] != 'checkbox' || isset($attribute['options'])) { ?> <?php ob_start(); ?> <label for="wp_crm_<?php echo $slug; ?> _field"> <?php echo $attribute['title']; ?> </label> <div class="wp_crm_description"><?php echo $attribute['description']; ?> </div> <?php $label = ob_get_contents(); ob_end_clean(); ?> <?php echo apply_filters('wp_crm_user_input_label', $label, $slug, $attribute, $post); ?> <?php } ?> </th> <td class="wp_crm_user_data_row" wp_crm_attribute="<?php echo $slug; ?> "> <div class="blank_slate hidden" show_attribute="<?php echo $slug; ?> "><?php echo !empty($attribute['blank_message']) ? $attribute['blank_message'] : "Add {$attribute['title']}"; ?> </div> <?php echo WP_CRM_F::user_input_field($slug, $post[$slug], $attribute, $post); ?> <?php if (isset($attribute['allow_multiple']) && $attribute['allow_multiple'] == 'true') { ?> <div class="add_another"><?php _('Add Another'); ?> </div> <?php } ?> </td> </tr> <?php do_action("wp_crm_after_{$slug}", array('values' => !empty($values) ? $values : false, 'attribute' => $attribute, 'user_object' => !empty($user_object) ? $user_object : false, 'args' => !empty($args) ? $args : array())); } ?> <?php } ?> </table> <?php }
/** * * @global type $wp_crm * @param type $user_object */ static function primary_information($user_object) { global $wp_crm; $user_role = WP_CRM_F::get_first_value(!empty($user_object['role']) ? $user_object['role'] : array()); ?> <table class="form-table"> <?php if (isset($_GET['user_id'])) { $user_id = $_GET['user_id']; $user_info = get_user_meta($user_id); $stripe_id = $user_info['stripe_customer_id'][0]; ?> <h2>Order History</h2> <tr> <td><strong>Order No.</strong></td> <td><strong>Order Date</strong></td> <td><strong>Status</strong></td> <td><strong>Tracking #</strong></td> </tr> <?php $boxes = get_user_boxes($user_id); foreach ($boxes as $box) { ?> <tr> <td><?php echo $box['order_id']; ?> </td> <td><?php echo $box['date_requested']; ?> </td> <td><?php echo $box['ship_status']; ?> </td> <td><?php if ($box['tracking_id'] == '') { if ($box['ship_status'] == 'Awaiting Shipment') { echo 'N/A'; } else { $_SESSION['order_id'] = $box['order_id']; $_SESSION['user_id'] = $user_id; $_SESSION['date_requested'] = $box['date_requested']; ?> <a href="/process-shipments.php" class="button add-new-h2"><?php _e('Sync Shipment', 'wp_crm'); ?> </a> <?php } } else { echo $box['tracking_id']; } ?> </td> </tr> <?php } } ?> </table> <table class="form-table"> <?php if (!empty($wp_crm['data_structure']) && is_array($wp_crm['data_structure']['attributes'])) { ?> <?php foreach (apply_filters('wp_crm_primary_information_attributes', $wp_crm['data_structure']['attributes']) as $slug => $attribute) { /* we already have an Actions box to change user pass, so we can just skip it here */ if ($slug == 'user_pass') { continue; } $row_classes = array(); $row_classes[] = @$attribute['has_options'] ? 'wp_crm_has_options' : 'wp_crm_no_options'; $row_classes[] = @$attribute['required'] == 'true' ? 'wp_crm_required_field' : ''; $row_classes[] = @$attribute['primary'] == 'true' ? 'primary' : 'not_primary'; $row_classes[] = !empty($wp_crm['hidden_attributes'][$user_role]) && is_array($wp_crm['hidden_attributes'][$user_role]) && in_array($slug, $wp_crm['hidden_attributes'][$user_role]) ? 'hidden' : ''; $row_classes[] = 'wp_crm_user_entry_row'; $row_classes[] = "wp_crm_{$slug}_row"; ?> <tr meta_key="<?php echo esc_attr($slug); ?> " wp_crm_input_type="<?php echo esc_attr($attribute['input_type']); ?> " class="<?php echo implode(' ', $row_classes); ?> "> <th> <?php ob_start(); ?> <label for="wp_crm_<?php echo $slug; ?> _field"> <?php echo $attribute['title']; ?> </label> <div class="wp_crm_description"><?php echo !empty($attribute['description']) ? $attribute['description'] : ''; ?> </div> <?php $label = ob_get_contents(); ob_end_clean(); ?> <?php echo apply_filters('wp_crm_user_input_label', $label, $slug, $attribute, $user_object); ?> </th> <td class="wp_crm_user_data_row" wp_crm_attribute="<?php echo $slug; ?> "> <div class="blank_slate hidden" show_attribute="<?php echo $slug; ?> "><?php echo !empty($attribute['blank_message']) ? $attribute['blank_message'] : "Add {$attribute['title']}"; ?> </div> <?php echo WP_CRM_F::user_input_field($slug, !empty($user_object[$slug]) ? $user_object[$slug] : '', $attribute, $user_object); ?> <?php if (isset($attribute['allow_multiple']) && $attribute['allow_multiple'] == 'true') { ?> <div class="add_another"><?php _('Add Another'); ?> </div> <?php } ?> </td> </tr> <?php } ?> <?php } ?> </table> <!--<table class="form-table"> <?php if (isset($_GET['user_id'])) { $user_id = $_GET['user_id']; $user_info = get_user_meta($user_id); $stripe_id = $user_info['stripe_customer_id'][0]; ?> <h2>Order History</h2> <tr> <td><strong>Order No.</strong></td> <td><strong>Order Date</strong></td> <td><strong>Status</strong></td> <td><strong>Tracking #</strong></td> </tr> <?php $boxes = get_user_boxes($user_id); foreach ($boxes as $box) { ?> <tr> <td><?php echo $box['order_id']; ?> </td> <td><?php echo $box['date_requested']; ?> </td> <td><?php echo $box['ship_status']; ?> </td> <td><?php echo $box['tracking_id']; ?> </td> </tr> <?php } } ?> </table>--> <?php }
function primary_information($user_object) { global $wp_crm; $user_role = WP_CRM_F::get_first_value($user_object['role']); ?> <table class="form-table"> <?php if (!empty($wp_crm['data_structure']) && is_array($wp_crm['data_structure']['attributes'])) { ?> <?php foreach ($wp_crm['data_structure']['attributes'] as $slug => $attribute) { $row_classes = array(); $row_classes[] = @$attribute['has_options'] ? 'wp_crm_has_options' : 'wp_crm_no_options'; $row_classes[] = @$attribute['required'] == 'true' ? 'wp_crm_required_field' : ''; $row_classes[] = @$attribute['primary'] == 'true' ? 'primary' : 'not_primary'; $row_classes[] = is_array($wp_crm['hidden_attributes'][$user_role]) && in_array($slug, $wp_crm['hidden_attributes'][$user_role]) ? 'hidden' : ''; $row_classes[] = 'wp_crm_user_entry_row'; $row_classes[] = "wp_crm_{$slug}_row"; ?> <tr meta_key="<?php echo esc_attr($slug); ?> " wp_crm_input_type="<?php echo esc_attr($attribute['input_type']); ?> " class="<?php echo implode(' ', $row_classes); ?> "> <th> <?php if (@$attribute['input_type'] != 'checkbox' || isset($attribute['options'])) { ?> <?php ob_start(); ?> <label for="wp_crm_<?php echo $slug; ?> _field"> <?php echo $attribute['title']; ?> </label> <div class="wp_crm_description"><?php echo $attribute['description']; ?> </div> <?php $label = ob_get_contents(); ob_end_clean(); ?> <?php echo apply_filters('wp_crm_user_input_label', $label, $slug, $attribute, $user_object); ?> <?php } ?> </th> <td class="wp_crm_user_data_row" wp_crm_attribute="<?php echo $slug; ?> "> <div class="blank_slate hidden" show_attribute="<?php echo $slug; ?> "><?php echo !empty($attribute['blank_message']) ? $attribute['blank_message'] : "Add {$attribute['title']}"; ?> </div> <?php echo WP_CRM_F::user_input_field($slug, $user_object[$slug], $attribute, $user_object); ?> <?php if (isset($attribute['allow_multiple']) && $attribute['allow_multiple'] == 'true') { ?> <div class="add_another"><?php _('Add Another'); ?> </div> <?php } ?> </td> </tr> <?php } ?> <?php } ?> </table> <?php }
/** * Render CRM fields on BP edit profile page * * @global object $profile_template * @global object $current_user * @author korotkov@UD */ static function bp_after_profile_field_content() { //** If we are going to edit profile */ if (bp_is_current_action('edit')) { global $profile_template, $current_user; //** Loop through BP fields in current group */ foreach ($profile_template->group->fields as $field_key => $field_value) { //** If field is not CRM field - skip */ if (empty($field_value->source) || $field_value->source != 'wp_crm') { continue; } //** Get current data from CRM */ $user_data = wp_crm_get_user($current_user->ID); //** Attribute title */ ob_start(); ?> <label class="control-label"><?php echo $field_value->attribute['title']; ?> </label> <?php $label = ob_get_contents(); ob_clean(); //** Attribute description */ ob_start(); ?> <p class="help-block"><?php echo $field_value->attribute['description']; ?> </p> <?php $description = ob_get_contents(); ob_clean(); //** Draw title, input and description */ ?> <div class="control-group"> <?php echo apply_filters('bp_wp_crm_profile_field_label', $label); ?> <div class="controls"> <?php echo WP_CRM_F::user_input_field($field_value->slug, $user_data[$field_value->slug], $field_value->attribute, $user_data); echo apply_filters('bp_wp_crm_profile_field_description', $description); ?> </div> </div> <?php //** Remove current custom field from BP fields list so they won't be processed by BP */ unset($profile_template->group->fields[$field_key]); } } }