<?php
require("config/koneksi.php");
require("config/crud.php");
if ($setting['id_server'] <> '') {
	echo "<script>location.href = 'admin/sign-in.php';</script>";
}
if (!$pilihdb) {
	$ket = 'disabled';
	$ket2 = '';
} else {
	$ket = '';
	$ket2 = 'disabled';
}
if (isset($_POST['create'])) {
	$nama_db = 'lokal';
	mysqli_query($koneksi, "CREATE DATABASE $nama_db CHARACTER SET utf8 COLLATE utf8_general_ci;");
	header('location:admin/sign-in.php');
}
if (isset($_POST['import'])) {
	$filename = 'assets/plugins/lokal.sql';
	$templine = '';
	$lines = file($filename);
	foreach ($lines as $line) {
		if (substr($line, 0, 2) == '--' || $line == '')
			continue;
		$templine .= $line;
		if (substr(trim($line), -1, 1) == ';') {
			mysqli_query($koneksi, $templine);
			$templine = '';
		}
	}
	header('location:admin/sign-in.php');
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="New Sandik MBS">
    <meta name="keywords" content="admin,dashboard">
    <meta name="author" content="stacks">
    <title>NEW MBS SANDIK MULTI</title>

    <link rel='shortcut icon' href="<?= $setting['logo'] ?>" />
    <link href="assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/plugins/perfectscroll/perfect-scrollbar.css" rel="stylesheet">
    <link href="assets/plugins/pace/pace.css" rel="stylesheet">
    <link href="assets/css/main.min.css" rel="stylesheet">
    <link href="assets/css/custom.css" rel="stylesheet">
     <link rel="icon" type="image/png" sizes="32x32" href="dist/img/logo65.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="dist/img/logo65.png" />
    <link rel='stylesheet' href='plugins/izitoast/css/iziToast.min.css'>
   
</head>
<body>
<?php if($setting['id_aplikasi']<>1): ?>
 <div class="app app-auth-sign-in align-content-stretch d-flex flex-wrap justify-content-end">
        <div class="app-auth-background">
 
        </div>
        <div class="app-auth-container">
            <div class="logo">
			
                <a href="#">INSTAL SERVER LOKAL SEKOLAH</a>
            </div>
			<p>
            <div class="alert alert-custom" role="alert">
             <div class="custom-alert-icon icon-primary"><img src="dist/img/logohome.png" style="max-width:70px"></div>
                 <div class="alert-content">
                  <span class="alert-text" style="text-align:justify"> Instalasi Aplikasi Sandik New MBS hanya dapat dilakukan di Localhost. Jika ingin memasang di VPS atau Hosting silahkan Backup Database untuk di import ke Database di VPS maupun Hosting dan Copy Source Code yang ada di Localhost.</span>
                      </div>
                            </div>
            <div class="auth-credentials m-b-xxl">
			<div class="row">
			<div class="col-md-6"> 
               <div class="card widget widget-info-inline">
                      <div class="card-header">
                       <h5 class="card-title">BUAT DATABASE<span class="badge badge-danger badge-style-light"></span></h5>
					    </div>
						<div class="card-body">
					<form action='' method='post'>
						<div class="wrap-login100-form-btn">
						<div class="login100-form-bgbtn"></div>
						<button name='create' class="btn btn-outline-success btn-raised  btn-block" <?php echo $ket2 ?>>
						SIMPAN
						</button>
						</div>
						</form>
						</div>
                            </div>
							 </div>
							<div class="col-md-6"> 
               <div class="card widget widget-info-inline">
                      <div class="card-header">
                       <h5 class="card-title">INSTALL DATABASE<span class="badge badge-danger badge-style-light"></span></h5>
					    </div>
						<div class="card-body">
						<form action='' method='post'>
						<div class="wrap-login100-form-btn">
						<div class="login100-form-bgbtn"></div>
						<button name='import' class="btn btn-outline-danger btn-raised  btn-block" <?php echo $ket ?>>
						INSTAL
						</button>
						</div>
						</form>
						</div>
						</div>
						</div>

              <?php elseif($setting['id_aplikasi']==1): ?>

   <div class="app app-auth-sign-in align-content-stretch d-flex flex-wrap justify-content-end">
        <div class="app-auth-background" style="background-image: url('dist/img/bk.svg');">
 
        </div>
        <div class="app-auth-container">
            <div class="logo">
			 <img src="<?= $homeurl . '/' . $setting['logo'] ?>" height="50px">
                <a href="#" style="margin-top:-50px">SINKRON SERVER</a>
            </div>
          <p>
           <form id="formserver"  name="fmLogin">
            <div class="auth-credentials m-b-xxl">
                <label for="signInEmail" class="form-label"><b>URL SERVER PUSAT<b></label>
                <input type="text" class="form-control m-b-md"  name='url'  required>

                <label for="signInPassword" class="form-label"><b>KODE SERVER</b></label>
                <input type="text" class="form-control" name="server"  required>
            </div>

            <div class="auth-submit">
               <button type="submit" class="btn btn-primary btn-block btn-login" id="btnLogin">
                                            SINKRON
                                        </button>
               <input type='hidden' name='token' value="<?= $setting['token_api'] ?>" class='form-control' />
            </div>
			 </form>
			 <?php endif; ?>
            <div class="divider"></div>
            <div class="auth-alts">
                <a href="#" class="auth-alts-google"></a>
                <a href="#" class="auth-alts-facebook"></a>
                <a href="#" class="auth-alts-twitter"></a>
            </div>
        </div>
    </div>
    
    <script src="assets/plugins/jquery/jquery-3.5.1.min.js"></script>
    <script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>
    <script src="assets/plugins/perfectscroll/perfect-scrollbar.min.js"></script>
    <script src="assets/plugins/pace/pace.min.js"></script>
    <script src="assets/js/main.min.js"></script>
    <script src="assets/js/custom.js"></script>
	<script src='plugins/izitoast/js/iziToast.min.js'></script>
                <script type="text/javascript">
               $(document).ready(function() {
			 $('#formserver').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: 'POST',
            url: 'cekserver.php',
            data: $(this).serialize(),
            success: function(data) {
                console.log(data);
                if (data == 'OK') {
             iziToast.info(
            {
                title: 'Sukses!',
                message: 'Data berhasil disimpan',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'
                    });
                    setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                } else {
                  iziToast.info(
            {
                title: 'Gagal!',
                message: 'Data Server Tidak Terdaftar',
				titleColor: '#FFFF00',
				messageColor: '#fff',
				backgroundColor: 'rgba(0, 0, 0, 0.5)',
				 progressBarColor: '#FFFF00',
                  position: 'topRight'
                    });
					setTimeout(function() {
                        window.location.reload();
                    }, 2000);
                }

            }
        });
        return false;
    });
	
		});

		
                </script>
                
</body>
</html>