-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathignitiondeck-admin.php
1892 lines (1686 loc) · 68.2 KB
/
ignitiondeck-admin.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
/**
* Create Projects post type
*/
add_action( 'init', 'ign_create_post_type' );
function ign_create_post_type() {
require 'languages/text_variables.php';
$slug = apply_filters('idcf_archive_slug', __('projects', 'ignitiondeck'));
register_post_type( 'ignition_product',
array(
'labels' => array(
'name' => $tr_Projects,
'singular_name' => $tr_Project,
'add_new' => $tr_Add_New_Project,
'add_new_item' => $tr_Add_New_Project,
'edit' => $tr_Edit,
'edit_item' => $tr_Edit_Project,
'new_item' => $tr_New_Project,
'view' => $tr_View_Project,
'view_item' => $tr_View_Project,
'search_items' =>$tr_Search_Project,
'not_found' => $tr_No_Products_found ,
'not_found_in_trash' => $tr_No_Product_in_Trash,
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => apply_filters('idcf_hierarchical', false),
'menu_position' => 5,
'capability_type' => 'post',
'menu_icon' => plugins_url( '/images/ignitiondeck-menu.png', __FILE__ ),
'query_var' => true,
'rewrite' => array( 'slug' => $slug, 'with_front' => true ),
'has_archive' => $slug,
'supports' => array('title', 'editor', 'comments', 'author', 'thumbnail'),
'taxonomies' => array('category', 'post_tag', 'project_category'),
)
);
}
add_action('init', 'ign_create_taxonomy');
function ign_create_taxonomy() {
$labels = array(
'name' => __('Project Categories', 'ignitiondeck'),
'singular_name' => __('Project Category', 'ignitiondeck'),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'project-category')
);
$args = apply_filters('project_category_args', $args);
register_taxonomy('project_category', 'ignition_product', $args);
$pt_labels = array(
'name' => __('Project Types', 'ignitiondeck'),
'singular_name' => __('Project Type', 'ignitiondeck'),
);
$pt_args = array(
'hierarchical' => false,
'labels' => $pt_labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'project-type')
);
$pt_args = apply_filters('project_type_args', $pt_args);
register_taxonomy('project_type', 'ignition_product', $pt_args);
}
add_image_size('id_embed_image', 190, 127, true);
add_image_size('id_checkout_image', 500, 226, true);
/**
* Enques Admin and Front End JS/CSS
*/
function enqueue_admin_js() {
wp_register_script('ignitiondeck-admin', plugins_url('/js/ignitiondeck-admin.js', __FILE__));
wp_enqueue_script('jQuery');
wp_enqueue_script('ignitiondeck-admin');
if (is_multisite() && is_id_network_activated()) {
$id_ajaxurl = network_home_url('/').'wp-admin/admin-ajax.php';
}
else {
$id_ajaxurl = site_url('/').'wp-admin/admin-ajax.php';
}
wp_localize_script('ignitiondeck-admin', 'id_homeurl', home_url());
wp_localize_script('ignitiondeck-admin', 'id_ajaxurl', $id_ajaxurl);
global $post;
if (isset($post->post_type) && $post->post_type == 'ignition_product') {
wp_register_script( 'ignitiondeck', plugins_url('/js/ignitiondeck.js', __FILE__));
wp_enqueue_script( 'ignitiondeck' );
wp_localize_script('ignitiondeck', 'id_ajaxurl', $id_ajaxurl);
wp_dequeue_script('autosave');
//wp_enqueue_style('wp-pointer');
//wp_enqueue_script('wp-pointer');
}
}
add_action('admin_enqueue_scripts', 'enqueue_admin_js');
function enqueue_admin_css() {
wp_register_style( 'admin-css', plugins_url('/ignitiondeck-admin.css', __FILE__));
wp_enqueue_style( 'admin-css');
}
add_action('admin_enqueue_scripts', 'enqueue_admin_css');
add_action('init', 'enqueue_styles_scripts_for_post_type');
function enqueue_styles_scripts_for_post_type() {
global $post;
if (isset($post->post_type) && $post->post_type == 'ignition_product') {
add_action('admin_enqueue_scripts', 'enqueue_admin_css');
add_action('admin_enqueue_scripts', 'enqueue_admin_js');
}
}
// Change the columns for the edit CPT screen
function ign_change_columns( $cols ) {
require 'languages/text_variables.php';
$cols = array(
'cb' => '<input type="checkbox" />',
'title' => $tr_Product,
'author' => __('Author', 'ignitiondeck'),
'type' => __('Type', 'ignitiondeck'),
'goal' => $tr_Funding_Goal,
'raised' => $tr_Pledged,
'enddate' => $tr_End_Date,
'daysleft' => $tr_Days_Remaining ,
);
return apply_filters('id_project_columns', $cols);
}
add_filter( "manage_ignition_product_posts_columns", "ign_change_columns" );
add_action( 'manage_posts_custom_column', 'manage_ign_product_columns', 10, 2 );
function manage_ign_product_columns($column_name, $id) {
global $post;
require 'languages/text_variables.php';
$post_id = $post->ID;
$project_id = get_post_meta($id, 'ign_project_id', true);
$project = new ID_Project($project_id);
$cCode = $project->currency_code();
switch ($column_name) {
// display goal amount with currency formatting
case 'author':
echo (!empty($post->post_author) ? $post->post_author : __('None', 'ignitiondeck'));
break;
case 'type':
$type = get_post_meta($post_id, 'ign_project_type', true);
if (isset($type)) {
if ($type == 'pwyw') {
$type = __('Pledge What You Want', 'Ignitiondeck');
}
else if ($type == 'level-based') {
$type = __('Level-Based', 'ignitiondeck');
}
}
$type = apply_filters('id_project_type', $type);
echo (isset($type) ? $type : '');
break;
case 'goal':
if (get_post_meta( $post->ID, 'ign_fund_goal', true)) {
$goal_amt = number_format(get_post_meta( $post->ID, 'ign_fund_goal', true), 2, '.', ',');
setlocale(LC_MONETARY, 'en_US');
echo //money_format('%(#10n', $goal_amt);
$cCode.$goal_amt;
} else {
echo '<em>'.$tr_No_Goal_set.'</em>';
}
break;
case 'raised':
if (isset($project_id)) {
$project = new ID_Project($project_id);
$post_id = $project->get_project_postid();
$raised = apply_filters('id_funds_raised', $project->get_project_raised(), $post_id);
echo $raised;
}
break;
// display end date
case 'enddate':
if (get_post_meta( $post->ID, 'ign_fund_end', true)) {
echo get_post_meta( $post->ID, 'ign_fund_end', true);
} else {
echo '<em>'.$tr_No_Date_set.'</em>';
}
break;
// calculate days remaining
case 'daysleft':
if (get_post_meta( $post->ID, 'ign_fund_end', true)) {
$days_left = $project->days_left();
//$ending = get_post_meta( $post->ID, 'ign_fund_end', true);
//$daysleft = ID_Project::days_left($ending);
echo $days_left;
} else {
echo '<em>'.$tr_No_Date_set.'</em>';
}
break;
// return standard post columns
default:
break;
} // end switch
}
// Make these columns sortable
function ign_sortable_columns() {
$sortable_columns = array(
'title' => 'title',
'author' => 'author',
'type' => 'type',
'goal' => 'goal',
'raised' => 'raised',
'enddate' => 'enddate',
'daysleft' => 'daysleft',
);
return apply_filters('id_sortable_project_columns', $sortable_columns);
}
add_filter( "manage_edit-ignition_product_sortable_columns", "ign_sortable_columns" );
// This is the NEW Order Details Menu but appears to be unused
add_filter('manage-order_columns', 'order_detail_columns');
function order_detail_columns($columns) {
require 'languages/text_variables.php';
$columns = array(
'name' => '<th scope="col" id="name" class="manage-column sortable desc"><b><?php echo $tr_Name; ?></b></th>',
'project' => '<th scope="col" id="status" class="manage-column sortable desc"><b><?php echo $tr_Product_Name; ?></b></th>',
'level' => '<th scope="col" id="action" class="manage-column sortable desc"><b><?php echo $tr_Level; ?></b></th>',
'pledged' => '<th scope="col" id="action" class="manage-column sortable desc"><b><?php echo $tr_Pledged; ?></b></th>',
'date' => '<th scope="col" id="action" class="manage-column sortable desc"><b><?php echo $tr_Date; ?></b></th>'
);
return apply_filters('id_order_columns', $columns);
}
// This is to make order details menu sortable but seems to be unused
add_filter ('edit-order_columns', 'order_details_sortable_columns');
function order_details_sortable_columns() {
$columns = array(
'name' => 'name',
'project' => 'project',
'level' => 'level',
'pledged' => 'pledged',
'date' => 'date'
);
return apply_filters('id_sortable_order_columns', $columns);
}
// change post title box text
function change_ign_product_title_text( $title ){
require 'languages/text_variables.php';
$screen = get_current_screen();
if ( 'ignition_product' == $screen->post_type ) {
$title = $tr_Enter_Project_Name_Here;
}
return $title;
}
add_filter( 'enter_title_here', 'change_ign_product_title_text' );
//-------------------------Admin Side Add IgnitionDeck STARTS------------------------------
add_action('admin_menu', 'id_admin_menus', 12);
function id_admin_menus() {
if (current_user_can('manage_options')) {
$settings = add_menu_page(__('IDCF Settings', 'ignitiondeck'), __('IDCF', 'ignitiondeck'), 'manage_options', 'ignitiondeck', 'id_main_menu', plugins_url( '/images/ignitiondeck-menu.png', __FILE__ ));
$project_settings = add_submenu_page( 'ignitiondeck', 'Project Settings', 'Project Settings', 'manage_options', 'project-settings', 'product_settings');
if (is_id_licensed()) {
$custom_settings = add_submenu_page( 'ignitiondeck', __('Custom Settings', 'ignitiondeck'), __('Custom Settings', 'ignitiondeck'), 'manage_options', 'custom-settings', 'custom_settings');
$payment_settings = add_submenu_page( 'ignitiondeck', __('Payment Settings', 'ignitiondeck'), __('Payment Settings', 'ignitiondeck'), 'manage_options', 'payment-options', 'paypal_payment_options');
$deck_settings = add_submenu_page( 'ignitiondeck', __('Deck Builder', 'ignitiondeck'), __('Deck Builder', 'ignitiondeck'), 'manage_options', 'deck-builder', 'deck_builder');
}
$order_menu = add_submenu_page( 'ignitiondeck', __('Orders', 'ignitiondeck'), __('Orders', 'ignitiondeck'), 'manage_options', 'order_details', 'order_details');
if (is_id_licensed()) {
$email_settings = add_submenu_page( 'ignitiondeck', __('Email Settings', 'ignitiondeck'), __('Email Settings', 'ignitiondeck'), 'manage_options', 'email-settings', 'email_settings');
}
//add_submenu_page( 'ignitiondeck', 'Social Settings', 'Social Settings ', 'manage_options', 'social-settings', 'social_application');
//add_submenu_page( 'ignitiondeck', 'Payment Form Settings', 'Payment Form Settings', 'manage_options', 'form-settings', 'form_settings');
//add_submenu_page( 'ignitiondeck', 'Asked Question', 'Asked Question', 'manage_options', 'asked_questions', 'asked_questions');
$edit_order = add_submenu_page( $order_menu, __('Edit Order', 'ignitiondeck'), '', 'manage_options', 'edit_order', 'edit_order');
$view_order = add_submenu_page( $order_menu, __('View order', 'ignitiondeck'), '', 'manage_options', 'view_order', 'view_order');
$delete_order = add_submenu_page( $order_menu, __('Delete Order', 'ignitiondeck'), '', 'manage_options', 'delete_order', 'delete_order');
$add_order = add_submenu_page( $order_menu, __('Add Order', 'ignitiondeck'), '', 'manage_options', 'add_order', 'add_order');
//add_submenu_page( $order_menu, 'Refund', '', 'manage_options', 'refund', 'refund_order');
do_action('id_submenu');
add_action('admin_print_styles-'.$settings, 'id_font_awesome');
$menus = array($settings, $project_settings, $order_menu, $edit_order, $view_order, $delete_order, $add_order);
if (is_id_licensed()) {
$menus[] = $custom_settings;
$menus[] = $payment_settings;
$menus[] = $deck_settings;
$menus[] = $email_settings;
}
$menus = apply_filters('id_menu_enqueue', $menus);
if (is_array($menus)) {
foreach ($menus as $menu) {
add_action('admin_print_styles-'.$menu, 'enqueue_admin_css');
add_action('admin_print_styles-'.$menu, 'enqueue_admin_js');
}
}
}
}
function id_main_menu(){
require 'languages/text_variables.php';
global $wpdb;
$super = true;
if (is_multisite()) {
$super = is_super_admin();
}
$license_key = get_option('id_license_key');
$is_pro = get_option('is_id_pro', 0);
$is_basic = get_option('is_id_basic', 0);
if (isset($_POST['license_key'])) {
$is_pro = 0;
$is_basic = 0;
$license_key = esc_attr($_POST['license_key']);
update_option('id_license_key', $license_key);
$validate = id_validate_license($license_key);
if (isset($validate['response'])) {
if ($validate['response']) {
if (isset($validate['download'])) {
if ($validate['download'] == '30') {
$is_pro = 1;
}
else if ($validate['download'] == '1') {
$is_basic = 1;
}
}
}
}
update_option('is_id_pro', $is_pro);
update_option('is_id_basic', $is_basic);
if ($is_pro || $is_basic) {
update_option('was_id_licensed', 1);
}
if ($is_pro) {
update_option('was_id_pro', 1);
}
}
if ($is_pro) {
$type_msg = __(' IgnitionDeck Enterprise', 'ignitiondeck');
}
else if ($is_basic) {
$type_msg = __(' IgnitionDeck', 'ignitiondeck');
}
$skins = $wpdb->get_row('SELECT theme_choices FROM '.$wpdb->prefix.'ign_settings WHERE id="1"');
if (isset($skins)) {
$skins = unserialize($skins->theme_choices);
}
else {
$skins = array();
}
$deleted_skin_list = deleted_skin_list($skins);
if (isset($_POST['add-skin'])) {
$skin = str_replace('.css', '', $_POST['skin-name']);
if ($skin !== '') {
$skins[] = $skin;
$deleted_skin_list = deleted_skin_list($skins);
$skins = serialize($skins);
$sql = $wpdb->prepare('UPDATE '.$wpdb->prefix.'ign_settings SET theme_choices=%s WHERE id="1"', $skins);
$res = $wpdb->query($sql);
}
}
if (isset($_POST['delete-skin'])) {
$deleted = $_POST['deleted-skin'];
foreach ($skins as $key => $val) {
if (strtolower(str_replace(' ', '', $val)) == strtolower(str_replace(' ', '', $deleted))) {
unset($skins[$key]);
}
}
$deleted_skin_list = deleted_skin_list($skins);
$skins = serialize($skins);
$sql = $wpdb->prepare('UPDATE '.$wpdb->prefix.'ign_settings SET theme_choices=%s WHERE id="1"', $skins);
$res = $wpdb->query($sql);
}
if (isset($_POST['btnIgnSettings'])) {
if ($_POST['btnIgnSettings'] == $tr_Add) {
$sql_insert = " INSERT INTO ".$wpdb->prefix."ign_settings
(
theme_value,
prod_page_fb,
prod_page_twitter,
prod_page_linkedin,
prod_page_google,
prod_page_pinterest,
id_widget_logo_on,
id_widget_link,
theme_choices
) VALUES (
'".(isset($_POST['theme_value']) ? $_POST['theme_value'] : 'style1')."',
'".(isset($_POST['prod_page_fb']) ? $_POST['prod_page_fb'] : 0)."',
'".(isset($_POST['prod_page_twitter']) ? $_POST['prod_page_twitter'] : 0)."',
'".(isset($_POST['prod_page_linkedin']) ? $_POST['prod_page_linkedin'] : 0)."',
'".(isset($_POST['prod_page_google']) ? $_POST['prod_page_google'] : 0)."',
'".(isset($_POST['prod_page_pinterest']) ? $_POST['prod_page_pinterest'] : 0)."',
'".(isset($_POST['id_widget_logo_on']) ? $_POST['id_widget_logo_on'] : 0)."',
'".$_POST['id_widget_link']."',
'".serialize($skins)."'
)";
$wpdb->query( $sql_insert );
update_option('id_settings_notice', 'off');
} else if ($_POST['btnIgnSettings'] == $tr_Update) {
$sql_update = " UPDATE ".$wpdb->prefix."ign_settings SET
theme_value = '".(isset($_POST['theme_value']) ? $_POST['theme_value'] : 'style1')."',
prod_page_fb = '".(isset($_POST['prod_page_fb']) ? $_POST['prod_page_fb'] : 0)."',
prod_page_twitter = '".(isset($_POST['prod_page_twitter']) ? $_POST['prod_page_twitter'] : 0)."',
prod_page_linkedin = '".(isset($_POST['prod_page_linkedin']) ? $_POST['prod_page_linkedin'] : 0)."',
prod_page_google = '".(isset($_POST['prod_page_google']) ? $_POST['prod_page_google'] : 0)."',
prod_page_pinterest = '".(isset($_POST['prod_page_pinterest']) ? $_POST['prod_page_pinterest'] : 0)."',
id_widget_logo_on = '".(isset($_POST['id_widget_logo_on']) ? $_POST['id_widget_logo_on'] : 0)."',
id_widget_link = '".$_POST['id_widget_link']."'
WHERE id = '1'";
$wpdb->query( $sql_update );
update_option('id_settings_notice', 'off');
}
}
if (isset($_POST['btnIgnSettings'])) {
echo '<div id="message" class="updated">Settings Saved</div>';
}
if (isset($_POST['btnActivateScriptPrice'])) {
$sql_script = "ALTER TABLE `".$wpdb->prefix."ign_pay_info` ADD `prod_price` VARCHAR( 200 ) NOT NULL AFTER `product_level`";
$wpdb->query( $sql_script );
// Getting all the previous records to modify them one by one to update prod_price
$sql_pay_info = "SELECT * FROM ".$wpdb->prefix."ign_pay_info";
$rows_pay_info = $wpdb->get_results($sql_pay_info);
// Looping through all the purchases and updating the new field accordingly
foreach ($rows_pay_info as $row_pay_info)
{
// Updating the record
$sql_update = "UPDATE ".$wpdb->prefix."ign_pay_info SET prod_price = '".getProductPrice($row_pay_info->product_level, $row_pay_info->product_id)."' WHERE id = '".$row_pay_info->id."'";
$wpdb->query($sql_update);
}
$message = '<div class="updated fade below-h2" id="message" class="updated"><p>Activated Successfully. You can now change price of product safely.</p></div>';
echo $message;
}
$data = getSettings();
if (isset($data)) {
if ($data->id_widget_link == "") {
$affiliate_link = "http://ignitiondeck.com";
}
else {
$affiliate_link = $data->id_widget_link;
}
}
else {
$affiliate_link = "http://ignitiondeck.com";
}
echo '<div class="wrap">
'.admin_menu_html()/*.'
<div class="icon32" id="icon-options-general"><br></div><h2>'.$tr_IgnitionDeck_Control_Panel.'</h2>'*/;
echo '<br />';
$sql_products = "SELECT * FROM ".$wpdb->prefix."ign_products";
$products = $wpdb->get_results($sql_products);
$site_url = site_url();
include_once 'templates/admin/_settingsIgnDeck.php';
}
/**
* Form settings for Admin area
* @global object $wpdb
*/
function form_settings(){
require 'languages/text_variables.php';
global $wpdb;
if(isset($_POST['submit'])){
$serializedForm = serialize($_POST['ignitiondeck_form']);
if($_POST['submit'] == $tr_Save_Settings){
$sql_insert="INSERT INTO ".$wpdb->prefix ."ign_form(form_settings) values ('".$serializedForm."')";
$res = $wpdb->query( $sql_insert );
$message = '<div class="updated fade below-h2" id="message" class="updated"><p>'.$tr_Settings_saved.'</p></div>';
echo $message;
}
if($_POST['submit'] == $tr_Update_Settings){
$sql_update="update ".$wpdb->prefix . "ign_form set form_settings='".$serializedForm."' where id='1'";
$res = $wpdb->query( $sql_update );
$message = '<div class="updated fade below-h2" id="message" class="updated"><p>'.$tr_Form_settings_successfully_updated.'</p></div>';
echo $message;
}
}
$sql="select * from ".$wpdb->prefix . "ign_form where id='1'";
$res1 = $wpdb->query( $sql );
$rows = $wpdb->get_results($sql);
$row = &$rows[0];
if($row != null){
$submit = 'Update Settings';
$form = unserialize( $row->form_settings );
}else{
$submit = 'Save Settings';
}
echo '<div class="wrap">
'.admin_menu_html();
include_once 'templates/admin/_formSettings.php';
echo '</div>';
}
/*
* Email settings combining both Aweber and Mailchinmp settings
*/
function email_settings() {
require 'languages/text_variables.php';
global $wpdb;
$inactive = get_option('id_email_inactive');
$aweber_check = 'SELECT * FROM '.$wpdb->prefix.'ign_aweber_settings WHERE id = "1"';
$aweber_res = $wpdb->get_row($aweber_check);
if (empty($aweber_res)) {
$aweber_new = true;
$aweber_res = new stdClass();
}
else {
$aweber_new = false;
$aweber_active = $aweber_res->is_active;
}
$mc_check = 'SELECT * FROM '.$wpdb->prefix.'ign_mailchimp_subscription WHERE id = "1"';
$mc_res = $wpdb->get_row($mc_check);
if (empty($mc_res)) {
$mc_new = true;
$mc_res = new stdClass();
}
else {
$mc_new = false;
$mc_active = $mc_res->is_active;
}
if (isset($_POST['submitEmailSettings'])) {
if (isset($_POST['mc_active'])) {
$mc_active = 1;
$aweber_active = 0;
$inactive = 0;
}
else if (isset($_POST['aweber_active'])) {
$mc_active = 0;
$aweber_active = 1;
$inactive = 0;
}
else {
$mc_active = 0;
$aweber_active = 0;
$inactive = 1;
}
$aweber_res->list_email = esc_attr($_POST['list_email']);
$mc_res->api_key = esc_attr($_POST['apikey']);
$mc_res->list_id = esc_attr($_POST['listid']);
//Condition for submission of Aweber Settings
if($aweber_new) {
$sql_insert = " INSERT INTO ".$wpdb->prefix . "ign_aweber_settings (list_email, is_active) VALUES ('".$aweber_res->list_email."','".($aweber_active ? '1' : '0')."')";
$res = $wpdb->query( $sql_insert );
//echo $sql_insert; exit;
}
else {
$sql_update = " UPDATE ".$wpdb->prefix . "ign_aweber_settings SET
list_email = '".$aweber_res->list_email."',
is_active = '".($aweber_active ? '1' : '0')."'
WHERE id = '1'";
$res = $wpdb->query( $sql_update );
}
//Condition for submission of Mailchimp Settings
$apiRegion = explode('-', $mc_res->api_key);
$apiRegion = (isset($apiRegion[1]))? $apiRegion[1] : '';
if($mc_new){
$sql="INSERT INTO ".$wpdb->prefix . "ign_mailchimp_subscription (api_key, list_id, region, is_active) VALUES ('".$mc_res->api_key."', '".$mc_res->list_id."', '".$apiRegion."', '".($mc_active ? '1' : '0')."')";
$res = $wpdb->query( $sql );
}
else {
$sql_update="update ".$wpdb->prefix . "ign_mailchimp_subscription set api_key='".$mc_res->api_key."',list_id='".$mc_res->list_id."', region='".$apiRegion."', is_active = '".($mc_active ? '1' : '0')."' where id='1'";
$res = $wpdb->query( $sql_update );
}
update_option('id_email_inactive', $inactive);
$message = '<div class="updated fade below-h2" id="message" class="updated"><p>'.$tr_Email_Settings_Saved.'</p></div>';
}
echo '<div class="wrap">
'.admin_menu_html();
include_once( "templates/admin/_emailSettings.php" );
echo '</div>';
}
/**
* Paypal Payment settings
* @global object $wpdb
*/
function paypal_payment_options() {
require 'languages/text_variables.php';
global $wpdb;
$tz = get_option('timezone_string');
if (empty($tz)) {
$tz = 'UTC';
}
date_default_timezone_set($tz);
if(isset($_POST['btnSaveAdaptivePayment'])){
if($_POST['btnSaveAdaptivePayment'] == $tr_Save_Settings) {
// check if it is first time data entered
$sql="SELECT * FROM ".$wpdb->prefix."ign_adaptive_pay_settings where id='1'";
$res = $wpdb->query( $sql );
$isFirstTime = ($res == 0)? true : false;
if (isset($_POST['sandbox_mode'])) {
$sandbox_mode = $_POST['sandbox_mode'];
}
else {
$sandbox_mode = '';
}
if($isFirstTime){
$sql="INSERT INTO ".$wpdb->prefix."ign_adaptive_pay_settings (id, paypal_email, app_id, api_username, api_password, api_signature, pre_approval_key, paypal_mode, fund_type)
VALUES (
1,
'".$_POST['adaptive_email']."',
'".$_POST['application_id']."',
'".$_POST['api_username']."',
'".$_POST['api_password']."',
'".$_POST['api_signature']."',
'',
'".$sandbox_mode."',
'".$_POST['fund_type']."'
)";
$res = $wpdb->query( $sql );
} else {
$sql="UPDATE ".$wpdb->prefix."ign_adaptive_pay_settings SET
paypal_email = '".$_POST['adaptive_email']."',
app_id='".$_POST['application_id']."',
api_username='".$_POST['api_username']."',
api_password='".$_POST['api_password']."',
api_signature='".$_POST['api_signature']."',
pre_approval_key = '',
paypal_mode = '".$sandbox_mode."',
fund_type = '".$_POST['fund_type']."'
WHERE id='1'";
$res = $wpdb->query( $sql );
}
// Check whether there is an entry in the selection table, if not make an entry\
// else update the selection table
// check if it is first time data entered
$sql_selection_table = "SELECT * FROM ".$wpdb->prefix . "ign_pay_selection WHERE id='1'";
$res = $wpdb->query( $sql_selection_table );
$isFirstTimeSelection = ($res == 0)? true : false;
if($isFirstTimeSelection) {
$sql="INSERT INTO ".$wpdb->prefix."ign_pay_selection (id, payment_gateway, modified_date) VALUES (1, '".$_POST['payment_gateway']."',
'".date('Y-m-d H:i:s')."')";
$res = $wpdb->query( $sql );
} else {
$sql="UPDATE ".$wpdb->prefix."ign_pay_selection SET payment_gateway = '".$_POST['payment_gateway']."', modified_date = '".date('Y-m-d H:i:s')."' WHERE id='1'";
$res = $wpdb->query( $sql );
}
$message = '<div class="updated fade below-h2" id="message" class="updated"><p>'.$tr_Payment_settings_saved.'</p></div>';
}
}
$sql="SELECT * FROM ".$wpdb->prefix . "ign_adaptive_pay_settings where id='1'";
$payment_settings = $wpdb->get_row( $sql );
//print_r($payment_settings);
if(isset($_POST['btnSavePaymentSettings'])) {
if($_POST['btnSavePaymentSettings'] == $tr_Save_Settings) {
// check if it is first time data entered
$sql="SELECT * FROM ".$wpdb->prefix . "ign_pay_settings where id='1'";
$res = $wpdb->query( $sql );
$isFirstTime = ($res == 0)? true : false;
if (!isset($_POST['paypal_override'])) {
$paypal_override = "";
}
else {
$paypal_override = $_POST['paypal_override'];
}
if (isset($_POST['paypal_mode'])) {
$test_mode = $_POST['paypal_mode'];
}
else {
$test_mode = '';
}
if($isFirstTime){
$sql="INSERT INTO ".$wpdb->prefix."ign_pay_settings (id, paypal_email, paypal_override, paypal_mode) VALUES (1, '".$_POST['paypal_email']."', '".$paypal_override."', '".$test_mode."')";
//echo $sql;
$res = $wpdb->query( $sql );
}else{
$sql="UPDATE ".$wpdb->prefix."ign_pay_settings set paypal_email='".$_POST['paypal_email']."', paypal_override='".$paypal_override."', paypal_mode='".$test_mode."' WHERE id='1'";
//echo $sql;
$res = $wpdb->query( $sql );
}
// Check whether there is an entry in the selection table, if not make an entry\
// else update the selection table
// check if it is first time data entered
$sql_selection_table = "SELECT * FROM ".$wpdb->prefix . "ign_pay_selection WHERE id='1'";
$res = $wpdb->query( $sql_selection_table );
$isFirstTimeSelection = ($res == 0)? true : false;
if($isFirstTimeSelection) {
$sql="INSERT INTO ".$wpdb->prefix."ign_pay_selection (id, payment_gateway, modified_date) VALUES (1, '".$_POST['payment_gateway']."',
'".date('Y-m-d H:i:s')."')";
$res = $wpdb->query( $sql );
} else {
$sql="UPDATE ".$wpdb->prefix."ign_pay_selection SET payment_gateway = '".$_POST['payment_gateway']."', modified_date = '".date('Y-m-d H:i:s')."' WHERE id='1'";
$res = $wpdb->query( $sql );
}
$message = '<div class="updated fade below-h2" id="message" class="updated"><p>'.$tr_Payment_settings_saved.'</p></div>';
}
}
$sql="SELECT * FROM ".$wpdb->prefix . "ign_pay_settings where id='1'";
$res = $wpdb->query( $sql );
$isFirstTime = ( $res == 0 )? true: false;
$items = $wpdb->get_results($sql);
$item = &$items[0];
// Selection the payment selection from the table 'ign_pay_selection'
$sql = "SELECT * FROM ".$wpdb->prefix."ign_pay_selection WHERE id = '1'";
$payment_select_data = $wpdb->get_row($sql);
if (isset($payment_select_data) && $payment_select_data->payment_gateway == "standard_paypal") {
$selected_standard = 'selected="selected"';
$selected_adaptive = "";
}
else if (isset($payment_select_data) && $payment_select_data->payment_gateway == "adaptive_paypal") {
$selected_standard = "";
$selected_adaptive = 'selected="selected"';
}
else {
$selected_standard = "";
$selected_adaptive = "";
}
echo '<div class="wrap">
'.admin_menu_html();
include_once 'templates/admin/_paymentSelection.php';
echo '<h3>Other Payment Settings</h3>';
do_action('id_paysettings_links');
echo '</div>';
}
function deck_builder() {
require 'languages/text_variables.php';
if (isset($_POST['deck_submit'])) {
$attrs = array();
foreach ($_POST as $k=>$v) {
if ($k !== 'deck_submit' && $k !== 'deck_select') {
if ($k == 'deck_title') {
$attrs[$k] = esc_attr($v);
}
else {
$attrs[$k] = absint($v);
}
}
}
if ($_POST['deck_select'] > 0) {
// update saved deck
$deck_id = absint($_POST['deck_select']);
Deck::update_deck($attrs, $deck_id);
}
else {
// new deck, insert
$new = Deck::create_deck($attrs);
}
}
else if (isset($_POST['deck_delete'])) {
$deck_id = absint($_POST['deck_select']);
Deck::delete_deck($deck_id);
}
echo '<div class="wrap">';
echo admin_menu_html();
include 'templates/admin/_deckBuilder.php';
echo '</div>';
}
/**
* Order Details
* @global object $wpdb
*/
function order_details(){
require 'languages/text_variables.php';
global $wpdb;
//$total_count = mysql_num_rows(mysql_query("SELECT * FROM ".$wpdb->prefix."ign_pay_info")); // number of total rows in the database
$sql_products = "SELECT * FROM ".$wpdb->prefix."ign_products";
$products = $wpdb->get_results($sql_products);
echo '<div class="wrap">
'.admin_menu_html();
include_once 'templates/admin/_orderDetails.php';
echo '</div>';
}
/*
* Function for editing Order
*/
function edit_order() {
require 'languages/text_variables.php';
$orderid = $_GET['orderid'];
global $wpdb;
$sql = "SELECT * FROM ".$wpdb->prefix."ign_pay_info WHERE id = '".$orderid."'";
$order_data = $wpdb->get_row( $sql );
$sql_prods = "SELECT * FROM ".$wpdb->prefix."ign_products";
$products = $wpdb->get_results( $sql_prods );
echo '<div class="wrap">
'.admin_menu_html();
include_once 'templates/admin/_orderEdit.php';
echo '</div>';
}
/*
* function for updating order on submission of form
*/
function update_order() {
if ( isset($_POST['btnUpdateOrder']) ) {
global $wpdb;
$orderid = $_GET['orderid'];
if (isset($_POST['manual-input']) && $_POST['manual-input'] !== "") {
$price = $_POST['manual-input'];
}
else {
$price = $_POST['prod_price'];
}
$sql = "UPDATE ".$wpdb->prefix."ign_pay_info SET
first_name = '".$_POST['first_name']."',
last_name = '".$_POST['last_name']."',
email = '".$_POST['email']."',
address = '".$_POST['address']."',
country = '".$_POST['country']."',
state = '".$_POST['state']."',
city = '".$_POST['city']."',
zip = '".$_POST['zip']."',
status = '".$_POST['status']."',
product_id = '".$_POST['product_id']."',
product_level = '".$_POST['product_level']."',
prod_price = '".$price."'
WHERE id = '".$_GET['orderid']."'
";
$wpdb->query( $sql );
wp_redirect( "admin.php?page=order_details" );
do_action('id_order_update', $orderid);
exit;
}
}
add_action('init', 'update_order');
/*
* function for viewing order
*/
function view_order() {
$orderid = $_GET['orderid'];
$order = new ID_Order($orderid);
$order_data = $order->get_order();
$project = new ID_Project($order_data->product_id);
$product_data = $project->the_project();
$post_id = $project->get_project_postid();
if ($order_data->product_level == 1) {
$level_price = $product_data->product_price;
$level_desc = $product_data->product_details;
} else {
$product_level = (int)($order_data->product_level);
$level_price = get_post_meta( $post_id, $name="ign_product_level_".$product_level."_price", true );
$level_desc = get_post_meta( $post_id, $name="ign_product_level_".$product_level."_desc", true );
}
require 'languages/text_variables.php';
echo '<div class="wrap">
'.admin_menu_html();
include_once 'templates/admin/_orderView.php';
echo '</div>';
}
/*
* Function for deleting Order
*/
function delete_order() {
global $wpdb;
$orderid = $_GET['orderid'];
do_action('id_pre_order_delete', $orderid);
$sql = "DELETE FROM ".$wpdb->prefix."ign_pay_info WHERE id = '".$orderid."'";
$wpdb->query( $sql );
do_action('id_order_delete', $orderid);
echo '<script type="text/javascript">window.location = "admin.php?page=order_details";</script>';
exit;
}
/*
* Manually add order
*/
function add_order() {
require 'languages/text_variables.php';
global $wpdb;
$tz = get_option('timezone_string');
if (empty($tz)) {
$tz = 'UTC';
}
date_default_timezone_set($tz);
$cancel_hook = false;
if ( isset($_POST['btnAddOrder']) ) {
if (isset($_POST['manual-input']) && $_POST['manual-input'] !== "") {
$price = esc_attr(str_replace(',', '', $_POST['manual-input']));
}
else {
$price = esc_attr($_POST['prod_price']);
}
if (isset($_POST['cancel-hook'])) {
$cancel_hook = true;
}
$sql = "INSERT INTO ".$wpdb->prefix."ign_pay_info
(first_name,last_name,email,address,country,state,city,zip,product_id,product_level,prod_price,status,created_at)
VALUES (
'".esc_attr($_POST['first_name'])."',
'".esc_attr($_POST['last_name'])."',
'".esc_attr($_POST['email'])."',
'".esc_attr($_POST['address'])."',
'".esc_attr($_POST['country'])."',
'".esc_attr($_POST['state'])."',
'".esc_attr($_POST['city'])."',
'".esc_attr($_POST['zip'])."',
'".absint($_POST['product_id'])."',
'".absint($_POST['product_level'])."',
'".esc_attr($price)."',
'".esc_attr($_POST['status'])."',
'".date('Y-m-d H:i:s')."'
)";
$wpdb->query( $sql );
$pay_info_id = $wpdb->insert_id;
if (!$cancel_hook) {
do_action('id_payment_success', $pay_info_id);
}
$product_settings = getProductSettings($_POST['product_id']);
$mailchip_settings = getMailchimpSettings();
$aweber_settings = getAweberSettings();
echo '<script type="text/javascript">window.location = "admin.php?page=order_details";</script>'; //wp_redirect( "admin.php?page=order_details" );
exit;
}
$products = ID_Project::get_all_projects();
//print_r($products);
echo '<div class="wrap">
'.admin_menu_html();
include_once 'templates/admin/_orderAdd.php';
echo '</div>';
}
/*
* Refund Paypal
*/
function refund_order() {
global $wpdb;