<?php
ob_start();
include_once("../../lib/function.php");
include_once("../../lib/konfig.php");
$MySQLi_auto = new MySQLi($strDBHostName, $strDBUsername, $strDBPassword, $strDBName);
session_start();
if (!isset($_SESSION['strEmail'])) {
    if (isset($_GET['session_data'])) {
        $query = "SELECT  FullName, 
                        Email, 
                        Level, 
                        Division, 
                        strKdLoc, 
                        strJobPosition, 
                        strPassword 
                FROM employee 
                WHERE   Email='" . $_GET['session_data'] . "' AND 
                        stsAktif=1 
                ";
        $result = $MySQLi_auto->query($query);
        if ($result->num_rows == 1) {
            $row = $result->fetch_array();
            //$strPassword=passwd()
            $_SESSION['strEmail'] = $row['Email'];
            $_SESSION['usrLevel'] = $row['Level'];
            $_SESSION['strNama'] = $row['FullName'];
            $_SESSION['strDivision'] = $row['Division'];
            $_SESSION['strKdLokasi'] = $row['strKdLoc'];
            $_SESSION['strJobPosition'] = $row['strJobPosition'];

            switch ($_SESSION['usrLevel']) {
                case 1:
                    $_SESSION['strJenisAkses'] = "DIR";
                    break;
                case 2:
                    $_SESSION['strJenisAkses'] = "MGR";
                    break;
                case 3:
                    $_SESSION['strJenisAkses'] = "SPV";
                    break;
                case 4:
                    $_SESSION['strJenisAkses'] = "STAFF";
                    break;
            }
            $strIP = getIPv4();
            if ($_SESSION['usrLevel'] == 3 || $_SESSION['usrLevel'] == 4) {
                $MySQLi = new MySQLi($strDBHostName, $strDBUsername, $strDBPassword, $strDBName);
                $query = "SELECT * 
                        FROM tpc_ip_allow 
                        WHERE strNmApp='LPBJ' AND 
                            strIPv4='" . $strIP . "' 
                        ";
                $result = $MySQLi->query($query);
                if ($result->num_rows == 0) {
                    //header("location:http://" . $strNmDomain);
                    header($strNmDomain);
                }
            }
        } else header($strNmDomain);
        //header("location:http://" . $strNmDomain);
    } else header($strNmDomain);
    //header("location:http://" . $strNmDomain);    
} else {
    if (isset($_GET['session_data']) && $_SESSION['strEmail'] <> $_GET['session_data'])
        echo "Anda tidak memiliki akses untuk masuk kehalaman ini. silahkan klik link berikut untuk kembali kehalaman awal : <a href='http://" . $strNmDomain . "/home/logout.php'>";
}


//$query="DELETE FROM item WHERE ID IN (SELECT item_ID FROM tpc_d_lpbj AS D_LPBJ LEFT JOIN tpc_h_lpbj AS H_LPBJ ON H_LPBJ.ID=D_LPBJ.h_lpbj_ID WHERE H_LPBJ.stsAktif=2 AND TIMESTAMPDIFF(HOUR, H_LPBJ.dtCreate, NOW()) >= 1)";
//$MySQLi_auto->query($query);
$query = "DELETE FROM tpc_d_lpbj WHERE h_lpbj_ID IN (SELECT ID FROM tpc_h_lpbj WHERE stsAktif > 1 AND TIMESTAMPDIFF(HOUR, dtCreate, NOW()) >= 1)";
$MySQLi_auto->query($query);
$query = "DELETE FROM tpc_h_lpbj WHERE stsAktif>1 AND TIMESTAMPDIFF(HOUR, dtCreate, NOW()) >= 1";
$MySQLi_auto->query($query);


include_once('header.php');
include_once('navigasi.php');
include_once('left.menu.php');
include_once('main.php');
include_once('footer.php');

/*
include_once('header2.php');
include_once('navigasi2.php');
include_once('left.menu2.php');
include_once('main2.php');
include_once('footer2.php');
*/