<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

// ------------------------------------------------------------------------------------------------
// Add linked Javascript & css.
// ------------------------------------------------------------------------------------------------

// $template->linkCss($cssPath);
// $template->linkJs($jsPath);

// ------------------------------------------------------------------------------------------------
// Add in-page Javascript & CSS
// ------------------------------------------------------------------------------------------------

//$headCss = <<<EOT
//EOT;
//$template->addCss($headCss);

//$headJavascript = <<<EOT
//EOT;
//$template->addJavascript(headJavascript);

// ------------------------------------------------------------------------------------------------
// Component View Settings
// ------------------------------------------------------------------------------------------------

$showErrors = FALSE;

$errorsAsComment = TRUE;
$showStatusAsComment = FALSE;
$showStatusAsOutput = FALSE;

//--------------------------------------------------------------------------------------------------
// Component Markup
//--------------------------------------------------------------------------------------------------

if (!empty($mMember)) {

	?>

	<h1><?=$mMember->get_business_name()?></h1>

	<div id="right_column">
	
		<?
		// ------------------------------------------
		// Tags
		// ------------------------------------------
		?>

		<div id="tags">

		<h2 style="font-size:14px;">Tags</h2>

		<?

		echo "<p><strong>Service Types:</strong> " . implode(", ",$tagServiceTypes) . "</p>";
		echo "<p><strong>Categories:</strong> " . implode(", ",$tagCategories) . "</p>";
		echo "<p><strong>Item Types:</strong> " . implode(", ",$tagItemTypes) . "</p>";
		echo "<p><strong>Manufacturers:</strong> " . implode(", ",$tagManufacturers) . "</p>";

		?>

		</div> <!-- tags -->

		<?
		// ------------------------------------------
		// Addresses
		// ------------------------------------------
		?>

		<div id="locations">

		<h2 style="font-size:14px;">Locations</h2>

		<?

		foreach($locations as $loc) {

			echo "<div class=\"location\">";

				$ls = "<span class=\"label\">";
				$vs = "<span class=\"value\">";
				$sc = "</span>";

				// ------------------------------------------
				// Location Name
				// ------------------------------------------

				$mainMarkup = ($loc['main'] == 1 ? "(main)" : "");

				if (!empty($loc['location_name'])) {
					echo "<p>";
					echo $ls . "Location Name" . $sc;
					echo $vs . $loc['location_name'] . $mainMarkup . $sc;
					echo "</p>";
				}

				// ------------------------------------------
				// Contact Name
				// ------------------------------------------

				$contactNameMarkup = "";

				if (!empty($loc['firstname']))
					$contactNameMarkup .= $loc['firstname'];

				if (!empty($loc['lastname']))
					$contactNameMarkup .= $loc['lastname'];

				if ($contactNameMarkup != "")
					$contactNameMarkup = "<p>{$ls}Contact Name{$sc}" . $vs . $contactNameMarkup . $sc . "</p>";

				echo $contactNameMarkup;

				// ------------------------------------------
				// Contact Details
				// ------------------------------------------

				$contactDetailsMarkup = "";

				if (!empty($loc['telephone']))
					$contactDetailsMarkup .= "<p>{$ls}Telephone{$sc}" . $vs. $loc['telephone'] . $sc . "</p>"; 

				if (!empty($loc['mobile']))
					$contactDetailsMarkup .= "<p>{$ls}Mobile{$sc}" . $vs. $loc['mobile'] . $sc . "</p>"; 

				if (!empty($loc['fax']))
					$contactDetailsMarkup .= "<p>{$ls}Fax{$sc}" . $vs. $loc['fax'] . $sc . "</p>"; 

				if (!empty($loc['email']))
					$contactDetailsMarkup .= "<p>{$ls}Email{$sc}" . $vs. $loc['email'] . $sc . "</p>"; 

				echo $contactDetailsMarkup;

				// ------------------------------------------
				// Address
				// ------------------------------------------

				$addressLines = array();

				if (!empty($loc['street_address']))
					$addressLines[] = $loc['street_address'];

				if (!empty($loc['town']))
					$addressLines[] = $loc['town'];

				if (!empty($loc['city']))
					$addressLines[] = $loc['city'];

				if (!empty($loc['county']))
					$addressLines[] = $loc['county'];

				if (!empty($loc['postcode']))
					$addressLines[] = $loc['postcode'];

				if (count($addressLines > 0))
					$addressMarkup = "<p>{$ls}Address{$sc}" . $vs . implode("<br/>",$addressLines) . $sc . "</p>";

				echo $addressMarkup;

			echo "</div> <!-- location -->";

		}

		?>

		</div> <!-- locations -->	

	</div> <!-- right_column -->
			
	<div id="left_column">

	<?
	
	// ------------------------------------------
	// Pages Index
	// ------------------------------------------

	if (count($pages) > 0) {

		echo "<h2>Pages</h2>";
		
		echo "<ul style=\"margin-bottom:30px;\">";
	
		foreach($pages as $p) {
		
			$href = MemberManager::publicViewCommercialUrl($p['member_id'],$p['id'],$p['uri']);
		
			$a = "<a href=\"$href\" title=\"\">" . $p['title'] . "</a>";
			
			echo "<li style=\"margin-bottom:5px;\">$a</li>";
			
		}
		
		echo "</ul>";
	
	}
	
	// echo "<pre>"; print_r($pages); echo "</pre>";
	
	// ------------------------------------------
	// Page
	// ------------------------------------------
	
	if ($component->hasPage()) {
	
		?>
	
		<h2>Page Content: <?=$mCommercialMemberPage->get_title()?></h2>
	
		<?
	
		echo $mCommercialMemberPage->get_body();
		
	}

	?>
	</div> <!-- left_column -->
	<?			 

} else {

	// No member provided.

	?>
	
	<h1>Error</h1>
	
	<?

}

//--------------------------------------------------------------------------------------------------
// Show Component Status As Comment
//--------------------------------------------------------------------------------------------------

if ($showStatusAsComment) {

	echo "\n<!--\n";
	echo $component->getStatusCommentContent();
	echo "\n-->\n";

}

//--------------------------------------------------------------------------------------------------
// Show Component Status As Output
//--------------------------------------------------------------------------------------------------

if ($showStatusAsOutput) {

	echo "<pre style=\"float:left;\">" . $component->getStatusCommentContent() . "</pre>";
	
}

//--------------------------------------------------------------------------------------------------
// Show Errors
//--------------------------------------------------------------------------------------------------

if ($showErrors && $component->hasErrors()) {

	?>

	<p style="color:red;margin-bottom:0px;"><strong>ERRORS</strong></p>

	<p>
		<?	
		echo implode("<br/>",$component->getErrors());
		?>
	</p>
	
	<?
	
}

//--------------------------------------------------------------------------------------------------
// Errors as Comment
//--------------------------------------------------------------------------------------------------

if ($errorsAsComment && $component->hasErrors()) {

	echo "<!-- ERRORS\n";
	echo implode("\n",$component->getErrors());
	echo "\n-->\n";
	
}

?>