Completed
Branch fix/remove-help-tours-events (db2a78)
by
unknown
12:28 queued 10:19
created
admin_pages/transactions/Transactions_Admin_Page.core.php 1 patch
Indentation   +2521 added lines, -2521 removed lines patch added patch discarded remove patch
@@ -13,2525 +13,2525 @@
 block discarded – undo
13 13
 class Transactions_Admin_Page extends EE_Admin_Page
14 14
 {
15 15
 
16
-    /**
17
-     * @var EE_Transaction
18
-     */
19
-    private $_transaction;
20
-
21
-    /**
22
-     * @var EE_Session
23
-     */
24
-    private $_session;
25
-
26
-    /**
27
-     * @var array $_txn_status
28
-     */
29
-    private static $_txn_status;
30
-
31
-    /**
32
-     * @var array $_pay_status
33
-     */
34
-    private static $_pay_status;
35
-
36
-    /**
37
-     * @var array $_existing_reg_payment_REG_IDs
38
-     */
39
-    protected $_existing_reg_payment_REG_IDs;
40
-
41
-
42
-    /**
43
-     *    _init_page_props
44
-     *
45
-     * @return void
46
-     */
47
-    protected function _init_page_props()
48
-    {
49
-        $this->page_slug        = TXN_PG_SLUG;
50
-        $this->page_label       = esc_html__('Transactions', 'event_espresso');
51
-        $this->_admin_base_url  = TXN_ADMIN_URL;
52
-        $this->_admin_base_path = TXN_ADMIN;
53
-    }
54
-
55
-
56
-    /**
57
-     *    _ajax_hooks
58
-     *
59
-     * @return void
60
-     */
61
-    protected function _ajax_hooks()
62
-    {
63
-        add_action('wp_ajax_espresso_apply_payment', [$this, 'apply_payments_or_refunds']);
64
-        add_action('wp_ajax_espresso_apply_refund', [$this, 'apply_payments_or_refunds']);
65
-        add_action('wp_ajax_espresso_delete_payment', [$this, 'delete_payment']);
66
-    }
67
-
68
-
69
-    /**
70
-     *    _define_page_props
71
-     *
72
-     * @return void
73
-     */
74
-    protected function _define_page_props()
75
-    {
76
-        $this->_admin_page_title = $this->page_label;
77
-        $this->_labels           = [
78
-            'buttons' => [
79
-                'add'    => esc_html__('Add New Transaction', 'event_espresso'),
80
-                'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
81
-                'delete' => esc_html__('Delete Transaction', 'event_espresso'),
82
-            ],
83
-        ];
84
-    }
85
-
86
-
87
-    /**
88
-     *        grab url requests and route them
89
-     *
90
-     * @access private
91
-     * @return void
92
-     * @throws EE_Error
93
-     * @throws InvalidArgumentException
94
-     * @throws InvalidDataTypeException
95
-     * @throws InvalidInterfaceException
96
-     */
97
-    public function _set_page_routes()
98
-    {
99
-
100
-        $this->_set_transaction_status_array();
101
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
102
-
103
-        $this->_page_routes = [
104
-
105
-            'default' => [
106
-                'func'       => '_transactions_overview_list_table',
107
-                'capability' => 'ee_read_transactions',
108
-            ],
109
-
110
-            'view_transaction' => [
111
-                'func'       => '_transaction_details',
112
-                'capability' => 'ee_read_transaction',
113
-                'obj_id'     => $TXN_ID,
114
-            ],
115
-
116
-            'send_payment_reminder' => [
117
-                'func'       => '_send_payment_reminder',
118
-                'noheader'   => true,
119
-                'capability' => 'ee_send_message',
120
-            ],
121
-
122
-            'espresso_apply_payment' => [
123
-                'func'       => 'apply_payments_or_refunds',
124
-                'noheader'   => true,
125
-                'capability' => 'ee_edit_payments',
126
-            ],
127
-
128
-            'espresso_apply_refund' => [
129
-                'func'       => 'apply_payments_or_refunds',
130
-                'noheader'   => true,
131
-                'capability' => 'ee_edit_payments',
132
-            ],
133
-
134
-            'espresso_delete_payment' => [
135
-                'func'       => 'delete_payment',
136
-                'noheader'   => true,
137
-                'capability' => 'ee_delete_payments',
138
-            ],
139
-
140
-            'espresso_recalculate_line_items' => [
141
-                'func'       => 'recalculateLineItems',
142
-                'noheader'   => true,
143
-                'capability' => 'ee_edit_payments',
144
-            ],
145
-
146
-        ];
147
-    }
148
-
149
-
150
-    protected function _set_page_config()
151
-    {
152
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
153
-        $this->_page_config = [
154
-            'default'          => [
155
-                'nav'           => [
156
-                    'label' => esc_html__('Overview', 'event_espresso'),
157
-                    'order' => 10,
158
-                ],
159
-                'list_table'    => 'EE_Admin_Transactions_List_Table',
160
-                'help_tabs'     => [
161
-                    'transactions_overview_help_tab'                       => [
162
-                        'title'    => esc_html__('Transactions Overview', 'event_espresso'),
163
-                        'filename' => 'transactions_overview',
164
-                    ],
165
-                    'transactions_overview_table_column_headings_help_tab' => [
166
-                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
167
-                        'filename' => 'transactions_overview_table_column_headings',
168
-                    ],
169
-                    'transactions_overview_views_filters_help_tab'         => [
170
-                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
171
-                        'filename' => 'transactions_overview_views_filters_search',
172
-                    ],
173
-                ],
174
-                /**
175
-                 * commented out because currently we are not displaying tips for transaction list table status but this
176
-                 * may change in a later iteration so want to keep the code for then.
177
-                 */
178
-                // 'qtips' => array( 'Transactions_List_Table_Tips' ),
179
-                'require_nonce' => false,
180
-            ],
181
-            'view_transaction' => [
182
-                'nav'       => [
183
-                    'label'      => esc_html__('View Transaction', 'event_espresso'),
184
-                    'order'      => 5,
185
-                    'url'        => $TXN_ID
186
-                        ? add_query_arg(['TXN_ID' => $TXN_ID], $this->_current_page_view_url)
187
-                        : $this->_admin_base_url,
188
-                    'persistent' => false,
189
-                ],
190
-                'help_tabs' => [
191
-                    'transactions_view_transaction_help_tab'                                              => [
192
-                        'title'    => esc_html__('View Transaction', 'event_espresso'),
193
-                        'filename' => 'transactions_view_transaction',
194
-                    ],
195
-                    'transactions_view_transaction_transaction_details_table_help_tab'                    => [
196
-                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
197
-                        'filename' => 'transactions_view_transaction_transaction_details_table',
198
-                    ],
199
-                    'transactions_view_transaction_attendees_registered_help_tab'                         => [
200
-                        'title'    => esc_html__('Attendees Registered', 'event_espresso'),
201
-                        'filename' => 'transactions_view_transaction_attendees_registered',
202
-                    ],
203
-                    'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => [
204
-                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
205
-                        'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
206
-                    ],
207
-                ],
208
-                'qtips'     => ['Transaction_Details_Tips'],
209
-                'metaboxes' => ['_transaction_details_metaboxes'],
210
-
211
-                'require_nonce' => false,
212
-            ],
213
-        ];
214
-    }
215
-
216
-
217
-    /**
218
-     * The below methods aren't used by this class currently
219
-     */
220
-    protected function _add_screen_options()
221
-    {
222
-        // noop
223
-    }
224
-
225
-
226
-    protected function _add_feature_pointers()
227
-    {
228
-        // noop
229
-    }
230
-
231
-
232
-    public function admin_init()
233
-    {
234
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
235
-        $event_name = $this->request->getRequestParam('event_name');
236
-        $redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
237
-        // IF a registration was JUST added via the admin...
238
-        if ($EVT_ID && $event_name && $redirect_from) {
239
-            // then set a cookie so that we can block any attempts to use
240
-            // the back button as a way to enter another registration.
241
-            setcookie('ee_registration_added', $EVT_ID, time() + WEEK_IN_SECONDS, '/');
242
-            // and update the global
243
-            $_COOKIE['ee_registration_added'] = $EVT_ID;
244
-        }
245
-        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
246
-            '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.',
247
-            'event_espresso'
248
-        );
249
-        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
250
-            'An error occurred! Please refresh the page and try again.',
251
-            'event_espresso'
252
-        );
253
-        EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
254
-        EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
255
-        EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
256
-        EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
257
-            'This transaction has been overpaid ! Payments Total',
258
-            'event_espresso'
259
-        );
260
-    }
261
-
262
-
263
-    public function admin_notices()
264
-    {
265
-        // noop
266
-    }
267
-
268
-
269
-    public function admin_footer_scripts()
270
-    {
271
-        // noop
272
-    }
273
-
274
-
275
-    /**
276
-     * _set_transaction_status_array
277
-     * sets list of transaction statuses
278
-     *
279
-     * @access private
280
-     * @return void
281
-     * @throws EE_Error
282
-     * @throws InvalidArgumentException
283
-     * @throws InvalidDataTypeException
284
-     * @throws InvalidInterfaceException
285
-     */
286
-    private function _set_transaction_status_array()
287
-    {
288
-        self::$_txn_status = EEM_Transaction::instance()->status_array(true);
289
-    }
290
-
291
-
292
-    /**
293
-     * get_transaction_status_array
294
-     * return the transaction status array for wp_list_table
295
-     *
296
-     * @access public
297
-     * @return array
298
-     */
299
-    public function get_transaction_status_array()
300
-    {
301
-        return self::$_txn_status;
302
-    }
303
-
304
-
305
-    /**
306
-     *    get list of payment statuses
307
-     *
308
-     * @access private
309
-     * @return void
310
-     * @throws EE_Error
311
-     * @throws InvalidArgumentException
312
-     * @throws InvalidDataTypeException
313
-     * @throws InvalidInterfaceException
314
-     */
315
-    private function _get_payment_status_array()
316
-    {
317
-        self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
318
-        $this->_template_args['payment_status'] = self::$_pay_status;
319
-    }
320
-
321
-
322
-    /**
323
-     *    _add_screen_options_default
324
-     *
325
-     * @access protected
326
-     * @return void
327
-     * @throws InvalidArgumentException
328
-     * @throws InvalidDataTypeException
329
-     * @throws InvalidInterfaceException
330
-     */
331
-    protected function _add_screen_options_default()
332
-    {
333
-        $this->_per_page_screen_option();
334
-    }
335
-
336
-
337
-    /**
338
-     * load_scripts_styles
339
-     *
340
-     * @access public
341
-     * @return void
342
-     */
343
-    public function load_scripts_styles()
344
-    {
345
-        // enqueue style
346
-        wp_register_style(
347
-            'espresso_txn',
348
-            TXN_ASSETS_URL . 'espresso_transactions_admin.css',
349
-            [],
350
-            EVENT_ESPRESSO_VERSION
351
-        );
352
-        wp_enqueue_style('espresso_txn');
353
-        // scripts
354
-        wp_register_script(
355
-            'espresso_txn',
356
-            TXN_ASSETS_URL . 'espresso_transactions_admin.js',
357
-            [
358
-                'ee_admin_js',
359
-                'ee-datepicker',
360
-                'jquery-ui-datepicker',
361
-                'jquery-ui-draggable',
362
-                'ee-dialog',
363
-                'ee-accounting',
364
-                'ee-serialize-full-array',
365
-            ],
366
-            EVENT_ESPRESSO_VERSION,
367
-            true
368
-        );
369
-        wp_enqueue_script('espresso_txn');
370
-    }
371
-
372
-
373
-    /**
374
-     *    load_scripts_styles_view_transaction
375
-     *
376
-     * @access public
377
-     * @return void
378
-     */
379
-    public function load_scripts_styles_view_transaction()
380
-    {
381
-        // styles
382
-        wp_enqueue_style('espresso-ui-theme');
383
-    }
384
-
385
-
386
-    /**
387
-     *    load_scripts_styles_default
388
-     *
389
-     * @access public
390
-     * @return void
391
-     */
392
-    public function load_scripts_styles_default()
393
-    {
394
-        // styles
395
-        wp_enqueue_style('espresso-ui-theme');
396
-    }
397
-
398
-
399
-    /**
400
-     *    _set_list_table_views_default
401
-     *
402
-     * @access protected
403
-     * @return void
404
-     */
405
-    protected function _set_list_table_views_default()
406
-    {
407
-        $this->_views = [
408
-            'all'        => [
409
-                'slug'  => 'all',
410
-                'label' => esc_html__('View All Transactions', 'event_espresso'),
411
-                'count' => 0,
412
-            ],
413
-            'abandoned'  => [
414
-                'slug'  => 'abandoned',
415
-                'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
416
-                'count' => 0,
417
-            ],
418
-            'incomplete' => [
419
-                'slug'  => 'incomplete',
420
-                'label' => esc_html__('Incomplete Transactions', 'event_espresso'),
421
-                'count' => 0,
422
-            ],
423
-        ];
424
-        if (
425
-            /**
426
-             * Filters whether a link to the "Failed Transactions" list table
427
-             * appears on the Transactions Admin Page list table.
428
-             * List display can be turned back on via the following:
429
-             * add_filter(
430
-             *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
431
-             *     '__return_true'
432
-             * );
433
-             *
434
-             * @param boolean                 $display_failed_txns_list
435
-             * @param Transactions_Admin_Page $this
436
-             * @since 4.9.70.p
437
-             */
438
-            apply_filters(
439
-                'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
440
-                false,
441
-                $this
442
-            )
443
-        ) {
444
-            $this->_views['failed'] = [
445
-                'slug'  => 'failed',
446
-                'label' => esc_html__('Failed Transactions', 'event_espresso'),
447
-                'count' => 0,
448
-            ];
449
-        }
450
-    }
451
-
452
-
453
-    /**
454
-     * _set_transaction_object
455
-     * This sets the _transaction property for the transaction details screen
456
-     *
457
-     * @access private
458
-     * @return void
459
-     * @throws EE_Error
460
-     * @throws InvalidArgumentException
461
-     * @throws RuntimeException
462
-     * @throws InvalidDataTypeException
463
-     * @throws InvalidInterfaceException
464
-     * @throws ReflectionException
465
-     */
466
-    private function _set_transaction_object()
467
-    {
468
-        if ($this->_transaction instanceof EE_Transaction) {
469
-            return;
470
-        } //get out we've already set the object
471
-
472
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
473
-
474
-        // get transaction object
475
-        $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
476
-        $this->_session     = $this->_transaction instanceof EE_Transaction
477
-            ? $this->_transaction->session_data()
478
-            : null;
479
-        if ($this->_transaction instanceof EE_Transaction) {
480
-            $this->_transaction->verify_abandoned_transaction_status();
481
-        }
482
-
483
-        if (! $this->_transaction instanceof EE_Transaction) {
484
-            $error_msg = sprintf(
485
-                esc_html__(
486
-                    'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
487
-                    'event_espresso'
488
-                ),
489
-                $TXN_ID
490
-            );
491
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
492
-        }
493
-    }
494
-
495
-
496
-    /**
497
-     *    _transaction_legend_items
498
-     *
499
-     * @access protected
500
-     * @return array
501
-     * @throws EE_Error
502
-     * @throws InvalidArgumentException
503
-     * @throws ReflectionException
504
-     * @throws InvalidDataTypeException
505
-     * @throws InvalidInterfaceException
506
-     */
507
-    protected function _transaction_legend_items()
508
-    {
509
-        EE_Registry::instance()->load_helper('MSG_Template');
510
-        $items = [];
511
-
512
-        if (
513
-            EE_Registry::instance()->CAP->current_user_can(
514
-                'ee_read_global_messages',
515
-                'view_filtered_messages'
516
-            )
517
-        ) {
518
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
519
-            if (
520
-                is_array($related_for_icon)
521
-                && isset($related_for_icon['css_class'], $related_for_icon['label'])
522
-            ) {
523
-                $items['view_related_messages'] = [
524
-                    'class' => $related_for_icon['css_class'],
525
-                    'desc'  => $related_for_icon['label'],
526
-                ];
527
-            }
528
-        }
529
-
530
-        $items = apply_filters(
531
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
532
-            array_merge(
533
-                $items,
534
-                [
535
-                    'view_details'          => [
536
-                        'class' => 'dashicons dashicons-cart',
537
-                        'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
538
-                    ],
539
-                    'view_invoice'          => [
540
-                        'class' => 'dashicons dashicons-media-spreadsheet',
541
-                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
542
-                    ],
543
-                    'view_receipt'          => [
544
-                        'class' => 'dashicons dashicons-media-default',
545
-                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
546
-                    ],
547
-                    'view_registration'     => [
548
-                        'class' => 'dashicons dashicons-clipboard',
549
-                        'desc'  => esc_html__('View Registration Details', 'event_espresso'),
550
-                    ],
551
-                    'payment_overview_link' => [
552
-                        'class' => 'dashicons dashicons-money',
553
-                        'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
554
-                    ],
555
-                ]
556
-            )
557
-        );
558
-
559
-        if (
560
-            EEH_MSG_Template::is_mt_active('payment_reminder')
561
-            && EE_Registry::instance()->CAP->current_user_can(
562
-                'ee_send_message',
563
-                'espresso_transactions_send_payment_reminder'
564
-            )
565
-        ) {
566
-            $items['send_payment_reminder'] = [
567
-                'class' => 'dashicons dashicons-email-alt',
568
-                'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
569
-            ];
570
-        } else {
571
-            $items['blank*'] = [
572
-                'class' => '',
573
-                'desc'  => '',
574
-            ];
575
-        }
576
-        $more_items = apply_filters(
577
-            'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
578
-            [
579
-                'overpaid'   => [
580
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
581
-                    'desc'  => EEH_Template::pretty_status(
582
-                        EEM_Transaction::overpaid_status_code,
583
-                        false,
584
-                        'sentence'
585
-                    ),
586
-                ],
587
-                'complete'   => [
588
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
589
-                    'desc'  => EEH_Template::pretty_status(
590
-                        EEM_Transaction::complete_status_code,
591
-                        false,
592
-                        'sentence'
593
-                    ),
594
-                ],
595
-                'incomplete' => [
596
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
597
-                    'desc'  => EEH_Template::pretty_status(
598
-                        EEM_Transaction::incomplete_status_code,
599
-                        false,
600
-                        'sentence'
601
-                    ),
602
-                ],
603
-                'abandoned'  => [
604
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
605
-                    'desc'  => EEH_Template::pretty_status(
606
-                        EEM_Transaction::abandoned_status_code,
607
-                        false,
608
-                        'sentence'
609
-                    ),
610
-                ],
611
-                'failed'     => [
612
-                    'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
613
-                    'desc'  => EEH_Template::pretty_status(
614
-                        EEM_Transaction::failed_status_code,
615
-                        false,
616
-                        'sentence'
617
-                    ),
618
-                ],
619
-            ]
620
-        );
621
-
622
-        return array_merge($items, $more_items);
623
-    }
624
-
625
-
626
-    /**
627
-     *    _transactions_overview_list_table
628
-     *
629
-     * @access protected
630
-     * @return void
631
-     * @throws DomainException
632
-     * @throws EE_Error
633
-     * @throws InvalidArgumentException
634
-     * @throws InvalidDataTypeException
635
-     * @throws InvalidInterfaceException
636
-     * @throws ReflectionException
637
-     */
638
-    protected function _transactions_overview_list_table()
639
-    {
640
-        $this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
641
-
642
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
643
-        $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
644
-        $this->_template_args['admin_page_header'] = $event instanceof EE_Event
645
-            ? sprintf(
646
-                esc_html__('%sViewing Transactions for the Event: %s%s', 'event_espresso'),
647
-                '<h3>',
648
-                '<a href="'
649
-                . EE_Admin_Page::add_query_args_and_nonce(
650
-                    ['action' => 'edit', 'post' => $event->ID()],
651
-                    EVENTS_ADMIN_URL
652
-                )
653
-                . '" title="'
654
-                . esc_attr__('Click to Edit event', 'event_espresso')
655
-                . '">' . $event->name() . '</a>',
656
-                '</h3>'
657
-            )
658
-            : '';
659
-        $this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
660
-        $this->display_admin_list_table_page_with_no_sidebar();
661
-    }
662
-
663
-
664
-    /**
665
-     *    _transaction_details
666
-     * generates HTML for the View Transaction Details Admin page
667
-     *
668
-     * @access protected
669
-     * @return void
670
-     * @throws DomainException
671
-     * @throws EE_Error
672
-     * @throws InvalidArgumentException
673
-     * @throws InvalidDataTypeException
674
-     * @throws InvalidInterfaceException
675
-     * @throws RuntimeException
676
-     * @throws ReflectionException
677
-     */
678
-    protected function _transaction_details()
679
-    {
680
-        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
681
-
682
-        $this->_set_transaction_status_array();
683
-
684
-        $this->_template_args                      = [];
685
-        $this->_template_args['transactions_page'] = $this->_wp_page_slug;
686
-
687
-        $this->_set_transaction_object();
688
-
689
-        if (! $this->_transaction instanceof EE_Transaction) {
690
-            return;
691
-        }
692
-
693
-        $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
694
-        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
695
-
696
-        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
697
-        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
698
-
699
-        $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ];
700
-        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
701
-        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID();
702
-
703
-        $this->_template_args['grand_total'] = $this->_transaction->total();
704
-        $this->_template_args['total_paid']  = $this->_transaction->paid();
705
-
706
-        $amount_due                         = $this->_transaction->total() - $this->_transaction->paid();
707
-        $this->_template_args['amount_due'] = EEH_Template::format_currency(
708
-            $amount_due,
709
-            true
710
-        );
711
-        if (EE_Registry::instance()->CFG->currency->sign_b4) {
712
-            $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
713
-                                                  . $this->_template_args['amount_due'];
714
-        } else {
715
-            $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
716
-        }
717
-        $this->_template_args['amount_due_class'] = '';
718
-
719
-        if ($this->_transaction->paid() === $this->_transaction->total()) {
720
-            // paid in full
721
-            $this->_template_args['amount_due'] = false;
722
-        } elseif ($this->_transaction->paid() > $this->_transaction->total()) {
723
-            // overpaid
724
-            $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
725
-        } elseif ($this->_transaction->total() > (float) 0) {
726
-            if ($this->_transaction->paid() > (float) 0) {
727
-                // monies owing
728
-                $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
729
-            } elseif ($this->_transaction->paid() === (float) 0) {
730
-                // no payments made yet
731
-                $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
732
-            }
733
-        } elseif ($this->_transaction->total() === (float) 0) {
734
-            // free event
735
-            $this->_template_args['amount_due'] = false;
736
-        }
737
-
738
-        $payment_method = $this->_transaction->payment_method();
739
-
740
-        $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
741
-            ? $payment_method->admin_name()
742
-            : esc_html__('Unknown', 'event_espresso');
743
-
744
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
745
-        // link back to overview
746
-        $this->_template_args['txn_overview_url'] = $this->request->getServerParam(
747
-            'HTTP_REFERER',
748
-            TXN_ADMIN_URL
749
-        );
750
-
751
-
752
-        // next link
753
-        $next_txn                                 = $this->_transaction->next(
754
-            null,
755
-            [['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
756
-            'TXN_ID'
757
-        );
758
-        $this->_template_args['next_transaction'] = $next_txn
759
-            ? $this->_next_link(
760
-                EE_Admin_Page::add_query_args_and_nonce(
761
-                    ['action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']],
762
-                    TXN_ADMIN_URL
763
-                ),
764
-                'dashicons dashicons-arrow-right ee-icon-size-22'
765
-            )
766
-            : '';
767
-        // previous link
768
-        $previous_txn                                 = $this->_transaction->previous(
769
-            null,
770
-            [['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
771
-            'TXN_ID'
772
-        );
773
-        $this->_template_args['previous_transaction'] = $previous_txn
774
-            ? $this->_previous_link(
775
-                EE_Admin_Page::add_query_args_and_nonce(
776
-                    ['action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']],
777
-                    TXN_ADMIN_URL
778
-                ),
779
-                'dashicons dashicons-arrow-left ee-icon-size-22'
780
-            )
781
-            : '';
782
-
783
-        $EVT_ID        = $this->request->getRequestParam('EVT_ID', 0, 'int');
784
-        $event_name    = $this->request->getRequestParam('event_name');
785
-        $redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
786
-
787
-        // were we just redirected here after adding a new registration ???
788
-        if ($EVT_ID && $event_name && $redirect_from) {
789
-            if (
790
-                EE_Registry::instance()->CAP->current_user_can(
791
-                    'ee_edit_registrations',
792
-                    'espresso_registrations_new_registration',
793
-                    $EVT_ID
794
-                )
795
-            ) {
796
-                $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
797
-                $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
798
-                    [
799
-                        'page'     => 'espresso_registrations',
800
-                        'action'   => 'new_registration',
801
-                        'return'   => 'default',
802
-                        'TXN_ID'   => $this->_transaction->ID(),
803
-                        'event_id' => $EVT_ID,
804
-                    ],
805
-                    REG_ADMIN_URL
806
-                );
807
-                $this->_admin_page_title .= '">';
808
-
809
-                $this->_admin_page_title .= sprintf(
810
-                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
811
-                    htmlentities(urldecode($event_name), ENT_QUOTES, 'UTF-8')
812
-                );
813
-                $this->_admin_page_title .= '</a>';
814
-            }
815
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
816
-        }
817
-        // grab messages at the last second
818
-        $this->_template_args['notices'] = EE_Error::get_notices();
819
-        // path to template
820
-        $template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
821
-        $this->_template_args['admin_page_header'] = EEH_Template::display_template(
822
-            $template_path,
823
-            $this->_template_args,
824
-            true
825
-        );
826
-
827
-        // the details template wrapper
828
-        $this->display_admin_page_with_sidebar();
829
-    }
830
-
831
-
832
-    /**
833
-     *        _transaction_details_metaboxes
834
-     *
835
-     * @access protected
836
-     * @return void
837
-     * @throws EE_Error
838
-     * @throws InvalidArgumentException
839
-     * @throws InvalidDataTypeException
840
-     * @throws InvalidInterfaceException
841
-     * @throws RuntimeException
842
-     * @throws ReflectionException
843
-     */
844
-    protected function _transaction_details_metaboxes()
845
-    {
846
-
847
-        $this->_set_transaction_object();
848
-
849
-        if (! $this->_transaction instanceof EE_Transaction) {
850
-            return;
851
-        }
852
-        add_meta_box(
853
-            'edit-txn-details-mbox',
854
-            esc_html__('Transaction Details', 'event_espresso'),
855
-            [$this, 'txn_details_meta_box'],
856
-            $this->_wp_page_slug,
857
-            'normal',
858
-            'high'
859
-        );
860
-        add_meta_box(
861
-            'edit-txn-attendees-mbox',
862
-            esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
863
-            [$this, 'txn_attendees_meta_box'],
864
-            $this->_wp_page_slug,
865
-            'normal',
866
-            'high',
867
-            ['TXN_ID' => $this->_transaction->ID()]
868
-        );
869
-        add_meta_box(
870
-            'edit-txn-registrant-mbox',
871
-            esc_html__('Primary Contact', 'event_espresso'),
872
-            [$this, 'txn_registrant_side_meta_box'],
873
-            $this->_wp_page_slug,
874
-            'side',
875
-            'high'
876
-        );
877
-        add_meta_box(
878
-            'edit-txn-billing-info-mbox',
879
-            esc_html__('Billing Information', 'event_espresso'),
880
-            [$this, 'txn_billing_info_side_meta_box'],
881
-            $this->_wp_page_slug,
882
-            'side',
883
-            'high'
884
-        );
885
-    }
886
-
887
-
888
-    /**
889
-     * Callback for transaction actions metabox.
890
-     *
891
-     * @param EE_Transaction|null $transaction
892
-     * @return string
893
-     * @throws DomainException
894
-     * @throws EE_Error
895
-     * @throws InvalidArgumentException
896
-     * @throws InvalidDataTypeException
897
-     * @throws InvalidInterfaceException
898
-     * @throws ReflectionException
899
-     * @throws RuntimeException
900
-     */
901
-    public function getActionButtons(EE_Transaction $transaction = null)
902
-    {
903
-        $content = '';
904
-        $actions = [];
905
-        if (! $transaction instanceof EE_Transaction) {
906
-            return $content;
907
-        }
908
-        /** @var EE_Registration $primary_registration */
909
-        $primary_registration = $transaction->primary_registration();
910
-        $attendee             = $primary_registration instanceof EE_Registration
911
-            ? $primary_registration->attendee()
912
-            : null;
913
-
914
-        if (
915
-            $attendee instanceof EE_Attendee
916
-            && EE_Registry::instance()->CAP->current_user_can(
917
-                'ee_send_message',
918
-                'espresso_transactions_send_payment_reminder'
919
-            )
920
-        ) {
921
-            $actions['payment_reminder'] =
922
-                EEH_MSG_Template::is_mt_active('payment_reminder')
923
-                && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code
924
-                && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code
925
-                    ? EEH_Template::get_button_or_link(
926
-                        EE_Admin_Page::add_query_args_and_nonce(
927
-                            [
928
-                            'action'      => 'send_payment_reminder',
929
-                            'TXN_ID'      => $this->_transaction->ID(),
930
-                            'redirect_to' => 'view_transaction',
931
-                            ],
932
-                            TXN_ADMIN_URL
933
-                        ),
934
-                        esc_html__(' Send Payment Reminder', 'event_espresso'),
935
-                        'button secondary-button',
936
-                        'dashicons dashicons-email-alt'
937
-                    )
938
-                    : '';
939
-        }
940
-
941
-        if (
942
-            EE_Registry::instance()->CAP->current_user_can(
943
-                'ee_edit_payments',
944
-                'espresso_transactions_recalculate_line_items'
945
-            )
946
-        ) {
947
-            $actions['recalculate_line_items'] = EEH_Template::get_button_or_link(
948
-                EE_Admin_Page::add_query_args_and_nonce(
949
-                    [
950
-                        'action'      => 'espresso_recalculate_line_items',
951
-                        'TXN_ID'      => $this->_transaction->ID(),
952
-                        'redirect_to' => 'view_transaction',
953
-                    ],
954
-                    TXN_ADMIN_URL
955
-                ),
956
-                esc_html__(' Recalculate Taxes and Total', 'event_espresso'),
957
-                'button secondary-button',
958
-                'dashicons dashicons-update'
959
-            );
960
-        }
961
-
962
-        if (
963
-            $primary_registration instanceof EE_Registration
964
-            && EEH_MSG_Template::is_mt_active('receipt')
965
-        ) {
966
-            $actions['receipt'] = EEH_Template::get_button_or_link(
967
-                $primary_registration->receipt_url(),
968
-                esc_html__('View Receipt', 'event_espresso'),
969
-                'button secondary-button',
970
-                'dashicons dashicons-media-default'
971
-            );
972
-        }
973
-
974
-        if (
975
-            $primary_registration instanceof EE_Registration
976
-            && EEH_MSG_Template::is_mt_active('invoice')
977
-        ) {
978
-            $actions['invoice'] = EEH_Template::get_button_or_link(
979
-                $primary_registration->invoice_url(),
980
-                esc_html__('View Invoice', 'event_espresso'),
981
-                'button secondary-button',
982
-                'dashicons dashicons-media-spreadsheet'
983
-            );
984
-        }
985
-        $actions = array_filter(
986
-            apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
987
-        );
988
-        if ($actions) {
989
-            $content = '<ul>';
990
-            $content .= '<li>' . implode('</li><li>', $actions) . '</li>';
991
-            $content .= '</uL>';
992
-        }
993
-        return $content;
994
-    }
995
-
996
-
997
-    /**
998
-     * txn_details_meta_box
999
-     * generates HTML for the Transaction main meta box
1000
-     *
1001
-     * @return void
1002
-     * @throws DomainException
1003
-     * @throws EE_Error
1004
-     * @throws InvalidArgumentException
1005
-     * @throws InvalidDataTypeException
1006
-     * @throws InvalidInterfaceException
1007
-     * @throws RuntimeException
1008
-     * @throws ReflectionException
1009
-     */
1010
-    public function txn_details_meta_box()
1011
-    {
1012
-        $this->_set_transaction_object();
1013
-        $this->_template_args['TXN_ID']              = $this->_transaction->ID();
1014
-        $this->_template_args['attendee']            =
1015
-            $this->_transaction->primary_registration() instanceof EE_Registration
1016
-                ? $this->_transaction->primary_registration()->attendee()
1017
-                : null;
1018
-        $this->_template_args['can_edit_payments']   = EE_Registry::instance()->CAP->current_user_can(
1019
-            'ee_edit_payments',
1020
-            'apply_payment_or_refund_from_registration_details'
1021
-        );
1022
-        $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1023
-            'ee_delete_payments',
1024
-            'delete_payment_from_registration_details'
1025
-        );
1026
-
1027
-        // get line table
1028
-        EEH_Autoloader::register_line_item_display_autoloaders();
1029
-        $Line_Item_Display                       = new EE_Line_Item_Display(
1030
-            'admin_table',
1031
-            'EE_Admin_Table_Line_Item_Display_Strategy'
1032
-        );
1033
-        $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1034
-            $this->_transaction->total_line_item()
1035
-        );
1036
-        $this->_template_args['REG_code']        =
1037
-            $this->_transaction->primary_registration() instanceof EE_Registration
1038
-                ? $this->_transaction->primary_registration()->reg_code()
1039
-                : null;
1040
-        // process taxes
1041
-        $taxes                         = $this->_transaction->line_items([['LIN_type' => EEM_Line_Item::type_tax]]);
1042
-        $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1043
-
1044
-        $this->_template_args['grand_total']     = EEH_Template::format_currency(
1045
-            $this->_transaction->total(),
1046
-            false,
1047
-            false
1048
-        );
1049
-        $this->_template_args['grand_raw_total'] = $this->_transaction->total();
1050
-        $this->_template_args['TXN_status']      = $this->_transaction->status_ID();
1051
-
1052
-        // process payment details
1053
-        $payments = $this->_transaction->payments();
1054
-        if (! empty($payments)) {
1055
-            $this->_template_args['payments']              = $payments;
1056
-            $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1057
-        } else {
1058
-            $this->_template_args['payments']              = false;
1059
-            $this->_template_args['existing_reg_payments'] = [];
1060
-        }
1061
-
1062
-        $this->_template_args['edit_payment_url']   = add_query_arg(['action' => 'edit_payment'], TXN_ADMIN_URL);
1063
-        $this->_template_args['delete_payment_url'] = add_query_arg(
1064
-            ['action' => 'espresso_delete_payment'],
1065
-            TXN_ADMIN_URL
1066
-        );
1067
-
1068
-        if (isset($txn_details['invoice_number'])) {
1069
-            $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1070
-            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1071
-                'Invoice Number',
1072
-                'event_espresso'
1073
-            );
1074
-        }
1075
-
1076
-        $this->_template_args['txn_details']['registration_session']['value'] =
1077
-            $this->_transaction->primary_registration() instanceof EE_Registration
1078
-                ? $this->_transaction->primary_registration()->session_ID()
1079
-                : null;
1080
-        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1081
-            'Registration Session',
1082
-            'event_espresso'
1083
-        );
1084
-
1085
-        $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1086
-            ? $this->_session['ip_address']
1087
-            : '';
1088
-        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1089
-            'Transaction placed from IP',
1090
-            'event_espresso'
1091
-        );
1092
-
1093
-        $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1094
-            ? $this->_session['user_agent']
1095
-            : '';
1096
-        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1097
-            'Registrant User Agent',
1098
-            'event_espresso'
1099
-        );
1100
-
1101
-        $reg_steps = '<ul>';
1102
-        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1103
-            if ($reg_step_status === true) {
1104
-                $reg_steps .= '<li style="color:#70cc50">'
1105
-                              . sprintf(
1106
-                                  esc_html__('%1$s : Completed', 'event_espresso'),
1107
-                                  ucwords(str_replace('_', ' ', $reg_step))
1108
-                              )
1109
-                              . '</li>';
1110
-            } elseif ($reg_step_status !== false && is_numeric($reg_step_status)) {
1111
-                $reg_steps .= '<li style="color:#2EA2CC">'
1112
-                              . sprintf(
1113
-                                  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1114
-                                  ucwords(str_replace('_', ' ', $reg_step)),
1115
-                                  date(
1116
-                                      get_option('date_format') . ' ' . get_option('time_format'),
1117
-                                      $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1118
-                                  )
1119
-                              )
1120
-                              . '</li>';
1121
-            } else {
1122
-                $reg_steps .= '<li style="color:#E76700">'
1123
-                              . sprintf(
1124
-                                  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1125
-                                  ucwords(str_replace('_', ' ', $reg_step))
1126
-                              )
1127
-                              . '</li>';
1128
-            }
1129
-        }
1130
-        $reg_steps                                                 .= '</ul>';
1131
-        $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1132
-        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1133
-            'Registration Step Progress',
1134
-            'event_espresso'
1135
-        );
1136
-
1137
-
1138
-        $this->_get_registrations_to_apply_payment_to();
1139
-        $this->_get_payment_methods($payments);
1140
-        $this->_get_payment_status_array();
1141
-        $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1142
-
1143
-        $this->_template_args['transaction_form_url']    = add_query_arg(
1144
-            [
1145
-                'action'  => 'edit_transaction',
1146
-                'process' => 'transaction',
1147
-            ],
1148
-            TXN_ADMIN_URL
1149
-        );
1150
-        $this->_template_args['apply_payment_form_url']  = add_query_arg(
1151
-            [
1152
-                'page'   => 'espresso_transactions',
1153
-                'action' => 'espresso_apply_payment',
1154
-            ],
1155
-            WP_AJAX_URL
1156
-        );
1157
-        $this->_template_args['delete_payment_form_url'] = add_query_arg(
1158
-            [
1159
-                'page'   => 'espresso_transactions',
1160
-                'action' => 'espresso_delete_payment',
1161
-            ],
1162
-            WP_AJAX_URL
1163
-        );
1164
-
1165
-        $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1166
-
1167
-        // 'espresso_delete_payment_nonce'
1168
-
1169
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1170
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1171
-    }
1172
-
1173
-
1174
-    /**
1175
-     * _get_registration_payment_IDs
1176
-     *    generates an array of Payment IDs and their corresponding Registration IDs
1177
-     *
1178
-     * @access protected
1179
-     * @param EE_Payment[] $payments
1180
-     * @return array
1181
-     * @throws EE_Error
1182
-     * @throws InvalidArgumentException
1183
-     * @throws InvalidDataTypeException
1184
-     * @throws InvalidInterfaceException
1185
-     * @throws ReflectionException
1186
-     */
1187
-    protected function _get_registration_payment_IDs($payments = [])
1188
-    {
1189
-        $existing_reg_payments = [];
1190
-        // get all reg payments for these payments
1191
-        $reg_payments = EEM_Registration_Payment::instance()->get_all(
1192
-            [
1193
-                [
1194
-                    'PAY_ID' => [
1195
-                        'IN',
1196
-                        array_keys($payments),
1197
-                    ],
1198
-                ],
1199
-            ]
1200
-        );
1201
-        if (! empty($reg_payments)) {
1202
-            foreach ($payments as $payment) {
1203
-                if (! $payment instanceof EE_Payment) {
1204
-                    continue;
1205
-                } elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1206
-                    $existing_reg_payments[ $payment->ID() ] = [];
1207
-                }
1208
-                foreach ($reg_payments as $reg_payment) {
1209
-                    if (
1210
-                        $reg_payment instanceof EE_Registration_Payment
1211
-                        && $reg_payment->payment_ID() === $payment->ID()
1212
-                    ) {
1213
-                        $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1214
-                    }
1215
-                }
1216
-            }
1217
-        }
1218
-
1219
-        return $existing_reg_payments;
1220
-    }
1221
-
1222
-
1223
-    /**
1224
-     * _get_registrations_to_apply_payment_to
1225
-     *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1226
-     * which allows the admin to only apply the payment to the specific registrations
1227
-     *
1228
-     * @access protected
1229
-     * @return void
1230
-     * @throws EE_Error
1231
-     * @throws InvalidArgumentException
1232
-     * @throws InvalidDataTypeException
1233
-     * @throws InvalidInterfaceException
1234
-     * @throws ReflectionException
1235
-     */
1236
-    protected function _get_registrations_to_apply_payment_to()
1237
-    {
1238
-        // we want any registration with an active status (ie: not deleted or cancelled)
1239
-        $query_params                      = [
1240
-            [
1241
-                'STS_ID' => [
1242
-                    'IN',
1243
-                    [
1244
-                        EEM_Registration::status_id_approved,
1245
-                        EEM_Registration::status_id_pending_payment,
1246
-                        EEM_Registration::status_id_not_approved,
1247
-                    ],
1248
-                ],
1249
-            ],
1250
-        ];
1251
-        $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
1252
-            '',
1253
-            'txn-admin-apply-payment-to-registrations-dv',
1254
-            '',
1255
-            'clear: both; margin: 1.5em 0 0; display: none;'
1256
-        );
1257
-        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1258
-        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1259
-        $registrations_to_apply_payment_to .= EEH_HTML::thead(
1260
-            EEH_HTML::tr(
1261
-                EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1262
-                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1263
-                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1264
-                EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1265
-                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1266
-                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1267
-                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1268
-            )
1269
-        );
1270
-        $registrations_to_apply_payment_to .= EEH_HTML::tbody();
1271
-        // get registrations for TXN
1272
-        $registrations         = $this->_transaction->registrations($query_params);
1273
-        $existing_reg_payments = $this->_template_args['existing_reg_payments'];
1274
-        foreach ($registrations as $registration) {
1275
-            if ($registration instanceof EE_Registration) {
1276
-                $attendee_name                     = $registration->attendee() instanceof EE_Attendee
1277
-                    ? $registration->attendee()->full_name()
1278
-                    : esc_html__('Unknown Attendee', 'event_espresso');
1279
-                $owing                             = $registration->final_price() - $registration->paid();
1280
-                $taxable                           = $registration->ticket()->taxable()
1281
-                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1282
-                    : '';
1283
-                $checked                           = empty($existing_reg_payments)
1284
-                                                     || in_array($registration->ID(), $existing_reg_payments, true)
1285
-                    ? ' checked="checked"'
1286
-                    : '';
1287
-                $disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1288
-                $registrations_to_apply_payment_to .= EEH_HTML::tr(
1289
-                    EEH_HTML::td($registration->ID()) .
1290
-                    EEH_HTML::td($attendee_name) .
1291
-                    EEH_HTML::td(
1292
-                        $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1293
-                    ) .
1294
-                    EEH_HTML::td($registration->event_name()) .
1295
-                    EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1296
-                    EEH_HTML::td(
1297
-                        EEH_Template::format_currency($owing),
1298
-                        '',
1299
-                        'txn-admin-payment-owing-td jst-cntr'
1300
-                    ) .
1301
-                    EEH_HTML::td(
1302
-                        '<input type="checkbox" value="' . $registration->ID()
1303
-                        . '" name="txn_admin_payment[registrations]"'
1304
-                        . $checked . $disabled . '>',
1305
-                        '',
1306
-                        'jst-cntr'
1307
-                    ),
1308
-                    'apply-payment-registration-row-' . $registration->ID()
1309
-                );
1310
-            }
1311
-        }
1312
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1313
-        $registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1314
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1315
-        $registrations_to_apply_payment_to                         .= EEH_HTML::p(
1316
-            esc_html__(
1317
-                '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.',
1318
-                'event_espresso'
1319
-            ),
1320
-            '',
1321
-            'clear description'
1322
-        );
1323
-        $registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1324
-        $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1325
-    }
1326
-
1327
-
1328
-    /**
1329
-     * _get_reg_status_selection
1330
-     *
1331
-     * @return void
1332
-     * @throws EE_Error
1333
-     * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1334
-     *         instead of events.
1335
-     * @access protected
1336
-     */
1337
-    protected function _get_reg_status_selection()
1338
-    {
1339
-        // first get all possible statuses
1340
-        $statuses = EEM_Registration::reg_status_array([], true);
1341
-        // let's add a "don't change" option.
1342
-        $status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1343
-        $status_array                                        = array_merge($status_array, $statuses);
1344
-        $this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1345
-            'txn_reg_status_change[reg_status]',
1346
-            $status_array,
1347
-            'NAN',
1348
-            'id="txn-admin-payment-reg-status-inp"',
1349
-            'txn-reg-status-change-reg-status'
1350
-        );
1351
-        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1352
-            'delete_txn_reg_status_change[reg_status]',
1353
-            $status_array,
1354
-            'NAN',
1355
-            'delete-txn-admin-payment-reg-status-inp',
1356
-            'delete-txn-reg-status-change-reg-status'
1357
-        );
1358
-    }
1359
-
1360
-
1361
-    /**
1362
-     *    _get_payment_methods
1363
-     * Gets all the payment methods available generally, or the ones that are already
1364
-     * selected on these payments (in case their payment methods are no longer active).
1365
-     * Has the side-effect of updating the template args' payment_methods item
1366
-     *
1367
-     * @access private
1368
-     * @param EE_Payment[] to show on this page
1369
-     * @return void
1370
-     * @throws EE_Error
1371
-     * @throws InvalidArgumentException
1372
-     * @throws InvalidDataTypeException
1373
-     * @throws InvalidInterfaceException
1374
-     * @throws ReflectionException
1375
-     */
1376
-    private function _get_payment_methods($payments = [])
1377
-    {
1378
-        $payment_methods_of_payments = [];
1379
-        foreach ($payments as $payment) {
1380
-            if ($payment instanceof EE_Payment) {
1381
-                $payment_methods_of_payments[] = $payment->ID();
1382
-            }
1383
-        }
1384
-        if ($payment_methods_of_payments) {
1385
-            $query_args = [
1386
-                [
1387
-                    'OR*payment_method_for_payment' => [
1388
-                        'PMD_ID'    => ['IN', $payment_methods_of_payments],
1389
-                        'PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%'],
1390
-                    ],
1391
-                ],
1392
-            ];
1393
-        } else {
1394
-            $query_args = [['PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%']]];
1395
-        }
1396
-        $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1397
-    }
1398
-
1399
-
1400
-    /**
1401
-     * txn_attendees_meta_box
1402
-     *    generates HTML for the Attendees Transaction main meta box
1403
-     *
1404
-     * @access public
1405
-     * @param WP_Post $post
1406
-     * @param array   $metabox
1407
-     * @return void
1408
-     * @throws DomainException
1409
-     * @throws EE_Error
1410
-     * @throws InvalidArgumentException
1411
-     * @throws InvalidDataTypeException
1412
-     * @throws InvalidInterfaceException
1413
-     * @throws ReflectionException
1414
-     */
1415
-    public function txn_attendees_meta_box($post, $metabox = ['args' => []])
1416
-    {
1417
-
1418
-        /** @noinspection NonSecureExtractUsageInspection */
1419
-        extract($metabox['args']);
1420
-        $this->_template_args['post']            = $post;
1421
-        $this->_template_args['event_attendees'] = [];
1422
-        // process items in cart
1423
-        $line_items = $this->_transaction->get_many_related(
1424
-            'Line_Item',
1425
-            [['LIN_type' => 'line-item']]
1426
-        );
1427
-        if (! empty($line_items)) {
1428
-            foreach ($line_items as $item) {
1429
-                if ($item instanceof EE_Line_Item) {
1430
-                    switch ($item->OBJ_type()) {
1431
-                        case 'Event':
1432
-                            break;
1433
-                        case 'Ticket':
1434
-                            $ticket = $item->ticket();
1435
-                            // right now we're only handling tickets here.
1436
-                            // Cause its expected that only tickets will have attendees right?
1437
-                            if (! $ticket instanceof EE_Ticket) {
1438
-                                break;
1439
-                            }
1440
-                            try {
1441
-                                $event_name = $ticket->get_event_name();
1442
-                            } catch (Exception $e) {
1443
-                                EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1444
-                                $event_name = esc_html__('Unknown Event', 'event_espresso');
1445
-                            }
1446
-                            $event_name   .= ' - ' . $item->name();
1447
-                            $ticket_price = EEH_Template::format_currency($item->unit_price());
1448
-                            // now get all of the registrations for this transaction that use this ticket
1449
-                            $registrations = $ticket->registrations(
1450
-                                [['TXN_ID' => $this->_transaction->ID()]]
1451
-                            );
1452
-                            foreach ($registrations as $registration) {
1453
-                                if (! $registration instanceof EE_Registration) {
1454
-                                    break;
1455
-                                }
1456
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1457
-                                    = $registration->status_ID();
1458
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1459
-                                    = $registration->count();
1460
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1461
-                                    = $event_name;
1462
-                                $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1463
-                                    = $ticket_price;
1464
-                                // attendee info
1465
-                                $attendee = $registration->get_first_related('Attendee');
1466
-                                if ($attendee instanceof EE_Attendee) {
1467
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1468
-                                        = $attendee->ID();
1469
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1470
-                                        = $attendee->full_name();
1471
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']
1472
-                                        = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1473
-                                          . esc_html__(
1474
-                                              ' Event',
1475
-                                              'event_espresso'
1476
-                                          )
1477
-                                          . '">' . $attendee->email() . '</a>';
1478
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']
1479
-                                        = EEH_Address::format($attendee, 'inline', false, false);
1480
-                                } else {
1481
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['att_id']   = '';
1482
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1483
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['email']    = '';
1484
-                                    $this->_template_args['event_attendees'][ $registration->ID() ]['address']  = '';
1485
-                                }
1486
-                            }
1487
-                            break;
1488
-                    }
1489
-                }
1490
-            }
1491
-
1492
-            $this->_template_args['transaction_form_url'] = add_query_arg(
1493
-                [
1494
-                    'action'  => 'edit_transaction',
1495
-                    'process' => 'attendees',
1496
-                ],
1497
-                TXN_ADMIN_URL
1498
-            );
1499
-            echo EEH_Template::display_template(
1500
-                TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1501
-                $this->_template_args,
1502
-                true
1503
-            );
1504
-        } else {
1505
-            printf(
1506
-                esc_html__(
1507
-                    '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1508
-                    'event_espresso'
1509
-                ),
1510
-                '<p class="important-notice">',
1511
-                '</p>'
1512
-            );
1513
-        }
1514
-    }
1515
-
1516
-
1517
-    /**
1518
-     * txn_registrant_side_meta_box
1519
-     * generates HTML for the Edit Transaction side meta box
1520
-     *
1521
-     * @access public
1522
-     * @return void
1523
-     * @throws DomainException
1524
-     * @throws EE_Error
1525
-     * @throws InvalidArgumentException
1526
-     * @throws InvalidDataTypeException
1527
-     * @throws InvalidInterfaceException
1528
-     * @throws ReflectionException
1529
-     */
1530
-    public function txn_registrant_side_meta_box()
1531
-    {
1532
-        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1533
-            ? $this->_transaction->primary_registration()->get_first_related('Attendee')
1534
-            : null;
1535
-        if (! $primary_att instanceof EE_Attendee) {
1536
-            $this->_template_args['no_attendee_message'] = esc_html__(
1537
-                'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1538
-                'event_espresso'
1539
-            );
1540
-            $primary_att                           = EEM_Attendee::instance()->create_default_object();
1541
-        }
1542
-        $this->_template_args['ATT_ID']            = $primary_att->ID();
1543
-        $this->_template_args['prime_reg_fname']   = $primary_att->fname();
1544
-        $this->_template_args['prime_reg_lname']   = $primary_att->lname();
1545
-        $this->_template_args['prime_reg_email']   = $primary_att->email();
1546
-        $this->_template_args['prime_reg_phone']   = $primary_att->phone();
1547
-        $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1548
-            [
1549
-                'action' => 'edit_attendee',
1550
-                'post'   => $primary_att->ID(),
1551
-            ],
1552
-            REG_ADMIN_URL
1553
-        );
1554
-        // get formatted address for registrant
1555
-        $this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1556
-        echo EEH_Template::display_template(
1557
-            TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1558
-            $this->_template_args,
1559
-            true
1560
-        );
1561
-    }
1562
-
1563
-
1564
-    /**
1565
-     * txn_billing_info_side_meta_box
1566
-     *    generates HTML for the Edit Transaction side meta box
1567
-     *
1568
-     * @access public
1569
-     * @return void
1570
-     * @throws DomainException
1571
-     * @throws EE_Error
1572
-     * @throws ReflectionException
1573
-     */
1574
-    public function txn_billing_info_side_meta_box()
1575
-    {
1576
-
1577
-        $this->_template_args['billing_form']     = $this->_transaction->billing_info();
1578
-        $this->_template_args['billing_form_url'] = add_query_arg(
1579
-            ['action' => 'edit_transaction', 'process' => 'billing'],
1580
-            TXN_ADMIN_URL
1581
-        );
1582
-
1583
-        $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1584
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1585
-    }
1586
-
1587
-
1588
-    /**
1589
-     * apply_payments_or_refunds
1590
-     *    registers a payment or refund made towards a transaction
1591
-     *
1592
-     * @access public
1593
-     * @return void
1594
-     * @throws EE_Error
1595
-     * @throws InvalidArgumentException
1596
-     * @throws ReflectionException
1597
-     * @throws RuntimeException
1598
-     * @throws InvalidDataTypeException
1599
-     * @throws InvalidInterfaceException
1600
-     */
1601
-    public function apply_payments_or_refunds()
1602
-    {
1603
-        $json_response_data = ['return_data' => false];
1604
-        $valid_data         = $this->_validate_payment_request_data();
1605
-        $has_access         = EE_Registry::instance()->CAP->current_user_can(
1606
-            'ee_edit_payments',
1607
-            'apply_payment_or_refund_from_registration_details'
1608
-        );
1609
-        if (! empty($valid_data) && $has_access) {
1610
-            $PAY_ID = $valid_data['PAY_ID'];
1611
-            // save  the new payment
1612
-            $payment = $this->_create_payment_from_request_data($valid_data);
1613
-            // get the TXN for this payment
1614
-            $transaction = $payment->transaction();
1615
-            // verify transaction
1616
-            if ($transaction instanceof EE_Transaction) {
1617
-                // calculate_total_payments_and_update_status
1618
-                $this->_process_transaction_payments($transaction);
1619
-                $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1620
-                $this->_remove_existing_registration_payments($payment, $PAY_ID);
1621
-                // apply payment to registrations (if applicable)
1622
-                if (! empty($REG_IDs)) {
1623
-                    $this->_update_registration_payments($transaction, $payment, $REG_IDs);
1624
-                    $this->_maybe_send_notifications();
1625
-                    // now process status changes for the same registrations
1626
-                    $this->_process_registration_status_change($transaction, $REG_IDs);
1627
-                }
1628
-                $this->_maybe_send_notifications($payment);
1629
-                // prepare to render page
1630
-                $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1631
-                do_action(
1632
-                    'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1633
-                    $transaction,
1634
-                    $payment
1635
-                );
1636
-            } else {
1637
-                EE_Error::add_error(
1638
-                    esc_html__(
1639
-                        'A valid Transaction for this payment could not be retrieved.',
1640
-                        'event_espresso'
1641
-                    ),
1642
-                    __FILE__,
1643
-                    __FUNCTION__,
1644
-                    __LINE__
1645
-                );
1646
-            }
1647
-        } elseif ($has_access) {
1648
-            EE_Error::add_error(
1649
-                esc_html__(
1650
-                    'The payment form data could not be processed. Please try again.',
1651
-                    'event_espresso'
1652
-                ),
1653
-                __FILE__,
1654
-                __FUNCTION__,
1655
-                __LINE__
1656
-            );
1657
-        } else {
1658
-            EE_Error::add_error(
1659
-                esc_html__(
1660
-                    'You do not have access to apply payments or refunds to a registration.',
1661
-                    'event_espresso'
1662
-                ),
1663
-                __FILE__,
1664
-                __FUNCTION__,
1665
-                __LINE__
1666
-            );
1667
-        }
1668
-        $notices              = EE_Error::get_notices(
1669
-            false,
1670
-            false,
1671
-            false
1672
-        );
1673
-        $this->_template_args = [
1674
-            'data'    => $json_response_data,
1675
-            'error'   => $notices['errors'],
1676
-            'success' => $notices['success'],
1677
-        ];
1678
-        $this->_return_json();
1679
-    }
1680
-
1681
-
1682
-    /**
1683
-     * _validate_payment_request_data
1684
-     *
1685
-     * @return array
1686
-     * @throws EE_Error
1687
-     * @throws InvalidArgumentException
1688
-     * @throws InvalidDataTypeException
1689
-     * @throws InvalidInterfaceException
1690
-     */
1691
-    protected function _validate_payment_request_data()
1692
-    {
1693
-        if (! $this->request->requestParamIsSet('txn_admin_payment')) {
1694
-            return [];
1695
-        }
1696
-        $payment_form = $this->_generate_payment_form_section();
1697
-        try {
1698
-            if ($payment_form->was_submitted()) {
1699
-                $payment_form->receive_form_submission();
1700
-                if (! $payment_form->is_valid()) {
1701
-                    $submission_error_messages = [];
1702
-                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1703
-                        if ($validation_error instanceof EE_Validation_Error) {
1704
-                            $form_input = $validation_error->get_form_section();
1705
-                            $submission_error_messages[] = sprintf(
1706
-                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1707
-                                $form_input instanceof EE_Form_Input_Base ? $form_input->html_label_text() : '',
1708
-                                $validation_error->getMessage()
1709
-                            );
1710
-                        }
1711
-                    }
1712
-                    EE_Error::add_error(
1713
-                        implode('<br />', $submission_error_messages),
1714
-                        __FILE__,
1715
-                        __FUNCTION__,
1716
-                        __LINE__
1717
-                    );
1718
-                    return [];
1719
-                }
1720
-            }
1721
-        } catch (EE_Error $e) {
1722
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1723
-            return [];
1724
-        }
1725
-
1726
-        return $payment_form->valid_data();
1727
-    }
1728
-
1729
-
1730
-    /**
1731
-     * _generate_payment_form_section
1732
-     *
1733
-     * @return EE_Form_Section_Proper
1734
-     * @throws EE_Error
1735
-     */
1736
-    protected function _generate_payment_form_section()
1737
-    {
1738
-        return new EE_Form_Section_Proper(
1739
-            [
1740
-                'name'        => 'txn_admin_payment',
1741
-                'subsections' => [
1742
-                    'PAY_ID'          => new EE_Text_Input(
1743
-                        [
1744
-                            'default'               => 0,
1745
-                            'required'              => false,
1746
-                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1747
-                            'validation_strategies' => [new EE_Int_Normalization()],
1748
-                        ]
1749
-                    ),
1750
-                    'TXN_ID'          => new EE_Text_Input(
1751
-                        [
1752
-                            'default'               => 0,
1753
-                            'required'              => true,
1754
-                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1755
-                            'validation_strategies' => [new EE_Int_Normalization()],
1756
-                        ]
1757
-                    ),
1758
-                    'type'            => new EE_Text_Input(
1759
-                        [
1760
-                            'default'               => 1,
1761
-                            'required'              => true,
1762
-                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1763
-                            'validation_strategies' => [new EE_Int_Normalization()],
1764
-                        ]
1765
-                    ),
1766
-                    'amount'          => new EE_Text_Input(
1767
-                        [
1768
-                            'default'               => 0,
1769
-                            'required'              => true,
1770
-                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1771
-                            'validation_strategies' => [new EE_Float_Normalization()],
1772
-                        ]
1773
-                    ),
1774
-                    'status'          => new EE_Text_Input(
1775
-                        [
1776
-                            'default'         => EEM_Payment::status_id_approved,
1777
-                            'required'        => true,
1778
-                            'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1779
-                        ]
1780
-                    ),
1781
-                    'PMD_ID'          => new EE_Text_Input(
1782
-                        [
1783
-                            'default'               => 2,
1784
-                            'required'              => true,
1785
-                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1786
-                            'validation_strategies' => [new EE_Int_Normalization()],
1787
-                        ]
1788
-                    ),
1789
-                    'date'            => new EE_Text_Input(
1790
-                        [
1791
-                            'default'         => time(),
1792
-                            'required'        => true,
1793
-                            'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1794
-                        ]
1795
-                    ),
1796
-                    'txn_id_chq_nmbr' => new EE_Text_Input(
1797
-                        [
1798
-                            'default'               => '',
1799
-                            'required'              => false,
1800
-                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1801
-                            'validation_strategies' => [
1802
-                                new EE_Max_Length_Validation_Strategy(
1803
-                                    esc_html__('Input too long', 'event_espresso'),
1804
-                                    100
1805
-                                ),
1806
-                            ],
1807
-                        ]
1808
-                    ),
1809
-                    'po_number'       => new EE_Text_Input(
1810
-                        [
1811
-                            'default'               => '',
1812
-                            'required'              => false,
1813
-                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1814
-                            'validation_strategies' => [
1815
-                                new EE_Max_Length_Validation_Strategy(
1816
-                                    esc_html__('Input too long', 'event_espresso'),
1817
-                                    100
1818
-                                ),
1819
-                            ],
1820
-                        ]
1821
-                    ),
1822
-                    'accounting'      => new EE_Text_Input(
1823
-                        [
1824
-                            'default'               => '',
1825
-                            'required'              => false,
1826
-                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1827
-                            'validation_strategies' => [
1828
-                                new EE_Max_Length_Validation_Strategy(
1829
-                                    esc_html__('Input too long', 'event_espresso'),
1830
-                                    100
1831
-                                ),
1832
-                            ],
1833
-                        ]
1834
-                    ),
1835
-                ],
1836
-            ]
1837
-        );
1838
-    }
1839
-
1840
-
1841
-    /**
1842
-     * _create_payment_from_request_data
1843
-     *
1844
-     * @param array $valid_data
1845
-     * @return EE_Payment
1846
-     * @throws EE_Error
1847
-     * @throws InvalidArgumentException
1848
-     * @throws InvalidDataTypeException
1849
-     * @throws InvalidInterfaceException
1850
-     * @throws ReflectionException
1851
-     */
1852
-    protected function _create_payment_from_request_data($valid_data)
1853
-    {
1854
-        $PAY_ID = $valid_data['PAY_ID'];
1855
-        // get payment amount
1856
-        $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1857
-        // payments have a type value of 1 and refunds have a type value of -1
1858
-        // so multiplying amount by type will give a positive value for payments, and negative values for refunds
1859
-        $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1860
-        // for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1861
-        $date    = $valid_data['date']
1862
-            ? preg_replace('/\s+/', ' ', $valid_data['date'])
1863
-            : date('Y-m-d g:i a', current_time('timestamp'));
1864
-        $payment = EE_Payment::new_instance(
1865
-            [
1866
-                'TXN_ID'              => $valid_data['TXN_ID'],
1867
-                'STS_ID'              => $valid_data['status'],
1868
-                'PAY_timestamp'       => $date,
1869
-                'PAY_source'          => EEM_Payment_Method::scope_admin,
1870
-                'PMD_ID'              => $valid_data['PMD_ID'],
1871
-                'PAY_amount'          => $amount,
1872
-                'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1873
-                'PAY_po_number'       => $valid_data['po_number'],
1874
-                'PAY_extra_accntng'   => $valid_data['accounting'],
1875
-                'PAY_details'         => $valid_data,
1876
-                'PAY_ID'              => $PAY_ID,
1877
-            ],
1878
-            '',
1879
-            ['Y-m-d', 'g:i a']
1880
-        );
1881
-
1882
-        if (! $payment->save()) {
1883
-            EE_Error::add_error(
1884
-                sprintf(
1885
-                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1886
-                    $payment->ID()
1887
-                ),
1888
-                __FILE__,
1889
-                __FUNCTION__,
1890
-                __LINE__
1891
-            );
1892
-        }
1893
-
1894
-        return $payment;
1895
-    }
1896
-
1897
-
1898
-    /**
1899
-     * _process_transaction_payments
1900
-     *
1901
-     * @param EE_Transaction $transaction
1902
-     * @return void
1903
-     * @throws EE_Error
1904
-     * @throws InvalidArgumentException
1905
-     * @throws ReflectionException
1906
-     * @throws InvalidDataTypeException
1907
-     * @throws InvalidInterfaceException
1908
-     */
1909
-    protected function _process_transaction_payments(EE_Transaction $transaction)
1910
-    {
1911
-        /** @type EE_Transaction_Payments $transaction_payments */
1912
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1913
-        // update the transaction with this payment
1914
-        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1915
-            EE_Error::add_success(
1916
-                esc_html__(
1917
-                    'The payment has been processed successfully.',
1918
-                    'event_espresso'
1919
-                ),
1920
-                __FILE__,
1921
-                __FUNCTION__,
1922
-                __LINE__
1923
-            );
1924
-        } else {
1925
-            EE_Error::add_error(
1926
-                esc_html__(
1927
-                    'The payment was processed successfully but the amount paid for the transaction was not updated.',
1928
-                    'event_espresso'
1929
-                ),
1930
-                __FILE__,
1931
-                __FUNCTION__,
1932
-                __LINE__
1933
-            );
1934
-        }
1935
-    }
1936
-
1937
-
1938
-    /**
1939
-     * _get_REG_IDs_to_apply_payment_to
1940
-     * returns a list of registration IDs that the payment will apply to
1941
-     *
1942
-     * @param EE_Payment $payment
1943
-     * @return array
1944
-     * @throws EE_Error
1945
-     * @throws InvalidArgumentException
1946
-     * @throws InvalidDataTypeException
1947
-     * @throws InvalidInterfaceException
1948
-     * @throws ReflectionException
1949
-     */
1950
-    protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1951
-    {
1952
-        // grab array of IDs for specific registrations to apply changes to
1953
-        $REG_IDs = $this->request->getRequestParam('txn_admin_payment[registrations]', [], 'int', true);
1954
-        // nothing specified ? then get all reg IDs
1955
-        if (empty($REG_IDs)) {
1956
-            $registrations = $payment->transaction()->registrations();
1957
-            $REG_IDs       = ! empty($registrations)
1958
-                ? array_keys($registrations)
1959
-                : $this->_get_existing_reg_payment_REG_IDs($payment);
1960
-        }
1961
-
1962
-        // ensure that REG_IDs are integers and NOT strings
1963
-        return array_map('intval', $REG_IDs);
1964
-    }
1965
-
1966
-
1967
-    /**
1968
-     * @return array
1969
-     */
1970
-    public function existing_reg_payment_REG_IDs()
1971
-    {
1972
-        return $this->_existing_reg_payment_REG_IDs;
1973
-    }
1974
-
1975
-
1976
-    /**
1977
-     * @param array $existing_reg_payment_REG_IDs
1978
-     */
1979
-    public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1980
-    {
1981
-        $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1982
-    }
1983
-
1984
-
1985
-    /**
1986
-     * _get_existing_reg_payment_REG_IDs
1987
-     * returns a list of registration IDs that the payment is currently related to
1988
-     * as recorded in the database
1989
-     *
1990
-     * @param EE_Payment $payment
1991
-     * @return array
1992
-     * @throws EE_Error
1993
-     * @throws InvalidArgumentException
1994
-     * @throws InvalidDataTypeException
1995
-     * @throws InvalidInterfaceException
1996
-     * @throws ReflectionException
1997
-     */
1998
-    protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1999
-    {
2000
-        if ($this->existing_reg_payment_REG_IDs() === null) {
2001
-            // let's get any existing reg payment records for this payment
2002
-            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
2003
-            // but we only want the REG IDs, so grab the array keys
2004
-            $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
2005
-                ? array_keys($existing_reg_payment_REG_IDs)
2006
-                : [];
2007
-            $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
2008
-        }
2009
-
2010
-        return $this->existing_reg_payment_REG_IDs();
2011
-    }
2012
-
2013
-
2014
-    /**
2015
-     * _remove_existing_registration_payments
2016
-     * this calculates the difference between existing relations
2017
-     * to the supplied payment and the new list registration IDs,
2018
-     * removes any related registrations that no longer apply,
2019
-     * and then updates the registration paid fields
2020
-     *
2021
-     * @param EE_Payment $payment
2022
-     * @param int        $PAY_ID
2023
-     * @return bool;
2024
-     * @throws EE_Error
2025
-     * @throws InvalidArgumentException
2026
-     * @throws ReflectionException
2027
-     * @throws InvalidDataTypeException
2028
-     * @throws InvalidInterfaceException
2029
-     */
2030
-    protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2031
-    {
2032
-        // newly created payments will have nothing recorded for $PAY_ID
2033
-        if (absint($PAY_ID) === 0) {
2034
-            return false;
2035
-        }
2036
-        $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2037
-        if (empty($existing_reg_payment_REG_IDs)) {
2038
-            return false;
2039
-        }
2040
-        /** @type EE_Transaction_Payments $transaction_payments */
2041
-        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2042
-
2043
-        return $transaction_payments->delete_registration_payments_and_update_registrations(
2044
-            $payment,
2045
-            [
2046
-                [
2047
-                    'PAY_ID' => $payment->ID(),
2048
-                    'REG_ID' => ['IN', $existing_reg_payment_REG_IDs],
2049
-                ],
2050
-            ]
2051
-        );
2052
-    }
2053
-
2054
-
2055
-    /**
2056
-     * _update_registration_payments
2057
-     * this applies the payments to the selected registrations
2058
-     * but only if they have not already been paid for
2059
-     *
2060
-     * @param EE_Transaction $transaction
2061
-     * @param EE_Payment     $payment
2062
-     * @param array          $REG_IDs
2063
-     * @return void
2064
-     * @throws EE_Error
2065
-     * @throws InvalidArgumentException
2066
-     * @throws ReflectionException
2067
-     * @throws RuntimeException
2068
-     * @throws InvalidDataTypeException
2069
-     * @throws InvalidInterfaceException
2070
-     */
2071
-    protected function _update_registration_payments(
2072
-        EE_Transaction $transaction,
2073
-        EE_Payment $payment,
2074
-        $REG_IDs = []
2075
-    ) {
2076
-        // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2077
-        // so let's do that using our set of REG_IDs from the form
2078
-        $registration_query_where_params = [
2079
-            'REG_ID' => ['IN', $REG_IDs],
2080
-        ];
2081
-        // but add in some conditions regarding payment,
2082
-        // so that we don't apply payments to registrations that are free or have already been paid for
2083
-        // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2084
-        if (! $payment->is_a_refund()) {
2085
-            $registration_query_where_params['REG_final_price']  = ['!=', 0];
2086
-            $registration_query_where_params['REG_final_price*'] = ['!=', 'REG_paid', true];
2087
-        }
2088
-        $registrations = $transaction->registrations([$registration_query_where_params]);
2089
-        if (! empty($registrations)) {
2090
-            /** @type EE_Payment_Processor $payment_processor */
2091
-            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2092
-            $payment_processor->process_registration_payments($transaction, $payment, $registrations);
2093
-        }
2094
-    }
2095
-
2096
-
2097
-    /**
2098
-     * _process_registration_status_change
2099
-     * This processes requested registration status changes for all the registrations
2100
-     * on a given transaction and (optionally) sends out notifications for the changes.
2101
-     *
2102
-     * @param EE_Transaction $transaction
2103
-     * @param array          $REG_IDs
2104
-     * @return bool
2105
-     * @throws EE_Error
2106
-     * @throws InvalidArgumentException
2107
-     * @throws ReflectionException
2108
-     * @throws InvalidDataTypeException
2109
-     * @throws InvalidInterfaceException
2110
-     */
2111
-    protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = [])
2112
-    {
2113
-        // first if there is no change in status then we get out.
2114
-        $reg_status = $this->request->getRequestParam('txn_reg_status_change[reg_status]', 'NAN');
2115
-        if ($reg_status === 'NAN') {
2116
-            // no error message, no change requested, just nothing to do man.
2117
-            return false;
2118
-        }
2119
-        /** @type EE_Transaction_Processor $transaction_processor */
2120
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2121
-
2122
-        // made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2123
-        return $transaction_processor->manually_update_registration_statuses(
2124
-            $transaction,
2125
-            $reg_status,
2126
-            [['REG_ID' => ['IN', $REG_IDs]]]
2127
-        );
2128
-    }
2129
-
2130
-
2131
-    /**
2132
-     * _build_payment_json_response
2133
-     *
2134
-     * @access public
2135
-     * @param EE_Payment  $payment
2136
-     * @param array       $REG_IDs
2137
-     * @param bool | null $delete_txn_reg_status_change
2138
-     * @return array
2139
-     * @throws EE_Error
2140
-     * @throws InvalidArgumentException
2141
-     * @throws InvalidDataTypeException
2142
-     * @throws InvalidInterfaceException
2143
-     * @throws ReflectionException
2144
-     */
2145
-    protected function _build_payment_json_response(
2146
-        EE_Payment $payment,
2147
-        $REG_IDs = [],
2148
-        $delete_txn_reg_status_change = null
2149
-    ) {
2150
-        // was the payment deleted ?
2151
-        if (is_bool($delete_txn_reg_status_change)) {
2152
-            return [
2153
-                'PAY_ID'                       => $payment->ID(),
2154
-                'amount'                       => $payment->amount(),
2155
-                'total_paid'                   => $payment->transaction()->paid(),
2156
-                'txn_status'                   => $payment->transaction()->status_ID(),
2157
-                'pay_status'                   => $payment->STS_ID(),
2158
-                'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2159
-                'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2160
-            ];
2161
-        }
2162
-
2163
-        $this->_get_payment_status_array();
2164
-        return [
2165
-            'amount'           => $payment->amount(),
2166
-            'total_paid'       => $payment->transaction()->paid(),
2167
-            'txn_status'       => $payment->transaction()->status_ID(),
2168
-            'pay_status'       => $payment->STS_ID(),
2169
-            'PAY_ID'           => $payment->ID(),
2170
-            'STS_ID'           => $payment->STS_ID(),
2171
-            'status'           => self::$_pay_status[ $payment->STS_ID() ],
2172
-            'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2173
-            'method'           => strtoupper($payment->source()),
2174
-            'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2175
-            'gateway'          => $payment->payment_method()
2176
-                ? $payment->payment_method()->admin_name()
2177
-                : esc_html__('Unknown', 'event_espresso'),
2178
-            'gateway_response' => $payment->gateway_response(),
2179
-            'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2180
-            'po_number'        => $payment->po_number(),
2181
-            'extra_accntng'    => $payment->extra_accntng(),
2182
-            'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2183
-        ];
2184
-    }
2185
-
2186
-
2187
-    /**
2188
-     * delete_payment
2189
-     *    delete a payment or refund made towards a transaction
2190
-     *
2191
-     * @access public
2192
-     * @return void
2193
-     * @throws EE_Error
2194
-     * @throws InvalidArgumentException
2195
-     * @throws ReflectionException
2196
-     * @throws InvalidDataTypeException
2197
-     * @throws InvalidInterfaceException
2198
-     */
2199
-    public function delete_payment()
2200
-    {
2201
-        $json_response_data = ['return_data' => false];
2202
-        $PAY_ID = $this->request->getRequestParam('delete_txn_admin_payment[PAY_ID]', 0, 'int');
2203
-
2204
-        $can_delete         = EE_Registry::instance()->CAP->current_user_can(
2205
-            'ee_delete_payments',
2206
-            'delete_payment_from_registration_details'
2207
-        );
2208
-        if ($PAY_ID && $can_delete) {
2209
-            $delete_txn_reg_status_change = $this->request->getRequestParam(
2210
-                'delete_txn_reg_status_change',
2211
-                false,
2212
-                'bool'
2213
-            );
2214
-            $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2215
-            if ($payment instanceof EE_Payment) {
2216
-                $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2217
-                /** @type EE_Transaction_Payments $transaction_payments */
2218
-                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2219
-                if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2220
-                    $json_response_data['return_data'] = $this->_build_payment_json_response(
2221
-                        $payment,
2222
-                        $REG_IDs,
2223
-                        $delete_txn_reg_status_change
2224
-                    );
2225
-                    if ($delete_txn_reg_status_change) {
2226
-                        // MAKE sure we also add the delete_txn_req_status_change to the
2227
-                        // request data because that's how messages will be looking for it.
2228
-                        $this->request->setRequestParam('txn_reg_status_change', $delete_txn_reg_status_change);
2229
-                        $this->_maybe_send_notifications();
2230
-                        $this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2231
-                    }
2232
-                }
2233
-            } else {
2234
-                EE_Error::add_error(
2235
-                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2236
-                    __FILE__,
2237
-                    __FUNCTION__,
2238
-                    __LINE__
2239
-                );
2240
-            }
2241
-        } elseif ($can_delete) {
2242
-            EE_Error::add_error(
2243
-                esc_html__(
2244
-                    'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2245
-                    'event_espresso'
2246
-                ),
2247
-                __FILE__,
2248
-                __FUNCTION__,
2249
-                __LINE__
2250
-            );
2251
-        } else {
2252
-            EE_Error::add_error(
2253
-                esc_html__(
2254
-                    'You do not have access to delete a payment.',
2255
-                    'event_espresso'
2256
-                ),
2257
-                __FILE__,
2258
-                __FUNCTION__,
2259
-                __LINE__
2260
-            );
2261
-        }
2262
-        $notices              = EE_Error::get_notices(false, false, false);
2263
-        $this->_template_args = [
2264
-            'data'      => $json_response_data,
2265
-            'success'   => $notices['success'],
2266
-            'error'     => $notices['errors'],
2267
-            'attention' => $notices['attention'],
2268
-        ];
2269
-        $this->_return_json();
2270
-    }
2271
-
2272
-
2273
-    /**
2274
-     * _registration_payment_data_array
2275
-     * adds info for 'owing' and 'paid' for each registration to the json response
2276
-     *
2277
-     * @access protected
2278
-     * @param array $REG_IDs
2279
-     * @return array
2280
-     * @throws EE_Error
2281
-     * @throws InvalidArgumentException
2282
-     * @throws InvalidDataTypeException
2283
-     * @throws InvalidInterfaceException
2284
-     * @throws ReflectionException
2285
-     */
2286
-    protected function _registration_payment_data_array($REG_IDs)
2287
-    {
2288
-        $registration_payment_data = [];
2289
-        // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2290
-        if (! empty($REG_IDs)) {
2291
-            $registrations = EEM_Registration::instance()->get_all([['REG_ID' => ['IN', $REG_IDs]]]);
2292
-            foreach ($registrations as $registration) {
2293
-                if ($registration instanceof EE_Registration) {
2294
-                    $registration_payment_data[ $registration->ID() ] = [
2295
-                        'paid'  => $registration->pretty_paid(),
2296
-                        'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2297
-                    ];
2298
-                }
2299
-            }
2300
-        }
2301
-
2302
-        return $registration_payment_data;
2303
-    }
2304
-
2305
-
2306
-    /**
2307
-     * _maybe_send_notifications
2308
-     * determines whether or not the admin has indicated that notifications should be sent.
2309
-     * If so, will toggle a filter switch for delivering registration notices.
2310
-     * If passed an EE_Payment object, then it will trigger payment notifications instead.
2311
-     *
2312
-     * @access protected
2313
-     * @param EE_Payment | null $payment
2314
-     */
2315
-    protected function _maybe_send_notifications($payment = null)
2316
-    {
2317
-        switch ($payment instanceof EE_Payment) {
2318
-            // payment notifications
2319
-            case true:
2320
-                if ($this->request->getRequestParam('txn_payments[send_notifications]', false, 'bool')) {
2321
-                    $this->_process_payment_notification($payment);
2322
-                }
2323
-                break;
2324
-            // registration notifications
2325
-            case false:
2326
-                if ($this->request->getRequestParam('txn_reg_status_change[send_notifications]', false, 'bool')) {
2327
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2328
-                }
2329
-                break;
2330
-        }
2331
-    }
2332
-
2333
-
2334
-    /**
2335
-     * _send_payment_reminder
2336
-     *    generates HTML for the View Transaction Details Admin page
2337
-     *
2338
-     * @access protected
2339
-     * @return void
2340
-     * @throws EE_Error
2341
-     * @throws InvalidArgumentException
2342
-     * @throws InvalidDataTypeException
2343
-     * @throws InvalidInterfaceException
2344
-     */
2345
-    protected function _send_payment_reminder()
2346
-    {
2347
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2348
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2349
-        $redirect_to = $this->request->getRequestParam('redirect_to');
2350
-        $query_args  = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2351
-        do_action(
2352
-            'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2353
-            $transaction
2354
-        );
2355
-        $this->_redirect_after_action(
2356
-            false,
2357
-            esc_html__('payment reminder', 'event_espresso'),
2358
-            esc_html__('sent', 'event_espresso'),
2359
-            $query_args,
2360
-            true
2361
-        );
2362
-    }
2363
-
2364
-
2365
-    /**
2366
-     *  get_transactions
2367
-     *    get transactions for given parameters (used by list table)
2368
-     *
2369
-     * @param int     $per_page how many transactions displayed per page
2370
-     * @param boolean $count   return the count or objects
2371
-     * @param string  $view
2372
-     * @return EE_Transaction[]|int int = count || array of transaction objects
2373
-     * @throws EE_Error
2374
-     * @throws InvalidArgumentException
2375
-     * @throws InvalidDataTypeException
2376
-     * @throws InvalidInterfaceException
2377
-     */
2378
-    public function get_transactions($per_page, $count = false, $view = '')
2379
-    {
2380
-        $start_date = wp_strip_all_tags(
2381
-            $this->request->getRequestParam('txn-filter-start-date', date('m/d/Y', strtotime('-10 year')))
2382
-        );
2383
-        $end_date = wp_strip_all_tags(
2384
-            $this->request->getRequestParam('txn-filter-end-date', date('m/d/Y'))
2385
-        );
2386
-
2387
-        // make sure our timestamps start and end right at the boundaries for each day
2388
-        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2389
-        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2390
-
2391
-
2392
-        // convert to timestamps
2393
-        $start_date = strtotime($start_date);
2394
-        $end_date   = strtotime($end_date);
2395
-
2396
-        // makes sure start date is the lowest value and vice versa
2397
-        $start_date = min($start_date, $end_date);
2398
-        $end_date   = max($start_date, $end_date);
2399
-
2400
-        // convert to correct format for query
2401
-        $start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2402
-            'TXN_timestamp',
2403
-            date('Y-m-d H:i:s', $start_date),
2404
-            'Y-m-d H:i:s'
2405
-        );
2406
-        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2407
-            'TXN_timestamp',
2408
-            date('Y-m-d H:i:s', $end_date),
2409
-            'Y-m-d H:i:s'
2410
-        );
2411
-
2412
-
2413
-        // set orderby
2414
-        $orderby = $this->request->getRequestParam('orderby');
2415
-
2416
-        switch ($orderby) {
2417
-            case 'TXN_ID':
2418
-                break;
2419
-            case 'ATT_fname':
2420
-                $orderby = 'Registration.Attendee.ATT_fname';
2421
-                break;
2422
-            case 'event_name':
2423
-                $orderby = 'Registration.Event.EVT_name';
2424
-                break;
2425
-            default: // 'TXN_timestamp'
2426
-                $orderby = 'TXN_timestamp';
2427
-        }
2428
-
2429
-        $sort         = $this->request->getRequestParam('order', 'DESC');
2430
-        $current_page = $this->request->getRequestParam('paged', 1, 'int');
2431
-
2432
-        $per_page = absint($per_page) ? $per_page : 10;
2433
-        $per_page = $this->request->getRequestParam('perpage', $per_page, 'int');
2434
-
2435
-        $offset = ($current_page - 1) * $per_page;
2436
-        $limit  = [$offset, $per_page];
2437
-
2438
-        $_where = [
2439
-            'TXN_timestamp'          => ['BETWEEN', [$start_date, $end_date]],
2440
-            'Registration.REG_count' => 1,
2441
-        ];
2442
-
2443
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2444
-        if ($EVT_ID) {
2445
-            $_where['Registration.EVT_ID'] = $EVT_ID;
2446
-        }
2447
-
2448
-        $search_term = $this->request->getRequestParam('s');
2449
-        if ($search_term) {
2450
-            $search_term = '%' . $search_term . '%';
2451
-            $_where['OR']  = [
2452
-                'Registration.Event.EVT_name'         => ['LIKE', $search_term],
2453
-                'Registration.Event.EVT_desc'         => ['LIKE', $search_term],
2454
-                'Registration.Event.EVT_short_desc'   => ['LIKE', $search_term],
2455
-                'Registration.Attendee.ATT_full_name' => ['LIKE', $search_term],
2456
-                'Registration.Attendee.ATT_fname'     => ['LIKE', $search_term],
2457
-                'Registration.Attendee.ATT_lname'     => ['LIKE', $search_term],
2458
-                'Registration.Attendee.ATT_short_bio' => ['LIKE', $search_term],
2459
-                'Registration.Attendee.ATT_email'     => ['LIKE', $search_term],
2460
-                'Registration.Attendee.ATT_address'   => ['LIKE', $search_term],
2461
-                'Registration.Attendee.ATT_address2'  => ['LIKE', $search_term],
2462
-                'Registration.Attendee.ATT_city'      => ['LIKE', $search_term],
2463
-                'Registration.REG_final_price'        => ['LIKE', $search_term],
2464
-                'Registration.REG_code'               => ['LIKE', $search_term],
2465
-                'Registration.REG_count'              => ['LIKE', $search_term],
2466
-                'Registration.REG_group_size'         => ['LIKE', $search_term],
2467
-                'Registration.Ticket.TKT_name'        => ['LIKE', $search_term],
2468
-                'Registration.Ticket.TKT_description' => ['LIKE', $search_term],
2469
-                'Payment.PAY_source'                  => ['LIKE', $search_term],
2470
-                'Payment.Payment_Method.PMD_name'     => ['LIKE', $search_term],
2471
-                'TXN_session_data'                    => ['LIKE', $search_term],
2472
-                'Payment.PAY_txn_id_chq_nmbr'         => ['LIKE', $search_term],
2473
-            ];
2474
-        }
2475
-
2476
-        $status = $this->request->getRequestParam('status');
2477
-        // failed transactions
2478
-        $failed     = (! empty($status) && $status === 'failed' && ! $count) || ($count && $view === 'failed');
2479
-        $abandoned  = (! empty($status) && $status === 'abandoned' && ! $count) || ($count && $view === 'abandoned');
2480
-        $incomplete = (! empty($status) && $status === 'incomplete' && ! $count) || ($count && $view === 'incomplete');
2481
-
2482
-        if ($failed) {
2483
-            $_where['STS_ID'] = EEM_Transaction::failed_status_code;
2484
-        } elseif ($abandoned) {
2485
-            $_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2486
-        } elseif ($incomplete) {
2487
-            $_where['STS_ID'] = EEM_Transaction::incomplete_status_code;
2488
-        } else {
2489
-            $_where['STS_ID']  = ['!=', EEM_Transaction::failed_status_code];
2490
-            $_where['STS_ID*'] = ['!=', EEM_Transaction::abandoned_status_code];
2491
-        }
2492
-
2493
-        $query_params = apply_filters(
2494
-            'FHEE__Transactions_Admin_Page___get_transactions_query_params',
2495
-            [
2496
-                $_where,
2497
-                'order_by'                 => [$orderby => $sort],
2498
-                'limit'                    => $limit,
2499
-                'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2500
-            ],
2501
-            $this->request->requestParams(),
2502
-            $view,
2503
-            $count
2504
-        );
2505
-
2506
-        return $count
2507
-            ? EEM_Transaction::instance()->count([$query_params[0]], 'TXN_ID', true)
2508
-            : EEM_Transaction::instance()->get_all($query_params);
2509
-    }
2510
-
2511
-
2512
-    /**
2513
-     * @throws EE_Error
2514
-     * @throws InvalidArgumentException
2515
-     * @throws InvalidDataTypeException
2516
-     * @throws InvalidInterfaceException
2517
-     * @throws ReflectionException
2518
-     * @throws RuntimeException
2519
-     * @since 4.9.79.p
2520
-     */
2521
-    public function recalculateLineItems()
2522
-    {
2523
-        $TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2524
-        /** @var EE_Transaction $transaction */
2525
-        $transaction     = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2526
-        $success         = $transaction->recalculateLineItems();
2527
-        $redirect_to = $this->request->getRequestParam('redirect_to');
2528
-        $query_args = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2529
-        $this->_redirect_after_action(
2530
-            $success,
2531
-            esc_html__('Transaction taxes and totals', 'event_espresso'),
2532
-            esc_html__('recalculated', 'event_espresso'),
2533
-            $query_args,
2534
-            true
2535
-        );
2536
-    }
16
+	/**
17
+	 * @var EE_Transaction
18
+	 */
19
+	private $_transaction;
20
+
21
+	/**
22
+	 * @var EE_Session
23
+	 */
24
+	private $_session;
25
+
26
+	/**
27
+	 * @var array $_txn_status
28
+	 */
29
+	private static $_txn_status;
30
+
31
+	/**
32
+	 * @var array $_pay_status
33
+	 */
34
+	private static $_pay_status;
35
+
36
+	/**
37
+	 * @var array $_existing_reg_payment_REG_IDs
38
+	 */
39
+	protected $_existing_reg_payment_REG_IDs;
40
+
41
+
42
+	/**
43
+	 *    _init_page_props
44
+	 *
45
+	 * @return void
46
+	 */
47
+	protected function _init_page_props()
48
+	{
49
+		$this->page_slug        = TXN_PG_SLUG;
50
+		$this->page_label       = esc_html__('Transactions', 'event_espresso');
51
+		$this->_admin_base_url  = TXN_ADMIN_URL;
52
+		$this->_admin_base_path = TXN_ADMIN;
53
+	}
54
+
55
+
56
+	/**
57
+	 *    _ajax_hooks
58
+	 *
59
+	 * @return void
60
+	 */
61
+	protected function _ajax_hooks()
62
+	{
63
+		add_action('wp_ajax_espresso_apply_payment', [$this, 'apply_payments_or_refunds']);
64
+		add_action('wp_ajax_espresso_apply_refund', [$this, 'apply_payments_or_refunds']);
65
+		add_action('wp_ajax_espresso_delete_payment', [$this, 'delete_payment']);
66
+	}
67
+
68
+
69
+	/**
70
+	 *    _define_page_props
71
+	 *
72
+	 * @return void
73
+	 */
74
+	protected function _define_page_props()
75
+	{
76
+		$this->_admin_page_title = $this->page_label;
77
+		$this->_labels           = [
78
+			'buttons' => [
79
+				'add'    => esc_html__('Add New Transaction', 'event_espresso'),
80
+				'edit'   => esc_html__('Edit Transaction', 'event_espresso'),
81
+				'delete' => esc_html__('Delete Transaction', 'event_espresso'),
82
+			],
83
+		];
84
+	}
85
+
86
+
87
+	/**
88
+	 *        grab url requests and route them
89
+	 *
90
+	 * @access private
91
+	 * @return void
92
+	 * @throws EE_Error
93
+	 * @throws InvalidArgumentException
94
+	 * @throws InvalidDataTypeException
95
+	 * @throws InvalidInterfaceException
96
+	 */
97
+	public function _set_page_routes()
98
+	{
99
+
100
+		$this->_set_transaction_status_array();
101
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
102
+
103
+		$this->_page_routes = [
104
+
105
+			'default' => [
106
+				'func'       => '_transactions_overview_list_table',
107
+				'capability' => 'ee_read_transactions',
108
+			],
109
+
110
+			'view_transaction' => [
111
+				'func'       => '_transaction_details',
112
+				'capability' => 'ee_read_transaction',
113
+				'obj_id'     => $TXN_ID,
114
+			],
115
+
116
+			'send_payment_reminder' => [
117
+				'func'       => '_send_payment_reminder',
118
+				'noheader'   => true,
119
+				'capability' => 'ee_send_message',
120
+			],
121
+
122
+			'espresso_apply_payment' => [
123
+				'func'       => 'apply_payments_or_refunds',
124
+				'noheader'   => true,
125
+				'capability' => 'ee_edit_payments',
126
+			],
127
+
128
+			'espresso_apply_refund' => [
129
+				'func'       => 'apply_payments_or_refunds',
130
+				'noheader'   => true,
131
+				'capability' => 'ee_edit_payments',
132
+			],
133
+
134
+			'espresso_delete_payment' => [
135
+				'func'       => 'delete_payment',
136
+				'noheader'   => true,
137
+				'capability' => 'ee_delete_payments',
138
+			],
139
+
140
+			'espresso_recalculate_line_items' => [
141
+				'func'       => 'recalculateLineItems',
142
+				'noheader'   => true,
143
+				'capability' => 'ee_edit_payments',
144
+			],
145
+
146
+		];
147
+	}
148
+
149
+
150
+	protected function _set_page_config()
151
+	{
152
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
153
+		$this->_page_config = [
154
+			'default'          => [
155
+				'nav'           => [
156
+					'label' => esc_html__('Overview', 'event_espresso'),
157
+					'order' => 10,
158
+				],
159
+				'list_table'    => 'EE_Admin_Transactions_List_Table',
160
+				'help_tabs'     => [
161
+					'transactions_overview_help_tab'                       => [
162
+						'title'    => esc_html__('Transactions Overview', 'event_espresso'),
163
+						'filename' => 'transactions_overview',
164
+					],
165
+					'transactions_overview_table_column_headings_help_tab' => [
166
+						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'),
167
+						'filename' => 'transactions_overview_table_column_headings',
168
+					],
169
+					'transactions_overview_views_filters_help_tab'         => [
170
+						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'),
171
+						'filename' => 'transactions_overview_views_filters_search',
172
+					],
173
+				],
174
+				/**
175
+				 * commented out because currently we are not displaying tips for transaction list table status but this
176
+				 * may change in a later iteration so want to keep the code for then.
177
+				 */
178
+				// 'qtips' => array( 'Transactions_List_Table_Tips' ),
179
+				'require_nonce' => false,
180
+			],
181
+			'view_transaction' => [
182
+				'nav'       => [
183
+					'label'      => esc_html__('View Transaction', 'event_espresso'),
184
+					'order'      => 5,
185
+					'url'        => $TXN_ID
186
+						? add_query_arg(['TXN_ID' => $TXN_ID], $this->_current_page_view_url)
187
+						: $this->_admin_base_url,
188
+					'persistent' => false,
189
+				],
190
+				'help_tabs' => [
191
+					'transactions_view_transaction_help_tab'                                              => [
192
+						'title'    => esc_html__('View Transaction', 'event_espresso'),
193
+						'filename' => 'transactions_view_transaction',
194
+					],
195
+					'transactions_view_transaction_transaction_details_table_help_tab'                    => [
196
+						'title'    => esc_html__('Transaction Details Table', 'event_espresso'),
197
+						'filename' => 'transactions_view_transaction_transaction_details_table',
198
+					],
199
+					'transactions_view_transaction_attendees_registered_help_tab'                         => [
200
+						'title'    => esc_html__('Attendees Registered', 'event_espresso'),
201
+						'filename' => 'transactions_view_transaction_attendees_registered',
202
+					],
203
+					'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => [
204
+						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'),
205
+						'filename' => 'transactions_view_transaction_primary_registrant_billing_information',
206
+					],
207
+				],
208
+				'qtips'     => ['Transaction_Details_Tips'],
209
+				'metaboxes' => ['_transaction_details_metaboxes'],
210
+
211
+				'require_nonce' => false,
212
+			],
213
+		];
214
+	}
215
+
216
+
217
+	/**
218
+	 * The below methods aren't used by this class currently
219
+	 */
220
+	protected function _add_screen_options()
221
+	{
222
+		// noop
223
+	}
224
+
225
+
226
+	protected function _add_feature_pointers()
227
+	{
228
+		// noop
229
+	}
230
+
231
+
232
+	public function admin_init()
233
+	{
234
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
235
+		$event_name = $this->request->getRequestParam('event_name');
236
+		$redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
237
+		// IF a registration was JUST added via the admin...
238
+		if ($EVT_ID && $event_name && $redirect_from) {
239
+			// then set a cookie so that we can block any attempts to use
240
+			// the back button as a way to enter another registration.
241
+			setcookie('ee_registration_added', $EVT_ID, time() + WEEK_IN_SECONDS, '/');
242
+			// and update the global
243
+			$_COOKIE['ee_registration_added'] = $EVT_ID;
244
+		}
245
+		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__(
246
+			'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.',
247
+			'event_espresso'
248
+		);
249
+		EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__(
250
+			'An error occurred! Please refresh the page and try again.',
251
+			'event_espresso'
252
+		);
253
+		EE_Registry::$i18n_js_strings['txn_status_array']        = self::$_txn_status;
254
+		EE_Registry::$i18n_js_strings['pay_status_array']        = self::$_pay_status;
255
+		EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso');
256
+		EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__(
257
+			'This transaction has been overpaid ! Payments Total',
258
+			'event_espresso'
259
+		);
260
+	}
261
+
262
+
263
+	public function admin_notices()
264
+	{
265
+		// noop
266
+	}
267
+
268
+
269
+	public function admin_footer_scripts()
270
+	{
271
+		// noop
272
+	}
273
+
274
+
275
+	/**
276
+	 * _set_transaction_status_array
277
+	 * sets list of transaction statuses
278
+	 *
279
+	 * @access private
280
+	 * @return void
281
+	 * @throws EE_Error
282
+	 * @throws InvalidArgumentException
283
+	 * @throws InvalidDataTypeException
284
+	 * @throws InvalidInterfaceException
285
+	 */
286
+	private function _set_transaction_status_array()
287
+	{
288
+		self::$_txn_status = EEM_Transaction::instance()->status_array(true);
289
+	}
290
+
291
+
292
+	/**
293
+	 * get_transaction_status_array
294
+	 * return the transaction status array for wp_list_table
295
+	 *
296
+	 * @access public
297
+	 * @return array
298
+	 */
299
+	public function get_transaction_status_array()
300
+	{
301
+		return self::$_txn_status;
302
+	}
303
+
304
+
305
+	/**
306
+	 *    get list of payment statuses
307
+	 *
308
+	 * @access private
309
+	 * @return void
310
+	 * @throws EE_Error
311
+	 * @throws InvalidArgumentException
312
+	 * @throws InvalidDataTypeException
313
+	 * @throws InvalidInterfaceException
314
+	 */
315
+	private function _get_payment_status_array()
316
+	{
317
+		self::$_pay_status                      = EEM_Payment::instance()->status_array(true);
318
+		$this->_template_args['payment_status'] = self::$_pay_status;
319
+	}
320
+
321
+
322
+	/**
323
+	 *    _add_screen_options_default
324
+	 *
325
+	 * @access protected
326
+	 * @return void
327
+	 * @throws InvalidArgumentException
328
+	 * @throws InvalidDataTypeException
329
+	 * @throws InvalidInterfaceException
330
+	 */
331
+	protected function _add_screen_options_default()
332
+	{
333
+		$this->_per_page_screen_option();
334
+	}
335
+
336
+
337
+	/**
338
+	 * load_scripts_styles
339
+	 *
340
+	 * @access public
341
+	 * @return void
342
+	 */
343
+	public function load_scripts_styles()
344
+	{
345
+		// enqueue style
346
+		wp_register_style(
347
+			'espresso_txn',
348
+			TXN_ASSETS_URL . 'espresso_transactions_admin.css',
349
+			[],
350
+			EVENT_ESPRESSO_VERSION
351
+		);
352
+		wp_enqueue_style('espresso_txn');
353
+		// scripts
354
+		wp_register_script(
355
+			'espresso_txn',
356
+			TXN_ASSETS_URL . 'espresso_transactions_admin.js',
357
+			[
358
+				'ee_admin_js',
359
+				'ee-datepicker',
360
+				'jquery-ui-datepicker',
361
+				'jquery-ui-draggable',
362
+				'ee-dialog',
363
+				'ee-accounting',
364
+				'ee-serialize-full-array',
365
+			],
366
+			EVENT_ESPRESSO_VERSION,
367
+			true
368
+		);
369
+		wp_enqueue_script('espresso_txn');
370
+	}
371
+
372
+
373
+	/**
374
+	 *    load_scripts_styles_view_transaction
375
+	 *
376
+	 * @access public
377
+	 * @return void
378
+	 */
379
+	public function load_scripts_styles_view_transaction()
380
+	{
381
+		// styles
382
+		wp_enqueue_style('espresso-ui-theme');
383
+	}
384
+
385
+
386
+	/**
387
+	 *    load_scripts_styles_default
388
+	 *
389
+	 * @access public
390
+	 * @return void
391
+	 */
392
+	public function load_scripts_styles_default()
393
+	{
394
+		// styles
395
+		wp_enqueue_style('espresso-ui-theme');
396
+	}
397
+
398
+
399
+	/**
400
+	 *    _set_list_table_views_default
401
+	 *
402
+	 * @access protected
403
+	 * @return void
404
+	 */
405
+	protected function _set_list_table_views_default()
406
+	{
407
+		$this->_views = [
408
+			'all'        => [
409
+				'slug'  => 'all',
410
+				'label' => esc_html__('View All Transactions', 'event_espresso'),
411
+				'count' => 0,
412
+			],
413
+			'abandoned'  => [
414
+				'slug'  => 'abandoned',
415
+				'label' => esc_html__('Abandoned Transactions', 'event_espresso'),
416
+				'count' => 0,
417
+			],
418
+			'incomplete' => [
419
+				'slug'  => 'incomplete',
420
+				'label' => esc_html__('Incomplete Transactions', 'event_espresso'),
421
+				'count' => 0,
422
+			],
423
+		];
424
+		if (
425
+			/**
426
+			 * Filters whether a link to the "Failed Transactions" list table
427
+			 * appears on the Transactions Admin Page list table.
428
+			 * List display can be turned back on via the following:
429
+			 * add_filter(
430
+			 *     'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
431
+			 *     '__return_true'
432
+			 * );
433
+			 *
434
+			 * @param boolean                 $display_failed_txns_list
435
+			 * @param Transactions_Admin_Page $this
436
+			 * @since 4.9.70.p
437
+			 */
438
+			apply_filters(
439
+				'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list',
440
+				false,
441
+				$this
442
+			)
443
+		) {
444
+			$this->_views['failed'] = [
445
+				'slug'  => 'failed',
446
+				'label' => esc_html__('Failed Transactions', 'event_espresso'),
447
+				'count' => 0,
448
+			];
449
+		}
450
+	}
451
+
452
+
453
+	/**
454
+	 * _set_transaction_object
455
+	 * This sets the _transaction property for the transaction details screen
456
+	 *
457
+	 * @access private
458
+	 * @return void
459
+	 * @throws EE_Error
460
+	 * @throws InvalidArgumentException
461
+	 * @throws RuntimeException
462
+	 * @throws InvalidDataTypeException
463
+	 * @throws InvalidInterfaceException
464
+	 * @throws ReflectionException
465
+	 */
466
+	private function _set_transaction_object()
467
+	{
468
+		if ($this->_transaction instanceof EE_Transaction) {
469
+			return;
470
+		} //get out we've already set the object
471
+
472
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
473
+
474
+		// get transaction object
475
+		$this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
476
+		$this->_session     = $this->_transaction instanceof EE_Transaction
477
+			? $this->_transaction->session_data()
478
+			: null;
479
+		if ($this->_transaction instanceof EE_Transaction) {
480
+			$this->_transaction->verify_abandoned_transaction_status();
481
+		}
482
+
483
+		if (! $this->_transaction instanceof EE_Transaction) {
484
+			$error_msg = sprintf(
485
+				esc_html__(
486
+					'An error occurred and the details for the transaction with the ID # %d could not be retrieved.',
487
+					'event_espresso'
488
+				),
489
+				$TXN_ID
490
+			);
491
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
492
+		}
493
+	}
494
+
495
+
496
+	/**
497
+	 *    _transaction_legend_items
498
+	 *
499
+	 * @access protected
500
+	 * @return array
501
+	 * @throws EE_Error
502
+	 * @throws InvalidArgumentException
503
+	 * @throws ReflectionException
504
+	 * @throws InvalidDataTypeException
505
+	 * @throws InvalidInterfaceException
506
+	 */
507
+	protected function _transaction_legend_items()
508
+	{
509
+		EE_Registry::instance()->load_helper('MSG_Template');
510
+		$items = [];
511
+
512
+		if (
513
+			EE_Registry::instance()->CAP->current_user_can(
514
+				'ee_read_global_messages',
515
+				'view_filtered_messages'
516
+			)
517
+		) {
518
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
519
+			if (
520
+				is_array($related_for_icon)
521
+				&& isset($related_for_icon['css_class'], $related_for_icon['label'])
522
+			) {
523
+				$items['view_related_messages'] = [
524
+					'class' => $related_for_icon['css_class'],
525
+					'desc'  => $related_for_icon['label'],
526
+				];
527
+			}
528
+		}
529
+
530
+		$items = apply_filters(
531
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__items',
532
+			array_merge(
533
+				$items,
534
+				[
535
+					'view_details'          => [
536
+						'class' => 'dashicons dashicons-cart',
537
+						'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
538
+					],
539
+					'view_invoice'          => [
540
+						'class' => 'dashicons dashicons-media-spreadsheet',
541
+						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
542
+					],
543
+					'view_receipt'          => [
544
+						'class' => 'dashicons dashicons-media-default',
545
+						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso'),
546
+					],
547
+					'view_registration'     => [
548
+						'class' => 'dashicons dashicons-clipboard',
549
+						'desc'  => esc_html__('View Registration Details', 'event_espresso'),
550
+					],
551
+					'payment_overview_link' => [
552
+						'class' => 'dashicons dashicons-money',
553
+						'desc'  => esc_html__('Make Payment on Frontend', 'event_espresso'),
554
+					],
555
+				]
556
+			)
557
+		);
558
+
559
+		if (
560
+			EEH_MSG_Template::is_mt_active('payment_reminder')
561
+			&& EE_Registry::instance()->CAP->current_user_can(
562
+				'ee_send_message',
563
+				'espresso_transactions_send_payment_reminder'
564
+			)
565
+		) {
566
+			$items['send_payment_reminder'] = [
567
+				'class' => 'dashicons dashicons-email-alt',
568
+				'desc'  => esc_html__('Send Payment Reminder', 'event_espresso'),
569
+			];
570
+		} else {
571
+			$items['blank*'] = [
572
+				'class' => '',
573
+				'desc'  => '',
574
+			];
575
+		}
576
+		$more_items = apply_filters(
577
+			'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items',
578
+			[
579
+				'overpaid'   => [
580
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code,
581
+					'desc'  => EEH_Template::pretty_status(
582
+						EEM_Transaction::overpaid_status_code,
583
+						false,
584
+						'sentence'
585
+					),
586
+				],
587
+				'complete'   => [
588
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code,
589
+					'desc'  => EEH_Template::pretty_status(
590
+						EEM_Transaction::complete_status_code,
591
+						false,
592
+						'sentence'
593
+					),
594
+				],
595
+				'incomplete' => [
596
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code,
597
+					'desc'  => EEH_Template::pretty_status(
598
+						EEM_Transaction::incomplete_status_code,
599
+						false,
600
+						'sentence'
601
+					),
602
+				],
603
+				'abandoned'  => [
604
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code,
605
+					'desc'  => EEH_Template::pretty_status(
606
+						EEM_Transaction::abandoned_status_code,
607
+						false,
608
+						'sentence'
609
+					),
610
+				],
611
+				'failed'     => [
612
+					'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code,
613
+					'desc'  => EEH_Template::pretty_status(
614
+						EEM_Transaction::failed_status_code,
615
+						false,
616
+						'sentence'
617
+					),
618
+				],
619
+			]
620
+		);
621
+
622
+		return array_merge($items, $more_items);
623
+	}
624
+
625
+
626
+	/**
627
+	 *    _transactions_overview_list_table
628
+	 *
629
+	 * @access protected
630
+	 * @return void
631
+	 * @throws DomainException
632
+	 * @throws EE_Error
633
+	 * @throws InvalidArgumentException
634
+	 * @throws InvalidDataTypeException
635
+	 * @throws InvalidInterfaceException
636
+	 * @throws ReflectionException
637
+	 */
638
+	protected function _transactions_overview_list_table()
639
+	{
640
+		$this->_admin_page_title = esc_html__('Transactions', 'event_espresso');
641
+
642
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
643
+		$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
644
+		$this->_template_args['admin_page_header'] = $event instanceof EE_Event
645
+			? sprintf(
646
+				esc_html__('%sViewing Transactions for the Event: %s%s', 'event_espresso'),
647
+				'<h3>',
648
+				'<a href="'
649
+				. EE_Admin_Page::add_query_args_and_nonce(
650
+					['action' => 'edit', 'post' => $event->ID()],
651
+					EVENTS_ADMIN_URL
652
+				)
653
+				. '" title="'
654
+				. esc_attr__('Click to Edit event', 'event_espresso')
655
+				. '">' . $event->name() . '</a>',
656
+				'</h3>'
657
+			)
658
+			: '';
659
+		$this->_template_args['after_list_table']  = $this->_display_legend($this->_transaction_legend_items());
660
+		$this->display_admin_list_table_page_with_no_sidebar();
661
+	}
662
+
663
+
664
+	/**
665
+	 *    _transaction_details
666
+	 * generates HTML for the View Transaction Details Admin page
667
+	 *
668
+	 * @access protected
669
+	 * @return void
670
+	 * @throws DomainException
671
+	 * @throws EE_Error
672
+	 * @throws InvalidArgumentException
673
+	 * @throws InvalidDataTypeException
674
+	 * @throws InvalidInterfaceException
675
+	 * @throws RuntimeException
676
+	 * @throws ReflectionException
677
+	 */
678
+	protected function _transaction_details()
679
+	{
680
+		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction);
681
+
682
+		$this->_set_transaction_status_array();
683
+
684
+		$this->_template_args                      = [];
685
+		$this->_template_args['transactions_page'] = $this->_wp_page_slug;
686
+
687
+		$this->_set_transaction_object();
688
+
689
+		if (! $this->_transaction instanceof EE_Transaction) {
690
+			return;
691
+		}
692
+
693
+		$this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID();
694
+		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso');
695
+
696
+		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp');
697
+		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso');
698
+
699
+		$this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ];
700
+		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso');
701
+		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID();
702
+
703
+		$this->_template_args['grand_total'] = $this->_transaction->total();
704
+		$this->_template_args['total_paid']  = $this->_transaction->paid();
705
+
706
+		$amount_due                         = $this->_transaction->total() - $this->_transaction->paid();
707
+		$this->_template_args['amount_due'] = EEH_Template::format_currency(
708
+			$amount_due,
709
+			true
710
+		);
711
+		if (EE_Registry::instance()->CFG->currency->sign_b4) {
712
+			$this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign
713
+												  . $this->_template_args['amount_due'];
714
+		} else {
715
+			$this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign;
716
+		}
717
+		$this->_template_args['amount_due_class'] = '';
718
+
719
+		if ($this->_transaction->paid() === $this->_transaction->total()) {
720
+			// paid in full
721
+			$this->_template_args['amount_due'] = false;
722
+		} elseif ($this->_transaction->paid() > $this->_transaction->total()) {
723
+			// overpaid
724
+			$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
725
+		} elseif ($this->_transaction->total() > (float) 0) {
726
+			if ($this->_transaction->paid() > (float) 0) {
727
+				// monies owing
728
+				$this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn';
729
+			} elseif ($this->_transaction->paid() === (float) 0) {
730
+				// no payments made yet
731
+				$this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn';
732
+			}
733
+		} elseif ($this->_transaction->total() === (float) 0) {
734
+			// free event
735
+			$this->_template_args['amount_due'] = false;
736
+		}
737
+
738
+		$payment_method = $this->_transaction->payment_method();
739
+
740
+		$this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method
741
+			? $payment_method->admin_name()
742
+			: esc_html__('Unknown', 'event_espresso');
743
+
744
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
745
+		// link back to overview
746
+		$this->_template_args['txn_overview_url'] = $this->request->getServerParam(
747
+			'HTTP_REFERER',
748
+			TXN_ADMIN_URL
749
+		);
750
+
751
+
752
+		// next link
753
+		$next_txn                                 = $this->_transaction->next(
754
+			null,
755
+			[['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
756
+			'TXN_ID'
757
+		);
758
+		$this->_template_args['next_transaction'] = $next_txn
759
+			? $this->_next_link(
760
+				EE_Admin_Page::add_query_args_and_nonce(
761
+					['action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']],
762
+					TXN_ADMIN_URL
763
+				),
764
+				'dashicons dashicons-arrow-right ee-icon-size-22'
765
+			)
766
+			: '';
767
+		// previous link
768
+		$previous_txn                                 = $this->_transaction->previous(
769
+			null,
770
+			[['STS_ID' => ['!=', EEM_Transaction::failed_status_code]]],
771
+			'TXN_ID'
772
+		);
773
+		$this->_template_args['previous_transaction'] = $previous_txn
774
+			? $this->_previous_link(
775
+				EE_Admin_Page::add_query_args_and_nonce(
776
+					['action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']],
777
+					TXN_ADMIN_URL
778
+				),
779
+				'dashicons dashicons-arrow-left ee-icon-size-22'
780
+			)
781
+			: '';
782
+
783
+		$EVT_ID        = $this->request->getRequestParam('EVT_ID', 0, 'int');
784
+		$event_name    = $this->request->getRequestParam('event_name');
785
+		$redirect_from = $this->request->getRequestParam('redirect_from', '', 'url');
786
+
787
+		// were we just redirected here after adding a new registration ???
788
+		if ($EVT_ID && $event_name && $redirect_from) {
789
+			if (
790
+				EE_Registry::instance()->CAP->current_user_can(
791
+					'ee_edit_registrations',
792
+					'espresso_registrations_new_registration',
793
+					$EVT_ID
794
+				)
795
+			) {
796
+				$this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="';
797
+				$this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce(
798
+					[
799
+						'page'     => 'espresso_registrations',
800
+						'action'   => 'new_registration',
801
+						'return'   => 'default',
802
+						'TXN_ID'   => $this->_transaction->ID(),
803
+						'event_id' => $EVT_ID,
804
+					],
805
+					REG_ADMIN_URL
806
+				);
807
+				$this->_admin_page_title .= '">';
808
+
809
+				$this->_admin_page_title .= sprintf(
810
+					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'),
811
+					htmlentities(urldecode($event_name), ENT_QUOTES, 'UTF-8')
812
+				);
813
+				$this->_admin_page_title .= '</a>';
814
+			}
815
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
816
+		}
817
+		// grab messages at the last second
818
+		$this->_template_args['notices'] = EE_Error::get_notices();
819
+		// path to template
820
+		$template_path                             = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php';
821
+		$this->_template_args['admin_page_header'] = EEH_Template::display_template(
822
+			$template_path,
823
+			$this->_template_args,
824
+			true
825
+		);
826
+
827
+		// the details template wrapper
828
+		$this->display_admin_page_with_sidebar();
829
+	}
830
+
831
+
832
+	/**
833
+	 *        _transaction_details_metaboxes
834
+	 *
835
+	 * @access protected
836
+	 * @return void
837
+	 * @throws EE_Error
838
+	 * @throws InvalidArgumentException
839
+	 * @throws InvalidDataTypeException
840
+	 * @throws InvalidInterfaceException
841
+	 * @throws RuntimeException
842
+	 * @throws ReflectionException
843
+	 */
844
+	protected function _transaction_details_metaboxes()
845
+	{
846
+
847
+		$this->_set_transaction_object();
848
+
849
+		if (! $this->_transaction instanceof EE_Transaction) {
850
+			return;
851
+		}
852
+		add_meta_box(
853
+			'edit-txn-details-mbox',
854
+			esc_html__('Transaction Details', 'event_espresso'),
855
+			[$this, 'txn_details_meta_box'],
856
+			$this->_wp_page_slug,
857
+			'normal',
858
+			'high'
859
+		);
860
+		add_meta_box(
861
+			'edit-txn-attendees-mbox',
862
+			esc_html__('Attendees Registered in this Transaction', 'event_espresso'),
863
+			[$this, 'txn_attendees_meta_box'],
864
+			$this->_wp_page_slug,
865
+			'normal',
866
+			'high',
867
+			['TXN_ID' => $this->_transaction->ID()]
868
+		);
869
+		add_meta_box(
870
+			'edit-txn-registrant-mbox',
871
+			esc_html__('Primary Contact', 'event_espresso'),
872
+			[$this, 'txn_registrant_side_meta_box'],
873
+			$this->_wp_page_slug,
874
+			'side',
875
+			'high'
876
+		);
877
+		add_meta_box(
878
+			'edit-txn-billing-info-mbox',
879
+			esc_html__('Billing Information', 'event_espresso'),
880
+			[$this, 'txn_billing_info_side_meta_box'],
881
+			$this->_wp_page_slug,
882
+			'side',
883
+			'high'
884
+		);
885
+	}
886
+
887
+
888
+	/**
889
+	 * Callback for transaction actions metabox.
890
+	 *
891
+	 * @param EE_Transaction|null $transaction
892
+	 * @return string
893
+	 * @throws DomainException
894
+	 * @throws EE_Error
895
+	 * @throws InvalidArgumentException
896
+	 * @throws InvalidDataTypeException
897
+	 * @throws InvalidInterfaceException
898
+	 * @throws ReflectionException
899
+	 * @throws RuntimeException
900
+	 */
901
+	public function getActionButtons(EE_Transaction $transaction = null)
902
+	{
903
+		$content = '';
904
+		$actions = [];
905
+		if (! $transaction instanceof EE_Transaction) {
906
+			return $content;
907
+		}
908
+		/** @var EE_Registration $primary_registration */
909
+		$primary_registration = $transaction->primary_registration();
910
+		$attendee             = $primary_registration instanceof EE_Registration
911
+			? $primary_registration->attendee()
912
+			: null;
913
+
914
+		if (
915
+			$attendee instanceof EE_Attendee
916
+			&& EE_Registry::instance()->CAP->current_user_can(
917
+				'ee_send_message',
918
+				'espresso_transactions_send_payment_reminder'
919
+			)
920
+		) {
921
+			$actions['payment_reminder'] =
922
+				EEH_MSG_Template::is_mt_active('payment_reminder')
923
+				&& $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code
924
+				&& $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code
925
+					? EEH_Template::get_button_or_link(
926
+						EE_Admin_Page::add_query_args_and_nonce(
927
+							[
928
+							'action'      => 'send_payment_reminder',
929
+							'TXN_ID'      => $this->_transaction->ID(),
930
+							'redirect_to' => 'view_transaction',
931
+							],
932
+							TXN_ADMIN_URL
933
+						),
934
+						esc_html__(' Send Payment Reminder', 'event_espresso'),
935
+						'button secondary-button',
936
+						'dashicons dashicons-email-alt'
937
+					)
938
+					: '';
939
+		}
940
+
941
+		if (
942
+			EE_Registry::instance()->CAP->current_user_can(
943
+				'ee_edit_payments',
944
+				'espresso_transactions_recalculate_line_items'
945
+			)
946
+		) {
947
+			$actions['recalculate_line_items'] = EEH_Template::get_button_or_link(
948
+				EE_Admin_Page::add_query_args_and_nonce(
949
+					[
950
+						'action'      => 'espresso_recalculate_line_items',
951
+						'TXN_ID'      => $this->_transaction->ID(),
952
+						'redirect_to' => 'view_transaction',
953
+					],
954
+					TXN_ADMIN_URL
955
+				),
956
+				esc_html__(' Recalculate Taxes and Total', 'event_espresso'),
957
+				'button secondary-button',
958
+				'dashicons dashicons-update'
959
+			);
960
+		}
961
+
962
+		if (
963
+			$primary_registration instanceof EE_Registration
964
+			&& EEH_MSG_Template::is_mt_active('receipt')
965
+		) {
966
+			$actions['receipt'] = EEH_Template::get_button_or_link(
967
+				$primary_registration->receipt_url(),
968
+				esc_html__('View Receipt', 'event_espresso'),
969
+				'button secondary-button',
970
+				'dashicons dashicons-media-default'
971
+			);
972
+		}
973
+
974
+		if (
975
+			$primary_registration instanceof EE_Registration
976
+			&& EEH_MSG_Template::is_mt_active('invoice')
977
+		) {
978
+			$actions['invoice'] = EEH_Template::get_button_or_link(
979
+				$primary_registration->invoice_url(),
980
+				esc_html__('View Invoice', 'event_espresso'),
981
+				'button secondary-button',
982
+				'dashicons dashicons-media-spreadsheet'
983
+			);
984
+		}
985
+		$actions = array_filter(
986
+			apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction)
987
+		);
988
+		if ($actions) {
989
+			$content = '<ul>';
990
+			$content .= '<li>' . implode('</li><li>', $actions) . '</li>';
991
+			$content .= '</uL>';
992
+		}
993
+		return $content;
994
+	}
995
+
996
+
997
+	/**
998
+	 * txn_details_meta_box
999
+	 * generates HTML for the Transaction main meta box
1000
+	 *
1001
+	 * @return void
1002
+	 * @throws DomainException
1003
+	 * @throws EE_Error
1004
+	 * @throws InvalidArgumentException
1005
+	 * @throws InvalidDataTypeException
1006
+	 * @throws InvalidInterfaceException
1007
+	 * @throws RuntimeException
1008
+	 * @throws ReflectionException
1009
+	 */
1010
+	public function txn_details_meta_box()
1011
+	{
1012
+		$this->_set_transaction_object();
1013
+		$this->_template_args['TXN_ID']              = $this->_transaction->ID();
1014
+		$this->_template_args['attendee']            =
1015
+			$this->_transaction->primary_registration() instanceof EE_Registration
1016
+				? $this->_transaction->primary_registration()->attendee()
1017
+				: null;
1018
+		$this->_template_args['can_edit_payments']   = EE_Registry::instance()->CAP->current_user_can(
1019
+			'ee_edit_payments',
1020
+			'apply_payment_or_refund_from_registration_details'
1021
+		);
1022
+		$this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can(
1023
+			'ee_delete_payments',
1024
+			'delete_payment_from_registration_details'
1025
+		);
1026
+
1027
+		// get line table
1028
+		EEH_Autoloader::register_line_item_display_autoloaders();
1029
+		$Line_Item_Display                       = new EE_Line_Item_Display(
1030
+			'admin_table',
1031
+			'EE_Admin_Table_Line_Item_Display_Strategy'
1032
+		);
1033
+		$this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item(
1034
+			$this->_transaction->total_line_item()
1035
+		);
1036
+		$this->_template_args['REG_code']        =
1037
+			$this->_transaction->primary_registration() instanceof EE_Registration
1038
+				? $this->_transaction->primary_registration()->reg_code()
1039
+				: null;
1040
+		// process taxes
1041
+		$taxes                         = $this->_transaction->line_items([['LIN_type' => EEM_Line_Item::type_tax]]);
1042
+		$this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false;
1043
+
1044
+		$this->_template_args['grand_total']     = EEH_Template::format_currency(
1045
+			$this->_transaction->total(),
1046
+			false,
1047
+			false
1048
+		);
1049
+		$this->_template_args['grand_raw_total'] = $this->_transaction->total();
1050
+		$this->_template_args['TXN_status']      = $this->_transaction->status_ID();
1051
+
1052
+		// process payment details
1053
+		$payments = $this->_transaction->payments();
1054
+		if (! empty($payments)) {
1055
+			$this->_template_args['payments']              = $payments;
1056
+			$this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments);
1057
+		} else {
1058
+			$this->_template_args['payments']              = false;
1059
+			$this->_template_args['existing_reg_payments'] = [];
1060
+		}
1061
+
1062
+		$this->_template_args['edit_payment_url']   = add_query_arg(['action' => 'edit_payment'], TXN_ADMIN_URL);
1063
+		$this->_template_args['delete_payment_url'] = add_query_arg(
1064
+			['action' => 'espresso_delete_payment'],
1065
+			TXN_ADMIN_URL
1066
+		);
1067
+
1068
+		if (isset($txn_details['invoice_number'])) {
1069
+			$this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code'];
1070
+			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__(
1071
+				'Invoice Number',
1072
+				'event_espresso'
1073
+			);
1074
+		}
1075
+
1076
+		$this->_template_args['txn_details']['registration_session']['value'] =
1077
+			$this->_transaction->primary_registration() instanceof EE_Registration
1078
+				? $this->_transaction->primary_registration()->session_ID()
1079
+				: null;
1080
+		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__(
1081
+			'Registration Session',
1082
+			'event_espresso'
1083
+		);
1084
+
1085
+		$this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address'])
1086
+			? $this->_session['ip_address']
1087
+			: '';
1088
+		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__(
1089
+			'Transaction placed from IP',
1090
+			'event_espresso'
1091
+		);
1092
+
1093
+		$this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent'])
1094
+			? $this->_session['user_agent']
1095
+			: '';
1096
+		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__(
1097
+			'Registrant User Agent',
1098
+			'event_espresso'
1099
+		);
1100
+
1101
+		$reg_steps = '<ul>';
1102
+		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) {
1103
+			if ($reg_step_status === true) {
1104
+				$reg_steps .= '<li style="color:#70cc50">'
1105
+							  . sprintf(
1106
+								  esc_html__('%1$s : Completed', 'event_espresso'),
1107
+								  ucwords(str_replace('_', ' ', $reg_step))
1108
+							  )
1109
+							  . '</li>';
1110
+			} elseif ($reg_step_status !== false && is_numeric($reg_step_status)) {
1111
+				$reg_steps .= '<li style="color:#2EA2CC">'
1112
+							  . sprintf(
1113
+								  esc_html__('%1$s : Initiated %2$s', 'event_espresso'),
1114
+								  ucwords(str_replace('_', ' ', $reg_step)),
1115
+								  date(
1116
+									  get_option('date_format') . ' ' . get_option('time_format'),
1117
+									  $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)
1118
+								  )
1119
+							  )
1120
+							  . '</li>';
1121
+			} else {
1122
+				$reg_steps .= '<li style="color:#E76700">'
1123
+							  . sprintf(
1124
+								  esc_html__('%1$s : Never Initiated', 'event_espresso'),
1125
+								  ucwords(str_replace('_', ' ', $reg_step))
1126
+							  )
1127
+							  . '</li>';
1128
+			}
1129
+		}
1130
+		$reg_steps                                                 .= '</ul>';
1131
+		$this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps;
1132
+		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__(
1133
+			'Registration Step Progress',
1134
+			'event_espresso'
1135
+		);
1136
+
1137
+
1138
+		$this->_get_registrations_to_apply_payment_to();
1139
+		$this->_get_payment_methods($payments);
1140
+		$this->_get_payment_status_array();
1141
+		$this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction.
1142
+
1143
+		$this->_template_args['transaction_form_url']    = add_query_arg(
1144
+			[
1145
+				'action'  => 'edit_transaction',
1146
+				'process' => 'transaction',
1147
+			],
1148
+			TXN_ADMIN_URL
1149
+		);
1150
+		$this->_template_args['apply_payment_form_url']  = add_query_arg(
1151
+			[
1152
+				'page'   => 'espresso_transactions',
1153
+				'action' => 'espresso_apply_payment',
1154
+			],
1155
+			WP_AJAX_URL
1156
+		);
1157
+		$this->_template_args['delete_payment_form_url'] = add_query_arg(
1158
+			[
1159
+				'page'   => 'espresso_transactions',
1160
+				'action' => 'espresso_delete_payment',
1161
+			],
1162
+			WP_AJAX_URL
1163
+		);
1164
+
1165
+		$this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction);
1166
+
1167
+		// 'espresso_delete_payment_nonce'
1168
+
1169
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php';
1170
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1171
+	}
1172
+
1173
+
1174
+	/**
1175
+	 * _get_registration_payment_IDs
1176
+	 *    generates an array of Payment IDs and their corresponding Registration IDs
1177
+	 *
1178
+	 * @access protected
1179
+	 * @param EE_Payment[] $payments
1180
+	 * @return array
1181
+	 * @throws EE_Error
1182
+	 * @throws InvalidArgumentException
1183
+	 * @throws InvalidDataTypeException
1184
+	 * @throws InvalidInterfaceException
1185
+	 * @throws ReflectionException
1186
+	 */
1187
+	protected function _get_registration_payment_IDs($payments = [])
1188
+	{
1189
+		$existing_reg_payments = [];
1190
+		// get all reg payments for these payments
1191
+		$reg_payments = EEM_Registration_Payment::instance()->get_all(
1192
+			[
1193
+				[
1194
+					'PAY_ID' => [
1195
+						'IN',
1196
+						array_keys($payments),
1197
+					],
1198
+				],
1199
+			]
1200
+		);
1201
+		if (! empty($reg_payments)) {
1202
+			foreach ($payments as $payment) {
1203
+				if (! $payment instanceof EE_Payment) {
1204
+					continue;
1205
+				} elseif (! isset($existing_reg_payments[ $payment->ID() ])) {
1206
+					$existing_reg_payments[ $payment->ID() ] = [];
1207
+				}
1208
+				foreach ($reg_payments as $reg_payment) {
1209
+					if (
1210
+						$reg_payment instanceof EE_Registration_Payment
1211
+						&& $reg_payment->payment_ID() === $payment->ID()
1212
+					) {
1213
+						$existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID();
1214
+					}
1215
+				}
1216
+			}
1217
+		}
1218
+
1219
+		return $existing_reg_payments;
1220
+	}
1221
+
1222
+
1223
+	/**
1224
+	 * _get_registrations_to_apply_payment_to
1225
+	 *    generates HTML for displaying a series of checkboxes in the admin payment modal window
1226
+	 * which allows the admin to only apply the payment to the specific registrations
1227
+	 *
1228
+	 * @access protected
1229
+	 * @return void
1230
+	 * @throws EE_Error
1231
+	 * @throws InvalidArgumentException
1232
+	 * @throws InvalidDataTypeException
1233
+	 * @throws InvalidInterfaceException
1234
+	 * @throws ReflectionException
1235
+	 */
1236
+	protected function _get_registrations_to_apply_payment_to()
1237
+	{
1238
+		// we want any registration with an active status (ie: not deleted or cancelled)
1239
+		$query_params                      = [
1240
+			[
1241
+				'STS_ID' => [
1242
+					'IN',
1243
+					[
1244
+						EEM_Registration::status_id_approved,
1245
+						EEM_Registration::status_id_pending_payment,
1246
+						EEM_Registration::status_id_not_approved,
1247
+					],
1248
+				],
1249
+			],
1250
+		];
1251
+		$registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div(
1252
+			'',
1253
+			'txn-admin-apply-payment-to-registrations-dv',
1254
+			'',
1255
+			'clear: both; margin: 1.5em 0 0; display: none;'
1256
+		);
1257
+		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap');
1258
+		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl');
1259
+		$registrations_to_apply_payment_to .= EEH_HTML::thead(
1260
+			EEH_HTML::tr(
1261
+				EEH_HTML::th(esc_html__('ID', 'event_espresso')) .
1262
+				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) .
1263
+				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) .
1264
+				EEH_HTML::th(esc_html__('Event', 'event_espresso')) .
1265
+				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') .
1266
+				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') .
1267
+				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr')
1268
+			)
1269
+		);
1270
+		$registrations_to_apply_payment_to .= EEH_HTML::tbody();
1271
+		// get registrations for TXN
1272
+		$registrations         = $this->_transaction->registrations($query_params);
1273
+		$existing_reg_payments = $this->_template_args['existing_reg_payments'];
1274
+		foreach ($registrations as $registration) {
1275
+			if ($registration instanceof EE_Registration) {
1276
+				$attendee_name                     = $registration->attendee() instanceof EE_Attendee
1277
+					? $registration->attendee()->full_name()
1278
+					: esc_html__('Unknown Attendee', 'event_espresso');
1279
+				$owing                             = $registration->final_price() - $registration->paid();
1280
+				$taxable                           = $registration->ticket()->taxable()
1281
+					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>'
1282
+					: '';
1283
+				$checked                           = empty($existing_reg_payments)
1284
+													 || in_array($registration->ID(), $existing_reg_payments, true)
1285
+					? ' checked="checked"'
1286
+					: '';
1287
+				$disabled                          = $registration->final_price() > 0 ? '' : ' disabled';
1288
+				$registrations_to_apply_payment_to .= EEH_HTML::tr(
1289
+					EEH_HTML::td($registration->ID()) .
1290
+					EEH_HTML::td($attendee_name) .
1291
+					EEH_HTML::td(
1292
+						$registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable
1293
+					) .
1294
+					EEH_HTML::td($registration->event_name()) .
1295
+					EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') .
1296
+					EEH_HTML::td(
1297
+						EEH_Template::format_currency($owing),
1298
+						'',
1299
+						'txn-admin-payment-owing-td jst-cntr'
1300
+					) .
1301
+					EEH_HTML::td(
1302
+						'<input type="checkbox" value="' . $registration->ID()
1303
+						. '" name="txn_admin_payment[registrations]"'
1304
+						. $checked . $disabled . '>',
1305
+						'',
1306
+						'jst-cntr'
1307
+					),
1308
+					'apply-payment-registration-row-' . $registration->ID()
1309
+				);
1310
+			}
1311
+		}
1312
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tbodyx();
1313
+		$registrations_to_apply_payment_to                         .= EEH_HTML::tablex();
1314
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1315
+		$registrations_to_apply_payment_to                         .= EEH_HTML::p(
1316
+			esc_html__(
1317
+				'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.',
1318
+				'event_espresso'
1319
+			),
1320
+			'',
1321
+			'clear description'
1322
+		);
1323
+		$registrations_to_apply_payment_to                         .= EEH_HTML::divx();
1324
+		$this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to;
1325
+	}
1326
+
1327
+
1328
+	/**
1329
+	 * _get_reg_status_selection
1330
+	 *
1331
+	 * @return void
1332
+	 * @throws EE_Error
1333
+	 * @todo   this will need to be adjusted either once MER comes along OR we move default reg status to tickets
1334
+	 *         instead of events.
1335
+	 * @access protected
1336
+	 */
1337
+	protected function _get_reg_status_selection()
1338
+	{
1339
+		// first get all possible statuses
1340
+		$statuses = EEM_Registration::reg_status_array([], true);
1341
+		// let's add a "don't change" option.
1342
+		$status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso');
1343
+		$status_array                                        = array_merge($status_array, $statuses);
1344
+		$this->_template_args['status_change_select']        = EEH_Form_Fields::select_input(
1345
+			'txn_reg_status_change[reg_status]',
1346
+			$status_array,
1347
+			'NAN',
1348
+			'id="txn-admin-payment-reg-status-inp"',
1349
+			'txn-reg-status-change-reg-status'
1350
+		);
1351
+		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input(
1352
+			'delete_txn_reg_status_change[reg_status]',
1353
+			$status_array,
1354
+			'NAN',
1355
+			'delete-txn-admin-payment-reg-status-inp',
1356
+			'delete-txn-reg-status-change-reg-status'
1357
+		);
1358
+	}
1359
+
1360
+
1361
+	/**
1362
+	 *    _get_payment_methods
1363
+	 * Gets all the payment methods available generally, or the ones that are already
1364
+	 * selected on these payments (in case their payment methods are no longer active).
1365
+	 * Has the side-effect of updating the template args' payment_methods item
1366
+	 *
1367
+	 * @access private
1368
+	 * @param EE_Payment[] to show on this page
1369
+	 * @return void
1370
+	 * @throws EE_Error
1371
+	 * @throws InvalidArgumentException
1372
+	 * @throws InvalidDataTypeException
1373
+	 * @throws InvalidInterfaceException
1374
+	 * @throws ReflectionException
1375
+	 */
1376
+	private function _get_payment_methods($payments = [])
1377
+	{
1378
+		$payment_methods_of_payments = [];
1379
+		foreach ($payments as $payment) {
1380
+			if ($payment instanceof EE_Payment) {
1381
+				$payment_methods_of_payments[] = $payment->ID();
1382
+			}
1383
+		}
1384
+		if ($payment_methods_of_payments) {
1385
+			$query_args = [
1386
+				[
1387
+					'OR*payment_method_for_payment' => [
1388
+						'PMD_ID'    => ['IN', $payment_methods_of_payments],
1389
+						'PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%'],
1390
+					],
1391
+				],
1392
+			];
1393
+		} else {
1394
+			$query_args = [['PMD_scope' => ['LIKE', '%' . EEM_Payment_Method::scope_admin . '%']]];
1395
+		}
1396
+		$this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args);
1397
+	}
1398
+
1399
+
1400
+	/**
1401
+	 * txn_attendees_meta_box
1402
+	 *    generates HTML for the Attendees Transaction main meta box
1403
+	 *
1404
+	 * @access public
1405
+	 * @param WP_Post $post
1406
+	 * @param array   $metabox
1407
+	 * @return void
1408
+	 * @throws DomainException
1409
+	 * @throws EE_Error
1410
+	 * @throws InvalidArgumentException
1411
+	 * @throws InvalidDataTypeException
1412
+	 * @throws InvalidInterfaceException
1413
+	 * @throws ReflectionException
1414
+	 */
1415
+	public function txn_attendees_meta_box($post, $metabox = ['args' => []])
1416
+	{
1417
+
1418
+		/** @noinspection NonSecureExtractUsageInspection */
1419
+		extract($metabox['args']);
1420
+		$this->_template_args['post']            = $post;
1421
+		$this->_template_args['event_attendees'] = [];
1422
+		// process items in cart
1423
+		$line_items = $this->_transaction->get_many_related(
1424
+			'Line_Item',
1425
+			[['LIN_type' => 'line-item']]
1426
+		);
1427
+		if (! empty($line_items)) {
1428
+			foreach ($line_items as $item) {
1429
+				if ($item instanceof EE_Line_Item) {
1430
+					switch ($item->OBJ_type()) {
1431
+						case 'Event':
1432
+							break;
1433
+						case 'Ticket':
1434
+							$ticket = $item->ticket();
1435
+							// right now we're only handling tickets here.
1436
+							// Cause its expected that only tickets will have attendees right?
1437
+							if (! $ticket instanceof EE_Ticket) {
1438
+								break;
1439
+							}
1440
+							try {
1441
+								$event_name = $ticket->get_event_name();
1442
+							} catch (Exception $e) {
1443
+								EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1444
+								$event_name = esc_html__('Unknown Event', 'event_espresso');
1445
+							}
1446
+							$event_name   .= ' - ' . $item->name();
1447
+							$ticket_price = EEH_Template::format_currency($item->unit_price());
1448
+							// now get all of the registrations for this transaction that use this ticket
1449
+							$registrations = $ticket->registrations(
1450
+								[['TXN_ID' => $this->_transaction->ID()]]
1451
+							);
1452
+							foreach ($registrations as $registration) {
1453
+								if (! $registration instanceof EE_Registration) {
1454
+									break;
1455
+								}
1456
+								$this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID']
1457
+									= $registration->status_ID();
1458
+								$this->_template_args['event_attendees'][ $registration->ID() ]['att_num']
1459
+									= $registration->count();
1460
+								$this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name']
1461
+									= $event_name;
1462
+								$this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price']
1463
+									= $ticket_price;
1464
+								// attendee info
1465
+								$attendee = $registration->get_first_related('Attendee');
1466
+								if ($attendee instanceof EE_Attendee) {
1467
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id']
1468
+										= $attendee->ID();
1469
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee']
1470
+										= $attendee->full_name();
1471
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email']
1472
+										= '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name
1473
+										  . esc_html__(
1474
+											  ' Event',
1475
+											  'event_espresso'
1476
+										  )
1477
+										  . '">' . $attendee->email() . '</a>';
1478
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address']
1479
+										= EEH_Address::format($attendee, 'inline', false, false);
1480
+								} else {
1481
+									$this->_template_args['event_attendees'][ $registration->ID() ]['att_id']   = '';
1482
+									$this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = '';
1483
+									$this->_template_args['event_attendees'][ $registration->ID() ]['email']    = '';
1484
+									$this->_template_args['event_attendees'][ $registration->ID() ]['address']  = '';
1485
+								}
1486
+							}
1487
+							break;
1488
+					}
1489
+				}
1490
+			}
1491
+
1492
+			$this->_template_args['transaction_form_url'] = add_query_arg(
1493
+				[
1494
+					'action'  => 'edit_transaction',
1495
+					'process' => 'attendees',
1496
+				],
1497
+				TXN_ADMIN_URL
1498
+			);
1499
+			echo EEH_Template::display_template(
1500
+				TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php',
1501
+				$this->_template_args,
1502
+				true
1503
+			);
1504
+		} else {
1505
+			printf(
1506
+				esc_html__(
1507
+					'%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s',
1508
+					'event_espresso'
1509
+				),
1510
+				'<p class="important-notice">',
1511
+				'</p>'
1512
+			);
1513
+		}
1514
+	}
1515
+
1516
+
1517
+	/**
1518
+	 * txn_registrant_side_meta_box
1519
+	 * generates HTML for the Edit Transaction side meta box
1520
+	 *
1521
+	 * @access public
1522
+	 * @return void
1523
+	 * @throws DomainException
1524
+	 * @throws EE_Error
1525
+	 * @throws InvalidArgumentException
1526
+	 * @throws InvalidDataTypeException
1527
+	 * @throws InvalidInterfaceException
1528
+	 * @throws ReflectionException
1529
+	 */
1530
+	public function txn_registrant_side_meta_box()
1531
+	{
1532
+		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration
1533
+			? $this->_transaction->primary_registration()->get_first_related('Attendee')
1534
+			: null;
1535
+		if (! $primary_att instanceof EE_Attendee) {
1536
+			$this->_template_args['no_attendee_message'] = esc_html__(
1537
+				'There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.',
1538
+				'event_espresso'
1539
+			);
1540
+			$primary_att                           = EEM_Attendee::instance()->create_default_object();
1541
+		}
1542
+		$this->_template_args['ATT_ID']            = $primary_att->ID();
1543
+		$this->_template_args['prime_reg_fname']   = $primary_att->fname();
1544
+		$this->_template_args['prime_reg_lname']   = $primary_att->lname();
1545
+		$this->_template_args['prime_reg_email']   = $primary_att->email();
1546
+		$this->_template_args['prime_reg_phone']   = $primary_att->phone();
1547
+		$this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(
1548
+			[
1549
+				'action' => 'edit_attendee',
1550
+				'post'   => $primary_att->ID(),
1551
+			],
1552
+			REG_ADMIN_URL
1553
+		);
1554
+		// get formatted address for registrant
1555
+		$this->_template_args['formatted_address'] = EEH_Address::format($primary_att);
1556
+		echo EEH_Template::display_template(
1557
+			TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php',
1558
+			$this->_template_args,
1559
+			true
1560
+		);
1561
+	}
1562
+
1563
+
1564
+	/**
1565
+	 * txn_billing_info_side_meta_box
1566
+	 *    generates HTML for the Edit Transaction side meta box
1567
+	 *
1568
+	 * @access public
1569
+	 * @return void
1570
+	 * @throws DomainException
1571
+	 * @throws EE_Error
1572
+	 * @throws ReflectionException
1573
+	 */
1574
+	public function txn_billing_info_side_meta_box()
1575
+	{
1576
+
1577
+		$this->_template_args['billing_form']     = $this->_transaction->billing_info();
1578
+		$this->_template_args['billing_form_url'] = add_query_arg(
1579
+			['action' => 'edit_transaction', 'process' => 'billing'],
1580
+			TXN_ADMIN_URL
1581
+		);
1582
+
1583
+		$template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php';
1584
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1585
+	}
1586
+
1587
+
1588
+	/**
1589
+	 * apply_payments_or_refunds
1590
+	 *    registers a payment or refund made towards a transaction
1591
+	 *
1592
+	 * @access public
1593
+	 * @return void
1594
+	 * @throws EE_Error
1595
+	 * @throws InvalidArgumentException
1596
+	 * @throws ReflectionException
1597
+	 * @throws RuntimeException
1598
+	 * @throws InvalidDataTypeException
1599
+	 * @throws InvalidInterfaceException
1600
+	 */
1601
+	public function apply_payments_or_refunds()
1602
+	{
1603
+		$json_response_data = ['return_data' => false];
1604
+		$valid_data         = $this->_validate_payment_request_data();
1605
+		$has_access         = EE_Registry::instance()->CAP->current_user_can(
1606
+			'ee_edit_payments',
1607
+			'apply_payment_or_refund_from_registration_details'
1608
+		);
1609
+		if (! empty($valid_data) && $has_access) {
1610
+			$PAY_ID = $valid_data['PAY_ID'];
1611
+			// save  the new payment
1612
+			$payment = $this->_create_payment_from_request_data($valid_data);
1613
+			// get the TXN for this payment
1614
+			$transaction = $payment->transaction();
1615
+			// verify transaction
1616
+			if ($transaction instanceof EE_Transaction) {
1617
+				// calculate_total_payments_and_update_status
1618
+				$this->_process_transaction_payments($transaction);
1619
+				$REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment);
1620
+				$this->_remove_existing_registration_payments($payment, $PAY_ID);
1621
+				// apply payment to registrations (if applicable)
1622
+				if (! empty($REG_IDs)) {
1623
+					$this->_update_registration_payments($transaction, $payment, $REG_IDs);
1624
+					$this->_maybe_send_notifications();
1625
+					// now process status changes for the same registrations
1626
+					$this->_process_registration_status_change($transaction, $REG_IDs);
1627
+				}
1628
+				$this->_maybe_send_notifications($payment);
1629
+				// prepare to render page
1630
+				$json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs);
1631
+				do_action(
1632
+					'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording',
1633
+					$transaction,
1634
+					$payment
1635
+				);
1636
+			} else {
1637
+				EE_Error::add_error(
1638
+					esc_html__(
1639
+						'A valid Transaction for this payment could not be retrieved.',
1640
+						'event_espresso'
1641
+					),
1642
+					__FILE__,
1643
+					__FUNCTION__,
1644
+					__LINE__
1645
+				);
1646
+			}
1647
+		} elseif ($has_access) {
1648
+			EE_Error::add_error(
1649
+				esc_html__(
1650
+					'The payment form data could not be processed. Please try again.',
1651
+					'event_espresso'
1652
+				),
1653
+				__FILE__,
1654
+				__FUNCTION__,
1655
+				__LINE__
1656
+			);
1657
+		} else {
1658
+			EE_Error::add_error(
1659
+				esc_html__(
1660
+					'You do not have access to apply payments or refunds to a registration.',
1661
+					'event_espresso'
1662
+				),
1663
+				__FILE__,
1664
+				__FUNCTION__,
1665
+				__LINE__
1666
+			);
1667
+		}
1668
+		$notices              = EE_Error::get_notices(
1669
+			false,
1670
+			false,
1671
+			false
1672
+		);
1673
+		$this->_template_args = [
1674
+			'data'    => $json_response_data,
1675
+			'error'   => $notices['errors'],
1676
+			'success' => $notices['success'],
1677
+		];
1678
+		$this->_return_json();
1679
+	}
1680
+
1681
+
1682
+	/**
1683
+	 * _validate_payment_request_data
1684
+	 *
1685
+	 * @return array
1686
+	 * @throws EE_Error
1687
+	 * @throws InvalidArgumentException
1688
+	 * @throws InvalidDataTypeException
1689
+	 * @throws InvalidInterfaceException
1690
+	 */
1691
+	protected function _validate_payment_request_data()
1692
+	{
1693
+		if (! $this->request->requestParamIsSet('txn_admin_payment')) {
1694
+			return [];
1695
+		}
1696
+		$payment_form = $this->_generate_payment_form_section();
1697
+		try {
1698
+			if ($payment_form->was_submitted()) {
1699
+				$payment_form->receive_form_submission();
1700
+				if (! $payment_form->is_valid()) {
1701
+					$submission_error_messages = [];
1702
+					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) {
1703
+						if ($validation_error instanceof EE_Validation_Error) {
1704
+							$form_input = $validation_error->get_form_section();
1705
+							$submission_error_messages[] = sprintf(
1706
+								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'),
1707
+								$form_input instanceof EE_Form_Input_Base ? $form_input->html_label_text() : '',
1708
+								$validation_error->getMessage()
1709
+							);
1710
+						}
1711
+					}
1712
+					EE_Error::add_error(
1713
+						implode('<br />', $submission_error_messages),
1714
+						__FILE__,
1715
+						__FUNCTION__,
1716
+						__LINE__
1717
+					);
1718
+					return [];
1719
+				}
1720
+			}
1721
+		} catch (EE_Error $e) {
1722
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
1723
+			return [];
1724
+		}
1725
+
1726
+		return $payment_form->valid_data();
1727
+	}
1728
+
1729
+
1730
+	/**
1731
+	 * _generate_payment_form_section
1732
+	 *
1733
+	 * @return EE_Form_Section_Proper
1734
+	 * @throws EE_Error
1735
+	 */
1736
+	protected function _generate_payment_form_section()
1737
+	{
1738
+		return new EE_Form_Section_Proper(
1739
+			[
1740
+				'name'        => 'txn_admin_payment',
1741
+				'subsections' => [
1742
+					'PAY_ID'          => new EE_Text_Input(
1743
+						[
1744
+							'default'               => 0,
1745
+							'required'              => false,
1746
+							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'),
1747
+							'validation_strategies' => [new EE_Int_Normalization()],
1748
+						]
1749
+					),
1750
+					'TXN_ID'          => new EE_Text_Input(
1751
+						[
1752
+							'default'               => 0,
1753
+							'required'              => true,
1754
+							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'),
1755
+							'validation_strategies' => [new EE_Int_Normalization()],
1756
+						]
1757
+					),
1758
+					'type'            => new EE_Text_Input(
1759
+						[
1760
+							'default'               => 1,
1761
+							'required'              => true,
1762
+							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'),
1763
+							'validation_strategies' => [new EE_Int_Normalization()],
1764
+						]
1765
+					),
1766
+					'amount'          => new EE_Text_Input(
1767
+						[
1768
+							'default'               => 0,
1769
+							'required'              => true,
1770
+							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'),
1771
+							'validation_strategies' => [new EE_Float_Normalization()],
1772
+						]
1773
+					),
1774
+					'status'          => new EE_Text_Input(
1775
+						[
1776
+							'default'         => EEM_Payment::status_id_approved,
1777
+							'required'        => true,
1778
+							'html_label_text' => esc_html__('Payment status', 'event_espresso'),
1779
+						]
1780
+					),
1781
+					'PMD_ID'          => new EE_Text_Input(
1782
+						[
1783
+							'default'               => 2,
1784
+							'required'              => true,
1785
+							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'),
1786
+							'validation_strategies' => [new EE_Int_Normalization()],
1787
+						]
1788
+					),
1789
+					'date'            => new EE_Text_Input(
1790
+						[
1791
+							'default'         => time(),
1792
+							'required'        => true,
1793
+							'html_label_text' => esc_html__('Payment date', 'event_espresso'),
1794
+						]
1795
+					),
1796
+					'txn_id_chq_nmbr' => new EE_Text_Input(
1797
+						[
1798
+							'default'               => '',
1799
+							'required'              => false,
1800
+							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'),
1801
+							'validation_strategies' => [
1802
+								new EE_Max_Length_Validation_Strategy(
1803
+									esc_html__('Input too long', 'event_espresso'),
1804
+									100
1805
+								),
1806
+							],
1807
+						]
1808
+					),
1809
+					'po_number'       => new EE_Text_Input(
1810
+						[
1811
+							'default'               => '',
1812
+							'required'              => false,
1813
+							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'),
1814
+							'validation_strategies' => [
1815
+								new EE_Max_Length_Validation_Strategy(
1816
+									esc_html__('Input too long', 'event_espresso'),
1817
+									100
1818
+								),
1819
+							],
1820
+						]
1821
+					),
1822
+					'accounting'      => new EE_Text_Input(
1823
+						[
1824
+							'default'               => '',
1825
+							'required'              => false,
1826
+							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'),
1827
+							'validation_strategies' => [
1828
+								new EE_Max_Length_Validation_Strategy(
1829
+									esc_html__('Input too long', 'event_espresso'),
1830
+									100
1831
+								),
1832
+							],
1833
+						]
1834
+					),
1835
+				],
1836
+			]
1837
+		);
1838
+	}
1839
+
1840
+
1841
+	/**
1842
+	 * _create_payment_from_request_data
1843
+	 *
1844
+	 * @param array $valid_data
1845
+	 * @return EE_Payment
1846
+	 * @throws EE_Error
1847
+	 * @throws InvalidArgumentException
1848
+	 * @throws InvalidDataTypeException
1849
+	 * @throws InvalidInterfaceException
1850
+	 * @throws ReflectionException
1851
+	 */
1852
+	protected function _create_payment_from_request_data($valid_data)
1853
+	{
1854
+		$PAY_ID = $valid_data['PAY_ID'];
1855
+		// get payment amount
1856
+		$amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0;
1857
+		// payments have a type value of 1 and refunds have a type value of -1
1858
+		// so multiplying amount by type will give a positive value for payments, and negative values for refunds
1859
+		$amount = $valid_data['type'] < 0 ? $amount * -1 : $amount;
1860
+		// for some reason the date string coming in has extra spaces between the date and time.  This fixes that.
1861
+		$date    = $valid_data['date']
1862
+			? preg_replace('/\s+/', ' ', $valid_data['date'])
1863
+			: date('Y-m-d g:i a', current_time('timestamp'));
1864
+		$payment = EE_Payment::new_instance(
1865
+			[
1866
+				'TXN_ID'              => $valid_data['TXN_ID'],
1867
+				'STS_ID'              => $valid_data['status'],
1868
+				'PAY_timestamp'       => $date,
1869
+				'PAY_source'          => EEM_Payment_Method::scope_admin,
1870
+				'PMD_ID'              => $valid_data['PMD_ID'],
1871
+				'PAY_amount'          => $amount,
1872
+				'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'],
1873
+				'PAY_po_number'       => $valid_data['po_number'],
1874
+				'PAY_extra_accntng'   => $valid_data['accounting'],
1875
+				'PAY_details'         => $valid_data,
1876
+				'PAY_ID'              => $PAY_ID,
1877
+			],
1878
+			'',
1879
+			['Y-m-d', 'g:i a']
1880
+		);
1881
+
1882
+		if (! $payment->save()) {
1883
+			EE_Error::add_error(
1884
+				sprintf(
1885
+					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'),
1886
+					$payment->ID()
1887
+				),
1888
+				__FILE__,
1889
+				__FUNCTION__,
1890
+				__LINE__
1891
+			);
1892
+		}
1893
+
1894
+		return $payment;
1895
+	}
1896
+
1897
+
1898
+	/**
1899
+	 * _process_transaction_payments
1900
+	 *
1901
+	 * @param EE_Transaction $transaction
1902
+	 * @return void
1903
+	 * @throws EE_Error
1904
+	 * @throws InvalidArgumentException
1905
+	 * @throws ReflectionException
1906
+	 * @throws InvalidDataTypeException
1907
+	 * @throws InvalidInterfaceException
1908
+	 */
1909
+	protected function _process_transaction_payments(EE_Transaction $transaction)
1910
+	{
1911
+		/** @type EE_Transaction_Payments $transaction_payments */
1912
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
1913
+		// update the transaction with this payment
1914
+		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) {
1915
+			EE_Error::add_success(
1916
+				esc_html__(
1917
+					'The payment has been processed successfully.',
1918
+					'event_espresso'
1919
+				),
1920
+				__FILE__,
1921
+				__FUNCTION__,
1922
+				__LINE__
1923
+			);
1924
+		} else {
1925
+			EE_Error::add_error(
1926
+				esc_html__(
1927
+					'The payment was processed successfully but the amount paid for the transaction was not updated.',
1928
+					'event_espresso'
1929
+				),
1930
+				__FILE__,
1931
+				__FUNCTION__,
1932
+				__LINE__
1933
+			);
1934
+		}
1935
+	}
1936
+
1937
+
1938
+	/**
1939
+	 * _get_REG_IDs_to_apply_payment_to
1940
+	 * returns a list of registration IDs that the payment will apply to
1941
+	 *
1942
+	 * @param EE_Payment $payment
1943
+	 * @return array
1944
+	 * @throws EE_Error
1945
+	 * @throws InvalidArgumentException
1946
+	 * @throws InvalidDataTypeException
1947
+	 * @throws InvalidInterfaceException
1948
+	 * @throws ReflectionException
1949
+	 */
1950
+	protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment)
1951
+	{
1952
+		// grab array of IDs for specific registrations to apply changes to
1953
+		$REG_IDs = $this->request->getRequestParam('txn_admin_payment[registrations]', [], 'int', true);
1954
+		// nothing specified ? then get all reg IDs
1955
+		if (empty($REG_IDs)) {
1956
+			$registrations = $payment->transaction()->registrations();
1957
+			$REG_IDs       = ! empty($registrations)
1958
+				? array_keys($registrations)
1959
+				: $this->_get_existing_reg_payment_REG_IDs($payment);
1960
+		}
1961
+
1962
+		// ensure that REG_IDs are integers and NOT strings
1963
+		return array_map('intval', $REG_IDs);
1964
+	}
1965
+
1966
+
1967
+	/**
1968
+	 * @return array
1969
+	 */
1970
+	public function existing_reg_payment_REG_IDs()
1971
+	{
1972
+		return $this->_existing_reg_payment_REG_IDs;
1973
+	}
1974
+
1975
+
1976
+	/**
1977
+	 * @param array $existing_reg_payment_REG_IDs
1978
+	 */
1979
+	public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null)
1980
+	{
1981
+		$this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs;
1982
+	}
1983
+
1984
+
1985
+	/**
1986
+	 * _get_existing_reg_payment_REG_IDs
1987
+	 * returns a list of registration IDs that the payment is currently related to
1988
+	 * as recorded in the database
1989
+	 *
1990
+	 * @param EE_Payment $payment
1991
+	 * @return array
1992
+	 * @throws EE_Error
1993
+	 * @throws InvalidArgumentException
1994
+	 * @throws InvalidDataTypeException
1995
+	 * @throws InvalidInterfaceException
1996
+	 * @throws ReflectionException
1997
+	 */
1998
+	protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment)
1999
+	{
2000
+		if ($this->existing_reg_payment_REG_IDs() === null) {
2001
+			// let's get any existing reg payment records for this payment
2002
+			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration');
2003
+			// but we only want the REG IDs, so grab the array keys
2004
+			$existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs)
2005
+				? array_keys($existing_reg_payment_REG_IDs)
2006
+				: [];
2007
+			$this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs);
2008
+		}
2009
+
2010
+		return $this->existing_reg_payment_REG_IDs();
2011
+	}
2012
+
2013
+
2014
+	/**
2015
+	 * _remove_existing_registration_payments
2016
+	 * this calculates the difference between existing relations
2017
+	 * to the supplied payment and the new list registration IDs,
2018
+	 * removes any related registrations that no longer apply,
2019
+	 * and then updates the registration paid fields
2020
+	 *
2021
+	 * @param EE_Payment $payment
2022
+	 * @param int        $PAY_ID
2023
+	 * @return bool;
2024
+	 * @throws EE_Error
2025
+	 * @throws InvalidArgumentException
2026
+	 * @throws ReflectionException
2027
+	 * @throws InvalidDataTypeException
2028
+	 * @throws InvalidInterfaceException
2029
+	 */
2030
+	protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0)
2031
+	{
2032
+		// newly created payments will have nothing recorded for $PAY_ID
2033
+		if (absint($PAY_ID) === 0) {
2034
+			return false;
2035
+		}
2036
+		$existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2037
+		if (empty($existing_reg_payment_REG_IDs)) {
2038
+			return false;
2039
+		}
2040
+		/** @type EE_Transaction_Payments $transaction_payments */
2041
+		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2042
+
2043
+		return $transaction_payments->delete_registration_payments_and_update_registrations(
2044
+			$payment,
2045
+			[
2046
+				[
2047
+					'PAY_ID' => $payment->ID(),
2048
+					'REG_ID' => ['IN', $existing_reg_payment_REG_IDs],
2049
+				],
2050
+			]
2051
+		);
2052
+	}
2053
+
2054
+
2055
+	/**
2056
+	 * _update_registration_payments
2057
+	 * this applies the payments to the selected registrations
2058
+	 * but only if they have not already been paid for
2059
+	 *
2060
+	 * @param EE_Transaction $transaction
2061
+	 * @param EE_Payment     $payment
2062
+	 * @param array          $REG_IDs
2063
+	 * @return void
2064
+	 * @throws EE_Error
2065
+	 * @throws InvalidArgumentException
2066
+	 * @throws ReflectionException
2067
+	 * @throws RuntimeException
2068
+	 * @throws InvalidDataTypeException
2069
+	 * @throws InvalidInterfaceException
2070
+	 */
2071
+	protected function _update_registration_payments(
2072
+		EE_Transaction $transaction,
2073
+		EE_Payment $payment,
2074
+		$REG_IDs = []
2075
+	) {
2076
+		// we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments()
2077
+		// so let's do that using our set of REG_IDs from the form
2078
+		$registration_query_where_params = [
2079
+			'REG_ID' => ['IN', $REG_IDs],
2080
+		];
2081
+		// but add in some conditions regarding payment,
2082
+		// so that we don't apply payments to registrations that are free or have already been paid for
2083
+		// but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative )
2084
+		if (! $payment->is_a_refund()) {
2085
+			$registration_query_where_params['REG_final_price']  = ['!=', 0];
2086
+			$registration_query_where_params['REG_final_price*'] = ['!=', 'REG_paid', true];
2087
+		}
2088
+		$registrations = $transaction->registrations([$registration_query_where_params]);
2089
+		if (! empty($registrations)) {
2090
+			/** @type EE_Payment_Processor $payment_processor */
2091
+			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor');
2092
+			$payment_processor->process_registration_payments($transaction, $payment, $registrations);
2093
+		}
2094
+	}
2095
+
2096
+
2097
+	/**
2098
+	 * _process_registration_status_change
2099
+	 * This processes requested registration status changes for all the registrations
2100
+	 * on a given transaction and (optionally) sends out notifications for the changes.
2101
+	 *
2102
+	 * @param EE_Transaction $transaction
2103
+	 * @param array          $REG_IDs
2104
+	 * @return bool
2105
+	 * @throws EE_Error
2106
+	 * @throws InvalidArgumentException
2107
+	 * @throws ReflectionException
2108
+	 * @throws InvalidDataTypeException
2109
+	 * @throws InvalidInterfaceException
2110
+	 */
2111
+	protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = [])
2112
+	{
2113
+		// first if there is no change in status then we get out.
2114
+		$reg_status = $this->request->getRequestParam('txn_reg_status_change[reg_status]', 'NAN');
2115
+		if ($reg_status === 'NAN') {
2116
+			// no error message, no change requested, just nothing to do man.
2117
+			return false;
2118
+		}
2119
+		/** @type EE_Transaction_Processor $transaction_processor */
2120
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
2121
+
2122
+		// made it here dude?  Oh WOW.  K, let's take care of changing the statuses
2123
+		return $transaction_processor->manually_update_registration_statuses(
2124
+			$transaction,
2125
+			$reg_status,
2126
+			[['REG_ID' => ['IN', $REG_IDs]]]
2127
+		);
2128
+	}
2129
+
2130
+
2131
+	/**
2132
+	 * _build_payment_json_response
2133
+	 *
2134
+	 * @access public
2135
+	 * @param EE_Payment  $payment
2136
+	 * @param array       $REG_IDs
2137
+	 * @param bool | null $delete_txn_reg_status_change
2138
+	 * @return array
2139
+	 * @throws EE_Error
2140
+	 * @throws InvalidArgumentException
2141
+	 * @throws InvalidDataTypeException
2142
+	 * @throws InvalidInterfaceException
2143
+	 * @throws ReflectionException
2144
+	 */
2145
+	protected function _build_payment_json_response(
2146
+		EE_Payment $payment,
2147
+		$REG_IDs = [],
2148
+		$delete_txn_reg_status_change = null
2149
+	) {
2150
+		// was the payment deleted ?
2151
+		if (is_bool($delete_txn_reg_status_change)) {
2152
+			return [
2153
+				'PAY_ID'                       => $payment->ID(),
2154
+				'amount'                       => $payment->amount(),
2155
+				'total_paid'                   => $payment->transaction()->paid(),
2156
+				'txn_status'                   => $payment->transaction()->status_ID(),
2157
+				'pay_status'                   => $payment->STS_ID(),
2158
+				'registrations'                => $this->_registration_payment_data_array($REG_IDs),
2159
+				'delete_txn_reg_status_change' => $delete_txn_reg_status_change,
2160
+			];
2161
+		}
2162
+
2163
+		$this->_get_payment_status_array();
2164
+		return [
2165
+			'amount'           => $payment->amount(),
2166
+			'total_paid'       => $payment->transaction()->paid(),
2167
+			'txn_status'       => $payment->transaction()->status_ID(),
2168
+			'pay_status'       => $payment->STS_ID(),
2169
+			'PAY_ID'           => $payment->ID(),
2170
+			'STS_ID'           => $payment->STS_ID(),
2171
+			'status'           => self::$_pay_status[ $payment->STS_ID() ],
2172
+			'date'             => $payment->timestamp('Y-m-d', 'h:i a'),
2173
+			'method'           => strtoupper($payment->source()),
2174
+			'PM_ID'            => $payment->payment_method() ? $payment->payment_method()->ID() : 1,
2175
+			'gateway'          => $payment->payment_method()
2176
+				? $payment->payment_method()->admin_name()
2177
+				: esc_html__('Unknown', 'event_espresso'),
2178
+			'gateway_response' => $payment->gateway_response(),
2179
+			'txn_id_chq_nmbr'  => $payment->txn_id_chq_nmbr(),
2180
+			'po_number'        => $payment->po_number(),
2181
+			'extra_accntng'    => $payment->extra_accntng(),
2182
+			'registrations'    => $this->_registration_payment_data_array($REG_IDs),
2183
+		];
2184
+	}
2185
+
2186
+
2187
+	/**
2188
+	 * delete_payment
2189
+	 *    delete a payment or refund made towards a transaction
2190
+	 *
2191
+	 * @access public
2192
+	 * @return void
2193
+	 * @throws EE_Error
2194
+	 * @throws InvalidArgumentException
2195
+	 * @throws ReflectionException
2196
+	 * @throws InvalidDataTypeException
2197
+	 * @throws InvalidInterfaceException
2198
+	 */
2199
+	public function delete_payment()
2200
+	{
2201
+		$json_response_data = ['return_data' => false];
2202
+		$PAY_ID = $this->request->getRequestParam('delete_txn_admin_payment[PAY_ID]', 0, 'int');
2203
+
2204
+		$can_delete         = EE_Registry::instance()->CAP->current_user_can(
2205
+			'ee_delete_payments',
2206
+			'delete_payment_from_registration_details'
2207
+		);
2208
+		if ($PAY_ID && $can_delete) {
2209
+			$delete_txn_reg_status_change = $this->request->getRequestParam(
2210
+				'delete_txn_reg_status_change',
2211
+				false,
2212
+				'bool'
2213
+			);
2214
+			$payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID);
2215
+			if ($payment instanceof EE_Payment) {
2216
+				$REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment);
2217
+				/** @type EE_Transaction_Payments $transaction_payments */
2218
+				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments');
2219
+				if ($transaction_payments->delete_payment_and_update_transaction($payment)) {
2220
+					$json_response_data['return_data'] = $this->_build_payment_json_response(
2221
+						$payment,
2222
+						$REG_IDs,
2223
+						$delete_txn_reg_status_change
2224
+					);
2225
+					if ($delete_txn_reg_status_change) {
2226
+						// MAKE sure we also add the delete_txn_req_status_change to the
2227
+						// request data because that's how messages will be looking for it.
2228
+						$this->request->setRequestParam('txn_reg_status_change', $delete_txn_reg_status_change);
2229
+						$this->_maybe_send_notifications();
2230
+						$this->_process_registration_status_change($payment->transaction(), $REG_IDs);
2231
+					}
2232
+				}
2233
+			} else {
2234
+				EE_Error::add_error(
2235
+					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'),
2236
+					__FILE__,
2237
+					__FUNCTION__,
2238
+					__LINE__
2239
+				);
2240
+			}
2241
+		} elseif ($can_delete) {
2242
+			EE_Error::add_error(
2243
+				esc_html__(
2244
+					'A valid Payment ID was not received, therefore payment form data could not be loaded.',
2245
+					'event_espresso'
2246
+				),
2247
+				__FILE__,
2248
+				__FUNCTION__,
2249
+				__LINE__
2250
+			);
2251
+		} else {
2252
+			EE_Error::add_error(
2253
+				esc_html__(
2254
+					'You do not have access to delete a payment.',
2255
+					'event_espresso'
2256
+				),
2257
+				__FILE__,
2258
+				__FUNCTION__,
2259
+				__LINE__
2260
+			);
2261
+		}
2262
+		$notices              = EE_Error::get_notices(false, false, false);
2263
+		$this->_template_args = [
2264
+			'data'      => $json_response_data,
2265
+			'success'   => $notices['success'],
2266
+			'error'     => $notices['errors'],
2267
+			'attention' => $notices['attention'],
2268
+		];
2269
+		$this->_return_json();
2270
+	}
2271
+
2272
+
2273
+	/**
2274
+	 * _registration_payment_data_array
2275
+	 * adds info for 'owing' and 'paid' for each registration to the json response
2276
+	 *
2277
+	 * @access protected
2278
+	 * @param array $REG_IDs
2279
+	 * @return array
2280
+	 * @throws EE_Error
2281
+	 * @throws InvalidArgumentException
2282
+	 * @throws InvalidDataTypeException
2283
+	 * @throws InvalidInterfaceException
2284
+	 * @throws ReflectionException
2285
+	 */
2286
+	protected function _registration_payment_data_array($REG_IDs)
2287
+	{
2288
+		$registration_payment_data = [];
2289
+		// if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows.
2290
+		if (! empty($REG_IDs)) {
2291
+			$registrations = EEM_Registration::instance()->get_all([['REG_ID' => ['IN', $REG_IDs]]]);
2292
+			foreach ($registrations as $registration) {
2293
+				if ($registration instanceof EE_Registration) {
2294
+					$registration_payment_data[ $registration->ID() ] = [
2295
+						'paid'  => $registration->pretty_paid(),
2296
+						'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()),
2297
+					];
2298
+				}
2299
+			}
2300
+		}
2301
+
2302
+		return $registration_payment_data;
2303
+	}
2304
+
2305
+
2306
+	/**
2307
+	 * _maybe_send_notifications
2308
+	 * determines whether or not the admin has indicated that notifications should be sent.
2309
+	 * If so, will toggle a filter switch for delivering registration notices.
2310
+	 * If passed an EE_Payment object, then it will trigger payment notifications instead.
2311
+	 *
2312
+	 * @access protected
2313
+	 * @param EE_Payment | null $payment
2314
+	 */
2315
+	protected function _maybe_send_notifications($payment = null)
2316
+	{
2317
+		switch ($payment instanceof EE_Payment) {
2318
+			// payment notifications
2319
+			case true:
2320
+				if ($this->request->getRequestParam('txn_payments[send_notifications]', false, 'bool')) {
2321
+					$this->_process_payment_notification($payment);
2322
+				}
2323
+				break;
2324
+			// registration notifications
2325
+			case false:
2326
+				if ($this->request->getRequestParam('txn_reg_status_change[send_notifications]', false, 'bool')) {
2327
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true');
2328
+				}
2329
+				break;
2330
+		}
2331
+	}
2332
+
2333
+
2334
+	/**
2335
+	 * _send_payment_reminder
2336
+	 *    generates HTML for the View Transaction Details Admin page
2337
+	 *
2338
+	 * @access protected
2339
+	 * @return void
2340
+	 * @throws EE_Error
2341
+	 * @throws InvalidArgumentException
2342
+	 * @throws InvalidDataTypeException
2343
+	 * @throws InvalidInterfaceException
2344
+	 */
2345
+	protected function _send_payment_reminder()
2346
+	{
2347
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2348
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2349
+		$redirect_to = $this->request->getRequestParam('redirect_to');
2350
+		$query_args  = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2351
+		do_action(
2352
+			'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder',
2353
+			$transaction
2354
+		);
2355
+		$this->_redirect_after_action(
2356
+			false,
2357
+			esc_html__('payment reminder', 'event_espresso'),
2358
+			esc_html__('sent', 'event_espresso'),
2359
+			$query_args,
2360
+			true
2361
+		);
2362
+	}
2363
+
2364
+
2365
+	/**
2366
+	 *  get_transactions
2367
+	 *    get transactions for given parameters (used by list table)
2368
+	 *
2369
+	 * @param int     $per_page how many transactions displayed per page
2370
+	 * @param boolean $count   return the count or objects
2371
+	 * @param string  $view
2372
+	 * @return EE_Transaction[]|int int = count || array of transaction objects
2373
+	 * @throws EE_Error
2374
+	 * @throws InvalidArgumentException
2375
+	 * @throws InvalidDataTypeException
2376
+	 * @throws InvalidInterfaceException
2377
+	 */
2378
+	public function get_transactions($per_page, $count = false, $view = '')
2379
+	{
2380
+		$start_date = wp_strip_all_tags(
2381
+			$this->request->getRequestParam('txn-filter-start-date', date('m/d/Y', strtotime('-10 year')))
2382
+		);
2383
+		$end_date = wp_strip_all_tags(
2384
+			$this->request->getRequestParam('txn-filter-end-date', date('m/d/Y'))
2385
+		);
2386
+
2387
+		// make sure our timestamps start and end right at the boundaries for each day
2388
+		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00';
2389
+		$end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59';
2390
+
2391
+
2392
+		// convert to timestamps
2393
+		$start_date = strtotime($start_date);
2394
+		$end_date   = strtotime($end_date);
2395
+
2396
+		// makes sure start date is the lowest value and vice versa
2397
+		$start_date = min($start_date, $end_date);
2398
+		$end_date   = max($start_date, $end_date);
2399
+
2400
+		// convert to correct format for query
2401
+		$start_date = EEM_Transaction::instance()->convert_datetime_for_query(
2402
+			'TXN_timestamp',
2403
+			date('Y-m-d H:i:s', $start_date),
2404
+			'Y-m-d H:i:s'
2405
+		);
2406
+		$end_date   = EEM_Transaction::instance()->convert_datetime_for_query(
2407
+			'TXN_timestamp',
2408
+			date('Y-m-d H:i:s', $end_date),
2409
+			'Y-m-d H:i:s'
2410
+		);
2411
+
2412
+
2413
+		// set orderby
2414
+		$orderby = $this->request->getRequestParam('orderby');
2415
+
2416
+		switch ($orderby) {
2417
+			case 'TXN_ID':
2418
+				break;
2419
+			case 'ATT_fname':
2420
+				$orderby = 'Registration.Attendee.ATT_fname';
2421
+				break;
2422
+			case 'event_name':
2423
+				$orderby = 'Registration.Event.EVT_name';
2424
+				break;
2425
+			default: // 'TXN_timestamp'
2426
+				$orderby = 'TXN_timestamp';
2427
+		}
2428
+
2429
+		$sort         = $this->request->getRequestParam('order', 'DESC');
2430
+		$current_page = $this->request->getRequestParam('paged', 1, 'int');
2431
+
2432
+		$per_page = absint($per_page) ? $per_page : 10;
2433
+		$per_page = $this->request->getRequestParam('perpage', $per_page, 'int');
2434
+
2435
+		$offset = ($current_page - 1) * $per_page;
2436
+		$limit  = [$offset, $per_page];
2437
+
2438
+		$_where = [
2439
+			'TXN_timestamp'          => ['BETWEEN', [$start_date, $end_date]],
2440
+			'Registration.REG_count' => 1,
2441
+		];
2442
+
2443
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2444
+		if ($EVT_ID) {
2445
+			$_where['Registration.EVT_ID'] = $EVT_ID;
2446
+		}
2447
+
2448
+		$search_term = $this->request->getRequestParam('s');
2449
+		if ($search_term) {
2450
+			$search_term = '%' . $search_term . '%';
2451
+			$_where['OR']  = [
2452
+				'Registration.Event.EVT_name'         => ['LIKE', $search_term],
2453
+				'Registration.Event.EVT_desc'         => ['LIKE', $search_term],
2454
+				'Registration.Event.EVT_short_desc'   => ['LIKE', $search_term],
2455
+				'Registration.Attendee.ATT_full_name' => ['LIKE', $search_term],
2456
+				'Registration.Attendee.ATT_fname'     => ['LIKE', $search_term],
2457
+				'Registration.Attendee.ATT_lname'     => ['LIKE', $search_term],
2458
+				'Registration.Attendee.ATT_short_bio' => ['LIKE', $search_term],
2459
+				'Registration.Attendee.ATT_email'     => ['LIKE', $search_term],
2460
+				'Registration.Attendee.ATT_address'   => ['LIKE', $search_term],
2461
+				'Registration.Attendee.ATT_address2'  => ['LIKE', $search_term],
2462
+				'Registration.Attendee.ATT_city'      => ['LIKE', $search_term],
2463
+				'Registration.REG_final_price'        => ['LIKE', $search_term],
2464
+				'Registration.REG_code'               => ['LIKE', $search_term],
2465
+				'Registration.REG_count'              => ['LIKE', $search_term],
2466
+				'Registration.REG_group_size'         => ['LIKE', $search_term],
2467
+				'Registration.Ticket.TKT_name'        => ['LIKE', $search_term],
2468
+				'Registration.Ticket.TKT_description' => ['LIKE', $search_term],
2469
+				'Payment.PAY_source'                  => ['LIKE', $search_term],
2470
+				'Payment.Payment_Method.PMD_name'     => ['LIKE', $search_term],
2471
+				'TXN_session_data'                    => ['LIKE', $search_term],
2472
+				'Payment.PAY_txn_id_chq_nmbr'         => ['LIKE', $search_term],
2473
+			];
2474
+		}
2475
+
2476
+		$status = $this->request->getRequestParam('status');
2477
+		// failed transactions
2478
+		$failed     = (! empty($status) && $status === 'failed' && ! $count) || ($count && $view === 'failed');
2479
+		$abandoned  = (! empty($status) && $status === 'abandoned' && ! $count) || ($count && $view === 'abandoned');
2480
+		$incomplete = (! empty($status) && $status === 'incomplete' && ! $count) || ($count && $view === 'incomplete');
2481
+
2482
+		if ($failed) {
2483
+			$_where['STS_ID'] = EEM_Transaction::failed_status_code;
2484
+		} elseif ($abandoned) {
2485
+			$_where['STS_ID'] = EEM_Transaction::abandoned_status_code;
2486
+		} elseif ($incomplete) {
2487
+			$_where['STS_ID'] = EEM_Transaction::incomplete_status_code;
2488
+		} else {
2489
+			$_where['STS_ID']  = ['!=', EEM_Transaction::failed_status_code];
2490
+			$_where['STS_ID*'] = ['!=', EEM_Transaction::abandoned_status_code];
2491
+		}
2492
+
2493
+		$query_params = apply_filters(
2494
+			'FHEE__Transactions_Admin_Page___get_transactions_query_params',
2495
+			[
2496
+				$_where,
2497
+				'order_by'                 => [$orderby => $sort],
2498
+				'limit'                    => $limit,
2499
+				'default_where_conditions' => EEM_Base::default_where_conditions_this_only,
2500
+			],
2501
+			$this->request->requestParams(),
2502
+			$view,
2503
+			$count
2504
+		);
2505
+
2506
+		return $count
2507
+			? EEM_Transaction::instance()->count([$query_params[0]], 'TXN_ID', true)
2508
+			: EEM_Transaction::instance()->get_all($query_params);
2509
+	}
2510
+
2511
+
2512
+	/**
2513
+	 * @throws EE_Error
2514
+	 * @throws InvalidArgumentException
2515
+	 * @throws InvalidDataTypeException
2516
+	 * @throws InvalidInterfaceException
2517
+	 * @throws ReflectionException
2518
+	 * @throws RuntimeException
2519
+	 * @since 4.9.79.p
2520
+	 */
2521
+	public function recalculateLineItems()
2522
+	{
2523
+		$TXN_ID = $this->request->getRequestParam('TXN_ID', 0, 'int');
2524
+		/** @var EE_Transaction $transaction */
2525
+		$transaction     = EEM_Transaction::instance()->get_one_by_ID($TXN_ID);
2526
+		$success         = $transaction->recalculateLineItems();
2527
+		$redirect_to = $this->request->getRequestParam('redirect_to');
2528
+		$query_args = $redirect_to ? ['action' => $redirect_to, 'TXN_ID' => $TXN_ID,] : [];
2529
+		$this->_redirect_after_action(
2530
+			$success,
2531
+			esc_html__('Transaction taxes and totals', 'event_espresso'),
2532
+			esc_html__('recalculated', 'event_espresso'),
2533
+			$query_args,
2534
+			true
2535
+		);
2536
+	}
2537 2537
 }
Please login to merge, or discard this patch.
transactions/help_tabs/transactions_view_transaction.help_tab.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -8,15 +8,15 @@
 block discarded – undo
8 8
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong>
9 9
     <br />
10 10
     <?php esc_html_e(
11
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
12
-        'event_espresso'
13
-    ); ?>
11
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
12
+		'event_espresso'
13
+	); ?>
14 14
 </p>
15 15
 <p>
16 16
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong>
17 17
     <br />
18 18
     <?php esc_html_e(
19
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
20
-        'event_espresso'
21
-    ); ?>
19
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
20
+		'event_espresso'
21
+	); ?>
22 22
 </p>
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/transactions/help_tabs/transactions_overview.help_tab.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -8,15 +8,15 @@
 block discarded – undo
8 8
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong>
9 9
     <br />
10 10
     <?php esc_html_e(
11
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
12
-        'event_espresso'
13
-    ); ?>
11
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
12
+		'event_espresso'
13
+	); ?>
14 14
 </p>
15 15
 <p>
16 16
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong>
17 17
     <br />
18 18
     <?php esc_html_e(
19
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for transactions.',
20
-        'event_espresso'
21
-    ); ?>
19
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for transactions.',
20
+		'event_espresso'
21
+	); ?>
22 22
 </p>
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.6.2');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.29.rc.016');
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.10.29.rc.016');
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
 }
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2793 added lines, -2793 removed lines patch added patch discarded remove patch
@@ -16,2800 +16,2800 @@
 block discarded – undo
16 16
 class Events_Admin_Page extends EE_Admin_Page_CPT
17 17
 {
18 18
 
19
-    /**
20
-     * This will hold the event object for event_details screen.
19
+	/**
20
+	 * This will hold the event object for event_details screen.
21
+	 *
22
+	 * @var EE_Event $_event
23
+	 */
24
+	protected $_event;
25
+
26
+
27
+	/**
28
+	 * This will hold the category object for category_details screen.
29
+	 *
30
+	 * @var stdClass $_category
31
+	 */
32
+	protected $_category;
33
+
34
+
35
+	/**
36
+	 * This will hold the event model instance
37
+	 *
38
+	 * @var EEM_Event $_event_model
39
+	 */
40
+	protected $_event_model;
41
+
42
+
43
+	/**
44
+	 * @var EE_Event
45
+	 */
46
+	protected $_cpt_model_obj = false;
47
+
48
+
49
+	/**
50
+	 * @var NodeGroupDao
51
+	 */
52
+	protected $model_obj_node_group_persister;
53
+
54
+
55
+	/**
56
+	 * Initialize page props for this admin page group.
57
+	 */
58
+	protected function _init_page_props()
59
+	{
60
+		$this->page_slug        = EVENTS_PG_SLUG;
61
+		$this->page_label       = EVENTS_LABEL;
62
+		$this->_admin_base_url  = EVENTS_ADMIN_URL;
63
+		$this->_admin_base_path = EVENTS_ADMIN;
64
+		$this->_cpt_model_names = [
65
+			'create_new' => 'EEM_Event',
66
+			'edit'       => 'EEM_Event',
67
+		];
68
+		$this->_cpt_edit_routes = [
69
+			'espresso_events' => 'edit',
70
+		];
71
+		add_action(
72
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
+			[$this, 'verify_event_edit'],
74
+			10,
75
+			2
76
+		);
77
+	}
78
+
79
+
80
+	/**
81
+	 * Sets the ajax hooks used for this admin page group.
82
+	 */
83
+	protected function _ajax_hooks()
84
+	{
85
+		add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
+	}
87
+
88
+
89
+	/**
90
+	 * Sets the page properties for this admin page group.
91
+	 */
92
+	protected function _define_page_props()
93
+	{
94
+		$this->_admin_page_title = EVENTS_LABEL;
95
+		$this->_labels           = [
96
+			'buttons'      => [
97
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
98
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
+			],
104
+			'editor_title' => [
105
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
+			],
107
+			'publishbox'   => [
108
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
110
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
+			],
114
+		];
115
+	}
116
+
117
+
118
+	/**
119
+	 * Sets the page routes property for this admin page group.
120
+	 */
121
+	protected function _set_page_routes()
122
+	{
123
+		// load formatter helper
124
+		// load field generator helper
125
+		// is there a evt_id in the request?
126
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
+		$EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
+
129
+		$this->_page_routes = [
130
+			'default'                       => [
131
+				'func'       => '_events_overview_list_table',
132
+				'capability' => 'ee_read_events',
133
+			],
134
+			'create_new'                    => [
135
+				'func'       => '_create_new_cpt_item',
136
+				'capability' => 'ee_edit_events',
137
+			],
138
+			'edit'                          => [
139
+				'func'       => '_edit_cpt_item',
140
+				'capability' => 'ee_edit_event',
141
+				'obj_id'     => $EVT_ID,
142
+			],
143
+			'copy_event'                    => [
144
+				'func'       => '_copy_events',
145
+				'capability' => 'ee_edit_event',
146
+				'obj_id'     => $EVT_ID,
147
+				'noheader'   => true,
148
+			],
149
+			'trash_event'                   => [
150
+				'func'       => '_trash_or_restore_event',
151
+				'args'       => ['event_status' => 'trash'],
152
+				'capability' => 'ee_delete_event',
153
+				'obj_id'     => $EVT_ID,
154
+				'noheader'   => true,
155
+			],
156
+			'trash_events'                  => [
157
+				'func'       => '_trash_or_restore_events',
158
+				'args'       => ['event_status' => 'trash'],
159
+				'capability' => 'ee_delete_events',
160
+				'noheader'   => true,
161
+			],
162
+			'restore_event'                 => [
163
+				'func'       => '_trash_or_restore_event',
164
+				'args'       => ['event_status' => 'draft'],
165
+				'capability' => 'ee_delete_event',
166
+				'obj_id'     => $EVT_ID,
167
+				'noheader'   => true,
168
+			],
169
+			'restore_events'                => [
170
+				'func'       => '_trash_or_restore_events',
171
+				'args'       => ['event_status' => 'draft'],
172
+				'capability' => 'ee_delete_events',
173
+				'noheader'   => true,
174
+			],
175
+			'delete_event'                  => [
176
+				'func'       => '_delete_event',
177
+				'capability' => 'ee_delete_event',
178
+				'obj_id'     => $EVT_ID,
179
+				'noheader'   => true,
180
+			],
181
+			'delete_events'                 => [
182
+				'func'       => '_delete_events',
183
+				'capability' => 'ee_delete_events',
184
+				'noheader'   => true,
185
+			],
186
+			'view_report'                   => [
187
+				'func'       => '_view_report',
188
+				'capability' => 'ee_edit_events',
189
+			],
190
+			'default_event_settings'        => [
191
+				'func'       => '_default_event_settings',
192
+				'capability' => 'manage_options',
193
+			],
194
+			'update_default_event_settings' => [
195
+				'func'       => '_update_default_event_settings',
196
+				'capability' => 'manage_options',
197
+				'noheader'   => true,
198
+			],
199
+			'template_settings'             => [
200
+				'func'       => '_template_settings',
201
+				'capability' => 'manage_options',
202
+			],
203
+			// event category tab related
204
+			'add_category'                  => [
205
+				'func'       => '_category_details',
206
+				'capability' => 'ee_edit_event_category',
207
+				'args'       => ['add'],
208
+			],
209
+			'edit_category'                 => [
210
+				'func'       => '_category_details',
211
+				'capability' => 'ee_edit_event_category',
212
+				'args'       => ['edit'],
213
+			],
214
+			'delete_categories'             => [
215
+				'func'       => '_delete_categories',
216
+				'capability' => 'ee_delete_event_category',
217
+				'noheader'   => true,
218
+			],
219
+			'delete_category'               => [
220
+				'func'       => '_delete_categories',
221
+				'capability' => 'ee_delete_event_category',
222
+				'noheader'   => true,
223
+			],
224
+			'insert_category'               => [
225
+				'func'       => '_insert_or_update_category',
226
+				'args'       => ['new_category' => true],
227
+				'capability' => 'ee_edit_event_category',
228
+				'noheader'   => true,
229
+			],
230
+			'update_category'               => [
231
+				'func'       => '_insert_or_update_category',
232
+				'args'       => ['new_category' => false],
233
+				'capability' => 'ee_edit_event_category',
234
+				'noheader'   => true,
235
+			],
236
+			'category_list'                 => [
237
+				'func'       => '_category_list_table',
238
+				'capability' => 'ee_manage_event_categories',
239
+			],
240
+			'preview_deletion'              => [
241
+				'func'       => 'previewDeletion',
242
+				'capability' => 'ee_delete_events',
243
+			],
244
+			'confirm_deletion'              => [
245
+				'func'       => 'confirmDeletion',
246
+				'capability' => 'ee_delete_events',
247
+				'noheader'   => true,
248
+			],
249
+		];
250
+	}
251
+
252
+
253
+	/**
254
+	 * Set the _page_config property for this admin page group.
255
+	 */
256
+	protected function _set_page_config()
257
+	{
258
+		$post_id            = $this->request->getRequestParam('post', 0, 'int');
259
+		$EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
+		$this->_page_config = [
261
+			'default'                => [
262
+				'nav'           => [
263
+					'label' => esc_html__('Overview', 'event_espresso'),
264
+					'order' => 10,
265
+				],
266
+				'list_table'    => 'Events_Admin_List_Table',
267
+				'help_tabs'     => [
268
+					'events_overview_help_tab'                       => [
269
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
270
+						'filename' => 'events_overview',
271
+					],
272
+					'events_overview_table_column_headings_help_tab' => [
273
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
+						'filename' => 'events_overview_table_column_headings',
275
+					],
276
+					'events_overview_filters_help_tab'               => [
277
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
+						'filename' => 'events_overview_filters',
279
+					],
280
+					'events_overview_view_help_tab'                  => [
281
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
+						'filename' => 'events_overview_views',
283
+					],
284
+					'events_overview_other_help_tab'                 => [
285
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
+						'filename' => 'events_overview_other',
287
+					],
288
+				],
289
+				'qtips'         => [
290
+					'EE_Event_List_Table_Tips',
291
+				],
292
+				'require_nonce' => false,
293
+			],
294
+			'create_new'             => [
295
+				'nav'           => [
296
+					'label'      => esc_html__('Add Event', 'event_espresso'),
297
+					'order'      => 5,
298
+					'persistent' => false,
299
+				],
300
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
301
+				'help_tabs'     => [
302
+					'event_editor_help_tab'                            => [
303
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
304
+						'filename' => 'event_editor',
305
+					],
306
+					'event_editor_title_richtexteditor_help_tab'       => [
307
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
308
+						'filename' => 'event_editor_title_richtexteditor',
309
+					],
310
+					'event_editor_venue_details_help_tab'              => [
311
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
312
+						'filename' => 'event_editor_venue_details',
313
+					],
314
+					'event_editor_event_datetimes_help_tab'            => [
315
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
316
+						'filename' => 'event_editor_event_datetimes',
317
+					],
318
+					'event_editor_event_tickets_help_tab'              => [
319
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
320
+						'filename' => 'event_editor_event_tickets',
321
+					],
322
+					'event_editor_event_registration_options_help_tab' => [
323
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
324
+						'filename' => 'event_editor_event_registration_options',
325
+					],
326
+					'event_editor_tags_categories_help_tab'            => [
327
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
328
+						'filename' => 'event_editor_tags_categories',
329
+					],
330
+					'event_editor_questions_registrants_help_tab'      => [
331
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
332
+						'filename' => 'event_editor_questions_registrants',
333
+					],
334
+					'event_editor_save_new_event_help_tab'             => [
335
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
336
+						'filename' => 'event_editor_save_new_event',
337
+					],
338
+					'event_editor_other_help_tab'                      => [
339
+						'title'    => esc_html__('Event Other', 'event_espresso'),
340
+						'filename' => 'event_editor_other',
341
+					],
342
+				],
343
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
344
+				'require_nonce' => false,
345
+			],
346
+			'edit'                   => [
347
+				'nav'           => [
348
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
349
+					'order'      => 5,
350
+					'persistent' => false,
351
+					'url'        => $post_id
352
+						? EE_Admin_Page::add_query_args_and_nonce(
353
+							['post' => $post_id, 'action' => 'edit'],
354
+							$this->_current_page_view_url
355
+						)
356
+						: $this->_admin_base_url,
357
+				],
358
+				'metaboxes'     => ['_register_event_editor_meta_boxes'],
359
+				'help_tabs'     => [
360
+					'event_editor_help_tab'                            => [
361
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
362
+						'filename' => 'event_editor',
363
+					],
364
+					'event_editor_title_richtexteditor_help_tab'       => [
365
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
366
+						'filename' => 'event_editor_title_richtexteditor',
367
+					],
368
+					'event_editor_venue_details_help_tab'              => [
369
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
370
+						'filename' => 'event_editor_venue_details',
371
+					],
372
+					'event_editor_event_datetimes_help_tab'            => [
373
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
374
+						'filename' => 'event_editor_event_datetimes',
375
+					],
376
+					'event_editor_event_tickets_help_tab'              => [
377
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
378
+						'filename' => 'event_editor_event_tickets',
379
+					],
380
+					'event_editor_event_registration_options_help_tab' => [
381
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
382
+						'filename' => 'event_editor_event_registration_options',
383
+					],
384
+					'event_editor_tags_categories_help_tab'            => [
385
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
386
+						'filename' => 'event_editor_tags_categories',
387
+					],
388
+					'event_editor_questions_registrants_help_tab'      => [
389
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
390
+						'filename' => 'event_editor_questions_registrants',
391
+					],
392
+					'event_editor_save_new_event_help_tab'             => [
393
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
394
+						'filename' => 'event_editor_save_new_event',
395
+					],
396
+					'event_editor_other_help_tab'                      => [
397
+						'title'    => esc_html__('Event Other', 'event_espresso'),
398
+						'filename' => 'event_editor_other',
399
+					],
400
+				],
401
+				'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
402
+				'require_nonce' => false,
403
+			],
404
+			'default_event_settings' => [
405
+				'nav'           => [
406
+					'label' => esc_html__('Default Settings', 'event_espresso'),
407
+					'order' => 40,
408
+				],
409
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
410
+				'labels'        => [
411
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
412
+				],
413
+				'help_tabs'     => [
414
+					'default_settings_help_tab'        => [
415
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
416
+						'filename' => 'events_default_settings',
417
+					],
418
+					'default_settings_status_help_tab' => [
419
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
420
+						'filename' => 'events_default_settings_status',
421
+					],
422
+					'default_maximum_tickets_help_tab' => [
423
+						'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
424
+						'filename' => 'events_default_settings_max_tickets',
425
+					],
426
+				],
427
+				'require_nonce' => false,
428
+			],
429
+			// template settings
430
+			'template_settings'      => [
431
+				'nav'           => [
432
+					'label' => esc_html__('Templates', 'event_espresso'),
433
+					'order' => 30,
434
+				],
435
+				'metaboxes'     => $this->_default_espresso_metaboxes,
436
+				'help_tabs'     => [
437
+					'general_settings_templates_help_tab' => [
438
+						'title'    => esc_html__('Templates', 'event_espresso'),
439
+						'filename' => 'general_settings_templates',
440
+					],
441
+				],
442
+				'require_nonce' => false,
443
+			],
444
+			// event category stuff
445
+			'add_category'           => [
446
+				'nav'           => [
447
+					'label'      => esc_html__('Add Category', 'event_espresso'),
448
+					'order'      => 15,
449
+					'persistent' => false,
450
+				],
451
+				'help_tabs'     => [
452
+					'add_category_help_tab' => [
453
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
454
+						'filename' => 'events_add_category',
455
+					],
456
+				],
457
+				'metaboxes'     => ['_publish_post_box'],
458
+				'require_nonce' => false,
459
+			],
460
+			'edit_category'          => [
461
+				'nav'           => [
462
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
463
+					'order'      => 15,
464
+					'persistent' => false,
465
+					'url'        => $EVT_CAT_ID
466
+						? add_query_arg(
467
+							['EVT_CAT_ID' => $EVT_CAT_ID],
468
+							$this->_current_page_view_url
469
+						)
470
+						: $this->_admin_base_url,
471
+				],
472
+				'help_tabs'     => [
473
+					'edit_category_help_tab' => [
474
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
475
+						'filename' => 'events_edit_category',
476
+					],
477
+				],
478
+				'metaboxes'     => ['_publish_post_box'],
479
+				'require_nonce' => false,
480
+			],
481
+			'category_list'          => [
482
+				'nav'           => [
483
+					'label' => esc_html__('Categories', 'event_espresso'),
484
+					'order' => 20,
485
+				],
486
+				'list_table'    => 'Event_Categories_Admin_List_Table',
487
+				'help_tabs'     => [
488
+					'events_categories_help_tab'                       => [
489
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
490
+						'filename' => 'events_categories',
491
+					],
492
+					'events_categories_table_column_headings_help_tab' => [
493
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
494
+						'filename' => 'events_categories_table_column_headings',
495
+					],
496
+					'events_categories_view_help_tab'                  => [
497
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
498
+						'filename' => 'events_categories_views',
499
+					],
500
+					'events_categories_other_help_tab'                 => [
501
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
502
+						'filename' => 'events_categories_other',
503
+					],
504
+				],
505
+				'metaboxes'     => $this->_default_espresso_metaboxes,
506
+				'require_nonce' => false,
507
+			],
508
+			'preview_deletion'       => [
509
+				'nav'           => [
510
+					'label'      => esc_html__('Preview Deletion', 'event_espresso'),
511
+					'order'      => 15,
512
+					'persistent' => false,
513
+					'url'        => '',
514
+				],
515
+				'require_nonce' => false,
516
+			],
517
+		];
518
+	}
519
+
520
+
521
+	/**
522
+	 * Used to register any global screen options if necessary for every route in this admin page group.
523
+	 */
524
+	protected function _add_screen_options()
525
+	{
526
+	}
527
+
528
+
529
+	/**
530
+	 * Implementing the screen options for the 'default' route.
531
+	 */
532
+	protected function _add_screen_options_default()
533
+	{
534
+		$this->_per_page_screen_option();
535
+	}
536
+
537
+
538
+	/**
539
+	 * Implementing screen options for the category list route.
540
+	 */
541
+	protected function _add_screen_options_category_list()
542
+	{
543
+		$page_title              = $this->_admin_page_title;
544
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
545
+		$this->_per_page_screen_option();
546
+		$this->_admin_page_title = $page_title;
547
+	}
548
+
549
+
550
+	/**
551
+	 * Used to register any global feature pointers for the admin page group.
552
+	 */
553
+	protected function _add_feature_pointers()
554
+	{
555
+	}
556
+
557
+
558
+	/**
559
+	 * Registers and enqueues any global scripts and styles for the entire admin page group.
560
+	 */
561
+	public function load_scripts_styles()
562
+	{
563
+		wp_register_style(
564
+			'events-admin-css',
565
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
566
+			[],
567
+			EVENT_ESPRESSO_VERSION
568
+		);
569
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
570
+		wp_enqueue_style('events-admin-css');
571
+		wp_enqueue_style('ee-cat-admin');
572
+		// todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
573
+		// registers for all views
574
+		// scripts
575
+		wp_register_script(
576
+			'event_editor_js',
577
+			EVENTS_ASSETS_URL . 'event_editor.js',
578
+			['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
579
+			EVENT_ESPRESSO_VERSION,
580
+			true
581
+		);
582
+	}
583
+
584
+
585
+	/**
586
+	 * Enqueuing scripts and styles specific to this view
587
+	 */
588
+	public function load_scripts_styles_create_new()
589
+	{
590
+		$this->load_scripts_styles_edit();
591
+	}
592
+
593
+
594
+	/**
595
+	 * Enqueuing scripts and styles specific to this view
596
+	 */
597
+	public function load_scripts_styles_edit()
598
+	{
599
+		// styles
600
+		wp_enqueue_style('espresso-ui-theme');
601
+		wp_register_style(
602
+			'event-editor-css',
603
+			EVENTS_ASSETS_URL . 'event-editor.css',
604
+			['ee-admin-css'],
605
+			EVENT_ESPRESSO_VERSION
606
+		);
607
+		wp_enqueue_style('event-editor-css');
608
+		// scripts
609
+		wp_register_script(
610
+			'event-datetime-metabox',
611
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
612
+			['event_editor_js', 'ee-datepicker'],
613
+			EVENT_ESPRESSO_VERSION
614
+		);
615
+		wp_enqueue_script('event-datetime-metabox');
616
+	}
617
+
618
+
619
+	/**
620
+	 * Populating the _views property for the category list table view.
621
+	 */
622
+	protected function _set_list_table_views_category_list()
623
+	{
624
+		$this->_views = [
625
+			'all' => [
626
+				'slug'        => 'all',
627
+				'label'       => esc_html__('All', 'event_espresso'),
628
+				'count'       => 0,
629
+				'bulk_action' => [
630
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
631
+				],
632
+			],
633
+		];
634
+	}
635
+
636
+
637
+	/**
638
+	 * For adding anything that fires on the admin_init hook for any route within this admin page group.
639
+	 */
640
+	public function admin_init()
641
+	{
642
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
643
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
644
+			'event_espresso'
645
+		);
646
+	}
647
+
648
+
649
+	/**
650
+	 * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
651
+	 * group.
652
+	 */
653
+	public function admin_notices()
654
+	{
655
+	}
656
+
657
+
658
+	/**
659
+	 * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
660
+	 * this admin page group.
661
+	 */
662
+	public function admin_footer_scripts()
663
+	{
664
+	}
665
+
666
+
667
+	/**
668
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
669
+	 * warning (via EE_Error::add_error());
670
+	 *
671
+	 * @param EE_Event $event Event object
672
+	 * @param string   $req_type
673
+	 * @return void
674
+	 * @throws EE_Error
675
+	 * @throws ReflectionException
676
+	 */
677
+	public function verify_event_edit($event = null, $req_type = '')
678
+	{
679
+		// don't need to do this when processing
680
+		if (! empty($req_type)) {
681
+			return;
682
+		}
683
+		// no event?
684
+		if (empty($event)) {
685
+			// set event
686
+			$event = $this->_cpt_model_obj;
687
+		}
688
+		// STILL no event?
689
+		if (! $event instanceof EE_Event) {
690
+			return;
691
+		}
692
+		$orig_status = $event->status();
693
+		// first check if event is active.
694
+		if (
695
+			$orig_status === EEM_Event::cancelled
696
+			|| $orig_status === EEM_Event::postponed
697
+			|| $event->is_expired()
698
+			|| $event->is_inactive()
699
+		) {
700
+			return;
701
+		}
702
+		// made it here so it IS active... next check that any of the tickets are sold.
703
+		if ($event->is_sold_out(true)) {
704
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
705
+				EE_Error::add_attention(
706
+					sprintf(
707
+						esc_html__(
708
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
709
+							'event_espresso'
710
+						),
711
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
712
+					)
713
+				);
714
+			}
715
+			return;
716
+		} elseif ($orig_status === EEM_Event::sold_out) {
717
+			EE_Error::add_attention(
718
+				sprintf(
719
+					esc_html__(
720
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
721
+						'event_espresso'
722
+					),
723
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
724
+				)
725
+			);
726
+		}
727
+		// now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
728
+		if (! $event->tickets_on_sale()) {
729
+			return;
730
+		}
731
+		// made it here so show warning
732
+		$this->_edit_event_warning();
733
+	}
734
+
735
+
736
+	/**
737
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
738
+	 * When needed, hook this into a EE_Error::add_error() notice.
739
+	 *
740
+	 * @access protected
741
+	 * @return void
742
+	 */
743
+	protected function _edit_event_warning()
744
+	{
745
+		// we don't want to add warnings during these requests
746
+		if ($this->request->getRequestParam('action') === 'editpost') {
747
+			return;
748
+		}
749
+		EE_Error::add_attention(
750
+			sprintf(
751
+				esc_html__(
752
+					'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
753
+					'event_espresso'
754
+				),
755
+				'<a class="espresso-help-tab-lnk">',
756
+				'</a>'
757
+			)
758
+		);
759
+	}
760
+
761
+
762
+	/**
763
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
764
+	 * Otherwise, do the normal logic
765
+	 *
766
+	 * @return void
767
+	 * @throws EE_Error
768
+	 */
769
+	protected function _create_new_cpt_item()
770
+	{
771
+		$has_timezone_string = get_option('timezone_string');
772
+		// only nag them about setting their timezone if it's their first event, and they haven't already done it
773
+		if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
774
+			EE_Error::add_attention(
775
+				sprintf(
776
+					esc_html__(
777
+						'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
778
+						'event_espresso'
779
+					),
780
+					'<br>',
781
+					'<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
782
+					. EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
783
+					. '</select>',
784
+					'<button class="button button-secondary timezone-submit">',
785
+					'</button><span class="spinner"></span>'
786
+				),
787
+				__FILE__,
788
+				__FUNCTION__,
789
+				__LINE__
790
+			);
791
+		}
792
+		parent::_create_new_cpt_item();
793
+	}
794
+
795
+
796
+	/**
797
+	 * Sets the _views property for the default route in this admin page group.
798
+	 */
799
+	protected function _set_list_table_views_default()
800
+	{
801
+		$this->_views = [
802
+			'all'   => [
803
+				'slug'        => 'all',
804
+				'label'       => esc_html__('View All Events', 'event_espresso'),
805
+				'count'       => 0,
806
+				'bulk_action' => [
807
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
808
+				],
809
+			],
810
+			'draft' => [
811
+				'slug'        => 'draft',
812
+				'label'       => esc_html__('Draft', 'event_espresso'),
813
+				'count'       => 0,
814
+				'bulk_action' => [
815
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
816
+				],
817
+			],
818
+		];
819
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
820
+			$this->_views['trash'] = [
821
+				'slug'        => 'trash',
822
+				'label'       => esc_html__('Trash', 'event_espresso'),
823
+				'count'       => 0,
824
+				'bulk_action' => [
825
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
826
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
827
+				],
828
+			];
829
+		}
830
+	}
831
+
832
+
833
+	/**
834
+	 * Provides the legend item array for the default list table view.
835
+	 *
836
+	 * @return array
837
+	 * @throws EE_Error
838
+	 * @throws EE_Error
839
+	 */
840
+	protected function _event_legend_items()
841
+	{
842
+		$items    = [
843
+			'view_details'   => [
844
+				'class' => 'dashicons dashicons-search',
845
+				'desc'  => esc_html__('View Event', 'event_espresso'),
846
+			],
847
+			'edit_event'     => [
848
+				'class' => 'ee-icon ee-icon-calendar-edit',
849
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
850
+			],
851
+			'view_attendees' => [
852
+				'class' => 'dashicons dashicons-groups',
853
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
854
+			],
855
+		];
856
+		$items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
857
+		$statuses = [
858
+			'sold_out_status'  => [
859
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
860
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
861
+			],
862
+			'active_status'    => [
863
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
864
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
865
+			],
866
+			'upcoming_status'  => [
867
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
868
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
869
+			],
870
+			'postponed_status' => [
871
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
872
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
873
+			],
874
+			'cancelled_status' => [
875
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
876
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
877
+			],
878
+			'expired_status'   => [
879
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
880
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
881
+			],
882
+			'inactive_status'  => [
883
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
884
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
885
+			],
886
+		];
887
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
888
+		return array_merge($items, $statuses);
889
+	}
890
+
891
+
892
+	/**
893
+	 * @return EEM_Event
894
+	 * @throws EE_Error
895
+	 * @throws ReflectionException
896
+	 */
897
+	private function _event_model()
898
+	{
899
+		if (! $this->_event_model instanceof EEM_Event) {
900
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
901
+		}
902
+		return $this->_event_model;
903
+	}
904
+
905
+
906
+	/**
907
+	 * Adds extra buttons to the WP CPT permalink field row.
908
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
909
+	 *
910
+	 * @param string $return    the current html
911
+	 * @param int    $id        the post id for the page
912
+	 * @param string $new_title What the title is
913
+	 * @param string $new_slug  what the slug is
914
+	 * @return string            The new html string for the permalink area
915
+	 */
916
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
917
+	{
918
+		// make sure this is only when editing
919
+		if (! empty($id)) {
920
+			$post   = get_post($id);
921
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
922
+					   . esc_html__('Shortcode', 'event_espresso')
923
+					   . '</a> ';
924
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
925
+					   . $post->ID
926
+					   . ']">';
927
+		}
928
+		return $return;
929
+	}
930
+
931
+
932
+	/**
933
+	 * _events_overview_list_table
934
+	 * This contains the logic for showing the events_overview list
935
+	 *
936
+	 * @access protected
937
+	 * @return void
938
+	 * @throws EE_Error
939
+	 */
940
+	protected function _events_overview_list_table()
941
+	{
942
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
943
+		$this->_template_args['after_list_table']                           =
944
+			! empty($this->_template_args['after_list_table'])
945
+				? (array) $this->_template_args['after_list_table']
946
+				: [];
947
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
948
+			. EEH_Template::get_button_or_link(
949
+				get_post_type_archive_link('espresso_events'),
950
+				esc_html__("View Event Archive Page", "event_espresso"),
951
+				'button'
952
+			);
953
+		$this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
954
+			$this->_event_legend_items()
955
+		);
956
+		$this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
957
+			'create_new',
958
+			'add',
959
+			[],
960
+			'add-new-h2'
961
+		);
962
+		$this->display_admin_list_table_page_with_no_sidebar();
963
+	}
964
+
965
+
966
+	/**
967
+	 * this allows for extra misc actions in the default WP publish box
968
+	 *
969
+	 * @return void
970
+	 * @throws EE_Error
971
+	 * @throws ReflectionException
972
+	 */
973
+	public function extra_misc_actions_publish_box()
974
+	{
975
+		$this->_generate_publish_box_extra_content();
976
+	}
977
+
978
+
979
+	/**
980
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
981
+	 * saved.
982
+	 * Typically you would use this to save any additional data.
983
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
984
+	 * ALSO very important.  When a post transitions from scheduled to published,
985
+	 * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
986
+	 * other meta saves. So MAKE sure that you handle this accordingly.
987
+	 *
988
+	 * @access protected
989
+	 * @abstract
990
+	 * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
991
+	 * @param object $post    The post object of the cpt that was saved.
992
+	 * @return void
993
+	 * @throws EE_Error
994
+	 * @throws ReflectionException
995
+	 */
996
+	protected function _insert_update_cpt_item($post_id, $post)
997
+	{
998
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
999
+			// get out we're not processing an event save.
1000
+			return;
1001
+		}
1002
+
1003
+		$event_values = [
1004
+			'EVT_display_desc'                => $this->request->getRequestParam('display_desc', false, 'bool'),
1005
+			'EVT_display_ticket_selector'     => $this->request->getRequestParam(
1006
+				'display_ticket_selector',
1007
+				false,
1008
+				'bool'
1009
+			),
1010
+			'EVT_additional_limit'            => min(
1011
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1012
+				$this->request->getRequestParam('additional_limit', null, 'int')
1013
+			),
1014
+			'EVT_default_registration_status' => $this->request->getRequestParam(
1015
+				'EVT_default_registration_status',
1016
+				EE_Registry::instance()->CFG->registration->default_STS_ID
1017
+			),
1018
+
1019
+			'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1020
+			'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1021
+			'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1022
+			'EVT_external_URL'    => $this->request->getRequestParam('externalURL'),
1023
+			'EVT_phone'           => $this->request->getRequestParam('event_phone'),
1024
+		];
1025
+		// update event
1026
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
1027
+		// get event_object for other metaboxes...
1028
+		// though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1029
+		// i have to setup where conditions to override the filters in the model
1030
+		// that filter out autodraft and inherit statuses so we GET the inherit id!
1031
+		$event = $this->_event_model()->get_one(
1032
+			[
1033
+				[
1034
+					$this->_event_model()->primary_key_name() => $post_id,
1035
+					'OR'                                      => [
1036
+						'status'   => $post->post_status,
1037
+						// if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1038
+						// but the returned object here has a status of "publish", so use the original post status as well
1039
+						'status*1' => $this->request->getRequestParam('original_post_status'),
1040
+					],
1041
+				],
1042
+			]
1043
+		);
1044
+		// the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1045
+		$event_update_callbacks = apply_filters(
1046
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1047
+			[
1048
+				[$this, '_default_venue_update'],
1049
+				[$this, '_default_tickets_update'],
1050
+			]
1051
+		);
1052
+		$att_success            = true;
1053
+		foreach ($event_update_callbacks as $e_callback) {
1054
+			$_success = is_callable($e_callback)
1055
+				? call_user_func($e_callback, $event, $this->request->requestParams())
1056
+				: false;
1057
+			// if ANY of these updates fail then we want the appropriate global error message
1058
+			$att_success = ! $att_success ? $att_success : $_success;
1059
+		}
1060
+		// any errors?
1061
+		if ($success && false === $att_success) {
1062
+			EE_Error::add_error(
1063
+				esc_html__(
1064
+					'Event Details saved successfully but something went wrong with saving attachments.',
1065
+					'event_espresso'
1066
+				),
1067
+				__FILE__,
1068
+				__FUNCTION__,
1069
+				__LINE__
1070
+			);
1071
+		} elseif ($success === false) {
1072
+			EE_Error::add_error(
1073
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1074
+				__FILE__,
1075
+				__FUNCTION__,
1076
+				__LINE__
1077
+			);
1078
+		}
1079
+	}
1080
+
1081
+
1082
+	/**
1083
+	 * @param int $post_id
1084
+	 * @param int $revision_id
1085
+	 * @throws EE_Error
1086
+	 * @throws EE_Error
1087
+	 * @throws ReflectionException
1088
+	 * @see parent::restore_item()
1089
+	 */
1090
+	protected function _restore_cpt_item($post_id, $revision_id)
1091
+	{
1092
+		// copy existing event meta to new post
1093
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1094
+		if ($post_evt instanceof EE_Event) {
1095
+			// meta revision restore
1096
+			$post_evt->restore_revision($revision_id);
1097
+			// related objs restore
1098
+			$post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1099
+		}
1100
+	}
1101
+
1102
+
1103
+	/**
1104
+	 * Attach the venue to the Event
1105
+	 *
1106
+	 * @param EE_Event $event Event Object to add the venue to
1107
+	 * @param array    $data  The request data from the form
1108
+	 * @return bool           Success or fail.
1109
+	 * @throws EE_Error
1110
+	 * @throws ReflectionException
1111
+	 */
1112
+	protected function _default_venue_update(EE_Event $event, $data)
1113
+	{
1114
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1115
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1116
+		$venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1117
+		// very important.  If we don't have a venue name...
1118
+		// then we'll get out because not necessary to create empty venue
1119
+		if (empty($data['venue_title'])) {
1120
+			return false;
1121
+		}
1122
+		$venue_array = [
1123
+			'VNU_wp_user'         => $event->get('EVT_wp_user'),
1124
+			'VNU_name'            => $data['venue_title'],
1125
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1126
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1127
+			'VNU_short_desc'      => ! empty($data['venue_short_description'])
1128
+				? $data['venue_short_description']
1129
+				: null,
1130
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1131
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1132
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1133
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1134
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1135
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1136
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1137
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1138
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1139
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1140
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1141
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1142
+			'status'              => 'publish',
1143
+		];
1144
+		// if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1145
+		if (! empty($venue_id)) {
1146
+			$update_where  = [$venue_model->primary_key_name() => $venue_id];
1147
+			$rows_affected = $venue_model->update($venue_array, [$update_where]);
1148
+			// we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1149
+			$event->_add_relation_to($venue_id, 'Venue');
1150
+			return $rows_affected > 0;
1151
+		}
1152
+		// we insert the venue
1153
+		$venue_id = $venue_model->insert($venue_array);
1154
+		$event->_add_relation_to($venue_id, 'Venue');
1155
+		return ! empty($venue_id);
1156
+		// when we have the ancestor come in it's already been handled by the revision save.
1157
+	}
1158
+
1159
+
1160
+	/**
1161
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1162
+	 *
1163
+	 * @param EE_Event $event The Event object we're attaching data to
1164
+	 * @param array    $data  The request data from the form
1165
+	 * @return array
1166
+	 * @throws EE_Error
1167
+	 * @throws ReflectionException
1168
+	 * @throws Exception
1169
+	 */
1170
+	protected function _default_tickets_update(EE_Event $event, $data)
1171
+	{
1172
+		$datetime       = null;
1173
+		$saved_tickets  = [];
1174
+		$event_timezone = $event->get_timezone();
1175
+		$date_formats   = ['Y-m-d', 'h:i a'];
1176
+		foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1177
+			// trim all values to ensure any excess whitespace is removed.
1178
+			$datetime_data                = array_map('trim', $datetime_data);
1179
+			$datetime_data['DTT_EVT_end'] =
1180
+				isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1181
+					? $datetime_data['DTT_EVT_end']
1182
+					: $datetime_data['DTT_EVT_start'];
1183
+			$datetime_values              = [
1184
+				'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1185
+				'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1186
+				'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1187
+				'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1188
+				'DTT_order'     => $row,
1189
+			];
1190
+			// if we have an id then let's get existing object first and then set the new values.
1191
+			//  Otherwise we instantiate a new object for save.
1192
+			if (! empty($datetime_data['DTT_ID'])) {
1193
+				$datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1194
+				if (! $datetime instanceof EE_Datetime) {
1195
+					throw new RuntimeException(
1196
+						sprintf(
1197
+							esc_html__(
1198
+								'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1199
+								'event_espresso'
1200
+							),
1201
+							$datetime_data['DTT_ID']
1202
+						)
1203
+					);
1204
+				}
1205
+				$datetime->set_date_format($date_formats[0]);
1206
+				$datetime->set_time_format($date_formats[1]);
1207
+				foreach ($datetime_values as $field => $value) {
1208
+					$datetime->set($field, $value);
1209
+				}
1210
+			} else {
1211
+				$datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1212
+			}
1213
+			if (! $datetime instanceof EE_Datetime) {
1214
+				throw new RuntimeException(
1215
+					sprintf(
1216
+						esc_html__(
1217
+							'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1218
+							'event_espresso'
1219
+						),
1220
+						print_r($datetime_values, true)
1221
+					)
1222
+				);
1223
+			}
1224
+			// before going any further make sure our dates are setup correctly
1225
+			// so that the end date is always equal or greater than the start date.
1226
+			if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1227
+				$datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1228
+				$datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1229
+			}
1230
+			$datetime->save();
1231
+			$event->_add_relation_to($datetime, 'Datetime');
1232
+		}
1233
+		// no datetimes get deleted so we don't do any of that logic here.
1234
+		// update tickets next
1235
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1236
+
1237
+		// set up some default start and end dates in case those are not present in the incoming data
1238
+		$default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1239
+		$default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1240
+		// use the start date of the first datetime for the end date
1241
+		$first_datetime   = $event->first_datetime();
1242
+		$default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1243
+
1244
+		// now process the incoming data
1245
+		foreach ($data['edit_tickets'] as $row => $ticket_data) {
1246
+			$update_prices = false;
1247
+			$ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1248
+				? $data['edit_prices'][ $row ][1]['PRC_amount']
1249
+				: 0;
1250
+			// trim inputs to ensure any excess whitespace is removed.
1251
+			$ticket_data   = array_map('trim', $ticket_data);
1252
+			$ticket_values = [
1253
+				'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1254
+				'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1255
+				'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1256
+				'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1257
+				'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1258
+					? $ticket_data['TKT_start_date']
1259
+					: $default_start_date,
1260
+				'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1261
+					? $ticket_data['TKT_end_date']
1262
+					: $default_end_date,
1263
+				'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1264
+									 || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1265
+					? $ticket_data['TKT_qty']
1266
+					: EE_INF,
1267
+				'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1268
+									 || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1269
+					? $ticket_data['TKT_uses']
1270
+					: EE_INF,
1271
+				'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1272
+				'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1273
+				'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1274
+				'TKT_price'       => $ticket_price,
1275
+				'TKT_row'         => $row,
1276
+			];
1277
+			// if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1278
+			// which means in turn that the prices will become new prices as well.
1279
+			if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1280
+				$ticket_values['TKT_ID']         = 0;
1281
+				$ticket_values['TKT_is_default'] = 0;
1282
+				$update_prices                   = true;
1283
+			}
1284
+			// if we have a TKT_ID then we need to get that existing TKT_obj and update it
1285
+			// we actually do our saves ahead of adding any relations because its entirely possible that this
1286
+			// ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1287
+			// keep in mind that if the ticket has been sold (and we have changed pricing information),
1288
+			// then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1289
+			if (! empty($ticket_data['TKT_ID'])) {
1290
+				$existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1291
+				if (! $existing_ticket instanceof EE_Ticket) {
1292
+					throw new RuntimeException(
1293
+						sprintf(
1294
+							esc_html__(
1295
+								'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1296
+								'event_espresso'
1297
+							),
1298
+							$ticket_data['TKT_ID']
1299
+						)
1300
+					);
1301
+				}
1302
+				$ticket_sold = $existing_ticket->count_related(
1303
+					'Registration',
1304
+					[
1305
+						[
1306
+							'STS_ID' => [
1307
+								'NOT IN',
1308
+								[EEM_Registration::status_id_incomplete],
1309
+							],
1310
+						],
1311
+					]
1312
+				) > 0;
1313
+				// let's just check the total price for the existing ticket and determine if it matches the new total price.
1314
+				// if they are different then we create a new ticket (if $ticket_sold)
1315
+				// if they aren't different then we go ahead and modify existing ticket.
1316
+				$create_new_ticket = $ticket_sold
1317
+									 && $ticket_price !== $existing_ticket->price()
1318
+									 && ! $existing_ticket->deleted();
1319
+				$existing_ticket->set_date_format($date_formats[0]);
1320
+				$existing_ticket->set_time_format($date_formats[1]);
1321
+				// set new values
1322
+				foreach ($ticket_values as $field => $value) {
1323
+					if ($field == 'TKT_qty') {
1324
+						$existing_ticket->set_qty($value);
1325
+					} elseif ($field == 'TKT_price') {
1326
+						$existing_ticket->set('TKT_price', $ticket_price);
1327
+					} else {
1328
+						$existing_ticket->set($field, $value);
1329
+					}
1330
+				}
1331
+				$ticket = $existing_ticket;
1332
+				// if $create_new_ticket is false then we can safely update the existing ticket.
1333
+				//  Otherwise we have to create a new ticket.
1334
+				if ($create_new_ticket) {
1335
+					// archive the old ticket first
1336
+					$existing_ticket->set('TKT_deleted', 1);
1337
+					$existing_ticket->save();
1338
+					// make sure this ticket is still recorded in our $saved_tickets
1339
+					// so we don't run it through the regular trash routine.
1340
+					$saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1341
+					// create new ticket that's a copy of the existing except,
1342
+					// (a new id of course and not archived) AND has the new TKT_price associated with it.
1343
+					$new_ticket = clone $existing_ticket;
1344
+					$new_ticket->set('TKT_ID', 0);
1345
+					$new_ticket->set('TKT_deleted', 0);
1346
+					$new_ticket->set('TKT_sold', 0);
1347
+					// now we need to make sure that $new prices are created as well and attached to new ticket.
1348
+					$update_prices = true;
1349
+					$ticket        = $new_ticket;
1350
+				}
1351
+			} else {
1352
+				// no TKT_id so a new ticket
1353
+				$ticket_values['TKT_price'] = $ticket_price;
1354
+				$ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1355
+				$update_prices              = true;
1356
+			}
1357
+			if (! $ticket instanceof EE_Ticket) {
1358
+				throw new RuntimeException(
1359
+					sprintf(
1360
+						esc_html__(
1361
+							'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1362
+							'event_espresso'
1363
+						),
1364
+						print_r($ticket_values, true)
1365
+					)
1366
+				);
1367
+			}
1368
+			// cap ticket qty by datetime reg limits
1369
+			$ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1370
+			// update ticket.
1371
+			$ticket->save();
1372
+			// before going any further make sure our dates are setup correctly
1373
+			// so that the end date is always equal or greater than the start date.
1374
+			if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1375
+				$ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1376
+				$ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1377
+				$ticket->save();
1378
+			}
1379
+			// initially let's add the ticket to the datetime
1380
+			$datetime->_add_relation_to($ticket, 'Ticket');
1381
+			$saved_tickets[ $ticket->ID() ] = $ticket;
1382
+			// add prices to ticket
1383
+			$this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices);
1384
+		}
1385
+		// however now we need to handle permanently deleting tickets via the ui.
1386
+		//  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1387
+		//  However, it does allow for deleting tickets that have no tickets sold,
1388
+		// in which case we want to get rid of permanently because there is no need to save in db.
1389
+		$old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets;
1390
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1391
+		foreach ($tickets_removed as $id) {
1392
+			$id = absint($id);
1393
+			// get the ticket for this id
1394
+			$ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1395
+			if (! $ticket_to_remove instanceof EE_Ticket) {
1396
+				continue;
1397
+			}
1398
+			// need to get all the related datetimes on this ticket and remove from every single one of them
1399
+			// (remember this process can ONLY kick off if there are NO tickets sold)
1400
+			$related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1401
+			foreach ($related_datetimes as $related_datetime) {
1402
+				$ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1403
+			}
1404
+			// need to do the same for prices (except these prices can also be deleted because again,
1405
+			// tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1406
+			$ticket_to_remove->delete_related_permanently('Price');
1407
+			// finally let's delete this ticket
1408
+			// (which should not be blocked at this point b/c we've removed all our relationships)
1409
+			$ticket_to_remove->delete_permanently();
1410
+		}
1411
+		return [$datetime, $saved_tickets];
1412
+	}
1413
+
1414
+
1415
+	/**
1416
+	 * This attaches a list of given prices to a ticket.
1417
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1418
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1419
+	 * price info and prices are automatically "archived" via the ticket.
1420
+	 *
1421
+	 * @access  private
1422
+	 * @param array     $prices_data Array of prices from the form.
1423
+	 * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1424
+	 * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1425
+	 * @return  void
1426
+	 * @throws EE_Error
1427
+	 * @throws ReflectionException
1428
+	 */
1429
+	private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1430
+	{
1431
+		$timezone = $ticket->get_timezone();
1432
+		foreach ($prices_data as $row => $price_data) {
1433
+			$price_values = [
1434
+				'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1435
+				'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1436
+				'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1437
+				'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1438
+				'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1439
+				'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1440
+				'PRC_order'      => $row,
1441
+			];
1442
+			if ($new_prices || empty($price_values['PRC_ID'])) {
1443
+				$price_values['PRC_ID'] = 0;
1444
+				$price                  = EE_Price::new_instance($price_values, $timezone);
1445
+			} else {
1446
+				$price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1447
+				// update this price with new values
1448
+				foreach ($price_values as $field => $new_price) {
1449
+					$price->set($field, $new_price);
1450
+				}
1451
+			}
1452
+			if (! $price instanceof EE_Price) {
1453
+				throw new RuntimeException(
1454
+					sprintf(
1455
+						esc_html__(
1456
+							'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1457
+							'event_espresso'
1458
+						),
1459
+						print_r($price_values, true)
1460
+					)
1461
+				);
1462
+			}
1463
+			$price->save();
1464
+			$ticket->_add_relation_to($price, 'Price');
1465
+		}
1466
+	}
1467
+
1468
+
1469
+	/**
1470
+	 * Add in our autosave ajax handlers
1471
+	 *
1472
+	 */
1473
+	protected function _ee_autosave_create_new()
1474
+	{
1475
+	}
1476
+
1477
+
1478
+	/**
1479
+	 * More autosave handlers.
1480
+	 */
1481
+	protected function _ee_autosave_edit()
1482
+	{
1483
+		// TEMPORARILY EXITING CAUSE THIS IS A TODO
1484
+	}
1485
+
1486
+
1487
+	/**
1488
+	 * @throws EE_Error
1489
+	 * @throws ReflectionException
1490
+	 */
1491
+	private function _generate_publish_box_extra_content()
1492
+	{
1493
+		// load formatter helper
1494
+		// args for getting related registrations
1495
+		$approved_query_args        = [
1496
+			[
1497
+				'REG_deleted' => 0,
1498
+				'STS_ID'      => EEM_Registration::status_id_approved,
1499
+			],
1500
+		];
1501
+		$not_approved_query_args    = [
1502
+			[
1503
+				'REG_deleted' => 0,
1504
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1505
+			],
1506
+		];
1507
+		$pending_payment_query_args = [
1508
+			[
1509
+				'REG_deleted' => 0,
1510
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1511
+			],
1512
+		];
1513
+		// publish box
1514
+		$publish_box_extra_args = [
1515
+			'view_approved_reg_url'        => add_query_arg(
1516
+				[
1517
+					'action'      => 'default',
1518
+					'event_id'    => $this->_cpt_model_obj->ID(),
1519
+					'_reg_status' => EEM_Registration::status_id_approved,
1520
+				],
1521
+				REG_ADMIN_URL
1522
+			),
1523
+			'view_not_approved_reg_url'    => add_query_arg(
1524
+				[
1525
+					'action'      => 'default',
1526
+					'event_id'    => $this->_cpt_model_obj->ID(),
1527
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1528
+				],
1529
+				REG_ADMIN_URL
1530
+			),
1531
+			'view_pending_payment_reg_url' => add_query_arg(
1532
+				[
1533
+					'action'      => 'default',
1534
+					'event_id'    => $this->_cpt_model_obj->ID(),
1535
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1536
+				],
1537
+				REG_ADMIN_URL
1538
+			),
1539
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1540
+				'Registration',
1541
+				$approved_query_args
1542
+			),
1543
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1544
+				'Registration',
1545
+				$not_approved_query_args
1546
+			),
1547
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1548
+				'Registration',
1549
+				$pending_payment_query_args
1550
+			),
1551
+			'misc_pub_section_class'       => apply_filters(
1552
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1553
+				'misc-pub-section'
1554
+			),
1555
+		];
1556
+		ob_start();
1557
+		do_action(
1558
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1559
+			$this->_cpt_model_obj
1560
+		);
1561
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1562
+		// load template
1563
+		EEH_Template::display_template(
1564
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1565
+			$publish_box_extra_args
1566
+		);
1567
+	}
1568
+
1569
+
1570
+	/**
1571
+	 * @return EE_Event
1572
+	 */
1573
+	public function get_event_object()
1574
+	{
1575
+		return $this->_cpt_model_obj;
1576
+	}
1577
+
1578
+
1579
+
1580
+
1581
+	/** METABOXES * */
1582
+	/**
1583
+	 * _register_event_editor_meta_boxes
1584
+	 * add all metaboxes related to the event_editor
1585
+	 *
1586
+	 * @return void
1587
+	 * @throws EE_Error
1588
+	 * @throws ReflectionException
1589
+	 */
1590
+	protected function _register_event_editor_meta_boxes()
1591
+	{
1592
+		$this->verify_cpt_object();
1593
+		add_meta_box(
1594
+			'espresso_event_editor_tickets',
1595
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1596
+			[$this, 'ticket_metabox'],
1597
+			$this->page_slug,
1598
+			'normal',
1599
+			'high'
1600
+		);
1601
+		add_meta_box(
1602
+			'espresso_event_editor_event_options',
1603
+			esc_html__('Event Registration Options', 'event_espresso'),
1604
+			[$this, 'registration_options_meta_box'],
1605
+			$this->page_slug,
1606
+			'side'
1607
+		);
1608
+		// NOTE: if you're looking for other metaboxes in here,
1609
+		// where a metabox has a related management page in the admin
1610
+		// you will find it setup in the related management page's "_Hooks" file.
1611
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1612
+	}
1613
+
1614
+
1615
+	/**
1616
+	 * @throws DomainException
1617
+	 * @throws EE_Error
1618
+	 * @throws ReflectionException
1619
+	 */
1620
+	public function ticket_metabox()
1621
+	{
1622
+		$existing_datetime_ids = $existing_ticket_ids = [];
1623
+		// defaults for template args
1624
+		$template_args = [
1625
+			'existing_datetime_ids'    => '',
1626
+			'event_datetime_help_link' => '',
1627
+			'ticket_options_help_link' => '',
1628
+			'time'                     => null,
1629
+			'ticket_rows'              => '',
1630
+			'existing_ticket_ids'      => '',
1631
+			'total_ticket_rows'        => 1,
1632
+			'ticket_js_structure'      => '',
1633
+			'trash_icon'               => 'ee-lock-icon',
1634
+			'disabled'                 => '',
1635
+		];
1636
+		$event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1637
+		/**
1638
+		 * 1. Start with retrieving Datetimes
1639
+		 * 2. Fore each datetime get related tickets
1640
+		 * 3. For each ticket get related prices
1641
+		 */
1642
+		$times          = EEM_Datetime::instance()->get_all_event_dates($event_id);
1643
+		$first_datetime = reset($times);
1644
+		// do we get related tickets?
1645
+		if (
1646
+			$first_datetime instanceof EE_Datetime
1647
+			&& $first_datetime->ID() !== 0
1648
+		) {
1649
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1650
+			$template_args['time']   = $first_datetime;
1651
+			$related_tickets         = $first_datetime->tickets(
1652
+				[
1653
+					['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1654
+					'default_where_conditions' => 'none',
1655
+				]
1656
+			);
1657
+			if (! empty($related_tickets)) {
1658
+				$template_args['total_ticket_rows'] = count($related_tickets);
1659
+				$row                                = 0;
1660
+				foreach ($related_tickets as $ticket) {
1661
+					$existing_ticket_ids[]        = $ticket->get('TKT_ID');
1662
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1663
+					$row++;
1664
+				}
1665
+			} else {
1666
+				$template_args['total_ticket_rows'] = 1;
1667
+				/** @type EE_Ticket $ticket */
1668
+				$ticket                       = EEM_Ticket::instance()->create_default_object();
1669
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1670
+			}
1671
+		} else {
1672
+			$template_args['time']        = $times[0];
1673
+			$tickets                      = EEM_Ticket::instance()->get_all_default_tickets();
1674
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1675
+			// NOTE: we're just sending the first default row
1676
+			// (decaf can't manage default tickets so this should be sufficient);
1677
+		}
1678
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1679
+			'event_editor_event_datetimes_help_tab'
1680
+		);
1681
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1682
+		$template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1683
+		$template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1684
+		$template_args['ticket_js_structure']      = $this->_get_ticket_row(
1685
+			EEM_Ticket::instance()->create_default_object(),
1686
+			true
1687
+		);
1688
+		$template                                  = apply_filters(
1689
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1690
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1691
+		);
1692
+		EEH_Template::display_template($template, $template_args);
1693
+	}
1694
+
1695
+
1696
+	/**
1697
+	 * Setup an individual ticket form for the decaf event editor page
1698
+	 *
1699
+	 * @access private
1700
+	 * @param EE_Ticket $ticket   the ticket object
1701
+	 * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1702
+	 * @param int       $row
1703
+	 * @return string generated html for the ticket row.
1704
+	 * @throws EE_Error
1705
+	 * @throws ReflectionException
1706
+	 */
1707
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1708
+	{
1709
+		$template_args = [
1710
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1711
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1712
+				: '',
1713
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1714
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1715
+			'TKT_name'            => $ticket->get('TKT_name'),
1716
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1717
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1718
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1719
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1720
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1721
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1722
+			'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1723
+									 && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1724
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1725
+			'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1726
+				: ' disabled=disabled',
1727
+		];
1728
+		$price         = $ticket->ID() !== 0
1729
+			? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1730
+			: null;
1731
+		$price         = $price instanceof EE_Price
1732
+			? $price
1733
+			: EEM_Price::instance()->create_default_object();
1734
+		$price_args    = [
1735
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1736
+			'PRC_amount'            => $price->get('PRC_amount'),
1737
+			'PRT_ID'                => $price->get('PRT_ID'),
1738
+			'PRC_ID'                => $price->get('PRC_ID'),
1739
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1740
+		];
1741
+		// make sure we have default start and end dates if skeleton
1742
+		// handle rows that should NOT be empty
1743
+		if (empty($template_args['TKT_start_date'])) {
1744
+			// if empty then the start date will be now.
1745
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1746
+		}
1747
+		if (empty($template_args['TKT_end_date'])) {
1748
+			// get the earliest datetime (if present);
1749
+			$earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1750
+				? $this->_cpt_model_obj->get_first_related(
1751
+					'Datetime',
1752
+					['order_by' => ['DTT_EVT_start' => 'ASC']]
1753
+				)
1754
+				: null;
1755
+			$template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1756
+				? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1757
+				: date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1758
+		}
1759
+		$template_args = array_merge($template_args, $price_args);
1760
+		$template      = apply_filters(
1761
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1762
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1763
+			$ticket
1764
+		);
1765
+		return EEH_Template::display_template($template, $template_args, true);
1766
+	}
1767
+
1768
+
1769
+	/**
1770
+	 * @throws EE_Error
1771
+	 * @throws ReflectionException
1772
+	 */
1773
+	public function registration_options_meta_box()
1774
+	{
1775
+		$yes_no_values             = [
1776
+			['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1777
+			['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1778
+		];
1779
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1780
+			[
1781
+				EEM_Registration::status_id_cancelled,
1782
+				EEM_Registration::status_id_declined,
1783
+				EEM_Registration::status_id_incomplete,
1784
+			],
1785
+			true
1786
+		);
1787
+		// $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1788
+		$template_args['_event']                          = $this->_cpt_model_obj;
1789
+		$template_args['event']                           = $this->_cpt_model_obj;
1790
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1791
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1792
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1793
+			'default_reg_status',
1794
+			$default_reg_status_values,
1795
+			$this->_cpt_model_obj->default_registration_status()
1796
+		);
1797
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
1798
+			'display_desc',
1799
+			$yes_no_values,
1800
+			$this->_cpt_model_obj->display_description()
1801
+		);
1802
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1803
+			'display_ticket_selector',
1804
+			$yes_no_values,
1805
+			$this->_cpt_model_obj->display_ticket_selector(),
1806
+			'',
1807
+			'',
1808
+			false
1809
+		);
1810
+		$template_args['additional_registration_options'] = apply_filters(
1811
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1812
+			'',
1813
+			$template_args,
1814
+			$yes_no_values,
1815
+			$default_reg_status_values
1816
+		);
1817
+		EEH_Template::display_template(
1818
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1819
+			$template_args
1820
+		);
1821
+	}
1822
+
1823
+
1824
+	/**
1825
+	 * _get_events()
1826
+	 * This method simply returns all the events (for the given _view and paging)
1827
+	 *
1828
+	 * @access public
1829
+	 * @param int  $per_page     count of items per page (20 default);
1830
+	 * @param int  $current_page what is the current page being viewed.
1831
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1832
+	 *                           If FALSE then we return an array of event objects
1833
+	 *                           that match the given _view and paging parameters.
1834
+	 * @return array|int         an array of event objects or a count of them.
1835
+	 * @throws Exception
1836
+	 */
1837
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1838
+	{
1839
+		$EEM_Event   = $this->_event_model();
1840
+		$offset      = ($current_page - 1) * $per_page;
1841
+		$limit       = $count ? null : $offset . ',' . $per_page;
1842
+		$orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1843
+		$order       = $this->request->getRequestParam('order', 'DESC');
1844
+		$month_range = $this->request->getRequestParam('month_range');
1845
+		if ($month_range) {
1846
+			$pieces = explode(' ', $month_range, 3);
1847
+			// simulate the FIRST day of the month, that fixes issues for months like February
1848
+			// where PHP doesn't know what to assume for date.
1849
+			// @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1850
+			$month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1851
+			$year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1852
+		}
1853
+		$where  = [];
1854
+		$status = $this->request->getRequestParam('status');
1855
+		// determine what post_status our condition will have for the query.
1856
+		switch ($status) {
1857
+			case 'month':
1858
+			case 'today':
1859
+			case null:
1860
+			case 'all':
1861
+				break;
1862
+			case 'draft':
1863
+				$where['status'] = ['IN', ['draft', 'auto-draft']];
1864
+				break;
1865
+			default:
1866
+				$where['status'] = $status;
1867
+		}
1868
+		// categories? The default for all categories is -1
1869
+		$category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1870
+		if ($category !== -1) {
1871
+			$where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1872
+			$where['Term_Taxonomy.term_id']  = $category;
1873
+		}
1874
+		// date where conditions
1875
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1876
+		if ($month_range) {
1877
+			$DateTime = new DateTime(
1878
+				$year_r . '-' . $month_r . '-01 00:00:00',
1879
+				new DateTimeZone('UTC')
1880
+			);
1881
+			$start    = $DateTime->getTimestamp();
1882
+			// set the datetime to be the end of the month
1883
+			$DateTime->setDate(
1884
+				$year_r,
1885
+				$month_r,
1886
+				$DateTime->format('t')
1887
+			)->setTime(23, 59, 59);
1888
+			$end                             = $DateTime->getTimestamp();
1889
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1890
+		} elseif ($status === 'today') {
1891
+			$DateTime                        =
1892
+				new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1893
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1894
+			$end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1895
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1896
+		} elseif ($status === 'month') {
1897
+			$now                             = date('Y-m-01');
1898
+			$DateTime                        =
1899
+				new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1900
+			$start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1901
+			$end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1902
+														->setTime(23, 59, 59)
1903
+														->format(implode(' ', $start_formats));
1904
+			$where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1905
+		}
1906
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1907
+			$where['EVT_wp_user'] = get_current_user_id();
1908
+		} else {
1909
+			if (! isset($where['status'])) {
1910
+				if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1911
+					$where['OR'] = [
1912
+						'status*restrict_private' => ['!=', 'private'],
1913
+						'AND'                     => [
1914
+							'status*inclusive' => ['=', 'private'],
1915
+							'EVT_wp_user'      => get_current_user_id(),
1916
+						],
1917
+					];
1918
+				}
1919
+			}
1920
+		}
1921
+		$wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1922
+		if (
1923
+			$wp_user
1924
+			&& $wp_user !== get_current_user_id()
1925
+			&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1926
+		) {
1927
+			$where['EVT_wp_user'] = $wp_user;
1928
+		}
1929
+		// search query handling
1930
+		$search_term = $this->request->getRequestParam('s');
1931
+		if ($search_term) {
1932
+			$search_term = '%' . $search_term . '%';
1933
+			$where['OR'] = [
1934
+				'EVT_name'       => ['LIKE', $search_term],
1935
+				'EVT_desc'       => ['LIKE', $search_term],
1936
+				'EVT_short_desc' => ['LIKE', $search_term],
1937
+			];
1938
+		}
1939
+		// filter events by venue.
1940
+		$venue = $this->request->getRequestParam('venue', 0, 'int');
1941
+		if ($venue) {
1942
+			$where['Venue.VNU_ID'] = $venue;
1943
+		}
1944
+		$request_params = $this->request->requestParams();
1945
+		$where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
1946
+		$query_params   = apply_filters(
1947
+			'FHEE__Events_Admin_Page__get_events__query_params',
1948
+			[
1949
+				$where,
1950
+				'limit'    => $limit,
1951
+				'order_by' => $orderby,
1952
+				'order'    => $order,
1953
+				'group_by' => 'EVT_ID',
1954
+			],
1955
+			$request_params
1956
+		);
1957
+
1958
+		// let's first check if we have special requests coming in.
1959
+		$active_status = $this->request->getRequestParam('active_status');
1960
+		if ($active_status) {
1961
+			switch ($active_status) {
1962
+				case 'upcoming':
1963
+					return $EEM_Event->get_upcoming_events($query_params, $count);
1964
+				case 'expired':
1965
+					return $EEM_Event->get_expired_events($query_params, $count);
1966
+				case 'active':
1967
+					return $EEM_Event->get_active_events($query_params, $count);
1968
+				case 'inactive':
1969
+					return $EEM_Event->get_inactive_events($query_params, $count);
1970
+			}
1971
+		}
1972
+
1973
+		return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
1974
+	}
1975
+
1976
+
1977
+	/**
1978
+	 * handling for WordPress CPT actions (trash, restore, delete)
1979
+	 *
1980
+	 * @param string $post_id
1981
+	 * @throws EE_Error
1982
+	 * @throws ReflectionException
1983
+	 */
1984
+	public function trash_cpt_item($post_id)
1985
+	{
1986
+		$this->request->setRequestParam('EVT_ID', $post_id);
1987
+		$this->_trash_or_restore_event('trash', false);
1988
+	}
1989
+
1990
+
1991
+	/**
1992
+	 * @param string $post_id
1993
+	 * @throws EE_Error
1994
+	 * @throws ReflectionException
1995
+	 */
1996
+	public function restore_cpt_item($post_id)
1997
+	{
1998
+		$this->request->setRequestParam('EVT_ID', $post_id);
1999
+		$this->_trash_or_restore_event('draft', false);
2000
+	}
2001
+
2002
+
2003
+	/**
2004
+	 * @param string $post_id
2005
+	 * @throws EE_Error
2006
+	 * @throws EE_Error
2007
+	 */
2008
+	public function delete_cpt_item($post_id)
2009
+	{
2010
+		throw new EE_Error(
2011
+			esc_html__(
2012
+				'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2013
+				'event_espresso'
2014
+			)
2015
+		);
2016
+		// $this->request->setRequestParam('EVT_ID', $post_id);
2017
+		// $this->_delete_event();
2018
+	}
2019
+
2020
+
2021
+	/**
2022
+	 * _trash_or_restore_event
2023
+	 *
2024
+	 * @access protected
2025
+	 * @param string $event_status
2026
+	 * @param bool   $redirect_after
2027
+	 * @throws EE_Error
2028
+	 * @throws EE_Error
2029
+	 * @throws ReflectionException
2030
+	 */
2031
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2032
+	{
2033
+		// determine the event id and set to array.
2034
+		$EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2035
+		// loop thru events
2036
+		if ($EVT_ID) {
2037
+			// clean status
2038
+			$event_status = sanitize_key($event_status);
2039
+			// grab status
2040
+			if (! empty($event_status)) {
2041
+				$success = $this->_change_event_status($EVT_ID, $event_status);
2042
+			} else {
2043
+				$success = false;
2044
+				$msg     = esc_html__(
2045
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2046
+					'event_espresso'
2047
+				);
2048
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2049
+			}
2050
+		} else {
2051
+			$success = false;
2052
+			$msg     = esc_html__(
2053
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2054
+				'event_espresso'
2055
+			);
2056
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2057
+		}
2058
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2059
+		if ($redirect_after) {
2060
+			$this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2061
+		}
2062
+	}
2063
+
2064
+
2065
+	/**
2066
+	 * _trash_or_restore_events
2067
+	 *
2068
+	 * @access protected
2069
+	 * @param string $event_status
2070
+	 * @return void
2071
+	 * @throws EE_Error
2072
+	 * @throws EE_Error
2073
+	 * @throws ReflectionException
2074
+	 */
2075
+	protected function _trash_or_restore_events($event_status = 'trash')
2076
+	{
2077
+		// clean status
2078
+		$event_status = sanitize_key($event_status);
2079
+		// grab status
2080
+		if (! empty($event_status)) {
2081
+			$success = true;
2082
+			// determine the event id and set to array.
2083
+			$EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2084
+			// loop thru events
2085
+			foreach ($EVT_IDs as $EVT_ID) {
2086
+				if ($EVT_ID = absint($EVT_ID)) {
2087
+					$results = $this->_change_event_status($EVT_ID, $event_status);
2088
+					$success = $results !== false ? $success : false;
2089
+				} else {
2090
+					$msg = sprintf(
2091
+						esc_html__(
2092
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2093
+							'event_espresso'
2094
+						),
2095
+						$EVT_ID
2096
+					);
2097
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2098
+					$success = false;
2099
+				}
2100
+			}
2101
+		} else {
2102
+			$success = false;
2103
+			$msg     = esc_html__(
2104
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2105
+				'event_espresso'
2106
+			);
2107
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2108
+		}
2109
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2110
+		$success = $success ? 2 : false;
2111
+		$action  = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2112
+		$this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2113
+	}
2114
+
2115
+
2116
+	/**
2117
+	 * @param int    $EVT_ID
2118
+	 * @param string $event_status
2119
+	 * @return bool
2120
+	 * @throws EE_Error
2121
+	 * @throws ReflectionException
2122
+	 */
2123
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
2124
+	{
2125
+		// grab event id
2126
+		if (! $EVT_ID) {
2127
+			$msg = esc_html__(
2128
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2129
+				'event_espresso'
2130
+			);
2131
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2132
+			return false;
2133
+		}
2134
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2135
+		// clean status
2136
+		$event_status = sanitize_key($event_status);
2137
+		// grab status
2138
+		if (empty($event_status)) {
2139
+			$msg = esc_html__(
2140
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2141
+				'event_espresso'
2142
+			);
2143
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2144
+			return false;
2145
+		}
2146
+		// was event trashed or restored ?
2147
+		switch ($event_status) {
2148
+			case 'draft':
2149
+				$action = 'restored from the trash';
2150
+				$hook   = 'AHEE_event_restored_from_trash';
2151
+				break;
2152
+			case 'trash':
2153
+				$action = 'moved to the trash';
2154
+				$hook   = 'AHEE_event_moved_to_trash';
2155
+				break;
2156
+			default:
2157
+				$action = 'updated';
2158
+				$hook   = false;
2159
+		}
2160
+		// use class to change status
2161
+		$this->_cpt_model_obj->set_status($event_status);
2162
+		$success = $this->_cpt_model_obj->save();
2163
+		if (! $success) {
2164
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2165
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2166
+			return false;
2167
+		}
2168
+		if ($hook) {
2169
+			do_action($hook);
2170
+		}
2171
+		return true;
2172
+	}
2173
+
2174
+
2175
+	/**
2176
+	 * @param array $event_ids
2177
+	 * @return array
2178
+	 * @since   4.10.23.p
2179
+	 */
2180
+	private function cleanEventIds(array $event_ids)
2181
+	{
2182
+		return array_map('absint', $event_ids);
2183
+	}
2184
+
2185
+
2186
+	/**
2187
+	 * @return array
2188
+	 * @since   4.10.23.p
2189
+	 */
2190
+	private function getEventIdsFromRequest()
2191
+	{
2192
+		if ($this->request->requestParamIsSet('EVT_IDs')) {
2193
+			return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2194
+		} else {
2195
+			return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2196
+		}
2197
+	}
2198
+
2199
+
2200
+	/**
2201
+	 * @param bool $preview_delete
2202
+	 * @throws EE_Error
2203
+	 */
2204
+	protected function _delete_event($preview_delete = true)
2205
+	{
2206
+		$this->_delete_events($preview_delete);
2207
+	}
2208
+
2209
+
2210
+	/**
2211
+	 * Gets the tree traversal batch persister.
2212
+	 *
2213
+	 * @return NodeGroupDao
2214
+	 * @throws InvalidArgumentException
2215
+	 * @throws InvalidDataTypeException
2216
+	 * @throws InvalidInterfaceException
2217
+	 * @since 4.10.12.p
2218
+	 */
2219
+	protected function getModelObjNodeGroupPersister()
2220
+	{
2221
+		if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2222
+			$this->model_obj_node_group_persister =
2223
+				$this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2224
+		}
2225
+		return $this->model_obj_node_group_persister;
2226
+	}
2227
+
2228
+
2229
+	/**
2230
+	 * @param bool $preview_delete
2231
+	 * @return void
2232
+	 * @throws EE_Error
2233
+	 */
2234
+	protected function _delete_events($preview_delete = true)
2235
+	{
2236
+		$event_ids = $this->getEventIdsFromRequest();
2237
+		if ($preview_delete) {
2238
+			$this->generateDeletionPreview($event_ids);
2239
+		} else {
2240
+			EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2241
+		}
2242
+	}
2243
+
2244
+
2245
+	/**
2246
+	 * @param array $event_ids
2247
+	 */
2248
+	protected function generateDeletionPreview(array $event_ids)
2249
+	{
2250
+		$event_ids = $this->cleanEventIds($event_ids);
2251
+		// Set a code we can use to reference this deletion task in the batch jobs and preview page.
2252
+		$deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2253
+		$return_url        = EE_Admin_Page::add_query_args_and_nonce(
2254
+			[
2255
+				'action'            => 'preview_deletion',
2256
+				'deletion_job_code' => $deletion_job_code,
2257
+			],
2258
+			$this->_admin_base_url
2259
+		);
2260
+		EEH_URL::safeRedirectAndExit(
2261
+			EE_Admin_Page::add_query_args_and_nonce(
2262
+				[
2263
+					'page'              => 'espresso_batch',
2264
+					'batch'             => EED_Batch::batch_job,
2265
+					'EVT_IDs'           => $event_ids,
2266
+					'deletion_job_code' => $deletion_job_code,
2267
+					'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2268
+					'return_url'        => urlencode($return_url),
2269
+				],
2270
+				admin_url()
2271
+			)
2272
+		);
2273
+	}
2274
+
2275
+
2276
+	/**
2277
+	 * Checks for a POST submission
2278
+	 *
2279
+	 * @since 4.10.12.p
2280
+	 */
2281
+	protected function confirmDeletion()
2282
+	{
2283
+		$deletion_redirect_logic =
2284
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2285
+		$deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2286
+	}
2287
+
2288
+
2289
+	/**
2290
+	 * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2291
+	 *
2292
+	 * @throws EE_Error
2293
+	 * @since 4.10.12.p
2294
+	 */
2295
+	protected function previewDeletion()
2296
+	{
2297
+		$preview_deletion_logic =
2298
+			$this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2299
+		$this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2300
+		$this->display_admin_page_with_no_sidebar();
2301
+	}
2302
+
2303
+
2304
+	/**
2305
+	 * get total number of events
2306
+	 *
2307
+	 * @access public
2308
+	 * @return int
2309
+	 * @throws EE_Error
2310
+	 * @throws EE_Error
2311
+	 */
2312
+	public function total_events()
2313
+	{
2314
+		return EEM_Event::instance()->count(
2315
+			['caps' => 'read_admin'],
2316
+			'EVT_ID',
2317
+			true
2318
+		);
2319
+	}
2320
+
2321
+
2322
+	/**
2323
+	 * get total number of draft events
2324
+	 *
2325
+	 * @access public
2326
+	 * @return int
2327
+	 * @throws EE_Error
2328
+	 * @throws EE_Error
2329
+	 */
2330
+	public function total_events_draft()
2331
+	{
2332
+		return EEM_Event::instance()->count(
2333
+			[
2334
+				['status' => ['IN', ['draft', 'auto-draft']]],
2335
+				'caps' => 'read_admin',
2336
+			],
2337
+			'EVT_ID',
2338
+			true
2339
+		);
2340
+	}
2341
+
2342
+
2343
+	/**
2344
+	 * get total number of trashed events
2345
+	 *
2346
+	 * @access public
2347
+	 * @return int
2348
+	 * @throws EE_Error
2349
+	 * @throws EE_Error
2350
+	 */
2351
+	public function total_trashed_events()
2352
+	{
2353
+		return EEM_Event::instance()->count(
2354
+			[
2355
+				['status' => 'trash'],
2356
+				'caps' => 'read_admin',
2357
+			],
2358
+			'EVT_ID',
2359
+			true
2360
+		);
2361
+	}
2362
+
2363
+
2364
+	/**
2365
+	 *    _default_event_settings
2366
+	 *    This generates the Default Settings Tab
2367
+	 *
2368
+	 * @return void
2369
+	 * @throws EE_Error
2370
+	 */
2371
+	protected function _default_event_settings()
2372
+	{
2373
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2374
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2375
+		$this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2376
+		$this->display_admin_page_with_sidebar();
2377
+	}
2378
+
2379
+
2380
+	/**
2381
+	 * Return the form for event settings.
2382
+	 *
2383
+	 * @return EE_Form_Section_Proper
2384
+	 * @throws EE_Error
2385
+	 */
2386
+	protected function _default_event_settings_form()
2387
+	{
2388
+		$registration_config              = EE_Registry::instance()->CFG->registration;
2389
+		$registration_stati_for_selection = EEM_Registration::reg_status_array(
2390
+		// exclude
2391
+			[
2392
+				EEM_Registration::status_id_cancelled,
2393
+				EEM_Registration::status_id_declined,
2394
+				EEM_Registration::status_id_incomplete,
2395
+				EEM_Registration::status_id_wait_list,
2396
+			],
2397
+			true
2398
+		);
2399
+		return new EE_Form_Section_Proper(
2400
+			[
2401
+				'name'            => 'update_default_event_settings',
2402
+				'html_id'         => 'update_default_event_settings',
2403
+				'html_class'      => 'form-table',
2404
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2405
+				'subsections'     => apply_filters(
2406
+					'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2407
+					[
2408
+						'default_reg_status'  => new EE_Select_Input(
2409
+							$registration_stati_for_selection,
2410
+							[
2411
+								'default'         => isset($registration_config->default_STS_ID)
2412
+													 && array_key_exists(
2413
+														 $registration_config->default_STS_ID,
2414
+														 $registration_stati_for_selection
2415
+													 )
2416
+									? sanitize_text_field($registration_config->default_STS_ID)
2417
+									: EEM_Registration::status_id_pending_payment,
2418
+								'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2419
+													 . EEH_Template::get_help_tab_link(
2420
+														 'default_settings_status_help_tab'
2421
+													 ),
2422
+								'html_help_text'  => esc_html__(
2423
+									'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2424
+									'event_espresso'
2425
+								),
2426
+							]
2427
+						),
2428
+						'default_max_tickets' => new EE_Integer_Input(
2429
+							[
2430
+								'default'         => isset($registration_config->default_maximum_number_of_tickets)
2431
+									? $registration_config->default_maximum_number_of_tickets
2432
+									: EEM_Event::get_default_additional_limit(),
2433
+								'html_label_text' => esc_html__(
2434
+									'Default Maximum Tickets Allowed Per Order:',
2435
+									'event_espresso'
2436
+								)
2437
+								. EEH_Template::get_help_tab_link(
2438
+									'default_maximum_tickets_help_tab"'
2439
+								),
2440
+								'html_help_text'  => esc_html__(
2441
+									'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2442
+									'event_espresso'
2443
+								),
2444
+							]
2445
+						),
2446
+					]
2447
+				),
2448
+			]
2449
+		);
2450
+	}
2451
+
2452
+
2453
+	/**
2454
+	 * _update_default_event_settings
2455
+	 *
2456
+	 * @access protected
2457
+	 * @return void
2458
+	 * @throws EE_Error
2459
+	 */
2460
+	protected function _update_default_event_settings()
2461
+	{
2462
+		$registration_config = EE_Registry::instance()->CFG->registration;
2463
+		$form                = $this->_default_event_settings_form();
2464
+		if ($form->was_submitted()) {
2465
+			$form->receive_form_submission();
2466
+			if ($form->is_valid()) {
2467
+				$valid_data = $form->valid_data();
2468
+				if (isset($valid_data['default_reg_status'])) {
2469
+					$registration_config->default_STS_ID = $valid_data['default_reg_status'];
2470
+				}
2471
+				if (isset($valid_data['default_max_tickets'])) {
2472
+					$registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2473
+				}
2474
+				// update because data was valid!
2475
+				EE_Registry::instance()->CFG->update_espresso_config();
2476
+				EE_Error::overwrite_success();
2477
+				EE_Error::add_success(
2478
+					esc_html__('Default Event Settings were updated', 'event_espresso')
2479
+				);
2480
+			}
2481
+		}
2482
+		$this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2483
+	}
2484
+
2485
+
2486
+	/*************        Templates        *************
21 2487
      *
22
-     * @var EE_Event $_event
23
-     */
24
-    protected $_event;
25
-
26
-
27
-    /**
28
-     * This will hold the category object for category_details screen.
29
-     *
30
-     * @var stdClass $_category
31
-     */
32
-    protected $_category;
33
-
34
-
35
-    /**
36
-     * This will hold the event model instance
37
-     *
38
-     * @var EEM_Event $_event_model
39
-     */
40
-    protected $_event_model;
41
-
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $_cpt_model_obj = false;
47
-
48
-
49
-    /**
50
-     * @var NodeGroupDao
51
-     */
52
-    protected $model_obj_node_group_persister;
53
-
54
-
55
-    /**
56
-     * Initialize page props for this admin page group.
57
-     */
58
-    protected function _init_page_props()
59
-    {
60
-        $this->page_slug        = EVENTS_PG_SLUG;
61
-        $this->page_label       = EVENTS_LABEL;
62
-        $this->_admin_base_url  = EVENTS_ADMIN_URL;
63
-        $this->_admin_base_path = EVENTS_ADMIN;
64
-        $this->_cpt_model_names = [
65
-            'create_new' => 'EEM_Event',
66
-            'edit'       => 'EEM_Event',
67
-        ];
68
-        $this->_cpt_edit_routes = [
69
-            'espresso_events' => 'edit',
70
-        ];
71
-        add_action(
72
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
73
-            [$this, 'verify_event_edit'],
74
-            10,
75
-            2
76
-        );
77
-    }
78
-
79
-
80
-    /**
81
-     * Sets the ajax hooks used for this admin page group.
82
-     */
83
-    protected function _ajax_hooks()
84
-    {
85
-        add_action('wp_ajax_ee_save_timezone_setting', [$this, 'saveTimezoneString']);
86
-    }
87
-
88
-
89
-    /**
90
-     * Sets the page properties for this admin page group.
91
-     */
92
-    protected function _define_page_props()
93
-    {
94
-        $this->_admin_page_title = EVENTS_LABEL;
95
-        $this->_labels           = [
96
-            'buttons'      => [
97
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
98
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
99
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
100
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
101
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
102
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
103
-            ],
104
-            'editor_title' => [
105
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
106
-            ],
107
-            'publishbox'   => [
108
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
109
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
110
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
111
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
112
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
113
-            ],
114
-        ];
115
-    }
116
-
117
-
118
-    /**
119
-     * Sets the page routes property for this admin page group.
120
-     */
121
-    protected function _set_page_routes()
122
-    {
123
-        // load formatter helper
124
-        // load field generator helper
125
-        // is there a evt_id in the request?
126
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
127
-        $EVT_ID = $this->request->getRequestParam('post', $EVT_ID, 'int');
128
-
129
-        $this->_page_routes = [
130
-            'default'                       => [
131
-                'func'       => '_events_overview_list_table',
132
-                'capability' => 'ee_read_events',
133
-            ],
134
-            'create_new'                    => [
135
-                'func'       => '_create_new_cpt_item',
136
-                'capability' => 'ee_edit_events',
137
-            ],
138
-            'edit'                          => [
139
-                'func'       => '_edit_cpt_item',
140
-                'capability' => 'ee_edit_event',
141
-                'obj_id'     => $EVT_ID,
142
-            ],
143
-            'copy_event'                    => [
144
-                'func'       => '_copy_events',
145
-                'capability' => 'ee_edit_event',
146
-                'obj_id'     => $EVT_ID,
147
-                'noheader'   => true,
148
-            ],
149
-            'trash_event'                   => [
150
-                'func'       => '_trash_or_restore_event',
151
-                'args'       => ['event_status' => 'trash'],
152
-                'capability' => 'ee_delete_event',
153
-                'obj_id'     => $EVT_ID,
154
-                'noheader'   => true,
155
-            ],
156
-            'trash_events'                  => [
157
-                'func'       => '_trash_or_restore_events',
158
-                'args'       => ['event_status' => 'trash'],
159
-                'capability' => 'ee_delete_events',
160
-                'noheader'   => true,
161
-            ],
162
-            'restore_event'                 => [
163
-                'func'       => '_trash_or_restore_event',
164
-                'args'       => ['event_status' => 'draft'],
165
-                'capability' => 'ee_delete_event',
166
-                'obj_id'     => $EVT_ID,
167
-                'noheader'   => true,
168
-            ],
169
-            'restore_events'                => [
170
-                'func'       => '_trash_or_restore_events',
171
-                'args'       => ['event_status' => 'draft'],
172
-                'capability' => 'ee_delete_events',
173
-                'noheader'   => true,
174
-            ],
175
-            'delete_event'                  => [
176
-                'func'       => '_delete_event',
177
-                'capability' => 'ee_delete_event',
178
-                'obj_id'     => $EVT_ID,
179
-                'noheader'   => true,
180
-            ],
181
-            'delete_events'                 => [
182
-                'func'       => '_delete_events',
183
-                'capability' => 'ee_delete_events',
184
-                'noheader'   => true,
185
-            ],
186
-            'view_report'                   => [
187
-                'func'       => '_view_report',
188
-                'capability' => 'ee_edit_events',
189
-            ],
190
-            'default_event_settings'        => [
191
-                'func'       => '_default_event_settings',
192
-                'capability' => 'manage_options',
193
-            ],
194
-            'update_default_event_settings' => [
195
-                'func'       => '_update_default_event_settings',
196
-                'capability' => 'manage_options',
197
-                'noheader'   => true,
198
-            ],
199
-            'template_settings'             => [
200
-                'func'       => '_template_settings',
201
-                'capability' => 'manage_options',
202
-            ],
203
-            // event category tab related
204
-            'add_category'                  => [
205
-                'func'       => '_category_details',
206
-                'capability' => 'ee_edit_event_category',
207
-                'args'       => ['add'],
208
-            ],
209
-            'edit_category'                 => [
210
-                'func'       => '_category_details',
211
-                'capability' => 'ee_edit_event_category',
212
-                'args'       => ['edit'],
213
-            ],
214
-            'delete_categories'             => [
215
-                'func'       => '_delete_categories',
216
-                'capability' => 'ee_delete_event_category',
217
-                'noheader'   => true,
218
-            ],
219
-            'delete_category'               => [
220
-                'func'       => '_delete_categories',
221
-                'capability' => 'ee_delete_event_category',
222
-                'noheader'   => true,
223
-            ],
224
-            'insert_category'               => [
225
-                'func'       => '_insert_or_update_category',
226
-                'args'       => ['new_category' => true],
227
-                'capability' => 'ee_edit_event_category',
228
-                'noheader'   => true,
229
-            ],
230
-            'update_category'               => [
231
-                'func'       => '_insert_or_update_category',
232
-                'args'       => ['new_category' => false],
233
-                'capability' => 'ee_edit_event_category',
234
-                'noheader'   => true,
235
-            ],
236
-            'category_list'                 => [
237
-                'func'       => '_category_list_table',
238
-                'capability' => 'ee_manage_event_categories',
239
-            ],
240
-            'preview_deletion'              => [
241
-                'func'       => 'previewDeletion',
242
-                'capability' => 'ee_delete_events',
243
-            ],
244
-            'confirm_deletion'              => [
245
-                'func'       => 'confirmDeletion',
246
-                'capability' => 'ee_delete_events',
247
-                'noheader'   => true,
248
-            ],
249
-        ];
250
-    }
251
-
252
-
253
-    /**
254
-     * Set the _page_config property for this admin page group.
255
-     */
256
-    protected function _set_page_config()
257
-    {
258
-        $post_id            = $this->request->getRequestParam('post', 0, 'int');
259
-        $EVT_CAT_ID         = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
260
-        $this->_page_config = [
261
-            'default'                => [
262
-                'nav'           => [
263
-                    'label' => esc_html__('Overview', 'event_espresso'),
264
-                    'order' => 10,
265
-                ],
266
-                'list_table'    => 'Events_Admin_List_Table',
267
-                'help_tabs'     => [
268
-                    'events_overview_help_tab'                       => [
269
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
270
-                        'filename' => 'events_overview',
271
-                    ],
272
-                    'events_overview_table_column_headings_help_tab' => [
273
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
274
-                        'filename' => 'events_overview_table_column_headings',
275
-                    ],
276
-                    'events_overview_filters_help_tab'               => [
277
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
278
-                        'filename' => 'events_overview_filters',
279
-                    ],
280
-                    'events_overview_view_help_tab'                  => [
281
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
282
-                        'filename' => 'events_overview_views',
283
-                    ],
284
-                    'events_overview_other_help_tab'                 => [
285
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
286
-                        'filename' => 'events_overview_other',
287
-                    ],
288
-                ],
289
-                'qtips'         => [
290
-                    'EE_Event_List_Table_Tips',
291
-                ],
292
-                'require_nonce' => false,
293
-            ],
294
-            'create_new'             => [
295
-                'nav'           => [
296
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
297
-                    'order'      => 5,
298
-                    'persistent' => false,
299
-                ],
300
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
301
-                'help_tabs'     => [
302
-                    'event_editor_help_tab'                            => [
303
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
304
-                        'filename' => 'event_editor',
305
-                    ],
306
-                    'event_editor_title_richtexteditor_help_tab'       => [
307
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
308
-                        'filename' => 'event_editor_title_richtexteditor',
309
-                    ],
310
-                    'event_editor_venue_details_help_tab'              => [
311
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
312
-                        'filename' => 'event_editor_venue_details',
313
-                    ],
314
-                    'event_editor_event_datetimes_help_tab'            => [
315
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
316
-                        'filename' => 'event_editor_event_datetimes',
317
-                    ],
318
-                    'event_editor_event_tickets_help_tab'              => [
319
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
320
-                        'filename' => 'event_editor_event_tickets',
321
-                    ],
322
-                    'event_editor_event_registration_options_help_tab' => [
323
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
324
-                        'filename' => 'event_editor_event_registration_options',
325
-                    ],
326
-                    'event_editor_tags_categories_help_tab'            => [
327
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
328
-                        'filename' => 'event_editor_tags_categories',
329
-                    ],
330
-                    'event_editor_questions_registrants_help_tab'      => [
331
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
332
-                        'filename' => 'event_editor_questions_registrants',
333
-                    ],
334
-                    'event_editor_save_new_event_help_tab'             => [
335
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
336
-                        'filename' => 'event_editor_save_new_event',
337
-                    ],
338
-                    'event_editor_other_help_tab'                      => [
339
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
340
-                        'filename' => 'event_editor_other',
341
-                    ],
342
-                ],
343
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
344
-                'require_nonce' => false,
345
-            ],
346
-            'edit'                   => [
347
-                'nav'           => [
348
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
349
-                    'order'      => 5,
350
-                    'persistent' => false,
351
-                    'url'        => $post_id
352
-                        ? EE_Admin_Page::add_query_args_and_nonce(
353
-                            ['post' => $post_id, 'action' => 'edit'],
354
-                            $this->_current_page_view_url
355
-                        )
356
-                        : $this->_admin_base_url,
357
-                ],
358
-                'metaboxes'     => ['_register_event_editor_meta_boxes'],
359
-                'help_tabs'     => [
360
-                    'event_editor_help_tab'                            => [
361
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
362
-                        'filename' => 'event_editor',
363
-                    ],
364
-                    'event_editor_title_richtexteditor_help_tab'       => [
365
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
366
-                        'filename' => 'event_editor_title_richtexteditor',
367
-                    ],
368
-                    'event_editor_venue_details_help_tab'              => [
369
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
370
-                        'filename' => 'event_editor_venue_details',
371
-                    ],
372
-                    'event_editor_event_datetimes_help_tab'            => [
373
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
374
-                        'filename' => 'event_editor_event_datetimes',
375
-                    ],
376
-                    'event_editor_event_tickets_help_tab'              => [
377
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
378
-                        'filename' => 'event_editor_event_tickets',
379
-                    ],
380
-                    'event_editor_event_registration_options_help_tab' => [
381
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
382
-                        'filename' => 'event_editor_event_registration_options',
383
-                    ],
384
-                    'event_editor_tags_categories_help_tab'            => [
385
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
386
-                        'filename' => 'event_editor_tags_categories',
387
-                    ],
388
-                    'event_editor_questions_registrants_help_tab'      => [
389
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
390
-                        'filename' => 'event_editor_questions_registrants',
391
-                    ],
392
-                    'event_editor_save_new_event_help_tab'             => [
393
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
394
-                        'filename' => 'event_editor_save_new_event',
395
-                    ],
396
-                    'event_editor_other_help_tab'                      => [
397
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
398
-                        'filename' => 'event_editor_other',
399
-                    ],
400
-                ],
401
-                'qtips'         => ['EE_Event_Editor_Decaf_Tips'],
402
-                'require_nonce' => false,
403
-            ],
404
-            'default_event_settings' => [
405
-                'nav'           => [
406
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
407
-                    'order' => 40,
408
-                ],
409
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
410
-                'labels'        => [
411
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
412
-                ],
413
-                'help_tabs'     => [
414
-                    'default_settings_help_tab'        => [
415
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
416
-                        'filename' => 'events_default_settings',
417
-                    ],
418
-                    'default_settings_status_help_tab' => [
419
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
420
-                        'filename' => 'events_default_settings_status',
421
-                    ],
422
-                    'default_maximum_tickets_help_tab' => [
423
-                        'title'    => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'),
424
-                        'filename' => 'events_default_settings_max_tickets',
425
-                    ],
426
-                ],
427
-                'require_nonce' => false,
428
-            ],
429
-            // template settings
430
-            'template_settings'      => [
431
-                'nav'           => [
432
-                    'label' => esc_html__('Templates', 'event_espresso'),
433
-                    'order' => 30,
434
-                ],
435
-                'metaboxes'     => $this->_default_espresso_metaboxes,
436
-                'help_tabs'     => [
437
-                    'general_settings_templates_help_tab' => [
438
-                        'title'    => esc_html__('Templates', 'event_espresso'),
439
-                        'filename' => 'general_settings_templates',
440
-                    ],
441
-                ],
442
-                'require_nonce' => false,
443
-            ],
444
-            // event category stuff
445
-            'add_category'           => [
446
-                'nav'           => [
447
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
448
-                    'order'      => 15,
449
-                    'persistent' => false,
450
-                ],
451
-                'help_tabs'     => [
452
-                    'add_category_help_tab' => [
453
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
454
-                        'filename' => 'events_add_category',
455
-                    ],
456
-                ],
457
-                'metaboxes'     => ['_publish_post_box'],
458
-                'require_nonce' => false,
459
-            ],
460
-            'edit_category'          => [
461
-                'nav'           => [
462
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
463
-                    'order'      => 15,
464
-                    'persistent' => false,
465
-                    'url'        => $EVT_CAT_ID
466
-                        ? add_query_arg(
467
-                            ['EVT_CAT_ID' => $EVT_CAT_ID],
468
-                            $this->_current_page_view_url
469
-                        )
470
-                        : $this->_admin_base_url,
471
-                ],
472
-                'help_tabs'     => [
473
-                    'edit_category_help_tab' => [
474
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
475
-                        'filename' => 'events_edit_category',
476
-                    ],
477
-                ],
478
-                'metaboxes'     => ['_publish_post_box'],
479
-                'require_nonce' => false,
480
-            ],
481
-            'category_list'          => [
482
-                'nav'           => [
483
-                    'label' => esc_html__('Categories', 'event_espresso'),
484
-                    'order' => 20,
485
-                ],
486
-                'list_table'    => 'Event_Categories_Admin_List_Table',
487
-                'help_tabs'     => [
488
-                    'events_categories_help_tab'                       => [
489
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
490
-                        'filename' => 'events_categories',
491
-                    ],
492
-                    'events_categories_table_column_headings_help_tab' => [
493
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
494
-                        'filename' => 'events_categories_table_column_headings',
495
-                    ],
496
-                    'events_categories_view_help_tab'                  => [
497
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
498
-                        'filename' => 'events_categories_views',
499
-                    ],
500
-                    'events_categories_other_help_tab'                 => [
501
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
502
-                        'filename' => 'events_categories_other',
503
-                    ],
504
-                ],
505
-                'metaboxes'     => $this->_default_espresso_metaboxes,
506
-                'require_nonce' => false,
507
-            ],
508
-            'preview_deletion'       => [
509
-                'nav'           => [
510
-                    'label'      => esc_html__('Preview Deletion', 'event_espresso'),
511
-                    'order'      => 15,
512
-                    'persistent' => false,
513
-                    'url'        => '',
514
-                ],
515
-                'require_nonce' => false,
516
-            ],
517
-        ];
518
-    }
519
-
520
-
521
-    /**
522
-     * Used to register any global screen options if necessary for every route in this admin page group.
523
-     */
524
-    protected function _add_screen_options()
525
-    {
526
-    }
527
-
528
-
529
-    /**
530
-     * Implementing the screen options for the 'default' route.
531
-     */
532
-    protected function _add_screen_options_default()
533
-    {
534
-        $this->_per_page_screen_option();
535
-    }
536
-
537
-
538
-    /**
539
-     * Implementing screen options for the category list route.
540
-     */
541
-    protected function _add_screen_options_category_list()
542
-    {
543
-        $page_title              = $this->_admin_page_title;
544
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
545
-        $this->_per_page_screen_option();
546
-        $this->_admin_page_title = $page_title;
547
-    }
548
-
549
-
550
-    /**
551
-     * Used to register any global feature pointers for the admin page group.
552
-     */
553
-    protected function _add_feature_pointers()
554
-    {
555
-    }
556
-
557
-
558
-    /**
559
-     * Registers and enqueues any global scripts and styles for the entire admin page group.
560
-     */
561
-    public function load_scripts_styles()
562
-    {
563
-        wp_register_style(
564
-            'events-admin-css',
565
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
566
-            [],
567
-            EVENT_ESPRESSO_VERSION
568
-        );
569
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', [], EVENT_ESPRESSO_VERSION);
570
-        wp_enqueue_style('events-admin-css');
571
-        wp_enqueue_style('ee-cat-admin');
572
-        // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
573
-        // registers for all views
574
-        // scripts
575
-        wp_register_script(
576
-            'event_editor_js',
577
-            EVENTS_ASSETS_URL . 'event_editor.js',
578
-            ['ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'],
579
-            EVENT_ESPRESSO_VERSION,
580
-            true
581
-        );
582
-    }
583
-
584
-
585
-    /**
586
-     * Enqueuing scripts and styles specific to this view
587
-     */
588
-    public function load_scripts_styles_create_new()
589
-    {
590
-        $this->load_scripts_styles_edit();
591
-    }
592
-
593
-
594
-    /**
595
-     * Enqueuing scripts and styles specific to this view
596
-     */
597
-    public function load_scripts_styles_edit()
598
-    {
599
-        // styles
600
-        wp_enqueue_style('espresso-ui-theme');
601
-        wp_register_style(
602
-            'event-editor-css',
603
-            EVENTS_ASSETS_URL . 'event-editor.css',
604
-            ['ee-admin-css'],
605
-            EVENT_ESPRESSO_VERSION
606
-        );
607
-        wp_enqueue_style('event-editor-css');
608
-        // scripts
609
-        wp_register_script(
610
-            'event-datetime-metabox',
611
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
612
-            ['event_editor_js', 'ee-datepicker'],
613
-            EVENT_ESPRESSO_VERSION
614
-        );
615
-        wp_enqueue_script('event-datetime-metabox');
616
-    }
617
-
618
-
619
-    /**
620
-     * Populating the _views property for the category list table view.
621
-     */
622
-    protected function _set_list_table_views_category_list()
623
-    {
624
-        $this->_views = [
625
-            'all' => [
626
-                'slug'        => 'all',
627
-                'label'       => esc_html__('All', 'event_espresso'),
628
-                'count'       => 0,
629
-                'bulk_action' => [
630
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
631
-                ],
632
-            ],
633
-        ];
634
-    }
635
-
636
-
637
-    /**
638
-     * For adding anything that fires on the admin_init hook for any route within this admin page group.
639
-     */
640
-    public function admin_init()
641
-    {
642
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
643
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
644
-            'event_espresso'
645
-        );
646
-    }
647
-
648
-
649
-    /**
650
-     * For adding anything that should be triggered on the admin_notices hook for any route within this admin page
651
-     * group.
652
-     */
653
-    public function admin_notices()
654
-    {
655
-    }
656
-
657
-
658
-    /**
659
-     * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within
660
-     * this admin page group.
661
-     */
662
-    public function admin_footer_scripts()
663
-    {
664
-    }
665
-
666
-
667
-    /**
668
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
669
-     * warning (via EE_Error::add_error());
670
-     *
671
-     * @param EE_Event $event Event object
672
-     * @param string   $req_type
673
-     * @return void
674
-     * @throws EE_Error
675
-     * @throws ReflectionException
676
-     */
677
-    public function verify_event_edit($event = null, $req_type = '')
678
-    {
679
-        // don't need to do this when processing
680
-        if (! empty($req_type)) {
681
-            return;
682
-        }
683
-        // no event?
684
-        if (empty($event)) {
685
-            // set event
686
-            $event = $this->_cpt_model_obj;
687
-        }
688
-        // STILL no event?
689
-        if (! $event instanceof EE_Event) {
690
-            return;
691
-        }
692
-        $orig_status = $event->status();
693
-        // first check if event is active.
694
-        if (
695
-            $orig_status === EEM_Event::cancelled
696
-            || $orig_status === EEM_Event::postponed
697
-            || $event->is_expired()
698
-            || $event->is_inactive()
699
-        ) {
700
-            return;
701
-        }
702
-        // made it here so it IS active... next check that any of the tickets are sold.
703
-        if ($event->is_sold_out(true)) {
704
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
705
-                EE_Error::add_attention(
706
-                    sprintf(
707
-                        esc_html__(
708
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
709
-                            'event_espresso'
710
-                        ),
711
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
712
-                    )
713
-                );
714
-            }
715
-            return;
716
-        } elseif ($orig_status === EEM_Event::sold_out) {
717
-            EE_Error::add_attention(
718
-                sprintf(
719
-                    esc_html__(
720
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
721
-                        'event_espresso'
722
-                    ),
723
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
724
-                )
725
-            );
726
-        }
727
-        // now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
728
-        if (! $event->tickets_on_sale()) {
729
-            return;
730
-        }
731
-        // made it here so show warning
732
-        $this->_edit_event_warning();
733
-    }
734
-
735
-
736
-    /**
737
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
738
-     * When needed, hook this into a EE_Error::add_error() notice.
739
-     *
740
-     * @access protected
741
-     * @return void
742
-     */
743
-    protected function _edit_event_warning()
744
-    {
745
-        // we don't want to add warnings during these requests
746
-        if ($this->request->getRequestParam('action') === 'editpost') {
747
-            return;
748
-        }
749
-        EE_Error::add_attention(
750
-            sprintf(
751
-                esc_html__(
752
-                    'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s',
753
-                    'event_espresso'
754
-                ),
755
-                '<a class="espresso-help-tab-lnk">',
756
-                '</a>'
757
-            )
758
-        );
759
-    }
760
-
761
-
762
-    /**
763
-     * When a user is creating a new event, notify them if they haven't set their timezone.
764
-     * Otherwise, do the normal logic
765
-     *
766
-     * @return void
767
-     * @throws EE_Error
768
-     */
769
-    protected function _create_new_cpt_item()
770
-    {
771
-        $has_timezone_string = get_option('timezone_string');
772
-        // only nag them about setting their timezone if it's their first event, and they haven't already done it
773
-        if (! $has_timezone_string && ! EEM_Event::instance()->exists([])) {
774
-            EE_Error::add_attention(
775
-                sprintf(
776
-                    esc_html__(
777
-                        'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s',
778
-                        'event_espresso'
779
-                    ),
780
-                    '<br>',
781
-                    '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">'
782
-                    . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale())
783
-                    . '</select>',
784
-                    '<button class="button button-secondary timezone-submit">',
785
-                    '</button><span class="spinner"></span>'
786
-                ),
787
-                __FILE__,
788
-                __FUNCTION__,
789
-                __LINE__
790
-            );
791
-        }
792
-        parent::_create_new_cpt_item();
793
-    }
794
-
795
-
796
-    /**
797
-     * Sets the _views property for the default route in this admin page group.
798
-     */
799
-    protected function _set_list_table_views_default()
800
-    {
801
-        $this->_views = [
802
-            'all'   => [
803
-                'slug'        => 'all',
804
-                'label'       => esc_html__('View All Events', 'event_espresso'),
805
-                'count'       => 0,
806
-                'bulk_action' => [
807
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
808
-                ],
809
-            ],
810
-            'draft' => [
811
-                'slug'        => 'draft',
812
-                'label'       => esc_html__('Draft', 'event_espresso'),
813
-                'count'       => 0,
814
-                'bulk_action' => [
815
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
816
-                ],
817
-            ],
818
-        ];
819
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
820
-            $this->_views['trash'] = [
821
-                'slug'        => 'trash',
822
-                'label'       => esc_html__('Trash', 'event_espresso'),
823
-                'count'       => 0,
824
-                'bulk_action' => [
825
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
826
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
827
-                ],
828
-            ];
829
-        }
830
-    }
831
-
832
-
833
-    /**
834
-     * Provides the legend item array for the default list table view.
835
-     *
836
-     * @return array
837
-     * @throws EE_Error
838
-     * @throws EE_Error
839
-     */
840
-    protected function _event_legend_items()
841
-    {
842
-        $items    = [
843
-            'view_details'   => [
844
-                'class' => 'dashicons dashicons-search',
845
-                'desc'  => esc_html__('View Event', 'event_espresso'),
846
-            ],
847
-            'edit_event'     => [
848
-                'class' => 'ee-icon ee-icon-calendar-edit',
849
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
850
-            ],
851
-            'view_attendees' => [
852
-                'class' => 'dashicons dashicons-groups',
853
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
854
-            ],
855
-        ];
856
-        $items    = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
857
-        $statuses = [
858
-            'sold_out_status'  => [
859
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
860
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
861
-            ],
862
-            'active_status'    => [
863
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
864
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
865
-            ],
866
-            'upcoming_status'  => [
867
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
868
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
869
-            ],
870
-            'postponed_status' => [
871
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
872
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
873
-            ],
874
-            'cancelled_status' => [
875
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
876
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
877
-            ],
878
-            'expired_status'   => [
879
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
880
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
881
-            ],
882
-            'inactive_status'  => [
883
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
884
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
885
-            ],
886
-        ];
887
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
888
-        return array_merge($items, $statuses);
889
-    }
890
-
891
-
892
-    /**
893
-     * @return EEM_Event
894
-     * @throws EE_Error
895
-     * @throws ReflectionException
896
-     */
897
-    private function _event_model()
898
-    {
899
-        if (! $this->_event_model instanceof EEM_Event) {
900
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
901
-        }
902
-        return $this->_event_model;
903
-    }
904
-
905
-
906
-    /**
907
-     * Adds extra buttons to the WP CPT permalink field row.
908
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
909
-     *
910
-     * @param string $return    the current html
911
-     * @param int    $id        the post id for the page
912
-     * @param string $new_title What the title is
913
-     * @param string $new_slug  what the slug is
914
-     * @return string            The new html string for the permalink area
915
-     */
916
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
917
-    {
918
-        // make sure this is only when editing
919
-        if (! empty($id)) {
920
-            $post   = get_post($id);
921
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
922
-                       . esc_html__('Shortcode', 'event_espresso')
923
-                       . '</a> ';
924
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
925
-                       . $post->ID
926
-                       . ']">';
927
-        }
928
-        return $return;
929
-    }
930
-
931
-
932
-    /**
933
-     * _events_overview_list_table
934
-     * This contains the logic for showing the events_overview list
935
-     *
936
-     * @access protected
937
-     * @return void
938
-     * @throws EE_Error
939
-     */
940
-    protected function _events_overview_list_table()
941
-    {
942
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
943
-        $this->_template_args['after_list_table']                           =
944
-            ! empty($this->_template_args['after_list_table'])
945
-                ? (array) $this->_template_args['after_list_table']
946
-                : [];
947
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
948
-            . EEH_Template::get_button_or_link(
949
-                get_post_type_archive_link('espresso_events'),
950
-                esc_html__("View Event Archive Page", "event_espresso"),
951
-                'button'
952
-            );
953
-        $this->_template_args['after_list_table']['legend']                 = $this->_display_legend(
954
-            $this->_event_legend_items()
955
-        );
956
-        $this->_admin_page_title                                            .= ' ' . $this->get_action_link_or_button(
957
-            'create_new',
958
-            'add',
959
-            [],
960
-            'add-new-h2'
961
-        );
962
-        $this->display_admin_list_table_page_with_no_sidebar();
963
-    }
964
-
965
-
966
-    /**
967
-     * this allows for extra misc actions in the default WP publish box
968
-     *
969
-     * @return void
970
-     * @throws EE_Error
971
-     * @throws ReflectionException
972
-     */
973
-    public function extra_misc_actions_publish_box()
974
-    {
975
-        $this->_generate_publish_box_extra_content();
976
-    }
977
-
978
-
979
-    /**
980
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
981
-     * saved.
982
-     * Typically you would use this to save any additional data.
983
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
984
-     * ALSO very important.  When a post transitions from scheduled to published,
985
-     * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from
986
-     * other meta saves. So MAKE sure that you handle this accordingly.
987
-     *
988
-     * @access protected
989
-     * @abstract
990
-     * @param string $post_id The ID of the cpt that was saved (so you can link relationally)
991
-     * @param object $post    The post object of the cpt that was saved.
992
-     * @return void
993
-     * @throws EE_Error
994
-     * @throws ReflectionException
995
-     */
996
-    protected function _insert_update_cpt_item($post_id, $post)
997
-    {
998
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
999
-            // get out we're not processing an event save.
1000
-            return;
1001
-        }
1002
-
1003
-        $event_values = [
1004
-            'EVT_display_desc'                => $this->request->getRequestParam('display_desc', false, 'bool'),
1005
-            'EVT_display_ticket_selector'     => $this->request->getRequestParam(
1006
-                'display_ticket_selector',
1007
-                false,
1008
-                'bool'
1009
-            ),
1010
-            'EVT_additional_limit'            => min(
1011
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
1012
-                $this->request->getRequestParam('additional_limit', null, 'int')
1013
-            ),
1014
-            'EVT_default_registration_status' => $this->request->getRequestParam(
1015
-                'EVT_default_registration_status',
1016
-                EE_Registry::instance()->CFG->registration->default_STS_ID
1017
-            ),
1018
-
1019
-            'EVT_member_only'     => $this->request->getRequestParam('member_only', false, 'bool'),
1020
-            'EVT_allow_overflow'  => $this->request->getRequestParam('EVT_allow_overflow', false, 'bool'),
1021
-            'EVT_timezone_string' => $this->request->getRequestParam('timezone_string'),
1022
-            'EVT_external_URL'    => $this->request->getRequestParam('externalURL'),
1023
-            'EVT_phone'           => $this->request->getRequestParam('event_phone'),
1024
-        ];
1025
-        // update event
1026
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
1027
-        // get event_object for other metaboxes...
1028
-        // though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id )..
1029
-        // i have to setup where conditions to override the filters in the model
1030
-        // that filter out autodraft and inherit statuses so we GET the inherit id!
1031
-        $event = $this->_event_model()->get_one(
1032
-            [
1033
-                [
1034
-                    $this->_event_model()->primary_key_name() => $post_id,
1035
-                    'OR'                                      => [
1036
-                        'status'   => $post->post_status,
1037
-                        // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db,
1038
-                        // but the returned object here has a status of "publish", so use the original post status as well
1039
-                        'status*1' => $this->request->getRequestParam('original_post_status'),
1040
-                    ],
1041
-                ],
1042
-            ]
1043
-        );
1044
-        // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
1045
-        $event_update_callbacks = apply_filters(
1046
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
1047
-            [
1048
-                [$this, '_default_venue_update'],
1049
-                [$this, '_default_tickets_update'],
1050
-            ]
1051
-        );
1052
-        $att_success            = true;
1053
-        foreach ($event_update_callbacks as $e_callback) {
1054
-            $_success = is_callable($e_callback)
1055
-                ? call_user_func($e_callback, $event, $this->request->requestParams())
1056
-                : false;
1057
-            // if ANY of these updates fail then we want the appropriate global error message
1058
-            $att_success = ! $att_success ? $att_success : $_success;
1059
-        }
1060
-        // any errors?
1061
-        if ($success && false === $att_success) {
1062
-            EE_Error::add_error(
1063
-                esc_html__(
1064
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1065
-                    'event_espresso'
1066
-                ),
1067
-                __FILE__,
1068
-                __FUNCTION__,
1069
-                __LINE__
1070
-            );
1071
-        } elseif ($success === false) {
1072
-            EE_Error::add_error(
1073
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1074
-                __FILE__,
1075
-                __FUNCTION__,
1076
-                __LINE__
1077
-            );
1078
-        }
1079
-    }
1080
-
1081
-
1082
-    /**
1083
-     * @param int $post_id
1084
-     * @param int $revision_id
1085
-     * @throws EE_Error
1086
-     * @throws EE_Error
1087
-     * @throws ReflectionException
1088
-     * @see parent::restore_item()
1089
-     */
1090
-    protected function _restore_cpt_item($post_id, $revision_id)
1091
-    {
1092
-        // copy existing event meta to new post
1093
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1094
-        if ($post_evt instanceof EE_Event) {
1095
-            // meta revision restore
1096
-            $post_evt->restore_revision($revision_id);
1097
-            // related objs restore
1098
-            $post_evt->restore_revision($revision_id, ['Venue', 'Datetime', 'Price']);
1099
-        }
1100
-    }
1101
-
1102
-
1103
-    /**
1104
-     * Attach the venue to the Event
1105
-     *
1106
-     * @param EE_Event $event Event Object to add the venue to
1107
-     * @param array    $data  The request data from the form
1108
-     * @return bool           Success or fail.
1109
-     * @throws EE_Error
1110
-     * @throws ReflectionException
1111
-     */
1112
-    protected function _default_venue_update(EE_Event $event, $data)
1113
-    {
1114
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1115
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1116
-        $venue_id    = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1117
-        // very important.  If we don't have a venue name...
1118
-        // then we'll get out because not necessary to create empty venue
1119
-        if (empty($data['venue_title'])) {
1120
-            return false;
1121
-        }
1122
-        $venue_array = [
1123
-            'VNU_wp_user'         => $event->get('EVT_wp_user'),
1124
-            'VNU_name'            => $data['venue_title'],
1125
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1126
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1127
-            'VNU_short_desc'      => ! empty($data['venue_short_description'])
1128
-                ? $data['venue_short_description']
1129
-                : null,
1130
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1131
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1132
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1133
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1134
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1135
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1136
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1137
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1138
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1139
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1140
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1141
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1142
-            'status'              => 'publish',
1143
-        ];
1144
-        // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1145
-        if (! empty($venue_id)) {
1146
-            $update_where  = [$venue_model->primary_key_name() => $venue_id];
1147
-            $rows_affected = $venue_model->update($venue_array, [$update_where]);
1148
-            // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1149
-            $event->_add_relation_to($venue_id, 'Venue');
1150
-            return $rows_affected > 0;
1151
-        }
1152
-        // we insert the venue
1153
-        $venue_id = $venue_model->insert($venue_array);
1154
-        $event->_add_relation_to($venue_id, 'Venue');
1155
-        return ! empty($venue_id);
1156
-        // when we have the ancestor come in it's already been handled by the revision save.
1157
-    }
1158
-
1159
-
1160
-    /**
1161
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1162
-     *
1163
-     * @param EE_Event $event The Event object we're attaching data to
1164
-     * @param array    $data  The request data from the form
1165
-     * @return array
1166
-     * @throws EE_Error
1167
-     * @throws ReflectionException
1168
-     * @throws Exception
1169
-     */
1170
-    protected function _default_tickets_update(EE_Event $event, $data)
1171
-    {
1172
-        $datetime       = null;
1173
-        $saved_tickets  = [];
1174
-        $event_timezone = $event->get_timezone();
1175
-        $date_formats   = ['Y-m-d', 'h:i a'];
1176
-        foreach ($data['edit_event_datetimes'] as $row => $datetime_data) {
1177
-            // trim all values to ensure any excess whitespace is removed.
1178
-            $datetime_data                = array_map('trim', $datetime_data);
1179
-            $datetime_data['DTT_EVT_end'] =
1180
-                isset($datetime_data['DTT_EVT_end']) && ! empty($datetime_data['DTT_EVT_end'])
1181
-                    ? $datetime_data['DTT_EVT_end']
1182
-                    : $datetime_data['DTT_EVT_start'];
1183
-            $datetime_values              = [
1184
-                'DTT_ID'        => ! empty($datetime_data['DTT_ID']) ? $datetime_data['DTT_ID'] : null,
1185
-                'DTT_EVT_start' => $datetime_data['DTT_EVT_start'],
1186
-                'DTT_EVT_end'   => $datetime_data['DTT_EVT_end'],
1187
-                'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) ? EE_INF : $datetime_data['DTT_reg_limit'],
1188
-                'DTT_order'     => $row,
1189
-            ];
1190
-            // if we have an id then let's get existing object first and then set the new values.
1191
-            //  Otherwise we instantiate a new object for save.
1192
-            if (! empty($datetime_data['DTT_ID'])) {
1193
-                $datetime = EEM_Datetime::instance($event_timezone)->get_one_by_ID($datetime_data['DTT_ID']);
1194
-                if (! $datetime instanceof EE_Datetime) {
1195
-                    throw new RuntimeException(
1196
-                        sprintf(
1197
-                            esc_html__(
1198
-                                'Something went wrong! A valid Datetime could not be retrieved from the database using the supplied ID: %1$d',
1199
-                                'event_espresso'
1200
-                            ),
1201
-                            $datetime_data['DTT_ID']
1202
-                        )
1203
-                    );
1204
-                }
1205
-                $datetime->set_date_format($date_formats[0]);
1206
-                $datetime->set_time_format($date_formats[1]);
1207
-                foreach ($datetime_values as $field => $value) {
1208
-                    $datetime->set($field, $value);
1209
-                }
1210
-            } else {
1211
-                $datetime = EE_Datetime::new_instance($datetime_values, $event_timezone, $date_formats);
1212
-            }
1213
-            if (! $datetime instanceof EE_Datetime) {
1214
-                throw new RuntimeException(
1215
-                    sprintf(
1216
-                        esc_html__(
1217
-                            'Something went wrong! A valid Datetime could not be generated or retrieved using the supplied data: %1$s',
1218
-                            'event_espresso'
1219
-                        ),
1220
-                        print_r($datetime_values, true)
1221
-                    )
1222
-                );
1223
-            }
1224
-            // before going any further make sure our dates are setup correctly
1225
-            // so that the end date is always equal or greater than the start date.
1226
-            if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) {
1227
-                $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start'));
1228
-                $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days');
1229
-            }
1230
-            $datetime->save();
1231
-            $event->_add_relation_to($datetime, 'Datetime');
1232
-        }
1233
-        // no datetimes get deleted so we don't do any of that logic here.
1234
-        // update tickets next
1235
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : [];
1236
-
1237
-        // set up some default start and end dates in case those are not present in the incoming data
1238
-        $default_start_date = new DateTime('now', new DateTimeZone($event->get_timezone()));
1239
-        $default_start_date = $default_start_date->format($date_formats[0] . ' ' . $date_formats[1]);
1240
-        // use the start date of the first datetime for the end date
1241
-        $first_datetime   = $event->first_datetime();
1242
-        $default_end_date = $first_datetime->start_date_and_time($date_formats[0], $date_formats[1]);
1243
-
1244
-        // now process the incoming data
1245
-        foreach ($data['edit_tickets'] as $row => $ticket_data) {
1246
-            $update_prices = false;
1247
-            $ticket_price  = isset($data['edit_prices'][ $row ][1]['PRC_amount'])
1248
-                ? $data['edit_prices'][ $row ][1]['PRC_amount']
1249
-                : 0;
1250
-            // trim inputs to ensure any excess whitespace is removed.
1251
-            $ticket_data   = array_map('trim', $ticket_data);
1252
-            $ticket_values = [
1253
-                'TKT_ID'          => ! empty($ticket_data['TKT_ID']) ? $ticket_data['TKT_ID'] : null,
1254
-                'TTM_ID'          => ! empty($ticket_data['TTM_ID']) ? $ticket_data['TTM_ID'] : 0,
1255
-                'TKT_name'        => ! empty($ticket_data['TKT_name']) ? $ticket_data['TKT_name'] : '',
1256
-                'TKT_description' => ! empty($ticket_data['TKT_description']) ? $ticket_data['TKT_description'] : '',
1257
-                'TKT_start_date'  => ! empty($ticket_data['TKT_start_date'])
1258
-                    ? $ticket_data['TKT_start_date']
1259
-                    : $default_start_date,
1260
-                'TKT_end_date'    => ! empty($ticket_data['TKT_end_date'])
1261
-                    ? $ticket_data['TKT_end_date']
1262
-                    : $default_end_date,
1263
-                'TKT_qty'         => ! empty($ticket_data['TKT_qty'])
1264
-                                     || (isset($ticket_data['TKT_qty']) && (int) $ticket_data['TKT_qty'] === 0)
1265
-                    ? $ticket_data['TKT_qty']
1266
-                    : EE_INF,
1267
-                'TKT_uses'        => ! empty($ticket_data['TKT_uses'])
1268
-                                     || (isset($ticket_data['TKT_uses']) && (int) $ticket_data['TKT_uses'] === 0)
1269
-                    ? $ticket_data['TKT_uses']
1270
-                    : EE_INF,
1271
-                'TKT_min'         => ! empty($ticket_data['TKT_min']) ? $ticket_data['TKT_min'] : 0,
1272
-                'TKT_max'         => ! empty($ticket_data['TKT_max']) ? $ticket_data['TKT_max'] : EE_INF,
1273
-                'TKT_order'       => isset($ticket_data['TKT_order']) ? $ticket_data['TKT_order'] : $row,
1274
-                'TKT_price'       => $ticket_price,
1275
-                'TKT_row'         => $row,
1276
-            ];
1277
-            // if this is a default ticket, then we need to set the TKT_ID to 0 and update accordingly,
1278
-            // which means in turn that the prices will become new prices as well.
1279
-            if (isset($ticket_data['TKT_is_default']) && $ticket_data['TKT_is_default']) {
1280
-                $ticket_values['TKT_ID']         = 0;
1281
-                $ticket_values['TKT_is_default'] = 0;
1282
-                $update_prices                   = true;
1283
-            }
1284
-            // if we have a TKT_ID then we need to get that existing TKT_obj and update it
1285
-            // we actually do our saves ahead of adding any relations because its entirely possible that this
1286
-            // ticket didn't get removed or added to any datetime in the session but DID have it's items modified.
1287
-            // keep in mind that if the ticket has been sold (and we have changed pricing information),
1288
-            // then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1289
-            if (! empty($ticket_data['TKT_ID'])) {
1290
-                $existing_ticket = EEM_Ticket::instance($event_timezone)->get_one_by_ID($ticket_data['TKT_ID']);
1291
-                if (! $existing_ticket instanceof EE_Ticket) {
1292
-                    throw new RuntimeException(
1293
-                        sprintf(
1294
-                            esc_html__(
1295
-                                'Something went wrong! A valid Ticket could not be retrieved from the database using the supplied ID: %1$d',
1296
-                                'event_espresso'
1297
-                            ),
1298
-                            $ticket_data['TKT_ID']
1299
-                        )
1300
-                    );
1301
-                }
1302
-                $ticket_sold = $existing_ticket->count_related(
1303
-                    'Registration',
1304
-                    [
1305
-                        [
1306
-                            'STS_ID' => [
1307
-                                'NOT IN',
1308
-                                [EEM_Registration::status_id_incomplete],
1309
-                            ],
1310
-                        ],
1311
-                    ]
1312
-                ) > 0;
1313
-                // let's just check the total price for the existing ticket and determine if it matches the new total price.
1314
-                // if they are different then we create a new ticket (if $ticket_sold)
1315
-                // if they aren't different then we go ahead and modify existing ticket.
1316
-                $create_new_ticket = $ticket_sold
1317
-                                     && $ticket_price !== $existing_ticket->price()
1318
-                                     && ! $existing_ticket->deleted();
1319
-                $existing_ticket->set_date_format($date_formats[0]);
1320
-                $existing_ticket->set_time_format($date_formats[1]);
1321
-                // set new values
1322
-                foreach ($ticket_values as $field => $value) {
1323
-                    if ($field == 'TKT_qty') {
1324
-                        $existing_ticket->set_qty($value);
1325
-                    } elseif ($field == 'TKT_price') {
1326
-                        $existing_ticket->set('TKT_price', $ticket_price);
1327
-                    } else {
1328
-                        $existing_ticket->set($field, $value);
1329
-                    }
1330
-                }
1331
-                $ticket = $existing_ticket;
1332
-                // if $create_new_ticket is false then we can safely update the existing ticket.
1333
-                //  Otherwise we have to create a new ticket.
1334
-                if ($create_new_ticket) {
1335
-                    // archive the old ticket first
1336
-                    $existing_ticket->set('TKT_deleted', 1);
1337
-                    $existing_ticket->save();
1338
-                    // make sure this ticket is still recorded in our $saved_tickets
1339
-                    // so we don't run it through the regular trash routine.
1340
-                    $saved_tickets[ $existing_ticket->ID() ] = $existing_ticket;
1341
-                    // create new ticket that's a copy of the existing except,
1342
-                    // (a new id of course and not archived) AND has the new TKT_price associated with it.
1343
-                    $new_ticket = clone $existing_ticket;
1344
-                    $new_ticket->set('TKT_ID', 0);
1345
-                    $new_ticket->set('TKT_deleted', 0);
1346
-                    $new_ticket->set('TKT_sold', 0);
1347
-                    // now we need to make sure that $new prices are created as well and attached to new ticket.
1348
-                    $update_prices = true;
1349
-                    $ticket        = $new_ticket;
1350
-                }
1351
-            } else {
1352
-                // no TKT_id so a new ticket
1353
-                $ticket_values['TKT_price'] = $ticket_price;
1354
-                $ticket                     = EE_Ticket::new_instance($ticket_values, $event_timezone, $date_formats);
1355
-                $update_prices              = true;
1356
-            }
1357
-            if (! $ticket instanceof EE_Ticket) {
1358
-                throw new RuntimeException(
1359
-                    sprintf(
1360
-                        esc_html__(
1361
-                            'Something went wrong! A valid Ticket could not be generated or retrieved using the supplied data: %1$s',
1362
-                            'event_espresso'
1363
-                        ),
1364
-                        print_r($ticket_values, true)
1365
-                    )
1366
-                );
1367
-            }
1368
-            // cap ticket qty by datetime reg limits
1369
-            $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit')));
1370
-            // update ticket.
1371
-            $ticket->save();
1372
-            // before going any further make sure our dates are setup correctly
1373
-            // so that the end date is always equal or greater than the start date.
1374
-            if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) {
1375
-                $ticket->set('TKT_end_date', $ticket->get('TKT_start_date'));
1376
-                $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days');
1377
-                $ticket->save();
1378
-            }
1379
-            // initially let's add the ticket to the datetime
1380
-            $datetime->_add_relation_to($ticket, 'Ticket');
1381
-            $saved_tickets[ $ticket->ID() ] = $ticket;
1382
-            // add prices to ticket
1383
-            $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $ticket, $update_prices);
1384
-        }
1385
-        // however now we need to handle permanently deleting tickets via the ui.
1386
-        //  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.
1387
-        //  However, it does allow for deleting tickets that have no tickets sold,
1388
-        // in which case we want to get rid of permanently because there is no need to save in db.
1389
-        $old_tickets     = isset($old_tickets[0]) && $old_tickets[0] == '' ? [] : $old_tickets;
1390
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1391
-        foreach ($tickets_removed as $id) {
1392
-            $id = absint($id);
1393
-            // get the ticket for this id
1394
-            $ticket_to_remove = EEM_Ticket::instance()->get_one_by_ID($id);
1395
-            if (! $ticket_to_remove instanceof EE_Ticket) {
1396
-                continue;
1397
-            }
1398
-            // need to get all the related datetimes on this ticket and remove from every single one of them
1399
-            // (remember this process can ONLY kick off if there are NO tickets sold)
1400
-            $related_datetimes = $ticket_to_remove->get_many_related('Datetime');
1401
-            foreach ($related_datetimes as $related_datetime) {
1402
-                $ticket_to_remove->_remove_relation_to($related_datetime, 'Datetime');
1403
-            }
1404
-            // need to do the same for prices (except these prices can also be deleted because again,
1405
-            // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1406
-            $ticket_to_remove->delete_related_permanently('Price');
1407
-            // finally let's delete this ticket
1408
-            // (which should not be blocked at this point b/c we've removed all our relationships)
1409
-            $ticket_to_remove->delete_permanently();
1410
-        }
1411
-        return [$datetime, $saved_tickets];
1412
-    }
1413
-
1414
-
1415
-    /**
1416
-     * This attaches a list of given prices to a ticket.
1417
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1418
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1419
-     * price info and prices are automatically "archived" via the ticket.
1420
-     *
1421
-     * @access  private
1422
-     * @param array     $prices_data Array of prices from the form.
1423
-     * @param EE_Ticket $ticket      EE_Ticket object that prices are being attached to.
1424
-     * @param bool      $new_prices  Whether attach existing incoming prices or create new ones.
1425
-     * @return  void
1426
-     * @throws EE_Error
1427
-     * @throws ReflectionException
1428
-     */
1429
-    private function _add_prices_to_ticket($prices_data, EE_Ticket $ticket, $new_prices = false)
1430
-    {
1431
-        $timezone = $ticket->get_timezone();
1432
-        foreach ($prices_data as $row => $price_data) {
1433
-            $price_values = [
1434
-                'PRC_ID'         => ! empty($price_data['PRC_ID']) ? $price_data['PRC_ID'] : null,
1435
-                'PRT_ID'         => ! empty($price_data['PRT_ID']) ? $price_data['PRT_ID'] : null,
1436
-                'PRC_amount'     => ! empty($price_data['PRC_amount']) ? $price_data['PRC_amount'] : 0,
1437
-                'PRC_name'       => ! empty($price_data['PRC_name']) ? $price_data['PRC_name'] : '',
1438
-                'PRC_desc'       => ! empty($price_data['PRC_desc']) ? $price_data['PRC_desc'] : '',
1439
-                'PRC_is_default' => 0, // make sure prices are NOT set as default from this context
1440
-                'PRC_order'      => $row,
1441
-            ];
1442
-            if ($new_prices || empty($price_values['PRC_ID'])) {
1443
-                $price_values['PRC_ID'] = 0;
1444
-                $price                  = EE_Price::new_instance($price_values, $timezone);
1445
-            } else {
1446
-                $price = EEM_Price::instance($timezone)->get_one_by_ID($price_data['PRC_ID']);
1447
-                // update this price with new values
1448
-                foreach ($price_values as $field => $new_price) {
1449
-                    $price->set($field, $new_price);
1450
-                }
1451
-            }
1452
-            if (! $price instanceof EE_Price) {
1453
-                throw new RuntimeException(
1454
-                    sprintf(
1455
-                        esc_html__(
1456
-                            'Something went wrong! A valid Price could not be generated or retrieved using the supplied data: %1$s',
1457
-                            'event_espresso'
1458
-                        ),
1459
-                        print_r($price_values, true)
1460
-                    )
1461
-                );
1462
-            }
1463
-            $price->save();
1464
-            $ticket->_add_relation_to($price, 'Price');
1465
-        }
1466
-    }
1467
-
1468
-
1469
-    /**
1470
-     * Add in our autosave ajax handlers
1471
-     *
1472
-     */
1473
-    protected function _ee_autosave_create_new()
1474
-    {
1475
-    }
1476
-
1477
-
1478
-    /**
1479
-     * More autosave handlers.
1480
-     */
1481
-    protected function _ee_autosave_edit()
1482
-    {
1483
-        // TEMPORARILY EXITING CAUSE THIS IS A TODO
1484
-    }
1485
-
1486
-
1487
-    /**
1488
-     * @throws EE_Error
1489
-     * @throws ReflectionException
1490
-     */
1491
-    private function _generate_publish_box_extra_content()
1492
-    {
1493
-        // load formatter helper
1494
-        // args for getting related registrations
1495
-        $approved_query_args        = [
1496
-            [
1497
-                'REG_deleted' => 0,
1498
-                'STS_ID'      => EEM_Registration::status_id_approved,
1499
-            ],
1500
-        ];
1501
-        $not_approved_query_args    = [
1502
-            [
1503
-                'REG_deleted' => 0,
1504
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1505
-            ],
1506
-        ];
1507
-        $pending_payment_query_args = [
1508
-            [
1509
-                'REG_deleted' => 0,
1510
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1511
-            ],
1512
-        ];
1513
-        // publish box
1514
-        $publish_box_extra_args = [
1515
-            'view_approved_reg_url'        => add_query_arg(
1516
-                [
1517
-                    'action'      => 'default',
1518
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1519
-                    '_reg_status' => EEM_Registration::status_id_approved,
1520
-                ],
1521
-                REG_ADMIN_URL
1522
-            ),
1523
-            'view_not_approved_reg_url'    => add_query_arg(
1524
-                [
1525
-                    'action'      => 'default',
1526
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1527
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1528
-                ],
1529
-                REG_ADMIN_URL
1530
-            ),
1531
-            'view_pending_payment_reg_url' => add_query_arg(
1532
-                [
1533
-                    'action'      => 'default',
1534
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1535
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1536
-                ],
1537
-                REG_ADMIN_URL
1538
-            ),
1539
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1540
-                'Registration',
1541
-                $approved_query_args
1542
-            ),
1543
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1544
-                'Registration',
1545
-                $not_approved_query_args
1546
-            ),
1547
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1548
-                'Registration',
1549
-                $pending_payment_query_args
1550
-            ),
1551
-            'misc_pub_section_class'       => apply_filters(
1552
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1553
-                'misc-pub-section'
1554
-            ),
1555
-        ];
1556
-        ob_start();
1557
-        do_action(
1558
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1559
-            $this->_cpt_model_obj
1560
-        );
1561
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1562
-        // load template
1563
-        EEH_Template::display_template(
1564
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1565
-            $publish_box_extra_args
1566
-        );
1567
-    }
1568
-
1569
-
1570
-    /**
1571
-     * @return EE_Event
1572
-     */
1573
-    public function get_event_object()
1574
-    {
1575
-        return $this->_cpt_model_obj;
1576
-    }
1577
-
1578
-
1579
-
1580
-
1581
-    /** METABOXES * */
1582
-    /**
1583
-     * _register_event_editor_meta_boxes
1584
-     * add all metaboxes related to the event_editor
1585
-     *
1586
-     * @return void
1587
-     * @throws EE_Error
1588
-     * @throws ReflectionException
1589
-     */
1590
-    protected function _register_event_editor_meta_boxes()
1591
-    {
1592
-        $this->verify_cpt_object();
1593
-        add_meta_box(
1594
-            'espresso_event_editor_tickets',
1595
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1596
-            [$this, 'ticket_metabox'],
1597
-            $this->page_slug,
1598
-            'normal',
1599
-            'high'
1600
-        );
1601
-        add_meta_box(
1602
-            'espresso_event_editor_event_options',
1603
-            esc_html__('Event Registration Options', 'event_espresso'),
1604
-            [$this, 'registration_options_meta_box'],
1605
-            $this->page_slug,
1606
-            'side'
1607
-        );
1608
-        // NOTE: if you're looking for other metaboxes in here,
1609
-        // where a metabox has a related management page in the admin
1610
-        // you will find it setup in the related management page's "_Hooks" file.
1611
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1612
-    }
1613
-
1614
-
1615
-    /**
1616
-     * @throws DomainException
1617
-     * @throws EE_Error
1618
-     * @throws ReflectionException
1619
-     */
1620
-    public function ticket_metabox()
1621
-    {
1622
-        $existing_datetime_ids = $existing_ticket_ids = [];
1623
-        // defaults for template args
1624
-        $template_args = [
1625
-            'existing_datetime_ids'    => '',
1626
-            'event_datetime_help_link' => '',
1627
-            'ticket_options_help_link' => '',
1628
-            'time'                     => null,
1629
-            'ticket_rows'              => '',
1630
-            'existing_ticket_ids'      => '',
1631
-            'total_ticket_rows'        => 1,
1632
-            'ticket_js_structure'      => '',
1633
-            'trash_icon'               => 'ee-lock-icon',
1634
-            'disabled'                 => '',
1635
-        ];
1636
-        $event_id      = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1637
-        /**
1638
-         * 1. Start with retrieving Datetimes
1639
-         * 2. Fore each datetime get related tickets
1640
-         * 3. For each ticket get related prices
1641
-         */
1642
-        $times          = EEM_Datetime::instance()->get_all_event_dates($event_id);
1643
-        $first_datetime = reset($times);
1644
-        // do we get related tickets?
1645
-        if (
1646
-            $first_datetime instanceof EE_Datetime
1647
-            && $first_datetime->ID() !== 0
1648
-        ) {
1649
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1650
-            $template_args['time']   = $first_datetime;
1651
-            $related_tickets         = $first_datetime->tickets(
1652
-                [
1653
-                    ['OR' => ['TKT_deleted' => 1, 'TKT_deleted*' => 0]],
1654
-                    'default_where_conditions' => 'none',
1655
-                ]
1656
-            );
1657
-            if (! empty($related_tickets)) {
1658
-                $template_args['total_ticket_rows'] = count($related_tickets);
1659
-                $row                                = 0;
1660
-                foreach ($related_tickets as $ticket) {
1661
-                    $existing_ticket_ids[]        = $ticket->get('TKT_ID');
1662
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1663
-                    $row++;
1664
-                }
1665
-            } else {
1666
-                $template_args['total_ticket_rows'] = 1;
1667
-                /** @type EE_Ticket $ticket */
1668
-                $ticket                       = EEM_Ticket::instance()->create_default_object();
1669
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1670
-            }
1671
-        } else {
1672
-            $template_args['time']        = $times[0];
1673
-            $tickets                      = EEM_Ticket::instance()->get_all_default_tickets();
1674
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($tickets[1]);
1675
-            // NOTE: we're just sending the first default row
1676
-            // (decaf can't manage default tickets so this should be sufficient);
1677
-        }
1678
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1679
-            'event_editor_event_datetimes_help_tab'
1680
-        );
1681
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1682
-        $template_args['existing_datetime_ids']    = implode(',', $existing_datetime_ids);
1683
-        $template_args['existing_ticket_ids']      = implode(',', $existing_ticket_ids);
1684
-        $template_args['ticket_js_structure']      = $this->_get_ticket_row(
1685
-            EEM_Ticket::instance()->create_default_object(),
1686
-            true
1687
-        );
1688
-        $template                                  = apply_filters(
1689
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1690
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1691
-        );
1692
-        EEH_Template::display_template($template, $template_args);
1693
-    }
1694
-
1695
-
1696
-    /**
1697
-     * Setup an individual ticket form for the decaf event editor page
1698
-     *
1699
-     * @access private
1700
-     * @param EE_Ticket $ticket   the ticket object
1701
-     * @param boolean   $skeleton whether we're generating a skeleton for js manipulation
1702
-     * @param int       $row
1703
-     * @return string generated html for the ticket row.
1704
-     * @throws EE_Error
1705
-     * @throws ReflectionException
1706
-     */
1707
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1708
-    {
1709
-        $template_args = [
1710
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1711
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1712
-                : '',
1713
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1714
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1715
-            'TKT_name'            => $ticket->get('TKT_name'),
1716
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1717
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1718
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1719
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1720
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1721
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1722
-            'trash_icon'          => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')))
1723
-                                     && (! empty($ticket) && $ticket->get('TKT_sold') === 0)
1724
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1725
-            'disabled'            => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1726
-                : ' disabled=disabled',
1727
-        ];
1728
-        $price         = $ticket->ID() !== 0
1729
-            ? $ticket->get_first_related('Price', ['default_where_conditions' => 'none'])
1730
-            : null;
1731
-        $price         = $price instanceof EE_Price
1732
-            ? $price
1733
-            : EEM_Price::instance()->create_default_object();
1734
-        $price_args    = [
1735
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1736
-            'PRC_amount'            => $price->get('PRC_amount'),
1737
-            'PRT_ID'                => $price->get('PRT_ID'),
1738
-            'PRC_ID'                => $price->get('PRC_ID'),
1739
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1740
-        ];
1741
-        // make sure we have default start and end dates if skeleton
1742
-        // handle rows that should NOT be empty
1743
-        if (empty($template_args['TKT_start_date'])) {
1744
-            // if empty then the start date will be now.
1745
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1746
-        }
1747
-        if (empty($template_args['TKT_end_date'])) {
1748
-            // get the earliest datetime (if present);
1749
-            $earliest_datetime             = $this->_cpt_model_obj->ID() > 0
1750
-                ? $this->_cpt_model_obj->get_first_related(
1751
-                    'Datetime',
1752
-                    ['order_by' => ['DTT_EVT_start' => 'ASC']]
1753
-                )
1754
-                : null;
1755
-            $template_args['TKT_end_date'] = $earliest_datetime instanceof EE_Datetime
1756
-                ? $earliest_datetime->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a')
1757
-                : date('Y-m-d h:i a', mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')));
1758
-        }
1759
-        $template_args = array_merge($template_args, $price_args);
1760
-        $template      = apply_filters(
1761
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1762
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1763
-            $ticket
1764
-        );
1765
-        return EEH_Template::display_template($template, $template_args, true);
1766
-    }
1767
-
1768
-
1769
-    /**
1770
-     * @throws EE_Error
1771
-     * @throws ReflectionException
1772
-     */
1773
-    public function registration_options_meta_box()
1774
-    {
1775
-        $yes_no_values             = [
1776
-            ['id' => true, 'text' => esc_html__('Yes', 'event_espresso')],
1777
-            ['id' => false, 'text' => esc_html__('No', 'event_espresso')],
1778
-        ];
1779
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1780
-            [
1781
-                EEM_Registration::status_id_cancelled,
1782
-                EEM_Registration::status_id_declined,
1783
-                EEM_Registration::status_id_incomplete,
1784
-            ],
1785
-            true
1786
-        );
1787
-        // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1788
-        $template_args['_event']                          = $this->_cpt_model_obj;
1789
-        $template_args['event']                           = $this->_cpt_model_obj;
1790
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
1791
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
1792
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
1793
-            'default_reg_status',
1794
-            $default_reg_status_values,
1795
-            $this->_cpt_model_obj->default_registration_status()
1796
-        );
1797
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
1798
-            'display_desc',
1799
-            $yes_no_values,
1800
-            $this->_cpt_model_obj->display_description()
1801
-        );
1802
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
1803
-            'display_ticket_selector',
1804
-            $yes_no_values,
1805
-            $this->_cpt_model_obj->display_ticket_selector(),
1806
-            '',
1807
-            '',
1808
-            false
1809
-        );
1810
-        $template_args['additional_registration_options'] = apply_filters(
1811
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1812
-            '',
1813
-            $template_args,
1814
-            $yes_no_values,
1815
-            $default_reg_status_values
1816
-        );
1817
-        EEH_Template::display_template(
1818
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1819
-            $template_args
1820
-        );
1821
-    }
1822
-
1823
-
1824
-    /**
1825
-     * _get_events()
1826
-     * This method simply returns all the events (for the given _view and paging)
1827
-     *
1828
-     * @access public
1829
-     * @param int  $per_page     count of items per page (20 default);
1830
-     * @param int  $current_page what is the current page being viewed.
1831
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1832
-     *                           If FALSE then we return an array of event objects
1833
-     *                           that match the given _view and paging parameters.
1834
-     * @return array|int         an array of event objects or a count of them.
1835
-     * @throws Exception
1836
-     */
1837
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1838
-    {
1839
-        $EEM_Event   = $this->_event_model();
1840
-        $offset      = ($current_page - 1) * $per_page;
1841
-        $limit       = $count ? null : $offset . ',' . $per_page;
1842
-        $orderby     = $this->request->getRequestParam('orderby', 'EVT_ID');
1843
-        $order       = $this->request->getRequestParam('order', 'DESC');
1844
-        $month_range = $this->request->getRequestParam('month_range');
1845
-        if ($month_range) {
1846
-            $pieces = explode(' ', $month_range, 3);
1847
-            // simulate the FIRST day of the month, that fixes issues for months like February
1848
-            // where PHP doesn't know what to assume for date.
1849
-            // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437
1850
-            $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : '';
1851
-            $year_r  = ! empty($pieces[1]) ? $pieces[1] : '';
1852
-        }
1853
-        $where  = [];
1854
-        $status = $this->request->getRequestParam('status');
1855
-        // determine what post_status our condition will have for the query.
1856
-        switch ($status) {
1857
-            case 'month':
1858
-            case 'today':
1859
-            case null:
1860
-            case 'all':
1861
-                break;
1862
-            case 'draft':
1863
-                $where['status'] = ['IN', ['draft', 'auto-draft']];
1864
-                break;
1865
-            default:
1866
-                $where['status'] = $status;
1867
-        }
1868
-        // categories? The default for all categories is -1
1869
-        $category = $this->request->getRequestParam('EVT_CAT', -1, 'int');
1870
-        if ($category !== -1) {
1871
-            $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY;
1872
-            $where['Term_Taxonomy.term_id']  = $category;
1873
-        }
1874
-        // date where conditions
1875
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1876
-        if ($month_range) {
1877
-            $DateTime = new DateTime(
1878
-                $year_r . '-' . $month_r . '-01 00:00:00',
1879
-                new DateTimeZone('UTC')
1880
-            );
1881
-            $start    = $DateTime->getTimestamp();
1882
-            // set the datetime to be the end of the month
1883
-            $DateTime->setDate(
1884
-                $year_r,
1885
-                $month_r,
1886
-                $DateTime->format('t')
1887
-            )->setTime(23, 59, 59);
1888
-            $end                             = $DateTime->getTimestamp();
1889
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1890
-        } elseif ($status === 'today') {
1891
-            $DateTime                        =
1892
-                new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1893
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1894
-            $end                             = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1895
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1896
-        } elseif ($status === 'month') {
1897
-            $now                             = date('Y-m-01');
1898
-            $DateTime                        =
1899
-                new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1900
-            $start                           = $DateTime->setTime(0, 0)->format(implode(' ', $start_formats));
1901
-            $end                             = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1902
-                                                        ->setTime(23, 59, 59)
1903
-                                                        ->format(implode(' ', $start_formats));
1904
-            $where['Datetime.DTT_EVT_start'] = ['BETWEEN', [$start, $end]];
1905
-        }
1906
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1907
-            $where['EVT_wp_user'] = get_current_user_id();
1908
-        } else {
1909
-            if (! isset($where['status'])) {
1910
-                if (! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1911
-                    $where['OR'] = [
1912
-                        'status*restrict_private' => ['!=', 'private'],
1913
-                        'AND'                     => [
1914
-                            'status*inclusive' => ['=', 'private'],
1915
-                            'EVT_wp_user'      => get_current_user_id(),
1916
-                        ],
1917
-                    ];
1918
-                }
1919
-            }
1920
-        }
1921
-        $wp_user = $this->request->getRequestParam('EVT_wp_user', 0, 'int');
1922
-        if (
1923
-            $wp_user
1924
-            && $wp_user !== get_current_user_id()
1925
-            && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1926
-        ) {
1927
-            $where['EVT_wp_user'] = $wp_user;
1928
-        }
1929
-        // search query handling
1930
-        $search_term = $this->request->getRequestParam('s');
1931
-        if ($search_term) {
1932
-            $search_term = '%' . $search_term . '%';
1933
-            $where['OR'] = [
1934
-                'EVT_name'       => ['LIKE', $search_term],
1935
-                'EVT_desc'       => ['LIKE', $search_term],
1936
-                'EVT_short_desc' => ['LIKE', $search_term],
1937
-            ];
1938
-        }
1939
-        // filter events by venue.
1940
-        $venue = $this->request->getRequestParam('venue', 0, 'int');
1941
-        if ($venue) {
1942
-            $where['Venue.VNU_ID'] = $venue;
1943
-        }
1944
-        $request_params = $this->request->requestParams();
1945
-        $where          = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $request_params);
1946
-        $query_params   = apply_filters(
1947
-            'FHEE__Events_Admin_Page__get_events__query_params',
1948
-            [
1949
-                $where,
1950
-                'limit'    => $limit,
1951
-                'order_by' => $orderby,
1952
-                'order'    => $order,
1953
-                'group_by' => 'EVT_ID',
1954
-            ],
1955
-            $request_params
1956
-        );
1957
-
1958
-        // let's first check if we have special requests coming in.
1959
-        $active_status = $this->request->getRequestParam('active_status');
1960
-        if ($active_status) {
1961
-            switch ($active_status) {
1962
-                case 'upcoming':
1963
-                    return $EEM_Event->get_upcoming_events($query_params, $count);
1964
-                case 'expired':
1965
-                    return $EEM_Event->get_expired_events($query_params, $count);
1966
-                case 'active':
1967
-                    return $EEM_Event->get_active_events($query_params, $count);
1968
-                case 'inactive':
1969
-                    return $EEM_Event->get_inactive_events($query_params, $count);
1970
-            }
1971
-        }
1972
-
1973
-        return $count ? $EEM_Event->count([$where], 'EVT_ID', true) : $EEM_Event->get_all($query_params);
1974
-    }
1975
-
1976
-
1977
-    /**
1978
-     * handling for WordPress CPT actions (trash, restore, delete)
1979
-     *
1980
-     * @param string $post_id
1981
-     * @throws EE_Error
1982
-     * @throws ReflectionException
1983
-     */
1984
-    public function trash_cpt_item($post_id)
1985
-    {
1986
-        $this->request->setRequestParam('EVT_ID', $post_id);
1987
-        $this->_trash_or_restore_event('trash', false);
1988
-    }
1989
-
1990
-
1991
-    /**
1992
-     * @param string $post_id
1993
-     * @throws EE_Error
1994
-     * @throws ReflectionException
1995
-     */
1996
-    public function restore_cpt_item($post_id)
1997
-    {
1998
-        $this->request->setRequestParam('EVT_ID', $post_id);
1999
-        $this->_trash_or_restore_event('draft', false);
2000
-    }
2001
-
2002
-
2003
-    /**
2004
-     * @param string $post_id
2005
-     * @throws EE_Error
2006
-     * @throws EE_Error
2007
-     */
2008
-    public function delete_cpt_item($post_id)
2009
-    {
2010
-        throw new EE_Error(
2011
-            esc_html__(
2012
-                'Please contact Event Espresso support with the details of the steps taken to produce this error.',
2013
-                'event_espresso'
2014
-            )
2015
-        );
2016
-        // $this->request->setRequestParam('EVT_ID', $post_id);
2017
-        // $this->_delete_event();
2018
-    }
2019
-
2020
-
2021
-    /**
2022
-     * _trash_or_restore_event
2023
-     *
2024
-     * @access protected
2025
-     * @param string $event_status
2026
-     * @param bool   $redirect_after
2027
-     * @throws EE_Error
2028
-     * @throws EE_Error
2029
-     * @throws ReflectionException
2030
-     */
2031
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
2032
-    {
2033
-        // determine the event id and set to array.
2034
-        $EVT_ID = $this->request->getRequestParam('EVT_ID', 0, 'int');
2035
-        // loop thru events
2036
-        if ($EVT_ID) {
2037
-            // clean status
2038
-            $event_status = sanitize_key($event_status);
2039
-            // grab status
2040
-            if (! empty($event_status)) {
2041
-                $success = $this->_change_event_status($EVT_ID, $event_status);
2042
-            } else {
2043
-                $success = false;
2044
-                $msg     = esc_html__(
2045
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2046
-                    'event_espresso'
2047
-                );
2048
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2049
-            }
2050
-        } else {
2051
-            $success = false;
2052
-            $msg     = esc_html__(
2053
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
2054
-                'event_espresso'
2055
-            );
2056
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2057
-        }
2058
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2059
-        if ($redirect_after) {
2060
-            $this->_redirect_after_action($success, 'Event', $action, ['action' => 'default']);
2061
-        }
2062
-    }
2063
-
2064
-
2065
-    /**
2066
-     * _trash_or_restore_events
2067
-     *
2068
-     * @access protected
2069
-     * @param string $event_status
2070
-     * @return void
2071
-     * @throws EE_Error
2072
-     * @throws EE_Error
2073
-     * @throws ReflectionException
2074
-     */
2075
-    protected function _trash_or_restore_events($event_status = 'trash')
2076
-    {
2077
-        // clean status
2078
-        $event_status = sanitize_key($event_status);
2079
-        // grab status
2080
-        if (! empty($event_status)) {
2081
-            $success = true;
2082
-            // determine the event id and set to array.
2083
-            $EVT_IDs = $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2084
-            // loop thru events
2085
-            foreach ($EVT_IDs as $EVT_ID) {
2086
-                if ($EVT_ID = absint($EVT_ID)) {
2087
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
2088
-                    $success = $results !== false ? $success : false;
2089
-                } else {
2090
-                    $msg = sprintf(
2091
-                        esc_html__(
2092
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
2093
-                            'event_espresso'
2094
-                        ),
2095
-                        $EVT_ID
2096
-                    );
2097
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2098
-                    $success = false;
2099
-                }
2100
-            }
2101
-        } else {
2102
-            $success = false;
2103
-            $msg     = esc_html__(
2104
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
2105
-                'event_espresso'
2106
-            );
2107
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2108
-        }
2109
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2110
-        $success = $success ? 2 : false;
2111
-        $action  = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
2112
-        $this->_redirect_after_action($success, 'Events', $action, ['action' => 'default']);
2113
-    }
2114
-
2115
-
2116
-    /**
2117
-     * @param int    $EVT_ID
2118
-     * @param string $event_status
2119
-     * @return bool
2120
-     * @throws EE_Error
2121
-     * @throws ReflectionException
2122
-     */
2123
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
2124
-    {
2125
-        // grab event id
2126
-        if (! $EVT_ID) {
2127
-            $msg = esc_html__(
2128
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2129
-                'event_espresso'
2130
-            );
2131
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2132
-            return false;
2133
-        }
2134
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2135
-        // clean status
2136
-        $event_status = sanitize_key($event_status);
2137
-        // grab status
2138
-        if (empty($event_status)) {
2139
-            $msg = esc_html__(
2140
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2141
-                'event_espresso'
2142
-            );
2143
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2144
-            return false;
2145
-        }
2146
-        // was event trashed or restored ?
2147
-        switch ($event_status) {
2148
-            case 'draft':
2149
-                $action = 'restored from the trash';
2150
-                $hook   = 'AHEE_event_restored_from_trash';
2151
-                break;
2152
-            case 'trash':
2153
-                $action = 'moved to the trash';
2154
-                $hook   = 'AHEE_event_moved_to_trash';
2155
-                break;
2156
-            default:
2157
-                $action = 'updated';
2158
-                $hook   = false;
2159
-        }
2160
-        // use class to change status
2161
-        $this->_cpt_model_obj->set_status($event_status);
2162
-        $success = $this->_cpt_model_obj->save();
2163
-        if (! $success) {
2164
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2165
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2166
-            return false;
2167
-        }
2168
-        if ($hook) {
2169
-            do_action($hook);
2170
-        }
2171
-        return true;
2172
-    }
2173
-
2174
-
2175
-    /**
2176
-     * @param array $event_ids
2177
-     * @return array
2178
-     * @since   4.10.23.p
2179
-     */
2180
-    private function cleanEventIds(array $event_ids)
2181
-    {
2182
-        return array_map('absint', $event_ids);
2183
-    }
2184
-
2185
-
2186
-    /**
2187
-     * @return array
2188
-     * @since   4.10.23.p
2189
-     */
2190
-    private function getEventIdsFromRequest()
2191
-    {
2192
-        if ($this->request->requestParamIsSet('EVT_IDs')) {
2193
-            return $this->request->getRequestParam('EVT_IDs', [], 'int', true);
2194
-        } else {
2195
-            return $this->request->getRequestParam('EVT_ID', [], 'int', true);
2196
-        }
2197
-    }
2198
-
2199
-
2200
-    /**
2201
-     * @param bool $preview_delete
2202
-     * @throws EE_Error
2203
-     */
2204
-    protected function _delete_event($preview_delete = true)
2205
-    {
2206
-        $this->_delete_events($preview_delete);
2207
-    }
2208
-
2209
-
2210
-    /**
2211
-     * Gets the tree traversal batch persister.
2212
-     *
2213
-     * @return NodeGroupDao
2214
-     * @throws InvalidArgumentException
2215
-     * @throws InvalidDataTypeException
2216
-     * @throws InvalidInterfaceException
2217
-     * @since 4.10.12.p
2218
-     */
2219
-    protected function getModelObjNodeGroupPersister()
2220
-    {
2221
-        if (! $this->model_obj_node_group_persister instanceof NodeGroupDao) {
2222
-            $this->model_obj_node_group_persister =
2223
-                $this->getLoader()->load('\EventEspresso\core\services\orm\tree_traversal\NodeGroupDao');
2224
-        }
2225
-        return $this->model_obj_node_group_persister;
2226
-    }
2227
-
2228
-
2229
-    /**
2230
-     * @param bool $preview_delete
2231
-     * @return void
2232
-     * @throws EE_Error
2233
-     */
2234
-    protected function _delete_events($preview_delete = true)
2235
-    {
2236
-        $event_ids = $this->getEventIdsFromRequest();
2237
-        if ($preview_delete) {
2238
-            $this->generateDeletionPreview($event_ids);
2239
-        } else {
2240
-            EEM_Event::instance()->delete_permanently([['EVT_ID' => ['IN', $event_ids]]]);
2241
-        }
2242
-    }
2243
-
2244
-
2245
-    /**
2246
-     * @param array $event_ids
2247
-     */
2248
-    protected function generateDeletionPreview(array $event_ids)
2249
-    {
2250
-        $event_ids = $this->cleanEventIds($event_ids);
2251
-        // Set a code we can use to reference this deletion task in the batch jobs and preview page.
2252
-        $deletion_job_code = $this->getModelObjNodeGroupPersister()->generateGroupCode();
2253
-        $return_url        = EE_Admin_Page::add_query_args_and_nonce(
2254
-            [
2255
-                'action'            => 'preview_deletion',
2256
-                'deletion_job_code' => $deletion_job_code,
2257
-            ],
2258
-            $this->_admin_base_url
2259
-        );
2260
-        EEH_URL::safeRedirectAndExit(
2261
-            EE_Admin_Page::add_query_args_and_nonce(
2262
-                [
2263
-                    'page'              => 'espresso_batch',
2264
-                    'batch'             => EED_Batch::batch_job,
2265
-                    'EVT_IDs'           => $event_ids,
2266
-                    'deletion_job_code' => $deletion_job_code,
2267
-                    'job_handler'       => urlencode('EventEspressoBatchRequest\JobHandlers\PreviewEventDeletion'),
2268
-                    'return_url'        => urlencode($return_url),
2269
-                ],
2270
-                admin_url()
2271
-            )
2272
-        );
2273
-    }
2274
-
2275
-
2276
-    /**
2277
-     * Checks for a POST submission
2278
-     *
2279
-     * @since 4.10.12.p
2280
-     */
2281
-    protected function confirmDeletion()
2282
-    {
2283
-        $deletion_redirect_logic =
2284
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\ConfirmDeletion');
2285
-        $deletion_redirect_logic->handle($this->get_request_data(), $this->admin_base_url());
2286
-    }
2287
-
2288
-
2289
-    /**
2290
-     * A page for users to preview what exactly will be deleted, and confirm they want to delete it.
2291
-     *
2292
-     * @throws EE_Error
2293
-     * @since 4.10.12.p
2294
-     */
2295
-    protected function previewDeletion()
2296
-    {
2297
-        $preview_deletion_logic =
2298
-            $this->getLoader()->getShared('\EventEspresso\core\domain\services\admin\events\data\PreviewDeletion');
2299
-        $this->set_template_args($preview_deletion_logic->handle($this->get_request_data(), $this->admin_base_url()));
2300
-        $this->display_admin_page_with_no_sidebar();
2301
-    }
2302
-
2303
-
2304
-    /**
2305
-     * get total number of events
2306
-     *
2307
-     * @access public
2308
-     * @return int
2309
-     * @throws EE_Error
2310
-     * @throws EE_Error
2311
-     */
2312
-    public function total_events()
2313
-    {
2314
-        return EEM_Event::instance()->count(
2315
-            ['caps' => 'read_admin'],
2316
-            'EVT_ID',
2317
-            true
2318
-        );
2319
-    }
2320
-
2321
-
2322
-    /**
2323
-     * get total number of draft events
2324
-     *
2325
-     * @access public
2326
-     * @return int
2327
-     * @throws EE_Error
2328
-     * @throws EE_Error
2329
-     */
2330
-    public function total_events_draft()
2331
-    {
2332
-        return EEM_Event::instance()->count(
2333
-            [
2334
-                ['status' => ['IN', ['draft', 'auto-draft']]],
2335
-                'caps' => 'read_admin',
2336
-            ],
2337
-            'EVT_ID',
2338
-            true
2339
-        );
2340
-    }
2341
-
2342
-
2343
-    /**
2344
-     * get total number of trashed events
2345
-     *
2346
-     * @access public
2347
-     * @return int
2348
-     * @throws EE_Error
2349
-     * @throws EE_Error
2350
-     */
2351
-    public function total_trashed_events()
2352
-    {
2353
-        return EEM_Event::instance()->count(
2354
-            [
2355
-                ['status' => 'trash'],
2356
-                'caps' => 'read_admin',
2357
-            ],
2358
-            'EVT_ID',
2359
-            true
2360
-        );
2361
-    }
2362
-
2363
-
2364
-    /**
2365
-     *    _default_event_settings
2366
-     *    This generates the Default Settings Tab
2367
-     *
2368
-     * @return void
2369
-     * @throws EE_Error
2370
-     */
2371
-    protected function _default_event_settings()
2372
-    {
2373
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2374
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2375
-        $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html();
2376
-        $this->display_admin_page_with_sidebar();
2377
-    }
2378
-
2379
-
2380
-    /**
2381
-     * Return the form for event settings.
2382
-     *
2383
-     * @return EE_Form_Section_Proper
2384
-     * @throws EE_Error
2385
-     */
2386
-    protected function _default_event_settings_form()
2387
-    {
2388
-        $registration_config              = EE_Registry::instance()->CFG->registration;
2389
-        $registration_stati_for_selection = EEM_Registration::reg_status_array(
2390
-        // exclude
2391
-            [
2392
-                EEM_Registration::status_id_cancelled,
2393
-                EEM_Registration::status_id_declined,
2394
-                EEM_Registration::status_id_incomplete,
2395
-                EEM_Registration::status_id_wait_list,
2396
-            ],
2397
-            true
2398
-        );
2399
-        return new EE_Form_Section_Proper(
2400
-            [
2401
-                'name'            => 'update_default_event_settings',
2402
-                'html_id'         => 'update_default_event_settings',
2403
-                'html_class'      => 'form-table',
2404
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
2405
-                'subsections'     => apply_filters(
2406
-                    'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections',
2407
-                    [
2408
-                        'default_reg_status'  => new EE_Select_Input(
2409
-                            $registration_stati_for_selection,
2410
-                            [
2411
-                                'default'         => isset($registration_config->default_STS_ID)
2412
-                                                     && array_key_exists(
2413
-                                                         $registration_config->default_STS_ID,
2414
-                                                         $registration_stati_for_selection
2415
-                                                     )
2416
-                                    ? sanitize_text_field($registration_config->default_STS_ID)
2417
-                                    : EEM_Registration::status_id_pending_payment,
2418
-                                'html_label_text' => esc_html__('Default Registration Status', 'event_espresso')
2419
-                                                     . EEH_Template::get_help_tab_link(
2420
-                                                         'default_settings_status_help_tab'
2421
-                                                     ),
2422
-                                'html_help_text'  => esc_html__(
2423
-                                    'This setting allows you to preselect what the default registration status setting is when creating an event.  Note that changing this setting does NOT retroactively apply it to existing events.',
2424
-                                    'event_espresso'
2425
-                                ),
2426
-                            ]
2427
-                        ),
2428
-                        'default_max_tickets' => new EE_Integer_Input(
2429
-                            [
2430
-                                'default'         => isset($registration_config->default_maximum_number_of_tickets)
2431
-                                    ? $registration_config->default_maximum_number_of_tickets
2432
-                                    : EEM_Event::get_default_additional_limit(),
2433
-                                'html_label_text' => esc_html__(
2434
-                                    'Default Maximum Tickets Allowed Per Order:',
2435
-                                    'event_espresso'
2436
-                                )
2437
-                                . EEH_Template::get_help_tab_link(
2438
-                                    'default_maximum_tickets_help_tab"'
2439
-                                ),
2440
-                                'html_help_text'  => esc_html__(
2441
-                                    'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.',
2442
-                                    'event_espresso'
2443
-                                ),
2444
-                            ]
2445
-                        ),
2446
-                    ]
2447
-                ),
2448
-            ]
2449
-        );
2450
-    }
2451
-
2452
-
2453
-    /**
2454
-     * _update_default_event_settings
2455
-     *
2456
-     * @access protected
2457
-     * @return void
2458
-     * @throws EE_Error
2459
-     */
2460
-    protected function _update_default_event_settings()
2461
-    {
2462
-        $registration_config = EE_Registry::instance()->CFG->registration;
2463
-        $form                = $this->_default_event_settings_form();
2464
-        if ($form->was_submitted()) {
2465
-            $form->receive_form_submission();
2466
-            if ($form->is_valid()) {
2467
-                $valid_data = $form->valid_data();
2468
-                if (isset($valid_data['default_reg_status'])) {
2469
-                    $registration_config->default_STS_ID = $valid_data['default_reg_status'];
2470
-                }
2471
-                if (isset($valid_data['default_max_tickets'])) {
2472
-                    $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets'];
2473
-                }
2474
-                // update because data was valid!
2475
-                EE_Registry::instance()->CFG->update_espresso_config();
2476
-                EE_Error::overwrite_success();
2477
-                EE_Error::add_success(
2478
-                    esc_html__('Default Event Settings were updated', 'event_espresso')
2479
-                );
2480
-            }
2481
-        }
2482
-        $this->_redirect_after_action(0, '', '', ['action' => 'default_event_settings'], true);
2483
-    }
2484
-
2485
-
2486
-    /*************        Templates        *************
2487
-     *
2488
-     * @throws EE_Error
2489
-     */
2490
-    protected function _template_settings()
2491
-    {
2492
-        $this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2493
-        $this->_template_args['preview_img']  = '<img src="'
2494
-                                                . EVENTS_ASSETS_URL
2495
-                                                . '/images/'
2496
-                                                . 'caffeinated_template_features.jpg" alt="'
2497
-                                                . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2498
-                                                . '" />';
2499
-        $this->_template_args['preview_text'] = '<strong>'
2500
-                                                . esc_html__(
2501
-                                                    'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2502
-                                                    'event_espresso'
2503
-                                                ) . '</strong>';
2504
-        $this->display_admin_caf_preview_page('template_settings_tab');
2505
-    }
2506
-
2507
-
2508
-    /** Event Category Stuff **/
2509
-    /**
2510
-     * set the _category property with the category object for the loaded page.
2511
-     *
2512
-     * @access private
2513
-     * @return void
2514
-     */
2515
-    private function _set_category_object()
2516
-    {
2517
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2518
-            return;
2519
-        } //already have the category object so get out.
2520
-        // set default category object
2521
-        $this->_set_empty_category_object();
2522
-        // only set if we've got an id
2523
-        $category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2524
-        if (! $category_ID) {
2525
-            return;
2526
-        }
2527
-        $term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2528
-        if (! empty($term)) {
2529
-            $this->_category->category_name       = $term->name;
2530
-            $this->_category->category_identifier = $term->slug;
2531
-            $this->_category->category_desc       = $term->description;
2532
-            $this->_category->id                  = $term->term_id;
2533
-            $this->_category->parent              = $term->parent;
2534
-        }
2535
-    }
2536
-
2537
-
2538
-    /**
2539
-     * Clears out category properties.
2540
-     */
2541
-    private function _set_empty_category_object()
2542
-    {
2543
-        $this->_category                = new stdClass();
2544
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2545
-        $this->_category->id            = $this->_category->parent = 0;
2546
-    }
2547
-
2548
-
2549
-    /**
2550
-     * @throws EE_Error
2551
-     */
2552
-    protected function _category_list_table()
2553
-    {
2554
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2555
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2556
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2557
-            'add_category',
2558
-            'add_category',
2559
-            [],
2560
-            'add-new-h2'
2561
-        );
2562
-        $this->display_admin_list_table_page_with_sidebar();
2563
-    }
2564
-
2565
-
2566
-    /**
2567
-     * Output category details view.
2568
-     *
2569
-     * @throws EE_Error
2570
-     * @throws EE_Error
2571
-     */
2572
-    protected function _category_details($view)
2573
-    {
2574
-        // load formatter helper
2575
-        // load field generator helper
2576
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2577
-        $this->_set_add_edit_form_tags($route);
2578
-        $this->_set_category_object();
2579
-        $id            = ! empty($this->_category->id) ? $this->_category->id : '';
2580
-        $delete_action = 'delete_category';
2581
-        // custom redirect
2582
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2583
-            ['action' => 'category_list'],
2584
-            $this->_admin_base_url
2585
-        );
2586
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2587
-        // take care of contents
2588
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2589
-        $this->display_admin_page_with_sidebar();
2590
-    }
2591
-
2592
-
2593
-    /**
2594
-     * Output category details content.
2595
-     */
2596
-    protected function _category_details_content()
2597
-    {
2598
-        $editor_args['category_desc'] = [
2599
-            'type'          => 'wp_editor',
2600
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2601
-            'class'         => 'my_editor_custom',
2602
-            'wpeditor_args' => ['media_buttons' => false],
2603
-        ];
2604
-        $_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2605
-        $all_terms                    = get_terms(
2606
-            [EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2607
-            ['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2608
-        );
2609
-        // setup category select for term parents.
2610
-        $category_select_values[] = [
2611
-            'text' => esc_html__('No Parent', 'event_espresso'),
2612
-            'id'   => 0,
2613
-        ];
2614
-        foreach ($all_terms as $term) {
2615
-            $category_select_values[] = [
2616
-                'text' => $term->name,
2617
-                'id'   => $term->term_id,
2618
-            ];
2619
-        }
2620
-        $category_select = EEH_Form_Fields::select_input(
2621
-            'category_parent',
2622
-            $category_select_values,
2623
-            $this->_category->parent
2624
-        );
2625
-        $template_args   = [
2626
-            'category'                 => $this->_category,
2627
-            'category_select'          => $category_select,
2628
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2629
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2630
-            'disable'                  => '',
2631
-            'disabled_message'         => false,
2632
-        ];
2633
-        $template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2634
-        return EEH_Template::display_template($template, $template_args, true);
2635
-    }
2636
-
2637
-
2638
-    /**
2639
-     * Handles deleting categories.
2640
-     *
2641
-     * @throws EE_Error
2642
-     */
2643
-    protected function _delete_categories()
2644
-    {
2645
-        $category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2646
-        foreach ($category_IDs as $category_ID) {
2647
-            $this->_delete_category($category_ID);
2648
-        }
2649
-        // doesn't matter what page we're coming from... we're going to the same place after delete.
2650
-        $query_args = [
2651
-            'action' => 'category_list',
2652
-        ];
2653
-        $this->_redirect_after_action(0, '', '', $query_args);
2654
-    }
2655
-
2656
-
2657
-    /**
2658
-     * Handles deleting specific category.
2659
-     *
2660
-     * @param int $cat_id
2661
-     */
2662
-    protected function _delete_category($cat_id)
2663
-    {
2664
-        $cat_id = absint($cat_id);
2665
-        wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2666
-    }
2667
-
2668
-
2669
-    /**
2670
-     * Handles triggering the update or insertion of a new category.
2671
-     *
2672
-     * @param bool $new_category true means we're triggering the insert of a new category.
2673
-     * @throws EE_Error
2674
-     * @throws EE_Error
2675
-     */
2676
-    protected function _insert_or_update_category($new_category)
2677
-    {
2678
-        $cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2679
-        $success = 0; // we already have a success message so lets not send another.
2680
-        if ($cat_id) {
2681
-            $query_args = [
2682
-                'action'     => 'edit_category',
2683
-                'EVT_CAT_ID' => $cat_id,
2684
-            ];
2685
-        } else {
2686
-            $query_args = ['action' => 'add_category'];
2687
-        }
2688
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2689
-    }
2690
-
2691
-
2692
-    /**
2693
-     * Inserts or updates category
2694
-     *
2695
-     * @param bool $update (true indicates we're updating a category).
2696
-     * @return bool|mixed|string
2697
-     */
2698
-    private function _insert_category($update = false)
2699
-    {
2700
-        $category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2701
-        $category_name       = $this->request->getRequestParam('category_name', '');
2702
-        $category_desc       = $this->request->getRequestParam('category_desc', '');
2703
-        $category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2704
-        $category_identifier = $this->request->getRequestParam('category_identifier', '');
2705
-
2706
-        if (empty($category_name)) {
2707
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2708
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2709
-            return false;
2710
-        }
2711
-        $term_args = [
2712
-            'name'        => $category_name,
2713
-            'description' => $category_desc,
2714
-            'parent'      => $category_parent,
2715
-        ];
2716
-        // was the category_identifier input disabled?
2717
-        if ($category_identifier) {
2718
-            $term_args['slug'] = $category_identifier;
2719
-        }
2720
-        $insert_ids = $update
2721
-            ? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2722
-            : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2723
-        if (! is_array($insert_ids)) {
2724
-            $msg = esc_html__(
2725
-                'An error occurred and the category has not been saved to the database.',
2726
-                'event_espresso'
2727
-            );
2728
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2729
-        } else {
2730
-            $category_ID = $insert_ids['term_id'];
2731
-            $msg         =
2732
-                sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2733
-            EE_Error::add_success($msg);
2734
-        }
2735
-        return $category_ID;
2736
-    }
2737
-
2738
-
2739
-    /**
2740
-     * Gets categories or count of categories matching the arguments in the request.
2741
-     *
2742
-     * @param int  $per_page
2743
-     * @param int  $current_page
2744
-     * @param bool $count
2745
-     * @return EE_Term_Taxonomy[]|int
2746
-     * @throws EE_Error
2747
-     * @throws EE_Error
2748
-     */
2749
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2750
-    {
2751
-        // testing term stuff
2752
-        $orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2753
-        $order       = $this->request->getRequestParam('order', 'DESC');
2754
-        $limit       = ($current_page - 1) * $per_page;
2755
-        $where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2756
-        $search_term = $this->request->getRequestParam('s');
2757
-        if ($search_term) {
2758
-            $search_term = '%' . $search_term . '%';
2759
-            $where['OR'] = [
2760
-                'Term.name'   => ['LIKE', $search_term],
2761
-                'description' => ['LIKE', $search_term],
2762
-            ];
2763
-        }
2764
-        $query_params = [
2765
-            $where,
2766
-            'order_by'   => [$orderby => $order],
2767
-            'limit'      => $limit . ',' . $per_page,
2768
-            'force_join' => ['Term'],
2769
-        ];
2770
-        return $count
2771
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2772
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2773
-    }
2774
-
2775
-    /* end category stuff */
2776
-    /**************/
2777
-
2778
-
2779
-    /**
2780
-     * Callback for the `ee_save_timezone_setting` ajax action.
2781
-     *
2782
-     * @throws EE_Error
2783
-     */
2784
-    public function saveTimezoneString()
2785
-    {
2786
-        $timezone_string = $this->request->getRequestParam('timezone_selected');
2787
-        if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2788
-            EE_Error::add_error(
2789
-                esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2790
-                __FILE__,
2791
-                __FUNCTION__,
2792
-                __LINE__
2793
-            );
2794
-            $this->_template_args['error'] = true;
2795
-            $this->_return_json();
2796
-        }
2797
-
2798
-        update_option('timezone_string', $timezone_string);
2799
-        EE_Error::add_success(
2800
-            esc_html__('Your timezone string was updated.', 'event_espresso')
2801
-        );
2802
-        $this->_template_args['success'] = true;
2803
-        $this->_return_json(true, ['action' => 'create_new']);
2804
-    }
2805
-
2806
-
2807
-    /**
2808 2488
      * @throws EE_Error
2809
-     * @deprecated 4.10.25.p
2810 2489
      */
2811
-    public function save_timezonestring_setting()
2812
-    {
2813
-        $this->saveTimezoneString();
2814
-    }
2490
+	protected function _template_settings()
2491
+	{
2492
+		$this->_admin_page_title              = esc_html__('Template Settings (Preview)', 'event_espresso');
2493
+		$this->_template_args['preview_img']  = '<img src="'
2494
+												. EVENTS_ASSETS_URL
2495
+												. '/images/'
2496
+												. 'caffeinated_template_features.jpg" alt="'
2497
+												. esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2498
+												. '" />';
2499
+		$this->_template_args['preview_text'] = '<strong>'
2500
+												. esc_html__(
2501
+													'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2502
+													'event_espresso'
2503
+												) . '</strong>';
2504
+		$this->display_admin_caf_preview_page('template_settings_tab');
2505
+	}
2506
+
2507
+
2508
+	/** Event Category Stuff **/
2509
+	/**
2510
+	 * set the _category property with the category object for the loaded page.
2511
+	 *
2512
+	 * @access private
2513
+	 * @return void
2514
+	 */
2515
+	private function _set_category_object()
2516
+	{
2517
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2518
+			return;
2519
+		} //already have the category object so get out.
2520
+		// set default category object
2521
+		$this->_set_empty_category_object();
2522
+		// only set if we've got an id
2523
+		$category_ID = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int');
2524
+		if (! $category_ID) {
2525
+			return;
2526
+		}
2527
+		$term = get_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2528
+		if (! empty($term)) {
2529
+			$this->_category->category_name       = $term->name;
2530
+			$this->_category->category_identifier = $term->slug;
2531
+			$this->_category->category_desc       = $term->description;
2532
+			$this->_category->id                  = $term->term_id;
2533
+			$this->_category->parent              = $term->parent;
2534
+		}
2535
+	}
2536
+
2537
+
2538
+	/**
2539
+	 * Clears out category properties.
2540
+	 */
2541
+	private function _set_empty_category_object()
2542
+	{
2543
+		$this->_category                = new stdClass();
2544
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2545
+		$this->_category->id            = $this->_category->parent = 0;
2546
+	}
2547
+
2548
+
2549
+	/**
2550
+	 * @throws EE_Error
2551
+	 */
2552
+	protected function _category_list_table()
2553
+	{
2554
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2555
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2556
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2557
+			'add_category',
2558
+			'add_category',
2559
+			[],
2560
+			'add-new-h2'
2561
+		);
2562
+		$this->display_admin_list_table_page_with_sidebar();
2563
+	}
2564
+
2565
+
2566
+	/**
2567
+	 * Output category details view.
2568
+	 *
2569
+	 * @throws EE_Error
2570
+	 * @throws EE_Error
2571
+	 */
2572
+	protected function _category_details($view)
2573
+	{
2574
+		// load formatter helper
2575
+		// load field generator helper
2576
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2577
+		$this->_set_add_edit_form_tags($route);
2578
+		$this->_set_category_object();
2579
+		$id            = ! empty($this->_category->id) ? $this->_category->id : '';
2580
+		$delete_action = 'delete_category';
2581
+		// custom redirect
2582
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2583
+			['action' => 'category_list'],
2584
+			$this->_admin_base_url
2585
+		);
2586
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2587
+		// take care of contents
2588
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2589
+		$this->display_admin_page_with_sidebar();
2590
+	}
2591
+
2592
+
2593
+	/**
2594
+	 * Output category details content.
2595
+	 */
2596
+	protected function _category_details_content()
2597
+	{
2598
+		$editor_args['category_desc'] = [
2599
+			'type'          => 'wp_editor',
2600
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2601
+			'class'         => 'my_editor_custom',
2602
+			'wpeditor_args' => ['media_buttons' => false],
2603
+		];
2604
+		$_wp_editor                   = $this->_generate_admin_form_fields($editor_args, 'array');
2605
+		$all_terms                    = get_terms(
2606
+			[EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY],
2607
+			['hide_empty' => 0, 'exclude' => [$this->_category->id]]
2608
+		);
2609
+		// setup category select for term parents.
2610
+		$category_select_values[] = [
2611
+			'text' => esc_html__('No Parent', 'event_espresso'),
2612
+			'id'   => 0,
2613
+		];
2614
+		foreach ($all_terms as $term) {
2615
+			$category_select_values[] = [
2616
+				'text' => $term->name,
2617
+				'id'   => $term->term_id,
2618
+			];
2619
+		}
2620
+		$category_select = EEH_Form_Fields::select_input(
2621
+			'category_parent',
2622
+			$category_select_values,
2623
+			$this->_category->parent
2624
+		);
2625
+		$template_args   = [
2626
+			'category'                 => $this->_category,
2627
+			'category_select'          => $category_select,
2628
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2629
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2630
+			'disable'                  => '',
2631
+			'disabled_message'         => false,
2632
+		];
2633
+		$template        = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2634
+		return EEH_Template::display_template($template, $template_args, true);
2635
+	}
2636
+
2637
+
2638
+	/**
2639
+	 * Handles deleting categories.
2640
+	 *
2641
+	 * @throws EE_Error
2642
+	 */
2643
+	protected function _delete_categories()
2644
+	{
2645
+		$category_IDs = $this->request->getRequestParam('EVT_CAT_ID', 0, 'int', true);
2646
+		foreach ($category_IDs as $category_ID) {
2647
+			$this->_delete_category($category_ID);
2648
+		}
2649
+		// doesn't matter what page we're coming from... we're going to the same place after delete.
2650
+		$query_args = [
2651
+			'action' => 'category_list',
2652
+		];
2653
+		$this->_redirect_after_action(0, '', '', $query_args);
2654
+	}
2655
+
2656
+
2657
+	/**
2658
+	 * Handles deleting specific category.
2659
+	 *
2660
+	 * @param int $cat_id
2661
+	 */
2662
+	protected function _delete_category($cat_id)
2663
+	{
2664
+		$cat_id = absint($cat_id);
2665
+		wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY);
2666
+	}
2667
+
2668
+
2669
+	/**
2670
+	 * Handles triggering the update or insertion of a new category.
2671
+	 *
2672
+	 * @param bool $new_category true means we're triggering the insert of a new category.
2673
+	 * @throws EE_Error
2674
+	 * @throws EE_Error
2675
+	 */
2676
+	protected function _insert_or_update_category($new_category)
2677
+	{
2678
+		$cat_id  = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2679
+		$success = 0; // we already have a success message so lets not send another.
2680
+		if ($cat_id) {
2681
+			$query_args = [
2682
+				'action'     => 'edit_category',
2683
+				'EVT_CAT_ID' => $cat_id,
2684
+			];
2685
+		} else {
2686
+			$query_args = ['action' => 'add_category'];
2687
+		}
2688
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2689
+	}
2690
+
2691
+
2692
+	/**
2693
+	 * Inserts or updates category
2694
+	 *
2695
+	 * @param bool $update (true indicates we're updating a category).
2696
+	 * @return bool|mixed|string
2697
+	 */
2698
+	private function _insert_category($update = false)
2699
+	{
2700
+		$category_ID         = $update ? $this->request->getRequestParam('EVT_CAT_ID', 0, 'int') : 0;
2701
+		$category_name       = $this->request->getRequestParam('category_name', '');
2702
+		$category_desc       = $this->request->getRequestParam('category_desc', '');
2703
+		$category_parent     = $this->request->getRequestParam('category_parent', 0, 'int');
2704
+		$category_identifier = $this->request->getRequestParam('category_identifier', '');
2705
+
2706
+		if (empty($category_name)) {
2707
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2708
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2709
+			return false;
2710
+		}
2711
+		$term_args = [
2712
+			'name'        => $category_name,
2713
+			'description' => $category_desc,
2714
+			'parent'      => $category_parent,
2715
+		];
2716
+		// was the category_identifier input disabled?
2717
+		if ($category_identifier) {
2718
+			$term_args['slug'] = $category_identifier;
2719
+		}
2720
+		$insert_ids = $update
2721
+			? wp_update_term($category_ID, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args)
2722
+			: wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args);
2723
+		if (! is_array($insert_ids)) {
2724
+			$msg = esc_html__(
2725
+				'An error occurred and the category has not been saved to the database.',
2726
+				'event_espresso'
2727
+			);
2728
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2729
+		} else {
2730
+			$category_ID = $insert_ids['term_id'];
2731
+			$msg         =
2732
+				sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2733
+			EE_Error::add_success($msg);
2734
+		}
2735
+		return $category_ID;
2736
+	}
2737
+
2738
+
2739
+	/**
2740
+	 * Gets categories or count of categories matching the arguments in the request.
2741
+	 *
2742
+	 * @param int  $per_page
2743
+	 * @param int  $current_page
2744
+	 * @param bool $count
2745
+	 * @return EE_Term_Taxonomy[]|int
2746
+	 * @throws EE_Error
2747
+	 * @throws EE_Error
2748
+	 */
2749
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2750
+	{
2751
+		// testing term stuff
2752
+		$orderby     = $this->request->getRequestParam('orderby', 'Term.term_id');
2753
+		$order       = $this->request->getRequestParam('order', 'DESC');
2754
+		$limit       = ($current_page - 1) * $per_page;
2755
+		$where       = ['taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY];
2756
+		$search_term = $this->request->getRequestParam('s');
2757
+		if ($search_term) {
2758
+			$search_term = '%' . $search_term . '%';
2759
+			$where['OR'] = [
2760
+				'Term.name'   => ['LIKE', $search_term],
2761
+				'description' => ['LIKE', $search_term],
2762
+			];
2763
+		}
2764
+		$query_params = [
2765
+			$where,
2766
+			'order_by'   => [$orderby => $order],
2767
+			'limit'      => $limit . ',' . $per_page,
2768
+			'force_join' => ['Term'],
2769
+		];
2770
+		return $count
2771
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2772
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2773
+	}
2774
+
2775
+	/* end category stuff */
2776
+	/**************/
2777
+
2778
+
2779
+	/**
2780
+	 * Callback for the `ee_save_timezone_setting` ajax action.
2781
+	 *
2782
+	 * @throws EE_Error
2783
+	 */
2784
+	public function saveTimezoneString()
2785
+	{
2786
+		$timezone_string = $this->request->getRequestParam('timezone_selected');
2787
+		if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) {
2788
+			EE_Error::add_error(
2789
+				esc_html__('An invalid timezone string submitted.', 'event_espresso'),
2790
+				__FILE__,
2791
+				__FUNCTION__,
2792
+				__LINE__
2793
+			);
2794
+			$this->_template_args['error'] = true;
2795
+			$this->_return_json();
2796
+		}
2797
+
2798
+		update_option('timezone_string', $timezone_string);
2799
+		EE_Error::add_success(
2800
+			esc_html__('Your timezone string was updated.', 'event_espresso')
2801
+		);
2802
+		$this->_template_args['success'] = true;
2803
+		$this->_return_json(true, ['action' => 'create_new']);
2804
+	}
2805
+
2806
+
2807
+	/**
2808
+	 * @throws EE_Error
2809
+	 * @deprecated 4.10.25.p
2810
+	 */
2811
+	public function save_timezonestring_setting()
2812
+	{
2813
+		$this->saveTimezoneString();
2814
+	}
2815 2815
 }
Please login to merge, or discard this patch.
admin_pages/events/help_tabs/events_default_settings.help_tab.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
 <p>
6 6
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br />
7 7
     <?php esc_html_e(
8
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
9
-        'event_espresso'
10
-    ); ?>
8
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
9
+		'event_espresso'
10
+	); ?>
11 11
 </p>
12 12
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/events/help_tabs/events_categories.help_tab.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,21 +1,21 @@
 block discarded – undo
1 1
 <p><strong><?php esc_html_e('Event Categories', 'event_espresso'); ?></strong></p>
2 2
 <p>
3 3
     <?php esc_html_e(
4
-        'This page shows all event categories that have been created with Event Espresso.',
5
-        'event_espresso'
6
-    ); ?>
4
+		'This page shows all event categories that have been created with Event Espresso.',
5
+		'event_espresso'
6
+	); ?>
7 7
 </p>
8 8
 <p>
9 9
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong><br />
10 10
     <?php esc_html_e(
11
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
12
-        'event_espresso'
13
-    ); ?>
11
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
12
+		'event_espresso'
13
+	); ?>
14 14
 </p>
15 15
 <p>
16 16
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br />
17 17
     <?php esc_html_e(
18
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for event categories.',
19
-        'event_espresso'
20
-    ); ?>
18
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for event categories.',
19
+		'event_espresso'
20
+	); ?>
21 21
 </p>
22 22
\ No newline at end of file
Please login to merge, or discard this patch.
admin_pages/events/help_tabs/events_edit_category.help_tab.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,15 +14,15 @@
 block discarded – undo
14 14
     <li>
15 15
         <strong><?php esc_html_e('Category Description', 'event_espresso'); ?></strong><br />
16 16
         <?php esc_html_e(
17
-            'The rich text editor can be used to create a description for your event category.',
18
-            'event_espresso'
19
-        ); ?>
17
+			'The rich text editor can be used to create a description for your event category.',
18
+			'event_espresso'
19
+		); ?>
20 20
     </li>
21 21
 </ul>
22 22
 <p>
23 23
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br />
24 24
     <?php esc_html_e(
25
-        'You can customize the information that is shown on this page by toggling the screen options tab. Then you can add or remove checkmarks to hide or show certain content.',
26
-        'event_espresso'
27
-    ); ?>
25
+		'You can customize the information that is shown on this page by toggling the screen options tab. Then you can add or remove checkmarks to hide or show certain content.',
26
+		'event_espresso'
27
+	); ?>
28 28
 </p>
Please login to merge, or discard this patch.
admin_pages/events/help_tabs/general_settings_templates.help_tab.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -15,25 +15,25 @@  discard block
 block discarded – undo
15 15
     <li>
16 16
         <strong><?php esc_html_e('Display Status Banner', 'event_espresso'); ?></strong><br />
17 17
         <?php esc_html_e(
18
-            'Specify whether event status banners should be shown next to the title on the single event page. Notice: Some themes do not use the_title() tag correctly and this may cause things to appear broken (stray html). You can use this option to test your theme.',
19
-            'event_espresso'
20
-        ); ?>
18
+			'Specify whether event status banners should be shown next to the title on the single event page. Notice: Some themes do not use the_title() tag correctly and this may cause things to appear broken (stray html). You can use this option to test your theme.',
19
+			'event_espresso'
20
+		); ?>
21 21
     </li>
22 22
 </ul>
23 23
 <ul>
24 24
     <li>
25 25
         <strong><?php esc_html_e('Display Venue Details', 'event_espresso'); ?></strong><br />
26 26
         <?php esc_html_e(
27
-            'Whether Venue information, such as the address and Google Map should be shown on the Single Event pages.',
28
-            'event_espresso'
29
-        ); ?>
27
+			'Whether Venue information, such as the address and Google Map should be shown on the Single Event pages.',
28
+			'event_espresso'
29
+		); ?>
30 30
     </li>
31 31
     <li>
32 32
         <strong><?php esc_html_e('Display Order', 'event_espresso'); ?></strong><br />
33 33
         <?php esc_html_e(
34
-            'This setting controls the order of the event elements on the single event page. For example, if you want the venue details to appear above the ticket selector on the single event pages, just set the "Venue Display Order" setting to "1", and set the "Tickets Display Order" setting to "2". The lower the number, the further down the page the venue details will appear.',
35
-            'event_espresso'
36
-        ); ?>
34
+			'This setting controls the order of the event elements on the single event page. For example, if you want the venue details to appear above the ticket selector on the single event pages, just set the "Venue Display Order" setting to "1", and set the "Tickets Display Order" setting to "2". The lower the number, the further down the page the venue details will appear.',
35
+			'event_espresso'
36
+		); ?>
37 37
     </li>
38 38
 </ul>
39 39
 <p><strong>
@@ -47,27 +47,27 @@  discard block
 block discarded – undo
47 47
     <li>
48 48
         <strong><?php esc_html_e('Display Status Banner', 'event_espresso'); ?></strong><br />
49 49
         <?php esc_html_e(
50
-            'Specify whether event status banners should be shown next to the title on the event list page. Notice: Some themes do not use the_title() tag correctly and this may cause things to appear broken (stray html). You can use this option to test your theme.',
51
-            'event_espresso'
52
-        ); ?>
50
+			'Specify whether event status banners should be shown next to the title on the event list page. Notice: Some themes do not use the_title() tag correctly and this may cause things to appear broken (stray html). You can use this option to test your theme.',
51
+			'event_espresso'
52
+		); ?>
53 53
     </li>
54 54
     <li>
55 55
         <strong><?php esc_html_e('Display Descriptions', 'event_espresso'); ?></strong><br />
56 56
         <?php printf(
57
-            esc_html__(
58
-                'Whether descriptions should be shown on the event list page.%1$sSelecting "none" will NOT display any of the text content you entered into the main text editor on the event admin page.%1$sSelecting "excerpt" will display the text you entered into the "Excerpt" textarea on the event admin page, OR, any text in the main text editor above the %2$s tag.%1$sSelecting "full description" will display ALL of the text content you entered into the main text editor on the event admin page.',
59
-                'event_espresso'
60
-            ),
61
-            '<br/>',
62
-            htmlentities('<!--more-->')
63
-        ); ?>
57
+			esc_html__(
58
+				'Whether descriptions should be shown on the event list page.%1$sSelecting "none" will NOT display any of the text content you entered into the main text editor on the event admin page.%1$sSelecting "excerpt" will display the text you entered into the "Excerpt" textarea on the event admin page, OR, any text in the main text editor above the %2$s tag.%1$sSelecting "full description" will display ALL of the text content you entered into the main text editor on the event admin page.',
59
+				'event_espresso'
60
+			),
61
+			'<br/>',
62
+			htmlentities('<!--more-->')
63
+		); ?>
64 64
     </li>
65 65
     <li>
66 66
         <strong><?php esc_html_e('Display Ticket Selector', 'event_espresso'); ?></strong><br />
67 67
         <?php esc_html_e(
68
-            'Whether the ticket options table (Ticket Selector) should be shown on the event list page.',
69
-            'event_espresso'
70
-        ); ?>
68
+			'Whether the ticket options table (Ticket Selector) should be shown on the event list page.',
69
+			'event_espresso'
70
+		); ?>
71 71
     </li>
72 72
     <li>
73 73
         <strong><?php esc_html_e('Display Datetimes', 'event_espresso'); ?></strong><br />
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
 <p>
90 90
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong><br />
91 91
     <?php esc_html_e(
92
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
93
-        'event_espresso'
94
-    ); ?>
92
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
93
+		'event_espresso'
94
+	); ?>
95 95
 </p>
96 96
 <p>
97 97
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br />
98 98
     <?php esc_html_e(
99
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
100
-        'event_espresso'
101
-    ); ?>
99
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
100
+		'event_espresso'
101
+	); ?>
102 102
 </p>
103 103
\ No newline at end of file
Please login to merge, or discard this patch.