Completed
Push — master ( a85a3b...a9e055 )
by Justin
11:13
created

wpsc_purchaselogs::wpsc_purchaselogs()   C

Complexity

Conditions 9
Paths 12

Size

Total Lines 51
Code Lines 44

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 51
rs 6.2727
cc 9
eloc 44
nc 12
nop 0

How to fix   Long Method   

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
3
add_action( 'wpsc_core_included', 'wpsc_instantiate_purchaselogitem' );
4
5
global $wpsc_purchlog_statuses;
6
if (!isset($wpsc_purchlog_statuses) || !count($wpsc_purchlog_statuses))
7
   wpsc_core_load_purchase_log_statuses();
8
9
function wpsc_instantiate_purchaselogitem() {
10
   global $purchlogitem;
11
   if ( isset( $_REQUEST['purchaselog_id'] ) )
12
	  $purchlogitem = new wpsc_purchaselogs_items( (int)$_REQUEST['purchaselog_id'] );
13
14
}
15
16
function wpsc_display_purchlog_howtheyfoundus() {
17
   global $purchlogitem;
18
   return esc_attr( $purchlogitem->extrainfo->find_us );
19
}
20
21
function wpsc_display_purchlog_display_howtheyfoundus() {
22
   global $purchlogitem;
23
   if ( !empty( $purchlogitem->extrainfo->find_us ) )
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return !empty($purchlogitem->extrainfo->find_us);.
Loading history...
24
	  return true;
25
   else
26
	  return false;
27
}
28
29
function wpsc_check_uniquenames() {
30
   global $wpdb;
31
   $sql = 'SELECT COUNT(`id`) FROM `' . WPSC_TABLE_CHECKOUT_FORMS . '` WHERE unique_name != "" ';
32
   $check_unique_names = $wpdb->get_var( $sql );
33
   if ( $check_unique_names > 0 ) {
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return !($check_unique_names > 0);.
Loading history...
34
	  return false;
35
   } else {
36
	  return true;
37
   }
38
}
39
40
/** Does the purchaselog have tracking information
41
 * @return boolean
42
 */
43
function wpsc_purchlogs_has_tracking() {
44
	global $purchlogitem;
45
	if ( ! empty( $purchlogitem->extrainfo->track_id ) ) {
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return !empty($purchlogi...->extrainfo->track_id);.
Loading history...
46
		return true;
47
	} else {
48
		return false;
49
	}
50
}
51
52
/**
53
 * * @return string  current tracking id or or empty string if there isn't a tracking id
54
 */
55
function wpsc_purchlogitem_trackid() {
56
	global $purchlogitem;
57
	return esc_attr( empty( $purchlogitem->extrainfo->track_id ) ? '' : $purchlogitem->extrainfo->track_id );
58
}
59
60
/** Purchase shipping status
61
 * @return string shipping status or empty string
62
 */
63
function wpsc_purchlogitem_trackstatus() {
64
	global $wpsc_shipping_modules, $purchlogitem;
65
66
	$callable = array( $purchlogitem->extrainfo->shipping_method, 'getStatus' );
67
	$shipping_status_is_callable = is_callable( $callable );
68
69
	if ( $shipping_status_is_callable && ! empty( $purchlogitem->extrainfo->track_id ) ) {
70
		$status = $wpsc_shipping_modules [$purchlogitem->extrainfo->shipping_method]->getStatus( $purchlogitem->extrainfo->track_id );
71
	} else {
72
		$status = '';
73
	}
74
75
	return $status;
76
}
77
78
/** Tracking history for purchase
79
 * @return string tracking history or empty string
80
 */
81
function wpsc_purchlogitem_trackhistory() {
82
	global $purchlogitem;
83
84
	if ( ( 'nzpost' == $purchlogitem->extrainfo->shipping_method ) && ! empty( $purchlogitem->extrainfo->track_id ) ) {
85
86
		$output  = '<ul>';
87
		$outputs = array();
88
89
		foreach ( ( array ) $_SESSION ['wpsc_nzpost_parsed'] [0] ['children'] [0] ['children'] [1] ['children'] as $history ) {
0 ignored issues
show
introduced by
Cast statements must not contain whitespace; expected "(array)" but found "( array )"
Loading history...
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
90
			$outputs[] = '<li>' . $history ['children'] [0] ['tagData'] . ' : ' . $history ['children'] [1] ['tagData'] . ' </li>';
91
		}
92
93
		$outputs = array_reverse( $outputs );
94
		foreach ( $outputs as $o ) {
95
			$output .= $o;
96
		}
97
98
		$output .= '</ul>';
99
		return $output;
100
	} else {
101
		// TODO: If there isn't one already, we should add a tracking callback to the shipping API
102
		return '';
103
	}
104
}
105
106
107
/**
108
 * Weight of current or specified purchase
109
 *
110
 * @since 3.8.14
111
 *
112
 *
113
 * @param string $id
114
 * @return float $weight in '$out_unit' of shipment
115
 */
116
function wpsc_purchlogs_get_weight( $id = '', $out_unit = 'pound' ) {
117
	global $purchlogitem;
118
	$weight = 0.0;
119
	$items_count = 0;
120
121
	if ( empty( $id ) || ( ! empty( $purchlogitem ) &&  ( $id == $purchlogitem->purchlogid ) ) ) {
122
		$thepurchlogitem = $purchlogitem;
123
	} else {
124
		$thepurchlogitem = new wpsc_purchaselogs_items( $id );
125
	}
126
127
	/**
128
	 * Filter wpsc_purchlogs_before_get_weight
129
	 *
130
	 * Allow the weight to be overridden, can be used to persistantly save weight and recall it rather than recalculate
131
	 *
132
	 * @since 3.8.14
133
	 *
134
	 * @param  float  $weight, purchase calculation will not continue if value is returned
135
	 * @param  string weight unit to use for return value
136
	 * @param  object wpsc_purchaselogs_items purchase log item being used
137
	 * @param  int    purchase log item id
138
	 * @return float  $weight
139
	 */
140
	$weight_override = apply_filters( 'wpsc_purchlogs_before_get_weight', false, $out_unit, $thepurchlogitem, $thepurchlogitem->purchlogid );
141
	if ( $weight_override !== false ) {
142
		return $weight_override;
143
	}
144
145
	// if there isn't a purchase log item we are done
146
	if ( empty( $thepurchlogitem ) ) {
147
		return false;
148
	}
149
150
	foreach ( ( array ) $thepurchlogitem->allcartcontent as $cartitem ) {
0 ignored issues
show
introduced by
Cast statements must not contain whitespace; expected "(array)" but found "( array )"
Loading history...
151
		$product_meta = get_product_meta( $cartitem->prodid, 'product_metadata', true );
152
		if ( ! empty( $product_meta ['weight'] ) ) {
153
154
			$converted_weight = wpsc_convert_weight( $product_meta ['weight'], $product_meta['weight_unit'], $out_unit, true );
155
156
			$weight += $converted_weight * $cartitem->quantity;
157
			$items_count += $cartitem->quantity;
158
		}
159
	}
160
161
	/**
162
	 * Filter wpsc_purchlogs_get_weight
163
	 *
164
	 * Allow the weight to be overridden
165
	 *
166
	 * @since 3.8.14
167
	 *
168
	 * @param  float  $weight                 calculated cart weight
169
	 * @param  object wpsc_purchaselogs_items purchase log item being used
170
	 * @param  int    purchase log item id
171
	 * @param  int    $items_count            how many items are in the cart, useful for
172
	 *                                        cases where packaging weight changes as more items are
173
	 *                                        added
174
	 */
175
	$weight = apply_filters( 'wpsc_purchlogs_get_weight', $weight, $thepurchlogitem, $thepurchlogitem->purchlogid, $items_count );
176
177
	return $weight;
178
}
179
180
/**
181
 * Weight of current or specified purchase formatted as text with units
182
 *
183
 * @since 3.8.14
184
 *
185
 * @param string $id
186
 * @return string $weight in KG and lbs and ounces
187
 */
188
function wpsc_purchlogs_get_weight_text( $id = '' ) {
189
	global $purchlogitem;
190
191
	if ( empty( $id ) ) {
192
		$id = $purchlogitem->purchlogid;
193
	}
194
195
	$weight_in_pounds = wpsc_purchlogs_get_weight( $id, 'pound' );
196
197
	if ( $weight_in_pounds > 0 ) {
198
199
		$pound = floor( $weight_in_pounds );
200
		$ounce = round( ( $weight_in_pounds - $pound ) * 16 );
201
202
		$weight_in_kg = wpsc_purchlogs_get_weight( $id, 'kg' );
203
204
		$weight_string = number_format( $weight_in_kg , 2 ) .' ' .  __( 'KG' , 'wp-e-commerce' ) . ' / ' .  $pound . ' ' .  __( 'LB', 'wp-e-commerce' ) . ' ' . $ounce . ' ' . __( 'OZ', 'wp-e-commerce' );
205
206
	} else {
207
		$weight_string = '';
208
	}
209
210
	/**
211
	 * Filter wpsc_purchlogs_get_weight_text
212
	 *
213
	 * Format weight as text suitable to inform user of purchase shipping weight
214
	 *
215
	 * @since 3.8.14
216
	 *
217
	 * @param  string weight of purchase as text string with both KG and pounds/ounces
218
	 * @param  object wpsc_purchaselogs_items purchase log item being used
219
	 */
220
	return apply_filters( 'wpsc_purchlogs_get_weight_text', $weight_string, $id  );
221
222
}
223
224
function wpsc_purchlogs_has_customfields( $id = '' ) {
225
   global $purchlogitem;
226
   if ( $id == '' ) {
227
	  foreach ( (array)$purchlogitem->allcartcontent as $cartitem ) {
228
		 if ( $cartitem->files != 'N;' || $cartitem->custom_message != '' ) {
229
			return true;
230
		 }
231
	  }
232
	  return false;
233
   } else {
234
	  $purchlogitem = new wpsc_purchaselogs_items( $id );
235
	  foreach ( (array)$purchlogitem->allcartcontent as $cartitem ) {
236
		 if ( $cartitem->files != 'N;' || $cartitem->custom_message != '' ) {
237
			return true;
238
		 }
239
	  }
240
	  return false;
241
   }
242
   return false;
0 ignored issues
show
Unused Code introduced by
return false; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
243
}
244
245
function wpsc_trackingid_value() {
246
   global $purchlogs;
247
   return $purchlogs->purchitem->track_id;
248
}
249
250
function wpsc_purchlogs_custommessages() {
251
   global $purchlogitem;
252
   $messages = array();
253
   foreach ( $purchlogitem->allcartcontent as $cartitem ) {
254
	  if ( $cartitem->custom_message != '' ) {
255
		 $messages[] = array(
256
		 	'title'   => apply_filters( 'the_title', $cartitem->name ),
257
		 	'message' => $cartitem->custom_message,
258
		 );
259
	  }
260
   }
261
   return $messages;
262
}
263
264
function wpsc_purchlogs_customfiles() {
265
   global $purchlogitem;
266
   $files = array( );
0 ignored issues
show
introduced by
Empty array declaration must have no space between the parentheses
Loading history...
267
   foreach ( $purchlogitem->allcartcontent as $cartitem ) {
268
	  if ( $cartitem->files != 'N;' ) {
269
		 $file = unserialize( $cartitem->files );
270
271
		 if ( $file["mime_type"] == "image/jpeg" || $file["mime_type"] == "image/png" || $file["mime_type"] == "image/gif" ) {
272
			$image = "<a href='" . esc_url ( WPSC_USER_UPLOADS_URL . $file['file_name'] ) . "' >";
0 ignored issues
show
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
273
			$image .= "<img width='150' src='".esc_url( WPSC_USER_UPLOADS_URL . $file['file_name'] ). "' alt='' />";
274
			$image .="</a>";
275
			$files[] = $cartitem->name . ' :<br />' . $image;
276
		 } else {
277
			$files[] = $cartitem->name . ' :<br />' . esc_url( $file['file_name'] );
278
		 }
279
	  }
280
   }
281
   return $files;
282
}
283
284
function wpsc_have_purch_items() {
285
   global $purchlogs;
286
   return $purchlogs->have_purch_items();
287
}
288
289
function wpsc_is_checked_status() {
290
   global $purchlogs;
291
292
   return $purchlogs->is_checked_status();
293
}
294
295
function wpsc_have_purchaselog_details() {
296
   global $purchlogitem;
297
   return $purchlogitem->have_purch_item();
298
}
299
300
function wpsc_purchaselog_details_name() {
301
   global $purchlogitem;
302
   return esc_html( apply_filters( 'the_title', $purchlogitem->purchitem->name ) );
303
}
304
305
function wpsc_purchaselog_details_id() {
306
   global $purchlogitem;
307
   return $purchlogitem->purchitem->id;
308
}
309
310
function wpsc_the_purchaselog_item() {
311
   global $purchlogitem;
312
   return $purchlogitem->the_purch_item();
313
}
314
315
function wpsc_purchaselog_details_SKU() {
316
   global $purchlogitem;
317
   $meta_value = wpsc_get_cart_item_meta( $purchlogitem->purchitem->id, 'sku', true );
318
   if ( $meta_value != null ) {
319
	  return esc_attr( $meta_value );
320
   } else {
321
	  $meta_value = get_product_meta( $purchlogitem->purchitem->prodid, 'sku', true );
322
	  if ( $meta_value != null ) {
323
		 return esc_attr( $meta_value );
324
	  } else {
325
		 return __('N/A', 'wp-e-commerce');
326
	  }
327
   }
328
}
329
330
function wpsc_purchaselog_details_quantity() {
331
   global $purchlogitem;
332
   return (float) $purchlogitem->purchitem->quantity;
333
}
334
335
function wpsc_purchaselog_details_price() {
336
   global $purchlogitem;
337
   return (float) $purchlogitem->purchitem->price;
338
}
339
340
function wpsc_purchaselog_details_shipping() {
341
   global $purchlogitem;
342
   return (float) $purchlogitem->purchitem->pnp;
343
}
344
345
function wpsc_purchaselog_details_tax() {
346
   global $purchlogitem, $wpsc_cart;
347
348
   return (float) $purchlogitem->purchitem->tax_charged;
349
}
350
351
function wpsc_purchaselog_details_discount() {
352
   global $purchlogitem;
353
   return (float) $purchlogitem->extrainfo->discount_value;
354
}
355
356
function wpsc_purchaselog_details_date() {
357
   global $purchlogitem;
358
   return date_i18n( apply_filters( 'wpsc_single_purchase_log_date_format', get_option( 'date_format' ) ), $purchlogitem->extrainfo->date + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
359
}
360
361
function wpsc_purchaselog_details_date_time() {
362
   global $purchlogitem;
363
   return date_i18n( apply_filters( 'wpsc_single_purchase_log_date_time_format', get_option( 'date_format' ) . ' g:ia' ),   $purchlogitem->extrainfo->date + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
364
}
365
366
function wpsc_purchaselog_details_total() {
367
   global $purchlogitem;
368
   $total = 0;
369
   $total += ( $purchlogitem->purchitem->price * $purchlogitem->purchitem->quantity);
370
   $total += ( $purchlogitem->purchitem->pnp );
371
   $purchlogitem->totalAmount += $total;
372
   return $total;
373
}
374
375
function wpsc_purchaselog_details_purchnumber() {
376
   global $purchlogitem;
377
   return $purchlogitem->extrainfo->id;
378
}
379
380
/*
381
 * Has Discount Data?
382
 */
383
384
function wpsc_purchlog_has_discount_data() {
385
   global $purchlogitem;
386
   return!empty( $purchlogitem->extrainfo->discount_data );
387
}
388
389
/*
390
 * Returns Discount Code
391
 */
392
393
function wpsc_display_purchlog_discount_data( $numeric = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $numeric 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...
394
   global $purchlogitem;
395
   return $purchlogitem->extrainfo->discount_data;
396
}
397
398
/*
399
 * Returns base shipping should make a function to calculate items shipping as well
400
 */
401
402
function wpsc_display_purchlog_discount( $numeric = false ) {
403
   global $purchlogitem;
404
   $discount = $purchlogitem->extrainfo->discount_value;
405
   if ( $numeric == true ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
406
	  return $discount;
407
   } else {
408
	  return wpsc_currency_display( $discount,array( 'display_as_html' => false ) );
409
   }
410
}
411
412
/*
413
 * Returns base shipping should make a function to calculate items shipping as well
414
 */
415
416
function wpsc_display_purchlog_shipping( $numeric = false, $include_item = false ) {
417
   global $purchlogitem;
418
   $base_shipping = $purchlogitem->extrainfo->base_shipping;
419
   $per_item_shipping = 0;
420
421
   if ( $include_item ) {
422
      foreach ( (array)$purchlogitem->allcartcontent as $cart_item ) {
423
         if ( $cart_item->pnp > 0 ) {
424
            $per_item_shipping += ( $cart_item->pnp );
425
         }
426
      }
427
   }
428
429
   $total_shipping = $per_item_shipping + $base_shipping;
430
431
   if ( $numeric == true ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
432
      return $total_shipping;
433
   } else {
434
      return wpsc_currency_display( $total_shipping,array( 'display_as_html' => false ) );
435
   }
436
}
437
438
/**
439
 * @description: returns taxes as set in purchase log
440
 * @param: numeric - if set will return unformatted price
441
 * */
442
function wpec_display_purchlog_taxes( $numeric = false ) {
443
	return wpsc_display_purchlog_taxes( $numeric );
444
}
445
446
/**
447
 * @description: determines whether or not to display the product tax or not
448
 * @return: boolean
449
**/
450
function wpec_display_product_tax()
451
{
452
   global $purchlogitem;
453
   return ($purchlogitem->extrainfo->wpec_taxes_total == 0.00) ? true : false;
454
}// wpec_display_product_tax
455
456
457
function wpsc_display_purchlog_taxes( $numeric = false ) {
458
	global $purchlogitem;
459
	return ($numeric) ? $purchlogitem->extrainfo->wpec_taxes_total : wpsc_currency_display( $purchlogitem->extrainfo->wpec_taxes_total,array( 'display_as_html' => false ) );
460
}
461
462
function wpsc_display_purchlog_totalprice() {
463
	global $purchlogitem;
464
	$total = $purchlogitem->totalAmount - wpsc_display_purchlog_discount( true ) + wpsc_display_purchlog_shipping( true ) + wpsc_display_purchlog_taxes( true );
465
	return wpsc_currency_display( $total, array( 'display_as_html' => false ) );
466
}
467
468
function wpsc_display_purchlog_buyers_name() {
469
   global $purchlogitem;
470
471
   $first_name = $last_name = '';
472
473
   if ( isset( $purchlogitem->userinfo['billingfirstname'] ) ) {
474
   		$first_name = $purchlogitem->userinfo['billingfirstname']['value'];
475
   }
476
477
   if ( isset( $purchlogitem->userinfo['billinglastname'] ) ) {
478
   		$last_name = ' ' . $purchlogitem->userinfo['billinglastname']['value'];
479
   }
480
481
   $name = trim( $first_name . $last_name );
482
483
   return esc_html( $name );
484
}
485
486
function wpsc_display_purchlog_buyers_city() {
487
   global $purchlogitem;
488
   return isset( $purchlogitem->userinfo['billingcity'] ) ? esc_html( $purchlogitem->userinfo['billingcity']['value'] ) : '';
489
}
490
491
function wpsc_display_purchlog_buyers_email() {
492
   global $purchlogitem;
493
   return esc_html( $purchlogitem->userinfo['billingemail']['value'] );
494
}
495
496
function wpsc_display_purchlog_buyers_address() {
497
   global $purchlogitem;
498
   return isset( $purchlogitem->userinfo['billingaddress'] ) ? nl2br( esc_html( $purchlogitem->userinfo['billingaddress']['value'] ) ) : '';
499
}
500
501
function wpsc_display_purchlog_buyers_state_and_postcode() {
502
   global $purchlogitem;
503
   if( is_numeric($purchlogitem->extrainfo->billing_region ) )
504
		 $state = wpsc_get_region($purchlogitem->extrainfo->billing_region);
505
   else
506
		 $state = $purchlogitem->userinfo['billingstate']['value'];
507
508
   $output = esc_html( $state );
509
510
   if ( isset( $purchlogitem->userinfo['billingpostcode']['value'] ) && ! empty( $purchlogitem->userinfo['billingpostcode']['value'] ) ) {
511
      if (! empty( $output ) ) {
512
         $output .= ', ';
513
      }
514
      $output .= esc_html( $purchlogitem->userinfo['billingpostcode']['value'] );
515
   }
516
517
   return $output;
518
}
519
520
function wpsc_display_purchlog_buyers_country() {
521
   global $purchlogitem;
522
   return esc_html( wpsc_get_country( $purchlogitem->userinfo['billingcountry']['value'] ) );
523
}
524
525
function wpsc_display_purchlog_buyers_phone() {
526
   global $purchlogitem;
527
   $value = '';
528
   if ( isset( $purchlogitem->userinfo['billingphone']['value'] ) )
529
      $value = $purchlogitem->userinfo['billingphone']['value'];
530
531
   return esc_html( $value );
532
}
533
534
function wpsc_display_purchlog_shipping_name() {
535
   global $purchlogitem;
536
   return esc_html( $purchlogitem->shippinginfo['shippingfirstname']['value'] ) . ' ' . esc_html( $purchlogitem->shippinginfo['shippinglastname']['value'] );
537
}
538
539
function wpsc_display_purchlog_shipping_address() {
540
	global $purchlogitem;
541
542
	if ( isset( $purchlogitem->shippinginfo['shippingaddress'] ) ) {
543
		return nl2br( esc_html( $purchlogitem->shippinginfo['shippingaddress']['value'] ) );
544
	} else {
545
		return '';
546
	}
547
548
}
549
550
function wpsc_display_purchlog_shipping_city() {
551
   global $purchlogitem;
552
553
	if ( isset( $purchlogitem->shippinginfo['shippingcity'] ) ) {
554
		return esc_html( $purchlogitem->shippinginfo['shippingcity']['value'] );
555
	} else {
556
		return '';
557
	}
558
}
559
560
function wpsc_display_purchlog_shipping_state_and_postcode() {
561
   global $purchlogitem;
562
   $state = '';
563
   if( is_numeric($purchlogitem->extrainfo->shipping_region) )
564
		$state = esc_html( wpsc_get_region($purchlogitem->extrainfo->shipping_region) );
565
   else
566
		$state = esc_html( $purchlogitem->shippinginfo['shippingstate']['value'] );
567
568
   if ( !empty( $purchlogitem->shippinginfo['shippingpostcode']['value'] ) ){
569
		if( empty( $state ) )
570
			$state = esc_html( $purchlogitem->shippinginfo['shippingpostcode']['value'] );
571
		else
572
			$state .= ' ' . esc_html( $purchlogitem->shippinginfo['shippingpostcode']['value'] );
573
   }
574
575
   return $state;
576
}
577
578
function wpsc_display_purchlog_shipping_country() {
579
   global $purchlogitem;
580
581
	if ( isset( $purchlogitem->shippinginfo['shippingcountry'] ) ) {
582
		return esc_html( wpsc_get_country( $purchlogitem->shippinginfo['shippingcountry']['value'] ) );
583
	} else {
584
		return '';
585
	}
586
}
587
588
function wpsc_display_purchlog_shipping_method() {
589
   global $purchlogitem, $wpsc_shipping_modules;
590
591
   if ( ! empty ( $wpsc_shipping_modules[$purchlogitem->extrainfo->shipping_method] ) ) {
592
	  $shipping_class = &$wpsc_shipping_modules[$purchlogitem->extrainfo->shipping_method];
593
	  return esc_html( $shipping_class->getName() );
594
   } else {
595
	  return esc_html( $purchlogitem->extrainfo->shipping_method );
596
   }
597
}
598
599
function wpsc_display_purchlog_shipping_option() {
600
   global $purchlogitem;
601
   return esc_html( $purchlogitem->extrainfo->shipping_option );
602
}
603
604
function wpsc_display_purchlog_paymentmethod() {
605
   global $purchlogitem, $nzshpcrt_gateways;
606
   $gateway_name = '';
607
   if('wpsc_merchant_testmode' == $purchlogitem->extrainfo->gateway)
608
      return __( 'Manual Payment', 'wp-e-commerce' );
609
610
   foreach ( (array)$nzshpcrt_gateways as $gateway ) {
611
	  if ( $gateway['internalname'] == $purchlogitem->extrainfo->gateway )
612
		 $gateway_name = $gateway['name'];
613
   }
614
   if( !empty($gateway_name) )
615
	  return esc_html( $gateway_name );
616
   else
617
	  return esc_html( $purchlogitem->extrainfo->gateway );
618
619
}
620
621
function wpsc_purchaselog_order_summary_headers() {
622
	global $purchlogitem;
623
	do_action( 'wpsc_purchaselog_order_summary_headers', $purchlogitem );
624
}
625
626
function wpsc_purchaselog_order_summary() {
627
	global $purchlogitem;
628
	do_action( 'wpsc_purchaselog_order_summary', $purchlogitem );
629
}
630
631
function wpsc_has_purchlog_shipping() {
632
   global $purchlogitem;
633
   if ( isset( $purchlogitem->shippinginfo['shippingfirstname'] ) && $purchlogitem->shippinginfo['shippingfirstname']['value'] != '' ) {
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return isset($purchlogit...tname']['value'] != '';.
Loading history...
634
	  return true;
635
   } else {
636
	  return false;
637
   }
638
}
639
640
function wpsc_purchlogs_have_downloads_locked() {
641
   global $purchlogitem;
642
   $ip = $purchlogitem->have_downloads_locked();
643
   if ( $ip != '' ) {
644
	  return sprintf( __( 'Release downloads locked to this IP address %s', 'wp-e-commerce' ), $ip );
645
   } else {
646
	  return false;
647
   }
648
}
649
650
/**
651
 * Display Purchase Log Notes
652
 *
653
 * @return  string  Notes.
654
 */
655
function wpsc_display_purchlog_notes() {
656
	global $purchlogitem;
657
	$purchase_log = new WPSC_Purchase_Log( $purchlogitem->purchlogid );
658
	return $purchase_log->get( 'notes' );
659
}
660
661
/**
662
 * WP eCommerce purchaselogs AND purchaselogs_items class
663
 *
664
 * These is the classes for the WP eCommerce purchase logs,
665
 * The purchaselogs class handles adding, removing and adjusting details in the purchaselogs,
666
 * The purchaselogs_items class handles adding, removing and adjusting individual item details in the purchaselogs,
667
 *
668
 * @package wp-e-commerce
669
 * @since 3.7
670
 * @subpackage wpsc-cart-classes
671
 */
672
class wpsc_purchaselogs {
0 ignored issues
show
Coding Style introduced by
Class name "wpsc_purchaselogs" is not in camel caps format
Loading history...
673
674
   var $earliest_timestamp;
675
   var $current_timestamp;
676
   var $earliest_year;
677
   var $current_year;
678
   var $form_data;
679
   var $purch_item_count;
680
   //individual purch log variables
681
   var $allpurchaselogs;
682
   var $currentitem = -1;
683
   var $purchitem;
684
   //used for purchase options
685
   var $currentstatus = -1;
686
   var $purch_status_count;
687
   var $allpurchaselogstatuses;
688
   var $purchstatus;
689
   //calculation of totals
690
   var $totalAmount;
691
   //used for csv
692
   var $current_start_timestamp;
693
   var $current_end_timestamp;
694
   var $start_timestamp;
695
   var $end_timestamp;
696
697
	/* Constructor function */
698
	public function __construct() {
699
		$this->getall_formdata();
700
		if ( !isset( $_GET['view_purchlogs_by'] ) && !isset( $_GET['purchlogs_searchbox'] ) ) {
701
			$dates = $this->getdates();
702
			$dates = array_slice( $dates, 0, 3 );
703
			if(isset($dates[2]['start']))
704
				$this->current_start_timestamp = $dates[2]['start'];
705
			$this->current_end_timestamp = $dates[0]['end'];
706
			$newlogs = $this->get_purchlogs( $dates );
707
			$_SESSION['newlogs'] = $newlogs;
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
708
			$this->allpurchaselogs = $newlogs;
709
	  } else {
710
		 $this->getdates();
711
		 if ( isset( $_GET['view_purchlogs_by'] ) && isset( $_GET['view_purchlogs_by_status'] ) ) {
712
			$status = sanitize_text_field( $_GET['view_purchlogs_by_status'] );
713
			$viewby = sanitize_text_field( $_GET['view_purchlogs_by'] );
714
			if ( $viewby == 'all' ) {
715
			   $dates = $this->getdates();
716
			   $purchaselogs = $this->get_purchlogs( $dates, $status );
717
			   $_SESSION['newlogs'] = $purchaselogs;
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
718
			   $this->allpurchaselogs = $purchaselogs;
719
			} elseif ( $viewby == '3mnths' ) {
720
			   $dates = $this->getdates();
721
722
			   $dates = array_slice( $dates, 0, 3 );
723
			   $this->current_start_timestamp = $dates[count($dates)-1]['start'];
724
			   $this->current_end_timestamp = $dates[0]['end'];
725
			   $newlogs = $this->get_purchlogs( $dates, $status );
726
			   $_SESSION['newlogs'] = $newlogs;
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
727
			   $this->allpurchaselogs = $newlogs;
728
			} else {
729
			   $dates = explode( '_', $viewby );
730
			   $date[0]['start'] = $dates[0];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$date was never initialized. Although not strictly required by PHP, it is generally a good practice to add $date = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
731
			   $date[0]['end'] = $dates[1];
732
			   $this->current_start_timestamp = $dates[0];
733
			   $this->current_end_timestamp = $dates[1];
734
			   $newlogs = $this->get_purchlogs( $date, $status );
735
			   $_SESSION['newlogs'] = $newlogs;
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
736
			   $this->allpurchaselogs = $newlogs;
737
			}
738
		 }
739
	  }
740
	  $this->purch_item_count = count( $this->allpurchaselogs );
741
	  $statuses = $this->the_purch_item_statuses();
742
	  if ( isset( $_SESSION['newlogs'] ) ) {
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
743
		 $this->allpurchaselogs = $_SESSION['newlogs'];
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
744
		 $this->purch_item_count = count( $_SESSION['newlogs'] );
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
745
	  }
746
747
	  return;
748
   }
749
750
   function get_purchlogs( $dates, $status='' ) {
0 ignored issues
show
introduced by
Expected 1 space between argument "$status" and equals sign; 0 found
Loading history...
introduced by
Expected 1 space between default value and equals sign for argument "$status";
Loading history...
751
	  global $wpdb;
752
	   $purchlog2 = array();
753
	  $orderby = apply_filters( 'wpsc_purchase_logs_orderby', "' ORDER BY `date` DESC" );
754
	  if ( $status == '' || $status == '-1' ) {
755
		 foreach ( (array)$dates as $date_pair ) {
756
			if ( ($date_pair['end'] >= $this->earliest_timestamp) && ($date_pair['start'] <= $this->current_timestamp) ) {
757
			   $sql = $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN %s AND %s {$orderby}", $date_pair['start'], $date_pair['end'] );
758
			   $purchase_logs = $wpdb->get_results( $sql );
759
			   array_push( $purchlog2, $purchase_logs );
760
			}
761
		 }
762
	  } else {
763
		 foreach ( (array)$dates as $date_pair ) {
764
			if ( ($date_pair['end'] >= $this->earliest_timestamp) && ($date_pair['start'] <= $this->current_timestamp) ) {
765
			   $sql = $wpdb->prepare( "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` BETWEEN %s AND %s AND `processed`=%s {$orderby}", $date_pair['start'], $date_pair['end'], $status );
766
			   $purchase_logs = $wpdb->get_results( $sql );
767
			   array_push( $purchlog2, $purchase_logs );
768
			}
769
		 }
770
	  }
771
	  $newarray = array( );
0 ignored issues
show
introduced by
Empty array declaration must have no space between the parentheses
Loading history...
772
	  foreach ( $purchlog2 as $purch ) {
773
		 if ( is_array( $purch ) ) {
774
			foreach ( $purch as $log ) {
775
			   $newarray[] = $log;
776
			}
777
		 } else {
778
			exit( 'Else :' . print_r( $purch ) );
0 ignored issues
show
introduced by
The use of function print_r() is discouraged
Loading history...
779
		 }
780
	  }
781
	  $this->allpurchaselogs = $newarray;
782
	  $this->purch_item_count = count( $this->allpurchaselogs );
783
	  return $newarray;
784
   }
785
786
   function getall_formdata() {
787
	  global $wpdb;
788
	  $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1';";
789
	  $form_data = $wpdb->get_results( $form_sql, ARRAY_A );
790
	  $this->form_data = $form_data;
791
	  return $form_data;
792
   }
793
794
   /*
795
	* This finds the earliest time in the shopping cart and sorts out the timestamp system for the month by month display
796
	* or if there was a filter applied use the filter to sort the dates.
797
	*/
798
799
   function getdates() {
800
	  global $wpdb, $purchlogs;
801
802
	  $earliest_record_sql = "SELECT MIN(`date`) AS `date` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date`!=''";
803
	  $earliest_record = $wpdb->get_results( $earliest_record_sql, ARRAY_A );
804
805
	  $this->current_timestamp = time();
806
	  //if there are no reccords set the date to now.
807
	  $this->earliest_timestamp = ( isset( $earliest_record[0] ) && isset( $earliest_record[0]['date'] ) )?$earliest_record[0]['date']:time();
808
809
	  $this->current_year = date( "Y" );
810
	  $this->earliest_year = date( "Y", $this->earliest_timestamp );
811
812
	  $j = 0;
813
	  $date_list = array();
814
815
	  for ( $year = $this->current_year; $year >= $this->earliest_year; $year-- ) {
816
		 for ( $month = 12; $month >= 1; $month-- ) {
817
			$this->start_timestamp = mktime( 0, 0, 0, $month, 1, $year );
818
			$this->end_timestamp = mktime( 0, 0, 0, ($month + 1 ), 1, $year );
819
			if ( ($this->end_timestamp >= $this->earliest_timestamp) && ($this->start_timestamp <= $this->current_timestamp) ) {
820
			   $date_list[$j]['start'] = $this->start_timestamp;
821
			   $date_list[$j]['end'] = $this->end_timestamp;
822
			   $j++;
823
			}
824
		 }
825
	  }
826
	  if ( is_object( $purchlogs ) ) {
827
		 $purchlogs->current_start_timestamp = $purchlogs->earliest_timestamp;
828
		 $purchlogs->current_end_timestamp = $purchlogs->current_timestamp;
829
	  }
830
	  return $date_list;
831
   }
832
833
   function deletelog( $deleteid ) {
834
	global $wpdb;
835
	  if ( is_numeric( $deleteid ) ) {
836
837
		 $delete_log_form_sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='$deleteid'";
838
		 $cart_content = $wpdb->get_results( $delete_log_form_sql, ARRAY_A );
839
		 $wpdb->query( "DELETE FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='$deleteid'" );
840
		 $wpdb->query( "DELETE FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` IN ('$deleteid')" );
841
		 $wpdb->query( "DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='$deleteid' LIMIT 1" );
842
		 return '<div id="message" class="updated fade"><p>' . __( 'Thanks, the purchase log record has been deleted', 'wp-e-commerce' ) . '</p></div>';
843
	  }
844
   }
845
846
   //individual purchase log functions
847
   function next_purch_item() {
848
	  $this->currentitem++;
849
850
	  $this->purchitem = $this->allpurchaselogs[$this->currentitem];
851
	  return $this->purchitem;
852
   }
853
854
   function the_purch_item() {
855
	  $this->purchitem = $this->next_purch_item();
856
   }
857
858
   function have_purch_items() {
859
	  if ( $this->currentitem + 1 < $this->purch_item_count ) {
860
		 return true;
861
	  } else if ( $this->currentitem + 1 == $this->purch_item_count && $this->purch_item_count > 0 ) {
862
		 // Do some cleaning up after the loop,
863
		 $this->rewind_purch_items();
864
	  }
865
	  return false;
866
   }
867
868
   function rewind_purch_items() {
869
	  $this->currentitem = -1;
870
	  if ( $this->purch_item_count > 0 ) {
871
		 $this->purchitem = $this->allpurchaselogs[0];
872
	  }
873
   }
874
875
   function the_purch_item_statuses() {
876
	  global $wpdb, $wpsc_purchlog_statuses;
877
	  $this->purch_status_count = count( $wpsc_purchlog_statuses );
878
	  $this->allpurchaselogstatuses = $wpsc_purchlog_statuses;
879
	  return $wpsc_purchlog_statuses;
880
   }
881
882
   // purchase status loop functions
883
   function next_purch_status() {
884
	  $this->currentstatus++;
885
	  $this->purchstatus = $this->allpurchaselogstatuses[$this->currentstatus];
886
	  return $this->purchstatus;
887
   }
888
889
   function the_purch_status() {
890
	  $this->purchstatus = $this->next_purch_status();
891
   }
892
893
   function have_purch_status() {
894
	  if ( $this->currentstatus + 1 < $this->purch_status_count ) {
895
		 return true;
896
	  } else if ( $this->currentstatus + 1 == $this->purch_status_count && $this->purch_status_count > 0 ) {
897
		 // Do some cleaning up after the loop,
898
		 $this->rewind_purch_status();
899
	  }
900
	  return false;
901
   }
902
903
   function rewind_purch_status() {
904
	  $this->currentstatus = -1;
905
	  if ( $this->purch_status_count > 0 ) {
906
		 $this->purchstatus = $this->allpurchaselogstatuses[0];
907
	  }
908
   }
909
910
   function is_checked_status() {
911
	  if ( isset( $this->purchstatus['order'] ) && isset( $this->purchitem->processed ) && ($this->purchstatus['order'] == $this->purchitem->processed) ) {
912
		 return 'selected="selected"';
913
	  } else {
914
		 return '';
915
	  }
916
   }
917
918
   function the_purch_item_name() {
919
	  global $wpdb;
920
	  $i = 0;
921
922
	  if ( $this->form_data == null ) {
923
		 $this->getall_formdata();
924
	  }
925
926
	  $emailformid = 0;
927
	  $fNameformid = 0;
928
	  $lNameformid = 0;
929
930
	  foreach ( (array)$this->form_data as $formdata ) {
931
		 if ( in_array( 'billingemail', $formdata ) ) {
932
			$emailformid = $formdata['id'];
933
		 }
934
		 if ( in_array( 'billingfirstname', $formdata ) ) {
935
			$fNameformid = $formdata['id'];
936
		 }
937
		 if ( in_array( 'billinglastname', $formdata ) ) {
938
			$lNameformid = $formdata['id'];
939
		 }
940
		 $i++;
941
	  }
942
943
	  $sql = "SELECT value FROM " . WPSC_TABLE_SUBMITTED_FORM_DATA . " WHERE log_id=" . $this->purchitem->id . " AND form_id=" . $emailformid;
944
	  $email = $wpdb->get_var( $sql );
945
946
	  $sql = "SELECT value FROM " . WPSC_TABLE_SUBMITTED_FORM_DATA . " WHERE log_id=" . $this->purchitem->id . " AND form_id=" . $fNameformid;
947
	  $fname = $wpdb->get_var( $sql );
948
949
	  $sql = "SELECT value FROM " . WPSC_TABLE_SUBMITTED_FORM_DATA . " WHERE log_id=" . $this->purchitem->id . " AND form_id=" . $lNameformid;
950
	  $lname = $wpdb->get_var( $sql );
951
952
	  $namestring = esc_html( $fname ) . ' ' . esc_html( $lname ) . ' (<a href="mailto:' . esc_attr( $email ) . '?subject=Message From ' . home_url() . '">' . esc_html( $email ) . '</a>) ';
953
954
	  if ( $fname == '' && $lname == '' && $email == '' ) {
955
		 $namestring = __('N/A', 'wp-e-commerce');
956
	  }
957
958
	  return $namestring;
959
   }
960
961
   function the_purch_item_details() {
962
	  global $wpdb;
963
	  $sql = "SELECT SUM(quantity) FROM " . WPSC_TABLE_CART_CONTENTS . " WHERE purchaseid=" . $this->purchitem->id;
964
	  $sum = $wpdb->get_var( $sql );
965
	  return $sum;
966
   }
967
968
	function search_purchlog_view( $searchterm ) {
969
		global $wpdb, $wp_version;
970
971
		if ( version_compare( $wp_version, '4.0', '>=' ) ) {
972
			$searchterm = '%' . $wpdb->esc_like( $searchterm ) . '%';
973
		} else {
974
			$searchterm = '%' . like_escape( $searchterm ) . '%';
975
		}
976
977
		$newlogs = $wpdb->get_results( $wpdb->prepare(
978
			"SELECT DISTINCT `" . WPSC_TABLE_PURCHASE_LOGS . "` . * FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "`
979
			LEFT JOIN `" . WPSC_TABLE_PURCHASE_LOGS . "`
980
			ON `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "`.`log_id` = `" . WPSC_TABLE_PURCHASE_LOGS . "`.`id`
981
			WHERE `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "`.`value` LIKE %s
982
			OR `" . WPSC_TABLE_PURCHASE_LOGS . "`.`transactid` = %s
983
			OR `" . WPSC_TABLE_PURCHASE_LOGS . "`.`track_id` LIKE %s",
984
			$searchterm
985
			)
986
		);
987
988
		$_SESSION['newlogs'] = $newlogs;
0 ignored issues
show
introduced by
Usage of $_SESSION variable is prohibited.
Loading history...
989
990
		return $newlogs;
991
	}
992
993
}
994
995
class wpsc_purchaselogs_items {
0 ignored issues
show
Coding Style introduced by
Class name "wpsc_purchaselogs_items" is not in camel caps format
Loading history...
996
997
   var $purchlogid;
998
   var $extrainfo;
999
   //the loop
1000
   var $currentitem = -1;
1001
   var $purchitem;
1002
   var $allcartcontent;
1003
   var $purch_item_count;
1004
   //grand total
1005
   var $totalAmount;
1006
   //usersinfo
1007
   var $userinfo;
1008
   var $shippinginfo;
1009
   var $customcheckoutfields = array( );
0 ignored issues
show
introduced by
Empty array declaration must have no space between the parentheses
Loading history...
1010
   var $additional_fields = array();
1011
1012
1013
   public function __construct( $id ) {
1014
	  $this->purchlogid = $id;
1015
	  $this->get_purchlog_details();
1016
   }
1017
1018
   function shippingstate( $id ) {
1019
	  global $wpdb;
1020
	  if ( is_numeric( $id ) ) {
1021
		 $name = wpsc_get_region( $id );
1022
		 return $name;
1023
	  } else {
1024
		 return $id;
1025
	  }
1026
   }
1027
1028
   function get_purchlog_details() {
1029
      global $wpdb;
1030
1031
      $cartcontent = $wpdb->get_results( "SELECT *  FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $this->purchlogid . "" );
1032
1033
      $this->allcartcontent = $cartcontent;
1034
      $sql = "SELECT DISTINCT `" . WPSC_TABLE_PURCHASE_LOGS . "` . * FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` LEFT JOIN `" . WPSC_TABLE_PURCHASE_LOGS . "` ON `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "`.`log_id` = `" . WPSC_TABLE_PURCHASE_LOGS . "`.`id` WHERE `" . WPSC_TABLE_PURCHASE_LOGS . "`.`id`=" . $this->purchlogid;
1035
      $extrainfo = $wpdb->get_results( $sql );
1036
1037
      $this->extrainfo = $extrainfo[0];
1038
1039
      $usersql = "SELECT `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "`.`id`, `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "`.`value`, `" . WPSC_TABLE_CHECKOUT_FORMS . "`.`name`, `" . WPSC_TABLE_CHECKOUT_FORMS . "`.`unique_name` 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`=" . $this->purchlogid . " ORDER BY `" . WPSC_TABLE_CHECKOUT_FORMS . "`.`checkout_order`";
1040
      $userinfo = $wpdb->get_results( $usersql, ARRAY_A );
1041
1042
      // the $additionaldetails array is buggy because if the fields have the same name, they will
1043
      // overwrite each other.
1044
      // $additional_fields is introduced to fix this. However, the $additionaldetails array as well
1045
      // as $this->customcheckoutfields needs to be kept for compatibility purposes.
1046
1047
      $additional_fields = $billingdetails = $shippinginfo = array();
1048
1049
      foreach ( (array) $userinfo as $input_row ) {
1050
         if ( stristr( $input_row['unique_name'], 'shipping' ) ) {
1051
            $shippinginfo[$input_row['unique_name']] = $input_row;
1052
         } elseif ( stristr( $input_row['unique_name'], 'billing' ) ) {
1053
            $billingdetails[ $input_row['unique_name'] ] = $input_row;
1054
         } else {
1055
            $additionaldetails[ $input_row['name'] ] = $input_row;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$additionaldetails was never initialized. Although not strictly required by PHP, it is generally a good practice to add $additionaldetails = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1056
            $additional_fields[] = $input_row;
1057
         }
1058
      }
1059
      $this->userinfo     = $billingdetails;
1060
      $this->shippinginfo = $shippinginfo;
1061
1062
      if ( isset( $additionaldetails ) ) {
1063
         $this->customcheckoutfields = $additionaldetails;
1064
      }
1065
      if ( isset( $additional_fields ) )
1066
         $this->additional_fields = $additional_fields;
1067
1068
      $this->purch_item_count = count( $cartcontent );
1069
   }
1070
1071
   function next_purch_item() {
1072
	  $this->currentitem++;
1073
	  $this->purchitem = $this->allcartcontent[$this->currentitem];
1074
	  return $this->purchitem;
1075
   }
1076
1077
   function the_purch_item() {
1078
	  $this->purchitem = $this->next_purch_item();
1079
   }
1080
1081
   function have_purch_item() {
1082
	  if ( $this->currentitem + 1 < $this->purch_item_count ) {
1083
		 return true;
1084
	  } else if ( $this->currentitem + 1 == $this->purch_item_count && $this->purch_item_count > 0 ) {
1085
		 // Do some cleaning up after the loop,
1086
		 $this->rewind_purch_item();
1087
	  }
1088
	  return false;
1089
   }
1090
1091
   function rewind_purch_item() {
1092
	  $this->currentitem = -1;
1093
	  if ( $this->purch_item_count > 0 ) {
1094
		 $this->purchitem = $this->allcartcontent[0];
1095
	  }
1096
   }
1097
1098
   function have_downloads_locked() {
1099
	  global $wpdb;
1100
	  $sql = "SELECT `ip_number` FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE purchid=" . $this->purchlogid;
1101
	  $ip_number = $wpdb->get_var( $sql );
1102
	  return $ip_number;
1103
   }
1104
}
1105
1106
//edit purchase log status function
1107
function wpsc_purchlog_edit_status( $purchlog_id='', $purchlog_status='' ) {
0 ignored issues
show
introduced by
Expected 1 space between argument "$purchlog_id" and equals sign; 0 found
Loading history...
introduced by
Expected 1 space between default value and equals sign for argument "$purchlog_id";
Loading history...
introduced by
Expected 1 space between argument "$purchlog_status" and equals sign; 0 found
Loading history...
introduced by
Expected 1 space between default value and equals sign for argument "$purchlog_status";
Loading history...
1108
   global $wpdb;
1109
   if ( empty($purchlog_id) && empty($purchlog_status) ) {
1110
      $purchlog_id = absint( $_POST['id'] );
1111
      $purchlog_status = absint( $_POST['new_status'] );
1112
   }
1113
1114
   $purchase_log = new WPSC_Purchase_Log( $purchlog_id );
1115
1116
   //in the future when everyone is using the 2.0 merchant api, we should use the merchant class to update the staus,
1117
   // then you can get rid of this hook and have each person overwrite the method that updates the status.
1118
   do_action('wpsc_edit_order_status', array('purchlog_id'=>$purchlog_id, 'purchlog_data'=>$purchase_log->get_data(), 'new_status'=>$purchlog_status));
1119
1120
   $result = wpsc_update_purchase_log_status( $purchlog_id, $purchlog_status );
1121
   wpsc_clear_stock_claims();
1122
1123
   return $result;
1124
}
1125