Subversion Repositories cheapmusic

Rev

Rev 153 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
include_once ($_SERVER['DOCUMENT_ROOT'] . "/php/hosting.php");
include_once ($_SERVER['DOCUMENT_ROOT'] . "/php/sessions_db.php");
include_once ($_SERVER['DOCUMENT_ROOT'] . "/php/cryptor.php");
include_once ($_SERVER['DOCUMENT_ROOT'] . "/php/vendors.php");
include_once ($_SERVER['DOCUMENT_ROOT'] . "/php/tools.php");
include_once ($_SERVER['DOCUMENT_ROOT'] . "/php/wishlist.php");
include_once ($_SERVER['DOCUMENT_ROOT'] . "/php/NonceUtil.php");

error_reporting(E_ALL);

$userData = [];
$configFile = parse_ini_file(FCM_CONFIGFILE, true);
$crypt = Cryptor::getInstance($configFile['cryptor']);
$tmpSessionTab = (!empty(getPGV("sessionTab")) && getPGV("sessionTab") > 0 ? getPGV("sessionTab"): null);
$handler = MySessionHandler::getInstance($tmpSessionTab, $configFile['mysqli']);
$vendors = Vendors::getInstance();
Vendors::setAllVendors($configFile, $vendors);
$systemConf = $configFile['system'];
unset($configFile);

session_set_cookie_params(604800, '/', '.' . $systemConf["domain_name"], true, true);
session_set_save_handler($handler, true);
if (!empty($_COOKIE['PHPSESSID'])) {
    session_id($_COOKIE['PHPSESSID']);
}
session_start();

initSessionVariables($systemConf);

include_once ($_SERVER['DOCUMENT_ROOT'] . "/php/csp.php");
//header("Link: <css/style.min.css?1591711694>; rel=preload; as=style");

// Check whether user ID is available in cookie
if (!empty($_COOKIE['rememberUserId']) && !empty($_COOKIE['hash']) && empty($_SESSION['sessData']['loginType'])) {
    require_once 'login/includes/config.php';
    require_once 'login/includes/User.class.php';
    require_once 'login/includes/password.php';
    $user = new User();
    $conditions['where'] = array(
        'id' => $_COOKIE['rememberUserId']
    );
    $conditions['return_type'] = 'single';
    $userData = $user->getRows($conditions);
    if (!empty($userData) && password_verify($userData['password'] . $userData['id'], $_COOKIE['hash'])) {
        $_SESSION['sessData']['userLoggedIn'] = true;
        $_SESSION['sessData']['userID'] = $_COOKIE['rememberUserId'];
        $_SESSION["userPicture"] = getUserImage($userData);
        $_SESSION["colorTheme"] = $userData['theme'];
        $_SESSION["currentLayout"] = ($userData['cardView'] == '1' ? 'CardView' : 'TableView');
        $_SESSION['buyer']['Zip'] = $userData['zip'];
        $_SESSION['buyer']['Country'] = 'United States';
        $_SESSION['buyer']['Currency'] = 'USD';
        $_SESSION["filterCondition"]["New"] = $userData['conditionNew'];
        $_SESSION["filterCondition"]["Used"] = $userData['conditionUsed'];
        $_SESSION["filterMediaType"]["CD"] = $userData['mediaCD'];
        $_SESSION["filterMediaType"]["Record"] = $userData['mediaRecord'];
        $_SESSION["filterMediaType"]["Digital"] = $userData['mediaDigital'];
        $_SESSION["filterMediaType"]["Book"] = $userData['mediaBook'];
    }
    else {
        unsetSessData();
    }
// or if the user has already logged in
} else if (isLoggedIn()) {
    require_once 'login/includes/config.php';
    require_once 'login/includes/User.class.php';
    require_once 'login/includes/password.php';
    $user = new User();
    $conditions['where'] = array(
        'id' => $_SESSION['sessData']['userID']
    );
    $conditions['return_type'] = 'single';
    $userData = $user->getRows($conditions);

    if (!empty($userData)) {
        $_SESSION["userPicture"] = getUserImage($userData);
        $_SESSION["colorTheme"] = $userData['theme'];
        $_SESSION["currentLayout"] = ($userData['cardView'] == '1' ? 'CardView' : 'TableView');
        $_SESSION['buyer']['Zip'] = $userData['zip'];
        $_SESSION['buyer']['Country'] = 'United States';
        $_SESSION['buyer']['Currency'] = 'USD';
        $_SESSION["filterCondition"]["New"] = $userData['conditionNew'];
        $_SESSION["filterCondition"]["Used"] = $userData['conditionUsed'];
        $_SESSION["filterMediaType"]["CD"] = $userData['mediaCD'];
        $_SESSION["filterMediaType"]["Record"] = $userData['mediaRecord'];
        $_SESSION["filterMediaType"]["Digital"] = $userData['mediaDigital'];
        $_SESSION["filterMediaType"]["Book"] = $userData['mediaBook'];
    }
    else {
        unsetSessData();
    }
// or user is not logged in
} else {
    unsetSessData();
    $_SESSION["colorTheme"] = 'default';
}

checkPriceMonitor();

echo "<!DOCTYPE html>"; // html5

$xh = new Html;
$xh->init($_SESSION["htmlIndent"]);
$xh->add_attribute("lang", "en-US");
$xh->tag('html');
$xh->tag('head');
    $xh->insert_code(headTitle(getPGV('submitBtn')));
    $xh->add_attribute('name', "keywords");
    $xh->add_attribute('content', "Cheap,Music,Album,Single,Promo,CD,Compact Disc,Vinyl,Record,Digital,Download,Sheet,Book");
    $xh->single_tag('meta');
    $xh->insert_code(metaDescription(getPGV('submitBtn')));
    $xh->insert_code(htmlHeader());
    $xh->insert_code(file_get_contents('snippets/fb_tw.txt'));
    if (!empty($_SESSION["gtmId"])) {
        $xh->add_attribute('nonce', base64_encode($_SESSION["nonce"]));
        $xh->tag('style');
           $xh->insert_code(".gtm-noscript{display:none;visibility:hidden;}");
        $xh->close(); // style
    }
    $xh->close(); // head
$xh->tag('body');

if (!empty($_SESSION["gtmId"])) {
    //$xh->add_attribute('nonce', base64_encode($_SESSION["nonce"]));
    $xh->tag('noscript');
        $xh->add_attribute("src", "https://www.googletagmanager.com/ns.html?id=" . $_SESSION["gtmId"]);
        $xh->add_attribute("height", "0");
        $xh->add_attribute("width", "0");
        $xh->add_attribute("class", "gtm-noscript");
        $xh->add_attribute("title", "Tagmanager");
        $xh->tag('iframe', "");
    $xh->close(); // noscript
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (empty($_POST["submitBtn"])) {
        $_POST["submitBtn"] = $_POST["submit"] ?? ""; // bugbug where does this come from?
    }
    if ($_POST["submitBtn"] == "Search") {
        buildDiscogsSearchTerm();

        if (!empty($_SESSION["searchTerm"])) {
            $_SESSION["mode"] = SIMPLE_SEARCH;
            performSearch();
            $xh->insert_code(jumpToSection("discogsTable"));
        }
    } else if ($_POST["submitBtn"] == "advSearch") {
        buildDiscogsSearchTerm();
        if (!empty($_SESSION["advSearch"])) {
            $_SESSION["mode"] = ADVANCED_SEARCH;
            performSearch();
            $xh->insert_code(jumpToSection("discogsTable"));
        }
    } else if ($_POST["submitBtn"] == "discogsSearch") {
        buildDiscogsSearchTerm();
        if (!empty($_SESSION["searchTerm"])) {
            $_SESSION["mode"] = ADVANCED_SEARCH;
            performSearch(true);
            $xh->insert_code(jumpToSection("productTable"));
        }
    } else if ($_POST["submitBtn"] == "unsubscribe") {
// bugbug
    }
}
else if ($_SERVER["REQUEST_METHOD"] == "GET") {
    $_GET["submitBtn"] = $_GET["submit"] ?? "";
    buildDiscogsSearchTerm();
    if (!empty($_SESSION["searchTerm"])) {
/*
        $xh->insert_code(printProgessbarModal());
        $xh->add_attribute('nonce', base64_encode($_SESSION["nonce"]));
        $xh->tag('script');
        $str = 'progressBar(' . $_SESSION["searchTerm"] . ');';
        $xh->insert_code($str);
        $xh->flush();
        $xh->close();  // script
*/
        performSearch();
    }
}

$xh->insert_code(navigationPane());

    $xh->add_attribute("class", "page-header bg-primary");
    $xh->tag('div');
        $xh->add_attribute("class", "container text-center py-3");
        $xh->tag('div');

if (getPGV('submitBtn') == "terms") {
    $xh->tag('h1', "Terms of Service");
} else if (getPGV('submitBtn') == "privacy") {
    $xh->tag('h1', "Privacy Policy");
} else if (getPGV('submitBtn') == "coupons") {
    $xh->tag('h1', "Special Offers &amp; Coupon Codes");
} else if (getPGV('submitBtn') == "wishlist") {
    $xh->tag('h1', "Wishlist");
    if (!empty($_SESSION['priceMonitor'])) {
        $xh->add_attribute("method", "post");
        $xh->add_attribute("action", "/index.php");
        $xh->tag('form');
            $xh->insert_code(inputSessionTab());
            $xh->insert_code(inputNonce());
            $xh->add_attribute("class", "btn btn-info rounded");
            $xh->add_attribute("id", "priceMonitor");
            $xh->add_attribute("type", "submit");
            $xh->add_attribute("name", "submitBtn");
            $xh->add_attribute("value", "priceMonitor");
            $xh->tag('button', "Price Monitor Results");
            if (!empty($_SESSION['priceMonitor']['newFlag']) && $_SESSION['priceMonitor']['newFlag'] === true) {
                $xh->add_attribute("class", "badge badge-pill badge-dark");
                 $xh->tag('span', "New");
            }
        $xh->close(); // form
    }
} else if (getPGV('submitBtn') == "priceMonitor") {
    $xh->tag('h1', "Price Monitor Results");
} else if (getPGV('submitBtn') == "help") {
    $xh->tag('h1', "Getting Started");
} else if (getPGV('submitBtn') == "barcode") {
    $xh->tag('h1', "Barcode Checker");
} else if (getPGV('submitBtn') == "unsubscribe") {
    $xh->tag('h1', "Unsubscribe Wishlist");
} else {
    $xh->tag('h1', "Find Cheap CDs, Records, Digital, Books and Sheets");
    $xh->add_attribute("id", "textslide");
    $xh->add_attribute("class", "d-none d-sm-block");
    $xh->tag('p', "Bookmark FindCheapMusic.com");
}

        $xh->close(); // div
    $xh->close(); // div

    $xh->insert_code(mainSearchForm());
    $xh->insert_code(mainAdvSearchForm());

if (getPGV('submitBtn') == "terms") {
    $snip = file_get_contents('snippets/terms.txt');
    $snip = str_replace("<script>", "<script nonce=\"" . base64_encode($_SESSION["nonce"]) . "\">", $snip);
    $xh->insert_code($snip);
} else if (getPGV('submitBtn') == "privacy") {
    $snip = file_get_contents('snippets/privacy.txt');
    $snip = str_replace("<script>", "<script nonce=\"" . base64_encode($_SESSION["nonce"]) . "\">", $snip);
    $xh->insert_code($snip);
} else if (getPGV('submitBtn') == "help") {
    $xh->insert_code(printHelp());
} else if (getPGV('submitBtn') == "barcode") {
    $xh->insert_code(barcodePage());
} else if (getPGV('submitBtn') == "coupons") {
    //get_linkshareCoupons(); // bugbug
    $xh->insert_code(getCouponCodes());
} else if (getPGV('submitBtn') == "wishlist") {
    $xh->insert_code(getWishlist());
} else if (getPGV('submitBtn') == "priceMonitor") {
    $xh->add_attribute("class", "container");
    $xh->add_attribute("id", "productTable");
    $xh->tag('div');
    $xh->insert_code(getPriceMonitor());
    $xh->close(); // div
} else if (getPGV('submitBtn') == "unsubscribe") {
    $xh->insert_code(unsubscribeWishlist($_GET));
} else if (getPGV('submitBtn') == "random") {
    findDiscogsMaster(true);
    if (!empty($_SESSION["discogs"])) {
        $xh->insert_code(str_replace("xxxNONCExxx", base64_encode($_SESSION["nonce"]), $_SESSION["discogs"]));
    }
} else {
    if ($_SESSION["lowestPrice"]["All"] > 0.00 || !empty($_SESSION["searchTerm"])) {
        $xh->insert_code(str_replace("xxxNONCExxx", base64_encode($_SESSION["nonce"]), $_SESSION["discogs"]));
        $xh->add_attribute("class", "container border py-2");
        $xh->add_attribute("id", "productTable");
        $xh->tag('div');
        $xh->insert_code(storeOfferHeader());
        if ($_SESSION["lowestPrice"]["All"] > 0.00) {
            $xh->insert_code(printResultHeader());
        }
        $xh->insert_code(printResult());
        $xh->close(); // div
        $xh->insert_code(productTableEventListeners());
    }
    else if (!empty($_SESSION["discogs"])) {
        $xh->insert_code(str_replace("xxxNONCExxx", base64_encode($_SESSION["nonce"]), $_SESSION["discogs"]));
    }
    else {
        $xh->insert_code(startscreen());
    }

    $xh->insert_code(printSearchInfoModal());
}

$xh->insert_code(printProgessbarModal());

$xh->insert_code(printSocialIconBar());

$xh->insert_code(htmlFooter());

$xh->insert_code(headerQuoteSlides());

$xh->insert_code(downloadAtOnload());

$xh->tag('form');
    $xh->add_attribute("type", "hidden");
    $xh->add_attribute("id", "nonce");
    $xh->add_attribute("name", "nonce");
    $xh->add_attribute("value", $_SESSION["nonce"]);
    $xh->single_tag('input');
$xh->close(); // form

$xh->close(); // body
$xh->close(); // html

$html = $xh->flush();
//error_log(print_r($html, 1));

echo $html;

MySessionHandler::commit(session_id());