<?
###########################################
#-----------Users login system------------#
###########################################
/*=========================================\
Author      :  Mohammed Ahmed(M@@king)    \\
Version     :  1.0                        \\
Date Created:  Aug 20  2005               \\
----------------------------              \\
Last Update:   August 22 2005             \\
----------------------------              \\
Country    :   Palestine                  \\
City       :   Gaza                       \\
E-mail     :   m@maaking.com              \\
MSN        :   m@maaking.com              \\
AOL-IM     :   maa2pal                    \\
WWW        :   http://www.maaking.com     \\
Mobile/SMS :   00972-599-622235           \\
                                          \\
===========================================\
------------------------------------------*/
// NEED TO CHECK AGAINST SERVER VERSION

//skip the config file if somebody call it from the browser.
session_start();

if (eregi("config.php", $_SERVER['SCRIPT_NAME'])) {
    Header("Location: index.php"); die();
}

$main_table = "Fitters";
$field_lead = "fitter_";
$site_url   = "/fitters";

include("../local/settings.php");

//added new code to fix compatibility issues.
//09-Nov-2005
$phpver = phpversion();
if ($phpver < '4.1.0') {
        $_GET = $HTTP_GET_VARS;
        $_POST = $HTTP_POST_VARS;
        $_SERVER = $HTTP_SERVER_VARS;
}
if ($phpver >= '4.0.4pl1' && strstr($_SERVER["HTTP_USER_AGENT"],'compatible')) {
        if (extension_loaded('zlib')) {
                ob_end_clean();
                ob_start('ob_gzhandler');
        }
} else if ($phpver > '4.0') {
        if (strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip')) {
                if (extension_loaded('zlib')) {
                        $do_gzip_compress = TRUE;
                        ob_start(array('ob_gzhandler',5));
                        ob_implicit_flush(0);
                        header('Content-Encoding: gzip');
                }
        }
}
$phpver = explode(".", $phpver);
$phpver = "$phpver[0]$phpver[1]";
if ($phpver >= 41) {
        $PHP_SELF = $_SERVER['PHP_SELF'];
}

if (!ini_get("register_globals")) {
        #import_request_variables('GPC');
}

$statecount = mysql_num_rows(mysql_query("SELECT * FROM gforum_Fitters WHERE fitter_valid = 1"));

$sql = "SELECT * FROM ".$prefix."FittersStates ORDER BY stateid";
$result = mysql_query($sql) OR die(mysql_error());
$state_list = array();
$state_tag_list = array();
while ($row = mysql_fetch_array($result)) {
        $state_list[$row['stateid']] = $row['statelong'];
        $state_tag_list[] = $row['statetag'];
}

function fist_equipped($fitter_id) {
        global $db,$prefix;
        
        $fist_equipped_bikes = array(10 => "guru", 13 => "retul", 12 => "purely", 2 => "exitcycling", 9 => "probikes");

        $sql = "SELECT * FROM ".$prefix."Fitters WHERE fitter_id=$fitter_id LIMIT 1";

        $sql_match = mysql_query($sql) or die(mysql_error());
        $match_row = mysql_fetch_array($sql_match);

        $match_row[fitter_certifications] = ltrim(rtrim($match_row[fitter_certifications], ", "), ", ");

        $sql = ("SELECT * FROM gforum_FittersCertifications WHERE fitter_certification_id IN ($match_row[fitter_certifications]) ORDER BY fitter_certification_name ASC");

        //echo $sql;

        $fetch = mysql_query($sql) or die(mysql_error());

        $fist_certified = false;
        $fist_equipped = false;
        $super_fist = false;
        while ($list = mysql_fetch_array($fetch)) {
                //echo ($list[fitter_certification_tag]);
                $pos = strpos($list[fitter_certification_tag], "fist");
                $sup = strpos($list[fitter_certification_tag], "super");
                if ($pos !== false) {
                        //echo ("TRUE");
                $fist_certified = true;
                if ($sup !== false) {
                                //echo ("TRUE");
                        $fist_super_cert = true;
                }
        }
        }

        if ($fist_certified === true) {
                $match_row[fitter_fitbikes] = ltrim(rtrim($match_row[fitter_fitbikes], ", "), ", ");

                $sql = ("SELECT * FROM gforum_FittersFitbikes WHERE fitter_fitbike_id IN ($match_row[fitter_fitbikes]) ORDER BY fitter_fitbike_name ASC");

                //echo $sql;

                $fetch = mysql_query($sql) or die(mysql_error());

                $fitbike_list = "";
                while ($list = mysql_fetch_array($fetch)) {
                        //echo ($list[fitter_fitbike_tag]);
                        $key = array_search($list[fitter_fitbike_tag], $fist_equipped_bikes);
                if ($key !== false){ $fist_equipped = true;}
                }
        }

        if ($fist_equipped == true && $fist_super_cert == true) { $super_fist = true; }

        if ($fist_equipped) { return("fist_equipped"); }
        elseif ($super_fist) { return("super_fist"); }
        else { return("none"); }

}

function curPageURL() {
        $isHTTPS = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on");
        $port = (isset($_SERVER["SERVER_PORT"]) && ((!$isHTTPS && $_SERVER["SERVER_PORT"] != "80") || ($isHTTPS && $_SERVER["SERVER_PORT"] != "443")));
    $port = ($port) ? ':'.$_SERVER["SERVER_PORT"] : '';
    $url = ($isHTTPS ? 'https://' : 'http://').$_SERVER["SERVER_NAME"].$port.$_SERVER["REQUEST_URI"];
    return $url; 
}

//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",
                        // New Foreign "States",
                        'UK'=>"United Kingdom",
                        'FR'=>"France",
                        'DE'=>"Germany",
                        'IT'=>"Italy",
                        'CH'=>"Switzerland",
                        'JP'=>"Japan",
                        'AU'=>"Australia",
                        'NZ'=>"New Zealand",
                        'PI'=>"Pacific Islands",
                        'HK'=>"Hong Kong");
*/
?>
