Completed
Branch BUG-9042-ics-organizer-email (0077fa)
by
unknown
26:47 queued 15:14
created
widgets/upcoming_events/EEW_Upcoming_Events.widget.php 1 patch
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -30,8 +30,8 @@  discard block
 block discarded – undo
30 30
 	function __construct() {
31 31
 		parent::__construct(
32 32
 			'ee-upcoming-events-widget',
33
-			__( 'Event Espresso Upcoming Events', 'event_espresso' ),
34
-			 array( 'description' => __( 'A widget to display your upcoming events.', 'event_espresso' )),
33
+			__('Event Espresso Upcoming Events', 'event_espresso'),
34
+			 array('description' => __('A widget to display your upcoming events.', 'event_espresso')),
35 35
 			array(
36 36
 				'width' => 300,
37 37
 				'height' => 350,
@@ -49,9 +49,9 @@  discard block
 block discarded – undo
49 49
 	 * @param array $instance Previously saved values from database.
50 50
 	 * @return string|void
51 51
 	 */
52
-	public function form( $instance ) {
52
+	public function form($instance) {
53 53
 
54
-		EE_Registry::instance()->load_class( 'Question_Option', array(), FALSE, FALSE, TRUE );
54
+		EE_Registry::instance()->load_class('Question_Option', array(), FALSE, FALSE, TRUE);
55 55
 		// Set up some default widget settings.
56 56
 		$defaults = array(
57 57
 			'title' => __('Upcoming Events', 'event_espresso'),
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 			'image_size' => 'medium'
67 67
 		);
68 68
 
69
-		$instance = wp_parse_args( (array) $instance, $defaults );
69
+		$instance = wp_parse_args((array) $instance, $defaults);
70 70
 		// don't add HTML labels for EE_Form_Fields generated inputs
71
-		add_filter( 'FHEE__EEH_Form_Fields__label_html', '__return_empty_string' );
71
+		add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string');
72 72
 		$yes_no_values = array(
73
-			EE_Question_Option::new_instance( array( 'QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))),
74
-			EE_Question_Option::new_instance( array( 'QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso')))
73
+			EE_Question_Option::new_instance(array('QSO_value' => FALSE, 'QSO_desc' => __('No', 'event_espresso'))),
74
+			EE_Question_Option::new_instance(array('QSO_value' => TRUE, 'QSO_desc' => __('Yes', 'event_espresso')))
75 75
 		);
76 76
 
77 77
 	?>
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 			<label for="<?php echo $this->get_field_id('title'); ?>">
83 83
 				<?php _e('Title:', 'event_espresso'); ?>
84 84
 			</label>
85
-			<input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" type="text" />
85
+			<input id="<?php echo $this->get_field_id('title'); ?>" class="widefat" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo esc_attr($instance['title']); ?>" type="text" />
86 86
 		</p>
87 87
 		<p>
88 88
 			<label for="<?php echo $this->get_field_id('category_name'); ?>">
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
 			<?php
92 92
 			$event_categories = array();
93 93
 			/** @type EEM_Term $EEM_Term */
94
-			$EEM_Term = EE_Registry::instance()->load_model( 'Term' );
95
-			$categories = $EEM_Term->get_all_ee_categories( TRUE );
96
-			if ( $categories ) {
97
-				foreach ( $categories as $category ) {
98
-					if ( $category instanceof EE_Term ) {
99
-						$event_categories[] = EE_Question_Option::new_instance( array( 'QSO_value' => $category->get( 'slug' ), 'QSO_desc' => $category->get( 'name' )));
94
+			$EEM_Term = EE_Registry::instance()->load_model('Term');
95
+			$categories = $EEM_Term->get_all_ee_categories(TRUE);
96
+			if ($categories) {
97
+				foreach ($categories as $category) {
98
+					if ($category instanceof EE_Term) {
99
+						$event_categories[] = EE_Question_Option::new_instance(array('QSO_value' => $category->get('slug'), 'QSO_desc' => $category->get('name')));
100 100
 					}
101 101
 				}
102 102
 			}
103
-			array_unshift( $event_categories, EE_Question_Option::new_instance( array( 'QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso'))));
103
+			array_unshift($event_categories, EE_Question_Option::new_instance(array('QSO_value' => '', 'QSO_desc' => __(' - display all - ', 'event_espresso'))));
104 104
 			echo EEH_Form_Fields::select(
105 105
 				 __('Event Category:', 'event_espresso'),
106 106
 				$instance['category_name'],
@@ -137,16 +137,16 @@  discard block
 block discarded – undo
137 137
 			<?php
138 138
 			$image_sizes = array();
139 139
 			$sizes = get_intermediate_image_sizes();
140
-			if ( $sizes ) {
140
+			if ($sizes) {
141 141
 				// loop thru images and create option objects out of them
142
-				foreach ( $sizes as $image_size ) {
143
-					$image_size = trim( $image_size );
142
+				foreach ($sizes as $image_size) {
143
+					$image_size = trim($image_size);
144 144
 					// no big images plz
145
-					if ( ! in_array( $image_size, array( 'large', 'post-thumbnail' ))) {
146
-						$image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => $image_size, 'QSO_desc' => $image_size ));
145
+					if ( ! in_array($image_size, array('large', 'post-thumbnail'))) {
146
+						$image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => $image_size, 'QSO_desc' => $image_size));
147 147
 					}
148 148
 				}
149
-				$image_sizes[] = EE_Question_Option::new_instance( array( 'QSO_value' => 'none', 'QSO_desc' =>  __('don\'t show images', 'event_espresso') ));
149
+				$image_sizes[] = EE_Question_Option::new_instance(array('QSO_value' => 'none', 'QSO_desc' =>  __('don\'t show images', 'event_espresso')));
150 150
 			}
151 151
 			echo EEH_Form_Fields::select(
152 152
 				 __('Image Size:', 'event_espresso'),
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 			<label for="<?php echo $this->get_field_id('date_limit'); ?>">
205 205
 				<?php _e('Number of Dates to Display:', 'event_espresso'); ?>
206 206
 			</label>
207
-			<input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr( $instance['date_limit'] ); ?>" size="3" type="text" />
207
+			<input id="<?php echo $this->get_field_id('date_limit'); ?>" name="<?php echo $this->get_field_name('date_limit'); ?>" value="<?php echo esc_attr($instance['date_limit']); ?>" size="3" type="text" />
208 208
 		</p>
209 209
 		<p>
210 210
 			<label for="<?php echo $this->get_field_id('date_range'); ?>">
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
 	 *
237 237
 	 * @return array Updated safe values to be saved.
238 238
 	 */
239
-	public function update( $new_instance, $old_instance ) {
239
+	public function update($new_instance, $old_instance) {
240 240
 		$instance = $old_instance;
241
-		$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
241
+		$instance['title'] = ! empty($new_instance['title']) ? strip_tags($new_instance['title']) : '';
242 242
 		$instance['category_name'] = $new_instance['category_name'];
243 243
 		$instance['show_expired'] = $new_instance['show_expired'];
244 244
 		$instance['limit'] = $new_instance['limit'];
@@ -261,18 +261,18 @@  discard block
 block discarded – undo
261 261
 	 * @param array $args     Widget arguments.
262 262
 	 * @param array $instance Saved values from database.
263 263
 	 */
264
-	public function widget( $args, $instance ) {
264
+	public function widget($args, $instance) {
265 265
 
266 266
 		global $post;
267 267
 		// make sure there is some kinda post object
268
-		if ( $post instanceof WP_Post ) {
268
+		if ($post instanceof WP_Post) {
269 269
 			$before_widget = '';
270 270
 			$before_title = '';
271 271
 			$after_title = '';
272 272
 			$after_widget = '';
273 273
 			// but NOT an events archives page, cuz that would be like two event lists on the same page
274
-			$show_everywhere = isset( $instance['show_everywhere'] ) ? (bool) absint( $instance['show_everywhere'] ) : TRUE;
275
-			if ( $show_everywhere || ! ( $post->post_type == 'espresso_events' && is_archive() )) {
274
+			$show_everywhere = isset($instance['show_everywhere']) ? (bool) absint($instance['show_everywhere']) : TRUE;
275
+			if ($show_everywhere || ! ($post->post_type == 'espresso_events' && is_archive())) {
276 276
 				// let's use some of the event helper functions'
277 277
 				// make separate vars out of attributes
278 278
 
@@ -291,83 +291,83 @@  discard block
 block discarded – undo
291 291
 				// Before widget (defined by themes).
292 292
 				echo $before_widget;
293 293
 				// Display the widget title if one was input (before and after defined by themes).
294
-				if ( ! empty( $title )) {
295
-					echo $before_title . $title . $after_title;
294
+				if ( ! empty($title)) {
295
+					echo $before_title.$title.$after_title;
296 296
 				}
297 297
 				// grab widget settings
298
-				$category = isset( $instance['category_name'] ) && ! empty( $instance['category_name'] ) ? $instance['category_name'] : FALSE;
299
-				$show_expired = isset( $instance['show_expired'] ) ? (bool) absint( $instance['show_expired'] ) : FALSE;
300
-				$image_size = isset( $instance['image_size'] ) && ! empty( $instance['image_size'] ) ? $instance['image_size'] : 'medium';
301
-				$show_desc = isset( $instance['show_desc'] ) ? (bool) absint( $instance['show_desc'] ) : TRUE;
302
-				$show_dates = isset( $instance['show_dates'] ) ? (bool) absint( $instance['show_dates'] ) : TRUE;
303
-				$date_limit = isset( $instance['date_limit'] ) && ! empty( $instance['date_limit'] ) ? $instance['date_limit'] : NULL;
304
-				$date_range = isset( $instance['date_range'] ) && ! empty( $instance['date_range'] ) ? $instance['date_range'] : FALSE;
298
+				$category = isset($instance['category_name']) && ! empty($instance['category_name']) ? $instance['category_name'] : FALSE;
299
+				$show_expired = isset($instance['show_expired']) ? (bool) absint($instance['show_expired']) : FALSE;
300
+				$image_size = isset($instance['image_size']) && ! empty($instance['image_size']) ? $instance['image_size'] : 'medium';
301
+				$show_desc = isset($instance['show_desc']) ? (bool) absint($instance['show_desc']) : TRUE;
302
+				$show_dates = isset($instance['show_dates']) ? (bool) absint($instance['show_dates']) : TRUE;
303
+				$date_limit = isset($instance['date_limit']) && ! empty($instance['date_limit']) ? $instance['date_limit'] : NULL;
304
+				$date_range = isset($instance['date_range']) && ! empty($instance['date_range']) ? $instance['date_range'] : FALSE;
305 305
 				// start to build our where clause
306 306
 				$where = array(
307 307
 //					'Datetime.DTT_is_primary' => 1,
308
-					'status' => array( 'IN', array( 'publish', 'sold_out' ) )
308
+					'status' => array('IN', array('publish', 'sold_out'))
309 309
 				);
310 310
 				// add category
311
-				if ( $category ) {
311
+				if ($category) {
312 312
 					$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
313 313
 					$where['Term_Taxonomy.Term.slug'] = $category;
314 314
 				}
315 315
 				// if NOT expired then we want events that start today or in the future
316
-				if ( ! $show_expired ) {
317
-					$where['Datetime.DTT_EVT_end'] = array( '>=', EEM_Datetime::instance()->current_time_for_query( 'DTT_EVT_end' ) );
316
+				if ( ! $show_expired) {
317
+					$where['Datetime.DTT_EVT_end'] = array('>=', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'));
318 318
 				}
319 319
 				// allow $where to be filtered
320
-				$where = apply_filters( 'FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired );
320
+				$where = apply_filters('FHEE__EEW_Upcoming_Events__widget__where', $where, $category, $show_expired);
321 321
 				// run the query
322
-				$events = EE_Registry::instance()->load_model( 'Event' )->get_all( array(
322
+				$events = EE_Registry::instance()->load_model('Event')->get_all(array(
323 323
 					$where,
324
-					'limit' => $instance['limit'] > 0 ? '0,' . $instance['limit'] : '0,10',
324
+					'limit' => $instance['limit'] > 0 ? '0,'.$instance['limit'] : '0,10',
325 325
 					'order_by' => 'Datetime.DTT_EVT_start',
326 326
 					'order' => 'ASC',
327 327
 					'group_by' => 'EVT_ID'
328 328
 				));
329 329
 
330
-				if ( ! empty( $events )) {
330
+				if ( ! empty($events)) {
331 331
 					echo '<ul class="ee-upcoming-events-widget-ul">';
332
-					foreach ( $events as $event ) {
333
-						if ( $event instanceof EE_Event && ( !is_single() || $post->ID != $event->ID() ) ) {
332
+					foreach ($events as $event) {
333
+						if ($event instanceof EE_Event && ( ! is_single() || $post->ID != $event->ID())) {
334 334
 							//printr( $event, '$event  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
335
-							echo '<li id="ee-upcoming-events-widget-li-' . $event->ID() . '" class="ee-upcoming-events-widget-li">';
335
+							echo '<li id="ee-upcoming-events-widget-li-'.$event->ID().'" class="ee-upcoming-events-widget-li">';
336 336
 							// how big is the event name ?
337
-							$name_length = strlen( $event->name() );
338
-							switch( $name_length ) {
337
+							$name_length = strlen($event->name());
338
+							switch ($name_length) {
339 339
 								case $name_length > 70 :
340
-									$len_class =  ' three-line';
340
+									$len_class = ' three-line';
341 341
 									break;
342 342
 								case $name_length > 35 :
343
-									$len_class =  ' two-line';
343
+									$len_class = ' two-line';
344 344
 									break;
345 345
 								default :
346
-									$len_class =  ' one-line';
346
+									$len_class = ' one-line';
347 347
 							}
348
-							$event_url = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event );
349
-							echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a' . $len_class . '" href="' . $event_url . '">' . $event->name() . '</a></h5>';
350
-							if ( post_password_required( $event->ID() ) ) {
351
-								$pswd_form = apply_filters( 'FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form( $event->ID() ), $event );
348
+							$event_url = apply_filters('FHEE_EEW_Upcoming_Events__widget__event_url', $event->get_permalink(), $event);
349
+							echo '<h5 class="ee-upcoming-events-widget-title-h5"><a class="ee-widget-event-name-a'.$len_class.'" href="'.$event_url.'">'.$event->name().'</a></h5>';
350
+							if (post_password_required($event->ID())) {
351
+								$pswd_form = apply_filters('FHEE_EEW_Upcoming_Events__widget__password_form', get_the_password_form($event->ID()), $event);
352 352
 								echo $pswd_form;
353 353
 							} else {
354
-								if ( has_post_thumbnail( $event->ID() ) && $image_size != 'none' ) {
355
-									echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="' . $event_url . '">' . get_the_post_thumbnail( $event->ID(), $image_size ) . '</a></div>';
354
+								if (has_post_thumbnail($event->ID()) && $image_size != 'none') {
355
+									echo '<div class="ee-upcoming-events-widget-img-dv"><a class="ee-upcoming-events-widget-img" href="'.$event_url.'">'.get_the_post_thumbnail($event->ID(), $image_size).'</a></div>';
356 356
 								}
357
-								$desc = $event->short_description( 25 );
358
-								if ( $show_dates ) {
359
-									$date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', get_option( 'date_format' ));
360
-									$time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', get_option( 'time_format' ));
361
-									$single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', get_option( 'date_format' ));
362
-									$single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', get_option( 'time_format' ));
363
-									if ( $date_range == TRUE ) {
364
-										echo espresso_event_date_range( $date_format, $time_format, $single_date_format, $single_time_format, $event->ID() );
365
-									}else{
366
-										echo espresso_list_of_event_dates( $event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit );
357
+								$desc = $event->short_description(25);
358
+								if ($show_dates) {
359
+									$date_format = apply_filters('FHEE__espresso_event_date_range__date_format', get_option('date_format'));
360
+									$time_format = apply_filters('FHEE__espresso_event_date_range__time_format', get_option('time_format'));
361
+									$single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', get_option('date_format'));
362
+									$single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', get_option('time_format'));
363
+									if ($date_range == TRUE) {
364
+										echo espresso_event_date_range($date_format, $time_format, $single_date_format, $single_time_format, $event->ID());
365
+									} else {
366
+										echo espresso_list_of_event_dates($event->ID(), $date_format, $time_format, FALSE, NULL, TRUE, TRUE, $date_limit);
367 367
 									}
368 368
 								}
369
-								if ( $show_desc && $desc ) {
370
-									echo '<p style="margin-top: .5em">' . $desc . '</p>';
369
+								if ($show_desc && $desc) {
370
+									echo '<p style="margin-top: .5em">'.$desc.'</p>';
371 371
 								}
372 372
 							}
373 373
 							echo '</li>';
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
 	 * @return string
392 392
 	 */
393 393
 	public function make_the_title_a_link($title) {
394
-	    return '<a href="' . EEH_Event_View::event_archive_url() . '">' . $title . '</a>';
394
+	    return '<a href="'.EEH_Event_View::event_archive_url().'">'.$title.'</a>';
395 395
 	}
396 396
 
397 397
 }
Please login to merge, or discard this patch.
shortcodes/espresso_events/EES_Espresso_Events.shortcode.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -104,16 +104,16 @@  discard block
 block discarded – undo
104 104
 		// grab attributes and merge with defaults, then extract
105 105
 		$attributes = array_merge( (array) $default_espresso_events_shortcode_atts, (array) $attributes );
106 106
 		$attributes = \EES_Shortcode::sanitize_attributes(
107
-		    $attributes,
108
-            // the following get sanitized/whitelisted in EEH_Event_Query
109
-            array(
110
-                'category_slug' => 'skip_sanitization',
111
-                'show_expired'  => 'skip_sanitization',
112
-                'order_by'      => 'skip_sanitization',
113
-                'month'         => 'skip_sanitization',
114
-                'sort'          => 'skip_sanitization',
115
-            )
116
-        );
107
+			$attributes,
108
+			// the following get sanitized/whitelisted in EEH_Event_Query
109
+			array(
110
+				'category_slug' => 'skip_sanitization',
111
+				'show_expired'  => 'skip_sanitization',
112
+				'order_by'      => 'skip_sanitization',
113
+				'month'         => 'skip_sanitization',
114
+				'sort'          => 'skip_sanitization',
115
+			)
116
+		);
117 117
 		// make sure we use the_excerpt()
118 118
 		add_filter( 'FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true' );
119 119
 		// apply query filters
@@ -232,9 +232,9 @@  discard block
 block discarded – undo
232 232
 
233 233
 
234 234
 	/**
235
-     * event_list_css
236
-     *
237
-     * @param string $event_list_css
235
+	 * event_list_css
236
+	 *
237
+	 * @param string $event_list_css
238 238
 	 * @return string
239 239
 	 */
240 240
 	public function event_list_css( $event_list_css = '' ) {
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -50,14 +50,14 @@  discard block
 block discarded – undo
50 50
 	 * @param WP $WP
51 51
 	 * @return    void
52 52
 	 */
53
-	public function run( WP $WP ) {
54
-		if ( did_action( 'pre_get_posts' ) && did_action( 'send_headers' ) ) {
53
+	public function run(WP $WP) {
54
+		if (did_action('pre_get_posts') && did_action('send_headers')) {
55 55
 			EED_Events_Archive::instance()->event_list();
56 56
 		} else {
57 57
 			// this will trigger the EED_Events_Archive module's event_list() method during the pre_get_posts hook point,
58 58
 			// this allows us to initialize things, enqueue assets, etc,
59 59
 			// as well, this saves an instantiation of the module in an array using 'espresso_events' as the key, so that we can retrieve it
60
-			add_action( 'pre_get_posts', array( EED_Events_Archive::instance(), 'event_list' ) );
60
+			add_action('pre_get_posts', array(EED_Events_Archive::instance(), 'event_list'));
61 61
 		}
62 62
 	}
63 63
 
@@ -79,9 +79,9 @@  discard block
 block discarded – undo
79 79
 	 *  @param 	array 	$attributes
80 80
 	 *  @return 	string
81 81
 	 */
82
-	public function process_shortcode( $attributes = array() ) {
82
+	public function process_shortcode($attributes = array()) {
83 83
 		// make sure EED_Events_Archive is setup properly
84
-		if ( apply_filters( 'FHEE__fallback_shortcode_processor__EES_Espresso_Events', FALSE )) {
84
+		if (apply_filters('FHEE__fallback_shortcode_processor__EES_Espresso_Events', FALSE)) {
85 85
 			EED_Events_Archive::instance()->event_list();
86 86
 		}
87 87
 		//set default attributes
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 			$default_espresso_events_shortcode_atts
103 103
 		);
104 104
 		// grab attributes and merge with defaults, then extract
105
-		$attributes = array_merge( (array) $default_espresso_events_shortcode_atts, (array) $attributes );
105
+		$attributes = array_merge((array) $default_espresso_events_shortcode_atts, (array) $attributes);
106 106
 		$attributes = \EES_Shortcode::sanitize_attributes(
107 107
 		    $attributes,
108 108
             // the following get sanitized/whitelisted in EEH_Event_Query
@@ -115,22 +115,22 @@  discard block
 block discarded – undo
115 115
             )
116 116
         );
117 117
 		// make sure we use the_excerpt()
118
-		add_filter( 'FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true' );
118
+		add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true');
119 119
 		// apply query filters
120
-		add_filter( 'FHEE__EEH_Event_Query__apply_query_filters', '__return_true' );
120
+		add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
121 121
 		// run the query
122 122
 		global $wp_query;
123
-		$wp_query = new EE_Event_List_Query( $attributes );
123
+		$wp_query = new EE_Event_List_Query($attributes);
124 124
 		// check what template is loaded and load filters accordingly
125
-		EED_Events_Archive::instance()->template_include( 'loop-espresso_events.php' );
125
+		EED_Events_Archive::instance()->template_include('loop-espresso_events.php');
126 126
 		// load our template
127
-		$event_list = EEH_Template::locate_template( 'loop-espresso_events.php', array(), TRUE, TRUE );
127
+		$event_list = EEH_Template::locate_template('loop-espresso_events.php', array(), TRUE, TRUE);
128 128
 		// now reset the query and postdata
129 129
 		wp_reset_query();
130 130
 		wp_reset_postdata();
131 131
 		EED_Events_Archive::remove_all_events_archive_filters();
132 132
 		// remove query filters
133
-		remove_filter( 'FHEE__EEH_Event_Query__apply_query_filters', '__return_true' );
133
+		remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
134 134
 		// pull our content from the output buffer and return it
135 135
 		return $event_list;
136 136
 	}
@@ -174,43 +174,43 @@  discard block
 block discarded – undo
174 174
 	 *
175 175
 	 * @param array $args
176 176
 	 */
177
-	public function __construct( $args = array() ) {
177
+	public function __construct($args = array()) {
178 178
 		// incoming args could be a mix of WP query args + EE shortcode args
179
-		foreach ( $args as $key =>$value ) {
180
-			$property = '_' . $key;
179
+		foreach ($args as $key =>$value) {
180
+			$property = '_'.$key;
181 181
 			// if the arg is a property of this class, then it's an EE shortcode arg
182
-			if ( property_exists( $this, $property )) {
182
+			if (property_exists($this, $property)) {
183 183
 				// set the property value
184 184
 				$this->{$property} = $value;
185 185
 				// then remove it from the array of args that will later be passed to WP_Query()
186
-				unset( $args[ $key ] );
186
+				unset($args[$key]);
187 187
 			}
188 188
 		}
189 189
 		//add query filters
190 190
 		EEH_Event_Query::add_query_filters();
191 191
 		// set params that will get used by the filters
192
-		EEH_Event_Query::set_query_params( $this->_month, $this->_category_slug, $this->_show_expired, $this->_order_by, $this->_sort );
192
+		EEH_Event_Query::set_query_params($this->_month, $this->_category_slug, $this->_show_expired, $this->_order_by, $this->_sort);
193 193
 		// first off, let's remove any filters from previous queries
194
-		remove_filter( 'FHEE__archive_espresso_events_template__upcoming_events_h1', array( $this, 'event_list_title' ));
195
-		remove_all_filters( 'FHEE__content_espresso_events__event_class' );
194
+		remove_filter('FHEE__archive_espresso_events_template__upcoming_events_h1', array($this, 'event_list_title'));
195
+		remove_all_filters('FHEE__content_espresso_events__event_class');
196 196
 		// Event List Title ?
197
-		add_filter( 'FHEE__archive_espresso_events_template__upcoming_events_h1', array( $this, 'event_list_title' ), 10, 1 );
197
+		add_filter('FHEE__archive_espresso_events_template__upcoming_events_h1', array($this, 'event_list_title'), 10, 1);
198 198
 		// add the css class
199
-		add_filter( 'FHEE__content_espresso_events__event_class', array( $this, 'event_list_css' ), 10, 1 );
199
+		add_filter('FHEE__content_espresso_events__event_class', array($this, 'event_list_css'), 10, 1);
200 200
 		// the current "page" we are viewing
201
-		$paged = max( 1, get_query_var( 'paged' ));
201
+		$paged = max(1, get_query_var('paged'));
202 202
 		// Force these args
203
-		$args = array_merge( $args, array(
203
+		$args = array_merge($args, array(
204 204
 			'post_type' => 'espresso_events',
205 205
 			'posts_per_page' => $this->_limit,
206 206
 			'update_post_term_cache' => FALSE,
207 207
 			'update_post_meta_cache' => FALSE,
208 208
 			'paged' => $paged,
209
-			'offset' => ( $paged - 1 ) * $this->_limit
209
+			'offset' => ($paged - 1) * $this->_limit
210 210
 		));
211 211
 
212 212
 		// run the query
213
-		parent::__construct( $args );
213
+		parent::__construct($args);
214 214
 	}
215 215
 
216 216
 
@@ -222,8 +222,8 @@  discard block
 block discarded – undo
222 222
 	 * @param string $event_list_title
223 223
 	 * @return string
224 224
 	 */
225
-	public function event_list_title( $event_list_title = '' ) {
226
-		if ( ! empty( $this->_title )) {
225
+	public function event_list_title($event_list_title = '') {
226
+		if ( ! empty($this->_title)) {
227 227
 			return $this->_title;
228 228
 		}
229 229
 		return $event_list_title;
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
      * @param string $event_list_css
238 238
 	 * @return string
239 239
 	 */
240
-	public function event_list_css( $event_list_css = '' ) {
241
-		$event_list_css .=  ! empty( $event_list_css ) ? ' ' : '';
242
-		$event_list_css .=  ! empty( $this->_css_class ) ? $this->_css_class : '';
243
-		$event_list_css .=  ! empty( $event_list_css ) ? ' ' : '';
244
-		$event_list_css .=  ! empty( $this->_category_slug ) ? $this->_category_slug : '';
240
+	public function event_list_css($event_list_css = '') {
241
+		$event_list_css .= ! empty($event_list_css) ? ' ' : '';
242
+		$event_list_css .= ! empty($this->_css_class) ? $this->_css_class : '';
243
+		$event_list_css .= ! empty($event_list_css) ? ' ' : '';
244
+		$event_list_css .= ! empty($this->_category_slug) ? $this->_category_slug : '';
245 245
 		return $event_list_css;
246 246
 	}
247 247
 
Please login to merge, or discard this patch.
core/helpers/EEH_Event_Query.helper.php 2 patches
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -91,9 +91,9 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public static function apply_query_filters( WP_Query $WP_Query ) {
93 93
 		return (
94
-		    isset( $WP_Query->query, $WP_Query->query['post_type'] )
95
-            && $WP_Query->query['post_type'] === 'espresso_events'
96
-        ) ||  apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ;
94
+			isset( $WP_Query->query, $WP_Query->query['post_type'] )
95
+			&& $WP_Query->query['post_type'] === 'espresso_events'
96
+		) ||  apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ;
97 97
 	}
98 98
 
99 99
 
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 */
105 105
 	public static function filter_query_parts( WP_Query $WP_Query ) {
106 106
 		// ONLY add our filters if this isn't the main wp_query,
107
-        // because if this is the main wp_query we already have
108
-        // our cpt strategies take care of adding things in.
107
+		// because if this is the main wp_query we already have
108
+		// our cpt strategies take care of adding things in.
109 109
 		if ( $WP_Query instanceof WP_Query && ! $WP_Query->is_main_query() ) {
110 110
 			// build event list query
111 111
 			add_filter( 'posts_fields', array( 'EEH_Event_Query', 'posts_fields' ), 10, 2 );
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 	 * @param string $orderby
128 128
 	 * @param string $sort
129 129
 	 */
130
-    public static function set_query_params(
131
-        $month = '',
132
-        $category = '',
133
-        $show_expired = false,
134
-        $orderby = 'start_date',
135
-        $sort = 'ASC'
136
-    ) {
130
+	public static function set_query_params(
131
+		$month = '',
132
+		$category = '',
133
+		$show_expired = false,
134
+		$orderby = 'start_date',
135
+		$sort = 'ASC'
136
+	) {
137 137
 		self::$_query_params = array();
138 138
 		EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month( $month );
139 139
 		EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug( $category );
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 	 * @return    string
152 152
 	 */
153 153
 	private static function _display_month( $month = '' ) {
154
-        return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month));
155
-    }
154
+		return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month));
155
+	}
156 156
 
157 157
 
158 158
 
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
 	private static function _show_expired( $show_expired = false ) {
178 178
 		// override default expired option if set via filter
179 179
 		return filter_var(
180
-		    EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired),
181
-            FILTER_VALIDATE_BOOLEAN
182
-        );
180
+			EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired),
181
+			FILTER_VALIDATE_BOOLEAN
182
+		);
183 183
 	}
184 184
 
185 185
 
@@ -193,8 +193,8 @@  discard block
 block discarded – undo
193 193
 	private static function _orderby( $orderby = 'start_date' ) {
194 194
 		$event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby);
195 195
 		$event_query_orderby = is_array( $event_query_orderby )
196
-            ? $event_query_orderby
197
-            : explode( ',', $event_query_orderby );
196
+			? $event_query_orderby
197
+			: explode( ',', $event_query_orderby );
198 198
 		$event_query_orderby = array_map( 'trim', $event_query_orderby );
199 199
 		$event_query_orderby = array_map( 'sanitize_text_field', $event_query_orderby );
200 200
 		return $event_query_orderby;
@@ -211,8 +211,8 @@  discard block
 block discarded – undo
211 211
 	private static function _sort( $sort = 'ASC' ) {
212 212
 		$sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort);
213 213
 		return in_array( $sort, array( 'ASC', 'asc', 'DESC', 'desc' ), true)
214
-            ? strtoupper( $sort )
215
-            : 'ASC';
214
+			? strtoupper( $sort )
215
+			: 'ASC';
216 216
 	}
217 217
 
218 218
 
@@ -235,14 +235,14 @@  discard block
 block discarded – undo
235 235
 
236 236
 
237 237
 
238
-    /**
239
-     *    posts_fields
240
-     *
241
-     * @param          $SQL
242
-     * @param WP_Query $wp_query
243
-     * @return    string
244
-     * @throws \EE_Error
245
-     */
238
+	/**
239
+	 *    posts_fields
240
+	 *
241
+	 * @param          $SQL
242
+	 * @param WP_Query $wp_query
243
+	 * @return    string
244
+	 * @throws \EE_Error
245
+	 */
246 246
 	public static function posts_fields( $SQL, WP_Query $wp_query ) {
247 247
 		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
248 248
 			// adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
@@ -253,13 +253,13 @@  discard block
 block discarded – undo
253 253
 
254 254
 
255 255
 
256
-    /**
257
-     *    posts_join_sql_for_terms
258
-     *
259
-     * @param array $orderby_params
260
-     * @return    string
261
-     * @throws \EE_Error
262
-     */
256
+	/**
257
+	 *    posts_join_sql_for_terms
258
+	 *
259
+	 * @param array $orderby_params
260
+	 * @return    string
261
+	 * @throws \EE_Error
262
+	 */
263 263
 	public static function posts_fields_sql_for_orderby( $orderby_params = array() ) {
264 264
 		$SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ' ;
265 265
 		foreach( (array)$orderby_params as $orderby ) {
@@ -292,14 +292,14 @@  discard block
 block discarded – undo
292 292
 
293 293
 
294 294
 
295
-    /**
296
-     *    posts_join
297
-     *
298
-     * @param string   $SQL
299
-     * @param WP_Query $wp_query
300
-     * @return    string
301
-     * @throws \EE_Error
302
-     */
295
+	/**
296
+	 *    posts_join
297
+	 *
298
+	 * @param string   $SQL
299
+	 * @param WP_Query $wp_query
300
+	 * @return    string
301
+	 * @throws \EE_Error
302
+	 */
303 303
 	public static function posts_join( $SQL = '', WP_Query $wp_query ) {
304 304
 		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
305 305
 			// Category
@@ -312,14 +312,14 @@  discard block
 block discarded – undo
312 312
 
313 313
 
314 314
 
315
-    /**
316
-     *    posts_join_sql_for_terms
317
-     *
318
-     * @param string     $SQL
319
-     * @param    boolean $show_expired if TRUE, then displayed past events
320
-     * @return string
321
-     * @throws \EE_Error
322
-     */
315
+	/**
316
+	 *    posts_join_sql_for_terms
317
+	 *
318
+	 * @param string     $SQL
319
+	 * @param    boolean $show_expired if TRUE, then displayed past events
320
+	 * @return string
321
+	 * @throws \EE_Error
322
+	 */
323 323
 	public static function posts_join_sql_for_show_expired( $SQL = '', $show_expired = FALSE ) {
324 324
 		if ( ! $show_expired ) {
325 325
 			$join = EEM_Event::instance()->table() . '.ID = ';
@@ -353,24 +353,24 @@  discard block
 block discarded – undo
353 353
 
354 354
 
355 355
 
356
-    /**
357
-     *    posts_join_for_orderby
358
-     *    usage:  $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params );
359
-     *
360
-     * @param    string $SQL
361
-     * @param    array  $orderby_params
362
-     * @return    string
363
-     * @throws \EE_Error
364
-     */
356
+	/**
357
+	 *    posts_join_for_orderby
358
+	 *    usage:  $SQL .= EEH_Event_Query::posts_join_for_orderby( $orderby_params );
359
+	 *
360
+	 * @param    string $SQL
361
+	 * @param    array  $orderby_params
362
+	 * @return    string
363
+	 * @throws \EE_Error
364
+	 */
365 365
 	public static function posts_join_for_orderby( $SQL = '', $orderby_params = array() ) {
366 366
 		foreach ( (array)$orderby_params as $orderby ) {
367 367
 			switch ( $orderby ) {
368 368
 				case 'ticket_start' :
369 369
 				case 'ticket_end' :
370 370
 					$SQL .= EEH_Event_Query::_posts_join_for_datetime(
371
-					    $SQL,
372
-                        EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
373
-                    );
371
+						$SQL,
372
+						EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
373
+					);
374 374
 					$SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table();
375 375
 					$SQL .= ' ON (';
376 376
 					$SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
@@ -398,14 +398,14 @@  discard block
 block discarded – undo
398 398
 
399 399
 
400 400
 
401
-    /**
402
-     *    _posts_join_for_datetime
403
-     *
404
-     * @param string $SQL
405
-     * @param string $join
406
-     * @return string
407
-     * @throws \EE_Error
408
-     */
401
+	/**
402
+	 *    _posts_join_for_datetime
403
+	 *
404
+	 * @param string $SQL
405
+	 * @param string $join
406
+	 * @return string
407
+	 * @throws \EE_Error
408
+	 */
409 409
 	protected static function _posts_join_for_datetime( $SQL = '', $join = '' ) {
410 410
 		if ( ! empty( $join )) {
411 411
 			$join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
@@ -418,13 +418,13 @@  discard block
 block discarded – undo
418 418
 
419 419
 
420 420
 
421
-    /**
422
-     *    _posts_join_for_event_venue
423
-     *
424
-     * @param string $SQL
425
-     * @return string
426
-     * @throws \EE_Error
427
-     */
421
+	/**
422
+	 *    _posts_join_for_event_venue
423
+	 *
424
+	 * @param string $SQL
425
+	 * @return string
426
+	 * @throws \EE_Error
427
+	 */
428 428
 	protected static function _posts_join_for_event_venue( $SQL = '' ) {
429 429
 		// Event Venue table name
430 430
 		$event_venue_table = EEM_Event_Venue::instance()->table();
@@ -454,13 +454,13 @@  discard block
 block discarded – undo
454 454
 
455 455
 
456 456
 
457
-    /**
458
-     *    _posts_join_for_venue_state
459
-     *
460
-     * @param string $SQL
461
-     * @return string
462
-     * @throws \EE_Error
463
-     */
457
+	/**
458
+	 *    _posts_join_for_venue_state
459
+	 *
460
+	 * @param string $SQL
461
+	 * @return string
462
+	 * @throws \EE_Error
463
+	 */
464 464
 	protected static function _posts_join_for_venue_state( $SQL = '' ) {
465 465
 		// Venue Meta table name
466 466
 		$venue_meta_table = EEM_Venue::instance()->second_table();
@@ -484,14 +484,14 @@  discard block
 block discarded – undo
484 484
 
485 485
 
486 486
 
487
-    /**
488
-     *    posts_where
489
-     *
490
-     * @param string   $SQL
491
-     * @param WP_Query $wp_query
492
-     * @return    string
493
-     * @throws \EE_Error
494
-     */
487
+	/**
488
+	 *    posts_where
489
+	 *
490
+	 * @param string   $SQL
491
+	 * @param WP_Query $wp_query
492
+	 * @return    string
493
+	 * @throws \EE_Error
494
+	 */
495 495
 	public static function posts_where( $SQL = '', WP_Query $wp_query ) {
496 496
 		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
497 497
 			// Show Expired ?
@@ -506,17 +506,17 @@  discard block
 block discarded – undo
506 506
 
507 507
 
508 508
 
509
-    /**
510
-     *    posts_where_sql_for_show_expired
511
-     *
512
-     * @param    boolean $show_expired if TRUE, then displayed past events
513
-     * @return    string
514
-     * @throws \EE_Error
515
-     */
509
+	/**
510
+	 *    posts_where_sql_for_show_expired
511
+	 *
512
+	 * @param    boolean $show_expired if TRUE, then displayed past events
513
+	 * @return    string
514
+	 * @throws \EE_Error
515
+	 */
516 516
 	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
517 517
 		return ! $show_expired
518
-            ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' '
519
-            : '';
518
+			? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' '
519
+			: '';
520 520
 	}
521 521
 
522 522
 
@@ -531,19 +531,19 @@  discard block
 block discarded – undo
531 531
 		global $wpdb;
532 532
 		$event_category_slug = esc_sql($event_category_slug);
533 533
 		return ! empty( $event_category_slug )
534
-            ? " AND {$wpdb->terms}.slug = '{$event_category_slug}' "
535
-            : '';
534
+			? " AND {$wpdb->terms}.slug = '{$event_category_slug}' "
535
+			: '';
536 536
 	}
537 537
 
538 538
 
539 539
 
540
-    /**
541
-     *    posts_where_sql_for_event_list_month
542
-     *
543
-     * @param    boolean $month
544
-     * @return    string
545
-     * @throws \EE_Error
546
-     */
540
+	/**
541
+	 *    posts_where_sql_for_event_list_month
542
+	 *
543
+	 * @param    boolean $month
544
+	 * @return    string
545
+	 * @throws \EE_Error
546
+	 */
547 547
 	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
548 548
 		$SQL = '';
549 549
 		if ( ! empty( $month ) ) {
@@ -558,55 +558,55 @@  discard block
 block discarded – undo
558 558
 
559 559
 
560 560
 
561
-    /**
562
-     *    posts_orderby
563
-     *
564
-     * @param string   $SQL
565
-     * @param WP_Query $wp_query
566
-     * @return    string
567
-     * @throws \EE_Error
568
-     */
561
+	/**
562
+	 *    posts_orderby
563
+	 *
564
+	 * @param string   $SQL
565
+	 * @param WP_Query $wp_query
566
+	 * @return    string
567
+	 * @throws \EE_Error
568
+	 */
569 569
 	public static function posts_orderby( $SQL = '', WP_Query $wp_query ) {
570 570
 		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
571 571
 			$SQL = EEH_Event_Query::posts_orderby_sql(
572
-			    EEH_Event_Query::$_event_query_orderby,
573
-                EEH_Event_Query::$_event_query_sort
574
-            );
572
+				EEH_Event_Query::$_event_query_orderby,
573
+				EEH_Event_Query::$_event_query_sort
574
+			);
575 575
 		}
576 576
 		return $SQL;
577 577
 	}
578 578
 
579 579
 
580 580
 
581
-    /**
582
-     *    posts_orderby_sql
583
-     *    possible parameters:
584
-     *    ID
585
-     *    start_date
586
-     *    end_date
587
-     *    event_name
588
-     *    category_slug
589
-     *    ticket_start
590
-     *    ticket_end
591
-     *    venue_title
592
-     *    city
593
-     *    state
594
-     *    **IMPORTANT**
595
-     *    make sure to also send the $orderby_params array to the posts_join_for_orderby() method
596
-     *    or else some of the table references below will result in MySQL errors
597
-     *
598
-     * @param array|bool $orderby_params
599
-     * @param string     $sort
600
-     * @return string
601
-     * @throws \EE_Error
602
-     */
581
+	/**
582
+	 *    posts_orderby_sql
583
+	 *    possible parameters:
584
+	 *    ID
585
+	 *    start_date
586
+	 *    end_date
587
+	 *    event_name
588
+	 *    category_slug
589
+	 *    ticket_start
590
+	 *    ticket_end
591
+	 *    venue_title
592
+	 *    city
593
+	 *    state
594
+	 *    **IMPORTANT**
595
+	 *    make sure to also send the $orderby_params array to the posts_join_for_orderby() method
596
+	 *    or else some of the table references below will result in MySQL errors
597
+	 *
598
+	 * @param array|bool $orderby_params
599
+	 * @param string     $sort
600
+	 * @return string
601
+	 * @throws \EE_Error
602
+	 */
603 603
 	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
604 604
 		global $wpdb;
605 605
 		$SQL = '';
606 606
 		$counter = 0;
607 607
 		$sort = in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
608
-            ? strtoupper($sort)
609
-            : 'ASC';
608
+			? strtoupper($sort)
609
+			: 'ASC';
610 610
 		//make sure 'orderby' is set in query params
611 611
 		if ( ! isset( self::$_query_params['orderby'] )) {
612 612
 			self::$_query_params['orderby'] = array();
Please login to merge, or discard this patch.
Spacing   +119 added lines, -119 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1
-<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
-	exit( 'No direct script access allowed' );
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 	 */
79 79
 	public static function add_query_filters() {
80 80
 		//add query filters
81
-		add_action( 'pre_get_posts', array( 'EEH_Event_Query', 'filter_query_parts' ), 10, 1 );
81
+		add_action('pre_get_posts', array('EEH_Event_Query', 'filter_query_parts'), 10, 1);
82 82
 	}
83 83
 
84 84
 
@@ -89,11 +89,11 @@  discard block
 block discarded – undo
89 89
 	 * @param \WP_Query $WP_Query
90 90
 	 * @return bool
91 91
 	 */
92
-	public static function apply_query_filters( WP_Query $WP_Query ) {
92
+	public static function apply_query_filters(WP_Query $WP_Query) {
93 93
 		return (
94
-		    isset( $WP_Query->query, $WP_Query->query['post_type'] )
94
+		    isset($WP_Query->query, $WP_Query->query['post_type'])
95 95
             && $WP_Query->query['post_type'] === 'espresso_events'
96
-        ) ||  apply_filters( 'FHEE__EEH_Event_Query__apply_query_filters', false ) ;
96
+        ) || apply_filters('FHEE__EEH_Event_Query__apply_query_filters', false);
97 97
 	}
98 98
 
99 99
 
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
 	 *
103 103
 	 * @param \WP_Query $WP_Query
104 104
 	 */
105
-	public static function filter_query_parts( WP_Query $WP_Query ) {
105
+	public static function filter_query_parts(WP_Query $WP_Query) {
106 106
 		// ONLY add our filters if this isn't the main wp_query,
107 107
         // because if this is the main wp_query we already have
108 108
         // our cpt strategies take care of adding things in.
109
-		if ( $WP_Query instanceof WP_Query && ! $WP_Query->is_main_query() ) {
109
+		if ($WP_Query instanceof WP_Query && ! $WP_Query->is_main_query()) {
110 110
 			// build event list query
111
-			add_filter( 'posts_fields', array( 'EEH_Event_Query', 'posts_fields' ), 10, 2 );
112
-			add_filter( 'posts_join', array( 'EEH_Event_Query', 'posts_join' ), 10, 2 );
113
-			add_filter( 'posts_where', array( 'EEH_Event_Query', 'posts_where' ), 10, 2 );
114
-			add_filter( 'posts_orderby', array( 'EEH_Event_Query', 'posts_orderby' ), 10, 2 );
115
-			add_filter( 'posts_clauses_request', array( 'EEH_Event_Query', 'posts_clauses' ), 10, 2 );
111
+			add_filter('posts_fields', array('EEH_Event_Query', 'posts_fields'), 10, 2);
112
+			add_filter('posts_join', array('EEH_Event_Query', 'posts_join'), 10, 2);
113
+			add_filter('posts_where', array('EEH_Event_Query', 'posts_where'), 10, 2);
114
+			add_filter('posts_orderby', array('EEH_Event_Query', 'posts_orderby'), 10, 2);
115
+			add_filter('posts_clauses_request', array('EEH_Event_Query', 'posts_clauses'), 10, 2);
116 116
 		}
117 117
 	}
118 118
 
@@ -135,11 +135,11 @@  discard block
 block discarded – undo
135 135
         $sort = 'ASC'
136 136
     ) {
137 137
 		self::$_query_params = array();
138
-		EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month( $month );
139
-		EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug( $category );
140
-		EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired( $show_expired );
141
-		EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby( $orderby );
142
-		EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort( $sort );
138
+		EEH_Event_Query::$_event_query_month = EEH_Event_Query::_display_month($month);
139
+		EEH_Event_Query::$_event_query_category = EEH_Event_Query::_event_category_slug($category);
140
+		EEH_Event_Query::$_event_query_show_expired = EEH_Event_Query::_show_expired($show_expired);
141
+		EEH_Event_Query::$_event_query_orderby = EEH_Event_Query::_orderby($orderby);
142
+		EEH_Event_Query::$_event_query_sort = EEH_Event_Query::_sort($sort);
143 143
 	}
144 144
 
145 145
 
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 * @param string $month
151 151
 	 * @return    string
152 152
 	 */
153
-	private static function _display_month( $month = '' ) {
153
+	private static function _display_month($month = '') {
154 154
         return sanitize_text_field(EE_Registry::instance()->REQ->get('event_query_month', $month));
155 155
     }
156 156
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * @param string $category
163 163
 	 * @return    string
164 164
 	 */
165
-	private static function _event_category_slug( $category = '' ) {
165
+	private static function _event_category_slug($category = '') {
166 166
 		return sanitize_title_with_dashes(EE_Registry::instance()->REQ->get('event_query_category', $category));
167 167
 	}
168 168
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @param bool $show_expired
175 175
 	 * @return    boolean
176 176
 	 */
177
-	private static function _show_expired( $show_expired = false ) {
177
+	private static function _show_expired($show_expired = false) {
178 178
 		// override default expired option if set via filter
179 179
 		return filter_var(
180 180
 		    EE_Registry::instance()->REQ->get('event_query_show_expired', $show_expired),
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
 	 * @param    string $orderby
191 191
 	 * @return    array
192 192
 	 */
193
-	private static function _orderby( $orderby = 'start_date' ) {
193
+	private static function _orderby($orderby = 'start_date') {
194 194
 		$event_query_orderby = EE_Registry::instance()->REQ->get('event_query_orderby', $orderby);
195
-		$event_query_orderby = is_array( $event_query_orderby )
195
+		$event_query_orderby = is_array($event_query_orderby)
196 196
             ? $event_query_orderby
197
-            : explode( ',', $event_query_orderby );
198
-		$event_query_orderby = array_map( 'trim', $event_query_orderby );
199
-		$event_query_orderby = array_map( 'sanitize_text_field', $event_query_orderby );
197
+            : explode(',', $event_query_orderby);
198
+		$event_query_orderby = array_map('trim', $event_query_orderby);
199
+		$event_query_orderby = array_map('sanitize_text_field', $event_query_orderby);
200 200
 		return $event_query_orderby;
201 201
 	}
202 202
 
@@ -208,10 +208,10 @@  discard block
 block discarded – undo
208 208
 	 * @param string $sort
209 209
 	 * @return string
210 210
 	 */
211
-	private static function _sort( $sort = 'ASC' ) {
211
+	private static function _sort($sort = 'ASC') {
212 212
 		$sort = EE_Registry::instance()->REQ->get('event_query_sort', $sort);
213
-		return in_array( $sort, array( 'ASC', 'asc', 'DESC', 'desc' ), true)
214
-            ? strtoupper( $sort )
213
+		return in_array($sort, array('ASC', 'asc', 'DESC', 'desc'), true)
214
+            ? strtoupper($sort)
215 215
             : 'ASC';
216 216
 	}
217 217
 
@@ -225,10 +225,10 @@  discard block
 block discarded – undo
225 225
 	 *
226 226
 	 * @return array   array of clauses
227 227
 	 */
228
-	public static function posts_clauses( $clauses, WP_Query $wp_query ) {
229
-		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
228
+	public static function posts_clauses($clauses, WP_Query $wp_query) {
229
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
230 230
 			global $wpdb;
231
-			$clauses['groupby'] = $wpdb->posts . '.ID ';
231
+			$clauses['groupby'] = $wpdb->posts.'.ID ';
232 232
 		}
233 233
 		return $clauses;
234 234
 	}
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
      * @return    string
244 244
      * @throws \EE_Error
245 245
      */
246
-	public static function posts_fields( $SQL, WP_Query $wp_query ) {
247
-		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
246
+	public static function posts_fields($SQL, WP_Query $wp_query) {
247
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
248 248
 			// adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
249
-			$SQL .= EEH_Event_Query::posts_fields_sql_for_orderby( EEH_Event_Query::$_event_query_orderby );
249
+			$SQL .= EEH_Event_Query::posts_fields_sql_for_orderby(EEH_Event_Query::$_event_query_orderby);
250 250
 		}
251 251
 		return $SQL;
252 252
 	}
@@ -260,29 +260,29 @@  discard block
 block discarded – undo
260 260
      * @return    string
261 261
      * @throws \EE_Error
262 262
      */
263
-	public static function posts_fields_sql_for_orderby( $orderby_params = array() ) {
264
-		$SQL = ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ' ;
265
-		foreach( (array)$orderby_params as $orderby ) {
266
-			switch ( $orderby ) {
263
+	public static function posts_fields_sql_for_orderby($orderby_params = array()) {
264
+		$SQL = ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date ';
265
+		foreach ((array) $orderby_params as $orderby) {
266
+			switch ($orderby) {
267 267
 
268 268
 				case 'ticket_start' :
269
-					$SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_start_date' ;
269
+					$SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_start_date';
270 270
 					break;
271 271
 
272 272
 				case 'ticket_end' :
273
-					$SQL .= ', ' . EEM_Ticket::instance()->table() . '.TKT_end_date' ;
273
+					$SQL .= ', '.EEM_Ticket::instance()->table().'.TKT_end_date';
274 274
 					break;
275 275
 
276 276
 				case 'venue_title' :
277
-					$SQL .= ', Venue.post_title AS venue_title' ;
277
+					$SQL .= ', Venue.post_title AS venue_title';
278 278
 					break;
279 279
 
280 280
 				case 'city' :
281
-					$SQL .= ', ' . EEM_Venue::instance()->second_table() . '.VNU_city' ;
281
+					$SQL .= ', '.EEM_Venue::instance()->second_table().'.VNU_city';
282 282
 					break;
283 283
 
284 284
 				case 'state' :
285
-					$SQL .= ', ' . EEM_State::instance()->table() . '.STA_name' ;
285
+					$SQL .= ', '.EEM_State::instance()->table().'.STA_name';
286 286
 					break;
287 287
 
288 288
 			}
@@ -300,12 +300,12 @@  discard block
 block discarded – undo
300 300
      * @return    string
301 301
      * @throws \EE_Error
302 302
      */
303
-	public static function posts_join( $SQL = '', WP_Query $wp_query ) {
304
-		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
303
+	public static function posts_join($SQL = '', WP_Query $wp_query) {
304
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
305 305
 			// Category
306
-			$SQL = EEH_Event_Query::posts_join_sql_for_show_expired( $SQL, EEH_Event_Query::$_event_query_show_expired );
307
-			$SQL = EEH_Event_Query::posts_join_sql_for_terms( $SQL, EEH_Event_Query::$_event_query_category );
308
-			$SQL = EEH_Event_Query::posts_join_for_orderby( $SQL, EEH_Event_Query::$_event_query_orderby );
306
+			$SQL = EEH_Event_Query::posts_join_sql_for_show_expired($SQL, EEH_Event_Query::$_event_query_show_expired);
307
+			$SQL = EEH_Event_Query::posts_join_sql_for_terms($SQL, EEH_Event_Query::$_event_query_category);
308
+			$SQL = EEH_Event_Query::posts_join_for_orderby($SQL, EEH_Event_Query::$_event_query_orderby);
309 309
 		}
310 310
 		return $SQL;
311 311
 	}
@@ -320,13 +320,13 @@  discard block
 block discarded – undo
320 320
      * @return string
321 321
      * @throws \EE_Error
322 322
      */
323
-	public static function posts_join_sql_for_show_expired( $SQL = '', $show_expired = FALSE ) {
324
-		if ( ! $show_expired ) {
325
-			$join = EEM_Event::instance()->table() . '.ID = ';
326
-			$join .= EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
323
+	public static function posts_join_sql_for_show_expired($SQL = '', $show_expired = FALSE) {
324
+		if ( ! $show_expired) {
325
+			$join = EEM_Event::instance()->table().'.ID = ';
326
+			$join .= EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name();
327 327
 			// don't add if this is already in the SQL
328
-			if ( strpos( $SQL, $join ) === FALSE ) {
329
-				$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' ) ';
328
+			if (strpos($SQL, $join) === FALSE) {
329
+				$SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' ) ';
330 330
 			}
331 331
 		}
332 332
 		return $SQL;
@@ -341,8 +341,8 @@  discard block
 block discarded – undo
341 341
 	 * @param 	string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet
342 342
 	 * @return 	string
343 343
 	 */
344
-	public static function posts_join_sql_for_terms( $SQL = '', $join_terms = '' ) {
345
-		if ( ! empty( $join_terms ) ) {
344
+	public static function posts_join_sql_for_terms($SQL = '', $join_terms = '') {
345
+		if ( ! empty($join_terms)) {
346 346
 			global $wpdb;
347 347
 			$SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
348 348
 			$SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)";
@@ -362,33 +362,33 @@  discard block
 block discarded – undo
362 362
      * @return    string
363 363
      * @throws \EE_Error
364 364
      */
365
-	public static function posts_join_for_orderby( $SQL = '', $orderby_params = array() ) {
366
-		foreach ( (array)$orderby_params as $orderby ) {
367
-			switch ( $orderby ) {
365
+	public static function posts_join_for_orderby($SQL = '', $orderby_params = array()) {
366
+		foreach ((array) $orderby_params as $orderby) {
367
+			switch ($orderby) {
368 368
 				case 'ticket_start' :
369 369
 				case 'ticket_end' :
370 370
 					$SQL .= EEH_Event_Query::_posts_join_for_datetime(
371 371
 					    $SQL,
372
-                        EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Datetime::instance()->primary_key_name()
372
+                        EEM_Datetime_Ticket::instance()->table().'.'.EEM_Datetime::instance()->primary_key_name()
373 373
                     );
374
-					$SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table();
374
+					$SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table();
375 375
 					$SQL .= ' ON (';
376
-					$SQL .= EEM_Datetime_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
376
+					$SQL .= EEM_Datetime_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name();
377 377
 					$SQL .= ' = ';
378
-					$SQL .= EEM_Ticket::instance()->table() . '.' . EEM_Ticket::instance()->primary_key_name();
379
-					$SQL .=  ' )';
378
+					$SQL .= EEM_Ticket::instance()->table().'.'.EEM_Ticket::instance()->primary_key_name();
379
+					$SQL .= ' )';
380 380
 					break;
381 381
 				case 'venue_title' :
382 382
 				case 'city' :
383
-					$SQL .= EEH_Event_Query::_posts_join_for_event_venue( $SQL );
383
+					$SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
384 384
 					break;
385 385
 				case 'state' :
386
-					$SQL .= EEH_Event_Query::_posts_join_for_event_venue( $SQL );
387
-					$SQL .= EEH_Event_Query::_posts_join_for_venue_state( $SQL );
386
+					$SQL .= EEH_Event_Query::_posts_join_for_event_venue($SQL);
387
+					$SQL .= EEH_Event_Query::_posts_join_for_venue_state($SQL);
388 388
 					break;
389 389
 				case 'start_date' :
390 390
 				default :
391
-					$SQL .= EEH_Event_Query::_posts_join_for_datetime( $SQL, EEM_Event::instance()->table() . '.ID' );
391
+					$SQL .= EEH_Event_Query::_posts_join_for_datetime($SQL, EEM_Event::instance()->table().'.ID');
392 392
 					break;
393 393
 
394 394
 			}
@@ -406,11 +406,11 @@  discard block
 block discarded – undo
406 406
      * @return string
407 407
      * @throws \EE_Error
408 408
      */
409
-	protected static function _posts_join_for_datetime( $SQL = '', $join = '' ) {
410
-		if ( ! empty( $join )) {
411
-			$join .= ' = ' . EEM_Datetime::instance()->table() . '.' . EEM_Event::instance()->primary_key_name();
412
-			if ( strpos( $SQL, $join ) === FALSE ) {
413
-				return ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . $join . ' )';
409
+	protected static function _posts_join_for_datetime($SQL = '', $join = '') {
410
+		if ( ! empty($join)) {
411
+			$join .= ' = '.EEM_Datetime::instance()->table().'.'.EEM_Event::instance()->primary_key_name();
412
+			if (strpos($SQL, $join) === FALSE) {
413
+				return ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.$join.' )';
414 414
 			}
415 415
 		}
416 416
 		return '';
@@ -425,14 +425,14 @@  discard block
 block discarded – undo
425 425
      * @return string
426 426
      * @throws \EE_Error
427 427
      */
428
-	protected static function _posts_join_for_event_venue( $SQL = '' ) {
428
+	protected static function _posts_join_for_event_venue($SQL = '') {
429 429
 		// Event Venue table name
430 430
 		$event_venue_table = EEM_Event_Venue::instance()->table();
431 431
 		// generate conditions for:  Event <=> Event Venue  JOIN clause
432
-		$event_to_event_venue_join = EEM_Event::instance()->table() . '.ID = ';
433
-		$event_to_event_venue_join .= $event_venue_table . '.' . EEM_Event::instance()->primary_key_name();
432
+		$event_to_event_venue_join = EEM_Event::instance()->table().'.ID = ';
433
+		$event_to_event_venue_join .= $event_venue_table.'.'.EEM_Event::instance()->primary_key_name();
434 434
 		// don't add joins if they have already been added
435
-		if ( strpos( $SQL, $event_to_event_venue_join ) === FALSE ) {
435
+		if (strpos($SQL, $event_to_event_venue_join) === FALSE) {
436 436
 			// Venue table name
437 437
 			$venue_table = EEM_Venue::instance()->table();
438 438
 			// Venue table pk
@@ -445,10 +445,10 @@  discard block
 block discarded – undo
445 445
 			$venue_SQL .= " LEFT JOIN $venue_table as Venue ON ( $event_venue_table.$venue_table_pk = Venue.ID )";
446 446
 			// generate JOIN clause for: Venue <=> Venue Meta
447 447
 			$venue_SQL .= " LEFT JOIN $venue_meta_table ON ( Venue.ID = $venue_meta_table.$venue_table_pk )";
448
-			unset( $event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table );
448
+			unset($event_venue_table, $event_to_event_venue_join, $venue_table, $venue_table_pk, $venue_meta_table);
449 449
 			return $venue_SQL;
450 450
 		}
451
-		unset( $event_venue_table, $event_to_event_venue_join );
451
+		unset($event_venue_table, $event_to_event_venue_join);
452 452
 		return '';
453 453
 	}
454 454
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
      * @return string
462 462
      * @throws \EE_Error
463 463
      */
464
-	protected static function _posts_join_for_venue_state( $SQL = '' ) {
464
+	protected static function _posts_join_for_venue_state($SQL = '') {
465 465
 		// Venue Meta table name
466 466
 		$venue_meta_table = EEM_Venue::instance()->second_table();
467 467
 		// State table name
@@ -469,16 +469,16 @@  discard block
 block discarded – undo
469 469
 		// State table pk
470 470
 		$state_table_pk = EEM_State::instance()->primary_key_name();
471 471
 		// verify vars
472
-		if ( $venue_meta_table && $state_table && $state_table_pk ) {
472
+		if ($venue_meta_table && $state_table && $state_table_pk) {
473 473
 			// like: wp_esp_venue_meta.STA_ID = wp_esp_state.STA_ID
474 474
 			$join = "$venue_meta_table.$state_table_pk = $state_table.$state_table_pk";
475 475
 			// don't add join if it has already been added
476
-			if ( strpos( $SQL, $join ) === FALSE ) {
477
-				unset( $state_table_pk, $venue_meta_table, $venue_table_pk );
476
+			if (strpos($SQL, $join) === FALSE) {
477
+				unset($state_table_pk, $venue_meta_table, $venue_table_pk);
478 478
 				return " LEFT JOIN $state_table ON ( $join )";
479 479
 			}
480 480
 		}
481
-		unset( $join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk );
481
+		unset($join, $state_table, $state_table_pk, $venue_meta_table, $venue_table_pk);
482 482
 		return '';
483 483
 	}
484 484
 
@@ -492,14 +492,14 @@  discard block
 block discarded – undo
492 492
      * @return    string
493 493
      * @throws \EE_Error
494 494
      */
495
-	public static function posts_where( $SQL = '', WP_Query $wp_query ) {
496
-		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
495
+	public static function posts_where($SQL = '', WP_Query $wp_query) {
496
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
497 497
 			// Show Expired ?
498
-			$SQL .= EEH_Event_Query::posts_where_sql_for_show_expired( EEH_Event_Query::$_event_query_show_expired );
498
+			$SQL .= EEH_Event_Query::posts_where_sql_for_show_expired(EEH_Event_Query::$_event_query_show_expired);
499 499
 			// Category
500
-			$SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug( EEH_Event_Query::$_event_query_category );
500
+			$SQL .= EEH_Event_Query::posts_where_sql_for_event_category_slug(EEH_Event_Query::$_event_query_category);
501 501
 			// Start Date
502
-			$SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month( EEH_Event_Query::$_event_query_month );
502
+			$SQL .= EEH_Event_Query::posts_where_sql_for_event_list_month(EEH_Event_Query::$_event_query_month);
503 503
 		}
504 504
 		return $SQL;
505 505
 	}
@@ -513,9 +513,9 @@  discard block
 block discarded – undo
513 513
      * @return    string
514 514
      * @throws \EE_Error
515 515
      */
516
-	public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) {
516
+	public static function posts_where_sql_for_show_expired($show_expired = FALSE) {
517 517
 		return ! $show_expired
518
-            ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > \'' . current_time( 'mysql', TRUE ) . '\' '
518
+            ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > \''.current_time('mysql', TRUE).'\' '
519 519
             : '';
520 520
 	}
521 521
 
@@ -527,10 +527,10 @@  discard block
 block discarded – undo
527 527
 	 * @param    boolean $event_category_slug
528 528
 	 * @return    string
529 529
 	 */
530
-	public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) {
530
+	public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) {
531 531
 		global $wpdb;
532 532
 		$event_category_slug = esc_sql($event_category_slug);
533
-		return ! empty( $event_category_slug )
533
+		return ! empty($event_category_slug)
534 534
             ? " AND {$wpdb->terms}.slug = '{$event_category_slug}' "
535 535
             : '';
536 536
 	}
@@ -544,16 +544,16 @@  discard block
 block discarded – undo
544 544
      * @return    string
545 545
      * @throws \EE_Error
546 546
      */
547
-	public static function posts_where_sql_for_event_list_month( $month = NULL ) {
547
+	public static function posts_where_sql_for_event_list_month($month = NULL) {
548 548
 		$SQL = '';
549
-		if ( ! empty( $month ) ) {
549
+		if ( ! empty($month)) {
550 550
 			$datetime_table = EEM_Datetime::instance()->table();
551 551
 			// event start date is LESS than the end of the month ( so nothing that doesn't start until next month )
552 552
 			$SQL = " AND {$datetime_table}.DTT_EVT_start <= '";
553
-			$SQL .= date( 'Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "'";
553
+			$SQL .= date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month))."'";
554 554
 			// event end date is GREATER than the start of the month ( so nothing that ended before this month )
555 555
 			$SQL .= " AND {$datetime_table}.DTT_EVT_end >= '";
556
-			$SQL .= date( 'Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . "' ";
556
+			$SQL .= date('Y-m-01 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month))."' ";
557 557
 		}
558 558
 		return $SQL;
559 559
 	}
@@ -568,8 +568,8 @@  discard block
 block discarded – undo
568 568
      * @return    string
569 569
      * @throws \EE_Error
570 570
      */
571
-	public static function posts_orderby( $SQL = '', WP_Query $wp_query ) {
572
-		if ( EEH_Event_Query::apply_query_filters( $wp_query ) ) {
571
+	public static function posts_orderby($SQL = '', WP_Query $wp_query) {
572
+		if (EEH_Event_Query::apply_query_filters($wp_query)) {
573 573
 			$SQL = EEH_Event_Query::posts_orderby_sql(
574 574
 			    EEH_Event_Query::$_event_query_orderby,
575 575
                 EEH_Event_Query::$_event_query_sort
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
      * @return string
603 603
      * @throws \EE_Error
604 604
      */
605
-	public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) {
605
+	public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') {
606 606
 		global $wpdb;
607 607
 		$SQL = '';
608 608
 		$counter = 0;
@@ -610,58 +610,58 @@  discard block
 block discarded – undo
610 610
             ? strtoupper($sort)
611 611
             : 'ASC';
612 612
 		//make sure 'orderby' is set in query params
613
-		if ( ! isset( self::$_query_params['orderby'] )) {
613
+		if ( ! isset(self::$_query_params['orderby'])) {
614 614
 			self::$_query_params['orderby'] = array();
615 615
 		}
616 616
 		// loop thru $orderby_params (type cast as array)
617
-		foreach ( (array)$orderby_params as $orderby ) {
617
+		foreach ((array) $orderby_params as $orderby) {
618 618
 			// check if we have already added this param
619
-			if ( isset( self::$_query_params['orderby'][ $orderby ] )) {
619
+			if (isset(self::$_query_params['orderby'][$orderby])) {
620 620
 				// if so then remove from the $orderby_params so that the count() method below is accurate
621
-				unset( $orderby_params[ $orderby ] );
621
+				unset($orderby_params[$orderby]);
622 622
 				// then bump ahead to the next param
623 623
 				continue;
624 624
 			}
625 625
 			// this will ad a comma depending on whether this is the first or last param
626
-			$glue = $counter === 0 || $counter === count( $orderby_params ) ? ' ' : ', ';
626
+			$glue = $counter === 0 || $counter === count($orderby_params) ? ' ' : ', ';
627 627
 			// ok what's we dealing with?
628
-			switch ( $orderby ) {
628
+			switch ($orderby) {
629 629
 				case 'id' :
630 630
 				case 'ID' :
631
-					$SQL .= $glue . $wpdb->posts . '.ID ' . $sort;
631
+					$SQL .= $glue.$wpdb->posts.'.ID '.$sort;
632 632
 					break;
633 633
 				case 'end_date' :
634
-					$SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort;
634
+					$SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort;
635 635
 					break;
636 636
 				case 'event_name' :
637
-					$SQL .= $glue . $wpdb->posts . '.post_title ' . $sort;
637
+					$SQL .= $glue.$wpdb->posts.'.post_title '.$sort;
638 638
 					break;
639 639
 				case 'category_slug' :
640
-					$SQL .= $glue . $wpdb->terms . '.slug ' . $sort;
640
+					$SQL .= $glue.$wpdb->terms.'.slug '.$sort;
641 641
 					break;
642 642
 				case 'ticket_start' :
643
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort;
643
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort;
644 644
 					break;
645 645
 				case 'ticket_end' :
646
-					$SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort;
646
+					$SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort;
647 647
 					break;
648 648
 				case 'venue_title' :
649
-					$SQL .= $glue . 'venue_title ' . $sort;
649
+					$SQL .= $glue.'venue_title '.$sort;
650 650
 					break;
651 651
 				case 'city' :
652
-					$SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort;
652
+					$SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort;
653 653
 					break;
654 654
 				case 'state' :
655
-					$SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort;
655
+					$SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort;
656 656
 					break;
657 657
 				case 'start_date' :
658 658
 				default :
659
-					$SQL .= $glue . ' event_start_date ' . $sort;
659
+					$SQL .= $glue.' event_start_date '.$sort;
660 660
 					break;
661 661
 			}
662 662
 			// add to array of orderby params that have been added
663
-			self::$_query_params['orderby'][ $orderby ] = TRUE;
664
-			$counter ++;
663
+			self::$_query_params['orderby'][$orderby] = TRUE;
664
+			$counter++;
665 665
 		}
666 666
 		return $SQL;
667 667
 	}
Please login to merge, or discard this patch.
core/EES_Shortcode.shortcode.php 2 patches
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 * @param WP $WP
43 43
 	 * @return    void
44 44
 	 */
45
-	public abstract function run( WP $WP );
45
+	public abstract function run(WP $WP);
46 46
 
47 47
 
48 48
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 *  @param		array 	$attributes
55 55
 	 *  @return 	mixed
56 56
 	 */
57
-	public abstract function process_shortcode( $attributes = array() );
57
+	public abstract function process_shortcode($attributes = array());
58 58
 
59 59
 
60 60
 
@@ -65,13 +65,13 @@  discard block
 block discarded – undo
65 65
 	 * @param 	string $shortcode_class
66 66
 	 * @return 	\EES_Shortcode
67 67
 	 */
68
-	final public static function instance( $shortcode_class = null ) {
69
-		$shortcode_class = ! empty( $shortcode_class ) ? $shortcode_class : get_called_class();
70
-		if ( $shortcode_class === 'EES_Shortcode' || empty( $shortcode_class )) {
68
+	final public static function instance($shortcode_class = null) {
69
+		$shortcode_class = ! empty($shortcode_class) ? $shortcode_class : get_called_class();
70
+		if ($shortcode_class === 'EES_Shortcode' || empty($shortcode_class)) {
71 71
 			return null;
72 72
 		}
73
-		$shortcode = str_replace( 'EES_', '', strtoupper( $shortcode_class ));
74
-		$shortcode_obj = isset( EE_Registry::instance()->shortcodes->{$shortcode} )
73
+		$shortcode = str_replace('EES_', '', strtoupper($shortcode_class));
74
+		$shortcode_obj = isset(EE_Registry::instance()->shortcodes->{$shortcode} )
75 75
             ? EE_Registry::instance()->shortcodes->{$shortcode}
76 76
             : null;
77 77
 		return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self'
@@ -90,23 +90,23 @@  discard block
 block discarded – undo
90 90
 	 * @param 	$attributes
91 91
 	 * @return 	mixed
92 92
 	 */
93
-	final public static function fallback_shortcode_processor( $attributes ) {
94
-		if ( EE_Maintenance_Mode::disable_frontend_for_maintenance() ) {
93
+	final public static function fallback_shortcode_processor($attributes) {
94
+		if (EE_Maintenance_Mode::disable_frontend_for_maintenance()) {
95 95
 			return null;
96 96
 		}
97 97
 		// what shortcode was actually parsed ?
98 98
 		$shortcode_class = get_called_class();
99 99
 		// notify rest of system that fallback processor was triggered
100
-		add_filter( 'FHEE__fallback_shortcode_processor__' . $shortcode_class, '__return_true' );
100
+		add_filter('FHEE__fallback_shortcode_processor__'.$shortcode_class, '__return_true');
101 101
 		// get instance of actual shortcode
102
-		$shortcode_obj = self::instance( $shortcode_class );
102
+		$shortcode_obj = self::instance($shortcode_class);
103 103
 		// verify class
104
-		if ( $shortcode_obj instanceof EES_Shortcode ) {
104
+		if ($shortcode_obj instanceof EES_Shortcode) {
105 105
 			global $wp;
106
-			$shortcode_obj->run( $wp );
106
+			$shortcode_obj->run($wp);
107 107
 			// set attributes and run the shortcode
108
-			$shortcode_obj->_attributes = (array)$attributes;
109
-			return $shortcode_obj->process_shortcode( $shortcode_obj->_attributes );
108
+			$shortcode_obj->_attributes = (array) $attributes;
109
+			return $shortcode_obj->process_shortcode($shortcode_obj->_attributes);
110 110
 		} else {
111 111
 			return null;
112 112
 		}
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 * @param 	$attributes
123 123
 	 * @return 	string
124 124
 	 */
125
-	final public static function invalid_shortcode_processor( $attributes ) {
125
+	final public static function invalid_shortcode_processor($attributes) {
126 126
 		return '';
127 127
 	}
128 128
 
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
 	 */
134 134
 	final public function __construct() {
135 135
 		// get classname, remove EES_prefix, and convert to UPPERCASE
136
-		$shortcode = strtoupper( str_replace( 'EES_', '', get_class( $this )));
136
+		$shortcode = strtoupper(str_replace('EES_', '', get_class($this)));
137 137
 		// assign shortcode to the preferred callback, which overwrites the "fallback shortcode processor" assigned earlier
138
-		add_shortcode( $shortcode, array( $this, 'process_shortcode' ));
138
+		add_shortcode($shortcode, array($this, 'process_shortcode'));
139 139
 		// make sure system knows this is an EE page
140
-		EE_Registry::instance()->REQ->set_espresso_page( TRUE );
140
+		EE_Registry::instance()->REQ->set_espresso_page(TRUE);
141 141
 	}
142 142
 
143 143
 
@@ -151,12 +151,12 @@  discard block
 block discarded – undo
151 151
     {
152 152
         foreach ($attributes as $key => $value) {
153 153
             // is a custom sanitization callback specified ?
154
-            if ( isset($custom_sanitization[$key])) {
154
+            if (isset($custom_sanitization[$key])) {
155 155
                 $callback = $custom_sanitization[$key];
156 156
                 if ($callback === 'skip_sanitization') {
157 157
                     $attributes[$key] = $value;
158 158
                     continue;
159
-                } else if (function_exists($callback)){
159
+                } else if (function_exists($callback)) {
160 160
                     $attributes[$key] = $callback($value);
161 161
                     continue;
162 162
                 }
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -72,11 +72,11 @@  discard block
 block discarded – undo
72 72
 		}
73 73
 		$shortcode = str_replace( 'EES_', '', strtoupper( $shortcode_class ));
74 74
 		$shortcode_obj = isset( EE_Registry::instance()->shortcodes->{$shortcode} )
75
-            ? EE_Registry::instance()->shortcodes->{$shortcode}
76
-            : null;
75
+			? EE_Registry::instance()->shortcodes->{$shortcode}
76
+			: null;
77 77
 		return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self'
78
-            ? $shortcode_obj
79
-            : new $shortcode_class();
78
+			? $shortcode_obj
79
+			: new $shortcode_class();
80 80
 	}
81 81
 
82 82
 
@@ -142,59 +142,59 @@  discard block
 block discarded – undo
142 142
 
143 143
 
144 144
 
145
-    /**
146
-     * Performs basic sanitization on shortcode attributes
147
-     * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
148
-     * most attributes will by default be sanitized using the sanitize_text_field() function.
149
-     * This can be overridden by supplying an array for the $custom_sanitization param,
150
-     * where keys match keys in your attributes array,
151
-     * and values represent the sanitization function you wish to be applied to that attribute.
152
-     * So for example, if you had an integer attribute named "event_id"
153
-     * that you wanted to be sanitized using absint(),
154
-     * then you would pass the following for your $custom_sanitization array:
155
-     *      array('event_id' => 'absint')
156
-     * all other attributes would be sanitized using the defaults in the switch statement below
157
-     *
158
-     * @param array $attributes
159
-     * @param array $custom_sanitization
160
-     * @return array
161
-     */
162
-    public static function sanitize_attributes(array $attributes, $custom_sanitization = array())
163
-    {
164
-        foreach ($attributes as $key => $value) {
165
-            // is a custom sanitization callback specified ?
166
-            if ( isset($custom_sanitization[$key])) {
167
-                $callback = $custom_sanitization[$key];
168
-                if ($callback === 'skip_sanitization') {
169
-                    $attributes[$key] = $value;
170
-                    continue;
171
-                } else if (function_exists($callback)){
172
-                    $attributes[$key] = $callback($value);
173
-                    continue;
174
-                }
175
-            }
176
-            switch (true) {
177
-                case $value === null :
178
-                case is_int($value) :
179
-                case is_float($value) :
180
-                    // typical booleans
181
-                case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
182
-                    $attributes[$key] = $value;
183
-                    break;
184
-                case is_string($value) :
185
-                    $attributes[$key] = sanitize_text_field($value);
186
-                    break;
187
-                case is_array($value) :
188
-                    $attributes[$key] = \EES_Shortcode::sanitize_attributes($value);
189
-                    break;
190
-                default :
191
-                    // only remaining data types are Object and Resource
192
-                    // which are not allowed as shortcode attributes
193
-                    $attributes[$key] = null;
194
-                    break;
195
-            }
196
-        }
197
-        return $attributes;
145
+	/**
146
+	 * Performs basic sanitization on shortcode attributes
147
+	 * Since incoming attributes from the shortcode usage in the WP editor will all be strings,
148
+	 * most attributes will by default be sanitized using the sanitize_text_field() function.
149
+	 * This can be overridden by supplying an array for the $custom_sanitization param,
150
+	 * where keys match keys in your attributes array,
151
+	 * and values represent the sanitization function you wish to be applied to that attribute.
152
+	 * So for example, if you had an integer attribute named "event_id"
153
+	 * that you wanted to be sanitized using absint(),
154
+	 * then you would pass the following for your $custom_sanitization array:
155
+	 *      array('event_id' => 'absint')
156
+	 * all other attributes would be sanitized using the defaults in the switch statement below
157
+	 *
158
+	 * @param array $attributes
159
+	 * @param array $custom_sanitization
160
+	 * @return array
161
+	 */
162
+	public static function sanitize_attributes(array $attributes, $custom_sanitization = array())
163
+	{
164
+		foreach ($attributes as $key => $value) {
165
+			// is a custom sanitization callback specified ?
166
+			if ( isset($custom_sanitization[$key])) {
167
+				$callback = $custom_sanitization[$key];
168
+				if ($callback === 'skip_sanitization') {
169
+					$attributes[$key] = $value;
170
+					continue;
171
+				} else if (function_exists($callback)){
172
+					$attributes[$key] = $callback($value);
173
+					continue;
174
+				}
175
+			}
176
+			switch (true) {
177
+				case $value === null :
178
+				case is_int($value) :
179
+				case is_float($value) :
180
+					// typical booleans
181
+				case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) :
182
+					$attributes[$key] = $value;
183
+					break;
184
+				case is_string($value) :
185
+					$attributes[$key] = sanitize_text_field($value);
186
+					break;
187
+				case is_array($value) :
188
+					$attributes[$key] = \EES_Shortcode::sanitize_attributes($value);
189
+					break;
190
+				default :
191
+					// only remaining data types are Object and Resource
192
+					// which are not allowed as shortcode attributes
193
+					$attributes[$key] = null;
194
+					break;
195
+			}
196
+		}
197
+		return $attributes;
198 198
 	}
199 199
 
200 200
 
Please login to merge, or discard this patch.
core/helpers/EEH_Activation.helper.php 1 patch
Indentation   +1712 added lines, -1712 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -14,244 +14,244 @@  discard block
 block discarded – undo
14 14
 class EEH_Activation
15 15
 {
16 16
 
17
-    /**
18
-     * constant used to indicate a cron task is no longer in use
19
-     */
20
-    const cron_task_no_longer_in_use = 'no_longer_in_use';
21
-
22
-    /**
23
-     * option name that will indicate whether or not we still
24
-     * need to create EE's folders in the uploads directory
25
-     * (because if EE was installed without file system access,
26
-     * we need to request credentials before we can create them)
27
-     */
28
-    const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
-
30
-    /**
31
-     * WP_User->ID
32
-     *
33
-     * @var int
34
-     */
35
-    private static $_default_creator_id;
36
-
37
-    /**
38
-     * indicates whether or not we've already verified core's default data during this request,
39
-     * because after migrations are done, any addons activated while in maintenance mode
40
-     * will want to setup their own default data, and they might hook into core's default data
41
-     * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
-     * This prevents doing that for EVERY single addon.
43
-     *
44
-     * @var boolean
45
-     */
46
-    protected static $_initialized_db_content_already_in_this_request = false;
47
-
48
-    /**
49
-     * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
50
-     */
51
-    private static $table_analysis;
52
-
53
-    /**
54
-     * @var \EventEspresso\core\services\database\TableManager $table_manager
55
-     */
56
-    private static $table_manager;
57
-
58
-
59
-    /**
60
-     * @return \EventEspresso\core\services\database\TableAnalysis
61
-     */
62
-    public static function getTableAnalysis()
63
-    {
64
-        if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
-            self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66
-        }
67
-        return self::$table_analysis;
68
-    }
69
-
70
-
71
-    /**
72
-     * @return \EventEspresso\core\services\database\TableManager
73
-     */
74
-    public static function getTableManager()
75
-    {
76
-        if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
-            self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78
-        }
79
-        return self::$table_manager;
80
-    }
81
-
82
-
83
-    /**
84
-     *    _ensure_table_name_has_prefix
85
-     *
86
-     * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
-     * @access     public
88
-     * @static
89
-     * @param $table_name
90
-     * @return string
91
-     */
92
-    public static function ensure_table_name_has_prefix($table_name)
93
-    {
94
-        return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
95
-    }
96
-
97
-
98
-    /**
99
-     *    system_initialization
100
-     *    ensures the EE configuration settings are loaded with at least default options set
101
-     *    and that all critical EE pages have been generated with the appropriate shortcodes in place
102
-     *
103
-     * @access public
104
-     * @static
105
-     * @return void
106
-     */
107
-    public static function system_initialization()
108
-    {
109
-        EEH_Activation::reset_and_update_config();
110
-        //which is fired BEFORE activation of plugin anyways
111
-        EEH_Activation::verify_default_pages_exist();
112
-    }
113
-
114
-
115
-    /**
116
-     * Sets the database schema and creates folders. This should
117
-     * be called on plugin activation and reactivation
118
-     *
119
-     * @return boolean success, whether the database and folders are setup properly
120
-     * @throws \EE_Error
121
-     */
122
-    public static function initialize_db_and_folders()
123
-    {
124
-        $good_filesystem = EEH_Activation::create_upload_directories();
125
-        $good_db         = EEH_Activation::create_database_tables();
126
-        return $good_filesystem && $good_db;
127
-    }
128
-
129
-
130
-    /**
131
-     * assuming we have an up-to-date database schema, this will populate it
132
-     * with default and initial data. This should be called
133
-     * upon activation of a new plugin, reactivation, and at the end
134
-     * of running migration scripts
135
-     *
136
-     * @throws \EE_Error
137
-     */
138
-    public static function initialize_db_content()
139
-    {
140
-        //let's avoid doing all this logic repeatedly, especially when addons are requesting it
141
-        if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
142
-            return;
143
-        }
144
-        EEH_Activation::$_initialized_db_content_already_in_this_request = true;
145
-
146
-        EEH_Activation::initialize_system_questions();
147
-        EEH_Activation::insert_default_status_codes();
148
-        EEH_Activation::generate_default_message_templates();
149
-        EEH_Activation::create_no_ticket_prices_array();
150
-        EE_Registry::instance()->CAP->init_caps();
151
-
152
-        EEH_Activation::validate_messages_system();
153
-        EEH_Activation::insert_default_payment_methods();
154
-        //in case we've
155
-        EEH_Activation::remove_cron_tasks();
156
-        EEH_Activation::create_cron_tasks();
157
-        // remove all TXN locks since that is being done via extra meta now
158
-        delete_option('ee_locked_transactions');
159
-        //also, check for CAF default db content
160
-        do_action('AHEE__EEH_Activation__initialize_db_content');
161
-        //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
162
-        //which users really won't care about on initial activation
163
-        EE_Error::overwrite_success();
164
-    }
165
-
166
-
167
-    /**
168
-     * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
169
-     * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
170
-     * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
171
-     * (null)
172
-     *
173
-     * @param string $which_to_include can be 'current' (ones that are currently in use),
174
-     *                                 'old' (only returns ones that should no longer be used),or 'all',
175
-     * @return array
176
-     * @throws \EE_Error
177
-     */
178
-    public static function get_cron_tasks($which_to_include)
179
-    {
180
-        $cron_tasks = apply_filters(
181
-            'FHEE__EEH_Activation__get_cron_tasks',
182
-            array(
183
-                'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
17
+	/**
18
+	 * constant used to indicate a cron task is no longer in use
19
+	 */
20
+	const cron_task_no_longer_in_use = 'no_longer_in_use';
21
+
22
+	/**
23
+	 * option name that will indicate whether or not we still
24
+	 * need to create EE's folders in the uploads directory
25
+	 * (because if EE was installed without file system access,
26
+	 * we need to request credentials before we can create them)
27
+	 */
28
+	const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete';
29
+
30
+	/**
31
+	 * WP_User->ID
32
+	 *
33
+	 * @var int
34
+	 */
35
+	private static $_default_creator_id;
36
+
37
+	/**
38
+	 * indicates whether or not we've already verified core's default data during this request,
39
+	 * because after migrations are done, any addons activated while in maintenance mode
40
+	 * will want to setup their own default data, and they might hook into core's default data
41
+	 * and trigger core to setup its default data. In which case they might all ask for core to init its default data.
42
+	 * This prevents doing that for EVERY single addon.
43
+	 *
44
+	 * @var boolean
45
+	 */
46
+	protected static $_initialized_db_content_already_in_this_request = false;
47
+
48
+	/**
49
+	 * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis
50
+	 */
51
+	private static $table_analysis;
52
+
53
+	/**
54
+	 * @var \EventEspresso\core\services\database\TableManager $table_manager
55
+	 */
56
+	private static $table_manager;
57
+
58
+
59
+	/**
60
+	 * @return \EventEspresso\core\services\database\TableAnalysis
61
+	 */
62
+	public static function getTableAnalysis()
63
+	{
64
+		if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) {
65
+			self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true);
66
+		}
67
+		return self::$table_analysis;
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return \EventEspresso\core\services\database\TableManager
73
+	 */
74
+	public static function getTableManager()
75
+	{
76
+		if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) {
77
+			self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true);
78
+		}
79
+		return self::$table_manager;
80
+	}
81
+
82
+
83
+	/**
84
+	 *    _ensure_table_name_has_prefix
85
+	 *
86
+	 * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix()
87
+	 * @access     public
88
+	 * @static
89
+	 * @param $table_name
90
+	 * @return string
91
+	 */
92
+	public static function ensure_table_name_has_prefix($table_name)
93
+	{
94
+		return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name);
95
+	}
96
+
97
+
98
+	/**
99
+	 *    system_initialization
100
+	 *    ensures the EE configuration settings are loaded with at least default options set
101
+	 *    and that all critical EE pages have been generated with the appropriate shortcodes in place
102
+	 *
103
+	 * @access public
104
+	 * @static
105
+	 * @return void
106
+	 */
107
+	public static function system_initialization()
108
+	{
109
+		EEH_Activation::reset_and_update_config();
110
+		//which is fired BEFORE activation of plugin anyways
111
+		EEH_Activation::verify_default_pages_exist();
112
+	}
113
+
114
+
115
+	/**
116
+	 * Sets the database schema and creates folders. This should
117
+	 * be called on plugin activation and reactivation
118
+	 *
119
+	 * @return boolean success, whether the database and folders are setup properly
120
+	 * @throws \EE_Error
121
+	 */
122
+	public static function initialize_db_and_folders()
123
+	{
124
+		$good_filesystem = EEH_Activation::create_upload_directories();
125
+		$good_db         = EEH_Activation::create_database_tables();
126
+		return $good_filesystem && $good_db;
127
+	}
128
+
129
+
130
+	/**
131
+	 * assuming we have an up-to-date database schema, this will populate it
132
+	 * with default and initial data. This should be called
133
+	 * upon activation of a new plugin, reactivation, and at the end
134
+	 * of running migration scripts
135
+	 *
136
+	 * @throws \EE_Error
137
+	 */
138
+	public static function initialize_db_content()
139
+	{
140
+		//let's avoid doing all this logic repeatedly, especially when addons are requesting it
141
+		if (EEH_Activation::$_initialized_db_content_already_in_this_request) {
142
+			return;
143
+		}
144
+		EEH_Activation::$_initialized_db_content_already_in_this_request = true;
145
+
146
+		EEH_Activation::initialize_system_questions();
147
+		EEH_Activation::insert_default_status_codes();
148
+		EEH_Activation::generate_default_message_templates();
149
+		EEH_Activation::create_no_ticket_prices_array();
150
+		EE_Registry::instance()->CAP->init_caps();
151
+
152
+		EEH_Activation::validate_messages_system();
153
+		EEH_Activation::insert_default_payment_methods();
154
+		//in case we've
155
+		EEH_Activation::remove_cron_tasks();
156
+		EEH_Activation::create_cron_tasks();
157
+		// remove all TXN locks since that is being done via extra meta now
158
+		delete_option('ee_locked_transactions');
159
+		//also, check for CAF default db content
160
+		do_action('AHEE__EEH_Activation__initialize_db_content');
161
+		//also: EEM_Gateways::load_all_gateways() outputs a lot of success messages
162
+		//which users really won't care about on initial activation
163
+		EE_Error::overwrite_success();
164
+	}
165
+
166
+
167
+	/**
168
+	 * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"),
169
+	 * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event
170
+	 * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use
171
+	 * (null)
172
+	 *
173
+	 * @param string $which_to_include can be 'current' (ones that are currently in use),
174
+	 *                                 'old' (only returns ones that should no longer be used),or 'all',
175
+	 * @return array
176
+	 * @throws \EE_Error
177
+	 */
178
+	public static function get_cron_tasks($which_to_include)
179
+	{
180
+		$cron_tasks = apply_filters(
181
+			'FHEE__EEH_Activation__get_cron_tasks',
182
+			array(
183
+				'AHEE__EE_Cron_Tasks__clean_up_junk_transactions'      => 'hourly',
184 184
 //				'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use
185
-                'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
186
-                //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
187
-                'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
188
-            )
189
-        );
190
-        if ($which_to_include === 'old') {
191
-            $cron_tasks = array_filter(
192
-                $cron_tasks,
193
-                function ($value) {
194
-                    return $value === EEH_Activation::cron_task_no_longer_in_use;
195
-                }
196
-            );
197
-        } elseif ($which_to_include === 'current') {
198
-            $cron_tasks = array_filter($cron_tasks);
199
-        } elseif (WP_DEBUG && $which_to_include !== 'all') {
200
-            throw new EE_Error(
201
-                sprintf(
202
-                    __(
203
-                        'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
204
-                        'event_espresso'
205
-                    ),
206
-                    $which_to_include
207
-                )
208
-            );
209
-        }
210
-        return $cron_tasks;
211
-    }
212
-
213
-
214
-    /**
215
-     * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
216
-     *
217
-     * @throws \EE_Error
218
-     */
219
-    public static function create_cron_tasks()
220
-    {
221
-
222
-        foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
223
-            if (! wp_next_scheduled($hook_name)) {
224
-                /**
225
-                 * This allows client code to define the initial start timestamp for this schedule.
226
-                 */
227
-                if (is_array($frequency)
228
-                    && count($frequency) === 2
229
-                    && isset($frequency[0], $frequency[1])
230
-                ) {
231
-                    $start_timestamp = $frequency[0];
232
-                    $frequency = $frequency[1];
233
-                } else {
234
-                    $start_timestamp = time();
235
-                }
236
-                wp_schedule_event($start_timestamp, $frequency, $hook_name);
237
-            }
238
-        }
239
-
240
-    }
241
-
242
-
243
-    /**
244
-     * Remove the currently-existing and now-removed cron tasks.
245
-     *
246
-     * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
247
-     * @throws \EE_Error
248
-     */
249
-    public static function remove_cron_tasks($remove_all = true)
250
-    {
251
-        $cron_tasks_to_remove = $remove_all ? 'all' : 'old';
252
-        $crons                = _get_cron_array();
253
-        $crons                = is_array($crons) ? $crons : array();
254
-        /* reminder of what $crons look like:
185
+				'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use,
186
+				//there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates
187
+				'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs'       => 'daily',
188
+			)
189
+		);
190
+		if ($which_to_include === 'old') {
191
+			$cron_tasks = array_filter(
192
+				$cron_tasks,
193
+				function ($value) {
194
+					return $value === EEH_Activation::cron_task_no_longer_in_use;
195
+				}
196
+			);
197
+		} elseif ($which_to_include === 'current') {
198
+			$cron_tasks = array_filter($cron_tasks);
199
+		} elseif (WP_DEBUG && $which_to_include !== 'all') {
200
+			throw new EE_Error(
201
+				sprintf(
202
+					__(
203
+						'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".',
204
+						'event_espresso'
205
+					),
206
+					$which_to_include
207
+				)
208
+			);
209
+		}
210
+		return $cron_tasks;
211
+	}
212
+
213
+
214
+	/**
215
+	 * Ensure cron tasks are setup (the removal of crons should be done by remove_crons())
216
+	 *
217
+	 * @throws \EE_Error
218
+	 */
219
+	public static function create_cron_tasks()
220
+	{
221
+
222
+		foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) {
223
+			if (! wp_next_scheduled($hook_name)) {
224
+				/**
225
+				 * This allows client code to define the initial start timestamp for this schedule.
226
+				 */
227
+				if (is_array($frequency)
228
+					&& count($frequency) === 2
229
+					&& isset($frequency[0], $frequency[1])
230
+				) {
231
+					$start_timestamp = $frequency[0];
232
+					$frequency = $frequency[1];
233
+				} else {
234
+					$start_timestamp = time();
235
+				}
236
+				wp_schedule_event($start_timestamp, $frequency, $hook_name);
237
+			}
238
+		}
239
+
240
+	}
241
+
242
+
243
+	/**
244
+	 * Remove the currently-existing and now-removed cron tasks.
245
+	 *
246
+	 * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones
247
+	 * @throws \EE_Error
248
+	 */
249
+	public static function remove_cron_tasks($remove_all = true)
250
+	{
251
+		$cron_tasks_to_remove = $remove_all ? 'all' : 'old';
252
+		$crons                = _get_cron_array();
253
+		$crons                = is_array($crons) ? $crons : array();
254
+		/* reminder of what $crons look like:
255 255
          * Top-level keys are timestamps, and their values are arrays.
256 256
          * The 2nd level arrays have keys with each of the cron task hook names to run at that time
257 257
          * and their values are arrays.
@@ -268,971 +268,971 @@  discard block
 block discarded – undo
268 268
          *					...
269 269
          *      ...
270 270
          */
271
-        $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
272
-        foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
273
-            if (is_array($hooks_to_fire_at_time)) {
274
-                foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
275
-                    if (isset($ee_cron_tasks_to_remove[$hook_name])
276
-                        && is_array($ee_cron_tasks_to_remove[$hook_name])
277
-                    ) {
278
-                        unset($crons[$timestamp][$hook_name]);
279
-                    }
280
-                }
281
-                //also take care of any empty cron timestamps.
282
-                if (empty($hooks_to_fire_at_time)) {
283
-                    unset($crons[$timestamp]);
284
-                }
285
-            }
286
-        }
287
-        _set_cron_array($crons);
288
-    }
289
-
290
-
291
-    /**
292
-     *    CPT_initialization
293
-     *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
294
-     *
295
-     * @access public
296
-     * @static
297
-     * @return void
298
-     */
299
-    public static function CPT_initialization()
300
-    {
301
-        // register Custom Post Types
302
-        EE_Registry::instance()->load_core('Register_CPTs');
303
-        flush_rewrite_rules();
304
-    }
305
-
306
-
307
-
308
-    /**
309
-     *    reset_and_update_config
310
-     * The following code was moved over from EE_Config so that it will no longer run on every request.
311
-     * If there is old calendar config data saved, then it will get converted on activation.
312
-     * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
313
-     *
314
-     * @access public
315
-     * @static
316
-     * @return void
317
-     */
318
-    public static function reset_and_update_config()
319
-    {
320
-        do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
321
-        add_filter(
322
-            'FHEE__EE_Config___load_core_config__config_settings',
323
-            array('EEH_Activation', 'migrate_old_config_data'),
324
-            10,
325
-            3
326
-        );
327
-        //EE_Config::reset();
328
-        if (! EE_Config::logging_enabled()) {
329
-            delete_option(EE_Config::LOG_NAME);
330
-        }
331
-    }
332
-
333
-
334
-    /**
335
-     *    load_calendar_config
336
-     *
337
-     * @access    public
338
-     * @return    void
339
-     */
340
-    public static function load_calendar_config()
341
-    {
342
-        // grab array of all plugin folders and loop thru it
343
-        $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
344
-        if (empty($plugins)) {
345
-            return;
346
-        }
347
-        foreach ($plugins as $plugin_path) {
348
-            // grab plugin folder name from path
349
-            $plugin = basename($plugin_path);
350
-            // drill down to Espresso plugins
351
-            // then to calendar related plugins
352
-            if (
353
-                strpos($plugin, 'espresso') !== false
354
-                || strpos($plugin, 'Espresso') !== false
355
-                || strpos($plugin, 'ee4') !== false
356
-                || strpos($plugin, 'EE4') !== false
357
-                || strpos($plugin, 'calendar') !== false
358
-            ) {
359
-                // this is what we are looking for
360
-                $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
361
-                // does it exist in this folder ?
362
-                if (is_readable($calendar_config)) {
363
-                    // YEAH! let's load it
364
-                    require_once($calendar_config);
365
-                }
366
-            }
367
-        }
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     *    _migrate_old_config_data
374
-     *
375
-     * @access    public
376
-     * @param array|stdClass $settings
377
-     * @param string         $config
378
-     * @param \EE_Config     $EE_Config
379
-     * @return \stdClass
380
-     */
381
-    public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
382
-    {
383
-        $convert_from_array = array('addons');
384
-        // in case old settings were saved as an array
385
-        if (is_array($settings) && in_array($config, $convert_from_array)) {
386
-            // convert existing settings to an object
387
-            $config_array = $settings;
388
-            $settings = new stdClass();
389
-            foreach ($config_array as $key => $value) {
390
-                if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
391
-                    $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
392
-                } else {
393
-                    $settings->{$key} = $value;
394
-                }
395
-            }
396
-            add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
397
-        }
398
-        return $settings;
399
-    }
400
-
401
-
402
-    /**
403
-     * deactivate_event_espresso
404
-     *
405
-     * @access public
406
-     * @static
407
-     * @return void
408
-     */
409
-    public static function deactivate_event_espresso()
410
-    {
411
-        // check permissions
412
-        if (current_user_can('activate_plugins')) {
413
-            deactivate_plugins(EE_PLUGIN_BASENAME, true);
414
-        }
415
-    }
416
-
417
-
418
-
419
-
420
-
421
-    /**
422
-     * verify_default_pages_exist
423
-     *
424
-     * @access public
425
-     * @static
426
-     * @return void
427
-     */
428
-    public static function verify_default_pages_exist()
429
-    {
430
-        $critical_page_problem = false;
431
-        $critical_pages = array(
432
-            array(
433
-                'id'   => 'reg_page_id',
434
-                'name' => __('Registration Checkout', 'event_espresso'),
435
-                'post' => null,
436
-                'code' => 'ESPRESSO_CHECKOUT',
437
-            ),
438
-            array(
439
-                'id'   => 'txn_page_id',
440
-                'name' => __('Transactions', 'event_espresso'),
441
-                'post' => null,
442
-                'code' => 'ESPRESSO_TXN_PAGE',
443
-            ),
444
-            array(
445
-                'id'   => 'thank_you_page_id',
446
-                'name' => __('Thank You', 'event_espresso'),
447
-                'post' => null,
448
-                'code' => 'ESPRESSO_THANK_YOU',
449
-            ),
450
-            array(
451
-                'id'   => 'cancel_page_id',
452
-                'name' => __('Registration Cancelled', 'event_espresso'),
453
-                'post' => null,
454
-                'code' => 'ESPRESSO_CANCELLED',
455
-            ),
456
-        );
457
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
458
-        foreach ($critical_pages as $critical_page) {
459
-            // is critical page ID set in config ?
460
-            if ($EE_Core_Config->{$critical_page['id']} !== false) {
461
-                // attempt to find post by ID
462
-                $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
463
-            }
464
-            // no dice?
465
-            if ($critical_page['post'] === null) {
466
-                // attempt to find post by title
467
-                $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
468
-                // still nothing?
469
-                if ($critical_page['post'] === null) {
470
-                    $critical_page = EEH_Activation::create_critical_page($critical_page);
471
-                    // REALLY? Still nothing ??!?!?
472
-                    if ($critical_page['post'] === null) {
473
-                        $msg = __(
474
-                            'The Event Espresso critical page configuration settings could not be updated.',
475
-                            'event_espresso'
476
-                        );
477
-                        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
478
-                        break;
479
-                    }
480
-                }
481
-            }
482
-            // track post_shortcodes
483
-            if ($critical_page['post']) {
484
-                EEH_Activation::_track_critical_page_post_shortcodes($critical_page);
485
-            }
486
-            // check that Post ID matches critical page ID in config
487
-            if (
488
-                isset($critical_page['post']->ID)
489
-                && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
490
-            ) {
491
-                //update Config with post ID
492
-                $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
493
-                if (! EE_Config::instance()->update_espresso_config(false, false)) {
494
-                    $msg = __(
495
-                        'The Event Espresso critical page configuration settings could not be updated.',
496
-                        'event_espresso'
497
-                    );
498
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
499
-                }
500
-            }
501
-            $critical_page_problem =
502
-                ! isset($critical_page['post']->post_status)
503
-                || $critical_page['post']->post_status !== 'publish'
504
-                || strpos($critical_page['post']->post_content, $critical_page['code']) === false
505
-                    ? true
506
-                    : $critical_page_problem;
507
-        }
508
-        if ($critical_page_problem) {
509
-            $msg = sprintf(
510
-                __(
511
-                    'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
512
-                    'event_espresso'
513
-                ),
514
-                '<a href="'
515
-                . admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
516
-                . '">'
517
-                . __('Event Espresso Critical Pages Settings', 'event_espresso')
518
-                . '</a>'
519
-            );
520
-            EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
521
-        }
522
-        if (EE_Error::has_notices()) {
523
-            EE_Error::get_notices(false, true, true);
524
-        }
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     * Returns the first post which uses the specified shortcode
531
-     *
532
-     * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
533
-     *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
534
-     *                             "[ESPRESSO_THANK_YOU"
535
-     *                             (we don't search for the closing shortcode bracket because they might have added
536
-     *                             parameter to the shortcode
537
-     * @return WP_Post or NULl
538
-     */
539
-    public static function get_page_by_ee_shortcode($ee_shortcode)
540
-    {
541
-        global $wpdb;
542
-        $shortcode_and_opening_bracket = '[' . $ee_shortcode;
543
-        $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
544
-        if ($post_id) {
545
-            return get_post($post_id);
546
-        } else {
547
-            return null;
548
-        }
549
-    }
550
-
551
-
552
-    /**
553
-     *    This function generates a post for critical espresso pages
554
-     *
555
-     * @access public
556
-     * @static
557
-     * @param array $critical_page
558
-     * @return array
559
-     */
560
-    public static function create_critical_page($critical_page)
561
-    {
562
-
563
-        $post_args = array(
564
-            'post_title'     => $critical_page['name'],
565
-            'post_status'    => 'publish',
566
-            'post_type'      => 'page',
567
-            'comment_status' => 'closed',
568
-            'post_content'   => '[' . $critical_page['code'] . ']',
569
-        );
570
-
571
-        $post_id = wp_insert_post($post_args);
572
-        if (! $post_id) {
573
-            $msg = sprintf(
574
-                __('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
575
-                $critical_page['name']
576
-            );
577
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
578
-            return $critical_page;
579
-        }
580
-        // get newly created post's details
581
-        if (! $critical_page['post'] = get_post($post_id)) {
582
-            $msg = sprintf(
583
-                __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
584
-                $critical_page['name']
585
-            );
586
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
587
-        }
588
-
589
-        return $critical_page;
590
-
591
-    }
592
-
593
-
594
-
595
-
596
-
597
-    /**
598
-     *    This function adds a critical page's shortcode to the post_shortcodes array
599
-     *
600
-     * @access private
601
-     * @static
602
-     * @param array $critical_page
603
-     * @return void
604
-     */
605
-    private static function _track_critical_page_post_shortcodes($critical_page = array())
606
-    {
607
-        // check the goods
608
-        if ( ! $critical_page['post'] instanceof WP_Post) {
609
-            $msg = sprintf(
610
-                __(
611
-                    'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.',
612
-                    'event_espresso'
613
-                ),
614
-                $critical_page['name']
615
-            );
616
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
617
-            return;
618
-        }
619
-        $EE_Core_Config = EE_Registry::instance()->CFG->core;
620
-        // map shortcode to post
621
-        $EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID;
622
-        // and make sure it's NOT added to the WP "Posts Page"
623
-        // name of the WP Posts Page
624
-        $posts_page = EE_Config::get_page_for_posts();
625
-        if (isset($EE_Core_Config->post_shortcodes[$posts_page])) {
626
-            unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]);
627
-        }
628
-        if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) {
629
-            unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]);
630
-        }
631
-        // update post_shortcode CFG
632
-        EE_Config::instance()->update_espresso_config(false, false);
633
-        // verify that saved ID in the config matches the ID for the post the shortcode is on
634
-        if (
635
-            EE_Registry::instance()->CFG->core->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']]
636
-            !== $critical_page['post']->ID
637
-        ) {
638
-            $msg = sprintf(
639
-                __(
640
-                    'The Event Espresso critical page shortcode for the %s page could not be configured properly.',
641
-                    'event_espresso'
642
-                ),
643
-                $critical_page['name']
644
-            );
645
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
646
-        }
647
-    }
648
-
649
-
650
-
651
-    /**
652
-     * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
653
-     * The role being used to check is filterable.
654
-     *
655
-     * @since  4.6.0
656
-     * @global WPDB $wpdb
657
-     * @return mixed null|int WP_user ID or NULL
658
-     */
659
-    public static function get_default_creator_id()
660
-    {
661
-        global $wpdb;
662
-        if ( ! empty(self::$_default_creator_id)) {
663
-            return self::$_default_creator_id;
664
-        }/**/
665
-        $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
666
-        //let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
667
-        $pre_filtered_id = apply_filters(
668
-            'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
669
-            false,
670
-            $role_to_check
671
-        );
672
-        if ($pre_filtered_id !== false) {
673
-            return (int)$pre_filtered_id;
674
-        }
675
-        $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
676
-        $query = $wpdb->prepare(
677
-            "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
678
-            '%' . $role_to_check . '%'
679
-        );
680
-        $user_id = $wpdb->get_var($query);
681
-        $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
682
-        if ($user_id && (int)$user_id) {
683
-            self::$_default_creator_id = (int)$user_id;
684
-            return self::$_default_creator_id;
685
-        } else {
686
-            return null;
687
-        }
688
-    }
689
-
690
-
691
-
692
-    /**
693
-     * used by EE and EE addons during plugin activation to create tables.
694
-     * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
695
-     * but includes extra logic regarding activations.
696
-     *
697
-     * @access public
698
-     * @static
699
-     * @param string  $table_name              without the $wpdb->prefix
700
-     * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
701
-     *                                         table query)
702
-     * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
703
-     * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
704
-     *                                         and new once this function is done (ie, you really do want to CREATE a
705
-     *                                         table, and expect it to be empty once you're done) leave as FALSE when
706
-     *                                         you just want to verify the table exists and matches this definition
707
-     *                                         (and if it HAS data in it you want to leave it be)
708
-     * @return void
709
-     * @throws EE_Error if there are database errors
710
-     */
711
-    public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
712
-    {
713
-        if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
714
-            return;
715
-        }
716
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
717
-        if ( ! function_exists('dbDelta')) {
718
-            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
719
-        }
720
-        $tableAnalysis = \EEH_Activation::getTableAnalysis();
721
-        $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
722
-        // do we need to first delete an existing version of this table ?
723
-        if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
724
-            // ok, delete the table... but ONLY if it's empty
725
-            $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
726
-            // table is NOT empty, are you SURE you want to delete this table ???
727
-            if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
728
-                \EEH_Activation::getTableManager()->dropTable($wp_table_name);
729
-            } else if ( ! $deleted_safely) {
730
-                // so we should be more cautious rather than just dropping tables so easily
731
-                error_log(
732
-                    sprintf(
733
-                        __(
734
-                            'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
735
-                            'event_espresso'
736
-                        ),
737
-                        $wp_table_name,
738
-                        '<br/>',
739
-                        'espresso_db_update'
740
-                    )
741
-                );
742
-            }
743
-        }
744
-        $engine = str_replace('ENGINE=', '', $engine);
745
-        \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
746
-    }
747
-
748
-
749
-
750
-    /**
751
-     *    add_column_if_it_doesn't_exist
752
-     *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
753
-     *
754
-     * @access     public
755
-     * @static
756
-     * @deprecated instead use TableManager::addColumn()
757
-     * @param string $table_name  (without "wp_", eg "esp_attendee"
758
-     * @param string $column_name
759
-     * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
760
-     *                            'VARCHAR(10)'
761
-     * @return bool|int
762
-     */
763
-    public static function add_column_if_it_doesnt_exist(
764
-        $table_name,
765
-        $column_name,
766
-        $column_info = 'INT UNSIGNED NOT NULL'
767
-    ) {
768
-        return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
769
-    }
770
-
771
-
772
-    /**
773
-     * get_fields_on_table
774
-     * Gets all the fields on the database table.
775
-     *
776
-     * @access     public
777
-     * @deprecated instead use TableManager::getTableColumns()
778
-     * @static
779
-     * @param string $table_name , without prefixed $wpdb->prefix
780
-     * @return array of database column names
781
-     */
782
-    public static function get_fields_on_table($table_name = null)
783
-    {
784
-        return \EEH_Activation::getTableManager()->getTableColumns($table_name);
785
-    }
786
-
787
-
788
-    /**
789
-     * db_table_is_empty
790
-     *
791
-     * @access     public\
792
-     * @deprecated instead use TableAnalysis::tableIsEmpty()
793
-     * @static
794
-     * @param string $table_name
795
-     * @return bool
796
-     */
797
-    public static function db_table_is_empty($table_name)
798
-    {
799
-        return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
800
-    }
801
-
802
-
803
-    /**
804
-     * delete_db_table_if_empty
805
-     *
806
-     * @access public
807
-     * @static
808
-     * @param string $table_name
809
-     * @return bool | int
810
-     */
811
-    public static function delete_db_table_if_empty($table_name)
812
-    {
813
-        if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
814
-            return \EEH_Activation::getTableManager()->dropTable($table_name);
815
-        }
816
-        return false;
817
-    }
818
-
819
-
820
-    /**
821
-     * delete_unused_db_table
822
-     *
823
-     * @access     public
824
-     * @static
825
-     * @deprecated instead use TableManager::dropTable()
826
-     * @param string $table_name
827
-     * @return bool | int
828
-     */
829
-    public static function delete_unused_db_table($table_name)
830
-    {
831
-        return \EEH_Activation::getTableManager()->dropTable($table_name);
832
-    }
833
-
834
-
835
-    /**
836
-     * drop_index
837
-     *
838
-     * @access     public
839
-     * @static
840
-     * @deprecated instead use TableManager::dropIndex()
841
-     * @param string $table_name
842
-     * @param string $index_name
843
-     * @return bool | int
844
-     */
845
-    public static function drop_index($table_name, $index_name)
846
-    {
847
-        return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
848
-    }
849
-
850
-
851
-
852
-    /**
853
-     * create_database_tables
854
-     *
855
-     * @access public
856
-     * @static
857
-     * @throws EE_Error
858
-     * @return boolean success (whether database is setup properly or not)
859
-     */
860
-    public static function create_database_tables()
861
-    {
862
-        EE_Registry::instance()->load_core('Data_Migration_Manager');
863
-        //find the migration script that sets the database to be compatible with the code
864
-        $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
865
-        if ($dms_name) {
866
-            $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
867
-            $current_data_migration_script->set_migrating(false);
868
-            $current_data_migration_script->schema_changes_before_migration();
869
-            $current_data_migration_script->schema_changes_after_migration();
870
-            if ($current_data_migration_script->get_errors()) {
871
-                if (WP_DEBUG) {
872
-                    foreach ($current_data_migration_script->get_errors() as $error) {
873
-                        EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
874
-                    }
875
-                } else {
876
-                    EE_Error::add_error(
877
-                        __(
878
-                            'There were errors creating the Event Espresso database tables and Event Espresso has been 
271
+		$ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove);
272
+		foreach ($crons as $timestamp => $hooks_to_fire_at_time) {
273
+			if (is_array($hooks_to_fire_at_time)) {
274
+				foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) {
275
+					if (isset($ee_cron_tasks_to_remove[$hook_name])
276
+						&& is_array($ee_cron_tasks_to_remove[$hook_name])
277
+					) {
278
+						unset($crons[$timestamp][$hook_name]);
279
+					}
280
+				}
281
+				//also take care of any empty cron timestamps.
282
+				if (empty($hooks_to_fire_at_time)) {
283
+					unset($crons[$timestamp]);
284
+				}
285
+			}
286
+		}
287
+		_set_cron_array($crons);
288
+	}
289
+
290
+
291
+	/**
292
+	 *    CPT_initialization
293
+	 *    registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist
294
+	 *
295
+	 * @access public
296
+	 * @static
297
+	 * @return void
298
+	 */
299
+	public static function CPT_initialization()
300
+	{
301
+		// register Custom Post Types
302
+		EE_Registry::instance()->load_core('Register_CPTs');
303
+		flush_rewrite_rules();
304
+	}
305
+
306
+
307
+
308
+	/**
309
+	 *    reset_and_update_config
310
+	 * The following code was moved over from EE_Config so that it will no longer run on every request.
311
+	 * If there is old calendar config data saved, then it will get converted on activation.
312
+	 * This was basically a DMS before we had DMS's, and will get removed after a few more versions.
313
+	 *
314
+	 * @access public
315
+	 * @static
316
+	 * @return void
317
+	 */
318
+	public static function reset_and_update_config()
319
+	{
320
+		do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config'));
321
+		add_filter(
322
+			'FHEE__EE_Config___load_core_config__config_settings',
323
+			array('EEH_Activation', 'migrate_old_config_data'),
324
+			10,
325
+			3
326
+		);
327
+		//EE_Config::reset();
328
+		if (! EE_Config::logging_enabled()) {
329
+			delete_option(EE_Config::LOG_NAME);
330
+		}
331
+	}
332
+
333
+
334
+	/**
335
+	 *    load_calendar_config
336
+	 *
337
+	 * @access    public
338
+	 * @return    void
339
+	 */
340
+	public static function load_calendar_config()
341
+	{
342
+		// grab array of all plugin folders and loop thru it
343
+		$plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR);
344
+		if (empty($plugins)) {
345
+			return;
346
+		}
347
+		foreach ($plugins as $plugin_path) {
348
+			// grab plugin folder name from path
349
+			$plugin = basename($plugin_path);
350
+			// drill down to Espresso plugins
351
+			// then to calendar related plugins
352
+			if (
353
+				strpos($plugin, 'espresso') !== false
354
+				|| strpos($plugin, 'Espresso') !== false
355
+				|| strpos($plugin, 'ee4') !== false
356
+				|| strpos($plugin, 'EE4') !== false
357
+				|| strpos($plugin, 'calendar') !== false
358
+			) {
359
+				// this is what we are looking for
360
+				$calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php';
361
+				// does it exist in this folder ?
362
+				if (is_readable($calendar_config)) {
363
+					// YEAH! let's load it
364
+					require_once($calendar_config);
365
+				}
366
+			}
367
+		}
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 *    _migrate_old_config_data
374
+	 *
375
+	 * @access    public
376
+	 * @param array|stdClass $settings
377
+	 * @param string         $config
378
+	 * @param \EE_Config     $EE_Config
379
+	 * @return \stdClass
380
+	 */
381
+	public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config)
382
+	{
383
+		$convert_from_array = array('addons');
384
+		// in case old settings were saved as an array
385
+		if (is_array($settings) && in_array($config, $convert_from_array)) {
386
+			// convert existing settings to an object
387
+			$config_array = $settings;
388
+			$settings = new stdClass();
389
+			foreach ($config_array as $key => $value) {
390
+				if ($key === 'calendar' && class_exists('EE_Calendar_Config')) {
391
+					$EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value);
392
+				} else {
393
+					$settings->{$key} = $value;
394
+				}
395
+			}
396
+			add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true');
397
+		}
398
+		return $settings;
399
+	}
400
+
401
+
402
+	/**
403
+	 * deactivate_event_espresso
404
+	 *
405
+	 * @access public
406
+	 * @static
407
+	 * @return void
408
+	 */
409
+	public static function deactivate_event_espresso()
410
+	{
411
+		// check permissions
412
+		if (current_user_can('activate_plugins')) {
413
+			deactivate_plugins(EE_PLUGIN_BASENAME, true);
414
+		}
415
+	}
416
+
417
+
418
+
419
+
420
+
421
+	/**
422
+	 * verify_default_pages_exist
423
+	 *
424
+	 * @access public
425
+	 * @static
426
+	 * @return void
427
+	 */
428
+	public static function verify_default_pages_exist()
429
+	{
430
+		$critical_page_problem = false;
431
+		$critical_pages = array(
432
+			array(
433
+				'id'   => 'reg_page_id',
434
+				'name' => __('Registration Checkout', 'event_espresso'),
435
+				'post' => null,
436
+				'code' => 'ESPRESSO_CHECKOUT',
437
+			),
438
+			array(
439
+				'id'   => 'txn_page_id',
440
+				'name' => __('Transactions', 'event_espresso'),
441
+				'post' => null,
442
+				'code' => 'ESPRESSO_TXN_PAGE',
443
+			),
444
+			array(
445
+				'id'   => 'thank_you_page_id',
446
+				'name' => __('Thank You', 'event_espresso'),
447
+				'post' => null,
448
+				'code' => 'ESPRESSO_THANK_YOU',
449
+			),
450
+			array(
451
+				'id'   => 'cancel_page_id',
452
+				'name' => __('Registration Cancelled', 'event_espresso'),
453
+				'post' => null,
454
+				'code' => 'ESPRESSO_CANCELLED',
455
+			),
456
+		);
457
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
458
+		foreach ($critical_pages as $critical_page) {
459
+			// is critical page ID set in config ?
460
+			if ($EE_Core_Config->{$critical_page['id']} !== false) {
461
+				// attempt to find post by ID
462
+				$critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']});
463
+			}
464
+			// no dice?
465
+			if ($critical_page['post'] === null) {
466
+				// attempt to find post by title
467
+				$critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']);
468
+				// still nothing?
469
+				if ($critical_page['post'] === null) {
470
+					$critical_page = EEH_Activation::create_critical_page($critical_page);
471
+					// REALLY? Still nothing ??!?!?
472
+					if ($critical_page['post'] === null) {
473
+						$msg = __(
474
+							'The Event Espresso critical page configuration settings could not be updated.',
475
+							'event_espresso'
476
+						);
477
+						EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
478
+						break;
479
+					}
480
+				}
481
+			}
482
+			// track post_shortcodes
483
+			if ($critical_page['post']) {
484
+				EEH_Activation::_track_critical_page_post_shortcodes($critical_page);
485
+			}
486
+			// check that Post ID matches critical page ID in config
487
+			if (
488
+				isset($critical_page['post']->ID)
489
+				&& $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']}
490
+			) {
491
+				//update Config with post ID
492
+				$EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID;
493
+				if (! EE_Config::instance()->update_espresso_config(false, false)) {
494
+					$msg = __(
495
+						'The Event Espresso critical page configuration settings could not be updated.',
496
+						'event_espresso'
497
+					);
498
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
499
+				}
500
+			}
501
+			$critical_page_problem =
502
+				! isset($critical_page['post']->post_status)
503
+				|| $critical_page['post']->post_status !== 'publish'
504
+				|| strpos($critical_page['post']->post_content, $critical_page['code']) === false
505
+					? true
506
+					: $critical_page_problem;
507
+		}
508
+		if ($critical_page_problem) {
509
+			$msg = sprintf(
510
+				__(
511
+					'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.',
512
+					'event_espresso'
513
+				),
514
+				'<a href="'
515
+				. admin_url('admin.php?page=espresso_general_settings&action=critical_pages')
516
+				. '">'
517
+				. __('Event Espresso Critical Pages Settings', 'event_espresso')
518
+				. '</a>'
519
+			);
520
+			EE_Error::add_persistent_admin_notice('critical_page_problem', $msg);
521
+		}
522
+		if (EE_Error::has_notices()) {
523
+			EE_Error::get_notices(false, true, true);
524
+		}
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 * Returns the first post which uses the specified shortcode
531
+	 *
532
+	 * @param string $ee_shortcode usually one of the critical pages shortcodes, eg
533
+	 *                             ESPRESSO_THANK_YOU. So we will search fora post with the content
534
+	 *                             "[ESPRESSO_THANK_YOU"
535
+	 *                             (we don't search for the closing shortcode bracket because they might have added
536
+	 *                             parameter to the shortcode
537
+	 * @return WP_Post or NULl
538
+	 */
539
+	public static function get_page_by_ee_shortcode($ee_shortcode)
540
+	{
541
+		global $wpdb;
542
+		$shortcode_and_opening_bracket = '[' . $ee_shortcode;
543
+		$post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1");
544
+		if ($post_id) {
545
+			return get_post($post_id);
546
+		} else {
547
+			return null;
548
+		}
549
+	}
550
+
551
+
552
+	/**
553
+	 *    This function generates a post for critical espresso pages
554
+	 *
555
+	 * @access public
556
+	 * @static
557
+	 * @param array $critical_page
558
+	 * @return array
559
+	 */
560
+	public static function create_critical_page($critical_page)
561
+	{
562
+
563
+		$post_args = array(
564
+			'post_title'     => $critical_page['name'],
565
+			'post_status'    => 'publish',
566
+			'post_type'      => 'page',
567
+			'comment_status' => 'closed',
568
+			'post_content'   => '[' . $critical_page['code'] . ']',
569
+		);
570
+
571
+		$post_id = wp_insert_post($post_args);
572
+		if (! $post_id) {
573
+			$msg = sprintf(
574
+				__('The Event Espresso  critical page entitled "%s" could not be created.', 'event_espresso'),
575
+				$critical_page['name']
576
+			);
577
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
578
+			return $critical_page;
579
+		}
580
+		// get newly created post's details
581
+		if (! $critical_page['post'] = get_post($post_id)) {
582
+			$msg = sprintf(
583
+				__('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'),
584
+				$critical_page['name']
585
+			);
586
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
587
+		}
588
+
589
+		return $critical_page;
590
+
591
+	}
592
+
593
+
594
+
595
+
596
+
597
+	/**
598
+	 *    This function adds a critical page's shortcode to the post_shortcodes array
599
+	 *
600
+	 * @access private
601
+	 * @static
602
+	 * @param array $critical_page
603
+	 * @return void
604
+	 */
605
+	private static function _track_critical_page_post_shortcodes($critical_page = array())
606
+	{
607
+		// check the goods
608
+		if ( ! $critical_page['post'] instanceof WP_Post) {
609
+			$msg = sprintf(
610
+				__(
611
+					'The Event Espresso critical page shortcode for the page %s can not be tracked because it is not a WP_Post object.',
612
+					'event_espresso'
613
+				),
614
+				$critical_page['name']
615
+			);
616
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
617
+			return;
618
+		}
619
+		$EE_Core_Config = EE_Registry::instance()->CFG->core;
620
+		// map shortcode to post
621
+		$EE_Core_Config->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']] = $critical_page['post']->ID;
622
+		// and make sure it's NOT added to the WP "Posts Page"
623
+		// name of the WP Posts Page
624
+		$posts_page = EE_Config::get_page_for_posts();
625
+		if (isset($EE_Core_Config->post_shortcodes[$posts_page])) {
626
+			unset($EE_Core_Config->post_shortcodes[$posts_page][$critical_page['code']]);
627
+		}
628
+		if ($posts_page !== 'posts' && isset($EE_Core_Config->post_shortcodes['posts'])) {
629
+			unset($EE_Core_Config->post_shortcodes['posts'][$critical_page['code']]);
630
+		}
631
+		// update post_shortcode CFG
632
+		EE_Config::instance()->update_espresso_config(false, false);
633
+		// verify that saved ID in the config matches the ID for the post the shortcode is on
634
+		if (
635
+			EE_Registry::instance()->CFG->core->post_shortcodes[$critical_page['post']->post_name][$critical_page['code']]
636
+			!== $critical_page['post']->ID
637
+		) {
638
+			$msg = sprintf(
639
+				__(
640
+					'The Event Espresso critical page shortcode for the %s page could not be configured properly.',
641
+					'event_espresso'
642
+				),
643
+				$critical_page['name']
644
+			);
645
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
646
+		}
647
+	}
648
+
649
+
650
+
651
+	/**
652
+	 * Tries to find the oldest admin for this site.  If there are no admins for this site then return NULL.
653
+	 * The role being used to check is filterable.
654
+	 *
655
+	 * @since  4.6.0
656
+	 * @global WPDB $wpdb
657
+	 * @return mixed null|int WP_user ID or NULL
658
+	 */
659
+	public static function get_default_creator_id()
660
+	{
661
+		global $wpdb;
662
+		if ( ! empty(self::$_default_creator_id)) {
663
+			return self::$_default_creator_id;
664
+		}/**/
665
+		$role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator');
666
+		//let's allow pre_filtering for early exits by alternative methods for getting id.  We check for truthy result and if so then exit early.
667
+		$pre_filtered_id = apply_filters(
668
+			'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id',
669
+			false,
670
+			$role_to_check
671
+		);
672
+		if ($pre_filtered_id !== false) {
673
+			return (int)$pre_filtered_id;
674
+		}
675
+		$capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities');
676
+		$query = $wpdb->prepare(
677
+			"SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1",
678
+			'%' . $role_to_check . '%'
679
+		);
680
+		$user_id = $wpdb->get_var($query);
681
+		$user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id);
682
+		if ($user_id && (int)$user_id) {
683
+			self::$_default_creator_id = (int)$user_id;
684
+			return self::$_default_creator_id;
685
+		} else {
686
+			return null;
687
+		}
688
+	}
689
+
690
+
691
+
692
+	/**
693
+	 * used by EE and EE addons during plugin activation to create tables.
694
+	 * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable,
695
+	 * but includes extra logic regarding activations.
696
+	 *
697
+	 * @access public
698
+	 * @static
699
+	 * @param string  $table_name              without the $wpdb->prefix
700
+	 * @param string  $sql                     SQL for creating the table (contents between brackets in an SQL create
701
+	 *                                         table query)
702
+	 * @param string  $engine                  like 'ENGINE=MyISAM' or 'ENGINE=InnoDB'
703
+	 * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty
704
+	 *                                         and new once this function is done (ie, you really do want to CREATE a
705
+	 *                                         table, and expect it to be empty once you're done) leave as FALSE when
706
+	 *                                         you just want to verify the table exists and matches this definition
707
+	 *                                         (and if it HAS data in it you want to leave it be)
708
+	 * @return void
709
+	 * @throws EE_Error if there are database errors
710
+	 */
711
+	public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false)
712
+	{
713
+		if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) {
714
+			return;
715
+		}
716
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
717
+		if ( ! function_exists('dbDelta')) {
718
+			require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
719
+		}
720
+		$tableAnalysis = \EEH_Activation::getTableAnalysis();
721
+		$wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name);
722
+		// do we need to first delete an existing version of this table ?
723
+		if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) {
724
+			// ok, delete the table... but ONLY if it's empty
725
+			$deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name);
726
+			// table is NOT empty, are you SURE you want to delete this table ???
727
+			if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) {
728
+				\EEH_Activation::getTableManager()->dropTable($wp_table_name);
729
+			} else if ( ! $deleted_safely) {
730
+				// so we should be more cautious rather than just dropping tables so easily
731
+				error_log(
732
+					sprintf(
733
+						__(
734
+							'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.',
735
+							'event_espresso'
736
+						),
737
+						$wp_table_name,
738
+						'<br/>',
739
+						'espresso_db_update'
740
+					)
741
+				);
742
+			}
743
+		}
744
+		$engine = str_replace('ENGINE=', '', $engine);
745
+		\EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine);
746
+	}
747
+
748
+
749
+
750
+	/**
751
+	 *    add_column_if_it_doesn't_exist
752
+	 *    Checks if this column already exists on the specified table. Handy for addons which want to add a column
753
+	 *
754
+	 * @access     public
755
+	 * @static
756
+	 * @deprecated instead use TableManager::addColumn()
757
+	 * @param string $table_name  (without "wp_", eg "esp_attendee"
758
+	 * @param string $column_name
759
+	 * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be
760
+	 *                            'VARCHAR(10)'
761
+	 * @return bool|int
762
+	 */
763
+	public static function add_column_if_it_doesnt_exist(
764
+		$table_name,
765
+		$column_name,
766
+		$column_info = 'INT UNSIGNED NOT NULL'
767
+	) {
768
+		return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info);
769
+	}
770
+
771
+
772
+	/**
773
+	 * get_fields_on_table
774
+	 * Gets all the fields on the database table.
775
+	 *
776
+	 * @access     public
777
+	 * @deprecated instead use TableManager::getTableColumns()
778
+	 * @static
779
+	 * @param string $table_name , without prefixed $wpdb->prefix
780
+	 * @return array of database column names
781
+	 */
782
+	public static function get_fields_on_table($table_name = null)
783
+	{
784
+		return \EEH_Activation::getTableManager()->getTableColumns($table_name);
785
+	}
786
+
787
+
788
+	/**
789
+	 * db_table_is_empty
790
+	 *
791
+	 * @access     public\
792
+	 * @deprecated instead use TableAnalysis::tableIsEmpty()
793
+	 * @static
794
+	 * @param string $table_name
795
+	 * @return bool
796
+	 */
797
+	public static function db_table_is_empty($table_name)
798
+	{
799
+		return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name);
800
+	}
801
+
802
+
803
+	/**
804
+	 * delete_db_table_if_empty
805
+	 *
806
+	 * @access public
807
+	 * @static
808
+	 * @param string $table_name
809
+	 * @return bool | int
810
+	 */
811
+	public static function delete_db_table_if_empty($table_name)
812
+	{
813
+		if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) {
814
+			return \EEH_Activation::getTableManager()->dropTable($table_name);
815
+		}
816
+		return false;
817
+	}
818
+
819
+
820
+	/**
821
+	 * delete_unused_db_table
822
+	 *
823
+	 * @access     public
824
+	 * @static
825
+	 * @deprecated instead use TableManager::dropTable()
826
+	 * @param string $table_name
827
+	 * @return bool | int
828
+	 */
829
+	public static function delete_unused_db_table($table_name)
830
+	{
831
+		return \EEH_Activation::getTableManager()->dropTable($table_name);
832
+	}
833
+
834
+
835
+	/**
836
+	 * drop_index
837
+	 *
838
+	 * @access     public
839
+	 * @static
840
+	 * @deprecated instead use TableManager::dropIndex()
841
+	 * @param string $table_name
842
+	 * @param string $index_name
843
+	 * @return bool | int
844
+	 */
845
+	public static function drop_index($table_name, $index_name)
846
+	{
847
+		return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name);
848
+	}
849
+
850
+
851
+
852
+	/**
853
+	 * create_database_tables
854
+	 *
855
+	 * @access public
856
+	 * @static
857
+	 * @throws EE_Error
858
+	 * @return boolean success (whether database is setup properly or not)
859
+	 */
860
+	public static function create_database_tables()
861
+	{
862
+		EE_Registry::instance()->load_core('Data_Migration_Manager');
863
+		//find the migration script that sets the database to be compatible with the code
864
+		$dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms();
865
+		if ($dms_name) {
866
+			$current_data_migration_script = EE_Registry::instance()->load_dms($dms_name);
867
+			$current_data_migration_script->set_migrating(false);
868
+			$current_data_migration_script->schema_changes_before_migration();
869
+			$current_data_migration_script->schema_changes_after_migration();
870
+			if ($current_data_migration_script->get_errors()) {
871
+				if (WP_DEBUG) {
872
+					foreach ($current_data_migration_script->get_errors() as $error) {
873
+						EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__);
874
+					}
875
+				} else {
876
+					EE_Error::add_error(
877
+						__(
878
+							'There were errors creating the Event Espresso database tables and Event Espresso has been 
879 879
                             deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.',
880
-                            'event_espresso'
881
-                        )
882
-                    );
883
-                }
884
-                return false;
885
-            }
886
-            EE_Data_Migration_Manager::instance()->update_current_database_state_to();
887
-        } else {
888
-            EE_Error::add_error(
889
-                __(
890
-                    'Could not determine most up-to-date data migration script from which to pull database schema
880
+							'event_espresso'
881
+						)
882
+					);
883
+				}
884
+				return false;
885
+			}
886
+			EE_Data_Migration_Manager::instance()->update_current_database_state_to();
887
+		} else {
888
+			EE_Error::add_error(
889
+				__(
890
+					'Could not determine most up-to-date data migration script from which to pull database schema
891 891
                      structure. So database is probably not setup properly',
892
-                    'event_espresso'
893
-                ),
894
-                __FILE__,
895
-                __FUNCTION__,
896
-                __LINE__
897
-            );
898
-            return false;
899
-        }
900
-        return true;
901
-    }
902
-
903
-
904
-
905
-    /**
906
-     * initialize_system_questions
907
-     *
908
-     * @access public
909
-     * @static
910
-     * @return void
911
-     */
912
-    public static function initialize_system_questions()
913
-    {
914
-        // QUESTION GROUPS
915
-        global $wpdb;
916
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
917
-        $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
918
-        // what we have
919
-        $question_groups = $wpdb->get_col($SQL);
920
-        // check the response
921
-        $question_groups = is_array($question_groups) ? $question_groups : array();
922
-        // what we should have
923
-        $QSG_systems = array(1, 2);
924
-        // loop thru what we should have and compare to what we have
925
-        foreach ($QSG_systems as $QSG_system) {
926
-            // reset values array
927
-            $QSG_values = array();
928
-            // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
929
-            if (! in_array("$QSG_system", $question_groups)) {
930
-                // add it
931
-                switch ($QSG_system) {
932
-                    case 1:
933
-                        $QSG_values = array(
934
-                            'QSG_name'            => __('Personal Information', 'event_espresso'),
935
-                            'QSG_identifier'      => 'personal-information-' . time(),
936
-                            'QSG_desc'            => '',
937
-                            'QSG_order'           => 1,
938
-                            'QSG_show_group_name' => 1,
939
-                            'QSG_show_group_desc' => 1,
940
-                            'QSG_system'          => EEM_Question_Group::system_personal,
941
-                            'QSG_deleted'         => 0,
942
-                        );
943
-                        break;
944
-                    case 2:
945
-                        $QSG_values = array(
946
-                            'QSG_name'            => __('Address Information', 'event_espresso'),
947
-                            'QSG_identifier'      => 'address-information-' . time(),
948
-                            'QSG_desc'            => '',
949
-                            'QSG_order'           => 2,
950
-                            'QSG_show_group_name' => 1,
951
-                            'QSG_show_group_desc' => 1,
952
-                            'QSG_system'          => EEM_Question_Group::system_address,
953
-                            'QSG_deleted'         => 0,
954
-                        );
955
-                        break;
956
-                }
957
-                // make sure we have some values before inserting them
958
-                if (! empty($QSG_values)) {
959
-                    // insert system question
960
-                    $wpdb->insert(
961
-                        $table_name,
962
-                        $QSG_values,
963
-                        array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
964
-                    );
965
-                    $QSG_IDs[$QSG_system] = $wpdb->insert_id;
966
-                }
967
-            }
968
-        }
969
-        // QUESTIONS
970
-        global $wpdb;
971
-        $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
972
-        $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
973
-        // what we have
974
-        $questions = $wpdb->get_col($SQL);
975
-        // what we should have
976
-        $QST_systems = array(
977
-            'fname',
978
-            'lname',
979
-            'email',
980
-            'address',
981
-            'address2',
982
-            'city',
983
-            'country',
984
-            'state',
985
-            'zip',
986
-            'phone',
987
-        );
988
-        $order_for_group_1 = 1;
989
-        $order_for_group_2 = 1;
990
-        // loop thru what we should have and compare to what we have
991
-        foreach ($QST_systems as $QST_system) {
992
-            // reset values array
993
-            $QST_values = array();
994
-            // if we don't have what we should have
995
-            if (! in_array($QST_system, $questions)) {
996
-                // add it
997
-                switch ($QST_system) {
998
-                    case 'fname':
999
-                        $QST_values = array(
1000
-                            'QST_display_text'  => __('First Name', 'event_espresso'),
1001
-                            'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
1002
-                            'QST_system'        => 'fname',
1003
-                            'QST_type'          => 'TEXT',
1004
-                            'QST_required'      => 1,
1005
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1006
-                            'QST_order'         => 1,
1007
-                            'QST_admin_only'    => 0,
1008
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1009
-                            'QST_wp_user'       => self::get_default_creator_id(),
1010
-                            'QST_deleted'       => 0,
1011
-                        );
1012
-                        break;
1013
-                    case 'lname':
1014
-                        $QST_values = array(
1015
-                            'QST_display_text'  => __('Last Name', 'event_espresso'),
1016
-                            'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
1017
-                            'QST_system'        => 'lname',
1018
-                            'QST_type'          => 'TEXT',
1019
-                            'QST_required'      => 1,
1020
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1021
-                            'QST_order'         => 2,
1022
-                            'QST_admin_only'    => 0,
1023
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1024
-                            'QST_wp_user'       => self::get_default_creator_id(),
1025
-                            'QST_deleted'       => 0,
1026
-                        );
1027
-                        break;
1028
-                    case 'email':
1029
-                        $QST_values = array(
1030
-                            'QST_display_text'  => __('Email Address', 'event_espresso'),
1031
-                            'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
1032
-                            'QST_system'        => 'email',
1033
-                            'QST_type'          => 'EMAIL',
1034
-                            'QST_required'      => 1,
1035
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1036
-                            'QST_order'         => 3,
1037
-                            'QST_admin_only'    => 0,
1038
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1039
-                            'QST_wp_user'       => self::get_default_creator_id(),
1040
-                            'QST_deleted'       => 0,
1041
-                        );
1042
-                        break;
1043
-                    case 'address':
1044
-                        $QST_values = array(
1045
-                            'QST_display_text'  => __('Address', 'event_espresso'),
1046
-                            'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
1047
-                            'QST_system'        => 'address',
1048
-                            'QST_type'          => 'TEXT',
1049
-                            'QST_required'      => 0,
1050
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1051
-                            'QST_order'         => 4,
1052
-                            'QST_admin_only'    => 0,
1053
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1054
-                            'QST_wp_user'       => self::get_default_creator_id(),
1055
-                            'QST_deleted'       => 0,
1056
-                        );
1057
-                        break;
1058
-                    case 'address2':
1059
-                        $QST_values = array(
1060
-                            'QST_display_text'  => __('Address2', 'event_espresso'),
1061
-                            'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1062
-                            'QST_system'        => 'address2',
1063
-                            'QST_type'          => 'TEXT',
1064
-                            'QST_required'      => 0,
1065
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1066
-                            'QST_order'         => 5,
1067
-                            'QST_admin_only'    => 0,
1068
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1069
-                            'QST_wp_user'       => self::get_default_creator_id(),
1070
-                            'QST_deleted'       => 0,
1071
-                        );
1072
-                        break;
1073
-                    case 'city':
1074
-                        $QST_values = array(
1075
-                            'QST_display_text'  => __('City', 'event_espresso'),
1076
-                            'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1077
-                            'QST_system'        => 'city',
1078
-                            'QST_type'          => 'TEXT',
1079
-                            'QST_required'      => 0,
1080
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1081
-                            'QST_order'         => 6,
1082
-                            'QST_admin_only'    => 0,
1083
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1084
-                            'QST_wp_user'       => self::get_default_creator_id(),
1085
-                            'QST_deleted'       => 0,
1086
-                        );
1087
-                        break;
1088
-                    case 'country':
1089
-                        $QST_values = array(
1090
-                            'QST_display_text'  => __('Country', 'event_espresso'),
1091
-                            'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1092
-                            'QST_system'        => 'country',
1093
-                            'QST_type'          => 'COUNTRY',
1094
-                            'QST_required'      => 0,
1095
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1096
-                            'QST_order'         => 7,
1097
-                            'QST_admin_only'    => 0,
1098
-                            'QST_wp_user'       => self::get_default_creator_id(),
1099
-                            'QST_deleted'       => 0,
1100
-                        );
1101
-                        break;
1102
-                    case 'state':
1103
-                        $QST_values = array(
1104
-                            'QST_display_text'  => __('State/Province', 'event_espresso'),
1105
-                            'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1106
-                            'QST_system'        => 'state',
1107
-                            'QST_type'          => 'STATE',
1108
-                            'QST_required'      => 0,
1109
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1110
-                            'QST_order'         => 8,
1111
-                            'QST_admin_only'    => 0,
1112
-                            'QST_wp_user'       => self::get_default_creator_id(),
1113
-                            'QST_deleted'       => 0,
1114
-                        );
1115
-                        break;
1116
-                    case 'zip':
1117
-                        $QST_values = array(
1118
-                            'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1119
-                            'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1120
-                            'QST_system'        => 'zip',
1121
-                            'QST_type'          => 'TEXT',
1122
-                            'QST_required'      => 0,
1123
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1124
-                            'QST_order'         => 9,
1125
-                            'QST_admin_only'    => 0,
1126
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1127
-                            'QST_wp_user'       => self::get_default_creator_id(),
1128
-                            'QST_deleted'       => 0,
1129
-                        );
1130
-                        break;
1131
-                    case 'phone':
1132
-                        $QST_values = array(
1133
-                            'QST_display_text'  => __('Phone Number', 'event_espresso'),
1134
-                            'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1135
-                            'QST_system'        => 'phone',
1136
-                            'QST_type'          => 'TEXT',
1137
-                            'QST_required'      => 0,
1138
-                            'QST_required_text' => __('This field is required', 'event_espresso'),
1139
-                            'QST_order'         => 10,
1140
-                            'QST_admin_only'    => 0,
1141
-                            'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1142
-                            'QST_wp_user'       => self::get_default_creator_id(),
1143
-                            'QST_deleted'       => 0,
1144
-                        );
1145
-                        break;
1146
-                }
1147
-                if (! empty($QST_values)) {
1148
-                    // insert system question
1149
-                    $wpdb->insert(
1150
-                        $table_name,
1151
-                        $QST_values,
1152
-                        array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1153
-                    );
1154
-                    $QST_ID = $wpdb->insert_id;
1155
-                    // QUESTION GROUP QUESTIONS
1156
-                    if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1157
-                        $system_question_we_want = EEM_Question_Group::system_personal;
1158
-                    } else {
1159
-                        $system_question_we_want = EEM_Question_Group::system_address;
1160
-                    }
1161
-                    if (isset($QSG_IDs[$system_question_we_want])) {
1162
-                        $QSG_ID = $QSG_IDs[$system_question_we_want];
1163
-                    } else {
1164
-                        $id_col = EEM_Question_Group::instance()
1165
-                                                    ->get_col(array(array('QSG_system' => $system_question_we_want)));
1166
-                        if (is_array($id_col)) {
1167
-                            $QSG_ID = reset($id_col);
1168
-                        } else {
1169
-                            //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1170
-                            EE_Log::instance()->log(
1171
-                                __FILE__,
1172
-                                __FUNCTION__,
1173
-                                sprintf(
1174
-                                    __(
1175
-                                        'Could not associate question %1$s to a question group because no system question
892
+					'event_espresso'
893
+				),
894
+				__FILE__,
895
+				__FUNCTION__,
896
+				__LINE__
897
+			);
898
+			return false;
899
+		}
900
+		return true;
901
+	}
902
+
903
+
904
+
905
+	/**
906
+	 * initialize_system_questions
907
+	 *
908
+	 * @access public
909
+	 * @static
910
+	 * @return void
911
+	 */
912
+	public static function initialize_system_questions()
913
+	{
914
+		// QUESTION GROUPS
915
+		global $wpdb;
916
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group');
917
+		$SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0";
918
+		// what we have
919
+		$question_groups = $wpdb->get_col($SQL);
920
+		// check the response
921
+		$question_groups = is_array($question_groups) ? $question_groups : array();
922
+		// what we should have
923
+		$QSG_systems = array(1, 2);
924
+		// loop thru what we should have and compare to what we have
925
+		foreach ($QSG_systems as $QSG_system) {
926
+			// reset values array
927
+			$QSG_values = array();
928
+			// if we don't have what we should have (but use $QST_system as as string because that's what we got from the db)
929
+			if (! in_array("$QSG_system", $question_groups)) {
930
+				// add it
931
+				switch ($QSG_system) {
932
+					case 1:
933
+						$QSG_values = array(
934
+							'QSG_name'            => __('Personal Information', 'event_espresso'),
935
+							'QSG_identifier'      => 'personal-information-' . time(),
936
+							'QSG_desc'            => '',
937
+							'QSG_order'           => 1,
938
+							'QSG_show_group_name' => 1,
939
+							'QSG_show_group_desc' => 1,
940
+							'QSG_system'          => EEM_Question_Group::system_personal,
941
+							'QSG_deleted'         => 0,
942
+						);
943
+						break;
944
+					case 2:
945
+						$QSG_values = array(
946
+							'QSG_name'            => __('Address Information', 'event_espresso'),
947
+							'QSG_identifier'      => 'address-information-' . time(),
948
+							'QSG_desc'            => '',
949
+							'QSG_order'           => 2,
950
+							'QSG_show_group_name' => 1,
951
+							'QSG_show_group_desc' => 1,
952
+							'QSG_system'          => EEM_Question_Group::system_address,
953
+							'QSG_deleted'         => 0,
954
+						);
955
+						break;
956
+				}
957
+				// make sure we have some values before inserting them
958
+				if (! empty($QSG_values)) {
959
+					// insert system question
960
+					$wpdb->insert(
961
+						$table_name,
962
+						$QSG_values,
963
+						array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')
964
+					);
965
+					$QSG_IDs[$QSG_system] = $wpdb->insert_id;
966
+				}
967
+			}
968
+		}
969
+		// QUESTIONS
970
+		global $wpdb;
971
+		$table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question');
972
+		$SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''";
973
+		// what we have
974
+		$questions = $wpdb->get_col($SQL);
975
+		// what we should have
976
+		$QST_systems = array(
977
+			'fname',
978
+			'lname',
979
+			'email',
980
+			'address',
981
+			'address2',
982
+			'city',
983
+			'country',
984
+			'state',
985
+			'zip',
986
+			'phone',
987
+		);
988
+		$order_for_group_1 = 1;
989
+		$order_for_group_2 = 1;
990
+		// loop thru what we should have and compare to what we have
991
+		foreach ($QST_systems as $QST_system) {
992
+			// reset values array
993
+			$QST_values = array();
994
+			// if we don't have what we should have
995
+			if (! in_array($QST_system, $questions)) {
996
+				// add it
997
+				switch ($QST_system) {
998
+					case 'fname':
999
+						$QST_values = array(
1000
+							'QST_display_text'  => __('First Name', 'event_espresso'),
1001
+							'QST_admin_label'   => __('First Name - System Question', 'event_espresso'),
1002
+							'QST_system'        => 'fname',
1003
+							'QST_type'          => 'TEXT',
1004
+							'QST_required'      => 1,
1005
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1006
+							'QST_order'         => 1,
1007
+							'QST_admin_only'    => 0,
1008
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1009
+							'QST_wp_user'       => self::get_default_creator_id(),
1010
+							'QST_deleted'       => 0,
1011
+						);
1012
+						break;
1013
+					case 'lname':
1014
+						$QST_values = array(
1015
+							'QST_display_text'  => __('Last Name', 'event_espresso'),
1016
+							'QST_admin_label'   => __('Last Name - System Question', 'event_espresso'),
1017
+							'QST_system'        => 'lname',
1018
+							'QST_type'          => 'TEXT',
1019
+							'QST_required'      => 1,
1020
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1021
+							'QST_order'         => 2,
1022
+							'QST_admin_only'    => 0,
1023
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1024
+							'QST_wp_user'       => self::get_default_creator_id(),
1025
+							'QST_deleted'       => 0,
1026
+						);
1027
+						break;
1028
+					case 'email':
1029
+						$QST_values = array(
1030
+							'QST_display_text'  => __('Email Address', 'event_espresso'),
1031
+							'QST_admin_label'   => __('Email Address - System Question', 'event_espresso'),
1032
+							'QST_system'        => 'email',
1033
+							'QST_type'          => 'EMAIL',
1034
+							'QST_required'      => 1,
1035
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1036
+							'QST_order'         => 3,
1037
+							'QST_admin_only'    => 0,
1038
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1039
+							'QST_wp_user'       => self::get_default_creator_id(),
1040
+							'QST_deleted'       => 0,
1041
+						);
1042
+						break;
1043
+					case 'address':
1044
+						$QST_values = array(
1045
+							'QST_display_text'  => __('Address', 'event_espresso'),
1046
+							'QST_admin_label'   => __('Address - System Question', 'event_espresso'),
1047
+							'QST_system'        => 'address',
1048
+							'QST_type'          => 'TEXT',
1049
+							'QST_required'      => 0,
1050
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1051
+							'QST_order'         => 4,
1052
+							'QST_admin_only'    => 0,
1053
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1054
+							'QST_wp_user'       => self::get_default_creator_id(),
1055
+							'QST_deleted'       => 0,
1056
+						);
1057
+						break;
1058
+					case 'address2':
1059
+						$QST_values = array(
1060
+							'QST_display_text'  => __('Address2', 'event_espresso'),
1061
+							'QST_admin_label'   => __('Address2 - System Question', 'event_espresso'),
1062
+							'QST_system'        => 'address2',
1063
+							'QST_type'          => 'TEXT',
1064
+							'QST_required'      => 0,
1065
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1066
+							'QST_order'         => 5,
1067
+							'QST_admin_only'    => 0,
1068
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1069
+							'QST_wp_user'       => self::get_default_creator_id(),
1070
+							'QST_deleted'       => 0,
1071
+						);
1072
+						break;
1073
+					case 'city':
1074
+						$QST_values = array(
1075
+							'QST_display_text'  => __('City', 'event_espresso'),
1076
+							'QST_admin_label'   => __('City - System Question', 'event_espresso'),
1077
+							'QST_system'        => 'city',
1078
+							'QST_type'          => 'TEXT',
1079
+							'QST_required'      => 0,
1080
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1081
+							'QST_order'         => 6,
1082
+							'QST_admin_only'    => 0,
1083
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1084
+							'QST_wp_user'       => self::get_default_creator_id(),
1085
+							'QST_deleted'       => 0,
1086
+						);
1087
+						break;
1088
+					case 'country':
1089
+						$QST_values = array(
1090
+							'QST_display_text'  => __('Country', 'event_espresso'),
1091
+							'QST_admin_label'   => __('Country - System Question', 'event_espresso'),
1092
+							'QST_system'        => 'country',
1093
+							'QST_type'          => 'COUNTRY',
1094
+							'QST_required'      => 0,
1095
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1096
+							'QST_order'         => 7,
1097
+							'QST_admin_only'    => 0,
1098
+							'QST_wp_user'       => self::get_default_creator_id(),
1099
+							'QST_deleted'       => 0,
1100
+						);
1101
+						break;
1102
+					case 'state':
1103
+						$QST_values = array(
1104
+							'QST_display_text'  => __('State/Province', 'event_espresso'),
1105
+							'QST_admin_label'   => __('State/Province - System Question', 'event_espresso'),
1106
+							'QST_system'        => 'state',
1107
+							'QST_type'          => 'STATE',
1108
+							'QST_required'      => 0,
1109
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1110
+							'QST_order'         => 8,
1111
+							'QST_admin_only'    => 0,
1112
+							'QST_wp_user'       => self::get_default_creator_id(),
1113
+							'QST_deleted'       => 0,
1114
+						);
1115
+						break;
1116
+					case 'zip':
1117
+						$QST_values = array(
1118
+							'QST_display_text'  => __('Zip/Postal Code', 'event_espresso'),
1119
+							'QST_admin_label'   => __('Zip/Postal Code - System Question', 'event_espresso'),
1120
+							'QST_system'        => 'zip',
1121
+							'QST_type'          => 'TEXT',
1122
+							'QST_required'      => 0,
1123
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1124
+							'QST_order'         => 9,
1125
+							'QST_admin_only'    => 0,
1126
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1127
+							'QST_wp_user'       => self::get_default_creator_id(),
1128
+							'QST_deleted'       => 0,
1129
+						);
1130
+						break;
1131
+					case 'phone':
1132
+						$QST_values = array(
1133
+							'QST_display_text'  => __('Phone Number', 'event_espresso'),
1134
+							'QST_admin_label'   => __('Phone Number - System Question', 'event_espresso'),
1135
+							'QST_system'        => 'phone',
1136
+							'QST_type'          => 'TEXT',
1137
+							'QST_required'      => 0,
1138
+							'QST_required_text' => __('This field is required', 'event_espresso'),
1139
+							'QST_order'         => 10,
1140
+							'QST_admin_only'    => 0,
1141
+							'QST_max'           => EEM_Question::instance()->absolute_max_for_system_question($QST_system),
1142
+							'QST_wp_user'       => self::get_default_creator_id(),
1143
+							'QST_deleted'       => 0,
1144
+						);
1145
+						break;
1146
+				}
1147
+				if (! empty($QST_values)) {
1148
+					// insert system question
1149
+					$wpdb->insert(
1150
+						$table_name,
1151
+						$QST_values,
1152
+						array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d')
1153
+					);
1154
+					$QST_ID = $wpdb->insert_id;
1155
+					// QUESTION GROUP QUESTIONS
1156
+					if (in_array($QST_system, array('fname', 'lname', 'email'))) {
1157
+						$system_question_we_want = EEM_Question_Group::system_personal;
1158
+					} else {
1159
+						$system_question_we_want = EEM_Question_Group::system_address;
1160
+					}
1161
+					if (isset($QSG_IDs[$system_question_we_want])) {
1162
+						$QSG_ID = $QSG_IDs[$system_question_we_want];
1163
+					} else {
1164
+						$id_col = EEM_Question_Group::instance()
1165
+													->get_col(array(array('QSG_system' => $system_question_we_want)));
1166
+						if (is_array($id_col)) {
1167
+							$QSG_ID = reset($id_col);
1168
+						} else {
1169
+							//ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method
1170
+							EE_Log::instance()->log(
1171
+								__FILE__,
1172
+								__FUNCTION__,
1173
+								sprintf(
1174
+									__(
1175
+										'Could not associate question %1$s to a question group because no system question
1176 1176
                                          group existed',
1177
-                                        'event_espresso'
1178
-                                    ),
1179
-                                    $QST_ID),
1180
-                                'error');
1181
-                            continue;
1182
-                        }
1183
-                    }
1184
-                    // add system questions to groups
1185
-                    $wpdb->insert(
1186
-                        \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1187
-                        array(
1188
-                            'QSG_ID'    => $QSG_ID,
1189
-                            'QST_ID'    => $QST_ID,
1190
-                            'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1191
-                        ),
1192
-                        array('%d', '%d', '%d')
1193
-                    );
1194
-                }
1195
-            }
1196
-        }
1197
-    }
1198
-
1199
-
1200
-    /**
1201
-     * Makes sure the default payment method (Invoice) is active.
1202
-     * This used to be done automatically as part of constructing the old gateways config
1203
-     *
1204
-     * @throws \EE_Error
1205
-     */
1206
-    public static function insert_default_payment_methods()
1207
-    {
1208
-        if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1209
-            EE_Registry::instance()->load_lib('Payment_Method_Manager');
1210
-            EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1211
-        } else {
1212
-            EEM_Payment_Method::instance()->verify_button_urls();
1213
-        }
1214
-    }
1215
-
1216
-    /**
1217
-     * insert_default_status_codes
1218
-     *
1219
-     * @access public
1220
-     * @static
1221
-     * @return void
1222
-     */
1223
-    public static function insert_default_status_codes()
1224
-    {
1225
-
1226
-        global $wpdb;
1227
-
1228
-        if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1229
-
1230
-            $table_name = EEM_Status::instance()->table();
1231
-
1232
-            $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1233
-            $wpdb->query($SQL);
1234
-
1235
-            $SQL = "INSERT INTO $table_name
1177
+										'event_espresso'
1178
+									),
1179
+									$QST_ID),
1180
+								'error');
1181
+							continue;
1182
+						}
1183
+					}
1184
+					// add system questions to groups
1185
+					$wpdb->insert(
1186
+						\EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'),
1187
+						array(
1188
+							'QSG_ID'    => $QSG_ID,
1189
+							'QST_ID'    => $QST_ID,
1190
+							'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++,
1191
+						),
1192
+						array('%d', '%d', '%d')
1193
+					);
1194
+				}
1195
+			}
1196
+		}
1197
+	}
1198
+
1199
+
1200
+	/**
1201
+	 * Makes sure the default payment method (Invoice) is active.
1202
+	 * This used to be done automatically as part of constructing the old gateways config
1203
+	 *
1204
+	 * @throws \EE_Error
1205
+	 */
1206
+	public static function insert_default_payment_methods()
1207
+	{
1208
+		if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) {
1209
+			EE_Registry::instance()->load_lib('Payment_Method_Manager');
1210
+			EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice');
1211
+		} else {
1212
+			EEM_Payment_Method::instance()->verify_button_urls();
1213
+		}
1214
+	}
1215
+
1216
+	/**
1217
+	 * insert_default_status_codes
1218
+	 *
1219
+	 * @access public
1220
+	 * @static
1221
+	 * @return void
1222
+	 */
1223
+	public static function insert_default_status_codes()
1224
+	{
1225
+
1226
+		global $wpdb;
1227
+
1228
+		if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) {
1229
+
1230
+			$table_name = EEM_Status::instance()->table();
1231
+
1232
+			$SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );";
1233
+			$wpdb->query($SQL);
1234
+
1235
+			$SQL = "INSERT INTO $table_name
1236 1236
 					(STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES
1237 1237
 					('ACT', 'ACTIVE', 'event', 0, NULL, 1),
1238 1238
 					('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0),
@@ -1272,521 +1272,521 @@  discard block
 block discarded – undo
1272 1272
 					('MID', 'IDLE', 'message', 0, NULL, 1),
1273 1273
 					('MRS', 'RESEND', 'message', 0, NULL, 1),
1274 1274
 					('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);";
1275
-            $wpdb->query($SQL);
1276
-
1277
-        }
1278
-
1279
-    }
1280
-
1281
-
1282
-    /**
1283
-     * create_upload_directories
1284
-     * Creates folders in the uploads directory to facilitate addons and templates
1285
-     *
1286
-     * @access public
1287
-     * @static
1288
-     * @return boolean success of verifying upload directories exist
1289
-     */
1290
-    public static function create_upload_directories()
1291
-    {
1292
-        // Create the required folders
1293
-        $folders = array(
1294
-            EVENT_ESPRESSO_TEMPLATE_DIR,
1295
-            EVENT_ESPRESSO_GATEWAY_DIR,
1296
-            EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1297
-            EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1298
-            EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1299
-        );
1300
-        foreach ($folders as $folder) {
1301
-            try {
1302
-                EEH_File::ensure_folder_exists_and_is_writable($folder);
1303
-                @ chmod($folder, 0755);
1304
-            } catch (EE_Error $e) {
1305
-                EE_Error::add_error(
1306
-                    sprintf(
1307
-                        __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1308
-                        $folder,
1309
-                        '<br />' . $e->getMessage()
1310
-                    ),
1311
-                    __FILE__, __FUNCTION__, __LINE__
1312
-                );
1313
-                //indicate we'll need to fix this later
1314
-                update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1315
-                return false;
1316
-            }
1317
-        }
1318
-        //just add the .htaccess file to the logs directory to begin with. Even if logging
1319
-        //is disabled, there might be activation errors recorded in there
1320
-        EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1321
-        //remember EE's folders are all good
1322
-        delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1323
-        return true;
1324
-    }
1325
-
1326
-    /**
1327
-     * Whether the upload directories need to be fixed or not.
1328
-     * If EE is installed but filesystem access isn't initially available,
1329
-     * we need to get the user's filesystem credentials and THEN create them,
1330
-     * so there might be period of time when EE is installed but its
1331
-     * upload directories aren't available. This indicates such a state
1332
-     *
1333
-     * @return boolean
1334
-     */
1335
-    public static function upload_directories_incomplete()
1336
-    {
1337
-        return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1338
-    }
1339
-
1340
-
1341
-    /**
1342
-     * generate_default_message_templates
1343
-     *
1344
-     * @static
1345
-     * @throws EE_Error
1346
-     * @return bool     true means new templates were created.
1347
-     *                  false means no templates were created.
1348
-     *                  This is NOT an error flag. To check for errors you will want
1349
-     *                  to use either EE_Error or a try catch for an EE_Error exception.
1350
-     */
1351
-    public static function generate_default_message_templates()
1352
-    {
1353
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1354
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1355
-        /*
1275
+			$wpdb->query($SQL);
1276
+
1277
+		}
1278
+
1279
+	}
1280
+
1281
+
1282
+	/**
1283
+	 * create_upload_directories
1284
+	 * Creates folders in the uploads directory to facilitate addons and templates
1285
+	 *
1286
+	 * @access public
1287
+	 * @static
1288
+	 * @return boolean success of verifying upload directories exist
1289
+	 */
1290
+	public static function create_upload_directories()
1291
+	{
1292
+		// Create the required folders
1293
+		$folders = array(
1294
+			EVENT_ESPRESSO_TEMPLATE_DIR,
1295
+			EVENT_ESPRESSO_GATEWAY_DIR,
1296
+			EVENT_ESPRESSO_UPLOAD_DIR . 'logs/',
1297
+			EVENT_ESPRESSO_UPLOAD_DIR . 'css/',
1298
+			EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/',
1299
+		);
1300
+		foreach ($folders as $folder) {
1301
+			try {
1302
+				EEH_File::ensure_folder_exists_and_is_writable($folder);
1303
+				@ chmod($folder, 0755);
1304
+			} catch (EE_Error $e) {
1305
+				EE_Error::add_error(
1306
+					sprintf(
1307
+						__('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'),
1308
+						$folder,
1309
+						'<br />' . $e->getMessage()
1310
+					),
1311
+					__FILE__, __FUNCTION__, __LINE__
1312
+				);
1313
+				//indicate we'll need to fix this later
1314
+				update_option(EEH_Activation::upload_directories_incomplete_option_name, true);
1315
+				return false;
1316
+			}
1317
+		}
1318
+		//just add the .htaccess file to the logs directory to begin with. Even if logging
1319
+		//is disabled, there might be activation errors recorded in there
1320
+		EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/');
1321
+		//remember EE's folders are all good
1322
+		delete_option(EEH_Activation::upload_directories_incomplete_option_name);
1323
+		return true;
1324
+	}
1325
+
1326
+	/**
1327
+	 * Whether the upload directories need to be fixed or not.
1328
+	 * If EE is installed but filesystem access isn't initially available,
1329
+	 * we need to get the user's filesystem credentials and THEN create them,
1330
+	 * so there might be period of time when EE is installed but its
1331
+	 * upload directories aren't available. This indicates such a state
1332
+	 *
1333
+	 * @return boolean
1334
+	 */
1335
+	public static function upload_directories_incomplete()
1336
+	{
1337
+		return get_option(EEH_Activation::upload_directories_incomplete_option_name, false);
1338
+	}
1339
+
1340
+
1341
+	/**
1342
+	 * generate_default_message_templates
1343
+	 *
1344
+	 * @static
1345
+	 * @throws EE_Error
1346
+	 * @return bool     true means new templates were created.
1347
+	 *                  false means no templates were created.
1348
+	 *                  This is NOT an error flag. To check for errors you will want
1349
+	 *                  to use either EE_Error or a try catch for an EE_Error exception.
1350
+	 */
1351
+	public static function generate_default_message_templates()
1352
+	{
1353
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1354
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1355
+		/*
1356 1356
          * This first method is taking care of ensuring any default messengers
1357 1357
          * that should be made active and have templates generated are done.
1358 1358
          */
1359
-        $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1360
-            $message_resource_manager
1361
-        );
1362
-        /**
1363
-         * This method is verifying there are no NEW default message types
1364
-         * for ACTIVE messengers that need activated (and corresponding templates setup).
1365
-         */
1366
-        $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1367
-            $message_resource_manager
1368
-        );
1369
-        //after all is done, let's persist these changes to the db.
1370
-        $message_resource_manager->update_has_activated_messengers_option();
1371
-        $message_resource_manager->update_active_messengers_option();
1372
-        // will return true if either of these are true.  Otherwise will return false.
1373
-        return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1374
-    }
1375
-
1376
-
1377
-
1378
-    /**
1379
-     * @param \EE_Message_Resource_Manager $message_resource_manager
1380
-     * @return array|bool
1381
-     * @throws \EE_Error
1382
-     */
1383
-    protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1384
-        EE_Message_Resource_Manager $message_resource_manager
1385
-    ) {
1386
-        /** @type EE_messenger[] $active_messengers */
1387
-        $active_messengers = $message_resource_manager->active_messengers();
1388
-        $installed_message_types = $message_resource_manager->installed_message_types();
1389
-        $templates_created = false;
1390
-        foreach ($active_messengers as $active_messenger) {
1391
-            $default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1392
-            $default_message_type_names_to_activate = array();
1393
-            // looping through each default message type reported by the messenger
1394
-            // and setup the actual message types to activate.
1395
-            foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1396
-                // if already active or has already been activated before we skip
1397
-                // (otherwise we might reactivate something user's intentionally deactivated.)
1398
-                // we also skip if the message type is not installed.
1399
-                if (
1400
-                    $message_resource_manager->has_message_type_been_activated_for_messenger(
1401
-                        $default_message_type_name_for_messenger,
1402
-                        $active_messenger->name
1403
-                    )
1404
-                    || $message_resource_manager->is_message_type_active_for_messenger(
1405
-                        $active_messenger->name,
1406
-                        $default_message_type_name_for_messenger
1407
-                    )
1408
-                    || ! isset($installed_message_types[$default_message_type_name_for_messenger])
1409
-                ) {
1410
-                    continue;
1411
-                }
1412
-                $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1413
-            }
1414
-            //let's activate!
1415
-            $message_resource_manager->ensure_message_types_are_active(
1416
-                $default_message_type_names_to_activate,
1417
-                $active_messenger->name,
1418
-                false
1419
-            );
1420
-            //activate the templates for these message types
1421
-            if ( ! empty($default_message_type_names_to_activate)) {
1422
-                $templates_created = EEH_MSG_Template::generate_new_templates(
1423
-                    $active_messenger->name,
1424
-                    $default_message_type_names_for_messenger,
1425
-                    '',
1426
-                    true
1427
-                );
1428
-            }
1429
-        }
1430
-        return $templates_created;
1431
-    }
1432
-
1433
-
1434
-
1435
-    /**
1436
-     * This will activate and generate default messengers and default message types for those messengers.
1437
-     *
1438
-     * @param EE_message_Resource_Manager $message_resource_manager
1439
-     * @return array|bool  True means there were default messengers and message type templates generated.
1440
-     *                     False means that there were no templates generated
1441
-     *                     (which could simply mean there are no default message types for a messenger).
1442
-     * @throws EE_Error
1443
-     */
1444
-    protected static function _activate_and_generate_default_messengers_and_message_templates(
1445
-        EE_Message_Resource_Manager $message_resource_manager
1446
-    ) {
1447
-        /** @type EE_messenger[] $messengers_to_generate */
1448
-        $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1449
-        $installed_message_types = $message_resource_manager->installed_message_types();
1450
-        $templates_generated = false;
1451
-        foreach ($messengers_to_generate as $messenger_to_generate) {
1452
-            $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1453
-            //verify the default message types match an installed message type.
1454
-            foreach ($default_message_type_names_for_messenger as $key => $name) {
1455
-                if (
1456
-                    ! isset($installed_message_types[$name])
1457
-                    || $message_resource_manager->has_message_type_been_activated_for_messenger(
1458
-                        $name,
1459
-                        $messenger_to_generate->name
1460
-                    )
1461
-                ) {
1462
-                    unset($default_message_type_names_for_messenger[$key]);
1463
-                }
1464
-            }
1465
-            // in previous iterations, the active_messengers option in the db
1466
-            // needed updated before calling create templates. however with the changes this may not be necessary.
1467
-            // This comment is left here just in case we discover that we _do_ need to update before
1468
-            // passing off to create templates (after the refactor is done).
1469
-            // @todo remove this comment when determined not necessary.
1470
-            $message_resource_manager->activate_messenger(
1471
-                $messenger_to_generate->name,
1472
-                $default_message_type_names_for_messenger,
1473
-                false
1474
-            );
1475
-            //create any templates needing created (or will reactivate templates already generated as necessary).
1476
-            if ( ! empty($default_message_type_names_for_messenger)) {
1477
-                $templates_generated = EEH_MSG_Template::generate_new_templates(
1478
-                    $messenger_to_generate->name,
1479
-                    $default_message_type_names_for_messenger,
1480
-                    '',
1481
-                    true
1482
-                );
1483
-            }
1484
-        }
1485
-        return $templates_generated;
1486
-    }
1487
-
1488
-
1489
-    /**
1490
-     * This returns the default messengers to generate templates for on activation of EE.
1491
-     * It considers:
1492
-     * - whether a messenger is already active in the db.
1493
-     * - whether a messenger has been made active at any time in the past.
1494
-     *
1495
-     * @static
1496
-     * @param  EE_Message_Resource_Manager $message_resource_manager
1497
-     * @return EE_messenger[]
1498
-     */
1499
-    protected static function _get_default_messengers_to_generate_on_activation(
1500
-        EE_Message_Resource_Manager $message_resource_manager
1501
-    ) {
1502
-        $active_messengers    = $message_resource_manager->active_messengers();
1503
-        $installed_messengers = $message_resource_manager->installed_messengers();
1504
-        $has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1505
-
1506
-        $messengers_to_generate = array();
1507
-        foreach ($installed_messengers as $installed_messenger) {
1508
-            //if installed messenger is a messenger that should be activated on install
1509
-            //and is not already active
1510
-            //and has never been activated
1511
-            if (
1512
-                ! $installed_messenger->activate_on_install
1513
-                || isset($active_messengers[$installed_messenger->name])
1514
-                || isset($has_activated[$installed_messenger->name])
1515
-            ) {
1516
-                continue;
1517
-            }
1518
-            $messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1519
-        }
1520
-        return $messengers_to_generate;
1521
-    }
1522
-
1523
-
1524
-    /**
1525
-     * This simply validates active message types to ensure they actually match installed
1526
-     * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1527
-     * rows are set inactive.
1528
-     * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1529
-     * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1530
-     * are still handled in here.
1531
-     *
1532
-     * @since 4.3.1
1533
-     * @return void
1534
-     */
1535
-    public static function validate_messages_system()
1536
-    {
1537
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
1538
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1539
-        $message_resource_manager->validate_active_message_types_are_installed();
1540
-        do_action('AHEE__EEH_Activation__validate_messages_system');
1541
-    }
1542
-
1543
-
1544
-    /**
1545
-     * create_no_ticket_prices_array
1546
-     *
1547
-     * @access public
1548
-     * @static
1549
-     * @return void
1550
-     */
1551
-    public static function create_no_ticket_prices_array()
1552
-    {
1553
-        // this creates an array for tracking events that have no active ticket prices created
1554
-        // this allows us to warn admins of the situation so that it can be corrected
1555
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1556
-        if (! $espresso_no_ticket_prices) {
1557
-            add_option('ee_no_ticket_prices', array(), '', false);
1558
-        }
1559
-    }
1560
-
1561
-
1562
-    /**
1563
-     * plugin_deactivation
1564
-     *
1565
-     * @access public
1566
-     * @static
1567
-     * @return void
1568
-     */
1569
-    public static function plugin_deactivation()
1570
-    {
1571
-    }
1572
-
1573
-
1574
-    /**
1575
-     * Finds all our EE4 custom post types, and deletes them and their associated data
1576
-     * (like post meta or term relations)
1577
-     *
1578
-     * @global wpdb $wpdb
1579
-     * @throws \EE_Error
1580
-     */
1581
-    public static function delete_all_espresso_cpt_data()
1582
-    {
1583
-        global $wpdb;
1584
-        //get all the CPT post_types
1585
-        $ee_post_types = array();
1586
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1587
-            if (method_exists($model_name, 'instance')) {
1588
-                $model_obj = call_user_func(array($model_name, 'instance'));
1589
-                if ($model_obj instanceof EEM_CPT_Base) {
1590
-                    $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1591
-                }
1592
-            }
1593
-        }
1594
-        //get all our CPTs
1595
-        $query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1596
-        $cpt_ids = $wpdb->get_col($query);
1597
-        //delete each post meta and term relations too
1598
-        foreach ($cpt_ids as $post_id) {
1599
-            wp_delete_post($post_id, true);
1600
-        }
1601
-    }
1602
-
1603
-    /**
1604
-     * Deletes all EE custom tables
1605
-     *
1606
-     * @return array
1607
-     */
1608
-    public static function drop_espresso_tables()
1609
-    {
1610
-        $tables = array();
1611
-        // load registry
1612
-        foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1613
-            if (method_exists($model_name, 'instance')) {
1614
-                $model_obj = call_user_func(array($model_name, 'instance'));
1615
-                if ($model_obj instanceof EEM_Base) {
1616
-                    foreach ($model_obj->get_tables() as $table) {
1617
-                        if (strpos($table->get_table_name(), 'esp_')
1618
-                            &&
1619
-                            (
1620
-                                is_main_site()//main site? nuke them all
1621
-                                || ! $table->is_global()//not main site,but not global either. nuke it
1622
-                            )
1623
-                        ) {
1624
-                            $tables[] = $table->get_table_name();
1625
-                        }
1626
-                    }
1627
-                }
1628
-            }
1629
-        }
1630
-
1631
-        //there are some tables whose models were removed.
1632
-        //they should be removed when removing all EE core's data
1633
-        $tables_without_models = array(
1634
-            'esp_promotion',
1635
-            'esp_promotion_applied',
1636
-            'esp_promotion_object',
1637
-            'esp_promotion_rule',
1638
-            'esp_rule',
1639
-        );
1640
-        foreach ($tables_without_models as $table) {
1641
-            $tables[] = $table;
1642
-        }
1643
-        return \EEH_Activation::getTableManager()->dropTables($tables);
1644
-    }
1645
-
1646
-
1647
-
1648
-    /**
1649
-     * Drops all the tables mentioned in a single MYSQL query. Double-checks
1650
-     * each table name provided has a wpdb prefix attached, and that it exists.
1651
-     * Returns the list actually deleted
1652
-     *
1653
-     * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1654
-     * @global WPDB $wpdb
1655
-     * @param array $table_names
1656
-     * @return array of table names which we deleted
1657
-     */
1658
-    public static function drop_tables($table_names)
1659
-    {
1660
-        return \EEH_Activation::getTableManager()->dropTables($table_names);
1661
-    }
1662
-
1663
-
1664
-
1665
-    /**
1666
-     * plugin_uninstall
1667
-     *
1668
-     * @access public
1669
-     * @static
1670
-     * @param bool $remove_all
1671
-     * @return void
1672
-     */
1673
-    public static function delete_all_espresso_tables_and_data($remove_all = true)
1674
-    {
1675
-        global $wpdb;
1676
-        self::drop_espresso_tables();
1677
-        $wp_options_to_delete = array(
1678
-            'ee_no_ticket_prices'                => true,
1679
-            'ee_active_messengers'               => true,
1680
-            'ee_has_activated_messenger'         => true,
1681
-            'ee_flush_rewrite_rules'             => true,
1682
-            'ee_config'                          => false,
1683
-            'ee_data_migration_current_db_state' => true,
1684
-            'ee_data_migration_mapping_'         => false,
1685
-            'ee_data_migration_script_'          => false,
1686
-            'ee_data_migrations'                 => true,
1687
-            'ee_dms_map'                         => false,
1688
-            'ee_notices'                         => true,
1689
-            'lang_file_check_'                   => false,
1690
-            'ee_maintenance_mode'                => true,
1691
-            'ee_ueip_optin'                      => true,
1692
-            'ee_ueip_has_notified'               => true,
1693
-            'ee_plugin_activation_errors'        => true,
1694
-            'ee_id_mapping_from'                 => false,
1695
-            'espresso_persistent_admin_notices'  => true,
1696
-            'ee_encryption_key'                  => true,
1697
-            'pue_force_upgrade_'                 => false,
1698
-            'pue_json_error_'                    => false,
1699
-            'pue_install_key_'                   => false,
1700
-            'pue_verification_error_'            => false,
1701
-            'pu_dismissed_upgrade_'              => false,
1702
-            'external_updates-'                  => false,
1703
-            'ee_extra_data'                      => true,
1704
-            'ee_ssn_'                            => false,
1705
-            'ee_rss_'                            => false,
1706
-            'ee_rte_n_tx_'                       => false,
1707
-            'ee_pers_admin_notices'              => true,
1708
-            'ee_job_parameters_'                 => false,
1709
-            'ee_upload_directories_incomplete'   => true,
1710
-            'ee_verified_db_collations'          => true,
1711
-        );
1712
-        if (is_main_site()) {
1713
-            $wp_options_to_delete['ee_network_config'] = true;
1714
-        }
1715
-        $undeleted_options = array();
1716
-        foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1717
-            if ($no_wildcard) {
1718
-                if ( ! delete_option($option_name)) {
1719
-                    $undeleted_options[] = $option_name;
1720
-                }
1721
-            } else {
1722
-                $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1723
-                foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1724
-                    if ( ! delete_option($option_name_from_wildcard)) {
1725
-                        $undeleted_options[] = $option_name_from_wildcard;
1726
-                    }
1727
-                }
1728
-            }
1729
-        }
1730
-        //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1731
-        remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1732
-        if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1733
-            $db_update_sans_ee4 = array();
1734
-            foreach ($espresso_db_update as $version => $times_activated) {
1735
-                if ((string)$version[0] === '3') {//if its NON EE4
1736
-                    $db_update_sans_ee4[$version] = $times_activated;
1737
-                }
1738
-            }
1739
-            update_option('espresso_db_update', $db_update_sans_ee4);
1740
-        }
1741
-        $errors = '';
1742
-        if ( ! empty($undeleted_options)) {
1743
-            $errors .= sprintf(
1744
-                __('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1745
-                '<br/>',
1746
-                implode(',<br/>', $undeleted_options)
1747
-            );
1748
-        }
1749
-        if ( ! empty($errors)) {
1750
-            EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1751
-        }
1752
-    }
1753
-
1754
-    /**
1755
-     * Gets the mysql error code from the last used query by wpdb
1756
-     *
1757
-     * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1758
-     */
1759
-    public static function last_wpdb_error_code()
1760
-    {
1761
-        global $wpdb;
1762
-        if ($wpdb->use_mysqli) {
1763
-            return mysqli_errno($wpdb->dbh);
1764
-        } else {
1765
-            return mysql_errno($wpdb->dbh);
1766
-        }
1767
-    }
1768
-
1769
-    /**
1770
-     * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1771
-     *
1772
-     * @global wpdb  $wpdb
1773
-     * @deprecated instead use TableAnalysis::tableExists()
1774
-     * @param string $table_name with or without $wpdb->prefix
1775
-     * @return boolean
1776
-     */
1777
-    public static function table_exists($table_name)
1778
-    {
1779
-        return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1780
-    }
1781
-
1782
-    /**
1783
-     * Resets the cache on EEH_Activation
1784
-     */
1785
-    public static function reset()
1786
-    {
1787
-        self::$_default_creator_id                             = null;
1788
-        self::$_initialized_db_content_already_in_this_request = false;
1789
-    }
1359
+		$new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates(
1360
+			$message_resource_manager
1361
+		);
1362
+		/**
1363
+		 * This method is verifying there are no NEW default message types
1364
+		 * for ACTIVE messengers that need activated (and corresponding templates setup).
1365
+		 */
1366
+		$new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates(
1367
+			$message_resource_manager
1368
+		);
1369
+		//after all is done, let's persist these changes to the db.
1370
+		$message_resource_manager->update_has_activated_messengers_option();
1371
+		$message_resource_manager->update_active_messengers_option();
1372
+		// will return true if either of these are true.  Otherwise will return false.
1373
+		return $new_templates_created_for_message_type || $new_templates_created_for_messenger;
1374
+	}
1375
+
1376
+
1377
+
1378
+	/**
1379
+	 * @param \EE_Message_Resource_Manager $message_resource_manager
1380
+	 * @return array|bool
1381
+	 * @throws \EE_Error
1382
+	 */
1383
+	protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates(
1384
+		EE_Message_Resource_Manager $message_resource_manager
1385
+	) {
1386
+		/** @type EE_messenger[] $active_messengers */
1387
+		$active_messengers = $message_resource_manager->active_messengers();
1388
+		$installed_message_types = $message_resource_manager->installed_message_types();
1389
+		$templates_created = false;
1390
+		foreach ($active_messengers as $active_messenger) {
1391
+			$default_message_type_names_for_messenger = $active_messenger->get_default_message_types();
1392
+			$default_message_type_names_to_activate = array();
1393
+			// looping through each default message type reported by the messenger
1394
+			// and setup the actual message types to activate.
1395
+			foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) {
1396
+				// if already active or has already been activated before we skip
1397
+				// (otherwise we might reactivate something user's intentionally deactivated.)
1398
+				// we also skip if the message type is not installed.
1399
+				if (
1400
+					$message_resource_manager->has_message_type_been_activated_for_messenger(
1401
+						$default_message_type_name_for_messenger,
1402
+						$active_messenger->name
1403
+					)
1404
+					|| $message_resource_manager->is_message_type_active_for_messenger(
1405
+						$active_messenger->name,
1406
+						$default_message_type_name_for_messenger
1407
+					)
1408
+					|| ! isset($installed_message_types[$default_message_type_name_for_messenger])
1409
+				) {
1410
+					continue;
1411
+				}
1412
+				$default_message_type_names_to_activate[] = $default_message_type_name_for_messenger;
1413
+			}
1414
+			//let's activate!
1415
+			$message_resource_manager->ensure_message_types_are_active(
1416
+				$default_message_type_names_to_activate,
1417
+				$active_messenger->name,
1418
+				false
1419
+			);
1420
+			//activate the templates for these message types
1421
+			if ( ! empty($default_message_type_names_to_activate)) {
1422
+				$templates_created = EEH_MSG_Template::generate_new_templates(
1423
+					$active_messenger->name,
1424
+					$default_message_type_names_for_messenger,
1425
+					'',
1426
+					true
1427
+				);
1428
+			}
1429
+		}
1430
+		return $templates_created;
1431
+	}
1432
+
1433
+
1434
+
1435
+	/**
1436
+	 * This will activate and generate default messengers and default message types for those messengers.
1437
+	 *
1438
+	 * @param EE_message_Resource_Manager $message_resource_manager
1439
+	 * @return array|bool  True means there were default messengers and message type templates generated.
1440
+	 *                     False means that there were no templates generated
1441
+	 *                     (which could simply mean there are no default message types for a messenger).
1442
+	 * @throws EE_Error
1443
+	 */
1444
+	protected static function _activate_and_generate_default_messengers_and_message_templates(
1445
+		EE_Message_Resource_Manager $message_resource_manager
1446
+	) {
1447
+		/** @type EE_messenger[] $messengers_to_generate */
1448
+		$messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager);
1449
+		$installed_message_types = $message_resource_manager->installed_message_types();
1450
+		$templates_generated = false;
1451
+		foreach ($messengers_to_generate as $messenger_to_generate) {
1452
+			$default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types();
1453
+			//verify the default message types match an installed message type.
1454
+			foreach ($default_message_type_names_for_messenger as $key => $name) {
1455
+				if (
1456
+					! isset($installed_message_types[$name])
1457
+					|| $message_resource_manager->has_message_type_been_activated_for_messenger(
1458
+						$name,
1459
+						$messenger_to_generate->name
1460
+					)
1461
+				) {
1462
+					unset($default_message_type_names_for_messenger[$key]);
1463
+				}
1464
+			}
1465
+			// in previous iterations, the active_messengers option in the db
1466
+			// needed updated before calling create templates. however with the changes this may not be necessary.
1467
+			// This comment is left here just in case we discover that we _do_ need to update before
1468
+			// passing off to create templates (after the refactor is done).
1469
+			// @todo remove this comment when determined not necessary.
1470
+			$message_resource_manager->activate_messenger(
1471
+				$messenger_to_generate->name,
1472
+				$default_message_type_names_for_messenger,
1473
+				false
1474
+			);
1475
+			//create any templates needing created (or will reactivate templates already generated as necessary).
1476
+			if ( ! empty($default_message_type_names_for_messenger)) {
1477
+				$templates_generated = EEH_MSG_Template::generate_new_templates(
1478
+					$messenger_to_generate->name,
1479
+					$default_message_type_names_for_messenger,
1480
+					'',
1481
+					true
1482
+				);
1483
+			}
1484
+		}
1485
+		return $templates_generated;
1486
+	}
1487
+
1488
+
1489
+	/**
1490
+	 * This returns the default messengers to generate templates for on activation of EE.
1491
+	 * It considers:
1492
+	 * - whether a messenger is already active in the db.
1493
+	 * - whether a messenger has been made active at any time in the past.
1494
+	 *
1495
+	 * @static
1496
+	 * @param  EE_Message_Resource_Manager $message_resource_manager
1497
+	 * @return EE_messenger[]
1498
+	 */
1499
+	protected static function _get_default_messengers_to_generate_on_activation(
1500
+		EE_Message_Resource_Manager $message_resource_manager
1501
+	) {
1502
+		$active_messengers    = $message_resource_manager->active_messengers();
1503
+		$installed_messengers = $message_resource_manager->installed_messengers();
1504
+		$has_activated        = $message_resource_manager->get_has_activated_messengers_option();
1505
+
1506
+		$messengers_to_generate = array();
1507
+		foreach ($installed_messengers as $installed_messenger) {
1508
+			//if installed messenger is a messenger that should be activated on install
1509
+			//and is not already active
1510
+			//and has never been activated
1511
+			if (
1512
+				! $installed_messenger->activate_on_install
1513
+				|| isset($active_messengers[$installed_messenger->name])
1514
+				|| isset($has_activated[$installed_messenger->name])
1515
+			) {
1516
+				continue;
1517
+			}
1518
+			$messengers_to_generate[$installed_messenger->name] = $installed_messenger;
1519
+		}
1520
+		return $messengers_to_generate;
1521
+	}
1522
+
1523
+
1524
+	/**
1525
+	 * This simply validates active message types to ensure they actually match installed
1526
+	 * message types.  If there's a mismatch then we deactivate the message type and ensure all related db
1527
+	 * rows are set inactive.
1528
+	 * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever
1529
+	 * EE_Messenger_Resource_Manager is constructed.  Message Types are a bit more resource heavy for validation so they
1530
+	 * are still handled in here.
1531
+	 *
1532
+	 * @since 4.3.1
1533
+	 * @return void
1534
+	 */
1535
+	public static function validate_messages_system()
1536
+	{
1537
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
1538
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
1539
+		$message_resource_manager->validate_active_message_types_are_installed();
1540
+		do_action('AHEE__EEH_Activation__validate_messages_system');
1541
+	}
1542
+
1543
+
1544
+	/**
1545
+	 * create_no_ticket_prices_array
1546
+	 *
1547
+	 * @access public
1548
+	 * @static
1549
+	 * @return void
1550
+	 */
1551
+	public static function create_no_ticket_prices_array()
1552
+	{
1553
+		// this creates an array for tracking events that have no active ticket prices created
1554
+		// this allows us to warn admins of the situation so that it can be corrected
1555
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false);
1556
+		if (! $espresso_no_ticket_prices) {
1557
+			add_option('ee_no_ticket_prices', array(), '', false);
1558
+		}
1559
+	}
1560
+
1561
+
1562
+	/**
1563
+	 * plugin_deactivation
1564
+	 *
1565
+	 * @access public
1566
+	 * @static
1567
+	 * @return void
1568
+	 */
1569
+	public static function plugin_deactivation()
1570
+	{
1571
+	}
1572
+
1573
+
1574
+	/**
1575
+	 * Finds all our EE4 custom post types, and deletes them and their associated data
1576
+	 * (like post meta or term relations)
1577
+	 *
1578
+	 * @global wpdb $wpdb
1579
+	 * @throws \EE_Error
1580
+	 */
1581
+	public static function delete_all_espresso_cpt_data()
1582
+	{
1583
+		global $wpdb;
1584
+		//get all the CPT post_types
1585
+		$ee_post_types = array();
1586
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1587
+			if (method_exists($model_name, 'instance')) {
1588
+				$model_obj = call_user_func(array($model_name, 'instance'));
1589
+				if ($model_obj instanceof EEM_CPT_Base) {
1590
+					$ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type());
1591
+				}
1592
+			}
1593
+		}
1594
+		//get all our CPTs
1595
+		$query   = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")";
1596
+		$cpt_ids = $wpdb->get_col($query);
1597
+		//delete each post meta and term relations too
1598
+		foreach ($cpt_ids as $post_id) {
1599
+			wp_delete_post($post_id, true);
1600
+		}
1601
+	}
1602
+
1603
+	/**
1604
+	 * Deletes all EE custom tables
1605
+	 *
1606
+	 * @return array
1607
+	 */
1608
+	public static function drop_espresso_tables()
1609
+	{
1610
+		$tables = array();
1611
+		// load registry
1612
+		foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) {
1613
+			if (method_exists($model_name, 'instance')) {
1614
+				$model_obj = call_user_func(array($model_name, 'instance'));
1615
+				if ($model_obj instanceof EEM_Base) {
1616
+					foreach ($model_obj->get_tables() as $table) {
1617
+						if (strpos($table->get_table_name(), 'esp_')
1618
+							&&
1619
+							(
1620
+								is_main_site()//main site? nuke them all
1621
+								|| ! $table->is_global()//not main site,but not global either. nuke it
1622
+							)
1623
+						) {
1624
+							$tables[] = $table->get_table_name();
1625
+						}
1626
+					}
1627
+				}
1628
+			}
1629
+		}
1630
+
1631
+		//there are some tables whose models were removed.
1632
+		//they should be removed when removing all EE core's data
1633
+		$tables_without_models = array(
1634
+			'esp_promotion',
1635
+			'esp_promotion_applied',
1636
+			'esp_promotion_object',
1637
+			'esp_promotion_rule',
1638
+			'esp_rule',
1639
+		);
1640
+		foreach ($tables_without_models as $table) {
1641
+			$tables[] = $table;
1642
+		}
1643
+		return \EEH_Activation::getTableManager()->dropTables($tables);
1644
+	}
1645
+
1646
+
1647
+
1648
+	/**
1649
+	 * Drops all the tables mentioned in a single MYSQL query. Double-checks
1650
+	 * each table name provided has a wpdb prefix attached, and that it exists.
1651
+	 * Returns the list actually deleted
1652
+	 *
1653
+	 * @deprecated in 4.9.13. Instead use TableManager::dropTables()
1654
+	 * @global WPDB $wpdb
1655
+	 * @param array $table_names
1656
+	 * @return array of table names which we deleted
1657
+	 */
1658
+	public static function drop_tables($table_names)
1659
+	{
1660
+		return \EEH_Activation::getTableManager()->dropTables($table_names);
1661
+	}
1662
+
1663
+
1664
+
1665
+	/**
1666
+	 * plugin_uninstall
1667
+	 *
1668
+	 * @access public
1669
+	 * @static
1670
+	 * @param bool $remove_all
1671
+	 * @return void
1672
+	 */
1673
+	public static function delete_all_espresso_tables_and_data($remove_all = true)
1674
+	{
1675
+		global $wpdb;
1676
+		self::drop_espresso_tables();
1677
+		$wp_options_to_delete = array(
1678
+			'ee_no_ticket_prices'                => true,
1679
+			'ee_active_messengers'               => true,
1680
+			'ee_has_activated_messenger'         => true,
1681
+			'ee_flush_rewrite_rules'             => true,
1682
+			'ee_config'                          => false,
1683
+			'ee_data_migration_current_db_state' => true,
1684
+			'ee_data_migration_mapping_'         => false,
1685
+			'ee_data_migration_script_'          => false,
1686
+			'ee_data_migrations'                 => true,
1687
+			'ee_dms_map'                         => false,
1688
+			'ee_notices'                         => true,
1689
+			'lang_file_check_'                   => false,
1690
+			'ee_maintenance_mode'                => true,
1691
+			'ee_ueip_optin'                      => true,
1692
+			'ee_ueip_has_notified'               => true,
1693
+			'ee_plugin_activation_errors'        => true,
1694
+			'ee_id_mapping_from'                 => false,
1695
+			'espresso_persistent_admin_notices'  => true,
1696
+			'ee_encryption_key'                  => true,
1697
+			'pue_force_upgrade_'                 => false,
1698
+			'pue_json_error_'                    => false,
1699
+			'pue_install_key_'                   => false,
1700
+			'pue_verification_error_'            => false,
1701
+			'pu_dismissed_upgrade_'              => false,
1702
+			'external_updates-'                  => false,
1703
+			'ee_extra_data'                      => true,
1704
+			'ee_ssn_'                            => false,
1705
+			'ee_rss_'                            => false,
1706
+			'ee_rte_n_tx_'                       => false,
1707
+			'ee_pers_admin_notices'              => true,
1708
+			'ee_job_parameters_'                 => false,
1709
+			'ee_upload_directories_incomplete'   => true,
1710
+			'ee_verified_db_collations'          => true,
1711
+		);
1712
+		if (is_main_site()) {
1713
+			$wp_options_to_delete['ee_network_config'] = true;
1714
+		}
1715
+		$undeleted_options = array();
1716
+		foreach ($wp_options_to_delete as $option_name => $no_wildcard) {
1717
+			if ($no_wildcard) {
1718
+				if ( ! delete_option($option_name)) {
1719
+					$undeleted_options[] = $option_name;
1720
+				}
1721
+			} else {
1722
+				$option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'");
1723
+				foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) {
1724
+					if ( ! delete_option($option_name_from_wildcard)) {
1725
+						$undeleted_options[] = $option_name_from_wildcard;
1726
+					}
1727
+				}
1728
+			}
1729
+		}
1730
+		//also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it
1731
+		remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10);
1732
+		if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) {
1733
+			$db_update_sans_ee4 = array();
1734
+			foreach ($espresso_db_update as $version => $times_activated) {
1735
+				if ((string)$version[0] === '3') {//if its NON EE4
1736
+					$db_update_sans_ee4[$version] = $times_activated;
1737
+				}
1738
+			}
1739
+			update_option('espresso_db_update', $db_update_sans_ee4);
1740
+		}
1741
+		$errors = '';
1742
+		if ( ! empty($undeleted_options)) {
1743
+			$errors .= sprintf(
1744
+				__('The following wp-options could not be deleted: %s%s', 'event_espresso'),
1745
+				'<br/>',
1746
+				implode(',<br/>', $undeleted_options)
1747
+			);
1748
+		}
1749
+		if ( ! empty($errors)) {
1750
+			EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__);
1751
+		}
1752
+	}
1753
+
1754
+	/**
1755
+	 * Gets the mysql error code from the last used query by wpdb
1756
+	 *
1757
+	 * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
1758
+	 */
1759
+	public static function last_wpdb_error_code()
1760
+	{
1761
+		global $wpdb;
1762
+		if ($wpdb->use_mysqli) {
1763
+			return mysqli_errno($wpdb->dbh);
1764
+		} else {
1765
+			return mysql_errno($wpdb->dbh);
1766
+		}
1767
+	}
1768
+
1769
+	/**
1770
+	 * Checks that the database table exists. Also works on temporary tables (for unit tests mostly).
1771
+	 *
1772
+	 * @global wpdb  $wpdb
1773
+	 * @deprecated instead use TableAnalysis::tableExists()
1774
+	 * @param string $table_name with or without $wpdb->prefix
1775
+	 * @return boolean
1776
+	 */
1777
+	public static function table_exists($table_name)
1778
+	{
1779
+		return \EEH_Activation::getTableAnalysis()->tableExists($table_name);
1780
+	}
1781
+
1782
+	/**
1783
+	 * Resets the cache on EEH_Activation
1784
+	 */
1785
+	public static function reset()
1786
+	{
1787
+		self::$_default_creator_id                             = null;
1788
+		self::$_initialized_db_content_already_in_this_request = false;
1789
+	}
1790 1790
 }
1791 1791
 // End of file EEH_Activation.helper.php
1792 1792
 // Location: /helpers/EEH_Activation.core.php
Please login to merge, or discard this patch.
form_sections/strategies/display/EE_Select_Display_Strategy.strategy.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@
 block discarded – undo
81 81
 	/**
82 82
 	 * Checks if that value is the one selected
83 83
 	 * @param string|int $value unnormalized value option (string)
84
-	 * @return string
84
+	 * @return boolean
85 85
 	 */
86 86
 	protected function _check_if_option_selected( $value ){
87 87
 		return $this->_input->raw_value() === $value ? TRUE : FALSE;
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -11,49 +11,49 @@  discard block
 block discarded – undo
11 11
  * @since 				$VID:$
12 12
  *
13 13
  */
14
-class EE_Select_Display_Strategy extends EE_Display_Strategy_Base{
14
+class EE_Select_Display_Strategy extends EE_Display_Strategy_Base {
15 15
 
16 16
 	/**
17 17
 	 *
18 18
 	 * @throws EE_Error
19 19
 	 * @return string of html to display the field
20 20
 	 */
21
-	function display(){
22
-		if( ! $this->_input instanceof EE_Form_Input_With_Options_Base){
23
-			throw new EE_Error( sprintf( __( 'Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso' )));
21
+	function display() {
22
+		if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
23
+			throw new EE_Error(sprintf(__('Cannot use Select Display Strategy with an input that doesn\'t have options', 'event_espresso')));
24 24
 		}
25 25
 
26
-		$html = EEH_HTML::nl( 0, 'select' );
26
+		$html = EEH_HTML::nl(0, 'select');
27 27
 		$html .= '<select';
28
-		$html .= ' id="' . $this->_input->html_id() . '"';
29
-		$html .= ' name="' . $this->_input->html_name() . '"';
30
-		$class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class();
31
-		$html .= ' class="' . $class . '"';
28
+		$html .= ' id="'.$this->_input->html_id().'"';
29
+		$html .= ' name="'.$this->_input->html_name().'"';
30
+		$class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class();
31
+		$html .= ' class="'.$class.'"';
32 32
 		// add html5 required
33 33
 		$html .= $this->_input->required() ? ' required' : '';
34
-		$html .= ' style="' . $this->_input->html_style() . '"';
35
-		$html .= ' ' . $this->_input->other_html_attributes();
34
+		$html .= ' style="'.$this->_input->html_style().'"';
35
+		$html .= ' '.$this->_input->other_html_attributes();
36 36
 		$html .= '>';
37 37
 
38
-		if ( EEH_Array::is_multi_dimensional_array( $this->_input->options() )) {
39
-			EEH_HTML::indent( 1, 'optgroup' );
40
-			foreach( $this->_input->options() as $opt_group_label => $opt_group ){
38
+		if (EEH_Array::is_multi_dimensional_array($this->_input->options())) {
39
+			EEH_HTML::indent(1, 'optgroup');
40
+			foreach ($this->_input->options() as $opt_group_label => $opt_group) {
41 41
 			    if ( ! empty($opt_group_label)) {
42
-                    $html .= EEH_HTML::nl(0, 'optgroup') . '<optgroup label="' . esc_attr($opt_group_label) . '">';
42
+                    $html .= EEH_HTML::nl(0, 'optgroup').'<optgroup label="'.esc_attr($opt_group_label).'">';
43 43
                 }
44
-				EEH_HTML::indent( 1, 'option' );
45
-				$html .= $this->_display_options( $opt_group );
44
+				EEH_HTML::indent(1, 'option');
45
+				$html .= $this->_display_options($opt_group);
46 46
 				EEH_HTML::indent( -1, 'option' );
47 47
                 if ( ! empty($opt_group_label)) {
48
-                    $html .= EEH_HTML::nl( 0, 'optgroup' ) . '</optgroup>';
48
+                    $html .= EEH_HTML::nl(0, 'optgroup').'</optgroup>';
49 49
 			    }
50 50
 			}
51 51
 			EEH_HTML::indent( -1, 'optgroup' );
52 52
 		} else {
53
-			$html.=$this->_display_options( $this->_input->options() );
53
+			$html .= $this->_display_options($this->_input->options());
54 54
 		}
55 55
 
56
-		$html.= EEH_HTML::nl( 0, 'select' ) . '</select>';
56
+		$html .= EEH_HTML::nl(0, 'select').'</select>';
57 57
 		return $html;
58 58
 	}
59 59
 
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
 	 * @param array $options
65 65
 	 * @return string
66 66
 	 */
67
-	protected function _display_options($options){
67
+	protected function _display_options($options) {
68 68
 		$html = '';
69
-		EEH_HTML::indent( 1, 'option' );
70
-		foreach( $options as $value => $display_text ){
71
-			$unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one( $value );
72
-			$selected = $this->_check_if_option_selected( $unnormalized_value ) ? ' selected="selected"' : '';
73
-			$html.= EEH_HTML::nl( 0, 'option' ) . '<option value="' . esc_attr( $unnormalized_value ) . '"' . $selected . '>' . $display_text . '</option>';
69
+		EEH_HTML::indent(1, 'option');
70
+		foreach ($options as $value => $display_text) {
71
+			$unnormalized_value = $this->_input->get_normalization_strategy()->unnormalize_one($value);
72
+			$selected = $this->_check_if_option_selected($unnormalized_value) ? ' selected="selected"' : '';
73
+			$html .= EEH_HTML::nl(0, 'option').'<option value="'.esc_attr($unnormalized_value).'"'.$selected.'>'.$display_text.'</option>';
74 74
 		}
75 75
 		EEH_HTML::indent( -1, 'option' );
76 76
 		return $html;
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 	 * @param string|int $value unnormalized value option (string)
84 84
 	 * @return string
85 85
 	 */
86
-	protected function _check_if_option_selected( $value ){
86
+	protected function _check_if_option_selected($value) {
87 87
 		return $this->_input->raw_value() === $value ? TRUE : FALSE;
88 88
 	}
89 89
 
Please login to merge, or discard this patch.
registration_form/templates/questions_main_meta_box.template.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@  discard block
 block discarded – undo
15 15
 //does question have any answers? cause if it does then we have to disable type
16 16
 $has_answers = $question->has_answers();
17 17
 
18
-if ( $QST_system === 'country' ) {
18
+if ($QST_system === 'country') {
19 19
 	echo EEH_HTML::div(
20
-		EEH_HTML::h4( '<span class="dashicons dashicons-info"></span>' . esc_html__( 'Did you know...', 'event_espresso' ) ) .
20
+		EEH_HTML::h4('<span class="dashicons dashicons-info"></span>'.esc_html__('Did you know...', 'event_espresso')).
21 21
 		EEH_HTML::p(
22 22
 			esc_html__(
23 23
 				'If you add a State/Province Select input immediately after this Country Select input when building your registration form, then the State/Province Select input options will change to correspond with the choice made in this input. So for example, choosing "United States" in this Country Select input will populate the State/Province Select input with just the state options for the United States.',
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 		<tbody>
35 35
 			<tr>
36 36
 				<th>
37
-					<label for="QST_display_text"><?php echo $fields['QST_display_text']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_text_info');?>
37
+					<label for="QST_display_text"><?php echo $fields['QST_display_text']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_text_info'); ?>
38 38
 				</th>
39 39
 				<td>
40 40
 					<input type="text" class="regular-text" id="QST_display_text" name="QST_display_text" value="<?php $question->f('QST_display_text')?>"/>
@@ -44,23 +44,23 @@  discard block
 block discarded – undo
44 44
 
45 45
 			<tr>
46 46
 				<th>
47
-					<label for="QST_admin_label"><?php echo $fields['QST_admin_label']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_label_info');?>
47
+					<label for="QST_admin_label"><?php echo $fields['QST_admin_label']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_label_info'); ?>
48 48
 				</th>
49 49
 				<td>
50 50
 					<?php
51
-						$disabled = ! empty( $QST_system ) ? ' disabled="disabled"' : '';
52
-						$id =  ! empty( $QST_system ) ? '_disabled' : '';
51
+						$disabled = ! empty($QST_system) ? ' disabled="disabled"' : '';
52
+						$id = ! empty($QST_system) ? '_disabled' : '';
53 53
 					?>
54 54
 					<input type="text" class="regular-text" id="QST_admin_label<?php echo $id?>" name="QST_admin_label<?php echo $id?>" value="<?php $question->f('QST_admin_label')?>"<?php echo $disabled?>/>
55 55
 					<input class="QST_order" type="hidden" id="QST_order<?php echo $id; ?>" name = "QST_order<?php echo $id; ?>" value="<?php echo $question->get('QST_order'); ?>" />
56
-					<?php if ( ! empty( $QST_system )) { ?>
56
+					<?php if ( ! empty($QST_system)) { ?>
57 57
 						<input type="hidden"  id="QST_admin_label" name="QST_admin_label" value="<?php echo $question->admin_label()?>"/>
58 58
 					<?php } ?>
59 59
 					<br/>
60 60
 					<p class="description">
61
-					<?php if ( ! empty( $QST_system )) { ?>
61
+					<?php if ( ! empty($QST_system)) { ?>
62 62
 					<span class="description" style="color:#D54E21;">
63
-						<?php esc_html_e('System question! This field cannot be changed.','event_espresso')?>
63
+						<?php esc_html_e('System question! This field cannot be changed.', 'event_espresso')?>
64 64
 					</span>
65 65
 					<?php } ?>
66 66
 
@@ -70,21 +70,21 @@  discard block
 block discarded – undo
70 70
 
71 71
 			<tr>
72 72
 				<th>
73
-					<label for="QST_admin_only"><?php echo $fields['QST_admin_only']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_admin_only_info');?>
73
+					<label for="QST_admin_only"><?php echo $fields['QST_admin_only']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_admin_only_info'); ?>
74 74
 				</th>
75 75
 				<td>
76 76
 					<?php
77
-						$disabled = ! empty( $QST_system ) ? ' disabled="disabled"' : '';
78
-						$id =  ! empty( $QST_system ) ? '_disabled' : '';
77
+						$disabled = ! empty($QST_system) ? ' disabled="disabled"' : '';
78
+						$id = ! empty($QST_system) ? '_disabled' : '';
79 79
 						$admin_only = $question->get('QST_admin_only');
80
-						$checked = !empty( $admin_only ) ? ' checked="checked"' : '';
80
+						$checked = ! empty($admin_only) ? ' checked="checked"' : '';
81 81
 					?>
82 82
 					<input class="QST_admin_only" type="checkbox" id="QST_admin_only<?php echo $id; ?>" name = "QST_admin_only<?php echo $id; ?>" value="1"<?php echo $disabled; echo $checked; ?>/>
83 83
 					<br/>
84 84
 					<p class="description">
85
-					<?php if ( ! empty( $QST_system )) { ?>
85
+					<?php if ( ! empty($QST_system)) { ?>
86 86
 					<span class="description" style="color:#D54E21;">
87
-						<?php esc_html_e('System question! This field cannot be changed.','event_espresso')?>
87
+						<?php esc_html_e('System question! This field cannot be changed.', 'event_espresso')?>
88 88
 					</span>
89 89
 					<?php } ?>
90 90
 
@@ -94,21 +94,21 @@  discard block
 block discarded – undo
94 94
 
95 95
 			<tr>
96 96
 				<th>
97
-					<label for="QST_type"><?php echo $fields['QST_type']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('question_type_info');?>
97
+					<label for="QST_type"><?php echo $fields['QST_type']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('question_type_info'); ?>
98 98
 				</th>
99 99
 				<td>
100 100
 					<?php
101
-						$disabled = ! empty( $QST_system ) ? ' disabled="disabled"' : '';
102
-						$id =  ! empty( $QST_system ) ? '_disabled' : '';
103
-						echo EEH_Form_Fields::select_input( 'QST_type' . $id, $question_types, $question->type(), 'id="QST_type' . $id . '"' . $disabled );
104
-						if( ! empty( $QST_system ) ) { ?>
101
+						$disabled = ! empty($QST_system) ? ' disabled="disabled"' : '';
102
+						$id = ! empty($QST_system) ? '_disabled' : '';
103
+						echo EEH_Form_Fields::select_input('QST_type'.$id, $question_types, $question->type(), 'id="QST_type'.$id.'"'.$disabled);
104
+						if ( ! empty($QST_system)) { ?>
105 105
 							<input type="hidden"  id="QST_type" name="QST_type" value="<?php echo $question->type()?>"/>
106 106
 						<?php
107
-							$explanatory_text = esc_html__('System question! This field cannot be changed.','event_espresso');
108
-						}else{
109
-							$explanatory_text = esc_html__('Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.','event_espresso');
107
+							$explanatory_text = esc_html__('System question! This field cannot be changed.', 'event_espresso');
108
+						} else {
109
+							$explanatory_text = esc_html__('Because there are currently answers for this question in the database, your options to change the question type have been limited to similar question-types.', 'event_espresso');
110 110
 						}
111
-						if ( ! empty( $QST_system ) || $has_answers ) { ?>
111
+						if ( ! empty($QST_system) || $has_answers) { ?>
112 112
 							<p><span class="description" style="color:#D54E21;">
113 113
 								<?php echo $explanatory_text; ?>
114 114
 							</span></p>
@@ -121,22 +121,22 @@  discard block
 block discarded – undo
121 121
 			<tr id="text_input_question_options">
122 122
 				<th>
123 123
 					<label>
124
-						<?php esc_html_e( 'Maximum Allowed Response Size', 'event_espresso' );?>
124
+						<?php esc_html_e('Maximum Allowed Response Size', 'event_espresso'); ?>
125 125
 					</label>
126 126
 				</th>
127 127
 				<td>
128
-					<input id="QST_max" name="QST_max" type="number" <?php echo $max_max === EE_INF ? '' : "max='$max_max'";?> value="<?php $question->f( 'QST_max' );?>" min="1">
128
+					<input id="QST_max" name="QST_max" type="number" <?php echo $max_max === EE_INF ? '' : "max='$max_max'"; ?> value="<?php $question->f('QST_max'); ?>" min="1">
129 129
 					<p>
130 130
 						<span class="description">
131
-							<?php esc_html_e( 'Maximum number of characters allowed when answering this question', 'event_espresso' );?>
131
+							<?php esc_html_e('Maximum number of characters allowed when answering this question', 'event_espresso'); ?>
132 132
 						</span>
133 133
 					</p>
134
-					<?php if ( $QST_system ) { ?>
134
+					<?php if ($QST_system) { ?>
135 135
 					<p>
136 136
 						<span class="description" style="color:#D54E21;">
137 137
 							<?php printf(
138
-									esc_html__( 'System question! The maximum number of characters that can be used for this question is %1$s', 'event_espresso' ),
139
-									$max_max );?>
138
+									esc_html__('System question! The maximum number of characters that can be used for this question is %1$s', 'event_espresso'),
139
+									$max_max ); ?>
140 140
 						</span>
141 141
 					</p>
142 142
 					<?php } ?>
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 			<tr id="question_options">
146 146
 				<th>
147 147
 					<label>
148
-						<?php esc_html_e('Answer Options','event_espresso')?>
148
+						<?php esc_html_e('Answer Options', 'event_espresso')?>
149 149
 					</label>
150 150
 				</th>
151 151
 				<td>
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
 						<thead>
155 155
 							<tr>
156 156
 								<th class="option-value-header">
157
-									<?php esc_html_e('Value','event_espresso')?>
157
+									<?php esc_html_e('Value', 'event_espresso')?>
158 158
 								</th>
159 159
 								<th class="option-desc-header">
160
-									<?php esc_html_e('Description (optional, only shown on registration form)','event_espresso')?>
160
+									<?php esc_html_e('Description (optional, only shown on registration form)', 'event_espresso')?>
161 161
 								</th>
162 162
 								<th>
163 163
 								</th>
@@ -180,17 +180,17 @@  discard block
 block discarded – undo
180 180
 							</tr>
181 181
 
182 182
 							<?php
183
-							$count=0;
183
+							$count = 0;
184 184
 							$question_options = $question->options();
185
-							if ( ! empty( $question_options )) {
186
-								foreach( $question_options as $option_id => $option ) {
187
-									$disabled =  $has_answers || $option->get('QSO_system') ? ' disabled="disabled"'  : '';
185
+							if ( ! empty($question_options)) {
186
+								foreach ($question_options as $option_id => $option) {
187
+									$disabled = $has_answers || $option->get('QSO_system') ? ' disabled="disabled"' : '';
188 188
 							?>
189 189
 								<tr class="question-option ee-options-sortable">
190 190
 									<td class="option-value-cell">
191 191
 										<input type="hidden" class="QSO_order" name="question_options[<?php echo $count; ?>][QSO_order]" value="<?php echo $count; ?>">
192 192
 										<input type="text" class="option-value regular-text" name="question_options[<?php echo $count?>][QSO_value]" value="<?php  $option->f('QSO_value')?>"<?php echo $disabled; ?>>
193
-										<?php if ( $has_answers ) : ?>
193
+										<?php if ($has_answers) : ?>
194 194
 											<input type="hidden" name="question_options[<?php echo $count; ?>][QSO_value]" value="<?php echo $option->f('QSO_value'); ?>" >
195 195
 										<?php endif; ?>
196 196
 									</td>
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 										<input type="text" class="option-desc regular-text" name="question_options[<?php echo $count?>][QSO_desc]" value="<?php $option->f('QSO_desc')?>">
199 199
 									</td>
200 200
 									<td>
201
-										<?php if ( ! $option->system() ) { ?>
201
+										<?php if ( ! $option->system()) { ?>
202 202
 											<span class="dashicons clickable dashicons-post-trash ee-icon-size-18 remove-option remove-item"></span>
203 203
 										<?php } ?>
204 204
                                         <span class="dashicons dashicons-image-flip-vertical sortable-drag-handle ee-icon-size-18"></span>
@@ -237,13 +237,13 @@  discard block
 block discarded – undo
237 237
 					</table>
238 238
 
239 239
 					<a id="new-question-option" class="button" style="margin:0 0 1em 3px;">
240
-						<?php esc_html_e('Add Another Answer Option','event_espresso')?>
240
+						<?php esc_html_e('Add Another Answer Option', 'event_espresso')?>
241 241
 					</a><br/>
242 242
 
243 243
 					<p class="description">
244
-						<?php esc_html_e('Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.','event_espresso')?>
244
+						<?php esc_html_e('Answer Options are the choices that you give people to select from for RADIO_BTN, CHECKBOX or DROPDOWN questions. The Value is a simple key that will be saved to the database and the description is optional. Note that values CANNOT contain any HTML, but descriptions can.', 'event_espresso')?>
245 245
 					</p>
246
-					<?php if ( $has_answers ) : ?>
246
+					<?php if ($has_answers) : ?>
247 247
 					<p class="description" style="color:#D54E21;">
248 248
 							<?php esc_html_e('Answer values that are uneditable are this way because there are registrations in the database that have answers for this question.  If you need to correct a mistake, or edit an existing option value, then trash the existing one and create a new option with the changes.  This will ensure that the existing registrations that chose the original answer will preserve that answer.', 'event_espresso'); ?>
249 249
 					</p>
@@ -254,32 +254,32 @@  discard block
 block discarded – undo
254 254
 
255 255
 			<tr>
256 256
 				<th>
257
-					<label for="QST_required"><?php echo $fields['QST_required']->get_nicename();?></label> <?php echo EEH_Template::get_help_tab_link('required_question_info');?>
257
+					<label for="QST_required"><?php echo $fields['QST_required']->get_nicename(); ?></label> <?php echo EEH_Template::get_help_tab_link('required_question_info'); ?>
258 258
 				</th>
259 259
 				<td>
260 260
 					<?php
261
-					$system_required = array( 'fname', 'email' );
262
-					$disabled = in_array( $QST_system, $system_required ) ? ' disabled="disabled"' : '';
261
+					$system_required = array('fname', 'email');
262
+					$disabled = in_array($QST_system, $system_required) ? ' disabled="disabled"' : '';
263 263
 					$required_on = $question->get('QST_admin_only');
264 264
 					$show_required_msg = $required_on ? '' : ' display:none;';
265
-					$disabled = $required_on || ! empty( $disabled ) ? ' disabled="disabled"' : '';
266
-					$id =  ! empty( $disabled ) && in_array( $QST_system, $system_required) ? '_disabled' : '';
267
-					$requiredOptions=array(
268
-						array( 'text'=> esc_html__( 'Optional', 'event_espresso' ), 'id'=>0 ),
269
-						array( 'text'=> esc_html__( 'Required', 'event_espresso' ), 'id'=>1 )
265
+					$disabled = $required_on || ! empty($disabled) ? ' disabled="disabled"' : '';
266
+					$id = ! empty($disabled) && in_array($QST_system, $system_required) ? '_disabled' : '';
267
+					$requiredOptions = array(
268
+						array('text'=> esc_html__('Optional', 'event_espresso'), 'id'=>0),
269
+						array('text'=> esc_html__('Required', 'event_espresso'), 'id'=>1)
270 270
 					);
271
-					echo EEH_Form_Fields::select_input('QST_required' . $id, $requiredOptions, $question->required(), 'id="QST_required' . $id . '"' . $disabled );
271
+					echo EEH_Form_Fields::select_input('QST_required'.$id, $requiredOptions, $question->required(), 'id="QST_required'.$id.'"'.$disabled);
272 272
 					?>
273 273
 						<p><span id="required_toggled_on" class="description" style="color:#D54E21;<?php echo $show_required_msg; ?>">
274
-						<?php esc_html_e('Required is set to optional, and this field is disabled, because the question is Admin-Only.','event_espresso')?>
274
+						<?php esc_html_e('Required is set to optional, and this field is disabled, because the question is Admin-Only.', 'event_espresso')?>
275 275
 						</span></p>
276 276
 						<p><span id="required_toggled_off" class="description" style="color:#D54E21; display: none;">
277
-							<?php esc_html_e('Required option field is no longer disabled because the question is not Admin-Only','event_espresso')?>
277
+							<?php esc_html_e('Required option field is no longer disabled because the question is not Admin-Only', 'event_espresso')?>
278 278
 						</span></p>
279
-					<?php if ( ! empty( $disabled ) && in_array( $QST_system, $system_required ) ) { ?>
279
+					<?php if ( ! empty($disabled) && in_array($QST_system, $system_required)) { ?>
280 280
 						<input type="hidden"  id="QST_required" name="QST_required" value="1"/>
281 281
 						<p><span class="description" style="color:#D54E21;">
282
-						<?php esc_html_e('System question! This field cannot be changed.','event_espresso')?>
282
+						<?php esc_html_e('System question! This field cannot be changed.', 'event_espresso')?>
283 283
 					</span></p>
284 284
 					<?php } ?>
285 285
 
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 
289 289
 			<tr>
290 290
 				<th>
291
-					<label for="QST_required_text"><?php esc_html_e('Required Text', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info');?>
291
+					<label for="QST_required_text"><?php esc_html_e('Required Text', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('required_text_info'); ?>
292 292
 				</th>
293 293
 				<td>
294 294
 					<input type="text" maxlength="100" class="regular-text" id="QST_required_text" name="QST_required_text" value="<?php  $question->f('QST_required_text')?>"/>
Please login to merge, or discard this patch.
admin_pages/registration_form/Registration_Form_Admin_Page.core.php 2 patches
Indentation   +633 added lines, -633 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -28,589 +28,589 @@  discard block
 block discarded – undo
28 28
 class Registration_Form_Admin_Page extends EE_Admin_Page
29 29
 {
30 30
 
31
-    /**
32
-     * _question
33
-     * holds the specific question object for the question details screen
34
-     *
35
-     * @var EE_Question $_question
36
-     */
37
-    protected $_question;
38
-
39
-    /**
40
-     * _question_group
41
-     * holds the specific question group object for the question group details screen
42
-     *
43
-     * @var EE_Question_Group $_question_group
44
-     */
45
-    protected $_question_group;
46
-
47
-    /**
48
-     *_question_model EEM_Question model instance (for queries)
49
-     *
50
-     * @var EEM_Question $_question_model ;
51
-     */
52
-    protected $_question_model;
53
-
54
-    /**
55
-     * _question_group_model EEM_Question_group instance (for queries)
56
-     *
57
-     * @var EEM_Question_Group $_question_group_model
58
-     */
59
-    protected $_question_group_model;
60
-
61
-
62
-    /**
63
-     * @Constructor
64
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
65
-     * @access public
66
-     */
67
-    public function __construct($routing = true)
68
-    {
69
-        require_once(EE_MODELS . 'EEM_Question.model.php');
70
-        require_once(EE_MODELS . 'EEM_Question_Group.model.php');
71
-        $this->_question_model       = EEM_Question::instance();
72
-        $this->_question_group_model = EEM_Question_Group::instance();
73
-        parent::__construct($routing);
74
-    }
75
-
76
-
77
-    protected function _init_page_props()
78
-    {
79
-        $this->page_slug        = REGISTRATION_FORM_PG_SLUG;
80
-        $this->page_label       = esc_html__('Registration Form', 'event_espresso');
81
-        $this->_admin_base_url  = REGISTRATION_FORM_ADMIN_URL;
82
-        $this->_admin_base_path = REGISTRATION_FORM_ADMIN;
83
-    }
84
-
85
-
86
-    protected function _ajax_hooks()
87
-    {
88
-    }
89
-
90
-
91
-    protected function _define_page_props()
92
-    {
93
-        $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso');
94
-        $this->_labels           = array(
95
-            'buttons' => array(
96
-                'edit_question' => esc_html__('Edit Question', 'event_espresso'),
97
-            ),
98
-        );
99
-    }
100
-
101
-
102
-    /**
103
-     *_set_page_routes
104
-     */
105
-    protected function _set_page_routes()
106
-    {
107
-        $qst_id             = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0;
108
-        $this->_page_routes = array(
109
-            'default' => array(
110
-                'func'       => '_questions_overview_list_table',
111
-                'capability' => 'ee_read_questions',
112
-            ),
113
-
114
-            'edit_question' => array(
115
-                'func'       => '_edit_question',
116
-                'capability' => 'ee_edit_question',
117
-                'obj_id'     => $qst_id,
118
-                'args'       => array('edit'),
119
-            ),
120
-
121
-            'question_groups' => array(
122
-                'func'       => '_questions_groups_preview',
123
-                'capability' => 'ee_read_question_groups',
124
-            ),
125
-
126
-            'update_question' => array(
127
-                'func'       => '_insert_or_update_question',
128
-                'args'       => array('new_question' => false),
129
-                'capability' => 'ee_edit_question',
130
-                'obj_id'     => $qst_id,
131
-                'noheader'   => true,
132
-            ),
133
-        );
134
-    }
135
-
136
-
137
-    protected function _set_page_config()
138
-    {
139
-        $this->_page_config = array(
140
-            'default' => array(
141
-                'nav'           => array(
142
-                    'label' => esc_html__('Questions', 'event_espresso'),
143
-                    'order' => 10,
144
-                ),
145
-                'list_table'    => 'Registration_Form_Questions_Admin_List_Table',
146
-                'metaboxes'     => $this->_default_espresso_metaboxes,
147
-                'help_tabs'     => array(
148
-                    'registration_form_questions_overview_help_tab'                           => array(
149
-                        'title'    => esc_html__('Questions Overview', 'event_espresso'),
150
-                        'filename' => 'registration_form_questions_overview',
151
-                    ),
152
-                    'registration_form_questions_overview_table_column_headings_help_tab'     => array(
153
-                        'title'    => esc_html__('Questions Overview Table Column Headings', 'event_espresso'),
154
-                        'filename' => 'registration_form_questions_overview_table_column_headings',
155
-                    ),
156
-                    'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array(
157
-                        'title'    => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'),
158
-                        'filename' => 'registration_form_questions_overview_views_bulk_actions_search',
159
-                    ),
160
-                ),
161
-                'help_tour'     => array('Registration_Form_Questions_Overview_Help_Tour'),
162
-                'require_nonce' => false,
163
-                'qtips'         => array(
164
-                    'EE_Registration_Form_Tips',
165
-                )/**/
166
-            ),
167
-
168
-            'question_groups' => array(
169
-                'nav'           => array(
170
-                    'label' => esc_html__('Question Groups', 'event_espresso'),
171
-                    'order' => 20,
172
-                ),
173
-                'metaboxes'     => $this->_default_espresso_metaboxes,
174
-                'help_tabs'     => array(
175
-                    'registration_form_question_groups_help_tab' => array(
176
-                        'title'    => esc_html__('Question Groups', 'event_espresso'),
177
-                        'filename' => 'registration_form_question_groups',
178
-                    ),
179
-                ),
180
-                'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'),
181
-                'require_nonce' => false,
182
-            ),
183
-
184
-            'edit_question' => array(
185
-                'nav'           => array(
186
-                    'label'      => esc_html__('Edit Question', 'event_espresso'),
187
-                    'order'      => 15,
188
-                    'persistent' => false,
189
-                    'url'        => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']),
190
-                        $this->_current_page_view_url) : $this->_admin_base_url,
191
-                ),
192
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
193
-                'help_tabs'     => array(
194
-                    'registration_form_edit_question_group_help_tab' => array(
195
-                        'title'    => esc_html__('Edit Question', 'event_espresso'),
196
-                        'filename' => 'registration_form_edit_question',
197
-                    ),
198
-                ),
199
-                'help_tour'     => array('Registration_Form_Edit_Question_Help_Tour'),
200
-                'require_nonce' => false,
201
-            ),
202
-        );
203
-    }
204
-
205
-
206
-    protected function _add_screen_options()
207
-    {
208
-        //todo
209
-    }
210
-
211
-    protected function _add_screen_options_default()
212
-    {
213
-        $page_title              = $this->_admin_page_title;
214
-        $this->_admin_page_title = esc_html__('Questions', 'event_espresso');
215
-        $this->_per_page_screen_option();
216
-        $this->_admin_page_title = $page_title;
217
-    }
218
-
219
-    protected function _add_screen_options_question_groups()
220
-    {
221
-        $page_title              = $this->_admin_page_title;
222
-        $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso');
223
-        $this->_per_page_screen_option();
224
-        $this->_admin_page_title = $page_title;
225
-    }
226
-
227
-    //none of the below group are currently used for Event Categories
228
-    protected function _add_feature_pointers()
229
-    {
230
-    }
231
-
232
-    public function load_scripts_styles()
233
-    {
234
-        wp_register_style('espresso_registration',
235
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
236
-        wp_enqueue_style('espresso_registration');
237
-    }
238
-
239
-    public function admin_init()
240
-    {
241
-    }
242
-
243
-    public function admin_notices()
244
-    {
245
-    }
246
-
247
-    public function admin_footer_scripts()
248
-    {
249
-    }
250
-
251
-
252
-    public function load_scripts_styles_default()
253
-    {
254
-    }
255
-
256
-
257
-    public function load_scripts_styles_add_question()
258
-    {
259
-        $this->load_scripts_styles_forms();
260
-        wp_register_script('espresso_registration_form_single',
261
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
262
-            EVENT_ESPRESSO_VERSION, true);
263
-        wp_enqueue_script('espresso_registration_form_single');
264
-    }
265
-
266
-    public function load_scripts_styles_edit_question()
267
-    {
268
-        $this->load_scripts_styles_forms();
269
-        wp_register_script('espresso_registration_form_single',
270
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
271
-            EVENT_ESPRESSO_VERSION, true);
272
-        wp_enqueue_script('espresso_registration_form_single');
273
-    }
274
-
275
-
276
-    public function recaptcha_info_help_tab()
277
-    {
278
-        $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
279
-        EEH_Template::display_template($template, array());
280
-    }
281
-
282
-
283
-    public function load_scripts_styles_forms()
284
-    {
285
-        //styles
286
-        wp_enqueue_style('espresso-ui-theme');
287
-        //scripts
288
-        wp_enqueue_script('ee_admin_js');
289
-    }
290
-
291
-
292
-    protected function _set_list_table_views_default()
293
-    {
294
-        $this->_views = array(
295
-            'all' => array(
296
-                'slug'  => 'all',
297
-                'label' => esc_html__('View All Questions', 'event_espresso'),
298
-                'count' => 0,
31
+	/**
32
+	 * _question
33
+	 * holds the specific question object for the question details screen
34
+	 *
35
+	 * @var EE_Question $_question
36
+	 */
37
+	protected $_question;
38
+
39
+	/**
40
+	 * _question_group
41
+	 * holds the specific question group object for the question group details screen
42
+	 *
43
+	 * @var EE_Question_Group $_question_group
44
+	 */
45
+	protected $_question_group;
46
+
47
+	/**
48
+	 *_question_model EEM_Question model instance (for queries)
49
+	 *
50
+	 * @var EEM_Question $_question_model ;
51
+	 */
52
+	protected $_question_model;
53
+
54
+	/**
55
+	 * _question_group_model EEM_Question_group instance (for queries)
56
+	 *
57
+	 * @var EEM_Question_Group $_question_group_model
58
+	 */
59
+	protected $_question_group_model;
60
+
61
+
62
+	/**
63
+	 * @Constructor
64
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
65
+	 * @access public
66
+	 */
67
+	public function __construct($routing = true)
68
+	{
69
+		require_once(EE_MODELS . 'EEM_Question.model.php');
70
+		require_once(EE_MODELS . 'EEM_Question_Group.model.php');
71
+		$this->_question_model       = EEM_Question::instance();
72
+		$this->_question_group_model = EEM_Question_Group::instance();
73
+		parent::__construct($routing);
74
+	}
75
+
76
+
77
+	protected function _init_page_props()
78
+	{
79
+		$this->page_slug        = REGISTRATION_FORM_PG_SLUG;
80
+		$this->page_label       = esc_html__('Registration Form', 'event_espresso');
81
+		$this->_admin_base_url  = REGISTRATION_FORM_ADMIN_URL;
82
+		$this->_admin_base_path = REGISTRATION_FORM_ADMIN;
83
+	}
84
+
85
+
86
+	protected function _ajax_hooks()
87
+	{
88
+	}
89
+
90
+
91
+	protected function _define_page_props()
92
+	{
93
+		$this->_admin_page_title = esc_html__('Registration Form', 'event_espresso');
94
+		$this->_labels           = array(
95
+			'buttons' => array(
96
+				'edit_question' => esc_html__('Edit Question', 'event_espresso'),
97
+			),
98
+		);
99
+	}
100
+
101
+
102
+	/**
103
+	 *_set_page_routes
104
+	 */
105
+	protected function _set_page_routes()
106
+	{
107
+		$qst_id             = ! empty($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0;
108
+		$this->_page_routes = array(
109
+			'default' => array(
110
+				'func'       => '_questions_overview_list_table',
111
+				'capability' => 'ee_read_questions',
112
+			),
113
+
114
+			'edit_question' => array(
115
+				'func'       => '_edit_question',
116
+				'capability' => 'ee_edit_question',
117
+				'obj_id'     => $qst_id,
118
+				'args'       => array('edit'),
119
+			),
120
+
121
+			'question_groups' => array(
122
+				'func'       => '_questions_groups_preview',
123
+				'capability' => 'ee_read_question_groups',
124
+			),
125
+
126
+			'update_question' => array(
127
+				'func'       => '_insert_or_update_question',
128
+				'args'       => array('new_question' => false),
129
+				'capability' => 'ee_edit_question',
130
+				'obj_id'     => $qst_id,
131
+				'noheader'   => true,
132
+			),
133
+		);
134
+	}
135
+
136
+
137
+	protected function _set_page_config()
138
+	{
139
+		$this->_page_config = array(
140
+			'default' => array(
141
+				'nav'           => array(
142
+					'label' => esc_html__('Questions', 'event_espresso'),
143
+					'order' => 10,
144
+				),
145
+				'list_table'    => 'Registration_Form_Questions_Admin_List_Table',
146
+				'metaboxes'     => $this->_default_espresso_metaboxes,
147
+				'help_tabs'     => array(
148
+					'registration_form_questions_overview_help_tab'                           => array(
149
+						'title'    => esc_html__('Questions Overview', 'event_espresso'),
150
+						'filename' => 'registration_form_questions_overview',
151
+					),
152
+					'registration_form_questions_overview_table_column_headings_help_tab'     => array(
153
+						'title'    => esc_html__('Questions Overview Table Column Headings', 'event_espresso'),
154
+						'filename' => 'registration_form_questions_overview_table_column_headings',
155
+					),
156
+					'registration_form_questions_overview_views_bulk_actions_search_help_tab' => array(
157
+						'title'    => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'),
158
+						'filename' => 'registration_form_questions_overview_views_bulk_actions_search',
159
+					),
160
+				),
161
+				'help_tour'     => array('Registration_Form_Questions_Overview_Help_Tour'),
162
+				'require_nonce' => false,
163
+				'qtips'         => array(
164
+					'EE_Registration_Form_Tips',
165
+				)/**/
166
+			),
167
+
168
+			'question_groups' => array(
169
+				'nav'           => array(
170
+					'label' => esc_html__('Question Groups', 'event_espresso'),
171
+					'order' => 20,
172
+				),
173
+				'metaboxes'     => $this->_default_espresso_metaboxes,
174
+				'help_tabs'     => array(
175
+					'registration_form_question_groups_help_tab' => array(
176
+						'title'    => esc_html__('Question Groups', 'event_espresso'),
177
+						'filename' => 'registration_form_question_groups',
178
+					),
179
+				),
180
+				'help_tour'     => array('Registration_Form_Question_Groups_Help_Tour'),
181
+				'require_nonce' => false,
182
+			),
183
+
184
+			'edit_question' => array(
185
+				'nav'           => array(
186
+					'label'      => esc_html__('Edit Question', 'event_espresso'),
187
+					'order'      => 15,
188
+					'persistent' => false,
189
+					'url'        => isset($this->_req_data['question_id']) ? add_query_arg(array('question_id' => $this->_req_data['question_id']),
190
+						$this->_current_page_view_url) : $this->_admin_base_url,
191
+				),
192
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
193
+				'help_tabs'     => array(
194
+					'registration_form_edit_question_group_help_tab' => array(
195
+						'title'    => esc_html__('Edit Question', 'event_espresso'),
196
+						'filename' => 'registration_form_edit_question',
197
+					),
198
+				),
199
+				'help_tour'     => array('Registration_Form_Edit_Question_Help_Tour'),
200
+				'require_nonce' => false,
201
+			),
202
+		);
203
+	}
204
+
205
+
206
+	protected function _add_screen_options()
207
+	{
208
+		//todo
209
+	}
210
+
211
+	protected function _add_screen_options_default()
212
+	{
213
+		$page_title              = $this->_admin_page_title;
214
+		$this->_admin_page_title = esc_html__('Questions', 'event_espresso');
215
+		$this->_per_page_screen_option();
216
+		$this->_admin_page_title = $page_title;
217
+	}
218
+
219
+	protected function _add_screen_options_question_groups()
220
+	{
221
+		$page_title              = $this->_admin_page_title;
222
+		$this->_admin_page_title = esc_html__('Question Groups', 'event_espresso');
223
+		$this->_per_page_screen_option();
224
+		$this->_admin_page_title = $page_title;
225
+	}
226
+
227
+	//none of the below group are currently used for Event Categories
228
+	protected function _add_feature_pointers()
229
+	{
230
+	}
231
+
232
+	public function load_scripts_styles()
233
+	{
234
+		wp_register_style('espresso_registration',
235
+			REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
236
+		wp_enqueue_style('espresso_registration');
237
+	}
238
+
239
+	public function admin_init()
240
+	{
241
+	}
242
+
243
+	public function admin_notices()
244
+	{
245
+	}
246
+
247
+	public function admin_footer_scripts()
248
+	{
249
+	}
250
+
251
+
252
+	public function load_scripts_styles_default()
253
+	{
254
+	}
255
+
256
+
257
+	public function load_scripts_styles_add_question()
258
+	{
259
+		$this->load_scripts_styles_forms();
260
+		wp_register_script('espresso_registration_form_single',
261
+			REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
262
+			EVENT_ESPRESSO_VERSION, true);
263
+		wp_enqueue_script('espresso_registration_form_single');
264
+	}
265
+
266
+	public function load_scripts_styles_edit_question()
267
+	{
268
+		$this->load_scripts_styles_forms();
269
+		wp_register_script('espresso_registration_form_single',
270
+			REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
271
+			EVENT_ESPRESSO_VERSION, true);
272
+		wp_enqueue_script('espresso_registration_form_single');
273
+	}
274
+
275
+
276
+	public function recaptcha_info_help_tab()
277
+	{
278
+		$template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
279
+		EEH_Template::display_template($template, array());
280
+	}
281
+
282
+
283
+	public function load_scripts_styles_forms()
284
+	{
285
+		//styles
286
+		wp_enqueue_style('espresso-ui-theme');
287
+		//scripts
288
+		wp_enqueue_script('ee_admin_js');
289
+	}
290
+
291
+
292
+	protected function _set_list_table_views_default()
293
+	{
294
+		$this->_views = array(
295
+			'all' => array(
296
+				'slug'  => 'all',
297
+				'label' => esc_html__('View All Questions', 'event_espresso'),
298
+				'count' => 0,
299 299
 //				'bulk_action' => array(
300 300
 //					'trash_questions' => esc_html__('Trash', 'event_espresso'),
301 301
 //					)
302
-            ),
303
-        );
304
-
305
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions',
306
-            'espresso_registration_form_trash_questions')
307
-        ) {
308
-            $this->_views['trash'] = array(
309
-                'slug'  => 'trash',
310
-                'label' => esc_html__('Trash', 'event_espresso'),
311
-                'count' => 0,
302
+			),
303
+		);
304
+
305
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions',
306
+			'espresso_registration_form_trash_questions')
307
+		) {
308
+			$this->_views['trash'] = array(
309
+				'slug'  => 'trash',
310
+				'label' => esc_html__('Trash', 'event_espresso'),
311
+				'count' => 0,
312 312
 //				'bulk_action' => array(
313 313
 //					'delete_questions' => esc_html__('Delete Permanently', 'event_espresso'),
314 314
 //					'restore_questions' => esc_html__('Restore', 'event_espresso'),
315
-            );
316
-        }
317
-    }
318
-
319
-    /**
320
-     * This just previews the question groups tab that comes in caffeinated.
321
-     *
322
-     * @return string html
323
-     */
324
-    protected function _questions_groups_preview()
325
-    {
326
-        $this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
327
-        $this->_template_args['preview_img']  = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot',
328
-                'event_espresso') . '" />';
329
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups 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. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
330
-                'event_espresso') . '</strong>';
331
-        $this->display_admin_caf_preview_page('question_groups_tab');
332
-    }
333
-
334
-
335
-    /**
336
-     * Extracts the question field's values from the POST request to update or insert them
337
-     *
338
-     * @param \EEM_Base $model
339
-     * @return array where each key is the name of a model's field/db column, and each value is its value.
340
-     */
341
-    protected function _set_column_values_for(EEM_Base $model)
342
-    {
343
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
344
-        $set_column_values = array();
345
-
346
-        //some initial checks for proper values.
347
-        //if QST_admin_only, then no matter what QST_required is we disable.
348
-        if (! empty($this->_req_data['QST_admin_only'])) {
349
-            $this->_req_data['QST_required'] = 0;
350
-        }
351
-        foreach ($model->field_settings() as $fieldName => $settings) {
352
-            // basically if QSG_identifier is empty or not set
353
-            if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) {
354
-                $QSG_name                      = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : '';
355
-                $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true);
315
+			);
316
+		}
317
+	}
318
+
319
+	/**
320
+	 * This just previews the question groups tab that comes in caffeinated.
321
+	 *
322
+	 * @return string html
323
+	 */
324
+	protected function _questions_groups_preview()
325
+	{
326
+		$this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
327
+		$this->_template_args['preview_img']  = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot',
328
+				'event_espresso') . '" />';
329
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups 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. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
330
+				'event_espresso') . '</strong>';
331
+		$this->display_admin_caf_preview_page('question_groups_tab');
332
+	}
333
+
334
+
335
+	/**
336
+	 * Extracts the question field's values from the POST request to update or insert them
337
+	 *
338
+	 * @param \EEM_Base $model
339
+	 * @return array where each key is the name of a model's field/db column, and each value is its value.
340
+	 */
341
+	protected function _set_column_values_for(EEM_Base $model)
342
+	{
343
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
344
+		$set_column_values = array();
345
+
346
+		//some initial checks for proper values.
347
+		//if QST_admin_only, then no matter what QST_required is we disable.
348
+		if (! empty($this->_req_data['QST_admin_only'])) {
349
+			$this->_req_data['QST_required'] = 0;
350
+		}
351
+		foreach ($model->field_settings() as $fieldName => $settings) {
352
+			// basically if QSG_identifier is empty or not set
353
+			if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) {
354
+				$QSG_name                      = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : '';
355
+				$set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true);
356 356
 //				dd($set_column_values);
357
-            } //if the admin label is blank, use a slug version of the question text
358
-            else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) {
359
-                $QST_text                      = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : '';
360
-                $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10));
361
-            } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
362
-                $set_column_values[$fieldName] = 0;
363
-            } else if ($fieldName === 'QST_max') {
364
-                $qst_system = EEM_Question::instance()->get_var(
365
-                    array(
366
-                        array(
367
-                            'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0,
368
-                        ),
369
-                    ),
370
-                    'QST_system');
371
-                $max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
372
-                if (empty($this->_req_data['QST_max']) ||
373
-                    $this->_req_data['QST_max'] > $max_max
374
-                ) {
375
-                    $set_column_values[$fieldName] = $max_max;
376
-                }
377
-            }
378
-
379
-
380
-            //only add a property to the array if it's not null (otherwise the model should just use the default value)
381
-            if (
382
-                ! isset($set_column_values[$fieldName]) &&
383
-                isset($this->_req_data[$fieldName])
384
-            ) {
385
-                $set_column_values[$fieldName] = $this->_req_data[$fieldName];
386
-            }
387
-
388
-        }
389
-        return $set_column_values;//validation fo this data to be performed by the model before insertion.
390
-    }
391
-
392
-
393
-    /**
394
-     *_questions_overview_list_table
395
-     */
396
-    protected function _questions_overview_list_table()
397
-    {
398
-        $this->_search_btn_label = esc_html__('Questions', 'event_espresso');
399
-        $this->display_admin_list_table_page_with_sidebar();
400
-    }
401
-
402
-
403
-    /**
404
-     * _edit_question
405
-     */
406
-    protected function _edit_question()
407
-    {
408
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
409
-        $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false;
410
-
411
-        switch ($this->_req_action) {
412
-            case 'add_question' :
413
-                $this->_admin_page_title = esc_html__('Add Question', 'event_espresso');
414
-                break;
415
-            case 'edit_question' :
416
-                $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso');
417
-                break;
418
-            default :
419
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
420
-        }
421
-
422
-        // add PRC_ID to title if editing
423
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
424
-        if ($ID) {
425
-            $question                 = $this->_question_model->get_one_by_ID($ID);
426
-            $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID));
427
-            $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields);
428
-        } else {
429
-            $question = EE_Question::new_instance();
430
-            $question->set_order_to_latest();
431
-            $this->_set_add_edit_form_tags('insert_question');
432
-        }
433
-        $question_types                                     = $question->has_answers()
434
-            ? $this->_question_model->question_types_in_same_category($question->type())
435
-            : $this->_question_model->allowed_question_types();
436
-        $this->_template_args['QST_ID']                     = $ID;
437
-        $this->_template_args['question']                   = $question;
438
-        $this->_template_args['question_types']             = $question_types;
439
-        $this->_template_args['max_max']                    = EEM_Question::instance()->absolute_max_for_system_question(
440
-            $question->system_ID()
441
-        );
442
-        $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
443
-        $this->_set_publish_post_box_vars('id', $ID);
444
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
445
-            REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
446
-            $this->_template_args, true
447
-        );
448
-
449
-        // the details template wrapper
450
-        $this->display_admin_page_with_sidebar();
451
-    }
452
-
453
-
454
-    /**
455
-     * @return string
456
-     */
457
-    protected function _get_question_type_descriptions()
458
-    {
459
-        EE_Registry::instance()->load_helper('HTML');
460
-        $descriptions               = '';
461
-        $question_type_descriptions = EEM_Question::instance()->question_descriptions();
462
-        foreach ($question_type_descriptions as $type => $question_type_description) {
463
-            if ($type == 'HTML_TEXTAREA') {
464
-                $html = new EE_Simple_HTML_Validation_Strategy();
465
-                $question_type_description .= sprintf(
466
-                    esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'),
467
-                    '<br/>',
468
-                    $html->get_list_of_allowed_tags()
469
-                );
470
-            }
471
-            $descriptions .= EEH_HTML::p(
472
-                $question_type_description,
473
-                'question_type_description-' . $type,
474
-                'question_type_description description',
475
-                'display:none;'
476
-            );
477
-        }
478
-        return $descriptions;
479
-    }
480
-
481
-
482
-    /**
483
-     * @param bool|true $new_question
484
-     * @throws \EE_Error
485
-     */
486
-    protected function _insert_or_update_question($new_question = true)
487
-    {
488
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
489
-        $set_column_values = $this->_set_column_values_for($this->_question_model);
490
-        if ($new_question) {
491
-            $ID          = $this->_question_model->insert($set_column_values);
492
-            $success     = $ID ? true : false;
493
-            $action_desc = 'added';
494
-        } else {
495
-            $ID     = absint($this->_req_data['QST_ID']);
496
-            $pk     = $this->_question_model->primary_key_name();
497
-            $wheres = array($pk => $ID);
498
-            unset($set_column_values[$pk]);
499
-            $success     = $this->_question_model->update($set_column_values, array($wheres));
500
-            $action_desc = 'updated';
501
-        }
502
-
503
-        if ($ID) {
504
-            //save the related options
505
-            //trash removed options, save old ones
506
-            //get list of all options
507
-            /** @type EE_Question $question */
508
-            $question = $this->_question_model->get_one_by_ID($ID);
509
-            $options  = $question->options();
510
-            if (! empty($options)) {
511
-                foreach ($options as $option_ID => $option) {
512
-                    $option_req_index = $this->_get_option_req_data_index($option_ID);
513
-                    if ($option_req_index !== false) {
514
-                        $option->save($this->_req_data['question_options'][$option_req_index]);
515
-                    } else {
516
-                        //not found, remove it
517
-                        $option->delete();
518
-                    }
519
-                }
520
-            }
521
-            //save new related options
522
-            foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
523
-                //skip $index that is from our sample
524
-                if ( $index === 'xxcountxx' ) {
525
-                    continue;
526
-                }
527
-                //note we allow saving blank options.
528
-                if (empty($option_req_data['QSO_ID'])
529
-                ) {//no ID! save it!
530
-                    $new_option = EE_Question_Option::new_instance(array(
531
-                        'QSO_value' => $option_req_data['QSO_value'],
532
-                        'QSO_desc'  => $option_req_data['QSO_desc'],
533
-                        'QSO_order' => $option_req_data['QSO_order'],
534
-                        'QST_ID'    => $question->ID(),
535
-                    ));
536
-                    $new_option->save();
537
-                }
538
-            }
539
-        }
540
-        $query_args = array('action' => 'edit_question', 'QST_ID' => $ID);
541
-        if ($success !== false) {
542
-            $msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'),
543
-                $this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'),
544
-                $this->_question_model->item_name());
545
-            EE_Error::add_success($msg);
546
-        }
547
-
548
-        $this->_redirect_after_action(false, '', $action_desc, $query_args, true);
549
-    }
550
-
551
-
552
-    /**
553
-     * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not
554
-     * by ID
555
-     * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously).
556
-     * So, this function gets the index in that request data array called question_options. Returns FALSE if not found.
557
-     *
558
-     * @param int $ID of the question option to find
559
-     * @return int index in question_options array if successful, FALSE if unsuccessful
560
-     */
561
-    protected function _get_option_req_data_index($ID)
562
-    {
563
-        $req_data_for_question_options = $this->_req_data['question_options'];
564
-        foreach ($req_data_for_question_options as $num => $option_data) {
565
-            if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) {
566
-                return $num;
567
-            }
568
-        }
569
-        return false;
570
-    }
571
-
572
-
573
-
574
-
575
-    /***********/
576
-    /* QUERIES */
577
-    /**
578
-     * For internal use in getting all the query parameters
579
-     * (because it's pretty well the same between question, question groups,
580
-     * and for both when searching for trashed and untrashed ones)
581
-     *
582
-     * @param EEM_Base $model either EEM_Question or EEM_Question_Group
583
-     * @param int      $per_page
584
-     * @param int      $current_page
585
-     * @return array lik EEM_Base::get_all's $query_params parameter
586
-     */
587
-    protected function get_query_params($model, $per_page = 10, $current_page = 10)
588
-    {
589
-        $query_params             = array();
590
-        $offset                   = ($current_page - 1) * $per_page;
591
-        $query_params['limit']    = array($offset, $per_page);
592
-        $order                    = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
593
-        $orderby_field            = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order';
594
-        $field_to_order_by        = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby'];
595
-        $query_params['order_by'] = array($field_to_order_by => $order);
596
-        $search_string            = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null;
597
-        if (! empty($search_string)) {
598
-            if ($model instanceof EEM_Question_Group) {
599
-                $query_params[0] = array(
600
-                    'OR' => array(
601
-                        'QSG_name' => array('LIKE', "%$search_string%"),
602
-                        'QSG_desc' => array('LIKE', "%$search_string%"),
603
-                    ),
604
-                );
605
-            } else {
606
-                $query_params[0] = array(
607
-                    'QST_display_text' => array('LIKE', "%$search_string%"),
608
-                );
609
-            }
610
-        }
611
-
612
-        //capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented)
613
-        /*if ( $model instanceof EEM_Question_Group ) {
357
+			} //if the admin label is blank, use a slug version of the question text
358
+			else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) {
359
+				$QST_text                      = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : '';
360
+				$set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10));
361
+			} else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
362
+				$set_column_values[$fieldName] = 0;
363
+			} else if ($fieldName === 'QST_max') {
364
+				$qst_system = EEM_Question::instance()->get_var(
365
+					array(
366
+						array(
367
+							'QST_ID' => isset($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0,
368
+						),
369
+					),
370
+					'QST_system');
371
+				$max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
372
+				if (empty($this->_req_data['QST_max']) ||
373
+					$this->_req_data['QST_max'] > $max_max
374
+				) {
375
+					$set_column_values[$fieldName] = $max_max;
376
+				}
377
+			}
378
+
379
+
380
+			//only add a property to the array if it's not null (otherwise the model should just use the default value)
381
+			if (
382
+				! isset($set_column_values[$fieldName]) &&
383
+				isset($this->_req_data[$fieldName])
384
+			) {
385
+				$set_column_values[$fieldName] = $this->_req_data[$fieldName];
386
+			}
387
+
388
+		}
389
+		return $set_column_values;//validation fo this data to be performed by the model before insertion.
390
+	}
391
+
392
+
393
+	/**
394
+	 *_questions_overview_list_table
395
+	 */
396
+	protected function _questions_overview_list_table()
397
+	{
398
+		$this->_search_btn_label = esc_html__('Questions', 'event_espresso');
399
+		$this->display_admin_list_table_page_with_sidebar();
400
+	}
401
+
402
+
403
+	/**
404
+	 * _edit_question
405
+	 */
406
+	protected function _edit_question()
407
+	{
408
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
409
+		$ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID']) ? absint($this->_req_data['QST_ID']) : false;
410
+
411
+		switch ($this->_req_action) {
412
+			case 'add_question' :
413
+				$this->_admin_page_title = esc_html__('Add Question', 'event_espresso');
414
+				break;
415
+			case 'edit_question' :
416
+				$this->_admin_page_title = esc_html__('Edit Question', 'event_espresso');
417
+				break;
418
+			default :
419
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
420
+		}
421
+
422
+		// add PRC_ID to title if editing
423
+		$this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
424
+		if ($ID) {
425
+			$question                 = $this->_question_model->get_one_by_ID($ID);
426
+			$additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID));
427
+			$this->_set_add_edit_form_tags('update_question', $additional_hidden_fields);
428
+		} else {
429
+			$question = EE_Question::new_instance();
430
+			$question->set_order_to_latest();
431
+			$this->_set_add_edit_form_tags('insert_question');
432
+		}
433
+		$question_types                                     = $question->has_answers()
434
+			? $this->_question_model->question_types_in_same_category($question->type())
435
+			: $this->_question_model->allowed_question_types();
436
+		$this->_template_args['QST_ID']                     = $ID;
437
+		$this->_template_args['question']                   = $question;
438
+		$this->_template_args['question_types']             = $question_types;
439
+		$this->_template_args['max_max']                    = EEM_Question::instance()->absolute_max_for_system_question(
440
+			$question->system_ID()
441
+		);
442
+		$this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
443
+		$this->_set_publish_post_box_vars('id', $ID);
444
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
445
+			REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
446
+			$this->_template_args, true
447
+		);
448
+
449
+		// the details template wrapper
450
+		$this->display_admin_page_with_sidebar();
451
+	}
452
+
453
+
454
+	/**
455
+	 * @return string
456
+	 */
457
+	protected function _get_question_type_descriptions()
458
+	{
459
+		EE_Registry::instance()->load_helper('HTML');
460
+		$descriptions               = '';
461
+		$question_type_descriptions = EEM_Question::instance()->question_descriptions();
462
+		foreach ($question_type_descriptions as $type => $question_type_description) {
463
+			if ($type == 'HTML_TEXTAREA') {
464
+				$html = new EE_Simple_HTML_Validation_Strategy();
465
+				$question_type_description .= sprintf(
466
+					esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'),
467
+					'<br/>',
468
+					$html->get_list_of_allowed_tags()
469
+				);
470
+			}
471
+			$descriptions .= EEH_HTML::p(
472
+				$question_type_description,
473
+				'question_type_description-' . $type,
474
+				'question_type_description description',
475
+				'display:none;'
476
+			);
477
+		}
478
+		return $descriptions;
479
+	}
480
+
481
+
482
+	/**
483
+	 * @param bool|true $new_question
484
+	 * @throws \EE_Error
485
+	 */
486
+	protected function _insert_or_update_question($new_question = true)
487
+	{
488
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
489
+		$set_column_values = $this->_set_column_values_for($this->_question_model);
490
+		if ($new_question) {
491
+			$ID          = $this->_question_model->insert($set_column_values);
492
+			$success     = $ID ? true : false;
493
+			$action_desc = 'added';
494
+		} else {
495
+			$ID     = absint($this->_req_data['QST_ID']);
496
+			$pk     = $this->_question_model->primary_key_name();
497
+			$wheres = array($pk => $ID);
498
+			unset($set_column_values[$pk]);
499
+			$success     = $this->_question_model->update($set_column_values, array($wheres));
500
+			$action_desc = 'updated';
501
+		}
502
+
503
+		if ($ID) {
504
+			//save the related options
505
+			//trash removed options, save old ones
506
+			//get list of all options
507
+			/** @type EE_Question $question */
508
+			$question = $this->_question_model->get_one_by_ID($ID);
509
+			$options  = $question->options();
510
+			if (! empty($options)) {
511
+				foreach ($options as $option_ID => $option) {
512
+					$option_req_index = $this->_get_option_req_data_index($option_ID);
513
+					if ($option_req_index !== false) {
514
+						$option->save($this->_req_data['question_options'][$option_req_index]);
515
+					} else {
516
+						//not found, remove it
517
+						$option->delete();
518
+					}
519
+				}
520
+			}
521
+			//save new related options
522
+			foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
523
+				//skip $index that is from our sample
524
+				if ( $index === 'xxcountxx' ) {
525
+					continue;
526
+				}
527
+				//note we allow saving blank options.
528
+				if (empty($option_req_data['QSO_ID'])
529
+				) {//no ID! save it!
530
+					$new_option = EE_Question_Option::new_instance(array(
531
+						'QSO_value' => $option_req_data['QSO_value'],
532
+						'QSO_desc'  => $option_req_data['QSO_desc'],
533
+						'QSO_order' => $option_req_data['QSO_order'],
534
+						'QST_ID'    => $question->ID(),
535
+					));
536
+					$new_option->save();
537
+				}
538
+			}
539
+		}
540
+		$query_args = array('action' => 'edit_question', 'QST_ID' => $ID);
541
+		if ($success !== false) {
542
+			$msg = $new_question ? sprintf(esc_html__('The %s has been created', 'event_espresso'),
543
+				$this->_question_model->item_name()) : sprintf(esc_html__('The %s has been updated', 'event_espresso'),
544
+				$this->_question_model->item_name());
545
+			EE_Error::add_success($msg);
546
+		}
547
+
548
+		$this->_redirect_after_action(false, '', $action_desc, $query_args, true);
549
+	}
550
+
551
+
552
+	/**
553
+	 * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not
554
+	 * by ID
555
+	 * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously).
556
+	 * So, this function gets the index in that request data array called question_options. Returns FALSE if not found.
557
+	 *
558
+	 * @param int $ID of the question option to find
559
+	 * @return int index in question_options array if successful, FALSE if unsuccessful
560
+	 */
561
+	protected function _get_option_req_data_index($ID)
562
+	{
563
+		$req_data_for_question_options = $this->_req_data['question_options'];
564
+		foreach ($req_data_for_question_options as $num => $option_data) {
565
+			if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) {
566
+				return $num;
567
+			}
568
+		}
569
+		return false;
570
+	}
571
+
572
+
573
+
574
+
575
+	/***********/
576
+	/* QUERIES */
577
+	/**
578
+	 * For internal use in getting all the query parameters
579
+	 * (because it's pretty well the same between question, question groups,
580
+	 * and for both when searching for trashed and untrashed ones)
581
+	 *
582
+	 * @param EEM_Base $model either EEM_Question or EEM_Question_Group
583
+	 * @param int      $per_page
584
+	 * @param int      $current_page
585
+	 * @return array lik EEM_Base::get_all's $query_params parameter
586
+	 */
587
+	protected function get_query_params($model, $per_page = 10, $current_page = 10)
588
+	{
589
+		$query_params             = array();
590
+		$offset                   = ($current_page - 1) * $per_page;
591
+		$query_params['limit']    = array($offset, $per_page);
592
+		$order                    = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC';
593
+		$orderby_field            = $model instanceof EEM_Question ? 'QST_ID' : 'QSG_order';
594
+		$field_to_order_by        = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby'];
595
+		$query_params['order_by'] = array($field_to_order_by => $order);
596
+		$search_string            = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null;
597
+		if (! empty($search_string)) {
598
+			if ($model instanceof EEM_Question_Group) {
599
+				$query_params[0] = array(
600
+					'OR' => array(
601
+						'QSG_name' => array('LIKE', "%$search_string%"),
602
+						'QSG_desc' => array('LIKE', "%$search_string%"),
603
+					),
604
+				);
605
+			} else {
606
+				$query_params[0] = array(
607
+					'QST_display_text' => array('LIKE', "%$search_string%"),
608
+				);
609
+			}
610
+		}
611
+
612
+		//capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented)
613
+		/*if ( $model instanceof EEM_Question_Group ) {
614 614
             if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) {
615 615
                 $query_params[0] = array(
616 616
                     'AND' => array(
@@ -640,62 +640,62 @@  discard block
 block discarded – undo
640 640
             }
641 641
         }/**/
642 642
 
643
-        return $query_params;
644
-
645
-    }
646
-
647
-
648
-    /**
649
-     * @param int        $per_page
650
-     * @param int        $current_page
651
-     * @param bool|false $count
652
-     * @return \EE_Soft_Delete_Base_Class[]|int
653
-     */
654
-    public function get_questions($per_page = 10, $current_page = 1, $count = false)
655
-    {
656
-        $QST          = EEM_Question::instance();
657
-        $query_params = $this->get_query_params($QST, $per_page, $current_page);
658
-        if ($count) {
659
-            $where   = isset($query_params[0]) ? array($query_params[0]) : array();
660
-            $results = $QST->count($where);
661
-        } else {
662
-            $results = $QST->get_all($query_params);
663
-        }
664
-        return $results;
665
-
666
-    }
667
-
668
-
669
-    /**
670
-     * @param            $per_page
671
-     * @param int        $current_page
672
-     * @param bool|false $count
673
-     * @return \EE_Soft_Delete_Base_Class[]|int
674
-     */
675
-    public function get_trashed_questions($per_page, $current_page = 1, $count = false)
676
-    {
677
-        $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
678
-        $where        = isset($query_params[0]) ? array($query_params[0]) : array();
679
-        $questions    = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params);
680
-        return $questions;
681
-    }
682
-
683
-
684
-    /**
685
-     * @param            $per_page
686
-     * @param int        $current_page
687
-     * @param bool|false $count
688
-     * @return \EE_Soft_Delete_Base_Class[]
689
-     */
690
-    public function get_question_groups($per_page, $current_page = 1, $count = false)
691
-    {
692
-        /** @type EEM_Question_Group $questionGroupModel */
693
-        $questionGroupModel = EEM_Question_Group::instance();
694
-        //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
695
-        return $questionGroupModel->get_all(
696
-            $this->get_query_params($questionGroupModel, $per_page, $current_page)
697
-        );
698
-    }
643
+		return $query_params;
644
+
645
+	}
646
+
647
+
648
+	/**
649
+	 * @param int        $per_page
650
+	 * @param int        $current_page
651
+	 * @param bool|false $count
652
+	 * @return \EE_Soft_Delete_Base_Class[]|int
653
+	 */
654
+	public function get_questions($per_page = 10, $current_page = 1, $count = false)
655
+	{
656
+		$QST          = EEM_Question::instance();
657
+		$query_params = $this->get_query_params($QST, $per_page, $current_page);
658
+		if ($count) {
659
+			$where   = isset($query_params[0]) ? array($query_params[0]) : array();
660
+			$results = $QST->count($where);
661
+		} else {
662
+			$results = $QST->get_all($query_params);
663
+		}
664
+		return $results;
665
+
666
+	}
667
+
668
+
669
+	/**
670
+	 * @param            $per_page
671
+	 * @param int        $current_page
672
+	 * @param bool|false $count
673
+	 * @return \EE_Soft_Delete_Base_Class[]|int
674
+	 */
675
+	public function get_trashed_questions($per_page, $current_page = 1, $count = false)
676
+	{
677
+		$query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
678
+		$where        = isset($query_params[0]) ? array($query_params[0]) : array();
679
+		$questions    = $count ? EEM_Question::instance()->count_deleted($where) : EEM_Question::instance()->get_all_deleted($query_params);
680
+		return $questions;
681
+	}
682
+
683
+
684
+	/**
685
+	 * @param            $per_page
686
+	 * @param int        $current_page
687
+	 * @param bool|false $count
688
+	 * @return \EE_Soft_Delete_Base_Class[]
689
+	 */
690
+	public function get_question_groups($per_page, $current_page = 1, $count = false)
691
+	{
692
+		/** @type EEM_Question_Group $questionGroupModel */
693
+		$questionGroupModel = EEM_Question_Group::instance();
694
+		//note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
695
+		return $questionGroupModel->get_all(
696
+			$this->get_query_params($questionGroupModel, $per_page, $current_page)
697
+		);
698
+	}
699 699
 
700 700
 
701 701
 } //ends Registration_Form_Admin_Page class
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function __construct($routing = true)
68 68
     {
69
-        require_once(EE_MODELS . 'EEM_Question.model.php');
70
-        require_once(EE_MODELS . 'EEM_Question_Group.model.php');
69
+        require_once(EE_MODELS.'EEM_Question.model.php');
70
+        require_once(EE_MODELS.'EEM_Question_Group.model.php');
71 71
         $this->_question_model       = EEM_Question::instance();
72 72
         $this->_question_group_model = EEM_Question_Group::instance();
73 73
         parent::__construct($routing);
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
     public function load_scripts_styles()
233 233
     {
234 234
         wp_register_style('espresso_registration',
235
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
235
+            REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.css', array(), EVENT_ESPRESSO_VERSION);
236 236
         wp_enqueue_style('espresso_registration');
237 237
     }
238 238
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
     {
259 259
         $this->load_scripts_styles_forms();
260 260
         wp_register_script('espresso_registration_form_single',
261
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
261
+            REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
262 262
             EVENT_ESPRESSO_VERSION, true);
263 263
         wp_enqueue_script('espresso_registration_form_single');
264 264
     }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
     {
268 268
         $this->load_scripts_styles_forms();
269 269
         wp_register_script('espresso_registration_form_single',
270
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
270
+            REGISTRATION_FORM_ASSETS_URL.'espresso_registration_form_admin.js', array('jquery-ui-sortable'),
271 271
             EVENT_ESPRESSO_VERSION, true);
272 272
         wp_enqueue_script('espresso_registration_form_single');
273 273
     }
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 
276 276
     public function recaptcha_info_help_tab()
277 277
     {
278
-        $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
278
+        $template = REGISTRATION_FORM_TEMPLATE_PATH.'recaptcha_info_help_tab.template.php';
279 279
         EEH_Template::display_template($template, array());
280 280
     }
281 281
 
@@ -324,10 +324,10 @@  discard block
 block discarded – undo
324 324
     protected function _questions_groups_preview()
325 325
     {
326 326
         $this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
327
-        $this->_template_args['preview_img']  = '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="' . esc_attr__('Preview Question Groups Overview List Table screenshot',
328
-                'event_espresso') . '" />';
329
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__('Question Groups 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. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
330
-                'event_espresso') . '</strong>';
327
+        $this->_template_args['preview_img']  = '<img src="'.REGISTRATION_FORM_ASSETS_URL.'caf_reg_form_preview.jpg" alt="'.esc_attr__('Preview Question Groups Overview List Table screenshot',
328
+                'event_espresso').'" />';
329
+        $this->_template_args['preview_text'] = '<strong>'.esc_html__('Question Groups 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. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
330
+                'event_espresso').'</strong>';
331 331
         $this->display_admin_caf_preview_page('question_groups_tab');
332 332
     }
333 333
 
@@ -345,20 +345,20 @@  discard block
 block discarded – undo
345 345
 
346 346
         //some initial checks for proper values.
347 347
         //if QST_admin_only, then no matter what QST_required is we disable.
348
-        if (! empty($this->_req_data['QST_admin_only'])) {
348
+        if ( ! empty($this->_req_data['QST_admin_only'])) {
349 349
             $this->_req_data['QST_required'] = 0;
350 350
         }
351 351
         foreach ($model->field_settings() as $fieldName => $settings) {
352 352
             // basically if QSG_identifier is empty or not set
353 353
             if ($fieldName === 'QSG_identifier' && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))) {
354 354
                 $QSG_name                      = isset($this->_req_data['QSG_name']) ? $this->_req_data['QSG_name'] : '';
355
-                $set_column_values[$fieldName] = sanitize_title($QSG_name) . '-' . uniqid('', true);
355
+                $set_column_values[$fieldName] = sanitize_title($QSG_name).'-'.uniqid('', true);
356 356
 //				dd($set_column_values);
357 357
             } //if the admin label is blank, use a slug version of the question text
358 358
             else if ($fieldName === 'QST_admin_label' && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))) {
359 359
                 $QST_text                      = isset($this->_req_data['QST_display_text']) ? $this->_req_data['QST_display_text'] : '';
360 360
                 $set_column_values[$fieldName] = sanitize_title(wp_trim_words($QST_text, 10));
361
-            } else if ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
361
+            } else if ($fieldName === 'QST_admin_only' && ( ! isset($this->_req_data['QST_admin_only']))) {
362 362
                 $set_column_values[$fieldName] = 0;
363 363
             } else if ($fieldName === 'QST_max') {
364 364
                 $qst_system = EEM_Question::instance()->get_var(
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
                         ),
369 369
                     ),
370 370
                     'QST_system');
371
-                $max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
371
+                $max_max = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
372 372
                 if (empty($this->_req_data['QST_max']) ||
373 373
                     $this->_req_data['QST_max'] > $max_max
374 374
                 ) {
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
             }
387 387
 
388 388
         }
389
-        return $set_column_values;//validation fo this data to be performed by the model before insertion.
389
+        return $set_column_values; //validation fo this data to be performed by the model before insertion.
390 390
     }
391 391
 
392 392
 
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
         }
421 421
 
422 422
         // add PRC_ID to title if editing
423
-        $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title;
423
+        $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title;
424 424
         if ($ID) {
425 425
             $question                 = $this->_question_model->get_one_by_ID($ID);
426 426
             $additional_hidden_fields = array('QST_ID' => array('type' => 'hidden', 'value' => $ID));
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
         $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
443 443
         $this->_set_publish_post_box_vars('id', $ID);
444 444
         $this->_template_args['admin_page_content'] = EEH_Template::display_template(
445
-            REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
445
+            REGISTRATION_FORM_TEMPLATE_PATH.'questions_main_meta_box.template.php',
446 446
             $this->_template_args, true
447 447
         );
448 448
 
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
             }
471 471
             $descriptions .= EEH_HTML::p(
472 472
                 $question_type_description,
473
-                'question_type_description-' . $type,
473
+                'question_type_description-'.$type,
474 474
                 'question_type_description description',
475 475
                 'display:none;'
476 476
             );
@@ -507,7 +507,7 @@  discard block
 block discarded – undo
507 507
             /** @type EE_Question $question */
508 508
             $question = $this->_question_model->get_one_by_ID($ID);
509 509
             $options  = $question->options();
510
-            if (! empty($options)) {
510
+            if ( ! empty($options)) {
511 511
                 foreach ($options as $option_ID => $option) {
512 512
                     $option_req_index = $this->_get_option_req_data_index($option_ID);
513 513
                     if ($option_req_index !== false) {
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
             //save new related options
522 522
             foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
523 523
                 //skip $index that is from our sample
524
-                if ( $index === 'xxcountxx' ) {
524
+                if ($index === 'xxcountxx') {
525 525
                     continue;
526 526
                 }
527 527
                 //note we allow saving blank options.
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
     {
563 563
         $req_data_for_question_options = $this->_req_data['question_options'];
564 564
         foreach ($req_data_for_question_options as $num => $option_data) {
565
-            if (array_key_exists('QSO_ID', $option_data) && (int)$option_data['QSO_ID'] === $ID) {
565
+            if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) {
566 566
                 return $num;
567 567
             }
568 568
         }
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
         $field_to_order_by        = empty($this->_req_data['orderby']) ? $orderby_field : $this->_req_data['orderby'];
595 595
         $query_params['order_by'] = array($field_to_order_by => $order);
596 596
         $search_string            = array_key_exists('s', $this->_req_data) ? $this->_req_data['s'] : null;
597
-        if (! empty($search_string)) {
597
+        if ( ! empty($search_string)) {
598 598
             if ($model instanceof EEM_Question_Group) {
599 599
                 $query_params[0] = array(
600 600
                     'OR' => array(
Please login to merge, or discard this patch.
admin_pages/registrations/Registrations_Admin_Page.core.php 2 patches
Indentation   +2947 added lines, -2947 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 
@@ -23,1831 +23,1831 @@  discard block
 block discarded – undo
23 23
 class Registrations_Admin_Page extends EE_Admin_Page_CPT
24 24
 {
25 25
 
26
-    /**
27
-     * @var EE_Registration
28
-     */
29
-    private $_registration;
30
-
31
-    /**
32
-     * @var EE_Event
33
-     */
34
-    private $_reg_event;
35
-
36
-    /**
37
-     * @var EE_Session
38
-     */
39
-    private $_session;
40
-
41
-    private static $_reg_status;
42
-
43
-    /**
44
-     * Form for displaying the custom questions for this registration.
45
-     * This gets used a few times throughout the request so its best to cache it
46
-     *
47
-     * @var EE_Registration_Custom_Questions_Form
48
-     */
49
-    protected $_reg_custom_questions_form = null;
50
-
51
-
52
-    /**
53
-     *        constructor
54
-     *
55
-     * @Constructor
56
-     * @access public
57
-     * @param bool $routing
58
-     * @return Registrations_Admin_Page
59
-     */
60
-    public function __construct($routing = true)
61
-    {
62
-        parent::__construct($routing);
63
-        add_action('wp_loaded', array($this, 'wp_loaded'));
64
-    }
65
-
66
-
67
-    public function wp_loaded()
68
-    {
69
-        // when adding a new registration...
70
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
-            EE_System::do_not_cache();
72
-            if ( ! isset($this->_req_data['processing_registration'])
73
-                 || absint($this->_req_data['processing_registration']) !== 1
74
-            ) {
75
-                // and it's NOT the attendee information reg step
76
-                // force cookie expiration by setting time to last week
77
-                setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
-                // and update the global
79
-                $_COOKIE['ee_registration_added'] = 0;
80
-            }
81
-        }
82
-    }
83
-
84
-
85
-    protected function _init_page_props()
86
-    {
87
-        $this->page_slug        = REG_PG_SLUG;
88
-        $this->_admin_base_url  = REG_ADMIN_URL;
89
-        $this->_admin_base_path = REG_ADMIN;
90
-        $this->page_label       = __('Registrations', 'event_espresso');
91
-        $this->_cpt_routes      = array(
92
-            'add_new_attendee' => 'espresso_attendees',
93
-            'edit_attendee'    => 'espresso_attendees',
94
-            'insert_attendee'  => 'espresso_attendees',
95
-            'update_attendee'  => 'espresso_attendees',
96
-        );
97
-        $this->_cpt_model_names = array(
98
-            'add_new_attendee' => 'EEM_Attendee',
99
-            'edit_attendee'    => 'EEM_Attendee',
100
-        );
101
-        $this->_cpt_edit_routes = array(
102
-            'espresso_attendees' => 'edit_attendee',
103
-        );
104
-        $this->_pagenow_map     = array(
105
-            'add_new_attendee' => 'post-new.php',
106
-            'edit_attendee'    => 'post.php',
107
-            'trash'            => 'post.php',
108
-        );
109
-        add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
-        //add filters so that the comment urls don't take users to a confusing 404 page
111
-        add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
-    }
113
-
114
-
115
-    public function clear_comment_link($link, $comment, $args)
116
-    {
117
-        //gotta make sure this only happens on this route
118
-        $post_type = get_post_type($comment->comment_post_ID);
119
-        if ($post_type === 'espresso_attendees') {
120
-            return '#commentsdiv';
121
-        }
122
-        return $link;
123
-    }
124
-
125
-
126
-    protected function _ajax_hooks()
127
-    {
128
-        //todo: all hooks for registrations ajax goes in here
129
-        add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
-    }
131
-
132
-
133
-    protected function _define_page_props()
134
-    {
135
-        $this->_admin_page_title = $this->page_label;
136
-        $this->_labels           = array(
137
-            'buttons'                      => array(
138
-                'add-registrant'      => __('Add New Registration', 'event_espresso'),
139
-                'add-attendee'        => __('Add Contact', 'event_espresso'),
140
-                'edit'                => __('Edit Contact', 'event_espresso'),
141
-                'report'              => __("Event Registrations CSV Report", "event_espresso"),
142
-                'report_all'          => __('All Registrations CSV Report', 'event_espresso'),
143
-                'report_filtered'     => __('Filtered CSV Report', 'event_espresso'),
144
-                'contact_list_report' => __('Contact List Report', 'event_espresso'),
145
-                'contact_list_export' => __("Export Data", "event_espresso"),
146
-            ),
147
-            'publishbox'                   => array(
148
-                'add_new_attendee' => __("Add Contact Record", 'event_espresso'),
149
-                'edit_attendee'    => __("Update Contact Record", 'event_espresso'),
150
-            ),
151
-            'hide_add_button_on_cpt_route' => array(
152
-                'edit_attendee' => true,
153
-            ),
154
-        );
155
-    }
156
-
157
-
158
-    /**
159
-     *        grab url requests and route them
160
-     *
161
-     * @access private
162
-     * @return void
163
-     */
164
-    public function _set_page_routes()
165
-    {
166
-        $this->_get_registration_status_array();
167
-        $reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
-            ? $this->_req_data['_REG_ID'] : 0;
169
-        $att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
-            ? $this->_req_data['ATT_ID'] : 0;
171
-        $att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post']
172
-            : $att_id;
173
-        $this->_page_routes = array(
174
-            'default'                            => array(
175
-                'func'       => '_registrations_overview_list_table',
176
-                'capability' => 'ee_read_registrations',
177
-            ),
178
-            'view_registration'                  => array(
179
-                'func'       => '_registration_details',
180
-                'capability' => 'ee_read_registration',
181
-                'obj_id'     => $reg_id,
182
-            ),
183
-            'edit_registration'                  => array(
184
-                'func'               => '_update_attendee_registration_form',
185
-                'noheader'           => true,
186
-                'headers_sent_route' => 'view_registration',
187
-                'capability'         => 'ee_edit_registration',
188
-                'obj_id'             => $reg_id,
189
-                '_REG_ID'            => $reg_id,
190
-            ),
191
-            'trash_registrations'                => array(
192
-                'func'       => '_trash_or_restore_registrations',
193
-                'args'       => array('trash' => true),
194
-                'noheader'   => true,
195
-                'capability' => 'ee_delete_registrations',
196
-            ),
197
-            'restore_registrations'              => array(
198
-                'func'       => '_trash_or_restore_registrations',
199
-                'args'       => array('trash' => false),
200
-                'noheader'   => true,
201
-                'capability' => 'ee_delete_registrations',
202
-            ),
203
-            'delete_registrations'               => array(
204
-                'func'       => '_delete_registrations',
205
-                'noheader'   => true,
206
-                'capability' => 'ee_delete_registrations',
207
-            ),
208
-            'new_registration'                   => array(
209
-                'func'       => 'new_registration',
210
-                'capability' => 'ee_edit_registrations',
211
-            ),
212
-            'process_reg_step'                   => array(
213
-                'func'       => 'process_reg_step',
214
-                'noheader'   => true,
215
-                'capability' => 'ee_edit_registrations',
216
-            ),
217
-            'redirect_to_txn'                    => array(
218
-                'func'       => 'redirect_to_txn',
219
-                'noheader'   => true,
220
-                'capability' => 'ee_edit_registrations',
221
-            ),
222
-            'change_reg_status'                  => array(
223
-                'func'       => '_change_reg_status',
224
-                'noheader'   => true,
225
-                'capability' => 'ee_edit_registration',
226
-                'obj_id'     => $reg_id,
227
-            ),
228
-            'approve_registration'               => array(
229
-                'func'       => 'approve_registration',
230
-                'noheader'   => true,
231
-                'capability' => 'ee_edit_registration',
232
-                'obj_id'     => $reg_id,
233
-            ),
234
-            'approve_and_notify_registration'    => array(
235
-                'func'       => 'approve_registration',
236
-                'noheader'   => true,
237
-                'args'       => array(true),
238
-                'capability' => 'ee_edit_registration',
239
-                'obj_id'     => $reg_id,
240
-            ),
241
-            'decline_registration'               => array(
242
-                'func'       => 'decline_registration',
243
-                'noheader'   => true,
244
-                'capability' => 'ee_edit_registration',
245
-                'obj_id'     => $reg_id,
246
-            ),
247
-            'decline_and_notify_registration'    => array(
248
-                'func'       => 'decline_registration',
249
-                'noheader'   => true,
250
-                'args'       => array(true),
251
-                'capability' => 'ee_edit_registration',
252
-                'obj_id'     => $reg_id,
253
-            ),
254
-            'pending_registration'               => array(
255
-                'func'       => 'pending_registration',
256
-                'noheader'   => true,
257
-                'capability' => 'ee_edit_registration',
258
-                'obj_id'     => $reg_id,
259
-            ),
260
-            'pending_and_notify_registration'    => array(
261
-                'func'       => 'pending_registration',
262
-                'noheader'   => true,
263
-                'args'       => array(true),
264
-                'capability' => 'ee_edit_registration',
265
-                'obj_id'     => $reg_id,
266
-            ),
267
-            'no_approve_registration'            => array(
268
-                'func'       => 'not_approve_registration',
269
-                'noheader'   => true,
270
-                'capability' => 'ee_edit_registration',
271
-                'obj_id'     => $reg_id,
272
-            ),
273
-            'no_approve_and_notify_registration' => array(
274
-                'func'       => 'not_approve_registration',
275
-                'noheader'   => true,
276
-                'args'       => array(true),
277
-                'capability' => 'ee_edit_registration',
278
-                'obj_id'     => $reg_id,
279
-            ),
280
-            'cancel_registration'                => array(
281
-                'func'       => 'cancel_registration',
282
-                'noheader'   => true,
283
-                'capability' => 'ee_edit_registration',
284
-                'obj_id'     => $reg_id,
285
-            ),
286
-            'cancel_and_notify_registration'     => array(
287
-                'func'       => 'cancel_registration',
288
-                'noheader'   => true,
289
-                'args'       => array(true),
290
-                'capability' => 'ee_edit_registration',
291
-                'obj_id'     => $reg_id,
292
-            ),
293
-            'contact_list'                       => array(
294
-                'func'       => '_attendee_contact_list_table',
295
-                'capability' => 'ee_read_contacts',
296
-            ),
297
-            'add_new_attendee'                   => array(
298
-                'func' => '_create_new_cpt_item',
299
-                'args' => array(
300
-                    'new_attendee' => true,
301
-                    'capability'   => 'ee_edit_contacts',
302
-                ),
303
-            ),
304
-            'edit_attendee'                      => array(
305
-                'func'       => '_edit_cpt_item',
306
-                'capability' => 'ee_edit_contacts',
307
-                'obj_id'     => $att_id,
308
-            ),
309
-            'duplicate_attendee'                 => array(
310
-                'func'       => '_duplicate_attendee',
311
-                'noheader'   => true,
312
-                'capability' => 'ee_edit_contacts',
313
-                'obj_id'     => $att_id,
314
-            ),
315
-            'insert_attendee'                    => array(
316
-                'func'       => '_insert_or_update_attendee',
317
-                'args'       => array(
318
-                    'new_attendee' => true,
319
-                ),
320
-                'noheader'   => true,
321
-                'capability' => 'ee_edit_contacts',
322
-            ),
323
-            'update_attendee'                    => array(
324
-                'func'       => '_insert_or_update_attendee',
325
-                'args'       => array(
326
-                    'new_attendee' => false,
327
-                ),
328
-                'noheader'   => true,
329
-                'capability' => 'ee_edit_contacts',
330
-                'obj_id'     => $att_id,
331
-            ),
332
-            'trash_attendees'                    => array(
333
-                'func'       => '_trash_or_restore_attendees',
334
-                'args'       => array(
335
-                    'trash' => true,
336
-                ),
337
-                'noheader'   => true,
338
-                'capability' => 'ee_delete_contacts',
339
-                'obj_id'     => $att_id,
340
-            ),
341
-            'restore_attendees'                  => array(
342
-                'func'       => '_trash_or_restore_attendees',
343
-                'args'       => array(
344
-                    'trash' => false,
345
-                ),
346
-                'noheader'   => true,
347
-                'capability' => 'ee_delete_contacts',
348
-                'obj_id'     => $att_id,
349
-            ),
350
-            'resend_registration'                => array(
351
-                'func'       => '_resend_registration',
352
-                'noheader'   => true,
353
-                'capability' => 'ee_send_message',
354
-            ),
355
-            'registrations_report'               => array(
356
-                'func'       => '_registrations_report',
357
-                'noheader'   => true,
358
-                'capability' => 'ee_read_registrations',
359
-            ),
360
-            'contact_list_export'                => array(
361
-                'func'       => '_contact_list_export',
362
-                'noheader'   => true,
363
-                'capability' => 'export',
364
-            ),
365
-            'contact_list_report'                => array(
366
-                'func'       => '_contact_list_report',
367
-                'noheader'   => true,
368
-                'capability' => 'ee_read_contacts',
369
-            ),
370
-        );
371
-    }
372
-
373
-
374
-    protected function _set_page_config()
375
-    {
376
-        $this->_page_config = array(
377
-            'default'           => array(
378
-                'nav'           => array(
379
-                    'label' => __('Overview', 'event_espresso'),
380
-                    'order' => 5,
381
-                ),
382
-                'help_tabs'     => array(
383
-                    'registrations_overview_help_tab'                       => array(
384
-                        'title'    => __('Registrations Overview', 'event_espresso'),
385
-                        'filename' => 'registrations_overview',
386
-                    ),
387
-                    'registrations_overview_table_column_headings_help_tab' => array(
388
-                        'title'    => __('Registrations Table Column Headings', 'event_espresso'),
389
-                        'filename' => 'registrations_overview_table_column_headings',
390
-                    ),
391
-                    'registrations_overview_filters_help_tab'               => array(
392
-                        'title'    => __('Registration Filters', 'event_espresso'),
393
-                        'filename' => 'registrations_overview_filters',
394
-                    ),
395
-                    'registrations_overview_views_help_tab'                 => array(
396
-                        'title'    => __('Registration Views', 'event_espresso'),
397
-                        'filename' => 'registrations_overview_views',
398
-                    ),
399
-                    'registrations_regoverview_other_help_tab'              => array(
400
-                        'title'    => __('Registrations Other', 'event_espresso'),
401
-                        'filename' => 'registrations_overview_other',
402
-                    ),
403
-                ),
404
-                'help_tour'     => array('Registration_Overview_Help_Tour'),
405
-                'qtips'         => array('Registration_List_Table_Tips'),
406
-                'list_table'    => 'EE_Registrations_List_Table',
407
-                'require_nonce' => false,
408
-            ),
409
-            'view_registration' => array(
410
-                'nav'           => array(
411
-                    'label'      => __('REG Details', 'event_espresso'),
412
-                    'order'      => 15,
413
-                    'url'        => isset($this->_req_data['_REG_ID'])
414
-                        ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
415
-                        : $this->_admin_base_url,
416
-                    'persistent' => false,
417
-                ),
418
-                'help_tabs'     => array(
419
-                    'registrations_details_help_tab'                    => array(
420
-                        'title'    => __('Registration Details', 'event_espresso'),
421
-                        'filename' => 'registrations_details',
422
-                    ),
423
-                    'registrations_details_table_help_tab'              => array(
424
-                        'title'    => __('Registration Details Table', 'event_espresso'),
425
-                        'filename' => 'registrations_details_table',
426
-                    ),
427
-                    'registrations_details_form_answers_help_tab'       => array(
428
-                        'title'    => __('Registration Form Answers', 'event_espresso'),
429
-                        'filename' => 'registrations_details_form_answers',
430
-                    ),
431
-                    'registrations_details_registrant_details_help_tab' => array(
432
-                        'title'    => __('Contact Details', 'event_espresso'),
433
-                        'filename' => 'registrations_details_registrant_details',
434
-                    ),
435
-                ),
436
-                'help_tour'     => array('Registration_Details_Help_Tour'),
437
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
438
-                    array('_registration_details_metaboxes')),
439
-                'require_nonce' => false,
440
-            ),
441
-            'new_registration'  => array(
442
-                'nav'           => array(
443
-                    'label'      => __('Add New Registration', 'event_espresso'),
444
-                    'url'        => '#',
445
-                    'order'      => 15,
446
-                    'persistent' => false,
447
-                ),
448
-                'metaboxes'     => $this->_default_espresso_metaboxes,
449
-                'labels'        => array(
450
-                    'publishbox' => __('Save Registration', 'event_espresso'),
451
-                ),
452
-                'require_nonce' => false,
453
-            ),
454
-            'add_new_attendee'  => array(
455
-                'nav'           => array(
456
-                    'label'      => __('Add Contact', 'event_espresso'),
457
-                    'order'      => 15,
458
-                    'persistent' => false,
459
-                ),
460
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
461
-                    array('_publish_post_box', 'attendee_editor_metaboxes')),
462
-                'require_nonce' => false,
463
-            ),
464
-            'edit_attendee'     => array(
465
-                'nav'           => array(
466
-                    'label'      => __('Edit Contact', 'event_espresso'),
467
-                    'order'      => 15,
468
-                    'persistent' => false,
469
-                    'url'        => isset($this->_req_data['ATT_ID'])
470
-                        ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
471
-                        : $this->_admin_base_url,
472
-                ),
473
-                'metaboxes'     => array('attendee_editor_metaboxes'),
474
-                'require_nonce' => false,
475
-            ),
476
-            'contact_list'      => array(
477
-                'nav'           => array(
478
-                    'label' => __('Contact List', 'event_espresso'),
479
-                    'order' => 20,
480
-                ),
481
-                'list_table'    => 'EE_Attendee_Contact_List_Table',
482
-                'help_tabs'     => array(
483
-                    'registrations_contact_list_help_tab'                       => array(
484
-                        'title'    => __('Registrations Contact List', 'event_espresso'),
485
-                        'filename' => 'registrations_contact_list',
486
-                    ),
487
-                    'registrations_contact-list_table_column_headings_help_tab' => array(
488
-                        'title'    => __('Contact List Table Column Headings', 'event_espresso'),
489
-                        'filename' => 'registrations_contact_list_table_column_headings',
490
-                    ),
491
-                    'registrations_contact_list_views_help_tab'                 => array(
492
-                        'title'    => __('Contact List Views', 'event_espresso'),
493
-                        'filename' => 'registrations_contact_list_views',
494
-                    ),
495
-                    'registrations_contact_list_other_help_tab'                 => array(
496
-                        'title'    => __('Contact List Other', 'event_espresso'),
497
-                        'filename' => 'registrations_contact_list_other',
498
-                    ),
499
-                ),
500
-                'help_tour'     => array('Contact_List_Help_Tour'),
501
-                'metaboxes'     => array(),
502
-                'require_nonce' => false,
503
-            ),
504
-            //override default cpt routes
505
-            'create_new'        => '',
506
-            'edit'              => '',
507
-        );
508
-    }
509
-
510
-
511
-    /**
512
-     * The below methods aren't used by this class currently
513
-     */
514
-    protected function _add_screen_options()
515
-    {
516
-    }
517
-
518
-
519
-    protected function _add_feature_pointers()
520
-    {
521
-    }
522
-
523
-
524
-    public function admin_init()
525
-    {
526
-        EE_Registry::$i18n_js_strings['update_att_qstns'] = __('click "Update Registration Questions" to save your changes',
527
-            'event_espresso');
528
-    }
529
-
530
-
531
-    public function admin_notices()
532
-    {
533
-    }
534
-
535
-
536
-    public function admin_footer_scripts()
537
-    {
538
-    }
539
-
540
-
541
-    /**
542
-     *        get list of registration statuses
543
-     *
544
-     * @access private
545
-     * @return void
546
-     */
547
-    private function _get_registration_status_array()
548
-    {
549
-        self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
550
-    }
551
-
552
-
553
-    protected function _add_screen_options_default()
554
-    {
555
-        $this->_per_page_screen_option();
556
-    }
557
-
558
-
559
-    protected function _add_screen_options_contact_list()
560
-    {
561
-        $page_title              = $this->_admin_page_title;
562
-        $this->_admin_page_title = __("Contacts", 'event_espresso');
563
-        $this->_per_page_screen_option();
564
-        $this->_admin_page_title = $page_title;
565
-    }
566
-
567
-
568
-    public function load_scripts_styles()
569
-    {
570
-        //style
571
-        //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION );
572
-        wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'),
573
-            EVENT_ESPRESSO_VERSION);
574
-        wp_enqueue_style('espresso_reg');
575
-        //script
576
-        wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js',
577
-            array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true);
578
-        wp_enqueue_script('espresso_reg');
579
-    }
580
-
581
-
582
-    public function load_scripts_styles_edit_attendee()
583
-    {
584
-        //stuff to only show up on our attendee edit details page.
585
-        $attendee_details_translations = array(
586
-            'att_publish_text' => sprintf(__('Created on: <b>%1$s</b>', 'event_espresso'),
587
-                $this->_cpt_model_obj->get_datetime('ATT_created')),
588
-        );
589
-        wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
590
-        wp_enqueue_script('jquery-validate');
591
-    }
592
-
593
-
594
-    public function load_scripts_styles_view_registration()
595
-    {
596
-        //styles
597
-        wp_enqueue_style('espresso-ui-theme');
598
-        //scripts
599
-        $this->_get_reg_custom_questions_form($this->_registration->ID());
600
-        $this->_reg_custom_questions_form->wp_enqueue_scripts(true);
601
-    }
602
-
603
-
604
-    public function load_scripts_styles_contact_list()
605
-    {
606
-        wp_deregister_style('espresso_reg');
607
-        wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'),
608
-            EVENT_ESPRESSO_VERSION);
609
-        wp_enqueue_style('espresso_att');
610
-    }
611
-
612
-
613
-    public function load_scripts_styles_new_registration()
614
-    {
615
-        wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'),
616
-            EVENT_ESPRESSO_VERSION, true);
617
-        wp_enqueue_script('ee-spco-for-admin');
618
-        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
619
-        EE_Form_Section_Proper::wp_enqueue_scripts();
620
-        EED_Ticket_Selector::load_tckt_slctr_assets();
621
-        EE_Datepicker_Input::enqueue_styles_and_scripts();
622
-    }
623
-
624
-
625
-    public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
626
-    {
627
-        add_filter('FHEE_load_EE_messages', '__return_true');
628
-    }
629
-
630
-
631
-    public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
632
-    {
633
-        add_filter('FHEE_load_EE_messages', '__return_true');
634
-    }
635
-
636
-
637
-    protected function _set_list_table_views_default()
638
-    {
639
-        //for notification related bulk actions we need to make sure only active messengers have an option.
640
-        EED_Messages::set_autoloaders();
641
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
642
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
643
-        $active_mts               = $message_resource_manager->list_of_active_message_types();
644
-        //key= bulk_action_slug, value= message type.
645
-        $match_array = array(
646
-            'approve_registration'    => 'registration',
647
-            'decline_registration'    => 'declined_registration',
648
-            'pending_registration'    => 'pending_approval',
649
-            'no_approve_registration' => 'not_approved_registration',
650
-            'cancel_registration'     => 'cancelled_registration',
651
-        );
652
-        /** setup reg status bulk actions **/
653
-        $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
654
-        if (in_array($match_array['approve_registration'], $active_mts)
655
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
656
-        ) {
657
-            $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
658
-                'event_espresso');
659
-        }
660
-        $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
661
-        if (in_array($match_array['decline_registration'], $active_mts)
662
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
663
-        ) {
664
-            $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
665
-                'event_espresso');
666
-        }
667
-        $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
668
-        if (in_array($match_array['pending_registration'], $active_mts)
669
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
670
-        ) {
671
-            $def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify',
672
-                'event_espresso');
673
-        }
674
-        $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
675
-        if (in_array($match_array['no_approve_registration'], $active_mts)
676
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
677
-        ) {
678
-            $def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify',
679
-                'event_espresso');
680
-        }
681
-        $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
682
-        if (in_array($match_array['cancel_registration'], $active_mts)
683
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
684
-        ) {
685
-            $def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify',
686
-                'event_espresso');
687
-        }
688
-        $this->_views = array(
689
-            'all'   => array(
690
-                'slug'        => 'all',
691
-                'label'       => __('View All Registrations', 'event_espresso'),
692
-                'count'       => 0,
693
-                'bulk_action' => array_merge($def_reg_status_actions, array(
694
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
695
-                )),
696
-            ),
697
-            'month' => array(
698
-                'slug'        => 'month',
699
-                'label'       => __('This Month', 'event_espresso'),
700
-                'count'       => 0,
701
-                'bulk_action' => array_merge($def_reg_status_actions, array(
702
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
703
-                )),
704
-            ),
705
-            'today' => array(
706
-                'slug'        => 'today',
707
-                'label'       => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))),
708
-                'count'       => 0,
709
-                'bulk_action' => array_merge($def_reg_status_actions, array(
710
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
711
-                )),
712
-            ),
713
-        );
714
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations',
715
-            'espresso_registrations_delete_registration')
716
-        ) {
717
-            $this->_views['incomplete'] = array(
718
-                'slug'        => 'incomplete',
719
-                'label'       => __('Incomplete', 'event_espresso'),
720
-                'count'       => 0,
721
-                'bulk_action' => array(
722
-                    'trash_registrations' => __('Trash Registrations', 'event_espresso'),
723
-                ),
724
-            );
725
-            $this->_views['trash']      = array(
726
-                'slug'        => 'trash',
727
-                'label'       => __('Trash', 'event_espresso'),
728
-                'count'       => 0,
729
-                'bulk_action' => array(
730
-                    'restore_registrations' => __('Restore Registrations', 'event_espresso'),
731
-                    'delete_registrations'  => __('Delete Registrations Permanently', 'event_espresso'),
732
-                ),
733
-            );
734
-        }
735
-    }
736
-
737
-
738
-    protected function _set_list_table_views_contact_list()
739
-    {
740
-        $this->_views = array(
741
-            'in_use' => array(
742
-                'slug'        => 'in_use',
743
-                'label'       => __('In Use', 'event_espresso'),
744
-                'count'       => 0,
745
-                'bulk_action' => array(
746
-                    'trash_attendees' => __('Move to Trash', 'event_espresso'),
747
-                ),
748
-            ),
749
-        );
750
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
751
-            'espresso_registrations_trash_attendees')
752
-        ) {
753
-            $this->_views['trash'] = array(
754
-                'slug'        => 'trash',
755
-                'label'       => __('Trash', 'event_espresso'),
756
-                'count'       => 0,
757
-                'bulk_action' => array(
758
-                    'restore_attendees' => __('Restore from Trash', 'event_espresso'),
759
-                ),
760
-            );
761
-        }
762
-    }
763
-
764
-
765
-    protected function _registration_legend_items()
766
-    {
767
-        $fc_items = array(
768
-            'star-icon'        => array(
769
-                'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
770
-                'desc'  => __('This is the Primary Registrant', 'event_espresso'),
771
-            ),
772
-            'view_details'     => array(
773
-                'class' => 'dashicons dashicons-clipboard',
774
-                'desc'  => __('View Registration Details', 'event_espresso'),
775
-            ),
776
-            'edit_attendee'    => array(
777
-                'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
778
-                'desc'  => __('Edit Contact Details', 'event_espresso'),
779
-            ),
780
-            'view_transaction' => array(
781
-                'class' => 'dashicons dashicons-cart',
782
-                'desc'  => __('View Transaction Details', 'event_espresso'),
783
-            ),
784
-            'view_invoice'     => array(
785
-                'class' => 'dashicons dashicons-media-spreadsheet',
786
-                'desc'  => __('View Transaction Invoice', 'event_espresso'),
787
-            ),
788
-        );
789
-        if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
790
-            'espresso_registrations_resend_registration')
791
-        ) {
792
-            $fc_items['resend_registration'] = array(
793
-                'class' => 'dashicons dashicons-email-alt',
794
-                'desc'  => __('Resend Registration Details', 'event_espresso'),
795
-            );
796
-        } else {
797
-            $fc_items['blank'] = array('class' => 'blank', 'desc' => '');
798
-        }
799
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
800
-            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
801
-            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
802
-                $fc_items['view_related_messages'] = array(
803
-                    'class' => $related_for_icon['css_class'],
804
-                    'desc'  => $related_for_icon['label'],
805
-                );
806
-            }
807
-        }
808
-        $sc_items = array(
809
-            'approved_status'   => array(
810
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
811
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
812
-            ),
813
-            'pending_status'    => array(
814
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
815
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
816
-            ),
817
-            'wait_list'         => array(
818
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
819
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
820
-            ),
821
-            'incomplete_status' => array(
822
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
823
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'),
824
-            ),
825
-            'not_approved'      => array(
826
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
827
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
828
-            ),
829
-            'declined_status'   => array(
830
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
831
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
832
-            ),
833
-            'cancelled_status'  => array(
834
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
835
-                'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
836
-            ),
837
-        );
838
-        return array_merge($fc_items, $sc_items);
839
-    }
840
-
841
-
842
-
843
-    /***************************************        REGISTRATION OVERVIEW        **************************************/
844
-    /**
845
-     * @throws \EE_Error
846
-     */
847
-    protected function _registrations_overview_list_table()
848
-    {
849
-        $this->_template_args['admin_page_header'] = '';
850
-        $EVT_ID                                    = ! empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : 0;
851
-        if ($EVT_ID) {
852
-            if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations',
853
-                'espresso_registrations_new_registration', $EVT_ID)
854
-            ) {
855
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant',
856
-                        array('event_id' => $EVT_ID), 'add-new-h2');
857
-            }
858
-            $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
859
-            if ($event instanceof EE_Event) {
860
-                $this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s',
861
-                    'event_espresso'), '<h3 style="line-height:1.5em;">',
862
-                    '<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array(
863
-                        'action' => 'edit',
864
-                        'post'   => $event->ID(),
865
-                    ), EVENTS_ADMIN_URL) . '">&nbsp;' . $event->get('EVT_name') . '&nbsp;</a>&nbsp;', '</h3>');
866
-            }
867
-            $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
868
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
869
-            if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
870
-                $this->_template_args['admin_page_header'] = substr($this->_template_args['admin_page_header'], 0, -5);
871
-                $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
872
-                $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
873
-                $this->_template_args['admin_page_header'] .= $datetime->name();
874
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
875
-                $this->_template_args['admin_page_header'] .= '</span></h3>';
876
-            }
877
-        }
878
-        $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
879
-        $this->display_admin_list_table_page_with_no_sidebar();
880
-    }
881
-
882
-
883
-    /**
884
-     * This sets the _registration property for the registration details screen
885
-     *
886
-     * @access private
887
-     * @return bool
888
-     */
889
-    private function _set_registration_object()
890
-    {
891
-        //get out if we've already set the object
892
-        if (is_object($this->_registration)) {
893
-            return true;
894
-        }
895
-        $REG    = EEM_Registration::instance();
896
-        $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
897
-        if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
898
-            return true;
899
-        } else {
900
-            $error_msg = sprintf(__('An error occurred and the details for Registration ID #%s could not be retrieved.',
901
-                'event_espresso'), $REG_ID);
902
-            EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
903
-            $this->_registration = null;
904
-            return false;
905
-        }
906
-    }
907
-
908
-
909
-    /**
910
-     * Used to retrieve registrations for the list table.
911
-     *
912
-     * @param int    $per_page
913
-     * @param bool   $count
914
-     * @param bool   $this_month
915
-     * @param bool   $today
916
-     * @return \EE_Registration[]|int
917
-     */
918
-    public function get_registrations(
919
-        $per_page = 10,
920
-        $count = false,
921
-        $this_month = false,
922
-        $today = false
923
-    ) {
924
-        if( $this_month ) {
925
-            $this->_req_data['status'] = 'month';
926
-        }
927
-        if( $today ) {
928
-            $this->_req_data['status'] = 'today';
929
-        }
930
-        $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
931
-        return $count
932
-            ? EEM_Registration::instance()->count($query_params)
933
-            /** @type EE_Registration[] */
934
-            : EEM_Registration::instance()->get_all($query_params);
935
-    }
936
-
937
-
938
-
939
-    /**
940
-     * Retrieves the query parameters to be used by the Registration model for getting registrations.
941
-     * Note: this listens to values on the request for some of the query parameters.
942
-     *
943
-     * @param array $request
944
-     * @param int    $per_page
945
-     * @param bool   $count
946
-     * @return array
947
-     */
948
-    protected function _get_registration_query_parameters(
949
-        $request = array(),
950
-        $per_page = 10,
951
-        $count = false
952
-    ) {
953
-
954
-        $query_params = array(
955
-            0                          => $this->_get_where_conditions_for_registrations_query(
956
-                $request
957
-            ),
958
-            'caps'                     => EEM_Registration::caps_read_admin,
959
-            'default_where_conditions' => 'this_model_only',
960
-        );
961
-        if ( ! $count) {
962
-            $query_params = array_merge(
963
-                $query_params,
964
-                $this->_get_orderby_for_registrations_query(),
965
-                $this->_get_limit($per_page)
966
-            );
967
-        }
968
-
969
-        return $query_params;
970
-    }
971
-
972
-
973
-    /**
974
-     * This will add EVT_ID to the provided $where array for EE model query parameters.
975
-     *
976
-     * @param array $request usually the same as $this->_req_data but not necessarily
977
-     * @return array
978
-     */
979
-    protected function _add_event_id_to_where_conditions(array $request)
980
-    {
981
-        $where = array();
982
-        if ( ! empty($request['event_id'])) {
983
-            $where['EVT_ID'] = absint($request['event_id']);
984
-        }
985
-        return $where;
986
-    }
987
-
988
-
989
-    /**
990
-     * Adds category ID if it exists in the request to the where conditions for the registrations query.
991
-     *
992
-     * @param array $request usually the same as $this->_req_data but not necessarily
993
-     * @return array
994
-     */
995
-    protected function _add_category_id_to_where_conditions(array $request)
996
-    {
997
-        $where = array();
998
-        if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
999
-            $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1000
-        }
1001
-        return $where;
1002
-    }
1003
-
1004
-
1005
-    /**
1006
-     * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1007
-     *
1008
-     * @param array $request usually the same as $this->_req_data but not necessarily
1009
-     * @return array
1010
-     */
1011
-    protected function _add_datetime_id_to_where_conditions(array $request)
1012
-    {
1013
-        $where = array();
1014
-        if ( ! empty($request['datetime_id'])) {
1015
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1016
-        }
1017
-        if( ! empty($request['DTT_ID'])){
1018
-            $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1019
-        }
1020
-        return $where;
1021
-    }
1022
-
1023
-
1024
-    /**
1025
-     * Adds the correct registration status to the where conditions for the registrations query.
1026
-     *
1027
-     * @param array $request usually the same as $this->_req_data but not necessarily
1028
-     * @return array
1029
-     */
1030
-    protected function _add_registration_status_to_where_conditions(array $request)
1031
-    {
1032
-        $where = array();
1033
-        $view  = EEH_Array::is_set( $request, 'status', '' );
1034
-        $registration_status = ! empty($request['_reg_status'])
1035
-            ? sanitize_text_field($request['_reg_status'])
1036
-            : '';
1037
-
1038
-        /*
26
+	/**
27
+	 * @var EE_Registration
28
+	 */
29
+	private $_registration;
30
+
31
+	/**
32
+	 * @var EE_Event
33
+	 */
34
+	private $_reg_event;
35
+
36
+	/**
37
+	 * @var EE_Session
38
+	 */
39
+	private $_session;
40
+
41
+	private static $_reg_status;
42
+
43
+	/**
44
+	 * Form for displaying the custom questions for this registration.
45
+	 * This gets used a few times throughout the request so its best to cache it
46
+	 *
47
+	 * @var EE_Registration_Custom_Questions_Form
48
+	 */
49
+	protected $_reg_custom_questions_form = null;
50
+
51
+
52
+	/**
53
+	 *        constructor
54
+	 *
55
+	 * @Constructor
56
+	 * @access public
57
+	 * @param bool $routing
58
+	 * @return Registrations_Admin_Page
59
+	 */
60
+	public function __construct($routing = true)
61
+	{
62
+		parent::__construct($routing);
63
+		add_action('wp_loaded', array($this, 'wp_loaded'));
64
+	}
65
+
66
+
67
+	public function wp_loaded()
68
+	{
69
+		// when adding a new registration...
70
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') {
71
+			EE_System::do_not_cache();
72
+			if ( ! isset($this->_req_data['processing_registration'])
73
+				 || absint($this->_req_data['processing_registration']) !== 1
74
+			) {
75
+				// and it's NOT the attendee information reg step
76
+				// force cookie expiration by setting time to last week
77
+				setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/');
78
+				// and update the global
79
+				$_COOKIE['ee_registration_added'] = 0;
80
+			}
81
+		}
82
+	}
83
+
84
+
85
+	protected function _init_page_props()
86
+	{
87
+		$this->page_slug        = REG_PG_SLUG;
88
+		$this->_admin_base_url  = REG_ADMIN_URL;
89
+		$this->_admin_base_path = REG_ADMIN;
90
+		$this->page_label       = __('Registrations', 'event_espresso');
91
+		$this->_cpt_routes      = array(
92
+			'add_new_attendee' => 'espresso_attendees',
93
+			'edit_attendee'    => 'espresso_attendees',
94
+			'insert_attendee'  => 'espresso_attendees',
95
+			'update_attendee'  => 'espresso_attendees',
96
+		);
97
+		$this->_cpt_model_names = array(
98
+			'add_new_attendee' => 'EEM_Attendee',
99
+			'edit_attendee'    => 'EEM_Attendee',
100
+		);
101
+		$this->_cpt_edit_routes = array(
102
+			'espresso_attendees' => 'edit_attendee',
103
+		);
104
+		$this->_pagenow_map     = array(
105
+			'add_new_attendee' => 'post-new.php',
106
+			'edit_attendee'    => 'post.php',
107
+			'trash'            => 'post.php',
108
+		);
109
+		add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10);
110
+		//add filters so that the comment urls don't take users to a confusing 404 page
111
+		add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3);
112
+	}
113
+
114
+
115
+	public function clear_comment_link($link, $comment, $args)
116
+	{
117
+		//gotta make sure this only happens on this route
118
+		$post_type = get_post_type($comment->comment_post_ID);
119
+		if ($post_type === 'espresso_attendees') {
120
+			return '#commentsdiv';
121
+		}
122
+		return $link;
123
+	}
124
+
125
+
126
+	protected function _ajax_hooks()
127
+	{
128
+		//todo: all hooks for registrations ajax goes in here
129
+		add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status'));
130
+	}
131
+
132
+
133
+	protected function _define_page_props()
134
+	{
135
+		$this->_admin_page_title = $this->page_label;
136
+		$this->_labels           = array(
137
+			'buttons'                      => array(
138
+				'add-registrant'      => __('Add New Registration', 'event_espresso'),
139
+				'add-attendee'        => __('Add Contact', 'event_espresso'),
140
+				'edit'                => __('Edit Contact', 'event_espresso'),
141
+				'report'              => __("Event Registrations CSV Report", "event_espresso"),
142
+				'report_all'          => __('All Registrations CSV Report', 'event_espresso'),
143
+				'report_filtered'     => __('Filtered CSV Report', 'event_espresso'),
144
+				'contact_list_report' => __('Contact List Report', 'event_espresso'),
145
+				'contact_list_export' => __("Export Data", "event_espresso"),
146
+			),
147
+			'publishbox'                   => array(
148
+				'add_new_attendee' => __("Add Contact Record", 'event_espresso'),
149
+				'edit_attendee'    => __("Update Contact Record", 'event_espresso'),
150
+			),
151
+			'hide_add_button_on_cpt_route' => array(
152
+				'edit_attendee' => true,
153
+			),
154
+		);
155
+	}
156
+
157
+
158
+	/**
159
+	 *        grab url requests and route them
160
+	 *
161
+	 * @access private
162
+	 * @return void
163
+	 */
164
+	public function _set_page_routes()
165
+	{
166
+		$this->_get_registration_status_array();
167
+		$reg_id             = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID'])
168
+			? $this->_req_data['_REG_ID'] : 0;
169
+		$att_id             = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID'])
170
+			? $this->_req_data['ATT_ID'] : 0;
171
+		$att_id             = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) ? $this->_req_data['post']
172
+			: $att_id;
173
+		$this->_page_routes = array(
174
+			'default'                            => array(
175
+				'func'       => '_registrations_overview_list_table',
176
+				'capability' => 'ee_read_registrations',
177
+			),
178
+			'view_registration'                  => array(
179
+				'func'       => '_registration_details',
180
+				'capability' => 'ee_read_registration',
181
+				'obj_id'     => $reg_id,
182
+			),
183
+			'edit_registration'                  => array(
184
+				'func'               => '_update_attendee_registration_form',
185
+				'noheader'           => true,
186
+				'headers_sent_route' => 'view_registration',
187
+				'capability'         => 'ee_edit_registration',
188
+				'obj_id'             => $reg_id,
189
+				'_REG_ID'            => $reg_id,
190
+			),
191
+			'trash_registrations'                => array(
192
+				'func'       => '_trash_or_restore_registrations',
193
+				'args'       => array('trash' => true),
194
+				'noheader'   => true,
195
+				'capability' => 'ee_delete_registrations',
196
+			),
197
+			'restore_registrations'              => array(
198
+				'func'       => '_trash_or_restore_registrations',
199
+				'args'       => array('trash' => false),
200
+				'noheader'   => true,
201
+				'capability' => 'ee_delete_registrations',
202
+			),
203
+			'delete_registrations'               => array(
204
+				'func'       => '_delete_registrations',
205
+				'noheader'   => true,
206
+				'capability' => 'ee_delete_registrations',
207
+			),
208
+			'new_registration'                   => array(
209
+				'func'       => 'new_registration',
210
+				'capability' => 'ee_edit_registrations',
211
+			),
212
+			'process_reg_step'                   => array(
213
+				'func'       => 'process_reg_step',
214
+				'noheader'   => true,
215
+				'capability' => 'ee_edit_registrations',
216
+			),
217
+			'redirect_to_txn'                    => array(
218
+				'func'       => 'redirect_to_txn',
219
+				'noheader'   => true,
220
+				'capability' => 'ee_edit_registrations',
221
+			),
222
+			'change_reg_status'                  => array(
223
+				'func'       => '_change_reg_status',
224
+				'noheader'   => true,
225
+				'capability' => 'ee_edit_registration',
226
+				'obj_id'     => $reg_id,
227
+			),
228
+			'approve_registration'               => array(
229
+				'func'       => 'approve_registration',
230
+				'noheader'   => true,
231
+				'capability' => 'ee_edit_registration',
232
+				'obj_id'     => $reg_id,
233
+			),
234
+			'approve_and_notify_registration'    => array(
235
+				'func'       => 'approve_registration',
236
+				'noheader'   => true,
237
+				'args'       => array(true),
238
+				'capability' => 'ee_edit_registration',
239
+				'obj_id'     => $reg_id,
240
+			),
241
+			'decline_registration'               => array(
242
+				'func'       => 'decline_registration',
243
+				'noheader'   => true,
244
+				'capability' => 'ee_edit_registration',
245
+				'obj_id'     => $reg_id,
246
+			),
247
+			'decline_and_notify_registration'    => array(
248
+				'func'       => 'decline_registration',
249
+				'noheader'   => true,
250
+				'args'       => array(true),
251
+				'capability' => 'ee_edit_registration',
252
+				'obj_id'     => $reg_id,
253
+			),
254
+			'pending_registration'               => array(
255
+				'func'       => 'pending_registration',
256
+				'noheader'   => true,
257
+				'capability' => 'ee_edit_registration',
258
+				'obj_id'     => $reg_id,
259
+			),
260
+			'pending_and_notify_registration'    => array(
261
+				'func'       => 'pending_registration',
262
+				'noheader'   => true,
263
+				'args'       => array(true),
264
+				'capability' => 'ee_edit_registration',
265
+				'obj_id'     => $reg_id,
266
+			),
267
+			'no_approve_registration'            => array(
268
+				'func'       => 'not_approve_registration',
269
+				'noheader'   => true,
270
+				'capability' => 'ee_edit_registration',
271
+				'obj_id'     => $reg_id,
272
+			),
273
+			'no_approve_and_notify_registration' => array(
274
+				'func'       => 'not_approve_registration',
275
+				'noheader'   => true,
276
+				'args'       => array(true),
277
+				'capability' => 'ee_edit_registration',
278
+				'obj_id'     => $reg_id,
279
+			),
280
+			'cancel_registration'                => array(
281
+				'func'       => 'cancel_registration',
282
+				'noheader'   => true,
283
+				'capability' => 'ee_edit_registration',
284
+				'obj_id'     => $reg_id,
285
+			),
286
+			'cancel_and_notify_registration'     => array(
287
+				'func'       => 'cancel_registration',
288
+				'noheader'   => true,
289
+				'args'       => array(true),
290
+				'capability' => 'ee_edit_registration',
291
+				'obj_id'     => $reg_id,
292
+			),
293
+			'contact_list'                       => array(
294
+				'func'       => '_attendee_contact_list_table',
295
+				'capability' => 'ee_read_contacts',
296
+			),
297
+			'add_new_attendee'                   => array(
298
+				'func' => '_create_new_cpt_item',
299
+				'args' => array(
300
+					'new_attendee' => true,
301
+					'capability'   => 'ee_edit_contacts',
302
+				),
303
+			),
304
+			'edit_attendee'                      => array(
305
+				'func'       => '_edit_cpt_item',
306
+				'capability' => 'ee_edit_contacts',
307
+				'obj_id'     => $att_id,
308
+			),
309
+			'duplicate_attendee'                 => array(
310
+				'func'       => '_duplicate_attendee',
311
+				'noheader'   => true,
312
+				'capability' => 'ee_edit_contacts',
313
+				'obj_id'     => $att_id,
314
+			),
315
+			'insert_attendee'                    => array(
316
+				'func'       => '_insert_or_update_attendee',
317
+				'args'       => array(
318
+					'new_attendee' => true,
319
+				),
320
+				'noheader'   => true,
321
+				'capability' => 'ee_edit_contacts',
322
+			),
323
+			'update_attendee'                    => array(
324
+				'func'       => '_insert_or_update_attendee',
325
+				'args'       => array(
326
+					'new_attendee' => false,
327
+				),
328
+				'noheader'   => true,
329
+				'capability' => 'ee_edit_contacts',
330
+				'obj_id'     => $att_id,
331
+			),
332
+			'trash_attendees'                    => array(
333
+				'func'       => '_trash_or_restore_attendees',
334
+				'args'       => array(
335
+					'trash' => true,
336
+				),
337
+				'noheader'   => true,
338
+				'capability' => 'ee_delete_contacts',
339
+				'obj_id'     => $att_id,
340
+			),
341
+			'restore_attendees'                  => array(
342
+				'func'       => '_trash_or_restore_attendees',
343
+				'args'       => array(
344
+					'trash' => false,
345
+				),
346
+				'noheader'   => true,
347
+				'capability' => 'ee_delete_contacts',
348
+				'obj_id'     => $att_id,
349
+			),
350
+			'resend_registration'                => array(
351
+				'func'       => '_resend_registration',
352
+				'noheader'   => true,
353
+				'capability' => 'ee_send_message',
354
+			),
355
+			'registrations_report'               => array(
356
+				'func'       => '_registrations_report',
357
+				'noheader'   => true,
358
+				'capability' => 'ee_read_registrations',
359
+			),
360
+			'contact_list_export'                => array(
361
+				'func'       => '_contact_list_export',
362
+				'noheader'   => true,
363
+				'capability' => 'export',
364
+			),
365
+			'contact_list_report'                => array(
366
+				'func'       => '_contact_list_report',
367
+				'noheader'   => true,
368
+				'capability' => 'ee_read_contacts',
369
+			),
370
+		);
371
+	}
372
+
373
+
374
+	protected function _set_page_config()
375
+	{
376
+		$this->_page_config = array(
377
+			'default'           => array(
378
+				'nav'           => array(
379
+					'label' => __('Overview', 'event_espresso'),
380
+					'order' => 5,
381
+				),
382
+				'help_tabs'     => array(
383
+					'registrations_overview_help_tab'                       => array(
384
+						'title'    => __('Registrations Overview', 'event_espresso'),
385
+						'filename' => 'registrations_overview',
386
+					),
387
+					'registrations_overview_table_column_headings_help_tab' => array(
388
+						'title'    => __('Registrations Table Column Headings', 'event_espresso'),
389
+						'filename' => 'registrations_overview_table_column_headings',
390
+					),
391
+					'registrations_overview_filters_help_tab'               => array(
392
+						'title'    => __('Registration Filters', 'event_espresso'),
393
+						'filename' => 'registrations_overview_filters',
394
+					),
395
+					'registrations_overview_views_help_tab'                 => array(
396
+						'title'    => __('Registration Views', 'event_espresso'),
397
+						'filename' => 'registrations_overview_views',
398
+					),
399
+					'registrations_regoverview_other_help_tab'              => array(
400
+						'title'    => __('Registrations Other', 'event_espresso'),
401
+						'filename' => 'registrations_overview_other',
402
+					),
403
+				),
404
+				'help_tour'     => array('Registration_Overview_Help_Tour'),
405
+				'qtips'         => array('Registration_List_Table_Tips'),
406
+				'list_table'    => 'EE_Registrations_List_Table',
407
+				'require_nonce' => false,
408
+			),
409
+			'view_registration' => array(
410
+				'nav'           => array(
411
+					'label'      => __('REG Details', 'event_espresso'),
412
+					'order'      => 15,
413
+					'url'        => isset($this->_req_data['_REG_ID'])
414
+						? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url)
415
+						: $this->_admin_base_url,
416
+					'persistent' => false,
417
+				),
418
+				'help_tabs'     => array(
419
+					'registrations_details_help_tab'                    => array(
420
+						'title'    => __('Registration Details', 'event_espresso'),
421
+						'filename' => 'registrations_details',
422
+					),
423
+					'registrations_details_table_help_tab'              => array(
424
+						'title'    => __('Registration Details Table', 'event_espresso'),
425
+						'filename' => 'registrations_details_table',
426
+					),
427
+					'registrations_details_form_answers_help_tab'       => array(
428
+						'title'    => __('Registration Form Answers', 'event_espresso'),
429
+						'filename' => 'registrations_details_form_answers',
430
+					),
431
+					'registrations_details_registrant_details_help_tab' => array(
432
+						'title'    => __('Contact Details', 'event_espresso'),
433
+						'filename' => 'registrations_details_registrant_details',
434
+					),
435
+				),
436
+				'help_tour'     => array('Registration_Details_Help_Tour'),
437
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
438
+					array('_registration_details_metaboxes')),
439
+				'require_nonce' => false,
440
+			),
441
+			'new_registration'  => array(
442
+				'nav'           => array(
443
+					'label'      => __('Add New Registration', 'event_espresso'),
444
+					'url'        => '#',
445
+					'order'      => 15,
446
+					'persistent' => false,
447
+				),
448
+				'metaboxes'     => $this->_default_espresso_metaboxes,
449
+				'labels'        => array(
450
+					'publishbox' => __('Save Registration', 'event_espresso'),
451
+				),
452
+				'require_nonce' => false,
453
+			),
454
+			'add_new_attendee'  => array(
455
+				'nav'           => array(
456
+					'label'      => __('Add Contact', 'event_espresso'),
457
+					'order'      => 15,
458
+					'persistent' => false,
459
+				),
460
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes,
461
+					array('_publish_post_box', 'attendee_editor_metaboxes')),
462
+				'require_nonce' => false,
463
+			),
464
+			'edit_attendee'     => array(
465
+				'nav'           => array(
466
+					'label'      => __('Edit Contact', 'event_espresso'),
467
+					'order'      => 15,
468
+					'persistent' => false,
469
+					'url'        => isset($this->_req_data['ATT_ID'])
470
+						? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url)
471
+						: $this->_admin_base_url,
472
+				),
473
+				'metaboxes'     => array('attendee_editor_metaboxes'),
474
+				'require_nonce' => false,
475
+			),
476
+			'contact_list'      => array(
477
+				'nav'           => array(
478
+					'label' => __('Contact List', 'event_espresso'),
479
+					'order' => 20,
480
+				),
481
+				'list_table'    => 'EE_Attendee_Contact_List_Table',
482
+				'help_tabs'     => array(
483
+					'registrations_contact_list_help_tab'                       => array(
484
+						'title'    => __('Registrations Contact List', 'event_espresso'),
485
+						'filename' => 'registrations_contact_list',
486
+					),
487
+					'registrations_contact-list_table_column_headings_help_tab' => array(
488
+						'title'    => __('Contact List Table Column Headings', 'event_espresso'),
489
+						'filename' => 'registrations_contact_list_table_column_headings',
490
+					),
491
+					'registrations_contact_list_views_help_tab'                 => array(
492
+						'title'    => __('Contact List Views', 'event_espresso'),
493
+						'filename' => 'registrations_contact_list_views',
494
+					),
495
+					'registrations_contact_list_other_help_tab'                 => array(
496
+						'title'    => __('Contact List Other', 'event_espresso'),
497
+						'filename' => 'registrations_contact_list_other',
498
+					),
499
+				),
500
+				'help_tour'     => array('Contact_List_Help_Tour'),
501
+				'metaboxes'     => array(),
502
+				'require_nonce' => false,
503
+			),
504
+			//override default cpt routes
505
+			'create_new'        => '',
506
+			'edit'              => '',
507
+		);
508
+	}
509
+
510
+
511
+	/**
512
+	 * The below methods aren't used by this class currently
513
+	 */
514
+	protected function _add_screen_options()
515
+	{
516
+	}
517
+
518
+
519
+	protected function _add_feature_pointers()
520
+	{
521
+	}
522
+
523
+
524
+	public function admin_init()
525
+	{
526
+		EE_Registry::$i18n_js_strings['update_att_qstns'] = __('click "Update Registration Questions" to save your changes',
527
+			'event_espresso');
528
+	}
529
+
530
+
531
+	public function admin_notices()
532
+	{
533
+	}
534
+
535
+
536
+	public function admin_footer_scripts()
537
+	{
538
+	}
539
+
540
+
541
+	/**
542
+	 *        get list of registration statuses
543
+	 *
544
+	 * @access private
545
+	 * @return void
546
+	 */
547
+	private function _get_registration_status_array()
548
+	{
549
+		self::$_reg_status = EEM_Registration::reg_status_array(array(), true);
550
+	}
551
+
552
+
553
+	protected function _add_screen_options_default()
554
+	{
555
+		$this->_per_page_screen_option();
556
+	}
557
+
558
+
559
+	protected function _add_screen_options_contact_list()
560
+	{
561
+		$page_title              = $this->_admin_page_title;
562
+		$this->_admin_page_title = __("Contacts", 'event_espresso');
563
+		$this->_per_page_screen_option();
564
+		$this->_admin_page_title = $page_title;
565
+	}
566
+
567
+
568
+	public function load_scripts_styles()
569
+	{
570
+		//style
571
+		//wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION );
572
+		wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'),
573
+			EVENT_ESPRESSO_VERSION);
574
+		wp_enqueue_style('espresso_reg');
575
+		//script
576
+		wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js',
577
+			array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true);
578
+		wp_enqueue_script('espresso_reg');
579
+	}
580
+
581
+
582
+	public function load_scripts_styles_edit_attendee()
583
+	{
584
+		//stuff to only show up on our attendee edit details page.
585
+		$attendee_details_translations = array(
586
+			'att_publish_text' => sprintf(__('Created on: <b>%1$s</b>', 'event_espresso'),
587
+				$this->_cpt_model_obj->get_datetime('ATT_created')),
588
+		);
589
+		wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations);
590
+		wp_enqueue_script('jquery-validate');
591
+	}
592
+
593
+
594
+	public function load_scripts_styles_view_registration()
595
+	{
596
+		//styles
597
+		wp_enqueue_style('espresso-ui-theme');
598
+		//scripts
599
+		$this->_get_reg_custom_questions_form($this->_registration->ID());
600
+		$this->_reg_custom_questions_form->wp_enqueue_scripts(true);
601
+	}
602
+
603
+
604
+	public function load_scripts_styles_contact_list()
605
+	{
606
+		wp_deregister_style('espresso_reg');
607
+		wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'),
608
+			EVENT_ESPRESSO_VERSION);
609
+		wp_enqueue_style('espresso_att');
610
+	}
611
+
612
+
613
+	public function load_scripts_styles_new_registration()
614
+	{
615
+		wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'),
616
+			EVENT_ESPRESSO_VERSION, true);
617
+		wp_enqueue_script('ee-spco-for-admin');
618
+		add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
619
+		EE_Form_Section_Proper::wp_enqueue_scripts();
620
+		EED_Ticket_Selector::load_tckt_slctr_assets();
621
+		EE_Datepicker_Input::enqueue_styles_and_scripts();
622
+	}
623
+
624
+
625
+	public function AHEE__EE_Admin_Page__route_admin_request_resend_registration()
626
+	{
627
+		add_filter('FHEE_load_EE_messages', '__return_true');
628
+	}
629
+
630
+
631
+	public function AHEE__EE_Admin_Page__route_admin_request_approve_registration()
632
+	{
633
+		add_filter('FHEE_load_EE_messages', '__return_true');
634
+	}
635
+
636
+
637
+	protected function _set_list_table_views_default()
638
+	{
639
+		//for notification related bulk actions we need to make sure only active messengers have an option.
640
+		EED_Messages::set_autoloaders();
641
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
642
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
643
+		$active_mts               = $message_resource_manager->list_of_active_message_types();
644
+		//key= bulk_action_slug, value= message type.
645
+		$match_array = array(
646
+			'approve_registration'    => 'registration',
647
+			'decline_registration'    => 'declined_registration',
648
+			'pending_registration'    => 'pending_approval',
649
+			'no_approve_registration' => 'not_approved_registration',
650
+			'cancel_registration'     => 'cancelled_registration',
651
+		);
652
+		/** setup reg status bulk actions **/
653
+		$def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso');
654
+		if (in_array($match_array['approve_registration'], $active_mts)
655
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
656
+		) {
657
+			$def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations',
658
+				'event_espresso');
659
+		}
660
+		$def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso');
661
+		if (in_array($match_array['decline_registration'], $active_mts)
662
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
663
+		) {
664
+			$def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations',
665
+				'event_espresso');
666
+		}
667
+		$def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso');
668
+		if (in_array($match_array['pending_registration'], $active_mts)
669
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
670
+		) {
671
+			$def_reg_status_actions['pending_and_notify_registration'] = __('Set Registrations to Pending Payment and Notify',
672
+				'event_espresso');
673
+		}
674
+		$def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso');
675
+		if (in_array($match_array['no_approve_registration'], $active_mts)
676
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
677
+		) {
678
+			$def_reg_status_actions['no_approve_and_notify_registration'] = __('Set Registrations to Not Approved and Notify',
679
+				'event_espresso');
680
+		}
681
+		$def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso');
682
+		if (in_array($match_array['cancel_registration'], $active_mts)
683
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message', 'batch_send_messages')
684
+		) {
685
+			$def_reg_status_actions['cancel_and_notify_registration'] = __('Cancel Registrations and Notify',
686
+				'event_espresso');
687
+		}
688
+		$this->_views = array(
689
+			'all'   => array(
690
+				'slug'        => 'all',
691
+				'label'       => __('View All Registrations', 'event_espresso'),
692
+				'count'       => 0,
693
+				'bulk_action' => array_merge($def_reg_status_actions, array(
694
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
695
+				)),
696
+			),
697
+			'month' => array(
698
+				'slug'        => 'month',
699
+				'label'       => __('This Month', 'event_espresso'),
700
+				'count'       => 0,
701
+				'bulk_action' => array_merge($def_reg_status_actions, array(
702
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
703
+				)),
704
+			),
705
+			'today' => array(
706
+				'slug'        => 'today',
707
+				'label'       => sprintf(__('Today - %s', 'event_espresso'), date('M d, Y', current_time('timestamp'))),
708
+				'count'       => 0,
709
+				'bulk_action' => array_merge($def_reg_status_actions, array(
710
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
711
+				)),
712
+			),
713
+		);
714
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations',
715
+			'espresso_registrations_delete_registration')
716
+		) {
717
+			$this->_views['incomplete'] = array(
718
+				'slug'        => 'incomplete',
719
+				'label'       => __('Incomplete', 'event_espresso'),
720
+				'count'       => 0,
721
+				'bulk_action' => array(
722
+					'trash_registrations' => __('Trash Registrations', 'event_espresso'),
723
+				),
724
+			);
725
+			$this->_views['trash']      = array(
726
+				'slug'        => 'trash',
727
+				'label'       => __('Trash', 'event_espresso'),
728
+				'count'       => 0,
729
+				'bulk_action' => array(
730
+					'restore_registrations' => __('Restore Registrations', 'event_espresso'),
731
+					'delete_registrations'  => __('Delete Registrations Permanently', 'event_espresso'),
732
+				),
733
+			);
734
+		}
735
+	}
736
+
737
+
738
+	protected function _set_list_table_views_contact_list()
739
+	{
740
+		$this->_views = array(
741
+			'in_use' => array(
742
+				'slug'        => 'in_use',
743
+				'label'       => __('In Use', 'event_espresso'),
744
+				'count'       => 0,
745
+				'bulk_action' => array(
746
+					'trash_attendees' => __('Move to Trash', 'event_espresso'),
747
+				),
748
+			),
749
+		);
750
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts',
751
+			'espresso_registrations_trash_attendees')
752
+		) {
753
+			$this->_views['trash'] = array(
754
+				'slug'        => 'trash',
755
+				'label'       => __('Trash', 'event_espresso'),
756
+				'count'       => 0,
757
+				'bulk_action' => array(
758
+					'restore_attendees' => __('Restore from Trash', 'event_espresso'),
759
+				),
760
+			);
761
+		}
762
+	}
763
+
764
+
765
+	protected function _registration_legend_items()
766
+	{
767
+		$fc_items = array(
768
+			'star-icon'        => array(
769
+				'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8',
770
+				'desc'  => __('This is the Primary Registrant', 'event_espresso'),
771
+			),
772
+			'view_details'     => array(
773
+				'class' => 'dashicons dashicons-clipboard',
774
+				'desc'  => __('View Registration Details', 'event_espresso'),
775
+			),
776
+			'edit_attendee'    => array(
777
+				'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16',
778
+				'desc'  => __('Edit Contact Details', 'event_espresso'),
779
+			),
780
+			'view_transaction' => array(
781
+				'class' => 'dashicons dashicons-cart',
782
+				'desc'  => __('View Transaction Details', 'event_espresso'),
783
+			),
784
+			'view_invoice'     => array(
785
+				'class' => 'dashicons dashicons-media-spreadsheet',
786
+				'desc'  => __('View Transaction Invoice', 'event_espresso'),
787
+			),
788
+		);
789
+		if (EE_Registry::instance()->CAP->current_user_can('ee_send_message',
790
+			'espresso_registrations_resend_registration')
791
+		) {
792
+			$fc_items['resend_registration'] = array(
793
+				'class' => 'dashicons dashicons-email-alt',
794
+				'desc'  => __('Resend Registration Details', 'event_espresso'),
795
+			);
796
+		} else {
797
+			$fc_items['blank'] = array('class' => 'blank', 'desc' => '');
798
+		}
799
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) {
800
+			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for');
801
+			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) {
802
+				$fc_items['view_related_messages'] = array(
803
+					'class' => $related_for_icon['css_class'],
804
+					'desc'  => $related_for_icon['label'],
805
+				);
806
+			}
807
+		}
808
+		$sc_items = array(
809
+			'approved_status'   => array(
810
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
811
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
812
+			),
813
+			'pending_status'    => array(
814
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
815
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
816
+			),
817
+			'wait_list'         => array(
818
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
819
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
820
+			),
821
+			'incomplete_status' => array(
822
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
823
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'),
824
+			),
825
+			'not_approved'      => array(
826
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
827
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
828
+			),
829
+			'declined_status'   => array(
830
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
831
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
832
+			),
833
+			'cancelled_status'  => array(
834
+				'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
835
+				'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
836
+			),
837
+		);
838
+		return array_merge($fc_items, $sc_items);
839
+	}
840
+
841
+
842
+
843
+	/***************************************        REGISTRATION OVERVIEW        **************************************/
844
+	/**
845
+	 * @throws \EE_Error
846
+	 */
847
+	protected function _registrations_overview_list_table()
848
+	{
849
+		$this->_template_args['admin_page_header'] = '';
850
+		$EVT_ID                                    = ! empty($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : 0;
851
+		if ($EVT_ID) {
852
+			if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations',
853
+				'espresso_registrations_new_registration', $EVT_ID)
854
+			) {
855
+				$this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant',
856
+						array('event_id' => $EVT_ID), 'add-new-h2');
857
+			}
858
+			$event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
859
+			if ($event instanceof EE_Event) {
860
+				$this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s',
861
+					'event_espresso'), '<h3 style="line-height:1.5em;">',
862
+					'<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array(
863
+						'action' => 'edit',
864
+						'post'   => $event->ID(),
865
+					), EVENTS_ADMIN_URL) . '">&nbsp;' . $event->get('EVT_name') . '&nbsp;</a>&nbsp;', '</h3>');
866
+			}
867
+			$DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
868
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
869
+			if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') {
870
+				$this->_template_args['admin_page_header'] = substr($this->_template_args['admin_page_header'], 0, -5);
871
+				$this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
872
+				$this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
873
+				$this->_template_args['admin_page_header'] .= $datetime->name();
874
+				$this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
875
+				$this->_template_args['admin_page_header'] .= '</span></h3>';
876
+			}
877
+		}
878
+		$this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items());
879
+		$this->display_admin_list_table_page_with_no_sidebar();
880
+	}
881
+
882
+
883
+	/**
884
+	 * This sets the _registration property for the registration details screen
885
+	 *
886
+	 * @access private
887
+	 * @return bool
888
+	 */
889
+	private function _set_registration_object()
890
+	{
891
+		//get out if we've already set the object
892
+		if (is_object($this->_registration)) {
893
+			return true;
894
+		}
895
+		$REG    = EEM_Registration::instance();
896
+		$REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false;
897
+		if ($this->_registration = $REG->get_one_by_ID($REG_ID)) {
898
+			return true;
899
+		} else {
900
+			$error_msg = sprintf(__('An error occurred and the details for Registration ID #%s could not be retrieved.',
901
+				'event_espresso'), $REG_ID);
902
+			EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__);
903
+			$this->_registration = null;
904
+			return false;
905
+		}
906
+	}
907
+
908
+
909
+	/**
910
+	 * Used to retrieve registrations for the list table.
911
+	 *
912
+	 * @param int    $per_page
913
+	 * @param bool   $count
914
+	 * @param bool   $this_month
915
+	 * @param bool   $today
916
+	 * @return \EE_Registration[]|int
917
+	 */
918
+	public function get_registrations(
919
+		$per_page = 10,
920
+		$count = false,
921
+		$this_month = false,
922
+		$today = false
923
+	) {
924
+		if( $this_month ) {
925
+			$this->_req_data['status'] = 'month';
926
+		}
927
+		if( $today ) {
928
+			$this->_req_data['status'] = 'today';
929
+		}
930
+		$query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
931
+		return $count
932
+			? EEM_Registration::instance()->count($query_params)
933
+			/** @type EE_Registration[] */
934
+			: EEM_Registration::instance()->get_all($query_params);
935
+	}
936
+
937
+
938
+
939
+	/**
940
+	 * Retrieves the query parameters to be used by the Registration model for getting registrations.
941
+	 * Note: this listens to values on the request for some of the query parameters.
942
+	 *
943
+	 * @param array $request
944
+	 * @param int    $per_page
945
+	 * @param bool   $count
946
+	 * @return array
947
+	 */
948
+	protected function _get_registration_query_parameters(
949
+		$request = array(),
950
+		$per_page = 10,
951
+		$count = false
952
+	) {
953
+
954
+		$query_params = array(
955
+			0                          => $this->_get_where_conditions_for_registrations_query(
956
+				$request
957
+			),
958
+			'caps'                     => EEM_Registration::caps_read_admin,
959
+			'default_where_conditions' => 'this_model_only',
960
+		);
961
+		if ( ! $count) {
962
+			$query_params = array_merge(
963
+				$query_params,
964
+				$this->_get_orderby_for_registrations_query(),
965
+				$this->_get_limit($per_page)
966
+			);
967
+		}
968
+
969
+		return $query_params;
970
+	}
971
+
972
+
973
+	/**
974
+	 * This will add EVT_ID to the provided $where array for EE model query parameters.
975
+	 *
976
+	 * @param array $request usually the same as $this->_req_data but not necessarily
977
+	 * @return array
978
+	 */
979
+	protected function _add_event_id_to_where_conditions(array $request)
980
+	{
981
+		$where = array();
982
+		if ( ! empty($request['event_id'])) {
983
+			$where['EVT_ID'] = absint($request['event_id']);
984
+		}
985
+		return $where;
986
+	}
987
+
988
+
989
+	/**
990
+	 * Adds category ID if it exists in the request to the where conditions for the registrations query.
991
+	 *
992
+	 * @param array $request usually the same as $this->_req_data but not necessarily
993
+	 * @return array
994
+	 */
995
+	protected function _add_category_id_to_where_conditions(array $request)
996
+	{
997
+		$where = array();
998
+		if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
999
+			$where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1000
+		}
1001
+		return $where;
1002
+	}
1003
+
1004
+
1005
+	/**
1006
+	 * Adds the datetime ID if it exists in the request to the where conditions for the registrations query.
1007
+	 *
1008
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1009
+	 * @return array
1010
+	 */
1011
+	protected function _add_datetime_id_to_where_conditions(array $request)
1012
+	{
1013
+		$where = array();
1014
+		if ( ! empty($request['datetime_id'])) {
1015
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1016
+		}
1017
+		if( ! empty($request['DTT_ID'])){
1018
+			$where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1019
+		}
1020
+		return $where;
1021
+	}
1022
+
1023
+
1024
+	/**
1025
+	 * Adds the correct registration status to the where conditions for the registrations query.
1026
+	 *
1027
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1028
+	 * @return array
1029
+	 */
1030
+	protected function _add_registration_status_to_where_conditions(array $request)
1031
+	{
1032
+		$where = array();
1033
+		$view  = EEH_Array::is_set( $request, 'status', '' );
1034
+		$registration_status = ! empty($request['_reg_status'])
1035
+			? sanitize_text_field($request['_reg_status'])
1036
+			: '';
1037
+
1038
+		/*
1039 1039
          * If filtering by registration status, then we show registrations matching that status.
1040 1040
          * If not filtering by specified status, then we show all registrations excluding incomplete registrations UNLESS
1041 1041
          * viewing trashed registrations.
1042 1042
          */
1043
-        if ( ! empty($registration_status)) {
1044
-            $where['STS_ID'] = $registration_status;
1045
-        } else {
1046
-            //make sure we exclude incomplete registrations, but only if not trashed.
1047
-            if ($view === 'trash') {
1048
-                $where['REG_deleted'] = true;
1049
-            } else if ($view === 'incomplete') {
1050
-                $where['STS_ID'] = EEM_Registration::status_id_incomplete;
1051
-            } else {
1052
-                $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1053
-            }
1054
-        }
1055
-        return $where;
1056
-    }
1057
-
1058
-
1059
-    /**
1060
-     * Adds any provided date restraints to the where conditions for the registrations query.
1061
-     *
1062
-     * @param array $request usually the same as $this->_req_data but not necessarily
1063
-     * @return array
1064
-     */
1065
-    protected function _add_date_to_where_conditions(array $request)
1066
-    {
1067
-        $where = array();
1068
-        $view  = EEH_Array::is_set( $request, 'status', '' );
1069
-        $month_range             = ! empty($request['month_range'])
1070
-            ? sanitize_text_field($request['month_range'])
1071
-            : '';
1072
-        $retrieve_for_today      = $view === 'today';
1073
-        $retrieve_for_this_month = $view === 'month';
1074
-
1075
-        if ($retrieve_for_today) {
1076
-            $now               = date('Y-m-d', current_time('timestamp'));
1077
-            $where['REG_date'] = array(
1078
-                'BETWEEN',
1079
-                array(
1080
-                    EEM_Registration::instance()->convert_datetime_for_query(
1081
-                        'REG_date',
1082
-                        $now . ' 00:00:00',
1083
-                        'Y-m-d H:i:s'
1084
-                    ),
1085
-                    EEM_Registration::instance()->convert_datetime_for_query(
1086
-                        'REG_date',
1087
-                        $now . ' 23:59:59',
1088
-                        'Y-m-d H:i:s'
1089
-                    ),
1090
-                ),
1091
-            );
1092
-        } elseif ($retrieve_for_this_month) {
1093
-            $current_year_and_month = date('Y-m', current_time('timestamp'));
1094
-            $days_this_month        = date('t', current_time('timestamp'));
1095
-            $where['REG_date']      = array(
1096
-                'BETWEEN',
1097
-                array(
1098
-                    EEM_Registration::instance()->convert_datetime_for_query(
1099
-                        'REG_date',
1100
-                        $current_year_and_month . '-01 00:00:00',
1101
-                        'Y-m-d H:i:s'
1102
-                    ),
1103
-                    EEM_Registration::instance()->convert_datetime_for_query(
1104
-                        'REG_date',
1105
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1106
-                        'Y-m-d H:i:s'
1107
-                    ),
1108
-                ),
1109
-            );
1110
-        } elseif ($month_range) {
1111
-            $pieces          = explode(' ', $month_range, 3);
1112
-            $month_requested = ! empty($pieces[0])
1113
-                ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1114
-                : '';
1115
-            $year_requested  = ! empty($pieces[1])
1116
-                ? $pieces[1]
1117
-                : '';
1118
-            //if there is not a month or year then we can't go further
1119
-            if ($month_requested && $year_requested) {
1120
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1121
-                $where['REG_date'] = array(
1122
-                    'BETWEEN',
1123
-                    array(
1124
-                        EEM_Registration::instance()->convert_datetime_for_query(
1125
-                            'REG_date',
1126
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1127
-                            'Y-m-d H:i:s'
1128
-                        ),
1129
-                        EEM_Registration::instance()->convert_datetime_for_query(
1130
-                            'REG_date',
1131
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1132
-                            'Y-m-d H:i:s'
1133
-                        ),
1134
-                    ),
1135
-                );
1136
-            }
1137
-        }
1138
-        return $where;
1139
-    }
1140
-
1141
-
1142
-    /**
1143
-     * Adds any provided search restraints to the where conditions for the registrations query
1144
-     *
1145
-     * @param array $request usually the same as $this->_req_data but not necessarily
1146
-     * @return array
1147
-     */
1148
-    protected function _add_search_to_where_conditions(array $request)
1149
-    {
1150
-        $where = array();
1151
-        if ( ! empty($request['s'])) {
1152
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1153
-            $where['OR'] = array(
1154
-                'Event.EVT_name'                          => array('LIKE', $search_string),
1155
-                'Event.EVT_desc'                          => array('LIKE', $search_string),
1156
-                'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1157
-                'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1158
-                'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1159
-                'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1160
-                'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1161
-                'Attendee.ATT_email'                      => array('LIKE', $search_string),
1162
-                'Attendee.ATT_address'                    => array('LIKE', $search_string),
1163
-                'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1164
-                'Attendee.ATT_city'                       => array('LIKE', $search_string),
1165
-                'REG_final_price'                         => array('LIKE', $search_string),
1166
-                'REG_code'                                => array('LIKE', $search_string),
1167
-                'REG_count'                               => array('LIKE', $search_string),
1168
-                'REG_group_size'                          => array('LIKE', $search_string),
1169
-                'Ticket.TKT_name'                         => array('LIKE', $search_string),
1170
-                'Ticket.TKT_description'                  => array('LIKE', $search_string),
1171
-                'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1172
-            );
1173
-        }
1174
-        return $where;
1175
-    }
1176
-
1177
-
1178
-    /**
1179
-     * Sets up the where conditions for the registrations query.
1180
-     *
1181
-     * @param array $request
1182
-     * @return array
1183
-     */
1184
-    protected function _get_where_conditions_for_registrations_query($request)
1185
-    {
1186
-        return array_merge(
1187
-            $this->_add_event_id_to_where_conditions($request),
1188
-            $this->_add_category_id_to_where_conditions($request),
1189
-            $this->_add_datetime_id_to_where_conditions($request),
1190
-            $this->_add_registration_status_to_where_conditions($request),
1191
-            $this->_add_date_to_where_conditions($request),
1192
-            $this->_add_search_to_where_conditions($request)
1193
-        );
1194
-    }
1195
-
1196
-
1197
-    /**
1198
-     * Sets up the orderby for the registrations query.
1199
-     *
1200
-     * @return array
1201
-     */
1202
-    protected function _get_orderby_for_registrations_query()
1203
-    {
1204
-        $orderby_field = ! empty($this->_req_data['orderby'])
1205
-            ? sanitize_text_field($this->_req_data['orderby'])
1206
-            : '';
1207
-        switch ($orderby_field) {
1208
-            case '_REG_ID':
1209
-                $orderby_field = 'REG_ID';
1210
-                break;
1211
-            case '_Reg_status':
1212
-                $orderby_field = 'STS_ID';
1213
-                break;
1214
-            case 'ATT_fname':
1215
-                //just for spite, we're going to order it by their LAST name, NOT their first name. Now who's the boss?
1216
-                //jk, we don't want to break existing links, and customers preferred ordering by last name
1217
-                //besides, from the UI, its ambiguous as to whether we will order by first or last name
1218
-                $orderby_field = 'Attendee.ATT_lname';
1219
-                break;
1220
-            case 'event_name':
1221
-                $orderby_field = 'Event.EVT_name';
1222
-                break;
1223
-            case 'DTT_EVT_start':
1224
-                $orderby_field = 'Event.Datetime.DTT_EVT_start';
1225
-                break;
1226
-            default: //'REG_date'
1227
-                $orderby_field = 'REG_date';
1228
-        }
1229
-
1230
-        //order
1231
-        $order = ! empty($this->_req_data['order'])
1232
-            ? sanitize_text_field($this->_req_data['order'])
1233
-            : 'DESC';
1234
-        return array('order_by' => array($orderby_field => $order));
1235
-    }
1236
-
1237
-
1238
-    /**
1239
-     * Sets up the limit for the registrations query.
1240
-     *
1241
-     * @param $per_page
1242
-     * @return array
1243
-     */
1244
-    protected function _get_limit($per_page)
1245
-    {
1246
-        $current_page = ! empty($this->_req_data['paged'])
1247
-            ? absint($this->_req_data['paged'])
1248
-            : 1;
1249
-        $per_page     = ! empty($this->_req_data['perpage'])
1250
-            ? $this->_req_data['perpage']
1251
-            : $per_page;
1252
-
1253
-        //-1 means return all results so get out if that's set.
1254
-        if ((int)$per_page === -1) {
1255
-            return array();
1256
-        }
1257
-        $per_page = absint($per_page);
1258
-        $offset   = ($current_page - 1) * $per_page;
1259
-        return array('limit' => array($offset, $per_page));
1260
-    }
1261
-
1262
-
1263
-    public function get_registration_status_array()
1264
-    {
1265
-        return self::$_reg_status;
1266
-    }
1267
-
1268
-
1269
-
1270
-
1271
-    /***************************************        REGISTRATION DETAILS        ***************************************/
1272
-    /**
1273
-     *        generates HTML for the View Registration Details Admin page
1274
-     *
1275
-     * @access protected
1276
-     * @return void
1277
-     */
1278
-    protected function _registration_details()
1279
-    {
1280
-        $this->_template_args = array();
1281
-        $this->_set_registration_object();
1282
-        if (is_object($this->_registration)) {
1283
-            $transaction                                   = $this->_registration->transaction() ? $this->_registration->transaction()
1284
-                : EE_Transaction::new_instance();
1285
-            $this->_session                                = $transaction->session_data();
1286
-            $event_id                                      = $this->_registration->event_ID();
1287
-            $this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1288
-            $this->_template_args['reg_nmbr']['label']     = __('Registration Number', 'event_espresso');
1289
-            $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1290
-            $this->_template_args['reg_datetime']['label'] = __('Date', 'event_espresso');
1291
-            $this->_template_args['grand_total']           = $transaction->total();
1292
-            $this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1293
-            // link back to overview
1294
-            $this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1295
-            $this->_template_args['registration']                = $this->_registration;
1296
-            $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
1297
-                'action'   => 'default',
1298
-                'event_id' => $event_id,
1299
-            ), REG_ADMIN_URL);
1300
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
1301
-                'action' => 'default',
1302
-                'EVT_ID' => $event_id,
1303
-                'page'   => 'espresso_transactions',
1304
-            ), admin_url('admin.php'));
1305
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(array(
1306
-                'page'   => 'espresso_events',
1307
-                'action' => 'edit',
1308
-                'post'   => $event_id,
1309
-            ), admin_url('admin.php'));
1310
-            //next and previous links
1311
-            $next_reg                                      = $this->_registration->next(null, array(), 'REG_ID');
1312
-            $this->_template_args['next_registration']     = $next_reg
1313
-                ? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array(
1314
-                    'action'  => 'view_registration',
1315
-                    '_REG_ID' => $next_reg['REG_ID'],
1316
-                ), REG_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : '';
1317
-            $previous_reg                                  = $this->_registration->previous(null, array(), 'REG_ID');
1318
-            $this->_template_args['previous_registration'] = $previous_reg
1319
-                ? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array(
1320
-                    'action'  => 'view_registration',
1321
-                    '_REG_ID' => $previous_reg['REG_ID'],
1322
-                ), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
1323
-            // grab header
1324
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1325
-            $this->_template_args['REG_ID']            = $this->_registration->ID();
1326
-            $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
1327
-                $this->_template_args, true);
1328
-        } else {
1329
-            $this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1330
-        }
1331
-        // the details template wrapper
1332
-        $this->display_admin_page_with_sidebar();
1333
-    }
1334
-
1335
-
1336
-    protected function _registration_details_metaboxes()
1337
-    {
1338
-        do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1339
-        $this->_set_registration_object();
1340
-        $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1341
-        add_meta_box('edit-reg-status-mbox', __('Registration Status', 'event_espresso'),
1342
-            array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1343
-        add_meta_box('edit-reg-details-mbox', __('Registration Details', 'event_espresso'),
1344
-            array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1345
-        if ($attendee instanceof EE_Attendee
1346
-            && EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox')
1347
-        ) {
1348
-            add_meta_box('edit-reg-questions-mbox', __('Registration Form Answers', 'event_espresso'),
1349
-                array($this, '_reg_questions_meta_box'), $this->wp_page_slug, 'normal', 'high');
1350
-        }
1351
-        add_meta_box('edit-reg-registrant-mbox', __('Contact Details', 'event_espresso'),
1352
-            array($this, '_reg_registrant_side_meta_box'), $this->wp_page_slug, 'side', 'high');
1353
-        if ($this->_registration->group_size() > 1) {
1354
-            add_meta_box('edit-reg-attendees-mbox', __('Other Registrations in this Transaction', 'event_espresso'),
1355
-                array($this, '_reg_attendees_meta_box'), $this->wp_page_slug, 'normal', 'high');
1356
-        }
1357
-    }
1358
-
1359
-
1360
-    /**
1361
-     * set_reg_status_buttons_metabox
1362
-     *
1363
-     * @access protected
1364
-     * @return string
1365
-     * @throws \EE_Error
1366
-     */
1367
-    public function set_reg_status_buttons_metabox()
1368
-    {
1369
-        $this->_set_registration_object();
1370
-        $change_reg_status_form = $this->_generate_reg_status_change_form();
1371
-        echo $change_reg_status_form->form_open(self::add_query_args_and_nonce(array(
1372
-            'action' => 'change_reg_status',
1373
-        ), REG_ADMIN_URL));
1374
-        echo $change_reg_status_form->get_html();
1375
-        echo $change_reg_status_form->form_close();
1376
-    }
1377
-
1378
-
1379
-    /**
1380
-     * @return EE_Form_Section_Proper
1381
-     */
1382
-    protected function _generate_reg_status_change_form()
1383
-    {
1384
-        return new EE_Form_Section_Proper(array(
1385
-            'name'            => 'reg_status_change_form',
1386
-            'html_id'         => 'reg-status-change-form',
1387
-            'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1388
-            'subsections'     => array(
1389
-                'return'             => new EE_Hidden_Input(array(
1390
-                    'name'    => 'return',
1391
-                    'default' => 'view_registration',
1392
-                )),
1393
-                'REG_ID'             => new EE_Hidden_Input(array(
1394
-                    'name'    => 'REG_ID',
1395
-                    'default' => $this->_registration->ID(),
1396
-                )),
1397
-                'current_status'     => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status',
1398
-                        'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(),
1399
-                        '', 'status-' . $this->_registration->status_ID(),
1400
-                        'line-height: 1em; font-size: 1.5em; font-weight: bold;')))),
1401
-                'reg_status'         => new EE_Select_Input($this->_get_reg_statuses(), array(
1402
-                    'html_label_text' => __('Change Registration Status to', 'event_espresso'),
1403
-                    'default'         => $this->_registration->status_ID(),
1404
-                )),
1405
-                'send_notifications' => new EE_Yes_No_Input(array(
1406
-                    'html_label_text' => __('Send Related Messages', 'event_espresso'),
1407
-                    'default'         => false,
1408
-                    'html_help_text'  => __('If set to "Yes", then the related messages will be sent to the registrant.',
1409
-                        'event_espresso'),
1410
-                )),
1411
-                'submit'             => new EE_Submit_Input(array(
1412
-                    'html_class'      => 'button-primary',
1413
-                    'html_label_text' => '&nbsp;',
1414
-                    'default'         => __('Update Registration Status', 'event_espresso'),
1415
-                )),
1416
-            ),
1417
-        ));
1418
-    }
1419
-
1420
-
1421
-
1422
-    /**
1423
-     * Returns an array of all the buttons for the various statuses and switch status actions
1424
-     *
1425
-     * @return array
1426
-     */
1427
-    protected function _get_reg_statuses()
1428
-    {
1429
-        $reg_status_array = EEM_Registration::instance()->reg_status_array();
1430
-        unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1431
-        // get current reg status
1432
-        $current_status = $this->_registration->status_ID();
1433
-        // is registration for free event? This will determine whether to display the pending payment option
1434
-        if ($current_status != EEM_Registration::status_id_pending_payment
1435
-            && $this->_registration->transaction()
1436
-                                   ->is_free()
1437
-        ) {
1438
-            unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1439
-        }
1440
-        return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1441
-    }
1442
-
1443
-
1444
-    /**
1445
-     * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1446
-     *
1447
-     * @param bool $status REG status given for changing registrations to.
1448
-     * @param bool $notify Whether to send messages notifications or not.
1449
-     * @return array  (array with reg_id(s) updated and whether update was successful.
1450
-     */
1451
-    protected function _set_registration_status_from_request($status = false, $notify = false)
1452
-    {
1453
-        if (isset($this->_req_data['reg_status_change_form'])) {
1454
-            $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1455
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1456
-        } else {
1457
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1458
-        }
1459
-        $success = $this->_set_registration_status($REG_IDs, $status);
1460
-        //notify?
1461
-        if ($success
1462
-            && $notify
1463
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1464
-                'espresso_registrations_resend_registration')
1465
-        ) {
1466
-            $this->_process_resend_registration();
1467
-        }
1468
-        return $success;
1469
-    }
1470
-
1471
-
1472
-    /**
1473
-     * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1474
-     * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1475
-     *
1476
-     * @param array $REG_IDs
1477
-     * @param bool  $status
1478
-     * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1479
-     *               the array of updated registrations).
1480
-     */
1481
-    protected function _set_registration_status($REG_IDs = array(), $status = false)
1482
-    {
1483
-        $success = false;
1484
-        // typecast $REG_IDs
1485
-        $REG_IDs = (array)$REG_IDs;
1486
-        if ( ! empty($REG_IDs)) {
1487
-            $success = true;
1488
-            // set default status if none is passed
1489
-            $status = $status ? $status : EEM_Registration::status_id_pending_payment;
1490
-            // sanitize $REG_IDs
1491
-            $REG_IDs = array_filter($REG_IDs, 'absint');
1492
-            //loop through REG_ID's and change status
1493
-            foreach ($REG_IDs as $REG_ID) {
1494
-                $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1495
-                if ($registration instanceof EE_Registration) {
1496
-                    $registration->set_status($status);
1497
-                    $result = $registration->save();
1498
-                    // verifying explicit fails because update *may* just return 0 for 0 rows affected
1499
-                    $success = $result !== false ? $success : false;
1500
-                }
1501
-            }
1502
-        }
1503
-        //reset _req_data['_REG_ID'] for any potential future messages notifications
1504
-        $this->_req_data['_REG_ID'] = $REG_IDs;
1505
-        //return $success and processed registrations
1506
-        return array('REG_ID' => $REG_IDs, 'success' => $success);
1507
-    }
1508
-
1509
-
1510
-    /**
1511
-     * Common logic for setting up success message and redirecting to appropriate route
1512
-     *
1513
-     * @param  string $STS_ID status id for the registration changed to
1514
-     * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1515
-     * @return void
1516
-     */
1517
-    protected function _reg_status_change_return($STS_ID, $notify = false)
1518
-    {
1519
-        $result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1520
-            : array('success' => false);
1521
-        $success = isset($result['success']) && $result['success'];
1522
-        //setup success message
1523
-        if ($success) {
1524
-            if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1525
-                $msg = sprintf(__('Registration status has been set to %s', 'event_espresso'),
1526
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1527
-            } else {
1528
-                $msg = sprintf(__('Registrations have been set to %s.', 'event_espresso'),
1529
-                    EEH_Template::pretty_status($STS_ID, false, 'lower'));
1530
-            }
1531
-            EE_Error::add_success($msg);
1532
-        } else {
1533
-            EE_Error::add_error(__('Something went wrong, and the status was not changed', 'event_espresso'), __FILE__,
1534
-                __LINE__, __FUNCTION__);
1535
-        }
1536
-        if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1537
-            $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1538
-        } else {
1539
-            $route = array('action' => 'default');
1540
-        }
1541
-        //unset nonces
1542
-        foreach ($this->_req_data as $ref => $value) {
1543
-            if (strpos($ref, 'nonce') !== false) {
1544
-                unset($this->_req_data[$ref]);
1545
-                continue;
1546
-            }
1547
-            $value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1548
-            $this->_req_data[$ref] = $value;
1549
-        }
1550
-        //merge request vars so that the reloaded list table contains any existing filter query params
1551
-        $route = array_merge($this->_req_data, $route);
1552
-        $this->_redirect_after_action($success, '', '', $route, true);
1553
-    }
1554
-
1555
-
1556
-    /**
1557
-     * incoming reg status change from reg details page.
1558
-     *
1559
-     * @return void
1560
-     */
1561
-    protected function _change_reg_status()
1562
-    {
1563
-        $this->_req_data['return'] = 'view_registration';
1564
-        //set notify based on whether the send notifications toggle is set or not
1565
-        $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1566
-        //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1567
-        $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1568
-            ? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1569
-        switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1570
-            case EEM_Registration::status_id_approved :
1571
-            case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1572
-                $this->approve_registration($notify);
1573
-                break;
1574
-            case EEM_Registration::status_id_pending_payment :
1575
-            case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1576
-                $this->pending_registration($notify);
1577
-                break;
1578
-            case EEM_Registration::status_id_not_approved :
1579
-            case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1580
-                $this->not_approve_registration($notify);
1581
-                break;
1582
-            case EEM_Registration::status_id_declined :
1583
-            case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1584
-                $this->decline_registration($notify);
1585
-                break;
1586
-            case EEM_Registration::status_id_cancelled :
1587
-            case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1588
-                $this->cancel_registration($notify);
1589
-                break;
1590
-            case EEM_Registration::status_id_wait_list :
1591
-            case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1592
-                $this->waitlist_registration($notify);
1593
-                break;
1594
-            case EEM_Registration::status_id_incomplete :
1595
-            default :
1596
-                $result['success'] = false;
1597
-                unset($this->_req_data['return']);
1598
-                $this->_reg_status_change_return('', false);
1599
-                break;
1600
-        }
1601
-    }
1602
-
1603
-
1604
-    /**
1605
-     * approve_registration
1606
-     *
1607
-     * @access protected
1608
-     * @param bool $notify whether or not to notify the registrant about their approval.
1609
-     * @return void
1610
-     */
1611
-    protected function approve_registration($notify = false)
1612
-    {
1613
-        $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1614
-    }
1615
-
1616
-
1617
-    /**
1618
-     *        decline_registration
1619
-     *
1620
-     * @access protected
1621
-     * @param bool $notify whether or not to notify the registrant about their status change.
1622
-     * @return void
1623
-     */
1624
-    protected function decline_registration($notify = false)
1625
-    {
1626
-        $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1627
-    }
1628
-
1629
-
1630
-    /**
1631
-     *        cancel_registration
1632
-     *
1633
-     * @access protected
1634
-     * @param bool $notify whether or not to notify the registrant about their status change.
1635
-     * @return void
1636
-     */
1637
-    protected function cancel_registration($notify = false)
1638
-    {
1639
-        $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1640
-    }
1641
-
1642
-
1643
-    /**
1644
-     *        not_approve_registration
1645
-     *
1646
-     * @access protected
1647
-     * @param bool $notify whether or not to notify the registrant about their status change.
1648
-     * @return void
1649
-     */
1650
-    protected function not_approve_registration($notify = false)
1651
-    {
1652
-        $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1653
-    }
1654
-
1655
-
1656
-    /**
1657
-     *        decline_registration
1658
-     *
1659
-     * @access protected
1660
-     * @param bool $notify whether or not to notify the registrant about their status change.
1661
-     * @return void
1662
-     */
1663
-    protected function pending_registration($notify = false)
1664
-    {
1665
-        $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1666
-    }
1667
-
1668
-
1669
-    /**
1670
-     * waitlist_registration
1671
-     *
1672
-     * @access protected
1673
-     * @param bool $notify whether or not to notify the registrant about their status change.
1674
-     * @return void
1675
-     */
1676
-    protected function waitlist_registration($notify = false)
1677
-    {
1678
-        $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1679
-    }
1680
-
1681
-
1682
-    /**
1683
-     *        generates HTML for the Registration main meta box
1684
-     *
1685
-     * @access public
1686
-     * @return void
1687
-     */
1688
-    public function _reg_details_meta_box()
1689
-    {
1690
-        EEH_Autoloader::register_line_item_display_autoloaders();
1691
-        EEH_Autoloader::register_line_item_filter_autoloaders();
1692
-        EE_Registry::instance()->load_helper('Line_Item');
1693
-        $transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1694
-            : EE_Transaction::new_instance();
1695
-        $this->_session = $transaction->session_data();
1696
-        $filters        = new EE_Line_Item_Filter_Collection();
1697
-        //$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1698
-        $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1699
-        $line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1700
-            $transaction->total_line_item());
1701
-        $filtered_line_item_tree                 = $line_item_filter_processor->process();
1702
-        $line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1703
-            'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1704
-        $this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree,
1705
-            array('EE_Registration' => $this->_registration));
1706
-        $attendee                                = $this->_registration->attendee();
1707
-        if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
1708
-            'espresso_transactions_view_transaction')
1709
-        ) {
1710
-            $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1711
-                'action' => 'view_transaction',
1712
-                'TXN_ID' => $transaction->ID(),
1713
-            ), TXN_ADMIN_URL), esc_html__(' View Transaction'), 'button secondary-button right',
1714
-                'dashicons dashicons-cart');
1715
-        } else {
1716
-            $this->_template_args['view_transaction_button'] = '';
1717
-        }
1718
-        if ($attendee instanceof EE_Attendee
1719
-            && EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1720
-                'espresso_registrations_resend_registration')
1721
-        ) {
1722
-            $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1723
-                'action'      => 'resend_registration',
1724
-                '_REG_ID'     => $this->_registration->ID(),
1725
-                'redirect_to' => 'view_registration',
1726
-            ), REG_ADMIN_URL), esc_html__(' Resend Registration'), 'button secondary-button right',
1727
-                'dashicons dashicons-email-alt');
1728
-        } else {
1729
-            $this->_template_args['resend_registration_button'] = '';
1730
-        }
1731
-        $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1732
-        $payment                               = $transaction->get_first_related('Payment');
1733
-        $payment                               = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
1734
-        $payment_method                        = $payment->get_first_related('Payment_Method');
1735
-        $payment_method                        = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance()
1736
-            : $payment_method;
1737
-        $reg_details                           = array(
1738
-            'payment_method'       => $payment_method->name(),
1739
-            'response_msg'         => $payment->gateway_response(),
1740
-            'registration_id'      => $this->_registration->get('REG_code'),
1741
-            'registration_session' => $this->_registration->session_ID(),
1742
-            'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1743
-            'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1744
-        );
1745
-        if (isset($reg_details['registration_id'])) {
1746
-            $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1747
-            $this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
1748
-            $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
1749
-        }
1750
-        if (isset($reg_details['payment_method'])) {
1751
-            $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
1752
-            $this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method',
1753
-                'event_espresso');
1754
-            $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
1755
-            $this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
1756
-            $this->_template_args['reg_details']['response_msg']['label']   = __('Payment method response',
1757
-                'event_espresso');
1758
-            $this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
1759
-        }
1760
-        $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
1761
-        $this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session',
1762
-            'event_espresso');
1763
-        $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
1764
-        $this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
1765
-        $this->_template_args['reg_details']['ip_address']['label']           = __('Registration placed from IP',
1766
-            'event_espresso');
1767
-        $this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
1768
-        $this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
1769
-        $this->_template_args['reg_details']['user_agent']['label']           = __('Registrant User Agent',
1770
-            'event_espresso');
1771
-        $this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
1772
-        $this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(array(
1773
-            'action'   => 'default',
1774
-            'event_id' => $this->_registration->event_ID(),
1775
-        ), REG_ADMIN_URL);
1776
-        $this->_template_args['REG_ID']                                       = $this->_registration->ID();
1777
-        $this->_template_args['event_id']                                     = $this->_registration->event_ID();
1778
-        $template_path                                                        = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
1779
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
1780
-    }
1781
-
1782
-
1783
-    /**
1784
-     * generates HTML for the Registration Questions meta box.
1785
-     * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
1786
-     * otherwise uses new forms system
1787
-     *
1788
-     * @access public
1789
-     * @return void
1790
-     */
1791
-    public function _reg_questions_meta_box()
1792
-    {
1793
-        //allow someone to override this method entirely
1794
-        if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
1795
-            $this->_registration)) {
1796
-            $form                                              = $this->_get_reg_custom_questions_form($this->_registration->ID());
1797
-            $this->_template_args['att_questions']             = count($form->subforms()) > 0 ? $form->get_html_and_js() : '';
1798
-            $this->_template_args['reg_questions_form_action'] = 'edit_registration';
1799
-            $this->_template_args['REG_ID']                    = $this->_registration->ID();
1800
-            $template_path                                     = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
1801
-            echo EEH_Template::display_template($template_path, $this->_template_args, true);
1802
-        }
1803
-    }
1804
-
1805
-
1806
-    /**
1807
-     * form_before_question_group
1808
-     *
1809
-     * @deprecated    as of 4.8.32.rc.000
1810
-     * @access        public
1811
-     * @param        string $output
1812
-     * @return        string
1813
-     */
1814
-    public function form_before_question_group($output)
1815
-    {
1816
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1817
-            __('This method would have been protected but was used on a filter callback'
1818
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1819
-            '4.8.32.rc.000');
1820
-        return '
1043
+		if ( ! empty($registration_status)) {
1044
+			$where['STS_ID'] = $registration_status;
1045
+		} else {
1046
+			//make sure we exclude incomplete registrations, but only if not trashed.
1047
+			if ($view === 'trash') {
1048
+				$where['REG_deleted'] = true;
1049
+			} else if ($view === 'incomplete') {
1050
+				$where['STS_ID'] = EEM_Registration::status_id_incomplete;
1051
+			} else {
1052
+				$where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete);
1053
+			}
1054
+		}
1055
+		return $where;
1056
+	}
1057
+
1058
+
1059
+	/**
1060
+	 * Adds any provided date restraints to the where conditions for the registrations query.
1061
+	 *
1062
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1063
+	 * @return array
1064
+	 */
1065
+	protected function _add_date_to_where_conditions(array $request)
1066
+	{
1067
+		$where = array();
1068
+		$view  = EEH_Array::is_set( $request, 'status', '' );
1069
+		$month_range             = ! empty($request['month_range'])
1070
+			? sanitize_text_field($request['month_range'])
1071
+			: '';
1072
+		$retrieve_for_today      = $view === 'today';
1073
+		$retrieve_for_this_month = $view === 'month';
1074
+
1075
+		if ($retrieve_for_today) {
1076
+			$now               = date('Y-m-d', current_time('timestamp'));
1077
+			$where['REG_date'] = array(
1078
+				'BETWEEN',
1079
+				array(
1080
+					EEM_Registration::instance()->convert_datetime_for_query(
1081
+						'REG_date',
1082
+						$now . ' 00:00:00',
1083
+						'Y-m-d H:i:s'
1084
+					),
1085
+					EEM_Registration::instance()->convert_datetime_for_query(
1086
+						'REG_date',
1087
+						$now . ' 23:59:59',
1088
+						'Y-m-d H:i:s'
1089
+					),
1090
+				),
1091
+			);
1092
+		} elseif ($retrieve_for_this_month) {
1093
+			$current_year_and_month = date('Y-m', current_time('timestamp'));
1094
+			$days_this_month        = date('t', current_time('timestamp'));
1095
+			$where['REG_date']      = array(
1096
+				'BETWEEN',
1097
+				array(
1098
+					EEM_Registration::instance()->convert_datetime_for_query(
1099
+						'REG_date',
1100
+						$current_year_and_month . '-01 00:00:00',
1101
+						'Y-m-d H:i:s'
1102
+					),
1103
+					EEM_Registration::instance()->convert_datetime_for_query(
1104
+						'REG_date',
1105
+						$current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1106
+						'Y-m-d H:i:s'
1107
+					),
1108
+				),
1109
+			);
1110
+		} elseif ($month_range) {
1111
+			$pieces          = explode(' ', $month_range, 3);
1112
+			$month_requested = ! empty($pieces[0])
1113
+				? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0]))
1114
+				: '';
1115
+			$year_requested  = ! empty($pieces[1])
1116
+				? $pieces[1]
1117
+				: '';
1118
+			//if there is not a month or year then we can't go further
1119
+			if ($month_requested && $year_requested) {
1120
+				$days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1121
+				$where['REG_date'] = array(
1122
+					'BETWEEN',
1123
+					array(
1124
+						EEM_Registration::instance()->convert_datetime_for_query(
1125
+							'REG_date',
1126
+							$year_requested . '-' . $month_requested . '-01 00:00:00',
1127
+							'Y-m-d H:i:s'
1128
+						),
1129
+						EEM_Registration::instance()->convert_datetime_for_query(
1130
+							'REG_date',
1131
+							$year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1132
+							'Y-m-d H:i:s'
1133
+						),
1134
+					),
1135
+				);
1136
+			}
1137
+		}
1138
+		return $where;
1139
+	}
1140
+
1141
+
1142
+	/**
1143
+	 * Adds any provided search restraints to the where conditions for the registrations query
1144
+	 *
1145
+	 * @param array $request usually the same as $this->_req_data but not necessarily
1146
+	 * @return array
1147
+	 */
1148
+	protected function _add_search_to_where_conditions(array $request)
1149
+	{
1150
+		$where = array();
1151
+		if ( ! empty($request['s'])) {
1152
+			$search_string = '%' . sanitize_text_field($request['s']) . '%';
1153
+			$where['OR'] = array(
1154
+				'Event.EVT_name'                          => array('LIKE', $search_string),
1155
+				'Event.EVT_desc'                          => array('LIKE', $search_string),
1156
+				'Event.EVT_short_desc'                    => array('LIKE', $search_string),
1157
+				'Attendee.ATT_full_name'                  => array('LIKE', $search_string),
1158
+				'Attendee.ATT_fname'                      => array('LIKE', $search_string),
1159
+				'Attendee.ATT_lname'                      => array('LIKE', $search_string),
1160
+				'Attendee.ATT_short_bio'                  => array('LIKE', $search_string),
1161
+				'Attendee.ATT_email'                      => array('LIKE', $search_string),
1162
+				'Attendee.ATT_address'                    => array('LIKE', $search_string),
1163
+				'Attendee.ATT_address2'                   => array('LIKE', $search_string),
1164
+				'Attendee.ATT_city'                       => array('LIKE', $search_string),
1165
+				'REG_final_price'                         => array('LIKE', $search_string),
1166
+				'REG_code'                                => array('LIKE', $search_string),
1167
+				'REG_count'                               => array('LIKE', $search_string),
1168
+				'REG_group_size'                          => array('LIKE', $search_string),
1169
+				'Ticket.TKT_name'                         => array('LIKE', $search_string),
1170
+				'Ticket.TKT_description'                  => array('LIKE', $search_string),
1171
+				'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string),
1172
+			);
1173
+		}
1174
+		return $where;
1175
+	}
1176
+
1177
+
1178
+	/**
1179
+	 * Sets up the where conditions for the registrations query.
1180
+	 *
1181
+	 * @param array $request
1182
+	 * @return array
1183
+	 */
1184
+	protected function _get_where_conditions_for_registrations_query($request)
1185
+	{
1186
+		return array_merge(
1187
+			$this->_add_event_id_to_where_conditions($request),
1188
+			$this->_add_category_id_to_where_conditions($request),
1189
+			$this->_add_datetime_id_to_where_conditions($request),
1190
+			$this->_add_registration_status_to_where_conditions($request),
1191
+			$this->_add_date_to_where_conditions($request),
1192
+			$this->_add_search_to_where_conditions($request)
1193
+		);
1194
+	}
1195
+
1196
+
1197
+	/**
1198
+	 * Sets up the orderby for the registrations query.
1199
+	 *
1200
+	 * @return array
1201
+	 */
1202
+	protected function _get_orderby_for_registrations_query()
1203
+	{
1204
+		$orderby_field = ! empty($this->_req_data['orderby'])
1205
+			? sanitize_text_field($this->_req_data['orderby'])
1206
+			: '';
1207
+		switch ($orderby_field) {
1208
+			case '_REG_ID':
1209
+				$orderby_field = 'REG_ID';
1210
+				break;
1211
+			case '_Reg_status':
1212
+				$orderby_field = 'STS_ID';
1213
+				break;
1214
+			case 'ATT_fname':
1215
+				//just for spite, we're going to order it by their LAST name, NOT their first name. Now who's the boss?
1216
+				//jk, we don't want to break existing links, and customers preferred ordering by last name
1217
+				//besides, from the UI, its ambiguous as to whether we will order by first or last name
1218
+				$orderby_field = 'Attendee.ATT_lname';
1219
+				break;
1220
+			case 'event_name':
1221
+				$orderby_field = 'Event.EVT_name';
1222
+				break;
1223
+			case 'DTT_EVT_start':
1224
+				$orderby_field = 'Event.Datetime.DTT_EVT_start';
1225
+				break;
1226
+			default: //'REG_date'
1227
+				$orderby_field = 'REG_date';
1228
+		}
1229
+
1230
+		//order
1231
+		$order = ! empty($this->_req_data['order'])
1232
+			? sanitize_text_field($this->_req_data['order'])
1233
+			: 'DESC';
1234
+		return array('order_by' => array($orderby_field => $order));
1235
+	}
1236
+
1237
+
1238
+	/**
1239
+	 * Sets up the limit for the registrations query.
1240
+	 *
1241
+	 * @param $per_page
1242
+	 * @return array
1243
+	 */
1244
+	protected function _get_limit($per_page)
1245
+	{
1246
+		$current_page = ! empty($this->_req_data['paged'])
1247
+			? absint($this->_req_data['paged'])
1248
+			: 1;
1249
+		$per_page     = ! empty($this->_req_data['perpage'])
1250
+			? $this->_req_data['perpage']
1251
+			: $per_page;
1252
+
1253
+		//-1 means return all results so get out if that's set.
1254
+		if ((int)$per_page === -1) {
1255
+			return array();
1256
+		}
1257
+		$per_page = absint($per_page);
1258
+		$offset   = ($current_page - 1) * $per_page;
1259
+		return array('limit' => array($offset, $per_page));
1260
+	}
1261
+
1262
+
1263
+	public function get_registration_status_array()
1264
+	{
1265
+		return self::$_reg_status;
1266
+	}
1267
+
1268
+
1269
+
1270
+
1271
+	/***************************************        REGISTRATION DETAILS        ***************************************/
1272
+	/**
1273
+	 *        generates HTML for the View Registration Details Admin page
1274
+	 *
1275
+	 * @access protected
1276
+	 * @return void
1277
+	 */
1278
+	protected function _registration_details()
1279
+	{
1280
+		$this->_template_args = array();
1281
+		$this->_set_registration_object();
1282
+		if (is_object($this->_registration)) {
1283
+			$transaction                                   = $this->_registration->transaction() ? $this->_registration->transaction()
1284
+				: EE_Transaction::new_instance();
1285
+			$this->_session                                = $transaction->session_data();
1286
+			$event_id                                      = $this->_registration->event_ID();
1287
+			$this->_template_args['reg_nmbr']['value']     = $this->_registration->ID();
1288
+			$this->_template_args['reg_nmbr']['label']     = __('Registration Number', 'event_espresso');
1289
+			$this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date');
1290
+			$this->_template_args['reg_datetime']['label'] = __('Date', 'event_espresso');
1291
+			$this->_template_args['grand_total']           = $transaction->total();
1292
+			$this->_template_args['currency_sign']         = EE_Registry::instance()->CFG->currency->sign;
1293
+			// link back to overview
1294
+			$this->_template_args['reg_overview_url']            = REG_ADMIN_URL;
1295
+			$this->_template_args['registration']                = $this->_registration;
1296
+			$this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
1297
+				'action'   => 'default',
1298
+				'event_id' => $event_id,
1299
+			), REG_ADMIN_URL);
1300
+			$this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
1301
+				'action' => 'default',
1302
+				'EVT_ID' => $event_id,
1303
+				'page'   => 'espresso_transactions',
1304
+			), admin_url('admin.php'));
1305
+			$this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(array(
1306
+				'page'   => 'espresso_events',
1307
+				'action' => 'edit',
1308
+				'post'   => $event_id,
1309
+			), admin_url('admin.php'));
1310
+			//next and previous links
1311
+			$next_reg                                      = $this->_registration->next(null, array(), 'REG_ID');
1312
+			$this->_template_args['next_registration']     = $next_reg
1313
+				? $this->_next_link(EE_Admin_Page::add_query_args_and_nonce(array(
1314
+					'action'  => 'view_registration',
1315
+					'_REG_ID' => $next_reg['REG_ID'],
1316
+				), REG_ADMIN_URL), 'dashicons dashicons-arrow-right ee-icon-size-22') : '';
1317
+			$previous_reg                                  = $this->_registration->previous(null, array(), 'REG_ID');
1318
+			$this->_template_args['previous_registration'] = $previous_reg
1319
+				? $this->_previous_link(EE_Admin_Page::add_query_args_and_nonce(array(
1320
+					'action'  => 'view_registration',
1321
+					'_REG_ID' => $previous_reg['REG_ID'],
1322
+				), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
1323
+			// grab header
1324
+			$template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1325
+			$this->_template_args['REG_ID']            = $this->_registration->ID();
1326
+			$this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
1327
+				$this->_template_args, true);
1328
+		} else {
1329
+			$this->_template_args['admin_page_header'] = $this->display_espresso_notices();
1330
+		}
1331
+		// the details template wrapper
1332
+		$this->display_admin_page_with_sidebar();
1333
+	}
1334
+
1335
+
1336
+	protected function _registration_details_metaboxes()
1337
+	{
1338
+		do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this);
1339
+		$this->_set_registration_object();
1340
+		$attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null;
1341
+		add_meta_box('edit-reg-status-mbox', __('Registration Status', 'event_espresso'),
1342
+			array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high');
1343
+		add_meta_box('edit-reg-details-mbox', __('Registration Details', 'event_espresso'),
1344
+			array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high');
1345
+		if ($attendee instanceof EE_Attendee
1346
+			&& EE_Registry::instance()->CAP->current_user_can('ee_edit_registration', 'edit-reg-questions-mbox')
1347
+		) {
1348
+			add_meta_box('edit-reg-questions-mbox', __('Registration Form Answers', 'event_espresso'),
1349
+				array($this, '_reg_questions_meta_box'), $this->wp_page_slug, 'normal', 'high');
1350
+		}
1351
+		add_meta_box('edit-reg-registrant-mbox', __('Contact Details', 'event_espresso'),
1352
+			array($this, '_reg_registrant_side_meta_box'), $this->wp_page_slug, 'side', 'high');
1353
+		if ($this->_registration->group_size() > 1) {
1354
+			add_meta_box('edit-reg-attendees-mbox', __('Other Registrations in this Transaction', 'event_espresso'),
1355
+				array($this, '_reg_attendees_meta_box'), $this->wp_page_slug, 'normal', 'high');
1356
+		}
1357
+	}
1358
+
1359
+
1360
+	/**
1361
+	 * set_reg_status_buttons_metabox
1362
+	 *
1363
+	 * @access protected
1364
+	 * @return string
1365
+	 * @throws \EE_Error
1366
+	 */
1367
+	public function set_reg_status_buttons_metabox()
1368
+	{
1369
+		$this->_set_registration_object();
1370
+		$change_reg_status_form = $this->_generate_reg_status_change_form();
1371
+		echo $change_reg_status_form->form_open(self::add_query_args_and_nonce(array(
1372
+			'action' => 'change_reg_status',
1373
+		), REG_ADMIN_URL));
1374
+		echo $change_reg_status_form->get_html();
1375
+		echo $change_reg_status_form->form_close();
1376
+	}
1377
+
1378
+
1379
+	/**
1380
+	 * @return EE_Form_Section_Proper
1381
+	 */
1382
+	protected function _generate_reg_status_change_form()
1383
+	{
1384
+		return new EE_Form_Section_Proper(array(
1385
+			'name'            => 'reg_status_change_form',
1386
+			'html_id'         => 'reg-status-change-form',
1387
+			'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1388
+			'subsections'     => array(
1389
+				'return'             => new EE_Hidden_Input(array(
1390
+					'name'    => 'return',
1391
+					'default' => 'view_registration',
1392
+				)),
1393
+				'REG_ID'             => new EE_Hidden_Input(array(
1394
+					'name'    => 'REG_ID',
1395
+					'default' => $this->_registration->ID(),
1396
+				)),
1397
+				'current_status'     => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status',
1398
+						'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(),
1399
+						'', 'status-' . $this->_registration->status_ID(),
1400
+						'line-height: 1em; font-size: 1.5em; font-weight: bold;')))),
1401
+				'reg_status'         => new EE_Select_Input($this->_get_reg_statuses(), array(
1402
+					'html_label_text' => __('Change Registration Status to', 'event_espresso'),
1403
+					'default'         => $this->_registration->status_ID(),
1404
+				)),
1405
+				'send_notifications' => new EE_Yes_No_Input(array(
1406
+					'html_label_text' => __('Send Related Messages', 'event_espresso'),
1407
+					'default'         => false,
1408
+					'html_help_text'  => __('If set to "Yes", then the related messages will be sent to the registrant.',
1409
+						'event_espresso'),
1410
+				)),
1411
+				'submit'             => new EE_Submit_Input(array(
1412
+					'html_class'      => 'button-primary',
1413
+					'html_label_text' => '&nbsp;',
1414
+					'default'         => __('Update Registration Status', 'event_espresso'),
1415
+				)),
1416
+			),
1417
+		));
1418
+	}
1419
+
1420
+
1421
+
1422
+	/**
1423
+	 * Returns an array of all the buttons for the various statuses and switch status actions
1424
+	 *
1425
+	 * @return array
1426
+	 */
1427
+	protected function _get_reg_statuses()
1428
+	{
1429
+		$reg_status_array = EEM_Registration::instance()->reg_status_array();
1430
+		unset ($reg_status_array[EEM_Registration::status_id_incomplete]);
1431
+		// get current reg status
1432
+		$current_status = $this->_registration->status_ID();
1433
+		// is registration for free event? This will determine whether to display the pending payment option
1434
+		if ($current_status != EEM_Registration::status_id_pending_payment
1435
+			&& $this->_registration->transaction()
1436
+								   ->is_free()
1437
+		) {
1438
+			unset($reg_status_array[EEM_Registration::status_id_pending_payment]);
1439
+		}
1440
+		return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence');
1441
+	}
1442
+
1443
+
1444
+	/**
1445
+	 * This method is used when using _REG_ID from request which may or may not be an array of reg_ids.
1446
+	 *
1447
+	 * @param bool $status REG status given for changing registrations to.
1448
+	 * @param bool $notify Whether to send messages notifications or not.
1449
+	 * @return array  (array with reg_id(s) updated and whether update was successful.
1450
+	 */
1451
+	protected function _set_registration_status_from_request($status = false, $notify = false)
1452
+	{
1453
+		if (isset($this->_req_data['reg_status_change_form'])) {
1454
+			$REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1455
+				? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1456
+		} else {
1457
+			$REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1458
+		}
1459
+		$success = $this->_set_registration_status($REG_IDs, $status);
1460
+		//notify?
1461
+		if ($success
1462
+			&& $notify
1463
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1464
+				'espresso_registrations_resend_registration')
1465
+		) {
1466
+			$this->_process_resend_registration();
1467
+		}
1468
+		return $success;
1469
+	}
1470
+
1471
+
1472
+	/**
1473
+	 * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an
1474
+	 * array). Note, this method does NOT take care of possible notifications.  That is required by calling code.
1475
+	 *
1476
+	 * @param array $REG_IDs
1477
+	 * @param bool  $status
1478
+	 * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as
1479
+	 *               the array of updated registrations).
1480
+	 */
1481
+	protected function _set_registration_status($REG_IDs = array(), $status = false)
1482
+	{
1483
+		$success = false;
1484
+		// typecast $REG_IDs
1485
+		$REG_IDs = (array)$REG_IDs;
1486
+		if ( ! empty($REG_IDs)) {
1487
+			$success = true;
1488
+			// set default status if none is passed
1489
+			$status = $status ? $status : EEM_Registration::status_id_pending_payment;
1490
+			// sanitize $REG_IDs
1491
+			$REG_IDs = array_filter($REG_IDs, 'absint');
1492
+			//loop through REG_ID's and change status
1493
+			foreach ($REG_IDs as $REG_ID) {
1494
+				$registration = EEM_Registration::instance()->get_one_by_ID($REG_ID);
1495
+				if ($registration instanceof EE_Registration) {
1496
+					$registration->set_status($status);
1497
+					$result = $registration->save();
1498
+					// verifying explicit fails because update *may* just return 0 for 0 rows affected
1499
+					$success = $result !== false ? $success : false;
1500
+				}
1501
+			}
1502
+		}
1503
+		//reset _req_data['_REG_ID'] for any potential future messages notifications
1504
+		$this->_req_data['_REG_ID'] = $REG_IDs;
1505
+		//return $success and processed registrations
1506
+		return array('REG_ID' => $REG_IDs, 'success' => $success);
1507
+	}
1508
+
1509
+
1510
+	/**
1511
+	 * Common logic for setting up success message and redirecting to appropriate route
1512
+	 *
1513
+	 * @param  string $STS_ID status id for the registration changed to
1514
+	 * @param   bool  $notify indicates whether the _set_registration_status_from_request does notifications or not.
1515
+	 * @return void
1516
+	 */
1517
+	protected function _reg_status_change_return($STS_ID, $notify = false)
1518
+	{
1519
+		$result  = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify)
1520
+			: array('success' => false);
1521
+		$success = isset($result['success']) && $result['success'];
1522
+		//setup success message
1523
+		if ($success) {
1524
+			if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) {
1525
+				$msg = sprintf(__('Registration status has been set to %s', 'event_espresso'),
1526
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1527
+			} else {
1528
+				$msg = sprintf(__('Registrations have been set to %s.', 'event_espresso'),
1529
+					EEH_Template::pretty_status($STS_ID, false, 'lower'));
1530
+			}
1531
+			EE_Error::add_success($msg);
1532
+		} else {
1533
+			EE_Error::add_error(__('Something went wrong, and the status was not changed', 'event_espresso'), __FILE__,
1534
+				__LINE__, __FUNCTION__);
1535
+		}
1536
+		if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') {
1537
+			$route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID']));
1538
+		} else {
1539
+			$route = array('action' => 'default');
1540
+		}
1541
+		//unset nonces
1542
+		foreach ($this->_req_data as $ref => $value) {
1543
+			if (strpos($ref, 'nonce') !== false) {
1544
+				unset($this->_req_data[$ref]);
1545
+				continue;
1546
+			}
1547
+			$value                 = is_array($value) ? array_map('urlencode', $value) : urlencode($value);
1548
+			$this->_req_data[$ref] = $value;
1549
+		}
1550
+		//merge request vars so that the reloaded list table contains any existing filter query params
1551
+		$route = array_merge($this->_req_data, $route);
1552
+		$this->_redirect_after_action($success, '', '', $route, true);
1553
+	}
1554
+
1555
+
1556
+	/**
1557
+	 * incoming reg status change from reg details page.
1558
+	 *
1559
+	 * @return void
1560
+	 */
1561
+	protected function _change_reg_status()
1562
+	{
1563
+		$this->_req_data['return'] = 'view_registration';
1564
+		//set notify based on whether the send notifications toggle is set or not
1565
+		$notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']);
1566
+		//$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] );
1567
+		$this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status'])
1568
+			? $this->_req_data['reg_status_change_form']['reg_status'] : '';
1569
+		switch ($this->_req_data['reg_status_change_form']['reg_status']) {
1570
+			case EEM_Registration::status_id_approved :
1571
+			case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') :
1572
+				$this->approve_registration($notify);
1573
+				break;
1574
+			case EEM_Registration::status_id_pending_payment :
1575
+			case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') :
1576
+				$this->pending_registration($notify);
1577
+				break;
1578
+			case EEM_Registration::status_id_not_approved :
1579
+			case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') :
1580
+				$this->not_approve_registration($notify);
1581
+				break;
1582
+			case EEM_Registration::status_id_declined :
1583
+			case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') :
1584
+				$this->decline_registration($notify);
1585
+				break;
1586
+			case EEM_Registration::status_id_cancelled :
1587
+			case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') :
1588
+				$this->cancel_registration($notify);
1589
+				break;
1590
+			case EEM_Registration::status_id_wait_list :
1591
+			case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') :
1592
+				$this->waitlist_registration($notify);
1593
+				break;
1594
+			case EEM_Registration::status_id_incomplete :
1595
+			default :
1596
+				$result['success'] = false;
1597
+				unset($this->_req_data['return']);
1598
+				$this->_reg_status_change_return('', false);
1599
+				break;
1600
+		}
1601
+	}
1602
+
1603
+
1604
+	/**
1605
+	 * approve_registration
1606
+	 *
1607
+	 * @access protected
1608
+	 * @param bool $notify whether or not to notify the registrant about their approval.
1609
+	 * @return void
1610
+	 */
1611
+	protected function approve_registration($notify = false)
1612
+	{
1613
+		$this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify);
1614
+	}
1615
+
1616
+
1617
+	/**
1618
+	 *        decline_registration
1619
+	 *
1620
+	 * @access protected
1621
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1622
+	 * @return void
1623
+	 */
1624
+	protected function decline_registration($notify = false)
1625
+	{
1626
+		$this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify);
1627
+	}
1628
+
1629
+
1630
+	/**
1631
+	 *        cancel_registration
1632
+	 *
1633
+	 * @access protected
1634
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1635
+	 * @return void
1636
+	 */
1637
+	protected function cancel_registration($notify = false)
1638
+	{
1639
+		$this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify);
1640
+	}
1641
+
1642
+
1643
+	/**
1644
+	 *        not_approve_registration
1645
+	 *
1646
+	 * @access protected
1647
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1648
+	 * @return void
1649
+	 */
1650
+	protected function not_approve_registration($notify = false)
1651
+	{
1652
+		$this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify);
1653
+	}
1654
+
1655
+
1656
+	/**
1657
+	 *        decline_registration
1658
+	 *
1659
+	 * @access protected
1660
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1661
+	 * @return void
1662
+	 */
1663
+	protected function pending_registration($notify = false)
1664
+	{
1665
+		$this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify);
1666
+	}
1667
+
1668
+
1669
+	/**
1670
+	 * waitlist_registration
1671
+	 *
1672
+	 * @access protected
1673
+	 * @param bool $notify whether or not to notify the registrant about their status change.
1674
+	 * @return void
1675
+	 */
1676
+	protected function waitlist_registration($notify = false)
1677
+	{
1678
+		$this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify);
1679
+	}
1680
+
1681
+
1682
+	/**
1683
+	 *        generates HTML for the Registration main meta box
1684
+	 *
1685
+	 * @access public
1686
+	 * @return void
1687
+	 */
1688
+	public function _reg_details_meta_box()
1689
+	{
1690
+		EEH_Autoloader::register_line_item_display_autoloaders();
1691
+		EEH_Autoloader::register_line_item_filter_autoloaders();
1692
+		EE_Registry::instance()->load_helper('Line_Item');
1693
+		$transaction    = $this->_registration->transaction() ? $this->_registration->transaction()
1694
+			: EE_Transaction::new_instance();
1695
+		$this->_session = $transaction->session_data();
1696
+		$filters        = new EE_Line_Item_Filter_Collection();
1697
+		//$filters->add( new EE_Non_Zero_Line_Item_Filter() );
1698
+		$filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration));
1699
+		$line_item_filter_processor              = new EE_Line_Item_Filter_Processor($filters,
1700
+			$transaction->total_line_item());
1701
+		$filtered_line_item_tree                 = $line_item_filter_processor->process();
1702
+		$line_item_display                       = new EE_Line_Item_Display('reg_admin_table',
1703
+			'EE_Admin_Table_Registration_Line_Item_Display_Strategy');
1704
+		$this->_template_args['line_item_table'] = $line_item_display->display_line_item($filtered_line_item_tree,
1705
+			array('EE_Registration' => $this->_registration));
1706
+		$attendee                                = $this->_registration->attendee();
1707
+		if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction',
1708
+			'espresso_transactions_view_transaction')
1709
+		) {
1710
+			$this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1711
+				'action' => 'view_transaction',
1712
+				'TXN_ID' => $transaction->ID(),
1713
+			), TXN_ADMIN_URL), esc_html__(' View Transaction'), 'button secondary-button right',
1714
+				'dashicons dashicons-cart');
1715
+		} else {
1716
+			$this->_template_args['view_transaction_button'] = '';
1717
+		}
1718
+		if ($attendee instanceof EE_Attendee
1719
+			&& EE_Registry::instance()->CAP->current_user_can('ee_send_message',
1720
+				'espresso_registrations_resend_registration')
1721
+		) {
1722
+			$this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link(EE_Admin_Page::add_query_args_and_nonce(array(
1723
+				'action'      => 'resend_registration',
1724
+				'_REG_ID'     => $this->_registration->ID(),
1725
+				'redirect_to' => 'view_registration',
1726
+			), REG_ADMIN_URL), esc_html__(' Resend Registration'), 'button secondary-button right',
1727
+				'dashicons dashicons-email-alt');
1728
+		} else {
1729
+			$this->_template_args['resend_registration_button'] = '';
1730
+		}
1731
+		$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
1732
+		$payment                               = $transaction->get_first_related('Payment');
1733
+		$payment                               = ! $payment instanceof EE_Payment ? EE_Payment::new_instance() : $payment;
1734
+		$payment_method                        = $payment->get_first_related('Payment_Method');
1735
+		$payment_method                        = ! $payment_method instanceof EE_Payment_Method ? EE_Payment_Method::new_instance()
1736
+			: $payment_method;
1737
+		$reg_details                           = array(
1738
+			'payment_method'       => $payment_method->name(),
1739
+			'response_msg'         => $payment->gateway_response(),
1740
+			'registration_id'      => $this->_registration->get('REG_code'),
1741
+			'registration_session' => $this->_registration->session_ID(),
1742
+			'ip_address'           => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '',
1743
+			'user_agent'           => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '',
1744
+		);
1745
+		if (isset($reg_details['registration_id'])) {
1746
+			$this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id'];
1747
+			$this->_template_args['reg_details']['registration_id']['label'] = __('Registration ID', 'event_espresso');
1748
+			$this->_template_args['reg_details']['registration_id']['class'] = 'regular-text';
1749
+		}
1750
+		if (isset($reg_details['payment_method'])) {
1751
+			$this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method'];
1752
+			$this->_template_args['reg_details']['payment_method']['label'] = __('Most Recent Payment Method',
1753
+				'event_espresso');
1754
+			$this->_template_args['reg_details']['payment_method']['class'] = 'regular-text';
1755
+			$this->_template_args['reg_details']['response_msg']['value']   = $reg_details['response_msg'];
1756
+			$this->_template_args['reg_details']['response_msg']['label']   = __('Payment method response',
1757
+				'event_espresso');
1758
+			$this->_template_args['reg_details']['response_msg']['class']   = 'regular-text';
1759
+		}
1760
+		$this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session'];
1761
+		$this->_template_args['reg_details']['registration_session']['label'] = __('Registration Session',
1762
+			'event_espresso');
1763
+		$this->_template_args['reg_details']['registration_session']['class'] = 'regular-text';
1764
+		$this->_template_args['reg_details']['ip_address']['value']           = $reg_details['ip_address'];
1765
+		$this->_template_args['reg_details']['ip_address']['label']           = __('Registration placed from IP',
1766
+			'event_espresso');
1767
+		$this->_template_args['reg_details']['ip_address']['class']           = 'regular-text';
1768
+		$this->_template_args['reg_details']['user_agent']['value']           = $reg_details['user_agent'];
1769
+		$this->_template_args['reg_details']['user_agent']['label']           = __('Registrant User Agent',
1770
+			'event_espresso');
1771
+		$this->_template_args['reg_details']['user_agent']['class']           = 'large-text';
1772
+		$this->_template_args['event_link']                                   = EE_Admin_Page::add_query_args_and_nonce(array(
1773
+			'action'   => 'default',
1774
+			'event_id' => $this->_registration->event_ID(),
1775
+		), REG_ADMIN_URL);
1776
+		$this->_template_args['REG_ID']                                       = $this->_registration->ID();
1777
+		$this->_template_args['event_id']                                     = $this->_registration->event_ID();
1778
+		$template_path                                                        = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
1779
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
1780
+	}
1781
+
1782
+
1783
+	/**
1784
+	 * generates HTML for the Registration Questions meta box.
1785
+	 * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters),
1786
+	 * otherwise uses new forms system
1787
+	 *
1788
+	 * @access public
1789
+	 * @return void
1790
+	 */
1791
+	public function _reg_questions_meta_box()
1792
+	{
1793
+		//allow someone to override this method entirely
1794
+		if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this,
1795
+			$this->_registration)) {
1796
+			$form                                              = $this->_get_reg_custom_questions_form($this->_registration->ID());
1797
+			$this->_template_args['att_questions']             = count($form->subforms()) > 0 ? $form->get_html_and_js() : '';
1798
+			$this->_template_args['reg_questions_form_action'] = 'edit_registration';
1799
+			$this->_template_args['REG_ID']                    = $this->_registration->ID();
1800
+			$template_path                                     = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
1801
+			echo EEH_Template::display_template($template_path, $this->_template_args, true);
1802
+		}
1803
+	}
1804
+
1805
+
1806
+	/**
1807
+	 * form_before_question_group
1808
+	 *
1809
+	 * @deprecated    as of 4.8.32.rc.000
1810
+	 * @access        public
1811
+	 * @param        string $output
1812
+	 * @return        string
1813
+	 */
1814
+	public function form_before_question_group($output)
1815
+	{
1816
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1817
+			__('This method would have been protected but was used on a filter callback'
1818
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1819
+			'4.8.32.rc.000');
1820
+		return '
1821 1821
 	<table class="form-table ee-width-100">
1822 1822
 		<tbody>
1823 1823
 			';
1824
-    }
1825
-
1826
-
1827
-    /**
1828
-     * form_after_question_group
1829
-     *
1830
-     * @deprecated    as of 4.8.32.rc.000
1831
-     * @access        public
1832
-     * @param        string $output
1833
-     * @return        string
1834
-     */
1835
-    public function form_after_question_group($output)
1836
-    {
1837
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1838
-            __('This method would have been protected but was used on a filter callback'
1839
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1840
-            '4.8.32.rc.000');
1841
-        return '
1824
+	}
1825
+
1826
+
1827
+	/**
1828
+	 * form_after_question_group
1829
+	 *
1830
+	 * @deprecated    as of 4.8.32.rc.000
1831
+	 * @access        public
1832
+	 * @param        string $output
1833
+	 * @return        string
1834
+	 */
1835
+	public function form_after_question_group($output)
1836
+	{
1837
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1838
+			__('This method would have been protected but was used on a filter callback'
1839
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1840
+			'4.8.32.rc.000');
1841
+		return '
1842 1842
 			<tr class="hide-if-no-js">
1843 1843
 				<th> </th>
1844 1844
 				<td class="reg-admin-edit-attendee-question-td">
1845 1845
 					<a class="reg-admin-edit-attendee-question-lnk" href="#" title="'
1846
-               . esc_attr__('click to edit question', 'event_espresso')
1847
-               . '">
1846
+			   . esc_attr__('click to edit question', 'event_espresso')
1847
+			   . '">
1848 1848
 						<span class="reg-admin-edit-question-group-spn lt-grey-txt">'
1849
-               . __('edit the above question group', 'event_espresso')
1850
-               . '</span>
1849
+			   . __('edit the above question group', 'event_espresso')
1850
+			   . '</span>
1851 1851
 						<div class="dashicons dashicons-edit"></div>
1852 1852
 					</a>
1853 1853
 				</td>
@@ -1855,495 +1855,495 @@  discard block
 block discarded – undo
1855 1855
 		</tbody>
1856 1856
 	</table>
1857 1857
 ';
1858
-    }
1859
-
1860
-
1861
-    /**
1862
-     * form_form_field_label_wrap
1863
-     *
1864
-     * @deprecated    as of 4.8.32.rc.000
1865
-     * @access        public
1866
-     * @param        string $label
1867
-     * @return        string
1868
-     */
1869
-    public function form_form_field_label_wrap($label)
1870
-    {
1871
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1872
-            __('This method would have been protected but was used on a filter callback'
1873
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1874
-            '4.8.32.rc.000');
1875
-        return '
1858
+	}
1859
+
1860
+
1861
+	/**
1862
+	 * form_form_field_label_wrap
1863
+	 *
1864
+	 * @deprecated    as of 4.8.32.rc.000
1865
+	 * @access        public
1866
+	 * @param        string $label
1867
+	 * @return        string
1868
+	 */
1869
+	public function form_form_field_label_wrap($label)
1870
+	{
1871
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1872
+			__('This method would have been protected but was used on a filter callback'
1873
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1874
+			'4.8.32.rc.000');
1875
+		return '
1876 1876
 			<tr>
1877 1877
 				<th>
1878 1878
 					' . $label . '
1879 1879
 				</th>';
1880
-    }
1881
-
1882
-
1883
-    /**
1884
-     * form_form_field_input__wrap
1885
-     *
1886
-     * @deprecated    as of 4.8.32.rc.000
1887
-     * @access        public
1888
-     * @param        string $input
1889
-     * @return        string
1890
-     */
1891
-    public function form_form_field_input__wrap($input)
1892
-    {
1893
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1894
-            __('This method would have been protected but was used on a filter callback'
1895
-               . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1896
-            '4.8.32.rc.000');
1897
-        return '
1880
+	}
1881
+
1882
+
1883
+	/**
1884
+	 * form_form_field_input__wrap
1885
+	 *
1886
+	 * @deprecated    as of 4.8.32.rc.000
1887
+	 * @access        public
1888
+	 * @param        string $input
1889
+	 * @return        string
1890
+	 */
1891
+	public function form_form_field_input__wrap($input)
1892
+	{
1893
+		EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1894
+			__('This method would have been protected but was used on a filter callback'
1895
+			   . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1896
+			'4.8.32.rc.000');
1897
+		return '
1898 1898
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
1899 1899
 					' . $input . '
1900 1900
 				</td>
1901 1901
 			</tr>';
1902
-    }
1903
-
1904
-
1905
-    /**
1906
-     * Updates the registration's custom questions according to the form info, if the form is submitted.
1907
-     * If it's not a post, the "view_registrations" route will be called next on the SAME request
1908
-     * to display the page
1909
-     *
1910
-     * @access protected
1911
-     * @return void
1912
-     */
1913
-    protected function _update_attendee_registration_form()
1914
-    {
1915
-        do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
1916
-        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1917
-            $REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
1918
-            $success = $this->_save_reg_custom_questions_form($REG_ID);
1919
-            if ($success) {
1920
-                $what  = __('Registration Form', 'event_espresso');
1921
-                $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
1922
-                    : array('action' => 'default');
1923
-                $this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
1924
-            }
1925
-        }
1926
-    }
1927
-
1928
-
1929
-    /**
1930
-     * Gets the form for saving registrations custom questions (if done
1931
-     * previously retrieves the cached form object, which may have validation errors in it)
1932
-     *
1933
-     * @param int $REG_ID
1934
-     * @return EE_Registration_Custom_Questions_Form
1935
-     */
1936
-    protected function _get_reg_custom_questions_form($REG_ID)
1937
-    {
1938
-        if ( ! $this->_reg_custom_questions_form) {
1939
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
1940
-            $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
1941
-                EEM_Registration::instance()->get_one_by_ID($REG_ID)
1942
-            );
1943
-            $this->_reg_custom_questions_form->_construct_finalize(null, null);
1944
-        }
1945
-        return $this->_reg_custom_questions_form;
1946
-    }
1947
-
1948
-
1949
-    /**
1950
-     * Saves
1951
-     *
1952
-     * @access private
1953
-     * @param bool $REG_ID
1954
-     * @return bool
1955
-     */
1956
-    private function _save_reg_custom_questions_form($REG_ID = false)
1957
-    {
1958
-        if ( ! $REG_ID) {
1959
-            EE_Error::add_error(__('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__,
1960
-                __FUNCTION__, __LINE__);
1961
-        }
1962
-        $form = $this->_get_reg_custom_questions_form($REG_ID);
1963
-        $form->receive_form_submission($this->_req_data);
1964
-        $success = false;
1965
-        if ($form->is_valid()) {
1966
-            foreach ($form->subforms() as $question_group_id => $question_group_form) {
1967
-                foreach ($question_group_form->inputs() as $question_id => $input) {
1968
-                    $where_conditions    = array(
1969
-                        'QST_ID' => $question_id,
1970
-                        'REG_ID' => $REG_ID,
1971
-                    );
1972
-                    $possibly_new_values = array(
1973
-                        'ANS_value' => $input->normalized_value(),
1974
-                    );
1975
-                    $answer              = EEM_Answer::instance()->get_one(array($where_conditions));
1976
-                    if ($answer instanceof EE_Answer) {
1977
-                        $success = $answer->save($possibly_new_values);
1978
-                    } else {
1979
-                        //insert it then
1980
-                        $cols_n_vals = array_merge($where_conditions, $possibly_new_values);
1981
-                        $answer      = EE_Answer::new_instance($cols_n_vals);
1982
-                        $success     = $answer->save();
1983
-                    }
1984
-                }
1985
-            }
1986
-        } else {
1987
-            EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
1988
-        }
1989
-        return $success;
1990
-    }
1991
-
1992
-
1993
-    /**
1994
-     *        generates HTML for the Registration main meta box
1995
-     *
1996
-     * @access public
1997
-     * @return void
1998
-     */
1999
-    public function _reg_attendees_meta_box()
2000
-    {
2001
-        $REG = EEM_Registration::instance();
2002
-        //get all other registrations on this transaction, and cache
2003
-        //the attendees for them so we don't have to run another query using force_join
2004
-        $registrations                           = $REG->get_all(array(
2005
-            array(
2006
-                'TXN_ID' => $this->_registration->transaction_ID(),
2007
-                'REG_ID' => array('!=', $this->_registration->ID()),
2008
-            ),
2009
-            'force_join' => array('Attendee'),
2010
-        ));
2011
-        $this->_template_args['attendees']       = array();
2012
-        $this->_template_args['attendee_notice'] = '';
2013
-        if (empty($registrations)
2014
-            || (is_array($registrations)
2015
-                && ! EEH_Array::get_one_item_from_array($registrations))
2016
-        ) {
2017
-            EE_Error::add_error(__('There are no records attached to this registration. Something may have gone wrong with the registration',
2018
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2019
-            $this->_template_args['attendee_notice'] = EE_Error::get_notices();
2020
-        } else {
2021
-            $att_nmbr = 1;
2022
-            foreach ($registrations as $registration) {
2023
-                /* @var $registration EE_Registration */
2024
-                $attendee                                                    = $registration->attendee()
2025
-                    ? $registration->attendee()
2026
-                    : EEM_Attendee::instance()
2027
-                                  ->create_default_object();
2028
-                $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2029
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
2030
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
2031
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
2032
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
2033
-                $this->_template_args['attendees'][$att_nmbr]['address']     = implode(', ',
2034
-                    $attendee->full_address_as_array());
2035
-                $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(array(
2036
-                    'action' => 'edit_attendee',
2037
-                    'post'   => $attendee->ID(),
2038
-                ), REG_ADMIN_URL);
2039
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2040
-                $att_nmbr++;
2041
-            }
2042
-            //EEH_Debug_Tools::printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' );
2043
-            $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2044
-            //			$this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees'  ), REG_ADMIN_URL );
2045
-        }
2046
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2047
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2048
-    }
2049
-
2050
-
2051
-    /**
2052
-     *        generates HTML for the Edit Registration side meta box
2053
-     *
2054
-     * @access public
2055
-     * @return void
2056
-     */
2057
-    public function _reg_registrant_side_meta_box()
2058
-    {
2059
-        /*@var $attendee EE_Attendee */
2060
-        $att_check = $this->_registration->attendee();
2061
-        $attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2062
-        //now let's determine if this is not the primary registration.  If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show create button or not)
2063
-        if ( ! $this->_registration->is_primary_registrant()) {
2064
-            $primary_registration = $this->_registration->get_primary_registration();
2065
-            $primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2066
-                : null;
2067
-            if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2068
-                //in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg.
2069
-                $primary_registration = null;
2070
-            }
2071
-        } else {
2072
-            $primary_registration = null;
2073
-        }
2074
-        $this->_template_args['ATT_ID']            = $attendee->ID();
2075
-        $this->_template_args['fname']             = $attendee->fname();//$this->_registration->ATT_fname;
2076
-        $this->_template_args['lname']             = $attendee->lname();//$this->_registration->ATT_lname;
2077
-        $this->_template_args['email']             = $attendee->email();//$this->_registration->ATT_email;
2078
-        $this->_template_args['phone']             = $attendee->phone();
2079
-        $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2080
-        //edit link
2081
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2082
-            'action' => 'edit_attendee',
2083
-            'post'   => $attendee->ID(),
2084
-        ), REG_ADMIN_URL);
2085
-        $this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso');
2086
-        //create link
2087
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2088
-            ? EE_Admin_Page::add_query_args_and_nonce(array(
2089
-                'action'  => 'duplicate_attendee',
2090
-                '_REG_ID' => $this->_registration->ID(),
2091
-            ), REG_ADMIN_URL) : '';
2092
-        $this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
2093
-        $this->_template_args['att_check']    = $att_check;
2094
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2095
-        echo EEH_Template::display_template($template_path, $this->_template_args, true);
2096
-    }
2097
-
2098
-
2099
-    /**
2100
-     * trash or restore registrations
2101
-     *
2102
-     * @param  boolean $trash whether to archive or restore
2103
-     * @access protected
2104
-     * @return void
2105
-     */
2106
-    protected function _trash_or_restore_registrations($trash = true)
2107
-    {
2108
-        $REGM    = EEM_Registration::instance();
2109
-        $success = 1;
2110
-        $error   = 0;
2111
-        $tickets = array();
2112
-        $dtts    = array();
2113
-        //if empty _REG_ID then get out because there's nothing to do
2114
-        if (empty($this->_req_data['_REG_ID'])) {
2115
-            $msg = $trash
2116
-                ? __('In order to trash registrations you must select which ones you wish to trash by clicking the checkboxes.',
2117
-                    'event_espresso')
2118
-                : __('In order to restore registrations you must select which ones you wish to restore by clicking the checkboxes.',
2119
-                    'event_espresso');
2120
-            EE_Error::add_error($msg, __FILE__, __LINE__, __FUNCTION__);
2121
-            $this->_redirect_after_action(false, '', '', array(), true);
2122
-        }
2123
-        //Checkboxes
2124
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2125
-            // if array has more than one element than success message should be plural
2126
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2127
-            // cycle thru checkboxes
2128
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2129
-                /** @var EE_Registration $REG */
2130
-                $REG           = $REGM->get_one_by_ID($REG_ID);
2131
-                $payment_count = $REG->get_first_related('Transaction')->count_related('Payment');
2132
-                if ($payment_count > 0) {
2133
-                    $name    = $REG->attendee() instanceof EE_Attendee ? $REG->attendee()->full_name()
2134
-                        : __('Unknown Attendee', 'event_espresso');
2135
-                    $error   = 1;
2136
-                    $success = 0;
2137
-                    EE_Error::add_error(sprintf(__('The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2138
-                        'event_espresso'), $name), __FILE__, __FUNCTION__, __LINE__);
2139
-                    continue; //can't trash this registration because it has payments.
2140
-                }
2141
-                $ticket                 = $REG->get_first_related('Ticket');
2142
-                $tickets[$ticket->ID()] = $ticket;
2143
-                $dtt                    = $ticket->get_many_related('Datetime');
2144
-                $dtts                   = array_merge($dtts, $dtt);
2145
-                $updated                = $trash ? $REG->delete() : $REG->restore();
2146
-                if ( ! $updated) {
2147
-                    $success = 0;
2148
-                } else {
2149
-                    $success = 2;
2150
-                }/**/
2151
-            }
2152
-        } else {
2153
-            // grab single id and delete
2154
-            $REG_ID                 = absint($this->_req_data['_REG_ID']);
2155
-            $REG                    = $REGM->get_one_by_ID($REG_ID);
2156
-            $ticket                 = $REG->get_first_related('Ticket');
2157
-            $tickets[$ticket->ID()] = $ticket;
2158
-            $dtts                   = $ticket->get_many_related('Datetime');
2159
-            $updated                = $trash ? $REG->delete() : $REG->restore();
2160
-            if ( ! $updated) {
2161
-                $success = 0;
2162
-            }
2163
-        }
2164
-        //now let's update counts
2165
-        EEM_Ticket::instance()->update_tickets_sold($tickets);
2166
-        EEM_Datetime::instance()->update_sold($dtts);
2167
-        $what           = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso');
2168
-        $action_desc    = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2169
-        $overwrite_msgs = $error ? true : false;
2170
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), $overwrite_msgs);
2171
-    }
2172
-
2173
-
2174
-    /**
2175
-     * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2176
-     * registration but also.
2177
-     * 1. Removing relations to EE_Attendee
2178
-     * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2179
-     * ALSO trashed.
2180
-     * 3. Deleting permanently any related Line items but only if the above conditions are met.
2181
-     * 4. Removing relationships between all tickets and the related registrations
2182
-     * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2183
-     * 6. Deleting permanently any related Checkins.
2184
-     *
2185
-     * @return void
2186
-     */
2187
-    protected function _delete_registrations()
2188
-    {
2189
-        $REG_MDL = EEM_Registration::instance();
2190
-        $success = 1;
2191
-        //Checkboxes
2192
-        if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2193
-            // if array has more than one element than success message should be plural
2194
-            $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2195
-            // cycle thru checkboxes
2196
-            while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2197
-                $REG = $REG_MDL->get_one_by_ID($REG_ID);
2198
-                if ( ! $REG instanceof EE_Registration) {
2199
-                    continue;
2200
-                }
2201
-                $deleted = $this->_delete_registration($REG);
2202
-                if ( ! $deleted) {
2203
-                    $success = 0;
2204
-                }
2205
-            }
2206
-        } else {
2207
-            // grab single id and delete
2208
-            $REG_ID  = $this->_req_data['_REG_ID'];
2209
-            $REG     = $REG_MDL->get_one_by_ID($REG_ID);
2210
-            $deleted = $this->_delete_registration($REG);
2211
-            if ( ! $deleted) {
2212
-                $success = 0;
2213
-            }
2214
-        }
2215
-        $what        = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso');
2216
-        $action_desc = __('permanently deleted.', 'event_espresso');
2217
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), true);
2218
-    }
2219
-
2220
-
2221
-    /**
2222
-     * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2223
-     * models get affected.
2224
-     *
2225
-     * @param  EE_Registration $REG registration to be deleted permenantly
2226
-     * @return boolean              true = successful deletion, false = fail.
2227
-     */
2228
-    protected function _delete_registration(EE_Registration $REG)
2229
-    {
2230
-        //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed.
2231
-        $TXN         = $REG->get_first_related('Transaction');
2232
-        $REGS        = $TXN->get_many_related('Registration');
2233
-        $all_trashed = true;
2234
-        foreach ($REGS as $registration) {
2235
-            if ( ! $registration->get('REG_deleted')) {
2236
-                $all_trashed = false;
2237
-            }
2238
-        }
2239
-        if ( ! $all_trashed) {
2240
-            EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2241
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2242
-            return false;
2243
-        }
2244
-        //k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one).
2245
-        foreach ($REGS as $registration) {
2246
-            //delete related answers
2247
-            $registration->delete_related_permanently('Answer');
2248
-            //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2249
-            $attendee = $registration->get_first_related('Attendee');
2250
-            if ($attendee instanceof EE_Attendee) {
2251
-                $registration->_remove_relation_to($attendee, 'Attendee');
2252
-            }
2253
-            //now remove relationships to tickets on this registration.
2254
-            $registration->_remove_relations('Ticket');
2255
-            //now delete permanently the checkins related to this registration.
2256
-            $registration->delete_related_permanently('Checkin');
2257
-            if ($registration->ID() === $REG->ID()) {
2258
-                continue;
2259
-            } //we don't want to delete permanently the existing registration just yet.
2260
-            //remove relation to transaction for these registrations if NOT the existing registrations
2261
-            $registration->_remove_relations('Transaction');
2262
-            //delete permanently any related messages.
2263
-            $registration->delete_related_permanently('Message');
2264
-            //now delete this registration permanently
2265
-            $registration->delete_permanently();
2266
-        }
2267
-        //now all related registrations on the transaction are handled.  So let's just handle this registration itself (the transaction and line items should be all that's left).
2268
-        //delete the line items related to the transaction for this registration.
2269
-        $TXN->delete_related_permanently('Line_Item');
2270
-        //we need to remove all the relationships on the transaction
2271
-        $TXN->delete_related_permanently('Payment');
2272
-        $TXN->delete_related_permanently('Extra_Meta');
2273
-        $TXN->delete_related_permanently('Message');
2274
-        //now we can delete this REG permanently (and the transaction of course)
2275
-        $REG->delete_related_permanently('Transaction');
2276
-        return $REG->delete_permanently();
2277
-    }
2278
-
2279
-
2280
-    /**
2281
-     *    generates HTML for the Register New Attendee Admin page
2282
-     *
2283
-     * @access private
2284
-     * @throws \EE_Error
2285
-     * @return void
2286
-     */
2287
-    public function new_registration()
2288
-    {
2289
-        if ( ! $this->_set_reg_event()) {
2290
-            throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request',
2291
-                'event_espresso'));
2292
-        }
2293
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2294
-        // gotta start with a clean slate if we're not coming here via ajax
2295
-        if ( ! defined('DOING_AJAX')
2296
-             && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2297
-        ) {
2298
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2299
-        }
2300
-        $this->_template_args['event_name'] = '';
2301
-        // event name
2302
-        if ($this->_reg_event) {
2303
-            $this->_template_args['event_name'] = $this->_reg_event->name();
2304
-            $edit_event_url                     = self::add_query_args_and_nonce(array(
2305
-                'action' => 'edit',
2306
-                'post'   => $this->_reg_event->ID(),
2307
-            ), EVENTS_ADMIN_URL);
2308
-            $edit_event_lnk                     = '<a href="'
2309
-                                                  . $edit_event_url
2310
-                                                  . '" title="'
2311
-                                                  . esc_attr__('Edit ', 'event_espresso')
2312
-                                                  . $this->_reg_event->name()
2313
-                                                  . '">'
2314
-                                                  . __('Edit Event', 'event_espresso')
2315
-                                                  . '</a>';
2316
-            $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2317
-                                                   . $edit_event_lnk
2318
-                                                   . '</span>';
2319
-        }
2320
-        $this->_template_args['step_content'] = $this->_get_registration_step_content();
2321
-        if (defined('DOING_AJAX')) {
2322
-            $this->_return_json();
2323
-        }
2324
-        // grab header
2325
-        $template_path                              = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2326
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2327
-            $this->_template_args, true);
2328
-        //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2329
-        // the details template wrapper
2330
-        $this->display_admin_page_with_sidebar();
2331
-    }
2332
-
2333
-
2334
-    /**
2335
-     * This returns the content for a registration step
2336
-     *
2337
-     * @access protected
2338
-     * @return string html
2339
-     */
2340
-    protected function _get_registration_step_content()
2341
-    {
2342
-        if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2343
-            $warning_msg = sprintf(__('%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2344
-                'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">',
2345
-                '<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>');
2346
-            return '
1902
+	}
1903
+
1904
+
1905
+	/**
1906
+	 * Updates the registration's custom questions according to the form info, if the form is submitted.
1907
+	 * If it's not a post, the "view_registrations" route will be called next on the SAME request
1908
+	 * to display the page
1909
+	 *
1910
+	 * @access protected
1911
+	 * @return void
1912
+	 */
1913
+	protected function _update_attendee_registration_form()
1914
+	{
1915
+		do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this);
1916
+		if ($_SERVER['REQUEST_METHOD'] == 'POST') {
1917
+			$REG_ID  = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false;
1918
+			$success = $this->_save_reg_custom_questions_form($REG_ID);
1919
+			if ($success) {
1920
+				$what  = __('Registration Form', 'event_espresso');
1921
+				$route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID)
1922
+					: array('action' => 'default');
1923
+				$this->_redirect_after_action($success, $what, __('updated', 'event_espresso'), $route);
1924
+			}
1925
+		}
1926
+	}
1927
+
1928
+
1929
+	/**
1930
+	 * Gets the form for saving registrations custom questions (if done
1931
+	 * previously retrieves the cached form object, which may have validation errors in it)
1932
+	 *
1933
+	 * @param int $REG_ID
1934
+	 * @return EE_Registration_Custom_Questions_Form
1935
+	 */
1936
+	protected function _get_reg_custom_questions_form($REG_ID)
1937
+	{
1938
+		if ( ! $this->_reg_custom_questions_form) {
1939
+			require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
1940
+			$this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
1941
+				EEM_Registration::instance()->get_one_by_ID($REG_ID)
1942
+			);
1943
+			$this->_reg_custom_questions_form->_construct_finalize(null, null);
1944
+		}
1945
+		return $this->_reg_custom_questions_form;
1946
+	}
1947
+
1948
+
1949
+	/**
1950
+	 * Saves
1951
+	 *
1952
+	 * @access private
1953
+	 * @param bool $REG_ID
1954
+	 * @return bool
1955
+	 */
1956
+	private function _save_reg_custom_questions_form($REG_ID = false)
1957
+	{
1958
+		if ( ! $REG_ID) {
1959
+			EE_Error::add_error(__('An error occurred. No registration ID was received.', 'event_espresso'), __FILE__,
1960
+				__FUNCTION__, __LINE__);
1961
+		}
1962
+		$form = $this->_get_reg_custom_questions_form($REG_ID);
1963
+		$form->receive_form_submission($this->_req_data);
1964
+		$success = false;
1965
+		if ($form->is_valid()) {
1966
+			foreach ($form->subforms() as $question_group_id => $question_group_form) {
1967
+				foreach ($question_group_form->inputs() as $question_id => $input) {
1968
+					$where_conditions    = array(
1969
+						'QST_ID' => $question_id,
1970
+						'REG_ID' => $REG_ID,
1971
+					);
1972
+					$possibly_new_values = array(
1973
+						'ANS_value' => $input->normalized_value(),
1974
+					);
1975
+					$answer              = EEM_Answer::instance()->get_one(array($where_conditions));
1976
+					if ($answer instanceof EE_Answer) {
1977
+						$success = $answer->save($possibly_new_values);
1978
+					} else {
1979
+						//insert it then
1980
+						$cols_n_vals = array_merge($where_conditions, $possibly_new_values);
1981
+						$answer      = EE_Answer::new_instance($cols_n_vals);
1982
+						$success     = $answer->save();
1983
+					}
1984
+				}
1985
+			}
1986
+		} else {
1987
+			EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__);
1988
+		}
1989
+		return $success;
1990
+	}
1991
+
1992
+
1993
+	/**
1994
+	 *        generates HTML for the Registration main meta box
1995
+	 *
1996
+	 * @access public
1997
+	 * @return void
1998
+	 */
1999
+	public function _reg_attendees_meta_box()
2000
+	{
2001
+		$REG = EEM_Registration::instance();
2002
+		//get all other registrations on this transaction, and cache
2003
+		//the attendees for them so we don't have to run another query using force_join
2004
+		$registrations                           = $REG->get_all(array(
2005
+			array(
2006
+				'TXN_ID' => $this->_registration->transaction_ID(),
2007
+				'REG_ID' => array('!=', $this->_registration->ID()),
2008
+			),
2009
+			'force_join' => array('Attendee'),
2010
+		));
2011
+		$this->_template_args['attendees']       = array();
2012
+		$this->_template_args['attendee_notice'] = '';
2013
+		if (empty($registrations)
2014
+			|| (is_array($registrations)
2015
+				&& ! EEH_Array::get_one_item_from_array($registrations))
2016
+		) {
2017
+			EE_Error::add_error(__('There are no records attached to this registration. Something may have gone wrong with the registration',
2018
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2019
+			$this->_template_args['attendee_notice'] = EE_Error::get_notices();
2020
+		} else {
2021
+			$att_nmbr = 1;
2022
+			foreach ($registrations as $registration) {
2023
+				/* @var $registration EE_Registration */
2024
+				$attendee                                                    = $registration->attendee()
2025
+					? $registration->attendee()
2026
+					: EEM_Attendee::instance()
2027
+								  ->create_default_object();
2028
+				$this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2029
+				$this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
2030
+				$this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
2031
+				$this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
2032
+				$this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
2033
+				$this->_template_args['attendees'][$att_nmbr]['address']     = implode(', ',
2034
+					$attendee->full_address_as_array());
2035
+				$this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(array(
2036
+					'action' => 'edit_attendee',
2037
+					'post'   => $attendee->ID(),
2038
+				), REG_ADMIN_URL);
2039
+				$this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2040
+				$att_nmbr++;
2041
+			}
2042
+			//EEH_Debug_Tools::printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' );
2043
+			$this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2044
+			//			$this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees'  ), REG_ADMIN_URL );
2045
+		}
2046
+		$template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2047
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2048
+	}
2049
+
2050
+
2051
+	/**
2052
+	 *        generates HTML for the Edit Registration side meta box
2053
+	 *
2054
+	 * @access public
2055
+	 * @return void
2056
+	 */
2057
+	public function _reg_registrant_side_meta_box()
2058
+	{
2059
+		/*@var $attendee EE_Attendee */
2060
+		$att_check = $this->_registration->attendee();
2061
+		$attendee  = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object();
2062
+		//now let's determine if this is not the primary registration.  If it isn't then we set the primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the primary registration object (that way we know if we need to show create button or not)
2063
+		if ( ! $this->_registration->is_primary_registrant()) {
2064
+			$primary_registration = $this->_registration->get_primary_registration();
2065
+			$primary_attendee     = $primary_registration instanceof EE_Registration ? $primary_registration->attendee()
2066
+				: null;
2067
+			if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) {
2068
+				//in here?  This means the displayed registration is not the primary registrant but ALREADY HAS its own custom attendee object so let's not worry about the primary reg.
2069
+				$primary_registration = null;
2070
+			}
2071
+		} else {
2072
+			$primary_registration = null;
2073
+		}
2074
+		$this->_template_args['ATT_ID']            = $attendee->ID();
2075
+		$this->_template_args['fname']             = $attendee->fname();//$this->_registration->ATT_fname;
2076
+		$this->_template_args['lname']             = $attendee->lname();//$this->_registration->ATT_lname;
2077
+		$this->_template_args['email']             = $attendee->email();//$this->_registration->ATT_email;
2078
+		$this->_template_args['phone']             = $attendee->phone();
2079
+		$this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2080
+		//edit link
2081
+		$this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2082
+			'action' => 'edit_attendee',
2083
+			'post'   => $attendee->ID(),
2084
+		), REG_ADMIN_URL);
2085
+		$this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso');
2086
+		//create link
2087
+		$this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2088
+			? EE_Admin_Page::add_query_args_and_nonce(array(
2089
+				'action'  => 'duplicate_attendee',
2090
+				'_REG_ID' => $this->_registration->ID(),
2091
+			), REG_ADMIN_URL) : '';
2092
+		$this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
2093
+		$this->_template_args['att_check']    = $att_check;
2094
+		$template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2095
+		echo EEH_Template::display_template($template_path, $this->_template_args, true);
2096
+	}
2097
+
2098
+
2099
+	/**
2100
+	 * trash or restore registrations
2101
+	 *
2102
+	 * @param  boolean $trash whether to archive or restore
2103
+	 * @access protected
2104
+	 * @return void
2105
+	 */
2106
+	protected function _trash_or_restore_registrations($trash = true)
2107
+	{
2108
+		$REGM    = EEM_Registration::instance();
2109
+		$success = 1;
2110
+		$error   = 0;
2111
+		$tickets = array();
2112
+		$dtts    = array();
2113
+		//if empty _REG_ID then get out because there's nothing to do
2114
+		if (empty($this->_req_data['_REG_ID'])) {
2115
+			$msg = $trash
2116
+				? __('In order to trash registrations you must select which ones you wish to trash by clicking the checkboxes.',
2117
+					'event_espresso')
2118
+				: __('In order to restore registrations you must select which ones you wish to restore by clicking the checkboxes.',
2119
+					'event_espresso');
2120
+			EE_Error::add_error($msg, __FILE__, __LINE__, __FUNCTION__);
2121
+			$this->_redirect_after_action(false, '', '', array(), true);
2122
+		}
2123
+		//Checkboxes
2124
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2125
+			// if array has more than one element than success message should be plural
2126
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2127
+			// cycle thru checkboxes
2128
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2129
+				/** @var EE_Registration $REG */
2130
+				$REG           = $REGM->get_one_by_ID($REG_ID);
2131
+				$payment_count = $REG->get_first_related('Transaction')->count_related('Payment');
2132
+				if ($payment_count > 0) {
2133
+					$name    = $REG->attendee() instanceof EE_Attendee ? $REG->attendee()->full_name()
2134
+						: __('Unknown Attendee', 'event_espresso');
2135
+					$error   = 1;
2136
+					$success = 0;
2137
+					EE_Error::add_error(sprintf(__('The registration for %s could not be trashed because it has payments attached to the related transaction.  If you wish to trash this registration you must first delete the payments on the related transaction.',
2138
+						'event_espresso'), $name), __FILE__, __FUNCTION__, __LINE__);
2139
+					continue; //can't trash this registration because it has payments.
2140
+				}
2141
+				$ticket                 = $REG->get_first_related('Ticket');
2142
+				$tickets[$ticket->ID()] = $ticket;
2143
+				$dtt                    = $ticket->get_many_related('Datetime');
2144
+				$dtts                   = array_merge($dtts, $dtt);
2145
+				$updated                = $trash ? $REG->delete() : $REG->restore();
2146
+				if ( ! $updated) {
2147
+					$success = 0;
2148
+				} else {
2149
+					$success = 2;
2150
+				}/**/
2151
+			}
2152
+		} else {
2153
+			// grab single id and delete
2154
+			$REG_ID                 = absint($this->_req_data['_REG_ID']);
2155
+			$REG                    = $REGM->get_one_by_ID($REG_ID);
2156
+			$ticket                 = $REG->get_first_related('Ticket');
2157
+			$tickets[$ticket->ID()] = $ticket;
2158
+			$dtts                   = $ticket->get_many_related('Datetime');
2159
+			$updated                = $trash ? $REG->delete() : $REG->restore();
2160
+			if ( ! $updated) {
2161
+				$success = 0;
2162
+			}
2163
+		}
2164
+		//now let's update counts
2165
+		EEM_Ticket::instance()->update_tickets_sold($tickets);
2166
+		EEM_Datetime::instance()->update_sold($dtts);
2167
+		$what           = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso');
2168
+		$action_desc    = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
2169
+		$overwrite_msgs = $error ? true : false;
2170
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), $overwrite_msgs);
2171
+	}
2172
+
2173
+
2174
+	/**
2175
+	 * This is used to permanently delete registrations.  Note, this will handle not only deleting permanently the
2176
+	 * registration but also.
2177
+	 * 1. Removing relations to EE_Attendee
2178
+	 * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are
2179
+	 * ALSO trashed.
2180
+	 * 3. Deleting permanently any related Line items but only if the above conditions are met.
2181
+	 * 4. Removing relationships between all tickets and the related registrations
2182
+	 * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.)
2183
+	 * 6. Deleting permanently any related Checkins.
2184
+	 *
2185
+	 * @return void
2186
+	 */
2187
+	protected function _delete_registrations()
2188
+	{
2189
+		$REG_MDL = EEM_Registration::instance();
2190
+		$success = 1;
2191
+		//Checkboxes
2192
+		if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) {
2193
+			// if array has more than one element than success message should be plural
2194
+			$success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1;
2195
+			// cycle thru checkboxes
2196
+			while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) {
2197
+				$REG = $REG_MDL->get_one_by_ID($REG_ID);
2198
+				if ( ! $REG instanceof EE_Registration) {
2199
+					continue;
2200
+				}
2201
+				$deleted = $this->_delete_registration($REG);
2202
+				if ( ! $deleted) {
2203
+					$success = 0;
2204
+				}
2205
+			}
2206
+		} else {
2207
+			// grab single id and delete
2208
+			$REG_ID  = $this->_req_data['_REG_ID'];
2209
+			$REG     = $REG_MDL->get_one_by_ID($REG_ID);
2210
+			$deleted = $this->_delete_registration($REG);
2211
+			if ( ! $deleted) {
2212
+				$success = 0;
2213
+			}
2214
+		}
2215
+		$what        = $success > 1 ? __('Registrations', 'event_espresso') : __('Registration', 'event_espresso');
2216
+		$action_desc = __('permanently deleted.', 'event_espresso');
2217
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'default'), true);
2218
+	}
2219
+
2220
+
2221
+	/**
2222
+	 * handles the permanent deletion of a registration.  See comments with _delete_registrations() for details on what
2223
+	 * models get affected.
2224
+	 *
2225
+	 * @param  EE_Registration $REG registration to be deleted permenantly
2226
+	 * @return boolean              true = successful deletion, false = fail.
2227
+	 */
2228
+	protected function _delete_registration(EE_Registration $REG)
2229
+	{
2230
+		//first we start with the transaction... ultimately, we WILL not delete permanently if there are any related registrations on the transaction that are NOT trashed.
2231
+		$TXN         = $REG->get_first_related('Transaction');
2232
+		$REGS        = $TXN->get_many_related('Registration');
2233
+		$all_trashed = true;
2234
+		foreach ($REGS as $registration) {
2235
+			if ( ! $registration->get('REG_deleted')) {
2236
+				$all_trashed = false;
2237
+			}
2238
+		}
2239
+		if ( ! $all_trashed) {
2240
+			EE_Error::add_error(__('Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well.  These registrations will be permanently deleted in the same action.',
2241
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2242
+			return false;
2243
+		}
2244
+		//k made it here so that means we can delete all the related transactions and their answers (but let's do them separately from THIS one).
2245
+		foreach ($REGS as $registration) {
2246
+			//delete related answers
2247
+			$registration->delete_related_permanently('Answer');
2248
+			//remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact)
2249
+			$attendee = $registration->get_first_related('Attendee');
2250
+			if ($attendee instanceof EE_Attendee) {
2251
+				$registration->_remove_relation_to($attendee, 'Attendee');
2252
+			}
2253
+			//now remove relationships to tickets on this registration.
2254
+			$registration->_remove_relations('Ticket');
2255
+			//now delete permanently the checkins related to this registration.
2256
+			$registration->delete_related_permanently('Checkin');
2257
+			if ($registration->ID() === $REG->ID()) {
2258
+				continue;
2259
+			} //we don't want to delete permanently the existing registration just yet.
2260
+			//remove relation to transaction for these registrations if NOT the existing registrations
2261
+			$registration->_remove_relations('Transaction');
2262
+			//delete permanently any related messages.
2263
+			$registration->delete_related_permanently('Message');
2264
+			//now delete this registration permanently
2265
+			$registration->delete_permanently();
2266
+		}
2267
+		//now all related registrations on the transaction are handled.  So let's just handle this registration itself (the transaction and line items should be all that's left).
2268
+		//delete the line items related to the transaction for this registration.
2269
+		$TXN->delete_related_permanently('Line_Item');
2270
+		//we need to remove all the relationships on the transaction
2271
+		$TXN->delete_related_permanently('Payment');
2272
+		$TXN->delete_related_permanently('Extra_Meta');
2273
+		$TXN->delete_related_permanently('Message');
2274
+		//now we can delete this REG permanently (and the transaction of course)
2275
+		$REG->delete_related_permanently('Transaction');
2276
+		return $REG->delete_permanently();
2277
+	}
2278
+
2279
+
2280
+	/**
2281
+	 *    generates HTML for the Register New Attendee Admin page
2282
+	 *
2283
+	 * @access private
2284
+	 * @throws \EE_Error
2285
+	 * @return void
2286
+	 */
2287
+	public function new_registration()
2288
+	{
2289
+		if ( ! $this->_set_reg_event()) {
2290
+			throw new EE_Error(__('Unable to continue with registering because there is no Event ID in the request',
2291
+				'event_espresso'));
2292
+		}
2293
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2294
+		// gotta start with a clean slate if we're not coming here via ajax
2295
+		if ( ! defined('DOING_AJAX')
2296
+			 && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error']))
2297
+		) {
2298
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2299
+		}
2300
+		$this->_template_args['event_name'] = '';
2301
+		// event name
2302
+		if ($this->_reg_event) {
2303
+			$this->_template_args['event_name'] = $this->_reg_event->name();
2304
+			$edit_event_url                     = self::add_query_args_and_nonce(array(
2305
+				'action' => 'edit',
2306
+				'post'   => $this->_reg_event->ID(),
2307
+			), EVENTS_ADMIN_URL);
2308
+			$edit_event_lnk                     = '<a href="'
2309
+												  . $edit_event_url
2310
+												  . '" title="'
2311
+												  . esc_attr__('Edit ', 'event_espresso')
2312
+												  . $this->_reg_event->name()
2313
+												  . '">'
2314
+												  . __('Edit Event', 'event_espresso')
2315
+												  . '</a>';
2316
+			$this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">'
2317
+												   . $edit_event_lnk
2318
+												   . '</span>';
2319
+		}
2320
+		$this->_template_args['step_content'] = $this->_get_registration_step_content();
2321
+		if (defined('DOING_AJAX')) {
2322
+			$this->_return_json();
2323
+		}
2324
+		// grab header
2325
+		$template_path                              = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2326
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2327
+			$this->_template_args, true);
2328
+		//$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
2329
+		// the details template wrapper
2330
+		$this->display_admin_page_with_sidebar();
2331
+	}
2332
+
2333
+
2334
+	/**
2335
+	 * This returns the content for a registration step
2336
+	 *
2337
+	 * @access protected
2338
+	 * @return string html
2339
+	 */
2340
+	protected function _get_registration_step_content()
2341
+	{
2342
+		if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) {
2343
+			$warning_msg = sprintf(__('%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s',
2344
+				'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">',
2345
+				'<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>');
2346
+			return '
2347 2347
 	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2348 2348
 	<script >
2349 2349
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
@@ -2356,658 +2356,658 @@  discard block
 block discarded – undo
2356 2356
 	        }
2357 2357
 	    }, 800 );
2358 2358
 	</script >';
2359
-        }
2360
-        $template_args = array(
2361
-            'title'                    => '',
2362
-            'content'                  => '',
2363
-            'step_button_text'         => '',
2364
-            'show_notification_toggle' => false,
2365
-        );
2366
-        //to indicate we're processing a new registration
2367
-        $hidden_fields = array(
2368
-            'processing_registration' => array(
2369
-                'type'  => 'hidden',
2370
-                'value' => 0,
2371
-            ),
2372
-            'event_id'                => array(
2373
-                'type'  => 'hidden',
2374
-                'value' => $this->_reg_event->ID(),
2375
-            ),
2376
-        );
2377
-        //if the cart is empty then we know we're at step one so we'll display ticket selector
2378
-        $cart = EE_Registry::instance()->SSN->cart();
2379
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2380
-        switch ($step) {
2381
-            case 'ticket' :
2382
-                $hidden_fields['processing_registration']['value'] = 1;
2383
-                $template_args['title']                            = __('Step One: Select the Ticket for this registration',
2384
-                    'event_espresso');
2385
-                $template_args['content']                          = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2386
-                $template_args['step_button_text']                 = __('Add Tickets and Continue to Registrant Details',
2387
-                    'event_espresso');
2388
-                $template_args['show_notification_toggle']         = false;
2389
-                break;
2390
-            case 'questions' :
2391
-                $hidden_fields['processing_registration']['value'] = 2;
2392
-                $template_args['title']                            = __('Step Two: Add Registrant Details for this Registration',
2393
-                    'event_espresso');
2394
-                //in theory we should be able to run EED_SPCO at this point because the cart should have been setup properly by the first process_reg_step run.
2395
-                $template_args['content']                  = EED_Single_Page_Checkout::registration_checkout_for_admin();
2396
-                $template_args['step_button_text']         = __('Save Registration and Continue to Details',
2397
-                    'event_espresso');
2398
-                $template_args['show_notification_toggle'] = true;
2399
-                break;
2400
-        }
2401
-        $this->_set_add_edit_form_tags('process_reg_step',
2402
-            $hidden_fields); //we come back to the process_registration_step route.
2403
-        return EEH_Template::display_template(REG_TEMPLATE_PATH
2404
-                                              . 'reg_admin_register_new_attendee_step_content.template.php',
2405
-            $template_args, true);
2406
-    }
2407
-
2408
-
2409
-    /**
2410
-     *        set_reg_event
2411
-     *
2412
-     * @access private
2413
-     * @return boolean
2414
-     */
2415
-    private function _set_reg_event()
2416
-    {
2417
-        if (is_object($this->_reg_event)) {
2418
-            return true;
2419
-        }
2420
-        $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2421
-        if ( ! $EVT_ID) {
2422
-            return false;
2423
-        }
2424
-        $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2425
-        return true;
2426
-    }
2427
-
2428
-
2429
-    /**
2430
-     * process_reg_step
2431
-     *
2432
-     * @access        public
2433
-     * @return        string
2434
-     * @throws \RuntimeException
2435
-     * @throws \EE_Error
2436
-     */
2437
-    public function process_reg_step()
2438
-    {
2439
-        EE_System::do_not_cache();
2440
-        $this->_set_reg_event();
2441
-        EE_Registry::instance()->REQ->set_espresso_page(true);
2442
-        EE_Registry::instance()->REQ->set('uts', time());
2443
-        //what step are we on?
2444
-        $cart = EE_Registry::instance()->SSN->cart();
2445
-        $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2446
-        //if doing ajax then we need to verify the nonce
2447
-        if (defined('DOING_AJAX')) {
2448
-            $nonce = isset($this->_req_data[$this->_req_nonce])
2449
-                ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2450
-            $this->_verify_nonce($nonce, $this->_req_nonce);
2451
-        }
2452
-        switch ($step) {
2453
-            case 'ticket' :
2454
-                //process ticket selection
2455
-                $success = EED_Ticket_Selector::instance()->process_ticket_selections();
2456
-                if ($success) {
2457
-                    EE_Error::add_success(esc_html__('Tickets Selected. Now complete the registration.',
2458
-                        'event_espresso'));
2459
-                } else {
2460
-                    $query_args['step_error'] = $this->_req_data['step_error'] = true;
2461
-                }
2462
-                if (defined('DOING_AJAX')) {
2463
-                    $this->new_registration(); //display next step
2464
-                } else {
2465
-                    $query_args = array(
2466
-                        'action'                  => 'new_registration',
2467
-                        'processing_registration' => 1,
2468
-                        'event_id'                => $this->_reg_event->ID(),
2469
-                        'uts'                     => time(),
2470
-                    );
2471
-                    $this->_redirect_after_action(false, '', '', $query_args, true);
2472
-                }
2473
-                break;
2474
-            case 'questions' :
2475
-                if ( ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) {
2476
-                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2477
-                }
2478
-                //process registration
2479
-                $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2480
-                if ($cart instanceof EE_Cart) {
2481
-                    $grand_total = $cart->get_cart_grand_total();
2482
-                    if ($grand_total instanceof EE_Line_Item) {
2483
-                        $grand_total->save_this_and_descendants_to_txn();
2484
-                    }
2485
-                }
2486
-                if ( ! $transaction instanceof EE_Transaction) {
2487
-                    $query_args = array(
2488
-                        'action'                  => 'new_registration',
2489
-                        'processing_registration' => 2,
2490
-                        'event_id'                => $this->_reg_event->ID(),
2491
-                        'uts'                     => time(),
2492
-                    );
2493
-                    if (defined('DOING_AJAX')) {
2494
-                        //display registration form again because there are errors (maybe validation?)
2495
-                        $this->new_registration();
2496
-                        return;
2497
-                    } else {
2498
-                        $this->_redirect_after_action(false, '', '', $query_args, true);
2499
-                        return;
2500
-                    }
2501
-                }
2502
-                // maybe update status, and make sure to save transaction if not done already
2503
-                if ( ! $transaction->update_status_based_on_total_paid()) {
2504
-                    $transaction->save();
2505
-                }
2506
-                EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2507
-                $this->_req_data = array();
2508
-                $query_args      = array(
2509
-                    'action'        => 'redirect_to_txn',
2510
-                    'TXN_ID'        => $transaction->ID(),
2511
-                    'EVT_ID'        => $this->_reg_event->ID(),
2512
-                    'event_name'    => urlencode($this->_reg_event->name()),
2513
-                    'redirect_from' => 'new_registration',
2514
-                );
2515
-                $this->_redirect_after_action(false, '', '', $query_args, true);
2516
-                break;
2517
-        }
2518
-        //what are you looking here for?  Should be nothing to do at this point.
2519
-    }
2520
-
2521
-
2522
-    /**
2523
-     * redirect_to_txn
2524
-     *
2525
-     * @access public
2526
-     * @return void
2527
-     */
2528
-    public function redirect_to_txn()
2529
-    {
2530
-        EE_System::do_not_cache();
2531
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2532
-        $query_args = array(
2533
-            'action' => 'view_transaction',
2534
-            'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2535
-            'page'   => 'espresso_transactions',
2536
-        );
2537
-        if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2538
-            $query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2539
-            $query_args['event_name']    = urlencode($this->_req_data['event_name']);
2540
-            $query_args['redirect_from'] = $this->_req_data['redirect_from'];
2541
-        }
2542
-        EE_Error::add_success(__('Registration Created.  Please review the transaction and add any payments as necessary',
2543
-            'event_espresso'));
2544
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2545
-    }
2546
-
2547
-
2548
-    /**
2549
-     *        generates HTML for the Attendee Contact List
2550
-     *
2551
-     * @access protected
2552
-     * @return void
2553
-     */
2554
-    protected function _attendee_contact_list_table()
2555
-    {
2556
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2557
-        $this->_search_btn_label = __('Contacts', 'event_espresso');
2558
-        $this->display_admin_list_table_page_with_no_sidebar();
2559
-    }
2560
-
2561
-
2562
-    /**
2563
-     *        get_attendees
2564
-     *
2565
-     * @param bool $count whether to return count or data.
2566
-     * @access public
2567
-     * @return array
2568
-     */
2569
-    public function get_attendees($per_page, $count = false, $trash = false)
2570
-    {
2571
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2572
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2573
-        $ATT_MDL                    = EEM_Attendee::instance();
2574
-        $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2575
-        switch ($this->_req_data['orderby']) {
2576
-            case 'ATT_ID':
2577
-                $orderby = 'ATT_ID';
2578
-                break;
2579
-            case 'ATT_fname':
2580
-                $orderby = 'ATT_fname';
2581
-                break;
2582
-            case 'ATT_email':
2583
-                $orderby = 'ATT_email';
2584
-                break;
2585
-            case 'ATT_city':
2586
-                $orderby = 'ATT_city';
2587
-                break;
2588
-            case 'STA_ID':
2589
-                $orderby = 'STA_ID';
2590
-                break;
2591
-            case 'CNT_ID':
2592
-                $orderby = 'CNT_ID';
2593
-                break;
2594
-            default:
2595
-                $orderby = 'ATT_lname';
2596
-        }
2597
-        $sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
2598
-            : 'ASC';
2599
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2600
-            ? $this->_req_data['paged'] : 1;
2601
-        $per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2602
-        $per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2603
-            ? $this->_req_data['perpage'] : $per_page;
2604
-        $_where       = array();
2605
-        if ( ! empty($this->_req_data['s'])) {
2606
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2607
-            $_where['OR'] = array(
2608
-                'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2609
-                'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
2610
-                'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
2611
-                'ATT_fname'                         => array('LIKE', $sstr),
2612
-                'ATT_lname'                         => array('LIKE', $sstr),
2613
-                'ATT_short_bio'                     => array('LIKE', $sstr),
2614
-                'ATT_email'                         => array('LIKE', $sstr),
2615
-                'ATT_address'                       => array('LIKE', $sstr),
2616
-                'ATT_address2'                      => array('LIKE', $sstr),
2617
-                'ATT_city'                          => array('LIKE', $sstr),
2618
-                'Country.CNT_name'                  => array('LIKE', $sstr),
2619
-                'State.STA_name'                    => array('LIKE', $sstr),
2620
-                'ATT_phone'                         => array('LIKE', $sstr),
2621
-                'Registration.REG_final_price'      => array('LIKE', $sstr),
2622
-                'Registration.REG_code'             => array('LIKE', $sstr),
2623
-                'Registration.REG_count'            => array('LIKE', $sstr),
2624
-                'Registration.REG_group_size'       => array('LIKE', $sstr),
2625
-            );
2626
-        }
2627
-        $offset = ($current_page - 1) * $per_page;
2628
-        $limit  = $count ? null : array($offset, $per_page);
2629
-        if ($trash) {
2630
-            $_where['status'] = array('!=', 'publish');
2631
-            $all_attendees    = $count
2632
-                ? $ATT_MDL->count(array(
2633
-                    $_where,
2634
-                    'order_by' => array($orderby => $sort),
2635
-                    'limit'    => $limit,
2636
-                ), 'ATT_ID', true)
2637
-                : $ATT_MDL->get_all(array(
2638
-                    $_where,
2639
-                    'order_by' => array($orderby => $sort),
2640
-                    'limit'    => $limit,
2641
-                ));
2642
-        } else {
2643
-            $_where['status'] = array('IN', array('publish'));
2644
-            $all_attendees    = $count
2645
-                ? $ATT_MDL->count(array(
2646
-                    $_where,
2647
-                    'order_by' => array($orderby => $sort),
2648
-                    'limit'    => $limit,
2649
-                ), 'ATT_ID', true)
2650
-                : $ATT_MDL->get_all(array(
2651
-                    $_where,
2652
-                    'order_by' => array($orderby => $sort),
2653
-                    'limit'    => $limit,
2654
-                ));
2655
-        }
2656
-        return $all_attendees;
2657
-    }
2658
-
2659
-
2660
-    /**
2661
-     * This is just taking care of resending the registration confirmation
2662
-     *
2663
-     * @access protected
2664
-     * @return void
2665
-     */
2666
-    protected function _resend_registration()
2667
-    {
2668
-        $this->_process_resend_registration();
2669
-        $query_args = isset($this->_req_data['redirect_to'])
2670
-            ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
2671
-            : array(
2672
-                'action' => 'default',
2673
-            );
2674
-        $this->_redirect_after_action(false, '', '', $query_args, true);
2675
-    }
2676
-
2677
-    /**
2678
-     * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
2679
-     * to use when selecting registrations
2680
-     * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
2681
-     *                                                     the query parameters from the request
2682
-     * @return void ends the request with a redirect or download
2683
-     */
2684
-    public function _registrations_report_base( $method_name_for_getting_query_params )
2685
-    {
2686
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2687
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2688
-                'page'        => 'espresso_batch',
2689
-                'batch'       => 'file',
2690
-                'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2691
-                'filters'     => urlencode(
2692
-                    serialize(
2693
-                        call_user_func(
2694
-                            array( $this, $method_name_for_getting_query_params ),
2695
-                            EEH_Array::is_set(
2696
-                                $this->_req_data,
2697
-                                'filters',
2698
-                                array()
2699
-                            )
2700
-                        )
2701
-                    )
2702
-                ),
2703
-                'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
2704
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
2705
-                'return_url'  => urlencode($this->_req_data['return_url']),
2706
-            )));
2707
-        } else {
2708
-            $new_request_args = array(
2709
-                'export' => 'report',
2710
-                'action' => 'registrations_report_for_event',
2711
-                'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2712
-            );
2713
-            $this->_req_data = array_merge($this->_req_data, $new_request_args);
2714
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2715
-                require_once(EE_CLASSES . 'EE_Export.class.php');
2716
-                $EE_Export = EE_Export::instance($this->_req_data);
2717
-                $EE_Export->export();
2718
-            }
2719
-        }
2720
-    }
2721
-
2722
-
2723
-
2724
-    /**
2725
-     * Creates a registration report using only query parameters in the request
2726
-     * @return void
2727
-     */
2728
-    public function _registrations_report()
2729
-    {
2730
-        $this->_registrations_report_base( '_get_registration_query_parameters' );
2731
-    }
2732
-
2733
-
2734
-    public function _contact_list_export()
2735
-    {
2736
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2737
-            require_once(EE_CLASSES . 'EE_Export.class.php');
2738
-            $EE_Export = EE_Export::instance($this->_req_data);
2739
-            $EE_Export->export_attendees();
2740
-        }
2741
-    }
2742
-
2743
-
2744
-    public function _contact_list_report()
2745
-    {
2746
-        if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2747
-            wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2748
-                'page'        => 'espresso_batch',
2749
-                'batch'       => 'file',
2750
-                'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
2751
-                'return_url'  => urlencode($this->_req_data['return_url']),
2752
-            )));
2753
-        } else {
2754
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2755
-                require_once(EE_CLASSES . 'EE_Export.class.php');
2756
-                $EE_Export = EE_Export::instance($this->_req_data);
2757
-                $EE_Export->report_attendees();
2758
-            }
2759
-        }
2760
-    }
2761
-
2762
-
2763
-
2764
-
2765
-
2766
-    /***************************************        ATTENDEE DETAILS        ***************************************/
2767
-    /**
2768
-     * This duplicates the attendee object for the given incoming registration id and attendee_id.
2769
-     *
2770
-     * @return void
2771
-     */
2772
-    protected function _duplicate_attendee()
2773
-    {
2774
-        $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
2775
-        //verify we have necessary info
2776
-        if (empty($this->_req_data['_REG_ID'])) {
2777
-            EE_Error::add_error(__('Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
2778
-                'event_espresso'), __FILE__, __LINE__, __FUNCTION__);
2779
-            $query_args = array('action' => $action);
2780
-            $this->_redirect_after_action('', '', '', $query_args, true);
2781
-        }
2782
-        //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
2783
-        $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
2784
-        $attendee     = $registration->attendee();
2785
-        //remove relation of existing attendee on registration
2786
-        $registration->_remove_relation_to($attendee, 'Attendee');
2787
-        //new attendee
2788
-        $new_attendee = clone $attendee;
2789
-        $new_attendee->set('ATT_ID', 0);
2790
-        $new_attendee->save();
2791
-        //add new attendee to reg
2792
-        $registration->_add_relation_to($new_attendee, 'Attendee');
2793
-        EE_Error::add_success(__('New Contact record created.  Now make any edits you wish to make for this contact.',
2794
-            'event_espresso'));
2795
-        //redirect to edit page for attendee
2796
-        $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
2797
-        $this->_redirect_after_action('', '', '', $query_args, true);
2798
-    }
2799
-
2800
-
2801
-    //related to cpt routes
2802
-    protected function _insert_update_cpt_item($post_id, $post)
2803
-    {
2804
-        $success  = true;
2805
-        $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
2806
-        //for attendee updates
2807
-        if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
2808
-            //note we should only be UPDATING attendees at this point.
2809
-            $updated_fields = array(
2810
-                'ATT_fname'     => $this->_req_data['ATT_fname'],
2811
-                'ATT_lname'     => $this->_req_data['ATT_lname'],
2812
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
2813
-                'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
2814
-                'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
2815
-                'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
2816
-                'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
2817
-                'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
2818
-                'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
2819
-                'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
2820
-                'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
2821
-            );
2822
-            foreach ($updated_fields as $field => $value) {
2823
-                $attendee->set($field, $value);
2824
-            }
2825
-            $success                   = $attendee->save();
2826
-            $attendee_update_callbacks = apply_filters('FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
2827
-                array());
2828
-            foreach ($attendee_update_callbacks as $a_callback) {
2829
-                if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
2830
-                    throw new EE_Error(sprintf(__('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
2831
-                        'event_espresso'), $a_callback));
2832
-                }
2833
-            }
2834
-        }
2835
-        if ($success === false) {
2836
-            EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.',
2837
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2838
-        }
2839
-    }
2840
-
2841
-
2842
-    public function trash_cpt_item($post_id)
2843
-    {
2844
-    }
2845
-
2846
-
2847
-    public function delete_cpt_item($post_id)
2848
-    {
2849
-    }
2850
-
2851
-
2852
-    public function restore_cpt_item($post_id)
2853
-    {
2854
-    }
2855
-
2856
-
2857
-    protected function _restore_cpt_item($post_id, $revision_id)
2858
-    {
2859
-    }
2860
-
2861
-
2862
-    public function attendee_editor_metaboxes()
2863
-    {
2864
-        $this->verify_cpt_object();
2865
-        remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action],
2866
-            'normal', 'core');
2867
-        remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2868
-        if (post_type_supports('espresso_attendees', 'excerpt')) {
2869
-            add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box',
2870
-                $this->_cpt_routes[$this->_req_action], 'normal');
2871
-        }
2872
-        if (post_type_supports('espresso_attendees', 'comments')) {
2873
-            add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box',
2874
-                $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2875
-        }
2876
-        add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'),
2877
-            array($this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core');
2878
-        add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'),
2879
-            array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2880
-        add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'),
2881
-            array($this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high');
2882
-    }
2883
-
2884
-
2885
-    /**
2886
-     * Metabox for attendee contact info
2887
-     *
2888
-     * @param  WP_Post $post wp post object
2889
-     * @return string        attendee contact info ( and form )
2890
-     */
2891
-    public function attendee_contact_info($post)
2892
-    {
2893
-        //get attendee object ( should already have it )
2894
-        $this->_template_args['attendee'] = $this->_cpt_model_obj;
2895
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
2896
-        EEH_Template::display_template($template, $this->_template_args);
2897
-    }
2898
-
2899
-
2900
-    /**
2901
-     * Metabox for attendee details
2902
-     *
2903
-     * @param  WP_Post $post wp post object
2904
-     * @return string        attendee address details (and form)
2905
-     */
2906
-    public function attendee_address_details($post)
2907
-    {
2908
-        //get attendee object (should already have it)
2909
-        $this->_template_args['attendee']     = $this->_cpt_model_obj;
2910
-        $this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2911
-            'QST_ID'           => 0,
2912
-            'QST_display_text' => __('State/Province', 'event_espresso'),
2913
-            'QST_system'       => 'admin-state',
2914
-        )), EE_Answer::new_instance(array(
2915
-            'ANS_ID'    => 0,
2916
-            'ANS_value' => $this->_cpt_model_obj->state_ID(),
2917
-        )), array(
2918
-            'input_id'       => 'STA_ID',
2919
-            'input_name'     => 'STA_ID',
2920
-            'input_prefix'   => '',
2921
-            'append_qstn_id' => false,
2922
-        )));
2923
-        $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2924
-            'QST_ID'           => 0,
2925
-            'QST_display_text' => __('Country', 'event_espresso'),
2926
-            'QST_system'       => 'admin-country',
2927
-        )), EE_Answer::new_instance(array(
2928
-            'ANS_ID'    => 0,
2929
-            'ANS_value' => $this->_cpt_model_obj->country_ID(),
2930
-        )), array(
2931
-            'input_id'       => 'CNT_ISO',
2932
-            'input_name'     => 'CNT_ISO',
2933
-            'input_prefix'   => '',
2934
-            'append_qstn_id' => false,
2935
-        )));
2936
-        $template                             = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
2937
-        EEH_Template::display_template($template, $this->_template_args);
2938
-    }
2939
-
2940
-
2941
-    /**
2942
-     *        _attendee_details
2943
-     *
2944
-     * @access protected
2945
-     * @return void
2946
-     */
2947
-    public function attendee_registrations_meta_box($post)
2948
-    {
2949
-        $this->_template_args['attendee']      = $this->_cpt_model_obj;
2950
-        $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
2951
-        $template                              = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
2952
-        EEH_Template::display_template($template, $this->_template_args);
2953
-    }
2954
-
2955
-
2956
-    /**
2957
-     * add in the form fields for the attendee edit
2958
-     *
2959
-     * @param  WP_Post $post wp post object
2960
-     * @return string        html for new form.
2961
-     */
2962
-    public function after_title_form_fields($post)
2963
-    {
2964
-        if ($post->post_type == 'espresso_attendees') {
2965
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
2966
-            $template_args['attendee'] = $this->_cpt_model_obj;
2967
-            EEH_Template::display_template($template, $template_args);
2968
-        }
2969
-    }
2970
-
2971
-
2972
-    /**
2973
-     *        _trash_or_restore_attendee
2974
-     *
2975
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
2976
-     * @access protected
2977
-     * @return void
2978
-     */
2979
-    protected function _trash_or_restore_attendees($trash = true)
2980
-    {
2981
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2982
-        $ATT_MDL = EEM_Attendee::instance();
2983
-        $success = 1;
2984
-        //Checkboxes
2985
-        if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2986
-            // if array has more than one element than success message should be plural
2987
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2988
-            // cycle thru checkboxes
2989
-            while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
2990
-                $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
2991
-                    : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
2992
-                if ( ! $updated) {
2993
-                    $success = 0;
2994
-                }
2995
-            }
2996
-        } else {
2997
-            // grab single id and delete
2998
-            $ATT_ID = absint($this->_req_data['ATT_ID']);
2999
-            //get attendee
3000
-            $att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3001
-            $updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3002
-            $updated = $att->save();
3003
-            if ( ! $updated) {
3004
-                $success = 0;
3005
-            }
3006
-        }
3007
-        $what        = $success > 1 ? __('Contacts', 'event_espresso') : __('Contact', 'event_espresso');
3008
-        $action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
3009
-        $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3010
-    }
2359
+		}
2360
+		$template_args = array(
2361
+			'title'                    => '',
2362
+			'content'                  => '',
2363
+			'step_button_text'         => '',
2364
+			'show_notification_toggle' => false,
2365
+		);
2366
+		//to indicate we're processing a new registration
2367
+		$hidden_fields = array(
2368
+			'processing_registration' => array(
2369
+				'type'  => 'hidden',
2370
+				'value' => 0,
2371
+			),
2372
+			'event_id'                => array(
2373
+				'type'  => 'hidden',
2374
+				'value' => $this->_reg_event->ID(),
2375
+			),
2376
+		);
2377
+		//if the cart is empty then we know we're at step one so we'll display ticket selector
2378
+		$cart = EE_Registry::instance()->SSN->cart();
2379
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2380
+		switch ($step) {
2381
+			case 'ticket' :
2382
+				$hidden_fields['processing_registration']['value'] = 1;
2383
+				$template_args['title']                            = __('Step One: Select the Ticket for this registration',
2384
+					'event_espresso');
2385
+				$template_args['content']                          = EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event);
2386
+				$template_args['step_button_text']                 = __('Add Tickets and Continue to Registrant Details',
2387
+					'event_espresso');
2388
+				$template_args['show_notification_toggle']         = false;
2389
+				break;
2390
+			case 'questions' :
2391
+				$hidden_fields['processing_registration']['value'] = 2;
2392
+				$template_args['title']                            = __('Step Two: Add Registrant Details for this Registration',
2393
+					'event_espresso');
2394
+				//in theory we should be able to run EED_SPCO at this point because the cart should have been setup properly by the first process_reg_step run.
2395
+				$template_args['content']                  = EED_Single_Page_Checkout::registration_checkout_for_admin();
2396
+				$template_args['step_button_text']         = __('Save Registration and Continue to Details',
2397
+					'event_espresso');
2398
+				$template_args['show_notification_toggle'] = true;
2399
+				break;
2400
+		}
2401
+		$this->_set_add_edit_form_tags('process_reg_step',
2402
+			$hidden_fields); //we come back to the process_registration_step route.
2403
+		return EEH_Template::display_template(REG_TEMPLATE_PATH
2404
+											  . 'reg_admin_register_new_attendee_step_content.template.php',
2405
+			$template_args, true);
2406
+	}
2407
+
2408
+
2409
+	/**
2410
+	 *        set_reg_event
2411
+	 *
2412
+	 * @access private
2413
+	 * @return boolean
2414
+	 */
2415
+	private function _set_reg_event()
2416
+	{
2417
+		if (is_object($this->_reg_event)) {
2418
+			return true;
2419
+		}
2420
+		$EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false;
2421
+		if ( ! $EVT_ID) {
2422
+			return false;
2423
+		}
2424
+		$this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2425
+		return true;
2426
+	}
2427
+
2428
+
2429
+	/**
2430
+	 * process_reg_step
2431
+	 *
2432
+	 * @access        public
2433
+	 * @return        string
2434
+	 * @throws \RuntimeException
2435
+	 * @throws \EE_Error
2436
+	 */
2437
+	public function process_reg_step()
2438
+	{
2439
+		EE_System::do_not_cache();
2440
+		$this->_set_reg_event();
2441
+		EE_Registry::instance()->REQ->set_espresso_page(true);
2442
+		EE_Registry::instance()->REQ->set('uts', time());
2443
+		//what step are we on?
2444
+		$cart = EE_Registry::instance()->SSN->cart();
2445
+		$step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions';
2446
+		//if doing ajax then we need to verify the nonce
2447
+		if (defined('DOING_AJAX')) {
2448
+			$nonce = isset($this->_req_data[$this->_req_nonce])
2449
+				? sanitize_text_field($this->_req_data[$this->_req_nonce]) : '';
2450
+			$this->_verify_nonce($nonce, $this->_req_nonce);
2451
+		}
2452
+		switch ($step) {
2453
+			case 'ticket' :
2454
+				//process ticket selection
2455
+				$success = EED_Ticket_Selector::instance()->process_ticket_selections();
2456
+				if ($success) {
2457
+					EE_Error::add_success(esc_html__('Tickets Selected. Now complete the registration.',
2458
+						'event_espresso'));
2459
+				} else {
2460
+					$query_args['step_error'] = $this->_req_data['step_error'] = true;
2461
+				}
2462
+				if (defined('DOING_AJAX')) {
2463
+					$this->new_registration(); //display next step
2464
+				} else {
2465
+					$query_args = array(
2466
+						'action'                  => 'new_registration',
2467
+						'processing_registration' => 1,
2468
+						'event_id'                => $this->_reg_event->ID(),
2469
+						'uts'                     => time(),
2470
+					);
2471
+					$this->_redirect_after_action(false, '', '', $query_args, true);
2472
+				}
2473
+				break;
2474
+			case 'questions' :
2475
+				if ( ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['send_notifications'])) {
2476
+					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15);
2477
+				}
2478
+				//process registration
2479
+				$transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin();
2480
+				if ($cart instanceof EE_Cart) {
2481
+					$grand_total = $cart->get_cart_grand_total();
2482
+					if ($grand_total instanceof EE_Line_Item) {
2483
+						$grand_total->save_this_and_descendants_to_txn();
2484
+					}
2485
+				}
2486
+				if ( ! $transaction instanceof EE_Transaction) {
2487
+					$query_args = array(
2488
+						'action'                  => 'new_registration',
2489
+						'processing_registration' => 2,
2490
+						'event_id'                => $this->_reg_event->ID(),
2491
+						'uts'                     => time(),
2492
+					);
2493
+					if (defined('DOING_AJAX')) {
2494
+						//display registration form again because there are errors (maybe validation?)
2495
+						$this->new_registration();
2496
+						return;
2497
+					} else {
2498
+						$this->_redirect_after_action(false, '', '', $query_args, true);
2499
+						return;
2500
+					}
2501
+				}
2502
+				// maybe update status, and make sure to save transaction if not done already
2503
+				if ( ! $transaction->update_status_based_on_total_paid()) {
2504
+					$transaction->save();
2505
+				}
2506
+				EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2507
+				$this->_req_data = array();
2508
+				$query_args      = array(
2509
+					'action'        => 'redirect_to_txn',
2510
+					'TXN_ID'        => $transaction->ID(),
2511
+					'EVT_ID'        => $this->_reg_event->ID(),
2512
+					'event_name'    => urlencode($this->_reg_event->name()),
2513
+					'redirect_from' => 'new_registration',
2514
+				);
2515
+				$this->_redirect_after_action(false, '', '', $query_args, true);
2516
+				break;
2517
+		}
2518
+		//what are you looking here for?  Should be nothing to do at this point.
2519
+	}
2520
+
2521
+
2522
+	/**
2523
+	 * redirect_to_txn
2524
+	 *
2525
+	 * @access public
2526
+	 * @return void
2527
+	 */
2528
+	public function redirect_to_txn()
2529
+	{
2530
+		EE_System::do_not_cache();
2531
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
2532
+		$query_args = array(
2533
+			'action' => 'view_transaction',
2534
+			'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0,
2535
+			'page'   => 'espresso_transactions',
2536
+		);
2537
+		if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) {
2538
+			$query_args['EVT_ID']        = $this->_req_data['EVT_ID'];
2539
+			$query_args['event_name']    = urlencode($this->_req_data['event_name']);
2540
+			$query_args['redirect_from'] = $this->_req_data['redirect_from'];
2541
+		}
2542
+		EE_Error::add_success(__('Registration Created.  Please review the transaction and add any payments as necessary',
2543
+			'event_espresso'));
2544
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2545
+	}
2546
+
2547
+
2548
+	/**
2549
+	 *        generates HTML for the Attendee Contact List
2550
+	 *
2551
+	 * @access protected
2552
+	 * @return void
2553
+	 */
2554
+	protected function _attendee_contact_list_table()
2555
+	{
2556
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2557
+		$this->_search_btn_label = __('Contacts', 'event_espresso');
2558
+		$this->display_admin_list_table_page_with_no_sidebar();
2559
+	}
2560
+
2561
+
2562
+	/**
2563
+	 *        get_attendees
2564
+	 *
2565
+	 * @param bool $count whether to return count or data.
2566
+	 * @access public
2567
+	 * @return array
2568
+	 */
2569
+	public function get_attendees($per_page, $count = false, $trash = false)
2570
+	{
2571
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2572
+		require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2573
+		$ATT_MDL                    = EEM_Attendee::instance();
2574
+		$this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2575
+		switch ($this->_req_data['orderby']) {
2576
+			case 'ATT_ID':
2577
+				$orderby = 'ATT_ID';
2578
+				break;
2579
+			case 'ATT_fname':
2580
+				$orderby = 'ATT_fname';
2581
+				break;
2582
+			case 'ATT_email':
2583
+				$orderby = 'ATT_email';
2584
+				break;
2585
+			case 'ATT_city':
2586
+				$orderby = 'ATT_city';
2587
+				break;
2588
+			case 'STA_ID':
2589
+				$orderby = 'STA_ID';
2590
+				break;
2591
+			case 'CNT_ID':
2592
+				$orderby = 'CNT_ID';
2593
+				break;
2594
+			default:
2595
+				$orderby = 'ATT_lname';
2596
+		}
2597
+		$sort         = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
2598
+			: 'ASC';
2599
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
2600
+			? $this->_req_data['paged'] : 1;
2601
+		$per_page     = isset($per_page) && ! empty($per_page) ? $per_page : 10;
2602
+		$per_page     = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
2603
+			? $this->_req_data['perpage'] : $per_page;
2604
+		$_where       = array();
2605
+		if ( ! empty($this->_req_data['s'])) {
2606
+			$sstr         = '%' . $this->_req_data['s'] . '%';
2607
+			$_where['OR'] = array(
2608
+				'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2609
+				'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
2610
+				'Registration.Event.EVT_short_desc' => array('LIKE', $sstr),
2611
+				'ATT_fname'                         => array('LIKE', $sstr),
2612
+				'ATT_lname'                         => array('LIKE', $sstr),
2613
+				'ATT_short_bio'                     => array('LIKE', $sstr),
2614
+				'ATT_email'                         => array('LIKE', $sstr),
2615
+				'ATT_address'                       => array('LIKE', $sstr),
2616
+				'ATT_address2'                      => array('LIKE', $sstr),
2617
+				'ATT_city'                          => array('LIKE', $sstr),
2618
+				'Country.CNT_name'                  => array('LIKE', $sstr),
2619
+				'State.STA_name'                    => array('LIKE', $sstr),
2620
+				'ATT_phone'                         => array('LIKE', $sstr),
2621
+				'Registration.REG_final_price'      => array('LIKE', $sstr),
2622
+				'Registration.REG_code'             => array('LIKE', $sstr),
2623
+				'Registration.REG_count'            => array('LIKE', $sstr),
2624
+				'Registration.REG_group_size'       => array('LIKE', $sstr),
2625
+			);
2626
+		}
2627
+		$offset = ($current_page - 1) * $per_page;
2628
+		$limit  = $count ? null : array($offset, $per_page);
2629
+		if ($trash) {
2630
+			$_where['status'] = array('!=', 'publish');
2631
+			$all_attendees    = $count
2632
+				? $ATT_MDL->count(array(
2633
+					$_where,
2634
+					'order_by' => array($orderby => $sort),
2635
+					'limit'    => $limit,
2636
+				), 'ATT_ID', true)
2637
+				: $ATT_MDL->get_all(array(
2638
+					$_where,
2639
+					'order_by' => array($orderby => $sort),
2640
+					'limit'    => $limit,
2641
+				));
2642
+		} else {
2643
+			$_where['status'] = array('IN', array('publish'));
2644
+			$all_attendees    = $count
2645
+				? $ATT_MDL->count(array(
2646
+					$_where,
2647
+					'order_by' => array($orderby => $sort),
2648
+					'limit'    => $limit,
2649
+				), 'ATT_ID', true)
2650
+				: $ATT_MDL->get_all(array(
2651
+					$_where,
2652
+					'order_by' => array($orderby => $sort),
2653
+					'limit'    => $limit,
2654
+				));
2655
+		}
2656
+		return $all_attendees;
2657
+	}
2658
+
2659
+
2660
+	/**
2661
+	 * This is just taking care of resending the registration confirmation
2662
+	 *
2663
+	 * @access protected
2664
+	 * @return void
2665
+	 */
2666
+	protected function _resend_registration()
2667
+	{
2668
+		$this->_process_resend_registration();
2669
+		$query_args = isset($this->_req_data['redirect_to'])
2670
+			? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID'])
2671
+			: array(
2672
+				'action' => 'default',
2673
+			);
2674
+		$this->_redirect_after_action(false, '', '', $query_args, true);
2675
+	}
2676
+
2677
+	/**
2678
+	 * Creates a registration report, but accepts the name of a method to use for preparing the query parameters
2679
+	 * to use when selecting registrations
2680
+	 * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing
2681
+	 *                                                     the query parameters from the request
2682
+	 * @return void ends the request with a redirect or download
2683
+	 */
2684
+	public function _registrations_report_base( $method_name_for_getting_query_params )
2685
+	{
2686
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2687
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2688
+				'page'        => 'espresso_batch',
2689
+				'batch'       => 'file',
2690
+				'EVT_ID'      => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2691
+				'filters'     => urlencode(
2692
+					serialize(
2693
+						call_user_func(
2694
+							array( $this, $method_name_for_getting_query_params ),
2695
+							EEH_Array::is_set(
2696
+								$this->_req_data,
2697
+								'filters',
2698
+								array()
2699
+							)
2700
+						)
2701
+					)
2702
+				),
2703
+				'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false),
2704
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'),
2705
+				'return_url'  => urlencode($this->_req_data['return_url']),
2706
+			)));
2707
+		} else {
2708
+			$new_request_args = array(
2709
+				'export' => 'report',
2710
+				'action' => 'registrations_report_for_event',
2711
+				'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2712
+			);
2713
+			$this->_req_data = array_merge($this->_req_data, $new_request_args);
2714
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2715
+				require_once(EE_CLASSES . 'EE_Export.class.php');
2716
+				$EE_Export = EE_Export::instance($this->_req_data);
2717
+				$EE_Export->export();
2718
+			}
2719
+		}
2720
+	}
2721
+
2722
+
2723
+
2724
+	/**
2725
+	 * Creates a registration report using only query parameters in the request
2726
+	 * @return void
2727
+	 */
2728
+	public function _registrations_report()
2729
+	{
2730
+		$this->_registrations_report_base( '_get_registration_query_parameters' );
2731
+	}
2732
+
2733
+
2734
+	public function _contact_list_export()
2735
+	{
2736
+		if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2737
+			require_once(EE_CLASSES . 'EE_Export.class.php');
2738
+			$EE_Export = EE_Export::instance($this->_req_data);
2739
+			$EE_Export->export_attendees();
2740
+		}
2741
+	}
2742
+
2743
+
2744
+	public function _contact_list_report()
2745
+	{
2746
+		if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2747
+			wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
2748
+				'page'        => 'espresso_batch',
2749
+				'batch'       => 'file',
2750
+				'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'),
2751
+				'return_url'  => urlencode($this->_req_data['return_url']),
2752
+			)));
2753
+		} else {
2754
+			if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2755
+				require_once(EE_CLASSES . 'EE_Export.class.php');
2756
+				$EE_Export = EE_Export::instance($this->_req_data);
2757
+				$EE_Export->report_attendees();
2758
+			}
2759
+		}
2760
+	}
2761
+
2762
+
2763
+
2764
+
2765
+
2766
+	/***************************************        ATTENDEE DETAILS        ***************************************/
2767
+	/**
2768
+	 * This duplicates the attendee object for the given incoming registration id and attendee_id.
2769
+	 *
2770
+	 * @return void
2771
+	 */
2772
+	protected function _duplicate_attendee()
2773
+	{
2774
+		$action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default';
2775
+		//verify we have necessary info
2776
+		if (empty($this->_req_data['_REG_ID'])) {
2777
+			EE_Error::add_error(__('Unable to create the contact for the registration because the required parameters are not present (_REG_ID )',
2778
+				'event_espresso'), __FILE__, __LINE__, __FUNCTION__);
2779
+			$query_args = array('action' => $action);
2780
+			$this->_redirect_after_action('', '', '', $query_args, true);
2781
+		}
2782
+		//okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration.
2783
+		$registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']);
2784
+		$attendee     = $registration->attendee();
2785
+		//remove relation of existing attendee on registration
2786
+		$registration->_remove_relation_to($attendee, 'Attendee');
2787
+		//new attendee
2788
+		$new_attendee = clone $attendee;
2789
+		$new_attendee->set('ATT_ID', 0);
2790
+		$new_attendee->save();
2791
+		//add new attendee to reg
2792
+		$registration->_add_relation_to($new_attendee, 'Attendee');
2793
+		EE_Error::add_success(__('New Contact record created.  Now make any edits you wish to make for this contact.',
2794
+			'event_espresso'));
2795
+		//redirect to edit page for attendee
2796
+		$query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee');
2797
+		$this->_redirect_after_action('', '', '', $query_args, true);
2798
+	}
2799
+
2800
+
2801
+	//related to cpt routes
2802
+	protected function _insert_update_cpt_item($post_id, $post)
2803
+	{
2804
+		$success  = true;
2805
+		$attendee = EEM_Attendee::instance()->get_one_by_ID($post_id);
2806
+		//for attendee updates
2807
+		if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) {
2808
+			//note we should only be UPDATING attendees at this point.
2809
+			$updated_fields = array(
2810
+				'ATT_fname'     => $this->_req_data['ATT_fname'],
2811
+				'ATT_lname'     => $this->_req_data['ATT_lname'],
2812
+				'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
2813
+				'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
2814
+				'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
2815
+				'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
2816
+				'STA_ID'        => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '',
2817
+				'CNT_ISO'       => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '',
2818
+				'ATT_zip'       => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '',
2819
+				'ATT_email'     => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '',
2820
+				'ATT_phone'     => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '',
2821
+			);
2822
+			foreach ($updated_fields as $field => $value) {
2823
+				$attendee->set($field, $value);
2824
+			}
2825
+			$success                   = $attendee->save();
2826
+			$attendee_update_callbacks = apply_filters('FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update',
2827
+				array());
2828
+			foreach ($attendee_update_callbacks as $a_callback) {
2829
+				if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) {
2830
+					throw new EE_Error(sprintf(__('The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback.  Please check the spelling.',
2831
+						'event_espresso'), $a_callback));
2832
+				}
2833
+			}
2834
+		}
2835
+		if ($success === false) {
2836
+			EE_Error::add_error(__('Something went wrong with updating the meta table data for the registration.',
2837
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
2838
+		}
2839
+	}
2840
+
2841
+
2842
+	public function trash_cpt_item($post_id)
2843
+	{
2844
+	}
2845
+
2846
+
2847
+	public function delete_cpt_item($post_id)
2848
+	{
2849
+	}
2850
+
2851
+
2852
+	public function restore_cpt_item($post_id)
2853
+	{
2854
+	}
2855
+
2856
+
2857
+	protected function _restore_cpt_item($post_id, $revision_id)
2858
+	{
2859
+	}
2860
+
2861
+
2862
+	public function attendee_editor_metaboxes()
2863
+	{
2864
+		$this->verify_cpt_object();
2865
+		remove_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', $this->_cpt_routes[$this->_req_action],
2866
+			'normal', 'core');
2867
+		remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2868
+		if (post_type_supports('espresso_attendees', 'excerpt')) {
2869
+			add_meta_box('postexcerpt', __('Short Biography', 'event_espresso'), 'post_excerpt_meta_box',
2870
+				$this->_cpt_routes[$this->_req_action], 'normal');
2871
+		}
2872
+		if (post_type_supports('espresso_attendees', 'comments')) {
2873
+			add_meta_box('commentsdiv', __('Notes on the Contact', 'event_espresso'), 'post_comment_meta_box',
2874
+				$this->_cpt_routes[$this->_req_action], 'normal', 'core');
2875
+		}
2876
+		add_meta_box('attendee_contact_info', __('Contact Info', 'event_espresso'),
2877
+			array($this, 'attendee_contact_info'), $this->_cpt_routes[$this->_req_action], 'side', 'core');
2878
+		add_meta_box('attendee_details_address', __('Address Details', 'event_espresso'),
2879
+			array($this, 'attendee_address_details'), $this->_cpt_routes[$this->_req_action], 'normal', 'core');
2880
+		add_meta_box('attendee_registrations', __('Registrations for this Contact', 'event_espresso'),
2881
+			array($this, 'attendee_registrations_meta_box'), $this->_cpt_routes[$this->_req_action], 'normal', 'high');
2882
+	}
2883
+
2884
+
2885
+	/**
2886
+	 * Metabox for attendee contact info
2887
+	 *
2888
+	 * @param  WP_Post $post wp post object
2889
+	 * @return string        attendee contact info ( and form )
2890
+	 */
2891
+	public function attendee_contact_info($post)
2892
+	{
2893
+		//get attendee object ( should already have it )
2894
+		$this->_template_args['attendee'] = $this->_cpt_model_obj;
2895
+		$template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
2896
+		EEH_Template::display_template($template, $this->_template_args);
2897
+	}
2898
+
2899
+
2900
+	/**
2901
+	 * Metabox for attendee details
2902
+	 *
2903
+	 * @param  WP_Post $post wp post object
2904
+	 * @return string        attendee address details (and form)
2905
+	 */
2906
+	public function attendee_address_details($post)
2907
+	{
2908
+		//get attendee object (should already have it)
2909
+		$this->_template_args['attendee']     = $this->_cpt_model_obj;
2910
+		$this->_template_args['state_html']   = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2911
+			'QST_ID'           => 0,
2912
+			'QST_display_text' => __('State/Province', 'event_espresso'),
2913
+			'QST_system'       => 'admin-state',
2914
+		)), EE_Answer::new_instance(array(
2915
+			'ANS_ID'    => 0,
2916
+			'ANS_value' => $this->_cpt_model_obj->state_ID(),
2917
+		)), array(
2918
+			'input_id'       => 'STA_ID',
2919
+			'input_name'     => 'STA_ID',
2920
+			'input_prefix'   => '',
2921
+			'append_qstn_id' => false,
2922
+		)));
2923
+		$this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input(new EE_Question_Form_Input(EE_Question::new_instance(array(
2924
+			'QST_ID'           => 0,
2925
+			'QST_display_text' => __('Country', 'event_espresso'),
2926
+			'QST_system'       => 'admin-country',
2927
+		)), EE_Answer::new_instance(array(
2928
+			'ANS_ID'    => 0,
2929
+			'ANS_value' => $this->_cpt_model_obj->country_ID(),
2930
+		)), array(
2931
+			'input_id'       => 'CNT_ISO',
2932
+			'input_name'     => 'CNT_ISO',
2933
+			'input_prefix'   => '',
2934
+			'append_qstn_id' => false,
2935
+		)));
2936
+		$template                             = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
2937
+		EEH_Template::display_template($template, $this->_template_args);
2938
+	}
2939
+
2940
+
2941
+	/**
2942
+	 *        _attendee_details
2943
+	 *
2944
+	 * @access protected
2945
+	 * @return void
2946
+	 */
2947
+	public function attendee_registrations_meta_box($post)
2948
+	{
2949
+		$this->_template_args['attendee']      = $this->_cpt_model_obj;
2950
+		$this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
2951
+		$template                              = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
2952
+		EEH_Template::display_template($template, $this->_template_args);
2953
+	}
2954
+
2955
+
2956
+	/**
2957
+	 * add in the form fields for the attendee edit
2958
+	 *
2959
+	 * @param  WP_Post $post wp post object
2960
+	 * @return string        html for new form.
2961
+	 */
2962
+	public function after_title_form_fields($post)
2963
+	{
2964
+		if ($post->post_type == 'espresso_attendees') {
2965
+			$template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
2966
+			$template_args['attendee'] = $this->_cpt_model_obj;
2967
+			EEH_Template::display_template($template, $template_args);
2968
+		}
2969
+	}
2970
+
2971
+
2972
+	/**
2973
+	 *        _trash_or_restore_attendee
2974
+	 *
2975
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
2976
+	 * @access protected
2977
+	 * @return void
2978
+	 */
2979
+	protected function _trash_or_restore_attendees($trash = true)
2980
+	{
2981
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2982
+		$ATT_MDL = EEM_Attendee::instance();
2983
+		$success = 1;
2984
+		//Checkboxes
2985
+		if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
2986
+			// if array has more than one element than success message should be plural
2987
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
2988
+			// cycle thru checkboxes
2989
+			while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) {
2990
+				$updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID)
2991
+					: $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID);
2992
+				if ( ! $updated) {
2993
+					$success = 0;
2994
+				}
2995
+			}
2996
+		} else {
2997
+			// grab single id and delete
2998
+			$ATT_ID = absint($this->_req_data['ATT_ID']);
2999
+			//get attendee
3000
+			$att     = $ATT_MDL->get_one_by_ID($ATT_ID);
3001
+			$updated = $trash ? $att->set_status('trash') : $att->set_status('publish');
3002
+			$updated = $att->save();
3003
+			if ( ! $updated) {
3004
+				$success = 0;
3005
+			}
3006
+		}
3007
+		$what        = $success > 1 ? __('Contacts', 'event_espresso') : __('Contact', 'event_espresso');
3008
+		$action_desc = $trash ? __('moved to the trash', 'event_espresso') : __('restored', 'event_espresso');
3009
+		$this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list'));
3010
+	}
3011 3011
 
3012 3012
 }
3013 3013
 
Please login to merge, or discard this patch.
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -569,11 +569,11 @@  discard block
 block discarded – undo
569 569
     {
570 570
         //style
571 571
         //wp_register_style('espresso_attendees', ATT_ASSETS_URL . 'espresso_attendees_admin.css', array(), EVENT_ESPRESSO_VERSION );
572
-        wp_register_style('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.css', array('ee-admin-css'),
572
+        wp_register_style('espresso_reg', REG_ASSETS_URL.'espresso_registrations_admin.css', array('ee-admin-css'),
573 573
             EVENT_ESPRESSO_VERSION);
574 574
         wp_enqueue_style('espresso_reg');
575 575
         //script
576
-        wp_register_script('espresso_reg', REG_ASSETS_URL . 'espresso_registrations_admin.js',
576
+        wp_register_script('espresso_reg', REG_ASSETS_URL.'espresso_registrations_admin.js',
577 577
             array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), EVENT_ESPRESSO_VERSION, true);
578 578
         wp_enqueue_script('espresso_reg');
579 579
     }
@@ -604,7 +604,7 @@  discard block
 block discarded – undo
604 604
     public function load_scripts_styles_contact_list()
605 605
     {
606 606
         wp_deregister_style('espresso_reg');
607
-        wp_register_style('espresso_att', REG_ASSETS_URL . 'espresso_attendees_admin.css', array('ee-admin-css'),
607
+        wp_register_style('espresso_att', REG_ASSETS_URL.'espresso_attendees_admin.css', array('ee-admin-css'),
608 608
             EVENT_ESPRESSO_VERSION);
609 609
         wp_enqueue_style('espresso_att');
610 610
     }
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 
613 613
     public function load_scripts_styles_new_registration()
614 614
     {
615
-        wp_register_script('ee-spco-for-admin', REG_ASSETS_URL . 'spco_for_admin.js', array('underscore', 'jquery'),
615
+        wp_register_script('ee-spco-for-admin', REG_ASSETS_URL.'spco_for_admin.js', array('underscore', 'jquery'),
616 616
             EVENT_ESPRESSO_VERSION, true);
617 617
         wp_enqueue_script('ee-spco-for-admin');
618 618
         add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
                     'trash_registrations' => __('Trash Registrations', 'event_espresso'),
723 723
                 ),
724 724
             );
725
-            $this->_views['trash']      = array(
725
+            $this->_views['trash'] = array(
726 726
                 'slug'        => 'trash',
727 727
                 'label'       => __('Trash', 'event_espresso'),
728 728
                 'count'       => 0,
@@ -807,31 +807,31 @@  discard block
 block discarded – undo
807 807
         }
808 808
         $sc_items = array(
809 809
             'approved_status'   => array(
810
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved,
810
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved,
811 811
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'),
812 812
             ),
813 813
             'pending_status'    => array(
814
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment,
814
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment,
815 815
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'),
816 816
             ),
817 817
             'wait_list'         => array(
818
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list,
818
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list,
819 819
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'),
820 820
             ),
821 821
             'incomplete_status' => array(
822
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete,
822
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete,
823 823
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_incomplete, false, 'sentence'),
824 824
             ),
825 825
             'not_approved'      => array(
826
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved,
826
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved,
827 827
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'),
828 828
             ),
829 829
             'declined_status'   => array(
830
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined,
830
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined,
831 831
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'),
832 832
             ),
833 833
             'cancelled_status'  => array(
834
-                'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled,
834
+                'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled,
835 835
                 'desc'  => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'),
836 836
             ),
837 837
         );
@@ -852,17 +852,17 @@  discard block
 block discarded – undo
852 852
             if (EE_Registry::instance()->CAP->current_user_can('ee_edit_registrations',
853 853
                 'espresso_registrations_new_registration', $EVT_ID)
854 854
             ) {
855
-                $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('new_registration', 'add-registrant',
855
+                $this->_admin_page_title .= ' '.$this->get_action_link_or_button('new_registration', 'add-registrant',
856 856
                         array('event_id' => $EVT_ID), 'add-new-h2');
857 857
             }
858 858
             $event = EEM_Event::instance()->get_one_by_ID($EVT_ID);
859 859
             if ($event instanceof EE_Event) {
860 860
                 $this->_template_args['admin_page_header'] = sprintf(__('%s Viewing registrations for the event: %s%s',
861 861
                     'event_espresso'), '<h3 style="line-height:1.5em;">',
862
-                    '<br /><a href="' . EE_Admin_Page::add_query_args_and_nonce(array(
862
+                    '<br /><a href="'.EE_Admin_Page::add_query_args_and_nonce(array(
863 863
                         'action' => 'edit',
864 864
                         'post'   => $event->ID(),
865
-                    ), EVENTS_ADMIN_URL) . '">&nbsp;' . $event->get('EVT_name') . '&nbsp;</a>&nbsp;', '</h3>');
865
+                    ), EVENTS_ADMIN_URL).'">&nbsp;'.$event->get('EVT_name').'&nbsp;</a>&nbsp;', '</h3>');
866 866
             }
867 867
             $DTT_ID   = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0;
868 868
             $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID);
@@ -871,7 +871,7 @@  discard block
 block discarded – undo
871 871
                 $this->_template_args['admin_page_header'] .= ' &nbsp;<span class="drk-grey-text">';
872 872
                 $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>';
873 873
                 $this->_template_args['admin_page_header'] .= $datetime->name();
874
-                $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )';
874
+                $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )';
875 875
                 $this->_template_args['admin_page_header'] .= '</span></h3>';
876 876
             }
877 877
         }
@@ -921,10 +921,10 @@  discard block
 block discarded – undo
921 921
         $this_month = false,
922 922
         $today = false
923 923
     ) {
924
-        if( $this_month ) {
924
+        if ($this_month) {
925 925
             $this->_req_data['status'] = 'month';
926 926
         }
927
-        if( $today ) {
927
+        if ($today) {
928 928
             $this->_req_data['status'] = 'today';
929 929
         }
930 930
         $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count);
@@ -995,7 +995,7 @@  discard block
 block discarded – undo
995 995
     protected function _add_category_id_to_where_conditions(array $request)
996 996
     {
997 997
         $where = array();
998
-        if ( ! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) {
998
+        if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) {
999 999
             $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']);
1000 1000
         }
1001 1001
         return $where;
@@ -1014,7 +1014,7 @@  discard block
 block discarded – undo
1014 1014
         if ( ! empty($request['datetime_id'])) {
1015 1015
             $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']);
1016 1016
         }
1017
-        if( ! empty($request['DTT_ID'])){
1017
+        if ( ! empty($request['DTT_ID'])) {
1018 1018
             $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']);
1019 1019
         }
1020 1020
         return $where;
@@ -1030,7 +1030,7 @@  discard block
 block discarded – undo
1030 1030
     protected function _add_registration_status_to_where_conditions(array $request)
1031 1031
     {
1032 1032
         $where = array();
1033
-        $view  = EEH_Array::is_set( $request, 'status', '' );
1033
+        $view  = EEH_Array::is_set($request, 'status', '');
1034 1034
         $registration_status = ! empty($request['_reg_status'])
1035 1035
             ? sanitize_text_field($request['_reg_status'])
1036 1036
             : '';
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
     protected function _add_date_to_where_conditions(array $request)
1066 1066
     {
1067 1067
         $where = array();
1068
-        $view  = EEH_Array::is_set( $request, 'status', '' );
1068
+        $view  = EEH_Array::is_set($request, 'status', '');
1069 1069
         $month_range             = ! empty($request['month_range'])
1070 1070
             ? sanitize_text_field($request['month_range'])
1071 1071
             : '';
@@ -1079,12 +1079,12 @@  discard block
 block discarded – undo
1079 1079
                 array(
1080 1080
                     EEM_Registration::instance()->convert_datetime_for_query(
1081 1081
                         'REG_date',
1082
-                        $now . ' 00:00:00',
1082
+                        $now.' 00:00:00',
1083 1083
                         'Y-m-d H:i:s'
1084 1084
                     ),
1085 1085
                     EEM_Registration::instance()->convert_datetime_for_query(
1086 1086
                         'REG_date',
1087
-                        $now . ' 23:59:59',
1087
+                        $now.' 23:59:59',
1088 1088
                         'Y-m-d H:i:s'
1089 1089
                     ),
1090 1090
                 ),
@@ -1097,12 +1097,12 @@  discard block
 block discarded – undo
1097 1097
                 array(
1098 1098
                     EEM_Registration::instance()->convert_datetime_for_query(
1099 1099
                         'REG_date',
1100
-                        $current_year_and_month . '-01 00:00:00',
1100
+                        $current_year_and_month.'-01 00:00:00',
1101 1101
                         'Y-m-d H:i:s'
1102 1102
                     ),
1103 1103
                     EEM_Registration::instance()->convert_datetime_for_query(
1104 1104
                         'REG_date',
1105
-                        $current_year_and_month . '-' . $days_this_month . ' 23:59:59',
1105
+                        $current_year_and_month.'-'.$days_this_month.' 23:59:59',
1106 1106
                         'Y-m-d H:i:s'
1107 1107
                     ),
1108 1108
                 ),
@@ -1117,18 +1117,18 @@  discard block
 block discarded – undo
1117 1117
                 : '';
1118 1118
             //if there is not a month or year then we can't go further
1119 1119
             if ($month_requested && $year_requested) {
1120
-                $days_in_month     = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01'));
1120
+                $days_in_month     = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01'));
1121 1121
                 $where['REG_date'] = array(
1122 1122
                     'BETWEEN',
1123 1123
                     array(
1124 1124
                         EEM_Registration::instance()->convert_datetime_for_query(
1125 1125
                             'REG_date',
1126
-                            $year_requested . '-' . $month_requested . '-01 00:00:00',
1126
+                            $year_requested.'-'.$month_requested.'-01 00:00:00',
1127 1127
                             'Y-m-d H:i:s'
1128 1128
                         ),
1129 1129
                         EEM_Registration::instance()->convert_datetime_for_query(
1130 1130
                             'REG_date',
1131
-                            $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59',
1131
+                            $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59',
1132 1132
                             'Y-m-d H:i:s'
1133 1133
                         ),
1134 1134
                     ),
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
     {
1150 1150
         $where = array();
1151 1151
         if ( ! empty($request['s'])) {
1152
-            $search_string = '%' . sanitize_text_field($request['s']) . '%';
1152
+            $search_string = '%'.sanitize_text_field($request['s']).'%';
1153 1153
             $where['OR'] = array(
1154 1154
                 'Event.EVT_name'                          => array('LIKE', $search_string),
1155 1155
                 'Event.EVT_desc'                          => array('LIKE', $search_string),
@@ -1251,7 +1251,7 @@  discard block
 block discarded – undo
1251 1251
             : $per_page;
1252 1252
 
1253 1253
         //-1 means return all results so get out if that's set.
1254
-        if ((int)$per_page === -1) {
1254
+        if ((int) $per_page === -1) {
1255 1255
             return array();
1256 1256
         }
1257 1257
         $per_page = absint($per_page);
@@ -1297,12 +1297,12 @@  discard block
 block discarded – undo
1297 1297
                 'action'   => 'default',
1298 1298
                 'event_id' => $event_id,
1299 1299
             ), REG_ADMIN_URL);
1300
-            $this->_template_args['filtered_transactions_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
1300
+            $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
1301 1301
                 'action' => 'default',
1302 1302
                 'EVT_ID' => $event_id,
1303 1303
                 'page'   => 'espresso_transactions',
1304 1304
             ), admin_url('admin.php'));
1305
-            $this->_template_args['event_link']                  = EE_Admin_Page::add_query_args_and_nonce(array(
1305
+            $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
1306 1306
                 'page'   => 'espresso_events',
1307 1307
                 'action' => 'edit',
1308 1308
                 'post'   => $event_id,
@@ -1321,7 +1321,7 @@  discard block
 block discarded – undo
1321 1321
                     '_REG_ID' => $previous_reg['REG_ID'],
1322 1322
                 ), REG_ADMIN_URL), 'dashicons dashicons-arrow-left ee-icon-size-22') : '';
1323 1323
             // grab header
1324
-            $template_path                             = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php';
1324
+            $template_path                             = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php';
1325 1325
             $this->_template_args['REG_ID']            = $this->_registration->ID();
1326 1326
             $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path,
1327 1327
                 $this->_template_args, true);
@@ -1395,8 +1395,8 @@  discard block
 block discarded – undo
1395 1395
                     'default' => $this->_registration->ID(),
1396 1396
                 )),
1397 1397
                 'current_status'     => new EE_Form_Section_HTML(EEH_HTML::tr(EEH_HTML::th(EEH_HTML::label(EEH_HTML::strong(__('Current Registration Status',
1398
-                        'event_espresso')))) . EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(),
1399
-                        '', 'status-' . $this->_registration->status_ID(),
1398
+                        'event_espresso')))).EEH_HTML::td(EEH_HTML::strong($this->_registration->pretty_status(),
1399
+                        '', 'status-'.$this->_registration->status_ID(),
1400 1400
                         'line-height: 1em; font-size: 1.5em; font-weight: bold;')))),
1401 1401
                 'reg_status'         => new EE_Select_Input($this->_get_reg_statuses(), array(
1402 1402
                     'html_label_text' => __('Change Registration Status to', 'event_espresso'),
@@ -1452,9 +1452,9 @@  discard block
 block discarded – undo
1452 1452
     {
1453 1453
         if (isset($this->_req_data['reg_status_change_form'])) {
1454 1454
             $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID'])
1455
-                ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array();
1455
+                ? (array) $this->_req_data['reg_status_change_form']['REG_ID'] : array();
1456 1456
         } else {
1457
-            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array();
1457
+            $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array) $this->_req_data['_REG_ID'] : array();
1458 1458
         }
1459 1459
         $success = $this->_set_registration_status($REG_IDs, $status);
1460 1460
         //notify?
@@ -1482,7 +1482,7 @@  discard block
 block discarded – undo
1482 1482
     {
1483 1483
         $success = false;
1484 1484
         // typecast $REG_IDs
1485
-        $REG_IDs = (array)$REG_IDs;
1485
+        $REG_IDs = (array) $REG_IDs;
1486 1486
         if ( ! empty($REG_IDs)) {
1487 1487
             $success = true;
1488 1488
             // set default status if none is passed
@@ -1775,7 +1775,7 @@  discard block
 block discarded – undo
1775 1775
         ), REG_ADMIN_URL);
1776 1776
         $this->_template_args['REG_ID']                                       = $this->_registration->ID();
1777 1777
         $this->_template_args['event_id']                                     = $this->_registration->event_ID();
1778
-        $template_path                                                        = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php';
1778
+        $template_path                                                        = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php';
1779 1779
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
1780 1780
     }
1781 1781
 
@@ -1797,7 +1797,7 @@  discard block
 block discarded – undo
1797 1797
             $this->_template_args['att_questions']             = count($form->subforms()) > 0 ? $form->get_html_and_js() : '';
1798 1798
             $this->_template_args['reg_questions_form_action'] = 'edit_registration';
1799 1799
             $this->_template_args['REG_ID']                    = $this->_registration->ID();
1800
-            $template_path                                     = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php';
1800
+            $template_path                                     = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php';
1801 1801
             echo EEH_Template::display_template($template_path, $this->_template_args, true);
1802 1802
         }
1803 1803
     }
@@ -1813,7 +1813,7 @@  discard block
 block discarded – undo
1813 1813
      */
1814 1814
     public function form_before_question_group($output)
1815 1815
     {
1816
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1816
+        EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__,
1817 1817
             __('This method would have been protected but was used on a filter callback'
1818 1818
                . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1819 1819
             '4.8.32.rc.000');
@@ -1834,7 +1834,7 @@  discard block
 block discarded – undo
1834 1834
      */
1835 1835
     public function form_after_question_group($output)
1836 1836
     {
1837
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1837
+        EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__,
1838 1838
             __('This method would have been protected but was used on a filter callback'
1839 1839
                . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1840 1840
             '4.8.32.rc.000');
@@ -1868,14 +1868,14 @@  discard block
 block discarded – undo
1868 1868
      */
1869 1869
     public function form_form_field_label_wrap($label)
1870 1870
     {
1871
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1871
+        EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__,
1872 1872
             __('This method would have been protected but was used on a filter callback'
1873 1873
                . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1874 1874
             '4.8.32.rc.000');
1875 1875
         return '
1876 1876
 			<tr>
1877 1877
 				<th>
1878
-					' . $label . '
1878
+					' . $label.'
1879 1879
 				</th>';
1880 1880
     }
1881 1881
 
@@ -1890,13 +1890,13 @@  discard block
 block discarded – undo
1890 1890
      */
1891 1891
     public function form_form_field_input__wrap($input)
1892 1892
     {
1893
-        EE_Error::doing_it_wrong(__CLASS__ . '::' . __FUNCTION__,
1893
+        EE_Error::doing_it_wrong(__CLASS__.'::'.__FUNCTION__,
1894 1894
             __('This method would have been protected but was used on a filter callback'
1895 1895
                . 'so needed to be public. Please discontinue usage as it will be removed soon.', 'event_espresso'),
1896 1896
             '4.8.32.rc.000');
1897 1897
         return '
1898 1898
 				<td class="reg-admin-attendee-questions-input-td disabled-input">
1899
-					' . $input . '
1899
+					' . $input.'
1900 1900
 				</td>
1901 1901
 			</tr>';
1902 1902
     }
@@ -1936,7 +1936,7 @@  discard block
 block discarded – undo
1936 1936
     protected function _get_reg_custom_questions_form($REG_ID)
1937 1937
     {
1938 1938
         if ( ! $this->_reg_custom_questions_form) {
1939
-            require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php');
1939
+            require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php');
1940 1940
             $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form(
1941 1941
                 EEM_Registration::instance()->get_one_by_ID($REG_ID)
1942 1942
             );
@@ -1965,7 +1965,7 @@  discard block
 block discarded – undo
1965 1965
         if ($form->is_valid()) {
1966 1966
             foreach ($form->subforms() as $question_group_id => $question_group_form) {
1967 1967
                 foreach ($question_group_form->inputs() as $question_id => $input) {
1968
-                    $where_conditions    = array(
1968
+                    $where_conditions = array(
1969 1969
                         'QST_ID' => $question_id,
1970 1970
                         'REG_ID' => $REG_ID,
1971 1971
                     );
@@ -2001,7 +2001,7 @@  discard block
 block discarded – undo
2001 2001
         $REG = EEM_Registration::instance();
2002 2002
         //get all other registrations on this transaction, and cache
2003 2003
         //the attendees for them so we don't have to run another query using force_join
2004
-        $registrations                           = $REG->get_all(array(
2004
+        $registrations = $REG->get_all(array(
2005 2005
             array(
2006 2006
                 'TXN_ID' => $this->_registration->transaction_ID(),
2007 2007
                 'REG_ID' => array('!=', $this->_registration->ID()),
@@ -2021,29 +2021,29 @@  discard block
 block discarded – undo
2021 2021
             $att_nmbr = 1;
2022 2022
             foreach ($registrations as $registration) {
2023 2023
                 /* @var $registration EE_Registration */
2024
-                $attendee                                                    = $registration->attendee()
2024
+                $attendee = $registration->attendee()
2025 2025
                     ? $registration->attendee()
2026 2026
                     : EEM_Attendee::instance()
2027 2027
                                   ->create_default_object();
2028 2028
                 $this->_template_args['attendees'][$att_nmbr]['STS_ID']      = $registration->status_ID();
2029
-                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname();//( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
2030
-                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname();//( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
2031
-                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email();//( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
2032
-                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price();//( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
2029
+                $this->_template_args['attendees'][$att_nmbr]['fname']       = $attendee->fname(); //( isset( $registration->ATT_fname ) & ! empty( $registration->ATT_fname ) ) ? $registration->ATT_fname : '';
2030
+                $this->_template_args['attendees'][$att_nmbr]['lname']       = $attendee->lname(); //( isset( $registration->ATT_lname ) & ! empty( $registration->ATT_lname ) ) ? $registration->ATT_lname : '';
2031
+                $this->_template_args['attendees'][$att_nmbr]['email']       = $attendee->email(); //( isset( $registration->ATT_email ) & ! empty( $registration->ATT_email ) ) ? $registration->ATT_email : '';
2032
+                $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price(); //( isset( $registration->REG_final_price ) & ! empty( $registration->REG_final_price ) ) ? $registration->REG_final_price : '';
2033 2033
                 $this->_template_args['attendees'][$att_nmbr]['address']     = implode(', ',
2034 2034
                     $attendee->full_address_as_array());
2035 2035
                 $this->_template_args['attendees'][$att_nmbr]['att_link']    = self::add_query_args_and_nonce(array(
2036 2036
                     'action' => 'edit_attendee',
2037 2037
                     'post'   => $attendee->ID(),
2038 2038
                 ), REG_ADMIN_URL);
2039
-                $this->_template_args['attendees'][$att_nmbr]['event_name']  = $registration->event_obj()->name();
2039
+                $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name();
2040 2040
                 $att_nmbr++;
2041 2041
             }
2042 2042
             //EEH_Debug_Tools::printr( $attendees, '$attendees  <br /><span style="font-size:10px;font-weight:normal;">( file: '. __FILE__ . ' - line no: ' . __LINE__ . ' )</span>', 'auto' );
2043 2043
             $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign;
2044 2044
             //			$this->_template_args['registration_form_url'] = add_query_arg( array( 'action' => 'edit_registration', 'process' => 'attendees'  ), REG_ADMIN_URL );
2045 2045
         }
2046
-        $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php';
2046
+        $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php';
2047 2047
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2048 2048
     }
2049 2049
 
@@ -2072,26 +2072,26 @@  discard block
 block discarded – undo
2072 2072
             $primary_registration = null;
2073 2073
         }
2074 2074
         $this->_template_args['ATT_ID']            = $attendee->ID();
2075
-        $this->_template_args['fname']             = $attendee->fname();//$this->_registration->ATT_fname;
2076
-        $this->_template_args['lname']             = $attendee->lname();//$this->_registration->ATT_lname;
2077
-        $this->_template_args['email']             = $attendee->email();//$this->_registration->ATT_email;
2075
+        $this->_template_args['fname']             = $attendee->fname(); //$this->_registration->ATT_fname;
2076
+        $this->_template_args['lname']             = $attendee->lname(); //$this->_registration->ATT_lname;
2077
+        $this->_template_args['email']             = $attendee->email(); //$this->_registration->ATT_email;
2078 2078
         $this->_template_args['phone']             = $attendee->phone();
2079 2079
         $this->_template_args['formatted_address'] = EEH_Address::format($attendee);
2080 2080
         //edit link
2081
-        $this->_template_args['att_edit_link']  = EE_Admin_Page::add_query_args_and_nonce(array(
2081
+        $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array(
2082 2082
             'action' => 'edit_attendee',
2083 2083
             'post'   => $attendee->ID(),
2084 2084
         ), REG_ADMIN_URL);
2085 2085
         $this->_template_args['att_edit_label'] = __('View/Edit Contact', 'event_espresso');
2086 2086
         //create link
2087
-        $this->_template_args['create_link']  = $primary_registration instanceof EE_Registration
2087
+        $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration
2088 2088
             ? EE_Admin_Page::add_query_args_and_nonce(array(
2089 2089
                 'action'  => 'duplicate_attendee',
2090 2090
                 '_REG_ID' => $this->_registration->ID(),
2091 2091
             ), REG_ADMIN_URL) : '';
2092 2092
         $this->_template_args['create_label'] = __('Create Contact', 'event_espresso');
2093 2093
         $this->_template_args['att_check']    = $att_check;
2094
-        $template_path                        = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php';
2094
+        $template_path                        = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php';
2095 2095
         echo EEH_Template::display_template($template_path, $this->_template_args, true);
2096 2096
     }
2097 2097
 
@@ -2305,7 +2305,7 @@  discard block
 block discarded – undo
2305 2305
                 'action' => 'edit',
2306 2306
                 'post'   => $this->_reg_event->ID(),
2307 2307
             ), EVENTS_ADMIN_URL);
2308
-            $edit_event_lnk                     = '<a href="'
2308
+            $edit_event_lnk = '<a href="'
2309 2309
                                                   . $edit_event_url
2310 2310
                                                   . '" title="'
2311 2311
                                                   . esc_attr__('Edit ', 'event_espresso')
@@ -2322,7 +2322,7 @@  discard block
 block discarded – undo
2322 2322
             $this->_return_json();
2323 2323
         }
2324 2324
         // grab header
2325
-        $template_path                              = REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php';
2325
+        $template_path                              = REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php';
2326 2326
         $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path,
2327 2327
             $this->_template_args, true);
2328 2328
         //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE );
@@ -2344,7 +2344,7 @@  discard block
 block discarded – undo
2344 2344
                 'event_espresso'), '<br />', '<h3 class="important-notice">', '</h3>', '<div class="float-right">',
2345 2345
                 '<span id="redirect_timer" class="important-notice">30</span>', '</div>', '<b>', '</b>');
2346 2346
             return '
2347
-	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div>
2347
+	<div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div>
2348 2348
 	<script >
2349 2349
 		// WHOAH !!! it appears that someone is using the back button from the Transaction admin page
2350 2350
 		// after just adding a new registration... we gotta try to put a stop to that !!!
@@ -2569,7 +2569,7 @@  discard block
 block discarded – undo
2569 2569
     public function get_attendees($per_page, $count = false, $trash = false)
2570 2570
     {
2571 2571
         do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2572
-        require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php');
2572
+        require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php');
2573 2573
         $ATT_MDL                    = EEM_Attendee::instance();
2574 2574
         $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
2575 2575
         switch ($this->_req_data['orderby']) {
@@ -2603,7 +2603,7 @@  discard block
 block discarded – undo
2603 2603
             ? $this->_req_data['perpage'] : $per_page;
2604 2604
         $_where       = array();
2605 2605
         if ( ! empty($this->_req_data['s'])) {
2606
-            $sstr         = '%' . $this->_req_data['s'] . '%';
2606
+            $sstr         = '%'.$this->_req_data['s'].'%';
2607 2607
             $_where['OR'] = array(
2608 2608
                 'Registration.Event.EVT_name'       => array('LIKE', $sstr),
2609 2609
                 'Registration.Event.EVT_desc'       => array('LIKE', $sstr),
@@ -2681,7 +2681,7 @@  discard block
 block discarded – undo
2681 2681
      *                                                     the query parameters from the request
2682 2682
      * @return void ends the request with a redirect or download
2683 2683
      */
2684
-    public function _registrations_report_base( $method_name_for_getting_query_params )
2684
+    public function _registrations_report_base($method_name_for_getting_query_params)
2685 2685
     {
2686 2686
         if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) {
2687 2687
             wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array(
@@ -2691,7 +2691,7 @@  discard block
 block discarded – undo
2691 2691
                 'filters'     => urlencode(
2692 2692
                     serialize(
2693 2693
                         call_user_func(
2694
-                            array( $this, $method_name_for_getting_query_params ),
2694
+                            array($this, $method_name_for_getting_query_params),
2695 2695
                             EEH_Array::is_set(
2696 2696
                                 $this->_req_data,
2697 2697
                                 'filters',
@@ -2711,8 +2711,8 @@  discard block
 block discarded – undo
2711 2711
                 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null,
2712 2712
             );
2713 2713
             $this->_req_data = array_merge($this->_req_data, $new_request_args);
2714
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2715
-                require_once(EE_CLASSES . 'EE_Export.class.php');
2714
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
2715
+                require_once(EE_CLASSES.'EE_Export.class.php');
2716 2716
                 $EE_Export = EE_Export::instance($this->_req_data);
2717 2717
                 $EE_Export->export();
2718 2718
             }
@@ -2727,14 +2727,14 @@  discard block
 block discarded – undo
2727 2727
      */
2728 2728
     public function _registrations_report()
2729 2729
     {
2730
-        $this->_registrations_report_base( '_get_registration_query_parameters' );
2730
+        $this->_registrations_report_base('_get_registration_query_parameters');
2731 2731
     }
2732 2732
 
2733 2733
 
2734 2734
     public function _contact_list_export()
2735 2735
     {
2736
-        if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2737
-            require_once(EE_CLASSES . 'EE_Export.class.php');
2736
+        if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
2737
+            require_once(EE_CLASSES.'EE_Export.class.php');
2738 2738
             $EE_Export = EE_Export::instance($this->_req_data);
2739 2739
             $EE_Export->export_attendees();
2740 2740
         }
@@ -2751,8 +2751,8 @@  discard block
 block discarded – undo
2751 2751
                 'return_url'  => urlencode($this->_req_data['return_url']),
2752 2752
             )));
2753 2753
         } else {
2754
-            if (is_readable(EE_CLASSES . 'EE_Export.class.php')) {
2755
-                require_once(EE_CLASSES . 'EE_Export.class.php');
2754
+            if (is_readable(EE_CLASSES.'EE_Export.class.php')) {
2755
+                require_once(EE_CLASSES.'EE_Export.class.php');
2756 2756
                 $EE_Export = EE_Export::instance($this->_req_data);
2757 2757
                 $EE_Export->report_attendees();
2758 2758
             }
@@ -2809,7 +2809,7 @@  discard block
 block discarded – undo
2809 2809
             $updated_fields = array(
2810 2810
                 'ATT_fname'     => $this->_req_data['ATT_fname'],
2811 2811
                 'ATT_lname'     => $this->_req_data['ATT_lname'],
2812
-                'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'],
2812
+                'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'],
2813 2813
                 'ATT_address'   => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '',
2814 2814
                 'ATT_address2'  => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '',
2815 2815
                 'ATT_city'      => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '',
@@ -2892,7 +2892,7 @@  discard block
 block discarded – undo
2892 2892
     {
2893 2893
         //get attendee object ( should already have it )
2894 2894
         $this->_template_args['attendee'] = $this->_cpt_model_obj;
2895
-        $template                         = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php';
2895
+        $template                         = REG_TEMPLATE_PATH.'attendee_contact_info_metabox_content.template.php';
2896 2896
         EEH_Template::display_template($template, $this->_template_args);
2897 2897
     }
2898 2898
 
@@ -2933,7 +2933,7 @@  discard block
 block discarded – undo
2933 2933
             'input_prefix'   => '',
2934 2934
             'append_qstn_id' => false,
2935 2935
         )));
2936
-        $template                             = REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php';
2936
+        $template = REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php';
2937 2937
         EEH_Template::display_template($template, $this->_template_args);
2938 2938
     }
2939 2939
 
@@ -2948,7 +2948,7 @@  discard block
 block discarded – undo
2948 2948
     {
2949 2949
         $this->_template_args['attendee']      = $this->_cpt_model_obj;
2950 2950
         $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration');
2951
-        $template                              = REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php';
2951
+        $template                              = REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php';
2952 2952
         EEH_Template::display_template($template, $this->_template_args);
2953 2953
     }
2954 2954
 
@@ -2962,7 +2962,7 @@  discard block
 block discarded – undo
2962 2962
     public function after_title_form_fields($post)
2963 2963
     {
2964 2964
         if ($post->post_type == 'espresso_attendees') {
2965
-            $template                  = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php';
2965
+            $template                  = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php';
2966 2966
             $template_args['attendee'] = $this->_cpt_model_obj;
2967 2967
             EEH_Template::display_template($template, $template_args);
2968 2968
         }
Please login to merge, or discard this patch.