コード例 #1
0
ファイル: Registration.php プロジェクト: msigley/shopp
 public function customer()
 {
     $Customer = ShoppOrder()->Customer;
     $updates = array('firstname' => $this->form('firstname'), 'lastname' => $this->form('lastname'), 'company' => $this->form('company'), 'email' => $this->form('email'), 'phone' => $this->form('phone'), 'info' => $this->form('info'), 'marketing' => $this->form('marketing'), 'password' => $this->form('password', true), 'loginname' => $this->form('loginname', true));
     // Remove invalid characters from the phone number
     $updates['phone'] = preg_replace('/[^\\d\\(\\)\\-+\\. (ext|x)]/', '', $updates['phone']);
     if (empty($Customer)) {
         $Customer = new ShoppCustomer();
     } else {
         $Customer->reset();
     }
     $Customer->updates($updates);
     // Keep confirm-password field value when showing checkout validation errors
     $confirmpass = $this->form('confirm-password', true);
     if (!empty($confirmpass)) {
         $Customer->_confirm_password = $confirmpass;
     }
 }
コード例 #2
0
ファイル: Validation.php プロジェクト: forthrobot/inuvik
 public static function login($result)
 {
     $Customer = ShoppOrder()->Customer;
     if ($Customer->loggedin()) {
         return $result;
     }
     $accounts = shopp_setting('account_system');
     $pleaselogin = '******' . Shopp::__('If you have an account with us, please login now.');
     // This specific !isset condition checks if the loginname is not provided
     // If no loginname is provided, but an account system is used, we need to
     // generate a new login name for the customer
     if ('wordpress' == $accounts && !isset($_POST['loginname'])) {
         ShoppLoginGenerator::object();
         $_POST['loginname'] = ShoppLoginGenerator::name();
         if (apply_filters('shopp_login_required', empty($_POST['loginname']))) {
             return shopp_add_error(Shopp::__('A login could not be created with the information you provided. Enter a different name or email address.') . $pleaselogin);
         }
         shopp_debug('Login set to ' . $_POST['loginname'] . ' for WordPress account creation.');
     }
     // Validate unique email address for new account
     if (in_array($accounts, array('wordpress', 'shopp')) && !$Customer->session(ShoppCustomer::GUEST)) {
         $ShoppCustomer = new ShoppCustomer($_POST['email'], 'email');
         if (apply_filters('shopp_email_exists', 'wordpress' == $accounts ? email_exists($_POST['email']) : $ShoppCustomer->exists())) {
             return shopp_add_error(Shopp::__('The email address you entered is already in use. Enter a different email address to create a new account.') . $pleaselogin);
         }
     }
     // Validate WP login
     if (isset($_POST['loginname'])) {
         if (apply_filters('shopp_login_required', empty($_POST['loginname']))) {
             return shopp_add_error(Shopp::__('You must enter a login name for your account.'));
         }
         if (apply_filters('shopp_login_valid', !validate_username($_POST['loginname']))) {
             $sanitized = sanitize_user($_POST['loginname'], true);
             $illegal = array_diff(str_split($_POST['loginname']), str_split($sanitized));
             return shopp_add_error(Shopp::__('The login name provided includes invalid characters: %s', esc_html(join(' ', $illegal))));
         }
         if (apply_filters('shopp_login_exists', username_exists($_POST['loginname']))) {
             return shopp_add_error(Shopp::__('"%s" is already in use. Enter a different login name to create a new account.', esc_html($_POST['loginname'])) . $pleaselogin);
         }
     }
     return $result;
 }
コード例 #3
0
ファイル: Customers.php プロジェクト: forthrobot/inuvik
 public function save(ShoppCustomer $Customer)
 {
     if ($this->request('new')) {
         if (!isset($this->valid_email)) {
             return $this->notice(Shopp::__('Could not create new customer. You must enter a valid email address.'));
         }
         if (!isset($this->valid_password)) {
             $this->password = wp_hash_password(wp_generate_password(12, true));
         }
         if ('wordpress' !== shopp_setting('account_system')) {
             $wpuser = $Customer->create_wpuser();
             $login = '******' . sanitize_user($this->form('userlogin')) . '</strong>';
             if ($wpuser) {
                 $this->notice(Shopp::__('A new customer has been created with the WordPress login &quot;%s&quot;.', $login), 'error');
             } else {
                 $this->notice(Shopp::__('Could not create the WordPress login &quot;%s&quot; for the new customer.', $login), 'error');
             }
         }
         $this->notice(Shopp::__('New customer created.'));
     }
     $Customer->save();
 }
コード例 #4
0
ファイル: customer.php プロジェクト: forthrobot/inuvik
 /**
  * Checks if a WP user account was created for the customer
  *
  * @api `shopp('customer.wpuser-created')`
  * @since 1.0
  *
  * @param string        $result  The output
  * @param array         $options The options
  * @param ShoppCustomer $O       The working object
  * @return bool True if an account was created, false otherwise
  **/
 public static function wpuser_created($result, $options, $O)
 {
     return $O->session(ShoppCustomer::WPUSER);
 }
コード例 #5
0
ファイル: Service.php プロジェクト: jonathandavis/shopp
 /**
  * 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');
 }
コード例 #6
0
ファイル: Pages.php プロジェクト: jonathandavis/shopp
 static function resetpassword($activation)
 {
     if ('none' == shopp_setting('account_system')) {
         return;
     }
     $user_data = false;
     $activation = preg_replace('/[^a-z0-9]/i', '', $activation);
     $errors = array();
     if (empty($activation) || !is_string($activation)) {
         $errors[] = new ShoppError(Shopp::__('Invalid key'));
     }
     $RecoveryCustomer = new ShoppCustomer($activation, 'activation');
     if (empty($RecoveryCustomer->id)) {
         $errors[] = new ShoppError(Shopp::__('Invalid key'));
     }
     if (!empty($errors)) {
         return false;
     }
     // Generate a new random password
     $password = wp_generate_password();
     do_action_ref_array('password_reset', array($RecoveryCustomer, $password));
     $RecoveryCustomer->password = wp_hash_password($password);
     if ('wordpress' == shopp_setting('account_system')) {
         $user_data = get_userdata($RecoveryCustomer->wpuser);
         wp_set_password($password, $user_data->ID);
     }
     $RecoveryCustomer->activation = '';
     $RecoveryCustomer->save();
     $subject = apply_filters('shopp_reset_password_subject', Shopp::__('[%s] New Password', get_option('blogname')));
     $_ = array();
     $_[] = 'From: ' . Shopp::email_from(shopp_setting('merchant_email'), shopp_setting('business_name'));
     $_[] = 'To: ' . $RecoveryCustomer->email;
     $_[] = 'Subject: ' . $subject;
     $_[] = 'Content-type: text/html';
     $_[] = '';
     $_[] = '<p>' . Shopp::__('Your new password for %s:', get_bloginfo('url')) . '</p>';
     $_[] = '';
     $_[] = '<ul>';
     if ($user_data) {
         $_[] = '<li>' . Shopp::__('Login name: %s', $user_data->user_login) . '</li>';
     }
     $_[] = '<li>' . Shopp::__('Password: %s', $password) . '</li>';
     $_[] = '</ul>';
     $_[] = '';
     $_[] = '<p>' . Shopp::__('Click here to login: %s', Shopp::url(false, 'account')) . '</p>';
     $message = apply_filters('shopp_reset_password_message', $_);
     if (!Shopp::email(join("\n", $message))) {
         shopp_add_error(Shopp::__('The e-mail could not be sent.'));
         Shopp::redirect(add_query_arg('acct', 'recover', Shopp::url(false, 'account')));
     } else {
         shopp_add_error(Shopp::__('Check your email address for your new password.'));
     }
     unset($_GET['acct']);
 }
コード例 #7
0
ファイル: Resources.php プロジェクト: msigley/shopp
 /**
  * Delivers customer export files to the browser
  *
  * @author Jonathan Davis
  * @since 1.1
  *
  * @return void
  **/
 public function export_customers()
 {
     if (!current_user_can('shopp_export_customers')) {
         exit;
     }
     if (!isset($_POST['settings']['customerexport_columns'])) {
         $Customer = ShoppCustomer::exportcolumns();
         $Billing = BillingAddress::exportcolumns();
         $Shipping = ShippingAddress::exportcolumns();
         $_POST['settings']['customerexport_columns'] = array_keys(array_merge($Customer, $Billing, $Shipping));
         $_POST['settings']['customerexport_headers'] = 'on';
     }
     shopp_set_formsettings();
     // Save workflow setting
     $format = shopp_setting('customerexport_format');
     if (empty($format)) {
         $format = 'tab';
     }
     switch ($format) {
         case 'csv':
             new CustomersCSVExport();
             break;
         default:
             new CustomersTabExport();
     }
     exit;
 }
コード例 #8
0
 public function __construct()
 {
     $this->customer_cols = ShoppCustomer::exportcolumns();
     $this->billing_cols = BillingAddress::exportcolumns();
     $this->shipping_cols = ShippingAddress::exportcolumns();
     $this->defined = array_merge($this->customer_cols, $this->billing_cols, $this->shipping_cols);
     $this->sitename = get_bloginfo('name');
     $this->headings = shopp_setting('customerexport_headers') == "on";
     $this->selected = shopp_setting('customerexport_columns');
     shopp_set_setting('customerexport_lastexport', current_time('timestamp'));
 }
コード例 #9
0
ファイル: Pages.php プロジェクト: crunnells/shopp
 /**
  * Resets a customer/user password with a valid activation key
  *
  * @since 1.0
  *
  * @param string $activation The activation key
  * @return void
  **/
 static function resetpassword($activation)
 {
     if ('none' == shopp_setting('account_system') || ShoppCustomer()->loggedin()) {
         return;
     }
     $user_data = false;
     $activation = preg_replace('/[^a-z0-9]/i', '', $activation);
     $errors = array();
     if (empty($activation) || !is_string($activation)) {
         $errors[] = shopp_add_error(Shopp::__("Invalid password reset key. Try copy/pasting the url in password reset email into your web browser's address bar."));
     } else {
         $RecoveryCustomer = new ShoppCustomer($activation, 'activation');
         if (empty($RecoveryCustomer->id)) {
             $errors[] = shopp_add_error(Shopp::__("Invalid password reset key. Try copy/pasting the url in password reset email into your web browser's address bar."));
         }
     }
     if (!empty($errors)) {
         return false;
     }
     // Generate a new random password
     $password = wp_generate_password(12, false);
     do_action_ref_array('password_reset', array($RecoveryCustomer, $password));
     $RecoveryCustomer->password = wp_hash_password($password);
     if ('wordpress' == shopp_setting('account_system')) {
         $user_data = get_userdata($RecoveryCustomer->wpuser);
         wp_set_password($password, $user_data->ID);
     }
     $RecoveryCustomer->activation = '';
     $RecoveryCustomer->save();
     $subject = apply_filters('shopp_reset_password_subject', Shopp::__('[%s] New Password', get_option('blogname')));
     $_ = array();
     $_[] = 'From: ' . Shopp::email_from(shopp_setting('merchant_email'), shopp_setting('business_name'));
     $_[] = 'To: ' . $RecoveryCustomer->email;
     $_[] = 'Subject: ' . $subject;
     $_[] = 'Content-type: text/html';
     $_[] = '';
     $_[] = '<p>' . Shopp::__('Your new password for %s:', get_bloginfo('url')) . '</p>';
     $_[] = '';
     $_[] = '<ul>';
     if (apply_filters('shopp_reset_password_wpuser', true) && !empty($user_data->user_login)) {
         $_[] = '<li>' . Shopp::__('Login: %s', $user_data->user_login) . '</li>';
     } elseif (!empty($RecoveryCustomer->email)) {
         $_[] = '<li>' . Shopp::__('Login: %s', $RecoveryCustomer->email) . '</li>';
     }
     $_[] = '<li>' . Shopp::__('Password: %s', $password) . '</li>';
     $_[] = '</ul>';
     $_[] = '';
     $_[] = '<p>' . Shopp::__('Click here to login: %s', Shopp::url(false, 'account')) . '</p>';
     $message = apply_filters('shopp_reset_password_message', $_);
     if (!Shopp::email(join("\n", $message))) {
         shopp_add_notice(Shopp::__('Your password was reset to: ' . $password));
     } else {
         shopp_add_notice(Shopp::__('Your new password has been emailed to you for your records. Your password was reset to: ' . $password));
     }
     unset($_GET['acct']);
     // Auto-login
     $RecoveryCustomer->login();
     // Login the customer
     if (!empty($user_data)) {
         // Log the WordPress user in
         ShoppLogin::wpuser($user_data);
     }
     // Show notice after login in case of failures during login
     shopp_add_notice(Shopp::__('You are now logged into your account.'));
     if (apply_filters('shopp_reset_password_redirect', true)) {
         shopp_add_notice(Shopp::__('If you wish, please use the form below to change your password to one of your choosing.'));
         Shopp::redirect(add_query_arg('profile', '', Shopp::url(false, 'account')));
     }
 }
コード例 #10
0
ファイル: Account.php プロジェクト: BlessySoftwares/anvelocom
 /**
  * Interface processor for the customer list screen
  *
  * Handles processing customer list actions and displaying the
  * customer list screen
  *
  * @author Jonathan Davis
  * @return void
  **/
 public function customers()
 {
     global $wpdb;
     $defaults = array('page' => false, 'deleting' => false, 'selected' => false, 'update' => false, 'newstatus' => false, 'pagenum' => 1, 'paged' => false, 'per_page' => 20, 'start' => '', 'end' => '', 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => '');
     $args = array_merge($defaults, $_GET);
     extract($args, EXTR_SKIP);
     if ($page == $this->Admin->pagename('customers') && !empty($deleting) && !empty($selected) && is_array($selected) && current_user_can('shopp_delete_customers')) {
         foreach ($selected as $deletion) {
             $Customer = new ShoppCustomer($deletion);
             $Billing = new BillingAddress($Customer->id, 'customer');
             $Billing->delete();
             $Shipping = new ShippingAddress($Customer->id, 'customer');
             $Shipping->delete();
             $Customer->delete();
         }
     }
     $updated = false;
     if (!empty($_POST['save'])) {
         check_admin_referer('shopp-save-customer');
         $wp_integration = 'wordpress' === shopp_setting('account_system');
         if ($_POST['id'] !== 'new') {
             $Customer = new ShoppCustomer($_POST['id']);
             $Billing = new BillingAddress($Customer->id, 'customer');
             $Shipping = new ShippingAddress($Customer->id, 'customer');
         } else {
             $Customer = new ShoppCustomer();
         }
         if (!empty($Customer->wpuser)) {
             $user = get_user_by('id', $Customer->wpuser);
         }
         $new_customer = empty($Customer->id);
         $Customer->updates($_POST);
         // Reassign WordPress login
         if ($wp_integration && isset($_POST['userlogin']) && $_POST['userlogin'] != $user->user_login) {
             $newlogin = get_user_by('login', $_POST['userlogin']);
             if (!empty($newlogin->ID)) {
                 if (sDB::query("SELECT count(*) AS used FROM {$Customer->_table} WHERE wpuser={$newlogin->ID}", 'auto', 'col', 'used') == 0) {
                     $Customer->wpuser = $newlogin->ID;
                     $updated = sprintf(__('Updated customer login to %s.', 'Shopp'), "<strong>{$newlogin->user_login}</strong>");
                 } else {
                     $updated = sprintf(__('Could not update customer login to &quot;%s&quot; because that user is already assigned to another customer.', 'Shopp'), '<strong>' . sanitize_user($_POST['userlogin']) . '</strong>');
                 }
             } else {
                 $updated = sprintf(__('Could not update customer login to &quot;%s&quot; because the user does not exist in WordPress.', 'Shopp'), '<strong>' . sanitize_user($_POST['userlogin']) . '</strong>');
             }
             if (empty($_POST['userlogin'])) {
                 $Customer->wpuser = 0;
             }
         }
         if (!empty($_POST['new-password']) && !empty($_POST['confirm-password']) && $_POST['new-password'] == $_POST['confirm-password']) {
             $Customer->password = wp_hash_password($_POST['new-password']);
             if (!empty($Customer->wpuser)) {
                 wp_set_password($_POST['new-password'], $Customer->wpuser);
             }
         }
         $valid_email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
         $password = !empty($_POST['new_password']);
         if ($wp_integration && $new_customer && $valid_email && $password) {
             $Customer->loginname = $_POST['userlogin'];
             $Customer->email = $_POST['email'];
             $Customer->firstname = $_POST['firstname'];
             $Customer->lastname = $_POST['lastname'];
             $return = $Customer->create_wpuser();
             if ($return) {
                 $updated = sprintf(__('The Shopp and WordPress accounts have been created with the username &quot;%s&quot;.', 'Shopp'), '<strong>' . sanitize_user($_POST['userlogin']) . '</strong>');
             } else {
                 $updated = sprintf(__('Could not create a WordPress account for customer &quot;%s&quot;.', 'Shopp'), '<strong>' . sanitize_user($_POST['userlogin']) . '</strong>');
             }
         } elseif ($new_customer && (!$valid_email || !$password)) {
             $updated = __('Could not create new user. You must enter a valid email address and a password first.', 'Shopp');
             $no_save = true;
         }
         if (!isset($new_save)) {
             $Customer->info = false;
             // No longer used from DB
             $Customer->save();
         }
         if (isset($_POST['info']) && !empty($_POST['info'])) {
             foreach ((array) $_POST['info'] as $id => $info) {
                 $Meta = new ShoppMetaObject($id);
                 $Meta->value = $info;
                 $Meta->save();
             }
         }
         if (isset($Customer->id)) {
             $Billing->customer = $Customer->id;
         }
         $Billing->updates($_POST['billing']);
         $Billing->save();
         if (isset($Customer->id)) {
             $Shipping->customer = $Customer->id;
         }
         $Shipping->updates($_POST['shipping']);
         $Shipping->save();
         if (!$updated) {
             __('Customer updated.', 'Shopp');
         }
         $Customer = false;
     }
     $pagenum = absint($paged);
     if (empty($pagenum)) {
         $pagenum = 1;
     }
     if (!$per_page || $per_page < 0) {
         $per_page = 20;
     }
     $index = $per_page * ($pagenum - 1);
     if (!empty($start)) {
         $startdate = $start;
         list($month, $day, $year) = explode("/", $startdate);
         $starts = mktime(0, 0, 0, $month, $day, $year);
     }
     if (!empty($end)) {
         $enddate = $end;
         list($month, $day, $year) = explode("/", $enddate);
         $ends = mktime(23, 59, 59, $month, $day, $year);
     }
     $customer_table = ShoppDatabaseObject::tablename(Customer::$table);
     $billing_table = ShoppDatabaseObject::tablename(BillingAddress::$table);
     $purchase_table = ShoppDatabaseObject::tablename(ShoppPurchase::$table);
     $users_table = $wpdb->users;
     $where = array();
     if (!empty($s)) {
         $s = stripslashes($s);
         if (preg_match_all('/(\\w+?)\\:(?="(.+?)"|(.+?)\\b)/', $s, $props, PREG_SET_ORDER)) {
             foreach ($props as $search) {
                 $keyword = !empty($search[2]) ? $search[2] : $search[3];
                 switch (strtolower($search[1])) {
                     case "company":
                         $where[] = "c.company LIKE '%{$keyword}%'";
                         break;
                     case "login":
                         $where[] = "u.user_login LIKE '%{$keyword}%'";
                         break;
                     case "address":
                         $where[] = "(b.address LIKE '%{$keyword}%' OR b.xaddress='%{$keyword}%')";
                         break;
                     case "city":
                         $where[] = "b.city LIKE '%{$keyword}%'";
                         break;
                     case "province":
                     case "state":
                         $where[] = "b.state='{$keyword}'";
                         break;
                     case "zip":
                     case "zipcode":
                     case "postcode":
                         $where[] = "b.postcode='{$keyword}'";
                         break;
                     case "country":
                         $where[] = "b.country='{$keyword}'";
                         break;
                 }
             }
         } elseif (strpos($s, '@') !== false) {
             $where[] = "c.email='{$s}'";
         } elseif (is_numeric($s)) {
             $where[] = "c.id='{$s}'";
         } else {
             $where[] = "(CONCAT(c.firstname,' ',c.lastname) LIKE '%{$s}%' OR c.company LIKE '%{$s}%')";
         }
     }
     if (!empty($starts) && !empty($ends)) {
         $where[] = ' (UNIX_TIMESTAMP(c.created) >= ' . $starts . ' AND UNIX_TIMESTAMP(c.created) <= ' . $ends . ')';
     }
     $select = array('columns' => 'SQL_CALC_FOUND_ROWS c.*,city,state,country,user_login', 'table' => "{$customer_table} as c", 'joins' => array($billing_table => "LEFT JOIN {$billing_table} AS b ON b.customer=c.id AND b.type='billing'", $users_table => "LEFT JOIN {$users_table} AS u ON u.ID=c.wpuser AND (c.wpuser IS NULL OR c.wpuser != 0)"), 'where' => $where, 'groupby' => "c.id", 'orderby' => "c.created DESC", 'limit' => "{$index},{$per_page}");
     $query = sDB::select($select);
     $Customers = sDB::query($query, 'array', 'index', 'id');
     $total = sDB::found();
     // Add order data to customer records in this view
     $orders = sDB::query("SELECT customer,SUM(total) AS total,count(id) AS orders FROM {$purchase_table} WHERE customer IN (" . join(',', array_keys($Customers)) . ") GROUP BY customer", 'array', 'index', 'customer');
     foreach ($Customers as &$record) {
         $record->total = 0;
         $record->orders = 0;
         if (!isset($orders[$record->id])) {
             continue;
         }
         $record->total = $orders[$record->id]->total;
         $record->orders = $orders[$record->id]->orders;
     }
     $num_pages = ceil($total / $per_page);
     $ListTable = ShoppUI::table_set_pagination($this->screen, $total, $num_pages, $per_page);
     $ranges = array('all' => __('Show New Customers', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'lastexport' => __('Last Export', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp'));
     $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp'), 'xls' => __('Microsoft&reg; Excel.xls', 'Shopp'));
     $formatPref = shopp_setting('customerexport_format');
     if (!$formatPref) {
         $formatPref = 'tab';
     }
     $columns = array_merge(Customer::exportcolumns(), BillingAddress::exportcolumns(), ShippingAddress::exportcolumns());
     $selected = shopp_setting('customerexport_columns');
     if (empty($selected)) {
         $selected = array_keys($columns);
     }
     $authentication = shopp_setting('account_system');
     $action = add_query_arg(array('page' => $this->Admin->pagename('customers')), admin_url('admin.php'));
     include $this->ui('customers.php');
 }
コード例 #11
0
ファイル: Orders.php プロジェクト: msigley/shopp
 public function add()
 {
     if ('new-customer' != $this->form('order-action')) {
         return;
     }
     if (!($updates = $this->form('customer'))) {
         return;
     }
     if (!is_array($updates)) {
         return;
     }
     extract($this->references, EXTR_SKIP);
     // Create the new customer record
     $Customer = new ShoppCustomer();
     $Customer->updates($updates);
     $Customer->password = wp_generate_password(12, true);
     if ('wordpress' == shopp_setting('account_system')) {
         $Customer->create_wpuser();
     } else {
         unset($this->form['loginname']);
     }
     $Customer->save();
     if (!$Customer->exists()) {
         return $this->notice(Shopp::__('An unknown error occured. The customer could not be created.'), 'error');
     }
     $Purchase->customer = $Customer->id;
     $Purchase->copydata($Customer);
     $Purchase->save();
     // Create a new billing address record for the new customer
     if ($billing = $this->form('billing') && is_array($billing) && empty($billing['id'])) {
         $Billing = new BillingAddress($billing);
         $Billing->customer = $Customer->id;
         $Billing->save();
     }
     // Create a new shipping address record for the new customer
     if ($shipping = $this->form('shipping') && is_array($shipping) && empty($shipping['id'])) {
         $Shipping = new ShippingAddress($shipping);
         $Shipping->customer = $Customer->id;
         $Shipping->save();
     }
 }
コード例 #12
0
ファイル: customer.php プロジェクト: forthrobot/inuvik
/**
 * Remove a customer, and data associated with the customer
 *
 * @api
 * @since 1.2
 *
 * @param int $customer (required) id of the customer to remove
 * @return bool true on success, false on failure
 **/
function shopp_rmv_customer($customer = false)
{
    if (!$customer) {
        shopp_debug(__FUNCTION__ . " failed: Customer id required.");
        return false;
    }
    $Customer = new ShoppCustomer($customer);
    if (empty($Customer->id)) {
        shopp_debug("shopp_rmv_customer notice: No such customer with id {$customer}");
        return false;
    }
    // Remove Addresses
    $Billing = new BillingAddress($customer, 'customer');
    $Shipping = new ShippingAddress($customer, 'customer');
    if (!empty($Billing->id)) {
        $Billing->delete();
    }
    if (!empty($Shipping->id)) {
        $Shipping->delete();
    }
    // Remove Meta records
    $metas = shopp_meta($customer, 'customer');
    foreach ($metas as $meta) {
        shopp_rmv_meta($meta->id);
    }
    // Remove Customer record
    $Customer->delete();
    return true;
}