Subversion Repositories cheapmusic

Rev

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

Rev Author Line No. Line
113 - 1
<?php
2
include_once ('php/dnsexit.php');
3
include_once ('php/sessions_db.php');
4
include_once ('php/cryptor.php');
5
include_once ('php/tools.php');
6
include_once ('php/clsLibGTIN.php');
7
 
8
error_reporting(E_ALL);
9
 
10
$configFile = parse_ini_file($_SERVER['DOCUMENT_ROOT'] . FCM_CONFIGFILE, true);
11
$crypt = Cryptor::getInstance($configFile['cryptor']);
12
$tmpSessionTab = (isset($_POST["sessionTab"]) && $_POST["sessionTab"] > 0 ? $_POST["sessionTab"] : null);
13
$handler = MySessionHandler::getInstance($tmpSessionTab, $configFile['mysqli']);
14
unset($configFile);
15
 
16
ini_set("session.cookie_httponly", 1);
17
ini_set("session.cookie_secure", 1);
18
session_set_save_handler($handler, true);
19
if (!empty($_COOKIE['PHPSESSID'])) {
20
    session_id($_COOKIE['PHPSESSID']);
21
}
22
session_start();
23
 
24
initSessionVariables();
25
 
26
if ($_SERVER["REQUEST_METHOD"] == "POST") {
27
    $barcode = getPGV("barcode");
28
 
29
 
30
    if ($_POST["submit"] == "check") {
31
        if (empty($barcode) || !is_numeric($barcode) || strlen($barcode) > 14 || strlen($barcode) < 8) {
114 - 32
            myExit("Invalid Barcode", null, true);
113 - 33
        }
34
 
35
        $type = clsLibGTIN::GTINCheck($barcode, false, 1);
36
        $value = clsLibGTIN::GTINCheck($barcode);
37
        if (!$type) {
114 - 38
            myExit("Barcode does not have a valid check digit", null, true);
113 - 39
        } else {
114 - 40
            myExit("Valid barcode<br>" . $type . " " . $value, $value);
113 - 41
        }
42
    } else if ($_POST["submit"] == "calc") {
43
        if (empty($barcode) || strlen($barcode) > 13 || strlen($barcode) < 8) {
114 - 44
            myExit("Invalid Barcode", null, true);
113 - 45
        }
46
 
47
        $type = clsLibGTIN::GTINCheck($barcode, false, 1);
48
        $value = clsLibGTIN::GTINCheck($barcode);
49
        if ($type) {
114 - 50
            myExit("Barcode already has a valid check digit" . "<br>" . $type . " " . $value, $value);
113 - 51
        }
52
        $checkDigit = clsLibGTIN::GTINCalcCheckDigit($barcode);
53
        $type = clsLibGTIN::GTINCheck($barcode . $checkDigit, false, 1);
54
        $value = clsLibGTIN::GTINCheck($barcode . $checkDigit);
114 - 55
        myExit("Check Digit is " . $checkDigit . "<br>" . $type . " " . $value, $value);
113 - 56
    }
57
}
58
 
59
MySessionHandler::commit(session_id());
60
exit;
61
 
114 - 62
function myExit($msg, $value, $isError = false) {
113 - 63
    echo '<span class="' . ($isError ? 'text-danger' : 'text-success') . '">' . $msg . '</span>';
114 - 64
    if (!$isError) {
65
        echo '<div class="mt-3">';
66
        echo '<form method="post" action="/index.php" onsubmit="progressBar(\'Searching for:<br><br><strong>' . $value . '</strong>\');">';
67
        echo '<input type="hidden" name="sessionTab" value="' . MySessionHandler::getSessionTab() . '">';
68
        echo '<input type="hidden" name="searchTerm" value="' . $value . '">';
69
        echo '<button type="submit" class="btn btn-success" name="submit" value="Search">Search ' . $value . '</button>';
70
        echo '</form>';
71
        echo '</div>';
72
    }
113 - 73
    MySessionHandler::commit(session_id());
74
    exit;
75
}