-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFunctions.php
More file actions
2649 lines (2231 loc) · 114 KB
/
Functions.php
File metadata and controls
2649 lines (2231 loc) · 114 KB
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Created by TwinCitiesTech.com
(website: twincitiestech.com email : support@twincitiestech.com)
Modified by S H Mohanjith
(website: mohanjith.com email : support@mohanjith.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 3 of the License, with the
exception of the JQuery JavaScript framework which is released
under it's own license. You may view the details of that license in
the prototype.js file.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
setlocale(LC_MONETARY, 'en_US');
function web_invoice_number_of_invoices()
{
global $wpdb;
$query = "SELECT COUNT(*) FROM ".Web_Invoice::tablename('main')."";
$count = $wpdb->get_var($query);
return $count;
}
function web_invoice_does_invoice_exist($invoice_id) {
global $wpdb;
$invoice = new Web_Invoice_GetInfo($invoice_id);
return $invoice->id;
}
function web_invoice_validate_cc_number($cc_number) {
/* Validate; return value is card type if valid. */
$false = false;
$card_type = "";
$card_regexes = array(
"/^4\d{12}(\d\d\d){0,1}$/" => "visa",
"/^5[12345]\d{14}$/" => "mastercard",
"/^3[47]\d{13}$/" => "amex",
"/^6011\d{12}$/" => "discover",
"/^30[012345]\d{11}$/" => "diners",
"/^3[68]\d{12}$/" => "diners",
);
foreach ($card_regexes as $regex => $type) {
if (preg_match($regex, $cc_number)) {
$card_type = $type;
break;
}
}
if (!$card_type) {
return $false;
}
/* mod 10 checksum algorithm */
$revcode = strrev($cc_number);
$checksum = 0;
for ($i = 0; $i < strlen($revcode); $i++) {
$current_num = intval($revcode[$i]);
if($i & 1) { /* Odd position */
$current_num *= 2;
}
/* Split digits and add. */
$checksum += $current_num % 10; if
($current_num > 9) {
$checksum += 1;
}
}
if ($checksum % 10 == 0) {
return $card_type;
} else {
return $false;
}
}
function web_invoice_update_log($invoice_id,$action_type,$value)
{
global $wpdb;
if(isset($invoice_id))
{
$time_stamp = date("Y-m-d h-i-s");
$wpdb->query("INSERT INTO ".Web_Invoice::tablename('log')."
(invoice_id , action_type , value, time_stamp)
VALUES ('$invoice_id', '$action_type', '$value', '$time_stamp');");
}
}
function web_invoice_query_log($invoice_id,$action_type) {
global $wpdb;
if($results = $wpdb->get_results("SELECT * FROM ".Web_Invoice::tablename('log')." WHERE invoice_id = '$invoice_id' AND action_type = '$action_type' ORDER BY 'time_stamp' DESC")) return $results;
}
function web_invoice_meta($invoice_id,$meta_key,$default=false)
{
global $wpdb;
global $_web_invoice_meta_cache;
if (!isset($_web_invoice_meta_cache[$invoice_id][$meta_key]) || !$_web_invoice_meta_cache[$invoice_id][$meta_key]) {
$_web_invoice_meta_cache[$invoice_id][$meta_key] = $wpdb->get_var("SELECT meta_value FROM `".Web_Invoice::tablename('meta')."` WHERE meta_key = '$meta_key' AND invoice_id = '$invoice_id'");
}
return ($_web_invoice_meta_cache[$invoice_id][$meta_key])?$_web_invoice_meta_cache[$invoice_id][$meta_key]:$default;
}
function web_invoice_payment_register($invoice_id, $amount, $trx_id = "", $status = 0) {
global $wpdb;
global $_web_invoice_payment_cache;
if (empty($trx_id)) {
$trx_id = uniqid('web_invoice_');
}
$wpdb->query("INSERT INTO `".Web_Invoice::tablename('payment')."` (invoice_id, trx_id, amount, status) VALUES ('$invoice_id', '$trx_id', '$amount', '$status')");
$_web_invoice_payment_cache[$trx_id] = mysql_insert_id();
return $_web_invoice_payment_cache[$trx_id];
}
function web_invoice_payment_update_status($trx_id, $status = 0) {
global $wpdb;
global $_web_invoice_payment_cache;
$wpdb->query("UPDATE `".Web_Invoice::tablename('payment')."` SET status = '$status' WHERE trx_id = '$trx_id';");
$_web_invoice_payment_cache[$trx_id] = $trx_id;
return $_web_invoice_payment_cache[$trx_id];
}
function web_invoice_sum_payments($invoice_id) {
global $wpdb;
$sum = $wpdb->get_var("SELECT SUM(amount) FROM `".Web_Invoice::tablename('payment')."` WHERE invoice_id = '$invoice_id'");
return $sum;
}
function web_invoice_payments($invoice_id, $status = 0) {
global $wpdb;
$rows = $wpdb->get_results("SELECT * FROM `".Web_Invoice::tablename('payment')."` WHERE invoice_id = '$invoice_id' AND status = '$status'");
return $rows;
}
function web_invoice_get_invoice_id_by_payment($trx_id) {
global $wpdb;
$invoice_id = $wpdb->get_var("SELECT invoice_id FROM `".Web_Invoice::tablename('payment')."` WHERE trx_id = '$trx_id'");
return $invoice_id;
}
function web_invoice_payment_meta($payment_id, $meta_key)
{
global $wpdb;
global $_web_invoice_payment_meta_cache;
if (!isset($_web_invoice_payment_meta_cache[$payment_id][$meta_key]) || !$_web_invoice_payment_meta_cache[$payment_id][$meta_key]) {
$_web_invoice_payment_meta_cache[$payment_id][$meta_key] = $wpdb->get_var("SELECT meta_value FROM `".Web_Invoice::tablename('payment_meta')."` WHERE meta_key = '$meta_key' AND payment_id = '$payment_id'");
}
return $_web_invoice_payment_meta_cache[$payment_id][$meta_key];
}
function web_invoice_update_invoice_meta($invoice_id,$meta_key,$meta_value)
{
global $wpdb;
global $_web_invoice_meta_cache;
if(empty($meta_value)) {
// Delete meta_key if no value is set
$wpdb->query("DELETE FROM ".Web_Invoice::tablename('meta')." WHERE invoice_id = '$invoice_id' AND meta_key = '$meta_key'");
}
else
{
// Check if meta key already exists, then we replace it Web_Invoice::tablename('meta')
if($wpdb->get_var("SELECT meta_key FROM `".Web_Invoice::tablename('meta')."` WHERE meta_key = '$meta_key' AND invoice_id = '$invoice_id'"))
{ $wpdb->query("UPDATE `".Web_Invoice::tablename('meta')."` SET meta_value = '$meta_value' WHERE meta_key = '$meta_key' AND invoice_id = '$invoice_id'"); }
else
{ $wpdb->query("INSERT INTO `".Web_Invoice::tablename('meta')."` (invoice_id, meta_key, meta_value) VALUES ('$invoice_id','$meta_key','$meta_value')"); }
}
if (isset($_web_invoice_meta_cache[$invoice_id][$meta_key])) {
$_web_invoice_meta_cache[$invoice_id][$meta_key] = $meta_value;
}
}
function web_invoice_update_payment_meta($payment_id,$meta_key,$meta_value)
{
global $wpdb;
global $_web_invoice_payment_meta_cache;
if(empty($meta_value)) {
// Delete meta_key if no value is set
$wpdb->query("DELETE FROM ".Web_Invoice::tablename('payment_meta')." WHERE payment_id = '$payment_id' AND meta_key = '$meta_key'");
}
else
{
// Check if meta key already exists, then we replace it Web_Invoice::tablename('payment_meta')
if($wpdb->get_var("SELECT meta_key FROM `".Web_Invoice::tablename('payment_meta')."` WHERE meta_key = '$meta_key' AND payment_id = '$payment_id'"))
{ $wpdb->query("UPDATE `".Web_Invoice::tablename('payment_meta')."` SET meta_value = '$meta_value' WHERE meta_key = '$meta_key' AND payment_id = '$payment_id'"); }
else
{ $wpdb->query("INSERT INTO `".Web_Invoice::tablename('payment_meta')."` (payment_id, meta_key, meta_value) VALUES ('$payment_id','$meta_key','$meta_value')"); }
}
if (isset($_web_invoice_payment_meta_cache[$payment_id][$meta_key])) {
$_web_invoice_payment_meta_cache[$payment_id][$meta_key] = $meta_value;
}
}
function web_invoice_delete_invoice_meta($invoice_id,$meta_key='')
{
global $wpdb;
global $_web_invoice_meta_cache;
if(empty($meta_key))
{ $wpdb->query("DELETE FROM `".Web_Invoice::tablename('meta')."` WHERE invoice_id = '$invoice_id' ");}
else
{ $wpdb->query("DELETE FROM `".Web_Invoice::tablename('meta')."` WHERE invoice_id = '$invoice_id' AND meta_key = '$meta_key'");}
if (isset($_web_invoice_meta_cache[$invoice_id][$meta_key])) {
$_web_invoice_meta_cache[$invoice_id][$meta_key] = false;
}
}
function web_invoice_delete_payment_meta($payment_id,$meta_key='')
{
global $wpdb;
global $_web_invoice_payment_meta_cache;
if(empty($meta_key))
{ $wpdb->query("DELETE FROM `".Web_Invoice::tablename('payment_meta')."` WHERE invoice_id = '$payment_id' ");}
else
{ $wpdb->query("DELETE FROM `".Web_Invoice::tablename('payment_meta')."` WHERE invoice_id = '$payment_id' AND meta_key = '$meta_key'");}
if (isset($_web_invoice_payment_meta_cache[$payment_id][$meta_key])) {
unset($_web_invoice_payment_meta_cache[$payment_id][$meta_key]);
}
}
function web_invoice_delete($invoice_id) {
global $wpdb;
// Check to see if array is passed or single.
if(is_array($invoice_id))
{
$counter=0;
foreach ($invoice_id as $single_invoice_id) {
$counter++;
if (web_invoice_meta($single_invoice_id, 'subscription_id') && web_invoice_meta($single_invoice_id, 'recurring_transaction_id')) {
require_once('gateways/payflowpro.class.php');
$pfp = new Web_Invoice_PayflowProRecurring();
$pfp->deleteProfile(web_invoice_meta($single_invoice_id, 'subscription_id'));
}
$wpdb->query("DELETE FROM ".Web_Invoice::tablename('main')." WHERE invoice_num = '$single_invoice_id'");
do_action('web_invoice_delete', $single_invoice_id);
web_invoice_update_log($single_invoice_id, "deleted", "Deleted on ");
// Get all meta keys for this invoice, then delete them
$all_invoice_meta_values = $wpdb->get_col("SELECT invoice_id FROM ".Web_Invoice::tablename('meta')." WHERE invoice_id = '$single_invoice_id'");
foreach ($all_invoice_meta_values as $meta_key) {
web_invoice_delete_invoice_meta($single_invoice_id);
}
}
return $counter . " invoice(s) successfully deleted.";
} else {
if (web_invoice_meta($single_invoice_id, 'subscription_id') && web_invoice_meta($single_invoice_id, 'recurring_transaction_id')) {
require_once('gateways/payflowpro.class.php');
$pfp = new Web_Invoice_PayflowProRecurring();
if ($pfp->deleteProfile(web_invoice_meta($single_invoice_id, 'subscription_id'))) {
web_invoice_delete_invoice_meta($single_invoice_id, 'subscription_id');
web_invoice_update_log($invoice_id, 'pfp_subscription_update', "Subscription cancelled. REF: ".$pfp->getRef());
}
}
// Delete Single
$wpdb->query("DELETE FROM ".Web_Invoice::tablename('main')." WHERE invoice_num = '$invoice_id'");
// Make log entry
do_action('web_invoice_delete', $invoice_id);
web_invoice_update_log($invoice_id, "deleted", "Deleted on ");
$all_invoice_meta_values = $wpdb->get_col("SELECT invoice_id FROM ".Web_Invoice::tablename('meta')." WHERE invoice_id = '$single_invoice_id'");
foreach ($all_invoice_meta_values as $meta_key) {
web_invoice_delete_invoice_meta($single_invoice_id);
}
return "Invoice successfully deleted.";
}
}
function web_invoice_archive($invoice_id) {
global $wpdb;
// Check to see if array is passed or single.
if(is_array($invoice_id))
{
$counter=0;
foreach ($invoice_id as $single_invoice_id) {
$counter++;
web_invoice_update_invoice_meta($single_invoice_id, "archive_status", "archived");
}
return $counter . " invoice(s) archived.";
}
else
{
web_invoice_update_invoice_meta($invoice_id, "archive_status", "archived");
return "Invoice successfully archived.";
}
}
function web_invoice_mark_as_paid($invoice_id) {
global $wpdb;
$counter=0;
// Check to see if array is passed or single.
if(is_array($invoice_id))
{
foreach ($invoice_id as $single_invoice_id) {
$counter++;
web_invoice_update_invoice_meta($single_invoice_id,'paid_status','paid');
web_invoice_update_log($single_invoice_id,'paid',"Invoice marked as paid");
if (web_invoice_recurring($single_invoice_id)) {
web_invoice_update_invoice_meta(
$single_invoice_id,'installment',
web_invoice_meta($single_invoice_id,'installment',0)+1
);
}
if(get_option('web_invoice_send_thank_you_email') == 'yes') web_invoice_send_email_receipt($single_invoice_id);
do_action('web_invoice_mark_as_paid', $single_invoice_id);
}
if(get_option('web_invoice_send_thank_you_email') == 'yes') {
return $counter . " invoice(s) marked as paid, and thank you email sent to customer.";
}
else{
return $counter . " invoice(s) marked as paid.";
}
}
else
{
$counter++;
web_invoice_update_invoice_meta($invoice_id,'paid_status','paid');
web_invoice_update_log($invoice_id,'paid',"Invoice marked as paid");
if (web_invoice_recurring($invoice_id)) {
web_invoice_update_invoice_meta(
$invoice_id,'installment',
web_invoice_meta($invoice_id,'installment',0)+1
);
}
if(get_option('web_invoice_send_thank_you_email') == 'yes') web_invoice_send_email_receipt($invoice_id);
do_action('web_invoice_mark_as_paid', $invoice_id);
if(get_option('web_invoice_send_thank_you_email') == 'yes') {
return $counter . " invoice marked as paid, and thank you email sent to customer.";
}
else{
return $counter . " invoice marked as paid.";
}
}
}
function web_invoice_mark_as_cancelled($invoice_id) {
global $wpdb;
$counter=0;
// Check to see if array is passed or single.
if(is_array($invoice_id))
{
foreach ($invoice_id as $single_invoice_id) {
if (!web_invoice_paid_status($single_invoice_id)) continue;
$counter++;
web_invoice_update_invoice_meta($single_invoice_id,'paid_status','cancelled');
web_invoice_update_log($single_invoice_id,'paid',"Invoice marked as cancelled");
do_action('web_invoice_mark_as_cancel', $single_invoice_id);
}
return $counter . " invoice(s) marked as cancelled.";
}
else
{
if (web_invoice_paid_status($single_invoice_id)) {
$counter++;
web_invoice_update_invoice_meta($invoice_id,'paid_status','cancelled');
web_invoice_update_log($invoice_id,'paid',"Invoice marked as cancelled");
do_action('web_invoice_mark_as_cancel', $invoice_id);
return $counter . " invoice marked as cancelled.";
} else {
return "No invoices marked as cancelled.";
}
}
}
function web_invoice_unarchive($invoice_id) {
global $wpdb;
// Check to see if array is passed or single.
if(is_array($invoice_id))
{
$counter=0;
foreach ($invoice_id as $single_invoice_id) {
$counter++;
web_invoice_delete_invoice_meta($single_invoice_id, "archive_status");
}
return $counter . " invoice(s) unarchived.";
}
else
{
web_invoice_delete_invoice_meta($invoice_id, "archive_status");
return "Invoice successfully unarchived.";
}
}
function web_invoice_mark_as_sent($invoice_id) {
global $wpdb;
// Check to see if array is passed or single.
if(is_array($invoice_id))
{
$counter=0;
foreach ($invoice_id as $single_invoice_id) {
$counter++;
web_invoice_update_invoice_meta($single_invoice_id, "sent_date", date("Y-m-d", time()));
web_invoice_update_log($single_invoice_id,'contact','Invoice Maked as eMailed'); //make sent entry
}
return $counter . " invoice(s) marked as sent.";
}
else
{
web_invoice_update_invoice_meta($invoice_id, "sent_date", date("Y-m-d", time()));
web_invoice_update_log($invoice_id,'contact','Invoice Maked as eMailed'); //make sent entry
return "Invoice market as sent.";
}
}
function web_invoice_get_invoice_attrib($invoice_id,$attribute)
{
global $wpdb;
$query = "SELECT $attribute FROM ".Web_Invoice::tablename('main')." WHERE invoice_num=".$invoice_id."";
return $wpdb->get_var($query);
}
function web_invoice_get_invoice_status($invoice_id,$count='1')
{
if($invoice_id != '') {
global $wpdb;
$query = "SELECT * FROM ".Web_Invoice::tablename('log')."
WHERE invoice_id = $invoice_id
ORDER BY time_stamp DESC
LIMIT 0 , $count";
$status_update = $wpdb->get_results($query);
foreach ($status_update as $single_status)
{
$message .= "<li>" . $single_status->value . " on <span class='web_invoice_tamp_stamp'>" . date(__('Y-m-d H:i:s'), strtotime($single_status->time_stamp)) . "</span></li>";
}
return $message;
}
}
function web_invoice_clear_invoice_status($invoice_id)
{
global $wpdb;
if(isset($invoice_id)) {
if($wpdb->query("DELETE FROM ".Web_Invoice::tablename('log')." WHERE invoice_id = $invoice_id"))
return "Logs for invoice #$invoice_id cleared.";
}
}
function web_invoice_get_single_invoice_status($invoice_id)
{
// in class
global $wpdb;
if($status_update = $wpdb->get_row("SELECT * FROM ".Web_Invoice::tablename('log')." WHERE invoice_id = $invoice_id ORDER BY `".Web_Invoice::tablename('log')."`.`time_stamp` DESC LIMIT 0 , 1"))
return $status_update->value . " - " . web_invoice_Date::convert($status_update->time_stamp, 'Y-m-d H', __('M d Y'));
}
function web_invoice_paid($invoice_id) {
global $wpdb;
//$wpdb->query("UPDATE ".Web_Invoice::tablename('main')." SET status = 1 WHERE invoice_num = '$invoice_id'");
web_invoice_update_invoice_meta($invoice_id,'paid_status','paid');
web_invoice_update_log($invoice_id,'paid',"Invoice successfully processed by ". $_SERVER['REMOTE_ADDR']);
}
function web_invoice_email_variables($invoice_id) {
global $web_invoices_email_variables;
$invoice_info = new Web_Invoice_GetInfo($invoice_id);
$recipient = new Web_Invoice_GetInfo($invoice_id);
$web_invoices_email_variables = array(
'call_sign' => $recipient->recipient('callsign'),
'streetaddress' => $recipient->recipient('streetaddress'),
'city' => $recipient->recipient('city'),
'zip' => $recipient->recipient('zip'),
'state' => $recipient->recipient('state'),
'country' => $recipient->recipient('country'),
'business_name' => stripslashes(get_option("web_invoice_business_name")),
'recurring' => (web_invoice_recurring($invoice_id) ? " recurring " : ""),
'amount' => $invoice_info->display('display_amount'),
'link' => $invoice_info->display('link'),
'business_email' => get_option("web_invoice_email_address"),
'subject' => $invoice_info->display('subject'),
'invoice_id' => $invoice_info->display('display_id'),
'invoice_hash' => $invoice_info->display('invoice_hash'),
'invoice_date' => $invoice_info->display('invoice_date'),
'due_date' => $invoice_info->display('due_date'),
);
if($invoice_info->display('description')) {
$web_invoices_email_variables['description'] = $invoice_info->display('description').".";
} else {
$web_invoices_email_variables['description'] = "";
}
}
function web_invoice_pdf_variables($invoice_id) {
global $web_invoices_pdf_variables;
$invoice_info = new Web_Invoice_GetInfo($invoice_id);
$recipient = new Web_Invoice_GetInfo($invoice_id);
$web_invoices_pdf_variables = array(
'call_sign' => $recipient->recipient('callsign'),
'streetaddress' => $recipient->recipient('streetaddress'),
'city' => $recipient->recipient('city'),
'zip' => $recipient->recipient('zip'),
'state' => $recipient->recipient('state'),
'country' => $recipient->recipient('country'),
'business_name' => stripslashes(get_option("web_invoice_business_name")),
'recurring' => (web_invoice_recurring($invoice_id) ? " recurring " : ""),
'amount' => $invoice_info->display('display_amount'),
'link' => $invoice_info->display('link'),
'business_email' => get_option("web_invoice_email_address"),
'subject' => $invoice_info->display('subject'),
'invoice_id' => $invoice_info->display('display_id'),
'invoice_hash' => $invoice_info->display('invoice_hash'),
'content' => web_invoice_generate_pdf_content($invoice_id),
'invoice_date' => $invoice_info->display('invoice_date'),
'due_date' => $invoice_info->display('due_date'),
);
if($invoice_info->display('description')) {
$web_invoices_pdf_variables['description'] = $invoice_info->display('description').".";
} else {
$web_invoices_pdf_variables['description'] = "";
}
}
function web_invoice_html_variables($invoice_id) {
global $web_invoices_html_variables;
$invoice_info = new Web_Invoice_GetInfo($invoice_id);
$recipient = new Web_Invoice_GetInfo($invoice_id);
$web_invoices_html_variables = array(
'call_sign' => $recipient->recipient('callsign'),
'streetaddress' => $recipient->recipient('streetaddress'),
'city' => $recipient->recipient('city'),
'zip' => $recipient->recipient('zip'),
'state' => $recipient->recipient('state'),
'country' => $recipient->recipient('country'),
'business_name' => stripslashes(get_option("web_invoice_business_name")),
'recurring' => (web_invoice_recurring($invoice_id) ? " recurring " : ""),
'amount' => $invoice_info->display('display_amount'),
'link' => $invoice_info->display('link'),
'business_email' => get_option("web_invoice_email_address"),
'subject' => $invoice_info->display('subject'),
'invoice_id' => $invoice_info->display('display_id'),
'invoice_hash' => $invoice_info->display('invoice_hash'),
'content' => web_invoice_generate_html_content($invoice_id),
'print_message' => sprintf(__("You can download a %s or print a copy of this invoice for your records; just
select the 'Print' item under the 'File' menu in your browser, or use the
<CTRL> + 'P' key combination to print a hard-copy in a more traditional,
neatly laid-out format. <em>Thank you</em> for your business <em>and</em> your prompt
payment!", WEB_INVOICE_TRANS_DOMAIN), '<a href="'.$invoice_info->display('print_link').'" class="web_invoice_pdf_link">PDF</a>'),
'pdf_link' => $invoice_info->display('print_link'),
'invoice_date' => $invoice_info->display('invoice_date'),
'due_date' => $invoice_info->display('due_date'),
);
if($invoice_info->display('description')) {
$web_invoices_html_variables['description'] = $invoice_info->display('description').".";
} else {
$web_invoices_html_variables['description'] = "";
}
}
function web_invoice_web_variables($invoice_id) {
global $web_invoices_web_variables;
$invoice_info = new Web_Invoice_GetInfo($invoice_id);
$recipient = new Web_Invoice_GetInfo($invoice_id);
$web_invoices_web_variables = array(
'call_sign' => $recipient->recipient('callsign'),
'streetaddress' => $recipient->recipient('streetaddress'),
'city' => $recipient->recipient('city'),
'zip' => $recipient->recipient('zip'),
'state' => $recipient->recipient('state'),
'country' => $recipient->recipient('country'),
'business_name' => stripslashes(get_option("web_invoice_business_name")),
'recurring' => (web_invoice_recurring($invoice_id) ? " recurring " : ""),
'amount' => $invoice_info->display('display_amount'),
'link' => $invoice_info->display('link'),
'business_email' => get_option("web_invoice_email_address"),
'subject' => $invoice_info->display('subject'),
'invoice_id' => $invoice_info->display('display_id'),
'invoice_hash' => $invoice_info->display('invoice_hash'),
'invoice_date' => $invoice_info->display('invoice_date'),
'due_date' => $invoice_info->display('due_date'),
);
if($invoice_info->display('description')) {
$web_invoices_web_variables['description'] = $invoice_info->display('description').".";
} else {
$web_invoices_web_variables['description'] = "";
}
}
function web_invoice_email_apply_variables($matches) {
global $web_invoices_email_variables;
if (isset($web_invoices_email_variables[$matches[2]])) {
return $web_invoices_email_variables[$matches[2]];
}
return $matches[2];
}
function web_invoice_web_apply_variables($matches) {
global $web_invoices_web_variables;
if (isset($web_invoices_web_variables[$matches[2]])) {
return $web_invoices_web_variables[$matches[2]];
}
return $matches[2];
}
function web_invoice_pdf_apply_variables($matches) {
global $web_invoices_pdf_variables;
if (isset($web_invoices_pdf_variables[$matches[2]])) {
return $web_invoices_pdf_variables[$matches[2]];
}
return $matches[2];
}
function web_invoice_html_apply_variables($matches) {
global $web_invoices_html_variables;
if (isset($web_invoices_html_variables[$matches[2]])) {
return $web_invoices_html_variables[$matches[2]];
}
return $matches[2];
}
function web_invoice_show_email($invoice_id) {
apply_filters('web_invoice_email_variables', $invoice_id);
return preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_email_apply_variables', get_option('web_invoice_email_send_invoice_content'));
}
function web_invoice_show_reminder_email($invoice_id) {
apply_filters('web_invoice_email_variables', $invoice_id);
return preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_email_apply_variables', get_option('web_invoice_email_send_reminder_content'));
}
function web_invoice_show_receipt_email($invoice_id) {
apply_filters('web_invoice_email_variables', $invoice_id);
return preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_email_apply_variables', get_option('web_invoice_email_send_receipt_content'));
}
function web_invoice_generate_pdf($invoice_id) {
global $web_invoice;
apply_filters('web_invoice_pdf_variables', $invoice_id);
return preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_pdf_apply_variables',
stripslashes(get_option('web_invoice_pdf_content', "<html>
<head>
<title>Invoice</title>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
</head>
<body>
<div id='invoice_page' class='clearfix'>
<img style='float: right;' src='".$web_invoice->the_path."/images/logo_small_padding.png' style='width:420px; height: 110px;' />
<h1>Invoice</h1>
%content
</div>
</body>
</html>")));
}
function web_invoice_generate_html($invoice_id) {
apply_filters('web_invoice_html_variables', $invoice_id);
return preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_html_apply_variables',
stripslashes(get_option('web_invoice_html_content', '<div id="invoice_page" class="clearfix"><div class="noprint"><p>%print_message</p></div>%content</div>')));
}
function web_invoice_send_email_receipt($invoice_id) {
global $wpdb;
$invoice_info = new Web_Invoice_GetInfo($invoice_id);
$message = web_invoice_show_receipt_email($invoice_id);
$from = strip_tags(stripslashes(get_option("web_invoice_email_address")));
$from_name = strip_tags(stripslashes(get_option("web_invoice_business_name")));
$headers = "From: {$from_name} <{$from}>\r\n";
if (get_option('web_invoice_cc_thank_you_email') == 'yes') {
$headers .= "Bcc: {$from}\r\n";
}
$message = web_invoice_show_receipt_email($invoice_id);
$subject = strip_tags(preg_replace_callback('/(%([a-z_]+))/', 'web_invoice_email_apply_variables', get_option('web_invoice_email_send_receipt_subject')));
if(wp_mail($invoice_info->recipient('email_address'), $subject, $message, $headers))
{ web_invoice_update_log($invoice_id,'contact','Receipt eMailed'); }
return $message;
}
function web_invoice_recurring($invoice_id) {
global $wpdb;
if(web_invoice_meta($invoice_id,'web_invoice_recurring_billing')) return true;
}
function web_invoice_recurring_started($invoice_id) {
global $wpdb;
if(web_invoice_meta($invoice_id,'subscription_id')) return true;
}
function web_invoice_paid_status($invoice_id) {
//Merged with paid_status in class
global $wpdb;
$invoice_info = new Web_Invoice_GetInfo($invoice_id);
if(!empty($invoice_id) && web_invoice_meta($invoice_id,'paid_status')) return web_invoice_meta($invoice_id,'paid_status');
if ($invoice_info && $invoice_info->display('status')) return $invoice_info->display('status');
}
function web_invoice_paid_date($invoice_id) {
// in invoice class
global $wpdb;
return $wpdb->get_var("SELECT time_stamp FROM ".Web_Invoice::tablename('log')." WHERE action_type = 'paid' AND invoice_id = '".$invoice_id."' ORDER BY time_stamp DESC LIMIT 0, 1");
}
function web_invoice_build_invoice_link($invoice_id) {
// in invoice class
global $wpdb;
$link_to_page = get_permalink(get_option('web_invoice_web_invoice_page'));
$hashed_invoice_id = md5($invoice_id);
if(get_option("permalink_structure")) { $link = $link_to_page . "?invoice_id=" .$hashed_invoice_id; }
else { $link = $link_to_page . "&invoice_id=" . $hashed_invoice_id; }
return $link;
}
function web_invoice_build_invoice_link_paypal($invoice_id) {
// in invoice class
global $wpdb;
$link_to_page = get_permalink(get_option('web_invoice_web_invoice_page'));
if(get_option("permalink_structure")) {
$link = $link_to_page . "?paypal_ipn=1";
} else {
$link = $link_to_page . "&paypal_ipn=1";
}
return $link;
}
function web_invoice_draw_inputfield($name,$value,$special = '') {
return "<input id='$name' class='$name' name='$name' value='$value' $special />";
}
function web_invoice_draw_select($name,$values,$current_value = '', $id=null) {
if ($id == null) {
$id = $name;
}
$output = "<select id='$id' name='$name' class='$name'>";
$output .= "<option></option>";
foreach($values as $key => $value) {
$output .= "<option value='$key'";
if($key == $current_value) $output .= " selected='selected'";
if (is_array($value)) {
$output .= ">{$value[0]}</option>";
} else {
$output .= ">$value</option>";
}
}
$output .= "</select>";
return $output;
}
function web_invoice_format_phone($phone)
{
$phone = preg_replace("/[^0-9]/", "", $phone);
if(strlen($phone) == 7)
return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
elseif(strlen($phone) == 10)
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
else
return $phone;
}
function web_invoice_complete_removal()
{
// Run regular deactivation, but also delete the main table - all invoice data is gone
global $wpdb;
$web_invoice = new Web_Invoice();
$web_invoice->uninstall();
$wpdb->query("DROP TABLE " . Web_Invoice::tablename('log') .";");
$wpdb->query("DROP TABLE " . Web_Invoice::tablename('main') .";");
$wpdb->query("DROP TABLE " . Web_Invoice::tablename('meta') .";");
$wpdb->query("DROP TABLE " . Web_Invoice::tablename('payment') .";");
$wpdb->query("DROP TABLE " . Web_Invoice::tablename('payment_meta') .";");
delete_option('web_invoice_version');
delete_option('web_invoice_payment_link');
delete_option('web_invoice_payment_method');
delete_option('web_invoice_protocol');
delete_option('web_invoice_email_address');
delete_option('web_invoice_business_name');
delete_option('web_invoice_business_address');
delete_option('web_invoice_business_phone');
delete_option('web_invoice_business_tax_id');
delete_option('web_invoice_default_currency_code');
delete_option('web_invoice_web_invoice_page');
delete_option('web_invoice_redirect_after_user_add');
delete_option('web_invoice_tax_count');
delete_option('web_invoice_tax_name');
delete_option('web_invoice_self_generate_from_template');
delete_option('web_invoice_partial_payments');
delete_option('web_invoice_billing_meta');
delete_option('web_invoice_show_billing_address');
delete_option('web_invoice_show_quantities');
delete_option('web_invoice_show_invoice_date');
delete_option('web_invoice_use_css');
delete_option('web_invoice_hide_page_title');
delete_option('web_invoice_send_thank_you_email');
delete_option('web_invoice_cc_thank_you_email');
delete_option('web_invoice_reminder_message');
//Gateway Settings
delete_option('web_invoice_gateway_username');
delete_option('web_invoice_gateway_tran_key');
delete_option('web_invoice_gateway_delim_char');
delete_option('web_invoice_gateway_encap_char');
delete_option('web_invoice_gateway_merchant_email');
delete_option('web_invoice_gateway_header_email_receipt');
delete_option('web_invoice_gateway_url');
delete_option('web_invoice_recurring_gateway_url');
delete_option('web_invoice_gateway_MD5Hash');
delete_option('web_invoice_gateway_test_mode');
delete_option('web_invoice_gateway_delim_data');
delete_option('web_invoice_gateway_relay_response');
delete_option('web_invoice_gateway_email_customer');
// PayPal
delete_option('web_invoice_paypal_button');
delete_option('web_invoice_paypal_address');
delete_option('web_invoice_paypal_only_button');
delete_option('web_invoice_paypal_sandbox');
// Payflow
delete_option('web_invoice_payflow_button');
delete_option('web_invoice_payflow_login');
delete_option('web_invoice_payflow_partner');
delete_option('web_invoice_payflow_only_button');
delete_option('web_invoice_payflow_shipping_details');
delete_option('web_invoice_payflow_silent_post');
// Payflow Pro
delete_option('web_invoice_pfp_partner');
delete_option('web_invoice_pfp_env');
delete_option('web_invoice_pfp_authentication');
delete_option('web_invoice_pfp_username');
delete_option('web_invoice_pfp_password');
delete_option('web_invoice_pfp_signature');
delete_option('web_invoice_pfp_wpppe_vendor');
delete_option('web_invoice_pfp_wpppe_username');
delete_option('web_invoice_pfp_wpppe_password');
delete_option('web_invoice_pfp_3rdparty_email');
delete_option('web_invoice_pfp_shipping_details');
// Other
delete_option('web_invoice_other_details');
// Moneybookers
delete_option('web_invoice_moneybookers_button');
delete_option('web_invoice_moneybookers_address');
delete_option('web_invoice_moneybookers_recurring_address');
delete_option('web_invoice_moneybookers_merchant');
delete_option('web_invoice_moneybookers_secret');
delete_option('web_invoice_moneybookers_ip');
// AlertPay
delete_option('web_invoice_alertpay_button');
delete_option('web_invoice_alertpay_address');
delete_option('web_invoice_alertpay_merchant');
delete_option('web_invoice_alertpay_secret');
delete_option('web_invoice_alertpay_test_mode');
delete_option('web_invoice_alertpay_ip');
// 2CO
delete_option('web_invoice_2co_button');
delete_option('web_invoice_2co_sid');
delete_option('web_invoice_2co_secret_word');
delete_option('web_invoice_2co_demo_mode');
// Google Checkout
delete_option('web_invoice_google_checkout_button');
delete_option('web_invoice_google_checkout_env');
delete_option('web_invoice_google_checkout_merchant_id');
delete_option('web_invoice_google_checkout_level2');
delete_option('web_invoice_google_checkout_merchant_key');
delete_option('web_invoice_google_checkout_tax_state');
// Sage Pay
delete_option('web_invoice_sagepay_button');
delete_option('web_invoice_sagepay_env');
delete_option('web_invoice_sagepay_vendor_name');
delete_option('web_invoice_sagepay_vendor_key');
delete_option('web_invoice_sagepay_shipping_details');
// Send invoice
delete_option('web_invoice_email_send_invoice_subject');
delete_option('web_invoice_email_send_invoice_content');
// Send reminder
delete_option('web_invoice_email_send_reminder_subject');
delete_option('web_invoice_email_send_reminder_content');
// Send receipt
delete_option('web_invoice_email_send_receipt_subject');
delete_option('web_invoice_email_send_receipt_content');
// PDF
delete_option('web_invoice_pdf_content');
// HTML
delete_option('web_invoice_html_content');
// Currency