<?PHP 
include("config.php");
if(!is_logged_in($user)){ 
  header('Location: '.$site_url);
  exit(); 
}

$useruid = base64_decode($_SESSION['user_id']);

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

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

?>

<? include("include_common_head.php"); ?>

<?
if($_POST[add_fitter] == true){
  include("add_X.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( $insert_success == true || $_GET[confirmed] == "yes" ) { ?>
                <h1>Thank you</h1>
                <p>Thank you. Your fitter information should be added within 24 hours. You will now be redirected back to the add page.</p>
                <META HTTP-EQUIV=Refresh CONTENT="4; URL=add.php">
                <? 
                        unset($insert_success);
                        unset($confirm_fitter);
                ?>
                <? } else if( $confirm_fitter == true ) { ?>
                <h1>Add a Fitter: Step 2 of 2</h1>
                <? } else if( ($confirm_fitter != true) || ($_POST[add_fitter] != true) ) { ?>
                <h1>Add a Fitter: Step 1 of 2</h1>
                <hr class="line" />
                <? include("../runshops/include_region_list.php"); ?>
                <? if (!$errmsg) { ?>
                <p >If you would like to add a fitter to our website, simply fill out the form below. Be sure to fill out every field. After filling out each field, click submit. <span style="color: red;">You will then be prompted to confirm your information before the information is sent to us.</span></p>
                <? } else { ?>
                <p><span style="color: red;"><? echo $errmsg; ?></span></p>
                <? } ?>
                <? } 

                // begin insert form
                if( (($_POST[add_fitter] != true) || ($errmsg) || (($confirm_fitter != true) && ($_POST[insert_fitter] != true))) && $_GET[confirmed] != "yes") { 
                ?>
                <form enctype="multipart/form-data" action="add.php" method="post">
                    <div class="dtable form">
                      <div class="drow">
                        <div class="dcell name">Fitter 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">Override Address With Lat/Lng</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input value="true" type="checkbox" name="latlng_override" <? if ($_POST[latlng_override] == true) { echo ("checked"); }?> > Check this if you know your physical address doesn't geocode properly using Google's API.<br />Then enter the desired lat/lng in the boxes below.
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Latitude</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input value="<? echo stripslashes(htmlspecialchars($_POST[lat])); ?>" type="text" name="lat" class="txt shotext"/>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Longitude</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input value="<? echo stripslashes(htmlspecialchars($_POST[lng])); ?>" type="text" name="lng" 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">Portfolio</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                          <input type="text" name="portfolio" value="<? echo stripslashes(htmlspecialchars($_POST[portfolio])); ?>" 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 (" FIT INFO ");
                        for ($i = 0; $i < 25; $i++) echo("*"); 
                        ?>
                        </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."FittersMethods ORDER BY fitter_method_name ASC") OR die(mysql_error());
                        echo("<input type=\"hidden\" name=\"methods\" value=\"0\" >");
                        while ($list = mysql_fetch_array($fetch)) {
                            echo("<span class=\"col2\"><input type=\"radio\" name=\"methods\" value=\"$list[fitter_method_id]\" ");
                            if ($list['fitter_method_id'] == $_POST[methods]){ echo "checked "; }
                            echo(">$list[fitter_method_name]</span>\n");
                        }
                        ?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Certifications</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                        <?
                        $explosion = array("");
                        if (!is_array($_POST[certifications])){ $explosion = explode(",", $_POST[certifications]); } else { $explosion = $_POST[certifications]; }

                        $fetch = mysql_query("SELECT * FROM ".$prefix."FittersCertifications ORDER BY fitter_certification_name ASC") OR die(mysql_error());

                        echo("<input type=\"hidden\" name=\"certifications[]\" value=\"0\" >");
                        while ($list = mysql_fetch_array($fetch)) {
                            echo("<span class=\"col\"><input type=\"checkbox\" name=\"certifications[]\" value=\"$list[fitter_certification_id]\" ");
                            if (in_array($list['fitter_certification_id'], $explosion)){ echo "checked "; }
                            echo(">$list[fitter_certification_name]</span>\n");
                        }
                        ?>
                        </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 ".$prefix."FittersFitbikes ORDER BY fitter_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[fitter_fitbike_id]\" ");
                            if (in_array($row[fitter_fitbike_id], $explosion)){ echo "checked "; }
                            echo(">$row[fitter_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 ".$prefix."FittersMotioncapture ORDER BY fitter_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[fitter_motioncapture_id]\"  ");
                            if (in_array($row[fitter_motioncapture_id], $explosion)){ echo "checked "; }
                            echo(">$row[fitter_motioncapture_name]</span>\n");
                        }
                        ?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Brand Friendly</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                        Brands where the fitter has a specific *verified* expertise in this brand.<br />  
                        <?
                        $explosion = array("");
                        if (!is_array($_POST[brandfriendly])){ $explosion = explode(",", $_POST[brandfriendly]); } else { $explosion = $_POST[brandfriendly]; }

                        $results = mysql_query("SELECT * FROM ".$prefix."FittersBrandFriendly ORDER BY fitter_brand_name ASC");

                        echo("<input type=\"hidden\" name=\"brandfriendly[]\" value=\"0\" >");
                        while ($row = mysql_fetch_array($results)) {
                            echo("<span class=\"col\"><input type=\"checkbox\" name=\"brandfriendly[]\" value=\"$row[fitter_brand_id]\"  ");
                            if (in_array($row[fitter_brand_id], $explosion)){ echo "checked "; }
                            echo(">$row[fitter_brand_name]</span>\n");
                        }
                        ?>
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">Cost of Fit</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
                            <input value="<? echo stripslashes(htmlspecialchars($_POST[cost])); ?>" type="text" name="cost" class="txt shotext" />
                        </div>
                      </div>
                      <div class="drow">
                        <div class="dcell name">General Info</div>
                        <div class="dcell divider"></div>
                        <div class="dcell value">
<textarea name="info" class="txt lngtext" placeholder="Please write some information about your fitting business.">
<? 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="add_fitter" value="true" />
                        </div>
                      </div>
                    </div>
                </form>
 
                <? }
                if ($confirm_fitter == true) {
                    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>
