function _wpsc_admin_download_file()
{
    if (!wpsc_is_store_admin()) {
        return;
    }
    $file_id = $_REQUEST['wpsc_download_id'];
    check_admin_referer('wpsc-admin-download-file-' . $file_id);
    $file_data = get_post($file_id);
    _wpsc_force_download_file($file_id);
}
function _wpsc_remove_erroneous_files()
{
    if (!wpsc_is_store_admin()) {
        return;
    }
    $files = array(WPSC_FILE_PATH . '/wpsc-components/marketplace-core-v1/library/Sputnik/.htaccess', WPSC_FILE_PATH . '/wpsc-components/marketplace-core-v1/library/Sputnik/error_log', WPSC_FILE_PATH . '/wpsc-components/marketplace-core-v1/library/Sputnik/functions.php', WPSC_FILE_PATH . '/wpsc-components/marketplace-core-v1/library/Sputnik/admin-functions.php', WPSC_FILE_PATH . '/wpsc-components/marketplace-core-v1/library/Sputnik/advanced-cache.php');
    foreach ($files as $file) {
        if (is_file($file)) {
            @unlink($file);
        }
    }
    update_option('wpsc_38131_file_check', false);
}
function wpsc_google_shipping_settings()
{
    _wpsc_deprecated_function(__FUNCTION__, '3.8.14');
    if (!wpsc_is_store_admin()) {
        return;
    }
    if (isset($_POST['submit'])) {
        foreach ((array) $_POST['google_shipping'] as $key => $country) {
            if ($country == 'on') {
                $google_shipping_country[] = $key;
                $updated++;
            }
        }
        update_option('google_shipping_country', $google_shipping_country);
        $sendback = wp_get_referer();
        $sendback = remove_query_arg('googlecheckoutshipping', $sendback);
        if (isset($updated)) {
            $sendback = add_query_arg('updated', $updated, $sendback);
        }
        wp_redirect(esc_url_raw($sendback));
        exit;
    }
}
function wpsc_force_flush_theme_transients()
{
    if (!wpsc_is_store_admin()) {
        return;
    }
    // Flush transients
    wpsc_flush_theme_transients(true);
    // Bounce back
    $sendback = wp_get_referer();
    wp_redirect($sendback);
    exit;
}
Beispiel #5
0
function wpsc_backup_theme()
{
    if (!wpsc_is_store_admin()) {
        return;
    }
    $wp_theme_path = get_stylesheet_directory();
    wpsc_recursive_copy($wp_theme_path, WPSC_THEME_BACKUP_DIR);
    $_SESSION['wpsc_themes_backup'] = true;
    $sendback = wp_get_referer();
    wp_redirect($sendback);
    exit;
}
/**
 * Checks visitor and visitor meta table for corruption.
 *
 * If tables are corrupted, site admins are alerted and given the ability to repair them.
 *
 * @since  3.9.4
 * @return void
 */
function wpsc_check_visitor_tables()
{
    // Don't check if current user is not a store admin or if we have checked in the last hour.
    if (wpsc_is_store_admin() && !($check = get_transient('wpsc_tables_intact'))) {
        global $wpdb;
        $visitor_check = $wpdb->get_row("CHECK TABLE {$wpdb->wpsc_visitors}");
        $visitor_meta_check = $wpdb->get_row("CHECK TABLE {$wpdb->wpsc_visitormeta}");
        // If both tables are fine
        if ('OK' == $visitor_check->Msg_text && 'OK' == $visitor_meta_check->Msg_text) {
            set_transient('wpsc_tables_intact', true, HOUR_IN_SECONDS);
            return;
        } else {
            set_transient('wpsc_tables_intact', false, HOUR_IN_SECONDS);
        }
        add_action('all_admin_notices', 'wpsc_visitor_tables_need_repair');
    }
}
 public static function admin_head_page()
 {
     if (!wpsc_is_store_admin()) {
         return;
     }
     add_filter('admin_body_class', array(__CLASS__, 'admin_body_class'));
     if (self::$page === 'dash') {
         self::$list_table = new Sputnik_List_Install();
         $pagenum = self::$list_table->get_pagenum();
         self::$list_table->prepare_items();
     } elseif (self::$page === 'account') {
         self::$list_table = new Sputnik_List_Account();
         $pagenum = self::$list_table->get_pagenum();
         self::$list_table->prepare_items();
     }
     add_action('sputnik_messages', array(__CLASS__, 'admin_notices'));
 }
function wpsc_display_coupons_page()
{
    global $wpdb;
    /**
     * Update / create code that will be abstracted to its own class at some point
     */
    if (isset($_POST) && is_array($_POST) && !empty($_POST)) {
        if (isset($_POST['add_coupon']) && (!isset($_POST['is_edit_coupon']) || !($_POST['is_edit_coupon'] == 'true'))) {
            check_admin_referer('wpsc_coupon', 'wpsc-coupon-add');
            if (!function_exists('wpsc_is_store_admin') || !wpsc_is_store_admin()) {
                wp_die(__('Permission denied', 'wpsc'));
            }
            $coupon_code = $_POST['add_coupon_code'];
            $discount = (double) $_POST['add_discount'];
            $discount_type = (int) $_POST['add_discount_type'];
            $use_once = (int) (bool) $_POST['add_use-once'];
            $every_product = (int) (bool) $_POST['add_every_product'];
            $is_active = (int) (bool) $_POST['add_active'];
            $start_date = !empty($_POST['add_start']) ? date('Y-m-d', strtotime($_POST['add_start'])) . " 00:00:00" : "0000-00-00 00:00:00";
            $end_date = !empty($_POST['add_end']) ? date('Y-m-d', strtotime($_POST['add_end'])) . " 23:59:59" : "0000-00-00 00:00:00";
            $rules = $_POST['rules'];
            $new_rules = array();
            foreach ($rules as $key => $rule) {
                foreach ($rule as $k => $r) {
                    $new_rules[$k][$key] = $r;
                }
            }
            foreach ($new_rules as $key => $rule) {
                if ('' == $rule['value']) {
                    unset($new_rules[$key]);
                }
            }
            $new_coupon = new WPSC_Coupon(array('coupon_code' => $coupon_code, 'value' => $discount, 'is-percentage' => $discount_type, 'use-once' => $use_once, 'is-used' => 0, 'active' => $is_active, 'every_product' => $every_product, 'start' => $start_date, 'expiry' => $end_date, 'condition' => $new_rules));
            $insert = $new_coupon->save();
            if ($insert) {
                echo '<div class="updated"><p>' . __('The coupon has been added.', 'wp-e-commerce') . '</p></div>';
            }
        }
        // update an existing coupon
        if (isset($_POST['is_edit_coupon']) && $_POST['is_edit_coupon'] == 'true' && !isset($_POST['delete_condition']) && !isset($_POST['submit_condition'])) {
            check_admin_referer('wpsc_coupon', 'wpsc-coupon-edit');
            if (!function_exists('wpsc_is_store_admin') || !wpsc_is_store_admin()) {
                wp_die(__('Permission denied', 'wpsc'));
            }
            $rules = isset($_POST['rules']) ? $_POST['rules'] : array();
            $new_rules = array();
            foreach ($rules as $key => $rule) {
                foreach ($rule as $k => $r) {
                    $new_rules[$k][$key] = $r;
                }
            }
            foreach ($new_rules as $key => $rule) {
                if ('' == $rule['value']) {
                    unset($new_rules[$key]);
                }
            }
            $update_coupon = new WPSC_Coupon($_POST['coupon_id']);
            $update_coupon->set(array('coupon_code' => $_POST['edit_coupon_code'], 'value' => $_POST['edit_coupon_amount'], 'is-percentage' => $_POST['edit_discount_type'], 'use-once' => $_POST['edit_coupon_use_once'], 'is-used' => $_POST['edit_coupon_is_used'], 'active' => $_POST['edit_coupon_active'], 'every_product' => $_POST['edit_coupon_every_product'], 'start' => !empty($_POST['edit_coupon_start']) ? get_gmt_from_date($_POST['edit_coupon_start'] . ' 00:00:00') : "0000-00-00 00:00:00", 'expiry' => !empty($_POST['edit_coupon_end']) ? get_gmt_from_date($_POST['edit_coupon_end'] . ' 23:59:59') : "0000-00-00 00:00:00", 'condition' => $new_rules));
            $update = $update_coupon->save();
            if ($update) {
                echo '<div class="updated"><p>' . __('The coupon has been updated.', 'wp-e-commerce') . '</p></div>';
            }
        }
    }
    /**
     * Load the selected view
     */
    if (isset($_GET['wpsc-action']) && $_GET['wpsc-action'] == 'add_coupon') {
        // load the coupon add screen
        include dirname(__FILE__) . '/display-coupon-add.php';
    } elseif (isset($_GET['wpsc-action']) && $_GET['wpsc-action'] == 'edit_coupon') {
        // load the coupon add screen
        include dirname(__FILE__) . '/display-coupon-edit.php';
    } else {
        require_once WPSC_FILE_PATH . '/wpsc-admin/includes/coupon-list-table-class.php';
        $coupons_table = new WPSC_Coupons_List_Table();
        $coupons_table->prepare_items();
        ?>
		<div class="wrap">
			<h2><?php 
        _e('Coupons', 'wp-e-commerce');
        ?>
<a href="<?php 
        echo esc_url(add_query_arg('wpsc-action', 'add_coupon'));
        ?>
" class="add-new-h2"><?php 
        _e('Add Coupon', 'wp-e-commerce');
        ?>
</a></h2>
			<?php 
        do_action('wpsc_coupons_page_top');
        ?>
			<form id="wpsc-coupons-filter" method="get" action="<?php 
        echo admin_url('edit.php?post_type=wpsc-product&page=wpsc-edit-coupons');
        ?>
">

				<input type="hidden" name="post_type" value="wpsc-product" />
				<input type="hidden" name="page" value="wpsc-edit-coupons" />

				<?php 
        $coupons_table->views();
        ?>
				<?php 
        $coupons_table->display();
        ?>
			</form>
			<?php 
        do_action('wpsc_coupons_page_bottom');
        ?>
		</div>
		<?php 
    }
    // end view check
}
Beispiel #9
0
 /**
  * Deletes a coupon from the database.
  *
  * @access  public
  * @since   4.0
  *
  * @return  boolean
  */
 public function delete()
 {
     global $wpdb;
     if (!function_exists('wpsc_is_store_admin') || !wpsc_is_store_admin()) {
         return;
     }
     do_action('wpsc_coupon_before_delete', $this->id);
     $this->delete_cache();
     $deleted = $wpdb->delete(WPSC_TABLE_COUPON_CODES, array('id' => $this->id), array($this->get_column_format($this->id)));
     do_action('wpsc_coupon_delete', $this->id);
     return $deleted;
 }
 /**
  * Deletes a log from the database.
  *
  * @access  public
  * @since   3.8.9
  *
  * @uses  $wpdb                              Global database instance.
  * @uses  wpsc_is_store_admin()              Check user has admin capabilities.
  * @uses  WPSC_Purchase_Log::delete_cache()  Delete purchaselog cache.
  * @uses  WPSC_Claimed_Stock                 Claimed Stock class.
  *
  * @param   string   $log_id   ID of the log.
  * @return  boolean            Deleted successfully.
  */
 public function delete($log_id = false)
 {
     global $wpdb;
     if (!(isset($this) && get_class($this) == __CLASS__)) {
         _wpsc_doing_it_wrong('WPSC_Purchase_Log::delete', __('WPSC_Purchase_Log::delete() is no longer a static method and should not be called statically.', 'wpsc'), '3.9.0');
     }
     if (false !== $log_id) {
         _wpsc_deprecated_argument(__FUNCTION__, '3.9.0', 'The $log_id param is not used. You must first create an instance of WPSC_Purchase_Log before calling this method.');
     }
     if (!wpsc_is_store_admin()) {
         return false;
     }
     $log_id = $this->get('id');
     if ($log_id > 0) {
         do_action('wpsc_purchase_log_before_delete', $log_id);
         self::delete_cache($log_id);
         // Delete claimed stock
         $purchlog_status = $wpdb->get_var($wpdb->prepare("SELECT `processed` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`= %d", $log_id));
         if ($purchlog_status == WPSC_Purchase_Log::CLOSED_ORDER || $purchlog_status == WPSC_Purchase_Log::INCOMPLETE_SALE) {
             $claimed_query = new WPSC_Claimed_Stock(array('cart_id' => $log_id, 'cart_submitted' => 1));
             $claimed_query->clear_claimed_stock(0);
         }
         // Delete cart content, submitted data, then purchase log
         $wpdb->query($wpdb->prepare("DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = %d", $log_id));
         $wpdb->query($wpdb->prepare("DELETE FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` IN (%d)", $log_id));
         $wpdb->query($wpdb->prepare("DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id` = %d LIMIT 1", $log_id));
         do_action('wpsc_purchase_log_delete', $log_id);
         return true;
     }
     return false;
 }
Beispiel #11
0
/**
 * @todo docs
 *
 * @uses $wpdb              WordPress database object for queries
 * @uses $wp_rewrite        Global variable instance of the WP_Rewrite Class
 * @uses wp_get_referer()   Retrieve referer from '_wp_http_referer' or HTTP referer.
 * @uses add_query_arg()    Retrieve a modified URL query string.
 * @uses wp_redirect()      Redirects to string given as argument
 */
function wpsc_clean_categories()
{
    if (!wpsc_is_store_admin()) {
        return;
    }
    global $wpdb, $wp_rewrite;
    $sql_query = "SELECT `id`, `name`, `active` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "`";
    $sql_data = $wpdb->get_results($sql_query, ARRAY_A);
    foreach ((array) $sql_data as $datarow) {
        if ($datarow['active'] == 1) {
            $tidied_name = strtolower(trim($datarow['name']));
            $url_name = sanitize_title($tidied_name);
            $similar_names = $wpdb->get_row($wpdb->prepare("SELECT COUNT(*) AS `count`, MAX(REPLACE(`nice-name`, '%s', '')) AS `max_number` FROM `" . WPSC_TABLE_PRODUCT_CATEGORIES . "` WHERE `nice-name` REGEXP '^( " . esc_sql($url_name) . " ){1}(\\d)*\$' AND `id` NOT IN (%d) ", $url_name, $datarow['id']), ARRAY_A);
            $extension_number = '';
            if ($similar_names['count'] > 0) {
                $extension_number = (int) $similar_names['max_number'] + 2;
            }
            $url_name .= $extension_number;
            $wpdb->update(WPSC_TABLE_PRODUCT_CATEGORIES, array('nice-name' => $url_name), array('id' => $datarow['id']), '%s', '%d');
        } else {
            if ($datarow['active'] == 0) {
                $wpdb->update(WPSC_TABLE_PRODUCT_CATEGORIES, array('nice-name' => ''), array('id' => $datarow['id']), '%s', '%d');
            }
        }
    }
    $wp_rewrite->flush_rules();
    $sendback = wp_get_referer();
    if (isset($updated)) {
        $sendback = add_query_arg('updated', $updated, $sendback);
    }
    if (isset($_SESSION['wpsc_settings_curr_page'])) {
        $sendback = add_query_arg('tab', $_SESSION['wpsc_settings_curr_page'], $sendback);
    }
    wp_redirect(esc_url_raw($sendback));
    exit;
}
Beispiel #12
0
/**
 * Delete a coupon
 *
 * @since 3.8
 */
function wpsc_delete_coupon()
{
    global $wpdb;
    check_admin_referer('delete-coupon');
    if (!function_exists('wpsc_is_store_admin') || !wpsc_is_store_admin()) {
        return;
    }
    $deleted = 0;
    if (isset($_GET['delete_id'])) {
        $coupon = new WPSC_Coupon($_GET['delete_id']);
        $coupon->delete();
        $deleted = 1;
    }
    $sendback = wp_get_referer();
    if ($deleted) {
        $sendback = add_query_arg('deleted', $deleted, $sendback);
    }
    $sendback = remove_query_arg(array('deleteid', 'wpsc_admin_action'), $sendback);
    wp_redirect(esc_url_raw($sendback));
    exit;
}