function shopp_transaction_tracking($push)
 {
     global $Shopp;
     // Only process if we're in the checkout process (receipt page)
     if (version_compare(substr(SHOPP_VERSION, 0, 3), '1.1') >= 0) {
         // Only process if we're in the checkout process (receipt page)
         if (function_exists('is_shopp_page') && !is_shopp_page('checkout')) {
             return $push;
         }
         if (empty($Shopp->Order->purchase)) {
             return $push;
         }
         $Purchase = new Purchase($Shopp->Order->purchase);
         $Purchase->load_purchased();
     } else {
         // For 1.0.x
         // Only process if we're in the checkout process (receipt page)
         if (function_exists('is_shopp_page') && !is_shopp_page('checkout')) {
             return $push;
         }
         // Only process if we have valid order data
         if (!isset($Shopp->Cart->data->Purchase)) {
             return $push;
         }
         if (empty($Shopp->Cart->data->Purchase->id)) {
             return $push;
         }
         $Purchase = $Shopp->Cart->data->Purchase;
     }
     $push[] = "'_addTrans'," . "'" . $Purchase->id . "'," . "'" . GA_Filter::ga_str_clean(get_bloginfo('name')) . "'," . "'" . number_format($Purchase->total, 2) . "'," . "'" . number_format($Purchase->tax, 2) . "'," . "'" . number_format($Purchase->shipping, 2) . "'," . "'" . $Purchase->city . "'," . "'" . $Purchase->state . "'," . "'.{$Purchase->country}.'";
     // Country
     foreach ($Purchase->purchased as $item) {
         $sku = empty($item->sku) ? 'PID-' . $item->product . str_pad($item->price, 4, '0', STR_PAD_LEFT) : $item->sku;
         $push[] = "'_addItem'," . "'" . $Purchase->id . "'," . "'" . $sku . "'," . "'" . str_replace("'", "", $item->name) . "'," . "'" . $item->optionlabel . "'," . "'" . number_format($item->unitprice, 2) . "'," . "'" . $item->quantity . "'";
     }
     $push[] = "'_trackTrans'";
     return $push;
 }
예제 #2
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;

		}
	}
 /**
  * Orders admin flow handlers
  */
 function orders_list()
 {
     global $Shopp, $Orders;
     $db = DB::get();
     $defaults = array('page' => false, 'deleting' => false, 'selected' => false, 'update' => false, 'newstatus' => false, 'pagenum' => 1, 'per_page' => false, 'start' => '', 'end' => '', 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => '');
     $args = array_merge($defaults, $_GET);
     extract($args, EXTR_SKIP);
     if (!current_user_can(SHOPP_USERLEVEL)) {
         wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp'));
     }
     if ($page == "shopp-orders" && !empty($deleting) && !empty($selected) && is_array($selected)) {
         foreach ($selected as $selection) {
             $Purchase = new Purchase($selection);
             $Purchase->load_purchased();
             foreach ($Purchase->purchased as $purchased) {
                 $Purchased = new Purchased($purchased->id);
                 $Purchased->delete();
             }
             $Purchase->delete();
         }
     }
     $statusLabels = $this->Settings->get('order_status');
     if (empty($statusLabels)) {
         $statusLabels = array('');
     }
     $txnStatusLabels = array('PENDING' => __('Pending', 'Shopp'), 'CHARGED' => __('Charged', 'Shopp'), 'REFUNDED' => __('Refunded', 'Shopp'), 'VOID' => __('Void', 'Shopp'));
     if ($update == "order" && !empty($selected) && is_array($selected)) {
         foreach ($selected as $selection) {
             $Purchase = new Purchase($selection);
             $Purchase->status = $newstatus;
             $Purchase->save();
         }
     }
     $Purchase = new Purchase();
     if (!empty($start)) {
         $startdate = $start;
         list($month, $day, $year) = explode("/", $startdate);
         $starts = mktime(0, 0, 0, $month, $day, $year);
     }
     if (!empty($end)) {
         $enddate = $end;
         list($month, $day, $year) = explode("/", $enddate);
         $ends = mktime(23, 59, 59, $month, $day, $year);
     }
     $pagenum = absint($pagenum);
     if (empty($pagenum)) {
         $pagenum = 1;
     }
     if (!$per_page || $per_page < 0) {
         $per_page = 20;
     }
     $start = $per_page * ($pagenum - 1);
     $where = '';
     if (!empty($status) || $status === '0') {
         $where = "WHERE status='{$status}'";
     }
     if (!empty($s)) {
         $s = stripslashes($s);
         if (preg_match_all('/(\\w+?)\\:(?="(.+?)"|(.+?)\\b)/', $s, $props, PREG_SET_ORDER) > 0) {
             foreach ($props as $search) {
                 $keyword = !empty($search[2]) ? $search[2] : $search[3];
                 switch (strtolower($search[1])) {
                     case "txn":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "transactionid='{$keyword}'";
                         break;
                     case "gateway":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "gateway LIKE '%{$keyword}%'";
                         break;
                     case "cardtype":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "cardtype LIKE '%{$keyword}%'";
                         break;
                     case "address":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "(address LIKE '%{$keyword}%' OR xaddress='%{$keyword}%')";
                         break;
                     case "city":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "city LIKE '%{$keyword}%'";
                         break;
                     case "province":
                     case "state":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "state='{$keyword}'";
                         break;
                     case "zip":
                     case "zipcode":
                     case "postcode":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "postcode='{$keyword}'";
                         break;
                     case "country":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "country='{$keyword}'";
                         break;
                 }
             }
             if (empty($where)) {
                 $where .= (empty($where) ? "WHERE " : " AND ") . " (id='{$s}' OR CONCAT(firstname,' ',lastname) LIKE '%{$s}%')";
             }
         } elseif (strpos($s, '@') !== false) {
             $where .= (empty($where) ? "WHERE " : " AND ") . " email='{$s}'";
         } else {
             $where .= (empty($where) ? "WHERE " : " AND ") . " (id='{$s}' OR CONCAT(firstname,' ',lastname) LIKE '%{$s}%')";
         }
     }
     if (!empty($starts) && !empty($ends)) {
         $where .= (empty($where) ? "WHERE " : " AND ") . ' (UNIX_TIMESTAMP(created) >= ' . $starts . ' AND UNIX_TIMESTAMP(created) <= ' . $ends . ')';
     }
     $ordercount = $db->query("SELECT count(*) as total,SUM(total) AS sales,AVG(total) AS avgsale FROM {$Purchase->_table} {$where} ORDER BY created DESC");
     $query = "SELECT * FROM {$Purchase->_table} {$where} ORDER BY created DESC LIMIT {$start},{$per_page}";
     $Orders = $db->query($query, AS_ARRAY);
     $num_pages = ceil($ordercount->total / $per_page);
     $page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'total' => $num_pages, 'current' => $pagenum));
     $ranges = array('all' => __('Show All Orders', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'lastexport' => __('Last Export', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp'));
     $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp'), 'xls' => __('Microsoft&reg; Excel.xls', 'Shopp'), 'iif' => __('Intuit&reg; QuickBooks.iif', 'Shopp'));
     $formatPref = $Shopp->Settings->get('purchaselog_format');
     if (!$formatPref) {
         $formatPref = 'tab';
     }
     $columns = array_merge(Purchase::exportcolumns(), Purchased::exportcolumns());
     $selected = $Shopp->Settings->get('purchaselog_columns');
     if (empty($selected)) {
         $selected = array_keys($columns);
     }
     include "{$this->basepath}/core/ui/orders/orders.php";
 }
 function tag($property, $options = array())
 {
     global $Shopp;
     $menus = array("account" => __("My Account", "Shopp"), "downloads" => __("Downloads", "Shopp"), "history" => __("Order History", "Shopp"), "status" => __("Order Status", "Shopp"), "logout" => __("Logout", "Shopp"));
     // Return strings with no options
     switch ($property) {
         case "url":
             return $Shopp->link('account');
         case "recover-url":
             return add_query_arg('acct', 'recover', $Shopp->link('account'));
         case "process":
             if (isset($_GET['acct'])) {
                 return $_GET['acct'];
             }
             return false;
         case "loggedin":
             return $Shopp->Cart->data->login;
             break;
         case "notloggedin":
             return !$Shopp->Cart->data->login && $Shopp->Settings->get('account_system') != "none";
             break;
         case "login-label":
             $accounts = $Shopp->Settings->get('account_system');
             $label = __('Email Address', 'Shopp');
             if ($accounts == "wordpress") {
                 $label = __('Login Name', 'Shopp');
             }
             if (isset($options['label'])) {
                 $label = $options['label'];
             }
             return $label;
             break;
         case "email-login":
         case "loginname-login":
         case "account-login":
             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 (!empty($_POST['password-login'])) {
                 $options['value'] = $_POST['password-login'];
             }
             return '<input type="password" name="password-login" id="password-login"' . inputattrs($options) . ' />';
             break;
         case "recover-button":
             if (!isset($options['value'])) {
                 $options['value'] = __('Get New Password', 'Shopp');
             }
             return '<input type="submit" name="recover-login" id="recover-button"' . inputattrs($options) . ' />';
             break;
         case "submit-login":
             // Deprecating
         // Deprecating
         case "login-button":
             if (!isset($options['value'])) {
                 $options['value'] = __('Login', 'Shopp');
             }
             if (is_shopp_page('account')) {
                 $string = '<input type="hidden" name="process-login" id="process-login" value="true" />';
             } else {
                 $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 "errors-exist":
             $Errors =& ShoppErrors();
             return $Errors->exist(SHOPP_AUTH_ERR);
             break;
         case "login-errors":
             $Errors =& ShoppErrors();
             $result = "";
             if (!$Errors->exist(SHOPP_AUTH_ERR)) {
                 return false;
             }
             $errors = $Errors->get(SHOPP_AUTH_ERR);
             foreach ((array) $errors as $error) {
                 if (!empty($error)) {
                     $result .= '<p class="error">' . $error->message() . '</p>';
                 }
             }
             $Errors->reset();
             return $result;
             break;
         case "menu":
             if (!$this->looping) {
                 reset($this->management);
                 $this->looping = true;
             } else {
                 next($this->management);
             }
             if (current($this->management)) {
                 return true;
             } else {
                 $this->looping = false;
                 reset($this->management);
                 return false;
             }
             break;
         case "management":
             if (array_key_exists('url', $options)) {
                 return add_query_arg('acct', key($this->management), $Shopp->link('account'));
             }
             if (array_key_exists('action', $options)) {
                 return key($this->management);
             }
             return $menus[key($this->management)];
         case "accounts":
             return $Shopp->Settings->get('account_system');
             break;
         case "order-lookup":
             $auth = $Shopp->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']) {
                     $Shopp->Cart->data->Purchase = $Purchase;
                     $Purchase->load_purchased();
                     ob_start();
                     include SHOPP_TEMPLATES . "/receipt.php";
                     $content = ob_get_contents();
                     ob_end_clean();
                     return '<div id="shopp">' . $content . '</div>';
                 }
             }
             ob_start();
             include SHOPP_ADMINPATH . "/orders/account.php";
             $content = ob_get_contents();
             ob_end_clean();
             return '<div id="shopp">' . $content . '</div>';
             break;
         case "firstname":
             if ($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 ($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 ($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 ($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 ($options['mode'] == "value") {
                 return $this->loginname;
             }
             if (!empty($this->login)) {
                 $options['value'] = $this->login;
             }
             return '<input type="text" name="login" id="login"' . inputattrs($options) . ' />';
             break;
         case "password":
             if ($options['mode'] == "value") {
                 return strlen($this->password) == 34 ? str_pad('&bull;', 8) : $this->password;
             }
             if (!empty($this->password)) {
                 $options['value'] = $this->password;
             }
             return '<input type="password" name="password" id="password"' . inputattrs($options) . ' />';
             break;
         case "confirm-password":
             if (!empty($this->confirm_password)) {
                 $options['value'] = $this->confirm_password;
             }
             return '<input type="password" name="confirm-password" id="confirm-password"' . inputattrs($options) . ' />';
             break;
         case "phone":
             if ($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 (empty($this->info)) {
                 return false;
             }
             if (!$this->looping) {
                 reset($this->info);
                 $this->looping = true;
             } else {
                 next($this->info);
             }
             if (current($this->info)) {
                 return true;
             } else {
                 $this->looping = false;
                 reset($this->info);
                 return false;
             }
             break;
         case "info":
             $info = current($this->info);
             $name = key($this->info);
             $allowed_types = array("text", "password", "hidden", "checkbox", "radio");
             if (empty($options['type'])) {
                 $options['type'] = "hidden";
             }
             if (in_array($options['type'], $allowed_types)) {
                 if ($options['mode'] == "name") {
                     return $name;
                 }
                 if ($options['mode'] == "value") {
                     return $info;
                 }
                 $options['value'] = $info;
                 return '<input type="text" name="info[' . $name . ']" id="customer-info-' . $name . '"' . inputattrs($options) . ' />';
             }
             break;
         case "save-button":
             if (!isset($options['label'])) {
                 $options['label'] = __('Save', 'Shopp');
             }
             $result = '<input type="hidden" name="customer" value="true" />';
             $result .= '<input type="submit" name="save" id="save-button"' . inputattrs($options) . ' />';
             return $result;
             break;
             // Downloads UI tags
         // Downloads UI tags
         case "hasdownloads":
         case "has-downloads":
             return !empty($this->downloads);
             break;
         case "downloads":
             if (empty($this->downloads)) {
                 return false;
             }
             if (!$this->looping) {
                 reset($this->downloads);
                 $this->looping = true;
             } else {
                 next($this->downloads);
             }
             if (current($this->downloads)) {
                 return true;
             } else {
                 $this->looping = false;
                 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 .= SHOPP_PERMALINKS ? $Shopp->shopuri . "download/" . $download->dkey : add_query_arg('shopp_download', $download->dkey, $Shopp->link('account'));
             }
             return $string;
             break;
             // Downloads UI tags
         // 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($Shopp->purchases)) {
                 $this->load_orders($filters);
             }
             return !empty($Shopp->purchases);
             break;
         case "purchases":
             if (!$this->looping) {
                 reset($Shopp->purchases);
                 $Shopp->Cart->data->Purchase = current($Shopp->purchases);
                 $this->looping = true;
             } else {
                 $Shopp->Cart->data->Purchase = next($Shopp->purchases);
             }
             if (current($Shopp->purchases)) {
                 $Shopp->Cart->data->Purchase = current($Shopp->purchases);
                 return true;
             } else {
                 $this->looping = false;
                 return false;
             }
             break;
         case "receipt":
             return add_query_arg(array('acct' => 'receipt', 'id' => $Shopp->Cart->data->Purchase->id), $Shopp->link('account'));
     }
 }