/**
  * ecartregcust::add_user()
  * 
  * @param mixed $data
  * @return
  */
 private function add_user()
 {
     require_once(ABSPATH."/wp-includes/registration.php");
     
     $Errors =& EcartErrors();
     $Errors->reset();
     if (empty($_POST['customer']['email'])) 
     {
         $this->form_error = 'Email address is required.';
         return false;
     }
     if ($this->email_exists($_POST['customer']['email'])) 
     {
         $this->form_error = 'Email address is already registered with another customer.';
         return false;
     }
     if (empty($_POST['customer']['password'])) 
     {
         $this->form_error = 'Password is required.';
         return false;
     }
     if ($_POST['customer']['password'] !== $_POST['customer']['confirm-password']) 
     {
         $this->form_error = 'Passwords do not match.';
         return false;
     } 
     if ($this->ecart_account_type == 'wordpress')
     {
         if (empty($_POST['customer']['loginname'])) 
         {
             $this->form_error = 'Username is already registered.';
             return false;                
         }
         if (email_exists($_POST['customer']['email']))
         {
             $this->form_error = 'Email address is already registered with another user.';
             return false;                 
         }
     }
     if ($this->show_billing)
     {
         if (empty($_POST['billing']['address']))
         {
             $this->form_error = 'Street address is required.';
             return false;                
         }
         if (empty($_POST['billing']['city']))
         {
             $this->form_error = 'City is required.';
             return false;                
         }
         if (empty($_POST['billing']['state']))
         {
             $this->form_error = 'State is required.';
             return false;                
         }
         if (empty($_POST['billing']['postcode']))
         {
             $this->form_error = 'Postcode is required.';
             return false;                
         }
     }
     
     $customer_data = $_POST['customer'];
     
     $ecart_customer = new Customer();
     $ecart_customer->updates($customer_data);
     
     if ($this->ecart_account_type == 'wordpress') 
     {
         $ecart_customer->create_wpuser(); // not logged in, create new account
         $customer_data['wpuser'] = $ecart_customer->wpuser;
         unset($ecart_customer->password);
         if ($Errors->exist(ECART_ERR)) 
         {
             $ecart_error = $Errors->get(ECART_ERR);
             $this->form_error = implode(', ', $ecart_error[0]->messages);
             return false;
         }
     }
     else
     {       
         $ecart_customer->password = wp_hash_password($data['password']);
     }        
     $ecart_customer->save();
     
     if ($Errors->exist(ECART_ERR)) 
     {
         $ecart_error = $Errors->get(ECART_ERR);
         $this->form_error = implode(', ', $ecart_error[0]->messages);
         return false;
     }                
     if ($this->show_billing)
     {
         $billing_data = $_POST['billing'];
         $ecart_billing = new Billing();  
         $ecart_billing->updates($billing_data);
         $ecart_billing->customer = $ecart_customer->id;
         $ecart_billing->save();
     }        
     
     return $customer_data;
 }
Exemple #2
0
	/**
	 * Provides ecart('cart') template api functionality
	 *	 
	 * @since 1.0
	 *
	 * @return mixed
	 **/
	function tag ($property,$options=array()) {
		global $Ecart;
		$submit_attrs = array('title','value','disabled','tabindex','accesskey','class');

		// Return strings with no options
		switch ($property) {
			case "url": return ecarturl(false,'cart'); break;
			case "referrer":
			case "referer":
				$referrer = $Ecart->Shopping->data->referrer;
				if (!$referrer) $referrer = ecart('catalog','url','return=1');
				return $referrer;
				break;
			case "hasitems":
			case "has-items": return (count($this->contents) > 0); break;
			case "totalitems":
			case "total-items": return $this->Totals->quantity; break;
			case "items":
				if (!isset($this->_item_loop)) {
					reset($this->contents);
					$this->_item_loop = true;
				} else next($this->contents);

				if (current($this->contents)) return true;
				else {
					unset($this->_item_loop);
					reset($this->contents);
					return false;
				}
				break;
			case "hasshipped":
			case "has-shipped": return $this->shipped(); break;
			case "shippeditems":
			case "shipped-items":
				if (!isset($this->_shipped_loop)) {
					reset($this->shipped);
					$this->_shipped_loop = true;
				} else next($this->shipped);

				if (current($this->shipped)) return true;
				else {
					unset($this->_shipped_loop);
					reset($this->shipped);
					return false;
				}
				break;
			case "hasdownloads":
			case "has-downloads": return $this->downloads(); break;
			case "downloaditems":
			case "download-items":
				if (!isset($this->_downloads_loop)) {
					reset($this->downloads);
					$this->_downloads_loop = true;
				} else next($this->downloads);

				if (current($this->downloads)) return true;
				else {
					unset($this->_downloads_loop);
					reset($this->downloads);
					return false;
				}
				break;
			case "lastitem":
			case "last-item": return $this->contents[$this->added]; break;
			case "totalpromos":
			case "total-promos": return count($this->discounts); break;
			case "haspromos":
			case "has-promos": return (count($this->discounts) > 0); break;
			case "discounts":
			case "promos":
				if (!isset($this->_promo_looping)) {
					reset($this->discounts);
					$this->_promo_looping = true;
				} else next($this->discounts);

				$discount = current($this->discounts);
				while ($discount && empty($discount->applied) && !$discount->freeshipping)
					$discount = next($this->discounts);

				if (current($this->discounts)) return true;
				else {
					unset($this->_promo_looping);
					reset($this->discounts);
					return false;
				}
			case "promoname":
			case "promo-name":
				$discount = current($this->discounts);
				if ($discount->applied == 0 && empty($discount->items) && !isset($this->freeshipping)) return false;
				return $discount->name;
				break;
			case "promodiscount":
			case "promo-discount":
				$discount = current($this->discounts);
				if ($discount->applied == 0 && empty($discount->items) && !isset($this->freeshipping)) return false;
				if (!isset($options['label'])) $options['label'] = ' '.__('Off!','Ecart');
				else $options['label'] = ' '.$options['label'];
				$string = false;
				if (!empty($options['before'])) $string = $options['before'];

				switch($discount->type) {
					case "Free Shipping": $string .= money($discount->freeshipping).$options['label']; break;
					case "Percentage Off": $string .= percentage($discount->discount,array('precision' => 0)).$options['label']; break;
					case "Amount Off": $string .= money($discount->discount).$options['label']; break;
					case "Buy X Get Y Free": return sprintf(__('Buy %s get %s free','Ecart'),$discount->buyqty,$discount->getqty); break;
				}
				if (!empty($options['after'])) $string .= $options['after'];

				return $string;
				break;
			case "function":
				$result = '<div class="hidden"><input type="hidden" id="cart-action" name="cart" value="true" /></div><input type="submit" name="update" id="hidden-update" />';

				$Errors = &EcartErrors();
				if (!$Errors->exist(ECART_STOCK_ERR)) return $result;

				ob_start();
				include(ECART_TEMPLATES."/errors.php");
				$errors = ob_get_contents();
				ob_end_clean();
				return $result.$errors;
				break;
			case "emptybutton":
			case "empty-button":
				if (!isset($options['value'])) $options['value'] = __('Empty Cart','Ecart');
				return '<input type="submit" name="empty" id="empty-button" '.inputattrs($options,$submit_attrs).' />';
				break;
			case "updatebutton":
			case "update-button":
				if (!isset($options['value'])) $options['value'] = __('Update Subtotal','Ecart');
				if (isset($options['class'])) $options['class'] .= " update-button";
				else $options['class'] = "update-button";
				return '<input type="submit" name="update"'.inputattrs($options,$submit_attrs).' />';
				break;
			case "sidecart":
				ob_start();
				include(ECART_TEMPLATES."/sidecart.php");
				$content = ob_get_contents();
				ob_end_clean();
				return $content;
				break;
			case "hasdiscount":
			case "has-discount": return ($this->Totals->discount > 0); break;
			case "discount": return money($this->Totals->discount); break;
		}

		$result = "";
		switch ($property) {
			case "promos-available":
				if (!$Ecart->Promotions->available()) return false;
				// Skip if the promo limit has been reached
				if ($Ecart->Settings->get('promo_limit') > 0 &&
					count($this->discounts) >= $Ecart->Settings->get('promo_limit')) return false;
				return true;
				break;
			case "promo-code":
				// Skip if no promotions exist
				if (!$Ecart->Promotions->available()) return false;
				// Skip if the promo limit has been reached
				if ($Ecart->Settings->get('promo_limit') > 0 &&
					count($this->discounts) >= $Ecart->Settings->get('promo_limit')) return false;
				if (!isset($options['value'])) $options['value'] = __("Apply Promo Code","Ecart");
				$result = '<ul><li>';

				if ($Ecart->Errors->exist()) {
					$result .= '<p class="error">';
					$errors = $Ecart->Errors->source('CartDiscounts');
					foreach ((array)$errors as $error) if (!empty($error)) $result .= $error->message(true,false);
					$result .= '</p>';
				}

				$result .= '<span><input type="text" id="promocode" name="promocode" value="" size="10" /></span>';
				$result .= '<span><input type="submit" id="apply-code" name="update" '.inputattrs($options,$submit_attrs).' /></span>';
				$result .= '</li></ul>';
				return $result;
			case "has-shipping-methods":
				return apply_filters(
							'ecart_shipping_hasestimates',
							(!empty($this->shipping) && !$this->noshipping),
							$this->shipping
						); break;
			case "needs-shipped": return (!empty($this->shipped)); break;
			case "hasshipcosts":
			case "has-shipcosts":
			case "hasship-costs":
			case "has-ship-costs": return ($this->Totals->shipping > 0); break;
			case "needs-shipping-estimates":
				$markets = $Ecart->Settings->get('target_markets');
				return (!empty($this->shipped) && !$this->noshipping && ($this->showpostcode || count($markets) > 1));
				break;
			case "shipping-estimates":
				if (empty($this->shipped)) return "";
				$base = $Ecart->Settings->get('base_operations');
				$markets = $Ecart->Settings->get('target_markets');
				$Shipping = &$Ecart->Order->Shipping;
				if (empty($markets)) return "";
				foreach ($markets as $iso => $country) $countries[$iso] = $country;
				if (!empty($Shipping->country)) $selected = $Shipping->country;
				else $selected = $base['country'];
				$result .= '<ul><li>';
				if ((isset($options['postcode']) && value_is_true($options['postcode'])) || $this->showpostcode) {
					$result .= '<span>';
					$result .= '<input type="text" name="shipping[postcode]" id="shipping-postcode" size="6" value="'.$Shipping->postcode.'" />&nbsp;';
					$result .= '</span>';
				}
				if (count($countries) > 1) {
					$result .= '<span>';
					$result .= '<select name="shipping[country]" id="shipping-country">';
					$result .= menuoptions($countries,$selected,true);
					$result .= '</select>';
					$result .= '</span>';
				} else $result .= '<input type="hidden" name="shipping[country]" id="shipping-country" value="'.key($markets).'" />';
				$result .= '<br class="clear" /></li></ul>';
				return $result;
				break;
		}

		$result = "";
		switch ($property) {
			case "subtotal": $result = $this->Totals->subtotal; break;
			case "shipping":
				if (empty($this->shipped)) return "";
				if (isset($options['label'])) {
					$options['currency'] = "false";
					if ($this->freeshipping) {
						$result = $Ecart->Settings->get('free_shipping_text');
						if (empty($result)) $result = __('Free Shipping!','Ecart');
					}

					else $result = $options['label'];
				} else {
					if ($this->Totals->shipping === null)
						return __("Enter Postal Code","Ecart");
					elseif ($this->Totals->shipping === false)
						return __("Not Available","Ecart");
					else $result = $this->Totals->shipping;
				}
				break;
			case "hastaxes":
			case "has-taxes":
				return ($this->Totals->tax > 0); break;
			case "tax":
				if ($this->Totals->tax > 0) {
					if (isset($options['label'])) {
						$options['currency'] = "false";
						$result = $options['label'];
					} else $result = $this->Totals->tax;
				} else $options['currency'] = "false";
				break;
			case "total":
				$result = $this->Totals->total;
				break;
		}

		if (isset($options['currency']) && !value_is_true($options['currency'])) return $result;
		if (is_numeric($result)) return '<span class="ecart_cart_'.$property.'">'.money($result).'</span>';

		return false;
	}
Exemple #3
0
	/**
	 * Provides ecart('checkout') template API functionality
	 * 
	 * @since 1.0
	 *
	 * @return mixed
	 **/
	function tag ($property,$options=array()) {
		global $Ecart,$wp;

		$pages = $Ecart->Settings->get('pages');
		$base = $Ecart->Settings->get('base_operations');
		$countries = $Ecart->Settings->get('target_markets');
		$process = get_query_var('ecart_proc');

		$select_attrs = array('title','required','class','disabled','required','size','tabindex','accesskey');
		$submit_attrs = array('title','class','value','disabled','tabindex','accesskey');

		if (!isset($options['mode'])) $options['mode'] = "input";

		switch ($property) {
			case "url":
				$link = ecarturl(false,'checkout',$this->security());

				// Pass any arguments along
				$args = $_GET;
				unset($args['page_id'],$args['acct']);
				$link = esc_url(add_query_arg($args,$link));
				if ($process == "confirm-order") $link = apply_filters('ecart_confirm_url',$link);
				else $link = apply_filters('ecart_checkout_url',$link);
				return $link;
				break;
			case "function":
				if (!isset($options['shipcalc'])) $options['shipcalc'] = '<img src="'.ECART_ADMIN_URI.'/icons/updating.gif" alt="'.__('Updating','Ecart').'" width="16" height="16" />';
				$regions = Lookup::country_zones();
				$base = $Ecart->Settings->get('base_operations');

				$js = "var regions = ".json_encode($regions).",".
									"SHIPCALC_STATUS = '".$options['shipcalc']."',".
									"d_pm = '".sanitize_title_with_dashes($this->paymethod)."',".
									"pm_cards = {};";

				foreach ($this->payoptions as $handle => $option) {
					if (empty($option->cards)) continue;
					$js .= "pm_cards['".$handle."'] = ".json_encode($option->cards).";";
				}
				add_storefrontjs($js,true);

				if (!empty($options['value'])) $value = $options['value'];
				else $value = "process";
				$output = '<div><input type="hidden" name="checkout" value="'.$value.'" /></div>';
				if ($value == "confirmed") $output = apply_filters('ecart_confirm_form',$output);
				else $output = apply_filters('ecart_checkout_form',$output);
				return $output;
				break;
			case "errors":
			case "error":
				$Errors = &EcartErrors();
				if (!$Errors->exist(ECART_COMM_ERR)) return false;
				$errors = $Errors->get(ECART_COMM_ERR);
				$defaults = array(
					'before' => '<li>',
					'after' => '</li>'
				);
				$options = array_merge($defaults,$options);
				extract($options);

				$result = "";
				foreach ((array)$errors as $error)
					if (!$error->blank()) $result .= $before.$error->message(true).$after;
				return $result;
				break;
			case "cart-summary":
				ob_start();
				include(ECART_TEMPLATES."/summary.php");
				$content = ob_get_contents();
				ob_end_clean();

				// If inside the checkout form, strip the extra <form> tag so we don't break standards
				// This is ugly, but necessary given the different markup contexts the cart summary is used in
				$Storefront =& EcartStorefront();
				if ($Storefront !== false && $Storefront->checkout)
					$content = preg_replace('/<\/?form.*?>/','',$content);

				return $content;
				break;
			case "loggedin": return $this->Customer->login; break;
			case "notloggedin": return (!$this->Customer->login && $Ecart->Settings->get('account_system') != "none"); break;
			case "email-login":  // Deprecating
			case "loginname-login":  // Deprecating
			case "account-login":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($_POST['account-login']))
					$options['value'] = $_POST['account-login'];
				return '<input type="text" name="account-login" id="account-login"'.inputattrs($options).' />';
				break;
			case "password-login":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($_POST['password-login']))
					$options['value'] = $_POST['password-login'];
				return '<input type="password" name="password-login" id="password-login" '.inputattrs($options).' />';
				break;
			case "submit-login": // Deprecating
			case "login-button":
				$string = '<input type="hidden" name="process-login" id="process-login" value="false" />';
				$string .= '<input type="submit" name="submit-login" id="submit-login" '.inputattrs($options).' />';
				return $string;
				break;
			case "firstname":
				if ($options['mode'] == "value") return $this->Customer->firstname;
				if (!empty($this->Customer->firstname))
					$options['value'] = $this->Customer->firstname;
				return '<input type="text" name="firstname" id="firstname" '.inputattrs($options).' />';
				break;
			case "lastname":
				if ($options['mode'] == "value") return $this->Customer->lastname;
				if (!empty($this->Customer->lastname))
					$options['value'] = $this->Customer->lastname;
				return '<input type="text" name="lastname" id="lastname" '.inputattrs($options).' />';
				break;
			case "email":
				if ($options['mode'] == "value") return $this->Customer->email;
				if (!empty($this->Customer->email))
					$options['value'] = $this->Customer->email;
				return '<input type="text" name="email" id="email" '.inputattrs($options).' />';
				break;
			case "loginname":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if ($options['mode'] == "value") return $this->Customer->loginname;
				if (!empty($this->Customer->loginname))
					$options['value'] = $this->Customer->loginname;
				return '<input type="text" name="loginname" id="login" '.inputattrs($options).' />';
				break;
			case "password":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if ($options['mode'] == "value")
					return strlen($this->Customer->password) == 34?str_pad('&bull;',8):$this->Customer->password;
				if (!empty($this->Customer->password))
					$options['value'] = $this->Customer->password;
				return '<input type="password" name="password" id="password" '.inputattrs($options).' />';
				break;
			case "confirm-password":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($this->Customer->_confirm_password))
					$options['value'] = $this->Customer->_confirm_password;
				return '<input type="password" name="confirm-password" id="confirm-password" '.inputattrs($options).' />';
				break;
			case "phone":
				if ($options['mode'] == "value") return $this->Customer->phone;
				if (!empty($this->Customer->phone))
					$options['value'] = $this->Customer->phone;
				return '<input type="text" name="phone" id="phone" '.inputattrs($options).' />';
				break;
			case "organization":
			case "company":
				if ($options['mode'] == "value") return $this->Customer->company;
				if (!empty($this->Customer->company))
					$options['value'] = $this->Customer->company;
				return '<input type="text" name="company" id="company" '.inputattrs($options).' />';
				break;
			case "marketing":
				if ($options['mode'] == "value") return $this->Customer->marketing;
				if (!empty($this->Customer->marketing))
					$options['value'] = $this->Customer->marketing;
				$attrs = array("accesskey","alt","checked","class","disabled","format",
					"minlength","maxlength","readonly","size","src","tabindex",
					"title");
				$input = '<input type="hidden" name="marketing" value="no" />';
				$input .= '<input type="checkbox" name="marketing" id="marketing" value="yes" '.inputattrs($options,$attrs).' />';
				return $input;
				break;
			case "customer-info":
				$defaults = array(
					'name' => false, // REQUIRED
					'info' => false,
					'mode' => false,
					'title' => '',
					'type' => 'hidden',
					'value' => '',
					'cols' => '30',
					'rows' => '3',
					'options' => ''
				);
				$op = array_merge($defaults,$options);
				extract($op);

				// Allowed input types
				$allowed_types = array("text","hidden","password","checkbox","radio","textarea","menu");

				// Input types that can override option-specified value with the loaded data value
				$value_override = array("text","hidden","password","textarea","menu");

				/// Allowable attributes for textarea inputs
				$textarea_attrs = array('accesskey','title','tabindex','class','disabled','required');

				if (!$name) { // Iterator for order data
					if (!isset($this->_customer_info_loop)) {
						reset($this->Customer->info->named);
						$this->_customer_info_loop = true;
					} else next($this->Customer->info->named);

					if (current($this->Customer->info->named) !== false) return true;
					else {
						unset($this->_customer_info_loop);
						return false;
					}
				}

				if (isset($this->Customer->info->named[$name])) $info = $this->Customer->info->named[$name];
				if ($name && $mode == "value") return $info;

				if (!in_array($type,$allowed_types)) $type = 'hidden';
				if (empty($title)) $title = $name;
				$id = 'customer-info-'.sanitize_title_with_dashes($name);

				if (in_array($type,$value_override) && !empty($info))
					$value = $info;
				switch (strtolower($type)) {
					case "textarea":
						return '<textarea name="info['.$name.']" cols="'.$cols.'" rows="'.$rows.'" id="'.$id.'" '.inputattrs($op,$textarea_attrs).'>'.$value.'</textarea>';
						break;
					case "menu":
						if (is_string($options)) $options = explode(',',$options);
						return '<select name="info['.$name.']" id="'.$id.'" '.inputattrs($op,$select_attrs).'>'.menuoptions($options,$value).'</select>';
						break;
					default:
						return '<input type="'.$type.'" name="info['.$name.']" id="'.$id.'" '.inputattrs($op).' />';
						break;
				}
				break;

			// SHIPPING TAGS
			case "shipping": return (!empty($this->shipped)); break;
			case "shipping-address":
				if ($options['mode'] == "value") return $this->Shipping->address;
				if (!empty($this->Shipping->address))
					$options['value'] = $this->Shipping->address;
				return '<input type="text" name="shipping[address]" id="shipping-address" '.inputattrs($options).' />';
				break;
			case "shipping-xaddress":
				if ($options['mode'] == "value") return $this->Shipping->xaddress;
				if (!empty($this->Shipping->xaddress))
					$options['value'] = $this->Shipping->xaddress;
				return '<input type="text" name="shipping[xaddress]" id="shipping-xaddress" '.inputattrs($options).' />';
				break;
			case "shipping-city":
				if ($options['mode'] == "value") return $this->Shipping->city;
				if (!empty($this->Shipping->city))
					$options['value'] = $this->Shipping->city;
				return '<input type="text" name="shipping[city]" id="shipping-city" '.inputattrs($options).' />';
				break;
			case "shipping-province":
			case "shipping-state":
				if ($options['mode'] == "value") return $this->Shipping->state;
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($this->Shipping->state)) {
					$options['selected'] = $this->Shipping->state;
					$options['value'] = $this->Shipping->state;
				}

				$output = false;
				$country = $base['country'];
				if (!empty($this->Shipping->country))
					$country = $this->Shipping->country;
				if (!array_key_exists($country,$countries)) $country = key($countries);

				$regions = Lookup::country_zones();
				$states = $regions[$country];

				if (isset($options['options']) && empty($states)) $states = explode(",",$options['options']);

				if (isset($options['type']) && $options['type'] == "text")
					return '<input type="text" name="shipping[state]" id="shipping-state" '.inputattrs($options).'/>';

				$classname = isset($options['class'])?$options['class']:'';
				$label = (!empty($options['label']))?$options['label']:'';
				$options['disabled'] = 'disabled';
				$options['class'] = ($classname?"$classname ":"").'disabled hidden';

				$output .= '<select name="shipping[state]" id="shipping-state-menu" '.inputattrs($options,$select_attrs).'>';
				$output .= '<option value="">'.$label.'</option>';
				if (is_array($states) && !empty($states)) $output .= menuoptions($states,$options['selected'],true);
				$output .= '</select>';
				unset($options['disabled']);
				$options['class'] = $classname;
				$output .= '<input type="text" name="shipping[state]" id="shipping-state" '.inputattrs($options).'/>';

				return $output;
				break;
			case "shipping-postcode":
				if ($options['mode'] == "value") return $this->Shipping->postcode;
				if (!empty($this->Shipping->postcode))
					$options['value'] = $this->Shipping->postcode;
				return '<input type="text" name="shipping[postcode]" id="shipping-postcode" '.inputattrs($options).' />'; break;
			case "shipping-country":
				if ($options['mode'] == "value") return $this->Shipping->country;
				if (!empty($this->Shipping->country))
					$options['selected'] = $this->Shipping->country;
				else if (empty($options['selected'])) $options['selected'] = $base['country'];
				$output = '<select name="shipping[country]" id="shipping-country" '.inputattrs($options,$select_attrs).'>';
			 	$output .= menuoptions($countries,$options['selected'],true);
				$output .= '</select>';
				return $output;
				break;
			case "same-shipping-address":
				$label = __("Same shipping address","Ecart");
				if (isset($options['label'])) $label = $options['label'];
				$checked = ' checked="checked"';
				if (isset($options['checked']) && !value_is_true($options['checked'])) $checked = '';
				$output = '<label for="same-shipping"><input type="checkbox" name="sameshipaddress" value="on" id="same-shipping" '.$checked.' /> '.$label.'</label>';
				return $output;
				break;
			case "residential-shipping-address":
				$label = __("Residential shipping address","Ecart");
				if (isset($options['label'])) $label = $options['label'];
				if (isset($options['checked']) && value_is_true($options['checked'])) $checked = ' checked="checked"';
				$output = '<label for="residential-shipping"><input type="hidden" name="shipping[residential]" value="no" /><input type="checkbox" name="shipping[residential]" value="yes" id="residential-shipping" '.$checked.' /> '.$label.'</label>';
				return $output;
				break;

			// BILLING TAGS
			case "billing-required": // DEPRECATED
			case "card-required":
				if ($this->Cart->Totals->total == 0) return false;
				foreach ($Ecart->Gateways->active as $gateway)
					if (!empty($gateway->cards)) return true;
				return false;
				break;
			case "billing-address":
				if ($options['mode'] == "value") return $this->Billing->address;
				if (!empty($this->Billing->address))
					$options['value'] = $this->Billing->address;
				return '<input type="text" name="billing[address]" id="billing-address" '.inputattrs($options).' />';
				break;
			case "billing-xaddress":
				if ($options['mode'] == "value") return $this->Billing->xaddress;
				if (!empty($this->Billing->xaddress))
					$options['value'] = $this->Billing->xaddress;
				return '<input type="text" name="billing[xaddress]" id="billing-xaddress" '.inputattrs($options).' />';
				break;
			case "billing-city":
				if ($options['mode'] == "value") return $this->Billing->city;
				if (!empty($this->Billing->city))
					$options['value'] = $this->Billing->city;
				return '<input type="text" name="billing[city]" id="billing-city" '.inputattrs($options).' />';
				break;
			case "billing-province":
			case "billing-state":
				if ($options['mode'] == "value") return $this->Billing->state;
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($this->Billing->state)) {
					$options['selected'] = $this->Billing->state;
					$options['value'] = $this->Billing->state;
				}

				$output = false;
				$country = $base['country'];
				if (!empty($this->Billing->country))
					$country = $this->Billing->country;
				if (!array_key_exists($country,$countries)) $country = key($countries);

				$regions = Lookup::country_zones();
				$states = $regions[$country];

				if (isset($options['options']) && empty($states)) $states = explode(",",$options['options']);

				if (isset($options['type']) && $options['type'] == "text")
					return '<input type="text" name="billing[state]" id="billing-state" '.inputattrs($options).'/>';

				$classname = isset($options['class'])?$options['class']:'';
				$label = (!empty($options['label']))?$options['label']:'';
				$options['disabled'] = 'disabled';
				$options['class'] = ($classname?"$classname ":"").'disabled hidden';

				$output .= '<select name="billing[state]" id="billing-state-menu" '.inputattrs($options,$select_attrs).'>';
				$output .= '<option value="">'.$label.'</option>';
				if (is_array($states) && !empty($states)) $output .= menuoptions($states,$options['selected'],true);
				$output .= '</select>';
				unset($options['disabled']);
				$options['class'] = $classname;
				$output .= '<input type="text" name="billing[state]" id="billing-state" '.inputattrs($options).'/>';

				return $output;
				break;
			case "billing-postcode":
				if ($options['mode'] == "value") return $this->Billing->postcode;
				if (!empty($this->Billing->postcode))
					$options['value'] = $this->Billing->postcode;
				return '<input type="text" name="billing[postcode]" id="billing-postcode" '.inputattrs($options).' />';
				break;
			case "billing-country":
				if ($options['mode'] == "value") return $this->Billing->country;
				if (!empty($this->Billing->country))
					$options['selected'] = $this->Billing->country;
				else if (empty($options['selected'])) $options['selected'] = $base['country'];
				$output = '<select name="billing[country]" id="billing-country" '.inputattrs($options,$select_attrs).'>';
			 	$output .= menuoptions($countries,$options['selected'],true);
				$output .= '</select>';
				return $output;
				break;
			case "billing-card":
				if ($options['mode'] == "value")
					return str_repeat('X',strlen($this->Billing->card)-4)
						.substr($this->Billing->card,-4);
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				if (!empty($this->Billing->card)) {
					$options['value'] = $this->Billing->card;
					$this->Billing->card = "";
				}
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				return '<input type="text" name="billing[card]" id="billing-card" '.inputattrs($options).' />';
				break;
			case "billing-cardexpires-mm":
				if ($options['mode'] == "value") return date("m",$this->Billing->cardexpires);
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($this->Billing->cardexpires))
					$options['value'] = date("m",$this->Billing->cardexpires);
				return '<input type="text" name="billing[cardexpires-mm]" id="billing-cardexpires-mm" '.inputattrs($options).' />';
				break;
			case "billing-cardexpires-yy":
				if ($options['mode'] == "value") return date("y",$this->Billing->cardexpires);
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($this->Billing->cardexpires))
					$options['value'] = date("y",$this->Billing->cardexpires);
				return '<input type="text" name="billing[cardexpires-yy]" id="billing-cardexpires-yy" '.inputattrs($options).' />';
				break;
			case "billing-cardtype":
				if ($options['mode'] == "value") return $this->Billing->cardtype;
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($this->Billing->cardtype))
					$options['selected'] = $this->Billing->cardtype;

				$cards = array();
				foreach ($this->paycards as $paycard)
					$cards[$paycard->symbol] = $paycard->name;

				$label = (!empty($options['label']))?$options['label']:'';
				$output = '<select name="billing[cardtype]" id="billing-cardtype" '.inputattrs($options,$select_attrs).'>';
				$output .= '<option value="" selected="selected">'.$label.'</option>';
			 	$output .= menuoptions($cards,$options['selected'],true);
				$output .= '</select>';

				$js = array();
				$js[] = "var paycards = {};";
				foreach ($this->paycards as $handle => $paycard) {
					$js[] = "paycards['".$handle."'] = ".json_encode($paycard).";";
				}
				add_storefrontjs(join("",$js), true);

				return $output;
				break;
			case "billing-cardholder":
				if ($options['mode'] == "value") return $this->Billing->cardholder;
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($this->Billing->cardholder))
					$options['value'] = $this->Billing->cardholder;
				return '<input type="text" name="billing[cardholder]" id="billing-cardholder" '.inputattrs($options).' />';
				break;
			case "billing-cvv":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($_POST['billing']['cvv']))
					$options['value'] = $_POST['billing']['cvv'];
				$options['class'] = isset($options['class']) ? $options['class'].' paycard':'paycard';
				return '<input type="text" name="billing[cvv]" id="billing-cvv" '.inputattrs($options).' />';
				break;
			case "billing-xcsc-required":
				$Gateways = $Ecart->Gateways->active;
				foreach ($Gateways as $Gateway) {
					foreach ((array)$Gateway->settings['cards'] as $card) {
						$PayCard = Lookup::paycard($card);
						if (!empty($PayCard->inputs)) return true;
					}
				}
				return false;
				break;
			case "billing-xcsc":
				if (empty($options['input'])) return;
				$input = $options['input'];

				$cards = array();
				$valid = array();
				// Collect valid card inputs for all gateways
				foreach ($this->payoptions as $payoption) {
					foreach ($payoption->cards as $card) {
						$PayCard = Lookup::paycard($card);
						if (empty($PayCard->inputs)) continue;
						$cards[] = $PayCard->symbol;
						foreach ($PayCard->inputs as $field => $size)
							$valid[$field] = $size;
					}
				}

				if (!array_key_exists($input,$valid)) return;

				if (!empty($_POST['billing']['xcsc'][$input]))
					$options['value'] = $_POST['billing']['xcsc'][$input];
				$options['class'] = isset($options['class']) ? $options['class'].' paycard xcsc':'paycard xcsc';

				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				$string = '<input type="text" name="billing[xcsc]['.$input.']" id="billing-xcsc-'.$input.'" '.inputattrs($options).' />';
				return $string;
				break;
			case "billing-xco": return; break; // DEPRECATED
			case "billing-localities":
				$rates = $Ecart->Settings->get("taxrates");
				foreach ((array)$rates as $rate) if (isset($rate['locals']) && is_array($rate['locals'])) return true;
				return false;
				break;
			case "billing-locale":
				if ($options['mode'] == "value") return $this->Billing->locale;
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($this->Billing->locale)) {
					$options['selected'] = $this->Billing->locale;
					$options['value'] = $this->Billing->locale;
				}
				if (empty($options['type'])) $options['type'] = "menu";
				$output = false;


				$rates = $Ecart->Settings->get("taxrates");
				foreach ($rates as $rate) if (is_array($rate['locals']))
					$locales[$rate['country'].$rate['zone']] = array_keys($rate['locals']);

				add_storefrontjs('var locales = '.json_encode($locales).';',true);

				$Taxes = new CartTax();
				$rate = $Taxes->rate(false,true);

				$localities = array_keys($rate['locals']);
				$label = (!empty($options['label']))?$options['label']:'';
				$output = '<select name="billing[locale]" id="billing-locale" '.inputattrs($options,$select_attrs).'>';
			 	$output .= menuoptions($localities,$options['selected']);
				$output .= '</select>';
				return $output;
				break;
			case "has-data":
			case "hasdata": return (is_array($this->data) && count($this->data) > 0); break;
			case "order-data":
			case "orderdata":
				$defaults = array(
					'name' => false, // REQUIRED
					'data' => false,
					'mode' => false,
					'title' => '',
					'type' => 'hidden',
					'value' => '',
					'cols' => '30',
					'rows' => '3',
					'options' => ''
				);
				$op = array_merge($defaults,$options);
				extract($op);

				// Allowed input types
				$allowed_types = array("text","hidden","password","checkbox","radio","textarea","menu");

				// Input types that can override option-specified value with the loaded data value
				$value_override = array("text","hidden","password","textarea","menu");

				/// Allowable attributes for textarea inputs
				$textarea_attrs = array('accesskey','title','tabindex','class','disabled','required');

				if (!$name) { // Iterator for order data
					if (!isset($this->_data_loop)) {
						reset($this->data);
						$this->_data_loop = true;
					} else next($this->data);

					if (current($this->data) !== false) return true;
					else {
						unset($this->_data_loop);
						return false;
					}
				}

				if (isset($this->data[$name])) $data = $this->data[$name];
				if ($name && $mode == "value") return $data;

				if (!in_array($type,$allowed_types)) $type = 'hidden';
				if (empty($title)) $title = $name;
				$id = 'order-data-'.sanitize_title_with_dashes($name);

				if (in_array($type,$value_override) && !empty($data))
					$value = $data;
				switch (strtolower($type)) {
					case "textarea":
						return '<textarea name="data['.$name.']" cols="'.$cols.'" rows="'.$rows.'" id="'.$id.'" '.inputattrs($op,$textarea_attrs).'>'.$value.'</textarea>';
						break;
					case "menu":
						if (is_string($options)) $options = explode(',',$options);
						return '<select name="data['.$name.']" id="'.$id.'" '.inputattrs($op,$select_attrs).'>'.menuoptions($options,$value).'</select>';
						break;
					default:
						return '<input type="'.$type.'" name="data['.$name.']" id="'.$id.'" '.inputattrs($op).' />';
						break;
				}
				break;
			case "data":
				if (!is_array($this->data)) return false;
				$data = current($this->data);
				$name = key($this->data);
				if (isset($options['name'])) return $name;
				return $data;
				break;
			case "submit":
				if (!isset($options['value'])) $options['value'] = __('Submit Order','Ecart');
				$options['class'] = isset($options['class'])?$options['class'].' checkout-button':'checkout-button';

				$wrapclass = '';
				if (isset($options['wrapclass'])) $wrapclass = ' '.$options['wrapclass'];

				$buttons = array('<input type="submit" name="process" id="checkout-button" '.inputattrs($options,$submit_attrs).' />');

				if (!$this->Cart->orderisfree())
					$buttons = apply_filters('ecart_checkout_submit_button',$buttons,$options,$submit_attrs);

				$_ = array();
				foreach ($buttons as $label => $button)
					$_[] = '<span class="payoption-button payoption-'.sanitize_title_with_dashes($label).($label === 0?$wrapclass:'').'">'.$button.'</span>';

				return join("\n",$_);
				break;
			case "confirm-button":
				if (empty($options['errorlabel'])) $options['errorlabel'] = __('Return to Checkout','Ecart');
				if (empty($options['value'])) $options['value'] = __('Confirm Order','Ecart');

				$button = '<input type="submit" name="confirmed" id="confirm-button" '.inputattrs($options,$submit_attrs).' />';
				$return = '<a href="'.ecarturl(false,'checkout',$this->security()).'"'.inputattrs($options,array('class')).'>'.
								$options['errorlabel'].'</a>';

				if (!$this->validated) $markup = $return;
				else $markup = $button;
				return apply_filters('ecart_checkout_confirm_button',$markup,$options,$submit_attrs);
				break;
			case "local-payment": return true; break; // DEPRECATED
			case "xco-buttons": return;	break; // DEPRECATED
			case "payoptions":
			case "payment-options":
			case "paymentoptions":
				if ($this->Cart->orderisfree()) return false;
				$payment_methods = apply_filters('ecart_payment_methods',count($this->payoptions));
				if ($payment_methods <= 1) return false; // Skip if only one gateway is active
				$defaults = array(
					'default' => false,
					'exclude' => false,
					'type' => 'menu',
					'mode' => false
				);
				$options = array_merge($defaults,$options);
				extract($options);
				unset($options['type']);

				if ("loop" == $mode) {
					if (!isset($this->_pay_loop)) {
						reset($this->payoptions);
						$this->_pay_loop = true;
					} else next($this->payoptions);

					if (current($this->payoptions) !== false) return true;
					else {
						unset($this->_pay_loop);
						return false;
					}
					return true;
				}

				$excludes = array_map('sanitize_title_with_dashes',explode(",",$exclude));
				$payoptions = array_keys($this->payoptions);

				$payoptions = array_diff($payoptions,$excludes);
				$paymethod = current($payoptions);

				if ($default !== false && !isset($this->_paymethod_selected)) {
					$default = sanitize_title_with_dashes($default);
					if (in_array($default,$payoptions)) $paymethod = $default;
				}

				if ($this->paymethod != $paymethod) {
					$this->paymethod = $paymethod;
					$processor = $this->payoptions[$this->paymethod]->processor;
					if (!empty($processor)) $this->processor($processor);
				}

				$output = '';
				switch ($type) {
					case "list":
						$output .= '<span><ul>';
						foreach ($payoptions as $value) {
							if (in_array($value,$excludes)) continue;
							$payoption = $this->payoptions[$value];
							$options['value'] = $value;
							$options['checked'] = ($this->paymethod == $value)?'checked':false;
							if ($options['checked'] === false) unset($options['checked']);
							$output .= '<li><label><input type="radio" name="paymethod" '.inputattrs($options).' /> '.$payoption->label.'</label></li>';
						}
						$output .= '</ul></span>';
						break;
					case "hidden":
						if (!isset($options['value']) && $default) $options['value'] = $this->paymethod;
						$output .= '<input type="hidden" name="paymethod"'.inputattrs($options).' />';
						break;
					default:
						$output .= '<select name="paymethod" '.inputattrs($options,$select_attrs).'>';
						foreach ($payoptions as $value) {
							if (in_array($value,$excludes)) continue;
							$payoption = $this->payoptions[$value];
							$selected = ($this->paymethod == $value)?' selected="selected"':'';
							$output .= '<option value="'.$value.'"'.$selected.'>'.$payoption->label.'</option>';
						}
						$output .= '</select>';
						break;
				}

				return $output;
				break;
			case "payoption":
			case "payment-option":
			case "paymentoption":
				$payoption = current($this->payoptions);
				$defaults = array(
					'labelpos' => 'after',
					'labeling' => false,
					'type' => 'hidden',
				);
				$options = array_merge($defaults,$options);
				extract($options);

				if (value_is_true($return)) return $payoption;

				$types = array('radio','checkbox','hidden');
				if (!in_array($type,$types)) $type = 'hidden';

				if (empty($options['value'])) $options['value'] = key($this->payoptions);

				$_ = array();
				if (value_is_true($labeling))
					$_[] = '<label>';
				if ($labelpos == "before") $_[] = $payoption->label;
				$_[] = '<input type="'.$type.'" name="paymethod"'.inputattrs($options).' />';
				if ($labelpos == "after") $_[] = $payoption->label;
				if (value_is_true($labeling))
					$_[] = '</label>';

				return join("",$_);
				break;
			case "gatewayinputs":
			case "gateway-inputs":
				return apply_filters('ecart_checkout_gateway_inputs',false);
				break;
			case "completed":
				if (empty($Ecart->Purchase->id) && $this->purchase !== false) {
					$Ecart->Purchase = new Purchase($this->purchase);
					$Ecart->Purchase->load_purchased();
					return (!empty($Ecart->Purchase->id));
				}
				return false;
				break;
			case "receipt":
				if (!empty($Ecart->Purchase->id))
					return $Ecart->Purchase->receipt();
				break;
		}
	}
Exemple #4
0
	/**
	 * Displays the appropriate checkout template
	 *
	 * Replaces the [checkout] shortcode on the Checkout page with
	 * the processed template contents.
	 *	 
	 * @since 1.1
	 *
	 * @param array $attrs Shortcode attributes
	 * @return string The processed template content
	 **/
	function checkout_page () {
		$Errors =& EcartErrors();
		$Order =& EcartOrder();
		$Cart =& $Order->Cart;
		$process = get_query_var('ecart_proc');

		do_action('ecart_init_checkout');
		switch ($process) {
			case "confirm-order":
				do_action('ecart_init_confirmation');
				$Order->validated = $Order->isvalid();
				$errors = "";
				if ($Errors->exist(ECART_STOCK_ERR)) {
					ob_start();
					include(ECART_TEMPLATES."/errors.php");
					$errors = ob_get_contents();
					ob_end_clean();
				}
				$content = $errors.$this->order_confirmation();
				break;
			case "thanks":
			case "receipt":
				$content = $this->thanks();
				break;
			default:
				ob_start();
				if ($Errors->exist(ECART_COMM_ERR)) include(ECART_TEMPLATES."/errors.php");
				$this->checkout = true;
				include(ECART_TEMPLATES."/checkout.php");
				$content = ob_get_contents();
				ob_end_clean();
		}

		return apply_filters('ecart_checkout_page',$content);
	}
Exemple #5
0
	function tag ($property,$options=array()) {
		global $Ecart;

		$Order =& $Ecart->Order;
		$checkout = false;
		if (isset($Ecart->Flow->Controller->checkout))
			$checkout = $Ecart->Flow->Controller->checkout;

		// Return strings with no options
		switch ($property) {
			case "url":
				return ecarturl(array('acct'=>null),'account',$Ecart->Gateways->secure); break;
			case "action":
				$action = null;
				if (isset($this->pages[$_GET['acct']])) $action = $_GET['acct'];
				return ecarturl(array('acct'=>$action),'account');
				break;

			case "accounturl": return ecarturl(false,'account'); break;
			case "recover-url": return add_query_arg('acct','recover',ecarturl(false,'account'));
			case "registration-form":
				$regions = Lookup::country_zones();
				add_storefrontjs("var regions = ".json_encode($regions).";",true);
				return $_SERVER['REQUEST_URI'];
				break;
			case "registration-errors":
				$Errors =& EcartErrors();
				if (!$Errors->exist(ECART_ERR)) return false;
				ob_start();
				include(ECART_TEMPLATES.'/errors.php');
				$markup = ob_get_contents();
				ob_end_clean();
				return $markup;
				break;
			case "register":
				return '<input type="submit" name="ecart_registration" value="Register" />';
				break;
			case "process":
				if (!empty($_GET['acct']) && isset($this->pages[$_GET['acct']])) return $_GET['acct'];
				return false;

			case "loggedin": return $Ecart->Order->Customer->login; break;
			case "notloggedin": return (!$Ecart->Order->Customer->login && $Ecart->Settings->get('account_system') != "none"); break;
			case "login-label":
				$accounts = $Ecart->Settings->get('account_system');
				$label = __('Email Address','Ecart');
				if ($accounts == "wordpress") $label = __('Login Name','Ecart');
				if (isset($options['label'])) $label = $options['label'];
				return $label;
				break;
			case "email-login":
			case "loginname-login":
			case "account-login":
				$id = "account-login".($checkout?"-checkout":'');
				if (!empty($_POST['account-login']))
					$options['value'] = $_POST['account-login'];
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				return '<input type="text" name="account-login" id="'.$id.'"'.inputattrs($options).' />';
				break;
			case "password-login":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				$id = "password-login".($checkout?"-checkout":'');

				if (!empty($_POST['password-login']))
					$options['value'] = $_POST['password-login'];
				return '<input type="password" name="password-login" id="'.$id.'"'.inputattrs($options).' />';
				break;
			case "recover-button":
				if (!isset($options['value'])) $options['value'] = __('Get New Password','Ecart');
 					return '<input type="submit" name="recover-login" id="recover-button"'.inputattrs($options).' />';
				break;
			case "submit-login": // Deprecating
			case "login-button":
				if (!isset($options['value'])) $options['value'] = __('Login','Ecart');
				$string = "";
				$id = "submit-login";

				$request = $_GET;
				if (isset($request['acct']) && $request['acct'] == "logout") unset($request['acct']);

				if ($checkout) {
					$id .= "-checkout";
					$string .= '<input type="hidden" name="process-login" id="process-login" value="false" />';
					$string .= '<input type="hidden" name="redirect" value="checkout" />';
				} else $string .= '<input type="hidden" name="process-login" value="true" /><input type="hidden" name="redirect" value="'.ecarturl($request,'account',$Order->security()).'" />';
				$string .= '<input type="submit" name="submit-login" id="'.$id.'"'.inputattrs($options).' />';
				return $string;
				break;
			case "profile-saved":
				$saved = (isset($this->_saved) && $this->_saved);
				unset($this->_saved);
				return $saved;
			case "password-changed":
				$change = (isset($this->_password_change) && $this->_password_change);
				unset($this->_password_change);
				return $change;
			case "errors-exist": return true;
				$Errors = &EcartErrors();
				return ($Errors->exist(ECART_AUTH_ERR));
				break;
			case "login-errors": // @deprecated
			case "errors":
				if (!apply_filters('ecart_show_account_errors',true)) return false;
				$Errors = &EcartErrors();
				if (!$Errors->exist(ECART_AUTH_ERR)) return false;

				ob_start();
				include(ECART_TEMPLATES."/errors.php");
				$errors = ob_get_contents();
				ob_end_clean();
				return $errors;
				break;

			case "menu":
				if (!isset($this->_menu_looping)) {
					reset($this->menus);
					$this->_menu_looping = true;
				} else next($this->menus);

				if (current($this->menus) !== false) return true;
				else {
					unset($this->_menu_looping);
					reset($this->menus);
					return false;
				}
				break;
			case "management":
				$page = current($this->menus);
				if (array_key_exists('url',$options)) return ecarturl(array('acct'=>$page->request),'account');
				if (array_key_exists('action',$options)) return $page->request;
				return $page->label;
			case "accounts": return $Ecart->Settings->get('account_system'); break;
			case "hasaccount":
				$system = $Ecart->Settings->get('account_system');
				if ($system == "wordpress") return ($this->wpuser != 0);
				elseif ($system == "ecart") return (!empty($this->password));
				else return false;
			case "wpuser-created": return $this->newuser;
			case "order-lookup":
				$auth = $Ecart->Settings->get('account_system');
				if ($auth != "none") return true;

				if (!empty($_POST['vieworder']) && !empty($_POST['purchaseid'])) {
					require_once("Purchase.php");
					$Purchase = new Purchase($_POST['purchaseid']);
					if ($Purchase->email == $_POST['email']) {
						$Ecart->Purchase = $Purchase;
						$Purchase->load_purchased();
						ob_start();
						include(ECART_TEMPLATES."/receipt.php");
						$content = ob_get_contents();
						ob_end_clean();
						return apply_filters('ecart_order_lookup',$content);
					}
				}

				ob_start();
				include(ECART_ADMIN_PATH."/orders/account.php");
				$content = ob_get_contents();
				ob_end_clean();
				return apply_filters('ecart_order_lookup',$content);
				break;

			case "firstname":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->firstname;
				if (!empty($this->firstname))
					$options['value'] = $this->firstname;
				return '<input type="text" name="firstname" id="firstname"'.inputattrs($options).' />';
				break;
			case "lastname":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->lastname;
				if (!empty($this->lastname))
					$options['value'] = $this->lastname;
				return '<input type="text" name="lastname" id="lastname"'.inputattrs($options).' />';
				break;
			case "company":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->company;
				if (!empty($this->company))
					$options['value'] = $this->company;
				return '<input type="text" name="company" id="company"'.inputattrs($options).' />';
				break;
			case "email":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->email;
				if (!empty($this->email))
					$options['value'] = $this->email;
				return '<input type="text" name="email" id="email"'.inputattrs($options).' />';
				break;
			case "loginname":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->loginname;
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (!empty($this->loginname))
					$options['value'] = $this->loginname;
				return '<input type="text" name="loginname" id="login"'.inputattrs($options).' />';
				break;
			case "password":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				if (isset($options['mode']) && $options['mode'] == "value")
					return strlen($this->password) == 34?str_pad('&bull;',8):$this->password;
				$options['value'] = "";
				return '<input type="password" name="password" id="password"'.inputattrs($options).' />';
				break;
			case "confirm-password":
				if (!isset($options['autocomplete'])) $options['autocomplete'] = "off";
				$options['value'] = "";
				return '<input type="password" name="confirm-password" id="confirm-password"'.inputattrs($options).' />';
				break;
			case "phone":
				if (isset($options['mode']) && $options['mode'] == "value") return $this->phone;
				if (!empty($this->phone))
					$options['value'] = $this->phone;
				return '<input type="text" name="phone" id="phone"'.inputattrs($options).' />';
				break;
			case "hasinfo":
			case "has-info":
				if (!is_object($this->info) || empty($this->info->meta)) return false;
				if (!isset($this->_info_looping)) {
					reset($this->info->meta);
					$this->_info_looping = true;
				} else next($this->info->meta);

				if (current($this->info->meta) !== false) return true;
				else {
					unset($this->_info_looping);
					reset($this->info->meta);
					return false;
				}
				break;
			case "info":
				$defaults = array(
					'mode' => 'input',
					'type' => 'text',
					'name' => false,
					'value' => false
				);
				$options = array_merge($defaults,$options);
				extract($options);

				if ($this->_info_looping)
					$info = current($this->info->meta);
				elseif ($name !== false && is_object($this->info->named[$name]))
					$info = $this->info->named[$name];

				switch ($mode) {
					case "name": return $info->name; break;
					case "value": return $info->value; break;
				}

				if (!$name && !empty($info->name)) $options['name'] = $info->name;
				elseif (!$name) return false;

				if (!$value && !empty($info->value)) $options['value'] = $info->value;

				$allowed_types = array("text","password","hidden","checkbox","radio");
				$type = in_array($type,$allowed_types)?$type:'hidden';
				return '<input type="'.$type.'" name="info['.$options['name'].']" id="customer-info-'.sanitize_title_with_dashes($options['name']).'"'.inputattrs($options).' />';
				break;

			// SHIPPING TAGS
			case "shipping": return $Order->Shipping;
			case "shipping-address":
				if ($options['mode'] == "value") return $Order->Shipping->address;
				if (!empty($Order->Shipping->address))
					$options['value'] = $Order->Shipping->address;
				return '<input type="text" name="shipping[address]" id="shipping-address" '.inputattrs($options).' />';
				break;
			case "shipping-xaddress":
				if ($options['mode'] == "value") return $Order->Shipping->xaddress;
				if (!empty($Order->Shipping->xaddress))
					$options['value'] = $Order->Shipping->xaddress;
				return '<input type="text" name="shipping[xaddress]" id="shipping-xaddress" '.inputattrs($options).' />';
				break;
			case "shipping-city":
				if ($options['mode'] == "value") return $Order->Shipping->city;
				if (!empty($Order->Shipping->city))
					$options['value'] = $Order->Shipping->city;
				return '<input type="text" name="shipping[city]" id="shipping-city" '.inputattrs($options).' />';
				break;
			case "shipping-province":
			case "shipping-state":
				if ($options['mode'] == "value") return $Order->Shipping->state;
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($Order->Shipping->state)) {
					$options['selected'] = $Order->Shipping->state;
					$options['value'] = $Order->Shipping->state;
				}
				$countries = Lookup::countries();
				$output = false;
				$country = $base['country'];
				if (!empty($Order->Shipping->country))
					$country = $Order->Shipping->country;
				if (!array_key_exists($country,$countries)) $country = key($countries);

				if (empty($options['type'])) $options['type'] = "menu";
				$regions = Lookup::country_zones();
				$states = $regions[$country];
				if (is_array($states) && $options['type'] == "menu") {
					$label = (!empty($options['label']))?$options['label']:'';
					$output = '<select name="shipping[state]" id="shipping-state" '.inputattrs($options,$select_attrs).'>';
					$output .= '<option value="" selected="selected">'.$label.'</option>';
				 	$output .= menuoptions($states,$options['selected'],true);
					$output .= '</select>';
				} else if ($options['type'] == "menu") {
					$options['disabled'] = 'disabled';
					$options['class'] = ($options['class']?" ":null).'unavailable';
					$label = (!empty($options['label']))?$options['label']:'';
					$output = '<select name="shipping[state]" id="shipping-state" '.inputattrs($options,$select_attrs).'></select>';
				} else $output .= '<input type="text" name="shipping[state]" id="shipping-state" '.inputattrs($options).'/>';
				return $output;
				break;
			case "shipping-postcode":
				if ($options['mode'] == "value") return $Order->Shipping->postcode;
				if (!empty($Order->Shipping->postcode))
					$options['value'] = $Order->Shipping->postcode;
				return '<input type="text" name="shipping[postcode]" id="shipping-postcode" '.inputattrs($options).' />'; break;
			case "shipping-country":
				if ($options['mode'] == "value") return $Order->Shipping->country;
				$base = $Ecart->Settings->get('base_operations');
				if (!empty($Order->Shipping->country))
					$options['selected'] = $Order->Shipping->country;
				else if (empty($options['selected'])) $options['selected'] = $base['country'];

				$countries = $Ecart->Settings->get('target_markets');

				$output = '<select name="shipping[country]" id="shipping-country" '.inputattrs($options,$select_attrs).'>';
			 	$output .= menuoptions($countries,$options['selected'],true);
				$output .= '</select>';
				return $output;
				break;
			case "same-shipping-address":
				$label = __("Same shipping address","Ecart");
				if (isset($options['label'])) $label = $options['label'];
				$checked = ' checked="checked"';
				if (isset($options['checked']) && !value_is_true($options['checked'])) $checked = '';
				$output = '<label for="same-shipping"><input type="checkbox" name="sameshipaddress" value="on" id="same-shipping" '.$checked.' /> '.$label.'</label>';
				return $output;
				break;
			case "residential-shipping-address":
				$label = __("Residential shipping address","Ecart");
				if (isset($options['label'])) $label = $options['label'];
				if (isset($options['checked']) && value_is_true($options['checked'])) $checked = ' checked="checked"';
				$output = '<label for="residential-shipping"><input type="hidden" name="shipping[residential]" value="no" /><input type="checkbox" name="shipping[residential]" value="yes" id="residential-shipping" '.$checked.' /> '.$label.'</label>';
				return $output;
				break;

			// BILLING TAGS
			case "billing-address":
				if ($options['mode'] == "value") return $Order->Billing->address;
				if (!empty($Order->Billing->address))
					$options['value'] = $Order->Billing->address;
				return '<input type="text" name="billing[address]" id="billing-address" '.inputattrs($options).' />';
				break;
			case "billing-xaddress":
				if ($options['mode'] == "value") return $Order->Billing->xaddress;
				if (!empty($Order->Billing->xaddress))
					$options['value'] = $Order->Billing->xaddress;
				return '<input type="text" name="billing[xaddress]" id="billing-xaddress" '.inputattrs($options).' />';
				break;
			case "billing-city":
				if ($options['mode'] == "value") return $Order->Billing->city;
				if (!empty($Order->Billing->city))
					$options['value'] = $Order->Billing->city;
				return '<input type="text" name="billing[city]" id="billing-city" '.inputattrs($options).' />';
				break;
			case "billing-province":
			case "billing-state":
				if ($options['mode'] == "value") return $Order->Billing->state;
				if (!isset($options['selected'])) $options['selected'] = false;
				if (!empty($Order->Billing->state)) {
					$options['selected'] = $Order->Billing->state;
					$options['value'] = $Order->Billing->state;
				}
				if (empty($options['type'])) $options['type'] = "menu";
				$countries = Lookup::countries();

				$output = false;
				$country = $base['country'];
				if (!empty($Order->Billing->country))
					$country = $Order->Billing->country;
				if (!array_key_exists($country,$countries)) $country = key($countries);

				$regions = Lookup::country_zones();
				$states = $regions[$country];
				if (is_array($states) && $options['type'] == "menu") {
					$label = (!empty($options['label']))?$options['label']:'';
					$output = '<select name="billing[state]" id="billing-state" '.inputattrs($options,$select_attrs).'>';
					$output .= '<option value="" selected="selected">'.$label.'</option>';
				 	$output .= menuoptions($states,$options['selected'],true);
					$output .= '</select>';
				} else if ($options['type'] == "menu") {
					$options['disabled'] = 'disabled';
					$options['class'] = ($options['class']?" ":null).'unavailable';
					$label = (!empty($options['label']))?$options['label']:'';
					$output = '<select name="billing[state]" id="billing-state" '.inputattrs($options,$select_attrs).'></select>';
				} else $output .= '<input type="text" name="billing[state]" id="billing-state" '.inputattrs($options).'/>';
				return $output;
				break;
			case "billing-postcode":
				if ($options['mode'] == "value") return $Order->Billing->postcode;
				if (!empty($Order->Billing->postcode))
					$options['value'] = $Order->Billing->postcode;
				return '<input type="text" name="billing[postcode]" id="billing-postcode" '.inputattrs($options).' />';
				break;
			case "billing-country":
				if ($options['mode'] == "value") return $Order->Billing->country;
				$base = $Ecart->Settings->get('base_operations');

				if (!empty($Order->Billing->country))
					$options['selected'] = $Order->Billing->country;
				else if (empty($options['selected'])) $options['selected'] = $base['country'];

				$countries = $Ecart->Settings->get('target_markets');

				$output = '<select name="billing[country]" id="billing-country" '.inputattrs($options,$select_attrs).'>';
			 	$output .= menuoptions($countries,$options['selected'],true);
				$output .= '</select>';
				return $output;
				break;

			case "save-button":
				if (!isset($options['label'])) $options['label'] = __('Save','Ecart');
				$result = '<input type="hidden" name="customer" value="true" />';
				$result .= '<input type="submit" name="save" id="save-button"'.inputattrs($options).' />';
				return $result;
				break;
			case "marketing":
				if ($options['mode'] == "value") return $this->marketing;
				if (!empty($this->marketing) && value_is_true($this->marketing)) $options['checked'] = true;
				$attrs = array("accesskey","alt","checked","class","disabled","format",
					"minlength","maxlength","readonly","size","src","tabindex",
					"title");
				$input = '<input type="hidden" name="marketing" value="no" />';
				$input .= '<input type="checkbox" name="marketing" id="marketing" value="yes" '.inputattrs($options,$attrs).' />';
				return $input;
				break;


			// Downloads UI tags
			case "hasdownloads":
			case "has-downloads": return (!empty($this->downloads)); break;
			case "downloads":
				if (empty($this->downloads)) return false;
				if (!isset($this->_dowload_looping)) {
					reset($this->downloads);
					$this->_dowload_looping = true;
				} else next($this->downloads);

				if (current($this->downloads) !== false) return true;
				else {
					unset($this->_dowload_looping);
					reset($this->downloads);
					return false;
				}
				break;
			case "download":
				$download = current($this->downloads);
				$df = get_option('date_format');
				$properties = unserialize($download->properties);
				$string = '';
				if (array_key_exists('id',$options)) $string .= $download->download;
				if (array_key_exists('purchase',$options)) $string .= $download->purchase;
				if (array_key_exists('name',$options)) $string .= $download->name;
				if (array_key_exists('variation',$options)) $string .= $download->optionlabel;
				if (array_key_exists('downloads',$options)) $string .= $download->downloads;
				if (array_key_exists('key',$options)) $string .= $download->dkey;
				if (array_key_exists('created',$options)) $string .= $download->created;
				if (array_key_exists('total',$options)) $string .= money($download->total);
				if (array_key_exists('filetype',$options)) $string .= $properties['mimetype'];
				if (array_key_exists('size',$options)) $string .= readableFileSize($download->size);
				if (array_key_exists('date',$options)) $string .= _d($df,mktimestamp($download->created));
				if (array_key_exists('url',$options))
					$string .= ECART_PRETTYURLS?
						ecarturl("download/$download->dkey"):
						ecarturl(array('ecart_download'=>$download->dkey),'account');

				return $string;
				break;

			// Downloads UI tags
			case "haspurchases":
			case "has-purchases":
				$filters = array();
				if (isset($options['daysago']))
					$filters['where'] = "UNIX_TIMESTAMP(o.created) > UNIX_TIMESTAMP()-".($options['daysago']*86400);
				if (empty($Ecart->purchases)) $this->load_orders($filters);
				return (!empty($Ecart->purchases));
				break;
			case "purchases":
				if (!isset($this->_purchaseloop)) {
					reset($Ecart->purchases);
					$Ecart->Purchase = current($Ecart->purchases);
					$this->_purchaseloop = true;
				} else {
					$Ecart->Purchase = next($Ecart->purchases);
				}

				if (current($Ecart->purchases) !== false) return true;
				else {
					unset($this->_purchaseloop);
					return false;
				}
				break;
			case "receipt": // DEPRECATED
			case "order":
				return ecarturl(array('acct'=>'order','id'=>$Ecart->Purchase->id),'account');
				break;

		}
	}
Exemple #6
0
	function registration () {
		$Errors =& EcartErrors();

		if (isset($_POST['info'])) $this->Customer->info = stripslashes_deep($_POST['info']);

		$this->Customer = new Customer();
		$this->Customer->updates($_POST);

		if (isset($_POST['confirm-password']))
			$this->Customer->confirm_password = $_POST['confirm-password'];

		$this->Billing = new Billing();
		if (isset($_POST['billing']))
			$this->Billing->updates($_POST['billing']);

		$this->Shipping = new Shipping();
		if (isset($_POST['shipping']))
			$this->Shipping->updates($_POST['shipping']);

		// Override posted shipping updates with billing address
		if ($_POST['sameshipaddress'] == "on")
			$this->Shipping->updates($this->Billing,
				array("_datatypes","_table","_key","_lists","id","created","modified"));

		// WordPress account integration used, customer has no wp user
		if ("wordpress" == $this->accounts && empty($this->Customer->wpuser)) {
			if ( $wpuser = get_current_user_id() ) $this->Customer->wpuser = $wpuser; // use logged in WordPress account
			else $this->Customer->create_wpuser(); // not logged in, create new account
		}

		if ($Errors->exist(ECART_ERR)) return false;

		// New customer, save hashed password
		if (empty($this->Customer->id) && !empty($this->Customer->password))
			$this->Customer->password = wp_hash_password($this->Customer->password);
		else unset($this->Customer->password); // Existing customer, do not overwrite password field!

		$this->Customer->save();
		if ($Errors->exist(ECART_ERR)) return false;

		$this->Billing->customer = $this->Customer->id;
		$this->Billing->save();

		if (!empty($this->Shipping->address)) {
			$this->Shipping->customer = $this->Customer->id;
			$this->Shipping->save();
		}

		if (!empty($this->Customer->id)) $this->login($this->Customer);

		ecart_redirect(ecarturl(false,'account'));
	}
Exemple #7
0
	/**
	 * Renders the shipping settings screen and processes updates
	 *	 
	 * @since 1.1
	 *
	 * @return void
	 **/
	function shipping () {
		global $Ecart;

		if ( !(current_user_can('manage_options') && current_user_can('ecart_settings_shipping')) )
			wp_die(__('You do not have sufficient permissions to access this page.'));

		if (!empty($_POST['save'])) {
			check_admin_referer('ecart-settings-shipping');

			// Sterilize $values
			foreach ($_POST['settings']['shipping_rates'] as $i => &$method) {
				$method['name'] = stripslashes($method['name']);
				foreach ($method as $key => &$mr) {
					if (!is_array($mr)) continue;
					foreach ($mr as $id => &$v) {
						if ($v == ">" || $v == "+" || $key == "services") continue;
						$v = floatvalue($v);
					}
				}
			}

			$_POST['settings']['order_shipfee'] = floatvalue($_POST['settings']['order_shipfee']);

	 		$this->settings_save();
			$updated = __('Shipping settings saved.','Ecart');

			// Reload the currently active shipping modules
			$active = $Ecart->Shipping->activated();
			$Ecart->Shipping->settings();

			$Errors = &EcartErrors();
			do_action('ecart_verify_shipping_services');

			if ($Errors->exist()) {
				// Get all addon related errors
				$failures = $Errors->level(ECART_ADDON_ERR);
				if (!empty($failures)) {
					$updated = __('Shipping settings saved but there were errors: ','Ecart');
					foreach ($failures as $error)
						$updated .= '<p>'.$error->message(true,true).'</p>';
				}
			}

		}

		$Ecart->Shipping->settings();

		$methods = $Ecart->Shipping->methods;
		$base = $Ecart->Settings->get('base_operations');
		$regions = Lookup::regions();
		$region = $regions[$base['region']];
		$useRegions = $Ecart->Settings->get('shipping_regions');

		$areas = Lookup::country_areas();
		if (is_array($areas[$base['country']]) && $useRegions == "on")
			$areas = array_keys($areas[$base['country']]);
		else $areas = array($base['country'] => $base['name']);
		unset($countries,$regions);

		$rates = $Ecart->Settings->get('shipping_rates');
		if (!empty($rates)) ksort($rates);

		$lowstock = $Ecart->Settings->get('lowstock_level');
		if (empty($lowstock)) $lowstock = 0;

		include(ECART_ADMIN_PATH."/settings/shipping.php");
	}
Exemple #8
0
	/**
	 * Relays triggered errors to email messages
	 *
	 * @since 1.0
	 *
	 * @param string $recipients List of email addresses
	 * @param array $types The types of errors to report
	 * @return void
	 **/
	function __construct ($recipients='',$types=array()) {
		if (empty($recipients)) return;
		$this->recipients = $recipients;
		foreach ((array)$types as $type) $this->types += $type;
		$Errors = &EcartErrors();
		$Errors->notifications->subscribe($this,'notify');
	}