Subversion Repositories cheapmusic

Rev

Rev 114 | Rev 121 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
include_once ('php/dnsexit.php');
include_once ('php/sessions_db.php');
include_once ('php/cryptor.php');
include_once ('php/tools.php');
include_once ('php/clsLibGTIN.php');

error_reporting(E_ALL);

$configFile = parse_ini_file($_SERVER['DOCUMENT_ROOT'] . FCM_CONFIGFILE, true);
$crypt = Cryptor::getInstance($configFile['cryptor']);
$tmpSessionTab = (isset($_POST["sessionTab"]) && $_POST["sessionTab"] > 0 ? $_POST["sessionTab"] : null);
$handler = MySessionHandler::getInstance($tmpSessionTab, $configFile['mysqli']);
unset($configFile);

ini_set("session.cookie_httponly", 1);
ini_set("session.cookie_secure", 1);
session_set_save_handler($handler, true);
if (!empty($_COOKIE['PHPSESSID'])) {
    session_id($_COOKIE['PHPSESSID']);
}
session_start();

initSessionVariables();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $barcode = getPGV("barcode");
    

    if ($_POST["submit"] == "check") {
        if (empty($barcode) || !is_numeric($barcode) || strlen($barcode) > 14 || strlen($barcode) < 8) {
            myExit("Invalid Barcode", null, true);
        }

        $type = clsLibGTIN::GTINCheck($barcode, false, 1);
        $value = clsLibGTIN::GTINCheck($barcode);
        if (!$type) {
            myExit("Barcode does not have a valid check digit", null, true);
        } else {
            myExit("Valid barcode<br>" . $type . " " . $value, $value);
        }
    } else if ($_POST["submit"] == "calc") {
        if (empty($barcode) || strlen($barcode) > 13 || strlen($barcode) < 8) {
            myExit("Invalid Barcode", null, true);
        }

        $type = clsLibGTIN::GTINCheck($barcode, false, 1);
        $value = clsLibGTIN::GTINCheck($barcode);
        if ($type) {
            myExit("Barcode already has a valid check digit" . "<br>" . $type . " " . $value, $value);
        }
        $checkDigit = clsLibGTIN::GTINCalcCheckDigit($barcode);
        $type = clsLibGTIN::GTINCheck($barcode . $checkDigit, false, 1);
        $value = clsLibGTIN::GTINCheck($barcode . $checkDigit);
        myExit("Check Digit is " . $checkDigit . "<br>" . $type . " " . $value, $value);
    }
}

MySessionHandler::commit(session_id());
exit;

function myExit($msg, $value, $isError = false) {
    echo '<span class="' . ($isError ? 'text-danger' : 'text-success') . '">' . $msg . '</span>';
    if (!$isError) {
        echo '<div class="mt-3">';
        echo '<form method="post" action="/index.php" onsubmit="progressBar(\'Searching for:<br><br><strong>' . $value . '</strong>\');">';
        echo '<input type="hidden" name="sessionTab" value="' . MySessionHandler::getSessionTab() . '" />';
        echo '<input type="hidden" name="searchTerm" value="' . $value . '" />';
        echo '<button type="submit" class="btn btn-success" name="submit" value="Search">Search ' . $value . '</button>';
        echo '</form>';
        echo '</div>';
    }
    MySessionHandler::commit(session_id());
    exit;
}