Subversion Repositories cheapmusic

Rev

Rev 65 | Rev 73 | 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'];
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
 
52 - 72
                if (empty($wlArr['format']) || !in_array($wlArr['format'], $formatArr)) {
73
                    $msg = "Invalid Format. Please correct.";
74
                }
75
 
76
                if (empty($msg)) {
77
                    $rc = updateWishlist($uid, $wlArr);
65 - 78
                }
79
                else {
52 - 80
                    $rc = 1;
81
                }
82
            }
83
        }
84
    }
85
}
86
 
65 - 87
echo json_encode(array(
88
    "retval" => $rc,
89
    "msg" => $msg
90
));
91
exit;