<?php
include ('includes/header.php');

$table_name = 'maintenance';
$page = "maintenance.php";


$data = ['title' => 'We are offline at the moment.','body' => 'The service has been temporarily suspended due to urgent maintenance. We apologize for the inconvenience and please try again in a few moments.','mode' => 'off'];

$db->insertIfEmpty($table_name, $data);

//table call
$rowU = $db->select($table_name, '*', '', '');

if(isset($_POST['submit'])){
	unset($_POST['submit']);
	$updateData = $_POST;
	$db->update($table_name, $updateData, 'id = :id',[':id' => 1]);
	echo "<script>window.location.href='". $page."?status=1'</script>";
}

?>

        <div class="col-md-6 mx-auto ctmain-table">
            <div class="card-body">
                <div class="card text-white ctcard">
                    <div class="card-header card-header-warning">
                        <center>
                            <h2><i class="icon icon-bullhorn"></i> Maintenance Mode</h2>
                        </center>
                    </div>
                    <div class="card-body ctcard">
                        <div class="col-12">
                            <h3>Maintenance Mode Details</h3>
                        </div>
                            <form method="post">
								<div class="form-group ctinput">
									  <label class="form-group form-float form-group-lg">Current Status</label>
									  <select class="form-control" id="select" name="mode">
										  <option value="off" <?=$rowU[0]['mode']=='off'?'selected':'' ?>>Off</option>
										  <option value="on" <?=$rowU[0]['mode']=='on'?'selected':'' ?>>On</option>
									  </select>
								</div>
                                <div class="form-group ctinput">
                                    <label class="form-label " for="version">Title</label>
                                        <input class="form-control" name="title" value="<?=$rowU[0]['title'] ?>" type="text"/>
                                </div>
                                <div class="form-group ctinput">
                                    <label class="form-label " for="package">Message</label>
                                        <input class="form-control"  name="body" value="<?=$rowU[0]['body'] ?>" type="text"/>
                                </div>
                                <div class="form-group ctinputform-group">
                                    <center>
                                        <button class="btn btn-info " name="submit" type="submit">
                                            <i class="icon icon-check"></i> Submit
                                        </button>
                                    </center>
                                </div>
                            </form>
                    </div>
                </div>
            </div>
        </div>

<?php include ('includes/footer.php');?>
</body>
</html>