function my_calendar_show_event($atts)
{
    extract(shortcode_atts(array('event' => '', 'template' => '<h3>{title}</h3>{description}', 'list' => '<li>{date}, {time}</li>', 'before' => '<ul>', 'after' => '</ul>'), $atts, 'my_calendar_event'));
    return mc_instance_list($event, false, $template, $list, $before, $after);
}
function mc_form_fields($data, $mode, $event_id)
{
    global $wpdb, $user_ID;
    $mcdb = $wpdb;
    $has_data = empty($data) ? false : true;
    if ($data) {
        $test = mc_test_occurrence_overlap($data);
    }
    $instance = isset($_GET['date']) ? (int) $_GET['date'] : false;
    if ($instance) {
        $ins = mc_get_instance_data($instance);
        $event_id = $ins->occur_event_id;
        $data = mc_get_event_core($event_id);
    }
    ?>

	<div class="postbox-container jcd-wide">
		<div class="metabox-holder">
		<?php 
    if ($mode == 'add' || $mode == 'copy') {
        $query_args = array();
    } else {
        $query_args = array('mode' => $mode, 'event_id' => $event_id);
        if ($instance) {
            $query_args['date'] = $instance;
        }
    }
    echo apply_filters('mc_before_event_form', '', $event_id);
    $action = add_query_arg($query_args, admin_url('admin.php?page=my-calendar'));
    if (!empty($data->event_group_id) && $mode != 'copy') {
        $group_id = $data->event_group_id;
    } else {
        $group_id = mc_group_id();
    }
    if ($mode != 'edit') {
        $event_author = $user_ID;
    } else {
        $event_author = $data->event_author;
    }
    ?>
<form id="my-calendar" method="post" action="<?php 
    echo $action;
    ?>
">
<div>
	<input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
" />
	<?php 
    if (isset($_GET['ref'])) {
        ?>
		<input type="hidden" name="ref" value="<?php 
        echo esc_url($_GET['ref']);
        ?>
" />
	<?php 
    }
    ?>
	<input type="hidden" name="event_group_id" value="<?php 
    echo $group_id;
    ?>
" />
	<input type="hidden" name="event_action" value="<?php 
    esc_attr_e($mode);
    ?>
" />
	<?php 
    if (!empty($_GET['date'])) {
        ?>
		<input type="hidden" name="event_instance" value="<?php 
        echo (int) $_GET['date'];
        ?>
"/>
	<?php 
    }
    ?>
	<input type="hidden" name="event_id" value="<?php 
    echo (int) $event_id;
    ?>
"/>
	<?php 
    if ($mode == 'edit') {
        if ($has_data && (!property_exists($data, 'event_post') || !$data->event_post)) {
            $array_data = (array) $data;
            $post_id = mc_event_post('add', $array_data, $event_id);
        } else {
            $post_id = $has_data ? $data->event_post : false;
        }
        ?>
		<input type='hidden' name='event_post' value="<?php 
        echo $post_id;
        ?>
" />
	<?php 
    } else {
        $post_id = false;
    }
    ?>
	<input type="hidden" name="event_nonce_name" value="<?php 
    echo wp_create_nonce('event_nonce');
    ?>
" />
</div>

<div class="ui-sortable meta-box-sortables">
	<div class="postbox">
		<?php 
    if ($mode == 'edit') {
        $text = __('Edit Event', 'my-calendar');
        $args = '';
        if (isset($_GET['date'])) {
            $id = is_numeric($_GET['date']) ? $_GET['date'] : false;
            if ($id) {
                $args = "&amp;date={$id}";
            }
        }
        $delete = " &middot; <a href='" . admin_url("admin.php?page=my-calendar-manage&amp;mode=delete&amp;event_id={$event_id}{$args}") . "' class='delete'>" . __('Delete', 'my-calendar') . "</a>";
    } else {
        $text = __('Add Event', 'my-calendar');
        $delete = '';
    }
    if (apply_filters('mc_use_permalinks', get_option('mc_use_permalinks')) == 'true') {
        $post_link = $post_id ? get_edit_post_link($post_id) : false;
        $text_link = $post_link ? sprintf(" &middot; <a href='%s'>" . __('Edit Event Post', 'my-calendar') . "</a>", $post_link) : '';
    } else {
        $text_link = '';
    }
    ?>
		<h2><?php 
    echo $text;
    ?>
</h2>
		<div class="inside">
		<p class='mc-controls'>
			<a href="<?php 
    echo admin_url('admin.php?page=my-calendar-manage');
    ?>
"><?php 
    echo current_user_can('mc_manage_events') ? __('Manage events', 'my-calendar') : __('Manage your events', 'my-calendar');
    ?>
</a>
			<?php 
    echo $delete;
    echo $text_link;
    ?>
	<input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Event', 'my-calendar');
    ?>
"/>
		</p>		
			<?php 
    if (!empty($_GET['date']) && $data->event_recur != 'S') {
        $event = mc_get_event($instance);
        $date = date_i18n(get_option('mc_date_format'), strtotime($event->occur_begin));
        $message = __("You are editing the <strong>{$date}</strong> instance of this event. Other instances of this event will not be changed.", 'my-calendar');
        //echo "<div><input type='hidden' name='event_instance' value='$instance' /></div>";
        echo "<div class='message updated'><p>{$message}</p></div>";
    } else {
        if (isset($_GET['date']) && empty($_GET['date'])) {
            echo "<div class='message updated'><p>" . __('There was an error acquiring information about this event instance. The ID for this event instance was not provided. <strong>You are editing this entire recurrence set.</strong>', 'my-calendar') . "</p></div>";
        }
    }
    ?>
			<fieldset>
				<legend class="screen-reader-text"><?php 
    _e('Event Details', 'my-calendar');
    ?>
</legend>
				<p>
					<label for="e_title"><?php 
    _e('Event Title', 'my-calendar');
    ?>
</label><br/><input
						type="text" id="e_title" name="event_title" size="50" maxlength="255"
						value="<?php 
    if ($has_data) {
        echo apply_filters('mc_manage_event_title', stripslashes(esc_attr($data->event_title)), $data);
    }
    ?>
"/><?php 
    if ($mode == 'edit') {
        ?>
						<input type='hidden' name='prev_event_status'
						       value='<?php 
        esc_attr_e($data->event_approved);
        ?>
' /><?php 
        if (get_option('mc_event_approve') == 'true') {
            if (current_user_can('mc_approve_events')) {
                // Added by Roland P.
                if ($has_data && $data->event_approved == '1') {
                    $checked = " checked=\"checked\"";
                } else {
                    if ($has_data && $data->event_approved == '0') {
                        $checked = "";
                    } else {
                        if (get_option('mc_event_approve') == 'true') {
                            $checked = "checked=\"checked\"";
                        }
                    }
                }
                ?>
								<input type="checkbox" value="1" id="e_approved"
								       name="event_approved" <?php 
                echo $checked;
                ?>
 /> <label
									for="e_approved"><?php 
                _e('Approve', 'my-calendar');
                ?>
</label><?php 
            } else {
                // case: editing, approval enabled, user cannot approve
                ?>
								<input type="hidden" value="0"
								       name="event_approved" /><?php 
                _e('An administrator must approve your new event.', 'my-calendar');
            }
        } else {
            // Case: editing, approval system is disabled - auto approve
            ?>
							<input type="hidden" value="1" name="event_approved"/><?php 
        }
    } else {
        // case: adding new event (if use can, then 1, else 0)
        if (get_option('mc_event_approve') != 'true') {
            $dvalue = 1;
        } else {
            if (current_user_can('mc_approve_events')) {
                $dvalue = 1;
            } else {
                $dvalue = 0;
            }
        }
        ?>
						<input type="hidden" value="<?php 
        echo $dvalue;
        ?>
" name="event_approved" /><?php 
    }
    ?>
				</p>
				<?php 
    if (is_object($data) && $data->event_flagged == 1) {
        ?>
					<div class="error">
						<p>
							<input type="checkbox" value="0" id="e_flagged"
							       name="event_flagged"<?php 
        if ($has_data && $data->event_flagged == '0') {
            echo " checked=\"checked\"";
        } else {
            if ($has_data && $data->event_flagged == '1') {
                echo "";
            }
        }
        ?>
 /> <label
								for="e_flagged"><?php 
        _e('This event is not spam', 'my-calendar');
        ?>
</label>
						</p>
					</div>
				<?php 
    }
    if (function_exists('jd_doTwitterAPIPost') && current_user_can('wpt_can_tweet')) {
        if (!($mode == 'edit' && $data->event_approved == 1)) {
            ?>
						<p class='mc-twitter'>
						<label
							for='mc_twitter'><?php 
            _e('Post to Twitter (via WP to Twitter)', 'my-calendar');
            ?>
</label><br/>
						<textarea cols='70' rows='2' id='mc_twitter'
						          name='mc_twitter'><?php 
            do_action('mc_twitter_text', $data);
            ?>
</textarea>
						</p><?php 
        }
    }
    mc_show_block('event_desc', $has_data, $data);
    mc_show_block('event_short', $has_data, $data);
    mc_show_block('event_image', $has_data, $data);
    mc_show_block('event_host', $has_data, $data);
    mc_show_block('event_author', $has_data, $data, true, $event_author);
    mc_show_block('event_category', $has_data, $data);
    mc_show_block('event_link', $has_data, $data);
    echo apply_filters('mc_event_details', '', $has_data, $data, 'admin');
    ?>
			</fieldset>
		</div>
	</div>
</div>

<div class="ui-sortable meta-box-sortables">
	<div class="postbox">
		<h2><?php 
    _e('Date and Time', 'my-calendar');
    ?>
</h2>

		<div class="inside">
			<?php 
    if (is_object($data)) {
        // information for rewriting recurring data
        ?>
				<input type="hidden" name="prev_event_begin" value="<?php 
        esc_attr_e($data->event_begin);
        ?>
"/>
				<input type="hidden" name="prev_event_time" value="<?php 
        esc_attr_e($data->event_time);
        ?>
"/>
				<input type="hidden" name="prev_event_end" value="<?php 
        esc_attr_e($data->event_end);
        ?>
"/>
				<input type="hidden" name="prev_event_endtime" value="<?php 
        esc_attr_e($data->event_endtime);
        ?>
"/>
			<?php 
    }
    ?>
			<fieldset>
				<legend class="screen-reader-text"><?php 
    _e('Event Date and Time', 'my-calendar');
    ?>
</legend>
				<div id="e_schedule">
					<div id="event1" class="clonedInput" aria-live="assertive">
						<?php 
    echo apply_filters('mc_datetime_inputs', '', $has_data, $data, 'admin');
    ?>
					</div>
					<?php 
    if ($mode != 'edit') {
        ?>
						<p id="event_span">
							<input type="checkbox" value="1" id="e_span"
							       name="event_span"<?php 
        if ($has_data && $data->event_span == '1') {
            echo " checked=\"checked\"";
        } else {
            if ($has_data && $data->event_span == '0') {
                echo "";
            } else {
                if (get_option('mc_event_span') == 'true') {
                    echo " checked=\"checked\"";
                }
            }
        }
        ?>
 /> <label
								for="e_span"><?php 
        _e('This is a multi-day event.', 'my-calendar');
        ?>
</label>
						</p>
						<p class="note">
							<em><?php 
        _e('Enter start and end dates/times for each occurrence of the event.', 'my-calendar');
        ?>
</em>
						</p>
						<div>
							<input type="button" id="add_field" value="<?php 
        _e('Add another occurrence', 'my-calendar');
        ?>
" class="button" />
							<input type="button" id="del_field" value="<?php 
        _e('Remove last occurrence', 'my-calendar');
        ?>
" class="button" />
						</div>
					<?php 
    } else {
        ?>
						<div id='mc-accordion'>
							<?php 
        if ($data->event_recur != 'S') {
            ?>
								<h4><span class='dashicons' aria-hidden='true'> </span><?php 
            _e('Scheduled dates for this event', 'my-calendar');
            ?>
</h4>
								<div>
									<p>
									<?php 
            _e('Editing a single date of an event changes only that date. Editing the root event changes all events in the series.', 'my-calendar');
            ?>
									</p>
									<div class='mc_response' aria-live='assertive'></div>
									<ul class="columns instance-list">
										<?php 
            if (isset($_GET['date'])) {
                $date = (int) $_GET['date'];
            } else {
                $date = false;
            }
            ?>
										<?php 
            echo mc_instance_list($data->event_id, $date);
            ?>
									</ul>
									<p><button type='button' class='add-occurrence' aria-expanded="false"><span class='dashicons' aria-hidden='true'> </span><?php 
            _e('Add another date', 'my-calendar');
            ?>
</button></p>
									<div class='mc_add_new'>
									<?php 
            echo mc_recur_datetime_input();
            ?>
									<button type='button' class='save-occurrence'><?php 
            _e('Add Date', 'my-calendar');
            ?>
</button>
									</div>
								</div>
							<?php 
        }
        ?>
							<?php 
        if ($data->event_group_id != 0) {
            ?>
								<?php 
            $edit_group_url = admin_url('admin.php?page=my-calendar-groups&mode=edit&event_id=' . $data->event_id . '&group_id=' . $data->event_group_id);
            ?>
								<h4><span class='dashicons' aria-hidden="true"></span><?php 
            _e('Related Events:', 'my-calendar');
            ?>
 (<a
										href='<?php 
            echo $edit_group_url;
            ?>
'><?php 
            _e('Edit group', 'my-calendar');
            ?>
</a>)
								</h4>
								<div>
									<ul class="columns">
										<?php 
            mc_related_events($data->event_group_id);
            ?>
									</ul>
								</div>
							<?php 
        }
        ?>
						</div>
					<?php 
    }
    ?>
				</div>
			</fieldset>
		</div>
	</div>
</div>
<?php 
    mc_show_block('event_recurs', $has_data, $data);
    mc_show_block('event_access', $has_data, $data);
    mc_show_block('event_open', $has_data, $data);
    if (mc_show_edit_block('event_location') || mc_show_edit_block('event_location_dropdown')) {
        ?>

<div class="ui-sortable meta-box-sortables">
	<div class="postbox">
		<h2><?php 
        _e('Event Location', 'my-calendar');
        ?>
</h2>

		<div class="inside location_form">
			<fieldset>
				<legend class='screen-reader-text'><?php 
        _e('Event Location', 'my-calendar');
        ?>
</legend><?php 
    }
    if (mc_show_edit_block('event_location_dropdown')) {
        $current_location = '';
        $locs = $mcdb->get_results("SELECT location_id,location_label FROM " . my_calendar_locations_table() . " ORDER BY location_label ASC");
        if (!empty($locs)) {
            ?>
						<p>
						<label for="l_preset"><?php 
            _e('Choose a preset location:', 'my-calendar');
            ?>
</label> <select
							name="location_preset" id="l_preset" aria-describedby='mc-current-location'>
							<option value="none"> --</option><?php 
            foreach ($locs as $loc) {
                if (is_object($loc)) {
                    echo "<option value=\"" . $loc->location_id . "\">" . mc_kses_post(stripslashes($loc->location_label)) . "</option>";
                    if (is_object($data)) {
                        if (property_exists($data, 'event_location')) {
                            $event_location = $data->event_location;
                        } else {
                            $event_location = false;
                        }
                        if ($loc->location_id == $event_location) {
                            $current_location = "<span id='mc-current-location'>" . sprintf(__('Current location: %s', 'my-calendar'), mc_kses_post($loc->location_label)) . "</span>";
                        }
                    }
                }
            }
            ?>
						</select>
						<?php 
            echo $current_location;
            ?>
						</p><?php 
        } else {
            ?>
						<input type="hidden" name="location_preset" value="none"/>
						<p><a
							href="<?php 
            echo admin_url('admin.php?page=my-calendar-locations');
            ?>
"><?php 
            _e('Add recurring locations for later use.', 'my-calendar');
            ?>
</a>
						</p><?php 
        }
    } else {
        ?>
					<input type="hidden" name="location_preset" value="none"/><?php 
    }
    mc_show_block('event_location', $has_data, $data);
    if (mc_show_edit_block('event_location') || mc_show_edit_block('event_location_dropdown')) {
        ?>
			</fieldset>
		</div>
	</div>
</div><?php 
    }
    if (mc_show_edit_block('event_specials')) {
        ?>
	<div class="ui-sortable meta-box-sortables">
	<div class="postbox">
		<h2><?php 
        _e('Special scheduling options', 'my-calendar');
        ?>
</h2>

		<div class="inside">
			<fieldset>
				<legend class="screen-reader-text"><?php 
        _e('Special Options', 'my-calendar');
        ?>
</legend>
				<p>
					<label
						for="e_holiday"><?php 
        _e('Cancel this event if it occurs on a date with an event in the Holidays category', 'my-calendar');
        ?>
</label>
					<input type="checkbox" value="true" id="e_holiday"
					       name="event_holiday"<?php 
        if ($has_data && $data->event_holiday == '1') {
            echo " checked=\"checked\"";
        } else {
            if ($has_data && $data->event_holiday == '0') {
                echo "";
            } else {
                if (get_option('mc_skip_holidays') == 'true') {
                    echo " checked=\"checked\"";
                }
            }
        }
        ?>
 />
				</p>

				<p>
					<label for="e_fifth_week"><?php 
        _e('If this event recurs, and falls on the 5th week of the month in a month with only four weeks, move it back one week.', 'my-calendar');
        ?>
</label>
					<input type="checkbox" value="true" id="e_fifth_week"
					       name="event_fifth_week"<?php 
        if ($has_data && $data->event_fifth_week == '1') {
            echo " checked=\"checked\"";
        } else {
            if ($has_data && $data->event_fifth_week == '0') {
                echo "";
            } else {
                if (get_option('mc_no_fifth_week') == 'true') {
                    echo " checked=\"checked\"";
                }
            }
        }
        ?>
 />
				</p>
			</fieldset>
		</div>
	</div>
	</div><?php 
    } else {
        ?>
	<div>
	<input type="hidden" name="event_holiday" value="true" <?php 
        checked(get_option('mc_skip_holidays'), 'true');
        ?>
 />
	<input type="hidden" name="event_fifth_week" value="true" <?php 
        checked(get_option('mc_no_fifth_week'), 'true');
        ?>
 />
	</div><?php 
    }
    ?>
<p>
	<input type="submit" name="save" class="button-primary" value="<?php 
    _e('Save Event', 'my-calendar');
    ?>
"/>
</p>
</form>
</div>
	</div><?php 
}