<?PHP 

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

$runshop_idhere = intval(mysql_escape_string($_GET[runshop_id]));
$results = mysql_query("SELECT * FROM ".$prefix."Runshops WHERE runshop_id='".$runshop_idhere."' LIMIT 1");
$row = mysql_fetch_array($results);
if (!$row){header('Location: '.$site_url.'/?error=invalid_id');}


if($row[runshop_valid] == 0) {
  if(!is_admin()){
    header('Location: '.$site_url);
    exit(); 
  }
}

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

// set meta tags
$meta_keywords = "triathlon, ".$row[runshop_name].", ".$row[runshop_state]." running store";
$meta_description = "Considering shopping at ".$row[runshop_name]."? Here is all of the information about this running store.";
?>

<? 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">
            <? $selected_item = strtolower($row[runshop_state]); ?>
            <? include("include_sidebar.php"); ?>
          </div>

          <div class="content content-has-widgets">
            <div class="grid">

              <div class="clearfix">
                <h1 class="float-left">Running Stores</h1>
                <? if ($user) { ?>
                <form method="post" action="wiki_edit.php?retailer_id=<? echo $row[runshop_id] ?>">
                  <input type="submit" value="Edit (wiki)" class="nobutton btn btn-white float-right">
                </form>
                <? } ?>
                <a href="" class="btn btn-white float-right">Back</a>
                <hr class="line" />
                <? include("include_region_list.php"); ?>
                <div class="details grid">
                  <div class="col-9-12">
                    <h2><? echo stripslashes(stripslashes($row[runshop_name])) ; echo " "; ?></h2>
                  </div>
                  <div class="col-3-12 right">
                    <? if(is_logged_in($user)) { ?><a href="#comment">Comment</a><? }?>
                  </div>
                  <div class="clearfix"></div>
                  <div class="col-6-12 address">
                    <? echo stripslashes(htmlspecialchars($row[runshop_address])); ?><br />
                    <? if ( $row[runshop_address_two] )  { echo stripslashes(htmlspecialchars($row[runshop_address_two]) . "<br />"); } ?>
                    <? echo stripslashes(htmlspecialchars($row[runshop_city])); ?>, <? echo stripslashes(htmlspecialchars($row[runshop_state])); ?> <? echo stripslashes(htmlspecialchars($row[runshop_zip])); ?><br />
                    Phone: <? echo stripslashes(htmlspecialchars($row[runshop_phone])); ?><br />
                    Fax: <? echo stripslashes(htmlspecialchars($row[runshop_fax])); ?>
                  </div>
                  <div class="col-6-12 contact">
                    Email: <a href="mailto:<? echo $row[runshop_email]; ?>"><? echo stripslashes(htmlspecialchars($row[runshop_email])); ?></a><br />
                    <span class="briefy-b">Website: <a href="<? echo $row[runshop_website]; ?>" target="_blank"><? echo stripslashes(htmlspecialchars($row[runshop_website])); ?></a></span>
                  </div>
                  <div class="clearfix"></div>
                  <? if($_GET[review_add] == 'ok') { ?>
                  <p class="success"><strong>Commenter:</strong> your comments have been submitted and will be validated within 24 hours.</p>
                  <? } ?>
                  <? if($_GET[wiki_change] == 'success') { ?>
                  <p class="success"><strong>Editor:</strong> your changes have been submitted and will be validated within 24 hours.</p>
                  <? } ?>
                  <? $wikiFetchSQL = "SELECT edit_id FROM ".$prefix."RunshopsEdits WHERE runshop_id_fk = '".intval(mysql_escape_string($_GET[runshop_id]))."'";
                  $boolEdits = mysql_num_rows(mysql_query($wikiFetchSQL));
                  if($boolEdits !== 0 && $_GET[wiki_change] != 'success') { ?>
                  <p class="error"><strong>Group Edits:</strong> there are group edits waiting to be validated.</p>
                  <? } ?>
                  <br />
                  <div class="col-1-1">
                    <? include("include_buttons.php"); ?>
                  </div>
                  <div class="col-1-1 detail-block">
                    <h3>Key Tri-Specific Contact(s)</h3>
                    <div class="highlight-block">
                      <? if ($row[runshop_contact] == 0) { echo "None"; } else { echo "Yes, Their Names - "; echo stripslashes($row[runshop_contact_names]); } ?>
                    </div>
                  </div>
                  <div class="col-1-1 detail-block">
                    <h3>Diagnostic Equipment</h3>
                    <div class="highlight-block">
                      <?
                      $row[runshop_diagnostics] = ltrim(rtrim($row[runshop_diagnostics], ", "), ", ");
                      if ($row[runshop_diagnostics]) {
                          $sql = ("SELECT * FROM ".$prefix."RunshopsDiagnostics WHERE diagnostic_id IN ($row[runshop_diagnostics]) ORDER BY diagnostic_name ASC");
                          $fetch = mysql_query($sql) or die(mysql_error());

                          $diagnostic_list = "";
                          while ($list = mysql_fetch_array($fetch)) {
                              $diagnostic_list  = $diagnostic_list."$list[diagnostic_name], ";
                          }
                          $diagnostic_list = rtrim($diagnostic_list, ', ');
                      }
                      if ($diagnostic_list) {echo $diagnostic_list;} else {echo "None";}
                      ?>
                    </div>
                  </div>
                  <div class="col-1-1 detail-block">
                    <h3>Brands</h3>
                    <div class="highlight-block">
                      <strong>Running Shoes:</strong>
                      <?
                      $row[runshop_shoes] = ltrim(rtrim($row[runshop_shoes], ", "), ", ");
                      if ($row[runshop_shoes]) {
                          $sql = ("SELECT * FROM ".$prefix."RunshopsShoes WHERE shoe_id IN ($row[runshop_shoes]) ORDER BY shoe_name ASC");
                          $fetch = mysql_query($sql) or die(mysql_error());
                          $shoe_list = "";
                          while ($list = mysql_fetch_array($fetch)) {
                              $shoe_list  = $shoe_list."$list[shoe_name], ";
                          }
                          $shoe_list = rtrim($shoe_list, ', ');
                          if ($shoe_list) {echo $shoe_list;} else {echo "None";}
                          ?><br />
                          <strong>Socks:</strong>
                          <?
                          $row[runshop_socks] = ltrim(rtrim($row[runshop_socks], ", "), ", ");
                          $sql = ("SELECT * FROM ".$prefix."RunshopsSocks WHERE sock_id IN ($row[runshop_socks]) ORDER BY sock_name ASC");
                          $fetch = mysql_query($sql) or die(mysql_error());
                          $sock_list = "";
                          while ($list = mysql_fetch_array($fetch)) {
                              $sock_list  = $sock_list."$list[sock_name], ";
                          }
                          $sock_list = rtrim($sock_list, ', ');
                      }

                      if ($sock_list) {echo $sock_list;} else {echo "None";}
                      ?><br />
                      <strong>Run Focused Apparel:</strong>
                      <?
                      $row[runshop_apparel_run] = ltrim(rtrim($row[runshop_apparel_run], ", "), ", ");
                      if ($row[runshop_apparel_run]) {
                          $sql = ("SELECT * FROM ".$prefix."RunshopsApparelRun WHERE apparel_run_id IN ($row[runshop_apparel_run]) ORDER BY apparel_run_name ASC");
                          $fetch = mysql_query($sql) or die(mysql_error());

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

                      if ($apparel_run_list) {echo $apparel_run_list;} else {echo "None";}
                      ?><br />
                      <strong>Tri Focused Apparel:</strong>
                      <?
                      $row[runshop_apparel_tri] = ltrim(rtrim($row[runshop_apparel_tri], ", "), ", ");
                      if ($row[runshop_apparel_tri]) {
                          $sql = ("SELECT * FROM ".$prefix."RunshopsApparelTri WHERE apparel_tri_id IN ($row[runshop_apparel_tri]) ORDER BY apparel_tri_name ASC");
                          $fetch = mysql_query($sql) or die(mysql_error());
                          $apparel_tri_list = "";
                          while ($list = mysql_fetch_array($fetch)) {
                              $apparel_tri_list  = $apparel_tri_list."$list[apparel_tri_name], ";
                          }
                          $apparel_tri_list = rtrim($apparel_tri_list, ', ');
                      }
                      if ($apparel_tri_list) {echo $apparel_tri_list;} else {echo "None";}
                      ?><br />
                      <strong>Swim Gear:</strong>
                      <?
                      $row[runshop_swimgear] = ltrim(rtrim($row[runshop_swimgear], ", "), ", ");
                      if ($row[runshop_swimgear]) {
                          $sql = ("SELECT * FROM ".$prefix."ResourceSwimgear WHERE swimgear_id IN ($row[runshop_swimgear]) ORDER BY swimgear_name ASC");
                          $fetch = mysql_query($sql) or die(mysql_error());
                          $swimgear_list = "";
                          while ($list = mysql_fetch_array($fetch)) {
                              $swimgear_list  = $swimgear_list."$list[swimgear_name], ";
                          }
                          $swimgear_list = rtrim($swimgear_list, ', ');
                      }
                      if ($swimgear_list) {echo $swimgear_list;} else {echo "None";}
                      ?><br />
                      <strong>Wetsuits:</strong>
                      <?
                      $row[runshop_wetsuits] = ltrim(rtrim($row[runshop_wetsuits], ", "), ", ");
                      if ($row[runshop_wetsuits]) {
                          $sql = ("SELECT * FROM ".$prefix."ResourceWetsuit WHERE wetsuit_id IN ($row[runshop_wetsuits]) ORDER BY wetsuit_name ASC");
                          $fetch = mysql_query($sql) or die(mysql_error());
                          $wetsuit_list = "";
                          while ($list = mysql_fetch_array($fetch)) {
                              $wetsuit_list  = $wetsuit_list."$list[wetsuit_name], ";
                          }
                          $wetsuit_list = rtrim($wetsuit_list, ', ');
                      }
                      if ($wetsuit_list) {echo $wetsuit_list;} else {echo "None";}
                      ?><br />
                    </div>
                  </div>
                  <div class="col-1-1 detail-block">
                    <h3>General Information</h3>
                    <div class="highlight-block">
                      <strong>Store Hours:</strong> <? echo stripslashes(htmlspecialchars($row[runshop_hours])); ?><br />
                      <strong>Runs &amp; Classes:</strong> <? echo stripslashes(stripslashes($row[runshop_classes])) ?><br />
                      <p><strong>Shop Info</strong> <? echo stripslashes(stripslashes($row[runshop_info])) ?></p>
                      <p><strong>Directions:</strong> <? echo stripslashes(stripslashes($row[runshop_directions])) ?></p> 
                    </div>
                  </div>
                  <div class="col-1-1">
                    <div id="map" class="map map-single" data-name="single" data-category="runshop" data-lat="<? echo $row[runshop_lat] ?>" data-lng="<? echo $row[runshop_lng] ?>">
                    </div>

                    <div class="map-description">
                      <small>
                        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."
                      </small>
                    </div>
                  </div>
                  <div class="col-1-1 detail-block">
                    <h3>Who Shops Here?</h3>
                    <div class="highlight-block">
                      <!-- BEGIN LIST OF TAGGED USERS -->
                      <? 
                      $testresults = mysql_query("SELECT runshop_shopper_tags FROM ".$prefix."Runshops WHERE runshop_id=$row[runshop_id]");
                      $testrow = mysql_fetch_array($testresults);
                      $tags = explode(",", $testrow[runshop_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: "; }
                      ?>
                      <a name="tagged"></a><? echo $phrase; ?>
                      <?
                      $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 ", "; }
                          echo "<a href=\"http://forum.slowtwitch.com/gforum.cgi?username=$temprow[user_username]&session=".$_SESSION['session_id']."&from=runshops\">$temprow[user_username]</a>";
                        }
                        $i++;
                      }
                      ?>
                      <!-- END OF LIST OF TAGGED USERS -->
                    </div>
                  </div>
                    <div class="col-1-1 detail-block">
                      <? 
                      $testresults = mysql_query("SELECT * FROM ".$prefix."RunshopsEditors WHERE runshop_id_fk=$row[runshop_id] ORDER BY edit_timestamp DESC");
                      $numcount = mysql_num_rows($testresults);
                      if($numcount == 0){ $phrase = "No updates have been made this running store yet."; }
                      else if($numcount == 1){ $phrase = "There has been 1 update to this running store:"; } 
                      else{ $phrase = "There have been $numcount updates to this running store: "; }
                      ?>
                      <div class="highlight-block">
                      <?
                      $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 />"; }
                          echo "<a href=\"http://forum.slowtwitch.com/gforum.cgi?username=$temprow[user_username]&session=".$_SESSION['session_id']."&from=runshops\">$temprow[user_username]</a> at ".date("F j, Y g:i A", $row[edit_timestamp]);
                        }
                        $i++;
                      }
                      if ($numcount <= 0) { echo "No users"; }
                      ?>
                    </div>
                  </div>
                </div>

                <div class="content-divider-bottom"></div>
                <? include ('comments_show.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>
