/** * Adds a ShoppAdminPage entry to the WordPress menus under the Shopp menus * * @author Jonathan Davis * @since 1.1 * * @param ShoppAdminPage $Page A ShoppAdminPage object * @return void **/ private function submenus(ShoppAdminPage $Page) { $name = $Page->name; $pagehook = $Page->page; // Set capability $capability = isset($this->caps[$name]) ? $this->caps[$name] : 'none'; $taxonomies = get_object_taxonomies(ShoppProduct::$posttype, 'names'); if (in_array("shopp_{$name}", $taxonomies)) { $capability = 'shopp_categories'; } // Set controller (callback handler) $controller = array(ShoppAdmin(), 'route'); if (Shopp::upgradedb()) { $controller = array('ShoppAdmin', 'updatedb'); } $menu = $Page->parent ? $Page->parent : $this->mainmenu; shopp_admin_add_submenu($Page->label, $pagehook, $menu, $controller, $capability); }
/** * Renders the recent orders dashboard widget * * @author Jonathan Davis * @since 1.0 * * @return void **/ public static function orders_widget($args = false) { $defaults = array('before_widget' => '', 'before_title' => '', 'widget_name' => '', 'after_title' => '', 'after_widget' => ''); $args = array_merge($defaults, (array) $args); extract($args, EXTR_SKIP); $statusLabels = shopp_setting('order_status'); echo $before_widget; echo $before_title; echo $widget_name; echo $after_title; $purchasetable = ShoppDatabaseObject::tablename(ShoppPurchase::$table); $purchasedtable = ShoppDatabaseObject::tablename(Purchased::$table); $txnlabels = Lookup::txnstatus_labels(); if (!($Orders = get_transient('shopp_dashboard_orders'))) { $Orders = sDB::query("SELECT p.*,count(*) as items FROM (SELECT * FROM {$purchasetable} WHERE txnstatus != 'purchased' AND txnstatus != 'invoiced' ORDER BY created DESC LIMIT 6) AS p LEFT JOIN {$purchasedtable} AS i ON i.purchase=p.id GROUP BY p.id ORDER BY p.id DESC", 'array'); set_transient('shopp_dashboard_orders', $Orders, 90); // Keep for the next 1 minute } if (!empty($Orders)) { echo '<table class="widefat">' . '<thead>' . ' <tr>' . ' <th scope="col">' . __('Name', 'Shopp') . '</th>' . ' <th scope="col">' . __('Date', 'Shopp') . '</th>' . ' <th scope="col" class="num">' . Shopp::__('Items') . '</th>' . ' <th scope="col" class="num">' . Shopp::__('Total') . '</th>' . ' <th scope="col" class="num">' . Shopp::__('Status') . '</th>' . ' </tr>' . '</thead>' . ' <tbody id="orders" class="list orders">'; $even = false; foreach ($Orders as $Order) { $classes = array(); if ($even = !$even) { $classes[] = 'alternate'; } $txnstatus = isset($txnlabels[$Order->txnstatus]) ? $txnlabels[$Order->txnstatus] : $Order->txnstatus; $status = isset($statusLabels[$Order->status]) ? $statusLabels[$Order->status] : $Order->status; $contact = '' == $Order->firstname . $Order->lastname ? '(no contact name)' : $Order->firstname . ' ' . $Order->lastname; $url = add_query_arg(array('page' => ShoppAdmin()->pagename('orders'), 'id' => $Order->id), admin_url('admin.php')); $classes[] = strtolower(preg_replace('/[^\\w]/', '_', $Order->txnstatus)); echo '<tr class="' . join(' ', $classes) . '">' . ' <td><a class="row-title" href="' . $url . '" title="View "Order ' . $Order->id . '"">' . (empty($Order->firstname) && empty($Order->lastname) ? '(no contact name)' : $Order->firstname . ' ' . $Order->lastname) . '</a></td>' . ' <td>' . date("Y/m/d", mktimestamp($Order->created)) . '</td>' . ' <td class="num items">' . $Order->items . '</td>' . ' <td class="num total">' . money($Order->total) . '</td>' . ' <td class="num status">' . $statusLabels[$Order->status] . '</td>' . '</tr>'; } echo '</tbody></table>'; } else { echo '<p>' . Shopp::__('No orders, yet.') . '</p>'; } echo $after_widget; }
/** * Builds the interface layout for the customer editor * * @author Jonathan Davis * @return void **/ public function layout() { $Shopp = Shopp::object(); $Admin = ShoppAdmin(); $Customer = $this->Model; $default = array('' => ' '); $countries = array_merge($default, ShoppLookup::countries()); $Customer->_countries = $countries; $states = ShoppLookup::country_zones(array($Customer->Billing->country, $Customer->Shipping->country)); $Customer->_billing_states = array_merge($default, (array) $states[$Customer->Billing->country]); $Customer->_shipping_states = array_merge($default, (array) $states[$Customer->Shipping->country]); new ShoppAdminCustomerSaveBox($this->id, 'side', 'core', array('Customer' => $Customer)); new ShoppAdminCustomerSettingsBox($this->id, 'side', 'core', array('Customer' => $Customer)); new ShoppAdminCustomerLoginBox($this->id, 'side', 'core', array('Customer' => $Customer)); new ShoppAdminCustomerContactBox($this->id, 'normal', 'core', array('Customer' => $Customer)); if (!empty($Customer->info->meta) && is_array($Customer->info->meta)) { new ShoppAdminCustomerInfoBox($this->id, 'normal', 'core', array('Customer' => $Customer)); } new ShoppAdminCustomerBillingAddressBox($this->id, 'normal', 'core', array('Customer' => $Customer)); new ShoppAdminCustomerShippingAddressBox($this->id, 'normal', 'core', array('Customer' => $Customer)); }
?> </tr> </thead> <tfoot> <tr><?php print_column_headers(ShoppAdmin()->screen(), false); ?> </tr> </tfoot> <?php if (count($Orders) > 0) { ?> <tbody id="orders-table" class="list orders"> <?php $columns = get_column_headers(ShoppAdmin()->screen()); $hidden = get_hidden_columns(ShoppAdmin()->screen()); $url = add_query_arg('page', 'shopp-orders', admin_url('admin.php')); $even = false; foreach ($Orders as $Order) { $classes = array(); $viewurl = add_query_arg('id', $Order->id, $url); $customer = '' == trim($Order->firstname . $Order->lastname) ? "(" . __('no contact name', 'Shopp') . ")" : ucfirst("{$Order->firstname} {$Order->lastname}"); $customerurl = add_query_arg(array('page' => 'shopp-customers', 'id' => $Order->customer), $url); $txnstatus = isset($txnstatus_labels[$Order->txnstatus]) ? $txnstatus_labels[$Order->txnstatus] : $Order->txnstatus; $classes[] = strtolower(preg_replace('/[^\\w]/', '_', $Order->txnstatus)); $Gateway = $Gateways->get($Order->gateway); if ($Gateway) { $gateway = $Gateway->name; } $addrfields = array('city', 'state', 'country'); $format = '%3$s, %2$s — %1$s';
/** * Renders the bestselling products dashboard widget * * @author Jonathan Davis * @since 1.0 * * @return void **/ public static function inventory_widget($args = false) { $warnings = array('none' => __('OK', 'Shopp'), 'warning' => __('warning', 'Shopp'), 'critical' => __('critical', 'Shopp'), 'backorder' => __('backorder', 'Shopp')); $defaults = array('before_widget' => '', 'before_title' => '', 'widget_name' => '', 'after_title' => '', 'after_widget' => ''); $args = array_merge($defaults, (array) $args); extract($args, EXTR_SKIP); $pt = ShoppDatabaseObject::tablename(ShoppPrice::$table); $setting = shopp_setting('lowstock_level'); $where = array(); $where[] = "pt.stock < pt.stocked AND pt.stock/pt.stocked < {$setting}"; $where[] = "(pt.context='product' OR pt.context='variation') AND pt.type != 'N/A'"; $loading = array('columns' => "pt.id AS stockid,IF(pt.context='variation',CONCAT(p.post_title,': ',pt.label),p.post_title) AS post_title,pt.sku AS sku,pt.stock,pt.stocked", 'joins' => array($pt => "LEFT JOIN {$pt} AS pt ON p.ID=pt.product"), 'where' => $where, 'groupby' => 'pt.id', 'orderby' => '(pt.stock/pt.stocked) ASC', 'published' => false, 'pagination' => false, 'limit' => 25); $Collection = new ProductCollection(); $Collection->load($loading); $productscreen = add_query_arg(array('page' => ShoppAdmin()->pagename('products')), admin_url('admin.php')); echo $before_widget; echo $before_title; echo $widget_name; echo $after_title; ?> <table><tbody> <?php foreach ($Collection->products as $product) { $product->lowstock($product->stock, $product->stocked); ?> <tr> <td class="amount"><?php echo abs($product->stock); ?> </td> <td><span class="stock lowstock <?php echo $product->lowstock; ?> "><?php echo $warnings[$product->lowstock]; ?> </span></td> <td><a href="<?php echo esc_url(add_query_arg('id', $product->id, $productscreen)); ?> "><?php echo $product->name; ?> </a></td> <td><a href="<?php echo esc_url(add_query_arg('view', 'inventory', $productscreen)); ?> "><?php echo $product->sku; ?> </a></td> </tr> <?php } ?> </tbody></table> <?php echo $after_widget; }
?> <div class="conditionals no-conditions"> <p><label><?php printf(__('Apply tax rate when %s of the following conditions match', 'Shopp'), $menu); ?> :</label></p> <ul> ${conditions} </ul> </div> </td> <td> <div class="local-rates panel subpanel no-local-rates"> <div class="label"><label><?php _e('Local Rates', 'Shopp'); echo ShoppAdmin()->boxhelp('settings-taxes-localrates'); ?> <span class="counter"></span><input type="hidden" name="settings[taxrates][${id}][haslocals]" value="${haslocals}" class="has-locals" /></label></div> <div class="ui"> <p class="instructions"><?php Shopp::_e('No local regions have been setup for this location. Local regions can be specified by uploading a formatted local rates file.'); ?> </p> ${errors} <ul>${localrates}</ul> <div class="upload"> <h3><?php Shopp::_e('Upload Local Tax Rates'); ?> </h3> <input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
/** * Renders the screen tabs registered for the current plugin page * * @api * @since 1.3 * * @return void **/ function shopp_admin_screen_tabs() { global $plugin_page; $tabs = ShoppAdmin()->tabs($plugin_page); $first = current($tabs); $default = $first[1]; $markup = array(); foreach ($tabs as $index => $entry) { list($title, $tab, $parent) = $entry; $classes = array('nav-tab'); if ($plugin_page == $parent && $default == $tab || $plugin_page == $tab) { $classes[] = 'nav-tab-active'; } $markup[] = '<a href="' . add_query_arg(array('page' => $tab), admin_url('admin.php')) . '" class="' . join(' ', $classes) . '">' . $title . '</a>'; } $pagehook = sanitize_key($plugin_page); echo '<h2 class="nav-tab-wrapper">' . join('', apply_filters('shopp_admin_' . $pagehook . '_screen_tabs', $markup)) . '</h2>'; }
/** * Provides the admin screen page value * * @since 1.3 * * @return string The prefixed admin page name **/ public function page() { return ShoppAdmin()->pagename($this->pagename); }