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