Completed
Branch BUG/add-instance-checks-reg-ad... (0bd096)
by
unknown
08:55 queued 47s
created
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Indentation   +3833 added lines, -3833 removed lines patch added patch discarded remove patch
@@ -19,2406 +19,2406 @@  discard block
 block discarded – undo
19 19
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
20 20
 {
21 21
 
22
-    /**
23
-     * @var EE_Registration
24
-     */
25
-    private $_registration;
26
-
27
-    /**
28
-     * @var EE_Event
29
-     */
30
-    private $_reg_event;
31
-
32
-    /**
33
-     * @var EE_Session
34
-     */
35
-    private $_session;
36
-
37
-    private static $_reg_status;
38
-
39
-    /**
40
-     * Form for displaying the custom questions for this registration.
41
-     * This gets used a few times throughout the request so its best to cache it
42
-     *
43
-     * @var EE_Registration_Custom_Questions_Form
44
-     */
45
-    protected $_reg_custom_questions_form = null;
46
-
47
-
48
-    /**
49
-     *        constructor
50
-     *
51
-     * @Constructor
52
-     * @access public
53
-     * @param bool $routing
54
-     * @return Registrations_Admin_Page
55
-     */
56
-    public function __construct($routing = true)
57
-    {
58
-        parent::__construct($routing);
59
-        add_action('wp_loaded', array($this, 'wp_loaded'));
60
-    }
61
-
62
-
63
-    public function wp_loaded()
64
-    {
65
-        // when adding a new registration...
66
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
67
-            EE_System::do_not_cache();
68
-            if (! isset($this->_req_data['processing_registration'])
69
-                || absint($this->_req_data['processing_registration']) !== 1
70
-            ) {
71
-                // and it's NOT the attendee information reg step
72
-                // force cookie expiration by setting time to last week
73
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
74
-                // and update the global
75
-                $_COOKIE['ee_registration_added'] = 0;
76
-            }
77
-        }
78
-    }
79
-
80
-
81
-    protected function _init_page_props()
82
-    {
83
-        $this->page_slug = REG_PG_SLUG;
84
-        $this->_admin_base_url = REG_ADMIN_URL;
85
-        $this->_admin_base_path = REG_ADMIN;
86
-        $this->page_label = esc_html__('Registrations', 'event_espresso');
87
-        $this->_cpt_routes = array(
88
-            'add_new_attendee' => 'espresso_attendees',
89
-            'edit_attendee'    => 'espresso_attendees',
90
-            'insert_attendee'  => 'espresso_attendees',
91
-            'update_attendee'  => 'espresso_attendees',
92
-        );
93
-        $this->_cpt_model_names = array(
94
-            'add_new_attendee' => 'EEM_Attendee',
95
-            'edit_attendee'    => 'EEM_Attendee',
96
-        );
97
-        $this->_cpt_edit_routes = array(
98
-            'espresso_attendees' => 'edit_attendee',
99
-        );
100
-        $this->_pagenow_map = array(
101
-            'add_new_attendee' => 'post-new.php',
102
-            'edit_attendee'    => 'post.php',
103
-            'trash'            => 'post.php',
104
-        );
105
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
106
-        // add filters so that the comment urls don't take users to a confusing 404 page
107
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
108
-    }
109
-
110
-
111
-    public function clear_comment_link($link, $comment, $args)
112
-    {
113
-        // gotta make sure this only happens on this route
114
-        $post_type = get_post_type($comment->comment_post_ID);
115
-        if ($post_type === 'espresso_attendees') {
116
-            return '#commentsdiv';
117
-        }
118
-        return $link;
119
-    }
120
-
121
-
122
-    protected function _ajax_hooks()
123
-    {
124
-        // todo: all hooks for registrations ajax goes in here
125
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
126
-    }
127
-
128
-
129
-    protected function _define_page_props()
130
-    {
131
-        $this->_admin_page_title = $this->page_label;
132
-        $this->_labels = array(
133
-            'buttons'                      => array(
134
-                'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
135
-                'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
136
-                'edit'                => esc_html__('Edit Contact', 'event_espresso'),
137
-                'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
138
-                'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
139
-                'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
140
-                'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
141
-                'contact_list_export' => esc_html__("Export Data", "event_espresso"),
142
-            ),
143
-            'publishbox'                   => array(
144
-                'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
145
-                'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
146
-            ),
147
-            'hide_add_button_on_cpt_route' => array(
148
-                'edit_attendee' => true,
149
-            ),
150
-        );
151
-    }
152
-
153
-
154
-    /**
155
-     *        grab url requests and route them
156
-     *
157
-     * @access private
158
-     * @return void
159
-     */
160
-    public function _set_page_routes()
161
-    {
162
-        $this->_get_registration_status_array();
163
-        $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
164
-            ? $this->_req_data['_REG_ID'] : 0;
165
-        $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
166
-            ? $this->_req_data['reg_status_change_form']['REG_ID']
167
-            : $reg_id;
168
-        $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
169
-            ? $this->_req_data['ATT_ID'] : 0;
170
-        $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
171
-            ? $this->_req_data['post']
172
-            : $att_id;
173
-        $this->_page_routes = array(
174
-            'default'                             => array(
175
-                'func'       => '_registrations_overview_list_table',
176
-                'capability' => 'ee_read_registrations',
177
-            ),
178
-            'view_registration'                   => array(
179
-                'func'       => '_registration_details',
180
-                'capability' => 'ee_read_registration',
181
-                'obj_id'     => $reg_id,
182
-            ),
183
-            'edit_registration'                   => array(
184
-                'func'               => '_update_attendee_registration_form',
185
-                'noheader'           => true,
186
-                'headers_sent_route' => 'view_registration',
187
-                'capability'         => 'ee_edit_registration',
188
-                'obj_id'             => $reg_id,
189
-                '_REG_ID'            => $reg_id,
190
-            ),
191
-            'trash_registrations'                 => array(
192
-                'func'       => '_trash_or_restore_registrations',
193
-                'args'       => array('trash' => true),
194
-                'noheader'   => true,
195
-                'capability' => 'ee_delete_registrations',
196
-            ),
197
-            'restore_registrations'               => array(
198
-                'func'       => '_trash_or_restore_registrations',
199
-                'args'       => array('trash' => false),
200
-                'noheader'   => true,
201
-                'capability' => 'ee_delete_registrations',
202
-            ),
203
-            'delete_registrations'                => array(
204
-                'func'       => '_delete_registrations',
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'new_registration'                    => array(
209
-                'func'       => 'new_registration',
210
-                'capability' => 'ee_edit_registrations',
211
-            ),
212
-            'process_reg_step'                    => array(
213
-                'func'       => 'process_reg_step',
214
-                'noheader'   => true,
215
-                'capability' => 'ee_edit_registrations',
216
-            ),
217
-            'redirect_to_txn'                     => array(
218
-                'func'       => 'redirect_to_txn',
219
-                'noheader'   => true,
220
-                'capability' => 'ee_edit_registrations',
221
-            ),
222
-            'change_reg_status'                   => array(
223
-                'func'       => '_change_reg_status',
224
-                'noheader'   => true,
225
-                'capability' => 'ee_edit_registration',
226
-                'obj_id'     => $reg_id,
227
-            ),
228
-            'approve_registration'                => array(
229
-                'func'       => 'approve_registration',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registration',
232
-                'obj_id'     => $reg_id,
233
-            ),
234
-            'approve_and_notify_registration'     => array(
235
-                'func'       => 'approve_registration',
236
-                'noheader'   => true,
237
-                'args'       => array(true),
238
-                'capability' => 'ee_edit_registration',
239
-                'obj_id'     => $reg_id,
240
-            ),
241
-            'approve_registrations'               => array(
242
-                'func'       => 'bulk_action_on_registrations',
243
-                'noheader'   => true,
244
-                'capability' => 'ee_edit_registrations',
245
-                'args'       => array('approve'),
246
-            ),
247
-            'approve_and_notify_registrations'    => array(
248
-                'func'       => 'bulk_action_on_registrations',
249
-                'noheader'   => true,
250
-                'capability' => 'ee_edit_registrations',
251
-                'args'       => array('approve', true),
252
-            ),
253
-            'decline_registration'                => array(
254
-                'func'       => 'decline_registration',
255
-                'noheader'   => true,
256
-                'capability' => 'ee_edit_registration',
257
-                'obj_id'     => $reg_id,
258
-            ),
259
-            'decline_and_notify_registration'     => array(
260
-                'func'       => 'decline_registration',
261
-                'noheader'   => true,
262
-                'args'       => array(true),
263
-                'capability' => 'ee_edit_registration',
264
-                'obj_id'     => $reg_id,
265
-            ),
266
-            'decline_registrations'               => array(
267
-                'func'       => 'bulk_action_on_registrations',
268
-                'noheader'   => true,
269
-                'capability' => 'ee_edit_registrations',
270
-                'args'       => array('decline'),
271
-            ),
272
-            'decline_and_notify_registrations'    => array(
273
-                'func'       => 'bulk_action_on_registrations',
274
-                'noheader'   => true,
275
-                'capability' => 'ee_edit_registrations',
276
-                'args'       => array('decline', true),
277
-            ),
278
-            'pending_registration'                => array(
279
-                'func'       => 'pending_registration',
280
-                'noheader'   => true,
281
-                'capability' => 'ee_edit_registration',
282
-                'obj_id'     => $reg_id,
283
-            ),
284
-            'pending_and_notify_registration'     => array(
285
-                'func'       => 'pending_registration',
286
-                'noheader'   => true,
287
-                'args'       => array(true),
288
-                'capability' => 'ee_edit_registration',
289
-                'obj_id'     => $reg_id,
290
-            ),
291
-            'pending_registrations'               => array(
292
-                'func'       => 'bulk_action_on_registrations',
293
-                'noheader'   => true,
294
-                'capability' => 'ee_edit_registrations',
295
-                'args'       => array('pending'),
296
-            ),
297
-            'pending_and_notify_registrations'    => array(
298
-                'func'       => 'bulk_action_on_registrations',
299
-                'noheader'   => true,
300
-                'capability' => 'ee_edit_registrations',
301
-                'args'       => array('pending', true),
302
-            ),
303
-            'no_approve_registration'             => array(
304
-                'func'       => 'not_approve_registration',
305
-                'noheader'   => true,
306
-                'capability' => 'ee_edit_registration',
307
-                'obj_id'     => $reg_id,
308
-            ),
309
-            'no_approve_and_notify_registration'  => array(
310
-                'func'       => 'not_approve_registration',
311
-                'noheader'   => true,
312
-                'args'       => array(true),
313
-                'capability' => 'ee_edit_registration',
314
-                'obj_id'     => $reg_id,
315
-            ),
316
-            'no_approve_registrations'            => array(
317
-                'func'       => 'bulk_action_on_registrations',
318
-                'noheader'   => true,
319
-                'capability' => 'ee_edit_registrations',
320
-                'args'       => array('not_approve'),
321
-            ),
322
-            'no_approve_and_notify_registrations' => array(
323
-                'func'       => 'bulk_action_on_registrations',
324
-                'noheader'   => true,
325
-                'capability' => 'ee_edit_registrations',
326
-                'args'       => array('not_approve', true),
327
-            ),
328
-            'cancel_registration'                 => array(
329
-                'func'       => 'cancel_registration',
330
-                'noheader'   => true,
331
-                'capability' => 'ee_edit_registration',
332
-                'obj_id'     => $reg_id,
333
-            ),
334
-            'cancel_and_notify_registration'      => array(
335
-                'func'       => 'cancel_registration',
336
-                'noheader'   => true,
337
-                'args'       => array(true),
338
-                'capability' => 'ee_edit_registration',
339
-                'obj_id'     => $reg_id,
340
-            ),
341
-            'cancel_registrations'                => array(
342
-                'func'       => 'bulk_action_on_registrations',
343
-                'noheader'   => true,
344
-                'capability' => 'ee_edit_registrations',
345
-                'args'       => array('cancel'),
346
-            ),
347
-            'cancel_and_notify_registrations'     => array(
348
-                'func'       => 'bulk_action_on_registrations',
349
-                'noheader'   => true,
350
-                'capability' => 'ee_edit_registrations',
351
-                'args'       => array('cancel', true),
352
-            ),
353
-            'wait_list_registration'              => array(
354
-                'func'       => 'wait_list_registration',
355
-                'noheader'   => true,
356
-                'capability' => 'ee_edit_registration',
357
-                'obj_id'     => $reg_id,
358
-            ),
359
-            'wait_list_and_notify_registration'   => array(
360
-                'func'       => 'wait_list_registration',
361
-                'noheader'   => true,
362
-                'args'       => array(true),
363
-                'capability' => 'ee_edit_registration',
364
-                'obj_id'     => $reg_id,
365
-            ),
366
-            'contact_list'                        => array(
367
-                'func'       => '_attendee_contact_list_table',
368
-                'capability' => 'ee_read_contacts',
369
-            ),
370
-            'add_new_attendee'                    => array(
371
-                'func' => '_create_new_cpt_item',
372
-                'args' => array(
373
-                    'new_attendee' => true,
374
-                    'capability'   => 'ee_edit_contacts',
375
-                ),
376
-            ),
377
-            'edit_attendee'                       => array(
378
-                'func'       => '_edit_cpt_item',
379
-                'capability' => 'ee_edit_contacts',
380
-                'obj_id'     => $att_id,
381
-            ),
382
-            'duplicate_attendee'                  => array(
383
-                'func'       => '_duplicate_attendee',
384
-                'noheader'   => true,
385
-                'capability' => 'ee_edit_contacts',
386
-                'obj_id'     => $att_id,
387
-            ),
388
-            'insert_attendee'                     => array(
389
-                'func'       => '_insert_or_update_attendee',
390
-                'args'       => array(
391
-                    'new_attendee' => true,
392
-                ),
393
-                'noheader'   => true,
394
-                'capability' => 'ee_edit_contacts',
395
-            ),
396
-            'update_attendee'                     => array(
397
-                'func'       => '_insert_or_update_attendee',
398
-                'args'       => array(
399
-                    'new_attendee' => false,
400
-                ),
401
-                'noheader'   => true,
402
-                'capability' => 'ee_edit_contacts',
403
-                'obj_id'     => $att_id,
404
-            ),
405
-            'trash_attendees'                     => array(
406
-                'func'       => '_trash_or_restore_attendees',
407
-                'args'       => array(
408
-                    'trash' => 'true',
409
-                ),
410
-                'noheader'   => true,
411
-                'capability' => 'ee_delete_contacts',
412
-            ),
413
-            'trash_attendee'                      => array(
414
-                'func'       => '_trash_or_restore_attendees',
415
-                'args'       => array(
416
-                    'trash' => true,
417
-                ),
418
-                'noheader'   => true,
419
-                'capability' => 'ee_delete_contacts',
420
-                'obj_id'     => $att_id,
421
-            ),
422
-            'restore_attendees'                   => array(
423
-                'func'       => '_trash_or_restore_attendees',
424
-                'args'       => array(
425
-                    'trash' => false,
426
-                ),
427
-                'noheader'   => true,
428
-                'capability' => 'ee_delete_contacts',
429
-                'obj_id'     => $att_id,
430
-            ),
431
-            'resend_registration'                 => array(
432
-                'func'       => '_resend_registration',
433
-                'noheader'   => true,
434
-                'capability' => 'ee_send_message',
435
-            ),
436
-            'registrations_report'                => array(
437
-                'func'       => '_registrations_report',
438
-                'noheader'   => true,
439
-                'capability' => 'ee_read_registrations',
440
-            ),
441
-            'contact_list_export'                 => array(
442
-                'func'       => '_contact_list_export',
443
-                'noheader'   => true,
444
-                'capability' => 'export',
445
-            ),
446
-            'contact_list_report'                 => array(
447
-                'func'       => '_contact_list_report',
448
-                'noheader'   => true,
449
-                'capability' => 'ee_read_contacts',
450
-            ),
451
-        );
452
-    }
453
-
454
-
455
-    protected function _set_page_config()
456
-    {
457
-        $this->_page_config = array(
458
-            'default'           => array(
459
-                'nav'           => array(
460
-                    'label' => esc_html__('Overview', 'event_espresso'),
461
-                    'order' => 5,
462
-                ),
463
-                'help_tabs'     => array(
464
-                    'registrations_overview_help_tab'                       => array(
465
-                        'title'    => esc_html__('Registrations Overview', 'event_espresso'),
466
-                        'filename' => 'registrations_overview',
467
-                    ),
468
-                    'registrations_overview_table_column_headings_help_tab' => array(
469
-                        'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
470
-                        'filename' => 'registrations_overview_table_column_headings',
471
-                    ),
472
-                    'registrations_overview_filters_help_tab'               => array(
473
-                        'title'    => esc_html__('Registration Filters', 'event_espresso'),
474
-                        'filename' => 'registrations_overview_filters',
475
-                    ),
476
-                    'registrations_overview_views_help_tab'                 => array(
477
-                        'title'    => esc_html__('Registration Views', 'event_espresso'),
478
-                        'filename' => 'registrations_overview_views',
479
-                    ),
480
-                    'registrations_regoverview_other_help_tab'              => array(
481
-                        'title'    => esc_html__('Registrations Other', 'event_espresso'),
482
-                        'filename' => 'registrations_overview_other',
483
-                    ),
484
-                ),
485
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
486
-                'qtips'         => array('Registration_List_Table_Tips'),
487
-                'list_table'    => 'EE_Registrations_List_Table',
488
-                'require_nonce' => false,
489
-            ),
490
-            'view_registration' => array(
491
-                'nav'           => array(
492
-                    'label'      => esc_html__('REG Details', 'event_espresso'),
493
-                    'order'      => 15,
494
-                    'url'        => isset($this->_req_data['_REG_ID'])
495
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
496
-                        : $this->_admin_base_url,
497
-                    'persistent' => false,
498
-                ),
499
-                'help_tabs'     => array(
500
-                    'registrations_details_help_tab'                    => array(
501
-                        'title'    => esc_html__('Registration Details', 'event_espresso'),
502
-                        'filename' => 'registrations_details',
503
-                    ),
504
-                    'registrations_details_table_help_tab'              => array(
505
-                        'title'    => esc_html__('Registration Details Table', 'event_espresso'),
506
-                        'filename' => 'registrations_details_table',
507
-                    ),
508
-                    'registrations_details_form_answers_help_tab'       => array(
509
-                        'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
510
-                        'filename' => 'registrations_details_form_answers',
511
-                    ),
512
-                    'registrations_details_registrant_details_help_tab' => array(
513
-                        'title'    => esc_html__('Contact Details', 'event_espresso'),
514
-                        'filename' => 'registrations_details_registrant_details',
515
-                    ),
516
-                ),
517
-                'help_tour'     => array('Registration_Details_Help_Tour'),
518
-                'metaboxes'     => array_merge(
519
-                    $this->_default_espresso_metaboxes,
520
-                    array('_registration_details_metaboxes')
521
-                ),
522
-                'require_nonce' => false,
523
-            ),
524
-            'new_registration'  => array(
525
-                'nav'           => array(
526
-                    'label'      => esc_html__('Add New Registration', 'event_espresso'),
527
-                    'url'        => '#',
528
-                    'order'      => 15,
529
-                    'persistent' => false,
530
-                ),
531
-                'metaboxes'     => $this->_default_espresso_metaboxes,
532
-                'labels'        => array(
533
-                    'publishbox' => esc_html__('Save Registration', 'event_espresso'),
534
-                ),
535
-                'require_nonce' => false,
536
-            ),
537
-            'add_new_attendee'  => array(
538
-                'nav'           => array(
539
-                    'label'      => esc_html__('Add Contact', 'event_espresso'),
540
-                    'order'      => 15,
541
-                    'persistent' => false,
542
-                ),
543
-                'metaboxes'     => array_merge(
544
-                    $this->_default_espresso_metaboxes,
545
-                    array('_publish_post_box', 'attendee_editor_metaboxes')
546
-                ),
547
-                'require_nonce' => false,
548
-            ),
549
-            'edit_attendee'     => array(
550
-                'nav'           => array(
551
-                    'label'      => esc_html__('Edit Contact', 'event_espresso'),
552
-                    'order'      => 15,
553
-                    'persistent' => false,
554
-                    'url'        => isset($this->_req_data['ATT_ID'])
555
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
556
-                        : $this->_admin_base_url,
557
-                ),
558
-                'metaboxes'     => array('attendee_editor_metaboxes'),
559
-                'require_nonce' => false,
560
-            ),
561
-            'contact_list'      => array(
562
-                'nav'           => array(
563
-                    'label' => esc_html__('Contact List', 'event_espresso'),
564
-                    'order' => 20,
565
-                ),
566
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
567
-                'help_tabs'     => array(
568
-                    'registrations_contact_list_help_tab'                       => array(
569
-                        'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
570
-                        'filename' => 'registrations_contact_list',
571
-                    ),
572
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
573
-                        'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
574
-                        'filename' => 'registrations_contact_list_table_column_headings',
575
-                    ),
576
-                    'registrations_contact_list_views_help_tab'                 => array(
577
-                        'title'    => esc_html__('Contact List Views', 'event_espresso'),
578
-                        'filename' => 'registrations_contact_list_views',
579
-                    ),
580
-                    'registrations_contact_list_other_help_tab'                 => array(
581
-                        'title'    => esc_html__('Contact List Other', 'event_espresso'),
582
-                        'filename' => 'registrations_contact_list_other',
583
-                    ),
584
-                ),
585
-                'help_tour'     => array('Contact_List_Help_Tour'),
586
-                'metaboxes'     => array(),
587
-                'require_nonce' => false,
588
-            ),
589
-            // override default cpt routes
590
-            'create_new'        => '',
591
-            'edit'              => '',
592
-        );
593
-    }
594
-
595
-
596
-    /**
597
-     * The below methods aren't used by this class currently
598
-     */
599
-    protected function _add_screen_options()
600
-    {
601
-    }
602
-
603
-
604
-    protected function _add_feature_pointers()
605
-    {
606
-    }
607
-
608
-
609
-    public function admin_init()
610
-    {
611
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
612
-            'click "Update Registration Questions" to save your changes',
613
-            'event_espresso'
614
-        );
615
-    }
616
-
617
-
618
-    public function admin_notices()
619
-    {
620
-    }
621
-
622
-
623
-    public function admin_footer_scripts()
624
-    {
625
-    }
626
-
627
-
628
-    /**
629
-     *        get list of registration statuses
630
-     *
631
-     * @access private
632
-     * @return void
633
-     * @throws EE_Error
634
-     */
635
-    private function _get_registration_status_array()
636
-    {
637
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
638
-    }
639
-
640
-
641
-    protected function _add_screen_options_default()
642
-    {
643
-        $this->_per_page_screen_option();
644
-    }
645
-
646
-
647
-    protected function _add_screen_options_contact_list()
648
-    {
649
-        $page_title = $this->_admin_page_title;
650
-        $this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
651
-        $this->_per_page_screen_option();
652
-        $this->_admin_page_title = $page_title;
653
-    }
654
-
655
-
656
-    public function load_scripts_styles()
657
-    {
658
-        // style
659
-        wp_register_style(
660
-            'espresso_reg',
661
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
662
-            array('ee-admin-css'),
663
-            EVENT_ESPRESSO_VERSION
664
-        );
665
-        wp_enqueue_style('espresso_reg');
666
-        // script
667
-        wp_register_script(
668
-            'espresso_reg',
669
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
670
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
671
-            EVENT_ESPRESSO_VERSION,
672
-            true
673
-        );
674
-        wp_enqueue_script('espresso_reg');
675
-    }
676
-
677
-
678
-    public function load_scripts_styles_edit_attendee()
679
-    {
680
-        // stuff to only show up on our attendee edit details page.
681
-        $attendee_details_translations = array(
682
-            'att_publish_text' => sprintf(
683
-                esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
684
-                $this->_cpt_model_obj->get_datetime('ATT_created')
685
-            ),
686
-        );
687
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
688
-        wp_enqueue_script('jquery-validate');
689
-    }
690
-
691
-
692
-    public function load_scripts_styles_view_registration()
693
-    {
694
-        // styles
695
-        wp_enqueue_style('espresso-ui-theme');
696
-        // scripts
697
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
698
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
699
-    }
700
-
701
-
702
-    public function load_scripts_styles_contact_list()
703
-    {
704
-        wp_dequeue_style('espresso_reg');
705
-        wp_register_style(
706
-            'espresso_att',
707
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
708
-            array('ee-admin-css'),
709
-            EVENT_ESPRESSO_VERSION
710
-        );
711
-        wp_enqueue_style('espresso_att');
712
-    }
713
-
714
-
715
-    public function load_scripts_styles_new_registration()
716
-    {
717
-        wp_register_script(
718
-            'ee-spco-for-admin',
719
-            REG_ASSETS_URL . 'spco_for_admin.js',
720
-            array('underscore', 'jquery'),
721
-            EVENT_ESPRESSO_VERSION,
722
-            true
723
-        );
724
-        wp_enqueue_script('ee-spco-for-admin');
725
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
726
-        EE_Form_Section_Proper::wp_enqueue_scripts();
727
-        EED_Ticket_Selector::load_tckt_slctr_assets();
728
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
729
-    }
730
-
731
-
732
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
733
-    {
734
-        add_filter('FHEE_load_EE_messages', '__return_true');
735
-    }
736
-
737
-
738
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
739
-    {
740
-        add_filter('FHEE_load_EE_messages', '__return_true');
741
-    }
742
-
743
-
744
-    protected function _set_list_table_views_default()
745
-    {
746
-        // for notification related bulk actions we need to make sure only active messengers have an option.
747
-        EED_Messages::set_autoloaders();
748
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
749
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
750
-        $active_mts = $message_resource_manager->list_of_active_message_types();
751
-        // key= bulk_action_slug, value= message type.
752
-        $match_array = array(
753
-            'approve_registrations'    => 'registration',
754
-            'decline_registrations'    => 'declined_registration',
755
-            'pending_registrations'    => 'pending_approval',
756
-            'no_approve_registrations' => 'not_approved_registration',
757
-            'cancel_registrations'     => 'cancelled_registration',
758
-        );
759
-        $can_send = EE_Registry::instance()->CAP->current_user_can(
760
-            'ee_send_message',
761
-            'batch_send_messages'
762
-        );
763
-        /** setup reg status bulk actions **/
764
-        $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
765
-        if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
766
-            $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
767
-                'Approve and Notify Registrations',
768
-                'event_espresso'
769
-            );
770
-        }
771
-        $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
772
-        if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
773
-            $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
774
-                'Decline and Notify Registrations',
775
-                'event_espresso'
776
-            );
777
-        }
778
-        $def_reg_status_actions['pending_registrations'] = esc_html__(
779
-            'Set Registrations to Pending Payment',
780
-            'event_espresso'
781
-        );
782
-        if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
783
-            $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
784
-                'Set Registrations to Pending Payment and Notify',
785
-                'event_espresso'
786
-            );
787
-        }
788
-        $def_reg_status_actions['no_approve_registrations'] = esc_html__(
789
-            'Set Registrations to Not Approved',
790
-            'event_espresso'
791
-        );
792
-        if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
793
-            $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
794
-                'Set Registrations to Not Approved and Notify',
795
-                'event_espresso'
796
-            );
797
-        }
798
-        $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
799
-        if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
800
-            $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
801
-                'Cancel Registrations and Notify',
802
-                'event_espresso'
803
-            );
804
-        }
805
-        $def_reg_status_actions = apply_filters(
806
-            'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
807
-            $def_reg_status_actions,
808
-            $active_mts,
809
-            $can_send
810
-        );
811
-
812
-        $this->_views = array(
813
-            'all'   => array(
814
-                'slug'        => 'all',
815
-                'label'       => esc_html__('View All Registrations', 'event_espresso'),
816
-                'count'       => 0,
817
-                'bulk_action' => array_merge(
818
-                    $def_reg_status_actions,
819
-                    array(
820
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
821
-                    )
822
-                ),
823
-            ),
824
-            'month' => array(
825
-                'slug'        => 'month',
826
-                'label'       => esc_html__('This Month', 'event_espresso'),
827
-                'count'       => 0,
828
-                'bulk_action' => array_merge(
829
-                    $def_reg_status_actions,
830
-                    array(
831
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
832
-                    )
833
-                ),
834
-            ),
835
-            'today' => array(
836
-                'slug'        => 'today',
837
-                'label'       => sprintf(
838
-                    esc_html__('Today - %s', 'event_espresso'),
839
-                    date('M d, Y', current_time('timestamp'))
840
-                ),
841
-                'count'       => 0,
842
-                'bulk_action' => array_merge(
843
-                    $def_reg_status_actions,
844
-                    array(
845
-                        'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
846
-                    )
847
-                ),
848
-            ),
849
-        );
850
-        if (EE_Registry::instance()->CAP->current_user_can(
851
-            'ee_delete_registrations',
852
-            'espresso_registrations_delete_registration'
853
-        )) {
854
-            $this->_views['incomplete'] = array(
855
-                'slug'        => 'incomplete',
856
-                'label'       => esc_html__('Incomplete', 'event_espresso'),
857
-                'count'       => 0,
858
-                'bulk_action' => array(
859
-                    'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
860
-                ),
861
-            );
862
-            $this->_views['trash'] = array(
863
-                'slug'        => 'trash',
864
-                'label'       => esc_html__('Trash', 'event_espresso'),
865
-                'count'       => 0,
866
-                'bulk_action' => array(
867
-                    'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
868
-                    'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
869
-                ),
870
-            );
871
-        }
872
-    }
873
-
874
-
875
-    protected function _set_list_table_views_contact_list()
876
-    {
877
-        $this->_views = array(
878
-            'in_use' => array(
879
-                'slug'        => 'in_use',
880
-                'label'       => esc_html__('In Use', 'event_espresso'),
881
-                'count'       => 0,
882
-                'bulk_action' => array(
883
-                    'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
884
-                ),
885
-            ),
886
-        );
887
-        if (EE_Registry::instance()->CAP->current_user_can(
888
-            'ee_delete_contacts',
889
-            'espresso_registrations_trash_attendees'
890
-        )
891
-        ) {
892
-            $this->_views['trash'] = array(
893
-                'slug'        => 'trash',
894
-                'label'       => esc_html__('Trash', 'event_espresso'),
895
-                'count'       => 0,
896
-                'bulk_action' => array(
897
-                    'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
898
-                ),
899
-            );
900
-        }
901
-    }
902
-
903
-
904
-    protected function _registration_legend_items()
905
-    {
906
-        $fc_items = array(
907
-            'star-icon'        => array(
908
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
909
-                'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
910
-            ),
911
-            'view_details'     => array(
912
-                'class' => 'dashicons dashicons-clipboard',
913
-                'desc'  => esc_html__('View Registration Details', 'event_espresso'),
914
-            ),
915
-            'edit_attendee'    => array(
916
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
917
-                'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
918
-            ),
919
-            'view_transaction' => array(
920
-                'class' => 'dashicons dashicons-cart',
921
-                'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
922
-            ),
923
-            'view_invoice'     => array(
924
-                'class' => 'dashicons dashicons-media-spreadsheet',
925
-                'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
926
-            ),
927
-        );
928
-        if (EE_Registry::instance()->CAP->current_user_can(
929
-            'ee_send_message',
930
-            'espresso_registrations_resend_registration'
931
-        )) {
932
-            $fc_items['resend_registration'] = array(
933
-                'class' => 'dashicons dashicons-email-alt',
934
-                'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
935
-            );
936
-        } else {
937
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
938
-        }
939
-        if (EE_Registry::instance()->CAP->current_user_can(
940
-            'ee_read_global_messages',
941
-            'view_filtered_messages'
942
-        )) {
943
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
944
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
945
-                $fc_items['view_related_messages'] = array(
946
-                    'class' => $related_for_icon['css_class'],
947
-                    'desc'  => $related_for_icon['label'],
948
-                );
949
-            }
950
-        }
951
-        $sc_items = array(
952
-            'approved_status'   => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
954
-                'desc'  => EEH_Template::pretty_status(
955
-                    EEM_Registration::status_id_approved,
956
-                    false,
957
-                    'sentence'
958
-                ),
959
-            ),
960
-            'pending_status'    => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
962
-                'desc'  => EEH_Template::pretty_status(
963
-                    EEM_Registration::status_id_pending_payment,
964
-                    false,
965
-                    'sentence'
966
-                ),
967
-            ),
968
-            'wait_list'         => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
970
-                'desc'  => EEH_Template::pretty_status(
971
-                    EEM_Registration::status_id_wait_list,
972
-                    false,
973
-                    'sentence'
974
-                ),
975
-            ),
976
-            'incomplete_status' => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
978
-                'desc'  => EEH_Template::pretty_status(
979
-                    EEM_Registration::status_id_incomplete,
980
-                    false,
981
-                    'sentence'
982
-                ),
983
-            ),
984
-            'not_approved'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
986
-                'desc'  => EEH_Template::pretty_status(
987
-                    EEM_Registration::status_id_not_approved,
988
-                    false,
989
-                    'sentence'
990
-                ),
991
-            ),
992
-            'declined_status'   => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
994
-                'desc'  => EEH_Template::pretty_status(
995
-                    EEM_Registration::status_id_declined,
996
-                    false,
997
-                    'sentence'
998
-                ),
999
-            ),
1000
-            'cancelled_status'  => array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1002
-                'desc'  => EEH_Template::pretty_status(
1003
-                    EEM_Registration::status_id_cancelled,
1004
-                    false,
1005
-                    'sentence'
1006
-                ),
1007
-            ),
1008
-        );
1009
-        return array_merge($fc_items, $sc_items);
1010
-    }
1011
-
1012
-
1013
-
1014
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
1015
-    /**
1016
-     * @throws \EE_Error
1017
-     */
1018
-    protected function _registrations_overview_list_table()
1019
-    {
1020
-        $this->_template_args['admin_page_header'] = '';
1021
-        $EVT_ID = ! empty($this->_req_data['event_id'])
1022
-            ? absint($this->_req_data['event_id'])
1023
-            : 0;
1024
-        $ATT_ID = ! empty($this->_req_data['ATT_ID'])
1025
-            ? absint($this->_req_data['ATT_ID'])
1026
-            : 0;
1027
-        if ($ATT_ID) {
1028
-            $attendee = EEM_Attendee::instance()->get_one_by_ID($ATT_ID);
1029
-            if ($attendee instanceof EE_Attendee) {
1030
-                $this->_template_args['admin_page_header'] = sprintf(
1031
-                    esc_html__(
1032
-                        '%1$s Viewing registrations for %2$s%3$s',
1033
-                        'event_espresso'
1034
-                    ),
1035
-                    '<h3 style="line-height:1.5em;">',
1036
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
1037
-                        array(
1038
-                            'action' => 'edit_attendee',
1039
-                            'post'   => $ATT_ID,
1040
-                        ),
1041
-                        REG_ADMIN_URL
1042
-                    ) . '">' . $attendee->full_name() . '</a>',
1043
-                    '</h3>'
1044
-                );
1045
-            }
1046
-        }
1047
-        if ($EVT_ID) {
1048
-            if (EE_Registry::instance()->CAP->current_user_can(
1049
-                'ee_edit_registrations',
1050
-                'espresso_registrations_new_registration',
1051
-                $EVT_ID
1052
-            )) {
1053
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1054
-                    'new_registration',
1055
-                    'add-registrant',
1056
-                    array('event_id' => $EVT_ID),
1057
-                    'add-new-h2'
1058
-                );
1059
-            }
1060
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1061
-            if ($event instanceof EE_Event) {
1062
-                $this->_template_args['admin_page_header'] = sprintf(
1063
-                    esc_html__(
1064
-                        '%s Viewing registrations for the event: %s%s',
1065
-                        'event_espresso'
1066
-                    ),
1067
-                    '<h3 style="line-height:1.5em;">',
1068
-                    '<br /><a href="'
1069
-                    . EE_Admin_Page::add_query_args_and_nonce(
1070
-                        array(
1071
-                            'action' => 'edit',
1072
-                            'post'   => $event->ID(),
1073
-                        ),
1074
-                        EVENTS_ADMIN_URL
1075
-                    )
1076
-                    . '">&nbsp;'
1077
-                    . $event->get('EVT_name')
1078
-                    . '&nbsp;</a>&nbsp;',
1079
-                    '</h3>'
1080
-                );
1081
-            }
1082
-            $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1083
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1084
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1085
-                $this->_template_args['admin_page_header'] = substr(
1086
-                    $this->_template_args['admin_page_header'],
1087
-                    0,
1088
-                    -5
1089
-                );
1090
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1091
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1092
-                $this->_template_args['admin_page_header'] .= $datetime->name();
1093
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1094
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
1095
-            }
1096
-        }
1097
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1098
-        $this->display_admin_list_table_page_with_no_sidebar();
1099
-    }
1100
-
1101
-
1102
-    /**
1103
-     * This sets the _registration property for the registration details screen
1104
-     *
1105
-     * @access private
1106
-     * @return bool
1107
-     * @throws EE_Error
1108
-     * @throws InvalidArgumentException
1109
-     * @throws InvalidDataTypeException
1110
-     * @throws InvalidInterfaceException
1111
-     */
1112
-    private function _set_registration_object()
1113
-    {
1114
-        // get out if we've already set the object
1115
-        if ($this->_registration instanceof EE_Registration) {
1116
-            return true;
1117
-        }
1118
-        $REG = EEM_Registration::instance();
1119
-        $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1120
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1121
-            return true;
1122
-        } else {
1123
-            $error_msg = sprintf(
1124
-                esc_html__(
1125
-                    'An error occurred and the details for Registration ID #%s could not be retrieved.',
1126
-                    'event_espresso'
1127
-                ),
1128
-                $REG_ID
1129
-            );
1130
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1131
-            $this->_registration = null;
1132
-            return false;
1133
-        }
1134
-    }
1135
-
1136
-
1137
-    /**
1138
-     * Used to retrieve registrations for the list table.
1139
-     *
1140
-     * @param int  $per_page
1141
-     * @param bool $count
1142
-     * @param bool $this_month
1143
-     * @param bool $today
1144
-     * @return EE_Registration[]|int
1145
-     * @throws EE_Error
1146
-     * @throws InvalidArgumentException
1147
-     * @throws InvalidDataTypeException
1148
-     * @throws InvalidInterfaceException
1149
-     */
1150
-    public function get_registrations(
1151
-        $per_page = 10,
1152
-        $count = false,
1153
-        $this_month = false,
1154
-        $today = false
1155
-    ) {
1156
-        if ($this_month) {
1157
-            $this->_req_data['status'] = 'month';
1158
-        }
1159
-        if ($today) {
1160
-            $this->_req_data['status'] = 'today';
1161
-        }
1162
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1163
-        /**
1164
-         * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1165
-         *
1166
-         * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1167
-         * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1168
-         *                             or if you have the development copy of EE you can view this at the path:
1169
-         *                             /docs/G--Model-System/model-query-params.md
1170
-         */
1171
-        $query_params['group_by'] = '';
1172
-
1173
-        return $count
1174
-            ? EEM_Registration::instance()->count($query_params)
1175
-            /** @type EE_Registration[] */
1176
-            : EEM_Registration::instance()->get_all($query_params);
1177
-    }
1178
-
1179
-
1180
-    /**
1181
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
1182
-     * Note: this listens to values on the request for some of the query parameters.
1183
-     *
1184
-     * @param array $request
1185
-     * @param int   $per_page
1186
-     * @param bool  $count
1187
-     * @return array
1188
-     * @throws EE_Error
1189
-     */
1190
-    protected function _get_registration_query_parameters(
1191
-        $request = array(),
1192
-        $per_page = 10,
1193
-        $count = false
1194
-    ) {
1195
-
1196
-        $query_params = array(
1197
-            0                          => $this->_get_where_conditions_for_registrations_query(
1198
-                $request
1199
-            ),
1200
-            'caps'                     => EEM_Registration::caps_read_admin,
1201
-            'default_where_conditions' => 'this_model_only',
1202
-        );
1203
-        if (! $count) {
1204
-            $query_params = array_merge(
1205
-                $query_params,
1206
-                $this->_get_orderby_for_registrations_query(),
1207
-                $this->_get_limit($per_page)
1208
-            );
1209
-        }
1210
-
1211
-        return $query_params;
1212
-    }
1213
-
1214
-
1215
-    /**
1216
-     * This will add ATT_ID to the provided $where array for EE model query parameters.
1217
-     *
1218
-     * @param array $request usually the same as $this->_req_data but not necessarily
1219
-     * @return array
1220
-     */
1221
-    protected function addAttendeeIdToWhereConditions(array $request)
1222
-    {
1223
-        $where = array();
1224
-        if (! empty($request['ATT_ID'])) {
1225
-            $where['ATT_ID'] = absint($request['ATT_ID']);
1226
-        }
1227
-        return $where;
1228
-    }
1229
-
1230
-
1231
-    /**
1232
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
1233
-     *
1234
-     * @param array $request usually the same as $this->_req_data but not necessarily
1235
-     * @return array
1236
-     */
1237
-    protected function _add_event_id_to_where_conditions(array $request)
1238
-    {
1239
-        $where = array();
1240
-        if (! empty($request['event_id'])) {
1241
-            $where['EVT_ID'] = absint($request['event_id']);
1242
-        }
1243
-        return $where;
1244
-    }
1245
-
1246
-
1247
-    /**
1248
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
1249
-     *
1250
-     * @param array $request usually the same as $this->_req_data but not necessarily
1251
-     * @return array
1252
-     */
1253
-    protected function _add_category_id_to_where_conditions(array $request)
1254
-    {
1255
-        $where = array();
1256
-        if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1257
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1258
-        }
1259
-        return $where;
1260
-    }
1261
-
1262
-
1263
-    /**
1264
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1265
-     *
1266
-     * @param array $request usually the same as $this->_req_data but not necessarily
1267
-     * @return array
1268
-     */
1269
-    protected function _add_datetime_id_to_where_conditions(array $request)
1270
-    {
1271
-        $where = array();
1272
-        if (! empty($request['datetime_id'])) {
1273
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1274
-        }
1275
-        if (! empty($request['DTT_ID'])) {
1276
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1277
-        }
1278
-        return $where;
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     * Adds the correct registration status to the where conditions for the registrations query.
1284
-     *
1285
-     * @param array $request usually the same as $this->_req_data but not necessarily
1286
-     * @return array
1287
-     */
1288
-    protected function _add_registration_status_to_where_conditions(array $request)
1289
-    {
1290
-        $where = array();
1291
-        $view = EEH_Array::is_set($request, 'status', '');
1292
-        $registration_status = ! empty($request['_reg_status'])
1293
-            ? sanitize_text_field($request['_reg_status'])
1294
-            : '';
1295
-
1296
-        /*
22
+	/**
23
+	 * @var EE_Registration
24
+	 */
25
+	private $_registration;
26
+
27
+	/**
28
+	 * @var EE_Event
29
+	 */
30
+	private $_reg_event;
31
+
32
+	/**
33
+	 * @var EE_Session
34
+	 */
35
+	private $_session;
36
+
37
+	private static $_reg_status;
38
+
39
+	/**
40
+	 * Form for displaying the custom questions for this registration.
41
+	 * This gets used a few times throughout the request so its best to cache it
42
+	 *
43
+	 * @var EE_Registration_Custom_Questions_Form
44
+	 */
45
+	protected $_reg_custom_questions_form = null;
46
+
47
+
48
+	/**
49
+	 *        constructor
50
+	 *
51
+	 * @Constructor
52
+	 * @access public
53
+	 * @param bool $routing
54
+	 * @return Registrations_Admin_Page
55
+	 */
56
+	public function __construct($routing = true)
57
+	{
58
+		parent::__construct($routing);
59
+		add_action('wp_loaded', array($this, 'wp_loaded'));
60
+	}
61
+
62
+
63
+	public function wp_loaded()
64
+	{
65
+		// when adding a new registration...
66
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
67
+			EE_System::do_not_cache();
68
+			if (! isset($this->_req_data['processing_registration'])
69
+				|| absint($this->_req_data['processing_registration']) !== 1
70
+			) {
71
+				// and it's NOT the attendee information reg step
72
+				// force cookie expiration by setting time to last week
73
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
74
+				// and update the global
75
+				$_COOKIE['ee_registration_added'] = 0;
76
+			}
77
+		}
78
+	}
79
+
80
+
81
+	protected function _init_page_props()
82
+	{
83
+		$this->page_slug = REG_PG_SLUG;
84
+		$this->_admin_base_url = REG_ADMIN_URL;
85
+		$this->_admin_base_path = REG_ADMIN;
86
+		$this->page_label = esc_html__('Registrations', 'event_espresso');
87
+		$this->_cpt_routes = array(
88
+			'add_new_attendee' => 'espresso_attendees',
89
+			'edit_attendee'    => 'espresso_attendees',
90
+			'insert_attendee'  => 'espresso_attendees',
91
+			'update_attendee'  => 'espresso_attendees',
92
+		);
93
+		$this->_cpt_model_names = array(
94
+			'add_new_attendee' => 'EEM_Attendee',
95
+			'edit_attendee'    => 'EEM_Attendee',
96
+		);
97
+		$this->_cpt_edit_routes = array(
98
+			'espresso_attendees' => 'edit_attendee',
99
+		);
100
+		$this->_pagenow_map = array(
101
+			'add_new_attendee' => 'post-new.php',
102
+			'edit_attendee'    => 'post.php',
103
+			'trash'            => 'post.php',
104
+		);
105
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
106
+		// add filters so that the comment urls don't take users to a confusing 404 page
107
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
108
+	}
109
+
110
+
111
+	public function clear_comment_link($link, $comment, $args)
112
+	{
113
+		// gotta make sure this only happens on this route
114
+		$post_type = get_post_type($comment->comment_post_ID);
115
+		if ($post_type === 'espresso_attendees') {
116
+			return '#commentsdiv';
117
+		}
118
+		return $link;
119
+	}
120
+
121
+
122
+	protected function _ajax_hooks()
123
+	{
124
+		// todo: all hooks for registrations ajax goes in here
125
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
126
+	}
127
+
128
+
129
+	protected function _define_page_props()
130
+	{
131
+		$this->_admin_page_title = $this->page_label;
132
+		$this->_labels = array(
133
+			'buttons'                      => array(
134
+				'add-registrant'      => esc_html__('Add New Registration', 'event_espresso'),
135
+				'add-attendee'        => esc_html__('Add Contact', 'event_espresso'),
136
+				'edit'                => esc_html__('Edit Contact', 'event_espresso'),
137
+				'report'              => esc_html__("Event Registrations CSV Report", "event_espresso"),
138
+				'report_all'          => esc_html__('All Registrations CSV Report', 'event_espresso'),
139
+				'report_filtered'     => esc_html__('Filtered CSV Report', 'event_espresso'),
140
+				'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'),
141
+				'contact_list_export' => esc_html__("Export Data", "event_espresso"),
142
+			),
143
+			'publishbox'                   => array(
144
+				'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'),
145
+				'edit_attendee'    => esc_html__("Update Contact Record", 'event_espresso'),
146
+			),
147
+			'hide_add_button_on_cpt_route' => array(
148
+				'edit_attendee' => true,
149
+			),
150
+		);
151
+	}
152
+
153
+
154
+	/**
155
+	 *        grab url requests and route them
156
+	 *
157
+	 * @access private
158
+	 * @return void
159
+	 */
160
+	public function _set_page_routes()
161
+	{
162
+		$this->_get_registration_status_array();
163
+		$reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
164
+			? $this->_req_data['_REG_ID'] : 0;
165
+		$reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID'])
166
+			? $this->_req_data['reg_status_change_form']['REG_ID']
167
+			: $reg_id;
168
+		$att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
169
+			? $this->_req_data['ATT_ID'] : 0;
170
+		$att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post'])
171
+			? $this->_req_data['post']
172
+			: $att_id;
173
+		$this->_page_routes = array(
174
+			'default'                             => array(
175
+				'func'       => '_registrations_overview_list_table',
176
+				'capability' => 'ee_read_registrations',
177
+			),
178
+			'view_registration'                   => array(
179
+				'func'       => '_registration_details',
180
+				'capability' => 'ee_read_registration',
181
+				'obj_id'     => $reg_id,
182
+			),
183
+			'edit_registration'                   => array(
184
+				'func'               => '_update_attendee_registration_form',
185
+				'noheader'           => true,
186
+				'headers_sent_route' => 'view_registration',
187
+				'capability'         => 'ee_edit_registration',
188
+				'obj_id'             => $reg_id,
189
+				'_REG_ID'            => $reg_id,
190
+			),
191
+			'trash_registrations'                 => array(
192
+				'func'       => '_trash_or_restore_registrations',
193
+				'args'       => array('trash' => true),
194
+				'noheader'   => true,
195
+				'capability' => 'ee_delete_registrations',
196
+			),
197
+			'restore_registrations'               => array(
198
+				'func'       => '_trash_or_restore_registrations',
199
+				'args'       => array('trash' => false),
200
+				'noheader'   => true,
201
+				'capability' => 'ee_delete_registrations',
202
+			),
203
+			'delete_registrations'                => array(
204
+				'func'       => '_delete_registrations',
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'new_registration'                    => array(
209
+				'func'       => 'new_registration',
210
+				'capability' => 'ee_edit_registrations',
211
+			),
212
+			'process_reg_step'                    => array(
213
+				'func'       => 'process_reg_step',
214
+				'noheader'   => true,
215
+				'capability' => 'ee_edit_registrations',
216
+			),
217
+			'redirect_to_txn'                     => array(
218
+				'func'       => 'redirect_to_txn',
219
+				'noheader'   => true,
220
+				'capability' => 'ee_edit_registrations',
221
+			),
222
+			'change_reg_status'                   => array(
223
+				'func'       => '_change_reg_status',
224
+				'noheader'   => true,
225
+				'capability' => 'ee_edit_registration',
226
+				'obj_id'     => $reg_id,
227
+			),
228
+			'approve_registration'                => array(
229
+				'func'       => 'approve_registration',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registration',
232
+				'obj_id'     => $reg_id,
233
+			),
234
+			'approve_and_notify_registration'     => array(
235
+				'func'       => 'approve_registration',
236
+				'noheader'   => true,
237
+				'args'       => array(true),
238
+				'capability' => 'ee_edit_registration',
239
+				'obj_id'     => $reg_id,
240
+			),
241
+			'approve_registrations'               => array(
242
+				'func'       => 'bulk_action_on_registrations',
243
+				'noheader'   => true,
244
+				'capability' => 'ee_edit_registrations',
245
+				'args'       => array('approve'),
246
+			),
247
+			'approve_and_notify_registrations'    => array(
248
+				'func'       => 'bulk_action_on_registrations',
249
+				'noheader'   => true,
250
+				'capability' => 'ee_edit_registrations',
251
+				'args'       => array('approve', true),
252
+			),
253
+			'decline_registration'                => array(
254
+				'func'       => 'decline_registration',
255
+				'noheader'   => true,
256
+				'capability' => 'ee_edit_registration',
257
+				'obj_id'     => $reg_id,
258
+			),
259
+			'decline_and_notify_registration'     => array(
260
+				'func'       => 'decline_registration',
261
+				'noheader'   => true,
262
+				'args'       => array(true),
263
+				'capability' => 'ee_edit_registration',
264
+				'obj_id'     => $reg_id,
265
+			),
266
+			'decline_registrations'               => array(
267
+				'func'       => 'bulk_action_on_registrations',
268
+				'noheader'   => true,
269
+				'capability' => 'ee_edit_registrations',
270
+				'args'       => array('decline'),
271
+			),
272
+			'decline_and_notify_registrations'    => array(
273
+				'func'       => 'bulk_action_on_registrations',
274
+				'noheader'   => true,
275
+				'capability' => 'ee_edit_registrations',
276
+				'args'       => array('decline', true),
277
+			),
278
+			'pending_registration'                => array(
279
+				'func'       => 'pending_registration',
280
+				'noheader'   => true,
281
+				'capability' => 'ee_edit_registration',
282
+				'obj_id'     => $reg_id,
283
+			),
284
+			'pending_and_notify_registration'     => array(
285
+				'func'       => 'pending_registration',
286
+				'noheader'   => true,
287
+				'args'       => array(true),
288
+				'capability' => 'ee_edit_registration',
289
+				'obj_id'     => $reg_id,
290
+			),
291
+			'pending_registrations'               => array(
292
+				'func'       => 'bulk_action_on_registrations',
293
+				'noheader'   => true,
294
+				'capability' => 'ee_edit_registrations',
295
+				'args'       => array('pending'),
296
+			),
297
+			'pending_and_notify_registrations'    => array(
298
+				'func'       => 'bulk_action_on_registrations',
299
+				'noheader'   => true,
300
+				'capability' => 'ee_edit_registrations',
301
+				'args'       => array('pending', true),
302
+			),
303
+			'no_approve_registration'             => array(
304
+				'func'       => 'not_approve_registration',
305
+				'noheader'   => true,
306
+				'capability' => 'ee_edit_registration',
307
+				'obj_id'     => $reg_id,
308
+			),
309
+			'no_approve_and_notify_registration'  => array(
310
+				'func'       => 'not_approve_registration',
311
+				'noheader'   => true,
312
+				'args'       => array(true),
313
+				'capability' => 'ee_edit_registration',
314
+				'obj_id'     => $reg_id,
315
+			),
316
+			'no_approve_registrations'            => array(
317
+				'func'       => 'bulk_action_on_registrations',
318
+				'noheader'   => true,
319
+				'capability' => 'ee_edit_registrations',
320
+				'args'       => array('not_approve'),
321
+			),
322
+			'no_approve_and_notify_registrations' => array(
323
+				'func'       => 'bulk_action_on_registrations',
324
+				'noheader'   => true,
325
+				'capability' => 'ee_edit_registrations',
326
+				'args'       => array('not_approve', true),
327
+			),
328
+			'cancel_registration'                 => array(
329
+				'func'       => 'cancel_registration',
330
+				'noheader'   => true,
331
+				'capability' => 'ee_edit_registration',
332
+				'obj_id'     => $reg_id,
333
+			),
334
+			'cancel_and_notify_registration'      => array(
335
+				'func'       => 'cancel_registration',
336
+				'noheader'   => true,
337
+				'args'       => array(true),
338
+				'capability' => 'ee_edit_registration',
339
+				'obj_id'     => $reg_id,
340
+			),
341
+			'cancel_registrations'                => array(
342
+				'func'       => 'bulk_action_on_registrations',
343
+				'noheader'   => true,
344
+				'capability' => 'ee_edit_registrations',
345
+				'args'       => array('cancel'),
346
+			),
347
+			'cancel_and_notify_registrations'     => array(
348
+				'func'       => 'bulk_action_on_registrations',
349
+				'noheader'   => true,
350
+				'capability' => 'ee_edit_registrations',
351
+				'args'       => array('cancel', true),
352
+			),
353
+			'wait_list_registration'              => array(
354
+				'func'       => 'wait_list_registration',
355
+				'noheader'   => true,
356
+				'capability' => 'ee_edit_registration',
357
+				'obj_id'     => $reg_id,
358
+			),
359
+			'wait_list_and_notify_registration'   => array(
360
+				'func'       => 'wait_list_registration',
361
+				'noheader'   => true,
362
+				'args'       => array(true),
363
+				'capability' => 'ee_edit_registration',
364
+				'obj_id'     => $reg_id,
365
+			),
366
+			'contact_list'                        => array(
367
+				'func'       => '_attendee_contact_list_table',
368
+				'capability' => 'ee_read_contacts',
369
+			),
370
+			'add_new_attendee'                    => array(
371
+				'func' => '_create_new_cpt_item',
372
+				'args' => array(
373
+					'new_attendee' => true,
374
+					'capability'   => 'ee_edit_contacts',
375
+				),
376
+			),
377
+			'edit_attendee'                       => array(
378
+				'func'       => '_edit_cpt_item',
379
+				'capability' => 'ee_edit_contacts',
380
+				'obj_id'     => $att_id,
381
+			),
382
+			'duplicate_attendee'                  => array(
383
+				'func'       => '_duplicate_attendee',
384
+				'noheader'   => true,
385
+				'capability' => 'ee_edit_contacts',
386
+				'obj_id'     => $att_id,
387
+			),
388
+			'insert_attendee'                     => array(
389
+				'func'       => '_insert_or_update_attendee',
390
+				'args'       => array(
391
+					'new_attendee' => true,
392
+				),
393
+				'noheader'   => true,
394
+				'capability' => 'ee_edit_contacts',
395
+			),
396
+			'update_attendee'                     => array(
397
+				'func'       => '_insert_or_update_attendee',
398
+				'args'       => array(
399
+					'new_attendee' => false,
400
+				),
401
+				'noheader'   => true,
402
+				'capability' => 'ee_edit_contacts',
403
+				'obj_id'     => $att_id,
404
+			),
405
+			'trash_attendees'                     => array(
406
+				'func'       => '_trash_or_restore_attendees',
407
+				'args'       => array(
408
+					'trash' => 'true',
409
+				),
410
+				'noheader'   => true,
411
+				'capability' => 'ee_delete_contacts',
412
+			),
413
+			'trash_attendee'                      => array(
414
+				'func'       => '_trash_or_restore_attendees',
415
+				'args'       => array(
416
+					'trash' => true,
417
+				),
418
+				'noheader'   => true,
419
+				'capability' => 'ee_delete_contacts',
420
+				'obj_id'     => $att_id,
421
+			),
422
+			'restore_attendees'                   => array(
423
+				'func'       => '_trash_or_restore_attendees',
424
+				'args'       => array(
425
+					'trash' => false,
426
+				),
427
+				'noheader'   => true,
428
+				'capability' => 'ee_delete_contacts',
429
+				'obj_id'     => $att_id,
430
+			),
431
+			'resend_registration'                 => array(
432
+				'func'       => '_resend_registration',
433
+				'noheader'   => true,
434
+				'capability' => 'ee_send_message',
435
+			),
436
+			'registrations_report'                => array(
437
+				'func'       => '_registrations_report',
438
+				'noheader'   => true,
439
+				'capability' => 'ee_read_registrations',
440
+			),
441
+			'contact_list_export'                 => array(
442
+				'func'       => '_contact_list_export',
443
+				'noheader'   => true,
444
+				'capability' => 'export',
445
+			),
446
+			'contact_list_report'                 => array(
447
+				'func'       => '_contact_list_report',
448
+				'noheader'   => true,
449
+				'capability' => 'ee_read_contacts',
450
+			),
451
+		);
452
+	}
453
+
454
+
455
+	protected function _set_page_config()
456
+	{
457
+		$this->_page_config = array(
458
+			'default'           => array(
459
+				'nav'           => array(
460
+					'label' => esc_html__('Overview', 'event_espresso'),
461
+					'order' => 5,
462
+				),
463
+				'help_tabs'     => array(
464
+					'registrations_overview_help_tab'                       => array(
465
+						'title'    => esc_html__('Registrations Overview', 'event_espresso'),
466
+						'filename' => 'registrations_overview',
467
+					),
468
+					'registrations_overview_table_column_headings_help_tab' => array(
469
+						'title'    => esc_html__('Registrations Table Column Headings', 'event_espresso'),
470
+						'filename' => 'registrations_overview_table_column_headings',
471
+					),
472
+					'registrations_overview_filters_help_tab'               => array(
473
+						'title'    => esc_html__('Registration Filters', 'event_espresso'),
474
+						'filename' => 'registrations_overview_filters',
475
+					),
476
+					'registrations_overview_views_help_tab'                 => array(
477
+						'title'    => esc_html__('Registration Views', 'event_espresso'),
478
+						'filename' => 'registrations_overview_views',
479
+					),
480
+					'registrations_regoverview_other_help_tab'              => array(
481
+						'title'    => esc_html__('Registrations Other', 'event_espresso'),
482
+						'filename' => 'registrations_overview_other',
483
+					),
484
+				),
485
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
486
+				'qtips'         => array('Registration_List_Table_Tips'),
487
+				'list_table'    => 'EE_Registrations_List_Table',
488
+				'require_nonce' => false,
489
+			),
490
+			'view_registration' => array(
491
+				'nav'           => array(
492
+					'label'      => esc_html__('REG Details', 'event_espresso'),
493
+					'order'      => 15,
494
+					'url'        => isset($this->_req_data['_REG_ID'])
495
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
496
+						: $this->_admin_base_url,
497
+					'persistent' => false,
498
+				),
499
+				'help_tabs'     => array(
500
+					'registrations_details_help_tab'                    => array(
501
+						'title'    => esc_html__('Registration Details', 'event_espresso'),
502
+						'filename' => 'registrations_details',
503
+					),
504
+					'registrations_details_table_help_tab'              => array(
505
+						'title'    => esc_html__('Registration Details Table', 'event_espresso'),
506
+						'filename' => 'registrations_details_table',
507
+					),
508
+					'registrations_details_form_answers_help_tab'       => array(
509
+						'title'    => esc_html__('Registration Form Answers', 'event_espresso'),
510
+						'filename' => 'registrations_details_form_answers',
511
+					),
512
+					'registrations_details_registrant_details_help_tab' => array(
513
+						'title'    => esc_html__('Contact Details', 'event_espresso'),
514
+						'filename' => 'registrations_details_registrant_details',
515
+					),
516
+				),
517
+				'help_tour'     => array('Registration_Details_Help_Tour'),
518
+				'metaboxes'     => array_merge(
519
+					$this->_default_espresso_metaboxes,
520
+					array('_registration_details_metaboxes')
521
+				),
522
+				'require_nonce' => false,
523
+			),
524
+			'new_registration'  => array(
525
+				'nav'           => array(
526
+					'label'      => esc_html__('Add New Registration', 'event_espresso'),
527
+					'url'        => '#',
528
+					'order'      => 15,
529
+					'persistent' => false,
530
+				),
531
+				'metaboxes'     => $this->_default_espresso_metaboxes,
532
+				'labels'        => array(
533
+					'publishbox' => esc_html__('Save Registration', 'event_espresso'),
534
+				),
535
+				'require_nonce' => false,
536
+			),
537
+			'add_new_attendee'  => array(
538
+				'nav'           => array(
539
+					'label'      => esc_html__('Add Contact', 'event_espresso'),
540
+					'order'      => 15,
541
+					'persistent' => false,
542
+				),
543
+				'metaboxes'     => array_merge(
544
+					$this->_default_espresso_metaboxes,
545
+					array('_publish_post_box', 'attendee_editor_metaboxes')
546
+				),
547
+				'require_nonce' => false,
548
+			),
549
+			'edit_attendee'     => array(
550
+				'nav'           => array(
551
+					'label'      => esc_html__('Edit Contact', 'event_espresso'),
552
+					'order'      => 15,
553
+					'persistent' => false,
554
+					'url'        => isset($this->_req_data['ATT_ID'])
555
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
556
+						: $this->_admin_base_url,
557
+				),
558
+				'metaboxes'     => array('attendee_editor_metaboxes'),
559
+				'require_nonce' => false,
560
+			),
561
+			'contact_list'      => array(
562
+				'nav'           => array(
563
+					'label' => esc_html__('Contact List', 'event_espresso'),
564
+					'order' => 20,
565
+				),
566
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
567
+				'help_tabs'     => array(
568
+					'registrations_contact_list_help_tab'                       => array(
569
+						'title'    => esc_html__('Registrations Contact List', 'event_espresso'),
570
+						'filename' => 'registrations_contact_list',
571
+					),
572
+					'registrations_contact-list_table_column_headings_help_tab' => array(
573
+						'title'    => esc_html__('Contact List Table Column Headings', 'event_espresso'),
574
+						'filename' => 'registrations_contact_list_table_column_headings',
575
+					),
576
+					'registrations_contact_list_views_help_tab'                 => array(
577
+						'title'    => esc_html__('Contact List Views', 'event_espresso'),
578
+						'filename' => 'registrations_contact_list_views',
579
+					),
580
+					'registrations_contact_list_other_help_tab'                 => array(
581
+						'title'    => esc_html__('Contact List Other', 'event_espresso'),
582
+						'filename' => 'registrations_contact_list_other',
583
+					),
584
+				),
585
+				'help_tour'     => array('Contact_List_Help_Tour'),
586
+				'metaboxes'     => array(),
587
+				'require_nonce' => false,
588
+			),
589
+			// override default cpt routes
590
+			'create_new'        => '',
591
+			'edit'              => '',
592
+		);
593
+	}
594
+
595
+
596
+	/**
597
+	 * The below methods aren't used by this class currently
598
+	 */
599
+	protected function _add_screen_options()
600
+	{
601
+	}
602
+
603
+
604
+	protected function _add_feature_pointers()
605
+	{
606
+	}
607
+
608
+
609
+	public function admin_init()
610
+	{
611
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__(
612
+			'click "Update Registration Questions" to save your changes',
613
+			'event_espresso'
614
+		);
615
+	}
616
+
617
+
618
+	public function admin_notices()
619
+	{
620
+	}
621
+
622
+
623
+	public function admin_footer_scripts()
624
+	{
625
+	}
626
+
627
+
628
+	/**
629
+	 *        get list of registration statuses
630
+	 *
631
+	 * @access private
632
+	 * @return void
633
+	 * @throws EE_Error
634
+	 */
635
+	private function _get_registration_status_array()
636
+	{
637
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
638
+	}
639
+
640
+
641
+	protected function _add_screen_options_default()
642
+	{
643
+		$this->_per_page_screen_option();
644
+	}
645
+
646
+
647
+	protected function _add_screen_options_contact_list()
648
+	{
649
+		$page_title = $this->_admin_page_title;
650
+		$this->_admin_page_title = esc_html__("Contacts", 'event_espresso');
651
+		$this->_per_page_screen_option();
652
+		$this->_admin_page_title = $page_title;
653
+	}
654
+
655
+
656
+	public function load_scripts_styles()
657
+	{
658
+		// style
659
+		wp_register_style(
660
+			'espresso_reg',
661
+			REG_ASSETS_URL . 'espresso_registrations_admin.css',
662
+			array('ee-admin-css'),
663
+			EVENT_ESPRESSO_VERSION
664
+		);
665
+		wp_enqueue_style('espresso_reg');
666
+		// script
667
+		wp_register_script(
668
+			'espresso_reg',
669
+			REG_ASSETS_URL . 'espresso_registrations_admin.js',
670
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
671
+			EVENT_ESPRESSO_VERSION,
672
+			true
673
+		);
674
+		wp_enqueue_script('espresso_reg');
675
+	}
676
+
677
+
678
+	public function load_scripts_styles_edit_attendee()
679
+	{
680
+		// stuff to only show up on our attendee edit details page.
681
+		$attendee_details_translations = array(
682
+			'att_publish_text' => sprintf(
683
+				esc_html__('Created on: <b>%1$s</b>', 'event_espresso'),
684
+				$this->_cpt_model_obj->get_datetime('ATT_created')
685
+			),
686
+		);
687
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
688
+		wp_enqueue_script('jquery-validate');
689
+	}
690
+
691
+
692
+	public function load_scripts_styles_view_registration()
693
+	{
694
+		// styles
695
+		wp_enqueue_style('espresso-ui-theme');
696
+		// scripts
697
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
698
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
699
+	}
700
+
701
+
702
+	public function load_scripts_styles_contact_list()
703
+	{
704
+		wp_dequeue_style('espresso_reg');
705
+		wp_register_style(
706
+			'espresso_att',
707
+			REG_ASSETS_URL . 'espresso_attendees_admin.css',
708
+			array('ee-admin-css'),
709
+			EVENT_ESPRESSO_VERSION
710
+		);
711
+		wp_enqueue_style('espresso_att');
712
+	}
713
+
714
+
715
+	public function load_scripts_styles_new_registration()
716
+	{
717
+		wp_register_script(
718
+			'ee-spco-for-admin',
719
+			REG_ASSETS_URL . 'spco_for_admin.js',
720
+			array('underscore', 'jquery'),
721
+			EVENT_ESPRESSO_VERSION,
722
+			true
723
+		);
724
+		wp_enqueue_script('ee-spco-for-admin');
725
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
726
+		EE_Form_Section_Proper::wp_enqueue_scripts();
727
+		EED_Ticket_Selector::load_tckt_slctr_assets();
728
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
729
+	}
730
+
731
+
732
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
733
+	{
734
+		add_filter('FHEE_load_EE_messages', '__return_true');
735
+	}
736
+
737
+
738
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
739
+	{
740
+		add_filter('FHEE_load_EE_messages', '__return_true');
741
+	}
742
+
743
+
744
+	protected function _set_list_table_views_default()
745
+	{
746
+		// for notification related bulk actions we need to make sure only active messengers have an option.
747
+		EED_Messages::set_autoloaders();
748
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
749
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
750
+		$active_mts = $message_resource_manager->list_of_active_message_types();
751
+		// key= bulk_action_slug, value= message type.
752
+		$match_array = array(
753
+			'approve_registrations'    => 'registration',
754
+			'decline_registrations'    => 'declined_registration',
755
+			'pending_registrations'    => 'pending_approval',
756
+			'no_approve_registrations' => 'not_approved_registration',
757
+			'cancel_registrations'     => 'cancelled_registration',
758
+		);
759
+		$can_send = EE_Registry::instance()->CAP->current_user_can(
760
+			'ee_send_message',
761
+			'batch_send_messages'
762
+		);
763
+		/** setup reg status bulk actions **/
764
+		$def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso');
765
+		if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) {
766
+			$def_reg_status_actions['approve_and_notify_registrations'] = esc_html__(
767
+				'Approve and Notify Registrations',
768
+				'event_espresso'
769
+			);
770
+		}
771
+		$def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso');
772
+		if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) {
773
+			$def_reg_status_actions['decline_and_notify_registrations'] = esc_html__(
774
+				'Decline and Notify Registrations',
775
+				'event_espresso'
776
+			);
777
+		}
778
+		$def_reg_status_actions['pending_registrations'] = esc_html__(
779
+			'Set Registrations to Pending Payment',
780
+			'event_espresso'
781
+		);
782
+		if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) {
783
+			$def_reg_status_actions['pending_and_notify_registrations'] = esc_html__(
784
+				'Set Registrations to Pending Payment and Notify',
785
+				'event_espresso'
786
+			);
787
+		}
788
+		$def_reg_status_actions['no_approve_registrations'] = esc_html__(
789
+			'Set Registrations to Not Approved',
790
+			'event_espresso'
791
+		);
792
+		if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) {
793
+			$def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__(
794
+				'Set Registrations to Not Approved and Notify',
795
+				'event_espresso'
796
+			);
797
+		}
798
+		$def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso');
799
+		if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) {
800
+			$def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__(
801
+				'Cancel Registrations and Notify',
802
+				'event_espresso'
803
+			);
804
+		}
805
+		$def_reg_status_actions = apply_filters(
806
+			'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array',
807
+			$def_reg_status_actions,
808
+			$active_mts,
809
+			$can_send
810
+		);
811
+
812
+		$this->_views = array(
813
+			'all'   => array(
814
+				'slug'        => 'all',
815
+				'label'       => esc_html__('View All Registrations', 'event_espresso'),
816
+				'count'       => 0,
817
+				'bulk_action' => array_merge(
818
+					$def_reg_status_actions,
819
+					array(
820
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
821
+					)
822
+				),
823
+			),
824
+			'month' => array(
825
+				'slug'        => 'month',
826
+				'label'       => esc_html__('This Month', 'event_espresso'),
827
+				'count'       => 0,
828
+				'bulk_action' => array_merge(
829
+					$def_reg_status_actions,
830
+					array(
831
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
832
+					)
833
+				),
834
+			),
835
+			'today' => array(
836
+				'slug'        => 'today',
837
+				'label'       => sprintf(
838
+					esc_html__('Today - %s', 'event_espresso'),
839
+					date('M d, Y', current_time('timestamp'))
840
+				),
841
+				'count'       => 0,
842
+				'bulk_action' => array_merge(
843
+					$def_reg_status_actions,
844
+					array(
845
+						'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
846
+					)
847
+				),
848
+			),
849
+		);
850
+		if (EE_Registry::instance()->CAP->current_user_can(
851
+			'ee_delete_registrations',
852
+			'espresso_registrations_delete_registration'
853
+		)) {
854
+			$this->_views['incomplete'] = array(
855
+				'slug'        => 'incomplete',
856
+				'label'       => esc_html__('Incomplete', 'event_espresso'),
857
+				'count'       => 0,
858
+				'bulk_action' => array(
859
+					'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'),
860
+				),
861
+			);
862
+			$this->_views['trash'] = array(
863
+				'slug'        => 'trash',
864
+				'label'       => esc_html__('Trash', 'event_espresso'),
865
+				'count'       => 0,
866
+				'bulk_action' => array(
867
+					'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'),
868
+					'delete_registrations'  => esc_html__('Delete Registrations Permanently', 'event_espresso'),
869
+				),
870
+			);
871
+		}
872
+	}
873
+
874
+
875
+	protected function _set_list_table_views_contact_list()
876
+	{
877
+		$this->_views = array(
878
+			'in_use' => array(
879
+				'slug'        => 'in_use',
880
+				'label'       => esc_html__('In Use', 'event_espresso'),
881
+				'count'       => 0,
882
+				'bulk_action' => array(
883
+					'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'),
884
+				),
885
+			),
886
+		);
887
+		if (EE_Registry::instance()->CAP->current_user_can(
888
+			'ee_delete_contacts',
889
+			'espresso_registrations_trash_attendees'
890
+		)
891
+		) {
892
+			$this->_views['trash'] = array(
893
+				'slug'        => 'trash',
894
+				'label'       => esc_html__('Trash', 'event_espresso'),
895
+				'count'       => 0,
896
+				'bulk_action' => array(
897
+					'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'),
898
+				),
899
+			);
900
+		}
901
+	}
902
+
903
+
904
+	protected function _registration_legend_items()
905
+	{
906
+		$fc_items = array(
907
+			'star-icon'        => array(
908
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
909
+				'desc'  => esc_html__('This is the Primary Registrant', 'event_espresso'),
910
+			),
911
+			'view_details'     => array(
912
+				'class' => 'dashicons dashicons-clipboard',
913
+				'desc'  => esc_html__('View Registration Details', 'event_espresso'),
914
+			),
915
+			'edit_attendee'    => array(
916
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
917
+				'desc'  => esc_html__('Edit Contact Details', 'event_espresso'),
918
+			),
919
+			'view_transaction' => array(
920
+				'class' => 'dashicons dashicons-cart',
921
+				'desc'  => esc_html__('View Transaction Details', 'event_espresso'),
922
+			),
923
+			'view_invoice'     => array(
924
+				'class' => 'dashicons dashicons-media-spreadsheet',
925
+				'desc'  => esc_html__('View Transaction Invoice', 'event_espresso'),
926
+			),
927
+		);
928
+		if (EE_Registry::instance()->CAP->current_user_can(
929
+			'ee_send_message',
930
+			'espresso_registrations_resend_registration'
931
+		)) {
932
+			$fc_items['resend_registration'] = array(
933
+				'class' => 'dashicons dashicons-email-alt',
934
+				'desc'  => esc_html__('Resend Registration Details', 'event_espresso'),
935
+			);
936
+		} else {
937
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
938
+		}
939
+		if (EE_Registry::instance()->CAP->current_user_can(
940
+			'ee_read_global_messages',
941
+			'view_filtered_messages'
942
+		)) {
943
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
944
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
945
+				$fc_items['view_related_messages'] = array(
946
+					'class' => $related_for_icon['css_class'],
947
+					'desc'  => $related_for_icon['label'],
948
+				);
949
+			}
950
+		}
951
+		$sc_items = array(
952
+			'approved_status'   => array(
953
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
954
+				'desc'  => EEH_Template::pretty_status(
955
+					EEM_Registration::status_id_approved,
956
+					false,
957
+					'sentence'
958
+				),
959
+			),
960
+			'pending_status'    => array(
961
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
962
+				'desc'  => EEH_Template::pretty_status(
963
+					EEM_Registration::status_id_pending_payment,
964
+					false,
965
+					'sentence'
966
+				),
967
+			),
968
+			'wait_list'         => array(
969
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
970
+				'desc'  => EEH_Template::pretty_status(
971
+					EEM_Registration::status_id_wait_list,
972
+					false,
973
+					'sentence'
974
+				),
975
+			),
976
+			'incomplete_status' => array(
977
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
978
+				'desc'  => EEH_Template::pretty_status(
979
+					EEM_Registration::status_id_incomplete,
980
+					false,
981
+					'sentence'
982
+				),
983
+			),
984
+			'not_approved'      => array(
985
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
986
+				'desc'  => EEH_Template::pretty_status(
987
+					EEM_Registration::status_id_not_approved,
988
+					false,
989
+					'sentence'
990
+				),
991
+			),
992
+			'declined_status'   => array(
993
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
994
+				'desc'  => EEH_Template::pretty_status(
995
+					EEM_Registration::status_id_declined,
996
+					false,
997
+					'sentence'
998
+				),
999
+			),
1000
+			'cancelled_status'  => array(
1001
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1002
+				'desc'  => EEH_Template::pretty_status(
1003
+					EEM_Registration::status_id_cancelled,
1004
+					false,
1005
+					'sentence'
1006
+				),
1007
+			),
1008
+		);
1009
+		return array_merge($fc_items, $sc_items);
1010
+	}
1011
+
1012
+
1013
+
1014
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
1015
+	/**
1016
+	 * @throws \EE_Error
1017
+	 */
1018
+	protected function _registrations_overview_list_table()
1019
+	{
1020
+		$this->_template_args['admin_page_header'] = '';
1021
+		$EVT_ID = ! empty($this->_req_data['event_id'])
1022
+			? absint($this->_req_data['event_id'])
1023
+			: 0;
1024
+		$ATT_ID = ! empty($this->_req_data['ATT_ID'])
1025
+			? absint($this->_req_data['ATT_ID'])
1026
+			: 0;
1027
+		if ($ATT_ID) {
1028
+			$attendee = EEM_Attendee::instance()->get_one_by_ID($ATT_ID);
1029
+			if ($attendee instanceof EE_Attendee) {
1030
+				$this->_template_args['admin_page_header'] = sprintf(
1031
+					esc_html__(
1032
+						'%1$s Viewing registrations for %2$s%3$s',
1033
+						'event_espresso'
1034
+					),
1035
+					'<h3 style="line-height:1.5em;">',
1036
+					'<a href="' . EE_Admin_Page::add_query_args_and_nonce(
1037
+						array(
1038
+							'action' => 'edit_attendee',
1039
+							'post'   => $ATT_ID,
1040
+						),
1041
+						REG_ADMIN_URL
1042
+					) . '">' . $attendee->full_name() . '</a>',
1043
+					'</h3>'
1044
+				);
1045
+			}
1046
+		}
1047
+		if ($EVT_ID) {
1048
+			if (EE_Registry::instance()->CAP->current_user_can(
1049
+				'ee_edit_registrations',
1050
+				'espresso_registrations_new_registration',
1051
+				$EVT_ID
1052
+			)) {
1053
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1054
+					'new_registration',
1055
+					'add-registrant',
1056
+					array('event_id' => $EVT_ID),
1057
+					'add-new-h2'
1058
+				);
1059
+			}
1060
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1061
+			if ($event instanceof EE_Event) {
1062
+				$this->_template_args['admin_page_header'] = sprintf(
1063
+					esc_html__(
1064
+						'%s Viewing registrations for the event: %s%s',
1065
+						'event_espresso'
1066
+					),
1067
+					'<h3 style="line-height:1.5em;">',
1068
+					'<br /><a href="'
1069
+					. EE_Admin_Page::add_query_args_and_nonce(
1070
+						array(
1071
+							'action' => 'edit',
1072
+							'post'   => $event->ID(),
1073
+						),
1074
+						EVENTS_ADMIN_URL
1075
+					)
1076
+					. '">&nbsp;'
1077
+					. $event->get('EVT_name')
1078
+					. '&nbsp;</a>&nbsp;',
1079
+					'</h3>'
1080
+				);
1081
+			}
1082
+			$DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
1083
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
1084
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
1085
+				$this->_template_args['admin_page_header'] = substr(
1086
+					$this->_template_args['admin_page_header'],
1087
+					0,
1088
+					-5
1089
+				);
1090
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1091
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1092
+				$this->_template_args['admin_page_header'] .= $datetime->name();
1093
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1094
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
1095
+			}
1096
+		}
1097
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
1098
+		$this->display_admin_list_table_page_with_no_sidebar();
1099
+	}
1100
+
1101
+
1102
+	/**
1103
+	 * This sets the _registration property for the registration details screen
1104
+	 *
1105
+	 * @access private
1106
+	 * @return bool
1107
+	 * @throws EE_Error
1108
+	 * @throws InvalidArgumentException
1109
+	 * @throws InvalidDataTypeException
1110
+	 * @throws InvalidInterfaceException
1111
+	 */
1112
+	private function _set_registration_object()
1113
+	{
1114
+		// get out if we've already set the object
1115
+		if ($this->_registration instanceof EE_Registration) {
1116
+			return true;
1117
+		}
1118
+		$REG = EEM_Registration::instance();
1119
+		$REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1120
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1121
+			return true;
1122
+		} else {
1123
+			$error_msg = sprintf(
1124
+				esc_html__(
1125
+					'An error occurred and the details for Registration ID #%s could not be retrieved.',
1126
+					'event_espresso'
1127
+				),
1128
+				$REG_ID
1129
+			);
1130
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
1131
+			$this->_registration = null;
1132
+			return false;
1133
+		}
1134
+	}
1135
+
1136
+
1137
+	/**
1138
+	 * Used to retrieve registrations for the list table.
1139
+	 *
1140
+	 * @param int  $per_page
1141
+	 * @param bool $count
1142
+	 * @param bool $this_month
1143
+	 * @param bool $today
1144
+	 * @return EE_Registration[]|int
1145
+	 * @throws EE_Error
1146
+	 * @throws InvalidArgumentException
1147
+	 * @throws InvalidDataTypeException
1148
+	 * @throws InvalidInterfaceException
1149
+	 */
1150
+	public function get_registrations(
1151
+		$per_page = 10,
1152
+		$count = false,
1153
+		$this_month = false,
1154
+		$today = false
1155
+	) {
1156
+		if ($this_month) {
1157
+			$this->_req_data['status'] = 'month';
1158
+		}
1159
+		if ($today) {
1160
+			$this->_req_data['status'] = 'today';
1161
+		}
1162
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
1163
+		/**
1164
+		 * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected
1165
+		 *
1166
+		 * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093
1167
+		 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
1168
+		 *                             or if you have the development copy of EE you can view this at the path:
1169
+		 *                             /docs/G--Model-System/model-query-params.md
1170
+		 */
1171
+		$query_params['group_by'] = '';
1172
+
1173
+		return $count
1174
+			? EEM_Registration::instance()->count($query_params)
1175
+			/** @type EE_Registration[] */
1176
+			: EEM_Registration::instance()->get_all($query_params);
1177
+	}
1178
+
1179
+
1180
+	/**
1181
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
1182
+	 * Note: this listens to values on the request for some of the query parameters.
1183
+	 *
1184
+	 * @param array $request
1185
+	 * @param int   $per_page
1186
+	 * @param bool  $count
1187
+	 * @return array
1188
+	 * @throws EE_Error
1189
+	 */
1190
+	protected function _get_registration_query_parameters(
1191
+		$request = array(),
1192
+		$per_page = 10,
1193
+		$count = false
1194
+	) {
1195
+
1196
+		$query_params = array(
1197
+			0                          => $this->_get_where_conditions_for_registrations_query(
1198
+				$request
1199
+			),
1200
+			'caps'                     => EEM_Registration::caps_read_admin,
1201
+			'default_where_conditions' => 'this_model_only',
1202
+		);
1203
+		if (! $count) {
1204
+			$query_params = array_merge(
1205
+				$query_params,
1206
+				$this->_get_orderby_for_registrations_query(),
1207
+				$this->_get_limit($per_page)
1208
+			);
1209
+		}
1210
+
1211
+		return $query_params;
1212
+	}
1213
+
1214
+
1215
+	/**
1216
+	 * This will add ATT_ID to the provided $where array for EE model query parameters.
1217
+	 *
1218
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1219
+	 * @return array
1220
+	 */
1221
+	protected function addAttendeeIdToWhereConditions(array $request)
1222
+	{
1223
+		$where = array();
1224
+		if (! empty($request['ATT_ID'])) {
1225
+			$where['ATT_ID'] = absint($request['ATT_ID']);
1226
+		}
1227
+		return $where;
1228
+	}
1229
+
1230
+
1231
+	/**
1232
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
1233
+	 *
1234
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1235
+	 * @return array
1236
+	 */
1237
+	protected function _add_event_id_to_where_conditions(array $request)
1238
+	{
1239
+		$where = array();
1240
+		if (! empty($request['event_id'])) {
1241
+			$where['EVT_ID'] = absint($request['event_id']);
1242
+		}
1243
+		return $where;
1244
+	}
1245
+
1246
+
1247
+	/**
1248
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
1249
+	 *
1250
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1251
+	 * @return array
1252
+	 */
1253
+	protected function _add_category_id_to_where_conditions(array $request)
1254
+	{
1255
+		$where = array();
1256
+		if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1257
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1258
+		}
1259
+		return $where;
1260
+	}
1261
+
1262
+
1263
+	/**
1264
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1265
+	 *
1266
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1267
+	 * @return array
1268
+	 */
1269
+	protected function _add_datetime_id_to_where_conditions(array $request)
1270
+	{
1271
+		$where = array();
1272
+		if (! empty($request['datetime_id'])) {
1273
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1274
+		}
1275
+		if (! empty($request['DTT_ID'])) {
1276
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1277
+		}
1278
+		return $where;
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 * Adds the correct registration status to the where conditions for the registrations query.
1284
+	 *
1285
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1286
+	 * @return array
1287
+	 */
1288
+	protected function _add_registration_status_to_where_conditions(array $request)
1289
+	{
1290
+		$where = array();
1291
+		$view = EEH_Array::is_set($request, 'status', '');
1292
+		$registration_status = ! empty($request['_reg_status'])
1293
+			? sanitize_text_field($request['_reg_status'])
1294
+			: '';
1295
+
1296
+		/*
1297 1297
          * If filtering by registration status, then we show registrations matching that status.
1298 1298
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1299 1299
          * UNLESS viewing trashed registrations.
1300 1300
          */
1301
-        if (! empty($registration_status)) {
1302
-            $where['STS_ID'] = $registration_status;
1303
-        } else {
1304
-            // make sure we exclude incomplete registrations, but only if not trashed.
1305
-            if ($view === 'trash') {
1306
-                $where['REG_deleted'] = true;
1307
-            } elseif ($view === 'incomplete') {
1308
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1309
-            } else {
1310
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1311
-            }
1312
-        }
1313
-        return $where;
1314
-    }
1315
-
1316
-
1317
-    /**
1318
-     * Adds any provided date restraints to the where conditions for the registrations query.
1319
-     *
1320
-     * @param array $request usually the same as $this->_req_data but not necessarily
1321
-     * @return array
1322
-     * @throws EE_Error
1323
-     * @throws InvalidArgumentException
1324
-     * @throws InvalidDataTypeException
1325
-     * @throws InvalidInterfaceException
1326
-     */
1327
-    protected function _add_date_to_where_conditions(array $request)
1328
-    {
1329
-        $where = array();
1330
-        $view = EEH_Array::is_set($request, 'status', '');
1331
-        $month_range = ! empty($request['month_range'])
1332
-            ? sanitize_text_field($request['month_range'])
1333
-            : '';
1334
-        $retrieve_for_today = $view === 'today';
1335
-        $retrieve_for_this_month = $view === 'month';
1336
-
1337
-        if ($retrieve_for_today) {
1338
-            $now = date('Y-m-d', current_time('timestamp'));
1339
-            $where['REG_date'] = array(
1340
-                'BETWEEN',
1341
-                array(
1342
-                    EEM_Registration::instance()->convert_datetime_for_query(
1343
-                        'REG_date',
1344
-                        $now . ' 00:00:00',
1345
-                        'Y-m-d H:i:s'
1346
-                    ),
1347
-                    EEM_Registration::instance()->convert_datetime_for_query(
1348
-                        'REG_date',
1349
-                        $now . ' 23:59:59',
1350
-                        'Y-m-d H:i:s'
1351
-                    ),
1352
-                ),
1353
-            );
1354
-        } elseif ($retrieve_for_this_month) {
1355
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1356
-            $days_this_month = date('t', current_time('timestamp'));
1357
-            $where['REG_date'] = array(
1358
-                'BETWEEN',
1359
-                array(
1360
-                    EEM_Registration::instance()->convert_datetime_for_query(
1361
-                        'REG_date',
1362
-                        $current_year_and_month . '-01 00:00:00',
1363
-                        'Y-m-d H:i:s'
1364
-                    ),
1365
-                    EEM_Registration::instance()->convert_datetime_for_query(
1366
-                        'REG_date',
1367
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1368
-                        'Y-m-d H:i:s'
1369
-                    ),
1370
-                ),
1371
-            );
1372
-        } elseif ($month_range) {
1373
-            $pieces = explode(' ', $month_range, 3);
1374
-            $month_requested = ! empty($pieces[0])
1375
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1376
-                : '';
1377
-            $year_requested = ! empty($pieces[1])
1378
-                ? $pieces[1]
1379
-                : '';
1380
-            // if there is not a month or year then we can't go further
1381
-            if ($month_requested && $year_requested) {
1382
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1383
-                $where['REG_date'] = array(
1384
-                    'BETWEEN',
1385
-                    array(
1386
-                        EEM_Registration::instance()->convert_datetime_for_query(
1387
-                            'REG_date',
1388
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1389
-                            'Y-m-d H:i:s'
1390
-                        ),
1391
-                        EEM_Registration::instance()->convert_datetime_for_query(
1392
-                            'REG_date',
1393
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1394
-                            'Y-m-d H:i:s'
1395
-                        ),
1396
-                    ),
1397
-                );
1398
-            }
1399
-        }
1400
-        return $where;
1401
-    }
1402
-
1403
-
1404
-    /**
1405
-     * Adds any provided search restraints to the where conditions for the registrations query
1406
-     *
1407
-     * @param array $request usually the same as $this->_req_data but not necessarily
1408
-     * @return array
1409
-     */
1410
-    protected function _add_search_to_where_conditions(array $request)
1411
-    {
1412
-        $where = array();
1413
-        if (! empty($request['s'])) {
1414
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1415
-            $where['OR*search_conditions'] = array(
1416
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1417
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1418
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1419
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1420
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1421
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1422
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1423
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1424
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1425
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1426
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1427
-                'REG_final_price'                         => array('LIKE', $search_string),
1428
-                'REG_code'                                => array('LIKE', $search_string),
1429
-                'REG_count'                               => array('LIKE', $search_string),
1430
-                'REG_group_size'                          => array('LIKE', $search_string),
1431
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1432
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1433
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1434
-            );
1435
-        }
1436
-        return $where;
1437
-    }
1438
-
1439
-
1440
-    /**
1441
-     * Sets up the where conditions for the registrations query.
1442
-     *
1443
-     * @param array $request
1444
-     * @return array
1445
-     * @throws EE_Error
1446
-     */
1447
-    protected function _get_where_conditions_for_registrations_query($request)
1448
-    {
1449
-        return apply_filters(
1450
-            'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1451
-            array_merge(
1452
-                $this->addAttendeeIdToWhereConditions($request),
1453
-                $this->_add_event_id_to_where_conditions($request),
1454
-                $this->_add_category_id_to_where_conditions($request),
1455
-                $this->_add_datetime_id_to_where_conditions($request),
1456
-                $this->_add_registration_status_to_where_conditions($request),
1457
-                $this->_add_date_to_where_conditions($request),
1458
-                $this->_add_search_to_where_conditions($request)
1459
-            ),
1460
-            $request
1461
-        );
1462
-    }
1463
-
1464
-
1465
-    /**
1466
-     * Sets up the orderby for the registrations query.
1467
-     *
1468
-     * @return array
1469
-     */
1470
-    protected function _get_orderby_for_registrations_query()
1471
-    {
1472
-        $orderby_field = ! empty($this->_req_data['orderby'])
1473
-            ? sanitize_text_field($this->_req_data['orderby'])
1474
-            : '_REG_date';
1475
-        switch ($orderby_field) {
1476
-            case '_REG_ID':
1477
-                $orderby = array('REG_ID');
1478
-                break;
1479
-            case '_Reg_status':
1480
-                $orderby = array('STS_ID');
1481
-                break;
1482
-            case 'ATT_fname':
1483
-                $orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1484
-                break;
1485
-            case 'ATT_lname':
1486
-                $orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1487
-                break;
1488
-            case 'event_name':
1489
-                $orderby = array('Event.EVT_name');
1490
-                break;
1491
-            case 'DTT_EVT_start':
1492
-                $orderby = array('Event.Datetime.DTT_EVT_start');
1493
-                break;
1494
-            case '_REG_date':
1495
-                $orderby = array('REG_date');
1496
-                break;
1497
-            default:
1498
-                $orderby = array($orderby_field);
1499
-                break;
1500
-        }
1501
-
1502
-        // order
1503
-        $order = ! empty($this->_req_data['order'])
1504
-            ? sanitize_text_field($this->_req_data['order'])
1505
-            : 'DESC';
1506
-        $orderby = array_combine(
1507
-            $orderby,
1508
-            array_fill(0, count($orderby), $order)
1509
-        );
1510
-        // because there are many registrations with the same date, define
1511
-        // a secondary way to order them, otherwise MySQL seems to be a bit random
1512
-        if (empty($orderby['REG_ID'])) {
1513
-            $orderby['REG_ID'] = $order;
1514
-        }
1515
-
1516
-        $orderby = apply_filters(
1517
-            'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
1518
-            $orderby,
1519
-            $this->_req_data
1520
-        );
1521
-
1522
-        return array('order_by' => $orderby);
1523
-    }
1524
-
1525
-
1526
-    /**
1527
-     * Sets up the limit for the registrations query.
1528
-     *
1529
-     * @param $per_page
1530
-     * @return array
1531
-     */
1532
-    protected function _get_limit($per_page)
1533
-    {
1534
-        $current_page = ! empty($this->_req_data['paged'])
1535
-            ? absint($this->_req_data['paged'])
1536
-            : 1;
1537
-        $per_page = ! empty($this->_req_data['perpage'])
1538
-            ? $this->_req_data['perpage']
1539
-            : $per_page;
1540
-
1541
-        // -1 means return all results so get out if that's set.
1542
-        if ((int) $per_page === -1) {
1543
-            return array();
1544
-        }
1545
-        $per_page = absint($per_page);
1546
-        $offset = ($current_page - 1) * $per_page;
1547
-        return array('limit' => array($offset, $per_page));
1548
-    }
1549
-
1550
-
1551
-    public function get_registration_status_array()
1552
-    {
1553
-        return self::$_reg_status;
1554
-    }
1555
-
1556
-
1557
-
1558
-
1559
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1560
-    /**
1561
-     *        generates HTML for the View Registration Details Admin page
1562
-     *
1563
-     * @access protected
1564
-     * @return void
1565
-     * @throws DomainException
1566
-     * @throws EE_Error
1567
-     * @throws InvalidArgumentException
1568
-     * @throws InvalidDataTypeException
1569
-     * @throws InvalidInterfaceException
1570
-     * @throws EntityNotFoundException
1571
-     */
1572
-    protected function _registration_details()
1573
-    {
1574
-        $this->_template_args = array();
1575
-        $this->_set_registration_object();
1576
-        if (is_object($this->_registration)) {
1577
-            $transaction = $this->_registration->transaction()
1578
-                ? $this->_registration->transaction()
1579
-                : EE_Transaction::new_instance();
1580
-            $this->_session = $transaction->session_data();
1581
-            $event_id = $this->_registration->event_ID();
1582
-            $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1583
-            $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1584
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1585
-            $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1586
-            $this->_template_args['grand_total'] = $transaction->total();
1587
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1588
-            // link back to overview
1589
-            $this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1590
-            $this->_template_args['registration'] = $this->_registration;
1591
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1592
-                array(
1593
-                    'action'   => 'default',
1594
-                    'event_id' => $event_id,
1595
-                ),
1596
-                REG_ADMIN_URL
1597
-            );
1598
-            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1599
-                array(
1600
-                    'action' => 'default',
1601
-                    'EVT_ID' => $event_id,
1602
-                    'page'   => 'espresso_transactions',
1603
-                ),
1604
-                admin_url('admin.php')
1605
-            );
1606
-            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1607
-                array(
1608
-                    'page'   => 'espresso_events',
1609
-                    'action' => 'edit',
1610
-                    'post'   => $event_id,
1611
-                ),
1612
-                admin_url('admin.php')
1613
-            );
1614
-            // next and previous links
1615
-            $next_reg = $this->_registration->next(
1616
-                null,
1617
-                array(),
1618
-                'REG_ID'
1619
-            );
1620
-            $this->_template_args['next_registration'] = $next_reg
1621
-                ? $this->_next_link(
1622
-                    EE_Admin_Page::add_query_args_and_nonce(
1623
-                        array(
1624
-                            'action'  => 'view_registration',
1625
-                            '_REG_ID' => $next_reg['REG_ID'],
1626
-                        ),
1627
-                        REG_ADMIN_URL
1628
-                    ),
1629
-                    'dashicons dashicons-arrow-right ee-icon-size-22'
1630
-                )
1631
-                : '';
1632
-            $previous_reg = $this->_registration->previous(
1633
-                null,
1634
-                array(),
1635
-                'REG_ID'
1636
-            );
1637
-            $this->_template_args['previous_registration'] = $previous_reg
1638
-                ? $this->_previous_link(
1639
-                    EE_Admin_Page::add_query_args_and_nonce(
1640
-                        array(
1641
-                            'action'  => 'view_registration',
1642
-                            '_REG_ID' => $previous_reg['REG_ID'],
1643
-                        ),
1644
-                        REG_ADMIN_URL
1645
-                    ),
1646
-                    'dashicons dashicons-arrow-left ee-icon-size-22'
1647
-                )
1648
-                : '';
1649
-            // grab header
1650
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1651
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
1652
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1653
-                $template_path,
1654
-                $this->_template_args,
1655
-                true
1656
-            );
1657
-        } else {
1658
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1659
-        }
1660
-        // the details template wrapper
1661
-        $this->display_admin_page_with_sidebar();
1662
-    }
1663
-
1664
-
1665
-    protected function _registration_details_metaboxes()
1666
-    {
1667
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1668
-        $this->_set_registration_object();
1669
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1670
-        add_meta_box(
1671
-            'edit-reg-status-mbox',
1672
-            esc_html__('Registration Status', 'event_espresso'),
1673
-            array($this, 'set_reg_status_buttons_metabox'),
1674
-            $this->wp_page_slug,
1675
-            'normal',
1676
-            'high'
1677
-        );
1678
-        add_meta_box(
1679
-            'edit-reg-details-mbox',
1680
-            esc_html__('Registration Details', 'event_espresso'),
1681
-            array($this, '_reg_details_meta_box'),
1682
-            $this->wp_page_slug,
1683
-            'normal',
1684
-            'high'
1685
-        );
1686
-        if ($attendee instanceof EE_Attendee
1687
-            && EE_Registry::instance()->CAP->current_user_can(
1688
-                'ee_read_registration',
1689
-                'edit-reg-questions-mbox',
1690
-                $this->_registration->ID()
1691
-            )
1692
-        ) {
1693
-            add_meta_box(
1694
-                'edit-reg-questions-mbox',
1695
-                esc_html__('Registration Form Answers', 'event_espresso'),
1696
-                array($this, '_reg_questions_meta_box'),
1697
-                $this->wp_page_slug,
1698
-                'normal',
1699
-                'high'
1700
-            );
1701
-        }
1702
-        add_meta_box(
1703
-            'edit-reg-registrant-mbox',
1704
-            esc_html__('Contact Details', 'event_espresso'),
1705
-            array($this, '_reg_registrant_side_meta_box'),
1706
-            $this->wp_page_slug,
1707
-            'side',
1708
-            'high'
1709
-        );
1710
-        if ($this->_registration->group_size() > 1) {
1711
-            add_meta_box(
1712
-                'edit-reg-attendees-mbox',
1713
-                esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1714
-                array($this, '_reg_attendees_meta_box'),
1715
-                $this->wp_page_slug,
1716
-                'normal',
1717
-                'high'
1718
-            );
1719
-        }
1720
-    }
1721
-
1722
-
1723
-    /**
1724
-     * set_reg_status_buttons_metabox
1725
-     *
1726
-     * @access protected
1727
-     * @return string
1728
-     * @throws \EE_Error
1729
-     */
1730
-    public function set_reg_status_buttons_metabox()
1731
-    {
1732
-        $this->_set_registration_object();
1733
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1734
-        echo $change_reg_status_form->form_open(
1735
-            self::add_query_args_and_nonce(
1736
-                array(
1737
-                    'action' => 'change_reg_status',
1738
-                ),
1739
-                REG_ADMIN_URL
1740
-            )
1741
-        );
1742
-        echo $change_reg_status_form->get_html();
1743
-        echo $change_reg_status_form->form_close();
1744
-    }
1745
-
1746
-
1747
-    /**
1748
-     * @return EE_Form_Section_Proper
1749
-     * @throws EE_Error
1750
-     * @throws InvalidArgumentException
1751
-     * @throws InvalidDataTypeException
1752
-     * @throws InvalidInterfaceException
1753
-     * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1754
-     */
1755
-    protected function _generate_reg_status_change_form()
1756
-    {
1757
-        $reg_status_change_form_array = array(
1758
-            'name'            => 'reg_status_change_form',
1759
-            'html_id'         => 'reg-status-change-form',
1760
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1761
-            'subsections'     => array(
1762
-                'return'             => new EE_Hidden_Input(
1763
-                    array(
1764
-                        'name'    => 'return',
1765
-                        'default' => 'view_registration',
1766
-                    )
1767
-                ),
1768
-                'REG_ID'             => new EE_Hidden_Input(
1769
-                    array(
1770
-                        'name'    => 'REG_ID',
1771
-                        'default' => $this->_registration->ID(),
1772
-                    )
1773
-                ),
1774
-                'current_status'     => new EE_Form_Section_HTML(
1775
-                    EEH_HTML::tr(
1776
-                        EEH_HTML::th(
1777
-                            EEH_HTML::label(
1778
-                                EEH_HTML::strong(
1779
-                                    esc_html__('Current Registration Status', 'event_espresso')
1780
-                                )
1781
-                            )
1782
-                        )
1783
-                        . EEH_HTML::td(
1784
-                            EEH_HTML::strong(
1785
-                                $this->_registration->pretty_status(),
1786
-                                '',
1787
-                                'status-' . $this->_registration->status_ID(),
1788
-                                'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1789
-                            )
1790
-                        )
1791
-                    )
1792
-                )
1793
-            )
1794
-        );
1795
-        if (EE_Registry::instance()->CAP->current_user_can(
1796
-            'ee_edit_registration',
1797
-            'toggle_registration_status',
1798
-            $this->_registration->ID()
1799
-        )) {
1800
-            $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1801
-                $this->_get_reg_statuses(),
1802
-                array(
1803
-                    'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1804
-                    'default'         => $this->_registration->status_ID(),
1805
-                )
1806
-            );
1807
-            $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1808
-                array(
1809
-                    'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1810
-                    'default'         => false,
1811
-                    'html_help_text'  => esc_html__(
1812
-                        'If set to "Yes", then the related messages will be sent to the registrant.',
1813
-                        'event_espresso'
1814
-                    )
1815
-                )
1816
-            );
1817
-            $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1818
-                array(
1819
-                    'html_class'      => 'button-primary',
1820
-                    'html_label_text' => '&nbsp;',
1821
-                    'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1822
-                )
1823
-            );
1824
-        }
1825
-        return new EE_Form_Section_Proper($reg_status_change_form_array);
1826
-    }
1827
-
1828
-
1829
-    /**
1830
-     * Returns an array of all the buttons for the various statuses and switch status actions
1831
-     *
1832
-     * @return array
1833
-     * @throws EE_Error
1834
-     * @throws InvalidArgumentException
1835
-     * @throws InvalidDataTypeException
1836
-     * @throws InvalidInterfaceException
1837
-     * @throws EntityNotFoundException
1838
-     */
1839
-    protected function _get_reg_statuses()
1840
-    {
1841
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1842
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1843
-        // get current reg status
1844
-        $current_status = $this->_registration->status_ID();
1845
-        // is registration for free event? This will determine whether to display the pending payment option
1846
-        if ($current_status !== EEM_Registration::status_id_pending_payment
1847
-            && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1848
-        ) {
1849
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1850
-        }
1851
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1852
-    }
1853
-
1854
-
1855
-    /**
1856
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1857
-     *
1858
-     * @param bool $status REG status given for changing registrations to.
1859
-     * @param bool $notify Whether to send messages notifications or not.
1860
-     * @return array (array with reg_id(s) updated and whether update was successful.
1861
-     * @throws EE_Error
1862
-     * @throws InvalidArgumentException
1863
-     * @throws InvalidDataTypeException
1864
-     * @throws InvalidInterfaceException
1865
-     * @throws ReflectionException
1866
-     * @throws RuntimeException
1867
-     * @throws EntityNotFoundException
1868
-     */
1869
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1870
-    {
1871
-        if (isset($this->_req_data['reg_status_change_form'])) {
1872
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1873
-                ? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1874
-                : array();
1875
-        } else {
1876
-            $REG_IDs = isset($this->_req_data['_REG_ID'])
1877
-                ? (array) $this->_req_data['_REG_ID']
1878
-                : array();
1879
-        }
1880
-        // sanitize $REG_IDs
1881
-        $REG_IDs = array_map('absint', $REG_IDs);
1882
-        // and remove empty entries
1883
-        $REG_IDs = array_filter($REG_IDs);
1884
-
1885
-        $result = $this->_set_registration_status($REG_IDs, $status, $notify);
1886
-
1887
-        /**
1888
-         * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1889
-         * Currently this value is used downstream by the _process_resend_registration method.
1890
-         *
1891
-         * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1892
-         * @param bool                     $status           The status registrations were changed to.
1893
-         * @param bool                     $success          If the status was changed successfully for all registrations.
1894
-         * @param Registrations_Admin_Page $admin_page_object
1895
-         */
1896
-        $this->_req_data['_REG_ID'] = apply_filters(
1897
-            'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1898
-            $result['REG_ID'],
1899
-            $status,
1900
-            $result['success'],
1901
-            $this
1902
-        );
1903
-
1904
-        // notify?
1905
-        if ($notify
1906
-            && $result['success']
1907
-            && ! empty($this->_req_data['_REG_ID'])
1908
-            && EE_Registry::instance()->CAP->current_user_can(
1909
-                'ee_send_message',
1910
-                'espresso_registrations_resend_registration'
1911
-            )
1912
-        ) {
1913
-            $this->_process_resend_registration();
1914
-        }
1915
-        return $result;
1916
-    }
1917
-
1918
-
1919
-    /**
1920
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1921
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1922
-     *
1923
-     * @param array  $REG_IDs
1924
-     * @param string $status
1925
-     * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1926
-     *                        slug sent with setting the registration status.
1927
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1928
-     * @throws EE_Error
1929
-     * @throws InvalidArgumentException
1930
-     * @throws InvalidDataTypeException
1931
-     * @throws InvalidInterfaceException
1932
-     * @throws ReflectionException
1933
-     * @throws RuntimeException
1934
-     * @throws EntityNotFoundException
1935
-     */
1936
-    protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1937
-    {
1938
-        $success = false;
1939
-        // typecast $REG_IDs
1940
-        $REG_IDs = (array) $REG_IDs;
1941
-        if (! empty($REG_IDs)) {
1942
-            $success = true;
1943
-            // set default status if none is passed
1944
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1945
-            $status_context = $notify
1946
-                ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1947
-                : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1948
-            // loop through REG_ID's and change status
1949
-            foreach ($REG_IDs as $REG_ID) {
1950
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1951
-                if ($registration instanceof EE_Registration) {
1952
-                    $registration->set_status(
1953
-                        $status,
1954
-                        false,
1955
-                        new Context(
1956
-                            $status_context,
1957
-                            esc_html__(
1958
-                                'Manually triggered status change on a Registration Admin Page route.',
1959
-                                'event_espresso'
1960
-                            )
1961
-                        )
1962
-                    );
1963
-                    $result = $registration->save();
1964
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1965
-                    $success = $result !== false ? $success : false;
1966
-                }
1967
-            }
1968
-        }
1969
-
1970
-        // return $success and processed registrations
1971
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1972
-    }
1973
-
1974
-
1975
-    /**
1976
-     * Common logic for setting up success message and redirecting to appropriate route
1977
-     *
1978
-     * @param  string $STS_ID status id for the registration changed to
1979
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1980
-     * @return void
1981
-     * @throws EE_Error
1982
-     */
1983
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1984
-    {
1985
-        $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1986
-            : array('success' => false);
1987
-        $success = isset($result['success']) && $result['success'];
1988
-        // setup success message
1989
-        if ($success) {
1990
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1991
-                $msg = sprintf(
1992
-                    esc_html__('Registration status has been set to %s', 'event_espresso'),
1993
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1994
-                );
1995
-            } else {
1996
-                $msg = sprintf(
1997
-                    esc_html__('Registrations have been set to %s.', 'event_espresso'),
1998
-                    EEH_Template::pretty_status($STS_ID, false, 'lower')
1999
-                );
2000
-            }
2001
-            EE_Error::add_success($msg);
2002
-        } else {
2003
-            EE_Error::add_error(
2004
-                esc_html__(
2005
-                    'Something went wrong, and the status was not changed',
2006
-                    'event_espresso'
2007
-                ),
2008
-                __FILE__,
2009
-                __LINE__,
2010
-                __FUNCTION__
2011
-            );
2012
-        }
2013
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
2014
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
2015
-        } else {
2016
-            $route = array('action' => 'default');
2017
-        }
2018
-        // unset nonces
2019
-        foreach ($this->_req_data as $ref => $value) {
2020
-            if (strpos($ref, 'nonce') !== false) {
2021
-                unset($this->_req_data[ $ref ]);
2022
-                continue;
2023
-            }
2024
-            $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
2025
-            $this->_req_data[ $ref ] = $value;
2026
-        }
2027
-        // merge request vars so that the reloaded list table contains any existing filter query params
2028
-        $route = array_merge($this->_req_data, $route);
2029
-        $this->_redirect_after_action($success, '', '', $route, true);
2030
-    }
2031
-
2032
-
2033
-    /**
2034
-     * incoming reg status change from reg details page.
2035
-     *
2036
-     * @return void
2037
-     */
2038
-    protected function _change_reg_status()
2039
-    {
2040
-        $this->_req_data['return'] = 'view_registration';
2041
-        // set notify based on whether the send notifications toggle is set or not
2042
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
2043
-        // $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
2044
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
2045
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
2046
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
2047
-            case EEM_Registration::status_id_approved:
2048
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
2049
-                $this->approve_registration($notify);
2050
-                break;
2051
-            case EEM_Registration::status_id_pending_payment:
2052
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
2053
-                $this->pending_registration($notify);
2054
-                break;
2055
-            case EEM_Registration::status_id_not_approved:
2056
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
2057
-                $this->not_approve_registration($notify);
2058
-                break;
2059
-            case EEM_Registration::status_id_declined:
2060
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
2061
-                $this->decline_registration($notify);
2062
-                break;
2063
-            case EEM_Registration::status_id_cancelled:
2064
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
2065
-                $this->cancel_registration($notify);
2066
-                break;
2067
-            case EEM_Registration::status_id_wait_list:
2068
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
2069
-                $this->wait_list_registration($notify);
2070
-                break;
2071
-            case EEM_Registration::status_id_incomplete:
2072
-            default:
2073
-                $result['success'] = false;
2074
-                unset($this->_req_data['return']);
2075
-                $this->_reg_status_change_return('', false);
2076
-                break;
2077
-        }
2078
-    }
2079
-
2080
-
2081
-    /**
2082
-     * Callback for bulk action routes.
2083
-     * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2084
-     * method was chosen so there is one central place all the registration status bulk actions are going through.
2085
-     * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2086
-     * when an action is happening on just a single registration).
2087
-     *
2088
-     * @param      $action
2089
-     * @param bool $notify
2090
-     */
2091
-    protected function bulk_action_on_registrations($action, $notify = false)
2092
-    {
2093
-        do_action(
2094
-            'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2095
-            $this,
2096
-            $action,
2097
-            $notify
2098
-        );
2099
-        $method = $action . '_registration';
2100
-        if (method_exists($this, $method)) {
2101
-            $this->$method($notify);
2102
-        }
2103
-    }
2104
-
2105
-
2106
-    /**
2107
-     * approve_registration
2108
-     *
2109
-     * @access protected
2110
-     * @param bool $notify whether or not to notify the registrant about their approval.
2111
-     * @return void
2112
-     */
2113
-    protected function approve_registration($notify = false)
2114
-    {
2115
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2116
-    }
2117
-
2118
-
2119
-    /**
2120
-     *        decline_registration
2121
-     *
2122
-     * @access protected
2123
-     * @param bool $notify whether or not to notify the registrant about their status change.
2124
-     * @return void
2125
-     */
2126
-    protected function decline_registration($notify = false)
2127
-    {
2128
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2129
-    }
2130
-
2131
-
2132
-    /**
2133
-     *        cancel_registration
2134
-     *
2135
-     * @access protected
2136
-     * @param bool $notify whether or not to notify the registrant about their status change.
2137
-     * @return void
2138
-     */
2139
-    protected function cancel_registration($notify = false)
2140
-    {
2141
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2142
-    }
2143
-
2144
-
2145
-    /**
2146
-     *        not_approve_registration
2147
-     *
2148
-     * @access protected
2149
-     * @param bool $notify whether or not to notify the registrant about their status change.
2150
-     * @return void
2151
-     */
2152
-    protected function not_approve_registration($notify = false)
2153
-    {
2154
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2155
-    }
2156
-
2157
-
2158
-    /**
2159
-     *        decline_registration
2160
-     *
2161
-     * @access protected
2162
-     * @param bool $notify whether or not to notify the registrant about their status change.
2163
-     * @return void
2164
-     */
2165
-    protected function pending_registration($notify = false)
2166
-    {
2167
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2168
-    }
2169
-
2170
-
2171
-    /**
2172
-     * waitlist_registration
2173
-     *
2174
-     * @access protected
2175
-     * @param bool $notify whether or not to notify the registrant about their status change.
2176
-     * @return void
2177
-     */
2178
-    protected function wait_list_registration($notify = false)
2179
-    {
2180
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2181
-    }
2182
-
2183
-
2184
-    /**
2185
-     *        generates HTML for the Registration main meta box
2186
-     *
2187
-     * @access public
2188
-     * @return void
2189
-     * @throws DomainException
2190
-     * @throws EE_Error
2191
-     * @throws InvalidArgumentException
2192
-     * @throws InvalidDataTypeException
2193
-     * @throws InvalidInterfaceException
2194
-     * @throws ReflectionException
2195
-     * @throws EntityNotFoundException
2196
-     */
2197
-    public function _reg_details_meta_box()
2198
-    {
2199
-        EEH_Autoloader::register_line_item_display_autoloaders();
2200
-        EEH_Autoloader::register_line_item_filter_autoloaders();
2201
-        EE_Registry::instance()->load_helper('Line_Item');
2202
-        $transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2203
-            : EE_Transaction::new_instance();
2204
-        $this->_session = $transaction->session_data();
2205
-        $filters = new EE_Line_Item_Filter_Collection();
2206
-        // $filters->add( new EE_Non_Zero_Line_Item_Filter() );
2207
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2208
-        $line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2209
-            $filters,
2210
-            $transaction->total_line_item()
2211
-        );
2212
-        $filtered_line_item_tree = $line_item_filter_processor->process();
2213
-        $line_item_display = new EE_Line_Item_Display(
2214
-            'reg_admin_table',
2215
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2216
-        );
2217
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2218
-            $filtered_line_item_tree,
2219
-            array('EE_Registration' => $this->_registration)
2220
-        );
2221
-        $attendee = $this->_registration->attendee();
2222
-        if (EE_Registry::instance()->CAP->current_user_can(
2223
-            'ee_read_transaction',
2224
-            'espresso_transactions_view_transaction'
2225
-        )) {
2226
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2227
-                EE_Admin_Page::add_query_args_and_nonce(
2228
-                    array(
2229
-                        'action' => 'view_transaction',
2230
-                        'TXN_ID' => $transaction->ID(),
2231
-                    ),
2232
-                    TXN_ADMIN_URL
2233
-                ),
2234
-                esc_html__(' View Transaction', 'event_espresso'),
2235
-                'button secondary-button right',
2236
-                'dashicons dashicons-cart'
2237
-            );
2238
-        } else {
2239
-            $this->_template_args['view_transaction_button'] = '';
2240
-        }
2241
-        if ($attendee instanceof EE_Attendee
2242
-            && EE_Registry::instance()->CAP->current_user_can(
2243
-                'ee_send_message',
2244
-                'espresso_registrations_resend_registration'
2245
-            )
2246
-        ) {
2247
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2248
-                EE_Admin_Page::add_query_args_and_nonce(
2249
-                    array(
2250
-                        'action'      => 'resend_registration',
2251
-                        '_REG_ID'     => $this->_registration->ID(),
2252
-                        'redirect_to' => 'view_registration',
2253
-                    ),
2254
-                    REG_ADMIN_URL
2255
-                ),
2256
-                esc_html__(' Resend Registration', 'event_espresso'),
2257
-                'button secondary-button right',
2258
-                'dashicons dashicons-email-alt'
2259
-            );
2260
-        } else {
2261
-            $this->_template_args['resend_registration_button'] = '';
2262
-        }
2263
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2264
-        $payment = $transaction->get_first_related('Payment');
2265
-        $payment = ! $payment instanceof EE_Payment
2266
-            ? EE_Payment::new_instance()
2267
-            : $payment;
2268
-        $payment_method = $payment->get_first_related('Payment_Method');
2269
-        $payment_method = ! $payment_method instanceof EE_Payment_Method
2270
-            ? EE_Payment_Method::new_instance()
2271
-            : $payment_method;
2272
-        $reg_details = array(
2273
-            'payment_method'       => $payment_method->name(),
2274
-            'response_msg'         => $payment->gateway_response(),
2275
-            'registration_id'      => $this->_registration->get('REG_code'),
2276
-            'registration_session' => $this->_registration->session_ID(),
2277
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2278
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2279
-        );
2280
-        if (isset($reg_details['registration_id'])) {
2281
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2282
-            $this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2283
-                'Registration ID',
2284
-                'event_espresso'
2285
-            );
2286
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2287
-        }
2288
-        if (isset($reg_details['payment_method'])) {
2289
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2290
-            $this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2291
-                'Most Recent Payment Method',
2292
-                'event_espresso'
2293
-            );
2294
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2295
-            $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2296
-            $this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2297
-                'Payment method response',
2298
-                'event_espresso'
2299
-            );
2300
-            $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2301
-        }
2302
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2303
-        $this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2304
-            'Registration Session',
2305
-            'event_espresso'
2306
-        );
2307
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2308
-        $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2309
-        $this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2310
-            'Registration placed from IP',
2311
-            'event_espresso'
2312
-        );
2313
-        $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2314
-        $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2315
-        $this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2316
-            'Registrant User Agent',
2317
-            'event_espresso'
2318
-        );
2319
-        $this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2320
-        $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2321
-            array(
2322
-                'action'   => 'default',
2323
-                'event_id' => $this->_registration->event_ID(),
2324
-            ),
2325
-            REG_ADMIN_URL
2326
-        );
2327
-        $this->_template_args['REG_ID'] = $this->_registration->ID();
2328
-        $this->_template_args['event_id'] = $this->_registration->event_ID();
2329
-        $template_path =
2330
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2331
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2332
-    }
2333
-
2334
-
2335
-    /**
2336
-     * generates HTML for the Registration Questions meta box.
2337
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2338
-     * otherwise uses new forms system
2339
-     *
2340
-     * @access public
2341
-     * @return void
2342
-     * @throws DomainException
2343
-     * @throws EE_Error
2344
-     */
2345
-    public function _reg_questions_meta_box()
2346
-    {
2347
-        // allow someone to override this method entirely
2348
-        if (apply_filters(
2349
-            'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2350
-            true,
2351
-            $this,
2352
-            $this->_registration
2353
-        )) {
2354
-            $form = $this->_get_reg_custom_questions_form(
2355
-                $this->_registration->ID()
2356
-            );
2357
-            $this->_template_args['att_questions'] = count($form->subforms()) > 0
2358
-                ? $form->get_html_and_js()
2359
-                : '';
2360
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2361
-            $this->_template_args['REG_ID'] = $this->_registration->ID();
2362
-            $template_path =
2363
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2364
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
2365
-        }
2366
-    }
2367
-
2368
-
2369
-    /**
2370
-     * form_before_question_group
2371
-     *
2372
-     * @deprecated    as of 4.8.32.rc.000
2373
-     * @access        public
2374
-     * @param        string $output
2375
-     * @return        string
2376
-     */
2377
-    public function form_before_question_group($output)
2378
-    {
2379
-        EE_Error::doing_it_wrong(
2380
-            __CLASS__ . '::' . __FUNCTION__,
2381
-            esc_html__(
2382
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2383
-                'event_espresso'
2384
-            ),
2385
-            '4.8.32.rc.000'
2386
-        );
2387
-        return '
1301
+		if (! empty($registration_status)) {
1302
+			$where['STS_ID'] = $registration_status;
1303
+		} else {
1304
+			// make sure we exclude incomplete registrations, but only if not trashed.
1305
+			if ($view === 'trash') {
1306
+				$where['REG_deleted'] = true;
1307
+			} elseif ($view === 'incomplete') {
1308
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1309
+			} else {
1310
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1311
+			}
1312
+		}
1313
+		return $where;
1314
+	}
1315
+
1316
+
1317
+	/**
1318
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1319
+	 *
1320
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1321
+	 * @return array
1322
+	 * @throws EE_Error
1323
+	 * @throws InvalidArgumentException
1324
+	 * @throws InvalidDataTypeException
1325
+	 * @throws InvalidInterfaceException
1326
+	 */
1327
+	protected function _add_date_to_where_conditions(array $request)
1328
+	{
1329
+		$where = array();
1330
+		$view = EEH_Array::is_set($request, 'status', '');
1331
+		$month_range = ! empty($request['month_range'])
1332
+			? sanitize_text_field($request['month_range'])
1333
+			: '';
1334
+		$retrieve_for_today = $view === 'today';
1335
+		$retrieve_for_this_month = $view === 'month';
1336
+
1337
+		if ($retrieve_for_today) {
1338
+			$now = date('Y-m-d', current_time('timestamp'));
1339
+			$where['REG_date'] = array(
1340
+				'BETWEEN',
1341
+				array(
1342
+					EEM_Registration::instance()->convert_datetime_for_query(
1343
+						'REG_date',
1344
+						$now . ' 00:00:00',
1345
+						'Y-m-d H:i:s'
1346
+					),
1347
+					EEM_Registration::instance()->convert_datetime_for_query(
1348
+						'REG_date',
1349
+						$now . ' 23:59:59',
1350
+						'Y-m-d H:i:s'
1351
+					),
1352
+				),
1353
+			);
1354
+		} elseif ($retrieve_for_this_month) {
1355
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1356
+			$days_this_month = date('t', current_time('timestamp'));
1357
+			$where['REG_date'] = array(
1358
+				'BETWEEN',
1359
+				array(
1360
+					EEM_Registration::instance()->convert_datetime_for_query(
1361
+						'REG_date',
1362
+						$current_year_and_month . '-01 00:00:00',
1363
+						'Y-m-d H:i:s'
1364
+					),
1365
+					EEM_Registration::instance()->convert_datetime_for_query(
1366
+						'REG_date',
1367
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1368
+						'Y-m-d H:i:s'
1369
+					),
1370
+				),
1371
+			);
1372
+		} elseif ($month_range) {
1373
+			$pieces = explode(' ', $month_range, 3);
1374
+			$month_requested = ! empty($pieces[0])
1375
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1376
+				: '';
1377
+			$year_requested = ! empty($pieces[1])
1378
+				? $pieces[1]
1379
+				: '';
1380
+			// if there is not a month or year then we can't go further
1381
+			if ($month_requested && $year_requested) {
1382
+				$days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1383
+				$where['REG_date'] = array(
1384
+					'BETWEEN',
1385
+					array(
1386
+						EEM_Registration::instance()->convert_datetime_for_query(
1387
+							'REG_date',
1388
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1389
+							'Y-m-d H:i:s'
1390
+						),
1391
+						EEM_Registration::instance()->convert_datetime_for_query(
1392
+							'REG_date',
1393
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1394
+							'Y-m-d H:i:s'
1395
+						),
1396
+					),
1397
+				);
1398
+			}
1399
+		}
1400
+		return $where;
1401
+	}
1402
+
1403
+
1404
+	/**
1405
+	 * Adds any provided search restraints to the where conditions for the registrations query
1406
+	 *
1407
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1408
+	 * @return array
1409
+	 */
1410
+	protected function _add_search_to_where_conditions(array $request)
1411
+	{
1412
+		$where = array();
1413
+		if (! empty($request['s'])) {
1414
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1415
+			$where['OR*search_conditions'] = array(
1416
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1417
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1418
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1419
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1420
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1421
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1422
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1423
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1424
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1425
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1426
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1427
+				'REG_final_price'                         => array('LIKE', $search_string),
1428
+				'REG_code'                                => array('LIKE', $search_string),
1429
+				'REG_count'                               => array('LIKE', $search_string),
1430
+				'REG_group_size'                          => array('LIKE', $search_string),
1431
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1432
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1433
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1434
+			);
1435
+		}
1436
+		return $where;
1437
+	}
1438
+
1439
+
1440
+	/**
1441
+	 * Sets up the where conditions for the registrations query.
1442
+	 *
1443
+	 * @param array $request
1444
+	 * @return array
1445
+	 * @throws EE_Error
1446
+	 */
1447
+	protected function _get_where_conditions_for_registrations_query($request)
1448
+	{
1449
+		return apply_filters(
1450
+			'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query',
1451
+			array_merge(
1452
+				$this->addAttendeeIdToWhereConditions($request),
1453
+				$this->_add_event_id_to_where_conditions($request),
1454
+				$this->_add_category_id_to_where_conditions($request),
1455
+				$this->_add_datetime_id_to_where_conditions($request),
1456
+				$this->_add_registration_status_to_where_conditions($request),
1457
+				$this->_add_date_to_where_conditions($request),
1458
+				$this->_add_search_to_where_conditions($request)
1459
+			),
1460
+			$request
1461
+		);
1462
+	}
1463
+
1464
+
1465
+	/**
1466
+	 * Sets up the orderby for the registrations query.
1467
+	 *
1468
+	 * @return array
1469
+	 */
1470
+	protected function _get_orderby_for_registrations_query()
1471
+	{
1472
+		$orderby_field = ! empty($this->_req_data['orderby'])
1473
+			? sanitize_text_field($this->_req_data['orderby'])
1474
+			: '_REG_date';
1475
+		switch ($orderby_field) {
1476
+			case '_REG_ID':
1477
+				$orderby = array('REG_ID');
1478
+				break;
1479
+			case '_Reg_status':
1480
+				$orderby = array('STS_ID');
1481
+				break;
1482
+			case 'ATT_fname':
1483
+				$orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname');
1484
+				break;
1485
+			case 'ATT_lname':
1486
+				$orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname');
1487
+				break;
1488
+			case 'event_name':
1489
+				$orderby = array('Event.EVT_name');
1490
+				break;
1491
+			case 'DTT_EVT_start':
1492
+				$orderby = array('Event.Datetime.DTT_EVT_start');
1493
+				break;
1494
+			case '_REG_date':
1495
+				$orderby = array('REG_date');
1496
+				break;
1497
+			default:
1498
+				$orderby = array($orderby_field);
1499
+				break;
1500
+		}
1501
+
1502
+		// order
1503
+		$order = ! empty($this->_req_data['order'])
1504
+			? sanitize_text_field($this->_req_data['order'])
1505
+			: 'DESC';
1506
+		$orderby = array_combine(
1507
+			$orderby,
1508
+			array_fill(0, count($orderby), $order)
1509
+		);
1510
+		// because there are many registrations with the same date, define
1511
+		// a secondary way to order them, otherwise MySQL seems to be a bit random
1512
+		if (empty($orderby['REG_ID'])) {
1513
+			$orderby['REG_ID'] = $order;
1514
+		}
1515
+
1516
+		$orderby = apply_filters(
1517
+			'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query',
1518
+			$orderby,
1519
+			$this->_req_data
1520
+		);
1521
+
1522
+		return array('order_by' => $orderby);
1523
+	}
1524
+
1525
+
1526
+	/**
1527
+	 * Sets up the limit for the registrations query.
1528
+	 *
1529
+	 * @param $per_page
1530
+	 * @return array
1531
+	 */
1532
+	protected function _get_limit($per_page)
1533
+	{
1534
+		$current_page = ! empty($this->_req_data['paged'])
1535
+			? absint($this->_req_data['paged'])
1536
+			: 1;
1537
+		$per_page = ! empty($this->_req_data['perpage'])
1538
+			? $this->_req_data['perpage']
1539
+			: $per_page;
1540
+
1541
+		// -1 means return all results so get out if that's set.
1542
+		if ((int) $per_page === -1) {
1543
+			return array();
1544
+		}
1545
+		$per_page = absint($per_page);
1546
+		$offset = ($current_page - 1) * $per_page;
1547
+		return array('limit' => array($offset, $per_page));
1548
+	}
1549
+
1550
+
1551
+	public function get_registration_status_array()
1552
+	{
1553
+		return self::$_reg_status;
1554
+	}
1555
+
1556
+
1557
+
1558
+
1559
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1560
+	/**
1561
+	 *        generates HTML for the View Registration Details Admin page
1562
+	 *
1563
+	 * @access protected
1564
+	 * @return void
1565
+	 * @throws DomainException
1566
+	 * @throws EE_Error
1567
+	 * @throws InvalidArgumentException
1568
+	 * @throws InvalidDataTypeException
1569
+	 * @throws InvalidInterfaceException
1570
+	 * @throws EntityNotFoundException
1571
+	 */
1572
+	protected function _registration_details()
1573
+	{
1574
+		$this->_template_args = array();
1575
+		$this->_set_registration_object();
1576
+		if (is_object($this->_registration)) {
1577
+			$transaction = $this->_registration->transaction()
1578
+				? $this->_registration->transaction()
1579
+				: EE_Transaction::new_instance();
1580
+			$this->_session = $transaction->session_data();
1581
+			$event_id = $this->_registration->event_ID();
1582
+			$this->_template_args['reg_nmbr']['value'] = $this->_registration->ID();
1583
+			$this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso');
1584
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1585
+			$this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso');
1586
+			$this->_template_args['grand_total'] = $transaction->total();
1587
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1588
+			// link back to overview
1589
+			$this->_template_args['reg_overview_url'] = REG_ADMIN_URL;
1590
+			$this->_template_args['registration'] = $this->_registration;
1591
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(
1592
+				array(
1593
+					'action'   => 'default',
1594
+					'event_id' => $event_id,
1595
+				),
1596
+				REG_ADMIN_URL
1597
+			);
1598
+			$this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(
1599
+				array(
1600
+					'action' => 'default',
1601
+					'EVT_ID' => $event_id,
1602
+					'page'   => 'espresso_transactions',
1603
+				),
1604
+				admin_url('admin.php')
1605
+			);
1606
+			$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
1607
+				array(
1608
+					'page'   => 'espresso_events',
1609
+					'action' => 'edit',
1610
+					'post'   => $event_id,
1611
+				),
1612
+				admin_url('admin.php')
1613
+			);
1614
+			// next and previous links
1615
+			$next_reg = $this->_registration->next(
1616
+				null,
1617
+				array(),
1618
+				'REG_ID'
1619
+			);
1620
+			$this->_template_args['next_registration'] = $next_reg
1621
+				? $this->_next_link(
1622
+					EE_Admin_Page::add_query_args_and_nonce(
1623
+						array(
1624
+							'action'  => 'view_registration',
1625
+							'_REG_ID' => $next_reg['REG_ID'],
1626
+						),
1627
+						REG_ADMIN_URL
1628
+					),
1629
+					'dashicons dashicons-arrow-right ee-icon-size-22'
1630
+				)
1631
+				: '';
1632
+			$previous_reg = $this->_registration->previous(
1633
+				null,
1634
+				array(),
1635
+				'REG_ID'
1636
+			);
1637
+			$this->_template_args['previous_registration'] = $previous_reg
1638
+				? $this->_previous_link(
1639
+					EE_Admin_Page::add_query_args_and_nonce(
1640
+						array(
1641
+							'action'  => 'view_registration',
1642
+							'_REG_ID' => $previous_reg['REG_ID'],
1643
+						),
1644
+						REG_ADMIN_URL
1645
+					),
1646
+					'dashicons dashicons-arrow-left ee-icon-size-22'
1647
+				)
1648
+				: '';
1649
+			// grab header
1650
+			$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1651
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
1652
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template(
1653
+				$template_path,
1654
+				$this->_template_args,
1655
+				true
1656
+			);
1657
+		} else {
1658
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1659
+		}
1660
+		// the details template wrapper
1661
+		$this->display_admin_page_with_sidebar();
1662
+	}
1663
+
1664
+
1665
+	protected function _registration_details_metaboxes()
1666
+	{
1667
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1668
+		$this->_set_registration_object();
1669
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1670
+		add_meta_box(
1671
+			'edit-reg-status-mbox',
1672
+			esc_html__('Registration Status', 'event_espresso'),
1673
+			array($this, 'set_reg_status_buttons_metabox'),
1674
+			$this->wp_page_slug,
1675
+			'normal',
1676
+			'high'
1677
+		);
1678
+		add_meta_box(
1679
+			'edit-reg-details-mbox',
1680
+			esc_html__('Registration Details', 'event_espresso'),
1681
+			array($this, '_reg_details_meta_box'),
1682
+			$this->wp_page_slug,
1683
+			'normal',
1684
+			'high'
1685
+		);
1686
+		if ($attendee instanceof EE_Attendee
1687
+			&& EE_Registry::instance()->CAP->current_user_can(
1688
+				'ee_read_registration',
1689
+				'edit-reg-questions-mbox',
1690
+				$this->_registration->ID()
1691
+			)
1692
+		) {
1693
+			add_meta_box(
1694
+				'edit-reg-questions-mbox',
1695
+				esc_html__('Registration Form Answers', 'event_espresso'),
1696
+				array($this, '_reg_questions_meta_box'),
1697
+				$this->wp_page_slug,
1698
+				'normal',
1699
+				'high'
1700
+			);
1701
+		}
1702
+		add_meta_box(
1703
+			'edit-reg-registrant-mbox',
1704
+			esc_html__('Contact Details', 'event_espresso'),
1705
+			array($this, '_reg_registrant_side_meta_box'),
1706
+			$this->wp_page_slug,
1707
+			'side',
1708
+			'high'
1709
+		);
1710
+		if ($this->_registration->group_size() > 1) {
1711
+			add_meta_box(
1712
+				'edit-reg-attendees-mbox',
1713
+				esc_html__('Other Registrations in this Transaction', 'event_espresso'),
1714
+				array($this, '_reg_attendees_meta_box'),
1715
+				$this->wp_page_slug,
1716
+				'normal',
1717
+				'high'
1718
+			);
1719
+		}
1720
+	}
1721
+
1722
+
1723
+	/**
1724
+	 * set_reg_status_buttons_metabox
1725
+	 *
1726
+	 * @access protected
1727
+	 * @return string
1728
+	 * @throws \EE_Error
1729
+	 */
1730
+	public function set_reg_status_buttons_metabox()
1731
+	{
1732
+		$this->_set_registration_object();
1733
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1734
+		echo $change_reg_status_form->form_open(
1735
+			self::add_query_args_and_nonce(
1736
+				array(
1737
+					'action' => 'change_reg_status',
1738
+				),
1739
+				REG_ADMIN_URL
1740
+			)
1741
+		);
1742
+		echo $change_reg_status_form->get_html();
1743
+		echo $change_reg_status_form->form_close();
1744
+	}
1745
+
1746
+
1747
+	/**
1748
+	 * @return EE_Form_Section_Proper
1749
+	 * @throws EE_Error
1750
+	 * @throws InvalidArgumentException
1751
+	 * @throws InvalidDataTypeException
1752
+	 * @throws InvalidInterfaceException
1753
+	 * @throws \EventEspresso\core\exceptions\EntityNotFoundException
1754
+	 */
1755
+	protected function _generate_reg_status_change_form()
1756
+	{
1757
+		$reg_status_change_form_array = array(
1758
+			'name'            => 'reg_status_change_form',
1759
+			'html_id'         => 'reg-status-change-form',
1760
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1761
+			'subsections'     => array(
1762
+				'return'             => new EE_Hidden_Input(
1763
+					array(
1764
+						'name'    => 'return',
1765
+						'default' => 'view_registration',
1766
+					)
1767
+				),
1768
+				'REG_ID'             => new EE_Hidden_Input(
1769
+					array(
1770
+						'name'    => 'REG_ID',
1771
+						'default' => $this->_registration->ID(),
1772
+					)
1773
+				),
1774
+				'current_status'     => new EE_Form_Section_HTML(
1775
+					EEH_HTML::tr(
1776
+						EEH_HTML::th(
1777
+							EEH_HTML::label(
1778
+								EEH_HTML::strong(
1779
+									esc_html__('Current Registration Status', 'event_espresso')
1780
+								)
1781
+							)
1782
+						)
1783
+						. EEH_HTML::td(
1784
+							EEH_HTML::strong(
1785
+								$this->_registration->pretty_status(),
1786
+								'',
1787
+								'status-' . $this->_registration->status_ID(),
1788
+								'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1789
+							)
1790
+						)
1791
+					)
1792
+				)
1793
+			)
1794
+		);
1795
+		if (EE_Registry::instance()->CAP->current_user_can(
1796
+			'ee_edit_registration',
1797
+			'toggle_registration_status',
1798
+			$this->_registration->ID()
1799
+		)) {
1800
+			$reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input(
1801
+				$this->_get_reg_statuses(),
1802
+				array(
1803
+					'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'),
1804
+					'default'         => $this->_registration->status_ID(),
1805
+				)
1806
+			);
1807
+			$reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input(
1808
+				array(
1809
+					'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'),
1810
+					'default'         => false,
1811
+					'html_help_text'  => esc_html__(
1812
+						'If set to "Yes", then the related messages will be sent to the registrant.',
1813
+						'event_espresso'
1814
+					)
1815
+				)
1816
+			);
1817
+			$reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input(
1818
+				array(
1819
+					'html_class'      => 'button-primary',
1820
+					'html_label_text' => '&nbsp;',
1821
+					'default'         => esc_html__('Update Registration Status', 'event_espresso'),
1822
+				)
1823
+			);
1824
+		}
1825
+		return new EE_Form_Section_Proper($reg_status_change_form_array);
1826
+	}
1827
+
1828
+
1829
+	/**
1830
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1831
+	 *
1832
+	 * @return array
1833
+	 * @throws EE_Error
1834
+	 * @throws InvalidArgumentException
1835
+	 * @throws InvalidDataTypeException
1836
+	 * @throws InvalidInterfaceException
1837
+	 * @throws EntityNotFoundException
1838
+	 */
1839
+	protected function _get_reg_statuses()
1840
+	{
1841
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1842
+		unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1843
+		// get current reg status
1844
+		$current_status = $this->_registration->status_ID();
1845
+		// is registration for free event? This will determine whether to display the pending payment option
1846
+		if ($current_status !== EEM_Registration::status_id_pending_payment
1847
+			&& EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1848
+		) {
1849
+			unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1850
+		}
1851
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1852
+	}
1853
+
1854
+
1855
+	/**
1856
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1857
+	 *
1858
+	 * @param bool $status REG status given for changing registrations to.
1859
+	 * @param bool $notify Whether to send messages notifications or not.
1860
+	 * @return array (array with reg_id(s) updated and whether update was successful.
1861
+	 * @throws EE_Error
1862
+	 * @throws InvalidArgumentException
1863
+	 * @throws InvalidDataTypeException
1864
+	 * @throws InvalidInterfaceException
1865
+	 * @throws ReflectionException
1866
+	 * @throws RuntimeException
1867
+	 * @throws EntityNotFoundException
1868
+	 */
1869
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1870
+	{
1871
+		if (isset($this->_req_data['reg_status_change_form'])) {
1872
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1873
+				? (array) $this->_req_data['reg_status_change_form']['REG_ID']
1874
+				: array();
1875
+		} else {
1876
+			$REG_IDs = isset($this->_req_data['_REG_ID'])
1877
+				? (array) $this->_req_data['_REG_ID']
1878
+				: array();
1879
+		}
1880
+		// sanitize $REG_IDs
1881
+		$REG_IDs = array_map('absint', $REG_IDs);
1882
+		// and remove empty entries
1883
+		$REG_IDs = array_filter($REG_IDs);
1884
+
1885
+		$result = $this->_set_registration_status($REG_IDs, $status, $notify);
1886
+
1887
+		/**
1888
+		 * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications.
1889
+		 * Currently this value is used downstream by the _process_resend_registration method.
1890
+		 *
1891
+		 * @param int|array                $registration_ids The registration ids that have had their status changed successfully.
1892
+		 * @param bool                     $status           The status registrations were changed to.
1893
+		 * @param bool                     $success          If the status was changed successfully for all registrations.
1894
+		 * @param Registrations_Admin_Page $admin_page_object
1895
+		 */
1896
+		$this->_req_data['_REG_ID'] = apply_filters(
1897
+			'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs',
1898
+			$result['REG_ID'],
1899
+			$status,
1900
+			$result['success'],
1901
+			$this
1902
+		);
1903
+
1904
+		// notify?
1905
+		if ($notify
1906
+			&& $result['success']
1907
+			&& ! empty($this->_req_data['_REG_ID'])
1908
+			&& EE_Registry::instance()->CAP->current_user_can(
1909
+				'ee_send_message',
1910
+				'espresso_registrations_resend_registration'
1911
+			)
1912
+		) {
1913
+			$this->_process_resend_registration();
1914
+		}
1915
+		return $result;
1916
+	}
1917
+
1918
+
1919
+	/**
1920
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1921
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1922
+	 *
1923
+	 * @param array  $REG_IDs
1924
+	 * @param string $status
1925
+	 * @param bool   $notify  Used to indicate whether notification was requested or not.  This determines the context
1926
+	 *                        slug sent with setting the registration status.
1927
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1928
+	 * @throws EE_Error
1929
+	 * @throws InvalidArgumentException
1930
+	 * @throws InvalidDataTypeException
1931
+	 * @throws InvalidInterfaceException
1932
+	 * @throws ReflectionException
1933
+	 * @throws RuntimeException
1934
+	 * @throws EntityNotFoundException
1935
+	 */
1936
+	protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false)
1937
+	{
1938
+		$success = false;
1939
+		// typecast $REG_IDs
1940
+		$REG_IDs = (array) $REG_IDs;
1941
+		if (! empty($REG_IDs)) {
1942
+			$success = true;
1943
+			// set default status if none is passed
1944
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1945
+			$status_context = $notify
1946
+				? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY
1947
+				: Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN;
1948
+			// loop through REG_ID's and change status
1949
+			foreach ($REG_IDs as $REG_ID) {
1950
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1951
+				if ($registration instanceof EE_Registration) {
1952
+					$registration->set_status(
1953
+						$status,
1954
+						false,
1955
+						new Context(
1956
+							$status_context,
1957
+							esc_html__(
1958
+								'Manually triggered status change on a Registration Admin Page route.',
1959
+								'event_espresso'
1960
+							)
1961
+						)
1962
+					);
1963
+					$result = $registration->save();
1964
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1965
+					$success = $result !== false ? $success : false;
1966
+				}
1967
+			}
1968
+		}
1969
+
1970
+		// return $success and processed registrations
1971
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1972
+	}
1973
+
1974
+
1975
+	/**
1976
+	 * Common logic for setting up success message and redirecting to appropriate route
1977
+	 *
1978
+	 * @param  string $STS_ID status id for the registration changed to
1979
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1980
+	 * @return void
1981
+	 * @throws EE_Error
1982
+	 */
1983
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1984
+	{
1985
+		$result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1986
+			: array('success' => false);
1987
+		$success = isset($result['success']) && $result['success'];
1988
+		// setup success message
1989
+		if ($success) {
1990
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1991
+				$msg = sprintf(
1992
+					esc_html__('Registration status has been set to %s', 'event_espresso'),
1993
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1994
+				);
1995
+			} else {
1996
+				$msg = sprintf(
1997
+					esc_html__('Registrations have been set to %s.', 'event_espresso'),
1998
+					EEH_Template::pretty_status($STS_ID, false, 'lower')
1999
+				);
2000
+			}
2001
+			EE_Error::add_success($msg);
2002
+		} else {
2003
+			EE_Error::add_error(
2004
+				esc_html__(
2005
+					'Something went wrong, and the status was not changed',
2006
+					'event_espresso'
2007
+				),
2008
+				__FILE__,
2009
+				__LINE__,
2010
+				__FUNCTION__
2011
+			);
2012
+		}
2013
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
2014
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
2015
+		} else {
2016
+			$route = array('action' => 'default');
2017
+		}
2018
+		// unset nonces
2019
+		foreach ($this->_req_data as $ref => $value) {
2020
+			if (strpos($ref, 'nonce') !== false) {
2021
+				unset($this->_req_data[ $ref ]);
2022
+				continue;
2023
+			}
2024
+			$value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
2025
+			$this->_req_data[ $ref ] = $value;
2026
+		}
2027
+		// merge request vars so that the reloaded list table contains any existing filter query params
2028
+		$route = array_merge($this->_req_data, $route);
2029
+		$this->_redirect_after_action($success, '', '', $route, true);
2030
+	}
2031
+
2032
+
2033
+	/**
2034
+	 * incoming reg status change from reg details page.
2035
+	 *
2036
+	 * @return void
2037
+	 */
2038
+	protected function _change_reg_status()
2039
+	{
2040
+		$this->_req_data['return'] = 'view_registration';
2041
+		// set notify based on whether the send notifications toggle is set or not
2042
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
2043
+		// $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
2044
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
2045
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
2046
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
2047
+			case EEM_Registration::status_id_approved:
2048
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'):
2049
+				$this->approve_registration($notify);
2050
+				break;
2051
+			case EEM_Registration::status_id_pending_payment:
2052
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'):
2053
+				$this->pending_registration($notify);
2054
+				break;
2055
+			case EEM_Registration::status_id_not_approved:
2056
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'):
2057
+				$this->not_approve_registration($notify);
2058
+				break;
2059
+			case EEM_Registration::status_id_declined:
2060
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'):
2061
+				$this->decline_registration($notify);
2062
+				break;
2063
+			case EEM_Registration::status_id_cancelled:
2064
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'):
2065
+				$this->cancel_registration($notify);
2066
+				break;
2067
+			case EEM_Registration::status_id_wait_list:
2068
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'):
2069
+				$this->wait_list_registration($notify);
2070
+				break;
2071
+			case EEM_Registration::status_id_incomplete:
2072
+			default:
2073
+				$result['success'] = false;
2074
+				unset($this->_req_data['return']);
2075
+				$this->_reg_status_change_return('', false);
2076
+				break;
2077
+		}
2078
+	}
2079
+
2080
+
2081
+	/**
2082
+	 * Callback for bulk action routes.
2083
+	 * Note: although we could just register the singular route callbacks for each bulk action route as well, this
2084
+	 * method was chosen so there is one central place all the registration status bulk actions are going through.
2085
+	 * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to
2086
+	 * when an action is happening on just a single registration).
2087
+	 *
2088
+	 * @param      $action
2089
+	 * @param bool $notify
2090
+	 */
2091
+	protected function bulk_action_on_registrations($action, $notify = false)
2092
+	{
2093
+		do_action(
2094
+			'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution',
2095
+			$this,
2096
+			$action,
2097
+			$notify
2098
+		);
2099
+		$method = $action . '_registration';
2100
+		if (method_exists($this, $method)) {
2101
+			$this->$method($notify);
2102
+		}
2103
+	}
2104
+
2105
+
2106
+	/**
2107
+	 * approve_registration
2108
+	 *
2109
+	 * @access protected
2110
+	 * @param bool $notify whether or not to notify the registrant about their approval.
2111
+	 * @return void
2112
+	 */
2113
+	protected function approve_registration($notify = false)
2114
+	{
2115
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
2116
+	}
2117
+
2118
+
2119
+	/**
2120
+	 *        decline_registration
2121
+	 *
2122
+	 * @access protected
2123
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2124
+	 * @return void
2125
+	 */
2126
+	protected function decline_registration($notify = false)
2127
+	{
2128
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
2129
+	}
2130
+
2131
+
2132
+	/**
2133
+	 *        cancel_registration
2134
+	 *
2135
+	 * @access protected
2136
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2137
+	 * @return void
2138
+	 */
2139
+	protected function cancel_registration($notify = false)
2140
+	{
2141
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
2142
+	}
2143
+
2144
+
2145
+	/**
2146
+	 *        not_approve_registration
2147
+	 *
2148
+	 * @access protected
2149
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2150
+	 * @return void
2151
+	 */
2152
+	protected function not_approve_registration($notify = false)
2153
+	{
2154
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
2155
+	}
2156
+
2157
+
2158
+	/**
2159
+	 *        decline_registration
2160
+	 *
2161
+	 * @access protected
2162
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2163
+	 * @return void
2164
+	 */
2165
+	protected function pending_registration($notify = false)
2166
+	{
2167
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
2168
+	}
2169
+
2170
+
2171
+	/**
2172
+	 * waitlist_registration
2173
+	 *
2174
+	 * @access protected
2175
+	 * @param bool $notify whether or not to notify the registrant about their status change.
2176
+	 * @return void
2177
+	 */
2178
+	protected function wait_list_registration($notify = false)
2179
+	{
2180
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
2181
+	}
2182
+
2183
+
2184
+	/**
2185
+	 *        generates HTML for the Registration main meta box
2186
+	 *
2187
+	 * @access public
2188
+	 * @return void
2189
+	 * @throws DomainException
2190
+	 * @throws EE_Error
2191
+	 * @throws InvalidArgumentException
2192
+	 * @throws InvalidDataTypeException
2193
+	 * @throws InvalidInterfaceException
2194
+	 * @throws ReflectionException
2195
+	 * @throws EntityNotFoundException
2196
+	 */
2197
+	public function _reg_details_meta_box()
2198
+	{
2199
+		EEH_Autoloader::register_line_item_display_autoloaders();
2200
+		EEH_Autoloader::register_line_item_filter_autoloaders();
2201
+		EE_Registry::instance()->load_helper('Line_Item');
2202
+		$transaction = $this->_registration->transaction() ? $this->_registration->transaction()
2203
+			: EE_Transaction::new_instance();
2204
+		$this->_session = $transaction->session_data();
2205
+		$filters = new EE_Line_Item_Filter_Collection();
2206
+		// $filters->add( new EE_Non_Zero_Line_Item_Filter() );
2207
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
2208
+		$line_item_filter_processor = new EE_Line_Item_Filter_Processor(
2209
+			$filters,
2210
+			$transaction->total_line_item()
2211
+		);
2212
+		$filtered_line_item_tree = $line_item_filter_processor->process();
2213
+		$line_item_display = new EE_Line_Item_Display(
2214
+			'reg_admin_table',
2215
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy'
2216
+		);
2217
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item(
2218
+			$filtered_line_item_tree,
2219
+			array('EE_Registration' => $this->_registration)
2220
+		);
2221
+		$attendee = $this->_registration->attendee();
2222
+		if (EE_Registry::instance()->CAP->current_user_can(
2223
+			'ee_read_transaction',
2224
+			'espresso_transactions_view_transaction'
2225
+		)) {
2226
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(
2227
+				EE_Admin_Page::add_query_args_and_nonce(
2228
+					array(
2229
+						'action' => 'view_transaction',
2230
+						'TXN_ID' => $transaction->ID(),
2231
+					),
2232
+					TXN_ADMIN_URL
2233
+				),
2234
+				esc_html__(' View Transaction', 'event_espresso'),
2235
+				'button secondary-button right',
2236
+				'dashicons dashicons-cart'
2237
+			);
2238
+		} else {
2239
+			$this->_template_args['view_transaction_button'] = '';
2240
+		}
2241
+		if ($attendee instanceof EE_Attendee
2242
+			&& EE_Registry::instance()->CAP->current_user_can(
2243
+				'ee_send_message',
2244
+				'espresso_registrations_resend_registration'
2245
+			)
2246
+		) {
2247
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(
2248
+				EE_Admin_Page::add_query_args_and_nonce(
2249
+					array(
2250
+						'action'      => 'resend_registration',
2251
+						'_REG_ID'     => $this->_registration->ID(),
2252
+						'redirect_to' => 'view_registration',
2253
+					),
2254
+					REG_ADMIN_URL
2255
+				),
2256
+				esc_html__(' Resend Registration', 'event_espresso'),
2257
+				'button secondary-button right',
2258
+				'dashicons dashicons-email-alt'
2259
+			);
2260
+		} else {
2261
+			$this->_template_args['resend_registration_button'] = '';
2262
+		}
2263
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2264
+		$payment = $transaction->get_first_related('Payment');
2265
+		$payment = ! $payment instanceof EE_Payment
2266
+			? EE_Payment::new_instance()
2267
+			: $payment;
2268
+		$payment_method = $payment->get_first_related('Payment_Method');
2269
+		$payment_method = ! $payment_method instanceof EE_Payment_Method
2270
+			? EE_Payment_Method::new_instance()
2271
+			: $payment_method;
2272
+		$reg_details = array(
2273
+			'payment_method'       => $payment_method->name(),
2274
+			'response_msg'         => $payment->gateway_response(),
2275
+			'registration_id'      => $this->_registration->get('REG_code'),
2276
+			'registration_session' => $this->_registration->session_ID(),
2277
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
2278
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
2279
+		);
2280
+		if (isset($reg_details['registration_id'])) {
2281
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
2282
+			$this->_template_args['reg_details']['registration_id']['label'] = esc_html__(
2283
+				'Registration ID',
2284
+				'event_espresso'
2285
+			);
2286
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
2287
+		}
2288
+		if (isset($reg_details['payment_method'])) {
2289
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
2290
+			$this->_template_args['reg_details']['payment_method']['label'] = esc_html__(
2291
+				'Most Recent Payment Method',
2292
+				'event_espresso'
2293
+			);
2294
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
2295
+			$this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg'];
2296
+			$this->_template_args['reg_details']['response_msg']['label'] = esc_html__(
2297
+				'Payment method response',
2298
+				'event_espresso'
2299
+			);
2300
+			$this->_template_args['reg_details']['response_msg']['class'] = 'regular-text';
2301
+		}
2302
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
2303
+		$this->_template_args['reg_details']['registration_session']['label'] = esc_html__(
2304
+			'Registration Session',
2305
+			'event_espresso'
2306
+		);
2307
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
2308
+		$this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address'];
2309
+		$this->_template_args['reg_details']['ip_address']['label'] = esc_html__(
2310
+			'Registration placed from IP',
2311
+			'event_espresso'
2312
+		);
2313
+		$this->_template_args['reg_details']['ip_address']['class'] = 'regular-text';
2314
+		$this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent'];
2315
+		$this->_template_args['reg_details']['user_agent']['label'] = esc_html__(
2316
+			'Registrant User Agent',
2317
+			'event_espresso'
2318
+		);
2319
+		$this->_template_args['reg_details']['user_agent']['class'] = 'large-text';
2320
+		$this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(
2321
+			array(
2322
+				'action'   => 'default',
2323
+				'event_id' => $this->_registration->event_ID(),
2324
+			),
2325
+			REG_ADMIN_URL
2326
+		);
2327
+		$this->_template_args['REG_ID'] = $this->_registration->ID();
2328
+		$this->_template_args['event_id'] = $this->_registration->event_ID();
2329
+		$template_path =
2330
+			REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2331
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2332
+	}
2333
+
2334
+
2335
+	/**
2336
+	 * generates HTML for the Registration Questions meta box.
2337
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
2338
+	 * otherwise uses new forms system
2339
+	 *
2340
+	 * @access public
2341
+	 * @return void
2342
+	 * @throws DomainException
2343
+	 * @throws EE_Error
2344
+	 */
2345
+	public function _reg_questions_meta_box()
2346
+	{
2347
+		// allow someone to override this method entirely
2348
+		if (apply_filters(
2349
+			'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default',
2350
+			true,
2351
+			$this,
2352
+			$this->_registration
2353
+		)) {
2354
+			$form = $this->_get_reg_custom_questions_form(
2355
+				$this->_registration->ID()
2356
+			);
2357
+			$this->_template_args['att_questions'] = count($form->subforms()) > 0
2358
+				? $form->get_html_and_js()
2359
+				: '';
2360
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
2361
+			$this->_template_args['REG_ID'] = $this->_registration->ID();
2362
+			$template_path =
2363
+				REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2364
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
2365
+		}
2366
+	}
2367
+
2368
+
2369
+	/**
2370
+	 * form_before_question_group
2371
+	 *
2372
+	 * @deprecated    as of 4.8.32.rc.000
2373
+	 * @access        public
2374
+	 * @param        string $output
2375
+	 * @return        string
2376
+	 */
2377
+	public function form_before_question_group($output)
2378
+	{
2379
+		EE_Error::doing_it_wrong(
2380
+			__CLASS__ . '::' . __FUNCTION__,
2381
+			esc_html__(
2382
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2383
+				'event_espresso'
2384
+			),
2385
+			'4.8.32.rc.000'
2386
+		);
2387
+		return '
2388 2388
 	<table class="form-table ee-width-100">
2389 2389
 		<tbody>
2390 2390
 			';
2391
-    }
2392
-
2393
-
2394
-    /**
2395
-     * form_after_question_group
2396
-     *
2397
-     * @deprecated    as of 4.8.32.rc.000
2398
-     * @access        public
2399
-     * @param        string $output
2400
-     * @return        string
2401
-     */
2402
-    public function form_after_question_group($output)
2403
-    {
2404
-        EE_Error::doing_it_wrong(
2405
-            __CLASS__ . '::' . __FUNCTION__,
2406
-            esc_html__(
2407
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2408
-                'event_espresso'
2409
-            ),
2410
-            '4.8.32.rc.000'
2411
-        );
2412
-        return '
2391
+	}
2392
+
2393
+
2394
+	/**
2395
+	 * form_after_question_group
2396
+	 *
2397
+	 * @deprecated    as of 4.8.32.rc.000
2398
+	 * @access        public
2399
+	 * @param        string $output
2400
+	 * @return        string
2401
+	 */
2402
+	public function form_after_question_group($output)
2403
+	{
2404
+		EE_Error::doing_it_wrong(
2405
+			__CLASS__ . '::' . __FUNCTION__,
2406
+			esc_html__(
2407
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2408
+				'event_espresso'
2409
+			),
2410
+			'4.8.32.rc.000'
2411
+		);
2412
+		return '
2413 2413
 			<tr class="hide-if-no-js">
2414 2414
 				<th> </th>
2415 2415
 				<td class="reg-admin-edit-attendee-question-td">
2416 2416
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
2417
-               . esc_attr__('click to edit question', 'event_espresso')
2418
-               . '">
2417
+			   . esc_attr__('click to edit question', 'event_espresso')
2418
+			   . '">
2419 2419
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
2420
-               . esc_html__('edit the above question group', 'event_espresso')
2421
-               . '</span>
2420
+			   . esc_html__('edit the above question group', 'event_espresso')
2421
+			   . '</span>
2422 2422
 						<div class="dashicons dashicons-edit"></div>
2423 2423
 					</a>
2424 2424
 				</td>
@@ -2426,608 +2426,608 @@  discard block
 block discarded – undo
2426 2426
 		</tbody>
2427 2427
 	</table>
2428 2428
 ';
2429
-    }
2430
-
2431
-
2432
-    /**
2433
-     * form_form_field_label_wrap
2434
-     *
2435
-     * @deprecated    as of 4.8.32.rc.000
2436
-     * @access        public
2437
-     * @param        string $label
2438
-     * @return        string
2439
-     */
2440
-    public function form_form_field_label_wrap($label)
2441
-    {
2442
-        EE_Error::doing_it_wrong(
2443
-            __CLASS__ . '::' . __FUNCTION__,
2444
-            esc_html__(
2445
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2446
-                'event_espresso'
2447
-            ),
2448
-            '4.8.32.rc.000'
2449
-        );
2450
-        return '
2429
+	}
2430
+
2431
+
2432
+	/**
2433
+	 * form_form_field_label_wrap
2434
+	 *
2435
+	 * @deprecated    as of 4.8.32.rc.000
2436
+	 * @access        public
2437
+	 * @param        string $label
2438
+	 * @return        string
2439
+	 */
2440
+	public function form_form_field_label_wrap($label)
2441
+	{
2442
+		EE_Error::doing_it_wrong(
2443
+			__CLASS__ . '::' . __FUNCTION__,
2444
+			esc_html__(
2445
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2446
+				'event_espresso'
2447
+			),
2448
+			'4.8.32.rc.000'
2449
+		);
2450
+		return '
2451 2451
 			<tr>
2452 2452
 				<th>
2453 2453
 					' . $label . '
2454 2454
 				</th>';
2455
-    }
2456
-
2457
-
2458
-    /**
2459
-     * form_form_field_input__wrap
2460
-     *
2461
-     * @deprecated    as of 4.8.32.rc.000
2462
-     * @access        public
2463
-     * @param        string $input
2464
-     * @return        string
2465
-     */
2466
-    public function form_form_field_input__wrap($input)
2467
-    {
2468
-        EE_Error::doing_it_wrong(
2469
-            __CLASS__ . '::' . __FUNCTION__,
2470
-            esc_html__(
2471
-                'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2472
-                'event_espresso'
2473
-            ),
2474
-            '4.8.32.rc.000'
2475
-        );
2476
-        return '
2455
+	}
2456
+
2457
+
2458
+	/**
2459
+	 * form_form_field_input__wrap
2460
+	 *
2461
+	 * @deprecated    as of 4.8.32.rc.000
2462
+	 * @access        public
2463
+	 * @param        string $input
2464
+	 * @return        string
2465
+	 */
2466
+	public function form_form_field_input__wrap($input)
2467
+	{
2468
+		EE_Error::doing_it_wrong(
2469
+			__CLASS__ . '::' . __FUNCTION__,
2470
+			esc_html__(
2471
+				'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2472
+				'event_espresso'
2473
+			),
2474
+			'4.8.32.rc.000'
2475
+		);
2476
+		return '
2477 2477
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2478 2478
 					' . $input . '
2479 2479
 				</td>
2480 2480
 			</tr>';
2481
-    }
2482
-
2483
-
2484
-    /**
2485
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
2486
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
2487
-     * to display the page
2488
-     *
2489
-     * @access protected
2490
-     * @return void
2491
-     * @throws EE_Error
2492
-     */
2493
-    protected function _update_attendee_registration_form()
2494
-    {
2495
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2496
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2497
-            $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2498
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
2499
-            if ($success) {
2500
-                $what = esc_html__('Registration Form', 'event_espresso');
2501
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2502
-                    : array('action' => 'default');
2503
-                $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2504
-            }
2505
-        }
2506
-    }
2507
-
2508
-
2509
-    /**
2510
-     * Gets the form for saving registrations custom questions (if done
2511
-     * previously retrieves the cached form object, which may have validation errors in it)
2512
-     *
2513
-     * @param int $REG_ID
2514
-     * @return EE_Registration_Custom_Questions_Form
2515
-     * @throws EE_Error
2516
-     * @throws InvalidArgumentException
2517
-     * @throws InvalidDataTypeException
2518
-     * @throws InvalidInterfaceException
2519
-     */
2520
-    protected function _get_reg_custom_questions_form($REG_ID)
2521
-    {
2522
-        if (! $this->_reg_custom_questions_form) {
2523
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2524
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2525
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
2526
-            );
2527
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
2528
-        }
2529
-        return $this->_reg_custom_questions_form;
2530
-    }
2531
-
2532
-
2533
-    /**
2534
-     * Saves
2535
-     *
2536
-     * @access private
2537
-     * @param bool $REG_ID
2538
-     * @return bool
2539
-     * @throws EE_Error
2540
-     * @throws InvalidArgumentException
2541
-     * @throws InvalidDataTypeException
2542
-     * @throws InvalidInterfaceException
2543
-     */
2544
-    private function _save_reg_custom_questions_form($REG_ID = false)
2545
-    {
2546
-        if (! $REG_ID) {
2547
-            EE_Error::add_error(
2548
-                esc_html__(
2549
-                    'An error occurred. No registration ID was received.',
2550
-                    'event_espresso'
2551
-                ),
2552
-                __FILE__,
2553
-                __FUNCTION__,
2554
-                __LINE__
2555
-            );
2556
-        }
2557
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
2558
-        $form->receive_form_submission($this->_req_data);
2559
-        $success = false;
2560
-        if ($form->is_valid()) {
2561
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
2562
-                foreach ($question_group_form->inputs() as $question_id => $input) {
2563
-                    $where_conditions = array(
2564
-                        'QST_ID' => $question_id,
2565
-                        'REG_ID' => $REG_ID,
2566
-                    );
2567
-                    $possibly_new_values = array(
2568
-                        'ANS_value' => $input->normalized_value(),
2569
-                    );
2570
-                    $answer = EEM_Answer::instance()->get_one(array($where_conditions));
2571
-                    if ($answer instanceof EE_Answer) {
2572
-                        $success = $answer->save($possibly_new_values);
2573
-                    } else {
2574
-                        // insert it then
2575
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2576
-                        $answer = EE_Answer::new_instance($cols_n_vals);
2577
-                        $success = $answer->save();
2578
-                    }
2579
-                }
2580
-            }
2581
-        } else {
2582
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2583
-        }
2584
-        return $success;
2585
-    }
2586
-
2587
-
2588
-    /**
2589
-     *        generates HTML for the Registration main meta box
2590
-     *
2591
-     * @access public
2592
-     * @return void
2593
-     * @throws DomainException
2594
-     * @throws EE_Error
2595
-     * @throws InvalidArgumentException
2596
-     * @throws InvalidDataTypeException
2597
-     * @throws InvalidInterfaceException
2598
-     */
2599
-    public function _reg_attendees_meta_box()
2600
-    {
2601
-        $REG = EEM_Registration::instance();
2602
-        // get all other registrations on this transaction, and cache
2603
-        // the attendees for them so we don't have to run another query using force_join
2604
-        $registrations = $REG->get_all(
2605
-            array(
2606
-                array(
2607
-                    'TXN_ID' => $this->_registration->transaction_ID(),
2608
-                    'REG_ID' => array('!=', $this->_registration->ID()),
2609
-                ),
2610
-                'force_join' => array('Attendee'),
2611
-            )
2612
-        );
2613
-        $this->_template_args['attendees'] = array();
2614
-        $this->_template_args['attendee_notice'] = '';
2615
-        if (empty($registrations)
2616
-            || (is_array($registrations)
2617
-                && ! EEH_Array::get_one_item_from_array($registrations))
2618
-        ) {
2619
-            EE_Error::add_error(
2620
-                esc_html__(
2621
-                    'There are no records attached to this registration. Something may have gone wrong with the registration',
2622
-                    'event_espresso'
2623
-                ),
2624
-                __FILE__,
2625
-                __FUNCTION__,
2626
-                __LINE__
2627
-            );
2628
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2629
-        } else {
2630
-            $att_nmbr = 1;
2631
-            foreach ($registrations as $registration) {
2632
-                /* @var $registration EE_Registration */
2633
-                $attendee = $registration->attendee()
2634
-                    ? $registration->attendee()
2635
-                    : EEM_Attendee::instance()
2636
-                                  ->create_default_object();
2637
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2638
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2639
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2640
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2641
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2642
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2643
-                    ', ',
2644
-                    $attendee->full_address_as_array()
2645
-                );
2646
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2647
-                    array(
2648
-                        'action' => 'edit_attendee',
2649
-                        'post'   => $attendee->ID(),
2650
-                    ),
2651
-                    REG_ADMIN_URL
2652
-                );
2653
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2654
-                    ? $registration->event_obj()->name()
2655
-                    : '';
2656
-                $att_nmbr++;
2657
-            }
2658
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2659
-        }
2660
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2661
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2662
-    }
2663
-
2664
-
2665
-    /**
2666
-     *        generates HTML for the Edit Registration side meta box
2667
-     *
2668
-     * @access public
2669
-     * @return void
2670
-     * @throws DomainException
2671
-     * @throws EE_Error
2672
-     * @throws InvalidArgumentException
2673
-     * @throws InvalidDataTypeException
2674
-     * @throws InvalidInterfaceException
2675
-     */
2676
-    public function _reg_registrant_side_meta_box()
2677
-    {
2678
-        /*@var $attendee EE_Attendee */
2679
-        $att_check = $this->_registration->attendee();
2680
-        $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2681
-        // now let's determine if this is not the primary registration.  If it isn't then we set the
2682
-        // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2683
-        // primary registration object (that way we know if we need to show create button or not)
2684
-        if (! $this->_registration->is_primary_registrant()) {
2685
-            $primary_registration = $this->_registration->get_primary_registration();
2686
-            $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2687
-                : null;
2688
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2689
-                // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2690
-                // custom attendee object so let's not worry about the primary reg.
2691
-                $primary_registration = null;
2692
-            }
2693
-        } else {
2694
-            $primary_registration = null;
2695
-        }
2696
-        $this->_template_args['ATT_ID'] = $attendee->ID();
2697
-        $this->_template_args['fname'] = $attendee->fname();
2698
-        $this->_template_args['lname'] = $attendee->lname();
2699
-        $this->_template_args['email'] = $attendee->email();
2700
-        $this->_template_args['phone'] = $attendee->phone();
2701
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2702
-        // edit link
2703
-        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2704
-            array(
2705
-                'action' => 'edit_attendee',
2706
-                'post'   => $attendee->ID(),
2707
-            ),
2708
-            REG_ADMIN_URL
2709
-        );
2710
-        $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2711
-        // create link
2712
-        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2713
-            ? EE_Admin_Page::add_query_args_and_nonce(
2714
-                array(
2715
-                    'action'  => 'duplicate_attendee',
2716
-                    '_REG_ID' => $this->_registration->ID(),
2717
-                ),
2718
-                REG_ADMIN_URL
2719
-            ) : '';
2720
-        $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2721
-        $this->_template_args['att_check'] = $att_check;
2722
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2723
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2724
-    }
2725
-
2726
-
2727
-    /**
2728
-     * trash or restore registrations
2729
-     *
2730
-     * @param  boolean $trash whether to archive or restore
2731
-     * @return void
2732
-     * @throws EE_Error
2733
-     * @throws InvalidArgumentException
2734
-     * @throws InvalidDataTypeException
2735
-     * @throws InvalidInterfaceException
2736
-     * @throws RuntimeException
2737
-     * @access protected
2738
-     */
2739
-    protected function _trash_or_restore_registrations($trash = true)
2740
-    {
2741
-        // if empty _REG_ID then get out because there's nothing to do
2742
-        if (empty($this->_req_data['_REG_ID'])) {
2743
-            EE_Error::add_error(
2744
-                sprintf(
2745
-                    esc_html__(
2746
-                        'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2747
-                        'event_espresso'
2748
-                    ),
2749
-                    $trash ? 'trash' : 'restore'
2750
-                ),
2751
-                __FILE__,
2752
-                __LINE__,
2753
-                __FUNCTION__
2754
-            );
2755
-            $this->_redirect_after_action(false, '', '', array(), true);
2756
-        }
2757
-        $success = 0;
2758
-        $overwrite_msgs = false;
2759
-        // Checkboxes
2760
-        if (! is_array($this->_req_data['_REG_ID'])) {
2761
-            $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2762
-        }
2763
-        $reg_count = count($this->_req_data['_REG_ID']);
2764
-        // cycle thru checkboxes
2765
-        foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2766
-            /** @var EE_Registration $REG */
2767
-            $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2768
-            $payments = $REG->registration_payments();
2769
-            if (! empty($payments)) {
2770
-                $name = $REG->attendee() instanceof EE_Attendee
2771
-                    ? $REG->attendee()->full_name()
2772
-                    : esc_html__('Unknown Attendee', 'event_espresso');
2773
-                $overwrite_msgs = true;
2774
-                EE_Error::add_error(
2775
-                    sprintf(
2776
-                        esc_html__(
2777
-                            'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2778
-                            'event_espresso'
2779
-                        ),
2780
-                        $name
2781
-                    ),
2782
-                    __FILE__,
2783
-                    __FUNCTION__,
2784
-                    __LINE__
2785
-                );
2786
-                // can't trash this registration because it has payments.
2787
-                continue;
2788
-            }
2789
-            $updated = $trash ? $REG->delete() : $REG->restore();
2790
-            if ($updated) {
2791
-                $success++;
2792
-            }
2793
-        }
2794
-        $this->_redirect_after_action(
2795
-            $success === $reg_count, // were ALL registrations affected?
2796
-            $success > 1
2797
-                ? esc_html__('Registrations', 'event_espresso')
2798
-                : esc_html__('Registration', 'event_espresso'),
2799
-            $trash
2800
-                ? esc_html__('moved to the trash', 'event_espresso')
2801
-                : esc_html__('restored', 'event_espresso'),
2802
-            array('action' => 'default'),
2803
-            $overwrite_msgs
2804
-        );
2805
-    }
2806
-
2807
-
2808
-    /**
2809
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2810
-     * registration but also.
2811
-     * 1. Removing relations to EE_Attendee
2812
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2813
-     * ALSO trashed.
2814
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2815
-     * 4. Removing relationships between all tickets and the related registrations
2816
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2817
-     * 6. Deleting permanently any related Checkins.
2818
-     *
2819
-     * @return void
2820
-     * @throws EE_Error
2821
-     * @throws InvalidArgumentException
2822
-     * @throws InvalidDataTypeException
2823
-     * @throws InvalidInterfaceException
2824
-     */
2825
-    protected function _delete_registrations()
2826
-    {
2827
-        $REG_MDL = EEM_Registration::instance();
2828
-        $success = 1;
2829
-        // Checkboxes
2830
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2831
-            // if array has more than one element than success message should be plural
2832
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2833
-            // cycle thru checkboxes
2834
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2835
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2836
-                if (! $REG instanceof EE_Registration) {
2837
-                    continue;
2838
-                }
2839
-                $deleted = $this->_delete_registration($REG);
2840
-                if (! $deleted) {
2841
-                    $success = 0;
2842
-                }
2843
-            }
2844
-        } else {
2845
-            // grab single id and delete
2846
-            $REG_ID = $this->_req_data['_REG_ID'];
2847
-            $REG = $REG_MDL->get_one_by_ID($REG_ID);
2848
-            $deleted = $this->_delete_registration($REG);
2849
-            if (! $deleted) {
2850
-                $success = 0;
2851
-            }
2852
-        }
2853
-        $what = $success > 1
2854
-            ? esc_html__('Registrations', 'event_espresso')
2855
-            : esc_html__('Registration', 'event_espresso');
2856
-        $action_desc = esc_html__('permanently deleted.', 'event_espresso');
2857
-        $this->_redirect_after_action(
2858
-            $success,
2859
-            $what,
2860
-            $action_desc,
2861
-            array('action' => 'default'),
2862
-            true
2863
-        );
2864
-    }
2865
-
2866
-
2867
-    /**
2868
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2869
-     * models get affected.
2870
-     *
2871
-     * @param  EE_Registration $REG registration to be deleted permenantly
2872
-     * @return bool true = successful deletion, false = fail.
2873
-     * @throws EE_Error
2874
-     */
2875
-    protected function _delete_registration(EE_Registration $REG)
2876
-    {
2877
-        // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2878
-        // registrations on the transaction that are NOT trashed.
2879
-        $TXN = $REG->get_first_related('Transaction');
2880
-        $REGS = $TXN->get_many_related('Registration');
2881
-        $all_trashed = true;
2882
-        foreach ($REGS as $registration) {
2883
-            if (! $registration->get('REG_deleted')) {
2884
-                $all_trashed = false;
2885
-            }
2886
-        }
2887
-        if (! $all_trashed) {
2888
-            EE_Error::add_error(
2889
-                esc_html__(
2890
-                    'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2891
-                    'event_espresso'
2892
-                ),
2893
-                __FILE__,
2894
-                __FUNCTION__,
2895
-                __LINE__
2896
-            );
2897
-            return false;
2898
-        }
2899
-        // k made it here so that means we can delete all the related transactions and their answers (but let's do them
2900
-        // separately from THIS one).
2901
-        foreach ($REGS as $registration) {
2902
-            // delete related answers
2903
-            $registration->delete_related_permanently('Answer');
2904
-            // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2905
-            $attendee = $registration->get_first_related('Attendee');
2906
-            if ($attendee instanceof EE_Attendee) {
2907
-                $registration->_remove_relation_to($attendee, 'Attendee');
2908
-            }
2909
-            // now remove relationships to tickets on this registration.
2910
-            $registration->_remove_relations('Ticket');
2911
-            // now delete permanently the checkins related to this registration.
2912
-            $registration->delete_related_permanently('Checkin');
2913
-            if ($registration->ID() === $REG->ID()) {
2914
-                continue;
2915
-            } //we don't want to delete permanently the existing registration just yet.
2916
-            // remove relation to transaction for these registrations if NOT the existing registrations
2917
-            $registration->_remove_relations('Transaction');
2918
-            // delete permanently any related messages.
2919
-            $registration->delete_related_permanently('Message');
2920
-            // now delete this registration permanently
2921
-            $registration->delete_permanently();
2922
-        }
2923
-        // now all related registrations on the transaction are handled.  So let's just handle this registration itself
2924
-        // (the transaction and line items should be all that's left).
2925
-        // delete the line items related to the transaction for this registration.
2926
-        $TXN->delete_related_permanently('Line_Item');
2927
-        // we need to remove all the relationships on the transaction
2928
-        $TXN->delete_related_permanently('Payment');
2929
-        $TXN->delete_related_permanently('Extra_Meta');
2930
-        $TXN->delete_related_permanently('Message');
2931
-        // now we can delete this REG permanently (and the transaction of course)
2932
-        $REG->delete_related_permanently('Transaction');
2933
-        return $REG->delete_permanently();
2934
-    }
2935
-
2936
-
2937
-    /**
2938
-     *    generates HTML for the Register New Attendee Admin page
2939
-     *
2940
-     * @access private
2941
-     * @throws DomainException
2942
-     * @throws EE_Error
2943
-     */
2944
-    public function new_registration()
2945
-    {
2946
-        if (! $this->_set_reg_event()) {
2947
-            throw new EE_Error(
2948
-                esc_html__(
2949
-                    'Unable to continue with registering because there is no Event ID in the request',
2950
-                    'event_espresso'
2951
-                )
2952
-            );
2953
-        }
2954
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2955
-        // gotta start with a clean slate if we're not coming here via ajax
2956
-        if (! defined('DOING_AJAX')
2957
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2958
-        ) {
2959
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2960
-        }
2961
-        $this->_template_args['event_name'] = '';
2962
-        // event name
2963
-        if ($this->_reg_event) {
2964
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2965
-            $edit_event_url = self::add_query_args_and_nonce(
2966
-                array(
2967
-                    'action' => 'edit',
2968
-                    'post'   => $this->_reg_event->ID(),
2969
-                ),
2970
-                EVENTS_ADMIN_URL
2971
-            );
2972
-            $edit_event_lnk = '<a href="'
2973
-                              . $edit_event_url
2974
-                              . '" title="'
2975
-                              . esc_attr__('Edit ', 'event_espresso')
2976
-                              . $this->_reg_event->name()
2977
-                              . '">'
2978
-                              . esc_html__('Edit Event', 'event_espresso')
2979
-                              . '</a>';
2980
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2981
-                                                   . $edit_event_lnk
2982
-                                                   . '</span>';
2983
-        }
2984
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2985
-        if (defined('DOING_AJAX')) {
2986
-            $this->_return_json();
2987
-        }
2988
-        // grab header
2989
-        $template_path =
2990
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2991
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2992
-            $template_path,
2993
-            $this->_template_args,
2994
-            true
2995
-        );
2996
-        // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2997
-        // the details template wrapper
2998
-        $this->display_admin_page_with_sidebar();
2999
-    }
3000
-
3001
-
3002
-    /**
3003
-     * This returns the content for a registration step
3004
-     *
3005
-     * @access protected
3006
-     * @return string html
3007
-     * @throws DomainException
3008
-     * @throws EE_Error
3009
-     * @throws InvalidArgumentException
3010
-     * @throws InvalidDataTypeException
3011
-     * @throws InvalidInterfaceException
3012
-     */
3013
-    protected function _get_registration_step_content()
3014
-    {
3015
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
3016
-            $warning_msg = sprintf(
3017
-                esc_html__(
3018
-                    '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
3019
-                    'event_espresso'
3020
-                ),
3021
-                '<br />',
3022
-                '<h3 class="important-notice">',
3023
-                '</h3>',
3024
-                '<div class="float-right">',
3025
-                '<span id="redirect_timer" class="important-notice">30</span>',
3026
-                '</div>',
3027
-                '<b>',
3028
-                '</b>'
3029
-            );
3030
-            return '
2481
+	}
2482
+
2483
+
2484
+	/**
2485
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
2486
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
2487
+	 * to display the page
2488
+	 *
2489
+	 * @access protected
2490
+	 * @return void
2491
+	 * @throws EE_Error
2492
+	 */
2493
+	protected function _update_attendee_registration_form()
2494
+	{
2495
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
2496
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
2497
+			$REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
2498
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
2499
+			if ($success) {
2500
+				$what = esc_html__('Registration Form', 'event_espresso');
2501
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
2502
+					: array('action' => 'default');
2503
+				$this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route);
2504
+			}
2505
+		}
2506
+	}
2507
+
2508
+
2509
+	/**
2510
+	 * Gets the form for saving registrations custom questions (if done
2511
+	 * previously retrieves the cached form object, which may have validation errors in it)
2512
+	 *
2513
+	 * @param int $REG_ID
2514
+	 * @return EE_Registration_Custom_Questions_Form
2515
+	 * @throws EE_Error
2516
+	 * @throws InvalidArgumentException
2517
+	 * @throws InvalidDataTypeException
2518
+	 * @throws InvalidInterfaceException
2519
+	 */
2520
+	protected function _get_reg_custom_questions_form($REG_ID)
2521
+	{
2522
+		if (! $this->_reg_custom_questions_form) {
2523
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2524
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2525
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
2526
+			);
2527
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
2528
+		}
2529
+		return $this->_reg_custom_questions_form;
2530
+	}
2531
+
2532
+
2533
+	/**
2534
+	 * Saves
2535
+	 *
2536
+	 * @access private
2537
+	 * @param bool $REG_ID
2538
+	 * @return bool
2539
+	 * @throws EE_Error
2540
+	 * @throws InvalidArgumentException
2541
+	 * @throws InvalidDataTypeException
2542
+	 * @throws InvalidInterfaceException
2543
+	 */
2544
+	private function _save_reg_custom_questions_form($REG_ID = false)
2545
+	{
2546
+		if (! $REG_ID) {
2547
+			EE_Error::add_error(
2548
+				esc_html__(
2549
+					'An error occurred. No registration ID was received.',
2550
+					'event_espresso'
2551
+				),
2552
+				__FILE__,
2553
+				__FUNCTION__,
2554
+				__LINE__
2555
+			);
2556
+		}
2557
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
2558
+		$form->receive_form_submission($this->_req_data);
2559
+		$success = false;
2560
+		if ($form->is_valid()) {
2561
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
2562
+				foreach ($question_group_form->inputs() as $question_id => $input) {
2563
+					$where_conditions = array(
2564
+						'QST_ID' => $question_id,
2565
+						'REG_ID' => $REG_ID,
2566
+					);
2567
+					$possibly_new_values = array(
2568
+						'ANS_value' => $input->normalized_value(),
2569
+					);
2570
+					$answer = EEM_Answer::instance()->get_one(array($where_conditions));
2571
+					if ($answer instanceof EE_Answer) {
2572
+						$success = $answer->save($possibly_new_values);
2573
+					} else {
2574
+						// insert it then
2575
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
2576
+						$answer = EE_Answer::new_instance($cols_n_vals);
2577
+						$success = $answer->save();
2578
+					}
2579
+				}
2580
+			}
2581
+		} else {
2582
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
2583
+		}
2584
+		return $success;
2585
+	}
2586
+
2587
+
2588
+	/**
2589
+	 *        generates HTML for the Registration main meta box
2590
+	 *
2591
+	 * @access public
2592
+	 * @return void
2593
+	 * @throws DomainException
2594
+	 * @throws EE_Error
2595
+	 * @throws InvalidArgumentException
2596
+	 * @throws InvalidDataTypeException
2597
+	 * @throws InvalidInterfaceException
2598
+	 */
2599
+	public function _reg_attendees_meta_box()
2600
+	{
2601
+		$REG = EEM_Registration::instance();
2602
+		// get all other registrations on this transaction, and cache
2603
+		// the attendees for them so we don't have to run another query using force_join
2604
+		$registrations = $REG->get_all(
2605
+			array(
2606
+				array(
2607
+					'TXN_ID' => $this->_registration->transaction_ID(),
2608
+					'REG_ID' => array('!=', $this->_registration->ID()),
2609
+				),
2610
+				'force_join' => array('Attendee'),
2611
+			)
2612
+		);
2613
+		$this->_template_args['attendees'] = array();
2614
+		$this->_template_args['attendee_notice'] = '';
2615
+		if (empty($registrations)
2616
+			|| (is_array($registrations)
2617
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2618
+		) {
2619
+			EE_Error::add_error(
2620
+				esc_html__(
2621
+					'There are no records attached to this registration. Something may have gone wrong with the registration',
2622
+					'event_espresso'
2623
+				),
2624
+				__FILE__,
2625
+				__FUNCTION__,
2626
+				__LINE__
2627
+			);
2628
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2629
+		} else {
2630
+			$att_nmbr = 1;
2631
+			foreach ($registrations as $registration) {
2632
+				/* @var $registration EE_Registration */
2633
+				$attendee = $registration->attendee()
2634
+					? $registration->attendee()
2635
+					: EEM_Attendee::instance()
2636
+								  ->create_default_object();
2637
+				$this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2638
+				$this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2639
+				$this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2640
+				$this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2641
+				$this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2642
+				$this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2643
+					', ',
2644
+					$attendee->full_address_as_array()
2645
+				);
2646
+				$this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2647
+					array(
2648
+						'action' => 'edit_attendee',
2649
+						'post'   => $attendee->ID(),
2650
+					),
2651
+					REG_ADMIN_URL
2652
+				);
2653
+				$this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2654
+					? $registration->event_obj()->name()
2655
+					: '';
2656
+				$att_nmbr++;
2657
+			}
2658
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2659
+		}
2660
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2661
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2662
+	}
2663
+
2664
+
2665
+	/**
2666
+	 *        generates HTML for the Edit Registration side meta box
2667
+	 *
2668
+	 * @access public
2669
+	 * @return void
2670
+	 * @throws DomainException
2671
+	 * @throws EE_Error
2672
+	 * @throws InvalidArgumentException
2673
+	 * @throws InvalidDataTypeException
2674
+	 * @throws InvalidInterfaceException
2675
+	 */
2676
+	public function _reg_registrant_side_meta_box()
2677
+	{
2678
+		/*@var $attendee EE_Attendee */
2679
+		$att_check = $this->_registration->attendee();
2680
+		$attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2681
+		// now let's determine if this is not the primary registration.  If it isn't then we set the
2682
+		// primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2683
+		// primary registration object (that way we know if we need to show create button or not)
2684
+		if (! $this->_registration->is_primary_registrant()) {
2685
+			$primary_registration = $this->_registration->get_primary_registration();
2686
+			$primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2687
+				: null;
2688
+			if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2689
+				// in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2690
+				// custom attendee object so let's not worry about the primary reg.
2691
+				$primary_registration = null;
2692
+			}
2693
+		} else {
2694
+			$primary_registration = null;
2695
+		}
2696
+		$this->_template_args['ATT_ID'] = $attendee->ID();
2697
+		$this->_template_args['fname'] = $attendee->fname();
2698
+		$this->_template_args['lname'] = $attendee->lname();
2699
+		$this->_template_args['email'] = $attendee->email();
2700
+		$this->_template_args['phone'] = $attendee->phone();
2701
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2702
+		// edit link
2703
+		$this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(
2704
+			array(
2705
+				'action' => 'edit_attendee',
2706
+				'post'   => $attendee->ID(),
2707
+			),
2708
+			REG_ADMIN_URL
2709
+		);
2710
+		$this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso');
2711
+		// create link
2712
+		$this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2713
+			? EE_Admin_Page::add_query_args_and_nonce(
2714
+				array(
2715
+					'action'  => 'duplicate_attendee',
2716
+					'_REG_ID' => $this->_registration->ID(),
2717
+				),
2718
+				REG_ADMIN_URL
2719
+			) : '';
2720
+		$this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2721
+		$this->_template_args['att_check'] = $att_check;
2722
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2723
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2724
+	}
2725
+
2726
+
2727
+	/**
2728
+	 * trash or restore registrations
2729
+	 *
2730
+	 * @param  boolean $trash whether to archive or restore
2731
+	 * @return void
2732
+	 * @throws EE_Error
2733
+	 * @throws InvalidArgumentException
2734
+	 * @throws InvalidDataTypeException
2735
+	 * @throws InvalidInterfaceException
2736
+	 * @throws RuntimeException
2737
+	 * @access protected
2738
+	 */
2739
+	protected function _trash_or_restore_registrations($trash = true)
2740
+	{
2741
+		// if empty _REG_ID then get out because there's nothing to do
2742
+		if (empty($this->_req_data['_REG_ID'])) {
2743
+			EE_Error::add_error(
2744
+				sprintf(
2745
+					esc_html__(
2746
+						'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.',
2747
+						'event_espresso'
2748
+					),
2749
+					$trash ? 'trash' : 'restore'
2750
+				),
2751
+				__FILE__,
2752
+				__LINE__,
2753
+				__FUNCTION__
2754
+			);
2755
+			$this->_redirect_after_action(false, '', '', array(), true);
2756
+		}
2757
+		$success = 0;
2758
+		$overwrite_msgs = false;
2759
+		// Checkboxes
2760
+		if (! is_array($this->_req_data['_REG_ID'])) {
2761
+			$this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2762
+		}
2763
+		$reg_count = count($this->_req_data['_REG_ID']);
2764
+		// cycle thru checkboxes
2765
+		foreach ($this->_req_data['_REG_ID'] as $REG_ID) {
2766
+			/** @var EE_Registration $REG */
2767
+			$REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2768
+			$payments = $REG->registration_payments();
2769
+			if (! empty($payments)) {
2770
+				$name = $REG->attendee() instanceof EE_Attendee
2771
+					? $REG->attendee()->full_name()
2772
+					: esc_html__('Unknown Attendee', 'event_espresso');
2773
+				$overwrite_msgs = true;
2774
+				EE_Error::add_error(
2775
+					sprintf(
2776
+						esc_html__(
2777
+							'The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2778
+							'event_espresso'
2779
+						),
2780
+						$name
2781
+					),
2782
+					__FILE__,
2783
+					__FUNCTION__,
2784
+					__LINE__
2785
+				);
2786
+				// can't trash this registration because it has payments.
2787
+				continue;
2788
+			}
2789
+			$updated = $trash ? $REG->delete() : $REG->restore();
2790
+			if ($updated) {
2791
+				$success++;
2792
+			}
2793
+		}
2794
+		$this->_redirect_after_action(
2795
+			$success === $reg_count, // were ALL registrations affected?
2796
+			$success > 1
2797
+				? esc_html__('Registrations', 'event_espresso')
2798
+				: esc_html__('Registration', 'event_espresso'),
2799
+			$trash
2800
+				? esc_html__('moved to the trash', 'event_espresso')
2801
+				: esc_html__('restored', 'event_espresso'),
2802
+			array('action' => 'default'),
2803
+			$overwrite_msgs
2804
+		);
2805
+	}
2806
+
2807
+
2808
+	/**
2809
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2810
+	 * registration but also.
2811
+	 * 1. Removing relations to EE_Attendee
2812
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2813
+	 * ALSO trashed.
2814
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2815
+	 * 4. Removing relationships between all tickets and the related registrations
2816
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2817
+	 * 6. Deleting permanently any related Checkins.
2818
+	 *
2819
+	 * @return void
2820
+	 * @throws EE_Error
2821
+	 * @throws InvalidArgumentException
2822
+	 * @throws InvalidDataTypeException
2823
+	 * @throws InvalidInterfaceException
2824
+	 */
2825
+	protected function _delete_registrations()
2826
+	{
2827
+		$REG_MDL = EEM_Registration::instance();
2828
+		$success = 1;
2829
+		// Checkboxes
2830
+		if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2831
+			// if array has more than one element than success message should be plural
2832
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2833
+			// cycle thru checkboxes
2834
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2835
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2836
+				if (! $REG instanceof EE_Registration) {
2837
+					continue;
2838
+				}
2839
+				$deleted = $this->_delete_registration($REG);
2840
+				if (! $deleted) {
2841
+					$success = 0;
2842
+				}
2843
+			}
2844
+		} else {
2845
+			// grab single id and delete
2846
+			$REG_ID = $this->_req_data['_REG_ID'];
2847
+			$REG = $REG_MDL->get_one_by_ID($REG_ID);
2848
+			$deleted = $this->_delete_registration($REG);
2849
+			if (! $deleted) {
2850
+				$success = 0;
2851
+			}
2852
+		}
2853
+		$what = $success > 1
2854
+			? esc_html__('Registrations', 'event_espresso')
2855
+			: esc_html__('Registration', 'event_espresso');
2856
+		$action_desc = esc_html__('permanently deleted.', 'event_espresso');
2857
+		$this->_redirect_after_action(
2858
+			$success,
2859
+			$what,
2860
+			$action_desc,
2861
+			array('action' => 'default'),
2862
+			true
2863
+		);
2864
+	}
2865
+
2866
+
2867
+	/**
2868
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2869
+	 * models get affected.
2870
+	 *
2871
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2872
+	 * @return bool true = successful deletion, false = fail.
2873
+	 * @throws EE_Error
2874
+	 */
2875
+	protected function _delete_registration(EE_Registration $REG)
2876
+	{
2877
+		// first we start with the transaction... ultimately, we WILL not delete permanently if there are any related
2878
+		// registrations on the transaction that are NOT trashed.
2879
+		$TXN = $REG->get_first_related('Transaction');
2880
+		$REGS = $TXN->get_many_related('Registration');
2881
+		$all_trashed = true;
2882
+		foreach ($REGS as $registration) {
2883
+			if (! $registration->get('REG_deleted')) {
2884
+				$all_trashed = false;
2885
+			}
2886
+		}
2887
+		if (! $all_trashed) {
2888
+			EE_Error::add_error(
2889
+				esc_html__(
2890
+					'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2891
+					'event_espresso'
2892
+				),
2893
+				__FILE__,
2894
+				__FUNCTION__,
2895
+				__LINE__
2896
+			);
2897
+			return false;
2898
+		}
2899
+		// k made it here so that means we can delete all the related transactions and their answers (but let's do them
2900
+		// separately from THIS one).
2901
+		foreach ($REGS as $registration) {
2902
+			// delete related answers
2903
+			$registration->delete_related_permanently('Answer');
2904
+			// remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2905
+			$attendee = $registration->get_first_related('Attendee');
2906
+			if ($attendee instanceof EE_Attendee) {
2907
+				$registration->_remove_relation_to($attendee, 'Attendee');
2908
+			}
2909
+			// now remove relationships to tickets on this registration.
2910
+			$registration->_remove_relations('Ticket');
2911
+			// now delete permanently the checkins related to this registration.
2912
+			$registration->delete_related_permanently('Checkin');
2913
+			if ($registration->ID() === $REG->ID()) {
2914
+				continue;
2915
+			} //we don't want to delete permanently the existing registration just yet.
2916
+			// remove relation to transaction for these registrations if NOT the existing registrations
2917
+			$registration->_remove_relations('Transaction');
2918
+			// delete permanently any related messages.
2919
+			$registration->delete_related_permanently('Message');
2920
+			// now delete this registration permanently
2921
+			$registration->delete_permanently();
2922
+		}
2923
+		// now all related registrations on the transaction are handled.  So let's just handle this registration itself
2924
+		// (the transaction and line items should be all that's left).
2925
+		// delete the line items related to the transaction for this registration.
2926
+		$TXN->delete_related_permanently('Line_Item');
2927
+		// we need to remove all the relationships on the transaction
2928
+		$TXN->delete_related_permanently('Payment');
2929
+		$TXN->delete_related_permanently('Extra_Meta');
2930
+		$TXN->delete_related_permanently('Message');
2931
+		// now we can delete this REG permanently (and the transaction of course)
2932
+		$REG->delete_related_permanently('Transaction');
2933
+		return $REG->delete_permanently();
2934
+	}
2935
+
2936
+
2937
+	/**
2938
+	 *    generates HTML for the Register New Attendee Admin page
2939
+	 *
2940
+	 * @access private
2941
+	 * @throws DomainException
2942
+	 * @throws EE_Error
2943
+	 */
2944
+	public function new_registration()
2945
+	{
2946
+		if (! $this->_set_reg_event()) {
2947
+			throw new EE_Error(
2948
+				esc_html__(
2949
+					'Unable to continue with registering because there is no Event ID in the request',
2950
+					'event_espresso'
2951
+				)
2952
+			);
2953
+		}
2954
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2955
+		// gotta start with a clean slate if we're not coming here via ajax
2956
+		if (! defined('DOING_AJAX')
2957
+			&& (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2958
+		) {
2959
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2960
+		}
2961
+		$this->_template_args['event_name'] = '';
2962
+		// event name
2963
+		if ($this->_reg_event) {
2964
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2965
+			$edit_event_url = self::add_query_args_and_nonce(
2966
+				array(
2967
+					'action' => 'edit',
2968
+					'post'   => $this->_reg_event->ID(),
2969
+				),
2970
+				EVENTS_ADMIN_URL
2971
+			);
2972
+			$edit_event_lnk = '<a href="'
2973
+							  . $edit_event_url
2974
+							  . '" title="'
2975
+							  . esc_attr__('Edit ', 'event_espresso')
2976
+							  . $this->_reg_event->name()
2977
+							  . '">'
2978
+							  . esc_html__('Edit Event', 'event_espresso')
2979
+							  . '</a>';
2980
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2981
+												   . $edit_event_lnk
2982
+												   . '</span>';
2983
+		}
2984
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2985
+		if (defined('DOING_AJAX')) {
2986
+			$this->_return_json();
2987
+		}
2988
+		// grab header
2989
+		$template_path =
2990
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2991
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2992
+			$template_path,
2993
+			$this->_template_args,
2994
+			true
2995
+		);
2996
+		// $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2997
+		// the details template wrapper
2998
+		$this->display_admin_page_with_sidebar();
2999
+	}
3000
+
3001
+
3002
+	/**
3003
+	 * This returns the content for a registration step
3004
+	 *
3005
+	 * @access protected
3006
+	 * @return string html
3007
+	 * @throws DomainException
3008
+	 * @throws EE_Error
3009
+	 * @throws InvalidArgumentException
3010
+	 * @throws InvalidDataTypeException
3011
+	 * @throws InvalidInterfaceException
3012
+	 */
3013
+	protected function _get_registration_step_content()
3014
+	{
3015
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
3016
+			$warning_msg = sprintf(
3017
+				esc_html__(
3018
+					'%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
3019
+					'event_espresso'
3020
+				),
3021
+				'<br />',
3022
+				'<h3 class="important-notice">',
3023
+				'</h3>',
3024
+				'<div class="float-right">',
3025
+				'<span id="redirect_timer" class="important-notice">30</span>',
3026
+				'</div>',
3027
+				'<b>',
3028
+				'</b>'
3029
+			);
3030
+			return '
3031 3031
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
3032 3032
 	<script >
3033 3033
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -3040,855 +3040,855 @@  discard block
 block discarded – undo
3040 3040
 	        }
3041 3041
 	    }, 800 );
3042 3042
 	</script >';
3043
-        }
3044
-        $template_args = array(
3045
-            'title'                    => '',
3046
-            'content'                  => '',
3047
-            'step_button_text'         => '',
3048
-            'show_notification_toggle' => false,
3049
-        );
3050
-        // to indicate we're processing a new registration
3051
-        $hidden_fields = array(
3052
-            'processing_registration' => array(
3053
-                'type'  => 'hidden',
3054
-                'value' => 0,
3055
-            ),
3056
-            'event_id'                => array(
3057
-                'type'  => 'hidden',
3058
-                'value' => $this->_reg_event->ID(),
3059
-            ),
3060
-        );
3061
-        // if the cart is empty then we know we're at step one so we'll display ticket selector
3062
-        $cart = EE_Registry::instance()->SSN->cart();
3063
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3064
-        switch ($step) {
3065
-            case 'ticket':
3066
-                $hidden_fields['processing_registration']['value'] = 1;
3067
-                $template_args['title'] = esc_html__(
3068
-                    'Step One: Select the Ticket for this registration',
3069
-                    'event_espresso'
3070
-                );
3071
-                $template_args['content'] =
3072
-                    EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
3073
-                $template_args['step_button_text'] = esc_html__(
3074
-                    'Add Tickets and Continue to Registrant Details',
3075
-                    'event_espresso'
3076
-                );
3077
-                $template_args['show_notification_toggle'] = false;
3078
-                break;
3079
-            case 'questions':
3080
-                $hidden_fields['processing_registration']['value'] = 2;
3081
-                $template_args['title'] = esc_html__(
3082
-                    'Step Two: Add Registrant Details for this Registration',
3083
-                    'event_espresso'
3084
-                );
3085
-                // in theory we should be able to run EED_SPCO at this point because the cart should have been setup
3086
-                // properly by the first process_reg_step run.
3087
-                $template_args['content'] =
3088
-                    EED_Single_Page_Checkout::registration_checkout_for_admin();
3089
-                $template_args['step_button_text'] = esc_html__(
3090
-                    'Save Registration and Continue to Details',
3091
-                    'event_espresso'
3092
-                );
3093
-                $template_args['show_notification_toggle'] = true;
3094
-                break;
3095
-        }
3096
-        // we come back to the process_registration_step route.
3097
-        $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3098
-        return EEH_Template::display_template(
3099
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3100
-            $template_args,
3101
-            true
3102
-        );
3103
-    }
3104
-
3105
-
3106
-    /**
3107
-     *        set_reg_event
3108
-     *
3109
-     * @access private
3110
-     * @return bool
3111
-     * @throws EE_Error
3112
-     * @throws InvalidArgumentException
3113
-     * @throws InvalidDataTypeException
3114
-     * @throws InvalidInterfaceException
3115
-     */
3116
-    private function _set_reg_event()
3117
-    {
3118
-        if (is_object($this->_reg_event)) {
3119
-            return true;
3120
-        }
3121
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3122
-        if (! $EVT_ID) {
3123
-            return false;
3124
-        }
3125
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3126
-        return true;
3127
-    }
3128
-
3129
-
3130
-    /**
3131
-     * process_reg_step
3132
-     *
3133
-     * @access        public
3134
-     * @return string
3135
-     * @throws DomainException
3136
-     * @throws EE_Error
3137
-     * @throws InvalidArgumentException
3138
-     * @throws InvalidDataTypeException
3139
-     * @throws InvalidInterfaceException
3140
-     * @throws ReflectionException
3141
-     * @throws RuntimeException
3142
-     */
3143
-    public function process_reg_step()
3144
-    {
3145
-        EE_System::do_not_cache();
3146
-        $this->_set_reg_event();
3147
-        EE_Registry::instance()->REQ->set_espresso_page(true);
3148
-        EE_Registry::instance()->REQ->set('uts', time());
3149
-        // what step are we on?
3150
-        $cart = EE_Registry::instance()->SSN->cart();
3151
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3152
-        // if doing ajax then we need to verify the nonce
3153
-        if (defined('DOING_AJAX')) {
3154
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
3155
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3156
-            $this->_verify_nonce($nonce, $this->_req_nonce);
3157
-        }
3158
-        switch ($step) {
3159
-            case 'ticket':
3160
-                // process ticket selection
3161
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
3162
-                if ($success) {
3163
-                    EE_Error::add_success(
3164
-                        esc_html__(
3165
-                            'Tickets Selected. Now complete the registration.',
3166
-                            'event_espresso'
3167
-                        )
3168
-                    );
3169
-                } else {
3170
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
3171
-                }
3172
-                if (defined('DOING_AJAX')) {
3173
-                    $this->new_registration(); // display next step
3174
-                } else {
3175
-                    $query_args = array(
3176
-                        'action'                  => 'new_registration',
3177
-                        'processing_registration' => 1,
3178
-                        'event_id'                => $this->_reg_event->ID(),
3179
-                        'uts'                     => time(),
3180
-                    );
3181
-                    $this->_redirect_after_action(
3182
-                        false,
3183
-                        '',
3184
-                        '',
3185
-                        $query_args,
3186
-                        true
3187
-                    );
3188
-                }
3189
-                break;
3190
-            case 'questions':
3191
-                if (! isset(
3192
-                    $this->_req_data['txn_reg_status_change'],
3193
-                    $this->_req_data['txn_reg_status_change']['send_notifications']
3194
-                )
3195
-                ) {
3196
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3197
-                }
3198
-                // process registration
3199
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3200
-                if ($cart instanceof EE_Cart) {
3201
-                    $grand_total = $cart->get_cart_grand_total();
3202
-                    if ($grand_total instanceof EE_Line_Item) {
3203
-                        $grand_total->save_this_and_descendants_to_txn();
3204
-                    }
3205
-                }
3206
-                if (! $transaction instanceof EE_Transaction) {
3207
-                    $query_args = array(
3208
-                        'action'                  => 'new_registration',
3209
-                        'processing_registration' => 2,
3210
-                        'event_id'                => $this->_reg_event->ID(),
3211
-                        'uts'                     => time(),
3212
-                    );
3213
-                    if (defined('DOING_AJAX')) {
3214
-                        // display registration form again because there are errors (maybe validation?)
3215
-                        $this->new_registration();
3216
-                        return;
3217
-                    } else {
3218
-                        $this->_redirect_after_action(
3219
-                            false,
3220
-                            '',
3221
-                            '',
3222
-                            $query_args,
3223
-                            true
3224
-                        );
3225
-                        return;
3226
-                    }
3227
-                }
3228
-                // maybe update status, and make sure to save transaction if not done already
3229
-                if (! $transaction->update_status_based_on_total_paid()) {
3230
-                    $transaction->save();
3231
-                }
3232
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3233
-                $this->_req_data = array();
3234
-                $query_args = array(
3235
-                    'action'        => 'redirect_to_txn',
3236
-                    'TXN_ID'        => $transaction->ID(),
3237
-                    'EVT_ID'        => $this->_reg_event->ID(),
3238
-                    'event_name'    => urlencode($this->_reg_event->name()),
3239
-                    'redirect_from' => 'new_registration',
3240
-                );
3241
-                $this->_redirect_after_action(false, '', '', $query_args, true);
3242
-                break;
3243
-        }
3244
-        // what are you looking here for?  Should be nothing to do at this point.
3245
-    }
3246
-
3247
-
3248
-    /**
3249
-     * redirect_to_txn
3250
-     *
3251
-     * @access public
3252
-     * @return void
3253
-     * @throws EE_Error
3254
-     * @throws InvalidArgumentException
3255
-     * @throws InvalidDataTypeException
3256
-     * @throws InvalidInterfaceException
3257
-     */
3258
-    public function redirect_to_txn()
3259
-    {
3260
-        EE_System::do_not_cache();
3261
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3262
-        $query_args = array(
3263
-            'action' => 'view_transaction',
3264
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3265
-            'page'   => 'espresso_transactions',
3266
-        );
3267
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3268
-            $query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3269
-            $query_args['event_name'] = urlencode($this->_req_data['event_name']);
3270
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
3271
-        }
3272
-        EE_Error::add_success(
3273
-            esc_html__(
3274
-                'Registration Created.  Please review the transaction and add any payments as necessary',
3275
-                'event_espresso'
3276
-            )
3277
-        );
3278
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3279
-    }
3280
-
3281
-
3282
-    /**
3283
-     *        generates HTML for the Attendee Contact List
3284
-     *
3285
-     * @access protected
3286
-     * @return void
3287
-     */
3288
-    protected function _attendee_contact_list_table()
3289
-    {
3290
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3291
-        $this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3292
-        $this->display_admin_list_table_page_with_no_sidebar();
3293
-    }
3294
-
3295
-
3296
-    /**
3297
-     *        get_attendees
3298
-     *
3299
-     * @param      $per_page
3300
-     * @param bool $count whether to return count or data.
3301
-     * @param bool $trash
3302
-     * @return array
3303
-     * @throws EE_Error
3304
-     * @throws InvalidArgumentException
3305
-     * @throws InvalidDataTypeException
3306
-     * @throws InvalidInterfaceException
3307
-     * @access public
3308
-     */
3309
-    public function get_attendees($per_page, $count = false, $trash = false)
3310
-    {
3311
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3312
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3313
-        $ATT_MDL = EEM_Attendee::instance();
3314
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3315
-        switch ($this->_req_data['orderby']) {
3316
-            case 'ATT_ID':
3317
-                $orderby = 'ATT_ID';
3318
-                break;
3319
-            case 'ATT_fname':
3320
-                $orderby = 'ATT_fname';
3321
-                break;
3322
-            case 'ATT_email':
3323
-                $orderby = 'ATT_email';
3324
-                break;
3325
-            case 'ATT_city':
3326
-                $orderby = 'ATT_city';
3327
-                break;
3328
-            case 'STA_ID':
3329
-                $orderby = 'STA_ID';
3330
-                break;
3331
-            case 'CNT_ID':
3332
-                $orderby = 'CNT_ID';
3333
-                break;
3334
-            case 'Registration_Count':
3335
-                $orderby = 'Registration_Count';
3336
-                break;
3337
-            default:
3338
-                $orderby = 'ATT_lname';
3339
-        }
3340
-        $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3341
-            ? $this->_req_data['order']
3342
-            : 'ASC';
3343
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3344
-            ? $this->_req_data['paged']
3345
-            : 1;
3346
-        $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3347
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3348
-            ? $this->_req_data['perpage']
3349
-            : $per_page;
3350
-        $_where = array();
3351
-        if (! empty($this->_req_data['s'])) {
3352
-            $sstr = '%' . $this->_req_data['s'] . '%';
3353
-            $_where['OR'] = array(
3354
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3355
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3356
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3357
-                'ATT_fname'                         => array('LIKE', $sstr),
3358
-                'ATT_lname'                         => array('LIKE', $sstr),
3359
-                'ATT_short_bio'                     => array('LIKE', $sstr),
3360
-                'ATT_email'                         => array('LIKE', $sstr),
3361
-                'ATT_address'                       => array('LIKE', $sstr),
3362
-                'ATT_address2'                      => array('LIKE', $sstr),
3363
-                'ATT_city'                          => array('LIKE', $sstr),
3364
-                'Country.CNT_name'                  => array('LIKE', $sstr),
3365
-                'State.STA_name'                    => array('LIKE', $sstr),
3366
-                'ATT_phone'                         => array('LIKE', $sstr),
3367
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
3368
-                'Registration.REG_code'             => array('LIKE', $sstr),
3369
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
3370
-            );
3371
-        }
3372
-        $offset = ($current_page - 1) * $per_page;
3373
-        $limit = $count ? null : array($offset, $per_page);
3374
-        $query_args = array(
3375
-            $_where,
3376
-            'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3377
-            'limit'         => $limit,
3378
-        );
3379
-        if (! $count) {
3380
-            $query_args['order_by'] = array($orderby => $sort);
3381
-        }
3382
-        if ($trash) {
3383
-            $query_args[0]['status'] = array('!=', 'publish');
3384
-            $all_attendees = $count
3385
-                ? $ATT_MDL->count($query_args, 'ATT_ID', true)
3386
-                : $ATT_MDL->get_all($query_args);
3387
-        } else {
3388
-            $query_args[0]['status'] = array('IN', array('publish'));
3389
-            $all_attendees = $count
3390
-                ? $ATT_MDL->count($query_args, 'ATT_ID', true)
3391
-                : $ATT_MDL->get_all($query_args);
3392
-        }
3393
-        return $all_attendees;
3394
-    }
3395
-
3396
-
3397
-    /**
3398
-     * This is just taking care of resending the registration confirmation
3399
-     *
3400
-     * @access protected
3401
-     * @return void
3402
-     */
3403
-    protected function _resend_registration()
3404
-    {
3405
-        $this->_process_resend_registration();
3406
-        $query_args = isset($this->_req_data['redirect_to'])
3407
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3408
-            : array('action' => 'default');
3409
-        $this->_redirect_after_action(false, '', '', $query_args, true);
3410
-    }
3411
-
3412
-    /**
3413
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3414
-     * to use when selecting registrations
3415
-     *
3416
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3417
-     *                                                     the query parameters from the request
3418
-     * @return void ends the request with a redirect or download
3419
-     */
3420
-    public function _registrations_report_base($method_name_for_getting_query_params)
3421
-    {
3422
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3423
-            wp_redirect(
3424
-                EE_Admin_Page::add_query_args_and_nonce(
3425
-                    array(
3426
-                        'page'        => 'espresso_batch',
3427
-                        'batch'       => 'file',
3428
-                        'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3429
-                        'filters'     => urlencode(
3430
-                            serialize(
3431
-                                call_user_func(
3432
-                                    array($this, $method_name_for_getting_query_params),
3433
-                                    EEH_Array::is_set(
3434
-                                        $this->_req_data,
3435
-                                        'filters',
3436
-                                        array()
3437
-                                    )
3438
-                                )
3439
-                            )
3440
-                        ),
3441
-                        'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3442
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3443
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3444
-                    )
3445
-                )
3446
-            );
3447
-        } else {
3448
-            $new_request_args = array(
3449
-                'export' => 'report',
3450
-                'action' => 'registrations_report_for_event',
3451
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3452
-            );
3453
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
3454
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3455
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3456
-                $EE_Export = EE_Export::instance($this->_req_data);
3457
-                $EE_Export->export();
3458
-            }
3459
-        }
3460
-    }
3461
-
3462
-
3463
-    /**
3464
-     * Creates a registration report using only query parameters in the request
3465
-     *
3466
-     * @return void
3467
-     */
3468
-    public function _registrations_report()
3469
-    {
3470
-        $this->_registrations_report_base('_get_registration_query_parameters');
3471
-    }
3472
-
3473
-
3474
-    public function _contact_list_export()
3475
-    {
3476
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3477
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3478
-            $EE_Export = EE_Export::instance($this->_req_data);
3479
-            $EE_Export->export_attendees();
3480
-        }
3481
-    }
3482
-
3483
-
3484
-    public function _contact_list_report()
3485
-    {
3486
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3487
-            wp_redirect(
3488
-                EE_Admin_Page::add_query_args_and_nonce(
3489
-                    array(
3490
-                        'page'        => 'espresso_batch',
3491
-                        'batch'       => 'file',
3492
-                        'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3493
-                        'return_url'  => urlencode($this->_req_data['return_url']),
3494
-                    )
3495
-                )
3496
-            );
3497
-        } else {
3498
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3499
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3500
-                $EE_Export = EE_Export::instance($this->_req_data);
3501
-                $EE_Export->report_attendees();
3502
-            }
3503
-        }
3504
-    }
3505
-
3506
-
3507
-
3508
-
3509
-
3510
-    /***************************************        ATTENDEE DETAILS        ***************************************/
3511
-    /**
3512
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
3513
-     *
3514
-     * @return void
3515
-     * @throws EE_Error
3516
-     * @throws InvalidArgumentException
3517
-     * @throws InvalidDataTypeException
3518
-     * @throws InvalidInterfaceException
3519
-     */
3520
-    protected function _duplicate_attendee()
3521
-    {
3522
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3523
-        // verify we have necessary info
3524
-        if (empty($this->_req_data['_REG_ID'])) {
3525
-            EE_Error::add_error(
3526
-                esc_html__(
3527
-                    'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3528
-                    'event_espresso'
3529
-                ),
3530
-                __FILE__,
3531
-                __LINE__,
3532
-                __FUNCTION__
3533
-            );
3534
-            $query_args = array('action' => $action);
3535
-            $this->_redirect_after_action('', '', '', $query_args, true);
3536
-        }
3537
-        // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3538
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3539
-        $attendee = $registration->attendee();
3540
-        // remove relation of existing attendee on registration
3541
-        $registration->_remove_relation_to($attendee, 'Attendee');
3542
-        // new attendee
3543
-        $new_attendee = clone $attendee;
3544
-        $new_attendee->set('ATT_ID', 0);
3545
-        $new_attendee->save();
3546
-        // add new attendee to reg
3547
-        $registration->_add_relation_to($new_attendee, 'Attendee');
3548
-        EE_Error::add_success(
3549
-            esc_html__(
3550
-                'New Contact record created.  Now make any edits you wish to make for this contact.',
3551
-                'event_espresso'
3552
-            )
3553
-        );
3554
-        // redirect to edit page for attendee
3555
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3556
-        $this->_redirect_after_action('', '', '', $query_args, true);
3557
-    }
3558
-
3559
-
3560
-    /**
3561
-     * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3562
-     *
3563
-     * @param int     $post_id
3564
-     * @param WP_POST $post
3565
-     * @throws DomainException
3566
-     * @throws EE_Error
3567
-     * @throws InvalidArgumentException
3568
-     * @throws InvalidDataTypeException
3569
-     * @throws InvalidInterfaceException
3570
-     * @throws LogicException
3571
-     * @throws InvalidFormSubmissionException
3572
-     */
3573
-    protected function _insert_update_cpt_item($post_id, $post)
3574
-    {
3575
-        $success = true;
3576
-        $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3577
-            ? EEM_Attendee::instance()->get_one_by_ID($post_id)
3578
-            : null;
3579
-        // for attendee updates
3580
-        if ($attendee instanceof EE_Attendee) {
3581
-            // note we should only be UPDATING attendees at this point.
3582
-            $updated_fields = array(
3583
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
3584
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
3585
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3586
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3587
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3588
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3589
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3590
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3591
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3592
-            );
3593
-            foreach ($updated_fields as $field => $value) {
3594
-                $attendee->set($field, $value);
3595
-            }
3596
-
3597
-            // process contact details metabox form handler (which will also save the attendee)
3598
-            $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3599
-            $success = $contact_details_form->process($this->_req_data);
3600
-
3601
-            $attendee_update_callbacks = apply_filters(
3602
-                'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3603
-                array()
3604
-            );
3605
-            foreach ($attendee_update_callbacks as $a_callback) {
3606
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3607
-                    throw new EE_Error(
3608
-                        sprintf(
3609
-                            esc_html__(
3610
-                                'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3611
-                                'event_espresso'
3612
-                            ),
3613
-                            $a_callback
3614
-                        )
3615
-                    );
3616
-                }
3617
-            }
3618
-        }
3619
-
3620
-        if ($success === false) {
3621
-            EE_Error::add_error(
3622
-                esc_html__(
3623
-                    'Something went wrong with updating the meta table data for the registration.',
3624
-                    'event_espresso'
3625
-                ),
3626
-                __FILE__,
3627
-                __FUNCTION__,
3628
-                __LINE__
3629
-            );
3630
-        }
3631
-    }
3632
-
3633
-
3634
-    public function trash_cpt_item($post_id)
3635
-    {
3636
-    }
3637
-
3638
-
3639
-    public function delete_cpt_item($post_id)
3640
-    {
3641
-    }
3642
-
3643
-
3644
-    public function restore_cpt_item($post_id)
3645
-    {
3646
-    }
3647
-
3648
-
3649
-    protected function _restore_cpt_item($post_id, $revision_id)
3650
-    {
3651
-    }
3652
-
3653
-
3654
-    public function attendee_editor_metaboxes()
3655
-    {
3656
-        $this->verify_cpt_object();
3657
-        remove_meta_box(
3658
-            'postexcerpt',
3659
-            esc_html__('Excerpt', 'event_espresso'),
3660
-            'post_excerpt_meta_box',
3661
-            $this->_cpt_routes[ $this->_req_action ],
3662
-            'normal',
3663
-            'core'
3664
-        );
3665
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3666
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
3667
-            add_meta_box(
3668
-                'postexcerpt',
3669
-                esc_html__('Short Biography', 'event_espresso'),
3670
-                'post_excerpt_meta_box',
3671
-                $this->_cpt_routes[ $this->_req_action ],
3672
-                'normal'
3673
-            );
3674
-        }
3675
-        if (post_type_supports('espresso_attendees', 'comments')) {
3676
-            add_meta_box(
3677
-                'commentsdiv',
3678
-                esc_html__('Notes on the Contact', 'event_espresso'),
3679
-                'post_comment_meta_box',
3680
-                $this->_cpt_routes[ $this->_req_action ],
3681
-                'normal',
3682
-                'core'
3683
-            );
3684
-        }
3685
-        add_meta_box(
3686
-            'attendee_contact_info',
3687
-            esc_html__('Contact Info', 'event_espresso'),
3688
-            array($this, 'attendee_contact_info'),
3689
-            $this->_cpt_routes[ $this->_req_action ],
3690
-            'side',
3691
-            'core'
3692
-        );
3693
-        add_meta_box(
3694
-            'attendee_details_address',
3695
-            esc_html__('Address Details', 'event_espresso'),
3696
-            array($this, 'attendee_address_details'),
3697
-            $this->_cpt_routes[ $this->_req_action ],
3698
-            'normal',
3699
-            'core'
3700
-        );
3701
-        add_meta_box(
3702
-            'attendee_registrations',
3703
-            esc_html__('Registrations for this Contact', 'event_espresso'),
3704
-            array($this, 'attendee_registrations_meta_box'),
3705
-            $this->_cpt_routes[ $this->_req_action ],
3706
-            'normal',
3707
-            'high'
3708
-        );
3709
-    }
3710
-
3711
-
3712
-    /**
3713
-     * Metabox for attendee contact info
3714
-     *
3715
-     * @param  WP_Post $post wp post object
3716
-     * @return string attendee contact info ( and form )
3717
-     * @throws EE_Error
3718
-     * @throws InvalidArgumentException
3719
-     * @throws InvalidDataTypeException
3720
-     * @throws InvalidInterfaceException
3721
-     * @throws LogicException
3722
-     * @throws DomainException
3723
-     */
3724
-    public function attendee_contact_info($post)
3725
-    {
3726
-        // get attendee object ( should already have it )
3727
-        $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3728
-        $form->enqueueStylesAndScripts();
3729
-        echo $form->display();
3730
-    }
3731
-
3732
-
3733
-    /**
3734
-     * Return form handler for the contact details metabox
3735
-     *
3736
-     * @param EE_Attendee $attendee
3737
-     * @return AttendeeContactDetailsMetaboxFormHandler
3738
-     * @throws DomainException
3739
-     * @throws InvalidArgumentException
3740
-     * @throws InvalidDataTypeException
3741
-     * @throws InvalidInterfaceException
3742
-     */
3743
-    protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3744
-    {
3745
-        return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3746
-    }
3747
-
3748
-
3749
-    /**
3750
-     * Metabox for attendee details
3751
-     *
3752
-     * @param  WP_Post $post wp post object
3753
-     * @throws DomainException
3754
-     */
3755
-    public function attendee_address_details($post)
3756
-    {
3757
-        // get attendee object (should already have it)
3758
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3759
-        $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3760
-            new EE_Question_Form_Input(
3761
-                EE_Question::new_instance(
3762
-                    array(
3763
-                        'QST_ID'           => 0,
3764
-                        'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3765
-                        'QST_system'       => 'admin-state',
3766
-                    )
3767
-                ),
3768
-                EE_Answer::new_instance(
3769
-                    array(
3770
-                        'ANS_ID'    => 0,
3771
-                        'ANS_value' => $this->_cpt_model_obj->state_ID(),
3772
-                    )
3773
-                ),
3774
-                array(
3775
-                    'input_id'       => 'STA_ID',
3776
-                    'input_name'     => 'STA_ID',
3777
-                    'input_prefix'   => '',
3778
-                    'append_qstn_id' => false,
3779
-                )
3780
-            )
3781
-        );
3782
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3783
-            new EE_Question_Form_Input(
3784
-                EE_Question::new_instance(
3785
-                    array(
3786
-                        'QST_ID'           => 0,
3787
-                        'QST_display_text' => esc_html__('Country', 'event_espresso'),
3788
-                        'QST_system'       => 'admin-country',
3789
-                    )
3790
-                ),
3791
-                EE_Answer::new_instance(
3792
-                    array(
3793
-                        'ANS_ID'    => 0,
3794
-                        'ANS_value' => $this->_cpt_model_obj->country_ID(),
3795
-                    )
3796
-                ),
3797
-                array(
3798
-                    'input_id'       => 'CNT_ISO',
3799
-                    'input_name'     => 'CNT_ISO',
3800
-                    'input_prefix'   => '',
3801
-                    'append_qstn_id' => false,
3802
-                )
3803
-            )
3804
-        );
3805
-        $template =
3806
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3807
-        EEH_Template::display_template($template, $this->_template_args);
3808
-    }
3809
-
3810
-
3811
-    /**
3812
-     *        _attendee_details
3813
-     *
3814
-     * @access protected
3815
-     * @param $post
3816
-     * @return void
3817
-     * @throws DomainException
3818
-     * @throws EE_Error
3819
-     */
3820
-    public function attendee_registrations_meta_box($post)
3821
-    {
3822
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
3823
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3824
-        $template =
3825
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3826
-        EEH_Template::display_template($template, $this->_template_args);
3827
-    }
3828
-
3829
-
3830
-    /**
3831
-     * add in the form fields for the attendee edit
3832
-     *
3833
-     * @param  WP_Post $post wp post object
3834
-     * @return string html for new form.
3835
-     * @throws DomainException
3836
-     */
3837
-    public function after_title_form_fields($post)
3838
-    {
3839
-        if ($post->post_type == 'espresso_attendees') {
3840
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3841
-            $template_args['attendee'] = $this->_cpt_model_obj;
3842
-            EEH_Template::display_template($template, $template_args);
3843
-        }
3844
-    }
3845
-
3846
-
3847
-    /**
3848
-     *        _trash_or_restore_attendee
3849
-     *
3850
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3851
-     * @return void
3852
-     * @throws EE_Error
3853
-     * @throws InvalidArgumentException
3854
-     * @throws InvalidDataTypeException
3855
-     * @throws InvalidInterfaceException
3856
-     * @access protected
3857
-     */
3858
-    protected function _trash_or_restore_attendees($trash = true)
3859
-    {
3860
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3861
-        $ATT_MDL = EEM_Attendee::instance();
3862
-        $success = 1;
3863
-        // Checkboxes
3864
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3865
-            // if array has more than one element than success message should be plural
3866
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3867
-            // cycle thru checkboxes
3868
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3869
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3870
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3871
-                if (! $updated) {
3872
-                    $success = 0;
3873
-                }
3874
-            }
3875
-        } else {
3876
-            // grab single id and delete
3877
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
3878
-            // get attendee
3879
-            $att = $ATT_MDL->get_one_by_ID($ATT_ID);
3880
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3881
-            $updated = $att->save();
3882
-            if (! $updated) {
3883
-                $success = 0;
3884
-            }
3885
-        }
3886
-        $what = $success > 1
3887
-            ? esc_html__('Contacts', 'event_espresso')
3888
-            : esc_html__('Contact', 'event_espresso');
3889
-        $action_desc = $trash
3890
-            ? esc_html__('moved to the trash', 'event_espresso')
3891
-            : esc_html__('restored', 'event_espresso');
3892
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3893
-    }
3043
+		}
3044
+		$template_args = array(
3045
+			'title'                    => '',
3046
+			'content'                  => '',
3047
+			'step_button_text'         => '',
3048
+			'show_notification_toggle' => false,
3049
+		);
3050
+		// to indicate we're processing a new registration
3051
+		$hidden_fields = array(
3052
+			'processing_registration' => array(
3053
+				'type'  => 'hidden',
3054
+				'value' => 0,
3055
+			),
3056
+			'event_id'                => array(
3057
+				'type'  => 'hidden',
3058
+				'value' => $this->_reg_event->ID(),
3059
+			),
3060
+		);
3061
+		// if the cart is empty then we know we're at step one so we'll display ticket selector
3062
+		$cart = EE_Registry::instance()->SSN->cart();
3063
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3064
+		switch ($step) {
3065
+			case 'ticket':
3066
+				$hidden_fields['processing_registration']['value'] = 1;
3067
+				$template_args['title'] = esc_html__(
3068
+					'Step One: Select the Ticket for this registration',
3069
+					'event_espresso'
3070
+				);
3071
+				$template_args['content'] =
3072
+					EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
3073
+				$template_args['step_button_text'] = esc_html__(
3074
+					'Add Tickets and Continue to Registrant Details',
3075
+					'event_espresso'
3076
+				);
3077
+				$template_args['show_notification_toggle'] = false;
3078
+				break;
3079
+			case 'questions':
3080
+				$hidden_fields['processing_registration']['value'] = 2;
3081
+				$template_args['title'] = esc_html__(
3082
+					'Step Two: Add Registrant Details for this Registration',
3083
+					'event_espresso'
3084
+				);
3085
+				// in theory we should be able to run EED_SPCO at this point because the cart should have been setup
3086
+				// properly by the first process_reg_step run.
3087
+				$template_args['content'] =
3088
+					EED_Single_Page_Checkout::registration_checkout_for_admin();
3089
+				$template_args['step_button_text'] = esc_html__(
3090
+					'Save Registration and Continue to Details',
3091
+					'event_espresso'
3092
+				);
3093
+				$template_args['show_notification_toggle'] = true;
3094
+				break;
3095
+		}
3096
+		// we come back to the process_registration_step route.
3097
+		$this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3098
+		return EEH_Template::display_template(
3099
+			REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3100
+			$template_args,
3101
+			true
3102
+		);
3103
+	}
3104
+
3105
+
3106
+	/**
3107
+	 *        set_reg_event
3108
+	 *
3109
+	 * @access private
3110
+	 * @return bool
3111
+	 * @throws EE_Error
3112
+	 * @throws InvalidArgumentException
3113
+	 * @throws InvalidDataTypeException
3114
+	 * @throws InvalidInterfaceException
3115
+	 */
3116
+	private function _set_reg_event()
3117
+	{
3118
+		if (is_object($this->_reg_event)) {
3119
+			return true;
3120
+		}
3121
+		$EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3122
+		if (! $EVT_ID) {
3123
+			return false;
3124
+		}
3125
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
3126
+		return true;
3127
+	}
3128
+
3129
+
3130
+	/**
3131
+	 * process_reg_step
3132
+	 *
3133
+	 * @access        public
3134
+	 * @return string
3135
+	 * @throws DomainException
3136
+	 * @throws EE_Error
3137
+	 * @throws InvalidArgumentException
3138
+	 * @throws InvalidDataTypeException
3139
+	 * @throws InvalidInterfaceException
3140
+	 * @throws ReflectionException
3141
+	 * @throws RuntimeException
3142
+	 */
3143
+	public function process_reg_step()
3144
+	{
3145
+		EE_System::do_not_cache();
3146
+		$this->_set_reg_event();
3147
+		EE_Registry::instance()->REQ->set_espresso_page(true);
3148
+		EE_Registry::instance()->REQ->set('uts', time());
3149
+		// what step are we on?
3150
+		$cart = EE_Registry::instance()->SSN->cart();
3151
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3152
+		// if doing ajax then we need to verify the nonce
3153
+		if (defined('DOING_AJAX')) {
3154
+			$nonce = isset($this->_req_data[ $this->_req_nonce ])
3155
+				? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3156
+			$this->_verify_nonce($nonce, $this->_req_nonce);
3157
+		}
3158
+		switch ($step) {
3159
+			case 'ticket':
3160
+				// process ticket selection
3161
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
3162
+				if ($success) {
3163
+					EE_Error::add_success(
3164
+						esc_html__(
3165
+							'Tickets Selected. Now complete the registration.',
3166
+							'event_espresso'
3167
+						)
3168
+					);
3169
+				} else {
3170
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
3171
+				}
3172
+				if (defined('DOING_AJAX')) {
3173
+					$this->new_registration(); // display next step
3174
+				} else {
3175
+					$query_args = array(
3176
+						'action'                  => 'new_registration',
3177
+						'processing_registration' => 1,
3178
+						'event_id'                => $this->_reg_event->ID(),
3179
+						'uts'                     => time(),
3180
+					);
3181
+					$this->_redirect_after_action(
3182
+						false,
3183
+						'',
3184
+						'',
3185
+						$query_args,
3186
+						true
3187
+					);
3188
+				}
3189
+				break;
3190
+			case 'questions':
3191
+				if (! isset(
3192
+					$this->_req_data['txn_reg_status_change'],
3193
+					$this->_req_data['txn_reg_status_change']['send_notifications']
3194
+				)
3195
+				) {
3196
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
3197
+				}
3198
+				// process registration
3199
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
3200
+				if ($cart instanceof EE_Cart) {
3201
+					$grand_total = $cart->get_cart_grand_total();
3202
+					if ($grand_total instanceof EE_Line_Item) {
3203
+						$grand_total->save_this_and_descendants_to_txn();
3204
+					}
3205
+				}
3206
+				if (! $transaction instanceof EE_Transaction) {
3207
+					$query_args = array(
3208
+						'action'                  => 'new_registration',
3209
+						'processing_registration' => 2,
3210
+						'event_id'                => $this->_reg_event->ID(),
3211
+						'uts'                     => time(),
3212
+					);
3213
+					if (defined('DOING_AJAX')) {
3214
+						// display registration form again because there are errors (maybe validation?)
3215
+						$this->new_registration();
3216
+						return;
3217
+					} else {
3218
+						$this->_redirect_after_action(
3219
+							false,
3220
+							'',
3221
+							'',
3222
+							$query_args,
3223
+							true
3224
+						);
3225
+						return;
3226
+					}
3227
+				}
3228
+				// maybe update status, and make sure to save transaction if not done already
3229
+				if (! $transaction->update_status_based_on_total_paid()) {
3230
+					$transaction->save();
3231
+				}
3232
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3233
+				$this->_req_data = array();
3234
+				$query_args = array(
3235
+					'action'        => 'redirect_to_txn',
3236
+					'TXN_ID'        => $transaction->ID(),
3237
+					'EVT_ID'        => $this->_reg_event->ID(),
3238
+					'event_name'    => urlencode($this->_reg_event->name()),
3239
+					'redirect_from' => 'new_registration',
3240
+				);
3241
+				$this->_redirect_after_action(false, '', '', $query_args, true);
3242
+				break;
3243
+		}
3244
+		// what are you looking here for?  Should be nothing to do at this point.
3245
+	}
3246
+
3247
+
3248
+	/**
3249
+	 * redirect_to_txn
3250
+	 *
3251
+	 * @access public
3252
+	 * @return void
3253
+	 * @throws EE_Error
3254
+	 * @throws InvalidArgumentException
3255
+	 * @throws InvalidDataTypeException
3256
+	 * @throws InvalidInterfaceException
3257
+	 */
3258
+	public function redirect_to_txn()
3259
+	{
3260
+		EE_System::do_not_cache();
3261
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
3262
+		$query_args = array(
3263
+			'action' => 'view_transaction',
3264
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
3265
+			'page'   => 'espresso_transactions',
3266
+		);
3267
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
3268
+			$query_args['EVT_ID'] = $this->_req_data['EVT_ID'];
3269
+			$query_args['event_name'] = urlencode($this->_req_data['event_name']);
3270
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
3271
+		}
3272
+		EE_Error::add_success(
3273
+			esc_html__(
3274
+				'Registration Created.  Please review the transaction and add any payments as necessary',
3275
+				'event_espresso'
3276
+			)
3277
+		);
3278
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3279
+	}
3280
+
3281
+
3282
+	/**
3283
+	 *        generates HTML for the Attendee Contact List
3284
+	 *
3285
+	 * @access protected
3286
+	 * @return void
3287
+	 */
3288
+	protected function _attendee_contact_list_table()
3289
+	{
3290
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3291
+		$this->_search_btn_label = esc_html__('Contacts', 'event_espresso');
3292
+		$this->display_admin_list_table_page_with_no_sidebar();
3293
+	}
3294
+
3295
+
3296
+	/**
3297
+	 *        get_attendees
3298
+	 *
3299
+	 * @param      $per_page
3300
+	 * @param bool $count whether to return count or data.
3301
+	 * @param bool $trash
3302
+	 * @return array
3303
+	 * @throws EE_Error
3304
+	 * @throws InvalidArgumentException
3305
+	 * @throws InvalidDataTypeException
3306
+	 * @throws InvalidInterfaceException
3307
+	 * @access public
3308
+	 */
3309
+	public function get_attendees($per_page, $count = false, $trash = false)
3310
+	{
3311
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3312
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3313
+		$ATT_MDL = EEM_Attendee::instance();
3314
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3315
+		switch ($this->_req_data['orderby']) {
3316
+			case 'ATT_ID':
3317
+				$orderby = 'ATT_ID';
3318
+				break;
3319
+			case 'ATT_fname':
3320
+				$orderby = 'ATT_fname';
3321
+				break;
3322
+			case 'ATT_email':
3323
+				$orderby = 'ATT_email';
3324
+				break;
3325
+			case 'ATT_city':
3326
+				$orderby = 'ATT_city';
3327
+				break;
3328
+			case 'STA_ID':
3329
+				$orderby = 'STA_ID';
3330
+				break;
3331
+			case 'CNT_ID':
3332
+				$orderby = 'CNT_ID';
3333
+				break;
3334
+			case 'Registration_Count':
3335
+				$orderby = 'Registration_Count';
3336
+				break;
3337
+			default:
3338
+				$orderby = 'ATT_lname';
3339
+		}
3340
+		$sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
3341
+			? $this->_req_data['order']
3342
+			: 'ASC';
3343
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
3344
+			? $this->_req_data['paged']
3345
+			: 1;
3346
+		$per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10;
3347
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
3348
+			? $this->_req_data['perpage']
3349
+			: $per_page;
3350
+		$_where = array();
3351
+		if (! empty($this->_req_data['s'])) {
3352
+			$sstr = '%' . $this->_req_data['s'] . '%';
3353
+			$_where['OR'] = array(
3354
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3355
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
3356
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
3357
+				'ATT_fname'                         => array('LIKE', $sstr),
3358
+				'ATT_lname'                         => array('LIKE', $sstr),
3359
+				'ATT_short_bio'                     => array('LIKE', $sstr),
3360
+				'ATT_email'                         => array('LIKE', $sstr),
3361
+				'ATT_address'                       => array('LIKE', $sstr),
3362
+				'ATT_address2'                      => array('LIKE', $sstr),
3363
+				'ATT_city'                          => array('LIKE', $sstr),
3364
+				'Country.CNT_name'                  => array('LIKE', $sstr),
3365
+				'State.STA_name'                    => array('LIKE', $sstr),
3366
+				'ATT_phone'                         => array('LIKE', $sstr),
3367
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
3368
+				'Registration.REG_code'             => array('LIKE', $sstr),
3369
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
3370
+			);
3371
+		}
3372
+		$offset = ($current_page - 1) * $per_page;
3373
+		$limit = $count ? null : array($offset, $per_page);
3374
+		$query_args = array(
3375
+			$_where,
3376
+			'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3377
+			'limit'         => $limit,
3378
+		);
3379
+		if (! $count) {
3380
+			$query_args['order_by'] = array($orderby => $sort);
3381
+		}
3382
+		if ($trash) {
3383
+			$query_args[0]['status'] = array('!=', 'publish');
3384
+			$all_attendees = $count
3385
+				? $ATT_MDL->count($query_args, 'ATT_ID', true)
3386
+				: $ATT_MDL->get_all($query_args);
3387
+		} else {
3388
+			$query_args[0]['status'] = array('IN', array('publish'));
3389
+			$all_attendees = $count
3390
+				? $ATT_MDL->count($query_args, 'ATT_ID', true)
3391
+				: $ATT_MDL->get_all($query_args);
3392
+		}
3393
+		return $all_attendees;
3394
+	}
3395
+
3396
+
3397
+	/**
3398
+	 * This is just taking care of resending the registration confirmation
3399
+	 *
3400
+	 * @access protected
3401
+	 * @return void
3402
+	 */
3403
+	protected function _resend_registration()
3404
+	{
3405
+		$this->_process_resend_registration();
3406
+		$query_args = isset($this->_req_data['redirect_to'])
3407
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
3408
+			: array('action' => 'default');
3409
+		$this->_redirect_after_action(false, '', '', $query_args, true);
3410
+	}
3411
+
3412
+	/**
3413
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
3414
+	 * to use when selecting registrations
3415
+	 *
3416
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
3417
+	 *                                                     the query parameters from the request
3418
+	 * @return void ends the request with a redirect or download
3419
+	 */
3420
+	public function _registrations_report_base($method_name_for_getting_query_params)
3421
+	{
3422
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3423
+			wp_redirect(
3424
+				EE_Admin_Page::add_query_args_and_nonce(
3425
+					array(
3426
+						'page'        => 'espresso_batch',
3427
+						'batch'       => 'file',
3428
+						'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3429
+						'filters'     => urlencode(
3430
+							serialize(
3431
+								call_user_func(
3432
+									array($this, $method_name_for_getting_query_params),
3433
+									EEH_Array::is_set(
3434
+										$this->_req_data,
3435
+										'filters',
3436
+										array()
3437
+									)
3438
+								)
3439
+							)
3440
+						),
3441
+						'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
3442
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
3443
+						'return_url'  => urlencode($this->_req_data['return_url']),
3444
+					)
3445
+				)
3446
+			);
3447
+		} else {
3448
+			$new_request_args = array(
3449
+				'export' => 'report',
3450
+				'action' => 'registrations_report_for_event',
3451
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3452
+			);
3453
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
3454
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3455
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3456
+				$EE_Export = EE_Export::instance($this->_req_data);
3457
+				$EE_Export->export();
3458
+			}
3459
+		}
3460
+	}
3461
+
3462
+
3463
+	/**
3464
+	 * Creates a registration report using only query parameters in the request
3465
+	 *
3466
+	 * @return void
3467
+	 */
3468
+	public function _registrations_report()
3469
+	{
3470
+		$this->_registrations_report_base('_get_registration_query_parameters');
3471
+	}
3472
+
3473
+
3474
+	public function _contact_list_export()
3475
+	{
3476
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3477
+			require_once(EE_CLASSES . 'EE_Export.class.php');
3478
+			$EE_Export = EE_Export::instance($this->_req_data);
3479
+			$EE_Export->export_attendees();
3480
+		}
3481
+	}
3482
+
3483
+
3484
+	public function _contact_list_report()
3485
+	{
3486
+		if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3487
+			wp_redirect(
3488
+				EE_Admin_Page::add_query_args_and_nonce(
3489
+					array(
3490
+						'page'        => 'espresso_batch',
3491
+						'batch'       => 'file',
3492
+						'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
3493
+						'return_url'  => urlencode($this->_req_data['return_url']),
3494
+					)
3495
+				)
3496
+			);
3497
+		} else {
3498
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3499
+				require_once(EE_CLASSES . 'EE_Export.class.php');
3500
+				$EE_Export = EE_Export::instance($this->_req_data);
3501
+				$EE_Export->report_attendees();
3502
+			}
3503
+		}
3504
+	}
3505
+
3506
+
3507
+
3508
+
3509
+
3510
+	/***************************************        ATTENDEE DETAILS        ***************************************/
3511
+	/**
3512
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
3513
+	 *
3514
+	 * @return void
3515
+	 * @throws EE_Error
3516
+	 * @throws InvalidArgumentException
3517
+	 * @throws InvalidDataTypeException
3518
+	 * @throws InvalidInterfaceException
3519
+	 */
3520
+	protected function _duplicate_attendee()
3521
+	{
3522
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
3523
+		// verify we have necessary info
3524
+		if (empty($this->_req_data['_REG_ID'])) {
3525
+			EE_Error::add_error(
3526
+				esc_html__(
3527
+					'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
3528
+					'event_espresso'
3529
+				),
3530
+				__FILE__,
3531
+				__LINE__,
3532
+				__FUNCTION__
3533
+			);
3534
+			$query_args = array('action' => $action);
3535
+			$this->_redirect_after_action('', '', '', $query_args, true);
3536
+		}
3537
+		// okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
3538
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
3539
+		$attendee = $registration->attendee();
3540
+		// remove relation of existing attendee on registration
3541
+		$registration->_remove_relation_to($attendee, 'Attendee');
3542
+		// new attendee
3543
+		$new_attendee = clone $attendee;
3544
+		$new_attendee->set('ATT_ID', 0);
3545
+		$new_attendee->save();
3546
+		// add new attendee to reg
3547
+		$registration->_add_relation_to($new_attendee, 'Attendee');
3548
+		EE_Error::add_success(
3549
+			esc_html__(
3550
+				'New Contact record created.  Now make any edits you wish to make for this contact.',
3551
+				'event_espresso'
3552
+			)
3553
+		);
3554
+		// redirect to edit page for attendee
3555
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
3556
+		$this->_redirect_after_action('', '', '', $query_args, true);
3557
+	}
3558
+
3559
+
3560
+	/**
3561
+	 * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook.
3562
+	 *
3563
+	 * @param int     $post_id
3564
+	 * @param WP_POST $post
3565
+	 * @throws DomainException
3566
+	 * @throws EE_Error
3567
+	 * @throws InvalidArgumentException
3568
+	 * @throws InvalidDataTypeException
3569
+	 * @throws InvalidInterfaceException
3570
+	 * @throws LogicException
3571
+	 * @throws InvalidFormSubmissionException
3572
+	 */
3573
+	protected function _insert_update_cpt_item($post_id, $post)
3574
+	{
3575
+		$success = true;
3576
+		$attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees'
3577
+			? EEM_Attendee::instance()->get_one_by_ID($post_id)
3578
+			: null;
3579
+		// for attendee updates
3580
+		if ($attendee instanceof EE_Attendee) {
3581
+			// note we should only be UPDATING attendees at this point.
3582
+			$updated_fields = array(
3583
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
3584
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
3585
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3586
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3587
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3588
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
3589
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
3590
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
3591
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
3592
+			);
3593
+			foreach ($updated_fields as $field => $value) {
3594
+				$attendee->set($field, $value);
3595
+			}
3596
+
3597
+			// process contact details metabox form handler (which will also save the attendee)
3598
+			$contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee);
3599
+			$success = $contact_details_form->process($this->_req_data);
3600
+
3601
+			$attendee_update_callbacks = apply_filters(
3602
+				'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
3603
+				array()
3604
+			);
3605
+			foreach ($attendee_update_callbacks as $a_callback) {
3606
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
3607
+					throw new EE_Error(
3608
+						sprintf(
3609
+							esc_html__(
3610
+								'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
3611
+								'event_espresso'
3612
+							),
3613
+							$a_callback
3614
+						)
3615
+					);
3616
+				}
3617
+			}
3618
+		}
3619
+
3620
+		if ($success === false) {
3621
+			EE_Error::add_error(
3622
+				esc_html__(
3623
+					'Something went wrong with updating the meta table data for the registration.',
3624
+					'event_espresso'
3625
+				),
3626
+				__FILE__,
3627
+				__FUNCTION__,
3628
+				__LINE__
3629
+			);
3630
+		}
3631
+	}
3632
+
3633
+
3634
+	public function trash_cpt_item($post_id)
3635
+	{
3636
+	}
3637
+
3638
+
3639
+	public function delete_cpt_item($post_id)
3640
+	{
3641
+	}
3642
+
3643
+
3644
+	public function restore_cpt_item($post_id)
3645
+	{
3646
+	}
3647
+
3648
+
3649
+	protected function _restore_cpt_item($post_id, $revision_id)
3650
+	{
3651
+	}
3652
+
3653
+
3654
+	public function attendee_editor_metaboxes()
3655
+	{
3656
+		$this->verify_cpt_object();
3657
+		remove_meta_box(
3658
+			'postexcerpt',
3659
+			esc_html__('Excerpt', 'event_espresso'),
3660
+			'post_excerpt_meta_box',
3661
+			$this->_cpt_routes[ $this->_req_action ],
3662
+			'normal',
3663
+			'core'
3664
+		);
3665
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3666
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
3667
+			add_meta_box(
3668
+				'postexcerpt',
3669
+				esc_html__('Short Biography', 'event_espresso'),
3670
+				'post_excerpt_meta_box',
3671
+				$this->_cpt_routes[ $this->_req_action ],
3672
+				'normal'
3673
+			);
3674
+		}
3675
+		if (post_type_supports('espresso_attendees', 'comments')) {
3676
+			add_meta_box(
3677
+				'commentsdiv',
3678
+				esc_html__('Notes on the Contact', 'event_espresso'),
3679
+				'post_comment_meta_box',
3680
+				$this->_cpt_routes[ $this->_req_action ],
3681
+				'normal',
3682
+				'core'
3683
+			);
3684
+		}
3685
+		add_meta_box(
3686
+			'attendee_contact_info',
3687
+			esc_html__('Contact Info', 'event_espresso'),
3688
+			array($this, 'attendee_contact_info'),
3689
+			$this->_cpt_routes[ $this->_req_action ],
3690
+			'side',
3691
+			'core'
3692
+		);
3693
+		add_meta_box(
3694
+			'attendee_details_address',
3695
+			esc_html__('Address Details', 'event_espresso'),
3696
+			array($this, 'attendee_address_details'),
3697
+			$this->_cpt_routes[ $this->_req_action ],
3698
+			'normal',
3699
+			'core'
3700
+		);
3701
+		add_meta_box(
3702
+			'attendee_registrations',
3703
+			esc_html__('Registrations for this Contact', 'event_espresso'),
3704
+			array($this, 'attendee_registrations_meta_box'),
3705
+			$this->_cpt_routes[ $this->_req_action ],
3706
+			'normal',
3707
+			'high'
3708
+		);
3709
+	}
3710
+
3711
+
3712
+	/**
3713
+	 * Metabox for attendee contact info
3714
+	 *
3715
+	 * @param  WP_Post $post wp post object
3716
+	 * @return string attendee contact info ( and form )
3717
+	 * @throws EE_Error
3718
+	 * @throws InvalidArgumentException
3719
+	 * @throws InvalidDataTypeException
3720
+	 * @throws InvalidInterfaceException
3721
+	 * @throws LogicException
3722
+	 * @throws DomainException
3723
+	 */
3724
+	public function attendee_contact_info($post)
3725
+	{
3726
+		// get attendee object ( should already have it )
3727
+		$form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj);
3728
+		$form->enqueueStylesAndScripts();
3729
+		echo $form->display();
3730
+	}
3731
+
3732
+
3733
+	/**
3734
+	 * Return form handler for the contact details metabox
3735
+	 *
3736
+	 * @param EE_Attendee $attendee
3737
+	 * @return AttendeeContactDetailsMetaboxFormHandler
3738
+	 * @throws DomainException
3739
+	 * @throws InvalidArgumentException
3740
+	 * @throws InvalidDataTypeException
3741
+	 * @throws InvalidInterfaceException
3742
+	 */
3743
+	protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee)
3744
+	{
3745
+		return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance());
3746
+	}
3747
+
3748
+
3749
+	/**
3750
+	 * Metabox for attendee details
3751
+	 *
3752
+	 * @param  WP_Post $post wp post object
3753
+	 * @throws DomainException
3754
+	 */
3755
+	public function attendee_address_details($post)
3756
+	{
3757
+		// get attendee object (should already have it)
3758
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3759
+		$this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input(
3760
+			new EE_Question_Form_Input(
3761
+				EE_Question::new_instance(
3762
+					array(
3763
+						'QST_ID'           => 0,
3764
+						'QST_display_text' => esc_html__('State/Province', 'event_espresso'),
3765
+						'QST_system'       => 'admin-state',
3766
+					)
3767
+				),
3768
+				EE_Answer::new_instance(
3769
+					array(
3770
+						'ANS_ID'    => 0,
3771
+						'ANS_value' => $this->_cpt_model_obj->state_ID(),
3772
+					)
3773
+				),
3774
+				array(
3775
+					'input_id'       => 'STA_ID',
3776
+					'input_name'     => 'STA_ID',
3777
+					'input_prefix'   => '',
3778
+					'append_qstn_id' => false,
3779
+				)
3780
+			)
3781
+		);
3782
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(
3783
+			new EE_Question_Form_Input(
3784
+				EE_Question::new_instance(
3785
+					array(
3786
+						'QST_ID'           => 0,
3787
+						'QST_display_text' => esc_html__('Country', 'event_espresso'),
3788
+						'QST_system'       => 'admin-country',
3789
+					)
3790
+				),
3791
+				EE_Answer::new_instance(
3792
+					array(
3793
+						'ANS_ID'    => 0,
3794
+						'ANS_value' => $this->_cpt_model_obj->country_ID(),
3795
+					)
3796
+				),
3797
+				array(
3798
+					'input_id'       => 'CNT_ISO',
3799
+					'input_name'     => 'CNT_ISO',
3800
+					'input_prefix'   => '',
3801
+					'append_qstn_id' => false,
3802
+				)
3803
+			)
3804
+		);
3805
+		$template =
3806
+			REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3807
+		EEH_Template::display_template($template, $this->_template_args);
3808
+	}
3809
+
3810
+
3811
+	/**
3812
+	 *        _attendee_details
3813
+	 *
3814
+	 * @access protected
3815
+	 * @param $post
3816
+	 * @return void
3817
+	 * @throws DomainException
3818
+	 * @throws EE_Error
3819
+	 */
3820
+	public function attendee_registrations_meta_box($post)
3821
+	{
3822
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
3823
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3824
+		$template =
3825
+			REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3826
+		EEH_Template::display_template($template, $this->_template_args);
3827
+	}
3828
+
3829
+
3830
+	/**
3831
+	 * add in the form fields for the attendee edit
3832
+	 *
3833
+	 * @param  WP_Post $post wp post object
3834
+	 * @return string html for new form.
3835
+	 * @throws DomainException
3836
+	 */
3837
+	public function after_title_form_fields($post)
3838
+	{
3839
+		if ($post->post_type == 'espresso_attendees') {
3840
+			$template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3841
+			$template_args['attendee'] = $this->_cpt_model_obj;
3842
+			EEH_Template::display_template($template, $template_args);
3843
+		}
3844
+	}
3845
+
3846
+
3847
+	/**
3848
+	 *        _trash_or_restore_attendee
3849
+	 *
3850
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
3851
+	 * @return void
3852
+	 * @throws EE_Error
3853
+	 * @throws InvalidArgumentException
3854
+	 * @throws InvalidDataTypeException
3855
+	 * @throws InvalidInterfaceException
3856
+	 * @access protected
3857
+	 */
3858
+	protected function _trash_or_restore_attendees($trash = true)
3859
+	{
3860
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3861
+		$ATT_MDL = EEM_Attendee::instance();
3862
+		$success = 1;
3863
+		// Checkboxes
3864
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3865
+			// if array has more than one element than success message should be plural
3866
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3867
+			// cycle thru checkboxes
3868
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3869
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3870
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3871
+				if (! $updated) {
3872
+					$success = 0;
3873
+				}
3874
+			}
3875
+		} else {
3876
+			// grab single id and delete
3877
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
3878
+			// get attendee
3879
+			$att = $ATT_MDL->get_one_by_ID($ATT_ID);
3880
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3881
+			$updated = $att->save();
3882
+			if (! $updated) {
3883
+				$success = 0;
3884
+			}
3885
+		}
3886
+		$what = $success > 1
3887
+			? esc_html__('Contacts', 'event_espresso')
3888
+			: esc_html__('Contact', 'event_espresso');
3889
+		$action_desc = $trash
3890
+			? esc_html__('moved to the trash', 'event_espresso')
3891
+			: esc_html__('restored', 'event_espresso');
3892
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3893
+	}
3894 3894
 }
Please login to merge, or discard this patch.
Spacing   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         // when adding a new registration...
66 66
         if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
67 67
             EE_System::do_not_cache();
68
-            if (! isset($this->_req_data['processing_registration'])
68
+            if ( ! isset($this->_req_data['processing_registration'])
69 69
                 || absint($this->_req_data['processing_registration']) !== 1
70 70
             ) {
71 71
                 // and it's NOT the attendee information reg step
@@ -658,7 +658,7 @@  discard block
 block discarded – undo
658 658
         // style
659 659
         wp_register_style(
660 660
             'espresso_reg',
661
-            REG_ASSETS_URL . 'espresso_registrations_admin.css',
661
+            REG_ASSETS_URL.'espresso_registrations_admin.css',
662 662
             array('ee-admin-css'),
663 663
             EVENT_ESPRESSO_VERSION
664 664
         );
@@ -666,7 +666,7 @@  discard block
 block discarded – undo
666 666
         // script
667 667
         wp_register_script(
668 668
             'espresso_reg',
669
-            REG_ASSETS_URL . 'espresso_registrations_admin.js',
669
+            REG_ASSETS_URL.'espresso_registrations_admin.js',
670 670
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'),
671 671
             EVENT_ESPRESSO_VERSION,
672 672
             true
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
         wp_dequeue_style('espresso_reg');
705 705
         wp_register_style(
706 706
             'espresso_att',
707
-            REG_ASSETS_URL . 'espresso_attendees_admin.css',
707
+            REG_ASSETS_URL.'espresso_attendees_admin.css',
708 708
             array('ee-admin-css'),
709 709
             EVENT_ESPRESSO_VERSION
710 710
         );
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
     {
717 717
         wp_register_script(
718 718
             'ee-spco-for-admin',
719
-            REG_ASSETS_URL . 'spco_for_admin.js',
719
+            REG_ASSETS_URL.'spco_for_admin.js',
720 720
             array('underscore', 'jquery'),
721 721
             EVENT_ESPRESSO_VERSION,
722 722
             true
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
         }
951 951
         $sc_items = array(
952 952
             'approved_status'   => array(
953
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
953
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
954 954
                 'desc'  => EEH_Template::pretty_status(
955 955
                     EEM_Registration::status_id_approved,
956 956
                     false,
@@ -958,7 +958,7 @@  discard block
 block discarded – undo
958 958
                 ),
959 959
             ),
960 960
             'pending_status'    => array(
961
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
961
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
962 962
                 'desc'  => EEH_Template::pretty_status(
963 963
                     EEM_Registration::status_id_pending_payment,
964 964
                     false,
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
                 ),
967 967
             ),
968 968
             'wait_list'         => array(
969
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
969
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
970 970
                 'desc'  => EEH_Template::pretty_status(
971 971
                     EEM_Registration::status_id_wait_list,
972 972
                     false,
@@ -974,7 +974,7 @@  discard block
 block discarded – undo
974 974
                 ),
975 975
             ),
976 976
             'incomplete_status' => array(
977
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
977
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
978 978
                 'desc'  => EEH_Template::pretty_status(
979 979
                     EEM_Registration::status_id_incomplete,
980 980
                     false,
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
                 ),
983 983
             ),
984 984
             'not_approved'      => array(
985
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
985
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
986 986
                 'desc'  => EEH_Template::pretty_status(
987 987
                     EEM_Registration::status_id_not_approved,
988 988
                     false,
@@ -990,7 +990,7 @@  discard block
 block discarded – undo
990 990
                 ),
991 991
             ),
992 992
             'declined_status'   => array(
993
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
993
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
994 994
                 'desc'  => EEH_Template::pretty_status(
995 995
                     EEM_Registration::status_id_declined,
996 996
                     false,
@@ -998,7 +998,7 @@  discard block
 block discarded – undo
998 998
                 ),
999 999
             ),
1000 1000
             'cancelled_status'  => array(
1001
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
1001
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
1002 1002
                 'desc'  => EEH_Template::pretty_status(
1003 1003
                     EEM_Registration::status_id_cancelled,
1004 1004
                     false,
@@ -1033,13 +1033,13 @@  discard block
 block discarded – undo
1033 1033
                         'event_espresso'
1034 1034
                     ),
1035 1035
                     '<h3 style="line-height:1.5em;">',
1036
-                    '<a href="' . EE_Admin_Page::add_query_args_and_nonce(
1036
+                    '<a href="'.EE_Admin_Page::add_query_args_and_nonce(
1037 1037
                         array(
1038 1038
                             'action' => 'edit_attendee',
1039 1039
                             'post'   => $ATT_ID,
1040 1040
                         ),
1041 1041
                         REG_ADMIN_URL
1042
-                    ) . '">' . $attendee->full_name() . '</a>',
1042
+                    ).'">'.$attendee->full_name().'</a>',
1043 1043
                     '</h3>'
1044 1044
                 );
1045 1045
             }
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
                 'espresso_registrations_new_registration',
1051 1051
                 $EVT_ID
1052 1052
             )) {
1053
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
1053
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button(
1054 1054
                     'new_registration',
1055 1055
                     'add-registrant',
1056 1056
                     array('event_id' => $EVT_ID),
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
1091 1091
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
1092 1092
                 $this->_template_args['admin_page_header'] .= $datetime->name();
1093
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
1093
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
1094 1094
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
1095 1095
             }
1096 1096
         }
@@ -1116,7 +1116,7 @@  discard block
 block discarded – undo
1116 1116
             return true;
1117 1117
         }
1118 1118
         $REG = EEM_Registration::instance();
1119
-        $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1119
+        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
1120 1120
         if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
1121 1121
             return true;
1122 1122
         } else {
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
             'caps'                     => EEM_Registration::caps_read_admin,
1201 1201
             'default_where_conditions' => 'this_model_only',
1202 1202
         );
1203
-        if (! $count) {
1203
+        if ( ! $count) {
1204 1204
             $query_params = array_merge(
1205 1205
                 $query_params,
1206 1206
                 $this->_get_orderby_for_registrations_query(),
@@ -1221,7 +1221,7 @@  discard block
 block discarded – undo
1221 1221
     protected function addAttendeeIdToWhereConditions(array $request)
1222 1222
     {
1223 1223
         $where = array();
1224
-        if (! empty($request['ATT_ID'])) {
1224
+        if ( ! empty($request['ATT_ID'])) {
1225 1225
             $where['ATT_ID'] = absint($request['ATT_ID']);
1226 1226
         }
1227 1227
         return $where;
@@ -1237,7 +1237,7 @@  discard block
 block discarded – undo
1237 1237
     protected function _add_event_id_to_where_conditions(array $request)
1238 1238
     {
1239 1239
         $where = array();
1240
-        if (! empty($request['event_id'])) {
1240
+        if ( ! empty($request['event_id'])) {
1241 1241
             $where['EVT_ID'] = absint($request['event_id']);
1242 1242
         }
1243 1243
         return $where;
@@ -1253,7 +1253,7 @@  discard block
 block discarded – undo
1253 1253
     protected function _add_category_id_to_where_conditions(array $request)
1254 1254
     {
1255 1255
         $where = array();
1256
-        if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1256
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
1257 1257
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1258 1258
         }
1259 1259
         return $where;
@@ -1269,10 +1269,10 @@  discard block
 block discarded – undo
1269 1269
     protected function _add_datetime_id_to_where_conditions(array $request)
1270 1270
     {
1271 1271
         $where = array();
1272
-        if (! empty($request['datetime_id'])) {
1272
+        if ( ! empty($request['datetime_id'])) {
1273 1273
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1274 1274
         }
1275
-        if (! empty($request['DTT_ID'])) {
1275
+        if ( ! empty($request['DTT_ID'])) {
1276 1276
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1277 1277
         }
1278 1278
         return $where;
@@ -1298,7 +1298,7 @@  discard block
 block discarded – undo
1298 1298
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations
1299 1299
          * UNLESS viewing trashed registrations.
1300 1300
          */
1301
-        if (! empty($registration_status)) {
1301
+        if ( ! empty($registration_status)) {
1302 1302
             $where['STS_ID'] = $registration_status;
1303 1303
         } else {
1304 1304
             // make sure we exclude incomplete registrations, but only if not trashed.
@@ -1341,12 +1341,12 @@  discard block
 block discarded – undo
1341 1341
                 array(
1342 1342
                     EEM_Registration::instance()->convert_datetime_for_query(
1343 1343
                         'REG_date',
1344
-                        $now . ' 00:00:00',
1344
+                        $now.' 00:00:00',
1345 1345
                         'Y-m-d H:i:s'
1346 1346
                     ),
1347 1347
                     EEM_Registration::instance()->convert_datetime_for_query(
1348 1348
                         'REG_date',
1349
-                        $now . ' 23:59:59',
1349
+                        $now.' 23:59:59',
1350 1350
                         'Y-m-d H:i:s'
1351 1351
                     ),
1352 1352
                 ),
@@ -1359,12 +1359,12 @@  discard block
 block discarded – undo
1359 1359
                 array(
1360 1360
                     EEM_Registration::instance()->convert_datetime_for_query(
1361 1361
                         'REG_date',
1362
-                        $current_year_and_month . '-01 00:00:00',
1362
+                        $current_year_and_month.'-01 00:00:00',
1363 1363
                         'Y-m-d H:i:s'
1364 1364
                     ),
1365 1365
                     EEM_Registration::instance()->convert_datetime_for_query(
1366 1366
                         'REG_date',
1367
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1367
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1368 1368
                         'Y-m-d H:i:s'
1369 1369
                     ),
1370 1370
                 ),
@@ -1379,18 +1379,18 @@  discard block
 block discarded – undo
1379 1379
                 : '';
1380 1380
             // if there is not a month or year then we can't go further
1381 1381
             if ($month_requested && $year_requested) {
1382
-                $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1382
+                $days_in_month = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1383 1383
                 $where['REG_date'] = array(
1384 1384
                     'BETWEEN',
1385 1385
                     array(
1386 1386
                         EEM_Registration::instance()->convert_datetime_for_query(
1387 1387
                             'REG_date',
1388
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1388
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1389 1389
                             'Y-m-d H:i:s'
1390 1390
                         ),
1391 1391
                         EEM_Registration::instance()->convert_datetime_for_query(
1392 1392
                             'REG_date',
1393
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1393
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1394 1394
                             'Y-m-d H:i:s'
1395 1395
                         ),
1396 1396
                     ),
@@ -1410,8 +1410,8 @@  discard block
 block discarded – undo
1410 1410
     protected function _add_search_to_where_conditions(array $request)
1411 1411
     {
1412 1412
         $where = array();
1413
-        if (! empty($request['s'])) {
1414
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1413
+        if ( ! empty($request['s'])) {
1414
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1415 1415
             $where['OR*search_conditions'] = array(
1416 1416
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1417 1417
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1647,7 +1647,7 @@  discard block
 block discarded – undo
1647 1647
                 )
1648 1648
                 : '';
1649 1649
             // grab header
1650
-            $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1650
+            $template_path = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1651 1651
             $this->_template_args['REG_ID'] = $this->_registration->ID();
1652 1652
             $this->_template_args['admin_page_header'] = EEH_Template::display_template(
1653 1653
                 $template_path,
@@ -1784,7 +1784,7 @@  discard block
 block discarded – undo
1784 1784
                             EEH_HTML::strong(
1785 1785
                                 $this->_registration->pretty_status(),
1786 1786
                                 '',
1787
-                                'status-' . $this->_registration->status_ID(),
1787
+                                'status-'.$this->_registration->status_ID(),
1788 1788
                                 'line-height: 1em; font-size: 1.5em; font-weight: bold;'
1789 1789
                             )
1790 1790
                         )
@@ -1839,14 +1839,14 @@  discard block
 block discarded – undo
1839 1839
     protected function _get_reg_statuses()
1840 1840
     {
1841 1841
         $reg_status_array = EEM_Registration::instance()->reg_status_array();
1842
-        unset($reg_status_array[ EEM_Registration::status_id_incomplete ]);
1842
+        unset($reg_status_array[EEM_Registration::status_id_incomplete]);
1843 1843
         // get current reg status
1844 1844
         $current_status = $this->_registration->status_ID();
1845 1845
         // is registration for free event? This will determine whether to display the pending payment option
1846 1846
         if ($current_status !== EEM_Registration::status_id_pending_payment
1847 1847
             && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00)
1848 1848
         ) {
1849
-            unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]);
1849
+            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1850 1850
         }
1851 1851
         return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1852 1852
     }
@@ -1938,7 +1938,7 @@  discard block
 block discarded – undo
1938 1938
         $success = false;
1939 1939
         // typecast $REG_IDs
1940 1940
         $REG_IDs = (array) $REG_IDs;
1941
-        if (! empty($REG_IDs)) {
1941
+        if ( ! empty($REG_IDs)) {
1942 1942
             $success = true;
1943 1943
             // set default status if none is passed
1944 1944
             $status = $status ? $status : EEM_Registration::status_id_pending_payment;
@@ -2018,11 +2018,11 @@  discard block
 block discarded – undo
2018 2018
         // unset nonces
2019 2019
         foreach ($this->_req_data as $ref => $value) {
2020 2020
             if (strpos($ref, 'nonce') !== false) {
2021
-                unset($this->_req_data[ $ref ]);
2021
+                unset($this->_req_data[$ref]);
2022 2022
                 continue;
2023 2023
             }
2024 2024
             $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
2025
-            $this->_req_data[ $ref ] = $value;
2025
+            $this->_req_data[$ref] = $value;
2026 2026
         }
2027 2027
         // merge request vars so that the reloaded list table contains any existing filter query params
2028 2028
         $route = array_merge($this->_req_data, $route);
@@ -2096,7 +2096,7 @@  discard block
 block discarded – undo
2096 2096
             $action,
2097 2097
             $notify
2098 2098
         );
2099
-        $method = $action . '_registration';
2099
+        $method = $action.'_registration';
2100 2100
         if (method_exists($this, $method)) {
2101 2101
             $this->$method($notify);
2102 2102
         }
@@ -2327,7 +2327,7 @@  discard block
 block discarded – undo
2327 2327
         $this->_template_args['REG_ID'] = $this->_registration->ID();
2328 2328
         $this->_template_args['event_id'] = $this->_registration->event_ID();
2329 2329
         $template_path =
2330
-            REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
2330
+            REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
2331 2331
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2332 2332
     }
2333 2333
 
@@ -2360,7 +2360,7 @@  discard block
 block discarded – undo
2360 2360
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
2361 2361
             $this->_template_args['REG_ID'] = $this->_registration->ID();
2362 2362
             $template_path =
2363
-                REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
2363
+                REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
2364 2364
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
2365 2365
         }
2366 2366
     }
@@ -2377,7 +2377,7 @@  discard block
 block discarded – undo
2377 2377
     public function form_before_question_group($output)
2378 2378
     {
2379 2379
         EE_Error::doing_it_wrong(
2380
-            __CLASS__ . '::' . __FUNCTION__,
2380
+            __CLASS__.'::'.__FUNCTION__,
2381 2381
             esc_html__(
2382 2382
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2383 2383
                 'event_espresso'
@@ -2402,7 +2402,7 @@  discard block
 block discarded – undo
2402 2402
     public function form_after_question_group($output)
2403 2403
     {
2404 2404
         EE_Error::doing_it_wrong(
2405
-            __CLASS__ . '::' . __FUNCTION__,
2405
+            __CLASS__.'::'.__FUNCTION__,
2406 2406
             esc_html__(
2407 2407
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2408 2408
                 'event_espresso'
@@ -2440,7 +2440,7 @@  discard block
 block discarded – undo
2440 2440
     public function form_form_field_label_wrap($label)
2441 2441
     {
2442 2442
         EE_Error::doing_it_wrong(
2443
-            __CLASS__ . '::' . __FUNCTION__,
2443
+            __CLASS__.'::'.__FUNCTION__,
2444 2444
             esc_html__(
2445 2445
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2446 2446
                 'event_espresso'
@@ -2450,7 +2450,7 @@  discard block
 block discarded – undo
2450 2450
         return '
2451 2451
 			<tr>
2452 2452
 				<th>
2453
-					' . $label . '
2453
+					' . $label.'
2454 2454
 				</th>';
2455 2455
     }
2456 2456
 
@@ -2466,7 +2466,7 @@  discard block
 block discarded – undo
2466 2466
     public function form_form_field_input__wrap($input)
2467 2467
     {
2468 2468
         EE_Error::doing_it_wrong(
2469
-            __CLASS__ . '::' . __FUNCTION__,
2469
+            __CLASS__.'::'.__FUNCTION__,
2470 2470
             esc_html__(
2471 2471
                 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.',
2472 2472
                 'event_espresso'
@@ -2475,7 +2475,7 @@  discard block
 block discarded – undo
2475 2475
         );
2476 2476
         return '
2477 2477
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
2478
-					' . $input . '
2478
+					' . $input.'
2479 2479
 				</td>
2480 2480
 			</tr>';
2481 2481
     }
@@ -2519,8 +2519,8 @@  discard block
 block discarded – undo
2519 2519
      */
2520 2520
     protected function _get_reg_custom_questions_form($REG_ID)
2521 2521
     {
2522
-        if (! $this->_reg_custom_questions_form) {
2523
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
2522
+        if ( ! $this->_reg_custom_questions_form) {
2523
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
2524 2524
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
2525 2525
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
2526 2526
             );
@@ -2543,7 +2543,7 @@  discard block
 block discarded – undo
2543 2543
      */
2544 2544
     private function _save_reg_custom_questions_form($REG_ID = false)
2545 2545
     {
2546
-        if (! $REG_ID) {
2546
+        if ( ! $REG_ID) {
2547 2547
             EE_Error::add_error(
2548 2548
                 esc_html__(
2549 2549
                     'An error occurred. No registration ID was received.',
@@ -2634,30 +2634,30 @@  discard block
 block discarded – undo
2634 2634
                     ? $registration->attendee()
2635 2635
                     : EEM_Attendee::instance()
2636 2636
                                   ->create_default_object();
2637
-                $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID();
2638
-                $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname();
2639
-                $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname();
2640
-                $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email();
2641
-                $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price();
2642
-                $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode(
2637
+                $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID();
2638
+                $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname();
2639
+                $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname();
2640
+                $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email();
2641
+                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();
2642
+                $this->_template_args['attendees'][$att_nmbr]['address'] = implode(
2643 2643
                     ', ',
2644 2644
                     $attendee->full_address_as_array()
2645 2645
                 );
2646
-                $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce(
2646
+                $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce(
2647 2647
                     array(
2648 2648
                         'action' => 'edit_attendee',
2649 2649
                         'post'   => $attendee->ID(),
2650 2650
                     ),
2651 2651
                     REG_ADMIN_URL
2652 2652
                 );
2653
-                $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event
2653
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj() instanceof EE_Event
2654 2654
                     ? $registration->event_obj()->name()
2655 2655
                     : '';
2656 2656
                 $att_nmbr++;
2657 2657
             }
2658 2658
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2659 2659
         }
2660
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2660
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2661 2661
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2662 2662
     }
2663 2663
 
@@ -2681,11 +2681,11 @@  discard block
 block discarded – undo
2681 2681
         // now let's determine if this is not the primary registration.  If it isn't then we set the
2682 2682
         // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the
2683 2683
         // primary registration object (that way we know if we need to show create button or not)
2684
-        if (! $this->_registration->is_primary_registrant()) {
2684
+        if ( ! $this->_registration->is_primary_registrant()) {
2685 2685
             $primary_registration = $this->_registration->get_primary_registration();
2686 2686
             $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2687 2687
                 : null;
2688
-            if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2688
+            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2689 2689
                 // in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own
2690 2690
                 // custom attendee object so let's not worry about the primary reg.
2691 2691
                 $primary_registration = null;
@@ -2719,7 +2719,7 @@  discard block
 block discarded – undo
2719 2719
             ) : '';
2720 2720
         $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso');
2721 2721
         $this->_template_args['att_check'] = $att_check;
2722
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2722
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2723 2723
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2724 2724
     }
2725 2725
 
@@ -2757,7 +2757,7 @@  discard block
 block discarded – undo
2757 2757
         $success = 0;
2758 2758
         $overwrite_msgs = false;
2759 2759
         // Checkboxes
2760
-        if (! is_array($this->_req_data['_REG_ID'])) {
2760
+        if ( ! is_array($this->_req_data['_REG_ID'])) {
2761 2761
             $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']);
2762 2762
         }
2763 2763
         $reg_count = count($this->_req_data['_REG_ID']);
@@ -2766,7 +2766,7 @@  discard block
 block discarded – undo
2766 2766
             /** @var EE_Registration $REG */
2767 2767
             $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID);
2768 2768
             $payments = $REG->registration_payments();
2769
-            if (! empty($payments)) {
2769
+            if ( ! empty($payments)) {
2770 2770
                 $name = $REG->attendee() instanceof EE_Attendee
2771 2771
                     ? $REG->attendee()->full_name()
2772 2772
                     : esc_html__('Unknown Attendee', 'event_espresso');
@@ -2827,17 +2827,17 @@  discard block
 block discarded – undo
2827 2827
         $REG_MDL = EEM_Registration::instance();
2828 2828
         $success = 1;
2829 2829
         // Checkboxes
2830
-        if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2830
+        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2831 2831
             // if array has more than one element than success message should be plural
2832 2832
             $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2833 2833
             // cycle thru checkboxes
2834 2834
             while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2835 2835
                 $REG = $REG_MDL->get_one_by_ID($REG_ID);
2836
-                if (! $REG instanceof EE_Registration) {
2836
+                if ( ! $REG instanceof EE_Registration) {
2837 2837
                     continue;
2838 2838
                 }
2839 2839
                 $deleted = $this->_delete_registration($REG);
2840
-                if (! $deleted) {
2840
+                if ( ! $deleted) {
2841 2841
                     $success = 0;
2842 2842
                 }
2843 2843
             }
@@ -2846,7 +2846,7 @@  discard block
 block discarded – undo
2846 2846
             $REG_ID = $this->_req_data['_REG_ID'];
2847 2847
             $REG = $REG_MDL->get_one_by_ID($REG_ID);
2848 2848
             $deleted = $this->_delete_registration($REG);
2849
-            if (! $deleted) {
2849
+            if ( ! $deleted) {
2850 2850
                 $success = 0;
2851 2851
             }
2852 2852
         }
@@ -2880,11 +2880,11 @@  discard block
 block discarded – undo
2880 2880
         $REGS = $TXN->get_many_related('Registration');
2881 2881
         $all_trashed = true;
2882 2882
         foreach ($REGS as $registration) {
2883
-            if (! $registration->get('REG_deleted')) {
2883
+            if ( ! $registration->get('REG_deleted')) {
2884 2884
                 $all_trashed = false;
2885 2885
             }
2886 2886
         }
2887
-        if (! $all_trashed) {
2887
+        if ( ! $all_trashed) {
2888 2888
             EE_Error::add_error(
2889 2889
                 esc_html__(
2890 2890
                     'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
@@ -2943,7 +2943,7 @@  discard block
 block discarded – undo
2943 2943
      */
2944 2944
     public function new_registration()
2945 2945
     {
2946
-        if (! $this->_set_reg_event()) {
2946
+        if ( ! $this->_set_reg_event()) {
2947 2947
             throw new EE_Error(
2948 2948
                 esc_html__(
2949 2949
                     'Unable to continue with registering because there is no Event ID in the request',
@@ -2953,8 +2953,8 @@  discard block
 block discarded – undo
2953 2953
         }
2954 2954
         EE_Registry::instance()->REQ->set_espresso_page(true);
2955 2955
         // gotta start with a clean slate if we're not coming here via ajax
2956
-        if (! defined('DOING_AJAX')
2957
-            && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2956
+        if ( ! defined('DOING_AJAX')
2957
+            && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2958 2958
         ) {
2959 2959
             EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2960 2960
         }
@@ -2987,7 +2987,7 @@  discard block
 block discarded – undo
2987 2987
         }
2988 2988
         // grab header
2989 2989
         $template_path =
2990
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2990
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2991 2991
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2992 2992
             $template_path,
2993 2993
             $this->_template_args,
@@ -3028,7 +3028,7 @@  discard block
 block discarded – undo
3028 3028
                 '</b>'
3029 3029
             );
3030 3030
             return '
3031
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
3031
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
3032 3032
 	<script >
3033 3033
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
3034 3034
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -3096,7 +3096,7 @@  discard block
 block discarded – undo
3096 3096
         // we come back to the process_registration_step route.
3097 3097
         $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields);
3098 3098
         return EEH_Template::display_template(
3099
-            REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php',
3099
+            REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php',
3100 3100
             $template_args,
3101 3101
             true
3102 3102
         );
@@ -3118,8 +3118,8 @@  discard block
 block discarded – undo
3118 3118
         if (is_object($this->_reg_event)) {
3119 3119
             return true;
3120 3120
         }
3121
-        $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3122
-        if (! $EVT_ID) {
3121
+        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
3122
+        if ( ! $EVT_ID) {
3123 3123
             return false;
3124 3124
         }
3125 3125
         $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
@@ -3151,8 +3151,8 @@  discard block
 block discarded – undo
3151 3151
         $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
3152 3152
         // if doing ajax then we need to verify the nonce
3153 3153
         if (defined('DOING_AJAX')) {
3154
-            $nonce = isset($this->_req_data[ $this->_req_nonce ])
3155
-                ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : '';
3154
+            $nonce = isset($this->_req_data[$this->_req_nonce])
3155
+                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
3156 3156
             $this->_verify_nonce($nonce, $this->_req_nonce);
3157 3157
         }
3158 3158
         switch ($step) {
@@ -3188,7 +3188,7 @@  discard block
 block discarded – undo
3188 3188
                 }
3189 3189
                 break;
3190 3190
             case 'questions':
3191
-                if (! isset(
3191
+                if ( ! isset(
3192 3192
                     $this->_req_data['txn_reg_status_change'],
3193 3193
                     $this->_req_data['txn_reg_status_change']['send_notifications']
3194 3194
                 )
@@ -3203,7 +3203,7 @@  discard block
 block discarded – undo
3203 3203
                         $grand_total->save_this_and_descendants_to_txn();
3204 3204
                     }
3205 3205
                 }
3206
-                if (! $transaction instanceof EE_Transaction) {
3206
+                if ( ! $transaction instanceof EE_Transaction) {
3207 3207
                     $query_args = array(
3208 3208
                         'action'                  => 'new_registration',
3209 3209
                         'processing_registration' => 2,
@@ -3226,7 +3226,7 @@  discard block
 block discarded – undo
3226 3226
                     }
3227 3227
                 }
3228 3228
                 // maybe update status, and make sure to save transaction if not done already
3229
-                if (! $transaction->update_status_based_on_total_paid()) {
3229
+                if ( ! $transaction->update_status_based_on_total_paid()) {
3230 3230
                     $transaction->save();
3231 3231
                 }
3232 3232
                 EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
@@ -3309,7 +3309,7 @@  discard block
 block discarded – undo
3309 3309
     public function get_attendees($per_page, $count = false, $trash = false)
3310 3310
     {
3311 3311
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
3312
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
3312
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
3313 3313
         $ATT_MDL = EEM_Attendee::instance();
3314 3314
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
3315 3315
         switch ($this->_req_data['orderby']) {
@@ -3348,8 +3348,8 @@  discard block
 block discarded – undo
3348 3348
             ? $this->_req_data['perpage']
3349 3349
             : $per_page;
3350 3350
         $_where = array();
3351
-        if (! empty($this->_req_data['s'])) {
3352
-            $sstr = '%' . $this->_req_data['s'] . '%';
3351
+        if ( ! empty($this->_req_data['s'])) {
3352
+            $sstr = '%'.$this->_req_data['s'].'%';
3353 3353
             $_where['OR'] = array(
3354 3354
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
3355 3355
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -3376,7 +3376,7 @@  discard block
 block discarded – undo
3376 3376
             'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')),
3377 3377
             'limit'         => $limit,
3378 3378
         );
3379
-        if (! $count) {
3379
+        if ( ! $count) {
3380 3380
             $query_args['order_by'] = array($orderby => $sort);
3381 3381
         }
3382 3382
         if ($trash) {
@@ -3419,7 +3419,7 @@  discard block
 block discarded – undo
3419 3419
      */
3420 3420
     public function _registrations_report_base($method_name_for_getting_query_params)
3421 3421
     {
3422
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3422
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3423 3423
             wp_redirect(
3424 3424
                 EE_Admin_Page::add_query_args_and_nonce(
3425 3425
                     array(
@@ -3451,8 +3451,8 @@  discard block
 block discarded – undo
3451 3451
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
3452 3452
             );
3453 3453
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
3454
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3455
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3454
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3455
+                require_once(EE_CLASSES.'EE_Export.class.php');
3456 3456
                 $EE_Export = EE_Export::instance($this->_req_data);
3457 3457
                 $EE_Export->export();
3458 3458
             }
@@ -3473,8 +3473,8 @@  discard block
 block discarded – undo
3473 3473
 
3474 3474
     public function _contact_list_export()
3475 3475
     {
3476
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3477
-            require_once(EE_CLASSES . 'EE_Export.class.php');
3476
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3477
+            require_once(EE_CLASSES.'EE_Export.class.php');
3478 3478
             $EE_Export = EE_Export::instance($this->_req_data);
3479 3479
             $EE_Export->export_attendees();
3480 3480
         }
@@ -3483,7 +3483,7 @@  discard block
 block discarded – undo
3483 3483
 
3484 3484
     public function _contact_list_report()
3485 3485
     {
3486
-        if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3486
+        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
3487 3487
             wp_redirect(
3488 3488
                 EE_Admin_Page::add_query_args_and_nonce(
3489 3489
                     array(
@@ -3495,8 +3495,8 @@  discard block
 block discarded – undo
3495 3495
                 )
3496 3496
             );
3497 3497
         } else {
3498
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
3499
-                require_once(EE_CLASSES . 'EE_Export.class.php');
3498
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
3499
+                require_once(EE_CLASSES.'EE_Export.class.php');
3500 3500
                 $EE_Export = EE_Export::instance($this->_req_data);
3501 3501
                 $EE_Export->report_attendees();
3502 3502
             }
@@ -3582,7 +3582,7 @@  discard block
 block discarded – undo
3582 3582
             $updated_fields = array(
3583 3583
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
3584 3584
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
3585
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
3585
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
3586 3586
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
3587 3587
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
3588 3588
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -3658,17 +3658,17 @@  discard block
 block discarded – undo
3658 3658
             'postexcerpt',
3659 3659
             esc_html__('Excerpt', 'event_espresso'),
3660 3660
             'post_excerpt_meta_box',
3661
-            $this->_cpt_routes[ $this->_req_action ],
3661
+            $this->_cpt_routes[$this->_req_action],
3662 3662
             'normal',
3663 3663
             'core'
3664 3664
         );
3665
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core');
3665
+        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
3666 3666
         if (post_type_supports('espresso_attendees', 'excerpt')) {
3667 3667
             add_meta_box(
3668 3668
                 'postexcerpt',
3669 3669
                 esc_html__('Short Biography', 'event_espresso'),
3670 3670
                 'post_excerpt_meta_box',
3671
-                $this->_cpt_routes[ $this->_req_action ],
3671
+                $this->_cpt_routes[$this->_req_action],
3672 3672
                 'normal'
3673 3673
             );
3674 3674
         }
@@ -3677,7 +3677,7 @@  discard block
 block discarded – undo
3677 3677
                 'commentsdiv',
3678 3678
                 esc_html__('Notes on the Contact', 'event_espresso'),
3679 3679
                 'post_comment_meta_box',
3680
-                $this->_cpt_routes[ $this->_req_action ],
3680
+                $this->_cpt_routes[$this->_req_action],
3681 3681
                 'normal',
3682 3682
                 'core'
3683 3683
             );
@@ -3686,7 +3686,7 @@  discard block
 block discarded – undo
3686 3686
             'attendee_contact_info',
3687 3687
             esc_html__('Contact Info', 'event_espresso'),
3688 3688
             array($this, 'attendee_contact_info'),
3689
-            $this->_cpt_routes[ $this->_req_action ],
3689
+            $this->_cpt_routes[$this->_req_action],
3690 3690
             'side',
3691 3691
             'core'
3692 3692
         );
@@ -3694,7 +3694,7 @@  discard block
 block discarded – undo
3694 3694
             'attendee_details_address',
3695 3695
             esc_html__('Address Details', 'event_espresso'),
3696 3696
             array($this, 'attendee_address_details'),
3697
-            $this->_cpt_routes[ $this->_req_action ],
3697
+            $this->_cpt_routes[$this->_req_action],
3698 3698
             'normal',
3699 3699
             'core'
3700 3700
         );
@@ -3702,7 +3702,7 @@  discard block
 block discarded – undo
3702 3702
             'attendee_registrations',
3703 3703
             esc_html__('Registrations for this Contact', 'event_espresso'),
3704 3704
             array($this, 'attendee_registrations_meta_box'),
3705
-            $this->_cpt_routes[ $this->_req_action ],
3705
+            $this->_cpt_routes[$this->_req_action],
3706 3706
             'normal',
3707 3707
             'high'
3708 3708
         );
@@ -3803,7 +3803,7 @@  discard block
 block discarded – undo
3803 3803
             )
3804 3804
         );
3805 3805
         $template =
3806
-            REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
3806
+            REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
3807 3807
         EEH_Template::display_template($template, $this->_template_args);
3808 3808
     }
3809 3809
 
@@ -3822,7 +3822,7 @@  discard block
 block discarded – undo
3822 3822
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
3823 3823
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
3824 3824
         $template =
3825
-            REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
3825
+            REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
3826 3826
         EEH_Template::display_template($template, $this->_template_args);
3827 3827
     }
3828 3828
 
@@ -3837,7 +3837,7 @@  discard block
 block discarded – undo
3837 3837
     public function after_title_form_fields($post)
3838 3838
     {
3839 3839
         if ($post->post_type == 'espresso_attendees') {
3840
-            $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
3840
+            $template = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
3841 3841
             $template_args['attendee'] = $this->_cpt_model_obj;
3842 3842
             EEH_Template::display_template($template, $template_args);
3843 3843
         }
@@ -3861,14 +3861,14 @@  discard block
 block discarded – undo
3861 3861
         $ATT_MDL = EEM_Attendee::instance();
3862 3862
         $success = 1;
3863 3863
         // Checkboxes
3864
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3864
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
3865 3865
             // if array has more than one element than success message should be plural
3866 3866
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
3867 3867
             // cycle thru checkboxes
3868 3868
             while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
3869 3869
                 $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
3870 3870
                     : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
3871
-                if (! $updated) {
3871
+                if ( ! $updated) {
3872 3872
                     $success = 0;
3873 3873
                 }
3874 3874
             }
@@ -3879,7 +3879,7 @@  discard block
 block discarded – undo
3879 3879
             $att = $ATT_MDL->get_one_by_ID($ATT_ID);
3880 3880
             $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3881 3881
             $updated = $att->save();
3882
-            if (! $updated) {
3882
+            if ( ! $updated) {
3883 3883
                 $success = 0;
3884 3884
             }
3885 3885
         }
Please login to merge, or discard this patch.