<?php
include('extension/connect.php');
include('extension/check-login.php');
include('extension/function.php');
include('extension/rank_check.php');
$admin_data = data_records($con);
$fast_loading = fast_loading($con);
$fastpro_loading = fastpro_loading($con);
$userid = $_SESSION['userid'];
$search = $userid;
$active = 'add_domain';
$status = '';
?>

<?php
if(isset($_POST['adddns'])){
    $domain = mysqli_real_escape_string($con,$_POST['domain_name']);
    $zone = mysqli_real_escape_string($con,$_POST['zone']);
    $global = mysqli_real_escape_string($con,$_POST['global']);
    $email = mysqli_real_escape_string($con,$_POST['email']);
  
  
    if($domain!='' && $zone!='' && $global!='' && $email!=''){
            if(domain_check($domain)){
                $query = mysqli_query($con,"insert into dns_settings(`domain`,`zone`,`global_api`,`email`) values('$domain','$zone','$global','$email')");
                    if($query){
                        $status = '<div class="alert alert-success alert-dismissible" role="alert">
                                        [Domain] Added successfully
                                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                    </div>';
                    }else{
                        $status = '<div class="alert alert-danger alert-dismissible" role="alert">
                                        [Domain] Add Failure
                                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                    </div>';
                            }
            }else{
                $status = '<div class="alert alert-danger alert-dismissible" role="alert">
                                Domain already registered
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">×</span>
                                </button>
                            </div>';
            }
    }else{
        $status = '<div class="alert alert-danger alert-dismissible" role="alert">
                        Please fill-out all forms
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">×</span>
                        </button>
                    </div>';
    }
}

if(!isset($_POST['action_a'])){
    
}else{
    if($_POST['action_a'] == 'delete'){
        
        $u = mysqli_real_escape_string($con,$_POST['action_u']);
        
        $query = mysqli_query($con,"DELETE FROM dns_settings WHERE id='$u'");
        if($query)
        {
        	$status2 = '<div class="alert alert-success alert-dismissible" role="alert">
                            [Domain] Delete successfully
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">×</span>
                            </button>
                        </div>';
        }else{
        	$status2 = '<div class="alert alert-danger alert-dismissible" role="alert">
                            [Domain] Delete failure
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">×</span>
                            </button>
                        </div>';
        }
    }else{
        
    }
}

?>

<?php 
function domain_check($domain){
  global $con;
  
  $query =mysqli_query($con,"select * from servers where domain='$domain'");
  if(mysqli_num_rows($query)>0){
    return false;
  }
  else{
    return true;
  }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="keywords" content="<?php include('extension/title.php'); ?>" />
  <meta name="description" content="<?php include('extension/title.php'); ?> - VPN Panel System" />
  <meta name="author" content="<?php include('extension/title.php'); ?>" />
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title><?php include('extension/title.php'); ?> | Add DNS Domain</title>

  <!-- Favicon -->
  <link rel="shortcut icon" href="<?php include('extension/logo.php'); ?>" />
  
  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="/assets/plugins/fontawesome-free/css/all.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- Bootstrap Color Picker -->
  <link rel="stylesheet" href="/assets/plugins/bootstrap-colorpicker/css/bootstrap-colorpicker.min.css">
  <!-- Tempusdominus Bootstrap 4 -->
  <link rel="stylesheet" href="/assets/plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
  <!-- iCheck -->
  <link rel="stylesheet" href="/assets/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- JQVMap -->
  <link rel="stylesheet" href="/assets/plugins/jqvmap/jqvmap.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="/assets/dist/css/adminlte.min.css">
  <!-- overlayScrollbars -->
  <link rel="stylesheet" href="/assets/plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <!-- Daterange picker -->
  <link rel="stylesheet" href="/assets/plugins/daterangepicker/daterangepicker.css">
  <!-- summernote -->
  <link rel="stylesheet" href="/assets/plugins/summernote/summernote-bs4.min.css">
</head>
<body class="hold-transition sidebar-mini layout-fixed">
<?php
    $dns_status = mysqli_query($con,"select status from dns");
    $dns_count = mysqli_num_rows($dns_status);
    
    if($dns_count == 0){
        $dns_bg = 'red-bg';
    }else{
        $dns_bg = 'green-bg';
    }
?>
<div class="wrapper">

  <!-- Preloader -->
  <div class="preloader flex-column justify-content-center align-items-center">
    <img class="animation__shake" src="<?php include('extension/logo.php'); ?>" alt="Preloader" height="60" width="60">
  </div>

  <?php include('extension/topnav.php'); ?>
  
  <?php include('extension/sidenav.php'); ?>

  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0">Add DNS Domain</h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#" style="color: <?php include('extension/theme.php'); ?>;">Home</a></li>
              <li class="breadcrumb-item active">Add DNS Domain</li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    
    <section class="content">
        
      <div class="container-fluid">
        
        <div class="row">
          <!-- left column -->
          <div class="col-md-6">
            <!-- jquery validation -->
            <?php
            $query = mysqli_query($con,"select * from users where user_name='$userid'");
            $result = mysqli_fetch_array($query);
            ?>
            <div class="card card-primary">
              <div class="card-header" style="color: <?php include('extension/theme_text.php'); ?>; background-color: <?php include('extension/theme.php'); ?>;">
                <h3 class="card-title">Add DNS Domain</h3>
              </div>
              <!-- /.card-header -->
              <!-- form start -->
              <form method="post" id="createSingleUserForm"> 
                  
                <div class="card-body">
                  <?php echo $status; ?>
                  
                  <div class="form-group">
                    <label for="domain_name">Domain Name</label>
                    <input name="domain_name" type="text" class="form-control" id="domain_name" placeholder="Enter domain name" required>
                  </div>
                  
                  <div class="form-group">
                    <label for="zone">Zone ID</label>
                    <input name="zone" type="text" class="form-control" id="zone" placeholder="Enter Zone ID" required>
                  </div>
                  
                  <div class="form-group">
                    <label for="global">Global API</label>
                    <input name="global" type="text" class="form-control" id="global" placeholder="Enter Global API" required>
                  </div>
                  
                  <div class="form-group">
                    <label for="email">Email Address</label>
                    <input name="email" type="email" class="form-control" id="email" placeholder="Enter email address" required>
                  </div>
                  
                </div>
                <!-- /.card-body -->
                <div class="card-footer">
                  <button type="submit" name="adddns" class="btn" style="color: <?php include('extension/theme_text.php'); ?>; background-color: <?php include('extension/theme.php'); ?>;">Submit</button>
                </div>
              </form>
            </div>
            <!-- /.card -->
            </div>
          <!--/.col (left) -->
        </div>
        <!-- /.row -->
        
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
  <?php include('extension/footer.php'); ?>

  <!-- Control Sidebar -->
  <aside class="control-sidebar control-sidebar-dark">
    <!-- Control sidebar content goes here -->
  </aside>
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="/assets/plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="/assets/plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
  $.widget.bridge('uibutton', $.ui.button)
</script>
<!-- jQuery -->
<script src="/assets/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="/assets/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Select2 -->
<script src="/assets/plugins/select2/js/select2.full.min.js"></script>
<!-- Bootstrap4 Duallistbox -->
<script src="/assets/plugins/bootstrap4-duallistbox/jquery.bootstrap-duallistbox.min.js"></script>
<!-- InputMask -->
<script src="/assets/plugins/moment/moment.min.js"></script>
<script src="/assets/plugins/inputmask/jquery.inputmask.min.js"></script>
<!-- date-range-picker -->
<script src="/assets/plugins/daterangepicker/daterangepicker.js"></script>
<!-- bootstrap color picker -->
<script src="/assets/plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="/assets/plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Bootstrap Switch -->
<script src="/assets/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<!-- BS-Stepper -->
<script src="/assets/plugins/bs-stepper/js/bs-stepper.min.js"></script>
<!-- dropzonejs -->
<script src="/assets/plugins/dropzone/min/dropzone.min.js"></script>
<!-- AdminLTE App -->
<script src="/assets/dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="/assets/dist/js/demo.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="/assets/dist/js/pages/dashboard.js"></script>
<script src="/assets/alertifyjs/alertify.js"></script>
</body>
</html>
