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 |
|
153 |
- |
12 |
$configFile = parse_ini_file(FCM_CONFIGFILE, true);
|
113 |
- |
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) {
|
147 |
- |
38 |
myExit("Invalid Barcode", null, null, true);
|
113 |
- |
39 |
}
|
|
|
40 |
|
|
|
41 |
$type = clsLibGTIN::GTINCheck($barcode, false, 1);
|
|
|
42 |
$value = clsLibGTIN::GTINCheck($barcode);
|
|
|
43 |
if (!$type) {
|
147 |
- |
44 |
myExit("Barcode does not have a valid check digit", null, null, true);
|
113 |
- |
45 |
} else {
|
147 |
- |
46 |
myExit("Valid barcode<br>" . $type . " " . $value, $value, $type);
|
113 |
- |
47 |
}
|
134 |
- |
48 |
} else if ($_POST["submitBtn"] == "calc") {
|
|
|
49 |
if (empty($barcode) || strlen($barcode) > 14 || strlen($barcode) < 8) {
|
147 |
- |
50 |
myExit("Invalid Barcode", null, null, true);
|
113 |
- |
51 |
}
|
|
|
52 |
|
|
|
53 |
$type = clsLibGTIN::GTINCheck($barcode, false, 1);
|
|
|
54 |
$value = clsLibGTIN::GTINCheck($barcode);
|
|
|
55 |
if ($type) {
|
147 |
- |
56 |
myExit("Barcode already has a valid check digit" . "<br>" . $type . " " . $value, $value, $type);
|
134 |
- |
57 |
} else if (strlen($barcode) > 13) {
|
147 |
- |
58 |
myExit("Invalid Barcode", null, 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) {
|
147 |
- |
64 |
myExit("Invalid Barcode", null, null, true);
|
121 |
- |
65 |
}
|
113 |
- |
66 |
$type = clsLibGTIN::GTINCheck($barcode . $checkDigit, false, 1);
|
|
|
67 |
$value = clsLibGTIN::GTINCheck($barcode . $checkDigit);
|
147 |
- |
68 |
myExit("Check Digit is " . $checkDigit . "<br>" . $type . " " . $value, $value, $type);
|
113 |
- |
69 |
}
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
MySessionHandler::commit(session_id());
|
|
|
73 |
exit;
|
|
|
74 |
|
147 |
- |
75 |
function myExit($msg, $value, $type = null, $isError = false) {
|
127 |
- |
76 |
$xh = new HTML;
|
|
|
77 |
$xh->init($_SESSION["htmlIndent"]);
|
141 |
- |
78 |
$xh->add_attribute("class", ($isError ? "alert alert-danger" : "text-success"));
|
127 |
- |
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)) {
|
147 |
- |
86 |
$xh->tag('div');
|
|
|
87 |
$xh->insert_code(getBarcodeImage($value, $type));
|
|
|
88 |
$xh->close(); // div
|
127 |
- |
89 |
$xh->add_attribute("class", "mt-3");
|
|
|
90 |
$xh->tag('div');
|
|
|
91 |
$xh->add_attribute("id", "barcodeSearchForm");
|
|
|
92 |
$xh->add_attribute("method", "post");
|
|
|
93 |
$xh->add_attribute("action", "/index.php");
|
|
|
94 |
$xh->tag('form');
|
|
|
95 |
$xh->insert_code(inputSessionTab());
|
|
|
96 |
$xh->add_attribute("id", "barcodeSearchTerm");
|
|
|
97 |
$xh->add_attribute("type", "hidden");
|
|
|
98 |
$xh->add_attribute("name", "searchTerm");
|
|
|
99 |
$xh->add_attribute("value", $value);
|
|
|
100 |
$xh->single_tag('input');
|
|
|
101 |
$xh->add_attribute("id", "barcodeSearchBtn");
|
|
|
102 |
$xh->add_attribute("type", "submit");
|
|
|
103 |
$xh->add_attribute("class", "btn btn-success");
|
134 |
- |
104 |
$xh->add_attribute("name", "submitBtn");
|
127 |
- |
105 |
$xh->add_attribute("value", "Search");
|
|
|
106 |
$xh->tag('button');
|
|
|
107 |
$xh->add_attribute("class", "material-icons material-text");
|
|
|
108 |
$xh->tag('i', "search");
|
147 |
- |
109 |
$xh->tag('span', " Search");
|
127 |
- |
110 |
$xh->close(); //span
|
|
|
111 |
$xh->close(); // form
|
|
|
112 |
$xh->close(); // div
|
|
|
113 |
|
|
|
114 |
$html = $xh->flush();
|
|
|
115 |
// error_log(print_r($html, 1));
|
|
|
116 |
echo $html;
|
|
|
117 |
|
123 |
- |
118 |
saveBarcodeSearch($value);
|
114 |
- |
119 |
}
|
113 |
- |
120 |
MySessionHandler::commit(session_id());
|
|
|
121 |
exit;
|
|
|
122 |
}
|
123 |
- |
123 |
|
|
|
124 |
function saveBarcodeSearch($value) {
|
|
|
125 |
$_sess_db = MySessionHandler::getDBSessionId();
|
|
|
126 |
|
|
|
127 |
$access = mysqli_real_escape_string($_sess_db, time());
|
|
|
128 |
$barcode = mysqli_real_escape_string($_sess_db, $value);
|
154 |
- |
129 |
$userId = (empty($_SESSION['sessData']['userID']) ? null : $_SESSION['sessData']['userID']);
|
123 |
- |
130 |
$ip = inet_pton($_SERVER['REMOTE_ADDR']);
|
154 |
- |
131 |
$sessionId = session_id();
|
123 |
- |
132 |
|
|
|
133 |
$sql = "INSERT
|
|
|
134 |
INTO barcodeChecks
|
|
|
135 |
(sessId, access, ip, barcode, userId)
|
154 |
- |
136 |
VALUES (?, ?, ?, ?, ?)";
|
|
|
137 |
$stmt = mysqli_prepare($_sess_db, $sql);
|
|
|
138 |
mysqli_stmt_bind_param($stmt, 'sdssd', $sessionId, $access, $ip, $barcode, $userId);
|
123 |
- |
139 |
|
154 |
- |
140 |
if (!mysqli_stmt_execute($stmt)) {
|
123 |
- |
141 |
error_log("Error: " . $sql . " | " . mysqli_error($_sess_db));
|
|
|
142 |
}
|
127 |
- |
143 |
|
154 |
- |
144 |
mysqli_stmt_close($stmt);
|
123 |
- |
145 |
}
|
147 |
- |
146 |
|
|
|
147 |
function getBarcodeImage($value, $type) {
|
|
|
148 |
include('php/php-barcode.php');
|
|
|
149 |
|
|
|
150 |
$fontSize = 10;
|
|
|
151 |
$marge = 10;
|
|
|
152 |
$x = 100;
|
|
|
153 |
$y = 30;
|
|
|
154 |
$height = 50;
|
|
|
155 |
$width = 2;
|
|
|
156 |
$angle = 0;
|
|
|
157 |
|
|
|
158 |
$code = substr($value, 0, -1);
|
|
|
159 |
if ($type == "EAN") { $type = 'ean13'; }
|
|
|
160 |
|
|
|
161 |
$im = imagecreatetruecolor(200, 60);
|
|
|
162 |
$black = ImageColorAllocate($im,0x00,0x00,0x00);
|
|
|
163 |
$white = ImageColorAllocate($im,0xff,0xff,0xff);
|
|
|
164 |
imagefilledrectangle($im, 0, 0, 200, 60, $white);
|
|
|
165 |
|
|
|
166 |
$data = Barcode::gd($im, $black, $x, $y, $angle, $type, array('code'=>$code), $width, $height);
|
|
|
167 |
ob_start();
|
|
|
168 |
imagegif($im);
|
|
|
169 |
$data = ob_get_contents();
|
|
|
170 |
ob_end_clean();
|
|
|
171 |
imagedestroy($im);
|
|
|
172 |
$data = base64_encode($data);
|
|
|
173 |
return("<img alt='Barcode $value Image' src='data:image/gif;base64,$data'>");
|
153 |
- |
174 |
}
|