<?php

date_default_timezone_set('America/New_York');

ini_set('session.cache_limiter','public');
session_cache_limiter(false);

session_start();
//if(empty($_SESSION['userid_brand'])){
//    header('Location: ../../setups/users/login.php');
//}\
$path = explode("/",$_SERVER['PHP_SELF']);
$script = $path[sizeof($path)-1];

if (!isset($_SESSION["userid_brand"]) && (($script != "cronProducts.php" ) && ($script != "cron.php" ) && ($script != "mpad.php" ) && ($script != "cronResetStatus.php" ) && ($script != "cronUpdateOrderStatusAndTracking.php" ) && ($script != "cronUpdareOrdersExceptToday.php" ))) {
    header('Location: ../users/login.php');
} else {
    // set time-out period (in seconds)
    $inactive = 1800;
    // check to see if $_SESSION["timeout"] is set
    if (isset($_SESSION["timeout"])) {
        // calculate the session's "time to live"
        $sessionTTL = time() - $_SESSION["timeout"];
        if ($sessionTTL > $inactive) {
            session_destroy();
            header('Location: ../users/login.php');
        }
    }

    $_SESSION["timeout"] = time();
}

//For Display Purposes
function fomatItemId($id, $name) {
    $value = substr($name, 0, 3) . "/" . $id;
    return $value;
}
