mage-eventpress/inc/mep_event_meta.php

474 lines
15 KiB
PHP

<?php
if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access pages directly.
add_action( 'add_meta_boxes', 'mep_event_meta_box_add' );
function mep_event_meta_box_add(){
add_meta_box( 'mep-event-meta', 'Event Venue', 'mep_event_venue_meta_box_cb', 'mep_events', 'normal', 'high' );
add_meta_box( 'mep-event-price', 'Event Price', 'mep_event_price_meta_box_cb', 'mep_events', 'normal', 'high' );
add_meta_box( 'mep-event-extra-price', 'Event Extra Option Price', 'mep_event_extra_price_option', 'mep_events', 'normal', 'high' );
add_meta_box( 'mep-event-date', 'Event Date & Time', 'mep_event_date_meta_box_cb', 'mep_events', 'normal', 'high' );
}
function mep_event_venue_meta_box_cb($post){
$values = get_post_custom( $post->ID );
$user_api = mep_get_option( 'google-map-api', 'general_setting_sec', '');
?>
<div class='sec'>
<label for="mep_ev_1"> Seat Capacity: </label>
<span><input id='mep_ev_1' type="number" name='mep_total_seat' value='<?php echo $values['mep_total_seat'][0]; ?>'> </span>
</div>
<div class='sec'>
<label for="mep_ev_2"> Location/Venue: </label>
<span><input id='mep_ev_2' type="text" name='mep_location_venue' value='<?php echo $values['mep_location_venue'][0]; ?>'> </span>
</div>
<div class='sec'>
<label for="mep_ev_3"> Street: </label>
<span><input id='mep_ev_3' type="text" name='mep_street' value='<?php echo $values['mep_street'][0]; ?>'> </span>
</div>
<div class='sec'>
<label for="mep_ev_4"> City: </label>
<span><input id='mep_ev_4' type="text" name='mep_city' value='<?php echo $values['mep_city'][0]; ?>'> </span>
</div>
<div class='sec'>
<label for="mep_ev_5"> State: </label>
<span><input id='mep_ev_5' type="text" name='mep_state' value='<?php echo $values['mep_state'][0]; ?>'> </span>
</div>
<div class='sec'>
<label for="mep_ev_6"> Postcode: </label>
<span><input id='mep_ev_6' type="text" name='mep_postcode' value='<?php echo $values['mep_postcode'][0]; ?>'> </span>
</div>
<div class='sec'>
<label for="mep_ev_7"> Country: </label>
<span><input id='mep_ev_7' type="text" name='mep_country' value='<?php echo $values['mep_country'][0]; ?>'> </span>
</div>
<?php
if($user_api){
?>
<div class='sec'>
<label for="mep_ev_989"> Show Google Map: </label>
<span><input style='text-align: left;width: auto;' id='mep_ev_989' type="checkbox" name='mep_sgm' value='1' <?php $mep_sgm = $values['mep_sgm'][0]; if($mep_sgm==1){ echo 'checked'; } ?> > Yes</span>
</div>
<div class='sec'>
<input id="pac-input" name='location_name' value='<?php //echo $values['location_name'][0]; ?>'/>
</div>
<input type="hidden" class="form-control" required name="latitude" value="<?php echo $values['latitude'][0]; ?>">
<input type="hidden" class="form-control" required name="longitude" value="<?php echo $values['longitude'][0]; ?>">
<div id="map"></div>
<?php
}else{
echo "<span class=mep_status><span class=err>No Google MAP API Key Found. Please enter API KEY <a href=".get_site_url()."/wp-admin/options-general.php?page=mep_event_settings_page>Here</a></span></span>";
}
if($values['latitude'][0]){
$lat = $values['latitude'][0];
}else{ $lat = '37.0902'; }
if($values['longitude'][0]){
$lon = $values['longitude'][0];
}else{ $lon = '95.7129'; }
?>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: <?php echo $lat; ?>,
lng: <?php echo $lon; ?>
},
zoom: 17
});
var input = /** @type {!HTMLInputElement} */ (
document.getElementById('pac-input'));
var types = document.getElementById('type-selector');
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(types);
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map,
anchorPoint: new google.maps.Point(0, -29),
draggable: true,
position: {lat: <?php echo $lat; ?>, lng: <?php echo $lon; ?>}
});
google.maps.event.addListener(marker, 'dragend', function() {
document.getElementsByName('latitude')[0].value = marker.getPosition().lat();
document.getElementsByName('longitude')[0].value = marker.getPosition().lng();
})
autocomplete.addListener('place_changed', function() {
infowindow.close();
marker.setVisible(false);
var place = autocomplete.getPlace();
if (!place.geometry) {
window.alert("Autocomplete's returned place contains no geometry");
return;
}
// If the place has a geometry, then present it on a map.
if (place.geometry.viewport) {
map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17); // Why 17? Because it looks good.
}
marker.setIcon( /** @type {google.maps.Icon} */ ({
url: 'http://maps.google.com/mapfiles/ms/icons/red.png',
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(35, 35)
}));
marker.setPosition(place.geometry.location);
marker.setVisible(true);
var address = '';
if (place.address_components) {
address = [
(place.address_components[0] && place.address_components[0].short_name || ''),
(place.address_components[1] && place.address_components[1].short_name || ''),
(place.address_components[2] && place.address_components[2].short_name || '')
].join(' ');
}
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
$("input[name=coordinate]").val(address);
$("input[name=latitude]").val(latitude);
$("input[name=longitude]").val(longitude);
//infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
//infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, "load", initMap);
</script>
<?php
}
function mep_event_price_meta_box_cb($post){
$values = get_post_custom( $post->ID );
?>
<div class='sec'>
<label for="mep_ev_98"> Show Quantity Input Box: </label>
<span><input style='text-align: left;width: auto;' id='mep_ev_98' type="checkbox" name='mep_sqi' value='1' <?php $sqi = $values['mep_sqi'][0]; if($sqi==1){ echo 'checked'; } ?> > Yes</span>
</div>
<div class='sec'>
<label for="mep_ev_8"> Price Label: </label>
<span><input id='mep_ev_8' type="text" name='mep_price_label' value='<?php echo $values['mep_price_label'][0]; ?>'> </span>
</div>
<div class='sec'>
<label for="mep_ev_9"> Price: </label>
<span><input id='mep_ev_9' type="number" name='_price' value='<?php echo $values['_price'][0]; ?>'> </span>
</div>
<?php
}
function mep_event_extra_price_option() {
global $post;
$mep_events_extra_prices = get_post_meta($post->ID, 'mep_events_extra_prices', true);
wp_nonce_field( 'mep_events_extra_price_nonce', 'mep_events_extra_price_nonce' );
?>
<script type="text/javascript">
jQuery(document).ready(function( $ ){
$( '#add-row' ).on('click', function() {
var row = $( '.empty-row.screen-reader-text' ).clone(true);
row.removeClass( 'empty-row screen-reader-text' );
row.insertBefore( '#repeatable-fieldset-one tbody>tr:last' );
return false;
});
$( '.remove-row' ).on('click', function() {
$(this).parents('tr').remove();
return false;
});
});
</script>
<table id="repeatable-fieldset-one" width="100%">
<thead>
<tr>
<th width="40%">Extra Option Name</th>
<th width="40%">Amount</th>
<th width="8%"></th>
</tr>
</thead>
<tbody>
<?php
if ( $mep_events_extra_prices ) :
foreach ( $mep_events_extra_prices as $field ) {
?>
<tr>
<td><input type="text" class="widefat" name="option_name[]" value="<?php if($field['option_name'] != '') echo esc_attr( $field['option_name'] ); ?>" /></td>
<td><input type="number" class="widefat" name="option_price[]" value="<?php if ($field['option_price'] != '') echo esc_attr( $field['option_price'] ); else echo ''; ?>" /></td>
<td><a class="button remove-row" href="#">Remove</a></td>
</tr>
<?php
}
else :
// show a blank one
endif;
?>
<!-- empty hidden one for jQuery -->
<tr class="empty-row screen-reader-text">
<td><input type="text" class="widefat" name="option_name[]" /></td>
<td><input type="number" class="widefat" name="option_price[]" value="" /></td>
<td><a class="button remove-row" href="#">Remove</a></td>
</tr>
</tbody>
</table>
<p><a id="add-row" class="button" href="#">Add Extra Price</a></p>
<?php
}
function mep_event_date_meta_box_cb($post){
$values = get_post_custom( $post->ID );
?>
<div class='sec'>
<label for="event_start_date"> Start Date & Time: </label>
<span><input class='event_start' id='event_start_date' type="text" name='mep_event_start_date' value='<?php echo $values['mep_event_start_date'][0]; ?>'> </span>
</div>
<div class='sec'>
<label for="event_end_date"> End Date & Time: </label>
<span><input class='event_end' id='event_end_date' type="text" name='mep_event_end_date' value='<?php echo $values['mep_event_end_date'][0]; ?>'> </span>
</div>
<?php
}
add_action('save_post', 'mep_events_repeatable_meta_box_save');
function mep_events_repeatable_meta_box_save($post_id) {
if ( ! isset( $_POST['mep_events_extra_price_nonce'] ) ||
! wp_verify_nonce( $_POST['mep_events_extra_price_nonce'], 'mep_events_extra_price_nonce' ) )
return;
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if (!current_user_can('edit_post', $post_id))
return;
$old = get_post_meta($post_id, 'mep_events_extra_prices', true);
$new = array();
// $options = hhs_get_sample_options();
$names = $_POST['option_name'];
// $selects = $_POST['select'];
$urls = $_POST['option_price'];
$count = count( $names );
for ( $i = 0; $i < $count; $i++ ) {
if ( $names[$i] != '' ) :
$new[$i]['option_name'] = stripslashes( strip_tags( $names[$i] ) );
endif;
if ( $urls[$i] != '' ) :
$new[$i]['option_price'] = stripslashes( strip_tags( $urls[$i] ) );
endif;
}
if ( !empty( $new ) && $new != $old )
update_post_meta( $post_id, 'mep_events_extra_prices', $new );
elseif ( empty($new) && $old )
delete_post_meta( $post_id, 'mep_events_extra_prices', $old );
}
add_action('save_post','mep_events_meta_save');
function mep_events_meta_save($post_id){
global $post;
$pid = $post->ID;
if ($post->post_type != 'mep_events'){
return;
}
//if you get here then it's your post type so do your thing....
$seat = strip_tags($_POST['mep_total_seat']);
$mep_location_venue = strip_tags($_POST['mep_location_venue']);
$mep_street = strip_tags($_POST['mep_street']);
$mep_city = strip_tags($_POST['mep_city']);
$mep_state = strip_tags($_POST['mep_state']);
$mep_postcode = strip_tags($_POST['mep_postcode']);
$mep_country = strip_tags($_POST['mep_country']);
$mep_price_label = strip_tags($_POST['mep_price_label']);
$mep_sqi = strip_tags($_POST['mep_sqi']);
$mep_sgm = strip_tags($_POST['mep_sgm']);
$_price = strip_tags($_POST['_price']);
$mep_event_start_date = strip_tags($_POST['mep_event_start_date']);
$mep_event_end_date = strip_tags($_POST['mep_event_end_date']);
$latitude = strip_tags($_POST['latitude']);
$longitude = strip_tags($_POST['longitude']);
$location_name = strip_tags($_POST['location_name']);
$update_seat = update_post_meta( $pid, 'mep_total_seat', $seat);
$update_seat_stock_status = update_post_meta( $pid, '_manage_stock', 'yes');
$update_seat_stock = update_post_meta( $pid, '_stock', $seat);
$sts_msg = update_post_meta( $pid, '_stock_msg', 'new');
// $ttl_booking = update_post_meta( $pid, 'total_booking', '0');
$longitude = update_post_meta( $pid, 'longitude', $longitude);
$latitude = update_post_meta( $pid, 'latitude', $latitude);
$location_name = update_post_meta( $pid, 'location_name', $location_name);
$update_location = update_post_meta( $pid, 'mep_location_venue', $mep_location_venue);
$update_mep_street = update_post_meta( $pid, 'mep_street', $mep_street);
$update_city = update_post_meta( $pid, 'mep_city', $mep_city);
$update_mep_state = update_post_meta( $pid, 'mep_state', $mep_state);
$update_postcode = update_post_meta( $pid, 'mep_postcode', $mep_postcode);
$update_conuntry = update_post_meta( $pid, 'mep_country', $mep_country);
$update_sqi = update_post_meta( $pid, 'mep_sqi', $mep_sqi);
$update_mep_sgm = update_post_meta( $pid, 'mep_sgm', $mep_sgm);
$update_price_label = update_post_meta( $pid, 'mep_price_label', $mep_price_label);
$update_price = update_post_meta( $pid, '_price', $_price);
$update_start = update_post_meta( $pid, 'mep_event_start_date', $mep_event_start_date);
$update_end = update_post_meta( $pid, 'mep_event_end_date', $mep_event_end_date);
}
add_action( 'add_meta_boxes', 'mep_meta_box_add' );
function mep_meta_box_add(){
add_meta_box( 'my-meta-box-id', 'Information', 'mep_meta_box_cb', 'mep_events_attendees', 'normal', 'high' );
}
function mep_meta_box_cb($post){
$values = get_post_custom( $post->ID );
?>
<div class='sec'>
<label for="my_meta_box_text"> Event: </label>
<span><?php echo $values['ea_event_name'][0]; ?> </span>
</div>
<div class='sec'>
<label for="my_meta_box_text"> Full Name: </label>
<span><?php echo $values['ea_first_name'][0]; ?> <?php echo $values['ea_last_name'][0]; ?></span>
</div>
<div class='sec'>
<label for="my_meta_box_text">Company: </label>
<span><?php echo $values['ea_company_name'][0]; ?></span>
</div>
<div class='sec'>
<label for="my_meta_box_text">Email: </label>
<span><?php echo $values['ea_email'][0]; ?></span>
</div>
<div class='sec'>
<label for="my_meta_box_text">Phone: </label>
<span><?php echo $values['ea_phone'][0]; ?></span>
</div>
<div class='sec'>
<label for="my_meta_box_text">Addres: </label>
<span>
<?php echo $values['ea_address_1'][0]; ?>
<?php echo $values['ea_address_2'][0]; ?>
</span>
</div>
<div class='sec'>
<label for="my_meta_box_text">State: </label>
<span>
<?php echo $values['ea_state'][0]; ?>
</span>
</div>
<div class='sec'>
<label for="my_meta_box_text">City: </label>
<span>
<?php echo $values['ea_city'][0]; ?>
</span>
</div>
<div class='sec'>
<label for="my_meta_box_text">Country: </label>
<span>
<?php echo $values['ea_country'][0]; ?>
</span>
</div>
<div class='sec'>
<label for="my_meta_box_text">Order ID: </label>
<span>
<?php echo $values['ea_order_id'][0]; ?>
</span>
</div>
<div class='sec'>
<span>
<a href="<?php echo get_site_url(); ?>/wp-admin/post.php?post=<?php echo $values['ea_order_id'][0]; ?>&action=edit" class='button button-primary button-large'>View Order</a>
</span>
</div>
<?php
}