Exemple #1
0
 /**
  * form_field method, returns the form html
  * @access public
  */
 function form_field()
 {
     global $wpdb, $user_ID;
     if ($user_ID > 0) {
         if (!isset($_SESSION['wpsc_checkout_saved_values'])) {
             $_SESSION['wpsc_checkout_saved_values'] = get_user_meta($user_ID, 'wpshpcrt_usr_profile', 1);
         }
         $delivery_country_id = wpsc_get_country_form_id_by_type('delivery_country');
         $billing_country_id = wpsc_get_country_form_id_by_type('country');
     }
     $saved_form_data = @htmlentities(stripslashes((string) $_SESSION['wpsc_checkout_saved_values'][$this->checkout_item->id]), ENT_QUOTES, 'UTF-8');
     $an_array = '';
     if (function_exists('wpsc_get_ticket_checkout_set')) {
         if ($this->checkout_item->checkout_set == wpsc_get_ticket_checkout_set()) {
             $an_array = '[]';
         }
     }
     switch ($this->checkout_item->type) {
         case "address":
         case "delivery_address":
         case "textarea":
             $output = "<textarea title='" . $this->checkout_item->unique_name . "' class='text' id='" . $this->form_element_id() . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' rows='3' cols='40' >" . $saved_form_data . "</textarea>";
             break;
         case "checkbox":
             $options = $this->get_checkout_options($this->checkout_item->id);
             if ($options != '') {
                 $i = mt_rand();
                 foreach ($options as $label => $value) {
                     $output .= "<input type='hidden' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "' value='-1' name='collected_data[{$this->checkout_item->id}][" . $i . "]'/><input type='checkbox' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "' value='" . esc_attr($value) . "' name='collected_data[{$this->checkout_item->id}][" . $i . "]'/> ";
                     $output .= "<label for='" . $this->form_element_id() . "'>" . $label . "</label>";
                 }
             }
             break;
         case "country":
             $output = wpsc_country_region_list($this->checkout_item->id, false, $_SESSION['wpsc_selected_country'], $_SESSION['wpsc_selected_region'], $this->form_element_id());
             break;
         case "delivery_country":
             if (wpsc_uses_shipping()) {
                 $country_name = $wpdb->get_var("SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`='" . $_SESSION['wpsc_delivery_country'] . "' LIMIT 1");
                 $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_country' name='collected_data[{$this->checkout_item->id}]' value='" . esc_attr($_SESSION['wpsc_delivery_country']) . "' size='4' /><span class='shipping_country_name'>" . $country_name . "</span> ";
             } else {
                 $checkoutfields = true;
                 $output = wpsc_country_region_list($this->checkout_item->id, false, $_SESSION['wpsc_delivery_country'], $_SESSION['wpsc_delivery_region'], $this->form_element_id(), $checkoutfields);
             }
             break;
         case "select":
             $options = $this->get_checkout_options($this->checkout_item->id);
             if ($options != '') {
                 $output = "<select name='collected_data[{$this->checkout_item->id}]" . $an_array . "'>";
                 $output .= "<option value='-1'>Select an Option</option>";
                 foreach ((array) $options as $label => $value) {
                     $value = esc_attr(str_replace(' ', '', $value));
                     $output .= "<option value='" . esc_attr($value) . "'>" . esc_html($label) . "</option>\n\r";
                 }
                 $output .= "</select>";
             }
             break;
         case "radio":
             $options = $this->get_checkout_options($this->checkout_item->id);
             if ($options != '') {
                 $i = mt_rand();
                 foreach ((array) $options as $label => $value) {
                     $output .= "<input type='radio' title='" . $this->checkout_item->unique_name . "' id='" . $this->form_element_id() . "'value='" . esc_attr($value) . "' name='collected_data[{$this->checkout_item->id}][" . $i . "]'/> ";
                     $output .= "<label for='" . $this->form_element_id() . "'>" . $label . "</label>";
                 }
             }
             break;
         case "text":
         case "city":
         case "delivery_city":
         case "email":
         case "coupon":
         default:
             if ($this->checkout_item->unique_name == 'shippingstate') {
                 if (wpsc_uses_shipping() && wpsc_has_regions($_SESSION['wpsc_delivery_country'])) {
                     $region_name = $wpdb->get_var("SELECT `name` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id`='" . $_SESSION['wpsc_delivery_region'] . "' LIMIT 1");
                     $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_region' name='collected_data[{$this->checkout_item->id}]' value='" . $_SESSION['wpsc_delivery_region'] . "' size='4' /><span class='shipping_region_name'>" . $region_name . "</span> ";
                 } else {
                     $disabled = '';
                     if (wpsc_disregard_shipping_state_fields()) {
                         $disabled = 'disabled = "disabled"';
                     }
                     $output = "<input class='shipping_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />";
                 }
             } elseif ($this->checkout_item->unique_name == 'billingstate') {
                 if (wpsc_uses_shipping() && wpsc_has_regions($_SESSION['wpsc_selected_country'])) {
                     $output = '';
                 } else {
                     $disabled = '';
                     if (wpsc_disregard_billing_state_fields()) {
                         $disabled = 'disabled = "disabled"';
                     }
                     $output = "<input class='billing_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />";
                 }
             } else {
                 $output = "<input title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' class='text' value='" . $saved_form_data . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' />";
             }
             break;
     }
     return $output;
 }
            ?>
</label>
					<input type='checkbox' value='true' name='shippingSameBilling' id='shippingSameBilling' <?php 
            echo $checked;
            ?>
 />
					<br/><span id="shippingsameasbillingmessage"><?php 
            _e('Your order will be shipped to the billing address', ETHEME_DOMAIN);
            ?>
</span>
                  </td>
               </tr>
               <?php 
        }
        // Not a header so start display form fields
    } elseif (wpsc_disregard_shipping_state_fields()) {
        ?>
               <tr class='wpsc_hidden'>
                  <td class='<?php 
        echo wpsc_checkout_form_element_id();
        ?>
'>
                     <label for='<?php 
        echo wpsc_checkout_form_element_id();
        ?>
'>
                     <?php 
        echo wpsc_checkout_form_name();
        ?>
                     </label>
                  </td>
    /**
     * form_field method, returns the form html
     * @access public
     */
    function form_field()
    {
        global $wpdb, $user_ID, $wpsc_customer_checkout_details;
        if ($user_ID > 0) {
            $delivery_country_id = wpsc_get_country_form_id_by_type('delivery_country');
            $billing_country_id = wpsc_get_country_form_id_by_type('country');
        }
        $saved_form_data = empty($wpsc_customer_checkout_details[$this->checkout_item->id]) ? null : $wpsc_customer_checkout_details[$this->checkout_item->id];
        $an_array = '';
        if (function_exists('wpsc_get_ticket_checkout_set')) {
            if ($this->checkout_item->checkout_set == wpsc_get_ticket_checkout_set()) {
                $an_array = '[]';
            }
        }
        $output = '';
        $delivery_country = wpsc_get_customer_meta('shipping_country');
        $billing_country = wpsc_get_customer_meta('billing_country');
        $delivery_region = wpsc_get_customer_meta('shipping_region');
        $billing_region = wpsc_get_customer_meta('billing_region');
        switch ($this->checkout_item->type) {
            case "address":
            case "delivery_address":
            case "textarea":
                $output .= "<textarea title='" . $this->checkout_item->unique_name . "' class='text' id='" . $this->form_element_id() . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' rows='3' cols='40' >" . esc_html((string) $saved_form_data) . "</textarea>";
                break;
            case "checkbox":
                $options = $this->get_checkout_options($this->checkout_item->id);
                if ($options != '') {
                    $i = mt_rand();
                    foreach ($options as $label => $value) {
                        ?>
							<label>
								<input <?php 
                        checked(in_array($value, (array) $saved_form_data));
                        ?>
 type="checkbox" name="collected_data[<?php 
                        echo esc_attr($this->checkout_item->id);
                        ?>
]<?php 
                        echo $an_array;
                        ?>
[]" value="<?php 
                        echo esc_attr($value);
                        ?>
"  />
								<?php 
                        echo esc_html($label);
                        ?>
							</label>
						<?php 
                    }
                }
                break;
            case "country":
                $output = wpsc_country_region_list($this->checkout_item->id, false, $billing_country, $billing_region, $this->form_element_id());
                break;
            case "delivery_country":
                if (wpsc_uses_shipping()) {
                    $country_name = $wpdb->get_var($wpdb->prepare("SELECT `country` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode`= %s LIMIT 1", $delivery_country));
                    $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_country' name='collected_data[{$this->checkout_item->id}]' value='" . esc_attr($delivery_country) . "' size='4' /><span class='shipping_country_name'>" . $country_name . "</span> ";
                } else {
                    $checkoutfields = true;
                    $output = wpsc_country_region_list($this->checkout_item->id, false, $delivery_country, $delivery_region, $this->form_element_id(), $checkoutfields);
                }
                break;
            case "select":
                $options = $this->get_checkout_options($this->checkout_item->id);
                if ($options != '') {
                    $output = "<select name='collected_data[{$this->checkout_item->id}]" . $an_array . "'>";
                    $output .= "<option value='-1'>" . _x('Select an Option', 'Dropdown default when called within checkout class', 'wpsc') . "</option>";
                    foreach ((array) $options as $label => $value) {
                        $value = esc_attr(str_replace(' ', '', $value));
                        $output .= "<option " . selected($value, $saved_form_data, false) . " value='" . esc_attr($value) . "'>" . esc_html($label) . "</option>\n\r";
                    }
                    $output .= "</select>";
                }
                break;
            case "radio":
                $options = $this->get_checkout_options($this->checkout_item->id);
                if ($options != '') {
                    foreach ((array) $options as $label => $value) {
                        ?>
							<label>
								<input type="radio" <?php 
                        checked($value, $saved_form_data);
                        ?>
 name="collected_data[<?php 
                        echo esc_attr($this->checkout_item->id);
                        ?>
]<?php 
                        echo $an_array;
                        ?>
" value="<?php 
                        echo esc_attr($value);
                        ?>
"  />
								<?php 
                        echo esc_html($label);
                        ?>
							</label>
						<?php 
                    }
                }
                break;
            case "text":
            case "city":
            case "delivery_city":
            case "email":
            case "coupon":
            default:
                if ($this->checkout_item->unique_name == 'shippingstate') {
                    if (wpsc_uses_shipping() && wpsc_has_regions($delivery_country)) {
                        $region_name = $wpdb->get_var($wpdb->prepare("SELECT `name` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id`= %d LIMIT 1", $delivery_region));
                        $output = "<input title='" . $this->checkout_item->unique_name . "' type='hidden' id='" . $this->form_element_id() . "' class='shipping_region' name='collected_data[{$this->checkout_item->id}]' value='" . esc_attr($delivery_region) . "' size='4' /><span class='shipping_region_name'>" . esc_html($region_name) . "</span> ";
                    } else {
                        $disabled = '';
                        if (wpsc_disregard_shipping_state_fields()) {
                            $disabled = 'disabled = "disabled"';
                        }
                        $output = "<input class='shipping_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . esc_attr($saved_form_data) . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />";
                    }
                } elseif ($this->checkout_item->unique_name == 'billingstate') {
                    $disabled = '';
                    if (wpsc_disregard_billing_state_fields()) {
                        $disabled = 'disabled = "disabled"';
                    }
                    $output = "<input class='billing_region text' title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' value='" . esc_attr($saved_form_data) . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' " . $disabled . " />";
                } else {
                    $output = "<input title='" . $this->checkout_item->unique_name . "' type='text' id='" . $this->form_element_id() . "' class='text' value='" . esc_attr($saved_form_data) . "' name='collected_data[{$this->checkout_item->id}]" . $an_array . "' />";
                }
                break;
        }
        return $output;
    }