<?php
include 'includ/header.php';
?>
        <div class="container grid px-6 mx-auto ">


            <a style="font-size: 20px"
               class="text-xs font-semibold tracking-wide text-left text-gray-500 0 dark:text-gray-400 inline-flex items-center w-full text-sm font-semibold transition-colors duration-150 hover:text-gray-800 dark:hover:text-gray-200"
            >
                <svg fill="gray" xmlns="http://www.w3.org/2000/svg" id="Outline" viewBox="0 0 24 24" width="21" height="21"><path d="M18.4,7.379a1.128,1.128,0,0,1-.769-.754h0a8,8,0,1,0-15.1,5.237A1.046,1.046,0,0,1,2.223,13.1,5.5,5.5,0,0,0,.057,18.3,5.622,5.622,0,0,0,5.683,23H11a1,1,0,0,0,1-1h0a1,1,0,0,0-1-1H5.683a3.614,3.614,0,0,1-3.646-2.981,3.456,3.456,0,0,1,1.376-3.313A3.021,3.021,0,0,0,4.4,11.141a6.113,6.113,0,0,1-.073-4.126A5.956,5.956,0,0,1,9.215,3.05,6.109,6.109,0,0,1,9.987,3a5.984,5.984,0,0,1,5.756,4.28,2.977,2.977,0,0,0,2.01,1.99,5.934,5.934,0,0,1,.778,11.09.976.976,0,0,0-.531.888h0a.988.988,0,0,0,1.388.915c4.134-1.987,6.38-7.214,2.88-12.264A6.935,6.935,0,0,0,18.4,7.379Z"/><path d="M18.707,16.707a1,1,0,0,0,0-1.414l-1.586-1.586a3,3,0,0,0-4.242,0l-1.586,1.586a1,1,0,0,0,1.414,1.414L14,15.414V23a1,1,0,0,0,2,0V15.414l1.293,1.293a1,1,0,0,0,1.414,0Z"/></svg>

                <span class="ml-4"><?php echo $_LANG['Backup']?></span>
                <span class="ml-4 justify-end inline-flex">
                    <button @click="openModal"
                            class=" text-sm font-medium leading-5 text-white transition-colors duration-150 border border-transparent rounded-lg focus:outline-none ">
                        <img src="icons/add.svg" width="30px">
                    </button>
                    </span>
                <?php session_notif_wizwiz() ?>
            </a>

            <div style='margin-top:40px' class=" w-full flex justify-center items-center grid gap-6 mb-8 xl:grid-cols-6 lg:grid-cols-3 md:grid-cols-2 sm:grid-cols-2 grid-cols-2">
                <?php

                $sql_servers = "SELECT * FROM servers ORDER BY id DESC";
				$stmt = $conn->prepare($sql_servers);
				$stmt->execute();
				$result_servers = $stmt->get_result();
				$stmt->close();
                while ($row_servers = $result_servers->fetch_assoc()) {

                    echo '
<div class="w-full p-4 m-auto bg-white shadow-sm rounded-2xl dark:bg-gray-800">
    <div class="w-full h-full text-center">
        <div class="flex flex-col justify-between h-full">
            <img src="icons/servers.svg" width="40px" class="mx-auto mt-4" style="color: #5f7d95">
            <p class="mt-4 text-xl font-bold text-gray-800 dark:text-gray-200" style="font-size: 16px">
                ' . $row_servers['name'] . '
            </p>
            <p class="px-6 py-2 text-xs text-gray-600 dark:text-gray-400">
               ip: ' . $row_servers['ip'] . '
            </p>';


                    ?>
                    <?php
                    echo '<div class="flex items-center justify-center w-full gap-4 mt-2">
                    <a href="wizwizbackup.php?delete=' . $row_servers['id'] . '">
                    <svg class="m-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="20" fill="#ff758f"><g id="_01_align_center" data-name="01 align center"><path d="M18.965,8.464l5.029-5.029L22.565,2.006,17.519,7.051,15.313,4.895a2.011,2.011,0,0,0-2.724-.073A19.71,19.71,0,0,1,6.226,8.687L-.006,10.514v.756A12.892,12.892,0,0,0,13.006,24.006h1.241l.261-.182a14.98,14.98,0,0,0,6.886-12.081,2.013,2.013,0,0,0-.611-1.5ZM13.9,6.34l5.477,5.341a12.652,12.652,0,0,1-.456,3.015L11.941,7.9A24.691,24.691,0,0,0,13.9,6.34Zm-.294,15.645h-.6a11.153,11.153,0,0,1-4.293-.859,11.55,11.55,0,0,0,4.348-3.8l.518-.76L11.91,15.43l-.518.761A9.539,9.539,0,0,1,7.8,19.324l-1.229.618a10.9,10.9,0,0,1-2.585-2.563,11.632,11.632,0,0,0,4.357-2.657L6.932,13.277a9.611,9.611,0,0,1-3.974,2.317,10.4,10.4,0,0,1-.921-3.575l4.755-1.394a15.234,15.234,0,0,0,3.423-1.59l7.911,7.7A14.1,14.1,0,0,1,13.608,21.985Z"/></g></svg>
                    </a>';
                    if ($row_servers['status'] == '1') {
                        echo '<a href="wizwizbackup.php?off=' . $row_servers['id'] . '">
                    <svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 24 24" class="m-1" width="20" fill="#219ebc"><path d="M23.821,11.181v0C22.943,9.261,19.5,3,12,3S1.057,9.261.179,11.181a1.969,1.969,0,0,0,0,1.64C1.057,14.739,4.5,21,12,21s10.943-6.261,11.821-8.181A1.968,1.968,0,0,0,23.821,11.181ZM12,18a6,6,0,1,1,6-6A6.006,6.006,0,0,1,12,18Z"/><circle cx="12" cy="12" r="4"/></svg>
                    </a>';
                    } else {
                        echo '<a href="wizwizbackup.php?on=' . $row_servers['id'] . '">
                    <svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 24 24" class="m-1" width="20" fill="#bde0fe"><path d="M23.821,11.181v0C22.943,9.261,19.5,3,12,3S1.057,9.261.179,11.181a1.969,1.969,0,0,0,0,1.64C1.057,14.739,4.5,21,12,21s10.943-6.261,11.821-8.181A1.968,1.968,0,0,0,23.821,11.181ZM12,18a6,6,0,1,1,6-6A6.006,6.006,0,0,1,12,18Z"/><circle cx="12" cy="12" r="4"/></svg>
                    </a>';
                    }
                    echo '
                </div>
            </div>
        </div>
    </div>

';
                }
                ?>

        </div>
    </main>
</div>
</div>


<!-- Modal backdrop. This what you want to place close to the closing body tag -->
<div
        x-show="isModalOpen"
        x-transition:enter="transition ease-out duration-150"
        x-transition:enter-start="opacity-0"
        x-transition:enter-end="opacity-100"
        x-transition:leave="transition ease-in duration-150"
        x-transition:leave-start="opacity-100"
        x-transition:leave-end="opacity-0"
        class="fixed inset-0 z-30 flex items-end bg-black bg-opacity-30 sm:items-center sm:justify-center"
>
    <!-- Modal -->
    <div
            x-show="isModalOpen"
            x-transition:enter="transition ease-out duration-150"
            x-transition:enter-start="opacity-0 transform translate-y-1/2"
            x-transition:enter-end="opacity-100"
            x-transition:leave="transition ease-in duration-150"
            x-transition:leave-start="opacity-100"
            x-transition:leave-end="opacity-0  transform translate-y-1/2"
            @click.away="closeModal"
            @keydown.escape="closeModal"
            class="w-full px-6 py-4 overflow-hidden bg-white rounded-t-lg dark:bg-gray-800 sm:rounded-lg sm:m-4 sm:max-w-xl"
            role="dialog"
            id="modal"
    >
        <!-- Remove header if you don't want a close icon. Use modal body to place modal tile. -->

        <?php
        if (isset($_GET['delete'])) {
            $id_delete_server = $_GET['delete'];
			if(is_numeric($id_delete_server)){
				$sql_delete_server = "DELETE FROM servers WHERE id=?";
				$stmt = $conn->prepare($sql_delete_server);
				$stmt->bind_param('i', $id_delete_server);
				$stmt->execute();

				if (!$stmt) {
					$error = $stmt->error;
					$stmt->close();
					die("خطای پایگاه داده" . $error);
				} else {
					$stmt->close();
					deletewizwiz();
					header("location: wizwizbackup.php");
				}
			}
        }

        if (isset($_GET['on'])) {
            $id_on_select = $_GET['on'];
			if(is_numeric($id_on_select)){
				$sql_on_select = "UPDATE servers SET status='1' WHERE id=?";
				$stmt = $conn->prepare($sql_on_select);
				$stmt->bind_param('i', $id_on_select);
				$stmt->execute();
				if (!$stmt) {
					$error = $stmt->error;
					$stmt->close();
					echo "خطا" . die($error);
				} else {
					$stmt->close();
					statusonwizwiz();
					header("location: wizwizbackup.php");
				}
			}
        }

        if (isset($_GET['off'])) {
            $id_off_select = $_GET['off'];
			if(is_numeric($id_off_select)){
				$sql_off_select = "UPDATE servers SET status='0' WHERE id='$id_off_select'";
				$stmt = $conn->prepare($sql_off_select);
				$stmt->bind_param('i', $id_off_select);
				$stmt->execute();
				if (!$stmt) {
					$error = $stmt->error;
					$stmt->close();
					echo "خطا" . die($error);
				} else {
					$stmt->close();
					statusoffwizwiz();
					header("location: wizwizbackup.php");
				}
			}
        }

        if(isset($_POST['action']) && $_POST['action'] == 'insert_server_backup') {
            $ip_server = $_POST['ip'];
            $port_server = $_POST['port'];
            $username_server = $_POST['username'];
            $password_server = $_POST['password'];
            $name_server = $_POST['name'];
            $panel_server = $_POST['panel'];

            if($panel_server == "NidukaAkalanka") $panel_server = "/etc/x-ui-english/x-ui-english.db";
            else $panel_server = "/etc/x-ui/x-ui.db";
            $status = '1';
            $insert_server_sql = "INSERT INTO servers (ip,port,username,password,name,status,panel) 
                          VALUES (?,?,?,?,?,?,?)";
			$stmt = $conn->prepare($insert_server_sql);
			$stmt->bind_param('sssssss',$ip_server,$port_server,$username_server,$password_server,$name_server,$status,$panel_server);
			$stmt->execute();

            if (!$stmt) {
				$error = $stmt->error;
				$stmt->close();
                echo "خطا" . die($error);
            } else {
				$stmt->close();
                creatwizwiz();
                header('Location: wizwizbackup.php');

            }
        }
        ?>
        <form id="insert_server_backup">
            <!-- Modal body -->
                <p class="m-4 dark:text-gray-200 text-gray-700">
                    <?php echo $_LANG['notbackup']?>
                </p>
                <div class="flex relative m-2">
                    <span class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-l-md inline-flex  items-center px-3 border-t bg-white border-l border-b  border-gray-300 text-gray-500 shadow-sm text-sm">
                        <?php echo $_LANG['servername']?>
                    </span>
                    <input name="name" style="font-size: 14px;" value="" type="text" id="with-email"
                           class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-r-lg flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-red-400 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-transparent"
                           placeholder="" required/>
                </div>
                <div class="flex relative m-2">
                    <span class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-l-md inline-flex  items-center px-3 border-t bg-white border-l border-b  border-gray-300 text-gray-500 shadow-sm text-sm">
                        <?php echo $_LANG['ip']?>
                    </span>
                    <input name="ip" style="font-size: 14px;" value="" type="text" id="with-email"
                           class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-r-lg flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-red-400 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-transparent"
                           placeholder="" required/>
                </div>
                <div class="flex relative m-2">
                    <span class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-l-md inline-flex  items-center px-3 border-t bg-white border-l border-b  border-gray-300 text-gray-500 shadow-sm text-sm">
                        <?php echo $_LANG['port']?>
                    </span>
                    <input name="port" style="font-size: 14px;" value="" type="number" id="with-email"
                           class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-r-lg flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-red-400 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-transparent"
                           placeholder="" required/>
                </div>
                <div class="flex relative m-2">
                    <span class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-l-md inline-flex  items-center px-3 border-t bg-white border-l border-b  border-gray-300 text-gray-500 shadow-sm text-sm">
                        <?php echo $_LANG['username']?>
                    </span>
                    <input name="username" style="font-size: 14px;" value="" type="text" id="with-email"
                           class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-r-lg flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-red-400 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-transparent"
                           placeholder="" required/>
                </div>
                <div class="flex relative m-2">
                    <span class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-l-md inline-flex  items-center px-3 border-t bg-white border-l border-b  border-gray-300 text-gray-500 shadow-sm text-sm">
                        <?php echo $_LANG['password']?>
                    </span>
                    <input name="password" style="font-size: 14px;" value="" type="text" id="with-email"
                           class="dark:border-gray-600 dark:bg-gray-700 focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:text-gray-300 dark:focus:shadow-outline-gray rounded-r-lg flex-1 appearance-none border border-gray-300 w-full py-2 px-4 bg-white text-red-400 placeholder-gray-400 shadow-sm text-base focus:outline-none focus:ring-2 focus:ring-blue-200 focus:border-transparent"
                           placeholder="" required/>
                </div>
            <label class="block mt-2 text-sm mx-auto" style="width: 97%;line-height: 16px ">
                <select required name="panel"
                        class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray">
                    <option value="Vaxilu">Vaxilu</option>
                    <option value="Alireza">Alireza</option>
                    <option value="Mhsanaei">Mhsanaei</option>
                    <option value="FranzKafkaYu">FranzKafkaYu</option>
                    <option value="Hossinasaadi">Hossinasaadi</option>
                    <option value="HexaSoftwareTech">HexaSoftwareTech</option>
                    <option value="NidukaAkalanka">NidukaAkalanka</option>
                </select>
            </label>
                <footer class="mt-5 flex flex-col items-center justify-end px-6 py-3 -mx-6 -mb-4 space-y-4 sm:space-y-0 sm:space-x-6 sm:flex-row bg-gray-50 dark:bg-gray-800">
                    <button type="button" style="border: 1px solid #e76d81"
                            class="w-full inline-flex items-center justify-center px-5 py-3 transition-colors duration-150 border border-transparent rounded-lg sm:w-auto sm:px-4 sm:py-2 hover:bg-red-100 "
                            aria-label="close" @click="closeModal">
                        <svg xmlns="http://www.w3.org/2000/svg" fill="#e76d81" id="Outline" viewBox="0 0 24 24" width="15">
                            <path d="M23.707.293h0a1,1,0,0,0-1.414,0L12,10.586,1.707.293a1,1,0,0,0-1.414,0h0a1,1,0,0,0,0,1.414L10.586,12,.293,22.293a1,1,0,0,0,0,1.414h0a1,1,0,0,0,1.414,0L12,13.414,22.293,23.707a1,1,0,0,0,1.414,0h0a1,1,0,0,0,0-1.414L13.414,12,23.707,1.707A1,1,0,0,0,23.707.293Z"/>
                        </svg>
                    </button>
                    <button style="border: 1px solid #41c76e" name="add_server" type="submit" @click="closeModal"
                            class="inline-flex items-center justify-center w-full px-5 py-3 text-sm font-medium leading-5 text-white transition-colors duration-15 border border-transparent rounded-lg sm:w-auto sm:px-4 sm:py-2 hover:bg-green-100 ">
                        <svg xmlns="http://www.w3.org/2000/svg" id="Outline" fill="#41c76e" viewBox="0 0 24 24" width="15">
                            <path d="M22.319,4.431,8.5,18.249a1,1,0,0,1-1.417,0L1.739,12.9a1,1,0,0,0-1.417,0h0a1,1,0,0,0,0,1.417l5.346,5.345a3.008,3.008,0,0,0,4.25,0L23.736,5.847a1,1,0,0,0,0-1.416h0A1,1,0,0,0,22.319,4.431Z"/>
                        </svg>
                    </button>
                </footer>
        </form>
<?php
include 'includ/footer.php';
?>
