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