<?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 Shop";

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

?>

<?  

if($_POST[addshop] == 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>
                <p class="cont">Thank you. Your shop should be added within 24 hours. You will now be redirected back to the homepage page.</p>
                <meta HTTP-EQUIV="Refresh" CONTENT="4; URL=index.php" /> 
                <? } else if ( $confirm == 1 ) { ?>
                <h1><strong>Add a Shop: Step 2 of 2</h1>
                <? } else if ( ($confirm !=1) && ($_POST[confirm1] != 1)) { ?>
                <h1>Add a Shop: Step 1 of 2</h1>
                <? } else if ( ($_POST[addshop] == 1) && (!$errmsg) && ($_POST[confirm1] == 1)) { ?>
                <h1>Thank you</h1>
                <? } ?> 
                <hr class="line" />
                <? include("../runshops/include_region_list.php"); ?>
                <? if (($confirm != 1) && ($_POST[confirm1] != 1) && $_GET[confirmed] != "yes") { ?>
                  <p class="cont">If you would like to add your triathlon/bike shop 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></p>
                <? } ?>

                <? if( $_GET[confirmed] != "yes" && (($_POST[addshop] != 1) || ($errmsg) || (($confirm != 1) && ($_POST[confirm1] != 1))) ){ ?>
                <form enctype="multipart/form-data" action="add.php" method="post">
                    <p class="cont"><font color="red"><? echo $errmsg; ?></font></p>
                    <div class="dtable form">
                      <div class="drow">
                        <div class="dcell name">Shop 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">Phone</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="text" name="phone" value="<? echo stripslashes(htmlspecialchars($_POST[phone])); ?>" class="txt shotext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Fax</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="text" name="fax" value="<? echo stripslashes(htmlspecialchars($_POST[fax])); ?>" 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">Online Shopping Cart</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <select name="cart">
                            <option value="0" <? if ($_POST[cart] == 0) { echo "selected='selected'"; } ?>>No</option>
                            <option value="1" <? if ($_POST[cart] == 1) { echo "selected='selected'"; } ?>>Yes</option>
                          </select> (Must be a fully functional ecommerce system)
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Spoke Alliance Member</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <select name="spoke">
                            <option value="0" <? if ($_POST[spoke] == 0) { echo "selected='selected'"; } ?>>No</option>
                            <option value="1" <? if ($_POST[spoke] == 1) { echo "selected='selected'"; } ?>>Yes</option>
                          </select>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name"></div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <? 
                            for ($i = 0; $i < 15; $i++) echo("*"); 
                            echo (" PRODUCT DELIVERY CHANNELS ");
                            for ($i = 0; $i < 15; $i++) echo("*"); 
                            ?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">We ship mail-order via</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="checkbox" name="mailorder_ecommerce" value="1"  <? if ($_POST[mailorder_ecommerce] == 1){ echo 'checked'; } ?>>e-commerce site<br />
                            <input type="checkbox" name="mailorder_phone" value="1"  <? if ($_POST[mailorder_phone] == 1){ echo 'checked'; } ?>>phone
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">We offer local home/work delivery, transacting via</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="checkbox" name="local_ecommerce" value="1"  <? if ($_POST[local_ecommerce] == 1){ echo 'checked'; } ?>>e-commerce site<br />
                            <input type="checkbox" name="local_phone" value="1"  <? if ($_POST[local_phone] == 1){ echo 'checked'; } ?>>phone
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">You may order in advance, and pick up, transacting via</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="checkbox" name="pickup_ecommerce" value="1"  <? if ($_POST[pickup_ecommerce] == 1){ echo 'checked'; } ?>>e-commerce site<br />
                            <input type="checkbox" name="pickup_phone" value="1"  <? if ($_POST[pickup_phone] == 1){ echo 'checked'; } ?>>phone
                        </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 (" BIKE FIT ");
                            for ($i = 0; $i < 25; $i++) echo("*"); 
                            ?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Key Tri-Specific Contact(s)</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="radio" name="contact" value="0"  <? if ($_POST[contact] == 0){ echo 'checked'; } ?>>None<br />
                            <input type="radio" name="contact" value="1"  <? if ($_POST[contact] == 1){ echo 'checked'; } ?>>Yes, Their Names:
                            <input value="<? echo stripslashes($_POST[contact_names]); ?>" type="text" name="contact_names" class="txt shotext"/>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">F.I.S.T. Tri Fitter(s)</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="radio" name="fist" value="0" <? if ($_POST[fist] == 0){ echo 'checked'; } ?>>None<br />
                            <input type="radio" name="fist" value="1"  <? if ($_POST[fist] == 1){ echo 'checked'; } ?>>Yes, Their Names:
                            <input value="<? echo stripslashes($_POST[fist_names]); ?>" type="text" name="fist_names" class="txt shotext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">F.I.S.T. Road Fitter(s)</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="radio" name="fist_road" value="0" <? if ($_POST[fist_road] == 0){ echo 'checked'; } ?>>None<br />
                            <input type="radio" name="fist_road" value="1"  <? if ($_POST[fist_road] == 1){ echo 'checked'; } ?>>Yes, Their Names:
                            <input value="<? echo stripslashes($_POST[fist_road_names]); ?>" type="text" name="fist_road_names" class="txt shotext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">F.I.S.T. Advanced Fitter(s)</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="radio" name="fist_advanced" value="0" <? if ($_POST[fist_advanced] == 0){ echo 'checked'; } ?>>None<br />
                            <input type="radio" name="fist_advanced" value="1"  <? if ($_POST[fist_advanced] == 1){ echo 'checked'; } ?>>Yes, Their Names:
                            <input value="<? echo stripslashes($_POST[fist_advanced_names]); ?>" type="text" name="fist_advanced_names" class="txt shotext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">BFACT Score</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input value="<? echo stripslashes(htmlspecialchars($_POST[bfact])); ?>" type="text" name="bfact" class="txt shotext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">BikeFit, BodyGeometry, Retul, Serotta, or Trek Fitter(s)</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="radio" name="serotta" value="0"  <? if ($_POST[serotta] == 0){ echo 'checked'; } ?>>None<br />
                            <input type="radio" name="serotta" value="1"  <? if ($_POST[serotta] == 1){ echo 'checked'; } ?>>Yes, Their Names: 
                            <input value="<? echo stripslashes($_POST[serotta_names]); ?>" type="text" name="serotta_names" class="txt shotext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Default Tri-Fit Methodology</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
<?
$fetch = mysql_query("SELECT * FROM ".$prefix."RetailersMethods ORDER BY retailer_method_name ASC") OR die(mysql_error());
echo("<input type=\"hidden\" name=\"methods\" value=\"0\" >");
while ($list = mysql_fetch_array($fetch)) {
        echo("<span class=\"cols\"><input type=\"radio\" name=\"methods\" value=\"$list[retailer_method_id]\" ");
        if ($list['retailer_method_id'] == $_POST[methods]){ echo "checked "; }
        echo(">$list[retailer_method_name]</span>\n");
        $i++;
}
?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Fit Bikes</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
<?
$explosion = array("");
if (!is_array($_POST[fitbikes])){ $explosion = explode(",", $_POST[fitbikes]); } else { $explosion = $_POST[fitbikes]; }

$results = mysql_query("SELECT * FROM gforum_RetailersFitbikes ORDER BY retailers_fitbike_name ASC");

echo("<input type=\"hidden\" name=\"fitbikes[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    echo("<span class=\"col\"><input type=\"checkbox\" name=\"fitbikes[]\" value=\"$row[retailers_fitbike_id]\" ");
    if (in_array($row[retailers_fitbike_id], $explosion)){ echo "checked "; }
    echo(">$row[retailers_fitbike_name]</span>\n");
}
?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Motion-Capture Systems</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
<?
$explosion = array("");
if (!is_array($_POST[motioncapture])){ $explosion = explode(",", $_POST[motioncapture]); } else { $explosion = $_POST[motioncapture]; }
$results = mysql_query("SELECT * FROM gforum_RetailersMotioncapture ORDER BY retailers_motioncapture_name ASC");
echo("<input type=\"hidden\" name=\"motioncapture[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    echo("<span class=\"col\"><input type=\"checkbox\" name=\"motioncapture[]\" value=\"$row[retailers_motioncapture_id]\"  ");
    if (in_array($row[retailers_motioncapture_id], $explosion)){ echo "checked "; }
    echo(">$row[retailers_motioncapture_name]</span>\n");
}
?>
                        </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 (" BRANDS ");
                            for ($i = 0; $i < 25; $i++) echo("*"); 
                            ?>
                            <p class="note">IMPORTANT: Tri and road bike brands of which you'll have six or more sitting on the floor during the season.</p>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Wetsuits</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
<?
$explosion = array("");
if (!is_array($_POST[wetsuits])){ $explosion = explode(",", $_POST[wetsuits]); } else { $explosion = $_POST[wetsuits]; }
$results = mysql_query("SELECT * FROM gforum_RetailersWetsuits ORDER BY retailers_wetsuit_name ASC");
echo("<input type=\"hidden\" name=\"wetsuits[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    echo("<span class=\"col\"><input type=\"checkbox\" name=\"wetsuits[]\" value=\"$row[retailers_wetsuit_id]\"  ");
    if (in_array($row[retailers_wetsuit_id], $explosion)){ echo "checked "; }
    echo(">$row[retailers_wetsuit_name]</span>\n");
}
?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Bikes</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
<?
$explosion = array("");
if (!is_array($_POST[bikes])){ $explosion = explode(",", $_POST[bikes]); } else { $explosion = $_POST[bikes]; }
$results = mysql_query("SELECT * FROM gforum_RetailersBikes ORDER BY retailers_bike_name ASC");
echo("<input type=\"hidden\" name=\"bikes[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    echo("<span class=\"col\"><input type=\"checkbox\" name=\"bikes[]\" value=\"$row[retailers_bike_id]\"  ");
    if (in_array($row[retailers_bike_id], $explosion)){ echo "checked "; }
    echo(">$row[retailers_bike_name]</span>\n");
}
?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Custom Frames</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <p class="note">IMPORTANT: Custom brands of which you'll sell six or more in a 12 month period.</p>
<?
$explosion = array("");
if (!is_array($_POST[customs])){ $explosion = explode(",", $_POST[customs]); } else { $explosion = $_POST[customs]; }
$results = mysql_query("SELECT * FROM gforum_RetailersCustoms ORDER BY retailers_custom_name ASC");
echo("<input type=\"hidden\" name=\"customs[]\" value=\"0\" >");
while ($row = mysql_fetch_array($results)) {
    echo("<span class=\"col\"><input type=\"checkbox\" name=\"customs[]\" value=\"$row[retailers_custom_id]\"  ");
    if (in_array($row[retailers_custom_id], $explosion)){ echo "checked "; }
    echo(">$row[retailers_custom_name]</span>\n");
}
?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Shop Hours</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input value="<? echo stripslashes(htmlspecialchars($_POST[hours])); ?>" type="text" name="hours" class="txt lngtext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Barnett-Trained Mechanic(s)</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="radio" name="barnett" value="0"  <? if ($_POST[barnett] == 0){ echo 'checked'; } ?>>None<br />
                            <input type="radio" name="barnett" value="1"  <? if ($_POST[barnett] == 1){ echo 'checked'; } ?>>Yes, Their Names: 
                            <input value="<? echo stripslashes($_POST[barnett_names]); ?>" type="text" name="barnett_names" class="txt shotext">
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">United Bicycle Institute-Trained Mechanic(s)</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input type="radio" name="ubi" value="0"  <? if ($_POST[ubi] == 0){ echo 'checked'; } ?>>None<br />
                            <input type="radio" name="ubi" value="1"  <? if ($_POST[ubi] == 1){ echo 'checked'; } ?>>Yes, Their Names: 
                            <input value="<? echo stripslashes($_POST[ubi_names]); ?>" type="text" name="ubi_names" class="txt shotext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Shop Info</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
<textarea name="info" class="txt lngtext" placeholder="Please write some information about your shop.">
<? if($_POST[info]){ echo strip_tags(stripslashes($_POST[info])); } ?>
</textarea>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Directions</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
<textarea name="directions" class="txt lngtext" placeholder="Please describe how to get to your shop from your surrounding area.">
<? if($_POST[directions]) { echo strip_tags(stripslashes($_POST[directions])); } ?>
</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="addshop" value="1" />
                        </div>
                      </div>
                    </div>
                </form>

                <? } else{ 
                    if(($_POST[addshop] == 1) && (!$errmsg) && ($_POST[confirm1] == 1)){
                       echo "<p class=\"cont\">Thank you. Your shop 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\">";
                    }

                    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>
