<?php
session_start();
$dbtype = "root";
require("includes/dbconnect.php");
require("includes/config.php");
require("includes/function.php");

$zdir = $dbname;
$zcomp = 1;
$zdbroot = $zdir;
$focusfield = "user";

if (isset($_POST["submit"])) {
    $udbf = $zdbroot . "passmain";

    $myip = $_SERVER['REMOTE_ADDR'];
    
    
    ########## Getting The Ip From Table ##########
    $fetchipcheck = mysqli_query($conn, "SELECT * FROM `passmain` WHERE `user` = '" . mysqli_real_escape_string($conn, $_POST['user']) . "'
                         AND `password` = '" . mysqli_real_escape_string($conn, $_POST['pass']) . "'") or die(mysqli_error($conn));
    $ipcheck = mysqli_fetch_array($fetchipcheck);
    
    ########## Putting A If Condition Whether Ip Exist Or Not ##########
    $login = "";
    $ipfail = 0;
    if($ipcheck[ipadd] == ''){
        $login = mysqli_query($conn, "SELECT * FROM `passmain` WHERE `user` = '" . mysqli_real_escape_string($conn, $_POST['user']) . "'
                         AND `password` = '" . mysqli_real_escape_string($conn, $_POST['pass']) . "'") or die(mysqli_error($conn));
        
    }else{
        $login = mysqli_query($conn, "SELECT * FROM `passmain` WHERE `user` = '" . mysqli_real_escape_string($conn, $_POST['user']) . "'
                         AND `password` = '" . mysqli_real_escape_string($conn, $_POST['pass']) . "' AND (`ipadd`='$myip' or `ipadd2`='$myip')") or die(mysqli_error($conn));
        $ipfail = 1;
    }
//    if($ipcheck[ipadd2] == ''){
//        $login = mysqli_query($conn, "SELECT * FROM `passmain` WHERE `username` = '" . mysqli_real_escape_string($conn, $_POST['user']) . "'
//                         AND `password` = '" . mysqli_real_escape_string($conn, $_POST['pass']) . "'") or die(mysqli_error($conn));
//    }else{
//        $login = mysqli_query($conn, "SELECT * FROM `passmain` WHERE `username` = '" . mysqli_real_escape_string($conn, $_POST['user']) . "'
//                         AND `password` = '" . mysqli_real_escape_string($conn, $_POST['pass']) . "' AND `ipadd2`='$myip'") or die(mysqli_error($conn));
//        $ipfail2 = 1;
//    }
    
    $loginfetch = mysqli_fetch_array($login);
    $usertype = $loginfetch['usertype'];

    $_SESSION["username_" . $dbname] = $login["user"];
    
    
    $_SESSION["zdbroot"] = $zdbroot;
    $_SESSION["zdir"] = $zdir;
    $_SESSION["zcompany"] = 'Seventh Sky International';
//browse(mysqli_num_rows($login));
    if (mysqli_num_rows($login) == 1) {
        $_SESSION['username_' . $dbname] = $_POST["user"];
        $_SESSION['usertype_' . $dbname] = $_POST["usertype"];
        $_SESSION['logged-in'] = true;
        $getuser_dtl = mysqli_fetch_object($login);
        $admin = $getuser_dtl->admin;
        $_SESSION["admin_" . $dbname] = $admin;
//        $_SESSION["zdbyear_$dbname"] = $dbyear;
        $_SESSION["usertype"] = $usertype;

        $_SESSION["zdbyear_" . $dbname] =  'apps4rea_tlt_1_1617';

        header("Location: menu.php");
    }  else {
       if($ipfail){
           browse("This Ip Is Blocked");
       } else {
           browse("Invalid Login Credentials");
       }
    }
    
}

include("includes/linkshead.php");
?>

</head>

<body class="animated fadeIn" >
    <section id="login-container">
        <div class="row text-center">
            
        </div>
        <div class="row" >
            <div class="col-lg-12" id="" style="" align="center">
                <div class="panel panel-primary flipInY" style="background : transparent">
                    <div class="panel-heading">
                        <h3 class="panel-title" style="font-size: 43px;">     
                           <?php Echo $project_title; ?>
                        </h3>      
                    </div>
                    <div class="panel-body">
<!--                       <p> Login to access your account.</p>-->
                       <form class="form-horizontal" action='' method="POST">
                               
                           <h1 style="color: red;">
                               Due To Non-Payment of Server Charges.Your System Is Down.
                           </h1>
                           <h1  style="color: blue;">
                               Sorry For The Inconvenience! Contact The Host Administrator.
                           </h1>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </section>
    <?php include("includes/linksfoot.php") ?>
</body>
</html>