Subversion Repositories cheapmusic

Rev

Rev 28 | Rev 36 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
<?php
25 - 2
include_once($_SERVER['DOCUMENT_ROOT'] . "/php/dnsexit.php");
3
include_once($_SERVER['DOCUMENT_ROOT'] . "/php/sessions_db.php");
4
include_once($_SERVER['DOCUMENT_ROOT'] . "/php/cryptor.php");
5
include_once($_SERVER['DOCUMENT_ROOT'] . "/php/vendors.php");
35 - 6
include_once($_SERVER['DOCUMENT_ROOT'] . "/php/tools.php");
7 - 7
 
9 - 8
error_reporting(E_ALL);
9
 
35 - 10
$userData = [];
25 - 11
$configFile = parse_ini_file($_SERVER['DOCUMENT_ROOT'] . "/../MyFiles/config/cheapmusic.ini", true);
7 - 12
$crypt = Cryptor::getInstance($configFile['cryptor']);
13
$tmpSessionTab = (isset($_POST["sessionTab"]) && $_POST["sessionTab"] > 0 ? $_POST["sessionTab"] : null);
14
$handler = MySessionHandler::getInstance($tmpSessionTab, $configFile['mysqli']);
9 - 15
$vendors = Vendors::getInstance();
16
$vendors->setVendor($configFile['ebay'], Vendors::EBAY);
17
$vendors->setVendor($configFile['discogs'], Vendors::DISCOGS);
20 - 18
$vendors->setVendor($configFile['linkshare'], Vendors::LINKSHARE);
19
$vendors->setVendor($configFile['cjaffiliate'], Vendors::CJAFFILIATE);
20
$vendors->setVendor($configFile['walmart'], Vendors::WALMART);
7 - 21
unset($configFile);
22
 
2 - 23
ini_set("session.cookie_httponly", 1);
24
ini_set("session.cookie_secure", 1);
7 - 25
session_set_save_handler($handler, true);
35 - 26
if (!empty($_COOKIE['PHPSESSID'])) {
27
    session_id($_COOKIE['PHPSESSID']);
28
}
2 - 29
session_start();
35 - 30
 
31
// Check whether user ID is available in cookie
32
if(!empty($_COOKIE['rememberUserId']) && !empty($_COOKIE['hash'])){
33
    require_once 'login/includes/config.php';
34
    require_once 'login/includes/User.class.php';
35
    require_once 'login/includes/password.php';
36
    $user = new User();
37
    $conditions['where'] = array(
38
        'id' => $_COOKIE['rememberUserId']
39
    );
40
    $conditions['return_type'] = 'single';
41
    $userData = $user->getRows($conditions);
42
    if (!empty($userData) && password_verify($userData['password'] . $userData['id'], $_COOKIE['hash'])) {
43
        $_SESSION['sessData']['userLoggedIn'] = TRUE;
44
        $_SESSION['sessData']['userID'] = $_COOKIE['rememberUserId'];
45
        $_SESSION['buyer']['Zip'] = $userData['zip'];
46
        $_SESSION['buyer']['Country'] = 'United States';
47
        $_SESSION['buyer']['Currency'] = 'USD';
48
    } else {
49
        unsetSessData();
50
    }
51
// or if the user has already logged in
52
} else if (isLoggedIn()) {
53
    require_once 'login/includes/config.php';
54
    require_once 'login/includes/User.class.php';
55
    require_once 'login/includes/password.php';
56
    $user = new User();
57
    $conditions['where'] = array(
58
        'id' => $_SESSION['sessData']['userID']
59
    );
60
    $conditions['return_type'] = 'single';
61
    $userData = $user->getRows($conditions);
62
    if (!empty($userData)) {
63
        if (!empty($userData['zip'])) {
64
            $_SESSION['buyer']['Zip'] = $userData['zip'];
65
            $_SESSION['buyer']['Country'] = 'United States';
66
            $_SESSION['buyer']['Currency'] = 'USD';
67
        }
68
    } else {
69
        unsetSessData();
70
    }
71
// not logged in
72
} else {
73
    unsetSessData();
74
}
2 - 75
?>
76
<!DOCTYPE html>
77
<html lang="en-US">
78
<head>
79
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
80
    <title>Find Cheap Music...</title>
81
    <meta name="viewport" content="width=device-width, initial-scale=1">
82
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
83
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js" integrity="sha384-JUMjoW8OzDJw4oFpWIB2Bu/c6768ObEthBMVSiIx4ruBIEdyNSUQAjJNFqT5pnJ6" crossorigin="anonymous"></script>
84
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
85
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
35 - 86
    <link rel="stylesheet" href="css/style.min.css" integrity="sha384-jiMCtagtxraIvSeV5hY5ZWeVpyX1b9eY+ylxFM/lkYGu/5gUh0cbZ6xjc4EUwkCa" crossorigin="anonymous">
3 - 87
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
17 - 88
    <link rel="stylesheet" href="css/jquery.flexdatalist.min.css" integrity="sha384-IUkltzhO8hiEuEm0UJQvWrrtE1xqVHA0NbUeIY7a+zCokg7LqiDf5HSt69ru8a7R" crossorigin="anonymous">
89
    <script src="js/jquery.flexdatalist.min.js" integrity="sha384-JKZ5fd3wxuyCR/AhbpbYALE2xwlYMGYu0XpsXixX7YOni1G0is+vwTuSMuGGYhnl" crossorigin="anonymous"></script>
20 - 90
    <script src="js/input-clearer.min.js" integrity="sha384-PPIpFAWvzKO0l06o6zNV8tPFHNistosIDKHylKx5kJIM9zceSlJxAScUWQpt02xy" crossorigin="anonymous"></script>
35 - 91
    <link href="https://fonts.googleapis.com/css?family=Roboto+Slab:100,300,400,700Roboto:100,100i,300,300i,400,400i,500,500i,700,700i,900,900iSlabo+27px&subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext,vietnamese" rel="stylesheet">
2 - 92
    <!-- Global site tag (gtag.js) - Google Analytics -->
93
    <!--script async src="https://www.googletagmanager.com/gtag/js?id=UA-138428761-2"></script-->
94
    <!--script src="/js/gtag.js" integrity="sha384-ZoAmOe9K3AXr6ONEK6njtE/HMsMvyjck9EfsgXdZLG7rEiz5GqXEk3RQc2cFIRNY" crossorigin="anonymous"></script-->
95
</head>
96
<body>
97
 
98
<?php
99
 
5 - 100
initSessionVariables();
2 - 101
 
102
if ($_SERVER["REQUEST_METHOD"] == "POST") {
5 - 103
	if ($_POST["submit"] == "Search") {
35 - 104
        if (empty($_SESSION['buyer']['Zip'])) {
105
    		$zip = (empty($_POST['buyerZip']) ? "" : sanitizeInput($_POST['buyerZip']));
106
        	if (strlen($zip) == 5 && preg_match("/^[0-9 ]*$/", $zip)) {
107
	        	$_SESSION["buyer"]["Zip"] = $zip;
108
   		    } else if (strlen($zip) == 0) {
109
        		$_SESSION["buyer"]["Zip"] = "";
110
	        }
111
	    }
2 - 112
 
35 - 113
		$searchTerm = (empty($_POST['searchTerm']) ? "" : searchFriendlyString($_POST['searchTerm']));
9 - 114
		if (empty($searchTerm)) {
115
			resetSessionVars();
5 - 116
		} else {
9 - 117
			$_SESSION["searchTerm"] = $searchTerm;
2 - 118
 
5 - 119
            if (checkSearchFilters()) {
120
    			performSearch();
121
    		}
122
		}
123
	} else if ($_POST["submit"] == "Save") {
124
		$_SESSION["filterCondition"]["New"] = checkPV("filterConditionNew");
125
		$_SESSION["filterCondition"]["Used"] = checkPV("filterConditionUsed");
126
		$_SESSION["filterMediaType"]["CD"] = checkPV("filterMediaTypeCD");
127
		$_SESSION["filterMediaType"]["Record"] = checkPV("filterMediaTypeRecord");
128
		$_SESSION["filterMediaType"]["Digital"] = checkPV("filterMediaTypeDigital");
20 - 129
		$_SESSION["filterMediaType"]["Book"] = checkPV("filterMediaTypeBook");
2 - 130
 
27 - 131
		$searchTerm = searchFriendlyString($_POST['searchTerm']);
132
		if (empty($searchTerm)) {
133
			resetSessionVars();
134
		} else {
135
			$_SESSION["searchTerm"] = $searchTerm;
136
 
137
            if (checkSearchFilters()) {
138
    			performSearch();
139
    		}
5 - 140
		}
14 - 141
	} else if ($_POST["submit"] == "discogsSearch") {
142
		$searchTerm = searchFriendlyString($_POST['discogsSearchTerm']);
143
		if (empty($searchTerm)) {
144
			resetSessionVars();
145
		} else {
146
			$_SESSION["searchTerm"] = $searchTerm;
147
 
148
            if (checkSearchFilters()) {
149
    			performSearch();
150
    		}
151
		}
5 - 152
	} else if (in_array($_POST["submit"], $buttonArr)) {
153
		$_SESSION["currentView"] = $_POST["submit"];
154
		filterResults();
155
	}
156
} else if ($_SERVER["REQUEST_METHOD"] == "GET") {
157
	if (isset($_GET['z'])) {
9 - 158
    	$_SESSION["buyer"]["Zip"] = "";
5 - 159
		$zip = sanitizeInput($_GET['z']);
160
		if (strlen($zip) == 5 && preg_match("/^[0-9 ]*$/", $zip)) {
161
			$_SESSION["buyer"]["Zip"] = $zip;
162
		}
163
	}
2 - 164
 
9 - 165
    $_SESSION["searchTerm"] = "";
5 - 166
	if (isset($_GET['q'])) {
14 - 167
		$_SESSION["searchTerm"] = searchFriendlyString($_GET["q"]);
5 - 168
        if (checkSearchFilters()) {
169
    		performSearch();
170
    	}
171
	}
2 - 172
}
173
?>
174
 
14 - 175
    <form method="post" action="/index.php">
20 - 176
        <input type="hidden" name="sessionTab" value="<?php echo MySessionHandler::getSessionTab(); ?>">
14 - 177
       	<input type="hidden" name="searchTerm" value="<?php echo getSV("searchTerm") ?>">
178
       	<input type="hidden" name="buyerZip" value="<?php echo $_SESSION["buyer"]["Zip"];?>">
179
        <nav class="navbar navbar-expand-sm bg-dark navbar-dark">
35 - 180
            <div class="navbar-header">
181
                <span class="navbar-brand" href="#">Find Cheap Music:</span>
182
            </div>
14 - 183
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
184
                <span class="navbar-toggler-icon"></span>
185
            </button>
186
            <div class="collapse navbar-collapse" id="collapsibleNavbar">
35 - 187
                <ul class="navbar-nav mr-auto">
14 - 188
                    <li class="nav-item">
35 - 189
                        <button type="submit" name="submit" value="Search" class="nav-link btn">Home</button>
190
                    </li>
191
                    <?php if (isLoggedIn()) { ?>
192
                        <li class="nav-item">
193
                            <button type="submit" name="submit" value="coupons" class="nav-link btn">Coupons</button>
194
                        </li>
195
                    <?php } ?>
196
                    <li class="nav-item">
15 - 197
                        <button type="submit" name="submit" value="terms" class="nav-link btn">Terms of Service</button>
14 - 198
                    </li>
199
                    <li class="nav-item">
15 - 200
                        <button type="submit" name="submit" value="privacy" class="nav-link btn">Privacy Policy</button>
14 - 201
                    </li>
202
                </ul>
35 - 203
                <ul class="navbar-nav">
204
                    <?php if (!isLoggedIn()) { ?>
205
                    <li class="nav-item">
206
                        <a href="/login/index.php" class="nav-link btn">Login</a>
207
                    </li>
208
                    <?php } else { ?>
209
                    <?php if (!empty($userData['picture'])) { ?>
210
                    <li class="nav-item">
211
                        <img class="img-fluid" src="<?php echo $userData['picture'] ?>" alt="User Image" style="max-height:45px;">
212
                    </li>
213
                    <?php } ?>
214
                        <li class="nav-item dropdown">
215
                          <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">Account</a>
216
                          <div class="dropdown-menu dropdown-menu-right">
217
                            <a class="dropdown-item" href="/login/account.php">Information</a>
218
                            <a class="dropdown-item" href="/login/editAccount.php">Edit Account</a>
219
                            <?php if (empty($_SESSION['sessData']['loginType']) || $_SESSION['sessData']['loginType'] != 'social') { ?>
220
                                <a class="dropdown-item" href="/login/changePassword.php">Change Password</a>
221
                            <?php } ?>
222
                            <a class="dropdown-item" href="/login/userAccount.php?logoutSubmit=1">Logout</a>
223
                          </div>
224
                        </li>
225
                    <?php } ?>
226
                </ul>
14 - 227
            </div>
228
        </nav>
229
    </form>
2 - 230
 
3 - 231
    <div class="page-header bg-primary">
232
        <div class="container text-center py-3">
14 - 233
        <?php
20 - 234
            if (getPGV('submit') == "terms") {
14 - 235
                echo file_get_contents('snippets/headerTerms.txt');
20 - 236
            } else if (getPGV('submit') == "privacy") {
14 - 237
                echo file_get_contents('snippets/headerPrivacy.txt');
238
            } else {
239
                echo file_get_contents('snippets/header.txt');
240
            }
241
        ?>
2 - 242
        </div>
243
    </div>
244
 
3 - 245
	<div class="container-fluid bg-primary py-3">
5 - 246
        <?php
20 - 247
        if (!in_array(getPGV('submit'), array("terms", "privacy"))) {
5 - 248
            echo $_SESSION["filterWarnings"];
14 - 249
        }
5 - 250
        ?>
20 - 251
        <form <?php if (in_array(getPGV('submit'), array("terms", "privacy"))) {echo "hidden";} ?> method="post" action="/index.php" class="form-inline"
35 - 252
            onsubmit="if (document.getElementById('searchTerm').value != '') { progressBar('Searching for ' + document.getElementById('searchTerm').value);document.getElementById('searchBtn').innerHTML = '&lt;span class=\'spinner-border spinner-border-sm\'&gt;&lt;/span&gt; Searching, please wait...'; }">
15 - 253
            <input id="sessionId" type="hidden" name="sessionId" value="<?php echo session_id(); ?>">
20 - 254
            <input id="sessionTab" type="hidden" name="sessionTab" value="<?php echo MySessionHandler::getSessionTab(); ?>">
17 - 255
        	<div class="form-group">
256
                <div class="btn-group">
257
                    <button class="btn input-group-text mx-1 rounded" type="button" data-toggle="modal" data-target="#searchInfoModal" data-toggle2="tooltip" title="Search Tips"><i class="fas fa-info-circle" style="font-size:25px"></i></button>
258
                    <button class="btn input-group-text mx-1 rounded" type="button" data-toggle="modal" data-target="#filterModal" data-keyboard="false" data-toggle2="tooltip" title="Search Filter"><i class="fas fa-filter" style='font-size:25px'></i></button>
259
                    <div class="btn-group">
260
                        <button class="btn dropdown-toggle <?php echo ($_SESSION["buyer"]["Zip"] == '' ? "bg-warning" : "input-group-text"); ?> mx-1 rounded" type="button" data-toggle="dropdown" data-toggle2="tooltip" title="<?php echo ($_SESSION["buyer"]["Zip"] == '' ? "Please enter your postal code to get the accurate shipping cost for items listed using a shipping rate table." : "Shipping to"); ?>"><i class="fas fa-shipping-fast" style='font-size:25px'></i></button>
261
                        <div class="dropdown-menu">
262
                            <div class="form-inline">
263
                                <label class="m-2">Shipping to:</label>
264
                                <input type="text" class="form-control form-control-sm m-2" maxlength="20" style="width:12em!important" id="buyerCountry" name="buyerCountry" value="United States" readonly>
265
                                <input type="text" class="form-control form-control-sm m-2" maxlength="3" style="width:3.5em!important" id="buyerCurrency" name="buyerCurrency" value="USD" readonly>
266
                                <input type="text" class="form-control form-control-sm m-2" maxlength="5" style="width:5.5em!important" id="buyerZip" name="buyerZip" placeholder="Zip Code" value="<?php echo $_SESSION["buyer"]["Zip"];?>">
267
                            </div>
268
                        </div>
269
                    </div>
2 - 270
                </div>
271
        	</div>
20 - 272
        	<div class="form-group mx-1">
273
        	    <input id="searchTerm" list="searchHistory" name="searchTerm" type="text" class="form-control flexdatalist searchTerm-width" placeholder="Search by Barcode, Artist, Title, ..." value="<?php echo getSV("searchTerm") ?>">
17 - 274
        	    <datalist id="searchHistory">
275
            	    <?php echo getSearchHistory(); ?>
276
            	</datalist>
277
            </div>
278
        	<div class="form-group">
279
                <button id="searchBtn" type="submit" class="btn btn-success mx-1 rounded" name="submit" value="Search">Go</button>
280
            </div>
2 - 281
        </form>
282
    </div>
283
 
5 - 284
    <?php
20 - 285
    if (getPGV('submit') == "terms") {
14 - 286
        echo file_get_contents('snippets/terms.txt');
20 - 287
    } else if (getPGV('submit') == "privacy") {
14 - 288
        echo file_get_contents('snippets/privacy.txt');
35 - 289
    } else if (getPGV('submit') == "coupons") {
290
        echo file_get_contents('snippets/coupons.txt');
14 - 291
    } else {
9 - 292
        if ($_SESSION["lowestPrice"]["All"] > 0.00 || !empty($_SESSION["searchTerm"])) {
12 - 293
            echo $_SESSION["discogs"];
11 - 294
	        echo "<div id=\"productTable\">";
9 - 295
            echo printTableHeader();
296
            echo buildTable();
11 - 297
            echo "</div>";
9 - 298
        }
5 - 299
        echo printSearchFilterModal();
300
        echo printSearchInfoModal();
14 - 301
    }
5 - 302
    ?>
2 - 303
 
14 - 304
    <div class="modal" id="progressBarDiv">
17 - 305
        <div class="modal-dialog modal-dialog-centered">
14 - 306
            <div class="modal-content">
307
                <div class="modal-header">
15 - 308
                    <h4 id="progressBarHeader">Searching</h4>
14 - 309
                </div>
310
                <div class="modal-body">
311
                    <div class="progress">
312
                        <div id="progressBar" class="progress-bar" style="width:0%">0%</div>
313
                    </div>
314
                </div>
15 - 315
                <div class="modal-footer">
316
                    <span id="progressBarMessage"></span>
317
                </div>
14 - 318
            </div>
319
        </div>
320
    </div>
321
 
2 - 322
    <footer class="container-fluid text-center">
20 - 323
        <?php if (!empty($_SESSION["searchTerm"])) {
324
            echo "<p>Disclaimer: As an Associate we earn from qualifying purchases.</p>";
325
        }
326
        ?>
327
        <form method="post" action="/index.php">
328
            <input type="hidden" name="sessionTab" value="<?php echo MySessionHandler::getSessionTab(); ?>">
329
       	    <input type="hidden" name="searchTerm" value="<?php echo getSV("searchTerm") ?>">
330
           	<input type="hidden" name="buyerZip" value="<?php echo $_SESSION["buyer"]["Zip"];?>">
331
            <ul class="list-inline text-center">
332
                <li class="list-inline-item">
333
                    <button class="btn btn-sm bg-light" type="submit" name="submit" value="terms">Terms of Service</button>
334
                </li>
335
                <li class="list-inline-item">
336
                    <button class="btn btn-sm bg-light" type="submit" name="submit" value="privacy">Privacy Policy</button>
337
                </li>
338
            </ul>
339
        </form>
17 - 340
        <p>Copyright &#169; <?php echo @date("Y"); ?> FindCheapMusic.com. All rights reserved.</p>
2 - 341
    </footer>
342
 
28 - 343
    <script src="/js/dr.min.js" integrity="sha384-6b/qg037L3Pi1Zf0NJdqziqzUHz7OzA2FHa9zzmlX6hhC6LWfKtw/hDzHgLC65aV" crossorigin="anonymous"></script>
20 - 344
 
2 - 345
</body>
346
</html>
21 - 347
<?php MySessionHandler::commit(session_id()); ?>