function mc_list_groups()
{
    global $wpdb;
    $mcdb = $wpdb;
    $sortby = isset($_GET['sort']) ? (int) $_GET['sort'] : get_option('mc_default_sort');
    if (isset($_GET['order'])) {
        $sortdir = isset($_GET['order']) && $_GET['order'] == 'ASC' ? 'ASC' : 'default';
    } else {
        $sortdir = 'default';
    }
    if (empty($sortby)) {
        $sortbyvalue = 'event_begin';
    } else {
        switch ($sortby) {
            case 1:
                $sortbyvalue = 'event_ID';
                break;
            case 2:
                $sortbyvalue = 'event_title';
                break;
            case 3:
                $sortbyvalue = 'event_desc';
                break;
            case 4:
                $sortbyvalue = 'event_begin';
                break;
            case 5:
                $sortbyvalue = 'event_author';
                break;
            case 6:
                $sortbyvalue = 'event_category';
                break;
            case 7:
                $sortbyvalue = 'event_label';
                break;
            case 8:
                $sortbyvalue = 'group_id';
                break;
            default:
                $sortbyvalue = 'event_begin';
        }
    }
    $sortbydirection = $sortdir == 'default' ? 'DESC' : $sortdir;
    $sorting = $sortbydirection == 'DESC' ? "&order=ASC" : '';
    $current = empty($_GET['paged']) ? 1 : intval($_GET['paged']);
    $user = get_current_user_id();
    $screen = get_current_screen();
    $option = $screen->get_option('per_page', 'option');
    $items_per_page = get_user_meta($user, $option, true);
    if (empty($items_per_page) || $items_per_page < 1) {
        $items_per_page = $screen->get_option('per_page', 'default');
    }
    $limit = isset($_GET['limit']) ? $_GET['limit'] : 'all';
    switch ($limit) {
        case 'all':
            $limit = '';
            break;
        case 'grouped':
            $limit = 'WHERE event_group_id <> 0';
            break;
        case 'ungrouped':
            $limit = 'WHERE event_group_id = 0';
            break;
        default:
            $limit = '';
    }
    $events = $mcdb->get_results("SELECT SQL_CALC_FOUND_ROWS * FROM " . my_calendar_table() . " {$limit} ORDER BY {$sortbyvalue} {$sortbydirection} LIMIT " . ($current - 1) * $items_per_page . ", " . $items_per_page);
    $found_rows = $wpdb->get_col("SELECT FOUND_ROWS();");
    $items = $found_rows[0];
    ?>
<div class='inside'><?php 
    if (get_option('mc_event_approve') == 'true') {
        ?>
		<ul class="links">
		<li><a <?php 
        echo isset($_GET['limit']) && $_GET['limit'] == 'groupeed' ? ' class="active-link"' : '';
        ?>
 href="<?php 
        echo admin_url('admin.php?page=my-calendar-groups&amp;limit=grouped#my-calendar-admin-table');
        ?>
"><?php 
        _e('Grouped Events', 'my-calendar');
        ?>
</a></li>
		<li><a <?php 
        echo isset($_GET['limit']) && $_GET['limit'] == 'ungrouped' ? ' class="active-link"' : '';
        ?>
  href="<?php 
        echo admin_url('admin.php?page=my-calendar-groups&amp;limit=ungrouped#my-calendar-admin-table');
        ?>
"><?php 
        _e('Ungrouped Events', 'my-calendar');
        ?>
</a></li> 
		<li><a <?php 
        echo isset($_GET['limit']) && $_GET['limit'] == 'all' || !isset($_GET['limit']) ? ' class="active-link"' : '';
        ?>
  href="<?php 
        echo admin_url('admin.php?page=my-calendar-groups#my-calendar-admin-table');
        ?>
"><?php 
        _e('All', 'my-calendar');
        ?>
</a></li>
		</ul>
	<?php 
    }
    ?>
	<p><?php 
    _e('Check a set of events to group them for mass editing.', 'my-calendar');
    ?>
</p><?php 
    $num_pages = ceil($items / $items_per_page);
    if ($num_pages > 1) {
        $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => __('&laquo; Previous<span class="screen-reader-text"> Events</span>', 'my-calendar'), 'next_text' => __('Next<span class="screen-reader-text"> Events</span> &raquo;', 'my-calendar'), 'total' => $num_pages, 'current' => $current, 'mid_size' => 1));
        printf("<div class='tablenav'><div class='tablenav-pages'>%s</div></div>", $page_links);
    }
    if (!empty($events)) {
        ?>
		<form action="<?php 
        echo admin_url("admin.php?page=my-calendar-groups");
        ?>
" method="post">
		<div>
		<input type="hidden" name="_wpnonce" value="<?php 
        echo wp_create_nonce('my-calendar-nonce');
        ?>
" />
		<input type="hidden" name="event_action" value="group" />
		</div>
		<p style="position:relative;display:inline-block;">
		<input type="submit" class="button-primary group" value="<?php 
        _e('Group checked events for mass editing', 'my-calendar');
        ?>
" />
		</p>
	</div>
	<table class="widefat wp-list-table" id="my-calendar-admin-table">
	<thead>
	<tr>
		<th  scope="col" style="width: 50px;"><a href="<?php 
        echo admin_url("admin.php?page=my-calendar-groups&amp;sort=1{$sorting}");
        ?>
"><?php 
        _e('ID', 'my-calendar');
        ?>
</a></th>
		<th  scope="col"><a href="<?php 
        echo admin_url("admin.php?page=my-calendar-groups&amp;sort=8{$sorting}");
        ?>
"><?php 
        _e('Group', 'my-calendar');
        ?>
</a></th>
		<th  scope="col"><a href="<?php 
        echo admin_url("admin.php?page=my-calendar-groups&amp;sort=2{$sorting}");
        ?>
"><?php 
        _e('Title', 'my-calendar');
        ?>
</a></th>
		<th  scope="col"><a href="<?php 
        echo admin_url("admin.php?page=my-calendar-groups&amp;sort=7{$sorting}");
        ?>
"><?php 
        _e('Where', 'my-calendar');
        ?>
</a></th>
		<th  scope="col"><a href="<?php 
        echo admin_url("admin.php?page=my-calendar-groups&amp;sort=4{$sorting}");
        ?>
"><?php 
        _e('Starts', 'my-calendar');
        ?>
</a></th>
		<th  scope="col"><?php 
        _e('Recurs', 'my-calendar');
        ?>
</th>
		<th  scope="col"><a href="<?php 
        echo admin_url("admin.php?page=my-calendar-groups&amp;sort=5{$sorting}");
        ?>
"><?php 
        _e('Author', 'my-calendar');
        ?>
</a></th>
		<th  scope="col"><a href="<?php 
        echo admin_url("admin.php?page=my-calendar-groups&amp;sort=6{$sorting}");
        ?>
"><?php 
        _e('Category', 'my-calendar');
        ?>
</a></th>
	</tr>
	</thead>
		<?php 
        $class = '';
        $sql = "SELECT * FROM " . my_calendar_categories_table();
        $categories = $mcdb->get_results($sql);
        foreach ($events as $event) {
            $class = $class == 'alternate' ? '' : 'alternate';
            $spam = $event->event_flagged == 1 ? ' spam' : '';
            $spam_label = $event->event_flagged == 1 ? '<strong>Possible spam:</strong> ' : '';
            $author = $event->event_author != 0 ? get_userdata($event->event_author) : 'Public Submitter';
            if ($event->event_link != '') {
                $title = "<a href='" . esc_attr($event->event_link) . "'>{$event->event_title}</a>";
            } else {
                $title = $event->event_title;
            }
            ?>
			<tr class="<?php 
            echo $class;
            echo $spam;
            ?>
" id="event<?php 
            echo $event->event_id;
            ?>
">
				<th scope="row"><input type="checkbox" value="<?php 
            echo $event->event_id;
            ?>
" name="group[]" id="mc<?php 
            echo $event->event_id;
            ?>
" <?php 
            echo mc_event_is_grouped($event->event_group_id) ? ' disabled="disabled"' : '';
            ?>
 /> <label for="mc<?php 
            echo $event->event_id;
            ?>
"><?php 
            echo $event->event_id;
            ?>
</label></th>
				<th scope="row"><?php 
            echo $event->event_group_id == 0 ? '-' : $event->event_group_id;
            ?>
</th>
				<td title="<?php 
            echo esc_attr(substr(strip_tags(stripslashes($event->event_desc)), 0, 240));
            ?>
">
					<strong><?php 
            if (mc_can_edit_event($event->event_author)) {
                ?>
						<a href="<?php 
                echo admin_url("admin.php?page=my-calendar&amp;mode=edit&amp;event_id={$event->event_id}");
                ?>
" class='edit'>
					<?php 
            }
            echo $spam_label;
            echo stripslashes($title);
            ?>
					<?php 
            if (mc_can_edit_event($event->event_author)) {
                echo "</a>";
            }
            ?>
</strong>
				<div class='row-actions' style="visibility:visible;">
				<?php 
            if (mc_can_edit_event($event->event_author)) {
                ?>
				<a href="<?php 
                echo admin_url("admin.php?page=my-calendar&amp;mode=edit&amp;event_id={$event->event_id}");
                ?>
" class='edit'><?php 
                _e('Edit Event', 'my-calendar');
                ?>
</a> | 
					<?php 
                if (mc_event_is_grouped($event->event_group_id)) {
                    ?>
					<a href="<?php 
                    echo admin_url("admin.php?page=my-calendar-groups&amp;mode=edit&amp;event_id={$event->event_id}&amp;group_id={$event->event_group_id}");
                    ?>
" class='edit group'><?php 
                    _e('Edit Group', 'my-calendar');
                    ?>
</a>
					<?php 
                } else {
                    ?>
					<em><?php 
                    _e('Ungrouped', 'my-calendar');
                    ?>
</em>
					<?php 
                }
            } else {
                _e("Not editable.", 'my-calendar');
            }
            ?>
		
				</div>
				</td>
				<td><?php 
            echo stripslashes($event->event_label);
            ?>
</td>
				<?php 
            if ($event->event_time != "00:00:00") {
                $eventTime = date_i18n(get_option('mc_time_format'), strtotime($event->event_time));
            } else {
                $eventTime = get_option('mc_notime_text');
            }
            ?>
				<td><?php 
            echo "{$event->event_begin}<br />{$eventTime}";
            ?>
</td>
				<td>
				<?php 
            $recurs = str_split($event->event_recur, 1);
            $recur = $recurs[0];
            $every = isset($recurs[1]) ? $recurs[1] : 1;
            // Interpret the DB values into something human readable
            if ($recur == 'S') {
                _e('Never', 'my-calendar');
            } else {
                if ($recur == 'D') {
                    _e('Daily', 'my-calendar');
                } else {
                    if ($recur == 'E') {
                        _e('Weekdays', 'my-calendar');
                    } else {
                        if ($recur == 'W') {
                            _e('Weekly', 'my-calendar');
                        } else {
                            if ($recur == 'B') {
                                _e('Bi-Weekly', 'my-calendar');
                            } else {
                                if ($recur == 'M') {
                                    _e('Monthly (by date)', 'my-calendar');
                                } else {
                                    if ($recur == 'U') {
                                        _e('Monthly (by day)', 'my-calendar');
                                    } else {
                                        if ($recur == 'Y') {
                                            _e('Yearly', 'my-calendar');
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            ?>
&ndash;<?php 
            if ($recur == 'S') {
                _e('N/A', 'my-calendar');
            } else {
                if (mc_event_repeats_forever($recur, $event->event_repeats)) {
                    _e('Forever', 'my-calendar');
                } else {
                    if ($event->event_repeats > 0) {
                        printf(__('%d Times', 'my-calendar'), $event->event_repeats);
                    }
                }
            }
            ?>
				
				</td>
				<td><?php 
            echo is_object($author) ? $author->display_name : $author;
            ?>
</td>
					<?php 
            $this_category = $event->event_category;
            foreach ($categories as $key => $value) {
                if ($value->category_id == $this_category) {
                    $this_cat = $categories[$key];
                }
            }
            ?>
				<td><div class="category-color" style="background-color:<?php 
            echo strpos($this_cat->category_color, '#') !== 0 ? '#' : '';
            echo $this_cat->category_color;
            ?>
;"> </div> <?php 
            echo stripslashes($this_cat->category_name);
            ?>
</td>
				<?php 
            unset($this_cat);
            ?>
			</tr><?php 
        }
        ?>
		</table>
		<div class="inside">
			<p>
			<input type="submit" class="button-secondary group" value="<?php 
        _e('Group checked events for mass editing', 'my-calendar');
        ?>
" />
			</p>
		</div>
		</form><?php 
    } else {
        ?>
		<div class="inside"><p><?php 
        _e("There are no events in the database!", 'my-calendar');
        ?>
</p></div><?php 
    }
}
function mc_list_events()
{
    global $wpdb;
    $mcdb = $wpdb;
    if (current_user_can('mc_approve_events') || current_user_can('mc_manage_events') || current_user_can('mc_add_events')) {
        $action = !empty($_POST['event_action']) ? $_POST['event_action'] : '';
        $event_id = !empty($_POST['event_id']) ? $_POST['event_id'] : '';
        if ($action == 'delete') {
            $message = mc_delete_event($event_id);
            echo $message;
        }
        if (isset($_GET['order'])) {
            $sortdir = isset($_GET['order']) && $_GET['order'] == 'ASC' ? 'ASC' : 'default';
            $sortdir = isset($_GET['order']) && $_GET['order'] == 'DESC' ? 'DESC' : $sortdir;
        } else {
            $sortdir = 'default';
        }
        $default_direction = get_option('mc_default_direction') == '' ? 'ASC' : get_option('mc_default_direction');
        $sortbydirection = $sortdir == 'default' ? $default_direction : $sortdir;
        $sortby = isset($_GET['sort']) ? $_GET['sort'] : get_option('mc_default_sort');
        if (empty($sortby)) {
            $sortbyvalue = 'event_begin';
        } else {
            switch ($sortby) {
                case 1:
                    $sortbyvalue = 'event_ID';
                    break;
                case 2:
                    $sortbyvalue = 'event_title';
                    break;
                case 3:
                    $sortbyvalue = 'event_desc';
                    break;
                case 4:
                    $sortbyvalue = "event_begin {$sortbydirection}, event_time";
                    break;
                case 5:
                    $sortbyvalue = 'event_author';
                    break;
                case 6:
                    $sortbyvalue = 'event_category';
                    break;
                case 7:
                    $sortbyvalue = 'event_label';
                    break;
                default:
                    $sortbyvalue = "event_begin {$sortbydirection}, event_time";
            }
        }
        $sorting = $sortbydirection == 'DESC' ? "&amp;order=ASC" : '&amp;order=DESC';
        $allow_filters = true;
        $status = isset($_GET['limit']) ? $_GET['limit'] : 'all';
        $restrict = isset($_GET['restrict']) ? $_GET['restrict'] : 'all';
        switch ($status) {
            case 'all':
                $limit = '';
                break;
            case 'reserved':
                $limit = 'WHERE event_approved <> 1';
                break;
            case 'published':
                $limit = 'WHERE event_approved = 1';
                break;
            default:
                $limit = '';
        }
        switch ($restrict) {
            case 'all':
                $filter = '';
                break;
            case 'where':
                $filter = isset($_GET['filter']) ? $_GET['filter'] : '';
                $restrict = "event_label";
                break;
            case 'author':
                $filter = isset($_GET['filter']) ? (int) $_GET['filter'] : '';
                $restrict = "event_author";
                break;
            case 'category':
                $filter = isset($_GET['filter']) ? (int) $_GET['filter'] : '';
                $restrict = "event_category";
                break;
            case 'flagged':
                $filter = isset($_GET['filter']) ? (int) $_GET['filter'] : '';
                $restrict = "event_flagged";
                break;
            default:
                $filter = '';
        }
        if (!current_user_can('mc_manage_events') && !current_user_can('mc_approve_events')) {
            $restrict = 'event_author';
            $filter = get_current_user_id();
            $allow_filters = false;
        }
        $filter = esc_sql(urldecode($filter));
        if ($restrict == "event_label") {
            $filter = "'{$filter}'";
        }
        if ($limit == '' && $filter != '') {
            $limit = "WHERE {$restrict} = {$filter}";
        } else {
            if ($limit != '' && $filter != '') {
                $limit .= "AND {$restrict} = {$filter}";
            }
        }
        if ($filter == '' || !$allow_filters) {
            $filtered = "";
        } else {
            $filtered = "<span class='dashicons dashicons-no'></span><a href='" . admin_url('admin.php?page=my-calendar-manage') . "'>" . __('Clear filters', 'my-calendar') . "</a>";
        }
        $current = empty($_GET['paged']) ? 1 : intval($_GET['paged']);
        $user = get_current_user_id();
        $screen = get_current_screen();
        $option = $screen->get_option('per_page', 'option');
        $items_per_page = get_user_meta($user, $option, true);
        if (empty($items_per_page) || $items_per_page < 1) {
            $items_per_page = $screen->get_option('per_page', 'default');
        }
        // default limits
        if ($limit == '') {
            $limit .= $restrict != 'event_flagged' ? " WHERE event_flagged = 0" : '';
        } else {
            $limit .= $restrict != 'event_flagged' ? " AND event_flagged = 0" : '';
        }
        if (isset($_POST['mcs'])) {
            $query = $_POST['mcs'];
            $limit .= mc_prepare_search_query($query);
        }
        $limit .= $restrict != 'archived' ? " AND event_status = 1" : ' AND event_status = 0';
        $events = $mcdb->get_results("SELECT SQL_CALC_FOUND_ROWS event_id FROM " . my_calendar_table() . " {$limit} ORDER BY {$sortbyvalue} {$sortbydirection} LIMIT " . ($current - 1) * $items_per_page . ", " . $items_per_page);
        $found_rows = $wpdb->get_col("SELECT FOUND_ROWS();");
        $items = $found_rows[0];
        if ((function_exists('akismet_http_post') || function_exists('bs_checker')) && $allow_filters) {
            ?>
			<ul class="links">
			<li>
				<a <?php 
            echo isset($_GET['restrict']) && $_GET['restrict'] == 'flagged' ? 'class="active-link"' : '';
            ?>
					href="<?php 
            echo admin_url('admin.php?page=my-calendar-manage&amp;restrict=flagged&amp;filter=1');
            ?>
"><?php 
            _e('Spam', 'my-calendar');
            ?>
</a>
			</li>
			</ul><?php 
        }
        ?>
		<div class='mc-search'>
			<form action="<?php 
        echo esc_url(add_query_arg($_GET, admin_url('admin.php')));
        ?>
" method="post">
				<div><input type="hidden" name="_wpnonce"
				            value="<?php 
        echo wp_create_nonce('my-calendar-nonce');
        ?>
"/>
				</div>
				<div>
					<label for="mc_search" class='screen-reader-text'><?php 
        _e('Search', 'my-calendar');
        ?>
</label>
					<input type='text' role='search' name='mcs' id='mc_search'
					       value='<?php 
        if (isset($_POST['mcs'])) {
            esc_attr_e($_POST['mcs']);
        }
        ?>
'/> <input type='submit' value='<?php 
        _e('Search Events', 'my-calendar');
        ?>
'
					                      class='button-secondary'/>
				</div>
			</form>
		</div>
		<?php 
        if (get_option('mc_event_approve') == 'true') {
            ?>
			<ul class="links">
			<li>
				<a <?php 
            echo isset($_GET['limit']) && $_GET['limit'] == 'published' ? 'class="active-link"' : '';
            ?>
					href="<?php 
            echo admin_url('admin.php?page=my-calendar-manage&amp;limit=published');
            ?>
"><?php 
            _e('Published', 'my-calendar');
            ?>
</a>
			</li>
			<li>
				<a <?php 
            echo isset($_GET['limit']) && $_GET['limit'] == 'reserved' ? 'class="active-link"' : '';
            ?>
					href="<?php 
            echo admin_url('admin.php?page=my-calendar-manage&amp;limit=reserved');
            ?>
"><?php 
            _e('Reserved', 'my-calendar');
            ?>
</a>
			</li>
			<li>
				<a <?php 
            echo isset($_GET['limit']) && $_GET['limit'] == 'all' || !isset($_GET['limit']) ? 'class="active-link"' : '';
            ?>
					href="<?php 
            echo admin_url('admin.php?page=my-calendar-manage&amp;restrict=archived');
            ?>
"><?php 
            _e('Archived', 'my-calendar');
            ?>
</a>
			</li>
			<li>
				<a <?php 
            echo isset($_GET['limit']) && $_GET['limit'] == 'all' || !isset($_GET['limit']) ? 'class="active-link"' : '';
            ?>
					href="<?php 
            echo admin_url('admin.php?page=my-calendar-manage&amp;limit=all');
            ?>
"><?php 
            _e('All', 'my-calendar');
            ?>
</a>
			</li>
			</ul><?php 
        }
        echo $filtered;
        $num_pages = ceil($items / $items_per_page);
        if ($num_pages > 1) {
            $page_links = paginate_links(array('base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => __('&laquo; Previous<span class="screen-reader-text"> Events</span>', 'my-calendar'), 'next_text' => __('Next<span class="screen-reader-text"> Events</span> &raquo;', 'my-calendar'), 'total' => $num_pages, 'current' => $current, 'mid_size' => 1));
            printf("<div class='tablenav'><div class='tablenav-pages'>%s</div></div>", $page_links);
        }
        if (!empty($events)) {
            ?>
			<form action="<?php 
            echo esc_url(add_query_arg($_GET, admin_url('admin.php')));
            ?>
" method="post">
			<div><input type="hidden" name="_wpnonce" value="<?php 
            echo wp_create_nonce('my-calendar-nonce');
            ?>
"/>
			</div>
			<div class='mc-actions'>
				<input type="submit" class="button-secondary delete" name="mass_delete"
				       value="<?php 
            _e('Delete events', 'my-calendar');
            ?>
"/>
				<?php 
            if (current_user_can('mc_approve_events')) {
                ?>
					<input type="submit" class="button-secondary mc-approve" name="mass_approve"
					       value="<?php 
                _e('Approve events', 'my-calendar');
                ?>
"/>
				<?php 
            }
            ?>
				<?php 
            if (!(isset($_GET['restrict']) && $_GET['restrict'] == 'archived')) {
                ?>
					<input type="submit" class="button-secondary mc-archive" name="mass_archive"
					       value="<?php 
                _e('Archive events', 'my-calendar');
                ?>
"/>
				<?php 
            } else {
                ?>
					<input type="submit" class="button-secondary mc-archive" name="mass_undo_archive"
					       value="<?php 
                _e('Remove from archive', 'my-calendar');
                ?>
"/>				
				<?php 
            }
            ?>
			</div>

			<table class="widefat wp-list-table" id="my-calendar-admin-table">
				<thead>
				<tr>
					<th scope="col" style="width: 50px;"><input type='checkbox' class='selectall' id='mass_edit'/>
						<label for='mass_edit' class="screen-reader-text"><?php 
            _e('Check/Uncheck all', 'my-calendar');
            ?>
</label> <a
							href="<?php 
            echo admin_url("admin.php?page=my-calendar-manage&amp;sort=1{$sorting}");
            ?>
"><?php 
            _e('ID', 'my-calendar');
            ?>
</a>
					</th>
					<th scope="col"><a
							href="<?php 
            echo admin_url("admin.php?page=my-calendar-manage&amp;sort=2{$sorting}");
            ?>
"><?php 
            _e('Title', 'my-calendar');
            ?>
</a>
					</th>
					<th scope="col"><a
							href="<?php 
            echo admin_url("admin.php?page=my-calendar-manage&amp;sort=7{$sorting}");
            ?>
"><?php 
            _e('Location', 'my-calendar');
            ?>
</a>
					</th>
					<th scope="col"><a
							href="<?php 
            echo admin_url("admin.php?page=my-calendar-manage&amp;sort=4{$sorting}");
            ?>
"><?php 
            _e('Date/Time', 'my-calendar');
            ?>
</a>
					</th>
					<th scope="col"><a
							href="<?php 
            echo admin_url("admin.php?page=my-calendar-manage&amp;sort=5{$sorting}");
            ?>
"><?php 
            _e('Author', 'my-calendar');
            ?>
</a>
					</th>
					<th scope="col"><a
							href="<?php 
            echo admin_url("admin.php?page=my-calendar-manage&amp;sort=6{$sorting}");
            ?>
"><?php 
            _e('Category', 'my-calendar');
            ?>
</a>
					</th>
				</tr>
				</thead>
				<?php 
            $class = '';
            $sql = "SELECT * FROM " . my_calendar_categories_table();
            $categories = $mcdb->get_results($sql);
            foreach (array_keys($events) as $key) {
                $event =& $events[$key];
                $event = mc_get_event_core($event->event_id);
                if (!is_object($event)) {
                    continue;
                }
                $class = $class == 'alternate' ? 'even' : 'alternate';
                $pending = $event->event_approved == 0 ? 'pending' : '';
                $author = $event->event_author != 0 ? get_userdata($event->event_author) : 'Public Submitter';
                if ($event->event_flagged == 1 && (isset($_GET['restrict']) && $_GET['restrict'] == 'flagged')) {
                    $spam = 'spam';
                    $pending = '';
                    $spam_label = '<strong>' . __('Possible spam', 'my-calendar') . ':</strong> ';
                } else {
                    $spam = '';
                    $spam_label = '';
                }
                $edit_url = admin_url("admin.php?page=my-calendar&amp;mode=edit&amp;event_id={$event->event_id}");
                $copy_url = admin_url("admin.php?page=my-calendar&amp;mode=copy&amp;event_id={$event->event_id}");
                $view_url = mc_get_details_link($event);
                $group_url = admin_url("admin.php?page=my-calendar-groups&amp;mode=edit&amp;event_id={$event->event_id}&amp;group_id={$event->event_group_id}");
                $delete_url = admin_url("admin.php?page=my-calendar-manage&amp;mode=delete&amp;event_id={$event->event_id}");
                $check = mc_test_occurrence_overlap($event, true);
                $problem = $check != '' ? 'problem' : '';
                if (current_user_can('mc_manage_events') || current_user_can('mc_approve_events') || mc_can_edit_event($event->event_id)) {
                    ?>
						<tr class="<?php 
                    echo "{$class} {$spam} {$pending} {$problem}";
                    ?>
">
							<th scope="row">
								<input type="checkbox" value="<?php 
                    echo $event->event_id;
                    ?>
" name="mass_edit[]" id="mc<?php 
                    echo $event->event_id;
                    ?>
" <?php 
                    echo $event->event_flagged == 1 ? 'checked="checked"' : '';
                    ?>
 />
								<label for="mc<?php 
                    echo $event->event_id;
                    ?>
"><?php 
                    echo $event->event_id;
                    ?>
</label>
							</th>
							<td title="<?php 
                    echo esc_attr(substr(strip_tags(stripslashes($event->event_desc)), 0, 240));
                    ?>
">
								<strong><?php 
                    if (mc_can_edit_event($event->event_id)) {
                        ?>
									<a href="<?php 
                        echo $edit_url;
                        ?>
" class='edit'>
										<?php 
                    }
                    ?>
										<?php 
                    echo $spam_label;
                    echo strip_tags(stripslashes($event->event_title));
                    ?>
									<?php 
                    if (mc_can_edit_event($event->event_id)) {
                        echo "</a>";
                        if ($check != '') {
                            echo '<br /><strong class="error">' . sprintf(__('There is a problem with this event. <a href="%s">View</a>', 'my-calendar'), $edit_url) . '</strong>';
                        }
                    }
                    ?>
</strong>

								<div class='row-actions' style="visibility:visible;">
									<?php 
                    if (mc_event_published($event)) {
                        ?>
										<a href="<?php 
                        echo $view_url;
                        ?>
"
									   class='view'><?php 
                        _e('View', 'my-calendar');
                        ?>
</a> |
									<?php 
                    }
                    ?>
									<a href="<?php 
                    echo $copy_url;
                    ?>
"
									   class='copy'><?php 
                    _e('Copy', 'my-calendar');
                    ?>
</a> |
									<?php 
                    if (mc_can_edit_event($event->event_id)) {
                        ?>
										<a href="<?php 
                        echo $edit_url;
                        ?>
" class='edit'><?php 
                        _e('Edit', 'my-calendar');
                        ?>
</a> 
										<?php 
                        if (mc_event_is_grouped($event->event_group_id)) {
                            ?>
											| <a href="<?php 
                            echo $group_url;
                            ?>
" class='edit group'><?php 
                            _e('Edit Group', 'my-calendar');
                            ?>
</a>
										<?php 
                        }
                        ?>
										| <a href="<?php 
                        echo $delete_url;
                        ?>
" class="delete"><?php 
                        _e('Delete', 'my-calendar');
                        ?>
</a>
									<?php 
                    } else {
                        _e("Not editable.", 'my-calendar');
                    }
                    if (get_option('mc_event_approve') == 'true') {
                        ?>
										|
										<?php 
                        if (current_user_can('mc_approve_events')) {
                            // Added by Roland P.
                            if ($event->event_approved == '1') {
                                $mo = 'reject';
                                $te = __('Reject', 'my-calendar');
                            } else {
                                $mo = 'publish';
                                $te = __('Approve', 'my-calendar');
                            }
                            ?>
											<a href="<?php 
                            echo admin_url("admin.php?page=my-calendar-manage&amp;mode={$mo}&amp;event_id={$event->event_id}");
                            ?>
"
											   class='<?php 
                            echo $mo;
                            ?>
'><?php 
                            echo $te;
                            ?>
</a>
										<?php 
                        } else {
                            switch ($event->event_approved) {
                                case 1:
                                    _e('Approved', 'my-calendar');
                                    break;
                                case 2:
                                    _e('Rejected', 'my-calendar');
                                    break;
                                default:
                                    _e('Awaiting Approval', 'my-calendar');
                            }
                        }
                    }
                    ?>
								</div>
							</td>
							<td>
								<?php 
                    if ($event->event_label != '') {
                        ?>
<a class='mc_filter' href='<?php 
                        $elabel = urlencode($event->event_label);
                        echo admin_url("admin.php?page=my-calendar-manage&amp;filter={$elabel}&amp;restrict=where");
                        ?>
' title="<?php 
                        _e('Filter by location', 'my-calendar');
                        ?>
"><span class="screen-reader-text"><?php 
                        _e('Show only: ', 'my-calendar');
                        ?>
</span><?php 
                        echo strip_tags(stripslashes($event->event_label));
                        ?>
</a><?php 
                    }
                    ?>
							</td>
							<?php 
                    if ($event->event_endtime != "23:59:59") {
                        $eventTime = date_i18n(get_option('mc_time_format'), strtotime($event->event_time));
                    } else {
                        $eventTime = mc_notime_label($event);
                    }
                    ?>
							<td><?php 
                    $date_format = get_option('mc_date_format') == '' ? get_option('date_format') : get_option('mc_date_format');
                    $begin = date_i18n($date_format, strtotime($event->event_begin));
                    echo "{$begin}, {$eventTime}";
                    ?>
								<div class="recurs">
									<strong><?php 
                    _e('Recurs', 'my-calendar');
                    ?>
</strong>
									<?php 
                    $recurs = str_split($event->event_recur, 1);
                    $recur = $recurs[0];
                    $every = isset($recurs[1]) ? $recurs[1] : 1;
                    // Interpret the DB values into something human readable
                    switch ($recur) {
                        case 'S':
                            _e('Never', 'my-calendar');
                            break;
                        case 'D':
                            $every == 1 ? _e('Daily', 'my-calendar') : printf(__('Every %d days', 'my-calendar'), $every);
                            break;
                        case 'E':
                            $every == 1 ? _e('Weekdays', 'my-calendar') : printf(__('Every %d weekdays', 'my-calendar'), $every);
                            break;
                        case 'W':
                            $every == 1 ? _e('Weekly', 'my-calendar') : printf(__('Every %d weeks', 'my-calendar'), $every);
                            break;
                        case 'B':
                            _e('Bi-Weekly', 'my-calendar');
                            break;
                        case 'M':
                            $every == 1 ? _e('Monthly (by date)', 'my-calendar') : printf(__('Every %d months (by date)', 'my-calendar'), $every);
                            break;
                        case 'U':
                            _e('Monthly (by day)', 'my-calendar');
                            break;
                        case 'Y':
                            $every == 1 ? _e('Yearly', 'my-calendar') : printf(__('Every %d years', 'my-calendar'), $every);
                            break;
                    }
                    $eternity = _mc_increment_values($recur);
                    if ($recur == 'S') {
                    } else {
                        if ($event->event_repeats > 0) {
                            printf(__('&ndash; %d Times', 'my-calendar'), $event->event_repeats);
                        } else {
                            if ($eternity) {
                                printf(__('&ndash; %d Times', 'my-calendar'), $eternity);
                            }
                        }
                    }
                    ?>
								</div>
							</td>
							<td><a class='mc_filter' href="<?php 
                    $auth = is_object($author) ? $author->ID : 0;
                    echo admin_url("admin.php?page=my-calendar-manage&amp;filter={$auth}&amp;restrict=author");
                    ?>
"
							       title="<?php 
                    _e('Filter by author', 'my-calendar');
                    ?>
"><span
										class="screen-reader-text"><?php 
                    _e('Show only: ', 'my-calendar');
                    ?>
</span><?php 
                    echo is_object($author) ? $author->display_name : $author;
                    ?>
								</a></td>
							<?php 
                    if (!$event->event_category) {
                        // events *must* have a category
                        mc_update_event('event_category', 1, $event->event_id, '%d');
                    }
                    $color = strip_tags(mc_get_category_detail($event->event_category, 'category_color'));
                    ?>
							<td>
								<div class="category-color"
								     style="background-color:<?php 
                    echo strpos($color, '#') !== 0 ? '#' : '';
                    echo $color;
                    ?>
;">
								</div>
								<a class='mc_filter'
								   href='<?php 
                    echo admin_url("admin.php?page=my-calendar-manage&amp;filter={$event->event_category}&amp;restrict=category");
                    ?>
'
								   title="<?php 
                    _e('Filter by category', 'my-calendar');
                    ?>
"><span
										class="screen-reader-text"><?php 
                    _e('Show only: ', 'my-calendar');
                    ?>
</span><?php 
                    echo mc_kses_post(mc_get_category_detail($event->event_category, 'category_name'));
                    ?>
								</a></td>
						</tr>
					<?php 
                }
            }
            ?>
			</table>
			<p>
				<input type="submit" class="button-secondary delete" name="mass_delete"
				       value="<?php 
            _e('Delete events', 'my-calendar');
            ?>
"/>
				<?php 
            if (current_user_can('mc_approve_events')) {
                ?>
					<input type="submit" class="button-secondary mc-approve" name="mass_approve"
					       value="<?php 
                _e('Approve events', 'my-calendar');
                ?>
"/>
				<?php 
            }
            ?>
				<?php 
            if (!(isset($_GET['restrict']) && $_GET['restrict'] == 'archived')) {
                ?>
					<input type="submit" class="button-secondary mc-archive" name="mass_archive"
					       value="<?php 
                _e('Archive events', 'my-calendar');
                ?>
"/>
				<?php 
            }
            ?>
			</p>

			<p>
				<?php 
            if (!(isset($_GET['restrict']) && $_GET['restrict'] == 'archived')) {
                ?>
					<a class='mc_filter'
					   href='<?php 
                echo admin_url("admin.php?page=my-calendar-manage&amp;restrict=archived");
                ?>
'><?php 
                _e('View Archived Events', 'my-calendar');
                ?>
</a>
				<?php 
            } else {
                ?>
					<a class='mc_filter'
					   href='<?php 
                echo admin_url("admin.php?page=my-calendar-manage");
                ?>
'><?php 
                _e('Return to Manage Events', 'my-calendar');
                ?>
</a>
				<?php 
            }
            ?>
			</p>
			</form>
		<?php 
        } else {
            ?>
			<p class='mc-none'><?php 
            _e("There are no events in the database meeting your current criteria.", 'my-calendar');
            ?>
</p><?php 
        }
    }
}
function mc_edit_panel($html, $event, $type, $time)
{
    // create edit links
    $edit = '';
    if (mc_can_edit_event($event->event_author) && get_option('mc_remote') != 'true') {
        $mc_id = $event->occur_id;
        $groupedit = $event->event_group_id != 0 ? " &bull; <a href='" . admin_url("admin.php?page=my-calendar-groups&amp;mode=edit&amp;event_id={$event->event_id}&amp;group_id={$event->event_group_id}") . "' class='group'>" . __('Edit Group', 'my-calendar') . "</a>\n" : '';
        $recurs = str_split($event->event_recur, 1);
        $recur = $recurs[0];
        $referer = urlencode(mc_get_current_url());
        $edit = "<div class='mc_edit_links'><p>";
        if ($recur == 'S') {
            $edit .= "<a href='" . admin_url("admin.php?page=my-calendar&amp;mode=edit&amp;event_id={$event->event_id}&amp;ref={$referer}") . "' class='edit'>" . __('Edit', 'my-calendar') . "</a> &bull; <a href='" . admin_url("admin.php?page=my-calendar-manage&amp;mode=delete&amp;event_id={$event->event_id}&amp;ref={$referer}") . "' class='delete'>" . __('Delete', 'my-calendar') . "</a>{$groupedit}";
        } else {
            $edit .= "<a href='" . admin_url("admin.php?page=my-calendar&amp;mode=edit&amp;event_id={$event->event_id}&amp;date={$mc_id}&amp;ref={$referer}") . "' class='edit'>" . __('Edit This Date', 'my-calendar') . "</a> &bull; <a href='" . admin_url("admin.php?page=my-calendar&amp;mode=edit&amp;event_id={$event->event_id}&amp;ref={$referer}") . "' class='edit'>" . __('Edit All', 'my-calendar') . "</a> &bull; <a href='" . admin_url("admin.php?page=my-calendar-manage&amp;mode=delete&amp;event_id={$event->event_id}&amp;date={$mc_id}&amp;ref={$referer}") . "' class='delete'>" . __('Delete This Date', 'my-calendar') . "</a> &bull; <a href='" . admin_url("admin.php?page=my-calendar-manage&amp;mode=delete&amp;event_id={$event->event_id}&amp;ref={$referer}") . "' class='delete'>" . __('Delete All', 'my-calendar') . "</a>\n\t\t\t{$groupedit}";
        }
        $edit .= "</p></div>";
    }
    if ($type == 'calendar' && get_option('mc_open_uri') == 'true' && $time != 'day') {
        $edit = '';
    }
    return $html . $edit;
}
function mc_submit_form($fields, $categories, $locations, $category, $location, $location_fields)
{
    $fields = apply_filters('mcs_submit_fields', $fields);
    $location_fields = apply_filters('mcs_submit_location_fields', $location_fields);
    // the big function. This creates the form.
    wp_enqueue_script('pickadate', plugins_url('my-calendar/js/pickadate/picker.js'));
    wp_enqueue_script('pickadate.date', plugins_url('my-calendar/js/pickadate/picker.date.js'));
    wp_enqueue_script('pickadate.time', plugins_url('my-calendar/js/pickadate/picker.time.js'));
    wp_localize_script('pickadate.date', 'mc_months', array(date_i18n('F', strtotime('January 1')), date_i18n('F', strtotime('February 1')), date_i18n('F', strtotime('March 1')), date_i18n('F', strtotime('April 1')), date_i18n('F', strtotime('May 1')), date_i18n('F', strtotime('June 1')), date_i18n('F', strtotime('July 1')), date_i18n('F', strtotime('August 1')), date_i18n('F', strtotime('September 1')), date_i18n('F', strtotime('October 1')), date_i18n('F', strtotime('November 1')), date_i18n('F', strtotime('December 1'))));
    wp_localize_script('pickadate.date', 'mc_days', array(date_i18n('D', strtotime('Sunday')), date_i18n('D', strtotime('Monday')), date_i18n('D', strtotime('Tuesday')), date_i18n('D', strtotime('Wednesday')), date_i18n('D', strtotime('Thursday')), date_i18n('D', strtotime('Friday')), date_i18n('D', strtotime('Saturday'))));
    wp_register_script('mcs-submit-form', plugins_url('/js/jquery.mcs-submit.js', __FILE__), array('jquery'));
    wp_enqueue_script('mcs-submit-form');
    $format = get_option('mcs_date_format');
    switch ($format) {
        case "m/d/Y":
            $js_format = 'mm/dd/yyyy';
            break;
        case "d-m-Y":
            $js_format = 'dd-mm-yyyy';
            break;
        case "Y-m-d":
            $js_format = 'yy-mm-dd';
            break;
        case "j F Y":
            $js_format = 'd mmmm yyyy';
            break;
        case "M j, Y":
            $js_format = 'mmm d, yyyy';
            break;
        default:
            $js_format = 'yy-mm-dd';
    }
    $time = get_option('mcs_time_format');
    switch ($time) {
        case "H:i":
            $js_time_format = 'HH:i';
            break;
        default:
            $js_time_format = 'h:i a';
    }
    $script = "\n<script>\n(function (\$) {\n\t\$(function() {\n\t\t\$( 'input.mc-date' ).pickadate({\n\t\t\tmonthsFull: mc_months,\n\t\t\tformat: '{$js_format}',\n\t\t\tweekdaysShort: mc_days,\n\t\t\tselectYears: true,\n\t\t\tselectMonths: true,\n\t\t\teditable: true\n\t\t});\n\t\t\$( 'input.mc-time' ).pickatime({\n\t\t\tinterval: 15,\n\t\t\tformat: '{$js_time_format}',\n\t\t\teditable: true\t\t\n\t\t});\n\t})\n})(jQuery);\n</script>";
    global $user_ID;
    if (is_user_logged_in()) {
        $auth = $user_ID;
    } else {
        $auth = 0;
    }
    $nonce = "<input type='hidden' name='event_nonce_name' value='" . wp_create_nonce('event_nonce') . "' />";
    $response = mcs_processor_response();
    $event = false;
    if (empty($response[1]) && isset($_GET['mcs_id']) && is_user_logged_in()) {
        $mc_id = intval($_GET['mcs_id']);
        $event = mc_form_data($mc_id);
        if (!mc_can_edit_event($event->event_id)) {
            $event = false;
        }
    }
    if (isset($_GET['mcs_id']) && !is_user_logged_in()) {
        $message = "<div class='updated'><p>" . __("You'll need to log-in to edit this event.", 'my-calendar-submissions') . "</p></div>";
    } else {
        $message = '';
    }
    $data = !empty($response[1]) ? $response[1] : $event;
    $has_data = empty($data) ? false : true;
    $title = !empty($data) ? esc_attr($data->event_title) : '';
    $desc = !empty($data) ? esc_attr($data->event_desc) : '';
    $tickets = !empty($data) ? esc_attr($data->event_tickets) : '';
    $registration = !empty($data) ? esc_attr($data->event_registration) : '';
    $begin = !empty($data) ? esc_attr($data->event_begin) : '';
    $format = date(get_option('mcs_date_format'), current_time('timestamp'));
    $format2 = date(get_option('mcs_time_format'), current_time('timestamp'));
    $endformat2 = date(get_option('mcs_time_format'), current_time('timestamp') + 3600);
    $end = !empty($data) ? esc_attr($data->event_end) : '';
    $time = !empty($data) ? esc_attr($data->event_time) : $format2;
    $endtime = !empty($data) ? esc_attr($data->event_endtime) : $endformat2;
    $recur = !empty($data) ? esc_attr($data->event_recur) : 'S';
    $recurs = str_split($recur, 1);
    $recur = $recurs[0];
    $every = isset($recurs[1]) ? $recurs[1] : 1;
    if ($every == 1 && $recur == 'B') {
        $every = 2;
    }
    $repeats = !empty($data) ? esc_attr($data->event_repeats) : 0;
    $selected_category = !empty($data) ? esc_attr($data->event_category) : $category;
    $event_host = !empty($data) ? esc_attr($data->event_host) : $user_ID;
    $link = !empty($data) ? esc_attr($data->event_link) : '';
    $label = !empty($data) ? esc_attr($data->event_label) : '';
    $street = !empty($data) ? esc_attr($data->event_street) : '';
    $street2 = !empty($data) ? esc_attr($data->event_street2) : '';
    $city = !empty($data) ? esc_attr($data->event_city) : '';
    $state = !empty($data) ? esc_attr($data->event_state) : '';
    $postcode = !empty($data) ? esc_attr($data->event_postcode) : '';
    $country = !empty($data) ? esc_attr($data->event_country) : '';
    $region = !empty($data) ? esc_attr($data->event_region) : '';
    $url = !empty($data) ? esc_attr($data->event_url) : '';
    $longitude = !empty($data) ? esc_attr($data->event_longitude) : '';
    $latitude = !empty($data) ? esc_attr($data->event_latitude) : '';
    $phone = !empty($data) ? esc_attr($data->event_phone) : '';
    $short = !empty($data) ? esc_attr($data->event_short) : '';
    $image = !empty($data) ? esc_attr($data->event_image) : '';
    $name = isset($_POST['event_name']) ? esc_attr($_POST['event_name']) : '';
    $email = isset($_POST['event_email']) ? esc_attr($_POST['event_email']) : '';
    $key = isset($_POST['event_key']) ? esc_attr($_POST['event_key']) : '';
    $key = isset($_GET['event_key']) ? esc_attr($_GET['event_key']) : '';
    if ($event) {
        $link_expires = $event->event_link_expires;
        $event_holiday = $event->event_holiday;
        $event_fifth_week = $event->event_fifth_week;
        $edit = "<input type='hidden' name='event_edit' value='{$mc_id}' />";
        $edit .= "\n\t\t\t<input type='hidden' name='prev_event_begin' value='{$begin}' />\n\t\t\t<input type='hidden' name='prev_event_repeats' value='{$repeats}' />\n\t\t\t<input type='hidden' name='prev_event_recur' value='{$recur}' />\n\t\t\t<input type='hidden' name='prev_event_status' value='{$event->event_approved}' />\n\t\t\t<input type='hidden' name='event_post' value='{$event->event_post}' />";
    } else {
        $link_expires = get_option('mc_event_link_expires') == 'false' ? 1 : 0;
        $event_holiday = get_option('mc_skip_holidays') == 'true' ? 'on' : 'false';
        $event_fifth_week = get_option('mc_no_fifth_week') == 'true' ? 1 : '';
        $edit = '';
    }
    $selected_location = array('label' => $label, 'street' => $street, 'street2' => $street2, 'city' => $city, 'state' => $state, 'postcode' => $postcode, 'country' => $country, 'region' => $region, 'url' => $url, 'longitude' => $longitude, 'latitude' => $latitude, 'phone' => $phone);
    $payment_form = mcs_payment_required() ? mcs_payment_form() : '';
    $check_conflicts = get_option('mcs_check_conflicts') == 'true' ? '<input type="hidden" name="mcs_check_conflicts" value="true" />' : '';
    $approved = get_option('mcs_automatic_approval') == 'true' || current_user_can('mc_manage_events') ? 1 : 0;
    // need to set hidden inputs to default values.
    $enctype = get_option('mcs_upload_images') == 'true' ? ' enctype="multipart/form-data"' : '';
    $return = "{$script}\n\t<div class='mc-submissions'>\n\t\t{$message}\n\t\t{$response['0']}\n\t\t{$payment_form}\n\t\t<form action='' method='post' class='mcs-submission'{$enctype}>\n\t\t<div>\n\t\t{$nonce}\n\t\t<input type='hidden' name='mcs_submission' value='on' />\n\t\t<input type='hidden' name='event_approved' value='{$approved}' /> \n\t\t<input type='hidden' name='event_author' value='{$auth}' />\n\t\t<input type='hidden' name='event_link_expires' value='" . $link_expires . "' />\n\t\t<input type='hidden' name='event_holiday' value='" . $event_holiday . "' />\n\t\t<input type='hidden' name='event_fifth_week' value='" . $event_fifth_week . "' />\n\t\t<input type='hidden' name='event_group_id' value='" . mc_group_id() . "' />\n\t\t<div style='display: none;'>\n\t\t\t<label for='your_name'>" . __('Do not complete this field.', 'my-calendar-submissions') . "</label>\n\t\t\t<input type='text' name='your_name' id='your_name' value='' />\n\t\t</div>\n\t\t{$edit}";
    if (apply_filters('mcs_event_allday', 0) == true) {
        $return .= "<input type='hidden' name='event_allday' value='1' />";
    }
    if (apply_filters('mcs_event_hide_end', 0) == true) {
        $return .= "<input type='hidden' name='event_hide_end' value='1' />";
    }
    $return .= "{$check_conflicts}\n\t\t</div>";
    if (mcs_payment_required()) {
        $return .= "<p><label for='mcs_key'>" . __('Payment Key', 'my-calendar-submissions') . ' <span>' . __('(required)', 'my-calendar-submissions') . "</span></label> <input type='text' name='mcs_key' id='mcs_key' value='{$key}' required='required' aria-required='true' /></p>";
    }
    $flabel = isset($fields['event_title']) ? $fields['event_title'] : __('Event Title', 'my-calendar-submissions');
    $dlabel = isset($fields['event_date']) ? $fields['event_date'] : __('Date', 'my-calendar-submissions');
    $tlabel = isset($fields['event_time']) ? $fields['event_time'] : __('Time', 'my-calendar-submissions');
    $return .= "\n\t\t<p>\n\t\t<label for='mc_event_title'>{$flabel} <span>" . __('(required)', 'my-calendar-submissions') . "</span></label> <input type='text' name='event_title' id='mc_event_title' value='{$title}' required='required' aria-required='true' />\n\t\t</p>\n\t\t<div class='mc_begin_container'>\n\t\t<p>\n\t\t<label for='mc_event_date'>{$dlabel} <span>" . __('(required)', 'my-calendar-submissions') . "</span></label> <input type='text' class='mc-date' name='event_begin[]' id='mc_event_date' value='{$begin}' required='required' aria-required='true' />\n\t\t</p>\n\t\t<p>\n\t\t<label for='mc_event_time'>{$tlabel}</label> <input type='time' name='event_time[]' id='mc_event_time' class='mc-time' value='{$time}' />\n\t\t</p>\n\t\t</div>";
    if (isset($fields['end_date']) || isset($fields['end_time'])) {
        $return .= "<div class='mc_end_container'>";
    }
    if (isset($fields['end_date'])) {
        $flabel = $fields['end_date'] != 'true' && $fields['end_date'] != 'End date' ? $fields['end_date'] : __('End date', 'my-calendar-submissions');
        $return .= "<p>\n\t\t\t<label for='mc_event_enddate'>{$flabel}</label> <input type='text' class='mc-date' name='event_end[]' id='mc_event_enddate' value='{$end}' />\n\t\t\t</p>";
    } else {
        $return .= "<input type='hidden' name='event_end[]' value='' />";
    }
    if (isset($fields['end_time'])) {
        $flabel = $fields['end_time'] != 'true' && $fields['end_time'] != 'End time' ? $fields['end_time'] : __('End time', 'my-calendar-submissions');
        $return .= "<p>\n\t\t\t<label for='mc_event_endtime'>{$flabel}</label> <input type='time' name='event_endtime[]' id='mc_event_endtime' class='mc-time' value='{$endtime}'/>\n\t\t\t</p>";
    }
    if (isset($fields['end_date']) || isset($fields['end_time'])) {
        $return .= "</div>";
    }
    if (is_user_logged_in()) {
        $current_user = wp_get_current_user();
        $name = $current_user->display_name;
        $email = $current_user->user_email;
    }
    $disallow_user_changes = apply_filters('mcs_disallow_user_changes', false);
    $required = apply_filters('mcs_require_name_and_email', 'required="required"');
    if ($disallow_user_changes && is_user_logged_in()) {
        $return .= "<input name='mcs_name' value='{$name}' type='hidden' /><input name='mcs_email' value='{$email}' type='hidden' />";
    } else {
        $flabel = isset($fields['mcs_name']) && $fields['mcs_name'] != 'true' && $fields['mcs_name'] != 'Your Name' ? $fields['mcs_name'] : __('Your Name', 'my-calendar-submissions');
        $return .= "<p>\n\t\t\t\t<label for='mcs_name'>{$flabel}</label> <input type='text' name='mcs_name' id='mcs_name' value='{$name}' {$required} />\n\t\t\t\t</p>";
        $flabel = isset($fields['mcs_email']) && $fields['mcs_email'] != 'true' && $fields['mcs_email'] != 'Your Email' ? $fields['mcs_email'] : __('Your Email', 'my-calendar-submissions');
        $return .= "<p>\n\t\t\t\t<label for='mcs_email'>{$flabel}</label> <input type='email' name='mcs_email' id='mcs_email' value='{$email}' {$required} />\n\t\t\t\t</p>";
    }
    if (isset($fields['event_host'])) {
        $host_select = '<select id="e_host" name="event_host">';
        // Grab all the users and list them
        $users = my_calendar_getUsers();
        $num = 0;
        foreach ($users as $u) {
            $display_name = $u->display_name == '' ? $u->user_nicename : $u->display_name;
            if ($event_host == $u->ID) {
                $selected = ' selected="selected"';
            } else {
                $selected = '';
            }
            if (user_can($u->ID, apply_filters('mcs_eligible_hosts', 'mc_add_events'))) {
                $host_select .= "<option value='{$u->ID}'{$selected}>{$display_name}</option>\n";
                $num++;
                $single_host = $u->ID;
            }
        }
        $host_select .= '</select>';
        $flabel = isset($fields['event_host']) && $fields['event_host'] != 'true' && $fields['event_host'] != 'Event Host' ? $fields['event_host'] : __('Event Host', 'my-calendar-submissions');
        if ($num <= 1) {
            $return .= "<input type='hidden' name='event_host' value='{$single_host}' />";
        } else {
            $return .= "\n\t\t\t\t<p class='event_host'>\n\t\t\t\t\t<label for='e_host'>" . $flabel . "</label>\n\t\t\t\t\t{$host_select}\n\t\t\t\t</p>";
        }
    }
    if (isset($fields['event_recurring'])) {
        $return .= "\n\t\t\t<p class='recurring'>\n\t\t\t<label for='event_repeats'>" . __('Repeats', 'my-calendar-submissions') . "</label> <input type='number' name='event_repeats' id='event_repeats' class='input' size='1' min='0' max='999' value='{$repeats}' /> \n\t\t\t<label for='event_every'>" . __('every', 'my-calendar') . "</label> <input type='number' name='event_every' id='event_every' class='input' size='1' min='1' max='9' maxlength='1' value='{$every}' /> \n\t\t\t<label for='event_recur' class='screen-reader-text'>" . __('Units', 'my-calendar-submissions') . "</label> <select name='event_recur' class='input' id='event_recur'>" . mc_recur_options($recur) . "\n\t\t\t</select> \n\t\t\t</p>";
        // event_repeats, event_recur
    } else {
        $return .= "<div>\n\t\t\t\t\t<input type='hidden' name='event_repeats' value='0' />\n\t\t\t\t\t<input type='hidden' name='event_recur' value='S' />\n\t\t\t\t\t<input type='hidden' name='event_every' value='1' />\n\t\t\t\t\t</div>";
    }
    // event_open, event_group
    if (isset($fields['description'])) {
        $flabel = $fields['description'] != 'true' && !($fields['description'] == 'Description' || $fields['description'] == 'Event Description') ? $fields['description'] : __('Description', 'my-calendar-submissions');
        $return .= "<p><label for='mc_event_description'>{$flabel}</label> <textarea name='content' id='mc_event_description' class='full_description'>{$desc}</textarea></p>";
    }
    if (isset($fields['short_description'])) {
        $flabel = $fields['short_description'] != 'true' && !($fields['short_description'] == 'Summary' || $fields['short_description'] == 'Short Description') ? $fields['short_description'] : __('Summary', 'my-calendar-submissions');
        $return .= "<p><label for='mc_event_short_description'>{$flabel}</label> <textarea name='event_short' id='mc_event_short_description' class='short_description'>{$short}</textarea></p>";
    }
    $return .= apply_filters('mc_event_details', '', $has_data, $data, 'public');
    if (isset($fields['access']) && function_exists('mc_event_accessibility')) {
        $flabel = $fields['access'] != 'true' && $fields['access'] != 'Event Access' ? $fields['access'] : __('Event Access', 'my-calendar-submissions');
        $return .= mc_event_accessibility('', $data, $flabel);
    }
    if (isset($fields['event_link'])) {
        $flabel = $fields['event_link'] != 'true' && !($fields['event_link'] == 'Link' || $fields['event_link'] == 'Event Link') ? $fields['event_link'] : __('Link', 'my-calendar-submissions');
        $return .= "<p>\n\t\t\t\t<label for='mc_event_link'>{$flabel}</label> <input type='url' name='event_link' id='mc_event_link' value='{$link}' placeholder='http://' />\n\t\t\t\t</p>";
    }
    if (isset($fields['event_image'])) {
        $flabel = $fields['event_image'] != 'true' && !($fields['event_image'] == 'Image (URL)' || $fields['event_image'] == 'Event image') ? $fields['event_image'] : __('Image (URL)', 'my-calendar-submissions');
        if (get_option('mcs_upload_images') == 'true' && $image == '') {
            $input_type = 'file';
        } else {
            $input_type = 'url';
        }
        $return .= "<p>\n\t\t\t\t<label for='mc_event_image'>{$flabel}</label> <input type='{$input_type}' name='event_image' id='mc_event_image' value='{$image}' />\n\t\t\t\t</p>";
    }
    $return .= mcs_submit_category($selected_category, $categories);
    if (isset($fields['registration'])) {
        $flabel = $fields['registration'] != 'true' && $fields['registration'] != 'Ticketing Information' ? $fields['registration'] : __('Ticketing Information', 'my-calendar-submissions');
        $return .= "<fieldset>\n\t\t\t<legend>{$flabel}</legend>";
        $return .= apply_filters('mc_event_registration', '', $has_data, $data, 'public');
        $return .= "</fieldset>";
    }
    $return .= mcs_submit_location($location, $locations, $location_fields, $selected_location);
    $return .= "<p><input type='submit' name='save' value='" . __('Submit your event', 'my-calendar-submissions') . "' /></p>";
    $return .= "\n\t\t</form>\t\n\t</div>";
    $return = apply_filters('mcs_after_submissions', $return, $response);
    return $return;
}