Subversion Repositories cheapmusic

Rev

Rev 134 | Rev 141 | 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
 
138 - 26
initSessionVariables($systemConf);
113 - 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
 
134 - 36
    if ($_POST["submitBtn"] == "check") {
113 - 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
        }
134 - 48
    } else if ($_POST["submitBtn"] == "calc") {
49
        if (empty($barcode) || strlen($barcode) > 14 || 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);
134 - 57
        } else if (strlen($barcode) > 13) {
58
            myExit("Invalid Barcode", null, true);
113 - 59
        }
121 - 60
        $res = $checkDigit = clsLibGTIN::GTINCalcCheckDigit($barcode);
134 - 61
        $type = clsLibGTIN::GTINCheck($barcode . $checkDigit, false, 1);
62
        $value = clsLibGTIN::GTINCheck($barcode . $checkDigit);
63
        if (!$res || !$type) {
121 - 64
            myExit("Invalid Barcode", null, true);
65
        }
113 - 66
        $type = clsLibGTIN::GTINCheck($barcode . $checkDigit, false, 1);
67
        $value = clsLibGTIN::GTINCheck($barcode . $checkDigit);
114 - 68
        myExit("Check Digit is " . $checkDigit . "<br>" . $type . " " . $value, $value);
113 - 69
    }
70
}
71
 
72
MySessionHandler::commit(session_id());
73
exit;
74
 
114 - 75
function myExit($msg, $value, $isError = false) {
127 - 76
    $xh = new HTML;
77
    $xh->init($_SESSION["htmlIndent"]);
78
    $xh->add_attribute("class", ($isError ? 'text-danger' : 'text-success'));
79
    $xh->tag('span', $msg);
80
 
81
    $html = $xh->flush();
82
//    error_log(print_r($html, 1));
83
    echo $html;
84
 
134 - 85
    if (!$isError && !empty($value)) {
127 - 86
        $xh->add_attribute("class", "mt-3");
87
        $xh->tag('div');
88
            $xh->add_attribute("id", "barcodeSearchForm");
89
            $xh->add_attribute("method", "post");
90
            $xh->add_attribute("action", "/index.php");
91
            $xh->tag('form');
92
                $xh->insert_code(inputSessionTab());
93
                $xh->add_attribute("id", "barcodeSearchTerm");
94
                $xh->add_attribute("type", "hidden");
95
                $xh->add_attribute("name", "searchTerm");
96
                $xh->add_attribute("value", $value);
97
                $xh->single_tag('input');
98
                $xh->add_attribute("id", "barcodeSearchBtn");
99
                $xh->add_attribute("type", "submit");
100
                $xh->add_attribute("class", "btn btn-success");
134 - 101
                $xh->add_attribute("name", "submitBtn");
127 - 102
                $xh->add_attribute("value", "Search");
103
                $xh->tag('button');
104
                    $xh->add_attribute("class", "material-icons material-text");
105
                    $xh->tag('i', "search");
106
                   $xh->tag('span', " Search $value");
107
                $xh->close(); //span
108
            $xh->close(); // form
109
        $xh->close(); // div
110
 
111
        $html = $xh->flush();
112
//        error_log(print_r($html, 1));
113
        echo $html;
114
 
123 - 115
        saveBarcodeSearch($value);
114 - 116
    }
113 - 117
    MySessionHandler::commit(session_id());
118
    exit;
119
}
123 - 120
 
121
function saveBarcodeSearch($value) {
122
    $_sess_db = MySessionHandler::getDBSessionId();
123
 
124
    $access = mysqli_real_escape_string($_sess_db, time());
125
    $barcode = mysqli_real_escape_string($_sess_db, $value);
126
    $userId = (empty($_SESSION['sessData']['userID']) ? 'NULL' : $_SESSION['sessData']['userID']);
127
    $ip = inet_pton($_SERVER['REMOTE_ADDR']);
128
 
129
    $sql = "INSERT
130
            INTO barcodeChecks
131
            (sessId, access, ip, barcode, userId)
132
            VALUES  ('" . session_id() . "', '$access', '$ip', '$barcode', $userId)";
133
 
134
    if (!mysqli_query($_sess_db, $sql)) {
135
        error_log("Error: " . $sql . " | " . mysqli_error($_sess_db));
136
    }
127 - 137
 
123 - 138
}