-
-
Save tosin2013/3815956 to your computer and use it in GitHub Desktop.
Submit Event in Frontend of Blog via Template in Theme for Plugin: EVENTS MANAGER EXTENDED
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Template Name: Submit Event | |
Author: Frank Bueltge | |
Author URI: http://bueltge.de/ | |
*/ | |
function add_errormessage_style() { ?> | |
<style type="text/css"> | |
.errormessage { border: 3px solid red; padding: 5px; color: #000; } | |
.event_spam{ display:none; } | |
.eventbox h4 { border-bottom: 1px solid #bbb; margin: 30px 0 15px 0; }; | |
</style> | |
<?php | |
} | |
add_action( 'wp_head', 'add_errormessage_style' ); | |
function add_script2admin_footer() { ?> | |
<script type="text/javascript"> | |
jQuery(document).ready( function($){ | |
$("#event_start_date, #event_end_date").datepicker({ dateFormat: 'yy-mm-dd' }); | |
$('#event_start_time, #event_end_time').timepicker({ hourText: 'Stunde', minuteText: 'Minute', amPmText: ['', ''] }); | |
}); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'add_script2admin_footer', 20 ); | |
// datepicker for event-date and correct format, include styles | |
wp_enqueue_script( 'jquery-ui-datepicker', get_bloginfo('stylesheet_directory') . '/js/jquery-ui-1.8.11.custom.min.js', array('jquery-ui-core') , 0.1, TRUE ); | |
wp_enqueue_script( 'jquery-ui-datepicker-de', get_bloginfo('stylesheet_directory') . '/js/jquery.ui.datepicker-de.js', array('jquery-ui-datepicker') , 0.1, TRUE ); | |
wp_enqueue_style( 'jquery-ui-datepicker', get_bloginfo('stylesheet_directory') . '/css/overcast/jquery-ui-1.8.11.custom.css' ); | |
// timepicker for timestamp, includes styles | |
wp_enqueue_script( 'jquery-ui-timepicker', get_bloginfo('stylesheet_directory') . '/js/jquery.ui.timepicker.js', array('jquery-ui-core') , 0.1, TRUE ); | |
wp_enqueue_style( 'jquery-ui-timepicker', get_bloginfo('stylesheet_directory') . '/css/jquery-ui-timepicker.css' ); | |
$categories = eme_get_categories(); | |
if ( $categories ) { | |
$category_list = ''; | |
foreach ($categories as $this_category) { | |
$category_list .= '<input type="radio" value="' . $this_category['category_id'] . '" name="event_category_id"/> ' . $this_category['category_name'] . '<br />'; | |
} | |
} | |
if( 'POST' == $_SERVER['REQUEST_METHOD'] && ! empty( $_POST['action'] ) && wp_verify_nonce( $_POST['new-event'], 'action_new_event' ) ) { | |
$error = ''; | |
// all fields for event | |
if ( isset($_POST['event_name']) && '' != $_POST['event_name'] ) { | |
$event_name = esc_attr( $_POST['event_name'] ); | |
} else { | |
$error .= __('Bitte hinterlasse einen Eventnamen!') . '<br/>'; | |
} | |
if ( isset($_POST['event_start_date']) && '' != $_POST['event_start_date'] ) { | |
$event_start_date = esc_attr( $_POST['event_start_date'] ); | |
} else { | |
$error .= __('Bitte hinterlasse einen Event-Startzeit!') . '<br/>'; | |
} | |
if ( isset($_POST['event_start_time']) && '' != $_POST['event_start_time'] ) { | |
$event_start_time = esc_attr( $_POST['event_start_time'] ) . '00'; | |
} else { | |
$event_start_time = '00:00:00'; | |
} | |
if ( isset($_POST['event_end_date']) && '' != $_POST['event_end_date'] ) { | |
$event_end_date = esc_attr( $_POST['event_end_date'] ); | |
} else { | |
$event_end_date = $event_start_date; | |
} | |
if ( isset($_POST['event_end_time']) && '' != $_POST['event_end_time'] ) { | |
$event_end_time = esc_attr( $_POST['event_end_time'] ) . ':00'; | |
} else { | |
$event_end_time = $event_start_time; | |
} | |
if ( isset($_POST['description']) && '' != $_POST['description'] ) { | |
$description = esc_attr( $_POST['description'] ); | |
} else { | |
$error .= __('Bitte hinterlasse eine kurze Beschreibung') . '<br/>'; | |
} | |
if ( isset($_POST['event_category_id']) && '' != $_POST['event_category_id'] ) { | |
$event_category_id = (int) esc_attr( $_POST['event_category_id'] ); | |
} else { | |
$event_category_id = NULL; | |
} | |
if ( isset($_POST['event_contactperson_email_body']) && '' != $_POST['event_contactperson_email_body'] ) { | |
$event_contactperson_email_body = esc_attr( $_POST['event_contactperson_email_body'] ); | |
$description .= "\n" . __('E-Mail-Kontakt:') . ' ' . $event_contactperson_email_body; | |
} else { | |
$error .= __('Bitte hinterlasse eine E-Mail Adresse zum Nachfragen!') . '<br/>'; | |
} | |
if ( isset($_POST['event_url']) && '' != $_POST['event_url'] ) { | |
$event_url = esc_url( $_POST['event_url'] ); | |
} else { | |
$event_url = ''; | |
} | |
if ( isset($_POST['event_spam']) && '' != $_POST['event_spam'] ) { | |
$error .= __('Das Feld Spamschutz muss leer sein, keinen Eintrag!') . '<br/>'; | |
$event_spam = esc_attr($_POST['event_spam']); | |
} else { | |
$event_spam = ''; | |
} | |
// locations | |
// pflichtfelder | |
if ( isset($_POST['location_name']) && '' != $_POST['location_name'] ) { | |
$location_name = esc_attr( $_POST['location_name'] ); | |
} else { | |
$location_name = NULL; | |
} | |
if ( isset($_POST['location_address']) && '' != $_POST['location_address'] ) { | |
$location_address = esc_attr( $_POST['location_address'] ); | |
} else { | |
$location_address = NULL; | |
} | |
if ( isset($_POST['location_town']) && '' != $_POST['location_town'] ) { | |
$location_town = esc_attr( $_POST['location_town'] ); | |
} else { | |
$location_town = NULL; | |
} | |
// optionale Felder | |
if ( isset($_POST['location_description']) && '' != $_POST['location_description'] ) { | |
$location_description = esc_attr( $_POST['location_description'] ); | |
} else { | |
$location_description = NULL; | |
} | |
$location_latitude = NULL; | |
$location_longitude = NULL; | |
if ( isset($location_name) && isset($location_address) && isset($location_town) ) { | |
$location = array ( | |
'location_name' => $location_name, | |
'location_address' => $location_address, | |
'location_town' => $location_town, | |
'location_latitude' => $location_latitude, | |
'location_longitude' => $location_longitude, | |
'location_description' => $location_description | |
); | |
// get locations | |
$locations_table = $wpdb->prefix . LOCATIONS_TBNAME; | |
$location_town = $location['location_town']; | |
$location_address = $location['location_address']; | |
$sql = "SELECT * FROM $locations_table WHERE | |
location_town = '$location_town' AND | |
location_address = '$location_address'"; | |
$old_location = $wpdb->get_row($sql, ARRAY_A); | |
if ( $old_location['location_id'] ) { | |
$new_location = $old_location; | |
} else { | |
$new_location = eme_insert_location($location); | |
} | |
} else { | |
$new_location['location_id'] = NULL; | |
} | |
if ( isset($event_name) && isset($event_start_date) && isset($event_end_date) | |
&& isset($description) && isset($event_contactperson_email_body) | |
&& $event_spam === '' ) { | |
$event = array ( | |
"event_name" => $event_name, | |
"event_status" => 5, | |
"event_start_date" => $event_start_date, | |
"event_end_date" => $event_end_date, | |
"event_start_time" => $event_start_time, | |
"event_end_time" => $event_end_time, | |
"event_rsvp" => 0, | |
"rsvp_number_days" => 0, | |
"registration_requires_approval" => 0, | |
"registration_wp_users_only" => 0, | |
"event_seats" => 0, | |
"event_contactperson_id" => '-1', | |
"event_notes" => $description, | |
'event_page_title_format' => '', | |
'event_single_event_format' => '', | |
'event_contactperson_email_body' => '', | |
'event_respondent_email_body' => '', | |
'event_url' => $event_url, | |
'event_category_ids' => $event_category_id, | |
'event_attributes' => 'a:0:{}', | |
'location_id' => $new_location['location_id'] | |
); | |
eme_db_insert_event($event); | |
wp_redirect( esc_url( $_SERVER['HTTP_REFERER'] ) . '?evententry=true' ); // redirect to home page after submit | |
} | |
} // end IF | |
if ( isset($_GET['evententry']) && $_GET['evententry'] == 'true' ) | |
$error = __('Der Eintrag liegt zur Prüfung vor. Vielen Dank!'); | |
get_header();?> | |
<?php if (have_posts()) { while (have_posts()) : the_post(); ?> | |
<div class="post" id="post-<?php the_ID(); ?>"> | |
<h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2> | |
<?php the_content(); | |
if ( $error ) | |
echo '<p class="errormessage">' . $error . '</p>'; ?> | |
<div class="eventbox"> | |
<form id="new_post" name="new_post" method="post" action=""> | |
<h4>Eventdaten</h4> | |
<p> | |
<label for="title"><?php _e('· Eventname <small>*(Pflichtfeld)</small>'); ?></label><br /> | |
<input type="text" id="event_name" value="" size="50" name="event_name" /> | |
</p> | |
<p><?php _e('· Start <small>*(Pflichtfeld)</small>'); ?><br /> | |
 <label for="event_start_date">Datum</label> | |
<input type="text" id="event_start_date" value="" size="10" name="event_start_date" /> | |
   <label for="event_start_time">Zeit</label> | |
<input type="text" id="event_start_time" value="" size="10" name="event_start_time" /> | |
</p> | |
<p>· Ende<br /> | |
 <label for="event_end_date">Datum</label> | |
<input type="text" id="event_end_date" value="" size="10" name="event_end_date" /> | |
   <label for="event_end_time">Zeit</label> | |
<input type="text" id="event_end_time" value="" size="10" name="event_end_time" /> | |
</p> | |
<p><label for="description"><?php _e('· Beschreibung <small>*(Pflichtfeld)</small>'); ?></label><br /> | |
<textarea id="description" name="description" cols="50" rows="6"></textarea> | |
</p> | |
<?php if ( $category_list ) echo '<p>' . $category_list . '</p>'; ?> | |
<p> | |
<label for="event_contactperson_email_body"><?php _e('· E-Mail Kontakt <small>*(Pflichtfeld)</small>'); ?></label><br /> | |
<input type="text" id="event_contactperson_email_body" value="" size="50" name="event_contactperson_email_body" /> | |
</p> | |
<p> | |
<label for="event_url"><?php _e('· Website, weitere Informationen zum Event'); ?></label><br /> | |
<input type="text" id="event_url" value="" size="50" name="event_url" /> | |
</p> | |
<h4>Veranstaltungsort</h4> | |
<p><?php _e('Sie können gern den Veranstaltungsort mit angeben, die Daten sind optional.<br />Für die korrekte Zuordung sind diverse Felder Pflicht.'); ?></p> | |
<p> | |
<label for="location_name"><?php _e('· Veranstaltungsort-Name <small>*(Pflichtfeld)</small>'); ?></label><br /> | |
<input type="text" id="location_name" value="" size="50" name="location_name" /> | |
</p> | |
<p> | |
<label for="location_town"><?php _e('· Veranstaltungsort-Stadt <small>*(Pflichtfeld)</small>'); ?></label><br /> | |
<input type="text" id="location_town" value="" size="50" name="location_town" /> | |
</p> | |
<p> | |
<label for="location_address"><?php _e('· Veranstaltungsort-Adresse <small>*(Pflichtfeld)</small>'); ?></label><br /> | |
<input type="text" id="location_address" value="" size="50" name="location_address" /> | |
</p> | |
<p> | |
<label for="location_description"><?php _e('· Beschreibung'); ?></label><br /> | |
<textarea id="location_description" name="location_description" cols="50" rows="6"></textarea> | |
</p> | |
<p class="event_spam"><?php _e('Spamschutz:'); ?> <input type="text" id="event_spam" value="" size="50" name="event_spam" /></p> | |
<p> | |
<input type="submit" value="<?php _e('Event einsenden'); ?>" id="submit" name="submit" /> | |
</p> | |
<input type="hidden" name="action" value="post" /> | |
<?php wp_nonce_field( 'action_new_event', 'new-event' ); ?> | |
</form> | |
</div> | |
<?php wp_link_pages(); ?> | |
<p class="info"><?php the_time('j.') ?><a href="<?php echo get_settings('home'); ?>/date/<?php the_time('Y') ?>/<?php the_time('m') ?>/" title="Alle Beiträge in <?php the_time('F Y'); ?> ansehen" > <?php the_time('F Y'); ?></a> · Author: <?php the_author_posts_link(); ?><br /><?php the_category(', '); the_tags(' · ', ', ', ''); edit_post_link('Editieren',' · ', ''); ?></p> | |
</div> | |
<?php endwhile; | |
} else { ?> | |
<p><?php _e('Nichts gefunden, was den Suchkriterien entspricht.'); ?></p> | |
<?php } ?> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment