/**
  * Handle AJAX request to display front-end create event form content.
  *
  * @return null
  */
 public function get_front_end_create_event_form()
 {
     global $ai1ec_view_helper, $ai1ec_settings;
     $date_format_pattern = Ai1ec_Time_Utility::get_date_pattern_by_key($ai1ec_settings->input_date_format);
     $week_start_day = get_option('start_of_week');
     $input_24h_time = $ai1ec_settings->input_24h_time;
     $cat_select = $this->get_html_for_category_selector();
     $tag_select = $this->get_html_for_tag_selector();
     $form_action = admin_url('admin-ajax.php?action=ai1ec_front_end_submit_event');
     $default_image = $ai1ec_view_helper->get_theme_img_url('default-event-avatar.png');
     if (!is_user_logged_in() && $ai1ec_settings->allow_anonymous_submissions && $ai1ec_settings->recaptcha_key !== '') {
         $recaptcha_key = $ai1ec_settings->recaptcha_public_key;
     } else {
         $recaptcha_key = false;
     }
     $allow_uploads = is_user_logged_in() || $ai1ec_settings->allow_anonymous_submissions && $ai1ec_settings->allow_anonymous_uploads;
     $args = array('date_format_pattern' => $date_format_pattern, 'week_start_day' => $week_start_day, 'input_24h_time' => $input_24h_time, 'cat_select' => $cat_select, 'tag_select' => $tag_select, 'form_action' => $form_action, 'interactive_gmaps' => !$ai1ec_settings->disable_autocompletion, 'default_image' => $default_image, 'recaptcha_key' => $recaptcha_key, 'allow_uploads' => $allow_uploads, 'timezone_expr' => Ai1ec_Time_Utility::get_gmt_offset_expr(), 'require_disclaimer' => $ai1ec_settings->require_disclaimer, 'disclaimer' => $ai1ec_settings->disclaimer);
     $ai1ec_view_helper->display_theme('create-event-form.php', $args);
     exit(0);
 }
 /**
  * Add Event Details meta box to the Add/Edit Event screen in the dashboard.
  *
  * @return void
  */
 public function meta_box_view()
 {
     global $ai1ec_view_helper, $ai1ec_events_helper, $post, $wpdb, $ai1ec_settings, $ai1ec_importer_plugin_helper;
     $empty_event = new Ai1ec_Event();
     // ==================
     // = Default values =
     // ==================
     // ATTENTION - When adding new fields to the event remember that you must
     // also set up the duplicate-controller.
     // TODO: Fix this duplication.
     $all_day_event = '';
     $instant_event = '';
     $start_timestamp = '';
     $end_timestamp = '';
     $show_map = false;
     $google_map = '';
     $venue = '';
     $country = '';
     $address = '';
     $city = '';
     $province = '';
     $postal_code = '';
     $contact_name = '';
     $contact_phone = '';
     $contact_email = '';
     $contact_url = '';
     $cost = '';
     $is_free = 'checked="checked"';
     $rrule = '';
     $rrule_text = '';
     $repeating_event = false;
     $exrule = '';
     $exrule_text = '';
     $exclude_event = false;
     $exdate = '';
     $show_coordinates = false;
     $longitude = '';
     $latitude = '';
     $coordinates = '';
     $ticket_url = '';
     $instance_id = false;
     if (isset($_REQUEST['instance'])) {
         $instance_id = absint($_REQUEST['instance']);
     }
     $parent_event_id = $ai1ec_events_helper->event_parent($post->ID);
     if ($instance_id) {
         add_filter('print_scripts_array', array($ai1ec_view_helper, 'disable_autosave'));
     }
     try {
         // on some php version, nested try catch blocks fail and the exception would never be caught.
         // this is why we use this approach.
         $excpt = NULL;
         try {
             $event = new Ai1ec_Event($post->ID, $instance_id);
         } catch (Ai1ec_Event_Not_Found $excpt) {
             global $ai1ec_localization_helper;
             $translatable_id = $ai1ec_localization_helper->get_translatable_id();
             if (false !== $translatable_id) {
                 $event = new Ai1ec_Event($translatable_id, $instance_id);
             }
         }
         if (NULL !== $excpt) {
             throw $excpt;
         }
         // Existing event was found. Initialize form values with values from
         // event object.
         $all_day_event = $event->allday ? 'checked' : '';
         $instant_event = $event->instant_event ? 'checked' : '';
         $start_timestamp = $ai1ec_events_helper->gmt_to_local($event->start);
         $end_timestamp = $ai1ec_events_helper->gmt_to_local($event->end);
         $multi_day = $event->get_multiday();
         $show_map = $event->show_map;
         $google_map = $show_map ? 'checked="checked"' : '';
         $show_coordinates = $event->show_coordinates;
         $coordinates = $show_coordinates ? 'checked="checked"' : '';
         $longitude = $event->longitude !== NULL ? floatval($event->longitude) : '';
         $latitude = $event->latitude !== NULL ? floatval($event->latitude) : '';
         // There is a known bug in Wordpress (https://core.trac.wordpress.org/ticket/15158) that saves 0 to the DB instead of null.
         // We handle a special case here to avoid having the fields with a value of 0 when the user never inputted any coordinates
         if (!$show_coordinates) {
             $longitude = '';
             $latitude = '';
         }
         $venue = $event->venue;
         $country = $event->country;
         $address = $event->address;
         $city = $event->city;
         $province = $event->province;
         $postal_code = $event->postal_code;
         $contact_name = $event->contact_name;
         $contact_phone = $event->contact_phone;
         $contact_email = $event->contact_email;
         $contact_url = $event->contact_url;
         $cost = $event->cost;
         $ticket_url = $event->ticket_url;
         $rrule = empty($event->recurrence_rules) ? '' : $ai1ec_events_helper->ics_rule_to_local($event->recurrence_rules);
         $exrule = empty($event->exception_rules) ? '' : $ai1ec_events_helper->ics_rule_to_local($event->exception_rules);
         $exdate = empty($event->exception_dates) ? '' : $ai1ec_events_helper->exception_dates_to_local($event->exception_dates);
         $repeating_event = empty($rrule) ? false : true;
         $exclude_event = empty($exrule) ? false : true;
         $facebook_status = $event->facebook_status;
         $is_free = '';
         if (!empty($event->is_free)) {
             $is_free = 'checked="checked" ';
             $cost = '';
         }
         if ($repeating_event) {
             $rrule_text = ucfirst($ai1ec_events_helper->rrule_to_text($rrule));
         }
         if ($exclude_event) {
             $exrule_text = ucfirst($ai1ec_events_helper->rrule_to_text($exrule));
         }
     } catch (Ai1ec_Event_Not_Found $e) {
         // Event does not exist.
         // Leave form fields undefined (= zero-length strings)
         $event = null;
     }
     // Time zone; display if set.
     $timezone = '';
     $timezone_string = Ai1ec_Meta::get_option('timezone_string');
     if ($timezone_string) {
         $timezone = Ai1ec_Time_Utility::get_gmt_offset_expr();
     }
     // This will store each of the accordion tabs' markup, and passed as an
     // argument to the final view.
     $boxes = array();
     // ===============================
     // = Display event time and date =
     // ===============================
     $args = array('all_day_event' => $all_day_event, 'instant_event' => $instant_event, 'start_timestamp' => $start_timestamp, 'end_timestamp' => $end_timestamp, 'repeating_event' => $repeating_event, 'rrule' => $rrule, 'rrule_text' => $rrule_text, 'exclude_event' => $exclude_event, 'exrule' => $exrule, 'exrule_text' => $exrule_text, 'timezone' => $timezone, 'timezone_string' => $timezone_string, 'exdate' => $exdate, 'parent_event_id' => $parent_event_id, 'instance_id' => $instance_id);
     $boxes[] = $ai1ec_view_helper->get_admin_view('box_time_and_date.php', $args);
     // =================================================
     // = Display event location details and Google map =
     // =================================================
     $args = array('venue' => $venue, 'country' => $country, 'address' => $address, 'city' => $city, 'province' => $province, 'postal_code' => $postal_code, 'google_map' => $google_map, 'show_map' => $show_map, 'show_coordinates' => $show_coordinates, 'longitude' => $longitude, 'latitude' => $latitude, 'coordinates' => $coordinates);
     $boxes[] = $ai1ec_view_helper->get_admin_view('box_event_location.php', $args);
     // ======================
     // = Display event cost =
     // ======================
     $args = array('cost' => $cost, 'is_free' => $is_free, 'ticket_url' => $ticket_url, 'event' => $empty_event);
     $boxes[] = $ai1ec_view_helper->get_admin_view('box_event_cost.php', $args);
     // =========================================
     // = Display organizer contact information =
     // =========================================
     $args = array('contact_name' => $contact_name, 'contact_phone' => $contact_phone, 'contact_email' => $contact_email, 'contact_url' => $contact_url, 'event' => $empty_event);
     $boxes[] = $ai1ec_view_helper->get_admin_view('box_event_contact.php', $args);
     /*
     	TODO Display Eventbrite ticketing
     	$ai1ec_view_helper->display( 'box_eventbrite.php' );
     */
     // ==================
     // = Publish button =
     // ==================
     $publish_button = '';
     if ($ai1ec_settings->show_publish_button) {
         $args = array();
         $post_type = $post->post_type;
         $post_type_object = get_post_type_object($post_type);
         if (current_user_can($post_type_object->cap->publish_posts)) {
             $args['button_value'] = is_null($event) ? __('Publish', AI1EC_PLUGIN_NAME) : __('Update', AI1EC_PLUGIN_NAME);
         } else {
             $args['button_value'] = __('Submit for Review', AI1EC_PLUGIN_NAME);
         }
         $publish_button = $ai1ec_view_helper->get_admin_view('box_publish_button.php', $args);
     }
     // ==========================
     // = Parent/Child relations =
     // ==========================
     if ($event) {
         $parent = $ai1ec_events_helper->get_parent_event($event->post_id);
         if ($parent) {
             try {
                 $parent = new Ai1ec_Event($parent);
             } catch (Ai1ec_Event_Not_Found $exception) {
                 // ignore
                 $parent = NULL;
             }
         }
         $children = $ai1ec_events_helper->get_child_event_objects($event->post_id);
         $args = compact('parent', 'children');
         $boxes[] = $ai1ec_view_helper->get_admin_view('box_event_children.php', $args);
     }
     // Display the final view of the meta box.
     $args = array('boxes' => $boxes, 'publish_button' => $publish_button);
     $ai1ec_view_helper->display_admin('add_new_event_meta_box.php', $args);
 }