Completed
Push — master ( ab284c...4fdc7c )
by Justin
07:07
created

init.php ➔ wpsc_purchase_log_csv()   F

Complexity

Conditions 23
Paths 2042

Size

Total Lines 147
Code Lines 100

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 23
eloc 100
c 1
b 0
f 0
nc 2042
nop 0
dl 0
loc 147
rs 2

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
function wpsc_ajax_sales_quarterly() {
3
4
	if ( ! wpsc_is_store_admin() ) {
5
		return;
6
	}
7
8
	$lastdate = sanitize_text_field( $_POST['add_start'] );
9
	$date = preg_split( '/-/', $lastdate );
10
	if ( !isset( $date[0] ) )
11
		$date[0] = 0;
12
	if ( !isset( $date[1] ) )
13
		$date[1] = 0;
14
	if ( !isset( $date[2] ) )
15
		$date[2] = 0;
16
	$lastquart = mktime( 0, 0, 0, $date[1], $date[2], $date[0] );
17
	if ( $lastquart != get_option( 'wpsc_last_quarter' ) ) {
18
		update_option( 'wpsc_last_date', $lastdate );
19
		update_option( 'wpsc_fourth_quart', $lastquart );
20
		$thirdquart = mktime( 0, 0, 0, $date[1] - 3, $date[2], $date[0] );
21
		update_option( 'wpsc_third_quart', $thirdquart );
22
		$secondquart = mktime( 0, 0, 0, $date[1] - 6, $date[2], $date[0] );
23
		update_option( 'wpsc_second_quart', $secondquart );
24
		$firstquart = mktime( 0, 0, 0, $date[1] - 9, $date[2], $date[0] );
25
		update_option( 'wpsc_first_quart', $firstquart );
26
		$finalquart = mktime( 0, 0, 0, $date[1], $date[2], $date[0] - 1 );
27
		update_option( 'wpsc_final_quart', $finalquart );
28
	}
29
}
30
31
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'wpsc_quarterly') )
32
	add_action( 'admin_init', 'wpsc_ajax_sales_quarterly' );
33
34
function wpsc_delete_file() {
35
	$product_id = absint( $_REQUEST['product_id'] );
36
	$file_name  = basename( $_REQUEST['file_name'] );
37
	check_admin_referer( 'delete_file_' . $file_name );
38
39
	_wpsc_delete_file( $product_id, $file_name );
40
41
	$sendback = wp_get_referer();
42
	wp_redirect( $sendback );
43
	exit;
44
}
45
46
47
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'delete_file') )
48
	add_action( 'admin_init', 'wpsc_delete_file' );
49
50
/**
51
 *  Function and action for publishing or unpublishing single products
52
 */
53
function wpsc_ajax_toggle_published() {
54
	$product_id = absint( $_GET['product'] );
55
	check_admin_referer( 'toggle_publish_' . $product_id );
56
57
	$status = (wpsc_toggle_publish_status( $product_id )) ? ('true') : ('false');
58
	$sendback = add_query_arg( 'flipped', "1", wp_get_referer() );
59
	wp_redirect( esc_url_raw( $sendback ) );
60
	exit();
61
}
62
63
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'toggle_publish') )
64
	add_action( 'admin_init', 'wpsc_ajax_toggle_published' );
65
66
/**
67
 * Function and action for duplicating products,
68
 * Refactored for 3.8
69
 * Purposely not duplicating stick post status (logically, products are most often duplicated because they share many attributes, where products are generally 'featured' uniquely.)
70
 */
71
function wpsc_duplicate_product() {
72
73
	if ( ! wpsc_is_store_admin() ) {
74
		return;
75
	}
76
77
	// Get the original post
78
	$id = absint( $_GET['product'] );
79
	$post = get_post( $id );
80
81
	// Copy the post and insert it
82
	if ( isset( $post ) && $post != null ) {
83
84
		$duplicate = new WPSC_Duplicate_Product( $post->ID );
85
		$new_id = $duplicate->duplicate_product_process();
86
87
		$duplicated = true;
88
		$sendback = wp_get_referer();
89
		$sendback = add_query_arg( 'duplicated', (int) $duplicated, $sendback );
90
91
		wp_redirect( esc_url_raw( $sendback ) );
92
		exit();
93
	} else {
94
		wp_die( __( 'Sorry, for some reason, we couldn\'t duplicate this product because it could not be found in the database, check there for this ID: ', 'wp-e-commerce' ) . $id );
95
	}
96
}
97
98
if ( isset( $_GET['wpsc_admin_action'] ) && ( $_GET['wpsc_admin_action'] == 'duplicate_product' ) )
99
    add_action( 'admin_init', 'wpsc_duplicate_product' );
100
101
function wpsc_purchase_log_csv() {
102
103
	if ( ! wpsc_is_store_admin() ) {
104
		return;
105
	}
106
107
	global $wpdb, $wpsc_gateways;
108
	get_currentuserinfo();
109
	$count = 0;
110
111
	if ( 'key' == $_REQUEST['rss_key'] ) {
112
		if ( isset( $_REQUEST['start_timestamp'] ) && isset( $_REQUEST['end_timestamp'] ) ) {
113
			$start_timestamp = $_REQUEST['start_timestamp'];
114
			$end_timestamp   = $_REQUEST['end_timestamp'];
115
			$start_end_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN '%d' AND '%d' ORDER BY `date` DESC";
116
			$start_end_sql = apply_filters( 'wpsc_purchase_log_start_end_csv', $start_end_sql );
117
			$data = $wpdb->get_results( $wpdb->prepare( $start_end_sql, $start_timestamp, $end_timestamp ), ARRAY_A );
118
			/* translators: %1$s is "start" date, %2$s is "to" date */
119
			$csv_name = _x( 'Purchase Log %1$s to %2$s.csv', 'exported purchase log csv file name', 'wp-e-commerce' );
120
			$csv_name = sprintf( $csv_name, date( "M-d-Y", $start_timestamp ), date( "M-d-Y", $end_timestamp ) );
121
		} elseif ( isset( $_REQUEST['m'] ) ) {
122
			$year = (int) substr( $_REQUEST['m'], 0, 4);
123
			$month = (int) substr( $_REQUEST['m'], -2 );
124
			$month_year_sql = "
125
				SELECT *
126
				FROM " . WPSC_TABLE_PURCHASE_LOGS . "
127
				WHERE YEAR(FROM_UNIXTIME(date)) = %d AND MONTH(FROM_UNIXTIME(date)) = %d
128
				ORDER BY `id` DESC
129
			";
130
			$month_year_sql = apply_filters( 'wpsc_purchase_log_month_year_csv', $month_year_sql );
131
			$data = $wpdb->get_results( $wpdb->prepare( $month_year_sql, $year, $month ), ARRAY_A );
132
			/* translators: %1$s is month, %2$s is year */
133
			$csv_name = _x( 'Purchase Log %1$s/%2$s.csv', 'exported purchase log csv file name', 'wp-e-commerce' );
134
			$csv_name = sprintf( $csv_name, $month, $year );
135
		} else {
136
			$sql = apply_filters( 'wpsc_purchase_log_month_year_csv', "SELECT * FROM " . WPSC_TABLE_PURCHASE_LOGS . " ORDER BY `id` DESC" );
137
			$data = $wpdb->get_results( $sql, ARRAY_A );
138
			$csv_name = _x( "All Purchase Logs.csv", 'exported purchase log csv file name', 'wp-e-commerce' );
139
		}
140
141
		$form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' AND `type` != 'heading' ORDER BY `checkout_order` DESC;";
142
		$form_data = $wpdb->get_results( $form_sql, ARRAY_A );
143
144
		$headers_array = array(
145
			_x( 'Purchase ID'   , 'purchase log csv headers', 'wp-e-commerce' ),
146
			_x( 'Purchase Total', 'purchase log csv headers', 'wp-e-commerce' ),
147
		);
148
		$headers2_array = array(
149
			_x( 'Payment Gateway', 'purchase log csv headers', 'wp-e-commerce' ),
150
			_x( 'Payment Status' , 'purchase log csv headers', 'wp-e-commerce' ),
151
			_x( 'Purchase Date'  , 'purchase log csv headers', 'wp-e-commerce' ),
152
		);
153
		$form_headers_array = array();
154
155
		$output = '';
156
157
		foreach ( (array) $form_data as $form_field ) {
158
			if ( empty ( $form_field['unique_name'] ) ) {
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
159
				$form_headers_array[] = $form_field['name'];
160
			} else {
161
				$prefix = false === strstr( $form_field['unique_name'], 'billing' ) ? _x( 'Shipping ', 'purchase log csv header field prefix', 'wp-e-commerce' ) : _x( 'Billing ', 'purchase log csv header field prefix', 'wp-e-commerce' );
162
				$form_headers_array[] = $prefix . $form_field['name'];
163
			}
164
		}
165
166
		foreach ( (array) $data as $purchase ) {
167
			$form_headers = '';
168
			$output .= "\"" . $purchase['id'] . "\","; //Purchase ID
169
			$output .= "\"" . $purchase['totalprice'] . "\","; //Purchase Total
170
			foreach ( (array) $form_data as $form_field ) {
171
				$collected_data_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = '" . $purchase['id'] . "' AND `form_id` = '" . $form_field['id'] . "' LIMIT 1";
172
				$collected_data = $wpdb->get_results( $collected_data_sql, ARRAY_A );
173
				$collected_data = $collected_data[0];
174
175
				if (  ( 'billingstate' == $form_field['unique_name'] || 'shippingstate' == $form_field['unique_name'] ) && is_numeric( $collected_data['value'] ) )
176
					$output .= "\"" . wpsc_get_state_by_id( $collected_data['value'], 'code' ) . "\","; // get form fields
177
				else
178
					$output .= "\"" . str_replace( array( "\r", "\r\n", "\n" ), ' ', $collected_data['value'] ) . "\","; // get form fields
179
			}
180
181
			if ( isset( $wpsc_gateways[$purchase['gateway']] ) && isset( $wpsc_gateways[$purchase['gateway']]['display_name'] ) )
182
				$output .= "\"" . $wpsc_gateways[$purchase['gateway']]['display_name'] . "\","; //get gateway name
183
			else
184
				$output .= "\"\",";
185
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
186
187
			$status_name = wpsc_find_purchlog_status_name( $purchase['processed'] );
188
189
			$output .= "\"" . $status_name . "\","; //get purchase status
190
			$output .= "\"" . date( apply_filters( 'wpsc_purchase_log_csv_date_format', 'jS M Y' ), $purchase['date'] ) . "\","; //date
191
192
			$cartsql = "SELECT `prodid`, `quantity`, `name` FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase['id'] . "";
193
			$cart = $wpdb->get_results( $cartsql, ARRAY_A );
194
195
			if ( $count < count( $cart ) )
196
			    $count = count( $cart );
197
198
			$items = count( $cart );
199
			$i     = 1;
200
201
			// Go through all products in cart and display quantity and sku
202
			foreach ( (array) $cart as $item ) {
203
				$skuvalue = get_product_meta( $item['prodid'], 'sku', true );
204
				if( empty( $skuvalue ) )
205
				    $skuvalue = __( 'N/A', 'wp-e-commerce' );
206
				$output .= "\"" . $item['quantity'] . "\",";
207
				$output .= "\"" . str_replace( '"', '\"', $item['name'] ) . "\",";
208
209
				if ( $items <= 1 )
210
					$output .= "\"" . $skuvalue . "\"" ;
211
				elseif ( $items > 1 && $i != $items  )
212
					$output .= "\"" . $skuvalue . "\"," ;
213
				else
214
					$output .= "\"" . $skuvalue . "\"" ;
215
216
				$i++;
217
			}
218
219
			$output .= "\n"; // terminates the row/line in the CSV file
220
		}
221
		// Get the most number of products and create a header for them
222
		$headers3 = array();
223
		for( $i = 0; $i < $count; $i++ ){
224
			$headers3[] = _x( 'Quantity', 'purchase log csv headers', 'wp-e-commerce' );
225
			$headers3[] = _x( 'Product Name', 'purchase log csv headers', 'wp-e-commerce' );
226
			$headers3[] = _x( 'SKU', 'purchase log csv headers', 'wp-e-commerce' );
227
		}
228
229
		$headers      = '"' . implode( '","', $headers_array ) . '",';
230
		$form_headers = '"' . implode( '","', $form_headers_array ) . '",';
231
		$headers2     = '"' . implode( '","', $headers2_array ) . '",';
232
		$headers3     = '"' . implode( '","', $headers3 ) . '"';
233
234
		$headers      = apply_filters( 'wpsc_purchase_log_csv_headers', $headers . $form_headers . $headers2 . $headers3, $data, $form_data );
235
		$output       = apply_filters( 'wpsc_purchase_log_csv_output' , $output, $data, $form_data );
236
237
		/**
238
		 * Fires when the WPSC purchase log is exported as a CSV
239
		 */
240
		do_action( 'wpsc_purchase_log_csv' );
241
242
		header( 'Content-Type: text/csv' );
243
		header( 'Content-Disposition: inline; filename="' . $csv_name . '"' );
244
		echo $headers . "\n". $output;
245
		exit;
246
	}
247
}
248
249
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'wpsc_downloadcsv') ) {
250
	add_action( 'admin_init', 'wpsc_purchase_log_csv' );
251
}
252
253
if ( isset( $_GET['purchase_log_csv'] ) && ( 'true' == $_GET['purchase_log_csv'] ) )
254
	add_action( 'admin_init', 'wpsc_purchase_log_csv' );
255
256
function wpsc_admin_sale_rss() {
257
258
	if ( ! wpsc_is_store_admin() ) {
259
		return;
260
	}
261
262
	global $wpdb;
263
	if ( ($_GET['rss'] == "true") && ($_GET['rss_key'] == 'key') && ($_GET['action'] == "purchase_log") ) {
264
		$sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date`!='' ORDER BY `date` DESC";
265
		$purchase_log = $wpdb->get_results( $sql, ARRAY_A );
266
		header( "Content-Type: application/xml; charset=UTF-8" );
267
		header( 'Content-Disposition: inline; filename="WP_E-Commerce_Purchase_Log.rss"' );
268
		$output = '';
269
		$output .= "<?xml version='1.0'?>\n\r";
270
		$output .= "<rss version='2.0'>\n\r";
271
		$output .= "  <channel>\n\r";
272
		$output .= "    <title>" . _x( 'WP eCommerce Product Log', 'admin rss product feed', 'wp-e-commerce' ) . "</title>\n\r";
273
		$output .= "    <link>" . admin_url( 'admin.php?page=' . WPSC_DIR_NAME . '/display-log.php' ) . "</link>\n\r";
274
		$output .= "    <description>" . _x( 'This is the WP eCommerce Product Log RSS feed', 'admin rss product feed', 'wp-e-commerce' ) . "</description>\n\r";
275
		$output .= "    <generator>" . _x( 'WP eCommerce Plugin', 'admin rss product feed', 'wp-e-commerce' ) . "</generator>\n\r";
276
277
		foreach ( (array)$purchase_log as $purchase ) {
278
			$purchase_link = admin_url( 'admin.php?page=' . WPSC_DIR_NAME . '/display-log.php' ) . "&amp;purchaseid=" . $purchase['id'];
279
			$purchase_title = _x( 'Purchase # %d', 'admin rss product feed', 'wp-e-commerce' );
280
			$purchase_title = sprintf( $purchase_title, $purchase['id'] );
281
			$output .= "    <item>\n\r";
282
			$output .= "      <title>{$purchase_title}</title>\n\r";
283
			$output .= "      <link>$purchase_link</link>\n\r";
284
			$output .= "      <description>" . _x( 'This is an entry in the purchase log', 'admin rss product feed', 'wp-e-commerce' ) . ".</description>\n\r";
285
			$output .= "      <pubDate>" . date( "r", $purchase['date'] ) . "</pubDate>\n\r";
286
			$output .= "      <guid>$purchase_link</guid>\n\r";
287
			$output .= "    </item>\n\r";
288
		}
289
		$output .= "  </channel>\n\r";
290
		$output .= "</rss>";
291
		echo $output;
292
		exit();
293
	}
294
}
295
296
if ( isset( $_GET['action'] ) && ( 'purchase_log' == $_GET['action'] ) ) {
297
	add_action( 'admin_init', 'wpsc_admin_sale_rss' );
298
}
299
300
/**
301
 * Do Purchase Log Actions
302
 *
303
 * All purchase log actions are capability and nonce checked before calling
304
 * the relevent 'wpsc_purchase_log_action-{wpsc_purchase_log_action}' hook.
305
 *
306
 * @since  3.9.0
307
 */
308
function wpsc_do_purchase_log_actions() {
309
310
	if ( ! wpsc_is_store_admin() ) {
311
		return;
312
	}
313
314
	if ( isset( $_GET['wpsc_purchase_log_action'] ) && isset( $_GET['id'] ) && isset( $_GET['_wpnonce'] ) ) {
315
		$wpsc_purchase_log_action = sanitize_key( $_GET['wpsc_purchase_log_action'] );
316
317
		if ( wp_verify_nonce( $_GET['_wpnonce'], 'wpsc_purchase_log_action_' . $wpsc_purchase_log_action ) ) {
318
319
			do_action( 'wpsc_purchase_log_action-' . $wpsc_purchase_log_action, absint( $_GET['id'] ) );
320
321
		}
322
	}
323
324
}
325
add_action( 'admin_init', 'wpsc_do_purchase_log_actions' );
326
327
/**
328
 * Handle clear downloads lock purchase log action
329
 *
330
 * The 'wpsc_purchase_log_action-downloads_lock' action hook which calls this function is nonce and capability checked
331
 * in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-downloads_lock' ).
332
 *
333
 * @since  3.9.0
334
 *
335
 * @param  int  $log_id  Purchase log ID.
336
 */
337
function wpsc_purchase_log_action_downloads_lock( $log_id ) {
338
339
	wpsc_purchlog_clear_download_items( $log_id );
340
341
	// Redirect back to purchase logs list
342
	$sendback = wp_get_referer();
343
	$sendback = esc_url_raw( add_query_arg( 'cleared', 1, $sendback ) );
344
	wp_redirect( $sendback );
345
	exit();
346
347
}
348
add_action( 'wpsc_purchase_log_action-downloads_lock', 'wpsc_purchase_log_action_downloads_lock' );
349
350
/**
351
 * Handle delete purchase log action
352
 *
353
 * The 'wpsc_purchase_log_action-delete' action hook which calls this function is nonce and capability checked
354
 * in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-delete' ).
355
 *
356
 * @since  3.9.0
357
 *
358
 * @param  int  $log_id  Purchase log ID.
359
 */
360
function wpsc_purchase_log_action_delete( $log_id ) {
361
362
	$log = new WPSC_Purchase_Log( $log_id );
363
	$deleted = $log->delete();
364
365
	// Redirect back to purchase logs list
366
	$sendback = wp_get_referer();
367
	$sendback = remove_query_arg( array( 'c', 'id' ), $sendback );
368
	$sendback = esc_url_raw( add_query_arg( 'deleted', absint( $deleted ), $sendback ) );
369
	wp_redirect( $sendback );
370
	exit();
371
372
}
373
add_action( 'wpsc_purchase_log_action-delete', 'wpsc_purchase_log_action_delete' );
374
375
/**
376
 * Handle email receipt purchase log action
377
 *
378
 * The 'wpsc_purchase_log_action-email_receipt' action hook which calls this function is nonce and capability checked
379
 * in wpsc_do_purchase_log_actions() before triggering do_action( 'wpsc_purchase_log_action-email_receipt' ).
380
 *
381
 * @since  3.9.0
382
 *
383
 * @param  int  $log_id  Purchase log ID.
384
 */
385
function wpsc_purchase_log_action_email_receipt( $log_id ) {
386
387
	$sent = wpsc_purchlog_resend_email( $log_id );
388
389
	// Redirect back to purchase logs list
390
	$sendback = wp_get_referer();
391
	$sendback = esc_url_raw( add_query_arg( 'sent', absint( $sent ), $sendback ) );
392
	wp_redirect( $sendback );
393
	exit();
394
395
}
396
add_action( 'wpsc_purchase_log_action-email_receipt', 'wpsc_purchase_log_action_email_receipt' );
397
398
/**
399
 * Resend Purchase Log Email
400
 *
401
 * @param   int|string  $log_id  Required. Purchase log ID (empty string is deprecated).
402
 * @return  boolean              Sent successfully.
403
 */
404
function wpsc_purchlog_resend_email( $log_id = '' ) {
405
406
	if ( ! wpsc_is_store_admin() ) {
407
		return;
408
	}
409
410
	global $wpdb;
411
412
	// Deprecate empty purchase log ID parameter.
413
	if ( $log_id == '' ) {
414
		_wpsc_doing_it_wrong( 'wpsc_purchlog_resend_email', __( '$log_id parameter requires a numeric purchase log ID.', 'wp-e-commerce' ), '3.9.0' );
415
416
		// Support redirect for legacy purposes for the moment
417
		$sendback = esc_url_raw( add_query_arg( 'sent', 0, wp_get_referer() ) );
418
		wp_redirect( $sendback );
419
		exit();
420
421
	}
422
423
	$log_id = absint( $log_id );
424
425
	if ( $log_id > 0 ) {
426
427
		$wpec_taxes_controller = new wpec_taxes_controller();
428
429
		if ( is_numeric( $log_id ) ) {
430
			$purchase_log = new WPSC_Purchase_Log( $log_id );
431
			return wpsc_send_customer_email( $purchase_log );
432
		}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
433
434
	}
435
436
	return false;
437
438
}
439
440
// Deprecate resending purchase log email receipt via URL query
441
if ( isset( $_REQUEST['email_buyer_id'] ) && is_numeric( $_REQUEST['email_buyer_id'] ) ) {
442
	_wpsc_doing_it_wrong( 'wpsc_purchlog_resend_email', __( 'Do not trigger resend purchase log email action via email_buyer_id URL query. Instead use the Purchase Log Action Links API.', 'wp-e-commerce' ), '3.9.0' );
443
}
444
445
/**
446
 * Clear Purchase Log Download Locks
447
 *
448
 * @param   string   $log_id  Required. Purchase log ID (empty string is deprecated).
449
 * @return  boolean
450
 */
451
function wpsc_purchlog_clear_download_items( $log_id = '' ) {
452
453
	if ( ! wpsc_is_store_admin() ) {
454
		return;
455
	}
456
457
	global $wpdb;
458
459
	// Deprecate empty purchase log ID parameter.
460
	if ( $log_id == '' ) {
461
		_wpsc_doing_it_wrong( 'wpsc_purchlog_clear_download_items', __( '$log_id parameter requires a numeric purchase log ID.', 'wp-e-commerce' ), '3.9.0' );
462
		return false;
463
	}
464
465
	$log_id = absint( $log_id );
466
467
	if ( $log_id > 0 ) {
468
469
		$downloadable_items = (array) $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `purchid` = %d", $log_id ), ARRAY_A );
470
471
		$wpdb->update( WPSC_TABLE_DOWNLOAD_STATUS, array( 'ip_number' => '' ), array( 'purchid' => $log_id ), '%s', '%d' );
472
473
		$email_form_field = $wpdb->get_var( "SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `checkout_order` ASC LIMIT 1" );
474
		$email_address = $wpdb->get_var( $wpdb->prepare( "SELECT `value` FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = '{$email_form_field}' LIMIT 1", $log_id ) );
475
476
		foreach ( $downloadable_items as $downloadable_item ) {
477
			$download_links .= add_query_arg( 'downloadid', $downloadable_item['uniqueid'], home_url() )  . "\n";
0 ignored issues
show
Bug introduced by
The variable $download_links does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
478
		}
479
480
		wp_mail( $email_address, __( 'The administrator has unlocked your file', 'wp-e-commerce' ), str_replace( "[download_links]", $download_links, __( 'Dear Customer, We are pleased to advise you that your order has been updated and your downloads are now active. Please download your purchase using the links provided below. [download_links] Thank you for your order.', 'wp-e-commerce' ) ), "From: " . get_option( 'return_email' )  );
481
482
		return true;
483
484
	}
485
486
	return false;
487
488
}
489
490
// Deprecate clearing purchase log download locks via URL query
491
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'clear_locks') ) {
492
	_wpsc_doing_it_wrong( 'wpsc_purchlog_clear_download_items', __( 'Do not trigger clear purchase log download locks action via wpsc_admin_action = clear_locks URL query. Instead use the Purchase Log Action Links API.', 'wp-e-commerce' ), '3.9.0' );
493
}
494
495
//bulk actions for purchase log
496
function wpsc_purchlog_bulk_modify() {
497
498
	if ( ! wpsc_is_store_admin() ) {
499
		return;
500
	}
501
502
	if ( $_POST['purchlog_multiple_status_change'] != -1 ) {
503
		if ( is_numeric( $_POST['purchlog_multiple_status_change'] ) && $_POST['purchlog_multiple_status_change'] != 'delete' ) {
504
			foreach ( (array)$_POST['purchlogids'] as $purchlogid ) {
505
				wpsc_purchlog_edit_status( $purchlogid, $_POST['purchlog_multiple_status_change'] );
506
				$updated++;
0 ignored issues
show
Bug introduced by
The variable $updated does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
507
			}
508
		} elseif ( $_POST['purchlog_multiple_status_change'] == 'delete' ) {
509
			foreach ( (array)$_POST['purchlogids'] as $purchlogid ) {
510
511
				$log = new WPSC_Purchase_Log( $purchlogid );
512
				$deleted_log = $log->delete();
513
				if ( $deleted_log ) {
514
					$deleted++;
0 ignored issues
show
Bug introduced by
The variable $deleted does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
515
				}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
516
517
			}
518
		}
519
	}
520
	$sendback = wp_get_referer();
521
	if ( isset( $updated ) ) {
522
		$sendback = add_query_arg( 'updated', $updated, $sendback );
523
	}
524
	if ( isset( $deleted ) ) {
525
		$sendback = add_query_arg( 'deleted', $deleted, $sendback );
526
	}
527
	if ( isset( $_POST['view_purchlogs_by'] ) ) {
528
		$sendback = add_query_arg( 'view_purchlogs_by', $_POST['view_purchlogs_by'], $sendback );
529
	}
530
	if ( isset( $_POST['view_purchlogs_by_status'] ) ) {
531
		$sendback = add_query_arg( 'view_purchlogs_by_status', $_POST['view_purchlogs_by_status'], $sendback );
532
	}
533
	wp_redirect( esc_url_raw( $sendback ) );
534
	exit();
535
}
536
537
if ( isset( $_REQUEST['wpsc_admin_action2'] ) && ($_REQUEST['wpsc_admin_action2'] == 'purchlog_bulk_modify') ) {
538
	add_action( 'admin_init', 'wpsc_purchlog_bulk_modify' );
539
}
540
541
/**
542
 * Update Purchase Log Notes
543
 *
544
 * @param  int     $purchlog_id     Purchase log ID.
545
 * @param  string  $purchlog_notes  Notes.
546
 */
547
function wpsc_purchlogs_update_notes( $purchlog_id = 0, $purchlog_notes = '' ) {
548
	if ( isset( $_POST['wpsc_purchlogs_update_notes_nonce'] ) && wp_verify_nonce( $_POST['wpsc_purchlogs_update_notes_nonce'], 'wpsc_purchlogs_update_notes' ) ) {
549
		if ( 0 == $purchlog_id && isset( $_POST['purchlog_id'] ) && '' == $purchlog_notes ) {
550
			$purchlog_id = absint( $_POST['purchlog_id'] );
551
			$purchlog_notes = stripslashes( $_POST['purchlog_notes'] );
552
		}
553
554
		if ( $purchlog_id > 0 ) {
555
			$purchase_log = new WPSC_Purchase_Log( $purchlog_id );
556
			$purchase_log->set( 'notes', $purchlog_notes );
557
			$purchase_log->save();
558
		}
559
	}
560
}
561
if ( isset( $_REQUEST['wpsc_admin_action'] ) && $_REQUEST['wpsc_admin_action'] == 'purchlogs_update_notes' ) {
562
	add_action( 'admin_init', 'wpsc_purchlogs_update_notes' );
563
}
564
565
/**
566
 * Delete a purchase log
567
 *
568
 * @deprecated  Use WPSC_Purchase_Log->delete() instead.
569
 *
570
 * @param   int|string  $purchlog_id  Required. Purchase log ID (empty string is deprecated).
571
 * @return  boolean                   Deleted successfully.
572
 */
573
function wpsc_delete_purchlog( $purchlog_id = '' ) {
574
575
	global $wpdb;
576
577
	// Deprecate empty purchase log ID parameter.
578
	if ( $purchlog_id == '' ) {
579
		_wpsc_doing_it_wrong( 'wpsc_delete_purchlog', __( '$purchlog_id parameter requires a numeric purchase log ID.', 'wp-e-commerce' ), '3.9.0' );
580
		return false;
581
	}
582
583
	$log = new WPSC_Purchase_Log( $purchlog_id );
584
585
	return $log->delete();
586
587
}
588
589
// Deprecate deleting purchase log via URL query
590
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'delete_purchlog' ) ) {
591
	_wpsc_doing_it_wrong( 'wpsc_delete_purchlog', __( 'Do not trigger delete purchase log action via wpsc_admin_action = delete_purchlog URL query. Instead use the Purchase Log Action Links API.', 'wp-e-commerce' ), '3.9.0' );
592
}
593
594
function _wpsc_action_flush_rewrite_rules() {
595
	flush_rewrite_rules( false );
596
}
597
598
function wpsc_update_option_product_category_hierarchical_url() {
599
	_wpsc_action_flush_rewrite_rules();
600
}
601
602
add_action( 'update_option_product_category_hierarchical_url', 'wpsc_update_option_product_category_hierarchical_url' );
603
604
function _wpsc_action_sanitize_option_grid_number_per_row( $value, $option ) {
605
	$value = (int) $value;
606
	if ( $value === 0 ) {
607
		add_settings_error( $option, 'invalid_grid_number_per_row', __( 'You just set the number of item per row for the grid view to 0. This means the column width will fall back to using whatever CSS you have for it. This could break your theme layout, so please make sure you have adjusted your theme\'s CSS accordingly.', 'wp-e-commerce' ) );
608
	}
609
610
	return $value;
611
}
612
add_filter( 'sanitize_option_grid_number_per_row', '_wpsc_action_sanitize_option_grid_number_per_row', 10, 2 );
613
614
/**
615
 * Automatically enable "Anyone can register" if registration before checkout is required.
616
 *
617
 * @since  3.8.9
618
 * @access private
619
 * @param  mixed $old_value Old value
620
 * @param  mixed $new_value New value
621
 */
622
function _wpsc_action_update_option_require_register( $old_value, $new_value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
623
	if ( $new_value == 1 && ! get_option( 'users_can_register' ) ) {
624
		update_option( 'users_can_register', 1 );
625
		$message = __( 'You wanted to require your customers to log in before checking out. However, the WordPress setting <a href="%s">"Anyone can register"</a> was disabled. WP eCommerce has enabled that setting for you automatically.', 'wp-e-commerce' );
626
		$message = sprintf( $message, admin_url( 'options-general.php' ) );
627
		add_settings_error( 'require_register', 'users_can_register_turned_on', $message, 'updated' );
628
	}
629
}
630
add_action( 'update_option_require_register', '_wpsc_action_update_option_require_register', 10, 2 );
631
632
/**
633
 * Automatically turn off "require registration before checkout" if "Anyone can register" is disabled.
634
 *
635
 * @since  3.8.9
636
 * @access private
637
 * @param  mixed $old_value Old value
638
 * @param  mixed $new_value New value
639
 */
640
function _wpsc_action_update_option_users_can_register( $old_value, $new_value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
641
	if ( ! $new_value && get_option( 'require_register' ) ) {
642
		update_option( 'require_register', 0 );
643
		$message = __( 'You just disabled the "Anyone can register" setting. As a result, the <a href="%s">"Require registration before checking out"</a> setting has been disabled.', 'wp-e-commerce' );
644
		$message = sprintf( $message, admin_url( 'options-general.php?page=wpsc-settings&tab=checkout' ) );
645
		add_settings_error( 'users_can_register', 'require_register_turned_off', $message, 'updated' );
646
	}
647
}
648
add_action( 'update_option_users_can_register', '_wpsc_action_update_option_users_can_register', 10, 2 );
649
650
/**
651
 * wpsc_update_page_urls gets the permalinks for products pages and stores them in the options for quick reference
652
 * @public
653
 *
654
 * @since 3.6
655
 * @param $auto (Boolean) true if coming from WordPress Permalink Page, false otherwise
656
 * @return nothing
657
 */
658
function wpsc_update_page_urls( $auto = false ) {
659
660
	if ( ! wpsc_is_store_admin() ) {
661
		return;
662
	}
663
664
	wpsc_update_permalink_slugs();
665
	wpsc_core_load_page_titles();
666
	wpsc_register_post_types();
667
668
	if ( ! $auto ) {
669
		$sendback = wp_get_referer();
670
		if ( isset( $updated ) )
0 ignored issues
show
Bug introduced by
The variable $updated seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
671
			$sendback = add_query_arg( 'updated', $updated, $sendback );
672
673
		if ( isset( $_SESSION['wpsc_settings_curr_page'] ) )
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
674
			$sendback = add_query_arg( 'tab', $_SESSION['wpsc_settings_curr_page'], $sendback );
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
675
676
		wp_redirect( esc_url_raw( $sendback ) );
677
		exit();
678
	}
679
}
680
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'update_page_urls') )
681
	add_action( 'admin_init', 'wpsc_update_page_urls' );
682
683
//change the regions tax settings
684
function wpsc_change_region_tax() {
685
686
	if ( ! wpsc_is_store_admin() ) {
687
		return;
688
	}
689
690
	global $wpdb;
691
	if ( is_array( $_POST['region_tax'] ) ) {
692
		foreach ( $_POST['region_tax'] as $region_id => $tax ) {
693
			if ( is_numeric( $region_id ) && is_numeric( $tax ) ) {
694
				$previous_tax = $wpdb->get_var( $wpdb->prepare( "SELECT `tax` FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `id` = %d LIMIT 1", $region_id ) );
695
				if ( $tax != $previous_tax ) {
696
					$wpdb->update(
697
						WPSC_TABLE_REGION_TAX,
698
						array(
699
						    'tax' => $tax
700
						),
701
						array(
702
						    'id' => $region_id
703
						),
704
						'%s',
705
						'%d'
706
					    );
707
					$changes_made = true;
708
				}
709
			}
710
		}
711
		$sendback = wp_get_referer();
712
		wp_redirect( $sendback );
713
	}
714
}
715
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'change_region_tax') )
716
	add_action( 'admin_init', 'wpsc_change_region_tax' );
717
718
function wpsc_product_files_existing() {
719
	//List all product_files, with checkboxes
720
721
	if ( ! wpsc_is_store_admin() ) {
722
		return;
723
	}
724
725
	$product_id = absint( $_GET["product_id"] );
726
	$file_list = wpsc_uploaded_files();
727
728
	$args = array(
729
		'post_type' => 'wpsc-product-file',
730
		'post_parent' => $product_id,
731
		'numberposts' => -1,
0 ignored issues
show
introduced by
Disabling pagination is prohibited in VIP context, do not set numberposts to -1 ever.
Loading history...
732
		'post_status' => 'all'
733
	);
734
	$attached_files = (array)get_posts( $args );
735
736
	$attached_files_by_file = array();
737
	foreach ( $attached_files as $key => $attached_file ) {
738
		$attached_files_by_file[$attached_file->post_title] = & $attached_files[$key];
739
	}
740
741
	$output = "<span class='admin_product_notes select_product_note '>" . esc_html__( 'Choose a downloadable file for this product:', 'wp-e-commerce' ) . "</span><br>";
742
	$output .= "<form method='post' class='product_upload'>";
743
	$output .= '<div class="ui-widget-content multiple-select select_product_file" style="width:100%">';
744
	$num = 0;
745
	foreach ( (array)$file_list as $file ) {
746
		$num++;
747
		$checked_curr_file = "";
748
		if ( isset( $attached_files_by_file[$file['display_filename']] ) ) {
749
			$checked_curr_file = "checked='checked'";
750
		}
751
752
		$output .= "<p " . ((($num % 2) > 0) ? '' : "class='alt'") . " id='select_product_file_row_$num'>\n";
753
		$output .= "  <input type='checkbox' name='select_product_file[]' value='" . $file['real_filename'] . "' id='select_product_file_$num' " . $checked_curr_file . " />\n";
754
		$output .= "  <label for='select_product_file_$num'>" . $file['display_filename'] . "</label>\n";
755
		$output .= "</p>\n";
756
	}
757
758
	$output .= "</div>";
759
	$output .= "<input type='hidden' id='hidden_id' value='$product_id' />";
760
	$output .= "<input data-nonce='" . _wpsc_create_ajax_nonce( 'upload_product_file' ) . "' type='submit' name='save' name='product_files_submit' class='button-primary prdfil' value='" . esc_html__( 'Save Product Files', 'wp-e-commerce' ) . "' />";
761
	$output .= "</form>";
762
	$output .= "<div class='" . ((is_numeric( $product_id )) ? "edit_" : "") . "select_product_handle'><div></div></div>";
763
	$output .= "<script type='text/javascript'>\n\r";
764
	$output .= "var select_min_height = " . (25 * 3) . ";\n\r";
765
	$output .= "var select_max_height = " . (25 * ($num + 1)) . ";\n\r";
766
	$output .= "</script>";
767
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
768
769
	echo $output;
770
}
771
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'product_files_existing') )
772
	add_action( 'admin_init', 'wpsc_product_files_existing' );
773
774
function wpsc_update_variations() {
775
	$product_id = absint( $_POST["product_id"] );
776
	$product_type_object = get_post_type_object('wpsc-product');
777
	if (!current_user_can($product_type_object->cap->edit_post, $product_id))
778
		return;
779
780
	//Setup postdata
781
	$post_data = array();
782
	$post_data['edit_var_val'] = isset( $_POST['edit_var_val'] ) ? $_POST["edit_var_val"] : '';
783
784
	//Add or delete variations
785
	wpsc_edit_product_variations( $product_id, $post_data );
786
}
787
788
if ( isset($_POST["edit_var_val"]) )
789
	add_action( 'admin_init', 'wpsc_update_variations', 50 );
790
791
function wpsc_delete_variation_set() {
792
	check_admin_referer( 'delete-variation' );
793
794
	if ( is_numeric( $_GET['deleteid'] ) ) {
795
		$variation_id = absint( $_GET['deleteid'] );
796
797
		$variation_set = get_term( $variation_id, 'wpsc-variation', ARRAY_A );
798
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
799
800
		$variations = get_terms( 'wpsc-variation', array(
801
					'hide_empty' => 0,
802
					'parent' => $variation_id
803
				) );
804
805
		foreach ( (array)$variations as $variation ) {
806
			$return_value = wp_delete_term( $variation->term_id, 'wpsc-variation' );
807
		}
808
809
		if ( !empty( $variation_set ) ) {
810
			$return_value = wp_delete_term( $variation_set['term_id'], 'wpsc-variation' );
811
		}
812
		$deleted = 1;
813
	}
814
815
	$sendback = wp_get_referer();
816
	if ( isset( $deleted ) ) {
817
		$sendback = add_query_arg( 'deleted', $deleted, $sendback );
818
	}
819
	$sendback = remove_query_arg( array(
820
				'deleteid',
821
				'variation_id'
822
					), $sendback );
823
824
	wp_redirect( esc_url_raw( $sendback ) );
825
	exit();
826
}
827
828
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-variation-set' == $_REQUEST['wpsc_admin_action'] ) )
829
	add_action( 'admin_init', 'wpsc_delete_variation_set' );
830
831
function wpsc_backup_theme() {
832
833
	if ( ! wpsc_is_store_admin() ) {
834
		return;
835
	}
836
837
	$wp_theme_path = get_stylesheet_directory();
838
	wpsc_recursive_copy( $wp_theme_path, WPSC_THEME_BACKUP_DIR );
839
	$_SESSION['wpsc_themes_backup'] = true;
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
840
	$sendback = wp_get_referer();
841
	wp_redirect( $sendback );
842
843
	exit();
844
}
845
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'backup_themes' ) )
846
	add_action( 'admin_init', 'wpsc_backup_theme' );
847
848
/**
849
 * Delete a coupon
850
 *
851
 * @since 3.8
852
 */
853
function wpsc_delete_coupon(){
854
855
	global $wpdb;
856
857
	check_admin_referer( 'delete-coupon' );
858
859
	$deleted = 0;
860
861
	if ( isset( $_GET['delete_id'] ) ) {
862
		$coupon = new WPSC_Coupon( $_GET['delete_id'] );
863
		$coupon->delete();
864
		$deleted = 1;
865
	}
866
867
	$sendback = wp_get_referer();
868
869
	if ( $deleted ) {
870
		$sendback = add_query_arg( 'deleted', $deleted, $sendback );
871
	}
872
873
	$sendback = remove_query_arg( array( 'deleteid', 'wpsc_admin_action' ), $sendback );
874
	wp_redirect( esc_url_raw( $sendback ) );
875
	exit();
876
877
}
878
879
// Delete Coupon
880
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-coupon' == $_REQUEST['wpsc_admin_action'] ) ) {
881
	add_action( 'admin_init', 'wpsc_delete_coupon' );
882
}
883
884
function _wpsc_action_update_option_base_country( $old_value, $new_value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
885
	global $wpdb;
886
	$region_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('%s')",  $new_value ) );
887
	if ( ! $region_count )
888
		update_option( 'base_region', '' );
889
}
890
add_action( 'update_option_base_country', '_wpsc_action_update_option_base_country', 10, 2 );
891