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

$zdir = $dbname;
$zcomp = 1;
$zdbroot = $zdir;
$focusfield = "submit";
$usertype = $_SESSION["usertype"];
$username = $_SESSION["username"];
$getusercode = mysqli_query($conn, "SELECT code,user FROM `passmain` WHERE user = '$username' ") OR die(mysqli_error($conn));
$gusercode = mysqli_fetch_array($getusercode);
$zroot = $_SESSION["zdbroot"];
$zrootmn = $_SESSION['zheadroot'];
$zroot1 = substr($zrootmn, 0, -4);
// browse($zroot);
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 `compcd`='$comp'")or die(mysqli_error($conn));
    $fetcomp = mysqli_fetch_array($getcomp);
    $compgodw = $fetcomp['compgodw'];
    $compchng = $fetcomp['compchng'];
    $possoft = $fetcomp['possoft'];
    $stpind = $fetcomp['stpind'];
    $crbrcpbpnp = $fetcomp['crbrcpbpnp'];
    $year1 = mysqli_query($conn, "SELECT finyear,DATE_FORMAT(`startdate`, '%d-%m-%Y') as mfrdt, DATE_FORMAT(`lastdate`, '%d-%m-%Y') as mtodt 
                                 FROM `compyear` limit 0,1 ") OR die(mysqli_error($conn));
//   print table($year1);
//   die();
    $cyear = mysqli_fetch_array($year1);

    $_SESSION["menucolor"] = $fetcomp['menucolor'];
    $_SESSION["vheadcolor"] = $fetcomp['vheadcolor'];
    $_SESSION["vmidcolor"] = $fetcomp['vmidcolor'];
    $_SESSION["repocolor"] = $fetcomp['repocolor'];
    $_SESSION["menutype"] = $fetcomp['menu'];
    $_SESSION["locflsec"] = $fetcomp['locflsec'];
    $_SESSION["stpind"] = $stpind;
    $_SESSION["crbrcpbpnp"] = $crbrcpbpnp;

    $zsdate = $cyear['mfrdt'];

    $zedate = $cyear['mtodt'];

    $myr = $cyear["finyear"];
    // browse($comp);
    // die();

    $_SESSION["zdbyear_" . $dbname] = $zroot1 . $comp . "_" . $myr;


    $mdb = $_SESSION["zdbyear_" . $dbname];

    $_SESSION["zdbyear_" . $zsdate] = $zsdate;

    $_SESSION["zdbyear_" . $zedate] = $zedate;

    $_SESSION[$myyear] = $myr;

    $_SESSION["society_" . $dbname] = $fetcomp["compcd"];
    $_SESSION["compchng"] = $compchng;
    $_SESSION["compgodw"] = $compgodw;
    $_SESSION["possoft"] = $possoft;
    $_SESSION["tit_" . $dbname] = $_POST["comp"];
    //    browse($_SESSION["comp_" .$dbname]);
    //    header("Location: year.php");
    header("Location: toursele.php");
}
include("includes/linkshead.php");
?>
<style>

    body {
        animation: fadeInAnimation ease 3s; 
        animation-iteration-count: 1;
        animation-fill-mode: forwards;
    }

    .select2 {
        font-weight: bold;
        color: #57606f;
    }

    @keyframes fadeInAnimation {
        0% {
            opacity: 0;
        }
        100% {
            opacity: 1;
        }
    }
    .shadow2 { 
        box-shadow: 0 7px 30px -10px rgba(150,170,180,0.5);
        padding: 10px;
        background: #fff;
        max-width: 360px;
        border-radius: 20px;
        margin: 60px auto;
        border: 1px;
    }
    .btn-submit {
        width: 100%;
        height: 50px;
        font-size: 20px;
        font-weight: bold;
        border-radius: 7px; 
        background-color: #B91646;
    }
    .ttext {
        font-weight: bold;
        color: #57606f;
    }
    .compTxt {
        font-weight: bold;
        color: #57606f;
    }
</style>

</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 shadow2 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 ttext">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
                                    $getcomp = mysqli_query($conn, "SELECT * FROM `company` order by code") OR die(mysqli_error($conn));
                                    while ($gcomp = mysqli_fetch_array($getcomp)) {
                                        echo "<option class='compTxt' value='$gcomp[compcd]'>$gcomp[compname]</option>";
                                    }
                                    ?>
                                </select>
                                <div class="form-control-feedback">
                                    <!--<i class="icon-user text-muted"></i>-->
                                </div>
                            </div>

                            <div class="form-group" style="width: 100%; text-align: center;">
                                <button type="submit" name="submit" class="btn btn-primary btn-block btn-submit" autofocus="on" >Sign in <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>
