<?php 
session_start();
if(isset($_SESSION['SESS_ADMINLOGGEDIN']) == FALSE) {
    header("Location: " . $config_basedir."../admin/adminlogin.php");
}

require_once("header.php");
?>





<?php

  // Prepare and execute
    $stmt = $pdo->prepare("SELECT * FROM settings WHERE id = :id");
    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
    $stmt->execute();

    $ordrow = $stmt->fetch(PDO::FETCH_ASSOC);

    // Now you can use $ordrow['column_name']

?>

<?php

$id = $_GET['id'] ?? null;

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['maintenace_action'])) {
    $main_status = $_POST['main_status']; // Value from form
    $end_time = $_POST['end_time']; // Value from form

    // Update using prepared statement
    $stmt = $pdo->prepare("UPDATE settings SET main_status = ?, end_time = ? WHERE id = ?");
    if ($stmt->execute([$main_status, $end_time, $id])) {
        if ($main_status == 1) {  
            echo "<script>
                alert('Maintenance successfully turned ON!');
                window.location.href = '';
            </script>";
        } elseif ($main_status == 0) {  
            echo "<script>
                alert('Maintenance successfully turned OFF!');
                window.location.href = '';
            </script>";
        }
    } else {
        echo "<script>
            alert('Failed to update maintenance status!');
            window.location.href = 'auto.php';
        </script>";
    }
}
?>


 
 <!--=============END==AUTO====================================-->


    


   



        <div wire:id="0ho7JEz65LVMGIzD4ceZ" wire:initial-data="{&quot;fingerprint&quot;:{&quot;id&quot;:&quot;0ho7JEz65LVMGIzD4ceZ&quot;,&quot;name&quot;:&quot;admin.manage-users&quot;,&quot;locale&quot;:&quot;en&quot;,&quot;path&quot;:&quot;admin\/dashboard\/manageusers&quot;,&quot;method&quot;:&quot;GET&quot;,&quot;v&quot;:&quot;acj&quot;},&quot;effects&quot;:{&quot;listeners&quot;:[],&quot;path&quot;:&quot;https:\/\/xtbtrading.live\/trade\/admin\/dashboard\/manageusers&quot;},&quot;serverMemo&quot;:{&quot;children&quot;:[],&quot;errors&quot;:[],&quot;htmlHash&quot;:&quot;ed570425&quot;,&quot;data&quot;:{&quot;pagenum&quot;:10,&quot;searchvalue&quot;:&quot;&quot;,&quot;orderby&quot;:&quot;id&quot;,&quot;orderdirection&quot;:&quot;desc&quot;,&quot;selectPage&quot;:false,&quot;selectAll&quot;:false,&quot;checkrecord&quot;:[],&quot;selected&quot;:&quot;&quot;,&quot;action&quot;:&quot;Delete&quot;,&quot;username&quot;:null,&quot;fullname&quot;:null,&quot;email&quot;:null,&quot;password&quot;:null,&quot;message&quot;:null,&quot;subject&quot;:null,&quot;plan&quot;:null,&quot;datecreated&quot;:null,&quot;topamount&quot;:null,&quot;toptype&quot;:null,&quot;topcolumn&quot;:&quot;Bonus&quot;,&quot;page&quot;:1,&quot;paginators&quot;:{&quot;page&quot;:1}},&quot;dataMeta&quot;:[],&quot;checksum&quot;:&quot;9e82a6adabccc53607a584c57da8f89b4130352eb62c7aa9cc50f9455ca3c494&quot;}}">
    <div class="main-panel">
        <div class="content bg-light">
            <div class="page-inner">
                <div class="mt-2 mb-4">
                    <h1 class="title1 text-dark">MAINTENANCE SYSTEM CONTROLLER</h1>
                </div>
                <div>
    </div>                <div>
    </div>                
               
               
               
               
                <div class="mb-5 row">
                    <div class="col-md-12 ">
                        <!--<div class="card shadow p-4 bg-light">-->
     
     
     
                   
                            
                            
                            
                            
    <?php

// / Get and sanitize ID from GET
    $id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

    // Fetch the row
    $stmt = $pdo->prepare("SELECT * FROM settings WHERE id = :id");
    $stmt->bindParam(':id', $id, PDO::PARAM_INT);
    $stmt->execute();
    $ordrow = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($ordrow) {
        // Display the form
        echo "<form method='POST' enctype='multipart/form-data' action=''>
  
  
  
  
    <div class='form-row mb-4'>
        <div class='form-group'>
            <label for=''>MAINTENANCE SYSTEM</label>
           
            <select name='main_status' class='form-control' required>
                <!-- Show the current value and options to change -->
                <option value='" . htmlspecialchars($ordrow['main_status'], ENT_QUOTES) . "'>";
                

                   if ($ordrow['main_status'] == 1) {  
                   echo "MAINTENANCE IS ON";
          }
            elseif ($ordrow['main_status'] == 0) {  
                   echo "MAINTENANCE IS OFF";
          }
                echo"</option>
                
                <option value='1'>ON-MAINTENANCE</option>
                <option value='0'>OFF-MAINTENANCE</option>
            </select>
            
        </div>
    </div>

          ";
} else {
    echo "<div class='alert alert-danger'>Settings not found.</div>";
}
?>
          
          
          
          
          
          
            <div class='form-row mb-4'>
        <div class='form-group'>
            <label for=''>MAINTENANCE SYSTEM</label>
  
          
          <input type='datetime-local' name='end_time' value='<?php echo date('Y-m-d\TH:i', strtotime($settings['end_time'])); ?>'  class='form-control' required>

</div>
    </div>
 

        
 <button type='submit' class='btn btn-success btn-block btn-theme-colored2 text-red btn-lg btn-flat' name='maintenace_action'>SITE MAINTENANCE</button>

    </form>
            
            <hr>
            
  
    

        
            
        </div></div></div>
<!--=====================================-->

</div>

 <?php
require ("footer.php")
?>