Completed
Pull Request — master (#2165)
by Justin
05:08
created

WPSC_Purchase_Log_Page::__construct()   C

Complexity

Conditions 8
Paths 12

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 16
nc 12
nop 0
dl 0
loc 26
rs 5.3846
c 0
b 0
f 0
1
<?php
2
/**
3
 * WP eCommerce edit and view sales page functions
4
 *
5
 * These are the main WPSC sales page functions
6
 *
7
 * @package wp-e-commerce
8
 * @since 3.8.8
9
 */
10
11
class WPSC_Purchase_Log_Page {
12
	private $list_table;
13
	private $output;
14
	public $log_id = 0;
15
16
	/**
17
	 * WPSC_Purchase_Log
18
	 *
19
	 * @var WPSC_Purchase_Log object.
20
	 */
21
	public $log = null;
22
23
	/**
24
	 * Whether the purchase log can be modified.
25
	 *
26
	 * @var boolean
27
	 */
28
	protected $can_edit = false;
29
30
	public function __construct() {
31
		$controller = 'default';
32
		$controller_method = 'controller_default';
33
34
		// If individual purchase log, setup ID and action links.
35
		if ( isset( $_REQUEST['id'] ) && is_numeric( $_REQUEST['id'] ) ) {
36
			$this->log_id = (int) $_REQUEST['id'];
37
			$this->log = new WPSC_Purchase_Log( $this->log_id );
38
			$this->can_edit = $this->log->can_edit();
39
		}
40
41
		if ( isset( $_REQUEST['c'] ) && method_exists( $this, 'controller_' . $_REQUEST['c'] ) ) {
42
			$controller = $_REQUEST['c'];
43
			$controller_method = 'controller_' . $controller;
44
		} elseif ( isset( $_REQUEST['id'] ) && is_numeric( $_REQUEST['id'] ) ) {
45
			$controller = 'item_details';
46
			$controller_method = 'controller_item_details';
47
		}
48
49
		// Can only edit in the item details view.
50
		if ( 'controller_item_details' !== $controller_method ) {
51
			$this->can_edit = false;
52
		}
53
54
		$this->$controller_method();
55
	}
56
57
	private function needs_update() {
58
		global $wpdb;
59
60
		if ( get_option( '_wpsc_purchlogs_3.8_updated' ) )
61
			return false;
62
63
		$c = $wpdb->get_var( "SELECT COUNT(*) FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE plugin_version IN ('3.6', '3.7')" );
64
		if ( $c > 0 )
65
			return true;
66
67
		update_option( '_wpsc_purchlogs_3.8_updated', true );
68
		return false;
69
	}
70
71
	public function controller_upgrade_purchase_logs_3_7() {
72
		add_action( 'wpsc_display_purchase_logs_page', array( $this, 'display_upgrade_purchase_logs_3_7' ) );
73
	}
74
75
	private function purchase_logs_fix_options( $id ) {
76
		?>
77
		<select name='<?php echo $id; ?>'>
78
			<option value='-1'><?php echo esc_html_x( 'Select an Option', 'Dropdown default when called in uniquename dropdown', 'wp-e-commerce' ); ?></option>
79
			<option value='billingfirstname'><?php esc_html_e( 'Billing First Name', 'wp-e-commerce' ); ?></option>
80
			<option value='billinglastname'><?php esc_html_e( 'Billing Last Name', 'wp-e-commerce' ); ?></option>
81
			<option value='billingaddress'><?php esc_html_e( 'Billing Address', 'wp-e-commerce' ); ?></option>
82
			<option value='billingcity'><?php esc_html_e( 'Billing City', 'wp-e-commerce' ); ?></option>
83
			<option value='billingstate'><?php esc_html_e( 'Billing State', 'wp-e-commerce' ); ?></option>
84
			<option value='billingcountry'><?php esc_html_e( 'Billing Country', 'wp-e-commerce' ); ?></option>
85
			<option value='billingemail'><?php esc_html_e( 'Billing Email', 'wp-e-commerce' ); ?></option>
86
			<option value='billingphone'><?php esc_html_e( 'Billing Phone', 'wp-e-commerce' ); ?></option>
87
			<option value='billingpostcode'><?php esc_html_e( 'Billing Post Code', 'wp-e-commerce' ); ?></option>
88
			<option value='shippingfirstname'><?php esc_html_e( 'Shipping First Name', 'wp-e-commerce' ); ?></option>
89
			<option value='shippinglastname'><?php esc_html_e( 'Shipping Last Name', 'wp-e-commerce' ); ?></option>
90
			<option value='shippingaddress'><?php esc_html_e( 'Shipping Address', 'wp-e-commerce' ); ?></option>
91
			<option value='shippingcity'><?php esc_html_e( 'Shipping City', 'wp-e-commerce' ); ?></option>
92
			<option value='shippingstate'><?php esc_html_e( 'Shipping State', 'wp-e-commerce' ); ?></option>
93
			<option value='shippingcountry'><?php esc_html_e( 'Shipping Country', 'wp-e-commerce' ); ?></option>
94
			<option value='shippingpostcode'><?php esc_html_e( 'Shipping Post Code', 'wp-e-commerce' ); ?></option>
95
		</select>
96
		<?php
97
	}
98
99
	public function display_upgrade_purchase_logs_3_7() {
100
		global $wpdb;
101
		$numChanged = 0;
102
		$numQueries = 0;
103
		$purchlog =  "SELECT DISTINCT id FROM `".WPSC_TABLE_PURCHASE_LOGS."` LIMIT 1";
0 ignored issues
show
introduced by
Expected 1 space after "="; 2 found
Loading history...
104
		$id = $wpdb->get_var($purchlog);
105
		$usersql = "SELECT DISTINCT `".WPSC_TABLE_SUBMITTED_FORM_DATA."`.value, `".WPSC_TABLE_CHECKOUT_FORMS."`.* FROM `".WPSC_TABLE_CHECKOUT_FORMS."` LEFT JOIN `".WPSC_TABLE_SUBMITTED_FORM_DATA."` ON `".WPSC_TABLE_CHECKOUT_FORMS."`.id = `".WPSC_TABLE_SUBMITTED_FORM_DATA."`.`form_id` WHERE `".WPSC_TABLE_SUBMITTED_FORM_DATA."`.log_id=".$id." ORDER BY `".WPSC_TABLE_CHECKOUT_FORMS."`.`checkout_order`" ;
106
		$formfields = $wpdb->get_results($usersql);
107
108
		if(count($formfields) < 1){
109
			$usersql = "SELECT DISTINCT  `".WPSC_TABLE_CHECKOUT_FORMS."`.* FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `type` != 'heading'";
110
			$formfields = $wpdb->get_results($usersql);
111
		}
112
113
		if(isset($_POST)){
114
			foreach($_POST as $key=>$value){
115
				if($value != '-1'){
116
					$complete = $wpdb->update(
117
				 WPSC_TABLE_CHECKOUT_FORMS,
118
				 array(
119
				'unique_name' => $value
120
				 ),
121
				 array(
122
				'id' => $key
123
				  ),
124
				 '%s',
125
				 '%d'
126
				 );
127
				}
128
				$numChanged++;
129
				$numQueries ++;
130
			}
131
132
			$sql = "UPDATE `".WPSC_TABLE_CHECKOUT_FORMS."` SET `unique_name`='delivertoafriend' WHERE `name` = '2. Shipping details'";
133
			$wpdb->query($sql);
134
135
			add_option('wpsc_purchaselogs_fixed',true);
136
		}
137
138
		include( 'includes/purchase-logs-page/upgrade.php' );
139
	}
140
141
	public function display_upgrade_purchase_logs_3_8() {
142
		?>
143
			<div class="wrap">
144
				<h2><?php echo esc_html( __('Sales', 'wp-e-commerce') ); ?> </h2>
145
				<div class="updated">
146
					<p><?php printf( __( 'Your purchase logs have been updated! <a href="%s">Click here</a> to return.' , 'wp-e-commerce' ), esc_url( remove_query_arg( 'c' ) ) ); ?></p>
147
				</div>
148
			</div>
149
		<?php
150
	}
151
152
	public function controller_upgrade_purchase_logs_3_8() {
153
		if ( $this->needs_update() ) {
154
			wpsc_update_purchase_logs();
155
		}
156
157
		add_action( 'wpsc_display_purchase_logs_page', array( $this, 'display_upgrade_purchase_logs_3_8' ) );
158
	}
159
160
	function purchase_logs_pagination() {
161
		global $wpdb, $purchlogitem;
162
		$prev_id = $this->log->get_previous_log_id();
163
		$next_id = $this->log->get_next_log_id();
164
		?>
165
		<span class='tablenav'><span class='tablenav-pages'><span class='pagination-links'>
166
			<?php if ( $prev_id ) : ?>
167
				<a href='<?php echo esc_url( $this->get_purchase_log_url( $prev_id ) ); ?>' class='prev-page'>&lsaquo; <?php _e( 'Previous', 'wp-e-commerce' ); ?></a>
168
			<?php endif; ?>
169
170
			<?php if ( $next_id ) : ?>
171
				<a href='<?php echo esc_url( $this->get_purchase_log_url( $next_id ) ); ?>' class='next-page'><?php _e( 'Next', 'wp-e-commerce' ); ?> &rsaquo;</a>
172
			<?php endif; ?>
173
		</span></span></span>
174
		<?php
175
	}
176
177
	function purchase_logs_checkout_fields(){
178
		global $purchlogitem;
179
180
		if ( ! empty( $purchlogitem->additional_fields ) ) {
181
		?>
182
			<div class="metabox-holder">
183
				<div id="custom_checkout_fields" class="postbox">
184
					<h3 class='hndle'><?php esc_html_e( 'Additional Checkout Fields' , 'wp-e-commerce' ); ?></h3>
185
					<div class='inside'>
186
						<?php
187
						foreach( (array) $purchlogitem->additional_fields as $value ) {
188
							$value['value'] = maybe_unserialize ( $value['value'] );
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
189
							if ( is_array( $value['value'] ) ) {
190
								?>
191
									<p><strong><?php echo $value['name']; ?> :</strong> <?php echo implode( stripslashes( $value['value'] ), ',' ); ?></p>
192
								<?php
193
							} else {
194
								$thevalue = esc_html( stripslashes( $value['value'] ));
195
								if ( empty( $thevalue ) ) {
196
									$thevalue = __( '<em>blank</em>', 'wp-e-commerce' );
197
								}
198
								?>
199
									<p><strong><?php echo $value['name']; ?> :</strong> <?php echo $thevalue; ?></p>
200
								<?php
201
							}
202
						}
203
						?>
204
					</div>
205
				</div>
206
			</div>
207
		<?php
208
		}
209
	}
210
211
	public function purchase_log_custom_fields(){
212
		if( wpsc_purchlogs_has_customfields() ){?>
213
			<div class='metabox-holder'>
214
				<div id='purchlogs_customfields' class='postbox'>
215
					<h3 class='hndle'><?php esc_html_e( 'Users Custom Fields' , 'wp-e-commerce' ); ?></h3>
216
					<div class='inside'>
217
						<?php $messages = wpsc_purchlogs_custommessages(); ?>
218
						<?php $files = wpsc_purchlogs_customfiles(); ?>
219
						<?php if(count($files) > 0){ ?>
220
							<h4><?php esc_html_e( 'Cart Items with Custom Files' , 'wp-e-commerce' ); ?>:</h4>
221
							<?php
222
							foreach($files as $file){
223
								echo $file;
224
							}
225
						}?>
226
						<?php if(count($messages) > 0){ ?>
227
							<h4><?php esc_html_e( 'Cart Items with Custom Messages' , 'wp-e-commerce' ); ?>:</h4>
228
							<?php
229
							foreach($messages as $message){
230
								echo esc_html( $message['title'] ) . ':<br />' . nl2br( esc_html( $message['message'] ) );
231
							}
232
						} ?>
233
					</div>
234
				</div>
235
			</div>
236
		<?php
237
		}
238
	}
239
240
	private function edit_contact_details_form() {
241
		$args = wpsc_get_customer_settings_form_args( $this->log->form_data() );
242
		$args['form_actions'][0]['class'] = 'button';
243
		$args['form_actions'][0]['title'] = __( 'Update', 'wp-e-commerce' );
244
		echo wpsc_get_form_output( $args );
245
	}
246
247
	private function purchase_log_cart_items() {
248
		while( wpsc_have_purchaselog_details() ) : wpsc_the_purchaselog_item();
249
			self::purchase_log_cart_item( $this->can_edit );
250
		endwhile;
251
	}
252
253
	public static function purchase_log_cart_item( $can_edit = false ) {
254
		?>
255
		<tr class="purchase-log-line-item" id="purchase-log-item-<?php echo wpsc_purchaselog_details_id(); ?>" data-id="<?php echo wpsc_purchaselog_details_id(); ?>" data-productid="<?php echo wpsc_purchaselog_product_id(); ?>">
256
			<td><?php echo wpsc_purchaselog_details_name(); ?></td> <!-- NAME! -->
257
			<td><?php echo wpsc_purchaselog_details_SKU(); ?></td> <!-- SKU! -->
258
			<td>
259
				<?php if ( $can_edit ) : ?>
260
					<input type="number" step="1" min="0" autocomplete="off" name="wpsc_item_qty" class="wpsc_item_qty" placeholder="0" value="<?php echo wpsc_purchaselog_details_quantity(); ?>" size="4" class="quantity">
261
				<?php else: ?>
262
					<?php echo wpsc_purchaselog_details_quantity(); ?>
263
				<?php endif; ?>
264
			</td> <!-- QUANTITY! -->
265
			<td>
266
		 <?php
267
		echo wpsc_currency_display( wpsc_purchaselog_details_price() );
268
		do_action( 'wpsc_additional_sales_amount_info', wpsc_purchaselog_details_id() );
269
		 ?>
270
	 </td> <!-- PRICE! -->
271
			<td><?php echo wpsc_currency_display( wpsc_purchaselog_details_shipping() ); ?></td> <!-- SHIPPING! -->
272
			<?php if( wpec_display_product_tax() ): ?>
273
				<td><?php echo wpsc_currency_display( wpsc_purchaselog_details_tax() ); ?></td> <!-- TAX! -->
274
			<?php endif; ?>
275
			<!-- <td><?php echo wpsc_currency_display( wpsc_purchaselog_details_discount() ); ?></td> --> <!-- DISCOUNT! -->
276
			<td class="amount"><?php echo wpsc_currency_display( wpsc_purchaselog_details_total() ); ?></td> <!-- TOTAL! -->
277
			<?php if ( $can_edit ) : ?>
278
				<td class="remove">
279
					<div class="wpsc-remove-row">
280
						<button type="button" class="wpsc-remove-item-button"><span style="color:#a00;" class="dashicons dashicons-dismiss"></span> <?php esc_html_e( 'Remove Item', 'wp-e-commerce' ); ?></button>
281
					</div>
282
				</td> <!-- REMOVE! -->
283
			<?php endif; ?>
284
		</tr>
285
		<?php
286
		do_action( 'wpsc_additional_sales_item_info', wpsc_purchaselog_details_id() );
287
	}
288
289
	public function controller_item_details() {
290
		if (
291
			! isset( $_REQUEST['id'] )
292
			|| ( isset( $_REQUEST['id'] ) && ! is_numeric( $_REQUEST['id'] ) )
293
			|| ! $this->log->exists()
294
		) {
295
			wp_die( __( 'Invalid sales log ID', 'wp-e-commerce'  ) );
296
		}
297
298
		if ( isset( $_POST['_wp_nonce'] ) && wp_verify_nonce( $_POST['_wp_nonce'], 'wpsc-customer-settings-form' ) ) {
299
			self::maybe_update_contact_details_for_log( $this->log );
300
		}
301
302
		$this->log->init_items();
303
304
		$columns = array(
305
			'title'    => __( 'Name', 'wp-e-commerce' ),
306
			'sku'      => __( 'SKU', 'wp-e-commerce' ),
307
			'quantity' => __( 'Quantity','wp-e-commerce' ),
308
			'price'    => __( 'Price', 'wp-e-commerce' ),
309
			'shipping' => __( 'Item Shipping', 'wp-e-commerce'),
310
		);
311
312
		if ( wpec_display_product_tax() ) {
313
			$columns['tax'] = __( 'Item Tax', 'wp-e-commerce' );
314
		}
315
316
		$columns['total'] = __( 'Item Total','wp-e-commerce' );
317
318
		if ( $this->can_edit ) {
319
			$columns['remove'] = '';
320
321
			$this->include_te_v2_resources();
322
			$this->enqueue_te_v2_resources();
323
		}
324
325
		add_filter( 'admin_title', array( $this, 'doc_title' ), 10, 2 );
326
327
		register_column_headers( 'wpsc_purchase_log_item_details', $columns );
328
329
		add_action( 'wpsc_display_purchase_logs_page', array( $this, 'display_purchase_log' ) );
330
		add_action( 'wpsc_purchlogitem_metabox_start', array( $this, 'purchase_log_custom_fields' ) );
331
	}
332
333
	public static function maybe_update_contact_details_for_log( WPSC_Purchase_Log $log ) {
334
		if ( isset( $_POST['wpsc_checkout_details'] ) && is_array( $_POST['wpsc_checkout_details'] ) ) {
335
			WPSC_Checkout_Form_Data::save_form(
336
				$log,
337
				WPSC_Checkout_Form::get()->get_fields(),
338
				array_map( 'sanitize_text_field', $_POST['wpsc_checkout_details'] ),
339
				false
340
			);
341
		}
342
	}
343
344
	public function include_te_v2_resources() {
345
		if ( ! defined( 'WPSC_TE_V2_CLASSES_PATH' ) ) {
346
			require_once WPSC_FILE_PATH . '/wpsc-components/theme-engine-v2/core.php';
347
			_wpsc_te_v2_includes();
348
		}
349
350
		require_once( WPSC_TE_V2_CLASSES_PATH . '/message-collection.php' );
351
		require_once( WPSC_TE_V2_HELPERS_PATH . '/message-collection.php' );
352
		require_once( WPSC_TE_V2_HELPERS_PATH . '/template-tags/form.php' );
353
	}
354
355
	public function enqueue_te_v2_resources() {
356
		_wpsc_te2_register_styles();
357
		wp_enqueue_style( 'wpsc-common' );
358
359
		$engine     = WPSC_Template_Engine::get_instance();
360
		$scripts    = $engine->get_core_scripts_data();
361
		$to_enqueue = array(
362
			'wpsc-select-autocomplete',
363
			'wpsc-country-region',
364
			'wpsc-copy-billing-info'
365
		);
366
367
		foreach ( $to_enqueue as $handle ) {
368
			wp_register_script(
369
				$handle,
370
				WPSC_TE_V2_URL . '/theming/assets/' . $scripts[ $handle ]['path'],
371
				$scripts[ $handle ]['dependencies'],
372
				$scripts[ $handle ]['version'],
373
				true
374
			);
375
			wpsc_enqueue_script( $handle );
376
		}
377
378
		wp_localize_script( 'wpsc-copy-billing-info', 'WPSC', array(
379
			'is_admin' => true,
380
		) );
381
382
		_wpsc_action_enqueue_shipping_billing_scripts();
383
384
		foreach ( $engine->get_queued_scripts() as $handle => $data ) {
385
			_wpsc_enqueue_and_localize_script( $handle, $data );
386
		}
387
	}
388
389
	public function doc_title( $admin_title, $title ) {
390
		/* translators: #%d represents the sales log id. */
391
		$this_title = sprintf( esc_html__( 'Sales Log #%d', 'wp-e-commerce' ), $this->log_id );
392
		$admin_title = str_replace( $title, $this_title, $admin_title );
393
394
		return $admin_title;
395
	}
396
397
	public function controller_packing_slip() {
398
		if ( ! isset( $_REQUEST['id'] ) || ( isset( $_REQUEST['id'] ) && ! is_numeric( $_REQUEST['id'] ) ) ) {
399
			wp_die( __( 'Invalid sales log ID', 'wp-e-commerce'  ) );
400
		}
401
402
		$this->log->init_items();
403
404
		$columns = array(
405
			'title'    => __( 'Item Name', 'wp-e-commerce' ),
406
			'sku'      => __( 'SKU', 'wp-e-commerce' ),
407
			'quantity' => __( 'Quantity', 'wp-e-commerce' ),
408
			'price'    => __( 'Price', 'wp-e-commerce' ),
409
			'shipping' => __( 'Item Shipping','wp-e-commerce' ),
410
		);
411
412
		if ( wpec_display_product_tax() ) {
413
			$columns['tax'] = __( 'Item Tax', 'wp-e-commerce' );
414
		}
415
416
		$columns['total'] = __( 'Item Total','wp-e-commerce' );
417
418
		$cols = count( $columns ) - 2;
419
420
		register_column_headers( 'wpsc_purchase_log_item_details', $columns );
421
422
		if ( file_exists( get_stylesheet_directory() . '/wpsc-packing-slip.php' ) ) {
423
			$packing_slip_file = get_stylesheet_directory() . '/wpsc-packing-slip.php';
424
		} else {
425
			$packing_slip_file = 'includes/purchase-logs-page/packing-slip.php';
426
		}
427
428
		$packing_slip_file = apply_filters( 'wpsc_packing_packing_slip_path', $packing_slip_file );
429
430
		include( $packing_slip_file );
431
432
		exit;
433
	}
434
435
	public function controller_default() {
436
		// Create an instance of our package class...
437
		$this->list_table = new WPSC_Purchase_Log_List_Table();
438
		$this->process_bulk_action();
439
		$this->list_table->prepare_items();
440
		add_action( 'wpsc_display_purchase_logs_page', array( $this, 'display_list_table' ) );
441
	}
442
443
	public function display_purchase_log() {
444
		$cols = 4;
445
		if ( wpec_display_product_tax() ) {
446
			$cols++;
447
		}
448
449
		if ( $this->can_edit ) {
450
			$cols++;
451
		}
452
453
		$receipt_sent = ! empty( $_GET['sent'] );
454
		$receipt_not_sent = isset( $_GET['sent'] ) && ! $_GET['sent'];
455
		include( 'includes/purchase-logs-page/item-details.php' );
456
457
		global $wp_scripts;
458
459
		wp_enqueue_script( 'wp-backbone' );
460
461
		if ( isset( $wp_scripts->registered['wp-e-commerce-purchase-logs'] ) ) {
462
			// JS needed for modal
463
			$wp_scripts->registered['wp-e-commerce-purchase-logs']->deps[] = 'wp-backbone';
464
		}
465
466
		add_action( 'admin_footer', 'find_posts_div' );
467
	}
468
469
	public function download_csv() {
470
		_wpsc_download_purchase_log_csv();
471
	}
472
473
	public function process_bulk_action() {
474
		global $wpdb;
475
		$current_action = $this->list_table->current_action();
476
477
		do_action( 'wpsc_sales_log_process_bulk_action', $current_action );
478
479
		if ( ! $current_action || ( 'download_csv' != $current_action && empty( $_REQUEST['post'] ) ) ) {
480
			if ( ! empty( $_REQUEST['_wp_http_referer'] ) ) {
481
				wp_redirect( esc_url_raw( remove_query_arg( array( '_wp_http_referer', '_wpnonce', 'action', 'action2' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) ) );
482
				exit;
483
			}
484
485
			unset( $_REQUEST['post'] );
486
			return;
487
		}
488
489
		if ( 'download_csv' == $current_action ) {
490
			$this->download_csv();
491
		}
492
493
		$sendback = remove_query_arg( array(
494
			'_wpnonce',
495
			'_wp_http_referer',
496
			'action',
497
			'action2',
498
			'confirm',
499
			'post',
500
			'last_paged'
501
		) );
502
503
		if ( 'delete' == $current_action ) {
504
505
			// delete action
506
			if ( empty( $_REQUEST['confirm'] ) ) {
507
				$this->list_table->disable_search_box();
508
				$this->list_table->disable_bulk_actions();
509
				$this->list_table->disable_sortable();
510
				$this->list_table->disable_month_filter();
511
				$this->list_table->disable_views();
512
				$this->list_table->set_per_page(0);
513
				add_action( 'wpsc_purchase_logs_list_table_before', array( $this, 'action_list_table_before' ) );
514
				return;
515
			} else {
516
				if ( empty( $_REQUEST['post'] ) )
517
					return;
518
519
				$ids = array_map( 'intval', $_REQUEST['post'] );
520
521
				foreach ( $ids as $id ) {
522
					$log = new WPSC_Purchase_Log( $id );
523
					$log->delete();
524
				}
525
526
				$sendback = add_query_arg( array(
527
					'paged'   => $_REQUEST['last_paged'],
528
					'deleted' => count( $_REQUEST['post'] ),
529
				), $sendback );
530
531
			}
532
		}
533
534
		// change status actions
535
		if ( is_numeric( $current_action ) && ! empty( $_REQUEST['post'] ) ) {
536
537
			foreach ( $_REQUEST['post'] as $id )
538
				wpsc_purchlog_edit_status( $id, $current_action );
539
540
			$sendback = add_query_arg( array(
541
				'updated' => count( $_REQUEST['post'] ),
542
			), $sendback );
543
		}
544
545
		wp_redirect( esc_url_raw( $sendback ) );
546
		exit;
547
	}
548
549
	public function action_list_table_before() {
550
		include( 'includes/purchase-logs-page/bulk-delete-confirm.php' );
551
	}
552
553
	public function display_list_table() {
554
		if ( ! empty( $this->output ) ) {
555
			echo $this->output;
556
			return;
557
		}
558
559
		include( 'includes/purchase-logs-page/list-table.php' );
560
	}
561
562
	private function get_purchase_log_url( $id ) {
563
		$location = add_query_arg( array(
564
			'page' => 'wpsc-purchase-logs',
565
			'c'    => 'item_details',
566
			'id'   => $id,
567
		), admin_url( 'index.php' ) );
568
569
		return esc_url( $location );
570
	}
571
572
}
573