-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathuser-log.php
445 lines (383 loc) · 17.6 KB
/
user-log.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
<?php
global $wpdb, $user_ID;
if(get_option('permalink_structure') != '') {
$seperator ="?";
} else {
$seperator ="&";
}
$siteurl = get_option('siteurl');
if($_GET['edit_profile'] == 'true') {
require('edit-profile.php');
} else if ($_GET['downloads'] == 'true'){
require('user-downloads.php');
} else {
/*
* this finds the earliest timedit-profile in the shopping cart and sorts out the timestamp system for the month by month display
*/
$sql = "SELECT COUNT(*) AS `count` FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `date`!='' ORDER BY `date` DESC";
$purchase_count= $wpdb->get_results($sql,ARRAY_A) ;
$earliest_record_sql = "SELECT MIN(`date`) AS `date` FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `date`!=''";
$earliest_record = $wpdb->get_results($earliest_record_sql,ARRAY_A) ;
$current_timestamp = time();
$earliest_timestamp = $earliest_record[0]['date'];
$current_year = date("Y");
$earliest_year = date("Y",$earliest_timestamp);
$date_list[0]['start'] = $start_timestamp;
$date_list[0]['end'] = $end_timestamp;
?>
<div class="wrap" style=''>
<?php
if(is_numeric($user_ID) && ($user_ID > 0)) {
echo " <div class='user-profile-links'><a href='".get_option('user_account_url')."'>Purchase History</a> | <a href='".get_option('user_account_url').$seperator."edit_profile=true'>Your Details</a> | <a href='".get_option('user_account_url').$seperator."downloads=true'>Your Downloads</a></div><br />";
if(($purchase_log == null) && !is_numeric($_GET['purchaseid'])) {
if($earliest_record[0]['date'] != null) {
$form_sql = "SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `active` = '1' AND `display_log` = '1';";
$col_count = 4 + count($form_data);
echo "<table class='logdisplay'>";
$sql = "SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `user_ID` IN ('".$user_ID."') ORDER BY `date` DESC";
$purchase_log = $wpdb->get_results($sql,ARRAY_A) ;
$i = 0;
$subtotal = 0;
if($purchase_log != null) {
echo "<tr class='toprow'>";
echo " <td>";
echo __('Status', 'wpsc');
echo " </td>";
echo " <td>";
echo __('Date', 'wpsc');
echo " </td>";
echo " <td>";
echo __('Price', 'wpsc');
echo " </td>";
if(get_option('payment_method') == 2) {
echo " <td>";
echo __('Payment Method', 'wpsc');
echo " </td>";
}
echo "</tr>";
foreach((array)$purchase_log as $purchase) {
$status_state = "expand";
$status_style = "";
$alternate = "";
$i++;
if(($i % 2) != 0) {
$alternate = "class='alt'";
}
echo "<tr $alternate>\n\r";
// echo " <td>";
// echo $purchase['id'];
// echo " </td>";
echo " <td class='processed'>";
echo "<a href='#' onclick='return show_details_box(\"status_box_".$purchase['id']."\",\"log_expander_icon_".$purchase['id']."\");'>";
if($_GET['id'] == $purchase['id']) {
$status_state = "collapse";
$status_style = "style='display: block;'";
}
echo "<img class='log_expander_icon' id='log_expander_icon_".$purchase['id']."' src='".WPSC_URL."/images/icon_window_$status_state.gif' alt='' title='' />";
if($stage_data['colour'] != '') {
$colour = "style='color: #".$stage_data['colour'].";'";
}
echo "<span id='form_group_".$purchase['id']."_text'>".__('Details', 'wpsc')."</span>";
echo "</a>";
echo " </td>\n\r";
echo " <td>";
echo date("jS M Y",$purchase['date']);
echo " </td>\n\r";
echo " <td>";
if($purchase['shipping_country'] != '') {
$billing_country = $purchase['billing_country'];
$shipping_country = $purchase['shipping_country'];
} else {
$country_sql = "SELECT * FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE `log_id` = '".$purchase['id']."' AND `form_id` = '".get_option('country_form_field')."' LIMIT 1";
$country_data = $wpdb->get_results($country_sql,ARRAY_A);
$billing_country = $country_data[0]['value'];
$shipping_country = $country_data[0]['value'];
}
echo nzshpcrt_currency_display($purchase['totalprice'],1);
$subtotal += $purchase['totalprice'];
echo " </td>\n\r";
if(get_option('payment_method') == 2) {
echo " <td>";
$gateway_name = '';
foreach((array)$GLOBALS['nzshpcrt_gateways'] as $gateway) {
if($purchase['gateway'] != 'testmode') {
if($gateway['internalname'] == $purchase['gateway'] ) {
$gateway_name = $gateway['name'];
}
} else {
$gateway_name = "Manual Payment";
}
}
echo $gateway_name;
echo " </td>\n\r";
}
echo "</tr>\n\r";
//$stage_list_sql = "SELECT * FROM `".WPSC_TABLE_PURCHASE_STATUSES."` ORDER BY `id` ASC";
//$stage_list_data = $wpdb->get_results($stage_list_sql,ARRAY_A);
echo "<tr>\n\r";
echo " <td colspan='$col_count' class='details'>\n\r";
echo " <div id='status_box_".$purchase['id']."' class='order_status' $status_style>\n\r";
echo " <div>\n\r";
//order status code lies heret
$stage_sql = "SELECT * FROM `".WPSC_TABLE_PURCHASE_STATUSES."` WHERE `id`='".$purchase['processed']."' AND `active`='1' LIMIT 1";
$stage_data = $wpdb->get_row($stage_sql,ARRAY_A);
echo " <strong class='form_group'>".__('Order Status', 'wpsc').":</strong>\n\r";
echo $stage_data['name']."<br /><br />";
//written by allen
$usps_id = get_option('usps_user_id');
if ($usps_id!=null) {
$XML1 = "<TrackFieldRequest USERID=\"$usps_id\"><TrackID ID=\"".$purchase['track_id']."\"></TrackID></TrackFieldRequest>";
//eecho cho "--->".$purchase['track_id'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://secure.shippingapis.com/ShippingAPITest.dll?");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$postdata = "API=TrackV2&XML=".$XML1;
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
// $result = curl_exec($ch);
$parser = new xml2array;
$parsed = $parser->parse($result);
$parsed = $parsed[0]['children'][0]['children'];
if($purchase['track_id'] != null){
echo "<br /><br />";
echo " <strong class='form_group'>".__('Shipping Details', 'wpsc')."</strong>\n\r";
echo "<table>";
foreach((array)$parsed as $parse){
if ($parse['name'] == "TRACKSUMMARY")
foreach((array)$parse['children'] as $attrs){
if ($attrs['name']!="EVENT")
$attrs['name'] = str_replace("EVENT", "", $attrs['name']);
$bar = ucfirst(strtolower($attrs['name']));
echo "<tr><td>".$bar."</td><td>".$attrs['tagData']."</td></tr>";
}
}
echo "</table>";
}
echo "<br /><br />";
}
//end of written by allen
//cart contents display starts here;
echo " <strong class='form_group'>".__('Order Details', 'wpsc').":</strong>\n\r";
$cartsql = "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`=".$purchase['id']."";
$cart_log = $wpdb->get_results($cartsql,ARRAY_A) ;
$j = 0;
// /*
if($cart_log != null)
{
echo "<table class='logdisplay'>";
echo "<tr class='toprow2'>";
echo " <td>";
echo __('Name', 'wpsc');
echo " </td>";
echo " <td>";
echo __('Quantity', 'wpsc');
echo " </td>";
echo " <td>";
echo __('Price', 'wpsc');
echo " </td>";
echo " <td>";
echo __('GST', 'wpsc');
echo " </td>";
echo " <td>";
echo __('P&P', 'wpsc');
echo " </td>";
echo " <td>";
echo __('Total', 'wpsc');
echo " </td>";
echo "</tr>";
$endtotal = 0;
foreach((array)$cart_log as $cart_row) {
$alternate = "";
$j++;
if(($j % 2) != 0) {
$alternate = "class='alt'";
}
$productsql= "SELECT * FROM `".WPSC_TABLE_PRODUCT_LIST."` WHERE `id`=".$cart_row['prodid']."";
$product_data = $wpdb->get_results($productsql,ARRAY_A);
$variation_sql = "SELECT * FROM `".WPSC_TABLE_CART_ITEM_VARIATIONS."` WHERE `cart_id`='".$cart_row['id']."'";
$variation_data = $wpdb->get_results($variation_sql,ARRAY_A);
$variation_count = count($variation_data);
if($variation_count > 1) {
$variation_list = " (";
$i = 0;
foreach((array)$variation_data as $variation) {
if($i > 0) {
$variation_list .= ", ";
}
$value_id = $variation['value_id'];
$value_data = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_VARIATION_VALUES."` WHERE `id`='".$value_id."' LIMIT 1",ARRAY_A);
$variation_list .= $value_data[0]['name'];
$i++;
}
$variation_list .= ")";
} else if($variation_count == 1) {
$value_id = $variation_data[0]['value_id'];
$value_data = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_VARIATION_VALUES."` WHERE `id`='".$value_id."' LIMIT 1",ARRAY_A);
$variation_list = " (".$value_data[0]['name'].")";
} else {
$variation_list = '';
}
if($purch_data[0]['shipping_country'] != '') {
$billing_country = $purch_data[0]['billing_country'];
$shipping_country = $purch_data[0]['shipping_country'];
} else {
$country_sql = "SELECT * FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE `log_id` = '".$purchase['id']."' AND `form_id` = '".get_option('country_form_field')."' LIMIT 1";
$country_data = $wpdb->get_results($country_sql,ARRAY_A);
$billing_country = $country_data[0]['value'];
$shipping_country = $country_data[0]['value'];
}
$shipping = $cart_row['pnp'];
$total_shipping += $shipping;
echo "<tr $alternate>";
echo " <td>";
echo $product_data[0]['name'];
echo $variation_list;
echo " </td>";
echo " <td>";
echo $cart_row['quantity'];
echo " </td>";
echo " <td>";
$price = $cart_row['price'] * $cart_row['quantity'];
echo nzshpcrt_currency_display($price, 1);
echo " </td>";
echo " <td>";
$gst = $cart_row['tax_charged'];
$endtotal += $gst * $cart_row['quantity'];
echo nzshpcrt_currency_display($gst, 1);
echo " </td>";
echo " <td>";
echo nzshpcrt_currency_display($shipping, 1);
echo " </td>";
echo " <td>";
$endtotal += $price;
echo nzshpcrt_currency_display(($shipping + $price + ($gst * $cart_row['quantity'])), 1);
echo " </td>";
echo '</tr>';
}
echo "<tr >";
echo " <td>";
echo " </td>";
echo " <td>";
echo " </td>";
echo " <td>";
echo " </td>";
echo " <td>";
echo "<strong>".__('Total Shipping', 'wpsc').":</strong><br />";
echo "<strong>".__('Final Total', 'wpsc').":</strong>";
echo " </td>";
echo " <td>";
$total_shipping += $purchase['base_shipping'];
$endtotal += $total_shipping;
echo nzshpcrt_currency_display($total_shipping, 1) . "<br />";
echo nzshpcrt_currency_display($endtotal,1);
echo " </td>";
echo '</tr>';
echo "</table>";
echo "<br />";
echo "<strong>".__('Customer Details', 'wpsc').":</strong>";
echo "<table class='customer_details'>";
$form_sql = "SELECT * FROM `".WPSC_TABLE_SUBMITED_FORM_DATA."` WHERE `log_id` = '".$purchase['id']."'";
$input_data = $wpdb->get_results($form_sql,ARRAY_A);
//exit("<pre>".print_r($input_data,true)."</pre>");
if($input_data != null) {
foreach((array)$input_data as $form_field) {
$form_sql = "SELECT * FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `active` = '1' AND `id` = '".$form_field['form_id']."' LIMIT 1";
$form_data = $wpdb->get_results($form_sql,ARRAY_A);
if($form_data != null) {
$form_data = $form_data[0];
if($form_data['type'] == 'country' ) {
if($form_field['value'] != null) {
echo " <tr><td>".$form_data['name'].":</td><td>".wpsc_get_country($form_field['value'])."</td></tr>";
} else {
echo " <tr><td>".$form_data['name'].":</td><td>".wpsc_get_country($purchase['shipping_country'])."</td></tr>";
}
} else {
echo " <tr><td>".$form_data['name'].":</td><td>".$form_field['value']."</td></tr>";
}
}
}
} else {
echo " <tr><td>".__('Name', 'wpsc').":</td><td>".$purchase['firstname']." ".$purchase['lastname']."</td></tr>";
echo " <tr><td>".__('Address', 'wpsc').":</td><td>".$purchase['address']."</td></tr>";
echo " <tr><td>".__('Phone', 'wpsc').":</td><td>".$purchase['phone']."</td></tr>";
echo " <tr><td>".__('Email', 'wpsc').":</td><td>".$purchase['email']."</td></tr>";
}
//if(get_option('payment_method') == 2)
//{
$gateway_name = '';
foreach((array)$GLOBALS['nzshpcrt_gateways'] as $gateway)
{
if($purchase_log[0]['gateway'] != 'testmode')
{
if($gateway['internalname'] == $purchase_log[0]['gateway'] )
{
$gateway_name = $gateway['name'];
}
}
else
{
$gateway_name = "Manual Payment";
}
}
//}
echo " <tr><td>".__('Payment Method', 'wpsc').":</td><td>".$gateway_name."</td></tr>";
echo " <tr><td>".__('Purchase No.', 'wpsc').":</td><td>".$purchase['id']."</td></tr>";
if($purchase['transactid'] != '')
{
echo " <tr><td>".__('Transaction Id', 'wpsc').":</td><td>".$purchase['transactid']."</td></tr>";
}
echo "</table>";
} // */
echo " </div>\n\r";
echo " </div>\n\r";
echo " </td>\n\r";
echo "</tr>\n\r";
}
}
else
{
echo "<tr>";
echo " <td colspan='$col_count'>";
echo __('No transactions for this month.', 'wpsc');
echo " </td>";
echo "</tr>";
}
echo " </table>";
}
else
{
echo " <table>";
echo "<tr>";
echo " <td>";
echo __('There have not been any purchases yet.', 'wpsc');
echo " </td>";
echo "</tr>";
echo " </table>";
}
}
// Commented out as this seemed to be breaking the Your Account layout.
// Doesn't seem to do anything, does it?
//$sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `date` != ''";
//$purchase_log = $wpdb->get_results( $sql, ARRAY_A );
}
else
{
echo __('You must be logged in to use this page. Please use the form below to login to your account.', 'wpsc');
?>
<form name="loginform" id="loginform" action="<?php echo $siteurl; ?>/wp-login.php" method="post"><br />
<label>Username:<br /><input type="text" name="log" id="log" value="" size="20" tabindex="1" /></label><br />
<label>Password:<br /> <input type="password" name="pwd" id="pwd" value="" size="20" tabindex="2" /></label>
<p>
<label><input name="rememberme" type="checkbox" id="rememberme" value="forever" tabindex="3" />
Remember me</label></p>
<p class="submit">
<input type="submit" name="submit" id="submit" value="Login »" tabindex="4" />
<input type="hidden" name="redirect_to" value="<?php echo get_option('user_account_url'); ?>" />
</p>
</form>
<?php
}
?>
</div>
<?php } ?>