Пример #1
0
 /**
  * ecartregcust::add_user()
  * 
  * @param mixed $data
  * @return
  */
 private function add_user()
 {
     require_once(ABSPATH."/wp-includes/registration.php");
     
     $Errors =& EcartErrors();
     $Errors->reset();
     if (empty($_POST['customer']['email'])) 
     {
         $this->form_error = 'Email address is required.';
         return false;
     }
     if ($this->email_exists($_POST['customer']['email'])) 
     {
         $this->form_error = 'Email address is already registered with another customer.';
         return false;
     }
     if (empty($_POST['customer']['password'])) 
     {
         $this->form_error = 'Password is required.';
         return false;
     }
     if ($_POST['customer']['password'] !== $_POST['customer']['confirm-password']) 
     {
         $this->form_error = 'Passwords do not match.';
         return false;
     } 
     if ($this->ecart_account_type == 'wordpress')
     {
         if (empty($_POST['customer']['loginname'])) 
         {
             $this->form_error = 'Username is already registered.';
             return false;                
         }
         if (email_exists($_POST['customer']['email']))
         {
             $this->form_error = 'Email address is already registered with another user.';
             return false;                 
         }
     }
     if ($this->show_billing)
     {
         if (empty($_POST['billing']['address']))
         {
             $this->form_error = 'Street address is required.';
             return false;                
         }
         if (empty($_POST['billing']['city']))
         {
             $this->form_error = 'City is required.';
             return false;                
         }
         if (empty($_POST['billing']['state']))
         {
             $this->form_error = 'State is required.';
             return false;                
         }
         if (empty($_POST['billing']['postcode']))
         {
             $this->form_error = 'Postcode is required.';
             return false;                
         }
     }
     
     $customer_data = $_POST['customer'];
     
     $ecart_customer = new Customer();
     $ecart_customer->updates($customer_data);
     
     if ($this->ecart_account_type == 'wordpress') 
     {
         $ecart_customer->create_wpuser(); // not logged in, create new account
         $customer_data['wpuser'] = $ecart_customer->wpuser;
         unset($ecart_customer->password);
         if ($Errors->exist(ECART_ERR)) 
         {
             $ecart_error = $Errors->get(ECART_ERR);
             $this->form_error = implode(', ', $ecart_error[0]->messages);
             return false;
         }
     }
     else
     {       
         $ecart_customer->password = wp_hash_password($data['password']);
     }        
     $ecart_customer->save();
     
     if ($Errors->exist(ECART_ERR)) 
     {
         $ecart_error = $Errors->get(ECART_ERR);
         $this->form_error = implode(', ', $ecart_error[0]->messages);
         return false;
     }                
     if ($this->show_billing)
     {
         $billing_data = $_POST['billing'];
         $ecart_billing = new Billing();  
         $ecart_billing->updates($billing_data);
         $ecart_billing->customer = $ecart_customer->id;
         $ecart_billing->save();
     }        
     
     return $customer_data;
 }
 function customers_list()
 {
     global $Shopp, $Customers, $wpdb;
     $db = DB::get();
     $defaults = array('page' => false, 'deleting' => false, 'selected' => false, 'update' => false, 'newstatus' => false, 'pagenum' => 1, 'per_page' => false, 'start' => '', 'end' => '', 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => '');
     $args = array_merge($defaults, $_GET);
     extract($args, EXTR_SKIP);
     if ($page == "shopp-customers" && !empty($deleting) && !empty($selected) && is_array($selected)) {
         foreach ($selected as $deletion) {
             $Customer = new Customer($deletion);
             $Billing = new Billing($Customer->id, 'customer');
             $Billing->delete();
             $Shipping = new Shipping($Customer->id, 'customer');
             $Shipping->delete();
             $Customer->delete();
         }
     }
     if (!empty($_POST['save'])) {
         check_admin_referer('shopp-save-customer');
         if ($_POST['id'] != "new") {
             $Customer = new Customer($_POST['id']);
             $Billing = new Billing($Customer->id, 'customer');
             $Shipping = new Shipping($Customer->id, 'customer');
         } else {
             $Customer = new Customer();
         }
         $Customer->updates($_POST);
         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);
             }
         }
         $Customer->save();
         $Billing->updates($_POST['billing']);
         $Billing->save();
         $Shipping->updates($_POST['shipping']);
         $Shipping->save();
     }
     $pagenum = absint($pagenum);
     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 = DatabaseObject::tablename(Customer::$table);
     $billing_table = DatabaseObject::tablename(Billing::$table);
     $purchase_table = DatabaseObject::tablename(Purchase::$table);
     $users_table = $wpdb->users;
     $where = '';
     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 .= (empty($where) ? "WHERE " : " AND ") . "c.company LIKE '%{$keyword}%'";
                         break;
                     case "login":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "u.user_login LIKE '%{$keyword}%'";
                         break;
                     case "address":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "(b.address LIKE '%{$keyword}%' OR b.xaddress='%{$keyword}%')";
                         break;
                     case "city":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "b.city LIKE '%{$keyword}%'";
                         break;
                     case "province":
                     case "state":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "b.state='{$keyword}'";
                         break;
                     case "zip":
                     case "zipcode":
                     case "postcode":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "b.postcode='{$keyword}'";
                         break;
                     case "country":
                         $where .= (empty($where) ? "WHERE " : " AND ") . "b.country='{$keyword}'";
                         break;
                 }
             }
         } elseif (strpos($s, '@') !== false) {
             $where .= (empty($where) ? "WHERE " : " AND ") . "c.email='{$s}'";
         } else {
             $where .= (empty($where) ? "WHERE " : " AND ") . " (c.id='{$s}' OR CONCAT(c.firstname,' ',c.lastname) LIKE '%{$s}%' OR c.company LIKE '%{$s}%')";
         }
     }
     if (!empty($starts) && !empty($ends)) {
         $where .= (empty($where) ? "WHERE " : " AND ") . ' (UNIX_TIMESTAMP(c.created) >= ' . $starts . ' AND UNIX_TIMESTAMP(c.created) <= ' . $ends . ')';
     }
     $customercount = $db->query("SELECT count(*) as total FROM {$customer_table} AS c {$where}");
     $query = "SELECT c.*,b.city,b.state,b.country, u.user_login, SUM(p.total) AS total,count(distinct p.id) AS orders FROM {$customer_table} AS c LEFT JOIN {$purchase_table} AS p ON p.customer=c.id LEFT JOIN {$billing_table} AS b ON b.customer=c.id LEFT JOIN {$users_table} AS u ON u.ID=c.wpuser AND (c.wpuser IS NULL OR c.wpuser !=0) {$where} GROUP BY c.id ORDER BY c.created DESC LIMIT {$index},{$per_page}";
     $Customers = $db->query($query, AS_ARRAY);
     $num_pages = ceil($customercount->total / $per_page);
     $page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'total' => $num_pages, 'current' => $pagenum));
     $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->Settings->get('customerexport_format');
     if (!$formatPref) {
         $formatPref = 'tab';
     }
     $columns = array_merge(Customer::exportcolumns(), Billing::exportcolumns(), Shipping::exportcolumns());
     $selected = $Shopp->Settings->get('customerexport_columns');
     if (empty($selected)) {
         $selected = array_keys($columns);
     }
     $authentication = $Shopp->Settings->get('account_system');
     include "{$this->basepath}/core/ui/customers/customers.php";
 }