Beispiel #1
0
    public function prepare_items()
    {
        $this->id = 'taxrates';
        $defaults = array('paged' => 1, 'per_page' => 25, 'action' => false);
        $args = array_merge($defaults, $_GET);
        extract($args, EXTR_SKIP);
        $rates = (array) shopp_setting('taxrates');
        $this->items = array();
        foreach ($rates as $index => $taxrate) {
            $this->items[$index] = array_merge(self::$template, array('id' => $index), $taxrate);
        }
        $specials = array(ShoppTax::ALL => Shopp::__('All Markets'));
        if (ShoppTax::euvat(false, ShoppBaseLocale()->country(), ShoppTax::EUVAT)) {
            $specials[ShoppTax::EUVAT] = Shopp::__('European Union');
        }
        $this->countries = array_filter(array_merge($specials, (array) shopp_setting('target_markets')));
        $this->zones = ShoppLookup::country_zones();
        $total = count($this->items);
        $this->set_pagination_args(array('total_items' => $total, 'total_pages' => $total / $per_page, 'per_page' => $per_page));
        shopp_custom_script('taxrates', '
			var suggurl = "' . wp_nonce_url(admin_url('admin-ajax.php'), 'wp_ajax_shopp_suggestions') . '",
				rates   = ' . json_encode($this->items) . ',
				zones   = ' . json_encode($this->zones) . ',
				lookup  = ' . json_encode(ShoppLookup::localities()) . ',
				taxrates = [];
		');
    }
Beispiel #2
0
 public function taxrates()
 {
     if (!current_user_can('shopp_settings_taxes')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $edit = false;
     if (isset($_REQUEST['id'])) {
         $edit = (int) $_REQUEST['id'];
     }
     $localerror = false;
     $rates = shopp_setting('taxrates');
     if (!is_array($rates)) {
         $rates = array();
     }
     if (isset($_GET['delete'])) {
         check_admin_referer('shopp_delete_taxrate');
         $delete = (int) $_GET['delete'];
         if (isset($rates[$delete])) {
             array_splice($rates, $delete, 1);
         }
         shopp_set_setting('taxrates', $rates);
     }
     if (isset($_POST['editing'])) {
         $rates[$edit] = $_POST['settings']['taxrates'][$edit];
     }
     if (isset($_POST['addrule'])) {
         $rates[$edit]['rules'][] = array('p' => '', 'v' => '');
     }
     if (isset($_POST['deleterule'])) {
         check_admin_referer('shopp-settings-taxrates');
         list($rateid, $row) = explode(',', $_POST['deleterule']);
         if (isset($rates[$rateid]) && isset($rates[$rateid]['rules'])) {
             array_splice($rates[$rateid]['rules'], $row, 1);
             shopp_set_setting('taxrates', $rates);
         }
     }
     if (isset($rates[$edit]['haslocals'])) {
         $rates[$edit]['haslocals'] = $rates[$edit]['haslocals'] == 'true' || $rates[$edit]['haslocals'] == '1';
     }
     if (isset($_POST['add-locals'])) {
         $rates[$edit]['haslocals'] = true;
     }
     if (isset($_POST['remove-locals'])) {
         $rates[$edit]['haslocals'] = false;
         $rates[$edit]['locals'] = array();
     }
     $upload = $this->taxrate_upload();
     if ($upload !== false) {
         if (isset($upload['error'])) {
             $localerror = $upload['error'];
         } else {
             $rates[$edit]['locals'] = $upload;
         }
     }
     if (isset($_POST['editing'])) {
         // Re-sort taxes from generic to most specific
         usort($rates, array($this, 'taxrates_sorting'));
         $rates = stripslashes_deep($rates);
         shopp_set_setting('taxrates', $rates);
     }
     if (isset($_POST['addrate'])) {
         $edit = count($rates);
     }
     if (isset($_POST['submit'])) {
         $edit = false;
     }
     $base = shopp_setting('base_operations');
     $specials = array(ShoppTax::ALL => Shopp::__('All Markets'));
     if (ShoppTax::euvat(false, $base['country'], ShoppTax::EUVAT)) {
         $specials[ShoppTax::EUVAT] = Shopp::__('European Union');
     }
     $countries = array_merge($specials, (array) shopp_setting('target_markets'));
     $zones = Lookup::country_zones();
     include $this->ui('taxrates.php');
 }