<?PHP include("config.php");

if(!is_logged_in($user)){ 
  header('Location: '.$site_url);
  exit(); 
}

$username = base64_decode($_SESSION['user']);
$testresults = mysql_query("SELECT user_id FROM ".$prefix."User WHERE user_username='$username'") or die(mysql_error());
$testrow = mysql_fetch_array($testresults);
$useruid = $testrow[user_id];

// set the page title
$pagetitle = "Add a Triathlon Club";

// set meta tags
$meta_keywords = "add triclub";
$meta_description = "Do you want to include your triathlon club in our online multisport club database? Then use this form to send us your information, and we will add it to our website.";

?>

<?  
if($_POST[addclub] == 1){
  include("add_X.php");
}

//Array of states for use in the form
$state_list = array('AL'=>"Alabama",  
    'AK'=>"Alaska", 
    'AB'=>'Alberta',
    'AZ'=>"Arizona",  
    'AR'=>"Arkansas", 
    'BC'=>'British Columbia',
    'CB'=>"Caribbean",
    'CA'=>"California",  
    'CM'=>"Central America",
    'CO'=>"Colorado",  
    'CT'=>"Connecticut",
    'DE'=>"Delaware",  
    'DC'=>"District of Columbia",
    'FL'=>"Florida",  
    'GA'=>"Georgia",  
    'HI'=>"Hawaii",  
    'ID'=>"Idaho",  
    'IL'=>"Illinois",  
    'IN'=>"Indiana",  
    'IA'=>"Iowa",  
    'KS'=>"Kansas",  
    'KY'=>"Kentucky",  
    'LA'=>"Louisiana",  
    'ME'=>"Maine",  
    'MB'=>'Manitoba',
    'MD'=>"Maryland",  
    'MA'=>"Massachusetts", 
    'MX'=>"Mexico",
    'MI'=>"Michigan",  
    'MN'=>"Minnesota",  
    'MS'=>"Mississippi",  
    'MO'=>"Missouri",  
    'MT'=>"Montana",
    'NE'=>"Nebraska",
    'NV'=>"Nevada",
    'NB'=>'New Brunswick',
    'NL'=>'Newfoundland',
    'NH'=>"New Hampshire",
    'NJ'=>"New Jersey",
    'NM'=>"New Mexico",
    'NY'=>"New York",
    'NC'=>"North Carolina",
    'ND'=>"North Dakota",
    'NS'=>'Nova Scotia',
    'OH'=>"Ohio",  
    'OK'=>"Oklahoma",
    'ON'=>'Ontario',
    'OR'=>"Oregon",  
    'PA'=>"Pennsylvania",
    'PE'=>'Prince Edward Island',
    'QC'=>'Quebec',
    'RI'=>"Rhode Island", 
    'SK'=>'Saskatchewan',
    'SC'=>"South Carolina",  
    'SD'=>"South Dakota",
    'TN'=>"Tennessee",  
    'TX'=>"Texas",  
    'UT'=>"Utah",  
    'VT'=>"Vermont",  
    'VA'=>"Virginia",  
    'WA'=>"Washington",  
    'WV'=>"West Virginia",  
    'WI'=>"Wisconsin",  
    'WY'=>"Wyoming");
?>

<? 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">
                <?
                if( $_GET[confirmed] == "yes" ) { ?>
                <h1>Thank you</h1>
                <? echo "<p>Thank you. Your club should be added within 24 hours. You will now be redirected back to the add page.</p>";
                echo "<META HTTP-EQUIV=Refresh CONTENT=\"4; URL=index.php\">"; 
                } else if($confirm == 1) { ?>
                <h1>Add a Triathlon Club: Step 2 of 2</h1>
                <? } else if( ($confirm !=1) && ($_POST[confirm1] != 1)){ ?>
                <h1>Add a Triathlon Club: Step 1 of 2</h1>
                <? } else if( ($_POST[addclub] == 1) && (!$errmsg) && ($_POST[confirm1] == 1)){ ?>
                <h1>Thank you</h1>
                <? } 

                if(($confirm != 1) && ($_POST[confirm1] != 1) && $_GET[confirmed] != "yes") { ?>
                <p>If you would like to add your triathlon club to our website, simply fill out the form below. Be sure to fill out every field. After filling out each field, click submit. <font color="red">You will then be prompted to confirm your information before the information is sent to us.</font> <!--Pictures are optional, and you can upload a maximum of 3 photos. The maximum file size for each picture is 600k.--></p>
                <? } ?>

                <? include("../runshops/include_region_list.php"); ?>

                <? if( $_GET[confirmed] != "yes" && (($_POST[addclub] != 1) || ($errmsg) || (($confirm != 1) && ($_POST[confirm1] != 1))) ){ ?>
                <form enctype="multipart/form-data" action="add.php" method="post">
                    <p><font color="red"><? echo $errmsg; ?></font></p>
                    <div class="dtable form">
                      <div class="drow">
                        <div class="dcell name">Club Name</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="text" name="name" value="<? echo stripslashes($_POST[name]); ?>" class="txt lngtext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Address</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="text" name="address" value="<? echo stripslashes(htmlspecialchars($_POST[address])); ?>" class="txt lngtext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Address 2</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="text" name="address_two" value="<? echo stripslashes(htmlspecialchars($_POST[address_two])); ?>" class="txt lngtext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">City</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="text" name="city" value="<? echo stripslashes(htmlspecialchars($_POST[city])); ?>" class="txt shotext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">State</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <select name="state">
                            <option value="0">Choose a State/Province</option>
                            <?
                            foreach($state_list as $key=>$value) {
                                if(strcmp($_POST[state], $value) == 0){
                                    $str = " selected=\"selected\"";
                                }
                                echo "<option value=\"$value\"$str>$value</option>";
                                $str = "";
                            }
                            ?>
                          </select>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Zip/Postal Code</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="text" name="zip" value="<? echo stripslashes(htmlspecialchars($_POST[zip])); ?>" class="txt shotext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">E-mail</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="text" name="email" value="<? echo stripslashes(htmlspecialchars($_POST[email])); ?>" class="txt lngtext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Website</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="text" name="website" value="<? echo stripslashes(htmlspecialchars($_POST[website])); ?>" class="txt lngtext" placeholder="http://" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name"></div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                        <?
                        for ($i = 0; $i < 25; $i++) echo("*"); 
                        echo (" MEMBERSHIP ");
                        for ($i = 0; $i < 25; $i++) echo("*"); 
                        ?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">President</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input value="<? echo stripslashes(htmlspecialchars($_POST[president])); ?>" type="text" name="president" class="txt lngtext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Board Members(s)</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="radio" name="board" value="0"  <? if ($_POST[board] == 0){ echo 'checked'; } ?>>None
                            <input type="radio" name="board" value="1"  <? if ($_POST[board] == 1){ echo 'checked'; } ?>>Yes, Their Names:
                            <input value="<? echo stripslashes($_POST[board_names]); ?>" type="text" name="board_names" class="txt midtext">
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Total Membership</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input value="<? echo stripslashes(htmlspecialchars($_POST[membership])); ?>" type="text" name="membership" class="txt smltext" /> (number of members only)
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Dues</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input value="<? echo stripslashes(htmlspecialchars($_POST[dues])); ?>" type="text" name="dues" class="txt smltext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name"></div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <? 
                            for ($i = 0; $i < 63; $i++) echo("*"); 
                            ?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Club Info</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <textarea name="info" class="txt lngtext" placeholder="Please write some information about your club."><? if($_POST[info]){ echo strip_tags(stripslashes($_POST[info])); } ?></textarea>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Sponsors</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <textarea name="sponsors" class="txt lngtext" placeholder="Please write some information about your club sponsors."><? if($_POST[sponsors]) { echo strip_tags(stripslashes($_POST[sponsors])); } ?></textarea>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Discounts</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <textarea name="discounts" class="txt lngtext" placeholder="Please write some information about any discounts offered to club members."><? if($_POST[discounts]){ echo strip_tags(stripslashes($_POST[discounts])); } ?></textarea>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Directions to Workouts &amp; Meeting Location(s)</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <textarea name="directions" class="txt lngtext" placeholder="Please describe how to get to your club's meetings and workouts from your surrounding area."><? if($_POST[directions]){ echo strip_tags(stripslashes($_POST[directions])); } ?></textarea>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Workout</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <textarea name="workouts" class="txt lngtext" placeholder="Please list the schedule of your organized group workouts."><? if($_POST[workouts]){ echo strip_tags(stripslashes($_POST[workouts])); } ?></textarea>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Meetings</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <textarea name="meetings" class="txt lngtext" placeholder="Please list the schedule of any organized club meetings."><? if($_POST[meetings]){ echo strip_tags(stripslashes($_POST[meetings])); } ?></textarea>
                        </div>
                      </div>
                      <div class="drow actions">
                        <div class="dcell name"></div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="submit" value="Submit" class="btn" />
                          <input type="hidden" name="addclub" value="1" />
                        </div>
                      </div>
                    </div>
                </form>
 
                <? } else { 
                    if(($_POST[addclub] == 1) && (!$errmsg) && ($_POST[confirm1] == 1)){
                        echo "<p class=\"cont\">Thank you. Your club should be added within 24 hours. You will now be redirected back to the add page.</p>";
                        echo "<META HTTP-EQUIV=Refresh CONTENT=\"4; URL=add.php\">";
                    }

                    if($confirm == 1){
                        $confirm = 0;
                        include("include_add_confirm.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>
