public function screen() { if (!current_user_can('shopp_promotions')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $table = ShoppDatabaseObject::tablename(ShoppPromo::$table); $defaults = array('page' => false, 'status' => false, 'type' => false, 'paged' => 1, 'per_page' => 20, 's' => ''); $args = array_merge($defaults, $_GET); extract($args, EXTR_SKIP); $url = add_query_arg(array_merge($_GET, array('page' => $this->page)), admin_url('admin.php')); $f = array('action', 'selected', 's'); $url = remove_query_arg($f, $url); $pagenum = absint($paged); $start = $per_page * ($pagenum - 1); $where = array(); if (!empty($s)) { $where[] = "name LIKE '%{$s}%'"; } if ($status) { $datesql = ShoppPromo::activedates(); switch (strtolower($status)) { case 'active': $where[] = "status='enabled' AND {$datesql}"; break; case 'inactive': $where[] = "status='enabled' AND NOT {$datesql}"; break; case 'enabled': $where[] = "status='enabled'"; break; case 'disabled': $where[] = "status='disabled'"; break; } } if ($type) { switch (strtolower($type)) { case 'catalog': $where[] = "target='Catalog'"; break; case 'cart': $where[] = "target='Cart'"; break; case 'cartitem': $where[] = "target='Cart Item'"; break; } } $select = sDB::select(array('table' => $table, 'columns' => 'SQL_CALC_FOUND_ROWS *', 'where' => $where, 'orderby' => 'created DESC', 'limit' => "{$start},{$per_page}")); $Promotions = sDB::query($select, 'array'); $count = sDB::found(); $num_pages = ceil($count / $per_page); $ListTable = ShoppUI::table_set_pagination($this->id, $count, $num_pages, $per_page); $states = array('active' => __('Active', 'Shopp'), 'inactive' => __('Not Active', 'Shopp'), 'enabled' => __('Enabled', 'Shopp'), 'disabled' => __('Disabled', 'Shopp')); $types = array('catalog' => __('Catalog Discounts', 'Shopp'), 'cart' => __('Cart Discounts', 'Shopp'), 'cartitem' => __('Cart Item Discounts', 'Shopp')); $num_pages = ceil($count / $per_page); $page_links = paginate_links(array('base' => add_query_arg('pagenum', '%#%'), 'format' => '', 'total' => $num_pages, 'current' => $pagenum)); include $this->ui('discounts.php'); }
public function screen() { 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 == ShoppAdmin::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 "%s" 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 "%s" 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 "%s".', 'Shopp'), '<strong>'.sanitize_user($_POST['userlogin']).'</strong>'); // } else { // $updated = sprintf( __( 'Could not create a WordPress account for customer "%s".','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(ShoppAdmin::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® 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' => ShoppAdmin::pagename('customers')), admin_url('admin.php')); include $this->ui('customers.php'); }
/** * Renders the admin screen * * @author Jonathan Davis * @since 1.3 * * @return void **/ public function screen() { if (!current_user_can('shopp_financials')) { wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp')); } extract($this->options, EXTR_SKIP); $Report = $this->Report; $Report->pagination(); $ListTable = ShoppUI::table_set_pagination($screen, $Report->total, $Report->pages, $per_page); $ranges = array('all' => __('Show All Orders', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp')); $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp')); $format = shopp_setting('report_format'); if (!$format) { $format = 'tab'; } $columns = array_merge(ShoppPurchase::exportcolumns(), ShoppPurchased::exportcolumns()); $selected = shopp_setting('purchaselog_columns'); if (empty($selected)) { $selected = array_keys($columns); } $reports = self::reports(); $report_title = isset($reports[$report]) ? $reports[$report]['name'] : __('Report', 'Shopp'); include $this->ui('reports.php'); }
/** * Interface processor for the orders list interface * * @author Jonathan Davis * * @return void **/ public function orders() { if (!current_user_can('shopp_orders')) { wp_die(__('You do not have sufficient permissions to access this page.', 'Shopp')); } global $Shopp, $Orders; $defaults = array('page' => false, 'update' => false, 'newstatus' => false, 'paged' => 1, 'per_page' => 20, 'status' => false, 's' => '', 'range' => '', 'startdate' => '', 'enddate' => ''); $args = array_merge($defaults, $_GET); extract($args, EXTR_SKIP); $s = stripslashes($s); $statusLabels = shopp_setting('order_status'); if (empty($statusLabels)) { $statusLabels = array(''); } $txnstatus_labels = Lookup::txnstatus_labels(); $Purchase = new ShoppPurchase(); $Orders = $this->orders; $ordercount = $this->ordercount; $num_pages = ceil($ordercount->total / $per_page); $ListTable = ShoppUI::table_set_pagination($this->screen, $ordercount->total, $num_pages, $per_page); $ranges = array('all' => __('Show All Orders', 'Shopp'), 'today' => __('Today', 'Shopp'), 'week' => __('This Week', 'Shopp'), 'month' => __('This Month', 'Shopp'), 'quarter' => __('This Quarter', 'Shopp'), 'year' => __('This Year', 'Shopp'), 'yesterday' => __('Yesterday', 'Shopp'), 'lastweek' => __('Last Week', 'Shopp'), 'last30' => __('Last 30 Days', 'Shopp'), 'last90' => __('Last 3 Months', 'Shopp'), 'lastmonth' => __('Last Month', 'Shopp'), 'lastquarter' => __('Last Quarter', 'Shopp'), 'lastyear' => __('Last Year', 'Shopp'), 'lastexport' => __('Last Export', 'Shopp'), 'custom' => __('Custom Dates', 'Shopp')); $exports = array('tab' => __('Tab-separated.txt', 'Shopp'), 'csv' => __('Comma-separated.csv', 'Shopp'), 'xls' => __('Microsoft® Excel.xls', 'Shopp'), 'iif' => __('Intuit® QuickBooks.iif', 'Shopp')); $formatPref = shopp_setting('purchaselog_format'); if (!$formatPref) { $formatPref = 'tab'; } $exportcolumns = array_merge(ShoppPurchase::exportcolumns(), ShoppPurchased::exportcolumns()); $selected = shopp_setting('purchaselog_columns'); if (empty($selected)) { $selected = array_keys($exportcolumns); } $Gateways = $Shopp->Gateways; include $this->ui('orders.php'); }
public function images() { if (!current_user_can('shopp_settings')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $defaults = array('paged' => 1, 'per_page' => 25, 'action' => false, 'selected' => array()); $args = array_merge($defaults, $_REQUEST); extract($args, EXTR_SKIP); $edit = false; if (isset($_GET['id'])) { $edit = (int) $_GET['id']; if ('new' == $_GET['id']) { $edit = 'new'; } } if (isset($_GET['delete']) || 'delete' == $action) { check_admin_referer('shopp-settings-images'); if (!empty($_GET['delete'])) { $selected[] = (int) $_GET['delete']; } $selected = array_filter($selected); foreach ($selected as $delete) { $Record = new ImageSetting((int) $delete); $Record->delete(); } } if (!empty($_POST['save'])) { check_admin_referer('shopp-settings-images'); $ImageSetting = new ImageSetting($edit); $_POST['name'] = sanitize_title_with_dashes($_POST['name']); $_POST['sharpen'] = floatval(str_replace('%', '', $_POST['sharpen'])); $ImageSetting->updates($_POST); if (!empty($ImageSetting->name)) { $ImageSetting->save(); } } $start = $per_page * ($paged - 1); $ImageSetting = new ImageSetting($edit); $table = $ImageSetting->_table; $columns = 'SQL_CALC_FOUND_ROWS *'; $where = array("type='{$ImageSetting->type}'", "context='{$ImageSetting->context}'"); $limit = "{$start},{$per_page}"; $options = compact('columns', 'useindex', 'table', 'joins', 'where', 'groupby', 'having', 'limit', 'orderby'); $query = sDB::select($options); $settings = sDB::query($query, 'array', array($ImageSetting, 'loader')); $total = sDB::found(); $num_pages = ceil($total / $per_page); $ListTable = ShoppUI::table_set_pagination($this->screen, $total, $num_pages, $per_page); $fit_menu = $ImageSetting->fit_menu(); $quality_menu = $ImageSetting->quality_menu(); $actions_menu = array('delete' => __('Delete', 'Shopp')); $json_settings = array(); $skip = array('created', 'modified', 'numeral', 'context', 'type', 'sortorder', 'parent'); foreach ($settings as &$Setting) { if (method_exists($Setting, 'json')) { $json_settings[$Setting->id] = $Setting->json($skip); } } include $this->ui('images.php'); }
/** * Interface processor for the product list manager * * @author Jonathan Davis * @since 1.0 * @version 1.2 * * @param boolean $workflow True to get workflow data * @return void **/ public function manager() { if (!current_user_can('shopp_products')) { wp_die(__('You do not have sufficient permissions to access this page.')); } // Explicitly recall the loader to reload products inside the admin content $this->loader(); $defaults = array('cat' => false, 'paged' => 1, 'per_page' => 20, 's' => '', 'sl' => '', 'matchcol' => '', 'view' => $this->view, 'is_inventory' => false, 'is_trash' => false, 'is_bestselling' => false, 'categories_menu' => false, 'inventory_menu' => false, 'lowstock' => 0, 'columns' => '', 'orderby' => '', 'order' => '', 'where' => array(), 'joins' => array()); $args = array_merge($defaults, $_GET); $per_page_option = get_current_screen()->get_option('per_page'); if (false !== ($user_per_page = get_user_option($per_page_option['option']))) { $args['per_page'] = $user_per_page; } extract($args, EXTR_SKIP); $url = add_query_arg(array_merge($_GET, array('page' => $this->Admin->pagename('products'))), admin_url('admin.php')); if (empty($categories)) { $categories = array(''); } $categories_menu = wp_dropdown_categories(array('show_option_all' => __('View all categories', 'Shopp'), 'show_option_none' => __('Uncategorized', 'Shopp'), 'hide_empty' => 0, 'hierarchical' => 1, 'show_count' => 0, 'orderby' => 'name', 'selected' => $cat, 'echo' => 0, 'taxonomy' => 'shopp_category')); if ('on' == shopp_setting('inventory')) { $inventory_filters = array('all' => __('View all products', 'Shopp'), 'is' => __('In stock', 'Shopp'), 'ls' => __('Low stock', 'Shopp'), 'oos' => __('Out-of-stock', 'Shopp'), 'ns' => __('Not stocked', 'Shopp')); $inventory_menu = '<select name="sl">' . Shopp::menuoptions($inventory_filters, $sl, true) . '</select>'; } if ('off' == shopp_setting('inventory')) { unset($this->subs['inventory']); } switch ($view) { case 'inventory': if (shopp_setting_enabled('inventory')) { $is_inventory = true; } break; case 'trash': $is_trash = true; break; case 'bestselling': $is_bestselling = true; break; } if ($is_inventory) { $per_page = 50; } $pagenum = absint($paged); $start = $per_page * ($pagenum - 1); $actions_menu = array('publish' => __('Publish', 'Shopp'), 'unpublish' => __('Unpublish', 'Shopp'), 'feature' => __('Feature', 'Shopp'), 'defeature' => __('De-feature', 'Shopp'), 'trash' => __('Move to trash', 'Shopp')); if ($is_trash) { $actions_menu = array('restore' => __('Restore', 'Shopp'), 'delete' => __('Delete permanently', 'Shopp')); } global $Products; $Products = $this->products; $num_pages = ceil($Products->total / $per_page); $ListTable = ShoppUI::table_set_pagination($this->screen, $Products->total, $num_pages, $per_page); $subs = $this->subs; switch ($view) { case 'inventory': if (shopp_setting_enabled('inventory')) { $ui = 'inventory.php'; } break; default: $ui = 'products.php'; break; } include SHOPP_ADMIN_PATH . '/products/' . $ui; }
/** * Interface processor for the category list manager * * @author Jonathan Davis * @since 1.0 * @return void **/ public function screen($workflow = false) { if (!current_user_can('shopp_categories')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $per_page_option = get_current_screen()->get_option('per_page'); $defaults = array('paged' => 1, 'per_page' => 20, 's' => '', 'a' => ''); $args = array_merge($defaults, $_GET); if (false !== ($user_per_page = get_user_option($per_page_option['option']))) { $args['per_page'] = $user_per_page; } extract($args, EXTR_SKIP); if ('arrange' == $a) { $this->init_positions(); $per_page = 300; } $paged = absint($paged); $start = $per_page * ($paged - 1); $end = $start + $per_page; $url = add_query_arg(array_merge($_GET, array('page' => ShoppAdmin::pagename('categories'))), admin_url('admin.php')); $taxonomy = 'shopp_category'; $filters = array('hide_empty' => 0, 'fields' => 'id=>parent'); add_filter('get_shopp_category', array($this, 'load_category'), 10, 2); // $filters['limit'] = "$start,$per_page"; if (!empty($s)) { $filters['search'] = $s; } $Categories = array(); $count = 0; $terms = get_terms($taxonomy, $filters); if (empty($s)) { $children = _get_term_hierarchy($taxonomy); ProductCategory::tree($taxonomy, $terms, $children, $count, $Categories, $paged, $per_page); $this->categories = $Categories; } else { foreach ($terms as $id => $parent) { $Categories[$id] = get_term($id, $taxonomy); } } $ids = array_keys($Categories); if ($workflow) { return $ids; } $meta = ShoppDatabaseObject::tablename(ShoppMetaObject::$table); if (!empty($ids)) { sDB::query("SELECT * FROM {$meta} WHERE parent IN (" . join(',', $ids) . ") AND context='category' AND type='meta'", 'array', array($this, 'metaloader')); } $count = wp_count_terms('shopp_category'); $num_pages = ceil($count / $per_page); $ListTable = ShoppUI::table_set_pagination($this->id, $count, $num_pages, $per_page); $action = esc_url(add_query_arg(array_merge(stripslashes_deep($_GET), array('page' => ShoppAdmin::pagename('categories'))), admin_url('admin.php'))); include $this->ui('categories.php'); }