/**
  * For adding any html output ab ove the payment overview.
  * Many gateways won't want ot display anything, so this function just returns an empty string.
  * Other gateways may want to override this, such as offline gateways.
  * @return string
  */
 public function payment_overview_content(EE_Payment $payment)
 {
     EE_Registry::instance()->load_helper('Template');
     $extra_meta_for_payment_method = $this->_pm_instance->all_extra_meta_array();
     $template_vars = array_merge(array('payment_method' => $this->_pm_instance, 'payment' => $payment, 'page_title' => '', 'payment_instructions' => ''), $extra_meta_for_payment_method);
     return EEH_Template::locate_template('payment_methods' . DS . 'Bank' . DS . 'templates' . DS . 'bank_payment_details_content.template.php', $template_vars);
 }
 public function __construct($template_file, $args = array(), $options_array = array())
 {
     EE_Registry::instance()->load_helper('Template');
     $html = EEH_Template::locate_template($template_file, $args);
     //		echo " filepath:$template_file html $html";
     parent::__construct($html, $options_array);
 }
 /**
  *	_migration_step
  *
  * @access protected
  * @param int $num_items
  * @throws EE_Error
  * @return int number of items ACTUALLY migrated
  */
 protected function _migration_step($num_items = 1)
 {
     $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
     $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', NULL, FALSE, FALSE, TRUE);
     $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', NULL, FALSE, FALSE, TRUE);
     if ($overridden_invoice_body || $overridden_receipt_body) {
         EE_Error::add_persistent_admin_notice('invoice_overriding_templates', sprintf(__('Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overriden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.')), TRUE);
     }
     //regardless of whether it worked or not, we ought to continue the migration
     $this->set_completed();
     return 1;
 }
 /**
  *    process_shortcode
  *
  *    [ESPRESSO_PROMOTIONS]
  *
  * @access 	public
  * @param 	array $attributes
  * @return 	string
  */
 public function process_shortcode($attributes = array())
 {
     /** @type EEM_Promotion $EEM_Promotion */
     $EEM_Promotion = EE_Registry::instance()->load_model('Promotion');
     EE_Registry::instance()->load_helper('Template');
     $active_promotions = $EEM_Promotion->get_all_active_codeless_promotions();
     $html = '<div id="ee-upcoming-promotions-dv">';
     foreach ($active_promotions as $promotion) {
         if ($promotion instanceof EE_Promotion) {
             $config = EED_Promotions::instance()->set_config();
             if (!empty($config->banner_template) && $config->banner_template == 'promo-banner-ribbon.template.php' && !empty($config->ribbon_banner_color)) {
                 $promo_bg_color = $config->ribbon_banner_color;
             } else {
                 $promo_bg_color = '';
             }
             $scope_objects = $promotion->get_objects_promo_applies_to();
             $html .= EEH_Template::locate_template(apply_filters('FHEE__EED_Promotions__process_shortcode__upcoming_promotions', EE_PROMOTIONS_PATH . 'templates' . DS . 'upcoming-promotions-grid.template.php'), array('PRO_ID' => $promotion->ID(), 'promo_bg_color' => apply_filters('FHEE__EED_Promotions__process_shortcode__promo_bg_color', $promo_bg_color), 'promo_header' => $promotion->name(), 'promo_desc' => $promotion->description() != '' ? $promotion->description() . '<br />' : '', 'promo_amount' => $promotion->pretty_amount(), 'promo_dates' => $promotion->promotion_date_range(), 'promo_scopes' => $promotion->get_promo_applies_to_link_array($scope_objects)));
         }
     }
     $html .= '</div>';
     return $html;
 }
 /**
  *	_migration_step
  *
  * @access protected
  * @param int $num_items
  * @throws EE_Error
  * @return int number of items ACTUALLY migrated
  */
 protected function _migration_step($num_items = 1)
 {
     // if this isn't set then something is really wrong
     if (!EE_Config::instance()->gateway instanceof EE_Gateway_Config) {
         throw new EE_Error(__('It appears the Event Espresso Core Configuration is not setup correctly.', 'event_espresso'));
     }
     $invoice_settings = isset(EE_Config::instance()->gateway->payment_settings['Invoice']) ? EE_Config::instance()->gateway->payment_settings['Invoice'] : NULL;
     if (!$invoice_settings) {
         $this->add_error(__('Could not migrate EE4.4 invoice settings to EE4.5 because they didnt exist', 'event_espresso'));
     } else {
         $invoice_settings['template_payment_instructions'] = $invoice_settings['pdf_instructions'];
         $invoice_settings['template_invoice_payee_name'] = $invoice_settings['payable_to'];
         $invoice_settings['template_invoice_address'] = $invoice_settings['payment_address'];
         $invoice_settings['template_invoice_email'] = '';
         $invoice_settings['template_invoice_tax_number'] = '';
         unset($invoice_settings['pdf_instructions']);
         unset($invoice_settings['payable_to']);
         unset($invoice_settings['payment_address']);
         EE_Config::instance()->gateway->payment_settings['Invoice'] = $invoice_settings;
         EE_Config::instance()->update_espresso_config(false, false);
         //@todo: check 'invoice_css' too because we can't easily affect that so we might need to set a persistent notice
         //(why is it tough to change? because we want to update the receipt and invoice message template, but
         //message templates are only initialized AFTER migrations and those two are new in 4.5. So if we wanted to
         //update them from a DMS, we'd need to have the DMS create the message templates which is quite a lot of code;
         //also we don't want to build a dependency on the messages code because it is likely to change soon
         if (!in_array($invoice_settings['invoice_css'], array('', 'simple.css'))) {
             EE_Error::add_persistent_admin_notice('invoice_css_not_updated', sprintf(__('You had previously set your Invoice Payment Method\'s stylesheet to be %1$s, but that setting has moved. PDF and HTML Invoices and Receipts are now Messages, which means you can easily modify them from your Wordpress Dashboard instead of using filters or uploading template files. Please visit Messages -> Receipt and Messages -> Invoice to change their stylesheets.', 'event_espresso'), $invoice_settings['invoice_css']), FALSE);
         }
         EE_Registry::instance()->load_helper('Template');
         $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
         $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', NULL, FALSE, FALSE, TRUE);
         $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', NULL, FALSE, FALSE, TRUE);
         if ($overridden_invoice_body || $overridden_receipt_body) {
             EE_Error::add_persistent_admin_notice('invoice_overriding_templates', sprintf(__('Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overriden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents. We recommend deleting your old Invoice/Receipt templates and modifying the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.')), TRUE);
         }
     }
     //regardless of whether it worked or not, we ought to continue the migration
     $this->set_completed();
     return 1;
 }
 /**
  * closing div tag for a form
  * @return string
  */
 public function layout_form_end()
 {
     if ($this->_layout_end_template_file) {
         return EEH_Template::locate_template($this->_layout_end_template_file, $this->template_args(), TRUE, TRUE);
     } else {
         return parent::layout_form_end();
     }
 }
 /**
  *    template_include
  *
  *    replacement EE CPT template that displays message notifying site visitors that EE has been temporarily placed into maintenance mode
  *
  * @access    public
  * @param    string $template_path
  * @return    string
  */
 public static function template_include($template_path)
 {
     EE_Registry::instance()->load_helper('Template');
     $template_located = EEH_Template::locate_template(EE_TEMPLATES . 'maintenance_mode.template.php', FALSE, FALSE);
     return $template_located ? $template_located : $template_path;
 }
 /**
  *    position_template_part
  *
  * based on the priority of the incoming template part
  * relative to the known event description template part priority,
  * this method will assign template parts to one of the following:
  *        $this->before_event_content
  *        $this->event_content
  *        $this->after_event_content
  *
  * @access protected
  * @param string $content
  * @param string $template
  * @param int $priority
  * @return string
  */
 protected function _position_template_part($content, $template, $priority)
 {
     // Event Description content is the actual incoming content itself
     if ($priority === $this->event_desc_priority) {
         $this->event_content = $content;
     } else {
         if ($priority < $this->event_desc_priority) {
             // everything BEFORE the Event Description
             $this->before_event_content .= EEH_Template::locate_template($template);
         } else {
             if ($priority > $this->event_desc_priority) {
                 // everything AFTER the Event Description
                 $this->after_event_content .= EEH_Template::locate_template($template);
             }
         }
     }
 }
 /**
  * For adding any html output above the payment overview.
  * Many gateways won't want ot display anything, so this function just returns an empty string.
  * Other gateways may want to override this, such as offline gateways.
  *
  * @param \EE_Payment $payment
  * @return string
  */
 public function payment_overview_content(EE_Payment $payment)
 {
     return EEH_Template::locate_template('payment_methods' . DS . 'Invoice' . DS . 'templates' . DS . 'invoice_payment_details_content.template.php', array_merge(array('payment_method' => $this->_pm_instance, 'payment' => $payment, 'page_confirmation_text' => '', 'page_extra_info' => '', 'invoice_url' => $payment->transaction()->primary_registration()->invoice_url('html')), $this->_pm_instance->all_extra_meta_array()));
 }
 /**
  * 	event_venues
  *
  *  	@access 	public
  * 	@param		string 	$content
  *  	@return 		void
  */
 public static function event_venues($content)
 {
     return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
 }
 /**
  * 	process_shortcode - ESPRESSO_EVENTS - Returns a list of events
  * 	[ESPRESSO_EVENTS]
  * 	[ESPRESSO_EVENTS title="My Super Event"]
  * 	[ESPRESSO_EVENTS limit=5]
  * 	[ESPRESSO_EVENTS css_class="my-custom-class"]
  * 	[ESPRESSO_EVENTS month="April 2014"]
  * 	[ESPRESSO_EVENTS show_expired=true]
  * 	[ESPRESSO_EVENTS category_slug="free-events"]
  * 	[ESPRESSO_EVENTS order_by="start_date,id"]
  * 	[ESPRESSO_EVENTS sort="ASC"]
  *
  *  @access 	public
  *  @param 	array 	$attributes
  *  @return 	string
  */
 public function process_shortcode($attributes = array())
 {
     // make sure EED_Events_Archive is setup properly
     if (apply_filters('FHEE__fallback_shortcode_processor__EES_Espresso_Events', FALSE)) {
         EED_Events_Archive::instance()->event_list();
     }
     // merge in any attributes passed via fallback shortcode processor
     $attributes = array_merge((array) $attributes, (array) $this->_attributes);
     //set default attributes
     $default_espresso_events_shortcode_atts = array('title' => NULL, 'limit' => 10, 'css_class' => NULL, 'show_expired' => FALSE, 'month' => NULL, 'category_slug' => NULL, 'order_by' => 'start_date', 'sort' => 'ASC', 'fallback_shortcode_processor' => FALSE);
     // allow the defaults to be filtered
     $default_espresso_events_shortcode_atts = apply_filters('EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', $default_espresso_events_shortcode_atts);
     // grab attributes and merge with defaults, then extract
     $attributes = array_merge($default_espresso_events_shortcode_atts, $attributes);
     // make sure we use the_excerpt()
     add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true');
     // run the query
     global $wp_query;
     $wp_query = new EE_Event_List_Query($attributes);
     // check what template is loaded and load filters accordingly
     EED_Events_Archive::instance()->template_include('loop-espresso_events.php');
     // load our template
     $event_list = EEH_Template::locate_template('loop-espresso_events.php', array(), TRUE, TRUE);
     // now reset the query and postdata
     wp_reset_query();
     wp_reset_postdata();
     EED_Events_Archive::remove_all_events_archive_filters();
     // pull our content from the output buffer and return it
     return $event_list;
 }
 /**
  * Renders the admin page, after most of the work was already done during enqueuing scripts
  * of creating the job and localizing some data
  */
 public function show_admin_page()
 {
     echo EEH_Template::locate_template(EE_MODULES . 'batch' . DS . 'templates' . DS . 'batch_wrapper.template.html', array('batch_request_type' => $this->batch_request_type()));
 }
 /**
  * EEH_Template::get_template_part
  * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
  * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
  *
  * @param string $slug The slug name for the generic template.
  * @param string $name The name of the specialised template.
  * @param array  $template_args
  * @param bool   $return_string
  * @return string        the html output for the formatted money value
  */
 public static function get_template_part($slug = NULL, $name = NULL, $template_args = array(), $return_string = FALSE)
 {
     do_action("get_template_part_{$slug}-{$name}", $slug, $name);
     $templates = array();
     $name = (string) $name;
     if ($name != '') {
         $templates[] = "{$slug}-{$name}.php";
     }
     // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
     if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", TRUE)) {
         EEH_Template::locate_template($templates, $template_args, TRUE, $return_string);
     }
 }
 /**
  * This is added right before event content is displayed for an event
  *
  * @since 1.0.0
  *
  * @param string $content (the content so far).
  *
  * @return string show people attached to an event.
  */
 public static function people_event_details($content)
 {
     if (function_exists('is_espresso_event') && is_espresso_event()) {
         EE_Registry::instance()->load_helper('Template');
         $content = EEH_Template::locate_template('content-espresso_events-people.php') . $content;
     }
     return $content;
 }
 /**
  * Loads a page for running a batch job that creates and downloads a file, 
  * and then sends the user back to wherever they were before
  */
 protected function batch_file_create()
 {
     //creates a job based on the request variable
     $job_handler_classname = str_replace('\\\\', '\\', $this->_req_data['job_handler']);
     $request_data = array_diff_key($this->_req_data, array_flip(array('action', 'page')));
     $batch_runner = new EventEspressoBatchRequest\BatchRequestProcessor();
     //eg 'EventEspressoBatchRequest\JobHandlers\RegistrationsReport'
     $job_response = $batch_runner->create_job($job_handler_classname, $request_data);
     wp_localize_script('support_batch_file_runner', 'ee_job_response', $job_response->to_array());
     wp_localize_script('support_batch_file_runner', 'ee_job_i18n', array('download_and_redirecting' => sprintf(__('File Generation complete. Downloading, and %1$sredirecting%2$s...', 'event_espresso'), '<a href="' . $this->_req_data['redirect_url'] . '">', '</a>'), 'redirect_url' => $this->_req_data['redirect_url']));
     echo EEH_Template::locate_template(EE_SUPPORT_ADMIN . 'templates' . DS . 'admin_batch_file_runner.template.html', array('filename' => EEH_File::get_filename_from_filepath($job_response->job_parameters()->extra_datum('filepath'))));
 }
 /**
  *    template_include
  *
  * @access    public
  * @param   string $template_include_path
  * @return    string
  */
 public function template_include($template_include_path = NULL)
 {
     if ($this->Request_Handler->is_espresso_page()) {
         $this->_template_path = !empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path);
         $template_path = EEH_Template::locate_template($this->_template_path, array(), false);
         $this->_template_path = !empty($template_path) ? $template_path : $template_include_path;
         $this->_template = basename($this->_template_path);
         return $this->_template_path;
     }
     return $template_include_path;
 }
 /**
  * venue_location
  *
  * @access public
  * @param  string $content
  * @return string
  */
 public function venue_location($content)
 {
     return $content . EEH_Template::locate_template('content-espresso_venues-location.php');
 }
 /**
  *    creates buttons for selecting number of attendees for an event
  *
  * @access 	public
  * @param 	object $event
  * @param 	bool 	$view_details
  * @return 	string
  */
 public static function display_ticket_selector($event = NULL, $view_details = FALSE)
 {
     do_action('AHEE_log', __FILE__, __FUNCTION__, '');
     //		d( $event );
     if ($event instanceof EE_Event) {
         self::$_event = $event;
     } else {
         if ($event instanceof WP_Post && isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) {
             self::$_event = $event->EE_Event;
         } else {
             if ($event instanceof WP_Post && (!isset($event->EE_Event) || !$event->EE_Event instanceof EE_Event)) {
                 $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event);
                 self::$_event = $event->EE_Event;
             } else {
                 $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso');
                 $dev_msg = $user_msg . __('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.', 'event_espresso');
                 EE_Error::add_error($user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__);
                 return FALSE;
             }
         }
     }
     if ((!self::$_event->display_ticket_selector() || $view_details) && !is_admin()) {
         return !is_single() ? EED_Ticket_Selector::display_view_details_btn(self::$_event) : '';
     }
     $template_args = array();
     $template_args['date_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', 'l F jS, Y');
     $template_args['time_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', 'g:i a');
     $template_args['EVT_ID'] = self::$_event->ID();
     $template_args['event'] = self::$_event;
     // is the event expired ?
     $template_args['event_is_expired'] = self::$_event->is_expired();
     if ($template_args['event_is_expired']) {
         return '<p><span class="important-notice">' . __('We\'re sorry, but all tickets sales have ended because the event is expired.', 'event_espresso') . '</span></p>';
     }
     // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
     $template_args['max_atndz'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', self::$_event->additional_limit());
     if ($template_args['max_atndz'] < 1) {
         $sales_closed_msg = __('We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', 'event_espresso');
         if (current_user_can('edit_post', self::$_event->ID())) {
             $sales_closed_msg .= sprintf(__('%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', 'event_espresso'), '<div class="ee-attention" style="text-align: left;"><b>', '</b><br />', $link = '<span class="edit-link"><a class="post-edit-link" href="' . get_edit_post_link(self::$_event->ID()) . '">', '</a></span></div>');
         }
         return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
     }
     // get all tickets for this event ordered by the datetime
     $template_args['tickets'] = EEM_Ticket::instance()->get_all(array(array('Datetime.EVT_ID' => self::$_event->ID()), 'order_by' => array('TKT_required' => 'DESC', 'TKT_order' => 'ASC', 'TKT_start_date' => 'ASC', 'TKT_end_date' => 'ASC', 'Datetime.DTT_EVT_start' => 'DESC')));
     $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php';
     $templates['ticket_selector'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', $templates['ticket_selector'], self::$_event);
     // redirecting to another site for registration ??
     $external_url = self::$_event->external_url() !== NULL || self::$_event->external_url() !== '' ? self::$_event->external_url() : FALSE;
     // set up the form (but not for the admin)
     $ticket_selector = !is_admin() ? EED_Ticket_Selector::ticket_selector_form_open(self::$_event->ID(), $external_url) : '';
     // if not redirecting to another site for registration
     if (!$external_url) {
         // then display the ticket selector
         $ticket_selector .= EEH_Template::locate_template($templates['ticket_selector'], $template_args);
     } else {
         // if not we still need to trigger the display of the submit button
         add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
         //display notice to admin that registration is external
         $ticket_selector .= !is_admin() ? '' : __('Registration is at an external URL for this event.', 'event_espresso');
     }
     // submit button and form close tag
     $ticket_selector .= !is_admin() ? EED_Ticket_Selector::display_ticket_selector_submit(self::$_event->ID()) : '';
     $ticket_selector .= !is_admin() ? EED_Ticket_Selector::ticket_selector_form_close() : '';
     return $ticket_selector;
 }
 /**
  *    process_shortcode
  *
  *    [ESPRESSO_GRID_TEMPLATE]
  *
  * @access 	public
  * @param 	array $attributes
  * @return 	string
  */
 public function process_shortcode($attributes = array())
 {
     // make sure $attributes is an array
     $attributes = array_merge(array('limit' => 10, 'show_expired' => FALSE, 'month' => NULL, 'category_slug' => NULL, 'order_by' => 'start_date', 'sort' => 'ASC'), (array) $attributes);
     // Show Expired ?
     $attributes['show_expired'] = filter_var($attributes['show_expired'], FILTER_VALIDATE_BOOLEAN);
     // run the query
     global $wp_query;
     $wp_query = new EE_Grid_Template_Query($attributes);
     //		d( $wp_query );
     // now filter the array of locations to search for templates
     add_filter('FHEE__EEH_Template__locate_template__template_folder_paths', array($this, 'template_folder_paths'));
     // load our template
     $grid_template = EEH_Template::locate_template('espresso-grid-template.template.php', $attributes);
     // now reset the query and postdata
     wp_reset_query();
     wp_reset_postdata();
     return $grid_template;
 }
 /**
  *    creates buttons for selecting number of attendees for an event
  *
  * @access 	public
  * @param 	object $event
  * @param 	bool 	$view_details
  * @return 	string
  */
 public static function display_ticket_selector($event = NULL, $view_details = FALSE)
 {
     // reset filter for displaying submit button
     remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
     // poke and prod incoming event till it tells us what it is
     if (!EED_Ticket_Selector::set_event($event)) {
         return false;
     }
     $event_post = self::$_event instanceof EE_Event ? self::$_event->ID() : $event;
     // grab event status
     $_event_active_status = self::$_event->get_active_status();
     if (!is_admin() && (!self::$_event->display_ticket_selector() || $view_details || post_password_required($event_post) || $_event_active_status != EE_Datetime::active && $_event_active_status != EE_Datetime::upcoming && $_event_active_status != EE_Datetime::sold_out && !($_event_active_status == EE_Datetime::inactive && is_user_logged_in()))) {
         return !is_single() ? EED_Ticket_Selector::display_view_details_btn() : '';
     }
     $template_args = array();
     $template_args['event_status'] = $_event_active_status;
     $template_args['date_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', get_option('date_format'));
     $template_args['time_format'] = apply_filters('FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', get_option('time_format'));
     $template_args['EVT_ID'] = self::$_event->ID();
     $template_args['event'] = self::$_event;
     // is the event expired ?
     $template_args['event_is_expired'] = self::$_event->is_expired();
     if ($template_args['event_is_expired']) {
         return '<div class="ee-event-expired-notice"><span class="important-notice">' . __('We\'re sorry, but all tickets sales have ended because the event is expired.', 'event_espresso') . '</span></div>';
     }
     $ticket_query_args = array(array('Datetime.EVT_ID' => self::$_event->ID()), 'order_by' => array('TKT_order' => 'ASC', 'TKT_required' => 'DESC', 'TKT_start_date' => 'ASC', 'TKT_end_date' => 'ASC', 'Datetime.DTT_EVT_start' => 'DESC'));
     if (!EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) {
         //use the correct applicable time query depending on what version of core is being run.
         $current_time = method_exists('EEM_Datetime', 'current_time_for_query') ? time() : current_time('timestamp');
         $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time);
     }
     // get all tickets for this event ordered by the datetime
     $template_args['tickets'] = EEM_Ticket::instance()->get_all($ticket_query_args);
     if (count($template_args['tickets']) < 1) {
         return '<div class="ee-event-expired-notice"><span class="important-notice">' . __('We\'re sorry, but all ticket sales have ended.', 'event_espresso') . '</span></div>';
     }
     // filter the maximum qty that can appear in the Ticket Selector qty dropdowns
     $template_args['max_atndz'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', self::$_event->additional_limit());
     if ($template_args['max_atndz'] < 1) {
         $sales_closed_msg = __('We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', 'event_espresso');
         if (current_user_can('edit_post', self::$_event->ID())) {
             $sales_closed_msg .= sprintf(__('%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', 'event_espresso'), '<div class="ee-attention" style="text-align: left;"><b>', '</b><br />', $link = '<span class="edit-link"><a class="post-edit-link" href="' . get_edit_post_link(self::$_event->ID()) . '">', '</a></span></div>');
         }
         return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>';
     }
     $templates['ticket_selector'] = TICKET_SELECTOR_TEMPLATES_PATH . 'ticket_selector_chart.template.php';
     $templates['ticket_selector'] = apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector__template_path', $templates['ticket_selector'], self::$_event);
     // redirecting to another site for registration ??
     $external_url = self::$_event->external_url() !== NULL || self::$_event->external_url() !== '' ? self::$_event->external_url() : FALSE;
     // set up the form (but not for the admin)
     $ticket_selector = !is_admin() ? EED_Ticket_Selector::ticket_selector_form_open(self::$_event->ID(), $external_url) : '';
     // if not redirecting to another site for registration
     if (!$external_url) {
         // then display the ticket selector
         $ticket_selector .= EEH_Template::locate_template($templates['ticket_selector'], $template_args);
     } else {
         // if not we still need to trigger the display of the submit button
         add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true');
         //display notice to admin that registration is external
         $ticket_selector .= !is_admin() ? '' : __('Registration is at an external URL for this event.', 'event_espresso');
     }
     // submit button and form close tag
     $ticket_selector .= !is_admin() ? EED_Ticket_Selector::display_ticket_selector_submit() : '';
     // set no cache headers and constants
     EE_System::do_not_cache();
     return $ticket_selector;
 }
 /**
  *    get_payment_details
  *
  * @access    public
  * @param    array $payments
  * @return    string
  */
 public function get_payment_details($payments = array())
 {
     //prepare variables for displaying
     $template_args = array();
     $template_args['transaction'] = $this->_current_txn;
     $template_args['reg_url_link'] = $this->_reg_url_link;
     $template_args['payments'] = array();
     foreach ($payments as $payment) {
         $template_args['payments'][] = $this->get_payment_row_html($payment);
     }
     //create a hacky payment object, but dont save it
     $payment = EE_Payment::new_instance(array('TXN_ID' => $this->_current_txn->ID(), 'STS_ID' => EEM_Payment::status_id_pending, 'PAY_timestamp' => time(), 'PAY_amount' => $this->_current_txn->total(), 'PMD_ID' => $this->_current_txn->payment_method_ID()));
     $payment_method = $this->_current_txn->payment_method();
     if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) {
         $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment);
     } else {
         $template_args['gateway_content'] = '';
     }
     // link to SPCO payment_options
     $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link;
     $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url;
     // verify template arguments
     EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction');
     EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments');
     EEH_Template_Validator::verify_isnt_null($template_args['show_try_pay_again_link'], '$show_try_pay_again_link');
     EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content');
     EEH_Template_Validator::verify_isnt_null($template_args['SPCO_payment_options_url'], '$SPCO_payment_options_url');
     return EEH_Template::locate_template(THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', $template_args, TRUE, TRUE);
 }
 /**
  * 	process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
  *
  *
  *
  * 	[ESPRESSO_EVENT_ATTENDEES] - defaults to attendees for earliest active event, or earliest upcoming event.
  * 	[ESPRESSO_EVENT_ATTENDEES event_id=123] - attendees for specific event.
  * 	[ESPRESSO_EVENT_ATTENDEES datetime_id=245] - attendees for a specific datetime.
  * 	[ESPRESSO_EVENT_ATTENDEES ticket_id=123] - attendees for a specific ticket.
  * 	[ESPRESSO_EVENT_ATTENDEES status=all] - specific registration status (use status id) or all for all attendees
  *                                          regardless of status.  Note default is to only return approved attendees
  * 	[ESPRESSO_EVENT_ATTENDEES show_gravatar=true] - default is to not return gravatar.  Otherwise if this is set
  *                                                  then return gravatar for email address given.
  *
  *  Note: because of the relationship between event_id, ticket_id, and datetime_id. If more than one of those params
  *  is included then preference is given to the following:
  *  - event_id is used whenever its present and any others are ignored.
  *  - if no event_id then datetime is used whenever its present and any others are ignored.
  *  - otherwise ticket_id is used if present.
  *
  *  @access 	public
  *  @param 	    array 	$attributes
  *  @return 	string
  */
 public function process_shortcode($attributes = array())
 {
     //load helpers
     EE_Registry::instance()->load_helper('Event_View');
     EE_Registry::instance()->load_helper('Template');
     // merge in any attributes passed via fallback shortcode processor
     $attributes = array_merge((array) $attributes, (array) $this->_attributes);
     //set default attributes
     $default_shortcode_attributes = array('event_id' => null, 'datetime_id' => null, 'ticket_id' => null, 'status' => EEM_Registration::status_id_approved, 'show_gravatar' => false);
     // allow the defaults to be filtered
     $default_shortcode_attributes = apply_filters('EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', $default_shortcode_attributes);
     // grab attributes and merge with defaults, then extract
     $attributes = array_merge($default_shortcode_attributes, $attributes);
     $template_args = array('contacts' => array(), 'event' => null, 'datetime' => null, 'ticket' => null, 'show_gravatar' => $attributes['show_gravatar']);
     //start setting up the query for the contacts
     $query = array();
     $error = false;
     //what event?
     if (empty($attributes['event_id']) && empty($attributes['datetime_id']) && empty($attributes['ticket_id'])) {
         //seems like is_espresso_event_single() isn't working as expected. So using alternate method.
         if (is_single() && is_espresso_event()) {
             $event = EEH_Event_View::get_event();
             if ($event instanceof EE_Event) {
                 $template_args['event'] = $event;
                 $query[0]['Registration.EVT_ID'] = $event->ID();
             }
         } else {
             //try getting the earliest active event if none then get the
             $events = EEM_Event::instance()->get_active_events(array('limit' => 1, 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC')));
             $events = empty($events) ? EEM_Event::instance()->get_upcoming_events(array('limit' => 1, 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'))) : $events;
             $event = reset($events);
             if ($event instanceof EE_Event) {
                 $query[0]['Registration.EVT_ID'] = $event->ID();
                 $template_args['event'] = $event;
             }
         }
     } elseif (!empty($attributes['event_id'])) {
         $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
         if ($event instanceof EE_Event) {
             $query[0]['Registration.EVT_ID'] = $attributes['event_id'];
             $template_args['event'] = $event;
         } else {
             $error = true;
         }
     }
     //datetime?
     if (!empty($attributes['datetime_id']) && empty($attributes['event_id'])) {
         $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
         if ($datetime instanceof EE_Datetime) {
             $query[0]['Registration.Ticket.Datetime.DTT_ID'] = $attributes['datetime_id'];
             $query['default_where_conditions'] = 'this_model_only';
             $template_args['datetime'] = $datetime;
             $template_args['event'] = $datetime->event();
         } else {
             $error = true;
         }
     }
     //ticket?just
     if (!empty($attributes['ticket_id']) && empty($attributes['event_id']) && empty($attributes['datetime_id'])) {
         $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
         if ($ticket instanceof EE_Ticket) {
             $query[0]['Registration.TKT_ID'] = $attributes['ticket_id'];
             $template_args['ticket'] = $ticket;
             $template_args['event'] = $ticket->first_datetime() instanceof EE_Datetime ? $ticket->first_datetime()->event() : null;
         } else {
             $error = true;
         }
     }
     //status
     $reg_status_array = EEM_Registration::reg_status_array();
     if ($attributes['status'] != 'all' && isset($reg_status_array[$attributes['status']])) {
         $query[0]['Registration.STS_ID'] = $attributes['status'];
     }
     $query['group_by'] = array('ATT_ID');
     $query['order_by'] = apply_filters('FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC'));
     //if we have NO query where conditions, then there was an invalid parameter or the shortcode was used incorrectly
     //so when WP_DEBUG is set and true, we'll show a message, otherwise we'll just return an empty string.
     if (!isset($query[0]) || !is_array($query[0]) || $error) {
         if (WP_DEBUG) {
             return '<div class="important-notice ee-attention">' . __('The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', 'event_espresso') . '</div>';
         } else {
             return '';
         }
     }
     //get contacts!
     $template_args['contacts'] = EEM_Attendee::instance()->get_all($query);
     //all set let's load up the template and return.
     return EEH_Template::locate_template('loop-espresso_event_attendees.php', $template_args, true, true);
 }
 /**
  * closing div tag for a form
  * @return string
  */
 public function layout_form_end()
 {
     if ($this->_layout_end_template_file) {
         EE_Registry::instance()->load_helper('Template');
         return EEH_Template::locate_template($this->_layout_end_template_file, $this->template_args(), TRUE, TRUE);
     } else {
         return parent::layout_form_end();
     }
 }
 /**
  *    template_include
  *
  * @access    public
  * @param   string $template_include_path
  * @return    string
  */
 public function template_include($template_include_path = NULL)
 {
     if (EE_Registry::instance()->REQ->is_espresso_page()) {
         $this->_template_path = !empty($this->_template_path) ? basename($this->_template_path) : basename($template_include_path);
         $template_path = EEH_Template::locate_template($this->_template_path, array(), false);
         $this->_template_path = !empty($template_path) ? $template_path : $template_include_path;
         $this->_template = basename($this->_template_path);
         return $this->_template_path;
     }
     return $template_include_path;
 }
 /**
  * Gets the string which represents the URL trigger for the invoice template in the message template system.
  * @param string $messenger 'pdf' or 'html'.  Default 'html'.
  * @return string
  */
 public function invoice_url($messenger = 'html')
 {
     /**
      * The below will be deprecated one version after this.  We check first if there is a custom invoice template already in use on old system.  If there is then we just return the standard url for it.
      *
      * @since 4.5.0
      */
     EE_Registry::instance()->load_helper('Template');
     $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php';
     $has_custom = EEH_Template::locate_template($template_relative_path, array(), TRUE, TRUE, TRUE);
     if ($has_custom) {
         if ($messenger == 'html') {
             return $this->invoice_url('launch');
         }
         $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice';
         $query_args = array('ee' => $route, 'id' => $this->reg_url_link());
         if ($messenger == 'html') {
             $query_args['html'] = TRUE;
         }
         return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id));
     }
     return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice');
 }
 /**
  *        load and display the Registration Single Page Checkout
  *
  * @access 	public
  * @param 	bool $from_admin
  * @return 	string
  */
 public function registration_checkout($from_admin = FALSE)
 {
     do_action('AHEE_log', __FILE__, __FUNCTION__, '');
     //d($this->_cart);
     EE_Registry::instance()->load_helper('Form_Fields');
     EE_Registry::instance()->load_helper('Template');
     EE_Registry::instance()->load_class('Question_Form_Input', array(), FALSE, FALSE, TRUE);
     $event_queue = array();
     $total_items = 0;
     $ticket_count = array();
     $payment_required = FALSE;
     $sold_out_events = array();
     $events_requiring_pre_approval = array();
     $additional_event_attendees = array();
     //		$events_that_use_coupon_codes = array();
     //		$events_that_use_groupon_codes = array();
     $template_args = array('css_class' => '', 'confirmation_data' => '', 'reg_page_discounts_dv_class' => 'hidden', 'additional_attendee_reg_info' => NULL, 'whats_in_the_cart' => '', 'prmy_att_input_name' => NULL);
     $event_queue['title'] = __('Registrations', 'event_espresso');
     $additional_attendee_forms = FALSE;
     $registrations = $this->_transaction->registrations(array(), TRUE);
     // grab the saved registrations from the transaction
     if ($this->_transaction instanceof EE_Transaction && $registrations !== NULL) {
         //d( $this->_transaction );
         $event_queue['has_items'] = TRUE;
         $prev_event = NULL;
         foreach ($registrations as $registration) {
             if (($registration->event()->is_sold_out() || $registration->event()->is_sold_out(TRUE)) && !$this->_reg_url_link == $registration->reg_url_link()) {
                 // add event to list of events that are sold out
                 $sold_out_events[$registration->event()->ID()] = '<li><span class="dashicons dashicons-marker ee-icon-size-16 pink-text"></span>' . $registration->event()->name() . '</li>';
             }
             $payment_required = $registration->status_ID() == EEM_Registration::status_id_pending_payment || $registration->status_ID() == EEM_Registration::status_id_approved ? TRUE : $payment_required;
             if (!$payment_required && !$this->_reg_url_link == $registration->reg_url_link()) {
                 // add event to list of events with pre-approval reg status
                 $events_requiring_pre_approval[$registration->event()->ID()] = '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' . $registration->event()->name() . '</li>';
             }
             $total_items++;
             $ticket_count[$registration->ticket()->ID()] = isset($ticket_count[$registration->ticket()->ID()]) ? $ticket_count[$registration->ticket()->ID()] + 1 : 1;
             $line_item_ID = $registration->reg_url_link();
             $event_queue['items'][$line_item_ID]['ticket'] = $registration->ticket();
             $event_queue['items'][$line_item_ID]['event'] = $registration->event();
             $event_queue['items'][$line_item_ID]['reg_count'] = $registration->count();
             // do we need to generate data regarding attendees and reg form questions?
             if (strpos($this->_current_step, 'attendee_information') !== FALSE) {
                 $question_meta = array('EVT_ID' => $registration->event()->ID(), 'att_nmbr' => $registration->count(), 'ticket_id' => $registration->ticket()->ID(), 'input_name' => '[' . $line_item_ID . ']', 'input_id' => $line_item_ID, 'input_class' => 'ee-reg-page-questions' . $template_args['css_class']);
                 $Question_Groups = EE_Registry::instance()->load_model('Question_Group')->get_all(array(array('Event.EVT_ID' => $registration->event()->ID(), 'Event_Question_Group.EQG_primary' => $registration->count() == 1 ? TRUE : FALSE), 'order_by' => array('QSG_order' => 'ASC')));
                 foreach ($Question_Groups as $QSG_ID => $Question_Group) {
                     $where = array('QST_deleted' => 0);
                     if (!$from_admin) {
                         $where['QST_admin_only'] = 0;
                     }
                     $Questions = $Question_Group->get_many_related('Question', array($where, 'order_by' => array('Question_Group_Question.QGQ_order' => 'ASC')));
                     foreach ($Questions as $Question) {
                         if ($Question instanceof EE_Question) {
                             // if this question was for an attendee detail, then check for that answer
                             $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value($registration, $Question->ID());
                             $answer = $this->_reg_url_link || !$answer_value ? EEM_Answer::instance()->get_one(array(array('QST_ID' => $Question->ID(), 'REG_ID' => $registration->ID()))) : NULL;
                             // if NOT returning to edit an existing registration OR if this question is for an attendee property OR we still don't have an EE_Answer object
                             if (!$this->_reg_url_link || $answer_value || !$answer instanceof EE_Answer) {
                                 // create an EE_Answer object for storing everything in
                                 $answer = EE_Answer::new_instance(array('QST_ID' => $Question->ID(), 'REG_ID' => $registration->ID()));
                             }
                             if ($answer instanceof EE_Answer) {
                                 if (!empty($answer_value)) {
                                     $answer->set('ANS_value', $answer_value);
                                 }
                                 $question_meta['attendee'][$Question->is_system_question() ? $Question->system_ID() : $Question->ID()] = $answer->value();
                                 $answer->cache('Question', $Question);
                                 $answer_cache_id = $Question->system_ID() != NULL ? $Question->system_ID() . '-' . $line_item_ID : $Question->ID() . '-' . $line_item_ID;
                                 //								echo '<h4>$answer_cache_id : ' . $answer_cache_id . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
                                 $registration->cache('Answer', $answer, $answer_cache_id);
                             }
                             $Question_Groups[$QSG_ID]->cache('Question', $Question);
                         }
                     }
                 }
                 //					printr( $registration, '$registration  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
                 add_filter('FHEE__EEH_Form_Fields__label_html', array('EED_Single_Page_Checkout', 'reg_form_form_field_label_wrap'), 10, 2);
                 add_filter('FHEE__EEH_Form_Fields__input_html', array('EED_Single_Page_Checkout', 'reg_form_form_field_input__wrap'), 10, 2);
                 $attendee_questions = EEH_Form_Fields::generate_question_groups_html2($Question_Groups, $question_meta, $from_admin, 'div');
                 // show this attendee form?
                 if (empty($attendee_questions)) {
                     $event_queue['items'][$line_item_ID]['additional_attendee_reg_info'] = "\n" . '<input type="hidden" id="' . $line_item_ID . '-additional_attendee_reg_info" name="qstn[' . $line_item_ID . '][additional_attendee_reg_info]" value="0" />' . "\n";
                 } else {
                     $additional_attendee_forms = $registration->count() == 1 ? FALSE : TRUE;
                     $event_queue['items'][$line_item_ID]['additional_attendee_reg_info'] = '';
                 }
                 $event_queue['items'][$line_item_ID]['attendee_questions'] = $attendee_questions;
                 // is this the primary registrant ?
                 if ($registration->count() == 1) {
                     // grab line item from primary attendee
                     $template_args['prmy_att_input_name'] = $line_item_ID;
                 } else {
                     // for all  attendees other than the primary attendee
                     $additional_event_attendees[$registration->ticket()->ID()][$line_item_ID] = array('ticket' => $registration->ticket()->name(), 'att_nmbr' => $registration->count(), 'input_id' => $line_item_ID, 'input_name' => '[' . $line_item_ID . ']');
                     $item_name = $registration->ticket()->name();
                     $item_name .= $registration->ticket()->description() != '' ? ' - ' . $registration->ticket()->description() : '';
                     // if this is a new ticket OR if this is the very first additional attendee after the primary attendee
                     if ($registration->ticket()->ID() != $prev_event || $registration->count() == 2) {
                         $additional_event_attendees[$registration->ticket()->ID()][$line_item_ID]['event_hdr'] = $item_name;
                         $prev_event = $registration->ticket()->ID();
                     } else {
                         // no heading
                         $additional_event_attendees[$registration->ticket()->ID()][$line_item_ID]['event_hdr'] = FALSE;
                     }
                 }
             }
         }
         if (!$this->_reg_url_link) {
             EE_Registry::instance()->SSN->set_session_data(array('transaction' => $this->_transaction));
         }
         //				echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
         //				EE_Registry::instance()->SSN->update();
         //				d( $this->_transaction );
         //				d( $this->_cart );
     } else {
         // empty
         $event_queue['has_items'] = FALSE;
     }
     // sold_out_events
     $template_args['sold_out_events'] = implode($sold_out_events);
     $template_args['sold_out_events_msg'] = apply_filters('FHEE__Single_Page_Checkout__registration_checkout__sold_out_events_msg', __('It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso'));
     // events_requiring_pre_approval
     $template_args['events_requiring_pre_approval'] = implode($events_requiring_pre_approval);
     $template_args['events_requiring_pre_approval_msg'] = apply_filters('FHEE__Single_Page_Checkout__registration_checkout__sold_out_events_msg', __('The following events do not require payment at this time and will not be billed during this transaction. Billing will only occur after the attendee has been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', 'event_espresso'));
     //  GOT COUPONS ?
     $template_args['events_that_use_coupon_codes'] = '';
     $template_args['use_coupon_codes'] = FALSE;
     // Groupons ?
     $template_args['events_that_use_groupon_codes'] = '';
     $template_args['use_groupon_codes'] = FALSE;
     $template_args['spco_reg_page_ajax_coupons_url'] = add_query_arg(array('ee' => 'apply_coupon'), $this->_reg_page_base_url);
     //		$template_args['print_copy_info'] = $additional_attendee_forms || $total_items > 2 ? TRUE : FALSE;
     $template_args['total_items'] = $total_items;
     $template_args['ticket_count'] = $ticket_count;
     $template_args['print_copy_info'] = $additional_attendee_forms;
     //		d($additional_event_attendees);
     $template_args['additional_event_attendees'] = $additional_event_attendees;
     // total monies paid to date
     $total_payments = 0;
     // the original total
     $cart_total_before_tax = $this->_cart->get_cart_total_before_tax();
     // get cart total
     $grand_total = $this->_cart->get_cart_grand_total();
     $template_args['grand_total'] = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__grand_total', $grand_total);
     // check if monies are potentially owing
     $template_args['payment_required'] = $cart_total_before_tax > 0 ? $payment_required : FALSE;
     // not a free event?
     if ($template_args['payment_required']) {
         //check for any previous payments
         if ($template_args['payments'] = $this->_transaction->approved_payments()) {
             foreach ($template_args['payments'] as $payment) {
                 if ($payment instanceof EE_Payment) {
                     // increment total payments
                     $total_payments += $payment->amount();
                 }
             }
             $template_args['pay_date_frmt'] = get_option('date_format') . ' ' . get_option('time_format');
         }
     } else {
         //unset( self::$_reg_steps['payment_options'] );
         EE_Registry::instance()->SSN->set_session_data(array('billing_info' => 'no payment required'));
         $template_args['payments'] = array();
     }
     $template_args['sub_total'] = $cart_total_before_tax;
     $template_args['taxes'] = $this->_cart->get_taxes_line_item()->children();
     // what's left to pay?
     $amount_owing = $grand_total - $total_payments;
     $template_args['amount_owing'] = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__amount_owing', $amount_owing);
     //$template_args['grand_total'] = $template_args['amount_owing'] !== FALSE ? $amount_owing : $grand_total;
     $template_args['total_items'] = $event_queue['total_items'] = $total_items;
     //	d( $event_queue );
     $template_args['event_queue'] = $event_queue;
     $template_args['images_dir_url'] = EE_GLOBAL_ASSETS_URL . 'images/';
     $template_args['reg_url_link'] = $this->_reg_url_link;
     $template_args['return_url'] = add_query_arg(array('ee' => 'event_queue'), $this->_reg_page_base_url);
     $template_args['update_url'] = add_query_arg(array('ee' => 'update_event_queue'), $this->_reg_page_base_url);
     $template_args['register_url'] = add_query_arg(array('ee' => '_register'), $this->_reg_page_base_url);
     $template_args['event_queue_url'] = add_query_arg(array('ee' => 'event_queue'), $this->_reg_page_base_url);
     $template_args['confirmation_data'] = $this->_current_step == 'registration_confirmation' ? $this->_registration_confirmation() : '';
     $step_or_revisit = __('Step ', 'event_espresso');
     if ($this->_revisit && $this->_current_step == 'attendee_information') {
         // Update Registration Details
         $confirmation_btn_text = sprintf(__('Update%1$sRegistration%1$sDetails', 'event_espresso'), '&nbsp;');
         $confirmation_btn_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__update_registration_details', $confirmation_btn_text);
         $step_or_revisit = __('Edit', 'event_espresso');
     } else {
         if ($this->_revisit && $this->_current_step == 'payment_options') {
             // Process Payment
             $confirmation_btn_text = sprintf(__('Process%1$sPayment', 'event_espresso'), '&nbsp;');
             $confirmation_btn_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__process_payment', $confirmation_btn_text);
             $step_or_revisit = '';
         } else {
             // Finalize Registration
             $confirmation_btn_text = sprintf(__('Finalize%1$sRegistration', 'event_espresso'), '&nbsp;');
             $confirmation_btn_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__finalize_registration', $confirmation_btn_text);
         }
     }
     // grand total less than paid but greater than zero ?
     if ($grand_total < $this->_transaction->paid() && $grand_total > 0 && $this->_next_step == 'payment_options') {
         // owing money
         $proceed_to_payment_btn_text = sprintf(__('%1$s%2$s%1$sProceed%1$sto%1$sPayment', 'event_espresso'), '&nbsp;', '&amp;');
         $confirmation_btn_text .= apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__and_proceed_to_payment', $proceed_to_payment_btn_text);
     }
     add_action('AHEE__SPCO_after_reg_step_form', array($this, 'add_extra_finalize_registration_inputs'), 10, 2);
     $template_args['from_admin'] = $from_admin;
     //if in admin we exit at this point and display the questions template
     if ($from_admin) {
         //some custom template args
         $template_args['step_dv_class'] = '';
         $template_args['revisit'] = $this->_revisit;
         return EEH_Template::display_template($this->_templates['registration_page_attendee_information'], $template_args, TRUE);
     }
     $proceed_to_btn_text = sprintf(__('Proceed%1$sto%1$s', 'event_espresso'), '&nbsp;');
     $proceed_to_btn_text = apply_filters('FHEE__EED_Single_Page_Checkout__registration_checkout__button_text__proceed_to', $proceed_to_btn_text);
     $registration_steps = '';
     $step_nmbr = 1;
     // set pointer to first step
     reset(self::$_reg_steps);
     // loop through steps
     while ($reg_step_details = current(self::$_reg_steps)) {
         $reg_step = key(self::$_reg_steps);
         //			echo '<br/><h4>$reg_step : ' . $reg_step . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
         //			echo '<h4>$this->_current_step : ' . $this->_current_step . '  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>';
         $edit_lnk_class = $this->_current_step == $reg_step ? ' hidden' : '';
         $edit_lnk_url = add_query_arg(array('ee' => '_register', 'step' => $reg_step_details['display_func']), $this->_reg_page_base_url);
         $step_dv_class = $this->_current_step == $reg_step ? '' : ' hidden';
         $reg_step_form_url = add_query_arg(array('ee' => '_register', 'step' => $reg_step_details['process_func']), $this->_reg_page_base_url);
         $next = $this->_get_next_reg_step();
         //d( $next );
         $next_step = $next ? $next['display_func'] : 'finalize_registration';
         $next_step_text = $next ? $proceed_to_btn_text . $next['name'] : $confirmation_btn_text;
         $step_args = array_merge($template_args, array('step' => $reg_step, 'step_nmbr' => $this->_revisit !== FALSE ? $step_or_revisit : $step_or_revisit . $step_nmbr . ' - ', 'edit_lnk_class' => $edit_lnk_class, 'edit_lnk_url' => $edit_lnk_url, 'step_dv_class' => $step_dv_class, 'reg_step_form_url' => $reg_step_form_url, 'reg_step_ajax_action' => $reg_step_details['process_func'], 'next_step' => $next_step, 'next_step_text' => $next_step_text, 'revisit' => $this->_revisit));
         if ($reg_step == 'payment_options') {
             EE_Registry::instance()->load_model('Gateways');
             // has gateway been set by no-js user?
             if (EE_Registry::instance()->REQ->is_set('payment')) {
                 if ($payment = sanitize_text_field(EE_Registry::instance()->REQ->get('payment'))) {
                     //						d( $payment );
                     if (EE_Registry::instance()->LIB->EEM_Gateways->selected_gateway() != $payment) {
                         EE_Registry::instance()->LIB->EEM_Gateways->set_selected_gateway($payment);
                     } else {
                         EE_Registry::instance()->LIB->EEM_Gateways->unset_selected_gateway($payment);
                     }
                 }
             }
             $step_args['selected_gateway'] = EE_Registry::instance()->LIB->EEM_Gateways->selected_gateway();
         } else {
             $step_args['selected_gateway'] = '';
         }
         //			printr( $step_args, '$step_args  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
         //			d( $step_args );
         $registration_steps .= EEH_Template::locate_template($this->_templates[$reg_step_details['template']], $step_args, TRUE, TRUE);
         // pass step info to js
         EE_Registry::$i18n_js_strings['reg_steps'][] = $reg_step_details['display_func'];
         next(self::$_reg_steps);
         $step_nmbr++;
     }
     EE_Registry::$i18n_js_strings['reg_steps'][] = 'finalize_registration';
     $wrapper_args = array('step' => $this->_current_step, 'empty_cart' => $total_items < 1 ? TRUE : FALSE, 'reg_steps' => self::$_reg_steps, 'registration_steps' => $registration_steps, 'revisit' => $this->_revisit, 'empty_msg' => apply_filters('FHEE__Single_Page_Checkout__registration_checkout__empty_msg', __('You need to select at least one event before you can proceed with the registration process.', 'event_espresso')));
     //		d( $wrapper_args );
     EE_Registry::instance()->REQ->add_output(EEH_Template::locate_template($this->_templates['registration_page_wrapper'], $wrapper_args, TRUE, TRUE));
 }
 /**
  * auto_copy_attendee_info
  *
  * @access public
  * @return 	EE_Form_Section_Proper
  */
 public function auto_copy_attendee_info()
 {
     return new EE_Form_Section_HTML(EEH_Template::locate_template(SPCO_TEMPLATES_PATH . 'attendee_information' . DS . 'auto_copy_attendee_info.template.php', apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', array()), TRUE, TRUE));
 }
 public function send_invoice($download = FALSE)
 {
     $template_args = array();
     $EE = EE_Registry::instance();
     //allow the request to override the default theme defined in the invoice settings
     $theme_requested = isset($_REQUEST['theme']) && $_REQUEST['theme'] > 0 && $_REQUEST['theme'] < 8 ? absint($_REQUEST['theme']) : null;
     $themes = array(1 => "simple.css", 2 => "bauhaus.css", 3 => "ejs.css", 4 => "horizon.css", 5 => "lola.css", 6 => "tranquility.css", 7 => "union.css");
     //Get the CSS file
     if (isset($themes[$theme_requested])) {
         $template_args['invoice_css'] = $themes[$theme_requested];
     } else {
         $template_args['invoice_css'] = $this->invoice_payment_method->get_extra_meta('legacy_invoice_css', TRUE, 'simple.css');
     }
     if (is_dir(EVENT_ESPRESSO_GATEWAY_DIR . '/invoice')) {
         $template_args['base_url'] = EVENT_ESPRESSO_GATEWAY_URL . 'Invoice/lib/templates/';
     } else {
         $template_args['base_url'] = EE_GATEWAYS . '/Invoice/lib/templates/';
     }
     $primary_attendee = $this->transaction->primary_registration()->attendee();
     $template_args['organization'] = $EE->CFG->organization->get_pretty('name');
     $template_args['street'] = empty($EE->CFG->organization->address_2) ? $EE->CFG->organization->get_pretty('address_1') : $EE->CFG->organization->get_pretty('address_1') . '<br>' . $EE->CFG->organization->get_pretty('address_2');
     $template_args['city'] = $EE->CFG->organization->get_pretty('city');
     $template_args['state'] = EE_Registry::instance()->load_model('State')->get_one_by_ID($EE->CFG->organization->STA_ID);
     $template_args['country'] = EE_Registry::instance()->load_model('Country')->get_one_by_ID($EE->CFG->organization->CNT_ISO);
     $template_args['zip'] = $EE->CFG->organization->get_pretty('zip');
     $template_args['email'] = $EE->CFG->organization->get_pretty('email');
     $template_args['registration_code'] = $this->registration->reg_code();
     $template_args['registration_date'] = $this->registration->date();
     $template_args['name'] = $primary_attendee->full_name();
     $template_args['attendee_address'] = $primary_attendee->address();
     $template_args['attendee_address2'] = $primary_attendee->address2();
     $template_args['attendee_city'] = $primary_attendee->city();
     $attendee_state = $primary_attendee->state_obj();
     if ($attendee_state) {
         $attendee_state_name = $attendee_state->name();
     } else {
         $attendee_state_name = '';
     }
     $template_args['attendee_state'] = $attendee_state_name;
     $template_args['attendee_zip'] = $primary_attendee->zip();
     $template_args['ship_name'] = $template_args['name'];
     $template_args['ship_address'] = $template_args['attendee_address'];
     $template_args['ship_city'] = $template_args['attendee_city'];
     $template_args['ship_state'] = $template_args['attendee_state'];
     $template_args['ship_zip'] = $template_args['attendee_zip'];
     $template_args['total_cost'] = number_format($this->transaction->total(), 2, '.', '');
     $template_args['transaction'] = $this->transaction;
     $template_args['amount_pd'] = $this->transaction->paid();
     $template_args['amount_owed'] = $this->transaction->total() - $this->transaction->paid();
     $template_args['payments'] = $this->transaction->approved_payments();
     $template_args['net_total'] = '';
     $template_args['edit_reg_info_url'] = $this->registration->edit_attendee_information_url();
     $template_args['retry_payment_url'] = $this->registration->payment_overview_url();
     $template_args['show_line_item_description'] = $this->check_if_any_line_items_have_a_description($this->transaction->total_line_item());
     if ($template_args['amount_pd'] != $template_args['total_cost']) {
         //$template_args['net_total'] = $this->espressoInvoiceTotals( __('SubTotal', 'event_espresso'), $this->transaction->total());//$this->session_data['cart']['REG']['sub_total']);
         $tax_items = $this->transaction->tax_items();
         if (!empty($tax_items)) {
             foreach ($tax_items as $tax) {
                 $template_args['net_total'] .= $this->espressoInvoiceTotals($tax->name(), $tax->total());
             }
         }
         $difference = $template_args['amount_pd'] - $template_args['total_cost'];
         if ($difference < 0) {
             $text = __('Discount', 'event_espresso');
         } else {
             $text = __('Extra', 'event_espresso');
         }
         $template_args['discount'] = $this->espressoInvoiceTotals($text, $difference);
     }
     $template_args['currency_symbol'] = $EE->CFG->currency->sign;
     $template_args['template_payment_instructions'] = wpautop(stripslashes_deep(html_entity_decode($this->invoice_payment_method->get_extra_meta('pdf_instructions', TRUE), ENT_QUOTES)));
     $template_args['shameless_plug'] = apply_filters('FHEE_Invoice__send_invoice__shameless_plug', true);
     if (isset($_GET['receipt'])) {
         //receipt-specific stuff
         $events_for_txn = EEM_Event::instance()->get_all(array(array('Registration.TXN_ID' => $this->transaction->ID())));
         $ticket_line_items_per_event = array();
         $registrations_per_line_item = array();
         $venues_for_events = array();
         foreach ($events_for_txn as $event_id => $event) {
             $line_items_for_this_event = EEM_Line_Item::instance()->get_all(array(array('Ticket.Datetime.EVT_ID' => $event_id, 'TXN_ID' => $this->transaction->ID())));
             $ticket_line_items_per_event[$event_id] = $line_items_for_this_event;
             foreach ($line_items_for_this_event as $line_item_id => $line_item) {
                 $ticket = $line_item->ticket();
                 $registrations_for_this_ticket = EEM_Registration::instance()->get_all(array(array('TKT_ID' => $ticket->ID(), 'TXN_ID' => $this->transaction->ID())));
                 $registrations_per_line_item[$line_item_id] = $registrations_for_this_ticket;
             }
             $venues_for_events = array_merge($venues_for_events, $event->venues());
         }
         $tax_total_line_item = EEM_Line_Item::instance()->get_one(array(array('TXN_ID' => $this->transaction->ID(), 'LIN_type' => EEM_Line_Item::type_tax_sub_total)));
         $questions_to_skip = array(EEM_Attendee::system_question_fname, EEM_Attendee::system_question_lname, EEM_Attendee::system_question_email);
         $template_args['events_for_txn'] = $events_for_txn;
         $template_args['ticket_line_items_per_event'] = $ticket_line_items_per_event;
         $template_args['registrations_per_line_item'] = $registrations_per_line_item;
         $template_args['venues_for_events'] = $venues_for_events;
         $template_args['tax_total_line_item'] = $tax_total_line_item;
         $template_args['questions_to_skip'] = $questions_to_skip;
         //			d($template_args);
         $template_args['download_link'] = $this->registration->receipt_url('download');
     } else {
         //it's just an invoice we're accessing
         $template_args['download_link'] = $this->registration->invoice_url('download');
     }
     //Get the HTML as an object
     $templates_relative_path = 'modules/gateways/Invoice/lib/templates/';
     $template_header = EEH_Template::locate_template($templates_relative_path . 'invoice_header.template.php', $template_args, TRUE, TRUE);
     if (isset($_GET['receipt'])) {
         $template_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', $template_args, TRUE, TRUE);
     } else {
         $template_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', $template_args, TRUE, TRUE);
     }
     $template_footer = EEH_Template::locate_template($templates_relative_path . 'invoice_footer.template.php', $template_args, TRUE, TRUE);
     $copies = !empty($_REQUEST['copies']) ? $_REQUEST['copies'] : 1;
     $content = $this->espresso_replace_invoice_shortcodes($template_header);
     for ($x = 1; $x <= $copies; $x++) {
         $content .= $this->espresso_replace_invoice_shortcodes($template_body);
     }
     $content .= $this->espresso_replace_invoice_shortcodes($template_footer);
     //Check if debugging or mobile is set
     if (!empty($_REQUEST['html'])) {
         echo $content;
         exit(0);
     }
     $invoice_name = $template_args['organization'] . ' ' . __('Invoice #', 'event_espresso') . $template_args['registration_code'] . __(' for ', 'event_espresso') . $template_args['name'];
     $invoice_name = str_replace(' ', '_', $invoice_name);
     //Create the PDF
     if (array_key_exists('html', $_GET)) {
         echo $content;
     } else {
         //only load dompdf if nobody else has yet...
         if (!defined('DOMPDF_DIR')) {
             define('DOMPDF_ENABLE_REMOTE', TRUE);
             define('DOMPDF_ENABLE_JAVASCRIPT', FALSE);
             define('DOMPDF_ENABLE_CSS_FLOAT', TRUE);
             require_once EE_THIRD_PARTY . 'dompdf/dompdf_config.inc.php';
         }
         $dompdf = new DOMPDF();
         $dompdf->load_html($content);
         $dompdf->render();
         $dompdf->stream($invoice_name . ".pdf", array('Attachment' => $download));
     }
     exit(0);
 }
 /**
  * 	event_venues - adds venues BELOW content
  *
  *  	@access 	public
  * 	@param		string 	$content
  *  	@return 		string
  */
 public static function event_venues($content)
 {
     if (post_password_required()) {
         return $content;
     }
     return $content . EEH_Template::locate_template('content-espresso_events-venues.php');
 }
 /**
  * _auto_copy_attendee_info
  *
  * @access public
  * @return 	EE_Form_Section_Proper
  */
 private function _auto_copy_attendee_info()
 {
     return new EE_Form_Section_HTML(EEH_Template::locate_template(SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', apply_filters('FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', array()), TRUE, TRUE));
 }