Пример #1
0
 static function country($data)
 {
     $countries = Lookup::countries();
     if (isset($countries[$data->country])) {
         return $countries[$data->country]['name'];
     }
     return $data->country;
 }
Пример #2
0
 /**
  * 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('' => '&nbsp;');
     $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('' => '&nbsp;'), (array) $regions[$Purchase->country]);
     $Purchase->_shipping_states = array_merge(array('' => '&nbsp;'), (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');
 }
Пример #3
0
 /**
  * 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');
 }
Пример #4
0
	/**
	 * 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(''=>'&nbsp;');
		$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(''=>'&nbsp;'),(array)$regions[$Customer->Billing->country]);
		$Customer->shipping_states = array_merge(array(''=>'&nbsp;'),(array)$regions[$Customer->Shipping->country]);

		include(ECART_ADMIN_PATH."/customers/editor.php");
	}
Пример #5
0
 public function shiprates()
 {
     if (!current_user_can('shopp_settings_shipping')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $Shopp = Shopp::object();
     $Shipping = $Shopp->Shipping;
     $Shipping->settings();
     // Load all installed shipping modules for settings UIs
     $methods = $Shopp->Shipping->methods;
     $edit = false;
     if (isset($_REQUEST['id'])) {
         $edit = (int) $_REQUEST['id'];
     }
     $active = shopp_setting('active_shipping');
     if (!$active) {
         $active = array();
     }
     if (!empty($_GET['delete'])) {
         check_admin_referer('shopp_delete_shiprate');
         $delete = $_GET['delete'];
         $index = false;
         if (strpos($delete, '-') !== false) {
             list($delete, $index) = explode('-', $delete);
         }
         if (array_key_exists($delete, $active)) {
             if (is_array($active[$delete])) {
                 if (array_key_exists($index, $active[$delete])) {
                     unset($active[$delete][$index]);
                     if (empty($active[$delete])) {
                         unset($active[$delete]);
                     }
                 }
             } else {
                 unset($active[$delete]);
             }
             $updated = __('Shipping method setting removed.', 'Shopp');
             shopp_set_setting('active_shipping', $active);
         }
     }
     if (isset($_POST['module'])) {
         check_admin_referer('shopp-settings-shiprate');
         $setting = false;
         $module = isset($_POST['module']) ? $_POST['module'] : false;
         $id = isset($_POST['id']) ? $_POST['id'] : false;
         if ($id == $module) {
             if (isset($_POST['settings'])) {
                 shopp_set_formsettings();
             }
             /** Save shipping service settings **/
             $active[$module] = true;
             shopp_set_setting('active_shipping', $active);
             $updated = __('Shipping settings saved.', 'Shopp');
             // Cancel editing if saving
             if (isset($_POST['save'])) {
                 unset($_REQUEST['id']);
             }
             $Errors = ShoppErrors();
             do_action('shopp_verify_shipping_services');
             if ($Errors->exist()) {
                 // Get all addon related errors
                 $failures = $Errors->level(SHOPP_ADDON_ERR);
                 if (!empty($failures)) {
                     $updated = __('Shipping settings saved but there were errors: ', 'Shopp');
                     foreach ($failures as $error) {
                         $updated .= '<p>' . $error->message(true, true) . '</p>';
                     }
                 }
             }
         } else {
             /** Save shipping calculator settings **/
             $setting = $_POST['id'];
             if (empty($setting)) {
                 // Determine next available setting ID
                 $index = 0;
                 if (is_array($active[$module])) {
                     $index = count($active[$module]);
                 }
                 $setting = "{$module}-{$index}";
             }
             // Cancel editing if saving
             if (isset($_POST['save'])) {
                 unset($_REQUEST['id']);
             }
             $setting_module = $setting;
             $id = 0;
             if (false !== strpos($setting, '-')) {
                 list($setting_module, $id) = explode('-', $setting);
             }
             // Prevent fishy stuff from happening
             if ($module != $setting_module) {
                 $module = false;
             }
             // Save shipping calculator settings
             $Shipper = $Shipping->get($module);
             if ($Shipper && isset($_POST[$module])) {
                 $Shipper->setting($id);
                 $_POST[$module]['label'] = stripslashes($_POST[$module]['label']);
                 // Sterilize $values
                 foreach ($_POST[$module]['table'] as $i => &$row) {
                     if (isset($row['rate'])) {
                         $row['rate'] = Shopp::floatval($row['rate']);
                     }
                     if (!isset($row['tiers'])) {
                         continue;
                     }
                     foreach ($row['tiers'] as &$tier) {
                         if (isset($tier['rate'])) {
                             $tier['rate'] = Shopp::floatval($tier['rate']);
                         }
                     }
                 }
                 // Delivery estimates: ensure max equals or exceeds min
                 ShippingFramework::sensibleestimates($_POST[$module]['mindelivery'], $_POST[$module]['maxdelivery']);
                 shopp_set_setting($Shipper->setting, $_POST[$module]);
                 if (!array_key_exists($module, $active)) {
                     $active[$module] = array();
                 }
                 $active[$module][(int) $id] = true;
                 shopp_set_setting('active_shipping', $active);
                 $this->notice(Shopp::__('Shipping settings saved.'));
             }
         }
     }
     $Shipping->settings();
     // Load all installed shipping modules for settings UIs
     $Shipping->ui();
     // Setup setting UIs
     $installed = array();
     $shiprates = array();
     // Registry for activated shipping rate modules
     $settings = array();
     // Registry of loaded settings for table-based shipping rates for JS
     foreach ($Shipping->active as $name => $module) {
         if (version_compare($Shipping->modules[$name]->since, '1.2') == -1) {
             continue;
         }
         // Skip 1.1 modules, they are incompatible
         $default_name = strtolower($name);
         $fullname = $module->methods();
         $installed[$name] = $fullname;
         if ($module->ui->tables) {
             $defaults[$default_name] = $module->ui->settings();
             $defaults[$default_name]['name'] = $fullname;
             $defaults[$default_name]['label'] = __('Shipping Method', 'Shopp');
         }
         if (array_key_exists($name, $active)) {
             $ModuleSetting = $active[$name];
         } else {
             continue;
         }
         // Not an activated shipping module, go to the next one
         // Setup shipping service shipping rate entries and settings
         if (!is_array($ModuleSetting)) {
             $shiprates[$name] = $name;
             continue;
         }
         // Setup shipping calcualtor shipping rate entries and settings
         foreach ($ModuleSetting as $id => $m) {
             $setting = "{$name}-{$id}";
             $shiprates[$setting] = $name;
             $settings[$setting] = shopp_setting($setting);
             $settings[$setting]['id'] = $setting;
             $settings[$setting] = array_merge($defaults[$default_name], $settings[$setting]);
             if (isset($settings[$setting]['table'])) {
                 usort($settings[$setting]['table'], array('ShippingFramework', '_sorttier'));
                 foreach ($settings[$setting]['table'] as &$r) {
                     if (isset($r['tiers'])) {
                         usort($r['tiers'], array('ShippingFramework', '_sorttier'));
                     }
                 }
             }
         }
     }
     if (isset($_REQUEST['id'])) {
         $edit = $_REQUEST['id'];
         $id = false;
         if (strpos($edit, '-') !== false) {
             list($module, $id) = explode('-', $edit);
         } else {
             $module = $edit;
         }
         if (isset($Shipping->active[$module])) {
             $Shipper = $Shipping->get($module);
             if (!$Shipper->singular) {
                 $Shipper->setting($id);
                 $Shipper->initui($Shipping->modules[$module]->name);
                 // Re-init setting UI with loaded settings
             }
             $editor = $Shipper->ui();
         }
     }
     asort($installed);
     $countrydata = Lookup::countries();
     $countries = $regionmap = $postcodes = array();
     $postcodedata = Lookup::postcodes();
     foreach ($countrydata as $code => $country) {
         $countries[$code] = $country['name'];
         if (!isset($regionmap[$country['region']])) {
             $regionmap[$country['region']] = array();
         }
         $regionmap[$country['region']][] = $code;
         if (isset($postcodedata[$code])) {
             if (!isset($postcodes[$code])) {
                 $postcodes[$code] = array();
             }
             $postcodes[$code] = true;
         }
     }
     unset($countrydata);
     unset($postcodedata);
     $lookup = array('regions' => array_merge(array('*' => __('Anywhere', 'Shopp')), Lookup::regions()), 'regionmap' => $regionmap, 'countries' => $countries, 'areas' => Lookup::country_areas(), 'zones' => Lookup::country_zones(), 'postcodes' => $postcodes);
     $ShippingTemplates = new TemplateShippingUI();
     add_action('shopp_shipping_module_settings', array($Shipping, 'templates'));
     include $this->ui('shiprates.php');
 }
Пример #6
0
 public function location_menu($destination = false, $row = 0, $module = false)
 {
     if (!$module) {
         $module = $this->module;
     }
     $menuarrow = ' &#x25be;';
     $tab = str_repeat('&sdot;', 3) . '&nbsp;';
     $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('&nbsp;', 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);
 }
Пример #7
0
	function tag ($property,$options=array()) {
		global $Ecart;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

				return $string;
				break;

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

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

		}
	}
Пример #8
0
	/**
	 * Displays the General Settings screen and processes updates
	 *	 
	 * @since 1.0
	 *
	 * @return void
	 **/
	function general () {
		global $Ecart;
		if ( !(current_user_can('manage_options') && current_user_can('ecart_settings')) )
			wp_die(__('You do not have sufficient permissions to access this page.'));

		$updatekey = $Ecart->Settings->get('updatekey');
		$activated = ($updatekey[0] == "1");
		$type = "text";
		$key = $updatekey[1];
		if (isset($updatekey[2]) && $updatekey[2] == "dev") {
			$type = "password";
			$key = preg_replace('/\w/','?',$key);
		}

		$country = (isset($_POST['settings']))?$_POST['settings']['base_operations']['country']:'';
		$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'];
		}

		if (!empty($_POST['setup'])) {
			$_POST['settings']['display_welcome'] = "off";
			$this->settings_save();
		}

		if (!empty($_POST['save'])) {
			check_admin_referer('ecart-settings-general');
			$vat_countries = Lookup::vat_countries();
			$zone = $_POST['settings']['base_operations']['zone'];
			$_POST['settings']['base_operations'] = $countrydata[$_POST['settings']['base_operations']['country']];
			$_POST['settings']['base_operations']['country'] = $country;
			$_POST['settings']['base_operations']['zone'] = $zone;
			$_POST['settings']['base_operations']['currency']['format'] =
				scan_money_format($_POST['settings']['base_operations']['currency']['format']);
			if (in_array($_POST['settings']['base_operations']['country'],$vat_countries))
				$_POST['settings']['base_operations']['vat'] = true;
			else $_POST['settings']['base_operations']['vat'] = false;

			if (!isset($_POST['settings']['target_markets']))
				asort($_POST['settings']['target_markets']);

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

		$operations = $Ecart->Settings->get('base_operations');
		if (!empty($operations['zone'])) {
			$zones = Lookup::country_zones();
			$zones = $zones[$operations['country']];
		}

		$targets = $Ecart->Settings->get('target_markets');
		if (!$targets) $targets = array();

		$statusLabels = $Ecart->Settings->get('order_status');
		include(ECART_ADMIN_PATH."/settings/settings.php");
	}
Пример #9
0
 /**
  * Sets the address location for calculating tax and shipping estimates
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return void
  **/
 public function locate($data = false)
 {
     $base = shopp_setting('base_operations');
     $markets = shopp_setting('target_markets');
     $countries = Lookup::countries();
     $regions = Lookup::regions();
     if ($data) {
         $this->updates($data);
     }
     if (empty($this->country)) {
         // If the target markets are set to single country, use that target as default country
         // otherwise default to the base of operations for tax and shipping estimates
         if (1 == count($markets)) {
             $this->country = key($markets);
         } else {
             $this->country = $base['country'];
         }
     }
     // Update state if postcode changes for tax updates
     if (isset($this->postcode)) {
         $this->postmap();
     }
     $this->region = false;
     if (isset($countries[$this->country]) && isset($regions[$countries[$this->country]['region']])) {
         $this->region = $regions[$countries[$this->country]['region']];
     }
 }
Пример #10
0
 /**
  * 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('' => '&nbsp;');
     $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('' => '&nbsp;'), (array) $regions[$Customer->Billing->country]);
     $Customer->shipping_states = array_merge(array('' => '&nbsp;'), (array) $regions[$Customer->Shipping->country]);
     include $this->ui('editor.php');
 }
Пример #11
0
 public function upgrade_120()
 {
     // 1.2 schema changes
     $db_version = ShoppSettings::dbversion();
     if ($db_version < 1120) {
         $this->upschema('schema-120.sql');
     }
     global $wpdb;
     // Clear the shopping session table
     $shopping_table = ShoppDatabaseObject::tablename('shopping');
     sDB::query("DELETE FROM {$shopping_table}");
     if ($db_version <= 1140) {
         $summary_table = ShoppDatabaseObject::tablename('summary');
         // Force summaries to rebuild
         sDB::query("UPDATE {$summary_table} SET modified='0000-00-00 00:00:01'");
     }
     $purchase_table = ShoppDatabaseObject::tablename('purchase');
     sDB::query("UPDATE {$purchase_table} SET txnstatus='captured' WHERE txnstatus='CHARGED'");
     sDB::query("UPDATE {$purchase_table} SET txnstatus='voided' WHERE txnstatus='VOID'");
     if ($db_version <= 1130) {
         // Move settings to meta table
         $meta_table = ShoppDatabaseObject::tablename('meta');
         $setting_table = ShoppDatabaseObject::tablename('setting');
         sDB::query("INSERT INTO {$meta_table} (context, type, name, value, created, modified) SELECT 'shopp', 'setting', name, value, created, modified FROM {$setting_table}");
         // Clean up unnecessary duplicate settings
         shopp_rmv_setting('data_model');
         shopp_rmv_setting('updates');
         shopp_rmv_setting('shopp_setup');
         shopp_rmv_setting('maintenance');
         // Re-load the Shopp settings registry
         ShoppSettings()->load();
         shopp_set_setting('maintenance', 'on');
         $db_version = intval(shopp_setting('db_version'));
         // Force inventory in 1.2 on to mimic 1.1 behavior (inventory tracking always on)
         shopp_set_setting('inventory', 'on');
         // Convert Shopp 1.1.x shipping settings to Shopp 1.2-compatible settings
         $active_shipping = array();
         $regions = Lookup::regions();
         $countries = Lookup::countries();
         $areas = Lookup::country_areas();
         $calcnaming = array('FlatRates::order' => 'OrderRates', 'FlatRates::item' => 'ItemRates', 'FreeOption' => 'FreeOption', 'ItemQuantity::range' => 'ItemQuantity', 'OrderAmount::range' => 'OrderAmount', 'OrderWeight::range' => 'OrderWeight');
         $shipping_rates = shopp_setting('shipping_rates');
         foreach ((array) $shipping_rates as $id => $old) {
             if (isset($calcnaming[$old['method']])) {
                 // Add to active setting registry for that calculator class
                 $calcname = $calcnaming[$old['method']];
                 if (!isset(${$calcname}) && !is_array(${$calcname})) {
                     ${$calcname} = array();
                 }
                 ${$calcname}[] = true;
                 $active_shipping[$calcname] = ${$calcname};
                 // Define the setting name
                 $settingid = end(array_keys(${$calcname}));
                 $setting_name = $calcname . '-' . $settingid;
             } else {
                 // Not a calculator, must be a shipping rate provider module, add it to the active roster
                 $active_shipping[$old['name']] = true;
                 continue;
             }
             $new = array();
             $new['label'] = $old['name'];
             list($new['mindelivery'], $new['maxdelivery']) = explode('-', $old['delivery']);
             $new['fallback'] = 'off';
             // Not used in legacy settings
             $oldkeys = array_keys($old);
             $old_destinations = array_diff($oldkeys, array('name', 'delivery', 'method', 'max'));
             $table = array();
             foreach ($old_destinations as $old_dest) {
                 $_ = array();
                 if ('Worldwide' == $old_dest) {
                     $d = '*';
                 }
                 $region = array_search($old_dest, $regions);
                 if (false !== $region) {
                     $d = "{$region}";
                 }
                 if (isset($countries[$old_dest])) {
                     $country = $countries[$old_dest];
                     $region = $country['region'];
                     $d = "{$region}, {$old_dest}";
                 }
                 foreach ($areas as $countrykey => $countryarea) {
                     $areakeys = array_keys($countryarea);
                     $area = array_search($old_dest, $areakeys);
                     if (false !== $area) {
                         $country = $countrykey;
                         $region = $countries[$countrykey]['region'];
                         $area = $areakeys[$area];
                         $d = "{$region}, {$country}, {$area}";
                         break;
                     }
                 }
                 $_['destination'] = $d;
                 $_['postcode'] = '*';
                 // Postcodes are new in 1.2, hardcode to wildcard
                 if (isset($old['max']) && !empty($old['max'])) {
                     // Capture tiered rates
                     $_['tiers'] = array();
                     $prior = 1;
                     foreach ($old['max'] as $index => $oldthreshold) {
                         $tier = array('threshold' => 0, 'rate' => 0);
                         if (in_array($oldthreshold, array('+', '>'))) {
                             $tier['threshold'] = $prior + 1;
                         } elseif (1 == $oldthreshold) {
                             $tier['threshold'] = 1;
                         } else {
                             $tier['threshold'] = $prior + 1;
                         }
                         $prior = $oldthreshold;
                         $tier['rate'] = $old[$old_dest][$index];
                         $_['tiers'][] = $tier;
                     }
                 } else {
                     $_['rate'] = $old[$old_dest][0];
                 }
                 // Capture flat rates
                 $table[] = $_;
             }
             $new['table'] = $table;
             shopp_set_setting($setting_name, $new);
             // Save the converted settings
         }
         // End foreach($shipping_rates) to convert old shipping calculator setting format
         shopp_set_setting('active_shipping', $active_shipping);
         // Save the active shipping options
     }
     if ($db_version <= 1121) {
         $address_table = ShoppDatabaseObject::tablename('address');
         $billing_table = ShoppDatabaseObject::tablename('billing');
         $shipping_table = ShoppDatabaseObject::tablename('shipping');
         // Move billing address data to the address table
         sDB::query("INSERT INTO {$address_table} (customer, type, address, xaddress, city, state, country, postcode, created, modified)\n\t\t\t\t\t\tSELECT customer, 'billing', address, xaddress, city, state, country, postcode, created, modified FROM {$billing_table}");
         sDB::query("INSERT INTO {$address_table} (customer, type, address, xaddress, city, state, country, postcode, created, modified)\n\t\t\t\t\t\tSELECT customer, 'shipping', address, xaddress, city, state, country, postcode, created, modified FROM {$shipping_table}");
     }
     // Migrate to WP custom posts & taxonomies
     if ($db_version <= 1131) {
         // Copy products to posts
         $catalog_table = ShoppDatabaseObject::tablename('catalog');
         $product_table = ShoppDatabaseObject::tablename('product');
         $price_table = ShoppDatabaseObject::tablename('price');
         $summary_table = ShoppDatabaseObject::tablename('summary');
         $meta_table = ShoppDatabaseObject::tablename('meta');
         $category_table = ShoppDatabaseObject::tablename('category');
         $tag_table = ShoppDatabaseObject::tablename('tag');
         $purchased_table = ShoppDatabaseObject::tablename('purchased');
         $index_table = ShoppDatabaseObject::tablename('index');
         $post_type = 'shopp_product';
         // Create custom post types from products, temporarily use post_parent for link to original product entry
         sDB::query("INSERT INTO {$wpdb->posts} (post_type, post_name, post_title, post_excerpt, post_content, post_status, post_date, post_date_gmt, post_modified, post_modified_gmt, post_parent)\n\t\t\t\t\t\t\tSELECT '{$post_type}', slug, name, summary, description, status, created, created, modified, modified, id FROM {$product_table}");
         // Update purchased table product column with new Post ID so sold counts can be updated
         sDB::query("UPDATE {$purchased_table} AS pd JOIN {$wpdb->posts} AS wp ON wp.post_parent=pd.product AND wp.post_type='{$post_type}' SET pd.product=wp.ID");
         // Update product links for prices and meta
         sDB::query("UPDATE {$price_table} AS price JOIN {$wpdb->posts} AS wp ON price.product=wp.post_parent SET price.product=wp.ID WHERE wp.post_type='{$post_type}'");
         sDB::query("UPDATE {$meta_table} AS meta JOIN {$wpdb->posts} AS wp ON meta.parent=wp.post_parent AND wp.post_type='{$post_type}' AND meta.context='product' SET meta.parent=wp.ID");
         sDB::query("UPDATE {$index_table} AS i JOIN {$wpdb->posts} AS wp ON i.product=wp.post_parent AND wp.post_type='{$post_type}' SET i.product=wp.ID");
         // Preliminary summary data
         sDB::query("INSERT INTO {$summary_table} (product, featured, variants, addons, modified)\n\t\t\t\t\t\t   SELECT wp.ID, p.featured, p.variations, p.addons, '0000-00-00 00:00:01'\n\t\t\t\t\t\t   FROM {$product_table} AS p\n\t\t\t\t\t\t   JOIN {$wpdb->posts} as wp ON p.id=wp.post_parent AND wp.post_type='{$post_type}'");
         // Move product options column to meta setting
         sDB::query("INSERT INTO {$meta_table} (parent, context, type, name, value)\n\t\t\t\t\t\tSELECT wp.ID, 'product', 'meta', 'options', options\n\t\t\t\t\t\tFROM {$product_table} AS p\n\t\t\t\t\t\tJOIN {$wpdb->posts} AS wp ON p.id=wp.post_parent AND wp.post_type='{$post_type}'");
         // Migrate Shopp categories and tags to WP taxonomies
         // Are there tag entries in the meta table? Old dev data present use meta table tags. No? use tags table.
         $dev_migration = $db_version >= 1120;
         // Copy categories and tags to WP taxonomies
         $tag_current_table = $dev_migration ? "{$meta_table} WHERE context='catalog' AND type='tag'" : $tag_table;
         $terms = sDB::query("(SELECT id, 'shopp_category' AS taxonomy, name, parent, description, slug FROM {$category_table})\n\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t(SELECT id, 'shopp_tag' AS taxonomy, name, 0 AS parent, '' AS description, name AS slug FROM {$tag_current_table}) ORDER BY id", 'array');
         // Prep category images for the move
         $category_image_offset = 65535;
         sDB::query("UPDATE {$meta_table} set parent=parent+{$category_image_offset} WHERE context='category' AND type='image'");
         $mapping = array();
         $children = array();
         $tt_ids = array();
         foreach ($terms as $term) {
             $term_id = (int) $term->id;
             $taxonomy = $term->taxonomy;
             if (!isset($mapping[$taxonomy])) {
                 $mapping[$taxonomy] = array();
             }
             if (!isset($children[$taxonomy])) {
                 $children[$taxonomy] = array();
             }
             $name = $term->name;
             $parent = $term->parent;
             $description = $term->description;
             $slug = strpos($term->slug, ' ') === false ? $term->slug : sanitize_title_with_dashes($term->slug);
             $term_group = 0;
             if ($exists = sDB::query("SELECT term_id, term_group FROM {$wpdb->terms} WHERE slug = '{$slug}'", 'array')) {
                 $term_group = $exists[0]->term_group;
                 $id = $exists[0]->term_id;
                 $num = 2;
                 do {
                     $alternate = sDB::escape($slug . "-" . $num++);
                     $alternate_used = sDB::query("SELECT slug FROM {$wpdb->terms} WHERE slug='{$alternate}'");
                 } while ($alternate_used);
                 $slug = $alternate;
                 if (empty($term_group)) {
                     $term_group = sDB::query("SELECT MAX(term_group) AS term_group FROM {$wpdb->terms} GROUP BY term_group", 'auto', 'col', 'term_group');
                     sDB::query("UPDATE {$wpdb->terms} SET term_group='{$term_group}' WHERE term_id='{$id}'");
                 }
             }
             // Move the term into the terms table
             $wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->terms} (name, slug, term_group) VALUES (%s, %s, %d)", $name, $slug, $term_group));
             $mapping[$taxonomy][$term_id] = (int) $wpdb->insert_id;
             // Map the old id to the new id
             $term_id = $mapping[$taxonomy][$term_id];
             // Update the working id to the new id
             if (!isset($tt_ids[$taxonomy])) {
                 $tt_ids[$taxonomy] = array();
             }
             if ('shopp_category' == $taxonomy) {
                 // If the parent term has already been added to the terms table, set the new parent id
                 if (isset($mapping[$taxonomy][$parent])) {
                     $parent = $mapping[$taxonomy][$parent];
                 } else {
                     // Parent hasn't been created, keep track of children for the parent to do a mass update when the parent term record is created
                     if (!isset($children[$taxonomy][$parent])) {
                         $children[$taxonomy][$parent] = array();
                     }
                     $children[$taxonomy][$parent][] = $term_id;
                 }
                 if (!empty($children[$taxonomy][$term->id])) {
                     // If there are children already created for this term, update their parent to our new id
                     $wpdb->query("UPDATE {$wpdb->term_taxonomy} SET parent={$term_id} WHERE term_id IN (" . join(', ', $children[$taxonomy][$term->id]) . ")");
                 }
                 // Associate the term to the proper taxonomy and parent terms
                 $wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->term_taxonomy} (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, 0));
                 $tt_ids[$taxonomy][$term_id] = (int) $wpdb->insert_id;
                 if (!empty($term_id)) {
                     // Move category settings to meta
                     $metafields = array('spectemplate', 'facetedmenus', 'variations', 'pricerange', 'priceranges', 'specs', 'options', 'prices');
                     foreach ($metafields as $field) {
                         sDB::query("INSERT INTO {$meta_table} (parent, context, type, name, value)\n\t\t\t\t\t\t\t\t\t\t\tSELECT {$term_id}, 'category', 'meta', '{$field}', {$field}\n\t\t\t\t\t\t\t\t\t\t\tFROM {$category_table}\n\t\t\t\t\t\t\t\t\t\t\tWHERE id={$term->id}");
                     }
                     // Update category images to new term ids
                     sDB::query("UPDATE {$meta_table} set parent='{$term_id}' WHERE parent='" . ((int) $term->id + $category_image_offset) . "' AND context='category' AND type='image'");
                 }
             }
             if ('shopp_tag' == $taxonomy) {
                 $wpdb->query($wpdb->prepare("INSERT INTO {$wpdb->term_taxonomy} (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, 0));
                 $tt_ids[$taxonomy][$term_id] = (int) $wpdb->insert_id;
             }
         }
         update_option('shopp_category_children', '');
         // Re-catalog custom post type_products term relationships (new taxonomical catalog) from old Shopp catalog table
         $wp_taxonomies = array(0 => 'shopp_category', 1 => 'shopp_tag', 'category' => 'shopp_category', 'tag' => 'shopp_tag');
         $cols = 'wp.ID AS product, c.parent, c.type';
         $where = "type='category' OR type='tag'";
         if ($db_version >= 1125) {
             $cols = 'wp.ID AS product, c.parent, c.taxonomy, c.type';
             $where = "taxonomy=0 OR taxonomy=1";
         }
         $rels = sDB::query("SELECT {$cols} FROM {$catalog_table} AS c LEFT JOIN {$wpdb->posts} AS wp ON c.product=wp.post_parent AND wp.post_type='{$post_type}' WHERE {$where}", 'array');
         foreach ((array) $rels as $r) {
             $object_id = $r->product;
             $taxonomy = $wp_taxonomies[$db_version >= 1125 ? $r->taxonomy : $r->type];
             $term_id = $mapping[$taxonomy][$r->parent];
             if (!isset($tt_ids[$taxonomy])) {
                 continue;
             }
             if (!isset($tt_ids[$taxonomy][$term_id])) {
                 continue;
             }
             $tt_id = $tt_ids[$taxonomy][$term_id];
             if (empty($tt_id)) {
                 continue;
             }
             sDB::query("INSERT {$wpdb->term_relationships} (object_id, term_taxonomy_id) VALUES ({$object_id}, {$tt_id})");
         }
         if (isset($tt_ids['shopp_category'])) {
             wp_update_term_count_now($tt_ids['shopp_category'], 'shopp_category');
         }
         if (isset($tt_ids['shopp_tag'])) {
             wp_update_term_count_now($tt_ids['shopp_tag'], 'shopp_tag');
         }
         // Clear custom post type parents
         sDB::query("UPDATE {$wpdb->posts} SET post_parent=0 WHERE post_type='{$post_type}'");
     }
     // END if ($db_version <= 1131)
     if ($db_version <= 1133) {
         // Ditch old WP pages for pseudorific new ones
         $search = array();
         $shortcodes = array('[catalog]', '[cart]', '[checkout]', '[account]');
         foreach ($shortcodes as $string) {
             $search[] = "post_content LIKE '%{$string}%'";
         }
         $results = sDB::query("SELECT ID, post_title AS title, post_name AS slug, post_content FROM {$wpdb->posts} WHERE post_type='page' AND (" . join(" OR ", $search) . ")", 'array');
         $pages = $trash = array();
         foreach ($results as $post) {
             $trash[] = $post->ID;
             foreach ($shortcodes as $code) {
                 if (strpos($post->post_content, $code) === false) {
                     continue;
                 }
                 $pagename = trim($code, '[]');
                 $pages[$pagename] = array('title' => $post->title, 'slug' => $post->slug);
             }
             // end foreach $shortcodes
         }
         // end foreach $results
         shopp_set_setting('storefront_pages', $pages);
         sDB::query("UPDATE {$wpdb->posts} SET post_name=CONCAT(post_name, '-deprecated'), post_status='trash' where ID IN (" . join(', ', $trash) . ")");
     }
     // Move needed price table columns to price meta records
     if ($db_version <= 1135) {
         $meta_table = ShoppDatabaseObject::tablename('meta');
         $price_table = ShoppDatabaseObject::tablename('price');
         // Move 'options' to meta 'options' record
         sDB::query("INSERT INTO {$meta_table} (parent, context, type, name, value, created, modified)\n\t\t\t\t\t\tSELECT id, 'price', 'meta', 'options', options, created, modified FROM {$price_table}");
         // Merge 'weight', 'dimensions' and 'donation' columns to a price 'settings' record
         sDB::query("INSERT INTO {$meta_table} (parent, context, type, name, value, created, modified)\n\t\t\t\t\t\t\tSELECT id, 'price', 'meta', 'settings',\n\t\t\t\t\t\t\tCONCAT('a:2:{s:10:\"dimensions\";',\n\t\t\t\t\t\t\t\tIF(weight = 0 AND dimensions = '0', 'a:0:{}',\n\t\t\t\t\t\t\t\t\tIF(dimensions = '0',\n\t\t\t\t\t\t\t\t\t\tCONCAT(\n\t\t\t\t\t\t\t\t\t\t\t'a:1:{s:6:\"weight\";s:', CHAR_LENGTH(weight), ':\"', weight, '\";}'\n\t\t\t\t\t\t\t\t\t\t), dimensions\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t), 's:8:\"donation\";', IF(donation='', 'N;', donation), '}'\n\t\t\t\t\t\t\t), created, modified FROM {$price_table}");
     }
     // END if ($db_version <= 1135)
     if ($db_version <= 1145) {
         // Update purchase gateway property to use gateway class names
         // for proper order event handling on 1.1-generated orders
         $gateways = array('PayPal Standard' => 'PayPalStandard', 'PayPal Expresss' => 'PayPalExpress', 'PayPal Pro' => 'PayPalPro', '2Checkout.com' => '_2Checkout', 'Authorize.Net' => 'AuthorizeNet', 'Google Checkout' => 'GoogleCheckout', 'HSBC ePayments' => 'HSBCepayments', 'iDeal Mollie' => 'iDealMollie', 'Manual Processing' => 'ManualProcessing', 'Merchant Warrior' => 'MerchantWarrior', 'Offline Payment' => 'OfflinePayment', 'PayPal Payflow Pro' => 'PayflowPro', 'Test Mode' => 'TestMode');
         foreach ($gateways as $name => $classname) {
             sDB::query("UPDATE {$purchase_table} SET gateway='{$classname}' WHERE gateway='{$name}'");
         }
     }
     // END if ($db_version <= 1145)
     if ($db_version <= 1148) {
         $price_table = ShoppDatabaseObject::tablename('price');
         sDB::query("UPDATE {$price_table} SET optionkey=(options*7001) WHERE context='addon'");
     }
     if ($db_verison <= 1150) {
         $meta_table = ShoppDatabaseObject::tablename('meta');
         sDB::query("DELETE {$meta_table} FROM {$meta_table} LEFT OUTER JOIN (SELECT MAX(id) AS keepid FROM {$meta_table} WHERE context='category' AND type='meta' GROUP BY parent, name) AS keepRowTable ON {$meta_table}.id = keepRowTable.keepid WHERE keepRowTable.keepid IS NULL AND context='category' AND type='meta'");
     }
 }
Пример #12
0
 function billmate_transaction($add_order = false)
 {
     global $Shopp;
     $Shopping =& $Shopp->Shopping;
     $Order =& $Shopp->Order;
     if (empty($_POST)) {
         $_POST = $_GET;
     }
     $pno = '';
     $eid = (int) $this->settings['merchantid'];
     $key = $this->settings['cardpaysecret'];
     $ssl = true;
     $debug = false;
     $k = new BillMate($eid, $key, $ssl, $debug);
     $Customer = $this->Order->Customer;
     $Billing = $this->Order->Billing;
     $Shipping = $this->Order->Shipping;
     $country = $zone = $locale = $global = false;
     $country = $Billing->country;
     $country_to_currency = array('NO' => 'NOK', 'SE' => 'SEK', 'FI' => 'EUR', 'DK' => 'DKK', 'DE' => 'EUR', 'NL' => 'EUR');
     $ship_address = $bill_address = array();
     $countries = Lookup::countries();
     //$countryData = BillmateCountry::getCountryData($Shipping->country);
     $countryData = BillmateCountry::getSwedenData();
     $ship_address = array('email' => $Customer->email, 'telno' => $Customer->phone, 'cellno' => '', 'fname' => $Customer->firstname, 'lname' => $Customer->lastname, 'company' => $Customer->company, 'careof' => '', 'street' => $Shipping->address, 'house_number' => isset($house_no) ? $house_no : '', 'house_extension' => isset($house_ext) ? $house_ext : '', 'zip' => $Shipping->postcode, 'city' => $Shipping->city, 'country' => $countries[$Shipping->country]['name']);
     $bill_address = array('email' => $Customer->email, 'telno' => $Customer->phone, 'cellno' => '', 'fname' => $Customer->firstname, 'lname' => $Customer->lastname, 'company' => $Customer->company, 'careof' => '', 'street' => $Billing->address, 'house_number' => '', 'house_extension' => '', 'zip' => $Billing->postcode, 'city' => $Billing->city, 'country' => $countries[$Billing->country]['name']);
     foreach ($ship_address as $key => $col) {
         $ship_address[$key] = utf8_decode(Encoding::fixUTF8($col));
     }
     foreach ($bill_address as $key => $col) {
         $bill_address[$key] = utf8_decode(Encoding::fixUTF8($col));
     }
     extract($countryData);
     $goods_list = array();
     $taxrate = 0;
     foreach ($this->Order->Cart as $item) {
         // echo links for the items
         $flag = stripos($item->name, 'billmate fee') === false ? stripos($item->name, 'billmate invoice fee') === false ? 0 : 16 : 0;
         $taxrate = $taxrate == 0 ? $item->taxrate : $taxrate;
         $goods_list[] = array('qty' => (int) $item->quantity, 'goods' => array('artno' => $item->product, 'title' => $item->name, 'price' => round($item->unitprice * 100, 0), 'vat' => (double) round($item->taxrate * 100, 0), 'discount' => 0.0, 'flags' => $flag));
     }
     if ($this->Order->Cart->Totals->discount > 0) {
         $rate = (100 + $taxrate * 100) / 100;
         $totalAmt = $this->Order->Cart->Totals->discount;
         $price = $totalAmt - $totalAmt / $rate;
         $discount = $totalAmt - $price;
         $goods_list[] = array('qty' => (int) 1, 'goods' => array('artno' => __('discount', 'shopp-billmate-cardpay'), 'title' => __('Discount', 'shopp-billmate-cardpay'), 'price' => -1 * abs(round($this->Order->Cart->Totals->discount * 100, 0)), 'vat' => (double) $taxrate * 100, 'discount' => (double) 0, 'flags' => $flag));
     }
     if (!empty($this->Order->Cart->Totals->shipping)) {
         /* $taxrate = $taxrate * 100;
            $rate = (100+$taxrate)/100;
            $totalAmt = $this->Order->Cart->Totals->shipping;
            $price = $totalAmt-($totalAmt/$rate);
            $shipping = $totalAmt - $price;*/
         $goods_list[] = array('qty' => (int) 1, 'goods' => array('artno' => __('Shipping', 'shopp-billmate-cardpay'), 'title' => __('Shipping', 'shopp-billmate-cardpay'), 'price' => round($this->Order->Cart->Totals->shipping * 100, 0), 'vat' => (double) $taxrate * 100, 'discount' => 0, 'flags' => 8));
     }
     $pclass = -1;
     $lang = explode("_", strtoupper(WPLANG));
     $base = $Shopp->Settings->get('base_operations');
     $_ = array();
     $transaction = array("order1" => (string) $this->txnid(), "comment" => (string) "", "flags" => 0, "reference" => "", "reference_code" => "", "currency" => $base['currency']['code'], "country" => 209, "language" => $lang[0], "pclass" => $pclass, "shipInfo" => array("delay_adjust" => "1"), "travelInfo" => array(), "incomeInfo" => array(), "bankInfo" => array(), "sid" => array("time" => microtime(true)), "extraInfo" => array(array("cust_no" => (string) $Customer->id, "creditcard_data" => $_POST)));
     if (!empty($this->Order->capture) && $this->Order->capture == 'YES') {
         $transaction["extraInfo"][0]["status"] = 'Paid';
     }
     if ($add_order) {
         return $k->AddOrder($pno, $bill_address, $ship_address, $goods_list, $transaction);
     }
     if (!isset($_SESSION['card_invoice_called']) || $_SESSION['card_invoice_called'] == false) {
         $result1 = $k->AddInvoice($pno, $bill_address, $ship_address, $goods_list, $transaction);
     } else {
         $result1[0] = $_SESSION['card_invoice_called_inv'];
     }
     if (!is_array($result1)) {
         new ShoppError(__('Unable to process billmate try again <br/>Error:', 'shopp-billmate-cardpay') . utf8_encode($result1), 2);
         echo '<script type="text/javascript">window.location.href="' . shoppurl(false, 'checkout') . '";</script>';
         die;
     } else {
         $this->Order->billmateId = $result1[0];
     }
 }
Пример #13
0
 public static function parse_location($destination)
 {
     $selected = array('region' => '*', 'country' => '', 'area' => '', 'zone' => '');
     $selection = array();
     if (strpos($destination, ',') !== false) {
         $selection = explode(',', $destination);
     } else {
         $selection = array($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));
     extract($selected);
     foreach ($selected as $name => &$value) {
         if ($value == '') {
             continue;
         }
         switch ($name) {
             case 'region':
                 if ('*' == $value) {
                     $value = __('Worldwide', 'Shopp');
                 } else {
                     $regions = Lookup::regions();
                     if (isset($regions[$value])) {
                         $value = $regions[$value];
                     }
                 }
                 break;
             case 'country':
                 $countries = Lookup::countries();
                 $selected['countrycode'] = $value;
                 if (isset($countries[$value])) {
                     $value = $countries[$value]['name'];
                 }
                 break;
             case 'zone':
                 $zones = Lookup::country_zones();
                 if (isset($zones[$country])) {
                     $zones = $zones[$country];
                 }
                 if (isset($zones[$value])) {
                     $value = $zones[$value];
                 }
                 break;
         }
     }
     return $selected;
 }
Пример #14
0
	/**
	 * Sets the shipping address location for calculating
	 * shipping estimates.
	 *	 
	 * @since 1.1
	 *
	 * @return void Description...
	 **/
	function destination ($data=false) {
		global $Ecart;

		$base = $Ecart->Settings->get('base_operations');
		$countries = Lookup::countries();
		$regions = Lookup::regions();

		if ($data) $this->updates($data);

		// Update state if postcode changes for tax updates
		if (isset($this->postcode))
			$this->postarea();

		if (empty($this->country))
			$this->country = $base['country'];

		$this->region = false;
		if (isset($regions[$countries[$this->country]['region']]))
			$this->region = $regions[$countries[$this->country]['region']];

	}