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

$zdir = $dbname;
$zcomp = 1;
$zdbroot = $zdir;
$focusfield = "submit";
$username = $_SESSION["username"];

$zroot = $_SESSION["zdbroot"];
$zroot1 = substr($zroot, 0, -4);
if (isset($_POST["submit"])) {

    $syear = $_POST["cmbyear"];
    $admin = $_SESSION["admin_" . $dbname];
    $_SESSION["comp_" . $dbname] = $_POST["comp"];
    $comp = $_POST["comp"];
    $getcomp = mysqli_query($conn, "SELECT * FROM `company` WHERE `code`='$comp'") or die(mysqli_error($conn));
    $fetcomp = mysqli_fetch_array($getcomp);
    $compchng = $fetcomp['compchng'];
    $_SESSION["instid"] = $fetcomp['instid'];
    $_SESSION["accstkn"] = $fetcomp['accstkn'];

    $_SESSION["compchng"] = $compchng;

    header("Location: year.php");
}
include("includes/linkshead.php");

$user = $_SESSION["username_" . $dbname];
$pass = $_SESSION["password_" . $dbname];
//browse($pass);
//$spltype = $_SESSION["spltype_" . $dbname];
$getusercode = mysqli_query($conn, "SELECT * FROM `passmain` WHERE `user`='$user' and `password`='$pass'") or die(mysqli_error($conn));
$gusercode = mysqli_fetch_array($getusercode);
$usercode = $gusercode['code'];
$usertype = $gusercode['usertype'];
$spltype = $gusercode['spltype'];
?>


</head>

<body>
    <!-- Page container -->
    <div class="page-container login-container">

        <!-- Page content -->
        <div class="page-content">

            <!-- Main content -->
            <div class="content-wrapper">

                <!-- Content area -->
                <div class="content">

                    <!-- Simple login form -->
                    <form action="" method="POST">
                        <div class="panel panel-body login-form">
                            <div class="text-center">
                                <!--<div class="icon-object border-slate-300 text-slate-300"><i class="icon-reading"></i></div>-->
                                <h4 class="content-group">Select Company</h4>
                            </div>

                            <div class="form-group has-feedback has-feedback-left text-center">
                                <select id='comp' name="comp" class="form-control select2"
                                    style="height:33px;width: 100%">
                                    <?php
//                                    if ($usertype == "1") {
                                        if ($spltype == "1") {
                                            $getcomp = mysqli_query($conn, "SELECT * FROM `company` where `compchng`='1'") OR die(mysqli_error($conn));

                                        } else {
                                            $getcomp = mysqli_query($conn, "SELECT * FROM `company` where `compchng`!='1'") OR die(mysqli_error($conn));
                                        }
                                        //print table($getcomp);
                                        while ($gcomp = mysqli_fetch_array($getcomp)) {
                                            echo "<option value='$gcomp[code]'>$gcomp[compname]</option>";
                                        }
//                                    } else {
//                                        $getcomp = mysqli_query($conn, "SELECT * FROM `usercomp` WHERE `username`='$usercode' group by cono") OR die(mysqli_error($conn));
//                                        while ($gcomp = mysqli_fetch_array($getcomp)) {
//                                            echo "<option value='$gcomp[cono]'>$gcomp[cname]</option>";
//                                        }
//                                    }
                                    ?>
                                </select>
                                <div class="form-control-feedback">
                                    <!--<i class="icon-user text-muted"></i>-->
                                </div>
                            </div>

                            <div class="form-group">
                                <button type="submit" id="submit" name="submit" class="btn btn-primary btn-block"
                                    style="background-color: #47a3da">Submit<i
                                        class="icon-circle-right2 position-right"></i></button>
                            </div>
                        </div>
                    </form>
                    <!-- /simple login form -->
                </div>
                <!-- /content area -->
            </div>
            <!-- /main content -->
        </div>
        <!-- /page content -->
    </div>
    <!-- /page container -->
    <?php include("includes/linksfoot.php") ?>
    <script>
        $("#submit").focus();
    </script>
</body>

</html>