/** * wpsc_display_form_fields() * * This function displays each of the form fields. Each of them are filterable via 'wpsc_account_form_field_$tag' where tag is permalink-styled name or uniquename. * i.e. First Name under Shipping would be 'wpsc_account_form_field_shippingfirstname' - while Your Billing Details would be filtered * via 'wpsc_account_form_field_your-billing-details'. * * @global <type> $wpdb * @global <type> $user_ID * @global <type> $wpsc_purchlog_statuses * @global <type> $gateway_checkout_form_fields */ function wpsc_display_form_fields() { // Field display and Data saving function global $wpdb, $user_ID, $wpsc_purchlog_statuses, $gateway_checkout_form_fields, $wpsc_checkout; if (empty($wpsc_checkout)) { $wpsc_checkout = new wpsc_checkout(); } $meta_data = wpsc_get_customer_meta('checkout_details'); $meta_data = apply_filters('wpsc_user_log_get', $meta_data, $user_ID); $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' ORDER BY `checkout_set`, `checkout_order`;"; $form_data = $wpdb->get_results($form_sql, ARRAY_A); foreach ($form_data as $form_field) { if (!empty($form_field['unique_name'])) { $ff_tag = $form_field['unique_name']; } else { $ff_tag = esc_html(strtolower(str_replace(' ', '-', $form_field['name']))); } if (!empty($meta_data[$form_field['id']]) && !is_array($meta_data[$form_field['id']])) { $meta_data[$form_field['id']] = esc_html($meta_data[$form_field['id']]); } if ($form_field['type'] == 'heading') { echo "\n <tr>\n <td colspan='2'>\n\r"; echo "<strong>" . apply_filters('wpsc_account_form_field_' . $ff_tag, esc_html($form_field['name'])) . "</strong>"; echo "\n </td>\n </tr>\n\r"; } else { $display = ''; if (in_array($form_field['unique_name'], array('shippingstate', 'billingstate'))) { if ($form_field['unique_name'] == 'shippingstate') { $country_field_id = wpsc_get_country_form_id_by_type('delivery_country'); } else { $country_field_id = wpsc_get_country_form_id_by_type('country'); } $country = is_array($meta_data[$country_field_id]) ? $meta_data[$country_field_id][0] : $meta_data[$country_field_id]; if (wpsc_has_regions($country)) { $display = ' style="display:none;"'; } } echo "\n\t\t <tr{$display}>\n \t\t <td align='left'>\n\r"; echo apply_filters('wpsc_account_form_field_' . $ff_tag, $form_field['name']); if ($form_field['mandatory'] == 1) { echo " *"; } echo "\n \t\t</td>\n\r\n \t\t<td align='left'>\n\r"; switch ($form_field['type']) { case "city": case "delivery_city": echo "<input type='text' value='" . $meta_data[$form_field['id']] . "' name='collected_data[" . $form_field['id'] . "]' />"; break; case "address": case "delivery_address": case "textarea": echo "<textarea name='collected_data[" . $form_field['id'] . "]'>" . $meta_data[$form_field['id']] . "</textarea>"; break; case "text": $value = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : ''; echo "<input type='text' value='" . $value . "' name='collected_data[" . $form_field['id'] . "]' />"; break; case "region": case "delivery_region": echo "<select name='collected_data[" . $form_field['id'] . "]'>" . nzshpcrt_region_list($_SESSION['collected_data'][$form_field['id']]) . "</select>"; break; case "country": if (is_array($meta_data[$form_field['id']])) { $country_code = $meta_data[$form_field['id']][0]; } else { $country_code = $meta_data[$form_field['id']]; } $html_id = 'wpsc-profile-billing-country'; $js = "onchange=\"wpsc_set_profile_country('{$html_id}', '" . $form_field['id'] . "');\""; echo "<select id='{$html_id}' {$js} name='collected_data[" . $form_field['id'] . "][0]' >" . nzshpcrt_country_list($country_code) . "</select>"; if (wpsc_has_regions($country_code)) { $region = isset($meta_data[$form_field['id']][1]) ? $meta_data[$form_field['id']][1] : ''; echo "<br /><select name='collected_data[" . $form_field['id'] . "][1]'>" . nzshpcrt_region_list($country_code, $region) . "</select>"; } break; case "delivery_country": if (is_array($meta_data[$form_field['id']])) { $country_code = $meta_data[$form_field['id']][0]; } else { $country_code = $meta_data[$form_field['id']]; } $html_id = 'wpsc-profile-shipping-country'; $js = "onchange=\"wpsc_set_profile_country('{$html_id}', '" . $form_field['id'] . "');\""; echo "<select id='{$html_id}' {$js} name='collected_data[" . $form_field['id'] . "][0]' >" . nzshpcrt_country_list($country_code) . "</select>"; if (wpsc_has_regions($country_code)) { $region = isset($meta_data[$form_field['id']][1]) ? $meta_data[$form_field['id']][1] : ''; echo "<br /><select name='collected_data[" . $form_field['id'] . "][1]'>" . nzshpcrt_region_list($country_code, $region) . "</select>"; } break; case "email": echo "<input type='text' value='" . $meta_data[$form_field['id']] . "' name='collected_data[" . $form_field['id'] . "]' />"; break; case "select": $options = $wpsc_checkout->get_checkout_options($form_field['id']); $selected = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : null; ?> <select name='collected_data[<?php echo esc_attr($form_field['id']); ?> ]'> <option value="-1"><?php _ex('Select an Option', 'Dropdown default on user log page', 'wp-e-commerce'); ?> </option> <?php foreach ($options as $label => $value) { ?> <option <?php selected($value, $selected); ?> value="<?php echo esc_attr($value); ?> "><?php echo esc_html($label); ?> </option> <?php } ?> </select> <?php break; case 'checkbox': case 'radio': $checked_values = isset($meta_data[$form_field['id']]) ? (array) $meta_data[$form_field['id']] : array(); $options = $wpsc_checkout->get_checkout_options($form_field['id']); $field_name = "collected_data[{$form_field['id']}]"; if ($form_field['type'] == 'checkbox') { $field_name .= '[]'; } foreach ($options as $label => $value) { ?> <label> <input <?php checked(in_array($value, $checked_values)); ?> type="<?php echo $form_field['type']; ?> " id="" name="collected_data[<?php echo esc_attr($form_field['id']); ?> ][]" value="<?php echo esc_attr($value); ?> " /> <?php echo esc_html($label); ?> </label><br /> <?php } break; default: $value = isset($meta_data[$form_field['id']]) ? $meta_data[$form_field['id']] : ''; echo "<input type='text' value='" . $value . "' name='collected_data[" . $form_field['id'] . "]' />"; break; } echo wp_nonce_field('wpsc_user_profile', '_wpsc_user_profile'); echo "\n </td>\n </tr>\n\r"; } } /* Returns an empty array at this point, empty in regards to fields, does show the internalname though. Needs to be reconsidered, even if it did work, need to check * functionality and PCI_DSS compliance if ( isset( $gateway_checkout_form_fields ) ) { echo $gateway_checkout_form_fields; } */ }