Example #1
0
/**
* Sets up the event data metabox
* This allows user to enter date / time, reoccurrence and venue data for the event
* @ignore
* @since 1.0.0
*/
function _eventorganiser_details_metabox($post)
{
    global $wp_locale;
    //Sets the format as php understands it, and textual.
    $phpFormat = eventorganiser_get_option('dateformat');
    if ('d-m-Y' == $phpFormat) {
        $format = 'dd-mm-yyyy';
        //Human form
    } elseif ('Y-m-d' == $phpFormat) {
        $format = 'yyyy-mm-dd';
        //Human form
    } else {
        $format = 'mm-dd-yyyy';
        //Human form
    }
    $is24 = eventorganiser_blog_is_24();
    $time_format = $is24 ? 'H:i' : 'g:ia';
    //Get the starting day of the week
    $start_day = intval(get_option('start_of_week'));
    $ical_days = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
    //Retrieve event details
    extract(eo_get_event_schedule($post->ID));
    $venues = eo_get_venues();
    $venue_id = (int) eo_get_venue($post->ID);
    //$sche_once is used to disable date editing unless the user specifically requests it.
    //But a new event might be recurring (via filter), and we don't want to 'lock' new events.
    //See https://wordpress.org/support/topic/wrong-default-in-input-element
    $sche_once = $schedule == 'once' || !empty(get_current_screen()->action);
    if (!$sche_once) {
        $notices = '<strong>' . __('This is a reoccurring event', 'eventorganiser') . '</strong>. ' . __('Check to edit this event and its reoccurrences', 'eventorganiser') . ' <input type="checkbox" id="HWSEvent_rec" name="eo_input[AlterRe]" value="yes">';
    } else {
        $notices = '';
    }
    //Start of meta box
    /**
     * Filters the notice at the top of the event details metabox.
     * 
     * @param string  $notices The message text.
     * @param WP_Post $post    The corresponding event (post).
     */
    $notices = apply_filters('eventorganiser_event_metabox_notice', $notices, $post);
    if ($notices) {
        echo '<div class="updated below-h2"><p>' . $notices . '</p></div>';
    }
    ?>
	<div class="<?php 
    echo $sche_once ? 'onetime' : 'reoccurence';
    ?>
">
		<p>
		<?php 
    if ($is24) {
        printf(__('Ensure dates are entered in %1$s format and times in 24 hour format', 'eventorganiser'), '<strong>' . $format . '</strong>');
    } else {
        printf(__('Ensure dates are entered in %1$s format and times in 12 hour format', 'eventorganiser'), '<strong>' . $format . '</strong>');
    }
    ?>
 		</p>

		<table id="eventorganiser_event_detail" class="form-table">
				<tr valign="top" class="event-date">
					<td class="eo-label"><?php 
    echo __('Start Date/Time', 'eventorganiser') . ':';
    ?>
 </td>
					<td> 
						<input class="ui-widget-content ui-corner-all" name="eo_input[StartDate]" size="10" maxlength="10" id="from_date" <?php 
    disabled(!$sche_once);
    ?>
 value="<?php 
    echo $start->format($phpFormat);
    ?>
"/>
						<?php 
    printf('<input name="eo_input[StartTime]" class="eo_time ui-widget-content ui-corner-all" size="6" maxlength="8" id="HWSEvent_time" %s value="%s"/>', disabled(!$sche_once || $all_day, true, false), eo_format_datetime($start, $time_format));
    ?>
						

					</td>
				</tr>

				<tr valign="top" class="event-date">
					<td class="eo-label"><?php 
    echo __('End Date/Time', 'eventorganiser') . ':';
    ?>
 </td>
					<td> 
						<input class="ui-widget-content ui-corner-all" name="eo_input[EndDate]" size="10" maxlength="10" id="to_date" <?php 
    disabled(!$sche_once);
    ?>
  value="<?php 
    echo $end->format($phpFormat);
    ?>
"/>
					
						<?php 
    printf('<input name="eo_input[FinishTime]" class="eo_time ui-widget-content ui-corner-all" size="6" maxlength="8" id="HWSEvent_time2" %s value="%s"/>', disabled(!$sche_once || $all_day, true, false), eo_format_datetime($end, $time_format));
    ?>
	

					<label>
					<input type="checkbox" id="eo_allday"  <?php 
    checked($all_day);
    ?>
 name="eo_input[allday]"  <?php 
    disabled(!$sche_once);
    ?>
 value="1"/>
						<?php 
    _e('All day', 'eventorganiser');
    ?>
					 </label>
			
					</td>
				</tr>

				<tr class="event-date">
					<td class="eo-label"><?php 
    _e('Reoccurence:', 'eventorganiser');
    ?>
 </td>
					<td> 
					<?php 
    $reoccurrence_schedules = array('once' => __('once', 'eventorganiser'), 'daily' => __('daily', 'eventorganiser'), 'weekly' => __('weekly', 'eventorganiser'), 'monthly' => __('monthly', 'eventorganiser'), 'yearly' => __('yearly', 'eventorganiser'), 'custom' => __('custom', 'eventorganiser'));
    ?>

					<select id="HWSEventInput_Req" name="eo_input[schedule]">
						<?php 
    foreach ($reoccurrence_schedules as $index => $val) {
        ?>
							<option value="<?php 
        echo $index;
        ?>
" <?php 
        selected($schedule, $index);
        ?>
><?php 
        echo $val;
        ?>
</option>
						<?php 
    }
    //End foreach $allowed_reoccurs
    ?>
					</select>
					</td>
				</tr>

				<tr valign="top"  class="event-date reocurrence_row">
					<td></td>
					<td>
						<p><?php 
    _e('Repeat every', 'eventorganiser');
    ?>
 
						<input <?php 
    disabled(!$sche_once || $all_day);
    ?>
 class="ui-widget-content ui-corner-all" name="eo_input[event_frequency]" id="HWSEvent_freq" type="number" min="1" max="365" maxlength="4" size="4" disabled="disabled" value="<?php 
    echo $frequency;
    ?>
" /> 
						<span id="recpan" >  </span>				
						</p>

						<p id="dayofweekrepeat">
						<?php 
    _e('on', 'eventorganiser');
    ?>
	
						<?php 
    for ($i = 0; $i <= 6; $i++) {
        $d = ($start_day + $i) % 7;
        $ical_d = $ical_days[$d];
        $day = $wp_locale->weekday_abbrev[$wp_locale->weekday[$d]];
        $schedule_days = is_array($schedule_meta) ? $schedule_meta : array();
        ?>
							<input type="checkbox" id="day-<?php 
        echo $day;
        ?>
"  <?php 
        checked(in_array($ical_d, $schedule_days), true);
        ?>
  value="<?php 
        echo esc_attr($ical_d);
        ?>
" class="daysofweek" name="eo_input[days][]" disabled="disabled" />
							<label for="day-<?php 
        echo $day;
        ?>
" > <?php 
        echo $day;
        ?>
</label>
						<?php 
    }
    ?>
						</p>

						<p id="dayofmonthrepeat">
						<label for="bymonthday" >	
							<input type="radio" id="bymonthday" disabled="disabled" name="eo_input[schedule_meta]" <?php 
    checked($occurs_by, 'BYMONTHDAY');
    ?>
 value="BYMONTHDAY=" /> 
							<?php 
    _e('day of month', 'eventorganiser');
    ?>
						</label>
						<label for="byday" >
							<input type="radio" id="byday" disabled="disabled" name="eo_input[schedule_meta]"  <?php 
    checked($occurs_by != 'BYMONTHDAY', true);
    ?>
 value="BYDAY=" /> 
							<?php 
    _e('day of week', 'eventorganiser');
    ?>
						</label>
						</p>

						<p class="reoccurrence_label">
						<?php 
    _e('until', 'eventorganiser');
    ?>
 
						<input <?php 
    disabled(!$sche_once || $all_day);
    ?>
 class="ui-widget-content ui-corner-all" name="eo_input[schedule_end]" id="recend" size="10" maxlength="10" disabled="disabled" value="<?php 
    echo $until->format($phpFormat);
    ?>
"/>
						</p>

						<p id="event_summary"> </p>
					</td>
				</tr>

				<tr valign="top" id="eo_occurrence_picker_row" class="event-date">
					<td class="eo-label">	
						<?php 
    esc_html_e('Include/Exclude occurrences', 'eventorganiser');
    ?>
					</td>
					<td>
						<?php 
    submit_button(__('Show dates', 'eventorganiser'), 'hide-if-no-js eo_occurrence_toggle button small', 'eo_date_toggle', false);
    ?>
						
						<div id="eo_occurrence_datepicker"></div>
						<?php 
    //var_dump($include);
    if (!empty($include)) {
        $include_str = array_map('eo_format_datetime', $include, array_fill(0, count($include), 'Y-m-d'));
        $include_str = esc_textarea(sanitize_text_field(implode(',', $include_str)));
    } else {
        $include_str = '';
    }
    ?>
						<textarea style="display:none;" name="eo_input[include]" id="eo_occurrence_includes"><?php 
    echo $include_str;
    ?>
</textarea>

						<?php 
    if (!empty($exclude)) {
        $exclude_str = array_map('eo_format_datetime', $exclude, array_fill(0, count($exclude), 'Y-m-d'));
        $exclude_str = esc_textarea(sanitize_text_field(implode(',', $exclude_str)));
    } else {
        $exclude_str = '';
    }
    ?>
						<textarea style="display:none;" name="eo_input[exclude]" id="eo_occurrence_excludes"><?php 
    echo $exclude_str;
    ?>
</textarea>

					</td>
				</tr>
				<?php 
    $tax = get_taxonomy('event-venue');
    if (taxonomy_exists('event-venue')) {
        ?>
		
					
						<tr valign="top" class="eo-venue-combobox-select">
							<td class="eo-label"> <?php 
        echo esc_html($tax->labels->singular_name_colon);
        ?>
 </td>
							<td> 	
								<select size="50" id="venue_select" name="eo_input[event-venue]">
									<option><?php 
        _e('Select a venue', 'eventorganiser');
        ?>
</option>
									<?php 
        foreach ($venues as $venue) {
            ?>
										<option <?php 
            selected($venue->term_id, $venue_id);
            ?>
 value="<?php 
            echo intval($venue->term_id);
            ?>
"><?php 
            echo esc_html($venue->name);
            ?>
</option>
									<?php 
        }
        ?>
								</select>
							</td>
						</tr>
		
						<!-- Add New Venue --> 
						<tr valign="top" class="eo-add-new-venue">
							<td class="eo-label"><label><?php 
        _e('Venue Name', 'eventorganiser');
        ?>
:</label></td>
							<td><input type="text" name="eo_venue[name]" id="eo_venue_name"  value=""/></td>
						</tr>
						<?php 
        $address_fields = _eventorganiser_get_venue_address_fields();
        foreach ($address_fields as $key => $label) {
            printf('<tr valign="top" class="eo-add-new-venue">
									<td class="eo-label"><label>%1$s:</label></td>
									<td><input type="text" name="eo_venue[%2$s]" class="eo_addressInput" id="eo_venue_add"  value=""/></td>
								</tr>', $label, esc_attr(trim($key, '_')));
        }
        ?>
						<tr valign="top" class="eo-add-new-venue" >
							<td class="eo-label"></td>
							<td>
								<a class="button eo-add-new-venue-cancel" href="#"><?php 
        esc_html_e('Cancel', 'eventorganiser');
        ?>
 </a>
							</td>
						</tr>

						<!-- Venue Map --> 
						<tr valign="top"  class="venue_row <?php 
        if (!$venue_id) {
            echo 'novenue';
        }
        ?>
" >
							<td class="eo-label"></td>
							<td>
								<div id="eventorganiser_venue_meta" style="display:none;">
									<input type="hidden" id="eo_venue_Lat" name="eo_venue[latitude]" value="<?php 
        eo_venue_lat($venue_id);
        ?>
" />
									<input type="hidden" id="eo_venue_Lng" name="eo_venue[longtitude]" value="<?php 
        eo_venue_lng($venue_id);
        ?>
" />
								</div>
								<div id="venuemap" class="ui-widget-content ui-corner-all gmap3"></div>
								<div class="clear"></div>
							</td>
						</tr>
				<?php 
    }
    //endif venue's supported
    ?>
			</table>
		</div>
	<?php 
    // create a custom nonce for submit verification later
    wp_nonce_field('eventorganiser_event_update_' . get_the_ID() . '_' . get_current_blog_id(), '_eononce');
}
/**
* Sets up the event data metabox
* This allows user to enter date / time, reoccurrence and venue data for the event
*
* @since 1.0.0
*/
function eventorganiser_details_metabox($post)
{
    global $wp_locale;
    //Sets the format as php understands it, and textual.
    $eo_settings_array = get_option('eventorganiser_options');
    if ($eo_settings_array['dateformat'] == 'dd-mm') {
        $phpFormat = 'd-m-Y';
        $format = 'dd-mm-yyyy';
    } else {
        $phpFormat = 'm-d-Y';
        $format = 'mm-dd-yyyy';
    }
    //Get the starting day of the week
    $start_day = intval(get_option('start_of_week'));
    //Retrieve event details (if they exist)
    $event = new EO_Event(get_the_ID());
    //Start of meta box
    ?>
	
		<p>
			<?php 
    if ($event->is_reoccurring()) {
        ?>
				<strong><?php 
        _e('This is a reoccurring event', 'eventorganiser');
        ?>
</strong>. 
				<input type="checkbox" id="HWSEvent_rec" name="eo_input[AlterRe]" value="yes" /> 
				<?php 
        _e('Check to edit this event and its reoccurrences', 'eventorganiser');
        ?>
.
			<?php 
    }
    ?>
		</p>

		<div class="<?php 
    if ($event->is_reoccurring()) {
        echo 'reoccurence';
    } else {
        echo 'onetime';
    }
    ?>
">
			<p><?php 
    sprintf(__('Ensure dates are entered in %1$s format and times in %2$s (24 hour) format', 'eventorganiser'), '<strong>' . $format . '</strong>', ' <strong>hh:mm</strong>');
    ?>
 </p>
			<table>
			<tr class="event-date">
			<td><?php 
    echo __("Start Date/Time", 'eventorganiser') . ':';
    ?>
 </td>
			<td> 
			<input class="ui-widget-content ui-corner-all" name="eo_input[StartDate]" size="10" maxlength="10" id="from_date" <?php 
    disabled($event->is_reoccurring());
    ?>
 value="<?php 
    $event->the_start($phpFormat);
    ?>
"/>
			<input name="eo_input[StartTime]" class="eo_time ui-widget-content ui-corner-all" size="4" maxlength="5" id="HWSEvent_time" <?php 
    disabled($event->is_reoccurring() || $event->is_allday());
    ?>
 value="<?php 
    $event->the_start('H:i');
    ?>
"/>
			</td>
			</tr>
			<tr class="event-date">
			<td><?php 
    echo __("End Date/Time", 'eventorganiser') . ':';
    ?>
 </td>
			<td> 
			<input class="ui-widget-content ui-corner-all" name="eo_input[EndDate]" size="10" maxlength="10" id="to_date" <?php 
    disabled($event->is_reoccurring());
    ?>
  value="<?php 
    $event->the_end($phpFormat);
    ?>
"/>
			<input name="eo_input[FinishTime]" class="eo_time ui-widget-content ui-corner-all " size="4" maxlength="5" id="HWSEvent_time2" <?php 
    disabled($event->is_reoccurring() || $event->is_allday());
    ?>
 value="<?php 
    $event->the_end('H:i');
    ?>
""/>
			<label>
				<input type="checkbox" id="eo_allday"  <?php 
    checked($event->is_allday());
    ?>
 name="eo_input[allday]"<?php 
    disabled($event->is_reoccurring());
    ?>
 value="1"/>
				<?php 
    _e("All day", 'eventorganiser');
    ?>
			 </label>
			</td>
			</tr>

			<tr class="event-date">
			<td><?php 
    _e("Reoccurence:", 'eventorganiser');
    ?>
 </td>
			<td> 
			<?php 
    $reoccurrence_schedules = array('once' => __('once', 'eventorganiser'), 'daily' => __('daily', 'eventorganiser'), 'weekly' => __('weekly', 'eventorganiser'), 'monthly' => __('monthly', 'eventorganiser'), 'yearly' => __('yearly', 'eventorganiser'));
    ?>
			<select id="HWSEventInput_Req" name="eo_input[schedule]" <?php 
    disabled($event->is_reoccurring());
    ?>
>
					<?php 
    foreach ($reoccurrence_schedules as $index => $val) {
        ?>
						<option value="<?php 
        echo $index;
        ?>
" <?php 
        selected($event->is_schedule($index));
        ?>
><?php 
        echo $val;
        ?>
</option>
					<?php 
    }
    //End foreach $allowed_reoccurs
    ?>
			</select>
			</td>
			</tr>

			<tr class="event-date reocurrence_row">
			<td></td><td>
			<p>
				<?php 
    _e("Repeat every ", 'eventorganiser');
    ?>
				<input <?php 
    disabled($event->is_reoccurring());
    ?>
 class="ui-widget-content ui-corner-all" name="eo_input[event_frequency]" id="HWSEvent_freq" type="number" min="1" max="365" maxlength="4" size="4" disabled="disabled" value="<?php 
    echo $event->frequency;
    ?>
" /> 
				<span id="recpan" >  </span>				
			</p>

			<p id="dayofweekrepeat">
			<?php 
    _e("on", 'eventorganiser');
    ?>
	
                                <?php 
    $days_meta = is_array($event->meta) ? $event->meta : array();
    ?>
				<?php 
    for ($i = 0; $i <= 6; $i++) {
        $d = ($start_day + $i) % 7;
        $ical_days = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
        $ical_d = $ical_days[$d];
        $day = $wp_locale->weekday_abbrev[$wp_locale->weekday[$d]];
        ?>
					<input type="checkbox" id="day-<?php 
        echo $day;
        ?>
"  <?php 
        checked(in_array($ical_d, $days_meta), true);
        ?>
  value="<?php 
        echo esc_attr($ical_d);
        ?>
" class="daysofweek" name="eo_input[days][]" disabled="disabled" />
					<label for="day-<?php 
        echo $day;
        ?>
" > <?php 
        echo $day;
        ?>
</label>
				<?php 
    }
    ?>
			</p>

			<p id="dayofmonthrepeat">
				<input type="radio" id="bymonthday" disabled="disabled" name="eo_input[schedule_meta]" <?php 
    checked($event->occursBy(), 'BYMONTHDAY');
    ?>
 value="BYMONTHDAY=" /> 
				<label for="bymonthday" >	<?php 
    _e("day of month", 'eventorganiser');
    ?>
	</label>
				<input type="radio" id="byday" disabled="disabled" name="eo_input[schedule_meta]"  <?php 
    checked($event->occursBy() == 'BYMONTHDAY', false);
    ?>
 value="BYDAY=" /> 
				<label for="byday" >	<?php 
    _e("day of week", 'eventorganiser');
    ?>
</label>
			</p>

			<p class="reoccurrence_label">
			<?php 
    _e("until", 'eventorganiser');
    ?>
 
				<input <?php 
    disabled($event->is_reoccurring());
    ?>
 class="ui-widget-content ui-corner-all" name="eo_input[schedule_end]" id="recend" size="10" maxlength="10" disabled="disabled" value="<?php 
    $event->the_schedule_end($phpFormat);
    ?>
"/>
			</p>

			<p id="event_summary"> </p>

			</td>
			</tr>

			<tr>	
			<td class="label"> <?php 
    _e("Venue", 'eventorganiser');
    ?>
 : </td>
			<td> 
			<?php 
    $venues = get_terms('event-venue', array('hide_empty' => false));
    $current_id = (int) eo_get_venue(get_the_ID());
    ?>

			<!-- If javascript is disabed, a simple drop down menu box is displayed to choose venue.
			Otherwise, the user is able to search the venues by typing in the input box.-->		
				<select size="50" id="venue_select" name="eo_input[event-venue]">
					<option><?php 
    _e("Select a venue", 'eventorganiser');
    ?>
</option>
				<?php 
    foreach ($venues as $venue) {
        ?>
					<option <?php 
        selected($venue->term_id, $current_id);
        ?>
 value="<?php 
        echo $venue->term_id;
        ?>
"><?php 
        echo $venue->name;
        ?>
</option>
				<?php 
    }
    ?>
				</select>
			<span style="font-size:0.8em;line-height:0.8em;"> <?php 
    _e("Search for a venue. To add a venues go to the venue page.", 'eventorganiser');
    ?>
</span>
			</td>
			</tr>
			<tr class="venue_row <?php 
    if (!$current_id) {
        echo 'novenue';
    }
    ?>
" >
			<td></td>
			<td>

			<div id="eventorganiser_venue_meta" style="display:none;">
				<input type="hidden" id="eo_venue_Lat" value="<?php 
    eo_venue_lat($current_id);
    ?>
" />
				<input type="hidden" id="eo_venue_Lng" value="<?php 
    eo_venue_lng($current_id);
    ?>
" />
			</div>
			
			<div id="venuemap" class="ui-widget-content ui-corner-all gmap3"></div>
			<div class="clear"></div>
			</td>
			</tr>

			</table>
		</div>
	<?php 
    // create a custom nonce for submit verification later
    wp_nonce_field('eventorganiser_event_update_' . get_the_ID(), '_eononce');
}