Exemplo n.º 1
0
function makerfaire_meta_box($post)
{
    // Let's use these as defaults
    $defaults = array('mfei_day' => 'Saturday', 'mfei_start' => '8:00 AM', 'mfei_stop' => '8:30 AM', 'mfei_record' => '', 'mfei_coverage' => '');
    // Get the post meta
    $post_meta = get_post_custom($post->ID);
    // Merge with defaults.
    $meta = shortcode_atts($defaults, $post_meta);
    $app_id = isset($meta['mfei_record'][0]) && !empty($meta['mfei_record'][0]) ? $meta['mfei_record'][0] : '';
    $event_scheduled = get_post_meta(absint($app_id), '_ef_editorial_meta_checkbox_schedule-completed', true);
    $schedules_emailed = get_post_meta(absint($app_id), 'app-emails-sent', true);
    ?>

	<style>#ei-details label{font-weight:bold; display:block; margin:15px 0 5px 0;} #ei-details select,#ei-details input[type=text]{width:200px}</style>
	<?php 
    wp_nonce_field('mfei_nonce', 'mfei_submit_nonce');
    ?>
	<label>Day</label>
	<select name="mfei_day">
		<option value="Saturday" <?php 
    selected($meta['mfei_day'][0], 'Saturday');
    ?>
>Saturday</option>
		<option value="Sunday" <?php 
    selected($meta['mfei_day'][0], 'Sunday');
    ?>
>Sunday</option>
	</select>
	<label>Start Time</label>
	<select name="mfei_start">
		<?php 
    makerfaire_create_time($meta['mfei_start'][0]);
    ?>
	</select>
	<label>Stop Time</label>
	<select name="mfei_stop">
		<?php 
    makerfaire_create_time($meta['mfei_stop'][0]);
    ?>
	</select>
	<label>Coverage Video Link</label>
	<input type="text" name="mfei_coverage" id="mfei_coverage" value="<?php 
    echo !empty($meta['mfei_coverage'][0]) ? esc_url($meta['mfei_coverage'][0]) : '';
    ?>
" />
	<label>Record Number - MUST BE VALID APPLICATION ID</label>
	<?php 
    // Check if we are loading from a referring post and add that ID to our Record field
    if (isset($_GET['refer_id']) && !empty($_GET['refer_id'])) {
        echo '<input type="text" name="mfei_record" id="mfei_record" value="' . absint($_GET['refer_id']) . '" />';
    } else {
        $id = !empty($meta['mfei_record'][0]) ? absint($meta['mfei_record'][0]) : '';
        echo '<input type="text" name="mfei_record" id="mfei_record" value="' . $id . '" />';
    }
    ?>
	<a title="Edit event items" href="#" id="view-application" class="post-edit-link">View Application</a> (opens new window with given application)
	<label>Schedule Completed</label>
	<input name="mfei_schedule_completed" type="checkbox" value="<?php 
    echo $event_scheduled === '1' ? '1' : '0';
    ?>
" <?php 
    echo checked($event_scheduled, '1');
    ?>
 /> &nbsp; Event is Scheduled
	<p><a href="#" id="mf-email-schedule-button" class="button">Email Presenter Schedule</a></p>
	<?php 
    wp_nonce_field('email-presenter-schedulees', 'mf-email-schedule');
    ?>
	<input type="hidden" name="meta-data" id="schedule-id" value="<?php 
    echo absint($post->ID);
    ?>
">
	<?php 
    if ($schedules_emailed) {
        ?>
		<div id="email-status" style="color:#468847;background-color:#dff0d8;border:1px solid #d6e9c6;padding:8px 35px 8px 14px;text-shadow:0 1px 0 rgba(255,255,255,.5);border-radius:4px;width:25%;margin-top:10px;">Emails have already been sent!</div>
	<?php 
    }
    ?>
	<script>
		jQuery( document ).ready( function( $ ) {
			// Listen for a call to set the MFEI Record
			$( '#view-application' ).click( function() {
				window.open('/makerfaire/wp-admin/post.php?post=' + jQuery( '#mfei_record' ).val() + '&action=edit', '_blank');
			});

			// Handle the request to email the schedule to the presenters over ajax
			$( '#mf-email-schedule-button' ).click( function( e ) {
				e.preventDefault();

				$.ajax({
					type: 'POST',
					dataType: 'json',
					url: ajaxurl,
					data: {
						'action' : 'mf_email_schedule',
						'nonce'  : $( '#mf-email-schedule' ).val(),
						'meta'   : $( '#schedule-id' ).val(),
					},
					success: function( results ) {
						if ( results.messages_sent ) {
							$( '#email-status' ).remove();
							$( '#mf-email-schedule-button' ).parent().replaceWith( '<div id="email-status" style="color:#468847;background-color:#dff0d8;border:1px solid #d6e9c6;padding:8px 35px 8px 14px;text-shadow:0 1px 0 rgba(255,255,255,.5);border-radius:4px;width:25%;margin-top:10px;">Emails were successfully sent!</div>' );
						} else {
							$( '#email-status' ).remove();
							$( '#mf-email-schedule-button' ).parent().after( '<div id="email-status" style="color:#b94a48;background-color:#f2dede;border:1px solid #eed3d7;padding:8px 35px 8px 14px;text-shadow:0 1px 0 rgba(255,255,255,.5);border-radius:4px;width:50%;margin-top:10px;">Email failed for ' + results.failed_email + '</div>' );
						}
					},
					error: function( jqHXR, textStatus, errorThrown ) {
						console.log( 'ERROR' );
						console.log( textStatus );
						console.log( errorThrown );
					}
				});
			});
		});
	</script>
<?php 
}
function makerfaire_meta_box($post)
{
    $meta = array('mfei_day' => __('Saturday', 'make-mini-mf'), 'mfei_start' => '8:00 AM', 'mfei_stop' => '8:30 AM', 'mfei_record' => '', 'mfei_coverage' => '');
    if ($post->post_status == 'publish') {
        $meta = get_post_custom($post->ID);
    }
    ?>

		<style>#ei-details label{font-weight:bold; display:block; margin:15px 0 5px 0;} #ei-details select,#ei-details input[type=text]{width:200px}</style>
		<?php 
    wp_nonce_field('mfei_nonce', 'mfei_submit_nonce');
    ?>
		<label><?php 
    _e('Day', 'make-mini-mf');
    ?>
</label>
		<select name="mfei_day">
			<option value="Saturday" <?php 
    selected($meta['mfei_day'][0], 'Saturday');
    ?>
><?php 
    _e('Saturday', 'make-mini-mf');
    ?>
</option>
			<option value="Sunday" <?php 
    selected($meta['mfei_day'][0], 'Sunday');
    ?>
><?php 
    _e('Sunday', 'make-mini-mf');
    ?>
</option>
		</select>
		<label><?php 
    _e('Start Time', 'make-mini-mf');
    ?>
</label>
		<select name="mfei_start">
			<?php 
    makerfaire_create_time($meta['mfei_start'][0]);
    ?>
		</select>
		<label><?php 
    _e('Stop Time', 'make-mini-mf');
    ?>
</label>
		<select name="mfei_stop">
			<?php 
    makerfaire_create_time($meta['mfei_stop'][0]);
    ?>
		</select>
		<label><?php 
    _e('Coverage Video Link', 'make-mini-mf');
    ?>
</label>
		<input type="text" name="mfei_coverage" id="mfei_coverage" value="<?php 
    echo !empty($meta['mfei_coverage'][0]) ? esc_url($meta['mfei_coverage'][0]) : '';
    ?>
" />
		<label><?php 
    _e('Record Number - MUST BE VALID APPLICATION ID', 'make-mini-mf');
    ?>
</label>
		<?php 
    // Check if we are loading from a referring post and add that ID to our Record field
    if (isset($_GET['refer_id']) && !empty($_GET['refer_id'])) {
        echo '<input type="text" name="mfei_record" id="mfei_record" value="' . intval($_GET['refer_id']) . '" />';
    } else {
        $id = !empty($meta['mfei_record'][0]) ? esc_attr($meta['mfei_record'][0]) : '';
        echo '<input type="text" name="mfei_record" id="mfei_record" value="' . $id . '" />';
    }
    ?>
		<a title="Edit event items" href="#" class="post-edit-link"><?php 
    _e('View Application', 'make-mini-mf');
    ?>
</a> <?php 
    _e('(opens new window with given application)', 'make-mini-mf');
    ?>
		<label><?php 
    _e('Schedule Completed', 'make-mini-mf');
    ?>
</label>
		<input name="mfei_schedule_completed" type="checkbox" value="1" /> &nbsp; <?php 
    _e('Event is Scheduled', 'make-mini-mf');
    ?>
		<script>		
			jQuery( '#ei-details a' ).click( function() {
				window.open('/wp-admin/post.php?post=' + jQuery( '#mfei_record' ).val() + '&action=edit', '_blank');
			});
		</script>
		<?php 
    mf_schedule_mailto($meta);
    ?>
	<?php 
}