@@ -2166,6 +2166,7 @@ |
||
2166 | 2166 | * |
2167 | 2167 | * @access protected |
2168 | 2168 | * @param \EE_Payment | null $payment |
2169 | + * @param EE_Payment $payment |
|
2169 | 2170 | */ |
2170 | 2171 | protected function _maybe_send_notifications($payment = null) |
2171 | 2172 | { |
@@ -266,7 +266,7 @@ discard block |
||
266 | 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 | 267 | 'event_espresso' |
268 | 268 | ); |
269 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
269 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
270 | 270 | 'An error occurred! Please refresh the page and try again.', |
271 | 271 | 'event_espresso' |
272 | 272 | ); |
@@ -364,13 +364,13 @@ discard block |
||
364 | 364 | //enqueue style |
365 | 365 | wp_register_style( |
366 | 366 | 'espresso_txn', |
367 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
367 | + TXN_ASSETS_URL.'espresso_transactions_admin.css', |
|
368 | 368 | array(), |
369 | 369 | EVENT_ESPRESSO_VERSION |
370 | 370 | ); |
371 | 371 | wp_enqueue_style('espresso_txn'); |
372 | 372 | //scripts |
373 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
373 | + wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array( |
|
374 | 374 | 'ee_admin_js', |
375 | 375 | 'ee-datepicker', |
376 | 376 | 'jquery-ui-datepicker', |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | : null; |
467 | 467 | $this->_transaction->verify_abandoned_transaction_status(); |
468 | 468 | |
469 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
469 | + if ( ! $this->_transaction instanceof EE_Transaction) { |
|
470 | 470 | $error_msg = sprintf( |
471 | 471 | esc_html__( |
472 | 472 | 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
565 | 565 | array( |
566 | 566 | 'overpaid' => array( |
567 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
567 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code, |
|
568 | 568 | 'desc' => EEH_Template::pretty_status( |
569 | 569 | EEM_Transaction::overpaid_status_code, |
570 | 570 | false, |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | ), |
573 | 573 | ), |
574 | 574 | 'complete' => array( |
575 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
575 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code, |
|
576 | 576 | 'desc' => EEH_Template::pretty_status( |
577 | 577 | EEM_Transaction::complete_status_code, |
578 | 578 | false, |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | ), |
581 | 581 | ), |
582 | 582 | 'incomplete' => array( |
583 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
583 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code, |
|
584 | 584 | 'desc' => EEH_Template::pretty_status( |
585 | 585 | EEM_Transaction::incomplete_status_code, |
586 | 586 | false, |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | ), |
589 | 589 | ), |
590 | 590 | 'abandoned' => array( |
591 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
591 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code, |
|
592 | 592 | 'desc' => EEH_Template::pretty_status( |
593 | 593 | EEM_Transaction::abandoned_status_code, |
594 | 594 | false, |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | ), |
597 | 597 | ), |
598 | 598 | 'failed' => array( |
599 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
599 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code, |
|
600 | 600 | 'desc' => EEH_Template::pretty_status( |
601 | 601 | EEM_Transaction::failed_status_code, |
602 | 602 | false, |
@@ -645,11 +645,11 @@ discard block |
||
645 | 645 | 'Click to Edit event', |
646 | 646 | 'event_espresso' |
647 | 647 | ) |
648 | - . '">' . $event->get('EVT_name') . '</a>', |
|
648 | + . '">'.$event->get('EVT_name').'</a>', |
|
649 | 649 | '</h3>' |
650 | 650 | ) |
651 | 651 | : ''; |
652 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
652 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
653 | 653 | $this->display_admin_list_table_page_with_no_sidebar(); |
654 | 654 | } |
655 | 655 | |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | |
692 | 692 | $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
693 | 693 | $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
694 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
694 | + $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID'); |
|
695 | 695 | |
696 | 696 | $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
697 | 697 | $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | |
773 | 773 | |
774 | 774 | // next link |
775 | - $next_txn = $this->_transaction->next( |
|
775 | + $next_txn = $this->_transaction->next( |
|
776 | 776 | null, |
777 | 777 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
778 | 778 | 'TXN_ID' |
@@ -787,7 +787,7 @@ discard block |
||
787 | 787 | ) |
788 | 788 | : ''; |
789 | 789 | // previous link |
790 | - $previous_txn = $this->_transaction->previous( |
|
790 | + $previous_txn = $this->_transaction->previous( |
|
791 | 791 | null, |
792 | 792 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
793 | 793 | 'TXN_ID' |
@@ -837,7 +837,7 @@ discard block |
||
837 | 837 | // grab messages at the last second |
838 | 838 | $this->_template_args['notices'] = EE_Error::get_notices(); |
839 | 839 | // path to template |
840 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
840 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php'; |
|
841 | 841 | $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
842 | 842 | $template_path, |
843 | 843 | $this->_template_args, |
@@ -926,7 +926,7 @@ discard block |
||
926 | 926 | |
927 | 927 | //get line table |
928 | 928 | EEH_Autoloader::register_line_item_display_autoloaders(); |
929 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
929 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
930 | 930 | 'admin_table', |
931 | 931 | 'EE_Admin_Table_Line_Item_Display_Strategy' |
932 | 932 | ); |
@@ -937,13 +937,13 @@ discard block |
||
937 | 937 | ->get('REG_code'); |
938 | 938 | |
939 | 939 | // process taxes |
940 | - $taxes = $this->_transaction->get_many_related( |
|
940 | + $taxes = $this->_transaction->get_many_related( |
|
941 | 941 | 'Line_Item', |
942 | 942 | array(array('LIN_type' => EEM_Line_Item::type_tax)) |
943 | 943 | ); |
944 | 944 | $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
945 | 945 | |
946 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
946 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
947 | 947 | $this->_transaction->get('TXN_total'), |
948 | 948 | false, |
949 | 949 | false |
@@ -953,7 +953,7 @@ discard block |
||
953 | 953 | |
954 | 954 | // process payment details |
955 | 955 | $payments = $this->_transaction->get_many_related('Payment'); |
956 | - if (! empty($payments)) { |
|
956 | + if ( ! empty($payments)) { |
|
957 | 957 | $this->_template_args['payments'] = $payments; |
958 | 958 | $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
959 | 959 | } else { |
@@ -1014,7 +1014,7 @@ discard block |
||
1014 | 1014 | esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
1015 | 1015 | ucwords(str_replace('_', ' ', $reg_step)), |
1016 | 1016 | date( |
1017 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
1017 | + get_option('date_format').' '.get_option('time_format'), |
|
1018 | 1018 | ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
1019 | 1019 | ) |
1020 | 1020 | ) |
@@ -1028,7 +1028,7 @@ discard block |
||
1028 | 1028 | . '</li>'; |
1029 | 1029 | } |
1030 | 1030 | } |
1031 | - $reg_steps .= '</ul>'; |
|
1031 | + $reg_steps .= '</ul>'; |
|
1032 | 1032 | $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
1033 | 1033 | $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
1034 | 1034 | 'Registration Step Progress', |
@@ -1041,11 +1041,11 @@ discard block |
||
1041 | 1041 | $this->_get_payment_status_array(); |
1042 | 1042 | $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
1043 | 1043 | |
1044 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
1044 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
1045 | 1045 | 'action' => 'edit_transaction', |
1046 | 1046 | 'process' => 'transaction', |
1047 | 1047 | ), TXN_ADMIN_URL); |
1048 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
1048 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
1049 | 1049 | 'page' => 'espresso_transactions', |
1050 | 1050 | 'action' => 'espresso_apply_payment', |
1051 | 1051 | ), WP_AJAX_URL); |
@@ -1056,7 +1056,7 @@ discard block |
||
1056 | 1056 | |
1057 | 1057 | // 'espresso_delete_payment_nonce' |
1058 | 1058 | |
1059 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
1059 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
1060 | 1060 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
1061 | 1061 | } |
1062 | 1062 | |
@@ -1085,11 +1085,11 @@ discard block |
||
1085 | 1085 | ), |
1086 | 1086 | ), |
1087 | 1087 | )); |
1088 | - if (! empty($reg_payments)) { |
|
1088 | + if ( ! empty($reg_payments)) { |
|
1089 | 1089 | foreach ($payments as $payment) { |
1090 | - if (! $payment instanceof EE_Payment) { |
|
1090 | + if ( ! $payment instanceof EE_Payment) { |
|
1091 | 1091 | continue; |
1092 | - } elseif (! isset($existing_reg_payments[$payment->ID()])) { |
|
1092 | + } elseif ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
1093 | 1093 | $existing_reg_payments[$payment->ID()] = array(); |
1094 | 1094 | } |
1095 | 1095 | foreach ($reg_payments as $reg_payment) { |
@@ -1118,7 +1118,7 @@ discard block |
||
1118 | 1118 | protected function _get_registrations_to_apply_payment_to() |
1119 | 1119 | { |
1120 | 1120 | // we want any registration with an active status (ie: not deleted or cancelled) |
1121 | - $query_params = array( |
|
1121 | + $query_params = array( |
|
1122 | 1122 | array( |
1123 | 1123 | 'STS_ID' => array( |
1124 | 1124 | 'IN', |
@@ -1137,16 +1137,16 @@ discard block |
||
1137 | 1137 | '', |
1138 | 1138 | 'clear: both; margin: 1.5em 0 0; display: none;' |
1139 | 1139 | ); |
1140 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
1140 | + $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
1141 | 1141 | $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
1142 | 1142 | $registrations_to_apply_payment_to .= EEH_HTML::thead( |
1143 | 1143 | EEH_HTML::tr( |
1144 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
1145 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
1146 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
1147 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
1148 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
1149 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
1144 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')). |
|
1145 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')). |
|
1146 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')). |
|
1147 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')). |
|
1148 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
1149 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
1150 | 1150 | EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
1151 | 1151 | ) |
1152 | 1152 | ); |
@@ -1161,29 +1161,29 @@ discard block |
||
1161 | 1161 | : esc_html__('Unknown Attendee', 'event_espresso'); |
1162 | 1162 | $owing = $registration->final_price() - $registration->paid(); |
1163 | 1163 | $taxable = $registration->ticket()->taxable() |
1164 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
1164 | + ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>' |
|
1165 | 1165 | : ''; |
1166 | 1166 | $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
1167 | 1167 | ? ' checked="checked"' |
1168 | 1168 | : ''; |
1169 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
1169 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
1170 | 1170 | $registrations_to_apply_payment_to .= EEH_HTML::tr( |
1171 | - EEH_HTML::td($registration->ID()) . |
|
1172 | - EEH_HTML::td($attendee_name) . |
|
1171 | + EEH_HTML::td($registration->ID()). |
|
1172 | + EEH_HTML::td($attendee_name). |
|
1173 | 1173 | EEH_HTML::td( |
1174 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
1175 | - ) . |
|
1176 | - EEH_HTML::td($registration->event_name()) . |
|
1177 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
1178 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
1174 | + $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable |
|
1175 | + ). |
|
1176 | + EEH_HTML::td($registration->event_name()). |
|
1177 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
1178 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
1179 | 1179 | EEH_HTML::td( |
1180 | - '<input type="checkbox" value="' . $registration->ID() |
|
1180 | + '<input type="checkbox" value="'.$registration->ID() |
|
1181 | 1181 | . '" name="txn_admin_payment[registrations]"' |
1182 | - . $checked . $disabled . '>', |
|
1182 | + . $checked.$disabled.'>', |
|
1183 | 1183 | '', |
1184 | 1184 | 'jst-cntr' |
1185 | 1185 | ), |
1186 | - 'apply-payment-registration-row-' . $registration->ID() |
|
1186 | + 'apply-payment-registration-row-'.$registration->ID() |
|
1187 | 1187 | ); |
1188 | 1188 | } |
1189 | 1189 | } |
@@ -1198,7 +1198,7 @@ discard block |
||
1198 | 1198 | '', |
1199 | 1199 | 'clear description' |
1200 | 1200 | ); |
1201 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1201 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1202 | 1202 | $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
1203 | 1203 | } |
1204 | 1204 | |
@@ -1263,12 +1263,12 @@ discard block |
||
1263 | 1263 | array( |
1264 | 1264 | 'OR*payment_method_for_payment' => array( |
1265 | 1265 | 'PMD_ID' => array('IN', $payment_methods_of_payments), |
1266 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
1266 | + 'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'), |
|
1267 | 1267 | ), |
1268 | 1268 | ), |
1269 | 1269 | ); |
1270 | 1270 | } else { |
1271 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
1271 | + $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'))); |
|
1272 | 1272 | } |
1273 | 1273 | $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
1274 | 1274 | } |
@@ -1297,7 +1297,7 @@ discard block |
||
1297 | 1297 | 'Line_Item', |
1298 | 1298 | array(array('LIN_type' => 'line-item')) |
1299 | 1299 | ); |
1300 | - if (! empty($line_items)) { |
|
1300 | + if ( ! empty($line_items)) { |
|
1301 | 1301 | foreach ($line_items as $item) { |
1302 | 1302 | if ($item instanceof EE_Line_Item) { |
1303 | 1303 | switch ($item->OBJ_type()) { |
@@ -1307,7 +1307,7 @@ discard block |
||
1307 | 1307 | $ticket = $item->ticket(); |
1308 | 1308 | //right now we're only handling tickets here. |
1309 | 1309 | //Cause its expected that only tickets will have attendees right? |
1310 | - if (! $ticket instanceof EE_Ticket) { |
|
1310 | + if ( ! $ticket instanceof EE_Ticket) { |
|
1311 | 1311 | continue; |
1312 | 1312 | } |
1313 | 1313 | try { |
@@ -1316,7 +1316,7 @@ discard block |
||
1316 | 1316 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
1317 | 1317 | $event_name = esc_html__('Unknown Event', 'event_espresso'); |
1318 | 1318 | } |
1319 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
1319 | + $event_name .= ' - '.$item->get('LIN_name'); |
|
1320 | 1320 | $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
1321 | 1321 | // now get all of the registrations for this transaction that use this ticket |
1322 | 1322 | $registrations = $ticket->get_many_related( |
@@ -1324,7 +1324,7 @@ discard block |
||
1324 | 1324 | array(array('TXN_ID' => $this->_transaction->ID())) |
1325 | 1325 | ); |
1326 | 1326 | foreach ($registrations as $registration) { |
1327 | - if (! $registration instanceof EE_Registration) { |
|
1327 | + if ( ! $registration instanceof EE_Registration) { |
|
1328 | 1328 | continue; |
1329 | 1329 | } |
1330 | 1330 | $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
@@ -1343,12 +1343,12 @@ discard block |
||
1343 | 1343 | $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
1344 | 1344 | = $attendee->full_name(); |
1345 | 1345 | $this->_template_args['event_attendees'][$registration->ID()]['email'] |
1346 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
1346 | + = '<a href="mailto:'.$attendee->email().'?subject='.$event_name |
|
1347 | 1347 | . esc_html__( |
1348 | 1348 | ' Event', |
1349 | 1349 | 'event_espresso' |
1350 | 1350 | ) |
1351 | - . '">' . $attendee->email() . '</a>'; |
|
1351 | + . '">'.$attendee->email().'</a>'; |
|
1352 | 1352 | $this->_template_args['event_attendees'][$registration->ID()]['address'] |
1353 | 1353 | = EEH_Address::format($attendee, 'inline', false, false); |
1354 | 1354 | } else { |
@@ -1372,7 +1372,7 @@ discard block |
||
1372 | 1372 | TXN_ADMIN_URL |
1373 | 1373 | ); |
1374 | 1374 | echo EEH_Template::display_template( |
1375 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
1375 | + TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php', |
|
1376 | 1376 | $this->_template_args, |
1377 | 1377 | true |
1378 | 1378 | ); |
@@ -1407,12 +1407,12 @@ discard block |
||
1407 | 1407 | $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
1408 | 1408 | ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
1409 | 1409 | : null; |
1410 | - if (! $primary_att instanceof EE_Attendee) { |
|
1410 | + if ( ! $primary_att instanceof EE_Attendee) { |
|
1411 | 1411 | $this->_template_args['no_attendee_message'] = esc_html__( |
1412 | 1412 | 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
1413 | 1413 | 'event_espresso' |
1414 | 1414 | ); |
1415 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
1415 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
1416 | 1416 | } |
1417 | 1417 | $this->_template_args['ATT_ID'] = $primary_att->ID(); |
1418 | 1418 | $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
@@ -1426,7 +1426,7 @@ discard block |
||
1426 | 1426 | // get formatted address for registrant |
1427 | 1427 | $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
1428 | 1428 | echo EEH_Template::display_template( |
1429 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
1429 | + TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php', |
|
1430 | 1430 | $this->_template_args, |
1431 | 1431 | true |
1432 | 1432 | ); |
@@ -1451,8 +1451,8 @@ discard block |
||
1451 | 1451 | TXN_ADMIN_URL |
1452 | 1452 | ); |
1453 | 1453 | |
1454 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
1455 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
1454 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
1455 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/ |
|
1456 | 1456 | } |
1457 | 1457 | |
1458 | 1458 | |
@@ -1477,7 +1477,7 @@ discard block |
||
1477 | 1477 | 'ee_edit_payments', |
1478 | 1478 | 'apply_payment_or_refund_from_registration_details' |
1479 | 1479 | ); |
1480 | - if (! empty($valid_data) && $has_access) { |
|
1480 | + if ( ! empty($valid_data) && $has_access) { |
|
1481 | 1481 | $PAY_ID = $valid_data['PAY_ID']; |
1482 | 1482 | //save the new payment |
1483 | 1483 | $payment = $this->_create_payment_from_request_data($valid_data); |
@@ -1490,7 +1490,7 @@ discard block |
||
1490 | 1490 | $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
1491 | 1491 | $this->_remove_existing_registration_payments($payment, $PAY_ID); |
1492 | 1492 | // apply payment to registrations (if applicable) |
1493 | - if (! empty($REG_IDs)) { |
|
1493 | + if ( ! empty($REG_IDs)) { |
|
1494 | 1494 | $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
1495 | 1495 | $this->_maybe_send_notifications(); |
1496 | 1496 | // now process status changes for the same registrations |
@@ -1538,7 +1538,7 @@ discard block |
||
1538 | 1538 | ); |
1539 | 1539 | } |
1540 | 1540 | } |
1541 | - $notices = EE_Error::get_notices( |
|
1541 | + $notices = EE_Error::get_notices( |
|
1542 | 1542 | false, |
1543 | 1543 | false, |
1544 | 1544 | false |
@@ -1559,14 +1559,14 @@ discard block |
||
1559 | 1559 | */ |
1560 | 1560 | protected function _validate_payment_request_data() |
1561 | 1561 | { |
1562 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
1562 | + if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
1563 | 1563 | return false; |
1564 | 1564 | } |
1565 | 1565 | $payment_form = $this->_generate_payment_form_section(); |
1566 | 1566 | try { |
1567 | 1567 | if ($payment_form->was_submitted()) { |
1568 | 1568 | $payment_form->receive_form_submission(); |
1569 | - if (! $payment_form->is_valid()) { |
|
1569 | + if ( ! $payment_form->is_valid()) { |
|
1570 | 1570 | $submission_error_messages = array(); |
1571 | 1571 | foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
1572 | 1572 | if ($validation_error instanceof EE_Validation_Error) { |
@@ -1744,7 +1744,7 @@ discard block |
||
1744 | 1744 | array('Y-m-d', 'g:i a') |
1745 | 1745 | ); |
1746 | 1746 | |
1747 | - if (! $payment->save()) { |
|
1747 | + if ( ! $payment->save()) { |
|
1748 | 1748 | EE_Error::add_error( |
1749 | 1749 | sprintf( |
1750 | 1750 | esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
@@ -1809,7 +1809,7 @@ discard block |
||
1809 | 1809 | $REG_IDs = array(); |
1810 | 1810 | // grab array of IDs for specific registrations to apply changes to |
1811 | 1811 | if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
1812 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
1812 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
1813 | 1813 | } |
1814 | 1814 | //nothing specified ? then get all reg IDs |
1815 | 1815 | if (empty($REG_IDs)) { |
@@ -1937,12 +1937,12 @@ discard block |
||
1937 | 1937 | // but add in some conditions regarding payment, |
1938 | 1938 | // so that we don't apply payments to registrations that are free or have already been paid for |
1939 | 1939 | // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
1940 | - if (! $payment->is_a_refund()) { |
|
1940 | + if ( ! $payment->is_a_refund()) { |
|
1941 | 1941 | $registration_query_where_params['REG_final_price'] = array('!=', 0); |
1942 | 1942 | $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
1943 | 1943 | } |
1944 | 1944 | $registrations = $transaction->registrations(array($registration_query_where_params)); |
1945 | - if (! empty($registrations)) { |
|
1945 | + if ( ! empty($registrations)) { |
|
1946 | 1946 | /** @type EE_Payment_Processor $payment_processor */ |
1947 | 1947 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
1948 | 1948 | $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
@@ -2142,7 +2142,7 @@ discard block |
||
2142 | 2142 | { |
2143 | 2143 | $registration_payment_data = array(); |
2144 | 2144 | //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
2145 | - if (! empty($REG_IDs)) { |
|
2145 | + if ( ! empty($REG_IDs)) { |
|
2146 | 2146 | $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
2147 | 2147 | foreach ($registrations as $registration) { |
2148 | 2148 | if ($registration instanceof EE_Registration) { |
@@ -2255,13 +2255,13 @@ discard block |
||
2255 | 2255 | 'm/d/Y', |
2256 | 2256 | strtotime('-10 year') |
2257 | 2257 | ); |
2258 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
2258 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
2259 | 2259 | ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
2260 | 2260 | : date('m/d/Y'); |
2261 | 2261 | |
2262 | 2262 | //make sure our timestamps start and end right at the boundaries for each day |
2263 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
2264 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
2263 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
2264 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
2265 | 2265 | |
2266 | 2266 | |
2267 | 2267 | //convert to timestamps |
@@ -2278,7 +2278,7 @@ discard block |
||
2278 | 2278 | date('Y-m-d H:i:s', $start_date), |
2279 | 2279 | 'Y-m-d H:i:s' |
2280 | 2280 | ); |
2281 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
2281 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
2282 | 2282 | 'TXN_timestamp', |
2283 | 2283 | date('Y-m-d H:i:s', $end_date), |
2284 | 2284 | 'Y-m-d H:i:s' |
@@ -2320,7 +2320,7 @@ discard block |
||
2320 | 2320 | } |
2321 | 2321 | |
2322 | 2322 | if (isset($this->_req_data['s'])) { |
2323 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
2323 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
2324 | 2324 | $_where['OR'] = array( |
2325 | 2325 | 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
2326 | 2326 | 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
@@ -2347,9 +2347,9 @@ discard block |
||
2347 | 2347 | } |
2348 | 2348 | |
2349 | 2349 | //failed transactions |
2350 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
2350 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
2351 | 2351 | || ($count && $view === 'failed'); |
2352 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
2352 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
2353 | 2353 | || ($count && $view === 'abandoned'); |
2354 | 2354 | |
2355 | 2355 | if ($failed) { |
@@ -16,2370 +16,2370 @@ |
||
16 | 16 | class Transactions_Admin_Page extends EE_Admin_Page |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var EE_Transaction |
|
21 | - */ |
|
22 | - private $_transaction; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var EE_Session |
|
26 | - */ |
|
27 | - private $_session; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var array $_txn_status |
|
31 | - */ |
|
32 | - private static $_txn_status; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var array $_pay_status |
|
36 | - */ |
|
37 | - private static $_pay_status; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var array $_existing_reg_payment_REG_IDs |
|
41 | - */ |
|
42 | - protected $_existing_reg_payment_REG_IDs = null; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @Constructor |
|
47 | - * @access public |
|
48 | - * @param bool $routing |
|
49 | - * @throws EE_Error |
|
50 | - * @throws InvalidArgumentException |
|
51 | - * @throws ReflectionException |
|
52 | - * @throws InvalidDataTypeException |
|
53 | - * @throws InvalidInterfaceException |
|
54 | - */ |
|
55 | - public function __construct($routing = true) |
|
56 | - { |
|
57 | - parent::__construct($routing); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * _init_page_props |
|
63 | - * |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - protected function _init_page_props() |
|
67 | - { |
|
68 | - $this->page_slug = TXN_PG_SLUG; |
|
69 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
70 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
71 | - $this->_admin_base_path = TXN_ADMIN; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * _ajax_hooks |
|
77 | - * |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - protected function _ajax_hooks() |
|
81 | - { |
|
82 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
83 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
84 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * _define_page_props |
|
90 | - * |
|
91 | - * @return void |
|
92 | - */ |
|
93 | - protected function _define_page_props() |
|
94 | - { |
|
95 | - $this->_admin_page_title = $this->page_label; |
|
96 | - $this->_labels = array( |
|
97 | - 'buttons' => array( |
|
98 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
99 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
100 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
101 | - ), |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * grab url requests and route them |
|
108 | - * |
|
109 | - * @access private |
|
110 | - * @return void |
|
111 | - * @throws EE_Error |
|
112 | - * @throws InvalidArgumentException |
|
113 | - * @throws InvalidDataTypeException |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - */ |
|
116 | - public function _set_page_routes() |
|
117 | - { |
|
118 | - |
|
119 | - $this->_set_transaction_status_array(); |
|
120 | - |
|
121 | - $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
122 | - && ! is_array($this->_req_data['TXN_ID']) |
|
123 | - ? $this->_req_data['TXN_ID'] |
|
124 | - : 0; |
|
125 | - |
|
126 | - $this->_page_routes = array( |
|
127 | - |
|
128 | - 'default' => array( |
|
129 | - 'func' => '_transactions_overview_list_table', |
|
130 | - 'capability' => 'ee_read_transactions', |
|
131 | - ), |
|
132 | - |
|
133 | - 'view_transaction' => array( |
|
134 | - 'func' => '_transaction_details', |
|
135 | - 'capability' => 'ee_read_transaction', |
|
136 | - 'obj_id' => $txn_id, |
|
137 | - ), |
|
138 | - |
|
139 | - 'send_payment_reminder' => array( |
|
140 | - 'func' => '_send_payment_reminder', |
|
141 | - 'noheader' => true, |
|
142 | - 'capability' => 'ee_send_message', |
|
143 | - ), |
|
144 | - |
|
145 | - 'espresso_apply_payment' => array( |
|
146 | - 'func' => 'apply_payments_or_refunds', |
|
147 | - 'noheader' => true, |
|
148 | - 'capability' => 'ee_edit_payments', |
|
149 | - ), |
|
150 | - |
|
151 | - 'espresso_apply_refund' => array( |
|
152 | - 'func' => 'apply_payments_or_refunds', |
|
153 | - 'noheader' => true, |
|
154 | - 'capability' => 'ee_edit_payments', |
|
155 | - ), |
|
156 | - |
|
157 | - 'espresso_delete_payment' => array( |
|
158 | - 'func' => 'delete_payment', |
|
159 | - 'noheader' => true, |
|
160 | - 'capability' => 'ee_delete_payments', |
|
161 | - ), |
|
162 | - |
|
163 | - ); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - protected function _set_page_config() |
|
168 | - { |
|
169 | - $this->_page_config = array( |
|
170 | - 'default' => array( |
|
171 | - 'nav' => array( |
|
172 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
173 | - 'order' => 10, |
|
174 | - ), |
|
175 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
176 | - 'help_tabs' => array( |
|
177 | - 'transactions_overview_help_tab' => array( |
|
178 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
179 | - 'filename' => 'transactions_overview', |
|
180 | - ), |
|
181 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
182 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
183 | - 'filename' => 'transactions_overview_table_column_headings', |
|
184 | - ), |
|
185 | - 'transactions_overview_views_filters_help_tab' => array( |
|
186 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
187 | - 'filename' => 'transactions_overview_views_filters_search', |
|
188 | - ), |
|
189 | - ), |
|
190 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
191 | - /** |
|
192 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
193 | - * may change in a later iteration so want to keep the code for then. |
|
194 | - */ |
|
195 | - //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
196 | - 'require_nonce' => false, |
|
197 | - ), |
|
198 | - 'view_transaction' => array( |
|
199 | - 'nav' => array( |
|
200 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
201 | - 'order' => 5, |
|
202 | - 'url' => isset($this->_req_data['TXN_ID']) |
|
203 | - ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
204 | - : $this->_admin_base_url, |
|
205 | - 'persistent' => false, |
|
206 | - ), |
|
207 | - 'help_tabs' => array( |
|
208 | - 'transactions_view_transaction_help_tab' => array( |
|
209 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
210 | - 'filename' => 'transactions_view_transaction', |
|
211 | - ), |
|
212 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
213 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
214 | - 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
215 | - ), |
|
216 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
217 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
218 | - 'filename' => 'transactions_view_transaction_attendees_registered', |
|
219 | - ), |
|
220 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
221 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
222 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
223 | - ), |
|
224 | - ), |
|
225 | - 'qtips' => array('Transaction_Details_Tips'), |
|
226 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
227 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
228 | - |
|
229 | - 'require_nonce' => false, |
|
230 | - ), |
|
231 | - ); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * The below methods aren't used by this class currently |
|
237 | - */ |
|
238 | - protected function _add_screen_options() |
|
239 | - { |
|
240 | - //noop |
|
241 | - } |
|
242 | - |
|
243 | - protected function _add_feature_pointers() |
|
244 | - { |
|
245 | - //noop |
|
246 | - } |
|
247 | - |
|
248 | - public function admin_init() |
|
249 | - { |
|
250 | - // IF a registration was JUST added via the admin... |
|
251 | - if (isset( |
|
252 | - $this->_req_data['redirect_from'], |
|
253 | - $this->_req_data['EVT_ID'], |
|
254 | - $this->_req_data['event_name'] |
|
255 | - )) { |
|
256 | - // then set a cookie so that we can block any attempts to use |
|
257 | - // the back button as a way to enter another registration. |
|
258 | - setcookie( |
|
259 | - 'ee_registration_added', |
|
260 | - $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/' |
|
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 | - /** |
|
342 | - * _add_screen_options_default |
|
343 | - * |
|
344 | - * @access protected |
|
345 | - * @return void |
|
346 | - * @throws InvalidArgumentException |
|
347 | - * @throws InvalidDataTypeException |
|
348 | - * @throws InvalidInterfaceException |
|
349 | - */ |
|
350 | - protected function _add_screen_options_default() |
|
351 | - { |
|
352 | - $this->_per_page_screen_option(); |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * load_scripts_styles |
|
358 | - * |
|
359 | - * @access public |
|
360 | - * @return void |
|
361 | - */ |
|
362 | - public function load_scripts_styles() |
|
363 | - { |
|
364 | - //enqueue style |
|
365 | - wp_register_style( |
|
366 | - 'espresso_txn', |
|
367 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
368 | - array(), |
|
369 | - EVENT_ESPRESSO_VERSION |
|
370 | - ); |
|
371 | - wp_enqueue_style('espresso_txn'); |
|
372 | - //scripts |
|
373 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
374 | - 'ee_admin_js', |
|
375 | - 'ee-datepicker', |
|
376 | - 'jquery-ui-datepicker', |
|
377 | - 'jquery-ui-draggable', |
|
378 | - 'ee-dialog', |
|
379 | - 'ee-accounting', |
|
380 | - 'ee-serialize-full-array', |
|
381 | - ), EVENT_ESPRESSO_VERSION, true); |
|
382 | - wp_enqueue_script('espresso_txn'); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - /** |
|
387 | - * load_scripts_styles_view_transaction |
|
388 | - * |
|
389 | - * @access public |
|
390 | - * @return void |
|
391 | - */ |
|
392 | - public function load_scripts_styles_view_transaction() |
|
393 | - { |
|
394 | - //styles |
|
395 | - wp_enqueue_style('espresso-ui-theme'); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * load_scripts_styles_default |
|
401 | - * |
|
402 | - * @access public |
|
403 | - * @return void |
|
404 | - */ |
|
405 | - public function load_scripts_styles_default() |
|
406 | - { |
|
407 | - //styles |
|
408 | - wp_enqueue_style('espresso-ui-theme'); |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * _set_list_table_views_default |
|
414 | - * |
|
415 | - * @access protected |
|
416 | - * @return void |
|
417 | - */ |
|
418 | - protected function _set_list_table_views_default() |
|
419 | - { |
|
420 | - $this->_views = array( |
|
421 | - 'all' => array( |
|
422 | - 'slug' => 'all', |
|
423 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
424 | - 'count' => 0, |
|
425 | - ), |
|
426 | - 'abandoned' => array( |
|
427 | - 'slug' => 'abandoned', |
|
428 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
429 | - 'count' => 0, |
|
430 | - ), |
|
431 | - 'failed' => array( |
|
432 | - 'slug' => 'failed', |
|
433 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
434 | - 'count' => 0, |
|
435 | - ), |
|
436 | - ); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * _set_transaction_object |
|
442 | - * This sets the _transaction property for the transaction details screen |
|
443 | - * |
|
444 | - * @access private |
|
445 | - * @return void |
|
446 | - * @throws EE_Error |
|
447 | - * @throws InvalidArgumentException |
|
448 | - * @throws RuntimeException |
|
449 | - * @throws InvalidDataTypeException |
|
450 | - * @throws InvalidInterfaceException |
|
451 | - */ |
|
452 | - private function _set_transaction_object() |
|
453 | - { |
|
454 | - if ($this->_transaction instanceof EE_Transaction) { |
|
455 | - return; |
|
456 | - } //get out we've already set the object |
|
457 | - |
|
458 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
459 | - ? absint($this->_req_data['TXN_ID']) |
|
460 | - : false; |
|
461 | - |
|
462 | - //get transaction object |
|
463 | - $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
464 | - $this->_session = $this->_transaction instanceof EE_Transaction |
|
465 | - ? $this->_transaction->get('TXN_session_data') |
|
466 | - : null; |
|
467 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
468 | - |
|
469 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
470 | - $error_msg = sprintf( |
|
471 | - esc_html__( |
|
472 | - 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
473 | - 'event_espresso' |
|
474 | - ), |
|
475 | - $TXN_ID |
|
476 | - ); |
|
477 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
478 | - } |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * _transaction_legend_items |
|
484 | - * |
|
485 | - * @access protected |
|
486 | - * @return array |
|
487 | - * @throws EE_Error |
|
488 | - * @throws InvalidArgumentException |
|
489 | - * @throws ReflectionException |
|
490 | - * @throws InvalidDataTypeException |
|
491 | - * @throws InvalidInterfaceException |
|
492 | - */ |
|
493 | - protected function _transaction_legend_items() |
|
494 | - { |
|
495 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
496 | - $items = array(); |
|
497 | - |
|
498 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
499 | - 'ee_read_global_messages', |
|
500 | - 'view_filtered_messages' |
|
501 | - )) { |
|
502 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
503 | - if (is_array($related_for_icon) |
|
504 | - && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
505 | - ) { |
|
506 | - $items['view_related_messages'] = array( |
|
507 | - 'class' => $related_for_icon['css_class'], |
|
508 | - 'desc' => $related_for_icon['label'], |
|
509 | - ); |
|
510 | - } |
|
511 | - } |
|
512 | - |
|
513 | - $items = apply_filters( |
|
514 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
515 | - array_merge( |
|
516 | - $items, |
|
517 | - array( |
|
518 | - 'view_details' => array( |
|
519 | - 'class' => 'dashicons dashicons-cart', |
|
520 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
521 | - ), |
|
522 | - 'view_invoice' => array( |
|
523 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
524 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
525 | - ), |
|
526 | - 'view_receipt' => array( |
|
527 | - 'class' => 'dashicons dashicons-media-default', |
|
528 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
529 | - ), |
|
530 | - 'view_registration' => array( |
|
531 | - 'class' => 'dashicons dashicons-clipboard', |
|
532 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
533 | - ), |
|
534 | - 'payment_overview_link' => array( |
|
535 | - 'class' => 'dashicons dashicons-money', |
|
536 | - 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
537 | - ), |
|
538 | - ) |
|
539 | - ) |
|
540 | - ); |
|
541 | - |
|
542 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
543 | - 'ee_send_message', |
|
544 | - 'espresso_transactions_send_payment_reminder' |
|
545 | - )) { |
|
546 | - if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
547 | - $items['send_payment_reminder'] = array( |
|
548 | - 'class' => 'dashicons dashicons-email-alt', |
|
549 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
550 | - ); |
|
551 | - } else { |
|
552 | - $items['blank*'] = array( |
|
553 | - 'class' => '', |
|
554 | - 'desc' => '', |
|
555 | - ); |
|
556 | - } |
|
557 | - } else { |
|
558 | - $items['blank*'] = array( |
|
559 | - 'class' => '', |
|
560 | - 'desc' => '', |
|
561 | - ); |
|
562 | - } |
|
563 | - $more_items = apply_filters( |
|
564 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
565 | - array( |
|
566 | - 'overpaid' => array( |
|
567 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
568 | - 'desc' => EEH_Template::pretty_status( |
|
569 | - EEM_Transaction::overpaid_status_code, |
|
570 | - false, |
|
571 | - 'sentence' |
|
572 | - ), |
|
573 | - ), |
|
574 | - 'complete' => array( |
|
575 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
576 | - 'desc' => EEH_Template::pretty_status( |
|
577 | - EEM_Transaction::complete_status_code, |
|
578 | - false, |
|
579 | - 'sentence' |
|
580 | - ), |
|
581 | - ), |
|
582 | - 'incomplete' => array( |
|
583 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
584 | - 'desc' => EEH_Template::pretty_status( |
|
585 | - EEM_Transaction::incomplete_status_code, |
|
586 | - false, |
|
587 | - 'sentence' |
|
588 | - ), |
|
589 | - ), |
|
590 | - 'abandoned' => array( |
|
591 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
592 | - 'desc' => EEH_Template::pretty_status( |
|
593 | - EEM_Transaction::abandoned_status_code, |
|
594 | - false, |
|
595 | - 'sentence' |
|
596 | - ), |
|
597 | - ), |
|
598 | - 'failed' => array( |
|
599 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
600 | - 'desc' => EEH_Template::pretty_status( |
|
601 | - EEM_Transaction::failed_status_code, |
|
602 | - false, |
|
603 | - 'sentence' |
|
604 | - ), |
|
605 | - ), |
|
606 | - ) |
|
607 | - ); |
|
608 | - |
|
609 | - return array_merge($items, $more_items); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * _transactions_overview_list_table |
|
615 | - * |
|
616 | - * @access protected |
|
617 | - * @return void |
|
618 | - * @throws DomainException |
|
619 | - * @throws EE_Error |
|
620 | - * @throws InvalidArgumentException |
|
621 | - * @throws InvalidDataTypeException |
|
622 | - * @throws InvalidInterfaceException |
|
623 | - * @throws ReflectionException |
|
624 | - */ |
|
625 | - protected function _transactions_overview_list_table() |
|
626 | - { |
|
627 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
628 | - $event = isset($this->_req_data['EVT_ID']) |
|
629 | - ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
630 | - : null; |
|
631 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
632 | - ? sprintf( |
|
633 | - esc_html__( |
|
634 | - '%sViewing Transactions for the Event: %s%s', |
|
635 | - 'event_espresso' |
|
636 | - ), |
|
637 | - '<h3>', |
|
638 | - '<a href="' |
|
639 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
640 | - array('action' => 'edit', 'post' => $event->ID()), |
|
641 | - EVENTS_ADMIN_URL |
|
642 | - ) |
|
643 | - . '" title="' |
|
644 | - . esc_attr__( |
|
645 | - 'Click to Edit event', |
|
646 | - 'event_espresso' |
|
647 | - ) |
|
648 | - . '">' . $event->get('EVT_name') . '</a>', |
|
649 | - '</h3>' |
|
650 | - ) |
|
651 | - : ''; |
|
652 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
653 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
654 | - } |
|
655 | - |
|
656 | - |
|
657 | - /** |
|
658 | - * _transaction_details |
|
659 | - * generates HTML for the View Transaction Details Admin page |
|
660 | - * |
|
661 | - * @access protected |
|
662 | - * @return void |
|
663 | - * @throws DomainException |
|
664 | - * @throws EE_Error |
|
665 | - * @throws InvalidArgumentException |
|
666 | - * @throws InvalidDataTypeException |
|
667 | - * @throws InvalidInterfaceException |
|
668 | - * @throws RuntimeException |
|
669 | - */ |
|
670 | - protected function _transaction_details() |
|
671 | - { |
|
672 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
673 | - |
|
674 | - $this->_set_transaction_status_array(); |
|
675 | - |
|
676 | - $this->_template_args = array(); |
|
677 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
678 | - |
|
679 | - $this->_set_transaction_object(); |
|
680 | - |
|
681 | - $primary_registration = $this->_transaction->primary_registration(); |
|
682 | - $attendee = $primary_registration instanceof EE_Registration |
|
683 | - ? $primary_registration->attendee() |
|
684 | - : null; |
|
685 | - |
|
686 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
687 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
688 | - |
|
689 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
690 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
691 | - |
|
692 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
693 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
694 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
695 | - |
|
696 | - $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
697 | - $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
698 | - |
|
699 | - if ($attendee instanceof EE_Attendee |
|
700 | - && EE_Registry::instance()->CAP->current_user_can( |
|
701 | - 'ee_send_message', |
|
702 | - 'espresso_transactions_send_payment_reminder' |
|
703 | - ) |
|
704 | - ) { |
|
705 | - $this->_template_args['send_payment_reminder_button'] = |
|
706 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
707 | - && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code |
|
708 | - && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code |
|
709 | - ? EEH_Template::get_button_or_link( |
|
710 | - EE_Admin_Page::add_query_args_and_nonce( |
|
711 | - array( |
|
712 | - 'action' => 'send_payment_reminder', |
|
713 | - 'TXN_ID' => $this->_transaction->ID(), |
|
714 | - 'redirect_to' => 'view_transaction', |
|
715 | - ), |
|
716 | - TXN_ADMIN_URL |
|
717 | - ), |
|
718 | - __(' Send Payment Reminder', 'event_espresso'), |
|
719 | - 'button secondary-button right', |
|
720 | - 'dashicons dashicons-email-alt' |
|
721 | - ) |
|
722 | - : ''; |
|
723 | - } else { |
|
724 | - $this->_template_args['send_payment_reminder_button'] = ''; |
|
725 | - } |
|
726 | - |
|
727 | - $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
728 | - $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
729 | - $amount_due, |
|
730 | - true |
|
731 | - ); |
|
732 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
733 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
734 | - . $this->_template_args['amount_due']; |
|
735 | - } else { |
|
736 | - $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
737 | - } |
|
738 | - $this->_template_args['amount_due_class'] = ''; |
|
739 | - |
|
740 | - if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
741 | - // paid in full |
|
742 | - $this->_template_args['amount_due'] = false; |
|
743 | - } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
744 | - // overpaid |
|
745 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
746 | - } elseif ($this->_transaction->get('TXN_total') > 0 |
|
747 | - && $this->_transaction->get('TXN_paid') > 0 |
|
748 | - ) { |
|
749 | - // monies owing |
|
750 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
751 | - } elseif ($this->_transaction->get('TXN_total') > 0 |
|
752 | - && $this->_transaction->get('TXN_paid') == 0 |
|
753 | - ) { |
|
754 | - // no payments made yet |
|
755 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
756 | - } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
757 | - // free event |
|
758 | - $this->_template_args['amount_due'] = false; |
|
759 | - } |
|
760 | - |
|
761 | - $payment_method = $this->_transaction->payment_method(); |
|
762 | - |
|
763 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
764 | - ? $payment_method->admin_name() |
|
765 | - : esc_html__('Unknown', 'event_espresso'); |
|
766 | - |
|
767 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
768 | - // link back to overview |
|
769 | - $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
770 | - ? $_SERVER['HTTP_REFERER'] |
|
771 | - : TXN_ADMIN_URL; |
|
772 | - |
|
773 | - |
|
774 | - // next link |
|
775 | - $next_txn = $this->_transaction->next( |
|
776 | - null, |
|
777 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
778 | - 'TXN_ID' |
|
779 | - ); |
|
780 | - $this->_template_args['next_transaction'] = $next_txn |
|
781 | - ? $this->_next_link( |
|
782 | - EE_Admin_Page::add_query_args_and_nonce( |
|
783 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
784 | - TXN_ADMIN_URL |
|
785 | - ), |
|
786 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
787 | - ) |
|
788 | - : ''; |
|
789 | - // previous link |
|
790 | - $previous_txn = $this->_transaction->previous( |
|
791 | - null, |
|
792 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
793 | - 'TXN_ID' |
|
794 | - ); |
|
795 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
796 | - ? $this->_previous_link( |
|
797 | - EE_Admin_Page::add_query_args_and_nonce( |
|
798 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
799 | - TXN_ADMIN_URL |
|
800 | - ), |
|
801 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
802 | - ) |
|
803 | - : ''; |
|
804 | - |
|
805 | - // were we just redirected here after adding a new registration ??? |
|
806 | - if (isset( |
|
807 | - $this->_req_data['redirect_from'], |
|
808 | - $this->_req_data['EVT_ID'], |
|
809 | - $this->_req_data['event_name'] |
|
810 | - )) { |
|
811 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
812 | - 'ee_edit_registrations', |
|
813 | - 'espresso_registrations_new_registration', |
|
814 | - $this->_req_data['EVT_ID'] |
|
815 | - )) { |
|
816 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
817 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
818 | - array( |
|
819 | - 'page' => 'espresso_registrations', |
|
820 | - 'action' => 'new_registration', |
|
821 | - 'return' => 'default', |
|
822 | - 'TXN_ID' => $this->_transaction->ID(), |
|
823 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
824 | - ), |
|
825 | - REG_ADMIN_URL |
|
826 | - ); |
|
827 | - $this->_admin_page_title .= '">'; |
|
828 | - |
|
829 | - $this->_admin_page_title .= sprintf( |
|
830 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
831 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
832 | - ); |
|
833 | - $this->_admin_page_title .= '</a>'; |
|
834 | - } |
|
835 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
836 | - } |
|
837 | - // grab messages at the last second |
|
838 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
839 | - // path to template |
|
840 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
841 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
842 | - $template_path, |
|
843 | - $this->_template_args, |
|
844 | - true |
|
845 | - ); |
|
846 | - |
|
847 | - // the details template wrapper |
|
848 | - $this->display_admin_page_with_sidebar(); |
|
849 | - |
|
850 | - } |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * _transaction_details_metaboxes |
|
855 | - * |
|
856 | - * @access protected |
|
857 | - * @return void |
|
858 | - * @throws EE_Error |
|
859 | - * @throws InvalidArgumentException |
|
860 | - * @throws InvalidDataTypeException |
|
861 | - * @throws InvalidInterfaceException |
|
862 | - * @throws RuntimeException |
|
863 | - */ |
|
864 | - protected function _transaction_details_metaboxes() |
|
865 | - { |
|
866 | - |
|
867 | - $this->_set_transaction_object(); |
|
868 | - |
|
869 | - add_meta_box( |
|
870 | - 'edit-txn-details-mbox', |
|
871 | - esc_html__('Transaction Details', 'event_espresso'), |
|
872 | - array($this, 'txn_details_meta_box'), |
|
873 | - $this->_wp_page_slug, |
|
874 | - 'normal', |
|
875 | - 'high' |
|
876 | - ); |
|
877 | - add_meta_box( |
|
878 | - 'edit-txn-attendees-mbox', |
|
879 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
880 | - array($this, 'txn_attendees_meta_box'), |
|
881 | - $this->_wp_page_slug, |
|
882 | - 'normal', |
|
883 | - 'high', |
|
884 | - array('TXN_ID' => $this->_transaction->ID()) |
|
885 | - ); |
|
886 | - add_meta_box( |
|
887 | - 'edit-txn-registrant-mbox', |
|
888 | - esc_html__('Primary Contact', 'event_espresso'), |
|
889 | - array($this, 'txn_registrant_side_meta_box'), |
|
890 | - $this->_wp_page_slug, |
|
891 | - 'side', |
|
892 | - 'high' |
|
893 | - ); |
|
894 | - add_meta_box( |
|
895 | - 'edit-txn-billing-info-mbox', |
|
896 | - esc_html__('Billing Information', 'event_espresso'), |
|
897 | - array($this, 'txn_billing_info_side_meta_box'), |
|
898 | - $this->_wp_page_slug, |
|
899 | - 'side', |
|
900 | - 'high' |
|
901 | - ); |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * txn_details_meta_box |
|
907 | - * generates HTML for the Transaction main meta box |
|
908 | - * |
|
909 | - * @access public |
|
910 | - * @return void |
|
911 | - * @throws DomainException |
|
912 | - * @throws EE_Error |
|
913 | - * @throws InvalidArgumentException |
|
914 | - * @throws InvalidDataTypeException |
|
915 | - * @throws InvalidInterfaceException |
|
916 | - * @throws RuntimeException |
|
917 | - */ |
|
918 | - public function txn_details_meta_box() |
|
919 | - { |
|
920 | - |
|
921 | - $this->_set_transaction_object(); |
|
922 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
923 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
924 | - ? $this->_transaction->primary_registration()->attendee() |
|
925 | - : null; |
|
926 | - $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
927 | - 'ee_edit_payments', |
|
928 | - 'apply_payment_or_refund_from_registration_details' |
|
929 | - ); |
|
930 | - $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
931 | - 'ee_delete_payments', |
|
932 | - 'delete_payment_from_registration_details' |
|
933 | - ); |
|
934 | - |
|
935 | - //get line table |
|
936 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
937 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
938 | - 'admin_table', |
|
939 | - 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
940 | - ); |
|
941 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
942 | - $this->_transaction->total_line_item() |
|
943 | - ); |
|
944 | - $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration') |
|
945 | - ->get('REG_code'); |
|
946 | - |
|
947 | - // process taxes |
|
948 | - $taxes = $this->_transaction->get_many_related( |
|
949 | - 'Line_Item', |
|
950 | - array(array('LIN_type' => EEM_Line_Item::type_tax)) |
|
951 | - ); |
|
952 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
953 | - |
|
954 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
955 | - $this->_transaction->get('TXN_total'), |
|
956 | - false, |
|
957 | - false |
|
958 | - ); |
|
959 | - $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
960 | - $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
961 | - |
|
962 | - // process payment details |
|
963 | - $payments = $this->_transaction->get_many_related('Payment'); |
|
964 | - if (! empty($payments)) { |
|
965 | - $this->_template_args['payments'] = $payments; |
|
966 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
967 | - } else { |
|
968 | - $this->_template_args['payments'] = false; |
|
969 | - $this->_template_args['existing_reg_payments'] = array(); |
|
970 | - } |
|
971 | - |
|
972 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
973 | - $this->_template_args['delete_payment_url'] = add_query_arg( |
|
974 | - array('action' => 'espresso_delete_payment'), |
|
975 | - TXN_ADMIN_URL |
|
976 | - ); |
|
977 | - |
|
978 | - if (isset($txn_details['invoice_number'])) { |
|
979 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
980 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
981 | - 'Invoice Number', |
|
982 | - 'event_espresso' |
|
983 | - ); |
|
984 | - } |
|
985 | - |
|
986 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
987 | - ->get_first_related('Registration') |
|
988 | - ->get('REG_session'); |
|
989 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
990 | - 'Registration Session', |
|
991 | - 'event_espresso' |
|
992 | - ); |
|
993 | - |
|
994 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
995 | - ? $this->_session['ip_address'] |
|
996 | - : ''; |
|
997 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
998 | - 'Transaction placed from IP', |
|
999 | - 'event_espresso' |
|
1000 | - ); |
|
1001 | - |
|
1002 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
1003 | - ? $this->_session['user_agent'] |
|
1004 | - : ''; |
|
1005 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
1006 | - 'Registrant User Agent', |
|
1007 | - 'event_espresso' |
|
1008 | - ); |
|
1009 | - |
|
1010 | - $reg_steps = '<ul>'; |
|
1011 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
1012 | - if ($reg_step_status === true) { |
|
1013 | - $reg_steps .= '<li style="color:#70cc50">' |
|
1014 | - . sprintf( |
|
1015 | - esc_html__('%1$s : Completed', 'event_espresso'), |
|
1016 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
1017 | - ) |
|
1018 | - . '</li>'; |
|
1019 | - } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
1020 | - $reg_steps .= '<li style="color:#2EA2CC">' |
|
1021 | - . sprintf( |
|
1022 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
1023 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
1024 | - date( |
|
1025 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
1026 | - ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
1027 | - ) |
|
1028 | - ) |
|
1029 | - . '</li>'; |
|
1030 | - } else { |
|
1031 | - $reg_steps .= '<li style="color:#E76700">' |
|
1032 | - . sprintf( |
|
1033 | - esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
1034 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
1035 | - ) |
|
1036 | - . '</li>'; |
|
1037 | - } |
|
1038 | - } |
|
1039 | - $reg_steps .= '</ul>'; |
|
1040 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
1041 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
1042 | - 'Registration Step Progress', |
|
1043 | - 'event_espresso' |
|
1044 | - ); |
|
1045 | - |
|
1046 | - |
|
1047 | - $this->_get_registrations_to_apply_payment_to(); |
|
1048 | - $this->_get_payment_methods($payments); |
|
1049 | - $this->_get_payment_status_array(); |
|
1050 | - $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
1051 | - |
|
1052 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
1053 | - 'action' => 'edit_transaction', |
|
1054 | - 'process' => 'transaction', |
|
1055 | - ), TXN_ADMIN_URL); |
|
1056 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
1057 | - 'page' => 'espresso_transactions', |
|
1058 | - 'action' => 'espresso_apply_payment', |
|
1059 | - ), WP_AJAX_URL); |
|
1060 | - $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
1061 | - 'page' => 'espresso_transactions', |
|
1062 | - 'action' => 'espresso_delete_payment', |
|
1063 | - ), WP_AJAX_URL); |
|
1064 | - |
|
1065 | - // 'espresso_delete_payment_nonce' |
|
1066 | - |
|
1067 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
1068 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
1069 | - } |
|
1070 | - |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * _get_registration_payment_IDs |
|
1074 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
1075 | - * |
|
1076 | - * @access protected |
|
1077 | - * @param EE_Payment[] $payments |
|
1078 | - * @return array |
|
1079 | - * @throws EE_Error |
|
1080 | - * @throws InvalidArgumentException |
|
1081 | - * @throws InvalidDataTypeException |
|
1082 | - * @throws InvalidInterfaceException |
|
1083 | - */ |
|
1084 | - protected function _get_registration_payment_IDs($payments = array()) |
|
1085 | - { |
|
1086 | - $existing_reg_payments = array(); |
|
1087 | - // get all reg payments for these payments |
|
1088 | - $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
1089 | - array( |
|
1090 | - 'PAY_ID' => array( |
|
1091 | - 'IN', |
|
1092 | - array_keys($payments), |
|
1093 | - ), |
|
1094 | - ), |
|
1095 | - )); |
|
1096 | - if (! empty($reg_payments)) { |
|
1097 | - foreach ($payments as $payment) { |
|
1098 | - if (! $payment instanceof EE_Payment) { |
|
1099 | - continue; |
|
1100 | - } elseif (! isset($existing_reg_payments[$payment->ID()])) { |
|
1101 | - $existing_reg_payments[$payment->ID()] = array(); |
|
1102 | - } |
|
1103 | - foreach ($reg_payments as $reg_payment) { |
|
1104 | - if ($reg_payment instanceof EE_Registration_Payment |
|
1105 | - && $reg_payment->payment_ID() === $payment->ID() |
|
1106 | - ) { |
|
1107 | - $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
1108 | - } |
|
1109 | - } |
|
1110 | - } |
|
1111 | - } |
|
1112 | - |
|
1113 | - return $existing_reg_payments; |
|
1114 | - } |
|
1115 | - |
|
1116 | - |
|
1117 | - /** |
|
1118 | - * _get_registrations_to_apply_payment_to |
|
1119 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
1120 | - * which allows the admin to only apply the payment to the specific registrations |
|
1121 | - * |
|
1122 | - * @access protected |
|
1123 | - * @return void |
|
1124 | - * @throws \EE_Error |
|
1125 | - */ |
|
1126 | - protected function _get_registrations_to_apply_payment_to() |
|
1127 | - { |
|
1128 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
1129 | - $query_params = array( |
|
1130 | - array( |
|
1131 | - 'STS_ID' => array( |
|
1132 | - 'IN', |
|
1133 | - array( |
|
1134 | - EEM_Registration::status_id_approved, |
|
1135 | - EEM_Registration::status_id_pending_payment, |
|
1136 | - EEM_Registration::status_id_not_approved, |
|
1137 | - ), |
|
1138 | - ), |
|
1139 | - ), |
|
1140 | - ); |
|
1141 | - $registrations_to_apply_payment_to = EEH_HTML::br() |
|
1142 | - . EEH_HTML::div( |
|
1143 | - '', |
|
1144 | - 'txn-admin-apply-payment-to-registrations-dv', |
|
1145 | - '', |
|
1146 | - 'clear: both; margin: 1.5em 0 0; display: none;' |
|
1147 | - ); |
|
1148 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
1149 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
1150 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
1151 | - EEH_HTML::tr( |
|
1152 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
1153 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
1154 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
1155 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
1156 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
1157 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
1158 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
1159 | - ) |
|
1160 | - ); |
|
1161 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
1162 | - // get registrations for TXN |
|
1163 | - $registrations = $this->_transaction->registrations($query_params); |
|
1164 | - $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
1165 | - foreach ($registrations as $registration) { |
|
1166 | - if ($registration instanceof EE_Registration) { |
|
1167 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
1168 | - ? $registration->attendee()->full_name() |
|
1169 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
1170 | - $owing = $registration->final_price() - $registration->paid(); |
|
1171 | - $taxable = $registration->ticket()->taxable() |
|
1172 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
1173 | - : ''; |
|
1174 | - $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
1175 | - ? ' checked="checked"' |
|
1176 | - : ''; |
|
1177 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
1178 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
1179 | - EEH_HTML::td($registration->ID()) . |
|
1180 | - EEH_HTML::td($attendee_name) . |
|
1181 | - EEH_HTML::td( |
|
1182 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
1183 | - ) . |
|
1184 | - EEH_HTML::td($registration->event_name()) . |
|
1185 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
1186 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
1187 | - EEH_HTML::td( |
|
1188 | - '<input type="checkbox" value="' . $registration->ID() |
|
1189 | - . '" name="txn_admin_payment[registrations]"' |
|
1190 | - . $checked . $disabled . '>', |
|
1191 | - '', |
|
1192 | - 'jst-cntr' |
|
1193 | - ), |
|
1194 | - 'apply-payment-registration-row-' . $registration->ID() |
|
1195 | - ); |
|
1196 | - } |
|
1197 | - } |
|
1198 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
1199 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
1200 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1201 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
1202 | - esc_html__( |
|
1203 | - '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.', |
|
1204 | - 'event_espresso' |
|
1205 | - ), |
|
1206 | - '', |
|
1207 | - 'clear description' |
|
1208 | - ); |
|
1209 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1210 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
1211 | - } |
|
1212 | - |
|
1213 | - |
|
1214 | - /** |
|
1215 | - * _get_reg_status_selection |
|
1216 | - * |
|
1217 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
1218 | - * instead of events. |
|
1219 | - * @access protected |
|
1220 | - * @return void |
|
1221 | - * @throws EE_Error |
|
1222 | - */ |
|
1223 | - protected function _get_reg_status_selection() |
|
1224 | - { |
|
1225 | - //first get all possible statuses |
|
1226 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
1227 | - //let's add a "don't change" option. |
|
1228 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
1229 | - $status_array = array_merge($status_array, $statuses); |
|
1230 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
1231 | - 'txn_reg_status_change[reg_status]', |
|
1232 | - $status_array, |
|
1233 | - 'NAN', |
|
1234 | - 'id="txn-admin-payment-reg-status-inp"', |
|
1235 | - 'txn-reg-status-change-reg-status' |
|
1236 | - ); |
|
1237 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
1238 | - 'delete_txn_reg_status_change[reg_status]', |
|
1239 | - $status_array, |
|
1240 | - 'NAN', |
|
1241 | - 'delete-txn-admin-payment-reg-status-inp', |
|
1242 | - 'delete-txn-reg-status-change-reg-status' |
|
1243 | - ); |
|
1244 | - } |
|
1245 | - |
|
1246 | - |
|
1247 | - /** |
|
1248 | - * _get_payment_methods |
|
1249 | - * Gets all the payment methods available generally, or the ones that are already |
|
1250 | - * selected on these payments (in case their payment methods are no longer active). |
|
1251 | - * Has the side-effect of updating the template args' payment_methods item |
|
1252 | - * |
|
1253 | - * @access private |
|
1254 | - * @param EE_Payment[] to show on this page |
|
1255 | - * @return void |
|
1256 | - * @throws EE_Error |
|
1257 | - * @throws InvalidArgumentException |
|
1258 | - * @throws InvalidDataTypeException |
|
1259 | - * @throws InvalidInterfaceException |
|
1260 | - */ |
|
1261 | - private function _get_payment_methods($payments = array()) |
|
1262 | - { |
|
1263 | - $payment_methods_of_payments = array(); |
|
1264 | - foreach ($payments as $payment) { |
|
1265 | - if ($payment instanceof EE_Payment) { |
|
1266 | - $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
1267 | - } |
|
1268 | - } |
|
1269 | - if ($payment_methods_of_payments) { |
|
1270 | - $query_args = array( |
|
1271 | - array( |
|
1272 | - 'OR*payment_method_for_payment' => array( |
|
1273 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
1274 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
1275 | - ), |
|
1276 | - ), |
|
1277 | - ); |
|
1278 | - } else { |
|
1279 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
1280 | - } |
|
1281 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
1282 | - } |
|
1283 | - |
|
1284 | - |
|
1285 | - /** |
|
1286 | - * txn_attendees_meta_box |
|
1287 | - * generates HTML for the Attendees Transaction main meta box |
|
1288 | - * |
|
1289 | - * @access public |
|
1290 | - * @param WP_Post $post |
|
1291 | - * @param array $metabox |
|
1292 | - * @return void |
|
1293 | - * @throws DomainException |
|
1294 | - * @throws EE_Error |
|
1295 | - */ |
|
1296 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
1297 | - { |
|
1298 | - |
|
1299 | - /** @noinspection NonSecureExtractUsageInspection */ |
|
1300 | - extract($metabox['args']); |
|
1301 | - $this->_template_args['post'] = $post; |
|
1302 | - $this->_template_args['event_attendees'] = array(); |
|
1303 | - // process items in cart |
|
1304 | - $line_items = $this->_transaction->get_many_related( |
|
1305 | - 'Line_Item', |
|
1306 | - array(array('LIN_type' => 'line-item')) |
|
1307 | - ); |
|
1308 | - if (! empty($line_items)) { |
|
1309 | - foreach ($line_items as $item) { |
|
1310 | - if ($item instanceof EE_Line_Item) { |
|
1311 | - switch ($item->OBJ_type()) { |
|
1312 | - case 'Event': |
|
1313 | - break; |
|
1314 | - case 'Ticket': |
|
1315 | - $ticket = $item->ticket(); |
|
1316 | - //right now we're only handling tickets here. |
|
1317 | - //Cause its expected that only tickets will have attendees right? |
|
1318 | - if (! $ticket instanceof EE_Ticket) { |
|
1319 | - continue; |
|
1320 | - } |
|
1321 | - try { |
|
1322 | - $event_name = $ticket->get_event_name(); |
|
1323 | - } catch (Exception $e) { |
|
1324 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1325 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
1326 | - } |
|
1327 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
1328 | - $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
1329 | - // now get all of the registrations for this transaction that use this ticket |
|
1330 | - $registrations = $ticket->get_many_related( |
|
1331 | - 'Registration', |
|
1332 | - array(array('TXN_ID' => $this->_transaction->ID())) |
|
1333 | - ); |
|
1334 | - foreach ($registrations as $registration) { |
|
1335 | - if (! $registration instanceof EE_Registration) { |
|
1336 | - continue; |
|
1337 | - } |
|
1338 | - $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
|
1339 | - = $registration->status_ID(); |
|
1340 | - $this->_template_args['event_attendees'][$registration->ID()]['att_num'] |
|
1341 | - = $registration->count(); |
|
1342 | - $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] |
|
1343 | - = $event_name; |
|
1344 | - $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] |
|
1345 | - = $ticket_price; |
|
1346 | - // attendee info |
|
1347 | - $attendee = $registration->get_first_related('Attendee'); |
|
1348 | - if ($attendee instanceof EE_Attendee) { |
|
1349 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] |
|
1350 | - = $attendee->ID(); |
|
1351 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
|
1352 | - = $attendee->full_name(); |
|
1353 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] |
|
1354 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
1355 | - . esc_html__( |
|
1356 | - ' Event', |
|
1357 | - 'event_espresso' |
|
1358 | - ) |
|
1359 | - . '">' . $attendee->email() . '</a>'; |
|
1360 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] |
|
1361 | - = EEH_Address::format($attendee, 'inline', false, false); |
|
1362 | - } else { |
|
1363 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
1364 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
1365 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
1366 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
1367 | - } |
|
1368 | - } |
|
1369 | - break; |
|
1370 | - |
|
1371 | - } |
|
1372 | - } |
|
1373 | - } |
|
1374 | - |
|
1375 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
1376 | - array( |
|
1377 | - 'action' => 'edit_transaction', |
|
1378 | - 'process' => 'attendees', |
|
1379 | - ), |
|
1380 | - TXN_ADMIN_URL |
|
1381 | - ); |
|
1382 | - echo EEH_Template::display_template( |
|
1383 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
1384 | - $this->_template_args, |
|
1385 | - true |
|
1386 | - ); |
|
1387 | - |
|
1388 | - } else { |
|
1389 | - echo sprintf( |
|
1390 | - esc_html__( |
|
1391 | - '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
1392 | - 'event_espresso' |
|
1393 | - ), |
|
1394 | - '<p class="important-notice">', |
|
1395 | - '</p>' |
|
1396 | - ); |
|
1397 | - } |
|
1398 | - } |
|
1399 | - |
|
1400 | - |
|
1401 | - /** |
|
1402 | - * txn_registrant_side_meta_box |
|
1403 | - * generates HTML for the Edit Transaction side meta box |
|
1404 | - * |
|
1405 | - * @access public |
|
1406 | - * @return void |
|
1407 | - * @throws DomainException |
|
1408 | - * @throws EE_Error |
|
1409 | - * @throws InvalidArgumentException |
|
1410 | - * @throws InvalidDataTypeException |
|
1411 | - * @throws InvalidInterfaceException |
|
1412 | - */ |
|
1413 | - public function txn_registrant_side_meta_box() |
|
1414 | - { |
|
1415 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
1416 | - ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
1417 | - : null; |
|
1418 | - if (! $primary_att instanceof EE_Attendee) { |
|
1419 | - $this->_template_args['no_attendee_message'] = esc_html__( |
|
1420 | - 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
1421 | - 'event_espresso' |
|
1422 | - ); |
|
1423 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
1424 | - } |
|
1425 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
1426 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
1427 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
1428 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
1429 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
1430 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1431 | - 'action' => 'edit_attendee', |
|
1432 | - 'post' => $primary_att->ID(), |
|
1433 | - ), REG_ADMIN_URL); |
|
1434 | - // get formatted address for registrant |
|
1435 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
1436 | - echo EEH_Template::display_template( |
|
1437 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
1438 | - $this->_template_args, |
|
1439 | - true |
|
1440 | - ); |
|
1441 | - } |
|
1442 | - |
|
1443 | - |
|
1444 | - /** |
|
1445 | - * txn_billing_info_side_meta_box |
|
1446 | - * generates HTML for the Edit Transaction side meta box |
|
1447 | - * |
|
1448 | - * @access public |
|
1449 | - * @return void |
|
1450 | - * @throws DomainException |
|
1451 | - * @throws EE_Error |
|
1452 | - */ |
|
1453 | - public function txn_billing_info_side_meta_box() |
|
1454 | - { |
|
1455 | - |
|
1456 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
1457 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
1458 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
1459 | - TXN_ADMIN_URL |
|
1460 | - ); |
|
1461 | - |
|
1462 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
1463 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
1464 | - } |
|
1465 | - |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * apply_payments_or_refunds |
|
1469 | - * registers a payment or refund made towards a transaction |
|
1470 | - * |
|
1471 | - * @access public |
|
1472 | - * @return void |
|
1473 | - * @throws EE_Error |
|
1474 | - * @throws InvalidArgumentException |
|
1475 | - * @throws ReflectionException |
|
1476 | - * @throws RuntimeException |
|
1477 | - * @throws InvalidDataTypeException |
|
1478 | - * @throws InvalidInterfaceException |
|
1479 | - */ |
|
1480 | - public function apply_payments_or_refunds() |
|
1481 | - { |
|
1482 | - $json_response_data = array('return_data' => false); |
|
1483 | - $valid_data = $this->_validate_payment_request_data(); |
|
1484 | - $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
1485 | - 'ee_edit_payments', |
|
1486 | - 'apply_payment_or_refund_from_registration_details' |
|
1487 | - ); |
|
1488 | - if (! empty($valid_data) && $has_access) { |
|
1489 | - $PAY_ID = $valid_data['PAY_ID']; |
|
1490 | - //save the new payment |
|
1491 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
1492 | - // get the TXN for this payment |
|
1493 | - $transaction = $payment->transaction(); |
|
1494 | - // verify transaction |
|
1495 | - if ($transaction instanceof EE_Transaction) { |
|
1496 | - // calculate_total_payments_and_update_status |
|
1497 | - $this->_process_transaction_payments($transaction); |
|
1498 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
1499 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
1500 | - // apply payment to registrations (if applicable) |
|
1501 | - if (! empty($REG_IDs)) { |
|
1502 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
1503 | - $this->_maybe_send_notifications(); |
|
1504 | - // now process status changes for the same registrations |
|
1505 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
1506 | - } |
|
1507 | - $this->_maybe_send_notifications($payment); |
|
1508 | - //prepare to render page |
|
1509 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
1510 | - do_action( |
|
1511 | - 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
1512 | - $transaction, |
|
1513 | - $payment |
|
1514 | - ); |
|
1515 | - } else { |
|
1516 | - EE_Error::add_error( |
|
1517 | - esc_html__( |
|
1518 | - 'A valid Transaction for this payment could not be retrieved.', |
|
1519 | - 'event_espresso' |
|
1520 | - ), |
|
1521 | - __FILE__, |
|
1522 | - __FUNCTION__, |
|
1523 | - __LINE__ |
|
1524 | - ); |
|
1525 | - } |
|
1526 | - } else { |
|
1527 | - if ($has_access) { |
|
1528 | - EE_Error::add_error( |
|
1529 | - esc_html__( |
|
1530 | - 'The payment form data could not be processed. Please try again.', |
|
1531 | - 'event_espresso' |
|
1532 | - ), |
|
1533 | - __FILE__, |
|
1534 | - __FUNCTION__, |
|
1535 | - __LINE__ |
|
1536 | - ); |
|
1537 | - } else { |
|
1538 | - EE_Error::add_error( |
|
1539 | - esc_html__( |
|
1540 | - 'You do not have access to apply payments or refunds to a registration.', |
|
1541 | - 'event_espresso' |
|
1542 | - ), |
|
1543 | - __FILE__, |
|
1544 | - __FUNCTION__, |
|
1545 | - __LINE__ |
|
1546 | - ); |
|
1547 | - } |
|
1548 | - } |
|
1549 | - $notices = EE_Error::get_notices( |
|
1550 | - false, |
|
1551 | - false, |
|
1552 | - false |
|
1553 | - ); |
|
1554 | - $this->_template_args = array( |
|
1555 | - 'data' => $json_response_data, |
|
1556 | - 'error' => $notices['errors'], |
|
1557 | - 'success' => $notices['success'], |
|
1558 | - ); |
|
1559 | - $this->_return_json(); |
|
1560 | - } |
|
1561 | - |
|
1562 | - |
|
1563 | - /** |
|
1564 | - * _validate_payment_request_data |
|
1565 | - * |
|
1566 | - * @return array |
|
1567 | - */ |
|
1568 | - protected function _validate_payment_request_data() |
|
1569 | - { |
|
1570 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
1571 | - return false; |
|
1572 | - } |
|
1573 | - $payment_form = $this->_generate_payment_form_section(); |
|
1574 | - try { |
|
1575 | - if ($payment_form->was_submitted()) { |
|
1576 | - $payment_form->receive_form_submission(); |
|
1577 | - if (! $payment_form->is_valid()) { |
|
1578 | - $submission_error_messages = array(); |
|
1579 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
1580 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1581 | - $submission_error_messages[] = sprintf( |
|
1582 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
1583 | - $validation_error->get_form_section()->html_label_text(), |
|
1584 | - $validation_error->getMessage() |
|
1585 | - ); |
|
1586 | - } |
|
1587 | - } |
|
1588 | - EE_Error::add_error( |
|
1589 | - implode('<br />', $submission_error_messages), |
|
1590 | - __FILE__, |
|
1591 | - __FUNCTION__, |
|
1592 | - __LINE__ |
|
1593 | - ); |
|
1594 | - |
|
1595 | - return array(); |
|
1596 | - } |
|
1597 | - } |
|
1598 | - } catch (EE_Error $e) { |
|
1599 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1600 | - |
|
1601 | - return array(); |
|
1602 | - } |
|
1603 | - |
|
1604 | - return $payment_form->valid_data(); |
|
1605 | - } |
|
1606 | - |
|
1607 | - |
|
1608 | - /** |
|
1609 | - * _generate_payment_form_section |
|
1610 | - * |
|
1611 | - * @return EE_Form_Section_Proper |
|
1612 | - */ |
|
1613 | - protected function _generate_payment_form_section() |
|
1614 | - { |
|
1615 | - return new EE_Form_Section_Proper( |
|
1616 | - array( |
|
1617 | - 'name' => 'txn_admin_payment', |
|
1618 | - 'subsections' => array( |
|
1619 | - 'PAY_ID' => new EE_Text_Input( |
|
1620 | - array( |
|
1621 | - 'default' => 0, |
|
1622 | - 'required' => false, |
|
1623 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
1624 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1625 | - ) |
|
1626 | - ), |
|
1627 | - 'TXN_ID' => new EE_Text_Input( |
|
1628 | - array( |
|
1629 | - 'default' => 0, |
|
1630 | - 'required' => true, |
|
1631 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
1632 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1633 | - ) |
|
1634 | - ), |
|
1635 | - 'type' => new EE_Text_Input( |
|
1636 | - array( |
|
1637 | - 'default' => 1, |
|
1638 | - 'required' => true, |
|
1639 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
1640 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1641 | - ) |
|
1642 | - ), |
|
1643 | - 'amount' => new EE_Text_Input( |
|
1644 | - array( |
|
1645 | - 'default' => 0, |
|
1646 | - 'required' => true, |
|
1647 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
1648 | - 'validation_strategies' => array(new EE_Float_Normalization()), |
|
1649 | - ) |
|
1650 | - ), |
|
1651 | - 'status' => new EE_Text_Input( |
|
1652 | - array( |
|
1653 | - 'default' => EEM_Payment::status_id_approved, |
|
1654 | - 'required' => true, |
|
1655 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
1656 | - ) |
|
1657 | - ), |
|
1658 | - 'PMD_ID' => new EE_Text_Input( |
|
1659 | - array( |
|
1660 | - 'default' => 2, |
|
1661 | - 'required' => true, |
|
1662 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
1663 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1664 | - ) |
|
1665 | - ), |
|
1666 | - 'date' => new EE_Text_Input( |
|
1667 | - array( |
|
1668 | - 'default' => time(), |
|
1669 | - 'required' => true, |
|
1670 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
1671 | - ) |
|
1672 | - ), |
|
1673 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
1674 | - array( |
|
1675 | - 'default' => '', |
|
1676 | - 'required' => false, |
|
1677 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
1678 | - 'validation_strategies' => array( |
|
1679 | - new EE_Max_Length_Validation_Strategy( |
|
1680 | - esc_html__('Input too long', 'event_espresso'), |
|
1681 | - 100 |
|
1682 | - ), |
|
1683 | - ), |
|
1684 | - ) |
|
1685 | - ), |
|
1686 | - 'po_number' => new EE_Text_Input( |
|
1687 | - array( |
|
1688 | - 'default' => '', |
|
1689 | - 'required' => false, |
|
1690 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
1691 | - 'validation_strategies' => array( |
|
1692 | - new EE_Max_Length_Validation_Strategy( |
|
1693 | - esc_html__('Input too long', 'event_espresso'), |
|
1694 | - 100 |
|
1695 | - ), |
|
1696 | - ), |
|
1697 | - ) |
|
1698 | - ), |
|
1699 | - 'accounting' => new EE_Text_Input( |
|
1700 | - array( |
|
1701 | - 'default' => '', |
|
1702 | - 'required' => false, |
|
1703 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
1704 | - 'validation_strategies' => array( |
|
1705 | - new EE_Max_Length_Validation_Strategy( |
|
1706 | - esc_html__('Input too long', 'event_espresso'), |
|
1707 | - 100 |
|
1708 | - ), |
|
1709 | - ), |
|
1710 | - ) |
|
1711 | - ), |
|
1712 | - ), |
|
1713 | - ) |
|
1714 | - ); |
|
1715 | - } |
|
1716 | - |
|
1717 | - |
|
1718 | - /** |
|
1719 | - * _create_payment_from_request_data |
|
1720 | - * |
|
1721 | - * @param array $valid_data |
|
1722 | - * @return EE_Payment |
|
1723 | - * @throws EE_Error |
|
1724 | - */ |
|
1725 | - protected function _create_payment_from_request_data($valid_data) |
|
1726 | - { |
|
1727 | - $PAY_ID = $valid_data['PAY_ID']; |
|
1728 | - // get payment amount |
|
1729 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
1730 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
1731 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
1732 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
1733 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
1734 | - $date = $valid_data['date'] |
|
1735 | - ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
1736 | - : date('Y-m-d g:i a', current_time('timestamp')); |
|
1737 | - $payment = EE_Payment::new_instance( |
|
1738 | - array( |
|
1739 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
1740 | - 'STS_ID' => $valid_data['status'], |
|
1741 | - 'PAY_timestamp' => $date, |
|
1742 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
1743 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
1744 | - 'PAY_amount' => $amount, |
|
1745 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
1746 | - 'PAY_po_number' => $valid_data['po_number'], |
|
1747 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
1748 | - 'PAY_details' => $valid_data, |
|
1749 | - 'PAY_ID' => $PAY_ID, |
|
1750 | - ), |
|
1751 | - '', |
|
1752 | - array('Y-m-d', 'g:i a') |
|
1753 | - ); |
|
1754 | - |
|
1755 | - if (! $payment->save()) { |
|
1756 | - EE_Error::add_error( |
|
1757 | - sprintf( |
|
1758 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
1759 | - $payment->ID() |
|
1760 | - ), |
|
1761 | - __FILE__, __FUNCTION__, __LINE__ |
|
1762 | - ); |
|
1763 | - } |
|
1764 | - |
|
1765 | - return $payment; |
|
1766 | - } |
|
1767 | - |
|
1768 | - |
|
1769 | - /** |
|
1770 | - * _process_transaction_payments |
|
1771 | - * |
|
1772 | - * @param \EE_Transaction $transaction |
|
1773 | - * @return void |
|
1774 | - * @throws EE_Error |
|
1775 | - * @throws InvalidArgumentException |
|
1776 | - * @throws ReflectionException |
|
1777 | - * @throws InvalidDataTypeException |
|
1778 | - * @throws InvalidInterfaceException |
|
1779 | - */ |
|
1780 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
1781 | - { |
|
1782 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
1783 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1784 | - //update the transaction with this payment |
|
1785 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
1786 | - EE_Error::add_success(esc_html__( |
|
1787 | - 'The payment has been processed successfully.', 'event_espresso'), |
|
1788 | - __FILE__, |
|
1789 | - __FUNCTION__, |
|
1790 | - __LINE__ |
|
1791 | - ); |
|
1792 | - } else { |
|
1793 | - EE_Error::add_error( |
|
1794 | - esc_html__( |
|
1795 | - 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
1796 | - 'event_espresso' |
|
1797 | - ) |
|
1798 | - , |
|
1799 | - __FILE__, |
|
1800 | - __FUNCTION__, |
|
1801 | - __LINE__ |
|
1802 | - ); |
|
1803 | - } |
|
1804 | - } |
|
1805 | - |
|
1806 | - |
|
1807 | - /** |
|
1808 | - * _get_REG_IDs_to_apply_payment_to |
|
1809 | - * returns a list of registration IDs that the payment will apply to |
|
1810 | - * |
|
1811 | - * @param \EE_Payment $payment |
|
1812 | - * @return array |
|
1813 | - * @throws EE_Error |
|
1814 | - */ |
|
1815 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
1816 | - { |
|
1817 | - $REG_IDs = array(); |
|
1818 | - // grab array of IDs for specific registrations to apply changes to |
|
1819 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
1820 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
1821 | - } |
|
1822 | - //nothing specified ? then get all reg IDs |
|
1823 | - if (empty($REG_IDs)) { |
|
1824 | - $registrations = $payment->transaction()->registrations(); |
|
1825 | - $REG_IDs = ! empty($registrations) |
|
1826 | - ? array_keys($registrations) |
|
1827 | - : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1828 | - } |
|
1829 | - |
|
1830 | - // ensure that REG_IDs are integers and NOT strings |
|
1831 | - return array_map('intval', $REG_IDs); |
|
1832 | - } |
|
1833 | - |
|
1834 | - |
|
1835 | - /** |
|
1836 | - * @return array |
|
1837 | - */ |
|
1838 | - public function existing_reg_payment_REG_IDs() |
|
1839 | - { |
|
1840 | - return $this->_existing_reg_payment_REG_IDs; |
|
1841 | - } |
|
1842 | - |
|
1843 | - |
|
1844 | - /** |
|
1845 | - * @param array $existing_reg_payment_REG_IDs |
|
1846 | - */ |
|
1847 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
1848 | - { |
|
1849 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
1850 | - } |
|
1851 | - |
|
1852 | - |
|
1853 | - /** |
|
1854 | - * _get_existing_reg_payment_REG_IDs |
|
1855 | - * returns a list of registration IDs that the payment is currently related to |
|
1856 | - * as recorded in the database |
|
1857 | - * |
|
1858 | - * @param \EE_Payment $payment |
|
1859 | - * @return array |
|
1860 | - * @throws EE_Error |
|
1861 | - */ |
|
1862 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
1863 | - { |
|
1864 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
1865 | - // let's get any existing reg payment records for this payment |
|
1866 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
1867 | - // but we only want the REG IDs, so grab the array keys |
|
1868 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
1869 | - ? array_keys($existing_reg_payment_REG_IDs) |
|
1870 | - : array(); |
|
1871 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
1872 | - } |
|
1873 | - |
|
1874 | - return $this->existing_reg_payment_REG_IDs(); |
|
1875 | - } |
|
1876 | - |
|
1877 | - |
|
1878 | - /** |
|
1879 | - * _remove_existing_registration_payments |
|
1880 | - * this calculates the difference between existing relations |
|
1881 | - * to the supplied payment and the new list registration IDs, |
|
1882 | - * removes any related registrations that no longer apply, |
|
1883 | - * and then updates the registration paid fields |
|
1884 | - * |
|
1885 | - * @param \EE_Payment $payment |
|
1886 | - * @param int $PAY_ID |
|
1887 | - * @return bool; |
|
1888 | - * @throws EE_Error |
|
1889 | - * @throws InvalidArgumentException |
|
1890 | - * @throws ReflectionException |
|
1891 | - * @throws InvalidDataTypeException |
|
1892 | - * @throws InvalidInterfaceException |
|
1893 | - */ |
|
1894 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
1895 | - { |
|
1896 | - // newly created payments will have nothing recorded for $PAY_ID |
|
1897 | - if ($PAY_ID == 0) { |
|
1898 | - return false; |
|
1899 | - } |
|
1900 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1901 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
1902 | - return false; |
|
1903 | - } |
|
1904 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
1905 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1906 | - |
|
1907 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
1908 | - $payment, |
|
1909 | - array( |
|
1910 | - array( |
|
1911 | - 'PAY_ID' => $payment->ID(), |
|
1912 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
1913 | - ), |
|
1914 | - ) |
|
1915 | - ); |
|
1916 | - } |
|
1917 | - |
|
1918 | - |
|
1919 | - /** |
|
1920 | - * _update_registration_payments |
|
1921 | - * this applies the payments to the selected registrations |
|
1922 | - * but only if they have not already been paid for |
|
1923 | - * |
|
1924 | - * @param EE_Transaction $transaction |
|
1925 | - * @param \EE_Payment $payment |
|
1926 | - * @param array $REG_IDs |
|
1927 | - * @return void |
|
1928 | - * @throws EE_Error |
|
1929 | - * @throws InvalidArgumentException |
|
1930 | - * @throws ReflectionException |
|
1931 | - * @throws RuntimeException |
|
1932 | - * @throws InvalidDataTypeException |
|
1933 | - * @throws InvalidInterfaceException |
|
1934 | - */ |
|
1935 | - protected function _update_registration_payments( |
|
1936 | - EE_Transaction $transaction, |
|
1937 | - EE_Payment $payment, |
|
1938 | - $REG_IDs = array() |
|
1939 | - ) { |
|
1940 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
1941 | - // so let's do that using our set of REG_IDs from the form |
|
1942 | - $registration_query_where_params = array( |
|
1943 | - 'REG_ID' => array('IN', $REG_IDs), |
|
1944 | - ); |
|
1945 | - // but add in some conditions regarding payment, |
|
1946 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
1947 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
1948 | - if (! $payment->is_a_refund()) { |
|
1949 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
1950 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
1951 | - } |
|
1952 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
1953 | - if (! empty($registrations)) { |
|
1954 | - /** @type EE_Payment_Processor $payment_processor */ |
|
1955 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
1956 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
1957 | - } |
|
1958 | - } |
|
1959 | - |
|
1960 | - |
|
1961 | - /** |
|
1962 | - * _process_registration_status_change |
|
1963 | - * This processes requested registration status changes for all the registrations |
|
1964 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
1965 | - * |
|
1966 | - * @param EE_Transaction $transaction |
|
1967 | - * @param array $REG_IDs |
|
1968 | - * @return bool |
|
1969 | - * @throws EE_Error |
|
1970 | - * @throws InvalidArgumentException |
|
1971 | - * @throws ReflectionException |
|
1972 | - * @throws InvalidDataTypeException |
|
1973 | - * @throws InvalidInterfaceException |
|
1974 | - */ |
|
1975 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
1976 | - { |
|
1977 | - // first if there is no change in status then we get out. |
|
1978 | - if ( |
|
1979 | - ! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
1980 | - || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
1981 | - ) { |
|
1982 | - //no error message, no change requested, just nothing to do man. |
|
1983 | - return false; |
|
1984 | - } |
|
1985 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
1986 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1987 | - |
|
1988 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
1989 | - return $transaction_processor->manually_update_registration_statuses( |
|
1990 | - $transaction, |
|
1991 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
1992 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
1993 | - ); |
|
1994 | - } |
|
1995 | - |
|
1996 | - |
|
1997 | - /** |
|
1998 | - * _build_payment_json_response |
|
1999 | - * |
|
2000 | - * @access public |
|
2001 | - * @param \EE_Payment $payment |
|
2002 | - * @param array $REG_IDs |
|
2003 | - * @param bool | null $delete_txn_reg_status_change |
|
2004 | - * @return array |
|
2005 | - * @throws EE_Error |
|
2006 | - * @throws InvalidArgumentException |
|
2007 | - * @throws InvalidDataTypeException |
|
2008 | - * @throws InvalidInterfaceException |
|
2009 | - */ |
|
2010 | - protected function _build_payment_json_response( |
|
2011 | - EE_Payment $payment, |
|
2012 | - $REG_IDs = array(), |
|
2013 | - $delete_txn_reg_status_change = null |
|
2014 | - ) { |
|
2015 | - // was the payment deleted ? |
|
2016 | - if (is_bool($delete_txn_reg_status_change)) { |
|
2017 | - return array( |
|
2018 | - 'PAY_ID' => $payment->ID(), |
|
2019 | - 'amount' => $payment->amount(), |
|
2020 | - 'total_paid' => $payment->transaction()->paid(), |
|
2021 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
2022 | - 'pay_status' => $payment->STS_ID(), |
|
2023 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
2024 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
2025 | - ); |
|
2026 | - } else { |
|
2027 | - $this->_get_payment_status_array(); |
|
2028 | - |
|
2029 | - return array( |
|
2030 | - 'amount' => $payment->amount(), |
|
2031 | - 'total_paid' => $payment->transaction()->paid(), |
|
2032 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
2033 | - 'pay_status' => $payment->STS_ID(), |
|
2034 | - 'PAY_ID' => $payment->ID(), |
|
2035 | - 'STS_ID' => $payment->STS_ID(), |
|
2036 | - 'status' => self::$_pay_status[$payment->STS_ID()], |
|
2037 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
2038 | - 'method' => strtoupper($payment->source()), |
|
2039 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
2040 | - 'gateway' => $payment->payment_method() |
|
2041 | - ? $payment->payment_method()->admin_name() |
|
2042 | - : esc_html__("Unknown", 'event_espresso'), |
|
2043 | - 'gateway_response' => $payment->gateway_response(), |
|
2044 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
2045 | - 'po_number' => $payment->po_number(), |
|
2046 | - 'extra_accntng' => $payment->extra_accntng(), |
|
2047 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
2048 | - ); |
|
2049 | - } |
|
2050 | - } |
|
2051 | - |
|
2052 | - |
|
2053 | - /** |
|
2054 | - * delete_payment |
|
2055 | - * delete a payment or refund made towards a transaction |
|
2056 | - * |
|
2057 | - * @access public |
|
2058 | - * @return void |
|
2059 | - * @throws EE_Error |
|
2060 | - * @throws InvalidArgumentException |
|
2061 | - * @throws ReflectionException |
|
2062 | - * @throws InvalidDataTypeException |
|
2063 | - * @throws InvalidInterfaceException |
|
2064 | - */ |
|
2065 | - public function delete_payment() |
|
2066 | - { |
|
2067 | - $json_response_data = array('return_data' => false); |
|
2068 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
2069 | - ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
2070 | - : 0; |
|
2071 | - $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
2072 | - 'ee_delete_payments', |
|
2073 | - 'delete_payment_from_registration_details' |
|
2074 | - ); |
|
2075 | - if ($PAY_ID && $can_delete) { |
|
2076 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
2077 | - ? $this->_req_data['delete_txn_reg_status_change'] |
|
2078 | - : false; |
|
2079 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
2080 | - if ($payment instanceof EE_Payment) { |
|
2081 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
2082 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
2083 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
2084 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
2085 | - $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
2086 | - $payment, |
|
2087 | - $REG_IDs, |
|
2088 | - $delete_txn_reg_status_change |
|
2089 | - ); |
|
2090 | - if ($delete_txn_reg_status_change) { |
|
2091 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
2092 | - //MAKE sure we also add the delete_txn_req_status_change to the |
|
2093 | - //$_REQUEST global because that's how messages will be looking for it. |
|
2094 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
2095 | - $this->_maybe_send_notifications(); |
|
2096 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
2097 | - } |
|
2098 | - } |
|
2099 | - } else { |
|
2100 | - EE_Error::add_error( |
|
2101 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
2102 | - __FILE__, __FUNCTION__, __LINE__ |
|
2103 | - ); |
|
2104 | - } |
|
2105 | - } else { |
|
2106 | - if ($can_delete) { |
|
2107 | - EE_Error::add_error( |
|
2108 | - esc_html__( |
|
2109 | - 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
2110 | - 'event_espresso' |
|
2111 | - ), |
|
2112 | - __FILE__, __FUNCTION__, __LINE__ |
|
2113 | - ); |
|
2114 | - } else { |
|
2115 | - EE_Error::add_error( |
|
2116 | - esc_html__( |
|
2117 | - 'You do not have access to delete a payment.', |
|
2118 | - 'event_espresso' |
|
2119 | - ), |
|
2120 | - __FILE__, |
|
2121 | - __FUNCTION__, |
|
2122 | - __LINE__ |
|
2123 | - ); |
|
2124 | - } |
|
2125 | - } |
|
2126 | - $notices = EE_Error::get_notices(false, false, false); |
|
2127 | - $this->_template_args = array( |
|
2128 | - 'data' => $json_response_data, |
|
2129 | - 'success' => $notices['success'], |
|
2130 | - 'error' => $notices['errors'], |
|
2131 | - 'attention' => $notices['attention'], |
|
2132 | - ); |
|
2133 | - $this->_return_json(); |
|
2134 | - } |
|
2135 | - |
|
2136 | - |
|
2137 | - /** |
|
2138 | - * _registration_payment_data_array |
|
2139 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
2140 | - * |
|
2141 | - * @access protected |
|
2142 | - * @param array $REG_IDs |
|
2143 | - * @return array |
|
2144 | - * @throws EE_Error |
|
2145 | - * @throws InvalidArgumentException |
|
2146 | - * @throws InvalidDataTypeException |
|
2147 | - * @throws InvalidInterfaceException |
|
2148 | - */ |
|
2149 | - protected function _registration_payment_data_array($REG_IDs) |
|
2150 | - { |
|
2151 | - $registration_payment_data = array(); |
|
2152 | - //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
2153 | - if (! empty($REG_IDs)) { |
|
2154 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
2155 | - foreach ($registrations as $registration) { |
|
2156 | - if ($registration instanceof EE_Registration) { |
|
2157 | - $registration_payment_data[$registration->ID()] = array( |
|
2158 | - 'paid' => $registration->pretty_paid(), |
|
2159 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
2160 | - ); |
|
2161 | - } |
|
2162 | - } |
|
2163 | - } |
|
2164 | - |
|
2165 | - return $registration_payment_data; |
|
2166 | - } |
|
2167 | - |
|
2168 | - |
|
2169 | - /** |
|
2170 | - * _maybe_send_notifications |
|
2171 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
2172 | - * If so, will toggle a filter switch for delivering registration notices. |
|
2173 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
2174 | - * |
|
2175 | - * @access protected |
|
2176 | - * @param \EE_Payment | null $payment |
|
2177 | - */ |
|
2178 | - protected function _maybe_send_notifications($payment = null) |
|
2179 | - { |
|
2180 | - switch ($payment instanceof EE_Payment) { |
|
2181 | - // payment notifications |
|
2182 | - case true : |
|
2183 | - if ( |
|
2184 | - isset( |
|
2185 | - $this->_req_data['txn_payments'], |
|
2186 | - $this->_req_data['txn_payments']['send_notifications'] |
|
2187 | - ) && |
|
2188 | - filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
2189 | - ) { |
|
2190 | - $this->_process_payment_notification($payment); |
|
2191 | - } |
|
2192 | - break; |
|
2193 | - // registration notifications |
|
2194 | - case false : |
|
2195 | - if ( |
|
2196 | - isset( |
|
2197 | - $this->_req_data['txn_reg_status_change'], |
|
2198 | - $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
2199 | - ) && |
|
2200 | - filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
2201 | - ) { |
|
2202 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
2203 | - } |
|
2204 | - break; |
|
2205 | - } |
|
2206 | - } |
|
2207 | - |
|
2208 | - |
|
2209 | - /** |
|
2210 | - * _send_payment_reminder |
|
2211 | - * generates HTML for the View Transaction Details Admin page |
|
2212 | - * |
|
2213 | - * @access protected |
|
2214 | - * @return void |
|
2215 | - * @throws EE_Error |
|
2216 | - * @throws InvalidArgumentException |
|
2217 | - * @throws InvalidDataTypeException |
|
2218 | - * @throws InvalidInterfaceException |
|
2219 | - */ |
|
2220 | - protected function _send_payment_reminder() |
|
2221 | - { |
|
2222 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
2223 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2224 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
2225 | - 'action' => $this->_req_data['redirect_to'], |
|
2226 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
2227 | - ) : array(); |
|
2228 | - do_action( |
|
2229 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
2230 | - $transaction |
|
2231 | - ); |
|
2232 | - $this->_redirect_after_action( |
|
2233 | - false, |
|
2234 | - esc_html__('payment reminder', 'event_espresso'), |
|
2235 | - esc_html__('sent', 'event_espresso'), |
|
2236 | - $query_args, |
|
2237 | - true |
|
2238 | - ); |
|
2239 | - } |
|
2240 | - |
|
2241 | - |
|
2242 | - /** |
|
2243 | - * get_transactions |
|
2244 | - * get transactions for given parameters (used by list table) |
|
2245 | - * |
|
2246 | - * @param int $perpage how many transactions displayed per page |
|
2247 | - * @param boolean $count return the count or objects |
|
2248 | - * @param string $view |
|
2249 | - * @return mixed int = count || array of transaction objects |
|
2250 | - * @throws EE_Error |
|
2251 | - * @throws InvalidArgumentException |
|
2252 | - * @throws InvalidDataTypeException |
|
2253 | - * @throws InvalidInterfaceException |
|
2254 | - */ |
|
2255 | - public function get_transactions($perpage, $count = false, $view = '') |
|
2256 | - { |
|
2257 | - |
|
2258 | - $TXN = EEM_Transaction::instance(); |
|
2259 | - |
|
2260 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
2261 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
2262 | - : date( |
|
2263 | - 'm/d/Y', |
|
2264 | - strtotime('-10 year') |
|
2265 | - ); |
|
2266 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
2267 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
2268 | - : date('m/d/Y'); |
|
2269 | - |
|
2270 | - //make sure our timestamps start and end right at the boundaries for each day |
|
2271 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
2272 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
2273 | - |
|
2274 | - |
|
2275 | - //convert to timestamps |
|
2276 | - $start_date = strtotime($start_date); |
|
2277 | - $end_date = strtotime($end_date); |
|
2278 | - |
|
2279 | - //makes sure start date is the lowest value and vice versa |
|
2280 | - $start_date = min($start_date, $end_date); |
|
2281 | - $end_date = max($start_date, $end_date); |
|
2282 | - |
|
2283 | - //convert to correct format for query |
|
2284 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
2285 | - 'TXN_timestamp', |
|
2286 | - date('Y-m-d H:i:s', $start_date), |
|
2287 | - 'Y-m-d H:i:s' |
|
2288 | - ); |
|
2289 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
2290 | - 'TXN_timestamp', |
|
2291 | - date('Y-m-d H:i:s', $end_date), |
|
2292 | - 'Y-m-d H:i:s' |
|
2293 | - ); |
|
2294 | - |
|
2295 | - |
|
2296 | - //set orderby |
|
2297 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
2298 | - |
|
2299 | - switch ($this->_req_data['orderby']) { |
|
2300 | - case 'TXN_ID': |
|
2301 | - $orderby = 'TXN_ID'; |
|
2302 | - break; |
|
2303 | - case 'ATT_fname': |
|
2304 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
2305 | - break; |
|
2306 | - case 'event_name': |
|
2307 | - $orderby = 'Registration.Event.EVT_name'; |
|
2308 | - break; |
|
2309 | - default: //'TXN_timestamp' |
|
2310 | - $orderby = 'TXN_timestamp'; |
|
2311 | - } |
|
2312 | - |
|
2313 | - $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2314 | - $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
2315 | - $per_page = ! empty($perpage) ? $perpage : 10; |
|
2316 | - $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
2317 | - |
|
2318 | - $offset = ($current_page - 1) * $per_page; |
|
2319 | - $limit = array($offset, $per_page); |
|
2320 | - |
|
2321 | - $_where = array( |
|
2322 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
2323 | - 'Registration.REG_count' => 1, |
|
2324 | - ); |
|
2325 | - |
|
2326 | - if (isset($this->_req_data['EVT_ID'])) { |
|
2327 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
2328 | - } |
|
2329 | - |
|
2330 | - if (isset($this->_req_data['s'])) { |
|
2331 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
2332 | - $_where['OR'] = array( |
|
2333 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
2334 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
2335 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
2336 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
2337 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
2338 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
2339 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
2340 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
2341 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
2342 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
2343 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
2344 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
2345 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
2346 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
2347 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
2348 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
2349 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
2350 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
2351 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
2352 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
2353 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
2354 | - ); |
|
2355 | - } |
|
2356 | - |
|
2357 | - //failed transactions |
|
2358 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
2359 | - || ($count && $view === 'failed'); |
|
2360 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
2361 | - || ($count && $view === 'abandoned'); |
|
2362 | - |
|
2363 | - if ($failed) { |
|
2364 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
2365 | - } else if ($abandoned) { |
|
2366 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
2367 | - } else { |
|
2368 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
2369 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
2370 | - } |
|
2371 | - |
|
2372 | - $query_params = array( |
|
2373 | - $_where, |
|
2374 | - 'order_by' => array($orderby => $sort), |
|
2375 | - 'limit' => $limit, |
|
2376 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
2377 | - ); |
|
2378 | - |
|
2379 | - $transactions = $count |
|
2380 | - ? $TXN->count(array($_where), 'TXN_ID', true) |
|
2381 | - : $TXN->get_all($query_params); |
|
2382 | - |
|
2383 | - return $transactions; |
|
2384 | - } |
|
19 | + /** |
|
20 | + * @var EE_Transaction |
|
21 | + */ |
|
22 | + private $_transaction; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var EE_Session |
|
26 | + */ |
|
27 | + private $_session; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var array $_txn_status |
|
31 | + */ |
|
32 | + private static $_txn_status; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var array $_pay_status |
|
36 | + */ |
|
37 | + private static $_pay_status; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var array $_existing_reg_payment_REG_IDs |
|
41 | + */ |
|
42 | + protected $_existing_reg_payment_REG_IDs = null; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @Constructor |
|
47 | + * @access public |
|
48 | + * @param bool $routing |
|
49 | + * @throws EE_Error |
|
50 | + * @throws InvalidArgumentException |
|
51 | + * @throws ReflectionException |
|
52 | + * @throws InvalidDataTypeException |
|
53 | + * @throws InvalidInterfaceException |
|
54 | + */ |
|
55 | + public function __construct($routing = true) |
|
56 | + { |
|
57 | + parent::__construct($routing); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * _init_page_props |
|
63 | + * |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + protected function _init_page_props() |
|
67 | + { |
|
68 | + $this->page_slug = TXN_PG_SLUG; |
|
69 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
70 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
71 | + $this->_admin_base_path = TXN_ADMIN; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * _ajax_hooks |
|
77 | + * |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + protected function _ajax_hooks() |
|
81 | + { |
|
82 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
83 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
84 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * _define_page_props |
|
90 | + * |
|
91 | + * @return void |
|
92 | + */ |
|
93 | + protected function _define_page_props() |
|
94 | + { |
|
95 | + $this->_admin_page_title = $this->page_label; |
|
96 | + $this->_labels = array( |
|
97 | + 'buttons' => array( |
|
98 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
99 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
100 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
101 | + ), |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * grab url requests and route them |
|
108 | + * |
|
109 | + * @access private |
|
110 | + * @return void |
|
111 | + * @throws EE_Error |
|
112 | + * @throws InvalidArgumentException |
|
113 | + * @throws InvalidDataTypeException |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + */ |
|
116 | + public function _set_page_routes() |
|
117 | + { |
|
118 | + |
|
119 | + $this->_set_transaction_status_array(); |
|
120 | + |
|
121 | + $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
122 | + && ! is_array($this->_req_data['TXN_ID']) |
|
123 | + ? $this->_req_data['TXN_ID'] |
|
124 | + : 0; |
|
125 | + |
|
126 | + $this->_page_routes = array( |
|
127 | + |
|
128 | + 'default' => array( |
|
129 | + 'func' => '_transactions_overview_list_table', |
|
130 | + 'capability' => 'ee_read_transactions', |
|
131 | + ), |
|
132 | + |
|
133 | + 'view_transaction' => array( |
|
134 | + 'func' => '_transaction_details', |
|
135 | + 'capability' => 'ee_read_transaction', |
|
136 | + 'obj_id' => $txn_id, |
|
137 | + ), |
|
138 | + |
|
139 | + 'send_payment_reminder' => array( |
|
140 | + 'func' => '_send_payment_reminder', |
|
141 | + 'noheader' => true, |
|
142 | + 'capability' => 'ee_send_message', |
|
143 | + ), |
|
144 | + |
|
145 | + 'espresso_apply_payment' => array( |
|
146 | + 'func' => 'apply_payments_or_refunds', |
|
147 | + 'noheader' => true, |
|
148 | + 'capability' => 'ee_edit_payments', |
|
149 | + ), |
|
150 | + |
|
151 | + 'espresso_apply_refund' => array( |
|
152 | + 'func' => 'apply_payments_or_refunds', |
|
153 | + 'noheader' => true, |
|
154 | + 'capability' => 'ee_edit_payments', |
|
155 | + ), |
|
156 | + |
|
157 | + 'espresso_delete_payment' => array( |
|
158 | + 'func' => 'delete_payment', |
|
159 | + 'noheader' => true, |
|
160 | + 'capability' => 'ee_delete_payments', |
|
161 | + ), |
|
162 | + |
|
163 | + ); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + protected function _set_page_config() |
|
168 | + { |
|
169 | + $this->_page_config = array( |
|
170 | + 'default' => array( |
|
171 | + 'nav' => array( |
|
172 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
173 | + 'order' => 10, |
|
174 | + ), |
|
175 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
176 | + 'help_tabs' => array( |
|
177 | + 'transactions_overview_help_tab' => array( |
|
178 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
179 | + 'filename' => 'transactions_overview', |
|
180 | + ), |
|
181 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
182 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
183 | + 'filename' => 'transactions_overview_table_column_headings', |
|
184 | + ), |
|
185 | + 'transactions_overview_views_filters_help_tab' => array( |
|
186 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
187 | + 'filename' => 'transactions_overview_views_filters_search', |
|
188 | + ), |
|
189 | + ), |
|
190 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
191 | + /** |
|
192 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
193 | + * may change in a later iteration so want to keep the code for then. |
|
194 | + */ |
|
195 | + //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
196 | + 'require_nonce' => false, |
|
197 | + ), |
|
198 | + 'view_transaction' => array( |
|
199 | + 'nav' => array( |
|
200 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
201 | + 'order' => 5, |
|
202 | + 'url' => isset($this->_req_data['TXN_ID']) |
|
203 | + ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
204 | + : $this->_admin_base_url, |
|
205 | + 'persistent' => false, |
|
206 | + ), |
|
207 | + 'help_tabs' => array( |
|
208 | + 'transactions_view_transaction_help_tab' => array( |
|
209 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
210 | + 'filename' => 'transactions_view_transaction', |
|
211 | + ), |
|
212 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
213 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
214 | + 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
215 | + ), |
|
216 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
217 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
218 | + 'filename' => 'transactions_view_transaction_attendees_registered', |
|
219 | + ), |
|
220 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
221 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
222 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
223 | + ), |
|
224 | + ), |
|
225 | + 'qtips' => array('Transaction_Details_Tips'), |
|
226 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
227 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
228 | + |
|
229 | + 'require_nonce' => false, |
|
230 | + ), |
|
231 | + ); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * The below methods aren't used by this class currently |
|
237 | + */ |
|
238 | + protected function _add_screen_options() |
|
239 | + { |
|
240 | + //noop |
|
241 | + } |
|
242 | + |
|
243 | + protected function _add_feature_pointers() |
|
244 | + { |
|
245 | + //noop |
|
246 | + } |
|
247 | + |
|
248 | + public function admin_init() |
|
249 | + { |
|
250 | + // IF a registration was JUST added via the admin... |
|
251 | + if (isset( |
|
252 | + $this->_req_data['redirect_from'], |
|
253 | + $this->_req_data['EVT_ID'], |
|
254 | + $this->_req_data['event_name'] |
|
255 | + )) { |
|
256 | + // then set a cookie so that we can block any attempts to use |
|
257 | + // the back button as a way to enter another registration. |
|
258 | + setcookie( |
|
259 | + 'ee_registration_added', |
|
260 | + $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/' |
|
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 | + /** |
|
342 | + * _add_screen_options_default |
|
343 | + * |
|
344 | + * @access protected |
|
345 | + * @return void |
|
346 | + * @throws InvalidArgumentException |
|
347 | + * @throws InvalidDataTypeException |
|
348 | + * @throws InvalidInterfaceException |
|
349 | + */ |
|
350 | + protected function _add_screen_options_default() |
|
351 | + { |
|
352 | + $this->_per_page_screen_option(); |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * load_scripts_styles |
|
358 | + * |
|
359 | + * @access public |
|
360 | + * @return void |
|
361 | + */ |
|
362 | + public function load_scripts_styles() |
|
363 | + { |
|
364 | + //enqueue style |
|
365 | + wp_register_style( |
|
366 | + 'espresso_txn', |
|
367 | + TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
368 | + array(), |
|
369 | + EVENT_ESPRESSO_VERSION |
|
370 | + ); |
|
371 | + wp_enqueue_style('espresso_txn'); |
|
372 | + //scripts |
|
373 | + wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
374 | + 'ee_admin_js', |
|
375 | + 'ee-datepicker', |
|
376 | + 'jquery-ui-datepicker', |
|
377 | + 'jquery-ui-draggable', |
|
378 | + 'ee-dialog', |
|
379 | + 'ee-accounting', |
|
380 | + 'ee-serialize-full-array', |
|
381 | + ), EVENT_ESPRESSO_VERSION, true); |
|
382 | + wp_enqueue_script('espresso_txn'); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + /** |
|
387 | + * load_scripts_styles_view_transaction |
|
388 | + * |
|
389 | + * @access public |
|
390 | + * @return void |
|
391 | + */ |
|
392 | + public function load_scripts_styles_view_transaction() |
|
393 | + { |
|
394 | + //styles |
|
395 | + wp_enqueue_style('espresso-ui-theme'); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * load_scripts_styles_default |
|
401 | + * |
|
402 | + * @access public |
|
403 | + * @return void |
|
404 | + */ |
|
405 | + public function load_scripts_styles_default() |
|
406 | + { |
|
407 | + //styles |
|
408 | + wp_enqueue_style('espresso-ui-theme'); |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * _set_list_table_views_default |
|
414 | + * |
|
415 | + * @access protected |
|
416 | + * @return void |
|
417 | + */ |
|
418 | + protected function _set_list_table_views_default() |
|
419 | + { |
|
420 | + $this->_views = array( |
|
421 | + 'all' => array( |
|
422 | + 'slug' => 'all', |
|
423 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
424 | + 'count' => 0, |
|
425 | + ), |
|
426 | + 'abandoned' => array( |
|
427 | + 'slug' => 'abandoned', |
|
428 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
429 | + 'count' => 0, |
|
430 | + ), |
|
431 | + 'failed' => array( |
|
432 | + 'slug' => 'failed', |
|
433 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
434 | + 'count' => 0, |
|
435 | + ), |
|
436 | + ); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * _set_transaction_object |
|
442 | + * This sets the _transaction property for the transaction details screen |
|
443 | + * |
|
444 | + * @access private |
|
445 | + * @return void |
|
446 | + * @throws EE_Error |
|
447 | + * @throws InvalidArgumentException |
|
448 | + * @throws RuntimeException |
|
449 | + * @throws InvalidDataTypeException |
|
450 | + * @throws InvalidInterfaceException |
|
451 | + */ |
|
452 | + private function _set_transaction_object() |
|
453 | + { |
|
454 | + if ($this->_transaction instanceof EE_Transaction) { |
|
455 | + return; |
|
456 | + } //get out we've already set the object |
|
457 | + |
|
458 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
459 | + ? absint($this->_req_data['TXN_ID']) |
|
460 | + : false; |
|
461 | + |
|
462 | + //get transaction object |
|
463 | + $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
464 | + $this->_session = $this->_transaction instanceof EE_Transaction |
|
465 | + ? $this->_transaction->get('TXN_session_data') |
|
466 | + : null; |
|
467 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
468 | + |
|
469 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
470 | + $error_msg = sprintf( |
|
471 | + esc_html__( |
|
472 | + 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
473 | + 'event_espresso' |
|
474 | + ), |
|
475 | + $TXN_ID |
|
476 | + ); |
|
477 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
478 | + } |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * _transaction_legend_items |
|
484 | + * |
|
485 | + * @access protected |
|
486 | + * @return array |
|
487 | + * @throws EE_Error |
|
488 | + * @throws InvalidArgumentException |
|
489 | + * @throws ReflectionException |
|
490 | + * @throws InvalidDataTypeException |
|
491 | + * @throws InvalidInterfaceException |
|
492 | + */ |
|
493 | + protected function _transaction_legend_items() |
|
494 | + { |
|
495 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
496 | + $items = array(); |
|
497 | + |
|
498 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
499 | + 'ee_read_global_messages', |
|
500 | + 'view_filtered_messages' |
|
501 | + )) { |
|
502 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
503 | + if (is_array($related_for_icon) |
|
504 | + && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
505 | + ) { |
|
506 | + $items['view_related_messages'] = array( |
|
507 | + 'class' => $related_for_icon['css_class'], |
|
508 | + 'desc' => $related_for_icon['label'], |
|
509 | + ); |
|
510 | + } |
|
511 | + } |
|
512 | + |
|
513 | + $items = apply_filters( |
|
514 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
515 | + array_merge( |
|
516 | + $items, |
|
517 | + array( |
|
518 | + 'view_details' => array( |
|
519 | + 'class' => 'dashicons dashicons-cart', |
|
520 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
521 | + ), |
|
522 | + 'view_invoice' => array( |
|
523 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
524 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
525 | + ), |
|
526 | + 'view_receipt' => array( |
|
527 | + 'class' => 'dashicons dashicons-media-default', |
|
528 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
529 | + ), |
|
530 | + 'view_registration' => array( |
|
531 | + 'class' => 'dashicons dashicons-clipboard', |
|
532 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
533 | + ), |
|
534 | + 'payment_overview_link' => array( |
|
535 | + 'class' => 'dashicons dashicons-money', |
|
536 | + 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
537 | + ), |
|
538 | + ) |
|
539 | + ) |
|
540 | + ); |
|
541 | + |
|
542 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
543 | + 'ee_send_message', |
|
544 | + 'espresso_transactions_send_payment_reminder' |
|
545 | + )) { |
|
546 | + if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
547 | + $items['send_payment_reminder'] = array( |
|
548 | + 'class' => 'dashicons dashicons-email-alt', |
|
549 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
550 | + ); |
|
551 | + } else { |
|
552 | + $items['blank*'] = array( |
|
553 | + 'class' => '', |
|
554 | + 'desc' => '', |
|
555 | + ); |
|
556 | + } |
|
557 | + } else { |
|
558 | + $items['blank*'] = array( |
|
559 | + 'class' => '', |
|
560 | + 'desc' => '', |
|
561 | + ); |
|
562 | + } |
|
563 | + $more_items = apply_filters( |
|
564 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
565 | + array( |
|
566 | + 'overpaid' => array( |
|
567 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
568 | + 'desc' => EEH_Template::pretty_status( |
|
569 | + EEM_Transaction::overpaid_status_code, |
|
570 | + false, |
|
571 | + 'sentence' |
|
572 | + ), |
|
573 | + ), |
|
574 | + 'complete' => array( |
|
575 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
576 | + 'desc' => EEH_Template::pretty_status( |
|
577 | + EEM_Transaction::complete_status_code, |
|
578 | + false, |
|
579 | + 'sentence' |
|
580 | + ), |
|
581 | + ), |
|
582 | + 'incomplete' => array( |
|
583 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
584 | + 'desc' => EEH_Template::pretty_status( |
|
585 | + EEM_Transaction::incomplete_status_code, |
|
586 | + false, |
|
587 | + 'sentence' |
|
588 | + ), |
|
589 | + ), |
|
590 | + 'abandoned' => array( |
|
591 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
592 | + 'desc' => EEH_Template::pretty_status( |
|
593 | + EEM_Transaction::abandoned_status_code, |
|
594 | + false, |
|
595 | + 'sentence' |
|
596 | + ), |
|
597 | + ), |
|
598 | + 'failed' => array( |
|
599 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
600 | + 'desc' => EEH_Template::pretty_status( |
|
601 | + EEM_Transaction::failed_status_code, |
|
602 | + false, |
|
603 | + 'sentence' |
|
604 | + ), |
|
605 | + ), |
|
606 | + ) |
|
607 | + ); |
|
608 | + |
|
609 | + return array_merge($items, $more_items); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * _transactions_overview_list_table |
|
615 | + * |
|
616 | + * @access protected |
|
617 | + * @return void |
|
618 | + * @throws DomainException |
|
619 | + * @throws EE_Error |
|
620 | + * @throws InvalidArgumentException |
|
621 | + * @throws InvalidDataTypeException |
|
622 | + * @throws InvalidInterfaceException |
|
623 | + * @throws ReflectionException |
|
624 | + */ |
|
625 | + protected function _transactions_overview_list_table() |
|
626 | + { |
|
627 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
628 | + $event = isset($this->_req_data['EVT_ID']) |
|
629 | + ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
630 | + : null; |
|
631 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
632 | + ? sprintf( |
|
633 | + esc_html__( |
|
634 | + '%sViewing Transactions for the Event: %s%s', |
|
635 | + 'event_espresso' |
|
636 | + ), |
|
637 | + '<h3>', |
|
638 | + '<a href="' |
|
639 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
640 | + array('action' => 'edit', 'post' => $event->ID()), |
|
641 | + EVENTS_ADMIN_URL |
|
642 | + ) |
|
643 | + . '" title="' |
|
644 | + . esc_attr__( |
|
645 | + 'Click to Edit event', |
|
646 | + 'event_espresso' |
|
647 | + ) |
|
648 | + . '">' . $event->get('EVT_name') . '</a>', |
|
649 | + '</h3>' |
|
650 | + ) |
|
651 | + : ''; |
|
652 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
653 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
654 | + } |
|
655 | + |
|
656 | + |
|
657 | + /** |
|
658 | + * _transaction_details |
|
659 | + * generates HTML for the View Transaction Details Admin page |
|
660 | + * |
|
661 | + * @access protected |
|
662 | + * @return void |
|
663 | + * @throws DomainException |
|
664 | + * @throws EE_Error |
|
665 | + * @throws InvalidArgumentException |
|
666 | + * @throws InvalidDataTypeException |
|
667 | + * @throws InvalidInterfaceException |
|
668 | + * @throws RuntimeException |
|
669 | + */ |
|
670 | + protected function _transaction_details() |
|
671 | + { |
|
672 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
673 | + |
|
674 | + $this->_set_transaction_status_array(); |
|
675 | + |
|
676 | + $this->_template_args = array(); |
|
677 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
678 | + |
|
679 | + $this->_set_transaction_object(); |
|
680 | + |
|
681 | + $primary_registration = $this->_transaction->primary_registration(); |
|
682 | + $attendee = $primary_registration instanceof EE_Registration |
|
683 | + ? $primary_registration->attendee() |
|
684 | + : null; |
|
685 | + |
|
686 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
687 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
688 | + |
|
689 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
690 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
691 | + |
|
692 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
693 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
694 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
695 | + |
|
696 | + $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
697 | + $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
698 | + |
|
699 | + if ($attendee instanceof EE_Attendee |
|
700 | + && EE_Registry::instance()->CAP->current_user_can( |
|
701 | + 'ee_send_message', |
|
702 | + 'espresso_transactions_send_payment_reminder' |
|
703 | + ) |
|
704 | + ) { |
|
705 | + $this->_template_args['send_payment_reminder_button'] = |
|
706 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
707 | + && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code |
|
708 | + && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code |
|
709 | + ? EEH_Template::get_button_or_link( |
|
710 | + EE_Admin_Page::add_query_args_and_nonce( |
|
711 | + array( |
|
712 | + 'action' => 'send_payment_reminder', |
|
713 | + 'TXN_ID' => $this->_transaction->ID(), |
|
714 | + 'redirect_to' => 'view_transaction', |
|
715 | + ), |
|
716 | + TXN_ADMIN_URL |
|
717 | + ), |
|
718 | + __(' Send Payment Reminder', 'event_espresso'), |
|
719 | + 'button secondary-button right', |
|
720 | + 'dashicons dashicons-email-alt' |
|
721 | + ) |
|
722 | + : ''; |
|
723 | + } else { |
|
724 | + $this->_template_args['send_payment_reminder_button'] = ''; |
|
725 | + } |
|
726 | + |
|
727 | + $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
728 | + $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
729 | + $amount_due, |
|
730 | + true |
|
731 | + ); |
|
732 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
733 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
734 | + . $this->_template_args['amount_due']; |
|
735 | + } else { |
|
736 | + $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
737 | + } |
|
738 | + $this->_template_args['amount_due_class'] = ''; |
|
739 | + |
|
740 | + if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
741 | + // paid in full |
|
742 | + $this->_template_args['amount_due'] = false; |
|
743 | + } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
744 | + // overpaid |
|
745 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
746 | + } elseif ($this->_transaction->get('TXN_total') > 0 |
|
747 | + && $this->_transaction->get('TXN_paid') > 0 |
|
748 | + ) { |
|
749 | + // monies owing |
|
750 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
751 | + } elseif ($this->_transaction->get('TXN_total') > 0 |
|
752 | + && $this->_transaction->get('TXN_paid') == 0 |
|
753 | + ) { |
|
754 | + // no payments made yet |
|
755 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
756 | + } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
757 | + // free event |
|
758 | + $this->_template_args['amount_due'] = false; |
|
759 | + } |
|
760 | + |
|
761 | + $payment_method = $this->_transaction->payment_method(); |
|
762 | + |
|
763 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
764 | + ? $payment_method->admin_name() |
|
765 | + : esc_html__('Unknown', 'event_espresso'); |
|
766 | + |
|
767 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
768 | + // link back to overview |
|
769 | + $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
770 | + ? $_SERVER['HTTP_REFERER'] |
|
771 | + : TXN_ADMIN_URL; |
|
772 | + |
|
773 | + |
|
774 | + // next link |
|
775 | + $next_txn = $this->_transaction->next( |
|
776 | + null, |
|
777 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
778 | + 'TXN_ID' |
|
779 | + ); |
|
780 | + $this->_template_args['next_transaction'] = $next_txn |
|
781 | + ? $this->_next_link( |
|
782 | + EE_Admin_Page::add_query_args_and_nonce( |
|
783 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
784 | + TXN_ADMIN_URL |
|
785 | + ), |
|
786 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
787 | + ) |
|
788 | + : ''; |
|
789 | + // previous link |
|
790 | + $previous_txn = $this->_transaction->previous( |
|
791 | + null, |
|
792 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
793 | + 'TXN_ID' |
|
794 | + ); |
|
795 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
796 | + ? $this->_previous_link( |
|
797 | + EE_Admin_Page::add_query_args_and_nonce( |
|
798 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
799 | + TXN_ADMIN_URL |
|
800 | + ), |
|
801 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
802 | + ) |
|
803 | + : ''; |
|
804 | + |
|
805 | + // were we just redirected here after adding a new registration ??? |
|
806 | + if (isset( |
|
807 | + $this->_req_data['redirect_from'], |
|
808 | + $this->_req_data['EVT_ID'], |
|
809 | + $this->_req_data['event_name'] |
|
810 | + )) { |
|
811 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
812 | + 'ee_edit_registrations', |
|
813 | + 'espresso_registrations_new_registration', |
|
814 | + $this->_req_data['EVT_ID'] |
|
815 | + )) { |
|
816 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
817 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
818 | + array( |
|
819 | + 'page' => 'espresso_registrations', |
|
820 | + 'action' => 'new_registration', |
|
821 | + 'return' => 'default', |
|
822 | + 'TXN_ID' => $this->_transaction->ID(), |
|
823 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
824 | + ), |
|
825 | + REG_ADMIN_URL |
|
826 | + ); |
|
827 | + $this->_admin_page_title .= '">'; |
|
828 | + |
|
829 | + $this->_admin_page_title .= sprintf( |
|
830 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
831 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
832 | + ); |
|
833 | + $this->_admin_page_title .= '</a>'; |
|
834 | + } |
|
835 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
836 | + } |
|
837 | + // grab messages at the last second |
|
838 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
839 | + // path to template |
|
840 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
841 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
842 | + $template_path, |
|
843 | + $this->_template_args, |
|
844 | + true |
|
845 | + ); |
|
846 | + |
|
847 | + // the details template wrapper |
|
848 | + $this->display_admin_page_with_sidebar(); |
|
849 | + |
|
850 | + } |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * _transaction_details_metaboxes |
|
855 | + * |
|
856 | + * @access protected |
|
857 | + * @return void |
|
858 | + * @throws EE_Error |
|
859 | + * @throws InvalidArgumentException |
|
860 | + * @throws InvalidDataTypeException |
|
861 | + * @throws InvalidInterfaceException |
|
862 | + * @throws RuntimeException |
|
863 | + */ |
|
864 | + protected function _transaction_details_metaboxes() |
|
865 | + { |
|
866 | + |
|
867 | + $this->_set_transaction_object(); |
|
868 | + |
|
869 | + add_meta_box( |
|
870 | + 'edit-txn-details-mbox', |
|
871 | + esc_html__('Transaction Details', 'event_espresso'), |
|
872 | + array($this, 'txn_details_meta_box'), |
|
873 | + $this->_wp_page_slug, |
|
874 | + 'normal', |
|
875 | + 'high' |
|
876 | + ); |
|
877 | + add_meta_box( |
|
878 | + 'edit-txn-attendees-mbox', |
|
879 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
880 | + array($this, 'txn_attendees_meta_box'), |
|
881 | + $this->_wp_page_slug, |
|
882 | + 'normal', |
|
883 | + 'high', |
|
884 | + array('TXN_ID' => $this->_transaction->ID()) |
|
885 | + ); |
|
886 | + add_meta_box( |
|
887 | + 'edit-txn-registrant-mbox', |
|
888 | + esc_html__('Primary Contact', 'event_espresso'), |
|
889 | + array($this, 'txn_registrant_side_meta_box'), |
|
890 | + $this->_wp_page_slug, |
|
891 | + 'side', |
|
892 | + 'high' |
|
893 | + ); |
|
894 | + add_meta_box( |
|
895 | + 'edit-txn-billing-info-mbox', |
|
896 | + esc_html__('Billing Information', 'event_espresso'), |
|
897 | + array($this, 'txn_billing_info_side_meta_box'), |
|
898 | + $this->_wp_page_slug, |
|
899 | + 'side', |
|
900 | + 'high' |
|
901 | + ); |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * txn_details_meta_box |
|
907 | + * generates HTML for the Transaction main meta box |
|
908 | + * |
|
909 | + * @access public |
|
910 | + * @return void |
|
911 | + * @throws DomainException |
|
912 | + * @throws EE_Error |
|
913 | + * @throws InvalidArgumentException |
|
914 | + * @throws InvalidDataTypeException |
|
915 | + * @throws InvalidInterfaceException |
|
916 | + * @throws RuntimeException |
|
917 | + */ |
|
918 | + public function txn_details_meta_box() |
|
919 | + { |
|
920 | + |
|
921 | + $this->_set_transaction_object(); |
|
922 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
923 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
924 | + ? $this->_transaction->primary_registration()->attendee() |
|
925 | + : null; |
|
926 | + $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
927 | + 'ee_edit_payments', |
|
928 | + 'apply_payment_or_refund_from_registration_details' |
|
929 | + ); |
|
930 | + $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
931 | + 'ee_delete_payments', |
|
932 | + 'delete_payment_from_registration_details' |
|
933 | + ); |
|
934 | + |
|
935 | + //get line table |
|
936 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
937 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
938 | + 'admin_table', |
|
939 | + 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
940 | + ); |
|
941 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
942 | + $this->_transaction->total_line_item() |
|
943 | + ); |
|
944 | + $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration') |
|
945 | + ->get('REG_code'); |
|
946 | + |
|
947 | + // process taxes |
|
948 | + $taxes = $this->_transaction->get_many_related( |
|
949 | + 'Line_Item', |
|
950 | + array(array('LIN_type' => EEM_Line_Item::type_tax)) |
|
951 | + ); |
|
952 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
953 | + |
|
954 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
955 | + $this->_transaction->get('TXN_total'), |
|
956 | + false, |
|
957 | + false |
|
958 | + ); |
|
959 | + $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
960 | + $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
961 | + |
|
962 | + // process payment details |
|
963 | + $payments = $this->_transaction->get_many_related('Payment'); |
|
964 | + if (! empty($payments)) { |
|
965 | + $this->_template_args['payments'] = $payments; |
|
966 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
967 | + } else { |
|
968 | + $this->_template_args['payments'] = false; |
|
969 | + $this->_template_args['existing_reg_payments'] = array(); |
|
970 | + } |
|
971 | + |
|
972 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
973 | + $this->_template_args['delete_payment_url'] = add_query_arg( |
|
974 | + array('action' => 'espresso_delete_payment'), |
|
975 | + TXN_ADMIN_URL |
|
976 | + ); |
|
977 | + |
|
978 | + if (isset($txn_details['invoice_number'])) { |
|
979 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
980 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
981 | + 'Invoice Number', |
|
982 | + 'event_espresso' |
|
983 | + ); |
|
984 | + } |
|
985 | + |
|
986 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
987 | + ->get_first_related('Registration') |
|
988 | + ->get('REG_session'); |
|
989 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
990 | + 'Registration Session', |
|
991 | + 'event_espresso' |
|
992 | + ); |
|
993 | + |
|
994 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
995 | + ? $this->_session['ip_address'] |
|
996 | + : ''; |
|
997 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
998 | + 'Transaction placed from IP', |
|
999 | + 'event_espresso' |
|
1000 | + ); |
|
1001 | + |
|
1002 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
1003 | + ? $this->_session['user_agent'] |
|
1004 | + : ''; |
|
1005 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
1006 | + 'Registrant User Agent', |
|
1007 | + 'event_espresso' |
|
1008 | + ); |
|
1009 | + |
|
1010 | + $reg_steps = '<ul>'; |
|
1011 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
1012 | + if ($reg_step_status === true) { |
|
1013 | + $reg_steps .= '<li style="color:#70cc50">' |
|
1014 | + . sprintf( |
|
1015 | + esc_html__('%1$s : Completed', 'event_espresso'), |
|
1016 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
1017 | + ) |
|
1018 | + . '</li>'; |
|
1019 | + } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
1020 | + $reg_steps .= '<li style="color:#2EA2CC">' |
|
1021 | + . sprintf( |
|
1022 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
1023 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
1024 | + date( |
|
1025 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
1026 | + ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
1027 | + ) |
|
1028 | + ) |
|
1029 | + . '</li>'; |
|
1030 | + } else { |
|
1031 | + $reg_steps .= '<li style="color:#E76700">' |
|
1032 | + . sprintf( |
|
1033 | + esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
1034 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
1035 | + ) |
|
1036 | + . '</li>'; |
|
1037 | + } |
|
1038 | + } |
|
1039 | + $reg_steps .= '</ul>'; |
|
1040 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
1041 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
1042 | + 'Registration Step Progress', |
|
1043 | + 'event_espresso' |
|
1044 | + ); |
|
1045 | + |
|
1046 | + |
|
1047 | + $this->_get_registrations_to_apply_payment_to(); |
|
1048 | + $this->_get_payment_methods($payments); |
|
1049 | + $this->_get_payment_status_array(); |
|
1050 | + $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
1051 | + |
|
1052 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
1053 | + 'action' => 'edit_transaction', |
|
1054 | + 'process' => 'transaction', |
|
1055 | + ), TXN_ADMIN_URL); |
|
1056 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
1057 | + 'page' => 'espresso_transactions', |
|
1058 | + 'action' => 'espresso_apply_payment', |
|
1059 | + ), WP_AJAX_URL); |
|
1060 | + $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
1061 | + 'page' => 'espresso_transactions', |
|
1062 | + 'action' => 'espresso_delete_payment', |
|
1063 | + ), WP_AJAX_URL); |
|
1064 | + |
|
1065 | + // 'espresso_delete_payment_nonce' |
|
1066 | + |
|
1067 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
1068 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
1069 | + } |
|
1070 | + |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * _get_registration_payment_IDs |
|
1074 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
1075 | + * |
|
1076 | + * @access protected |
|
1077 | + * @param EE_Payment[] $payments |
|
1078 | + * @return array |
|
1079 | + * @throws EE_Error |
|
1080 | + * @throws InvalidArgumentException |
|
1081 | + * @throws InvalidDataTypeException |
|
1082 | + * @throws InvalidInterfaceException |
|
1083 | + */ |
|
1084 | + protected function _get_registration_payment_IDs($payments = array()) |
|
1085 | + { |
|
1086 | + $existing_reg_payments = array(); |
|
1087 | + // get all reg payments for these payments |
|
1088 | + $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
1089 | + array( |
|
1090 | + 'PAY_ID' => array( |
|
1091 | + 'IN', |
|
1092 | + array_keys($payments), |
|
1093 | + ), |
|
1094 | + ), |
|
1095 | + )); |
|
1096 | + if (! empty($reg_payments)) { |
|
1097 | + foreach ($payments as $payment) { |
|
1098 | + if (! $payment instanceof EE_Payment) { |
|
1099 | + continue; |
|
1100 | + } elseif (! isset($existing_reg_payments[$payment->ID()])) { |
|
1101 | + $existing_reg_payments[$payment->ID()] = array(); |
|
1102 | + } |
|
1103 | + foreach ($reg_payments as $reg_payment) { |
|
1104 | + if ($reg_payment instanceof EE_Registration_Payment |
|
1105 | + && $reg_payment->payment_ID() === $payment->ID() |
|
1106 | + ) { |
|
1107 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
1108 | + } |
|
1109 | + } |
|
1110 | + } |
|
1111 | + } |
|
1112 | + |
|
1113 | + return $existing_reg_payments; |
|
1114 | + } |
|
1115 | + |
|
1116 | + |
|
1117 | + /** |
|
1118 | + * _get_registrations_to_apply_payment_to |
|
1119 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
1120 | + * which allows the admin to only apply the payment to the specific registrations |
|
1121 | + * |
|
1122 | + * @access protected |
|
1123 | + * @return void |
|
1124 | + * @throws \EE_Error |
|
1125 | + */ |
|
1126 | + protected function _get_registrations_to_apply_payment_to() |
|
1127 | + { |
|
1128 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
1129 | + $query_params = array( |
|
1130 | + array( |
|
1131 | + 'STS_ID' => array( |
|
1132 | + 'IN', |
|
1133 | + array( |
|
1134 | + EEM_Registration::status_id_approved, |
|
1135 | + EEM_Registration::status_id_pending_payment, |
|
1136 | + EEM_Registration::status_id_not_approved, |
|
1137 | + ), |
|
1138 | + ), |
|
1139 | + ), |
|
1140 | + ); |
|
1141 | + $registrations_to_apply_payment_to = EEH_HTML::br() |
|
1142 | + . EEH_HTML::div( |
|
1143 | + '', |
|
1144 | + 'txn-admin-apply-payment-to-registrations-dv', |
|
1145 | + '', |
|
1146 | + 'clear: both; margin: 1.5em 0 0; display: none;' |
|
1147 | + ); |
|
1148 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
1149 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
1150 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
1151 | + EEH_HTML::tr( |
|
1152 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
1153 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
1154 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
1155 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
1156 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
1157 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
1158 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
1159 | + ) |
|
1160 | + ); |
|
1161 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
1162 | + // get registrations for TXN |
|
1163 | + $registrations = $this->_transaction->registrations($query_params); |
|
1164 | + $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
1165 | + foreach ($registrations as $registration) { |
|
1166 | + if ($registration instanceof EE_Registration) { |
|
1167 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
1168 | + ? $registration->attendee()->full_name() |
|
1169 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
1170 | + $owing = $registration->final_price() - $registration->paid(); |
|
1171 | + $taxable = $registration->ticket()->taxable() |
|
1172 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
1173 | + : ''; |
|
1174 | + $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
1175 | + ? ' checked="checked"' |
|
1176 | + : ''; |
|
1177 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
1178 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
1179 | + EEH_HTML::td($registration->ID()) . |
|
1180 | + EEH_HTML::td($attendee_name) . |
|
1181 | + EEH_HTML::td( |
|
1182 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
1183 | + ) . |
|
1184 | + EEH_HTML::td($registration->event_name()) . |
|
1185 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
1186 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
1187 | + EEH_HTML::td( |
|
1188 | + '<input type="checkbox" value="' . $registration->ID() |
|
1189 | + . '" name="txn_admin_payment[registrations]"' |
|
1190 | + . $checked . $disabled . '>', |
|
1191 | + '', |
|
1192 | + 'jst-cntr' |
|
1193 | + ), |
|
1194 | + 'apply-payment-registration-row-' . $registration->ID() |
|
1195 | + ); |
|
1196 | + } |
|
1197 | + } |
|
1198 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
1199 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
1200 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1201 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
1202 | + esc_html__( |
|
1203 | + '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.', |
|
1204 | + 'event_espresso' |
|
1205 | + ), |
|
1206 | + '', |
|
1207 | + 'clear description' |
|
1208 | + ); |
|
1209 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
1210 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
1211 | + } |
|
1212 | + |
|
1213 | + |
|
1214 | + /** |
|
1215 | + * _get_reg_status_selection |
|
1216 | + * |
|
1217 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
1218 | + * instead of events. |
|
1219 | + * @access protected |
|
1220 | + * @return void |
|
1221 | + * @throws EE_Error |
|
1222 | + */ |
|
1223 | + protected function _get_reg_status_selection() |
|
1224 | + { |
|
1225 | + //first get all possible statuses |
|
1226 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
1227 | + //let's add a "don't change" option. |
|
1228 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
1229 | + $status_array = array_merge($status_array, $statuses); |
|
1230 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
1231 | + 'txn_reg_status_change[reg_status]', |
|
1232 | + $status_array, |
|
1233 | + 'NAN', |
|
1234 | + 'id="txn-admin-payment-reg-status-inp"', |
|
1235 | + 'txn-reg-status-change-reg-status' |
|
1236 | + ); |
|
1237 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
1238 | + 'delete_txn_reg_status_change[reg_status]', |
|
1239 | + $status_array, |
|
1240 | + 'NAN', |
|
1241 | + 'delete-txn-admin-payment-reg-status-inp', |
|
1242 | + 'delete-txn-reg-status-change-reg-status' |
|
1243 | + ); |
|
1244 | + } |
|
1245 | + |
|
1246 | + |
|
1247 | + /** |
|
1248 | + * _get_payment_methods |
|
1249 | + * Gets all the payment methods available generally, or the ones that are already |
|
1250 | + * selected on these payments (in case their payment methods are no longer active). |
|
1251 | + * Has the side-effect of updating the template args' payment_methods item |
|
1252 | + * |
|
1253 | + * @access private |
|
1254 | + * @param EE_Payment[] to show on this page |
|
1255 | + * @return void |
|
1256 | + * @throws EE_Error |
|
1257 | + * @throws InvalidArgumentException |
|
1258 | + * @throws InvalidDataTypeException |
|
1259 | + * @throws InvalidInterfaceException |
|
1260 | + */ |
|
1261 | + private function _get_payment_methods($payments = array()) |
|
1262 | + { |
|
1263 | + $payment_methods_of_payments = array(); |
|
1264 | + foreach ($payments as $payment) { |
|
1265 | + if ($payment instanceof EE_Payment) { |
|
1266 | + $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
1267 | + } |
|
1268 | + } |
|
1269 | + if ($payment_methods_of_payments) { |
|
1270 | + $query_args = array( |
|
1271 | + array( |
|
1272 | + 'OR*payment_method_for_payment' => array( |
|
1273 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
1274 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
1275 | + ), |
|
1276 | + ), |
|
1277 | + ); |
|
1278 | + } else { |
|
1279 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
1280 | + } |
|
1281 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
1282 | + } |
|
1283 | + |
|
1284 | + |
|
1285 | + /** |
|
1286 | + * txn_attendees_meta_box |
|
1287 | + * generates HTML for the Attendees Transaction main meta box |
|
1288 | + * |
|
1289 | + * @access public |
|
1290 | + * @param WP_Post $post |
|
1291 | + * @param array $metabox |
|
1292 | + * @return void |
|
1293 | + * @throws DomainException |
|
1294 | + * @throws EE_Error |
|
1295 | + */ |
|
1296 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
1297 | + { |
|
1298 | + |
|
1299 | + /** @noinspection NonSecureExtractUsageInspection */ |
|
1300 | + extract($metabox['args']); |
|
1301 | + $this->_template_args['post'] = $post; |
|
1302 | + $this->_template_args['event_attendees'] = array(); |
|
1303 | + // process items in cart |
|
1304 | + $line_items = $this->_transaction->get_many_related( |
|
1305 | + 'Line_Item', |
|
1306 | + array(array('LIN_type' => 'line-item')) |
|
1307 | + ); |
|
1308 | + if (! empty($line_items)) { |
|
1309 | + foreach ($line_items as $item) { |
|
1310 | + if ($item instanceof EE_Line_Item) { |
|
1311 | + switch ($item->OBJ_type()) { |
|
1312 | + case 'Event': |
|
1313 | + break; |
|
1314 | + case 'Ticket': |
|
1315 | + $ticket = $item->ticket(); |
|
1316 | + //right now we're only handling tickets here. |
|
1317 | + //Cause its expected that only tickets will have attendees right? |
|
1318 | + if (! $ticket instanceof EE_Ticket) { |
|
1319 | + continue; |
|
1320 | + } |
|
1321 | + try { |
|
1322 | + $event_name = $ticket->get_event_name(); |
|
1323 | + } catch (Exception $e) { |
|
1324 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1325 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
1326 | + } |
|
1327 | + $event_name .= ' - ' . $item->get('LIN_name'); |
|
1328 | + $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
1329 | + // now get all of the registrations for this transaction that use this ticket |
|
1330 | + $registrations = $ticket->get_many_related( |
|
1331 | + 'Registration', |
|
1332 | + array(array('TXN_ID' => $this->_transaction->ID())) |
|
1333 | + ); |
|
1334 | + foreach ($registrations as $registration) { |
|
1335 | + if (! $registration instanceof EE_Registration) { |
|
1336 | + continue; |
|
1337 | + } |
|
1338 | + $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
|
1339 | + = $registration->status_ID(); |
|
1340 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] |
|
1341 | + = $registration->count(); |
|
1342 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] |
|
1343 | + = $event_name; |
|
1344 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] |
|
1345 | + = $ticket_price; |
|
1346 | + // attendee info |
|
1347 | + $attendee = $registration->get_first_related('Attendee'); |
|
1348 | + if ($attendee instanceof EE_Attendee) { |
|
1349 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] |
|
1350 | + = $attendee->ID(); |
|
1351 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
|
1352 | + = $attendee->full_name(); |
|
1353 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] |
|
1354 | + = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
1355 | + . esc_html__( |
|
1356 | + ' Event', |
|
1357 | + 'event_espresso' |
|
1358 | + ) |
|
1359 | + . '">' . $attendee->email() . '</a>'; |
|
1360 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] |
|
1361 | + = EEH_Address::format($attendee, 'inline', false, false); |
|
1362 | + } else { |
|
1363 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
1364 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
1365 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
1366 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
1367 | + } |
|
1368 | + } |
|
1369 | + break; |
|
1370 | + |
|
1371 | + } |
|
1372 | + } |
|
1373 | + } |
|
1374 | + |
|
1375 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
1376 | + array( |
|
1377 | + 'action' => 'edit_transaction', |
|
1378 | + 'process' => 'attendees', |
|
1379 | + ), |
|
1380 | + TXN_ADMIN_URL |
|
1381 | + ); |
|
1382 | + echo EEH_Template::display_template( |
|
1383 | + TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
1384 | + $this->_template_args, |
|
1385 | + true |
|
1386 | + ); |
|
1387 | + |
|
1388 | + } else { |
|
1389 | + echo sprintf( |
|
1390 | + esc_html__( |
|
1391 | + '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
1392 | + 'event_espresso' |
|
1393 | + ), |
|
1394 | + '<p class="important-notice">', |
|
1395 | + '</p>' |
|
1396 | + ); |
|
1397 | + } |
|
1398 | + } |
|
1399 | + |
|
1400 | + |
|
1401 | + /** |
|
1402 | + * txn_registrant_side_meta_box |
|
1403 | + * generates HTML for the Edit Transaction side meta box |
|
1404 | + * |
|
1405 | + * @access public |
|
1406 | + * @return void |
|
1407 | + * @throws DomainException |
|
1408 | + * @throws EE_Error |
|
1409 | + * @throws InvalidArgumentException |
|
1410 | + * @throws InvalidDataTypeException |
|
1411 | + * @throws InvalidInterfaceException |
|
1412 | + */ |
|
1413 | + public function txn_registrant_side_meta_box() |
|
1414 | + { |
|
1415 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
1416 | + ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
1417 | + : null; |
|
1418 | + if (! $primary_att instanceof EE_Attendee) { |
|
1419 | + $this->_template_args['no_attendee_message'] = esc_html__( |
|
1420 | + 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
1421 | + 'event_espresso' |
|
1422 | + ); |
|
1423 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
1424 | + } |
|
1425 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
1426 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
1427 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
1428 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
1429 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
1430 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
1431 | + 'action' => 'edit_attendee', |
|
1432 | + 'post' => $primary_att->ID(), |
|
1433 | + ), REG_ADMIN_URL); |
|
1434 | + // get formatted address for registrant |
|
1435 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
1436 | + echo EEH_Template::display_template( |
|
1437 | + TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
1438 | + $this->_template_args, |
|
1439 | + true |
|
1440 | + ); |
|
1441 | + } |
|
1442 | + |
|
1443 | + |
|
1444 | + /** |
|
1445 | + * txn_billing_info_side_meta_box |
|
1446 | + * generates HTML for the Edit Transaction side meta box |
|
1447 | + * |
|
1448 | + * @access public |
|
1449 | + * @return void |
|
1450 | + * @throws DomainException |
|
1451 | + * @throws EE_Error |
|
1452 | + */ |
|
1453 | + public function txn_billing_info_side_meta_box() |
|
1454 | + { |
|
1455 | + |
|
1456 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
1457 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
1458 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
1459 | + TXN_ADMIN_URL |
|
1460 | + ); |
|
1461 | + |
|
1462 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
1463 | + echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
1464 | + } |
|
1465 | + |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * apply_payments_or_refunds |
|
1469 | + * registers a payment or refund made towards a transaction |
|
1470 | + * |
|
1471 | + * @access public |
|
1472 | + * @return void |
|
1473 | + * @throws EE_Error |
|
1474 | + * @throws InvalidArgumentException |
|
1475 | + * @throws ReflectionException |
|
1476 | + * @throws RuntimeException |
|
1477 | + * @throws InvalidDataTypeException |
|
1478 | + * @throws InvalidInterfaceException |
|
1479 | + */ |
|
1480 | + public function apply_payments_or_refunds() |
|
1481 | + { |
|
1482 | + $json_response_data = array('return_data' => false); |
|
1483 | + $valid_data = $this->_validate_payment_request_data(); |
|
1484 | + $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
1485 | + 'ee_edit_payments', |
|
1486 | + 'apply_payment_or_refund_from_registration_details' |
|
1487 | + ); |
|
1488 | + if (! empty($valid_data) && $has_access) { |
|
1489 | + $PAY_ID = $valid_data['PAY_ID']; |
|
1490 | + //save the new payment |
|
1491 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
1492 | + // get the TXN for this payment |
|
1493 | + $transaction = $payment->transaction(); |
|
1494 | + // verify transaction |
|
1495 | + if ($transaction instanceof EE_Transaction) { |
|
1496 | + // calculate_total_payments_and_update_status |
|
1497 | + $this->_process_transaction_payments($transaction); |
|
1498 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
1499 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
1500 | + // apply payment to registrations (if applicable) |
|
1501 | + if (! empty($REG_IDs)) { |
|
1502 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
1503 | + $this->_maybe_send_notifications(); |
|
1504 | + // now process status changes for the same registrations |
|
1505 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
1506 | + } |
|
1507 | + $this->_maybe_send_notifications($payment); |
|
1508 | + //prepare to render page |
|
1509 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
1510 | + do_action( |
|
1511 | + 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
1512 | + $transaction, |
|
1513 | + $payment |
|
1514 | + ); |
|
1515 | + } else { |
|
1516 | + EE_Error::add_error( |
|
1517 | + esc_html__( |
|
1518 | + 'A valid Transaction for this payment could not be retrieved.', |
|
1519 | + 'event_espresso' |
|
1520 | + ), |
|
1521 | + __FILE__, |
|
1522 | + __FUNCTION__, |
|
1523 | + __LINE__ |
|
1524 | + ); |
|
1525 | + } |
|
1526 | + } else { |
|
1527 | + if ($has_access) { |
|
1528 | + EE_Error::add_error( |
|
1529 | + esc_html__( |
|
1530 | + 'The payment form data could not be processed. Please try again.', |
|
1531 | + 'event_espresso' |
|
1532 | + ), |
|
1533 | + __FILE__, |
|
1534 | + __FUNCTION__, |
|
1535 | + __LINE__ |
|
1536 | + ); |
|
1537 | + } else { |
|
1538 | + EE_Error::add_error( |
|
1539 | + esc_html__( |
|
1540 | + 'You do not have access to apply payments or refunds to a registration.', |
|
1541 | + 'event_espresso' |
|
1542 | + ), |
|
1543 | + __FILE__, |
|
1544 | + __FUNCTION__, |
|
1545 | + __LINE__ |
|
1546 | + ); |
|
1547 | + } |
|
1548 | + } |
|
1549 | + $notices = EE_Error::get_notices( |
|
1550 | + false, |
|
1551 | + false, |
|
1552 | + false |
|
1553 | + ); |
|
1554 | + $this->_template_args = array( |
|
1555 | + 'data' => $json_response_data, |
|
1556 | + 'error' => $notices['errors'], |
|
1557 | + 'success' => $notices['success'], |
|
1558 | + ); |
|
1559 | + $this->_return_json(); |
|
1560 | + } |
|
1561 | + |
|
1562 | + |
|
1563 | + /** |
|
1564 | + * _validate_payment_request_data |
|
1565 | + * |
|
1566 | + * @return array |
|
1567 | + */ |
|
1568 | + protected function _validate_payment_request_data() |
|
1569 | + { |
|
1570 | + if (! isset($this->_req_data['txn_admin_payment'])) { |
|
1571 | + return false; |
|
1572 | + } |
|
1573 | + $payment_form = $this->_generate_payment_form_section(); |
|
1574 | + try { |
|
1575 | + if ($payment_form->was_submitted()) { |
|
1576 | + $payment_form->receive_form_submission(); |
|
1577 | + if (! $payment_form->is_valid()) { |
|
1578 | + $submission_error_messages = array(); |
|
1579 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
1580 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1581 | + $submission_error_messages[] = sprintf( |
|
1582 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
1583 | + $validation_error->get_form_section()->html_label_text(), |
|
1584 | + $validation_error->getMessage() |
|
1585 | + ); |
|
1586 | + } |
|
1587 | + } |
|
1588 | + EE_Error::add_error( |
|
1589 | + implode('<br />', $submission_error_messages), |
|
1590 | + __FILE__, |
|
1591 | + __FUNCTION__, |
|
1592 | + __LINE__ |
|
1593 | + ); |
|
1594 | + |
|
1595 | + return array(); |
|
1596 | + } |
|
1597 | + } |
|
1598 | + } catch (EE_Error $e) { |
|
1599 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
1600 | + |
|
1601 | + return array(); |
|
1602 | + } |
|
1603 | + |
|
1604 | + return $payment_form->valid_data(); |
|
1605 | + } |
|
1606 | + |
|
1607 | + |
|
1608 | + /** |
|
1609 | + * _generate_payment_form_section |
|
1610 | + * |
|
1611 | + * @return EE_Form_Section_Proper |
|
1612 | + */ |
|
1613 | + protected function _generate_payment_form_section() |
|
1614 | + { |
|
1615 | + return new EE_Form_Section_Proper( |
|
1616 | + array( |
|
1617 | + 'name' => 'txn_admin_payment', |
|
1618 | + 'subsections' => array( |
|
1619 | + 'PAY_ID' => new EE_Text_Input( |
|
1620 | + array( |
|
1621 | + 'default' => 0, |
|
1622 | + 'required' => false, |
|
1623 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
1624 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1625 | + ) |
|
1626 | + ), |
|
1627 | + 'TXN_ID' => new EE_Text_Input( |
|
1628 | + array( |
|
1629 | + 'default' => 0, |
|
1630 | + 'required' => true, |
|
1631 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
1632 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1633 | + ) |
|
1634 | + ), |
|
1635 | + 'type' => new EE_Text_Input( |
|
1636 | + array( |
|
1637 | + 'default' => 1, |
|
1638 | + 'required' => true, |
|
1639 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
1640 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1641 | + ) |
|
1642 | + ), |
|
1643 | + 'amount' => new EE_Text_Input( |
|
1644 | + array( |
|
1645 | + 'default' => 0, |
|
1646 | + 'required' => true, |
|
1647 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
1648 | + 'validation_strategies' => array(new EE_Float_Normalization()), |
|
1649 | + ) |
|
1650 | + ), |
|
1651 | + 'status' => new EE_Text_Input( |
|
1652 | + array( |
|
1653 | + 'default' => EEM_Payment::status_id_approved, |
|
1654 | + 'required' => true, |
|
1655 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
1656 | + ) |
|
1657 | + ), |
|
1658 | + 'PMD_ID' => new EE_Text_Input( |
|
1659 | + array( |
|
1660 | + 'default' => 2, |
|
1661 | + 'required' => true, |
|
1662 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
1663 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
1664 | + ) |
|
1665 | + ), |
|
1666 | + 'date' => new EE_Text_Input( |
|
1667 | + array( |
|
1668 | + 'default' => time(), |
|
1669 | + 'required' => true, |
|
1670 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
1671 | + ) |
|
1672 | + ), |
|
1673 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
1674 | + array( |
|
1675 | + 'default' => '', |
|
1676 | + 'required' => false, |
|
1677 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
1678 | + 'validation_strategies' => array( |
|
1679 | + new EE_Max_Length_Validation_Strategy( |
|
1680 | + esc_html__('Input too long', 'event_espresso'), |
|
1681 | + 100 |
|
1682 | + ), |
|
1683 | + ), |
|
1684 | + ) |
|
1685 | + ), |
|
1686 | + 'po_number' => new EE_Text_Input( |
|
1687 | + array( |
|
1688 | + 'default' => '', |
|
1689 | + 'required' => false, |
|
1690 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
1691 | + 'validation_strategies' => array( |
|
1692 | + new EE_Max_Length_Validation_Strategy( |
|
1693 | + esc_html__('Input too long', 'event_espresso'), |
|
1694 | + 100 |
|
1695 | + ), |
|
1696 | + ), |
|
1697 | + ) |
|
1698 | + ), |
|
1699 | + 'accounting' => new EE_Text_Input( |
|
1700 | + array( |
|
1701 | + 'default' => '', |
|
1702 | + 'required' => false, |
|
1703 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
1704 | + 'validation_strategies' => array( |
|
1705 | + new EE_Max_Length_Validation_Strategy( |
|
1706 | + esc_html__('Input too long', 'event_espresso'), |
|
1707 | + 100 |
|
1708 | + ), |
|
1709 | + ), |
|
1710 | + ) |
|
1711 | + ), |
|
1712 | + ), |
|
1713 | + ) |
|
1714 | + ); |
|
1715 | + } |
|
1716 | + |
|
1717 | + |
|
1718 | + /** |
|
1719 | + * _create_payment_from_request_data |
|
1720 | + * |
|
1721 | + * @param array $valid_data |
|
1722 | + * @return EE_Payment |
|
1723 | + * @throws EE_Error |
|
1724 | + */ |
|
1725 | + protected function _create_payment_from_request_data($valid_data) |
|
1726 | + { |
|
1727 | + $PAY_ID = $valid_data['PAY_ID']; |
|
1728 | + // get payment amount |
|
1729 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
1730 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
1731 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
1732 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
1733 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
1734 | + $date = $valid_data['date'] |
|
1735 | + ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
1736 | + : date('Y-m-d g:i a', current_time('timestamp')); |
|
1737 | + $payment = EE_Payment::new_instance( |
|
1738 | + array( |
|
1739 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
1740 | + 'STS_ID' => $valid_data['status'], |
|
1741 | + 'PAY_timestamp' => $date, |
|
1742 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
1743 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
1744 | + 'PAY_amount' => $amount, |
|
1745 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
1746 | + 'PAY_po_number' => $valid_data['po_number'], |
|
1747 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
1748 | + 'PAY_details' => $valid_data, |
|
1749 | + 'PAY_ID' => $PAY_ID, |
|
1750 | + ), |
|
1751 | + '', |
|
1752 | + array('Y-m-d', 'g:i a') |
|
1753 | + ); |
|
1754 | + |
|
1755 | + if (! $payment->save()) { |
|
1756 | + EE_Error::add_error( |
|
1757 | + sprintf( |
|
1758 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
1759 | + $payment->ID() |
|
1760 | + ), |
|
1761 | + __FILE__, __FUNCTION__, __LINE__ |
|
1762 | + ); |
|
1763 | + } |
|
1764 | + |
|
1765 | + return $payment; |
|
1766 | + } |
|
1767 | + |
|
1768 | + |
|
1769 | + /** |
|
1770 | + * _process_transaction_payments |
|
1771 | + * |
|
1772 | + * @param \EE_Transaction $transaction |
|
1773 | + * @return void |
|
1774 | + * @throws EE_Error |
|
1775 | + * @throws InvalidArgumentException |
|
1776 | + * @throws ReflectionException |
|
1777 | + * @throws InvalidDataTypeException |
|
1778 | + * @throws InvalidInterfaceException |
|
1779 | + */ |
|
1780 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
1781 | + { |
|
1782 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
1783 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1784 | + //update the transaction with this payment |
|
1785 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
1786 | + EE_Error::add_success(esc_html__( |
|
1787 | + 'The payment has been processed successfully.', 'event_espresso'), |
|
1788 | + __FILE__, |
|
1789 | + __FUNCTION__, |
|
1790 | + __LINE__ |
|
1791 | + ); |
|
1792 | + } else { |
|
1793 | + EE_Error::add_error( |
|
1794 | + esc_html__( |
|
1795 | + 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
1796 | + 'event_espresso' |
|
1797 | + ) |
|
1798 | + , |
|
1799 | + __FILE__, |
|
1800 | + __FUNCTION__, |
|
1801 | + __LINE__ |
|
1802 | + ); |
|
1803 | + } |
|
1804 | + } |
|
1805 | + |
|
1806 | + |
|
1807 | + /** |
|
1808 | + * _get_REG_IDs_to_apply_payment_to |
|
1809 | + * returns a list of registration IDs that the payment will apply to |
|
1810 | + * |
|
1811 | + * @param \EE_Payment $payment |
|
1812 | + * @return array |
|
1813 | + * @throws EE_Error |
|
1814 | + */ |
|
1815 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
1816 | + { |
|
1817 | + $REG_IDs = array(); |
|
1818 | + // grab array of IDs for specific registrations to apply changes to |
|
1819 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
1820 | + $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
1821 | + } |
|
1822 | + //nothing specified ? then get all reg IDs |
|
1823 | + if (empty($REG_IDs)) { |
|
1824 | + $registrations = $payment->transaction()->registrations(); |
|
1825 | + $REG_IDs = ! empty($registrations) |
|
1826 | + ? array_keys($registrations) |
|
1827 | + : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1828 | + } |
|
1829 | + |
|
1830 | + // ensure that REG_IDs are integers and NOT strings |
|
1831 | + return array_map('intval', $REG_IDs); |
|
1832 | + } |
|
1833 | + |
|
1834 | + |
|
1835 | + /** |
|
1836 | + * @return array |
|
1837 | + */ |
|
1838 | + public function existing_reg_payment_REG_IDs() |
|
1839 | + { |
|
1840 | + return $this->_existing_reg_payment_REG_IDs; |
|
1841 | + } |
|
1842 | + |
|
1843 | + |
|
1844 | + /** |
|
1845 | + * @param array $existing_reg_payment_REG_IDs |
|
1846 | + */ |
|
1847 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
1848 | + { |
|
1849 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
1850 | + } |
|
1851 | + |
|
1852 | + |
|
1853 | + /** |
|
1854 | + * _get_existing_reg_payment_REG_IDs |
|
1855 | + * returns a list of registration IDs that the payment is currently related to |
|
1856 | + * as recorded in the database |
|
1857 | + * |
|
1858 | + * @param \EE_Payment $payment |
|
1859 | + * @return array |
|
1860 | + * @throws EE_Error |
|
1861 | + */ |
|
1862 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
1863 | + { |
|
1864 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
1865 | + // let's get any existing reg payment records for this payment |
|
1866 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
1867 | + // but we only want the REG IDs, so grab the array keys |
|
1868 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
1869 | + ? array_keys($existing_reg_payment_REG_IDs) |
|
1870 | + : array(); |
|
1871 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
1872 | + } |
|
1873 | + |
|
1874 | + return $this->existing_reg_payment_REG_IDs(); |
|
1875 | + } |
|
1876 | + |
|
1877 | + |
|
1878 | + /** |
|
1879 | + * _remove_existing_registration_payments |
|
1880 | + * this calculates the difference between existing relations |
|
1881 | + * to the supplied payment and the new list registration IDs, |
|
1882 | + * removes any related registrations that no longer apply, |
|
1883 | + * and then updates the registration paid fields |
|
1884 | + * |
|
1885 | + * @param \EE_Payment $payment |
|
1886 | + * @param int $PAY_ID |
|
1887 | + * @return bool; |
|
1888 | + * @throws EE_Error |
|
1889 | + * @throws InvalidArgumentException |
|
1890 | + * @throws ReflectionException |
|
1891 | + * @throws InvalidDataTypeException |
|
1892 | + * @throws InvalidInterfaceException |
|
1893 | + */ |
|
1894 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
1895 | + { |
|
1896 | + // newly created payments will have nothing recorded for $PAY_ID |
|
1897 | + if ($PAY_ID == 0) { |
|
1898 | + return false; |
|
1899 | + } |
|
1900 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
1901 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
1902 | + return false; |
|
1903 | + } |
|
1904 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
1905 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
1906 | + |
|
1907 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
1908 | + $payment, |
|
1909 | + array( |
|
1910 | + array( |
|
1911 | + 'PAY_ID' => $payment->ID(), |
|
1912 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
1913 | + ), |
|
1914 | + ) |
|
1915 | + ); |
|
1916 | + } |
|
1917 | + |
|
1918 | + |
|
1919 | + /** |
|
1920 | + * _update_registration_payments |
|
1921 | + * this applies the payments to the selected registrations |
|
1922 | + * but only if they have not already been paid for |
|
1923 | + * |
|
1924 | + * @param EE_Transaction $transaction |
|
1925 | + * @param \EE_Payment $payment |
|
1926 | + * @param array $REG_IDs |
|
1927 | + * @return void |
|
1928 | + * @throws EE_Error |
|
1929 | + * @throws InvalidArgumentException |
|
1930 | + * @throws ReflectionException |
|
1931 | + * @throws RuntimeException |
|
1932 | + * @throws InvalidDataTypeException |
|
1933 | + * @throws InvalidInterfaceException |
|
1934 | + */ |
|
1935 | + protected function _update_registration_payments( |
|
1936 | + EE_Transaction $transaction, |
|
1937 | + EE_Payment $payment, |
|
1938 | + $REG_IDs = array() |
|
1939 | + ) { |
|
1940 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
1941 | + // so let's do that using our set of REG_IDs from the form |
|
1942 | + $registration_query_where_params = array( |
|
1943 | + 'REG_ID' => array('IN', $REG_IDs), |
|
1944 | + ); |
|
1945 | + // but add in some conditions regarding payment, |
|
1946 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
1947 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
1948 | + if (! $payment->is_a_refund()) { |
|
1949 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
1950 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
1951 | + } |
|
1952 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
1953 | + if (! empty($registrations)) { |
|
1954 | + /** @type EE_Payment_Processor $payment_processor */ |
|
1955 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
1956 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
1957 | + } |
|
1958 | + } |
|
1959 | + |
|
1960 | + |
|
1961 | + /** |
|
1962 | + * _process_registration_status_change |
|
1963 | + * This processes requested registration status changes for all the registrations |
|
1964 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
1965 | + * |
|
1966 | + * @param EE_Transaction $transaction |
|
1967 | + * @param array $REG_IDs |
|
1968 | + * @return bool |
|
1969 | + * @throws EE_Error |
|
1970 | + * @throws InvalidArgumentException |
|
1971 | + * @throws ReflectionException |
|
1972 | + * @throws InvalidDataTypeException |
|
1973 | + * @throws InvalidInterfaceException |
|
1974 | + */ |
|
1975 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
1976 | + { |
|
1977 | + // first if there is no change in status then we get out. |
|
1978 | + if ( |
|
1979 | + ! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
1980 | + || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
1981 | + ) { |
|
1982 | + //no error message, no change requested, just nothing to do man. |
|
1983 | + return false; |
|
1984 | + } |
|
1985 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
1986 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1987 | + |
|
1988 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
1989 | + return $transaction_processor->manually_update_registration_statuses( |
|
1990 | + $transaction, |
|
1991 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
1992 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
1993 | + ); |
|
1994 | + } |
|
1995 | + |
|
1996 | + |
|
1997 | + /** |
|
1998 | + * _build_payment_json_response |
|
1999 | + * |
|
2000 | + * @access public |
|
2001 | + * @param \EE_Payment $payment |
|
2002 | + * @param array $REG_IDs |
|
2003 | + * @param bool | null $delete_txn_reg_status_change |
|
2004 | + * @return array |
|
2005 | + * @throws EE_Error |
|
2006 | + * @throws InvalidArgumentException |
|
2007 | + * @throws InvalidDataTypeException |
|
2008 | + * @throws InvalidInterfaceException |
|
2009 | + */ |
|
2010 | + protected function _build_payment_json_response( |
|
2011 | + EE_Payment $payment, |
|
2012 | + $REG_IDs = array(), |
|
2013 | + $delete_txn_reg_status_change = null |
|
2014 | + ) { |
|
2015 | + // was the payment deleted ? |
|
2016 | + if (is_bool($delete_txn_reg_status_change)) { |
|
2017 | + return array( |
|
2018 | + 'PAY_ID' => $payment->ID(), |
|
2019 | + 'amount' => $payment->amount(), |
|
2020 | + 'total_paid' => $payment->transaction()->paid(), |
|
2021 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
2022 | + 'pay_status' => $payment->STS_ID(), |
|
2023 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
2024 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
2025 | + ); |
|
2026 | + } else { |
|
2027 | + $this->_get_payment_status_array(); |
|
2028 | + |
|
2029 | + return array( |
|
2030 | + 'amount' => $payment->amount(), |
|
2031 | + 'total_paid' => $payment->transaction()->paid(), |
|
2032 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
2033 | + 'pay_status' => $payment->STS_ID(), |
|
2034 | + 'PAY_ID' => $payment->ID(), |
|
2035 | + 'STS_ID' => $payment->STS_ID(), |
|
2036 | + 'status' => self::$_pay_status[$payment->STS_ID()], |
|
2037 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
2038 | + 'method' => strtoupper($payment->source()), |
|
2039 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
2040 | + 'gateway' => $payment->payment_method() |
|
2041 | + ? $payment->payment_method()->admin_name() |
|
2042 | + : esc_html__("Unknown", 'event_espresso'), |
|
2043 | + 'gateway_response' => $payment->gateway_response(), |
|
2044 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
2045 | + 'po_number' => $payment->po_number(), |
|
2046 | + 'extra_accntng' => $payment->extra_accntng(), |
|
2047 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
2048 | + ); |
|
2049 | + } |
|
2050 | + } |
|
2051 | + |
|
2052 | + |
|
2053 | + /** |
|
2054 | + * delete_payment |
|
2055 | + * delete a payment or refund made towards a transaction |
|
2056 | + * |
|
2057 | + * @access public |
|
2058 | + * @return void |
|
2059 | + * @throws EE_Error |
|
2060 | + * @throws InvalidArgumentException |
|
2061 | + * @throws ReflectionException |
|
2062 | + * @throws InvalidDataTypeException |
|
2063 | + * @throws InvalidInterfaceException |
|
2064 | + */ |
|
2065 | + public function delete_payment() |
|
2066 | + { |
|
2067 | + $json_response_data = array('return_data' => false); |
|
2068 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
2069 | + ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
2070 | + : 0; |
|
2071 | + $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
2072 | + 'ee_delete_payments', |
|
2073 | + 'delete_payment_from_registration_details' |
|
2074 | + ); |
|
2075 | + if ($PAY_ID && $can_delete) { |
|
2076 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
2077 | + ? $this->_req_data['delete_txn_reg_status_change'] |
|
2078 | + : false; |
|
2079 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
2080 | + if ($payment instanceof EE_Payment) { |
|
2081 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
2082 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
2083 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
2084 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
2085 | + $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
2086 | + $payment, |
|
2087 | + $REG_IDs, |
|
2088 | + $delete_txn_reg_status_change |
|
2089 | + ); |
|
2090 | + if ($delete_txn_reg_status_change) { |
|
2091 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
2092 | + //MAKE sure we also add the delete_txn_req_status_change to the |
|
2093 | + //$_REQUEST global because that's how messages will be looking for it. |
|
2094 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
2095 | + $this->_maybe_send_notifications(); |
|
2096 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
2097 | + } |
|
2098 | + } |
|
2099 | + } else { |
|
2100 | + EE_Error::add_error( |
|
2101 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
2102 | + __FILE__, __FUNCTION__, __LINE__ |
|
2103 | + ); |
|
2104 | + } |
|
2105 | + } else { |
|
2106 | + if ($can_delete) { |
|
2107 | + EE_Error::add_error( |
|
2108 | + esc_html__( |
|
2109 | + 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
2110 | + 'event_espresso' |
|
2111 | + ), |
|
2112 | + __FILE__, __FUNCTION__, __LINE__ |
|
2113 | + ); |
|
2114 | + } else { |
|
2115 | + EE_Error::add_error( |
|
2116 | + esc_html__( |
|
2117 | + 'You do not have access to delete a payment.', |
|
2118 | + 'event_espresso' |
|
2119 | + ), |
|
2120 | + __FILE__, |
|
2121 | + __FUNCTION__, |
|
2122 | + __LINE__ |
|
2123 | + ); |
|
2124 | + } |
|
2125 | + } |
|
2126 | + $notices = EE_Error::get_notices(false, false, false); |
|
2127 | + $this->_template_args = array( |
|
2128 | + 'data' => $json_response_data, |
|
2129 | + 'success' => $notices['success'], |
|
2130 | + 'error' => $notices['errors'], |
|
2131 | + 'attention' => $notices['attention'], |
|
2132 | + ); |
|
2133 | + $this->_return_json(); |
|
2134 | + } |
|
2135 | + |
|
2136 | + |
|
2137 | + /** |
|
2138 | + * _registration_payment_data_array |
|
2139 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
2140 | + * |
|
2141 | + * @access protected |
|
2142 | + * @param array $REG_IDs |
|
2143 | + * @return array |
|
2144 | + * @throws EE_Error |
|
2145 | + * @throws InvalidArgumentException |
|
2146 | + * @throws InvalidDataTypeException |
|
2147 | + * @throws InvalidInterfaceException |
|
2148 | + */ |
|
2149 | + protected function _registration_payment_data_array($REG_IDs) |
|
2150 | + { |
|
2151 | + $registration_payment_data = array(); |
|
2152 | + //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
2153 | + if (! empty($REG_IDs)) { |
|
2154 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
2155 | + foreach ($registrations as $registration) { |
|
2156 | + if ($registration instanceof EE_Registration) { |
|
2157 | + $registration_payment_data[$registration->ID()] = array( |
|
2158 | + 'paid' => $registration->pretty_paid(), |
|
2159 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
2160 | + ); |
|
2161 | + } |
|
2162 | + } |
|
2163 | + } |
|
2164 | + |
|
2165 | + return $registration_payment_data; |
|
2166 | + } |
|
2167 | + |
|
2168 | + |
|
2169 | + /** |
|
2170 | + * _maybe_send_notifications |
|
2171 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
2172 | + * If so, will toggle a filter switch for delivering registration notices. |
|
2173 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
2174 | + * |
|
2175 | + * @access protected |
|
2176 | + * @param \EE_Payment | null $payment |
|
2177 | + */ |
|
2178 | + protected function _maybe_send_notifications($payment = null) |
|
2179 | + { |
|
2180 | + switch ($payment instanceof EE_Payment) { |
|
2181 | + // payment notifications |
|
2182 | + case true : |
|
2183 | + if ( |
|
2184 | + isset( |
|
2185 | + $this->_req_data['txn_payments'], |
|
2186 | + $this->_req_data['txn_payments']['send_notifications'] |
|
2187 | + ) && |
|
2188 | + filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
2189 | + ) { |
|
2190 | + $this->_process_payment_notification($payment); |
|
2191 | + } |
|
2192 | + break; |
|
2193 | + // registration notifications |
|
2194 | + case false : |
|
2195 | + if ( |
|
2196 | + isset( |
|
2197 | + $this->_req_data['txn_reg_status_change'], |
|
2198 | + $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
2199 | + ) && |
|
2200 | + filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
2201 | + ) { |
|
2202 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
2203 | + } |
|
2204 | + break; |
|
2205 | + } |
|
2206 | + } |
|
2207 | + |
|
2208 | + |
|
2209 | + /** |
|
2210 | + * _send_payment_reminder |
|
2211 | + * generates HTML for the View Transaction Details Admin page |
|
2212 | + * |
|
2213 | + * @access protected |
|
2214 | + * @return void |
|
2215 | + * @throws EE_Error |
|
2216 | + * @throws InvalidArgumentException |
|
2217 | + * @throws InvalidDataTypeException |
|
2218 | + * @throws InvalidInterfaceException |
|
2219 | + */ |
|
2220 | + protected function _send_payment_reminder() |
|
2221 | + { |
|
2222 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
2223 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2224 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
2225 | + 'action' => $this->_req_data['redirect_to'], |
|
2226 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
2227 | + ) : array(); |
|
2228 | + do_action( |
|
2229 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
2230 | + $transaction |
|
2231 | + ); |
|
2232 | + $this->_redirect_after_action( |
|
2233 | + false, |
|
2234 | + esc_html__('payment reminder', 'event_espresso'), |
|
2235 | + esc_html__('sent', 'event_espresso'), |
|
2236 | + $query_args, |
|
2237 | + true |
|
2238 | + ); |
|
2239 | + } |
|
2240 | + |
|
2241 | + |
|
2242 | + /** |
|
2243 | + * get_transactions |
|
2244 | + * get transactions for given parameters (used by list table) |
|
2245 | + * |
|
2246 | + * @param int $perpage how many transactions displayed per page |
|
2247 | + * @param boolean $count return the count or objects |
|
2248 | + * @param string $view |
|
2249 | + * @return mixed int = count || array of transaction objects |
|
2250 | + * @throws EE_Error |
|
2251 | + * @throws InvalidArgumentException |
|
2252 | + * @throws InvalidDataTypeException |
|
2253 | + * @throws InvalidInterfaceException |
|
2254 | + */ |
|
2255 | + public function get_transactions($perpage, $count = false, $view = '') |
|
2256 | + { |
|
2257 | + |
|
2258 | + $TXN = EEM_Transaction::instance(); |
|
2259 | + |
|
2260 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
2261 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
2262 | + : date( |
|
2263 | + 'm/d/Y', |
|
2264 | + strtotime('-10 year') |
|
2265 | + ); |
|
2266 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
2267 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
2268 | + : date('m/d/Y'); |
|
2269 | + |
|
2270 | + //make sure our timestamps start and end right at the boundaries for each day |
|
2271 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
2272 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
2273 | + |
|
2274 | + |
|
2275 | + //convert to timestamps |
|
2276 | + $start_date = strtotime($start_date); |
|
2277 | + $end_date = strtotime($end_date); |
|
2278 | + |
|
2279 | + //makes sure start date is the lowest value and vice versa |
|
2280 | + $start_date = min($start_date, $end_date); |
|
2281 | + $end_date = max($start_date, $end_date); |
|
2282 | + |
|
2283 | + //convert to correct format for query |
|
2284 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
2285 | + 'TXN_timestamp', |
|
2286 | + date('Y-m-d H:i:s', $start_date), |
|
2287 | + 'Y-m-d H:i:s' |
|
2288 | + ); |
|
2289 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
2290 | + 'TXN_timestamp', |
|
2291 | + date('Y-m-d H:i:s', $end_date), |
|
2292 | + 'Y-m-d H:i:s' |
|
2293 | + ); |
|
2294 | + |
|
2295 | + |
|
2296 | + //set orderby |
|
2297 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
2298 | + |
|
2299 | + switch ($this->_req_data['orderby']) { |
|
2300 | + case 'TXN_ID': |
|
2301 | + $orderby = 'TXN_ID'; |
|
2302 | + break; |
|
2303 | + case 'ATT_fname': |
|
2304 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
2305 | + break; |
|
2306 | + case 'event_name': |
|
2307 | + $orderby = 'Registration.Event.EVT_name'; |
|
2308 | + break; |
|
2309 | + default: //'TXN_timestamp' |
|
2310 | + $orderby = 'TXN_timestamp'; |
|
2311 | + } |
|
2312 | + |
|
2313 | + $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2314 | + $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
2315 | + $per_page = ! empty($perpage) ? $perpage : 10; |
|
2316 | + $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
2317 | + |
|
2318 | + $offset = ($current_page - 1) * $per_page; |
|
2319 | + $limit = array($offset, $per_page); |
|
2320 | + |
|
2321 | + $_where = array( |
|
2322 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
2323 | + 'Registration.REG_count' => 1, |
|
2324 | + ); |
|
2325 | + |
|
2326 | + if (isset($this->_req_data['EVT_ID'])) { |
|
2327 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
2328 | + } |
|
2329 | + |
|
2330 | + if (isset($this->_req_data['s'])) { |
|
2331 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
2332 | + $_where['OR'] = array( |
|
2333 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
2334 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
2335 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
2336 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
2337 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
2338 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
2339 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
2340 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
2341 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
2342 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
2343 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
2344 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
2345 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
2346 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
2347 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
2348 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
2349 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
2350 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
2351 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
2352 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
2353 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
2354 | + ); |
|
2355 | + } |
|
2356 | + |
|
2357 | + //failed transactions |
|
2358 | + $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
2359 | + || ($count && $view === 'failed'); |
|
2360 | + $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
2361 | + || ($count && $view === 'abandoned'); |
|
2362 | + |
|
2363 | + if ($failed) { |
|
2364 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
2365 | + } else if ($abandoned) { |
|
2366 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
2367 | + } else { |
|
2368 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
2369 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
2370 | + } |
|
2371 | + |
|
2372 | + $query_params = array( |
|
2373 | + $_where, |
|
2374 | + 'order_by' => array($orderby => $sort), |
|
2375 | + 'limit' => $limit, |
|
2376 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
2377 | + ); |
|
2378 | + |
|
2379 | + $transactions = $count |
|
2380 | + ? $TXN->count(array($_where), 'TXN_ID', true) |
|
2381 | + : $TXN->get_all($query_params); |
|
2382 | + |
|
2383 | + return $transactions; |
|
2384 | + } |
|
2385 | 2385 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | <div id="payment-accntng-<?php echo $PAY_ID; ?>"><?php echo $payment->extra_accntng(); ?></div> |
160 | 160 | </td> |
161 | 161 | <td class=" jst-rght"> |
162 | - <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-' . $payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?> |
|
162 | + <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-'.$payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?> |
|
163 | 163 | <span class="<?php echo $payment_class; ?>"> |
164 | 164 | <div id="payment-amount-<?php echo $PAY_ID; ?>" |
165 | 165 | style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(), |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | <?php endforeach; // $payment?> |
174 | 174 | <?php |
175 | 175 | $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
176 | - $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', |
|
177 | - 'event_espresso') . '</span>' : ''; |
|
176 | + $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">'.esc_html__('This transaction has been overpaid ! ', |
|
177 | + 'event_espresso').'</span>' : ''; |
|
178 | 178 | ?> |
179 | 179 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden"> |
180 | 180 | <td class=" jst-rght" colspan="11"> |
@@ -184,9 +184,9 @@ discard block |
||
184 | 184 | <tr id="txn-admin-payments-total-tr" |
185 | 185 | class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>"> |
186 | 186 | <th class=" jst-rght" colspan="10"><span |
187 | - id="payments-total-spn"><?php echo $overpaid . sprintf(esc_html__('Payments Total %s', |
|
187 | + id="payments-total-spn"><?php echo $overpaid.sprintf(esc_html__('Payments Total %s', |
|
188 | 188 | 'event_espresso'), |
189 | - '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th> |
|
189 | + '('.EE_Registry::instance()->CFG->currency->code.')'); ?></span></th> |
|
190 | 190 | <th class=" jst-rght"><span |
191 | 191 | id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, |
192 | 192 | false, false); ?></span></th> |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | <h2 id="admin-modal-dialog-apply-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
300 | 300 | style="display:none;"> |
301 | 301 | <div class="ee-icon ee-icon-cash-add float-left"></div> |
302 | - <?php echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . $txn_nmbr['value']; ?> |
|
302 | + <?php echo esc_html__('Apply a Payment to Transaction #', 'event_espresso').$txn_nmbr['value']; ?> |
|
303 | 303 | </h2> |
304 | 304 | |
305 | 305 | <h2 id="admin-modal-dialog-edit-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
329 | 329 | style="display:none;"> |
330 | 330 | <div class="ee-icon ee-icon-cash-remove float-left"></div> |
331 | - <?php echo esc_html__('Apply a Refund to Transaction #', 'event_espresso') . $txn_nmbr['value']; ?> |
|
331 | + <?php echo esc_html__('Apply a Refund to Transaction #', 'event_espresso').$txn_nmbr['value']; ?> |
|
332 | 332 | </h2> |
333 | 333 | |
334 | 334 | <form name="txn-admin-apply-payment-frm" id="txn-admin-apply-payment-frm" |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | style="display:none;"> |
558 | 558 | <span class="ee-icon ee-icon-cash-add"></span> |
559 | 559 | <?php echo esc_html__('Delete Payment/Refund for Transaction #', |
560 | - 'event_espresso') . $txn_nmbr['value']; ?> |
|
560 | + 'event_espresso').$txn_nmbr['value']; ?> |
|
561 | 561 | </h2> |
562 | 562 | |
563 | 563 | <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm" |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) : |
644 | 644 | ?> |
645 | 645 | <tr> |
646 | - <td class="jst-left"><?php echo date(get_option('date_format') . ' ' . get_option('time_format'), |
|
646 | + <td class="jst-left"><?php echo date(get_option('date_format').' '.get_option('time_format'), |
|
647 | 647 | ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td> |
648 | 648 | <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td> |
649 | 649 | <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td> |
@@ -191,10 +191,13 @@ discard block |
||
191 | 191 | id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, |
192 | 192 | false, false); ?></span></th> |
193 | 193 | </tr> |
194 | - <?php else : ?> |
|
194 | + <?php else { |
|
195 | + : ?> |
|
195 | 196 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr"> |
196 | 197 | <td class=" jst-rght" colspan="11"> |
197 | - <span class="important-notice"><?php echo $no_payment_text; ?></span> |
|
198 | + <span class="important-notice"><?php echo $no_payment_text; |
|
199 | +} |
|
200 | +?></span> |
|
198 | 201 | </td> |
199 | 202 | </tr> |
200 | 203 | <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden"> |
@@ -285,10 +288,13 @@ discard block |
||
285 | 288 | <?php esc_html_e('Apply Refund', 'event_espresso'); ?> |
286 | 289 | </a> |
287 | 290 | </li> |
288 | - <?php else : ?> |
|
291 | + <?php else { |
|
292 | + : ?> |
|
289 | 293 | <li> |
290 | 294 | <p><?php esc_html__('You do not have access to apply payments or refunds.', |
291 | - 'event_espresso'); ?></p> |
|
295 | + 'event_espresso'); |
|
296 | +} |
|
297 | +?></p> |
|
292 | 298 | </li> |
293 | 299 | <?php endif; ?> |
294 | 300 | </ul> |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | <a id="display-additional-transaction-session-info" class="display-the-hidden smaller-text" |
13 | 13 | rel="additional-transaction-session-info"> |
14 | 14 | <span class="dashicons dashicons-plus-alt"></span><?php esc_html_e('view additional transaction session details', |
15 | - 'event_espresso'); ?> |
|
15 | + 'event_espresso'); ?> |
|
16 | 16 | </a> |
17 | 17 | |
18 | 18 | <div id="additional-transaction-session-info-dv" class="hidden"> |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | <a id="hide-additional-transaction-session-info" class="hide-the-displayed hidden smaller-text" |
21 | 21 | rel="additional-transaction-session-info"> |
22 | 22 | <span class="dashicons dashicons-dismiss"></span><?php esc_html_e('hide additional transaction session details', |
23 | - 'event_espresso'); ?> |
|
23 | + 'event_espresso'); ?> |
|
24 | 24 | </a> |
25 | 25 | <br class="clear"/> |
26 | 26 | |
@@ -45,16 +45,16 @@ discard block |
||
45 | 45 | |
46 | 46 | |
47 | 47 | <?php if ($attendee instanceof EE_Attendee && ($grand_raw_total > 0 || $TXN_status !== EEM_Transaction::complete_status_code || ! empty($payments))) : |
48 | - $no_payment_text = $can_edit_payments |
|
49 | - ? esc_html__( |
|
50 | - 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
51 | - 'event_espresso' |
|
52 | - ) |
|
53 | - : esc_html__( |
|
54 | - 'No payments have been applied to this transaction yet.', |
|
55 | - 'event_espresso' |
|
56 | - ); |
|
57 | - ?> |
|
48 | + $no_payment_text = $can_edit_payments |
|
49 | + ? esc_html__( |
|
50 | + 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
51 | + 'event_espresso' |
|
52 | + ) |
|
53 | + : esc_html__( |
|
54 | + 'No payments have been applied to this transaction yet.', |
|
55 | + 'event_espresso' |
|
56 | + ); |
|
57 | + ?> |
|
58 | 58 | |
59 | 59 | <h3 class="admin-primary-mbox-h4 hdr-has-icon"> |
60 | 60 | <span class="ee-icon ee-icon-cash"></span><?php esc_html_e('Payment Details', 'event_espresso'); ?> |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | <?php if ($payments) : ?> |
83 | 83 | <?php $payment_total = 0; ?> |
84 | 84 | <?php foreach ($payments as $PAY_ID => $payment) : |
85 | - $existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID]) |
|
86 | - ? wp_json_encode($existing_reg_payments[$PAY_ID]) |
|
87 | - : '{}'; |
|
88 | - ?> |
|
85 | + $existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID]) |
|
86 | + ? wp_json_encode($existing_reg_payments[$PAY_ID]) |
|
87 | + : '{}'; |
|
88 | + ?> |
|
89 | 89 | <tr id="txn-admin-payment-tr-<?php echo $PAY_ID; ?>"> |
90 | 90 | <td> |
91 | 91 | <span id="payment-status-<?php echo $PAY_ID; ?>" |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | <td class=" jst-left"> |
133 | 133 | <div id="payment-gateway-<?php echo $PAY_ID; ?>"> |
134 | 134 | <?php echo $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
135 | - 'event_espresso'); ?> |
|
135 | + 'event_espresso'); ?> |
|
136 | 136 | </div> |
137 | 137 | <div id="payment-gateway-id-<?php echo $PAY_ID; ?>" |
138 | 138 | class="hidden"><?php echo $payment->payment_method() ? $payment->payment_method()->ID() : 0; ?></div> |
@@ -154,19 +154,19 @@ discard block |
||
154 | 154 | <span class="<?php echo $payment_class; ?>"> |
155 | 155 | <div id="payment-amount-<?php echo $PAY_ID; ?>" |
156 | 156 | style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(), |
157 | - false, false); ?></div> |
|
157 | + false, false); ?></div> |
|
158 | 158 | </span> |
159 | 159 | </td> |
160 | 160 | </tr> |
161 | 161 | <?php |
162 | - $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; |
|
163 | - ?> |
|
162 | + $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; |
|
163 | + ?> |
|
164 | 164 | <?php endforeach; // $payment?> |
165 | 165 | <?php |
166 | - $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
|
167 | - $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', |
|
168 | - 'event_espresso') . '</span>' : ''; |
|
169 | - ?> |
|
166 | + $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
|
167 | + $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', |
|
168 | + 'event_espresso') . '</span>' : ''; |
|
169 | + ?> |
|
170 | 170 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden"> |
171 | 171 | <td class=" jst-rght" colspan="11"> |
172 | 172 | <span class="important-notice"><?php echo $no_payment_text; ?></span> |
@@ -176,11 +176,11 @@ discard block |
||
176 | 176 | class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>"> |
177 | 177 | <th class=" jst-rght" colspan="10"><span |
178 | 178 | id="payments-total-spn"><?php echo $overpaid . sprintf(esc_html__('Payments Total %s', |
179 | - 'event_espresso'), |
|
180 | - '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th> |
|
179 | + 'event_espresso'), |
|
180 | + '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th> |
|
181 | 181 | <th class=" jst-rght"><span |
182 | 182 | id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, |
183 | - false, false); ?></span></th> |
|
183 | + false, false); ?></span></th> |
|
184 | 184 | </tr> |
185 | 185 | <?php else : ?> |
186 | 186 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr"> |
@@ -191,11 +191,11 @@ discard block |
||
191 | 191 | <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden"> |
192 | 192 | <th class=" jst-rght" colspan="10"><span |
193 | 193 | id="payments-total-spn"><?php echo esc_html__('Payments Total', |
194 | - 'event_espresso'); ?></span></th> |
|
194 | + 'event_espresso'); ?></span></th> |
|
195 | 195 | <th class=" jst-rght"><span id="txn-admin-payment-total"></span></th> |
196 | 196 | </tr> |
197 | 197 | <?php endif; // $payments |
198 | - ?> |
|
198 | + ?> |
|
199 | 199 | |
200 | 200 | <tr id="txn-admin-payment-empty-row-tr" class="hidden"> |
201 | 201 | <td> |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | |
261 | 261 | <ul id="txn-admin-payment-options-ul"> |
262 | 262 | <?php if ($can_edit_payments) : |
263 | - ?> |
|
263 | + ?> |
|
264 | 264 | <li> |
265 | 265 | <a id="display-txn-admin-apply-payment" class="button-primary no-icon no-hide" |
266 | 266 | rel="txn-admin-apply-payment"> <!--display-the-hidden --> |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | <?php else : ?> |
277 | 277 | <li> |
278 | 278 | <p><?php esc_html__('You do not have access to apply payments or refunds.', |
279 | - 'event_espresso'); ?></p> |
|
279 | + 'event_espresso'); ?></p> |
|
280 | 280 | </li> |
281 | 281 | <?php endif; ?> |
282 | 282 | </ul> |
@@ -294,23 +294,23 @@ discard block |
||
294 | 294 | style="display:none;"> |
295 | 295 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
296 | 296 | <?php |
297 | - echo sprintf( |
|
298 | - __('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
299 | - '<span></span>', |
|
300 | - $txn_nmbr['value'] |
|
301 | - ); |
|
302 | - ?> |
|
297 | + echo sprintf( |
|
298 | + __('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
299 | + '<span></span>', |
|
300 | + $txn_nmbr['value'] |
|
301 | + ); |
|
302 | + ?> |
|
303 | 303 | </h2> |
304 | 304 | |
305 | 305 | <h2 id="admin-modal-dialog-edit-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;"> |
306 | 306 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
307 | 307 | <?php |
308 | - echo sprintf( |
|
309 | - __('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
310 | - '<span></span>', |
|
311 | - $txn_nmbr['value'] |
|
312 | - ); |
|
313 | - ?> |
|
308 | + echo sprintf( |
|
309 | + __('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
310 | + '<span></span>', |
|
311 | + $txn_nmbr['value'] |
|
312 | + ); |
|
313 | + ?> |
|
314 | 314 | </h2> |
315 | 315 | |
316 | 316 | <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
@@ -343,55 +343,55 @@ discard block |
||
343 | 343 | |
344 | 344 | <div class="txn-admin-apply-payment-date-dv admin-modal-dialog-row"> |
345 | 345 | <div class="validation-notice-dv"><?php esc_html_e('The following is a required field', |
346 | - 'event_espresso'); ?></div> |
|
346 | + 'event_espresso'); ?></div> |
|
347 | 347 | <label for="txn-admin-payment-date-inp" class=""><?php esc_html_e('Payment Date', |
348 | - 'event_espresso'); ?></label> |
|
348 | + 'event_espresso'); ?></label> |
|
349 | 349 | <input name="txn_admin_payment[date]" id="txn-admin-payment-date-inp" |
350 | 350 | class="txn-admin-apply-payment-inp required" type="text" |
351 | 351 | value="<?php echo date('Y-m-d g:i a', current_time('timestamp')); ?>"/> |
352 | 352 | <p class="description"><?php esc_html_e('The date the payment was actually made on', |
353 | - 'event_espresso'); ?></p> |
|
353 | + 'event_espresso'); ?></p> |
|
354 | 354 | </div> |
355 | 355 | |
356 | 356 | <div class="txn-admin-apply-payment-amount-dv admin-modal-dialog-row"> |
357 | 357 | <div class="validation-notice-dv"><?php esc_html_e('The following is a required field', |
358 | - 'event_espresso'); ?></div> |
|
358 | + 'event_espresso'); ?></div> |
|
359 | 359 | <label for="txn-admin-payment-amount-inp" class=""><?php esc_html_e('Amount', |
360 | - 'event_espresso'); ?></label> |
|
360 | + 'event_espresso'); ?></label> |
|
361 | 361 | <input name="txn_admin_payment[amount]" id="txn-admin-payment-amount-inp" |
362 | 362 | class="txn-admin-apply-payment-inp required" type="text" value=""/> |
363 | 363 | <p class="description"><?php esc_html_e('The amount of the payment', |
364 | - 'event_espresso'); ?></p> |
|
364 | + 'event_espresso'); ?></p> |
|
365 | 365 | </div> |
366 | 366 | |
367 | 367 | <div class="txn-admin-apply-payment-method-dv admin-modal-dialog-row"> |
368 | 368 | <div class="validation-notice-dv"><?php esc_html_e('The following is a required field', |
369 | - 'event_espresso'); ?></div> |
|
369 | + 'event_espresso'); ?></div> |
|
370 | 370 | <label for="txn-admin-payment-method-inp" class=""><?php esc_html_e('Method of Payment', |
371 | - 'event_espresso'); ?></label> |
|
371 | + 'event_espresso'); ?></label> |
|
372 | 372 | <select name="txn_admin_payment[PMD_ID]" id="txn-admin-payment-method-slct" |
373 | 373 | class="txn-admin-apply-payment-slct required" type="text"> |
374 | 374 | <?php foreach ($payment_methods as $method) : ?> |
375 | 375 | <?php $selected = $method->slug() == 'cash' ? ' selected="selected"' : ''; ?> |
376 | 376 | <option id="payment-method-opt-<?php echo $method->slug(); ?>" |
377 | 377 | value="<?php echo $method->ID(); ?>"<?php echo $selected; ?>><?php echo sanitize_key($method->admin_desc()) ? substr($method->admin_desc(), |
378 | - 0, 128) : $method->admin_name(); ?> |
|
378 | + 0, 128) : $method->admin_name(); ?> |
|
379 | 379 | </option> |
380 | 380 | <?php endforeach; ?> |
381 | 381 | </select> |
382 | 382 | <p class="description"><?php esc_html_e('Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', |
383 | - 'event_espresso'); ?></p> |
|
383 | + 'event_espresso'); ?></p> |
|
384 | 384 | </div> |
385 | 385 | |
386 | 386 | <div class="mop-PP mop-CC mop-CHQ mop"> |
387 | 387 | <div class="txn-admin-apply-payment-gw-txn-id-dv admin-modal-dialog-row"> |
388 | 388 | <label for="txn-admin-payment-txn-id-inp" class=""><?php esc_html_e('TXN ID / CHQ #', |
389 | - 'event_espresso'); ?></label> |
|
389 | + 'event_espresso'); ?></label> |
|
390 | 390 | <input name="txn_admin_payment[txn_id_chq_nmbr]" |
391 | 391 | id="txn-admin-payment-txn-id-chq-nmbr-inp" class="txn-admin-apply-payment-inp" |
392 | 392 | type="text" maxlength="100"/> |
393 | 393 | <p class="description"><?php esc_html_e('The Transaction ID sent back from the payment gateway, or the Cheque #', |
394 | - 'event_espresso'); ?></p> |
|
394 | + 'event_espresso'); ?></p> |
|
395 | 395 | </div> |
396 | 396 | </div> |
397 | 397 | |
@@ -403,14 +403,14 @@ discard block |
||
403 | 403 | id="txn-admin-payment-gateway-response-inp" class="txn-admin-apply-payment-inp" |
404 | 404 | type="text"/> |
405 | 405 | <p class="description"><?php esc_html_e('The gateway response string (optional)', |
406 | - 'event_espresso'); ?></p> |
|
406 | + 'event_espresso'); ?></p> |
|
407 | 407 | </div> |
408 | 408 | </div> |
409 | 409 | |
410 | 410 | <div class="mop-PP mop-CC mop"> |
411 | 411 | <div class="txn-admin-apply-payment-status-dv admin-modal-dialog-row"> |
412 | 412 | <label for="txn-admin-payment-status-inp" class=""><?php esc_html_e('Payment Status', |
413 | - 'event_espresso'); ?></label> |
|
413 | + 'event_espresso'); ?></label> |
|
414 | 414 | <select name="txn_admin_payment[status]" id="txn-admin-payment-status-slct" |
415 | 415 | class="txn-admin-apply-payment-slct" type="text"> |
416 | 416 | <?php foreach ($payment_status as $STS_ID => $STS_code) : ?> |
@@ -422,35 +422,35 @@ discard block |
||
422 | 422 | <?php endforeach; ?> |
423 | 423 | </select> |
424 | 424 | <p class="description"><?php esc_html_e('Whether the payment was approved, cancelled, declined or failed after submission to the gateway', |
425 | - 'event_espresso'); ?></p> |
|
425 | + 'event_espresso'); ?></p> |
|
426 | 426 | </div> |
427 | 427 | </div> |
428 | 428 | |
429 | 429 | <div class="txn-admin-apply-payment-po-nmbr-dv admin-modal-dialog-row"> |
430 | 430 | <label for="txn-admin-payment-po-nmbr-inp" class=""><?php esc_html_e('P.O. / S.O. #', |
431 | - 'event_espresso'); ?></label> |
|
431 | + 'event_espresso'); ?></label> |
|
432 | 432 | <input name="txn_admin_payment[po_number]" id="txn-admin-payment-po-nmbr-inp" |
433 | 433 | class="txn-admin-apply-payment-inp" type="text" maxlength="100"/> |
434 | 434 | <p class="description"><?php esc_html_e('The Purchase or Sales Order Number if any (optional)', |
435 | - 'event_espresso'); ?></p> |
|
435 | + 'event_espresso'); ?></p> |
|
436 | 436 | </div> |
437 | 437 | |
438 | 438 | <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
439 | 439 | <label for="txn-admin-payment-accounting-inp" |
440 | 440 | class="last"><?php esc_html_e('Notes / Extra Accounting', |
441 | - 'event_espresso'); ?></label> |
|
441 | + 'event_espresso'); ?></label> |
|
442 | 442 | <input name="txn_admin_payment[accounting]" id="txn-admin-payment-accounting-inp" |
443 | 443 | class="txn-admin-apply-payment-inp" type="text" value="<?php echo $REG_code; ?>" |
444 | 444 | maxlength="100"/> <input type="hidden" id="txn-admin-reg-code-inp" |
445 | 445 | value="<?php echo $REG_code; ?>"/> |
446 | 446 | <p class="description"><?php esc_html_e('An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', |
447 | - 'event_espresso'); ?></p> |
|
447 | + 'event_espresso'); ?></p> |
|
448 | 448 | </div> |
449 | 449 | |
450 | 450 | <div class="txn-admin-apply-payment-registrations-dv admin-modal-dialog-row"> |
451 | 451 | <label for="txn-admin-payment-registrations-inp" |
452 | 452 | class="last"><?php esc_html_e('Registrations to Apply Payment to:', |
453 | - 'event_espresso'); ?></label> |
|
453 | + 'event_espresso'); ?></label> |
|
454 | 454 | <label class="txn-admin-apply-payment-to-registrations-lbl"> |
455 | 455 | <input type="radio" value="1" id="txn-admin-apply-payment-to-all-registrations-inp" |
456 | 456 | name="txn_admin_payment[apply_to_all_registrations]" checked="checked"/> |
@@ -467,10 +467,10 @@ discard block |
||
467 | 467 | <div class="txn-admin-payment-reg-status-dv admin-modal-dialog-row"> |
468 | 468 | <label for="txn-admin-payment-reg-status-inp" |
469 | 469 | class="last"><?php esc_html_e('Change Registration Status?', |
470 | - 'event_espresso'); ?></label> |
|
470 | + 'event_espresso'); ?></label> |
|
471 | 471 | <?php echo $status_change_select; ?> |
472 | 472 | <p class="description"><?php esc_html_e('If you wish to change the status for the registrations selected above, then select which status from this dropdown.', |
473 | - 'event_espresso'); ?></p> |
|
473 | + 'event_espresso'); ?></p> |
|
474 | 474 | <br/> |
475 | 475 | </div> |
476 | 476 | |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | </label> |
491 | 491 | <br class="clear-float"/> |
492 | 492 | <p class="description"><?php printf(esc_html__('By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.', |
493 | - 'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p> |
|
493 | + 'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p> |
|
494 | 494 | <label></label> |
495 | 495 | </div> |
496 | 496 | <div class="clear"></div> |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | </li> |
531 | 531 | <li> |
532 | 532 | <span id="ee-ajax-processing-text" style="display:none;"><?php esc_html_e('Processing...', |
533 | - 'event_espresso'); ?></span> |
|
533 | + 'event_espresso'); ?></span> |
|
534 | 534 | </li> |
535 | 535 | </ul> |
536 | 536 | |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | style="display:none;"> |
546 | 546 | <span class="ee-icon ee-icon-cash-add"></span> |
547 | 547 | <?php echo esc_html__('Delete Payment/Refund for Transaction #', |
548 | - 'event_espresso') . $txn_nmbr['value']; ?> |
|
548 | + 'event_espresso') . $txn_nmbr['value']; ?> |
|
549 | 549 | </h2> |
550 | 550 | |
551 | 551 | <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm" |
@@ -566,10 +566,10 @@ discard block |
||
566 | 566 | <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
567 | 567 | <label for="delete-txn-admin-payment-reg-status-inp" |
568 | 568 | class="last"><?php esc_html_e('Change Registration Status?', |
569 | - 'event_espresso'); ?></label> |
|
569 | + 'event_espresso'); ?></label> |
|
570 | 570 | <?php echo $delete_status_change_select; ?> |
571 | 571 | <p class="description"><?php printf(esc_html__('If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s', |
572 | - 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
572 | + 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
573 | 573 | </div> |
574 | 574 | |
575 | 575 | <div class="ee-attention txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | class="last"><?php esc_html_e('Send Related Messages?', 'event_espresso'); ?></label> |
578 | 578 | <input type="checkbox" value="1" name="delete_txn_reg_status_change[send_notifications]"> |
579 | 579 | <p class="description"><?php esc_html_e('If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.', |
580 | - 'event_espresso'); ?></p> |
|
580 | + 'event_espresso'); ?></p> |
|
581 | 581 | </div> |
582 | 582 | <div class="clear"></div> |
583 | 583 | |
@@ -609,13 +609,13 @@ discard block |
||
609 | 609 | <?php endif; // $grand_raw_total > 0?> |
610 | 610 | |
611 | 611 | <?php |
612 | - if (WP_DEBUG) { |
|
613 | - $delivered_messages = get_option('EED_Messages__payment', array()); |
|
614 | - if (isset($delivered_messages[$TXN_ID])) { |
|
615 | - ?> |
|
612 | + if (WP_DEBUG) { |
|
613 | + $delivered_messages = get_option('EED_Messages__payment', array()); |
|
614 | + if (isset($delivered_messages[$TXN_ID])) { |
|
615 | + ?> |
|
616 | 616 | <h4 class="admin-primary-mbox-h4 hdr-has-icon"><span |
617 | 617 | class="dashicons dashicons-email-alt"></span><?php esc_html_e('Messages Sent to Primary Registrant', |
618 | - 'event_espresso'); ?></h4> |
|
618 | + 'event_espresso'); ?></h4> |
|
619 | 619 | |
620 | 620 | <div class="admin-primary-mbox-tbl-wrap"> |
621 | 621 | <table class="admin-primary-mbox-tbl"> |
@@ -629,10 +629,10 @@ discard block |
||
629 | 629 | </thead> |
630 | 630 | <tbody> |
631 | 631 | <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) : |
632 | - ?> |
|
632 | + ?> |
|
633 | 633 | <tr> |
634 | 634 | <td class="jst-left"><?php echo date(get_option('date_format') . ' ' . get_option('time_format'), |
635 | - ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td> |
|
635 | + ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td> |
|
636 | 636 | <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td> |
637 | 637 | <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td> |
638 | 638 | <td class="jst-left"><?php echo isset($delivered_message['txn_status']) ? $delivered_message['txn_status'] : ''; ?></td> |
@@ -642,9 +642,9 @@ discard block |
||
642 | 642 | </table> |
643 | 643 | </div> |
644 | 644 | <?php |
645 | - } |
|
646 | - } |
|
647 | - ?> |
|
645 | + } |
|
646 | + } |
|
647 | + ?> |
|
648 | 648 | |
649 | 649 | |
650 | 650 | </div> |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | */ |
32 | 32 | public function __construct() { |
33 | 33 | parent::__construct( |
34 | - __( 'Event Espresso Upcoming Events', 'event_espresso' ), |
|
35 | - array( 'description' => __( 'A widget to display your upcoming events.', 'event_espresso' )) |
|
34 | + __('Event Espresso Upcoming Events', 'event_espresso'), |
|
35 | + array('description' => __('A widget to display your upcoming events.', 'event_espresso')) |
|
36 | 36 | ); |
37 | 37 | } |
38 | 38 | |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | * @param array $instance Previously saved values from database. |
46 | 46 | * @return string|void |
47 | 47 | */ |
48 | - public function form( $instance ) { |
|
48 | + public function form($instance) { |
|
49 | 49 | |
50 | - EE_Registry::instance()->load_class( 'Question_Option', array(), FALSE, FALSE, TRUE ); |
|
50 | + EE_Registry::instance()->load_class('Question_Option', array(), FALSE, FALSE, TRUE); |
|
51 | 51 | // Set up some default widget settings. |
52 | 52 | $defaults = array( |
53 | 53 | 'title' => __('Upcoming Events', 'event_espresso'), |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | 'image_size' => 'medium' |
64 | 64 | ); |
65 | 65 | |
66 | - $instance = wp_parse_args( (array) $instance, $defaults ); |
|
66 | + $instance = wp_parse_args((array) $instance, $defaults); |
|
67 | 67 | // don't add HTML labels for EE_Form_Fields generated inputs |
68 | - add_filter( 'FHEE__EEH_Form_Fields__label_html', '__return_empty_string' ); |
|
68 | + add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string'); |
|
69 | 69 | $yes_no_values = array( |
70 | - EE_Question_Option::new_instance( array( 'QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))), |
|
71 | - EE_Question_Option::new_instance( array( 'QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso'))) |
|
70 | + EE_Question_Option::new_instance(array('QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))), |
|
71 | + EE_Question_Option::new_instance(array('QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso'))) |
|
72 | 72 | ); |
73 | 73 | $sort_values = array( |
74 | - EE_Question_Option::new_instance( array( 'QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))), |
|
75 | - EE_Question_Option::new_instance( array( 'QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso'))) |
|
74 | + EE_Question_Option::new_instance(array('QSO_value' => 'ASC', 'QSO_desc' => __('ASC', 'event_espresso'))), |
|
75 | + EE_Question_Option::new_instance(array('QSO_value' => 'DESC', 'QSO_desc' => __('DESC', 'event_espresso'))) |
|
76 | 76 | ); |
77 | 77 | |
78 | 78 | ?> |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | <label for="<?php echo $this->get_field_id('title'); ?>"> |
84 | 84 | <?php _e('Title:', 'event_espresso'); ?> |
85 | 85 | </label> |
86 | - <input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" type="text" /> |
|
86 | + <input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" type="text" /> |
|
87 | 87 | </p> |
88 | 88 | <p> |
89 | 89 | <label for="<?php echo $this->get_field_id('category_name'); ?>"> |
@@ -92,16 +92,16 @@ discard block |
||
92 | 92 | <?php |
93 | 93 | $event_categories = array(); |
94 | 94 | /** @type EEM_Term $EEM_Term */ |
95 | - $EEM_Term = EE_Registry::instance()->load_model( 'Term' ); |
|
96 | - $categories = $EEM_Term->get_all_ee_categories( TRUE ); |
|
97 | - if ( $categories ) { |
|
98 | - foreach ( $categories as $category ) { |
|
99 | - if ( $category instanceof EE_Term ) { |
|
100 | - $event_categories[] = EE_Question_Option::new_instance( array( 'QSO_value' => $category->get( 'slug' ), 'QSO_desc' => $category->get( 'name' ))); |
|
95 | + $EEM_Term = EE_Registry::instance()->load_model('Term'); |
|
96 | + $categories = $EEM_Term->get_all_ee_categories(TRUE); |
|
97 | + if ($categories) { |
|
98 | + foreach ($categories as $category) { |
|
99 | + if ($category instanceof EE_Term) { |
|
100 | + $event_categories[] = EE_Question_Option::new_instance(array('QSO_value' => $category->get('slug'), 'QSO_desc' => $category->get('name'))); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | } |
104 | - array_unshift( $event_categories, EE_Question_Option::new_instance( array( 'QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso')))); |
|
104 | + array_unshift($event_categories, EE_Question_Option::new_instance(array('QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso')))); |
|
105 | 105 | echo EEH_Form_Fields::select( |
106 | 106 | __('Event Category:', 'event_espresso'), |
107 | 107 | $instance['category_name'], |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | __('Show Expired Events:', 'event_espresso'), |
127 | 127 | $instance['show_expired'], |
128 | 128 | array( |
129 | - EE_Question_Option::new_instance( array( 'QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), |
|
130 | - EE_Question_Option::new_instance( array( 'QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), |
|
131 | - EE_Question_Option::new_instance( array( 'QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), |
|
129 | + EE_Question_Option::new_instance(array('QSO_value' => 0, 'QSO_desc' => __('No', 'event_espresso'))), |
|
130 | + EE_Question_Option::new_instance(array('QSO_value' => 1, 'QSO_desc' => __('Yes', 'event_espresso'))), |
|
131 | + EE_Question_Option::new_instance(array('QSO_value' => 2, 'QSO_desc' => __('Show Only Expired', 'event_espresso'))), |
|
132 | 132 | ), |
133 | 133 | $this->get_field_name('show_expired'), |
134 | 134 | $this->get_field_id('show_expired') |
@@ -156,16 +156,16 @@ discard block |
||
156 | 156 | <?php |
157 | 157 | $image_sizes = array(); |
158 | 158 | $sizes = get_intermediate_image_sizes(); |
159 | - if ( $sizes ) { |
|
159 | + if ($sizes) { |
|
160 | 160 | // loop thru images and create option objects out of them |
161 | - foreach ( $sizes as $image_size ) { |
|
162 | - $image_size = trim( $image_size ); |
|
161 | + foreach ($sizes as $image_size) { |
|
162 | + $image_size = trim($image_size); |
|
163 | 163 | // no big images plz |
164 | - if ( ! in_array( $image_size, array( 'large', 'post-thumbnail' ))) { |
|
165 | - $image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => $image_size, 'QSO_desc' => $image_size )); |
|
164 | + if ( ! in_array($image_size, array('large', 'post-thumbnail'))) { |
|
165 | + $image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => $image_size, 'QSO_desc' => $image_size)); |
|
166 | 166 | } |
167 | 167 | } |
168 | - $image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => 'none', 'QSO_desc' => __('don\'t show images', 'event_espresso') )); |
|
168 | + $image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => 'none', 'QSO_desc' => __('don\'t show images', 'event_espresso'))); |
|
169 | 169 | } |
170 | 170 | echo EEH_Form_Fields::select( |
171 | 171 | __('Image Size:', 'event_espresso'), |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | <label for="<?php echo $this->get_field_id('date_limit'); ?>"> |
224 | 224 | <?php _e('Number of Dates to Display:', 'event_espresso'); ?> |
225 | 225 | </label> |
226 | - <input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr( $instance['date_limit'] ); ?>" size="3" type="text" /> |
|
226 | + <input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr($instance['date_limit']); ?>" size="3" type="text" /> |
|
227 | 227 | </p> |
228 | 228 | <p> |
229 | 229 | <label for="<?php echo $this->get_field_id('date_range'); ?>"> |
@@ -255,9 +255,9 @@ discard block |
||
255 | 255 | * |
256 | 256 | * @return array Updated safe values to be saved. |
257 | 257 | */ |
258 | - public function update( $new_instance, $old_instance ) { |
|
258 | + public function update($new_instance, $old_instance) { |
|
259 | 259 | $instance = $old_instance; |
260 | - $instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : ''; |
|
260 | + $instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : ''; |
|
261 | 261 | $instance['category_name'] = $new_instance['category_name']; |
262 | 262 | $instance['show_expired'] = $new_instance['show_expired']; |
263 | 263 | $instance['limit'] = $new_instance['limit']; |
@@ -281,18 +281,18 @@ discard block |
||
281 | 281 | * @param array $args Widget arguments. |
282 | 282 | * @param array $instance Saved values from database. |
283 | 283 | */ |
284 | - public function widget( $args, $instance ) { |
|
284 | + public function widget($args, $instance) { |
|
285 | 285 | |
286 | 286 | global $post; |
287 | 287 | // make sure there is some kinda post object |
288 | - if ( $post instanceof WP_Post ) { |
|
288 | + if ($post instanceof WP_Post) { |
|
289 | 289 | $before_widget = ''; |
290 | 290 | $before_title = ''; |
291 | 291 | $after_title = ''; |
292 | 292 | $after_widget = ''; |
293 | 293 | // but NOT an events archives page, cuz that would be like two event lists on the same page |
294 | - $show_everywhere = isset( $instance['show_everywhere'] ) ? (bool) absint( $instance['show_everywhere'] ) : TRUE; |
|
295 | - if ( $show_everywhere || ! ( $post->post_type == 'espresso_events' && is_archive() )) { |
|
294 | + $show_everywhere = isset($instance['show_everywhere']) ? (bool) absint($instance['show_everywhere']) : TRUE; |
|
295 | + if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) { |
|
296 | 296 | // let's use some of the event helper functions' |
297 | 297 | // make separate vars out of attributes |
298 | 298 | |
@@ -311,88 +311,88 @@ discard block |
||
311 | 311 | // Before widget (defined by themes). |
312 | 312 | echo $before_widget; |
313 | 313 | // Display the widget title if one was input (before and after defined by themes). |
314 | - if ( ! empty( $title )) { |
|
315 | - echo $before_title . $title . $after_title; |
|
314 | + if ( ! empty($title)) { |
|
315 | + echo $before_title.$title.$after_title; |
|
316 | 316 | } |
317 | 317 | // grab widget settings |
318 | - $category = isset( $instance['category_name'] ) && ! empty( $instance['category_name'] ) ? $instance['category_name'] : FALSE; |
|
319 | - $show_expired = isset( $instance['show_expired'] ) ? absint( $instance['show_expired'] ) : 0; |
|
320 | - $image_size = isset( $instance['image_size'] ) && ! empty( $instance['image_size'] ) ? $instance['image_size'] : 'medium'; |
|
321 | - $show_desc = isset( $instance['show_desc'] ) ? (bool) absint( $instance['show_desc'] ) : TRUE; |
|
322 | - $show_dates = isset( $instance['show_dates'] ) ? (bool) absint( $instance['show_dates'] ) : TRUE; |
|
323 | - $date_limit = isset( $instance['date_limit'] ) && ! empty( $instance['date_limit'] ) ? $instance['date_limit'] : NULL; |
|
324 | - $date_range = isset( $instance['date_range'] ) && ! empty( $instance['date_range'] ) ? $instance['date_range'] : FALSE; |
|
318 | + $category = isset($instance['category_name']) && ! empty($instance['category_name']) ? $instance['category_name'] : FALSE; |
|
319 | + $show_expired = isset($instance['show_expired']) ? absint($instance['show_expired']) : 0; |
|
320 | + $image_size = isset($instance['image_size']) && ! empty($instance['image_size']) ? $instance['image_size'] : 'medium'; |
|
321 | + $show_desc = isset($instance['show_desc']) ? (bool) absint($instance['show_desc']) : TRUE; |
|
322 | + $show_dates = isset($instance['show_dates']) ? (bool) absint($instance['show_dates']) : TRUE; |
|
323 | + $date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) ? $instance['date_limit'] : NULL; |
|
324 | + $date_range = isset($instance['date_range']) && ! empty($instance['date_range']) ? $instance['date_range'] : FALSE; |
|
325 | 325 | // start to build our where clause |
326 | 326 | $where = array( |
327 | 327 | // 'Datetime.DTT_is_primary' => 1, |
328 | - 'status' => array( 'IN', array( 'publish', 'sold_out' ) ) |
|
328 | + 'status' => array('IN', array('publish', 'sold_out')) |
|
329 | 329 | ); |
330 | 330 | // add category |
331 | - if ( $category ) { |
|
331 | + if ($category) { |
|
332 | 332 | $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
333 | 333 | $where['Term_Taxonomy.Term.slug'] = $category; |
334 | 334 | } |
335 | 335 | // if NOT expired then we want events that start today or in the future |
336 | 336 | // if NOT show expired then we want events that start today or in the future |
337 | - if ( $show_expired == 0 ) { |
|
338 | - $where['Datetime.DTT_EVT_end'] = array( '>=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) ); |
|
337 | + if ($show_expired == 0) { |
|
338 | + $where['Datetime.DTT_EVT_end'] = array('>=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')); |
|
339 | 339 | } |
340 | 340 | // if show ONLY expired we want events that ended prior to today |
341 | - if ( $show_expired == 2 ) { |
|
342 | - $where['Datetime.DTT_EVT_end'] = array( '<=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_start' ) ); |
|
341 | + if ($show_expired == 2) { |
|
342 | + $where['Datetime.DTT_EVT_end'] = array('<=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')); |
|
343 | 343 | } |
344 | 344 | // allow $where to be filtered |
345 | - $where = apply_filters( 'FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired ); |
|
345 | + $where = apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired); |
|
346 | 346 | // run the query |
347 | - $events = EE_Registry::instance()->load_model( 'Event' )->get_all( array( |
|
347 | + $events = EE_Registry::instance()->load_model('Event')->get_all(array( |
|
348 | 348 | $where, |
349 | - 'limit' => $instance['limit'] > 0 ? '0,' . $instance['limit'] : '0,10', |
|
349 | + 'limit' => $instance['limit'] > 0 ? '0,'.$instance['limit'] : '0,10', |
|
350 | 350 | 'order_by' => 'Datetime.DTT_EVT_start', |
351 | 351 | 'order' => isset($instance['sort']) ? $instance['sort'] : 'ASC', |
352 | 352 | 'group_by' => 'EVT_ID' |
353 | 353 | )); |
354 | 354 | |
355 | - if ( ! empty( $events )) { |
|
355 | + if ( ! empty($events)) { |
|
356 | 356 | echo '<ul class="ee-upcoming-events-widget-ul">'; |
357 | - foreach ( $events as $event ) { |
|
358 | - if ( $event instanceof EE_Event && ( !is_single() || $post->ID != $event->ID() ) ) { |
|
357 | + foreach ($events as $event) { |
|
358 | + if ($event instanceof EE_Event && ( ! is_single() || $post->ID != $event->ID())) { |
|
359 | 359 | //printr( $event, '$event <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
360 | - echo '<li id="ee-upcoming-events-widget-li-' . $event->ID() . '" class="ee-upcoming-events-widget-li">'; |
|
360 | + echo '<li id="ee-upcoming-events-widget-li-'.$event->ID().'" class="ee-upcoming-events-widget-li">'; |
|
361 | 361 | // how big is the event name ? |
362 | - $name_length = strlen( $event->name() ); |
|
363 | - switch( $name_length ) { |
|
362 | + $name_length = strlen($event->name()); |
|
363 | + switch ($name_length) { |
|
364 | 364 | case $name_length > 70 : |
365 | - $len_class = ' three-line'; |
|
365 | + $len_class = ' three-line'; |
|
366 | 366 | break; |
367 | 367 | case $name_length > 35 : |
368 | - $len_class = ' two-line'; |
|
368 | + $len_class = ' two-line'; |
|
369 | 369 | break; |
370 | 370 | default : |
371 | - $len_class = ' one-line'; |
|
371 | + $len_class = ' one-line'; |
|
372 | 372 | } |
373 | - $event_url = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event ); |
|
374 | - echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a' . $len_class . '" href="' . $event_url . '">' . $event->name() . '</a></h5>'; |
|
375 | - if ( post_password_required( $event->ID() ) ) { |
|
376 | - $pswd_form = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form( $event->ID() ), $event ); |
|
373 | + $event_url = apply_filters('FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event); |
|
374 | + echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a'.$len_class.'" href="'.$event_url.'">'.$event->name().'</a></h5>'; |
|
375 | + if (post_password_required($event->ID())) { |
|
376 | + $pswd_form = apply_filters('FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form($event->ID()), $event); |
|
377 | 377 | echo $pswd_form; |
378 | 378 | } else { |
379 | - if ( has_post_thumbnail( $event->ID() ) && $image_size != 'none' ) { |
|
380 | - echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="' . $event_url . '">' . get_the_post_thumbnail( $event->ID(), $image_size ) . '</a></div>'; |
|
379 | + if (has_post_thumbnail($event->ID()) && $image_size != 'none') { |
|
380 | + echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="'.$event_url.'">'.get_the_post_thumbnail($event->ID(), $image_size).'</a></div>'; |
|
381 | 381 | } |
382 | - $desc = $event->short_description( 25 ); |
|
383 | - if ( $show_dates ) { |
|
384 | - $date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', get_option( 'date_format' )); |
|
385 | - $time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', get_option( 'time_format' )); |
|
386 | - $single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', get_option( 'date_format' )); |
|
387 | - $single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', get_option( 'time_format' )); |
|
388 | - if ( $date_range == TRUE ) { |
|
389 | - echo espresso_event_date_range( $date_format, $time_format, $single_date_format, $single_time_format, $event->ID() ); |
|
390 | - }else{ |
|
391 | - echo espresso_list_of_event_dates( $event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit ); |
|
382 | + $desc = $event->short_description(25); |
|
383 | + if ($show_dates) { |
|
384 | + $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', get_option('date_format')); |
|
385 | + $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', get_option('time_format')); |
|
386 | + $single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', get_option('date_format')); |
|
387 | + $single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', get_option('time_format')); |
|
388 | + if ($date_range == TRUE) { |
|
389 | + echo espresso_event_date_range($date_format, $time_format, $single_date_format, $single_time_format, $event->ID()); |
|
390 | + } else { |
|
391 | + echo espresso_list_of_event_dates($event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit); |
|
392 | 392 | } |
393 | 393 | } |
394 | - if ( $show_desc && $desc ) { |
|
395 | - echo '<p style="margin-top: .5em">' . $desc . '</p>'; |
|
394 | + if ($show_desc && $desc) { |
|
395 | + echo '<p style="margin-top: .5em">'.$desc.'</p>'; |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | echo '</li>'; |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | * @return string |
417 | 417 | */ |
418 | 418 | public function make_the_title_a_link($title) { |
419 | - return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>'; |
|
419 | + return '<a href="'.EEH_Event_View::event_archive_url().'">'.$title.'</a>'; |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * cancelTicketSelections |
44 | 44 | * |
45 | - * @return string |
|
45 | + * @return false|null |
|
46 | 46 | * @throws EE_Error |
47 | 47 | * @throws InvalidArgumentException |
48 | 48 | * @throws InvalidInterfaceException |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | /** |
115 | 115 | * process_ticket_selections |
116 | 116 | * |
117 | - * @return array|bool |
|
117 | + * @return null|boolean |
|
118 | 118 | * @throws \ReflectionException |
119 | 119 | * @throws InvalidArgumentException |
120 | 120 | * @throws InvalidInterfaceException |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | * validate_post_data |
299 | 299 | * |
300 | 300 | * @param int $id |
301 | - * @return array|FALSE |
|
301 | + * @return string |
|
302 | 302 | * @throws \ReflectionException |
303 | 303 | * @throws InvalidArgumentException |
304 | 304 | * @throws InvalidInterfaceException |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | * |
422 | 422 | * @param EE_Ticket $ticket |
423 | 423 | * @param int $qty |
424 | - * @return TRUE on success, FALSE on fail |
|
424 | + * @return boolean on success, FALSE on fail |
|
425 | 425 | * @throws InvalidArgumentException |
426 | 426 | * @throws InvalidInterfaceException |
427 | 427 | * @throws InvalidDataTypeException |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | use InvalidArgumentException; |
15 | 15 | |
16 | 16 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
17 | - exit('No direct script access allowed'); |
|
17 | + exit('No direct script access allowed'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | |
@@ -31,602 +31,602 @@ discard block |
||
31 | 31 | class ProcessTicketSelector |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * array of datetimes and the spaces available for them |
|
36 | - * |
|
37 | - * @var array[][] |
|
38 | - */ |
|
39 | - private static $_available_spaces = array(); |
|
34 | + /** |
|
35 | + * array of datetimes and the spaces available for them |
|
36 | + * |
|
37 | + * @var array[][] |
|
38 | + */ |
|
39 | + private static $_available_spaces = array(); |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * cancelTicketSelections |
|
44 | - * |
|
45 | - * @return string |
|
46 | - * @throws EE_Error |
|
47 | - * @throws InvalidArgumentException |
|
48 | - * @throws InvalidInterfaceException |
|
49 | - * @throws InvalidDataTypeException |
|
50 | - */ |
|
51 | - public function cancelTicketSelections() |
|
52 | - { |
|
53 | - // check nonce |
|
54 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
55 | - return false; |
|
56 | - } |
|
57 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
58 | - if (EE_Registry::instance()->REQ->is_set('event_id')) { |
|
59 | - wp_safe_redirect( |
|
60 | - EEH_Event_View::event_link_url( |
|
61 | - EE_Registry::instance()->REQ->get('event_id') |
|
62 | - ) |
|
63 | - ); |
|
64 | - } else { |
|
65 | - wp_safe_redirect( |
|
66 | - site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
67 | - ); |
|
68 | - } |
|
69 | - exit(); |
|
70 | - } |
|
42 | + /** |
|
43 | + * cancelTicketSelections |
|
44 | + * |
|
45 | + * @return string |
|
46 | + * @throws EE_Error |
|
47 | + * @throws InvalidArgumentException |
|
48 | + * @throws InvalidInterfaceException |
|
49 | + * @throws InvalidDataTypeException |
|
50 | + */ |
|
51 | + public function cancelTicketSelections() |
|
52 | + { |
|
53 | + // check nonce |
|
54 | + if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
55 | + return false; |
|
56 | + } |
|
57 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
58 | + if (EE_Registry::instance()->REQ->is_set('event_id')) { |
|
59 | + wp_safe_redirect( |
|
60 | + EEH_Event_View::event_link_url( |
|
61 | + EE_Registry::instance()->REQ->get('event_id') |
|
62 | + ) |
|
63 | + ); |
|
64 | + } else { |
|
65 | + wp_safe_redirect( |
|
66 | + site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
67 | + ); |
|
68 | + } |
|
69 | + exit(); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * processTicketSelectorNonce |
|
75 | - * |
|
76 | - * @param string $nonce_name |
|
77 | - * @param string $id |
|
78 | - * @return bool |
|
79 | - * @throws InvalidArgumentException |
|
80 | - * @throws InvalidInterfaceException |
|
81 | - * @throws InvalidDataTypeException |
|
82 | - */ |
|
83 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
84 | - { |
|
85 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
86 | - if ( |
|
87 | - ! is_admin() |
|
88 | - && ( |
|
89 | - ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
90 | - || ! wp_verify_nonce( |
|
91 | - EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
92 | - $nonce_name |
|
93 | - ) |
|
94 | - ) |
|
95 | - ) { |
|
96 | - EE_Error::add_error( |
|
97 | - sprintf( |
|
98 | - __( |
|
99 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
100 | - 'event_espresso' |
|
101 | - ), |
|
102 | - '<br/>' |
|
103 | - ), |
|
104 | - __FILE__, |
|
105 | - __FUNCTION__, |
|
106 | - __LINE__ |
|
107 | - ); |
|
108 | - return false; |
|
109 | - } |
|
110 | - return true; |
|
111 | - } |
|
73 | + /** |
|
74 | + * processTicketSelectorNonce |
|
75 | + * |
|
76 | + * @param string $nonce_name |
|
77 | + * @param string $id |
|
78 | + * @return bool |
|
79 | + * @throws InvalidArgumentException |
|
80 | + * @throws InvalidInterfaceException |
|
81 | + * @throws InvalidDataTypeException |
|
82 | + */ |
|
83 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
84 | + { |
|
85 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
86 | + if ( |
|
87 | + ! is_admin() |
|
88 | + && ( |
|
89 | + ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
90 | + || ! wp_verify_nonce( |
|
91 | + EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
92 | + $nonce_name |
|
93 | + ) |
|
94 | + ) |
|
95 | + ) { |
|
96 | + EE_Error::add_error( |
|
97 | + sprintf( |
|
98 | + __( |
|
99 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
100 | + 'event_espresso' |
|
101 | + ), |
|
102 | + '<br/>' |
|
103 | + ), |
|
104 | + __FILE__, |
|
105 | + __FUNCTION__, |
|
106 | + __LINE__ |
|
107 | + ); |
|
108 | + return false; |
|
109 | + } |
|
110 | + return true; |
|
111 | + } |
|
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * process_ticket_selections |
|
116 | - * |
|
117 | - * @return array|bool |
|
118 | - * @throws \ReflectionException |
|
119 | - * @throws InvalidArgumentException |
|
120 | - * @throws InvalidInterfaceException |
|
121 | - * @throws InvalidDataTypeException |
|
122 | - * @throws EE_Error |
|
123 | - */ |
|
124 | - public function processTicketSelections() |
|
125 | - { |
|
126 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
127 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
128 | - if($request->isBot()) { |
|
129 | - wp_safe_redirect( |
|
130 | - apply_filters( |
|
131 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
132 | - site_url() |
|
133 | - ) |
|
134 | - ); |
|
135 | - exit(); |
|
136 | - } |
|
137 | - // do we have an event id? |
|
138 | - if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
139 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
140 | - EE_Error::add_error( |
|
141 | - sprintf( |
|
142 | - __( |
|
143 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
144 | - 'event_espresso' |
|
145 | - ), |
|
146 | - '<br/>' |
|
147 | - ), |
|
148 | - __FILE__, |
|
149 | - __FUNCTION__, |
|
150 | - __LINE__ |
|
151 | - ); |
|
152 | - } |
|
153 | - //if event id is valid |
|
154 | - $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
155 | - // d( \EE_Registry::instance()->REQ ); |
|
156 | - self::$_available_spaces = array( |
|
157 | - 'tickets' => array(), |
|
158 | - 'datetimes' => array(), |
|
159 | - ); |
|
160 | - //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
161 | - // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
162 | - EE_Registry::instance()->load_core('Session'); |
|
163 | - // unless otherwise requested, clear the session |
|
164 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
165 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
166 | - } |
|
167 | - //d( \EE_Registry::instance()->SSN ); |
|
168 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
169 | - // validate/sanitize data |
|
170 | - $valid = $this->validatePostData($id); |
|
171 | - //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
172 | - //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
173 | - //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
174 | - //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
175 | - //check total tickets ordered vs max number of attendees that can register |
|
176 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
177 | - // ordering too many tickets !!! |
|
178 | - $total_tickets_string = _n( |
|
179 | - 'You have attempted to purchase %s ticket.', |
|
180 | - 'You have attempted to purchase %s tickets.', |
|
181 | - $valid['total_tickets'], |
|
182 | - 'event_espresso' |
|
183 | - ); |
|
184 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
185 | - // dev only message |
|
186 | - $max_atndz_string = _n( |
|
187 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
188 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
189 | - $valid['max_atndz'], |
|
190 | - 'event_espresso' |
|
191 | - ); |
|
192 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
193 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
194 | - } else { |
|
195 | - // all data appears to be valid |
|
196 | - $tckts_slctd = false; |
|
197 | - $tickets_added = 0; |
|
198 | - $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
199 | - $valid); |
|
200 | - if ($valid['total_tickets'] > 0) { |
|
201 | - // load cart |
|
202 | - EE_Registry::instance()->load_core('Cart'); |
|
203 | - // cycle thru the number of data rows sent from the event listing |
|
204 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
205 | - // does this row actually contain a ticket quantity? |
|
206 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
207 | - // YES we have a ticket quantity |
|
208 | - $tckts_slctd = true; |
|
209 | - // d( $valid['ticket_obj'][$x] ); |
|
210 | - if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
211 | - // then add ticket to cart |
|
212 | - $tickets_added += $this->addTicketToCart( |
|
213 | - $valid['ticket_obj'][ $x ], |
|
214 | - $valid['qty'][ $x ] |
|
215 | - ); |
|
216 | - if (EE_Error::has_error()) { |
|
217 | - break; |
|
218 | - } |
|
219 | - } else { |
|
220 | - // nothing added to cart retrieved |
|
221 | - EE_Error::add_error( |
|
222 | - sprintf( |
|
223 | - __( |
|
224 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
225 | - 'event_espresso' |
|
226 | - ), |
|
227 | - '<br/>' |
|
228 | - ), |
|
229 | - __FILE__, __FUNCTION__, __LINE__ |
|
230 | - ); |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - } |
|
235 | - do_action( |
|
236 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
237 | - EE_Registry::instance()->CART, |
|
238 | - $this |
|
239 | - ); |
|
240 | - //d( \EE_Registry::instance()->CART ); |
|
241 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
242 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
243 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
244 | - do_action( |
|
245 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
246 | - EE_Registry::instance()->CART, |
|
247 | - $this |
|
248 | - ); |
|
249 | - EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
250 | - EE_Registry::instance()->CART->save_cart(false); |
|
251 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
252 | - // just return TRUE for registrations being made from admin |
|
253 | - if (is_admin()) { |
|
254 | - return true; |
|
255 | - } |
|
256 | - EE_Error::get_notices(false, true); |
|
257 | - wp_safe_redirect( |
|
258 | - apply_filters( |
|
259 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
260 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
261 | - ) |
|
262 | - ); |
|
263 | - exit(); |
|
264 | - } else { |
|
265 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
266 | - // nothing added to cart |
|
267 | - EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
268 | - __FILE__, __FUNCTION__, __LINE__); |
|
269 | - } |
|
270 | - } |
|
271 | - } else { |
|
272 | - // no ticket quantities were selected |
|
273 | - EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
274 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
275 | - } |
|
276 | - } |
|
277 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
278 | - // at this point, just return if registration is being made from admin |
|
279 | - if (is_admin()) { |
|
280 | - return false; |
|
281 | - } |
|
282 | - if ($valid['return_url']) { |
|
283 | - EE_Error::get_notices(false, true); |
|
284 | - wp_safe_redirect($valid['return_url']); |
|
285 | - exit(); |
|
286 | - } elseif (isset($event_to_add['id'])) { |
|
287 | - EE_Error::get_notices(false, true); |
|
288 | - wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
289 | - exit(); |
|
290 | - } else { |
|
291 | - echo EE_Error::get_notices(); |
|
292 | - } |
|
293 | - return false; |
|
294 | - } |
|
114 | + /** |
|
115 | + * process_ticket_selections |
|
116 | + * |
|
117 | + * @return array|bool |
|
118 | + * @throws \ReflectionException |
|
119 | + * @throws InvalidArgumentException |
|
120 | + * @throws InvalidInterfaceException |
|
121 | + * @throws InvalidDataTypeException |
|
122 | + * @throws EE_Error |
|
123 | + */ |
|
124 | + public function processTicketSelections() |
|
125 | + { |
|
126 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
127 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
128 | + if($request->isBot()) { |
|
129 | + wp_safe_redirect( |
|
130 | + apply_filters( |
|
131 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
132 | + site_url() |
|
133 | + ) |
|
134 | + ); |
|
135 | + exit(); |
|
136 | + } |
|
137 | + // do we have an event id? |
|
138 | + if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
139 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
140 | + EE_Error::add_error( |
|
141 | + sprintf( |
|
142 | + __( |
|
143 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
144 | + 'event_espresso' |
|
145 | + ), |
|
146 | + '<br/>' |
|
147 | + ), |
|
148 | + __FILE__, |
|
149 | + __FUNCTION__, |
|
150 | + __LINE__ |
|
151 | + ); |
|
152 | + } |
|
153 | + //if event id is valid |
|
154 | + $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
155 | + // d( \EE_Registry::instance()->REQ ); |
|
156 | + self::$_available_spaces = array( |
|
157 | + 'tickets' => array(), |
|
158 | + 'datetimes' => array(), |
|
159 | + ); |
|
160 | + //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
161 | + // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
162 | + EE_Registry::instance()->load_core('Session'); |
|
163 | + // unless otherwise requested, clear the session |
|
164 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
165 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
166 | + } |
|
167 | + //d( \EE_Registry::instance()->SSN ); |
|
168 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
169 | + // validate/sanitize data |
|
170 | + $valid = $this->validatePostData($id); |
|
171 | + //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
172 | + //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
173 | + //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
174 | + //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
175 | + //check total tickets ordered vs max number of attendees that can register |
|
176 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
177 | + // ordering too many tickets !!! |
|
178 | + $total_tickets_string = _n( |
|
179 | + 'You have attempted to purchase %s ticket.', |
|
180 | + 'You have attempted to purchase %s tickets.', |
|
181 | + $valid['total_tickets'], |
|
182 | + 'event_espresso' |
|
183 | + ); |
|
184 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
185 | + // dev only message |
|
186 | + $max_atndz_string = _n( |
|
187 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
188 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
189 | + $valid['max_atndz'], |
|
190 | + 'event_espresso' |
|
191 | + ); |
|
192 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
193 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
194 | + } else { |
|
195 | + // all data appears to be valid |
|
196 | + $tckts_slctd = false; |
|
197 | + $tickets_added = 0; |
|
198 | + $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
199 | + $valid); |
|
200 | + if ($valid['total_tickets'] > 0) { |
|
201 | + // load cart |
|
202 | + EE_Registry::instance()->load_core('Cart'); |
|
203 | + // cycle thru the number of data rows sent from the event listing |
|
204 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
205 | + // does this row actually contain a ticket quantity? |
|
206 | + if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
207 | + // YES we have a ticket quantity |
|
208 | + $tckts_slctd = true; |
|
209 | + // d( $valid['ticket_obj'][$x] ); |
|
210 | + if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
211 | + // then add ticket to cart |
|
212 | + $tickets_added += $this->addTicketToCart( |
|
213 | + $valid['ticket_obj'][ $x ], |
|
214 | + $valid['qty'][ $x ] |
|
215 | + ); |
|
216 | + if (EE_Error::has_error()) { |
|
217 | + break; |
|
218 | + } |
|
219 | + } else { |
|
220 | + // nothing added to cart retrieved |
|
221 | + EE_Error::add_error( |
|
222 | + sprintf( |
|
223 | + __( |
|
224 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
225 | + 'event_espresso' |
|
226 | + ), |
|
227 | + '<br/>' |
|
228 | + ), |
|
229 | + __FILE__, __FUNCTION__, __LINE__ |
|
230 | + ); |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + } |
|
235 | + do_action( |
|
236 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
237 | + EE_Registry::instance()->CART, |
|
238 | + $this |
|
239 | + ); |
|
240 | + //d( \EE_Registry::instance()->CART ); |
|
241 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
242 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
243 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
244 | + do_action( |
|
245 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
246 | + EE_Registry::instance()->CART, |
|
247 | + $this |
|
248 | + ); |
|
249 | + EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
250 | + EE_Registry::instance()->CART->save_cart(false); |
|
251 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
252 | + // just return TRUE for registrations being made from admin |
|
253 | + if (is_admin()) { |
|
254 | + return true; |
|
255 | + } |
|
256 | + EE_Error::get_notices(false, true); |
|
257 | + wp_safe_redirect( |
|
258 | + apply_filters( |
|
259 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
260 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
261 | + ) |
|
262 | + ); |
|
263 | + exit(); |
|
264 | + } else { |
|
265 | + if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
266 | + // nothing added to cart |
|
267 | + EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
268 | + __FILE__, __FUNCTION__, __LINE__); |
|
269 | + } |
|
270 | + } |
|
271 | + } else { |
|
272 | + // no ticket quantities were selected |
|
273 | + EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
274 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
275 | + } |
|
276 | + } |
|
277 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
278 | + // at this point, just return if registration is being made from admin |
|
279 | + if (is_admin()) { |
|
280 | + return false; |
|
281 | + } |
|
282 | + if ($valid['return_url']) { |
|
283 | + EE_Error::get_notices(false, true); |
|
284 | + wp_safe_redirect($valid['return_url']); |
|
285 | + exit(); |
|
286 | + } elseif (isset($event_to_add['id'])) { |
|
287 | + EE_Error::get_notices(false, true); |
|
288 | + wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
289 | + exit(); |
|
290 | + } else { |
|
291 | + echo EE_Error::get_notices(); |
|
292 | + } |
|
293 | + return false; |
|
294 | + } |
|
295 | 295 | |
296 | 296 | |
297 | - /** |
|
298 | - * validate_post_data |
|
299 | - * |
|
300 | - * @param int $id |
|
301 | - * @return array|FALSE |
|
302 | - * @throws \ReflectionException |
|
303 | - * @throws InvalidArgumentException |
|
304 | - * @throws InvalidInterfaceException |
|
305 | - * @throws InvalidDataTypeException |
|
306 | - * @throws EE_Error |
|
307 | - */ |
|
308 | - private function validatePostData($id = 0) |
|
309 | - { |
|
310 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
311 | - if (! $id) { |
|
312 | - EE_Error::add_error( |
|
313 | - __('The event id provided was not valid.', 'event_espresso'), |
|
314 | - __FILE__, |
|
315 | - __FUNCTION__, |
|
316 | - __LINE__ |
|
317 | - ); |
|
318 | - return false; |
|
319 | - } |
|
320 | - // start with an empty array() |
|
321 | - $valid_data = array(); |
|
322 | - // grab valid id |
|
323 | - $valid_data['id'] = $id; |
|
324 | - // array of other form names |
|
325 | - $inputs_to_clean = array( |
|
326 | - 'event_id' => 'tkt-slctr-event-id', |
|
327 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
328 | - 'rows' => 'tkt-slctr-rows-', |
|
329 | - 'qty' => 'tkt-slctr-qty-', |
|
330 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
331 | - 'return_url' => 'tkt-slctr-return-url-', |
|
332 | - ); |
|
333 | - // let's track the total number of tickets ordered.' |
|
334 | - $valid_data['total_tickets'] = 0; |
|
335 | - // cycle through $inputs_to_clean array |
|
336 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
337 | - // check for POST data |
|
338 | - if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
339 | - // grab value |
|
340 | - $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
341 | - switch ($what) { |
|
342 | - // integers |
|
343 | - case 'event_id': |
|
344 | - $valid_data[ $what ] = absint($input_value); |
|
345 | - // get event via the event id we put in the form |
|
346 | - $valid_data['event'] = EE_Registry::instance() |
|
347 | - ->load_model('Event') |
|
348 | - ->get_one_by_ID($valid_data['event_id']); |
|
349 | - break; |
|
350 | - case 'rows': |
|
351 | - case 'max_atndz': |
|
352 | - $valid_data[ $what ] = absint($input_value); |
|
353 | - break; |
|
354 | - // arrays of integers |
|
355 | - case 'qty': |
|
356 | - /** @var array $row_qty */ |
|
357 | - $row_qty = $input_value; |
|
358 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
359 | - if (! is_array($row_qty)) { |
|
360 | - // get number of rows |
|
361 | - $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
362 | - ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
363 | - : 1; |
|
364 | - // explode ints by the dash |
|
365 | - $row_qty = explode('-', $row_qty); |
|
366 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
367 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
368 | - $row_qty = array($row => $qty); |
|
369 | - for ($x = 1; $x <= $rows; $x++) { |
|
370 | - if (! isset($row_qty[ $x ])) { |
|
371 | - $row_qty[ $x ] = 0; |
|
372 | - } |
|
373 | - } |
|
374 | - } |
|
375 | - ksort($row_qty); |
|
376 | - // cycle thru values |
|
377 | - foreach ($row_qty as $qty) { |
|
378 | - $qty = absint($qty); |
|
379 | - // sanitize as integers |
|
380 | - $valid_data[ $what ][] = $qty; |
|
381 | - $valid_data['total_tickets'] += $qty; |
|
382 | - } |
|
383 | - break; |
|
384 | - // array of integers |
|
385 | - case 'ticket_id': |
|
386 | - $value_array = array(); |
|
387 | - // cycle thru values |
|
388 | - foreach ((array) $input_value as $key => $value) { |
|
389 | - // allow only numbers, letters, spaces, commas and dashes |
|
390 | - $value_array[ $key ] = wp_strip_all_tags($value); |
|
391 | - // get ticket via the ticket id we put in the form |
|
392 | - $ticket_obj = EE_Registry::instance() |
|
393 | - ->load_model('Ticket') |
|
394 | - ->get_one_by_ID($value); |
|
395 | - $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
396 | - } |
|
397 | - $valid_data[ $what ] = $value_array; |
|
398 | - break; |
|
399 | - case 'return_url' : |
|
400 | - // grab and sanitize return-url |
|
401 | - $input_value = esc_url_raw($input_value); |
|
402 | - // was the request coming from an iframe ? if so, then: |
|
403 | - if (strpos($input_value, 'event_list=iframe')) { |
|
404 | - // get anchor fragment |
|
405 | - $input_value = explode('#', $input_value); |
|
406 | - $input_value = end($input_value); |
|
407 | - // use event list url instead, but append anchor |
|
408 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
409 | - } |
|
410 | - $valid_data[ $what ] = $input_value; |
|
411 | - break; |
|
412 | - } // end switch $what |
|
413 | - } |
|
414 | - } // end foreach $inputs_to_clean |
|
415 | - return $valid_data; |
|
416 | - } |
|
297 | + /** |
|
298 | + * validate_post_data |
|
299 | + * |
|
300 | + * @param int $id |
|
301 | + * @return array|FALSE |
|
302 | + * @throws \ReflectionException |
|
303 | + * @throws InvalidArgumentException |
|
304 | + * @throws InvalidInterfaceException |
|
305 | + * @throws InvalidDataTypeException |
|
306 | + * @throws EE_Error |
|
307 | + */ |
|
308 | + private function validatePostData($id = 0) |
|
309 | + { |
|
310 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
311 | + if (! $id) { |
|
312 | + EE_Error::add_error( |
|
313 | + __('The event id provided was not valid.', 'event_espresso'), |
|
314 | + __FILE__, |
|
315 | + __FUNCTION__, |
|
316 | + __LINE__ |
|
317 | + ); |
|
318 | + return false; |
|
319 | + } |
|
320 | + // start with an empty array() |
|
321 | + $valid_data = array(); |
|
322 | + // grab valid id |
|
323 | + $valid_data['id'] = $id; |
|
324 | + // array of other form names |
|
325 | + $inputs_to_clean = array( |
|
326 | + 'event_id' => 'tkt-slctr-event-id', |
|
327 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
328 | + 'rows' => 'tkt-slctr-rows-', |
|
329 | + 'qty' => 'tkt-slctr-qty-', |
|
330 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
331 | + 'return_url' => 'tkt-slctr-return-url-', |
|
332 | + ); |
|
333 | + // let's track the total number of tickets ordered.' |
|
334 | + $valid_data['total_tickets'] = 0; |
|
335 | + // cycle through $inputs_to_clean array |
|
336 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
337 | + // check for POST data |
|
338 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
339 | + // grab value |
|
340 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
341 | + switch ($what) { |
|
342 | + // integers |
|
343 | + case 'event_id': |
|
344 | + $valid_data[ $what ] = absint($input_value); |
|
345 | + // get event via the event id we put in the form |
|
346 | + $valid_data['event'] = EE_Registry::instance() |
|
347 | + ->load_model('Event') |
|
348 | + ->get_one_by_ID($valid_data['event_id']); |
|
349 | + break; |
|
350 | + case 'rows': |
|
351 | + case 'max_atndz': |
|
352 | + $valid_data[ $what ] = absint($input_value); |
|
353 | + break; |
|
354 | + // arrays of integers |
|
355 | + case 'qty': |
|
356 | + /** @var array $row_qty */ |
|
357 | + $row_qty = $input_value; |
|
358 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
359 | + if (! is_array($row_qty)) { |
|
360 | + // get number of rows |
|
361 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
362 | + ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
363 | + : 1; |
|
364 | + // explode ints by the dash |
|
365 | + $row_qty = explode('-', $row_qty); |
|
366 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
367 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
368 | + $row_qty = array($row => $qty); |
|
369 | + for ($x = 1; $x <= $rows; $x++) { |
|
370 | + if (! isset($row_qty[ $x ])) { |
|
371 | + $row_qty[ $x ] = 0; |
|
372 | + } |
|
373 | + } |
|
374 | + } |
|
375 | + ksort($row_qty); |
|
376 | + // cycle thru values |
|
377 | + foreach ($row_qty as $qty) { |
|
378 | + $qty = absint($qty); |
|
379 | + // sanitize as integers |
|
380 | + $valid_data[ $what ][] = $qty; |
|
381 | + $valid_data['total_tickets'] += $qty; |
|
382 | + } |
|
383 | + break; |
|
384 | + // array of integers |
|
385 | + case 'ticket_id': |
|
386 | + $value_array = array(); |
|
387 | + // cycle thru values |
|
388 | + foreach ((array) $input_value as $key => $value) { |
|
389 | + // allow only numbers, letters, spaces, commas and dashes |
|
390 | + $value_array[ $key ] = wp_strip_all_tags($value); |
|
391 | + // get ticket via the ticket id we put in the form |
|
392 | + $ticket_obj = EE_Registry::instance() |
|
393 | + ->load_model('Ticket') |
|
394 | + ->get_one_by_ID($value); |
|
395 | + $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
396 | + } |
|
397 | + $valid_data[ $what ] = $value_array; |
|
398 | + break; |
|
399 | + case 'return_url' : |
|
400 | + // grab and sanitize return-url |
|
401 | + $input_value = esc_url_raw($input_value); |
|
402 | + // was the request coming from an iframe ? if so, then: |
|
403 | + if (strpos($input_value, 'event_list=iframe')) { |
|
404 | + // get anchor fragment |
|
405 | + $input_value = explode('#', $input_value); |
|
406 | + $input_value = end($input_value); |
|
407 | + // use event list url instead, but append anchor |
|
408 | + $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
409 | + } |
|
410 | + $valid_data[ $what ] = $input_value; |
|
411 | + break; |
|
412 | + } // end switch $what |
|
413 | + } |
|
414 | + } // end foreach $inputs_to_clean |
|
415 | + return $valid_data; |
|
416 | + } |
|
417 | 417 | |
418 | 418 | |
419 | - /** |
|
420 | - * adds a ticket to the cart |
|
421 | - * |
|
422 | - * @param EE_Ticket $ticket |
|
423 | - * @param int $qty |
|
424 | - * @return TRUE on success, FALSE on fail |
|
425 | - * @throws InvalidArgumentException |
|
426 | - * @throws InvalidInterfaceException |
|
427 | - * @throws InvalidDataTypeException |
|
428 | - * @throws EE_Error |
|
429 | - */ |
|
430 | - private function addTicketToCart(EE_Ticket $ticket = null, $qty = 1) |
|
431 | - { |
|
432 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
433 | - // get the number of spaces left for this datetime ticket |
|
434 | - $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
435 | - // compare available spaces against the number of tickets being purchased |
|
436 | - if ($available_spaces >= $qty) { |
|
437 | - // allow addons to prevent a ticket from being added to cart |
|
438 | - if ( |
|
439 | - ! apply_filters( |
|
440 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
441 | - true, |
|
442 | - $ticket, |
|
443 | - $qty, |
|
444 | - $available_spaces |
|
445 | - ) |
|
446 | - ) { |
|
447 | - return false; |
|
448 | - } |
|
449 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
450 | - // add event to cart |
|
451 | - if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
452 | - $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
453 | - return true; |
|
454 | - } |
|
455 | - return false; |
|
456 | - } |
|
457 | - // tickets can not be purchased but let's find the exact number left |
|
458 | - // for the last ticket selected PRIOR to subtracting tickets |
|
459 | - $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
460 | - // greedy greedy greedy eh? |
|
461 | - if ($available_spaces > 0) { |
|
462 | - if ( |
|
463 | - apply_filters( |
|
464 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
465 | - true, |
|
466 | - $ticket, |
|
467 | - $qty, |
|
468 | - $available_spaces |
|
469 | - ) |
|
470 | - ) { |
|
471 | - $this->displayAvailabilityError($available_spaces); |
|
472 | - } |
|
473 | - } else { |
|
474 | - EE_Error::add_error( |
|
475 | - __( |
|
476 | - 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
477 | - 'event_espresso' |
|
478 | - ), |
|
479 | - __FILE__, __FUNCTION__, __LINE__ |
|
480 | - ); |
|
481 | - } |
|
482 | - return false; |
|
483 | - } |
|
419 | + /** |
|
420 | + * adds a ticket to the cart |
|
421 | + * |
|
422 | + * @param EE_Ticket $ticket |
|
423 | + * @param int $qty |
|
424 | + * @return TRUE on success, FALSE on fail |
|
425 | + * @throws InvalidArgumentException |
|
426 | + * @throws InvalidInterfaceException |
|
427 | + * @throws InvalidDataTypeException |
|
428 | + * @throws EE_Error |
|
429 | + */ |
|
430 | + private function addTicketToCart(EE_Ticket $ticket = null, $qty = 1) |
|
431 | + { |
|
432 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
433 | + // get the number of spaces left for this datetime ticket |
|
434 | + $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
435 | + // compare available spaces against the number of tickets being purchased |
|
436 | + if ($available_spaces >= $qty) { |
|
437 | + // allow addons to prevent a ticket from being added to cart |
|
438 | + if ( |
|
439 | + ! apply_filters( |
|
440 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
441 | + true, |
|
442 | + $ticket, |
|
443 | + $qty, |
|
444 | + $available_spaces |
|
445 | + ) |
|
446 | + ) { |
|
447 | + return false; |
|
448 | + } |
|
449 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
450 | + // add event to cart |
|
451 | + if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
452 | + $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
453 | + return true; |
|
454 | + } |
|
455 | + return false; |
|
456 | + } |
|
457 | + // tickets can not be purchased but let's find the exact number left |
|
458 | + // for the last ticket selected PRIOR to subtracting tickets |
|
459 | + $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
460 | + // greedy greedy greedy eh? |
|
461 | + if ($available_spaces > 0) { |
|
462 | + if ( |
|
463 | + apply_filters( |
|
464 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
465 | + true, |
|
466 | + $ticket, |
|
467 | + $qty, |
|
468 | + $available_spaces |
|
469 | + ) |
|
470 | + ) { |
|
471 | + $this->displayAvailabilityError($available_spaces); |
|
472 | + } |
|
473 | + } else { |
|
474 | + EE_Error::add_error( |
|
475 | + __( |
|
476 | + 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
477 | + 'event_espresso' |
|
478 | + ), |
|
479 | + __FILE__, __FUNCTION__, __LINE__ |
|
480 | + ); |
|
481 | + } |
|
482 | + return false; |
|
483 | + } |
|
484 | 484 | |
485 | 485 | |
486 | - /** |
|
487 | - * @param int $available_spaces |
|
488 | - * @throws InvalidArgumentException |
|
489 | - * @throws InvalidInterfaceException |
|
490 | - * @throws InvalidDataTypeException |
|
491 | - * @throws EE_Error |
|
492 | - */ |
|
493 | - private function displayAvailabilityError($available_spaces = 1) |
|
494 | - { |
|
495 | - // add error messaging - we're using the _n function that will generate |
|
496 | - // the appropriate singular or plural message based on the number of $available_spaces |
|
497 | - if (EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
498 | - $msg = sprintf( |
|
499 | - _n( |
|
500 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
501 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
502 | - $available_spaces, |
|
503 | - 'event_espresso' |
|
504 | - ), |
|
505 | - $available_spaces, |
|
506 | - '<br />' |
|
507 | - ); |
|
508 | - } else { |
|
509 | - $msg = sprintf( |
|
510 | - _n( |
|
511 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
512 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
513 | - $available_spaces, |
|
514 | - 'event_espresso' |
|
515 | - ), |
|
516 | - $available_spaces, |
|
517 | - '<br />' |
|
518 | - ); |
|
519 | - } |
|
520 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
521 | - } |
|
486 | + /** |
|
487 | + * @param int $available_spaces |
|
488 | + * @throws InvalidArgumentException |
|
489 | + * @throws InvalidInterfaceException |
|
490 | + * @throws InvalidDataTypeException |
|
491 | + * @throws EE_Error |
|
492 | + */ |
|
493 | + private function displayAvailabilityError($available_spaces = 1) |
|
494 | + { |
|
495 | + // add error messaging - we're using the _n function that will generate |
|
496 | + // the appropriate singular or plural message based on the number of $available_spaces |
|
497 | + if (EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
498 | + $msg = sprintf( |
|
499 | + _n( |
|
500 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
501 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
502 | + $available_spaces, |
|
503 | + 'event_espresso' |
|
504 | + ), |
|
505 | + $available_spaces, |
|
506 | + '<br />' |
|
507 | + ); |
|
508 | + } else { |
|
509 | + $msg = sprintf( |
|
510 | + _n( |
|
511 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
512 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
513 | + $available_spaces, |
|
514 | + 'event_espresso' |
|
515 | + ), |
|
516 | + $available_spaces, |
|
517 | + '<br />' |
|
518 | + ); |
|
519 | + } |
|
520 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
521 | + } |
|
522 | 522 | |
523 | 523 | |
524 | - /** |
|
525 | - * ticketDatetimeAvailability |
|
526 | - * creates an array of tickets plus all of the datetimes available to each ticket |
|
527 | - * and tracks the spaces remaining for each of those datetimes |
|
528 | - * |
|
529 | - * @param EE_Ticket $ticket - selected ticket |
|
530 | - * @param bool $get_original_ticket_spaces |
|
531 | - * @return int |
|
532 | - * @throws InvalidArgumentException |
|
533 | - * @throws InvalidInterfaceException |
|
534 | - * @throws InvalidDataTypeException |
|
535 | - * @throws EE_Error |
|
536 | - */ |
|
537 | - private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
538 | - { |
|
539 | - // if the $_available_spaces array has not been set up yet... |
|
540 | - if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
541 | - $this->setInitialTicketDatetimeAvailability($ticket); |
|
542 | - } |
|
543 | - $available_spaces = $ticket->qty() - $ticket->sold(); |
|
544 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
545 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
546 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
547 | - // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
548 | - if ($get_original_ticket_spaces) { |
|
549 | - // then grab the available spaces from the "tickets" array |
|
550 | - // and compare with the above to get the lowest number |
|
551 | - $available_spaces = min( |
|
552 | - $available_spaces, |
|
553 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
554 | - ); |
|
555 | - } else { |
|
556 | - // we want the updated ticket availability as stored in the "datetimes" array |
|
557 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
558 | - } |
|
559 | - } |
|
560 | - } |
|
561 | - return $available_spaces; |
|
562 | - } |
|
524 | + /** |
|
525 | + * ticketDatetimeAvailability |
|
526 | + * creates an array of tickets plus all of the datetimes available to each ticket |
|
527 | + * and tracks the spaces remaining for each of those datetimes |
|
528 | + * |
|
529 | + * @param EE_Ticket $ticket - selected ticket |
|
530 | + * @param bool $get_original_ticket_spaces |
|
531 | + * @return int |
|
532 | + * @throws InvalidArgumentException |
|
533 | + * @throws InvalidInterfaceException |
|
534 | + * @throws InvalidDataTypeException |
|
535 | + * @throws EE_Error |
|
536 | + */ |
|
537 | + private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
538 | + { |
|
539 | + // if the $_available_spaces array has not been set up yet... |
|
540 | + if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
541 | + $this->setInitialTicketDatetimeAvailability($ticket); |
|
542 | + } |
|
543 | + $available_spaces = $ticket->qty() - $ticket->sold(); |
|
544 | + if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
545 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
546 | + foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
547 | + // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
548 | + if ($get_original_ticket_spaces) { |
|
549 | + // then grab the available spaces from the "tickets" array |
|
550 | + // and compare with the above to get the lowest number |
|
551 | + $available_spaces = min( |
|
552 | + $available_spaces, |
|
553 | + self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
554 | + ); |
|
555 | + } else { |
|
556 | + // we want the updated ticket availability as stored in the "datetimes" array |
|
557 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
558 | + } |
|
559 | + } |
|
560 | + } |
|
561 | + return $available_spaces; |
|
562 | + } |
|
563 | 563 | |
564 | 564 | |
565 | - /** |
|
566 | - * @param EE_Ticket $ticket |
|
567 | - * @return void |
|
568 | - * @throws InvalidArgumentException |
|
569 | - * @throws InvalidInterfaceException |
|
570 | - * @throws InvalidDataTypeException |
|
571 | - * @throws EE_Error |
|
572 | - */ |
|
573 | - private function setInitialTicketDatetimeAvailability(EE_Ticket $ticket) |
|
574 | - { |
|
575 | - // first, get all of the datetimes that are available to this ticket |
|
576 | - $datetimes = $ticket->get_many_related( |
|
577 | - 'Datetime', |
|
578 | - array( |
|
579 | - array( |
|
580 | - 'DTT_EVT_end' => array( |
|
581 | - '>=', |
|
582 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
583 | - ), |
|
584 | - ), |
|
585 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
586 | - ) |
|
587 | - ); |
|
588 | - if (! empty($datetimes)) { |
|
589 | - // now loop thru all of the datetimes |
|
590 | - foreach ($datetimes as $datetime) { |
|
591 | - if ($datetime instanceof EE_Datetime) { |
|
592 | - // the number of spaces available for the datetime without considering individual ticket quantities |
|
593 | - $spaces_remaining = $datetime->spaces_remaining(); |
|
594 | - // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
595 | - // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
596 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
597 | - $ticket->qty() - $ticket->sold(), |
|
598 | - $spaces_remaining |
|
599 | - ); |
|
600 | - // if the remaining spaces for this datetime is already set, |
|
601 | - // then compare that against the datetime spaces remaining, and take the lowest number, |
|
602 | - // else just take the datetime spaces remaining, and assign to the datetimes array |
|
603 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
604 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
605 | - ) |
|
606 | - ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
607 | - : $spaces_remaining; |
|
608 | - } |
|
609 | - } |
|
610 | - } |
|
611 | - } |
|
565 | + /** |
|
566 | + * @param EE_Ticket $ticket |
|
567 | + * @return void |
|
568 | + * @throws InvalidArgumentException |
|
569 | + * @throws InvalidInterfaceException |
|
570 | + * @throws InvalidDataTypeException |
|
571 | + * @throws EE_Error |
|
572 | + */ |
|
573 | + private function setInitialTicketDatetimeAvailability(EE_Ticket $ticket) |
|
574 | + { |
|
575 | + // first, get all of the datetimes that are available to this ticket |
|
576 | + $datetimes = $ticket->get_many_related( |
|
577 | + 'Datetime', |
|
578 | + array( |
|
579 | + array( |
|
580 | + 'DTT_EVT_end' => array( |
|
581 | + '>=', |
|
582 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
583 | + ), |
|
584 | + ), |
|
585 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
586 | + ) |
|
587 | + ); |
|
588 | + if (! empty($datetimes)) { |
|
589 | + // now loop thru all of the datetimes |
|
590 | + foreach ($datetimes as $datetime) { |
|
591 | + if ($datetime instanceof EE_Datetime) { |
|
592 | + // the number of spaces available for the datetime without considering individual ticket quantities |
|
593 | + $spaces_remaining = $datetime->spaces_remaining(); |
|
594 | + // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
595 | + // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
596 | + self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
597 | + $ticket->qty() - $ticket->sold(), |
|
598 | + $spaces_remaining |
|
599 | + ); |
|
600 | + // if the remaining spaces for this datetime is already set, |
|
601 | + // then compare that against the datetime spaces remaining, and take the lowest number, |
|
602 | + // else just take the datetime spaces remaining, and assign to the datetimes array |
|
603 | + self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
604 | + self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
605 | + ) |
|
606 | + ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
607 | + : $spaces_remaining; |
|
608 | + } |
|
609 | + } |
|
610 | + } |
|
611 | + } |
|
612 | 612 | |
613 | 613 | |
614 | - /** |
|
615 | - * @param EE_Ticket $ticket |
|
616 | - * @param int $qty |
|
617 | - * @return void |
|
618 | - * @throws EE_Error |
|
619 | - */ |
|
620 | - private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
|
621 | - { |
|
622 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
623 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
624 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
625 | - // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
626 | - self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
627 | - } |
|
628 | - } |
|
629 | - } |
|
614 | + /** |
|
615 | + * @param EE_Ticket $ticket |
|
616 | + * @param int $qty |
|
617 | + * @return void |
|
618 | + * @throws EE_Error |
|
619 | + */ |
|
620 | + private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
|
621 | + { |
|
622 | + if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
623 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
624 | + foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
625 | + // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
626 | + self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
627 | + } |
|
628 | + } |
|
629 | + } |
|
630 | 630 | } |
631 | 631 | // End of file ProcessTicketSelector.php |
632 | 632 | // Location: /ProcessTicketSelector.php |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | use EventEspresso\core\services\loaders\LoaderFactory; |
14 | 14 | use InvalidArgumentException; |
15 | 15 | |
16 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
16 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
17 | 17 | exit('No direct script access allowed'); |
18 | 18 | } |
19 | 19 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | public function cancelTicketSelections() |
52 | 52 | { |
53 | 53 | // check nonce |
54 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
54 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
55 | 55 | return false; |
56 | 56 | } |
57 | 57 | EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ); |
64 | 64 | } else { |
65 | 65 | wp_safe_redirect( |
66 | - site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
66 | + site_url('/'.EE_Registry::instance()->CFG->core->event_cpt_slug.'/') |
|
67 | 67 | ); |
68 | 68 | } |
69 | 69 | exit(); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | { |
126 | 126 | do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
127 | 127 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
128 | - if($request->isBot()) { |
|
128 | + if ($request->isBot()) { |
|
129 | 129 | wp_safe_redirect( |
130 | 130 | apply_filters( |
131 | 131 | 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | exit(); |
136 | 136 | } |
137 | 137 | // do we have an event id? |
138 | - if (! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
138 | + if ( ! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
139 | 139 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
140 | 140 | EE_Error::add_error( |
141 | 141 | sprintf( |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $valid['total_tickets'], |
182 | 182 | 'event_espresso' |
183 | 183 | ); |
184 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
184 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
185 | 185 | // dev only message |
186 | 186 | $max_atndz_string = _n( |
187 | 187 | 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | $valid['max_atndz'], |
190 | 190 | 'event_espresso' |
191 | 191 | ); |
192 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
193 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
192 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
193 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
194 | 194 | } else { |
195 | 195 | // all data appears to be valid |
196 | 196 | $tckts_slctd = false; |
@@ -203,15 +203,15 @@ discard block |
||
203 | 203 | // cycle thru the number of data rows sent from the event listing |
204 | 204 | for ($x = 0; $x < $valid['rows']; $x++) { |
205 | 205 | // does this row actually contain a ticket quantity? |
206 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
206 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
207 | 207 | // YES we have a ticket quantity |
208 | 208 | $tckts_slctd = true; |
209 | 209 | // d( $valid['ticket_obj'][$x] ); |
210 | - if ($valid['ticket_obj'][ $x ] instanceof EE_Ticket) { |
|
210 | + if ($valid['ticket_obj'][$x] instanceof EE_Ticket) { |
|
211 | 211 | // then add ticket to cart |
212 | 212 | $tickets_added += $this->addTicketToCart( |
213 | - $valid['ticket_obj'][ $x ], |
|
214 | - $valid['qty'][ $x ] |
|
213 | + $valid['ticket_obj'][$x], |
|
214 | + $valid['qty'][$x] |
|
215 | 215 | ); |
216 | 216 | if (EE_Error::has_error()) { |
217 | 217 | break; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | ); |
263 | 263 | exit(); |
264 | 264 | } else { |
265 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
265 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
266 | 266 | // nothing added to cart |
267 | 267 | EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
268 | 268 | __FILE__, __FUNCTION__, __LINE__); |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | private function validatePostData($id = 0) |
309 | 309 | { |
310 | 310 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
311 | - if (! $id) { |
|
311 | + if ( ! $id) { |
|
312 | 312 | EE_Error::add_error( |
313 | 313 | __('The event id provided was not valid.', 'event_espresso'), |
314 | 314 | __FILE__, |
@@ -335,13 +335,13 @@ discard block |
||
335 | 335 | // cycle through $inputs_to_clean array |
336 | 336 | foreach ($inputs_to_clean as $what => $input_to_clean) { |
337 | 337 | // check for POST data |
338 | - if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
338 | + if (EE_Registry::instance()->REQ->is_set($input_to_clean.$id)) { |
|
339 | 339 | // grab value |
340 | - $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
340 | + $input_value = EE_Registry::instance()->REQ->get($input_to_clean.$id); |
|
341 | 341 | switch ($what) { |
342 | 342 | // integers |
343 | 343 | case 'event_id': |
344 | - $valid_data[ $what ] = absint($input_value); |
|
344 | + $valid_data[$what] = absint($input_value); |
|
345 | 345 | // get event via the event id we put in the form |
346 | 346 | $valid_data['event'] = EE_Registry::instance() |
347 | 347 | ->load_model('Event') |
@@ -349,17 +349,17 @@ discard block |
||
349 | 349 | break; |
350 | 350 | case 'rows': |
351 | 351 | case 'max_atndz': |
352 | - $valid_data[ $what ] = absint($input_value); |
|
352 | + $valid_data[$what] = absint($input_value); |
|
353 | 353 | break; |
354 | 354 | // arrays of integers |
355 | 355 | case 'qty': |
356 | 356 | /** @var array $row_qty */ |
357 | 357 | $row_qty = $input_value; |
358 | 358 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
359 | - if (! is_array($row_qty)) { |
|
359 | + if ( ! is_array($row_qty)) { |
|
360 | 360 | // get number of rows |
361 | - $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
362 | - ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
361 | + $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-'.$id) |
|
362 | + ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-'.$id)) |
|
363 | 363 | : 1; |
364 | 364 | // explode ints by the dash |
365 | 365 | $row_qty = explode('-', $row_qty); |
@@ -367,8 +367,8 @@ discard block |
||
367 | 367 | $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
368 | 368 | $row_qty = array($row => $qty); |
369 | 369 | for ($x = 1; $x <= $rows; $x++) { |
370 | - if (! isset($row_qty[ $x ])) { |
|
371 | - $row_qty[ $x ] = 0; |
|
370 | + if ( ! isset($row_qty[$x])) { |
|
371 | + $row_qty[$x] = 0; |
|
372 | 372 | } |
373 | 373 | } |
374 | 374 | } |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | foreach ($row_qty as $qty) { |
378 | 378 | $qty = absint($qty); |
379 | 379 | // sanitize as integers |
380 | - $valid_data[ $what ][] = $qty; |
|
380 | + $valid_data[$what][] = $qty; |
|
381 | 381 | $valid_data['total_tickets'] += $qty; |
382 | 382 | } |
383 | 383 | break; |
@@ -387,14 +387,14 @@ discard block |
||
387 | 387 | // cycle thru values |
388 | 388 | foreach ((array) $input_value as $key => $value) { |
389 | 389 | // allow only numbers, letters, spaces, commas and dashes |
390 | - $value_array[ $key ] = wp_strip_all_tags($value); |
|
390 | + $value_array[$key] = wp_strip_all_tags($value); |
|
391 | 391 | // get ticket via the ticket id we put in the form |
392 | 392 | $ticket_obj = EE_Registry::instance() |
393 | 393 | ->load_model('Ticket') |
394 | 394 | ->get_one_by_ID($value); |
395 | - $valid_data['ticket_obj'][ $key ] = $ticket_obj; |
|
395 | + $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
396 | 396 | } |
397 | - $valid_data[ $what ] = $value_array; |
|
397 | + $valid_data[$what] = $value_array; |
|
398 | 398 | break; |
399 | 399 | case 'return_url' : |
400 | 400 | // grab and sanitize return-url |
@@ -405,9 +405,9 @@ discard block |
||
405 | 405 | $input_value = explode('#', $input_value); |
406 | 406 | $input_value = end($input_value); |
407 | 407 | // use event list url instead, but append anchor |
408 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
408 | + $input_value = EEH_Event_View::event_archive_url().'#'.$input_value; |
|
409 | 409 | } |
410 | - $valid_data[ $what ] = $input_value; |
|
410 | + $valid_data[$what] = $input_value; |
|
411 | 411 | break; |
412 | 412 | } // end switch $what |
413 | 413 | } |
@@ -537,24 +537,24 @@ discard block |
||
537 | 537 | private function ticketDatetimeAvailability(EE_Ticket $ticket, $get_original_ticket_spaces = false) |
538 | 538 | { |
539 | 539 | // if the $_available_spaces array has not been set up yet... |
540 | - if (! isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
540 | + if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
541 | 541 | $this->setInitialTicketDatetimeAvailability($ticket); |
542 | 542 | } |
543 | 543 | $available_spaces = $ticket->qty() - $ticket->sold(); |
544 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
544 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
545 | 545 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
546 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
546 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
547 | 547 | // if we want the original datetime availability BEFORE we started subtracting tickets ? |
548 | 548 | if ($get_original_ticket_spaces) { |
549 | 549 | // then grab the available spaces from the "tickets" array |
550 | 550 | // and compare with the above to get the lowest number |
551 | 551 | $available_spaces = min( |
552 | 552 | $available_spaces, |
553 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $DTD_ID ] |
|
553 | + self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
554 | 554 | ); |
555 | 555 | } else { |
556 | 556 | // we want the updated ticket availability as stored in the "datetimes" array |
557 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][ $DTD_ID ]); |
|
557 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | } |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | 'order_by' => array('DTT_EVT_start' => 'ASC'), |
586 | 586 | ) |
587 | 587 | ); |
588 | - if (! empty($datetimes)) { |
|
588 | + if ( ! empty($datetimes)) { |
|
589 | 589 | // now loop thru all of the datetimes |
590 | 590 | foreach ($datetimes as $datetime) { |
591 | 591 | if ($datetime instanceof EE_Datetime) { |
@@ -593,17 +593,17 @@ discard block |
||
593 | 593 | $spaces_remaining = $datetime->spaces_remaining(); |
594 | 594 | // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
595 | 595 | // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
596 | - self::$_available_spaces['tickets'][ $ticket->ID() ][ $datetime->ID() ] = min( |
|
596 | + self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
597 | 597 | $ticket->qty() - $ticket->sold(), |
598 | 598 | $spaces_remaining |
599 | 599 | ); |
600 | 600 | // if the remaining spaces for this datetime is already set, |
601 | 601 | // then compare that against the datetime spaces remaining, and take the lowest number, |
602 | 602 | // else just take the datetime spaces remaining, and assign to the datetimes array |
603 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] = isset( |
|
604 | - self::$_available_spaces['datetimes'][ $datetime->ID() ] |
|
603 | + self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
604 | + self::$_available_spaces['datetimes'][$datetime->ID()] |
|
605 | 605 | ) |
606 | - ? min(self::$_available_spaces['datetimes'][ $datetime->ID() ], $spaces_remaining) |
|
606 | + ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
607 | 607 | : $spaces_remaining; |
608 | 608 | } |
609 | 609 | } |
@@ -619,11 +619,11 @@ discard block |
||
619 | 619 | */ |
620 | 620 | private function recalculateTicketDatetimeAvailability(EE_Ticket $ticket, $qty = 0) |
621 | 621 | { |
622 | - if (isset(self::$_available_spaces['tickets'][ $ticket->ID() ])) { |
|
622 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
623 | 623 | // loop thru tickets, which will ALSO include individual ticket records AND a total |
624 | - foreach (self::$_available_spaces['tickets'][ $ticket->ID() ] as $DTD_ID => $spaces) { |
|
624 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
625 | 625 | // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
626 | - self::$_available_spaces['datetimes'][ $DTD_ID ] -= $qty; |
|
626 | + self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
627 | 627 | } |
628 | 628 | } |
629 | 629 | } |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | // if you're a dev and want to receive all errors via email |
12 | 12 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
13 | 13 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
14 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
14 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -27,256 +27,256 @@ discard block |
||
27 | 27 | class EE_Error extends Exception |
28 | 28 | { |
29 | 29 | |
30 | - const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * name of the file to log exceptions to |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | - |
|
40 | - /** |
|
41 | - * stores details for all exception |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - private static $_all_exceptions = array(); |
|
46 | - |
|
47 | - /** |
|
48 | - * tracks number of errors |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - private static $_error_count = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array $_espresso_notices |
|
56 | - */ |
|
57 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @override default exception handling |
|
63 | - * @param string $message |
|
64 | - * @param int $code |
|
65 | - * @param Exception|null $previous |
|
66 | - */ |
|
67 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | - { |
|
69 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | - parent::__construct($message, $code); |
|
71 | - } else { |
|
72 | - parent::__construct($message, $code, $previous); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * error_handler |
|
80 | - * |
|
81 | - * @param $code |
|
82 | - * @param $message |
|
83 | - * @param $file |
|
84 | - * @param $line |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - public static function error_handler($code, $message, $file, $line) |
|
88 | - { |
|
89 | - $type = EE_Error::error_type($code); |
|
90 | - $site = site_url(); |
|
91 | - switch ($site) { |
|
92 | - case 'http://ee4.eventespresso.com/' : |
|
93 | - case 'http://ee4decaf.eventespresso.com/' : |
|
94 | - case 'http://ee4hf.eventespresso.com/' : |
|
95 | - case 'http://ee4a.eventespresso.com/' : |
|
96 | - case 'http://ee4ad.eventespresso.com/' : |
|
97 | - case 'http://ee4b.eventespresso.com/' : |
|
98 | - case 'http://ee4bd.eventespresso.com/' : |
|
99 | - case 'http://ee4d.eventespresso.com/' : |
|
100 | - case 'http://ee4dd.eventespresso.com/' : |
|
101 | - $to = '[email protected]'; |
|
102 | - break; |
|
103 | - default : |
|
104 | - $to = get_option('admin_email'); |
|
105 | - } |
|
106 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
107 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
108 | - if (function_exists('wp_mail')) { |
|
109 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
110 | - wp_mail($to, $subject, $msg); |
|
111 | - } |
|
112 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
113 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
114 | - echo '<br /></p></div>'; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * error_type |
|
121 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
122 | - * |
|
123 | - * @param $code |
|
124 | - * @return string |
|
125 | - */ |
|
126 | - public static function error_type($code) |
|
127 | - { |
|
128 | - switch ($code) { |
|
129 | - case E_ERROR: // 1 // |
|
130 | - return 'E_ERROR'; |
|
131 | - case E_WARNING: // 2 // |
|
132 | - return 'E_WARNING'; |
|
133 | - case E_PARSE: // 4 // |
|
134 | - return 'E_PARSE'; |
|
135 | - case E_NOTICE: // 8 // |
|
136 | - return 'E_NOTICE'; |
|
137 | - case E_CORE_ERROR: // 16 // |
|
138 | - return 'E_CORE_ERROR'; |
|
139 | - case E_CORE_WARNING: // 32 // |
|
140 | - return 'E_CORE_WARNING'; |
|
141 | - case E_COMPILE_ERROR: // 64 // |
|
142 | - return 'E_COMPILE_ERROR'; |
|
143 | - case E_COMPILE_WARNING: // 128 // |
|
144 | - return 'E_COMPILE_WARNING'; |
|
145 | - case E_USER_ERROR: // 256 // |
|
146 | - return 'E_USER_ERROR'; |
|
147 | - case E_USER_WARNING: // 512 // |
|
148 | - return 'E_USER_WARNING'; |
|
149 | - case E_USER_NOTICE: // 1024 // |
|
150 | - return 'E_USER_NOTICE'; |
|
151 | - case E_STRICT: // 2048 // |
|
152 | - return 'E_STRICT'; |
|
153 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
154 | - return 'E_RECOVERABLE_ERROR'; |
|
155 | - case E_DEPRECATED: // 8192 // |
|
156 | - return 'E_DEPRECATED'; |
|
157 | - case E_USER_DEPRECATED: // 16384 // |
|
158 | - return 'E_USER_DEPRECATED'; |
|
159 | - case E_ALL: // 16384 // |
|
160 | - return 'E_ALL'; |
|
161 | - } |
|
162 | - return ''; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * fatal_error_handler |
|
169 | - * |
|
170 | - * @return void |
|
171 | - */ |
|
172 | - public static function fatal_error_handler() |
|
173 | - { |
|
174 | - $last_error = error_get_last(); |
|
175 | - if ($last_error['type'] === E_ERROR) { |
|
176 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * _format_error |
|
184 | - * |
|
185 | - * @param $code |
|
186 | - * @param $message |
|
187 | - * @param $file |
|
188 | - * @param $line |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - private static function _format_error($code, $message, $file, $line) |
|
192 | - { |
|
193 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
194 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
195 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
196 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
197 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
198 | - $html .= '</tbody></table>'; |
|
199 | - return $html; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * set_content_type |
|
206 | - * |
|
207 | - * @param $content_type |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - public static function set_content_type($content_type) |
|
211 | - { |
|
212 | - return 'text/html'; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * @return void |
|
219 | - * @throws EE_Error |
|
220 | - * @throws ReflectionException |
|
221 | - */ |
|
222 | - public function get_error() |
|
223 | - { |
|
224 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
225 | - throw $this; |
|
226 | - } |
|
227 | - // get separate user and developer messages if they exist |
|
228 | - $msg = explode('||', $this->getMessage()); |
|
229 | - $user_msg = $msg[0]; |
|
230 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
231 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
232 | - // add details to _all_exceptions array |
|
233 | - $x_time = time(); |
|
234 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
235 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
236 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
237 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
238 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
239 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
240 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
241 | - self::$_error_count++; |
|
242 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
243 | - $this->display_errors(); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - |
|
248 | - /** |
|
249 | - * @param bool $check_stored |
|
250 | - * @param string $type_to_check |
|
251 | - * @return bool |
|
252 | - */ |
|
253 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
254 | - { |
|
255 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
256 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
257 | - ? true |
|
258 | - : false; |
|
259 | - if ($check_stored && ! $has_error) { |
|
260 | - $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
261 | - foreach ($notices as $type => $notice) { |
|
262 | - if ($type === $type_to_check && $notice) { |
|
263 | - return true; |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
267 | - return $has_error; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * @echo string |
|
274 | - * @throws \ReflectionException |
|
275 | - */ |
|
276 | - public function display_errors() |
|
277 | - { |
|
278 | - $trace_details = ''; |
|
279 | - $output = ' |
|
30 | + const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * name of the file to log exceptions to |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | + |
|
40 | + /** |
|
41 | + * stores details for all exception |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + private static $_all_exceptions = array(); |
|
46 | + |
|
47 | + /** |
|
48 | + * tracks number of errors |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + private static $_error_count = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array $_espresso_notices |
|
56 | + */ |
|
57 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @override default exception handling |
|
63 | + * @param string $message |
|
64 | + * @param int $code |
|
65 | + * @param Exception|null $previous |
|
66 | + */ |
|
67 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | + { |
|
69 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | + parent::__construct($message, $code); |
|
71 | + } else { |
|
72 | + parent::__construct($message, $code, $previous); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * error_handler |
|
80 | + * |
|
81 | + * @param $code |
|
82 | + * @param $message |
|
83 | + * @param $file |
|
84 | + * @param $line |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + public static function error_handler($code, $message, $file, $line) |
|
88 | + { |
|
89 | + $type = EE_Error::error_type($code); |
|
90 | + $site = site_url(); |
|
91 | + switch ($site) { |
|
92 | + case 'http://ee4.eventespresso.com/' : |
|
93 | + case 'http://ee4decaf.eventespresso.com/' : |
|
94 | + case 'http://ee4hf.eventespresso.com/' : |
|
95 | + case 'http://ee4a.eventespresso.com/' : |
|
96 | + case 'http://ee4ad.eventespresso.com/' : |
|
97 | + case 'http://ee4b.eventespresso.com/' : |
|
98 | + case 'http://ee4bd.eventespresso.com/' : |
|
99 | + case 'http://ee4d.eventespresso.com/' : |
|
100 | + case 'http://ee4dd.eventespresso.com/' : |
|
101 | + $to = '[email protected]'; |
|
102 | + break; |
|
103 | + default : |
|
104 | + $to = get_option('admin_email'); |
|
105 | + } |
|
106 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
107 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
108 | + if (function_exists('wp_mail')) { |
|
109 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
110 | + wp_mail($to, $subject, $msg); |
|
111 | + } |
|
112 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
113 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
114 | + echo '<br /></p></div>'; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * error_type |
|
121 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
122 | + * |
|
123 | + * @param $code |
|
124 | + * @return string |
|
125 | + */ |
|
126 | + public static function error_type($code) |
|
127 | + { |
|
128 | + switch ($code) { |
|
129 | + case E_ERROR: // 1 // |
|
130 | + return 'E_ERROR'; |
|
131 | + case E_WARNING: // 2 // |
|
132 | + return 'E_WARNING'; |
|
133 | + case E_PARSE: // 4 // |
|
134 | + return 'E_PARSE'; |
|
135 | + case E_NOTICE: // 8 // |
|
136 | + return 'E_NOTICE'; |
|
137 | + case E_CORE_ERROR: // 16 // |
|
138 | + return 'E_CORE_ERROR'; |
|
139 | + case E_CORE_WARNING: // 32 // |
|
140 | + return 'E_CORE_WARNING'; |
|
141 | + case E_COMPILE_ERROR: // 64 // |
|
142 | + return 'E_COMPILE_ERROR'; |
|
143 | + case E_COMPILE_WARNING: // 128 // |
|
144 | + return 'E_COMPILE_WARNING'; |
|
145 | + case E_USER_ERROR: // 256 // |
|
146 | + return 'E_USER_ERROR'; |
|
147 | + case E_USER_WARNING: // 512 // |
|
148 | + return 'E_USER_WARNING'; |
|
149 | + case E_USER_NOTICE: // 1024 // |
|
150 | + return 'E_USER_NOTICE'; |
|
151 | + case E_STRICT: // 2048 // |
|
152 | + return 'E_STRICT'; |
|
153 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
154 | + return 'E_RECOVERABLE_ERROR'; |
|
155 | + case E_DEPRECATED: // 8192 // |
|
156 | + return 'E_DEPRECATED'; |
|
157 | + case E_USER_DEPRECATED: // 16384 // |
|
158 | + return 'E_USER_DEPRECATED'; |
|
159 | + case E_ALL: // 16384 // |
|
160 | + return 'E_ALL'; |
|
161 | + } |
|
162 | + return ''; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * fatal_error_handler |
|
169 | + * |
|
170 | + * @return void |
|
171 | + */ |
|
172 | + public static function fatal_error_handler() |
|
173 | + { |
|
174 | + $last_error = error_get_last(); |
|
175 | + if ($last_error['type'] === E_ERROR) { |
|
176 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * _format_error |
|
184 | + * |
|
185 | + * @param $code |
|
186 | + * @param $message |
|
187 | + * @param $file |
|
188 | + * @param $line |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + private static function _format_error($code, $message, $file, $line) |
|
192 | + { |
|
193 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
194 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
195 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
196 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
197 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
198 | + $html .= '</tbody></table>'; |
|
199 | + return $html; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * set_content_type |
|
206 | + * |
|
207 | + * @param $content_type |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + public static function set_content_type($content_type) |
|
211 | + { |
|
212 | + return 'text/html'; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * @return void |
|
219 | + * @throws EE_Error |
|
220 | + * @throws ReflectionException |
|
221 | + */ |
|
222 | + public function get_error() |
|
223 | + { |
|
224 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
225 | + throw $this; |
|
226 | + } |
|
227 | + // get separate user and developer messages if they exist |
|
228 | + $msg = explode('||', $this->getMessage()); |
|
229 | + $user_msg = $msg[0]; |
|
230 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
231 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
232 | + // add details to _all_exceptions array |
|
233 | + $x_time = time(); |
|
234 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
235 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
236 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
237 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
238 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
239 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
240 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
241 | + self::$_error_count++; |
|
242 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
243 | + $this->display_errors(); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + |
|
248 | + /** |
|
249 | + * @param bool $check_stored |
|
250 | + * @param string $type_to_check |
|
251 | + * @return bool |
|
252 | + */ |
|
253 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
254 | + { |
|
255 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
256 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
257 | + ? true |
|
258 | + : false; |
|
259 | + if ($check_stored && ! $has_error) { |
|
260 | + $notices = (array)get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
261 | + foreach ($notices as $type => $notice) { |
|
262 | + if ($type === $type_to_check && $notice) { |
|
263 | + return true; |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | + return $has_error; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * @echo string |
|
274 | + * @throws \ReflectionException |
|
275 | + */ |
|
276 | + public function display_errors() |
|
277 | + { |
|
278 | + $trace_details = ''; |
|
279 | + $output = ' |
|
280 | 280 | <style type="text/css"> |
281 | 281 | #ee-error-message { |
282 | 282 | max-width:90% !important; |
@@ -332,21 +332,21 @@ discard block |
||
332 | 332 | } |
333 | 333 | </style> |
334 | 334 | <div id="ee-error-message" class="error">'; |
335 | - if (! WP_DEBUG) { |
|
336 | - $output .= ' |
|
335 | + if (! WP_DEBUG) { |
|
336 | + $output .= ' |
|
337 | 337 | <p>'; |
338 | - } |
|
339 | - // cycle thru errors |
|
340 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
341 | - $error_code = ''; |
|
342 | - // process trace info |
|
343 | - if (empty($ex['trace'])) { |
|
344 | - $trace_details .= __( |
|
345 | - 'Sorry, but no trace information was available for this exception.', |
|
346 | - 'event_espresso' |
|
347 | - ); |
|
348 | - } else { |
|
349 | - $trace_details .= ' |
|
338 | + } |
|
339 | + // cycle thru errors |
|
340 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
341 | + $error_code = ''; |
|
342 | + // process trace info |
|
343 | + if (empty($ex['trace'])) { |
|
344 | + $trace_details .= __( |
|
345 | + 'Sorry, but no trace information was available for this exception.', |
|
346 | + 'event_espresso' |
|
347 | + ); |
|
348 | + } else { |
|
349 | + $trace_details .= ' |
|
350 | 350 | <div id="ee-trace-details"> |
351 | 351 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
352 | 352 | <tr> |
@@ -356,43 +356,43 @@ discard block |
||
356 | 356 | <th scope="col" align="left">Class</th> |
357 | 357 | <th scope="col" align="left">Method( arguments )</th> |
358 | 358 | </tr>'; |
359 | - $last_on_stack = count($ex['trace']) - 1; |
|
360 | - // reverse array so that stack is in proper chronological order |
|
361 | - $sorted_trace = array_reverse($ex['trace']); |
|
362 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
363 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
364 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
365 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
366 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
367 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
368 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
369 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
370 | - if (empty($file) && ! empty($class)) { |
|
371 | - $a = new ReflectionClass($class); |
|
372 | - $file = $a->getFileName(); |
|
373 | - if (empty($line) && ! empty($function)) { |
|
374 | - try { |
|
375 | - //if $function is a closure, this throws an exception |
|
376 | - $b = new ReflectionMethod($class, $function); |
|
377 | - $line = $b->getStartLine(); |
|
378 | - } catch (Exception $closure_exception) { |
|
379 | - $line = 'unknown'; |
|
380 | - } |
|
381 | - } |
|
382 | - } |
|
383 | - if ($nmbr === $last_on_stack) { |
|
384 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
385 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
386 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
387 | - } |
|
388 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
389 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
390 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
391 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
392 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
393 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
394 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
395 | - $trace_details .= ' |
|
359 | + $last_on_stack = count($ex['trace']) - 1; |
|
360 | + // reverse array so that stack is in proper chronological order |
|
361 | + $sorted_trace = array_reverse($ex['trace']); |
|
362 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
363 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
364 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
365 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
366 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
367 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
368 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
369 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
370 | + if (empty($file) && ! empty($class)) { |
|
371 | + $a = new ReflectionClass($class); |
|
372 | + $file = $a->getFileName(); |
|
373 | + if (empty($line) && ! empty($function)) { |
|
374 | + try { |
|
375 | + //if $function is a closure, this throws an exception |
|
376 | + $b = new ReflectionMethod($class, $function); |
|
377 | + $line = $b->getStartLine(); |
|
378 | + } catch (Exception $closure_exception) { |
|
379 | + $line = 'unknown'; |
|
380 | + } |
|
381 | + } |
|
382 | + } |
|
383 | + if ($nmbr === $last_on_stack) { |
|
384 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
385 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
386 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
387 | + } |
|
388 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
389 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
390 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
391 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
392 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
393 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
394 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
395 | + $trace_details .= ' |
|
396 | 396 | <tr> |
397 | 397 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
398 | 398 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -400,523 +400,523 @@ discard block |
||
400 | 400 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
401 | 401 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
402 | 402 | </tr>'; |
403 | - } |
|
404 | - $trace_details .= ' |
|
403 | + } |
|
404 | + $trace_details .= ' |
|
405 | 405 | </table> |
406 | 406 | </div>'; |
407 | - } |
|
408 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
409 | - // add generic non-identifying messages for non-privileged users |
|
410 | - if (! WP_DEBUG) { |
|
411 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
412 | - . trim($ex['msg']) |
|
413 | - . '</span> <sup>' |
|
414 | - . $ex['code'] |
|
415 | - . '</sup><br />'; |
|
416 | - } else { |
|
417 | - // or helpful developer messages if debugging is on |
|
418 | - $output .= ' |
|
407 | + } |
|
408 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
409 | + // add generic non-identifying messages for non-privileged users |
|
410 | + if (! WP_DEBUG) { |
|
411 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
412 | + . trim($ex['msg']) |
|
413 | + . '</span> <sup>' |
|
414 | + . $ex['code'] |
|
415 | + . '</sup><br />'; |
|
416 | + } else { |
|
417 | + // or helpful developer messages if debugging is on |
|
418 | + $output .= ' |
|
419 | 419 | <div class="ee-error-dev-msg-dv"> |
420 | 420 | <p class="ee-error-dev-msg-pg"> |
421 | 421 | <strong class="ee-error-dev-msg-str">An ' |
422 | - . $ex['name'] |
|
423 | - . ' exception was thrown!</strong> <span>code: ' |
|
424 | - . $ex['code'] |
|
425 | - . '</span><br /> |
|
422 | + . $ex['name'] |
|
423 | + . ' exception was thrown!</strong> <span>code: ' |
|
424 | + . $ex['code'] |
|
425 | + . '</span><br /> |
|
426 | 426 | <span class="big-text">"' |
427 | - . trim($ex['msg']) |
|
428 | - . '"</span><br/> |
|
427 | + . trim($ex['msg']) |
|
428 | + . '"</span><br/> |
|
429 | 429 | <a id="display-ee-error-trace-' |
430 | - . self::$_error_count |
|
431 | - . $time |
|
432 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
433 | - . self::$_error_count |
|
434 | - . $time |
|
435 | - . '"> |
|
430 | + . self::$_error_count |
|
431 | + . $time |
|
432 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
433 | + . self::$_error_count |
|
434 | + . $time |
|
435 | + . '"> |
|
436 | 436 | ' |
437 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
438 | - . ' |
|
437 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
438 | + . ' |
|
439 | 439 | </a><br /> |
440 | 440 | <span class="small-text lt-grey-text">' |
441 | - . $ex['file'] |
|
442 | - . ' ( line no: ' |
|
443 | - . $ex['line'] |
|
444 | - . ' )</span> |
|
441 | + . $ex['file'] |
|
442 | + . ' ( line no: ' |
|
443 | + . $ex['line'] |
|
444 | + . ' )</span> |
|
445 | 445 | </p> |
446 | 446 | <div id="ee-error-trace-' |
447 | - . self::$_error_count |
|
448 | - . $time |
|
449 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
447 | + . self::$_error_count |
|
448 | + . $time |
|
449 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
450 | 450 | ' |
451 | - . $trace_details; |
|
452 | - if (! empty($class)) { |
|
453 | - $output .= ' |
|
451 | + . $trace_details; |
|
452 | + if (! empty($class)) { |
|
453 | + $output .= ' |
|
454 | 454 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
455 | 455 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
456 | 456 | <h3>Class Details</h3>'; |
457 | - $a = new ReflectionClass($class); |
|
458 | - $output .= ' |
|
457 | + $a = new ReflectionClass($class); |
|
458 | + $output .= ' |
|
459 | 459 | <pre>' . $a . '</pre> |
460 | 460 | </div> |
461 | 461 | </div>'; |
462 | - } |
|
463 | - $output .= ' |
|
462 | + } |
|
463 | + $output .= ' |
|
464 | 464 | </div> |
465 | 465 | </div> |
466 | 466 | <br />'; |
467 | - } |
|
468 | - $this->write_to_error_log($time, $ex); |
|
469 | - } |
|
470 | - // remove last linebreak |
|
471 | - $output = substr($output, 0, -6); |
|
472 | - if (! WP_DEBUG) { |
|
473 | - $output .= ' |
|
467 | + } |
|
468 | + $this->write_to_error_log($time, $ex); |
|
469 | + } |
|
470 | + // remove last linebreak |
|
471 | + $output = substr($output, 0, -6); |
|
472 | + if (! WP_DEBUG) { |
|
473 | + $output .= ' |
|
474 | 474 | </p>'; |
475 | - } |
|
476 | - $output .= ' |
|
475 | + } |
|
476 | + $output .= ' |
|
477 | 477 | </div>'; |
478 | - $output .= self::_print_scripts(true); |
|
479 | - if (defined('DOING_AJAX')) { |
|
480 | - echo wp_json_encode(array('error' => $output)); |
|
481 | - exit(); |
|
482 | - } |
|
483 | - echo $output; |
|
484 | - die(); |
|
485 | - } |
|
486 | - |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * generate string from exception trace args |
|
491 | - * |
|
492 | - * @param array $arguments |
|
493 | - * @param bool $array |
|
494 | - * @return string |
|
495 | - */ |
|
496 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
497 | - { |
|
498 | - $arg_string = ''; |
|
499 | - if (! empty($arguments)) { |
|
500 | - $args = array(); |
|
501 | - foreach ($arguments as $arg) { |
|
502 | - if (! empty($arg)) { |
|
503 | - if (is_string($arg)) { |
|
504 | - $args[] = " '" . $arg . "'"; |
|
505 | - } elseif (is_array($arg)) { |
|
506 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
507 | - } elseif ($arg === null) { |
|
508 | - $args[] = ' NULL'; |
|
509 | - } elseif (is_bool($arg)) { |
|
510 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
511 | - } elseif (is_object($arg)) { |
|
512 | - $args[] = ' OBJECT ' . get_class($arg); |
|
513 | - } elseif (is_resource($arg)) { |
|
514 | - $args[] = get_resource_type($arg); |
|
515 | - } else { |
|
516 | - $args[] = $arg; |
|
517 | - } |
|
518 | - } |
|
519 | - } |
|
520 | - $arg_string = implode(', ', $args); |
|
521 | - } |
|
522 | - if ($array) { |
|
523 | - $arg_string .= ' )'; |
|
524 | - } |
|
525 | - return $arg_string; |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * add error message |
|
532 | - * |
|
533 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
534 | - * separate messages for user || dev |
|
535 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
536 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
537 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
538 | - * @return void |
|
539 | - */ |
|
540 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
541 | - { |
|
542 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
543 | - self::$_error_count++; |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
550 | - * adds an error |
|
551 | - * |
|
552 | - * @param string $msg |
|
553 | - * @param string $file |
|
554 | - * @param string $func |
|
555 | - * @param string $line |
|
556 | - * @throws EE_Error |
|
557 | - */ |
|
558 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
559 | - { |
|
560 | - if (WP_DEBUG) { |
|
561 | - throw new EE_Error($msg); |
|
562 | - } |
|
563 | - EE_Error::add_error($msg, $file, $func, $line); |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * add success message |
|
570 | - * |
|
571 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
572 | - * separate messages for user || dev |
|
573 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
574 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
575 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
576 | - * @return void |
|
577 | - */ |
|
578 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
579 | - { |
|
580 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * add attention message |
|
587 | - * |
|
588 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
589 | - * separate messages for user || dev |
|
590 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
591 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
592 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
593 | - * @return void |
|
594 | - */ |
|
595 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
596 | - { |
|
597 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
598 | - } |
|
599 | - |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * @param string $type whether the message is for a success or error notification |
|
604 | - * @param string $msg the message to display to users or developers |
|
605 | - * - adding a double pipe || (OR) creates separate messages for user || dev |
|
606 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
607 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
608 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
609 | - * @return void |
|
610 | - */ |
|
611 | - private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
612 | - { |
|
613 | - if (empty($msg)) { |
|
614 | - EE_Error::doing_it_wrong( |
|
615 | - 'EE_Error::add_' . $type . '()', |
|
616 | - sprintf( |
|
617 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
618 | - 'event_espresso'), |
|
619 | - $type, |
|
620 | - $file, |
|
621 | - $line |
|
622 | - ), |
|
623 | - EVENT_ESPRESSO_VERSION |
|
624 | - ); |
|
625 | - } |
|
626 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
627 | - EE_Error::doing_it_wrong( |
|
628 | - 'EE_Error::add_error()', |
|
629 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
630 | - 'event_espresso'), |
|
631 | - EVENT_ESPRESSO_VERSION |
|
632 | - ); |
|
633 | - } |
|
634 | - // get separate user and developer messages if they exist |
|
635 | - $msg = explode('||', $msg); |
|
636 | - $user_msg = $msg[0]; |
|
637 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
638 | - /** |
|
639 | - * Do an action so other code can be triggered when a notice is created |
|
640 | - * |
|
641 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
642 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
643 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
644 | - * @param string $file file where error was generated |
|
645 | - * @param string $func function where error was generated |
|
646 | - * @param string $line line where error was generated |
|
647 | - */ |
|
648 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
649 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
650 | - // add notice if message exists |
|
651 | - if (! empty($msg)) { |
|
652 | - // get error code |
|
653 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
654 | - if (WP_DEBUG && $type === 'errors') { |
|
655 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
656 | - } |
|
657 | - // add notice. Index by code if it's not blank |
|
658 | - if ($notice_code) { |
|
659 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
660 | - } else { |
|
661 | - self::$_espresso_notices[$type][] = $msg; |
|
662 | - } |
|
663 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
664 | - } |
|
665 | - } |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * in some case it may be necessary to overwrite the existing success messages |
|
670 | - * |
|
671 | - * @return void |
|
672 | - */ |
|
673 | - public static function overwrite_success() |
|
674 | - { |
|
675 | - self::$_espresso_notices['success'] = false; |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * in some case it may be necessary to overwrite the existing attention messages |
|
682 | - * |
|
683 | - * @return void |
|
684 | - */ |
|
685 | - public static function overwrite_attention() |
|
686 | - { |
|
687 | - self::$_espresso_notices['attention'] = false; |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - |
|
692 | - /** |
|
693 | - * in some case it may be necessary to overwrite the existing error messages |
|
694 | - * |
|
695 | - * @return void |
|
696 | - */ |
|
697 | - public static function overwrite_errors() |
|
698 | - { |
|
699 | - self::$_espresso_notices['errors'] = false; |
|
700 | - } |
|
701 | - |
|
702 | - |
|
703 | - |
|
704 | - /** |
|
705 | - * @return void |
|
706 | - */ |
|
707 | - public static function reset_notices() |
|
708 | - { |
|
709 | - self::$_espresso_notices['success'] = false; |
|
710 | - self::$_espresso_notices['attention'] = false; |
|
711 | - self::$_espresso_notices['errors'] = false; |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * @return int |
|
718 | - */ |
|
719 | - public static function has_notices() |
|
720 | - { |
|
721 | - $has_notices = 0; |
|
722 | - // check for success messages |
|
723 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
724 | - ? 3 |
|
725 | - : $has_notices; |
|
726 | - // check for attention messages |
|
727 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
728 | - ? 2 |
|
729 | - : $has_notices; |
|
730 | - // check for error messages |
|
731 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
732 | - ? 1 |
|
733 | - : $has_notices; |
|
734 | - return $has_notices; |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
740 | - * |
|
741 | - * @since 4.9.0 |
|
742 | - * @return array |
|
743 | - */ |
|
744 | - public static function get_vanilla_notices() |
|
745 | - { |
|
746 | - return array( |
|
747 | - 'success' => isset(self::$_espresso_notices['success']) |
|
748 | - ? self::$_espresso_notices['success'] |
|
749 | - : array(), |
|
750 | - 'attention' => isset(self::$_espresso_notices['attention']) |
|
751 | - ? self::$_espresso_notices['attention'] |
|
752 | - : array(), |
|
753 | - 'errors' => isset(self::$_espresso_notices['errors']) |
|
754 | - ? self::$_espresso_notices['errors'] |
|
755 | - : array(), |
|
756 | - ); |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - |
|
761 | - /** |
|
762 | - * compile all error or success messages into one string |
|
763 | - * |
|
764 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
765 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
766 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
767 | - * - ONLY do this just before redirecting |
|
768 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
769 | - * @return array |
|
770 | - */ |
|
771 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
772 | - { |
|
773 | - // do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
774 | - $success_messages = ''; |
|
775 | - $attention_messages = ''; |
|
776 | - $error_messages = ''; |
|
777 | - $print_scripts = false; |
|
778 | - // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
779 | - // either save notices to the db |
|
780 | - if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
781 | - $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | - $existing_notices = is_array($existing_notices) ? $existing_notices : array(); |
|
783 | - self::$_espresso_notices = array_merge( |
|
784 | - $existing_notices, |
|
785 | - self::$_espresso_notices |
|
786 | - ); |
|
787 | - update_option(EE_Error::OPTIONS_KEY_NOTICES, self::$_espresso_notices); |
|
788 | - return array(); |
|
789 | - } |
|
790 | - // grab any notices that have been previously saved |
|
791 | - if ($notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array())) { |
|
792 | - foreach ($notices as $type => $notice) { |
|
793 | - if (is_array($notice) && ! empty($notice)) { |
|
794 | - // make sure that existing notice type is an array |
|
795 | - self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
796 | - && ! empty(self::$_espresso_notices[$type]) |
|
797 | - ? self::$_espresso_notices[$type] |
|
798 | - : array(); |
|
799 | - // merge stored notices with any newly created ones |
|
800 | - self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
801 | - $print_scripts = true; |
|
802 | - } |
|
803 | - } |
|
804 | - // now clear any stored notices |
|
805 | - update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
806 | - } |
|
807 | - // check for success messages |
|
808 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
809 | - // combine messages |
|
810 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
811 | - $print_scripts = true; |
|
812 | - } |
|
813 | - // check for attention messages |
|
814 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
815 | - // combine messages |
|
816 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
817 | - $print_scripts = true; |
|
818 | - } |
|
819 | - // check for error messages |
|
820 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
821 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
822 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
823 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
824 | - // combine messages |
|
825 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
826 | - $print_scripts = true; |
|
827 | - } |
|
828 | - if ($format_output) { |
|
829 | - |
|
830 | - $notices = '<div id="espresso-notices">'; |
|
831 | - $close = is_admin() ? '' |
|
832 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
833 | - if ($success_messages !== '') { |
|
834 | - $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
|
835 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
836 | - //showMessage( $success_messages ); |
|
837 | - $notices .= '<div id="' |
|
838 | - . $css_id |
|
839 | - . '" class="espresso-notices ' |
|
840 | - . $css_class |
|
841 | - . '" style="display:none;"><p>' |
|
842 | - . $success_messages |
|
843 | - . '</p>' |
|
844 | - . $close |
|
845 | - . '</div>'; |
|
846 | - } |
|
847 | - if ($attention_messages !== '') { |
|
848 | - $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
|
849 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
850 | - //showMessage( $error_messages, TRUE ); |
|
851 | - $notices .= '<div id="' |
|
852 | - . $css_id |
|
853 | - . '" class="espresso-notices ' |
|
854 | - . $css_class |
|
855 | - . '" style="display:none;"><p>' |
|
856 | - . $attention_messages |
|
857 | - . '</p>' |
|
858 | - . $close |
|
859 | - . '</div>'; |
|
860 | - } |
|
861 | - if ($error_messages !== '') { |
|
862 | - $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
|
863 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
864 | - //showMessage( $error_messages, TRUE ); |
|
865 | - $notices .= '<div id="' |
|
866 | - . $css_id |
|
867 | - . '" class="espresso-notices ' |
|
868 | - . $css_class |
|
869 | - . '" style="display:none;"><p>' |
|
870 | - . $error_messages |
|
871 | - . '</p>' |
|
872 | - . $close |
|
873 | - . '</div>'; |
|
874 | - } |
|
875 | - $notices .= '</div>'; |
|
876 | - } else { |
|
877 | - |
|
878 | - $notices = array( |
|
879 | - 'success' => $success_messages, |
|
880 | - 'attention' => $attention_messages, |
|
881 | - 'errors' => $error_messages, |
|
882 | - ); |
|
883 | - if ($remove_empty) { |
|
884 | - // remove empty notices |
|
885 | - foreach ($notices as $type => $notice) { |
|
886 | - if (empty($notice)) { |
|
887 | - unset($notices[$type]); |
|
888 | - } |
|
889 | - } |
|
890 | - } |
|
891 | - } |
|
892 | - if ($print_scripts) { |
|
893 | - self::_print_scripts(); |
|
894 | - } |
|
895 | - return $notices; |
|
896 | - } |
|
897 | - |
|
898 | - |
|
899 | - |
|
900 | - /** |
|
901 | - * _print_scripts |
|
902 | - * |
|
903 | - * @param bool $force_print |
|
904 | - * @return string |
|
905 | - */ |
|
906 | - private static function _print_scripts($force_print = false) |
|
907 | - { |
|
908 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
909 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
910 | - return ''; |
|
911 | - } |
|
912 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
913 | - wp_enqueue_style('espresso_default'); |
|
914 | - wp_enqueue_style('espresso_custom_css'); |
|
915 | - wp_enqueue_script('ee_error_js'); |
|
916 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
917 | - } |
|
918 | - } else { |
|
919 | - return ' |
|
478 | + $output .= self::_print_scripts(true); |
|
479 | + if (defined('DOING_AJAX')) { |
|
480 | + echo wp_json_encode(array('error' => $output)); |
|
481 | + exit(); |
|
482 | + } |
|
483 | + echo $output; |
|
484 | + die(); |
|
485 | + } |
|
486 | + |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * generate string from exception trace args |
|
491 | + * |
|
492 | + * @param array $arguments |
|
493 | + * @param bool $array |
|
494 | + * @return string |
|
495 | + */ |
|
496 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
497 | + { |
|
498 | + $arg_string = ''; |
|
499 | + if (! empty($arguments)) { |
|
500 | + $args = array(); |
|
501 | + foreach ($arguments as $arg) { |
|
502 | + if (! empty($arg)) { |
|
503 | + if (is_string($arg)) { |
|
504 | + $args[] = " '" . $arg . "'"; |
|
505 | + } elseif (is_array($arg)) { |
|
506 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
507 | + } elseif ($arg === null) { |
|
508 | + $args[] = ' NULL'; |
|
509 | + } elseif (is_bool($arg)) { |
|
510 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
511 | + } elseif (is_object($arg)) { |
|
512 | + $args[] = ' OBJECT ' . get_class($arg); |
|
513 | + } elseif (is_resource($arg)) { |
|
514 | + $args[] = get_resource_type($arg); |
|
515 | + } else { |
|
516 | + $args[] = $arg; |
|
517 | + } |
|
518 | + } |
|
519 | + } |
|
520 | + $arg_string = implode(', ', $args); |
|
521 | + } |
|
522 | + if ($array) { |
|
523 | + $arg_string .= ' )'; |
|
524 | + } |
|
525 | + return $arg_string; |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * add error message |
|
532 | + * |
|
533 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
534 | + * separate messages for user || dev |
|
535 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
536 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
537 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
538 | + * @return void |
|
539 | + */ |
|
540 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
541 | + { |
|
542 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
543 | + self::$_error_count++; |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
550 | + * adds an error |
|
551 | + * |
|
552 | + * @param string $msg |
|
553 | + * @param string $file |
|
554 | + * @param string $func |
|
555 | + * @param string $line |
|
556 | + * @throws EE_Error |
|
557 | + */ |
|
558 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
559 | + { |
|
560 | + if (WP_DEBUG) { |
|
561 | + throw new EE_Error($msg); |
|
562 | + } |
|
563 | + EE_Error::add_error($msg, $file, $func, $line); |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * add success message |
|
570 | + * |
|
571 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
572 | + * separate messages for user || dev |
|
573 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
574 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
575 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
576 | + * @return void |
|
577 | + */ |
|
578 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
579 | + { |
|
580 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * add attention message |
|
587 | + * |
|
588 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
589 | + * separate messages for user || dev |
|
590 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
591 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
592 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
593 | + * @return void |
|
594 | + */ |
|
595 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
596 | + { |
|
597 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
598 | + } |
|
599 | + |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * @param string $type whether the message is for a success or error notification |
|
604 | + * @param string $msg the message to display to users or developers |
|
605 | + * - adding a double pipe || (OR) creates separate messages for user || dev |
|
606 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
607 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
608 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
609 | + * @return void |
|
610 | + */ |
|
611 | + private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
612 | + { |
|
613 | + if (empty($msg)) { |
|
614 | + EE_Error::doing_it_wrong( |
|
615 | + 'EE_Error::add_' . $type . '()', |
|
616 | + sprintf( |
|
617 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
618 | + 'event_espresso'), |
|
619 | + $type, |
|
620 | + $file, |
|
621 | + $line |
|
622 | + ), |
|
623 | + EVENT_ESPRESSO_VERSION |
|
624 | + ); |
|
625 | + } |
|
626 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
627 | + EE_Error::doing_it_wrong( |
|
628 | + 'EE_Error::add_error()', |
|
629 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
630 | + 'event_espresso'), |
|
631 | + EVENT_ESPRESSO_VERSION |
|
632 | + ); |
|
633 | + } |
|
634 | + // get separate user and developer messages if they exist |
|
635 | + $msg = explode('||', $msg); |
|
636 | + $user_msg = $msg[0]; |
|
637 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
638 | + /** |
|
639 | + * Do an action so other code can be triggered when a notice is created |
|
640 | + * |
|
641 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
642 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
643 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
644 | + * @param string $file file where error was generated |
|
645 | + * @param string $func function where error was generated |
|
646 | + * @param string $line line where error was generated |
|
647 | + */ |
|
648 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
649 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
650 | + // add notice if message exists |
|
651 | + if (! empty($msg)) { |
|
652 | + // get error code |
|
653 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
654 | + if (WP_DEBUG && $type === 'errors') { |
|
655 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
656 | + } |
|
657 | + // add notice. Index by code if it's not blank |
|
658 | + if ($notice_code) { |
|
659 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
660 | + } else { |
|
661 | + self::$_espresso_notices[$type][] = $msg; |
|
662 | + } |
|
663 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
664 | + } |
|
665 | + } |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * in some case it may be necessary to overwrite the existing success messages |
|
670 | + * |
|
671 | + * @return void |
|
672 | + */ |
|
673 | + public static function overwrite_success() |
|
674 | + { |
|
675 | + self::$_espresso_notices['success'] = false; |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * in some case it may be necessary to overwrite the existing attention messages |
|
682 | + * |
|
683 | + * @return void |
|
684 | + */ |
|
685 | + public static function overwrite_attention() |
|
686 | + { |
|
687 | + self::$_espresso_notices['attention'] = false; |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + |
|
692 | + /** |
|
693 | + * in some case it may be necessary to overwrite the existing error messages |
|
694 | + * |
|
695 | + * @return void |
|
696 | + */ |
|
697 | + public static function overwrite_errors() |
|
698 | + { |
|
699 | + self::$_espresso_notices['errors'] = false; |
|
700 | + } |
|
701 | + |
|
702 | + |
|
703 | + |
|
704 | + /** |
|
705 | + * @return void |
|
706 | + */ |
|
707 | + public static function reset_notices() |
|
708 | + { |
|
709 | + self::$_espresso_notices['success'] = false; |
|
710 | + self::$_espresso_notices['attention'] = false; |
|
711 | + self::$_espresso_notices['errors'] = false; |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * @return int |
|
718 | + */ |
|
719 | + public static function has_notices() |
|
720 | + { |
|
721 | + $has_notices = 0; |
|
722 | + // check for success messages |
|
723 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
724 | + ? 3 |
|
725 | + : $has_notices; |
|
726 | + // check for attention messages |
|
727 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
728 | + ? 2 |
|
729 | + : $has_notices; |
|
730 | + // check for error messages |
|
731 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
732 | + ? 1 |
|
733 | + : $has_notices; |
|
734 | + return $has_notices; |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
740 | + * |
|
741 | + * @since 4.9.0 |
|
742 | + * @return array |
|
743 | + */ |
|
744 | + public static function get_vanilla_notices() |
|
745 | + { |
|
746 | + return array( |
|
747 | + 'success' => isset(self::$_espresso_notices['success']) |
|
748 | + ? self::$_espresso_notices['success'] |
|
749 | + : array(), |
|
750 | + 'attention' => isset(self::$_espresso_notices['attention']) |
|
751 | + ? self::$_espresso_notices['attention'] |
|
752 | + : array(), |
|
753 | + 'errors' => isset(self::$_espresso_notices['errors']) |
|
754 | + ? self::$_espresso_notices['errors'] |
|
755 | + : array(), |
|
756 | + ); |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + |
|
761 | + /** |
|
762 | + * compile all error or success messages into one string |
|
763 | + * |
|
764 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
765 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
766 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
767 | + * - ONLY do this just before redirecting |
|
768 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
769 | + * @return array |
|
770 | + */ |
|
771 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
772 | + { |
|
773 | + // do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
774 | + $success_messages = ''; |
|
775 | + $attention_messages = ''; |
|
776 | + $error_messages = ''; |
|
777 | + $print_scripts = false; |
|
778 | + // EEH_Debug_Tools::printr( self::$_espresso_notices, 'espresso_notices <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
779 | + // either save notices to the db |
|
780 | + if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
781 | + $existing_notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | + $existing_notices = is_array($existing_notices) ? $existing_notices : array(); |
|
783 | + self::$_espresso_notices = array_merge( |
|
784 | + $existing_notices, |
|
785 | + self::$_espresso_notices |
|
786 | + ); |
|
787 | + update_option(EE_Error::OPTIONS_KEY_NOTICES, self::$_espresso_notices); |
|
788 | + return array(); |
|
789 | + } |
|
790 | + // grab any notices that have been previously saved |
|
791 | + if ($notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array())) { |
|
792 | + foreach ($notices as $type => $notice) { |
|
793 | + if (is_array($notice) && ! empty($notice)) { |
|
794 | + // make sure that existing notice type is an array |
|
795 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
796 | + && ! empty(self::$_espresso_notices[$type]) |
|
797 | + ? self::$_espresso_notices[$type] |
|
798 | + : array(); |
|
799 | + // merge stored notices with any newly created ones |
|
800 | + self::$_espresso_notices[$type] = array_merge(self::$_espresso_notices[$type], $notice); |
|
801 | + $print_scripts = true; |
|
802 | + } |
|
803 | + } |
|
804 | + // now clear any stored notices |
|
805 | + update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
806 | + } |
|
807 | + // check for success messages |
|
808 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
809 | + // combine messages |
|
810 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
811 | + $print_scripts = true; |
|
812 | + } |
|
813 | + // check for attention messages |
|
814 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
815 | + // combine messages |
|
816 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
817 | + $print_scripts = true; |
|
818 | + } |
|
819 | + // check for error messages |
|
820 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
821 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
822 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
823 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
824 | + // combine messages |
|
825 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
826 | + $print_scripts = true; |
|
827 | + } |
|
828 | + if ($format_output) { |
|
829 | + |
|
830 | + $notices = '<div id="espresso-notices">'; |
|
831 | + $close = is_admin() ? '' |
|
832 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"></span></a>'; |
|
833 | + if ($success_messages !== '') { |
|
834 | + $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
|
835 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
836 | + //showMessage( $success_messages ); |
|
837 | + $notices .= '<div id="' |
|
838 | + . $css_id |
|
839 | + . '" class="espresso-notices ' |
|
840 | + . $css_class |
|
841 | + . '" style="display:none;"><p>' |
|
842 | + . $success_messages |
|
843 | + . '</p>' |
|
844 | + . $close |
|
845 | + . '</div>'; |
|
846 | + } |
|
847 | + if ($attention_messages !== '') { |
|
848 | + $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
|
849 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
850 | + //showMessage( $error_messages, TRUE ); |
|
851 | + $notices .= '<div id="' |
|
852 | + . $css_id |
|
853 | + . '" class="espresso-notices ' |
|
854 | + . $css_class |
|
855 | + . '" style="display:none;"><p>' |
|
856 | + . $attention_messages |
|
857 | + . '</p>' |
|
858 | + . $close |
|
859 | + . '</div>'; |
|
860 | + } |
|
861 | + if ($error_messages !== '') { |
|
862 | + $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
|
863 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
864 | + //showMessage( $error_messages, TRUE ); |
|
865 | + $notices .= '<div id="' |
|
866 | + . $css_id |
|
867 | + . '" class="espresso-notices ' |
|
868 | + . $css_class |
|
869 | + . '" style="display:none;"><p>' |
|
870 | + . $error_messages |
|
871 | + . '</p>' |
|
872 | + . $close |
|
873 | + . '</div>'; |
|
874 | + } |
|
875 | + $notices .= '</div>'; |
|
876 | + } else { |
|
877 | + |
|
878 | + $notices = array( |
|
879 | + 'success' => $success_messages, |
|
880 | + 'attention' => $attention_messages, |
|
881 | + 'errors' => $error_messages, |
|
882 | + ); |
|
883 | + if ($remove_empty) { |
|
884 | + // remove empty notices |
|
885 | + foreach ($notices as $type => $notice) { |
|
886 | + if (empty($notice)) { |
|
887 | + unset($notices[$type]); |
|
888 | + } |
|
889 | + } |
|
890 | + } |
|
891 | + } |
|
892 | + if ($print_scripts) { |
|
893 | + self::_print_scripts(); |
|
894 | + } |
|
895 | + return $notices; |
|
896 | + } |
|
897 | + |
|
898 | + |
|
899 | + |
|
900 | + /** |
|
901 | + * _print_scripts |
|
902 | + * |
|
903 | + * @param bool $force_print |
|
904 | + * @return string |
|
905 | + */ |
|
906 | + private static function _print_scripts($force_print = false) |
|
907 | + { |
|
908 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
909 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
910 | + return ''; |
|
911 | + } |
|
912 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
913 | + wp_enqueue_style('espresso_default'); |
|
914 | + wp_enqueue_style('espresso_custom_css'); |
|
915 | + wp_enqueue_script('ee_error_js'); |
|
916 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
917 | + } |
|
918 | + } else { |
|
919 | + return ' |
|
920 | 920 | <script> |
921 | 921 | /* <![CDATA[ */ |
922 | 922 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -926,223 +926,223 @@ discard block |
||
926 | 926 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
927 | 927 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
928 | 928 | '; |
929 | - } |
|
930 | - return ''; |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - |
|
935 | - /** |
|
936 | - * @return void |
|
937 | - */ |
|
938 | - public static function enqueue_error_scripts() |
|
939 | - { |
|
940 | - self::_print_scripts(); |
|
941 | - } |
|
942 | - |
|
943 | - |
|
944 | - |
|
945 | - /** |
|
946 | - * create error code from filepath, function name, |
|
947 | - * and line number where exception or error was thrown |
|
948 | - * |
|
949 | - * @param string $file |
|
950 | - * @param string $func |
|
951 | - * @param string $line |
|
952 | - * @return string |
|
953 | - */ |
|
954 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
955 | - { |
|
956 | - $file = explode('.', basename($file)); |
|
957 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
958 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
959 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
960 | - return $error_code; |
|
961 | - } |
|
962 | - |
|
963 | - |
|
964 | - |
|
965 | - /** |
|
966 | - * write exception details to log file |
|
967 | - * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
968 | - * |
|
969 | - * @param int $time |
|
970 | - * @param array $ex |
|
971 | - * @param bool $clear |
|
972 | - * @return void |
|
973 | - */ |
|
974 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
975 | - { |
|
976 | - if (empty($ex)) { |
|
977 | - return; |
|
978 | - } |
|
979 | - if (! $time) { |
|
980 | - $time = time(); |
|
981 | - } |
|
982 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
983 | - . PHP_EOL; |
|
984 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
985 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
986 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
987 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
988 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
989 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
990 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
991 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
992 | - . PHP_EOL; |
|
993 | - try { |
|
994 | - error_log($exception_log); |
|
995 | - } catch (EE_Error $e) { |
|
996 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
997 | - 'event_espresso'), $e->getMessage())); |
|
998 | - } |
|
999 | - } |
|
1000 | - |
|
1001 | - |
|
1002 | - |
|
1003 | - /** |
|
1004 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1005 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1006 | - * but the code execution is done in a manner that could lead to unexpected results |
|
1007 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
1008 | - * A good test for knowing whether to use this method is: |
|
1009 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1010 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1011 | - * 2. If this is loaded before something else, it won't break anything, |
|
1012 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1013 | - * |
|
1014 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1015 | - * @param string $function The function that was called |
|
1016 | - * @param string $message A message explaining what has been done incorrectly |
|
1017 | - * @param string $version The version of Event Espresso where the error was added |
|
1018 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1019 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
1020 | - * but not have any notices appear until a later version. This allows developers |
|
1021 | - * extra time to update their code before notices appear. |
|
1022 | - * @param int $error_type |
|
1023 | - */ |
|
1024 | - public static function doing_it_wrong( |
|
1025 | - $function, |
|
1026 | - $message, |
|
1027 | - $version, |
|
1028 | - $applies_when = '', |
|
1029 | - $error_type = null |
|
1030 | - ) { |
|
1031 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1032 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1033 | - } |
|
1034 | - } |
|
1035 | - |
|
1036 | - |
|
1037 | - |
|
1038 | - /** |
|
1039 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
1040 | - * |
|
1041 | - * @return array { |
|
1042 | - * @type array $success all the success messages |
|
1043 | - * @type array $errors all the error messages |
|
1044 | - * @type array $attention all the attention messages |
|
1045 | - * } |
|
1046 | - */ |
|
1047 | - public static function get_raw_notices() |
|
1048 | - { |
|
1049 | - return self::$_espresso_notices; |
|
1050 | - } |
|
1051 | - |
|
1052 | - |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * @deprecated 4.9.27 |
|
1056 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1057 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1058 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1059 | - * @return void |
|
1060 | - * @throws InvalidDataTypeException |
|
1061 | - */ |
|
1062 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1063 | - { |
|
1064 | - new PersistentAdminNotice( |
|
1065 | - $pan_name, |
|
1066 | - $pan_message, |
|
1067 | - $force_update |
|
1068 | - ); |
|
1069 | - EE_Error::doing_it_wrong( |
|
1070 | - __METHOD__, |
|
1071 | - sprintf( |
|
1072 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1073 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1074 | - ), |
|
1075 | - '4.9.27' |
|
1076 | - ); |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * @deprecated 4.9.27 |
|
1083 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1084 | - * @param bool $purge |
|
1085 | - * @param bool $return |
|
1086 | - * @throws DomainException |
|
1087 | - * @throws InvalidInterfaceException |
|
1088 | - * @throws InvalidDataTypeException |
|
1089 | - * @throws ServiceNotFoundException |
|
1090 | - * @throws InvalidArgumentException |
|
1091 | - */ |
|
1092 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1093 | - { |
|
1094 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1095 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1096 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1097 | - ); |
|
1098 | - $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1099 | - EE_Error::doing_it_wrong( |
|
1100 | - __METHOD__, |
|
1101 | - sprintf( |
|
1102 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1103 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1104 | - ), |
|
1105 | - '4.9.27' |
|
1106 | - ); |
|
1107 | - } |
|
1108 | - |
|
1109 | - |
|
1110 | - |
|
1111 | - /** |
|
1112 | - * @deprecated 4.9.27 |
|
1113 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1114 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1115 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
1116 | - */ |
|
1117 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1118 | - { |
|
1119 | - EE_Error::doing_it_wrong( |
|
1120 | - __METHOD__, |
|
1121 | - sprintf( |
|
1122 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1123 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1124 | - ), |
|
1125 | - '4.9.27' |
|
1126 | - ); |
|
1127 | - } |
|
1128 | - |
|
1129 | - |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * @deprecated 4.9.27 |
|
1133 | - * @param string $return_url |
|
1134 | - */ |
|
1135 | - public static function get_persistent_admin_notices($return_url = '') |
|
1136 | - { |
|
1137 | - EE_Error::doing_it_wrong( |
|
1138 | - __METHOD__, |
|
1139 | - sprintf( |
|
1140 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1141 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1142 | - ), |
|
1143 | - '4.9.27' |
|
1144 | - ); |
|
1145 | - } |
|
929 | + } |
|
930 | + return ''; |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + |
|
935 | + /** |
|
936 | + * @return void |
|
937 | + */ |
|
938 | + public static function enqueue_error_scripts() |
|
939 | + { |
|
940 | + self::_print_scripts(); |
|
941 | + } |
|
942 | + |
|
943 | + |
|
944 | + |
|
945 | + /** |
|
946 | + * create error code from filepath, function name, |
|
947 | + * and line number where exception or error was thrown |
|
948 | + * |
|
949 | + * @param string $file |
|
950 | + * @param string $func |
|
951 | + * @param string $line |
|
952 | + * @return string |
|
953 | + */ |
|
954 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
955 | + { |
|
956 | + $file = explode('.', basename($file)); |
|
957 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
958 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
959 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
960 | + return $error_code; |
|
961 | + } |
|
962 | + |
|
963 | + |
|
964 | + |
|
965 | + /** |
|
966 | + * write exception details to log file |
|
967 | + * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
968 | + * |
|
969 | + * @param int $time |
|
970 | + * @param array $ex |
|
971 | + * @param bool $clear |
|
972 | + * @return void |
|
973 | + */ |
|
974 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
975 | + { |
|
976 | + if (empty($ex)) { |
|
977 | + return; |
|
978 | + } |
|
979 | + if (! $time) { |
|
980 | + $time = time(); |
|
981 | + } |
|
982 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
983 | + . PHP_EOL; |
|
984 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
985 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
986 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
987 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
988 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
989 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
990 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
991 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
992 | + . PHP_EOL; |
|
993 | + try { |
|
994 | + error_log($exception_log); |
|
995 | + } catch (EE_Error $e) { |
|
996 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
997 | + 'event_espresso'), $e->getMessage())); |
|
998 | + } |
|
999 | + } |
|
1000 | + |
|
1001 | + |
|
1002 | + |
|
1003 | + /** |
|
1004 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1005 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1006 | + * but the code execution is done in a manner that could lead to unexpected results |
|
1007 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
1008 | + * A good test for knowing whether to use this method is: |
|
1009 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1010 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1011 | + * 2. If this is loaded before something else, it won't break anything, |
|
1012 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1013 | + * |
|
1014 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1015 | + * @param string $function The function that was called |
|
1016 | + * @param string $message A message explaining what has been done incorrectly |
|
1017 | + * @param string $version The version of Event Espresso where the error was added |
|
1018 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1019 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
1020 | + * but not have any notices appear until a later version. This allows developers |
|
1021 | + * extra time to update their code before notices appear. |
|
1022 | + * @param int $error_type |
|
1023 | + */ |
|
1024 | + public static function doing_it_wrong( |
|
1025 | + $function, |
|
1026 | + $message, |
|
1027 | + $version, |
|
1028 | + $applies_when = '', |
|
1029 | + $error_type = null |
|
1030 | + ) { |
|
1031 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1032 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1033 | + } |
|
1034 | + } |
|
1035 | + |
|
1036 | + |
|
1037 | + |
|
1038 | + /** |
|
1039 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
1040 | + * |
|
1041 | + * @return array { |
|
1042 | + * @type array $success all the success messages |
|
1043 | + * @type array $errors all the error messages |
|
1044 | + * @type array $attention all the attention messages |
|
1045 | + * } |
|
1046 | + */ |
|
1047 | + public static function get_raw_notices() |
|
1048 | + { |
|
1049 | + return self::$_espresso_notices; |
|
1050 | + } |
|
1051 | + |
|
1052 | + |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * @deprecated 4.9.27 |
|
1056 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1057 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1058 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1059 | + * @return void |
|
1060 | + * @throws InvalidDataTypeException |
|
1061 | + */ |
|
1062 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1063 | + { |
|
1064 | + new PersistentAdminNotice( |
|
1065 | + $pan_name, |
|
1066 | + $pan_message, |
|
1067 | + $force_update |
|
1068 | + ); |
|
1069 | + EE_Error::doing_it_wrong( |
|
1070 | + __METHOD__, |
|
1071 | + sprintf( |
|
1072 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1073 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1074 | + ), |
|
1075 | + '4.9.27' |
|
1076 | + ); |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * @deprecated 4.9.27 |
|
1083 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1084 | + * @param bool $purge |
|
1085 | + * @param bool $return |
|
1086 | + * @throws DomainException |
|
1087 | + * @throws InvalidInterfaceException |
|
1088 | + * @throws InvalidDataTypeException |
|
1089 | + * @throws ServiceNotFoundException |
|
1090 | + * @throws InvalidArgumentException |
|
1091 | + */ |
|
1092 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1093 | + { |
|
1094 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1095 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1096 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1097 | + ); |
|
1098 | + $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1099 | + EE_Error::doing_it_wrong( |
|
1100 | + __METHOD__, |
|
1101 | + sprintf( |
|
1102 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1103 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1104 | + ), |
|
1105 | + '4.9.27' |
|
1106 | + ); |
|
1107 | + } |
|
1108 | + |
|
1109 | + |
|
1110 | + |
|
1111 | + /** |
|
1112 | + * @deprecated 4.9.27 |
|
1113 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1114 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1115 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
1116 | + */ |
|
1117 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1118 | + { |
|
1119 | + EE_Error::doing_it_wrong( |
|
1120 | + __METHOD__, |
|
1121 | + sprintf( |
|
1122 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1123 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1124 | + ), |
|
1125 | + '4.9.27' |
|
1126 | + ); |
|
1127 | + } |
|
1128 | + |
|
1129 | + |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * @deprecated 4.9.27 |
|
1133 | + * @param string $return_url |
|
1134 | + */ |
|
1135 | + public static function get_persistent_admin_notices($return_url = '') |
|
1136 | + { |
|
1137 | + EE_Error::doing_it_wrong( |
|
1138 | + __METHOD__, |
|
1139 | + sprintf( |
|
1140 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1141 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1142 | + ), |
|
1143 | + '4.9.27' |
|
1144 | + ); |
|
1145 | + } |
|
1146 | 1146 | |
1147 | 1147 | |
1148 | 1148 | |
@@ -1157,27 +1157,27 @@ discard block |
||
1157 | 1157 | */ |
1158 | 1158 | function espresso_error_enqueue_scripts() |
1159 | 1159 | { |
1160 | - // js for error handling |
|
1161 | - wp_register_script( |
|
1162 | - 'espresso_core', |
|
1163 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1164 | - array('jquery'), |
|
1165 | - EVENT_ESPRESSO_VERSION, |
|
1166 | - false |
|
1167 | - ); |
|
1168 | - wp_register_script( |
|
1169 | - 'ee_error_js', |
|
1170 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1171 | - array('espresso_core'), |
|
1172 | - EVENT_ESPRESSO_VERSION, |
|
1173 | - false |
|
1174 | - ); |
|
1160 | + // js for error handling |
|
1161 | + wp_register_script( |
|
1162 | + 'espresso_core', |
|
1163 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1164 | + array('jquery'), |
|
1165 | + EVENT_ESPRESSO_VERSION, |
|
1166 | + false |
|
1167 | + ); |
|
1168 | + wp_register_script( |
|
1169 | + 'ee_error_js', |
|
1170 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1171 | + array('espresso_core'), |
|
1172 | + EVENT_ESPRESSO_VERSION, |
|
1173 | + false |
|
1174 | + ); |
|
1175 | 1175 | } |
1176 | 1176 | |
1177 | 1177 | if (is_admin()) { |
1178 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1178 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1179 | 1179 | } else { |
1180 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1180 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 |
@@ -9,22 +9,22 @@ discard block |
||
9 | 9 | */ |
10 | 10 | function espresso_load_error_handling() |
11 | 11 | { |
12 | - static $error_handling_loaded = false; |
|
13 | - if ($error_handling_loaded) { |
|
14 | - return; |
|
15 | - } |
|
16 | - // load debugging tools |
|
17 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
18 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
19 | - \EEH_Debug_Tools::instance(); |
|
20 | - } |
|
21 | - // load error handling |
|
22 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
23 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
24 | - } else { |
|
25 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
26 | - } |
|
27 | - $error_handling_loaded = true; |
|
12 | + static $error_handling_loaded = false; |
|
13 | + if ($error_handling_loaded) { |
|
14 | + return; |
|
15 | + } |
|
16 | + // load debugging tools |
|
17 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
18 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
19 | + \EEH_Debug_Tools::instance(); |
|
20 | + } |
|
21 | + // load error handling |
|
22 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
23 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
24 | + } else { |
|
25 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
26 | + } |
|
27 | + $error_handling_loaded = true; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | |
@@ -38,19 +38,19 @@ discard block |
||
38 | 38 | */ |
39 | 39 | function espresso_load_required($classname, $full_path_to_file) |
40 | 40 | { |
41 | - if (is_readable($full_path_to_file)) { |
|
42 | - require_once $full_path_to_file; |
|
43 | - } else { |
|
44 | - throw new \EE_Error ( |
|
45 | - sprintf( |
|
46 | - esc_html__( |
|
47 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
48 | - 'event_espresso' |
|
49 | - ), |
|
50 | - $classname |
|
51 | - ) |
|
52 | - ); |
|
53 | - } |
|
41 | + if (is_readable($full_path_to_file)) { |
|
42 | + require_once $full_path_to_file; |
|
43 | + } else { |
|
44 | + throw new \EE_Error ( |
|
45 | + sprintf( |
|
46 | + esc_html__( |
|
47 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
48 | + 'event_espresso' |
|
49 | + ), |
|
50 | + $classname |
|
51 | + ) |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | |
@@ -69,41 +69,41 @@ discard block |
||
69 | 69 | */ |
70 | 70 | function bootstrap_espresso() |
71 | 71 | { |
72 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
73 | - try { |
|
74 | - espresso_load_error_handling(); |
|
75 | - espresso_load_required( |
|
76 | - 'EEH_Base', |
|
77 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
78 | - ); |
|
79 | - espresso_load_required( |
|
80 | - 'EEH_File', |
|
81 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
82 | - ); |
|
83 | - espresso_load_required( |
|
84 | - 'EEH_File', |
|
85 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
86 | - ); |
|
87 | - espresso_load_required( |
|
88 | - 'EEH_Array', |
|
89 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
90 | - ); |
|
91 | - // instantiate and configure PSR4 autoloader |
|
92 | - espresso_load_required( |
|
93 | - 'Psr4Autoloader', |
|
94 | - EE_CORE . 'Psr4Autoloader.php' |
|
95 | - ); |
|
96 | - espresso_load_required( |
|
97 | - 'EE_Psr4AutoloaderInit', |
|
98 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
99 | - ); |
|
100 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
101 | - $AutoloaderInit->initializeAutoloader(); |
|
102 | - new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
103 | - } catch (Exception $e) { |
|
104 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
105 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
106 | - } |
|
72 | + require_once __DIR__ . '/espresso_definitions.php'; |
|
73 | + try { |
|
74 | + espresso_load_error_handling(); |
|
75 | + espresso_load_required( |
|
76 | + 'EEH_Base', |
|
77 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
78 | + ); |
|
79 | + espresso_load_required( |
|
80 | + 'EEH_File', |
|
81 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
82 | + ); |
|
83 | + espresso_load_required( |
|
84 | + 'EEH_File', |
|
85 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
86 | + ); |
|
87 | + espresso_load_required( |
|
88 | + 'EEH_Array', |
|
89 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
90 | + ); |
|
91 | + // instantiate and configure PSR4 autoloader |
|
92 | + espresso_load_required( |
|
93 | + 'Psr4Autoloader', |
|
94 | + EE_CORE . 'Psr4Autoloader.php' |
|
95 | + ); |
|
96 | + espresso_load_required( |
|
97 | + 'EE_Psr4AutoloaderInit', |
|
98 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
99 | + ); |
|
100 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
101 | + $AutoloaderInit->initializeAutoloader(); |
|
102 | + new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
103 | + } catch (Exception $e) { |
|
104 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
105 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
106 | + } |
|
107 | 107 | } |
108 | 108 | |
109 | 109 |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | return; |
15 | 15 | } |
16 | 16 | // load debugging tools |
17 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
18 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
17 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
18 | + require_once EE_HELPERS.'EEH_Debug_Tools.helper.php'; |
|
19 | 19 | \EEH_Debug_Tools::instance(); |
20 | 20 | } |
21 | 21 | // load error handling |
22 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
23 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
22 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
23 | + require_once EE_CORE.'EE_Error.core.php'; |
|
24 | 24 | } else { |
25 | 25 | wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
26 | 26 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | if (is_readable($full_path_to_file)) { |
42 | 42 | require_once $full_path_to_file; |
43 | 43 | } else { |
44 | - throw new \EE_Error ( |
|
44 | + throw new \EE_Error( |
|
45 | 45 | sprintf( |
46 | 46 | esc_html__( |
47 | 47 | 'The %s class file could not be located or is not readable due to file permissions.', |
@@ -69,39 +69,39 @@ discard block |
||
69 | 69 | */ |
70 | 70 | function bootstrap_espresso() |
71 | 71 | { |
72 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
72 | + require_once __DIR__.'/espresso_definitions.php'; |
|
73 | 73 | try { |
74 | 74 | espresso_load_error_handling(); |
75 | 75 | espresso_load_required( |
76 | 76 | 'EEH_Base', |
77 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
77 | + EE_CORE.'helpers'.DS.'EEH_Base.helper.php' |
|
78 | 78 | ); |
79 | 79 | espresso_load_required( |
80 | 80 | 'EEH_File', |
81 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
81 | + EE_CORE.'interfaces'.DS.'EEHI_File.interface.php' |
|
82 | 82 | ); |
83 | 83 | espresso_load_required( |
84 | 84 | 'EEH_File', |
85 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
85 | + EE_CORE.'helpers'.DS.'EEH_File.helper.php' |
|
86 | 86 | ); |
87 | 87 | espresso_load_required( |
88 | 88 | 'EEH_Array', |
89 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
89 | + EE_CORE.'helpers'.DS.'EEH_Array.helper.php' |
|
90 | 90 | ); |
91 | 91 | // instantiate and configure PSR4 autoloader |
92 | 92 | espresso_load_required( |
93 | 93 | 'Psr4Autoloader', |
94 | - EE_CORE . 'Psr4Autoloader.php' |
|
94 | + EE_CORE.'Psr4Autoloader.php' |
|
95 | 95 | ); |
96 | 96 | espresso_load_required( |
97 | 97 | 'EE_Psr4AutoloaderInit', |
98 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
98 | + EE_CORE.'EE_Psr4AutoloaderInit.core.php' |
|
99 | 99 | ); |
100 | 100 | $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
101 | 101 | $AutoloaderInit->initializeAutoloader(); |
102 | 102 | new EventEspresso\core\services\bootstrap\BootstrapCore(); |
103 | 103 | } catch (Exception $e) { |
104 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
104 | + require_once EE_CORE.'exceptions'.DS.'ExceptionStackTraceDisplay.php'; |
|
105 | 105 | new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
106 | 106 | } |
107 | 107 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | + if ( ! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | 42 | /** |
43 | 43 | * espresso_duplicate_plugin_error |
44 | 44 | * displays if more than one version of EE is activated at the same time |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | } else { |
65 | 65 | define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | 67 | /** |
68 | 68 | * espresso_minimum_php_version_error |
69 | 69 | * @return void |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | |
117 | 117 | register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
119 | + require_once __DIR__.'/core/bootstrap_espresso.php'; |
|
120 | 120 | bootstrap_espresso(); |
121 | 121 | } |
122 | 122 | } |
123 | -if (! function_exists('espresso_deactivate_plugin')) { |
|
123 | +if ( ! function_exists('espresso_deactivate_plugin')) { |
|
124 | 124 | /** |
125 | 125 | * deactivate_plugin |
126 | 126 | * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | */ |
132 | 132 | function espresso_deactivate_plugin($plugin_basename = '') |
133 | 133 | { |
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
134 | + if ( ! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
136 | 136 | } |
137 | 137 | unset($_GET['activate'], $_REQUEST['activate']); |
138 | 138 | deactivate_plugins($plugin_basename); |
@@ -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 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
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.59.rc.032'); |
|
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.59.rc.032'); |
|
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 | } |
@@ -45,8 +45,8 @@ |
||
45 | 45 | } |
46 | 46 | } |
47 | 47 | } |
48 | - return true; |
|
49 | - } |
|
48 | + return true; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | 52 |
@@ -22,744 +22,744 @@ |
||
22 | 22 | |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @return EED_Module|EED_Add_New_State |
|
27 | - */ |
|
28 | - public static function instance() |
|
29 | - { |
|
30 | - return parent::get_instance(__CLASS__); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
37 | - * |
|
38 | - * @return void |
|
39 | - */ |
|
40 | - public static function set_hooks() |
|
41 | - { |
|
42 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
43 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
44 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
45 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
46 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
47 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
48 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
49 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
50 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
51 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
52 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
53 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
54 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
55 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
56 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
57 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
58 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
65 | - * |
|
66 | - * @return void |
|
67 | - */ |
|
68 | - public static function set_hooks_admin() |
|
69 | - { |
|
70 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
71 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
72 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
73 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
74 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
75 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
76 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
77 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
78 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
79 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
80 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
81 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
82 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
83 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
84 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
85 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
86 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
87 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
88 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
89 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
90 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
91 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
92 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public static function set_definitions() |
|
101 | - { |
|
102 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
103 | - define('ANS_TEMPLATES_PATH', str_replace( |
|
104 | - '\\', |
|
105 | - DS, |
|
106 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
107 | - ); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @param WP $WP |
|
114 | - * @return void |
|
115 | - */ |
|
116 | - public function run($WP) |
|
117 | - { |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public static function translate_js_strings() |
|
126 | - { |
|
127 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
128 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
129 | - 'event_espresso' |
|
130 | - ); |
|
131 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
132 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
133 | - 'event_espresso' |
|
134 | - ); |
|
135 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
136 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
137 | - 'event_espresso' |
|
138 | - ); |
|
139 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
140 | - 'The new state was successfully saved to the database.', |
|
141 | - 'event_espresso' |
|
142 | - ); |
|
143 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
144 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
145 | - 'event_espresso' |
|
146 | - ); |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return void |
|
153 | - */ |
|
154 | - public static function wp_enqueue_scripts() |
|
155 | - { |
|
156 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
157 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
158 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
159 | - wp_enqueue_script('add_new_state'); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * display_add_new_state_micro_form |
|
167 | - * |
|
168 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
169 | - * @return string |
|
170 | - * @throws EE_Error |
|
171 | - * @throws InvalidArgumentException |
|
172 | - * @throws InvalidDataTypeException |
|
173 | - * @throws InvalidInterfaceException |
|
174 | - */ |
|
175 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
176 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
177 | - { |
|
178 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
179 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
180 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
181 | - // is the "state" question in this form section? |
|
182 | - $input = $question_group_reg_form->get_subsection('state'); |
|
183 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
184 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
185 | - //by forcing it to set it now, like it did while getting the form for display |
|
186 | - if ($input instanceof EE_State_Select_Input) { |
|
187 | - $input->html_name(); |
|
188 | - } |
|
189 | - return $question_group_reg_form; |
|
190 | - } |
|
191 | - // we're only doing this for state select inputs |
|
192 | - if ($input instanceof EE_State_Select_Input && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
193 | - // grab any set values from the request |
|
194 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
195 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
196 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
197 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
198 | - $country_options = array(); |
|
199 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
200 | - if (! empty($countries)) { |
|
201 | - foreach ($countries as $country) { |
|
202 | - if ($country instanceof EE_Country) { |
|
203 | - $country_options[$country->ID()] = $country->name(); |
|
204 | - } |
|
205 | - } |
|
206 | - } |
|
207 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
208 | - array( |
|
209 | - 'name' => 'new_state_micro_form', |
|
210 | - 'html_id' => 'new_state_micro_form', |
|
211 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
212 | - 'subsections' => array( |
|
213 | - // add hidden input to indicate that a new state is being added |
|
214 | - 'add_new_state' => new EE_Hidden_Input( |
|
215 | - array( |
|
216 | - 'html_name' => str_replace( |
|
217 | - 'state', |
|
218 | - 'nsmf_add_new_state', |
|
219 | - $input->html_name() |
|
220 | - ), |
|
221 | - 'html_id' => str_replace( |
|
222 | - 'state', |
|
223 | - 'nsmf_add_new_state', |
|
224 | - $input->html_id() |
|
225 | - ), |
|
226 | - 'default' => 0, |
|
227 | - ) |
|
228 | - ), |
|
229 | - // add link for displaying hidden container |
|
230 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
231 | - apply_filters( |
|
232 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
233 | - EEH_HTML::link( |
|
234 | - '', |
|
235 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
236 | - '', |
|
237 | - 'display-' . $input->html_id(), |
|
238 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
239 | - '', |
|
240 | - 'data-target="' . $input->html_id() . '"' |
|
241 | - ) |
|
242 | - ) |
|
243 | - ), |
|
244 | - // add initial html for hidden container |
|
245 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
246 | - apply_filters( |
|
247 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
248 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
249 | - 'display: none;') . |
|
250 | - EEH_HTML::h6( |
|
251 | - esc_html__( |
|
252 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
253 | - 'event_espresso' |
|
254 | - ) |
|
255 | - ) . |
|
256 | - EEH_HTML::ul() . |
|
257 | - EEH_HTML::li( |
|
258 | - esc_html__( |
|
259 | - 'first select the Country that your State/Province belongs to', |
|
260 | - 'event_espresso' |
|
261 | - ) |
|
262 | - ) . |
|
263 | - EEH_HTML::li( |
|
264 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
265 | - ) . |
|
266 | - EEH_HTML::li( |
|
267 | - esc_html__( |
|
268 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
269 | - 'event_espresso' |
|
270 | - ) |
|
271 | - ) . |
|
272 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
273 | - EEH_HTML::ulx() |
|
274 | - ) |
|
275 | - ), |
|
276 | - // NEW STATE COUNTRY |
|
277 | - 'new_state_country' => new EE_Country_Select_Input( |
|
278 | - $country_options, |
|
279 | - array( |
|
280 | - 'html_name' => $country_name, |
|
281 | - 'html_id' => str_replace( |
|
282 | - 'state', |
|
283 | - 'nsmf_new_state_country', $input->html_id() |
|
284 | - ), |
|
285 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
286 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
287 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
288 | - 'required' => false, |
|
289 | - ) |
|
290 | - ), |
|
291 | - // NEW STATE NAME |
|
292 | - 'new_state_name' => new EE_Text_Input( |
|
293 | - array( |
|
294 | - 'html_name' => $state_name, |
|
295 | - 'html_id' => str_replace( |
|
296 | - 'state', |
|
297 | - 'nsmf_new_state_name', $input->html_id() |
|
298 | - ), |
|
299 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
300 | - 'html_label_text' => esc_html__('New State/Province Name', |
|
301 | - 'event_espresso'), |
|
302 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
303 | - 'required' => false, |
|
304 | - ) |
|
305 | - ), |
|
306 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
307 | - // NEW STATE NAME |
|
308 | - 'new_state_abbrv' => new EE_Text_Input( |
|
309 | - array( |
|
310 | - 'html_name' => $abbrv_name, |
|
311 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
312 | - $input->html_id()), |
|
313 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
314 | - 'html_label_text' => esc_html__( |
|
315 | - 'New State/Province Abbreviation', |
|
316 | - 'event_espresso' |
|
317 | - ) . ' *', |
|
318 | - 'html_other_attributes' => 'size="24"', |
|
319 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
320 | - 'required' => false, |
|
321 | - ) |
|
322 | - ), |
|
323 | - // "submit" button |
|
324 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
325 | - apply_filters( |
|
326 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
327 | - EEH_HTML::nbsp(3) . |
|
328 | - EEH_HTML::link( |
|
329 | - '', |
|
330 | - esc_html__('ADD', 'event_espresso'), |
|
331 | - '', |
|
332 | - 'submit-' . $new_state_submit_id, |
|
333 | - 'ee-form-add-new-state-submit button button-secondary', |
|
334 | - '', |
|
335 | - 'data-target="' . $new_state_submit_id . '"' |
|
336 | - ) |
|
337 | - ) |
|
338 | - ), |
|
339 | - // extra info |
|
340 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
341 | - apply_filters( |
|
342 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
343 | - EEH_HTML::br(2) |
|
344 | - . |
|
345 | - EEH_HTML::div('', '', 'small-text') |
|
346 | - . |
|
347 | - EEH_HTML::strong( |
|
348 | - '* ' . |
|
349 | - esc_html__( |
|
350 | - 'Don\'t know your State/Province Abbreviation?', |
|
351 | - 'event_espresso' |
|
352 | - ) |
|
353 | - ) |
|
354 | - . |
|
355 | - EEH_HTML::br() |
|
356 | - . |
|
357 | - sprintf( |
|
358 | - esc_html__( |
|
359 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
360 | - 'event_espresso' |
|
361 | - ), |
|
362 | - EEH_HTML::link( |
|
363 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
364 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
365 | - '', |
|
366 | - '', |
|
367 | - 'ee-form-add-new-state-wiki-lnk', |
|
368 | - '', |
|
369 | - 'target="_blank"' |
|
370 | - ) |
|
371 | - ) |
|
372 | - . |
|
373 | - EEH_HTML::divx() |
|
374 | - . |
|
375 | - EEH_HTML::br() |
|
376 | - . |
|
377 | - EEH_HTML::link( |
|
378 | - '', |
|
379 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
380 | - '', |
|
381 | - 'hide-' . $input->html_id(), |
|
382 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
383 | - '', |
|
384 | - 'data-target="' . $input->html_id() . '"' |
|
385 | - ) |
|
386 | - . |
|
387 | - EEH_HTML::divx() |
|
388 | - . |
|
389 | - EEH_HTML::br() |
|
390 | - ) |
|
391 | - ), |
|
392 | - ), |
|
393 | - ) |
|
394 | - ); |
|
395 | - $question_group_reg_form->add_subsections( |
|
396 | - array('new_state_micro_form' => $new_state_micro_form), |
|
397 | - 'state', |
|
398 | - false |
|
399 | - ); |
|
400 | - } |
|
401 | - return $question_group_reg_form; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * set_new_state_input_width |
|
408 | - * |
|
409 | - * @return int|string |
|
410 | - * @throws EE_Error |
|
411 | - * @throws InvalidArgumentException |
|
412 | - * @throws InvalidDataTypeException |
|
413 | - * @throws InvalidInterfaceException |
|
414 | - * @throws ReflectionException |
|
415 | - */ |
|
416 | - public static function add_new_state() |
|
417 | - { |
|
418 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
419 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
420 | - EE_Registry::instance()->load_model('State'); |
|
421 | - // grab country ISO code, new state name, and new state abbreviation |
|
422 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
423 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
424 | - : false; |
|
425 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
426 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
427 | - : false; |
|
428 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
429 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
430 | - : false; |
|
431 | - if ($state_country && $state_name && $state_abbr) { |
|
432 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
433 | - 'CNT_ISO' => strtoupper($state_country), |
|
434 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
435 | - 'STA_name' => ucwords($state_name), |
|
436 | - 'STA_active' => false, |
|
437 | - )); |
|
438 | - if ($new_state instanceof EE_State) { |
|
439 | - // clean house |
|
440 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
441 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
442 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
443 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
444 | - // get any existing new states |
|
445 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
446 | - 'nsmf_new_states' |
|
447 | - ); |
|
448 | - $new_states[$new_state->ID()] = $new_state; |
|
449 | - EE_Registry::instance()->SSN->set_session_data( |
|
450 | - array('nsmf_new_states' => $new_states) |
|
451 | - ); |
|
452 | - if (EE_Registry::instance()->REQ->ajax) { |
|
453 | - echo wp_json_encode(array( |
|
454 | - 'success' => true, |
|
455 | - 'id' => $new_state->ID(), |
|
456 | - 'name' => $new_state->name(), |
|
457 | - 'abbrev' => $new_state->abbrev(), |
|
458 | - 'country_iso' => $new_state->country_iso(), |
|
459 | - 'country_name' => $new_state->country()->name(), |
|
460 | - )); |
|
461 | - exit(); |
|
462 | - } |
|
463 | - return $new_state->ID(); |
|
464 | - } |
|
465 | - } else { |
|
466 | - $error = esc_html__( |
|
467 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
468 | - 'event_espresso' |
|
469 | - ); |
|
470 | - if (EE_Registry::instance()->REQ->ajax) { |
|
471 | - echo wp_json_encode(array('error' => $error)); |
|
472 | - exit(); |
|
473 | - } |
|
474 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
475 | - } |
|
476 | - } |
|
477 | - return false; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * recursively drills down through request params to remove any that were added by this module |
|
484 | - * |
|
485 | - * @param array $request_params |
|
486 | - * @return array |
|
487 | - */ |
|
488 | - public static function filter_checkout_request_params($request_params) |
|
489 | - { |
|
490 | - foreach ($request_params as $form_section) { |
|
491 | - if (is_array($form_section)) { |
|
492 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
493 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
494 | - } |
|
495 | - } |
|
496 | - return $request_params; |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * @param array $request_params |
|
503 | - * @return array |
|
504 | - */ |
|
505 | - public static function unset_new_state_request_params($request_params) |
|
506 | - { |
|
507 | - unset( |
|
508 | - $request_params['new_state_micro_form'], |
|
509 | - $request_params['new_state_micro_add_new_state'], |
|
510 | - $request_params['new_state_micro_new_state_country'], |
|
511 | - $request_params['new_state_micro_new_state_name'], |
|
512 | - $request_params['new_state_micro_new_state_abbrv'] |
|
513 | - ); |
|
514 | - return $request_params; |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * @param array $props_n_values |
|
521 | - * @return bool |
|
522 | - * @throws EE_Error |
|
523 | - * @throws InvalidArgumentException |
|
524 | - * @throws InvalidDataTypeException |
|
525 | - * @throws InvalidInterfaceException |
|
526 | - */ |
|
527 | - public static function save_new_state_to_db($props_n_values = array()) |
|
528 | - { |
|
529 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
530 | - if (! empty($existing_state)) { |
|
531 | - return array_pop($existing_state); |
|
532 | - } |
|
533 | - $new_state = EE_State::new_instance($props_n_values); |
|
534 | - if ($new_state instanceof EE_State) { |
|
535 | - $country_settings_url = add_query_arg( |
|
536 | - array( |
|
537 | - 'page' => 'espresso_general_settings', |
|
538 | - 'action' => 'country_settings', |
|
539 | - 'country' => $new_state->country_iso(), |
|
540 | - ), |
|
541 | - admin_url('admin.php') |
|
542 | - ); |
|
543 | - // if not non-ajax admin |
|
544 | - new PersistentAdminNotice( |
|
545 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
546 | - sprintf( |
|
547 | - esc_html__( |
|
548 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
549 | - 'event_espresso' |
|
550 | - ), |
|
551 | - '<b>' . $new_state->name() . '</b>', |
|
552 | - '<b>' . $new_state->abbrev() . '</b>', |
|
553 | - '<b>' . $new_state->country()->name() . '</b>', |
|
554 | - '<a href="' |
|
555 | - . $country_settings_url |
|
556 | - . '">' |
|
557 | - . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
558 | - 'event_espresso') |
|
559 | - . '</a>', |
|
560 | - '<br />' |
|
561 | - ) |
|
562 | - ); |
|
563 | - $new_state->save(); |
|
564 | - EEM_State::instance()->reset_cached_states(); |
|
565 | - return $new_state; |
|
566 | - } |
|
567 | - return false; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - |
|
572 | - /** |
|
573 | - * @param string $CNT_ISO |
|
574 | - * @param string $STA_ID |
|
575 | - * @param array $cols_n_values |
|
576 | - * @return void |
|
577 | - * @throws DomainException |
|
578 | - * @throws EE_Error |
|
579 | - * @throws InvalidArgumentException |
|
580 | - * @throws InvalidDataTypeException |
|
581 | - * @throws InvalidInterfaceException |
|
582 | - */ |
|
583 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
584 | - { |
|
585 | - if (! $CNT_ISO) { |
|
586 | - EE_Error::add_error( |
|
587 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
588 | - __FILE__, |
|
589 | - __FUNCTION__, |
|
590 | - __LINE__ |
|
591 | - ); |
|
592 | - } |
|
593 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
594 | - : false; |
|
595 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
596 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
597 | - if ($state instanceof EE_State) { |
|
598 | - $STA_abbrev = $state->abbrev(); |
|
599 | - } |
|
600 | - } |
|
601 | - if (! $STA_abbrev) { |
|
602 | - EE_Error::add_error( |
|
603 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
604 | - __FILE__, |
|
605 | - __FUNCTION__, |
|
606 | - __LINE__ |
|
607 | - ); |
|
608 | - } |
|
609 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
610 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
611 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
612 | - ); |
|
613 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
614 | - } |
|
615 | - |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * @param EE_State[] $state_options |
|
620 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
621 | - * @param EE_Registration $registration |
|
622 | - * @param EE_Question $question |
|
623 | - * @param $answer |
|
624 | - * @return array |
|
625 | - * @throws EE_Error |
|
626 | - * @throws InvalidArgumentException |
|
627 | - * @throws InvalidDataTypeException |
|
628 | - * @throws InvalidInterfaceException |
|
629 | - */ |
|
630 | - public static function inject_new_reg_state_into_options( |
|
631 | - $state_options = array(), |
|
632 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
633 | - EE_Registration $registration, |
|
634 | - EE_Question $question, |
|
635 | - $answer |
|
636 | - ) { |
|
637 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
638 | - && $question->type() === EEM_Question::QST_type_state |
|
639 | - ) { |
|
640 | - $STA_ID = $answer->value(); |
|
641 | - if (! empty($STA_ID)) { |
|
642 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
643 | - if ($state instanceof EE_State) { |
|
644 | - $country = $state->country(); |
|
645 | - if ($country instanceof EE_Country) { |
|
646 | - if (! isset($state_options[$country->name()])) { |
|
647 | - $state_options[$country->name()] = array(); |
|
648 | - } |
|
649 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
650 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
651 | - } |
|
652 | - } |
|
653 | - } |
|
654 | - } |
|
655 | - } |
|
656 | - return $state_options; |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * @param EE_Country[] $country_options |
|
663 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
664 | - * @param EE_Registration $registration |
|
665 | - * @param EE_Question $question |
|
666 | - * @param $answer |
|
667 | - * @return array |
|
668 | - * @throws EE_Error |
|
669 | - * @throws InvalidArgumentException |
|
670 | - * @throws InvalidDataTypeException |
|
671 | - * @throws InvalidInterfaceException |
|
672 | - */ |
|
673 | - public static function inject_new_reg_country_into_options( |
|
674 | - $country_options = array(), |
|
675 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
676 | - EE_Registration $registration, |
|
677 | - EE_Question $question, |
|
678 | - $answer |
|
679 | - ) { |
|
680 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
681 | - && $question->type() |
|
682 | - === EEM_Question::QST_type_country |
|
683 | - ) { |
|
684 | - $CNT_ISO = $answer->value(); |
|
685 | - if (! empty($CNT_ISO)) { |
|
686 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
687 | - if ($country instanceof EE_Country) { |
|
688 | - if (! isset($country_options[$CNT_ISO])) { |
|
689 | - $country_options[$CNT_ISO] = $country->name(); |
|
690 | - } |
|
691 | - } |
|
692 | - } |
|
693 | - } |
|
694 | - return $country_options; |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * @param EE_State[] $state_options |
|
701 | - * @return array |
|
702 | - * @throws EE_Error |
|
703 | - * @throws InvalidArgumentException |
|
704 | - * @throws InvalidDataTypeException |
|
705 | - * @throws InvalidInterfaceException |
|
706 | - */ |
|
707 | - public static function state_options($state_options = array()) |
|
708 | - { |
|
709 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
710 | - foreach ($new_states as $new_state) { |
|
711 | - if ( |
|
712 | - $new_state instanceof EE_State |
|
713 | - && $new_state->country() instanceof EE_Country |
|
714 | - ) { |
|
715 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
716 | - } |
|
717 | - } |
|
718 | - return $state_options; |
|
719 | - } |
|
720 | - |
|
721 | - |
|
722 | - |
|
723 | - /** |
|
724 | - * @return array |
|
725 | - * @throws InvalidArgumentException |
|
726 | - * @throws InvalidDataTypeException |
|
727 | - * @throws InvalidInterfaceException |
|
728 | - */ |
|
729 | - protected static function _get_new_states() |
|
730 | - { |
|
731 | - $new_states = array(); |
|
732 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
733 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
734 | - 'nsmf_new_states' |
|
735 | - ); |
|
736 | - } |
|
737 | - return is_array($new_states) ? $new_states : array(); |
|
738 | - } |
|
739 | - |
|
740 | - |
|
741 | - |
|
742 | - /** |
|
743 | - * @param EE_Country[] $country_options |
|
744 | - * @return array |
|
745 | - * @throws EE_Error |
|
746 | - * @throws InvalidArgumentException |
|
747 | - * @throws InvalidDataTypeException |
|
748 | - * @throws InvalidInterfaceException |
|
749 | - */ |
|
750 | - public static function country_options($country_options = array()) |
|
751 | - { |
|
752 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
753 | - foreach ($new_states as $new_state) { |
|
754 | - if ( |
|
755 | - $new_state instanceof EE_State |
|
756 | - && $new_state->country() instanceof EE_Country |
|
757 | - ) { |
|
758 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
759 | - } |
|
760 | - } |
|
761 | - return $country_options; |
|
762 | - } |
|
25 | + /** |
|
26 | + * @return EED_Module|EED_Add_New_State |
|
27 | + */ |
|
28 | + public static function instance() |
|
29 | + { |
|
30 | + return parent::get_instance(__CLASS__); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
37 | + * |
|
38 | + * @return void |
|
39 | + */ |
|
40 | + public static function set_hooks() |
|
41 | + { |
|
42 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
43 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
44 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
45 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
46 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
47 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
48 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
49 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
50 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
51 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
52 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
53 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
54 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
55 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
56 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
57 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
58 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
65 | + * |
|
66 | + * @return void |
|
67 | + */ |
|
68 | + public static function set_hooks_admin() |
|
69 | + { |
|
70 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
71 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
72 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
73 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
74 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
75 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
76 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
77 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
78 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
79 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
80 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
81 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
82 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
83 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
84 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
85 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
86 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
87 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
88 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
89 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
90 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
91 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
92 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public static function set_definitions() |
|
101 | + { |
|
102 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
103 | + define('ANS_TEMPLATES_PATH', str_replace( |
|
104 | + '\\', |
|
105 | + DS, |
|
106 | + plugin_dir_path(__FILE__)) . 'templates' . DS |
|
107 | + ); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @param WP $WP |
|
114 | + * @return void |
|
115 | + */ |
|
116 | + public function run($WP) |
|
117 | + { |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public static function translate_js_strings() |
|
126 | + { |
|
127 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
128 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
129 | + 'event_espresso' |
|
130 | + ); |
|
131 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
132 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
133 | + 'event_espresso' |
|
134 | + ); |
|
135 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
136 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
137 | + 'event_espresso' |
|
138 | + ); |
|
139 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
140 | + 'The new state was successfully saved to the database.', |
|
141 | + 'event_espresso' |
|
142 | + ); |
|
143 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
144 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
145 | + 'event_espresso' |
|
146 | + ); |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return void |
|
153 | + */ |
|
154 | + public static function wp_enqueue_scripts() |
|
155 | + { |
|
156 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
157 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
158 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
159 | + wp_enqueue_script('add_new_state'); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * display_add_new_state_micro_form |
|
167 | + * |
|
168 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
169 | + * @return string |
|
170 | + * @throws EE_Error |
|
171 | + * @throws InvalidArgumentException |
|
172 | + * @throws InvalidDataTypeException |
|
173 | + * @throws InvalidInterfaceException |
|
174 | + */ |
|
175 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
176 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
177 | + { |
|
178 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
179 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
180 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
181 | + // is the "state" question in this form section? |
|
182 | + $input = $question_group_reg_form->get_subsection('state'); |
|
183 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
184 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
185 | + //by forcing it to set it now, like it did while getting the form for display |
|
186 | + if ($input instanceof EE_State_Select_Input) { |
|
187 | + $input->html_name(); |
|
188 | + } |
|
189 | + return $question_group_reg_form; |
|
190 | + } |
|
191 | + // we're only doing this for state select inputs |
|
192 | + if ($input instanceof EE_State_Select_Input && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
193 | + // grab any set values from the request |
|
194 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
195 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
196 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
197 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
198 | + $country_options = array(); |
|
199 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
200 | + if (! empty($countries)) { |
|
201 | + foreach ($countries as $country) { |
|
202 | + if ($country instanceof EE_Country) { |
|
203 | + $country_options[$country->ID()] = $country->name(); |
|
204 | + } |
|
205 | + } |
|
206 | + } |
|
207 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
208 | + array( |
|
209 | + 'name' => 'new_state_micro_form', |
|
210 | + 'html_id' => 'new_state_micro_form', |
|
211 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
212 | + 'subsections' => array( |
|
213 | + // add hidden input to indicate that a new state is being added |
|
214 | + 'add_new_state' => new EE_Hidden_Input( |
|
215 | + array( |
|
216 | + 'html_name' => str_replace( |
|
217 | + 'state', |
|
218 | + 'nsmf_add_new_state', |
|
219 | + $input->html_name() |
|
220 | + ), |
|
221 | + 'html_id' => str_replace( |
|
222 | + 'state', |
|
223 | + 'nsmf_add_new_state', |
|
224 | + $input->html_id() |
|
225 | + ), |
|
226 | + 'default' => 0, |
|
227 | + ) |
|
228 | + ), |
|
229 | + // add link for displaying hidden container |
|
230 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
231 | + apply_filters( |
|
232 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
233 | + EEH_HTML::link( |
|
234 | + '', |
|
235 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
236 | + '', |
|
237 | + 'display-' . $input->html_id(), |
|
238 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
239 | + '', |
|
240 | + 'data-target="' . $input->html_id() . '"' |
|
241 | + ) |
|
242 | + ) |
|
243 | + ), |
|
244 | + // add initial html for hidden container |
|
245 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
246 | + apply_filters( |
|
247 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
248 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
249 | + 'display: none;') . |
|
250 | + EEH_HTML::h6( |
|
251 | + esc_html__( |
|
252 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
253 | + 'event_espresso' |
|
254 | + ) |
|
255 | + ) . |
|
256 | + EEH_HTML::ul() . |
|
257 | + EEH_HTML::li( |
|
258 | + esc_html__( |
|
259 | + 'first select the Country that your State/Province belongs to', |
|
260 | + 'event_espresso' |
|
261 | + ) |
|
262 | + ) . |
|
263 | + EEH_HTML::li( |
|
264 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
265 | + ) . |
|
266 | + EEH_HTML::li( |
|
267 | + esc_html__( |
|
268 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
269 | + 'event_espresso' |
|
270 | + ) |
|
271 | + ) . |
|
272 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
273 | + EEH_HTML::ulx() |
|
274 | + ) |
|
275 | + ), |
|
276 | + // NEW STATE COUNTRY |
|
277 | + 'new_state_country' => new EE_Country_Select_Input( |
|
278 | + $country_options, |
|
279 | + array( |
|
280 | + 'html_name' => $country_name, |
|
281 | + 'html_id' => str_replace( |
|
282 | + 'state', |
|
283 | + 'nsmf_new_state_country', $input->html_id() |
|
284 | + ), |
|
285 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
286 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
287 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
288 | + 'required' => false, |
|
289 | + ) |
|
290 | + ), |
|
291 | + // NEW STATE NAME |
|
292 | + 'new_state_name' => new EE_Text_Input( |
|
293 | + array( |
|
294 | + 'html_name' => $state_name, |
|
295 | + 'html_id' => str_replace( |
|
296 | + 'state', |
|
297 | + 'nsmf_new_state_name', $input->html_id() |
|
298 | + ), |
|
299 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
300 | + 'html_label_text' => esc_html__('New State/Province Name', |
|
301 | + 'event_espresso'), |
|
302 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
303 | + 'required' => false, |
|
304 | + ) |
|
305 | + ), |
|
306 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
307 | + // NEW STATE NAME |
|
308 | + 'new_state_abbrv' => new EE_Text_Input( |
|
309 | + array( |
|
310 | + 'html_name' => $abbrv_name, |
|
311 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
312 | + $input->html_id()), |
|
313 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
314 | + 'html_label_text' => esc_html__( |
|
315 | + 'New State/Province Abbreviation', |
|
316 | + 'event_espresso' |
|
317 | + ) . ' *', |
|
318 | + 'html_other_attributes' => 'size="24"', |
|
319 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
320 | + 'required' => false, |
|
321 | + ) |
|
322 | + ), |
|
323 | + // "submit" button |
|
324 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
325 | + apply_filters( |
|
326 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
327 | + EEH_HTML::nbsp(3) . |
|
328 | + EEH_HTML::link( |
|
329 | + '', |
|
330 | + esc_html__('ADD', 'event_espresso'), |
|
331 | + '', |
|
332 | + 'submit-' . $new_state_submit_id, |
|
333 | + 'ee-form-add-new-state-submit button button-secondary', |
|
334 | + '', |
|
335 | + 'data-target="' . $new_state_submit_id . '"' |
|
336 | + ) |
|
337 | + ) |
|
338 | + ), |
|
339 | + // extra info |
|
340 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
341 | + apply_filters( |
|
342 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
343 | + EEH_HTML::br(2) |
|
344 | + . |
|
345 | + EEH_HTML::div('', '', 'small-text') |
|
346 | + . |
|
347 | + EEH_HTML::strong( |
|
348 | + '* ' . |
|
349 | + esc_html__( |
|
350 | + 'Don\'t know your State/Province Abbreviation?', |
|
351 | + 'event_espresso' |
|
352 | + ) |
|
353 | + ) |
|
354 | + . |
|
355 | + EEH_HTML::br() |
|
356 | + . |
|
357 | + sprintf( |
|
358 | + esc_html__( |
|
359 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
360 | + 'event_espresso' |
|
361 | + ), |
|
362 | + EEH_HTML::link( |
|
363 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
364 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
365 | + '', |
|
366 | + '', |
|
367 | + 'ee-form-add-new-state-wiki-lnk', |
|
368 | + '', |
|
369 | + 'target="_blank"' |
|
370 | + ) |
|
371 | + ) |
|
372 | + . |
|
373 | + EEH_HTML::divx() |
|
374 | + . |
|
375 | + EEH_HTML::br() |
|
376 | + . |
|
377 | + EEH_HTML::link( |
|
378 | + '', |
|
379 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
380 | + '', |
|
381 | + 'hide-' . $input->html_id(), |
|
382 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
383 | + '', |
|
384 | + 'data-target="' . $input->html_id() . '"' |
|
385 | + ) |
|
386 | + . |
|
387 | + EEH_HTML::divx() |
|
388 | + . |
|
389 | + EEH_HTML::br() |
|
390 | + ) |
|
391 | + ), |
|
392 | + ), |
|
393 | + ) |
|
394 | + ); |
|
395 | + $question_group_reg_form->add_subsections( |
|
396 | + array('new_state_micro_form' => $new_state_micro_form), |
|
397 | + 'state', |
|
398 | + false |
|
399 | + ); |
|
400 | + } |
|
401 | + return $question_group_reg_form; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * set_new_state_input_width |
|
408 | + * |
|
409 | + * @return int|string |
|
410 | + * @throws EE_Error |
|
411 | + * @throws InvalidArgumentException |
|
412 | + * @throws InvalidDataTypeException |
|
413 | + * @throws InvalidInterfaceException |
|
414 | + * @throws ReflectionException |
|
415 | + */ |
|
416 | + public static function add_new_state() |
|
417 | + { |
|
418 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
419 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
420 | + EE_Registry::instance()->load_model('State'); |
|
421 | + // grab country ISO code, new state name, and new state abbreviation |
|
422 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
423 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
424 | + : false; |
|
425 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
426 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
427 | + : false; |
|
428 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
429 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
430 | + : false; |
|
431 | + if ($state_country && $state_name && $state_abbr) { |
|
432 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
433 | + 'CNT_ISO' => strtoupper($state_country), |
|
434 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
435 | + 'STA_name' => ucwords($state_name), |
|
436 | + 'STA_active' => false, |
|
437 | + )); |
|
438 | + if ($new_state instanceof EE_State) { |
|
439 | + // clean house |
|
440 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
441 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
442 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
443 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
444 | + // get any existing new states |
|
445 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
446 | + 'nsmf_new_states' |
|
447 | + ); |
|
448 | + $new_states[$new_state->ID()] = $new_state; |
|
449 | + EE_Registry::instance()->SSN->set_session_data( |
|
450 | + array('nsmf_new_states' => $new_states) |
|
451 | + ); |
|
452 | + if (EE_Registry::instance()->REQ->ajax) { |
|
453 | + echo wp_json_encode(array( |
|
454 | + 'success' => true, |
|
455 | + 'id' => $new_state->ID(), |
|
456 | + 'name' => $new_state->name(), |
|
457 | + 'abbrev' => $new_state->abbrev(), |
|
458 | + 'country_iso' => $new_state->country_iso(), |
|
459 | + 'country_name' => $new_state->country()->name(), |
|
460 | + )); |
|
461 | + exit(); |
|
462 | + } |
|
463 | + return $new_state->ID(); |
|
464 | + } |
|
465 | + } else { |
|
466 | + $error = esc_html__( |
|
467 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
468 | + 'event_espresso' |
|
469 | + ); |
|
470 | + if (EE_Registry::instance()->REQ->ajax) { |
|
471 | + echo wp_json_encode(array('error' => $error)); |
|
472 | + exit(); |
|
473 | + } |
|
474 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
475 | + } |
|
476 | + } |
|
477 | + return false; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * recursively drills down through request params to remove any that were added by this module |
|
484 | + * |
|
485 | + * @param array $request_params |
|
486 | + * @return array |
|
487 | + */ |
|
488 | + public static function filter_checkout_request_params($request_params) |
|
489 | + { |
|
490 | + foreach ($request_params as $form_section) { |
|
491 | + if (is_array($form_section)) { |
|
492 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
493 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
494 | + } |
|
495 | + } |
|
496 | + return $request_params; |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * @param array $request_params |
|
503 | + * @return array |
|
504 | + */ |
|
505 | + public static function unset_new_state_request_params($request_params) |
|
506 | + { |
|
507 | + unset( |
|
508 | + $request_params['new_state_micro_form'], |
|
509 | + $request_params['new_state_micro_add_new_state'], |
|
510 | + $request_params['new_state_micro_new_state_country'], |
|
511 | + $request_params['new_state_micro_new_state_name'], |
|
512 | + $request_params['new_state_micro_new_state_abbrv'] |
|
513 | + ); |
|
514 | + return $request_params; |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * @param array $props_n_values |
|
521 | + * @return bool |
|
522 | + * @throws EE_Error |
|
523 | + * @throws InvalidArgumentException |
|
524 | + * @throws InvalidDataTypeException |
|
525 | + * @throws InvalidInterfaceException |
|
526 | + */ |
|
527 | + public static function save_new_state_to_db($props_n_values = array()) |
|
528 | + { |
|
529 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
530 | + if (! empty($existing_state)) { |
|
531 | + return array_pop($existing_state); |
|
532 | + } |
|
533 | + $new_state = EE_State::new_instance($props_n_values); |
|
534 | + if ($new_state instanceof EE_State) { |
|
535 | + $country_settings_url = add_query_arg( |
|
536 | + array( |
|
537 | + 'page' => 'espresso_general_settings', |
|
538 | + 'action' => 'country_settings', |
|
539 | + 'country' => $new_state->country_iso(), |
|
540 | + ), |
|
541 | + admin_url('admin.php') |
|
542 | + ); |
|
543 | + // if not non-ajax admin |
|
544 | + new PersistentAdminNotice( |
|
545 | + 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
546 | + sprintf( |
|
547 | + esc_html__( |
|
548 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
549 | + 'event_espresso' |
|
550 | + ), |
|
551 | + '<b>' . $new_state->name() . '</b>', |
|
552 | + '<b>' . $new_state->abbrev() . '</b>', |
|
553 | + '<b>' . $new_state->country()->name() . '</b>', |
|
554 | + '<a href="' |
|
555 | + . $country_settings_url |
|
556 | + . '">' |
|
557 | + . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
558 | + 'event_espresso') |
|
559 | + . '</a>', |
|
560 | + '<br />' |
|
561 | + ) |
|
562 | + ); |
|
563 | + $new_state->save(); |
|
564 | + EEM_State::instance()->reset_cached_states(); |
|
565 | + return $new_state; |
|
566 | + } |
|
567 | + return false; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + |
|
572 | + /** |
|
573 | + * @param string $CNT_ISO |
|
574 | + * @param string $STA_ID |
|
575 | + * @param array $cols_n_values |
|
576 | + * @return void |
|
577 | + * @throws DomainException |
|
578 | + * @throws EE_Error |
|
579 | + * @throws InvalidArgumentException |
|
580 | + * @throws InvalidDataTypeException |
|
581 | + * @throws InvalidInterfaceException |
|
582 | + */ |
|
583 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
584 | + { |
|
585 | + if (! $CNT_ISO) { |
|
586 | + EE_Error::add_error( |
|
587 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
588 | + __FILE__, |
|
589 | + __FUNCTION__, |
|
590 | + __LINE__ |
|
591 | + ); |
|
592 | + } |
|
593 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
594 | + : false; |
|
595 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
596 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
597 | + if ($state instanceof EE_State) { |
|
598 | + $STA_abbrev = $state->abbrev(); |
|
599 | + } |
|
600 | + } |
|
601 | + if (! $STA_abbrev) { |
|
602 | + EE_Error::add_error( |
|
603 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
604 | + __FILE__, |
|
605 | + __FUNCTION__, |
|
606 | + __LINE__ |
|
607 | + ); |
|
608 | + } |
|
609 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
610 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
611 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
612 | + ); |
|
613 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
614 | + } |
|
615 | + |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * @param EE_State[] $state_options |
|
620 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
621 | + * @param EE_Registration $registration |
|
622 | + * @param EE_Question $question |
|
623 | + * @param $answer |
|
624 | + * @return array |
|
625 | + * @throws EE_Error |
|
626 | + * @throws InvalidArgumentException |
|
627 | + * @throws InvalidDataTypeException |
|
628 | + * @throws InvalidInterfaceException |
|
629 | + */ |
|
630 | + public static function inject_new_reg_state_into_options( |
|
631 | + $state_options = array(), |
|
632 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
633 | + EE_Registration $registration, |
|
634 | + EE_Question $question, |
|
635 | + $answer |
|
636 | + ) { |
|
637 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
638 | + && $question->type() === EEM_Question::QST_type_state |
|
639 | + ) { |
|
640 | + $STA_ID = $answer->value(); |
|
641 | + if (! empty($STA_ID)) { |
|
642 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
643 | + if ($state instanceof EE_State) { |
|
644 | + $country = $state->country(); |
|
645 | + if ($country instanceof EE_Country) { |
|
646 | + if (! isset($state_options[$country->name()])) { |
|
647 | + $state_options[$country->name()] = array(); |
|
648 | + } |
|
649 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
650 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
651 | + } |
|
652 | + } |
|
653 | + } |
|
654 | + } |
|
655 | + } |
|
656 | + return $state_options; |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * @param EE_Country[] $country_options |
|
663 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
664 | + * @param EE_Registration $registration |
|
665 | + * @param EE_Question $question |
|
666 | + * @param $answer |
|
667 | + * @return array |
|
668 | + * @throws EE_Error |
|
669 | + * @throws InvalidArgumentException |
|
670 | + * @throws InvalidDataTypeException |
|
671 | + * @throws InvalidInterfaceException |
|
672 | + */ |
|
673 | + public static function inject_new_reg_country_into_options( |
|
674 | + $country_options = array(), |
|
675 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
676 | + EE_Registration $registration, |
|
677 | + EE_Question $question, |
|
678 | + $answer |
|
679 | + ) { |
|
680 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
681 | + && $question->type() |
|
682 | + === EEM_Question::QST_type_country |
|
683 | + ) { |
|
684 | + $CNT_ISO = $answer->value(); |
|
685 | + if (! empty($CNT_ISO)) { |
|
686 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
687 | + if ($country instanceof EE_Country) { |
|
688 | + if (! isset($country_options[$CNT_ISO])) { |
|
689 | + $country_options[$CNT_ISO] = $country->name(); |
|
690 | + } |
|
691 | + } |
|
692 | + } |
|
693 | + } |
|
694 | + return $country_options; |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * @param EE_State[] $state_options |
|
701 | + * @return array |
|
702 | + * @throws EE_Error |
|
703 | + * @throws InvalidArgumentException |
|
704 | + * @throws InvalidDataTypeException |
|
705 | + * @throws InvalidInterfaceException |
|
706 | + */ |
|
707 | + public static function state_options($state_options = array()) |
|
708 | + { |
|
709 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
710 | + foreach ($new_states as $new_state) { |
|
711 | + if ( |
|
712 | + $new_state instanceof EE_State |
|
713 | + && $new_state->country() instanceof EE_Country |
|
714 | + ) { |
|
715 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
716 | + } |
|
717 | + } |
|
718 | + return $state_options; |
|
719 | + } |
|
720 | + |
|
721 | + |
|
722 | + |
|
723 | + /** |
|
724 | + * @return array |
|
725 | + * @throws InvalidArgumentException |
|
726 | + * @throws InvalidDataTypeException |
|
727 | + * @throws InvalidInterfaceException |
|
728 | + */ |
|
729 | + protected static function _get_new_states() |
|
730 | + { |
|
731 | + $new_states = array(); |
|
732 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
733 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
734 | + 'nsmf_new_states' |
|
735 | + ); |
|
736 | + } |
|
737 | + return is_array($new_states) ? $new_states : array(); |
|
738 | + } |
|
739 | + |
|
740 | + |
|
741 | + |
|
742 | + /** |
|
743 | + * @param EE_Country[] $country_options |
|
744 | + * @return array |
|
745 | + * @throws EE_Error |
|
746 | + * @throws InvalidArgumentException |
|
747 | + * @throws InvalidDataTypeException |
|
748 | + * @throws InvalidInterfaceException |
|
749 | + */ |
|
750 | + public static function country_options($country_options = array()) |
|
751 | + { |
|
752 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
753 | + foreach ($new_states as $new_state) { |
|
754 | + if ( |
|
755 | + $new_state instanceof EE_State |
|
756 | + && $new_state->country() instanceof EE_Country |
|
757 | + ) { |
|
758 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
759 | + } |
|
760 | + } |
|
761 | + return $country_options; |
|
762 | + } |
|
763 | 763 | |
764 | 764 | |
765 | 765 |