<?PHP include("config.php");
require_once("class/rating/classes/include.all.php");
include("class/rating/int.to.words.php");

if (!isset($_GET['state']) || !in_array($_GET['state'], $state_tag_list)) {
    header('Location: '.$site_url.'/?error=no_state');
}

$results = mysql_query("SELECT statelong FROM ".$prefix."FittersStates WHERE statetag = '".substr(mysql_escape_string($_GET[state]),0,20)."' LIMIT 1") OR die(mysql_error());

if (mysql_num_rows($results) == 0) {
  header('Location: '.$site_url.'?mysql_error');
}

$row = mysql_fetch_array($results);
$statename = $row[statelong];

$results = mysql_query("SELECT fitter_id, fitter_name, fitter_address, fitter_address_two, fitter_city, fitter_state, fitter_zip, fitter_phone, fitter_fax, fitter_email, fitter_website, fitter_certifications, fitter_fitbikes FROM ".$prefix."Fitters WHERE fitter_state_tag='".substr(mysql_escape_string($_GET[state]),0,20)."' AND fitter_valid=1 ORDER BY fitter_name ASC");

$none = FALSE;
if (mysql_num_rows($results) == 0) {
  $none = TRUE;
}

// set the page title
$pagetitle = $statename;
$selected_item = mysql_escape_string($_GET[state]);

// set meta tags
$meta_keywords = "bike fitters in ".$statename;
$meta_description = "Trying to find bike fitters in ".$statename."? Here is a listing of all ".$statename." bike fitters. Users can even rate and comment on these fitters.";
?>

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

<body class="listings">
  <? include($common_path . "/ads/ad_wallpaper.html"); ?>

  <div class="container">
    <? include($common_path . "/templates/include_header.php"); ?>
    <div class="main">
      <div class="contentwrapper clearfix">

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

        <section class="section listings section-has-widgets section-static remove-sidebar">
          <div class="sidebar-b">
            <? include("include_sidebar.php"); ?>
          </div>
          <div class="content content-has-widgets">
            <div class="grid">

              <div class="clearfix">
                <h1 class="float-left">Fitters</h1>
                <a href="<? echo $site_url ?>" class="btn btn-white float-right">Back</a>
                <? if (is_logged_in($user)) { ?>
                <a href="<? echo $site_url . '/add.php' ?>" class="btn btn-white float-right">Add Fitter</a>
                <? } ?>
                <hr class="line" />
                <? include("../runshops/include_region_list.php"); ?>

                <h2><? echo $statename ?> State</h2>
                <?
                if($none == TRUE){
                    echo "<p>No bike fitters have been entered yet for $statename.</p>";
                }
                ?>

                <? while ($row = mysql_fetch_array($results)) {
                  include("include_store.php");
                } ?>

              </div><!-- end col-2/3 -->
            </div><!-- end grid -->
          </div><!-- end content -->
        </section>
          
      </div><!-- end contentwrapper -->
    </div> <!-- end main -->

  <? include($common_path . "/templates/include_footer.php") ?>
  </div> <!-- container  -->
</body>
<? include($common_path . "/templates/include_global_js.php") ?>
</html>