Completed
Branch FET-10840-domain-class (a1fdb0)
by
unknown
139:37 queued 128:02
created
caffeinated/admin/extend/events/Extend_Events_Admin_Page.core.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
      * Returns template for the additional datetime.
340 340
      * @param $template
341 341
      * @param $template_args
342
-     * @return mixed
342
+     * @return string
343 343
      * @throws DomainException
344 344
      */
345 345
     public function add_additional_datetime_button($template, $template_args)
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
      * Returns the template for cloning a datetime.
357 357
      * @param $template
358 358
      * @param $template_args
359
-     * @return mixed
359
+     * @return string
360 360
      * @throws DomainException
361 361
      */
362 362
     public function add_datetime_clone_button($template, $template_args)
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
      * Returns the template for datetime timezones.
374 374
      * @param $template
375 375
      * @param $template_args
376
-     * @return mixed
376
+     * @return string
377 377
      * @throws DomainException
378 378
      */
379 379
     public function datetime_timezones_template($template, $template_args)
Please login to merge, or discard this patch.
Indentation   +1235 added lines, -1235 removed lines patch added patch discarded remove patch
@@ -14,1239 +14,1239 @@
 block discarded – undo
14 14
 {
15 15
 
16 16
 
17
-    /**
18
-     * Extend_Events_Admin_Page constructor.
19
-     *
20
-     * @param bool $routing
21
-     */
22
-    public function __construct($routing = true)
23
-    {
24
-        parent::__construct($routing);
25
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
26
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
27
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
28
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
29
-        }
30
-    }
31
-
32
-
33
-    /**
34
-     * Sets routes.
35
-     */
36
-    protected function _extend_page_config()
37
-    {
38
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
-        //is there a evt_id in the request?
40
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
-            ? $this->_req_data['EVT_ID']
42
-            : 0;
43
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
-        //tkt_id?
45
-        $tkt_id             = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
-            ? $this->_req_data['TKT_ID']
47
-            : 0;
48
-        $new_page_routes    = array(
49
-            'duplicate_event'          => array(
50
-                'func'       => '_duplicate_event',
51
-                'capability' => 'ee_edit_event',
52
-                'obj_id'     => $evt_id,
53
-                'noheader'   => true,
54
-            ),
55
-            'ticket_list_table'        => array(
56
-                'func'       => '_tickets_overview_list_table',
57
-                'capability' => 'ee_read_default_tickets',
58
-            ),
59
-            'trash_ticket'             => array(
60
-                'func'       => '_trash_or_restore_ticket',
61
-                'capability' => 'ee_delete_default_ticket',
62
-                'obj_id'     => $tkt_id,
63
-                'noheader'   => true,
64
-                'args'       => array('trash' => true),
65
-            ),
66
-            'trash_tickets'            => array(
67
-                'func'       => '_trash_or_restore_ticket',
68
-                'capability' => 'ee_delete_default_tickets',
69
-                'noheader'   => true,
70
-                'args'       => array('trash' => true),
71
-            ),
72
-            'restore_ticket'           => array(
73
-                'func'       => '_trash_or_restore_ticket',
74
-                'capability' => 'ee_delete_default_ticket',
75
-                'obj_id'     => $tkt_id,
76
-                'noheader'   => true,
77
-            ),
78
-            'restore_tickets'          => array(
79
-                'func'       => '_trash_or_restore_ticket',
80
-                'capability' => 'ee_delete_default_tickets',
81
-                'noheader'   => true,
82
-            ),
83
-            'delete_ticket'            => array(
84
-                'func'       => '_delete_ticket',
85
-                'capability' => 'ee_delete_default_ticket',
86
-                'obj_id'     => $tkt_id,
87
-                'noheader'   => true,
88
-            ),
89
-            'delete_tickets'           => array(
90
-                'func'       => '_delete_ticket',
91
-                'capability' => 'ee_delete_default_tickets',
92
-                'noheader'   => true,
93
-            ),
94
-            'import_page'              => array(
95
-                'func'       => '_import_page',
96
-                'capability' => 'import',
97
-            ),
98
-            'import'                   => array(
99
-                'func'       => '_import_events',
100
-                'capability' => 'import',
101
-                'noheader'   => true,
102
-            ),
103
-            'import_events'            => array(
104
-                'func'       => '_import_events',
105
-                'capability' => 'import',
106
-                'noheader'   => true,
107
-            ),
108
-            'export_events'            => array(
109
-                'func'       => '_events_export',
110
-                'capability' => 'export',
111
-                'noheader'   => true,
112
-            ),
113
-            'export_categories'        => array(
114
-                'func'       => '_categories_export',
115
-                'capability' => 'export',
116
-                'noheader'   => true,
117
-            ),
118
-            'sample_export_file'       => array(
119
-                'func'       => '_sample_export_file',
120
-                'capability' => 'export',
121
-                'noheader'   => true,
122
-            ),
123
-            'update_template_settings' => array(
124
-                'func'       => '_update_template_settings',
125
-                'capability' => 'manage_options',
126
-                'noheader'   => true,
127
-            ),
128
-        );
129
-        $this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
-        //partial route/config override
131
-        $this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
-        $this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
-        $this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
-        $this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
-        $this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
-        $this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
-        //add tickets tab but only if there are more than one default ticket!
138
-        $tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
-            array(array('TKT_is_default' => 1)),
140
-            'TKT_ID',
141
-            true
142
-        );
143
-        if ($tkt_count > 1) {
144
-            $new_page_config = array(
145
-                'ticket_list_table' => array(
146
-                    'nav'           => array(
147
-                        'label' => esc_html__('Default Tickets', 'event_espresso'),
148
-                        'order' => 60,
149
-                    ),
150
-                    'list_table'    => 'Tickets_List_Table',
151
-                    'require_nonce' => false,
152
-                ),
153
-            );
154
-        }
155
-        //template settings
156
-        $new_page_config['template_settings'] = array(
157
-            'nav'           => array(
158
-                'label' => esc_html__('Templates', 'event_espresso'),
159
-                'order' => 30,
160
-            ),
161
-            'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
-            'help_tabs'     => array(
163
-                'general_settings_templates_help_tab' => array(
164
-                    'title'    => esc_html__('Templates', 'event_espresso'),
165
-                    'filename' => 'general_settings_templates',
166
-                ),
167
-            ),
168
-            'help_tour'     => array('Templates_Help_Tour'),
169
-            'require_nonce' => false,
170
-        );
171
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
172
-        //add filters and actions
173
-        //modifying _views
174
-        add_filter(
175
-            'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
-            array($this, 'add_additional_datetime_button'),
177
-            10,
178
-            2
179
-        );
180
-        add_filter(
181
-            'FHEE_event_datetime_metabox_clone_button_template',
182
-            array($this, 'add_datetime_clone_button'),
183
-            10,
184
-            2
185
-        );
186
-        add_filter(
187
-            'FHEE_event_datetime_metabox_timezones_template',
188
-            array($this, 'datetime_timezones_template'),
189
-            10,
190
-            2
191
-        );
192
-        //filters for event list table
193
-        add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
-        add_filter(
195
-            'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
-            array($this, 'extra_list_table_actions'),
197
-            10,
198
-            2
199
-        );
200
-        //legend item
201
-        add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
-        add_action('admin_init', array($this, 'admin_init'));
203
-        //heartbeat stuff
204
-        add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
-    }
206
-
207
-
208
-    /**
209
-     * admin_init
210
-     */
211
-    public function admin_init()
212
-    {
213
-        EE_Registry::$i18n_js_strings = array_merge(
214
-            EE_Registry::$i18n_js_strings,
215
-            array(
216
-                'image_confirm'          => esc_html__(
217
-                    'Do you really want to delete this image? Please remember to update your event to complete the removal.',
218
-                    'event_espresso'
219
-                ),
220
-                'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
221
-                'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
222
-                'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
223
-                'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
224
-                'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
225
-            )
226
-        );
227
-    }
228
-
229
-
230
-    /**
231
-     * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
232
-     * accordingly.
233
-     *
234
-     * @param array $response The existing heartbeat response array.
235
-     * @param array $data     The incoming data package.
236
-     * @return array  possibly appended response.
237
-     */
238
-    public function heartbeat_response($response, $data)
239
-    {
240
-        /**
241
-         * check whether count of tickets is approaching the potential
242
-         * limits for the server.
243
-         */
244
-        if (! empty($data['input_count'])) {
245
-            $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
246
-                $data['input_count']
247
-            );
248
-        }
249
-        return $response;
250
-    }
251
-
252
-
253
-    /**
254
-     * Add per page screen options to the default ticket list table view.
255
-     */
256
-    protected function _add_screen_options_ticket_list_table()
257
-    {
258
-        $this->_per_page_screen_option();
259
-    }
260
-
261
-
262
-    /**
263
-     * @param string $return
264
-     * @param int    $id
265
-     * @param string $new_title
266
-     * @param string $new_slug
267
-     * @return string
268
-     */
269
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
270
-    {
271
-        $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
272
-        //make sure this is only when editing
273
-        if (! empty($id)) {
274
-            $href   = EE_Admin_Page::add_query_args_and_nonce(
275
-                array('action' => 'duplicate_event', 'EVT_ID' => $id),
276
-                $this->_admin_base_url
277
-            );
278
-            $title  = esc_attr__('Duplicate Event', 'event_espresso');
279
-            $return .= '<a href="'
280
-                       . $href
281
-                       . '" title="'
282
-                       . $title
283
-                       . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
284
-                       . $title
285
-                       . '</button>';
286
-        }
287
-        return $return;
288
-    }
289
-
290
-
291
-    /**
292
-     * Set the list table views for the default ticket list table view.
293
-     */
294
-    public function _set_list_table_views_ticket_list_table()
295
-    {
296
-        $this->_views = array(
297
-            'all'     => array(
298
-                'slug'        => 'all',
299
-                'label'       => esc_html__('All', 'event_espresso'),
300
-                'count'       => 0,
301
-                'bulk_action' => array(
302
-                    'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
303
-                ),
304
-            ),
305
-            'trashed' => array(
306
-                'slug'        => 'trashed',
307
-                'label'       => esc_html__('Trash', 'event_espresso'),
308
-                'count'       => 0,
309
-                'bulk_action' => array(
310
-                    'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
311
-                    'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
312
-                ),
313
-            ),
314
-        );
315
-    }
316
-
317
-
318
-    /**
319
-     * Enqueue scripts and styles for the event editor.
320
-     */
321
-    public function load_scripts_styles_edit()
322
-    {
323
-        wp_register_script(
324
-            'ee-event-editor-heartbeat',
325
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
326
-            array('ee_admin_js', 'heartbeat'),
327
-            EVENT_ESPRESSO_VERSION,
328
-            true
329
-        );
330
-        wp_enqueue_script('ee-accounting');
331
-        //styles
332
-        wp_enqueue_style('espresso-ui-theme');
333
-        wp_enqueue_script('event_editor_js');
334
-        wp_enqueue_script('ee-event-editor-heartbeat');
335
-    }
336
-
337
-
338
-    /**
339
-     * Returns template for the additional datetime.
340
-     * @param $template
341
-     * @param $template_args
342
-     * @return mixed
343
-     * @throws DomainException
344
-     */
345
-    public function add_additional_datetime_button($template, $template_args)
346
-    {
347
-        return EEH_Template::display_template(
348
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
349
-            $template_args,
350
-            true
351
-        );
352
-    }
353
-
354
-
355
-    /**
356
-     * Returns the template for cloning a datetime.
357
-     * @param $template
358
-     * @param $template_args
359
-     * @return mixed
360
-     * @throws DomainException
361
-     */
362
-    public function add_datetime_clone_button($template, $template_args)
363
-    {
364
-        return EEH_Template::display_template(
365
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
366
-            $template_args,
367
-            true
368
-        );
369
-    }
370
-
371
-
372
-    /**
373
-     * Returns the template for datetime timezones.
374
-     * @param $template
375
-     * @param $template_args
376
-     * @return mixed
377
-     * @throws DomainException
378
-     */
379
-    public function datetime_timezones_template($template, $template_args)
380
-    {
381
-        return EEH_Template::display_template(
382
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
383
-            $template_args,
384
-            true
385
-        );
386
-    }
387
-
388
-
389
-    /**
390
-     * Sets the views for the default list table view.
391
-     */
392
-    protected function _set_list_table_views_default()
393
-    {
394
-        parent::_set_list_table_views_default();
395
-        $new_views    = array(
396
-            'today' => array(
397
-                'slug'        => 'today',
398
-                'label'       => esc_html__('Today', 'event_espresso'),
399
-                'count'       => $this->total_events_today(),
400
-                'bulk_action' => array(
401
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
-                ),
403
-            ),
404
-            'month' => array(
405
-                'slug'        => 'month',
406
-                'label'       => esc_html__('This Month', 'event_espresso'),
407
-                'count'       => $this->total_events_this_month(),
408
-                'bulk_action' => array(
409
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
410
-                ),
411
-            ),
412
-        );
413
-        $this->_views = array_merge($this->_views, $new_views);
414
-    }
415
-
416
-
417
-    /**
418
-     * Returns the extra action links for the default list table view.
419
-     * @param array     $action_links
420
-     * @param \EE_Event $event
421
-     * @return array
422
-     * @throws EE_Error
423
-     */
424
-    public function extra_list_table_actions(array $action_links, \EE_Event $event)
425
-    {
426
-        if (EE_Registry::instance()->CAP->current_user_can(
427
-            'ee_read_registrations',
428
-            'espresso_registrations_reports',
429
-            $event->ID()
430
-        )
431
-        ) {
432
-            $reports_query_args = array(
433
-                'action' => 'reports',
434
-                'EVT_ID' => $event->ID(),
435
-            );
436
-            $reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
437
-            $action_links[]     = '<a href="'
438
-                                  . $reports_link
439
-                                  . '" title="'
440
-                                  . esc_attr__('View Report', 'event_espresso')
441
-                                  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
442
-                                  . "\n\t";
443
-        }
444
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
445
-            EE_Registry::instance()->load_helper('MSG_Template');
446
-            $action_links[] = EEH_MSG_Template::get_message_action_link(
447
-                'see_notifications_for',
448
-                null,
449
-                array('EVT_ID' => $event->ID())
450
-            );
451
-        }
452
-        return $action_links;
453
-    }
454
-
455
-
456
-    /**
457
-     * @param $items
458
-     * @return mixed
459
-     */
460
-    public function additional_legend_items($items)
461
-    {
462
-        if (EE_Registry::instance()->CAP->current_user_can(
463
-            'ee_read_registrations',
464
-            'espresso_registrations_reports'
465
-        )
466
-        ) {
467
-            $items['reports'] = array(
468
-                'class' => 'dashicons dashicons-chart-bar',
469
-                'desc'  => esc_html__('Event Reports', 'event_espresso'),
470
-            );
471
-        }
472
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
473
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
474
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
475
-                $items['view_related_messages'] = array(
476
-                    'class' => $related_for_icon['css_class'],
477
-                    'desc'  => $related_for_icon['label'],
478
-                );
479
-            }
480
-        }
481
-        return $items;
482
-    }
483
-
484
-
485
-    /**
486
-     * This is the callback method for the duplicate event route
487
-     * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
488
-     * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
489
-     * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
490
-     * After duplication the redirect is to the new event edit page.
491
-     *
492
-     * @return void
493
-     * @access protected
494
-     * @throws EE_Error If EE_Event is not available with given ID
495
-     */
496
-    protected function _duplicate_event()
497
-    {
498
-        // first make sure the ID for the event is in the request.
499
-        //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
500
-        if (! isset($this->_req_data['EVT_ID'])) {
501
-            EE_Error::add_error(
502
-                esc_html__(
503
-                    'In order to duplicate an event an Event ID is required.  None was given.',
504
-                    'event_espresso'
505
-                ),
506
-                __FILE__,
507
-                __FUNCTION__,
508
-                __LINE__
509
-            );
510
-            $this->_redirect_after_action(false, '', '', array(), true);
511
-            return;
512
-        }
513
-        //k we've got EVT_ID so let's use that to get the event we'll duplicate
514
-        $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
515
-        if (! $orig_event instanceof EE_Event) {
516
-            throw new EE_Error(
517
-                sprintf(
518
-                    esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
519
-                    $this->_req_data['EVT_ID']
520
-                )
521
-            );
522
-        }
523
-        //k now let's clone the $orig_event before getting relations
524
-        $new_event = clone $orig_event;
525
-        //original datetimes
526
-        $orig_datetimes = $orig_event->get_many_related('Datetime');
527
-        //other original relations
528
-        $orig_ven = $orig_event->get_many_related('Venue');
529
-        //reset the ID and modify other details to make it clear this is a dupe
530
-        $new_event->set('EVT_ID', 0);
531
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
532
-        $new_event->set('EVT_name', $new_name);
533
-        $new_event->set(
534
-            'EVT_slug',
535
-            wp_unique_post_slug(
536
-                sanitize_title($orig_event->name()),
537
-                0,
538
-                'publish',
539
-                'espresso_events',
540
-                0
541
-            )
542
-        );
543
-        $new_event->set('status', 'draft');
544
-        //duplicate discussion settings
545
-        $new_event->set('comment_status', $orig_event->get('comment_status'));
546
-        $new_event->set('ping_status', $orig_event->get('ping_status'));
547
-        //save the new event
548
-        $new_event->save();
549
-        //venues
550
-        foreach ($orig_ven as $ven) {
551
-            $new_event->_add_relation_to($ven, 'Venue');
552
-        }
553
-        $new_event->save();
554
-        //now we need to get the question group relations and handle that
555
-        //first primary question groups
556
-        $orig_primary_qgs = $orig_event->get_many_related(
557
-            'Question_Group',
558
-            array(array('Event_Question_Group.EQG_primary' => 1))
559
-        );
560
-        if (! empty($orig_primary_qgs)) {
561
-            foreach ($orig_primary_qgs as $id => $obj) {
562
-                if ($obj instanceof EE_Question_Group) {
563
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
564
-                }
565
-            }
566
-        }
567
-        //next additional attendee question groups
568
-        $orig_additional_qgs = $orig_event->get_many_related(
569
-            'Question_Group',
570
-            array(array('Event_Question_Group.EQG_primary' => 0))
571
-        );
572
-        if (! empty($orig_additional_qgs)) {
573
-            foreach ($orig_additional_qgs as $id => $obj) {
574
-                if ($obj instanceof EE_Question_Group) {
575
-                    $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
576
-                }
577
-            }
578
-        }
579
-        //now save
580
-        $new_event->save();
581
-        //k now that we have the new event saved we can loop through the datetimes and start adding relations.
582
-        $cloned_tickets = array();
583
-        foreach ($orig_datetimes as $orig_dtt) {
584
-            if (! $orig_dtt instanceof EE_Datetime) {
585
-                continue;
586
-            }
587
-            $new_dtt   = clone $orig_dtt;
588
-            $orig_tkts = $orig_dtt->tickets();
589
-            //save new dtt then add to event
590
-            $new_dtt->set('DTT_ID', 0);
591
-            $new_dtt->set('DTT_sold', 0);
592
-            $new_dtt->set_reserved(0);
593
-            $new_dtt->save();
594
-            $new_event->_add_relation_to($new_dtt, 'Datetime');
595
-            $new_event->save();
596
-            //now let's get the ticket relations setup.
597
-            foreach ((array)$orig_tkts as $orig_tkt) {
598
-                //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
599
-                if (! $orig_tkt instanceof EE_Ticket) {
600
-                    continue;
601
-                }
602
-                //is this ticket archived?  If it is then let's skip
603
-                if ($orig_tkt->get('TKT_deleted')) {
604
-                    continue;
605
-                }
606
-                // does this original ticket already exist in the clone_tickets cache?
607
-                //  If so we'll just use the new ticket from it.
608
-                if (isset($cloned_tickets[$orig_tkt->ID()])) {
609
-                    $new_tkt = $cloned_tickets[$orig_tkt->ID()];
610
-                } else {
611
-                    $new_tkt = clone $orig_tkt;
612
-                    //get relations on the $orig_tkt that we need to setup.
613
-                    $orig_prices = $orig_tkt->prices();
614
-                    $new_tkt->set('TKT_ID', 0);
615
-                    $new_tkt->set('TKT_sold', 0);
616
-                    $new_tkt->set('TKT_reserved', 0);
617
-                    $new_tkt->save(); //make sure new ticket has ID.
618
-                    //price relations on new ticket need to be setup.
619
-                    foreach ($orig_prices as $orig_price) {
620
-                        $new_price = clone $orig_price;
621
-                        $new_price->set('PRC_ID', 0);
622
-                        $new_price->save();
623
-                        $new_tkt->_add_relation_to($new_price, 'Price');
624
-                        $new_tkt->save();
625
-                    }
626
-                }
627
-                // k now we can add the new ticket as a relation to the new datetime
628
-                // and make sure its added to our cached $cloned_tickets array
629
-                // for use with later datetimes that have the same ticket.
630
-                $new_dtt->_add_relation_to($new_tkt, 'Ticket');
631
-                $new_dtt->save();
632
-                $cloned_tickets[$orig_tkt->ID()] = $new_tkt;
633
-            }
634
-        }
635
-        //clone taxonomy information
636
-        $taxonomies_to_clone_with = apply_filters(
637
-            'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
638
-            array('espresso_event_categories', 'espresso_event_type', 'post_tag')
639
-        );
640
-        //get terms for original event (notice)
641
-        $orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
642
-        //loop through terms and add them to new event.
643
-        foreach ($orig_terms as $term) {
644
-            wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
645
-        }
646
-        do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
647
-        //now let's redirect to the edit page for this duplicated event if we have a new event id.
648
-        if ($new_event->ID()) {
649
-            $redirect_args = array(
650
-                'post'   => $new_event->ID(),
651
-                'action' => 'edit',
652
-            );
653
-            EE_Error::add_success(
654
-                esc_html__(
655
-                    'Event successfully duplicated.  Please review the details below and make any necessary edits',
656
-                    'event_espresso'
657
-                )
658
-            );
659
-        } else {
660
-            $redirect_args = array(
661
-                'action' => 'default',
662
-            );
663
-            EE_Error::add_error(
664
-                esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
665
-                __FILE__,
666
-                __FUNCTION__,
667
-                __LINE__
668
-            );
669
-        }
670
-        $this->_redirect_after_action(false, '', '', $redirect_args, true);
671
-    }
672
-
673
-
674
-    /**
675
-     * Generates output for the import page.
676
-     * @throws DomainException
677
-     */
678
-    protected function _import_page()
679
-    {
680
-        $title                                      = esc_html__('Import', 'event_espresso');
681
-        $intro                                      = esc_html__(
682
-            'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
683
-            'event_espresso'
684
-        );
685
-        $form_url                                   = EVENTS_ADMIN_URL;
686
-        $action                                     = 'import_events';
687
-        $type                                       = 'csv';
688
-        $this->_template_args['form']               = EE_Import::instance()->upload_form(
689
-            $title, $intro, $form_url, $action, $type
690
-        );
691
-        $this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
692
-            array('action' => 'sample_export_file'),
693
-            $this->_admin_base_url
694
-        );
695
-        $content                                    = EEH_Template::display_template(
696
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
697
-            $this->_template_args,
698
-            true
699
-        );
700
-        $this->_template_args['admin_page_content'] = $content;
701
-        $this->display_admin_page_with_sidebar();
702
-    }
703
-
704
-
705
-    /**
706
-     * _import_events
707
-     * This handles displaying the screen and running imports for importing events.
708
-     *
709
-     * @return void
710
-     */
711
-    protected function _import_events()
712
-    {
713
-        require_once(EE_CLASSES . 'EE_Import.class.php');
714
-        $success = EE_Import::instance()->import();
715
-        $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
716
-    }
717
-
718
-
719
-    /**
720
-     * _events_export
721
-     * Will export all (or just the given event) to a Excel compatible file.
722
-     *
723
-     * @access protected
724
-     * @return void
725
-     */
726
-    protected function _events_export()
727
-    {
728
-        if (isset($this->_req_data['EVT_ID'])) {
729
-            $event_ids = $this->_req_data['EVT_ID'];
730
-        } elseif (isset($this->_req_data['EVT_IDs'])) {
731
-            $event_ids = $this->_req_data['EVT_IDs'];
732
-        } else {
733
-            $event_ids = null;
734
-        }
735
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
736
-        $new_request_args = array(
737
-            'export' => 'report',
738
-            'action' => 'all_event_data',
739
-            'EVT_ID' => $event_ids,
740
-        );
741
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
742
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
743
-            require_once(EE_CLASSES . 'EE_Export.class.php');
744
-            $EE_Export = EE_Export::instance($this->_req_data);
745
-            $EE_Export->export();
746
-        }
747
-    }
748
-
749
-
750
-    /**
751
-     * handle category exports()
752
-     *
753
-     * @return void
754
-     */
755
-    protected function _categories_export()
756
-    {
757
-        //todo: I don't like doing this but it'll do until we modify EE_Export Class.
758
-        $new_request_args = array(
759
-            'export'       => 'report',
760
-            'action'       => 'categories',
761
-            'category_ids' => $this->_req_data['EVT_CAT_ID'],
762
-        );
763
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
764
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
765
-            require_once(EE_CLASSES . 'EE_Export.class.php');
766
-            $EE_Export = EE_Export::instance($this->_req_data);
767
-            $EE_Export->export();
768
-        }
769
-    }
770
-
771
-
772
-    /**
773
-     * Creates a sample CSV file for importing
774
-     */
775
-    protected function _sample_export_file()
776
-    {
777
-        //		require_once(EE_CLASSES . 'EE_Export.class.php');
778
-        EE_Export::instance()->export_sample();
779
-    }
780
-
781
-
782
-    /*************        Template Settings        *************/
783
-    /**
784
-     * Generates template settings page output
785
-     * @throws DomainException
786
-     * @throws EE_Error
787
-     */
788
-    protected function _template_settings()
789
-    {
790
-        $this->_template_args['values'] = $this->_yes_no_values;
791
-        /**
792
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
793
-         * from General_Settings_Admin_Page to here.
794
-         */
795
-        $this->_template_args = apply_filters(
796
-            'FHEE__General_Settings_Admin_Page__template_settings__template_args',
797
-            $this->_template_args
798
-        );
799
-        $this->_set_add_edit_form_tags('update_template_settings');
800
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
801
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
802
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
803
-            $this->_template_args,
804
-            true
805
-        );
806
-        $this->display_admin_page_with_sidebar();
807
-    }
808
-
809
-
810
-    /**
811
-     * Handler for updating template settings.
812
-     */
813
-    protected function _update_template_settings()
814
-    {
815
-        /**
816
-         * Note leaving this filter in for backward compatibility this was moved in 4.6.x
817
-         * from General_Settings_Admin_Page to here.
818
-         */
819
-        EE_Registry::instance()->CFG->template_settings = apply_filters(
820
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
821
-            EE_Registry::instance()->CFG->template_settings,
822
-            $this->_req_data
823
-        );
824
-        //update custom post type slugs and detect if we need to flush rewrite rules
825
-        $old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
826
-        EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
827
-            ? EE_Registry::instance()->CFG->core->event_cpt_slug
828
-            : sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
829
-        $what                                              = 'Template Settings';
830
-        $success                                           = $this->_update_espresso_configuration(
831
-            $what,
832
-            EE_Registry::instance()->CFG->template_settings,
833
-            __FILE__,
834
-            __FUNCTION__,
835
-            __LINE__
836
-        );
837
-        if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
838
-            update_option('ee_flush_rewrite_rules', true);
839
-        }
840
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
841
-    }
842
-
843
-
844
-    /**
845
-     * _premium_event_editor_meta_boxes
846
-     * add all metaboxes related to the event_editor
847
-     *
848
-     * @access protected
849
-     * @return void
850
-     * @throws EE_Error
851
-     */
852
-    protected function _premium_event_editor_meta_boxes()
853
-    {
854
-        $this->verify_cpt_object();
855
-        add_meta_box(
856
-            'espresso_event_editor_event_options',
857
-            esc_html__('Event Registration Options', 'event_espresso'),
858
-            array($this, 'registration_options_meta_box'),
859
-            $this->page_slug,
860
-            'side',
861
-            'core'
862
-        );
863
-    }
864
-
865
-
866
-    /**
867
-     * override caf metabox
868
-     *
869
-     * @return void
870
-     * @throws DomainException
871
-     */
872
-    public function registration_options_meta_box()
873
-    {
874
-        $yes_no_values                                    = array(
875
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
876
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
877
-        );
878
-        $default_reg_status_values                        = EEM_Registration::reg_status_array(
879
-            array(
880
-                EEM_Registration::status_id_cancelled,
881
-                EEM_Registration::status_id_declined,
882
-                EEM_Registration::status_id_incomplete,
883
-                EEM_Registration::status_id_wait_list,
884
-            ),
885
-            true
886
-        );
887
-        $template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
888
-        $template_args['_event']                          = $this->_cpt_model_obj;
889
-        $template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
890
-        $template_args['default_registration_status']     = EEH_Form_Fields::select_input(
891
-            'default_reg_status',
892
-            $default_reg_status_values,
893
-            $this->_cpt_model_obj->default_registration_status()
894
-        );
895
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
896
-            'display_desc',
897
-            $yes_no_values,
898
-            $this->_cpt_model_obj->display_description()
899
-        );
900
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
901
-            'display_ticket_selector',
902
-            $yes_no_values,
903
-            $this->_cpt_model_obj->display_ticket_selector(),
904
-            '',
905
-            '',
906
-            false
907
-        );
908
-        $template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
909
-            'EVT_default_registration_status',
910
-            $default_reg_status_values,
911
-            $this->_cpt_model_obj->default_registration_status()
912
-        );
913
-        $template_args['additional_registration_options'] = apply_filters(
914
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
915
-            '',
916
-            $template_args,
917
-            $yes_no_values,
918
-            $default_reg_status_values
919
-        );
920
-        EEH_Template::display_template(
921
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
922
-            $template_args
923
-        );
924
-    }
925
-
926
-
927
-
928
-    /**
929
-     * wp_list_table_mods for caf
930
-     * ============================
931
-     */
932
-    /**
933
-     * hook into list table filters and provide filters for caffeinated list table
934
-     *
935
-     * @param  array $old_filters    any existing filters present
936
-     * @param  array $list_table_obj the list table object
937
-     * @return array                  new filters
938
-     */
939
-    public function list_table_filters($old_filters, $list_table_obj)
940
-    {
941
-        $filters = array();
942
-        //first month/year filters
943
-        $filters[] = $this->espresso_event_months_dropdown();
944
-        $status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
945
-        //active status dropdown
946
-        if ($status !== 'draft') {
947
-            $filters[] = $this->active_status_dropdown(
948
-                isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
949
-            );
950
-        }
951
-        //category filter
952
-        $filters[] = $this->category_dropdown();
953
-        return array_merge($old_filters, $filters);
954
-    }
955
-
956
-
957
-    /**
958
-     * espresso_event_months_dropdown
959
-     *
960
-     * @access public
961
-     * @return string                dropdown listing month/year selections for events.
962
-     */
963
-    public function espresso_event_months_dropdown()
964
-    {
965
-        // what we need to do is get all PRIMARY datetimes for all events to filter on.
966
-        // Note we need to include any other filters that are set!
967
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
968
-        //categories?
969
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
970
-            ? $this->_req_data['EVT_CAT']
971
-            : null;
972
-        //active status?
973
-        $active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
974
-        $cur_date      = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
975
-        return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
976
-    }
977
-
978
-
979
-    /**
980
-     * returns a list of "active" statuses on the event
981
-     *
982
-     * @param  string $current_value whatever the current active status is
983
-     * @return string
984
-     */
985
-    public function active_status_dropdown($current_value = '')
986
-    {
987
-        $select_name = 'active_status';
988
-        $values      = array(
989
-            'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
990
-            'active'   => esc_html__('Active', 'event_espresso'),
991
-            'upcoming' => esc_html__('Upcoming', 'event_espresso'),
992
-            'expired'  => esc_html__('Expired', 'event_espresso'),
993
-            'inactive' => esc_html__('Inactive', 'event_espresso'),
994
-        );
995
-        $id          = 'id="espresso-active-status-dropdown-filter"';
996
-        $class       = 'wide';
997
-        return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
998
-    }
999
-
1000
-
1001
-    /**
1002
-     * output a dropdown of the categories for the category filter on the event admin list table
1003
-     *
1004
-     * @access  public
1005
-     * @return string html
1006
-     */
1007
-    public function category_dropdown()
1008
-    {
1009
-        $cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1010
-        return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1011
-    }
1012
-
1013
-
1014
-    /**
1015
-     * get total number of events today
1016
-     *
1017
-     * @access public
1018
-     * @return int
1019
-     * @throws EE_Error
1020
-     */
1021
-    public function total_events_today()
1022
-    {
1023
-        $start = EEM_Datetime::instance()->convert_datetime_for_query(
1024
-            'DTT_EVT_start',
1025
-            date('Y-m-d') . ' 00:00:00',
1026
-            'Y-m-d H:i:s',
1027
-            'UTC'
1028
-        );
1029
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1030
-            'DTT_EVT_start',
1031
-            date('Y-m-d') . ' 23:59:59',
1032
-            'Y-m-d H:i:s',
1033
-            'UTC'
1034
-        );
1035
-        $where = array(
1036
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1037
-        );
1038
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1039
-        return $count;
1040
-    }
1041
-
1042
-
1043
-    /**
1044
-     * get total number of events this month
1045
-     *
1046
-     * @access public
1047
-     * @return int
1048
-     * @throws EE_Error
1049
-     */
1050
-    public function total_events_this_month()
1051
-    {
1052
-        //Dates
1053
-        $this_year_r     = date('Y');
1054
-        $this_month_r    = date('m');
1055
-        $days_this_month = date('t');
1056
-        $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1057
-            'DTT_EVT_start',
1058
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1059
-            'Y-m-d H:i:s',
1060
-            'UTC'
1061
-        );
1062
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1063
-            'DTT_EVT_start',
1064
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1065
-            'Y-m-d H:i:s',
1066
-            'UTC'
1067
-        );
1068
-        $where           = array(
1069
-            'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1070
-        );
1071
-        $count           = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1072
-        return $count;
1073
-    }
1074
-
1075
-
1076
-    /** DEFAULT TICKETS STUFF **/
1077
-
1078
-    /**
1079
-     * Output default tickets list table view.
1080
-     */
1081
-    public function _tickets_overview_list_table()
1082
-    {
1083
-        $this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1084
-        $this->display_admin_list_table_page_with_no_sidebar();
1085
-    }
1086
-
1087
-
1088
-    /**
1089
-     * @param int  $per_page
1090
-     * @param bool $count
1091
-     * @param bool $trashed
1092
-     * @return \EE_Soft_Delete_Base_Class[]|int
1093
-     */
1094
-    public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1095
-    {
1096
-        $orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1097
-        $order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1098
-        switch ($orderby) {
1099
-            case 'TKT_name':
1100
-                $orderby = array('TKT_name' => $order);
1101
-                break;
1102
-            case 'TKT_price':
1103
-                $orderby = array('TKT_price' => $order);
1104
-                break;
1105
-            case 'TKT_uses':
1106
-                $orderby = array('TKT_uses' => $order);
1107
-                break;
1108
-            case 'TKT_min':
1109
-                $orderby = array('TKT_min' => $order);
1110
-                break;
1111
-            case 'TKT_max':
1112
-                $orderby = array('TKT_max' => $order);
1113
-                break;
1114
-            case 'TKT_qty':
1115
-                $orderby = array('TKT_qty' => $order);
1116
-                break;
1117
-        }
1118
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1119
-            ? $this->_req_data['paged']
1120
-            : 1;
1121
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1122
-            ? $this->_req_data['perpage']
1123
-            : $per_page;
1124
-        $_where       = array(
1125
-            'TKT_is_default' => 1,
1126
-            'TKT_deleted'    => $trashed,
1127
-        );
1128
-        $offset       = ($current_page - 1) * $per_page;
1129
-        $limit        = array($offset, $per_page);
1130
-        if (isset($this->_req_data['s'])) {
1131
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1132
-            $_where['OR'] = array(
1133
-                'TKT_name'        => array('LIKE', $sstr),
1134
-                'TKT_description' => array('LIKE', $sstr),
1135
-            );
1136
-        }
1137
-        $query_params = array(
1138
-            $_where,
1139
-            'order_by' => $orderby,
1140
-            'limit'    => $limit,
1141
-            'group_by' => 'TKT_ID',
1142
-        );
1143
-        if ($count) {
1144
-            return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1145
-        } else {
1146
-            return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1147
-        }
1148
-    }
1149
-
1150
-
1151
-    /**
1152
-     * @param bool $trash
1153
-     * @throws EE_Error
1154
-     */
1155
-    protected function _trash_or_restore_ticket($trash = false)
1156
-    {
1157
-        $success = 1;
1158
-        $TKT     = EEM_Ticket::instance();
1159
-        //checkboxes?
1160
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1161
-            //if array has more than one element then success message should be plural
1162
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1163
-            //cycle thru the boxes
1164
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1165
-                if ($trash) {
1166
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1167
-                        $success = 0;
1168
-                    }
1169
-                } else {
1170
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1171
-                        $success = 0;
1172
-                    }
1173
-                }
1174
-            }
1175
-        } else {
1176
-            //grab single id and trash
1177
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1178
-            if ($trash) {
1179
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1180
-                    $success = 0;
1181
-                }
1182
-            } else {
1183
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1184
-                    $success = 0;
1185
-                }
1186
-            }
1187
-        }
1188
-        $action_desc = $trash ? 'moved to the trash' : 'restored';
1189
-        $query_args  = array(
1190
-            'action' => 'ticket_list_table',
1191
-            'status' => $trash ? '' : 'trashed',
1192
-        );
1193
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1194
-    }
1195
-
1196
-
1197
-    /**
1198
-     * Handles trashing default ticket.
1199
-     */
1200
-    protected function _delete_ticket()
1201
-    {
1202
-        $success = 1;
1203
-        //checkboxes?
1204
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1205
-            //if array has more than one element then success message should be plural
1206
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1207
-            //cycle thru the boxes
1208
-            while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1209
-                //delete
1210
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1211
-                    $success = 0;
1212
-                }
1213
-            }
1214
-        } else {
1215
-            //grab single id and trash
1216
-            $TKT_ID = absint($this->_req_data['TKT_ID']);
1217
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1218
-                $success = 0;
1219
-            }
1220
-        }
1221
-        $action_desc = 'deleted';
1222
-        $query_args  = array(
1223
-            'action' => 'ticket_list_table',
1224
-            'status' => 'trashed',
1225
-        );
1226
-        //fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1227
-        if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1228
-            array(array('TKT_is_default' => 1)),
1229
-            'TKT_ID',
1230
-            true
1231
-        )
1232
-        ) {
1233
-            $query_args = array();
1234
-        }
1235
-        $this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1236
-    }
1237
-
1238
-
1239
-    /**
1240
-     * @param int $TKT_ID
1241
-     * @return bool|int
1242
-     * @throws EE_Error
1243
-     */
1244
-    protected function _delete_the_ticket($TKT_ID)
1245
-    {
1246
-        $tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1247
-        $tkt->_remove_relations('Datetime');
1248
-        //delete all related prices first
1249
-        $tkt->delete_related_permanently('Price');
1250
-        return $tkt->delete_permanently();
1251
-    }
17
+	/**
18
+	 * Extend_Events_Admin_Page constructor.
19
+	 *
20
+	 * @param bool $routing
21
+	 */
22
+	public function __construct($routing = true)
23
+	{
24
+		parent::__construct($routing);
25
+		if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
26
+			define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
27
+			define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
28
+			define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
29
+		}
30
+	}
31
+
32
+
33
+	/**
34
+	 * Sets routes.
35
+	 */
36
+	protected function _extend_page_config()
37
+	{
38
+		$this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
39
+		//is there a evt_id in the request?
40
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41
+			? $this->_req_data['EVT_ID']
42
+			: 0;
43
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
44
+		//tkt_id?
45
+		$tkt_id             = ! empty($this->_req_data['TKT_ID']) && ! is_array($this->_req_data['TKT_ID'])
46
+			? $this->_req_data['TKT_ID']
47
+			: 0;
48
+		$new_page_routes    = array(
49
+			'duplicate_event'          => array(
50
+				'func'       => '_duplicate_event',
51
+				'capability' => 'ee_edit_event',
52
+				'obj_id'     => $evt_id,
53
+				'noheader'   => true,
54
+			),
55
+			'ticket_list_table'        => array(
56
+				'func'       => '_tickets_overview_list_table',
57
+				'capability' => 'ee_read_default_tickets',
58
+			),
59
+			'trash_ticket'             => array(
60
+				'func'       => '_trash_or_restore_ticket',
61
+				'capability' => 'ee_delete_default_ticket',
62
+				'obj_id'     => $tkt_id,
63
+				'noheader'   => true,
64
+				'args'       => array('trash' => true),
65
+			),
66
+			'trash_tickets'            => array(
67
+				'func'       => '_trash_or_restore_ticket',
68
+				'capability' => 'ee_delete_default_tickets',
69
+				'noheader'   => true,
70
+				'args'       => array('trash' => true),
71
+			),
72
+			'restore_ticket'           => array(
73
+				'func'       => '_trash_or_restore_ticket',
74
+				'capability' => 'ee_delete_default_ticket',
75
+				'obj_id'     => $tkt_id,
76
+				'noheader'   => true,
77
+			),
78
+			'restore_tickets'          => array(
79
+				'func'       => '_trash_or_restore_ticket',
80
+				'capability' => 'ee_delete_default_tickets',
81
+				'noheader'   => true,
82
+			),
83
+			'delete_ticket'            => array(
84
+				'func'       => '_delete_ticket',
85
+				'capability' => 'ee_delete_default_ticket',
86
+				'obj_id'     => $tkt_id,
87
+				'noheader'   => true,
88
+			),
89
+			'delete_tickets'           => array(
90
+				'func'       => '_delete_ticket',
91
+				'capability' => 'ee_delete_default_tickets',
92
+				'noheader'   => true,
93
+			),
94
+			'import_page'              => array(
95
+				'func'       => '_import_page',
96
+				'capability' => 'import',
97
+			),
98
+			'import'                   => array(
99
+				'func'       => '_import_events',
100
+				'capability' => 'import',
101
+				'noheader'   => true,
102
+			),
103
+			'import_events'            => array(
104
+				'func'       => '_import_events',
105
+				'capability' => 'import',
106
+				'noheader'   => true,
107
+			),
108
+			'export_events'            => array(
109
+				'func'       => '_events_export',
110
+				'capability' => 'export',
111
+				'noheader'   => true,
112
+			),
113
+			'export_categories'        => array(
114
+				'func'       => '_categories_export',
115
+				'capability' => 'export',
116
+				'noheader'   => true,
117
+			),
118
+			'sample_export_file'       => array(
119
+				'func'       => '_sample_export_file',
120
+				'capability' => 'export',
121
+				'noheader'   => true,
122
+			),
123
+			'update_template_settings' => array(
124
+				'func'       => '_update_template_settings',
125
+				'capability' => 'manage_options',
126
+				'noheader'   => true,
127
+			),
128
+		);
129
+		$this->_page_routes = array_merge($this->_page_routes, $new_page_routes);
130
+		//partial route/config override
131
+		$this->_page_config['import_events']['metaboxes'] = $this->_default_espresso_metaboxes;
132
+		$this->_page_config['create_new']['metaboxes'][]  = '_premium_event_editor_meta_boxes';
133
+		$this->_page_config['create_new']['qtips'][]      = 'EE_Event_Editor_Tips';
134
+		$this->_page_config['edit']['qtips'][]            = 'EE_Event_Editor_Tips';
135
+		$this->_page_config['edit']['metaboxes'][]        = '_premium_event_editor_meta_boxes';
136
+		$this->_page_config['default']['list_table']      = 'Extend_Events_Admin_List_Table';
137
+		//add tickets tab but only if there are more than one default ticket!
138
+		$tkt_count = EEM_Ticket::instance()->count_deleted_and_undeleted(
139
+			array(array('TKT_is_default' => 1)),
140
+			'TKT_ID',
141
+			true
142
+		);
143
+		if ($tkt_count > 1) {
144
+			$new_page_config = array(
145
+				'ticket_list_table' => array(
146
+					'nav'           => array(
147
+						'label' => esc_html__('Default Tickets', 'event_espresso'),
148
+						'order' => 60,
149
+					),
150
+					'list_table'    => 'Tickets_List_Table',
151
+					'require_nonce' => false,
152
+				),
153
+			);
154
+		}
155
+		//template settings
156
+		$new_page_config['template_settings'] = array(
157
+			'nav'           => array(
158
+				'label' => esc_html__('Templates', 'event_espresso'),
159
+				'order' => 30,
160
+			),
161
+			'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
162
+			'help_tabs'     => array(
163
+				'general_settings_templates_help_tab' => array(
164
+					'title'    => esc_html__('Templates', 'event_espresso'),
165
+					'filename' => 'general_settings_templates',
166
+				),
167
+			),
168
+			'help_tour'     => array('Templates_Help_Tour'),
169
+			'require_nonce' => false,
170
+		);
171
+		$this->_page_config                   = array_merge($this->_page_config, $new_page_config);
172
+		//add filters and actions
173
+		//modifying _views
174
+		add_filter(
175
+			'FHEE_event_datetime_metabox_add_additional_date_time_template',
176
+			array($this, 'add_additional_datetime_button'),
177
+			10,
178
+			2
179
+		);
180
+		add_filter(
181
+			'FHEE_event_datetime_metabox_clone_button_template',
182
+			array($this, 'add_datetime_clone_button'),
183
+			10,
184
+			2
185
+		);
186
+		add_filter(
187
+			'FHEE_event_datetime_metabox_timezones_template',
188
+			array($this, 'datetime_timezones_template'),
189
+			10,
190
+			2
191
+		);
192
+		//filters for event list table
193
+		add_filter('FHEE__Extend_Events_Admin_List_Table__filters', array($this, 'list_table_filters'), 10, 2);
194
+		add_filter(
195
+			'FHEE__Events_Admin_List_Table__column_actions__action_links',
196
+			array($this, 'extra_list_table_actions'),
197
+			10,
198
+			2
199
+		);
200
+		//legend item
201
+		add_filter('FHEE__Events_Admin_Page___event_legend_items__items', array($this, 'additional_legend_items'));
202
+		add_action('admin_init', array($this, 'admin_init'));
203
+		//heartbeat stuff
204
+		add_filter('heartbeat_received', array($this, 'heartbeat_response'), 10, 2);
205
+	}
206
+
207
+
208
+	/**
209
+	 * admin_init
210
+	 */
211
+	public function admin_init()
212
+	{
213
+		EE_Registry::$i18n_js_strings = array_merge(
214
+			EE_Registry::$i18n_js_strings,
215
+			array(
216
+				'image_confirm'          => esc_html__(
217
+					'Do you really want to delete this image? Please remember to update your event to complete the removal.',
218
+					'event_espresso'
219
+				),
220
+				'event_starts_on'        => esc_html__('Event Starts on', 'event_espresso'),
221
+				'event_ends_on'          => esc_html__('Event Ends on', 'event_espresso'),
222
+				'event_datetime_actions' => esc_html__('Actions', 'event_espresso'),
223
+				'event_clone_dt_msg'     => esc_html__('Clone this Event Date and Time', 'event_espresso'),
224
+				'remove_event_dt_msg'    => esc_html__('Remove this Event Time', 'event_espresso'),
225
+			)
226
+		);
227
+	}
228
+
229
+
230
+	/**
231
+	 * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle
232
+	 * accordingly.
233
+	 *
234
+	 * @param array $response The existing heartbeat response array.
235
+	 * @param array $data     The incoming data package.
236
+	 * @return array  possibly appended response.
237
+	 */
238
+	public function heartbeat_response($response, $data)
239
+	{
240
+		/**
241
+		 * check whether count of tickets is approaching the potential
242
+		 * limits for the server.
243
+		 */
244
+		if (! empty($data['input_count'])) {
245
+			$response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
246
+				$data['input_count']
247
+			);
248
+		}
249
+		return $response;
250
+	}
251
+
252
+
253
+	/**
254
+	 * Add per page screen options to the default ticket list table view.
255
+	 */
256
+	protected function _add_screen_options_ticket_list_table()
257
+	{
258
+		$this->_per_page_screen_option();
259
+	}
260
+
261
+
262
+	/**
263
+	 * @param string $return
264
+	 * @param int    $id
265
+	 * @param string $new_title
266
+	 * @param string $new_slug
267
+	 * @return string
268
+	 */
269
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
270
+	{
271
+		$return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
272
+		//make sure this is only when editing
273
+		if (! empty($id)) {
274
+			$href   = EE_Admin_Page::add_query_args_and_nonce(
275
+				array('action' => 'duplicate_event', 'EVT_ID' => $id),
276
+				$this->_admin_base_url
277
+			);
278
+			$title  = esc_attr__('Duplicate Event', 'event_espresso');
279
+			$return .= '<a href="'
280
+					   . $href
281
+					   . '" title="'
282
+					   . $title
283
+					   . '" id="ee-duplicate-event-button" class="button button-small"  value="duplicate_event">'
284
+					   . $title
285
+					   . '</button>';
286
+		}
287
+		return $return;
288
+	}
289
+
290
+
291
+	/**
292
+	 * Set the list table views for the default ticket list table view.
293
+	 */
294
+	public function _set_list_table_views_ticket_list_table()
295
+	{
296
+		$this->_views = array(
297
+			'all'     => array(
298
+				'slug'        => 'all',
299
+				'label'       => esc_html__('All', 'event_espresso'),
300
+				'count'       => 0,
301
+				'bulk_action' => array(
302
+					'trash_tickets' => esc_html__('Move to Trash', 'event_espresso'),
303
+				),
304
+			),
305
+			'trashed' => array(
306
+				'slug'        => 'trashed',
307
+				'label'       => esc_html__('Trash', 'event_espresso'),
308
+				'count'       => 0,
309
+				'bulk_action' => array(
310
+					'restore_tickets' => esc_html__('Restore from Trash', 'event_espresso'),
311
+					'delete_tickets'  => esc_html__('Delete Permanently', 'event_espresso'),
312
+				),
313
+			),
314
+		);
315
+	}
316
+
317
+
318
+	/**
319
+	 * Enqueue scripts and styles for the event editor.
320
+	 */
321
+	public function load_scripts_styles_edit()
322
+	{
323
+		wp_register_script(
324
+			'ee-event-editor-heartbeat',
325
+			EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
326
+			array('ee_admin_js', 'heartbeat'),
327
+			EVENT_ESPRESSO_VERSION,
328
+			true
329
+		);
330
+		wp_enqueue_script('ee-accounting');
331
+		//styles
332
+		wp_enqueue_style('espresso-ui-theme');
333
+		wp_enqueue_script('event_editor_js');
334
+		wp_enqueue_script('ee-event-editor-heartbeat');
335
+	}
336
+
337
+
338
+	/**
339
+	 * Returns template for the additional datetime.
340
+	 * @param $template
341
+	 * @param $template_args
342
+	 * @return mixed
343
+	 * @throws DomainException
344
+	 */
345
+	public function add_additional_datetime_button($template, $template_args)
346
+	{
347
+		return EEH_Template::display_template(
348
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
349
+			$template_args,
350
+			true
351
+		);
352
+	}
353
+
354
+
355
+	/**
356
+	 * Returns the template for cloning a datetime.
357
+	 * @param $template
358
+	 * @param $template_args
359
+	 * @return mixed
360
+	 * @throws DomainException
361
+	 */
362
+	public function add_datetime_clone_button($template, $template_args)
363
+	{
364
+		return EEH_Template::display_template(
365
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
366
+			$template_args,
367
+			true
368
+		);
369
+	}
370
+
371
+
372
+	/**
373
+	 * Returns the template for datetime timezones.
374
+	 * @param $template
375
+	 * @param $template_args
376
+	 * @return mixed
377
+	 * @throws DomainException
378
+	 */
379
+	public function datetime_timezones_template($template, $template_args)
380
+	{
381
+		return EEH_Template::display_template(
382
+			EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
383
+			$template_args,
384
+			true
385
+		);
386
+	}
387
+
388
+
389
+	/**
390
+	 * Sets the views for the default list table view.
391
+	 */
392
+	protected function _set_list_table_views_default()
393
+	{
394
+		parent::_set_list_table_views_default();
395
+		$new_views    = array(
396
+			'today' => array(
397
+				'slug'        => 'today',
398
+				'label'       => esc_html__('Today', 'event_espresso'),
399
+				'count'       => $this->total_events_today(),
400
+				'bulk_action' => array(
401
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
402
+				),
403
+			),
404
+			'month' => array(
405
+				'slug'        => 'month',
406
+				'label'       => esc_html__('This Month', 'event_espresso'),
407
+				'count'       => $this->total_events_this_month(),
408
+				'bulk_action' => array(
409
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
410
+				),
411
+			),
412
+		);
413
+		$this->_views = array_merge($this->_views, $new_views);
414
+	}
415
+
416
+
417
+	/**
418
+	 * Returns the extra action links for the default list table view.
419
+	 * @param array     $action_links
420
+	 * @param \EE_Event $event
421
+	 * @return array
422
+	 * @throws EE_Error
423
+	 */
424
+	public function extra_list_table_actions(array $action_links, \EE_Event $event)
425
+	{
426
+		if (EE_Registry::instance()->CAP->current_user_can(
427
+			'ee_read_registrations',
428
+			'espresso_registrations_reports',
429
+			$event->ID()
430
+		)
431
+		) {
432
+			$reports_query_args = array(
433
+				'action' => 'reports',
434
+				'EVT_ID' => $event->ID(),
435
+			);
436
+			$reports_link       = EE_Admin_Page::add_query_args_and_nonce($reports_query_args, REG_ADMIN_URL);
437
+			$action_links[]     = '<a href="'
438
+								  . $reports_link
439
+								  . '" title="'
440
+								  . esc_attr__('View Report', 'event_espresso')
441
+								  . '"><div class="dashicons dashicons-chart-bar"></div></a>'
442
+								  . "\n\t";
443
+		}
444
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
445
+			EE_Registry::instance()->load_helper('MSG_Template');
446
+			$action_links[] = EEH_MSG_Template::get_message_action_link(
447
+				'see_notifications_for',
448
+				null,
449
+				array('EVT_ID' => $event->ID())
450
+			);
451
+		}
452
+		return $action_links;
453
+	}
454
+
455
+
456
+	/**
457
+	 * @param $items
458
+	 * @return mixed
459
+	 */
460
+	public function additional_legend_items($items)
461
+	{
462
+		if (EE_Registry::instance()->CAP->current_user_can(
463
+			'ee_read_registrations',
464
+			'espresso_registrations_reports'
465
+		)
466
+		) {
467
+			$items['reports'] = array(
468
+				'class' => 'dashicons dashicons-chart-bar',
469
+				'desc'  => esc_html__('Event Reports', 'event_espresso'),
470
+			);
471
+		}
472
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
473
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
474
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
475
+				$items['view_related_messages'] = array(
476
+					'class' => $related_for_icon['css_class'],
477
+					'desc'  => $related_for_icon['label'],
478
+				);
479
+			}
480
+		}
481
+		return $items;
482
+	}
483
+
484
+
485
+	/**
486
+	 * This is the callback method for the duplicate event route
487
+	 * Method looks for 'EVT_ID' in the request and retrieves that event and its details and duplicates them
488
+	 * into a new event.  We add a hook so that any plugins that add extra event details can hook into this
489
+	 * action.  Note that the dupe will have **DUPLICATE** as its title and slug.
490
+	 * After duplication the redirect is to the new event edit page.
491
+	 *
492
+	 * @return void
493
+	 * @access protected
494
+	 * @throws EE_Error If EE_Event is not available with given ID
495
+	 */
496
+	protected function _duplicate_event()
497
+	{
498
+		// first make sure the ID for the event is in the request.
499
+		//  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
500
+		if (! isset($this->_req_data['EVT_ID'])) {
501
+			EE_Error::add_error(
502
+				esc_html__(
503
+					'In order to duplicate an event an Event ID is required.  None was given.',
504
+					'event_espresso'
505
+				),
506
+				__FILE__,
507
+				__FUNCTION__,
508
+				__LINE__
509
+			);
510
+			$this->_redirect_after_action(false, '', '', array(), true);
511
+			return;
512
+		}
513
+		//k we've got EVT_ID so let's use that to get the event we'll duplicate
514
+		$orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
515
+		if (! $orig_event instanceof EE_Event) {
516
+			throw new EE_Error(
517
+				sprintf(
518
+					esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
519
+					$this->_req_data['EVT_ID']
520
+				)
521
+			);
522
+		}
523
+		//k now let's clone the $orig_event before getting relations
524
+		$new_event = clone $orig_event;
525
+		//original datetimes
526
+		$orig_datetimes = $orig_event->get_many_related('Datetime');
527
+		//other original relations
528
+		$orig_ven = $orig_event->get_many_related('Venue');
529
+		//reset the ID and modify other details to make it clear this is a dupe
530
+		$new_event->set('EVT_ID', 0);
531
+		$new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
532
+		$new_event->set('EVT_name', $new_name);
533
+		$new_event->set(
534
+			'EVT_slug',
535
+			wp_unique_post_slug(
536
+				sanitize_title($orig_event->name()),
537
+				0,
538
+				'publish',
539
+				'espresso_events',
540
+				0
541
+			)
542
+		);
543
+		$new_event->set('status', 'draft');
544
+		//duplicate discussion settings
545
+		$new_event->set('comment_status', $orig_event->get('comment_status'));
546
+		$new_event->set('ping_status', $orig_event->get('ping_status'));
547
+		//save the new event
548
+		$new_event->save();
549
+		//venues
550
+		foreach ($orig_ven as $ven) {
551
+			$new_event->_add_relation_to($ven, 'Venue');
552
+		}
553
+		$new_event->save();
554
+		//now we need to get the question group relations and handle that
555
+		//first primary question groups
556
+		$orig_primary_qgs = $orig_event->get_many_related(
557
+			'Question_Group',
558
+			array(array('Event_Question_Group.EQG_primary' => 1))
559
+		);
560
+		if (! empty($orig_primary_qgs)) {
561
+			foreach ($orig_primary_qgs as $id => $obj) {
562
+				if ($obj instanceof EE_Question_Group) {
563
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
564
+				}
565
+			}
566
+		}
567
+		//next additional attendee question groups
568
+		$orig_additional_qgs = $orig_event->get_many_related(
569
+			'Question_Group',
570
+			array(array('Event_Question_Group.EQG_primary' => 0))
571
+		);
572
+		if (! empty($orig_additional_qgs)) {
573
+			foreach ($orig_additional_qgs as $id => $obj) {
574
+				if ($obj instanceof EE_Question_Group) {
575
+					$new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
576
+				}
577
+			}
578
+		}
579
+		//now save
580
+		$new_event->save();
581
+		//k now that we have the new event saved we can loop through the datetimes and start adding relations.
582
+		$cloned_tickets = array();
583
+		foreach ($orig_datetimes as $orig_dtt) {
584
+			if (! $orig_dtt instanceof EE_Datetime) {
585
+				continue;
586
+			}
587
+			$new_dtt   = clone $orig_dtt;
588
+			$orig_tkts = $orig_dtt->tickets();
589
+			//save new dtt then add to event
590
+			$new_dtt->set('DTT_ID', 0);
591
+			$new_dtt->set('DTT_sold', 0);
592
+			$new_dtt->set_reserved(0);
593
+			$new_dtt->save();
594
+			$new_event->_add_relation_to($new_dtt, 'Datetime');
595
+			$new_event->save();
596
+			//now let's get the ticket relations setup.
597
+			foreach ((array)$orig_tkts as $orig_tkt) {
598
+				//it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
599
+				if (! $orig_tkt instanceof EE_Ticket) {
600
+					continue;
601
+				}
602
+				//is this ticket archived?  If it is then let's skip
603
+				if ($orig_tkt->get('TKT_deleted')) {
604
+					continue;
605
+				}
606
+				// does this original ticket already exist in the clone_tickets cache?
607
+				//  If so we'll just use the new ticket from it.
608
+				if (isset($cloned_tickets[$orig_tkt->ID()])) {
609
+					$new_tkt = $cloned_tickets[$orig_tkt->ID()];
610
+				} else {
611
+					$new_tkt = clone $orig_tkt;
612
+					//get relations on the $orig_tkt that we need to setup.
613
+					$orig_prices = $orig_tkt->prices();
614
+					$new_tkt->set('TKT_ID', 0);
615
+					$new_tkt->set('TKT_sold', 0);
616
+					$new_tkt->set('TKT_reserved', 0);
617
+					$new_tkt->save(); //make sure new ticket has ID.
618
+					//price relations on new ticket need to be setup.
619
+					foreach ($orig_prices as $orig_price) {
620
+						$new_price = clone $orig_price;
621
+						$new_price->set('PRC_ID', 0);
622
+						$new_price->save();
623
+						$new_tkt->_add_relation_to($new_price, 'Price');
624
+						$new_tkt->save();
625
+					}
626
+				}
627
+				// k now we can add the new ticket as a relation to the new datetime
628
+				// and make sure its added to our cached $cloned_tickets array
629
+				// for use with later datetimes that have the same ticket.
630
+				$new_dtt->_add_relation_to($new_tkt, 'Ticket');
631
+				$new_dtt->save();
632
+				$cloned_tickets[$orig_tkt->ID()] = $new_tkt;
633
+			}
634
+		}
635
+		//clone taxonomy information
636
+		$taxonomies_to_clone_with = apply_filters(
637
+			'FHEE__Extend_Events_Admin_Page___duplicate_event__taxonomies_to_clone',
638
+			array('espresso_event_categories', 'espresso_event_type', 'post_tag')
639
+		);
640
+		//get terms for original event (notice)
641
+		$orig_terms = wp_get_object_terms($orig_event->ID(), $taxonomies_to_clone_with);
642
+		//loop through terms and add them to new event.
643
+		foreach ($orig_terms as $term) {
644
+			wp_set_object_terms($new_event->ID(), $term->term_id, $term->taxonomy, true);
645
+		}
646
+		do_action('AHEE__Extend_Events_Admin_Page___duplicate_event__after', $new_event, $orig_event);
647
+		//now let's redirect to the edit page for this duplicated event if we have a new event id.
648
+		if ($new_event->ID()) {
649
+			$redirect_args = array(
650
+				'post'   => $new_event->ID(),
651
+				'action' => 'edit',
652
+			);
653
+			EE_Error::add_success(
654
+				esc_html__(
655
+					'Event successfully duplicated.  Please review the details below and make any necessary edits',
656
+					'event_espresso'
657
+				)
658
+			);
659
+		} else {
660
+			$redirect_args = array(
661
+				'action' => 'default',
662
+			);
663
+			EE_Error::add_error(
664
+				esc_html__('Not able to duplicate event.  Something went wrong.', 'event_espresso'),
665
+				__FILE__,
666
+				__FUNCTION__,
667
+				__LINE__
668
+			);
669
+		}
670
+		$this->_redirect_after_action(false, '', '', $redirect_args, true);
671
+	}
672
+
673
+
674
+	/**
675
+	 * Generates output for the import page.
676
+	 * @throws DomainException
677
+	 */
678
+	protected function _import_page()
679
+	{
680
+		$title                                      = esc_html__('Import', 'event_espresso');
681
+		$intro                                      = esc_html__(
682
+			'If you have a previously exported Event Espresso 4 information in a Comma Separated Value (CSV) file format, you can upload the file here: ',
683
+			'event_espresso'
684
+		);
685
+		$form_url                                   = EVENTS_ADMIN_URL;
686
+		$action                                     = 'import_events';
687
+		$type                                       = 'csv';
688
+		$this->_template_args['form']               = EE_Import::instance()->upload_form(
689
+			$title, $intro, $form_url, $action, $type
690
+		);
691
+		$this->_template_args['sample_file_link']   = EE_Admin_Page::add_query_args_and_nonce(
692
+			array('action' => 'sample_export_file'),
693
+			$this->_admin_base_url
694
+		);
695
+		$content                                    = EEH_Template::display_template(
696
+			EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
697
+			$this->_template_args,
698
+			true
699
+		);
700
+		$this->_template_args['admin_page_content'] = $content;
701
+		$this->display_admin_page_with_sidebar();
702
+	}
703
+
704
+
705
+	/**
706
+	 * _import_events
707
+	 * This handles displaying the screen and running imports for importing events.
708
+	 *
709
+	 * @return void
710
+	 */
711
+	protected function _import_events()
712
+	{
713
+		require_once(EE_CLASSES . 'EE_Import.class.php');
714
+		$success = EE_Import::instance()->import();
715
+		$this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
716
+	}
717
+
718
+
719
+	/**
720
+	 * _events_export
721
+	 * Will export all (or just the given event) to a Excel compatible file.
722
+	 *
723
+	 * @access protected
724
+	 * @return void
725
+	 */
726
+	protected function _events_export()
727
+	{
728
+		if (isset($this->_req_data['EVT_ID'])) {
729
+			$event_ids = $this->_req_data['EVT_ID'];
730
+		} elseif (isset($this->_req_data['EVT_IDs'])) {
731
+			$event_ids = $this->_req_data['EVT_IDs'];
732
+		} else {
733
+			$event_ids = null;
734
+		}
735
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
736
+		$new_request_args = array(
737
+			'export' => 'report',
738
+			'action' => 'all_event_data',
739
+			'EVT_ID' => $event_ids,
740
+		);
741
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
742
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
743
+			require_once(EE_CLASSES . 'EE_Export.class.php');
744
+			$EE_Export = EE_Export::instance($this->_req_data);
745
+			$EE_Export->export();
746
+		}
747
+	}
748
+
749
+
750
+	/**
751
+	 * handle category exports()
752
+	 *
753
+	 * @return void
754
+	 */
755
+	protected function _categories_export()
756
+	{
757
+		//todo: I don't like doing this but it'll do until we modify EE_Export Class.
758
+		$new_request_args = array(
759
+			'export'       => 'report',
760
+			'action'       => 'categories',
761
+			'category_ids' => $this->_req_data['EVT_CAT_ID'],
762
+		);
763
+		$this->_req_data  = array_merge($this->_req_data, $new_request_args);
764
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
765
+			require_once(EE_CLASSES . 'EE_Export.class.php');
766
+			$EE_Export = EE_Export::instance($this->_req_data);
767
+			$EE_Export->export();
768
+		}
769
+	}
770
+
771
+
772
+	/**
773
+	 * Creates a sample CSV file for importing
774
+	 */
775
+	protected function _sample_export_file()
776
+	{
777
+		//		require_once(EE_CLASSES . 'EE_Export.class.php');
778
+		EE_Export::instance()->export_sample();
779
+	}
780
+
781
+
782
+	/*************        Template Settings        *************/
783
+	/**
784
+	 * Generates template settings page output
785
+	 * @throws DomainException
786
+	 * @throws EE_Error
787
+	 */
788
+	protected function _template_settings()
789
+	{
790
+		$this->_template_args['values'] = $this->_yes_no_values;
791
+		/**
792
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
793
+		 * from General_Settings_Admin_Page to here.
794
+		 */
795
+		$this->_template_args = apply_filters(
796
+			'FHEE__General_Settings_Admin_Page__template_settings__template_args',
797
+			$this->_template_args
798
+		);
799
+		$this->_set_add_edit_form_tags('update_template_settings');
800
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
801
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
802
+			EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
803
+			$this->_template_args,
804
+			true
805
+		);
806
+		$this->display_admin_page_with_sidebar();
807
+	}
808
+
809
+
810
+	/**
811
+	 * Handler for updating template settings.
812
+	 */
813
+	protected function _update_template_settings()
814
+	{
815
+		/**
816
+		 * Note leaving this filter in for backward compatibility this was moved in 4.6.x
817
+		 * from General_Settings_Admin_Page to here.
818
+		 */
819
+		EE_Registry::instance()->CFG->template_settings = apply_filters(
820
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
821
+			EE_Registry::instance()->CFG->template_settings,
822
+			$this->_req_data
823
+		);
824
+		//update custom post type slugs and detect if we need to flush rewrite rules
825
+		$old_slug                                          = EE_Registry::instance()->CFG->core->event_cpt_slug;
826
+		EE_Registry::instance()->CFG->core->event_cpt_slug = empty($this->_req_data['event_cpt_slug'])
827
+			? EE_Registry::instance()->CFG->core->event_cpt_slug
828
+			: sanitize_title_with_dashes($this->_req_data['event_cpt_slug']);
829
+		$what                                              = 'Template Settings';
830
+		$success                                           = $this->_update_espresso_configuration(
831
+			$what,
832
+			EE_Registry::instance()->CFG->template_settings,
833
+			__FILE__,
834
+			__FUNCTION__,
835
+			__LINE__
836
+		);
837
+		if (EE_Registry::instance()->CFG->core->event_cpt_slug != $old_slug) {
838
+			update_option('ee_flush_rewrite_rules', true);
839
+		}
840
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'template_settings'));
841
+	}
842
+
843
+
844
+	/**
845
+	 * _premium_event_editor_meta_boxes
846
+	 * add all metaboxes related to the event_editor
847
+	 *
848
+	 * @access protected
849
+	 * @return void
850
+	 * @throws EE_Error
851
+	 */
852
+	protected function _premium_event_editor_meta_boxes()
853
+	{
854
+		$this->verify_cpt_object();
855
+		add_meta_box(
856
+			'espresso_event_editor_event_options',
857
+			esc_html__('Event Registration Options', 'event_espresso'),
858
+			array($this, 'registration_options_meta_box'),
859
+			$this->page_slug,
860
+			'side',
861
+			'core'
862
+		);
863
+	}
864
+
865
+
866
+	/**
867
+	 * override caf metabox
868
+	 *
869
+	 * @return void
870
+	 * @throws DomainException
871
+	 */
872
+	public function registration_options_meta_box()
873
+	{
874
+		$yes_no_values                                    = array(
875
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
876
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
877
+		);
878
+		$default_reg_status_values                        = EEM_Registration::reg_status_array(
879
+			array(
880
+				EEM_Registration::status_id_cancelled,
881
+				EEM_Registration::status_id_declined,
882
+				EEM_Registration::status_id_incomplete,
883
+				EEM_Registration::status_id_wait_list,
884
+			),
885
+			true
886
+		);
887
+		$template_args['active_status']                   = $this->_cpt_model_obj->pretty_active_status(false);
888
+		$template_args['_event']                          = $this->_cpt_model_obj;
889
+		$template_args['additional_limit']                = $this->_cpt_model_obj->additional_limit();
890
+		$template_args['default_registration_status']     = EEH_Form_Fields::select_input(
891
+			'default_reg_status',
892
+			$default_reg_status_values,
893
+			$this->_cpt_model_obj->default_registration_status()
894
+		);
895
+		$template_args['display_description']             = EEH_Form_Fields::select_input(
896
+			'display_desc',
897
+			$yes_no_values,
898
+			$this->_cpt_model_obj->display_description()
899
+		);
900
+		$template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
901
+			'display_ticket_selector',
902
+			$yes_no_values,
903
+			$this->_cpt_model_obj->display_ticket_selector(),
904
+			'',
905
+			'',
906
+			false
907
+		);
908
+		$template_args['EVT_default_registration_status'] = EEH_Form_Fields::select_input(
909
+			'EVT_default_registration_status',
910
+			$default_reg_status_values,
911
+			$this->_cpt_model_obj->default_registration_status()
912
+		);
913
+		$template_args['additional_registration_options'] = apply_filters(
914
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
915
+			'',
916
+			$template_args,
917
+			$yes_no_values,
918
+			$default_reg_status_values
919
+		);
920
+		EEH_Template::display_template(
921
+			EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
922
+			$template_args
923
+		);
924
+	}
925
+
926
+
927
+
928
+	/**
929
+	 * wp_list_table_mods for caf
930
+	 * ============================
931
+	 */
932
+	/**
933
+	 * hook into list table filters and provide filters for caffeinated list table
934
+	 *
935
+	 * @param  array $old_filters    any existing filters present
936
+	 * @param  array $list_table_obj the list table object
937
+	 * @return array                  new filters
938
+	 */
939
+	public function list_table_filters($old_filters, $list_table_obj)
940
+	{
941
+		$filters = array();
942
+		//first month/year filters
943
+		$filters[] = $this->espresso_event_months_dropdown();
944
+		$status    = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
945
+		//active status dropdown
946
+		if ($status !== 'draft') {
947
+			$filters[] = $this->active_status_dropdown(
948
+				isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : ''
949
+			);
950
+		}
951
+		//category filter
952
+		$filters[] = $this->category_dropdown();
953
+		return array_merge($old_filters, $filters);
954
+	}
955
+
956
+
957
+	/**
958
+	 * espresso_event_months_dropdown
959
+	 *
960
+	 * @access public
961
+	 * @return string                dropdown listing month/year selections for events.
962
+	 */
963
+	public function espresso_event_months_dropdown()
964
+	{
965
+		// what we need to do is get all PRIMARY datetimes for all events to filter on.
966
+		// Note we need to include any other filters that are set!
967
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
968
+		//categories?
969
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
970
+			? $this->_req_data['EVT_CAT']
971
+			: null;
972
+		//active status?
973
+		$active_status = isset($this->_req_data['active_status']) ? $this->_req_data['active_status'] : null;
974
+		$cur_date      = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : '';
975
+		return EEH_Form_Fields::generate_event_months_dropdown($cur_date, $status, $category, $active_status);
976
+	}
977
+
978
+
979
+	/**
980
+	 * returns a list of "active" statuses on the event
981
+	 *
982
+	 * @param  string $current_value whatever the current active status is
983
+	 * @return string
984
+	 */
985
+	public function active_status_dropdown($current_value = '')
986
+	{
987
+		$select_name = 'active_status';
988
+		$values      = array(
989
+			'none'     => esc_html__('Show Active/Inactive', 'event_espresso'),
990
+			'active'   => esc_html__('Active', 'event_espresso'),
991
+			'upcoming' => esc_html__('Upcoming', 'event_espresso'),
992
+			'expired'  => esc_html__('Expired', 'event_espresso'),
993
+			'inactive' => esc_html__('Inactive', 'event_espresso'),
994
+		);
995
+		$id          = 'id="espresso-active-status-dropdown-filter"';
996
+		$class       = 'wide';
997
+		return EEH_Form_Fields::select_input($select_name, $values, $current_value, $id, $class);
998
+	}
999
+
1000
+
1001
+	/**
1002
+	 * output a dropdown of the categories for the category filter on the event admin list table
1003
+	 *
1004
+	 * @access  public
1005
+	 * @return string html
1006
+	 */
1007
+	public function category_dropdown()
1008
+	{
1009
+		$cur_cat = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1;
1010
+		return EEH_Form_Fields::generate_event_category_dropdown($cur_cat);
1011
+	}
1012
+
1013
+
1014
+	/**
1015
+	 * get total number of events today
1016
+	 *
1017
+	 * @access public
1018
+	 * @return int
1019
+	 * @throws EE_Error
1020
+	 */
1021
+	public function total_events_today()
1022
+	{
1023
+		$start = EEM_Datetime::instance()->convert_datetime_for_query(
1024
+			'DTT_EVT_start',
1025
+			date('Y-m-d') . ' 00:00:00',
1026
+			'Y-m-d H:i:s',
1027
+			'UTC'
1028
+		);
1029
+		$end   = EEM_Datetime::instance()->convert_datetime_for_query(
1030
+			'DTT_EVT_start',
1031
+			date('Y-m-d') . ' 23:59:59',
1032
+			'Y-m-d H:i:s',
1033
+			'UTC'
1034
+		);
1035
+		$where = array(
1036
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1037
+		);
1038
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1039
+		return $count;
1040
+	}
1041
+
1042
+
1043
+	/**
1044
+	 * get total number of events this month
1045
+	 *
1046
+	 * @access public
1047
+	 * @return int
1048
+	 * @throws EE_Error
1049
+	 */
1050
+	public function total_events_this_month()
1051
+	{
1052
+		//Dates
1053
+		$this_year_r     = date('Y');
1054
+		$this_month_r    = date('m');
1055
+		$days_this_month = date('t');
1056
+		$start           = EEM_Datetime::instance()->convert_datetime_for_query(
1057
+			'DTT_EVT_start',
1058
+			$this_year_r . '-' . $this_month_r . '-01 00:00:00',
1059
+			'Y-m-d H:i:s',
1060
+			'UTC'
1061
+		);
1062
+		$end             = EEM_Datetime::instance()->convert_datetime_for_query(
1063
+			'DTT_EVT_start',
1064
+			$this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1065
+			'Y-m-d H:i:s',
1066
+			'UTC'
1067
+		);
1068
+		$where           = array(
1069
+			'Datetime.DTT_EVT_start' => array('BETWEEN', array($start, $end)),
1070
+		);
1071
+		$count           = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
1072
+		return $count;
1073
+	}
1074
+
1075
+
1076
+	/** DEFAULT TICKETS STUFF **/
1077
+
1078
+	/**
1079
+	 * Output default tickets list table view.
1080
+	 */
1081
+	public function _tickets_overview_list_table()
1082
+	{
1083
+		$this->_search_btn_label = esc_html__('Tickets', 'event_espresso');
1084
+		$this->display_admin_list_table_page_with_no_sidebar();
1085
+	}
1086
+
1087
+
1088
+	/**
1089
+	 * @param int  $per_page
1090
+	 * @param bool $count
1091
+	 * @param bool $trashed
1092
+	 * @return \EE_Soft_Delete_Base_Class[]|int
1093
+	 */
1094
+	public function get_default_tickets($per_page = 10, $count = false, $trashed = false)
1095
+	{
1096
+		$orderby = empty($this->_req_data['orderby']) ? 'TKT_name' : $this->_req_data['orderby'];
1097
+		$order   = empty($this->_req_data['order']) ? 'ASC' : $this->_req_data['order'];
1098
+		switch ($orderby) {
1099
+			case 'TKT_name':
1100
+				$orderby = array('TKT_name' => $order);
1101
+				break;
1102
+			case 'TKT_price':
1103
+				$orderby = array('TKT_price' => $order);
1104
+				break;
1105
+			case 'TKT_uses':
1106
+				$orderby = array('TKT_uses' => $order);
1107
+				break;
1108
+			case 'TKT_min':
1109
+				$orderby = array('TKT_min' => $order);
1110
+				break;
1111
+			case 'TKT_max':
1112
+				$orderby = array('TKT_max' => $order);
1113
+				break;
1114
+			case 'TKT_qty':
1115
+				$orderby = array('TKT_qty' => $order);
1116
+				break;
1117
+		}
1118
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
1119
+			? $this->_req_data['paged']
1120
+			: 1;
1121
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
1122
+			? $this->_req_data['perpage']
1123
+			: $per_page;
1124
+		$_where       = array(
1125
+			'TKT_is_default' => 1,
1126
+			'TKT_deleted'    => $trashed,
1127
+		);
1128
+		$offset       = ($current_page - 1) * $per_page;
1129
+		$limit        = array($offset, $per_page);
1130
+		if (isset($this->_req_data['s'])) {
1131
+			$sstr         = '%' . $this->_req_data['s'] . '%';
1132
+			$_where['OR'] = array(
1133
+				'TKT_name'        => array('LIKE', $sstr),
1134
+				'TKT_description' => array('LIKE', $sstr),
1135
+			);
1136
+		}
1137
+		$query_params = array(
1138
+			$_where,
1139
+			'order_by' => $orderby,
1140
+			'limit'    => $limit,
1141
+			'group_by' => 'TKT_ID',
1142
+		);
1143
+		if ($count) {
1144
+			return EEM_Ticket::instance()->count_deleted_and_undeleted(array($_where));
1145
+		} else {
1146
+			return EEM_Ticket::instance()->get_all_deleted_and_undeleted($query_params);
1147
+		}
1148
+	}
1149
+
1150
+
1151
+	/**
1152
+	 * @param bool $trash
1153
+	 * @throws EE_Error
1154
+	 */
1155
+	protected function _trash_or_restore_ticket($trash = false)
1156
+	{
1157
+		$success = 1;
1158
+		$TKT     = EEM_Ticket::instance();
1159
+		//checkboxes?
1160
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1161
+			//if array has more than one element then success message should be plural
1162
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1163
+			//cycle thru the boxes
1164
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1165
+				if ($trash) {
1166
+					if (! $TKT->delete_by_ID($TKT_ID)) {
1167
+						$success = 0;
1168
+					}
1169
+				} else {
1170
+					if (! $TKT->restore_by_ID($TKT_ID)) {
1171
+						$success = 0;
1172
+					}
1173
+				}
1174
+			}
1175
+		} else {
1176
+			//grab single id and trash
1177
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1178
+			if ($trash) {
1179
+				if (! $TKT->delete_by_ID($TKT_ID)) {
1180
+					$success = 0;
1181
+				}
1182
+			} else {
1183
+				if (! $TKT->restore_by_ID($TKT_ID)) {
1184
+					$success = 0;
1185
+				}
1186
+			}
1187
+		}
1188
+		$action_desc = $trash ? 'moved to the trash' : 'restored';
1189
+		$query_args  = array(
1190
+			'action' => 'ticket_list_table',
1191
+			'status' => $trash ? '' : 'trashed',
1192
+		);
1193
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1194
+	}
1195
+
1196
+
1197
+	/**
1198
+	 * Handles trashing default ticket.
1199
+	 */
1200
+	protected function _delete_ticket()
1201
+	{
1202
+		$success = 1;
1203
+		//checkboxes?
1204
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1205
+			//if array has more than one element then success message should be plural
1206
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1207
+			//cycle thru the boxes
1208
+			while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1209
+				//delete
1210
+				if (! $this->_delete_the_ticket($TKT_ID)) {
1211
+					$success = 0;
1212
+				}
1213
+			}
1214
+		} else {
1215
+			//grab single id and trash
1216
+			$TKT_ID = absint($this->_req_data['TKT_ID']);
1217
+			if (! $this->_delete_the_ticket($TKT_ID)) {
1218
+				$success = 0;
1219
+			}
1220
+		}
1221
+		$action_desc = 'deleted';
1222
+		$query_args  = array(
1223
+			'action' => 'ticket_list_table',
1224
+			'status' => 'trashed',
1225
+		);
1226
+		//fail safe.  If the default ticket count === 1 then we need to redirect to event overview.
1227
+		if (EEM_Ticket::instance()->count_deleted_and_undeleted(
1228
+			array(array('TKT_is_default' => 1)),
1229
+			'TKT_ID',
1230
+			true
1231
+		)
1232
+		) {
1233
+			$query_args = array();
1234
+		}
1235
+		$this->_redirect_after_action($success, 'Tickets', $action_desc, $query_args);
1236
+	}
1237
+
1238
+
1239
+	/**
1240
+	 * @param int $TKT_ID
1241
+	 * @return bool|int
1242
+	 * @throws EE_Error
1243
+	 */
1244
+	protected function _delete_the_ticket($TKT_ID)
1245
+	{
1246
+		$tkt = EEM_Ticket::instance()->get_one_by_ID($TKT_ID);
1247
+		$tkt->_remove_relations('Datetime');
1248
+		//delete all related prices first
1249
+		$tkt->delete_related_permanently('Price');
1250
+		return $tkt->delete_permanently();
1251
+	}
1252 1252
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -22,10 +22,10 @@  discard block
 block discarded – undo
22 22
     public function __construct($routing = true)
23 23
     {
24 24
         parent::__construct($routing);
25
-        if (! defined('EVENTS_CAF_TEMPLATE_PATH')) {
26
-            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'events/templates/');
27
-            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'events/assets/');
28
-            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'events/assets/');
25
+        if ( ! defined('EVENTS_CAF_TEMPLATE_PATH')) {
26
+            define('EVENTS_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'events/templates/');
27
+            define('EVENTS_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'events/assets/');
28
+            define('EVENTS_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'events/assets/');
29 29
         }
30 30
     }
31 31
 
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      */
36 36
     protected function _extend_page_config()
37 37
     {
38
-        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'events';
38
+        $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'events';
39 39
         //is there a evt_id in the request?
40 40
         $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
41 41
             ? $this->_req_data['EVT_ID']
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             'help_tour'     => array('Templates_Help_Tour'),
169 169
             'require_nonce' => false,
170 170
         );
171
-        $this->_page_config                   = array_merge($this->_page_config, $new_page_config);
171
+        $this->_page_config = array_merge($this->_page_config, $new_page_config);
172 172
         //add filters and actions
173 173
         //modifying _views
174 174
         add_filter(
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
          * check whether count of tickets is approaching the potential
242 242
          * limits for the server.
243 243
          */
244
-        if (! empty($data['input_count'])) {
244
+        if ( ! empty($data['input_count'])) {
245 245
             $response['max_input_vars_check'] = EE_Registry::instance()->CFG->environment->max_input_vars_limit_check(
246 246
                 $data['input_count']
247 247
             );
@@ -270,12 +270,12 @@  discard block
 block discarded – undo
270 270
     {
271 271
         $return = parent::extra_permalink_field_buttons($return, $id, $new_title, $new_slug);
272 272
         //make sure this is only when editing
273
-        if (! empty($id)) {
274
-            $href   = EE_Admin_Page::add_query_args_and_nonce(
273
+        if ( ! empty($id)) {
274
+            $href = EE_Admin_Page::add_query_args_and_nonce(
275 275
                 array('action' => 'duplicate_event', 'EVT_ID' => $id),
276 276
                 $this->_admin_base_url
277 277
             );
278
-            $title  = esc_attr__('Duplicate Event', 'event_espresso');
278
+            $title = esc_attr__('Duplicate Event', 'event_espresso');
279 279
             $return .= '<a href="'
280 280
                        . $href
281 281
                        . '" title="'
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
     {
323 323
         wp_register_script(
324 324
             'ee-event-editor-heartbeat',
325
-            EVENTS_CAF_ASSETS_URL . 'event-editor-heartbeat.js',
325
+            EVENTS_CAF_ASSETS_URL.'event-editor-heartbeat.js',
326 326
             array('ee_admin_js', 'heartbeat'),
327 327
             EVENT_ESPRESSO_VERSION,
328 328
             true
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
     public function add_additional_datetime_button($template, $template_args)
346 346
     {
347 347
         return EEH_Template::display_template(
348
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_add_additional_time.template.php',
348
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_add_additional_time.template.php',
349 349
             $template_args,
350 350
             true
351 351
         );
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
     public function add_datetime_clone_button($template, $template_args)
363 363
     {
364 364
         return EEH_Template::display_template(
365
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_metabox_clone_button.template.php',
365
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_metabox_clone_button.template.php',
366 366
             $template_args,
367 367
             true
368 368
         );
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
     public function datetime_timezones_template($template, $template_args)
380 380
     {
381 381
         return EEH_Template::display_template(
382
-            EVENTS_CAF_TEMPLATE_PATH . 'event_datetime_timezones.template.php',
382
+            EVENTS_CAF_TEMPLATE_PATH.'event_datetime_timezones.template.php',
383 383
             $template_args,
384 384
             true
385 385
         );
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
     protected function _set_list_table_views_default()
393 393
     {
394 394
         parent::_set_list_table_views_default();
395
-        $new_views    = array(
395
+        $new_views = array(
396 396
             'today' => array(
397 397
                 'slug'        => 'today',
398 398
                 'label'       => esc_html__('Today', 'event_espresso'),
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
     {
498 498
         // first make sure the ID for the event is in the request.
499 499
         //  If it isn't then we need to bail and redirect back to overview list table (cause how did we get here?)
500
-        if (! isset($this->_req_data['EVT_ID'])) {
500
+        if ( ! isset($this->_req_data['EVT_ID'])) {
501 501
             EE_Error::add_error(
502 502
                 esc_html__(
503 503
                     'In order to duplicate an event an Event ID is required.  None was given.',
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
         }
513 513
         //k we've got EVT_ID so let's use that to get the event we'll duplicate
514 514
         $orig_event = EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']);
515
-        if (! $orig_event instanceof EE_Event) {
515
+        if ( ! $orig_event instanceof EE_Event) {
516 516
             throw new EE_Error(
517 517
                 sprintf(
518 518
                     esc_html__('An EE_Event object could not be retrieved for the given ID (%s)', 'event_espresso'),
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
         $orig_ven = $orig_event->get_many_related('Venue');
529 529
         //reset the ID and modify other details to make it clear this is a dupe
530 530
         $new_event->set('EVT_ID', 0);
531
-        $new_name = $new_event->name() . ' ' . esc_html__('**DUPLICATE**', 'event_espresso');
531
+        $new_name = $new_event->name().' '.esc_html__('**DUPLICATE**', 'event_espresso');
532 532
         $new_event->set('EVT_name', $new_name);
533 533
         $new_event->set(
534 534
             'EVT_slug',
@@ -557,7 +557,7 @@  discard block
 block discarded – undo
557 557
             'Question_Group',
558 558
             array(array('Event_Question_Group.EQG_primary' => 1))
559 559
         );
560
-        if (! empty($orig_primary_qgs)) {
560
+        if ( ! empty($orig_primary_qgs)) {
561 561
             foreach ($orig_primary_qgs as $id => $obj) {
562 562
                 if ($obj instanceof EE_Question_Group) {
563 563
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 1));
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
             'Question_Group',
570 570
             array(array('Event_Question_Group.EQG_primary' => 0))
571 571
         );
572
-        if (! empty($orig_additional_qgs)) {
572
+        if ( ! empty($orig_additional_qgs)) {
573 573
             foreach ($orig_additional_qgs as $id => $obj) {
574 574
                 if ($obj instanceof EE_Question_Group) {
575 575
                     $new_event->_add_relation_to($obj, 'Question_Group', array('EQG_primary' => 0));
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
         //k now that we have the new event saved we can loop through the datetimes and start adding relations.
582 582
         $cloned_tickets = array();
583 583
         foreach ($orig_datetimes as $orig_dtt) {
584
-            if (! $orig_dtt instanceof EE_Datetime) {
584
+            if ( ! $orig_dtt instanceof EE_Datetime) {
585 585
                 continue;
586 586
             }
587 587
             $new_dtt   = clone $orig_dtt;
@@ -594,9 +594,9 @@  discard block
 block discarded – undo
594 594
             $new_event->_add_relation_to($new_dtt, 'Datetime');
595 595
             $new_event->save();
596 596
             //now let's get the ticket relations setup.
597
-            foreach ((array)$orig_tkts as $orig_tkt) {
597
+            foreach ((array) $orig_tkts as $orig_tkt) {
598 598
                 //it's possible a datetime will have no tickets so let's verify we HAVE a ticket first.
599
-                if (! $orig_tkt instanceof EE_Ticket) {
599
+                if ( ! $orig_tkt instanceof EE_Ticket) {
600 600
                     continue;
601 601
                 }
602 602
                 //is this ticket archived?  If it is then let's skip
@@ -692,8 +692,8 @@  discard block
 block discarded – undo
692 692
             array('action' => 'sample_export_file'),
693 693
             $this->_admin_base_url
694 694
         );
695
-        $content                                    = EEH_Template::display_template(
696
-            EVENTS_CAF_TEMPLATE_PATH . 'import_page.template.php',
695
+        $content = EEH_Template::display_template(
696
+            EVENTS_CAF_TEMPLATE_PATH.'import_page.template.php',
697 697
             $this->_template_args,
698 698
             true
699 699
         );
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
      */
711 711
     protected function _import_events()
712 712
     {
713
-        require_once(EE_CLASSES . 'EE_Import.class.php');
713
+        require_once(EE_CLASSES.'EE_Import.class.php');
714 714
         $success = EE_Import::instance()->import();
715 715
         $this->_redirect_after_action($success, 'Import File', 'ran', array('action' => 'import_page'), true);
716 716
     }
@@ -738,9 +738,9 @@  discard block
 block discarded – undo
738 738
             'action' => 'all_event_data',
739 739
             'EVT_ID' => $event_ids,
740 740
         );
741
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
742
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
743
-            require_once(EE_CLASSES . 'EE_Export.class.php');
741
+        $this->_req_data = array_merge($this->_req_data, $new_request_args);
742
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
743
+            require_once(EE_CLASSES.'EE_Export.class.php');
744 744
             $EE_Export = EE_Export::instance($this->_req_data);
745 745
             $EE_Export->export();
746 746
         }
@@ -760,9 +760,9 @@  discard block
 block discarded – undo
760 760
             'action'       => 'categories',
761 761
             'category_ids' => $this->_req_data['EVT_CAT_ID'],
762 762
         );
763
-        $this->_req_data  = array_merge($this->_req_data, $new_request_args);
764
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
765
-            require_once(EE_CLASSES . 'EE_Export.class.php');
763
+        $this->_req_data = array_merge($this->_req_data, $new_request_args);
764
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
765
+            require_once(EE_CLASSES.'EE_Export.class.php');
766 766
             $EE_Export = EE_Export::instance($this->_req_data);
767 767
             $EE_Export->export();
768 768
         }
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
         $this->_set_add_edit_form_tags('update_template_settings');
800 800
         $this->_set_publish_post_box_vars(null, false, false, null, false);
801 801
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
802
-            EVENTS_CAF_TEMPLATE_PATH . 'template_settings.template.php',
802
+            EVENTS_CAF_TEMPLATE_PATH.'template_settings.template.php',
803 803
             $this->_template_args,
804 804
             true
805 805
         );
@@ -871,11 +871,11 @@  discard block
 block discarded – undo
871 871
      */
872 872
     public function registration_options_meta_box()
873 873
     {
874
-        $yes_no_values                                    = array(
874
+        $yes_no_values = array(
875 875
             array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
876 876
             array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
877 877
         );
878
-        $default_reg_status_values                        = EEM_Registration::reg_status_array(
878
+        $default_reg_status_values = EEM_Registration::reg_status_array(
879 879
             array(
880 880
                 EEM_Registration::status_id_cancelled,
881 881
                 EEM_Registration::status_id_declined,
@@ -892,12 +892,12 @@  discard block
 block discarded – undo
892 892
             $default_reg_status_values,
893 893
             $this->_cpt_model_obj->default_registration_status()
894 894
         );
895
-        $template_args['display_description']             = EEH_Form_Fields::select_input(
895
+        $template_args['display_description'] = EEH_Form_Fields::select_input(
896 896
             'display_desc',
897 897
             $yes_no_values,
898 898
             $this->_cpt_model_obj->display_description()
899 899
         );
900
-        $template_args['display_ticket_selector']         = EEH_Form_Fields::select_input(
900
+        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
901 901
             'display_ticket_selector',
902 902
             $yes_no_values,
903 903
             $this->_cpt_model_obj->display_ticket_selector(),
@@ -918,7 +918,7 @@  discard block
 block discarded – undo
918 918
             $default_reg_status_values
919 919
         );
920 920
         EEH_Template::display_template(
921
-            EVENTS_CAF_TEMPLATE_PATH . 'event_registration_options.template.php',
921
+            EVENTS_CAF_TEMPLATE_PATH.'event_registration_options.template.php',
922 922
             $template_args
923 923
         );
924 924
     }
@@ -1022,13 +1022,13 @@  discard block
 block discarded – undo
1022 1022
     {
1023 1023
         $start = EEM_Datetime::instance()->convert_datetime_for_query(
1024 1024
             'DTT_EVT_start',
1025
-            date('Y-m-d') . ' 00:00:00',
1025
+            date('Y-m-d').' 00:00:00',
1026 1026
             'Y-m-d H:i:s',
1027 1027
             'UTC'
1028 1028
         );
1029
-        $end   = EEM_Datetime::instance()->convert_datetime_for_query(
1029
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1030 1030
             'DTT_EVT_start',
1031
-            date('Y-m-d') . ' 23:59:59',
1031
+            date('Y-m-d').' 23:59:59',
1032 1032
             'Y-m-d H:i:s',
1033 1033
             'UTC'
1034 1034
         );
@@ -1055,13 +1055,13 @@  discard block
 block discarded – undo
1055 1055
         $days_this_month = date('t');
1056 1056
         $start           = EEM_Datetime::instance()->convert_datetime_for_query(
1057 1057
             'DTT_EVT_start',
1058
-            $this_year_r . '-' . $this_month_r . '-01 00:00:00',
1058
+            $this_year_r.'-'.$this_month_r.'-01 00:00:00',
1059 1059
             'Y-m-d H:i:s',
1060 1060
             'UTC'
1061 1061
         );
1062
-        $end             = EEM_Datetime::instance()->convert_datetime_for_query(
1062
+        $end = EEM_Datetime::instance()->convert_datetime_for_query(
1063 1063
             'DTT_EVT_start',
1064
-            $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' 23:59:59',
1064
+            $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' 23:59:59',
1065 1065
             'Y-m-d H:i:s',
1066 1066
             'UTC'
1067 1067
         );
@@ -1128,7 +1128,7 @@  discard block
 block discarded – undo
1128 1128
         $offset       = ($current_page - 1) * $per_page;
1129 1129
         $limit        = array($offset, $per_page);
1130 1130
         if (isset($this->_req_data['s'])) {
1131
-            $sstr         = '%' . $this->_req_data['s'] . '%';
1131
+            $sstr         = '%'.$this->_req_data['s'].'%';
1132 1132
             $_where['OR'] = array(
1133 1133
                 'TKT_name'        => array('LIKE', $sstr),
1134 1134
                 'TKT_description' => array('LIKE', $sstr),
@@ -1157,17 +1157,17 @@  discard block
 block discarded – undo
1157 1157
         $success = 1;
1158 1158
         $TKT     = EEM_Ticket::instance();
1159 1159
         //checkboxes?
1160
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1160
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1161 1161
             //if array has more than one element then success message should be plural
1162 1162
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1163 1163
             //cycle thru the boxes
1164 1164
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1165 1165
                 if ($trash) {
1166
-                    if (! $TKT->delete_by_ID($TKT_ID)) {
1166
+                    if ( ! $TKT->delete_by_ID($TKT_ID)) {
1167 1167
                         $success = 0;
1168 1168
                     }
1169 1169
                 } else {
1170
-                    if (! $TKT->restore_by_ID($TKT_ID)) {
1170
+                    if ( ! $TKT->restore_by_ID($TKT_ID)) {
1171 1171
                         $success = 0;
1172 1172
                     }
1173 1173
                 }
@@ -1176,11 +1176,11 @@  discard block
 block discarded – undo
1176 1176
             //grab single id and trash
1177 1177
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1178 1178
             if ($trash) {
1179
-                if (! $TKT->delete_by_ID($TKT_ID)) {
1179
+                if ( ! $TKT->delete_by_ID($TKT_ID)) {
1180 1180
                     $success = 0;
1181 1181
                 }
1182 1182
             } else {
1183
-                if (! $TKT->restore_by_ID($TKT_ID)) {
1183
+                if ( ! $TKT->restore_by_ID($TKT_ID)) {
1184 1184
                     $success = 0;
1185 1185
                 }
1186 1186
             }
@@ -1201,20 +1201,20 @@  discard block
 block discarded – undo
1201 1201
     {
1202 1202
         $success = 1;
1203 1203
         //checkboxes?
1204
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1204
+        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1205 1205
             //if array has more than one element then success message should be plural
1206 1206
             $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1207 1207
             //cycle thru the boxes
1208 1208
             while (list($TKT_ID, $value) = each($this->_req_data['checkbox'])) {
1209 1209
                 //delete
1210
-                if (! $this->_delete_the_ticket($TKT_ID)) {
1210
+                if ( ! $this->_delete_the_ticket($TKT_ID)) {
1211 1211
                     $success = 0;
1212 1212
                 }
1213 1213
             }
1214 1214
         } else {
1215 1215
             //grab single id and trash
1216 1216
             $TKT_ID = absint($this->_req_data['TKT_ID']);
1217
-            if (! $this->_delete_the_ticket($TKT_ID)) {
1217
+            if ( ! $this->_delete_the_ticket($TKT_ID)) {
1218 1218
                 $success = 0;
1219 1219
             }
1220 1220
         }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('ABSPATH')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /*
5 5
   Plugin Name:		Event Espresso
@@ -40,243 +40,243 @@  discard block
 block discarded – undo
40 40
  * @since            4.0
41 41
  */
42 42
 if (function_exists('espresso_version')) {
43
-    /**
44
-     *    espresso_duplicate_plugin_error
45
-     *    displays if more than one version of EE is activated at the same time
46
-     */
47
-    function espresso_duplicate_plugin_error()
48
-    {
49
-        ?>
43
+	/**
44
+	 *    espresso_duplicate_plugin_error
45
+	 *    displays if more than one version of EE is activated at the same time
46
+	 */
47
+	function espresso_duplicate_plugin_error()
48
+	{
49
+		?>
50 50
         <div class="error">
51 51
             <p>
52 52
                 <?php echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                ); ?>
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+				); ?>
56 56
             </p>
57 57
         </div>
58 58
         <?php
59
-        espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-    }
59
+		espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+	}
61 61
 
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
-    if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.3.9');
65
+	if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                            esc_html__(
79
-                                    'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                                    'event_espresso'
81
-                            ),
82
-                            EE_MIN_PHP_VER_REQUIRED,
83
-                            PHP_VERSION,
84
-                            '<br/>',
85
-                            '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+							esc_html__(
79
+									'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+									'event_espresso'
81
+							),
82
+							EE_MIN_PHP_VER_REQUIRED,
83
+							PHP_VERSION,
84
+							'<br/>',
85
+							'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.006');
105
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.44.rc.006');
105
+		}
106 106
 
107
-        // define versions
108
-        define('EVENT_ESPRESSO_VERSION', espresso_version());
109
-        define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
-        define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
-        define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
-        //used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
-        if ( ! defined('DS')) {
115
-            define('DS', '/');
116
-        }
117
-        if ( ! defined('PS')) {
118
-            define('PS', PATH_SEPARATOR);
119
-        }
120
-        if ( ! defined('SP')) {
121
-            define('SP', ' ');
122
-        }
123
-        if ( ! defined('EENL')) {
124
-            define('EENL', "\n");
125
-        }
126
-        define('EE_SUPPORT_EMAIL', '[email protected]');
127
-        // define the plugin directory and URL
128
-        define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
-        define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
-        define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
-        // main root folder paths
132
-        define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
-        define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
-        define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
-        define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
-        define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
-        define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
-        define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
-        define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
-        // core system paths
141
-        define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
-        define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
-        define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
-        define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
-        define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
-        define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
-        define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
-        define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
-        define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
-        define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
-        define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
-        define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
-        // gateways
154
-        define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
-        define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
-        // asset URL paths
157
-        define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
-        define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
-        define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
-        define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
-        define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
-        define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
-        // define upload paths
164
-        $uploads = wp_upload_dir();
165
-        // define the uploads directory and URL
166
-        define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
-        define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
-        // define the templates directory and URL
169
-        define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
-        define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
-        // define the gateway directory and URL
172
-        define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
-        define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
-        // languages folder/path
175
-        define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
-        define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
-        //check for dompdf fonts in uploads
178
-        if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
-            define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
-        }
181
-        //ajax constants
182
-        define(
183
-                'EE_FRONT_AJAX',
184
-                isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
-        );
186
-        define(
187
-                'EE_ADMIN_AJAX',
188
-                isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
-        );
190
-        //just a handy constant occasionally needed for finding values representing infinity in the DB
191
-        //you're better to use this than its straight value (currently -1) in case you ever
192
-        //want to change its default value! or find when -1 means infinity
193
-        define('EE_INF_IN_DB', -1);
194
-        define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
-        define('EE_DEBUG', false);
196
-        // for older WP versions
197
-        if ( ! defined('MONTH_IN_SECONDS')) {
198
-            define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
-        }
200
-        /**
201
-         *    espresso_plugin_activation
202
-         *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
-         */
204
-        function espresso_plugin_activation()
205
-        {
206
-            update_option('ee_espresso_activation', true);
207
-        }
107
+		// define versions
108
+		define('EVENT_ESPRESSO_VERSION', espresso_version());
109
+		define('EE_MIN_WP_VER_REQUIRED', '4.1');
110
+		define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2');
111
+		define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44');
112
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
113
+		//used to be DIRECTORY_SEPARATOR, but that caused issues on windows
114
+		if ( ! defined('DS')) {
115
+			define('DS', '/');
116
+		}
117
+		if ( ! defined('PS')) {
118
+			define('PS', PATH_SEPARATOR);
119
+		}
120
+		if ( ! defined('SP')) {
121
+			define('SP', ' ');
122
+		}
123
+		if ( ! defined('EENL')) {
124
+			define('EENL', "\n");
125
+		}
126
+		define('EE_SUPPORT_EMAIL', '[email protected]');
127
+		// define the plugin directory and URL
128
+		define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE));
129
+		define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE));
130
+		define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE));
131
+		// main root folder paths
132
+		define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS);
133
+		define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS);
134
+		define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS);
135
+		define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS);
136
+		define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS);
137
+		define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS);
138
+		define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS);
139
+		define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS);
140
+		// core system paths
141
+		define('EE_ADMIN', EE_CORE . 'admin' . DS);
142
+		define('EE_CPTS', EE_CORE . 'CPTs' . DS);
143
+		define('EE_CLASSES', EE_CORE . 'db_classes' . DS);
144
+		define('EE_INTERFACES', EE_CORE . 'interfaces' . DS);
145
+		define('EE_BUSINESS', EE_CORE . 'business' . DS);
146
+		define('EE_MODELS', EE_CORE . 'db_models' . DS);
147
+		define('EE_HELPERS', EE_CORE . 'helpers' . DS);
148
+		define('EE_LIBRARIES', EE_CORE . 'libraries' . DS);
149
+		define('EE_TEMPLATES', EE_CORE . 'templates' . DS);
150
+		define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS);
151
+		define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS);
152
+		define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS);
153
+		// gateways
154
+		define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS);
155
+		define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS);
156
+		// asset URL paths
157
+		define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS);
158
+		define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS);
159
+		define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS);
160
+		define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS);
161
+		define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/');
162
+		define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/');
163
+		// define upload paths
164
+		$uploads = wp_upload_dir();
165
+		// define the uploads directory and URL
166
+		define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS);
167
+		define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS);
168
+		// define the templates directory and URL
169
+		define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS);
170
+		define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS);
171
+		// define the gateway directory and URL
172
+		define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS);
173
+		define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS);
174
+		// languages folder/path
175
+		define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS);
176
+		define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS);
177
+		//check for dompdf fonts in uploads
178
+		if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) {
179
+			define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS);
180
+		}
181
+		//ajax constants
182
+		define(
183
+				'EE_FRONT_AJAX',
184
+				isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false
185
+		);
186
+		define(
187
+				'EE_ADMIN_AJAX',
188
+				isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false
189
+		);
190
+		//just a handy constant occasionally needed for finding values representing infinity in the DB
191
+		//you're better to use this than its straight value (currently -1) in case you ever
192
+		//want to change its default value! or find when -1 means infinity
193
+		define('EE_INF_IN_DB', -1);
194
+		define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX);
195
+		define('EE_DEBUG', false);
196
+		// for older WP versions
197
+		if ( ! defined('MONTH_IN_SECONDS')) {
198
+			define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30);
199
+		}
200
+		/**
201
+		 *    espresso_plugin_activation
202
+		 *    adds a wp-option to indicate that EE has been activated via the WP admin plugins page
203
+		 */
204
+		function espresso_plugin_activation()
205
+		{
206
+			update_option('ee_espresso_activation', true);
207
+		}
208 208
 
209
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
-        /**
211
-         *    espresso_load_error_handling
212
-         *    this function loads EE's class for handling exceptions and errors
213
-         */
214
-        function espresso_load_error_handling()
215
-        {
216
-            // load debugging tools
217
-            if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
-                require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
-                EEH_Debug_Tools::instance();
220
-            }
221
-            // load error handling
222
-            if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
-                require_once(EE_CORE . 'EE_Error.core.php');
224
-            } else {
225
-                wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
-            }
227
-        }
209
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
210
+		/**
211
+		 *    espresso_load_error_handling
212
+		 *    this function loads EE's class for handling exceptions and errors
213
+		 */
214
+		function espresso_load_error_handling()
215
+		{
216
+			// load debugging tools
217
+			if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) {
218
+				require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php');
219
+				EEH_Debug_Tools::instance();
220
+			}
221
+			// load error handling
222
+			if (is_readable(EE_CORE . 'EE_Error.core.php')) {
223
+				require_once(EE_CORE . 'EE_Error.core.php');
224
+			} else {
225
+				wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso'));
226
+			}
227
+		}
228 228
 
229
-        /**
230
-         *    espresso_load_required
231
-         *    given a class name and path, this function will load that file or throw an exception
232
-         *
233
-         * @param    string $classname
234
-         * @param    string $full_path_to_file
235
-         * @throws    EE_Error
236
-         */
237
-        function espresso_load_required($classname, $full_path_to_file)
238
-        {
239
-            static $error_handling_loaded = false;
240
-            if ( ! $error_handling_loaded) {
241
-                espresso_load_error_handling();
242
-                $error_handling_loaded = true;
243
-            }
244
-            if (is_readable($full_path_to_file)) {
245
-                require_once($full_path_to_file);
246
-            } else {
247
-                throw new EE_Error (
248
-                        sprintf(
249
-                                esc_html__(
250
-                                        'The %s class file could not be located or is not readable due to file permissions.',
251
-                                        'event_espresso'
252
-                                ),
253
-                                $classname
254
-                        )
255
-                );
256
-            }
257
-        }
229
+		/**
230
+		 *    espresso_load_required
231
+		 *    given a class name and path, this function will load that file or throw an exception
232
+		 *
233
+		 * @param    string $classname
234
+		 * @param    string $full_path_to_file
235
+		 * @throws    EE_Error
236
+		 */
237
+		function espresso_load_required($classname, $full_path_to_file)
238
+		{
239
+			static $error_handling_loaded = false;
240
+			if ( ! $error_handling_loaded) {
241
+				espresso_load_error_handling();
242
+				$error_handling_loaded = true;
243
+			}
244
+			if (is_readable($full_path_to_file)) {
245
+				require_once($full_path_to_file);
246
+			} else {
247
+				throw new EE_Error (
248
+						sprintf(
249
+								esc_html__(
250
+										'The %s class file could not be located or is not readable due to file permissions.',
251
+										'event_espresso'
252
+								),
253
+								$classname
254
+						)
255
+				);
256
+			}
257
+		}
258 258
 
259
-        espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
-        espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
-        espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
-        new EE_Bootstrap();
263
-    }
259
+		espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php');
260
+		espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php');
261
+		espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php');
262
+		new EE_Bootstrap();
263
+	}
264 264
 }
265 265
 if ( ! function_exists('espresso_deactivate_plugin')) {
266
-    /**
267
-     *    deactivate_plugin
268
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
-     *
270
-     * @access public
271
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
-     * @return    void
273
-     */
274
-    function espresso_deactivate_plugin($plugin_basename = '')
275
-    {
276
-        if ( ! function_exists('deactivate_plugins')) {
277
-            require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
-        }
279
-        unset($_GET['activate'], $_REQUEST['activate']);
280
-        deactivate_plugins($plugin_basename);
281
-    }
266
+	/**
267
+	 *    deactivate_plugin
268
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
269
+	 *
270
+	 * @access public
271
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
272
+	 * @return    void
273
+	 */
274
+	function espresso_deactivate_plugin($plugin_basename = '')
275
+	{
276
+		if ( ! function_exists('deactivate_plugins')) {
277
+			require_once(ABSPATH . 'wp-admin/includes/plugin.php');
278
+		}
279
+		unset($_GET['activate'], $_REQUEST['activate']);
280
+		deactivate_plugins($plugin_basename);
281
+	}
282 282
 }
283 283
\ No newline at end of file
Please login to merge, or discard this patch.