<?php
session_start();
include("../db.php");

if(!isset($_SESSION['admin'])){
header("Location:index.php");
exit();
}

/* Update ticker */

if(isset($_POST['update'])){

$content=$_POST['content'];

mysqli_query($conn,"UPDATE ticker SET content='$content' WHERE id=1");

}

$ticker=mysqli_fetch_assoc(mysqli_query($conn,"SELECT * FROM ticker LIMIT 1"));

?>

<!DOCTYPE html>
<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>Manage Ticker</title>

<style>

body{
margin:0;
font-family:Arial;
background:#eef1f5;
display:flex;
}

*{
box-sizing:border-box;
}

/* Sidebar */

.sidebar{
width:230px;
background:#0f6c74;
color:white;
height:100vh;
position:fixed;
padding-top:20px;
}

.sidebar h2{
text-align:center;
margin-bottom:30px;
}

.sidebar a{
display:block;
padding:12px 20px;
color:white;
text-decoration:none;
}

.sidebar a:hover{
background:#0a5258;
}

/* Main */

.main{
margin-left:230px;
width:100%;
}

/* Topbar */

.topbar{
background:white;
padding:15px;
display:flex;
justify-content:space-between;
align-items:center;
box-shadow:0 2px 6px rgba(0,0,0,0.1);
}

/* Container */

.container{
padding:20px;
}

/* Card */

.card{
background:white;
padding:20px;
border-radius:10px;
box-shadow:0 3px 8px rgba(0,0,0,0.1);
margin-bottom:20px;
}

/* Inputs */

textarea{
width:100%;
height:120px;
padding:10px;
margin-top:10px;
border:1px solid #ccc;
border-radius:5px;
font-size:14px;
}

/* Button */

button{
background:#0f6c74;
color:white;
border:none;
padding:10px 18px;
border-radius:6px;
cursor:pointer;
margin-top:10px;
}

/* Preview */

.preview{
margin-top:15px;
background:#ff9900;
color:white;
padding:10px;
border-radius:6px;
font-weight:bold;
white-space:nowrap;
overflow:hidden;
}

</style>

</head>

<body>

<!-- Sidebar Include -->

<?php include("layout/sidebar.php"); ?>

<!-- Main -->

<div class="main">

<div class="topbar">

<h3>Manage Ticker</h3>

<div>Super Admin</div>

</div>

<div class="container">

<!-- Edit Ticker -->

<div class="card">

<h3>Edit Ticker Message</h3>

<form method="post">

<textarea name="content"><?php echo $ticker['content']; ?></textarea>

<button name="update">Update Ticker</button>

</form>

</div>

<!-- Live Preview -->

<div class="card">

<h3>Live Preview</h3>

<div class="preview">

<?php echo $ticker['content']; ?>

</div>

</div>

</div>

</div>

</body>

</html>