<?php


$db = new SQLite3('./api/.db.db');
$res = $db->query("SELECT * FROM users WHERE id='1'");
$row = $res->fetchArray();

if (isset($_POST['submit']))
{
    $db->exec("UPDATE users SET	username='" . $_POST['username'] . "', password='" . $_POST['password'] . "' WHERE id='1' ");
    session_start();
    session_regenerate_id();
    $_SESSION['loggedin'] = true;
    $_SESSION['name'] = $_POST['username'];
    header("Location: ". basename($_SERVER["SCRIPT_NAME"])."?status=1");
}
$user = $row['username'];
$pass = $row['password'];

include ('includes/header.php');

echo "    	<div class=\"col-md-8 mx-auto\">\n";
echo "			<div class=\"card-body\">\n";
echo "				<div class=\"card bg-primary text-white\">\n";
echo "					<div class=\"card-header card-header-warning\">\n";
echo "                        <center>\n";
echo "                            <h2><i class=\"icon icon-user\"></i> Update Credentials</h2>\n";
echo "                        </center>\n";
echo "						<center>\n";
echo "							<h4 style=\"color:red!important\">Do <strong style=\"color:red!important\">not</strong> use <em>admin</em> for username or password!\n";
echo "							SECURE YOUR PANEL</h4>\n";
echo "						</center>\n";
echo "					</div>\n";
echo "\n";
echo "					<div class=\"card-body\">\n";
echo "						<form  method=\"post\">\n";
echo "\n";
echo "							<div class=\"form-group\">\n";
echo "								<div class=\"form-group form-float form-group-lg\">\n";
echo "                                    <div class=\"form-line\">\n";
echo "                                        <label class=\"form-label\">Username</label>\n";
echo "										<input type=\"text\" class=\"form-control\" name=\"username\" value=\"$user\">\n";
echo "									</div>\n";
echo "								</div>\n";
echo "							</div>\n";
echo "\n";
echo "							<div class=\"form-group\">\n";
echo "								<div class=\"form-group form-float form-group-lg\">\n";
echo "                                    <div class=\"form-line\">\n";
echo "                                        <label class=\"form-label\">Password</label>\n";
echo "										<input type=\"text\" class=\"form-control\" name=\"password\" value=\"$pass\">\n";
echo "									</div>\n";
echo "								</div>\n";
echo "							</div>\n";
echo "\n";
echo "							<hr>\n";
echo "\n";
echo "							<center>\n";
echo "								<button type=\"submit\" name=\"submit\" class=\"btn btn-info\">\n";
echo "									<i class=\"icon icon-check\"></i>Update Credentials\n";
echo "								</button>\n";
echo "							</center>\n";
echo "						</form>\n";
echo "					</div>\n";
echo "				</div>\n";
echo "			</div>\n";
echo "		</div>\n";
echo "\n";
echo "\n";
include ('includes/footer.php');
echo "\n";
echo "</body>\n";
echo "</html>\n";


?>