@@ -289,12 +289,12 @@ discard block |
||
289 | 289 | wp_enqueue_script('thickbox'); |
290 | 290 | wp_register_script( |
291 | 291 | 'organization_settings', |
292 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
292 | + GEN_SET_ASSETS_URL.'your_organization_settings.js', |
|
293 | 293 | array('jquery', 'media-upload', 'thickbox'), |
294 | 294 | EVENT_ESPRESSO_VERSION, |
295 | 295 | true |
296 | 296 | ); |
297 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
297 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
298 | 298 | wp_enqueue_script('organization_settings'); |
299 | 299 | wp_enqueue_style('organization-css'); |
300 | 300 | $confirm_image_delete = array( |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | // scripts |
316 | 316 | wp_register_script( |
317 | 317 | 'gen_settings_countries', |
318 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
318 | + GEN_SET_ASSETS_URL.'gen_settings_countries.js', |
|
319 | 319 | array('ee_admin_js'), |
320 | 320 | EVENT_ESPRESSO_VERSION, |
321 | 321 | true |
322 | 322 | ); |
323 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
323 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL.'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
324 | 324 | wp_enqueue_script('gen_settings_countries'); |
325 | 325 | wp_enqueue_style('organization-css'); |
326 | 326 | } |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
371 | 371 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
372 | 372 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
373 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
373 | + GEN_SET_TEMPLATE_PATH.'espresso_page_settings.template.php', |
|
374 | 374 | $this->_template_args, |
375 | 375 | true |
376 | 376 | ); |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | { |
535 | 535 | try { |
536 | 536 | $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
537 | - $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]); |
|
537 | + $admin_options_settings_form->process($this->_req_data[$admin_options_settings_form->slug()]); |
|
538 | 538 | EE_Registry::instance()->CFG->admin = apply_filters( |
539 | 539 | 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
540 | 540 | EE_Registry::instance()->CFG->admin |
@@ -625,7 +625,7 @@ discard block |
||
625 | 625 | $this->_set_add_edit_form_tags('update_country_settings'); |
626 | 626 | $this->_set_publish_post_box_vars(null, false, false, null, false); |
627 | 627 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
628 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
628 | + GEN_SET_TEMPLATE_PATH.'countries_settings.template.php', |
|
629 | 629 | $this->_template_args, |
630 | 630 | true |
631 | 631 | ); |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | $CNT_ISO = isset($this->_req_data['country']) |
649 | 649 | ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
650 | 650 | : $CNT_ISO; |
651 | - if (! $CNT_ISO) { |
|
651 | + if ( ! $CNT_ISO) { |
|
652 | 652 | return ''; |
653 | 653 | } |
654 | 654 | |
@@ -666,59 +666,59 @@ discard block |
||
666 | 666 | $country_input_types = array( |
667 | 667 | 'CNT_active' => array( |
668 | 668 | 'type' => 'RADIO_BTN', |
669 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
669 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
670 | 670 | 'class' => '', |
671 | 671 | 'options' => $this->_yes_no_values, |
672 | 672 | 'use_desc_4_label' => true, |
673 | 673 | ), |
674 | 674 | 'CNT_ISO' => array( |
675 | 675 | 'type' => 'TEXT', |
676 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
676 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
677 | 677 | 'class' => 'small-text', |
678 | 678 | ), |
679 | 679 | 'CNT_ISO3' => array( |
680 | 680 | 'type' => 'TEXT', |
681 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
681 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
682 | 682 | 'class' => 'small-text', |
683 | 683 | ), |
684 | 684 | 'RGN_ID' => array( |
685 | 685 | 'type' => 'TEXT', |
686 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
686 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
687 | 687 | 'class' => 'small-text', |
688 | 688 | ), |
689 | 689 | 'CNT_name' => array( |
690 | 690 | 'type' => 'TEXT', |
691 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
691 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
692 | 692 | 'class' => 'regular-text', |
693 | 693 | ), |
694 | 694 | 'CNT_cur_code' => array( |
695 | 695 | 'type' => 'TEXT', |
696 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
696 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
697 | 697 | 'class' => 'small-text', |
698 | 698 | 'disabled' => $CNT_cur_disabled |
699 | 699 | ), |
700 | 700 | 'CNT_cur_single' => array( |
701 | 701 | 'type' => 'TEXT', |
702 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
702 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
703 | 703 | 'class' => 'medium-text', |
704 | 704 | 'disabled' => $CNT_cur_disabled |
705 | 705 | ), |
706 | 706 | 'CNT_cur_plural' => array( |
707 | 707 | 'type' => 'TEXT', |
708 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
708 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
709 | 709 | 'class' => 'medium-text', |
710 | 710 | 'disabled' => $CNT_cur_disabled |
711 | 711 | ), |
712 | 712 | 'CNT_cur_sign' => array( |
713 | 713 | 'type' => 'TEXT', |
714 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
714 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
715 | 715 | 'class' => 'small-text', |
716 | 716 | 'htmlentities' => false, |
717 | 717 | 'disabled' => $CNT_cur_disabled |
718 | 718 | ), |
719 | 719 | 'CNT_cur_sign_b4' => array( |
720 | 720 | 'type' => 'RADIO_BTN', |
721 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
721 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
722 | 722 | 'class' => '', |
723 | 723 | 'options' => $this->_yes_no_values, |
724 | 724 | 'use_desc_4_label' => true, |
@@ -726,7 +726,7 @@ discard block |
||
726 | 726 | ), |
727 | 727 | 'CNT_cur_dec_plc' => array( |
728 | 728 | 'type' => 'RADIO_BTN', |
729 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
729 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
730 | 730 | 'class' => '', |
731 | 731 | 'options' => array( |
732 | 732 | array('id' => 0, 'text' => ''), |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | ), |
739 | 739 | 'CNT_cur_dec_mrk' => array( |
740 | 740 | 'type' => 'RADIO_BTN', |
741 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
741 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
742 | 742 | 'class' => '', |
743 | 743 | 'options' => array( |
744 | 744 | array( |
@@ -752,7 +752,7 @@ discard block |
||
752 | 752 | ), |
753 | 753 | 'CNT_cur_thsnds' => array( |
754 | 754 | 'type' => 'RADIO_BTN', |
755 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
755 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
756 | 756 | 'class' => '', |
757 | 757 | 'options' => array( |
758 | 758 | array( |
@@ -766,12 +766,12 @@ discard block |
||
766 | 766 | ), |
767 | 767 | 'CNT_tel_code' => array( |
768 | 768 | 'type' => 'TEXT', |
769 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
769 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
770 | 770 | 'class' => 'small-text', |
771 | 771 | ), |
772 | 772 | 'CNT_is_EU' => array( |
773 | 773 | 'type' => 'RADIO_BTN', |
774 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
774 | + 'input_name' => 'cntry['.$CNT_ISO.']', |
|
775 | 775 | 'class' => '', |
776 | 776 | 'options' => $this->_yes_no_values, |
777 | 777 | 'use_desc_4_label' => true, |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | $country_input_types |
783 | 783 | ); |
784 | 784 | $country_details_settings = EEH_Template::display_template( |
785 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
785 | + GEN_SET_TEMPLATE_PATH.'country_details_settings.template.php', |
|
786 | 786 | $this->_template_args, |
787 | 787 | true |
788 | 788 | ); |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | |
817 | 817 | $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO; |
818 | 818 | |
819 | - if (! $CNT_ISO) { |
|
819 | + if ( ! $CNT_ISO) { |
|
820 | 820 | return ''; |
821 | 821 | } |
822 | 822 | // for ajax |
@@ -833,22 +833,22 @@ discard block |
||
833 | 833 | $state_input_types = array( |
834 | 834 | 'STA_abbrev' => array( |
835 | 835 | 'type' => 'TEXT', |
836 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
836 | + 'input_name' => 'states['.$STA_ID.']', |
|
837 | 837 | 'class' => 'mid-text', |
838 | 838 | ), |
839 | 839 | 'STA_name' => array( |
840 | 840 | 'type' => 'TEXT', |
841 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
841 | + 'input_name' => 'states['.$STA_ID.']', |
|
842 | 842 | 'class' => 'regular-text', |
843 | 843 | ), |
844 | 844 | 'STA_active' => array( |
845 | 845 | 'type' => 'RADIO_BTN', |
846 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
846 | + 'input_name' => 'states['.$STA_ID.']', |
|
847 | 847 | 'options' => $this->_yes_no_values, |
848 | 848 | 'use_desc_4_label' => true, |
849 | 849 | ), |
850 | 850 | ); |
851 | - $this->_template_args['states'][ $STA_ID ]['inputs'] = |
|
851 | + $this->_template_args['states'][$STA_ID]['inputs'] = |
|
852 | 852 | EE_Question_Form_Input::generate_question_form_inputs_for_object( |
853 | 853 | $state, |
854 | 854 | $state_input_types |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | 'CNT_ISO' => $CNT_ISO, |
860 | 860 | 'STA_abbrev' => $state->abbrev(), |
861 | 861 | ); |
862 | - $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = |
|
862 | + $this->_template_args['states'][$STA_ID]['delete_state_url'] = |
|
863 | 863 | EE_Admin_Page::add_query_args_and_nonce( |
864 | 864 | $query_args, |
865 | 865 | GEN_SET_ADMIN_URL |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | ); |
877 | 877 | |
878 | 878 | $state_details_settings = EEH_Template::display_template( |
879 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
879 | + GEN_SET_TEMPLATE_PATH.'state_details_settings.template.php', |
|
880 | 880 | $this->_template_args, |
881 | 881 | true |
882 | 882 | ); |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
913 | 913 | ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
914 | 914 | : false; |
915 | - if (! $CNT_ISO) { |
|
915 | + if ( ! $CNT_ISO) { |
|
916 | 916 | EE_Error::add_error( |
917 | 917 | __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
918 | 918 | __FILE__, |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
925 | 925 | ? sanitize_text_field($this->_req_data['STA_abbrev']) |
926 | 926 | : false; |
927 | - if (! $STA_abbrev) { |
|
927 | + if ( ! $STA_abbrev) { |
|
928 | 928 | EE_Error::add_error( |
929 | 929 | __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
930 | 930 | __FILE__, |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | $STA_name = isset($this->_req_data['STA_name']) |
937 | 937 | ? sanitize_text_field($this->_req_data['STA_name']) |
938 | 938 | : false; |
939 | - if (! $STA_name) { |
|
939 | + if ( ! $STA_name) { |
|
940 | 940 | EE_Error::add_error( |
941 | 941 | __('No State name or an invalid State name was received.', 'event_espresso'), |
942 | 942 | __FILE__, |
@@ -986,7 +986,7 @@ discard block |
||
986 | 986 | $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
987 | 987 | ? sanitize_text_field($this->_req_data['STA_abbrev']) |
988 | 988 | : false; |
989 | - if (! $STA_ID) { |
|
989 | + if ( ! $STA_ID) { |
|
990 | 990 | EE_Error::add_error( |
991 | 991 | __('No State ID or an invalid State ID was received.', 'event_espresso'), |
992 | 992 | __FILE__, |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | $CNT_ISO = isset($this->_req_data['country']) |
1036 | 1036 | ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
1037 | 1037 | : false; |
1038 | - if (! $CNT_ISO) { |
|
1038 | + if ( ! $CNT_ISO) { |
|
1039 | 1039 | EE_Error::add_error( |
1040 | 1040 | __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
1041 | 1041 | __FILE__, |
@@ -1046,63 +1046,63 @@ discard block |
||
1046 | 1046 | return; |
1047 | 1047 | } |
1048 | 1048 | $cols_n_values = array(); |
1049 | - $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']) |
|
1050 | - ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])) |
|
1049 | + $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3']) |
|
1050 | + ? strtoupper(sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_ISO3'])) |
|
1051 | 1051 | : false; |
1052 | - $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1053 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1052 | + $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
1053 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['RGN_ID']) |
|
1054 | 1054 | : null; |
1055 | - $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1056 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1055 | + $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
1056 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_name']) |
|
1057 | 1057 | : null; |
1058 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) { |
|
1058 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code'])) { |
|
1059 | 1059 | $cols_n_values['CNT_cur_code'] = strtoupper( |
1060 | - sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code']) |
|
1060 | + sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_code']) |
|
1061 | 1061 | ); |
1062 | 1062 | } |
1063 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) { |
|
1063 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'])) { |
|
1064 | 1064 | $cols_n_values['CNT_cur_single'] = sanitize_text_field( |
1065 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'] |
|
1065 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_single'] |
|
1066 | 1066 | ); |
1067 | 1067 | } |
1068 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) { |
|
1068 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'])) { |
|
1069 | 1069 | $cols_n_values['CNT_cur_plural'] = sanitize_text_field( |
1070 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'] |
|
1070 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_plural'] |
|
1071 | 1071 | ); |
1072 | 1072 | } |
1073 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) { |
|
1073 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'])) { |
|
1074 | 1074 | $cols_n_values['CNT_cur_sign'] = sanitize_text_field( |
1075 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'] |
|
1075 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign'] |
|
1076 | 1076 | ); |
1077 | 1077 | } |
1078 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) { |
|
1078 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'])) { |
|
1079 | 1079 | $cols_n_values['CNT_cur_sign_b4'] = absint( |
1080 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'] |
|
1080 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_sign_b4'] |
|
1081 | 1081 | ); |
1082 | 1082 | } |
1083 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) { |
|
1083 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'])) { |
|
1084 | 1084 | $cols_n_values['CNT_cur_dec_plc'] = absint( |
1085 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'] |
|
1085 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_plc'] |
|
1086 | 1086 | ); |
1087 | 1087 | } |
1088 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) { |
|
1088 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'])) { |
|
1089 | 1089 | $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field( |
1090 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'] |
|
1090 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_dec_mrk'] |
|
1091 | 1091 | ); |
1092 | 1092 | } |
1093 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) { |
|
1093 | + if (isset($this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'])) { |
|
1094 | 1094 | $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field( |
1095 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'] |
|
1095 | + $this->_req_data['cntry'][$CNT_ISO]['CNT_cur_thsnds'] |
|
1096 | 1096 | ); |
1097 | 1097 | } |
1098 | - $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1099 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1098 | + $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
1099 | + ? sanitize_text_field($this->_req_data['cntry'][$CNT_ISO]['CNT_tel_code']) |
|
1100 | 1100 | : null; |
1101 | - $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1102 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1101 | + $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
1102 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_is_EU']) |
|
1103 | 1103 | : false; |
1104 | - $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1105 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1104 | + $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
1105 | + ? absint($this->_req_data['cntry'][$CNT_ISO]['CNT_active']) |
|
1106 | 1106 | : false; |
1107 | 1107 | // allow filtering of country data |
1108 | 1108 | $cols_n_values = apply_filters( |
@@ -1179,7 +1179,7 @@ discard block |
||
1179 | 1179 | return ' |
1180 | 1180 | <tr> |
1181 | 1181 | <th> |
1182 | - ' . $label . ' |
|
1182 | + ' . $label.' |
|
1183 | 1183 | </th>'; |
1184 | 1184 | } |
1185 | 1185 | |
@@ -1195,7 +1195,7 @@ discard block |
||
1195 | 1195 | { |
1196 | 1196 | return ' |
1197 | 1197 | <td class="general-settings-country-input-td"> |
1198 | - ' . $input . ' |
|
1198 | + ' . $input.' |
|
1199 | 1199 | </td> |
1200 | 1200 | </tr>'; |
1201 | 1201 | } |
@@ -1226,7 +1226,7 @@ discard block |
||
1226 | 1226 | { |
1227 | 1227 | return ' |
1228 | 1228 | <td class="general-settings-country-state-input-td"> |
1229 | - ' . $input . ' |
|
1229 | + ' . $input.' |
|
1230 | 1230 | </td>'; |
1231 | 1231 | } |
1232 | 1232 | |
@@ -1252,7 +1252,7 @@ discard block |
||
1252 | 1252 | . __('Edit', 'event_espresso') |
1253 | 1253 | . '</a>'; |
1254 | 1254 | $links .= ' | '; |
1255 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>'; |
|
1255 | + $links .= '<a href="'.get_permalink($ee_page_id).'" >'.__('View', 'event_espresso').'</a>'; |
|
1256 | 1256 | |
1257 | 1257 | return $links; |
1258 | 1258 | } |
@@ -1285,9 +1285,9 @@ discard block |
||
1285 | 1285 | $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), ' '); |
1286 | 1286 | } |
1287 | 1287 | |
1288 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
1288 | + return '<span style="color:'.$pg_colour.'; margin-right:2em;"><strong>' |
|
1289 | 1289 | . $pg_status |
1290 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
1290 | + . '</strong></span><span style="color:'.$sc_colour.'"><strong>'.$sc_status.'</strong></span>'; |
|
1291 | 1291 | } |
1292 | 1292 | |
1293 | 1293 |
@@ -21,1347 +21,1347 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * _question_group |
|
26 | - * holds the specific question group object for the question group details screen |
|
27 | - * |
|
28 | - * @var object |
|
29 | - */ |
|
30 | - protected $_question_group; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Initialize basic properties. |
|
35 | - */ |
|
36 | - protected function _init_page_props() |
|
37 | - { |
|
38 | - $this->page_slug = GEN_SET_PG_SLUG; |
|
39 | - $this->page_label = GEN_SET_LABEL; |
|
40 | - $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
41 | - $this->_admin_base_path = GEN_SET_ADMIN; |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * Set ajax hooks |
|
47 | - */ |
|
48 | - protected function _ajax_hooks() |
|
49 | - { |
|
50 | - add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings')); |
|
51 | - add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states')); |
|
52 | - add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3); |
|
53 | - add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state')); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * More page properties initialization. |
|
59 | - */ |
|
60 | - protected function _define_page_props() |
|
61 | - { |
|
62 | - $this->_admin_page_title = GEN_SET_LABEL; |
|
63 | - $this->_labels = array( |
|
64 | - 'publishbox' => __('Update Settings', 'event_espresso'), |
|
65 | - ); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Set page routes property. |
|
71 | - */ |
|
72 | - protected function _set_page_routes() |
|
73 | - { |
|
74 | - $this->_page_routes = array( |
|
75 | - |
|
76 | - 'critical_pages' => array( |
|
77 | - 'func' => '_espresso_page_settings', |
|
78 | - 'capability' => 'manage_options', |
|
79 | - ), |
|
80 | - 'update_espresso_page_settings' => array( |
|
81 | - 'func' => '_update_espresso_page_settings', |
|
82 | - 'capability' => 'manage_options', |
|
83 | - 'noheader' => true, |
|
84 | - ), |
|
85 | - 'default' => array( |
|
86 | - 'func' => '_your_organization_settings', |
|
87 | - 'capability' => 'manage_options', |
|
88 | - ), |
|
89 | - |
|
90 | - 'update_your_organization_settings' => array( |
|
91 | - 'func' => '_update_your_organization_settings', |
|
92 | - 'capability' => 'manage_options', |
|
93 | - 'noheader' => true, |
|
94 | - ), |
|
95 | - |
|
96 | - 'admin_option_settings' => array( |
|
97 | - 'func' => '_admin_option_settings', |
|
98 | - 'capability' => 'manage_options', |
|
99 | - ), |
|
100 | - |
|
101 | - 'update_admin_option_settings' => array( |
|
102 | - 'func' => '_update_admin_option_settings', |
|
103 | - 'capability' => 'manage_options', |
|
104 | - 'noheader' => true, |
|
105 | - ), |
|
106 | - |
|
107 | - 'country_settings' => array( |
|
108 | - 'func' => '_country_settings', |
|
109 | - 'capability' => 'manage_options', |
|
110 | - ), |
|
111 | - |
|
112 | - 'update_country_settings' => array( |
|
113 | - 'func' => '_update_country_settings', |
|
114 | - 'capability' => 'manage_options', |
|
115 | - 'noheader' => true, |
|
116 | - ), |
|
117 | - |
|
118 | - 'display_country_settings' => array( |
|
119 | - 'func' => 'display_country_settings', |
|
120 | - 'capability' => 'manage_options', |
|
121 | - 'noheader' => true, |
|
122 | - ), |
|
123 | - |
|
124 | - 'add_new_state' => array( |
|
125 | - 'func' => 'add_new_state', |
|
126 | - 'capability' => 'manage_options', |
|
127 | - 'noheader' => true, |
|
128 | - ), |
|
129 | - |
|
130 | - 'delete_state' => array( |
|
131 | - 'func' => 'delete_state', |
|
132 | - 'capability' => 'manage_options', |
|
133 | - 'noheader' => true, |
|
134 | - ), |
|
135 | - 'privacy_settings' => array( |
|
136 | - 'func' => 'privacySettings', |
|
137 | - 'capability' => 'manage_options', |
|
138 | - ), |
|
139 | - 'update_privacy_settings' => array( |
|
140 | - 'func' => 'updatePrivacySettings', |
|
141 | - 'capability' => 'manage_options', |
|
142 | - 'noheader' => true, |
|
143 | - 'headers_sent_route' => 'privacy_settings' |
|
144 | - ) |
|
145 | - ); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * Set page configuration property |
|
151 | - */ |
|
152 | - protected function _set_page_config() |
|
153 | - { |
|
154 | - $this->_page_config = array( |
|
155 | - 'critical_pages' => array( |
|
156 | - 'nav' => array( |
|
157 | - 'label' => __('Critical Pages', 'event_espresso'), |
|
158 | - 'order' => 50, |
|
159 | - ), |
|
160 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
161 | - 'help_tabs' => array( |
|
162 | - 'general_settings_critical_pages_help_tab' => array( |
|
163 | - 'title' => __('Critical Pages', 'event_espresso'), |
|
164 | - 'filename' => 'general_settings_critical_pages', |
|
165 | - ), |
|
166 | - ), |
|
167 | - 'help_tour' => array('Critical_Pages_Help_Tour'), |
|
168 | - 'require_nonce' => false, |
|
169 | - ), |
|
170 | - 'default' => array( |
|
171 | - 'nav' => array( |
|
172 | - 'label' => __('Your Organization', 'event_espresso'), |
|
173 | - 'order' => 20, |
|
174 | - ), |
|
175 | - 'help_tabs' => array( |
|
176 | - 'general_settings_your_organization_help_tab' => array( |
|
177 | - 'title' => __('Your Organization', 'event_espresso'), |
|
178 | - 'filename' => 'general_settings_your_organization', |
|
179 | - ), |
|
180 | - ), |
|
181 | - 'help_tour' => array('Your_Organization_Help_Tour'), |
|
182 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
183 | - 'require_nonce' => false, |
|
184 | - ), |
|
185 | - 'admin_option_settings' => array( |
|
186 | - 'nav' => array( |
|
187 | - 'label' => __('Admin Options', 'event_espresso'), |
|
188 | - 'order' => 60, |
|
189 | - ), |
|
190 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
191 | - 'help_tabs' => array( |
|
192 | - 'general_settings_admin_options_help_tab' => array( |
|
193 | - 'title' => __('Admin Options', 'event_espresso'), |
|
194 | - 'filename' => 'general_settings_admin_options', |
|
195 | - ), |
|
196 | - ), |
|
197 | - 'help_tour' => array('Admin_Options_Help_Tour'), |
|
198 | - 'require_nonce' => false, |
|
199 | - ), |
|
200 | - 'country_settings' => array( |
|
201 | - 'nav' => array( |
|
202 | - 'label' => __('Countries', 'event_espresso'), |
|
203 | - 'order' => 70, |
|
204 | - ), |
|
205 | - 'help_tabs' => array( |
|
206 | - 'general_settings_countries_help_tab' => array( |
|
207 | - 'title' => __('Countries', 'event_espresso'), |
|
208 | - 'filename' => 'general_settings_countries', |
|
209 | - ), |
|
210 | - ), |
|
211 | - 'help_tour' => array('Countries_Help_Tour'), |
|
212 | - 'require_nonce' => false, |
|
213 | - ), |
|
214 | - 'privacy_settings' => array( |
|
215 | - 'nav' => array( |
|
216 | - 'label' => esc_html__('Privacy', 'event_espresso'), |
|
217 | - 'order' => 80 |
|
218 | - ), |
|
219 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
220 | - 'require_nonce' => false |
|
221 | - ) |
|
222 | - ); |
|
223 | - } |
|
224 | - |
|
225 | - |
|
226 | - protected function _add_screen_options() |
|
227 | - { |
|
228 | - } |
|
229 | - |
|
230 | - protected function _add_feature_pointers() |
|
231 | - { |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
237 | - */ |
|
238 | - public function load_scripts_styles() |
|
239 | - { |
|
240 | - // styles |
|
241 | - wp_enqueue_style('espresso-ui-theme'); |
|
242 | - // scripts |
|
243 | - wp_enqueue_script('ee_admin_js'); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Execute logic running on `admin_init` |
|
249 | - */ |
|
250 | - public function admin_init() |
|
251 | - { |
|
252 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = __( |
|
253 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
254 | - 'event_espresso' |
|
255 | - ); |
|
256 | - EE_Registry::$i18n_js_strings['error_occurred'] = __( |
|
257 | - 'An error occurred! Please refresh the page and try again.', |
|
258 | - 'event_espresso' |
|
259 | - ); |
|
260 | - EE_Registry::$i18n_js_strings['confirm_delete_state'] = __( |
|
261 | - 'Are you sure you want to delete this State / Province?', |
|
262 | - 'event_espresso' |
|
263 | - ); |
|
264 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
265 | - EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
266 | - 'admin-ajax.php?page=espresso_general_settings', |
|
267 | - $protocol |
|
268 | - ); |
|
269 | - } |
|
270 | - |
|
271 | - public function admin_notices() |
|
272 | - { |
|
273 | - } |
|
274 | - |
|
275 | - public function admin_footer_scripts() |
|
276 | - { |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Enqueue scripts and styles for the default route. |
|
282 | - */ |
|
283 | - public function load_scripts_styles_default() |
|
284 | - { |
|
285 | - // styles |
|
286 | - wp_enqueue_style('thickbox'); |
|
287 | - // scripts |
|
288 | - wp_enqueue_script('media-upload'); |
|
289 | - wp_enqueue_script('thickbox'); |
|
290 | - wp_register_script( |
|
291 | - 'organization_settings', |
|
292 | - GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
293 | - array('jquery', 'media-upload', 'thickbox'), |
|
294 | - EVENT_ESPRESSO_VERSION, |
|
295 | - true |
|
296 | - ); |
|
297 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
298 | - wp_enqueue_script('organization_settings'); |
|
299 | - wp_enqueue_style('organization-css'); |
|
300 | - $confirm_image_delete = array( |
|
301 | - 'text' => __( |
|
302 | - 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
303 | - 'event_espresso' |
|
304 | - ), |
|
305 | - ); |
|
306 | - wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * Enqueue scripts and styles for the country settings route. |
|
312 | - */ |
|
313 | - public function load_scripts_styles_country_settings() |
|
314 | - { |
|
315 | - // scripts |
|
316 | - wp_register_script( |
|
317 | - 'gen_settings_countries', |
|
318 | - GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
319 | - array('ee_admin_js'), |
|
320 | - EVENT_ESPRESSO_VERSION, |
|
321 | - true |
|
322 | - ); |
|
323 | - wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
324 | - wp_enqueue_script('gen_settings_countries'); |
|
325 | - wp_enqueue_style('organization-css'); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /************* Espresso Pages *************/ |
|
330 | - /** |
|
331 | - * _espresso_page_settings |
|
332 | - * |
|
333 | - * @throws \EE_Error |
|
334 | - * @throws DomainException |
|
335 | - * @throws DomainException |
|
336 | - * @throws InvalidDataTypeException |
|
337 | - * @throws InvalidArgumentException |
|
338 | - */ |
|
339 | - protected function _espresso_page_settings() |
|
340 | - { |
|
341 | - // Check to make sure all of the main pages are setup properly, |
|
342 | - // if not create the default pages and display an admin notice |
|
343 | - EEH_Activation::verify_default_pages_exist(); |
|
344 | - $this->_transient_garbage_collection(); |
|
345 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
346 | - $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
347 | - ? EE_Registry::instance()->CFG->core->reg_page_id |
|
348 | - : null; |
|
349 | - $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
350 | - ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) |
|
351 | - : false; |
|
352 | - $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
353 | - ? EE_Registry::instance()->CFG->core->txn_page_id |
|
354 | - : null; |
|
355 | - $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
356 | - ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) |
|
357 | - : false; |
|
358 | - $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
359 | - ? EE_Registry::instance()->CFG->core->thank_you_page_id |
|
360 | - : null; |
|
361 | - $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
362 | - ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
363 | - : false; |
|
364 | - $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
365 | - ? EE_Registry::instance()->CFG->core->cancel_page_id |
|
366 | - : null; |
|
367 | - $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
368 | - ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
369 | - : false; |
|
370 | - $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
371 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
372 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
373 | - GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
374 | - $this->_template_args, |
|
375 | - true |
|
376 | - ); |
|
377 | - $this->display_admin_page_with_sidebar(); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * Handler for updating espresso page settings. |
|
383 | - * |
|
384 | - * @throws EE_Error |
|
385 | - */ |
|
386 | - protected function _update_espresso_page_settings() |
|
387 | - { |
|
388 | - // capture incoming request data && set page IDs |
|
389 | - EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id']) |
|
390 | - ? absint($this->_req_data['reg_page_id']) |
|
391 | - : EE_Registry::instance()->CFG->core->reg_page_id; |
|
392 | - EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id']) |
|
393 | - ? absint($this->_req_data['txn_page_id']) |
|
394 | - : EE_Registry::instance()->CFG->core->txn_page_id; |
|
395 | - EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id']) |
|
396 | - ? absint($this->_req_data['thank_you_page_id']) |
|
397 | - : EE_Registry::instance()->CFG->core->thank_you_page_id; |
|
398 | - EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id']) |
|
399 | - ? absint($this->_req_data['cancel_page_id']) |
|
400 | - : EE_Registry::instance()->CFG->core->cancel_page_id; |
|
401 | - |
|
402 | - EE_Registry::instance()->CFG->core = apply_filters( |
|
403 | - 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
404 | - EE_Registry::instance()->CFG->core, |
|
405 | - $this->_req_data |
|
406 | - ); |
|
407 | - $what = __('Critical Pages & Shortcodes', 'event_espresso'); |
|
408 | - $this->_redirect_after_action( |
|
409 | - $this->_update_espresso_configuration( |
|
410 | - $what, |
|
411 | - EE_Registry::instance()->CFG->core, |
|
412 | - __FILE__, |
|
413 | - __FUNCTION__, |
|
414 | - __LINE__ |
|
415 | - ), |
|
416 | - $what, |
|
417 | - '', |
|
418 | - array( |
|
419 | - 'action' => 'critical_pages', |
|
420 | - ), |
|
421 | - true |
|
422 | - ); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /************* Your Organization *************/ |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * @throws DomainException |
|
431 | - * @throws EE_Error |
|
432 | - * @throws InvalidArgumentException |
|
433 | - * @throws InvalidDataTypeException |
|
434 | - * @throws InvalidInterfaceException |
|
435 | - */ |
|
436 | - protected function _your_organization_settings() |
|
437 | - { |
|
438 | - $this->_template_args['admin_page_content'] = ''; |
|
439 | - try { |
|
440 | - $organization_settings_form = new OrganizationSettings( |
|
441 | - EE_Registry::instance(), |
|
442 | - EE_Registry::instance()->CFG->organization, |
|
443 | - EE_Registry::instance()->CFG->core, |
|
444 | - EE_Registry::instance()->NET_CFG->core |
|
445 | - ); |
|
446 | - $this->_template_args['admin_page_content'] = $organization_settings_form->display(); |
|
447 | - } catch (Exception $e) { |
|
448 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
449 | - } |
|
450 | - $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
451 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
452 | - $this->display_admin_page_with_sidebar(); |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - |
|
457 | - /** |
|
458 | - * Handler for updating organization settings. |
|
459 | - * |
|
460 | - * @throws EE_Error |
|
461 | - */ |
|
462 | - protected function _update_your_organization_settings() |
|
463 | - { |
|
464 | - try { |
|
465 | - $organization_settings_form = new OrganizationSettings( |
|
466 | - EE_Registry::instance(), |
|
467 | - EE_Registry::instance()->CFG->organization, |
|
468 | - EE_Registry::instance()->CFG->core, |
|
469 | - EE_Registry::instance()->NET_CFG->core |
|
470 | - ); |
|
471 | - $success = $organization_settings_form->process($this->_req_data); |
|
472 | - EE_Registry::instance()->CFG = apply_filters( |
|
473 | - 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
474 | - EE_Registry::instance()->CFG |
|
475 | - ); |
|
476 | - } catch (Exception $e) { |
|
477 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
478 | - $success = false; |
|
479 | - } |
|
480 | - |
|
481 | - if ($success) { |
|
482 | - $success = $this->_update_espresso_configuration( |
|
483 | - esc_html__('Your Organization Settings', 'event_espresso'), |
|
484 | - EE_Registry::instance()->CFG, |
|
485 | - __FILE__, |
|
486 | - __FUNCTION__, |
|
487 | - __LINE__ |
|
488 | - ); |
|
489 | - } |
|
490 | - |
|
491 | - $this->_redirect_after_action($success, '', '', array('action' => 'default'), true); |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - |
|
496 | - /************* Admin Options *************/ |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * _admin_option_settings |
|
501 | - * |
|
502 | - * @throws \EE_Error |
|
503 | - * @throws \LogicException |
|
504 | - */ |
|
505 | - protected function _admin_option_settings() |
|
506 | - { |
|
507 | - $this->_template_args['admin_page_content'] = ''; |
|
508 | - try { |
|
509 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
510 | - // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
511 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
512 | - // also need to account for the do_action that was in the old template |
|
513 | - $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
514 | - $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
515 | - } catch (Exception $e) { |
|
516 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
517 | - } |
|
518 | - $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
519 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
520 | - $this->display_admin_page_with_sidebar(); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * _update_admin_option_settings |
|
526 | - * |
|
527 | - * @throws \EE_Error |
|
528 | - * @throws InvalidDataTypeException |
|
529 | - * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException |
|
530 | - * @throws \InvalidArgumentException |
|
531 | - * @throws \LogicException |
|
532 | - */ |
|
533 | - protected function _update_admin_option_settings() |
|
534 | - { |
|
535 | - try { |
|
536 | - $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
537 | - $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]); |
|
538 | - EE_Registry::instance()->CFG->admin = apply_filters( |
|
539 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
540 | - EE_Registry::instance()->CFG->admin |
|
541 | - ); |
|
542 | - } catch (Exception $e) { |
|
543 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
544 | - } |
|
545 | - $this->_redirect_after_action( |
|
546 | - apply_filters( |
|
547 | - 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
548 | - $this->_update_espresso_configuration( |
|
549 | - 'Admin Options', |
|
550 | - EE_Registry::instance()->CFG->admin, |
|
551 | - __FILE__, |
|
552 | - __FUNCTION__, |
|
553 | - __LINE__ |
|
554 | - ) |
|
555 | - ), |
|
556 | - 'Admin Options', |
|
557 | - 'updated', |
|
558 | - array('action' => 'admin_option_settings') |
|
559 | - ); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /************* Countries *************/ |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * @return string |
|
568 | - */ |
|
569 | - protected function getCountryIsoForSite() |
|
570 | - { |
|
571 | - return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
572 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
573 | - : 'US'; |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * Output Country Settings view. |
|
580 | - * |
|
581 | - * @throws DomainException |
|
582 | - * @throws EE_Error |
|
583 | - */ |
|
584 | - protected function _country_settings() |
|
585 | - { |
|
586 | - $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
587 | - $CNT_ISO = isset($this->_req_data['country']) |
|
588 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
589 | - : $CNT_ISO_for_site; |
|
590 | - |
|
591 | - // load field generator helper |
|
592 | - |
|
593 | - $this->_template_args['values'] = $this->_yes_no_values; |
|
594 | - |
|
595 | - $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
596 | - EE_Question::new_instance( |
|
597 | - array( |
|
598 | - 'QST_ID' => 0, |
|
599 | - 'QST_display_text' => __('Select Country', 'event_espresso'), |
|
600 | - 'QST_system' => 'admin-country', |
|
601 | - ) |
|
602 | - ), |
|
603 | - EE_Answer::new_instance( |
|
604 | - array( |
|
605 | - 'ANS_ID' => 0, |
|
606 | - 'ANS_value' => $CNT_ISO, |
|
607 | - ) |
|
608 | - ), |
|
609 | - array( |
|
610 | - 'input_id' => 'country', |
|
611 | - 'input_name' => 'country', |
|
612 | - 'input_prefix' => '', |
|
613 | - 'append_qstn_id' => false, |
|
614 | - ) |
|
615 | - ); |
|
616 | - |
|
617 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
618 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
619 | - $this->_template_args['country_details_settings'] = $this->display_country_settings(); |
|
620 | - $this->_template_args['country_states_settings'] = $this->display_country_states(); |
|
621 | - $this->_template_args['CNT_name_for_site'] = EEM_Country::instance()->get_one_by_ID($CNT_ISO_for_site) |
|
622 | - ->name(); |
|
623 | - |
|
624 | - $this->_set_add_edit_form_tags('update_country_settings'); |
|
625 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
626 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
627 | - GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
628 | - $this->_template_args, |
|
629 | - true |
|
630 | - ); |
|
631 | - $this->display_admin_page_with_no_sidebar(); |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - /** |
|
636 | - * display_country_settings |
|
637 | - * |
|
638 | - * @access public |
|
639 | - * @param string $CNT_ISO |
|
640 | - * @return mixed string | array |
|
641 | - * @throws DomainException |
|
642 | - */ |
|
643 | - public function display_country_settings($CNT_ISO = '') |
|
644 | - { |
|
645 | - $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
646 | - |
|
647 | - $CNT_ISO = isset($this->_req_data['country']) |
|
648 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
649 | - : $CNT_ISO; |
|
650 | - if (! $CNT_ISO) { |
|
651 | - return ''; |
|
652 | - } |
|
653 | - |
|
654 | - // for ajax |
|
655 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
656 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
657 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
658 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
659 | - /** @var EE_Country $country */ |
|
660 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
661 | - |
|
662 | - $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
663 | - $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
664 | - |
|
665 | - $country_input_types = array( |
|
666 | - 'CNT_active' => array( |
|
667 | - 'type' => 'RADIO_BTN', |
|
668 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
669 | - 'class' => '', |
|
670 | - 'options' => $this->_yes_no_values, |
|
671 | - 'use_desc_4_label' => true, |
|
672 | - ), |
|
673 | - 'CNT_ISO' => array( |
|
674 | - 'type' => 'TEXT', |
|
675 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
676 | - 'class' => 'small-text', |
|
677 | - ), |
|
678 | - 'CNT_ISO3' => array( |
|
679 | - 'type' => 'TEXT', |
|
680 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
681 | - 'class' => 'small-text', |
|
682 | - ), |
|
683 | - 'RGN_ID' => array( |
|
684 | - 'type' => 'TEXT', |
|
685 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
686 | - 'class' => 'small-text', |
|
687 | - ), |
|
688 | - 'CNT_name' => array( |
|
689 | - 'type' => 'TEXT', |
|
690 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
691 | - 'class' => 'regular-text', |
|
692 | - ), |
|
693 | - 'CNT_cur_code' => array( |
|
694 | - 'type' => 'TEXT', |
|
695 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
696 | - 'class' => 'small-text', |
|
697 | - 'disabled' => $CNT_cur_disabled |
|
698 | - ), |
|
699 | - 'CNT_cur_single' => array( |
|
700 | - 'type' => 'TEXT', |
|
701 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
702 | - 'class' => 'medium-text', |
|
703 | - 'disabled' => $CNT_cur_disabled |
|
704 | - ), |
|
705 | - 'CNT_cur_plural' => array( |
|
706 | - 'type' => 'TEXT', |
|
707 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
708 | - 'class' => 'medium-text', |
|
709 | - 'disabled' => $CNT_cur_disabled |
|
710 | - ), |
|
711 | - 'CNT_cur_sign' => array( |
|
712 | - 'type' => 'TEXT', |
|
713 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
714 | - 'class' => 'small-text', |
|
715 | - 'htmlentities' => false, |
|
716 | - 'disabled' => $CNT_cur_disabled |
|
717 | - ), |
|
718 | - 'CNT_cur_sign_b4' => array( |
|
719 | - 'type' => 'RADIO_BTN', |
|
720 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
721 | - 'class' => '', |
|
722 | - 'options' => $this->_yes_no_values, |
|
723 | - 'use_desc_4_label' => true, |
|
724 | - 'disabled' => $CNT_cur_disabled |
|
725 | - ), |
|
726 | - 'CNT_cur_dec_plc' => array( |
|
727 | - 'type' => 'RADIO_BTN', |
|
728 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
729 | - 'class' => '', |
|
730 | - 'options' => array( |
|
731 | - array('id' => 0, 'text' => ''), |
|
732 | - array('id' => 1, 'text' => ''), |
|
733 | - array('id' => 2, 'text' => ''), |
|
734 | - array('id' => 3, 'text' => ''), |
|
735 | - ), |
|
736 | - 'disabled' => $CNT_cur_disabled |
|
737 | - ), |
|
738 | - 'CNT_cur_dec_mrk' => array( |
|
739 | - 'type' => 'RADIO_BTN', |
|
740 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
741 | - 'class' => '', |
|
742 | - 'options' => array( |
|
743 | - array( |
|
744 | - 'id' => ',', |
|
745 | - 'text' => __(', (comma)', 'event_espresso'), |
|
746 | - ), |
|
747 | - array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
748 | - ), |
|
749 | - 'use_desc_4_label' => true, |
|
750 | - 'disabled' => $CNT_cur_disabled |
|
751 | - ), |
|
752 | - 'CNT_cur_thsnds' => array( |
|
753 | - 'type' => 'RADIO_BTN', |
|
754 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
755 | - 'class' => '', |
|
756 | - 'options' => array( |
|
757 | - array( |
|
758 | - 'id' => ',', |
|
759 | - 'text' => __(', (comma)', 'event_espresso'), |
|
760 | - ), |
|
761 | - array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
762 | - ), |
|
763 | - 'use_desc_4_label' => true, |
|
764 | - 'disabled' => $CNT_cur_disabled |
|
765 | - ), |
|
766 | - 'CNT_tel_code' => array( |
|
767 | - 'type' => 'TEXT', |
|
768 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
769 | - 'class' => 'small-text', |
|
770 | - ), |
|
771 | - 'CNT_is_EU' => array( |
|
772 | - 'type' => 'RADIO_BTN', |
|
773 | - 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
774 | - 'class' => '', |
|
775 | - 'options' => $this->_yes_no_values, |
|
776 | - 'use_desc_4_label' => true, |
|
777 | - ), |
|
778 | - ); |
|
779 | - $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
780 | - $country, |
|
781 | - $country_input_types |
|
782 | - ); |
|
783 | - $country_details_settings = EEH_Template::display_template( |
|
784 | - GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
785 | - $this->_template_args, |
|
786 | - true |
|
787 | - ); |
|
788 | - |
|
789 | - if (defined('DOING_AJAX')) { |
|
790 | - $notices = EE_Error::get_notices(false, false, false); |
|
791 | - echo wp_json_encode( |
|
792 | - array( |
|
793 | - 'return_data' => $country_details_settings, |
|
794 | - 'success' => $notices['success'], |
|
795 | - 'errors' => $notices['errors'], |
|
796 | - ) |
|
797 | - ); |
|
798 | - die(); |
|
799 | - } else { |
|
800 | - return $country_details_settings; |
|
801 | - } |
|
802 | - } |
|
803 | - |
|
804 | - |
|
805 | - /** |
|
806 | - * display_country_states |
|
807 | - * |
|
808 | - * @access public |
|
809 | - * @param string $CNT_ISO |
|
810 | - * @return string |
|
811 | - * @throws DomainException |
|
812 | - */ |
|
813 | - public function display_country_states($CNT_ISO = '') |
|
814 | - { |
|
815 | - |
|
816 | - $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO; |
|
817 | - |
|
818 | - if (! $CNT_ISO) { |
|
819 | - return ''; |
|
820 | - } |
|
821 | - // for ajax |
|
822 | - remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
823 | - remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
824 | - add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2); |
|
825 | - add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2); |
|
826 | - $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO)); |
|
827 | - |
|
828 | - if ($states) { |
|
829 | - foreach ($states as $STA_ID => $state) { |
|
830 | - if ($state instanceof EE_State) { |
|
831 | - // STA_abbrev STA_name STA_active |
|
832 | - $state_input_types = array( |
|
833 | - 'STA_abbrev' => array( |
|
834 | - 'type' => 'TEXT', |
|
835 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
836 | - 'class' => 'mid-text', |
|
837 | - ), |
|
838 | - 'STA_name' => array( |
|
839 | - 'type' => 'TEXT', |
|
840 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
841 | - 'class' => 'regular-text', |
|
842 | - ), |
|
843 | - 'STA_active' => array( |
|
844 | - 'type' => 'RADIO_BTN', |
|
845 | - 'input_name' => 'states[' . $STA_ID . ']', |
|
846 | - 'options' => $this->_yes_no_values, |
|
847 | - 'use_desc_4_label' => true, |
|
848 | - ), |
|
849 | - ); |
|
850 | - $this->_template_args['states'][ $STA_ID ]['inputs'] = |
|
851 | - EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
852 | - $state, |
|
853 | - $state_input_types |
|
854 | - ); |
|
855 | - $query_args = array( |
|
856 | - 'action' => 'delete_state', |
|
857 | - 'STA_ID' => $STA_ID, |
|
858 | - 'CNT_ISO' => $CNT_ISO, |
|
859 | - 'STA_abbrev' => $state->abbrev(), |
|
860 | - ); |
|
861 | - $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = |
|
862 | - EE_Admin_Page::add_query_args_and_nonce( |
|
863 | - $query_args, |
|
864 | - GEN_SET_ADMIN_URL |
|
865 | - ); |
|
866 | - } |
|
867 | - } |
|
868 | - } else { |
|
869 | - $this->_template_args['states'] = false; |
|
870 | - } |
|
871 | - |
|
872 | - $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
873 | - array('action' => 'add_new_state'), |
|
874 | - GEN_SET_ADMIN_URL |
|
875 | - ); |
|
876 | - |
|
877 | - $state_details_settings = EEH_Template::display_template( |
|
878 | - GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
879 | - $this->_template_args, |
|
880 | - true |
|
881 | - ); |
|
882 | - |
|
883 | - if (defined('DOING_AJAX')) { |
|
884 | - $notices = EE_Error::get_notices(false, false, false); |
|
885 | - echo wp_json_encode( |
|
886 | - array( |
|
887 | - 'return_data' => $state_details_settings, |
|
888 | - 'success' => $notices['success'], |
|
889 | - 'errors' => $notices['errors'], |
|
890 | - ) |
|
891 | - ); |
|
892 | - die(); |
|
893 | - } else { |
|
894 | - return $state_details_settings; |
|
895 | - } |
|
896 | - } |
|
897 | - |
|
898 | - |
|
899 | - /** |
|
900 | - * add_new_state |
|
901 | - * |
|
902 | - * @access public |
|
903 | - * @return void |
|
904 | - * @throws EE_Error |
|
905 | - */ |
|
906 | - public function add_new_state() |
|
907 | - { |
|
908 | - |
|
909 | - $success = true; |
|
910 | - |
|
911 | - $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
912 | - ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
913 | - : false; |
|
914 | - if (! $CNT_ISO) { |
|
915 | - EE_Error::add_error( |
|
916 | - __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
917 | - __FILE__, |
|
918 | - __FUNCTION__, |
|
919 | - __LINE__ |
|
920 | - ); |
|
921 | - $success = false; |
|
922 | - } |
|
923 | - $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
924 | - ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
925 | - : false; |
|
926 | - if (! $STA_abbrev) { |
|
927 | - EE_Error::add_error( |
|
928 | - __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
929 | - __FILE__, |
|
930 | - __FUNCTION__, |
|
931 | - __LINE__ |
|
932 | - ); |
|
933 | - $success = false; |
|
934 | - } |
|
935 | - $STA_name = isset($this->_req_data['STA_name']) |
|
936 | - ? sanitize_text_field($this->_req_data['STA_name']) |
|
937 | - : false; |
|
938 | - if (! $STA_name) { |
|
939 | - EE_Error::add_error( |
|
940 | - __('No State name or an invalid State name was received.', 'event_espresso'), |
|
941 | - __FILE__, |
|
942 | - __FUNCTION__, |
|
943 | - __LINE__ |
|
944 | - ); |
|
945 | - $success = false; |
|
946 | - } |
|
947 | - |
|
948 | - if ($success) { |
|
949 | - $cols_n_values = array( |
|
950 | - 'CNT_ISO' => $CNT_ISO, |
|
951 | - 'STA_abbrev' => $STA_abbrev, |
|
952 | - 'STA_name' => $STA_name, |
|
953 | - 'STA_active' => true, |
|
954 | - ); |
|
955 | - $success = EEM_State::instance()->insert($cols_n_values); |
|
956 | - EE_Error::add_success(__('The State was added successfully.', 'event_espresso')); |
|
957 | - } |
|
958 | - |
|
959 | - if (defined('DOING_AJAX')) { |
|
960 | - $notices = EE_Error::get_notices(false, false, false); |
|
961 | - echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO))); |
|
962 | - die(); |
|
963 | - } else { |
|
964 | - $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings')); |
|
965 | - } |
|
966 | - } |
|
967 | - |
|
968 | - |
|
969 | - /** |
|
970 | - * delete_state |
|
971 | - * |
|
972 | - * @access public |
|
973 | - * @return boolean |
|
974 | - * @throws EE_Error |
|
975 | - * @throws EE_Error |
|
976 | - */ |
|
977 | - public function delete_state() |
|
978 | - { |
|
979 | - $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
980 | - ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
981 | - : false; |
|
982 | - $STA_ID = isset($this->_req_data['STA_ID']) |
|
983 | - ? sanitize_text_field($this->_req_data['STA_ID']) |
|
984 | - : false; |
|
985 | - $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
986 | - ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
987 | - : false; |
|
988 | - if (! $STA_ID) { |
|
989 | - EE_Error::add_error( |
|
990 | - __('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
991 | - __FILE__, |
|
992 | - __FUNCTION__, |
|
993 | - __LINE__ |
|
994 | - ); |
|
995 | - return false; |
|
996 | - } |
|
997 | - |
|
998 | - $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
999 | - if ($success !== false) { |
|
1000 | - do_action( |
|
1001 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
1002 | - $CNT_ISO, |
|
1003 | - $STA_ID, |
|
1004 | - array('STA_abbrev' => $STA_abbrev) |
|
1005 | - ); |
|
1006 | - EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso')); |
|
1007 | - } |
|
1008 | - if (defined('DOING_AJAX')) { |
|
1009 | - $notices = EE_Error::get_notices(false, false); |
|
1010 | - $notices['return_data'] = true; |
|
1011 | - echo wp_json_encode($notices); |
|
1012 | - die(); |
|
1013 | - } else { |
|
1014 | - $this->_redirect_after_action( |
|
1015 | - $success, |
|
1016 | - 'State', |
|
1017 | - 'deleted', |
|
1018 | - array('action' => 'country_settings') |
|
1019 | - ); |
|
1020 | - } |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * _update_country_settings |
|
1026 | - * |
|
1027 | - * @access protected |
|
1028 | - * @return void |
|
1029 | - * @throws EE_Error |
|
1030 | - */ |
|
1031 | - protected function _update_country_settings() |
|
1032 | - { |
|
1033 | - // grab the country ISO code |
|
1034 | - $CNT_ISO = isset($this->_req_data['country']) |
|
1035 | - ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
1036 | - : false; |
|
1037 | - if (! $CNT_ISO) { |
|
1038 | - EE_Error::add_error( |
|
1039 | - __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
1040 | - __FILE__, |
|
1041 | - __FUNCTION__, |
|
1042 | - __LINE__ |
|
1043 | - ); |
|
1044 | - |
|
1045 | - return; |
|
1046 | - } |
|
1047 | - $cols_n_values = array(); |
|
1048 | - $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']) |
|
1049 | - ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])) |
|
1050 | - : false; |
|
1051 | - $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1052 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1053 | - : null; |
|
1054 | - $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1055 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1056 | - : null; |
|
1057 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) { |
|
1058 | - $cols_n_values['CNT_cur_code'] = strtoupper( |
|
1059 | - sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code']) |
|
1060 | - ); |
|
1061 | - } |
|
1062 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) { |
|
1063 | - $cols_n_values['CNT_cur_single'] = sanitize_text_field( |
|
1064 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'] |
|
1065 | - ); |
|
1066 | - } |
|
1067 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) { |
|
1068 | - $cols_n_values['CNT_cur_plural'] = sanitize_text_field( |
|
1069 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'] |
|
1070 | - ); |
|
1071 | - } |
|
1072 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) { |
|
1073 | - $cols_n_values['CNT_cur_sign'] = sanitize_text_field( |
|
1074 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'] |
|
1075 | - ); |
|
1076 | - } |
|
1077 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) { |
|
1078 | - $cols_n_values['CNT_cur_sign_b4'] = absint( |
|
1079 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'] |
|
1080 | - ); |
|
1081 | - } |
|
1082 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) { |
|
1083 | - $cols_n_values['CNT_cur_dec_plc'] = absint( |
|
1084 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'] |
|
1085 | - ); |
|
1086 | - } |
|
1087 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) { |
|
1088 | - $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field( |
|
1089 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'] |
|
1090 | - ); |
|
1091 | - } |
|
1092 | - if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) { |
|
1093 | - $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field( |
|
1094 | - $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'] |
|
1095 | - ); |
|
1096 | - } |
|
1097 | - $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1098 | - ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1099 | - : null; |
|
1100 | - $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1101 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1102 | - : false; |
|
1103 | - $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1104 | - ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1105 | - : false; |
|
1106 | - // allow filtering of country data |
|
1107 | - $cols_n_values = apply_filters( |
|
1108 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
1109 | - $cols_n_values |
|
1110 | - ); |
|
1111 | - |
|
1112 | - // where values |
|
1113 | - $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); |
|
1114 | - // run the update |
|
1115 | - $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
1116 | - |
|
1117 | - if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) { |
|
1118 | - // allow filtering of states data |
|
1119 | - $states = apply_filters( |
|
1120 | - 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
1121 | - $this->_req_data['states'] |
|
1122 | - ); |
|
1123 | - |
|
1124 | - // loop thru state data ( looks like : states[75][STA_name] ) |
|
1125 | - foreach ($states as $STA_ID => $state) { |
|
1126 | - $cols_n_values = array( |
|
1127 | - 'CNT_ISO' => $CNT_ISO, |
|
1128 | - 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
1129 | - 'STA_name' => sanitize_text_field($state['STA_name']), |
|
1130 | - 'STA_active' => (bool) absint($state['STA_active']), |
|
1131 | - ); |
|
1132 | - // where values |
|
1133 | - $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
|
1134 | - // run the update |
|
1135 | - $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
1136 | - if ($success !== false) { |
|
1137 | - do_action( |
|
1138 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
1139 | - $CNT_ISO, |
|
1140 | - $STA_ID, |
|
1141 | - $cols_n_values |
|
1142 | - ); |
|
1143 | - } |
|
1144 | - } |
|
1145 | - } |
|
1146 | - // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
1147 | - if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
1148 | - && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
1149 | - ) { |
|
1150 | - EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
1151 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
1152 | - } |
|
1153 | - |
|
1154 | - if ($success !== false) { |
|
1155 | - EE_Error::add_success( |
|
1156 | - esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
1157 | - ); |
|
1158 | - } |
|
1159 | - $this->_redirect_after_action( |
|
1160 | - $success, |
|
1161 | - '', |
|
1162 | - '', |
|
1163 | - array('action' => 'country_settings', 'country' => $CNT_ISO), |
|
1164 | - true |
|
1165 | - ); |
|
1166 | - } |
|
1167 | - |
|
1168 | - |
|
1169 | - /** |
|
1170 | - * form_form_field_label_wrap |
|
1171 | - * |
|
1172 | - * @access public |
|
1173 | - * @param string $label |
|
1174 | - * @return string |
|
1175 | - */ |
|
1176 | - public function country_form_field_label_wrap($label, $required_text) |
|
1177 | - { |
|
1178 | - return ' |
|
24 | + /** |
|
25 | + * _question_group |
|
26 | + * holds the specific question group object for the question group details screen |
|
27 | + * |
|
28 | + * @var object |
|
29 | + */ |
|
30 | + protected $_question_group; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Initialize basic properties. |
|
35 | + */ |
|
36 | + protected function _init_page_props() |
|
37 | + { |
|
38 | + $this->page_slug = GEN_SET_PG_SLUG; |
|
39 | + $this->page_label = GEN_SET_LABEL; |
|
40 | + $this->_admin_base_url = GEN_SET_ADMIN_URL; |
|
41 | + $this->_admin_base_path = GEN_SET_ADMIN; |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * Set ajax hooks |
|
47 | + */ |
|
48 | + protected function _ajax_hooks() |
|
49 | + { |
|
50 | + add_action('wp_ajax_espresso_display_country_settings', array($this, 'display_country_settings')); |
|
51 | + add_action('wp_ajax_espresso_display_country_states', array($this, 'display_country_states')); |
|
52 | + add_action('wp_ajax_espresso_delete_state', array($this, 'delete_state'), 10, 3); |
|
53 | + add_action('wp_ajax_espresso_add_new_state', array($this, 'add_new_state')); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * More page properties initialization. |
|
59 | + */ |
|
60 | + protected function _define_page_props() |
|
61 | + { |
|
62 | + $this->_admin_page_title = GEN_SET_LABEL; |
|
63 | + $this->_labels = array( |
|
64 | + 'publishbox' => __('Update Settings', 'event_espresso'), |
|
65 | + ); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Set page routes property. |
|
71 | + */ |
|
72 | + protected function _set_page_routes() |
|
73 | + { |
|
74 | + $this->_page_routes = array( |
|
75 | + |
|
76 | + 'critical_pages' => array( |
|
77 | + 'func' => '_espresso_page_settings', |
|
78 | + 'capability' => 'manage_options', |
|
79 | + ), |
|
80 | + 'update_espresso_page_settings' => array( |
|
81 | + 'func' => '_update_espresso_page_settings', |
|
82 | + 'capability' => 'manage_options', |
|
83 | + 'noheader' => true, |
|
84 | + ), |
|
85 | + 'default' => array( |
|
86 | + 'func' => '_your_organization_settings', |
|
87 | + 'capability' => 'manage_options', |
|
88 | + ), |
|
89 | + |
|
90 | + 'update_your_organization_settings' => array( |
|
91 | + 'func' => '_update_your_organization_settings', |
|
92 | + 'capability' => 'manage_options', |
|
93 | + 'noheader' => true, |
|
94 | + ), |
|
95 | + |
|
96 | + 'admin_option_settings' => array( |
|
97 | + 'func' => '_admin_option_settings', |
|
98 | + 'capability' => 'manage_options', |
|
99 | + ), |
|
100 | + |
|
101 | + 'update_admin_option_settings' => array( |
|
102 | + 'func' => '_update_admin_option_settings', |
|
103 | + 'capability' => 'manage_options', |
|
104 | + 'noheader' => true, |
|
105 | + ), |
|
106 | + |
|
107 | + 'country_settings' => array( |
|
108 | + 'func' => '_country_settings', |
|
109 | + 'capability' => 'manage_options', |
|
110 | + ), |
|
111 | + |
|
112 | + 'update_country_settings' => array( |
|
113 | + 'func' => '_update_country_settings', |
|
114 | + 'capability' => 'manage_options', |
|
115 | + 'noheader' => true, |
|
116 | + ), |
|
117 | + |
|
118 | + 'display_country_settings' => array( |
|
119 | + 'func' => 'display_country_settings', |
|
120 | + 'capability' => 'manage_options', |
|
121 | + 'noheader' => true, |
|
122 | + ), |
|
123 | + |
|
124 | + 'add_new_state' => array( |
|
125 | + 'func' => 'add_new_state', |
|
126 | + 'capability' => 'manage_options', |
|
127 | + 'noheader' => true, |
|
128 | + ), |
|
129 | + |
|
130 | + 'delete_state' => array( |
|
131 | + 'func' => 'delete_state', |
|
132 | + 'capability' => 'manage_options', |
|
133 | + 'noheader' => true, |
|
134 | + ), |
|
135 | + 'privacy_settings' => array( |
|
136 | + 'func' => 'privacySettings', |
|
137 | + 'capability' => 'manage_options', |
|
138 | + ), |
|
139 | + 'update_privacy_settings' => array( |
|
140 | + 'func' => 'updatePrivacySettings', |
|
141 | + 'capability' => 'manage_options', |
|
142 | + 'noheader' => true, |
|
143 | + 'headers_sent_route' => 'privacy_settings' |
|
144 | + ) |
|
145 | + ); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * Set page configuration property |
|
151 | + */ |
|
152 | + protected function _set_page_config() |
|
153 | + { |
|
154 | + $this->_page_config = array( |
|
155 | + 'critical_pages' => array( |
|
156 | + 'nav' => array( |
|
157 | + 'label' => __('Critical Pages', 'event_espresso'), |
|
158 | + 'order' => 50, |
|
159 | + ), |
|
160 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
161 | + 'help_tabs' => array( |
|
162 | + 'general_settings_critical_pages_help_tab' => array( |
|
163 | + 'title' => __('Critical Pages', 'event_espresso'), |
|
164 | + 'filename' => 'general_settings_critical_pages', |
|
165 | + ), |
|
166 | + ), |
|
167 | + 'help_tour' => array('Critical_Pages_Help_Tour'), |
|
168 | + 'require_nonce' => false, |
|
169 | + ), |
|
170 | + 'default' => array( |
|
171 | + 'nav' => array( |
|
172 | + 'label' => __('Your Organization', 'event_espresso'), |
|
173 | + 'order' => 20, |
|
174 | + ), |
|
175 | + 'help_tabs' => array( |
|
176 | + 'general_settings_your_organization_help_tab' => array( |
|
177 | + 'title' => __('Your Organization', 'event_espresso'), |
|
178 | + 'filename' => 'general_settings_your_organization', |
|
179 | + ), |
|
180 | + ), |
|
181 | + 'help_tour' => array('Your_Organization_Help_Tour'), |
|
182 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
183 | + 'require_nonce' => false, |
|
184 | + ), |
|
185 | + 'admin_option_settings' => array( |
|
186 | + 'nav' => array( |
|
187 | + 'label' => __('Admin Options', 'event_espresso'), |
|
188 | + 'order' => 60, |
|
189 | + ), |
|
190 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
191 | + 'help_tabs' => array( |
|
192 | + 'general_settings_admin_options_help_tab' => array( |
|
193 | + 'title' => __('Admin Options', 'event_espresso'), |
|
194 | + 'filename' => 'general_settings_admin_options', |
|
195 | + ), |
|
196 | + ), |
|
197 | + 'help_tour' => array('Admin_Options_Help_Tour'), |
|
198 | + 'require_nonce' => false, |
|
199 | + ), |
|
200 | + 'country_settings' => array( |
|
201 | + 'nav' => array( |
|
202 | + 'label' => __('Countries', 'event_espresso'), |
|
203 | + 'order' => 70, |
|
204 | + ), |
|
205 | + 'help_tabs' => array( |
|
206 | + 'general_settings_countries_help_tab' => array( |
|
207 | + 'title' => __('Countries', 'event_espresso'), |
|
208 | + 'filename' => 'general_settings_countries', |
|
209 | + ), |
|
210 | + ), |
|
211 | + 'help_tour' => array('Countries_Help_Tour'), |
|
212 | + 'require_nonce' => false, |
|
213 | + ), |
|
214 | + 'privacy_settings' => array( |
|
215 | + 'nav' => array( |
|
216 | + 'label' => esc_html__('Privacy', 'event_espresso'), |
|
217 | + 'order' => 80 |
|
218 | + ), |
|
219 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
220 | + 'require_nonce' => false |
|
221 | + ) |
|
222 | + ); |
|
223 | + } |
|
224 | + |
|
225 | + |
|
226 | + protected function _add_screen_options() |
|
227 | + { |
|
228 | + } |
|
229 | + |
|
230 | + protected function _add_feature_pointers() |
|
231 | + { |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * Enqueue global scripts and styles for all routes in the General Settings Admin Pages. |
|
237 | + */ |
|
238 | + public function load_scripts_styles() |
|
239 | + { |
|
240 | + // styles |
|
241 | + wp_enqueue_style('espresso-ui-theme'); |
|
242 | + // scripts |
|
243 | + wp_enqueue_script('ee_admin_js'); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Execute logic running on `admin_init` |
|
249 | + */ |
|
250 | + public function admin_init() |
|
251 | + { |
|
252 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = __( |
|
253 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
254 | + 'event_espresso' |
|
255 | + ); |
|
256 | + EE_Registry::$i18n_js_strings['error_occurred'] = __( |
|
257 | + 'An error occurred! Please refresh the page and try again.', |
|
258 | + 'event_espresso' |
|
259 | + ); |
|
260 | + EE_Registry::$i18n_js_strings['confirm_delete_state'] = __( |
|
261 | + 'Are you sure you want to delete this State / Province?', |
|
262 | + 'event_espresso' |
|
263 | + ); |
|
264 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
265 | + EE_Registry::$i18n_js_strings['ajax_url'] = admin_url( |
|
266 | + 'admin-ajax.php?page=espresso_general_settings', |
|
267 | + $protocol |
|
268 | + ); |
|
269 | + } |
|
270 | + |
|
271 | + public function admin_notices() |
|
272 | + { |
|
273 | + } |
|
274 | + |
|
275 | + public function admin_footer_scripts() |
|
276 | + { |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Enqueue scripts and styles for the default route. |
|
282 | + */ |
|
283 | + public function load_scripts_styles_default() |
|
284 | + { |
|
285 | + // styles |
|
286 | + wp_enqueue_style('thickbox'); |
|
287 | + // scripts |
|
288 | + wp_enqueue_script('media-upload'); |
|
289 | + wp_enqueue_script('thickbox'); |
|
290 | + wp_register_script( |
|
291 | + 'organization_settings', |
|
292 | + GEN_SET_ASSETS_URL . 'your_organization_settings.js', |
|
293 | + array('jquery', 'media-upload', 'thickbox'), |
|
294 | + EVENT_ESPRESSO_VERSION, |
|
295 | + true |
|
296 | + ); |
|
297 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
298 | + wp_enqueue_script('organization_settings'); |
|
299 | + wp_enqueue_style('organization-css'); |
|
300 | + $confirm_image_delete = array( |
|
301 | + 'text' => __( |
|
302 | + 'Do you really want to delete this image? Please remember to save your settings to complete the removal.', |
|
303 | + 'event_espresso' |
|
304 | + ), |
|
305 | + ); |
|
306 | + wp_localize_script('organization_settings', 'confirm_image_delete', $confirm_image_delete); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * Enqueue scripts and styles for the country settings route. |
|
312 | + */ |
|
313 | + public function load_scripts_styles_country_settings() |
|
314 | + { |
|
315 | + // scripts |
|
316 | + wp_register_script( |
|
317 | + 'gen_settings_countries', |
|
318 | + GEN_SET_ASSETS_URL . 'gen_settings_countries.js', |
|
319 | + array('ee_admin_js'), |
|
320 | + EVENT_ESPRESSO_VERSION, |
|
321 | + true |
|
322 | + ); |
|
323 | + wp_register_style('organization-css', GEN_SET_ASSETS_URL . 'organization.css', array(), EVENT_ESPRESSO_VERSION); |
|
324 | + wp_enqueue_script('gen_settings_countries'); |
|
325 | + wp_enqueue_style('organization-css'); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /************* Espresso Pages *************/ |
|
330 | + /** |
|
331 | + * _espresso_page_settings |
|
332 | + * |
|
333 | + * @throws \EE_Error |
|
334 | + * @throws DomainException |
|
335 | + * @throws DomainException |
|
336 | + * @throws InvalidDataTypeException |
|
337 | + * @throws InvalidArgumentException |
|
338 | + */ |
|
339 | + protected function _espresso_page_settings() |
|
340 | + { |
|
341 | + // Check to make sure all of the main pages are setup properly, |
|
342 | + // if not create the default pages and display an admin notice |
|
343 | + EEH_Activation::verify_default_pages_exist(); |
|
344 | + $this->_transient_garbage_collection(); |
|
345 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
346 | + $this->_template_args['reg_page_id'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
347 | + ? EE_Registry::instance()->CFG->core->reg_page_id |
|
348 | + : null; |
|
349 | + $this->_template_args['reg_page_obj'] = isset(EE_Registry::instance()->CFG->core->reg_page_id) |
|
350 | + ? get_page(EE_Registry::instance()->CFG->core->reg_page_id) |
|
351 | + : false; |
|
352 | + $this->_template_args['txn_page_id'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
353 | + ? EE_Registry::instance()->CFG->core->txn_page_id |
|
354 | + : null; |
|
355 | + $this->_template_args['txn_page_obj'] = isset(EE_Registry::instance()->CFG->core->txn_page_id) |
|
356 | + ? get_page(EE_Registry::instance()->CFG->core->txn_page_id) |
|
357 | + : false; |
|
358 | + $this->_template_args['thank_you_page_id'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
359 | + ? EE_Registry::instance()->CFG->core->thank_you_page_id |
|
360 | + : null; |
|
361 | + $this->_template_args['thank_you_page_obj'] = isset(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
362 | + ? get_page(EE_Registry::instance()->CFG->core->thank_you_page_id) |
|
363 | + : false; |
|
364 | + $this->_template_args['cancel_page_id'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
365 | + ? EE_Registry::instance()->CFG->core->cancel_page_id |
|
366 | + : null; |
|
367 | + $this->_template_args['cancel_page_obj'] = isset(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
368 | + ? get_page(EE_Registry::instance()->CFG->core->cancel_page_id) |
|
369 | + : false; |
|
370 | + $this->_set_add_edit_form_tags('update_espresso_page_settings'); |
|
371 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
372 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
373 | + GEN_SET_TEMPLATE_PATH . 'espresso_page_settings.template.php', |
|
374 | + $this->_template_args, |
|
375 | + true |
|
376 | + ); |
|
377 | + $this->display_admin_page_with_sidebar(); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * Handler for updating espresso page settings. |
|
383 | + * |
|
384 | + * @throws EE_Error |
|
385 | + */ |
|
386 | + protected function _update_espresso_page_settings() |
|
387 | + { |
|
388 | + // capture incoming request data && set page IDs |
|
389 | + EE_Registry::instance()->CFG->core->reg_page_id = isset($this->_req_data['reg_page_id']) |
|
390 | + ? absint($this->_req_data['reg_page_id']) |
|
391 | + : EE_Registry::instance()->CFG->core->reg_page_id; |
|
392 | + EE_Registry::instance()->CFG->core->txn_page_id = isset($this->_req_data['txn_page_id']) |
|
393 | + ? absint($this->_req_data['txn_page_id']) |
|
394 | + : EE_Registry::instance()->CFG->core->txn_page_id; |
|
395 | + EE_Registry::instance()->CFG->core->thank_you_page_id = isset($this->_req_data['thank_you_page_id']) |
|
396 | + ? absint($this->_req_data['thank_you_page_id']) |
|
397 | + : EE_Registry::instance()->CFG->core->thank_you_page_id; |
|
398 | + EE_Registry::instance()->CFG->core->cancel_page_id = isset($this->_req_data['cancel_page_id']) |
|
399 | + ? absint($this->_req_data['cancel_page_id']) |
|
400 | + : EE_Registry::instance()->CFG->core->cancel_page_id; |
|
401 | + |
|
402 | + EE_Registry::instance()->CFG->core = apply_filters( |
|
403 | + 'FHEE__General_Settings_Admin_Page___update_espresso_page_settings__CFG_core', |
|
404 | + EE_Registry::instance()->CFG->core, |
|
405 | + $this->_req_data |
|
406 | + ); |
|
407 | + $what = __('Critical Pages & Shortcodes', 'event_espresso'); |
|
408 | + $this->_redirect_after_action( |
|
409 | + $this->_update_espresso_configuration( |
|
410 | + $what, |
|
411 | + EE_Registry::instance()->CFG->core, |
|
412 | + __FILE__, |
|
413 | + __FUNCTION__, |
|
414 | + __LINE__ |
|
415 | + ), |
|
416 | + $what, |
|
417 | + '', |
|
418 | + array( |
|
419 | + 'action' => 'critical_pages', |
|
420 | + ), |
|
421 | + true |
|
422 | + ); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /************* Your Organization *************/ |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * @throws DomainException |
|
431 | + * @throws EE_Error |
|
432 | + * @throws InvalidArgumentException |
|
433 | + * @throws InvalidDataTypeException |
|
434 | + * @throws InvalidInterfaceException |
|
435 | + */ |
|
436 | + protected function _your_organization_settings() |
|
437 | + { |
|
438 | + $this->_template_args['admin_page_content'] = ''; |
|
439 | + try { |
|
440 | + $organization_settings_form = new OrganizationSettings( |
|
441 | + EE_Registry::instance(), |
|
442 | + EE_Registry::instance()->CFG->organization, |
|
443 | + EE_Registry::instance()->CFG->core, |
|
444 | + EE_Registry::instance()->NET_CFG->core |
|
445 | + ); |
|
446 | + $this->_template_args['admin_page_content'] = $organization_settings_form->display(); |
|
447 | + } catch (Exception $e) { |
|
448 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
449 | + } |
|
450 | + $this->_set_add_edit_form_tags('update_your_organization_settings'); |
|
451 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
452 | + $this->display_admin_page_with_sidebar(); |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + |
|
457 | + /** |
|
458 | + * Handler for updating organization settings. |
|
459 | + * |
|
460 | + * @throws EE_Error |
|
461 | + */ |
|
462 | + protected function _update_your_organization_settings() |
|
463 | + { |
|
464 | + try { |
|
465 | + $organization_settings_form = new OrganizationSettings( |
|
466 | + EE_Registry::instance(), |
|
467 | + EE_Registry::instance()->CFG->organization, |
|
468 | + EE_Registry::instance()->CFG->core, |
|
469 | + EE_Registry::instance()->NET_CFG->core |
|
470 | + ); |
|
471 | + $success = $organization_settings_form->process($this->_req_data); |
|
472 | + EE_Registry::instance()->CFG = apply_filters( |
|
473 | + 'FHEE__General_Settings_Admin_Page___update_your_organization_settings__CFG', |
|
474 | + EE_Registry::instance()->CFG |
|
475 | + ); |
|
476 | + } catch (Exception $e) { |
|
477 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
478 | + $success = false; |
|
479 | + } |
|
480 | + |
|
481 | + if ($success) { |
|
482 | + $success = $this->_update_espresso_configuration( |
|
483 | + esc_html__('Your Organization Settings', 'event_espresso'), |
|
484 | + EE_Registry::instance()->CFG, |
|
485 | + __FILE__, |
|
486 | + __FUNCTION__, |
|
487 | + __LINE__ |
|
488 | + ); |
|
489 | + } |
|
490 | + |
|
491 | + $this->_redirect_after_action($success, '', '', array('action' => 'default'), true); |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + |
|
496 | + /************* Admin Options *************/ |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * _admin_option_settings |
|
501 | + * |
|
502 | + * @throws \EE_Error |
|
503 | + * @throws \LogicException |
|
504 | + */ |
|
505 | + protected function _admin_option_settings() |
|
506 | + { |
|
507 | + $this->_template_args['admin_page_content'] = ''; |
|
508 | + try { |
|
509 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
510 | + // still need this for the old school form in Extend_General_Settings_Admin_Page |
|
511 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
512 | + // also need to account for the do_action that was in the old template |
|
513 | + $admin_options_settings_form->setTemplateArgs($this->_template_args); |
|
514 | + $this->_template_args['admin_page_content'] = $admin_options_settings_form->display(); |
|
515 | + } catch (Exception $e) { |
|
516 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
517 | + } |
|
518 | + $this->_set_add_edit_form_tags('update_admin_option_settings'); |
|
519 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
520 | + $this->display_admin_page_with_sidebar(); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * _update_admin_option_settings |
|
526 | + * |
|
527 | + * @throws \EE_Error |
|
528 | + * @throws InvalidDataTypeException |
|
529 | + * @throws \EventEspresso\core\exceptions\InvalidFormSubmissionException |
|
530 | + * @throws \InvalidArgumentException |
|
531 | + * @throws \LogicException |
|
532 | + */ |
|
533 | + protected function _update_admin_option_settings() |
|
534 | + { |
|
535 | + try { |
|
536 | + $admin_options_settings_form = new AdminOptionsSettings(EE_Registry::instance()); |
|
537 | + $admin_options_settings_form->process($this->_req_data[ $admin_options_settings_form->slug() ]); |
|
538 | + EE_Registry::instance()->CFG->admin = apply_filters( |
|
539 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__CFG_admin', |
|
540 | + EE_Registry::instance()->CFG->admin |
|
541 | + ); |
|
542 | + } catch (Exception $e) { |
|
543 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
544 | + } |
|
545 | + $this->_redirect_after_action( |
|
546 | + apply_filters( |
|
547 | + 'FHEE__General_Settings_Admin_Page___update_admin_option_settings__success', |
|
548 | + $this->_update_espresso_configuration( |
|
549 | + 'Admin Options', |
|
550 | + EE_Registry::instance()->CFG->admin, |
|
551 | + __FILE__, |
|
552 | + __FUNCTION__, |
|
553 | + __LINE__ |
|
554 | + ) |
|
555 | + ), |
|
556 | + 'Admin Options', |
|
557 | + 'updated', |
|
558 | + array('action' => 'admin_option_settings') |
|
559 | + ); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /************* Countries *************/ |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * @return string |
|
568 | + */ |
|
569 | + protected function getCountryIsoForSite() |
|
570 | + { |
|
571 | + return ! empty(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
572 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
573 | + : 'US'; |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * Output Country Settings view. |
|
580 | + * |
|
581 | + * @throws DomainException |
|
582 | + * @throws EE_Error |
|
583 | + */ |
|
584 | + protected function _country_settings() |
|
585 | + { |
|
586 | + $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
587 | + $CNT_ISO = isset($this->_req_data['country']) |
|
588 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
589 | + : $CNT_ISO_for_site; |
|
590 | + |
|
591 | + // load field generator helper |
|
592 | + |
|
593 | + $this->_template_args['values'] = $this->_yes_no_values; |
|
594 | + |
|
595 | + $this->_template_args['countries'] = new EE_Question_Form_Input( |
|
596 | + EE_Question::new_instance( |
|
597 | + array( |
|
598 | + 'QST_ID' => 0, |
|
599 | + 'QST_display_text' => __('Select Country', 'event_espresso'), |
|
600 | + 'QST_system' => 'admin-country', |
|
601 | + ) |
|
602 | + ), |
|
603 | + EE_Answer::new_instance( |
|
604 | + array( |
|
605 | + 'ANS_ID' => 0, |
|
606 | + 'ANS_value' => $CNT_ISO, |
|
607 | + ) |
|
608 | + ), |
|
609 | + array( |
|
610 | + 'input_id' => 'country', |
|
611 | + 'input_name' => 'country', |
|
612 | + 'input_prefix' => '', |
|
613 | + 'append_qstn_id' => false, |
|
614 | + ) |
|
615 | + ); |
|
616 | + |
|
617 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
618 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
619 | + $this->_template_args['country_details_settings'] = $this->display_country_settings(); |
|
620 | + $this->_template_args['country_states_settings'] = $this->display_country_states(); |
|
621 | + $this->_template_args['CNT_name_for_site'] = EEM_Country::instance()->get_one_by_ID($CNT_ISO_for_site) |
|
622 | + ->name(); |
|
623 | + |
|
624 | + $this->_set_add_edit_form_tags('update_country_settings'); |
|
625 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
626 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
627 | + GEN_SET_TEMPLATE_PATH . 'countries_settings.template.php', |
|
628 | + $this->_template_args, |
|
629 | + true |
|
630 | + ); |
|
631 | + $this->display_admin_page_with_no_sidebar(); |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + /** |
|
636 | + * display_country_settings |
|
637 | + * |
|
638 | + * @access public |
|
639 | + * @param string $CNT_ISO |
|
640 | + * @return mixed string | array |
|
641 | + * @throws DomainException |
|
642 | + */ |
|
643 | + public function display_country_settings($CNT_ISO = '') |
|
644 | + { |
|
645 | + $CNT_ISO_for_site = $this->getCountryIsoForSite(); |
|
646 | + |
|
647 | + $CNT_ISO = isset($this->_req_data['country']) |
|
648 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
649 | + : $CNT_ISO; |
|
650 | + if (! $CNT_ISO) { |
|
651 | + return ''; |
|
652 | + } |
|
653 | + |
|
654 | + // for ajax |
|
655 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
656 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
657 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'country_form_field_label_wrap'), 10, 2); |
|
658 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'country_form_field_input__wrap'), 10, 2); |
|
659 | + /** @var EE_Country $country */ |
|
660 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
661 | + |
|
662 | + $CNT_cur_disabled = $CNT_ISO !== $CNT_ISO_for_site; |
|
663 | + $this->_template_args['CNT_cur_disabled'] = $CNT_cur_disabled; |
|
664 | + |
|
665 | + $country_input_types = array( |
|
666 | + 'CNT_active' => array( |
|
667 | + 'type' => 'RADIO_BTN', |
|
668 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
669 | + 'class' => '', |
|
670 | + 'options' => $this->_yes_no_values, |
|
671 | + 'use_desc_4_label' => true, |
|
672 | + ), |
|
673 | + 'CNT_ISO' => array( |
|
674 | + 'type' => 'TEXT', |
|
675 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
676 | + 'class' => 'small-text', |
|
677 | + ), |
|
678 | + 'CNT_ISO3' => array( |
|
679 | + 'type' => 'TEXT', |
|
680 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
681 | + 'class' => 'small-text', |
|
682 | + ), |
|
683 | + 'RGN_ID' => array( |
|
684 | + 'type' => 'TEXT', |
|
685 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
686 | + 'class' => 'small-text', |
|
687 | + ), |
|
688 | + 'CNT_name' => array( |
|
689 | + 'type' => 'TEXT', |
|
690 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
691 | + 'class' => 'regular-text', |
|
692 | + ), |
|
693 | + 'CNT_cur_code' => array( |
|
694 | + 'type' => 'TEXT', |
|
695 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
696 | + 'class' => 'small-text', |
|
697 | + 'disabled' => $CNT_cur_disabled |
|
698 | + ), |
|
699 | + 'CNT_cur_single' => array( |
|
700 | + 'type' => 'TEXT', |
|
701 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
702 | + 'class' => 'medium-text', |
|
703 | + 'disabled' => $CNT_cur_disabled |
|
704 | + ), |
|
705 | + 'CNT_cur_plural' => array( |
|
706 | + 'type' => 'TEXT', |
|
707 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
708 | + 'class' => 'medium-text', |
|
709 | + 'disabled' => $CNT_cur_disabled |
|
710 | + ), |
|
711 | + 'CNT_cur_sign' => array( |
|
712 | + 'type' => 'TEXT', |
|
713 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
714 | + 'class' => 'small-text', |
|
715 | + 'htmlentities' => false, |
|
716 | + 'disabled' => $CNT_cur_disabled |
|
717 | + ), |
|
718 | + 'CNT_cur_sign_b4' => array( |
|
719 | + 'type' => 'RADIO_BTN', |
|
720 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
721 | + 'class' => '', |
|
722 | + 'options' => $this->_yes_no_values, |
|
723 | + 'use_desc_4_label' => true, |
|
724 | + 'disabled' => $CNT_cur_disabled |
|
725 | + ), |
|
726 | + 'CNT_cur_dec_plc' => array( |
|
727 | + 'type' => 'RADIO_BTN', |
|
728 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
729 | + 'class' => '', |
|
730 | + 'options' => array( |
|
731 | + array('id' => 0, 'text' => ''), |
|
732 | + array('id' => 1, 'text' => ''), |
|
733 | + array('id' => 2, 'text' => ''), |
|
734 | + array('id' => 3, 'text' => ''), |
|
735 | + ), |
|
736 | + 'disabled' => $CNT_cur_disabled |
|
737 | + ), |
|
738 | + 'CNT_cur_dec_mrk' => array( |
|
739 | + 'type' => 'RADIO_BTN', |
|
740 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
741 | + 'class' => '', |
|
742 | + 'options' => array( |
|
743 | + array( |
|
744 | + 'id' => ',', |
|
745 | + 'text' => __(', (comma)', 'event_espresso'), |
|
746 | + ), |
|
747 | + array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
748 | + ), |
|
749 | + 'use_desc_4_label' => true, |
|
750 | + 'disabled' => $CNT_cur_disabled |
|
751 | + ), |
|
752 | + 'CNT_cur_thsnds' => array( |
|
753 | + 'type' => 'RADIO_BTN', |
|
754 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
755 | + 'class' => '', |
|
756 | + 'options' => array( |
|
757 | + array( |
|
758 | + 'id' => ',', |
|
759 | + 'text' => __(', (comma)', 'event_espresso'), |
|
760 | + ), |
|
761 | + array('id' => '.', 'text' => __('. (decimal)', 'event_espresso')), |
|
762 | + ), |
|
763 | + 'use_desc_4_label' => true, |
|
764 | + 'disabled' => $CNT_cur_disabled |
|
765 | + ), |
|
766 | + 'CNT_tel_code' => array( |
|
767 | + 'type' => 'TEXT', |
|
768 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
769 | + 'class' => 'small-text', |
|
770 | + ), |
|
771 | + 'CNT_is_EU' => array( |
|
772 | + 'type' => 'RADIO_BTN', |
|
773 | + 'input_name' => 'cntry[' . $CNT_ISO . ']', |
|
774 | + 'class' => '', |
|
775 | + 'options' => $this->_yes_no_values, |
|
776 | + 'use_desc_4_label' => true, |
|
777 | + ), |
|
778 | + ); |
|
779 | + $this->_template_args['inputs'] = EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
780 | + $country, |
|
781 | + $country_input_types |
|
782 | + ); |
|
783 | + $country_details_settings = EEH_Template::display_template( |
|
784 | + GEN_SET_TEMPLATE_PATH . 'country_details_settings.template.php', |
|
785 | + $this->_template_args, |
|
786 | + true |
|
787 | + ); |
|
788 | + |
|
789 | + if (defined('DOING_AJAX')) { |
|
790 | + $notices = EE_Error::get_notices(false, false, false); |
|
791 | + echo wp_json_encode( |
|
792 | + array( |
|
793 | + 'return_data' => $country_details_settings, |
|
794 | + 'success' => $notices['success'], |
|
795 | + 'errors' => $notices['errors'], |
|
796 | + ) |
|
797 | + ); |
|
798 | + die(); |
|
799 | + } else { |
|
800 | + return $country_details_settings; |
|
801 | + } |
|
802 | + } |
|
803 | + |
|
804 | + |
|
805 | + /** |
|
806 | + * display_country_states |
|
807 | + * |
|
808 | + * @access public |
|
809 | + * @param string $CNT_ISO |
|
810 | + * @return string |
|
811 | + * @throws DomainException |
|
812 | + */ |
|
813 | + public function display_country_states($CNT_ISO = '') |
|
814 | + { |
|
815 | + |
|
816 | + $CNT_ISO = isset($this->_req_data['country']) ? sanitize_text_field($this->_req_data['country']) : $CNT_ISO; |
|
817 | + |
|
818 | + if (! $CNT_ISO) { |
|
819 | + return ''; |
|
820 | + } |
|
821 | + // for ajax |
|
822 | + remove_all_filters('FHEE__EEH_Form_Fields__label_html'); |
|
823 | + remove_all_filters('FHEE__EEH_Form_Fields__input_html'); |
|
824 | + add_filter('FHEE__EEH_Form_Fields__label_html', array($this, 'state_form_field_label_wrap'), 10, 2); |
|
825 | + add_filter('FHEE__EEH_Form_Fields__input_html', array($this, 'state_form_field_input__wrap'), 10, 2); |
|
826 | + $states = EEM_State::instance()->get_all_states_for_these_countries(array($CNT_ISO => $CNT_ISO)); |
|
827 | + |
|
828 | + if ($states) { |
|
829 | + foreach ($states as $STA_ID => $state) { |
|
830 | + if ($state instanceof EE_State) { |
|
831 | + // STA_abbrev STA_name STA_active |
|
832 | + $state_input_types = array( |
|
833 | + 'STA_abbrev' => array( |
|
834 | + 'type' => 'TEXT', |
|
835 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
836 | + 'class' => 'mid-text', |
|
837 | + ), |
|
838 | + 'STA_name' => array( |
|
839 | + 'type' => 'TEXT', |
|
840 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
841 | + 'class' => 'regular-text', |
|
842 | + ), |
|
843 | + 'STA_active' => array( |
|
844 | + 'type' => 'RADIO_BTN', |
|
845 | + 'input_name' => 'states[' . $STA_ID . ']', |
|
846 | + 'options' => $this->_yes_no_values, |
|
847 | + 'use_desc_4_label' => true, |
|
848 | + ), |
|
849 | + ); |
|
850 | + $this->_template_args['states'][ $STA_ID ]['inputs'] = |
|
851 | + EE_Question_Form_Input::generate_question_form_inputs_for_object( |
|
852 | + $state, |
|
853 | + $state_input_types |
|
854 | + ); |
|
855 | + $query_args = array( |
|
856 | + 'action' => 'delete_state', |
|
857 | + 'STA_ID' => $STA_ID, |
|
858 | + 'CNT_ISO' => $CNT_ISO, |
|
859 | + 'STA_abbrev' => $state->abbrev(), |
|
860 | + ); |
|
861 | + $this->_template_args['states'][ $STA_ID ]['delete_state_url'] = |
|
862 | + EE_Admin_Page::add_query_args_and_nonce( |
|
863 | + $query_args, |
|
864 | + GEN_SET_ADMIN_URL |
|
865 | + ); |
|
866 | + } |
|
867 | + } |
|
868 | + } else { |
|
869 | + $this->_template_args['states'] = false; |
|
870 | + } |
|
871 | + |
|
872 | + $this->_template_args['add_new_state_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
873 | + array('action' => 'add_new_state'), |
|
874 | + GEN_SET_ADMIN_URL |
|
875 | + ); |
|
876 | + |
|
877 | + $state_details_settings = EEH_Template::display_template( |
|
878 | + GEN_SET_TEMPLATE_PATH . 'state_details_settings.template.php', |
|
879 | + $this->_template_args, |
|
880 | + true |
|
881 | + ); |
|
882 | + |
|
883 | + if (defined('DOING_AJAX')) { |
|
884 | + $notices = EE_Error::get_notices(false, false, false); |
|
885 | + echo wp_json_encode( |
|
886 | + array( |
|
887 | + 'return_data' => $state_details_settings, |
|
888 | + 'success' => $notices['success'], |
|
889 | + 'errors' => $notices['errors'], |
|
890 | + ) |
|
891 | + ); |
|
892 | + die(); |
|
893 | + } else { |
|
894 | + return $state_details_settings; |
|
895 | + } |
|
896 | + } |
|
897 | + |
|
898 | + |
|
899 | + /** |
|
900 | + * add_new_state |
|
901 | + * |
|
902 | + * @access public |
|
903 | + * @return void |
|
904 | + * @throws EE_Error |
|
905 | + */ |
|
906 | + public function add_new_state() |
|
907 | + { |
|
908 | + |
|
909 | + $success = true; |
|
910 | + |
|
911 | + $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
912 | + ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
913 | + : false; |
|
914 | + if (! $CNT_ISO) { |
|
915 | + EE_Error::add_error( |
|
916 | + __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
917 | + __FILE__, |
|
918 | + __FUNCTION__, |
|
919 | + __LINE__ |
|
920 | + ); |
|
921 | + $success = false; |
|
922 | + } |
|
923 | + $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
924 | + ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
925 | + : false; |
|
926 | + if (! $STA_abbrev) { |
|
927 | + EE_Error::add_error( |
|
928 | + __('No State ISO code or an invalid State ISO code was received.', 'event_espresso'), |
|
929 | + __FILE__, |
|
930 | + __FUNCTION__, |
|
931 | + __LINE__ |
|
932 | + ); |
|
933 | + $success = false; |
|
934 | + } |
|
935 | + $STA_name = isset($this->_req_data['STA_name']) |
|
936 | + ? sanitize_text_field($this->_req_data['STA_name']) |
|
937 | + : false; |
|
938 | + if (! $STA_name) { |
|
939 | + EE_Error::add_error( |
|
940 | + __('No State name or an invalid State name was received.', 'event_espresso'), |
|
941 | + __FILE__, |
|
942 | + __FUNCTION__, |
|
943 | + __LINE__ |
|
944 | + ); |
|
945 | + $success = false; |
|
946 | + } |
|
947 | + |
|
948 | + if ($success) { |
|
949 | + $cols_n_values = array( |
|
950 | + 'CNT_ISO' => $CNT_ISO, |
|
951 | + 'STA_abbrev' => $STA_abbrev, |
|
952 | + 'STA_name' => $STA_name, |
|
953 | + 'STA_active' => true, |
|
954 | + ); |
|
955 | + $success = EEM_State::instance()->insert($cols_n_values); |
|
956 | + EE_Error::add_success(__('The State was added successfully.', 'event_espresso')); |
|
957 | + } |
|
958 | + |
|
959 | + if (defined('DOING_AJAX')) { |
|
960 | + $notices = EE_Error::get_notices(false, false, false); |
|
961 | + echo wp_json_encode(array_merge($notices, array('return_data' => $CNT_ISO))); |
|
962 | + die(); |
|
963 | + } else { |
|
964 | + $this->_redirect_after_action($success, 'State', 'added', array('action' => 'country_settings')); |
|
965 | + } |
|
966 | + } |
|
967 | + |
|
968 | + |
|
969 | + /** |
|
970 | + * delete_state |
|
971 | + * |
|
972 | + * @access public |
|
973 | + * @return boolean |
|
974 | + * @throws EE_Error |
|
975 | + * @throws EE_Error |
|
976 | + */ |
|
977 | + public function delete_state() |
|
978 | + { |
|
979 | + $CNT_ISO = isset($this->_req_data['CNT_ISO']) |
|
980 | + ? strtoupper(sanitize_text_field($this->_req_data['CNT_ISO'])) |
|
981 | + : false; |
|
982 | + $STA_ID = isset($this->_req_data['STA_ID']) |
|
983 | + ? sanitize_text_field($this->_req_data['STA_ID']) |
|
984 | + : false; |
|
985 | + $STA_abbrev = isset($this->_req_data['STA_abbrev']) |
|
986 | + ? sanitize_text_field($this->_req_data['STA_abbrev']) |
|
987 | + : false; |
|
988 | + if (! $STA_ID) { |
|
989 | + EE_Error::add_error( |
|
990 | + __('No State ID or an invalid State ID was received.', 'event_espresso'), |
|
991 | + __FILE__, |
|
992 | + __FUNCTION__, |
|
993 | + __LINE__ |
|
994 | + ); |
|
995 | + return false; |
|
996 | + } |
|
997 | + |
|
998 | + $success = EEM_State::instance()->delete_by_ID($STA_ID); |
|
999 | + if ($success !== false) { |
|
1000 | + do_action( |
|
1001 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
1002 | + $CNT_ISO, |
|
1003 | + $STA_ID, |
|
1004 | + array('STA_abbrev' => $STA_abbrev) |
|
1005 | + ); |
|
1006 | + EE_Error::add_success(__('The State was deleted successfully.', 'event_espresso')); |
|
1007 | + } |
|
1008 | + if (defined('DOING_AJAX')) { |
|
1009 | + $notices = EE_Error::get_notices(false, false); |
|
1010 | + $notices['return_data'] = true; |
|
1011 | + echo wp_json_encode($notices); |
|
1012 | + die(); |
|
1013 | + } else { |
|
1014 | + $this->_redirect_after_action( |
|
1015 | + $success, |
|
1016 | + 'State', |
|
1017 | + 'deleted', |
|
1018 | + array('action' => 'country_settings') |
|
1019 | + ); |
|
1020 | + } |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * _update_country_settings |
|
1026 | + * |
|
1027 | + * @access protected |
|
1028 | + * @return void |
|
1029 | + * @throws EE_Error |
|
1030 | + */ |
|
1031 | + protected function _update_country_settings() |
|
1032 | + { |
|
1033 | + // grab the country ISO code |
|
1034 | + $CNT_ISO = isset($this->_req_data['country']) |
|
1035 | + ? strtoupper(sanitize_text_field($this->_req_data['country'])) |
|
1036 | + : false; |
|
1037 | + if (! $CNT_ISO) { |
|
1038 | + EE_Error::add_error( |
|
1039 | + __('No Country ISO code or an invalid Country ISO code was received.', 'event_espresso'), |
|
1040 | + __FILE__, |
|
1041 | + __FUNCTION__, |
|
1042 | + __LINE__ |
|
1043 | + ); |
|
1044 | + |
|
1045 | + return; |
|
1046 | + } |
|
1047 | + $cols_n_values = array(); |
|
1048 | + $cols_n_values['CNT_ISO3'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3']) |
|
1049 | + ? strtoupper(sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_ISO3'])) |
|
1050 | + : false; |
|
1051 | + $cols_n_values['RGN_ID'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1052 | + ? absint($this->_req_data['cntry'][ $CNT_ISO ]['RGN_ID']) |
|
1053 | + : null; |
|
1054 | + $cols_n_values['CNT_name'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1055 | + ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_name']) |
|
1056 | + : null; |
|
1057 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code'])) { |
|
1058 | + $cols_n_values['CNT_cur_code'] = strtoupper( |
|
1059 | + sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_code']) |
|
1060 | + ); |
|
1061 | + } |
|
1062 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'])) { |
|
1063 | + $cols_n_values['CNT_cur_single'] = sanitize_text_field( |
|
1064 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_single'] |
|
1065 | + ); |
|
1066 | + } |
|
1067 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'])) { |
|
1068 | + $cols_n_values['CNT_cur_plural'] = sanitize_text_field( |
|
1069 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_plural'] |
|
1070 | + ); |
|
1071 | + } |
|
1072 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'])) { |
|
1073 | + $cols_n_values['CNT_cur_sign'] = sanitize_text_field( |
|
1074 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign'] |
|
1075 | + ); |
|
1076 | + } |
|
1077 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'])) { |
|
1078 | + $cols_n_values['CNT_cur_sign_b4'] = absint( |
|
1079 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_sign_b4'] |
|
1080 | + ); |
|
1081 | + } |
|
1082 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'])) { |
|
1083 | + $cols_n_values['CNT_cur_dec_plc'] = absint( |
|
1084 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_plc'] |
|
1085 | + ); |
|
1086 | + } |
|
1087 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'])) { |
|
1088 | + $cols_n_values['CNT_cur_dec_mrk'] = sanitize_text_field( |
|
1089 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_dec_mrk'] |
|
1090 | + ); |
|
1091 | + } |
|
1092 | + if (isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'])) { |
|
1093 | + $cols_n_values['CNT_cur_thsnds'] = sanitize_text_field( |
|
1094 | + $this->_req_data['cntry'][ $CNT_ISO ]['CNT_cur_thsnds'] |
|
1095 | + ); |
|
1096 | + } |
|
1097 | + $cols_n_values['CNT_tel_code'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1098 | + ? sanitize_text_field($this->_req_data['cntry'][ $CNT_ISO ]['CNT_tel_code']) |
|
1099 | + : null; |
|
1100 | + $cols_n_values['CNT_is_EU'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1101 | + ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_is_EU']) |
|
1102 | + : false; |
|
1103 | + $cols_n_values['CNT_active'] = isset($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1104 | + ? absint($this->_req_data['cntry'][ $CNT_ISO ]['CNT_active']) |
|
1105 | + : false; |
|
1106 | + // allow filtering of country data |
|
1107 | + $cols_n_values = apply_filters( |
|
1108 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__cols_n_values', |
|
1109 | + $cols_n_values |
|
1110 | + ); |
|
1111 | + |
|
1112 | + // where values |
|
1113 | + $where_cols_n_values = array(array('CNT_ISO' => $CNT_ISO)); |
|
1114 | + // run the update |
|
1115 | + $success = EEM_Country::instance()->update($cols_n_values, $where_cols_n_values); |
|
1116 | + |
|
1117 | + if (isset($this->_req_data['states']) && is_array($this->_req_data['states']) && $success !== false) { |
|
1118 | + // allow filtering of states data |
|
1119 | + $states = apply_filters( |
|
1120 | + 'FHEE__General_Settings_Admin_Page___update_country_settings__states', |
|
1121 | + $this->_req_data['states'] |
|
1122 | + ); |
|
1123 | + |
|
1124 | + // loop thru state data ( looks like : states[75][STA_name] ) |
|
1125 | + foreach ($states as $STA_ID => $state) { |
|
1126 | + $cols_n_values = array( |
|
1127 | + 'CNT_ISO' => $CNT_ISO, |
|
1128 | + 'STA_abbrev' => sanitize_text_field($state['STA_abbrev']), |
|
1129 | + 'STA_name' => sanitize_text_field($state['STA_name']), |
|
1130 | + 'STA_active' => (bool) absint($state['STA_active']), |
|
1131 | + ); |
|
1132 | + // where values |
|
1133 | + $where_cols_n_values = array(array('STA_ID' => $STA_ID)); |
|
1134 | + // run the update |
|
1135 | + $success = EEM_State::instance()->update($cols_n_values, $where_cols_n_values); |
|
1136 | + if ($success !== false) { |
|
1137 | + do_action( |
|
1138 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
1139 | + $CNT_ISO, |
|
1140 | + $STA_ID, |
|
1141 | + $cols_n_values |
|
1142 | + ); |
|
1143 | + } |
|
1144 | + } |
|
1145 | + } |
|
1146 | + // check if country being edited matches org option country, and if so, then update EE_Config with new settings |
|
1147 | + if (isset(EE_Registry::instance()->CFG->organization->CNT_ISO) |
|
1148 | + && $CNT_ISO == EE_Registry::instance()->CFG->organization->CNT_ISO |
|
1149 | + ) { |
|
1150 | + EE_Registry::instance()->CFG->currency = new EE_Currency_Config($CNT_ISO); |
|
1151 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
1152 | + } |
|
1153 | + |
|
1154 | + if ($success !== false) { |
|
1155 | + EE_Error::add_success( |
|
1156 | + esc_html__('Country Settings updated successfully.', 'event_espresso') |
|
1157 | + ); |
|
1158 | + } |
|
1159 | + $this->_redirect_after_action( |
|
1160 | + $success, |
|
1161 | + '', |
|
1162 | + '', |
|
1163 | + array('action' => 'country_settings', 'country' => $CNT_ISO), |
|
1164 | + true |
|
1165 | + ); |
|
1166 | + } |
|
1167 | + |
|
1168 | + |
|
1169 | + /** |
|
1170 | + * form_form_field_label_wrap |
|
1171 | + * |
|
1172 | + * @access public |
|
1173 | + * @param string $label |
|
1174 | + * @return string |
|
1175 | + */ |
|
1176 | + public function country_form_field_label_wrap($label, $required_text) |
|
1177 | + { |
|
1178 | + return ' |
|
1179 | 1179 | <tr> |
1180 | 1180 | <th> |
1181 | 1181 | ' . $label . ' |
1182 | 1182 | </th>'; |
1183 | - } |
|
1184 | - |
|
1185 | - |
|
1186 | - /** |
|
1187 | - * form_form_field_input__wrap |
|
1188 | - * |
|
1189 | - * @access public |
|
1190 | - * @param string $label |
|
1191 | - * @return string |
|
1192 | - */ |
|
1193 | - public function country_form_field_input__wrap($input, $label) |
|
1194 | - { |
|
1195 | - return ' |
|
1183 | + } |
|
1184 | + |
|
1185 | + |
|
1186 | + /** |
|
1187 | + * form_form_field_input__wrap |
|
1188 | + * |
|
1189 | + * @access public |
|
1190 | + * @param string $label |
|
1191 | + * @return string |
|
1192 | + */ |
|
1193 | + public function country_form_field_input__wrap($input, $label) |
|
1194 | + { |
|
1195 | + return ' |
|
1196 | 1196 | <td class="general-settings-country-input-td"> |
1197 | 1197 | ' . $input . ' |
1198 | 1198 | </td> |
1199 | 1199 | </tr>'; |
1200 | - } |
|
1201 | - |
|
1202 | - |
|
1203 | - /** |
|
1204 | - * form_form_field_label_wrap |
|
1205 | - * |
|
1206 | - * @access public |
|
1207 | - * @param string $label |
|
1208 | - * @param string $required_text |
|
1209 | - * @return string |
|
1210 | - */ |
|
1211 | - public function state_form_field_label_wrap($label, $required_text) |
|
1212 | - { |
|
1213 | - return $required_text; |
|
1214 | - } |
|
1215 | - |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * form_form_field_input__wrap |
|
1219 | - * |
|
1220 | - * @access public |
|
1221 | - * @param string $label |
|
1222 | - * @return string |
|
1223 | - */ |
|
1224 | - public function state_form_field_input__wrap($input, $label) |
|
1225 | - { |
|
1226 | - return ' |
|
1200 | + } |
|
1201 | + |
|
1202 | + |
|
1203 | + /** |
|
1204 | + * form_form_field_label_wrap |
|
1205 | + * |
|
1206 | + * @access public |
|
1207 | + * @param string $label |
|
1208 | + * @param string $required_text |
|
1209 | + * @return string |
|
1210 | + */ |
|
1211 | + public function state_form_field_label_wrap($label, $required_text) |
|
1212 | + { |
|
1213 | + return $required_text; |
|
1214 | + } |
|
1215 | + |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * form_form_field_input__wrap |
|
1219 | + * |
|
1220 | + * @access public |
|
1221 | + * @param string $label |
|
1222 | + * @return string |
|
1223 | + */ |
|
1224 | + public function state_form_field_input__wrap($input, $label) |
|
1225 | + { |
|
1226 | + return ' |
|
1227 | 1227 | <td class="general-settings-country-state-input-td"> |
1228 | 1228 | ' . $input . ' |
1229 | 1229 | </td>'; |
1230 | - } |
|
1231 | - |
|
1232 | - |
|
1233 | - /***********/ |
|
1234 | - |
|
1235 | - |
|
1236 | - /** |
|
1237 | - * displays edit and view links for critical EE pages |
|
1238 | - * |
|
1239 | - * @access public |
|
1240 | - * @param int $ee_page_id |
|
1241 | - * @return string |
|
1242 | - */ |
|
1243 | - public static function edit_view_links($ee_page_id) |
|
1244 | - { |
|
1245 | - $links = '<a href="' |
|
1246 | - . add_query_arg( |
|
1247 | - array('post' => $ee_page_id, 'action' => 'edit'), |
|
1248 | - admin_url('post.php') |
|
1249 | - ) |
|
1250 | - . '" >' |
|
1251 | - . __('Edit', 'event_espresso') |
|
1252 | - . '</a>'; |
|
1253 | - $links .= ' | '; |
|
1254 | - $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>'; |
|
1255 | - |
|
1256 | - return $links; |
|
1257 | - } |
|
1258 | - |
|
1259 | - |
|
1260 | - /** |
|
1261 | - * displays page and shortcode status for critical EE pages |
|
1262 | - * |
|
1263 | - * @param WP page object $ee_page |
|
1264 | - * @return string |
|
1265 | - */ |
|
1266 | - public static function page_and_shortcode_status($ee_page, $shortcode) |
|
1267 | - { |
|
1268 | - |
|
1269 | - // page status |
|
1270 | - if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
1271 | - $pg_colour = 'green'; |
|
1272 | - $pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
1273 | - } else { |
|
1274 | - $pg_colour = 'red'; |
|
1275 | - $pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
1276 | - } |
|
1277 | - |
|
1278 | - // shortcode status |
|
1279 | - if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
1280 | - $sc_colour = 'green'; |
|
1281 | - $sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), ' '); |
|
1282 | - } else { |
|
1283 | - $sc_colour = 'red'; |
|
1284 | - $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
1285 | - } |
|
1286 | - |
|
1287 | - return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
1288 | - . $pg_status |
|
1289 | - . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
1290 | - } |
|
1291 | - |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * generates a dropdown of all parent pages - copied from WP core |
|
1295 | - * |
|
1296 | - * @param int $default |
|
1297 | - * @param int $parent |
|
1298 | - * @param int $level |
|
1299 | - */ |
|
1300 | - public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0) |
|
1301 | - { |
|
1302 | - global $wpdb; |
|
1303 | - $items = $wpdb->get_results( |
|
1304 | - $wpdb->prepare( |
|
1305 | - "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
1306 | - $parent |
|
1307 | - ) |
|
1308 | - ); |
|
1309 | - |
|
1310 | - if ($items) { |
|
1311 | - foreach ($items as $item) { |
|
1312 | - $pad = str_repeat(' ', $level * 3); |
|
1313 | - if ($item->ID == $default) { |
|
1314 | - $current = ' selected="selected"'; |
|
1315 | - } else { |
|
1316 | - $current = ''; |
|
1317 | - } |
|
1318 | - |
|
1319 | - echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " |
|
1320 | - . esc_html($item->post_title) |
|
1321 | - . "</option>"; |
|
1322 | - parent_dropdown($default, $item->ID, $level + 1); |
|
1323 | - } |
|
1324 | - } |
|
1325 | - } |
|
1326 | - |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Loads the scripts for the privacy settings form |
|
1330 | - */ |
|
1331 | - public function load_scripts_styles_privacy_settings() |
|
1332 | - { |
|
1333 | - $form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1334 | - $form_handler->enqueueStylesAndScripts(); |
|
1335 | - } |
|
1336 | - |
|
1337 | - |
|
1338 | - /** |
|
1339 | - * display the privacy settings form |
|
1340 | - */ |
|
1341 | - public function privacySettings() |
|
1342 | - { |
|
1343 | - $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
1344 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1345 | - $form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1346 | - $this->_template_args['admin_page_content'] = $form_handler->display(); |
|
1347 | - $this->display_admin_page_with_sidebar(); |
|
1348 | - } |
|
1349 | - |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * Update the privacy settings from form data |
|
1353 | - * |
|
1354 | - * @throws EE_Error |
|
1355 | - */ |
|
1356 | - public function updatePrivacySettings() |
|
1357 | - { |
|
1358 | - $form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1359 | - $success = $form_handler->process($this->get_request_data()); |
|
1360 | - $this->_redirect_after_action( |
|
1361 | - $success, |
|
1362 | - esc_html__('Registration Form Options', 'event_espresso'), |
|
1363 | - 'updated', |
|
1364 | - array('action' => 'privacy_settings') |
|
1365 | - ); |
|
1366 | - } |
|
1230 | + } |
|
1231 | + |
|
1232 | + |
|
1233 | + /***********/ |
|
1234 | + |
|
1235 | + |
|
1236 | + /** |
|
1237 | + * displays edit and view links for critical EE pages |
|
1238 | + * |
|
1239 | + * @access public |
|
1240 | + * @param int $ee_page_id |
|
1241 | + * @return string |
|
1242 | + */ |
|
1243 | + public static function edit_view_links($ee_page_id) |
|
1244 | + { |
|
1245 | + $links = '<a href="' |
|
1246 | + . add_query_arg( |
|
1247 | + array('post' => $ee_page_id, 'action' => 'edit'), |
|
1248 | + admin_url('post.php') |
|
1249 | + ) |
|
1250 | + . '" >' |
|
1251 | + . __('Edit', 'event_espresso') |
|
1252 | + . '</a>'; |
|
1253 | + $links .= ' | '; |
|
1254 | + $links .= '<a href="' . get_permalink($ee_page_id) . '" >' . __('View', 'event_espresso') . '</a>'; |
|
1255 | + |
|
1256 | + return $links; |
|
1257 | + } |
|
1258 | + |
|
1259 | + |
|
1260 | + /** |
|
1261 | + * displays page and shortcode status for critical EE pages |
|
1262 | + * |
|
1263 | + * @param WP page object $ee_page |
|
1264 | + * @return string |
|
1265 | + */ |
|
1266 | + public static function page_and_shortcode_status($ee_page, $shortcode) |
|
1267 | + { |
|
1268 | + |
|
1269 | + // page status |
|
1270 | + if (isset($ee_page->post_status) && $ee_page->post_status == 'publish') { |
|
1271 | + $pg_colour = 'green'; |
|
1272 | + $pg_status = sprintf(__('Page%sStatus%sOK', 'event_espresso'), ' ', ' '); |
|
1273 | + } else { |
|
1274 | + $pg_colour = 'red'; |
|
1275 | + $pg_status = sprintf(__('Page%sVisibility%sProblem', 'event_espresso'), ' ', ' '); |
|
1276 | + } |
|
1277 | + |
|
1278 | + // shortcode status |
|
1279 | + if (isset($ee_page->post_content) && strpos($ee_page->post_content, $shortcode) !== false) { |
|
1280 | + $sc_colour = 'green'; |
|
1281 | + $sc_status = sprintf(__('Shortcode%sOK', 'event_espresso'), ' '); |
|
1282 | + } else { |
|
1283 | + $sc_colour = 'red'; |
|
1284 | + $sc_status = sprintf(__('Shortcode%sProblem', 'event_espresso'), ' '); |
|
1285 | + } |
|
1286 | + |
|
1287 | + return '<span style="color:' . $pg_colour . '; margin-right:2em;"><strong>' |
|
1288 | + . $pg_status |
|
1289 | + . '</strong></span><span style="color:' . $sc_colour . '"><strong>' . $sc_status . '</strong></span>'; |
|
1290 | + } |
|
1291 | + |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * generates a dropdown of all parent pages - copied from WP core |
|
1295 | + * |
|
1296 | + * @param int $default |
|
1297 | + * @param int $parent |
|
1298 | + * @param int $level |
|
1299 | + */ |
|
1300 | + public static function page_settings_dropdown($default = 0, $parent = 0, $level = 0) |
|
1301 | + { |
|
1302 | + global $wpdb; |
|
1303 | + $items = $wpdb->get_results( |
|
1304 | + $wpdb->prepare( |
|
1305 | + "SELECT ID, post_parent, post_title FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'page' AND post_status != 'trash' ORDER BY menu_order", |
|
1306 | + $parent |
|
1307 | + ) |
|
1308 | + ); |
|
1309 | + |
|
1310 | + if ($items) { |
|
1311 | + foreach ($items as $item) { |
|
1312 | + $pad = str_repeat(' ', $level * 3); |
|
1313 | + if ($item->ID == $default) { |
|
1314 | + $current = ' selected="selected"'; |
|
1315 | + } else { |
|
1316 | + $current = ''; |
|
1317 | + } |
|
1318 | + |
|
1319 | + echo "\n\t<option class='level-$level' value='$item->ID'$current>$pad " |
|
1320 | + . esc_html($item->post_title) |
|
1321 | + . "</option>"; |
|
1322 | + parent_dropdown($default, $item->ID, $level + 1); |
|
1323 | + } |
|
1324 | + } |
|
1325 | + } |
|
1326 | + |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Loads the scripts for the privacy settings form |
|
1330 | + */ |
|
1331 | + public function load_scripts_styles_privacy_settings() |
|
1332 | + { |
|
1333 | + $form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1334 | + $form_handler->enqueueStylesAndScripts(); |
|
1335 | + } |
|
1336 | + |
|
1337 | + |
|
1338 | + /** |
|
1339 | + * display the privacy settings form |
|
1340 | + */ |
|
1341 | + public function privacySettings() |
|
1342 | + { |
|
1343 | + $this->_set_add_edit_form_tags('update_privacy_settings'); |
|
1344 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
1345 | + $form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1346 | + $this->_template_args['admin_page_content'] = $form_handler->display(); |
|
1347 | + $this->display_admin_page_with_sidebar(); |
|
1348 | + } |
|
1349 | + |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * Update the privacy settings from form data |
|
1353 | + * |
|
1354 | + * @throws EE_Error |
|
1355 | + */ |
|
1356 | + public function updatePrivacySettings() |
|
1357 | + { |
|
1358 | + $form_handler = LoaderFactory::getLoader()->getShared('EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler'); |
|
1359 | + $success = $form_handler->process($this->get_request_data()); |
|
1360 | + $this->_redirect_after_action( |
|
1361 | + $success, |
|
1362 | + esc_html__('Registration Form Options', 'event_espresso'), |
|
1363 | + 'updated', |
|
1364 | + array('action' => 'privacy_settings') |
|
1365 | + ); |
|
1366 | + } |
|
1367 | 1367 | } |
@@ -14,2488 +14,2488 @@ |
||
14 | 14 | class Transactions_Admin_Page extends EE_Admin_Page |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @var EE_Transaction |
|
19 | - */ |
|
20 | - private $_transaction; |
|
21 | - |
|
22 | - /** |
|
23 | - * @var EE_Session |
|
24 | - */ |
|
25 | - private $_session; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var array $_txn_status |
|
29 | - */ |
|
30 | - private static $_txn_status; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var array $_pay_status |
|
34 | - */ |
|
35 | - private static $_pay_status; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var array $_existing_reg_payment_REG_IDs |
|
39 | - */ |
|
40 | - protected $_existing_reg_payment_REG_IDs = null; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @Constructor |
|
45 | - * @access public |
|
46 | - * @param bool $routing |
|
47 | - * @throws EE_Error |
|
48 | - * @throws InvalidArgumentException |
|
49 | - * @throws ReflectionException |
|
50 | - * @throws InvalidDataTypeException |
|
51 | - * @throws InvalidInterfaceException |
|
52 | - */ |
|
53 | - public function __construct($routing = true) |
|
54 | - { |
|
55 | - parent::__construct($routing); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * _init_page_props |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - protected function _init_page_props() |
|
65 | - { |
|
66 | - $this->page_slug = TXN_PG_SLUG; |
|
67 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
68 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
69 | - $this->_admin_base_path = TXN_ADMIN; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * _ajax_hooks |
|
75 | - * |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - protected function _ajax_hooks() |
|
79 | - { |
|
80 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
81 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
82 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * _define_page_props |
|
88 | - * |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - protected function _define_page_props() |
|
92 | - { |
|
93 | - $this->_admin_page_title = $this->page_label; |
|
94 | - $this->_labels = array( |
|
95 | - 'buttons' => array( |
|
96 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
97 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
98 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
99 | - ), |
|
100 | - ); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * grab url requests and route them |
|
106 | - * |
|
107 | - * @access private |
|
108 | - * @return void |
|
109 | - * @throws EE_Error |
|
110 | - * @throws InvalidArgumentException |
|
111 | - * @throws InvalidDataTypeException |
|
112 | - * @throws InvalidInterfaceException |
|
113 | - */ |
|
114 | - public function _set_page_routes() |
|
115 | - { |
|
116 | - |
|
117 | - $this->_set_transaction_status_array(); |
|
118 | - |
|
119 | - $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
120 | - && ! is_array($this->_req_data['TXN_ID']) |
|
121 | - ? $this->_req_data['TXN_ID'] |
|
122 | - : 0; |
|
123 | - |
|
124 | - $this->_page_routes = array( |
|
125 | - |
|
126 | - 'default' => array( |
|
127 | - 'func' => '_transactions_overview_list_table', |
|
128 | - 'capability' => 'ee_read_transactions', |
|
129 | - ), |
|
130 | - |
|
131 | - 'view_transaction' => array( |
|
132 | - 'func' => '_transaction_details', |
|
133 | - 'capability' => 'ee_read_transaction', |
|
134 | - 'obj_id' => $txn_id, |
|
135 | - ), |
|
136 | - |
|
137 | - 'send_payment_reminder' => array( |
|
138 | - 'func' => '_send_payment_reminder', |
|
139 | - 'noheader' => true, |
|
140 | - 'capability' => 'ee_send_message', |
|
141 | - ), |
|
142 | - |
|
143 | - 'espresso_apply_payment' => array( |
|
144 | - 'func' => 'apply_payments_or_refunds', |
|
145 | - 'noheader' => true, |
|
146 | - 'capability' => 'ee_edit_payments', |
|
147 | - ), |
|
148 | - |
|
149 | - 'espresso_apply_refund' => array( |
|
150 | - 'func' => 'apply_payments_or_refunds', |
|
151 | - 'noheader' => true, |
|
152 | - 'capability' => 'ee_edit_payments', |
|
153 | - ), |
|
154 | - |
|
155 | - 'espresso_delete_payment' => array( |
|
156 | - 'func' => 'delete_payment', |
|
157 | - 'noheader' => true, |
|
158 | - 'capability' => 'ee_delete_payments', |
|
159 | - ), |
|
160 | - |
|
161 | - ); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - protected function _set_page_config() |
|
166 | - { |
|
167 | - $this->_page_config = array( |
|
168 | - 'default' => array( |
|
169 | - 'nav' => array( |
|
170 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
171 | - 'order' => 10, |
|
172 | - ), |
|
173 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
174 | - 'help_tabs' => array( |
|
175 | - 'transactions_overview_help_tab' => array( |
|
176 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
177 | - 'filename' => 'transactions_overview', |
|
178 | - ), |
|
179 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
180 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
181 | - 'filename' => 'transactions_overview_table_column_headings', |
|
182 | - ), |
|
183 | - 'transactions_overview_views_filters_help_tab' => array( |
|
184 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
185 | - 'filename' => 'transactions_overview_views_filters_search', |
|
186 | - ), |
|
187 | - ), |
|
188 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
189 | - /** |
|
190 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
191 | - * may change in a later iteration so want to keep the code for then. |
|
192 | - */ |
|
193 | - // 'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
194 | - 'require_nonce' => false, |
|
195 | - ), |
|
196 | - 'view_transaction' => array( |
|
197 | - 'nav' => array( |
|
198 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
199 | - 'order' => 5, |
|
200 | - 'url' => isset($this->_req_data['TXN_ID']) |
|
201 | - ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
202 | - : $this->_admin_base_url, |
|
203 | - 'persistent' => false, |
|
204 | - ), |
|
205 | - 'help_tabs' => array( |
|
206 | - 'transactions_view_transaction_help_tab' => array( |
|
207 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
208 | - 'filename' => 'transactions_view_transaction', |
|
209 | - ), |
|
210 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
211 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
212 | - 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
213 | - ), |
|
214 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
215 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
216 | - 'filename' => 'transactions_view_transaction_attendees_registered', |
|
217 | - ), |
|
218 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
219 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
220 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
221 | - ), |
|
222 | - ), |
|
223 | - 'qtips' => array('Transaction_Details_Tips'), |
|
224 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
225 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
226 | - |
|
227 | - 'require_nonce' => false, |
|
228 | - ), |
|
229 | - ); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * The below methods aren't used by this class currently |
|
235 | - */ |
|
236 | - protected function _add_screen_options() |
|
237 | - { |
|
238 | - // noop |
|
239 | - } |
|
240 | - |
|
241 | - protected function _add_feature_pointers() |
|
242 | - { |
|
243 | - // noop |
|
244 | - } |
|
245 | - |
|
246 | - public function admin_init() |
|
247 | - { |
|
248 | - // IF a registration was JUST added via the admin... |
|
249 | - if (isset( |
|
250 | - $this->_req_data['redirect_from'], |
|
251 | - $this->_req_data['EVT_ID'], |
|
252 | - $this->_req_data['event_name'] |
|
253 | - )) { |
|
254 | - // then set a cookie so that we can block any attempts to use |
|
255 | - // the back button as a way to enter another registration. |
|
256 | - setcookie( |
|
257 | - 'ee_registration_added', |
|
258 | - $this->_req_data['EVT_ID'], |
|
259 | - time() + WEEK_IN_SECONDS, |
|
260 | - '/' |
|
261 | - ); |
|
262 | - // and update the global |
|
263 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
264 | - } |
|
265 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
266 | - 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
267 | - 'event_espresso' |
|
268 | - ); |
|
269 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
270 | - 'An error occurred! Please refresh the page and try again.', |
|
271 | - 'event_espresso' |
|
272 | - ); |
|
273 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
274 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
275 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
276 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
277 | - 'This transaction has been overpaid ! Payments Total', |
|
278 | - 'event_espresso' |
|
279 | - ); |
|
280 | - } |
|
281 | - |
|
282 | - public function admin_notices() |
|
283 | - { |
|
284 | - // noop |
|
285 | - } |
|
286 | - |
|
287 | - public function admin_footer_scripts() |
|
288 | - { |
|
289 | - // noop |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * _set_transaction_status_array |
|
295 | - * sets list of transaction statuses |
|
296 | - * |
|
297 | - * @access private |
|
298 | - * @return void |
|
299 | - * @throws EE_Error |
|
300 | - * @throws InvalidArgumentException |
|
301 | - * @throws InvalidDataTypeException |
|
302 | - * @throws InvalidInterfaceException |
|
303 | - */ |
|
304 | - private function _set_transaction_status_array() |
|
305 | - { |
|
306 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * get_transaction_status_array |
|
312 | - * return the transaction status array for wp_list_table |
|
313 | - * |
|
314 | - * @access public |
|
315 | - * @return array |
|
316 | - */ |
|
317 | - public function get_transaction_status_array() |
|
318 | - { |
|
319 | - return self::$_txn_status; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * get list of payment statuses |
|
325 | - * |
|
326 | - * @access private |
|
327 | - * @return void |
|
328 | - * @throws EE_Error |
|
329 | - * @throws InvalidArgumentException |
|
330 | - * @throws InvalidDataTypeException |
|
331 | - * @throws InvalidInterfaceException |
|
332 | - */ |
|
333 | - private function _get_payment_status_array() |
|
334 | - { |
|
335 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
336 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * _add_screen_options_default |
|
342 | - * |
|
343 | - * @access protected |
|
344 | - * @return void |
|
345 | - * @throws InvalidArgumentException |
|
346 | - * @throws InvalidDataTypeException |
|
347 | - * @throws InvalidInterfaceException |
|
348 | - */ |
|
349 | - protected function _add_screen_options_default() |
|
350 | - { |
|
351 | - $this->_per_page_screen_option(); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * load_scripts_styles |
|
357 | - * |
|
358 | - * @access public |
|
359 | - * @return void |
|
360 | - */ |
|
361 | - public function load_scripts_styles() |
|
362 | - { |
|
363 | - // enqueue style |
|
364 | - wp_register_style( |
|
365 | - 'espresso_txn', |
|
366 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
367 | - array(), |
|
368 | - EVENT_ESPRESSO_VERSION |
|
369 | - ); |
|
370 | - wp_enqueue_style('espresso_txn'); |
|
371 | - // scripts |
|
372 | - wp_register_script( |
|
373 | - 'espresso_txn', |
|
374 | - TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
375 | - array( |
|
376 | - 'ee_admin_js', |
|
377 | - 'ee-datepicker', |
|
378 | - 'jquery-ui-datepicker', |
|
379 | - 'jquery-ui-draggable', |
|
380 | - 'ee-dialog', |
|
381 | - 'ee-accounting', |
|
382 | - 'ee-serialize-full-array', |
|
383 | - ), |
|
384 | - EVENT_ESPRESSO_VERSION, |
|
385 | - true |
|
386 | - ); |
|
387 | - wp_enqueue_script('espresso_txn'); |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * load_scripts_styles_view_transaction |
|
393 | - * |
|
394 | - * @access public |
|
395 | - * @return void |
|
396 | - */ |
|
397 | - public function load_scripts_styles_view_transaction() |
|
398 | - { |
|
399 | - // styles |
|
400 | - wp_enqueue_style('espresso-ui-theme'); |
|
401 | - } |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * load_scripts_styles_default |
|
406 | - * |
|
407 | - * @access public |
|
408 | - * @return void |
|
409 | - */ |
|
410 | - public function load_scripts_styles_default() |
|
411 | - { |
|
412 | - // styles |
|
413 | - wp_enqueue_style('espresso-ui-theme'); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * _set_list_table_views_default |
|
419 | - * |
|
420 | - * @access protected |
|
421 | - * @return void |
|
422 | - */ |
|
423 | - protected function _set_list_table_views_default() |
|
424 | - { |
|
425 | - $this->_views = array( |
|
426 | - 'all' => array( |
|
427 | - 'slug' => 'all', |
|
428 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
429 | - 'count' => 0, |
|
430 | - ), |
|
431 | - 'abandoned' => array( |
|
432 | - 'slug' => 'abandoned', |
|
433 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
434 | - 'count' => 0, |
|
435 | - ), |
|
436 | - ); |
|
437 | - if (/** |
|
438 | - * Filters whether a link to the "Failed Transactions" list table |
|
439 | - * appears on the Transactions Admin Page list table. |
|
440 | - * List display can be turned back on via the following: |
|
441 | - * add_filter( |
|
442 | - * 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
443 | - * '__return_true' |
|
444 | - * ); |
|
445 | - * |
|
446 | - * @since $VID:$ |
|
447 | - * @param boolean $display_failed_txns_list |
|
448 | - * @param Transactions_Admin_Page $this |
|
449 | - */ |
|
450 | - apply_filters( |
|
451 | - 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
452 | - false, |
|
453 | - $this |
|
454 | - ) |
|
455 | - ) { |
|
456 | - $this->_views['failed'] = array( |
|
457 | - 'slug' => 'failed', |
|
458 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
459 | - 'count' => 0, |
|
460 | - ); |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - /** |
|
466 | - * _set_transaction_object |
|
467 | - * This sets the _transaction property for the transaction details screen |
|
468 | - * |
|
469 | - * @access private |
|
470 | - * @return void |
|
471 | - * @throws EE_Error |
|
472 | - * @throws InvalidArgumentException |
|
473 | - * @throws RuntimeException |
|
474 | - * @throws InvalidDataTypeException |
|
475 | - * @throws InvalidInterfaceException |
|
476 | - * @throws ReflectionException |
|
477 | - */ |
|
478 | - private function _set_transaction_object() |
|
479 | - { |
|
480 | - if ($this->_transaction instanceof EE_Transaction) { |
|
481 | - return; |
|
482 | - } //get out we've already set the object |
|
483 | - |
|
484 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
485 | - ? absint($this->_req_data['TXN_ID']) |
|
486 | - : false; |
|
487 | - |
|
488 | - // get transaction object |
|
489 | - $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
490 | - $this->_session = $this->_transaction instanceof EE_Transaction |
|
491 | - ? $this->_transaction->get('TXN_session_data') |
|
492 | - : null; |
|
493 | - if ($this->_transaction instanceof EE_Transaction) { |
|
494 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
495 | - } |
|
496 | - |
|
497 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
498 | - $error_msg = sprintf( |
|
499 | - esc_html__( |
|
500 | - 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
501 | - 'event_espresso' |
|
502 | - ), |
|
503 | - $TXN_ID |
|
504 | - ); |
|
505 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
506 | - } |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * _transaction_legend_items |
|
512 | - * |
|
513 | - * @access protected |
|
514 | - * @return array |
|
515 | - * @throws EE_Error |
|
516 | - * @throws InvalidArgumentException |
|
517 | - * @throws ReflectionException |
|
518 | - * @throws InvalidDataTypeException |
|
519 | - * @throws InvalidInterfaceException |
|
520 | - */ |
|
521 | - protected function _transaction_legend_items() |
|
522 | - { |
|
523 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
524 | - $items = array(); |
|
525 | - |
|
526 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
527 | - 'ee_read_global_messages', |
|
528 | - 'view_filtered_messages' |
|
529 | - )) { |
|
530 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
531 | - if (is_array($related_for_icon) |
|
532 | - && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
533 | - ) { |
|
534 | - $items['view_related_messages'] = array( |
|
535 | - 'class' => $related_for_icon['css_class'], |
|
536 | - 'desc' => $related_for_icon['label'], |
|
537 | - ); |
|
538 | - } |
|
539 | - } |
|
540 | - |
|
541 | - $items = apply_filters( |
|
542 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
543 | - array_merge( |
|
544 | - $items, |
|
545 | - array( |
|
546 | - 'view_details' => array( |
|
547 | - 'class' => 'dashicons dashicons-cart', |
|
548 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
549 | - ), |
|
550 | - 'view_invoice' => array( |
|
551 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
552 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
553 | - ), |
|
554 | - 'view_receipt' => array( |
|
555 | - 'class' => 'dashicons dashicons-media-default', |
|
556 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
557 | - ), |
|
558 | - 'view_registration' => array( |
|
559 | - 'class' => 'dashicons dashicons-clipboard', |
|
560 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
561 | - ), |
|
562 | - 'payment_overview_link' => array( |
|
563 | - 'class' => 'dashicons dashicons-money', |
|
564 | - 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
565 | - ), |
|
566 | - ) |
|
567 | - ) |
|
568 | - ); |
|
569 | - |
|
570 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
571 | - 'ee_send_message', |
|
572 | - 'espresso_transactions_send_payment_reminder' |
|
573 | - )) { |
|
574 | - if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
575 | - $items['send_payment_reminder'] = array( |
|
576 | - 'class' => 'dashicons dashicons-email-alt', |
|
577 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
578 | - ); |
|
579 | - } else { |
|
580 | - $items['blank*'] = array( |
|
581 | - 'class' => '', |
|
582 | - 'desc' => '', |
|
583 | - ); |
|
584 | - } |
|
585 | - } else { |
|
586 | - $items['blank*'] = array( |
|
587 | - 'class' => '', |
|
588 | - 'desc' => '', |
|
589 | - ); |
|
590 | - } |
|
591 | - $more_items = apply_filters( |
|
592 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
593 | - array( |
|
594 | - 'overpaid' => array( |
|
595 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
596 | - 'desc' => EEH_Template::pretty_status( |
|
597 | - EEM_Transaction::overpaid_status_code, |
|
598 | - false, |
|
599 | - 'sentence' |
|
600 | - ), |
|
601 | - ), |
|
602 | - 'complete' => array( |
|
603 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
604 | - 'desc' => EEH_Template::pretty_status( |
|
605 | - EEM_Transaction::complete_status_code, |
|
606 | - false, |
|
607 | - 'sentence' |
|
608 | - ), |
|
609 | - ), |
|
610 | - 'incomplete' => array( |
|
611 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
612 | - 'desc' => EEH_Template::pretty_status( |
|
613 | - EEM_Transaction::incomplete_status_code, |
|
614 | - false, |
|
615 | - 'sentence' |
|
616 | - ), |
|
617 | - ), |
|
618 | - 'abandoned' => array( |
|
619 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
620 | - 'desc' => EEH_Template::pretty_status( |
|
621 | - EEM_Transaction::abandoned_status_code, |
|
622 | - false, |
|
623 | - 'sentence' |
|
624 | - ), |
|
625 | - ), |
|
626 | - 'failed' => array( |
|
627 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
628 | - 'desc' => EEH_Template::pretty_status( |
|
629 | - EEM_Transaction::failed_status_code, |
|
630 | - false, |
|
631 | - 'sentence' |
|
632 | - ), |
|
633 | - ), |
|
634 | - ) |
|
635 | - ); |
|
636 | - |
|
637 | - return array_merge($items, $more_items); |
|
638 | - } |
|
639 | - |
|
640 | - |
|
641 | - /** |
|
642 | - * _transactions_overview_list_table |
|
643 | - * |
|
644 | - * @access protected |
|
645 | - * @return void |
|
646 | - * @throws DomainException |
|
647 | - * @throws EE_Error |
|
648 | - * @throws InvalidArgumentException |
|
649 | - * @throws InvalidDataTypeException |
|
650 | - * @throws InvalidInterfaceException |
|
651 | - * @throws ReflectionException |
|
652 | - */ |
|
653 | - protected function _transactions_overview_list_table() |
|
654 | - { |
|
655 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
656 | - $event = isset($this->_req_data['EVT_ID']) |
|
657 | - ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
658 | - : null; |
|
659 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
660 | - ? sprintf( |
|
661 | - esc_html__( |
|
662 | - '%sViewing Transactions for the Event: %s%s', |
|
663 | - 'event_espresso' |
|
664 | - ), |
|
665 | - '<h3>', |
|
666 | - '<a href="' |
|
667 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
668 | - array('action' => 'edit', 'post' => $event->ID()), |
|
669 | - EVENTS_ADMIN_URL |
|
670 | - ) |
|
671 | - . '" title="' |
|
672 | - . esc_attr__( |
|
673 | - 'Click to Edit event', |
|
674 | - 'event_espresso' |
|
675 | - ) |
|
676 | - . '">' . $event->get('EVT_name') . '</a>', |
|
677 | - '</h3>' |
|
678 | - ) |
|
679 | - : ''; |
|
680 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
681 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
682 | - } |
|
683 | - |
|
684 | - |
|
685 | - /** |
|
686 | - * _transaction_details |
|
687 | - * generates HTML for the View Transaction Details Admin page |
|
688 | - * |
|
689 | - * @access protected |
|
690 | - * @return void |
|
691 | - * @throws DomainException |
|
692 | - * @throws EE_Error |
|
693 | - * @throws InvalidArgumentException |
|
694 | - * @throws InvalidDataTypeException |
|
695 | - * @throws InvalidInterfaceException |
|
696 | - * @throws RuntimeException |
|
697 | - * @throws ReflectionException |
|
698 | - */ |
|
699 | - protected function _transaction_details() |
|
700 | - { |
|
701 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
702 | - |
|
703 | - $this->_set_transaction_status_array(); |
|
704 | - |
|
705 | - $this->_template_args = array(); |
|
706 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
707 | - |
|
708 | - $this->_set_transaction_object(); |
|
709 | - |
|
710 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
711 | - return; |
|
712 | - } |
|
713 | - $primary_registration = $this->_transaction->primary_registration(); |
|
714 | - $attendee = $primary_registration instanceof EE_Registration |
|
715 | - ? $primary_registration->attendee() |
|
716 | - : null; |
|
717 | - |
|
718 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
719 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
720 | - |
|
721 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
722 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
723 | - |
|
724 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->get('STS_ID') ]; |
|
725 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
726 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
727 | - |
|
728 | - $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
729 | - $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
730 | - |
|
731 | - $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
732 | - $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
733 | - $amount_due, |
|
734 | - true |
|
735 | - ); |
|
736 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
737 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
738 | - . $this->_template_args['amount_due']; |
|
739 | - } else { |
|
740 | - $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
741 | - } |
|
742 | - $this->_template_args['amount_due_class'] = ''; |
|
743 | - |
|
744 | - if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
745 | - // paid in full |
|
746 | - $this->_template_args['amount_due'] = false; |
|
747 | - } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
748 | - // overpaid |
|
749 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
750 | - } elseif ($this->_transaction->get('TXN_total') > 0 |
|
751 | - && $this->_transaction->get('TXN_paid') > 0 |
|
752 | - ) { |
|
753 | - // monies owing |
|
754 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
755 | - } elseif ($this->_transaction->get('TXN_total') > 0 |
|
756 | - && $this->_transaction->get('TXN_paid') == 0 |
|
757 | - ) { |
|
758 | - // no payments made yet |
|
759 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
760 | - } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
761 | - // free event |
|
762 | - $this->_template_args['amount_due'] = false; |
|
763 | - } |
|
764 | - |
|
765 | - $payment_method = $this->_transaction->payment_method(); |
|
766 | - |
|
767 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
768 | - ? $payment_method->admin_name() |
|
769 | - : esc_html__('Unknown', 'event_espresso'); |
|
770 | - |
|
771 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
772 | - // link back to overview |
|
773 | - $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
774 | - ? $_SERVER['HTTP_REFERER'] |
|
775 | - : TXN_ADMIN_URL; |
|
776 | - |
|
777 | - |
|
778 | - // next link |
|
779 | - $next_txn = $this->_transaction->next( |
|
780 | - null, |
|
781 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
782 | - 'TXN_ID' |
|
783 | - ); |
|
784 | - $this->_template_args['next_transaction'] = $next_txn |
|
785 | - ? $this->_next_link( |
|
786 | - EE_Admin_Page::add_query_args_and_nonce( |
|
787 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
788 | - TXN_ADMIN_URL |
|
789 | - ), |
|
790 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
791 | - ) |
|
792 | - : ''; |
|
793 | - // previous link |
|
794 | - $previous_txn = $this->_transaction->previous( |
|
795 | - null, |
|
796 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
797 | - 'TXN_ID' |
|
798 | - ); |
|
799 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
800 | - ? $this->_previous_link( |
|
801 | - EE_Admin_Page::add_query_args_and_nonce( |
|
802 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
803 | - TXN_ADMIN_URL |
|
804 | - ), |
|
805 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
806 | - ) |
|
807 | - : ''; |
|
808 | - |
|
809 | - // were we just redirected here after adding a new registration ??? |
|
810 | - if (isset( |
|
811 | - $this->_req_data['redirect_from'], |
|
812 | - $this->_req_data['EVT_ID'], |
|
813 | - $this->_req_data['event_name'] |
|
814 | - )) { |
|
815 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
816 | - 'ee_edit_registrations', |
|
817 | - 'espresso_registrations_new_registration', |
|
818 | - $this->_req_data['EVT_ID'] |
|
819 | - )) { |
|
820 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
821 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
822 | - array( |
|
823 | - 'page' => 'espresso_registrations', |
|
824 | - 'action' => 'new_registration', |
|
825 | - 'return' => 'default', |
|
826 | - 'TXN_ID' => $this->_transaction->ID(), |
|
827 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
828 | - ), |
|
829 | - REG_ADMIN_URL |
|
830 | - ); |
|
831 | - $this->_admin_page_title .= '">'; |
|
832 | - |
|
833 | - $this->_admin_page_title .= sprintf( |
|
834 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
835 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
836 | - ); |
|
837 | - $this->_admin_page_title .= '</a>'; |
|
838 | - } |
|
839 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
840 | - } |
|
841 | - // grab messages at the last second |
|
842 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
843 | - // path to template |
|
844 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
845 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
846 | - $template_path, |
|
847 | - $this->_template_args, |
|
848 | - true |
|
849 | - ); |
|
850 | - |
|
851 | - // the details template wrapper |
|
852 | - $this->display_admin_page_with_sidebar(); |
|
853 | - } |
|
854 | - |
|
855 | - |
|
856 | - /** |
|
857 | - * _transaction_details_metaboxes |
|
858 | - * |
|
859 | - * @access protected |
|
860 | - * @return void |
|
861 | - * @throws EE_Error |
|
862 | - * @throws InvalidArgumentException |
|
863 | - * @throws InvalidDataTypeException |
|
864 | - * @throws InvalidInterfaceException |
|
865 | - * @throws RuntimeException |
|
866 | - * @throws ReflectionException |
|
867 | - */ |
|
868 | - protected function _transaction_details_metaboxes() |
|
869 | - { |
|
870 | - |
|
871 | - $this->_set_transaction_object(); |
|
872 | - |
|
873 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
874 | - return; |
|
875 | - } |
|
876 | - add_meta_box( |
|
877 | - 'edit-txn-details-mbox', |
|
878 | - esc_html__('Transaction Details', 'event_espresso'), |
|
879 | - array($this, 'txn_details_meta_box'), |
|
880 | - $this->_wp_page_slug, |
|
881 | - 'normal', |
|
882 | - 'high' |
|
883 | - ); |
|
884 | - add_meta_box( |
|
885 | - 'edit-txn-attendees-mbox', |
|
886 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
887 | - array($this, 'txn_attendees_meta_box'), |
|
888 | - $this->_wp_page_slug, |
|
889 | - 'normal', |
|
890 | - 'high', |
|
891 | - array('TXN_ID' => $this->_transaction->ID()) |
|
892 | - ); |
|
893 | - add_meta_box( |
|
894 | - 'edit-txn-registrant-mbox', |
|
895 | - esc_html__('Primary Contact', 'event_espresso'), |
|
896 | - array($this, 'txn_registrant_side_meta_box'), |
|
897 | - $this->_wp_page_slug, |
|
898 | - 'side', |
|
899 | - 'high' |
|
900 | - ); |
|
901 | - add_meta_box( |
|
902 | - 'edit-txn-billing-info-mbox', |
|
903 | - esc_html__('Billing Information', 'event_espresso'), |
|
904 | - array($this, 'txn_billing_info_side_meta_box'), |
|
905 | - $this->_wp_page_slug, |
|
906 | - 'side', |
|
907 | - 'high' |
|
908 | - ); |
|
909 | - } |
|
910 | - |
|
911 | - |
|
912 | - /** |
|
913 | - * Callback for transaction actions metabox. |
|
914 | - * |
|
915 | - * @param EE_Transaction|null $transaction |
|
916 | - * @throws DomainException |
|
917 | - * @throws EE_Error |
|
918 | - * @throws InvalidArgumentException |
|
919 | - * @throws InvalidDataTypeException |
|
920 | - * @throws InvalidInterfaceException |
|
921 | - * @throws ReflectionException |
|
922 | - * @throws RuntimeException |
|
923 | - */ |
|
924 | - public function getActionButtons(EE_Transaction $transaction = null) |
|
925 | - { |
|
926 | - $content = ''; |
|
927 | - $actions = array(); |
|
928 | - if (! $transaction instanceof EE_Transaction) { |
|
929 | - return $content; |
|
930 | - } |
|
931 | - /** @var EE_Registration $primary_registration */ |
|
932 | - $primary_registration = $transaction->primary_registration(); |
|
933 | - $attendee = $primary_registration instanceof EE_Registration |
|
934 | - ? $primary_registration->attendee() |
|
935 | - : null; |
|
936 | - |
|
937 | - if ($attendee instanceof EE_Attendee |
|
938 | - && EE_Registry::instance()->CAP->current_user_can( |
|
939 | - 'ee_send_message', |
|
940 | - 'espresso_transactions_send_payment_reminder' |
|
941 | - ) |
|
942 | - ) { |
|
943 | - $actions['payment_reminder'] = |
|
944 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
945 | - && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code |
|
946 | - && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code |
|
947 | - ? EEH_Template::get_button_or_link( |
|
948 | - EE_Admin_Page::add_query_args_and_nonce( |
|
949 | - array( |
|
950 | - 'action' => 'send_payment_reminder', |
|
951 | - 'TXN_ID' => $this->_transaction->ID(), |
|
952 | - 'redirect_to' => 'view_transaction', |
|
953 | - ), |
|
954 | - TXN_ADMIN_URL |
|
955 | - ), |
|
956 | - esc_html__(' Send Payment Reminder', 'event_espresso'), |
|
957 | - 'button secondary-button', |
|
958 | - 'dashicons dashicons-email-alt' |
|
959 | - ) |
|
960 | - : ''; |
|
961 | - } |
|
962 | - |
|
963 | - if ($primary_registration instanceof EE_Registration |
|
964 | - && EEH_MSG_Template::is_mt_active('receipt') |
|
965 | - ) { |
|
966 | - $actions['receipt'] = EEH_Template::get_button_or_link( |
|
967 | - $primary_registration->receipt_url(), |
|
968 | - esc_html__('View Receipt', 'event_espresso'), |
|
969 | - 'button secondary-button', |
|
970 | - 'dashicons dashicons-media-default' |
|
971 | - ); |
|
972 | - } |
|
973 | - |
|
974 | - if ($primary_registration instanceof EE_Registration |
|
975 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
976 | - ) { |
|
977 | - $actions['invoice'] = EEH_Template::get_button_or_link( |
|
978 | - $primary_registration->invoice_url(), |
|
979 | - esc_html__('View Invoice', 'event_espresso'), |
|
980 | - 'button secondary-button', |
|
981 | - 'dashicons dashicons-media-spreadsheet' |
|
982 | - ); |
|
983 | - } |
|
984 | - $actions = array_filter( |
|
985 | - apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction) |
|
986 | - ); |
|
987 | - if ($actions) { |
|
988 | - $content = '<ul>'; |
|
989 | - $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
990 | - $content .= '</uL>'; |
|
991 | - } |
|
992 | - return $content; |
|
993 | - } |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * txn_details_meta_box |
|
998 | - * generates HTML for the Transaction main meta box |
|
999 | - * |
|
1000 | - * @return void |
|
1001 | - * @throws DomainException |
|
1002 | - * @throws EE_Error |
|
1003 | - * @throws InvalidArgumentException |
|
1004 | - * @throws InvalidDataTypeException |
|
1005 | - * @throws InvalidInterfaceException |
|
1006 | - * @throws RuntimeException |
|
1007 | - * @throws ReflectionException |
|
1008 | - */ |
|
1009 | - public function txn_details_meta_box() |
|
1010 | - { |
|
1011 | - $this->_set_transaction_object(); |
|
1012 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
1013 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
1014 | - ? $this->_transaction->primary_registration()->attendee() |
|
1015 | - : null; |
|
1016 | - $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
1017 | - 'ee_edit_payments', |
|
1018 | - 'apply_payment_or_refund_from_registration_details' |
|
1019 | - ); |
|
1020 | - $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
1021 | - 'ee_delete_payments', |
|
1022 | - 'delete_payment_from_registration_details' |
|
1023 | - ); |
|
1024 | - |
|
1025 | - // get line table |
|
1026 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
1027 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
1028 | - 'admin_table', |
|
1029 | - 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
1030 | - ); |
|
1031 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
1032 | - $this->_transaction->total_line_item() |
|
1033 | - ); |
|
1034 | - $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration') |
|
1035 | - ->get('REG_code'); |
|
1036 | - |
|
1037 | - // process taxes |
|
1038 | - $taxes = $this->_transaction->get_many_related( |
|
1039 | - 'Line_Item', |
|
1040 | - array(array('LIN_type' => EEM_Line_Item::type_tax)) |
|
1041 | - ); |
|
1042 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
1043 | - |
|
1044 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
1045 | - $this->_transaction->get('TXN_total'), |
|
1046 | - false, |
|
1047 | - false |
|
1048 | - ); |
|
1049 | - $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
1050 | - $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
1051 | - |
|
1052 | - // process payment details |
|
1053 | - $payments = $this->_transaction->get_many_related('Payment'); |
|
1054 | - if (! empty($payments)) { |
|
1055 | - $this->_template_args['payments'] = $payments; |
|
1056 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
1057 | - } else { |
|
1058 | - $this->_template_args['payments'] = false; |
|
1059 | - $this->_template_args['existing_reg_payments'] = array(); |
|
1060 | - } |
|
1061 | - |
|
1062 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
1063 | - $this->_template_args['delete_payment_url'] = add_query_arg( |
|
1064 | - array('action' => 'espresso_delete_payment'), |
|
1065 | - TXN_ADMIN_URL |
|
1066 | - ); |
|
1067 | - |
|
1068 | - if (isset($txn_details['invoice_number'])) { |
|
1069 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
1070 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
1071 | - 'Invoice Number', |
|
1072 | - 'event_espresso' |
|
1073 | - ); |
|
1074 | - } |
|
1075 | - |
|
1076 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
1077 | - ->get_first_related('Registration') |
|
1078 | - ->get('REG_session'); |
|
1079 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
1080 | - 'Registration Session', |
|
1081 | - 'event_espresso' |
|
1082 | - ); |
|
1083 | - |
|
1084 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
1085 | - ? $this->_session['ip_address'] |
|
1086 | - : ''; |
|
1087 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
1088 | - 'Transaction placed from IP', |
|
1089 | - 'event_espresso' |
|
1090 | - ); |
|
1091 | - |
|
1092 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
1093 | - ? $this->_session['user_agent'] |
|
1094 | - : ''; |
|
1095 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
1096 | - 'Registrant User Agent', |
|
1097 | - 'event_espresso' |
|
1098 | - ); |
|
1099 | - |
|
1100 | - $reg_steps = '<ul>'; |
|
1101 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
1102 | - if ($reg_step_status === true) { |
|
1103 | - $reg_steps .= '<li style="color:#70cc50">' |
|
1104 | - . sprintf( |
|
1105 | - esc_html__('%1$s : Completed', 'event_espresso'), |
|
1106 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
1107 | - ) |
|
1108 | - . '</li>'; |
|
1109 | - } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
1110 | - $reg_steps .= '<li style="color:#2EA2CC">' |
|
1111 | - . sprintf( |
|
1112 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
1113 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
1114 | - date( |
|
1115 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
1116 | - ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
1117 | - ) |
|
1118 | - ) |
|
1119 | - . '</li>'; |
|
1120 | - } else { |
|
1121 | - $reg_steps .= '<li style="color:#E76700">' |
|
1122 | - . sprintf( |
|
1123 | - esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
1124 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
1125 | - ) |
|
1126 | - . '</li>'; |
|
1127 | - } |
|
1128 | - } |
|
1129 | - $reg_steps .= '</ul>'; |
|
1130 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
1131 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
1132 | - 'Registration Step Progress', |
|
1133 | - 'event_espresso' |
|
1134 | - ); |
|
1135 | - |
|
1136 | - |
|
1137 | - $this->_get_registrations_to_apply_payment_to(); |
|
1138 | - $this->_get_payment_methods($payments); |
|
1139 | - $this->_get_payment_status_array(); |
|
1140 | - $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction. |
|
1141 | - |
|
1142 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
1143 | - array( |
|
1144 | - 'action' => 'edit_transaction', |
|
1145 | - 'process' => 'transaction', |
|
1146 | - ), |
|
1147 | - TXN_ADMIN_URL |
|
1148 | - ); |
|
1149 | - $this->_template_args['apply_payment_form_url'] = add_query_arg( |
|
1150 | - array( |
|
1151 | - 'page' => 'espresso_transactions', |
|
1152 | - 'action' => 'espresso_apply_payment', |
|
1153 | - ), |
|
1154 | - WP_AJAX_URL |
|
1155 | - ); |
|
1156 | - $this->_template_args['delete_payment_form_url'] = add_query_arg( |
|
1157 | - array( |
|
1158 | - 'page' => 'espresso_transactions', |
|
1159 | - 'action' => 'espresso_delete_payment', |
|
1160 | - ), |
|
1161 | - WP_AJAX_URL |
|
1162 | - ); |
|
1163 | - |
|
1164 | - $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction); |
|
1165 | - |
|
1166 | - // 'espresso_delete_payment_nonce' |
|
1167 | - |
|
1168 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
1169 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
1170 | - } |
|
1171 | - |
|
1172 | - |
|
1173 | - /** |
|
1174 | - * _get_registration_payment_IDs |
|
1175 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
1176 | - * |
|
1177 | - * @access protected |
|
1178 | - * @param EE_Payment[] $payments |
|
1179 | - * @return array |
|
1180 | - * @throws EE_Error |
|
1181 | - * @throws InvalidArgumentException |
|
1182 | - * @throws InvalidDataTypeException |
|
1183 | - * @throws InvalidInterfaceException |
|
1184 | - * @throws ReflectionException |
|
1185 | - */ |
|
1186 | - protected function _get_registration_payment_IDs($payments = array()) |
|
1187 | - { |
|
1188 | - $existing_reg_payments = array(); |
|
1189 | - // get all reg payments for these payments |
|
1190 | - $reg_payments = EEM_Registration_Payment::instance()->get_all( |
|
1191 | - array( |
|
1192 | - array( |
|
1193 | - 'PAY_ID' => array( |
|
1194 | - 'IN', |
|
1195 | - array_keys($payments), |
|
1196 | - ), |
|
1197 | - ), |
|
1198 | - ) |
|
1199 | - ); |
|
1200 | - if (! empty($reg_payments)) { |
|
1201 | - foreach ($payments as $payment) { |
|
1202 | - if (! $payment instanceof EE_Payment) { |
|
1203 | - continue; |
|
1204 | - } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
1205 | - $existing_reg_payments[ $payment->ID() ] = array(); |
|
1206 | - } |
|
1207 | - foreach ($reg_payments as $reg_payment) { |
|
1208 | - if ($reg_payment instanceof EE_Registration_Payment |
|
1209 | - && $reg_payment->payment_ID() === $payment->ID() |
|
1210 | - ) { |
|
1211 | - $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
1212 | - } |
|
1213 | - } |
|
1214 | - } |
|
1215 | - } |
|
1216 | - |
|
1217 | - return $existing_reg_payments; |
|
1218 | - } |
|
1219 | - |
|
1220 | - |
|
1221 | - /** |
|
1222 | - * _get_registrations_to_apply_payment_to |
|
1223 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
1224 | - * which allows the admin to only apply the payment to the specific registrations |
|
1225 | - * |
|
1226 | - * @access protected |
|
1227 | - * @return void |
|
1228 | - * @throws \EE_Error |
|
1229 | - */ |
|
1230 | - protected function _get_registrations_to_apply_payment_to() |
|
1231 | - { |
|
1232 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
1233 | - $query_params = array( |
|
1234 | - array( |
|
1235 | - 'STS_ID' => array( |
|
1236 | - 'IN', |
|
1237 | - array( |
|
1238 | - EEM_Registration::status_id_approved, |
|
1239 | - EEM_Registration::status_id_pending_payment, |
|
1240 | - EEM_Registration::status_id_not_approved, |
|
1241 | - ), |
|
1242 | - ), |
|
1243 | - ), |
|
1244 | - ); |
|
1245 | - $registrations_to_apply_payment_to = EEH_HTML::br() |
|
1246 | - . EEH_HTML::div( |
|
1247 | - '', |
|
1248 | - 'txn-admin-apply-payment-to-registrations-dv', |
|
1249 | - '', |
|
1250 | - 'clear: both; margin: 1.5em 0 0; display: none;' |
|
1251 | - ); |
|
1252 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
1253 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
1254 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
1255 | - EEH_HTML::tr( |
|
1256 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
1257 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
1258 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
1259 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
1260 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
1261 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
1262 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
1263 | - ) |
|
1264 | - ); |
|
1265 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
1266 | - // get registrations for TXN |
|
1267 | - $registrations = $this->_transaction->registrations($query_params); |
|
1268 | - $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
1269 | - foreach ($registrations as $registration) { |
|
1270 | - if ($registration instanceof EE_Registration) { |
|
1271 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
1272 | - ? $registration->attendee()->full_name() |
|
1273 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
1274 | - $owing = $registration->final_price() - $registration->paid(); |
|
1275 | - $taxable = $registration->ticket()->taxable() |
|
1276 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
1277 | - : ''; |
|
1278 | - $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
1279 | - ? ' checked="checked"' |
|
1280 | - : ''; |
|
1281 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
1282 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
1283 | - EEH_HTML::td($registration->ID()) . |
|
1284 | - EEH_HTML::td($attendee_name) . |
|
1285 | - EEH_HTML::td( |
|
1286 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
1287 | - ) . |
|
1288 | - EEH_HTML::td($registration->event_name()) . |
|
1289 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
1290 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
1291 | - EEH_HTML::td( |
|
1292 | - '<input type="checkbox" value="' . $registration->ID() |
|
1293 | - . '" name="txn_admin_payment[registrations]"' |
|
1294 | - . $checked . $disabled . '>', |
|
1295 | - '', |
|
1296 | - 'jst-cntr' |
|
1297 | - ), |
|
1298 | - 'apply-payment-registration-row-' . $registration->ID() |
|
1299 | - ); |
|
1300 | - } |
|
1301 | - } |
|
1302 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
1303 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
1304 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1305 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
1306 | - esc_html__( |
|
1307 | - 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
1308 | - 'event_espresso' |
|
1309 | - ), |
|
1310 | - '', |
|
1311 | - 'clear description' |
|
1312 | - ); |
|
1313 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1314 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
1315 | - } |
|
1316 | - |
|
1317 | - |
|
1318 | - /** |
|
1319 | - * _get_reg_status_selection |
|
1320 | - * |
|
1321 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
1322 | - * instead of events. |
|
1323 | - * @access protected |
|
1324 | - * @return void |
|
1325 | - * @throws EE_Error |
|
1326 | - */ |
|
1327 | - protected function _get_reg_status_selection() |
|
1328 | - { |
|
1329 | - // first get all possible statuses |
|
1330 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
1331 | - // let's add a "don't change" option. |
|
1332 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
1333 | - $status_array = array_merge($status_array, $statuses); |
|
1334 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
1335 | - 'txn_reg_status_change[reg_status]', |
|
1336 | - $status_array, |
|
1337 | - 'NAN', |
|
1338 | - 'id="txn-admin-payment-reg-status-inp"', |
|
1339 | - 'txn-reg-status-change-reg-status' |
|
1340 | - ); |
|
1341 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
1342 | - 'delete_txn_reg_status_change[reg_status]', |
|
1343 | - $status_array, |
|
1344 | - 'NAN', |
|
1345 | - 'delete-txn-admin-payment-reg-status-inp', |
|
1346 | - 'delete-txn-reg-status-change-reg-status' |
|
1347 | - ); |
|
1348 | - } |
|
1349 | - |
|
1350 | - |
|
1351 | - /** |
|
1352 | - * _get_payment_methods |
|
1353 | - * Gets all the payment methods available generally, or the ones that are already |
|
1354 | - * selected on these payments (in case their payment methods are no longer active). |
|
1355 | - * Has the side-effect of updating the template args' payment_methods item |
|
1356 | - * |
|
1357 | - * @access private |
|
1358 | - * @param EE_Payment[] to show on this page |
|
1359 | - * @return void |
|
1360 | - * @throws EE_Error |
|
1361 | - * @throws InvalidArgumentException |
|
1362 | - * @throws InvalidDataTypeException |
|
1363 | - * @throws InvalidInterfaceException |
|
1364 | - * @throws ReflectionException |
|
1365 | - */ |
|
1366 | - private function _get_payment_methods($payments = array()) |
|
1367 | - { |
|
1368 | - $payment_methods_of_payments = array(); |
|
1369 | - foreach ($payments as $payment) { |
|
1370 | - if ($payment instanceof EE_Payment) { |
|
1371 | - $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
1372 | - } |
|
1373 | - } |
|
1374 | - if ($payment_methods_of_payments) { |
|
1375 | - $query_args = array( |
|
1376 | - array( |
|
1377 | - 'OR*payment_method_for_payment' => array( |
|
1378 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
1379 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
1380 | - ), |
|
1381 | - ), |
|
1382 | - ); |
|
1383 | - } else { |
|
1384 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
1385 | - } |
|
1386 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
1387 | - } |
|
1388 | - |
|
1389 | - |
|
1390 | - /** |
|
1391 | - * txn_attendees_meta_box |
|
1392 | - * generates HTML for the Attendees Transaction main meta box |
|
1393 | - * |
|
1394 | - * @access public |
|
1395 | - * @param WP_Post $post |
|
1396 | - * @param array $metabox |
|
1397 | - * @return void |
|
1398 | - * @throws DomainException |
|
1399 | - * @throws EE_Error |
|
1400 | - */ |
|
1401 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
1402 | - { |
|
1403 | - |
|
1404 | - /** @noinspection NonSecureExtractUsageInspection */ |
|
1405 | - extract($metabox['args']); |
|
1406 | - $this->_template_args['post'] = $post; |
|
1407 | - $this->_template_args['event_attendees'] = array(); |
|
1408 | - // process items in cart |
|
1409 | - $line_items = $this->_transaction->get_many_related( |
|
1410 | - 'Line_Item', |
|
1411 | - array(array('LIN_type' => 'line-item')) |
|
1412 | - ); |
|
1413 | - if (! empty($line_items)) { |
|
1414 | - foreach ($line_items as $item) { |
|
1415 | - if ($item instanceof EE_Line_Item) { |
|
1416 | - switch ($item->OBJ_type()) { |
|
1417 | - case 'Event': |
|
1418 | - break; |
|
1419 | - case 'Ticket': |
|
1420 | - $ticket = $item->ticket(); |
|
1421 | - // right now we're only handling tickets here. |
|
1422 | - // Cause its expected that only tickets will have attendees right? |
|
1423 | - if (! $ticket instanceof EE_Ticket) { |
|
1424 | - continue; |
|
1425 | - } |
|
1426 | - try { |
|
1427 | - $event_name = $ticket->get_event_name(); |
|
1428 | - } catch (Exception $e) { |
|
1429 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1430 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
1431 | - } |
|
1432 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
1433 | - $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
1434 | - // now get all of the registrations for this transaction that use this ticket |
|
1435 | - $registrations = $ticket->get_many_related( |
|
1436 | - 'Registration', |
|
1437 | - array(array('TXN_ID' => $this->_transaction->ID())) |
|
1438 | - ); |
|
1439 | - foreach ($registrations as $registration) { |
|
1440 | - if (! $registration instanceof EE_Registration) { |
|
1441 | - continue; |
|
1442 | - } |
|
1443 | - $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
1444 | - = $registration->status_ID(); |
|
1445 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
1446 | - = $registration->count(); |
|
1447 | - $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
1448 | - = $event_name; |
|
1449 | - $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
1450 | - = $ticket_price; |
|
1451 | - // attendee info |
|
1452 | - $attendee = $registration->get_first_related('Attendee'); |
|
1453 | - if ($attendee instanceof EE_Attendee) { |
|
1454 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
1455 | - = $attendee->ID(); |
|
1456 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
1457 | - = $attendee->full_name(); |
|
1458 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
1459 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
1460 | - . esc_html__( |
|
1461 | - ' Event', |
|
1462 | - 'event_espresso' |
|
1463 | - ) |
|
1464 | - . '">' . $attendee->email() . '</a>'; |
|
1465 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
1466 | - = EEH_Address::format($attendee, 'inline', false, false); |
|
1467 | - } else { |
|
1468 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
1469 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
1470 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
1471 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
1472 | - } |
|
1473 | - } |
|
1474 | - break; |
|
1475 | - } |
|
1476 | - } |
|
1477 | - } |
|
1478 | - |
|
1479 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
1480 | - array( |
|
1481 | - 'action' => 'edit_transaction', |
|
1482 | - 'process' => 'attendees', |
|
1483 | - ), |
|
1484 | - TXN_ADMIN_URL |
|
1485 | - ); |
|
1486 | - echo EEH_Template::display_template( |
|
1487 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
1488 | - $this->_template_args, |
|
1489 | - true |
|
1490 | - ); |
|
1491 | - } else { |
|
1492 | - echo sprintf( |
|
1493 | - esc_html__( |
|
1494 | - '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
1495 | - 'event_espresso' |
|
1496 | - ), |
|
1497 | - '<p class="important-notice">', |
|
1498 | - '</p>' |
|
1499 | - ); |
|
1500 | - } |
|
1501 | - } |
|
1502 | - |
|
1503 | - |
|
1504 | - /** |
|
1505 | - * txn_registrant_side_meta_box |
|
1506 | - * generates HTML for the Edit Transaction side meta box |
|
1507 | - * |
|
1508 | - * @access public |
|
1509 | - * @return void |
|
1510 | - * @throws DomainException |
|
1511 | - * @throws EE_Error |
|
1512 | - * @throws InvalidArgumentException |
|
1513 | - * @throws InvalidDataTypeException |
|
1514 | - * @throws InvalidInterfaceException |
|
1515 | - * @throws ReflectionException |
|
1516 | - */ |
|
1517 | - public function txn_registrant_side_meta_box() |
|
1518 | - { |
|
1519 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
1520 | - ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
1521 | - : null; |
|
1522 | - if (! $primary_att instanceof EE_Attendee) { |
|
1523 | - $this->_template_args['no_attendee_message'] = esc_html__( |
|
1524 | - 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
1525 | - 'event_espresso' |
|
1526 | - ); |
|
1527 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
1528 | - } |
|
1529 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
1530 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
1531 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
1532 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
1533 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
1534 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
1535 | - array( |
|
1536 | - 'action' => 'edit_attendee', |
|
1537 | - 'post' => $primary_att->ID(), |
|
1538 | - ), |
|
1539 | - REG_ADMIN_URL |
|
1540 | - ); |
|
1541 | - // get formatted address for registrant |
|
1542 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
1543 | - echo EEH_Template::display_template( |
|
1544 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
1545 | - $this->_template_args, |
|
1546 | - true |
|
1547 | - ); |
|
1548 | - } |
|
1549 | - |
|
1550 | - |
|
1551 | - /** |
|
1552 | - * txn_billing_info_side_meta_box |
|
1553 | - * generates HTML for the Edit Transaction side meta box |
|
1554 | - * |
|
1555 | - * @access public |
|
1556 | - * @return void |
|
1557 | - * @throws DomainException |
|
1558 | - * @throws EE_Error |
|
1559 | - */ |
|
1560 | - public function txn_billing_info_side_meta_box() |
|
1561 | - { |
|
1562 | - |
|
1563 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
1564 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
1565 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
1566 | - TXN_ADMIN_URL |
|
1567 | - ); |
|
1568 | - |
|
1569 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
1570 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
1571 | - } |
|
1572 | - |
|
1573 | - |
|
1574 | - /** |
|
1575 | - * apply_payments_or_refunds |
|
1576 | - * registers a payment or refund made towards a transaction |
|
1577 | - * |
|
1578 | - * @access public |
|
1579 | - * @return void |
|
1580 | - * @throws EE_Error |
|
1581 | - * @throws InvalidArgumentException |
|
1582 | - * @throws ReflectionException |
|
1583 | - * @throws RuntimeException |
|
1584 | - * @throws InvalidDataTypeException |
|
1585 | - * @throws InvalidInterfaceException |
|
1586 | - */ |
|
1587 | - public function apply_payments_or_refunds() |
|
1588 | - { |
|
1589 | - $json_response_data = array('return_data' => false); |
|
1590 | - $valid_data = $this->_validate_payment_request_data(); |
|
1591 | - $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
1592 | - 'ee_edit_payments', |
|
1593 | - 'apply_payment_or_refund_from_registration_details' |
|
1594 | - ); |
|
1595 | - if (! empty($valid_data) && $has_access) { |
|
1596 | - $PAY_ID = $valid_data['PAY_ID']; |
|
1597 | - // save the new payment |
|
1598 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
1599 | - // get the TXN for this payment |
|
1600 | - $transaction = $payment->transaction(); |
|
1601 | - // verify transaction |
|
1602 | - if ($transaction instanceof EE_Transaction) { |
|
1603 | - // calculate_total_payments_and_update_status |
|
1604 | - $this->_process_transaction_payments($transaction); |
|
1605 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
1606 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
1607 | - // apply payment to registrations (if applicable) |
|
1608 | - if (! empty($REG_IDs)) { |
|
1609 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
1610 | - $this->_maybe_send_notifications(); |
|
1611 | - // now process status changes for the same registrations |
|
1612 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
1613 | - } |
|
1614 | - $this->_maybe_send_notifications($payment); |
|
1615 | - // prepare to render page |
|
1616 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
1617 | - do_action( |
|
1618 | - 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
1619 | - $transaction, |
|
1620 | - $payment |
|
1621 | - ); |
|
1622 | - } else { |
|
1623 | - EE_Error::add_error( |
|
1624 | - esc_html__( |
|
1625 | - 'A valid Transaction for this payment could not be retrieved.', |
|
1626 | - 'event_espresso' |
|
1627 | - ), |
|
1628 | - __FILE__, |
|
1629 | - __FUNCTION__, |
|
1630 | - __LINE__ |
|
1631 | - ); |
|
1632 | - } |
|
1633 | - } else { |
|
1634 | - if ($has_access) { |
|
1635 | - EE_Error::add_error( |
|
1636 | - esc_html__( |
|
1637 | - 'The payment form data could not be processed. Please try again.', |
|
1638 | - 'event_espresso' |
|
1639 | - ), |
|
1640 | - __FILE__, |
|
1641 | - __FUNCTION__, |
|
1642 | - __LINE__ |
|
1643 | - ); |
|
1644 | - } else { |
|
1645 | - EE_Error::add_error( |
|
1646 | - esc_html__( |
|
1647 | - 'You do not have access to apply payments or refunds to a registration.', |
|
1648 | - 'event_espresso' |
|
1649 | - ), |
|
1650 | - __FILE__, |
|
1651 | - __FUNCTION__, |
|
1652 | - __LINE__ |
|
1653 | - ); |
|
1654 | - } |
|
1655 | - } |
|
1656 | - $notices = EE_Error::get_notices( |
|
1657 | - false, |
|
1658 | - false, |
|
1659 | - false |
|
1660 | - ); |
|
1661 | - $this->_template_args = array( |
|
1662 | - 'data' => $json_response_data, |
|
1663 | - 'error' => $notices['errors'], |
|
1664 | - 'success' => $notices['success'], |
|
1665 | - ); |
|
1666 | - $this->_return_json(); |
|
1667 | - } |
|
1668 | - |
|
1669 | - |
|
1670 | - /** |
|
1671 | - * _validate_payment_request_data |
|
1672 | - * |
|
1673 | - * @return array |
|
1674 | - * @throws EE_Error |
|
1675 | - */ |
|
1676 | - protected function _validate_payment_request_data() |
|
1677 | - { |
|
1678 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
1679 | - return false; |
|
1680 | - } |
|
1681 | - $payment_form = $this->_generate_payment_form_section(); |
|
1682 | - try { |
|
1683 | - if ($payment_form->was_submitted()) { |
|
1684 | - $payment_form->receive_form_submission(); |
|
1685 | - if (! $payment_form->is_valid()) { |
|
1686 | - $submission_error_messages = array(); |
|
1687 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
1688 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1689 | - $submission_error_messages[] = sprintf( |
|
1690 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
1691 | - $validation_error->get_form_section()->html_label_text(), |
|
1692 | - $validation_error->getMessage() |
|
1693 | - ); |
|
1694 | - } |
|
1695 | - } |
|
1696 | - EE_Error::add_error( |
|
1697 | - implode('<br />', $submission_error_messages), |
|
1698 | - __FILE__, |
|
1699 | - __FUNCTION__, |
|
1700 | - __LINE__ |
|
1701 | - ); |
|
1702 | - |
|
1703 | - return array(); |
|
1704 | - } |
|
1705 | - } |
|
1706 | - } catch (EE_Error $e) { |
|
1707 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1708 | - |
|
1709 | - return array(); |
|
1710 | - } |
|
1711 | - |
|
1712 | - return $payment_form->valid_data(); |
|
1713 | - } |
|
1714 | - |
|
1715 | - |
|
1716 | - /** |
|
1717 | - * _generate_payment_form_section |
|
1718 | - * |
|
1719 | - * @return EE_Form_Section_Proper |
|
1720 | - * @throws EE_Error |
|
1721 | - */ |
|
1722 | - protected function _generate_payment_form_section() |
|
1723 | - { |
|
1724 | - return new EE_Form_Section_Proper( |
|
1725 | - array( |
|
1726 | - 'name' => 'txn_admin_payment', |
|
1727 | - 'subsections' => array( |
|
1728 | - 'PAY_ID' => new EE_Text_Input( |
|
1729 | - array( |
|
1730 | - 'default' => 0, |
|
1731 | - 'required' => false, |
|
1732 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
1733 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1734 | - ) |
|
1735 | - ), |
|
1736 | - 'TXN_ID' => new EE_Text_Input( |
|
1737 | - array( |
|
1738 | - 'default' => 0, |
|
1739 | - 'required' => true, |
|
1740 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
1741 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1742 | - ) |
|
1743 | - ), |
|
1744 | - 'type' => new EE_Text_Input( |
|
1745 | - array( |
|
1746 | - 'default' => 1, |
|
1747 | - 'required' => true, |
|
1748 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
1749 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1750 | - ) |
|
1751 | - ), |
|
1752 | - 'amount' => new EE_Text_Input( |
|
1753 | - array( |
|
1754 | - 'default' => 0, |
|
1755 | - 'required' => true, |
|
1756 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
1757 | - 'validation_strategies' => array(new EE_Float_Normalization()), |
|
1758 | - ) |
|
1759 | - ), |
|
1760 | - 'status' => new EE_Text_Input( |
|
1761 | - array( |
|
1762 | - 'default' => EEM_Payment::status_id_approved, |
|
1763 | - 'required' => true, |
|
1764 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
1765 | - ) |
|
1766 | - ), |
|
1767 | - 'PMD_ID' => new EE_Text_Input( |
|
1768 | - array( |
|
1769 | - 'default' => 2, |
|
1770 | - 'required' => true, |
|
1771 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
1772 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1773 | - ) |
|
1774 | - ), |
|
1775 | - 'date' => new EE_Text_Input( |
|
1776 | - array( |
|
1777 | - 'default' => time(), |
|
1778 | - 'required' => true, |
|
1779 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
1780 | - ) |
|
1781 | - ), |
|
1782 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
1783 | - array( |
|
1784 | - 'default' => '', |
|
1785 | - 'required' => false, |
|
1786 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
1787 | - 'validation_strategies' => array( |
|
1788 | - new EE_Max_Length_Validation_Strategy( |
|
1789 | - esc_html__('Input too long', 'event_espresso'), |
|
1790 | - 100 |
|
1791 | - ), |
|
1792 | - ), |
|
1793 | - ) |
|
1794 | - ), |
|
1795 | - 'po_number' => new EE_Text_Input( |
|
1796 | - array( |
|
1797 | - 'default' => '', |
|
1798 | - 'required' => false, |
|
1799 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
1800 | - 'validation_strategies' => array( |
|
1801 | - new EE_Max_Length_Validation_Strategy( |
|
1802 | - esc_html__('Input too long', 'event_espresso'), |
|
1803 | - 100 |
|
1804 | - ), |
|
1805 | - ), |
|
1806 | - ) |
|
1807 | - ), |
|
1808 | - 'accounting' => new EE_Text_Input( |
|
1809 | - array( |
|
1810 | - 'default' => '', |
|
1811 | - 'required' => false, |
|
1812 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
1813 | - 'validation_strategies' => array( |
|
1814 | - new EE_Max_Length_Validation_Strategy( |
|
1815 | - esc_html__('Input too long', 'event_espresso'), |
|
1816 | - 100 |
|
1817 | - ), |
|
1818 | - ), |
|
1819 | - ) |
|
1820 | - ), |
|
1821 | - ), |
|
1822 | - ) |
|
1823 | - ); |
|
1824 | - } |
|
1825 | - |
|
1826 | - |
|
1827 | - /** |
|
1828 | - * _create_payment_from_request_data |
|
1829 | - * |
|
1830 | - * @param array $valid_data |
|
1831 | - * @return EE_Payment |
|
1832 | - * @throws EE_Error |
|
1833 | - */ |
|
1834 | - protected function _create_payment_from_request_data($valid_data) |
|
1835 | - { |
|
1836 | - $PAY_ID = $valid_data['PAY_ID']; |
|
1837 | - // get payment amount |
|
1838 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
1839 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
1840 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
1841 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
1842 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
1843 | - $date = $valid_data['date'] |
|
1844 | - ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
1845 | - : date('Y-m-d g:i a', current_time('timestamp')); |
|
1846 | - $payment = EE_Payment::new_instance( |
|
1847 | - array( |
|
1848 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
1849 | - 'STS_ID' => $valid_data['status'], |
|
1850 | - 'PAY_timestamp' => $date, |
|
1851 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
1852 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
1853 | - 'PAY_amount' => $amount, |
|
1854 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
1855 | - 'PAY_po_number' => $valid_data['po_number'], |
|
1856 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
1857 | - 'PAY_details' => $valid_data, |
|
1858 | - 'PAY_ID' => $PAY_ID, |
|
1859 | - ), |
|
1860 | - '', |
|
1861 | - array('Y-m-d', 'g:i a') |
|
1862 | - ); |
|
1863 | - |
|
1864 | - if (! $payment->save()) { |
|
1865 | - EE_Error::add_error( |
|
1866 | - sprintf( |
|
1867 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
1868 | - $payment->ID() |
|
1869 | - ), |
|
1870 | - __FILE__, |
|
1871 | - __FUNCTION__, |
|
1872 | - __LINE__ |
|
1873 | - ); |
|
1874 | - } |
|
1875 | - |
|
1876 | - return $payment; |
|
1877 | - } |
|
1878 | - |
|
1879 | - |
|
1880 | - /** |
|
1881 | - * _process_transaction_payments |
|
1882 | - * |
|
1883 | - * @param \EE_Transaction $transaction |
|
1884 | - * @return void |
|
1885 | - * @throws EE_Error |
|
1886 | - * @throws InvalidArgumentException |
|
1887 | - * @throws ReflectionException |
|
1888 | - * @throws InvalidDataTypeException |
|
1889 | - * @throws InvalidInterfaceException |
|
1890 | - */ |
|
1891 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
1892 | - { |
|
1893 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
1894 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1895 | - // update the transaction with this payment |
|
1896 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
1897 | - EE_Error::add_success( |
|
1898 | - esc_html__( |
|
1899 | - 'The payment has been processed successfully.', |
|
1900 | - 'event_espresso' |
|
1901 | - ), |
|
1902 | - __FILE__, |
|
1903 | - __FUNCTION__, |
|
1904 | - __LINE__ |
|
1905 | - ); |
|
1906 | - } else { |
|
1907 | - EE_Error::add_error( |
|
1908 | - esc_html__( |
|
1909 | - 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
1910 | - 'event_espresso' |
|
1911 | - ), |
|
1912 | - __FILE__, |
|
1913 | - __FUNCTION__, |
|
1914 | - __LINE__ |
|
1915 | - ); |
|
1916 | - } |
|
1917 | - } |
|
1918 | - |
|
1919 | - |
|
1920 | - /** |
|
1921 | - * _get_REG_IDs_to_apply_payment_to |
|
1922 | - * returns a list of registration IDs that the payment will apply to |
|
1923 | - * |
|
1924 | - * @param \EE_Payment $payment |
|
1925 | - * @return array |
|
1926 | - * @throws EE_Error |
|
1927 | - */ |
|
1928 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
1929 | - { |
|
1930 | - $REG_IDs = array(); |
|
1931 | - // grab array of IDs for specific registrations to apply changes to |
|
1932 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
1933 | - $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
1934 | - } |
|
1935 | - // nothing specified ? then get all reg IDs |
|
1936 | - if (empty($REG_IDs)) { |
|
1937 | - $registrations = $payment->transaction()->registrations(); |
|
1938 | - $REG_IDs = ! empty($registrations) |
|
1939 | - ? array_keys($registrations) |
|
1940 | - : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1941 | - } |
|
1942 | - |
|
1943 | - // ensure that REG_IDs are integers and NOT strings |
|
1944 | - return array_map('intval', $REG_IDs); |
|
1945 | - } |
|
1946 | - |
|
1947 | - |
|
1948 | - /** |
|
1949 | - * @return array |
|
1950 | - */ |
|
1951 | - public function existing_reg_payment_REG_IDs() |
|
1952 | - { |
|
1953 | - return $this->_existing_reg_payment_REG_IDs; |
|
1954 | - } |
|
1955 | - |
|
1956 | - |
|
1957 | - /** |
|
1958 | - * @param array $existing_reg_payment_REG_IDs |
|
1959 | - */ |
|
1960 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
1961 | - { |
|
1962 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
1963 | - } |
|
1964 | - |
|
1965 | - |
|
1966 | - /** |
|
1967 | - * _get_existing_reg_payment_REG_IDs |
|
1968 | - * returns a list of registration IDs that the payment is currently related to |
|
1969 | - * as recorded in the database |
|
1970 | - * |
|
1971 | - * @param \EE_Payment $payment |
|
1972 | - * @return array |
|
1973 | - * @throws EE_Error |
|
1974 | - */ |
|
1975 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
1976 | - { |
|
1977 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
1978 | - // let's get any existing reg payment records for this payment |
|
1979 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
1980 | - // but we only want the REG IDs, so grab the array keys |
|
1981 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
1982 | - ? array_keys($existing_reg_payment_REG_IDs) |
|
1983 | - : array(); |
|
1984 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
1985 | - } |
|
1986 | - |
|
1987 | - return $this->existing_reg_payment_REG_IDs(); |
|
1988 | - } |
|
1989 | - |
|
1990 | - |
|
1991 | - /** |
|
1992 | - * _remove_existing_registration_payments |
|
1993 | - * this calculates the difference between existing relations |
|
1994 | - * to the supplied payment and the new list registration IDs, |
|
1995 | - * removes any related registrations that no longer apply, |
|
1996 | - * and then updates the registration paid fields |
|
1997 | - * |
|
1998 | - * @param \EE_Payment $payment |
|
1999 | - * @param int $PAY_ID |
|
2000 | - * @return bool; |
|
2001 | - * @throws EE_Error |
|
2002 | - * @throws InvalidArgumentException |
|
2003 | - * @throws ReflectionException |
|
2004 | - * @throws InvalidDataTypeException |
|
2005 | - * @throws InvalidInterfaceException |
|
2006 | - */ |
|
2007 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
2008 | - { |
|
2009 | - // newly created payments will have nothing recorded for $PAY_ID |
|
2010 | - if ($PAY_ID == 0) { |
|
2011 | - return false; |
|
2012 | - } |
|
2013 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
2014 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
2015 | - return false; |
|
2016 | - } |
|
2017 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
2018 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
2019 | - |
|
2020 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
2021 | - $payment, |
|
2022 | - array( |
|
2023 | - array( |
|
2024 | - 'PAY_ID' => $payment->ID(), |
|
2025 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
2026 | - ), |
|
2027 | - ) |
|
2028 | - ); |
|
2029 | - } |
|
2030 | - |
|
2031 | - |
|
2032 | - /** |
|
2033 | - * _update_registration_payments |
|
2034 | - * this applies the payments to the selected registrations |
|
2035 | - * but only if they have not already been paid for |
|
2036 | - * |
|
2037 | - * @param EE_Transaction $transaction |
|
2038 | - * @param \EE_Payment $payment |
|
2039 | - * @param array $REG_IDs |
|
2040 | - * @return void |
|
2041 | - * @throws EE_Error |
|
2042 | - * @throws InvalidArgumentException |
|
2043 | - * @throws ReflectionException |
|
2044 | - * @throws RuntimeException |
|
2045 | - * @throws InvalidDataTypeException |
|
2046 | - * @throws InvalidInterfaceException |
|
2047 | - */ |
|
2048 | - protected function _update_registration_payments( |
|
2049 | - EE_Transaction $transaction, |
|
2050 | - EE_Payment $payment, |
|
2051 | - $REG_IDs = array() |
|
2052 | - ) { |
|
2053 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
2054 | - // so let's do that using our set of REG_IDs from the form |
|
2055 | - $registration_query_where_params = array( |
|
2056 | - 'REG_ID' => array('IN', $REG_IDs), |
|
2057 | - ); |
|
2058 | - // but add in some conditions regarding payment, |
|
2059 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
2060 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
2061 | - if (! $payment->is_a_refund()) { |
|
2062 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
2063 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
2064 | - } |
|
2065 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
2066 | - if (! empty($registrations)) { |
|
2067 | - /** @type EE_Payment_Processor $payment_processor */ |
|
2068 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2069 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
2070 | - } |
|
2071 | - } |
|
2072 | - |
|
2073 | - |
|
2074 | - /** |
|
2075 | - * _process_registration_status_change |
|
2076 | - * This processes requested registration status changes for all the registrations |
|
2077 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
2078 | - * |
|
2079 | - * @param EE_Transaction $transaction |
|
2080 | - * @param array $REG_IDs |
|
2081 | - * @return bool |
|
2082 | - * @throws EE_Error |
|
2083 | - * @throws InvalidArgumentException |
|
2084 | - * @throws ReflectionException |
|
2085 | - * @throws InvalidDataTypeException |
|
2086 | - * @throws InvalidInterfaceException |
|
2087 | - */ |
|
2088 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
2089 | - { |
|
2090 | - // first if there is no change in status then we get out. |
|
2091 | - if (! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
2092 | - || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
2093 | - ) { |
|
2094 | - // no error message, no change requested, just nothing to do man. |
|
2095 | - return false; |
|
2096 | - } |
|
2097 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
2098 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
2099 | - |
|
2100 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
2101 | - return $transaction_processor->manually_update_registration_statuses( |
|
2102 | - $transaction, |
|
2103 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
2104 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
2105 | - ); |
|
2106 | - } |
|
2107 | - |
|
2108 | - |
|
2109 | - /** |
|
2110 | - * _build_payment_json_response |
|
2111 | - * |
|
2112 | - * @access public |
|
2113 | - * @param \EE_Payment $payment |
|
2114 | - * @param array $REG_IDs |
|
2115 | - * @param bool | null $delete_txn_reg_status_change |
|
2116 | - * @return array |
|
2117 | - * @throws EE_Error |
|
2118 | - * @throws InvalidArgumentException |
|
2119 | - * @throws InvalidDataTypeException |
|
2120 | - * @throws InvalidInterfaceException |
|
2121 | - * @throws ReflectionException |
|
2122 | - */ |
|
2123 | - protected function _build_payment_json_response( |
|
2124 | - EE_Payment $payment, |
|
2125 | - $REG_IDs = array(), |
|
2126 | - $delete_txn_reg_status_change = null |
|
2127 | - ) { |
|
2128 | - // was the payment deleted ? |
|
2129 | - if (is_bool($delete_txn_reg_status_change)) { |
|
2130 | - return array( |
|
2131 | - 'PAY_ID' => $payment->ID(), |
|
2132 | - 'amount' => $payment->amount(), |
|
2133 | - 'total_paid' => $payment->transaction()->paid(), |
|
2134 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
2135 | - 'pay_status' => $payment->STS_ID(), |
|
2136 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
2137 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
2138 | - ); |
|
2139 | - } else { |
|
2140 | - $this->_get_payment_status_array(); |
|
2141 | - |
|
2142 | - return array( |
|
2143 | - 'amount' => $payment->amount(), |
|
2144 | - 'total_paid' => $payment->transaction()->paid(), |
|
2145 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
2146 | - 'pay_status' => $payment->STS_ID(), |
|
2147 | - 'PAY_ID' => $payment->ID(), |
|
2148 | - 'STS_ID' => $payment->STS_ID(), |
|
2149 | - 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
2150 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
2151 | - 'method' => strtoupper($payment->source()), |
|
2152 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
2153 | - 'gateway' => $payment->payment_method() |
|
2154 | - ? $payment->payment_method()->admin_name() |
|
2155 | - : esc_html__("Unknown", 'event_espresso'), |
|
2156 | - 'gateway_response' => $payment->gateway_response(), |
|
2157 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
2158 | - 'po_number' => $payment->po_number(), |
|
2159 | - 'extra_accntng' => $payment->extra_accntng(), |
|
2160 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
2161 | - ); |
|
2162 | - } |
|
2163 | - } |
|
2164 | - |
|
2165 | - |
|
2166 | - /** |
|
2167 | - * delete_payment |
|
2168 | - * delete a payment or refund made towards a transaction |
|
2169 | - * |
|
2170 | - * @access public |
|
2171 | - * @return void |
|
2172 | - * @throws EE_Error |
|
2173 | - * @throws InvalidArgumentException |
|
2174 | - * @throws ReflectionException |
|
2175 | - * @throws InvalidDataTypeException |
|
2176 | - * @throws InvalidInterfaceException |
|
2177 | - */ |
|
2178 | - public function delete_payment() |
|
2179 | - { |
|
2180 | - $json_response_data = array('return_data' => false); |
|
2181 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
2182 | - ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
2183 | - : 0; |
|
2184 | - $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
2185 | - 'ee_delete_payments', |
|
2186 | - 'delete_payment_from_registration_details' |
|
2187 | - ); |
|
2188 | - if ($PAY_ID && $can_delete) { |
|
2189 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
2190 | - ? $this->_req_data['delete_txn_reg_status_change'] |
|
2191 | - : false; |
|
2192 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
2193 | - if ($payment instanceof EE_Payment) { |
|
2194 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
2195 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
2196 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
2197 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
2198 | - $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
2199 | - $payment, |
|
2200 | - $REG_IDs, |
|
2201 | - $delete_txn_reg_status_change |
|
2202 | - ); |
|
2203 | - if ($delete_txn_reg_status_change) { |
|
2204 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
2205 | - // MAKE sure we also add the delete_txn_req_status_change to the |
|
2206 | - // $_REQUEST global because that's how messages will be looking for it. |
|
2207 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
2208 | - $this->_maybe_send_notifications(); |
|
2209 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
2210 | - } |
|
2211 | - } |
|
2212 | - } else { |
|
2213 | - EE_Error::add_error( |
|
2214 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
2215 | - __FILE__, |
|
2216 | - __FUNCTION__, |
|
2217 | - __LINE__ |
|
2218 | - ); |
|
2219 | - } |
|
2220 | - } else { |
|
2221 | - if ($can_delete) { |
|
2222 | - EE_Error::add_error( |
|
2223 | - esc_html__( |
|
2224 | - 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
2225 | - 'event_espresso' |
|
2226 | - ), |
|
2227 | - __FILE__, |
|
2228 | - __FUNCTION__, |
|
2229 | - __LINE__ |
|
2230 | - ); |
|
2231 | - } else { |
|
2232 | - EE_Error::add_error( |
|
2233 | - esc_html__( |
|
2234 | - 'You do not have access to delete a payment.', |
|
2235 | - 'event_espresso' |
|
2236 | - ), |
|
2237 | - __FILE__, |
|
2238 | - __FUNCTION__, |
|
2239 | - __LINE__ |
|
2240 | - ); |
|
2241 | - } |
|
2242 | - } |
|
2243 | - $notices = EE_Error::get_notices(false, false, false); |
|
2244 | - $this->_template_args = array( |
|
2245 | - 'data' => $json_response_data, |
|
2246 | - 'success' => $notices['success'], |
|
2247 | - 'error' => $notices['errors'], |
|
2248 | - 'attention' => $notices['attention'], |
|
2249 | - ); |
|
2250 | - $this->_return_json(); |
|
2251 | - } |
|
2252 | - |
|
2253 | - |
|
2254 | - /** |
|
2255 | - * _registration_payment_data_array |
|
2256 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
2257 | - * |
|
2258 | - * @access protected |
|
2259 | - * @param array $REG_IDs |
|
2260 | - * @return array |
|
2261 | - * @throws EE_Error |
|
2262 | - * @throws InvalidArgumentException |
|
2263 | - * @throws InvalidDataTypeException |
|
2264 | - * @throws InvalidInterfaceException |
|
2265 | - * @throws ReflectionException |
|
2266 | - */ |
|
2267 | - protected function _registration_payment_data_array($REG_IDs) |
|
2268 | - { |
|
2269 | - $registration_payment_data = array(); |
|
2270 | - // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
2271 | - if (! empty($REG_IDs)) { |
|
2272 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
2273 | - foreach ($registrations as $registration) { |
|
2274 | - if ($registration instanceof EE_Registration) { |
|
2275 | - $registration_payment_data[ $registration->ID() ] = array( |
|
2276 | - 'paid' => $registration->pretty_paid(), |
|
2277 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
2278 | - ); |
|
2279 | - } |
|
2280 | - } |
|
2281 | - } |
|
2282 | - |
|
2283 | - return $registration_payment_data; |
|
2284 | - } |
|
2285 | - |
|
2286 | - |
|
2287 | - /** |
|
2288 | - * _maybe_send_notifications |
|
2289 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
2290 | - * If so, will toggle a filter switch for delivering registration notices. |
|
2291 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
2292 | - * |
|
2293 | - * @access protected |
|
2294 | - * @param \EE_Payment | null $payment |
|
2295 | - */ |
|
2296 | - protected function _maybe_send_notifications($payment = null) |
|
2297 | - { |
|
2298 | - switch ($payment instanceof EE_Payment) { |
|
2299 | - // payment notifications |
|
2300 | - case true: |
|
2301 | - if (isset( |
|
2302 | - $this->_req_data['txn_payments'], |
|
2303 | - $this->_req_data['txn_payments']['send_notifications'] |
|
2304 | - ) |
|
2305 | - && filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
2306 | - ) { |
|
2307 | - $this->_process_payment_notification($payment); |
|
2308 | - } |
|
2309 | - break; |
|
2310 | - // registration notifications |
|
2311 | - case false: |
|
2312 | - if (isset( |
|
2313 | - $this->_req_data['txn_reg_status_change'], |
|
2314 | - $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
2315 | - ) |
|
2316 | - && filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
2317 | - ) { |
|
2318 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
2319 | - } |
|
2320 | - break; |
|
2321 | - } |
|
2322 | - } |
|
2323 | - |
|
2324 | - |
|
2325 | - /** |
|
2326 | - * _send_payment_reminder |
|
2327 | - * generates HTML for the View Transaction Details Admin page |
|
2328 | - * |
|
2329 | - * @access protected |
|
2330 | - * @return void |
|
2331 | - * @throws EE_Error |
|
2332 | - * @throws InvalidArgumentException |
|
2333 | - * @throws InvalidDataTypeException |
|
2334 | - * @throws InvalidInterfaceException |
|
2335 | - */ |
|
2336 | - protected function _send_payment_reminder() |
|
2337 | - { |
|
2338 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
2339 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2340 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
2341 | - 'action' => $this->_req_data['redirect_to'], |
|
2342 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
2343 | - ) : array(); |
|
2344 | - do_action( |
|
2345 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
2346 | - $transaction |
|
2347 | - ); |
|
2348 | - $this->_redirect_after_action( |
|
2349 | - false, |
|
2350 | - esc_html__('payment reminder', 'event_espresso'), |
|
2351 | - esc_html__('sent', 'event_espresso'), |
|
2352 | - $query_args, |
|
2353 | - true |
|
2354 | - ); |
|
2355 | - } |
|
2356 | - |
|
2357 | - |
|
2358 | - /** |
|
2359 | - * get_transactions |
|
2360 | - * get transactions for given parameters (used by list table) |
|
2361 | - * |
|
2362 | - * @param int $perpage how many transactions displayed per page |
|
2363 | - * @param boolean $count return the count or objects |
|
2364 | - * @param string $view |
|
2365 | - * @return mixed int = count || array of transaction objects |
|
2366 | - * @throws EE_Error |
|
2367 | - * @throws InvalidArgumentException |
|
2368 | - * @throws InvalidDataTypeException |
|
2369 | - * @throws InvalidInterfaceException |
|
2370 | - */ |
|
2371 | - public function get_transactions($perpage, $count = false, $view = '') |
|
2372 | - { |
|
2373 | - |
|
2374 | - $TXN = EEM_Transaction::instance(); |
|
2375 | - |
|
2376 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
2377 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
2378 | - : date( |
|
2379 | - 'm/d/Y', |
|
2380 | - strtotime('-10 year') |
|
2381 | - ); |
|
2382 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
2383 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
2384 | - : date('m/d/Y'); |
|
2385 | - |
|
2386 | - // make sure our timestamps start and end right at the boundaries for each day |
|
2387 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
2388 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
2389 | - |
|
2390 | - |
|
2391 | - // convert to timestamps |
|
2392 | - $start_date = strtotime($start_date); |
|
2393 | - $end_date = strtotime($end_date); |
|
2394 | - |
|
2395 | - // makes sure start date is the lowest value and vice versa |
|
2396 | - $start_date = min($start_date, $end_date); |
|
2397 | - $end_date = max($start_date, $end_date); |
|
2398 | - |
|
2399 | - // convert to correct format for query |
|
2400 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
2401 | - 'TXN_timestamp', |
|
2402 | - date('Y-m-d H:i:s', $start_date), |
|
2403 | - 'Y-m-d H:i:s' |
|
2404 | - ); |
|
2405 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
2406 | - 'TXN_timestamp', |
|
2407 | - date('Y-m-d H:i:s', $end_date), |
|
2408 | - 'Y-m-d H:i:s' |
|
2409 | - ); |
|
2410 | - |
|
2411 | - |
|
2412 | - // set orderby |
|
2413 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
2414 | - |
|
2415 | - switch ($this->_req_data['orderby']) { |
|
2416 | - case 'TXN_ID': |
|
2417 | - $orderby = 'TXN_ID'; |
|
2418 | - break; |
|
2419 | - case 'ATT_fname': |
|
2420 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
2421 | - break; |
|
2422 | - case 'event_name': |
|
2423 | - $orderby = 'Registration.Event.EVT_name'; |
|
2424 | - break; |
|
2425 | - default: // 'TXN_timestamp' |
|
2426 | - $orderby = 'TXN_timestamp'; |
|
2427 | - } |
|
2428 | - |
|
2429 | - $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2430 | - $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
2431 | - $per_page = ! empty($perpage) ? $perpage : 10; |
|
2432 | - $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
2433 | - |
|
2434 | - $offset = ($current_page - 1) * $per_page; |
|
2435 | - $limit = array($offset, $per_page); |
|
2436 | - |
|
2437 | - $_where = array( |
|
2438 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
2439 | - 'Registration.REG_count' => 1, |
|
2440 | - ); |
|
2441 | - |
|
2442 | - if (isset($this->_req_data['EVT_ID'])) { |
|
2443 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
2444 | - } |
|
2445 | - |
|
2446 | - if (isset($this->_req_data['s'])) { |
|
2447 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
2448 | - $_where['OR'] = array( |
|
2449 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
2450 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
2451 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
2452 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
2453 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
2454 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
2455 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
2456 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
2457 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
2458 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
2459 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
2460 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
2461 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
2462 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
2463 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
2464 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
2465 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
2466 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
2467 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
2468 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
2469 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
2470 | - ); |
|
2471 | - } |
|
2472 | - |
|
2473 | - // failed transactions |
|
2474 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
2475 | - || ($count && $view === 'failed'); |
|
2476 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
2477 | - || ($count && $view === 'abandoned'); |
|
2478 | - |
|
2479 | - if ($failed) { |
|
2480 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
2481 | - } elseif ($abandoned) { |
|
2482 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
2483 | - } else { |
|
2484 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
2485 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
2486 | - } |
|
2487 | - |
|
2488 | - $query_params = array( |
|
2489 | - $_where, |
|
2490 | - 'order_by' => array($orderby => $sort), |
|
2491 | - 'limit' => $limit, |
|
2492 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
2493 | - ); |
|
2494 | - |
|
2495 | - $transactions = $count |
|
2496 | - ? $TXN->count(array($_where), 'TXN_ID', true) |
|
2497 | - : $TXN->get_all($query_params); |
|
2498 | - |
|
2499 | - return $transactions; |
|
2500 | - } |
|
17 | + /** |
|
18 | + * @var EE_Transaction |
|
19 | + */ |
|
20 | + private $_transaction; |
|
21 | + |
|
22 | + /** |
|
23 | + * @var EE_Session |
|
24 | + */ |
|
25 | + private $_session; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var array $_txn_status |
|
29 | + */ |
|
30 | + private static $_txn_status; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var array $_pay_status |
|
34 | + */ |
|
35 | + private static $_pay_status; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var array $_existing_reg_payment_REG_IDs |
|
39 | + */ |
|
40 | + protected $_existing_reg_payment_REG_IDs = null; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @Constructor |
|
45 | + * @access public |
|
46 | + * @param bool $routing |
|
47 | + * @throws EE_Error |
|
48 | + * @throws InvalidArgumentException |
|
49 | + * @throws ReflectionException |
|
50 | + * @throws InvalidDataTypeException |
|
51 | + * @throws InvalidInterfaceException |
|
52 | + */ |
|
53 | + public function __construct($routing = true) |
|
54 | + { |
|
55 | + parent::__construct($routing); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * _init_page_props |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + protected function _init_page_props() |
|
65 | + { |
|
66 | + $this->page_slug = TXN_PG_SLUG; |
|
67 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
68 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
69 | + $this->_admin_base_path = TXN_ADMIN; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * _ajax_hooks |
|
75 | + * |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + protected function _ajax_hooks() |
|
79 | + { |
|
80 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
81 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
82 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * _define_page_props |
|
88 | + * |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + protected function _define_page_props() |
|
92 | + { |
|
93 | + $this->_admin_page_title = $this->page_label; |
|
94 | + $this->_labels = array( |
|
95 | + 'buttons' => array( |
|
96 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
97 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
98 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
99 | + ), |
|
100 | + ); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * grab url requests and route them |
|
106 | + * |
|
107 | + * @access private |
|
108 | + * @return void |
|
109 | + * @throws EE_Error |
|
110 | + * @throws InvalidArgumentException |
|
111 | + * @throws InvalidDataTypeException |
|
112 | + * @throws InvalidInterfaceException |
|
113 | + */ |
|
114 | + public function _set_page_routes() |
|
115 | + { |
|
116 | + |
|
117 | + $this->_set_transaction_status_array(); |
|
118 | + |
|
119 | + $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
120 | + && ! is_array($this->_req_data['TXN_ID']) |
|
121 | + ? $this->_req_data['TXN_ID'] |
|
122 | + : 0; |
|
123 | + |
|
124 | + $this->_page_routes = array( |
|
125 | + |
|
126 | + 'default' => array( |
|
127 | + 'func' => '_transactions_overview_list_table', |
|
128 | + 'capability' => 'ee_read_transactions', |
|
129 | + ), |
|
130 | + |
|
131 | + 'view_transaction' => array( |
|
132 | + 'func' => '_transaction_details', |
|
133 | + 'capability' => 'ee_read_transaction', |
|
134 | + 'obj_id' => $txn_id, |
|
135 | + ), |
|
136 | + |
|
137 | + 'send_payment_reminder' => array( |
|
138 | + 'func' => '_send_payment_reminder', |
|
139 | + 'noheader' => true, |
|
140 | + 'capability' => 'ee_send_message', |
|
141 | + ), |
|
142 | + |
|
143 | + 'espresso_apply_payment' => array( |
|
144 | + 'func' => 'apply_payments_or_refunds', |
|
145 | + 'noheader' => true, |
|
146 | + 'capability' => 'ee_edit_payments', |
|
147 | + ), |
|
148 | + |
|
149 | + 'espresso_apply_refund' => array( |
|
150 | + 'func' => 'apply_payments_or_refunds', |
|
151 | + 'noheader' => true, |
|
152 | + 'capability' => 'ee_edit_payments', |
|
153 | + ), |
|
154 | + |
|
155 | + 'espresso_delete_payment' => array( |
|
156 | + 'func' => 'delete_payment', |
|
157 | + 'noheader' => true, |
|
158 | + 'capability' => 'ee_delete_payments', |
|
159 | + ), |
|
160 | + |
|
161 | + ); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + protected function _set_page_config() |
|
166 | + { |
|
167 | + $this->_page_config = array( |
|
168 | + 'default' => array( |
|
169 | + 'nav' => array( |
|
170 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
171 | + 'order' => 10, |
|
172 | + ), |
|
173 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
174 | + 'help_tabs' => array( |
|
175 | + 'transactions_overview_help_tab' => array( |
|
176 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
177 | + 'filename' => 'transactions_overview', |
|
178 | + ), |
|
179 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
180 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
181 | + 'filename' => 'transactions_overview_table_column_headings', |
|
182 | + ), |
|
183 | + 'transactions_overview_views_filters_help_tab' => array( |
|
184 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
185 | + 'filename' => 'transactions_overview_views_filters_search', |
|
186 | + ), |
|
187 | + ), |
|
188 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
189 | + /** |
|
190 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
191 | + * may change in a later iteration so want to keep the code for then. |
|
192 | + */ |
|
193 | + // 'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
194 | + 'require_nonce' => false, |
|
195 | + ), |
|
196 | + 'view_transaction' => array( |
|
197 | + 'nav' => array( |
|
198 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
199 | + 'order' => 5, |
|
200 | + 'url' => isset($this->_req_data['TXN_ID']) |
|
201 | + ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
202 | + : $this->_admin_base_url, |
|
203 | + 'persistent' => false, |
|
204 | + ), |
|
205 | + 'help_tabs' => array( |
|
206 | + 'transactions_view_transaction_help_tab' => array( |
|
207 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
208 | + 'filename' => 'transactions_view_transaction', |
|
209 | + ), |
|
210 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
211 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
212 | + 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
213 | + ), |
|
214 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
215 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
216 | + 'filename' => 'transactions_view_transaction_attendees_registered', |
|
217 | + ), |
|
218 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
219 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
220 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
221 | + ), |
|
222 | + ), |
|
223 | + 'qtips' => array('Transaction_Details_Tips'), |
|
224 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
225 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
226 | + |
|
227 | + 'require_nonce' => false, |
|
228 | + ), |
|
229 | + ); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * The below methods aren't used by this class currently |
|
235 | + */ |
|
236 | + protected function _add_screen_options() |
|
237 | + { |
|
238 | + // noop |
|
239 | + } |
|
240 | + |
|
241 | + protected function _add_feature_pointers() |
|
242 | + { |
|
243 | + // noop |
|
244 | + } |
|
245 | + |
|
246 | + public function admin_init() |
|
247 | + { |
|
248 | + // IF a registration was JUST added via the admin... |
|
249 | + if (isset( |
|
250 | + $this->_req_data['redirect_from'], |
|
251 | + $this->_req_data['EVT_ID'], |
|
252 | + $this->_req_data['event_name'] |
|
253 | + )) { |
|
254 | + // then set a cookie so that we can block any attempts to use |
|
255 | + // the back button as a way to enter another registration. |
|
256 | + setcookie( |
|
257 | + 'ee_registration_added', |
|
258 | + $this->_req_data['EVT_ID'], |
|
259 | + time() + WEEK_IN_SECONDS, |
|
260 | + '/' |
|
261 | + ); |
|
262 | + // and update the global |
|
263 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
264 | + } |
|
265 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
266 | + 'An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', |
|
267 | + 'event_espresso' |
|
268 | + ); |
|
269 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
270 | + 'An error occurred! Please refresh the page and try again.', |
|
271 | + 'event_espresso' |
|
272 | + ); |
|
273 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
274 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
275 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
276 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
277 | + 'This transaction has been overpaid ! Payments Total', |
|
278 | + 'event_espresso' |
|
279 | + ); |
|
280 | + } |
|
281 | + |
|
282 | + public function admin_notices() |
|
283 | + { |
|
284 | + // noop |
|
285 | + } |
|
286 | + |
|
287 | + public function admin_footer_scripts() |
|
288 | + { |
|
289 | + // noop |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * _set_transaction_status_array |
|
295 | + * sets list of transaction statuses |
|
296 | + * |
|
297 | + * @access private |
|
298 | + * @return void |
|
299 | + * @throws EE_Error |
|
300 | + * @throws InvalidArgumentException |
|
301 | + * @throws InvalidDataTypeException |
|
302 | + * @throws InvalidInterfaceException |
|
303 | + */ |
|
304 | + private function _set_transaction_status_array() |
|
305 | + { |
|
306 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * get_transaction_status_array |
|
312 | + * return the transaction status array for wp_list_table |
|
313 | + * |
|
314 | + * @access public |
|
315 | + * @return array |
|
316 | + */ |
|
317 | + public function get_transaction_status_array() |
|
318 | + { |
|
319 | + return self::$_txn_status; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * get list of payment statuses |
|
325 | + * |
|
326 | + * @access private |
|
327 | + * @return void |
|
328 | + * @throws EE_Error |
|
329 | + * @throws InvalidArgumentException |
|
330 | + * @throws InvalidDataTypeException |
|
331 | + * @throws InvalidInterfaceException |
|
332 | + */ |
|
333 | + private function _get_payment_status_array() |
|
334 | + { |
|
335 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
336 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * _add_screen_options_default |
|
342 | + * |
|
343 | + * @access protected |
|
344 | + * @return void |
|
345 | + * @throws InvalidArgumentException |
|
346 | + * @throws InvalidDataTypeException |
|
347 | + * @throws InvalidInterfaceException |
|
348 | + */ |
|
349 | + protected function _add_screen_options_default() |
|
350 | + { |
|
351 | + $this->_per_page_screen_option(); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * load_scripts_styles |
|
357 | + * |
|
358 | + * @access public |
|
359 | + * @return void |
|
360 | + */ |
|
361 | + public function load_scripts_styles() |
|
362 | + { |
|
363 | + // enqueue style |
|
364 | + wp_register_style( |
|
365 | + 'espresso_txn', |
|
366 | + TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
367 | + array(), |
|
368 | + EVENT_ESPRESSO_VERSION |
|
369 | + ); |
|
370 | + wp_enqueue_style('espresso_txn'); |
|
371 | + // scripts |
|
372 | + wp_register_script( |
|
373 | + 'espresso_txn', |
|
374 | + TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
375 | + array( |
|
376 | + 'ee_admin_js', |
|
377 | + 'ee-datepicker', |
|
378 | + 'jquery-ui-datepicker', |
|
379 | + 'jquery-ui-draggable', |
|
380 | + 'ee-dialog', |
|
381 | + 'ee-accounting', |
|
382 | + 'ee-serialize-full-array', |
|
383 | + ), |
|
384 | + EVENT_ESPRESSO_VERSION, |
|
385 | + true |
|
386 | + ); |
|
387 | + wp_enqueue_script('espresso_txn'); |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * load_scripts_styles_view_transaction |
|
393 | + * |
|
394 | + * @access public |
|
395 | + * @return void |
|
396 | + */ |
|
397 | + public function load_scripts_styles_view_transaction() |
|
398 | + { |
|
399 | + // styles |
|
400 | + wp_enqueue_style('espresso-ui-theme'); |
|
401 | + } |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * load_scripts_styles_default |
|
406 | + * |
|
407 | + * @access public |
|
408 | + * @return void |
|
409 | + */ |
|
410 | + public function load_scripts_styles_default() |
|
411 | + { |
|
412 | + // styles |
|
413 | + wp_enqueue_style('espresso-ui-theme'); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * _set_list_table_views_default |
|
419 | + * |
|
420 | + * @access protected |
|
421 | + * @return void |
|
422 | + */ |
|
423 | + protected function _set_list_table_views_default() |
|
424 | + { |
|
425 | + $this->_views = array( |
|
426 | + 'all' => array( |
|
427 | + 'slug' => 'all', |
|
428 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
429 | + 'count' => 0, |
|
430 | + ), |
|
431 | + 'abandoned' => array( |
|
432 | + 'slug' => 'abandoned', |
|
433 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
434 | + 'count' => 0, |
|
435 | + ), |
|
436 | + ); |
|
437 | + if (/** |
|
438 | + * Filters whether a link to the "Failed Transactions" list table |
|
439 | + * appears on the Transactions Admin Page list table. |
|
440 | + * List display can be turned back on via the following: |
|
441 | + * add_filter( |
|
442 | + * 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
443 | + * '__return_true' |
|
444 | + * ); |
|
445 | + * |
|
446 | + * @since $VID:$ |
|
447 | + * @param boolean $display_failed_txns_list |
|
448 | + * @param Transactions_Admin_Page $this |
|
449 | + */ |
|
450 | + apply_filters( |
|
451 | + 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
452 | + false, |
|
453 | + $this |
|
454 | + ) |
|
455 | + ) { |
|
456 | + $this->_views['failed'] = array( |
|
457 | + 'slug' => 'failed', |
|
458 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
459 | + 'count' => 0, |
|
460 | + ); |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + /** |
|
466 | + * _set_transaction_object |
|
467 | + * This sets the _transaction property for the transaction details screen |
|
468 | + * |
|
469 | + * @access private |
|
470 | + * @return void |
|
471 | + * @throws EE_Error |
|
472 | + * @throws InvalidArgumentException |
|
473 | + * @throws RuntimeException |
|
474 | + * @throws InvalidDataTypeException |
|
475 | + * @throws InvalidInterfaceException |
|
476 | + * @throws ReflectionException |
|
477 | + */ |
|
478 | + private function _set_transaction_object() |
|
479 | + { |
|
480 | + if ($this->_transaction instanceof EE_Transaction) { |
|
481 | + return; |
|
482 | + } //get out we've already set the object |
|
483 | + |
|
484 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
485 | + ? absint($this->_req_data['TXN_ID']) |
|
486 | + : false; |
|
487 | + |
|
488 | + // get transaction object |
|
489 | + $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
490 | + $this->_session = $this->_transaction instanceof EE_Transaction |
|
491 | + ? $this->_transaction->get('TXN_session_data') |
|
492 | + : null; |
|
493 | + if ($this->_transaction instanceof EE_Transaction) { |
|
494 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
495 | + } |
|
496 | + |
|
497 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
498 | + $error_msg = sprintf( |
|
499 | + esc_html__( |
|
500 | + 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
501 | + 'event_espresso' |
|
502 | + ), |
|
503 | + $TXN_ID |
|
504 | + ); |
|
505 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
506 | + } |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * _transaction_legend_items |
|
512 | + * |
|
513 | + * @access protected |
|
514 | + * @return array |
|
515 | + * @throws EE_Error |
|
516 | + * @throws InvalidArgumentException |
|
517 | + * @throws ReflectionException |
|
518 | + * @throws InvalidDataTypeException |
|
519 | + * @throws InvalidInterfaceException |
|
520 | + */ |
|
521 | + protected function _transaction_legend_items() |
|
522 | + { |
|
523 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
524 | + $items = array(); |
|
525 | + |
|
526 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
527 | + 'ee_read_global_messages', |
|
528 | + 'view_filtered_messages' |
|
529 | + )) { |
|
530 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
531 | + if (is_array($related_for_icon) |
|
532 | + && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
533 | + ) { |
|
534 | + $items['view_related_messages'] = array( |
|
535 | + 'class' => $related_for_icon['css_class'], |
|
536 | + 'desc' => $related_for_icon['label'], |
|
537 | + ); |
|
538 | + } |
|
539 | + } |
|
540 | + |
|
541 | + $items = apply_filters( |
|
542 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
543 | + array_merge( |
|
544 | + $items, |
|
545 | + array( |
|
546 | + 'view_details' => array( |
|
547 | + 'class' => 'dashicons dashicons-cart', |
|
548 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
549 | + ), |
|
550 | + 'view_invoice' => array( |
|
551 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
552 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
553 | + ), |
|
554 | + 'view_receipt' => array( |
|
555 | + 'class' => 'dashicons dashicons-media-default', |
|
556 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
557 | + ), |
|
558 | + 'view_registration' => array( |
|
559 | + 'class' => 'dashicons dashicons-clipboard', |
|
560 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
561 | + ), |
|
562 | + 'payment_overview_link' => array( |
|
563 | + 'class' => 'dashicons dashicons-money', |
|
564 | + 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
565 | + ), |
|
566 | + ) |
|
567 | + ) |
|
568 | + ); |
|
569 | + |
|
570 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
571 | + 'ee_send_message', |
|
572 | + 'espresso_transactions_send_payment_reminder' |
|
573 | + )) { |
|
574 | + if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
575 | + $items['send_payment_reminder'] = array( |
|
576 | + 'class' => 'dashicons dashicons-email-alt', |
|
577 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
578 | + ); |
|
579 | + } else { |
|
580 | + $items['blank*'] = array( |
|
581 | + 'class' => '', |
|
582 | + 'desc' => '', |
|
583 | + ); |
|
584 | + } |
|
585 | + } else { |
|
586 | + $items['blank*'] = array( |
|
587 | + 'class' => '', |
|
588 | + 'desc' => '', |
|
589 | + ); |
|
590 | + } |
|
591 | + $more_items = apply_filters( |
|
592 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
593 | + array( |
|
594 | + 'overpaid' => array( |
|
595 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
596 | + 'desc' => EEH_Template::pretty_status( |
|
597 | + EEM_Transaction::overpaid_status_code, |
|
598 | + false, |
|
599 | + 'sentence' |
|
600 | + ), |
|
601 | + ), |
|
602 | + 'complete' => array( |
|
603 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
604 | + 'desc' => EEH_Template::pretty_status( |
|
605 | + EEM_Transaction::complete_status_code, |
|
606 | + false, |
|
607 | + 'sentence' |
|
608 | + ), |
|
609 | + ), |
|
610 | + 'incomplete' => array( |
|
611 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
612 | + 'desc' => EEH_Template::pretty_status( |
|
613 | + EEM_Transaction::incomplete_status_code, |
|
614 | + false, |
|
615 | + 'sentence' |
|
616 | + ), |
|
617 | + ), |
|
618 | + 'abandoned' => array( |
|
619 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
620 | + 'desc' => EEH_Template::pretty_status( |
|
621 | + EEM_Transaction::abandoned_status_code, |
|
622 | + false, |
|
623 | + 'sentence' |
|
624 | + ), |
|
625 | + ), |
|
626 | + 'failed' => array( |
|
627 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
628 | + 'desc' => EEH_Template::pretty_status( |
|
629 | + EEM_Transaction::failed_status_code, |
|
630 | + false, |
|
631 | + 'sentence' |
|
632 | + ), |
|
633 | + ), |
|
634 | + ) |
|
635 | + ); |
|
636 | + |
|
637 | + return array_merge($items, $more_items); |
|
638 | + } |
|
639 | + |
|
640 | + |
|
641 | + /** |
|
642 | + * _transactions_overview_list_table |
|
643 | + * |
|
644 | + * @access protected |
|
645 | + * @return void |
|
646 | + * @throws DomainException |
|
647 | + * @throws EE_Error |
|
648 | + * @throws InvalidArgumentException |
|
649 | + * @throws InvalidDataTypeException |
|
650 | + * @throws InvalidInterfaceException |
|
651 | + * @throws ReflectionException |
|
652 | + */ |
|
653 | + protected function _transactions_overview_list_table() |
|
654 | + { |
|
655 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
656 | + $event = isset($this->_req_data['EVT_ID']) |
|
657 | + ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
658 | + : null; |
|
659 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
660 | + ? sprintf( |
|
661 | + esc_html__( |
|
662 | + '%sViewing Transactions for the Event: %s%s', |
|
663 | + 'event_espresso' |
|
664 | + ), |
|
665 | + '<h3>', |
|
666 | + '<a href="' |
|
667 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
668 | + array('action' => 'edit', 'post' => $event->ID()), |
|
669 | + EVENTS_ADMIN_URL |
|
670 | + ) |
|
671 | + . '" title="' |
|
672 | + . esc_attr__( |
|
673 | + 'Click to Edit event', |
|
674 | + 'event_espresso' |
|
675 | + ) |
|
676 | + . '">' . $event->get('EVT_name') . '</a>', |
|
677 | + '</h3>' |
|
678 | + ) |
|
679 | + : ''; |
|
680 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
681 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
682 | + } |
|
683 | + |
|
684 | + |
|
685 | + /** |
|
686 | + * _transaction_details |
|
687 | + * generates HTML for the View Transaction Details Admin page |
|
688 | + * |
|
689 | + * @access protected |
|
690 | + * @return void |
|
691 | + * @throws DomainException |
|
692 | + * @throws EE_Error |
|
693 | + * @throws InvalidArgumentException |
|
694 | + * @throws InvalidDataTypeException |
|
695 | + * @throws InvalidInterfaceException |
|
696 | + * @throws RuntimeException |
|
697 | + * @throws ReflectionException |
|
698 | + */ |
|
699 | + protected function _transaction_details() |
|
700 | + { |
|
701 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
702 | + |
|
703 | + $this->_set_transaction_status_array(); |
|
704 | + |
|
705 | + $this->_template_args = array(); |
|
706 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
707 | + |
|
708 | + $this->_set_transaction_object(); |
|
709 | + |
|
710 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
711 | + return; |
|
712 | + } |
|
713 | + $primary_registration = $this->_transaction->primary_registration(); |
|
714 | + $attendee = $primary_registration instanceof EE_Registration |
|
715 | + ? $primary_registration->attendee() |
|
716 | + : null; |
|
717 | + |
|
718 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
719 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
720 | + |
|
721 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
722 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
723 | + |
|
724 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->get('STS_ID') ]; |
|
725 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
726 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
727 | + |
|
728 | + $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
729 | + $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
730 | + |
|
731 | + $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
732 | + $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
733 | + $amount_due, |
|
734 | + true |
|
735 | + ); |
|
736 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
737 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
738 | + . $this->_template_args['amount_due']; |
|
739 | + } else { |
|
740 | + $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
741 | + } |
|
742 | + $this->_template_args['amount_due_class'] = ''; |
|
743 | + |
|
744 | + if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
745 | + // paid in full |
|
746 | + $this->_template_args['amount_due'] = false; |
|
747 | + } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
748 | + // overpaid |
|
749 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
750 | + } elseif ($this->_transaction->get('TXN_total') > 0 |
|
751 | + && $this->_transaction->get('TXN_paid') > 0 |
|
752 | + ) { |
|
753 | + // monies owing |
|
754 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
755 | + } elseif ($this->_transaction->get('TXN_total') > 0 |
|
756 | + && $this->_transaction->get('TXN_paid') == 0 |
|
757 | + ) { |
|
758 | + // no payments made yet |
|
759 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
760 | + } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
761 | + // free event |
|
762 | + $this->_template_args['amount_due'] = false; |
|
763 | + } |
|
764 | + |
|
765 | + $payment_method = $this->_transaction->payment_method(); |
|
766 | + |
|
767 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
768 | + ? $payment_method->admin_name() |
|
769 | + : esc_html__('Unknown', 'event_espresso'); |
|
770 | + |
|
771 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
772 | + // link back to overview |
|
773 | + $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
774 | + ? $_SERVER['HTTP_REFERER'] |
|
775 | + : TXN_ADMIN_URL; |
|
776 | + |
|
777 | + |
|
778 | + // next link |
|
779 | + $next_txn = $this->_transaction->next( |
|
780 | + null, |
|
781 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
782 | + 'TXN_ID' |
|
783 | + ); |
|
784 | + $this->_template_args['next_transaction'] = $next_txn |
|
785 | + ? $this->_next_link( |
|
786 | + EE_Admin_Page::add_query_args_and_nonce( |
|
787 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
788 | + TXN_ADMIN_URL |
|
789 | + ), |
|
790 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
791 | + ) |
|
792 | + : ''; |
|
793 | + // previous link |
|
794 | + $previous_txn = $this->_transaction->previous( |
|
795 | + null, |
|
796 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
797 | + 'TXN_ID' |
|
798 | + ); |
|
799 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
800 | + ? $this->_previous_link( |
|
801 | + EE_Admin_Page::add_query_args_and_nonce( |
|
802 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
803 | + TXN_ADMIN_URL |
|
804 | + ), |
|
805 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
806 | + ) |
|
807 | + : ''; |
|
808 | + |
|
809 | + // were we just redirected here after adding a new registration ??? |
|
810 | + if (isset( |
|
811 | + $this->_req_data['redirect_from'], |
|
812 | + $this->_req_data['EVT_ID'], |
|
813 | + $this->_req_data['event_name'] |
|
814 | + )) { |
|
815 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
816 | + 'ee_edit_registrations', |
|
817 | + 'espresso_registrations_new_registration', |
|
818 | + $this->_req_data['EVT_ID'] |
|
819 | + )) { |
|
820 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
821 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
822 | + array( |
|
823 | + 'page' => 'espresso_registrations', |
|
824 | + 'action' => 'new_registration', |
|
825 | + 'return' => 'default', |
|
826 | + 'TXN_ID' => $this->_transaction->ID(), |
|
827 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
828 | + ), |
|
829 | + REG_ADMIN_URL |
|
830 | + ); |
|
831 | + $this->_admin_page_title .= '">'; |
|
832 | + |
|
833 | + $this->_admin_page_title .= sprintf( |
|
834 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
835 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
836 | + ); |
|
837 | + $this->_admin_page_title .= '</a>'; |
|
838 | + } |
|
839 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
840 | + } |
|
841 | + // grab messages at the last second |
|
842 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
843 | + // path to template |
|
844 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
845 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
846 | + $template_path, |
|
847 | + $this->_template_args, |
|
848 | + true |
|
849 | + ); |
|
850 | + |
|
851 | + // the details template wrapper |
|
852 | + $this->display_admin_page_with_sidebar(); |
|
853 | + } |
|
854 | + |
|
855 | + |
|
856 | + /** |
|
857 | + * _transaction_details_metaboxes |
|
858 | + * |
|
859 | + * @access protected |
|
860 | + * @return void |
|
861 | + * @throws EE_Error |
|
862 | + * @throws InvalidArgumentException |
|
863 | + * @throws InvalidDataTypeException |
|
864 | + * @throws InvalidInterfaceException |
|
865 | + * @throws RuntimeException |
|
866 | + * @throws ReflectionException |
|
867 | + */ |
|
868 | + protected function _transaction_details_metaboxes() |
|
869 | + { |
|
870 | + |
|
871 | + $this->_set_transaction_object(); |
|
872 | + |
|
873 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
874 | + return; |
|
875 | + } |
|
876 | + add_meta_box( |
|
877 | + 'edit-txn-details-mbox', |
|
878 | + esc_html__('Transaction Details', 'event_espresso'), |
|
879 | + array($this, 'txn_details_meta_box'), |
|
880 | + $this->_wp_page_slug, |
|
881 | + 'normal', |
|
882 | + 'high' |
|
883 | + ); |
|
884 | + add_meta_box( |
|
885 | + 'edit-txn-attendees-mbox', |
|
886 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
887 | + array($this, 'txn_attendees_meta_box'), |
|
888 | + $this->_wp_page_slug, |
|
889 | + 'normal', |
|
890 | + 'high', |
|
891 | + array('TXN_ID' => $this->_transaction->ID()) |
|
892 | + ); |
|
893 | + add_meta_box( |
|
894 | + 'edit-txn-registrant-mbox', |
|
895 | + esc_html__('Primary Contact', 'event_espresso'), |
|
896 | + array($this, 'txn_registrant_side_meta_box'), |
|
897 | + $this->_wp_page_slug, |
|
898 | + 'side', |
|
899 | + 'high' |
|
900 | + ); |
|
901 | + add_meta_box( |
|
902 | + 'edit-txn-billing-info-mbox', |
|
903 | + esc_html__('Billing Information', 'event_espresso'), |
|
904 | + array($this, 'txn_billing_info_side_meta_box'), |
|
905 | + $this->_wp_page_slug, |
|
906 | + 'side', |
|
907 | + 'high' |
|
908 | + ); |
|
909 | + } |
|
910 | + |
|
911 | + |
|
912 | + /** |
|
913 | + * Callback for transaction actions metabox. |
|
914 | + * |
|
915 | + * @param EE_Transaction|null $transaction |
|
916 | + * @throws DomainException |
|
917 | + * @throws EE_Error |
|
918 | + * @throws InvalidArgumentException |
|
919 | + * @throws InvalidDataTypeException |
|
920 | + * @throws InvalidInterfaceException |
|
921 | + * @throws ReflectionException |
|
922 | + * @throws RuntimeException |
|
923 | + */ |
|
924 | + public function getActionButtons(EE_Transaction $transaction = null) |
|
925 | + { |
|
926 | + $content = ''; |
|
927 | + $actions = array(); |
|
928 | + if (! $transaction instanceof EE_Transaction) { |
|
929 | + return $content; |
|
930 | + } |
|
931 | + /** @var EE_Registration $primary_registration */ |
|
932 | + $primary_registration = $transaction->primary_registration(); |
|
933 | + $attendee = $primary_registration instanceof EE_Registration |
|
934 | + ? $primary_registration->attendee() |
|
935 | + : null; |
|
936 | + |
|
937 | + if ($attendee instanceof EE_Attendee |
|
938 | + && EE_Registry::instance()->CAP->current_user_can( |
|
939 | + 'ee_send_message', |
|
940 | + 'espresso_transactions_send_payment_reminder' |
|
941 | + ) |
|
942 | + ) { |
|
943 | + $actions['payment_reminder'] = |
|
944 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
945 | + && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code |
|
946 | + && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code |
|
947 | + ? EEH_Template::get_button_or_link( |
|
948 | + EE_Admin_Page::add_query_args_and_nonce( |
|
949 | + array( |
|
950 | + 'action' => 'send_payment_reminder', |
|
951 | + 'TXN_ID' => $this->_transaction->ID(), |
|
952 | + 'redirect_to' => 'view_transaction', |
|
953 | + ), |
|
954 | + TXN_ADMIN_URL |
|
955 | + ), |
|
956 | + esc_html__(' Send Payment Reminder', 'event_espresso'), |
|
957 | + 'button secondary-button', |
|
958 | + 'dashicons dashicons-email-alt' |
|
959 | + ) |
|
960 | + : ''; |
|
961 | + } |
|
962 | + |
|
963 | + if ($primary_registration instanceof EE_Registration |
|
964 | + && EEH_MSG_Template::is_mt_active('receipt') |
|
965 | + ) { |
|
966 | + $actions['receipt'] = EEH_Template::get_button_or_link( |
|
967 | + $primary_registration->receipt_url(), |
|
968 | + esc_html__('View Receipt', 'event_espresso'), |
|
969 | + 'button secondary-button', |
|
970 | + 'dashicons dashicons-media-default' |
|
971 | + ); |
|
972 | + } |
|
973 | + |
|
974 | + if ($primary_registration instanceof EE_Registration |
|
975 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
976 | + ) { |
|
977 | + $actions['invoice'] = EEH_Template::get_button_or_link( |
|
978 | + $primary_registration->invoice_url(), |
|
979 | + esc_html__('View Invoice', 'event_espresso'), |
|
980 | + 'button secondary-button', |
|
981 | + 'dashicons dashicons-media-spreadsheet' |
|
982 | + ); |
|
983 | + } |
|
984 | + $actions = array_filter( |
|
985 | + apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction) |
|
986 | + ); |
|
987 | + if ($actions) { |
|
988 | + $content = '<ul>'; |
|
989 | + $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
990 | + $content .= '</uL>'; |
|
991 | + } |
|
992 | + return $content; |
|
993 | + } |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * txn_details_meta_box |
|
998 | + * generates HTML for the Transaction main meta box |
|
999 | + * |
|
1000 | + * @return void |
|
1001 | + * @throws DomainException |
|
1002 | + * @throws EE_Error |
|
1003 | + * @throws InvalidArgumentException |
|
1004 | + * @throws InvalidDataTypeException |
|
1005 | + * @throws InvalidInterfaceException |
|
1006 | + * @throws RuntimeException |
|
1007 | + * @throws ReflectionException |
|
1008 | + */ |
|
1009 | + public function txn_details_meta_box() |
|
1010 | + { |
|
1011 | + $this->_set_transaction_object(); |
|
1012 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
1013 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
1014 | + ? $this->_transaction->primary_registration()->attendee() |
|
1015 | + : null; |
|
1016 | + $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
1017 | + 'ee_edit_payments', |
|
1018 | + 'apply_payment_or_refund_from_registration_details' |
|
1019 | + ); |
|
1020 | + $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
1021 | + 'ee_delete_payments', |
|
1022 | + 'delete_payment_from_registration_details' |
|
1023 | + ); |
|
1024 | + |
|
1025 | + // get line table |
|
1026 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
1027 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
1028 | + 'admin_table', |
|
1029 | + 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
1030 | + ); |
|
1031 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
1032 | + $this->_transaction->total_line_item() |
|
1033 | + ); |
|
1034 | + $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration') |
|
1035 | + ->get('REG_code'); |
|
1036 | + |
|
1037 | + // process taxes |
|
1038 | + $taxes = $this->_transaction->get_many_related( |
|
1039 | + 'Line_Item', |
|
1040 | + array(array('LIN_type' => EEM_Line_Item::type_tax)) |
|
1041 | + ); |
|
1042 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
1043 | + |
|
1044 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
1045 | + $this->_transaction->get('TXN_total'), |
|
1046 | + false, |
|
1047 | + false |
|
1048 | + ); |
|
1049 | + $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
1050 | + $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
1051 | + |
|
1052 | + // process payment details |
|
1053 | + $payments = $this->_transaction->get_many_related('Payment'); |
|
1054 | + if (! empty($payments)) { |
|
1055 | + $this->_template_args['payments'] = $payments; |
|
1056 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
1057 | + } else { |
|
1058 | + $this->_template_args['payments'] = false; |
|
1059 | + $this->_template_args['existing_reg_payments'] = array(); |
|
1060 | + } |
|
1061 | + |
|
1062 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
1063 | + $this->_template_args['delete_payment_url'] = add_query_arg( |
|
1064 | + array('action' => 'espresso_delete_payment'), |
|
1065 | + TXN_ADMIN_URL |
|
1066 | + ); |
|
1067 | + |
|
1068 | + if (isset($txn_details['invoice_number'])) { |
|
1069 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
1070 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
1071 | + 'Invoice Number', |
|
1072 | + 'event_espresso' |
|
1073 | + ); |
|
1074 | + } |
|
1075 | + |
|
1076 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
1077 | + ->get_first_related('Registration') |
|
1078 | + ->get('REG_session'); |
|
1079 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
1080 | + 'Registration Session', |
|
1081 | + 'event_espresso' |
|
1082 | + ); |
|
1083 | + |
|
1084 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
1085 | + ? $this->_session['ip_address'] |
|
1086 | + : ''; |
|
1087 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
1088 | + 'Transaction placed from IP', |
|
1089 | + 'event_espresso' |
|
1090 | + ); |
|
1091 | + |
|
1092 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
1093 | + ? $this->_session['user_agent'] |
|
1094 | + : ''; |
|
1095 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
1096 | + 'Registrant User Agent', |
|
1097 | + 'event_espresso' |
|
1098 | + ); |
|
1099 | + |
|
1100 | + $reg_steps = '<ul>'; |
|
1101 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
1102 | + if ($reg_step_status === true) { |
|
1103 | + $reg_steps .= '<li style="color:#70cc50">' |
|
1104 | + . sprintf( |
|
1105 | + esc_html__('%1$s : Completed', 'event_espresso'), |
|
1106 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
1107 | + ) |
|
1108 | + . '</li>'; |
|
1109 | + } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
1110 | + $reg_steps .= '<li style="color:#2EA2CC">' |
|
1111 | + . sprintf( |
|
1112 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
1113 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
1114 | + date( |
|
1115 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
1116 | + ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
1117 | + ) |
|
1118 | + ) |
|
1119 | + . '</li>'; |
|
1120 | + } else { |
|
1121 | + $reg_steps .= '<li style="color:#E76700">' |
|
1122 | + . sprintf( |
|
1123 | + esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
1124 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
1125 | + ) |
|
1126 | + . '</li>'; |
|
1127 | + } |
|
1128 | + } |
|
1129 | + $reg_steps .= '</ul>'; |
|
1130 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
1131 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
1132 | + 'Registration Step Progress', |
|
1133 | + 'event_espresso' |
|
1134 | + ); |
|
1135 | + |
|
1136 | + |
|
1137 | + $this->_get_registrations_to_apply_payment_to(); |
|
1138 | + $this->_get_payment_methods($payments); |
|
1139 | + $this->_get_payment_status_array(); |
|
1140 | + $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction. |
|
1141 | + |
|
1142 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
1143 | + array( |
|
1144 | + 'action' => 'edit_transaction', |
|
1145 | + 'process' => 'transaction', |
|
1146 | + ), |
|
1147 | + TXN_ADMIN_URL |
|
1148 | + ); |
|
1149 | + $this->_template_args['apply_payment_form_url'] = add_query_arg( |
|
1150 | + array( |
|
1151 | + 'page' => 'espresso_transactions', |
|
1152 | + 'action' => 'espresso_apply_payment', |
|
1153 | + ), |
|
1154 | + WP_AJAX_URL |
|
1155 | + ); |
|
1156 | + $this->_template_args['delete_payment_form_url'] = add_query_arg( |
|
1157 | + array( |
|
1158 | + 'page' => 'espresso_transactions', |
|
1159 | + 'action' => 'espresso_delete_payment', |
|
1160 | + ), |
|
1161 | + WP_AJAX_URL |
|
1162 | + ); |
|
1163 | + |
|
1164 | + $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction); |
|
1165 | + |
|
1166 | + // 'espresso_delete_payment_nonce' |
|
1167 | + |
|
1168 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
1169 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
1170 | + } |
|
1171 | + |
|
1172 | + |
|
1173 | + /** |
|
1174 | + * _get_registration_payment_IDs |
|
1175 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
1176 | + * |
|
1177 | + * @access protected |
|
1178 | + * @param EE_Payment[] $payments |
|
1179 | + * @return array |
|
1180 | + * @throws EE_Error |
|
1181 | + * @throws InvalidArgumentException |
|
1182 | + * @throws InvalidDataTypeException |
|
1183 | + * @throws InvalidInterfaceException |
|
1184 | + * @throws ReflectionException |
|
1185 | + */ |
|
1186 | + protected function _get_registration_payment_IDs($payments = array()) |
|
1187 | + { |
|
1188 | + $existing_reg_payments = array(); |
|
1189 | + // get all reg payments for these payments |
|
1190 | + $reg_payments = EEM_Registration_Payment::instance()->get_all( |
|
1191 | + array( |
|
1192 | + array( |
|
1193 | + 'PAY_ID' => array( |
|
1194 | + 'IN', |
|
1195 | + array_keys($payments), |
|
1196 | + ), |
|
1197 | + ), |
|
1198 | + ) |
|
1199 | + ); |
|
1200 | + if (! empty($reg_payments)) { |
|
1201 | + foreach ($payments as $payment) { |
|
1202 | + if (! $payment instanceof EE_Payment) { |
|
1203 | + continue; |
|
1204 | + } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
1205 | + $existing_reg_payments[ $payment->ID() ] = array(); |
|
1206 | + } |
|
1207 | + foreach ($reg_payments as $reg_payment) { |
|
1208 | + if ($reg_payment instanceof EE_Registration_Payment |
|
1209 | + && $reg_payment->payment_ID() === $payment->ID() |
|
1210 | + ) { |
|
1211 | + $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
1212 | + } |
|
1213 | + } |
|
1214 | + } |
|
1215 | + } |
|
1216 | + |
|
1217 | + return $existing_reg_payments; |
|
1218 | + } |
|
1219 | + |
|
1220 | + |
|
1221 | + /** |
|
1222 | + * _get_registrations_to_apply_payment_to |
|
1223 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
1224 | + * which allows the admin to only apply the payment to the specific registrations |
|
1225 | + * |
|
1226 | + * @access protected |
|
1227 | + * @return void |
|
1228 | + * @throws \EE_Error |
|
1229 | + */ |
|
1230 | + protected function _get_registrations_to_apply_payment_to() |
|
1231 | + { |
|
1232 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
1233 | + $query_params = array( |
|
1234 | + array( |
|
1235 | + 'STS_ID' => array( |
|
1236 | + 'IN', |
|
1237 | + array( |
|
1238 | + EEM_Registration::status_id_approved, |
|
1239 | + EEM_Registration::status_id_pending_payment, |
|
1240 | + EEM_Registration::status_id_not_approved, |
|
1241 | + ), |
|
1242 | + ), |
|
1243 | + ), |
|
1244 | + ); |
|
1245 | + $registrations_to_apply_payment_to = EEH_HTML::br() |
|
1246 | + . EEH_HTML::div( |
|
1247 | + '', |
|
1248 | + 'txn-admin-apply-payment-to-registrations-dv', |
|
1249 | + '', |
|
1250 | + 'clear: both; margin: 1.5em 0 0; display: none;' |
|
1251 | + ); |
|
1252 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
1253 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
1254 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
1255 | + EEH_HTML::tr( |
|
1256 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
1257 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
1258 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
1259 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
1260 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
1261 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
1262 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
1263 | + ) |
|
1264 | + ); |
|
1265 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
1266 | + // get registrations for TXN |
|
1267 | + $registrations = $this->_transaction->registrations($query_params); |
|
1268 | + $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
1269 | + foreach ($registrations as $registration) { |
|
1270 | + if ($registration instanceof EE_Registration) { |
|
1271 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
1272 | + ? $registration->attendee()->full_name() |
|
1273 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
1274 | + $owing = $registration->final_price() - $registration->paid(); |
|
1275 | + $taxable = $registration->ticket()->taxable() |
|
1276 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
1277 | + : ''; |
|
1278 | + $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
1279 | + ? ' checked="checked"' |
|
1280 | + : ''; |
|
1281 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
1282 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
1283 | + EEH_HTML::td($registration->ID()) . |
|
1284 | + EEH_HTML::td($attendee_name) . |
|
1285 | + EEH_HTML::td( |
|
1286 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
1287 | + ) . |
|
1288 | + EEH_HTML::td($registration->event_name()) . |
|
1289 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
1290 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
1291 | + EEH_HTML::td( |
|
1292 | + '<input type="checkbox" value="' . $registration->ID() |
|
1293 | + . '" name="txn_admin_payment[registrations]"' |
|
1294 | + . $checked . $disabled . '>', |
|
1295 | + '', |
|
1296 | + 'jst-cntr' |
|
1297 | + ), |
|
1298 | + 'apply-payment-registration-row-' . $registration->ID() |
|
1299 | + ); |
|
1300 | + } |
|
1301 | + } |
|
1302 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
1303 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
1304 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1305 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
1306 | + esc_html__( |
|
1307 | + 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', |
|
1308 | + 'event_espresso' |
|
1309 | + ), |
|
1310 | + '', |
|
1311 | + 'clear description' |
|
1312 | + ); |
|
1313 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1314 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
1315 | + } |
|
1316 | + |
|
1317 | + |
|
1318 | + /** |
|
1319 | + * _get_reg_status_selection |
|
1320 | + * |
|
1321 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
1322 | + * instead of events. |
|
1323 | + * @access protected |
|
1324 | + * @return void |
|
1325 | + * @throws EE_Error |
|
1326 | + */ |
|
1327 | + protected function _get_reg_status_selection() |
|
1328 | + { |
|
1329 | + // first get all possible statuses |
|
1330 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
1331 | + // let's add a "don't change" option. |
|
1332 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
1333 | + $status_array = array_merge($status_array, $statuses); |
|
1334 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
1335 | + 'txn_reg_status_change[reg_status]', |
|
1336 | + $status_array, |
|
1337 | + 'NAN', |
|
1338 | + 'id="txn-admin-payment-reg-status-inp"', |
|
1339 | + 'txn-reg-status-change-reg-status' |
|
1340 | + ); |
|
1341 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
1342 | + 'delete_txn_reg_status_change[reg_status]', |
|
1343 | + $status_array, |
|
1344 | + 'NAN', |
|
1345 | + 'delete-txn-admin-payment-reg-status-inp', |
|
1346 | + 'delete-txn-reg-status-change-reg-status' |
|
1347 | + ); |
|
1348 | + } |
|
1349 | + |
|
1350 | + |
|
1351 | + /** |
|
1352 | + * _get_payment_methods |
|
1353 | + * Gets all the payment methods available generally, or the ones that are already |
|
1354 | + * selected on these payments (in case their payment methods are no longer active). |
|
1355 | + * Has the side-effect of updating the template args' payment_methods item |
|
1356 | + * |
|
1357 | + * @access private |
|
1358 | + * @param EE_Payment[] to show on this page |
|
1359 | + * @return void |
|
1360 | + * @throws EE_Error |
|
1361 | + * @throws InvalidArgumentException |
|
1362 | + * @throws InvalidDataTypeException |
|
1363 | + * @throws InvalidInterfaceException |
|
1364 | + * @throws ReflectionException |
|
1365 | + */ |
|
1366 | + private function _get_payment_methods($payments = array()) |
|
1367 | + { |
|
1368 | + $payment_methods_of_payments = array(); |
|
1369 | + foreach ($payments as $payment) { |
|
1370 | + if ($payment instanceof EE_Payment) { |
|
1371 | + $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
1372 | + } |
|
1373 | + } |
|
1374 | + if ($payment_methods_of_payments) { |
|
1375 | + $query_args = array( |
|
1376 | + array( |
|
1377 | + 'OR*payment_method_for_payment' => array( |
|
1378 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
1379 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
1380 | + ), |
|
1381 | + ), |
|
1382 | + ); |
|
1383 | + } else { |
|
1384 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
1385 | + } |
|
1386 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
1387 | + } |
|
1388 | + |
|
1389 | + |
|
1390 | + /** |
|
1391 | + * txn_attendees_meta_box |
|
1392 | + * generates HTML for the Attendees Transaction main meta box |
|
1393 | + * |
|
1394 | + * @access public |
|
1395 | + * @param WP_Post $post |
|
1396 | + * @param array $metabox |
|
1397 | + * @return void |
|
1398 | + * @throws DomainException |
|
1399 | + * @throws EE_Error |
|
1400 | + */ |
|
1401 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
1402 | + { |
|
1403 | + |
|
1404 | + /** @noinspection NonSecureExtractUsageInspection */ |
|
1405 | + extract($metabox['args']); |
|
1406 | + $this->_template_args['post'] = $post; |
|
1407 | + $this->_template_args['event_attendees'] = array(); |
|
1408 | + // process items in cart |
|
1409 | + $line_items = $this->_transaction->get_many_related( |
|
1410 | + 'Line_Item', |
|
1411 | + array(array('LIN_type' => 'line-item')) |
|
1412 | + ); |
|
1413 | + if (! empty($line_items)) { |
|
1414 | + foreach ($line_items as $item) { |
|
1415 | + if ($item instanceof EE_Line_Item) { |
|
1416 | + switch ($item->OBJ_type()) { |
|
1417 | + case 'Event': |
|
1418 | + break; |
|
1419 | + case 'Ticket': |
|
1420 | + $ticket = $item->ticket(); |
|
1421 | + // right now we're only handling tickets here. |
|
1422 | + // Cause its expected that only tickets will have attendees right? |
|
1423 | + if (! $ticket instanceof EE_Ticket) { |
|
1424 | + continue; |
|
1425 | + } |
|
1426 | + try { |
|
1427 | + $event_name = $ticket->get_event_name(); |
|
1428 | + } catch (Exception $e) { |
|
1429 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1430 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
1431 | + } |
|
1432 | + $event_name .= ' - ' . $item->get('LIN_name'); |
|
1433 | + $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
1434 | + // now get all of the registrations for this transaction that use this ticket |
|
1435 | + $registrations = $ticket->get_many_related( |
|
1436 | + 'Registration', |
|
1437 | + array(array('TXN_ID' => $this->_transaction->ID())) |
|
1438 | + ); |
|
1439 | + foreach ($registrations as $registration) { |
|
1440 | + if (! $registration instanceof EE_Registration) { |
|
1441 | + continue; |
|
1442 | + } |
|
1443 | + $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
1444 | + = $registration->status_ID(); |
|
1445 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
1446 | + = $registration->count(); |
|
1447 | + $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
1448 | + = $event_name; |
|
1449 | + $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
1450 | + = $ticket_price; |
|
1451 | + // attendee info |
|
1452 | + $attendee = $registration->get_first_related('Attendee'); |
|
1453 | + if ($attendee instanceof EE_Attendee) { |
|
1454 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
1455 | + = $attendee->ID(); |
|
1456 | + $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
1457 | + = $attendee->full_name(); |
|
1458 | + $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
1459 | + = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
1460 | + . esc_html__( |
|
1461 | + ' Event', |
|
1462 | + 'event_espresso' |
|
1463 | + ) |
|
1464 | + . '">' . $attendee->email() . '</a>'; |
|
1465 | + $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
1466 | + = EEH_Address::format($attendee, 'inline', false, false); |
|
1467 | + } else { |
|
1468 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
1469 | + $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
1470 | + $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
1471 | + $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
1472 | + } |
|
1473 | + } |
|
1474 | + break; |
|
1475 | + } |
|
1476 | + } |
|
1477 | + } |
|
1478 | + |
|
1479 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
1480 | + array( |
|
1481 | + 'action' => 'edit_transaction', |
|
1482 | + 'process' => 'attendees', |
|
1483 | + ), |
|
1484 | + TXN_ADMIN_URL |
|
1485 | + ); |
|
1486 | + echo EEH_Template::display_template( |
|
1487 | + TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
1488 | + $this->_template_args, |
|
1489 | + true |
|
1490 | + ); |
|
1491 | + } else { |
|
1492 | + echo sprintf( |
|
1493 | + esc_html__( |
|
1494 | + '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
1495 | + 'event_espresso' |
|
1496 | + ), |
|
1497 | + '<p class="important-notice">', |
|
1498 | + '</p>' |
|
1499 | + ); |
|
1500 | + } |
|
1501 | + } |
|
1502 | + |
|
1503 | + |
|
1504 | + /** |
|
1505 | + * txn_registrant_side_meta_box |
|
1506 | + * generates HTML for the Edit Transaction side meta box |
|
1507 | + * |
|
1508 | + * @access public |
|
1509 | + * @return void |
|
1510 | + * @throws DomainException |
|
1511 | + * @throws EE_Error |
|
1512 | + * @throws InvalidArgumentException |
|
1513 | + * @throws InvalidDataTypeException |
|
1514 | + * @throws InvalidInterfaceException |
|
1515 | + * @throws ReflectionException |
|
1516 | + */ |
|
1517 | + public function txn_registrant_side_meta_box() |
|
1518 | + { |
|
1519 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
1520 | + ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
1521 | + : null; |
|
1522 | + if (! $primary_att instanceof EE_Attendee) { |
|
1523 | + $this->_template_args['no_attendee_message'] = esc_html__( |
|
1524 | + 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
1525 | + 'event_espresso' |
|
1526 | + ); |
|
1527 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
1528 | + } |
|
1529 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
1530 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
1531 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
1532 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
1533 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
1534 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
1535 | + array( |
|
1536 | + 'action' => 'edit_attendee', |
|
1537 | + 'post' => $primary_att->ID(), |
|
1538 | + ), |
|
1539 | + REG_ADMIN_URL |
|
1540 | + ); |
|
1541 | + // get formatted address for registrant |
|
1542 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
1543 | + echo EEH_Template::display_template( |
|
1544 | + TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
1545 | + $this->_template_args, |
|
1546 | + true |
|
1547 | + ); |
|
1548 | + } |
|
1549 | + |
|
1550 | + |
|
1551 | + /** |
|
1552 | + * txn_billing_info_side_meta_box |
|
1553 | + * generates HTML for the Edit Transaction side meta box |
|
1554 | + * |
|
1555 | + * @access public |
|
1556 | + * @return void |
|
1557 | + * @throws DomainException |
|
1558 | + * @throws EE_Error |
|
1559 | + */ |
|
1560 | + public function txn_billing_info_side_meta_box() |
|
1561 | + { |
|
1562 | + |
|
1563 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
1564 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
1565 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
1566 | + TXN_ADMIN_URL |
|
1567 | + ); |
|
1568 | + |
|
1569 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
1570 | + echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
1571 | + } |
|
1572 | + |
|
1573 | + |
|
1574 | + /** |
|
1575 | + * apply_payments_or_refunds |
|
1576 | + * registers a payment or refund made towards a transaction |
|
1577 | + * |
|
1578 | + * @access public |
|
1579 | + * @return void |
|
1580 | + * @throws EE_Error |
|
1581 | + * @throws InvalidArgumentException |
|
1582 | + * @throws ReflectionException |
|
1583 | + * @throws RuntimeException |
|
1584 | + * @throws InvalidDataTypeException |
|
1585 | + * @throws InvalidInterfaceException |
|
1586 | + */ |
|
1587 | + public function apply_payments_or_refunds() |
|
1588 | + { |
|
1589 | + $json_response_data = array('return_data' => false); |
|
1590 | + $valid_data = $this->_validate_payment_request_data(); |
|
1591 | + $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
1592 | + 'ee_edit_payments', |
|
1593 | + 'apply_payment_or_refund_from_registration_details' |
|
1594 | + ); |
|
1595 | + if (! empty($valid_data) && $has_access) { |
|
1596 | + $PAY_ID = $valid_data['PAY_ID']; |
|
1597 | + // save the new payment |
|
1598 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
1599 | + // get the TXN for this payment |
|
1600 | + $transaction = $payment->transaction(); |
|
1601 | + // verify transaction |
|
1602 | + if ($transaction instanceof EE_Transaction) { |
|
1603 | + // calculate_total_payments_and_update_status |
|
1604 | + $this->_process_transaction_payments($transaction); |
|
1605 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
1606 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
1607 | + // apply payment to registrations (if applicable) |
|
1608 | + if (! empty($REG_IDs)) { |
|
1609 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
1610 | + $this->_maybe_send_notifications(); |
|
1611 | + // now process status changes for the same registrations |
|
1612 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
1613 | + } |
|
1614 | + $this->_maybe_send_notifications($payment); |
|
1615 | + // prepare to render page |
|
1616 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
1617 | + do_action( |
|
1618 | + 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
1619 | + $transaction, |
|
1620 | + $payment |
|
1621 | + ); |
|
1622 | + } else { |
|
1623 | + EE_Error::add_error( |
|
1624 | + esc_html__( |
|
1625 | + 'A valid Transaction for this payment could not be retrieved.', |
|
1626 | + 'event_espresso' |
|
1627 | + ), |
|
1628 | + __FILE__, |
|
1629 | + __FUNCTION__, |
|
1630 | + __LINE__ |
|
1631 | + ); |
|
1632 | + } |
|
1633 | + } else { |
|
1634 | + if ($has_access) { |
|
1635 | + EE_Error::add_error( |
|
1636 | + esc_html__( |
|
1637 | + 'The payment form data could not be processed. Please try again.', |
|
1638 | + 'event_espresso' |
|
1639 | + ), |
|
1640 | + __FILE__, |
|
1641 | + __FUNCTION__, |
|
1642 | + __LINE__ |
|
1643 | + ); |
|
1644 | + } else { |
|
1645 | + EE_Error::add_error( |
|
1646 | + esc_html__( |
|
1647 | + 'You do not have access to apply payments or refunds to a registration.', |
|
1648 | + 'event_espresso' |
|
1649 | + ), |
|
1650 | + __FILE__, |
|
1651 | + __FUNCTION__, |
|
1652 | + __LINE__ |
|
1653 | + ); |
|
1654 | + } |
|
1655 | + } |
|
1656 | + $notices = EE_Error::get_notices( |
|
1657 | + false, |
|
1658 | + false, |
|
1659 | + false |
|
1660 | + ); |
|
1661 | + $this->_template_args = array( |
|
1662 | + 'data' => $json_response_data, |
|
1663 | + 'error' => $notices['errors'], |
|
1664 | + 'success' => $notices['success'], |
|
1665 | + ); |
|
1666 | + $this->_return_json(); |
|
1667 | + } |
|
1668 | + |
|
1669 | + |
|
1670 | + /** |
|
1671 | + * _validate_payment_request_data |
|
1672 | + * |
|
1673 | + * @return array |
|
1674 | + * @throws EE_Error |
|
1675 | + */ |
|
1676 | + protected function _validate_payment_request_data() |
|
1677 | + { |
|
1678 | + if (! isset($this->_req_data['txn_admin_payment'])) { |
|
1679 | + return false; |
|
1680 | + } |
|
1681 | + $payment_form = $this->_generate_payment_form_section(); |
|
1682 | + try { |
|
1683 | + if ($payment_form->was_submitted()) { |
|
1684 | + $payment_form->receive_form_submission(); |
|
1685 | + if (! $payment_form->is_valid()) { |
|
1686 | + $submission_error_messages = array(); |
|
1687 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
1688 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1689 | + $submission_error_messages[] = sprintf( |
|
1690 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
1691 | + $validation_error->get_form_section()->html_label_text(), |
|
1692 | + $validation_error->getMessage() |
|
1693 | + ); |
|
1694 | + } |
|
1695 | + } |
|
1696 | + EE_Error::add_error( |
|
1697 | + implode('<br />', $submission_error_messages), |
|
1698 | + __FILE__, |
|
1699 | + __FUNCTION__, |
|
1700 | + __LINE__ |
|
1701 | + ); |
|
1702 | + |
|
1703 | + return array(); |
|
1704 | + } |
|
1705 | + } |
|
1706 | + } catch (EE_Error $e) { |
|
1707 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1708 | + |
|
1709 | + return array(); |
|
1710 | + } |
|
1711 | + |
|
1712 | + return $payment_form->valid_data(); |
|
1713 | + } |
|
1714 | + |
|
1715 | + |
|
1716 | + /** |
|
1717 | + * _generate_payment_form_section |
|
1718 | + * |
|
1719 | + * @return EE_Form_Section_Proper |
|
1720 | + * @throws EE_Error |
|
1721 | + */ |
|
1722 | + protected function _generate_payment_form_section() |
|
1723 | + { |
|
1724 | + return new EE_Form_Section_Proper( |
|
1725 | + array( |
|
1726 | + 'name' => 'txn_admin_payment', |
|
1727 | + 'subsections' => array( |
|
1728 | + 'PAY_ID' => new EE_Text_Input( |
|
1729 | + array( |
|
1730 | + 'default' => 0, |
|
1731 | + 'required' => false, |
|
1732 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
1733 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1734 | + ) |
|
1735 | + ), |
|
1736 | + 'TXN_ID' => new EE_Text_Input( |
|
1737 | + array( |
|
1738 | + 'default' => 0, |
|
1739 | + 'required' => true, |
|
1740 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
1741 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1742 | + ) |
|
1743 | + ), |
|
1744 | + 'type' => new EE_Text_Input( |
|
1745 | + array( |
|
1746 | + 'default' => 1, |
|
1747 | + 'required' => true, |
|
1748 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
1749 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1750 | + ) |
|
1751 | + ), |
|
1752 | + 'amount' => new EE_Text_Input( |
|
1753 | + array( |
|
1754 | + 'default' => 0, |
|
1755 | + 'required' => true, |
|
1756 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
1757 | + 'validation_strategies' => array(new EE_Float_Normalization()), |
|
1758 | + ) |
|
1759 | + ), |
|
1760 | + 'status' => new EE_Text_Input( |
|
1761 | + array( |
|
1762 | + 'default' => EEM_Payment::status_id_approved, |
|
1763 | + 'required' => true, |
|
1764 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
1765 | + ) |
|
1766 | + ), |
|
1767 | + 'PMD_ID' => new EE_Text_Input( |
|
1768 | + array( |
|
1769 | + 'default' => 2, |
|
1770 | + 'required' => true, |
|
1771 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
1772 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1773 | + ) |
|
1774 | + ), |
|
1775 | + 'date' => new EE_Text_Input( |
|
1776 | + array( |
|
1777 | + 'default' => time(), |
|
1778 | + 'required' => true, |
|
1779 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
1780 | + ) |
|
1781 | + ), |
|
1782 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
1783 | + array( |
|
1784 | + 'default' => '', |
|
1785 | + 'required' => false, |
|
1786 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
1787 | + 'validation_strategies' => array( |
|
1788 | + new EE_Max_Length_Validation_Strategy( |
|
1789 | + esc_html__('Input too long', 'event_espresso'), |
|
1790 | + 100 |
|
1791 | + ), |
|
1792 | + ), |
|
1793 | + ) |
|
1794 | + ), |
|
1795 | + 'po_number' => new EE_Text_Input( |
|
1796 | + array( |
|
1797 | + 'default' => '', |
|
1798 | + 'required' => false, |
|
1799 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
1800 | + 'validation_strategies' => array( |
|
1801 | + new EE_Max_Length_Validation_Strategy( |
|
1802 | + esc_html__('Input too long', 'event_espresso'), |
|
1803 | + 100 |
|
1804 | + ), |
|
1805 | + ), |
|
1806 | + ) |
|
1807 | + ), |
|
1808 | + 'accounting' => new EE_Text_Input( |
|
1809 | + array( |
|
1810 | + 'default' => '', |
|
1811 | + 'required' => false, |
|
1812 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
1813 | + 'validation_strategies' => array( |
|
1814 | + new EE_Max_Length_Validation_Strategy( |
|
1815 | + esc_html__('Input too long', 'event_espresso'), |
|
1816 | + 100 |
|
1817 | + ), |
|
1818 | + ), |
|
1819 | + ) |
|
1820 | + ), |
|
1821 | + ), |
|
1822 | + ) |
|
1823 | + ); |
|
1824 | + } |
|
1825 | + |
|
1826 | + |
|
1827 | + /** |
|
1828 | + * _create_payment_from_request_data |
|
1829 | + * |
|
1830 | + * @param array $valid_data |
|
1831 | + * @return EE_Payment |
|
1832 | + * @throws EE_Error |
|
1833 | + */ |
|
1834 | + protected function _create_payment_from_request_data($valid_data) |
|
1835 | + { |
|
1836 | + $PAY_ID = $valid_data['PAY_ID']; |
|
1837 | + // get payment amount |
|
1838 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
1839 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
1840 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
1841 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
1842 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
1843 | + $date = $valid_data['date'] |
|
1844 | + ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
1845 | + : date('Y-m-d g:i a', current_time('timestamp')); |
|
1846 | + $payment = EE_Payment::new_instance( |
|
1847 | + array( |
|
1848 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
1849 | + 'STS_ID' => $valid_data['status'], |
|
1850 | + 'PAY_timestamp' => $date, |
|
1851 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
1852 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
1853 | + 'PAY_amount' => $amount, |
|
1854 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
1855 | + 'PAY_po_number' => $valid_data['po_number'], |
|
1856 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
1857 | + 'PAY_details' => $valid_data, |
|
1858 | + 'PAY_ID' => $PAY_ID, |
|
1859 | + ), |
|
1860 | + '', |
|
1861 | + array('Y-m-d', 'g:i a') |
|
1862 | + ); |
|
1863 | + |
|
1864 | + if (! $payment->save()) { |
|
1865 | + EE_Error::add_error( |
|
1866 | + sprintf( |
|
1867 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
1868 | + $payment->ID() |
|
1869 | + ), |
|
1870 | + __FILE__, |
|
1871 | + __FUNCTION__, |
|
1872 | + __LINE__ |
|
1873 | + ); |
|
1874 | + } |
|
1875 | + |
|
1876 | + return $payment; |
|
1877 | + } |
|
1878 | + |
|
1879 | + |
|
1880 | + /** |
|
1881 | + * _process_transaction_payments |
|
1882 | + * |
|
1883 | + * @param \EE_Transaction $transaction |
|
1884 | + * @return void |
|
1885 | + * @throws EE_Error |
|
1886 | + * @throws InvalidArgumentException |
|
1887 | + * @throws ReflectionException |
|
1888 | + * @throws InvalidDataTypeException |
|
1889 | + * @throws InvalidInterfaceException |
|
1890 | + */ |
|
1891 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
1892 | + { |
|
1893 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
1894 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1895 | + // update the transaction with this payment |
|
1896 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
1897 | + EE_Error::add_success( |
|
1898 | + esc_html__( |
|
1899 | + 'The payment has been processed successfully.', |
|
1900 | + 'event_espresso' |
|
1901 | + ), |
|
1902 | + __FILE__, |
|
1903 | + __FUNCTION__, |
|
1904 | + __LINE__ |
|
1905 | + ); |
|
1906 | + } else { |
|
1907 | + EE_Error::add_error( |
|
1908 | + esc_html__( |
|
1909 | + 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
1910 | + 'event_espresso' |
|
1911 | + ), |
|
1912 | + __FILE__, |
|
1913 | + __FUNCTION__, |
|
1914 | + __LINE__ |
|
1915 | + ); |
|
1916 | + } |
|
1917 | + } |
|
1918 | + |
|
1919 | + |
|
1920 | + /** |
|
1921 | + * _get_REG_IDs_to_apply_payment_to |
|
1922 | + * returns a list of registration IDs that the payment will apply to |
|
1923 | + * |
|
1924 | + * @param \EE_Payment $payment |
|
1925 | + * @return array |
|
1926 | + * @throws EE_Error |
|
1927 | + */ |
|
1928 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
1929 | + { |
|
1930 | + $REG_IDs = array(); |
|
1931 | + // grab array of IDs for specific registrations to apply changes to |
|
1932 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
1933 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
1934 | + } |
|
1935 | + // nothing specified ? then get all reg IDs |
|
1936 | + if (empty($REG_IDs)) { |
|
1937 | + $registrations = $payment->transaction()->registrations(); |
|
1938 | + $REG_IDs = ! empty($registrations) |
|
1939 | + ? array_keys($registrations) |
|
1940 | + : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1941 | + } |
|
1942 | + |
|
1943 | + // ensure that REG_IDs are integers and NOT strings |
|
1944 | + return array_map('intval', $REG_IDs); |
|
1945 | + } |
|
1946 | + |
|
1947 | + |
|
1948 | + /** |
|
1949 | + * @return array |
|
1950 | + */ |
|
1951 | + public function existing_reg_payment_REG_IDs() |
|
1952 | + { |
|
1953 | + return $this->_existing_reg_payment_REG_IDs; |
|
1954 | + } |
|
1955 | + |
|
1956 | + |
|
1957 | + /** |
|
1958 | + * @param array $existing_reg_payment_REG_IDs |
|
1959 | + */ |
|
1960 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
1961 | + { |
|
1962 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
1963 | + } |
|
1964 | + |
|
1965 | + |
|
1966 | + /** |
|
1967 | + * _get_existing_reg_payment_REG_IDs |
|
1968 | + * returns a list of registration IDs that the payment is currently related to |
|
1969 | + * as recorded in the database |
|
1970 | + * |
|
1971 | + * @param \EE_Payment $payment |
|
1972 | + * @return array |
|
1973 | + * @throws EE_Error |
|
1974 | + */ |
|
1975 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
1976 | + { |
|
1977 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
1978 | + // let's get any existing reg payment records for this payment |
|
1979 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
1980 | + // but we only want the REG IDs, so grab the array keys |
|
1981 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
1982 | + ? array_keys($existing_reg_payment_REG_IDs) |
|
1983 | + : array(); |
|
1984 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
1985 | + } |
|
1986 | + |
|
1987 | + return $this->existing_reg_payment_REG_IDs(); |
|
1988 | + } |
|
1989 | + |
|
1990 | + |
|
1991 | + /** |
|
1992 | + * _remove_existing_registration_payments |
|
1993 | + * this calculates the difference between existing relations |
|
1994 | + * to the supplied payment and the new list registration IDs, |
|
1995 | + * removes any related registrations that no longer apply, |
|
1996 | + * and then updates the registration paid fields |
|
1997 | + * |
|
1998 | + * @param \EE_Payment $payment |
|
1999 | + * @param int $PAY_ID |
|
2000 | + * @return bool; |
|
2001 | + * @throws EE_Error |
|
2002 | + * @throws InvalidArgumentException |
|
2003 | + * @throws ReflectionException |
|
2004 | + * @throws InvalidDataTypeException |
|
2005 | + * @throws InvalidInterfaceException |
|
2006 | + */ |
|
2007 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
2008 | + { |
|
2009 | + // newly created payments will have nothing recorded for $PAY_ID |
|
2010 | + if ($PAY_ID == 0) { |
|
2011 | + return false; |
|
2012 | + } |
|
2013 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
2014 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
2015 | + return false; |
|
2016 | + } |
|
2017 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
2018 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
2019 | + |
|
2020 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
2021 | + $payment, |
|
2022 | + array( |
|
2023 | + array( |
|
2024 | + 'PAY_ID' => $payment->ID(), |
|
2025 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
2026 | + ), |
|
2027 | + ) |
|
2028 | + ); |
|
2029 | + } |
|
2030 | + |
|
2031 | + |
|
2032 | + /** |
|
2033 | + * _update_registration_payments |
|
2034 | + * this applies the payments to the selected registrations |
|
2035 | + * but only if they have not already been paid for |
|
2036 | + * |
|
2037 | + * @param EE_Transaction $transaction |
|
2038 | + * @param \EE_Payment $payment |
|
2039 | + * @param array $REG_IDs |
|
2040 | + * @return void |
|
2041 | + * @throws EE_Error |
|
2042 | + * @throws InvalidArgumentException |
|
2043 | + * @throws ReflectionException |
|
2044 | + * @throws RuntimeException |
|
2045 | + * @throws InvalidDataTypeException |
|
2046 | + * @throws InvalidInterfaceException |
|
2047 | + */ |
|
2048 | + protected function _update_registration_payments( |
|
2049 | + EE_Transaction $transaction, |
|
2050 | + EE_Payment $payment, |
|
2051 | + $REG_IDs = array() |
|
2052 | + ) { |
|
2053 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
2054 | + // so let's do that using our set of REG_IDs from the form |
|
2055 | + $registration_query_where_params = array( |
|
2056 | + 'REG_ID' => array('IN', $REG_IDs), |
|
2057 | + ); |
|
2058 | + // but add in some conditions regarding payment, |
|
2059 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
2060 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
2061 | + if (! $payment->is_a_refund()) { |
|
2062 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
2063 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
2064 | + } |
|
2065 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
2066 | + if (! empty($registrations)) { |
|
2067 | + /** @type EE_Payment_Processor $payment_processor */ |
|
2068 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2069 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
2070 | + } |
|
2071 | + } |
|
2072 | + |
|
2073 | + |
|
2074 | + /** |
|
2075 | + * _process_registration_status_change |
|
2076 | + * This processes requested registration status changes for all the registrations |
|
2077 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
2078 | + * |
|
2079 | + * @param EE_Transaction $transaction |
|
2080 | + * @param array $REG_IDs |
|
2081 | + * @return bool |
|
2082 | + * @throws EE_Error |
|
2083 | + * @throws InvalidArgumentException |
|
2084 | + * @throws ReflectionException |
|
2085 | + * @throws InvalidDataTypeException |
|
2086 | + * @throws InvalidInterfaceException |
|
2087 | + */ |
|
2088 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
2089 | + { |
|
2090 | + // first if there is no change in status then we get out. |
|
2091 | + if (! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
2092 | + || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
2093 | + ) { |
|
2094 | + // no error message, no change requested, just nothing to do man. |
|
2095 | + return false; |
|
2096 | + } |
|
2097 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
2098 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
2099 | + |
|
2100 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
2101 | + return $transaction_processor->manually_update_registration_statuses( |
|
2102 | + $transaction, |
|
2103 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
2104 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
2105 | + ); |
|
2106 | + } |
|
2107 | + |
|
2108 | + |
|
2109 | + /** |
|
2110 | + * _build_payment_json_response |
|
2111 | + * |
|
2112 | + * @access public |
|
2113 | + * @param \EE_Payment $payment |
|
2114 | + * @param array $REG_IDs |
|
2115 | + * @param bool | null $delete_txn_reg_status_change |
|
2116 | + * @return array |
|
2117 | + * @throws EE_Error |
|
2118 | + * @throws InvalidArgumentException |
|
2119 | + * @throws InvalidDataTypeException |
|
2120 | + * @throws InvalidInterfaceException |
|
2121 | + * @throws ReflectionException |
|
2122 | + */ |
|
2123 | + protected function _build_payment_json_response( |
|
2124 | + EE_Payment $payment, |
|
2125 | + $REG_IDs = array(), |
|
2126 | + $delete_txn_reg_status_change = null |
|
2127 | + ) { |
|
2128 | + // was the payment deleted ? |
|
2129 | + if (is_bool($delete_txn_reg_status_change)) { |
|
2130 | + return array( |
|
2131 | + 'PAY_ID' => $payment->ID(), |
|
2132 | + 'amount' => $payment->amount(), |
|
2133 | + 'total_paid' => $payment->transaction()->paid(), |
|
2134 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
2135 | + 'pay_status' => $payment->STS_ID(), |
|
2136 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
2137 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
2138 | + ); |
|
2139 | + } else { |
|
2140 | + $this->_get_payment_status_array(); |
|
2141 | + |
|
2142 | + return array( |
|
2143 | + 'amount' => $payment->amount(), |
|
2144 | + 'total_paid' => $payment->transaction()->paid(), |
|
2145 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
2146 | + 'pay_status' => $payment->STS_ID(), |
|
2147 | + 'PAY_ID' => $payment->ID(), |
|
2148 | + 'STS_ID' => $payment->STS_ID(), |
|
2149 | + 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
2150 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
2151 | + 'method' => strtoupper($payment->source()), |
|
2152 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
2153 | + 'gateway' => $payment->payment_method() |
|
2154 | + ? $payment->payment_method()->admin_name() |
|
2155 | + : esc_html__("Unknown", 'event_espresso'), |
|
2156 | + 'gateway_response' => $payment->gateway_response(), |
|
2157 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
2158 | + 'po_number' => $payment->po_number(), |
|
2159 | + 'extra_accntng' => $payment->extra_accntng(), |
|
2160 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
2161 | + ); |
|
2162 | + } |
|
2163 | + } |
|
2164 | + |
|
2165 | + |
|
2166 | + /** |
|
2167 | + * delete_payment |
|
2168 | + * delete a payment or refund made towards a transaction |
|
2169 | + * |
|
2170 | + * @access public |
|
2171 | + * @return void |
|
2172 | + * @throws EE_Error |
|
2173 | + * @throws InvalidArgumentException |
|
2174 | + * @throws ReflectionException |
|
2175 | + * @throws InvalidDataTypeException |
|
2176 | + * @throws InvalidInterfaceException |
|
2177 | + */ |
|
2178 | + public function delete_payment() |
|
2179 | + { |
|
2180 | + $json_response_data = array('return_data' => false); |
|
2181 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
2182 | + ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
2183 | + : 0; |
|
2184 | + $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
2185 | + 'ee_delete_payments', |
|
2186 | + 'delete_payment_from_registration_details' |
|
2187 | + ); |
|
2188 | + if ($PAY_ID && $can_delete) { |
|
2189 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
2190 | + ? $this->_req_data['delete_txn_reg_status_change'] |
|
2191 | + : false; |
|
2192 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
2193 | + if ($payment instanceof EE_Payment) { |
|
2194 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
2195 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
2196 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
2197 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
2198 | + $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
2199 | + $payment, |
|
2200 | + $REG_IDs, |
|
2201 | + $delete_txn_reg_status_change |
|
2202 | + ); |
|
2203 | + if ($delete_txn_reg_status_change) { |
|
2204 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
2205 | + // MAKE sure we also add the delete_txn_req_status_change to the |
|
2206 | + // $_REQUEST global because that's how messages will be looking for it. |
|
2207 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
2208 | + $this->_maybe_send_notifications(); |
|
2209 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
2210 | + } |
|
2211 | + } |
|
2212 | + } else { |
|
2213 | + EE_Error::add_error( |
|
2214 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
2215 | + __FILE__, |
|
2216 | + __FUNCTION__, |
|
2217 | + __LINE__ |
|
2218 | + ); |
|
2219 | + } |
|
2220 | + } else { |
|
2221 | + if ($can_delete) { |
|
2222 | + EE_Error::add_error( |
|
2223 | + esc_html__( |
|
2224 | + 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
2225 | + 'event_espresso' |
|
2226 | + ), |
|
2227 | + __FILE__, |
|
2228 | + __FUNCTION__, |
|
2229 | + __LINE__ |
|
2230 | + ); |
|
2231 | + } else { |
|
2232 | + EE_Error::add_error( |
|
2233 | + esc_html__( |
|
2234 | + 'You do not have access to delete a payment.', |
|
2235 | + 'event_espresso' |
|
2236 | + ), |
|
2237 | + __FILE__, |
|
2238 | + __FUNCTION__, |
|
2239 | + __LINE__ |
|
2240 | + ); |
|
2241 | + } |
|
2242 | + } |
|
2243 | + $notices = EE_Error::get_notices(false, false, false); |
|
2244 | + $this->_template_args = array( |
|
2245 | + 'data' => $json_response_data, |
|
2246 | + 'success' => $notices['success'], |
|
2247 | + 'error' => $notices['errors'], |
|
2248 | + 'attention' => $notices['attention'], |
|
2249 | + ); |
|
2250 | + $this->_return_json(); |
|
2251 | + } |
|
2252 | + |
|
2253 | + |
|
2254 | + /** |
|
2255 | + * _registration_payment_data_array |
|
2256 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
2257 | + * |
|
2258 | + * @access protected |
|
2259 | + * @param array $REG_IDs |
|
2260 | + * @return array |
|
2261 | + * @throws EE_Error |
|
2262 | + * @throws InvalidArgumentException |
|
2263 | + * @throws InvalidDataTypeException |
|
2264 | + * @throws InvalidInterfaceException |
|
2265 | + * @throws ReflectionException |
|
2266 | + */ |
|
2267 | + protected function _registration_payment_data_array($REG_IDs) |
|
2268 | + { |
|
2269 | + $registration_payment_data = array(); |
|
2270 | + // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
2271 | + if (! empty($REG_IDs)) { |
|
2272 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
2273 | + foreach ($registrations as $registration) { |
|
2274 | + if ($registration instanceof EE_Registration) { |
|
2275 | + $registration_payment_data[ $registration->ID() ] = array( |
|
2276 | + 'paid' => $registration->pretty_paid(), |
|
2277 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
2278 | + ); |
|
2279 | + } |
|
2280 | + } |
|
2281 | + } |
|
2282 | + |
|
2283 | + return $registration_payment_data; |
|
2284 | + } |
|
2285 | + |
|
2286 | + |
|
2287 | + /** |
|
2288 | + * _maybe_send_notifications |
|
2289 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
2290 | + * If so, will toggle a filter switch for delivering registration notices. |
|
2291 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
2292 | + * |
|
2293 | + * @access protected |
|
2294 | + * @param \EE_Payment | null $payment |
|
2295 | + */ |
|
2296 | + protected function _maybe_send_notifications($payment = null) |
|
2297 | + { |
|
2298 | + switch ($payment instanceof EE_Payment) { |
|
2299 | + // payment notifications |
|
2300 | + case true: |
|
2301 | + if (isset( |
|
2302 | + $this->_req_data['txn_payments'], |
|
2303 | + $this->_req_data['txn_payments']['send_notifications'] |
|
2304 | + ) |
|
2305 | + && filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
2306 | + ) { |
|
2307 | + $this->_process_payment_notification($payment); |
|
2308 | + } |
|
2309 | + break; |
|
2310 | + // registration notifications |
|
2311 | + case false: |
|
2312 | + if (isset( |
|
2313 | + $this->_req_data['txn_reg_status_change'], |
|
2314 | + $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
2315 | + ) |
|
2316 | + && filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
2317 | + ) { |
|
2318 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
2319 | + } |
|
2320 | + break; |
|
2321 | + } |
|
2322 | + } |
|
2323 | + |
|
2324 | + |
|
2325 | + /** |
|
2326 | + * _send_payment_reminder |
|
2327 | + * generates HTML for the View Transaction Details Admin page |
|
2328 | + * |
|
2329 | + * @access protected |
|
2330 | + * @return void |
|
2331 | + * @throws EE_Error |
|
2332 | + * @throws InvalidArgumentException |
|
2333 | + * @throws InvalidDataTypeException |
|
2334 | + * @throws InvalidInterfaceException |
|
2335 | + */ |
|
2336 | + protected function _send_payment_reminder() |
|
2337 | + { |
|
2338 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
2339 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2340 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
2341 | + 'action' => $this->_req_data['redirect_to'], |
|
2342 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
2343 | + ) : array(); |
|
2344 | + do_action( |
|
2345 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
2346 | + $transaction |
|
2347 | + ); |
|
2348 | + $this->_redirect_after_action( |
|
2349 | + false, |
|
2350 | + esc_html__('payment reminder', 'event_espresso'), |
|
2351 | + esc_html__('sent', 'event_espresso'), |
|
2352 | + $query_args, |
|
2353 | + true |
|
2354 | + ); |
|
2355 | + } |
|
2356 | + |
|
2357 | + |
|
2358 | + /** |
|
2359 | + * get_transactions |
|
2360 | + * get transactions for given parameters (used by list table) |
|
2361 | + * |
|
2362 | + * @param int $perpage how many transactions displayed per page |
|
2363 | + * @param boolean $count return the count or objects |
|
2364 | + * @param string $view |
|
2365 | + * @return mixed int = count || array of transaction objects |
|
2366 | + * @throws EE_Error |
|
2367 | + * @throws InvalidArgumentException |
|
2368 | + * @throws InvalidDataTypeException |
|
2369 | + * @throws InvalidInterfaceException |
|
2370 | + */ |
|
2371 | + public function get_transactions($perpage, $count = false, $view = '') |
|
2372 | + { |
|
2373 | + |
|
2374 | + $TXN = EEM_Transaction::instance(); |
|
2375 | + |
|
2376 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
2377 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
2378 | + : date( |
|
2379 | + 'm/d/Y', |
|
2380 | + strtotime('-10 year') |
|
2381 | + ); |
|
2382 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
2383 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
2384 | + : date('m/d/Y'); |
|
2385 | + |
|
2386 | + // make sure our timestamps start and end right at the boundaries for each day |
|
2387 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
2388 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
2389 | + |
|
2390 | + |
|
2391 | + // convert to timestamps |
|
2392 | + $start_date = strtotime($start_date); |
|
2393 | + $end_date = strtotime($end_date); |
|
2394 | + |
|
2395 | + // makes sure start date is the lowest value and vice versa |
|
2396 | + $start_date = min($start_date, $end_date); |
|
2397 | + $end_date = max($start_date, $end_date); |
|
2398 | + |
|
2399 | + // convert to correct format for query |
|
2400 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
2401 | + 'TXN_timestamp', |
|
2402 | + date('Y-m-d H:i:s', $start_date), |
|
2403 | + 'Y-m-d H:i:s' |
|
2404 | + ); |
|
2405 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
2406 | + 'TXN_timestamp', |
|
2407 | + date('Y-m-d H:i:s', $end_date), |
|
2408 | + 'Y-m-d H:i:s' |
|
2409 | + ); |
|
2410 | + |
|
2411 | + |
|
2412 | + // set orderby |
|
2413 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
2414 | + |
|
2415 | + switch ($this->_req_data['orderby']) { |
|
2416 | + case 'TXN_ID': |
|
2417 | + $orderby = 'TXN_ID'; |
|
2418 | + break; |
|
2419 | + case 'ATT_fname': |
|
2420 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
2421 | + break; |
|
2422 | + case 'event_name': |
|
2423 | + $orderby = 'Registration.Event.EVT_name'; |
|
2424 | + break; |
|
2425 | + default: // 'TXN_timestamp' |
|
2426 | + $orderby = 'TXN_timestamp'; |
|
2427 | + } |
|
2428 | + |
|
2429 | + $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2430 | + $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
2431 | + $per_page = ! empty($perpage) ? $perpage : 10; |
|
2432 | + $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
2433 | + |
|
2434 | + $offset = ($current_page - 1) * $per_page; |
|
2435 | + $limit = array($offset, $per_page); |
|
2436 | + |
|
2437 | + $_where = array( |
|
2438 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
2439 | + 'Registration.REG_count' => 1, |
|
2440 | + ); |
|
2441 | + |
|
2442 | + if (isset($this->_req_data['EVT_ID'])) { |
|
2443 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
2444 | + } |
|
2445 | + |
|
2446 | + if (isset($this->_req_data['s'])) { |
|
2447 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
2448 | + $_where['OR'] = array( |
|
2449 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
2450 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
2451 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
2452 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
2453 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
2454 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
2455 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
2456 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
2457 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
2458 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
2459 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
2460 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
2461 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
2462 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
2463 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
2464 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
2465 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
2466 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
2467 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
2468 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
2469 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
2470 | + ); |
|
2471 | + } |
|
2472 | + |
|
2473 | + // failed transactions |
|
2474 | + $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
2475 | + || ($count && $view === 'failed'); |
|
2476 | + $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
2477 | + || ($count && $view === 'abandoned'); |
|
2478 | + |
|
2479 | + if ($failed) { |
|
2480 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
2481 | + } elseif ($abandoned) { |
|
2482 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
2483 | + } else { |
|
2484 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
2485 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
2486 | + } |
|
2487 | + |
|
2488 | + $query_params = array( |
|
2489 | + $_where, |
|
2490 | + 'order_by' => array($orderby => $sort), |
|
2491 | + 'limit' => $limit, |
|
2492 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
2493 | + ); |
|
2494 | + |
|
2495 | + $transactions = $count |
|
2496 | + ? $TXN->count(array($_where), 'TXN_ID', true) |
|
2497 | + : $TXN->get_all($query_params); |
|
2498 | + |
|
2499 | + return $transactions; |
|
2500 | + } |
|
2501 | 2501 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.70.rc.010'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.70.rc.010'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |