<?PHP 

include("config.php");

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(); 
  }

//$count_fitters = mysql_fetch_row(mysql_query("SELECT COUNT(fitter_id) FROM gforum_Fitters"));
//$num_fitters = $count_fitters[0];
//$fitter_idhere = $num_fitters

echo ("Name, Address, Address Two, City, State, Zip, Phone, Email, Website, Methodology, Certification(s), Fitbike(s), Motion Capture System(s)<br /><br />");

$results = mysql_query("SELECT * FROM ".$prefix."Fitters ORDER BY fitter_id ASC");
while ($row = mysql_fetch_array($results)){
	echo stripslashes(stripslashes($row[fitter_name])) . ", "; 
	
	echo stripslashes(htmlspecialchars($row[fitter_address])) . ", ";

	echo stripslashes(htmlspecialchars($row[fitter_address_two])) . ", ";

	echo stripslashes(htmlspecialchars($row[fitter_city])) . ", ";

	echo stripslashes(htmlspecialchars($row[fitter_state])) . ", ";

	echo stripslashes(htmlspecialchars($row[fitter_zip])) . ", ";

	echo stripslashes(htmlspecialchars($row[fitter_phone])) . ", ";

	echo stripslashes(htmlspecialchars($row[fitter_email])) . ", ";

	$substring = "http";
	if (!is_int(strpos($row[fitter_website], $substring))) {
		$row[fitter_website] = "http://".$row[fitter_website];
	}
	echo $row[fitter_website] . ", ";
	
	$row[fitter_fitbikes] = ltrim(rtrim($row[fitter_fitbikes], ", "), ", ");

	//methodology
	$sql = ("SELECT * FROM ".$prefix."FittersMethods WHERE fitter_method_id = ".$row[fitter_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[fitter_method_name], ");
		}
	} else {
		echo ("Unanswered on fit methodology, ");
	}


	//certifications
	$row[fitter_certifications] = ltrim(rtrim($row[fitter_certifications], ", "), ", ");

	$sql = ("SELECT * FROM gforum_FittersCertifications WHERE fitter_certification_id IN ($row[fitter_certifications]) ORDER BY fitter_certification_name ASC");

	//echo $sql;

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

	$certification_list = "";
	while ($list = mysql_fetch_array($fetch)) {
		$certification_list  = $certification_list."$list[fitter_certification_name] / ";
	}
	$certification_list = rtrim($certification_list, '/ ');

	if ($certification_list) {echo $certification_list . ", ";} else {echo "No certification(s), ";}

	//fitbikes
	$sql = ("SELECT * FROM gforum_FittersFitbikes WHERE fitter_fitbike_id IN ($row[fitter_fitbikes]) ORDER BY fitter_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[fitter_fitbike_name] / ";
	}
	$fitbike_list = rtrim($fitbike_list, '/ ');

	if ($fitbike_list) {echo $fitbike_list . ", ";} else {echo "No fitbike(s), ";}

	//motion captures
	$row[fitter_motioncapture] = ltrim(rtrim($row[fitter_motioncapture], ", "), ", ");

	$sql = ("SELECT * FROM gforum_FittersMotioncapture WHERE fitter_motioncapture_id IN ($row[fitter_motioncapture]) ORDER BY fitter_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[fitter_motioncapture_name] / ";
	}
	$motioncapture_list = rtrim($motioncapture_list, '/ ');

	if ($motioncapture_list) {echo $motioncapture_list;} else {echo "No motion capture system(s)";}
	
	echo "<br /> ";
	
}
?>