Subversion Repositories cheapmusic

Rev

Rev 41 | Rev 45 | 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>
43 - 88
    <link rel="stylesheet" href="css/style.min.css" integrity="sha384-6kmyirE7QUPCpJIMox63Jli9jebBd+oy6fJO/H+Poiqvlb67jPuyIDL7aoN3sYf9" 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>
43 - 93
    <script src="js/paginate.min.js" integrity="sha384-sN78hrw/H8RzeS4ete92bJj3Y0lEBeiryHisgrRm/pvsPyGLf0M14Vnm+cRxVchm" crossorigin="anonymous"></script>
35 - 94
    <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 - 95
    <!-- Global site tag (gtag.js) - Google Analytics -->
96
    <!--script async src="https://www.googletagmanager.com/gtag/js?id=UA-138428761-2"></script-->
97
    <!--script src="/js/gtag.js" integrity="sha384-ZoAmOe9K3AXr6ONEK6njtE/HMsMvyjck9EfsgXdZLG7rEiz5GqXEk3RQc2cFIRNY" crossorigin="anonymous"></script-->
98
</head>
99
<body>
100
 
101
<?php
102
 
5 - 103
initSessionVariables();
2 - 104
 
105
if ($_SERVER["REQUEST_METHOD"] == "POST") {
5 - 106
	if ($_POST["submit"] == "Search") {
35 - 107
        if (empty($_SESSION['buyer']['Zip'])) {
108
    		$zip = (empty($_POST['buyerZip']) ? "" : sanitizeInput($_POST['buyerZip']));
109
        	if (strlen($zip) == 5 && preg_match("/^[0-9 ]*$/", $zip)) {
110
	        	$_SESSION["buyer"]["Zip"] = $zip;
111
   		    } else if (strlen($zip) == 0) {
112
        		$_SESSION["buyer"]["Zip"] = "";
113
	        }
114
	    }
2 - 115
 
35 - 116
		$searchTerm = (empty($_POST['searchTerm']) ? "" : searchFriendlyString($_POST['searchTerm']));
9 - 117
		if (empty($searchTerm)) {
118
			resetSessionVars();
5 - 119
		} else {
9 - 120
			$_SESSION["searchTerm"] = $searchTerm;
2 - 121
 
5 - 122
            if (checkSearchFilters()) {
123
    			performSearch();
124
    		}
125
		}
126
	} else if ($_POST["submit"] == "Save") {
127
		$_SESSION["filterCondition"]["New"] = checkPV("filterConditionNew");
128
		$_SESSION["filterCondition"]["Used"] = checkPV("filterConditionUsed");
129
		$_SESSION["filterMediaType"]["CD"] = checkPV("filterMediaTypeCD");
130
		$_SESSION["filterMediaType"]["Record"] = checkPV("filterMediaTypeRecord");
131
		$_SESSION["filterMediaType"]["Digital"] = checkPV("filterMediaTypeDigital");
20 - 132
		$_SESSION["filterMediaType"]["Book"] = checkPV("filterMediaTypeBook");
2 - 133
 
27 - 134
		$searchTerm = searchFriendlyString($_POST['searchTerm']);
135
		if (empty($searchTerm)) {
136
			resetSessionVars();
137
		} else {
138
			$_SESSION["searchTerm"] = $searchTerm;
139
 
140
            if (checkSearchFilters()) {
141
    			performSearch();
142
    		}
5 - 143
		}
14 - 144
	} else if ($_POST["submit"] == "discogsSearch") {
145
		$searchTerm = searchFriendlyString($_POST['discogsSearchTerm']);
146
		if (empty($searchTerm)) {
147
			resetSessionVars();
148
		} else {
149
			$_SESSION["searchTerm"] = $searchTerm;
150
 
151
            if (checkSearchFilters()) {
152
    			performSearch();
153
    		}
154
		}
5 - 155
	} else if (in_array($_POST["submit"], $buttonArr)) {
156
		$_SESSION["currentView"] = $_POST["submit"];
157
		filterResults();
158
	}
159
} else if ($_SERVER["REQUEST_METHOD"] == "GET") {
160
	if (isset($_GET['z'])) {
9 - 161
    	$_SESSION["buyer"]["Zip"] = "";
5 - 162
		$zip = sanitizeInput($_GET['z']);
163
		if (strlen($zip) == 5 && preg_match("/^[0-9 ]*$/", $zip)) {
164
			$_SESSION["buyer"]["Zip"] = $zip;
165
		}
166
	}
2 - 167
 
9 - 168
    $_SESSION["searchTerm"] = "";
5 - 169
	if (isset($_GET['q'])) {
14 - 170
		$_SESSION["searchTerm"] = searchFriendlyString($_GET["q"]);
5 - 171
        if (checkSearchFilters()) {
172
    		performSearch();
173
    	}
174
	}
2 - 175
}
176
?>
177
 
14 - 178
    <form method="post" action="/index.php">
20 - 179
        <input type="hidden" name="sessionTab" value="<?php echo MySessionHandler::getSessionTab(); ?>">
14 - 180
       	<input type="hidden" name="searchTerm" value="<?php echo getSV("searchTerm") ?>">
181
       	<input type="hidden" name="buyerZip" value="<?php echo $_SESSION["buyer"]["Zip"];?>">
182
        <nav class="navbar navbar-expand-sm bg-dark navbar-dark">
35 - 183
            <div class="navbar-header">
43 - 184
                <span class="navbar-brand"><button type="submit" name="submit" value="Search" class="nav-link btn text-white">Find Cheap Music</button></span>
35 - 185
            </div>
14 - 186
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
187
                <span class="navbar-toggler-icon"></span>
188
            </button>
189
            <div class="collapse navbar-collapse" id="collapsibleNavbar">
35 - 190
                <ul class="navbar-nav mr-auto">
14 - 191
                    <li class="nav-item">
35 - 192
                        <button type="submit" name="submit" value="Search" class="nav-link btn">Home</button>
193
                    </li>
194
                    <?php if (isLoggedIn()) { ?>
195
                        <li class="nav-item">
196
                            <button type="submit" name="submit" value="coupons" class="nav-link btn">Coupons</button>
197
                        </li>
198
                    <?php } ?>
199
                    <li class="nav-item">
15 - 200
                        <button type="submit" name="submit" value="terms" class="nav-link btn">Terms of Service</button>
14 - 201
                    </li>
202
                    <li class="nav-item">
15 - 203
                        <button type="submit" name="submit" value="privacy" class="nav-link btn">Privacy Policy</button>
14 - 204
                    </li>
205
                </ul>
35 - 206
                <ul class="navbar-nav">
207
                    <?php if (!isLoggedIn()) { ?>
208
                    <li class="nav-item">
209
                        <a href="/login/index.php" class="nav-link btn">Login</a>
210
                    </li>
211
                    <?php } else { ?>
36 - 212
                        <li class="nav-item">
43 - 213
                            <img class="img-fluid hide-extra-small hide-small" src="<?php echo $userPicture ?>" alt="User Image" style="max-height:45px;">
36 - 214
                        </li>
35 - 215
                        <li class="nav-item dropdown">
216
                          <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">Account</a>
217
                          <div class="dropdown-menu dropdown-menu-right">
36 - 218
                              <button formaction="/login/account.php" type="submit" name="submit" value="account" class="dropdown-item btn">Information</button>
219
                              <button formaction="/login/editAccount.php" type="submit" name="submit" value="editAccount" class="dropdown-item btn">Edit Account</button>
220
                              <?php if (empty($_SESSION['sessData']['loginType']) || $_SESSION['sessData']['loginType'] != 'social') { ?>
221
                                  <button formaction="/login/changePassword.php" type="submit" name="submit" value="changePassword" class="dropdown-item btn">Change Password</button>
222
                              <?php } ?>
223
                              <button formaction="/login/userAccount.php?logoutSubmit=1" type="submit" name="submit" value="logout" class="dropdown-item btn">Logout</button>
35 - 224
                          </div>
225
                        </li>
226
                    <?php } ?>
227
                </ul>
14 - 228
            </div>
229
        </nav>
230
    </form>
2 - 231
 
3 - 232
    <div class="page-header bg-primary">
233
        <div class="container text-center py-3">
14 - 234
        <?php
20 - 235
            if (getPGV('submit') == "terms") {
14 - 236
                echo file_get_contents('snippets/headerTerms.txt');
20 - 237
            } else if (getPGV('submit') == "privacy") {
14 - 238
                echo file_get_contents('snippets/headerPrivacy.txt');
239
            } else {
36 - 240
                echo '<p id="textslide" class="d-none d-sm-block">FindCheapMusic.com</p>';
14 - 241
            }
242
        ?>
2 - 243
        </div>
244
    </div>
245
 
3 - 246
	<div class="container-fluid bg-primary py-3">
5 - 247
        <?php
20 - 248
        if (!in_array(getPGV('submit'), array("terms", "privacy"))) {
5 - 249
            echo $_SESSION["filterWarnings"];
14 - 250
        }
5 - 251
        ?>
20 - 252
        <form <?php if (in_array(getPGV('submit'), array("terms", "privacy"))) {echo "hidden";} ?> method="post" action="/index.php" class="form-inline"
35 - 253
            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 - 254
            <input id="sessionId" type="hidden" name="sessionId" value="<?php echo session_id(); ?>">
20 - 255
            <input id="sessionTab" type="hidden" name="sessionTab" value="<?php echo MySessionHandler::getSessionTab(); ?>">
17 - 256
        	<div class="form-group">
257
                <div class="btn-group">
258
                    <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>
259
                    <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>
260
                    <div class="btn-group">
261
                        <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>
262
                        <div class="dropdown-menu">
263
                            <div class="form-inline">
264
                                <label class="m-2">Shipping to:</label>
265
                                <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>
266
                                <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>
267
                                <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"];?>">
268
                            </div>
269
                        </div>
270
                    </div>
2 - 271
                </div>
272
        	</div>
20 - 273
        	<div class="form-group mx-1">
274
        	    <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 - 275
        	    <datalist id="searchHistory">
276
            	    <?php echo getSearchHistory(); ?>
277
            	</datalist>
278
            </div>
279
        	<div class="form-group">
280
                <button id="searchBtn" type="submit" class="btn btn-success mx-1 rounded" name="submit" value="Search">Go</button>
281
            </div>
2 - 282
        </form>
283
    </div>
284
 
5 - 285
    <?php
20 - 286
    if (getPGV('submit') == "terms") {
14 - 287
        echo file_get_contents('snippets/terms.txt');
20 - 288
    } else if (getPGV('submit') == "privacy") {
14 - 289
        echo file_get_contents('snippets/privacy.txt');
35 - 290
    } else if (getPGV('submit') == "coupons") {
41 - 291
        //get_linkshareCoupons(); // bugbug
292
        echo getCouponCodes();
38 - 293
    } else if (getPGV('submit') == "random") {
294
        findDiscogsMaster("***RANDOM***");
295
        echo $_SESSION["discogs"];
14 - 296
    } else {
9 - 297
        if ($_SESSION["lowestPrice"]["All"] > 0.00 || !empty($_SESSION["searchTerm"])) {
12 - 298
            echo $_SESSION["discogs"];
11 - 299
	        echo "<div id=\"productTable\">";
9 - 300
            echo printTableHeader();
301
            echo buildTable();
11 - 302
            echo "</div>";
38 - 303
        } else { ?>
304
    <div class="container-fluid text-center">
305
    <form method="post" action="/index.php">
306
        <input type="hidden" name="sessionTab" value="<?php echo MySessionHandler::getSessionTab(); ?>">
307
       	<input type="hidden" name="searchTerm" value="<?php echo getSV("searchTerm") ?>">
308
       	<input type="hidden" name="buyerZip" value="<?php echo $_SESSION["buyer"]["Zip"];?>">
43 - 309
        <button id="randomBtn" type="submit" class="btn btn-success mt-5 rounded" name="submit" value="random">Random Album Suggestions</button>
38 - 310
    </form>
311
    </div>
312
        <?php }
5 - 313
        echo printSearchFilterModal();
314
        echo printSearchInfoModal();
14 - 315
    }
5 - 316
    ?>
2 - 317
 
14 - 318
    <div class="modal" id="progressBarDiv">
17 - 319
        <div class="modal-dialog modal-dialog-centered">
14 - 320
            <div class="modal-content">
321
                <div class="modal-header">
15 - 322
                    <h4 id="progressBarHeader">Searching</h4>
14 - 323
                </div>
324
                <div class="modal-body">
325
                    <div class="progress">
326
                        <div id="progressBar" class="progress-bar" style="width:0%">0%</div>
327
                    </div>
328
                </div>
15 - 329
                <div class="modal-footer">
330
                    <span id="progressBarMessage"></span>
331
                </div>
14 - 332
            </div>
333
        </div>
334
    </div>
335
 
43 - 336
    <footer class="container-fluid text-center bg-primary py-5 mt-5">
20 - 337
        <?php if (!empty($_SESSION["searchTerm"])) {
338
            echo "<p>Disclaimer: As an Associate we earn from qualifying purchases.</p>";
339
        }
340
        ?>
341
        <form method="post" action="/index.php">
342
            <input type="hidden" name="sessionTab" value="<?php echo MySessionHandler::getSessionTab(); ?>">
343
       	    <input type="hidden" name="searchTerm" value="<?php echo getSV("searchTerm") ?>">
344
           	<input type="hidden" name="buyerZip" value="<?php echo $_SESSION["buyer"]["Zip"];?>">
345
            <ul class="list-inline text-center">
346
                <li class="list-inline-item">
347
                    <button class="btn btn-sm bg-light" type="submit" name="submit" value="terms">Terms of Service</button>
348
                </li>
349
                <li class="list-inline-item">
350
                    <button class="btn btn-sm bg-light" type="submit" name="submit" value="privacy">Privacy Policy</button>
351
                </li>
352
            </ul>
353
        </form>
17 - 354
        <p>Copyright &#169; <?php echo @date("Y"); ?> FindCheapMusic.com. All rights reserved.</p>
2 - 355
    </footer>
356
 
43 - 357
    <script src="js/dr.min.js" integrity="sha384-hlFytYQZX3anjWYHjNMtdlX/o6E4DVZ1Qfw0OJY8hGUElhCkrCAikEFL+RvXBPRB" crossorigin="anonymous"></script>
36 - 358
    <script>var quotes = [
38 - 359
    <?php
36 - 360
        if ($file = fopen("snippets/header.txt", "r")) {
361
            while (($line = fgets($file)) !== false) {
362
                echo "\"" . trim($line) . "\",";
363
            }
364
            fclose($file);
365
        }
366
     ?>
367
    ]; var i = 0; setInterval(function() { $("#textslide").html(quotes[i]); if (i == quotes.length) i=0; else i++; }, 5 * 1000);</script>
20 - 368
 
2 - 369
</body>
370
</html>
21 - 371
<?php MySessionHandler::commit(session_id()); ?>