-
Notifications
You must be signed in to change notification settings - Fork 0
/
payer.php
3119 lines (2532 loc) · 162 KB
/
payer.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
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
/*
Plugin Name: Gravity Forms Payer Add-On
Plugin URI: http://www.gravityforms.com
Description: Integrates Gravity Forms with Payer, enabling end users to purchase goods and services through Gravity Forms.
Version: 1.0
Author: christianbolstad
Author URI: http://www.hippies.se
------------------------------------------------------------------------
Copyright 2012, 2009 Christian Bolstad, rocketgenius
last updated: November 11, 2012
Based on Gravity Forms Paypal Add-On by rocketgenius
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; either version 2 of the License, or
(at your option) any later version.
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
*/
add_action('parse_request', array("GFPayPal", "process_ipn"));
add_action('wp', array('GFPayPal', 'maybe_thankyou_page'), 5);
add_action('init', array('GFPayPal', 'init'));
register_activation_hook( __FILE__, array("GFPayPal", "add_permissions"));
class GFPayPal {
private static $path = "hip-gravityformspayer/payer.php";
private static $url = "http://www.gravityforms.com";
private static $slug = "hip-gravityformspayer";
private static $version = "1.0";
private static $min_gravityforms_version = "1.6.4";
private static $production_url = "https://www.paypal.com/cgi-bin/webscr/";
private static $sandbox_url = "https://www.sandbox.paypal.com/cgi-bin/webscr/";
private static $supported_fields = array("checkbox", "radio", "select", "text", "website", "textarea", "email", "hidden", "number", "phone", "multiselect", "post_title",
"post_tags", "post_custom_field", "post_content", "post_excerpt");
//Plugin starting point. Will load appropriate files
public static function init(){
//supports logging
add_filter("gform_logging_supported", array("GFPayPal", "set_logging_supported"));
if(basename($_SERVER['PHP_SELF']) == "plugins.php") {
//loading translations
load_plugin_textdomain('gravityformspayer', FALSE, '/hip-gravityformspayer/languages' );
add_action('after_plugin_row_' . self::$path, array('GFPayPal', 'plugin_row') );
//force new remote request for version info on the plugin page
self::flush_version_info();
}
if(!self::is_gravityforms_supported())
return;
if(is_admin()){
//loading translations
load_plugin_textdomain('gravityformspayer', FALSE, '/hip-gravityformspayer/languages' );
//automatic upgrade hooks
add_filter("transient_update_plugins", array('GFPayPal', 'check_update'));
add_filter("site_transient_update_plugins", array('GFPayPal', 'check_update'));
add_action('install_plugins_pre_plugin-information', array('GFPayPal', 'display_changelog'));
//integrating with Members plugin
if(function_exists('members_get_capabilities'))
add_filter('members_get_capabilities', array("GFPayPal", "members_get_capabilities"));
//creates the subnav left menu
add_filter("gform_addon_navigation", array('GFPayPal', 'create_menu'));
//add actions to allow the payment status to be modified
add_action('gform_payment_status', array('GFPayPal','admin_edit_payment_status'), 3, 3);
add_action('gform_entry_info', array('GFPayPal','admin_edit_payment_status_details'), 4, 2);
add_action('gform_after_update_entry', array('GFPayPal','admin_update_payment'), 4, 2);
//loading Gravity Forms tooltips
require_once(GFCommon::get_base_path() . "/tooltips.php");
add_filter('gform_tooltips', array('GFPayPal', 'tooltips'));
if(self::is_paypal_page()){
//enqueueing sack for AJAX requests
wp_enqueue_script(array("sack"));
//loading data lib
require_once(self::get_base_path() . "/data.php");
//loading upgrade lib
if(!class_exists("RGPayPalUpgrade"))
require_once("plugin-upgrade.php");
//runs the setup when version changes
self::setup();
}
else if(in_array(RG_CURRENT_PAGE, array("admin-ajax.php"))){
//loading data class
require_once(self::get_base_path() . "/data.php");
add_action('wp_ajax_gf_paypal_update_feed_active', array('GFPayPal', 'update_feed_active'));
add_action('wp_ajax_gf_select_paypal_form', array('GFPayPal', 'select_paypal_form'));
add_action('wp_ajax_gf_paypal_confirm_settings', array('GFPayPal', 'confirm_settings'));
}
else if(RGForms::get("page") == "gf_settings"){
RGForms::add_settings_page("PayPal", array("GFPayPal", "settings_page"), self::get_base_url() . "/images/paypal_wordpress_icon_32.png");
}
}
else{
//loading data class
require_once(self::get_base_path() . "/data.php");
//handling post submission.
add_filter("gform_confirmation", array("GFPayPal", "send_to_paypal"), 1000, 4);
//setting some entry metas
add_action("gform_after_submission", array("GFPayPal", "set_entry_meta"), 5, 2);
add_filter("gform_disable_post_creation", array("GFPayPal", "delay_post"), 10, 3);
add_filter("gform_disable_user_notification", array("GFPayPal", "delay_autoresponder"), 10, 3);
add_filter("gform_disable_admin_notification", array("GFPayPal", "delay_notification"), 10, 3);
// ManageWP premium update filters
add_filter( 'mwp_premium_update_notification', array('GFPayPal', 'premium_update_push') );
add_filter( 'mwp_premium_perform_update', array('GFPayPal', 'premium_update') );
}
}
public static function update_feed_active(){
check_ajax_referer('gf_paypal_update_feed_active','gf_paypal_update_feed_active');
$id = $_POST["feed_id"];
$feed = GFPayPalData::get_feed($id);
GFPayPalData::update_feed($id, $feed["form_id"], $_POST["is_active"], $feed["meta"]);
}
//-------------- Automatic upgrade ---------------------------------------
//Integration with ManageWP
public static function premium_update_push( $premium_update ){
if( !function_exists( 'get_plugin_data' ) )
include_once( ABSPATH.'wp-admin/includes/plugin.php');
$update = GFCommon::get_version_info();
if( $update["is_valid_key"] == true && version_compare(self::$version, $update["version"], '<') ){
$plugin_data = get_plugin_data( __FILE__ );
$plugin_data['type'] = 'plugin';
$plugin_data['slug'] = self::$path;
$plugin_data['new_version'] = isset($update['version']) ? $update['version'] : false ;
$premium_update[] = $plugin_data;
}
return $premium_update;
}
//Integration with ManageWP
public static function premium_update( $premium_update ){
if( !function_exists( 'get_plugin_data' ) )
include_once( ABSPATH.'wp-admin/includes/plugin.php');
$update = GFCommon::get_version_info();
if( $update["is_valid_key"] == true && version_compare(self::$version, $update["version"], '<') ){
$plugin_data = get_plugin_data( __FILE__ );
$plugin_data['slug'] = self::$path;
$plugin_data['type'] = 'plugin';
$plugin_data['url'] = isset($update["url"]) ? $update["url"] : false; // OR provide your own callback function for managing the update
array_push($premium_update, $plugin_data);
}
return $premium_update;
}
public static function flush_version_info(){
if(!class_exists("RGPayPalUpgrade"))
require_once("plugin-upgrade.php");
RGPayPalUpgrade::set_version_info(false);
}
public static function plugin_row(){
if(!self::is_gravityforms_supported()){
$message = sprintf(__("Gravity Forms " . self::$min_gravityforms_version . " is required. Activate it now or %spurchase it today!%s", "gravityformspaypal"), "<a href='http://www.gravityforms.com'>", "</a>");
RGPayPalUpgrade::display_plugin_message($message, true);
}
else{
$version_info = RGPayPalUpgrade::get_version_info(self::$slug, self::get_key(), self::$version);
if(!$version_info["is_valid_key"]){
$new_version = version_compare(self::$version, $version_info["version"], '<') ? __('There is a new version of Gravity Forms PayPal Add-On available.', 'gravityformspaypal') .' <a class="thickbox" title="Gravity Forms PayPal Add-On" href="plugin-install.php?tab=plugin-information&plugin=' . self::$slug . '&TB_iframe=true&width=640&height=808">'. sprintf(__('View version %s Details', 'gravityformspaypal'), $version_info["version"]) . '</a>. ' : '';
$message = $new_version . sprintf(__('%sRegister%s your copy of Gravity Forms to receive access to automatic upgrades and support. Need a license key? %sPurchase one now%s.', 'gravityformspaypal'), '<a href="admin.php?page=gf_settings">', '</a>', '<a href="http://www.gravityforms.com">', '</a>') . '</div></td>';
RGPayPalUpgrade::display_plugin_message($message);
}
}
}
//Displays current version details on Plugin's page
public static function display_changelog(){
if($_REQUEST["plugin"] != self::$slug)
return;
//loading upgrade lib
if(!class_exists("RGPayPalUpgrade"))
require_once("plugin-upgrade.php");
RGPayPalUpgrade::display_changelog(self::$slug, self::get_key(), self::$version);
}
public static function check_update($update_plugins_option){
if(!class_exists("RGPayPalUpgrade"))
require_once("plugin-upgrade.php");
return RGPayPalUpgrade::check_update(self::$path, self::$slug, self::$url, self::$slug, self::get_key(), self::$version, $update_plugins_option);
}
private static function get_key(){
if(self::is_gravityforms_supported())
return GFCommon::get_key();
else
return "";
}
//------------------------------------------------------------------------
//Creates PayPal left nav menu under Forms
public static function create_menu($menus){
// Adding submenu if user has access
$permission = self::has_access("gravityforms_paypal");
if(!empty($permission))
$menus[] = array("name" => "gf_paypal", "label" => __("Payer", "gravityformspaypal"), "callback" => array("GFPayPal", "paypal_page"), "permission" => $permission);
return $menus;
}
//Creates or updates database tables. Will only run when version changes
private static function setup(){
if(get_option("gf_paypal_version") != self::$version)
GFPayPalData::update_table();
update_option("gf_paypal_version", self::$version);
}
//Adds feed tooltips to the list of tooltips
public static function tooltips($tooltips){
$paypal_tooltips = array(
"paypal_email_address" => "<h6>" . __("PayPal Email Address", "gravityformspaypal") . "</h6>" . __("Enter the PayPal email address where payment should be received.", "gravityformspaypal"),
"paypal_mode" => "<h6>" . __("Mode", "gravityformspaypal") . "</h6>" . __("Select Production to receive live payments. Select Test for testing purposes when using the PayPal development sandbox.", "gravityformspaypal"),
"paypal_transaction_type" => "<h6>" . __("Transaction Type", "gravityformspaypal") . "</h6>" . __("Select which PayPal transaction type should be used. Products and Services, Donations or Subscription.", "gravityformspaypal"),
"paypal_gravity_form" => "<h6>" . __("Gravity Form", "gravityformspaypal") . "</h6>" . __("Select which Gravity Forms you would like to integrate with PayPal.", "gravityformspaypal"),
"paypal_customer" => "<h6>" . __("Customer", "gravityformspaypal") . "</h6>" . __("Map your Form Fields to the available PayPal customer information fields.", "gravityformspaypal"),
"paypal_page_style" => "<h6>" . __("Page Style", "gravityformspaypal") . "</h6>" . __("This option allows you to select which PayPal page style should be used if you have setup a custom payment page style with PayPal.", "gravityformspaypal"),
"paypal_continue_button_label" => "<h6>" . __("Continue Button Label", "gravityformspaypal") . "</h6>" . __("Enter the text that should appear on the continue button once payment has been completed via PayPal.", "gravityformspaypal"),
"paypal_cancel_url" => "<h6>" . __("Cancel URL", "gravityformspaypal") . "</h6>" . __("Enter the URL the user should be sent to should they cancel before completing their PayPal payment.", "gravityformspaypal"),
"paypal_options" => "<h6>" . __("Options", "gravityformspaypal") . "</h6>" . __("Turn on or off the available PayPal checkout options.", "gravityformspaypal"),
"paypal_recurring_amount" => "<h6>" . __("Recurring Amount", "gravityformspaypal") . "</h6>" . __("Select which field determines the recurring payment amount, or select 'Form Total' to use the total of all pricing fields as the recurring amount.", "gravityformspaypal"),
"paypal_billing_cycle" => "<h6>" . __("Billing Cycle", "gravityformspaypal") . "</h6>" . __("Select your billing cycle. This determines how often the recurring payment should occur.", "gravityformspaypal"),
"paypal_recurring_times" => "<h6>" . __("Recurring Times", "gravityformspaypal") . "</h6>" . __("Select how many times the recurring payment should be made. The default is to bill the customer until the subscription is canceled.", "gravityformspaypal"),
"paypal_trial_period_enable" => "<h6>" . __("Trial Period", "gravityformspaypal") . "</h6>" . __("Enable a trial period. The users recurring payment will not begin until after this trial period.", "gravityformspaypal"),
"paypal_trial_amount" => "<h6>" . __("Trial Amount", "gravityformspaypal") . "</h6>" . __("Enter the trial period amount or leave it blank for a free trial.", "gravityformspaypal"),
"paypal_trial_period" => "<h6>" . __("Trial Period", "gravityformspaypal") . "</h6>" . __("Select the trial period length.", "gravityformspaypal"),
"paypal_conditional" => "<h6>" . __("PayPal Condition", "gravityformspaypal") . "</h6>" . __("When the PayPal condition is enabled, form submissions will only be sent to PayPal when the condition is met. When disabled all form submissions will be sent to PayPal.", "gravityformspaypal"),
"paypal_edit_payment_amount" => "<h6>" . __("Amount", "gravityformspaypal") . "</h6>" . __("Enter the amount the user paid for this transaction.", "gravityformspaypal"),
"paypal_edit_payment_date" => "<h6>" . __("Date", "gravityformspaypal") . "</h6>" . __("Enter the date of this transaction.", "gravityformspaypal"),
"paypal_edit_payment_transaction_id" => "<h6>" . __("Transaction ID", "gravityformspaypal") . "</h6>" . __("The transacation id is returned from PayPal and uniquely identifies this payment.", "gravityformspaypal"),
"paypal_edit_payment_status" => "<h6>" . __("Status", "gravityformspaypal") . "</h6>" . __("Set the payment status. This status can only be altered if not currently set to Approved and not a subscription.", "gravityformspaypal")
);
return array_merge($tooltips, $paypal_tooltips);
}
public static function delay_post($is_disabled, $form, $lead){
//loading data class
require_once(self::get_base_path() . "/data.php");
$config = GFPayPalData::get_feed_by_form($form["id"]);
if(!$config)
return $is_disabled;
$config = $config[0];
if(!self::has_paypal_condition($form, $config))
return $is_disabled;
return $config["meta"]["delay_post"] == true;
}
public static function delay_notification($is_disabled, $form, $lead){
//loading data class
require_once(self::get_base_path() . "/data.php");
$config = GFPayPalData::get_feed_by_form($form["id"]);
if(!$config)
return $is_disabled;
$config = $config[0];
if(!self::has_paypal_condition($form, $config))
return $is_disabled;
return $config["meta"]["delay_notification"] == true;
}
public static function delay_autoresponder($is_disabled, $form, $lead){
//loading data class
require_once(self::get_base_path() . "/data.php");
$config = GFPayPalData::get_feed_by_form($form["id"]);
if(!$config)
return $is_disabled;
$config = $config[0];
if(!self::has_paypal_condition($form, $config))
return $is_disabled;
return $config["meta"]["delay_autoresponder"];
}
public static function paypal_page(){
$view = rgget("view");
if($view == "edit")
self::edit_page(rgget("id"));
else if($view == "stats")
self::stats_page(rgget("id"));
else
self::list_page();
}
//Displays the paypal feeds list page
private static function list_page(){
if(!self::is_gravityforms_supported()){
die(__(sprintf("PayPal Add-On requires Gravity Forms %s. Upgrade automatically on the %sPlugin page%s.", self::$min_gravityforms_version, "<a href='plugins.php'>", "</a>"), "gravityformspaypal"));
}
if(rgpost('action') == "delete"){
check_admin_referer("list_action", "gf_paypal_list");
$id = absint($_POST["action_argument"]);
GFPayPalData::delete_feed($id);
?>
<div class="updated fade" style="padding:6px"><?php _e("Feed deleted.", "gravityformspaypal") ?></div>
<?php
}
else if (!empty($_POST["bulk_action"])){
check_admin_referer("list_action", "gf_paypal_list");
$selected_feeds = $_POST["feed"];
if(is_array($selected_feeds)){
foreach($selected_feeds as $feed_id)
GFPayPalData::delete_feed($feed_id);
}
?>
<div class="updated fade" style="padding:6px"><?php _e("Feeds deleted.", "gravityformspaypal") ?></div>
<?php
}
?>
<div class="wrap">
<img alt="<?php _e("PayPal Transactions", "gravityformspaypal") ?>" src="<?php echo self::get_base_url()?>/images/paypal_wordpress_icon_32.png" style="float:left; margin:15px 7px 0 0;"/>
<h2><?php
_e("PayPal Forms", "gravityformspaypal");
if(get_option("gf_paypal_configured")){
?>
<a class="button add-new-h2" href="admin.php?page=gf_paypal&view=edit&id=0"><?php _e("Add New", "gravityformspaypal") ?></a>
<?php
}
?>
</h2>
<form id="feed_form" method="post">
<?php wp_nonce_field('list_action', 'gf_paypal_list') ?>
<input type="hidden" id="action" name="action"/>
<input type="hidden" id="action_argument" name="action_argument"/>
<div class="tablenav">
<div class="alignleft actions" style="padding:8px 0 7px 0;">
<label class="hidden" for="bulk_action"><?php _e("Bulk action", "gravityformspaypal") ?></label>
<select name="bulk_action" id="bulk_action">
<option value=''> <?php _e("Bulk action", "gravityformspaypal") ?> </option>
<option value='delete'><?php _e("Delete", "gravityformspaypal") ?></option>
</select>
<?php
echo '<input type="submit" class="button" value="' . __("Apply", "gravityformspaypal") . '" onclick="if( jQuery(\'#bulk_action\').val() == \'delete\' && !confirm(\'' . __("Delete selected feeds? ", "gravityformspaypal") . __("\'Cancel\' to stop, \'OK\' to delete.", "gravityformspaypal") .'\')) { return false; } return true;"/>';
?>
</div>
</div>
<table class="widefat fixed" cellspacing="0">
<thead>
<tr>
<th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
<th scope="col" id="active" class="manage-column check-column"></th>
<th scope="col" class="manage-column"><?php _e("Form", "gravityformspaypal") ?></th>
<th scope="col" class="manage-column"><?php _e("Transaction Type", "gravityformspaypal") ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
<th scope="col" id="active" class="manage-column check-column"></th>
<th scope="col" class="manage-column"><?php _e("Form", "gravityformspaypal") ?></th>
<th scope="col" class="manage-column"><?php _e("Transaction Type", "gravityformspaypal") ?></th>
</tr>
</tfoot>
<tbody class="list:user user-list">
<?php
$settings = GFPayPalData::get_feeds();
if(!get_option("gf_paypal_configured")){
?>
<tr>
<td colspan="3" style="padding:20px;">
<?php echo sprintf(__("To get started, please configure your %sPayPal Settings%s.", "gravityformspaypal"), '<a href="admin.php?page=gf_settings&addon=PayPal">', "</a>"); ?>
</td>
</tr>
<?php
}
else if(is_array($settings) && sizeof($settings) > 0){
foreach($settings as $setting){
?>
<tr class='author-self status-inherit' valign="top">
<th scope="row" class="check-column"><input type="checkbox" name="feed[]" value="<?php echo $setting["id"] ?>"/></th>
<td><img src="<?php echo self::get_base_url() ?>/images/active<?php echo intval($setting["is_active"]) ?>.png" alt="<?php echo $setting["is_active"] ? __("Active", "gravityformspaypal") : __("Inactive", "gravityformspaypal");?>" title="<?php echo $setting["is_active"] ? __("Active", "gravityformspaypal") : __("Inactive", "gravityformspaypal");?>" onclick="ToggleActive(this, <?php echo $setting['id'] ?>); " /></td>
<td class="column-title">
<a href="admin.php?page=gf_paypal&view=edit&id=<?php echo $setting["id"] ?>" title="<?php _e("Edit", "gravityformspaypal") ?>"><?php echo $setting["form_title"] ?></a>
<div class="row-actions">
<span class="edit">
<a title="<?php _e("Edit", "gravityformspaypal")?>" href="admin.php?page=gf_paypal&view=edit&id=<?php echo $setting["id"] ?>" ><?php _e("Edit", "gravityformspaypal") ?></a>
|
</span>
<span class="view">
<a title="<?php _e("View Stats", "gravityformspaypal")?>" href="admin.php?page=gf_paypal&view=stats&id=<?php echo $setting["id"] ?>"><?php _e("Stats", "gravityformspaypal") ?></a>
|
</span>
<span class="view">
<a title="<?php _e("View Entries", "gravityformspaypal")?>" href="admin.php?page=gf_entries&view=entries&id=<?php echo $setting["form_id"] ?>"><?php _e("Entries", "gravityformspaypal") ?></a>
|
</span>
<span class="trash">
<a title="<?php _e("Delete", "gravityformspaypal") ?>" href="javascript: if(confirm('<?php _e("Delete this feed? ", "gravityformspaypal") ?> <?php _e("\'Cancel\' to stop, \'OK\' to delete.", "gravityformspaypal") ?>')){ DeleteSetting(<?php echo $setting["id"] ?>);}"><?php _e("Delete", "gravityformspaypal")?></a>
</span>
</div>
</td>
<td class="column-date">
<?php
switch($setting["meta"]["type"]){
case "product" :
_e("Product and Services", "gravityformspaypal");
break;
case "donation" :
_e("Donation", "gravityformspaypal");
break;
case "subscription" :
_e("Subscription", "gravityformspaypal");
break;
}
?>
</td>
</tr>
<?php
}
}
else{
?>
<tr>
<td colspan="4" style="padding:20px;">
<?php echo sprintf(__("You don't have any PayPal feeds configured. Let's go %screate one%s!", "gravityformspaypal"), '<a href="admin.php?page=gf_paypal&view=edit&id=0">', "</a>"); ?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</form>
</div>
<script type="text/javascript">
function DeleteSetting(id){
jQuery("#action_argument").val(id);
jQuery("#action").val("delete");
jQuery("#feed_form")[0].submit();
}
function ToggleActive(img, feed_id){
var is_active = img.src.indexOf("active1.png") >=0
if(is_active){
img.src = img.src.replace("active1.png", "active0.png");
jQuery(img).attr('title','<?php _e("Inactive", "gravityformspaypal") ?>').attr('alt', '<?php _e("Inactive", "gravityformspaypal") ?>');
}
else{
img.src = img.src.replace("active0.png", "active1.png");
jQuery(img).attr('title','<?php _e("Active", "gravityformspaypal") ?>').attr('alt', '<?php _e("Active", "gravityformspaypal") ?>');
}
var mysack = new sack("<?php echo admin_url("admin-ajax.php")?>" );
mysack.execute = 1;
mysack.method = 'POST';
mysack.setVar( "action", "gf_paypal_update_feed_active" );
mysack.setVar( "gf_paypal_update_feed_active", "<?php echo wp_create_nonce("gf_paypal_update_feed_active") ?>" );
mysack.setVar( "feed_id", feed_id );
mysack.setVar( "is_active", is_active ? 0 : 1 );
mysack.encVar( "cookie", document.cookie, false );
mysack.onError = function() { alert('<?php _e("Ajax error while updating feed", "gravityformspaypal" ) ?>' )};
mysack.runAJAX();
return true;
}
</script>
<?php
}
public static function confirm_settings(){
update_option("gf_paypal_configured", $_POST["is_confirmed"]);
}
public static function settings_page(){
if(rgpost("uninstall")){
check_admin_referer("uninstall", "gf_paypal_uninstall");
self::uninstall();
?>
<div class="updated fade" style="padding:20px;"><?php _e(sprintf("Gravity Forms PayPal Add-On have been successfully uninstalled. It can be re-activated from the %splugins page%s.", "<a href='plugins.php'>","</a>"), "gravityformspaypal")?></div>
<?php
return;
}
$is_configured = get_option("gf_paypal_configured");
?>
<form action="" method="post">
<?php wp_nonce_field("update", "gf_paypal_update") ?>
<h3><?php _e("PayPal Settings", "gravityformspaypal") ?></h3>
<p style="text-align: left;">
<?php _e("Gravity Forms requires IPN to be enabled on your PayPal account. Follow the following steps to confirm IPN is enabled.", "gravityformspaypal") ?>
</p>
<ul>
<li><?php echo sprintf(__("Navigate to your PayPal %sIPN Settings page.%s", "gravityformspaypal"), "<a href='https://www.paypal.com/us/cgi-bin/webscr?cmd=_profile-ipn-notify' target='_blank'>" , "</a>") ?></li>
<li><?php _e("If IPN is already enabled, you will see your current IPN settings along with a button to turn off IPN. If that is the case, just check the confirmation box below and you are ready to go!", "gravityformspaypal") ?></li>
<li><?php _e("If IPN is not enabled, click the 'Choose IPN Settings' button.", "gravityformspaypal") ?></li>
<li><?php echo sprintf(__("Click the box to enable IPN and enter the following Notification URL: %s", "gravityformspaypal"), "<strong>" . add_query_arg("page", "gf_paypal_ipn", get_bloginfo("url") . "/") . "</strong>") ?></li>
</ul>
<br/>
<input type="checkbox" name="gf_paypal_configured" id="gf_paypal_configured" onclick="confirm_settings()" <?php echo $is_configured ? "checked='checked'" : ""?>/>
<label for="gf_paypal_configured" class="inline"><?php _e("Confirm that your have configured your PayPal account to enable IPN", "gravityformspaypal") ?></label>
<script type="text/javascript">
function confirm_settings(){
var confirmed = jQuery("#gf_paypal_configured").is(":checked") ? 1 : 0;
jQuery.post(ajaxurl, {action:"gf_paypal_confirm_settings", is_confirmed: confirmed, cookie: encodeURIComponent(document.cookie)});
}
</script>
</form>
<form action="" method="post">
<?php wp_nonce_field("uninstall", "gf_paypal_uninstall") ?>
<?php if(GFCommon::current_user_can_any("gravityforms_paypal_uninstall")){ ?>
<div class="hr-divider"></div>
<h3><?php _e("Uninstall PayPal Add-On", "gravityformspaypal") ?></h3>
<div class="delete-alert"><?php _e("Warning! This operation deletes ALL PayPal Feeds.", "gravityformspaypal") ?>
<?php
$uninstall_button = '<input type="submit" name="uninstall" value="' . __("Uninstall PayPal Add-On", "gravityformspaypal") . '" class="button" onclick="return confirm(\'' . __("Warning! ALL PayPal Feeds will be deleted. This cannot be undone. \'OK\' to delete, \'Cancel\' to stop", "gravityformspaypal") . '\');"/>';
echo apply_filters("gform_paypal_uninstall_button", $uninstall_button);
?>
</div>
<?php } ?>
</form>
<?php
}
private static function get_product_field_options($productFields, $selectedValue){
$options = "<option value=''>" . __("Select a product", "gravityformspaypal") . "</option>";
foreach($productFields as $field){
$label = GFCommon::truncate_middle($field["label"], 30);
$selected = $selectedValue == $field["id"] ? "selected='selected'" : "";
$options .= "<option value='{$field["id"]}' {$selected}>{$label}</option>";
}
return $options;
}
private static function stats_page(){
?>
<style>
.paypal_graph_container{clear:both; padding-left:5px; min-width:789px; margin-right:50px;}
.paypal_message_container{clear: both; padding-left:5px; text-align:center; padding-top:120px; border: 1px solid #CCC; background-color: #FFF; width:100%; height:160px;}
.paypal_summary_container {margin:30px 60px; text-align: center; min-width:740px; margin-left:50px;}
.paypal_summary_item {width:160px; background-color: #FFF; border: 1px solid #CCC; padding:14px 8px; margin:6px 3px 6px 0; display: -moz-inline-stack; display: inline-block; zoom: 1; *display: inline; text-align:center;}
.paypal_summary_value {font-size:20px; margin:5px 0; font-family:Georgia,"Times New Roman","Bitstream Charter",Times,serif}
.paypal_summary_title {}
#paypal_graph_tooltip {border:4px solid #b9b9b9; padding:11px 0 0 0; background-color: #f4f4f4; text-align:center; -moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px; -khtml-border-radius: 4px;}
#paypal_graph_tooltip .tooltip_tip {width:14px; height:14px; background-image:url(<?php echo self::get_base_url() ?>/images/tooltip_tip.png); background-repeat: no-repeat; position: absolute; bottom:-14px; left:68px;}
.paypal_tooltip_date {line-height:130%; font-weight:bold; font-size:13px; color:#21759B;}
.paypal_tooltip_sales {line-height:130%;}
.paypal_tooltip_revenue {line-height:130%;}
.paypal_tooltip_revenue .paypal_tooltip_heading {}
.paypal_tooltip_revenue .paypal_tooltip_value {}
.paypal_trial_disclaimer {clear:both; padding-top:20px; font-size:10px;}
</style>
<script type="text/javascript" src="<?php echo self::get_base_url() ?>/flot/jquery.flot.min.js"></script>
<script type="text/javascript" src="<?php echo self::get_base_url() ?>/js/currency.js"></script>
<div class="wrap">
<img alt="<?php _e("PayPal", "gravityformspaypal") ?>" style="margin: 15px 7px 0pt 0pt; float: left;" src="<?php echo self::get_base_url() ?>/images/paypal_wordpress_icon_32.png"/>
<h2><?php _e("PayPal Stats", "gravityformspaypal") ?></h2>
<form method="post" action="">
<ul class="subsubsub">
<li><a class="<?php echo (!RGForms::get("tab") || RGForms::get("tab") == "daily") ? "current" : "" ?>" href="?page=gf_paypal&view=stats&id=<?php echo $_GET["id"] ?>"><?php _e("Daily", "gravityforms"); ?></a> | </li>
<li><a class="<?php echo RGForms::get("tab") == "weekly" ? "current" : ""?>" href="?page=gf_paypal&view=stats&id=<?php echo $_GET["id"] ?>&tab=weekly"><?php _e("Weekly", "gravityforms"); ?></a> | </li>
<li><a class="<?php echo RGForms::get("tab") == "monthly" ? "current" : ""?>" href="?page=gf_paypal&view=stats&id=<?php echo $_GET["id"] ?>&tab=monthly"><?php _e("Monthly", "gravityforms"); ?></a></li>
</ul>
<?php
$config = GFPayPalData::get_feed(RGForms::get("id"));
switch(RGForms::get("tab")){
case "monthly" :
$chart_info = self::monthly_chart_info($config);
break;
case "weekly" :
$chart_info = self::weekly_chart_info($config);
break;
default :
$chart_info = self::daily_chart_info($config);
break;
}
if(!$chart_info["series"]){
?>
<div class="paypal_message_container"><?php _e("No payments have been made yet.", "gravityformspaypal") ?> <?php echo $config["meta"]["trial_period_enabled"] && empty($config["meta"]["trial_amount"]) ? " **" : ""?></div>
<?php
}
else{
?>
<div class="paypal_graph_container">
<div id="graph_placeholder" style="width:100%;height:300px;"></div>
</div>
<script type="text/javascript">
var paypal_graph_tooltips = <?php echo $chart_info["tooltips"] ?>;
jQuery.plot(jQuery("#graph_placeholder"), <?php echo $chart_info["series"] ?>, <?php echo $chart_info["options"] ?>);
jQuery(window).resize(function(){
jQuery.plot(jQuery("#graph_placeholder"), <?php echo $chart_info["series"] ?>, <?php echo $chart_info["options"] ?>);
});
var previousPoint = null;
jQuery("#graph_placeholder").bind("plothover", function (event, pos, item) {
startShowTooltip(item);
});
jQuery("#graph_placeholder").bind("plotclick", function (event, pos, item) {
startShowTooltip(item);
});
function startShowTooltip(item){
if (item) {
if (!previousPoint || previousPoint[0] != item.datapoint[0]) {
previousPoint = item.datapoint;
jQuery("#paypal_graph_tooltip").remove();
var x = item.datapoint[0].toFixed(2),
y = item.datapoint[1].toFixed(2);
showTooltip(item.pageX, item.pageY, paypal_graph_tooltips[item.dataIndex]);
}
}
else {
jQuery("#paypal_graph_tooltip").remove();
previousPoint = null;
}
}
function showTooltip(x, y, contents) {
jQuery('<div id="paypal_graph_tooltip">' + contents + '<div class="tooltip_tip"></div></div>').css( {
position: 'absolute',
display: 'none',
opacity: 0.90,
width:'150px',
height:'<?php echo $config["meta"]["type"] == "subscription" ? "75px" : "60px" ;?>',
top: y - <?php echo $config["meta"]["type"] == "subscription" ? "100" : "89" ;?>,
left: x - 79
}).appendTo("body").fadeIn(200);
}
function convertToMoney(number){
var currency = getCurrentCurrency();
return currency.toMoney(number);
}
function formatWeeks(number){
number = number + "";
return "<?php _e("Week ", "gravityformspaypal") ?>" + number.substring(number.length-2);
}
function getCurrentCurrency(){
<?php
if(!class_exists("RGCurrency"))
require_once(ABSPATH . "/" . PLUGINDIR . "/gravityforms/currency.php");
$current_currency = RGCurrency::get_currency(GFCommon::get_currency());
?>
var currency = new Currency(<?php echo GFCommon::json_encode($current_currency)?>);
return currency;
}
</script>
<?php
}
$payment_totals = RGFormsModel::get_form_payment_totals($config["form_id"]);
$transaction_totals = GFPayPalData::get_transaction_totals($config["form_id"]);
switch($config["meta"]["type"]){
case "product" :
$total_sales = $payment_totals["orders"];
$sales_label = __("Total Orders", "gravityformspaypal");
break;
case "donation" :
$total_sales = $payment_totals["orders"];
$sales_label = __("Total Donations", "gravityformspaypal");
break;
case "subscription" :
$total_sales = $payment_totals["active"];
$sales_label = __("Active Subscriptions", "gravityformspaypal");
break;
}
$total_revenue = empty($transaction_totals["payment"]["revenue"]) ? 0 : $transaction_totals["payment"]["revenue"];
?>
<div class="paypal_summary_container">
<div class="paypal_summary_item">
<div class="paypal_summary_title"><?php _e("Total Revenue", "gravityformspaypal")?></div>
<div class="paypal_summary_value"><?php echo GFCommon::to_money($total_revenue) ?></div>
</div>
<div class="paypal_summary_item">
<div class="paypal_summary_title"><?php echo $chart_info["revenue_label"]?></div>
<div class="paypal_summary_value"><?php echo $chart_info["revenue"] ?></div>
</div>
<div class="paypal_summary_item">
<div class="paypal_summary_title"><?php echo $sales_label?></div>
<div class="paypal_summary_value"><?php echo $total_sales ?></div>
</div>
<div class="paypal_summary_item">
<div class="paypal_summary_title"><?php echo $chart_info["sales_label"] ?></div>
<div class="paypal_summary_value"><?php echo $chart_info["sales"] ?></div>
</div>
</div>
<?php
if(!$chart_info["series"] && $config["meta"]["trial_period_enabled"] && empty($config["meta"]["trial_amount"])){
?>
<div class="paypal_trial_disclaimer"><?php _e("** Free trial transactions will only be reflected in the graph after the first payment is made (i.e. after trial period ends)", "gravityformspaypal") ?></div>
<?php
}
?>
</form>
</div>
<?php
}
private function get_graph_timestamp($local_datetime){
$local_timestamp = mysql2date("G", $local_datetime); //getting timestamp with timezone adjusted
$local_date_timestamp = mysql2date("G", gmdate("Y-m-d 23:59:59", $local_timestamp)); //setting time portion of date to midnight (to match the way Javascript handles dates)
$timestamp = ($local_date_timestamp - (24 * 60 * 60) + 1) * 1000; //adjusting timestamp for Javascript (subtracting a day and transforming it to milliseconds
return $timestamp;
}
private static function matches_current_date($format, $js_timestamp){
$target_date = $format == "YW" ? $js_timestamp : date($format, $js_timestamp / 1000);
$current_date = gmdate($format, GFCommon::get_local_timestamp(time()));
return $target_date == $current_date;
}
private static function daily_chart_info($config){
global $wpdb;
$tz_offset = self::get_mysql_tz_offset();
$results = $wpdb->get_results("SELECT CONVERT_TZ(t.date_created, '+00:00', '" . $tz_offset . "') as date, sum(t.amount) as amount_sold, sum(is_renewal) as renewals, sum(is_renewal=0) as new_sales
FROM {$wpdb->prefix}rg_lead l
INNER JOIN {$wpdb->prefix}rg_paypal_transaction t ON l.id = t.entry_id
WHERE form_id={$config["form_id"]} AND t.transaction_type='payment'
GROUP BY date(date)
ORDER BY payment_date desc
LIMIT 30");
$sales_today = 0;
$revenue_today = 0;
$tooltips = "";
if(!empty($results)){
$data = "[";
foreach($results as $result){
$timestamp = self::get_graph_timestamp($result->date);
if(self::matches_current_date("Y-m-d", $timestamp)){
$sales_today += $result->new_sales;
$revenue_today += $result->amount_sold;
}
$data .="[{$timestamp},{$result->amount_sold}],";
if($config["meta"]["type"] == "subscription"){
$sales_line = " <div class='paypal_tooltip_subscription'><span class='paypal_tooltip_heading'>" . __("New Subscriptions", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . $result->new_sales . "</span></div><div class='paypal_tooltip_subscription'><span class='paypal_tooltip_heading'>" . __("Renewals", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . $result->renewals . "</span></div>";
}
else{
$sales_line = "<div class='paypal_tooltip_sales'><span class='paypal_tooltip_heading'>" . __("Orders", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . $result->new_sales . "</span></div>";
}
$tooltips .= "\"<div class='paypal_tooltip_date'>" . GFCommon::format_date($result->date, false, "", false) . "</div>{$sales_line}<div class='paypal_tooltip_revenue'><span class='paypal_tooltip_heading'>" . __("Revenue", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . GFCommon::to_money($result->amount_sold) . "</span></div>\",";
}
$data = substr($data, 0, strlen($data)-1);
$tooltips = substr($tooltips, 0, strlen($tooltips)-1);
$data .="]";
$series = "[{data:" . $data . "}]";
$month_names = self::get_chart_month_names();
$options ="
{
xaxis: {mode: 'time', monthnames: $month_names, timeformat: '%b %d', minTickSize:[1, 'day']},
yaxis: {tickFormatter: convertToMoney},
bars: {show:true, align:'right', barWidth: (24 * 60 * 60 * 1000) - 10000000},
colors: ['#a3bcd3', '#14568a'],
grid: {hoverable: true, clickable: true, tickColor: '#F1F1F1', backgroundColor:'#FFF', borderWidth: 1, borderColor: '#CCC'}
}";
}
switch($config["meta"]["type"]){
case "product" :
$sales_label = __("Orders Today", "gravityformspaypal");
break;
case "donation" :
$sales_label = __("Donations Today", "gravityformspaypal");
break;
case "subscription" :
$sales_label = __("Subscriptions Today", "gravityformspaypal");
break;
}
$revenue_today = GFCommon::to_money($revenue_today);
return array("series" => $series, "options" => $options, "tooltips" => "[$tooltips]", "revenue_label" => __("Revenue Today", "gravityformspaypal"), "revenue" => $revenue_today, "sales_label" => $sales_label, "sales" => $sales_today);
}
private static function weekly_chart_info($config){
global $wpdb;
$tz_offset = self::get_mysql_tz_offset();
$results = $wpdb->get_results("SELECT yearweek(CONVERT_TZ(t.date_created, '+00:00', '" . $tz_offset . "')) week_number, sum(t.amount) as amount_sold, sum(is_renewal) as renewals, sum(is_renewal=0) as new_sales
FROM {$wpdb->prefix}rg_lead l
INNER JOIN {$wpdb->prefix}rg_paypal_transaction t ON l.id = t.entry_id
WHERE form_id={$config["form_id"]} AND t.transaction_type='payment'
GROUP BY week_number
ORDER BY week_number desc
LIMIT 30");
$sales_week = 0;
$revenue_week = 0;
$tooltips = "";
if(!empty($results))
{
$data = "[";
foreach($results as $result){
if(self::matches_current_date("YW", $result->week_number)){
$sales_week += $result->new_sales;
$revenue_week += $result->amount_sold;
}
$data .="[{$result->week_number},{$result->amount_sold}],";
if($config["meta"]["type"] == "subscription"){
$sales_line = " <div class='paypal_tooltip_subscription'><span class='paypal_tooltip_heading'>" . __("New Subscriptions", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . $result->new_sales . "</span></div><div class='paypal_tooltip_subscription'><span class='paypal_tooltip_heading'>" . __("Renewals", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . $result->renewals . "</span></div>";
}
else{
$sales_line = "<div class='paypal_tooltip_sales'><span class='paypal_tooltip_heading'>" . __("Orders", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . $result->new_sales . "</span></div>";
}
$tooltips .= "\"<div class='paypal_tooltip_date'>" . substr($result->week_number, 0, 4) . ", " . __("Week", "gravityformspaypal") . " " . substr($result->week_number, strlen($result->week_number)-2, 2) . "</div>{$sales_line}<div class='paypal_tooltip_revenue'><span class='paypal_tooltip_heading'>" . __("Revenue", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . GFCommon::to_money($result->amount_sold) . "</span></div>\",";
}
$data = substr($data, 0, strlen($data)-1);
$tooltips = substr($tooltips, 0, strlen($tooltips)-1);
$data .="]";
$series = "[{data:" . $data . "}]";
$month_names = self::get_chart_month_names();
$options ="
{
xaxis: {tickFormatter: formatWeeks, tickDecimals: 0},
yaxis: {tickFormatter: convertToMoney},
bars: {show:true, align:'center', barWidth:0.95},
colors: ['#a3bcd3', '#14568a'],
grid: {hoverable: true, clickable: true, tickColor: '#F1F1F1', backgroundColor:'#FFF', borderWidth: 1, borderColor: '#CCC'}
}";
}
switch($config["meta"]["type"]){
case "product" :
$sales_label = __("Orders this Week", "gravityformspaypal");
break;
case "donation" :
$sales_label = __("Donations this Week", "gravityformspaypal");
break;
case "subscription" :
$sales_label = __("Subscriptions this Week", "gravityformspaypal");
break;
}
$revenue_week = GFCommon::to_money($revenue_week);
return array("series" => $series, "options" => $options, "tooltips" => "[$tooltips]", "revenue_label" => __("Revenue this Week", "gravityformspaypal"), "revenue" => $revenue_week, "sales_label" => $sales_label , "sales" => $sales_week);
}
private static function monthly_chart_info($config){
global $wpdb;
$tz_offset = self::get_mysql_tz_offset();
$results = $wpdb->get_results("SELECT date_format(CONVERT_TZ(t.date_created, '+00:00', '" . $tz_offset . "'), '%Y-%m-02') date, sum(t.amount) as amount_sold, sum(is_renewal) as renewals, sum(is_renewal=0) as new_sales
FROM {$wpdb->prefix}rg_lead l
INNER JOIN {$wpdb->prefix}rg_paypal_transaction t ON l.id = t.entry_id
WHERE form_id={$config["form_id"]} AND t.transaction_type='payment'
group by date
order by date desc
LIMIT 30");
$sales_month = 0;
$revenue_month = 0;
$tooltips = "";
if(!empty($results)){
$data = "[";
foreach($results as $result){
$timestamp = self::get_graph_timestamp($result->date);
if(self::matches_current_date("Y-m", $timestamp)){
$sales_month += $result->new_sales;
$revenue_month += $result->amount_sold;
}
$data .="[{$timestamp},{$result->amount_sold}],";
if($config["meta"]["type"] == "subscription"){
$sales_line = " <div class='paypal_tooltip_subscription'><span class='paypal_tooltip_heading'>" . __("New Subscriptions", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . $result->new_sales . "</span></div><div class='paypal_tooltip_subscription'><span class='paypal_tooltip_heading'>" . __("Renewals", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . $result->renewals . "</span></div>";
}
else{
$sales_line = "<div class='paypal_tooltip_sales'><span class='paypal_tooltip_heading'>" . __("Orders", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . $result->new_sales . "</span></div>";
}
$tooltips .= "\"<div class='paypal_tooltip_date'>" . GFCommon::format_date($result->date, false, "F, Y", false) . "</div>{$sales_line}<div class='paypal_tooltip_revenue'><span class='paypal_tooltip_heading'>" . __("Revenue", "gravityformspaypal") . ": </span><span class='paypal_tooltip_value'>" . GFCommon::to_money($result->amount_sold) . "</span></div>\",";
}
$data = substr($data, 0, strlen($data)-1);
$tooltips = substr($tooltips, 0, strlen($tooltips)-1);
$data .="]";
$series = "[{data:" . $data . "}]";
$month_names = self::get_chart_month_names();
$options ="
{
xaxis: {mode: 'time', monthnames: $month_names, timeformat: '%b %y', minTickSize: [1, 'month']},
yaxis: {tickFormatter: convertToMoney},
bars: {show:true, align:'center', barWidth: (24 * 60 * 60 * 30 * 1000) - 130000000},
colors: ['#a3bcd3', '#14568a'],
grid: {hoverable: true, clickable: true, tickColor: '#F1F1F1', backgroundColor:'#FFF', borderWidth: 1, borderColor: '#CCC'}
}";
}
switch($config["meta"]["type"]){
case "product" :
$sales_label = __("Orders this Month", "gravityformspaypal");
break;
case "donation" :
$sales_label = __("Donations this Month", "gravityformspaypal");
break;
case "subscription" :
$sales_label = __("Subscriptions this Month", "gravityformspaypal");
break;
}