Exemplo n.º 1
0
function mc_selected_users($selected)
{
    $selected = explode(',', $selected);
    $users = my_calendar_getUsers();
    $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_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 = my_calendar_getUsers();
    $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>
					</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 
        _e("For navigational fields above and below the calendar: the defaults specified in your settings will be used if the attribute is left blank. Use <code>none</code> to hide all navigation elements.", 'my-calendar');
        ?>
				</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('Fallback', '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="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>						
						<option value="year"><?php 
        _e('Current Year', 'my-calendar');
        ?>
</option>
						<option value="days"><?php 
        _e('Days', 'my-calendar');
        ?>
</option>
					</select>
				</p>
				<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 
}
function my_calendar_print_group_fields($data, $mode, $event_id, $group_id = '')
{
    global $user_ID, $wpdb;
    $mcdb = $wpdb;
    get_currentuserinfo();
    $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 $mode;
    ?>
" />
		<input type="hidden" name="event_id" value="<?php 
    echo $event_id;
    ?>
" />
		<input type="hidden" name="event_author" value="<?php 
    echo $user_ID;
    ?>
" />
		<input type="hidden" name="event_post" value="<?php 
    echo $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">	
	<h3><?php 
    _e('Manage Event Groups', 'my-calendar');
    ?>
</h3>
	<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 
        echo $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 
        if (version_compare(get_bloginfo('version'), '3.3', '>=')) {
            wp_editor(stripslashes($description), 'content', array('textarea_rows' => 10));
        } else {
            the_editor(stripslashes($description));
        }
        ?>
			</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 = my_calendar_getUsers();
    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">
	<h3><?php 
        _e('Event Registration Options', 'my-calendar');
        ?>
</h3>
		<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 ? $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">
<h3><?php 
        _e('Event Location', 'my-calendar');
        ?>
</h3>
<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 . "\">" . 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', get_option('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>', $id, $checked, $label, $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 
}
Exemplo n.º 4
0
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">
			<input type='hidden' name='shortcode' value='<?php 
    echo $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 = my_calendar_getUsers();
    $options = '';
    foreach ($users as $u) {
        $options = '<option value="' . $u->ID . '">' . $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>
					</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 id='navigation-info'>
					<?php 
        _e("For navigational fields above and below the calendar: the defaults specified in your settings will be used if the attribute is left blank. Use <code>none</code> to hide all navigation elements.", 'my-calendar');
        ?>
				</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('Fallback', '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="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>						
						<option value="year"><?php 
        _e('Current Year', 'my-calendar');
        ?>
</option>
						<option value="days"><?php 
        _e('Days', 'my-calendar');
        ?>
</option>
					</select>
				</p>
				<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 
}
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;
}
function mc_show_block($field, $has_data, $data, $echo = true)
{
    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 = my_calendar_getUsers();
                $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_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">' . __('Event Description', 'my-calendar') . '</label><br />
									<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">' . __('Event Description', 'my-calendar') . '</label><br />';
                    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) {
                $value = $has_data ? $data->event_image : '';
                $return = '
				<div class="mc-image-upload field-holder">
					<input type="hidden" name="event_image_id" value="" 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($value) . '" placeholder="http://yourdomain.com/image.jpg" /> <a href="#" class="button textfield-field">' . __("Upload", 'my-calendar') . '</a>';
                if (!empty($data->event_image)) {
                    $return .= '<div class="event_image"><img src="' . esc_attr($data->event_image) . '" alt="" /></div>';
                } else {
                    $return .= '<div class="event_image"></div>';
                }
                $return .= '</div>';
            } else {
                $return = '<input type="hidden" name="event_image" value="' . esc_attr($value) . '" />';
            }
            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 . '
<h3>' . __('Recurring', 'my-calendar') . '</h3>
	<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="12" maxlength="1" 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 . '
						<h3>' . $label . '</h3>
							<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 . '
				<h3>' . __('Event Registration Settings', 'my-calendar') . '</h3>
				<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 = "\n\t\t\t\t<div>\n\t\t\t\t\t<input type='hidden' name='event_label' value='" . esc_attr(stripslashes($data->event_label)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_street' value='" . esc_attr(stripslashes($data->event_street)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_street2' value='" . esc_attr(stripslashes($data->event_street2)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_phone' value='" . esc_attr(stripslashes($data->event_phone)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_phone2' value='" . esc_attr(stripslashes($data->event_phone2)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_city' value='" . esc_attr(stripslashes($data->event_city)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_state' value='" . esc_attr(stripslashes($data->event_state)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_postcode' value='" . esc_attr(stripslashes($data->event_postcode)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_region' value='" . esc_attr(stripslashes($data->event_region)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_country' value='" . esc_attr(stripslashes($data->event_country)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_zoom' value='" . esc_attr(stripslashes($data->event_zoom)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_url' value='" . esc_attr(stripslashes($data->event_url)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_latitude' value='" . esc_attr(stripslashes($data->event_latitude)) . "' />\n\t\t\t\t\t<input type='hidden' name='event_longitude' value='" . esc_attr(stripslashes($data->event_longitude)) . "' />\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 mc_form_fields($data, $mode, $event_id)
{
    global $wpdb, $user_ID;
    $mcdb = $wpdb;
    $has_data = empty($data) ? false : true;
    if ($data) {
        $test = mc_test_occurrence_overlap($data);
    }
    $instance = isset($_GET['date']) ? (int) $_GET['date'] : false;
    if ($instance) {
        $ins = mc_get_instance_data($instance);
        $event_id = $ins->occur_event_id;
        $data = mc_get_event_core($event_id);
    }
    ?>

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

<div class="ui-sortable meta-box-sortables">
	<div class="postbox">
		<?php 
    if (isset($_GET['mode']) && $_GET['mode'] == 'edit') {
        $text = __('Edit Event', 'my-calendar');
        $args = '';
        if (isset($_GET['date'])) {
            $id = is_numeric($_GET['date']) ? $_GET['date'] : false;
            if ($id) {
                $args = "&amp;date={$id}";
            }
        }
        $delete = " &middot; <a href='" . admin_url("admin.php?page=my-calendar-manage&amp;mode=delete&amp;event_id={$data->event_id}{$args}") . "' class='delete'>" . __('Delete', 'my-calendar') . "</a>";
    } else {
        $text = __('Add Event', 'my-calendar');
        $delete = '';
    }
    $post_id = $has_data ? $data->event_post : false;
    if ($has_data && !$data->event_post) {
        $array_data = (array) $data;
        $post_id = mc_event_post('add', $array_data, $data->event_id);
    }
    if (apply_filters('mc_use_permalinks', get_option('mc_use_permalinks')) == 'true') {
        $post_link = $post_id ? get_edit_post_link($post_id) : false;
        $text_link = $post_link ? sprintf(" &middot; <a href='%s'>" . __('Edit Event Post', 'my-calendar') . "</a>", $post_link) : '';
    } else {
        $text_link = '';
    }
    ?>
		<h3><?php 
    echo $text;
    ?>
 <span class="alignright"><a
					href="<?php 
    echo admin_url('admin.php?page=my-calendar-manage');
    ?>
"><?php 
    _e('Manage events', 'my-calendar');
    ?>
</a><?php 
    echo $delete;
    echo $text_link;
    ?>
</span>
		</h3>

		<div class="inside">
			<?php 
    if (!empty($_GET['date']) && $data->event_recur != 'S') {
        $event = mc_get_event($instance);
        $date = date_i18n(get_option('mc_date_format'), strtotime($event->occur_begin));
        $message = __("You are editing the <strong>{$date}</strong> instance of this event. Other instances of this event will not be changed.", 'my-calendar');
        //echo "<div><input type='hidden' name='event_instance' value='$instance' /></div>";
        echo "<div class='message updated'><p>{$message}</p></div>";
    } else {
        if (isset($_GET['date']) && empty($_GET['date'])) {
            echo "<div class='message updated'><p>" . __('There was an error acquiring information about this event instance. The ID for this event instance was not provided. <strong>You are editing this entire recurrence set.</strong>', 'my-calendar') . "</p></div>";
        }
    }
    ?>
			<fieldset>
				<legend class="screen-reader-text"><?php 
    _e('Event Details', 'my-calendar');
    ?>
</legend>
				<p>
					<label for="e_title"><?php 
    _e('Event Title', 'my-calendar');
    ?>
 <span
							class='required'><?php 
    _e('(required)', 'my-calendar');
    ?>
</span></label><br/><input
						type="text" id="e_title" name="event_title" size="50" maxlength="255"
						value="<?php 
    if ($has_data) {
        echo apply_filters('mc_manage_event_title', stripslashes(esc_attr($data->event_title)), $data);
    }
    ?>
"/><?php 
    if ($mode == 'edit') {
        ?>
						<input type='hidden' name='prev_event_status'
						       value='<?php 
        echo $data->event_approved;
        ?>
' /><?php 
        if (get_option('mc_event_approve') == 'true') {
            if (current_user_can('mc_approve_events')) {
                // Added by Roland P.
                if ($has_data && $data->event_approved == '1') {
                    $checked = " checked=\"checked\"";
                } else {
                    if ($has_data && $data->event_approved == '0') {
                        $checked = "";
                    } else {
                        if (get_option('mc_event_approve') == 'true') {
                            $checked = "checked=\"checked\"";
                        }
                    }
                }
                ?>
								<input type="checkbox" value="1" id="e_approved"
								       name="event_approved" <?php 
                echo $checked;
                ?>
 /> <label
									for="e_approved"><?php 
                _e('Approve', 'my-calendar');
                ?>
</label><?php 
            } else {
                // case: editing, approval enabled, user cannot approve
                ?>
								<input type="hidden" value="0"
								       name="event_approved" /><?php 
                _e('An administrator must approve your new event.', 'my-calendar');
            }
        } else {
            // Case: editing, approval system is disabled - auto approve
            ?>
							<input type="hidden" value="1" name="event_approved"/><?php 
        }
    } else {
        // case: adding new event (if use can, then 1, else 0)
        if (get_option('mc_event_approve') != 'true') {
            $dvalue = 1;
        } else {
            if (current_user_can('mc_approve_events')) {
                $dvalue = 1;
            } else {
                $dvalue = 0;
            }
        }
        ?>
						<input type="hidden" value="<?php 
        echo $dvalue;
        ?>
" name="event_approved" /><?php 
    }
    ?>
				</p>
				<?php 
    if (is_object($data) && $data->event_flagged == 1) {
        ?>
					<div class="error">
						<p>
							<input type="checkbox" value="0" id="e_flagged"
							       name="event_flagged"<?php 
        if ($has_data && $data->event_flagged == '0') {
            echo " checked=\"checked\"";
        } else {
            if ($has_data && $data->event_flagged == '1') {
                echo "";
            }
        }
        ?>
 /> <label
								for="e_flagged"><?php 
        _e('This event is not spam', 'my-calendar');
        ?>
</label>
						</p>
					</div>
				<?php 
    }
    if (function_exists('jd_doTwitterAPIPost') && current_user_can('wpt_can_tweet')) {
        if (!($mode == 'edit' && $data->event_approved == 1)) {
            ?>
						<p>
						<label
							for='mc_twitter'><?php 
            _e('Post to Twitter (via WP to Twitter)', 'my-calendar');
            ?>
</label><br/>
						<textarea cols='70' rows='2' id='mc_twitter'
						          name='mc_twitter'><?php 
            do_action('mc_twitter_text', $data);
            ?>
</textarea>
						</p><?php 
        }
    }
    mc_show_block('event_desc', $has_data, $data);
    mc_show_block('event_short', $has_data, $data);
    mc_show_block('event_image', $has_data, $data);
    ?>
				<p>
					<label for="e_host"><?php 
    _e('Host', 'my-calendar');
    ?>
</label>
					<select id="e_host" name="event_host">
						<?php 
    // Grab all the categories and list them
    $users = my_calendar_getUsers();
    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 = '';
            }
        }
        echo "<option value='{$u->ID}'{$selected}>{$display_name}</option>\n";
    }
    ?>
					</select>
				</p>
				<?php 
    mc_show_block('event_category', $has_data, $data);
    mc_show_block('event_link', $has_data, $data);
    echo apply_filters('mc_event_details', '', $has_data, $data, 'admin');
    ?>
			</fieldset>
		</div>
	</div>
</div>

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

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

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

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

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

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