/** * Interface processor for the order manager * * @author Jonathan Davis * @return void **/ public function manager() { global $Shopp, $Notes; global $is_IIS; if (!current_user_can('shopp_orders')) { wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp')); } $Purchase = ShoppPurchase(); $Purchase->Customer = new ShoppCustomer($Purchase->customer); $Gateway = $Purchase->gateway(); if (!empty($_POST["send-note"])) { $user = wp_get_current_user(); shopp_add_order_event($Purchase->id, 'note', array('note' => stripslashes($_POST['note']), 'user' => $user->ID)); $Purchase->load_events(); } // Handle Order note processing if (!empty($_POST['note'])) { $this->addnote($Purchase->id, stripslashes($_POST['note']), !empty($_POST['send-note'])); } if (!empty($_POST['delete-note'])) { $noteid = key($_POST['delete-note']); $Note = new ShoppMetaObject(array('id' => $noteid, 'type' => 'order_note')); $Note->delete(); } if (!empty($_POST['edit-note'])) { $noteid = key($_POST['note-editor']); $Note = new ShoppMetaObject(array('id' => $noteid, 'type' => 'order_note')); $Note->value->message = stripslashes($_POST['note-editor'][$noteid]); $Note->save(); } $Notes = new ObjectMeta($Purchase->id, 'purchase', 'order_note'); if (isset($_POST['submit-shipments']) && isset($_POST['shipment']) && !empty($_POST['shipment'])) { $shipments = $_POST['shipment']; foreach ((array) $shipments as $shipment) { shopp_add_order_event($Purchase->id, 'shipped', array('tracking' => $shipment['tracking'], 'carrier' => $shipment['carrier'])); } $updated = __('Shipping notice sent.', 'Shopp'); // Save shipping carrier default preference for the user $userid = get_current_user_id(); $setting = 'shopp_shipping_carrier'; if (!get_user_meta($userid, $setting, true)) { add_user_meta($userid, $setting, $shipment['carrier']); } else { update_user_meta($userid, $setting, $shipment['carrier']); } unset($_POST['ship-notice']); $Purchase->load_events(); } if (isset($_POST['order-action']) && 'refund' == $_POST['order-action']) { if (!current_user_can('shopp_refund')) { wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp')); } $user = wp_get_current_user(); $reason = (int) $_POST['reason']; $amount = Shopp::floatval($_POST['amount']); $Purchase->load_events(); if (!empty($_POST['message'])) { $message = $_POST['message']; $Purchase->message['note'] = $message; } if ($amount <= $Purchase->captured - $Purchase->refunded) { if (!Shopp::str_true($_POST['send'])) { // Force the order status shopp_add_order_event($Purchase->id, 'notice', array('user' => $user->ID, 'kind' => 'refunded', 'notice' => __('Marked Refunded', 'Shopp'))); shopp_add_order_event($Purchase->id, 'refunded', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'amount' => $amount)); shopp_add_order_event($Purchase->id, 'voided', array('txnorigin' => $Purchase->txnid, 'txnid' => time(), 'gateway' => $Gateway->module)); } else { shopp_add_order_event($Purchase->id, 'refund', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'amount' => $amount, 'reason' => $reason, 'user' => $user->ID)); } if (!empty($_POST['message'])) { $this->addnote($Purchase->id, $_POST['message']); } $Purchase->load_events(); } else { $this->notice(Shopp::__('Refund failed. Cannot refund more than the current balance.'), 'error'); } } if (isset($_POST['order-action']) && 'cancel' == $_POST['order-action']) { if (!current_user_can('shopp_void')) { wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp')); } // unset($_POST['refund-order']); $user = wp_get_current_user(); $reason = (int) $_POST['reason']; $message = ''; if (!empty($_POST['message'])) { $message = $_POST['message']; $Purchase->message['note'] = $message; } else { $message = 0; } if (!Shopp::str_true($_POST['send'])) { // Force the order status shopp_add_order_event($Purchase->id, 'notice', array('user' => $user->ID, 'kind' => 'cancelled', 'notice' => __('Marked Cancelled', 'Shopp'))); shopp_add_order_event($Purchase->id, 'voided', array('txnorigin' => $Purchase->txnid, 'txnid' => time(), 'gateway' => $Gateway->module)); } else { shopp_add_order_event($Purchase->id, 'void', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'reason' => $reason, 'user' => $user->ID, 'note' => $message)); } if (!empty($_POST['message'])) { $this->addnote($Purchase->id, $_POST['message']); } $Purchase->load_events(); } if (isset($_POST['billing']) && is_array($_POST['billing'])) { $Purchase->updates($_POST['billing']); $Purchase->save(); } if (isset($_POST['shipping']) && is_array($_POST['shipping'])) { $shipping = array(); foreach ($_POST['shipping'] as $name => $value) { $shipping["ship{$name}"] = $value; } $Purchase->updates($shipping); $Purchase->shipname = $shipping['shipfirstname'] . ' ' . $shipping['shiplastname']; $Purchase->save(); } if (isset($_POST['order-action']) && 'update-customer' == $_POST['order-action'] && !empty($_POST['customer'])) { $Purchase->updates($_POST['customer']); $Purchase->save(); } if (isset($_POST['cancel-edit-customer'])) { unset($_POST['order-action'], $_POST['edit-customer'], $_POST['select-customer']); } if (isset($_POST['order-action']) && 'new-customer' == $_POST['order-action'] && !empty($_POST['customer']) && !isset($_POST['cancel-edit-customer'])) { $Customer = new ShoppCustomer(); $Customer->updates($_POST['customer']); $Customer->password = wp_generate_password(12, true); if ('wordpress' == shopp_setting('account_system')) { $Customer->create_wpuser(); } else { unset($_POST['loginname']); } $Customer->save(); if ((int) $Customer->id > 0) { $Purchase->copydata($Customer); $Purchase->save(); } else { $this->notice(__('An unknown error occured. The customer could not be created.', 'Shopp'), 'error'); } } if (isset($_GET['order-action']) && 'change-customer' == $_GET['order-action'] && !empty($_GET['customerid'])) { $Customer = new ShoppCustomer((int) $_GET['customerid']); if ((int) $Customer->id > 0) { $Purchase->copydata($Customer); $Purchase->customer = $Customer->id; $Purchase->save(); } else { $this->notice(__('The selected customer was not found.', 'Shopp'), 'error'); } } if (isset($_POST['save-item']) && !empty($_POST['lineid'])) { // Create a cart representation of the order to recalculate order totals $Cart = new ShoppCart(); foreach ($Purchase->purchased as $OrderItem) { $CartItem = new Item($OrderItem); $Cart->contents[$OrderItem->id] = $CartItem; } $purchasedid = (int) $_POST['lineid']; $Purchased = $Purchase->purchased[$purchasedid]; if ($Purchased->id) { $override_total = Shopp::floatval($_POST['total']) != $Purchased->total; // Override total $Item = $Cart->contents[$purchasedid]; $Item->quantity($_POST['quantity']); $Item->unitprice = Shopp::floatval($_POST['unitprice']); $Item->retotal(); $Purchased->quantity = $Item->quantity; $Purchased->unitprice = $Item->unitprice; $Purchased->unittax = $Item->unittax; $Purchased->total = $Item->total; if ($override_total) { $Purchased->total = Shopp::floatval($_POST['total']); } $Purchased->save(); } $Cart->retotal = true; $Cart->totals(); $Purchase->copydata($Cart->Totals); $Purchase->save(); } if (isset($_POST['charge']) && $Gateway && $Gateway->captures) { if (!current_user_can('shopp_capture')) { wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp')); } $user = wp_get_current_user(); shopp_add_order_event($Purchase->id, 'capture', array('txnid' => $Purchase->txnid, 'gateway' => $Purchase->gateway, 'amount' => $Purchase->capturable(), 'user' => $user->ID)); $Purchase->load_events(); } $base = shopp_setting('base_operations'); $targets = shopp_setting('target_markets'); $countries = array('' => ' '); $countrydata = Lookup::countries(); foreach ($countrydata as $iso => $c) { if ($base['country'] == $iso) { $base_region = $c['region']; } $countries[$iso] = $c['name']; } $Purchase->_countries = $countries; $regions = Lookup::country_zones(); $Purchase->_billing_states = array_merge(array('' => ' '), (array) $regions[$Purchase->country]); $Purchase->_shipping_states = array_merge(array('' => ' '), (array) $regions[$Purchase->shipcountry]); // Setup shipping carriers menu and JS data $carriers_menu = $carriers_json = array(); $shipping_carriers = (array) shopp_setting('shipping_carriers'); // The store-preferred shipping carriers $shipcarriers = Lookup::shipcarriers(); // The full list of available shipping carriers $notrack = Shopp::__('No Tracking'); // No tracking label $default = get_user_meta(get_current_user_id(), 'shopp_shipping_carrier', true); if (isset($shipcarriers[$default])) { $carriers_menu[$default] = $shipcarriers[$default]->name; $carriers_json[$default] = array($shipcarriers[$default]->name, $shipcarriers[$default]->trackpattern); } else { $carriers_menu['NOTRACKING'] = $notrack; $carriers_json['NOTRACKING'] = array($notrack, false); } $serviceareas = array('*', $base['country']); foreach ($shipcarriers as $code => $carrier) { if ($code == $default) { continue; } if (!empty($shipping_carriers) && !in_array($code, $shipping_carriers)) { continue; } if (!in_array($carrier->areas, $serviceareas)) { continue; } $carriers_menu[$code] = $carrier->name; $carriers_json[$code] = array($carrier->name, $carrier->trackpattern); } if (isset($shipcarriers[$default])) { $carriers_menu['NOTRACKING'] = $notrack; $carriers_json['NOTRACKING'] = array($notrack, false); } if (empty($statusLabels)) { $statusLabels = array(''); } include $this->ui('order.php'); }
/** * 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('•',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; } }
/** * Provides hidden checkout inputs required for proper checkout processing * * @api `shopp('checkout.function')` * @since 1.0 * * @param string $result The output * @param array $options The options * @param ShoppOrder $O The working object * @return string The generated hidden inputs **/ public static function checkout_function($result, $options, $O) { $Payments = $O->Payments; $defaults = array('updating' => '<div class="shoppui-spinfx-align"><span class="shoppui-spinner shoppui-spinfx shoppui-spinfx-steps8"></span></div>'); $options = array_merge($defaults, $options); extract($options); $regions = Lookup::country_zones(); $js = "var regions=" . json_encode($regions) . "," . "c_upd='" . $updating . "'," . "d_pm='" . $Payments->selected()->slug . "'," . "pm_cards={};"; foreach ($Payments as $slug => $option) { if (empty($option->cards)) { continue; } $js .= "pm_cards['" . $slug . "'] = " . json_encode($option->cards) . ";"; } add_storefrontjs($js, true); if (!empty($options['value'])) { $value = $options['value']; } else { $value = 'process'; } $output = '<div><input id="shopp-checkout-function" type="hidden" name="checkout" value="' . $value . '" /></div>'; if ('confirmed' == $value) { $output = apply_filters('shopp_confirm_form', $output); } else { $output = apply_filters('shopp_checkout_form', $output); } return $output; }
/** * Displays the General Settings screen and processes updates * * @author Jonathan Davis * @since 1.0 * * @return void **/ public function setup() { if (!current_user_can('shopp_settings')) { wp_die(__('You do not have sufficient permissions to access this page.')); } // Welcome screen handling if (!empty($_POST['setup'])) { $_POST['settings']['display_welcome'] = 'off'; shopp_set_formsettings(); } $country = isset($_POST['settings']) && isset($_POST['settings']['base_operations']) ? $_POST['settings']['base_operations']['country'] : ''; $countries = array(); $countrydata = Lookup::countries(); $country_zones = Lookup::country_zones(); foreach ($countrydata as $iso => $c) { if ($country == $iso) { $base_region = $c['region']; } $countries[$iso] = $c['name']; } // Save settings if (!empty($_POST['save']) && isset($_POST['settings'])) { check_admin_referer('shopp-setup'); if (isset($_POST['settings']['base_operations'])) { $baseop =& $_POST['settings']['base_operations']; $zone = isset($baseop['zone']) && isset($country_zones[$country]) && isset($country_zones[$country][$baseop['zone']]) ? $baseop['zone'] : false; if (isset($countrydata[$country])) { $baseop = $countrydata[$country]; } $baseop['country'] = $country; $baseop['zone'] = $zone; $baseop['currency']['format'] = scan_money_format($baseop['currency']['format']); if (is_array($baseop['currency']['format'])) { $fields = array_keys($baseop['currency']['format']); foreach ($fields as $field) { if (isset($baseop['currency'][$field])) { $baseop['currency']['format'][$field] = $baseop['currency'][$field]; } } } shopp_set_setting('tax_inclusive', in_array($country, Lookup::country_inclusive_taxes()) ? 'on' : 'off'); } if (!isset($_POST['settings']['target_markets'])) { asort($_POST['settings']['target_markets']); } shopp_set_formsettings(); $updated = __('Shopp settings saved.', 'Shopp'); } $operations = shopp_setting('base_operations'); if (isset($country_zones[$operations['country']])) { $zones = $country_zones[$operations['country']]; } $targets = shopp_setting('target_markets'); if (is_array($targets)) { $targets = array_map('stripslashes', $targets); } if (!$targets) { $targets = array(); } include $this->ui('setup.php'); }
public function taxrates() { if (!current_user_can('shopp_settings_taxes')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $edit = false; if (isset($_REQUEST['id'])) { $edit = (int) $_REQUEST['id']; } $localerror = false; $rates = shopp_setting('taxrates'); if (!is_array($rates)) { $rates = array(); } if (isset($_GET['delete'])) { check_admin_referer('shopp_delete_taxrate'); $delete = (int) $_GET['delete']; if (isset($rates[$delete])) { array_splice($rates, $delete, 1); } shopp_set_setting('taxrates', $rates); } if (isset($_POST['editing'])) { $rates[$edit] = $_POST['settings']['taxrates'][$edit]; } if (isset($_POST['addrule'])) { $rates[$edit]['rules'][] = array('p' => '', 'v' => ''); } if (isset($_POST['deleterule'])) { check_admin_referer('shopp-settings-taxrates'); list($rateid, $row) = explode(',', $_POST['deleterule']); if (isset($rates[$rateid]) && isset($rates[$rateid]['rules'])) { array_splice($rates[$rateid]['rules'], $row, 1); shopp_set_setting('taxrates', $rates); } } if (isset($rates[$edit]['haslocals'])) { $rates[$edit]['haslocals'] = $rates[$edit]['haslocals'] == 'true' || $rates[$edit]['haslocals'] == '1'; } if (isset($_POST['add-locals'])) { $rates[$edit]['haslocals'] = true; } if (isset($_POST['remove-locals'])) { $rates[$edit]['haslocals'] = false; $rates[$edit]['locals'] = array(); } $upload = $this->taxrate_upload(); if ($upload !== false) { if (isset($upload['error'])) { $localerror = $upload['error']; } else { $rates[$edit]['locals'] = $upload; } } if (isset($_POST['editing'])) { // Re-sort taxes from generic to most specific usort($rates, array($this, 'taxrates_sorting')); $rates = stripslashes_deep($rates); shopp_set_setting('taxrates', $rates); } if (isset($_POST['addrate'])) { $edit = count($rates); } if (isset($_POST['submit'])) { $edit = false; } $base = shopp_setting('base_operations'); $specials = array(ShoppTax::ALL => Shopp::__('All Markets')); if (ShoppTax::euvat(false, $base['country'], ShoppTax::EUVAT)) { $specials[ShoppTax::EUVAT] = Shopp::__('European Union'); } $countries = array_merge($specials, (array) shopp_setting('target_markets')); $zones = Lookup::country_zones(); include $this->ui('taxrates.php'); }
/** * Interface processor for the customer editor * * Handles rendering the interface, processing updated customer details * and handing saving them back to the database * * @return void **/ function editor () { global $Ecart,$Customer; $db =& DB::get(); if ( !(is_ecart_userlevel() || current_user_can('ecart_customers')) ) wp_die(__('You do not have sufficient permissions to access this page.')); if ($_GET['id'] != "new") { $Customer = new Customer($_GET['id']); $Customer->Billing = new Billing($Customer->id,'customer'); $Customer->Shipping = new Shipping($Customer->id,'customer'); if (empty($Customer->id)) wp_die(__('The requested customer record does not exist.','Ecart')); } else $Customer = new Customer(); if (empty($Customer->info->meta)) remove_meta_box('customer-info','ecart_page_ecart-customers','normal'); $purchase_table = DatabaseObject::tablename(Purchase::$table); $r = $db->query("SELECT count(id) AS purchases,SUM(total) AS total FROM $purchase_table WHERE customer='$Customer->id' LIMIT 1"); $Customer->orders = $r->purchases; $Customer->total = $r->total; $countries = array(''=>' '); $countrydata = Lookup::countries(); foreach ($countrydata as $iso => $c) { if (isset($_POST['settings']) && $_POST['settings']['base_operations']['country'] == $iso) $base_region = $c['region']; $countries[$iso] = $c['name']; } $Customer->countries = $countries; $regions = Lookup::country_zones(); $Customer->billing_states = array_merge(array(''=>' '),(array)$regions[$Customer->Billing->country]); $Customer->shipping_states = array_merge(array(''=>' '),(array)$regions[$Customer->Shipping->country]); include(ECART_ADMIN_PATH."/customers/editor.php"); }
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('•',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; } }
/** * Provides the billing address state/province name * * @api `shopp('purchase.state')` * @since 1.0 * * @param string $result The output * @param array $options The options * @param ShoppPurchase $O The working object * @return string The billing address state name **/ public static function state($result, $options, $O) { $state = esc_html($O->state); if (strlen($O->state) > 2) { return $state; } $regions = Lookup::country_zones(); if (isset($regions[$O->country])) { $states = $regions[$O->country]; if (isset($states[$O->state])) { return esc_html($states[$O->state]); } } return $state; }
function taxes () { if ( !(current_user_can('manage_options') && current_user_can('ecart_settings_taxes')) ) wp_die(__('You do not have sufficient permissions to access this page.')); if (!empty($_POST['save'])) { check_admin_referer('ecart-settings-taxes'); $this->settings_save(); $updated = __('Ecart taxes settings saved.','Ecart'); } $rates = $this->Settings->get('taxrates'); $base = $this->Settings->get('base_operations'); $countries = array_merge(array('*' => __('All Markets','Ecart')), $this->Settings->get('target_markets')); $zones = Lookup::country_zones(); include(ECART_ADMIN_PATH."/settings/taxes.php"); }
public function location_menu($destination = false, $row = 0, $module = false) { if (!$module) { $module = $this->module; } $menuarrow = ' ▾'; $tab = str_repeat('⋅', 3) . ' '; $regions = Lookup::regions(); $countries = Lookup::countries(); $regional_countries = array(); $country_areas = array(); $country_zones = array(); $postcode = false; $subregions = isset($_POST[$module]['table'][$row]['subregions']); $selection = array(); $selected = array('region' => '*', 'country' => '', 'area' => '', 'zone' => ''); if (strpos($destination, ',') !== false) { $selection = explode(',', $destination); } else { $selection = array($destination); } if ($subregions && isset($_POST[$module]['table'][$row]['destination'])) { $selection = explode(',', $_POST[$module]['table'][$row]['destination']); } if (!is_array($selection)) { $selection = array($selection); } $keys = array_slice(array_keys($selected), 0, count($selection)); $selected = array_merge($selected, array_combine($keys, $selection)); $regional_countries = array_filter($countries, create_function('$c', 'return (\'' . $selected['region'] . '\' === (string)$c[\'region\']);')); if (!empty($selected['country'])) { $ca = Lookup::country_areas(); if (isset($ca[$selected['country']])) { $country_areas = $ca[$selected['country']]; } $cz = Lookup::country_zones(); if (isset($cz[$selected['country']])) { $country_zones = $cz[$selected['country']]; } } $options = array('*' => __('Anywhere', 'Shopp')); foreach ($regions as $index => $region) { if ($index == $selected['region'] && !empty($regional_countries) && ($subregions || !empty($selected['country']))) { $options[$index] = $region . $menuarrow; foreach ($regional_countries as $country => $country_data) { $country_name = $country_data['name']; if ($country == $selected['country']) { $postcodes = Lookup::postcodes(); $postcode = isset($postcodes[$selected['country']]); if (!empty($country_areas) && ($subregions || !empty($selected['area']))) { $options["{$index},{$country}"] = $country_name . $menuarrow; $areas = array_keys($country_areas); foreach ($areas as $area => $area_name) { if ((string) $area == (string) $selected['area']) { $zones = array_flip($country_areas[$area_name]); $zones = array_intersect_key($country_zones, $zones); $group_name = $area_name . $menuarrow; $options[$group_name] = array(); // Setup option group for area zones if (empty($selected['zone'])) { $selected['zone'] = key($zones); } foreach ($zones as $zone => $zone_name) { $options[$group_name]["{$index},{$country},{$area},{$zone}"] = $zone_name . ', ' . substr($country, 0, 2); } // end foreach($country_zones) } else { $options["{$index},{$country},{$area}"] = str_repeat(' ', 2) . $area_name; } } // end foreach($areas) } elseif (!empty($country_zones) && ($subregions || !empty($selected['area']))) { $options[$country_name] = array(); if (empty($selected['area'])) { $selected['area'] = key($country_zones); } foreach ($country_zones as $zone => $zone_name) { $options[$country_name]["{$index},{$country},{$zone}"] = $zone_name . ', ' . substr($country, 0, 2); } // end foreach($country_zones) } else { $options["{$index},{$country}"] = $country_name; } } else { $options["{$index},{$country}"] = $tab . $country_name; } } // end foreach ($regional_countries) } else { $options[$index] = $region; } } // end foreach ($regions) $selected = array_filter($selected, create_function('$i', 'return (\'\' != $i);')); $selection = join(',', $selected); return array('options' => $options, 'selection' => $selection, 'postcode' => $postcode); }
/** * Interface processor for the customer editor * * Handles rendering the interface, processing updated customer details * and handing saving them back to the database * * @author Jonathan Davis * @return void **/ public function editor() { if (!current_user_can('shopp_customers')) { wp_die(__('You do not have sufficient permissions to access this page.')); } if ($_GET['id'] != "new") { $Customer = new ShoppCustomer($_GET['id']); $Customer->Billing = new BillingAddress($Customer->id, 'customer'); $Customer->Shipping = new ShippingAddress($Customer->id, 'customer'); if (empty($Customer->id)) { wp_die(__('The requested customer record does not exist.', 'Shopp')); } } else { $Customer = new ShoppCustomer(); } if (empty($Customer->info->meta)) { remove_meta_box('customer-info', 'shopp_page_shopp-customers', 'normal'); } if ($Customer->id > 0) { $purchase_table = ShoppDatabaseObject::tablename(ShoppPurchase::$table); $r = sDB::query("SELECT count(id) AS purchases,SUM(total) AS total FROM {$purchase_table} WHERE customer='{$Customer->id}' LIMIT 1"); $Customer->orders = $r->purchases; $Customer->total = $r->total; } $countries = array('' => ' '); $countrydata = Lookup::countries(); foreach ($countrydata as $iso => $c) { if (isset($_POST['settings']) && $_POST['settings']['base_operations']['country'] == $iso) { $base_region = $c['region']; } $countries[$iso] = $c['name']; } $Customer->countries = $countries; $regions = Lookup::country_zones(); $Customer->billing_states = array_merge(array('' => ' '), (array) $regions[$Customer->Billing->country]); $Customer->shipping_states = array_merge(array('' => ' '), (array) $regions[$Customer->Shipping->country]); include $this->ui('editor.php'); }
public function country_zones() { check_admin_referer('wp_ajax_shopp_country_zones'); $zones = Lookup::country_zones(); if (isset($_GET['country']) && isset($zones[$_GET['country']])) { echo json_encode($zones[$_GET['country']]); } else { echo json_encode(false); } exit; }
function screen() { if (!current_user_can('shopp_orders')) { wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp')); } $Purchase = ShoppPurchase(); $Purchase->Customer = new ShoppCustomer($Purchase->customer); $Gateway = $Purchase->gateway(); if (!empty($_POST['send-note'])) { $user = wp_get_current_user(); shopp_add_order_event($Purchase->id, 'note', array('note' => stripslashes($_POST['note']), 'user' => $user->ID)); $Purchase->load_events(); } if (isset($_POST['submit-shipments']) && isset($_POST['shipment']) && !empty($_POST['shipment'])) { $shipments = $_POST['shipment']; foreach ((array) $shipments as $shipment) { shopp_add_order_event($Purchase->id, 'shipped', array('tracking' => $shipment['tracking'], 'carrier' => $shipment['carrier'])); } $updated = __('Shipping notice sent.', 'Shopp'); // Save shipping carrier default preference for the user $userid = get_current_user_id(); $setting = 'shopp_shipping_carrier'; if (!get_user_meta($userid, $setting, true)) { add_user_meta($userid, $setting, $shipment['carrier']); } else { update_user_meta($userid, $setting, $shipment['carrier']); } unset($_POST['ship-notice']); $Purchase->load_events(); } if (isset($_POST['order-action']) && 'refund' == $_POST['order-action']) { if (!current_user_can('shopp_refund')) { wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp')); } $user = wp_get_current_user(); $reason = (int) $_POST['reason']; $amount = Shopp::floatval($_POST['amount']); if (!empty($_POST['message'])) { $message = $_POST['message']; $Purchase->message['note'] = $message; } if (!Shopp::str_true($_POST['send'])) { // Force the order status shopp_add_order_event($Purchase->id, 'notice', array('user' => $user->ID, 'kind' => 'refunded', 'notice' => __('Marked Refunded', 'Shopp'))); shopp_add_order_event($Purchase->id, 'refunded', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'amount' => $amount)); shopp_add_order_event($Purchase->id, 'voided', array('txnorigin' => $Purchase->txnid, 'txnid' => time(), 'gateway' => $Gateway->module)); } else { shopp_add_order_event($Purchase->id, 'refund', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'amount' => $amount, 'reason' => $reason, 'user' => $user->ID)); } if (!empty($_POST['message'])) { $this->addnote($Purchase->id, $_POST['message']); } $Purchase->load_events(); } if (isset($_POST['order-action']) && 'cancel' == $_POST['order-action']) { if (!current_user_can('shopp_void')) { wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp')); } // unset($_POST['refund-order']); $user = wp_get_current_user(); $reason = (int) $_POST['reason']; $message = ''; if (!empty($_POST['message'])) { $message = $_POST['message']; $Purchase->message['note'] = $message; } else { $message = 0; } if (!Shopp::str_true($_POST['send'])) { // Force the order status shopp_add_order_event($Purchase->id, 'notice', array('user' => $user->ID, 'kind' => 'cancelled', 'notice' => __('Marked Cancelled', 'Shopp'))); shopp_add_order_event($Purchase->id, 'voided', array('txnorigin' => $Purchase->txnid, 'txnid' => time(), 'gateway' => $Gateway->module)); } else { shopp_add_order_event($Purchase->id, 'void', array('txnid' => $Purchase->txnid, 'gateway' => $Gateway->module, 'reason' => $reason, 'user' => $user->ID, 'note' => $message)); } if (!empty($_POST['message'])) { $this->addnote($Purchase->id, $_POST['message']); } $Purchase->load_events(); } if (isset($_POST['billing']) && is_array($_POST['billing'])) { $Purchase->updates($_POST['billing']); $Purchase->save(); } if (isset($_POST['shipping']) && is_array($_POST['shipping'])) { $shipping = array(); foreach ($_POST['shipping'] as $name => $value) { $shipping["ship{$name}"] = $value; } $Purchase->updates($shipping); $Purchase->shipname = $shipping['shipfirstname'] . ' ' . $shipping['shiplastname']; $Purchase->save(); } if (isset($_POST['order-action']) && 'update-customer' == $_POST['order-action'] && !empty($_POST['customer'])) { $Purchase->updates($_POST['customer']); $Purchase->save(); } if (isset($_POST['cancel-edit-customer'])) { unset($_POST['order-action'], $_POST['edit-customer'], $_POST['select-customer']); } // Create a new customer if (isset($_POST['order-action']) && 'new-customer' == $_POST['order-action'] && !empty($_POST['customer']) && !isset($_POST['cancel-edit-customer'])) { $Customer = new ShoppCustomer(); $Customer->updates($_POST['customer']); $Customer->password = wp_generate_password(12, true); if ('wordpress' == shopp_setting('account_system')) { $Customer->create_wpuser(); } else { unset($_POST['loginname']); } $Customer->save(); if ((int) $Customer->id > 0) { $Purchase->customer = $Customer->id; $Purchase->copydata($Customer); $Purchase->save(); // New billing address, create record for new customer if (isset($_POST['billing']) && is_array($_POST['billing']) && empty($_POST['billing']['id'])) { $Billing = new BillingAddress($_POST['billing']); $Billing->customer = $Customer->id; $Billing->save(); } // New shipping address, create record for new customer if (isset($_POST['shipping']) && is_array($_POST['shipping']) && empty($_POST['shipping']['id'])) { $Shipping = new ShippingAddress($_POST['shipping']); $Shipping->customer = $Customer->id; $Shipping->save(); } } else { $this->notice(Shopp::__('An unknown error occured. The customer could not be created.'), 'error'); } } if (isset($_GET['order-action']) && 'change-customer' == $_GET['order-action'] && !empty($_GET['customerid'])) { $Customer = new ShoppCustomer((int) $_GET['customerid']); if ((int) $Customer->id > 0) { $Purchase->copydata($Customer); $Purchase->customer = $Customer->id; $Purchase->save(); } else { $this->notice(Shopp::__('The selected customer was not found.'), 'error'); } } if (isset($_POST['save-item']) && isset($_POST['lineid'])) { if (isset($_POST['lineid']) && '' == $_POST['lineid']) { $lineid = 'new'; } else { $lineid = (int) $_POST['lineid']; } $name = $_POST['itemname']; if (!empty($_POST['product'])) { list($productid, $priceid) = explode('-', $_POST['product']); $Product = new ShoppProduct($productid); $Price = new ShoppPrice($priceid); $name = $Product->name; if (Shopp::__('Price & Delivery') != $Price->label) { $name .= ": {$Price->label}"; } } // Create a cart representation of the order to recalculate order totals $Cart = new ShoppCart(); $taxcountry = $Purchase->country; $taxstate = $Purchase->state; if (!empty($Purchase->shipcountry) && !empty($Purchase->shipstate)) { $taxcountry = $Purchase->shipcountry; $taxstate = $Purchase->shipstate; } ShoppOrder()->Tax->location($taxcountry, $taxstate); if ('new' == $lineid) { $NewLineItem = new ShoppPurchased(); $NewLineItem->purchase = $Purchase->id; $Purchase->purchased[] = $NewLineItem; } foreach ($Purchase->purchased as &$Purchased) { $CartItem = new ShoppCartItem($Purchased); if ($Purchased->id == $lineid || 'new' == $lineid && empty($Purchased->id)) { if (!empty($_POST['product'])) { list($CartItem->product, $CartItem->priceline) = explode('-', $_POST['product']); } elseif (!empty($_POST['id'])) { list($CartItem->product, $CartItem->priceline) = explode('-', $_POST['id']); } $CartItem->name = $name; $CartItem->unitprice = Shopp::floatval($_POST['unitprice']); $Cart->additem((int) $_POST['quantity'], $CartItem); $CartItem = $Cart->get($CartItem->fingerprint()); $Purchased->name = $CartItem->name; $Purchased->product = $CartItem->product; $Purchased->price = $CartItem->priceline; $Purchased->quantity = $CartItem->quantity; $Purchased->unitprice = $CartItem->unitprice; $Purchased->total = $CartItem->total; $Purchased->save(); } else { $Cart->additem($CartItem->quantity, $CartItem); } } $Cart->Totals->register(new OrderAmountShipping(array('id' => 'cart', 'amount' => $Purchase->freight))); $Purchase->total = $Cart->total(); $Purchase->subtotal = $Cart->total('order'); $Purchase->discount = $Cart->total('discount'); $Purchase->tax = $Cart->total('tax'); $Purchase->freight = $Cart->total('shipping'); $Purchase->save(); $Purchase->load_purchased(); } if (!empty($_POST['save-totals'])) { $totals = array(); if (!empty($_POST['totals'])) { $totals = $_POST['totals']; } $objects = array('tax' => 'OrderAmountTax', 'shipping' => 'OrderAmountShipping', 'discount' => 'OrderAmountDiscount'); $methods = array('fee' => 'fees', 'tax' => 'taxes', 'shipping' => 'shipfees', 'discount' => 'discounts'); $total = 0; foreach ($totals as $property => $fields) { if (empty($fields)) { continue; } if (count($fields) > 1) { if (isset($fields['labels'])) { $labels = $fields['labels']; unset($fields['labels']); if (count($fields) > count($labels)) { $totalfield = array_pop($fields); } $fields = array_combine($labels, $fields); } $fields = array_map(array('Shopp', 'floatval'), $fields); $entries = array(); $OrderAmountObject = isset($objects[$property]) ? $objects[$property] : 'OrderAmountFee'; foreach ($fields as $label => $amount) { $entries[] = new $OrderAmountObject(array('id' => count($entries) + 1, 'label' => $label, 'amount' => $amount)); } $savetotal = isset($methods[$property]) ? $methods[$property] : $fees; $Purchase->{$savetotal}($entries); $sum = array_sum($fields); if ($sum > 0) { $Purchase->{$property} = $sum; } } else { $Purchase->{$property} = Shopp::floatval($fields[0]); } $total += 'discount' == $property ? $Purchase->{$property} * -1 : $Purchase->{$property}; } $Purchase->total = $Purchase->subtotal + $total; $Purchase->save(); } if (!empty($_GET['rmvline'])) { $lineid = (int) $_GET['rmvline']; if (isset($Purchase->purchased[$lineid])) { $Purchase->purchased[$lineid]->delete(); unset($Purchase->purchased[$lineid]); } $Cart = new ShoppCart(); $taxcountry = $Purchase->country; $taxstate = $Purchase->state; if (!empty($Purchase->shipcountry) && !empty($Purchase->shipstate)) { $taxcountry = $Purchase->shipcountry; $taxstate = $Purchase->shipstate; } ShoppOrder()->Tax->location($taxcountry, $taxstate); foreach ($Purchase->purchased as &$Purchased) { $Cart->additem($Purchased->quantity, new ShoppCartItem($Purchased)); } $Cart->Totals->register(new OrderAmountShipping(array('id' => 'cart', 'amount' => $Purchase->freight))); $Purchase->total = $Cart->total(); $Purchase->subtotal = $Cart->total('order'); $Purchase->discount = $Cart->total('discount'); $Purchase->tax = $Cart->total('tax'); $Purchase->freight = $Cart->total('shipping'); $Purchase->save(); $Purchase->load_purchased(); } if (isset($_POST['charge']) && $Gateway && $Gateway->captures) { if (!current_user_can('shopp_capture')) { wp_die(__('You do not have sufficient permissions to carry out this action.', 'Shopp')); } $user = wp_get_current_user(); shopp_add_order_event($Purchase->id, 'capture', array('txnid' => $Purchase->txnid, 'gateway' => $Purchase->gateway, 'amount' => $Purchase->capturable(), 'user' => $user->ID)); $Purchase->load_events(); } $targets = shopp_setting('target_markets'); $default = array('' => ' '); $Purchase->_countries = array_merge($default, ShoppLookup::countries()); $regions = Lookup::country_zones(); $Purchase->_billing_states = array_merge($default, (array) $regions[$Purchase->country]); $Purchase->_shipping_states = array_merge($default, (array) $regions[$Purchase->shipcountry]); // Setup shipping carriers menu and JS data $carriers_menu = $carriers_json = array(); $shipping_carriers = (array) shopp_setting('shipping_carriers'); // The store-preferred shipping carriers $shipcarriers = Lookup::shipcarriers(); // The full list of available shipping carriers $notrack = Shopp::__('No Tracking'); // No tracking label $default = get_user_meta(get_current_user_id(), 'shopp_shipping_carrier', true); if (isset($shipcarriers[$default])) { $carriers_menu[$default] = $shipcarriers[$default]->name; $carriers_json[$default] = array($shipcarriers[$default]->name, $shipcarriers[$default]->trackpattern); } else { $carriers_menu['NOTRACKING'] = $notrack; $carriers_json['NOTRACKING'] = array($notrack, false); } $serviceareas = array('*', ShoppBaseLocale()->country()); foreach ($shipcarriers as $code => $carrier) { if ($code == $default) { continue; } if (!empty($shipping_carriers) && !in_array($code, $shipping_carriers)) { continue; } if (!in_array($carrier->areas, $serviceareas)) { continue; } $carriers_menu[$code] = $carrier->name; $carriers_json[$code] = array($carrier->name, $carrier->trackpattern); } if (isset($shipcarriers[$default])) { $carriers_menu['NOTRACKING'] = $notrack; $carriers_json['NOTRACKING'] = array($notrack, false); } if (empty($statusLabels)) { $statusLabels = array(''); } $Purchase->taxes(); $Purchase->discounts(); $columns = get_column_headers($this->id); $hidden = get_hidden_columns($this->id); include $this->ui('new.php'); }
/** * Queues Shopp storefront javascript and styles as needed * * @author Jonathan Davis * @since 1.1 * * @return void **/ public function behaviors() { $Shopp = Shopp::object(); if (is_ssl()) { $urls = array('option_siteurl', 'option_home', 'option_url', 'option_wpurl', 'option_stylesheet_url', 'option_template_url', 'script_loader_src'); foreach ($urls as $filter) { add_filter($filter, 'force_ssl'); } } // Replace the WordPress canonical link remove_action('wp_head', 'rel_canonical'); add_action('wp_head', array($this, 'header')); add_action('wp_footer', array($this, 'footer')); wp_enqueue_style('shopp.catalog', SHOPP_ADMIN_URI . '/styles/catalog.css', array(), 20110511, 'screen'); wp_enqueue_style('shopp.icons', SHOPP_ADMIN_URI . '/styles/icons.css', array(), 20110511, 'screen'); wp_enqueue_style('shopp', Shopp::template_url('shopp.css'), array(), 20110511, 'screen'); wp_enqueue_style('shopp.colorbox', SHOPP_ADMIN_URI . '/styles/colorbox.css', array(), 20110511, 'screen'); $orderhistory = is_account_page() && isset($_GET['id']) && !empty($_GET['id']); if (is_thanks_page() || $orderhistory) { wp_enqueue_style('shopp.printable', SHOPP_ADMIN_URI . '/styles/printable.css', array(), 20110511, 'print'); } $loading = shopp_setting('script_loading'); if (!$loading || 'global' == $loading || !empty($page)) { shopp_enqueue_script('colorbox'); shopp_enqueue_script('shopp'); shopp_enqueue_script('catalog'); shopp_enqueue_script('cart'); if (is_catalog_page()) { shopp_custom_script('catalog', "var pricetags = {};\n"); } } if (is_checkout_page()) { shopp_enqueue_script('address'); shopp_enqueue_script('checkout'); } if (is_confirm_page()) { shopp_enqueue_script('checkout'); } if (is_account_page()) { shopp_enqueue_script('address'); $regions = Lookup::country_zones(); $js = 'var regions=' . json_encode($regions); add_storefrontjs($js, true); } }
function tag ($property,$options=array()) { global $Ecart; $taxes = isset($options['taxes'])?$options['taxes']:false; $taxrate = 0; if ($property == "item-unitprice" || $property == "item-total") $taxrate = ecart_taxrate($taxes); // Return strings with no options switch ($property) { case "receipt": // Skip the receipt processing when sending order notifications in admin without the receipt if (defined('WP_ADMIN') && isset($_POST['receipt']) && $_POST['receipt'] == "no") return; if (isset($options['template']) && is_readable(ECART_TEMPLATES."/".$options['template'])) return $this->receipt($template); else return $this->receipt(); break; case "url": return ecarturl(false,'account'); break; case "id": return $this->id; break; case "customer": return $this->customer; break; case "date": if (empty($options['format'])) $options['format'] = get_option('date_format').' '.get_option('time_format'); return _d($options['format'],((is_int($this->created))?$this->created:mktimestamp($this->created))); break; case "card": return (!empty($this->card))?sprintf("%'X16d",$this->card):''; break; case "cardtype": return $this->cardtype; break; case "txnid": case "transactionid": return $this->txnid; break; case "firstname": return esc_html($this->firstname); break; case "lastname": return esc_html($this->lastname); break; case "company": return esc_html($this->company); break; case "email": return esc_html($this->email); break; case "phone": return esc_html($this->phone); break; case "address": return esc_html($this->address); break; case "xaddress": return esc_html($this->xaddress); break; case "city": return esc_html($this->city); break; case "state": if (strlen($this->state > 2)) return esc_html($this->state); $regions = Lookup::country_zones(); $states = $regions[$this->country]; return $states[$this->state]; break; case "postcode": return esc_html($this->postcode); break; case "country": $countries = $Ecart->Settings->get('target_markets'); return $countries[$this->country]; break; case "shipaddress": return esc_html($this->shipaddress); break; case "shipxaddress": return esc_html($this->shipxaddress); break; case "shipcity": return esc_html($this->shipcity); break; case "shipstate": if (strlen($this->shipstate > 2)) return esc_html($this->shipstate); $regions = Lookup::country_zones(); $states = $regions[$this->country]; return $states[$this->shipstate]; break; case "shippostcode": return esc_html($this->shippostcode); break; case "shipcountry": $countries = $Ecart->Settings->get('target_markets'); return $countries[$this->shipcountry]; break; case "shipmethod": return esc_html($this->shipmethod); break; case "totalitems": return count($this->purchased); break; case "has-items": case "hasitems": if (empty($this->purchased)) $this->load_purchased(); return (count($this->purchased) > 0); break; case "items": if (!isset($this->_items_loop)) { reset($this->purchased); $this->_items_loop = true; } else next($this->purchased); if (current($this->purchased) !== false) return true; else { unset($this->_items_loop); return false; } case "item-id": $item = current($this->purchased); return $item->id; break; case "item-product": $item = current($this->purchased); return $item->product; break; case "item-price": $item = current($this->purchased); return $item->price; break; case "item-name": $item = current($this->purchased); return $item->name; break; case "item-description": $item = current($this->purchased); return $item->description; break; case "item-options": if (!isset($options['after'])) $options['after'] = ""; $item = current($this->purchased); return (!empty($item->optionlabel))?$options['before'].$item->optionlabel.$options['after']:''; break; case "item-sku": $item = current($this->purchased); return $item->sku; break; case "item-download": $item = current($this->purchased); if (empty($item->download)) return ""; if (!isset($options['label'])) $options['label'] = __('Download','Ecart'); $classes = ""; if (isset($options['class'])) $classes = ' class="'.$options['class'].'"'; $request = ECART_PRETTYURLS? "download/$item->dkey": array('src'=>'download','ecart_download'=>$item->dkey); $url = ecarturl($request,'catalog'); return '<a href="'.$url.'"'.$classes.'>'.$options['label'].'</a>'; break; case "item-quantity": $item = current($this->purchased); return $item->quantity; break; case "item-unitprice": $item = current($this->purchased); $amount = $item->unitprice+($this->taxing == 'inclusive'?$item->unittax:0); return money($amount); break; case "item-total": $item = current($this->purchased); $amount = $item->total+($this->taxing == 'inclusive'?$item->unittax*$item->quantity:0); return money($amount); break; case "item-has-inputs": case "item-hasinputs": $item = current($this->purchased); return (count($item->data) > 0); break; case "item-inputs": $item = current($this->purchased); if (!isset($this->_iteminputs_loop)) { reset($item->data); $this->_iteminputs_loop = true; } else next($item->data); if (current($item->data) !== false) return true; else { unset($this->_iteminputs_loop); return false; } break; case "item-input": $item = current($this->purchased); $data = current($item->data); $name = key($item->data); if (isset($options['name'])) return esc_html($name); return esc_html($data); break; case "item-inputs-list": case "item-inputslist": case "item-inputs-list": case "iteminputslist": $item = current($this->purchased); if (empty($item->data)) return false; $before = ""; $after = ""; $classes = ""; $excludes = array(); if (!empty($options['class'])) $classes = ' class="'.$options['class'].'"'; if (!empty($options['exclude'])) $excludes = explode(",",$options['exclude']); if (!empty($options['before'])) $before = $options['before']; if (!empty($options['after'])) $after = $options['after']; $result .= $before.'<ul'.$classes.'>'; foreach ($item->data as $name => $data) { if (in_array($name,$excludes)) continue; $result .= '<li><strong>'.esc_html($name).'</strong>: '.esc_html($data).'</li>'; } $result .= '</ul>'.$after; return $result; break; case "item-has-addons": case "item-hasaddons": $item = current($this->purchased); return (count($item->addons) > 0); break; case "item-addons": $item = current($this->purchased); if (!isset($this->_itemaddons_loop)) { reset($item->addons->meta); $this->_itemaddons_loop = true; } else next($item->addons->meta); if (current($item->addons->meta) !== false) return true; else { unset($this->_itemaddons_loop); return false; } break; case "item-addons": $item = current($this->purchased); $addon = current($item->addons->meta); if (isset($options['id'])) return esc_html($addon->id); if (isset($options['name'])) return esc_html($addon->name); if (isset($options['label'])) return esc_html($addon->name); if (isset($options['type'])) return esc_html($addon->value->type); if (isset($options['onsale'])) return $addon->value->onsale; if (isset($options['inventory'])) return $addon->value->inventory; if (isset($options['sku'])) return esc_html($addon->value->sku); if (isset($options['unitprice'])) return money($addon->value->unitprice); return money($addon->value->unitprice); break; case "item-addons-list": case "item-addonslist": case "item-addons-list": case "itemaddonslist": $item = current($this->purchased); if (empty($item->addons)) return false; $defaults = array( 'prices' => "on", 'download' => __('Download','Ecart'), 'before' => '', 'after' => '', 'classes' => '', 'excludes' => '' ); $options = array_merge($defaults,$options); extract($options); $class = !empty($classes)?' class="'.join(' ',explode(',',$classes)).'"':''; $taxrate = 0; if ($item->unitprice > 0) $taxrate = round($item->unittax/$item->unitprice,4); $result = $before.'<ul'.$class.'>'; foreach ($item->addons->meta as $id => $addon) { if (in_array($addon->name,$excludes)) continue; if ($this->taxing == "inclusive") $price = $addon->value->unitprice+($addon->value->unitprice*$taxrate); else $price = $addon->value->unitprice; $link = false; if (isset($addon->value->download) && isset($addon->value->dkey)) { $dkey = $addon->value->dkey; $request = ECART_PRETTYURLS?"download/$dkey":array('ecart_download'=>$dkey); $url = ecarturl($request,'catalog'); $link = '<br /><a href="'.$url.'">'.$download.'</a>'; } $pricing = value_is_true($prices)?" (".money($price).")":""; $result .= '<li>'.esc_html($addon->name.$pricing).$link.'</li>'; } $result .= '</ul>'.$after; return $result; break; case "has-data": case "hasdata": return (is_array($this->data) && count($this->data) > 0); break; case "orderdata": 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; } break; case "data": if (!is_array($this->data)) return false; $data = current($this->data); $name = key($this->data); if (isset($options['name'])) return esc_html($name); return esc_html($data); break; case "promolist": case "promo-list": $output = ""; if (!empty($this->promos)) { $output .= '<ul>'; foreach ($this->promos as $promo) $output .= '<li>'.$promo.'</li>'; $output .= '</ul>'; } return $output; case "has-promo": case "haspromo": if (empty($options['name'])) return false; return (in_array($options['name'],$this->promos)); break; case "subtotal": return money($this->subtotal); break; case "hasfreight": return (!empty($this->shipmethod) || $this->freight > 0); case "freight": return money($this->freight); break; case "hasdownloads": return ($this->downloads); case "hasdiscount": return ($this->discount > 0); case "discount": return money($this->discount); break; case "hastax": return ($this->tax > 0)?true:false; case "tax": return money($this->tax); break; case "total": return money($this->total); break; case "status": $labels = $Ecart->Settings->get('order_status'); if (empty($labels)) $labels = array(''); return $labels[$this->status]; break; case "paid": return ($this->txnstatus == "CHARGED"); break; case "notpaid": return ($this->txnstatus != "CHARGED"); break; case "payment": $labels = Lookup::payment_status_labels(); return isset($labels[$this->txnstatus])?$labels[$this->txnstatus]:$this->txnstatus; break; } }
/** * Helper method to render markup for state/province input fields * * @internal * @since 1.3 * * @param string $result The output * @param array $options The options * - **mode**: `input` (input, value) Displays the field `input` or the current value of the property * - **type**: `menu` (menu, text) Changes the input type to a drop-down menu or text input field * - **options**: A comma-separated list of options for the drop-down menu when the **type** is set to `menu` * - **required**: `auto` (auto,on,off) Sets the field to be required automatically, always `on` or disabled `off` * - **class**: The class attribute specifies one or more class-names for the input * - **label**: The label shown as the default option of the drop-down menu when the **type** is set to `menu` * - **address**: `billing` (billing,shipping) Used to specify which address the field takes input for * @param ShoppCustomer $O The working object * @return string The state input markup **/ private static function state($result, $options, $O) { $defaults = array('mode' => 'input', 'type' => 'menu', 'options' => '', 'required' => 'auto', 'class' => '', 'label' => '', 'address' => 'billing'); $options = array_merge($defaults, $options); $options['address'] = self::valid_address($options['address']); $Address = self::AddressObject($options['address']); if (!isset($options['value'])) { $options['value'] = $Address->state; } $options['selected'] = $options['value']; $options['id'] = "{$options['address']}-state"; extract($options, EXTR_SKIP); if ('value' == $mode) { return $value; } $countries = (array) shopp_setting('target_markets'); $select_attrs = array('title', 'required', 'class', 'disabled', 'required', 'size', 'tabindex', 'accesskey'); $country = ShoppBaseLocale()->country(); if (!empty($Address->country)) { $country = $Address->country; } if (!array_key_exists($country, $countries)) { $country = key($countries); } $regions = Lookup::country_zones(); $states = isset($regions[$country]) ? $regions[$country] : array(); if (!empty($options['options']) && empty($states)) { $states = explode(',', $options['options']); } $classes = false === strpos($class, ' ') ? explode(' ', $class) : array(); $classes[] = $id; if ('auto' == $required) { unset($options['required']); // prevent inputattrs from handling required=auto $classes[] = 'auto-required'; } $options['class'] = join(' ', $classes); if ('text' == $type) { return '<input type="text" name="' . $address . '[state]" id="' . $id . '" ' . inputattrs($options) . '/>'; } $options['disabled'] = 'disabled'; $options['class'] = join(' ', array_merge($classes, array('disabled', 'hidden'))); $result = '<select name="' . $address . '[state]" id="' . $id . '-menu" ' . inputattrs($options, $select_attrs) . '>' . '<option value="">' . $label . '</option>' . (!empty($states) ? menuoptions($states, $selected, true) : '') . '</select>'; unset($options['disabled']); $options['class'] = join(' ', $classes); $result .= '<input type="text" name="' . $address . '[state]" id="' . $id . '" ' . inputattrs($options) . '/>'; return $result; }
function country_zones () { check_admin_referer('wp_ajax_ecart_country_zones'); $zones = Lookup::country_zones(); if (isset($_GET['country']) && isset($zones[$_GET['country']])) echo json_encode($zones[$_GET['country']]); else echo json_encode(false); exit(); }