/**
  * 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;
     // ==================
     // = 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 = '';
     $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 {
         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) {
                 throw $excpt;
             }
             $event = new Ai1ec_Event($translatable_id, $instance_id);
         }
         // 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;
         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
     $timezone = $ai1ec_events_helper->get_gmt_offset();
     $timezone = sprintf('(GMT%+d:%02d)', intval($timezone), abs($timezone) * 60 % 60);
     // 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, '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, 'ticket_url' => $ticket_url);
     $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);
     $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);
     }
     // 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);
 }