Subversion Repositories cheapmusic

Rev

Rev 36 | Rev 39 | 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';
36 - 48
        $userPicture = getUserImage($userData);
35 - 49
    } else {
50
        unsetSessData();
51
    }
52
// or if the user has already logged in
53
} else if (isLoggedIn()) {
54
    require_once 'login/includes/config.php';
55
    require_once 'login/includes/User.class.php';
56
    require_once 'login/includes/password.php';
57
    $user = new User();
58
    $conditions['where'] = array(
59
        'id' => $_SESSION['sessData']['userID']
60
    );
61
    $conditions['return_type'] = 'single';
62
    $userData = $user->getRows($conditions);
63
    if (!empty($userData)) {
36 - 64
        $userPicture = getUserImage($userData);
35 - 65
        if (!empty($userData['zip'])) {
66
            $_SESSION['buyer']['Zip'] = $userData['zip'];
67
            $_SESSION['buyer']['Country'] = 'United States';
68
            $_SESSION['buyer']['Currency'] = 'USD';
69
        }
70
    } else {
71
        unsetSessData();
72
    }
73
// not logged in
74
} else {
75
    unsetSessData();
76
}
2 - 77
?>
78
<!DOCTYPE html>
79
<html lang="en-US">
80
<head>
81
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
82
    <title>Find Cheap Music...</title>
83
    <meta name="viewport" content="width=device-width, initial-scale=1">
84
    <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">
85
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js" integrity="sha384-JUMjoW8OzDJw4oFpWIB2Bu/c6768ObEthBMVSiIx4ruBIEdyNSUQAjJNFqT5pnJ6" crossorigin="anonymous"></script>
86
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
87
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
35 - 88
    <link rel="stylesheet" href="css/style.min.css" integrity="sha384-jiMCtagtxraIvSeV5hY5ZWeVpyX1b9eY+ylxFM/lkYGu/5gUh0cbZ6xjc4EUwkCa" crossorigin="anonymous">
3 - 89
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
17 - 90
    <link rel="stylesheet" href="css/jquery.flexdatalist.min.css" integrity="sha384-IUkltzhO8hiEuEm0UJQvWrrtE1xqVHA0NbUeIY7a+zCokg7LqiDf5HSt69ru8a7R" crossorigin="anonymous">
91
    <script src="js/jquery.flexdatalist.min.js" integrity="sha384-JKZ5fd3wxuyCR/AhbpbYALE2xwlYMGYu0XpsXixX7YOni1G0is+vwTuSMuGGYhnl" crossorigin="anonymous"></script>
20 - 92
    <script src="js/input-clearer.min.js" integrity="sha384-PPIpFAWvzKO0l06o6zNV8tPFHNistosIDKHylKx5kJIM9zceSlJxAScUWQpt02xy" crossorigin="anonymous"></script>
35 - 93
    <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 - 94
    <!-- Global site tag (gtag.js) - Google Analytics -->
95
    <!--script async src="https://www.googletagmanager.com/gtag/js?id=UA-138428761-2"></script-->
96
    <!--script src="/js/gtag.js" integrity="sha384-ZoAmOe9K3AXr6ONEK6njtE/HMsMvyjck9EfsgXdZLG7rEiz5GqXEk3RQc2cFIRNY" crossorigin="anonymous"></script-->
97
</head>
98
<body>
99
 
100
<?php
101
 
5 - 102
initSessionVariables();
2 - 103
 
104
if ($_SERVER["REQUEST_METHOD"] == "POST") {
5 - 105
	if ($_POST["submit"] == "Search") {
35 - 106
        if (empty($_SESSION['buyer']['Zip'])) {
107
    		$zip = (empty($_POST['buyerZip']) ? "" : sanitizeInput($_POST['buyerZip']));
108
        	if (strlen($zip) == 5 && preg_match("/^[0-9 ]*$/", $zip)) {
109
	        	$_SESSION["buyer"]["Zip"] = $zip;
110
   		    } else if (strlen($zip) == 0) {
111
        		$_SESSION["buyer"]["Zip"] = "";
112
	        }
113
	    }
2 - 114
 
35 - 115
		$searchTerm = (empty($_POST['searchTerm']) ? "" : searchFriendlyString($_POST['searchTerm']));
9 - 116
		if (empty($searchTerm)) {
117
			resetSessionVars();
5 - 118
		} else {
9 - 119
			$_SESSION["searchTerm"] = $searchTerm;
2 - 120
 
5 - 121
            if (checkSearchFilters()) {
122
    			performSearch();
123
    		}
124
		}
125
	} else if ($_POST["submit"] == "Save") {
126
		$_SESSION["filterCondition"]["New"] = checkPV("filterConditionNew");
127
		$_SESSION["filterCondition"]["Used"] = checkPV("filterConditionUsed");
128
		$_SESSION["filterMediaType"]["CD"] = checkPV("filterMediaTypeCD");
129
		$_SESSION["filterMediaType"]["Record"] = checkPV("filterMediaTypeRecord");
130
		$_SESSION["filterMediaType"]["Digital"] = checkPV("filterMediaTypeDigital");
20 - 131
		$_SESSION["filterMediaType"]["Book"] = checkPV("filterMediaTypeBook");
2 - 132
 
27 - 133
		$searchTerm = searchFriendlyString($_POST['searchTerm']);
134
		if (empty($searchTerm)) {
135
			resetSessionVars();
136
		} else {
137
			$_SESSION["searchTerm"] = $searchTerm;
138
 
139
            if (checkSearchFilters()) {
140
    			performSearch();
141
    		}
5 - 142
		}
14 - 143
	} else if ($_POST["submit"] == "discogsSearch") {
144
		$searchTerm = searchFriendlyString($_POST['discogsSearchTerm']);
145
		if (empty($searchTerm)) {
146
			resetSessionVars();
147
		} else {
148
			$_SESSION["searchTerm"] = $searchTerm;
149
 
150
            if (checkSearchFilters()) {
151
    			performSearch();
152
    		}
153
		}
5 - 154
	} else if (in_array($_POST["submit"], $buttonArr)) {
155
		$_SESSION["currentView"] = $_POST["submit"];
156
		filterResults();
157
	}
158
} else if ($_SERVER["REQUEST_METHOD"] == "GET") {
159
	if (isset($_GET['z'])) {
9 - 160
    	$_SESSION["buyer"]["Zip"] = "";
5 - 161
		$zip = sanitizeInput($_GET['z']);
162
		if (strlen($zip) == 5 && preg_match("/^[0-9 ]*$/", $zip)) {
163
			$_SESSION["buyer"]["Zip"] = $zip;
164
		}
165
	}
2 - 166
 
9 - 167
    $_SESSION["searchTerm"] = "";
5 - 168
	if (isset($_GET['q'])) {
14 - 169
		$_SESSION["searchTerm"] = searchFriendlyString($_GET["q"]);
5 - 170
        if (checkSearchFilters()) {
171
    		performSearch();
172
    	}
173
	}
2 - 174
}
175
?>
176
 
14 - 177
    <form method="post" action="/index.php">
20 - 178
        <input type="hidden" name="sessionTab" value="<?php echo MySessionHandler::getSessionTab(); ?>">
14 - 179
       	<input type="hidden" name="searchTerm" value="<?php echo getSV("searchTerm") ?>">
180
       	<input type="hidden" name="buyerZip" value="<?php echo $_SESSION["buyer"]["Zip"];?>">
181
        <nav class="navbar navbar-expand-sm bg-dark navbar-dark">
35 - 182
            <div class="navbar-header">
183
                <span class="navbar-brand" href="#">Find Cheap Music:</span>
184
            </div>
14 - 185
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
186
                <span class="navbar-toggler-icon"></span>
187
            </button>
188
            <div class="collapse navbar-collapse" id="collapsibleNavbar">
35 - 189
                <ul class="navbar-nav mr-auto">
14 - 190
                    <li class="nav-item">
35 - 191
                        <button type="submit" name="submit" value="Search" class="nav-link btn">Home</button>
192
                    </li>
193
                    <?php if (isLoggedIn()) { ?>
194
                        <li class="nav-item">
195
                            <button type="submit" name="submit" value="coupons" class="nav-link btn">Coupons</button>
196
                        </li>
197
                    <?php } ?>
198
                    <li class="nav-item">
15 - 199
                        <button type="submit" name="submit" value="terms" class="nav-link btn">Terms of Service</button>
14 - 200
                    </li>
201
                    <li class="nav-item">
15 - 202
                        <button type="submit" name="submit" value="privacy" class="nav-link btn">Privacy Policy</button>
14 - 203
                    </li>
204
                </ul>
35 - 205
                <ul class="navbar-nav">
206
                    <?php if (!isLoggedIn()) { ?>
207
                    <li class="nav-item">
208
                        <a href="/login/index.php" class="nav-link btn">Login</a>
209
                    </li>
210
                    <?php } else { ?>
36 - 211
                        <li class="nav-item">
212
                            <img class="img-fluid" src="<?php echo $userPicture ?>" alt="User Image" style="max-height:45px;">
213
                        </li>
35 - 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">
36 - 217
                              <button formaction="/login/account.php" type="submit" name="submit" value="account" class="dropdown-item btn">Information</button>
218
                              <button formaction="/login/editAccount.php" type="submit" name="submit" value="editAccount" class="dropdown-item btn">Edit Account</button>
219
                              <?php if (empty($_SESSION['sessData']['loginType']) || $_SESSION['sessData']['loginType'] != 'social') { ?>
220
                                  <button formaction="/login/changePassword.php" type="submit" name="submit" value="changePassword" class="dropdown-item btn">Change Password</button>
221
                              <?php } ?>
222
                              <button formaction="/login/userAccount.php?logoutSubmit=1" type="submit" name="submit" value="logout" class="dropdown-item btn">Logout</button>
35 - 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 {
36 - 239
                echo '<p id="textslide" class="d-none d-sm-block">FindCheapMusic.com</p>';
14 - 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');
38 - 291
    } else if (getPGV('submit') == "random") {
292
        findDiscogsMaster("***RANDOM***");
293
        echo $_SESSION["discogs"];
14 - 294
    } else {
9 - 295
        if ($_SESSION["lowestPrice"]["All"] > 0.00 || !empty($_SESSION["searchTerm"])) {
12 - 296
            echo $_SESSION["discogs"];
11 - 297
	        echo "<div id=\"productTable\">";
9 - 298
            echo printTableHeader();
299
            echo buildTable();
11 - 300
            echo "</div>";
38 - 301
        } else { ?>
302
    <div class="container-fluid text-center">
303
    <form method="post" action="/index.php">
304
        <input type="hidden" name="sessionTab" value="<?php echo MySessionHandler::getSessionTab(); ?>">
305
       	<input type="hidden" name="searchTerm" value="<?php echo getSV("searchTerm") ?>">
306
       	<input type="hidden" name="buyerZip" value="<?php echo $_SESSION["buyer"]["Zip"];?>">
307
                <button id="randomBtn" type="submit" class="btn btn-success m-2 rounded" name="submit" value="random">Find Random Album Suggestions</button>
308
    </form>
309
    </div>
310
        <?php }
5 - 311
        echo printSearchFilterModal();
312
        echo printSearchInfoModal();
14 - 313
    }
5 - 314
    ?>
2 - 315
 
14 - 316
    <div class="modal" id="progressBarDiv">
17 - 317
        <div class="modal-dialog modal-dialog-centered">
14 - 318
            <div class="modal-content">
319
                <div class="modal-header">
15 - 320
                    <h4 id="progressBarHeader">Searching</h4>
14 - 321
                </div>
322
                <div class="modal-body">
323
                    <div class="progress">
324
                        <div id="progressBar" class="progress-bar" style="width:0%">0%</div>
325
                    </div>
326
                </div>
15 - 327
                <div class="modal-footer">
328
                    <span id="progressBarMessage"></span>
329
                </div>
14 - 330
            </div>
331
        </div>
332
    </div>
333
 
2 - 334
    <footer class="container-fluid text-center">
20 - 335
        <?php if (!empty($_SESSION["searchTerm"])) {
336
            echo "<p>Disclaimer: As an Associate we earn from qualifying purchases.</p>";
337
        }
338
        ?>
339
        <form method="post" action="/index.php">
340
            <input type="hidden" name="sessionTab" value="<?php echo MySessionHandler::getSessionTab(); ?>">
341
       	    <input type="hidden" name="searchTerm" value="<?php echo getSV("searchTerm") ?>">
342
           	<input type="hidden" name="buyerZip" value="<?php echo $_SESSION["buyer"]["Zip"];?>">
343
            <ul class="list-inline text-center">
344
                <li class="list-inline-item">
345
                    <button class="btn btn-sm bg-light" type="submit" name="submit" value="terms">Terms of Service</button>
346
                </li>
347
                <li class="list-inline-item">
348
                    <button class="btn btn-sm bg-light" type="submit" name="submit" value="privacy">Privacy Policy</button>
349
                </li>
350
            </ul>
351
        </form>
17 - 352
        <p>Copyright &#169; <?php echo @date("Y"); ?> FindCheapMusic.com. All rights reserved.</p>
2 - 353
    </footer>
354
 
28 - 355
    <script src="/js/dr.min.js" integrity="sha384-6b/qg037L3Pi1Zf0NJdqziqzUHz7OzA2FHa9zzmlX6hhC6LWfKtw/hDzHgLC65aV" crossorigin="anonymous"></script>
36 - 356
    <script>var quotes = [
38 - 357
    <?php
36 - 358
        if ($file = fopen("snippets/header.txt", "r")) {
359
            while (($line = fgets($file)) !== false) {
360
                echo "\"" . trim($line) . "\",";
361
            }
362
            fclose($file);
363
        }
364
     ?>
365
    ]; var i = 0; setInterval(function() { $("#textslide").html(quotes[i]); if (i == quotes.length) i=0; else i++; }, 5 * 1000);</script>
20 - 366
 
2 - 367
</body>
368
</html>
21 - 369
<?php MySessionHandler::commit(session_id()); ?>