| 113 |
- |
1 |
<?php
|
| 121 |
- |
2 |
include_once ('php/hosting.php');
|
| 113 |
- |
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');
|
| 121 |
- |
7 |
include_once ("php/NonceUtil.php");
|
| 113 |
- |
8 |
|
|
|
9 |
error_reporting(E_ALL);
|
|
|
10 |
|
|
|
11 |
$configFile = parse_ini_file($_SERVER['DOCUMENT_ROOT'] . FCM_CONFIGFILE, true);
|
|
|
12 |
$crypt = Cryptor::getInstance($configFile['cryptor']);
|
|
|
13 |
$tmpSessionTab = (isset($_POST["sessionTab"]) && $_POST["sessionTab"] > 0 ? $_POST["sessionTab"] : null);
|
|
|
14 |
$handler = MySessionHandler::getInstance($tmpSessionTab, $configFile['mysqli']);
|
| 121 |
- |
15 |
$systemConf = $configFile['system'];
|
| 113 |
- |
16 |
unset($configFile);
|
|
|
17 |
|
|
|
18 |
ini_set("session.cookie_httponly", 1);
|
|
|
19 |
ini_set("session.cookie_secure", 1);
|
|
|
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 |
}
|
|
|
32 |
|
| 113 |
- |
33 |
$barcode = getPGV("barcode");
|
|
|
34 |
|
|
|
35 |
|
|
|
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) {
|
| 113 |
- |
72 |
echo '<span class="' . ($isError ? 'text-danger' : 'text-success') . '">' . $msg . '</span>';
|
| 114 |
- |
73 |
if (!$isError) {
|
|
|
74 |
echo '<div class="mt-3">';
|
| 121 |
- |
75 |
echo '<form id="barcodeSearchForm" method="post" action="/index.php">';
|
| 116 |
- |
76 |
echo '<input type="hidden" name="sessionTab" value="' . MySessionHandler::getSessionTab() . '" />';
|
| 121 |
- |
77 |
echo '<input id="barcodeSearchTerm" type="hidden" name="searchTerm" value="' . $value . '" />';
|
|
|
78 |
echo '<button id="barcodeSearchBtn" type="submit" class="btn btn-success" name="submit" value="Search">Search ' . $value . '</button>';
|
| 114 |
- |
79 |
echo '</form>';
|
|
|
80 |
echo '</div>';
|
|
|
81 |
}
|
| 113 |
- |
82 |
MySessionHandler::commit(session_id());
|
|
|
83 |
exit;
|
|
|
84 |
}
|