Completed
Branch BUG-8698-ticket-sellouts (6f3040)
by
unknown
12:05 queued 10s
created
modules/ticket_selector/EED_Ticket_Selector.module.php 2 patches
Indentation   +1200 added lines, -1200 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,1211 +14,1211 @@  discard block
 block discarded – undo
14 14
 class EED_Ticket_Selector extends EED_Module
15 15
 {
16 16
 
17
-    const debug = false;    //	true false
18
-
19
-    /**
20
-     * event that ticket selector is being generated for
21
-     *
22
-     * @access protected
23
-     * @var \EE_Event
24
-     */
25
-    protected static $_event;
26
-
27
-    /**
28
-     * array of datetimes and the spaces available for them
29
-     *
30
-     * @access private
31
-     * @var array
32
-     */
33
-    private static $_available_spaces = array();
34
-
35
-    /**
36
-     * max attendees that can register for event at one time
37
-     *
38
-     * @access private
39
-     * @var int
40
-     */
41
-    private static $_max_atndz = EE_INF;
42
-
43
-
44
-
45
-    /**
46
-     * Used to flag when the ticket selector is being called from an external iframe.
47
-     *
48
-     * @var bool
49
-     */
50
-    protected static $_in_iframe = false;
51
-
52
-
53
-
54
-    /**
55
-     * @return EED_Ticket_Selector
56
-     */
57
-    public static function instance()
58
-    {
59
-        return parent::get_instance(__CLASS__);
60
-    }
61
-
62
-
63
-
64
-    protected function set_config()
65
-    {
66
-        $this->set_config_section('template_settings');
67
-        $this->set_config_class('EE_Ticket_Selector_Config');
68
-        $this->set_config_name('EED_Ticket_Selector');
69
-    }
70
-
71
-
72
-
73
-    /**
74
-     *    set_hooks - for hooking into EE Core, other modules, etc
75
-     *
76
-     * @access    public
77
-     * @return    void
78
-     */
79
-    public static function set_hooks()
80
-    {
81
-        // routing
82
-        EE_Config::register_route('iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector');
83
-        EE_Config::register_route('process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections');
84
-        EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections');
85
-        add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2);
86
-        add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1);
87
-        add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10);
88
-    }
89
-
90
-
91
-
92
-    /**
93
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
94
-     *
95
-     * @access    public
96
-     * @return    void
97
-     */
98
-    public static function set_hooks_admin()
99
-    {
100
-        add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2);
101
-        //add button for iframe code to event editor.
102
-        add_filter('get_sample_permalink_html', array('EED_Ticket_Selector', 'iframe_code_button'), 10, 2);
103
-        add_action('admin_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets_admin'), 10);
104
-    }
105
-
106
-
107
-
108
-    /**
109
-     *    set_definitions
110
-     *
111
-     * @access    public
112
-     * @return    void
113
-     */
114
-    public static function set_definitions()
115
-    {
116
-        define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
117
-        define('TICKET_SELECTOR_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS);
118
-        //if config is not set, initialize
119
-        //If config is not set, set it.
120
-        if (EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector === null) {
121
-            EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = new EE_Ticket_Selector_Config();
122
-        }
123
-        EE_Registry::$i18n_js_strings['ts_embed_iframe_title'] = __('Copy and Paste the following:', 'event_espresso');
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     *    gets the ball rolling
130
-     *
131
-     * @access public
132
-     * @param    WP $WP
133
-     * @return void
134
-     */
135
-    public function run($WP)
136
-    {
137
-    }
138
-
139
-
140
-
141
-    /**
142
-     * ticket_selector_iframe
143
-     *
144
-     * @access    public
145
-     * @return    void
146
-     * @throws \EE_Error
147
-     */
148
-    public function ticket_selector_iframe()
149
-    {
150
-        self::$_in_iframe = true;
151
-        /** @type EEM_Event $EEM_Event */
152
-        $EEM_Event = EE_Registry::instance()->load_model('Event');
153
-        $event = $EEM_Event->get_one_by_ID(
154
-            EE_Registry::instance()->REQ->get('event', 0)
155
-        );
156
-        EE_Registry::instance()->REQ->set_espresso_page(true);
157
-        $template_args['ticket_selector'] = EED_Ticket_Selector::display_ticket_selector($event);
158
-        $template_args['css'] = apply_filters(
159
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
160
-            array(
161
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_embed.css?ver=' . EVENT_ESPRESSO_VERSION,
162
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css?ver=' . EVENT_ESPRESSO_VERSION,
163
-                includes_url('css/dashicons.min.css?ver=' . $GLOBALS['wp_version']),
164
-                EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
165
-            )
166
-        );
167
-        EE_Registry::$i18n_js_strings['ticket_selector_iframe'] = true;
168
-        EE_Registry::$i18n_js_strings['EEDTicketSelectorMsg'] = esc_html__('Please choose at least one ticket before continuing.',
169
-            'event_espresso');
170
-        $template_args['eei18n'] = apply_filters(
171
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__eei18n_js_strings',
172
-            EE_Registry::localize_i18n_js_strings()
173
-        );
174
-        $template_args['js'] = apply_filters(
175
-            'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
176
-            array(
177
-                includes_url('js/jquery/jquery.js?ver=' . $GLOBALS['wp_version']),
178
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION,
179
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_iframe_embed.js?ver=' . EVENT_ESPRESSO_VERSION,
180
-            )
181
-        );
182
-        $template_args['notices'] = EEH_Template::display_template(
183
-            EE_TEMPLATES . 'espresso-ajax-notices.template.php',
184
-            array(),
185
-            true
186
-        );
187
-        EEH_Template::display_template(
188
-            TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart_iframe.template.php',
189
-            $template_args
190
-        );
191
-        exit;
192
-    }
193
-
194
-
195
-
196
-    /**
197
-     * Adds an iframe embed code button to the Event editor.
198
-     *
199
-     * @param string $permalink_string The current html string for the permalink section.
200
-     * @param int    $id               The post id for the event.
201
-     * @return string The new html string for the permalink area.
202
-     */
203
-    public static function iframe_code_button($permalink_string, $id )
204
-    {
205
-        //make sure this is ONLY when editing and the event id has been set.
206
-        if ( ! empty($id)) {
207
-            $post = get_post($id);
208
-            //if NOT event then let's get out.
209
-            if ($post->post_type !== 'espresso_events') {
210
-                return $permalink_string;
211
-            }
212
-            $permalink_string .= '<a id="js-ticket-selector-embed-trigger" class="button button-small" href="#"  tabindex="-1">'
213
-                                 . __('Embed', 'event_espresso')
214
-                                 . '</a> ';
215
-            $ticket_selector_url = add_query_arg(array('ticket_selector' => 'iframe', 'event' => $id), site_url());
216
-            $iframe_string = esc_html(
217
-                '<iframe src="' . $ticket_selector_url . '" width="100%" height="100%"></iframe>'
218
-            );
219
-            $permalink_string .= '
17
+	const debug = false;    //	true false
18
+
19
+	/**
20
+	 * event that ticket selector is being generated for
21
+	 *
22
+	 * @access protected
23
+	 * @var \EE_Event
24
+	 */
25
+	protected static $_event;
26
+
27
+	/**
28
+	 * array of datetimes and the spaces available for them
29
+	 *
30
+	 * @access private
31
+	 * @var array
32
+	 */
33
+	private static $_available_spaces = array();
34
+
35
+	/**
36
+	 * max attendees that can register for event at one time
37
+	 *
38
+	 * @access private
39
+	 * @var int
40
+	 */
41
+	private static $_max_atndz = EE_INF;
42
+
43
+
44
+
45
+	/**
46
+	 * Used to flag when the ticket selector is being called from an external iframe.
47
+	 *
48
+	 * @var bool
49
+	 */
50
+	protected static $_in_iframe = false;
51
+
52
+
53
+
54
+	/**
55
+	 * @return EED_Ticket_Selector
56
+	 */
57
+	public static function instance()
58
+	{
59
+		return parent::get_instance(__CLASS__);
60
+	}
61
+
62
+
63
+
64
+	protected function set_config()
65
+	{
66
+		$this->set_config_section('template_settings');
67
+		$this->set_config_class('EE_Ticket_Selector_Config');
68
+		$this->set_config_name('EED_Ticket_Selector');
69
+	}
70
+
71
+
72
+
73
+	/**
74
+	 *    set_hooks - for hooking into EE Core, other modules, etc
75
+	 *
76
+	 * @access    public
77
+	 * @return    void
78
+	 */
79
+	public static function set_hooks()
80
+	{
81
+		// routing
82
+		EE_Config::register_route('iframe', 'EED_Ticket_Selector', 'ticket_selector_iframe', 'ticket_selector');
83
+		EE_Config::register_route('process_ticket_selections', 'EED_Ticket_Selector', 'process_ticket_selections');
84
+		EE_Config::register_route('cancel_ticket_selections', 'EED_Ticket_Selector', 'cancel_ticket_selections');
85
+		add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2);
86
+		add_action('AHEE_event_details_header_bottom', array('EED_Ticket_Selector', 'display_ticket_selector'), 10, 1);
87
+		add_action('wp_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets'), 10);
88
+	}
89
+
90
+
91
+
92
+	/**
93
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
94
+	 *
95
+	 * @access    public
96
+	 * @return    void
97
+	 */
98
+	public static function set_hooks_admin()
99
+	{
100
+		add_action('wp_loaded', array('EED_Ticket_Selector', 'set_definitions'), 2);
101
+		//add button for iframe code to event editor.
102
+		add_filter('get_sample_permalink_html', array('EED_Ticket_Selector', 'iframe_code_button'), 10, 2);
103
+		add_action('admin_enqueue_scripts', array('EED_Ticket_Selector', 'load_tckt_slctr_assets_admin'), 10);
104
+	}
105
+
106
+
107
+
108
+	/**
109
+	 *    set_definitions
110
+	 *
111
+	 * @access    public
112
+	 * @return    void
113
+	 */
114
+	public static function set_definitions()
115
+	{
116
+		define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
117
+		define('TICKET_SELECTOR_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS);
118
+		//if config is not set, initialize
119
+		//If config is not set, set it.
120
+		if (EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector === null) {
121
+			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = new EE_Ticket_Selector_Config();
122
+		}
123
+		EE_Registry::$i18n_js_strings['ts_embed_iframe_title'] = __('Copy and Paste the following:', 'event_espresso');
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 *    gets the ball rolling
130
+	 *
131
+	 * @access public
132
+	 * @param    WP $WP
133
+	 * @return void
134
+	 */
135
+	public function run($WP)
136
+	{
137
+	}
138
+
139
+
140
+
141
+	/**
142
+	 * ticket_selector_iframe
143
+	 *
144
+	 * @access    public
145
+	 * @return    void
146
+	 * @throws \EE_Error
147
+	 */
148
+	public function ticket_selector_iframe()
149
+	{
150
+		self::$_in_iframe = true;
151
+		/** @type EEM_Event $EEM_Event */
152
+		$EEM_Event = EE_Registry::instance()->load_model('Event');
153
+		$event = $EEM_Event->get_one_by_ID(
154
+			EE_Registry::instance()->REQ->get('event', 0)
155
+		);
156
+		EE_Registry::instance()->REQ->set_espresso_page(true);
157
+		$template_args['ticket_selector'] = EED_Ticket_Selector::display_ticket_selector($event);
158
+		$template_args['css'] = apply_filters(
159
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
160
+			array(
161
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_embed.css?ver=' . EVENT_ESPRESSO_VERSION,
162
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css?ver=' . EVENT_ESPRESSO_VERSION,
163
+				includes_url('css/dashicons.min.css?ver=' . $GLOBALS['wp_version']),
164
+				EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
165
+			)
166
+		);
167
+		EE_Registry::$i18n_js_strings['ticket_selector_iframe'] = true;
168
+		EE_Registry::$i18n_js_strings['EEDTicketSelectorMsg'] = esc_html__('Please choose at least one ticket before continuing.',
169
+			'event_espresso');
170
+		$template_args['eei18n'] = apply_filters(
171
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__eei18n_js_strings',
172
+			EE_Registry::localize_i18n_js_strings()
173
+		);
174
+		$template_args['js'] = apply_filters(
175
+			'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
176
+			array(
177
+				includes_url('js/jquery/jquery.js?ver=' . $GLOBALS['wp_version']),
178
+				EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION,
179
+				TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_iframe_embed.js?ver=' . EVENT_ESPRESSO_VERSION,
180
+			)
181
+		);
182
+		$template_args['notices'] = EEH_Template::display_template(
183
+			EE_TEMPLATES . 'espresso-ajax-notices.template.php',
184
+			array(),
185
+			true
186
+		);
187
+		EEH_Template::display_template(
188
+			TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart_iframe.template.php',
189
+			$template_args
190
+		);
191
+		exit;
192
+	}
193
+
194
+
195
+
196
+	/**
197
+	 * Adds an iframe embed code button to the Event editor.
198
+	 *
199
+	 * @param string $permalink_string The current html string for the permalink section.
200
+	 * @param int    $id               The post id for the event.
201
+	 * @return string The new html string for the permalink area.
202
+	 */
203
+	public static function iframe_code_button($permalink_string, $id )
204
+	{
205
+		//make sure this is ONLY when editing and the event id has been set.
206
+		if ( ! empty($id)) {
207
+			$post = get_post($id);
208
+			//if NOT event then let's get out.
209
+			if ($post->post_type !== 'espresso_events') {
210
+				return $permalink_string;
211
+			}
212
+			$permalink_string .= '<a id="js-ticket-selector-embed-trigger" class="button button-small" href="#"  tabindex="-1">'
213
+								 . __('Embed', 'event_espresso')
214
+								 . '</a> ';
215
+			$ticket_selector_url = add_query_arg(array('ticket_selector' => 'iframe', 'event' => $id), site_url());
216
+			$iframe_string = esc_html(
217
+				'<iframe src="' . $ticket_selector_url . '" width="100%" height="100%"></iframe>'
218
+			);
219
+			$permalink_string .= '
220 220
 <div id="js-ts-iframe" style="display:none">
221 221
 	<div style="width:100%; height: 500px;">
222 222
 		' . $iframe_string . '
223 223
 	</div>
224 224
 </div>';
225
-        }
226
-        return $permalink_string;
227
-    }
228
-
229
-
230
-
231
-    /**
232
-     *    finds and sets the EE_Event object for use throughout class
233
-     *
234
-     * @access    public
235
-     * @param    mixed $event
236
-     * @return    bool
237
-     */
238
-    protected static function set_event($event = null)
239
-    {
240
-        if ($event === null) {
241
-            global $post;
242
-            $event = $post;
243
-        }
244
-        if ($event instanceof EE_Event) {
245
-            self::$_event = $event;
246
-        } else if ($event instanceof WP_Post ) {
247
-            if ( isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
248
-                self::$_event = $event->EE_Event;
249
-            } else if ( $event->post_type === 'espresso_events') {
250
-                $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
251
-                self::$_event = $event->EE_Event;
252
-            }
253
-        } else {
254
-            $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
255
-            $dev_msg = $user_msg
256
-                       . __('In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
257
-                    'event_espresso');
258
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
259
-            return false;
260
-        }
261
-        return true;
262
-    }
263
-
264
-
265
-
266
-    /**
267
-     * creates buttons for selecting number of attendees for an event
268
-     *
269
-     * @access public
270
-     * @param EE_Event $event
271
-     * @param bool     $view_details
272
-     * @return string
273
-     * @throws \EE_Error
274
-     */
275
-    public static function display_ticket_selector($event = null, $view_details = false)
276
-    {
277
-        // reset filter for displaying submit button
278
-        remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
279
-        // poke and prod incoming event till it tells us what it is
280
-        if ( ! EED_Ticket_Selector::set_event($event)) {
281
-            return false;
282
-        }
283
-        $event_post = self::$_event instanceof EE_Event ? self::$_event->ID() : $event;
284
-        // grab event status
285
-        $_event_active_status = self::$_event->get_active_status();
286
-        if (
287
-            ! is_admin()
288
-            && (
289
-                ! self::$_event->display_ticket_selector()
290
-                || $view_details
291
-                || post_password_required($event_post)
292
-                || (
293
-                    $_event_active_status !== EE_Datetime::active
294
-                    && $_event_active_status !== EE_Datetime::upcoming
295
-                    && $_event_active_status !== EE_Datetime::sold_out
296
-                    && ! (
297
-                        $_event_active_status === EE_Datetime::inactive
298
-                        && is_user_logged_in()
299
-                    )
300
-                )
301
-            )
302
-        ) {
303
-            return ! is_single() ? EED_Ticket_Selector::display_view_details_btn() : '';
304
-        }
305
-        $template_args = array();
306
-        $template_args['event_status'] = $_event_active_status;
307
-        $template_args['date_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
308
-            get_option('date_format'));
309
-        $template_args['time_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
310
-            get_option('time_format'));
311
-        $template_args['EVT_ID'] = self::$_event->ID();
312
-        $template_args['event'] = self::$_event;
313
-        // is the event expired ?
314
-        $template_args['event_is_expired'] = self::$_event->is_expired();
315
-        if ($template_args['event_is_expired']) {
316
-            return '<div class="ee-event-expired-notice"><span class="important-notice">'
317
-                   . __('We\'re sorry, but all tickets sales have ended because the event is expired.',
318
-                'event_espresso')
319
-                   . '</span></div>';
320
-        }
321
-        $ticket_query_args = array(
322
-            array('Datetime.EVT_ID' => self::$_event->ID()),
323
-            'order_by' => array(
324
-                'TKT_order'              => 'ASC',
325
-                'TKT_required'           => 'DESC',
326
-                'TKT_start_date'         => 'ASC',
327
-                'TKT_end_date'           => 'ASC',
328
-                'Datetime.DTT_EVT_start' => 'DESC',
329
-            ),
330
-        );
331
-        if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) {
332
-            //use the correct applicable time query depending on what version of core is being run.
333
-            $current_time = method_exists('EEM_Datetime', 'current_time_for_query') ? time()
334
-                : current_time('timestamp');
335
-            $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
336
-        }
337
-        // get all tickets for this event ordered by the datetime
338
-        $template_args['tickets'] = EEM_Ticket::instance()->get_all($ticket_query_args);
339
-        if (count($template_args['tickets']) < 1) {
340
-            return '<div class="ee-event-expired-notice"><span class="important-notice">'
341
-                   . __('We\'re sorry, but all ticket sales have ended.', 'event_espresso')
342
-                   . '</span></div>';
343
-        }
344
-        // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
345
-        \EED_Ticket_Selector::$_max_atndz = apply_filters(
346
-            'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
347
-            self::$_event->additional_limit()
348
-        );
349
-        $template_args['max_atndz'] = \EED_Ticket_Selector::$_max_atndz;
350
-        if ($template_args['max_atndz'] < 1) {
351
-            $sales_closed_msg = __('We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
352
-                'event_espresso');
353
-            if (current_user_can('edit_post', self::$_event->ID())) {
354
-                $sales_closed_msg .= sprintf(
355
-                    __('%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
356
-                        'event_espresso'),
357
-                    '<div class="ee-attention" style="text-align: left;"><b>',
358
-                    '</b><br />',
359
-                    $link = '<span class="edit-link"><a class="post-edit-link" href="'
360
-                            . get_edit_post_link(self::$_event->ID())
361
-                            . '">',
362
-                    '</a></span></div>'
363
-                );
364
-            }
365
-            return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
366
-        }
367
-        $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php';
368
-        $templates['ticket_selector'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__template_path',
369
-            $templates['ticket_selector'], self::$_event);
370
-        // redirecting to another site for registration ??
371
-        $external_url = self::$_event->external_url() !== null || self::$_event->external_url() !== ''
372
-            ? self::$_event->external_url() : false;
373
-        // if not redirecting to another site for registration
374
-        if ( ! $external_url) {
375
-            // then display the ticket selector
376
-            $ticket_selector = EEH_Template::locate_template($templates['ticket_selector'], $template_args);
377
-        } else {
378
-            // if not we still need to trigger the display of the submit button
379
-            add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
380
-            //display notice to admin that registration is external
381
-            $ticket_selector = ! is_admin() ? ''
382
-                : __('Registration is at an external URL for this event.', 'event_espresso');
383
-        }
384
-        // now set up the form (but not for the admin)
385
-        $ticket_selector = ! is_admin()
386
-            ? EED_Ticket_Selector::ticket_selector_form_open(
387
-                self::$_event->ID(),
388
-                $external_url
389
-            ) . $ticket_selector
390
-            : $ticket_selector;
391
-        // submit button and form close tag
392
-        $ticket_selector .= ! is_admin() ? EED_Ticket_Selector::display_ticket_selector_submit() : '';
393
-        // set no cache headers and constants
394
-        EE_System::do_not_cache();
395
-        return $ticket_selector;
396
-    }
397
-
398
-
399
-
400
-    /**
401
-     *    ticket_selector_form_open
402
-     *
403
-     * @access        public
404
-     * @param        int    $ID
405
-     * @param        string $external_url
406
-     * @return        string
407
-     */
408
-    public static function ticket_selector_form_open($ID = 0, $external_url = '')
409
-    {
410
-        // if redirecting, we don't need any anything else
411
-        if ($external_url) {
412
-            $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '">';
413
-            $query_args = (array)EEH_URL::get_query_string($external_url);
414
-            foreach ($query_args as $query_arg => $value) {
415
-                $html .= '
225
+		}
226
+		return $permalink_string;
227
+	}
228
+
229
+
230
+
231
+	/**
232
+	 *    finds and sets the EE_Event object for use throughout class
233
+	 *
234
+	 * @access    public
235
+	 * @param    mixed $event
236
+	 * @return    bool
237
+	 */
238
+	protected static function set_event($event = null)
239
+	{
240
+		if ($event === null) {
241
+			global $post;
242
+			$event = $post;
243
+		}
244
+		if ($event instanceof EE_Event) {
245
+			self::$_event = $event;
246
+		} else if ($event instanceof WP_Post ) {
247
+			if ( isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
248
+				self::$_event = $event->EE_Event;
249
+			} else if ( $event->post_type === 'espresso_events') {
250
+				$event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
251
+				self::$_event = $event->EE_Event;
252
+			}
253
+		} else {
254
+			$user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
255
+			$dev_msg = $user_msg
256
+					   . __('In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
257
+					'event_espresso');
258
+			EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
259
+			return false;
260
+		}
261
+		return true;
262
+	}
263
+
264
+
265
+
266
+	/**
267
+	 * creates buttons for selecting number of attendees for an event
268
+	 *
269
+	 * @access public
270
+	 * @param EE_Event $event
271
+	 * @param bool     $view_details
272
+	 * @return string
273
+	 * @throws \EE_Error
274
+	 */
275
+	public static function display_ticket_selector($event = null, $view_details = false)
276
+	{
277
+		// reset filter for displaying submit button
278
+		remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
279
+		// poke and prod incoming event till it tells us what it is
280
+		if ( ! EED_Ticket_Selector::set_event($event)) {
281
+			return false;
282
+		}
283
+		$event_post = self::$_event instanceof EE_Event ? self::$_event->ID() : $event;
284
+		// grab event status
285
+		$_event_active_status = self::$_event->get_active_status();
286
+		if (
287
+			! is_admin()
288
+			&& (
289
+				! self::$_event->display_ticket_selector()
290
+				|| $view_details
291
+				|| post_password_required($event_post)
292
+				|| (
293
+					$_event_active_status !== EE_Datetime::active
294
+					&& $_event_active_status !== EE_Datetime::upcoming
295
+					&& $_event_active_status !== EE_Datetime::sold_out
296
+					&& ! (
297
+						$_event_active_status === EE_Datetime::inactive
298
+						&& is_user_logged_in()
299
+					)
300
+				)
301
+			)
302
+		) {
303
+			return ! is_single() ? EED_Ticket_Selector::display_view_details_btn() : '';
304
+		}
305
+		$template_args = array();
306
+		$template_args['event_status'] = $_event_active_status;
307
+		$template_args['date_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__date_format',
308
+			get_option('date_format'));
309
+		$template_args['time_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__time_format',
310
+			get_option('time_format'));
311
+		$template_args['EVT_ID'] = self::$_event->ID();
312
+		$template_args['event'] = self::$_event;
313
+		// is the event expired ?
314
+		$template_args['event_is_expired'] = self::$_event->is_expired();
315
+		if ($template_args['event_is_expired']) {
316
+			return '<div class="ee-event-expired-notice"><span class="important-notice">'
317
+				   . __('We\'re sorry, but all tickets sales have ended because the event is expired.',
318
+				'event_espresso')
319
+				   . '</span></div>';
320
+		}
321
+		$ticket_query_args = array(
322
+			array('Datetime.EVT_ID' => self::$_event->ID()),
323
+			'order_by' => array(
324
+				'TKT_order'              => 'ASC',
325
+				'TKT_required'           => 'DESC',
326
+				'TKT_start_date'         => 'ASC',
327
+				'TKT_end_date'           => 'ASC',
328
+				'Datetime.DTT_EVT_start' => 'DESC',
329
+			),
330
+		);
331
+		if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) {
332
+			//use the correct applicable time query depending on what version of core is being run.
333
+			$current_time = method_exists('EEM_Datetime', 'current_time_for_query') ? time()
334
+				: current_time('timestamp');
335
+			$ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
336
+		}
337
+		// get all tickets for this event ordered by the datetime
338
+		$template_args['tickets'] = EEM_Ticket::instance()->get_all($ticket_query_args);
339
+		if (count($template_args['tickets']) < 1) {
340
+			return '<div class="ee-event-expired-notice"><span class="important-notice">'
341
+				   . __('We\'re sorry, but all ticket sales have ended.', 'event_espresso')
342
+				   . '</span></div>';
343
+		}
344
+		// filter the maximum qty that can appear in the Ticket Selector qty dropdowns
345
+		\EED_Ticket_Selector::$_max_atndz = apply_filters(
346
+			'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets',
347
+			self::$_event->additional_limit()
348
+		);
349
+		$template_args['max_atndz'] = \EED_Ticket_Selector::$_max_atndz;
350
+		if ($template_args['max_atndz'] < 1) {
351
+			$sales_closed_msg = __('We\'re sorry, but ticket sales have been closed at this time. Please check back again later.',
352
+				'event_espresso');
353
+			if (current_user_can('edit_post', self::$_event->ID())) {
354
+				$sales_closed_msg .= sprintf(
355
+					__('%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s',
356
+						'event_espresso'),
357
+					'<div class="ee-attention" style="text-align: left;"><b>',
358
+					'</b><br />',
359
+					$link = '<span class="edit-link"><a class="post-edit-link" href="'
360
+							. get_edit_post_link(self::$_event->ID())
361
+							. '">',
362
+					'</a></span></div>'
363
+				);
364
+			}
365
+			return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
366
+		}
367
+		$templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php';
368
+		$templates['ticket_selector'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__template_path',
369
+			$templates['ticket_selector'], self::$_event);
370
+		// redirecting to another site for registration ??
371
+		$external_url = self::$_event->external_url() !== null || self::$_event->external_url() !== ''
372
+			? self::$_event->external_url() : false;
373
+		// if not redirecting to another site for registration
374
+		if ( ! $external_url) {
375
+			// then display the ticket selector
376
+			$ticket_selector = EEH_Template::locate_template($templates['ticket_selector'], $template_args);
377
+		} else {
378
+			// if not we still need to trigger the display of the submit button
379
+			add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
380
+			//display notice to admin that registration is external
381
+			$ticket_selector = ! is_admin() ? ''
382
+				: __('Registration is at an external URL for this event.', 'event_espresso');
383
+		}
384
+		// now set up the form (but not for the admin)
385
+		$ticket_selector = ! is_admin()
386
+			? EED_Ticket_Selector::ticket_selector_form_open(
387
+				self::$_event->ID(),
388
+				$external_url
389
+			) . $ticket_selector
390
+			: $ticket_selector;
391
+		// submit button and form close tag
392
+		$ticket_selector .= ! is_admin() ? EED_Ticket_Selector::display_ticket_selector_submit() : '';
393
+		// set no cache headers and constants
394
+		EE_System::do_not_cache();
395
+		return $ticket_selector;
396
+	}
397
+
398
+
399
+
400
+	/**
401
+	 *    ticket_selector_form_open
402
+	 *
403
+	 * @access        public
404
+	 * @param        int    $ID
405
+	 * @param        string $external_url
406
+	 * @return        string
407
+	 */
408
+	public static function ticket_selector_form_open($ID = 0, $external_url = '')
409
+	{
410
+		// if redirecting, we don't need any anything else
411
+		if ($external_url) {
412
+			$html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '">';
413
+			$query_args = (array)EEH_URL::get_query_string($external_url);
414
+			foreach ($query_args as $query_arg => $value) {
415
+				$html .= '
416 416
 				<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
417
-            }
418
-            return $html;
419
-        }
420
-        // if there is no submit button, then don't start building a form
421
-        // because the "View Details" button will build its own form
422
-        if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
423
-            return '';
424
-        }
425
-        $checkout_url = EEH_Event_View::event_link_url($ID);
426
-        if ( ! $checkout_url) {
427
-            EE_Error::add_error(__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
428
-                __FILE__, __FUNCTION__, __LINE__);
429
-        }
430
-        $extra_params = self::$_in_iframe ? ' target="_blank"' : '';
431
-        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
432
-        $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false);
433
-        $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
434
-        $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, self::$_event);
435
-        return $html;
436
-    }
437
-
438
-
439
-
440
-    /**
441
-     *    display_ticket_selector_submit
442
-     *
443
-     * @access        public
444
-     * @access        public
445
-     * @return        string
446
-     * @throws \EE_Error
447
-     */
448
-    public static function display_ticket_selector_submit()
449
-    {
450
-        $html = '';
451
-        if ( ! is_admin()) {
452
-            // standard TS displayed with submit button, ie: "Register Now"
453
-            if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
454
-                $html .= \EED_Ticket_Selector::display_register_now_button();
455
-                $html .= empty($external_url) ?
456
-                    \EED_Ticket_Selector::no_tkt_slctr_end_dv()
457
-                    : \EED_Ticket_Selector::clear_tkt_slctr();
458
-                $html .= '<br/>' . \EED_Ticket_Selector::ticket_selector_form_close();
459
-            } else if ( EED_Ticket_Selector::$_max_atndz === 1 ) {
460
-                // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
461
-                if ( EED_Ticket_Selector::$_event->is_sold_out() ) {
462
-                    // then instead of a View Details or Submit button, just display a "Sold Out" message
463
-                    $html .= apply_filters(
464
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
465
-                        sprintf(
466
-                            __(
467
-                                '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
468
-                                'event_espresso'
469
-                            ),
470
-                            '<p class="no-ticket-selector-msg clear-float">',
471
-                            EED_Ticket_Selector::$_event->name(),
472
-                            '</p>',
473
-                            '<br />'
474
-                        ),
475
-                        EED_Ticket_Selector::$_event
476
-                    );
477
-                    if (
478
-                        apply_filters(
479
-                            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
480
-                            false,
481
-                            EED_Ticket_Selector::$_event
482
-                        )
483
-                    ) {
484
-                        $html .= \EED_Ticket_Selector::display_register_now_button();
485
-                    }
486
-                    // sold out DWMTS event, no TS, no submit or view details button, but has additional content
487
-                    $html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv();
488
-                } else if (
489
-                    apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
490
-                    && ! is_single()
491
-                ) {
492
-                    // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
493
-                    // but no tickets are available, so display event's "View Details" button.
494
-                    // it is being viewed via somewhere other than a single post
495
-                    $html .= EED_Ticket_Selector::display_view_details_btn(true);
496
-                }
497
-            } else if (is_archive()) {
498
-                // event list, no tickets available so display event's "View Details" button
499
-                $html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv();
500
-                $html .= EED_Ticket_Selector::display_view_details_btn();
501
-            } else {
502
-                if (
503
-                    apply_filters(
504
-                        'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
505
-                        false,
506
-                        EED_Ticket_Selector::$_event
507
-                    )
508
-                ) {
509
-                    $html .= \EED_Ticket_Selector::display_register_now_button();
510
-                }
511
-                // no submit or view details button, and no additional content
512
-                $html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv();
513
-            }
514
-            if ( ! is_archive()) {
515
-                $html .= \EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
516
-            }
517
-        }
518
-        return $html;
519
-    }
520
-
521
-
522
-
523
-    /**
524
-     * @return string
525
-     */
526
-    public static function clear_tkt_slctr()
527
-    {
528
-        // standard TS displayed, appears after a "Register Now" or "view Details" button
529
-        return '<div class="clear"></div>';
530
-    }
531
-
532
-
533
-
534
-    /**
535
-     * @deprecated 4.9.13
536
-     * @return string
537
-     */
538
-    public static function tkt_slctr_end_dv()
539
-    {
540
-        return \EED_Ticket_Selector::clear_tkt_slctr();
541
-    }
542
-
543
-
544
-
545
-    /**
546
-     * @return string
547
-     */
548
-    public static function no_tkt_slctr_end_dv()
549
-    {
550
-        // DWMTS event, no TS, appears after a "Register Now" or "view Details" button
551
-        return '<div class="clear"></div></div>';
552
-    }
553
-
554
-
555
-
556
-    /**
557
-     *    ticket_selector_form_close
558
-     *
559
-     * @access        public
560
-     * @access        public
561
-     * @return        string
562
-     */
563
-    public static function ticket_selector_form_close()
564
-    {
565
-        return '</form>';
566
-    }
567
-
568
-
569
-
570
-    /**
571
-     * @return string
572
-     * @throws \EE_Error
573
-     */
574
-    public static function display_register_now_button()
575
-    {
576
-        $btn_text = apply_filters(
577
-            'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
578
-            __('Register Now', 'event_espresso'),
579
-            EED_Ticket_Selector::$_event
580
-        );
581
-        $external_url = EED_Ticket_Selector::$_event->external_url();
582
-        $html = '<input id="ticket-selector-submit-' . EED_Ticket_Selector::$_event->ID() . '-btn"';
583
-        $html .= ' class="ticket-selector-submit-btn ';
584
-        $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
585
-        $html .= ' type="submit" value="' . $btn_text . '" />';
586
-        $html .= apply_filters(
587
-            'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
588
-            '',
589
-            EED_Ticket_Selector::$_event
590
-        );
591
-        return $html;
592
-    }
593
-
594
-
595
-    /**
596
-     * display_view_details_btn
597
-     *
598
-     * @access public
599
-     * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
600
-     *                    (ie: $_max_atndz === 1) where there are no available tickets,
601
-     *                    either because they are sold out, expired, or not yet on sale.
602
-     *                    In this case, we need to close the form BEFORE adding any closing divs
603
-     * @return string
604
-     * @throws \EE_Error
605
-     */
606
-    public static function display_view_details_btn($DWMTS = false)
607
-    {
608
-        if ( ! self::$_event->get_permalink()) {
609
-            EE_Error::add_error(
610
-                __('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
611
-                __FILE__, __FUNCTION__, __LINE__
612
-            );
613
-        }
614
-        $view_details_btn = '<form method="POST" action="';
615
-        $view_details_btn .= apply_filters(
616
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
617
-            self::$_event->get_permalink(),
618
-            self::$_event
619
-        );
620
-        $view_details_btn .= '">';
621
-        $btn_text = apply_filters(
622
-            'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
623
-            __('View Details', 'event_espresso'),
624
-            self::$_event
625
-        );
626
-        $view_details_btn .= '<input id="ticket-selector-submit-'
627
-                             . self::$_event->ID()
628
-                             . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
629
-                             . $btn_text
630
-                             . '" />';
631
-        $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', self::$_event);
632
-        if ($DWMTS) {
633
-            $view_details_btn .= \EED_Ticket_Selector::ticket_selector_form_close();
634
-            $view_details_btn .= \EED_Ticket_Selector::no_tkt_slctr_end_dv();
635
-            $view_details_btn .= '<br/>';
636
-        } else {
637
-            $view_details_btn .= \EED_Ticket_Selector::clear_tkt_slctr();
638
-            $view_details_btn .= '<br/>';
639
-            $view_details_btn .= \EED_Ticket_Selector::ticket_selector_form_close();
640
-        }
641
-        return $view_details_btn;
642
-    }
643
-
644
-
645
-
646
-    /**
647
-     *    cancel_ticket_selections
648
-     *
649
-     * @access        public
650
-     * @access        public
651
-     * @return        string
652
-     */
653
-    public static function cancel_ticket_selections()
654
-    {
655
-        // check nonce
656
-        if ( ! EED_Ticket_Selector::process_ticket_selector_nonce('cancel_ticket_selections')) {
657
-            return false;
658
-        }
659
-        EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
660
-        if (EE_Registry::instance()->REQ->is_set('event_id')) {
661
-            wp_safe_redirect(
662
-                EEH_Event_View::event_link_url(
663
-                    EE_Registry::instance()->REQ->get('event_id')
664
-                )
665
-            );
666
-        } else {
667
-            wp_safe_redirect(
668
-                site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/')
669
-            );
670
-        }
671
-        die();
672
-    }
673
-
674
-
675
-
676
-    /**
677
-     *    process_ticket_selector_nonce
678
-     *
679
-     * @access public
680
-     * @param  string $nonce_name
681
-     * @param string  $id
682
-     * @return bool
683
-     */
684
-    public static function process_ticket_selector_nonce($nonce_name, $id = '')
685
-    {
686
-        $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
687
-        if (
688
-            ! is_admin()
689
-            && (
690
-                ! EE_Registry::instance()->REQ->is_set($nonce_name_with_id)
691
-                || ! wp_verify_nonce(
692
-                    EE_Registry::instance()->REQ->get($nonce_name_with_id),
693
-                    $nonce_name
694
-                )
695
-            )
696
-        ) {
697
-            EE_Error::add_error(
698
-                sprintf(
699
-                    __(
700
-                        'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
701
-                        'event_espresso'
702
-                    ),
703
-                    '<br/>'
704
-                ),
705
-                __FILE__,
706
-                __FUNCTION__,
707
-                __LINE__
708
-            );
709
-            return false;
710
-        }
711
-        return true;
712
-    }
713
-
714
-
715
-
716
-    /**
717
-     *    process_ticket_selections
718
-     *
719
-     * @access public
720
-     * @return array|boolean
721
-     * @throws \EE_Error
722
-     */
723
-    public function process_ticket_selections()
724
-    {
725
-        do_action('EED_Ticket_Selector__process_ticket_selections__before');
726
-        // do we have an event id?
727
-        if ( ! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) {
728
-            // $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
729
-            EE_Error::add_error(
730
-                sprintf(
731
-                    __(
732
-                        'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
733
-                        'event_espresso'
734
-                    ),
735
-                    '<br/>'
736
-                ),
737
-                __FILE__,
738
-                __FUNCTION__,
739
-                __LINE__
740
-            );
741
-        }
742
-        //if event id is valid
743
-        $id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id'));
744
-        // check nonce
745
-        if ( ! EED_Ticket_Selector::process_ticket_selector_nonce('process_ticket_selections', $id)) {
746
-            return false;
747
-        }
748
-        //		d( EE_Registry::instance()->REQ );
749
-        self::$_available_spaces = array(
750
-            'tickets'   => array(),
751
-            'datetimes' => array(),
752
-        );
753
-        //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart.
754
-        // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc.
755
-        EE_Registry::instance()->load_core('Session');
756
-        // unless otherwise requested, clear the session
757
-        if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
758
-            EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
759
-        }
760
-        //d( EE_Registry::instance()->SSN );
761
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
762
-        // validate/sanitize data
763
-        $valid = self::_validate_post_data($id);
764
-        //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
765
-        //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ );
766
-        //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ );
767
-        //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ );
768
-        //check total tickets ordered vs max number of attendees that can register
769
-        if ($valid['total_tickets'] > $valid['max_atndz']) {
770
-            // ordering too many tickets !!!
771
-            $total_tickets_string = _n('You have attempted to purchase %s ticket.',
772
-                'You have attempted to purchase %s tickets.', $valid['total_tickets'], 'event_espresso');
773
-            $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
774
-            // dev only message
775
-            $max_atndz_string = _n('The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
776
-                'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
777
-                $valid['max_atndz'], 'event_espresso');
778
-            $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']);
779
-            EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
780
-        } else {
781
-            // all data appears to be valid
782
-            $tckts_slctd = false;
783
-            $tickets_added = 0;
784
-            $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid);
785
-            if ($valid['total_tickets'] > 0) {
786
-                // load cart
787
-                EE_Registry::instance()->load_core('Cart');
788
-                // cycle thru the number of data rows sent from the event listing
789
-                for ($x = 0; $x < $valid['rows']; $x++) {
790
-                    // does this row actually contain a ticket quantity?
791
-                    if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
792
-                        // YES we have a ticket quantity
793
-                        $tckts_slctd = true;
794
-                        //						d( $valid['ticket_obj'][$x] );
795
-                        if ($valid['ticket_obj'][$x] instanceof EE_Ticket) {
796
-                            // then add ticket to cart
797
-                            $tickets_added += self::_add_ticket_to_cart($valid['ticket_obj'][$x], $valid['qty'][$x]);
798
-                            if (EE_Error::has_error()) {
799
-                                break;
800
-                            }
801
-                        } else {
802
-                            // nothing added to cart retrieved
803
-                            EE_Error::add_error(
804
-                                sprintf(__('A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
805
-                                    'event_espresso'), '<br/>'),
806
-                                __FILE__, __FUNCTION__, __LINE__
807
-                            );
808
-                        }
809
-                    }
810
-                }
811
-            }
812
-            do_action(
813
-                'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
814
-                EE_Registry::instance()->CART,
815
-                $this
816
-            );
817
-            //d( EE_Registry::instance()->CART );
818
-            //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
819
-            if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) {
820
-                if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
821
-                    do_action(
822
-                        'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
823
-                        EE_Registry::instance()->CART,
824
-                        $this
825
-                    );
826
-                    EE_Registry::instance()->CART->recalculate_all_cart_totals();
827
-                    EE_Registry::instance()->CART->save_cart(false);
828
-                    // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE
829
-                    // just return TRUE for registrations being made from admin
830
-                    if (is_admin()) {
831
-                        return true;
832
-                    }
833
-                    EE_Error::get_notices(false, true);
834
-                    wp_safe_redirect(
835
-                        apply_filters(
836
-                            'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
837
-                            EE_Registry::instance()->CFG->core->reg_page_url()
838
-                        )
839
-                    );
840
-                    exit();
841
-                } else {
842
-                    if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
843
-                        // nothing added to cart
844
-                        EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), __FILE__,
845
-                            __FUNCTION__, __LINE__);
846
-                    }
847
-                }
848
-            } else {
849
-                // no ticket quantities were selected
850
-                EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.',
851
-                    'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
852
-            }
853
-        }
854
-        //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
855
-        // at this point, just return if registration is being made from admin
856
-        if (is_admin()) {
857
-            return false;
858
-        }
859
-        if ($valid['return_url']) {
860
-            EE_Error::get_notices(false, true);
861
-            wp_safe_redirect($valid['return_url']);
862
-            exit();
863
-        } elseif (isset($event_to_add['id'])) {
864
-            EE_Error::get_notices(false, true);
865
-            wp_safe_redirect(get_permalink($event_to_add['id']));
866
-            exit();
867
-        } else {
868
-            echo EE_Error::get_notices();
869
-        }
870
-        return false;
871
-    }
872
-
873
-
874
-
875
-    /**
876
-     *    validate_post_data
877
-     *
878
-     * @access        private
879
-     * @param int $id
880
-     * @return array|FALSE
881
-     */
882
-    private static function _validate_post_data($id = 0)
883
-    {
884
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
885
-        if ( ! $id) {
886
-            EE_Error::add_error(
887
-                __('The event id provided was not valid.', 'event_espresso'),
888
-                __FILE__,
889
-                __FUNCTION__,
890
-                __LINE__
891
-            );
892
-            return false;
893
-        }
894
-        // start with an empty array()
895
-        $valid_data = array();
896
-        // grab valid id
897
-        $valid_data['id'] = $id;
898
-        // grab and sanitize return-url
899
-        $valid_data['return_url'] = esc_url_raw(EE_Registry::instance()->REQ->get('tkt-slctr-return-url-' . $id));
900
-        // array of other form names
901
-        $inputs_to_clean = array(
902
-            'event_id'   => 'tkt-slctr-event-id',
903
-            'max_atndz'  => 'tkt-slctr-max-atndz-',
904
-            'rows'       => 'tkt-slctr-rows-',
905
-            'qty'        => 'tkt-slctr-qty-',
906
-            'ticket_id'  => 'tkt-slctr-ticket-id-',
907
-            'return_url' => 'tkt-slctr-return-url-',
908
-        );
909
-        // let's track the total number of tickets ordered.'
910
-        $valid_data['total_tickets'] = 0;
911
-        // cycle through $inputs_to_clean array
912
-        foreach ($inputs_to_clean as $what => $input_to_clean) {
913
-            // check for POST data
914
-            if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) {
915
-                // grab value
916
-                $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id);
917
-                switch ($what) {
918
-                    // integers
919
-                    case 'event_id':
920
-                        $valid_data[$what] = absint($input_value);
921
-                        // get event via the event id we put in the form
922
-                        $valid_data['event'] = EE_Registry::instance()
923
-                                                          ->load_model('Event')
924
-                                                          ->get_one_by_ID($valid_data['event_id']);
925
-                        break;
926
-                    case 'rows':
927
-                    case 'max_atndz':
928
-                        $valid_data[$what] = absint($input_value);
929
-                        break;
930
-                    // arrays of integers
931
-                    case 'qty':
932
-                        /** @var array $row_qty */
933
-                        $row_qty = $input_value;
934
-                        // if qty is coming from a radio button input, then we need to assemble an array of rows
935
-                        if ( ! is_array($row_qty)) {
936
-                            // get number of rows
937
-                            $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id)
938
-                                ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id))
939
-                                : 1;
940
-                            // explode ints by the dash
941
-                            $row_qty = explode('-', $row_qty);
942
-                            $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
943
-                            $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
944
-                            $row_qty = array($row => $qty);
945
-                            //								 d( $row_qty );
946
-                            for ($x = 1; $x <= $rows; $x++) {
947
-                                if ( ! isset($row_qty[$x])) {
948
-                                    $row_qty[$x] = 0;
949
-                                }
950
-                            }
951
-                        }
952
-                        ksort($row_qty);
953
-                        //							 d( $row_qty );
954
-                        // cycle thru values
955
-                        foreach ($row_qty as $qty) {
956
-                            $qty = absint($qty);
957
-                            // sanitize as integers
958
-                            $valid_data[$what][] = $qty;
959
-                            $valid_data['total_tickets'] += $qty;
960
-                        }
961
-                        break;
962
-                    // array of integers
963
-                    case 'ticket_id':
964
-                        $value_array = array();
965
-                        // cycle thru values
966
-                        foreach ((array)$input_value as $key => $value) {
967
-                            // allow only numbers, letters,  spaces, commas and dashes
968
-                            $value_array[$key] = wp_strip_all_tags($value);
969
-                            // get ticket via the ticket id we put in the form
970
-                            $ticket_obj = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value);
971
-                            $valid_data['ticket_obj'][$key] = $ticket_obj;
972
-                        }
973
-                        $valid_data[$what] = $value_array;
974
-                        break;
975
-                    case 'return_url' :
976
-                        // grab and sanitize return-url
977
-                        $valid_data[$what] = esc_url_raw($input_value);
978
-                        break;
979
-                }    // end switch $what
980
-            }
981
-        }    // end foreach $inputs_to_clean
982
-        //		d( $valid_data );
983
-        //		die();
984
-        return $valid_data;
985
-    }
986
-
987
-
988
-
989
-    /**
990
-     *    adds a ticket to the cart
991
-     *
992
-     * @access   private
993
-     * @param EE_Ticket $ticket
994
-     * @param int       $qty
995
-     * @return TRUE on success, FALSE on fail
996
-     * @throws \EE_Error
997
-     */
998
-    private static function _add_ticket_to_cart(EE_Ticket $ticket = null, $qty = 1)
999
-    {
1000
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1001
-        // get the number of spaces left for this datetime ticket
1002
-        $available_spaces = self::_ticket_datetime_availability($ticket);
1003
-        // compare available spaces against the number of tickets being purchased
1004
-        if ($available_spaces >= $qty) {
1005
-            // allow addons to prevent a ticket from being added to cart
1006
-            if ( ! apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', true, $ticket,
1007
-                $qty, $available_spaces)
1008
-            ) {
1009
-                return false;
1010
-            }
1011
-            $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
1012
-            // add event to cart
1013
-            if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) {
1014
-                self::_recalculate_ticket_datetime_availability($ticket, $qty);
1015
-                return true;
1016
-            } else {
1017
-                return false;
1018
-            }
1019
-        } else {
1020
-            // tickets can not be purchased but let's find the exact number left for the last ticket selected PRIOR to subtracting tickets
1021
-            $available_spaces = self::_ticket_datetime_availability($ticket, true);
1022
-            // greedy greedy greedy eh?
1023
-            if ($available_spaces > 0) {
1024
-                if (
1025
-                apply_filters(
1026
-                    'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error',
1027
-                    true,
1028
-                    $ticket,
1029
-                    $qty,
1030
-                    $available_spaces
1031
-                )
1032
-                ) {
1033
-                    EED_Ticket_Selector::_display_availability_error($available_spaces);
1034
-                }
1035
-            } else {
1036
-                EE_Error::add_error(
1037
-                    __('We\'re sorry, but there are no available spaces left for this event at this particular date and time.',
1038
-                        'event_espresso'),
1039
-                    __FILE__, __FUNCTION__, __LINE__
1040
-                );
1041
-            }
1042
-            return false;
1043
-        }
1044
-    }
1045
-
1046
-
1047
-
1048
-    /**
1049
-     *  _display_availability_error
1050
-     *
1051
-     * @access    private
1052
-     * @param int $available_spaces
1053
-     * @throws \EE_Error
1054
-     */
1055
-    private static function _display_availability_error($available_spaces = 1)
1056
-    {
1057
-        // add error messaging - we're using the _n function that will generate
1058
-        // the appropriate singular or plural message based on the number of $available_spaces
1059
-        if (EE_Registry::instance()->CART->all_ticket_quantity_count()) {
1060
-            $msg = sprintf(
1061
-                _n(
1062
-                    'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
1063
-                    'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
1064
-                    $available_spaces,
1065
-                    'event_espresso'
1066
-                ),
1067
-                $available_spaces,
1068
-                '<br />'
1069
-            );
1070
-        } else {
1071
-            $msg = sprintf(
1072
-                _n(
1073
-                    'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
1074
-                    'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
1075
-                    $available_spaces,
1076
-                    'event_espresso'
1077
-                ),
1078
-                $available_spaces,
1079
-                '<br />'
1080
-            );
1081
-        }
1082
-        EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1083
-    }
1084
-
1085
-
1086
-
1087
-    /**
1088
-     * _ticket_datetime_availability
1089
-     * creates an array of tickets plus all of the datetimes available to each ticket
1090
-     * and tracks the spaces remaining for each of those datetimes
1091
-     *
1092
-     * @access private
1093
-     * @param EE_Ticket $ticket - selected ticket
1094
-     * @param bool      $get_original_ticket_spaces
1095
-     * @return int
1096
-     * @throws \EE_Error
1097
-     */
1098
-    private static function _ticket_datetime_availability(EE_Ticket $ticket, $get_original_ticket_spaces = false)
1099
-    {
1100
-        // if the $_available_spaces array has not been set up yet...
1101
-        if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
1102
-            self::_set_initial_ticket_datetime_availability($ticket);
1103
-        }
1104
-        $available_spaces = $ticket->qty() - $ticket->sold();
1105
-        if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
1106
-            // loop thru tickets, which will ALSO include individual ticket records AND a total
1107
-            foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
1108
-                // if we want the original datetime availability BEFORE we started subtracting tickets ?
1109
-                if ($get_original_ticket_spaces) {
1110
-                    // then grab the available spaces from the "tickets" array and compare with the above to get the lowest number
1111
-                    $available_spaces = min($available_spaces,
1112
-                        self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID]);
1113
-                } else {
1114
-                    // we want the updated ticket availability as stored in the "datetimes" array
1115
-                    $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]);
1116
-                }
1117
-            }
1118
-        }
1119
-        return $available_spaces;
1120
-    }
1121
-
1122
-
1123
-
1124
-    /**
1125
-     * _set_initial_ticket_datetime_availability
1126
-     *
1127
-     * @access private
1128
-     * @param EE_Ticket $ticket
1129
-     * @return void
1130
-     * @throws \EE_Error
1131
-     */
1132
-    private static function _set_initial_ticket_datetime_availability(EE_Ticket $ticket)
1133
-    {
1134
-        // first, get all of the datetimes that are available to this ticket
1135
-        $datetimes = $ticket->get_many_related(
1136
-            'Datetime',
1137
-            array(
1138
-                array(
1139
-                    'DTT_EVT_end' => array(
1140
-                        '>=',
1141
-                        EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
1142
-                    ),
1143
-                ),
1144
-                'order_by' => array('DTT_EVT_start' => 'ASC'),
1145
-            )
1146
-        );
1147
-        if ( ! empty($datetimes)) {
1148
-            // now loop thru all of the datetimes
1149
-            foreach ($datetimes as $datetime) {
1150
-                if ($datetime instanceof EE_Datetime) {
1151
-                    // the number of spaces available for the datetime without considering individual ticket quantities
1152
-                    $spaces_remaining = $datetime->spaces_remaining();
1153
-                    // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold or the datetime spaces remaining) to this ticket using the datetime ID as the key
1154
-                    self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min(
1155
-                        $ticket->qty() - $ticket->sold(),
1156
-                        $spaces_remaining
1157
-                    );
1158
-                    // if the remaining spaces for this datetime is already set, then compare that against the datetime spaces remaining, and take the lowest number,
1159
-                    // else just take the datetime spaces remaining, and assign to the datetimes array
1160
-                    self::$_available_spaces['datetimes'][$datetime->ID()] = isset(self::$_available_spaces['datetimes'][$datetime->ID()])
1161
-                        ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining)
1162
-                        : $spaces_remaining;
1163
-                }
1164
-            }
1165
-        }
1166
-    }
1167
-
1168
-
1169
-
1170
-    /**
1171
-     *    _recalculate_ticket_datetime_availability
1172
-     *
1173
-     * @access    private
1174
-     * @param    EE_Ticket $ticket
1175
-     * @param    int       $qty
1176
-     * @return    void
1177
-     */
1178
-    private static function _recalculate_ticket_datetime_availability(EE_Ticket $ticket, $qty = 0)
1179
-    {
1180
-        if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
1181
-            // loop thru tickets, which will ALSO include individual ticket records AND a total
1182
-            foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
1183
-                // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to,
1184
-                self::$_available_spaces['datetimes'][$DTD_ID] -= $qty;
1185
-            }
1186
-        }
1187
-    }
1188
-
1189
-
1190
-
1191
-    /**
1192
-     *    load js
1193
-     *
1194
-     * @access        public
1195
-     * @return        void
1196
-     */
1197
-    public static function load_tckt_slctr_assets()
1198
-    {
1199
-        // add some style
1200
-        if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) {
1201
-            wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css');
1202
-            wp_enqueue_style('ticket_selector');
1203
-            // make it dance
1204
-            // wp_register_script('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', array('espresso_core'), '', TRUE);
1205
-            // wp_enqueue_script('ticket_selector');
1206
-        }
1207
-    }
1208
-
1209
-
1210
-
1211
-    public static function load_tckt_slctr_assets_admin()
1212
-    {
1213
-        //iframe button js on admin event editor page
1214
-        if (EE_Registry::instance()->REQ->get('page') === 'espresso_events'
1215
-            && EE_Registry::instance()->REQ->get('action') === 'edit'
1216
-        ) {
1217
-            wp_register_script('ticket_selector_embed', TICKET_SELECTOR_ASSETS_URL . 'ticket-selector-embed.js',
1218
-                array('ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1219
-            wp_enqueue_script('ticket_selector_embed');
1220
-        }
1221
-    }
417
+			}
418
+			return $html;
419
+		}
420
+		// if there is no submit button, then don't start building a form
421
+		// because the "View Details" button will build its own form
422
+		if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
423
+			return '';
424
+		}
425
+		$checkout_url = EEH_Event_View::event_link_url($ID);
426
+		if ( ! $checkout_url) {
427
+			EE_Error::add_error(__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
428
+				__FILE__, __FUNCTION__, __LINE__);
429
+		}
430
+		$extra_params = self::$_in_iframe ? ' target="_blank"' : '';
431
+		$html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
432
+		$html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false);
433
+		$html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
434
+		$html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, self::$_event);
435
+		return $html;
436
+	}
437
+
438
+
439
+
440
+	/**
441
+	 *    display_ticket_selector_submit
442
+	 *
443
+	 * @access        public
444
+	 * @access        public
445
+	 * @return        string
446
+	 * @throws \EE_Error
447
+	 */
448
+	public static function display_ticket_selector_submit()
449
+	{
450
+		$html = '';
451
+		if ( ! is_admin()) {
452
+			// standard TS displayed with submit button, ie: "Register Now"
453
+			if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) {
454
+				$html .= \EED_Ticket_Selector::display_register_now_button();
455
+				$html .= empty($external_url) ?
456
+					\EED_Ticket_Selector::no_tkt_slctr_end_dv()
457
+					: \EED_Ticket_Selector::clear_tkt_slctr();
458
+				$html .= '<br/>' . \EED_Ticket_Selector::ticket_selector_form_close();
459
+			} else if ( EED_Ticket_Selector::$_max_atndz === 1 ) {
460
+				// its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
461
+				if ( EED_Ticket_Selector::$_event->is_sold_out() ) {
462
+					// then instead of a View Details or Submit button, just display a "Sold Out" message
463
+					$html .= apply_filters(
464
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
465
+						sprintf(
466
+							__(
467
+								'%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s',
468
+								'event_espresso'
469
+							),
470
+							'<p class="no-ticket-selector-msg clear-float">',
471
+							EED_Ticket_Selector::$_event->name(),
472
+							'</p>',
473
+							'<br />'
474
+						),
475
+						EED_Ticket_Selector::$_event
476
+					);
477
+					if (
478
+						apply_filters(
479
+							'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
480
+							false,
481
+							EED_Ticket_Selector::$_event
482
+						)
483
+					) {
484
+						$html .= \EED_Ticket_Selector::display_register_now_button();
485
+					}
486
+					// sold out DWMTS event, no TS, no submit or view details button, but has additional content
487
+					$html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv();
488
+				} else if (
489
+					apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false)
490
+					&& ! is_single()
491
+				) {
492
+					// this is a "Dude Where's my Ticket Selector?" (DWMTS) type event,
493
+					// but no tickets are available, so display event's "View Details" button.
494
+					// it is being viewed via somewhere other than a single post
495
+					$html .= EED_Ticket_Selector::display_view_details_btn(true);
496
+				}
497
+			} else if (is_archive()) {
498
+				// event list, no tickets available so display event's "View Details" button
499
+				$html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv();
500
+				$html .= EED_Ticket_Selector::display_view_details_btn();
501
+			} else {
502
+				if (
503
+					apply_filters(
504
+						'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button',
505
+						false,
506
+						EED_Ticket_Selector::$_event
507
+					)
508
+				) {
509
+					$html .= \EED_Ticket_Selector::display_register_now_button();
510
+				}
511
+				// no submit or view details button, and no additional content
512
+				$html .= \EED_Ticket_Selector::no_tkt_slctr_end_dv();
513
+			}
514
+			if ( ! is_archive()) {
515
+				$html .= \EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector'));
516
+			}
517
+		}
518
+		return $html;
519
+	}
520
+
521
+
522
+
523
+	/**
524
+	 * @return string
525
+	 */
526
+	public static function clear_tkt_slctr()
527
+	{
528
+		// standard TS displayed, appears after a "Register Now" or "view Details" button
529
+		return '<div class="clear"></div>';
530
+	}
531
+
532
+
533
+
534
+	/**
535
+	 * @deprecated 4.9.13
536
+	 * @return string
537
+	 */
538
+	public static function tkt_slctr_end_dv()
539
+	{
540
+		return \EED_Ticket_Selector::clear_tkt_slctr();
541
+	}
542
+
543
+
544
+
545
+	/**
546
+	 * @return string
547
+	 */
548
+	public static function no_tkt_slctr_end_dv()
549
+	{
550
+		// DWMTS event, no TS, appears after a "Register Now" or "view Details" button
551
+		return '<div class="clear"></div></div>';
552
+	}
553
+
554
+
555
+
556
+	/**
557
+	 *    ticket_selector_form_close
558
+	 *
559
+	 * @access        public
560
+	 * @access        public
561
+	 * @return        string
562
+	 */
563
+	public static function ticket_selector_form_close()
564
+	{
565
+		return '</form>';
566
+	}
567
+
568
+
569
+
570
+	/**
571
+	 * @return string
572
+	 * @throws \EE_Error
573
+	 */
574
+	public static function display_register_now_button()
575
+	{
576
+		$btn_text = apply_filters(
577
+			'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text',
578
+			__('Register Now', 'event_espresso'),
579
+			EED_Ticket_Selector::$_event
580
+		);
581
+		$external_url = EED_Ticket_Selector::$_event->external_url();
582
+		$html = '<input id="ticket-selector-submit-' . EED_Ticket_Selector::$_event->ID() . '-btn"';
583
+		$html .= ' class="ticket-selector-submit-btn ';
584
+		$html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
585
+		$html .= ' type="submit" value="' . $btn_text . '" />';
586
+		$html .= apply_filters(
587
+			'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
588
+			'',
589
+			EED_Ticket_Selector::$_event
590
+		);
591
+		return $html;
592
+	}
593
+
594
+
595
+	/**
596
+	 * display_view_details_btn
597
+	 *
598
+	 * @access public
599
+	 * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event
600
+	 *                    (ie: $_max_atndz === 1) where there are no available tickets,
601
+	 *                    either because they are sold out, expired, or not yet on sale.
602
+	 *                    In this case, we need to close the form BEFORE adding any closing divs
603
+	 * @return string
604
+	 * @throws \EE_Error
605
+	 */
606
+	public static function display_view_details_btn($DWMTS = false)
607
+	{
608
+		if ( ! self::$_event->get_permalink()) {
609
+			EE_Error::add_error(
610
+				__('The URL for the Event Details page could not be retrieved.', 'event_espresso'),
611
+				__FILE__, __FUNCTION__, __LINE__
612
+			);
613
+		}
614
+		$view_details_btn = '<form method="POST" action="';
615
+		$view_details_btn .= apply_filters(
616
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url',
617
+			self::$_event->get_permalink(),
618
+			self::$_event
619
+		);
620
+		$view_details_btn .= '">';
621
+		$btn_text = apply_filters(
622
+			'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text',
623
+			__('View Details', 'event_espresso'),
624
+			self::$_event
625
+		);
626
+		$view_details_btn .= '<input id="ticket-selector-submit-'
627
+							 . self::$_event->ID()
628
+							 . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="'
629
+							 . $btn_text
630
+							 . '" />';
631
+		$view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', self::$_event);
632
+		if ($DWMTS) {
633
+			$view_details_btn .= \EED_Ticket_Selector::ticket_selector_form_close();
634
+			$view_details_btn .= \EED_Ticket_Selector::no_tkt_slctr_end_dv();
635
+			$view_details_btn .= '<br/>';
636
+		} else {
637
+			$view_details_btn .= \EED_Ticket_Selector::clear_tkt_slctr();
638
+			$view_details_btn .= '<br/>';
639
+			$view_details_btn .= \EED_Ticket_Selector::ticket_selector_form_close();
640
+		}
641
+		return $view_details_btn;
642
+	}
643
+
644
+
645
+
646
+	/**
647
+	 *    cancel_ticket_selections
648
+	 *
649
+	 * @access        public
650
+	 * @access        public
651
+	 * @return        string
652
+	 */
653
+	public static function cancel_ticket_selections()
654
+	{
655
+		// check nonce
656
+		if ( ! EED_Ticket_Selector::process_ticket_selector_nonce('cancel_ticket_selections')) {
657
+			return false;
658
+		}
659
+		EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
660
+		if (EE_Registry::instance()->REQ->is_set('event_id')) {
661
+			wp_safe_redirect(
662
+				EEH_Event_View::event_link_url(
663
+					EE_Registry::instance()->REQ->get('event_id')
664
+				)
665
+			);
666
+		} else {
667
+			wp_safe_redirect(
668
+				site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/')
669
+			);
670
+		}
671
+		die();
672
+	}
673
+
674
+
675
+
676
+	/**
677
+	 *    process_ticket_selector_nonce
678
+	 *
679
+	 * @access public
680
+	 * @param  string $nonce_name
681
+	 * @param string  $id
682
+	 * @return bool
683
+	 */
684
+	public static function process_ticket_selector_nonce($nonce_name, $id = '')
685
+	{
686
+		$nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce";
687
+		if (
688
+			! is_admin()
689
+			&& (
690
+				! EE_Registry::instance()->REQ->is_set($nonce_name_with_id)
691
+				|| ! wp_verify_nonce(
692
+					EE_Registry::instance()->REQ->get($nonce_name_with_id),
693
+					$nonce_name
694
+				)
695
+			)
696
+		) {
697
+			EE_Error::add_error(
698
+				sprintf(
699
+					__(
700
+						'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.',
701
+						'event_espresso'
702
+					),
703
+					'<br/>'
704
+				),
705
+				__FILE__,
706
+				__FUNCTION__,
707
+				__LINE__
708
+			);
709
+			return false;
710
+		}
711
+		return true;
712
+	}
713
+
714
+
715
+
716
+	/**
717
+	 *    process_ticket_selections
718
+	 *
719
+	 * @access public
720
+	 * @return array|boolean
721
+	 * @throws \EE_Error
722
+	 */
723
+	public function process_ticket_selections()
724
+	{
725
+		do_action('EED_Ticket_Selector__process_ticket_selections__before');
726
+		// do we have an event id?
727
+		if ( ! EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) {
728
+			// $_POST['tkt-slctr-event-id'] was not set ?!?!?!?
729
+			EE_Error::add_error(
730
+				sprintf(
731
+					__(
732
+						'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.',
733
+						'event_espresso'
734
+					),
735
+					'<br/>'
736
+				),
737
+				__FILE__,
738
+				__FUNCTION__,
739
+				__LINE__
740
+			);
741
+		}
742
+		//if event id is valid
743
+		$id = absint(EE_Registry::instance()->REQ->get('tkt-slctr-event-id'));
744
+		// check nonce
745
+		if ( ! EED_Ticket_Selector::process_ticket_selector_nonce('process_ticket_selections', $id)) {
746
+			return false;
747
+		}
748
+		//		d( EE_Registry::instance()->REQ );
749
+		self::$_available_spaces = array(
750
+			'tickets'   => array(),
751
+			'datetimes' => array(),
752
+		);
753
+		//we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart.
754
+		// When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc.
755
+		EE_Registry::instance()->load_core('Session');
756
+		// unless otherwise requested, clear the session
757
+		if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) {
758
+			EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__);
759
+		}
760
+		//d( EE_Registry::instance()->SSN );
761
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
762
+		// validate/sanitize data
763
+		$valid = self::_validate_post_data($id);
764
+		//EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ );
765
+		//EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ );
766
+		//EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ );
767
+		//EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ );
768
+		//check total tickets ordered vs max number of attendees that can register
769
+		if ($valid['total_tickets'] > $valid['max_atndz']) {
770
+			// ordering too many tickets !!!
771
+			$total_tickets_string = _n('You have attempted to purchase %s ticket.',
772
+				'You have attempted to purchase %s tickets.', $valid['total_tickets'], 'event_espresso');
773
+			$limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']);
774
+			// dev only message
775
+			$max_atndz_string = _n('The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
776
+				'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
777
+				$valid['max_atndz'], 'event_espresso');
778
+			$limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']);
779
+			EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
780
+		} else {
781
+			// all data appears to be valid
782
+			$tckts_slctd = false;
783
+			$tickets_added = 0;
784
+			$valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid);
785
+			if ($valid['total_tickets'] > 0) {
786
+				// load cart
787
+				EE_Registry::instance()->load_core('Cart');
788
+				// cycle thru the number of data rows sent from the event listing
789
+				for ($x = 0; $x < $valid['rows']; $x++) {
790
+					// does this row actually contain a ticket quantity?
791
+					if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) {
792
+						// YES we have a ticket quantity
793
+						$tckts_slctd = true;
794
+						//						d( $valid['ticket_obj'][$x] );
795
+						if ($valid['ticket_obj'][$x] instanceof EE_Ticket) {
796
+							// then add ticket to cart
797
+							$tickets_added += self::_add_ticket_to_cart($valid['ticket_obj'][$x], $valid['qty'][$x]);
798
+							if (EE_Error::has_error()) {
799
+								break;
800
+							}
801
+						} else {
802
+							// nothing added to cart retrieved
803
+							EE_Error::add_error(
804
+								sprintf(__('A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.',
805
+									'event_espresso'), '<br/>'),
806
+								__FILE__, __FUNCTION__, __LINE__
807
+							);
808
+						}
809
+					}
810
+				}
811
+			}
812
+			do_action(
813
+				'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart',
814
+				EE_Registry::instance()->CART,
815
+				$this
816
+			);
817
+			//d( EE_Registry::instance()->CART );
818
+			//die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE
819
+			if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) {
820
+				if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) {
821
+					do_action(
822
+						'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout',
823
+						EE_Registry::instance()->CART,
824
+						$this
825
+					);
826
+					EE_Registry::instance()->CART->recalculate_all_cart_totals();
827
+					EE_Registry::instance()->CART->save_cart(false);
828
+					// exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE
829
+					// just return TRUE for registrations being made from admin
830
+					if (is_admin()) {
831
+						return true;
832
+					}
833
+					EE_Error::get_notices(false, true);
834
+					wp_safe_redirect(
835
+						apply_filters(
836
+							'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url',
837
+							EE_Registry::instance()->CFG->core->reg_page_url()
838
+						)
839
+					);
840
+					exit();
841
+				} else {
842
+					if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) {
843
+						// nothing added to cart
844
+						EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), __FILE__,
845
+							__FUNCTION__, __LINE__);
846
+					}
847
+				}
848
+			} else {
849
+				// no ticket quantities were selected
850
+				EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.',
851
+					'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
852
+			}
853
+		}
854
+		//die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT
855
+		// at this point, just return if registration is being made from admin
856
+		if (is_admin()) {
857
+			return false;
858
+		}
859
+		if ($valid['return_url']) {
860
+			EE_Error::get_notices(false, true);
861
+			wp_safe_redirect($valid['return_url']);
862
+			exit();
863
+		} elseif (isset($event_to_add['id'])) {
864
+			EE_Error::get_notices(false, true);
865
+			wp_safe_redirect(get_permalink($event_to_add['id']));
866
+			exit();
867
+		} else {
868
+			echo EE_Error::get_notices();
869
+		}
870
+		return false;
871
+	}
872
+
873
+
874
+
875
+	/**
876
+	 *    validate_post_data
877
+	 *
878
+	 * @access        private
879
+	 * @param int $id
880
+	 * @return array|FALSE
881
+	 */
882
+	private static function _validate_post_data($id = 0)
883
+	{
884
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
885
+		if ( ! $id) {
886
+			EE_Error::add_error(
887
+				__('The event id provided was not valid.', 'event_espresso'),
888
+				__FILE__,
889
+				__FUNCTION__,
890
+				__LINE__
891
+			);
892
+			return false;
893
+		}
894
+		// start with an empty array()
895
+		$valid_data = array();
896
+		// grab valid id
897
+		$valid_data['id'] = $id;
898
+		// grab and sanitize return-url
899
+		$valid_data['return_url'] = esc_url_raw(EE_Registry::instance()->REQ->get('tkt-slctr-return-url-' . $id));
900
+		// array of other form names
901
+		$inputs_to_clean = array(
902
+			'event_id'   => 'tkt-slctr-event-id',
903
+			'max_atndz'  => 'tkt-slctr-max-atndz-',
904
+			'rows'       => 'tkt-slctr-rows-',
905
+			'qty'        => 'tkt-slctr-qty-',
906
+			'ticket_id'  => 'tkt-slctr-ticket-id-',
907
+			'return_url' => 'tkt-slctr-return-url-',
908
+		);
909
+		// let's track the total number of tickets ordered.'
910
+		$valid_data['total_tickets'] = 0;
911
+		// cycle through $inputs_to_clean array
912
+		foreach ($inputs_to_clean as $what => $input_to_clean) {
913
+			// check for POST data
914
+			if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) {
915
+				// grab value
916
+				$input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id);
917
+				switch ($what) {
918
+					// integers
919
+					case 'event_id':
920
+						$valid_data[$what] = absint($input_value);
921
+						// get event via the event id we put in the form
922
+						$valid_data['event'] = EE_Registry::instance()
923
+														  ->load_model('Event')
924
+														  ->get_one_by_ID($valid_data['event_id']);
925
+						break;
926
+					case 'rows':
927
+					case 'max_atndz':
928
+						$valid_data[$what] = absint($input_value);
929
+						break;
930
+					// arrays of integers
931
+					case 'qty':
932
+						/** @var array $row_qty */
933
+						$row_qty = $input_value;
934
+						// if qty is coming from a radio button input, then we need to assemble an array of rows
935
+						if ( ! is_array($row_qty)) {
936
+							// get number of rows
937
+							$rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id)
938
+								? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id))
939
+								: 1;
940
+							// explode ints by the dash
941
+							$row_qty = explode('-', $row_qty);
942
+							$row = isset($row_qty[0]) ? absint($row_qty[0]) : 1;
943
+							$qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0;
944
+							$row_qty = array($row => $qty);
945
+							//								 d( $row_qty );
946
+							for ($x = 1; $x <= $rows; $x++) {
947
+								if ( ! isset($row_qty[$x])) {
948
+									$row_qty[$x] = 0;
949
+								}
950
+							}
951
+						}
952
+						ksort($row_qty);
953
+						//							 d( $row_qty );
954
+						// cycle thru values
955
+						foreach ($row_qty as $qty) {
956
+							$qty = absint($qty);
957
+							// sanitize as integers
958
+							$valid_data[$what][] = $qty;
959
+							$valid_data['total_tickets'] += $qty;
960
+						}
961
+						break;
962
+					// array of integers
963
+					case 'ticket_id':
964
+						$value_array = array();
965
+						// cycle thru values
966
+						foreach ((array)$input_value as $key => $value) {
967
+							// allow only numbers, letters,  spaces, commas and dashes
968
+							$value_array[$key] = wp_strip_all_tags($value);
969
+							// get ticket via the ticket id we put in the form
970
+							$ticket_obj = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value);
971
+							$valid_data['ticket_obj'][$key] = $ticket_obj;
972
+						}
973
+						$valid_data[$what] = $value_array;
974
+						break;
975
+					case 'return_url' :
976
+						// grab and sanitize return-url
977
+						$valid_data[$what] = esc_url_raw($input_value);
978
+						break;
979
+				}    // end switch $what
980
+			}
981
+		}    // end foreach $inputs_to_clean
982
+		//		d( $valid_data );
983
+		//		die();
984
+		return $valid_data;
985
+	}
986
+
987
+
988
+
989
+	/**
990
+	 *    adds a ticket to the cart
991
+	 *
992
+	 * @access   private
993
+	 * @param EE_Ticket $ticket
994
+	 * @param int       $qty
995
+	 * @return TRUE on success, FALSE on fail
996
+	 * @throws \EE_Error
997
+	 */
998
+	private static function _add_ticket_to_cart(EE_Ticket $ticket = null, $qty = 1)
999
+	{
1000
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1001
+		// get the number of spaces left for this datetime ticket
1002
+		$available_spaces = self::_ticket_datetime_availability($ticket);
1003
+		// compare available spaces against the number of tickets being purchased
1004
+		if ($available_spaces >= $qty) {
1005
+			// allow addons to prevent a ticket from being added to cart
1006
+			if ( ! apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', true, $ticket,
1007
+				$qty, $available_spaces)
1008
+			) {
1009
+				return false;
1010
+			}
1011
+			$qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket));
1012
+			// add event to cart
1013
+			if (EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) {
1014
+				self::_recalculate_ticket_datetime_availability($ticket, $qty);
1015
+				return true;
1016
+			} else {
1017
+				return false;
1018
+			}
1019
+		} else {
1020
+			// tickets can not be purchased but let's find the exact number left for the last ticket selected PRIOR to subtracting tickets
1021
+			$available_spaces = self::_ticket_datetime_availability($ticket, true);
1022
+			// greedy greedy greedy eh?
1023
+			if ($available_spaces > 0) {
1024
+				if (
1025
+				apply_filters(
1026
+					'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error',
1027
+					true,
1028
+					$ticket,
1029
+					$qty,
1030
+					$available_spaces
1031
+				)
1032
+				) {
1033
+					EED_Ticket_Selector::_display_availability_error($available_spaces);
1034
+				}
1035
+			} else {
1036
+				EE_Error::add_error(
1037
+					__('We\'re sorry, but there are no available spaces left for this event at this particular date and time.',
1038
+						'event_espresso'),
1039
+					__FILE__, __FUNCTION__, __LINE__
1040
+				);
1041
+			}
1042
+			return false;
1043
+		}
1044
+	}
1045
+
1046
+
1047
+
1048
+	/**
1049
+	 *  _display_availability_error
1050
+	 *
1051
+	 * @access    private
1052
+	 * @param int $available_spaces
1053
+	 * @throws \EE_Error
1054
+	 */
1055
+	private static function _display_availability_error($available_spaces = 1)
1056
+	{
1057
+		// add error messaging - we're using the _n function that will generate
1058
+		// the appropriate singular or plural message based on the number of $available_spaces
1059
+		if (EE_Registry::instance()->CART->all_ticket_quantity_count()) {
1060
+			$msg = sprintf(
1061
+				_n(
1062
+					'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
1063
+					'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.',
1064
+					$available_spaces,
1065
+					'event_espresso'
1066
+				),
1067
+				$available_spaces,
1068
+				'<br />'
1069
+			);
1070
+		} else {
1071
+			$msg = sprintf(
1072
+				_n(
1073
+					'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
1074
+					'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.',
1075
+					$available_spaces,
1076
+					'event_espresso'
1077
+				),
1078
+				$available_spaces,
1079
+				'<br />'
1080
+			);
1081
+		}
1082
+		EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1083
+	}
1084
+
1085
+
1086
+
1087
+	/**
1088
+	 * _ticket_datetime_availability
1089
+	 * creates an array of tickets plus all of the datetimes available to each ticket
1090
+	 * and tracks the spaces remaining for each of those datetimes
1091
+	 *
1092
+	 * @access private
1093
+	 * @param EE_Ticket $ticket - selected ticket
1094
+	 * @param bool      $get_original_ticket_spaces
1095
+	 * @return int
1096
+	 * @throws \EE_Error
1097
+	 */
1098
+	private static function _ticket_datetime_availability(EE_Ticket $ticket, $get_original_ticket_spaces = false)
1099
+	{
1100
+		// if the $_available_spaces array has not been set up yet...
1101
+		if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
1102
+			self::_set_initial_ticket_datetime_availability($ticket);
1103
+		}
1104
+		$available_spaces = $ticket->qty() - $ticket->sold();
1105
+		if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
1106
+			// loop thru tickets, which will ALSO include individual ticket records AND a total
1107
+			foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
1108
+				// if we want the original datetime availability BEFORE we started subtracting tickets ?
1109
+				if ($get_original_ticket_spaces) {
1110
+					// then grab the available spaces from the "tickets" array and compare with the above to get the lowest number
1111
+					$available_spaces = min($available_spaces,
1112
+						self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID]);
1113
+				} else {
1114
+					// we want the updated ticket availability as stored in the "datetimes" array
1115
+					$available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]);
1116
+				}
1117
+			}
1118
+		}
1119
+		return $available_spaces;
1120
+	}
1121
+
1122
+
1123
+
1124
+	/**
1125
+	 * _set_initial_ticket_datetime_availability
1126
+	 *
1127
+	 * @access private
1128
+	 * @param EE_Ticket $ticket
1129
+	 * @return void
1130
+	 * @throws \EE_Error
1131
+	 */
1132
+	private static function _set_initial_ticket_datetime_availability(EE_Ticket $ticket)
1133
+	{
1134
+		// first, get all of the datetimes that are available to this ticket
1135
+		$datetimes = $ticket->get_many_related(
1136
+			'Datetime',
1137
+			array(
1138
+				array(
1139
+					'DTT_EVT_end' => array(
1140
+						'>=',
1141
+						EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
1142
+					),
1143
+				),
1144
+				'order_by' => array('DTT_EVT_start' => 'ASC'),
1145
+			)
1146
+		);
1147
+		if ( ! empty($datetimes)) {
1148
+			// now loop thru all of the datetimes
1149
+			foreach ($datetimes as $datetime) {
1150
+				if ($datetime instanceof EE_Datetime) {
1151
+					// the number of spaces available for the datetime without considering individual ticket quantities
1152
+					$spaces_remaining = $datetime->spaces_remaining();
1153
+					// save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold or the datetime spaces remaining) to this ticket using the datetime ID as the key
1154
+					self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min(
1155
+						$ticket->qty() - $ticket->sold(),
1156
+						$spaces_remaining
1157
+					);
1158
+					// if the remaining spaces for this datetime is already set, then compare that against the datetime spaces remaining, and take the lowest number,
1159
+					// else just take the datetime spaces remaining, and assign to the datetimes array
1160
+					self::$_available_spaces['datetimes'][$datetime->ID()] = isset(self::$_available_spaces['datetimes'][$datetime->ID()])
1161
+						? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining)
1162
+						: $spaces_remaining;
1163
+				}
1164
+			}
1165
+		}
1166
+	}
1167
+
1168
+
1169
+
1170
+	/**
1171
+	 *    _recalculate_ticket_datetime_availability
1172
+	 *
1173
+	 * @access    private
1174
+	 * @param    EE_Ticket $ticket
1175
+	 * @param    int       $qty
1176
+	 * @return    void
1177
+	 */
1178
+	private static function _recalculate_ticket_datetime_availability(EE_Ticket $ticket, $qty = 0)
1179
+	{
1180
+		if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
1181
+			// loop thru tickets, which will ALSO include individual ticket records AND a total
1182
+			foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
1183
+				// subtract the qty of selected tickets from each datetime's available spaces this ticket has access to,
1184
+				self::$_available_spaces['datetimes'][$DTD_ID] -= $qty;
1185
+			}
1186
+		}
1187
+	}
1188
+
1189
+
1190
+
1191
+	/**
1192
+	 *    load js
1193
+	 *
1194
+	 * @access        public
1195
+	 * @return        void
1196
+	 */
1197
+	public static function load_tckt_slctr_assets()
1198
+	{
1199
+		// add some style
1200
+		if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) {
1201
+			wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css');
1202
+			wp_enqueue_style('ticket_selector');
1203
+			// make it dance
1204
+			// wp_register_script('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', array('espresso_core'), '', TRUE);
1205
+			// wp_enqueue_script('ticket_selector');
1206
+		}
1207
+	}
1208
+
1209
+
1210
+
1211
+	public static function load_tckt_slctr_assets_admin()
1212
+	{
1213
+		//iframe button js on admin event editor page
1214
+		if (EE_Registry::instance()->REQ->get('page') === 'espresso_events'
1215
+			&& EE_Registry::instance()->REQ->get('action') === 'edit'
1216
+		) {
1217
+			wp_register_script('ticket_selector_embed', TICKET_SELECTOR_ASSETS_URL . 'ticket-selector-embed.js',
1218
+				array('ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1219
+			wp_enqueue_script('ticket_selector_embed');
1220
+		}
1221
+	}
1222 1222
 
1223 1223
 
1224 1224
 
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 class EED_Ticket_Selector extends EED_Module
15 15
 {
16 16
 
17
-    const debug = false;    //	true false
17
+    const debug = false; //	true false
18 18
 
19 19
     /**
20 20
      * event that ticket selector is being generated for
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public static function set_definitions()
115 115
     {
116
-        define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS);
117
-        define('TICKET_SELECTOR_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)) . 'templates' . DS);
116
+        define('TICKET_SELECTOR_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS);
117
+        define('TICKET_SELECTOR_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS);
118 118
         //if config is not set, initialize
119 119
         //If config is not set, set it.
120 120
         if (EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector === null) {
@@ -158,10 +158,10 @@  discard block
 block discarded – undo
158 158
         $template_args['css'] = apply_filters(
159 159
             'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
160 160
             array(
161
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_embed.css?ver=' . EVENT_ESPRESSO_VERSION,
162
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css?ver=' . EVENT_ESPRESSO_VERSION,
163
-                includes_url('css/dashicons.min.css?ver=' . $GLOBALS['wp_version']),
164
-                EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
161
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector_embed.css?ver='.EVENT_ESPRESSO_VERSION,
162
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css?ver='.EVENT_ESPRESSO_VERSION,
163
+                includes_url('css/dashicons.min.css?ver='.$GLOBALS['wp_version']),
164
+                EE_GLOBAL_ASSETS_URL.'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION,
165 165
             )
166 166
         );
167 167
         EE_Registry::$i18n_js_strings['ticket_selector_iframe'] = true;
@@ -174,18 +174,18 @@  discard block
 block discarded – undo
174 174
         $template_args['js'] = apply_filters(
175 175
             'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
176 176
             array(
177
-                includes_url('js/jquery/jquery.js?ver=' . $GLOBALS['wp_version']),
178
-                EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION,
179
-                TICKET_SELECTOR_ASSETS_URL . 'ticket_selector_iframe_embed.js?ver=' . EVENT_ESPRESSO_VERSION,
177
+                includes_url('js/jquery/jquery.js?ver='.$GLOBALS['wp_version']),
178
+                EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION,
179
+                TICKET_SELECTOR_ASSETS_URL.'ticket_selector_iframe_embed.js?ver='.EVENT_ESPRESSO_VERSION,
180 180
             )
181 181
         );
182 182
         $template_args['notices'] = EEH_Template::display_template(
183
-            EE_TEMPLATES . 'espresso-ajax-notices.template.php',
183
+            EE_TEMPLATES.'espresso-ajax-notices.template.php',
184 184
             array(),
185 185
             true
186 186
         );
187 187
         EEH_Template::display_template(
188
-            TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart_iframe.template.php',
188
+            TICKET_SELECTOR_TEMPLATES_PATH.'ticket_selector_chart_iframe.template.php',
189 189
             $template_args
190 190
         );
191 191
         exit;
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
      * @param int    $id               The post id for the event.
201 201
      * @return string The new html string for the permalink area.
202 202
      */
203
-    public static function iframe_code_button($permalink_string, $id )
203
+    public static function iframe_code_button($permalink_string, $id)
204 204
     {
205 205
         //make sure this is ONLY when editing and the event id has been set.
206 206
         if ( ! empty($id)) {
@@ -214,12 +214,12 @@  discard block
 block discarded – undo
214 214
                                  . '</a> ';
215 215
             $ticket_selector_url = add_query_arg(array('ticket_selector' => 'iframe', 'event' => $id), site_url());
216 216
             $iframe_string = esc_html(
217
-                '<iframe src="' . $ticket_selector_url . '" width="100%" height="100%"></iframe>'
217
+                '<iframe src="'.$ticket_selector_url.'" width="100%" height="100%"></iframe>'
218 218
             );
219 219
             $permalink_string .= '
220 220
 <div id="js-ts-iframe" style="display:none">
221 221
 	<div style="width:100%; height: 500px;">
222
-		' . $iframe_string . '
222
+		' . $iframe_string.'
223 223
 	</div>
224 224
 </div>';
225 225
         }
@@ -243,10 +243,10 @@  discard block
 block discarded – undo
243 243
         }
244 244
         if ($event instanceof EE_Event) {
245 245
             self::$_event = $event;
246
-        } else if ($event instanceof WP_Post ) {
247
-            if ( isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
246
+        } else if ($event instanceof WP_Post) {
247
+            if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
248 248
                 self::$_event = $event->EE_Event;
249
-            } else if ( $event->post_type === 'espresso_events') {
249
+            } else if ($event->post_type === 'espresso_events') {
250 250
                 $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
251 251
                 self::$_event = $event->EE_Event;
252 252
             }
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
             $dev_msg = $user_msg
256 256
                        . __('In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.',
257 257
                     'event_espresso');
258
-            EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
258
+            EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__);
259 259
             return false;
260 260
         }
261 261
         return true;
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
                     '</a></span></div>'
363 363
                 );
364 364
             }
365
-            return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
365
+            return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>';
366 366
         }
367
-        $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php';
367
+        $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH.'ticket_selector_chart.template.php';
368 368
         $templates['ticket_selector'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__template_path',
369 369
             $templates['ticket_selector'], self::$_event);
370 370
         // redirecting to another site for registration ??
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
             ? EED_Ticket_Selector::ticket_selector_form_open(
387 387
                 self::$_event->ID(),
388 388
                 $external_url
389
-            ) . $ticket_selector
389
+            ).$ticket_selector
390 390
             : $ticket_selector;
391 391
         // submit button and form close tag
392 392
         $ticket_selector .= ! is_admin() ? EED_Ticket_Selector::display_ticket_selector_submit() : '';
@@ -409,11 +409,11 @@  discard block
 block discarded – undo
409 409
     {
410 410
         // if redirecting, we don't need any anything else
411 411
         if ($external_url) {
412
-            $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '">';
413
-            $query_args = (array)EEH_URL::get_query_string($external_url);
412
+            $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'">';
413
+            $query_args = (array) EEH_URL::get_query_string($external_url);
414 414
             foreach ($query_args as $query_arg => $value) {
415 415
                 $html .= '
416
-				<input type="hidden" name="' . $query_arg . '" value="' . $value . '">';
416
+				<input type="hidden" name="' . $query_arg.'" value="'.$value.'">';
417 417
             }
418 418
             return $html;
419 419
         }
@@ -428,8 +428,8 @@  discard block
 block discarded – undo
428 428
                 __FILE__, __FUNCTION__, __LINE__);
429 429
         }
430 430
         $extra_params = self::$_in_iframe ? ' target="_blank"' : '';
431
-        $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>';
432
-        $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_' . $ID, true, false);
431
+        $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>';
432
+        $html .= wp_nonce_field('process_ticket_selections', 'process_ticket_selections_nonce_'.$ID, true, false);
433 433
         $html .= '<input type="hidden" name="ee" value="process_ticket_selections">';
434 434
         $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, self::$_event);
435 435
         return $html;
@@ -455,10 +455,10 @@  discard block
 block discarded – undo
455 455
                 $html .= empty($external_url) ?
456 456
                     \EED_Ticket_Selector::no_tkt_slctr_end_dv()
457 457
                     : \EED_Ticket_Selector::clear_tkt_slctr();
458
-                $html .= '<br/>' . \EED_Ticket_Selector::ticket_selector_form_close();
459
-            } else if ( EED_Ticket_Selector::$_max_atndz === 1 ) {
458
+                $html .= '<br/>'.\EED_Ticket_Selector::ticket_selector_form_close();
459
+            } else if (EED_Ticket_Selector::$_max_atndz === 1) {
460 460
                 // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1)
461
-                if ( EED_Ticket_Selector::$_event->is_sold_out() ) {
461
+                if (EED_Ticket_Selector::$_event->is_sold_out()) {
462 462
                     // then instead of a View Details or Submit button, just display a "Sold Out" message
463 463
                     $html .= apply_filters(
464 464
                         'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg',
@@ -579,10 +579,10 @@  discard block
 block discarded – undo
579 579
             EED_Ticket_Selector::$_event
580 580
         );
581 581
         $external_url = EED_Ticket_Selector::$_event->external_url();
582
-        $html = '<input id="ticket-selector-submit-' . EED_Ticket_Selector::$_event->ID() . '-btn"';
582
+        $html = '<input id="ticket-selector-submit-'.EED_Ticket_Selector::$_event->ID().'-btn"';
583 583
         $html .= ' class="ticket-selector-submit-btn ';
584 584
         $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"';
585
-        $html .= ' type="submit" value="' . $btn_text . '" />';
585
+        $html .= ' type="submit" value="'.$btn_text.'" />';
586 586
         $html .= apply_filters(
587 587
             'FHEE__EE_Ticket_Selector__after_ticket_selector_submit',
588 588
             '',
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
             );
666 666
         } else {
667 667
             wp_safe_redirect(
668
-                site_url('/' . EE_Registry::instance()->CFG->core->event_cpt_slug . '/')
668
+                site_url('/'.EE_Registry::instance()->CFG->core->event_cpt_slug.'/')
669 669
             );
670 670
         }
671 671
         die();
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
                 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.',
777 777
                 $valid['max_atndz'], 'event_espresso');
778 778
             $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']);
779
-            EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__);
779
+            EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__);
780 780
         } else {
781 781
             // all data appears to be valid
782 782
             $tckts_slctd = false;
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
         // grab valid id
897 897
         $valid_data['id'] = $id;
898 898
         // grab and sanitize return-url
899
-        $valid_data['return_url'] = esc_url_raw(EE_Registry::instance()->REQ->get('tkt-slctr-return-url-' . $id));
899
+        $valid_data['return_url'] = esc_url_raw(EE_Registry::instance()->REQ->get('tkt-slctr-return-url-'.$id));
900 900
         // array of other form names
901 901
         $inputs_to_clean = array(
902 902
             'event_id'   => 'tkt-slctr-event-id',
@@ -911,9 +911,9 @@  discard block
 block discarded – undo
911 911
         // cycle through $inputs_to_clean array
912 912
         foreach ($inputs_to_clean as $what => $input_to_clean) {
913 913
             // check for POST data
914
-            if (EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) {
914
+            if (EE_Registry::instance()->REQ->is_set($input_to_clean.$id)) {
915 915
                 // grab value
916
-                $input_value = EE_Registry::instance()->REQ->get($input_to_clean . $id);
916
+                $input_value = EE_Registry::instance()->REQ->get($input_to_clean.$id);
917 917
                 switch ($what) {
918 918
                     // integers
919 919
                     case 'event_id':
@@ -934,8 +934,8 @@  discard block
 block discarded – undo
934 934
                         // if qty is coming from a radio button input, then we need to assemble an array of rows
935 935
                         if ( ! is_array($row_qty)) {
936 936
                             // get number of rows
937
-                            $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id)
938
-                                ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id))
937
+                            $rows = EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-'.$id)
938
+                                ? absint(EE_Registry::instance()->REQ->get('tkt-slctr-rows-'.$id))
939 939
                                 : 1;
940 940
                             // explode ints by the dash
941 941
                             $row_qty = explode('-', $row_qty);
@@ -963,7 +963,7 @@  discard block
 block discarded – undo
963 963
                     case 'ticket_id':
964 964
                         $value_array = array();
965 965
                         // cycle thru values
966
-                        foreach ((array)$input_value as $key => $value) {
966
+                        foreach ((array) $input_value as $key => $value) {
967 967
                             // allow only numbers, letters,  spaces, commas and dashes
968 968
                             $value_array[$key] = wp_strip_all_tags($value);
969 969
                             // get ticket via the ticket id we put in the form
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
         $available_spaces = $ticket->qty() - $ticket->sold();
1105 1105
         if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
1106 1106
             // loop thru tickets, which will ALSO include individual ticket records AND a total
1107
-            foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
1107
+            foreach ((array) self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
1108 1108
                 // if we want the original datetime availability BEFORE we started subtracting tickets ?
1109 1109
                 if ($get_original_ticket_spaces) {
1110 1110
                     // then grab the available spaces from the "tickets" array and compare with the above to get the lowest number
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
     {
1180 1180
         if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) {
1181 1181
             // loop thru tickets, which will ALSO include individual ticket records AND a total
1182
-            foreach ((array)self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
1182
+            foreach ((array) self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) {
1183 1183
                 // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to,
1184 1184
                 self::$_available_spaces['datetimes'][$DTD_ID] -= $qty;
1185 1185
             }
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
     {
1199 1199
         // add some style
1200 1200
         if (apply_filters('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', false)) {
1201
-            wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.css');
1201
+            wp_register_style('ticket_selector', TICKET_SELECTOR_ASSETS_URL.'ticket_selector.css');
1202 1202
             wp_enqueue_style('ticket_selector');
1203 1203
             // make it dance
1204 1204
             // wp_register_script('ticket_selector', TICKET_SELECTOR_ASSETS_URL . 'ticket_selector.js', array('espresso_core'), '', TRUE);
@@ -1214,7 +1214,7 @@  discard block
 block discarded – undo
1214 1214
         if (EE_Registry::instance()->REQ->get('page') === 'espresso_events'
1215 1215
             && EE_Registry::instance()->REQ->get('action') === 'edit'
1216 1216
         ) {
1217
-            wp_register_script('ticket_selector_embed', TICKET_SELECTOR_ASSETS_URL . 'ticket-selector-embed.js',
1217
+            wp_register_script('ticket_selector_embed', TICKET_SELECTOR_ASSETS_URL.'ticket-selector-embed.js',
1218 1218
                 array('ee-dialog'), EVENT_ESPRESSO_VERSION, true);
1219 1219
             wp_enqueue_script('ticket_selector_embed');
1220 1220
         }
Please login to merge, or discard this patch.