Completed
Branch BUG-10253-pending-always-pendi... (2508c1)
by
unknown
46:30 queued 34:43
created
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2550 added lines, -2550 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -17,2556 +17,2556 @@  discard block
 block discarded – undo
17 17
 class Events_Admin_Page extends EE_Admin_Page_CPT
18 18
 {
19 19
 
20
-    /**
21
-     * This will hold the event object for event_details screen.
22
-     *
23
-     * @access protected
24
-     * @var EE_Event $_event
25
-     */
26
-    protected $_event;
27
-
28
-
29
-    /**
30
-     * This will hold the category object for category_details screen.
31
-     *
32
-     * @var stdClass $_category
33
-     */
34
-    protected $_category;
35
-
36
-
37
-    /**
38
-     * This will hold the event model instance
39
-     *
40
-     * @var EEM_Event $_event_model
41
-     */
42
-    protected $_event_model;
43
-
44
-
45
-    /**
46
-     * @var EE_Event
47
-     */
48
-    protected $_cpt_model_obj = false;
49
-
50
-
51
-
52
-    protected function _init_page_props()
53
-    {
54
-        $this->page_slug = EVENTS_PG_SLUG;
55
-        $this->page_label = EVENTS_LABEL;
56
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
57
-        $this->_admin_base_path = EVENTS_ADMIN;
58
-        $this->_cpt_model_names = array(
59
-            'create_new' => 'EEM_Event',
60
-            'edit'       => 'EEM_Event',
61
-        );
62
-        $this->_cpt_edit_routes = array(
63
-            'espresso_events' => 'edit',
64
-        );
65
-        add_action(
66
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
67
-            array($this, 'verify_event_edit')
68
-        );
69
-    }
70
-
71
-
72
-
73
-    protected function _ajax_hooks()
74
-    {
75
-        //todo: all hooks for events ajax goes in here.
76
-    }
77
-
78
-
79
-
80
-    protected function _define_page_props()
81
-    {
82
-        $this->_admin_page_title = EVENTS_LABEL;
83
-        $this->_labels = array(
84
-            'buttons'      => array(
85
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
86
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
87
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
88
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
89
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
90
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
91
-            ),
92
-            'editor_title' => array(
93
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
94
-            ),
95
-            'publishbox'   => array(
96
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
97
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
98
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
99
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
100
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
101
-            ),
102
-        );
103
-    }
104
-
105
-
106
-
107
-    protected function _set_page_routes()
108
-    {
109
-        //load formatter helper
110
-        //load field generator helper
111
-        //is there a evt_id in the request?
112
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
113
-            ? $this->_req_data['EVT_ID'] : 0;
114
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
115
-        $this->_page_routes = array(
116
-            'default'                       => array(
117
-                'func'       => '_events_overview_list_table',
118
-                'capability' => 'ee_read_events',
119
-            ),
120
-            'create_new'                    => array(
121
-                'func'       => '_create_new_cpt_item',
122
-                'capability' => 'ee_edit_events',
123
-            ),
124
-            'edit'                          => array(
125
-                'func'       => '_edit_cpt_item',
126
-                'capability' => 'ee_edit_event',
127
-                'obj_id'     => $evt_id,
128
-            ),
129
-            'copy_event'                    => array(
130
-                'func'       => '_copy_events',
131
-                'capability' => 'ee_edit_event',
132
-                'obj_id'     => $evt_id,
133
-                'noheader'   => true,
134
-            ),
135
-            'trash_event'                   => array(
136
-                'func'       => '_trash_or_restore_event',
137
-                'args'       => array('event_status' => 'trash'),
138
-                'capability' => 'ee_delete_event',
139
-                'obj_id'     => $evt_id,
140
-                'noheader'   => true,
141
-            ),
142
-            'trash_events'                  => array(
143
-                'func'       => '_trash_or_restore_events',
144
-                'args'       => array('event_status' => 'trash'),
145
-                'capability' => 'ee_delete_events',
146
-                'noheader'   => true,
147
-            ),
148
-            'restore_event'                 => array(
149
-                'func'       => '_trash_or_restore_event',
150
-                'args'       => array('event_status' => 'draft'),
151
-                'capability' => 'ee_delete_event',
152
-                'obj_id'     => $evt_id,
153
-                'noheader'   => true,
154
-            ),
155
-            'restore_events'                => array(
156
-                'func'       => '_trash_or_restore_events',
157
-                'args'       => array('event_status' => 'draft'),
158
-                'capability' => 'ee_delete_events',
159
-                'noheader'   => true,
160
-            ),
161
-            'delete_event'                  => array(
162
-                'func'       => '_delete_event',
163
-                'capability' => 'ee_delete_event',
164
-                'obj_id'     => $evt_id,
165
-                'noheader'   => true,
166
-            ),
167
-            'delete_events'                 => array(
168
-                'func'       => '_delete_events',
169
-                'capability' => 'ee_delete_events',
170
-                'noheader'   => true,
171
-            ),
172
-            'view_report'                   => array(
173
-                'func'      => '_view_report',
174
-                'capablity' => 'ee_edit_events',
175
-            ),
176
-            'default_event_settings'        => array(
177
-                'func'       => '_default_event_settings',
178
-                'capability' => 'manage_options',
179
-            ),
180
-            'update_default_event_settings' => array(
181
-                'func'       => '_update_default_event_settings',
182
-                'capability' => 'manage_options',
183
-                'noheader'   => true,
184
-            ),
185
-            'template_settings'             => array(
186
-                'func'       => '_template_settings',
187
-                'capability' => 'manage_options',
188
-            ),
189
-            //event category tab related
190
-            'add_category'                  => array(
191
-                'func'       => '_category_details',
192
-                'capability' => 'ee_edit_event_category',
193
-                'args'       => array('add'),
194
-            ),
195
-            'edit_category'                 => array(
196
-                'func'       => '_category_details',
197
-                'capability' => 'ee_edit_event_category',
198
-                'args'       => array('edit'),
199
-            ),
200
-            'delete_categories'             => array(
201
-                'func'       => '_delete_categories',
202
-                'capability' => 'ee_delete_event_category',
203
-                'noheader'   => true,
204
-            ),
205
-            'delete_category'               => array(
206
-                'func'       => '_delete_categories',
207
-                'capability' => 'ee_delete_event_category',
208
-                'noheader'   => true,
209
-            ),
210
-            'insert_category'               => array(
211
-                'func'       => '_insert_or_update_category',
212
-                'args'       => array('new_category' => true),
213
-                'capability' => 'ee_edit_event_category',
214
-                'noheader'   => true,
215
-            ),
216
-            'update_category'               => array(
217
-                'func'       => '_insert_or_update_category',
218
-                'args'       => array('new_category' => false),
219
-                'capability' => 'ee_edit_event_category',
220
-                'noheader'   => true,
221
-            ),
222
-            'category_list'                 => array(
223
-                'func'       => '_category_list_table',
224
-                'capability' => 'ee_manage_event_categories',
225
-            ),
226
-        );
227
-    }
228
-
229
-
230
-
231
-    protected function _set_page_config()
232
-    {
233
-        $this->_page_config = array(
234
-            'default'                => array(
235
-                'nav'           => array(
236
-                    'label' => esc_html__('Overview', 'event_espresso'),
237
-                    'order' => 10,
238
-                ),
239
-                'list_table'    => 'Events_Admin_List_Table',
240
-                'help_tabs'     => array(
241
-                    'events_overview_help_tab'                       => array(
242
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
243
-                        'filename' => 'events_overview',
244
-                    ),
245
-                    'events_overview_table_column_headings_help_tab' => array(
246
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
247
-                        'filename' => 'events_overview_table_column_headings',
248
-                    ),
249
-                    'events_overview_filters_help_tab'               => array(
250
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
251
-                        'filename' => 'events_overview_filters',
252
-                    ),
253
-                    'events_overview_view_help_tab'                  => array(
254
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
255
-                        'filename' => 'events_overview_views',
256
-                    ),
257
-                    'events_overview_other_help_tab'                 => array(
258
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
259
-                        'filename' => 'events_overview_other',
260
-                    ),
261
-                ),
262
-                'help_tour'     => array(
263
-                    'Event_Overview_Help_Tour',
264
-                    //'New_Features_Test_Help_Tour' for testing multiple help tour
265
-                ),
266
-                'qtips'         => array(
267
-                    'EE_Event_List_Table_Tips',
268
-                ),
269
-                'require_nonce' => false,
270
-            ),
271
-            'create_new'             => array(
272
-                'nav'           => array(
273
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
274
-                    'order'      => 5,
275
-                    'persistent' => false,
276
-                ),
277
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
278
-                'help_tabs'     => array(
279
-                    'event_editor_help_tab'                            => array(
280
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
281
-                        'filename' => 'event_editor',
282
-                    ),
283
-                    'event_editor_title_richtexteditor_help_tab'       => array(
284
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
285
-                        'filename' => 'event_editor_title_richtexteditor',
286
-                    ),
287
-                    'event_editor_venue_details_help_tab'              => array(
288
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
289
-                        'filename' => 'event_editor_venue_details',
290
-                    ),
291
-                    'event_editor_event_datetimes_help_tab'            => array(
292
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
293
-                        'filename' => 'event_editor_event_datetimes',
294
-                    ),
295
-                    'event_editor_event_tickets_help_tab'              => array(
296
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
297
-                        'filename' => 'event_editor_event_tickets',
298
-                    ),
299
-                    'event_editor_event_registration_options_help_tab' => array(
300
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
301
-                        'filename' => 'event_editor_event_registration_options',
302
-                    ),
303
-                    'event_editor_tags_categories_help_tab'            => array(
304
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
305
-                        'filename' => 'event_editor_tags_categories',
306
-                    ),
307
-                    'event_editor_questions_registrants_help_tab'      => array(
308
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
309
-                        'filename' => 'event_editor_questions_registrants',
310
-                    ),
311
-                    'event_editor_save_new_event_help_tab'             => array(
312
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
313
-                        'filename' => 'event_editor_save_new_event',
314
-                    ),
315
-                    'event_editor_other_help_tab'                      => array(
316
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
317
-                        'filename' => 'event_editor_other',
318
-                    ),
319
-                ),
320
-                'help_tour'     => array(
321
-                    'Event_Editor_Help_Tour',
322
-                ),
323
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
324
-                'require_nonce' => false,
325
-            ),
326
-            'edit'                   => array(
327
-                'nav'           => array(
328
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
329
-                    'order'      => 5,
330
-                    'persistent' => false,
331
-                    'url'        => isset($this->_req_data['post'])
332
-                        ? EE_Admin_Page::add_query_args_and_nonce(
333
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
334
-                            $this->_current_page_view_url
335
-                        )
336
-                        : $this->_admin_base_url,
337
-                ),
338
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
339
-                'help_tabs'     => array(
340
-                    'event_editor_help_tab'                            => array(
341
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
342
-                        'filename' => 'event_editor',
343
-                    ),
344
-                    'event_editor_title_richtexteditor_help_tab'       => array(
345
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
346
-                        'filename' => 'event_editor_title_richtexteditor',
347
-                    ),
348
-                    'event_editor_venue_details_help_tab'              => array(
349
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
350
-                        'filename' => 'event_editor_venue_details',
351
-                    ),
352
-                    'event_editor_event_datetimes_help_tab'            => array(
353
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
354
-                        'filename' => 'event_editor_event_datetimes',
355
-                    ),
356
-                    'event_editor_event_tickets_help_tab'              => array(
357
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
358
-                        'filename' => 'event_editor_event_tickets',
359
-                    ),
360
-                    'event_editor_event_registration_options_help_tab' => array(
361
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
362
-                        'filename' => 'event_editor_event_registration_options',
363
-                    ),
364
-                    'event_editor_tags_categories_help_tab'            => array(
365
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
366
-                        'filename' => 'event_editor_tags_categories',
367
-                    ),
368
-                    'event_editor_questions_registrants_help_tab'      => array(
369
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
370
-                        'filename' => 'event_editor_questions_registrants',
371
-                    ),
372
-                    'event_editor_save_new_event_help_tab'             => array(
373
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
374
-                        'filename' => 'event_editor_save_new_event',
375
-                    ),
376
-                    'event_editor_other_help_tab'                      => array(
377
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
378
-                        'filename' => 'event_editor_other',
379
-                    ),
380
-                ),
381
-                /*'help_tour' => array(
20
+	/**
21
+	 * This will hold the event object for event_details screen.
22
+	 *
23
+	 * @access protected
24
+	 * @var EE_Event $_event
25
+	 */
26
+	protected $_event;
27
+
28
+
29
+	/**
30
+	 * This will hold the category object for category_details screen.
31
+	 *
32
+	 * @var stdClass $_category
33
+	 */
34
+	protected $_category;
35
+
36
+
37
+	/**
38
+	 * This will hold the event model instance
39
+	 *
40
+	 * @var EEM_Event $_event_model
41
+	 */
42
+	protected $_event_model;
43
+
44
+
45
+	/**
46
+	 * @var EE_Event
47
+	 */
48
+	protected $_cpt_model_obj = false;
49
+
50
+
51
+
52
+	protected function _init_page_props()
53
+	{
54
+		$this->page_slug = EVENTS_PG_SLUG;
55
+		$this->page_label = EVENTS_LABEL;
56
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
57
+		$this->_admin_base_path = EVENTS_ADMIN;
58
+		$this->_cpt_model_names = array(
59
+			'create_new' => 'EEM_Event',
60
+			'edit'       => 'EEM_Event',
61
+		);
62
+		$this->_cpt_edit_routes = array(
63
+			'espresso_events' => 'edit',
64
+		);
65
+		add_action(
66
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
67
+			array($this, 'verify_event_edit')
68
+		);
69
+	}
70
+
71
+
72
+
73
+	protected function _ajax_hooks()
74
+	{
75
+		//todo: all hooks for events ajax goes in here.
76
+	}
77
+
78
+
79
+
80
+	protected function _define_page_props()
81
+	{
82
+		$this->_admin_page_title = EVENTS_LABEL;
83
+		$this->_labels = array(
84
+			'buttons'      => array(
85
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
86
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
87
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
88
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
89
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
90
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
91
+			),
92
+			'editor_title' => array(
93
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
94
+			),
95
+			'publishbox'   => array(
96
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
97
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
98
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
99
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
100
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
101
+			),
102
+		);
103
+	}
104
+
105
+
106
+
107
+	protected function _set_page_routes()
108
+	{
109
+		//load formatter helper
110
+		//load field generator helper
111
+		//is there a evt_id in the request?
112
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
113
+			? $this->_req_data['EVT_ID'] : 0;
114
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
115
+		$this->_page_routes = array(
116
+			'default'                       => array(
117
+				'func'       => '_events_overview_list_table',
118
+				'capability' => 'ee_read_events',
119
+			),
120
+			'create_new'                    => array(
121
+				'func'       => '_create_new_cpt_item',
122
+				'capability' => 'ee_edit_events',
123
+			),
124
+			'edit'                          => array(
125
+				'func'       => '_edit_cpt_item',
126
+				'capability' => 'ee_edit_event',
127
+				'obj_id'     => $evt_id,
128
+			),
129
+			'copy_event'                    => array(
130
+				'func'       => '_copy_events',
131
+				'capability' => 'ee_edit_event',
132
+				'obj_id'     => $evt_id,
133
+				'noheader'   => true,
134
+			),
135
+			'trash_event'                   => array(
136
+				'func'       => '_trash_or_restore_event',
137
+				'args'       => array('event_status' => 'trash'),
138
+				'capability' => 'ee_delete_event',
139
+				'obj_id'     => $evt_id,
140
+				'noheader'   => true,
141
+			),
142
+			'trash_events'                  => array(
143
+				'func'       => '_trash_or_restore_events',
144
+				'args'       => array('event_status' => 'trash'),
145
+				'capability' => 'ee_delete_events',
146
+				'noheader'   => true,
147
+			),
148
+			'restore_event'                 => array(
149
+				'func'       => '_trash_or_restore_event',
150
+				'args'       => array('event_status' => 'draft'),
151
+				'capability' => 'ee_delete_event',
152
+				'obj_id'     => $evt_id,
153
+				'noheader'   => true,
154
+			),
155
+			'restore_events'                => array(
156
+				'func'       => '_trash_or_restore_events',
157
+				'args'       => array('event_status' => 'draft'),
158
+				'capability' => 'ee_delete_events',
159
+				'noheader'   => true,
160
+			),
161
+			'delete_event'                  => array(
162
+				'func'       => '_delete_event',
163
+				'capability' => 'ee_delete_event',
164
+				'obj_id'     => $evt_id,
165
+				'noheader'   => true,
166
+			),
167
+			'delete_events'                 => array(
168
+				'func'       => '_delete_events',
169
+				'capability' => 'ee_delete_events',
170
+				'noheader'   => true,
171
+			),
172
+			'view_report'                   => array(
173
+				'func'      => '_view_report',
174
+				'capablity' => 'ee_edit_events',
175
+			),
176
+			'default_event_settings'        => array(
177
+				'func'       => '_default_event_settings',
178
+				'capability' => 'manage_options',
179
+			),
180
+			'update_default_event_settings' => array(
181
+				'func'       => '_update_default_event_settings',
182
+				'capability' => 'manage_options',
183
+				'noheader'   => true,
184
+			),
185
+			'template_settings'             => array(
186
+				'func'       => '_template_settings',
187
+				'capability' => 'manage_options',
188
+			),
189
+			//event category tab related
190
+			'add_category'                  => array(
191
+				'func'       => '_category_details',
192
+				'capability' => 'ee_edit_event_category',
193
+				'args'       => array('add'),
194
+			),
195
+			'edit_category'                 => array(
196
+				'func'       => '_category_details',
197
+				'capability' => 'ee_edit_event_category',
198
+				'args'       => array('edit'),
199
+			),
200
+			'delete_categories'             => array(
201
+				'func'       => '_delete_categories',
202
+				'capability' => 'ee_delete_event_category',
203
+				'noheader'   => true,
204
+			),
205
+			'delete_category'               => array(
206
+				'func'       => '_delete_categories',
207
+				'capability' => 'ee_delete_event_category',
208
+				'noheader'   => true,
209
+			),
210
+			'insert_category'               => array(
211
+				'func'       => '_insert_or_update_category',
212
+				'args'       => array('new_category' => true),
213
+				'capability' => 'ee_edit_event_category',
214
+				'noheader'   => true,
215
+			),
216
+			'update_category'               => array(
217
+				'func'       => '_insert_or_update_category',
218
+				'args'       => array('new_category' => false),
219
+				'capability' => 'ee_edit_event_category',
220
+				'noheader'   => true,
221
+			),
222
+			'category_list'                 => array(
223
+				'func'       => '_category_list_table',
224
+				'capability' => 'ee_manage_event_categories',
225
+			),
226
+		);
227
+	}
228
+
229
+
230
+
231
+	protected function _set_page_config()
232
+	{
233
+		$this->_page_config = array(
234
+			'default'                => array(
235
+				'nav'           => array(
236
+					'label' => esc_html__('Overview', 'event_espresso'),
237
+					'order' => 10,
238
+				),
239
+				'list_table'    => 'Events_Admin_List_Table',
240
+				'help_tabs'     => array(
241
+					'events_overview_help_tab'                       => array(
242
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
243
+						'filename' => 'events_overview',
244
+					),
245
+					'events_overview_table_column_headings_help_tab' => array(
246
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
247
+						'filename' => 'events_overview_table_column_headings',
248
+					),
249
+					'events_overview_filters_help_tab'               => array(
250
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
251
+						'filename' => 'events_overview_filters',
252
+					),
253
+					'events_overview_view_help_tab'                  => array(
254
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
255
+						'filename' => 'events_overview_views',
256
+					),
257
+					'events_overview_other_help_tab'                 => array(
258
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
259
+						'filename' => 'events_overview_other',
260
+					),
261
+				),
262
+				'help_tour'     => array(
263
+					'Event_Overview_Help_Tour',
264
+					//'New_Features_Test_Help_Tour' for testing multiple help tour
265
+				),
266
+				'qtips'         => array(
267
+					'EE_Event_List_Table_Tips',
268
+				),
269
+				'require_nonce' => false,
270
+			),
271
+			'create_new'             => array(
272
+				'nav'           => array(
273
+					'label'      => esc_html__('Add Event', 'event_espresso'),
274
+					'order'      => 5,
275
+					'persistent' => false,
276
+				),
277
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
278
+				'help_tabs'     => array(
279
+					'event_editor_help_tab'                            => array(
280
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
281
+						'filename' => 'event_editor',
282
+					),
283
+					'event_editor_title_richtexteditor_help_tab'       => array(
284
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
285
+						'filename' => 'event_editor_title_richtexteditor',
286
+					),
287
+					'event_editor_venue_details_help_tab'              => array(
288
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
289
+						'filename' => 'event_editor_venue_details',
290
+					),
291
+					'event_editor_event_datetimes_help_tab'            => array(
292
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
293
+						'filename' => 'event_editor_event_datetimes',
294
+					),
295
+					'event_editor_event_tickets_help_tab'              => array(
296
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
297
+						'filename' => 'event_editor_event_tickets',
298
+					),
299
+					'event_editor_event_registration_options_help_tab' => array(
300
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
301
+						'filename' => 'event_editor_event_registration_options',
302
+					),
303
+					'event_editor_tags_categories_help_tab'            => array(
304
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
305
+						'filename' => 'event_editor_tags_categories',
306
+					),
307
+					'event_editor_questions_registrants_help_tab'      => array(
308
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
309
+						'filename' => 'event_editor_questions_registrants',
310
+					),
311
+					'event_editor_save_new_event_help_tab'             => array(
312
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
313
+						'filename' => 'event_editor_save_new_event',
314
+					),
315
+					'event_editor_other_help_tab'                      => array(
316
+						'title'    => esc_html__('Event Other', 'event_espresso'),
317
+						'filename' => 'event_editor_other',
318
+					),
319
+				),
320
+				'help_tour'     => array(
321
+					'Event_Editor_Help_Tour',
322
+				),
323
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
324
+				'require_nonce' => false,
325
+			),
326
+			'edit'                   => array(
327
+				'nav'           => array(
328
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
329
+					'order'      => 5,
330
+					'persistent' => false,
331
+					'url'        => isset($this->_req_data['post'])
332
+						? EE_Admin_Page::add_query_args_and_nonce(
333
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
334
+							$this->_current_page_view_url
335
+						)
336
+						: $this->_admin_base_url,
337
+				),
338
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
339
+				'help_tabs'     => array(
340
+					'event_editor_help_tab'                            => array(
341
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
342
+						'filename' => 'event_editor',
343
+					),
344
+					'event_editor_title_richtexteditor_help_tab'       => array(
345
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
346
+						'filename' => 'event_editor_title_richtexteditor',
347
+					),
348
+					'event_editor_venue_details_help_tab'              => array(
349
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
350
+						'filename' => 'event_editor_venue_details',
351
+					),
352
+					'event_editor_event_datetimes_help_tab'            => array(
353
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
354
+						'filename' => 'event_editor_event_datetimes',
355
+					),
356
+					'event_editor_event_tickets_help_tab'              => array(
357
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
358
+						'filename' => 'event_editor_event_tickets',
359
+					),
360
+					'event_editor_event_registration_options_help_tab' => array(
361
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
362
+						'filename' => 'event_editor_event_registration_options',
363
+					),
364
+					'event_editor_tags_categories_help_tab'            => array(
365
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
366
+						'filename' => 'event_editor_tags_categories',
367
+					),
368
+					'event_editor_questions_registrants_help_tab'      => array(
369
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
370
+						'filename' => 'event_editor_questions_registrants',
371
+					),
372
+					'event_editor_save_new_event_help_tab'             => array(
373
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
374
+						'filename' => 'event_editor_save_new_event',
375
+					),
376
+					'event_editor_other_help_tab'                      => array(
377
+						'title'    => esc_html__('Event Other', 'event_espresso'),
378
+						'filename' => 'event_editor_other',
379
+					),
380
+				),
381
+				/*'help_tour' => array(
382 382
 					'Event_Edit_Help_Tour'
383 383
 				),*/
384
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
385
-                'require_nonce' => false,
386
-            ),
387
-            'default_event_settings' => array(
388
-                'nav'           => array(
389
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
390
-                    'order' => 40,
391
-                ),
392
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
393
-                'labels'        => array(
394
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
395
-                ),
396
-                'help_tabs'     => array(
397
-                    'default_settings_help_tab'        => array(
398
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
399
-                        'filename' => 'events_default_settings',
400
-                    ),
401
-                    'default_settings_status_help_tab' => array(
402
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
403
-                        'filename' => 'events_default_settings_status',
404
-                    ),
405
-                ),
406
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
407
-                'require_nonce' => false,
408
-            ),
409
-            //template settings
410
-            'template_settings'      => array(
411
-                'nav'           => array(
412
-                    'label' => esc_html__('Templates', 'event_espresso'),
413
-                    'order' => 30,
414
-                ),
415
-                'metaboxes'     => $this->_default_espresso_metaboxes,
416
-                'help_tabs'     => array(
417
-                    'general_settings_templates_help_tab' => array(
418
-                        'title'    => esc_html__('Templates', 'event_espresso'),
419
-                        'filename' => 'general_settings_templates',
420
-                    ),
421
-                ),
422
-                'help_tour'     => array('Templates_Help_Tour'),
423
-                'require_nonce' => false,
424
-            ),
425
-            //event category stuff
426
-            'add_category'           => array(
427
-                'nav'           => array(
428
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
429
-                    'order'      => 15,
430
-                    'persistent' => false,
431
-                ),
432
-                'help_tabs'     => array(
433
-                    'add_category_help_tab' => array(
434
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
435
-                        'filename' => 'events_add_category',
436
-                    ),
437
-                ),
438
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
439
-                'metaboxes'     => array('_publish_post_box'),
440
-                'require_nonce' => false,
441
-            ),
442
-            'edit_category'          => array(
443
-                'nav'           => array(
444
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
445
-                    'order'      => 15,
446
-                    'persistent' => false,
447
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
448
-                        ? add_query_arg(
449
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
450
-                            $this->_current_page_view_url
451
-                        )
452
-                        : $this->_admin_base_url,
453
-                ),
454
-                'help_tabs'     => array(
455
-                    'edit_category_help_tab' => array(
456
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
457
-                        'filename' => 'events_edit_category',
458
-                    ),
459
-                ),
460
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
461
-                'metaboxes'     => array('_publish_post_box'),
462
-                'require_nonce' => false,
463
-            ),
464
-            'category_list'          => array(
465
-                'nav'           => array(
466
-                    'label' => esc_html__('Categories', 'event_espresso'),
467
-                    'order' => 20,
468
-                ),
469
-                'list_table'    => 'Event_Categories_Admin_List_Table',
470
-                'help_tabs'     => array(
471
-                    'events_categories_help_tab'                       => array(
472
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
473
-                        'filename' => 'events_categories',
474
-                    ),
475
-                    'events_categories_table_column_headings_help_tab' => array(
476
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
477
-                        'filename' => 'events_categories_table_column_headings',
478
-                    ),
479
-                    'events_categories_view_help_tab'                  => array(
480
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
481
-                        'filename' => 'events_categories_views',
482
-                    ),
483
-                    'events_categories_other_help_tab'                 => array(
484
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
485
-                        'filename' => 'events_categories_other',
486
-                    ),
487
-                ),
488
-                'help_tour'     => array(
489
-                    'Event_Categories_Help_Tour',
490
-                ),
491
-                'metaboxes'     => $this->_default_espresso_metaboxes,
492
-                'require_nonce' => false,
493
-            ),
494
-        );
495
-    }
496
-
497
-
498
-
499
-    protected function _add_screen_options()
500
-    {
501
-        //todo
502
-    }
503
-
504
-
505
-
506
-    protected function _add_screen_options_default()
507
-    {
508
-        $this->_per_page_screen_option();
509
-    }
510
-
511
-
512
-
513
-    protected function _add_screen_options_category_list()
514
-    {
515
-        $page_title = $this->_admin_page_title;
516
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
517
-        $this->_per_page_screen_option();
518
-        $this->_admin_page_title = $page_title;
519
-    }
520
-
521
-
522
-
523
-    protected function _add_feature_pointers()
524
-    {
525
-        //todo
526
-    }
527
-
528
-
529
-
530
-    public function load_scripts_styles()
531
-    {
532
-        wp_register_style(
533
-            'events-admin-css',
534
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
535
-            array(),
536
-            EVENT_ESPRESSO_VERSION
537
-        );
538
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
539
-        wp_enqueue_style('events-admin-css');
540
-        wp_enqueue_style('ee-cat-admin');
541
-        //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
542
-        //registers for all views
543
-        //scripts
544
-        wp_register_script(
545
-            'event_editor_js',
546
-            EVENTS_ASSETS_URL . 'event_editor.js',
547
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
548
-            EVENT_ESPRESSO_VERSION,
549
-            true
550
-        );
551
-    }
552
-
553
-
554
-
555
-    /**
556
-     * enqueuing scripts and styles specific to this view
557
-     *
558
-     * @return void
559
-     */
560
-    public function load_scripts_styles_create_new()
561
-    {
562
-        $this->load_scripts_styles_edit();
563
-    }
564
-
565
-
566
-
567
-    /**
568
-     * enqueuing scripts and styles specific to this view
569
-     *
570
-     * @return void
571
-     */
572
-    public function load_scripts_styles_edit()
573
-    {
574
-        //styles
575
-        wp_enqueue_style('espresso-ui-theme');
576
-        wp_register_style(
577
-            'event-editor-css',
578
-            EVENTS_ASSETS_URL . 'event-editor.css',
579
-            array('ee-admin-css'),
580
-            EVENT_ESPRESSO_VERSION
581
-        );
582
-        wp_enqueue_style('event-editor-css');
583
-        //scripts
584
-        wp_register_script(
585
-            'event-datetime-metabox',
586
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
587
-            array('event_editor_js', 'ee-datepicker'),
588
-            EVENT_ESPRESSO_VERSION
589
-        );
590
-        wp_enqueue_script('event-datetime-metabox');
591
-    }
592
-
593
-
594
-
595
-    public function load_scripts_styles_add_category()
596
-    {
597
-        $this->load_scripts_styles_edit_category();
598
-    }
599
-
600
-
601
-
602
-    public function load_scripts_styles_edit_category()
603
-    {
604
-    }
605
-
606
-
607
-
608
-    protected function _set_list_table_views_category_list()
609
-    {
610
-        $this->_views = array(
611
-            'all' => array(
612
-                'slug'        => 'all',
613
-                'label'       => esc_html__('All', 'event_espresso'),
614
-                'count'       => 0,
615
-                'bulk_action' => array(
616
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
617
-                ),
618
-            ),
619
-        );
620
-    }
621
-
622
-
623
-
624
-    public function admin_init()
625
-    {
626
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
627
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
628
-            'event_espresso'
629
-        );
630
-    }
631
-
632
-
633
-
634
-    //nothing needed for events with these methods.
635
-    public function admin_notices()
636
-    {
637
-    }
638
-
639
-
640
-
641
-    public function admin_footer_scripts()
642
-    {
643
-    }
644
-
645
-
646
-
647
-    /**
648
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
649
-     * warning (via EE_Error::add_error());
650
-     *
651
-     * @param  EE_Event $event Event object
652
-     * @access public
653
-     * @return void
654
-     */
655
-    public function verify_event_edit($event = null)
656
-    {
657
-        // no event?
658
-        if (empty($event)) {
659
-            // set event
660
-            $event = $this->_cpt_model_obj;
661
-        }
662
-        // STILL no event?
663
-        if (empty ($event)) {
664
-            return;
665
-        }
666
-        $orig_status = $event->status();
667
-        // first check if event is active.
668
-        if (
669
-            $orig_status === EEM_Event::cancelled
670
-            || $orig_status === EEM_Event::postponed
671
-            || $event->is_expired()
672
-            || $event->is_inactive()
673
-        ) {
674
-            return;
675
-        }
676
-        //made it here so it IS active... next check that any of the tickets are sold.
677
-        if ($event->is_sold_out(true)) {
678
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
679
-                EE_Error::add_attention(
680
-                    sprintf(
681
-                        esc_html__(
682
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
683
-                            'event_espresso'
684
-                        ),
685
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
686
-                    )
687
-                );
688
-            }
689
-            return;
690
-        } else if ($orig_status === EEM_Event::sold_out) {
691
-            EE_Error::add_attention(
692
-                sprintf(
693
-                    esc_html__(
694
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
695
-                        'event_espresso'
696
-                    ),
697
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
698
-                )
699
-            );
700
-        }
701
-        //now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
702
-        if ( ! $event->tickets_on_sale()) {
703
-            return;
704
-        }
705
-        //made it here so show warning
706
-        $this->_edit_event_warning();
707
-    }
708
-
709
-
710
-
711
-    /**
712
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
713
-     * When needed, hook this into a EE_Error::add_error() notice.
714
-     *
715
-     * @access protected
716
-     * @return void
717
-     */
718
-    protected function _edit_event_warning()
719
-    {
720
-        // we don't want to add warnings during these requests
721
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
722
-            return;
723
-        }
724
-        EE_Error::add_attention(
725
-            esc_html__(
726
-                'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
727
-                'event_espresso'
728
-            )
729
-        );
730
-    }
731
-
732
-
733
-
734
-    /**
735
-     * When a user is creating a new event, notify them if they haven't set their timezone.
736
-     * Otherwise, do the normal logic
737
-     *
738
-     * @return string
739
-     * @throws \EE_Error
740
-     */
741
-    protected function _create_new_cpt_item()
742
-    {
743
-        $gmt_offset = get_option('gmt_offset');
744
-        //only nag them about setting their timezone if it's their first event, and they haven't already done it
745
-        if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) {
746
-            EE_Error::add_attention(
747
-                sprintf(
748
-                    __(
749
-                        'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
750
-                        'event_espresso'
751
-                    ),
752
-                    '<a href="' . admin_url('options-general.php') . '">',
753
-                    '</a>'
754
-                ),
755
-                __FILE__,
756
-                __FUNCTION__,
757
-                __LINE__
758
-            );
759
-        }
760
-        return parent::_create_new_cpt_item();
761
-    }
762
-
763
-
764
-
765
-    protected function _set_list_table_views_default()
766
-    {
767
-        $this->_views = array(
768
-            'all'   => array(
769
-                'slug'        => 'all',
770
-                'label'       => esc_html__('View All Events', 'event_espresso'),
771
-                'count'       => 0,
772
-                'bulk_action' => array(
773
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
774
-                ),
775
-            ),
776
-            'draft' => array(
777
-                'slug'        => 'draft',
778
-                'label'       => esc_html__('Draft', 'event_espresso'),
779
-                'count'       => 0,
780
-                'bulk_action' => array(
781
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
782
-                ),
783
-            ),
784
-        );
785
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
786
-            $this->_views['trash'] = array(
787
-                'slug'        => 'trash',
788
-                'label'       => esc_html__('Trash', 'event_espresso'),
789
-                'count'       => 0,
790
-                'bulk_action' => array(
791
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
792
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
793
-                ),
794
-            );
795
-        }
796
-    }
797
-
798
-
799
-
800
-    /**
801
-     * @return array
802
-     */
803
-    protected function _event_legend_items()
804
-    {
805
-        $items = array(
806
-            'view_details'   => array(
807
-                'class' => 'dashicons dashicons-search',
808
-                'desc'  => esc_html__('View Event', 'event_espresso'),
809
-            ),
810
-            'edit_event'     => array(
811
-                'class' => 'ee-icon ee-icon-calendar-edit',
812
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
813
-            ),
814
-            'view_attendees' => array(
815
-                'class' => 'dashicons dashicons-groups',
816
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
817
-            ),
818
-        );
819
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
820
-        $statuses = array(
821
-            'sold_out_status'  => array(
822
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
823
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
824
-            ),
825
-            'active_status'    => array(
826
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
827
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
828
-            ),
829
-            'upcoming_status'  => array(
830
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
831
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
832
-            ),
833
-            'postponed_status' => array(
834
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
835
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
836
-            ),
837
-            'cancelled_status' => array(
838
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
839
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
840
-            ),
841
-            'expired_status'   => array(
842
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
843
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
844
-            ),
845
-            'inactive_status'  => array(
846
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
847
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
848
-            ),
849
-        );
850
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
851
-        return array_merge($items, $statuses);
852
-    }
853
-
854
-
855
-
856
-    /**
857
-     * _event_model
858
-     *
859
-     * @return EEM_Event
860
-     */
861
-    private function _event_model()
862
-    {
863
-        if ( ! $this->_event_model instanceof EEM_Event) {
864
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
865
-        }
866
-        return $this->_event_model;
867
-    }
868
-
869
-
870
-
871
-    /**
872
-     * Adds extra buttons to the WP CPT permalink field row.
873
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
874
-     *
875
-     * @param  string $return    the current html
876
-     * @param  int    $id        the post id for the page
877
-     * @param  string $new_title What the title is
878
-     * @param  string $new_slug  what the slug is
879
-     * @return string            The new html string for the permalink area
880
-     */
881
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
882
-    {
883
-        //make sure this is only when editing
884
-        if ( ! empty($id)) {
885
-            $post = get_post($id);
886
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
887
-                       . esc_html__('Shortcode', 'event_espresso')
888
-                       . '</a> ';
889
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
890
-                       . $post->ID
891
-                       . ']">';
892
-        }
893
-        return $return;
894
-    }
895
-
896
-
897
-
898
-    /**
899
-     * _events_overview_list_table
900
-     * This contains the logic for showing the events_overview list
901
-     *
902
-     * @access protected
903
-     * @return void
904
-     */
905
-    protected function _events_overview_list_table()
906
-    {
907
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
908
-        $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
909
-            get_post_type_archive_link('espresso_events'),
910
-            esc_html__("View Event Archive Page", "event_espresso"),
911
-            'button'
912
-        );
913
-        $this->_template_args['after_list_table'] .= $this->_display_legend($this->_event_legend_items());
914
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
915
-                'create_new',
916
-                'add',
917
-                array(),
918
-                'add-new-h2'
919
-            );
920
-        $this->display_admin_list_table_page_with_no_sidebar();
921
-    }
922
-
923
-
924
-
925
-    /**
926
-     * this allows for extra misc actions in the default WP publish box
927
-     *
928
-     * @return void
929
-     */
930
-    public function extra_misc_actions_publish_box()
931
-    {
932
-        $this->_generate_publish_box_extra_content();
933
-    }
934
-
935
-
936
-
937
-    /**
938
-     * @param string $post_id
939
-     * @param object $post
940
-     */
941
-    protected function _insert_update_cpt_item($post_id, $post)
942
-    {
943
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
944
-            //get out we're not processing an event save.
945
-            return;
946
-        }
947
-        $event_values = array(
948
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
949
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
950
-            'EVT_additional_limit'            => min(
951
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
952
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
953
-            ),
954
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
955
-                ? $this->_req_data['EVT_default_registration_status']
956
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
957
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
958
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
959
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
960
-                ? $this->_req_data['timezone_string'] : null,
961
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
962
-                ? $this->_req_data['externalURL'] : null,
963
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
964
-                ? $this->_req_data['event_phone'] : null,
965
-        );
966
-        //update event
967
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
968
-        //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
969
-        $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
970
-        $event = $this->_event_model()->get_one(array($get_one_where));
971
-        //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
972
-        $event_update_callbacks = apply_filters(
973
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
974
-            array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
975
-        );
976
-        $att_success = true;
977
-        foreach ($event_update_callbacks as $e_callback) {
978
-            $_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
979
-            $att_success = ! $att_success ? $att_success
980
-                : $_succ; //if ANY of these updates fail then we want the appropriate global error message
981
-        }
982
-        //any errors?
983
-        if ($success && false === $att_success) {
984
-            EE_Error::add_error(
985
-                esc_html__(
986
-                    'Event Details saved successfully but something went wrong with saving attachments.',
987
-                    'event_espresso'
988
-                ),
989
-                __FILE__,
990
-                __FUNCTION__,
991
-                __LINE__
992
-            );
993
-        } else if ($success === false) {
994
-            EE_Error::add_error(
995
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
996
-                __FILE__,
997
-                __FUNCTION__,
998
-                __LINE__
999
-            );
1000
-        }
1001
-    }
1002
-
1003
-
1004
-
1005
-    /**
1006
-     * @see parent::restore_item()
1007
-     * @param int $post_id
1008
-     * @param int $revision_id
1009
-     */
1010
-    protected function _restore_cpt_item($post_id, $revision_id)
1011
-    {
1012
-        //copy existing event meta to new post
1013
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1014
-        if ($post_evt instanceof EE_Event) {
1015
-            //meta revision restore
1016
-            $post_evt->restore_revision($revision_id);
1017
-            //related objs restore
1018
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1019
-        }
1020
-    }
1021
-
1022
-
1023
-
1024
-    /**
1025
-     * Attach the venue to the Event
1026
-     *
1027
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1028
-     * @param  array     $data   The request data from the form
1029
-     * @return bool           Success or fail.
1030
-     */
1031
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1032
-    {
1033
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1034
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1035
-        $rows_affected = null;
1036
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1037
-        // very important.  If we don't have a venue name...
1038
-        // then we'll get out because not necessary to create empty venue
1039
-        if (empty($data['venue_title'])) {
1040
-            return false;
1041
-        }
1042
-        $venue_array = array(
1043
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1044
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1045
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1046
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1047
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1048
-                : null,
1049
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1050
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1051
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1052
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1053
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1054
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1055
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1056
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1057
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1058
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1059
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1060
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1061
-            'status'              => 'publish',
1062
-        );
1063
-        //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1064
-        if ( ! empty($venue_id)) {
1065
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1066
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1067
-            //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1068
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1069
-            return $rows_affected > 0 ? true : false;
1070
-        } else {
1071
-            //we insert the venue
1072
-            $venue_id = $venue_model->insert($venue_array);
1073
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1074
-            return ! empty($venue_id) ? true : false;
1075
-        }
1076
-        //when we have the ancestor come in it's already been handled by the revision save.
1077
-    }
1078
-
1079
-
1080
-
1081
-    /**
1082
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1083
-     *
1084
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1085
-     * @param  array    $data   The request data from the form
1086
-     * @return array
1087
-     */
1088
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1089
-    {
1090
-        $success = true;
1091
-        $saved_dtt = null;
1092
-        $saved_tickets = array();
1093
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1094
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1095
-            //trim all values to ensure any excess whitespace is removed.
1096
-            $dtt = array_map('trim', $dtt);
1097
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1098
-                : $dtt['DTT_EVT_start'];
1099
-            $datetime_values = array(
1100
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1101
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1102
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1103
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1104
-                'DTT_order'     => $row,
1105
-            );
1106
-            //if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1107
-            if ( ! empty($dtt['DTT_ID'])) {
1108
-                $DTM = EE_Registry::instance()
1109
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1110
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1111
-                $DTM->set_date_format($incoming_date_formats[0]);
1112
-                $DTM->set_time_format($incoming_date_formats[1]);
1113
-                foreach ($datetime_values as $field => $value) {
1114
-                    $DTM->set($field, $value);
1115
-                }
1116
-                //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1117
-                $saved_dtts[$DTM->ID()] = $DTM;
1118
-            } else {
1119
-                $DTM = EE_Registry::instance()->load_class(
1120
-                    'Datetime',
1121
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1122
-                    false,
1123
-                    false
1124
-                );
1125
-                foreach ($datetime_values as $field => $value) {
1126
-                    $DTM->set($field, $value);
1127
-                }
1128
-            }
1129
-            $DTM->save();
1130
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1131
-            //load DTT helper
1132
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1133
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1134
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1135
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1136
-                $DTT->save();
1137
-            }
1138
-            //now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1139
-            $saved_dtt = $DTT;
1140
-            $success = ! $success ? $success : $DTT;
1141
-            //if ANY of these updates fail then we want the appropriate global error message.
1142
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1143
-        }
1144
-        //no dtts get deleted so we don't do any of that logic here.
1145
-        //update tickets next
1146
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1147
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1148
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1149
-            $update_prices = false;
1150
-            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1151
-                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1152
-            // trim inputs to ensure any excess whitespace is removed.
1153
-            $tkt = array_map('trim', $tkt);
1154
-            if (empty($tkt['TKT_start_date'])) {
1155
-                //let's use now in the set timezone.
1156
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1157
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1158
-            }
1159
-            if (empty($tkt['TKT_end_date'])) {
1160
-                //use the start date of the first datetime
1161
-                $dtt = $evtobj->first_datetime();
1162
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1163
-                    $incoming_date_formats[0],
1164
-                    $incoming_date_formats[1]
1165
-                );
1166
-            }
1167
-            $TKT_values = array(
1168
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1169
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1170
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1171
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1172
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1173
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1174
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1175
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1176
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1177
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1178
-                'TKT_row'         => $row,
1179
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1180
-                'TKT_price'       => $ticket_price,
1181
-            );
1182
-            //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1183
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1184
-                $TKT_values['TKT_ID'] = 0;
1185
-                $TKT_values['TKT_is_default'] = 0;
1186
-                $TKT_values['TKT_price'] = $ticket_price;
1187
-                $update_prices = true;
1188
-            }
1189
-            //if we have a TKT_ID then we need to get that existing TKT_obj and update it
1190
-            //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1191
-            //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1192
-            if ( ! empty($tkt['TKT_ID'])) {
1193
-                $TKT = EE_Registry::instance()
1194
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1195
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1196
-                if ($TKT instanceof EE_Ticket) {
1197
-                    $ticket_sold = $TKT->count_related(
1198
-                        'Registration',
1199
-                        array(
1200
-                            array(
1201
-                                'STS_ID' => array(
1202
-                                    'NOT IN',
1203
-                                    array(EEM_Registration::status_id_incomplete),
1204
-                                ),
1205
-                            ),
1206
-                        )
1207
-                    ) > 0 ? true : false;
1208
-                    //let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1209
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1210
-                                      && ! $TKT->get(
1211
-                        'TKT_deleted'
1212
-                    ) ? true : false;
1213
-                    $TKT->set_date_format($incoming_date_formats[0]);
1214
-                    $TKT->set_time_format($incoming_date_formats[1]);
1215
-                    //set new values
1216
-                    foreach ($TKT_values as $field => $value) {
1217
-                        if ($field == 'TKT_qty') {
1218
-                            $TKT->set_qty($value);
1219
-                        } else {
1220
-                            $TKT->set($field, $value);
1221
-                        }
1222
-                    }
1223
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1224
-                    if ($create_new_TKT) {
1225
-                        //archive the old ticket first
1226
-                        $TKT->set('TKT_deleted', 1);
1227
-                        $TKT->save();
1228
-                        //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1229
-                        $saved_tickets[$TKT->ID()] = $TKT;
1230
-                        //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1231
-                        $TKT = clone $TKT;
1232
-                        $TKT->set('TKT_ID', 0);
1233
-                        $TKT->set('TKT_deleted', 0);
1234
-                        $TKT->set('TKT_price', $ticket_price);
1235
-                        $TKT->set('TKT_sold', 0);
1236
-                        //now we need to make sure that $new prices are created as well and attached to new ticket.
1237
-                        $update_prices = true;
1238
-                    }
1239
-                    //make sure price is set if it hasn't been already
1240
-                    $TKT->set('TKT_price', $ticket_price);
1241
-                }
1242
-            } else {
1243
-                //no TKT_id so a new TKT
1244
-                $TKT_values['TKT_price'] = $ticket_price;
1245
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1246
-                if ($TKT instanceof EE_Ticket) {
1247
-                    //need to reset values to properly account for the date formats
1248
-                    $TKT->set_date_format($incoming_date_formats[0]);
1249
-                    $TKT->set_time_format($incoming_date_formats[1]);
1250
-                    $TKT->set_timezone($evtobj->get_timezone());
1251
-                    //set new values
1252
-                    foreach ($TKT_values as $field => $value) {
1253
-                        if ($field == 'TKT_qty') {
1254
-                            $TKT->set_qty($value);
1255
-                        } else {
1256
-                            $TKT->set($field, $value);
1257
-                        }
1258
-                    }
1259
-                    $update_prices = true;
1260
-                }
1261
-            }
1262
-            // cap ticket qty by datetime reg limits
1263
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1264
-            //update ticket.
1265
-            $TKT->save();
1266
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1267
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1268
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1269
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1270
-                $TKT->save();
1271
-            }
1272
-            //initially let's add the ticket to the dtt
1273
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1274
-            $saved_tickets[$TKT->ID()] = $TKT;
1275
-            //add prices to ticket
1276
-            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1277
-        }
1278
-        //however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1279
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1280
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1281
-        foreach ($tickets_removed as $id) {
1282
-            $id = absint($id);
1283
-            //get the ticket for this id
1284
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1285
-            //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1286
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1287
-            foreach ($dtts as $dtt) {
1288
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1289
-            }
1290
-            //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1291
-            $tkt_to_remove->delete_related_permanently('Price');
1292
-            //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1293
-            $tkt_to_remove->delete_permanently();
1294
-        }
1295
-        return array($saved_dtt, $saved_tickets);
1296
-    }
1297
-
1298
-
1299
-
1300
-    /**
1301
-     * This attaches a list of given prices to a ticket.
1302
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1303
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1304
-     * price info and prices are automatically "archived" via the ticket.
1305
-     *
1306
-     * @access  private
1307
-     * @param array     $prices     Array of prices from the form.
1308
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1309
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1310
-     * @return  void
1311
-     */
1312
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1313
-    {
1314
-        foreach ($prices as $row => $prc) {
1315
-            $PRC_values = array(
1316
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1317
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1318
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1319
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1320
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1321
-                'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1322
-                'PRC_order'      => $row,
1323
-            );
1324
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1325
-                $PRC_values['PRC_ID'] = 0;
1326
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1327
-            } else {
1328
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1329
-                //update this price with new values
1330
-                foreach ($PRC_values as $field => $newprc) {
1331
-                    $PRC->set($field, $newprc);
1332
-                }
1333
-                $PRC->save();
1334
-            }
1335
-            $ticket->_add_relation_to($PRC, 'Price');
1336
-        }
1337
-    }
1338
-
1339
-
1340
-
1341
-    /**
1342
-     * Add in our autosave ajax handlers
1343
-     *
1344
-     * @return void
1345
-     */
1346
-    protected function _ee_autosave_create_new()
1347
-    {
1348
-        // $this->_ee_autosave_edit();
1349
-    }
1350
-
1351
-
1352
-
1353
-    protected function _ee_autosave_edit()
1354
-    {
1355
-        return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1356
-    }
1357
-
1358
-
1359
-
1360
-    /**
1361
-     *    _generate_publish_box_extra_content
1362
-     *
1363
-     * @access private
1364
-     * @return void
1365
-     */
1366
-    private function _generate_publish_box_extra_content()
1367
-    {
1368
-        //load formatter helper
1369
-        //args for getting related registrations
1370
-        $approved_query_args = array(
1371
-            array(
1372
-                'REG_deleted' => 0,
1373
-                'STS_ID'      => EEM_Registration::status_id_approved,
1374
-            ),
1375
-        );
1376
-        $not_approved_query_args = array(
1377
-            array(
1378
-                'REG_deleted' => 0,
1379
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1380
-            ),
1381
-        );
1382
-        $pending_payment_query_args = array(
1383
-            array(
1384
-                'REG_deleted' => 0,
1385
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1386
-            ),
1387
-        );
1388
-        // publish box
1389
-        $publish_box_extra_args = array(
1390
-            'view_approved_reg_url'        => add_query_arg(
1391
-                array(
1392
-                    'action'      => 'default',
1393
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1394
-                    '_reg_status' => EEM_Registration::status_id_approved,
1395
-                ),
1396
-                REG_ADMIN_URL
1397
-            ),
1398
-            'view_not_approved_reg_url'    => add_query_arg(
1399
-                array(
1400
-                    'action'      => 'default',
1401
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1402
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1403
-                ),
1404
-                REG_ADMIN_URL
1405
-            ),
1406
-            'view_pending_payment_reg_url' => add_query_arg(
1407
-                array(
1408
-                    'action'      => 'default',
1409
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1410
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1411
-                ),
1412
-                REG_ADMIN_URL
1413
-            ),
1414
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1415
-                'Registration',
1416
-                $approved_query_args
1417
-            ),
1418
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1419
-                'Registration',
1420
-                $not_approved_query_args
1421
-            ),
1422
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1423
-                'Registration',
1424
-                $pending_payment_query_args
1425
-            ),
1426
-            'misc_pub_section_class'       => apply_filters(
1427
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1428
-                'misc-pub-section'
1429
-            ),
1430
-            //'email_attendees_url' => add_query_arg(
1431
-            //	array(
1432
-            //		'event_admin_reports' => 'event_newsletter',
1433
-            //		'event_id' => $this->_cpt_model_obj->id
1434
-            //	),
1435
-            //	'admin.php?page=espresso_registrations'
1436
-            //),
1437
-        );
1438
-        ob_start();
1439
-        do_action(
1440
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1441
-            $this->_cpt_model_obj
1442
-        );
1443
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1444
-        // load template
1445
-        EEH_Template::display_template(
1446
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1447
-            $publish_box_extra_args
1448
-        );
1449
-    }
1450
-
1451
-
1452
-
1453
-    /**
1454
-     * This just returns whatever is set as the _event object property
1455
-     * //todo this will become obsolete once the models are in place
1456
-     *
1457
-     * @return object
1458
-     */
1459
-    public function get_event_object()
1460
-    {
1461
-        return $this->_cpt_model_obj;
1462
-    }
1463
-
1464
-
1465
-
1466
-
1467
-    /** METABOXES * */
1468
-    /**
1469
-     * _register_event_editor_meta_boxes
1470
-     * add all metaboxes related to the event_editor
1471
-     *
1472
-     * @return void
1473
-     */
1474
-    protected function _register_event_editor_meta_boxes()
1475
-    {
1476
-        $this->verify_cpt_object();
1477
-        add_meta_box(
1478
-            'espresso_event_editor_tickets',
1479
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1480
-            array($this, 'ticket_metabox'),
1481
-            $this->page_slug,
1482
-            'normal',
1483
-            'high'
1484
-        );
1485
-        add_meta_box(
1486
-            'espresso_event_editor_event_options',
1487
-            esc_html__('Event Registration Options', 'event_espresso'),
1488
-            array($this, 'registration_options_meta_box'),
1489
-            $this->page_slug,
1490
-            'side',
1491
-            'default'
1492
-        );
1493
-        // NOTE: if you're looking for other metaboxes in here,
1494
-        // where a metabox has a related management page in the admin
1495
-        // you will find it setup in the related management page's "_Hooks" file.
1496
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1497
-    }
1498
-
1499
-
1500
-
1501
-    public function ticket_metabox()
1502
-    {
1503
-        $existing_datetime_ids = $existing_ticket_ids = array();
1504
-        //defaults for template args
1505
-        $template_args = array(
1506
-            'existing_datetime_ids'    => '',
1507
-            'event_datetime_help_link' => '',
1508
-            'ticket_options_help_link' => '',
1509
-            'time'                     => null,
1510
-            'ticket_rows'              => '',
1511
-            'existing_ticket_ids'      => '',
1512
-            'total_ticket_rows'        => 1,
1513
-            'ticket_js_structure'      => '',
1514
-            'trash_icon'               => 'ee-lock-icon',
1515
-            'disabled'                 => '',
1516
-        );
1517
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1518
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1519
-        /**
1520
-         * 1. Start with retrieving Datetimes
1521
-         * 2. Fore each datetime get related tickets
1522
-         * 3. For each ticket get related prices
1523
-         */
1524
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1525
-        /** @type EE_Datetime $first_datetime */
1526
-        $first_datetime = reset($times);
1527
-        //do we get related tickets?
1528
-        if ($first_datetime instanceof EE_Datetime
1529
-            && $first_datetime->ID() !== 0
1530
-        ) {
1531
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1532
-            $template_args['time'] = $first_datetime;
1533
-            $related_tickets = $first_datetime->tickets(
1534
-                array(
1535
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1536
-                    'default_where_conditions' => 'none',
1537
-                )
1538
-            );
1539
-            if ( ! empty($related_tickets)) {
1540
-                $template_args['total_ticket_rows'] = count($related_tickets);
1541
-                $row = 0;
1542
-                foreach ($related_tickets as $ticket) {
1543
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1544
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1545
-                    $row++;
1546
-                }
1547
-            } else {
1548
-                $template_args['total_ticket_rows'] = 1;
1549
-                /** @type EE_Ticket $ticket */
1550
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1551
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1552
-            }
1553
-        } else {
1554
-            $template_args['time'] = $times[0];
1555
-            /** @type EE_Ticket $ticket */
1556
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1557
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1558
-            // NOTE: we're just sending the first default row
1559
-            // (decaf can't manage default tickets so this should be sufficient);
1560
-        }
1561
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1562
-            'event_editor_event_datetimes_help_tab'
1563
-        );
1564
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1565
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1566
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1567
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1568
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1569
-            true
1570
-        );
1571
-        $template = apply_filters(
1572
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1573
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1574
-        );
1575
-        EEH_Template::display_template($template, $template_args);
1576
-    }
1577
-
1578
-
1579
-
1580
-    /**
1581
-     * Setup an individual ticket form for the decaf event editor page
1582
-     *
1583
-     * @access private
1584
-     * @param  EE_Ticket $ticket   the ticket object
1585
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1586
-     * @param int        $row
1587
-     * @return string generated html for the ticket row.
1588
-     */
1589
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1590
-    {
1591
-        $template_args = array(
1592
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1593
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1594
-                : '',
1595
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1596
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1597
-            'TKT_name'            => $ticket->get('TKT_name'),
1598
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1599
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1600
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1601
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1602
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1603
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1604
-            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1605
-                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1606
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1607
-            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1608
-                : ' disabled=disabled',
1609
-        );
1610
-        $price = $ticket->ID() !== 0
1611
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1612
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1613
-        $price_args = array(
1614
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1615
-            'PRC_amount'            => $price->get('PRC_amount'),
1616
-            'PRT_ID'                => $price->get('PRT_ID'),
1617
-            'PRC_ID'                => $price->get('PRC_ID'),
1618
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1619
-        );
1620
-        //make sure we have default start and end dates if skeleton
1621
-        //handle rows that should NOT be empty
1622
-        if (empty($template_args['TKT_start_date'])) {
1623
-            //if empty then the start date will be now.
1624
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1625
-        }
1626
-        if (empty($template_args['TKT_end_date'])) {
1627
-            //get the earliest datetime (if present);
1628
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1629
-                ? $this->_cpt_model_obj->get_first_related(
1630
-                    'Datetime',
1631
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1632
-                )
1633
-                : null;
1634
-            if ( ! empty($earliest_dtt)) {
1635
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1636
-            } else {
1637
-                $template_args['TKT_end_date'] = date(
1638
-                    'Y-m-d h:i a',
1639
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1640
-                );
1641
-            }
1642
-        }
1643
-        $template_args = array_merge($template_args, $price_args);
1644
-        $template = apply_filters(
1645
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1646
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1647
-            $ticket
1648
-        );
1649
-        return EEH_Template::display_template($template, $template_args, true);
1650
-    }
1651
-
1652
-
1653
-
1654
-    public function registration_options_meta_box()
1655
-    {
1656
-        $yes_no_values = array(
1657
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1658
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1659
-        );
1660
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1661
-            array(
1662
-                EEM_Registration::status_id_cancelled,
1663
-                EEM_Registration::status_id_declined,
1664
-                EEM_Registration::status_id_incomplete,
1665
-            ),
1666
-            true
1667
-        );
1668
-        //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1669
-        $template_args['_event'] = $this->_cpt_model_obj;
1670
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1671
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1672
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1673
-            'default_reg_status',
1674
-            $default_reg_status_values,
1675
-            $this->_cpt_model_obj->default_registration_status()
1676
-        );
1677
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1678
-            'display_desc',
1679
-            $yes_no_values,
1680
-            $this->_cpt_model_obj->display_description()
1681
-        );
1682
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1683
-            'display_ticket_selector',
1684
-            $yes_no_values,
1685
-            $this->_cpt_model_obj->display_ticket_selector(),
1686
-            '',
1687
-            '',
1688
-            false
1689
-        );
1690
-        $template_args['additional_registration_options'] = apply_filters(
1691
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1692
-            '',
1693
-            $template_args,
1694
-            $yes_no_values,
1695
-            $default_reg_status_values
1696
-        );
1697
-        EEH_Template::display_template(
1698
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1699
-            $template_args
1700
-        );
1701
-    }
1702
-
1703
-
1704
-
1705
-    /**
1706
-     * _get_events()
1707
-     * This method simply returns all the events (for the given _view and paging)
1708
-     *
1709
-     * @access public
1710
-     * @param int  $per_page     count of items per page (20 default);
1711
-     * @param int  $current_page what is the current page being viewed.
1712
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1713
-     *                           If FALSE then we return an array of event objects
1714
-     *                           that match the given _view and paging parameters.
1715
-     * @return array an array of event objects.
1716
-     */
1717
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1718
-    {
1719
-        $EEME = $this->_event_model();
1720
-        $offset = ($current_page - 1) * $per_page;
1721
-        $limit = $count ? null : $offset . ',' . $per_page;
1722
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1723
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1724
-        if (isset($this->_req_data['month_range'])) {
1725
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1726
-            $month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : '';
1727
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1728
-        }
1729
-        $where = array();
1730
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1731
-        //determine what post_status our condition will have for the query.
1732
-        switch ($status) {
1733
-            case 'month' :
1734
-            case 'today' :
1735
-            case null :
1736
-            case 'all' :
1737
-                break;
1738
-            case 'draft' :
1739
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1740
-                break;
1741
-            default :
1742
-                $where['status'] = $status;
1743
-        }
1744
-        //categories?
1745
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1746
-            ? $this->_req_data['EVT_CAT'] : null;
1747
-        if ( ! empty ($category)) {
1748
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1749
-            $where['Term_Taxonomy.term_id'] = $category;
1750
-        }
1751
-        //date where conditions
1752
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1753
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1754
-            $DateTime = new DateTime(
1755
-                $year_r . '-' . $month_r . '-01 00:00:00',
1756
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1757
-            );
1758
-            $start = $DateTime->format(implode(' ', $start_formats));
1759
-            $end = $DateTime->setDate($year_r, $month_r, $DateTime
1760
-                ->format('t'))->setTime(23, 59, 59)
1761
-                            ->format(implode(' ', $start_formats));
1762
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1763
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1764
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1765
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1766
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1767
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1768
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1769
-            $now = date('Y-m-01');
1770
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1771
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1772
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1773
-                            ->setTime(23, 59, 59)
1774
-                            ->format(implode(' ', $start_formats));
1775
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1776
-        }
1777
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1778
-            $where['EVT_wp_user'] = get_current_user_id();
1779
-        } else {
1780
-            if ( ! isset($where['status'])) {
1781
-                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1782
-                    $where['OR'] = array(
1783
-                        'status*restrict_private' => array('!=', 'private'),
1784
-                        'AND'                     => array(
1785
-                            'status*inclusive' => array('=', 'private'),
1786
-                            'EVT_wp_user'      => get_current_user_id(),
1787
-                        ),
1788
-                    );
1789
-                }
1790
-            }
1791
-        }
1792
-        if (isset($this->_req_data['EVT_wp_user'])) {
1793
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1794
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1795
-            ) {
1796
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1797
-            }
1798
-        }
1799
-        //search query handling
1800
-        if (isset($this->_req_data['s'])) {
1801
-            $search_string = '%' . $this->_req_data['s'] . '%';
1802
-            $where['OR'] = array(
1803
-                'EVT_name'       => array('LIKE', $search_string),
1804
-                'EVT_desc'       => array('LIKE', $search_string),
1805
-                'EVT_short_desc' => array('LIKE', $search_string),
1806
-            );
1807
-        }
1808
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1809
-        $query_params = apply_filters(
1810
-            'FHEE__Events_Admin_Page__get_events__query_params',
1811
-            array(
1812
-                $where,
1813
-                'limit'    => $limit,
1814
-                'order_by' => $orderby,
1815
-                'order'    => $order,
1816
-                'group_by' => 'EVT_ID',
1817
-            ),
1818
-            $this->_req_data
1819
-        );
1820
-        //let's first check if we have special requests coming in.
1821
-        if (isset($this->_req_data['active_status'])) {
1822
-            switch ($this->_req_data['active_status']) {
1823
-                case 'upcoming' :
1824
-                    return $EEME->get_upcoming_events($query_params, $count);
1825
-                    break;
1826
-                case 'expired' :
1827
-                    return $EEME->get_expired_events($query_params, $count);
1828
-                    break;
1829
-                case 'active' :
1830
-                    return $EEME->get_active_events($query_params, $count);
1831
-                    break;
1832
-                case 'inactive' :
1833
-                    return $EEME->get_inactive_events($query_params, $count);
1834
-                    break;
1835
-            }
1836
-        }
1837
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1838
-        return $events;
1839
-    }
1840
-
1841
-
1842
-
1843
-    /**
1844
-     * handling for WordPress CPT actions (trash, restore, delete)
1845
-     *
1846
-     * @param string $post_id
1847
-     */
1848
-    public function trash_cpt_item($post_id)
1849
-    {
1850
-        $this->_req_data['EVT_ID'] = $post_id;
1851
-        $this->_trash_or_restore_event('trash', false);
1852
-    }
1853
-
1854
-
1855
-
1856
-    /**
1857
-     * @param string $post_id
1858
-     */
1859
-    public function restore_cpt_item($post_id)
1860
-    {
1861
-        $this->_req_data['EVT_ID'] = $post_id;
1862
-        $this->_trash_or_restore_event('draft', false);
1863
-    }
1864
-
1865
-
1866
-
1867
-    /**
1868
-     * @param string $post_id
1869
-     */
1870
-    public function delete_cpt_item($post_id)
1871
-    {
1872
-        $this->_req_data['EVT_ID'] = $post_id;
1873
-        $this->_delete_event(false);
1874
-    }
1875
-
1876
-
1877
-
1878
-    /**
1879
-     * _trash_or_restore_event
1880
-     *
1881
-     * @access protected
1882
-     * @param  string $event_status
1883
-     * @param bool    $redirect_after
1884
-     */
1885
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1886
-    {
1887
-        //determine the event id and set to array.
1888
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1889
-        // loop thru events
1890
-        if ($EVT_ID) {
1891
-            // clean status
1892
-            $event_status = sanitize_key($event_status);
1893
-            // grab status
1894
-            if ( ! empty($event_status)) {
1895
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1896
-            } else {
1897
-                $success = false;
1898
-                $msg = esc_html__(
1899
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1900
-                    'event_espresso'
1901
-                );
1902
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1903
-            }
1904
-        } else {
1905
-            $success = false;
1906
-            $msg = esc_html__(
1907
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1908
-                'event_espresso'
1909
-            );
1910
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1911
-        }
1912
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1913
-        if ($redirect_after) {
1914
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1915
-        }
1916
-    }
1917
-
1918
-
1919
-
1920
-    /**
1921
-     * _trash_or_restore_events
1922
-     *
1923
-     * @access protected
1924
-     * @param  string $event_status
1925
-     * @return void
1926
-     */
1927
-    protected function _trash_or_restore_events($event_status = 'trash')
1928
-    {
1929
-        // clean status
1930
-        $event_status = sanitize_key($event_status);
1931
-        // grab status
1932
-        if ( ! empty($event_status)) {
1933
-            $success = true;
1934
-            //determine the event id and set to array.
1935
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1936
-            // loop thru events
1937
-            foreach ($EVT_IDs as $EVT_ID) {
1938
-                if ($EVT_ID = absint($EVT_ID)) {
1939
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1940
-                    $success = $results !== false ? $success : false;
1941
-                } else {
1942
-                    $msg = sprintf(
1943
-                        esc_html__(
1944
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1945
-                            'event_espresso'
1946
-                        ),
1947
-                        $EVT_ID
1948
-                    );
1949
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1950
-                    $success = false;
1951
-                }
1952
-            }
1953
-        } else {
1954
-            $success = false;
1955
-            $msg = esc_html__(
1956
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1957
-                'event_espresso'
1958
-            );
1959
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1960
-        }
1961
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1962
-        $success = $success ? 2 : false;
1963
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1964
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1965
-    }
1966
-
1967
-
1968
-
1969
-    /**
1970
-     * _trash_or_restore_events
1971
-     *
1972
-     * @access  private
1973
-     * @param  int    $EVT_ID
1974
-     * @param  string $event_status
1975
-     * @return bool
1976
-     */
1977
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
1978
-    {
1979
-        // grab event id
1980
-        if ( ! $EVT_ID) {
1981
-            $msg = esc_html__(
1982
-                'An error occurred. No Event ID or an invalid Event ID was received.',
1983
-                'event_espresso'
1984
-            );
1985
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1986
-            return false;
1987
-        }
1988
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1989
-        // clean status
1990
-        $event_status = sanitize_key($event_status);
1991
-        // grab status
1992
-        if (empty($event_status)) {
1993
-            $msg = esc_html__(
1994
-                'An error occurred. No Event Status or an invalid Event Status was received.',
1995
-                'event_espresso'
1996
-            );
1997
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1998
-            return false;
1999
-        }
2000
-        // was event trashed or restored ?
2001
-        switch ($event_status) {
2002
-            case 'draft' :
2003
-                $action = 'restored from the trash';
2004
-                $hook = 'AHEE_event_restored_from_trash';
2005
-                break;
2006
-            case 'trash' :
2007
-                $action = 'moved to the trash';
2008
-                $hook = 'AHEE_event_moved_to_trash';
2009
-                break;
2010
-            default :
2011
-                $action = 'updated';
2012
-                $hook = false;
2013
-        }
2014
-        //use class to change status
2015
-        $this->_cpt_model_obj->set_status($event_status);
2016
-        $success = $this->_cpt_model_obj->save();
2017
-        if ($success === false) {
2018
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2019
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2020
-            return false;
2021
-        }
2022
-        if ($hook) {
2023
-            do_action($hook);
2024
-        }
2025
-        return true;
2026
-    }
2027
-
2028
-
2029
-
2030
-    /**
2031
-     * _delete_event
2032
-     *
2033
-     * @access protected
2034
-     * @param bool $redirect_after
2035
-     */
2036
-    protected function _delete_event($redirect_after = true)
2037
-    {
2038
-        //determine the event id and set to array.
2039
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2040
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2041
-        // loop thru events
2042
-        if ($EVT_ID) {
2043
-            $success = $this->_permanently_delete_event($EVT_ID);
2044
-            // get list of events with no prices
2045
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2046
-            // remove this event from the list of events with no prices
2047
-            if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2048
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2049
-            }
2050
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2051
-        } else {
2052
-            $success = false;
2053
-            $msg = esc_html__(
2054
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2055
-                'event_espresso'
2056
-            );
2057
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2058
-        }
2059
-        if ($redirect_after) {
2060
-            $this->_redirect_after_action(
2061
-                $success,
2062
-                'Event',
2063
-                'deleted',
2064
-                array('action' => 'default', 'status' => 'trash')
2065
-            );
2066
-        }
2067
-    }
2068
-
2069
-
2070
-
2071
-    /**
2072
-     * _delete_events
2073
-     *
2074
-     * @access protected
2075
-     * @return void
2076
-     */
2077
-    protected function _delete_events()
2078
-    {
2079
-        $success = true;
2080
-        // get list of events with no prices
2081
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2082
-        //determine the event id and set to array.
2083
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2084
-        // loop thru events
2085
-        foreach ($EVT_IDs as $EVT_ID) {
2086
-            $EVT_ID = absint($EVT_ID);
2087
-            if ($EVT_ID) {
2088
-                $results = $this->_permanently_delete_event($EVT_ID);
2089
-                $success = $results !== false ? $success : false;
2090
-                // remove this event from the list of events with no prices
2091
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2092
-            } else {
2093
-                $success = false;
2094
-                $msg = esc_html__(
2095
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2096
-                    'event_espresso'
2097
-                );
2098
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2099
-            }
2100
-        }
2101
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2102
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2103
-        $success = $success ? 2 : false;
2104
-        $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2105
-    }
2106
-
2107
-
2108
-
2109
-    /**
2110
-     * _permanently_delete_event
2111
-     *
2112
-     * @access  private
2113
-     * @param  int $EVT_ID
2114
-     * @return bool
2115
-     */
2116
-    private function _permanently_delete_event($EVT_ID = 0)
2117
-    {
2118
-        // grab event id
2119
-        if ( ! $EVT_ID) {
2120
-            $msg = esc_html__(
2121
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2122
-                'event_espresso'
2123
-            );
2124
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2125
-            return false;
2126
-        }
2127
-        if (
2128
-            ! $this->_cpt_model_obj instanceof EE_Event
2129
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2130
-        ) {
2131
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2132
-        }
2133
-        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2134
-            return false;
2135
-        }
2136
-        //need to delete related tickets and prices first.
2137
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2138
-        foreach ($datetimes as $datetime) {
2139
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2140
-            $tickets = $datetime->get_many_related('Ticket');
2141
-            foreach ($tickets as $ticket) {
2142
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2143
-                $ticket->delete_related_permanently('Price');
2144
-                $ticket->delete_permanently();
2145
-            }
2146
-            $datetime->delete();
2147
-        }
2148
-        //what about related venues or terms?
2149
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2150
-        foreach ($venues as $venue) {
2151
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2152
-        }
2153
-        //any attached question groups?
2154
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2155
-        if ( ! empty($question_groups)) {
2156
-            foreach ($question_groups as $question_group) {
2157
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2158
-            }
2159
-        }
2160
-        //Message Template Groups
2161
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2162
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2163
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2164
-        foreach ($term_taxonomies as $term_taxonomy) {
2165
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2166
-        }
2167
-        $success = $this->_cpt_model_obj->delete_permanently();
2168
-        // did it all go as planned ?
2169
-        if ($success) {
2170
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2171
-            EE_Error::add_success($msg);
2172
-        } else {
2173
-            $msg = sprintf(
2174
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2175
-                $EVT_ID
2176
-            );
2177
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2178
-            return false;
2179
-        }
2180
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2181
-        return true;
2182
-    }
2183
-
2184
-
2185
-
2186
-    /**
2187
-     * get total number of events
2188
-     *
2189
-     * @access public
2190
-     * @return int
2191
-     */
2192
-    public function total_events()
2193
-    {
2194
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2195
-        return $count;
2196
-    }
2197
-
2198
-
2199
-
2200
-    /**
2201
-     * get total number of draft events
2202
-     *
2203
-     * @access public
2204
-     * @return int
2205
-     */
2206
-    public function total_events_draft()
2207
-    {
2208
-        $where = array(
2209
-            'status' => array('IN', array('draft', 'auto-draft')),
2210
-        );
2211
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2212
-        return $count;
2213
-    }
2214
-
2215
-
2216
-
2217
-    /**
2218
-     * get total number of trashed events
2219
-     *
2220
-     * @access public
2221
-     * @return int
2222
-     */
2223
-    public function total_trashed_events()
2224
-    {
2225
-        $where = array(
2226
-            'status' => 'trash',
2227
-        );
2228
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2229
-        return $count;
2230
-    }
2231
-
2232
-
2233
-
2234
-    /**
2235
-     *    _default_event_settings
2236
-     *    This generates the Default Settings Tab
2237
-     *
2238
-     * @return void
2239
-     */
2240
-    protected function _default_event_settings()
2241
-    {
2242
-        $this->_template_args['values'] = $this->_yes_no_values;
2243
-        $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array(
2244
-        // exclude array
2245
-            array(
2246
-                EEM_Registration::status_id_cancelled,
2247
-                EEM_Registration::status_id_declined,
2248
-                EEM_Registration::status_id_incomplete,
2249
-                EEM_Registration::status_id_wait_list,
2250
-            ),
2251
-            // translated
2252
-            true
2253
-        );
2254
-        $this->_template_args['default_reg_status'] = isset(
2255
-                                                          EE_Registry::instance()->CFG->registration->default_STS_ID
2256
-                                                      )
2257
-                                                      && array_key_exists(
2258
-                                                          EE_Registry::instance()->CFG->registration->default_STS_ID,
2259
-                                                          $this->_template_args['reg_status_array']
2260
-                                                      )
2261
-            ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID)
2262
-            : EEM_Registration::status_id_pending_payment;
2263
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2264
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2265
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2266
-            EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2267
-            $this->_template_args,
2268
-            true
2269
-        );
2270
-        $this->display_admin_page_with_sidebar();
2271
-    }
2272
-
2273
-
2274
-
2275
-    /**
2276
-     * _update_default_event_settings
2277
-     *
2278
-     * @access protected
2279
-     * @return void
2280
-     */
2281
-    protected function _update_default_event_settings()
2282
-    {
2283
-        EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status'])
2284
-            ? sanitize_text_field($this->_req_data['default_reg_status'])
2285
-            : EEM_Registration::status_id_pending_payment;
2286
-        $what = 'Default Event Settings';
2287
-        $success = $this->_update_espresso_configuration(
2288
-            $what,
2289
-            EE_Config::instance(),
2290
-            __FILE__,
2291
-            __FUNCTION__,
2292
-            __LINE__
2293
-        );
2294
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings'));
2295
-    }
2296
-
2297
-
2298
-
2299
-    /*************        Templates        *************/
2300
-    protected function _template_settings()
2301
-    {
2302
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2303
-        $this->_template_args['preview_img'] = '<img src="'
2304
-                                               . EVENTS_ASSETS_URL
2305
-                                               . DS
2306
-                                               . 'images'
2307
-                                               . DS
2308
-                                               . 'caffeinated_template_features.jpg" alt="'
2309
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2310
-                                               . '" />';
2311
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2312
-                'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2313
-                'event_espresso'
2314
-            ) . '</strong>';
2315
-        $this->display_admin_caf_preview_page('template_settings_tab');
2316
-    }
2317
-
2318
-
2319
-    /** Event Category Stuff **/
2320
-    /**
2321
-     * set the _category property with the category object for the loaded page.
2322
-     *
2323
-     * @access private
2324
-     * @return void
2325
-     */
2326
-    private function _set_category_object()
2327
-    {
2328
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2329
-            return;
2330
-        } //already have the category object so get out.
2331
-        //set default category object
2332
-        $this->_set_empty_category_object();
2333
-        //only set if we've got an id
2334
-        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2335
-            return;
2336
-        }
2337
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2338
-        $term = get_term($category_id, 'espresso_event_categories');
2339
-        if ( ! empty($term)) {
2340
-            $this->_category->category_name = $term->name;
2341
-            $this->_category->category_identifier = $term->slug;
2342
-            $this->_category->category_desc = $term->description;
2343
-            $this->_category->id = $term->term_id;
2344
-            $this->_category->parent = $term->parent;
2345
-        }
2346
-    }
2347
-
2348
-
2349
-
2350
-    private function _set_empty_category_object()
2351
-    {
2352
-        $this->_category = new stdClass();
2353
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2354
-        $this->_category->id = $this->_category->parent = 0;
2355
-    }
2356
-
2357
-
2358
-
2359
-    protected function _category_list_table()
2360
-    {
2361
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2362
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2363
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2364
-                'add_category',
2365
-                'add_category',
2366
-                array(),
2367
-                'add-new-h2'
2368
-            );
2369
-        $this->display_admin_list_table_page_with_sidebar();
2370
-    }
2371
-
2372
-
2373
-
2374
-    /**
2375
-     * @param $view
2376
-     */
2377
-    protected function _category_details($view)
2378
-    {
2379
-        //load formatter helper
2380
-        //load field generator helper
2381
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2382
-        $this->_set_add_edit_form_tags($route);
2383
-        $this->_set_category_object();
2384
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2385
-        $delete_action = 'delete_category';
2386
-        //custom redirect
2387
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2388
-            array('action' => 'category_list'),
2389
-            $this->_admin_base_url
2390
-        );
2391
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2392
-        //take care of contents
2393
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2394
-        $this->display_admin_page_with_sidebar();
2395
-    }
2396
-
2397
-
2398
-
2399
-    /**
2400
-     * @return mixed
2401
-     */
2402
-    protected function _category_details_content()
2403
-    {
2404
-        $editor_args['category_desc'] = array(
2405
-            'type'          => 'wp_editor',
2406
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2407
-            'class'         => 'my_editor_custom',
2408
-            'wpeditor_args' => array('media_buttons' => false),
2409
-        );
2410
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2411
-        $all_terms = get_terms(
2412
-            array('espresso_event_categories'),
2413
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2414
-        );
2415
-        //setup category select for term parents.
2416
-        $category_select_values[] = array(
2417
-            'text' => esc_html__('No Parent', 'event_espresso'),
2418
-            'id'   => 0,
2419
-        );
2420
-        foreach ($all_terms as $term) {
2421
-            $category_select_values[] = array(
2422
-                'text' => $term->name,
2423
-                'id'   => $term->term_id,
2424
-            );
2425
-        }
2426
-        $category_select = EEH_Form_Fields::select_input(
2427
-            'category_parent',
2428
-            $category_select_values,
2429
-            $this->_category->parent
2430
-        );
2431
-        $template_args = array(
2432
-            'category'                 => $this->_category,
2433
-            'category_select'          => $category_select,
2434
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2435
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2436
-            'disable'                  => '',
2437
-            'disabled_message'         => false,
2438
-        );
2439
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2440
-        return EEH_Template::display_template($template, $template_args, true);
2441
-    }
2442
-
2443
-
2444
-
2445
-    protected function _delete_categories()
2446
-    {
2447
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2448
-            : (array)$this->_req_data['category_id'];
2449
-        foreach ($cat_ids as $cat_id) {
2450
-            $this->_delete_category($cat_id);
2451
-        }
2452
-        //doesn't matter what page we're coming from... we're going to the same place after delete.
2453
-        $query_args = array(
2454
-            'action' => 'category_list',
2455
-        );
2456
-        $this->_redirect_after_action(0, '', '', $query_args);
2457
-    }
2458
-
2459
-
2460
-
2461
-    /**
2462
-     * @param $cat_id
2463
-     */
2464
-    protected function _delete_category($cat_id)
2465
-    {
2466
-        $cat_id = absint($cat_id);
2467
-        wp_delete_term($cat_id, 'espresso_event_categories');
2468
-    }
2469
-
2470
-
2471
-
2472
-    /**
2473
-     * @param $new_category
2474
-     */
2475
-    protected function _insert_or_update_category($new_category)
2476
-    {
2477
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2478
-        $success = 0; //we already have a success message so lets not send another.
2479
-        if ($cat_id) {
2480
-            $query_args = array(
2481
-                'action'     => 'edit_category',
2482
-                'EVT_CAT_ID' => $cat_id,
2483
-            );
2484
-        } else {
2485
-            $query_args = array('action' => 'add_category');
2486
-        }
2487
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2488
-    }
2489
-
2490
-
2491
-
2492
-    /**
2493
-     * @param bool $update
2494
-     * @return bool|mixed|string
2495
-     */
2496
-    private function _insert_category($update = false)
2497
-    {
2498
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2499
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2500
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2501
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2502
-        if (empty($category_name)) {
2503
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2504
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2505
-            return false;
2506
-        }
2507
-        $term_args = array(
2508
-            'name'        => $category_name,
2509
-            'description' => $category_desc,
2510
-            'parent'      => $category_parent,
2511
-        );
2512
-        //was the category_identifier input disabled?
2513
-        if (isset($this->_req_data['category_identifier'])) {
2514
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2515
-        }
2516
-        $insert_ids = $update
2517
-            ? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2518
-            : wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2519
-        if ( ! is_array($insert_ids)) {
2520
-            $msg = esc_html__(
2521
-                'An error occurred and the category has not been saved to the database.',
2522
-                'event_espresso'
2523
-            );
2524
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2525
-        } else {
2526
-            $cat_id = $insert_ids['term_id'];
2527
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2528
-            EE_Error::add_success($msg);
2529
-        }
2530
-        return $cat_id;
2531
-    }
2532
-
2533
-
2534
-
2535
-    /**
2536
-     * @param int  $per_page
2537
-     * @param int  $current_page
2538
-     * @param bool $count
2539
-     * @return \EE_Base_Class[]|int
2540
-     */
2541
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2542
-    {
2543
-        //testing term stuff
2544
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2545
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2546
-        $limit = ($current_page - 1) * $per_page;
2547
-        $where = array('taxonomy' => 'espresso_event_categories');
2548
-        if (isset($this->_req_data['s'])) {
2549
-            $sstr = '%' . $this->_req_data['s'] . '%';
2550
-            $where['OR'] = array(
2551
-                'Term.name'   => array('LIKE', $sstr),
2552
-                'description' => array('LIKE', $sstr),
2553
-            );
2554
-        }
2555
-        $query_params = array(
2556
-            $where,
2557
-            'order_by'   => array($orderby => $order),
2558
-            'limit'      => $limit . ',' . $per_page,
2559
-            'force_join' => array('Term'),
2560
-        );
2561
-        $categories = $count
2562
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2563
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2564
-        return $categories;
2565
-    }
2566
-
2567
-
2568
-
2569
-    /* end category stuff */
2570
-    /**************/
384
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
385
+				'require_nonce' => false,
386
+			),
387
+			'default_event_settings' => array(
388
+				'nav'           => array(
389
+					'label' => esc_html__('Default Settings', 'event_espresso'),
390
+					'order' => 40,
391
+				),
392
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
393
+				'labels'        => array(
394
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
395
+				),
396
+				'help_tabs'     => array(
397
+					'default_settings_help_tab'        => array(
398
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
399
+						'filename' => 'events_default_settings',
400
+					),
401
+					'default_settings_status_help_tab' => array(
402
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
403
+						'filename' => 'events_default_settings_status',
404
+					),
405
+				),
406
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
407
+				'require_nonce' => false,
408
+			),
409
+			//template settings
410
+			'template_settings'      => array(
411
+				'nav'           => array(
412
+					'label' => esc_html__('Templates', 'event_espresso'),
413
+					'order' => 30,
414
+				),
415
+				'metaboxes'     => $this->_default_espresso_metaboxes,
416
+				'help_tabs'     => array(
417
+					'general_settings_templates_help_tab' => array(
418
+						'title'    => esc_html__('Templates', 'event_espresso'),
419
+						'filename' => 'general_settings_templates',
420
+					),
421
+				),
422
+				'help_tour'     => array('Templates_Help_Tour'),
423
+				'require_nonce' => false,
424
+			),
425
+			//event category stuff
426
+			'add_category'           => array(
427
+				'nav'           => array(
428
+					'label'      => esc_html__('Add Category', 'event_espresso'),
429
+					'order'      => 15,
430
+					'persistent' => false,
431
+				),
432
+				'help_tabs'     => array(
433
+					'add_category_help_tab' => array(
434
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
435
+						'filename' => 'events_add_category',
436
+					),
437
+				),
438
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
439
+				'metaboxes'     => array('_publish_post_box'),
440
+				'require_nonce' => false,
441
+			),
442
+			'edit_category'          => array(
443
+				'nav'           => array(
444
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
445
+					'order'      => 15,
446
+					'persistent' => false,
447
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
448
+						? add_query_arg(
449
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
450
+							$this->_current_page_view_url
451
+						)
452
+						: $this->_admin_base_url,
453
+				),
454
+				'help_tabs'     => array(
455
+					'edit_category_help_tab' => array(
456
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
457
+						'filename' => 'events_edit_category',
458
+					),
459
+				),
460
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
461
+				'metaboxes'     => array('_publish_post_box'),
462
+				'require_nonce' => false,
463
+			),
464
+			'category_list'          => array(
465
+				'nav'           => array(
466
+					'label' => esc_html__('Categories', 'event_espresso'),
467
+					'order' => 20,
468
+				),
469
+				'list_table'    => 'Event_Categories_Admin_List_Table',
470
+				'help_tabs'     => array(
471
+					'events_categories_help_tab'                       => array(
472
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
473
+						'filename' => 'events_categories',
474
+					),
475
+					'events_categories_table_column_headings_help_tab' => array(
476
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
477
+						'filename' => 'events_categories_table_column_headings',
478
+					),
479
+					'events_categories_view_help_tab'                  => array(
480
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
481
+						'filename' => 'events_categories_views',
482
+					),
483
+					'events_categories_other_help_tab'                 => array(
484
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
485
+						'filename' => 'events_categories_other',
486
+					),
487
+				),
488
+				'help_tour'     => array(
489
+					'Event_Categories_Help_Tour',
490
+				),
491
+				'metaboxes'     => $this->_default_espresso_metaboxes,
492
+				'require_nonce' => false,
493
+			),
494
+		);
495
+	}
496
+
497
+
498
+
499
+	protected function _add_screen_options()
500
+	{
501
+		//todo
502
+	}
503
+
504
+
505
+
506
+	protected function _add_screen_options_default()
507
+	{
508
+		$this->_per_page_screen_option();
509
+	}
510
+
511
+
512
+
513
+	protected function _add_screen_options_category_list()
514
+	{
515
+		$page_title = $this->_admin_page_title;
516
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
517
+		$this->_per_page_screen_option();
518
+		$this->_admin_page_title = $page_title;
519
+	}
520
+
521
+
522
+
523
+	protected function _add_feature_pointers()
524
+	{
525
+		//todo
526
+	}
527
+
528
+
529
+
530
+	public function load_scripts_styles()
531
+	{
532
+		wp_register_style(
533
+			'events-admin-css',
534
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
535
+			array(),
536
+			EVENT_ESPRESSO_VERSION
537
+		);
538
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
539
+		wp_enqueue_style('events-admin-css');
540
+		wp_enqueue_style('ee-cat-admin');
541
+		//todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
542
+		//registers for all views
543
+		//scripts
544
+		wp_register_script(
545
+			'event_editor_js',
546
+			EVENTS_ASSETS_URL . 'event_editor.js',
547
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
548
+			EVENT_ESPRESSO_VERSION,
549
+			true
550
+		);
551
+	}
552
+
553
+
554
+
555
+	/**
556
+	 * enqueuing scripts and styles specific to this view
557
+	 *
558
+	 * @return void
559
+	 */
560
+	public function load_scripts_styles_create_new()
561
+	{
562
+		$this->load_scripts_styles_edit();
563
+	}
564
+
565
+
566
+
567
+	/**
568
+	 * enqueuing scripts and styles specific to this view
569
+	 *
570
+	 * @return void
571
+	 */
572
+	public function load_scripts_styles_edit()
573
+	{
574
+		//styles
575
+		wp_enqueue_style('espresso-ui-theme');
576
+		wp_register_style(
577
+			'event-editor-css',
578
+			EVENTS_ASSETS_URL . 'event-editor.css',
579
+			array('ee-admin-css'),
580
+			EVENT_ESPRESSO_VERSION
581
+		);
582
+		wp_enqueue_style('event-editor-css');
583
+		//scripts
584
+		wp_register_script(
585
+			'event-datetime-metabox',
586
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
587
+			array('event_editor_js', 'ee-datepicker'),
588
+			EVENT_ESPRESSO_VERSION
589
+		);
590
+		wp_enqueue_script('event-datetime-metabox');
591
+	}
592
+
593
+
594
+
595
+	public function load_scripts_styles_add_category()
596
+	{
597
+		$this->load_scripts_styles_edit_category();
598
+	}
599
+
600
+
601
+
602
+	public function load_scripts_styles_edit_category()
603
+	{
604
+	}
605
+
606
+
607
+
608
+	protected function _set_list_table_views_category_list()
609
+	{
610
+		$this->_views = array(
611
+			'all' => array(
612
+				'slug'        => 'all',
613
+				'label'       => esc_html__('All', 'event_espresso'),
614
+				'count'       => 0,
615
+				'bulk_action' => array(
616
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
617
+				),
618
+			),
619
+		);
620
+	}
621
+
622
+
623
+
624
+	public function admin_init()
625
+	{
626
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
627
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
628
+			'event_espresso'
629
+		);
630
+	}
631
+
632
+
633
+
634
+	//nothing needed for events with these methods.
635
+	public function admin_notices()
636
+	{
637
+	}
638
+
639
+
640
+
641
+	public function admin_footer_scripts()
642
+	{
643
+	}
644
+
645
+
646
+
647
+	/**
648
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
649
+	 * warning (via EE_Error::add_error());
650
+	 *
651
+	 * @param  EE_Event $event Event object
652
+	 * @access public
653
+	 * @return void
654
+	 */
655
+	public function verify_event_edit($event = null)
656
+	{
657
+		// no event?
658
+		if (empty($event)) {
659
+			// set event
660
+			$event = $this->_cpt_model_obj;
661
+		}
662
+		// STILL no event?
663
+		if (empty ($event)) {
664
+			return;
665
+		}
666
+		$orig_status = $event->status();
667
+		// first check if event is active.
668
+		if (
669
+			$orig_status === EEM_Event::cancelled
670
+			|| $orig_status === EEM_Event::postponed
671
+			|| $event->is_expired()
672
+			|| $event->is_inactive()
673
+		) {
674
+			return;
675
+		}
676
+		//made it here so it IS active... next check that any of the tickets are sold.
677
+		if ($event->is_sold_out(true)) {
678
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
679
+				EE_Error::add_attention(
680
+					sprintf(
681
+						esc_html__(
682
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
683
+							'event_espresso'
684
+						),
685
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
686
+					)
687
+				);
688
+			}
689
+			return;
690
+		} else if ($orig_status === EEM_Event::sold_out) {
691
+			EE_Error::add_attention(
692
+				sprintf(
693
+					esc_html__(
694
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
695
+						'event_espresso'
696
+					),
697
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
698
+				)
699
+			);
700
+		}
701
+		//now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
702
+		if ( ! $event->tickets_on_sale()) {
703
+			return;
704
+		}
705
+		//made it here so show warning
706
+		$this->_edit_event_warning();
707
+	}
708
+
709
+
710
+
711
+	/**
712
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
713
+	 * When needed, hook this into a EE_Error::add_error() notice.
714
+	 *
715
+	 * @access protected
716
+	 * @return void
717
+	 */
718
+	protected function _edit_event_warning()
719
+	{
720
+		// we don't want to add warnings during these requests
721
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
722
+			return;
723
+		}
724
+		EE_Error::add_attention(
725
+			esc_html__(
726
+				'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
727
+				'event_espresso'
728
+			)
729
+		);
730
+	}
731
+
732
+
733
+
734
+	/**
735
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
736
+	 * Otherwise, do the normal logic
737
+	 *
738
+	 * @return string
739
+	 * @throws \EE_Error
740
+	 */
741
+	protected function _create_new_cpt_item()
742
+	{
743
+		$gmt_offset = get_option('gmt_offset');
744
+		//only nag them about setting their timezone if it's their first event, and they haven't already done it
745
+		if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) {
746
+			EE_Error::add_attention(
747
+				sprintf(
748
+					__(
749
+						'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
750
+						'event_espresso'
751
+					),
752
+					'<a href="' . admin_url('options-general.php') . '">',
753
+					'</a>'
754
+				),
755
+				__FILE__,
756
+				__FUNCTION__,
757
+				__LINE__
758
+			);
759
+		}
760
+		return parent::_create_new_cpt_item();
761
+	}
762
+
763
+
764
+
765
+	protected function _set_list_table_views_default()
766
+	{
767
+		$this->_views = array(
768
+			'all'   => array(
769
+				'slug'        => 'all',
770
+				'label'       => esc_html__('View All Events', 'event_espresso'),
771
+				'count'       => 0,
772
+				'bulk_action' => array(
773
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
774
+				),
775
+			),
776
+			'draft' => array(
777
+				'slug'        => 'draft',
778
+				'label'       => esc_html__('Draft', 'event_espresso'),
779
+				'count'       => 0,
780
+				'bulk_action' => array(
781
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
782
+				),
783
+			),
784
+		);
785
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
786
+			$this->_views['trash'] = array(
787
+				'slug'        => 'trash',
788
+				'label'       => esc_html__('Trash', 'event_espresso'),
789
+				'count'       => 0,
790
+				'bulk_action' => array(
791
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
792
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
793
+				),
794
+			);
795
+		}
796
+	}
797
+
798
+
799
+
800
+	/**
801
+	 * @return array
802
+	 */
803
+	protected function _event_legend_items()
804
+	{
805
+		$items = array(
806
+			'view_details'   => array(
807
+				'class' => 'dashicons dashicons-search',
808
+				'desc'  => esc_html__('View Event', 'event_espresso'),
809
+			),
810
+			'edit_event'     => array(
811
+				'class' => 'ee-icon ee-icon-calendar-edit',
812
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
813
+			),
814
+			'view_attendees' => array(
815
+				'class' => 'dashicons dashicons-groups',
816
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
817
+			),
818
+		);
819
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
820
+		$statuses = array(
821
+			'sold_out_status'  => array(
822
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
823
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
824
+			),
825
+			'active_status'    => array(
826
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
827
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
828
+			),
829
+			'upcoming_status'  => array(
830
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
831
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
832
+			),
833
+			'postponed_status' => array(
834
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
835
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
836
+			),
837
+			'cancelled_status' => array(
838
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
839
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
840
+			),
841
+			'expired_status'   => array(
842
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
843
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
844
+			),
845
+			'inactive_status'  => array(
846
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
847
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
848
+			),
849
+		);
850
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
851
+		return array_merge($items, $statuses);
852
+	}
853
+
854
+
855
+
856
+	/**
857
+	 * _event_model
858
+	 *
859
+	 * @return EEM_Event
860
+	 */
861
+	private function _event_model()
862
+	{
863
+		if ( ! $this->_event_model instanceof EEM_Event) {
864
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
865
+		}
866
+		return $this->_event_model;
867
+	}
868
+
869
+
870
+
871
+	/**
872
+	 * Adds extra buttons to the WP CPT permalink field row.
873
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
874
+	 *
875
+	 * @param  string $return    the current html
876
+	 * @param  int    $id        the post id for the page
877
+	 * @param  string $new_title What the title is
878
+	 * @param  string $new_slug  what the slug is
879
+	 * @return string            The new html string for the permalink area
880
+	 */
881
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
882
+	{
883
+		//make sure this is only when editing
884
+		if ( ! empty($id)) {
885
+			$post = get_post($id);
886
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
887
+					   . esc_html__('Shortcode', 'event_espresso')
888
+					   . '</a> ';
889
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
890
+					   . $post->ID
891
+					   . ']">';
892
+		}
893
+		return $return;
894
+	}
895
+
896
+
897
+
898
+	/**
899
+	 * _events_overview_list_table
900
+	 * This contains the logic for showing the events_overview list
901
+	 *
902
+	 * @access protected
903
+	 * @return void
904
+	 */
905
+	protected function _events_overview_list_table()
906
+	{
907
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
908
+		$this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(
909
+			get_post_type_archive_link('espresso_events'),
910
+			esc_html__("View Event Archive Page", "event_espresso"),
911
+			'button'
912
+		);
913
+		$this->_template_args['after_list_table'] .= $this->_display_legend($this->_event_legend_items());
914
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
915
+				'create_new',
916
+				'add',
917
+				array(),
918
+				'add-new-h2'
919
+			);
920
+		$this->display_admin_list_table_page_with_no_sidebar();
921
+	}
922
+
923
+
924
+
925
+	/**
926
+	 * this allows for extra misc actions in the default WP publish box
927
+	 *
928
+	 * @return void
929
+	 */
930
+	public function extra_misc_actions_publish_box()
931
+	{
932
+		$this->_generate_publish_box_extra_content();
933
+	}
934
+
935
+
936
+
937
+	/**
938
+	 * @param string $post_id
939
+	 * @param object $post
940
+	 */
941
+	protected function _insert_update_cpt_item($post_id, $post)
942
+	{
943
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
944
+			//get out we're not processing an event save.
945
+			return;
946
+		}
947
+		$event_values = array(
948
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
949
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
950
+			'EVT_additional_limit'            => min(
951
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
952
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
953
+			),
954
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
955
+				? $this->_req_data['EVT_default_registration_status']
956
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
957
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
958
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
959
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
960
+				? $this->_req_data['timezone_string'] : null,
961
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
962
+				? $this->_req_data['externalURL'] : null,
963
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
964
+				? $this->_req_data['event_phone'] : null,
965
+		);
966
+		//update event
967
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
968
+		//get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
969
+		$get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
970
+		$event = $this->_event_model()->get_one(array($get_one_where));
971
+		//the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
972
+		$event_update_callbacks = apply_filters(
973
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
974
+			array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
975
+		);
976
+		$att_success = true;
977
+		foreach ($event_update_callbacks as $e_callback) {
978
+			$_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
979
+			$att_success = ! $att_success ? $att_success
980
+				: $_succ; //if ANY of these updates fail then we want the appropriate global error message
981
+		}
982
+		//any errors?
983
+		if ($success && false === $att_success) {
984
+			EE_Error::add_error(
985
+				esc_html__(
986
+					'Event Details saved successfully but something went wrong with saving attachments.',
987
+					'event_espresso'
988
+				),
989
+				__FILE__,
990
+				__FUNCTION__,
991
+				__LINE__
992
+			);
993
+		} else if ($success === false) {
994
+			EE_Error::add_error(
995
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
996
+				__FILE__,
997
+				__FUNCTION__,
998
+				__LINE__
999
+			);
1000
+		}
1001
+	}
1002
+
1003
+
1004
+
1005
+	/**
1006
+	 * @see parent::restore_item()
1007
+	 * @param int $post_id
1008
+	 * @param int $revision_id
1009
+	 */
1010
+	protected function _restore_cpt_item($post_id, $revision_id)
1011
+	{
1012
+		//copy existing event meta to new post
1013
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1014
+		if ($post_evt instanceof EE_Event) {
1015
+			//meta revision restore
1016
+			$post_evt->restore_revision($revision_id);
1017
+			//related objs restore
1018
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1019
+		}
1020
+	}
1021
+
1022
+
1023
+
1024
+	/**
1025
+	 * Attach the venue to the Event
1026
+	 *
1027
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1028
+	 * @param  array     $data   The request data from the form
1029
+	 * @return bool           Success or fail.
1030
+	 */
1031
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1032
+	{
1033
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1034
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1035
+		$rows_affected = null;
1036
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1037
+		// very important.  If we don't have a venue name...
1038
+		// then we'll get out because not necessary to create empty venue
1039
+		if (empty($data['venue_title'])) {
1040
+			return false;
1041
+		}
1042
+		$venue_array = array(
1043
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1044
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1045
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1046
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1047
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1048
+				: null,
1049
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1050
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1051
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1052
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1053
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1054
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1055
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1056
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1057
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1058
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1059
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1060
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1061
+			'status'              => 'publish',
1062
+		);
1063
+		//if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1064
+		if ( ! empty($venue_id)) {
1065
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1066
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1067
+			//we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1068
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1069
+			return $rows_affected > 0 ? true : false;
1070
+		} else {
1071
+			//we insert the venue
1072
+			$venue_id = $venue_model->insert($venue_array);
1073
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1074
+			return ! empty($venue_id) ? true : false;
1075
+		}
1076
+		//when we have the ancestor come in it's already been handled by the revision save.
1077
+	}
1078
+
1079
+
1080
+
1081
+	/**
1082
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1083
+	 *
1084
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1085
+	 * @param  array    $data   The request data from the form
1086
+	 * @return array
1087
+	 */
1088
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1089
+	{
1090
+		$success = true;
1091
+		$saved_dtt = null;
1092
+		$saved_tickets = array();
1093
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1094
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1095
+			//trim all values to ensure any excess whitespace is removed.
1096
+			$dtt = array_map('trim', $dtt);
1097
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1098
+				: $dtt['DTT_EVT_start'];
1099
+			$datetime_values = array(
1100
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1101
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1102
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1103
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1104
+				'DTT_order'     => $row,
1105
+			);
1106
+			//if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1107
+			if ( ! empty($dtt['DTT_ID'])) {
1108
+				$DTM = EE_Registry::instance()
1109
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1110
+								  ->get_one_by_ID($dtt['DTT_ID']);
1111
+				$DTM->set_date_format($incoming_date_formats[0]);
1112
+				$DTM->set_time_format($incoming_date_formats[1]);
1113
+				foreach ($datetime_values as $field => $value) {
1114
+					$DTM->set($field, $value);
1115
+				}
1116
+				//make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1117
+				$saved_dtts[$DTM->ID()] = $DTM;
1118
+			} else {
1119
+				$DTM = EE_Registry::instance()->load_class(
1120
+					'Datetime',
1121
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1122
+					false,
1123
+					false
1124
+				);
1125
+				foreach ($datetime_values as $field => $value) {
1126
+					$DTM->set($field, $value);
1127
+				}
1128
+			}
1129
+			$DTM->save();
1130
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1131
+			//load DTT helper
1132
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1133
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1134
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1135
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1136
+				$DTT->save();
1137
+			}
1138
+			//now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1139
+			$saved_dtt = $DTT;
1140
+			$success = ! $success ? $success : $DTT;
1141
+			//if ANY of these updates fail then we want the appropriate global error message.
1142
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1143
+		}
1144
+		//no dtts get deleted so we don't do any of that logic here.
1145
+		//update tickets next
1146
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1147
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1148
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1149
+			$update_prices = false;
1150
+			$ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1151
+				? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1152
+			// trim inputs to ensure any excess whitespace is removed.
1153
+			$tkt = array_map('trim', $tkt);
1154
+			if (empty($tkt['TKT_start_date'])) {
1155
+				//let's use now in the set timezone.
1156
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1157
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1158
+			}
1159
+			if (empty($tkt['TKT_end_date'])) {
1160
+				//use the start date of the first datetime
1161
+				$dtt = $evtobj->first_datetime();
1162
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1163
+					$incoming_date_formats[0],
1164
+					$incoming_date_formats[1]
1165
+				);
1166
+			}
1167
+			$TKT_values = array(
1168
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1169
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1170
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1171
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1172
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1173
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1174
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1175
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1176
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1177
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1178
+				'TKT_row'         => $row,
1179
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1180
+				'TKT_price'       => $ticket_price,
1181
+			);
1182
+			//if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1183
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1184
+				$TKT_values['TKT_ID'] = 0;
1185
+				$TKT_values['TKT_is_default'] = 0;
1186
+				$TKT_values['TKT_price'] = $ticket_price;
1187
+				$update_prices = true;
1188
+			}
1189
+			//if we have a TKT_ID then we need to get that existing TKT_obj and update it
1190
+			//we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1191
+			//keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1192
+			if ( ! empty($tkt['TKT_ID'])) {
1193
+				$TKT = EE_Registry::instance()
1194
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1195
+								  ->get_one_by_ID($tkt['TKT_ID']);
1196
+				if ($TKT instanceof EE_Ticket) {
1197
+					$ticket_sold = $TKT->count_related(
1198
+						'Registration',
1199
+						array(
1200
+							array(
1201
+								'STS_ID' => array(
1202
+									'NOT IN',
1203
+									array(EEM_Registration::status_id_incomplete),
1204
+								),
1205
+							),
1206
+						)
1207
+					) > 0 ? true : false;
1208
+					//let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1209
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1210
+									  && ! $TKT->get(
1211
+						'TKT_deleted'
1212
+					) ? true : false;
1213
+					$TKT->set_date_format($incoming_date_formats[0]);
1214
+					$TKT->set_time_format($incoming_date_formats[1]);
1215
+					//set new values
1216
+					foreach ($TKT_values as $field => $value) {
1217
+						if ($field == 'TKT_qty') {
1218
+							$TKT->set_qty($value);
1219
+						} else {
1220
+							$TKT->set($field, $value);
1221
+						}
1222
+					}
1223
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1224
+					if ($create_new_TKT) {
1225
+						//archive the old ticket first
1226
+						$TKT->set('TKT_deleted', 1);
1227
+						$TKT->save();
1228
+						//make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1229
+						$saved_tickets[$TKT->ID()] = $TKT;
1230
+						//create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1231
+						$TKT = clone $TKT;
1232
+						$TKT->set('TKT_ID', 0);
1233
+						$TKT->set('TKT_deleted', 0);
1234
+						$TKT->set('TKT_price', $ticket_price);
1235
+						$TKT->set('TKT_sold', 0);
1236
+						//now we need to make sure that $new prices are created as well and attached to new ticket.
1237
+						$update_prices = true;
1238
+					}
1239
+					//make sure price is set if it hasn't been already
1240
+					$TKT->set('TKT_price', $ticket_price);
1241
+				}
1242
+			} else {
1243
+				//no TKT_id so a new TKT
1244
+				$TKT_values['TKT_price'] = $ticket_price;
1245
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1246
+				if ($TKT instanceof EE_Ticket) {
1247
+					//need to reset values to properly account for the date formats
1248
+					$TKT->set_date_format($incoming_date_formats[0]);
1249
+					$TKT->set_time_format($incoming_date_formats[1]);
1250
+					$TKT->set_timezone($evtobj->get_timezone());
1251
+					//set new values
1252
+					foreach ($TKT_values as $field => $value) {
1253
+						if ($field == 'TKT_qty') {
1254
+							$TKT->set_qty($value);
1255
+						} else {
1256
+							$TKT->set($field, $value);
1257
+						}
1258
+					}
1259
+					$update_prices = true;
1260
+				}
1261
+			}
1262
+			// cap ticket qty by datetime reg limits
1263
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1264
+			//update ticket.
1265
+			$TKT->save();
1266
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1267
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1268
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1269
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1270
+				$TKT->save();
1271
+			}
1272
+			//initially let's add the ticket to the dtt
1273
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1274
+			$saved_tickets[$TKT->ID()] = $TKT;
1275
+			//add prices to ticket
1276
+			$this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1277
+		}
1278
+		//however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1279
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1280
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1281
+		foreach ($tickets_removed as $id) {
1282
+			$id = absint($id);
1283
+			//get the ticket for this id
1284
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1285
+			//need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1286
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1287
+			foreach ($dtts as $dtt) {
1288
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1289
+			}
1290
+			//need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1291
+			$tkt_to_remove->delete_related_permanently('Price');
1292
+			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1293
+			$tkt_to_remove->delete_permanently();
1294
+		}
1295
+		return array($saved_dtt, $saved_tickets);
1296
+	}
1297
+
1298
+
1299
+
1300
+	/**
1301
+	 * This attaches a list of given prices to a ticket.
1302
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1303
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1304
+	 * price info and prices are automatically "archived" via the ticket.
1305
+	 *
1306
+	 * @access  private
1307
+	 * @param array     $prices     Array of prices from the form.
1308
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1309
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1310
+	 * @return  void
1311
+	 */
1312
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1313
+	{
1314
+		foreach ($prices as $row => $prc) {
1315
+			$PRC_values = array(
1316
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1317
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1318
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1319
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1320
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1321
+				'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1322
+				'PRC_order'      => $row,
1323
+			);
1324
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1325
+				$PRC_values['PRC_ID'] = 0;
1326
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1327
+			} else {
1328
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1329
+				//update this price with new values
1330
+				foreach ($PRC_values as $field => $newprc) {
1331
+					$PRC->set($field, $newprc);
1332
+				}
1333
+				$PRC->save();
1334
+			}
1335
+			$ticket->_add_relation_to($PRC, 'Price');
1336
+		}
1337
+	}
1338
+
1339
+
1340
+
1341
+	/**
1342
+	 * Add in our autosave ajax handlers
1343
+	 *
1344
+	 * @return void
1345
+	 */
1346
+	protected function _ee_autosave_create_new()
1347
+	{
1348
+		// $this->_ee_autosave_edit();
1349
+	}
1350
+
1351
+
1352
+
1353
+	protected function _ee_autosave_edit()
1354
+	{
1355
+		return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1356
+	}
1357
+
1358
+
1359
+
1360
+	/**
1361
+	 *    _generate_publish_box_extra_content
1362
+	 *
1363
+	 * @access private
1364
+	 * @return void
1365
+	 */
1366
+	private function _generate_publish_box_extra_content()
1367
+	{
1368
+		//load formatter helper
1369
+		//args for getting related registrations
1370
+		$approved_query_args = array(
1371
+			array(
1372
+				'REG_deleted' => 0,
1373
+				'STS_ID'      => EEM_Registration::status_id_approved,
1374
+			),
1375
+		);
1376
+		$not_approved_query_args = array(
1377
+			array(
1378
+				'REG_deleted' => 0,
1379
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1380
+			),
1381
+		);
1382
+		$pending_payment_query_args = array(
1383
+			array(
1384
+				'REG_deleted' => 0,
1385
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1386
+			),
1387
+		);
1388
+		// publish box
1389
+		$publish_box_extra_args = array(
1390
+			'view_approved_reg_url'        => add_query_arg(
1391
+				array(
1392
+					'action'      => 'default',
1393
+					'event_id'    => $this->_cpt_model_obj->ID(),
1394
+					'_reg_status' => EEM_Registration::status_id_approved,
1395
+				),
1396
+				REG_ADMIN_URL
1397
+			),
1398
+			'view_not_approved_reg_url'    => add_query_arg(
1399
+				array(
1400
+					'action'      => 'default',
1401
+					'event_id'    => $this->_cpt_model_obj->ID(),
1402
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1403
+				),
1404
+				REG_ADMIN_URL
1405
+			),
1406
+			'view_pending_payment_reg_url' => add_query_arg(
1407
+				array(
1408
+					'action'      => 'default',
1409
+					'event_id'    => $this->_cpt_model_obj->ID(),
1410
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1411
+				),
1412
+				REG_ADMIN_URL
1413
+			),
1414
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1415
+				'Registration',
1416
+				$approved_query_args
1417
+			),
1418
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1419
+				'Registration',
1420
+				$not_approved_query_args
1421
+			),
1422
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1423
+				'Registration',
1424
+				$pending_payment_query_args
1425
+			),
1426
+			'misc_pub_section_class'       => apply_filters(
1427
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1428
+				'misc-pub-section'
1429
+			),
1430
+			//'email_attendees_url' => add_query_arg(
1431
+			//	array(
1432
+			//		'event_admin_reports' => 'event_newsletter',
1433
+			//		'event_id' => $this->_cpt_model_obj->id
1434
+			//	),
1435
+			//	'admin.php?page=espresso_registrations'
1436
+			//),
1437
+		);
1438
+		ob_start();
1439
+		do_action(
1440
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1441
+			$this->_cpt_model_obj
1442
+		);
1443
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1444
+		// load template
1445
+		EEH_Template::display_template(
1446
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1447
+			$publish_box_extra_args
1448
+		);
1449
+	}
1450
+
1451
+
1452
+
1453
+	/**
1454
+	 * This just returns whatever is set as the _event object property
1455
+	 * //todo this will become obsolete once the models are in place
1456
+	 *
1457
+	 * @return object
1458
+	 */
1459
+	public function get_event_object()
1460
+	{
1461
+		return $this->_cpt_model_obj;
1462
+	}
1463
+
1464
+
1465
+
1466
+
1467
+	/** METABOXES * */
1468
+	/**
1469
+	 * _register_event_editor_meta_boxes
1470
+	 * add all metaboxes related to the event_editor
1471
+	 *
1472
+	 * @return void
1473
+	 */
1474
+	protected function _register_event_editor_meta_boxes()
1475
+	{
1476
+		$this->verify_cpt_object();
1477
+		add_meta_box(
1478
+			'espresso_event_editor_tickets',
1479
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1480
+			array($this, 'ticket_metabox'),
1481
+			$this->page_slug,
1482
+			'normal',
1483
+			'high'
1484
+		);
1485
+		add_meta_box(
1486
+			'espresso_event_editor_event_options',
1487
+			esc_html__('Event Registration Options', 'event_espresso'),
1488
+			array($this, 'registration_options_meta_box'),
1489
+			$this->page_slug,
1490
+			'side',
1491
+			'default'
1492
+		);
1493
+		// NOTE: if you're looking for other metaboxes in here,
1494
+		// where a metabox has a related management page in the admin
1495
+		// you will find it setup in the related management page's "_Hooks" file.
1496
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1497
+	}
1498
+
1499
+
1500
+
1501
+	public function ticket_metabox()
1502
+	{
1503
+		$existing_datetime_ids = $existing_ticket_ids = array();
1504
+		//defaults for template args
1505
+		$template_args = array(
1506
+			'existing_datetime_ids'    => '',
1507
+			'event_datetime_help_link' => '',
1508
+			'ticket_options_help_link' => '',
1509
+			'time'                     => null,
1510
+			'ticket_rows'              => '',
1511
+			'existing_ticket_ids'      => '',
1512
+			'total_ticket_rows'        => 1,
1513
+			'ticket_js_structure'      => '',
1514
+			'trash_icon'               => 'ee-lock-icon',
1515
+			'disabled'                 => '',
1516
+		);
1517
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1518
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1519
+		/**
1520
+		 * 1. Start with retrieving Datetimes
1521
+		 * 2. Fore each datetime get related tickets
1522
+		 * 3. For each ticket get related prices
1523
+		 */
1524
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1525
+		/** @type EE_Datetime $first_datetime */
1526
+		$first_datetime = reset($times);
1527
+		//do we get related tickets?
1528
+		if ($first_datetime instanceof EE_Datetime
1529
+			&& $first_datetime->ID() !== 0
1530
+		) {
1531
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1532
+			$template_args['time'] = $first_datetime;
1533
+			$related_tickets = $first_datetime->tickets(
1534
+				array(
1535
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1536
+					'default_where_conditions' => 'none',
1537
+				)
1538
+			);
1539
+			if ( ! empty($related_tickets)) {
1540
+				$template_args['total_ticket_rows'] = count($related_tickets);
1541
+				$row = 0;
1542
+				foreach ($related_tickets as $ticket) {
1543
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1544
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1545
+					$row++;
1546
+				}
1547
+			} else {
1548
+				$template_args['total_ticket_rows'] = 1;
1549
+				/** @type EE_Ticket $ticket */
1550
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1551
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1552
+			}
1553
+		} else {
1554
+			$template_args['time'] = $times[0];
1555
+			/** @type EE_Ticket $ticket */
1556
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1557
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1558
+			// NOTE: we're just sending the first default row
1559
+			// (decaf can't manage default tickets so this should be sufficient);
1560
+		}
1561
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1562
+			'event_editor_event_datetimes_help_tab'
1563
+		);
1564
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1565
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1566
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1567
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1568
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1569
+			true
1570
+		);
1571
+		$template = apply_filters(
1572
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1573
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1574
+		);
1575
+		EEH_Template::display_template($template, $template_args);
1576
+	}
1577
+
1578
+
1579
+
1580
+	/**
1581
+	 * Setup an individual ticket form for the decaf event editor page
1582
+	 *
1583
+	 * @access private
1584
+	 * @param  EE_Ticket $ticket   the ticket object
1585
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1586
+	 * @param int        $row
1587
+	 * @return string generated html for the ticket row.
1588
+	 */
1589
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1590
+	{
1591
+		$template_args = array(
1592
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1593
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1594
+				: '',
1595
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1596
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1597
+			'TKT_name'            => $ticket->get('TKT_name'),
1598
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1599
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1600
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1601
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1602
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1603
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1604
+			'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1605
+									 && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1606
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1607
+			'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1608
+				: ' disabled=disabled',
1609
+		);
1610
+		$price = $ticket->ID() !== 0
1611
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1612
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1613
+		$price_args = array(
1614
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1615
+			'PRC_amount'            => $price->get('PRC_amount'),
1616
+			'PRT_ID'                => $price->get('PRT_ID'),
1617
+			'PRC_ID'                => $price->get('PRC_ID'),
1618
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1619
+		);
1620
+		//make sure we have default start and end dates if skeleton
1621
+		//handle rows that should NOT be empty
1622
+		if (empty($template_args['TKT_start_date'])) {
1623
+			//if empty then the start date will be now.
1624
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1625
+		}
1626
+		if (empty($template_args['TKT_end_date'])) {
1627
+			//get the earliest datetime (if present);
1628
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1629
+				? $this->_cpt_model_obj->get_first_related(
1630
+					'Datetime',
1631
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1632
+				)
1633
+				: null;
1634
+			if ( ! empty($earliest_dtt)) {
1635
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1636
+			} else {
1637
+				$template_args['TKT_end_date'] = date(
1638
+					'Y-m-d h:i a',
1639
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1640
+				);
1641
+			}
1642
+		}
1643
+		$template_args = array_merge($template_args, $price_args);
1644
+		$template = apply_filters(
1645
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1646
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1647
+			$ticket
1648
+		);
1649
+		return EEH_Template::display_template($template, $template_args, true);
1650
+	}
1651
+
1652
+
1653
+
1654
+	public function registration_options_meta_box()
1655
+	{
1656
+		$yes_no_values = array(
1657
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1658
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1659
+		);
1660
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1661
+			array(
1662
+				EEM_Registration::status_id_cancelled,
1663
+				EEM_Registration::status_id_declined,
1664
+				EEM_Registration::status_id_incomplete,
1665
+			),
1666
+			true
1667
+		);
1668
+		//$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1669
+		$template_args['_event'] = $this->_cpt_model_obj;
1670
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1671
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1672
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1673
+			'default_reg_status',
1674
+			$default_reg_status_values,
1675
+			$this->_cpt_model_obj->default_registration_status()
1676
+		);
1677
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1678
+			'display_desc',
1679
+			$yes_no_values,
1680
+			$this->_cpt_model_obj->display_description()
1681
+		);
1682
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1683
+			'display_ticket_selector',
1684
+			$yes_no_values,
1685
+			$this->_cpt_model_obj->display_ticket_selector(),
1686
+			'',
1687
+			'',
1688
+			false
1689
+		);
1690
+		$template_args['additional_registration_options'] = apply_filters(
1691
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1692
+			'',
1693
+			$template_args,
1694
+			$yes_no_values,
1695
+			$default_reg_status_values
1696
+		);
1697
+		EEH_Template::display_template(
1698
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1699
+			$template_args
1700
+		);
1701
+	}
1702
+
1703
+
1704
+
1705
+	/**
1706
+	 * _get_events()
1707
+	 * This method simply returns all the events (for the given _view and paging)
1708
+	 *
1709
+	 * @access public
1710
+	 * @param int  $per_page     count of items per page (20 default);
1711
+	 * @param int  $current_page what is the current page being viewed.
1712
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1713
+	 *                           If FALSE then we return an array of event objects
1714
+	 *                           that match the given _view and paging parameters.
1715
+	 * @return array an array of event objects.
1716
+	 */
1717
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1718
+	{
1719
+		$EEME = $this->_event_model();
1720
+		$offset = ($current_page - 1) * $per_page;
1721
+		$limit = $count ? null : $offset . ',' . $per_page;
1722
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1723
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1724
+		if (isset($this->_req_data['month_range'])) {
1725
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1726
+			$month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : '';
1727
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1728
+		}
1729
+		$where = array();
1730
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1731
+		//determine what post_status our condition will have for the query.
1732
+		switch ($status) {
1733
+			case 'month' :
1734
+			case 'today' :
1735
+			case null :
1736
+			case 'all' :
1737
+				break;
1738
+			case 'draft' :
1739
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1740
+				break;
1741
+			default :
1742
+				$where['status'] = $status;
1743
+		}
1744
+		//categories?
1745
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1746
+			? $this->_req_data['EVT_CAT'] : null;
1747
+		if ( ! empty ($category)) {
1748
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1749
+			$where['Term_Taxonomy.term_id'] = $category;
1750
+		}
1751
+		//date where conditions
1752
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1753
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1754
+			$DateTime = new DateTime(
1755
+				$year_r . '-' . $month_r . '-01 00:00:00',
1756
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1757
+			);
1758
+			$start = $DateTime->format(implode(' ', $start_formats));
1759
+			$end = $DateTime->setDate($year_r, $month_r, $DateTime
1760
+				->format('t'))->setTime(23, 59, 59)
1761
+							->format(implode(' ', $start_formats));
1762
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1763
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1764
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1765
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1766
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1767
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1768
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1769
+			$now = date('Y-m-01');
1770
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1771
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1772
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1773
+							->setTime(23, 59, 59)
1774
+							->format(implode(' ', $start_formats));
1775
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1776
+		}
1777
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1778
+			$where['EVT_wp_user'] = get_current_user_id();
1779
+		} else {
1780
+			if ( ! isset($where['status'])) {
1781
+				if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1782
+					$where['OR'] = array(
1783
+						'status*restrict_private' => array('!=', 'private'),
1784
+						'AND'                     => array(
1785
+							'status*inclusive' => array('=', 'private'),
1786
+							'EVT_wp_user'      => get_current_user_id(),
1787
+						),
1788
+					);
1789
+				}
1790
+			}
1791
+		}
1792
+		if (isset($this->_req_data['EVT_wp_user'])) {
1793
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1794
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1795
+			) {
1796
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1797
+			}
1798
+		}
1799
+		//search query handling
1800
+		if (isset($this->_req_data['s'])) {
1801
+			$search_string = '%' . $this->_req_data['s'] . '%';
1802
+			$where['OR'] = array(
1803
+				'EVT_name'       => array('LIKE', $search_string),
1804
+				'EVT_desc'       => array('LIKE', $search_string),
1805
+				'EVT_short_desc' => array('LIKE', $search_string),
1806
+			);
1807
+		}
1808
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1809
+		$query_params = apply_filters(
1810
+			'FHEE__Events_Admin_Page__get_events__query_params',
1811
+			array(
1812
+				$where,
1813
+				'limit'    => $limit,
1814
+				'order_by' => $orderby,
1815
+				'order'    => $order,
1816
+				'group_by' => 'EVT_ID',
1817
+			),
1818
+			$this->_req_data
1819
+		);
1820
+		//let's first check if we have special requests coming in.
1821
+		if (isset($this->_req_data['active_status'])) {
1822
+			switch ($this->_req_data['active_status']) {
1823
+				case 'upcoming' :
1824
+					return $EEME->get_upcoming_events($query_params, $count);
1825
+					break;
1826
+				case 'expired' :
1827
+					return $EEME->get_expired_events($query_params, $count);
1828
+					break;
1829
+				case 'active' :
1830
+					return $EEME->get_active_events($query_params, $count);
1831
+					break;
1832
+				case 'inactive' :
1833
+					return $EEME->get_inactive_events($query_params, $count);
1834
+					break;
1835
+			}
1836
+		}
1837
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1838
+		return $events;
1839
+	}
1840
+
1841
+
1842
+
1843
+	/**
1844
+	 * handling for WordPress CPT actions (trash, restore, delete)
1845
+	 *
1846
+	 * @param string $post_id
1847
+	 */
1848
+	public function trash_cpt_item($post_id)
1849
+	{
1850
+		$this->_req_data['EVT_ID'] = $post_id;
1851
+		$this->_trash_or_restore_event('trash', false);
1852
+	}
1853
+
1854
+
1855
+
1856
+	/**
1857
+	 * @param string $post_id
1858
+	 */
1859
+	public function restore_cpt_item($post_id)
1860
+	{
1861
+		$this->_req_data['EVT_ID'] = $post_id;
1862
+		$this->_trash_or_restore_event('draft', false);
1863
+	}
1864
+
1865
+
1866
+
1867
+	/**
1868
+	 * @param string $post_id
1869
+	 */
1870
+	public function delete_cpt_item($post_id)
1871
+	{
1872
+		$this->_req_data['EVT_ID'] = $post_id;
1873
+		$this->_delete_event(false);
1874
+	}
1875
+
1876
+
1877
+
1878
+	/**
1879
+	 * _trash_or_restore_event
1880
+	 *
1881
+	 * @access protected
1882
+	 * @param  string $event_status
1883
+	 * @param bool    $redirect_after
1884
+	 */
1885
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1886
+	{
1887
+		//determine the event id and set to array.
1888
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1889
+		// loop thru events
1890
+		if ($EVT_ID) {
1891
+			// clean status
1892
+			$event_status = sanitize_key($event_status);
1893
+			// grab status
1894
+			if ( ! empty($event_status)) {
1895
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1896
+			} else {
1897
+				$success = false;
1898
+				$msg = esc_html__(
1899
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1900
+					'event_espresso'
1901
+				);
1902
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1903
+			}
1904
+		} else {
1905
+			$success = false;
1906
+			$msg = esc_html__(
1907
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1908
+				'event_espresso'
1909
+			);
1910
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1911
+		}
1912
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1913
+		if ($redirect_after) {
1914
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1915
+		}
1916
+	}
1917
+
1918
+
1919
+
1920
+	/**
1921
+	 * _trash_or_restore_events
1922
+	 *
1923
+	 * @access protected
1924
+	 * @param  string $event_status
1925
+	 * @return void
1926
+	 */
1927
+	protected function _trash_or_restore_events($event_status = 'trash')
1928
+	{
1929
+		// clean status
1930
+		$event_status = sanitize_key($event_status);
1931
+		// grab status
1932
+		if ( ! empty($event_status)) {
1933
+			$success = true;
1934
+			//determine the event id and set to array.
1935
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1936
+			// loop thru events
1937
+			foreach ($EVT_IDs as $EVT_ID) {
1938
+				if ($EVT_ID = absint($EVT_ID)) {
1939
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1940
+					$success = $results !== false ? $success : false;
1941
+				} else {
1942
+					$msg = sprintf(
1943
+						esc_html__(
1944
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1945
+							'event_espresso'
1946
+						),
1947
+						$EVT_ID
1948
+					);
1949
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1950
+					$success = false;
1951
+				}
1952
+			}
1953
+		} else {
1954
+			$success = false;
1955
+			$msg = esc_html__(
1956
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1957
+				'event_espresso'
1958
+			);
1959
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1960
+		}
1961
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1962
+		$success = $success ? 2 : false;
1963
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1964
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1965
+	}
1966
+
1967
+
1968
+
1969
+	/**
1970
+	 * _trash_or_restore_events
1971
+	 *
1972
+	 * @access  private
1973
+	 * @param  int    $EVT_ID
1974
+	 * @param  string $event_status
1975
+	 * @return bool
1976
+	 */
1977
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
1978
+	{
1979
+		// grab event id
1980
+		if ( ! $EVT_ID) {
1981
+			$msg = esc_html__(
1982
+				'An error occurred. No Event ID or an invalid Event ID was received.',
1983
+				'event_espresso'
1984
+			);
1985
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1986
+			return false;
1987
+		}
1988
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
1989
+		// clean status
1990
+		$event_status = sanitize_key($event_status);
1991
+		// grab status
1992
+		if (empty($event_status)) {
1993
+			$msg = esc_html__(
1994
+				'An error occurred. No Event Status or an invalid Event Status was received.',
1995
+				'event_espresso'
1996
+			);
1997
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1998
+			return false;
1999
+		}
2000
+		// was event trashed or restored ?
2001
+		switch ($event_status) {
2002
+			case 'draft' :
2003
+				$action = 'restored from the trash';
2004
+				$hook = 'AHEE_event_restored_from_trash';
2005
+				break;
2006
+			case 'trash' :
2007
+				$action = 'moved to the trash';
2008
+				$hook = 'AHEE_event_moved_to_trash';
2009
+				break;
2010
+			default :
2011
+				$action = 'updated';
2012
+				$hook = false;
2013
+		}
2014
+		//use class to change status
2015
+		$this->_cpt_model_obj->set_status($event_status);
2016
+		$success = $this->_cpt_model_obj->save();
2017
+		if ($success === false) {
2018
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2019
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2020
+			return false;
2021
+		}
2022
+		if ($hook) {
2023
+			do_action($hook);
2024
+		}
2025
+		return true;
2026
+	}
2027
+
2028
+
2029
+
2030
+	/**
2031
+	 * _delete_event
2032
+	 *
2033
+	 * @access protected
2034
+	 * @param bool $redirect_after
2035
+	 */
2036
+	protected function _delete_event($redirect_after = true)
2037
+	{
2038
+		//determine the event id and set to array.
2039
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2040
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2041
+		// loop thru events
2042
+		if ($EVT_ID) {
2043
+			$success = $this->_permanently_delete_event($EVT_ID);
2044
+			// get list of events with no prices
2045
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2046
+			// remove this event from the list of events with no prices
2047
+			if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2048
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2049
+			}
2050
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2051
+		} else {
2052
+			$success = false;
2053
+			$msg = esc_html__(
2054
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2055
+				'event_espresso'
2056
+			);
2057
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2058
+		}
2059
+		if ($redirect_after) {
2060
+			$this->_redirect_after_action(
2061
+				$success,
2062
+				'Event',
2063
+				'deleted',
2064
+				array('action' => 'default', 'status' => 'trash')
2065
+			);
2066
+		}
2067
+	}
2068
+
2069
+
2070
+
2071
+	/**
2072
+	 * _delete_events
2073
+	 *
2074
+	 * @access protected
2075
+	 * @return void
2076
+	 */
2077
+	protected function _delete_events()
2078
+	{
2079
+		$success = true;
2080
+		// get list of events with no prices
2081
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2082
+		//determine the event id and set to array.
2083
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2084
+		// loop thru events
2085
+		foreach ($EVT_IDs as $EVT_ID) {
2086
+			$EVT_ID = absint($EVT_ID);
2087
+			if ($EVT_ID) {
2088
+				$results = $this->_permanently_delete_event($EVT_ID);
2089
+				$success = $results !== false ? $success : false;
2090
+				// remove this event from the list of events with no prices
2091
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2092
+			} else {
2093
+				$success = false;
2094
+				$msg = esc_html__(
2095
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2096
+					'event_espresso'
2097
+				);
2098
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2099
+			}
2100
+		}
2101
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2102
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2103
+		$success = $success ? 2 : false;
2104
+		$this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2105
+	}
2106
+
2107
+
2108
+
2109
+	/**
2110
+	 * _permanently_delete_event
2111
+	 *
2112
+	 * @access  private
2113
+	 * @param  int $EVT_ID
2114
+	 * @return bool
2115
+	 */
2116
+	private function _permanently_delete_event($EVT_ID = 0)
2117
+	{
2118
+		// grab event id
2119
+		if ( ! $EVT_ID) {
2120
+			$msg = esc_html__(
2121
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2122
+				'event_espresso'
2123
+			);
2124
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2125
+			return false;
2126
+		}
2127
+		if (
2128
+			! $this->_cpt_model_obj instanceof EE_Event
2129
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2130
+		) {
2131
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2132
+		}
2133
+		if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2134
+			return false;
2135
+		}
2136
+		//need to delete related tickets and prices first.
2137
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2138
+		foreach ($datetimes as $datetime) {
2139
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2140
+			$tickets = $datetime->get_many_related('Ticket');
2141
+			foreach ($tickets as $ticket) {
2142
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2143
+				$ticket->delete_related_permanently('Price');
2144
+				$ticket->delete_permanently();
2145
+			}
2146
+			$datetime->delete();
2147
+		}
2148
+		//what about related venues or terms?
2149
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2150
+		foreach ($venues as $venue) {
2151
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2152
+		}
2153
+		//any attached question groups?
2154
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2155
+		if ( ! empty($question_groups)) {
2156
+			foreach ($question_groups as $question_group) {
2157
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2158
+			}
2159
+		}
2160
+		//Message Template Groups
2161
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2162
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2163
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2164
+		foreach ($term_taxonomies as $term_taxonomy) {
2165
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2166
+		}
2167
+		$success = $this->_cpt_model_obj->delete_permanently();
2168
+		// did it all go as planned ?
2169
+		if ($success) {
2170
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2171
+			EE_Error::add_success($msg);
2172
+		} else {
2173
+			$msg = sprintf(
2174
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2175
+				$EVT_ID
2176
+			);
2177
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2178
+			return false;
2179
+		}
2180
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2181
+		return true;
2182
+	}
2183
+
2184
+
2185
+
2186
+	/**
2187
+	 * get total number of events
2188
+	 *
2189
+	 * @access public
2190
+	 * @return int
2191
+	 */
2192
+	public function total_events()
2193
+	{
2194
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2195
+		return $count;
2196
+	}
2197
+
2198
+
2199
+
2200
+	/**
2201
+	 * get total number of draft events
2202
+	 *
2203
+	 * @access public
2204
+	 * @return int
2205
+	 */
2206
+	public function total_events_draft()
2207
+	{
2208
+		$where = array(
2209
+			'status' => array('IN', array('draft', 'auto-draft')),
2210
+		);
2211
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2212
+		return $count;
2213
+	}
2214
+
2215
+
2216
+
2217
+	/**
2218
+	 * get total number of trashed events
2219
+	 *
2220
+	 * @access public
2221
+	 * @return int
2222
+	 */
2223
+	public function total_trashed_events()
2224
+	{
2225
+		$where = array(
2226
+			'status' => 'trash',
2227
+		);
2228
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2229
+		return $count;
2230
+	}
2231
+
2232
+
2233
+
2234
+	/**
2235
+	 *    _default_event_settings
2236
+	 *    This generates the Default Settings Tab
2237
+	 *
2238
+	 * @return void
2239
+	 */
2240
+	protected function _default_event_settings()
2241
+	{
2242
+		$this->_template_args['values'] = $this->_yes_no_values;
2243
+		$this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array(
2244
+		// exclude array
2245
+			array(
2246
+				EEM_Registration::status_id_cancelled,
2247
+				EEM_Registration::status_id_declined,
2248
+				EEM_Registration::status_id_incomplete,
2249
+				EEM_Registration::status_id_wait_list,
2250
+			),
2251
+			// translated
2252
+			true
2253
+		);
2254
+		$this->_template_args['default_reg_status'] = isset(
2255
+														  EE_Registry::instance()->CFG->registration->default_STS_ID
2256
+													  )
2257
+													  && array_key_exists(
2258
+														  EE_Registry::instance()->CFG->registration->default_STS_ID,
2259
+														  $this->_template_args['reg_status_array']
2260
+													  )
2261
+			? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID)
2262
+			: EEM_Registration::status_id_pending_payment;
2263
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2264
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2265
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2266
+			EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2267
+			$this->_template_args,
2268
+			true
2269
+		);
2270
+		$this->display_admin_page_with_sidebar();
2271
+	}
2272
+
2273
+
2274
+
2275
+	/**
2276
+	 * _update_default_event_settings
2277
+	 *
2278
+	 * @access protected
2279
+	 * @return void
2280
+	 */
2281
+	protected function _update_default_event_settings()
2282
+	{
2283
+		EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status'])
2284
+			? sanitize_text_field($this->_req_data['default_reg_status'])
2285
+			: EEM_Registration::status_id_pending_payment;
2286
+		$what = 'Default Event Settings';
2287
+		$success = $this->_update_espresso_configuration(
2288
+			$what,
2289
+			EE_Config::instance(),
2290
+			__FILE__,
2291
+			__FUNCTION__,
2292
+			__LINE__
2293
+		);
2294
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings'));
2295
+	}
2296
+
2297
+
2298
+
2299
+	/*************        Templates        *************/
2300
+	protected function _template_settings()
2301
+	{
2302
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2303
+		$this->_template_args['preview_img'] = '<img src="'
2304
+											   . EVENTS_ASSETS_URL
2305
+											   . DS
2306
+											   . 'images'
2307
+											   . DS
2308
+											   . 'caffeinated_template_features.jpg" alt="'
2309
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2310
+											   . '" />';
2311
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__(
2312
+				'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2313
+				'event_espresso'
2314
+			) . '</strong>';
2315
+		$this->display_admin_caf_preview_page('template_settings_tab');
2316
+	}
2317
+
2318
+
2319
+	/** Event Category Stuff **/
2320
+	/**
2321
+	 * set the _category property with the category object for the loaded page.
2322
+	 *
2323
+	 * @access private
2324
+	 * @return void
2325
+	 */
2326
+	private function _set_category_object()
2327
+	{
2328
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2329
+			return;
2330
+		} //already have the category object so get out.
2331
+		//set default category object
2332
+		$this->_set_empty_category_object();
2333
+		//only set if we've got an id
2334
+		if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2335
+			return;
2336
+		}
2337
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2338
+		$term = get_term($category_id, 'espresso_event_categories');
2339
+		if ( ! empty($term)) {
2340
+			$this->_category->category_name = $term->name;
2341
+			$this->_category->category_identifier = $term->slug;
2342
+			$this->_category->category_desc = $term->description;
2343
+			$this->_category->id = $term->term_id;
2344
+			$this->_category->parent = $term->parent;
2345
+		}
2346
+	}
2347
+
2348
+
2349
+
2350
+	private function _set_empty_category_object()
2351
+	{
2352
+		$this->_category = new stdClass();
2353
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2354
+		$this->_category->id = $this->_category->parent = 0;
2355
+	}
2356
+
2357
+
2358
+
2359
+	protected function _category_list_table()
2360
+	{
2361
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2362
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2363
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2364
+				'add_category',
2365
+				'add_category',
2366
+				array(),
2367
+				'add-new-h2'
2368
+			);
2369
+		$this->display_admin_list_table_page_with_sidebar();
2370
+	}
2371
+
2372
+
2373
+
2374
+	/**
2375
+	 * @param $view
2376
+	 */
2377
+	protected function _category_details($view)
2378
+	{
2379
+		//load formatter helper
2380
+		//load field generator helper
2381
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2382
+		$this->_set_add_edit_form_tags($route);
2383
+		$this->_set_category_object();
2384
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2385
+		$delete_action = 'delete_category';
2386
+		//custom redirect
2387
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2388
+			array('action' => 'category_list'),
2389
+			$this->_admin_base_url
2390
+		);
2391
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2392
+		//take care of contents
2393
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2394
+		$this->display_admin_page_with_sidebar();
2395
+	}
2396
+
2397
+
2398
+
2399
+	/**
2400
+	 * @return mixed
2401
+	 */
2402
+	protected function _category_details_content()
2403
+	{
2404
+		$editor_args['category_desc'] = array(
2405
+			'type'          => 'wp_editor',
2406
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2407
+			'class'         => 'my_editor_custom',
2408
+			'wpeditor_args' => array('media_buttons' => false),
2409
+		);
2410
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2411
+		$all_terms = get_terms(
2412
+			array('espresso_event_categories'),
2413
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2414
+		);
2415
+		//setup category select for term parents.
2416
+		$category_select_values[] = array(
2417
+			'text' => esc_html__('No Parent', 'event_espresso'),
2418
+			'id'   => 0,
2419
+		);
2420
+		foreach ($all_terms as $term) {
2421
+			$category_select_values[] = array(
2422
+				'text' => $term->name,
2423
+				'id'   => $term->term_id,
2424
+			);
2425
+		}
2426
+		$category_select = EEH_Form_Fields::select_input(
2427
+			'category_parent',
2428
+			$category_select_values,
2429
+			$this->_category->parent
2430
+		);
2431
+		$template_args = array(
2432
+			'category'                 => $this->_category,
2433
+			'category_select'          => $category_select,
2434
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2435
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2436
+			'disable'                  => '',
2437
+			'disabled_message'         => false,
2438
+		);
2439
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2440
+		return EEH_Template::display_template($template, $template_args, true);
2441
+	}
2442
+
2443
+
2444
+
2445
+	protected function _delete_categories()
2446
+	{
2447
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2448
+			: (array)$this->_req_data['category_id'];
2449
+		foreach ($cat_ids as $cat_id) {
2450
+			$this->_delete_category($cat_id);
2451
+		}
2452
+		//doesn't matter what page we're coming from... we're going to the same place after delete.
2453
+		$query_args = array(
2454
+			'action' => 'category_list',
2455
+		);
2456
+		$this->_redirect_after_action(0, '', '', $query_args);
2457
+	}
2458
+
2459
+
2460
+
2461
+	/**
2462
+	 * @param $cat_id
2463
+	 */
2464
+	protected function _delete_category($cat_id)
2465
+	{
2466
+		$cat_id = absint($cat_id);
2467
+		wp_delete_term($cat_id, 'espresso_event_categories');
2468
+	}
2469
+
2470
+
2471
+
2472
+	/**
2473
+	 * @param $new_category
2474
+	 */
2475
+	protected function _insert_or_update_category($new_category)
2476
+	{
2477
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2478
+		$success = 0; //we already have a success message so lets not send another.
2479
+		if ($cat_id) {
2480
+			$query_args = array(
2481
+				'action'     => 'edit_category',
2482
+				'EVT_CAT_ID' => $cat_id,
2483
+			);
2484
+		} else {
2485
+			$query_args = array('action' => 'add_category');
2486
+		}
2487
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2488
+	}
2489
+
2490
+
2491
+
2492
+	/**
2493
+	 * @param bool $update
2494
+	 * @return bool|mixed|string
2495
+	 */
2496
+	private function _insert_category($update = false)
2497
+	{
2498
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2499
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2500
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2501
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2502
+		if (empty($category_name)) {
2503
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2504
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2505
+			return false;
2506
+		}
2507
+		$term_args = array(
2508
+			'name'        => $category_name,
2509
+			'description' => $category_desc,
2510
+			'parent'      => $category_parent,
2511
+		);
2512
+		//was the category_identifier input disabled?
2513
+		if (isset($this->_req_data['category_identifier'])) {
2514
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2515
+		}
2516
+		$insert_ids = $update
2517
+			? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2518
+			: wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2519
+		if ( ! is_array($insert_ids)) {
2520
+			$msg = esc_html__(
2521
+				'An error occurred and the category has not been saved to the database.',
2522
+				'event_espresso'
2523
+			);
2524
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2525
+		} else {
2526
+			$cat_id = $insert_ids['term_id'];
2527
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2528
+			EE_Error::add_success($msg);
2529
+		}
2530
+		return $cat_id;
2531
+	}
2532
+
2533
+
2534
+
2535
+	/**
2536
+	 * @param int  $per_page
2537
+	 * @param int  $current_page
2538
+	 * @param bool $count
2539
+	 * @return \EE_Base_Class[]|int
2540
+	 */
2541
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2542
+	{
2543
+		//testing term stuff
2544
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2545
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2546
+		$limit = ($current_page - 1) * $per_page;
2547
+		$where = array('taxonomy' => 'espresso_event_categories');
2548
+		if (isset($this->_req_data['s'])) {
2549
+			$sstr = '%' . $this->_req_data['s'] . '%';
2550
+			$where['OR'] = array(
2551
+				'Term.name'   => array('LIKE', $sstr),
2552
+				'description' => array('LIKE', $sstr),
2553
+			);
2554
+		}
2555
+		$query_params = array(
2556
+			$where,
2557
+			'order_by'   => array($orderby => $order),
2558
+			'limit'      => $limit . ',' . $per_page,
2559
+			'force_join' => array('Term'),
2560
+		);
2561
+		$categories = $count
2562
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2563
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2564
+		return $categories;
2565
+	}
2566
+
2567
+
2568
+
2569
+	/* end category stuff */
2570
+	/**************/
2571 2571
 }
2572 2572
 //end class Events_Admin_Page
Please login to merge, or discard this patch.