function mc_selected_users($selected)
{
    $selected = explode(',', $selected);
    $users = mc_get_users();
    $options = '';
    foreach ($users as $u) {
        if (in_array($u->ID, $selected)) {
            $checked = ' checked="checked"';
        } else {
            $checked = '';
        }
        $display_name = $u->display_name == '' ? $u->user_nicename : $u->display_name;
        $options .= '<option value="' . $u->ID . '"' . $checked . ">{$display_name}</option>\n";
    }
    return $options;
}
function mc_show_block($field, $has_data, $data, $echo = true, $default = '')
{
    global $user_ID;
    $return = $checked = $value = '';
    $show_block = mc_show_edit_block($field);
    $pre = '<div class="ui-sortable meta-box-sortables"><div class="postbox">';
    $post = '</div></div>';
    switch ($field) {
        case 'event_host':
            if ($show_block) {
                $users = mc_get_users();
                $select = '';
                foreach ($users as $u) {
                    $display_name = $u->display_name == '' ? $u->user_nicename : $u->display_name;
                    if (is_object($data) && $data->event_host == $u->ID) {
                        $selected = ' selected="selected"';
                    } else {
                        if (is_object($u) && $u->ID == $user_ID && empty($data->event_host)) {
                            $selected = ' selected="selected"';
                        } else {
                            $selected = '';
                        }
                    }
                    $select .= "<option value='{$u->ID}'{$selected}>{$display_name}</option>\n";
                }
                $return = '
					<p>
					<label for="e_host">' . __('Host', 'my-calendar') . '</label>
					<select id="e_host" name="event_host">' . $select . '</select>
				</p>';
            }
            break;
        case 'event_author':
            if ($show_block && is_object($data) && $data->event_author === '0') {
                $users = mc_get_users();
                $select = '';
                foreach ($users as $u) {
                    $display_name = $u->display_name == '' ? $u->user_nicename : $u->display_name;
                    $select .= "<option value='{$u->ID}'>{$display_name}</option>\n";
                }
                $return = '
					<p>
					<label for="e_author">' . __('Author', 'my-calendar') . '</label>
					<select id="e_author" name="event_author">
						<option value="0" selected="selected">Public Submitter</option>' . $select . '</select>
				</p>';
            } else {
                $return = '<input type="hidden" name="event_author" value="' . $default . '" />';
            }
            break;
        case 'event_desc':
            if ($show_block) {
                global $current_screen;
                // because wp_editor cannot return a value, event_desc fields cannot be filtered if its enabled.
                $value = $has_data ? stripslashes($data->event_desc) : '';
                if ($current_screen->base == 'post') {
                    $return = '<div class="event_description">
									<label for="content" class="screen-reader-text">' . __('Event Description', 'my-calendar') . '</label>
									<textarea id="content" name="content" class="event_desc" rows="8" cols="80">' . stripslashes(esc_attr($value)) . '</textarea>
								</div>';
                } else {
                    echo '
					<div class="event_description">
					<label for="content" class="screen-reader-text">' . __('Event Description', 'my-calendar') . '</label>';
                    if (user_can_richedit()) {
                        wp_editor($value, 'content', array('textarea_rows' => 10));
                    } else {
                        echo '<textarea id="content" name="content" class="event_desc" rows="8" cols="80">' . stripslashes(esc_attr($value)) . '</textarea>';
                    }
                    echo '</div>';
                }
            }
            break;
        case 'event_short':
            if ($show_block) {
                $value = $has_data ? stripslashes(esc_attr($data->event_short)) : '';
                $return = '
				<p>
					<label for="e_short">' . __('Short Description', 'my-calendar') . '</label><br /><textarea id="e_short" name="event_short" rows="2" cols="80">' . $value . '</textarea>
				</p>';
            }
            break;
        case 'event_image':
            if ($show_block) {
                if ($has_data && property_exists($data, 'event_post')) {
                    $image = has_post_thumbnail($data->event_post) ? get_the_post_thumbnail_url($data->event_post) : $data->event_image;
                    $image_id = has_post_thumbnail($data->event_post) ? get_post_thumbnail_id($data->event_post) : '';
                } else {
                    $image = '';
                    $image_id = '';
                }
                $return = '
				<div class="mc-image-upload field-holder">
					<input type="hidden" name="event_image_id" value="' . esc_attr($image_id) . '" class="textfield" id="e_image_id" />
					<label for="e_image">' . __("Add an image:", 'my-calendar') . '</label><br /><input type="text" name="event_image" id="e_image" size="60" value="' . esc_attr($image) . '" placeholder="http://yourdomain.com/image.jpg" /> <button type="button" class="button textfield-field">' . __("Upload", 'my-calendar') . '</button>';
                if ($image != '') {
                    $image = has_post_thumbnail($data->event_post) ? get_the_post_thumbnail_url($data->event_post) : $data->event_image;
                    $return .= '<div class="event_image"><img src="' . esc_attr($image) . '" alt="" /></div>';
                } else {
                    $return .= '<div class="event_image"></div>';
                }
                $return .= '</div>';
            } else {
                $return = '<input type="hidden" name="event_image" value="' . esc_attr($image) . '" />';
            }
            break;
        case 'event_category':
            if ($show_block) {
                $return = '<p>
				<label for="e_category">' . __('Category', 'my-calendar') . '</label>
				<select id="e_category" name="event_category">' . mc_category_select($data) . '
				</select>
				</p>';
            } else {
                $return = '<div><input type="hidden" name="event_category" value="' . mc_category_select($data, false) . '" /></div>';
            }
            break;
        case 'event_link':
            if ($show_block) {
                $value = $has_data ? esc_url($data->event_link) : '';
                if ($has_data && $data->event_link_expires == '1') {
                    $checked = " checked=\"checked\"";
                } else {
                    if ($has_data && $data->event_link_expires == '0') {
                        $checked = "";
                    } else {
                        if (get_option('mc_event_link_expires') == 'true') {
                            $checked = " checked=\"checked\"";
                        }
                    }
                }
                $return = '
					<p>
						<label for="e_link">' . __('URL', 'my-calendar') . '</label> <input type="text" id="e_link" name="event_link" size="40" value="' . $value . '" /> <input type="checkbox" value="1" id="e_link_expires" name="event_link_expires"' . $checked . ' /> <label for="e_link_expires">' . __('Link will expire after event', 'my-calendar') . '</label>
					</p>';
            }
            break;
        case 'event_recurs':
            if (is_object($data)) {
                $event_recur = is_object($data) ? $data->event_recur : '';
                $recurs = str_split($event_recur, 1);
                $recur = $recurs[0];
                $every = isset($recurs[1]) ? $recurs[1] : 1;
                if ($every == 1 && $recur == 'B') {
                    $every = 2;
                }
                $prev = '<input type="hidden" name="prev_event_repeats" value="' . $data->event_repeats . '" /><input type="hidden" name="prev_event_recur" value="' . $data->event_recur . '" />';
            } else {
                $recur = false;
                $every = 1;
                $prev = '';
            }
            if (is_object($data) && $data->event_repeats != null) {
                $repeats = $data->event_repeats;
            } else {
                $repeats = 0;
            }
            if ($show_block && empty($_GET['date'])) {
                $return = $pre . '
<h2>' . __('Recurring', 'my-calendar') . '</h2>
	<div class="inside">' . $prev . '
		<fieldset>
		<legend class="screen-reader-text">' . __('Recurring Events', 'my-calendar') . '</legend>
			<p>
				<label for="e_repeats">' . __('Repeats', 'my-calendar') . ' <input type="text" name="event_repeats" aria-labelledby="e_repeats_label" id="e_repeats" size="1" value="' . esc_attr($repeats) . '" /> <span id="e_repeats_label">' . __('times', 'my-calendar') . '</span>, </label>
				<label for="e_every">' . __('every', 'my-calendar') . '</label> <input type="number" name="event_every" id="e_every" size="1" min="1" max="99" maxlength="2" value="' . esc_attr($every) . '" /> 
				<label for="e_recur" class="screen-reader-text">' . __('Units', 'my-calendar') . '</label> 
				<select name="event_recur" id="e_recur">
					' . mc_recur_options($recur) . '
				</select><br />
				' . __('Your entry is the number of events after the first occurrence of the event: a recurrence of <em>2</em> means the event will happen three times.', 'my-calendar') . '
				<div class="mc_recur_notice" aria-live="polite"><p><span class="dashicons dashicons-no"></span>' . __('Month by day events currently only support monthly recurrances.', 'my-calendar') . '</p></div>
			</p>
		</fieldset>	
	</div>
							' . $post;
            } else {
                if ($every == '' && $repeats == '') {
                    $every = 'S';
                    $repeats = '0';
                }
                $return = '
				<div>' . $prev . '		
					<input type="hidden" name="event_repeats" value="' . esc_attr($repeats) . '" />
					<input type="hidden" name="event_every" value="' . esc_attr($every) . '" />
					<input type="hidden" name="event_recur" value="' . esc_attr($recur) . '" />
				</div>';
            }
            break;
        case 'event_access':
            if ($show_block) {
                $label = __('Event Access', 'my-calendar');
                $return = $pre . '
						<h2>' . $label . '</h2>
							<div class="inside">		
								' . mc_event_accessibility('', $data, $label) . apply_filters('mc_event_access_fields', '', $has_data, $data) . '						
							</div>' . $post;
            }
            break;
        case 'event_open':
            if ($show_block) {
                $return = $pre . '
				<h2>' . __('Event Registration Settings', 'my-calendar') . '</h2>
				<div class="inside">
					<fieldset>
					<legend class="screen-reader-text">' . __('Event Registration', 'my-calendar') . '</legend>
					' . apply_filters('mc_event_registration', '', $has_data, $data, 'admin') . '		
					</fieldset>
				</div>
				' . $post;
            } else {
                $open = $has_data ? esc_attr($data->event_open) : '2';
                $tickets = $has_data ? esc_url($data->event_tickets) : '';
                $registration = $has_data ? esc_attr($data->event_registration) : '';
                $return = '
				<div>
					<input type="hidden" name="event_open" value="' . $open . '" />
					<input type="hidden"  name="event_tickets" value="' . $tickets . '" />
					<input type="hidden" name="event_registration" value="' . $registration . '" />
				</div>';
            }
            break;
        case 'event_location':
            if ($show_block) {
                $return = mc_locations_fields($has_data, $data, 'event');
            } else {
                if ($has_data) {
                    $return = "\r\n\t\t\t\t<div>\r\n\t\t\t\t\t<input type='hidden' name='event_label' value='" . esc_attr(stripslashes($data->event_label)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_street' value='" . esc_attr(stripslashes($data->event_street)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_street2' value='" . esc_attr(stripslashes($data->event_street2)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_phone' value='" . esc_attr(stripslashes($data->event_phone)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_phone2' value='" . esc_attr(stripslashes($data->event_phone2)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_city' value='" . esc_attr(stripslashes($data->event_city)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_state' value='" . esc_attr(stripslashes($data->event_state)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_postcode' value='" . esc_attr(stripslashes($data->event_postcode)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_region' value='" . esc_attr(stripslashes($data->event_region)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_country' value='" . esc_attr(stripslashes($data->event_country)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_zoom' value='" . esc_attr(stripslashes($data->event_zoom)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_url' value='" . esc_attr(stripslashes($data->event_url)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_latitude' value='" . esc_attr(stripslashes($data->event_latitude)) . "' />\r\n\t\t\t\t\t<input type='hidden' name='event_longitude' value='" . esc_attr(stripslashes($data->event_longitude)) . "' />\r\n\t\t\t\t</div>";
                }
            }
            break;
        default:
            return;
    }
    $return = apply_filters('mc_show_block', $return, $data, $field);
    if ($echo == true) {
        echo $return;
    } else {
        return $return;
    }
}
function my_calendar_print_group_fields($data, $mode, $event_id, $group_id = '')
{
    global $user_ID, $wpdb;
    $mcdb = $wpdb;
    $current_user = wp_get_current_user();
    $has_data = empty($data) ? false : true;
    $user = get_userdata($user_ID);
    $mc_input_administrator = get_option('mc_input_options_administrators') == 'true' && current_user_can('manage_options') ? true : false;
    $mc_input = get_option('mc_input_options');
    ?>

	<div class="postbox-container jcd-wide">
	<div class="metabox-holder">
	<form method="post"
	      action="<?php 
    echo admin_url("admin.php?page=my-calendar-groups&amp;mode=edit&amp;event_id={$event_id}&amp;group_id={$group_id}");
    ?>
">
	<div>
		<input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-nonce');
    ?>
"/>
		<input type="hidden" name="group_id" value="<?php 
    if (!empty($data->event_group_id)) {
        echo $data->event_group_id;
    } else {
        echo mc_group_id();
    }
    ?>
"/>
		<input type="hidden" name="event_action" value="<?php 
    echo esc_attr($mode);
    ?>
"/>
		<input type="hidden" name="event_id" value="<?php 
    echo esc_attr($event_id);
    ?>
"/>
		<input type="hidden" name="event_author" value="<?php 
    echo esc_attr($user_ID);
    ?>
"/>
		<input type="hidden" name="event_post" value="<?php 
    echo esc_attr($data->event_post);
    ?>
"/>
		<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">
			<h2><?php 
    _e('Manage Event Groups', 'my-calendar');
    ?>
</h2>

			<div class="inside">
				<fieldset>
					<legend><?php 
    _e('Enter your Event Information', 'my-calendar');
    ?>
</legend>
					<p>
						<label for="e_title"><?php 
    _e('Event Title', 'my-calendar');
    ?>
							<span><?php 
    _e('(required)', 'my-calendar');
    ?>
</span><?php 
    if (!mc_compare_group_members($group_id, 'event_title')) {
        echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
    }
    ?>
</label><br/><input type="text" id="e_title" name="event_title" size="60"
						                            value="<?php 
    if (!empty($data)) {
        echo stripslashes(esc_attr($data->event_title));
    }
    ?>
"/>
					</p>
					<?php 
    $apply = mc_group_form($group_id, 'apply');
    echo $apply;
    if ($data->event_repeats == 0 && ($data->event_recur == 'S1' || $data->event_recur == 'S')) {
        ?>
						<p>
							<input type="checkbox" value="1" id="e_span"
							       name="event_span"<?php 
        if (!empty($data) && $data->event_span == '1') {
            echo " checked=\"checked\"";
        } else {
            if (!empty($data) && $data->event_span == '0') {
                echo "";
            } else {
                if (get_option('mc_event_span') == 'true') {
                    echo " checked=\"checked\"";
                }
            }
        }
        ?>
 /> <label
								for="e_span"><?php 
        _e('Selected dates are a single multi-day event.', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_span')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label>
						</p>
					<?php 
    } else {
        ?>
						<div><input type='hidden' name='event_span' value='<?php 
        esc_attr_e($data->event_span);
        ?>
'/></div>
					<?php 
    }
    ?>
					<?php 
    if ($mc_input['event_desc'] == 'on' || $mc_input_administrator) {
        ?>
						<div id="group_description"><?php 
        if (!empty($data)) {
            $description = $data->event_desc;
        } else {
            $description = '';
        }
        ?>
							<label
								for="content"><?php 
        _e('Event Description (<abbr title="hypertext markup language">HTML</abbr> allowed)', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_desc')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label><br/><?php 
        wp_editor(stripslashes($description), 'content', array('textarea_rows' => 10));
        ?>
						</div>
					<?php 
    }
    ?>
					<?php 
    if ($mc_input['event_short'] == 'on' || $mc_input_administrator) {
        ?>
						<p>
							<label
								for="e_short"><?php 
        _e('Event Short Description (<abbr title="hypertext markup language">HTML</abbr> allowed)', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_short')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label><br/><textarea id="e_short" name="event_short" rows="2"
							                               cols="80"><?php 
        if (!empty($data)) {
            echo stripslashes(esc_attr($data->event_short));
        }
        ?>
</textarea>
						</p>
					<?php 
    }
    if (mc_show_edit_block('event_image')) {
        ?>
						<div class='mc-image-upload field-holder'>
							<?php 
        if (!empty($data->event_image)) {
            ?>
								<div class="event_image"><img
										src="<?php 
            if ($has_data) {
                echo esc_attr($data->event_image);
            }
            ?>
" alt=""/></div>
							<?php 
        } else {
            ?>
								<div class="event_image"></div>
							<?php 
        }
        ?>
							<input type="hidden" name="event_image_id" value="" class="textfield" id="e_image_id"/>
							<label
								for="e_image"><?php 
        _e("Add an image:", 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_image')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" name="event_image" id="e_image" size="60"
							                        value="<?php 
        if ($has_data) {
            echo esc_attr($data->event_image);
        }
        ?>
"
							                        placeholder="http://yourdomain.com/image.jpg"/> <a href="#"
							                                                                           class="button textfield-field"><?php 
        _e("Upload", 'my-calendar');
        ?>
</a>
						</div>
					<?php 
    } else {
        ?>
						<div>
							<input type="hidden" name="event_image"
							       value="<?php 
        if ($has_data) {
            echo esc_attr($data->event_image);
        }
        ?>
"/>
							<?php 
        if (!empty($data->event_image)) {
            ?>
								<div class="event_image"><img src="<?php 
            echo esc_attr($data->event_image);
            ?>
"
								                              alt=""/>
								</div>
							<?php 
        }
        ?>
						</div>
					<?php 
    }
    ?>
					<p>
						<label
							for="e_host"><?php 
    _e('Event Host', 'my-calendar');
    if (!mc_compare_group_members($group_id, 'event_host')) {
        echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
    }
    ?>
</label>
						<select id="e_host" name="event_host">
							<?php 
    // Grab all the categories and list them
    $userList = mc_get_users();
    foreach ($userList as $u) {
        echo '<option value="' . $u->ID . '"';
        if (is_object($data) && $data->event_host == $u->ID) {
            echo ' selected="selected"';
        } else {
            if (is_object($u) && $u->ID == $user->ID && empty($data->event_host)) {
                echo ' selected="selected"';
            }
        }
        $display_name = $u->display_name == '' ? $u->user_nicename : $u->display_name;
        echo ">{$display_name}</option>\n";
    }
    ?>
						</select>
					</p>
					<?php 
    if ($mc_input['event_category'] == 'on' || $mc_input_administrator) {
        ?>
						<p>
							<label
								for="e_category"><?php 
        _e('Event Category', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_category')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label>
							<select id="e_category" name="event_category">
								<?php 
        echo mc_category_select($data);
        ?>
							</select>
						</p>
					<?php 
    } else {
        ?>
						<div>
							<input type="hidden" name="event_category" value="1"/>
						</div>
					<?php 
    }
    ?>
					<?php 
    if ($mc_input['event_link'] == 'on' || $mc_input_administrator) {
        ?>
						<p>
							<label
								for="e_link"><?php 
        _e('Event Link (Optional)', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_link')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_link" name="event_link" size="40"
							                        value="<?php 
        if (!empty($data)) {
            echo esc_url($data->event_link);
        }
        ?>
"/> <input type="checkbox" value="1" id="e_link_expires"
							                                       name="event_link_expires"<?php 
        if (!empty($data) && $data->event_link_expires == '1') {
            echo " checked=\"checked\"";
        } else {
            if (!empty($data) && $data->event_link_expires == '0') {
                echo "";
            } else {
                if (get_option('mc_event_link_expires') == 'true') {
                    echo " checked=\"checked\"";
                }
            }
        }
        ?>
 /> <label
								for="e_link_expires"><?php 
        _e('Link will expire after event.', 'my-calendar');
        ?>
</label>
						</p>
					<?php 
    }
    ?>
				</fieldset>
				<p>
					<input type="submit" name="save" class="button-primary"
					       value="<?php 
    _e('Edit Event Group', 'my-calendar');
    ?>
"/>
				</p>
			</div>
		</div>
	</div>
	<?php 
    if ($mc_input['event_open'] == 'on' || $mc_input_administrator) {
        // add a "don't change" option here
        ?>
		<div class="ui-sortable meta-box-sortables">
			<div class="postbox">
				<h2><?php 
        _e('Event Registration Options', 'my-calendar');
        ?>
</h2>

				<div class="inside">
					<fieldset>
						<legend><?php 
        _e('Event Registration Status', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_open')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</legend>
						<?php 
        echo apply_filters('mc_event_registration', '', $has_data, $data, 'admin');
        ?>
					</fieldset>
				</div>
			</div>
		</div>
	<?php 
    } else {
        ?>
		<div>
			<input type="hidden" name="event_open" value="<?php 
        echo $has_data ? esc_attr($data->event_open) : '2';
        ?>
"/>
			<input type="hidden" name="event_tickets"
			       value="<?php 
        echo $has_data ? esc_attr($data->event_tickets) : '';
        ?>
"/>
			<input type="hidden" name="event_registration"
			       value="<?php 
        echo $has_data ? esc_attr($data->event_registration) : '';
        ?>
"/>
		</div>

	<?php 
    }
    ?>

	<?php 
    if ($mc_input['event_location'] == 'on' || $mc_input['event_location_dropdown'] == 'on' || $mc_input_administrator) {
        ?>

	<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><?php 
        _e('Event Location', 'my-calendar');
        ?>
</legend>
					<?php 
    }
    ?>
					<?php 
    if ($mc_input['event_location_dropdown'] == 'on' || $mc_input_administrator) {
        ?>
						<?php 
        $locations = $mcdb->get_results("SELECT location_id,location_label FROM " . my_calendar_locations_table() . " ORDER BY location_label ASC");
        if (!empty($locations)) {
            ?>
							<p>
								<label
									for="location_preset"><?php 
            _e('Choose a preset location:', 'my-calendar');
            ?>
</label>
								<select name="location_preset" id="location_preset">
									<option value="none"> --</option>
									<?php 
            foreach ($locations as $location) {
                echo "<option value=\"" . $location->location_id . "\">" . esc_html(stripslashes($location->location_label)) . "</option>";
            }
            ?>
								</select>
							</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 
        }
        ?>
					<?php 
    } else {
        ?>
						<input type="hidden" name="location_preset" value="none"/>
					<?php 
    }
    ?>
					<?php 
    if ($mc_input['event_location'] == 'on' || $mc_input_administrator) {
        ?>
						<p>
							<label
								for="e_label"><?php 
        _e('Name of Location (e.g. <em>Joe\'s Bar and Grill</em>)', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_label')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label><br/><input type="text" id="e_label" name="event_label" size="40"
							                            value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_label));
        }
        ?>
"/>
						</p>
						<p>
							<label
								for="e_street"><?php 
        _e('Street Address', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_street')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_street" name="event_street" size="40"
							                        value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_street));
        }
        ?>
"/>
						</p>
						<p>
							<label
								for="e_street2"><?php 
        _e('Street Address (2)', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_street2')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_street2" name="event_street2" size="40"
							                        value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_street2));
        }
        ?>
"/>
						</p>
						<p>
							<label
								for="e_city"><?php 
        _e('City', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_city')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_city" name="event_city" size="40"
							                        value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_city));
        }
        ?>
"/>
							<label
								for="e_state"><?php 
        _e('State/Province', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_state')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_state" name="event_state" size="10"
							                        value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_state));
        }
        ?>
"/>
						</p>
						<p>
							<label
								for="e_postcode"><?php 
        _e('Postal Code', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_postcode')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_postcode" name="event_postcode" size="10"
							                        value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_postcode));
        }
        ?>
"/>
							<label
								for="e_region"><?php 
        _e('Region', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_region')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_region" name="event_region" size="40"
							                        value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_region));
        }
        ?>
"/>
						</p>
						<p>
							<label
								for="e_country"><?php 
        _e('Country', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_country')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_country" name="event_country" size="10"
							                        value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_country));
        }
        ?>
"/>
						</p>
						<p>
							<label
								for="e_zoom"><?php 
        _e('Initial Zoom', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_zoom')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label>
							<select name="event_zoom" id="e_zoom">
								<option value="16"<?php 
        if (!empty($data) && $data->event_zoom == 16) {
            echo " selected=\"selected\"";
        }
        ?>
><?php 
        _e('Neighborhood', 'my-calendar');
        ?>
</option>
								<option value="14"<?php 
        if (!empty($data) && $data->event_zoom == 14) {
            echo " selected=\"selected\"";
        }
        ?>
><?php 
        _e('Small City', 'my-calendar');
        ?>
</option>
								<option value="12"<?php 
        if (!empty($data) && $data->event_zoom == 12) {
            echo " selected=\"selected\"";
        }
        ?>
><?php 
        _e('Large City', 'my-calendar');
        ?>
</option>
								<option value="10"<?php 
        if (!empty($data) && $data->event_zoom == 10) {
            echo " selected=\"selected\"";
        }
        ?>
><?php 
        _e('Greater Metro Area', 'my-calendar');
        ?>
</option>
								<option value="8"<?php 
        if (!empty($data) && $data->event_zoom == 8) {
            echo " selected=\"selected\"";
        }
        ?>
><?php 
        _e('State', 'my-calendar');
        ?>
</option>
								<option value="6"<?php 
        if (!empty($data) && $data->event_zoom == 6) {
            echo " selected=\"selected\"";
        }
        ?>
><?php 
        _e('Region', 'my-calendar');
        ?>
</option>
							</select>
						</p>
						<p>
							<label
								for="e_phone"><?php 
        _e('Phone', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_phone')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_phone" name="event_phone" size="32"
							                        value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_phone));
        }
        ?>
"/>
						</p>
						<p>
							<label
								for="e_url"><?php 
        _e('Location URL', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_url')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_url" name="event_url" size="40"
							                        value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_url));
        }
        ?>
"/>
						</p>
						<fieldset>
							<legend><?php 
        _e('GPS Coordinates (optional)', 'my-calendar');
        ?>
</legend>
							<p>
								<label
									for="e_latitude"><?php 
        _e('Latitude', 'my-calendar');
        if (!mc_compare_group_members($group_id, 'event_latitude')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        if (!mc_compare_group_members($group_id, 'event_longitude')) {
            echo " <span>" . __('Fields do not match', 'my-calendar') . "</span>";
        }
        ?>
</label> <input type="text" id="e_latitude" name="event_latitude" size="10"
								                        value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_latitude));
        }
        ?>
"/>
								<label for="e_longitude"><?php 
        _e('Longitude', 'my-calendar');
        ?>
</label> <input
									type="text" id="e_longitude" name="event_longitude" size="10"
									value="<?php 
        if (!empty($data)) {
            esc_attr_e(stripslashes($data->event_longitude));
        }
        ?>
"/>
							</p>
						</fieldset>
						<fieldset>
							<legend><?php 
        _e('Location Accessibility', 'my-calendar');
        ?>
</legend>
							<ul class='checkboxes'>
								<?php 
        $access = apply_filters('mc_venue_accessibility', mc_location_access());
        $access_list = '';
        if (!empty($data)) {
            $location_access = unserialize($data->event_access);
        } else {
            $location_access = array();
        }
        foreach ($access as $k => $a) {
            $id = "loc_access_{$k}";
            $label = $a;
            $checked = '';
            if (is_array($location_access)) {
                $checked = in_array($k, $location_access) ? " checked='checked'" : '';
            }
            $item = sprintf('<li><input type="checkbox" id="%1$s" name="event_access[]" value="%4$s" class="checkbox" %2$s /> <label for="%1$s">%3$s</label></li>', esc_attr($id), $checked, esc_html($label), esc_attr($k));
            $access_list .= $item;
        }
        echo $access_list;
        ?>
							</ul>
						</fieldset>
					<?php 
    }
    ?>
					<?php 
    if ($mc_input['event_location'] == 'on' || $mc_input['event_location_dropdown'] == 'on' || $mc_input_administrator) {
        ?>
				</fieldset>
			</div>
		</div>
	</div>
	<?php 
    }
    ?>
	<p>
		<input type="submit" name="save" class="button-secondary"
		       value="<?php 
    _e('Edit Event Group', 'my-calendar');
    ?>
"/>
	</p>
	</form>
	</div>
	</div>
<?php 
}
function mc_generator($type)
{
    ?>
<form action="<?php 
    echo admin_url('admin.php?page=my-calendar-help');
    ?>
" method="POST" id="my-calendar-generate">
	<fieldset>
		<legend><strong><?php 
    echo ucfirst($type);
    ?>
</strong>: <?php 
    _e('Shortcode Attributes', 'my-calendar');
    ?>
		</legend>
		<div id="mc-generator" class="generator">
			<div><input type="hidden" name="_wpnonce" value="<?php 
    echo wp_create_nonce('my-calendar-generator');
    ?>
"/></div>		
			<input type='hidden' name='shortcode' value='<?php 
    esc_attr_e($type);
    ?>
'/>
			<?php 
    // Common Elements to all Shortcodes
    ?>
			<p><?php 
    echo my_calendar_categories_list('select', 'admin');
    ?>
</p>

			<p>
				<label for="ltype"><?php 
    _e('Location filter type:', 'my-calendar');
    ?>
</label>
				<select name="ltype" id="ltype">
					<option value="" selected="selected"><?php 
    _e('All locations', 'my-calendar');
    ?>
</option>
					<option value='event_label'><?php 
    _e('Location Name', 'my-calendar');
    ?>
</option>
					<option value='event_city'><?php 
    _e('City', 'my-calendar');
    ?>
</option>
					<option value='event_state'><?php 
    _e('State', 'my-calendar');
    ?>
</option>
					<option value='event_postcode'><?php 
    _e('Postal Code', 'my-calendar');
    ?>
</option>
					<option value='event_country'><?php 
    _e('Country', 'my-calendar');
    ?>
</option>
					<option value='event_region'><?php 
    _e('Region', 'my-calendar');
    ?>
</option>
				</select>
			</p>
			<p>
				<label for="lvalue" id='lval'><?php 
    _e('Location filter value:', 'my-calendar');
    ?>
</label>
				<input type="text" name="lvalue" id="lvalue" aria-labelledby='lval location-info' />
			</p>

			<p id='location-info'>
				<?php 
    _e('<strong>Note:</strong> If you provide a location filter value, it must be an exact match for that information as saved with your events. (e.g. "Saint Paul" is not equivalent to "saint paul" or "St. Paul")', 'my-calendar');
    ?>
			</p>
			<?php 
    // Grab users and list them
    $users = mc_get_users();
    $options = '';
    foreach ($users as $u) {
        $options .= '<option value="' . $u->ID . '">' . esc_html($u->display_name) . "</option>\n";
    }
    ?>
			<p>
				<label for="author"><?php 
    _e('Limit by Author', 'my-calendar');
    ?>
</label>
				<select name="author[]" id="author" multiple="multiple">
					<option value="all"><?php 
    _e('All authors', 'my-calendar');
    ?>
</option>
					<option value="current"><?php 
    _e('Currently logged-in user', 'my-calendar');
    ?>
</option>
					<?php 
    echo $options;
    ?>
				</select>
			</p>
			<p>
				<label for="host"><?php 
    _e('Limit by Host', 'my-calendar');
    ?>
</label>
				<select name="host[]" id="host" multiple="multiple">
					<option value="all"><?php 
    _e('All hosts', 'my-calendar');
    ?>
</option>
					<option value="current"><?php 
    _e('Currently logged-in user', 'my-calendar');
    ?>
</option>
					<?php 
    echo $options;
    ?>
				</select>
			</p>
			<?php 
    // Main shortcode only
    if ($type == 'main') {
        ?>
				<p>
					<label for="format"><?php 
        _e('Format', 'my-calendar');
        ?>
</label>
					<select name="format" id="format">
						<option value="calendar" selected="selected"><?php 
        _e('Grid', 'my-calendar');
        ?>
</option>
						<option value="list"><?php 
        _e('List', 'my-calendar');
        ?>
</option>
						<option value="mini"><?php 
        _e('Mini', 'my-calendar');
        ?>
</option>
					</select>
				</p>
				<p>
					<label for="time"><?php 
        _e('Time Segment', 'my-calendar');
        ?>
</label>
					<select name="time" id="time">
						<option value="month" selected="selected"><?php 
        _e('Month', 'my-calendar');
        ?>
</option>
						<option value="month+1"><?php 
        _e('Next Month', 'my-calendar');
        ?>
</option>
						<option value="week"><?php 
        _e('Week', 'my-calendar');
        ?>
</option>
						<option value="day"><?php 
        _e('Day', 'my-calendar');
        ?>
</option>
					</select>
				</p>
				<p>
					<label for="year"><?php 
        _e('Year', 'my-calendar');
        ?>
</label>
					<select name="year" id="year">
						<option value=''><?php 
        _e('Default', 'my-calendar');
        ?>
</option>					
						<?php 
        global $wpdb;
        $mcdb = $wpdb;
        $query = "SELECT event_begin FROM " . my_calendar_table() . " WHERE event_approved = 1 AND event_flagged <> 1 ORDER BY event_begin ASC LIMIT 0 , 1";
        $year1 = date('Y', strtotime($mcdb->get_var($query)));
        $diff1 = date('Y') - $year1;
        $past = $diff1;
        $future = apply_filters('mc_jumpbox_future_years', 5, false);
        $fut = 1;
        $f = '';
        $p = '';
        $offset = 60 * 60 * get_option('gmt_offset');
        while ($past > 0) {
            $p .= '<option value="';
            $p .= date("Y", time() + $offset) - $past;
            $p .= '">';
            $p .= date("Y", time() + $offset) - $past . "</option>\n";
            $past = $past - 1;
        }
        while ($fut < $future) {
            $f .= '<option value="';
            $f .= date("Y", time() + $offset) + $fut;
            $f .= '">';
            $f .= date("Y", time() + $offset) + $fut . "</option>\n";
            $fut = $fut + 1;
        }
        echo $p . '<option value="' . date("Y") . '">' . date("Y") . "</option>\n" . $f;
        ?>
					</select>
					</p>
					<p>
					<label for="month"><?php 
        _e('Month', 'my-calendar');
        ?>
</label>
					<select name="month" id="month">
						<option value=''><?php 
        _e('Default', 'my-calendar');
        ?>
</option>					
						<?php 
        $months = '';
        for ($i = 1; $i <= 12; $i++) {
            $months .= "<option value='{$i}'>" . date_i18n('F', mktime(0, 0, 0, $i, 1)) . '</option>' . "\n";
        }
        echo $months;
        ?>
					</select>
					</p>
					<p>
					<label for="day"><?php 
        _e('Day', 'my-calendar');
        ?>
</label>
					<select name="day" id="day">
						<option value=''><?php 
        _e('Default', 'my-calendar');
        ?>
</option>
						<?php 
        $days = '';
        for ($i = 1; $i <= 31; $i++) {
            $days .= "<option value='{$i}'>" . $i . '</option>' . "\n";
        }
        echo $days;
        ?>
					</select>
				</p>				
				<p id='navigation-info'>
					<?php 
        printf(__("Navigation above and below the calendar: your <a href='%s'>settings</a> if this is left blank. Use <code>none</code> to hide all navigation.", 'my-calendar'), admin_url('admin.php?page=my-calendar-config#mc-output'));
        ?>
				</p>
				<p>
					<label for="above" id='labove'><?php 
        _e('Navigation above calendar', 'my-calendar');
        ?>
</label>
					<input type="text" name="above" id="above" value="nav,toggle,jump,print,timeframe"
					       aria-labelledby='labove navigation-info' /><br/>
				</p>
				<p>
					<label for="below" id='lbelow'><?php 
        _e('Navigation below calendar', 'my-calendar');
        ?>
</label>
					<input type="text" name="below" id="below" value="key,feeds"
					       aria-labelledby='lbelow navigation-info' /><br/>
				</p>
			<?php 
    }
    if ($type == 'upcoming' || $type == 'today') {
        // Upcoming Events & Today's Events shortcodes
        ?>
				<p>
					<label for="fallback"><?php 
        _e('Fallback Text', 'my-calendar');
        ?>
</label>
					<input type="text" name="fallback" id="fallback" value="" />
				</p>
				<p>
					<label for="template"><?php 
        _e('Template', 'my-calendar');
        ?>
</label>
					<textarea cols="40" rows="4" name="template"
					          id="template"><?php 
        echo htmlentities("<strong>{date}</strong>, {time}: {link_title}");
        ?>
</textarea>
				</p>
			<?php 
    }
    if ($type == 'upcoming') {
        // Upcoming events only
        ?>
				<p>
					<label for="before"><?php 
        _e('Events/Days Before Current Day', 'my-calendar');
        ?>
</label>
					<input type="number" name="before" id="before" value="" />
				</p>
				<p>
					<label for="after"><?php 
        _e('Events/Days After Current Day', 'my-calendar');
        ?>
</label>
					<input type="number" name="after" id="after" value="" />
				</p>
				<p>
					<label for="skip"><?php 
        _e('Events/Days to Skip', 'my-calendar');
        ?>
</label>
					<input type="number" name="skip" id="skip" value="" />
				</p>
				<p>
					<label for="show_today"><?php 
        _e("Show Today's Events", 'my-calendar');
        ?>
</label>
					<input type="checkbox" name="show_today" id="show_today" value="yes"/>
				</p>
				<p>
					<label for="type"><?php 
        _e('Type of Upcoming Events List', 'my-calendar');
        ?>
</label>
					<select name="type" id="type">
						<option value="event" selected="selected"><?php 
        _e('Events', 'my-calendar');
        ?>
</option>
						<option value="year"><?php 
        _e('Current Year', 'my-calendar');
        ?>
</option>
						<option value="days"><?php 
        _e('Days', 'my-calendar');
        ?>
</option>
						<option value="custom"><?php 
        _e('Custom Dates', 'my-calendar');
        ?>
</option>
						<option value="month"><?php 
        _e('Current Month', 'my-calendar');
        ?>
</option>
						<option value="month+1"><?php 
        _e('Next Month', 'my-calendar');
        ?>
</option>
						<option value="month+2"><?php 
        _e('2nd Month Out', 'my-calendar');
        ?>
</option>
						<option value="month+3"><?php 
        _e('3rd Month Out', 'my-calendar');
        ?>
</option>
						<option value="month+4"><?php 
        _e('4th Month Out', 'my-calendar');
        ?>
</option>
						<option value="month+5"><?php 
        _e('5th Month Out', 'my-calendar');
        ?>
</option>
						<option value="month+6"><?php 
        _e('6th Month Out', 'my-calendar');
        ?>
</option>
						<option value="month+7"><?php 
        _e('7th Month Out', 'my-calendar');
        ?>
</option>
						<option value="month+8"><?php 
        _e('8th Month Out', 'my-calendar');
        ?>
</option>
						<option value="month+9"><?php 
        _e('9th Month Out', 'my-calendar');
        ?>
</option>
						<option value="month+10"><?php 
        _e('10th Month Out', 'my-calendar');
        ?>
</option>
						<option value="month+11"><?php 
        _e('11th Month Out', 'my-calendar');
        ?>
</option>
						<option value="month+12"><?php 
        _e('12th Month Out', 'my-calendar');
        ?>
</option>
					</select>
				</p>
				<div class='custom'>
					<p>
						<label for='from'><?php 
        _e('Starting Date', 'my-calendar');
        ?>
</label> <input type='text' name='from' id='from' />
					</p>
					<p>
						<label for='to'><?php 
        _e('End Date', 'my-calendar');
        ?>
</label> <input type='text' name='to' id='to' />
					</p>
				</div>
				<p>
					<label for="order"><?php 
        _e('Event Order', 'my-calendar');
        ?>
</label>
					<select name="order" id="order">
						<option value="asc" selected="selected"><?php 
        _e('Ascending', 'my-calendar');
        ?>
</option>
						<option value="desc"><?php 
        _e('Descending', 'my-calendar');
        ?>
</option>
					</select>
				</p>
			<?php 
    }
    ?>
		</div>
	</fieldset>
	<p>
		<input type="submit" class="button-primary" name="generator"
		       value="<?php 
    _e('Generate Shortcode', 'my-calendar');
    ?>
"/>
	</p>
	</form><?php 
}