<?PHP 

include("config.php");
require_once("rating/classes/include.all.php");

$retailer_idhere = mysql_real_escape_string($_GET[retailer_id]);
$results = mysql_query("SELECT * FROM gforum_Retailers WHERE retailer_id=$retailer_idhere LIMIT 1");
$row = mysql_fetch_array($results);
if (!$row){header('Location: '.$site_url.'/?error=invalid_id');}


if($row[retailer_valid] == 0) {
  if(is_logged_in($user)){
    $username = base64_decode($_SESSION['user']);
    if($username != "Slowman" && $username != "Rappstar") { 
      header('Location: '.$site_url);
      exit();
    }
  } else { 
    header('Location: '.$site_url);
    exit(); 
  }
}

// set the page title
$pagetitle = $row[retailer_name];

// set meta tags
$meta_keywords = "triathlon, ".$row[retailer_name].", ".$row[retailer_state]." triathlon retailer";
$meta_description = "Considering shopping at ".$row[retailer_name]."? Here is all of the information about this retailer.";

/**if($row[retailer_'addcomment'] == 1){
  $init = '';
  $errmsg = NULL;
  $content1 = strip_tags(substr($row[retailer_content], 0, 4096));
  $rating = $row[retailer_rating];
  if($row[retailer_rating] == NULL){ $rating = 6; }
  $raceid = $row[retailer_id];
  if((trim($row[retailer_content]) == NULL)){ $errmsg = 'Please make a comment.'; }
  if(!$errmsg){
    $content = nl2br($content1);
    mysql_query("INSERT INTO comments(rating, name, content, raceid, date) VALUES($rating, \"$row[retailer_postusername]\", \"$content\", $raceid, NOW())");
  } 

}**/

// TODO: SLOWTWITCH EDIT
//$results = mysql_query("SELECT retailer_id, rating, name, content, raceid, UNIX_TIMESTAMP(date) as foo FROM comments WHERE raceid=$row[retailer_id] ORDER BY date DESC");
//$numcomments = mysql_num_rows($results);

//Compute average rating
//$test = mysql_query("SELECT rating FROM comments WHERE raceid=$row[retailer_id]");
//$num = mysql_num_rows($test);
/**if($num > 0){
  $total = 0;
  while($testrow = mysql_fetch_array($test)){
    if($testrow[rating] < 6){ $total = $total + $testrow[rating]; }
    if($testrow[rating] == 6){ $num = $num - 1; }
  }
  $avg = $total / $num;
}else{
  //No ratings
  $avg = 0;
}**/
?>

<? include("include_common_head.php"); ?>

<? include("include_common_content.php"); ?>

<!-- BEGIN OUTER -->
<div id="outer">

<?    
      include("include_starfunc.php");
?>

<!-- BEGIN CONTENT -->
<div class="content">

<div style="margin-bottom: 10px;">
<h2 style="display: inline; height: 16px; margin-bottom: 20px;"><!-- class="content-title"--><? echo stripslashes(stripslashes($row[retailer_name])) ; echo " "; ?></h2>

<?
    
  	  $foo = $retailer_idhere;
      
      $ratingData = Rating::OutputParentRating("$foo");
      
      if (Error::HasErrors())
      {
        echo Error::ShowErrorMessages();
        Error::ClearErrors();
      }
      else
      {
        echo $ratingData;
      }
 ?>
</div>

<? include("include_buttons.php") ?>

<div style="margin-top: 10px;">

<? if($_GET[review_add] == 'ok') { ?>
<span style="color: red;"><strong>Commenter:</strong> your comments have been submitted and will be validated within 24 hours.
<br /><br /></span>
<? } ?>

<? if($_GET[wiki_change] == 'success') { ?>
<span style="color: red;"><strong>Editor:</strong> your changes have been submitted and will be validated within 24 hours.
<br /><br /></span>
<? } ?>

<? $wikiFetchSQL = "SELECT edit_id FROM gforum_RetailersEdits WHERE retailer_id_fk = ".intval(mysql_escape_string($_GET[retailer_id]));

$boolEdits = mysql_num_rows(mysql_query($wikiFetchSQL));

if($boolEdits !== 0 && $_GET[wiki_change] != 'success') { ?>
<span style="color: red;"><strong>Group Edits:</strong> there are group edits waiting to be validated.
<br /><br /></span>
<? } ?>

<strong>Street Address: </strong><? echo stripslashes(htmlspecialchars($row[retailer_address])); ?>
<br />
<strong>Street Address Two: </strong><? echo stripslashes(htmlspecialchars($row[retailer_address_two])); ?>
<br />
<strong>City: </strong><? echo stripslashes(htmlspecialchars($row[retailer_city])); ?>
<br />
<strong>State: </strong><? echo stripslashes(htmlspecialchars($row[retailer_state])); ?>
<br />
<strong>Zip/Postal Code: </strong><? echo stripslashes(htmlspecialchars($row[retailer_zip])); ?>
<br />
<strong>Phone: </strong><? echo stripslashes(htmlspecialchars($row[retailer_phone])); ?>
<br />
<strong>Fax / Alternate Phone: </strong><? echo stripslashes(htmlspecialchars($row[retailer_fax])); ?>
<br />
<strong>E-mail: </strong><a href="mailto:<? echo $row[retailer_email]; ?>"><? echo stripslashes(htmlspecialchars($row[retailer_email])); ?></a>
<br />
<strong>Website: </strong><a href="<? echo $row[retailer_website]; ?>" target="_blank"><? echo $row[retailer_website]; ?></a><? if ($row[retailer_cart] == 1) { echo (" **eCommerce Shopping Cart**"); } ?>

<br />
<br />

<div class="indentlarge">
<? 
for ($i = 0; $i < 26; $i++) echo("*"); 
echo (" PRODUCT DELIVERY CHANNELS ");
for ($i = 0; $i < 25; $i++) echo("*"); 
?>
<br />
<br />
</div>

<strong>We ship mail-order via: </strong>
<? if ($row[retailer_mailorder_ecommerce] == 0) { echo (""); } else { echo ("e-commerce site"); } ?>
<? if ($row[retailer_mailorder_phone] == 0) { echo (""); } elseif ($row[retailer_mailorder_ecommerce] == 1) { echo (", phone"); } else { echo ("phone"); } ?>
<br />
<strong>We offer local home/work delivery, transacting via: </strong>
<? if ($row[retailer_local_ecommerce] == 0) { echo (""); } else { echo ("e-commerce site"); } ?>
<? if ($row[retailer_local_phone] == 0) { echo (""); } elseif ($row[retailer_local_ecommerce] == 1) { echo (", phone"); } else { echo ("phone"); } ?>
<br />
<strong>You may order in advance, and pick up, transacting via: </strong>
<? if ($row[retailer_pickup_ecommerce] == 0) { echo (""); } else { echo ("e-commerce site"); } ?>
<? if ($row[retailer_pickup_phone] == 0) { echo (""); } elseif ($row[retailer_pickup_ecommerce] == 1) { echo (", phone"); } else { echo ("phone"); } ?>

<br />
<br />

<div class="indentlarge">
<? 
for ($i = 0; $i < 35; $i++) echo("*"); 
echo (" BIKE FIT ");
for ($i = 0; $i < 35; $i++) echo("*"); 
?>
</div>

<br />
<strong>Key Tri-Specific Contact(s): </strong>
<? if ($row[retailer_contact] == 0) { echo "None"; } else { echo "Yes, Their Names - "; echo stripslashes($row[retailer_contact_names]); } ?> 
<br />
<strong>F.I.S.T. Tri Fitter(s): </strong>
<? if ($row[retailer_fist] == 0) { echo "None"; } else { echo "Yes, Their Names -  "; echo stripslashes($row[retailer_fist_names]); } ?> 
<br />
<strong>F.I.S.T. Road Fitter(s): </strong>
<? if ($row[retailer_fist_road] == 0) { echo "None"; } else { echo "Yes, Their Names -  "; echo stripslashes($row[retailer_fist_road_names]); } ?> 
<br />
<strong>F.I.S.T. Advanced Fitter(s): </strong>
<? if ($row[retailer_fist_advanced] == 0) { echo "None"; } else { echo "Yes, Their Names -  "; echo stripslashes($row[retailer_fist_advanced_names]); } ?> 
<br />
<strong>BFACT Score: </strong><? echo stripslashes($row[retailer_bfact]); ?>
<br />
<strong>BikeFit, BodyGeometry, Retul, Serotta, or Trek Fitter(s): </strong>
<? if ($row[retailer_serotta] == 0) { echo "None"; } else { echo "Yes, Their Names - "; echo stripslashes($row[retailer_serotta_names]); } ?>
<br />
<strong>Default Tri-Fit Methodology: </strong>
<?
$sql = ("SELECT * FROM ".$prefix."RetailersMethods WHERE retailer_method_id = ".$row[retailer_method]." LIMIT 1");

//echo $sql;

$fetch = mysql_query($sql) or die(mysql_error());

if (mysql_num_rows($fetch) > 0) {
	while ($method_list = mysql_fetch_array($fetch)) {
		echo ("$method_list[retailer_method_name]");
	}
} else {
	echo ("Unanswered");
}

?>
<br />
<strong>Fit Bikes: </strong><?

$row[retailer_fitbikes] = ltrim(rtrim($row[retailer_fitbikes], ", "), ", ");

$sql = ("SELECT * FROM gforum_RetailersFitbikes WHERE retailers_fitbike_id IN ($row[retailer_fitbikes]) ORDER BY retailers_fitbike_name ASC");

//echo $sql;

$fetch = mysql_query($sql) or die(mysql_error());

$fitbike_list = "";
while ($list = mysql_fetch_array($fetch)) {
    $fitbike_list  = $fitbike_list."$list[retailers_fitbike_name], ";
}
$fitbike_list = rtrim($fitbike_list, ', ');

if ($fitbike_list) {echo $fitbike_list;} else {echo "None";}

?>

<br />
<strong>Motion-Capture Systems: </strong><?

$row[retailer_motioncapture] = ltrim(rtrim($row[retailer_motioncapture], ", "), ", ");

$sql = ("SELECT * FROM gforum_RetailersMotioncapture WHERE retailers_motioncapture_id IN ($row[retailer_motioncapture]) ORDER BY retailers_motioncapture_name ASC");

//echo $sql;

$fetch = mysql_query($sql) or die(mysql_error());

$motioncapture_list = "";
while ($list = mysql_fetch_array($fetch)) {
    $motioncapture_list  = $motioncapture_list."$list[retailers_motioncapture_name], ";
}
$motioncapture_list = rtrim($motioncapture_list, ', ');

if ($motioncapture_list) {echo $motioncapture_list;} else {echo "None";}

?>

<br /><br />
<div class="indentlarge">
<? 
for ($i = 0; $i < 36; $i++) echo("*"); 
echo (" BRANDS ");
for ($i = 0; $i < 36; $i++) echo("*"); 
?>
</div>

<br />
<strong>Wetsuits: </strong><?

$row[retailer_wetsuits] = ltrim(rtrim($row[retailer_wetsuits], ", "), ", ");

$sql = ("SELECT * FROM gforum_RetailersWetsuits WHERE retailers_wetsuit_id IN ($row[retailer_wetsuits]) ORDER BY retailers_wetsuit_name ASC");

//echo $sql;

$fetch = mysql_query($sql) or die(mysql_error());

$wetsuit_list = "";
while ($list = mysql_fetch_array($fetch)) {
    $wetsuit_list  = $wetsuit_list."$list[retailers_wetsuit_name], ";
}
$wetsuit_list = rtrim($wetsuit_list, ', ');

if ($wetsuit_list) {echo $wetsuit_list;} else {echo "None";}

?>

<br />
<strong>Bikes: </strong><?

$row[retailer_bikes] = ltrim(rtrim($row[retailer_bikes], ", "), ", ");

$sql = ("SELECT * FROM gforum_RetailersBikes WHERE retailers_bike_id IN ($row[retailer_bikes]) ORDER BY retailers_bike_name ASC");

//echo $sql;

$fetch = mysql_query($sql) or die(mysql_error());

$bike_list = "";
while ($list = mysql_fetch_array($fetch)) {
    $bike_list  = $bike_list."$list[retailers_bike_name], ";
}
$bike_list = rtrim($bike_list, ', ');

if ($bike_list) {echo $bike_list;} else {echo "None";}

?>

<br />
<strong>Custom Frames: </strong><?

$row[retailer_customs] = ltrim(rtrim($row[retailer_customs], ", "), ", ");

$sql = ("SELECT * FROM gforum_RetailersCustoms WHERE retailers_custom_id IN ($row[retailer_customs]) ORDER BY retailers_custom_name ASC");

//echo $sql;

$fetch = mysql_query($sql) or die(mysql_error());

$custom_list = "";
while ($list = mysql_fetch_array($fetch)) {
    $custom_list  = $custom_list."$list[retailers_custom_name], ";
}
$custom_list = rtrim($custom_list, ', ');

if ($custom_list) {echo $custom_list;} else {echo "None";}

?>

<br /><br />
<div class="indentlarge">
<? 
for ($i = 0; $i < 80; $i++) echo("*"); 
?>
</div>
<br />
<strong>Shop Hours: </strong><? echo stripslashes(htmlspecialchars($row[retailer_hours])); ?>
<br />
<strong>Barnett-Trained Mechanic(s): </strong>
<? if ($row[retailer_barnett] == 0) { echo "None"; } else { echo "Yes, Their Names - "; echo stripslashes($row[retailer_barnett_names]); } ?> 
<br />
<strong>United Bicycle Institute-Trained Mechanic(s): </strong>
<? if ($row[retailer_ubi] == 0) { echo "None"; } else { echo "Yes, Their Names - "; echo stripslashes($row[retailer_ubi_names]); } ?> 
<br /><br />
<strong>Shop Info: </strong>
<? echo stripslashes(stripslashes($row[retailer_info])) ?>
<br /><br />
<strong>Directions: </strong>
<? echo stripslashes(stripslashes($row[retailer_directions])); ?>

<br />
<br />

</div>

<!-- BEGIN COMMENTS -->
<? 

include ('comments_show.php');

/**if (is_logged_in($user)) { 
	echo "<br />";
	include ('comments_add.php');
}**/

?>
 
<!-- END COMMENTS -->

<div>

<!-- BEGIN GOOGLE MAP -->

</div>

<table border="0" width="100%" cellspacing="2" cellpadding="2" bgcolor="#ffffff">
<tr>
<td bgcolor="#cecece">
<div class="content-title-no"><strong>Google Map</strong></div>
</tr>
</table>

<br />
<? $myLat = $row[retailer_lat]; ?>
<? $myLng = $row[retailer_lng]; ?>
<div id="map_canvas" style="width:625px; height:450px; border: 1px solid;"></div>
<script type="text/javascript">initializeGoogleMap(<? echo ($myLat.", ".$myLng); ?>)</script>
<br />
Map location is based off of a geocode of the addressed entered using Google's Google Maps API. If your address does not geocode properly, you can either update the address (we will attempt to re-geocode after any updates to your entry) <strong>or</strong> you can use Google's geocoding tool found here: <a href="http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html">http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html</a> to obtain a lat/long for your location and enter that. To use the utility, type in an address that is close to your location and then drag-and-drop the marker to obtain the desired lat/long. If you choose to enter a lat/long, you <strong>must</strong> check the box on the edit page that says, "override geocode with entered lat/long."

<div>

<!-- END GOOGLE MAP -->

<!-- BEGIN LIST OF RACERS -->
<a name="racers"></a>
<? 
$testresults = mysql_query("SELECT retailer_shopper_tags FROM gforum_Retailers WHERE retailer_id=$row[retailer_id]");
$testrow = mysql_fetch_array($testresults);
$tags = explode(",", $testrow[retailer_shopper_tags]);
$numcount = count($tags) - 1;
if($numcount == 0){ $phrase = "No users have tagged this shop yet."; }
else if($numcount == 1){ $phrase = "There is 1 user who has tagged this shop:"; } 
else{ $phrase = "There are $numcount users who have tagged this shop: "; }
echo "<br />";
?>
<table border="0" width="100%" cellspacing="2" cellpadding="2" bgcolor="#ffffff">
<tr>
<td bgcolor="#cecece">
<div class="content-title-no"><strong><? echo $phrase; ?></strong></div>
</tr>
<tr><td bgcolor="#cecece">
<?
//List users
$i = 0;
foreach($tags as $value){
if($i > 0){
$tempresults = mysql_query("SELECT user_username FROM ".$prefix."User WHERE user_id='$value'") or die (mysql_error());
$temprow = mysql_fetch_array($tempresults);
if($i > 1){ echo ", "; }
// TODO: SLOWTWITCH EDIT
//echo "<a href=\"profiles/$temprow[user_username].html\">$temprow[user_username]</a>";
// replace the link above with the link below for integration into gforum
echo "<a href=\"http://forum.slowtwitch.com/gforum.cgi?username=$temprow[user_username]&session=".$_SESSION['session_id']."&from=retailers\">$temprow[user_username]</a>";
// TODO: SLOWTWITCH EDIT END
}
$i++;
}
if(count($tags) <= 1){ echo "No users"; }
?>
</td>
</tr> 
</table>
<!-- END OF LIST OF RACERS -->
<br />

<!-- BEGIN RATING -->
<strong><a name="rate"></a>Rate This Shop:</strong><br /><br />
<?

$numVoters = mysql_numrows(mysql_query("SELECT DISTINCT rating_ip FROM gforum_RetailersRating WHERE rating_retailer_id = '".mysql_real_escape_string($_GET[retailer_id])."'"));

include("rating/int.to.words.php");

?>
Below are the current ratings for this retail shop, based on <? echo("<strong>".int_to_words($numVoters)."</strong>"); if($numVoters == 1) { echo(" respondent"); } else { echo(" respondents"); } ?>.  To rate this shop yourself, just mouse over each set of
"stars" below, and click on the star that corresponds to your view in each
category.  Your vote in each category is recorded once you click the
appropriate star. The composite average rating for the shop is displayed at the top of the page. To view the top-10 retailers, <!--in each category, and overall,-->
click <a href="top_retailers.php">here</a>.
<br /><br />
    <?php
      
      // begin rating matrix
      $catResults = mysql_query("SELECT * FROM gforum_RetailersRatingCategory");
      
      while ($catRow = mysql_fetch_array($catResults)) {
      
      	  $bar = $catRow[rating_cat_id];
      
		  $ratingData = Rating::OutputRating("$foo","$bar");
		  
		  if (Error::HasErrors())
		  {
			echo Error::ShowErrorMessages();
			Error::ClearErrors();
		  }
		  else
		  {
			echo $ratingData;
		  }
		  
	  }
	?>
<!-- END RATING -->

<br />

<!-- BEGIN LIST OF EDITORS -->
<a name="editors"></a>
<? 
$testresults = mysql_query("SELECT * FROM gforum_RetailersEditors WHERE retailer_id_fk=$row[retailer_id] ORDER BY edit_timestamp DESC");
$numcount = mysql_num_rows($testresults);
if($numcount == 0){ $phrase = "No updates have been made this retailer yet."; }
else if($numcount == 1){ $phrase = "There has been 1 update to this retailer:"; } 
else{ $phrase = "There have been $numcount updates to this retailer: "; }
echo "<br />";
?>
<table border="0" width="100%" cellspacing="2" cellpadding="2" bgcolor="#ffffff">
<tr>
<td bgcolor="#cecece">
<div class="content-title-no"><strong><? echo $phrase; ?></strong></div>
</td></tr>
<tr><td bgcolor="#cecece">
<?
//List users
$i = 0;
while($row=mysql_fetch_array($testresults)){
if($i >= 0){
$tempresults = mysql_query("SELECT user_username FROM ".$prefix."User WHERE user_id='$row[user_id_fk]'") or die (mysql_error());
$temprow = mysql_fetch_array($tempresults);
if($i >= 1){ echo "<br />"; }
	// TODO: SLOWTWITCH EDIT
	//echo "<a href=\"profiles/$temprow[user_username].html\">$temprow[user_username]</a>";
	// replace the link above with the link below for integration into gforum
	echo "<a href=\"http://forum.slowtwitch.com/gforum.cgi?username=$temprow[user_username]&session=".$_SESSION['session_id']."&from=racecalendar\">$temprow[user_username]</a> at ".date("F j, Y g:i A", $row[edit_timestamp]);
	// TODO: SLOWTWITCH EDIT END
}
$i++;
}
if($numcount <= 0){ echo "No users"; }
?>
</td></tr> 
</table>
<!-- END OF LIST OF EDITORS -->
</div>

</div>
<!-- End BODY -->
</div>
<!-- End Outer -->

<? include("include_common_footer.php"); ?>

