<?php
require ("includes/check_auth_user.php");
require ("includes/dbconnect.php");
include ('includes/function.php');
include("includes/menu_rights2.php");

$admin = $_SESSION["admin_" . $dbname];
$usertype = $_SESSION["usertype_" . $dbname];

$user = $_SESSION["username_" . $dbname];
$spec = $_SESSION["spltype_" . $dbname];
$fseries = $_SESSION["series_" . $dbname];


$zroot = $_SESSION["zdir"];
$src = "";
$action = isset($_GET["action"]) ? $_GET["action"] : "";
switch ($action) {

    ####################### MASTERS ##########################
    case "customer";
        $src = "customer.php?mode=last";
        break;

    case "supplier";
        $src = "supplier.php?mode=last";
        break;

    case "architect";
        $src = "architect.php?mode=last";
        break;

    case "unit";
        $src = "unit.php?mode=last";
        break;

    case "itemgrp";
        $src = "itemgrp.php?mode=last";
        break;

    case "godown";
        $src = "godown.php?mode=last";
        break;

    case "item";
        $src = "item.php?mode=last";
        break;

    case "chrateop";
        $src = "openstock.php?mode=last";
        break;

    case "itempart";
        $src = "itempart.php?mode=last";
        break;

    ####################### TRANSACTION ##########################

    case "inward";
        $src = "inward.php?mode=last";
        break;

    case "outward";
        $src = "outward.php?mode=last";
        break;

    case "damaged";
        $src = "damaged.php?mode=last";
        break;

    case "estimate";
        $src = "estimate.php?mode=last";
        break;

    case "quotation";
        $src = "quotation.php?mode=last";
        break;

    case "transfer";
        $src = "transfer.php?mode=last";
        break;

    ######################### REPORTS ###########################
    
    case "stock";
        $src = "stock.php";
        break;

    case "prodhist";
        $src = "prodhist.php";
        break;

    case "nonmoving";
        $src = "nonmoving.php";
        break;

    case "itemquery";
        $src = "itemquery.php";
        break;

    ########################## REGISTERS ########################
    case "inwreg";
        $src = "inwreg.php";
        break;

    case "outreg";
        $src = "outreg.php";
        break;

    case "damreg";
        $src = "damreg.php";
        break;
    case "estreg";
        $src = "estreg.php";
        break;

    case "intrnfreg";
        $src = "intrnfreg.php";
        break;

    #########################TOOLS#########################
    case "company";
        $src = "company.php?mode=last";
        break;

    case "profile";
        if ($usertype == 1) {

            $src = "user.php?mode=last";
        } else {
            $src = "user2.php?mode=last";
        }
        break;

//    case "stock";
//        $src = "default2.php";
//        break;
//
    case "backup";
        $src = "backup.php";
        break;

//    case "balsms";
//        $src = "http://vas.gsmash.com/balance.php?username=ABDRAS&password=ABDRAS2017&route=1";
//        break;
//
    case "yearend";
        $src = "yearend.php";
        break;

    default :
        $head = "Home";
        $src = "default.php?mode=last";
}

include("includes/linkshead.php");
$dispyear = right(($_SESSION["zdbyear_" . $dbname]), 4);

$zdb = $_SESSION["zdbyear_" . $dbname];
//browse($zdb);
$compcd = $_SESSION["comp_" . $dbname];

$getcomp = mysqli_query($conn, "SELECT code, name FROM `company` where `code`= '$compcd'") or die(mysqli_error($conn));
$fetcomp = mysqli_fetch_array($getcomp);
$cmpname = $fetcomp['name'];
mysqli_select_db($conn, $zdb);

//$srchresult = mysqli_query($conn, "SELECT vouchno, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as vouchdt, compcode, source, qty
//                                       FROM `transacn` where `complete`= '0000-00-00' and `source`='TR' group by vouchno order by vouchdt DESC") or die(mysqli_error($conn));
//$srchresult = mysqli_query($conn, "SELECT vouchno, DATE_FORMAT(`vouchdt`, '%d-%m-%Y')as vouchdt, party, totqty
//                                       FROM `purmain` where `complete`= '0000-00-00' and `salevouch` > 0 group by vouchno order by vouchdt DESC") or die(mysqli_error($conn));
//            print table($srchresult);
if (!empty($srchresult)) {
    $srcinst = mysqli_num_rows($srchresult);
} else {
    $srcinst = 0;
}
?>
<script>
    $(document).ready(function () {

        document.addEventListener("keydown", function (zEvent) {
            if (zEvent.ctrlKey && zEvent.altKey && zEvent.code === "KeyE") {
//                alert('Invalid key Nagvigate Through Menu');

                $(window).keydown(function (event) {
                    if (event.ctrlKey && event.keyCode == 52) { //ctrl + 4
                        var href = $('#crlink').attr('href');
                        window.location.href = href;
                    }
                });
            }
            if (zEvent.ctrlKey && zEvent.altKey && zEvent.code === "KeyR") {

                $(window).keydown(function (event) {
                    if (event.ctrlKey && event.keyCode == 55) {  //ctrl + 7
                        var href = $('#dclink').attr('href');
                        window.location.href = href;
                    }
                });
            }
        });

    });
</script>
</head>
<body class="off-canvas">
    <div id="container" class="sidebar-mini">
        <header id="header">
            <!--logo start-->
            <div class="brand"><a href="menu.php" class="logo"><?php Echo $cmpname; ?></a></div>
            <!--<div class="brand"><a href="menu.php" class="logo"><?php // Echo $project_name;                     ?></a></div>-->
            <!--logo end-->
            <div class="toggle-navigation toggle-left">
                <button type="button" class="btn btn-default" id="toggle-left" data-toggle="tooltip" data-placement="right" title="Toggle Navigation">
                    <i class="fa fa-bars"></i>
                </button>
            </div>

            <div class="user-nav">
                <ul>
                    <!--                    <li class="dropdown settings"><a href="<?
//                        if ($usertype == 1) {
//                            Echo "comp.php";
//                        } else {
//                            Echo "#";
//                        }
                    ?>"><label class="label-control" style="font-size: 12px;color: #263238;"> Company : <?php // echo $cmpname; ?></label></a></li>-->
                    <?php
                    if ($usertype == 99) {
                        ?>
                        <li class="dropdown settings">
                            <a class="dropdown-toggle" href="?action=quotation">
                                <label class="label-control" style="font-size: 15px;color: blue;"><i class="fa fa-"></i>Quotation</label>
                            </a>
                        </li>
                        <li class="dropdown settings">
                            <a class="dropdown-toggle" href="?action=estimate">
                                <label class="label-control" style="font-size: 15px;color: red;"><i class="fa fa-"></i>Estimate</label>
                            </a>
                        </li>
                    <?php } ?>
                    <li class="dropdown settings">
                        <a class="dropdown-toggle" href="year.php">
                            <label class="label-control" style="font-size: 13px"><i class="fa fa-calendar" aria-hidden="true"></i> <?php echo 'Financial Year : ' . $dispyear; ?></label>
                        </a>
                    </li>


                    <!--<li <?= $dcombstock; ?> class="dropdown settings"><label class="label-control" style="font-size: 18px;"><i class="fa fa-list"></i>  <a href="?action=combstock">Combined Stock</a></label></li>-->

                    <?php if ($srcinst > 0) {
                        ?>
                        <li class="dropdown settings">
                            <a class="dropdown-toggle" href="?action=autotran">
                                <label class="label-control" style="font-size: 15px;color: red;"><i class="fa fa-"></i>Transfer (<?= $srcinst ?>)</label>
                            </a>
                        </li>
                        <?php
                    }
                    ?>
<!--                    <li class="profile-photo"><img src="assets/img/avatar.png" alt="" class="img-circle"></li>-->
                    <li class="dropdown settings">
                        <a class="dropdown-toggle balsms" data-toggle="dropdown" href="#">
                            <b style="font-size: 20px;"><?php echo $_SESSION["username_" . $dbname]; ?></b> <i class="fa fa-angle-down"></i>
                        </a>
                        <ul class="dropdown-menu animated fadeInDown">
                            <li <?= $tlcompany; ?>><a href="?action=company"><i class="fa fa-building-o"></i> Company SetUp</a></li>
                            <li <?= $tlbackup; ?>><a href="?action=backup"><i class="fa fa-cloud-download"></i> Backup</a></li>
                            <li <?= $tlprofile; ?>><a href="?action=profile"><i class="fa fa-user"></i> Profile</a></li>
                            <!--<li <?= $tlbalsms; ?>><a href="?action=balsms"><i class="fa fa-user"></i> Balance SMS</a></li>-->
                            <!--<li <?= $tlyearend; ?>><a href="?action=yearend"><i class="fa fa-calendar"></i>Year End</a></li>-->
                            <li><a href="logout.php"><i class="fa fa-power-off"></i> Logout</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </header>


        <!-- AUTO LINKS-->
        <!--        <a href="ch_recd.php?mode=last" id="crlink" ></a>
                <a href="dailycash.php" id="dclink" ></a>-->


        <!--sidebar left start-->
        <nav class="sidebar sidebar-left">
            <h5 class="sidebar-header">Navigation</h5>
            <?php if ($usertype != 99) { ?>
                <ul class="nav nav-pills nav-stacked">
                    <li class="nav-dropdown">
                        <a href="#" title="UI Elements"><i class="fa fa-graduation-cap"></i>Masters</a>
                        <ul class="nav-sub">
    <!--                        <li <?= $customer; ?>><a href="?action=customer">Customer</a></li>
                            <li <?= $supplier; ?>><a href="?action=supplier">Supplier</a></li>
                            <li <?= $architect; ?>><a href="?action=architect">Architect</a></li>-->
                            <li <?= $godown; ?>><a href="?action=godown">Godown</a></li>
                            <li <?= $unit; ?>><a href="?action=unit">Unit</a></li>
                            <li <?= $item; ?>><a href="?action=item">Item</a></li>
                        </ul>
                    </li>
                    <li class="nav-dropdown">
                        <a href="#" title="Transaction"><i class="fa fa-usd"></i>Transaction</a>
                        <ul class='nav-sub'>
                            <li <?= $inward; ?>><a href="?action=inward">Inward</a></li>
                            <li <?= $outward; ?>><a href="?action=outward">Outward</a></li>
                            <li <?= $damaged; ?>><a href="?action=damaged">Damaged</a></li>
                            <li <?= $transfer; ?>><a href="?action=transfer">Internal Transfer</a></li>
                        </ul>
                    </li>
                    <li class="nav-dropdown">
                        <a href='#'><i class="fa fa-file"></i>Reports</a>
                        <ul class='nav-sub'>
                            <li <?= $stock; ?>><a href="?action=stock">Stock</a></li>
                            <li <?= $itemquery; ?>><a href="?action=itemquery">Item Query</a></li>
                            <li <?= $prodhist; ?>><a href="?action=prodhist">Product History</a></li>
                            <li <?= $nonmoving; ?>><a href="?action=nonmoving">Non Moving Products</a></li>
                        </ul>
                    </li> 
                    <li class="nav-dropdown">
                        <a href='#'><i class="fa fa-registered"></i>Registers</a>
                        <ul class='nav-sub'>
                            <li <?= $inwreg; ?>><a href="?action=inwreg">Inward</a></li>
                            <li <?= $outreg; ?>><a href="?action=outreg">Outward</a></li>
                            <li <?= $damreg; ?>><a href="?action=damreg">Damaged</a></li>
                            <li <?= $estreg; ?>><a href="?action=estreg">Estimate</a></li>
                            <li <?= $intrnfreg; ?>><a href="?action=intrnfreg">Internal Transfer</a></li>
                        </ul>
                    </li>
                </ul>
            <?php } ?>
        </nav>
        <!--sidebar left end-->
        <!--main content start-->
        <section class="main-content-wrapper">
            <section id="main-content">
                <div class="col-md-12 pad">
                    <iframe src="<?php echo $src; ?>" name="frame1" style="width: 100%; height:5000px;"  frameBorder="0" scrolling="no"></iframe>
                </div>
            </section>
        </section>
    </div>
    <!--main content end-->
    <?php include("includes/linksfoot.php") ?>
</body>
</html>
