<?php
/** 
 * Template to output a contact form
 *
 * @since BlogCentral 1.0.0
 *
 * @param global variable $blogcentral_layout_opts, passed to this template by the bcswp contact form shortcode.
 *
 * @package BlogCentral
 * @subpackage contact-form.php
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
	exit; 
}

// Global variable that holds the theme options.
global $blogcentral_opts;

$extra_class = '';

if ( isset( $blogcentral_layout_opts['contact_form'] ) && $blogcentral_layout_opts['contact_form'] &&
	isset( $blogcentral_layout_opts['show_contact'] ) && $blogcentral_layout_opts['show_contact'] ) {
	$extra_class = ' contact-form-cols-2';
}

echo '<div class="blogcentral-contact-form-cont' . $extra_class . '">';

$key = isset( $blogcentral_opts['google_app_id'] ) ? $blogcentral_opts['google_app_id'] : null;

if ( $key && isset( $blogcentral_layout_opts['show_map'] ) && $blogcentral_layout_opts['show_map'] &&
	isset( $blogcentral_opts['contact_info']['contact_address'] ) ) {
	$address = str_replace( ' ', '+', $blogcentral_opts['contact_info']['contact_address'] );
?>
<div class="map"><iframe style="border:0" height="450" src="<?php echo esc_url('https://www.google.com/maps/embed/v1/search?key=' . $key . '&q=' . $address ); ?>">
</iframe></div>
<?php
}

if ( isset( $blogcentral_layout_opts['show_contact'] ) && $blogcentral_layout_opts['show_contact'] ) :
?>	
	<div class="contact-info-main">
		<?php 
			// Call the shortcode to construct and display the contact information.
			global $bcswp_plugin;
			
			// Don't show the contact form's title and tagline text again.
			$blogcentral_layout_opts['title_text'] = '';
			$blogcentral_layout_opts['tagline_text'] = '';
			
			echo $bcswp_plugin->blogcentral_shortcodes->contact_info( $blogcentral_layout_opts );
		?>
	</div>
<?php 
endif;

// Now call the shortcode to display the contact form.
if ( isset( $blogcentral_layout_opts['contact_form'] ) && $blogcentral_layout_opts['contact_form'] ) {
	echo '<div class="contact-info-form">';
	echo do_shortcode( stripslashes( $blogcentral_layout_opts['contact_form'] ) );
	echo '</div>';
}

echo '</div>';
?>