Subversion Repositories cheapmusic

Rev

Rev 114 | 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", true);
        }

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

        $type = clsLibGTIN::GTINCheck($barcode, false, 1);
        $value = clsLibGTIN::GTINCheck($barcode);
        if ($type) {
            myExit("Barcode already has a valid check digit" . "<br>" . $type . " " . $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);
    }
}

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

function myExit($msg, $isError = false) {
    echo '<span class="' . ($isError ? 'text-danger' : 'text-success') . '">' . $msg . '</span>';
    MySessionHandler::commit(session_id());
    exit;
}