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

if (!isset($_GET['region']) || !is_numeric($_GET['region'])) {
  header('Location: '.$site_url.'/?error=no_region');
}

$results = mysql_query("SELECT regionlong FROM ".$prefix."ResourceRegions WHERE regionid = '".mysql_real_escape_string($_GET[region])."' LIMIT 1");

$row = mysql_fetch_array($results);
$selected_item = mysql_real_escape_string($_GET[region]);
$regionname = $row[regionlong];

$results = mysql_query("SELECT gr.runshop_id, gr.runshop_name, gr.runshop_address, gr.runshop_address_two, gr.runshop_city, gr.runshop_state, gr.runshop_zip, gr.runshop_phone, gr.runshop_fax, gr.runshop_email, gr.runshop_website, gr.runshop_cart
FROM ".$prefix."Runshops AS gr
RIGHT JOIN ".$prefix."ResourceStates AS gts
ON gts.regionid = '".mysql_real_escape_string($_GET[region])."' AND gr.runshop_state_tag = gts.statetag
WHERE gr.runshop_valid = 1 ORDER BY gr.runshop_name ASC");

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

// set the page title
$pagetitle = $regionname;

// set meta tags
$meta_keywords = "running stores in ".$regionname;
$meta_description = "Trying to find running stores in ".$regionname."? Here is a listing of all ".$regionname." running stores.";
?>

<? 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 clearfix">
          <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">Running Stores</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 Retailer</a>
                <? } ?>
                <hr class="line" />
                <? include("include_region_list.php"); ?>

                <h2><? echo $regionname ?> Region</h2>
                <hr />
                <? if($none == TRUE) {
                  echo "<p>No running stores have been entered yet for ".$regionname. ".</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>

