Subversion Repositories cheapmusic

Rev

Rev 70 | Rev 120 | 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
 
25
        ini_set("session.cookie_httponly", 1);
26
        ini_set("session.cookie_secure", 1);
27
        session_set_save_handler($handler, true);
28
        if (!empty($_COOKIE['PHPSESSID'])) {
29
            session_id($_COOKIE['PHPSESSID']);
30
        }
31
        @session_start();
32
 
33
        $uid = $_SESSION['sessData']['userID'];
34
 
35
        if (!empty($uid) && $uid > 0) {
36
            if ($_POST['function'] == "delete") {
37
                $rc = deleteWishlist($uid, $_POST["id"]);
65 - 38
            }
39
            else if ($_POST['function'] == "add") {
52 - 40
                $rc = addWishlist($uid, json_decode(base64_decode($_POST['wl'])));
65 - 41
            }
42
            else { /* update */
52 - 43
                $wlArr = [];
44
                $wlArr["id"] = $_POST['id'];
45
                $wlArr["artist"] = $_POST['artist'];
46
                $wlArr["title"] = $_POST['title'];
47
                $wlArr["barcode"] = $_POST['barcode'];
73 - 48
                $wlArr["cond"] = $_POST['cond'];
52 - 49
                $wlArr["format"] = $_POST['format'];
50
                $wlArr["price"] = $_POST['price'];
51
 
52
                if (empty($wlArr['id']) || $wlArr['id'] < 0) {
53
                    $msg = "Internal Error. Please reload page.";
54
                }
65 - 55
 
52 - 56
                if (empty($wlArr['artist']) && empty($wlArr['title']) && empty($wlArr['barcode'])) {
57
                    $msg = "Artist, Ttile and Barcode are empty. Please set at least one of them.";
58
                }
65 - 59
 
52 - 60
                if (!empty($wlArr['barcode'])) {
61
                    $barcodeType = clsLibGTIN::GTINCheck($wlArr['barcode'], false, 1);
62
                    if (empty($barcodeType)) {
63
                        $msg = "Invalid Barcode number. Please correct.";
64
                    }
65
                }
65 - 66
 
52 - 67
                if (!empty($wlArr['price'])) {
68
                    if (!is_numeric($wlArr['price']) || $wlArr['price'] < 0) {
69
                        $msg = "Invalid Ceiling Price. Please correct.";
70
                    }
71
                }
65 - 72
 
73 - 73
                if (empty($wlArr['cond']) || !in_array($wlArr['cond'], $condArr)) {
74
                    $msg = "Invalid Condition. Please correct.";
75
                }
76
 
52 - 77
                if (empty($wlArr['format']) || !in_array($wlArr['format'], $formatArr)) {
78
                    $msg = "Invalid Format. Please correct.";
79
                }
80
 
81
                if (empty($msg)) {
82
                    $rc = updateWishlist($uid, $wlArr);
65 - 83
                }
84
                else {
52 - 85
                    $rc = 1;
86
                }
87
            }
88
        }
89
    }
90
}
91
 
65 - 92
echo json_encode(array(
93
    "retval" => $rc,
94
    "msg" => $msg
95
));
96
exit;