Subversion Repositories cheapmusic

Rev

Rev 65 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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