<?php
/*

Template Name: Contact

*/
?>


<?php 
		
	if(isset($_REQUEST["um_name"]) && isset($_REQUEST["um_email"]) && isset($_REQUEST["um_message"])){
		$name = $_REQUEST["um_name"];
		$email = $_REQUEST["um_email"];
		$message = $_REQUEST["um_message"];
		$to_email = get_field("email_receiver"); 
		if(!$to_email){
			$to_email = get_option('admin_email');
		}
		$subject = "[".get_bloginfo('name')."] - ".$email;
		
			$message = "
				Name : {$name},
				Email : {$email}

				$message
			";
	  
		if(wp_mail($to_email,$subject,$message))
		{
			echo  get_field('success_message');
		}
		else{
			echo get_field('fail_message');
		}

		die;
	}

?>

<?php get_header(); ?>

<?php wp_reset_postdata(); ?>
<main class="content contactPage headerImg">
	
	<?php
    	$latLng = get_field('google_map');
    	$zoomLevel = get_field('zoom_level');
		$marker = get_field('custom_marker');
		$zoomIn = get_field('disable_zoom_in');
		
		if(!$zoomIn){
			$zoomIn = 'true';
		}else{
			$zoomIn = 'false';
		}
		$markerImage = '';
		if($marker){
			$markerImage = wp_get_attachment_image_src( $marker, 'mapMarker');
			$markerImage = $markerImage[0]; 
		}
	?>
	
	<?php if($latLng != ""): ?> 
    <script>
        jQuery(document).ready(function ($) {

            var myCenter = new google.maps.LatLng(<?php echo $latLng['coordinates']; ?>);
			var customMarker = "<?php echo $markerImage; ?>";
			
            function initialize()
            {
                var mapProp = {
                    center:myCenter,
                    zoom: <?php echo $zoomLevel; ?>,
					scrollwheel: <?php echo $zoomIn;?>,
                    mapTypeId:google.maps.MapTypeId.ROADMAP,
                    disableDefaultUI: true, 
                    
                };
                
				if($('#googleMap').length == 1){
					
					var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);
					
					
			
					
					
					if(customMarker != ''){
						var marker = new google.maps.Marker({
							position:myCenter,
							icon: customMarker
						});
					}
					else{
						   marker = new google.maps.Marker({
                                position:myCenter
                            });
					}
					marker.setMap(map);
				}
            }
            initialize();
        });

    </script>
<?php endif; ?>
	
	<?php if(!get_field('disable_map')):?>
    <div class="breadcrumb_box_cont"> <div class="container"><?php
echo do_shortcode( '[breadcrumb]' ); 
?></div></div>
		<section class="pageImage">
			<div id="googleMap"></div>
            
        </section>
	<?php endif; ?>	
       
               <section class="contactFormWrapper">
       			
       			 <div class="container">
       
       				<div class=" hasDec"> 
      
                	<div class="row">
                		
                	 <?php if(get_field('contact_form') == "umC"): ?>
                	 	
                	 		
                		<div class="col-md-8 col-sm-8 col-xs-12">
		                	<h4 class="title titleUp contact_head"><?php the_title(); ?></h4>
							<div class="formDescription">
								<?php the_content(); ?>
							</div>
		                <div class="conatcttitle2">
<h4>DROP YOUR MESSAGE</h4>
&nbsp;
<form action="" method="post" class="contactForm">
		                		<div class="row">
		                			<div class="col-md-6 col-sm-6 col-xs-12">
										<div class="formInput">
											<label for="name"><?php the_field('name_label'); ?></label>
											<i class="fa fa-user"></i>
											<input id='full_name' name='full_name'  type="text" >
										</div>
									</div>
									
									<div class="col-md-6 col-sm-6 col-xs-12">
										<div class="formInput">
											<label for="email"><?php the_field('email_label'); ?></label>
											<i class="fa fa-user"></i>
											<input id='email' name='email' type="email">
										</div>
									</div>
									
									<div class="col-md-12 col-xs-12">
										<div class="formInput textArea">
											<label for="special"><?php the_field('message_label'); ?></label>
											<i class="fa fa-user"></i>
											<textarea  id="comment" class="hasScrollbar" name='comment' ></textarea>
										</div>
									</div>
									
									<div class="col-md-12 col-xs-12">
										<div class="formInput">
											<button type="submit" class="btn submitBtn brandBgColor"><?php the_field('send_button_label'); ?></button>
										</div>
									</div>						
		                		</div>
		                	</form>
                            <div class="um_message text-center">
								<h1></h1>
							</div>
</div>	
		                	
							  	
	                	</div><!-- col-md -->
	                	<?php else: ?>
	                		
			                	<div class="col-md-8 col-sm-8 col-xs-12">
				                	<h4 class="title titleUp contact_head"><?php the_title(); ?></h4>
									<div class="formDescription">
										<?php the_content(); ?>
									
				                		<?php  echo do_shortcode(get_field('contact_form_7_shortcode')); ?>	
				              	  </div>
				                </div>
		                	
	                	<?php endif; ?>
	                	
	                	
	                	<div class="col-md-4 col-sm-4 col-xs-12">
	                		<?php if(get_field('title')): ?>
	                			<h4 class="title titleUp contact_head"><?php the_field('title'); ?></h4>
                			<?php endif; ?>
							<?php if(get_field('content')): ?>
								<div class="formDescription">
									<?php the_field('content'); ?>
								</div>
							<?php endif; ?>
							
							<?php $attributes = get_field('attributes'); ?>
							<?php if($attributes): ?>
								<ul class="list-unstyled">
									<?php foreach($attributes as $attr): ?>
										<li class="contactInfo">
											<h5 class="titleUp"><b><?php echo $attr['title']; ?></b><i class="fa <?php echo $attr['icon']; ?>"></i> </h5>
											<address><?php echo $attr['content']; ?></address>
										</li>
									<?php endforeach; ?>
								</ul>
							<?php endif; ?>
	                	</div>
                	</div>
				</div>
	        </div>
	    </section>
           <?php get_footer(); ?>
    </main>

 