<?PHP 

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

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


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

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

// set meta tags
$meta_keywords = "triathlon, ".$row[triclub_name].", ".$row[triclub_state]." triathlon club";
$meta_description = "Considering joining ".$row[triclub_name]."? Here is all of the information about this triathlon club.";

?>

<? 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[triclub_state]); ?>
            <? include("include_sidebar.php"); ?>
          </div>

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

              <div class="clearfix">
                <? include("include_starfunc.php"); ?>
                <h1 class="float-left">Triathlon Clubs</h1>
                <? if ($user) { ?>
                <form method="post" action="wiki_edit.php?retailer_id=<? echo $row[triclub_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("../runshops/include_region_list.php"); ?>

                <div class="details grid">
                  <div class="col-9-12">
                    <h2><? echo stripslashes(stripslashes($row[triclub_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[triclub_address])); ?><br />
                    <? if ( $row[triclub_address_two] )  { echo stripslashes(htmlspecialchars($row[triclub_address_two]) . "<br />"); } ?>
                    <? echo stripslashes(htmlspecialchars($row[triclub_city])); ?>, <? echo stripslashes(htmlspecialchars($row[triclub_state])); ?> <? echo stripslashes(htmlspecialchars($row[triclub_zip])); ?><br />
                    Phone: <? echo stripslashes(htmlspecialchars($row[triclub_phone])); ?><br />
                    Fax: <? echo stripslashes(htmlspecialchars($row[triclub_fax])); ?>
                  </div>
                  <div class="col-6-12 contact">
                    Email: <a href="mailto:<? echo $row[triclub_email]; ?>"><? echo stripslashes(htmlspecialchars($row[triclub_email])); ?></a><br />
                    <span class="briefy-b">Website: <a href="<? echo $row[triclub_website]; ?>" target="_blank"><? echo stripslashes(htmlspecialchars($row[triclub_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."TriclubsEdits WHERE triclub_id_fk = '".intval(mysql_escape_string($_GET[triclub_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>
                  <? } ?>
                  <div class="col-1-1">
                    <? include("include_buttons.php"); ?>
                  </div>
                  <div class="col-1-1 detail-block">
                    <h3>Membership</h3>
                    <div class="highlight-block">
                      <strong>Club President: </strong><? echo stripslashes(htmlspecialchars($row[triclub_president])); ?><br />
                      <strong>Board Member(s): </strong><? if ($row[triclub_board] == 0) { echo "None"; } else { echo "Yes, Their Names - "; echo stripslashes($row[triclub_board_names]); } ?> <br />
                      <strong>Total Membership: </strong><? echo $row[triclub_membership]; ?><br />
                      <strong>Club Dues: </strong><? echo stripslashes(htmlspecialchars($row[triclub_dues])); ?>
                    </div>
                  </div>
                  <div class="col-1-1 detail-block">
                    <h3>General Information</h3>
                    <div class="highlight-block">
                      <strong>Club Info: </strong><? echo stripslashes(stripslashes($row[triclub_info])) ?>
                      <br />
                      <strong>Club Sponsors: </strong><? echo stripslashes(stripslashes($row[triclub_sponsors])) ?>
                      <br />
                      <strong>Club Discounts: </strong><? echo stripslashes(stripslashes($row[triclub_discounts])) ?>
                      <br />
                      <strong>Directions to Workouts &amp; Meeting Location(s): </strong><? echo stripslashes(stripslashes($row[triclub_directions])); ?>
                      <br />
                      <strong>Club Workout Schedule: </strong><? echo stripslashes(stripslashes($row[triclub_workouts])); ?>
                      <br />
                      <strong>Club Meetings &amp; Events Schedule: </strong><? echo stripslashes(stripslashes($row[triclub_meetings])); ?>
                    </div>
                  </div>
                  <div class="col-1-1">
                    <div id="map" class="map map-single" data-name="single" data-category="triclub" data-lat="<? echo $row[triclub_lat] ?>" data-lng="<? echo $row[triclub_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>Racers</h3>
                    <div class="highlight-block">
                      <a name="racers"></a>
                      <? 
                      $testresults = mysql_query("SELECT triclub_member_tags FROM ".$prefix."Triclubs WHERE triclub_id=$row[triclub_id]");
                      $testrow = mysql_fetch_array($testresults);
                      $tags = explode(",", $testrow[triclub_member_tags]);
                      $numcount = count($tags) - 1;
                      if($numcount == 0){ $phrase = "No users have tagged this club yet."; }
                      else if($numcount == 1){ $phrase = "There is 1 user who has tagged this club:"; } 
                      else{ $phrase = "There are $numcount users who have tagged this club: "; }
                      echo $phrase; ?>
                      <?
                      //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 ", "; }
                      echo "<a href=\"http://forum.slowtwitch.com/gforum.cgi?username=$temprow[user_username]&session=".$_SESSION['session_id']."&from=triclubs\">$temprow[user_username]</a>";
                      }
                      $i++;
                      }
                      ?>
                    </div>
                  </div>
                  <div class="col-1-1 detail-block">
                    <a name="editors"></a>
                    <? 
                    $testresults = mysql_query("SELECT * FROM ".$prefix."TriclubsEditors WHERE triclub_id_fk=$row[triclub_id] ORDER BY edit_timestamp DESC");
                    $numcount = mysql_num_rows($testresults);
                    if($numcount == 0){ $phrase = "No updates have been made this club yet."; }
                    else if($numcount == 1){ $phrase = "There has been 1 update to this club:"; } 
                    else{ $phrase = "There have been $numcount updates to this club: "; }
                    ?>
                    <h3><? echo $phrase; ?></h3>
                    <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 />"; }
                            // 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"; }
                    ?>
                    </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>
