Subversion Repositories cheapmusic

Rev

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

Rev Author Line No. Line
52 - 1
<?php
65 - 2
include_once ($_SERVER['DOCUMENT_ROOT'] . '/php/dnsexit.php');
52 - 3
 
65 - 4
$rc = - 1;
52 - 5
$msg = "";
6
 
65 - 7
if (isset($_POST['function']) && in_array($_POST['function'], array(
8
    "add",
9
    "delete",
10
    "update"
11
))) {
52 - 12
    if (isset($_POST["id"])) {
65 - 13
        include_once ($_SERVER['DOCUMENT_ROOT'] . '/php/sessions_db.php');
14
        include_once ($_SERVER['DOCUMENT_ROOT'] . '/php/cryptor.php');
15
        include_once ($_SERVER['DOCUMENT_ROOT'] . '/php/wishlist.php');
16
        include_once ($_SERVER['DOCUMENT_ROOT'] . '/php/clsLibGTIN.php');
17
        include_once ($_SERVER['DOCUMENT_ROOT'] . '/php/constants.php');
52 - 18
 
70 - 19
        $configFile = parse_ini_file($_SERVER['DOCUMENT_ROOT'] . FCM_CONFIGFILE, true);
52 - 20
        $crypt = Cryptor::getInstance($configFile['cryptor']);
21
        $tmpSessionTab = (isset($_POST["sessionTab"]) && $_POST["sessionTab"] > 0 ? $_POST["sessionTab"] : null);
22
        $handler = MySessionHandler::getInstance($tmpSessionTab, $configFile['mysqli']);
23
        unset($configFile);
24
 
120 - 25
        session_set_cookie_params(604800, '/', '.findcheapmusic.com', true, true);
52 - 26
        session_set_save_handler($handler, true);
27
        if (!empty($_COOKIE['PHPSESSID'])) {
28
            session_id($_COOKIE['PHPSESSID']);
29
        }
30
        @session_start();
31
 
32
        $uid = $_SESSION['sessData']['userID'];
33
 
34
        if (!empty($uid) && $uid > 0) {
35
            if ($_POST['function'] == "delete") {
36
                $rc = deleteWishlist($uid, $_POST["id"]);
65 - 37
            }
38
            else if ($_POST['function'] == "add") {
52 - 39
                $rc = addWishlist($uid, json_decode(base64_decode($_POST['wl'])));
65 - 40
            }
41
            else { /* update */
52 - 42
                $wlArr = [];
43
                $wlArr["id"] = $_POST['id'];
44
                $wlArr["artist"] = $_POST['artist'];
45
                $wlArr["title"] = $_POST['title'];
46
                $wlArr["barcode"] = $_POST['barcode'];
73 - 47
                $wlArr["cond"] = $_POST['cond'];
52 - 48
                $wlArr["format"] = $_POST['format'];
49
                $wlArr["price"] = $_POST['price'];
50
 
51
                if (empty($wlArr['id']) || $wlArr['id'] < 0) {
52
                    $msg = "Internal Error. Please reload page.";
53
                }
65 - 54
 
52 - 55
                if (empty($wlArr['artist']) && empty($wlArr['title']) && empty($wlArr['barcode'])) {
56
                    $msg = "Artist, Ttile and Barcode are empty. Please set at least one of them.";
57
                }
65 - 58
 
52 - 59
                if (!empty($wlArr['barcode'])) {
60
                    $barcodeType = clsLibGTIN::GTINCheck($wlArr['barcode'], false, 1);
61
                    if (empty($barcodeType)) {
62
                        $msg = "Invalid Barcode number. Please correct.";
63
                    }
64
                }
65 - 65
 
52 - 66
                if (!empty($wlArr['price'])) {
67
                    if (!is_numeric($wlArr['price']) || $wlArr['price'] < 0) {
68
                        $msg = "Invalid Ceiling Price. Please correct.";
69
                    }
70
                }
65 - 71
 
73 - 72
                if (empty($wlArr['cond']) || !in_array($wlArr['cond'], $condArr)) {
73
                    $msg = "Invalid Condition. Please correct.";
74
                }
75
 
52 - 76
                if (empty($wlArr['format']) || !in_array($wlArr['format'], $formatArr)) {
77
                    $msg = "Invalid Format. Please correct.";
78
                }
79
 
80
                if (empty($msg)) {
81
                    $rc = updateWishlist($uid, $wlArr);
65 - 82
                }
83
                else {
52 - 84
                    $rc = 1;
85
                }
86
            }
87
        }
88
    }
89
}
90
 
65 - 91
echo json_encode(array(
92
    "retval" => $rc,
93
    "msg" => $msg
94
));
95
exit;