Subversion Repositories cheapmusic

Rev

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

Rev Author Line No. Line
113 - 1
<?php
121 - 2
include_once ('php/hosting.php');
123 - 3
include_once ('php/constants.php');
113 - 4
include_once ('php/sessions_db.php');
5
include_once ('php/cryptor.php');
6
include_once ('php/tools.php');
7
include_once ('php/clsLibGTIN.php');
121 - 8
include_once ("php/NonceUtil.php");
113 - 9
 
10
error_reporting(E_ALL);
11
 
12
$configFile = parse_ini_file($_SERVER['DOCUMENT_ROOT'] . FCM_CONFIGFILE, true);
13
$crypt = Cryptor::getInstance($configFile['cryptor']);
14
$tmpSessionTab = (isset($_POST["sessionTab"]) && $_POST["sessionTab"] > 0 ? $_POST["sessionTab"] : null);
15
$handler = MySessionHandler::getInstance($tmpSessionTab, $configFile['mysqli']);
121 - 16
$systemConf = $configFile['system'];
113 - 17
unset($configFile);
18
 
123 - 19
session_set_cookie_params(604800, '/', '.findcheapmusic.com', true, true);
113 - 20
session_set_save_handler($handler, true);
21
if (!empty($_COOKIE['PHPSESSID'])) {
22
    session_id($_COOKIE['PHPSESSID']);
23
}
24
session_start();
25
 
26
initSessionVariables();
27
 
28
if ($_SERVER["REQUEST_METHOD"] == "POST") {
121 - 29
    if (!getPGV("nonce") || NonceUtil::check($systemConf["nonce_secret"], getPGV("nonce")) === false) {
30
        exit;
31
    }
127 - 32
 
113 - 33
    $barcode = getPGV("barcode");
34
 
127 - 35
 
113 - 36
    if ($_POST["submit"] == "check") {
37
        if (empty($barcode) || !is_numeric($barcode) || strlen($barcode) > 14 || strlen($barcode) < 8) {
114 - 38
            myExit("Invalid Barcode", null, true);
113 - 39
        }
40
 
41
        $type = clsLibGTIN::GTINCheck($barcode, false, 1);
42
        $value = clsLibGTIN::GTINCheck($barcode);
43
        if (!$type) {
114 - 44
            myExit("Barcode does not have a valid check digit", null, true);
113 - 45
        } else {
114 - 46
            myExit("Valid barcode<br>" . $type . " " . $value, $value);
113 - 47
        }
48
    } else if ($_POST["submit"] == "calc") {
49
        if (empty($barcode) || strlen($barcode) > 13 || strlen($barcode) < 8) {
114 - 50
            myExit("Invalid Barcode", null, true);
113 - 51
        }
52
 
53
        $type = clsLibGTIN::GTINCheck($barcode, false, 1);
54
        $value = clsLibGTIN::GTINCheck($barcode);
55
        if ($type) {
114 - 56
            myExit("Barcode already has a valid check digit" . "<br>" . $type . " " . $value, $value);
113 - 57
        }
121 - 58
        $res = $checkDigit = clsLibGTIN::GTINCalcCheckDigit($barcode);
59
        if (!$res) {
60
            myExit("Invalid Barcode", null, true);
61
        }
113 - 62
        $type = clsLibGTIN::GTINCheck($barcode . $checkDigit, false, 1);
63
        $value = clsLibGTIN::GTINCheck($barcode . $checkDigit);
114 - 64
        myExit("Check Digit is " . $checkDigit . "<br>" . $type . " " . $value, $value);
113 - 65
    }
66
}
67
 
68
MySessionHandler::commit(session_id());
69
exit;
70
 
114 - 71
function myExit($msg, $value, $isError = false) {
127 - 72
    $xh = new HTML;
73
    $xh->init($_SESSION["htmlIndent"]);
74
    $xh->add_attribute("class", ($isError ? 'text-danger' : 'text-success'));
75
    $xh->tag('span', $msg);
76
 
77
    $html = $xh->flush();
78
//    error_log(print_r($html, 1));
79
    echo $html;
80
 
114 - 81
    if (!$isError) {
127 - 82
        $xh->add_attribute("class", "mt-3");
83
        $xh->tag('div');
84
            $xh->add_attribute("id", "barcodeSearchForm");
85
            $xh->add_attribute("method", "post");
86
            $xh->add_attribute("action", "/index.php");
87
            $xh->tag('form');
88
                $xh->insert_code(inputSessionTab());
89
                $xh->add_attribute("id", "barcodeSearchTerm");
90
                $xh->add_attribute("type", "hidden");
91
                $xh->add_attribute("name", "searchTerm");
92
                $xh->add_attribute("value", $value);
93
                $xh->single_tag('input');
94
                $xh->add_attribute("id", "barcodeSearchBtn");
95
                $xh->add_attribute("type", "submit");
96
                $xh->add_attribute("class", "btn btn-success");
97
                $xh->add_attribute("name", "submit");
98
                $xh->add_attribute("value", "Search");
99
                $xh->tag('button');
100
                    $xh->add_attribute("class", "material-icons material-text");
101
                    $xh->tag('i', "search");
102
                   $xh->tag('span', " Search $value");
103
                $xh->close(); //span
104
            $xh->close(); // form
105
        $xh->close(); // div
106
 
107
        $html = $xh->flush();
108
//        error_log(print_r($html, 1));
109
        echo $html;
110
 
123 - 111
        saveBarcodeSearch($value);
114 - 112
    }
113 - 113
    MySessionHandler::commit(session_id());
114
    exit;
115
}
123 - 116
 
117
function saveBarcodeSearch($value) {
118
    $_sess_db = MySessionHandler::getDBSessionId();
119
 
120
    $access = mysqli_real_escape_string($_sess_db, time());
121
    $barcode = mysqli_real_escape_string($_sess_db, $value);
122
    $userId = (empty($_SESSION['sessData']['userID']) ? 'NULL' : $_SESSION['sessData']['userID']);
123
    $ip = inet_pton($_SERVER['REMOTE_ADDR']);
124
 
125
    $sql = "INSERT
126
            INTO barcodeChecks
127
            (sessId, access, ip, barcode, userId)
128
            VALUES  ('" . session_id() . "', '$access', '$ip', '$barcode', $userId)";
129
 
130
    if (!mysqli_query($_sess_db, $sql)) {
131
        error_log("Error: " . $sql . " | " . mysqli_error($_sess_db));
132
    }
127 - 133
 
123 - 134
}