<?php
$form 		= ($page->field("recipients") != "");
$info 		= ($page->field("phone_numbers") != "" || $page->field("hours") != "" || $page->field("address_info") != "");
$map_type 	= $page->field("map_type");
$map 		= ($page->field("api_key") != "");
$social 	= ($page->field("facebook") != "" || $page->field("twitter") != "" || $page->field("google") != "" || $page->field("flickr") != "" || $page->field("pinterest") != "" || $page->field("youtube") != "" || $page->field("linkedin") != "" || $page->field("instagram") != "" || $page->field("etsy") != "");
$columns 	= ($form ? 1 : 0) + ($info ? 1 : 0) + ($map ? 1 : 0) + ($social ? 1 : 0);
$CI 		= get_instance();
?>
<div class="row">
	<?php
	if($map_type == "osm")
	{
		require_once(MODULE_PATH . "/openstreetmap/openstreetmap.php");

		$m = new OpenStreetMap();

		// Transfer page fields to module settings.
		foreach($page->fields as $f)
		{
			$m->set($f->key, $f->value);
		}

		if($m->enable_jquery())
		{
			$CI->enable_jquery = true;
		}
		if($m->enable_jquery_ui())
		{
			$CI->enable_jquery_ui = true;
		}

		foreach($m->scripts() as $script)
		{
			$CI->scripts[] = $script;
		}

		$m->module_instance_id = "a";
		$m->set("title", $page->field("title_map"));
		$m->set("title_heading_level", $page->field("title_heading_level_map"));
		$m->set("address", $page->field("address_map"));

		?><div class="col-12"><div class="p-3"><?php
		$m->render();
		?></div></div><?php
	}
	else if($map_type == "google" || $map_type == "")
	{
		require_once(MODULE_PATH . "/googlemap/googlemap.php");

		$m = new GoogleMap();

		// Transfer page fields to module settings.
		foreach($page->fields as $f)
		{
			$m->set($f->key, $f->value);
		}

		if($m->enable_jquery())
		{
			$CI->enable_jquery = true;
		}
		if($m->enable_jquery_ui())
		{
			$CI->enable_jquery_ui = true;
		}

		foreach($m->scripts() as $script)
		{
			$CI->scripts[] = $script;
		}

		if(file_exists(MODULE_PATH . "/googlemap/googlemap.less"))
		{
			$CI->less[] = MODULE_PATH . "/googlemap/googlemap.less";
		}

		$m->module_instance_id = "a";
		$m->set("title", $page->field("title_map"));
		$m->set("title_heading_level", $page->field("title_heading_level_map"));
		$m->set("address", $page->field("address_map"));

		?><div class="col-12"><div class="p-3"><?php
		$m->render();
		?></div></div><?php
	}
	?>

	<div class="<?php echo(TWO_COL); ?>">
		<?php
		if($info)
		{
			require_once(MODULE_PATH . "/contact_info/contact_info.php");

			$m = new ContactInfoModule();

			// Transfer page fields to module settings.
			foreach($page->fields as $f)
			{
				$m->set($f->key, $f->value);
			}

			if($m->enable_jquery())
			{
				$CI->enable_jquery = true;
			}
			if($m->enable_jquery_ui())
			{
				$CI->enable_jquery_ui = true;
			}

			foreach($m->scripts() as $script)
			{
				$CI->scripts[] = $script;
			}

			if(file_exists(MODULE_PATH . "/contact_info/contact_info.less"))
			{
				$CI->less[] = MODULE_PATH . "/contact_info/contact_info.less";
			}

			$m->module_instance_id = "b";
			$m->set("title", $page->field("title_info"));
			$m->set("title_heading_level", $page->field("title_heading_level_info"));
			$m->set("icon_size", $page->field("icon_size_info"));
			$m->set("address", $page->field("address_info"));

			?><div class="p-3"><?php
			$m->render();
			?></div><?php
		}

		if($social)
		{
			require_once(MODULE_PATH . "/social/social.php");

			$m = new SocialModule();

			// Transfer page fields to module settings.
			foreach($page->fields as $f)
			{
				$m->set($f->key, $f->value);
			}

			if($m->enable_jquery())
			{
				$CI->enable_jquery = true;
			}
			if($m->enable_jquery_ui())
			{
				$CI->enable_jquery_ui = true;
			}

			foreach($m->scripts() as $script)
			{
				$CI->scripts[] = $script;
			}

			if(file_exists(MODULE_PATH . "/social/social.less"))
			{
				$CI->less[] = MODULE_PATH . "/social/social.less";
			}

			$m->module_instance_id = "c";
			$m->set("title", $page->field("title_social"));
			$m->set("title_heading_level", $page->field("title_heading_level_social"));
			$m->set("icon_size", $page->field("icon_size_social"));

			?><div class="p-3"><?php
			$m->render();
			?></div><?php
		}
		?>
	</div>
	<div class="<?php echo(TWO_COL); ?>">
		<?php
		if($form)
		{
			require_once(MODULE_PATH . "/contact/contact.php");

			$m = new ContactForm();

			// Transfer page fields to module settings.
			foreach($page->fields as $f)
			{
				$m->set($f->key, $f->value);
			}

			if($m->enable_jquery())
			{
				$CI->enable_jquery = true;
			}
			if($m->enable_jquery_ui())
			{
				$CI->enable_jquery_ui = true;
			}

			foreach($m->scripts() as $script)
			{
				$CI->scripts[] = $script;
			}

			if(file_exists(MODULE_PATH . "/contact/contact.less"))
			{
				$CI->less[] = MODULE_PATH . "/contact/contact.less";
			}

			$m->module_instance_id = "d";
			$m->set("title", $page->field("title_contact"));
			$m->set("title_heading_level", $page->field("title_heading_level_contact"));

			?><div class="p-3"><?php
			$m->render();
			?></div><?php
		}
		?>
	</div>
</div>
